Skip to content

Commit 759dff0

Browse files
Add Pubnub sdk (C-Core) logs passing to UE sdk. (#42)
feat(log): pass logs from c-core to UE sdk. Now all logs from C-Core will be printed the same way as UE sdk logs.
1 parent 32dd0b7 commit 759dff0

36 files changed

+792
-1255
lines changed

.pubnub.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
name: unreal-engine
2-
version: 0.1.0
2+
version: 0.2.4
33
schema: 1
44
scm: github.com/pubnub/unreal-engine
55
changelog:
6+
- date: 2024-01-21
7+
version: 0.2.4
8+
changes:
9+
- type: feature
10+
text: "Pass logs from c-core to UE sdk."
11+
- date: 2024-11-28
12+
version: 0.2.3
13+
changes:
14+
- type: bug
15+
text: "Fix incorrect memberships input object Json checks"
616
- date: 2024-11-25
717
version: 0.2.2
818
changes:

PubnubLibrary.uplugin

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"FileVersion": 3,
3-
"Version": 3,
4-
"VersionName": "0.2.3",
3+
"Version": 4,
4+
"VersionName": "0.2.4",
55
"FriendlyName": "Pubnub Unreal SDK",
66
"Description": "Quickly add interactive features to your game that scale without building your backend infrastructure.",
77
"Category": "Code",

Source/PubnubLibrary/Private/PubnubSubsystem.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#include "PubnubSubsystem.h"
44
#include "Json.h"
5-
65
#include "Config/PubnubSettings.h"
76
#include "FunctionLibraries/PubnubJsonUtilities.h"
87
#include "FunctionLibraries/PubnubUtilities.h"
@@ -1066,6 +1065,9 @@ void UPubnubSubsystem::InitPubnub_priv()
10661065
ctx_pub = pubnub_alloc();
10671066
ctx_sub = pubnub_alloc();
10681067

1068+
//Send logging callback to Pubnub sdk, so we can pass all logs to UE
1069+
pubnub_set_log_callback(PubnubSDKLogConverter);
1070+
10691071
pubnub_init(ctx_pub, PublishKey, SubscribeKey);
10701072
pubnub_init(ctx_sub, PublishKey, SubscribeKey);
10711073

Source/PubnubLibrary/Public/PubnubSubsystem.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,4 +892,21 @@ class PUBNUBLIBRARY_API UPubnubSubsystem : public UGameInstanceSubsystem
892892
TSharedPtr<FJsonObject> AddChannelPermissionsToJson(TArray<FString> Channels, TArray<FPubnubChannelPermissions> ChannelPermissions);
893893
TSharedPtr<FJsonObject> AddChannelGroupPermissionsToJson(TArray<FString> ChannelGroups, TArray<FPubnubChannelGroupPermissions> ChannelGroupPermissions);
894894
TSharedPtr<FJsonObject> AddUserPermissionsToJson(TArray<FString> Users, TArray<FPubnubUserPermissions> UserPermissions);
895+
896+
//Function that is sent to Pubnub sdk (c-core) to pass sdk logs to Unreal
897+
static void PubnubSDKLogConverter(enum pubnub_log_level log_level, const char* message) {
898+
switch (log_level)
899+
{
900+
case pubnub_log_level::PUBNUB_LOG_LEVEL_WARNING:
901+
UE_LOG(PubnubLog, Warning, TEXT("%s"), UTF8_TO_TCHAR(message));
902+
break;
903+
case pubnub_log_level::PUBNUB_LOG_LEVEL_ERROR:
904+
UE_LOG(PubnubLog, Error, TEXT("%s"), UTF8_TO_TCHAR(message));
905+
break;
906+
default:
907+
UE_LOG(PubnubLog, Log, TEXT("%s"), UTF8_TO_TCHAR(message));
908+
break;
909+
};
910+
};
895911
};
912+

Source/ThirdParty/sdk/Include/core/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
PROJECT_SOURCEFILES = pbcc_set_state.c pubnub_pubsubapi.c pubnub_coreapi.c pubnub_ccore_pubsub.c pubnub_ccore.c pubnub_netcore.c pubnub_alloc_static.c pubnub_assert_std.c pubnub_json_parse.c pubnub_keep_alive.c pubnub_helper.c pubnub_url_encode.c ../lib/pb_strnlen_s.c ../lib/pb_strncasecmp.c ../lib/base64/pbbase64.c pubnub_coreapi_ex.c
1+
PROJECT_SOURCEFILES = pbcc_set_state.c pubnub_pubsubapi.c pubnub_coreapi.c pubnub_ccore_pubsub.c pubnub_ccore.c pubnub_netcore.c pubnub_alloc_static.c pubnub_assert_std.c pubnub_json_parse.c pubnub_keep_alive.c pubnub_helper.c pubnub_url_encode.c ../lib/pb_strnlen_s.c ../lib/pb_strncasecmp.c ../lib/base64/pbbase64.c pubnub_coreapi_ex.c pubnub_log.c
22
# TODO: move coreapi_ex to new module
33

44
all: pubnub_crypto_unittest pubnub_subscribe_v2_unittest pbcc_crypto_unittest pubnub_grant_token_api_unittest pubnub_proxy_unittest pubnub_timer_list_unittest unittest
@@ -17,7 +17,7 @@ endif
1717

1818
generate_report: all
1919
#$(GCOVR) -r . --html --html-details -o coverage.html
20-
$(GCOVR) -r . --xml -o coverage.xml
20+
#$(GCOVR) -r . --xml -o coverage.xml
2121

2222
ifndef RECEIVE_GZIP_RESPONSE
2323
RECEIVE_GZIP_RESPONSE = 1
@@ -57,7 +57,7 @@ unittest: $(PROJECT_SOURCEFILES) pubnub_core_unit_test.c
5757
#$(GCOVR) -r . --html --html-details -o coverage.html
5858

5959

60-
TIMER_LIST_SOURCEFILES = pubnub_alloc_static.c pubnub_assert_std.c pubnub_timers.c
60+
TIMER_LIST_SOURCEFILES = pubnub_alloc_static.c pubnub_assert_std.c pubnub_timers.c pubnub_log.c
6161

6262
pubnub_timer_list_unittest: pubnub_timer_list.c pubnub_timer_list_unit_test.c
6363
gcc -o pubnub_timer_list_unit_test.so -shared $(CFLAGS) $(LDFLAGS) -D PUBNUB_CALLBACK_API -D PUBNUB_ASSERT_LEVEL_NONE -Wall $(COVERAGE_FLAGS) -fPIC $(TIMER_LIST_SOURCEFILES) pubnub_timer_list.c pubnub_timer_list_unit_test.c -lcgreen -lm

Source/ThirdParty/sdk/Include/core/pbcc_fetch_history.c

Lines changed: 75 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -18,58 +18,87 @@
1818

1919

2020
enum pubnub_res pbcc_fetch_history_prep(struct pbcc_context* pb,
21-
const char* channel,
22-
unsigned int max_per_channel,
23-
enum pubnub_tribool include_meta,
24-
enum pubnub_tribool include_custom_message_type,
25-
enum pubnub_tribool include_message_type,
26-
enum pubnub_tribool include_user_id,
27-
enum pubnub_tribool include_message_actions,
28-
enum pubnub_tribool reverse,
29-
char const* start,
30-
char const* end)
21+
const char* channel,
22+
unsigned int max_per_channel,
23+
enum pubnub_tribool include_meta,
24+
enum pubnub_tribool
25+
include_custom_message_type,
26+
enum pubnub_tribool
27+
include_message_type,
28+
enum pubnub_tribool include_user_id,
29+
enum pubnub_tribool
30+
include_message_actions,
31+
enum pubnub_tribool reverse,
32+
char const* start,
33+
char const* end)
3134
{
3235
char const* const uname = pubnub_uname();
33-
enum pubnub_res rslt = PNR_OK;
36+
enum pubnub_res rslt = PNR_OK;
3437

3538
pb->http_content_len = 0;
36-
pb->msg_ofs = pb->msg_end = 0;
39+
pb->msg_ofs = pb->msg_end = 0;
3740

3841
pb->http_buf_len = snprintf(pb->http_buf,
3942
sizeof pb->http_buf,
4043
"/v3/%s/sub-key/%s/channel/",
41-
(include_message_actions == pbccTrue) ? "history-with-actions" : "history",
44+
(include_message_actions == pbccTrue)
45+
? "history-with-actions"
46+
: "history",
4247
pb->subscribe_key);
4348
APPEND_URL_ENCODED_M(pb, channel);
4449

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

48-
int ch_count = 0;
49-
char* ch_lst = (char*)strtok((char*)channel, ",");
53+
int ch_count = 0;
54+
char* ch_lst = (char*)strtok((char*)channel, ",");
5055
while (ch_lst != NULL) {
5156
ch_count++;
5257
ch_lst = (char*)strtok(NULL, ",");
5358
}
5459
if (max_per_channel <= 0) {
55-
if (include_message_actions == pbccTrue || ch_count > 1) { max_per_channel = 25; }
56-
else {max_per_channel = 100; }
60+
if (include_message_actions == pbccTrue || ch_count > 1) {
61+
max_per_channel = 25;
62+
}
63+
else { max_per_channel = 100; }
5764
}
5865
char max_per_ch_cnt_buf[sizeof(int) * 4 + 1];
59-
sprintf(max_per_ch_cnt_buf, "%d", max_per_channel);
66+
snprintf(max_per_ch_cnt_buf,
67+
sizeof(max_per_ch_cnt_buf),
68+
"%d",
69+
max_per_channel);
6070
if (max_per_channel) { ADD_URL_PARAM(qparam, max, max_per_ch_cnt_buf); }
6171

62-
if (include_meta != pbccNotSet) { ADD_URL_PARAM(qparam, include_meta, include_meta == pbccTrue ? "true" : "false"); }
63-
if (include_custom_message_type != pbccNotSet) { ADD_URL_PARAM(qparam, include_custom_message_type, include_custom_message_type == pbccTrue ? "true" : "false"); }
64-
if (include_message_type != pbccNotSet) { ADD_URL_PARAM(qparam, include_message_type, include_message_type == pbccTrue ? "true" : "false"); }
65-
if (include_user_id != pbccNotSet) { ADD_URL_PARAM(qparam, include_uuid, include_user_id == pbccTrue ? "true" : "false"); }
72+
if (include_meta != pbccNotSet) {
73+
ADD_URL_PARAM(qparam,
74+
include_meta,
75+
include_meta == pbccTrue ? "true" : "false");
76+
}
77+
if (include_custom_message_type != pbccNotSet) {
78+
ADD_URL_PARAM(qparam,
79+
include_custom_message_type,
80+
include_custom_message_type == pbccTrue ? "true" :
81+
"false");
82+
}
83+
if (include_message_type != pbccNotSet) {
84+
ADD_URL_PARAM(qparam,
85+
include_message_type,
86+
include_message_type == pbccTrue ? "true" : "false");
87+
}
88+
if (include_user_id != pbccNotSet) {
89+
ADD_URL_PARAM(qparam,
90+
include_uuid,
91+
include_user_id == pbccTrue ? "true" : "false");
92+
}
6693
#if PUBNUB_CRYPTO_API
6794
if (pb->secret_key == NULL) { ADD_URL_AUTH_PARAM(pb, qparam, auth); }
6895
ADD_TS_TO_URL_PARAM();
6996
#else
7097
ADD_URL_AUTH_PARAM(pb, qparam, auth);
7198
#endif
72-
if (reverse != pbccNotSet) { ADD_URL_PARAM(qparam, reverse, reverse == pbccTrue ? "true" : "false"); }
99+
if (reverse != pbccNotSet) {
100+
ADD_URL_PARAM(qparam, reverse, reverse == pbccTrue ? "true" : "false");
101+
}
73102
if (start) { ADD_URL_PARAM(qparam, start, start); }
74103
if (end) { ADD_URL_PARAM(qparam, end, end); }
75104

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

90119
enum pubnub_res pbcc_parse_fetch_history_response(struct pbcc_context* pb)
91120
{
92-
char* reply = pb->http_reply;
93-
int replylen = pb->http_buf_len;
121+
char* reply = pb->http_reply;
122+
int replylen = pb->http_buf_len;
94123
struct pbjson_elem elem;
95124

96125
if ((replylen < 2) || (reply[0] != '{')) {
97126
return PNR_FORMAT_ERROR;
98127
}
99-
128+
100129
pb->msg_end = replylen + 1;
101130

102131
elem.end = pbjson_find_end_element(reply, reply + replylen);
103132
/* elem.end has to be just behind end curly brace */
104133
if ((*reply != '{') || (*(elem.end++) != '}')) {
105-
PUBNUB_LOG_ERROR("pbcc_parse_fetch_history_response(pbcc=%p) - Invalid: "
106-
"response from server is not JSON - response='%s'\n",
107-
pb,
108-
reply);
134+
PUBNUB_LOG_ERROR(
135+
"pbcc_parse_fetch_history_response(pbcc=%p) - Invalid: "
136+
"response from server is not JSON - response='%s'\n",
137+
pb,
138+
reply);
109139

110140
return PNR_FORMAT_ERROR;
111141
}
112142
elem.start = reply;
113143

114-
if (pbjson_value_for_field_found(&elem, "status", "403")){
115-
PUBNUB_LOG_ERROR("pbcc_parse_fetch_history_response(pbcc=%p) - AccessDenied: "
116-
"response from server - response='%s'\n",
117-
pb,
118-
reply);
144+
if (pbjson_value_for_field_found(&elem, "status", "403")) {
145+
PUBNUB_LOG_ERROR(
146+
"pbcc_parse_fetch_history_response(pbcc=%p) - AccessDenied: "
147+
"response from server - response='%s'\n",
148+
pb,
149+
reply);
119150
return PNR_ACCESS_DENIED;
120151
}
121152

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

133164
pubnub_chamebl_t pbcc_get_fetch_history(struct pbcc_context* pb)
134165
{
135-
pubnub_chamebl_t result;
136-
char const* reply = pb->http_reply;
137-
int replylen = pb->http_buf_len;
166+
pubnub_chamebl_t result;
167+
char const* reply = pb->http_reply;
168+
int replylen = pb->http_buf_len;
138169
struct pbjson_elem elem;
139170
if (pb->last_result != PNR_OK) {
140171
PUBNUB_LOG_ERROR("pbcc_get_fetch_history(pb=%p) can be called only if "
@@ -144,16 +175,16 @@ pubnub_chamebl_t pbcc_get_fetch_history(struct pbcc_context* pb)
144175
PBTT_FETCH_HISTORY,
145176
pb->last_result,
146177
pubnub_res_2_string(pb->last_result));
147-
result.ptr = NULL;
178+
result.ptr = NULL;
148179
result.size = 0;
149180
return result;
150181
}
151-
182+
152183
elem.start = reply;
153-
elem.end = pbjson_find_end_element(reply, reply + replylen) + 1;
184+
elem.end = pbjson_find_end_element(reply, reply + replylen) + 1;
154185

155-
result.size = elem.end - elem.start;
156-
result.ptr = (char*)elem.start;
186+
result.size = elem.end - elem.start;
187+
result.ptr = (char*)elem.start;
157188
result.ptr[result.size] = '\0';
158189

159190
return result;

Source/ThirdParty/sdk/Include/core/pbcc_subscribe_event_engine.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
/* -*- c-file-style:"stroustrup"; indent-tabs-mode: nil -*- */
22
#include "pbcc_subscribe_event_engine.h"
33

4-
#include <pthread.h>
54
#include <string.h>
65
#include <stdlib.h>
7-
#include <unistd.h>
86

97
#include "core/pubnub_helper.h"
108
#include "core/pubnub_subscribe_event_engine_internal.h"
@@ -215,7 +213,7 @@ pbcc_subscribe_ee_t* pbcc_subscribe_ee_alloc(pubnub_t* pb)
215213
PBARRAY_CHAR_CONTENT_TYPE,
216214
(pbarray_element_free)free);
217215
ee->current_transaction = PBTT_NONE;
218-
ee->cancel_invocation = NULL;
216+
ee->cancel_invocation = NULL;
219217
pubnub_mutex_init(ee->mutw);
220218

221219
if (NULL == ee->subscriptions) {
@@ -557,7 +555,7 @@ enum pubnub_res pbcc_subscribe_ee_unsubscribe_all(pbcc_subscribe_ee_t* ee)
557555
PUBNUB_ASSERT_OPT(NULL != ee);
558556

559557
pubnub_mutex_lock(ee->mutw);
560-
char* ch,* cg;
558+
char * ch, *cg;
561559
enum pubnub_res rslt = pbcc_subscribe_ee_subscribables_(ee->subscribables,
562560
&ch,
563561
&cg,
@@ -736,7 +734,7 @@ enum pubnub_res pbcc_subscribe_ee_subscribe_(
736734
const bool sent_by_ee)
737735
{
738736
pbcc_ee_event_t* event = NULL;
739-
char* ch = NULL,* cg = NULL;
737+
char * ch = NULL, *cg = NULL;
740738
enum pubnub_res rslt = PNR_OK;
741739

742740
if (update) { rslt = pbcc_subscribe_ee_update_subscribables_(ee); }
@@ -798,7 +796,7 @@ enum pubnub_res pbcc_subscribe_ee_unsubscribe_(
798796
pbcc_subscribe_ee_t* ee,
799797
pbhash_set_t* subscribables)
800798
{
801-
char* ch = NULL,* cg = NULL;
799+
char *ch = NULL, *cg = NULL;
802800
bool send_leave = false;
803801

804802
size_t count = 0;
@@ -1070,14 +1068,14 @@ enum pubnub_res pbcc_subscribe_ee_subscribables_(
10701068
ch_offset += snprintf(*channels + ch_offset,
10711069
ch_len - ch_offset,
10721070
"%s%s",
1073-
ch_offset > 0 ? ",": "",
1071+
ch_offset > 0 ? "," : "",
10741072
sub->id->ptr);
10751073
}
10761074
else {
10771075
cg_offset += snprintf(*channel_groups + cg_offset,
10781076
cg_len - cg_offset,
10791077
"%s%s",
1080-
cg_offset > 0 ? ",": "",
1078+
cg_offset > 0 ? "," : "",
10811079
sub->id->ptr);
10821080
}
10831081
}

0 commit comments

Comments
 (0)