diff --git a/.pubnub.yml b/.pubnub.yml index 3da3c1d2..57513eaa 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,7 +1,17 @@ name: c-core -version: 2.10.2 +schema: 1 +version: 2.11.0 scm: github.com/pubnub/c-core changelog: + - version: v2.11.0 + date: Oct 20, 2019 + changes: + - type: enhancement + text: Introduce Actions API + - type: bug + text: Fix stopwatch not working after 25 days + - type: ehnancement + text: Add 'include_meta' parameter to pubnub_history_ex() - version: v2.10.2 date: Oct 18, 2019 changes: @@ -111,9 +121,9 @@ changelog: - type: enhancement text: Update Qt functional tests and make them reliable - type: enhancement - text: UUID is now part of the Pubnub context (instead of a pointer to it). This makes handling its lifetime easier, yet doesn't incur much memory increase + text: UUID is now part of the Pubnub context (instead of a pointer to it). This makes handling its lifetime easier, yet does not incur much memory increase - type: bug - text: C++ wrapper and Qt did not have proper multithreading support as they did not protect _their_ data. Now that's fixed. + text: C++ wrapper and Qt did not have proper multithreading support as they did not protect _their_ data. Now that is fixed. - version: v2.6.2 date: Dec 20, 2018 changes: @@ -372,37 +382,72 @@ features: - PUBLISH-RAW-JSON - PUBLISH-WITH-METADATA - PUBLISH-GET + - PUBLISH-POST - PUBLISH-SYNC - PUBLISH-ASYNC - - SIGNAL-SEND + - PUBLISH-FIRE + - PUBLISH-REPLICATION-FLAG storage: - STORAGE-INCLUDE-TIMETOKEN - STORAGE-COUNT - STORAGE-REVERSE - STORAGE-START-END - STORAGE-MESSAGE-COUNT - time: - - TIME-TIME + - STORAGE-HISTORY-WITH-META + - STORAGE-FETCH-WITH-META + - STORAGE-FETCH-WITH-MESSAGE-ACTIONS subscribe: - SUBSCRIBE-CHANNELS - SUBSCRIBE-CHANNEL-GROUPS - SUBSCRIBE-PRESENCE-CHANNELS - SUBSCRIBE-PRESENCE-CHANNELS-GROUPS - SUBSCRIBE-WILDCARD + - SUBSCRIBE-FILTER-EXPRESSION - SUBSCRIBE-SIGNAL-LISTENER + - SUBSCRIBE-USER-LISTENER + - SUBSCRIBE-SPACE-LISTENER + - SUBSCRIBE-MEMBERSHIP-LISTENER + - SUBSCRIBE-MESSAGE-ACTIONS-LISTENER + signal: + - SIGNAL-SEND + objects: + - OBJECTS-GET-USER + - OBJECTS-GET-USERS + - OBJECTS-CREATE-USER + - OBJECTS-UPDATE-USER + - OBJECTS-DELETE-USER + - OBJECTS-GET-SPACE + - OBJECTS-GET-SPACES + - OBJECTS-CREATE-SPACE + - OBJECTS-UPDATE-SPACE + - OBJECTS-DELETE-SPACE + - OBJECTS-GET-MEMBERSHIPS + - OBJECTS-JOIN-SPACES + - OBJECTS-UPDATE-MEMBERSHIPS + - OBJECTS-LEAVE-SPACES + - OBJECTS-GET-MEMBERS + - OBJECTS-ADD-MEMBERS + - OBJECTS-UPDATE-MEMBERS + - OBJECTS-REMOVE-MEMBERS + message-actions: + - MESSAGE-ACTIONS-GET + - MESSAGE-ACTIONS-ADD + - MESSAGE-ACTIONS-REMOVE + time: + - TIME-TIME supported-platforms: - version: PubNub POSIX C SDK platforms: - Most modern Unix-derived OSes support enough of POSIX to work. For some, like MacOS (OSX) we have special support to handle them not being fully POSIX compliant. Basically, if the OS is released in last 3/4 years, it will most probably work. - Some older OSes, like Ubuntu 12.04 or older, may need a few tweaks to work. - - For TLS/SSL support, we use OpenSSL, and a recent version, 0.9.8 or higher should work. If the user doesn't wish to use TLS/SSL, she doesn't need OpenSSL at all. + - For TLS/SSL support, we use OpenSSL, and a recent version, 0.9.8 or higher should work. If the user doe snot wish to use TLS/SSL, she does not need OpenSSL at all. - version: PubNub POSIX C++ SDK platforms: - Most modern Unix-derived OSes support enough of POSIX to work. For some, like MacOS (OSX) we have special support to handle them not being fully POSIX compliant. Basically, if the OS is released in last 3/4 years, it will most probably work. - Some older OSes, like Ubuntu 12.04 or older, may need a few tweaks to work. - - For TLS/SSL support, we use OpenSSL, and a recent version, 0.9.8 or higher should work. If the user doesn't wish to use TLS/SSL, she doesn't need OpenSSL at all. + - For TLS/SSL support, we use OpenSSL, and a recent version, 0.9.8 or higher should work. If the user does not wish to use TLS/SSL, she does not need OpenSSL at all. - Some features require C++11 or newer compliant compiler, if you do not have such a compiler you will not be able to use those features (but will be able to use the rest of the POSIX C++ SDK) - version: PubNub Windows C SDK @@ -413,7 +458,7 @@ supported-platforms: version: PubNub Windows C++ SDK platforms: - Windows 7 or newer with Visual Studio 2008 or newer should work. Newer versions of Clang for Windows and GCC (MINGW or Cygwin) should also work. - - For TLS/SSL support, we use OpenSSL, and a recent version, 0.9.8 or higher should work. If the user doesn't wish to use TLS/SSL, she doesn't need OpenSSL at all. + - For TLS/SSL support, we use OpenSSL, and a recent version, 0.9.8 or higher should work. If the user doesn't wish to use TLS/SSL, she does not need OpenSSL at all. - Some features require C++11 or newer compliant compiler, if you do not have such a compiler you will not be able to use those features (but will be able to use the rest of the Windows C++ SDK) - version: PubNub FreeRTOS SDK diff --git a/core/pbcc_actions_api.c b/core/pbcc_actions_api.c index bf1f6d73..ba0ef07e 100644 --- a/core/pbcc_actions_api.c +++ b/core/pbcc_actions_api.c @@ -20,7 +20,7 @@ enum pubnub_res pbcc_form_the_action_object(struct pbcc_context* pb, char* obj_buffer, size_t buffer_size, enum pubnub_action_type actype, - char const** json) + char const** val) { char const* uuid = pbcc_uuid_get(pb); char const* type_literal; @@ -28,6 +28,14 @@ enum pubnub_res pbcc_form_the_action_object(struct pbcc_context* pb, PUBNUB_LOG_ERROR("pbcc_form_the_action_object(pbcc=%p) - uuid not set.\n", pb); return PNR_INVALID_PARAMETERS; } + if (('\"' != **val) || ('\"' != *(*val + pb_strnlen_s(*val, PUBNUB_MAX_OBJECT_LENGTH) - 1))) { + PUBNUB_LOG_ERROR("pbcc_form_the_action_object(pbcc=%p) - " + "quotation marks on value ends are missing: " + "value = %s\n", + pb, + *val); + return PNR_INVALID_PARAMETERS; + } switch(actype) { case pbactypReaction: type_literal = "reaction"; @@ -47,7 +55,7 @@ enum pubnub_res pbcc_form_the_action_object(struct pbcc_context* pb, } if (buffer_size < sizeof("{\"type\":\"\",\"value\":,\"uuid\":\"\"}") + pb_strnlen_s(type_literal, sizeof "reaction") + - pb_strnlen_s(*json, PUBNUB_MAX_OBJECT_LENGTH) + + pb_strnlen_s(*val, PUBNUB_MAX_OBJECT_LENGTH) + pb_strnlen_s(uuid, sizeof pb->uuid)) { PUBNUB_LOG_ERROR("pbcc_form_the_action_object(pbcc=%p) - " "buffer size is too small: " @@ -57,7 +65,7 @@ enum pubnub_res pbcc_form_the_action_object(struct pbcc_context* pb, (unsigned long)buffer_size, (unsigned long)(sizeof("{\"type\":\"\",\"value\":,\"uuid\":\"\"}") + pb_strnlen_s(type_literal, sizeof "reaction") + - pb_strnlen_s(*json, PUBNUB_MAX_OBJECT_LENGTH) + + pb_strnlen_s(*val, PUBNUB_MAX_OBJECT_LENGTH) + pb_strnlen_s(uuid, sizeof pb->uuid))); return PNR_TX_BUFF_TOO_SMALL; } @@ -65,9 +73,9 @@ enum pubnub_res pbcc_form_the_action_object(struct pbcc_context* pb, buffer_size, "{\"type\":\"%s\",\"value\":%s,\"uuid\":\"%s\"}", type_literal, - *json, + *val, uuid); - *json = obj_buffer; + *val = obj_buffer; return PNR_OK; } @@ -89,7 +97,7 @@ enum pubnub_res pbcc_add_action_prep(struct pbcc_context* pb, pb->msg_ofs = pb->msg_end = 0; pb->http_buf_len = snprintf(pb->http_buf, sizeof pb->http_buf, - "/v1/actions/%s/channel/", + "/v1/message-actions/%s/channel/", pb->subscribe_key); APPEND_URL_ENCODED_M(pb, channel); APPEND_URL_LITERAL_M(pb, "/message/"); @@ -189,27 +197,48 @@ pubnub_chamebl_t pbcc_get_action_timetoken(struct pbcc_context* pb) enum pubnub_res pbcc_remove_action_prep(struct pbcc_context* pb, char const* channel, - char const* message_timetoken, - char const* action_timetoken) + pubnub_chamebl_t message_timetoken, + pubnub_chamebl_t action_timetoken) { char const* const uname = pubnub_uname(); char const* uuid = pbcc_uuid_get(pb); PUBNUB_ASSERT_OPT(channel != NULL); - PUBNUB_ASSERT_OPT(message_timetoken != NULL); - PUBNUB_ASSERT_OPT(action_timetoken != NULL); + PUBNUB_ASSERT_OPT(message_timetoken.ptr != NULL); + PUBNUB_ASSERT_OPT(action_timetoken.ptr != NULL); + + if ((*message_timetoken.ptr != '\"') || + (*(message_timetoken.ptr + message_timetoken.size - 1) != '\"')) { + PUBNUB_LOG_ERROR("pbcc_remove_action_prep(pbcc=%p) - " + "message timetoken is missing quotation marks: " + "message_timetoken = %.*s\n", + pb, + (int)message_timetoken.size, + message_timetoken.ptr); + return PNR_INVALID_PARAMETERS; + } + if ((*action_timetoken.ptr != '\"') || + (*(action_timetoken.ptr + action_timetoken.size - 1) != '\"')) { + PUBNUB_LOG_ERROR("pbcc_remove_action_prep(pbcc=%p) - " + "action timetoken is missing quotation marks: " + "action_timetoken = %.*s\n", + pb, + (int)action_timetoken.size, + action_timetoken.ptr); + return PNR_INVALID_PARAMETERS; + } pb->http_content_len = 0; pb->msg_ofs = pb->msg_end = 0; pb->http_buf_len = snprintf(pb->http_buf, sizeof pb->http_buf, - "/v1/actions/%s/channel/", + "/v1/message-actions/%s/channel/", pb->subscribe_key); APPEND_URL_ENCODED_M(pb, channel); APPEND_URL_LITERAL_M(pb, "/message/"); - APPEND_URL_ENCODED_M(pb, message_timetoken); + APPEND_URL_STRING_M(pb, message_timetoken.ptr + 1, message_timetoken.size - 2); APPEND_URL_LITERAL_M(pb, "/action/"); - APPEND_URL_ENCODED_M(pb, action_timetoken); + APPEND_URL_STRING_M(pb, action_timetoken.ptr + 1, action_timetoken.size - 2); APPEND_URL_PARAM_M(pb, "pnsdk", uname, '?'); APPEND_URL_PARAM_M(pb, "uuid", uuid, '&'); APPEND_URL_PARAM_M(pb, "auth", pb->auth, '&'); @@ -228,13 +257,13 @@ enum pubnub_res pbcc_get_actions_prep(struct pbcc_context* pb, char const* uuid = pbcc_uuid_get(pb); PUBNUB_ASSERT_OPT(channel != NULL); - PUBNUB_ASSERT_OPT(limit < MAX_ACTIONS_LIMIT); + PUBNUB_ASSERT_OPT(limit <= MAX_ACTIONS_LIMIT); pb->http_content_len = 0; pb->msg_ofs = pb->msg_end = 0; pb->http_buf_len = snprintf(pb->http_buf, sizeof pb->http_buf, - "/v1/actions/%s/channel/", + "/v1/message-actions/%s/channel/", pb->subscribe_key); APPEND_URL_ENCODED_M(pb, channel); APPEND_URL_PARAM_M(pb, "pnsdk", uname, '?'); @@ -242,7 +271,9 @@ enum pubnub_res pbcc_get_actions_prep(struct pbcc_context* pb, APPEND_URL_PARAM_M(pb, "auth", pb->auth, '&'); APPEND_URL_PARAM_M(pb, "start", start, '&'); APPEND_URL_PARAM_M(pb, "end", end, '&'); - APPEND_URL_PARAM_UNSIGNED_M(pb, "limit", (unsigned)limit, '&'); + if (limit != 0) { + APPEND_URL_PARAM_UNSIGNED_M(pb, "limit", (unsigned)limit, '&'); + } return PNR_STARTED; } @@ -282,13 +313,22 @@ enum pubnub_res pbcc_get_actions_more_prep(struct pbcc_context* pb) return PNR_FORMAT_ERROR; } + json_rslt = pbjson_get_object_value(&parsed, "url", &elem); + if (json_rslt != jonmpOK) { + PUBNUB_LOG_ERROR("pbcc_get_actions_more_prep(pbcc=%p) - Invalid response: " + "pbjson_get_object_value(\"url\") reported an error: %s\n", + pb, + pbjson_object_name_parse_result_2_string(json_rslt)); + + return PNR_FORMAT_ERROR; + } pb->http_content_len = 0; pb->msg_ofs = pb->msg_end = 0; pb->http_buf_len = snprintf(pb->http_buf, sizeof pb->http_buf, "%.*s", - (int)(parsed.end - parsed.start - 2), - parsed.start + 1); + (int)(elem.end - elem.start - 2), + elem.start + 1); APPEND_URL_PARAM_M(pb, "pnsdk", uname, '&'); APPEND_URL_PARAM_M(pb, "uuid", uuid, '&'); APPEND_URL_PARAM_M(pb, "auth", pb->auth, '&'); @@ -307,13 +347,13 @@ enum pubnub_res pbcc_history_with_actions_prep(struct pbcc_context* pb, char const* uuid = pbcc_uuid_get(pb); PUBNUB_ASSERT_OPT(channel != NULL); - PUBNUB_ASSERT_OPT(limit < MAX_ACTIONS_LIMIT); + PUBNUB_ASSERT_OPT(limit <= MAX_ACTIONS_LIMIT); pb->http_content_len = 0; pb->msg_ofs = pb->msg_end = 0; pb->http_buf_len = snprintf(pb->http_buf, sizeof pb->http_buf, - "/v1/history-with-actions/%s/channel/", + "/v3/history-with-actions/sub-key/%s/channel/", pb->subscribe_key); APPEND_URL_ENCODED_M(pb, channel); APPEND_URL_PARAM_M(pb, "pnsdk", uname, '?'); @@ -321,7 +361,9 @@ enum pubnub_res pbcc_history_with_actions_prep(struct pbcc_context* pb, APPEND_URL_PARAM_M(pb, "auth", pb->auth, '&'); APPEND_URL_PARAM_M(pb, "start", start, '&'); APPEND_URL_PARAM_M(pb, "end", end, '&'); - APPEND_URL_PARAM_UNSIGNED_M(pb, "limit", (unsigned)limit, '&'); + if (limit != 0) { + APPEND_URL_PARAM_UNSIGNED_M(pb, "limit", (unsigned)limit, '&'); + } return PNR_STARTED; } diff --git a/core/pbcc_actions_api.h b/core/pbcc_actions_api.h index 2962eff9..11457149 100644 --- a/core/pbcc_actions_api.h +++ b/core/pbcc_actions_api.h @@ -51,8 +51,8 @@ pubnub_chamebl_t pbcc_get_action_timetoken(struct pbcc_context* pb); */ enum pubnub_res pbcc_remove_action_prep(struct pbcc_context* pb, char const* channel, - char const* message_timetoken, - char const* action_timetoken); + pubnub_chamebl_t message_timetoken, + pubnub_chamebl_t action_timetoken); /** Prepares the 'get_actions' transaction, mostly by formatting the URI of the HTTP request. diff --git a/core/pubnub_actions_api.c b/core/pubnub_actions_api.c index 04a4a1a4..d556eef0 100644 --- a/core/pubnub_actions_api.c +++ b/core/pubnub_actions_api.c @@ -13,17 +13,18 @@ #include #include - -enum pubnub_res pubnub_add_action(pubnub_t* pb, - char const* channel, - char const* message_timetoken, - enum pubnub_action_type actype, + +enum pubnub_res pubnub_add_message_action(pubnub_t* pb, + char const* channel, + char const* message_timetoken, + enum pubnub_action_type actype, char const* value) { enum pubnub_res rslt; char obj_buffer[PUBNUB_BUF_MAXLEN]; PUBNUB_ASSERT(pb_valid_ctx_ptr(pb)); + PUBNUB_ASSERT(value != NULL); pubnub_mutex_lock(pb->monitor); if (!pbnc_can_start_transaction(pb)) { @@ -43,8 +44,8 @@ enum pubnub_res pubnub_add_action(pubnub_t* pb, value = (pbgzip_compress(pb, value) == PNR_OK) ? pb->core.gzip_msg_buf : value; #endif rslt = pbcc_add_action_prep(&pb->core, - channel, - message_timetoken, + channel, + message_timetoken, value); if (PNR_STARTED == rslt) { pb->trans = PBTT_ADD_ACTION; @@ -84,7 +85,7 @@ pubnub_chamebl_t pubnub_get_message_timetoken(pubnub_t* pb) } -pubnub_chamebl_t pubnub_get_action_timetoken(pubnub_t* pb) +pubnub_chamebl_t pubnub_get_message_action_timetoken(pubnub_t* pb) { pubnub_chamebl_t result; PUBNUB_ASSERT(pb_valid_ctx_ptr(pb)); @@ -109,10 +110,10 @@ pubnub_chamebl_t pubnub_get_action_timetoken(pubnub_t* pb) } -enum pubnub_res pubnub_remove_action(pubnub_t* pb, +enum pubnub_res pubnub_remove_message_action(pubnub_t* pb, char const* channel, - char const* message_timetoken, - char const* action_timetoken) + pubnub_chamebl_t message_timetoken, + pubnub_chamebl_t action_timetoken) { enum pubnub_res rslt; @@ -125,8 +126,8 @@ enum pubnub_res pubnub_remove_action(pubnub_t* pb, } rslt = pbcc_remove_action_prep(&pb->core, - channel, - message_timetoken, + channel, + message_timetoken, action_timetoken); if (PNR_STARTED == rslt) { pb->trans = PBTT_REMOVE_ACTION; @@ -141,7 +142,7 @@ enum pubnub_res pubnub_remove_action(pubnub_t* pb, } -enum pubnub_res pubnub_get_actions(pubnub_t* pb, +enum pubnub_res pubnub_get_message_actions(pubnub_t* pb, char const* channel, char const* start, char const* end, @@ -170,7 +171,7 @@ enum pubnub_res pubnub_get_actions(pubnub_t* pb, } -enum pubnub_res pubnub_get_actions_more(pubnub_t* pb) +enum pubnub_res pubnub_get_message_actions_more(pubnub_t* pb) { enum pubnub_res rslt; @@ -204,7 +205,7 @@ enum pubnub_res pubnub_get_actions_more(pubnub_t* pb) } -enum pubnub_res pubnub_history_with_actions(pubnub_t* pb, +enum pubnub_res pubnub_history_with_message_actions(pubnub_t* pb, char const* channel, char const* start, char const* end, @@ -233,7 +234,7 @@ enum pubnub_res pubnub_history_with_actions(pubnub_t* pb, } -enum pubnub_res pubnub_history_with_actions_more(pubnub_t* pb) +enum pubnub_res pubnub_history_with_message_actions_more(pubnub_t* pb) { enum pubnub_res rslt; diff --git a/core/pubnub_actions_api.h b/core/pubnub_actions_api.h index ef2f2382..1de200ce 100644 --- a/core/pubnub_actions_api.h +++ b/core/pubnub_actions_api.h @@ -9,20 +9,23 @@ /** Adds new type of message called action as a support for user reactions on a published messages. + Json string @p value is checked for its quotation marks at its ends. If any of the + quotation marks is missing function returns parameter error. If the transaction is finished successfully response will have 'data' field with added action data. If there is no data, nor error description in the response, response parsing function returns format error. @param pb The pubnub context. Can't be NULL @param channel The channel on which action is referring to. - @param message_timetoken The timetoken of a published message action is applying to + @param message_timetoken The timetoken(unquoted) of a published message action is + applying to @param actype Action type - @param value Json object describing the action that is to be added + @param value Json string describing the action that is to be added @return #PNR_STARTED on success, an error otherwise */ -enum pubnub_res pubnub_add_action(pubnub_t* pb, - char const* channel, - char const* message_timetoken, - enum pubnub_action_type actype, +enum pubnub_res pubnub_add_message_action(pubnub_t* pb, + char const* channel, + char const* message_timetoken, + enum pubnub_action_type actype, char const* value); @@ -33,8 +36,8 @@ enum pubnub_res pubnub_add_action(pubnub_t* pb, or error was encountered, returned structure has 0 'size' field and NULL 'ptr' field. @param pb The pubnub context. Can't be NULL - @return Structured pointer to memory block containing message timetoken value within the - context response buffer + @return Structured pointer to memory block containing message timetoken value(including + its quotation marks) within the context response buffer */ pubnub_chamebl_t pubnub_get_message_timetoken(pubnub_t* pb); @@ -45,10 +48,10 @@ pubnub_chamebl_t pubnub_get_message_timetoken(pubnub_t* pb); If key expected is not found, preconditions were not fulfilled, or error was encountered, returned structure has 0 'size' field and NULL 'ptr' field. @param pb The pubnub context. Can't be NULL - @return Structured pointer to memory block containing action timetoken value within the - context response buffer + @return Structured pointer to memory block containing action timetoken value(including + its quotation marks) within the context response buffer */ -pubnub_chamebl_t pubnub_get_action_timetoken(pubnub_t* pb); +pubnub_chamebl_t pubnub_get_message_action_timetoken(pubnub_t* pb); /** Initiates transaction that deletes(removes) previously added action on a published message. @@ -57,15 +60,17 @@ pubnub_chamebl_t pubnub_get_action_timetoken(pubnub_t* pb); @param pb The pubnub context. Can't be NULL @param channel The channel on which action was previously added. @param message_timetoken The timetoken of a published message action was applied to. - (Obtained from the response when action was added) + (Obtained from the response when action was added and expected + with its quotation marks at both ends) @param action_timetoken The action timetoken when it was added(Gotten from the transaction - response when action was added) + response when action was added and expected with its quotation + marks at both ends) @return #PNR_STARTED on success, an error otherwise */ -enum pubnub_res pubnub_remove_action(pubnub_t* pb, +enum pubnub_res pubnub_remove_message_action(pubnub_t* pb, char const* channel, - char const* message_timetoken, - char const* action_timetoken); + pubnub_chamebl_t message_timetoken, + pubnub_chamebl_t action_timetoken); /** Initiates transaction that returns all actions added on a given @p channel between @p start @@ -77,14 +82,16 @@ enum pubnub_res pubnub_remove_action(pubnub_t* pb, format error. @param pb The pubnub context. Can't be NULL @param channel The channel on which actions are observed. - @param start Start action timetoken. Can be NULL meaning there is no lower limitation in time. - @param end End action timetoken. Can be NULL in which case upper time limit is present moment. + @param start Start action timetoken(unquoted). Can be NULL meaning there is no lower + limitation in time. + @param end End action timetoken(unquoted). Can be NULL in which case upper time limit is + present moment. @param limit Number of actions to return in response. Regular values 1 - 100. If you set `0`, that means “use the default”. At the time of this writing, default was 100. Any value greater than 100 is considered an error. @return #PNR_STARTED on success, an error otherwise */ -enum pubnub_res pubnub_get_actions(pubnub_t* pb, +enum pubnub_res pubnub_get_message_actions(pubnub_t* pb, char const* channel, char const* start, char const* end, @@ -105,7 +112,7 @@ enum pubnub_res pubnub_get_actions(pubnub_t* pb, @retval PNR_GOT_ALL_ACTIONS transaction successfully finished. @retval corresponding error otherwise */ -enum pubnub_res pubnub_get_actions_more(pubnub_t* pb); +enum pubnub_res pubnub_get_message_actions_more(pubnub_t* pb); /** Initiates transaction that returns all actions added on a given @p channel between @p start @@ -117,14 +124,16 @@ enum pubnub_res pubnub_get_actions_more(pubnub_t* pb); format error. @param pb The pubnub context. Can't be NULL @param channel The channel on which actions are observed. - @param start Start message timetoken. Can be NULL meaning there is no lower limitation in time. - @param end End message timetoken. Can be NULL in which case upper time limit is present moment. - @param limit Number of actions to return in response. Regular values 1 - 100. If you set `0`, - that means “use the default”. At the time of this writing, default was 100. - Any value greater than 100 is considered an error. + @param start Start message timetoken(unquoted). Can be NULL meaning there is no lower + limitation in time. + @param end End message timetoken(unquoted). Can be NULL in which case upper time limit + is present moment. + @param limit Number of messages to return in response. Regular values 1 - 100. If you + set `0`, that means “use the default”. At the time of this writing, default + was 100. Any value greater than 100 is considered an error. @return #PNR_STARTED on success, an error otherwise */ -enum pubnub_res pubnub_history_with_actions(pubnub_t* pb, +enum pubnub_res pubnub_history_with_message_actions(pubnub_t* pb, char const* channel, char const* start, char const* end, @@ -146,7 +155,7 @@ enum pubnub_res pubnub_history_with_actions(pubnub_t* pb, @retval PNR_GOT_ALL_ACTIONS transaction successfully finished. @retval corresponding error otherwise */ -enum pubnub_res pubnub_history_with_actions_more(pubnub_t* pb); +enum pubnub_res pubnub_history_with_message_actions_more(pubnub_t* pb); #endif /* !defined INC_PUBNUB_ACTIONS_API */ diff --git a/core/pubnub_ccore.c b/core/pubnub_ccore.c index 9d0d8ee5..4fa94b76 100644 --- a/core/pubnub_ccore.c +++ b/core/pubnub_ccore.c @@ -156,6 +156,7 @@ enum pubnub_res pbcc_history_prep(struct pbcc_context* pb, bool include_token, enum pubnub_tribool string_token, enum pubnub_tribool reverse, + enum pubnub_tribool include_meta, char const* start, char const* end) { @@ -179,6 +180,7 @@ enum pubnub_res pbcc_history_prep(struct pbcc_context* pb, APPEND_URL_PARAM_BOOL_M(pb, "include_token", include_token, '&'); APPEND_URL_PARAM_TRIBOOL_SIMBOL_M(pb, "stringtoken", string_token, '&'); APPEND_URL_PARAM_TRIBOOL_SIMBOL_M(pb, "reverse", reverse, '&'); + APPEND_URL_PARAM_TRIBOOL_SIMBOL_M(pb, "include_meta", include_meta, '&'); APPEND_URL_PARAM_M(pb, "start", start, '&'); APPEND_URL_PARAM_M(pb, "start", end, '&'); diff --git a/core/pubnub_ccore.h b/core/pubnub_ccore.h index f4e83b63..0308dfb3 100644 --- a/core/pubnub_ccore.h +++ b/core/pubnub_ccore.h @@ -85,6 +85,7 @@ enum pubnub_res pbcc_history_prep(struct pbcc_context* p, bool include_token, enum pubnub_tribool string_token, enum pubnub_tribool reverse, + enum pubnub_tribool include_meta, char const* start, char const* end); diff --git a/core/pubnub_ccore_pubsub.h b/core/pubnub_ccore_pubsub.h index acb84550..c5fb30bd 100644 --- a/core/pubnub_ccore_pubsub.h +++ b/core/pubnub_ccore_pubsub.h @@ -122,7 +122,7 @@ struct pbcc_context { } #define APPEND_URL_LITERAL_M_IMP(pbc, string_literal) \ - { \ + do { \ if ((pbc)->http_buf_len + sizeof(string_literal) > sizeof (pbc)->http_buf) {\ PUBNUB_LOG_ERROR("Error: Request buffer too small - cannot append url literal:\n"\ "current_buffer_size = %lu\n" \ @@ -133,10 +133,32 @@ struct pbcc_context { } \ strcpy((pbc)->http_buf + (pbc)->http_buf_len, (string_literal)); \ (pbc)->http_buf_len += sizeof(string_literal) - 1; \ - } + } while (0) #define APPEND_URL_LITERAL_M(pbc, string_literal) APPEND_URL_LITERAL_M_IMP(pbc, "" string_literal) +#define APPEND_URL_STRING_M(pbc, s, n) \ + do { \ + char const* M_s_ = s; \ + if (M_s_ != NULL) { \ + struct pbcc_context* M_pbc_ = pbc; \ + size_t M_n_ = n; \ + if (M_pbc_->http_buf_len + M_n_ > sizeof M_pbc_->http_buf) { \ + PUBNUB_LOG_ERROR("Error: Request buffer too small - cannot append url string:\n"\ + "current_buffer_size = %lu\n" \ + "required_buffer_size = %lu\n", \ + (unsigned long)(sizeof M_pbc_->http_buf), \ + (unsigned long)(M_pbc_->http_buf_len + 1 + M_n_));\ + return PNR_TX_BUFF_TOO_SMALL; \ + } \ + M_pbc_->http_buf_len += snprintf(M_pbc_->http_buf + M_pbc_->http_buf_len,\ + sizeof M_pbc_->http_buf - M_pbc_->http_buf_len - 1,\ + "%.*s", \ + (int)M_n_, \ + M_s_); \ + } \ + } while (0) + #define APPEND_URL_ENCODED_M(pbc, what) \ if ((what) != NULL) { \ enum pubnub_res rslt_ = pbcc_url_encode((pbc), (what)); \ diff --git a/core/pubnub_coreapi.c b/core/pubnub_coreapi.c index 876a152e..b6b18100 100644 --- a/core/pubnub_coreapi.c +++ b/core/pubnub_coreapi.c @@ -84,7 +84,7 @@ enum pubnub_res pubnub_history(pubnub_t* pb, } rslt = pbcc_history_prep( - &pb->core, channel, count, include_token, pbccNotSet, pbccNotSet, NULL, NULL); + &pb->core, channel, count, include_token, pbccNotSet, pbccNotSet, pbccNotSet, NULL, NULL); if (PNR_STARTED == rslt) { pb->trans = PBTT_HISTORY; pb->core.last_result = PNR_STARTED; diff --git a/core/pubnub_coreapi_ex.c b/core/pubnub_coreapi_ex.c index 2e2abe2b..51603e1c 100644 --- a/core/pubnub_coreapi_ex.c +++ b/core/pubnub_coreapi_ex.c @@ -203,6 +203,7 @@ struct pubnub_history_options pubnub_history_defopts(void) rslt.start = NULL; rslt.end = NULL; rslt.include_token = false; + rslt.include_meta = false; return rslt; } @@ -228,6 +229,7 @@ enum pubnub_res pubnub_history_ex(pubnub_t* pb, opt.include_token, opt.string_token ? pbccTrue : pbccFalse, opt.reverse ? pbccTrue : pbccFalse, + opt.include_meta ? pbccTrue : pbccFalse, opt.start, opt.end); if (PNR_STARTED == rslt) { diff --git a/core/pubnub_coreapi_ex.h b/core/pubnub_coreapi_ex.h index 88f1f2fa..b91a145d 100644 --- a/core/pubnub_coreapi_ex.h +++ b/core/pubnub_coreapi_ex.h @@ -214,10 +214,15 @@ struct pubnub_history_options { */ char const* end; /** If true to recieve a timetoken with each history - * message. If true, not timetokens per message. Defaults to + * message. If false, no timetokens per message. Defaults to * false. */ bool include_token; + /** If true to recieve metadata with each history + * message if any. If false, no metadata per message. Defaults to + * false. + */ + bool include_meta; }; diff --git a/core/pubnub_memory_block.c b/core/pubnub_memory_block.c new file mode 100644 index 00000000..1800494b --- /dev/null +++ b/core/pubnub_memory_block.c @@ -0,0 +1,12 @@ +/* -*- c-file-style:"stroustrup"; indent-tabs-mode: nil -*- */ +#include "pubnub_internal.h" +#include "pubnub_memory_block.h" +#include "lib/pb_strnlen_s.h" + +pubnub_chamebl_t pubnub_str_2_chamebl_t(char* str) +{ + pubnub_chamebl_t rslt; + rslt.ptr = str; + rslt.size = (NULL == str) ? 0 : pb_strnlen_s(str, PUBNUB_MAX_OBJECT_LENGTH); + return rslt; +} diff --git a/core/pubnub_memory_block.h b/core/pubnub_memory_block.h index 5675a55f..dca4b51e 100644 --- a/core/pubnub_memory_block.h +++ b/core/pubnub_memory_block.h @@ -49,5 +49,11 @@ typedef struct pubnub_byte_mem_block pubnub_bymebl_t; /** Helper typedef for a char memory block */ typedef struct pubnub_char_mem_block pubnub_chamebl_t; +/** Returns memory block for a given NUL terminated string. + Makes no allocations, nor copies. + Result 'ptr' field is equal to @p str and 'size' to its length. + In case @p str is NULL, the 'size' field becomes 0. + */ +pubnub_chamebl_t pubnub_str_2_chamebl_t(char* str); #endif /* !defined INC_PUBNUB_MEMORY_BLOCK */ diff --git a/core/pubnub_version_internal.h b/core/pubnub_version_internal.h index 04bc33bc..99be9213 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 "2.10.2" +#define PUBNUB_SDK_VERSION "2.11.0" #endif /* !defined INC_PUBNUB_VERSION_INTERNAL */ diff --git a/cpp/posix.mk b/cpp/posix.mk index ae7e1603..b3075867 100644 --- a/cpp/posix.mk +++ b/cpp/posix.mk @@ -1,4 +1,4 @@ -SOURCEFILES = ../core/pubnub_pubsubapi.c ../core/pubnub_coreapi.c ../core/pubnub_coreapi_ex.c ../core/pubnub_ccore_pubsub.c ../core/pubnub_ccore.c ../core/pubnub_netcore.c ../lib/sockets/pbpal_sockets.c ../lib/sockets/pbpal_resolv_and_connect_sockets.c ../lib/sockets/pbpal_handle_socket_error.c ../core/pubnub_alloc_std.c ../core/pubnub_assert_std.c ../core/pubnub_generate_uuid.c ../core/pubnub_blocking_io.c ../posix/posix_socket_blocking_io.c ../core/pubnub_timers.c ../core/pubnub_json_parse.c ../lib/md5/md5.c ../lib/base64/pbbase64.c ../lib/pb_strnlen_s.c ../core/pubnub_helper.c pubnub_version_posix.cpp ../posix/pubnub_generate_uuid_posix.c ../posix/pbpal_posix_blocking_io.c ../core/pubnub_free_with_timeout_std.c pubnub_subloop.cpp ../posix/msstopwatch_monotonic_clock.c ../core/pubnub_url_encode.c +SOURCEFILES = ../core/pubnub_pubsubapi.c ../core/pubnub_coreapi.c ../core/pubnub_coreapi_ex.c ../core/pubnub_ccore_pubsub.c ../core/pubnub_ccore.c ../core/pubnub_netcore.c ../lib/sockets/pbpal_sockets.c ../lib/sockets/pbpal_resolv_and_connect_sockets.c ../lib/sockets/pbpal_handle_socket_error.c ../core/pubnub_alloc_std.c ../core/pubnub_assert_std.c ../core/pubnub_generate_uuid.c ../core/pubnub_blocking_io.c ../posix/posix_socket_blocking_io.c ../core/pubnub_timers.c ../core/pubnub_json_parse.c ../lib/md5/md5.c ../lib/base64/pbbase64.c ../lib/pb_strnlen_s.c ../core/pubnub_helper.c pubnub_version_posix.cpp ../posix/pubnub_generate_uuid_posix.c ../posix/pbpal_posix_blocking_io.c ../core/pubnub_free_with_timeout_std.c pubnub_subloop.cpp ../posix/msstopwatch_monotonic_clock.c ../posix/pbtimespec_elapsed_ms.c ../core/pubnub_url_encode.c ../core/pubnub_memory_block.c ifndef ONLY_PUBSUB_API ONLY_PUBSUB_API = 0 diff --git a/cpp/posix_openssl.mk b/cpp/posix_openssl.mk index 58cfb6f7..356c4869 100644 --- a/cpp/posix_openssl.mk +++ b/cpp/posix_openssl.mk @@ -1,4 +1,4 @@ -SOURCEFILES = ../core/pubnub_pubsubapi.c ../core/pubnub_coreapi.c ../core/pubnub_ccore_pubsub.c ../core/pubnub_ccore.c ../core/pubnub_netcore.c ../lib/sockets/pbpal_resolv_and_connect_sockets.c ../lib/sockets/pbpal_handle_socket_error.c ../openssl/pbpal_openssl.c ../openssl/pbpal_connect_openssl.c ../openssl/pbpal_add_system_certs_posix.c ../core/pubnub_alloc_std.c ../core/pubnub_assert_std.c ../core/pubnub_generate_uuid.c ../core/pubnub_blocking_io.c ../posix/posix_socket_blocking_io.c ../core/pubnub_free_with_timeout_std.c ../core/pubnub_timers.c ../core/pubnub_json_parse.c ../lib/md5/md5.c ../lib/base64/pbbase64.c ../lib/pb_strnlen_s.c ../core/pubnub_helper.c pubnub_version_posix.cpp ../posix/pubnub_generate_uuid_posix.c ../openssl/pbpal_openssl_blocking_io.c ../core/pubnub_crypto.c ../core/pubnub_coreapi_ex.c ../openssl/pbaes256.c ../posix/msstopwatch_monotonic_clock.c ../core/pubnub_url_encode.c +SOURCEFILES = ../core/pubnub_pubsubapi.c ../core/pubnub_coreapi.c ../core/pubnub_ccore_pubsub.c ../core/pubnub_ccore.c ../core/pubnub_netcore.c ../lib/sockets/pbpal_resolv_and_connect_sockets.c ../lib/sockets/pbpal_handle_socket_error.c ../openssl/pbpal_openssl.c ../openssl/pbpal_connect_openssl.c ../openssl/pbpal_add_system_certs_posix.c ../core/pubnub_alloc_std.c ../core/pubnub_assert_std.c ../core/pubnub_generate_uuid.c ../core/pubnub_blocking_io.c ../posix/posix_socket_blocking_io.c ../core/pubnub_free_with_timeout_std.c ../core/pubnub_timers.c ../core/pubnub_json_parse.c ../lib/md5/md5.c ../lib/base64/pbbase64.c ../lib/pb_strnlen_s.c ../core/pubnub_helper.c pubnub_version_posix.cpp ../posix/pubnub_generate_uuid_posix.c ../openssl/pbpal_openssl_blocking_io.c ../core/pubnub_crypto.c ../core/pubnub_coreapi_ex.c ../openssl/pbaes256.c ../posix/msstopwatch_monotonic_clock.c ../posix/pbtimespec_elapsed_ms.c ../core/pubnub_url_encode.c ../core/pubnub_memory_block.c ifndef ONLY_PUBSUB_API ONLY_PUBSUB_API = 0 diff --git a/cpp/pubnub_common.hpp b/cpp/pubnub_common.hpp index 7373c429..fcd12717 100644 --- a/cpp/pubnub_common.hpp +++ b/cpp/pubnub_common.hpp @@ -372,6 +372,11 @@ class history_options { d_.include_token = inc_token; return *this; } + history_options& include_meta(bool inc_meta) + { + d_.include_meta = inc_meta; + return *this; + } pubnub_history_options data() { return d_; } }; @@ -1328,12 +1333,15 @@ class context { #endif /* PUBNUB_USE_OBJECTS_API */ #if PUBNUB_USE_ACTIONS_API - futres add_action(std::string const& channel, + /// Starts a transaction that adds new type of message called action as a support for + /// user reactions on a published messages. + /// @see pubnub_add_message_action + futres add_message_action(std::string const& channel, std::string const& message_timetoken, enum pubnub_action_type actype, std::string const& value) { - return doit(pubnub_add_action( + return doit(pubnub_add_message_action( d_pb, channel.c_str(), message_timetoken.c_str(), @@ -1341,35 +1349,45 @@ class context { value.c_str())); } + /// Returns message timetoken if previous transaction had been add_action() + /// @see pubnub_get_message_timetoken() std::string get_message_timetoken() { pubnub_chamebl_t result = pubnub_get_message_timetoken(d_pb); return std::string(result.ptr, result.size); } - std::string get_action_timetoken() + /// Returns action timetoken if previous transaction had been add_action() + /// @see pubnub_get_action_timetoken() + std::string get_message_action_timetoken() { - pubnub_chamebl_t result = pubnub_get_action_timetoken(d_pb); + pubnub_chamebl_t result = pubnub_get_message_action_timetoken(d_pb); return std::string(result.ptr, result.size); } - futres remove_action(std::string const& channel, + /// Initiates transaction that deletes(removes) previously added action on a + /// published message. + /// @see pubnub_remove_message_action() + futres remove_message_action(std::string const& channel, std::string const& message_timetoken, std::string const& action_timetoken) { - return doit(pubnub_remove_action( + return doit(pubnub_remove_message_action( d_pb, channel.c_str(), - message_timetoken.c_str(), - action_timetoken.c_str())); + pubnub_str_2_chamebl_t((char*)message_timetoken.c_str()), + pubnub_str_2_chamebl_t((char*)action_timetoken.c_str()))); } - futres get_actions(std::string const& channel, + /// Initiates transaction that returns all actions added on a given @p channel + /// between @p start and @p end action timetoken. + /// @see pubnub_get_message_actions() + futres get_message_actions(std::string const& channel, std::string const& start, std::string const& end, size_t limit=0) { - return doit(pubnub_get_actions( + return doit(pubnub_get_message_actions( d_pb, channel.c_str(), (start.size() > 0) ? start.c_str() : NULL, @@ -1377,17 +1395,21 @@ class context { limit)); } - futres get_actions_more() + /// @see pubnub_get_actions_more() + futres get_message_actions_more() { - return doit(pubnub_get_actions_more(d_pb)); + return doit(pubnub_get_message_actions_more(d_pb)); } - futres history_with_actions(std::string const& channel, + /// Initiates transaction that returns all actions added on a given @p channel + /// between @p start and @p end message timetoken. + /// @see pubnub_history_with_actions() + futres history_with_message_actions(std::string const& channel, std::string const& start, std::string const& end, size_t limit=0) { - return doit(pubnub_history_with_actions( + return doit(pubnub_history_with_message_actions( d_pb, channel.c_str(), (start.size() > 0) ? start.c_str() : NULL, @@ -1395,9 +1417,10 @@ class context { limit)); } - futres history_with_actions_more() + /// @see pubnub_history_with_actions_more() + futres history_with_message_actions_more() { - return doit(pubnub_history_with_actions_more(d_pb)); + return doit(pubnub_history_with_message_actions_more(d_pb)); } #endif /* PUBNUB_USE_ACTIONS_API */ diff --git a/cpp/windows.mk b/cpp/windows.mk index 70f1b45c..16954d67 100644 --- a/cpp/windows.mk +++ b/cpp/windows.mk @@ -1,4 +1,4 @@ -SOURCEFILES = ..\core\pubnub_pubsubapi.c ..\core\pubnub_coreapi.c ..\core\pubnub_coreapi_ex.c ..\core\pubnub_ccore_pubsub.c ..\core\pubnub_ccore.c ..\core\pubnub_netcore.c ..\lib\sockets\pbpal_sockets.c ..\lib\sockets\pbpal_resolv_and_connect_sockets.c ..\lib\sockets\pbpal_handle_socket_error.c ..\core\pubnub_alloc_std.c ..\core\pubnub_assert_std.c ..\core\pubnub_generate_uuid.c ..\core\pubnub_timers.c ..\core\pubnub_blocking_io.c ..\lib\base64\pbbase64.c ..\core\pubnub_json_parse.c ..\core\pubnub_free_with_timeout_std.c ..\lib\md5\md5.c ..\lib\pb_strnlen_s.c ..\core\pubnub_helper.c pubnub_version_windows.cpp ..\windows\pubnub_generate_uuid_windows.c ..\windows\pbpal_windows_blocking_io.c ..\windows\windows_socket_blocking_io.c ..\core\c99\snprintf.c ..\lib\miniz\miniz_tinfl.c ..\lib\miniz\miniz_tdef.c ..\lib\miniz\miniz.c ..\lib\pbcrc32.c ..\core\pbgzip_compress.c ..\core\pbgzip_decompress.c ..\core\pbcc_subscribe_v2.c ..\core\pubnub_subscribe_v2.c ..\windows\msstopwatch_windows.c ..\core\pubnub_url_encode.c ..\core\pbcc_advanced_history.c ..\core\pubnub_advanced_history.c ..\core\pbcc_objects_api.c ..\core\pubnub_objects_api.c ..\core\pbcc_actions_api.c ..\core\pubnub_actions_api.c +SOURCEFILES = ..\core\pubnub_pubsubapi.c ..\core\pubnub_coreapi.c ..\core\pubnub_coreapi_ex.c ..\core\pubnub_ccore_pubsub.c ..\core\pubnub_ccore.c ..\core\pubnub_netcore.c ..\lib\sockets\pbpal_sockets.c ..\lib\sockets\pbpal_resolv_and_connect_sockets.c ..\lib\sockets\pbpal_handle_socket_error.c ..\core\pubnub_alloc_std.c ..\core\pubnub_assert_std.c ..\core\pubnub_generate_uuid.c ..\core\pubnub_timers.c ..\core\pubnub_blocking_io.c ..\lib\base64\pbbase64.c ..\core\pubnub_json_parse.c ..\core\pubnub_free_with_timeout_std.c ..\lib\md5\md5.c ..\lib\pb_strnlen_s.c ..\core\pubnub_helper.c pubnub_version_windows.cpp ..\windows\pubnub_generate_uuid_windows.c ..\windows\pbpal_windows_blocking_io.c ..\windows\windows_socket_blocking_io.c ..\core\c99\snprintf.c ..\lib\miniz\miniz_tinfl.c ..\lib\miniz\miniz_tdef.c ..\lib\miniz\miniz.c ..\lib\pbcrc32.c ..\core\pbgzip_compress.c ..\core\pbgzip_decompress.c ..\core\pbcc_subscribe_v2.c ..\core\pubnub_subscribe_v2.c ..\windows\msstopwatch_windows.c ..\core\pubnub_url_encode.c ..\core\pbcc_advanced_history.c ..\core\pubnub_advanced_history.c ..\core\pbcc_objects_api.c ..\core\pubnub_objects_api.c ..\core\pbcc_actions_api.c ..\core\pubnub_actions_api.c ..\core\pubnub_memory_block.c LIBS=ws2_32.lib rpcrt4.lib diff --git a/cpp/windows_openssl.mk b/cpp/windows_openssl.mk index e3fcbc20..28acfda9 100644 --- a/cpp/windows_openssl.mk +++ b/cpp/windows_openssl.mk @@ -1,4 +1,4 @@ -SOURCEFILES = ..\core\pubnub_pubsubapi.c ..\core\pubnub_coreapi.c ..\core\pubnub_ccore_pubsub.c ..\core\pubnub_ccore.c ..\core\pubnub_netcore.c ..\lib\sockets\pbpal_resolv_and_connect_sockets.c ..\lib\sockets\pbpal_handle_socket_error.c ..\openssl\pbpal_openssl.c ..\openssl\pbpal_connect_openssl.c ..\core\pubnub_alloc_std.c ..\core\pubnub_assert_std.c ..\core\pubnub_generate_uuid.c ..\core\pubnub_blocking_io.c ..\lib\base64\pbbase64.c ..\core\pubnub_json_parse.c ..\core\pubnub_helper.c pubnub_version_windows.cpp ..\windows\pubnub_generate_uuid_windows.c ..\openssl\pbpal_openssl_blocking_io.c ..\windows\windows_socket_blocking_io.c ..\core\pubnub_timers.c ..\core\c99\snprintf.c ..\openssl\pbpal_add_system_certs_windows.c ..\core\pubnub_free_with_timeout_std.c ..\lib\md5\md5.c ..\lib\pb_strnlen_s.c ..\core\pubnub_ssl.c ..\core\pubnub_crypto.c ..\core\pubnub_coreapi_ex.c ..\openssl\pbaes256.c ..\lib\miniz\miniz_tinfl.c ..\lib\miniz\miniz_tdef.c ..\lib\miniz\miniz.c ..\lib\pbcrc32.c ..\core\pbgzip_compress.c ..\core\pbgzip_decompress.c ..\core\pbcc_subscribe_v2.c ..\core\pubnub_subscribe_v2.c ..\windows\msstopwatch_windows.c ..\core\pubnub_url_encode.c ..\core\pbcc_advanced_history.c ..\core\pubnub_advanced_history.c ..\core\pbcc_objects_api.c ..\core\pubnub_objects_api.c ..\core\pbcc_actions_api.c ..\core\pubnub_actions_api.c +SOURCEFILES = ..\core\pubnub_pubsubapi.c ..\core\pubnub_coreapi.c ..\core\pubnub_ccore_pubsub.c ..\core\pubnub_ccore.c ..\core\pubnub_netcore.c ..\lib\sockets\pbpal_resolv_and_connect_sockets.c ..\lib\sockets\pbpal_handle_socket_error.c ..\openssl\pbpal_openssl.c ..\openssl\pbpal_connect_openssl.c ..\core\pubnub_alloc_std.c ..\core\pubnub_assert_std.c ..\core\pubnub_generate_uuid.c ..\core\pubnub_blocking_io.c ..\lib\base64\pbbase64.c ..\core\pubnub_json_parse.c ..\core\pubnub_helper.c pubnub_version_windows.cpp ..\windows\pubnub_generate_uuid_windows.c ..\openssl\pbpal_openssl_blocking_io.c ..\windows\windows_socket_blocking_io.c ..\core\pubnub_timers.c ..\core\c99\snprintf.c ..\openssl\pbpal_add_system_certs_windows.c ..\core\pubnub_free_with_timeout_std.c ..\lib\md5\md5.c ..\lib\pb_strnlen_s.c ..\core\pubnub_ssl.c ..\core\pubnub_crypto.c ..\core\pubnub_coreapi_ex.c ..\openssl\pbaes256.c ..\lib\miniz\miniz_tinfl.c ..\lib\miniz\miniz_tdef.c ..\lib\miniz\miniz.c ..\lib\pbcrc32.c ..\core\pbgzip_compress.c ..\core\pbgzip_decompress.c ..\core\pbcc_subscribe_v2.c ..\core\pubnub_subscribe_v2.c ..\windows\msstopwatch_windows.c ..\core\pubnub_url_encode.c ..\core\pbcc_advanced_history.c ..\core\pubnub_advanced_history.c ..\core\pbcc_objects_api.c ..\core\pubnub_objects_api.c ..\core\pbcc_actions_api.c ..\core\pubnub_actions_api.c ..\core\pubnub_memory_block.c !ifndef OPENSSLPATH OPENSSLPATH=c:\OpenSSL-Win32 diff --git a/lib/msstopwatch/msstopwatch.h b/lib/msstopwatch/msstopwatch.h index 71ecb7a3..cee2c067 100644 --- a/lib/msstopwatch/msstopwatch.h +++ b/lib/msstopwatch/msstopwatch.h @@ -24,12 +24,12 @@ measures. */ +#include "msstopwatch_pal.h" #include #include -typedef struct { int32_t t_ref; } pbmsref_t; typedef int32_t pbms_t; /** Starts a stopwatch. The result has no particular meaning, diff --git a/openssl/msstopwatch_pal.h b/openssl/msstopwatch_pal.h new file mode 100644 index 00000000..3c3679fe --- /dev/null +++ b/openssl/msstopwatch_pal.h @@ -0,0 +1,6 @@ +/* -*- c-file-style:"stroustrup"; indent-tabs-mode: nil -*- */ +#ifdef _WIN32 +#include "windows/msstopwatch_pal.h" +#else +#include "posix/msstopwatch_pal.h" +#endif diff --git a/openssl/posix.mk b/openssl/posix.mk index a27b7ba5..2e7c448e 100644 --- a/openssl/posix.mk +++ b/openssl/posix.mk @@ -1,6 +1,6 @@ -SOURCEFILES = ../core/pubnub_ssl.c ../core/pubnub_pubsubapi.c ../core/pubnub_coreapi.c ../core/pubnub_ccore_pubsub.c ../core/pubnub_ccore.c ../core/pubnub_netcore.c ../lib/sockets/pbpal_resolv_and_connect_sockets.c ../lib/sockets/pbpal_handle_socket_error.c pbpal_openssl.c pbpal_connect_openssl.c pbpal_add_system_certs_posix.c ../core/pubnub_alloc_std.c ../core/pubnub_assert_std.c ../core/pubnub_generate_uuid.c ../core/pubnub_blocking_io.c ../posix/posix_socket_blocking_io.c ../core/pubnub_timers.c ../core/pubnub_json_parse.c ../core/pubnub_helper.c ../posix/pubnub_version_posix.c ../posix/pubnub_generate_uuid_posix.c pbpal_openssl_blocking_io.c ../lib/base64/pbbase64.c ../lib/pb_strnlen_s.c ../core/pubnub_crypto.c ../core/pubnub_coreapi_ex.c ../core/pubnub_free_with_timeout_std.c pbaes256.c ../posix/msstopwatch_monotonic_clock.c ../core/pubnub_url_encode.c +SOURCEFILES = ../core/pubnub_ssl.c ../core/pubnub_pubsubapi.c ../core/pubnub_coreapi.c ../core/pubnub_ccore_pubsub.c ../core/pubnub_ccore.c ../core/pubnub_netcore.c ../lib/sockets/pbpal_resolv_and_connect_sockets.c ../lib/sockets/pbpal_handle_socket_error.c pbpal_openssl.c pbpal_connect_openssl.c pbpal_add_system_certs_posix.c ../core/pubnub_alloc_std.c ../core/pubnub_assert_std.c ../core/pubnub_generate_uuid.c ../core/pubnub_blocking_io.c ../posix/posix_socket_blocking_io.c ../core/pubnub_timers.c ../core/pubnub_json_parse.c ../core/pubnub_helper.c ../posix/pubnub_version_posix.c ../posix/pubnub_generate_uuid_posix.c pbpal_openssl_blocking_io.c ../lib/base64/pbbase64.c ../lib/pb_strnlen_s.c ../core/pubnub_crypto.c ../core/pubnub_coreapi_ex.c ../core/pubnub_free_with_timeout_std.c pbaes256.c ../posix/msstopwatch_monotonic_clock.c ../posix/pbtimespec_elapsed_ms.c ../core/pubnub_url_encode.c ../core/pubnub_memory_block.c -OBJFILES = pubnub_ssl.o pubnub_pubsubapi.o pubnub_coreapi.o pubnub_ccore_pubsub.o pubnub_ccore.o pubnub_netcore.o pbpal_resolv_and_connect_sockets.o pbpal_handle_socket_error.o pbpal_openssl.o pbpal_connect_openssl.o pbpal_add_system_certs_posix.o pubnub_alloc_std.o pubnub_assert_std.o pubnub_generate_uuid.o pubnub_blocking_io.o posix_socket_blocking_io.o pubnub_timers.o pubnub_json_parse.o pubnub_helper.o pubnub_version_posix.o pubnub_generate_uuid_posix.o pbpal_openssl_blocking_io.o pbbase64.o pb_strnlen_s.o pubnub_crypto.o pubnub_coreapi_ex.o pubnub_free_with_timeout_std.o pbaes256.o msstopwatch_monotonic_clock.o pubnub_url_encode.o +OBJFILES = pubnub_ssl.o pubnub_pubsubapi.o pubnub_coreapi.o pubnub_ccore_pubsub.o pubnub_ccore.o pubnub_netcore.o pbpal_resolv_and_connect_sockets.o pbpal_handle_socket_error.o pbpal_openssl.o pbpal_connect_openssl.o pbpal_add_system_certs_posix.o pubnub_alloc_std.o pubnub_assert_std.o pubnub_generate_uuid.o pubnub_blocking_io.o posix_socket_blocking_io.o pubnub_timers.o pubnub_json_parse.o pubnub_helper.o pubnub_version_posix.o pubnub_generate_uuid_posix.o pbpal_openssl_blocking_io.o pbbase64.o pb_strnlen_s.o pubnub_crypto.o pubnub_coreapi_ex.o pubnub_free_with_timeout_std.o pbaes256.o msstopwatch_monotonic_clock.o pbtimespec_elapsed_ms.o pubnub_url_encode.o pubnub_memory_block.o ifndef ONLY_PUBSUB_API ONLY_PUBSUB_API = 0 diff --git a/openssl/windows.mk b/openssl/windows.mk index d79b80d2..c3682ac8 100644 --- a/openssl/windows.mk +++ b/openssl/windows.mk @@ -1,6 +1,6 @@ -SOURCEFILES = ..\core\pubnub_pubsubapi.c ..\core\pubnub_coreapi.c ..\core\pubnub_ccore_pubsub.c ..\core\pubnub_ccore.c ..\core\pubnub_netcore.c ..\lib\sockets\pbpal_resolv_and_connect_sockets.c ..\lib\sockets\pbpal_handle_socket_error.c pbpal_openssl.c pbpal_connect_openssl.c pbpal_add_system_certs_windows.c ..\core\pubnub_alloc_std.c ..\core\pubnub_assert_std.c ..\core\pubnub_generate_uuid.c ..\core\pubnub_blocking_io.c ..\windows\windows_socket_blocking_io.c ..\core\pubnub_free_with_timeout_std.c ..\core\pubnub_timers.c ..\core\pubnub_json_parse.c ..\lib\md5\md5.c ..\lib\pb_strnlen_s.c ..\core\pubnub_ssl.c ..\core\pubnub_helper.c ..\windows\pubnub_version_windows.c ..\windows\pubnub_generate_uuid_windows.c pbpal_openssl_blocking_io.c ..\lib\base64\pbbase64.c ..\core\pubnub_crypto.c ..\core\pubnub_coreapi_ex.c pbaes256.c ..\core\c99\snprintf.c ..\lib\miniz\miniz_tinfl.c ..\lib\miniz\miniz_tdef.c ..\lib\miniz\miniz.c ..\lib\pbcrc32.c ..\core\pbgzip_compress.c ..\core\pbgzip_decompress.c ..\core\pbcc_subscribe_v2.c ..\core\pubnub_subscribe_v2.c ..\windows\msstopwatch_windows.c ..\core\pubnub_url_encode.c ..\core\pbcc_advanced_history.c ..\core\pubnub_advanced_history.c ..\core\pbcc_objects_api.c ..\core\pubnub_objects_api.c ..\core\pbcc_actions_api.c ..\core\pubnub_actions_api.c +SOURCEFILES = ..\core\pubnub_pubsubapi.c ..\core\pubnub_coreapi.c ..\core\pubnub_ccore_pubsub.c ..\core\pubnub_ccore.c ..\core\pubnub_netcore.c ..\lib\sockets\pbpal_resolv_and_connect_sockets.c ..\lib\sockets\pbpal_handle_socket_error.c pbpal_openssl.c pbpal_connect_openssl.c pbpal_add_system_certs_windows.c ..\core\pubnub_alloc_std.c ..\core\pubnub_assert_std.c ..\core\pubnub_generate_uuid.c ..\core\pubnub_blocking_io.c ..\windows\windows_socket_blocking_io.c ..\core\pubnub_free_with_timeout_std.c ..\core\pubnub_timers.c ..\core\pubnub_json_parse.c ..\lib\md5\md5.c ..\lib\pb_strnlen_s.c ..\core\pubnub_ssl.c ..\core\pubnub_helper.c ..\windows\pubnub_version_windows.c ..\windows\pubnub_generate_uuid_windows.c pbpal_openssl_blocking_io.c ..\lib\base64\pbbase64.c ..\core\pubnub_crypto.c ..\core\pubnub_coreapi_ex.c pbaes256.c ..\core\c99\snprintf.c ..\lib\miniz\miniz_tinfl.c ..\lib\miniz\miniz_tdef.c ..\lib\miniz\miniz.c ..\lib\pbcrc32.c ..\core\pbgzip_compress.c ..\core\pbgzip_decompress.c ..\core\pbcc_subscribe_v2.c ..\core\pubnub_subscribe_v2.c ..\windows\msstopwatch_windows.c ..\core\pubnub_url_encode.c ..\core\pbcc_advanced_history.c ..\core\pubnub_advanced_history.c ..\core\pbcc_objects_api.c ..\core\pubnub_objects_api.c ..\core\pbcc_actions_api.c ..\core\pubnub_actions_api.c ..\core\pubnub_memory_block.c -OBJFILES = pubnub_pubsubapi.obj pubnub_coreapi.obj pubnub_ccore_pubsub.obj pubnub_ccore.obj pubnub_netcore.obj pbpal_resolv_and_connect_sockets.obj pbpal_handle_socket_error.obj pbpal_openssl.obj pbpal_connect_openssl.obj pbpal_add_system_certs_windows.obj pubnub_alloc_std.obj pubnub_assert_std.obj pubnub_generate_uuid.obj pubnub_blocking_io.obj pubnub_free_with_timeout_std.obj pubnub_timers.obj pubnub_json_parse.obj md5.obj pb_strnlen_s.obj pubnub_ssl.obj pubnub_helper.obj pubnub_version_windows.obj pubnub_generate_uuid_windows.obj pbpal_openssl_blocking_io.obj windows_socket_blocking_io.obj pbbase64.obj pubnub_crypto.obj pubnub_coreapi_ex.obj pbaes256.obj snprintf.obj miniz_tinfl.obj miniz_tdef.obj miniz.obj pbcrc32.obj pbgzip_compress.obj pbgzip_decompress.obj pbcc_subscribe_v2.obj pubnub_subscribe_v2.obj msstopwatch_windows.obj pubnub_url_encode.obj pbcc_advanced_history.obj pubnub_advanced_history.obj pbcc_objects_api.obj pubnub_objects_api.obj pbcc_actions_api.obj pubnub_actions_api.obj +OBJFILES = pubnub_pubsubapi.obj pubnub_coreapi.obj pubnub_ccore_pubsub.obj pubnub_ccore.obj pubnub_netcore.obj pbpal_resolv_and_connect_sockets.obj pbpal_handle_socket_error.obj pbpal_openssl.obj pbpal_connect_openssl.obj pbpal_add_system_certs_windows.obj pubnub_alloc_std.obj pubnub_assert_std.obj pubnub_generate_uuid.obj pubnub_blocking_io.obj pubnub_free_with_timeout_std.obj pubnub_timers.obj pubnub_json_parse.obj md5.obj pb_strnlen_s.obj pubnub_ssl.obj pubnub_helper.obj pubnub_version_windows.obj pubnub_generate_uuid_windows.obj pbpal_openssl_blocking_io.obj windows_socket_blocking_io.obj pbbase64.obj pubnub_crypto.obj pubnub_coreapi_ex.obj pbaes256.obj snprintf.obj miniz_tinfl.obj miniz_tdef.obj miniz.obj pbcrc32.obj pbgzip_compress.obj pbgzip_decompress.obj pbcc_subscribe_v2.obj pubnub_subscribe_v2.obj msstopwatch_windows.obj pubnub_url_encode.obj pbcc_advanced_history.obj pubnub_advanced_history.obj pbcc_objects_api.obj pubnub_objects_api.obj pbcc_actions_api.obj pubnub_actions_api.obj pubnub_memory_block.obj !ifndef OPENSSLPATH OPENSSLPATH=c:\OpenSSL-Win32 diff --git a/posix/msstopwatch_monotonic_clock.c b/posix/msstopwatch_monotonic_clock.c index bd72b079..ddccd92f 100644 --- a/posix/msstopwatch_monotonic_clock.c +++ b/posix/msstopwatch_monotonic_clock.c @@ -5,20 +5,22 @@ #include "core/pubnub_assert.h" #include "posix/monotonic_clock_get_time.h" +#include "posix/pbtimespec_elapsed_ms.h" /** This uses our helper module that provides a monotonic clock like POSIX clock_gettime(CLOCK_MONOTONIC,...); */ -static int32_t msclock(void) +static struct timespec msclock(void) { struct timespec ts; if (0 == monotonic_clock_get_time(&ts)) { - return ts.tv_sec * 1000 + ts.tv_nsec / 1000000; + return ts; } else { - return -1; + ts.tv_nsec = -1; + return ts; } } @@ -32,18 +34,18 @@ pbmsref_t pbms_start(void) void pbms_stop(pbmsref_t* psw) { - psw->t_ref = -1; + psw->t_ref.tv_nsec = -1; } bool pbms_active(pbmsref_t stopwatch) { - return stopwatch.t_ref > -1; + return stopwatch.t_ref.tv_nsec > -1; } pbms_t pbms_elapsed(pbmsref_t since) { PUBNUB_ASSERT(pbms_active(since)); - return msclock() - since.t_ref; + return pbtimespec_elapsed_ms(since.t_ref, msclock()); } diff --git a/posix/msstopwatch_pal.h b/posix/msstopwatch_pal.h new file mode 100644 index 00000000..d01aa2d7 --- /dev/null +++ b/posix/msstopwatch_pal.h @@ -0,0 +1,10 @@ +/* -*- c-file-style:"stroustrup"; indent-tabs-mode: nil -*- */ +#if !defined(INC_MSSTOPWATCH_PAL) +#define INC_MSSTOPWATCH_PAL + +#include + +typedef struct { struct timespec t_ref; } pbmsref_t; + + +#endif /* !defined(INC_MSSTOPWATCH_PAL) */ diff --git a/posix/pbtimespec_elapsed_ms.c b/posix/pbtimespec_elapsed_ms.c new file mode 100644 index 00000000..109d52c0 --- /dev/null +++ b/posix/pbtimespec_elapsed_ms.c @@ -0,0 +1,10 @@ +/* -*- c-file-style:"stroustrup"; indent-tabs-mode: nil -*- */ +#include "posix/monotonic_clock_get_time.h" + + +int pbtimespec_elapsed_ms(struct timespec prev_timspec, struct timespec timspec) +{ + int s_diff = timspec.tv_sec - prev_timspec.tv_sec; + int m_s_diff = (timspec.tv_nsec - prev_timspec.tv_nsec) / MILLI_IN_NANO; + return (s_diff * UNIT_IN_MILLI) + m_s_diff; +} diff --git a/posix/pbtimespec_elapsed_ms.h b/posix/pbtimespec_elapsed_ms.h new file mode 100644 index 00000000..cbe11c54 --- /dev/null +++ b/posix/pbtimespec_elapsed_ms.h @@ -0,0 +1,9 @@ +/* -*- c-file-style:"stroustrup"; indent-tabs-mode: nil -*- */ +#if !defined(INC_PBMC_ELAPSED_MS) +#define INC_PBMC_ELAPSED_MS + +#include + +int pbtimespec_elapsed_ms(struct timespec prev_timspec, struct timespec timspec); + +#endif /* !defined(INC_PBMC_ELAPSED_MS) */ diff --git a/posix/posix.mk b/posix/posix.mk index d084e941..7ad2e485 100644 --- a/posix/posix.mk +++ b/posix/posix.mk @@ -1,6 +1,6 @@ -SOURCEFILES = ../core/pubnub_pubsubapi.c ../core/pubnub_coreapi.c ../core/pubnub_coreapi_ex.c ../core/pubnub_ccore_pubsub.c ../core/pubnub_ccore.c ../core/pubnub_netcore.c ../lib/sockets/pbpal_sockets.c ../lib/sockets/pbpal_resolv_and_connect_sockets.c ../lib/sockets/pbpal_handle_socket_error.c ../core/pubnub_alloc_std.c ../core/pubnub_assert_std.c ../core/pubnub_generate_uuid.c ../core/pubnub_blocking_io.c ../posix/posix_socket_blocking_io.c ../core/pubnub_timers.c ../core/pubnub_json_parse.c ../lib/md5/md5.c ../lib/base64/pbbase64.c ../lib/pb_strnlen_s.c ../core/pubnub_helper.c pubnub_version_posix.c pubnub_generate_uuid_posix.c pbpal_posix_blocking_io.c ../core/pubnub_generate_uuid_v3_md5.c ../core/pubnub_free_with_timeout_std.c msstopwatch_monotonic_clock.c ../core/pubnub_url_encode.c +SOURCEFILES = ../core/pubnub_pubsubapi.c ../core/pubnub_coreapi.c ../core/pubnub_coreapi_ex.c ../core/pubnub_ccore_pubsub.c ../core/pubnub_ccore.c ../core/pubnub_netcore.c ../lib/sockets/pbpal_sockets.c ../lib/sockets/pbpal_resolv_and_connect_sockets.c ../lib/sockets/pbpal_handle_socket_error.c ../core/pubnub_alloc_std.c ../core/pubnub_assert_std.c ../core/pubnub_generate_uuid.c ../core/pubnub_blocking_io.c ../posix/posix_socket_blocking_io.c ../core/pubnub_timers.c ../core/pubnub_json_parse.c ../lib/md5/md5.c ../lib/base64/pbbase64.c ../lib/pb_strnlen_s.c ../core/pubnub_helper.c pubnub_version_posix.c pubnub_generate_uuid_posix.c pbpal_posix_blocking_io.c ../core/pubnub_generate_uuid_v3_md5.c ../core/pubnub_free_with_timeout_std.c msstopwatch_monotonic_clock.c pbtimespec_elapsed_ms.c ../core/pubnub_url_encode.c ../core/pubnub_memory_block.c -OBJFILES = pubnub_pubsubapi.o pubnub_coreapi.o pubnub_coreapi_ex.o pubnub_ccore_pubsub.o pubnub_ccore.o pubnub_netcore.o pbpal_sockets.o pbpal_resolv_and_connect_sockets.o pbpal_handle_socket_error.o pubnub_alloc_std.o pubnub_assert_std.o pubnub_generate_uuid.o pubnub_blocking_io.o posix_socket_blocking_io.o pubnub_timers.o pubnub_json_parse.o md5.o pbbase64.o pb_strnlen_s.o pubnub_helper.o pubnub_version_posix.o pubnub_generate_uuid_posix.o pbpal_posix_blocking_io.o pubnub_generate_uuid_v3_md5.o pubnub_free_with_timeout_std.o msstopwatch_monotonic_clock.o pubnub_url_encode.o +OBJFILES = pubnub_pubsubapi.o pubnub_coreapi.o pubnub_coreapi_ex.o pubnub_ccore_pubsub.o pubnub_ccore.o pubnub_netcore.o pbpal_sockets.o pbpal_resolv_and_connect_sockets.o pbpal_handle_socket_error.o pubnub_alloc_std.o pubnub_assert_std.o pubnub_generate_uuid.o pubnub_blocking_io.o posix_socket_blocking_io.o pubnub_timers.o pubnub_json_parse.o md5.o pbbase64.o pb_strnlen_s.o pubnub_helper.o pubnub_version_posix.o pubnub_generate_uuid_posix.o pbpal_posix_blocking_io.o pubnub_generate_uuid_v3_md5.o pubnub_free_with_timeout_std.o msstopwatch_monotonic_clock.o pbtimespec_elapsed_ms.o pubnub_url_encode.o pubnub_memory_block.o ifndef ONLY_PUBSUB_API ONLY_PUBSUB_API = 0 diff --git a/posix/pubnub_ntf_callback_posix.c b/posix/pubnub_ntf_callback_posix.c index 9bf1b4c7..bd7abf7a 100644 --- a/posix/pubnub_ntf_callback_posix.c +++ b/posix/pubnub_ntf_callback_posix.c @@ -2,6 +2,7 @@ #include "core/pubnub_ntf_callback.h" #include "posix/monotonic_clock_get_time.h" +#include "posix/pbtimespec_elapsed_ms.h" #include "pubnub_internal.h" #include "core/pubnub_assert.h" @@ -36,14 +37,6 @@ struct SocketWatcherData { static struct SocketWatcherData m_watcher; -static int elapsed_ms(struct timespec prev_timspec, struct timespec timspec) -{ - int s_diff = timspec.tv_sec - prev_timspec.tv_sec; - int m_s_diff = (timspec.tv_nsec - prev_timspec.tv_nsec) / MILLI_IN_NANO; - return (s_diff * UNIT_IN_MILLI) + m_s_diff; -} - - int pbntf_watch_in_events(pubnub_t* pbp) { return pbpal_ntf_watch_in_events(m_watcher.poll, pbp); @@ -82,7 +75,7 @@ void* socket_watcher_thread(void* arg) pthread_mutex_unlock(&m_watcher.mutw); if (PUBNUB_TIMERS_API) { - int elapsed = elapsed_ms(prev_timspec, timspec); + int elapsed = pbtimespec_elapsed_ms(prev_timspec, timspec); if (elapsed > 0) { if (elapsed > max_poll_ms + 5) { PUBNUB_LOG_TRACE("elapsed = %d: prev_timspec={%ld, %ld}, timspec={%ld,%ld}\n", diff --git a/qt/fn_test.pro b/qt/fn_test.pro index d11d5488..4c5a8111 100644 --- a/qt/fn_test.pro +++ b/qt/fn_test.pro @@ -4,7 +4,7 @@ mac:CONFIG -= app_bundle win32:CONFIG += console CONFIG += c++11 HEADERS += pubnub_qt.h pubnub.hpp -SOURCES += pubnub_qt.cpp pubnub.cpp fntest/pubnub_fntest_runner.cpp ../cpp/fntest/pubnub_fntest.cpp ../cpp/fntest/pubnub_fntest_basic.cpp ../cpp/fntest/pubnub_fntest_medium.cpp ../core/pubnub_ccore.c ../core/pubnub_ccore_pubsub.c ../core/pbcc_subscribe_v2.c ../core/pbcc_advanced_history.c ../core/pbcc_objects_api.c ../core/pbcc_actions_api.c ../core/pubnub_url_encode.c ../core/pubnub_assert_std.c ../core/pubnub_json_parse.c ../core/pubnub_helper.c ../lib/pbcrc32.c ../lib/pb_strnlen_s.c +SOURCES += pubnub_qt.cpp pubnub.cpp fntest/pubnub_fntest_runner.cpp ../cpp/fntest/pubnub_fntest.cpp ../cpp/fntest/pubnub_fntest_basic.cpp ../cpp/fntest/pubnub_fntest_medium.cpp ../core/pubnub_ccore.c ../core/pubnub_ccore_pubsub.c ../core/pbcc_subscribe_v2.c ../core/pbcc_advanced_history.c ../core/pbcc_objects_api.c ../core/pbcc_actions_api.c ../core/pubnub_url_encode.c ../core/pubnub_assert_std.c ../core/pubnub_json_parse.c ../core/pubnub_helper.c ../lib/pbcrc32.c ../lib/pb_strnlen_s.c ../core/pubnub_memory_block.c win32:SOURCES += ../core/c99/snprintf.c INCLUDEPATH += ../core ../cpp/fntest .. diff --git a/qt/pubnub.pro b/qt/pubnub.pro index 7dd17b8d..4fead68e 100644 --- a/qt/pubnub.pro +++ b/qt/pubnub.pro @@ -4,7 +4,7 @@ CONFIG += C++11 mac:CONFIG -= app_bundle win32:CONFIG += console HEADERS += pubnub_qt.h pubnub_qt_sample.h -SOURCES += pubnub_qt.cpp pubnub_qt_sample.cpp ../core/pubnub_ccore.c ../core/pubnub_ccore_pubsub.c ../core/pbcc_subscribe_v2.c ../core/pbcc_advanced_history.c ../core/pbcc_objects_api.c ../core/pbcc_actions_api.c ../core/pubnub_url_encode.c ../core/pubnub_assert_std.c ../core/pubnub_json_parse.c ../core/pubnub_helper.c ../lib/pbcrc32.c ../lib/pb_strnlen_s.c +SOURCES += pubnub_qt.cpp pubnub_qt_sample.cpp ../core/pubnub_ccore.c ../core/pubnub_ccore_pubsub.c ../core/pbcc_subscribe_v2.c ../core/pbcc_advanced_history.c ../core/pbcc_objects_api.c ../core/pbcc_actions_api.c ../core/pubnub_url_encode.c ../core/pubnub_assert_std.c ../core/pubnub_json_parse.c ../core/pubnub_helper.c ../lib/pbcrc32.c ../lib/pb_strnlen_s.c ../core/pubnub_memory_block.c win32:SOURCES += ../core/c99/snprintf.c INCLUDEPATH += .. diff --git a/qt/pubnub_gui.pro b/qt/pubnub_gui.pro index 510e2f0d..c88b3c3c 100644 --- a/qt/pubnub_gui.pro +++ b/qt/pubnub_gui.pro @@ -2,7 +2,7 @@ TEMPLATE = app QT += widgets network CONFIG += C++11 HEADERS += pubnub_qt.h pubnub_qt_gui_sample.h -SOURCES += pubnub_qt.cpp pubnub_qt_gui_sample.cpp ../core/pubnub_ccore_pubsub.c ../core/pubnub_ccore.c ../core/pbcc_subscribe_v2.c ../core/pbcc_advanced_history.c ../core/pbcc_objects_api.c ../core/pbcc_actions_api.c ../core/pubnub_url_encode.c ../core/pubnub_assert_std.c ../core/pubnub_json_parse.c ../core/pubnub_helper.c ../lib/pbcrc32.c ../lib/pb_strnlen_s.c +SOURCES += pubnub_qt.cpp pubnub_qt_gui_sample.cpp ../core/pubnub_ccore_pubsub.c ../core/pubnub_ccore.c ../core/pbcc_subscribe_v2.c ../core/pbcc_advanced_history.c ../core/pbcc_objects_api.c ../core/pbcc_actions_api.c ../core/pubnub_url_encode.c ../core/pubnub_assert_std.c ../core/pubnub_json_parse.c ../core/pubnub_helper.c ../lib/pbcrc32.c ../lib/pb_strnlen_s.c ../core/pubnub_memory_block.c win32:SOURCES += ../core/c99/snprintf.c INCLUDEPATH += .. diff --git a/qt/pubnub_qt.cpp b/qt/pubnub_qt.cpp index f0d21351..ebcc0cd8 100644 --- a/qt/pubnub_qt.cpp +++ b/qt/pubnub_qt.cpp @@ -416,6 +416,7 @@ pubnub_res pubnub_qt::history(QString const& channel, unsigned count, bool inclu include_token, pbccNotSet, pbccNotSet, + pbccNotSet, 0, 0), PBTT_HISTORY); @@ -427,6 +428,7 @@ pubnub_res pubnub_qt::history(QString const& channel, bool include_token, QString const& start, bool reverse, + bool include_meta, QString const& end, bool string_token) { @@ -438,6 +440,7 @@ pubnub_res pubnub_qt::history(QString const& channel, include_token, string_token ? pbccTrue : pbccFalse, reverse ? pbccTrue : pbccFalse, + include_meta ? pbccTrue : pbccFalse, start.isEmpty() ? 0 : start.toLatin1().data(), end.isEmpty() ? 0 : end.toLatin1().data()), PBTT_HISTORY); @@ -1060,8 +1063,8 @@ pubnub_res pubnub_qt::remove_action(QString const& channel, return startRequest( pbcc_remove_action_prep(d_context.data(), channel.toLatin1().data(), - message_timetoken.toLatin1().data(), - action_timetoken.toLatin1().data()), + pubnub_str_2_chamebl_t((char*)message_timetoken.toLatin1().data()), + pubnub_str_2_chamebl_t((char*)action_timetoken.toLatin1().data())), PBTT_REMOVE_ACTION); } diff --git a/qt/pubnub_qt.h b/qt/pubnub_qt.h index b3409f19..22564758 100644 --- a/qt/pubnub_qt.h +++ b/qt/pubnub_qt.h @@ -611,6 +611,9 @@ class pubnub_qt : public QObject @param reverse Direction of time traversal. False means timeline is traversed newest to oldest. + @param include_meta If true, transaction response will include + metadata for every gotten message + @param end Lets you select an “end date”, in Timetoken format. If not provided, it will provide up to the number of messages defined in the “count” parameter. Page through @@ -632,6 +635,7 @@ class pubnub_qt : public QObject bool include_token, QString const& start, bool reverse, + bool include_meta, QString const& end, bool string_token); @@ -1733,39 +1737,141 @@ class pubnub_qt : public QObject #endif /* PUBNUB_USE_OBJECTS_API */ #if PUBNUB_USE_ACTIONS_API - pubnub_res add_action(QString const& channel, + /** Adds new type of message called action as a support for user reactions on a published + messages. + Json string @p value is checked for its quotation marks at its ends. If any of the + quotation marks is missing function returns parameter error. + If the transaction is finished successfully response will have 'data' field with + added action data. If there is no data, nor error description in the response, + response parsing function returns format error. + @param channel The channel on which action is referring to. + @param message_timetoken The timetoken(unquoted) of a published message action is + applying to + @param actype Action type + @param value Json string describing the action that is to be added + @return #PNR_STARTED on success, an error otherwise + */ + pubnub_res add_message_action(QString const& channel, QString const& message_timetoken, pubnub_action_type actype, QString const& value); - pubnub_res add_action(QString const& channel, + /** Function receives 'Qt Json' document for @p value. Helpful if you're already using Qt + support for Json in your code, ensuring that value you are passing is valid Json. + @see add_message_action() + */ + pubnub_res add_message_action(QString const& channel, QString const& message_timetoken, pubnub_action_type actype, QJsonDocument const& value) { return add_action(channel, message_timetoken, actype, value.toJson()); } + /** Searches the response, if previous transaction had been 'add_action' and was accomplished + successfully) and retrieves timetoken of a message action was added on. + If key expected is not found, preconditions(about right transaction) were not fulfilled, + or error was encountered, returnes an empty string. + @return Message timetoken value including its quotation marks + */ QString get_message_timetoken(); + /** Searches the response, if previous transaction had been 'add_action' and was accomplished + successfully) and retrieves timetoken of a resently added action. + If key expected is not found, preconditions were not fulfilled, or error was encountered, + returnes an empty string. + @return Action timetoken value including its quotation marks + */ QString get_action_timetoken(); - pubnub_res remove_action(QString const& channel, + /** Initiates transaction that deletes(removes) previously added action on a published message. + If there is no success confirming data, nor error description in the response it is + considered format error. + @param channel The channel on which action was previously added. + @param message_timetoken The timetoken of a published message action was applied to. + (Obtained from the response when action was added and expected + with its quotation marks at both ends) + @param action_timetoken The action timetoken when it was added(Gotten from the transaction + response when action was added and expected with its quotation + marks at both ends) + @return #PNR_STARTED on success, an error otherwise + */ + pubnub_res remove_message_action(QString const& channel, QString const& message_timetoken, QString const& action_timetoken); - pubnub_res get_actions(QString const& channel, + /** Initiates transaction that returns all actions added on a given @p channel between @p start + and @p end action timetoken. + The response to this transaction can be partial and than it contains the hyperlink string + value to the rest. + @see get_actions_more() + If there is no actions data, nor error description in the response it is considered + format error. + @param channel The channel on which actions are observed. + @param start Start action timetoken(unquoted). Can be an empty string meaning there is + no lower limitation in time. + @param end End action timetoken(unquoted). Can be an empty string in which case upper + time limit is present moment. + @param limit Number of actions to return in response. Regular values 1 - 100. If you set `0`, + that means “use the default”. At the time of this writing, default was 100. + Any value greater than 100 is considered an error. + @return #PNR_STARTED on success, an error otherwise + */ + pubnub_res get_message_actions(QString const& channel, QString const& start, QString const& end, size_t limit=0); - pubnub_res get_actions_more(); - - pubnub_res history_with_actions(QString const& channel, + /** This function expects previous transaction to be the one for reading the actions and + that it was successfully accomplished. If it is not the case, returns corresponding + error. + When preconditions are fulfilled, it searches the hyperlink to the rest in the existing + response buffer which it uses for obtaining another part of the server response. + Anotherwords, once the hyperlink is found in the existing response it is used for + initiating new request and function than behaves, essentially, as get_actions(). + If there is no hyperlink encountered in the previous transaction response it + returns success: PNR_GOT_ALL_ACTIONS meaning that the answer is complete. + @retval PNR_STARTED transaction successfully initiated. + @retval PNR_GOT_ALL_ACTIONS transaction successfully finished. + @retval corresponding error otherwise + */ + pubnub_res get_message_actions_more(); + + /** Initiates transaction that returns all actions added on a given @p channel between @p start + and @p end message timetoken. + The response to this transaction can be partial and than it contains the hyperlink string + value to the rest. + @see history_with_actions_more() + If there is no actions data, nor error description in the response it is considered + format error. + @param channel The channel on which actions are observed. + @param start Start message timetoken(unquoted). Can be an empty string meaning there is + no lower limitation in time. + @param end End message timetoken(unquoted). Can be an empty string in which case upper + time limit is present moment. + @param limit Number of messages to return in response. Regular values 1 - 100. If you + set `0`, that means “use the default”. At the time of this writing, default + was 100. Any value greater than 100 is considered an error. + @return #PNR_STARTED on success, an error otherwise + */ + pubnub_res history_with_message_actions(QString const& channel, QString const& start, QString const& end, size_t limit=0); - pubnub_res history_with_actions_more(); + /** This function expects previous transaction to be the one for reading the history with + actions and that it was successfully accomplished. If it is not the case, returns + corresponding error. + When preconditions are fulfilled it searches for the hyperlink to the rest of the answer + in the existing response buffer which it uses for obtaining another part of the server + response. Anotherwords, once the hyperlink is found in the existing response it is used + for initiating new request and function than behaves as history_with_actions(). + If there is no hyperlink encountered in the previous transaction response it + returns success: PNR_GOT_ALL_ACTIONS meaning that the answer is complete. + @retval PNR_STARTED transaction successfully initiated. + @retval PNR_GOT_ALL_ACTIONS transaction successfully finished. + @retval corresponding error otherwise + */ + pubnub_res history_with_message_actions_more(); #endif /* PUBNUB_USE_ACTIONS_API */ /** Returns the HTTP code of the last transaction. If the diff --git a/windows/msstopwatch_pal.h b/windows/msstopwatch_pal.h new file mode 100644 index 00000000..5e0aa286 --- /dev/null +++ b/windows/msstopwatch_pal.h @@ -0,0 +1,11 @@ +/* -*- c-file-style:"stroustrup"; indent-tabs-mode: nil -*- */ +#if !defined(INC_MSSTOPWATCH_PAL) +#define INC_MSSTOPWATCH_PAL + +#define WIN32_LEAN_AND_MEAN +#include + +typedef struct { ULONGLONG t_ref; } pbmsref_t; + + +#endif /* !defined(INC_MSSTOPWATCH_PAL) */ diff --git a/windows/msstopwatch_windows.c b/windows/msstopwatch_windows.c index d57bac24..2b4b3baf 100644 --- a/windows/msstopwatch_windows.c +++ b/windows/msstopwatch_windows.c @@ -4,11 +4,8 @@ #include "core/pubnub_assert.h" -#define WIN32_LEAN_AND_MEAN -#include - -/** This uses GetTickCount(), which is very fast, but innacurate - +/** This uses GetTickCount64(), which is very fast, but innacurate - typical resolution is ~16 ms, could be better or worse, but not much better. This is acceptable for the purposes of this module. @@ -16,25 +13,25 @@ pbmsref_t pbms_start(void) { - pbmsref_t rslt = { (int32_t)GetTickCount() }; + pbmsref_t rslt = { GetTickCount64() + 1 }; return rslt; } void pbms_stop(pbmsref_t* psw) { - psw->t_ref = -1; + psw->t_ref = 0; } bool pbms_active(pbmsref_t stopwatch) { - return stopwatch.t_ref > -1; + return stopwatch.t_ref > 0; } pbms_t pbms_elapsed(pbmsref_t since) { PUBNUB_ASSERT(pbms_active(since)); - return GetTickCount() - since.t_ref; + return (pbms_t)(GetTickCount64() + 1 - since.t_ref); } diff --git a/windows/windows.mk b/windows/windows.mk index 78894593..c1cf5e1c 100644 --- a/windows/windows.mk +++ b/windows/windows.mk @@ -1,6 +1,6 @@ -SOURCEFILES = ..\core\pubnub_pubsubapi.c ..\core\pubnub_coreapi.c ..\core\pubnub_coreapi_ex.c ..\core\pubnub_ccore_pubsub.c ..\core\pubnub_ccore.c ..\core\pubnub_netcore.c ..\lib\sockets\pbpal_sockets.c ..\lib\sockets\pbpal_resolv_and_connect_sockets.c ..\lib\sockets\pbpal_handle_socket_error.c ..\core\pubnub_alloc_std.c ..\core\pubnub_assert_std.c ..\core\pubnub_generate_uuid.c ..\core\pubnub_blocking_io.c ..\windows\windows_socket_blocking_io.c ..\core\pubnub_free_with_timeout_std.c ..\lib\base64\pbbase64.c ..\core\pubnub_timers.c ..\core\pubnub_json_parse.c ..\lib\md5\md5.c ..\lib\pb_strnlen_s.c ..\core\pubnub_helper.c pubnub_version_windows.c pubnub_generate_uuid_windows.c pbpal_windows_blocking_io.c ..\core\c99\snprintf.c ..\lib\miniz\miniz_tinfl.c ..\lib\miniz\miniz_tdef.c ..\lib\miniz\miniz.c ..\lib\pbcrc32.c ..\core\pbgzip_compress.c ..\core\pbgzip_decompress.c ..\core\pbcc_subscribe_v2.c ..\core\pubnub_subscribe_v2.c msstopwatch_windows.c ..\core\pubnub_url_encode.c ..\core\pbcc_advanced_history.c ..\core\pubnub_advanced_history.c ..\core\pbcc_objects_api.c ..\core\pubnub_objects_api.c ..\core\pbcc_actions_api.c ..\core\pubnub_actions_api.c +SOURCEFILES = ..\core\pubnub_pubsubapi.c ..\core\pubnub_coreapi.c ..\core\pubnub_coreapi_ex.c ..\core\pubnub_ccore_pubsub.c ..\core\pubnub_ccore.c ..\core\pubnub_netcore.c ..\lib\sockets\pbpal_sockets.c ..\lib\sockets\pbpal_resolv_and_connect_sockets.c ..\lib\sockets\pbpal_handle_socket_error.c ..\core\pubnub_alloc_std.c ..\core\pubnub_assert_std.c ..\core\pubnub_generate_uuid.c ..\core\pubnub_blocking_io.c ..\windows\windows_socket_blocking_io.c ..\core\pubnub_free_with_timeout_std.c ..\lib\base64\pbbase64.c ..\core\pubnub_timers.c ..\core\pubnub_json_parse.c ..\lib\md5\md5.c ..\lib\pb_strnlen_s.c ..\core\pubnub_helper.c pubnub_version_windows.c pubnub_generate_uuid_windows.c pbpal_windows_blocking_io.c ..\core\c99\snprintf.c ..\lib\miniz\miniz_tinfl.c ..\lib\miniz\miniz_tdef.c ..\lib\miniz\miniz.c ..\lib\pbcrc32.c ..\core\pbgzip_compress.c ..\core\pbgzip_decompress.c ..\core\pbcc_subscribe_v2.c ..\core\pubnub_subscribe_v2.c msstopwatch_windows.c ..\core\pubnub_url_encode.c ..\core\pbcc_advanced_history.c ..\core\pubnub_advanced_history.c ..\core\pbcc_objects_api.c ..\core\pubnub_objects_api.c ..\core\pbcc_actions_api.c ..\core\pubnub_actions_api.c ..\core\pubnub_memory_block.c -OBJFILES = pubnub_pubsubapi.obj pubnub_coreapi.obj pubnub_coreapi_ex.obj pubnub_ccore_pubsub.obj pubnub_ccore.obj pubnub_netcore.obj pbpal_sockets.obj pbpal_resolv_and_connect_sockets.obj pbpal_handle_socket_error.obj pubnub_alloc_std.obj pubnub_assert_std.obj pubnub_generate_uuid.obj pubnub_blocking_io.obj windows_socket_blocking_io.obj pubnub_free_with_timeout_std.obj pbbase64.obj pubnub_timers.obj pubnub_json_parse.obj md5.obj pb_strnlen_s.obj pubnub_helper.obj pubnub_version_windows.obj pubnub_generate_uuid_windows.obj pbpal_windows_blocking_io.obj snprintf.obj miniz_tinfl.obj miniz_tdef.obj miniz.obj pbcrc32.obj pbgzip_compress.obj pbgzip_decompress.obj pbcc_subscribe_v2.obj pubnub_subscribe_v2.obj msstopwatch_windows.obj pubnub_url_encode.obj pbcc_advanced_history.obj pubnub_advanced_history.obj pbcc_objects_api.obj pubnub_objects_api.obj pbcc_actions_api.obj pubnub_actions_api.obj +OBJFILES = pubnub_pubsubapi.obj pubnub_coreapi.obj pubnub_coreapi_ex.obj pubnub_ccore_pubsub.obj pubnub_ccore.obj pubnub_netcore.obj pbpal_sockets.obj pbpal_resolv_and_connect_sockets.obj pbpal_handle_socket_error.obj pubnub_alloc_std.obj pubnub_assert_std.obj pubnub_generate_uuid.obj pubnub_blocking_io.obj windows_socket_blocking_io.obj pubnub_free_with_timeout_std.obj pbbase64.obj pubnub_timers.obj pubnub_json_parse.obj md5.obj pb_strnlen_s.obj pubnub_helper.obj pubnub_version_windows.obj pubnub_generate_uuid_windows.obj pbpal_windows_blocking_io.obj snprintf.obj miniz_tinfl.obj miniz_tdef.obj miniz.obj pbcrc32.obj pbgzip_compress.obj pbgzip_decompress.obj pbcc_subscribe_v2.obj pubnub_subscribe_v2.obj msstopwatch_windows.obj pubnub_url_encode.obj pbcc_advanced_history.obj pubnub_advanced_history.obj pbcc_objects_api.obj pubnub_objects_api.obj pbcc_actions_api.obj pubnub_actions_api.obj pubnub_memory_block.obj LDLIBS=ws2_32.lib IPHlpAPI.lib rpcrt4.lib