Skip to content

Commit

Permalink
Merge branch 'master' into feat/new-crypto
Browse files Browse the repository at this point in the history
  • Loading branch information
Xavrax authored Oct 13, 2023
2 parents dbe3e14 + 2fd4975 commit 196c582
Show file tree
Hide file tree
Showing 19 changed files with 417 additions and 17 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
*.pdb
*.ilk

# Compilation database
compile_commands.json

# GitHub Actions #
##################
.github/.release
Expand All @@ -43,4 +46,5 @@
cgreen-src/
cgreen/
cucumber-cpp/
cucumber-cpp-src/
cucumber-cpp-src/

28 changes: 20 additions & 8 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
name: c-core
schema: 1
version: "4.2.2"
version: "4.4.0"
scm: github.com/pubnub/c-core
changelog:
- date: 2023-09-28
version: v4.4.0
changes:
- type: feature
text: "Provide module files to integrate SDK with Unreal Enigne."
- date: 2023-07-24
version: v4.3.0
changes:
- type: feature
text: "Add `publisher` field into `pubnub_v2_message`."
- type: bug
text: "Fixed `flags` and `region` values that always equaled `0`."
- date: 2023-05-24
version: v4.2.2
changes:
Expand Down Expand Up @@ -720,7 +732,7 @@ sdks:
distribution-type: source code
distribution-repository: GitHub release
package-name: C-Core
location: https://github.com/pubnub/c-core/releases/tag/v4.2.2
location: https://github.com/pubnub/c-core/releases/tag/v4.4.0
requires:
-
name: "miniz"
Expand Down Expand Up @@ -786,7 +798,7 @@ sdks:
distribution-type: source code
distribution-repository: GitHub release
package-name: C-Core
location: https://github.com/pubnub/c-core/releases/tag/v4.2.2
location: https://github.com/pubnub/c-core/releases/tag/v4.4.0
requires:
-
name: "miniz"
Expand Down Expand Up @@ -852,7 +864,7 @@ sdks:
distribution-type: source code
distribution-repository: GitHub release
package-name: C-Core
location: https://github.com/pubnub/c-core/releases/tag/v4.2.2
location: https://github.com/pubnub/c-core/releases/tag/v4.4.0
requires:
-
name: "miniz"
Expand Down Expand Up @@ -914,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.2.2
location: https://github.com/pubnub/c-core/releases/tag/v4.4.0
requires:
-
name: "miniz"
Expand Down Expand Up @@ -975,7 +987,7 @@ sdks:
distribution-type: source code
distribution-repository: GitHub release
package-name: C-Core
location: https://github.com/pubnub/c-core/releases/tag/v4.2.2
location: https://github.com/pubnub/c-core/releases/tag/v4.4.0
requires:
-
name: "miniz"
Expand Down Expand Up @@ -1031,7 +1043,7 @@ sdks:
distribution-type: source code
distribution-repository: GitHub release
package-name: C-Core
location: https://github.com/pubnub/c-core/releases/tag/v4.2.2
location: https://github.com/pubnub/c-core/releases/tag/v4.4.0
requires:
-
name: "miniz"
Expand Down Expand Up @@ -1084,7 +1096,7 @@ sdks:
distribution-type: source code
distribution-repository: GitHub release
package-name: C-Core
location: https://github.com/pubnub/c-core/releases/tag/v4.2.2
location: https://github.com/pubnub/c-core/releases/tag/v4.4.0
requires:
-
name: "miniz"
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
## v4.4.0
September 28 2023

#### Added
- Provide module files to integrate SDK with Unreal Enigne.

## v4.3.0
July 24 2023

#### Added
- Add `publisher` field into `pubnub_v2_message`.

#### Fixed
- Fixed `flags` and `region` values that always equaled `0`.

## v4.2.2
May 24 2023

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ The directories of the library repository are:

- `microchip_harmony` : Modules and project for Microchip MPLAB Harmony

- `unreal` : Unreal Engine integration module


## Files

Expand Down
9 changes: 8 additions & 1 deletion core/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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
# TODO: move coreapi_ex to new module

all: pubnub_crypto_unittest pbcc_crypto_unittest pubnub_grant_token_api_unittest pubnub_proxy_unittest pubnub_timer_list_unittest unittest
all: pubnub_crypto_unittest pubnub_subscribe_v2_unittest pbcc_crypto_unittest pubnub_grant_token_api_unittest pubnub_proxy_unittest pubnub_timer_list_unittest unittest

OS := $(shell uname)
# Coverage doesn't seem to work on MacOS for some reason, but, since
Expand Down Expand Up @@ -97,6 +97,13 @@ pubnub_crypto_unittest: $(PROJECT_SOURCEFILES) $(CRYPTO_SOURCEFILES) pubnub_cryp
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
# 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
#$(GCOVR) -r . --html --html-details -o coverage.html


Expand Down
13 changes: 13 additions & 0 deletions core/pbcc_subscribe_v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ enum pubnub_res pbcc_subscribe_v2_prep(struct pbcc_context* p,
}
#endif
PUBNUB_LOG_DEBUG("pbcc_subscribe_v2_prep. REQUEST =%s\n", p->http_buf);

return (rslt != PNR_OK) ? rslt : PNR_STARTED;
}

Expand Down Expand Up @@ -311,5 +312,17 @@ struct pubnub_v2_message pbcc_get_msg_v2(struct pbcc_context* p)
rslt.metadata.size = found.end - found.start;
}

if (jonmpOK == pbjson_get_object_value(&el, "i", &found)) {
rslt.publisher.ptr = (char*)found.start + 1;
rslt.publisher.size = found.end - found.start - 2;
}

if (jonmpOK == pbjson_get_object_value(&el, "f", &found)) {
rslt.flags = strtol(found.start, NULL, 0);
}

rslt.region = p->region;


return rslt;
}
2 changes: 2 additions & 0 deletions core/pubnub_subscribe_v2_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ struct pubnub_v2_message {
struct pubnub_char_mem_block metadata;
/** Indicates the message type: a signal, published, or something else */
enum pubnub_message_type message_type;
/** The message information about publisher */
struct pubnub_char_mem_block publisher;
};


Expand Down
105 changes: 105 additions & 0 deletions core/pubnub_subscribe_v2_unit_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/* -*- c-file-style:"stroustrup"; indent-tabs-mode: nil -*- */
#include "pubnub_memory_block.h"
#include <stdlib.h>
#if defined PUBNUB_USE_SUBSCRIBE_V2

#include "cgreen/assertions.h"
#include "cgreen/cgreen.h"
#include "cgreen/mocks.h"
#include "cgreen/constraint_syntax_helpers.h"

#include "pubnub_alloc.h"
#include "pubnub_grant_token_api.h"
#include "pubnub_pubsubapi.h"
#include "pubnub_internal.h"
#include "pubnub_internal_common.h"
#include "pubnub_assert.h"
#include "pubnub_log.h"
#include "pubnub_subscribe_v2_message.h"
#include "pubnub_subscribe_v2.h"
#include "test/pubnub_test_mocks.h"

static pubnub_t* pbp;

Describe(subscribe_v2);

BeforeEach(subscribe_v2) {
pubnub_setup_mocks(&pbp);
printf("B address=%p\n", pbp);

pubnub_origin_set(pbp, NULL);
pubnub_init(pbp, "pub_key", "sub_key");
pubnub_set_user_id(pbp, "test_id");
}

AfterEach(subscribe_v2) {
pubnub_cleanup_mocks(pbp);
}

void assert_char_mem_block(struct pubnub_char_mem_block block, char const* expected) {
char* str = malloc(block.size + 1);
memcpy((void*)str, block.ptr, block.size);

str[block.size] = '\0';

assert_that(str, is_equal_to_string(expected));

free((void*)str);
}

Ensure(subscribe_v2, should_parse_response_correctly) {
assert_that(pubnub_last_time_token(pbp), is_equal_to_string("0"));

assert_that(pubnub_auth_get(pbp), is_equal_to_string(NULL));
expect_have_dns_for_pubnub_origin_on_ctx(pbp);
expect_outgoing_with_url_on_ctx(pbp,
"/v2/subscribe/sub_key/my-channel/0?pnsdk=unit-test-0.1&tt=0&tr=0&uuid=test_id&heartbeat=270");
incoming("HTTP/1.1 200\r\nContent-Length: "
"44\r\n\r\n{\"t\":{\"t\":\"15628652479932717\",\"r\":4},\"m\":[]}",
NULL);

expect(pbntf_lost_socket, when(pb, is_equal_to(pbp)));
expect(pbntf_trans_outcome, when(pb, is_equal_to(pbp)));

assert_that(pubnub_subscribe_v2(pbp, "my-channel", pubnub_subscribe_v2_defopts()),
is_equal_to(PNR_OK));

assert_that(pubnub_last_http_code(pbp), is_equal_to(200));
assert_that(pubnub_last_time_token(pbp), is_equal_to_string("15628652479932717"));

expect(pbntf_enqueue_for_processing, when(pb, is_equal_to(pbp)), will_return(0));
expect(pbntf_got_socket, when(pb, is_equal_to(pbp)), will_return(0));

expect_outgoing_with_url_on_ctx(pbp,
"/v2/subscribe/sub_key/my-channel/0?pnsdk=unit-test-0.1&tt=15628652479932717&tr=4&uuid=test_id&heartbeat=270");
incoming("HTTP/1.1 220\r\nContent-Length: "
"183\r\n\r\n{\"t\":{\"t\":\"15628652479932717\",\"r\":4},\"m\":[{\"a\":\"1\",\"f\":514,\"i\":\"publisher_id\",\"s\":1,\"p\":{\"t\":\"15628652479933927\",\"r\":4},\"k\":\"demo\",\"c\":\"my-channel\",\"d\":\"mymessage\",\"b\":\"my-channel\"}]}",
NULL);

expect(pbntf_lost_socket, when(pb, is_equal_to(pbp)));
expect(pbntf_trans_outcome, when(pb, is_equal_to(pbp)));

assert_that(pubnub_subscribe_v2(pbp, "my-channel", pubnub_subscribe_v2_defopts()),
is_equal_to(PNR_OK));

struct pubnub_v2_message msg = pubnub_get_v2(pbp);

assert_char_mem_block(msg.tt, "15628652479933927");
assert_char_mem_block(msg.channel, "my-channel");
assert_char_mem_block(msg.payload, "\"mymessage\"");
assert_char_mem_block(msg.publisher, "publisher_id");

assert_that(msg.region, is_equal_to(4));
assert_that(msg.flags, is_equal_to(514));
assert_that(msg.message_type, is_equal_to(pbsbPublished));
}

#if 0
int main(int argc, char *argv[]) {
TestSuite *suite = create_test_suite();
add_test_with_context(suite, token_parsing);
run_test_suite(suite, create_text_reporter());
}
#endif // 0
#endif // defined PUBNUB_USE_SUBSCRIBE_V2

2 changes: 1 addition & 1 deletion core/pubnub_version_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#define INC_PUBNUB_VERSION_INTERNAL


#define PUBNUB_SDK_VERSION "4.2.2"
#define PUBNUB_SDK_VERSION "4.4.0"


#endif /* !defined INC_PUBNUB_VERSION_INTERNAL */
2 changes: 2 additions & 0 deletions core/samples/metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ static int printout_subscribe_v2_outcome(pubnub_t* pbp, enum pubnub_res res)
printf(" Metadata = '%.*s'\n", (int)msg.metadata.size, msg.metadata.ptr);
printf(" Payload = '%.*s'\n", (int)msg.payload.size, msg.payload.ptr);
printf(" MessageType= '%s'\n", pubnub_msg_type_to_str(msg.message_type));
printf(" Publisher = '%.*s'\n", (int)msg.publisher.size, msg.publisher.ptr);
printf(" Region = '%d'\n", msg.region);
}
return 0;
}
Expand Down
6 changes: 3 additions & 3 deletions core/test/pubnub_test_mocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ void pubnub_cleanup_mocks(pubnub_t* pbp)
free_m_msgs(m_string_msg_array);
}

void expect_have_dns_for_pubnub_origin_on(pubnub_t* pbp)
void expect_have_dns_for_pubnub_origin_on_ctx(pubnub_t* pbp)
{
expect(pbntf_enqueue_for_processing, when(pb, equals(pbp)), returns(0));
expect(pbpal_resolv_and_connect,
Expand All @@ -573,7 +573,7 @@ void expect_have_dns_for_pubnub_origin_on(pubnub_t* pbp)
expect(pbntf_got_socket, when(pb, equals(pbp)), returns(0));
}

void expect_outgoing_with_url_on(pubnub_t* pbp, char const* url)
void expect_outgoing_with_url_on_ctx(pubnub_t* pbp, char const* url)
{
expect(pbpal_send_str, when(s, streqs("GET ")), returns(0));
expect(pbpal_send_status, returns(0));
Expand All @@ -592,7 +592,7 @@ void expect_outgoing_with_url_on(pubnub_t* pbp, char const* url)
expect(pbntf_watch_in_events, when(pb, equals(pbp)), returns(0));
}

void expect_outgoing_with_url_no_params_on(pubnub_t* pbp, char const* url)
void expect_outgoing_with_url_no_params_on_ctx(pubnub_t* pbp, char const* url)
{
expect(pbpal_send_str, when(s, streqs("GET ")), returns(0));
expect(pbpal_send_status, returns(0));
Expand Down
6 changes: 3 additions & 3 deletions core/test/pubnub_test_mocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ void pubnub_setup_mocks(pubnub_t** pbp);

void pubnub_cleanup_mocks(pubnub_t* pbp);

void expect_have_dns_for_pubnub_origin_on(pubnub_t* pbp);
void expect_outgoing_with_url_no_params_on_ctx(pubnub_t* pbp, char const* url);

void expect_outgoing_with_url_on(pubnub_t* pbp, char const* url);
void expect_have_dns_for_pubnub_origin_on_ctx(pubnub_t* pbp);

void expect_outgoing_with_url_no_params_on(pubnub_t* pbp, char const* url);
void expect_outgoing_with_url_on_ctx(pubnub_t* pbp, char const* url);

#endif // INC_PUBNUB_TEST_MOCKS
1 change: 1 addition & 0 deletions cpp/pubnub_v2_message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class v2_message {
}
std::string payload() const { return std::string(d_.payload.ptr, d_.payload.size); }
std::string metadata() const { return std::string(d_.metadata.ptr, d_.metadata.size); }
std::string publisher() const { return std::string(d_.publisher.ptr, d_.publisher.size); }
pubnub_message_type message_type() const { return d_.message_type; }
/** Message structure is considered empty if there is no timetoken info(whose
existence is obligatory for any valid v2 message)
Expand Down
6 changes: 6 additions & 0 deletions unreal/PubNubModule/Private/PubNubModule.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright Epic Games, Inc. All Rights Reserved.

#include "PubNubModule.h"
#include "Modules/ModuleManager.h"

IMPLEMENT_MODULE(FDefaultModuleImpl, PubNubModule);
Loading

0 comments on commit 196c582

Please sign in to comment.