diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..478223e --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +cmake-build-debug +.idea +*.so +CMakeFiles/ +CMakeCache.txt +Makefile +cmake_install.cmake + +asynchronous +asynchronous-user_data +synchronous +synchronous-user_data +websockets diff --git a/CMakeLists.txt b/CMakeLists.txt index a271f88..4fb6a24 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,71 +1,55 @@ cmake_minimum_required(VERSION 3.2) project(binapi) -set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD 20) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -fsanitize=address") +find_package(Threads REQUIRED) +find_package(OpenSSL REQUIRED SSL Crypto) +find_package(ZLIB REQUIRED) -add_definitions( - -UNDEBUG - -DDTF_HEADER_ONLY -) +add_library(binapi SHARED + src/api.cpp + src/dtf.cpp + src/enums.cpp + src/errors.cpp + src/pairslist.cpp + src/reports.cpp + src/tools.cpp + src/types.cpp + src/websocket.cpp) -include_directories( - ./include -) +target_include_directories(binapi PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) -if (DEFINED ${BOOST_INCLUDE_DIR}) - include_directories( - ${BOOST_INCLUDE_DIR} - ) -endif() +target_compile_options(binapi PUBLIC + -pipe -Wall -Wextra + $<$:-g3 -Og -fno-inline -fstack-protector-all -fsanitize=address> + $<$:-O3 -s>) -set(BINAPI_HEADERS - binapi/api.hpp - binapi/flatjson.hpp - binapi/dtf.hpp - binapi/double_type.hpp - binapi/enums.hpp - binapi/errors.hpp - binapi/invoker.hpp - binapi/message.hpp - binapi/pairslist.hpp - binapi/reports.hpp - binapi/tools.hpp - binapi/types.hpp - binapi/websocket.hpp -) +target_link_options(binapi PUBLIC + $<$:-fsanitize=address>) -set(BINAPI_SOURCES - src/api.cpp - src/enums.cpp - src/errors.cpp - src/pairslist.cpp - src/reports.cpp - src/tools.cpp - src/types.cpp - src/websocket.cpp -) +target_link_libraries(binapi PUBLIC + ZLIB::ZLIB + OpenSSL::Crypto OpenSSL::SSL + ${BOOST_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT}) -add_executable( - ${PROJECT_NAME} - # - main.cpp - # - ${BINAPI_SOURCES} -) +target_include_directories(binapi PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) -if (DEFINED ${BOOST_LIB_DIR}) - target_link_libraries( - ${PROJECT_NAME} - -L${BOOST_LIB_DIR} - ) -endif() +add_executable(example_asynchronous examples/asynchronous/main.cpp) +target_link_libraries(example_asynchronous binapi) -target_link_libraries( - ${PROJECT_NAME} - z - crypto - ssl - pthread -) +add_executable(example_asynchronous-user_data examples/asynchronous-user_data/main.cpp) +target_link_libraries(example_asynchronous-user_data binapi) + +add_executable(example_synchronous examples/synchronous/main.cpp) +target_link_libraries(example_synchronous binapi) + +add_executable(example_synchronous-user_data examples/synchronous-user_data/main.cpp) +target_link_libraries(example_synchronous-user_data binapi) + +add_executable(example_websockets examples/websockets/main.cpp) +target_link_libraries(example_websockets binapi) + +add_executable(example_api main.cpp) +target_link_libraries(example_api binapi) diff --git a/examples/asynchronous-user_data/CMakeLists.txt b/examples/asynchronous-user_data/CMakeLists.txt deleted file mode 100644 index 3ab159e..0000000 --- a/examples/asynchronous-user_data/CMakeLists.txt +++ /dev/null @@ -1,70 +0,0 @@ -cmake_minimum_required(VERSION 3.2) -project(asynchronous-user_data) - -set(CMAKE_CXX_STANDARD 14) - -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") - -add_definitions( - -UNDEBUG - -DDTF_HEADER_ONLY -) - -include_directories( - ../../include -) - -if (DEFINED ${BOOST_INCLUDE_DIR}) - include_directories( - ${BOOST_INCLUDE_DIR} - ) -endif() - -set(BINAPI_HEADERS - binapi/errors.hpp - binapi/api.hpp - binapi/flatjson.hpp - binapi/dtf.hpp - binapi/double_type.hpp - binapi/invoker.hpp - binapi/message.hpp - binapi/pairslist.hpp - binapi/reports.hpp - binapi/tools.hpp - binapi/types.hpp - binapi/websocket.hpp -) - -set(BINAPI_SOURCES - ../../src/errors.cpp - ../../src/api.cpp - ../../src/enums.cpp - ../../src/pairslist.cpp - ../../src/reports.cpp - ../../src/tools.cpp - ../../src/types.cpp - ../../src/websocket.cpp -) - -add_executable( - ${PROJECT_NAME} - # - main.cpp - # - ${BINAPI_SOURCES} -) - -if (DEFINED ${BOOST_LIB_DIR}) - target_link_libraries( - ${PROJECT_NAME} - -L${BOOST_LIB_DIR} - ) -endif() - -target_link_libraries( - ${PROJECT_NAME} - z - crypto - ssl - pthread -) diff --git a/examples/asynchronous-user_data/main.cpp b/examples/asynchronous-user_data/main.cpp index ebf175a..2898f70 100644 --- a/examples/asynchronous-user_data/main.cpp +++ b/examples/asynchronous-user_data/main.cpp @@ -9,12 +9,12 @@ // Copyright (c) 2019-2021 niXman (github dot nixman dog pm.me). All rights reserved. // ---------------------------------------------------------------------------- -#include -#include +#include #include -#include +#include +#include int main(int argc, char **argv) { assert(argc == 3); diff --git a/examples/asynchronous/CMakeLists.txt b/examples/asynchronous/CMakeLists.txt deleted file mode 100644 index d761205..0000000 --- a/examples/asynchronous/CMakeLists.txt +++ /dev/null @@ -1,71 +0,0 @@ -cmake_minimum_required(VERSION 3.2) -project(asynchronous) - -set(CMAKE_CXX_STANDARD 14) - -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") - -add_definitions( - -UNDEBUG - -DDTF_HEADER_ONLY -) - -include_directories( - ../../include -) - -if (DEFINED ${BOOST_INCLUDE_DIR}) - include_directories( - ${BOOST_INCLUDE_DIR} - ) -endif() - -set(BINAPI_HEADERS - binapi/errors.hpp - binapi/api.hpp - binapi/flatjson.hpp - binapi/dtf.hpp - binapi/double_type.hpp - binapi/enums.hpp - binapi/invoker.hpp - binapi/message.hpp - binapi/pairslist.hpp - binapi/reports.hpp - binapi/tools.hpp - binapi/types.hpp - binapi/websocket.hpp -) - -set(BINAPI_SOURCES - ../../src/errors.cpp - ../../src/api.cpp - ../../src/enums.cpp - ../../src/pairslist.cpp - ../../src/reports.cpp - ../../src/tools.cpp - ../../src/types.cpp - ../../src/websocket.cpp -) - -add_executable( - ${PROJECT_NAME} - # - main.cpp - # - ${BINAPI_SOURCES} -) - -if (DEFINED ${BOOST_LIB_DIR}) - target_link_libraries( - ${PROJECT_NAME} - -L${BOOST_LIB_DIR} - ) -endif() - -target_link_libraries( - ${PROJECT_NAME} - z - crypto - ssl - pthread -) diff --git a/examples/asynchronous/main.cpp b/examples/asynchronous/main.cpp index 964602e..d185564 100644 --- a/examples/asynchronous/main.cpp +++ b/examples/asynchronous/main.cpp @@ -9,11 +9,11 @@ // Copyright (c) 2019-2021 niXman (github dot nixman dog pm.me). All rights reserved. // ---------------------------------------------------------------------------- -#include +#include #include -#include +#include int main() { boost::asio::io_context ioctx; diff --git a/examples/synchronous-user_data/CMakeLists.txt b/examples/synchronous-user_data/CMakeLists.txt deleted file mode 100644 index b5f91be..0000000 --- a/examples/synchronous-user_data/CMakeLists.txt +++ /dev/null @@ -1,71 +0,0 @@ -cmake_minimum_required(VERSION 3.2) -project(synchronous-user_data) - -set(CMAKE_CXX_STANDARD 14) - -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") - -add_definitions( - -UNDEBUG - -DDTF_HEADER_ONLY -) - -include_directories( - ../../include -) - -if (DEFINED ${BOOST_INCLUDE_DIR}) - include_directories( - ${BOOST_INCLUDE_DIR} - ) -endif() - -set(BINAPI_HEADERS - binapi/errors.hpp - binapi/api.hpp - binapi/flatjson.hpp - binapi/dtf.hpp - binapi/double_type.hpp - binapi/enums.hpp - binapi/invoker.hpp - binapi/message.hpp - binapi/pairslist.hpp - binapi/reports.hpp - binapi/tools.hpp - binapi/types.hpp - binapi/websocket.hpp -) - -set(BINAPI_SOURCES - ../../src/errors.cpp - ../../src/api.cpp - ../../src/enums.cpp - ../../src/pairslist.cpp - ../../src/reports.cpp - ../../src/tools.cpp - ../../src/types.cpp - ../../src/websocket.cpp -) - -add_executable( - ${PROJECT_NAME} - # - main.cpp - # - ${BINAPI_SOURCES} -) - -if (DEFINED ${BOOST_LIB_DIR}) - target_link_libraries( - ${PROJECT_NAME} - -L${BOOST_LIB_DIR} - ) -endif() - -target_link_libraries( - ${PROJECT_NAME} - z - crypto - ssl - pthread -) diff --git a/examples/synchronous-user_data/main.cpp b/examples/synchronous-user_data/main.cpp index 2486445..ae954d0 100644 --- a/examples/synchronous-user_data/main.cpp +++ b/examples/synchronous-user_data/main.cpp @@ -9,11 +9,11 @@ // Copyright (c) 2019-2021 niXman (github dot nixman dog pm.me). All rights reserved. // ---------------------------------------------------------------------------- -#include +#include #include -#include +#include int main(int argc, char **argv) { assert(argc == 3); diff --git a/examples/synchronous/CMakeLists.txt b/examples/synchronous/CMakeLists.txt deleted file mode 100644 index 1ff4c8b..0000000 --- a/examples/synchronous/CMakeLists.txt +++ /dev/null @@ -1,71 +0,0 @@ -cmake_minimum_required(VERSION 3.2) -project(synchronous) - -set(CMAKE_CXX_STANDARD 14) - -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") - -add_definitions( - -UNDEBUG - -DDTF_HEADER_ONLY -) - -include_directories( - ../../include -) - -if (DEFINED ${BOOST_INCLUDE_DIR}) - include_directories( - ${BOOST_INCLUDE_DIR} - ) -endif() - -set(BINAPI_HEADERS - binapi/errors.hpp - binapi/api.hpp - binapi/flatjson.hpp - binapi/dtf.hpp - binapi/double_type.hpp - binapi/enums.hpp - binapi/invoker.hpp - binapi/message.hpp - binapi/pairslist.hpp - binapi/reports.hpp - binapi/tools.hpp - binapi/types.hpp - binapi/websocket.hpp -) - -set(BINAPI_SOURCES - ../../src/errors.cpp - ../../src/api.cpp - ../../src/enums.cpp - ../../src/pairslist.cpp - ../../src/reports.cpp - ../../src/tools.cpp - ../../src/types.cpp - ../../src/websocket.cpp -) - -add_executable( - ${PROJECT_NAME} - # - main.cpp - # - ${BINAPI_SOURCES} -) - -if (DEFINED ${BOOST_LIB_DIR}) - target_link_libraries( - ${PROJECT_NAME} - -L${BOOST_LIB_DIR} - ) -endif() - -target_link_libraries( - ${PROJECT_NAME} - z - crypto - ssl - pthread -) diff --git a/examples/synchronous/main.cpp b/examples/synchronous/main.cpp index c132eea..b9b92c0 100644 --- a/examples/synchronous/main.cpp +++ b/examples/synchronous/main.cpp @@ -9,11 +9,11 @@ // Copyright (c) 2019-2021 niXman (github dot nixman dog pm.me). All rights reserved. // ---------------------------------------------------------------------------- -#include +#include #include -#include +#include int main() { boost::asio::io_context ioctx; diff --git a/examples/websockets/CMakeLists.txt b/examples/websockets/CMakeLists.txt deleted file mode 100644 index 3ea74c1..0000000 --- a/examples/websockets/CMakeLists.txt +++ /dev/null @@ -1,71 +0,0 @@ -cmake_minimum_required(VERSION 3.2) -project(websockets) - -set(CMAKE_CXX_STANDARD 14) - -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") - -add_definitions( - -UNDEBUG - -DDTF_HEADER_ONLY -) - -include_directories( - ../../include -) - -if (DEFINED ${BOOST_INCLUDE_DIR}) - include_directories( - ${BOOST_INCLUDE_DIR} - ) -endif() - -set(BINAPI_HEADERS - binapi/api.hpp - binapi/flatjson.hpp - binapi/dtf.hpp - binapi/double_type.hpp - binapi/enums.hpp - binapi/errors.hpp - binapi/invoker.hpp - binapi/message.hpp - binapi/pairslist.hpp - binapi/reports.hpp - binapi/tools.hpp - binapi/types.hpp - binapi/websocket.hpp -) - -set(BINAPI_SOURCES - ../../src/api.cpp - ../../src/enums.cpp - ../../src/errors.cpp - ../../src/pairslist.cpp - ../../src/reports.cpp - ../../src/tools.cpp - ../../src/types.cpp - ../../src/websocket.cpp -) - -add_executable( - ${PROJECT_NAME} - # - main.cpp - # - ${BINAPI_SOURCES} -) - -if (DEFINED ${BOOST_LIB_DIR}) - target_link_libraries( - ${PROJECT_NAME} - -L${BOOST_LIB_DIR} - ) -endif() - -target_link_libraries( - ${PROJECT_NAME} - z - crypto - ssl - pthread -) diff --git a/examples/websockets/main.cpp b/examples/websockets/main.cpp index d7ff512..2700abf 100644 --- a/examples/websockets/main.cpp +++ b/examples/websockets/main.cpp @@ -9,13 +9,13 @@ // Copyright (c) 2019-2021 niXman (github dot nixman dog pm.me). All rights reserved. // ---------------------------------------------------------------------------- -#include -#include +#include #include #include -#include +#include +#include int main() { boost::asio::io_context ioctx; diff --git a/include/binapi/api.hpp b/include/binapi/api.hpp index e5d0549..820da0e 100644 --- a/include/binapi/api.hpp +++ b/include/binapi/api.hpp @@ -12,12 +12,12 @@ #ifndef __binapi__api_hpp #define __binapi__api_hpp -#include "types.hpp" -#include "enums.hpp" - #include #include +#include +#include + namespace boost { namespace asio { diff --git a/include/binapi/dtf.hpp b/include/binapi/dtf.hpp index 65dd4a2..c455949 100644 --- a/include/binapi/dtf.hpp +++ b/include/binapi/dtf.hpp @@ -95,8 +95,4 @@ std::size_t dt_str_flags(const char *buf, std::size_t n); } // ns dtf -#ifdef DTF_HEADER_ONLY -# include "dtf.cpp" -#endif // DTF_HEADER_ONLY - #endif // __dtf__dtf_hpp diff --git a/include/binapi/invoker.hpp b/include/binapi/invoker.hpp index 9a0af21..2bc99bf 100644 --- a/include/binapi/invoker.hpp +++ b/include/binapi/invoker.hpp @@ -17,9 +17,9 @@ #include #include -#include "message.hpp" -#include "flatjson.hpp" -#include "errors.hpp" +#include +#include +#include namespace binapi { namespace detail { diff --git a/include/binapi/tools.hpp b/include/binapi/tools.hpp index cfee401..76b943c 100644 --- a/include/binapi/tools.hpp +++ b/include/binapi/tools.hpp @@ -12,11 +12,11 @@ #ifndef __binapi__tools_hpp #define __binapi__tools_hpp -#include "double_type.hpp" - #include #include +#include + namespace binapi { /*************************************************************************************************/ diff --git a/include/binapi/types.hpp b/include/binapi/types.hpp index 9c81769..2df575d 100644 --- a/include/binapi/types.hpp +++ b/include/binapi/types.hpp @@ -12,17 +12,17 @@ #ifndef __binapi__types_hpp #define __binapi__types_hpp -#include "double_type.hpp" -#include "enums.hpp" - -#include - #include #include #include #include #include +#include + +#include +#include + // forward namespace flatjson { struct fjson; diff --git a/include/binapi/websocket.hpp b/include/binapi/websocket.hpp index e6c66c0..7cd229b 100644 --- a/include/binapi/websocket.hpp +++ b/include/binapi/websocket.hpp @@ -12,11 +12,11 @@ #ifndef __binapi__websocket_hpp #define __binapi__websocket_hpp -#include "enums.hpp" - #include #include +#include + namespace boost { namespace asio { class io_context; diff --git a/main.cpp b/main.cpp index e9a63fd..d2593ca 100644 --- a/main.cpp +++ b/main.cpp @@ -9,18 +9,18 @@ // Copyright (c) 2019-2021 niXman (github dot nixman dog pm.me). All rights reserved. // ---------------------------------------------------------------------------- -#include "binapi/websocket.hpp" -#include "binapi/api.hpp" -#include "binapi/pairslist.hpp" -#include "binapi/reports.hpp" -#include "binapi/flatjson.hpp" +#include +#include #include #include -#include -#include #include +#include +#include +#include +#include +#include /*************************************************************************************************/ diff --git a/src/api.cpp b/src/api.cpp index e31c6c9..2673422 100644 --- a/src/api.cpp +++ b/src/api.cpp @@ -9,9 +9,12 @@ // Copyright (c) 2019-2021 niXman (github dot nixman dog pm.me). All rights reserved. // ---------------------------------------------------------------------------- -#include -#include -#include +#include "binapi/api.hpp" + +#include +#include +#include +#include #include #include @@ -25,14 +28,13 @@ #include #include -#include -#include -#include -#include - #include #include + #include +#include +#include + namespace binapi { namespace rest { diff --git a/include/binapi/dtf.cpp b/src/dtf.cpp similarity index 99% rename from include/binapi/dtf.cpp rename to src/dtf.cpp index 820fe58..5d5b021 100644 --- a/include/binapi/dtf.cpp +++ b/src/dtf.cpp @@ -24,7 +24,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "dtf.hpp" +#include "binapi/dtf.hpp" #include #include diff --git a/src/enums.cpp b/src/enums.cpp index 1537849..3b65782 100644 --- a/src/enums.cpp +++ b/src/enums.cpp @@ -9,11 +9,12 @@ // Copyright (c) 2019-2021 niXman (github dot nixman dog pm.me). All rights reserved. // ---------------------------------------------------------------------------- -#include -#include +#include "binapi/enums.hpp" #include +#include + namespace binapi { /*************************************************************************************************/ diff --git a/src/errors.cpp b/src/errors.cpp index 45e22e9..56c59f9 100644 --- a/src/errors.cpp +++ b/src/errors.cpp @@ -9,7 +9,8 @@ // Copyright (c) 2019-2021 niXman (github dot nixman dog pm.me). All rights reserved. // ---------------------------------------------------------------------------- -#include +#include "binapi/errors.hpp" + #include namespace binapi { diff --git a/src/pairslist.cpp b/src/pairslist.cpp index 36b0740..2931d57 100644 --- a/src/pairslist.cpp +++ b/src/pairslist.cpp @@ -9,13 +9,14 @@ // Copyright (c) 2019-2021 niXman (github dot nixman dog pm.me). All rights reserved. // ---------------------------------------------------------------------------- -#include -#include -#include +#include "binapi/pairslist.hpp" + +#include #include -#include +#include +#include namespace binapi { diff --git a/src/reports.cpp b/src/reports.cpp index 404aa94..60c5581 100644 --- a/src/reports.cpp +++ b/src/reports.cpp @@ -9,17 +9,18 @@ // Copyright (c) 2019-2021 niXman (github dot nixman dog pm.me). All rights reserved. // ---------------------------------------------------------------------------- -#include +#include "binapi/reports.hpp" + +#include // TODO: comment out + +#include + #include #include #include #include #include -#include - -#include // TODO: comment out - namespace binapi { /*************************************************************************************************/ diff --git a/src/tools.cpp b/src/tools.cpp index b879a28..a167d2b 100644 --- a/src/tools.cpp +++ b/src/tools.cpp @@ -9,14 +9,15 @@ // Copyright (c) 2019-2021 niXman (github dot nixman dog pm.me). All rights reserved. // ---------------------------------------------------------------------------- -#include -#include +#include "binapi/tools.hpp" #include #include #include #include +#include + namespace binapi { /*************************************************************************************************/ diff --git a/src/types.cpp b/src/types.cpp index af8fbf3..bd30bad 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -9,14 +9,15 @@ // Copyright (c) 2019-2021 niXman (github dot nixman dog pm.me). All rights reserved. // ---------------------------------------------------------------------------- -#include -#include -#include +#include "binapi/types.hpp" #include #include +#include +#include + //#include // TODO: comment out namespace binapi { diff --git a/src/websocket.cpp b/src/websocket.cpp index a003818..3a539c7 100644 --- a/src/websocket.cpp +++ b/src/websocket.cpp @@ -9,12 +9,12 @@ // Copyright (c) 2019-2021 niXman (github dot nixman dog pm.me). All rights reserved. // ---------------------------------------------------------------------------- -#include -#include -#include -#include -#include -#include +#include "binapi/websocket.hpp" + +#include +#include +#include +//#include // TODO: comment out #include #include @@ -30,11 +30,12 @@ #include -#include -#include -#include +#include +#include +#include +#include +#include -//#include // TODO: comment out #define __BINAPI_CB_ON_ERROR(cb, ec) \ cb(__FILE__ "(" BOOST_PP_STRINGIZE(__LINE__) ")", ec.value(), ec.message(), nullptr, 0);