diff --git a/.pubnub.yml b/.pubnub.yml index 736e780f..f0df2e95 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,8 +1,15 @@ name: c-core schema: 1 -version: "4.9.0" +version: "4.10.0" scm: github.com/pubnub/c-core changelog: + - date: 2024-06-14 + version: v4.10.0 + changes: + - type: feature + text: "Added possibility to use strings in actions API." + - type: improvement + text: "`pubnub_action_type` enum has been deprecated." - date: 2024-03-26 version: v4.9.1 changes: @@ -787,7 +794,7 @@ sdks: distribution-type: source code distribution-repository: GitHub release package-name: C-Core - location: https://github.com/pubnub/c-core/releases/tag/v4.9.0 + location: https://github.com/pubnub/c-core/releases/tag/v4.10.0 requires: - name: "miniz" @@ -853,7 +860,7 @@ sdks: distribution-type: source code distribution-repository: GitHub release package-name: C-Core - location: https://github.com/pubnub/c-core/releases/tag/v4.9.0 + location: https://github.com/pubnub/c-core/releases/tag/v4.10.0 requires: - name: "miniz" @@ -919,7 +926,7 @@ sdks: distribution-type: source code distribution-repository: GitHub release package-name: C-Core - location: https://github.com/pubnub/c-core/releases/tag/v4.9.0 + location: https://github.com/pubnub/c-core/releases/tag/v4.10.0 requires: - name: "miniz" @@ -981,7 +988,7 @@ sdks: distribution-type: source code distribution-repository: GitHub release package-name: C-Core - location: https://github.com/pubnub/c-core/releases/tag/v4.9.0 + location: https://github.com/pubnub/c-core/releases/tag/v4.10.0 requires: - name: "miniz" @@ -1042,7 +1049,7 @@ sdks: distribution-type: source code distribution-repository: GitHub release package-name: C-Core - location: https://github.com/pubnub/c-core/releases/tag/v4.9.0 + location: https://github.com/pubnub/c-core/releases/tag/v4.10.0 requires: - name: "miniz" @@ -1098,7 +1105,7 @@ sdks: distribution-type: source code distribution-repository: GitHub release package-name: C-Core - location: https://github.com/pubnub/c-core/releases/tag/v4.9.0 + location: https://github.com/pubnub/c-core/releases/tag/v4.10.0 requires: - name: "miniz" @@ -1151,7 +1158,7 @@ sdks: distribution-type: source code distribution-repository: GitHub release package-name: C-Core - location: https://github.com/pubnub/c-core/releases/tag/v4.9.0 + location: https://github.com/pubnub/c-core/releases/tag/v4.10.0 requires: - name: "miniz" diff --git a/CHANGELOG.md b/CHANGELOG.md index 0af13f52..733c6770 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +## v4.10.0 +June 14 2024 + +#### Added +- Added possibility to use strings in actions API. + +#### Modified +- `pubnub_action_type` enum has been deprecated. + + + ## v4.9.1 March 26 2024 diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d23eb54..49e8abbb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ # CMakeLists.txt for the C-core library of Pubnub. cmake_minimum_required(VERSION 3.12) -project(c-core VERSION 4.8.0) +project(c-core VERSION 4.10.0) message(STATUS Preparing\ ${PROJECT_NAME}\ version\ ${PROJECT_VERSION}) diff --git a/core/pbcc_actions_api.c b/core/pbcc_actions_api.c index 5cd52a24..b1400f31 100644 --- a/core/pbcc_actions_api.c +++ b/core/pbcc_actions_api.c @@ -17,17 +17,45 @@ /* Maximum number of actions to return in response */ #define MAX_ACTIONS_LIMIT 100 +#define MAX_ACTION_TYPE_LENGTH 15 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** val) -{ - char const* user_id = pbcc_user_id_get(pb); + char const** val) { char const* type_literal; + switch(actype) { + case pbactypReaction: + type_literal = "\"reaction\""; + break; + case pbactypReceipt: + type_literal = "\"receipt\""; + break; + case pbactypCustom: + type_literal = "\"custom\""; + break; + default: + PUBNUB_LOG_ERROR("pbcc_form_the_action_object(pbcc=%p) - " + "unknown action type = %d\n", + pb, + actype); + return PNR_INVALID_PARAMETERS; + } + + return pbcc_form_the_action_object_str(pb, obj_buffer, buffer_size, type_literal, val); +} + + +enum pubnub_res pbcc_form_the_action_object_str(struct pbcc_context* pb, + char* obj_buffer, + size_t buffer_size, + char const* action_type, + char const** val) { + char const* user_id = pbcc_user_id_get(pb); + PUBNUB_ASSERT_OPT(user_id != NULL); if (NULL == user_id) { @@ -42,25 +70,17 @@ enum pubnub_res pbcc_form_the_action_object(struct pbcc_context* pb, *val); return PNR_INVALID_PARAMETERS; } - switch(actype) { - case pbactypReaction: - type_literal = "reaction"; - break; - case pbactypReceipt: - type_literal = "receipt"; - break; - case pbactypCustom: - type_literal = "custom"; - break; - default: + if (('\"' != *action_type) || ('\"' != *(action_type + pb_strnlen_s(action_type, MAX_ACTION_TYPE_LENGTH) - 1))) { PUBNUB_LOG_ERROR("pbcc_form_the_action_object(pbcc=%p) - " - "unknown action type = %d\n", + "quotation marks on action type ends are missing: " + "action_type = %s\n", pb, - actype); + action_type); return PNR_INVALID_PARAMETERS; } + if (buffer_size < sizeof("{\"type\":\"\",\"value\":,\"user_id\":\"\"}") + - pb_strnlen_s(type_literal, sizeof "reaction") + + pb_strnlen_s(action_type, MAX_ACTION_TYPE_LENGTH) + pb_strnlen_s(*val, PUBNUB_MAX_OBJECT_LENGTH) + pb->user_id_len) { PUBNUB_LOG_ERROR("pbcc_form_the_action_object(pbcc=%p) - " @@ -70,15 +90,15 @@ enum pubnub_res pbcc_form_the_action_object(struct pbcc_context* pb, pb, (unsigned long)buffer_size, (unsigned long)(sizeof("{\"type\":\"\",\"value\":,\"user_id\":\"\"}") + - pb_strnlen_s(type_literal, sizeof "reaction") + + pb_strnlen_s(action_type, MAX_ACTION_TYPE_LENGTH) + pb_strnlen_s(*val, PUBNUB_MAX_OBJECT_LENGTH) + pb->user_id_len)); return PNR_TX_BUFF_TOO_SMALL; } snprintf(obj_buffer, buffer_size, - "{\"type\":\"%s\",\"value\":%s,\"user_id\":\"%s\"}", - type_literal, + "{\"type\":%s,\"value\":%s,\"user_id\":\"%s\"}", + action_type, *val, user_id); *val = obj_buffer; diff --git a/core/pbcc_actions_api.h b/core/pbcc_actions_api.h index b5c0caeb..21b5d621 100644 --- a/core/pbcc_actions_api.h +++ b/core/pbcc_actions_api.h @@ -7,6 +7,7 @@ #include "pubnub_api_types.h" #include "pubnub_memory_block.h" +#include "lib/pb_deprecated.h" struct pbcc_context; @@ -25,14 +26,30 @@ enum pubnub_action_type { }; /** Forms the action object to be sent in 'pubnub_add_action' request body. + + @deprecated This function is deprecated. Use pbcc_form_the_action_object_str() instead. + The present declaration will be changed to the string version in the future. + @see pbcc_form_the_action_object_str + @return #PNR_OK on success, an error otherwise */ -enum pubnub_res pbcc_form_the_action_object(struct pbcc_context* pb, +PUBNUB_DEPRECATED 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); + +/** Forms the action object to be sent in 'pubnub_add_action' request body. + @return #PNR_OK on success, an error otherwise + */ +enum pubnub_res pbcc_form_the_action_object_str(struct pbcc_context* pb, + char* obj_buffer, + size_t buffer_size, + const char* action_type, + char const** json); + + /** Prepares the 'add_action' 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 af1c9e8f..48505247 100644 --- a/core/pubnub_actions_api.c +++ b/core/pubnub_actions_api.c @@ -17,12 +17,40 @@ #include -enum pubnub_res pubnub_add_message_action(pubnub_t* pb, +enum pubnub_res pubnub_add_message_action(pubnub_t *pb, + const char *channel, + const char *message_timetoken, + enum pubnub_action_type actype, + const char *value) { + char const* type_literal; + + switch(actype) { + case pbactypReaction: + type_literal = "\"reaction\""; + break; + case pbactypReceipt: + type_literal = "\"receipt\""; + break; + case pbactypCustom: + type_literal = "\"custom\""; + break; + default: + PUBNUB_LOG_ERROR("pubnub_add_message_action(pbcc=%p) - " + "unknown action type = %d\n", + pb, + actype); + return PNR_INVALID_PARAMETERS; + } + + return pubnub_add_message_action_str(pb, channel, message_timetoken, type_literal, value); +} + + +enum pubnub_res pubnub_add_message_action_str(pubnub_t* pb, char const* channel, char const* message_timetoken, - enum pubnub_action_type actype, - char const* value) -{ + char const* actype, + char const* value) { enum pubnub_res rslt; char obj_buffer[PUBNUB_BUF_MAXLEN]; @@ -34,7 +62,7 @@ enum pubnub_res pubnub_add_message_action(pubnub_t* pb, pubnub_mutex_unlock(pb->monitor); return PNR_IN_PROGRESS; } - rslt = pbcc_form_the_action_object(&pb->core, + rslt = pbcc_form_the_action_object_str(&pb->core, obj_buffer, sizeof obj_buffer, actype, diff --git a/core/pubnub_actions_api.h b/core/pubnub_actions_api.h index 47abbfce..22cc6f58 100644 --- a/core/pubnub_actions_api.h +++ b/core/pubnub_actions_api.h @@ -7,6 +7,7 @@ #include "lib/pb_extern.h" #include "pbcc_actions_api.h" +#include "lib/pb_deprecated.h" #include @@ -18,6 +19,12 @@ 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. + + @deprecated This function is deprecated. Use pubnub_add_message_action_str() instead. + The present declaration will be changed to the string version in the future. + @see pubnub_add_message_action_str() + @see pbcc_action_type_to_str + @param pb The pubnub context. Can't be NULL @param channel The channel on which action is referring to. @param message_timetoken The timetoken(unquoted) of a published message action is @@ -26,13 +33,39 @@ @param value Json string describing the action that is to be added @return #PNR_STARTED on success, an error otherwise */ -PUBNUB_EXTERN enum pubnub_res pubnub_add_message_action(pubnub_t* pb, +PUBNUB_EXTERN PUBNUB_DEPRECATED 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); +/** 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. + + @deprecated This function is deprecated. Use pubnub_add_message_action_str() instead. + @see pubnub_add_message_action_str() + + @param pb The pubnub context. Can't be NULL + @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 action_type Jsoned string describing the action type (Max 15 characters without whitespaces) + @param value Json string describing the action that is to be added + @return #PNR_STARTED on success, an error otherwise + */ +PUBNUB_EXTERN enum pubnub_res pubnub_add_message_action_str(pubnub_t* pb, + char const* channel, + char const* message_timetoken, + char const* action_type, + char const* value); + + /** Searches the response(if previous transaction on the @p pb context had been pubnub_add_message_action and was accomplished successfully) and retrieves timetoken of a message action was added on. diff --git a/core/pubnub_version_internal.h b/core/pubnub_version_internal.h index e270e168..818337cd 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.9.0" +#define PUBNUB_SDK_VERSION "4.10.0" #endif /* !defined INC_PUBNUB_VERSION_INTERNAL */