From 445e7fc600e1e0a7073ffdf76cd07c6e60c78ba3 Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Thu, 9 Jan 2025 03:22:54 +0200 Subject: [PATCH 1/4] fix(user_id): remove length limit from user id Remove the `user_id` length restriction for dynamically allocated memory for it. build(CMakeLists): add `try_compile` configuration Configure `try_compile` when building static library. --- CMakeLists.txt | 912 ++++++++++++++++++----------------- core/Makefile | 2 +- core/pubnub_ccore_pubsub.c | 143 +++--- core/pubnub_core_unit_test.c | 14 +- 4 files changed, 556 insertions(+), 515 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ed79ce1..159dad87 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,34 +1,42 @@ # CMakeLists.txt for the C-core library of Pubnub. cmake_minimum_required(VERSION 3.12) +# Setup `try_compile` if required. +if (DEFINED SHARED_LIB) + # Setup try_compile to build for static library. + if (NOT ${SHARED_LIB}) + set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY") + endif () +endif () + # Project name and version for casual builds # For ESP32 builds it is considered as a IDF component -if(NOT ESP_PLATFORM) +if (NOT ESP_PLATFORM) project(pubnub VERSION 4.10.0) -endif() +endif () message(STATUS Preparing\ ${PROJECT_NAME}\ version\ ${PROJECT_VERSION}) # Function to convert between "ON"/"OFF" and 1/0 function(num_option name description default) option(${name} ${description} ${default}) - if(${name}) + if (${name}) message(STATUS "[*] ${name}") set(${name} 1 PARENT_SCOPE) - else() + else () message(STATUS "[ ] ${name}") set(${name} 0 PARENT_SCOPE) - endif() + endif () endfunction() # Function to log a option and its value function(log_option name description default) option(${name} ${description} ${default}) - if(${name}) + if (${name}) message(STATUS "[*] ${name}") - else() + else () message(STATUS "[ ] ${name}") - endif() + endif () endfunction() # Function to log a set and its value @@ -50,9 +58,9 @@ log_option(ASAN "Use Address sanitizer" OFF) if (WITH_CPP) set(DEFAULT_USE_CALLBACK_API ON) -else() +else () set(DEFAULT_USE_CALLBACK_API OFF) -endif() +endif () log_option(USE_CPP11 "Use C++11 [WITH_CPP=ON needed]" OFF) log_option(UNIT_TEST "Build and run unit tests" OFF) @@ -60,7 +68,7 @@ num_option(ONLY_PUBSUB_API "Only pubsub API" OFF) num_option(USE_PROXY "Use proxy" ON) num_option(USE_GZIP_COMPRESSION "Use gzip compression" ON) num_option(RECEIVE_GZIP_RESPONSE "Use gzip decompression" ON) -num_option(USE_RETRY_CONFIGURATION "Use requests retry" OFF) +num_option(USE_REDidONFIGURATION "Use requests retry" OFF) num_option(USE_SUBSCRIBE_V2 "Use subscribe v2" ON) num_option(USE_SUBSCRIBE_EVENT_ENGINE "Use Subscribe Event Engine [USE_SUBSCRIBE_V2=ON needed]" OFF) num_option(USE_ADVANCED_HISTORY "Use advanced history" ON) @@ -86,7 +94,7 @@ log_set(CUSTOM_BOOL_TYPE "" "Type of bool for platform differences. Select whate if (${OPENSSL} AND ${MBEDTLS}) message(FATAL_ERROR "You can't use both OpenSSL and mbedTLS at the same time!") -endif() +endif () # Flags configuration @@ -111,15 +119,15 @@ set(FLAGS "\ -D PUBNUB_CRYPTO_API=${USE_CRYPTO_API} \ -D PUBNUB_RAND_INIT_VECTOR=${USE_LEGACY_CRYPTO_RANDOM_IV} \ -D PUBNUB_MBEDTLS=${MBEDTLS}") - + #Required on windows with Event Engine, so only winsock2 is used (otherwise it tries to use winsock and winsock2 and there are redefinition errors) -if(WIN32 OR WIN64 OR MSVC) -set(FLAGS "\ +if (WIN32 OR WIN64 OR MSVC) + set(FLAGS "\ ${FLAGS} \ -D _WINSOCKAPI_") -endif() +endif () + - set(LDLIBS) set(OS_SOURCEFILES) @@ -129,7 +137,7 @@ if (${USE_CALLBACK_API}) -D PUBNUB_SET_DNS_SERVERS=${USE_SET_DNS_SERVERS} \ -D PUBNUB_USE_IPV6=${USE_IPV6} \ -D PUBNUB_CALLBACK_API") -endif() +endif () if (${ASAN}) set(FLAGS "\ @@ -138,212 +146,212 @@ if (${ASAN}) set(LDLIBS "\ ${LDLIBS} \ -fsanitize=address") -endif() +endif () set(CMAKE_C_FLAGS "\ ${FLAGS} \ ${CMAKE_C_FLAGS}") -if(${WITH_CPP}) +if (${WITH_CPP}) set(CMAKE_CXX_FLAGS "\ ${FLAGS} \ -D PUBNUB_USE_EXTERN_C=${USE_EXTERN_API} \ ${CMAKE_CXX_FLAGS}") - if(${USE_CPP11}) + if (${USE_CPP11}) set(CMAKE_CXX_FLAGS "\ ${CMAKE_CXX_FLAGS} \ -std=c++11") - endif() -endif() + endif () +endif () -if(NOT ${CUSTOM_BOOL_TYPE} STREQUAL "") +if (NOT ${CUSTOM_BOOL_TYPE} STREQUAL "") message(STATUS "Using custom bool type: ${CUSTOM_BOOL_TYPE}") set(FLAGS "\ ${FLAGS} \ -D PUBNUB_BOOL_TYPE=${CUSTOM_BOOL_TYPE}") -endif() - -set(CORE_SOURCEFILES - ${CMAKE_CURRENT_LIST_DIR}/core/pbcc_set_state.c - ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_pubsubapi.c - ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_coreapi.c - ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_coreapi_ex.c - ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_ccore_pubsub.c - ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_ccore.c - ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_netcore.c - ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_blocking_io.c - ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_timers.c - ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_json_parse.c - ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_helper.c - ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_generate_uuid_v3_md5.c - ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_free_with_timeout_std.c - ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_url_encode.c) +endif () + +set(CORE_SOURCEFILES + ${CMAKE_CURRENT_LIST_DIR}/core/pbcc_set_state.c + ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_pubsubapi.c + ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_coreapi.c + ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_coreapi_ex.c + ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_ccore_pubsub.c + ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_ccore.c + ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_netcore.c + ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_blocking_io.c + ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_timers.c + ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_json_parse.c + ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_helper.c + ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_generate_uuid_v3_md5.c + ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_free_with_timeout_std.c + ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_url_encode.c) set(LIB_SOURCEFILES - ${CMAKE_CURRENT_LIST_DIR}/lib/sockets/pbpal_handle_socket_error.c - ${CMAKE_CURRENT_LIST_DIR}/lib/base64/pbbase64.c - ${CMAKE_CURRENT_LIST_DIR}/lib/pb_strnlen_s.c - ${CMAKE_CURRENT_LIST_DIR}/lib/pb_strncasecmp.c - ${CMAKE_CURRENT_LIST_DIR}/lib/pubnub_dns_codec.c) + ${CMAKE_CURRENT_LIST_DIR}/lib/sockets/pbpal_handle_socket_error.c + ${CMAKE_CURRENT_LIST_DIR}/lib/base64/pbbase64.c + ${CMAKE_CURRENT_LIST_DIR}/lib/pb_strnlen_s.c + ${CMAKE_CURRENT_LIST_DIR}/lib/pb_strncasecmp.c + ${CMAKE_CURRENT_LIST_DIR}/lib/pubnub_dns_codec.c) -if(UNIX OR WIN32 OR WIN64 OR MSVC) +if (UNIX OR WIN32 OR WIN64 OR MSVC) set(CORE_SOURCEFILES - ${CORE_SOURCEFILES} - ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_alloc_std.c - ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_generate_uuid.c - ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_assert_std.c) + ${CORE_SOURCEFILES} + ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_alloc_std.c + ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_generate_uuid.c + ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_assert_std.c) set(LIB_SOURCEFILES - ${LIB_SOURCEFILES} - ${CMAKE_CURRENT_LIST_DIR}/lib/sockets/pbpal_adns_sockets.c - ${CMAKE_CURRENT_LIST_DIR}/lib/sockets/pbpal_resolv_and_connect_sockets.c) -else() + ${LIB_SOURCEFILES} + ${CMAKE_CURRENT_LIST_DIR}/lib/sockets/pbpal_adns_sockets.c + ${CMAKE_CURRENT_LIST_DIR}/lib/sockets/pbpal_resolv_and_connect_sockets.c) +else () set(CORE_SOURCEFILES - ${CORE_SOURCEFILES} - ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_alloc_std.c) -endif() + ${CORE_SOURCEFILES} + ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_alloc_std.c) +endif () -if(NOT ${OPENSSL}) +if (NOT ${OPENSSL}) set(LIB_SOURCEFILES - ${LIB_SOURCEFILES} - ${CMAKE_CURRENT_LIST_DIR}/lib/md5/md5.c) -endif() + ${LIB_SOURCEFILES} + ${CMAKE_CURRENT_LIST_DIR}/lib/md5/md5.c) +endif () -if(UNIX) +if (UNIX) message(STATUS "Using POSIX setup") set(LDLIBS "-lpthread ${LDLIBS}") set(OS_SOURCEFILES - ${CMAKE_CURRENT_LIST_DIR}/posix/posix_socket_blocking_io.c - ${CMAKE_CURRENT_LIST_DIR}/posix/pubnub_version_posix.c - ${CMAKE_CURRENT_LIST_DIR}/posix/pubnub_generate_uuid_posix.c - ${CMAKE_CURRENT_LIST_DIR}/posix/msstopwatch_monotonic_clock.c - ${CMAKE_CURRENT_LIST_DIR}/posix/pbtimespec_elapsed_ms.c - ${CMAKE_CURRENT_LIST_DIR}/posix/pb_sleep_ms.c) - - if(APPLE) + ${CMAKE_CURRENT_LIST_DIR}/posix/posix_socket_blocking_io.c + ${CMAKE_CURRENT_LIST_DIR}/posix/pubnub_version_posix.c + ${CMAKE_CURRENT_LIST_DIR}/posix/pubnub_generate_uuid_posix.c + ${CMAKE_CURRENT_LIST_DIR}/posix/msstopwatch_monotonic_clock.c + ${CMAKE_CURRENT_LIST_DIR}/posix/pbtimespec_elapsed_ms.c + ${CMAKE_CURRENT_LIST_DIR}/posix/pb_sleep_ms.c) + + if (APPLE) set(OS_SOURCEFILES ${OS_SOURCEFILES} ${CMAKE_CURRENT_LIST_DIR}/posix/monotonic_clock_get_time_darwin.c) - else() + else () set(OS_SOURCEFILES ${OS_SOURCEFILES} ${CMAKE_CURRENT_LIST_DIR}/posix/monotonic_clock_get_time_posix.c) - endif() -elseif(WIN32 OR WIN64 OR MSVC) + endif () +elseif (WIN32 OR WIN64 OR MSVC) message(STATUS "Using Windows setup") set(LDLIBS "ws2_32.lib IPHlpAPI.lib rpcrt4.lib") set(OS_SOURCEFILES - ${CMAKE_CURRENT_LIST_DIR}/windows/windows_socket_blocking_io.c - ${CMAKE_CURRENT_LIST_DIR}/windows/pbtimespec_elapsed_ms.c - ${CMAKE_CURRENT_LIST_DIR}/windows/pubnub_version_windows.c - ${CMAKE_CURRENT_LIST_DIR}/windows/pubnub_generate_uuid_windows.c - ${CMAKE_CURRENT_LIST_DIR}/windows/pbpal_windows_blocking_io.c - ${CMAKE_CURRENT_LIST_DIR}/windows/msstopwatch_windows.c - ${CMAKE_CURRENT_LIST_DIR}/windows/pb_sleep_ms.c - ${CMAKE_CURRENT_LIST_DIR}/windows/pbauto_heartbeat_init_windows.c) -else() + ${CMAKE_CURRENT_LIST_DIR}/windows/windows_socket_blocking_io.c + ${CMAKE_CURRENT_LIST_DIR}/windows/pbtimespec_elapsed_ms.c + ${CMAKE_CURRENT_LIST_DIR}/windows/pubnub_version_windows.c + ${CMAKE_CURRENT_LIST_DIR}/windows/pubnub_generate_uuid_windows.c + ${CMAKE_CURRENT_LIST_DIR}/windows/pbpal_windows_blocking_io.c + ${CMAKE_CURRENT_LIST_DIR}/windows/msstopwatch_windows.c + ${CMAKE_CURRENT_LIST_DIR}/windows/pb_sleep_ms.c + ${CMAKE_CURRENT_LIST_DIR}/windows/pbauto_heartbeat_init_windows.c) +else () message(STATUS "Using FreeRTOS setup") set(OS_SOURCEFILES - ${CMAKE_CURRENT_LIST_DIR}/freertos/pbpal_freertos_blocking_io.c - ${CMAKE_CURRENT_LIST_DIR}/freertos/pbpal_resolv_and_connect_freertos_tcp.c - ${CMAKE_CURRENT_LIST_DIR}/freertos/pubnub_assert_freertos.c - ${CMAKE_CURRENT_LIST_DIR}/freertos/pubnub_generate_uuid_freertos.c - ${CMAKE_CURRENT_LIST_DIR}/freertos/pubnub_version_freertos.c) - if(ESP_PLATFORM) + ${CMAKE_CURRENT_LIST_DIR}/freertos/pbpal_freertos_blocking_io.c + ${CMAKE_CURRENT_LIST_DIR}/freertos/pbpal_resolv_and_connect_freertos_tcp.c + ${CMAKE_CURRENT_LIST_DIR}/freertos/pubnub_assert_freertos.c + ${CMAKE_CURRENT_LIST_DIR}/freertos/pubnub_generate_uuid_freertos.c + ${CMAKE_CURRENT_LIST_DIR}/freertos/pubnub_version_freertos.c) + if (ESP_PLATFORM) set(OS_SOURCEFILES ${OS_SOURCEFILES} - ${CMAKE_CURRENT_LIST_DIR}/freertos/msstopwatch_esp32.c - ${CMAKE_CURRENT_LIST_DIR}/freertos/pbtimespec_elapsed_ms_esp32.c) - endif() -endif() + ${CMAKE_CURRENT_LIST_DIR}/freertos/msstopwatch_esp32.c + ${CMAKE_CURRENT_LIST_DIR}/freertos/pbtimespec_elapsed_ms_esp32.c) + endif () +endif () set(INTF_SOURCEFILES) -if(${USE_CALLBACK_API}) +if (${USE_CALLBACK_API}) message(STATUS "Using callback API") set(CORE_SOURCEFILES - ${CORE_SOURCEFILES} - ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_memory_block.c - ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_dns_servers.c) + ${CORE_SOURCEFILES} + ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_memory_block.c + ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_dns_servers.c) set(INTF_SOURCEFILES - ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_timer_list.c - ${CMAKE_CURRENT_LIST_DIR}/lib/pubnub_parse_ipv4_addr.c - ${CMAKE_CURRENT_LIST_DIR}/lib/pubnub_parse_ipv6_addr.c - ${CMAKE_CURRENT_LIST_DIR}/lib/sockets/pbpal_ntf_callback_poller_poll.c - ${CMAKE_CURRENT_LIST_DIR}/core/pbpal_ntf_callback_queue.c - ${CMAKE_CURRENT_LIST_DIR}/core/pbpal_ntf_callback_handle_timer_list.c - ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_callback_subscribe_loop.c - ${CMAKE_CURRENT_LIST_DIR}/core/pbpal_ntf_callback_admin.c - ${CMAKE_CURRENT_LIST_DIR}/lib/sockets/pbpal_adns_sockets.c - ${INTF_SOURCEFILES}) + ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_timer_list.c + ${CMAKE_CURRENT_LIST_DIR}/lib/pubnub_parse_ipv4_addr.c + ${CMAKE_CURRENT_LIST_DIR}/lib/pubnub_parse_ipv6_addr.c + ${CMAKE_CURRENT_LIST_DIR}/lib/sockets/pbpal_ntf_callback_poller_poll.c + ${CMAKE_CURRENT_LIST_DIR}/core/pbpal_ntf_callback_queue.c + ${CMAKE_CURRENT_LIST_DIR}/core/pbpal_ntf_callback_handle_timer_list.c + ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_callback_subscribe_loop.c + ${CMAKE_CURRENT_LIST_DIR}/core/pbpal_ntf_callback_admin.c + ${CMAKE_CURRENT_LIST_DIR}/lib/sockets/pbpal_adns_sockets.c + ${INTF_SOURCEFILES}) if (UNIX) set(INTF_SOURCEFILES - ${INTF_SOURCEFILES} - ${CMAKE_CURRENT_LIST_DIR}/posix/pubnub_dns_system_servers.c - ${CMAKE_CURRENT_LIST_DIR}/posix/pubnub_ntf_callback_posix.c - ${CMAKE_CURRENT_LIST_DIR}/posix/pubnub_get_native_socket.c) - elseif(WIN32 OR WIN64 OR MSVC) - set(INTF_SOURCEFILES - ${INTF_SOURCEFILES} - ${CMAKE_CURRENT_LIST_DIR}/windows/pubnub_ntf_callback_windows.c - ${CMAKE_CURRENT_LIST_DIR}/windows/pubnub_dns_system_servers.c - ${CMAKE_CURRENT_LIST_DIR}/windows/pubnub_get_native_socket.c) - endif() -else() + ${INTF_SOURCEFILES} + ${CMAKE_CURRENT_LIST_DIR}/posix/pubnub_dns_system_servers.c + ${CMAKE_CURRENT_LIST_DIR}/posix/pubnub_ntf_callback_posix.c + ${CMAKE_CURRENT_LIST_DIR}/posix/pubnub_get_native_socket.c) + elseif (WIN32 OR WIN64 OR MSVC) + set(INTF_SOURCEFILES + ${INTF_SOURCEFILES} + ${CMAKE_CURRENT_LIST_DIR}/windows/pubnub_ntf_callback_windows.c + ${CMAKE_CURRENT_LIST_DIR}/windows/pubnub_dns_system_servers.c + ${CMAKE_CURRENT_LIST_DIR}/windows/pubnub_get_native_socket.c) + endif () +else () message(STATUS "Using sync API") set(INTF_SOURCEFILES - ${INTF_SOURCEFILES} - ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_ntf_sync.c - ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_sync_subscribe_loop.c - ${CMAKE_CURRENT_LIST_DIR}/core/srand_from_pubnub_time.c) -endif() + ${INTF_SOURCEFILES} + ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_ntf_sync.c + ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_sync_subscribe_loop.c + ${CMAKE_CURRENT_LIST_DIR}/core/srand_from_pubnub_time.c) +endif () set(FEATURE_SOURCEFILES) -if(${USE_PROXY}) +if (${USE_PROXY}) set(FEATURE_SOURCEFILES - ${FEATURE_SOURCEFILES} - ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_proxy.c - ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_proxy_core.c - ${CMAKE_CURRENT_LIST_DIR}/core/pbhttp_digest.c - ${CMAKE_CURRENT_LIST_DIR}/core/pbntlm_core.c - ${CMAKE_CURRENT_LIST_DIR}/core/pbntlm_packer_std.c) -endif() - -if(${USE_GZIP_COMPRESSION}) + ${FEATURE_SOURCEFILES} + ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_proxy.c + ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_proxy_core.c + ${CMAKE_CURRENT_LIST_DIR}/core/pbhttp_digest.c + ${CMAKE_CURRENT_LIST_DIR}/core/pbntlm_core.c + ${CMAKE_CURRENT_LIST_DIR}/core/pbntlm_packer_std.c) +endif () + +if (${USE_GZIP_COMPRESSION}) set(FEATURE_SOURCEFILES - ${FEATURE_SOURCEFILES} - ${CMAKE_CURRENT_LIST_DIR}/lib/miniz/miniz_tdef.c - ${CMAKE_CURRENT_LIST_DIR}/lib/miniz/miniz.c - ${CMAKE_CURRENT_LIST_DIR}/lib/pbcrc32.c - ${CMAKE_CURRENT_LIST_DIR}/core/pbgzip_compress.c) -endif() + ${FEATURE_SOURCEFILES} + ${CMAKE_CURRENT_LIST_DIR}/lib/miniz/miniz_tdef.c + ${CMAKE_CURRENT_LIST_DIR}/lib/miniz/miniz.c + ${CMAKE_CURRENT_LIST_DIR}/lib/pbcrc32.c + ${CMAKE_CURRENT_LIST_DIR}/core/pbgzip_compress.c) +endif () -if(${RECEIVE_GZIP_RESPONSE}) +if (${RECEIVE_GZIP_RESPONSE}) set(FEATURE_SOURCEFILES - ${FEATURE_SOURCEFILES} - ${CMAKE_CURRENT_LIST_DIR}/lib/miniz/miniz_tinfl.c - ${CMAKE_CURRENT_LIST_DIR}/core/pbgzip_decompress.c) -endif() + ${FEATURE_SOURCEFILES} + ${CMAKE_CURRENT_LIST_DIR}/lib/miniz/miniz_tinfl.c + ${CMAKE_CURRENT_LIST_DIR}/core/pbgzip_decompress.c) +endif () if (${USE_RETRY_CONFIGURATION}) set(FEATURE_SOURCEFILES - ${FEATURE_SOURCEFILES} - ${CMAKE_CURRENT_LIST_DIR}/core/pbcc_request_retry_timer.c - ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_retry_configuration.c) + ${FEATURE_SOURCEFILES} + ${CMAKE_CURRENT_LIST_DIR}/core/pbcc_request_retry_timer.c + ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_retry_configuration.c) endif () -if(${USE_SUBSCRIBE_V2}) -set(FEATURE_SOURCEFILES - ${FEATURE_SOURCEFILES} - ${CMAKE_CURRENT_LIST_DIR}/core/pbcc_subscribe_v2.c - ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_subscribe_v2.c) -endif() +if (${USE_SUBSCRIBE_V2}) + set(FEATURE_SOURCEFILES + ${FEATURE_SOURCEFILES} + ${CMAKE_CURRENT_LIST_DIR}/core/pbcc_subscribe_v2.c + ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_subscribe_v2.c) +endif () -if(${USE_SUBSCRIBE_EVENT_ENGINE}) +if (${USE_SUBSCRIBE_EVENT_ENGINE}) message(STATUS "Using subscribe event engine API") set(LIB_SOURCEFILES ${LIB_SOURCEFILES} @@ -364,96 +372,96 @@ if(${USE_SUBSCRIBE_EVENT_ENGINE}) ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_entities.c ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_subscribe_event_engine.c ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_subscribe_event_listener.c) -endif() +endif () -if(${USE_ADVANCED_HISTORY}) +if (${USE_ADVANCED_HISTORY}) set(FEATURE_SOURCEFILES - ${FEATURE_SOURCEFILES} - ${CMAKE_CURRENT_LIST_DIR}/core/pbcc_advanced_history.c - ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_advanced_history.c) -endif() - -if(${USE_OBJECTS_API}) - set(FEATURE_SOURCEFILES - ${FEATURE_SOURCEFILES} - ${CMAKE_CURRENT_LIST_DIR}/core/pbcc_objects_api.c - ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_objects_api.c) -endif() - -if(${USE_ACTIONS_API}) - set(FEATURE_SOURCEFILES - ${FEATURE_SOURCEFILES} - ${CMAKE_CURRENT_LIST_DIR}/core/pbcc_actions_api.c - ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_actions_api.c) -endif() - -if(${USE_AUTO_HEARTBEAT}) - set(FEATURE_SOURCEFILES - ${FEATURE_SOURCEFILES} - ${CMAKE_CURRENT_LIST_DIR}/core/pbauto_heartbeat.c - ${CMAKE_CURRENT_LIST_DIR}/lib/pbstr_remove_from_list.c) - if(NOT ${OPENSSL}) - if(UNIX) - set(FEATURE_SOURCEFILES - ${FEATURE_SOURCEFILES} - ${CMAKE_CURRENT_LIST_DIR}/posix/pbauto_heartbeat_init_posix.c) - elseif(WIN32 OR WIN64 OR MSVC) - set(FEATURE_SOURCEFILES - ${FEATURE_SOURCEFILES} - ${CMAKE_CURRENT_LIST_DIR}/windows/pbauto_heartbeat_init_windows.c) - endif() - endif() -endif() - -if(${USE_FETCH_HISTORY}) - set(FEATURE_SOURCEFILES - ${FEATURE_SOURCEFILES} - ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_fetch_history.c - ${CMAKE_CURRENT_LIST_DIR}/core/pbcc_fetch_history.c) -endif() - -if(${USE_GRANT_TOKEN_API}) - set(FEATURE_SOURCEFILES - ${FEATURE_SOURCEFILES} - ${CMAKE_CURRENT_LIST_DIR}/lib/cbor/cborparser.c - ${CMAKE_CURRENT_LIST_DIR}/lib/cbor/cborerrorstrings.c - ${CMAKE_CURRENT_LIST_DIR}/lib/cbor/cborparser_dup_string.c - ${CMAKE_CURRENT_LIST_DIR}/core/pbcc_grant_token_api.c - ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_grant_token_api.c) -endif() - -if(${USE_REVOKE_TOKEN_API}) - set(FEATURE_SOURCEFILES - ${FEATURE_SOURCEFILES} - ${CMAKE_CURRENT_LIST_DIR}/core/pbcc_revoke_token_api.c - ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_revoke_token_api.c) -endif() + ${FEATURE_SOURCEFILES} + ${CMAKE_CURRENT_LIST_DIR}/core/pbcc_advanced_history.c + ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_advanced_history.c) +endif () + +if (${USE_OBJECTS_API}) + set(FEATURE_SOURCEFILES + ${FEATURE_SOURCEFILES} + ${CMAKE_CURRENT_LIST_DIR}/core/pbcc_objects_api.c + ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_objects_api.c) +endif () + +if (${USE_ACTIONS_API}) + set(FEATURE_SOURCEFILES + ${FEATURE_SOURCEFILES} + ${CMAKE_CURRENT_LIST_DIR}/core/pbcc_actions_api.c + ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_actions_api.c) +endif () + +if (${USE_AUTO_HEARTBEAT}) + set(FEATURE_SOURCEFILES + ${FEATURE_SOURCEFILES} + ${CMAKE_CURRENT_LIST_DIR}/core/pbauto_heartbeat.c + ${CMAKE_CURRENT_LIST_DIR}/lib/pbstr_remove_from_list.c) + if (NOT ${OPENSSL}) + if (UNIX) + set(FEATURE_SOURCEFILES + ${FEATURE_SOURCEFILES} + ${CMAKE_CURRENT_LIST_DIR}/posix/pbauto_heartbeat_init_posix.c) + elseif (WIN32 OR WIN64 OR MSVC) + set(FEATURE_SOURCEFILES + ${FEATURE_SOURCEFILES} + ${CMAKE_CURRENT_LIST_DIR}/windows/pbauto_heartbeat_init_windows.c) + endif () + endif () +endif () + +if (${USE_FETCH_HISTORY}) + set(FEATURE_SOURCEFILES + ${FEATURE_SOURCEFILES} + ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_fetch_history.c + ${CMAKE_CURRENT_LIST_DIR}/core/pbcc_fetch_history.c) +endif () + +if (${USE_GRANT_TOKEN_API}) + set(FEATURE_SOURCEFILES + ${FEATURE_SOURCEFILES} + ${CMAKE_CURRENT_LIST_DIR}/lib/cbor/cborparser.c + ${CMAKE_CURRENT_LIST_DIR}/lib/cbor/cborerrorstrings.c + ${CMAKE_CURRENT_LIST_DIR}/lib/cbor/cborparser_dup_string.c + ${CMAKE_CURRENT_LIST_DIR}/core/pbcc_grant_token_api.c + ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_grant_token_api.c) +endif () + +if (${USE_REVOKE_TOKEN_API}) + set(FEATURE_SOURCEFILES + ${FEATURE_SOURCEFILES} + ${CMAKE_CURRENT_LIST_DIR}/core/pbcc_revoke_token_api.c + ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_revoke_token_api.c) +endif () set(SSL_LINK_LIBRARIES) -if(${OPENSSL}) +if (${OPENSSL}) message(STATUS "Using OpenSSL") - if("${OPENSSL_ROOT_DIR}" STREQUAL "") + if ("${OPENSSL_ROOT_DIR}" STREQUAL "") find_package(OpenSSL REQUIRED) set(SSL_LINK_LIBRARIES OpenSSL::SSL OpenSSL::Crypto) - else() + else () find_package(OpenSSL PATHS ${OPENSSL_ROOT_DIR}) - if(OpenSSl_FOUND) + if (OpenSSl_FOUND) set(SSL_LINK_LIBRARIES OpenSSL::SSL OpenSSL::Crypto) - else() + else () message(STATUS "Searching for custom OpenSSL library") - if(WIN32 OR WIN64 OR MSVC) + if (WIN32 OR WIN64 OR MSVC) find_library(OpenSSL REQUIRED NAMES libssl PATHS ${OPENSSL_ROOT_DIR}/${CUSTOM_OPENSSL_LIB_DIR} NO_DEFAULT_PATH) find_library(Crypto REQUIRED NAMES libcrypto PATHS ${OPENSSL_ROOT_DIR}/${CUSTOM_OPENSSL_LIB_DIR} NO_DEFAULT_PATH) - elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64") + elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64") # find_library doesn't work when building for Android architecture set(OpenSSL "${OPENSSL_ROOT_DIR}/${CUSTOM_OPENSSL_LIB_DIR}/libssl.a") set(Crypto "${OPENSSL_ROOT_DIR}/${CUSTOM_OPENSSL_LIB_DIR}/libcrypto.a") link_libraries(${OpenSSL} ${Crypto}) - else() + else () find_library(OpenSSL REQUIRED NAMES ssl PATHS ${OPENSSL_ROOT_DIR}/${CUSTOM_OPENSSL_LIB_DIR} NO_DEFAULT_PATH) find_library(Crypto REQUIRED NAMES crypto PATHS ${OPENSSL_ROOT_DIR}/${CUSTOM_OPENSSL_LIB_DIR} NO_DEFAULT_PATH) - endif() + endif () message(STATUS "Used libraries:") message(STATUS "-> ${OpenSSL}") @@ -466,168 +474,168 @@ if(${OPENSSL}) message(STATUS "-> ${OPENSSL_ROOT_DIR}/${CUSTOM_OPENSSL_INCLUDE_DIR}") message(STATUS "OpenSSL ready!") - endif() - endif() - - set(FEATURE_SOURCEFILES - ${OPENSSL_LIBRARIES} - ${FEATURE_SOURCEFILES}) - - set(LIB_SOURCEFILES - ${CMAKE_CURRENT_LIST_DIR}/lib/base64/pbbase64.c - ${LIB_SOURCEFILES}) - - set(FEATURE_SOURCEFILES - ${CMAKE_CURRENT_LIST_DIR}/openssl/pbpal_openssl.c - ${CMAKE_CURRENT_LIST_DIR}/openssl/pbpal_connect_openssl.c - ${CMAKE_CURRENT_LIST_DIR}/openssl/pbpal_openssl_blocking_io.c - ${FEATURE_SOURCEFILES}) - - if(UNIX) - set(FEATURE_SOURCEFILES - ${CMAKE_CURRENT_LIST_DIR}/posix/pbauto_heartbeat_init_posix.c + endif () + endif () + + set(FEATURE_SOURCEFILES + ${OPENSSL_LIBRARIES} ${FEATURE_SOURCEFILES}) - else() - set(FEATURE_SOURCEFILES - ${CMAKE_CURRENT_LIST_DIR}/windows/pbauto_heartbeat_init_windows.c + + set(LIB_SOURCEFILES + ${CMAKE_CURRENT_LIST_DIR}/lib/base64/pbbase64.c + ${LIB_SOURCEFILES}) + + set(FEATURE_SOURCEFILES + ${CMAKE_CURRENT_LIST_DIR}/openssl/pbpal_openssl.c + ${CMAKE_CURRENT_LIST_DIR}/openssl/pbpal_connect_openssl.c + ${CMAKE_CURRENT_LIST_DIR}/openssl/pbpal_openssl_blocking_io.c ${FEATURE_SOURCEFILES}) - endif() - set(LDLIBS ${LDLIBS}) + if (UNIX) + set(FEATURE_SOURCEFILES + ${CMAKE_CURRENT_LIST_DIR}/posix/pbauto_heartbeat_init_posix.c + ${FEATURE_SOURCEFILES}) + else () + set(FEATURE_SOURCEFILES + ${CMAKE_CURRENT_LIST_DIR}/windows/pbauto_heartbeat_init_windows.c + ${FEATURE_SOURCEFILES}) + endif () - if(USE_CRYPTO_API) + set(LDLIBS ${LDLIBS}) + + if (USE_CRYPTO_API) set(FEATURE_SOURCEFILES - ${CMAKE_CURRENT_LIST_DIR}/core/pbcc_crypto.c - ${CMAKE_CURRENT_LIST_DIR}/core/pbcc_crypto_aes_cbc.c - ${CMAKE_CURRENT_LIST_DIR}/core/pbcc_crypto_legacy.c - ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_crypto.c - ${CMAKE_CURRENT_LIST_DIR}/openssl/pbaes256.c - ${FEATURE_SOURCEFILES}) - endif() + ${CMAKE_CURRENT_LIST_DIR}/core/pbcc_crypto.c + ${CMAKE_CURRENT_LIST_DIR}/core/pbcc_crypto_aes_cbc.c + ${CMAKE_CURRENT_LIST_DIR}/core/pbcc_crypto_legacy.c + ${CMAKE_CURRENT_LIST_DIR}/core/pubnub_crypto.c + ${CMAKE_CURRENT_LIST_DIR}/openssl/pbaes256.c + ${FEATURE_SOURCEFILES}) + endif () - if(UNIX) + if (UNIX) set(FEATURE_SOURCEFILES ${FEATURE_SOURCEFILES} ${CMAKE_CURRENT_LIST_DIR}/openssl/pbpal_add_system_certs_posix.c) - elseif(WIN32 OR WIN64 OR MSVC) + elseif (WIN32 OR WIN64 OR MSVC) set(FEATURE_SOURCEFILES ${FEATURE_SOURCEFILES} ${CMAKE_CURRENT_LIST_DIR}/openssl/pbpal_add_system_certs_windows.c) - endif() -elseif(${MBEDTLS}) + endif () +elseif (${MBEDTLS}) message(STATUS "Using mbedTLS") - if(NOT ESP_PLATFORM) + if (NOT ESP_PLATFORM) # TODO: Add mbedTLS support for generic builds - endif() + endif () set(FEATURE_SOURCEFILES ${FEATURE_SOURCEFILES} - ${CMAKE_CURRENT_LIST_DIR}/mbedtls/pbpal_mbedtls.c - ${CMAKE_CURRENT_LIST_DIR}/mbedtls/pbpal_connect_mbedtls.c) -else() - set(LIB_SOURCEFILES - ${CMAKE_CURRENT_LIST_DIR}/lib/sockets/pbpal_sockets.c - ${LIB_SOURCEFILES}) - if(UNIX) - set(LIB_SOURCEFILES - ${CMAKE_CURRENT_LIST_DIR}/posix/pbpal_posix_blocking_io.c - ${LIB_SOURCEFILES}) - elseif(WIN32 OR WIN64 OR MSVC) - set(LIB_SOURCEFILES - ${CMAKE_CURRENT_LIST_DIR}/windows/pbpal_windows_blocking_io.c + ${CMAKE_CURRENT_LIST_DIR}/mbedtls/pbpal_mbedtls.c + ${CMAKE_CURRENT_LIST_DIR}/mbedtls/pbpal_connect_mbedtls.c) +else () + set(LIB_SOURCEFILES + ${CMAKE_CURRENT_LIST_DIR}/lib/sockets/pbpal_sockets.c ${LIB_SOURCEFILES}) - endif() -endif() - -set(SOURCEFILES - ${CORE_SOURCEFILES} - ${LIB_SOURCEFILES} - ${OS_SOURCEFILES} - ${FEATURE_SOURCEFILES} - ${INTF_SOURCEFILES}) - -if(NOT ESP_PLATFORM) - if(${SHARED_LIB}) + if (UNIX) + set(LIB_SOURCEFILES + ${CMAKE_CURRENT_LIST_DIR}/posix/pbpal_posix_blocking_io.c + ${LIB_SOURCEFILES}) + elseif (WIN32 OR WIN64 OR MSVC) + set(LIB_SOURCEFILES + ${CMAKE_CURRENT_LIST_DIR}/windows/pbpal_windows_blocking_io.c + ${LIB_SOURCEFILES}) + endif () +endif () + +set(SOURCEFILES + ${CORE_SOURCEFILES} + ${LIB_SOURCEFILES} + ${OS_SOURCEFILES} + ${FEATURE_SOURCEFILES} + ${INTF_SOURCEFILES}) + +if (NOT ESP_PLATFORM) + if (${SHARED_LIB}) message(STATUS "Building shared library") set(LIBTYPE SHARED) - else() + else () message(STATUS "Building static library") set(LIBTYPE STATIC) - endif() + endif () add_library(pubnub ${LIBTYPE} ${SOURCEFILES}) - if(NOT ${CUSTOM_BOOL_TYPE} STREQUAL "") + if (NOT ${CUSTOM_BOOL_TYPE} STREQUAL "") target_compile_definitions(pubnub PUBLIC PUBNUB_BOOL_TYPE=${CUSTOM_BOOL_TYPE}) - endif() + endif () target_include_directories(pubnub PUBLIC - ${CMAKE_CURRENT_LIST_DIR} - ${CMAKE_CURRENT_LIST_DIR}/core - ${CMAKE_CURRENT_LIST_DIR}/lib) - - if(${WITH_CPP}) + ${CMAKE_CURRENT_LIST_DIR} + ${CMAKE_CURRENT_LIST_DIR}/core + ${CMAKE_CURRENT_LIST_DIR}/lib) + + if (${WITH_CPP}) target_include_directories(pubnub PUBLIC ${CMAKE_CURRENT_LIST_DIR}/cpp) - endif() - - if(${OPENSSL}) - target_include_directories(pubnub PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/openssl/ - ${CMAKE_CURRENT_LIST_DIR}/lib/base64) + endif () + + if (${OPENSSL}) + target_include_directories(pubnub PUBLIC + ${CMAKE_CURRENT_LIST_DIR}/openssl/ + ${CMAKE_CURRENT_LIST_DIR}/lib/base64) target_include_directories(pubnub PUBLIC ${OPENSSL_INCLUDE_DIR}) - elseif(${MBEDTLS}) + elseif (${MBEDTLS}) target_include_directories(pubnub PUBLIC ${CMAKE_CURRENT_LIST_DIR}/mbedtls) - else() - if(UNIX) + else () + if (UNIX) target_include_directories(pubnub PUBLIC ${CMAKE_CURRENT_LIST_DIR}/posix) - elseif(WIN32 OR WIN64 OR MSVC) + elseif (WIN32 OR WIN64 OR MSVC) target_include_directories(pubnub PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/windows - ${CMAKE_CURRENT_LIST_DIR}/core/c99) - else() + ${CMAKE_CURRENT_LIST_DIR}/windows + ${CMAKE_CURRENT_LIST_DIR}/core/c99) + else () target_include_directories(pubnub PUBLIC ${CMAKE_CURRENT_LIST_DIR}/freertos) - endif() - endif() - + endif () + endif () + string(STRIP ${LDLIBS} LDLIBS) target_link_libraries(pubnub ${LDLIBS} ${SSL_LINK_LIBRARIES}) -else() +else () message(STATUS "Building ESP32 IDF component") set(EXTRA_CFLAGS ${EXTRA_CFLAGS} ${FLAGS}) if (${MBEDTLS}) - idf_component_register(SRCS ${SOURCEFILES} - INCLUDE_DIRS - ${CMAKE_CURRENT_LIST_DIR} - ${CMAKE_CURRENT_LIST_DIR}/core - ${CMAKE_CURRENT_LIST_DIR}/lib - ${CMAKE_CURRENT_LIST_DIR}/freertos - ${CMAKE_CURRENT_LIST_DIR}/mbedtls - $ENV{IDF_PATH}/components/freertos/FreeRTOS-Kernel/include/freertos - $ENV{IDF_PATH}/components/mbedtls/mbedtls/include - REQUIRES - freertos - lwip - mbedtls) - else() idf_component_register(SRCS ${SOURCEFILES} - INCLUDE_DIRS + INCLUDE_DIRS + ${CMAKE_CURRENT_LIST_DIR} + ${CMAKE_CURRENT_LIST_DIR}/core + ${CMAKE_CURRENT_LIST_DIR}/lib + ${CMAKE_CURRENT_LIST_DIR}/freertos + ${CMAKE_CURRENT_LIST_DIR}/mbedtls + $ENV{IDF_PATH}/components/freertos/FreeRTOS-Kernel/include/freertos + $ENV{IDF_PATH}/components/mbedtls/mbedtls/include + REQUIRES + freertos + lwip + mbedtls) + else () + idf_component_register(SRCS ${SOURCEFILES} + INCLUDE_DIRS ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_CURRENT_LIST_DIR}/core ${CMAKE_CURRENT_LIST_DIR}/lib ${CMAKE_CURRENT_LIST_DIR}/freertos $ENV{IDF_PATH}/components/freertos/FreeRTOS-Kernel/include/freertos - REQUIRES + REQUIRES freertos lwip) - endif() -endif() + endif () +endif () if (NOT ESP_PLATFORM) -endif() +endif () # TODO: C++ support for ESP32 platform if (WITH_CPP AND ESP_PLATFORM) message(FATAL_ERROR "C++ support is not available for ESP32 platform!") -endif() +endif () if (WITH_CPP AND NOT ESP_PLATFORM) # TODO: Tests @@ -637,180 +645,180 @@ if (WITH_CPP AND NOT ESP_PLATFORM) # fntest/pubnub_fntest.cpp set(CPP_SOURCE - ${CMAKE_CURRENT_LIST_DIR}/cpp/pubnub_subloop.cpp) - + ${CMAKE_CURRENT_LIST_DIR}/cpp/pubnub_subloop.cpp) + if (UNIX) set(CPP_SOURCE - ${CPP_SOURCE} - ${CMAKE_CURRENT_LIST_DIR}/cpp/pubnub_version_posix.cpp) + ${CPP_SOURCE} + ${CMAKE_CURRENT_LIST_DIR}/cpp/pubnub_version_posix.cpp) - if(${USE_CPP11}) + if (${USE_CPP11}) + set(CPP_SOURCE + ${CPP_SOURCE} + ${CMAKE_CURRENT_LIST_DIR}/cpp/pubnub_futres_cpp11.cpp) + else () set(CPP_SOURCE - ${CPP_SOURCE} - ${CMAKE_CURRENT_LIST_DIR}/cpp/pubnub_futres_cpp11.cpp) - else() - set(CPP_SOURCE ${CPP_SOURCE} ${CMAKE_CURRENT_LIST_DIR}/cpp/pubnub_futres_posix.cpp) - endif() - endif() + endif () + endif () if (WIN32 OR WIN64 OR MSVC) set(CPP_SOURCE - ${CPP_SOURCE} - ${CMAKE_CURRENT_LIST_DIR}/cpp/pubnub_version_windows.cpp) + ${CPP_SOURCE} + ${CMAKE_CURRENT_LIST_DIR}/cpp/pubnub_version_windows.cpp) - if(${USE_CPP11}) + if (${USE_CPP11}) set(CPP_SOURCE - ${CPP_SOURCE} - ${CMAKE_CURRENT_LIST_DIR}/cpp/pubnub_futres_cpp11.cpp) - else() + ${CPP_SOURCE} + ${CMAKE_CURRENT_LIST_DIR}/cpp/pubnub_futres_cpp11.cpp) + else () set(CPP_SOURCE - ${CPP_SOURCE} - ${CMAKE_CURRENT_LIST_DIR}/cpp/pubnub_futres_windows.cpp) - endif() - endif() - + ${CPP_SOURCE} + ${CMAKE_CURRENT_LIST_DIR}/cpp/pubnub_futres_windows.cpp) + endif () + endif () + add_library(pubnub-cpp ${LIBTYPE} ${CPP_SOURCE}) target_link_libraries(pubnub-cpp PUBLIC pubnub) target_include_directories(pubnub-cpp PUBLIC ${CMAKE_CURRENT_LIST_DIR}/cpp) -endif() +endif () -if(${EXAMPLES}) +if (${EXAMPLES}) message(STATUS "Building all examples") set(EXAMPLE_LIST) set(CPP_EXAMPLE_LIST) - if(${EXAMPLE} STREQUAL "all") + if (${EXAMPLE} STREQUAL "all") if (WITH_CPP) set(CPP_EXAMPLE_LIST - pubnub_subloop_sample - pubnub_sample - cancel_subscribe_sync_sample - futres_nesting - ${CPP_EXAMPLE_LIST}) - - if(${OPENSSL} AND ${USE_CPP11}) - # TODO: Fix this example to be 98 compatible - set(CPP_EXAMPLE_LIST + pubnub_subloop_sample + pubnub_sample + cancel_subscribe_sync_sample + futres_nesting + ${CPP_EXAMPLE_LIST}) + + if (${OPENSSL} AND ${USE_CPP11}) + # TODO: Fix this example to be 98 compatible + set(CPP_EXAMPLE_LIST pubnub_crypto_module_sample ${CPP_EXAMPLE_LIST}) - endif() + endif () - if (${USE_GRANT_TOKEN_API}) - set(CPP_EXAMPLE_LIST + if (${USE_GRANT_TOKEN_API}) + set(CPP_EXAMPLE_LIST pubnub_sample_grant_token ${CPP_EXAMPLE_LIST}) - endif() + endif () - if (${USE_REVOKE_TOKEN_API}) - set(CPP_EXAMPLE_LIST + if (${USE_REVOKE_TOKEN_API}) + set(CPP_EXAMPLE_LIST pubnub_sample_revoke_token ${CPP_EXAMPLE_LIST}) - endif() - endif() + endif () + endif () - if(${USE_CALLBACK_API}) + if (${USE_CALLBACK_API}) message(STATUS "Building callback examples") set(EXAMPLE_LIST - pubnub_callback_sample - pubnub_callback_subloop_sample - subscribe_publish_callback_sample - subscribe_publish_from_callback - publish_callback_subloop_sample - publish_queue_callback_subloop) - if(${USE_SUBSCRIBE_EVENT_ENGINE}) + pubnub_callback_sample + pubnub_callback_subloop_sample + subscribe_publish_callback_sample + subscribe_publish_from_callback + publish_callback_subloop_sample + publish_queue_callback_subloop) + if (${USE_SUBSCRIBE_EVENT_ENGINE}) set(EXAMPLE_LIST - subscribe_event_engine_sample - ${EXAMPLE_LIST}) - endif() + subscribe_event_engine_sample + ${EXAMPLE_LIST}) + endif () if (WITH_CPP) set(CPP_EXAMPLE_LIST - subscribe_publish_callback_sample # Only supports callback! - ${CPP_EXAMPLE_LIST}) - endif() - else() + subscribe_publish_callback_sample # Only supports callback! + ${CPP_EXAMPLE_LIST}) + endif () + else () message(STATUS "Building sync examples") set(EXAMPLE_LIST - metadata - pubnub_sync_subloop_sample - pubnub_sync_publish_retry - pubnub_publish_via_post_sample - pubnub_advanced_history_sample - pubnub_fetch_history_sample - cancel_subscribe_sync_sample) + metadata + pubnub_sync_subloop_sample + pubnub_sync_publish_retry + pubnub_publish_via_post_sample + pubnub_advanced_history_sample + pubnub_fetch_history_sample + cancel_subscribe_sync_sample) if (OPENSSL) set(EXAMPLE_LIST - pubnub_crypto_module_sample - ${EXAMPLE_LIST}) + pubnub_crypto_module_sample + ${EXAMPLE_LIST}) if (${USE_GRANT_TOKEN_API}) set(EXAMPLE_LIST - pubnub_sync_grant_token_sample - ${EXAMPLE_LIST}) - endif() - endif() + pubnub_sync_grant_token_sample + ${EXAMPLE_LIST}) + endif () + endif () if (${USE_OBJECTS_API}) set(EXAMPLE_LIST - pubnub_objects_api_sample - ${EXAMPLE_LIST}) - endif() - endif() - else() + pubnub_objects_api_sample + ${EXAMPLE_LIST}) + endif () + endif () + else () message(STATUS "Building example ${EXAMPLE}") set(EXAMPLE_LIST ${EXAMPLE}) - endif() + endif () - foreach(EXAMPLE ${EXAMPLE_LIST}) + foreach (EXAMPLE ${EXAMPLE_LIST}) add_executable(${EXAMPLE} ${CMAKE_CURRENT_LIST_DIR}/core/samples/${EXAMPLE}.c) target_link_libraries(${EXAMPLE} pubnub ${LDLIBS}) - endforeach() + endforeach () - foreach(EXAMPLE ${CPP_EXAMPLE_LIST}) + foreach (EXAMPLE ${CPP_EXAMPLE_LIST}) add_executable(${EXAMPLE}-cpp ${CMAKE_CURRENT_LIST_DIR}/cpp/samples/${EXAMPLE}.cpp) target_link_libraries(${EXAMPLE}-cpp pubnub-cpp ${LDLIBS}) - endforeach() -endif() + endforeach () +endif () -if(${UNIT_TEST}) +if (${UNIT_TEST}) message(STATUS "Building unit tests") message(STATUS "UNIT TESTS ARE NOT FINISHED YET!") -# set(CMAKE_C_FLAGS " \ -# ${CMAKE_C_FLAGS} \ -# -D PUBNUB_ADVANCED_KEEP_ALIVE=1 \ -# -D PUBNUB_DYNAMIC_REPLY_BUFFER=1 \ -# -D PUBNUB_ORIGIN_SETTABLE=1") -# -# add_library(pubnub-unit-test SHARED core/pubnub_core_unit_test.c core/test/pubnub_test_mocks.c ${SOURCEFILES}) -# target_include_directories(pubnub-unit-test PUBLIC -# ${CGREEN_ROOT_DIR}/include -# ${CMAKE_CURRENT_LIST_DIR}/core -# ${CMAKE_CURRENT_LIST_DIR}/core/test -# ${CMAKE_CURRENT_LIST_DIR}/lib -# ${CMAKE_CURRENT_LIST_DIR}) -# -# if(${OPENSSL}) -# target_include_directories(pubnub-unit-test PUBLIC -# ${CMAKE_CURRENT_LIST_DIR}/openssl/ -# ${CMAKE_CURRENT_LIST_DIR}/lib/base64) -# target_include_directories(pubnub-unit-test PUBLIC ${OPENSSL_INCLUDE_DIR}) -# else() -# if(UNIX) -# target_include_directories(pubnub-unit-test PUBLIC ${CMAKE_CURRENT_LIST_DIR}/posix) -# elseif(WIN32 OR WIN64 OR MSVC) -# target_include_directories(pubnub-unit-test PUBLIC -# ${CMAKE_CURRENT_LIST_DIR}/windows -# ${CMAKE_CURRENT_LIST_DIR}/core/c99) -# endif() -# endif() -# -# target_link_libraries(pubnub-unit-test ${LDLIBS} pubnub ${CGREEN_ROOT_DIR}/build/src/libcgreen.a) -# -# add_custom_target(RunUnitTests -# COMMAND ${CGREEN_ROOT_DIR/build/tools/cgreen-runner} pubnub-unit-test) + # set(CMAKE_C_FLAGS " \ + # ${CMAKE_C_FLAGS} \ + # -D PUBNUB_ADVANCED_KEEP_ALIVE=1 \ + # -D PUBNUB_DYNAMIC_REPLY_BUFFER=1 \ + # -D PUBNUB_ORIGIN_SETTABLE=1") + # + # add_library(pubnub-unit-test SHARED core/pubnub_core_unit_test.c core/test/pubnub_test_mocks.c ${SOURCEFILES}) + # target_include_directories(pubnub-unit-test PUBLIC + # ${CGREEN_ROOT_DIR}/include + # ${CMAKE_CURRENT_LIST_DIR}/core + # ${CMAKE_CURRENT_LIST_DIR}/core/test + # ${CMAKE_CURRENT_LIST_DIR}/lib + # ${CMAKE_CURRENT_LIST_DIR}) + # + # if(${OPENSSL}) + # target_include_directories(pubnub-unit-test PUBLIC + # ${CMAKE_CURRENT_LIST_DIR}/openssl/ + # ${CMAKE_CURRENT_LIST_DIR}/lib/base64) + # target_include_directories(pubnub-unit-test PUBLIC ${OPENSSL_INCLUDE_DIR}) + # else() + # if(UNIX) + # target_include_directories(pubnub-unit-test PUBLIC ${CMAKE_CURRENT_LIST_DIR}/posix) + # elseif(WIN32 OR WIN64 OR MSVC) + # target_include_directories(pubnub-unit-test PUBLIC + # ${CMAKE_CURRENT_LIST_DIR}/windows + # ${CMAKE_CURRENT_LIST_DIR}/core/c99) + # endif() + # endif() + # + # target_link_libraries(pubnub-unit-test ${LDLIBS} pubnub ${CGREEN_ROOT_DIR}/build/src/libcgreen.a) + # + # add_custom_target(RunUnitTests + # COMMAND ${CGREEN_ROOT_DIR/build/tools/cgreen-runner} pubnub-unit-test) # TODO: finish unit tests -endif() +endif () diff --git a/core/Makefile b/core/Makefile index 3727ea07..08f32a6c 100644 --- a/core/Makefile +++ b/core/Makefile @@ -17,7 +17,7 @@ endif generate_report: all #$(GCOVR) -r . --html --html-details -o coverage.html - $(GCOVR) -r . --xml -o coverage.xml + #$(GCOVR) -r . --xml -o coverage.xml ifndef RECEIVE_GZIP_RESPONSE RECEIVE_GZIP_RESPONSE = 1 diff --git a/core/pubnub_ccore_pubsub.c b/core/pubnub_ccore_pubsub.c index db886ce9..f9716dbc 100644 --- a/core/pubnub_ccore_pubsub.c +++ b/core/pubnub_ccore_pubsub.c @@ -22,21 +22,20 @@ #include #include -/* Maximum allowed user-provided UUID string length. */ -#define MAX_USER_ID_STRING_LENGTH 64 - -void pbcc_init(struct pbcc_context* p, const char* publish_key, const char* subscribe_key) +void pbcc_init(struct pbcc_context* p, + const char* publish_key, + const char* subscribe_key) { p->publish_key = publish_key; p->subscribe_key = subscribe_key; p->timetoken[0] = '0'; p->timetoken[1] = '\0'; - p->user_id = NULL; - p->user_id_len = 0; + p->user_id = NULL; + p->user_id_len = 0; p->auth = NULL; p->auth_token = NULL; - p->msg_ofs = p->msg_end = 0; + p->msg_ofs = p->msg_end = 0; #if PUBNUB_DYNAMIC_REPLY_BUFFER p->http_reply = NULL; #if PUBNUB_RECEIVE_GZIP_RESPONSE @@ -45,11 +44,11 @@ void pbcc_init(struct pbcc_context* p, const char* publish_key, const char* subs #endif /* PUBNUB_RECEIVE_GZIP_RESPONSE */ #endif /* PUBNUB_DYNAMIC_REPLY_BUFFER */ p->message_to_send = NULL; - p->state = NULL; + p->state = NULL; #if PUBNUB_USE_RETRY_CONFIGURATION p->retry_configuration = NULL; - p->http_retry_count = 0; - p->retry_timer = NULL; + p->http_retry_count = 0; + p->retry_timer = NULL; #endif // #if PUBNUB_USE_RETRY_CONFIGURATION #if PUBNUB_USE_GZIP_COMPRESSION p->gzip_msg_len = 0; @@ -89,7 +88,7 @@ void pbcc_deinit(struct pbcc_context* p) #if PUBNUB_CRYPTO_API if (NULL != p->crypto_module) { free(p->crypto_module); - p->crypto_module = NULL; + p->crypto_module = NULL; } #endif /* PUBNUB_CRYPTO_API */ #if PUBNUB_USE_SUBSCRIBE_EVENT_ENGINE @@ -137,7 +136,7 @@ bool pbcc_ensure_reply_buffer(struct pbcc_context* p) char const* pbcc_get_msg(struct pbcc_context* pb) { -#if PUBNUB_CRYPTO_API +#if PUBNUB_CRYPTO_API size_t len; #endif // PUBNUB_CRYPTO_API if (pb->msg_ofs < pb->msg_end) { @@ -150,7 +149,7 @@ char const* pbcc_get_msg(struct pbcc_context* pb) len = strlen(rslt); rslt = pbcc_decrypt_message(pb, rslt, len, NULL); } -#endif // PUBNUB_CRYPTO_API +#endif // PUBNUB_CRYPTO_API return rslt; } } @@ -179,9 +178,8 @@ enum pubnub_res pbcc_set_user_id(struct pbcc_context* pb, const char* user_id) free(pb->user_id); pb->user_id = NULL; } - pb->user_id_len = (NULL == user_id) ? 0 : strlen(user_id); + pb->user_id_len = NULL == user_id ? 0 : strlen(user_id); if (pb->user_id_len > 0) { - PUBNUB_ASSERT_OPT(pb->user_id_len <= MAX_USER_ID_STRING_LENGTH); /** Alloc additional space for NULL character */ pb->user_id = (char*)malloc((pb->user_id_len + 1) * sizeof(char)); if (NULL == pb->user_id) { @@ -257,7 +255,7 @@ bool pbcc_split_array(char* buf) case '}': bracket_level--; break; - /* if at root, split! */ + /* if at root, split! */ case ',': if (bracket_level == 0) { *buf = '\0'; @@ -276,16 +274,16 @@ bool pbcc_split_array(char* buf) enum pubnub_res pbcc_parse_publish_response(struct pbcc_context* p) { struct pbjson_elem el; - char* reply = p->http_reply; + char* reply = p->http_reply; PUBNUB_LOG_DEBUG("\n%s\n", reply); - int replylen = p->http_buf_len; + int replylen = p->http_buf_len; if (replylen < 2) { return PNR_FORMAT_ERROR; } el.start = reply; el.end = reply + replylen; - if (pbjson_value_for_field_found(&el, "status", "403")){ + if (pbjson_value_for_field_found(&el, "status", "403")) { PUBNUB_LOG_ERROR("pbcc_parse_publish_response(pbcc=%p) - AccessDenied: " "response from server - response='%s'\n", p, @@ -294,7 +292,7 @@ enum pubnub_res pbcc_parse_publish_response(struct pbcc_context* p) } p->chan_ofs = p->chan_end = 0; - p->msg_ofs = p->msg_end = 0; + p->msg_ofs = p->msg_end = 0; if ((reply[0] != '[') || (reply[replylen - 1] != ']')) { if (reply[0] != '{') { @@ -321,35 +319,38 @@ enum pubnub_res pbcc_parse_publish_response(struct pbcc_context* p) enum pubnub_res pbcc_parse_subscribe_response(struct pbcc_context* p) { struct pbjson_elem el; - int i; - int previous_i; - unsigned time_token_length; - char* reply = p->http_reply; + int i; + int previous_i; + unsigned time_token_length; + char* reply = p->http_reply; PUBNUB_LOG_DEBUG("\n%s\n", reply); - int replylen = p->http_buf_len; + int replylen = p->http_buf_len; if (replylen < 2) { return PNR_FORMAT_ERROR; } el.start = reply; el.end = reply + replylen; - if (pbjson_value_for_field_found(&el, "status", "403")){ - PUBNUB_LOG_ERROR("pbcc_parse_subscribe_response(pbcc=%p) - AccessDenied: " - "response from server - response='%s'\n", - p, - reply); + if (pbjson_value_for_field_found(&el, "status", "403")) { + PUBNUB_LOG_ERROR( + "pbcc_parse_subscribe_response(pbcc=%p) - AccessDenied: " + "response from server - response='%s'\n", + p, + reply); return PNR_ACCESS_DENIED; } - if (pbjson_value_for_field_found(&el, "status", "400")){ + if (pbjson_value_for_field_found(&el, "status", "400")) { char* msgtext = (char*)pbjson_get_status_400_message_value(&el); - if (msgtext != NULL && strcmp(msgtext,"\"Channel group or groups result in empty subscription set\"") == 0){ + if (msgtext != NULL && strcmp(msgtext, + "\"Channel group or groups result in empty subscription set\"") + == 0) { return PNR_GROUP_EMPTY; } - else{ + else { return PNR_FORMAT_ERROR; } } - + if (reply[replylen - 1] != ']' && replylen > 2) { replylen -= 2; /* XXX: this seems required by Manxiang */ } @@ -474,7 +475,10 @@ void pbcc_via_post_headers(struct pbcc_context* pb, #if PUBNUB_USE_GZIP_COMPRESSION if (pb->gzip_msg_len != 0) { char h_encoding[] = "Content-Encoding: gzip\0"; - length = snprintf(header, max_length, "%lu\r\n", (unsigned long)pb->gzip_msg_len); + length = snprintf(header, + max_length, + "%lu\r\n", + (unsigned long)pb->gzip_msg_len); PUBNUB_ASSERT_OPT(max_length > length + sizeof h_encoding - 1); memcpy(header + length, h_encoding, sizeof h_encoding - 1); return; @@ -483,17 +487,23 @@ void pbcc_via_post_headers(struct pbcc_context* pb, length = snprintf(header, max_length, "%lu", - (unsigned long)pb_strnlen_s(pb->message_to_send, PUBNUB_MAX_OBJECT_LENGTH)); + (unsigned long)pb_strnlen_s( + pb->message_to_send, + PUBNUB_MAX_OBJECT_LENGTH)); PUBNUB_ASSERT_OPT(max_length > length); } -enum pubnub_res pbcc_url_encode(struct pbcc_context* pb, char const* what, enum pubnub_trans pt) +enum pubnub_res pbcc_url_encode(struct pbcc_context* pb, + char const* what, + enum pubnub_trans pt) { int url_encoded_length; url_encoded_length = pubnub_url_encode(pb->http_buf + pb->http_buf_len, what, - sizeof pb->http_buf - pb->http_buf_len, pt); + sizeof pb->http_buf - pb-> + http_buf_len, + pt); if (url_encoded_length < 0) { pb->http_buf_len = 0; return PNR_TX_BUFF_TOO_SMALL; @@ -505,10 +515,10 @@ enum pubnub_res pbcc_url_encode(struct pbcc_context* pb, char const* what, enum enum pubnub_res pbcc_append_url_param_encoded(struct pbcc_context* pb, - char const* param_name, - size_t param_name_len, + char const* param_name, + size_t param_name_len, char const* param_val, - char separator, + char separator, enum pubnub_trans pt) { if (pb->http_buf_len + 1 + param_name_len + 1 > sizeof pb->http_buf) { @@ -636,11 +646,15 @@ enum pubnub_res pbcc_publish_prep(struct pbcc_context* pb, return (rslt != PNR_OK) ? rslt : PNR_STARTED; } -enum pubnub_res pbcc_sign_url(struct pbcc_context* pc, const char* msg, enum pubnub_method method, bool v3sign){ - enum pubnub_res rslt_ = PNR_INTERNAL_ERROR; - char* url = (char*)malloc(sizeof(pc->http_buf)); - char* ques = strchr(pc->http_buf, '?'); - size_t pos_ques_char = (int)(ques - pc->http_buf); +enum pubnub_res pbcc_sign_url(struct pbcc_context* pc, + const char* msg, + enum pubnub_method method, + bool v3sign) +{ + enum pubnub_res rslt_ = PNR_INTERNAL_ERROR; + char* url = (char*)malloc(sizeof(pc->http_buf)); + char* ques = strchr(pc->http_buf, '?'); + size_t pos_ques_char = (int)(ques - pc->http_buf); if (url != NULL) { url[pos_ques_char] = '\0'; memcpy(url, pc->http_buf, pos_ques_char); @@ -656,8 +670,12 @@ enum pubnub_res pbcc_sign_url(struct pbcc_context* pc, const char* msg, enum pub #endif if (rslt_ == PNR_OK) { const char* param_ = "signature"; - rslt_ = pbcc_append_url_param( - (pc), param_, strlen(param_), (final_signature), ('&')); + rslt_ = pbcc_append_url_param( + (pc), + param_, + strlen(param_), + (final_signature), + ('&')); if (rslt_ != PNR_OK) { return rslt_; } @@ -670,19 +688,19 @@ enum pubnub_res pbcc_sign_url(struct pbcc_context* pc, const char* msg, enum pub enum pubnub_res pbcc_signal_prep(struct pbcc_context* pb, - const char* channel, - const char* message, - const char* custom_message_type) + const char* channel, + const char* message, + const char* custom_message_type) { - enum pubnub_res rslt = PNR_OK; - char const* const uname = pubnub_uname(); + enum pubnub_res rslt = PNR_OK; + char const* const uname = pubnub_uname(); char const* user_id = pbcc_user_id_get(pb); PUBNUB_ASSERT_OPT(user_id != NULL); PUBNUB_ASSERT_OPT(message != NULL); pb->http_content_len = 0; - pb->http_buf_len = snprintf(pb->http_buf, + pb->http_buf_len = snprintf(pb->http_buf, sizeof pb->http_buf, "/signal/%s/%s/0/", pb->publish_key, @@ -703,7 +721,7 @@ enum pubnub_res pbcc_signal_prep(struct pbcc_context* pb, #else ADD_URL_AUTH_PARAM(pb, qparam, auth); #endif - + #if PUBNUB_CRYPTO_API SORT_URL_PARAMETERS(qparam); #endif @@ -726,8 +744,8 @@ enum pubnub_res pbcc_subscribe_prep(struct pbcc_context* p, char const* channel_group, const unsigned* heartbeat) { - char const* user_id = pbcc_user_id_get(p); - char const* const uname = pubnub_uname(); + char const* user_id = pbcc_user_id_get(p); + char const* const uname = pubnub_uname(); PUBNUB_ASSERT_OPT(user_id != NULL); @@ -744,7 +762,7 @@ enum pubnub_res pbcc_subscribe_prep(struct pbcc_context* p, } p->http_content_len = 0; - p->msg_ofs = p->msg_end = 0; + p->msg_ofs = p->msg_end = 0; #if PUBNUB_CRYPTO_API for (size_t i = 0; i < p->decrypted_message_count; i++) { @@ -754,7 +772,10 @@ enum pubnub_res pbcc_subscribe_prep(struct pbcc_context* p, #endif p->http_buf_len = snprintf( - p->http_buf, sizeof p->http_buf, "/subscribe/%s/", p->subscribe_key); + p->http_buf, + sizeof p->http_buf, + "/subscribe/%s/", + p->subscribe_key); APPEND_URL_ENCODED_M(p, channel); p->http_buf_len += snprintf(p->http_buf + p->http_buf_len, sizeof p->http_buf - p->http_buf_len, @@ -771,7 +792,9 @@ enum pubnub_res pbcc_subscribe_prep(struct pbcc_context* p, ADD_URL_AUTH_PARAM(p, qparam, auth); #endif - if (heartbeat) { ADD_URL_PARAM_SIZET(qparam, heartbeat, (unsigned long)(*heartbeat)); } + if (heartbeat) { + ADD_URL_PARAM_SIZET(qparam, heartbeat, (unsigned long)(*heartbeat)); + } #if PUBNUB_CRYPTO_API SORT_URL_PARAMETERS(qparam); diff --git a/core/pubnub_core_unit_test.c b/core/pubnub_core_unit_test.c index 0aa7611a..e397567b 100644 --- a/core/pubnub_core_unit_test.c +++ b/core/pubnub_core_unit_test.c @@ -355,6 +355,18 @@ static void cancel_and_cleanup(pubnub_t* pbp) attest(pbp->core.last_result, equals(PNR_CANCELLED)); } + +Ensure(single_context_pubnub, no_user_id_length_limit) +{ + pubnub_init(pbp, "pubkey", "subkey"); + char *user_id = "WC65Z7Gg9fnY6M2XxfxF6Q0JRH8pFRhwDiJsnqtgXs6keqzOE24SqQiE20Yzv4v5wuKtrn96iA7TjDKe3pMeAqW3wYRsjLAVWO1efmIdueuQwlB6DRRgoCSKReczOySSoH9KcJTLtjDZatNFTFyP2IF8jtYtef3P1SOwEWzGtJW6jV67gM0tTPJogEdcxetJhRYU5BtMTrsxA2EMmnZ8AWXZWCPAr3rZ"; + // Test 224 long user id + pubnub_set_uuid(pbp, user_id); + attest(pubnub_uuid_get(pbp), streqs(user_id)); + pubnub_set_user_id(pbp, user_id); + attest(pubnub_user_id_get(pbp), streqs(user_id)); +} + /* -- LEAVE operation -- */ Ensure(single_context_pubnub, leave_have_dns) { @@ -4571,11 +4583,9 @@ Ensure(single_context_pubnub, illegal_context_fires_assert) expect_assert_in(pubnub_leave(NULL, "x", NULL), "pubnub_coreapi.c"); expect_assert_in(pubnub_cancel(NULL), "pubnub_pubsubapi.c"); expect_assert_in(pubnub_set_user_id(NULL, ""), "pubnub_pubsubapi.c"); - expect_assert_in(pubnub_set_user_id(pbp, "50fb7a0b-1688-45b9-9f27-ea83308464d8-ab3817df-07eb-446a-b990-c3b62a31706f"), "pubnub_ccore_pubsub.c"); PUBNUB_DISABLE_WARNING_PUSH PUBNUB_DISABLE_DEPRECATED expect_assert_in(pubnub_set_uuid(NULL, ""), "pubnub_pubsubapi.c"); - expect_assert_in(pubnub_set_uuid(pbp, "50fb7a0b-1688-45b9-9f27-ea83308464d8-ab3817df-07eb-446a-b990-c3b62a31706f"), "pubnub_ccore_pubsub.c"); PUBNUB_DISABLE_WARNING_POP expect_assert_in(pubnub_user_id_get(NULL), "pubnub_pubsubapi.c"); expect_assert_in(pubnub_set_auth(NULL, ""), "pubnub_pubsubapi.c"); From 12497baa7cdb5982446c5becfff35b6616ce1f42 Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Thu, 9 Jan 2025 11:23:48 +0200 Subject: [PATCH 2/4] fix(build): fix CMakeFiles build option name --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 159dad87..4b815e02 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,7 +68,7 @@ num_option(ONLY_PUBSUB_API "Only pubsub API" OFF) num_option(USE_PROXY "Use proxy" ON) num_option(USE_GZIP_COMPRESSION "Use gzip compression" ON) num_option(RECEIVE_GZIP_RESPONSE "Use gzip decompression" ON) -num_option(USE_REDidONFIGURATION "Use requests retry" OFF) +num_option(USE_RETRY_CONFIGURATION "Use requests retry" OFF) num_option(USE_SUBSCRIBE_V2 "Use subscribe v2" ON) num_option(USE_SUBSCRIBE_EVENT_ENGINE "Use Subscribe Event Engine [USE_SUBSCRIBE_V2=ON needed]" OFF) num_option(USE_ADVANCED_HISTORY "Use advanced history" ON) From d91c211df19ddc8ec2feb5367cb0238102609cbc Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Thu, 9 Jan 2025 11:31:54 +0200 Subject: [PATCH 3/4] build: disable gcovr because of cache issues --- lib/Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/Makefile b/lib/Makefile index 878edfcb..a9476473 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -15,7 +15,7 @@ endif generate_report: all #$(GCOVR) -r . --html --html-details -o coverage.html - $(GCOVR) -r . --xml -o coverage.xml + #$(GCOVR) -r . --xml -o coverage.xml CFLAGS +=-g -D PUBNUB_CALLBACK_API -D PUBNUB_LOG_LEVEL=PUBNUB_LOG_LEVEL_NONE -I. -I.. -I../core -I ../core/test -I../lib/base64 -I../lib/md5 -I../lib/miniz -I../cgreen/include @@ -29,7 +29,7 @@ pubnub_parse_ipv6_addr_unit_test: pubnub_parse_ipv6_addr.c pubnub_parse_ipv6_add gcc -o pubnub_parse_ipv6_addr_unit_test.so -shared $(CFLAGS) $(LDFLAGS) -Wall $(COVERAGE_FLAGS) -fPIC $(PARSE_IPV6_ADDR_SOURCE_FILES) pubnub_parse_ipv6_addr.c pubnub_parse_ipv6_addr_unit_test.c -lcgreen -lm # gcc -o pubnub_parse_ipv6_addr_unit_testo $(CFLAGS) -Wall $(COVERAGE_FLAGS) $(PARSE_IPV6_ADDR_SOURCE_FILES) ../lib/pubnub_parse_ipv6_addr.c pubnub_parse_ipv6_addr_unit_test.c -lcgreen -lm $(CGREEN_RUNNER) ./pubnub_parse_ipv6_addr_unit_test.so - $(GCOVR) -r . --html --html-details -o coverage.html + #$(GCOVR) -r . --html --html-details -o coverage.html DNS_CODEC_SOURCE_FILES = ../core/pubnub_assert_std.c @@ -37,17 +37,17 @@ pubnub_dns_codec_unit_test: pubnub_dns_codec.c pubnub_dns_codec_unit_test.c gcc -o pubnub_dns_codec_unit_test.so -shared $(CFLAGS) -D PUBNUB_USE_IPV6=1 -D PUBNUB_USE_SSL=1 $(LDFLAGS) -Wall $(COVERAGE_FLAGS) -fPIC $(DNS_CODEC_SOURCE_FILES) pubnub_dns_codec.c pubnub_dns_codec_unit_test.c -lcgreen -lm # gcc -o pubnub_dns_codec_unit_testo $(CFLAGS) -Wall $(COVERAGE_FLAGS) $(DNS_CODEC_SOURCE_FILES) ../lib/pubnub_dns_codec.c pubnub_dns_codec_unit_test.c -lcgreen -lm $(CGREEN_RUNNER) ./pubnub_dns_codec_unit_test.so - $(GCOVR) -r . --html --html-details -o coverage.html + #$(GCOVR) -r . --html --html-details -o coverage.html pbarray_unit_test: pbref_counter.c pbarray.c pbarray_unit_test.c gcc -o pbarray_unit_test.so -shared $(CFLAGS) $(LDFLAGS) -I../core/c99 -Wall $(COVERAGE_FLAGS) pbref_counter.c pbarray.c pbarray_unit_test.c -lcgreen -lm $(CGREEN_RUNNER) ./pbarray_unit_test.so - $(GCOVR) -r . --html --html-details -o coverage.html + #$(GCOVR) -r . --html --html-details -o coverage.html pbhash_set_unit_test: pbref_counter.c pbhash_set.c pbarray.c pbhash_set_unit_test.c gcc -o pbhash_set_unit_test.so -shared $(CFLAGS) $(LDFLAGS) -I../core/c99 -Wall $(COVERAGE_FLAGS) pbref_counter.c pbhash_set.c pbarray.c pbhash_set_unit_test.c -lcgreen -lm $(CGREEN_RUNNER) ./pbhash_set_unit_test.so - $(GCOVR) -r . --html --html-details -o coverage.html + #$(GCOVR) -r . --html --html-details -o coverage.html clean: find . -type d -iname "*.dSYM" -exec rm -rf {} \+ From 3c2fab3aeb93c5da3343d06fda568c7940ddcb7e Mon Sep 17 00:00:00 2001 From: PubNub Release Bot <120067856+pubnub-release-bot@users.noreply.github.com> Date: Thu, 9 Jan 2025 09:57:55 +0000 Subject: [PATCH 4/4] PubNub SDK v4.16.1 release. --- .pubnub.yml | 23 +++++++++++++++-------- CHANGELOG.md | 9 +++++++++ core/pubnub_version_internal.h | 2 +- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index 9d0c2f6f..f78cf876 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,8 +1,15 @@ name: c-core schema: 1 -version: "4.16.0" +version: "4.16.1" scm: github.com/pubnub/c-core changelog: + - date: 2025-01-09 + version: v4.16.1 + changes: + - type: bug + text: "Remove the `user_id` length restriction for dynamically allocated memory for it." + - type: improvement + text: "Configure `try_compile` when building a static library." - date: 2024-12-25 version: v4.16.0 changes: @@ -895,7 +902,7 @@ sdks: distribution-type: source code distribution-repository: GitHub release package-name: C-Core - location: https://github.com/pubnub/c-core/releases/tag/v4.16.0 + location: https://github.com/pubnub/c-core/releases/tag/v4.16.1 requires: - name: "miniz" @@ -961,7 +968,7 @@ sdks: distribution-type: source code distribution-repository: GitHub release package-name: C-Core - location: https://github.com/pubnub/c-core/releases/tag/v4.16.0 + location: https://github.com/pubnub/c-core/releases/tag/v4.16.1 requires: - name: "miniz" @@ -1027,7 +1034,7 @@ sdks: distribution-type: source code distribution-repository: GitHub release package-name: C-Core - location: https://github.com/pubnub/c-core/releases/tag/v4.16.0 + location: https://github.com/pubnub/c-core/releases/tag/v4.16.1 requires: - name: "miniz" @@ -1089,7 +1096,7 @@ sdks: distribution-type: source code distribution-repository: GitHub release package-name: C-Core - location: https://github.com/pubnub/c-core/releases/tag/v4.16.0 + location: https://github.com/pubnub/c-core/releases/tag/v4.16.1 requires: - name: "miniz" @@ -1150,7 +1157,7 @@ sdks: distribution-type: source code distribution-repository: GitHub release package-name: C-Core - location: https://github.com/pubnub/c-core/releases/tag/v4.16.0 + location: https://github.com/pubnub/c-core/releases/tag/v4.16.1 requires: - name: "miniz" @@ -1206,7 +1213,7 @@ sdks: distribution-type: source code distribution-repository: GitHub release package-name: C-Core - location: https://github.com/pubnub/c-core/releases/tag/v4.16.0 + location: https://github.com/pubnub/c-core/releases/tag/v4.16.1 requires: - name: "miniz" @@ -1259,7 +1266,7 @@ sdks: distribution-type: source code distribution-repository: GitHub release package-name: C-Core - location: https://github.com/pubnub/c-core/releases/tag/v4.16.0 + location: https://github.com/pubnub/c-core/releases/tag/v4.16.1 requires: - name: "miniz" diff --git a/CHANGELOG.md b/CHANGELOG.md index d2e1aa43..763d8966 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## v4.16.1 +January 09 2025 + +#### Fixed +- Remove the `user_id` length restriction for dynamically allocated memory for it. + +#### Modified +- Configure `try_compile` when building a static library. + ## v4.16.0 December 25 2024 diff --git a/core/pubnub_version_internal.h b/core/pubnub_version_internal.h index e47fc9bc..1ec076ed 100644 --- a/core/pubnub_version_internal.h +++ b/core/pubnub_version_internal.h @@ -3,7 +3,7 @@ #define INC_PUBNUB_VERSION_INTERNAL -#define PUBNUB_SDK_VERSION "4.16.0" +#define PUBNUB_SDK_VERSION "4.16.1" #endif /* !defined INC_PUBNUB_VERSION_INTERNAL */