Skip to content

Commit

Permalink
Dev/prerelease fixes vol3 (#14)
Browse files Browse the repository at this point in the history

Co-authored-by: KamilGronek <[email protected]>
  • Loading branch information
Xavrax and KamilGronek authored Aug 14, 2024
1 parent 9ff437f commit 97e570e
Show file tree
Hide file tree
Showing 62 changed files with 2,549 additions and 247 deletions.
19 changes: 17 additions & 2 deletions Source/PubnubLibrary/Private/PubnubLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,33 @@

#include "PubnubLibrary.h"
#include "Core.h"
#include "Kismet/KismetSystemLibrary.h"
#include "Interfaces/IPluginManager.h"

#define LOCTEXT_NAMESPACE "FPubnubLibraryModule"

void FPubnubLibraryModule::StartupModule()
{
#if PLATFORM_MAC
FString BaseDir = IPluginManager::Get().FindPlugin("PubnubChat")->GetBaseDir();
FString LibraryPath;
LibraryPath = FPaths::Combine(*BaseDir, TEXT("Source/ThirdParty/sdk/lib/macos/libpubnub-chat.dylib"));


ChatSDKLibraryHandle = !LibraryPath.IsEmpty() ? FPlatformProcess::GetDllHandle(*LibraryPath) : nullptr;

if (!ChatSDKLibraryHandle)
{
FMessageDialog::Open(EAppMsgType::Ok, LOCTEXT("ChatSDKModuleHandle", "Failed to load pubnub third party library"));
}
#endif
}

void FPubnubLibraryModule::ShutdownModule()
{

#if PLATFORM_MAC
FPlatformProcess::FreeDllHandle(ChatSDKLibraryHandle);
ChatSDKLibraryHandle = nullptr;
#endif
}

#undef LOCTEXT_NAMESPACE
Expand Down
1 change: 1 addition & 0 deletions Source/PubnubLibrary/Public/PubnubLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ class FPubnubLibraryModule : public IModuleInterface
virtual void StartupModule() override;
virtual void ShutdownModule() override;

void* PubnubLibraryHandle;
};
8 changes: 4 additions & 4 deletions Source/ThirdParty/sdk/Include/core/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ pbcc_crypto_unittest: $(PROJECT_SOURCEFILES) $(CRYPTO_SOURCEFILES) pbcc_crypto_u
$(CGREEN_RUNNER) ./pbcc_crypto_unit_test.so
#$(GCOVR) -r . --html --html-details -o coverage.html

pubnub_crypto_unittest: $(PROJECT_SOURCEFILES) $(CRYPTO_SOURCEFILES) pubnub_crypto_unit_tests.c
gcc -o pubnub_crypto_unit_test.so -shared $(CFLAGS) $(LDFLAGS) $(CRYPTO_INCLUDES) $(CRYPTO_LIBS) -D PUBNUB_CRYPTO_API=1 -Wall $(COVERAGE_FLAGS) -fPIC $(PROJECT_SOURCEFILES) $(CRYPTO_SOURCEFILES) test/pubnub_test_mocks.c pubnub_crypto_unit_tests.c -lcgreen -lm
SUBSCRIBE_V2_SOURCEFILES += pubnub_subscribe_v2.c pbcc_subscribe_v2.c

pubnub_crypto_unittest: $(PROJECT_SOURCEFILES) $(CRYPTO_SOURCEFILES) $(SUBSCRIBE_V2_SOURCEFILES) pubnub_crypto_unit_tests.c
gcc -o pubnub_crypto_unit_test.so -shared $(CFLAGS) $(LDFLAGS) $(CRYPTO_INCLUDES) $(CRYPTO_LIBS) -D PUBNUB_CRYPTO_API=1 -D PUBNUB_USE_SUBSCRIBE_V2=1 -Wall $(COVERAGE_FLAGS) -fPIC $(PROJECT_SOURCEFILES) $(CRYPTO_SOURCEFILES) $(SUBSCRIBE_V2_SOURCEFILES) test/pubnub_test_mocks.c pubnub_crypto_unit_tests.c -lcgreen -lm
# gcc -o pubnub_core_unit_testo $(CFLAGS) -Wall $(COVERAGE_FLAGS) $(PROJECT_SOURCEFILES) pubnub_crypto_unit_tests.c -lcgreen -lm
$(CGREEN_RUNNER) ./pubnub_crypto_unit_test.so


SUBSCRIBE_V2_SOURCEFILES += pubnub_subscribe_v2.c pbcc_subscribe_v2.c

pubnub_subscribe_v2_unittest: $(PROJECT_SOURCEFILES) $(SUBSCRIBE_V2_SOURCEFILES) pubnub_subscribe_v2_unit_test.c
gcc -o pubnub_subscribe_v2_unit_test.so -shared $(CFLAGS) $(LDFLAGS) -D PUBNUB_ORIGIN_SETTABLE=1 -D PUBNUB_USE_SUBSCRIBE_V2=1 -Wall $(COVERAGE_FLAGS) -fPIC $(PROJECT_SOURCEFILES) $(SUBSCRIBE_V2_SOURCEFILES) test/pubnub_test_mocks.c pubnub_subscribe_v2_unit_test.c -lcgreen -lm
$(CGREEN_RUNNER) ./pubnub_subscribe_v2_unit_test.so
Expand Down
6 changes: 5 additions & 1 deletion Source/ThirdParty/sdk/Include/core/c99/stdbool.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#define false 0
#define true 1

#ifdef PUBNUB_BOOL_TYPE
#define bool PUBNUB_BOOL_TYPE
#else
#define bool int
#endif

#endif /* !defined __cplusplus */
#endif /* !defined __cplusplus */
60 changes: 40 additions & 20 deletions Source/ThirdParty/sdk/Include/core/pbcc_actions_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) - "
Expand All @@ -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;
Expand Down
19 changes: 18 additions & 1 deletion Source/ThirdParty/sdk/Include/core/pbcc_actions_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "pubnub_api_types.h"
#include "pubnub_memory_block.h"
#include "lib/pb_deprecated.h"

struct pbcc_context;

Expand All @@ -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.
*/
Expand Down
129 changes: 129 additions & 0 deletions Source/ThirdParty/sdk/Include/core/pbcc_advanced_history.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "pubnub_url_encode.h"

#include "pubnub_assert.h"
#include "pubnub_helper.h"
#include "pubnub_log.h"
#else
#error this module can only be used if PUBNUB_USE_ADVANCED_HISTORY is defined and set to 1
Expand Down Expand Up @@ -543,3 +544,131 @@ enum pubnub_res pbcc_message_counts_prep(
PUBNUB_LOG_DEBUG("pbcc_message_counts_prep. REQUEST =%s\n", p->http_buf);
return (rslt != PNR_OK) ? rslt : PNR_STARTED;
}

enum pubnub_res pbcc_delete_messages_prep(struct pbcc_context* pb,
char const* channel,
char const* start,
char const* end)
{
char const* const uname = pubnub_uname();
char const* user_id = pbcc_user_id_get(pb);
#if PUBNUB_CRYPTO_API
enum pubnub_res rslt = PNR_OK;
#endif

PUBNUB_ASSERT_OPT(NULL != user_id);

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

pb->http_buf_len =
snprintf(pb->http_buf,
sizeof pb->http_buf,
"/v3/history/sub-key/%s/channel/",
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); }
ADD_URL_PARAM(qparam, uuid, user_id);
#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 (start) { ADD_URL_PARAM(qparam, start, start); }
if (end) { ADD_URL_PARAM(qparam, end, end); }

#if PUBNUB_CRYPTO_API
SORT_URL_PARAMETERS(qparam);
#endif
ENCODE_URL_PARAMETERS(pb, qparam);
#if PUBNUB_CRYPTO_API
if (pb->secret_key != NULL) {
rslt = pbcc_sign_url(pb, "", pubnubSendViaGET, true);
}
#endif

PUBNUB_LOG_DEBUG("pbcc_delete_messages_prep. REQUEST =%s\n", pb->http_buf);
#if PUBNUB_CRYPTO_API
return (rslt != PNR_OK) ? rslt : PNR_STARTED;
#else
return PNR_STARTED;
#endif
}

pubnub_chamebl_t pbcc_get_delete_messages_response(struct pbcc_context* pb)
{
pubnub_chamebl_t resp;
char const* reply = pb->http_reply;
int reply_len = pb->http_buf_len;

if (PNR_OK != pb->last_result) {
PUBNUB_LOG_ERROR("pbcc_get_delete_messages_response(pb=%p) can be "
"called only if previous transactin "
"PBTT_DELETE_MESSAGES(%d) is finished successfully. "
"Transaction result was: %d('%s')\n",
pb,
PBTT_DELETE_MESSAGES,
pb->last_result,
pubnub_res_2_string(pb->last_result));
resp.ptr = NULL;
resp.size = 0;
return resp;
}

resp.ptr = (char*)reply;
resp.size = reply_len;
return resp;
}

enum pubnub_res pbcc_parse_delete_messages_response(struct pbcc_context* pb)
{
enum pbjson_object_name_parse_result jpresult;
struct pbjson_elem el;
struct pbjson_elem found;
char* reply = pb->http_reply;
int reply_len = pb->http_buf_len;

if ((reply[0] != '{') || (reply[reply_len - 1] != '}')) {
PUBNUB_LOG_ERROR(
"Error: pbcc_parse_delete_messages_response(pbcc=%p) - "
"Response is not json object: response='%.*s'\n",
pb,
reply_len,
reply);
return PNR_FORMAT_ERROR;
}
el.start = reply;
el.end = reply + reply_len;
if (pbjson_value_for_field_found(&el, "status", "403")) {
PUBNUB_LOG_ERROR(
"Error: pbcc_parse_delete_messages_response(pbcc=%p) - "
"Access Denied: response='%.*s'\n",
pb,
reply_len,
reply);
return PNR_ACCESS_DENIED;
}
jpresult = pbjson_get_object_value(&el, "error", &found);
if (jonmpOK == jpresult) {
if (pbjson_elem_equals_string(&found, "true")) {
return PNR_ERROR_ON_SERVER;
}
}
else {
PUBNUB_LOG_ERROR(
"Error: pbcc_parse_delete_messages_response(pbcc=%p) - "
"'error' atribute not found in the response. error=%d\n"
"response='%.*s'\n",
pb,
jpresult,
reply_len,
reply);
return PNR_FORMAT_ERROR;
}
pb->chan_ofs = pb->chan_end = 0;

return PNR_OK;
}
37 changes: 37 additions & 0 deletions Source/ThirdParty/sdk/Include/core/pbcc_advanced_history.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,43 @@ enum pubnub_res pbcc_message_counts_prep(
char const* channel,
char const* timetoken,
char const* channel_timetokens);

/**
* @brief Prepare `delete messages` operation (transaction), mostly by
* formatting the URI of the HTTP request.
*
* @param pb PubNub context which provides resources to send request.
* @param channel Channel from which messages should be deleted.
* @param start Timetoken delimiting the start of time slice (exclusive) to
* delete messages from.
* @param end Timetoken delimiting the end of time slice (inclusive) to
* delete messages to.
* @return Results of `delete messages` transaction call.
*/
enum pubnub_res pbcc_delete_messages_prep(struct pbcc_context* pb,
char const* channel,
char const* start,
char const* end);

/**
* @brief Get `delete messages` service response.
*
* @param pb PubNub context which has been used to delete channel messages.
* @return `pubnub_chamebl_t` with pointer to string with response.
*/
pubnub_chamebl_t pbcc_get_delete_messages_response(struct pbcc_context* pb);



/**
* @brief Parses the string received as a response for a history v3
* operation (transaction).
*
* @param pb PubNub context to parse delete channel messages response.
* @return PNR_OK: OK, !PNR_OK: error (invalid response)
*/
enum pubnub_res pbcc_parse_delete_messages_response(struct pbcc_context* pb);

#endif /* INC_PBCC_ADVANCED_HISTORY */
#endif /* PUBNUB_USE_ADVANCED_HISTORY */

Loading

0 comments on commit 97e570e

Please sign in to comment.