wip in progress.

This commit is contained in:
NADAL Jean-Baptiste
2019-12-11 18:57:59 +01:00
parent 214b09e6d3
commit bde9ffd991
9 changed files with 309 additions and 35 deletions

View File

@@ -10,10 +10,9 @@ set(ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/build/lib")
set(LIBRARY_OUTPUT_PATH "${CMAKE_SOURCE_DIR}/build/lib")
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake-modules/")
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../libuv ${CMAKE_CURRENT_BINARY_DIR}/libuv)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../libwebsockets ${CMAKE_CURRENT_BINARY_DIR}/libwebsockets)
#add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../libuv ${CMAKE_CURRENT_BINARY_DIR}/libuv)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../nats.c ${CMAKE_CURRENT_BINARY_DIR}/nats.c)
#add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../json-c ${CMAKE_CURRENT_BINARY_DIR}/json-c)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../libsourcey ${CMAKE_CURRENT_BINARY_DIR}/libsourcey)
add_subdirectory(src)
add_custom_target (static_analysis

View File

@@ -3,3 +3,11 @@ https://auth0.com/docs/flows/guides/device-auth/call-api-device-auth
nikhilm.github.io/uvbook/An%20Introduction%20to%20libuv.pdf
https://github.com/lasote/async_http_request/
https://github.com/LeonHartley/libhttp
https://github.com/liigo/tinyweb
https://github.com/dropbox/json11
https://github.com/lzpong/TinyWeb

View File

@@ -6,23 +6,17 @@ fi
CMAKE_OPTS="-DCMAKE_EXPORT_COMPILE_COMMANDS=On"
#
# General
CMAKE_OPTS="$CMAKE_OPTS -DCMAKE_BUILD_TYPE=DEBUG"
# Options for LIBWEBSOCKET
CMAKE_OPTS="$CMAKE_OPTS -DLWS_WITH_HTTP2=OFF"
CMAKE_OPTS="$CMAKE_OPTS -DLWS_WITH_STATIC=ON"
CMAKE_OPTS="$CMAKE_OPTS -DLWS_WITH_SHARED=OFF"
CMAKE_OPTS="$CMAKE_OPTS -DLWS_WITH_SSL=OFF"
CMAKE_OPTS="$CMAKE_OPTS -DLWS_WITH_LIBUV=ON"
CMAKE_OPTS="$CMAKE_OPTS -DLIBUV_INCLUDE_DIRS=$PWD/../libuv/include/"
CMAKE_OPTS="$CMAKE_OPTS -DLIBUV_LIBRARIES=$PWD/build/lib/"
CMAKE_OPTS="$CMAKE_OPTS -DLWS_WITHOUT_TESTAPPS=ON"
CMAKE_OPTS="$CMAKE_OPTS -DLWS_WITHOUT_TEST_SERVER=ON"
CMAKE_OPTS="$CMAKE_OPTS -DLWS_WITHOUT_TEST_SERVER_EXTPOLL=ON"
CMAKE_OPTS="$CMAKE_OPTS -DLWS_WITHOUT_TEST_PING=ON"
CMAKE_OPTS="$CMAKE_OPTS -DLWS_WITHOUT_TEST_CLIENT=ON"
# Options for LibSourcey
CMAKE_OPTS="$CMAKE_OPTS -DBUILD_SHARED_LIBS=OFF"
CMAKE_OPTS="$CMAKE_OPTS -D-DBUILD_WITH_STATIC_CRT=ON"
CMAKE_OPTS="$CMAKE_OPTS -DBUILD_MODULES=ON"
CMAKE_OPTS="$CMAKE_OPTS -DBUILD_APPLICATIONS=OFF"
CMAKE_OPTS="$CMAKE_OPTS -DBUILD_SAMPLES=OFF"
CMAKE_OPTS="$CMAKE_OPTS -DBUILD_TESTS=OFF"
CMAKE_OPTS="$CMAKE_OPTS -DENABLE_LOGGING=ON"
# Options for NATS.c
CMAKE_OPTS="$CMAKE_OPTS -DNATS_BUILD_EXAMPLES=OFF"

141
patches/libsourcey.patch Normal file
View File

@@ -0,0 +1,141 @@
diff --git a/src/crypto/include/scy/crypto/hash.h b/src/crypto/include/scy/crypto/hash.h
index a93fdde9..1d65c374 100644
--- a/src/crypto/include/scy/crypto/hash.h
+++ b/src/crypto/include/scy/crypto/hash.h
@@ -53,7 +53,11 @@ public:
protected:
Hash& operator=(Hash const&);
- EVP_MD_CTX _ctx;
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
+ EVP_MD_CTX _ctx;
+#else
+ EVP_MD_CTX* _ctxPtr;
+#endif
const EVP_MD* _md;
crypto::ByteVec _digest;
std::string _algorithm;
diff --git a/src/crypto/src/crypto.cpp b/src/crypto/src/crypto.cpp
index 729fa615..6113c02f 100644
--- a/src/crypto/src/crypto.cpp
+++ b/src/crypto/src/crypto.cpp
@@ -120,7 +120,9 @@ void init()
if (++_refCount == 1) {
#if OPENSSL_VERSION_NUMBER >= 0x0907000L
+ #if OPENSSL_VERSION_NUMBER < 0x10100000L
OPENSSL_config(NULL);
+ #endif
#endif
SSL_library_init();
SSL_load_error_strings();
diff --git a/src/crypto/src/hash.cpp b/src/crypto/src/hash.cpp
index 1a0fad34..d132be3b 100644
--- a/src/crypto/src/hash.cpp
+++ b/src/crypto/src/hash.cpp
@@ -32,7 +32,11 @@ Hash::Hash(const std::string& algorithm)
if (!_md)
throw std::runtime_error("Algorithm not supported: " + algorithm);
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
EVP_DigestInit(&_ctx, _md);
+#else
+ EVP_DigestInit(_ctxPtr, _md);
+#endif
}
@@ -40,7 +44,11 @@ Hash::~Hash()
{
crypto::uninitializeEngine();
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
EVP_MD_CTX_cleanup(&_ctx);
+#else
+ EVP_MD_CTX_free(_ctxPtr);
+#endif
//EVP_MD_CTX_free(_ctx);
}
@@ -49,15 +57,24 @@ void Hash::reset()
{
//EVP_MD_CTX_free(_ctx);
//_ctx = EVP_MD_CTX_new();
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
internal::api(EVP_MD_CTX_cleanup(&_ctx));
internal::api(EVP_DigestInit(&_ctx, _md));
+#else
+ internal::api(EVP_MD_CTX_reset(_ctxPtr));
+ internal::api(EVP_DigestInit(_ctxPtr, _md));
+#endif
_digest.clear();
}
void Hash::update(const void* data, size_t length)
{
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
internal::api(EVP_DigestUpdate(&_ctx, data, length));
+#else
+ internal::api(EVP_DigestUpdate(_ctxPtr, data, length));
+#endif
}
@@ -79,7 +96,11 @@ const ByteVec& Hash::digest()
if (_digest.size() == 0) {
_digest.resize(EVP_MAX_MD_SIZE); // TODO: Get actual algorithm size
unsigned int len = 0;
+ #if OPENSSL_VERSION_NUMBER < 0x10100000L
internal::api(EVP_DigestFinal(&_ctx, &_digest[0], &len));
+ #else
+ internal::api(EVP_DigestFinal(_ctxPtr, &_digest[0], &len));
+ #endif
_digest.resize(len);
}
return _digest;
diff --git a/src/crypto/src/x509certificate.cpp b/src/crypto/src/x509certificate.cpp
index 76f5e799..d362fada 100644
--- a/src/crypto/src/x509certificate.cpp
+++ b/src/crypto/src/x509certificate.cpp
@@ -58,10 +58,14 @@ X509Certificate::X509Certificate(X509* pCert, bool shared)
{
assert(_certificate);
- if (shared)
+ if (shared) {
+ #if OPENSSL_VERSION_NUMBER < 0x10100000L
_certificate->references++;
// X509_up_ref(_certificate); // OpenSSL >= 1.1.0
-
+ #else
+ X509_up_ref(_certificate); // OpenSSL >= 1.1.0
+ #endif
+ }
init();
}
@@ -241,8 +245,15 @@ void X509Certificate::extractNames(std::string& cmnName,
for (int i = 0; i < sk_GENERAL_NAME_num(names); ++i) {
const GENERAL_NAME* name = sk_GENERAL_NAME_value(names, i);
if (name->type == GEN_DNS) {
- const char* data =
+ #if OPENSSL_VERSION_NUMBER < 0x10100000L
+ const char* data =
reinterpret_cast<char*>(ASN1_STRING_data(name->d.ia5));
+ #else
+ const char* data =
+ reinterpret_cast<const char*>(ASN1_STRING_get0_data(name->d.ia5));
+ #endif
+
+
size_t len = ASN1_STRING_length(name->d.ia5);
domainNames.insert(std::string(data, len));
}
@@ -310,4 +321,4 @@ const X509* X509Certificate::certificate() const
} // namespace scy
-/// @\}
\ No newline at end of file
+/// @\}

View File

@@ -3,29 +3,41 @@ cmake_minimum_required(VERSION 3.0)
project(domo-iot)
set (CMAKE_MODULE_PATH "${MODULE_PATH}")
set (CMAKE_CXX_STANDARD 11)
set (CMAKE_CXX_STANDARD 14)
link_directories(${CMAKE_SOURCE_DIR}/build/lib)
include_directories(${CMAKE_SOURCE_DIR}/../nats.c/src)
include_directories(${CMAKE_SOURCE_DIR}/../libuv/include)
include_directories(${CMAKE_SOURCE_DIR}/build/libwebsockets/include)
include_directories(${CMAKE_SOURCE_DIR}/src)
include_directories(${CMAKE_SOURCE_DIR}/../libsourcey/src/base/include)
include_directories(${CMAKE_SOURCE_DIR}/../libsourcey/src/net/include)
include_directories(${CMAKE_SOURCE_DIR}/../libsourcey/vendor/libuv/include/)
include_directories(${CMAKE_SOURCE_DIR}/build)
#include_directories(${CMAKE_SOURCE_DIR}/libhttp/vendor/http-parser)
#set(CMAKE_CXX_FLAGS "-Wall -Wextra -pedantic -Werror=strict-aliasing")
file(
GLOB_RECURSE
source_files
main.c
main.cpp
server/domo-server.cpp
broker/nats-broker.cpp
http/http-server.cpp
)
#http/http-server.cpp
add_executable (domo-iot ${source_files})
target_link_libraries (domo-iot
LINK_PUBLIC
nats_static
websockets
uv_a
rt
libuv
libscy_base.a
libscy_http.a
libscy_net.a
pthread
)
install (TARGETS domo-iot DESTINATION local/bin)

62
src/http/http-server.cpp Normal file
View File

@@ -0,0 +1,62 @@
/*!
* http-server.cpp
*
* Copyright (c) 2015-2019, NADAL Jean-Baptiste. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*
* @Author: NADAL Jean-Baptiste
* @Date: 13/11/2019
*
*/
// This is an independent project of an individual developer. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++, C#, and Java: http://www.viva64.com
/*------------------------------- INCLUDES ----------------------------------*/
#include <string.h>
#include "http-server.h"
/*! ----------------------------------------------------------------------------
* @fn HttpServer
*
* @brief Constructor of the HTTP Server Object.
*/
HttpServer::HttpServer(void)
{
}
/*! ----------------------------------------------------------------------------
* @fn ~HttpServer
*
* @brief Destructor of the HTTP Server Object.
*/
HttpServer::~HttpServer(void)
{
}
/*! ----------------------------------------------------------------------------
* @fn setup
*
* @brief Setup the Http server
*/
int HttpServer::setup(char *a_document_root, int a_port, uv_loop_t *an_evt_loop)
{
return 0;
}

48
src/http/http-server.h Normal file
View File

@@ -0,0 +1,48 @@
/*!
* http-server.h
*
* Copyright (c) 2015-2019, NADAL Jean-Baptiste. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*
* @Author: NADAL Jean-Baptiste
* @Date: 13/11/2019
*
*/
#ifndef _HTTP_SERVER_H
#define _HTTP_SERVER_H
/*------------------------------- INCLUDES ----------------------------------*/
#include <uv.h>
/*---------------------------------- Deps -----------------------------------*/
/*--------------------------------- CLASS ----------------------------------*/
class HttpServer
{
public:
HttpServer(void);
~HttpServer(void);
int setup(char *a_document_root, int a_port, uv_loop_t *an_evt_loop);
private:
};
#endif /* __HTTP_SERVER_H */

View File

@@ -28,11 +28,15 @@
/*-------------------------------- INCLUDES ---------------------------------*/
#include <scy/logger.h>
#include "domo-server.h"
#define kDocumentRoot "."
#define kPort 8081
using namespace std;
/*! ----------------------------------------------------------------------------
* @fn DomoServer
*
@@ -58,24 +62,27 @@ DomoServer::~DomoServer(void)
*/
bool DomoServer::setup(void)
{
LDebug("DomoServer::setup");
// Create the event loop.
m_evt_loop = uv_default_loop();
m_evt_loop = uv::defaultLoop();
if (m_evt_loop == NULL)
{
return false;
}
#if 0
if (m_broker.setup(m_evt_loop))
{
fprintf(stderr, "Failed to setup the Nats Broker.\n");
return false;
}
m_server.setup(kDocumentRoot, kPort, m_evt_loop);
m_http_server.setup(kDocumentRoot, kPort, m_evt_loop);
// TODO
m_broker.connect();
#endif
return true;
}
@@ -89,7 +96,7 @@ void DomoServer::terminate(void)
m_broker.terminate();
if (m_evt_loop != NULL)
uv_loop_close(m_evt_loop);
uv::closeLoop(m_evt_loop);
}
/*! ----------------------------------------------------------------------------
@@ -99,5 +106,6 @@ void DomoServer::terminate(void)
*/
int DomoServer::loop(void)
{
return uv_run(m_evt_loop, UV_RUN_DEFAULT);;
uv::runLoop(m_evt_loop, UV_RUN_DEFAULT);
return 0;
}

View File

@@ -28,13 +28,15 @@
/*------------------------------- INCLUDES ----------------------------------*/
#include <uv.h>
#include <scy/loop.h>
#include "broker/nats-broker.h"
#include "web/web-server.h"
#include "http/http-server.h"
/*---------------------------------- Deps -----------------------------------*/
using namespace scy;
/*--------------------------------- CLASS ----------------------------------*/
class DomoServer
@@ -50,8 +52,8 @@ public:
private:
NatsBroker m_broker;
WebServer m_server;
uv_loop_t *m_evt_loop;
HttpServer m_http_server;
uv::Loop *m_evt_loop;
};
#endif /* _DOMO_SERVER_H */