Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for windows.mk openssl makefile CLEN-2403 #200

Merged
merged 19 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
name: c-core
schema: 1
version: "4.15.0"
version: "4.16.0"
scm: github.com/pubnub/c-core
changelog:
- date: 2024-12-25
version: v4.16.0
changes:
- type: feature
text: "Additional flags for C/CPP can be set with: `USER_C_FLAGS` / `USER_CXX_FLAGS`."
- type: bug
text: "Fix because of which one of the source files has been missed for Windows."
- type: bug
text: "Fix issue with unsupported concatenation of sources files / definitions (`+=`)."
- type: improvement
text: "Refactor our `Makefiles` from different folders and platforms to use `include` directives to include shared definitions, flags, source files."
- date: 2024-11-25
version: v4.15.0
changes:
Expand Down Expand Up @@ -884,7 +895,7 @@ sdks:
distribution-type: source code
distribution-repository: GitHub release
package-name: C-Core
location: https://github.com/pubnub/c-core/releases/tag/v4.15.0
location: https://github.com/pubnub/c-core/releases/tag/v4.16.0
requires:
-
name: "miniz"
Expand Down Expand Up @@ -950,7 +961,7 @@ sdks:
distribution-type: source code
distribution-repository: GitHub release
package-name: C-Core
location: https://github.com/pubnub/c-core/releases/tag/v4.15.0
location: https://github.com/pubnub/c-core/releases/tag/v4.16.0
requires:
-
name: "miniz"
Expand Down Expand Up @@ -1016,7 +1027,7 @@ sdks:
distribution-type: source code
distribution-repository: GitHub release
package-name: C-Core
location: https://github.com/pubnub/c-core/releases/tag/v4.15.0
location: https://github.com/pubnub/c-core/releases/tag/v4.16.0
requires:
-
name: "miniz"
Expand Down Expand Up @@ -1078,7 +1089,7 @@ sdks:
distribution-type: source code
distribution-repository: GitHub release
package-name: C-Core
location: https://github.com/pubnub/c-core/releases/tag/v4.15.0
location: https://github.com/pubnub/c-core/releases/tag/v4.16.0
requires:
-
name: "miniz"
Expand Down Expand Up @@ -1139,7 +1150,7 @@ sdks:
distribution-type: source code
distribution-repository: GitHub release
package-name: C-Core
location: https://github.com/pubnub/c-core/releases/tag/v4.15.0
location: https://github.com/pubnub/c-core/releases/tag/v4.16.0
requires:
-
name: "miniz"
Expand Down Expand Up @@ -1195,7 +1206,7 @@ sdks:
distribution-type: source code
distribution-repository: GitHub release
package-name: C-Core
location: https://github.com/pubnub/c-core/releases/tag/v4.15.0
location: https://github.com/pubnub/c-core/releases/tag/v4.16.0
requires:
-
name: "miniz"
Expand Down Expand Up @@ -1248,7 +1259,7 @@ sdks:
distribution-type: source code
distribution-repository: GitHub release
package-name: C-Core
location: https://github.com/pubnub/c-core/releases/tag/v4.15.0
location: https://github.com/pubnub/c-core/releases/tag/v4.16.0
requires:
-
name: "miniz"
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
## v4.16.0
December 25 2024

#### Added
- Additional flags for C/CPP can be set with: `USER_C_FLAGS` / `USER_CXX_FLAGS`.

#### Fixed
- Fix because of which one of the source files has been missed for Windows.
- Fix issue with unsupported concatenation of sources files / definitions (`+=`).

#### Modified
- Refactor our `Makefiles` from different folders and platforms to use `include` directives to include shared definitions, flags, source files.

## v4.15.0
November 25 2024

Expand Down
34 changes: 17 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ 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_SUBSCRIBE_V2 "Use subscribe v2" ON)
num_option(USE_SUBSCRIBE_EVENT_ENGINE "Use Subscribe Event Engine" OFF)
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)
num_option(USE_OBJECTS_API "Use objects API" ON)
num_option(USE_AUTO_HEARTBEAT "Use auto heartbeat" ON)
num_option(USE_ACTIONS_API "Use actions API" ON)
num_option(USE_REVOKE_TOKEN_API "Use revoke token API" OFF)
num_option(USE_GRANT_TOKEN_API "Use grant token API" OFF)
num_option(USE_REVOKE_TOKEN_API "Use revoke token API [OPENSSL ONLY]" OFF)
num_option(USE_GRANT_TOKEN_API "Use grant token API [OPENSSL ONLY]" OFF)
num_option(USE_FETCH_HISTORY "Use fetch history" ON)
num_option(USE_CRYPTO_API "Use crypto API [OPENSSL ONLY]" OFF)
num_option(USE_CALLBACK_API "Use callback API [CALLBACK=ON SYNC=OFF]" ${DEFAULT_USE_CALLBACK_API})
num_option(USE_IPV6 "Use IPv6 [CALLBACK=ON]" ${DEFAULT_USE_CALLBACK_API})
num_option(USE_IPV6 "Use IPv6" ON)
num_option(USE_SET_DNS_SERVERS "Use set DNS servers [CALLBACK=ON]" ${DEFAULT_USE_CALLBACK_API})
num_option(USE_EXTERN_API "Use extern C API [WITH_CPP=ON]" ON)
num_option(USE_LEGACY_CRYPTO_RANDOM_IV "Use random IV for legacy crypto module [OpenSSL only]" ON)
Expand Down Expand Up @@ -112,6 +112,14 @@ set(FLAGS "\
-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 "\
${FLAGS} \
-D _WINSOCKAPI_")
endif()


set(LDLIBS)
set(OS_SOURCEFILES)

Expand Down Expand Up @@ -277,19 +285,11 @@ if(${USE_CALLBACK_API})
${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)
if (${OPENSSL})
set(INTF_SOURCEFILES
${INTF_SOURCEFILES}
${CMAKE_CURRENT_LIST_DIR}/openssl/pubnub_ntf_callback_windows.c
${CMAKE_CURRENT_LIST_DIR}/openssl/pubnub_dns_system_servers.c
${CMAKE_CURRENT_LIST_DIR}/openssl/pubnub_get_native_socket.c)
else()
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()
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")
Expand Down
119 changes: 75 additions & 44 deletions core/pbcc_fetch_history.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,58 +18,87 @@


enum pubnub_res pbcc_fetch_history_prep(struct pbcc_context* pb,
const char* channel,
unsigned int max_per_channel,
enum pubnub_tribool include_meta,
enum pubnub_tribool include_custom_message_type,
enum pubnub_tribool include_message_type,
enum pubnub_tribool include_user_id,
enum pubnub_tribool include_message_actions,
enum pubnub_tribool reverse,
char const* start,
char const* end)
const char* channel,
unsigned int max_per_channel,
enum pubnub_tribool include_meta,
enum pubnub_tribool
include_custom_message_type,
enum pubnub_tribool
include_message_type,
enum pubnub_tribool include_user_id,
enum pubnub_tribool
include_message_actions,
enum pubnub_tribool reverse,
char const* start,
char const* end)
{
char const* const uname = pubnub_uname();
enum pubnub_res rslt = PNR_OK;
enum pubnub_res rslt = PNR_OK;

pb->http_content_len = 0;
pb->msg_ofs = pb->msg_end = 0;
pb->msg_ofs = pb->msg_end = 0;

pb->http_buf_len = snprintf(pb->http_buf,
sizeof pb->http_buf,
"/v3/%s/sub-key/%s/channel/",
(include_message_actions == pbccTrue) ? "history-with-actions" : "history",
(include_message_actions == pbccTrue)
? "history-with-actions"
: "history",
pb->subscribe_key);
APPEND_URL_ENCODED_M(pb, channel);

URL_PARAMS_INIT(qparam, PUBNUB_MAX_URL_PARAMS);
if (uname) { ADD_URL_PARAM(qparam, pnsdk, uname); }

int ch_count = 0;
char* ch_lst = (char*)strtok((char*)channel, ",");
int ch_count = 0;
char* ch_lst = (char*)strtok((char*)channel, ",");
while (ch_lst != NULL) {
ch_count++;
ch_lst = (char*)strtok(NULL, ",");
}
if (max_per_channel <= 0) {
if (include_message_actions == pbccTrue || ch_count > 1) { max_per_channel = 25; }
else {max_per_channel = 100; }
if (include_message_actions == pbccTrue || ch_count > 1) {
max_per_channel = 25;
}
else { max_per_channel = 100; }
}
char max_per_ch_cnt_buf[sizeof(int) * 4 + 1];
sprintf(max_per_ch_cnt_buf, "%d", max_per_channel);
snprintf(max_per_ch_cnt_buf,
sizeof(max_per_ch_cnt_buf),
"%d",
max_per_channel);
if (max_per_channel) { ADD_URL_PARAM(qparam, max, max_per_ch_cnt_buf); }

if (include_meta != pbccNotSet) { ADD_URL_PARAM(qparam, include_meta, include_meta == pbccTrue ? "true" : "false"); }
if (include_custom_message_type != pbccNotSet) { ADD_URL_PARAM(qparam, include_custom_message_type, include_custom_message_type == pbccTrue ? "true" : "false"); }
if (include_message_type != pbccNotSet) { ADD_URL_PARAM(qparam, include_message_type, include_message_type == pbccTrue ? "true" : "false"); }
if (include_user_id != pbccNotSet) { ADD_URL_PARAM(qparam, include_uuid, include_user_id == pbccTrue ? "true" : "false"); }
if (include_meta != pbccNotSet) {
ADD_URL_PARAM(qparam,
include_meta,
include_meta == pbccTrue ? "true" : "false");
}
if (include_custom_message_type != pbccNotSet) {
ADD_URL_PARAM(qparam,
include_custom_message_type,
include_custom_message_type == pbccTrue ? "true" :
"false");
}
if (include_message_type != pbccNotSet) {
ADD_URL_PARAM(qparam,
include_message_type,
include_message_type == pbccTrue ? "true" : "false");
}
if (include_user_id != pbccNotSet) {
ADD_URL_PARAM(qparam,
include_uuid,
include_user_id == pbccTrue ? "true" : "false");
}
#if PUBNUB_CRYPTO_API
if (pb->secret_key == NULL) { ADD_URL_AUTH_PARAM(pb, qparam, auth); }
ADD_TS_TO_URL_PARAM();
#else
ADD_URL_AUTH_PARAM(pb, qparam, auth);
#endif
if (reverse != pbccNotSet) { ADD_URL_PARAM(qparam, reverse, reverse == pbccTrue ? "true" : "false"); }
if (reverse != pbccNotSet) {
ADD_URL_PARAM(qparam, reverse, reverse == pbccTrue ? "true" : "false");
}
if (start) { ADD_URL_PARAM(qparam, start, start); }
if (end) { ADD_URL_PARAM(qparam, end, end); }

Expand All @@ -89,37 +118,39 @@ enum pubnub_res pbcc_fetch_history_prep(struct pbcc_context* pb,

enum pubnub_res pbcc_parse_fetch_history_response(struct pbcc_context* pb)
{
char* reply = pb->http_reply;
int replylen = pb->http_buf_len;
char* reply = pb->http_reply;
int replylen = pb->http_buf_len;
struct pbjson_elem elem;

if ((replylen < 2) || (reply[0] != '{')) {
return PNR_FORMAT_ERROR;
}

pb->msg_end = replylen + 1;

elem.end = pbjson_find_end_element(reply, reply + replylen);
/* elem.end has to be just behind end curly brace */
if ((*reply != '{') || (*(elem.end++) != '}')) {
PUBNUB_LOG_ERROR("pbcc_parse_fetch_history_response(pbcc=%p) - Invalid: "
"response from server is not JSON - response='%s'\n",
pb,
reply);
PUBNUB_LOG_ERROR(
"pbcc_parse_fetch_history_response(pbcc=%p) - Invalid: "
"response from server is not JSON - response='%s'\n",
pb,
reply);

return PNR_FORMAT_ERROR;
}
elem.start = reply;

if (pbjson_value_for_field_found(&elem, "status", "403")){
PUBNUB_LOG_ERROR("pbcc_parse_fetch_history_response(pbcc=%p) - AccessDenied: "
"response from server - response='%s'\n",
pb,
reply);
if (pbjson_value_for_field_found(&elem, "status", "403")) {
PUBNUB_LOG_ERROR(
"pbcc_parse_fetch_history_response(pbcc=%p) - AccessDenied: "
"response from server - response='%s'\n",
pb,
reply);
return PNR_ACCESS_DENIED;
}

if (pbjson_value_for_field_found(&elem, "error", "true")){
if (pbjson_value_for_field_found(&elem, "error", "true")) {
PUBNUB_LOG_ERROR("pbcc_parse_fetch_history_response(pbcc=%p) - Error: "
"response from server - response='%s'\n",
pb,
Expand All @@ -132,9 +163,9 @@ enum pubnub_res pbcc_parse_fetch_history_response(struct pbcc_context* pb)

pubnub_chamebl_t pbcc_get_fetch_history(struct pbcc_context* pb)
{
pubnub_chamebl_t result;
char const* reply = pb->http_reply;
int replylen = pb->http_buf_len;
pubnub_chamebl_t result;
char const* reply = pb->http_reply;
int replylen = pb->http_buf_len;
struct pbjson_elem elem;
if (pb->last_result != PNR_OK) {
PUBNUB_LOG_ERROR("pbcc_get_fetch_history(pb=%p) can be called only if "
Expand All @@ -144,16 +175,16 @@ pubnub_chamebl_t pbcc_get_fetch_history(struct pbcc_context* pb)
PBTT_FETCH_HISTORY,
pb->last_result,
pubnub_res_2_string(pb->last_result));
result.ptr = NULL;
result.ptr = NULL;
result.size = 0;
return result;
}

elem.start = reply;
elem.end = pbjson_find_end_element(reply, reply + replylen) + 1;
elem.end = pbjson_find_end_element(reply, reply + replylen) + 1;

result.size = elem.end - elem.start;
result.ptr = (char*)elem.start;
result.size = elem.end - elem.start;
result.ptr = (char*)elem.start;
result.ptr[result.size] = '\0';

return result;
Expand Down
Loading
Loading