diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 55c779c..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "files.associations": { - "cmath": "cpp", - "cstdarg": "cpp", - "cstdint": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "cstring": "cpp", - "type_traits": "cpp", - "limits": "cpp", - "*.tcc": "cpp", - "cinttypes": "cpp", - "typeinfo": "cpp" - } -} \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e23701d..99a00e5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,41 +3,36 @@ cmake_minimum_required(VERSION 3.0) project(domo-iot) set (CMAKE_MODULE_PATH "${MODULE_PATH}") -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}/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) +include_directories (${CMAKE_SOURCE_DIR}/libasyncd/include) +include_directories (${CMAKE_SOURCE_DIR}/libevent/include) +include_directories (${CMAKE_SOURCE_DIR}/build/libevent/include) +include_directories (${CMAKE_SOURCE_DIR}/qlibc/include) #set(CMAKE_CXX_FLAGS "-Wall -Wextra -pedantic -Werror=strict-aliasing") file( GLOB_RECURSE source_files - main.cpp - server/domo-server.cpp - broker/nats-broker.cpp - http/http-server.cpp + main.c ) -#http/http-server.cpp + add_executable (domo-iot ${source_files}) target_link_libraries (domo-iot LINK_PUBLIC nats_static - libuv - libscy_base.a - libscy_http.a - libscy_net.a - pthread + asyncd-static + qlibc-static + qlibcext-static + event + event_openssl + ssl + crypto ) install (TARGETS domo-iot DESTINATION local/bin) diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..a0913a7 --- /dev/null +++ b/src/main.c @@ -0,0 +1,72 @@ +/*! + * main.c + * + * 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: 08/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 + +int my_http_get_handler(short event, ad_conn_t *conn, void *userdata) +{ + if (event & AD_EVENT_READ) + { + if (ad_http_get_status(conn) == AD_HTTP_REQ_DONE) + { + ad_http_response(conn, 200, "text/html", "Hello World", 11); + return ad_http_is_keepalive_request(conn) ? AD_DONE : AD_CLOSE; + } + } + return AD_OK; +} + +int my_http_default_handler(short event, ad_conn_t *conn, void *userdata) +{ + if (event & AD_EVENT_READ) + { + if (ad_http_get_status(conn) == AD_HTTP_REQ_DONE) + { + ad_http_response(conn, 501, "text/html", "Not implemented", 15); + return AD_CLOSE; // Close connection. + } + } + return AD_OK; +} + +int main(int argc, char **argv) +{ + //SSL_load_error_strings(); + //SSL_library_init(); + ad_log_level(AD_LOG_DEBUG); + ad_server_t *server = ad_server_new(); + ad_server_set_option(server, "server.port", "8888"); + //ad_server_set_ssl_ctx(server, + // ad_server_ssl_ctx_create_simple("ssl.cert", "ssl.pkey")); + ad_server_register_hook(server, ad_http_handler, NULL); // HTTP Parser is also a hook. + ad_server_register_hook_on_method(server, "GET", my_http_get_handler, NULL); + ad_server_register_hook(server, my_http_default_handler, NULL); + return ad_server_start(server); +}