Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom message type support #199

Merged
merged 36 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
3869006
feat(message-type): add custom message type support
parfeon Nov 14, 2024
e58459c
feat(ipv6): add the ability to enforce IPv6 usage
parfeon Nov 19, 2024
386b05f
test(ssl): fix paths to the ssl in Makefile
parfeon Nov 20, 2024
b7c2b3a
tes(openssl): update paths in other makefiles
parfeon Nov 20, 2024
71e9383
test(debug): runner SSL path
parfeon Nov 20, 2024
b0d58f7
test(debug): runner SSL path
parfeon Nov 20, 2024
c610714
test(debug): list runner env variables
parfeon Nov 20, 2024
30b866b
test(debug): check whether openssl really installed
parfeon Nov 20, 2024
e17a9ea
test(debug): package config debug
parfeon Nov 20, 2024
17d4da1
test(debug): package config debug
parfeon Nov 20, 2024
406dca6
test(debug): package config debug
parfeon Nov 20, 2024
1c4edfa
test(debug): package config debug
parfeon Nov 20, 2024
4c97cb9
test(debug): package config debug
parfeon Nov 20, 2024
cd04ac4
test(debug): package config debug
parfeon Nov 20, 2024
91cba6f
test(debug): package config debug
parfeon Nov 20, 2024
72c3aa1
test(debug): package config debug
parfeon Nov 20, 2024
b93f638
test(debug): package config debug
parfeon Nov 20, 2024
716fcc1
test(openssl): detect on Darwin and hardcode paths in other case
parfeon Nov 20, 2024
47ff35d
test(debug): libcrypto includes
parfeon Nov 20, 2024
46f8b6d
test(debug): libcrypto includes
parfeon Nov 20, 2024
70eb196
test(debug): libcrypto includes
parfeon Nov 20, 2024
ee32802
test(libcrypto): fix paths
parfeon Nov 20, 2024
1663da6
test(debug): printout evp to check types
parfeon Nov 20, 2024
550ea81
test(debug): debug libcrypto load issue
parfeon Nov 20, 2024
e05a062
test(debug): debug libcrypto load issue
parfeon Nov 20, 2024
4ce9676
test(debug): debug libcrypto load issue
parfeon Nov 20, 2024
b5a9345
test(debug): debug libcrypto load issue
parfeon Nov 20, 2024
83eb8ee
feat(ipv6): add connectivity setter
parfeon Nov 24, 2024
1cb5745
fix(subscribe): fix subscribe v2 decrypt issue
parfeon Nov 25, 2024
dc6826f
build(samples): update publish via post sample to support IPv6 connec…
parfeon Nov 25, 2024
31fb49c
build(sample): fix missing compilation flags
parfeon Nov 25, 2024
9dc1252
test(docker): restore original Dockerfile
parfeon Nov 25, 2024
e5f1027
test(sample): change condition in publish via post sample
parfeon Nov 25, 2024
f293253
test(sample): add IPv6 flags for callback based sample
parfeon Nov 25, 2024
666f8d1
PubNub SDK v4.15.0 release.
pubnub-release-bot Nov 25, 2024
0557529
doc(changelog): fix changelog entries
parfeon Nov 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -e

echo "::group::Run unit tests ('$1' $CC / $CXX)"
cd "$GITHUB_WORKSPACE/core"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/composite/unit-test-framework/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ runs:
steps:
- name: Build and Cache Unit Test framework ('${{ inputs.os }}' ${{ inputs.compilers }})
id: unit-test-framework
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
cgreen
Expand All @@ -27,7 +27,7 @@ runs:
${{ inputs.os }}-cgreen-${{ inputs.version }}-
- name: Checkout Unit Test framework
if: steps.unit-test-framework.outputs.cache-hit != 'true'
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: cgreen-devs/cgreen
ref: ${{ matrix.cgreen }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ jobs:
# group: organization/macos-gh
steps:
- name: Checkout project
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
token: ${{ secrets.GH_TOKEN }}
- name: Checkout actions
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: pubnub/client-engineering-deployment-tools
ref: v1
Expand Down
17 changes: 16 additions & 1 deletion core/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pubnub_timer_list_unittest: pubnub_timer_list.c pubnub_timer_list_unit_test.c
#$(GCOVR) -r . --html --html-details -o coverage.html


PROXY_PROJECT_SOURCEFILES = pubnub_proxy_core.c pubnub_proxy.c pbhttp_digest.c pbntlm_core.c pbntlm_packer_std.c pubnub_generate_uuid_v4_random_std.c ../lib/pubnub_parse_ipv4_addr.c ../lib/pubnub_parse_ipv6_addr.c ../lib/md5/md5.c
PROXY_PROJECT_SOURCEFILES = pubnub_proxy_core.c pubnub_proxy.c pbhttp_digest.c pbntlm_core.c pbntlm_packer_std.c pubnub_generate_uuid_v4_random_std.c pubnub_dns_servers.c ../lib/pubnub_parse_ipv4_addr.c ../lib/pubnub_parse_ipv6_addr.c ../lib/md5/md5.c

pubnub_proxy_unittest: $(PROJECT_SOURCEFILES) $(PROXY_PROJECT_SOURCEFILES) pubnub_proxy_unit_test.c
gcc -o pubnub_proxy_unit_test.so -shared $(CFLAGS) $(LDFLAGS) -D PUBNUB_CALLBACK_API -D PUBNUB_PROXY_API=1 -Wall $(COVERAGE_FLAGS) -fPIC $(PROJECT_SOURCEFILES) $(PROXY_PROJECT_SOURCEFILES) pubnub_proxy_unit_test.c -lcgreen -lm
Expand All @@ -87,6 +87,21 @@ CRYPTO_INCLUDES += -I ../openssl/.
CRYPTO_LIBS += -lssl -lcrypto
CRYPTO_SOURCEFILES += pubnub_crypto.c pbcc_crypto.c pbcc_crypto_aes_cbc.c pbcc_crypto_legacy.c ../openssl/pbaes256.c

ifeq ($(shell uname),Darwin)
CRYPTO_CFLAGS := $(shell pkg-config --cflags openssl 2>/dev/null)
CRYPTO_LIBS := $(shell pkg-config --libs openssl 2>/dev/null)

ifeq ($(CRYPTO_CFLAGS),)
CRYPTO_CFLAGS := -I/usr/local/opt/openssl/include
endif
ifeq ($(CRYPTO_LIBS),)
CRYPTO_LIBS := -L/usr/local/opt/openssl/lib -lssl -lcrypto
endif

CRYPTO_INCLUDES += $(CRYPTO_CFLAGS)
CRYPTO_LIBS += $(CRYPTO_LIBS)
endif

pbcc_crypto_unittest: $(PROJECT_SOURCEFILES) $(CRYPTO_SOURCEFILES) pbcc_crypto_unit_tests.c
gcc -o pbcc_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 pbcc_crypto_unit_tests.c -lcgreen -lm
# gcc -o pubnub_core_unit_testo $(CFLAGS) -Wall $(COVERAGE_FLAGS) $(PROJECT_SOURCEFILES) pbcc_crypto_unit_tests.c -lcgreen -lm
Expand Down
4 changes: 3 additions & 1 deletion core/pbcc_fetch_history.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ enum pubnub_res pbcc_fetch_history_prep(struct pbcc_context* pb,
const char* channel,
unsigned int max_per_channel,
enum pubnub_tribool include_meta,
enum pubnub_tribool include_custom_message_type,
enum pubnub_tribool include_message_type,
enum pubnub_tribool include_user_id,
enum pubnub_tribool include_message_actions,
Expand Down Expand Up @@ -59,7 +60,8 @@ enum pubnub_res pbcc_fetch_history_prep(struct pbcc_context* pb,
if (max_per_channel) { ADD_URL_PARAM(qparam, max, max_per_ch_cnt_buf); }

if (include_meta != pbccNotSet) { ADD_URL_PARAM(qparam, include_meta, include_meta == pbccTrue ? "true" : "false"); }
if (include_message_type != pbccNotSet) { ADD_URL_PARAM(qparam, include_message_type, include_meta == pbccTrue ? "true" : "false"); }
if (include_custom_message_type != pbccNotSet) { ADD_URL_PARAM(qparam, include_custom_message_type, include_custom_message_type == pbccTrue ? "true" : "false"); }
if (include_message_type != pbccNotSet) { ADD_URL_PARAM(qparam, include_message_type, include_message_type == pbccTrue ? "true" : "false"); }
if (include_user_id != pbccNotSet) { ADD_URL_PARAM(qparam, include_uuid, include_user_id == pbccTrue ? "true" : "false"); }
#if PUBNUB_CRYPTO_API
if (pb->secret_key == NULL) { ADD_URL_AUTH_PARAM(pb, qparam, auth); }
Expand Down
1 change: 1 addition & 0 deletions core/pbcc_fetch_history.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ enum pubnub_res pbcc_fetch_history_prep(struct pbcc_context* pb,
const char* channel,
unsigned int max_per_channel,
enum pubnub_tribool include_meta,
enum pubnub_tribool include_custom_message_type,
enum pubnub_tribool include_message_type,
enum pubnub_tribool include_user_id,
enum pubnub_tribool include_message_actions,
Expand Down
7 changes: 6 additions & 1 deletion core/pbcc_subscribe_v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
enum pubnub_res pbcc_subscribe_v2_prep(struct pbcc_context* p,
char const* channel,
char const* channel_group,
unsigned* heartbeat,
const unsigned* heartbeat,
char const* filter_expr)
{
char region_str[20];
Expand Down Expand Up @@ -303,6 +303,11 @@ struct pubnub_v2_message pbcc_get_msg_v2(struct pbcc_context* p)
rslt.message_type = pbsbPublished;
}

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

jpresult = pbjson_get_object_value(&el, "p", &found);
if (jonmpOK == jpresult) {
struct pbjson_elem titel;
Expand Down
2 changes: 1 addition & 1 deletion core/pbcc_subscribe_v2.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct pbcc_context;
enum pubnub_res pbcc_subscribe_v2_prep(struct pbcc_context* p,
char const* channel,
char const* channel_group,
unsigned* heartbeat,
const unsigned* heartbeat,
char const* filter_expr);


Expand Down
14 changes: 11 additions & 3 deletions core/pubnub_ccore_pubsub.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ enum pubnub_res pbcc_append_url_param_encoded(struct pbcc_context* pb,
enum pubnub_res pbcc_publish_prep(struct pbcc_context* pb,
const char* channel,
const char* message,
const char* custom_message_type,
bool store_in_history,
bool norep,
char const* meta,
Expand Down Expand Up @@ -596,7 +597,7 @@ enum pubnub_res pbcc_publish_prep(struct pbcc_context* pb,
URL_PARAMS_INIT(qparam, PUBNUB_MAX_URL_PARAMS);
if (uname) { ADD_URL_PARAM(qparam, pnsdk, uname); }
ADD_URL_PARAM(qparam, uuid, user_id);
if (ttl != SIZE_MAX) { ADD_URL_PARAM_SIZET(qparam, ttl, ttl); }
if (ttl != 0 && ttl != SIZE_MAX) { ADD_URL_PARAM_SIZET(qparam, ttl, ttl); }
#if PUBNUB_CRYPTO_API
if (pb->secret_key == NULL) { ADD_URL_AUTH_PARAM(pb, qparam, auth); }
ADD_TS_TO_URL_PARAM();
Expand All @@ -606,6 +607,9 @@ enum pubnub_res pbcc_publish_prep(struct pbcc_context* pb,
if (!store_in_history) { ADD_URL_PARAM(qparam, store, "0"); }
if (norep) { ADD_URL_PARAM(qparam, norep, "true"); }
if (meta) { ADD_URL_PARAM(qparam, meta, meta); }
if (custom_message_type) {
ADD_URL_PARAM(qparam, custom_message_type, custom_message_type);
}

#if PUBNUB_CRYPTO_API
SORT_URL_PARAMETERS(qparam);
Expand Down Expand Up @@ -667,7 +671,8 @@ enum pubnub_res pbcc_sign_url(struct pbcc_context* pc, const char* msg, enum pub

enum pubnub_res pbcc_signal_prep(struct pbcc_context* pb,
const char* channel,
const char* message)
const char* message,
const char* custom_message_type)
{
enum pubnub_res rslt = PNR_OK;
char const* const uname = pubnub_uname();
Expand All @@ -689,6 +694,9 @@ enum pubnub_res pbcc_signal_prep(struct pbcc_context* pb,
URL_PARAMS_INIT(qparam, PUBNUB_MAX_URL_PARAMS);
if (uname) { ADD_URL_PARAM(qparam, pnsdk, uname); }
if (user_id) { ADD_URL_PARAM(qparam, uuid, user_id); }
if (custom_message_type) {
ADD_URL_PARAM(qparam, custom_message_type, custom_message_type);
}
#if PUBNUB_CRYPTO_API
if (pb->secret_key == NULL) { ADD_URL_AUTH_PARAM(pb, qparam, auth); }
ADD_TS_TO_URL_PARAM();
Expand Down Expand Up @@ -716,7 +724,7 @@ enum pubnub_res pbcc_signal_prep(struct pbcc_context* pb,
enum pubnub_res pbcc_subscribe_prep(struct pbcc_context* p,
char const* channel,
char const* channel_group,
unsigned* heartbeat)
const unsigned* heartbeat)
{
char const* user_id = pbcc_user_id_get(p);
char const* const uname = pubnub_uname();
Expand Down
6 changes: 4 additions & 2 deletions core/pubnub_ccore_pubsub.h
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ void pbcc_via_post_headers(struct pbcc_context* p, char* header, size_t max_leng
enum pubnub_res pbcc_publish_prep(struct pbcc_context* pb,
const char* channel,
const char* message,
const char* custom_message_type,
bool store_in_history,
bool norep,
char const* meta,
Expand All @@ -488,15 +489,16 @@ enum pubnub_res pbcc_publish_prep(struct pbcc_context* pb,
*/
enum pubnub_res pbcc_signal_prep(struct pbcc_context* pb,
const char* channel,
const char* message);
const char* message,
const char* custom_message_type);

/** Prepares the Subscribe operation (transaction), mostly by
formatting the URI of the HTTP request.
*/
enum pubnub_res pbcc_subscribe_prep(struct pbcc_context* p,
char const* channel,
char const* channel_group,
unsigned* heartbeat);
const unsigned* heartbeat);


/** Split @p buf string containing a JSON array (with arbitrary
Expand Down
48 changes: 42 additions & 6 deletions core/pubnub_coreapi_ex.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@
struct pubnub_publish_options pubnub_publish_defopts(void)
{
struct pubnub_publish_options result;
result.store = true;
result.cipher_key = NULL;
result.replicate = true;
result.meta = NULL;
result.method = pubnubSendViaGET;
result.ttl = SIZE_MAX;
result.store = true;
result.cipher_key = NULL;
result.replicate = true;
result.meta = NULL;
result.method = pubnubSendViaGET;
result.ttl = 0;
result.custom_message_type = NULL;
return result;
}

Expand Down Expand Up @@ -85,6 +86,7 @@ enum pubnub_res pubnub_publish_ex(pubnub_t* pb,
rslt = pbcc_publish_prep(&pb->core,
channel,
message,
opts.custom_message_type,
opts.store,
!opts.replicate,
opts.meta,
Expand All @@ -102,6 +104,40 @@ enum pubnub_res pubnub_publish_ex(pubnub_t* pb,
return rslt;
}

struct pubnub_signal_options pubnub_signal_defopts(void)
{
struct pubnub_signal_options result;
result.custom_message_type = NULL;
return result;
}

enum pubnub_res pubnub_signal_ex(
pubnub_t* pb,
const char* channel,
const char* message,
struct pubnub_signal_options opts)
{
enum pubnub_res rslt;

PUBNUB_ASSERT(pb_valid_ctx_ptr(pb));

pubnub_mutex_lock(pb->monitor);
if (!pbnc_can_start_transaction(pb)) {
pubnub_mutex_unlock(pb->monitor);
return PNR_IN_PROGRESS;
}

rslt = pbcc_signal_prep(&pb->core, channel, message, opts.custom_message_type);
if (PNR_STARTED == rslt) {
pb->trans = PBTT_SIGNAL;
pb->core.last_result = PNR_STARTED;
pbnc_fsm(pb);
rslt = pb->core.last_result;
}
pubnub_mutex_unlock(pb->monitor);

return rslt;
}

struct pubnub_subscribe_options pubnub_subscribe_defopts(void)
{
Expand Down
45 changes: 43 additions & 2 deletions core/pubnub_coreapi_ex.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,17 @@ struct pubnub_publish_options {
API.
*/
size_t ttl;
/** User-specified message type.
Important: String limited by **3**-**50** case-sensitive alphanumeric
characters with only `-` and `_` special characters allowed.
*/
char const* custom_message_type;
};

/** This returns the default options for publish V1 transactions.
Will set `store = true`, `cipher_key = NULL`, `replicate = true`,
`meta = NULL` and `method = pubnubPublishViaGet`
`meta = NULL`, `method = pubnubPublishViaGet`, `ttl=0`, and
`custom_message_type=NULL`.
*/
PUBNUB_EXTERN struct pubnub_publish_options pubnub_publish_defopts(void);

Expand All @@ -85,7 +91,7 @@ PUBNUB_EXTERN struct pubnub_publish_options pubnub_publish_defopts(void);
@param p The Pubnub context. Can't be NULL.
@param channel The string with the channel name to publish to. Can't be
NULL.
@param opt Publish V1 options
@param opts Publish V1 options
@return #PNR_STARTED on success, an error otherwise
*/
PUBNUB_EXTERN enum pubnub_res pubnub_publish_ex(pubnub_t* p,
Expand All @@ -94,6 +100,41 @@ PUBNUB_EXTERN enum pubnub_res pubnub_publish_ex(pubnub_t* p,
struct pubnub_publish_options opts);


/** Options for "extended" signal V1. */
struct pubnub_signal_options {
/** User-specified message type.
Important: String limited by **3**-**50** case-sensitive alphanumeric
characters with only `-` and `_` special characters allowed.
*/
char const* custom_message_type;
};

/** This returns the default options for signal V1 transactions.
Will set `custom_message_type=NULL`. */
PUBNUB_EXTERN struct pubnub_signal_options pubnub_signal_defopts(void);

/** The extended signal V1. Basically the same as pubnub_signal(),
but with added optional parameters in @p opts.

Basic usage:

struct pubnub_signal_options opt = pubnub_signal_defopts();
opt.custom_message_type = "test-message-type";
pbresult = pubnub_signal_ex(pn, "my_channel", "status:active", opt);

@param pb The pubnub context. Can't be NULL
@param channel The string with the channel to signal to.
@param message The signal message to send, expected to be in JSON format
@param opts Signal V1 options
@return #PNR_STARTED on success, an error otherwise
*/
PUBNUB_EXTERN enum pubnub_res pubnub_signal_ex(
pubnub_t* pb,
const char* channel,
const char* message,
struct pubnub_signal_options opts);


/** Options for "extended" subscribe. */
struct pubnub_subscribe_options {
/** Channel group (a comma-delimited list of channel group names).
Expand Down
15 changes: 14 additions & 1 deletion core/pubnub_dns_servers.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ void pubnub_dns_servers_deinit(void)
pubnub_mutex_destroy(m_lock);
}


int pubnub_dns_set_primary_server_ipv4(struct pubnub_ipv4_address ipv4_address)
{
uint8_t* ipv4 = ipv4_address.ipv4;
Expand Down Expand Up @@ -166,6 +165,20 @@ int pubnub_get_dns_secondary_server_ipv4(struct pubnub_ipv4_address* o_ipv4)
}

#if PUBNUB_USE_IPV6
void pubnub_set_ipv4_connectivity(pubnub_t *p)
{
pubnub_mutex_lock(p->monitor);
p->options.ipv6_connectivity = false;
pubnub_mutex_unlock(p->monitor);
}

void pubnub_set_ipv6_connectivity(pubnub_t *p)
{
pubnub_mutex_lock(p->monitor);
p->options.ipv6_connectivity = true;
pubnub_mutex_unlock(p->monitor);
}

int pubnub_dns_set_primary_server_ipv6(struct pubnub_ipv6_address ipv6_address)
{
uint8_t* ipv6 = ipv6_address.ipv6;
Expand Down
9 changes: 9 additions & 0 deletions core/pubnub_dns_servers.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#if !defined INC_PUBNUB_DNS_SERVERS
#define INC_PUBNUB_DNS_SERVERS

#include "core/pubnub_api_types.h"
#include <stdint.h>

/** IPv4 Address, in binary format.
Expand All @@ -19,6 +20,14 @@ struct pubnub_ipv6_address {
uint8_t ipv6[16];
};

/** IPv4 connectivity type for @p.
Use IPv4 addresses to establish connection with remote origin. */
void pubnub_set_ipv4_connectivity(pubnub_t *p);

/** IPv6 connectivity type for @p.
Use IPv6 addresses to establish connection with remote origin. */
void pubnub_set_ipv6_connectivity(pubnub_t *p);

/* primary, secondary(ipv4, ipv6) and default dns server */
#define PUBNUB_MAX_DNS_SERVERS_MASK 0x10
#else
Expand Down
Loading
Loading