Skip to content

Commit

Permalink
build(makefiles): restructure Makefiles
Browse files Browse the repository at this point in the history
Restructure Makefiles (for `nmake` and `make`) to reduce amount of repeated declarations.
  • Loading branch information
parfeon committed Dec 9, 2024
1 parent 3ad9249 commit 6db8881
Show file tree
Hide file tree
Showing 31 changed files with 2,508 additions and 1,501 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ num_option(USE_GZIP_COMPRESSION "Use gzip compression" ON)
num_option(RECEIVE_GZIP_RESPONSE "Use gzip decompression" ON)
num_option(USE_RETRY_CONFIGURATION "Use requests retry" OFF)
num_option(USE_SUBSCRIBE_V2 "Use subscribe v2" ON)
num_option(USE_SUBSCRIBE_EVENT_ENGINE "Use Subscribe Event Engine" OFF)
num_option(USE_SUBSCRIBE_EVENT_ENGINE "Use Subscribe Event Engine [USE_SUBSCRIBE_V2=ON needed]" OFF)
num_option(USE_ADVANCED_HISTORY "Use advanced history" ON)
num_option(USE_OBJECTS_API "Use objects API" ON)
num_option(USE_AUTO_HEARTBEAT "Use auto heartbeat" ON)
num_option(USE_ACTIONS_API "Use actions API" ON)
num_option(USE_REVOKE_TOKEN_API "Use revoke token API" OFF)
num_option(USE_GRANT_TOKEN_API "Use grant token API" OFF)
num_option(USE_REVOKE_TOKEN_API "Use revoke token API [OPENSSL ONLY]" OFF)
num_option(USE_GRANT_TOKEN_API "Use grant token API [OPENSSL ONLY]" OFF)
num_option(USE_FETCH_HISTORY "Use fetch history" ON)
num_option(USE_CRYPTO_API "Use crypto API [OPENSSL ONLY]" OFF)
num_option(USE_CALLBACK_API "Use callback API [CALLBACK=ON SYNC=OFF]" ${DEFAULT_USE_CALLBACK_API})
num_option(USE_IPV6 "Use IPv6 [CALLBACK=ON]" ${DEFAULT_USE_CALLBACK_API})
num_option(USE_IPV6 "Use IPv6" ON)
num_option(USE_SET_DNS_SERVERS "Use set DNS servers [CALLBACK=ON]" ${DEFAULT_USE_CALLBACK_API})
num_option(USE_EXTERN_API "Use extern C API [WITH_CPP=ON]" ON)
num_option(USE_LEGACY_CRYPTO_RANDOM_IV "Use random IV for legacy crypto module [OpenSSL only]" ON)
Expand Down
122 changes: 69 additions & 53 deletions core/pubnub_dns_servers.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
#if PUBNUB_SET_DNS_SERVERS
#include "core/pubnub_dns_servers.h"
#include "lib/pubnub_parse_ipv4_addr.h"
#if PUBNUB_USE_IPV6
#include "lib/pubnub_parse_ipv6_addr.h"
#endif
#else
#error PUBNUB_SET_DNS_SERVERS must be defined and set to 1 before compiling this file
#endif

#if PUBNUB_USE_IPV6
#include "lib/pubnub_parse_ipv6_addr.h"
#endif

#include "core/pubnub_assert.h"
#include "core/pubnub_log.h"
Expand All @@ -20,11 +20,15 @@


pubnub_mutex_static_decl_and_init(m_lock);
static struct pubnub_ipv4_address m_primary_dns_server_ipv4 pubnub_guarded_by(m_lock);
static struct pubnub_ipv4_address m_secondary_dns_server_ipv4 pubnub_guarded_by(m_lock);
static struct pubnub_ipv4_address m_primary_dns_server_ipv4
pubnub_guarded_by(m_lock);
static struct pubnub_ipv4_address m_secondary_dns_server_ipv4
pubnub_guarded_by(m_lock);
#if PUBNUB_USE_IPV6
static struct pubnub_ipv6_address m_primary_dns_server_ipv6 pubnub_guarded_by(m_lock);
static struct pubnub_ipv6_address m_secondary_dns_server_ipv6 pubnub_guarded_by(m_lock);
static struct pubnub_ipv6_address m_primary_dns_server_ipv6
pubnub_guarded_by(m_lock);
static struct pubnub_ipv6_address m_secondary_dns_server_ipv6
pubnub_guarded_by(m_lock);
#endif /* PUBNUB_USE_IPV6 */


Expand Down Expand Up @@ -69,7 +73,8 @@ int pubnub_dns_set_primary_server_ipv4_str(char const* ipv4_str)
}


int pubnub_dns_set_secondary_server_ipv4(struct pubnub_ipv4_address ipv4_address)
int pubnub_dns_set_secondary_server_ipv4(
struct pubnub_ipv4_address ipv4_address)
{
uint8_t* ipv4 = ipv4_address.ipv4;

Expand All @@ -94,7 +99,8 @@ int pubnub_dns_set_secondary_server_ipv4_str(char const* ipv4_str)
int ret;

PUBNUB_ASSERT_OPT(ipv4_str != NULL);
PUBNUB_LOG_TRACE("pubnub_dns_set_secondary_server_ipv4_str(%s)\n", ipv4_str);
PUBNUB_LOG_TRACE("pubnub_dns_set_secondary_server_ipv4_str(%s)\n",
ipv4_str);

pubnub_mutex_init_static(m_lock);
pubnub_mutex_lock(m_lock);
Expand Down Expand Up @@ -169,15 +175,16 @@ int pubnub_dns_set_primary_server_ipv6(struct pubnub_ipv6_address ipv6_address)
{
uint8_t* ipv6 = ipv6_address.ipv6;

PUBNUB_LOG_TRACE("pubnub_dns_set_primary_server_ipv6(%u:%u:%u:%u:%u:%u:%u:%u).\n",
ipv6[0]*256 + ipv6[1],
ipv6[2]*256 + ipv6[3],
ipv6[4]*256 + ipv6[5],
ipv6[6]*256 + ipv6[7],
ipv6[8]*256 + ipv6[9],
ipv6[10]*256 + ipv6[11],
ipv6[12]*256 + ipv6[13],
ipv6[14]*256 + ipv6[15]);
PUBNUB_LOG_TRACE(
"pubnub_dns_set_primary_server_ipv6(%u:%u:%u:%u:%u:%u:%u:%u).\n",
ipv6[0]*256 + ipv6[1],
ipv6[2]*256 + ipv6[3],
ipv6[4]*256 + ipv6[5],
ipv6[6]*256 + ipv6[7],
ipv6[8]*256 + ipv6[9],
ipv6[10]*256 + ipv6[11],
ipv6[12]*256 + ipv6[13],
ipv6[14]*256 + ipv6[15]);

pubnub_mutex_init_static(m_lock);
pubnub_mutex_lock(m_lock);
Expand Down Expand Up @@ -205,19 +212,21 @@ int pubnub_dns_set_primary_server_ipv6_str(char const* ipv6_str)
}


int pubnub_dns_set_secondary_server_ipv6(struct pubnub_ipv6_address ipv6_address)
int pubnub_dns_set_secondary_server_ipv6(
struct pubnub_ipv6_address ipv6_address)
{
uint8_t* ipv6 = ipv6_address.ipv6;

PUBNUB_LOG_TRACE("pubnub_dns_set_secondary_server_ipv6(%u:%u:%u:%u:%u:%u:%u:%u).\n",
ipv6[0]*256 + ipv6[1],
ipv6[2]*256 + ipv6[3],
ipv6[4]*256 + ipv6[5],
ipv6[6]*256 + ipv6[7],
ipv6[8]*256 + ipv6[9],
ipv6[10]*256 + ipv6[11],
ipv6[12]*256 + ipv6[13],
ipv6[14]*256 + ipv6[15]);
PUBNUB_LOG_TRACE(
"pubnub_dns_set_secondary_server_ipv6(%u:%u:%u:%u:%u:%u:%u:%u).\n",
ipv6[0]*256 + ipv6[1],
ipv6[2]*256 + ipv6[3],
ipv6[4]*256 + ipv6[5],
ipv6[6]*256 + ipv6[7],
ipv6[8]*256 + ipv6[9],
ipv6[10]*256 + ipv6[11],
ipv6[12]*256 + ipv6[13],
ipv6[14]*256 + ipv6[15]);

pubnub_mutex_init_static(m_lock);
pubnub_mutex_lock(m_lock);
Expand All @@ -234,7 +243,8 @@ int pubnub_dns_set_secondary_server_ipv6_str(char const* ipv6_str)
int ret;

PUBNUB_ASSERT_OPT(ipv6_str != NULL);
PUBNUB_LOG_TRACE("pubnub_dns_set_secondary_server_ipv6_str(%s)\n", ipv6_str);
PUBNUB_LOG_TRACE("pubnub_dns_set_secondary_server_ipv6_str(%s)\n",
ipv6_str);

pubnub_mutex_init_static(m_lock);
pubnub_mutex_lock(m_lock);
Expand All @@ -249,24 +259,27 @@ int pubnub_get_dns_primary_server_ipv6(struct pubnub_ipv6_address* o_ipv6)
{
int ret;
const uint8_t* ipv6 = m_primary_dns_server_ipv6.ipv6;
uint8_t zero[sizeof m_primary_dns_server_ipv6.ipv6] = {0};
uint8_t zero[sizeof m_primary_dns_server_ipv6.ipv6] = { 0 };

PUBNUB_ASSERT_OPT(o_ipv6 != NULL);

pubnub_mutex_init_static(m_lock);
pubnub_mutex_lock(m_lock);

PUBNUB_LOG_TRACE("pubnub_dns_get_primary_server_ipv6(%u:%u:%u:%u:%u:%u:%u:%u).\n",
ipv6[0]*256 + ipv6[1],
ipv6[2]*256 + ipv6[3],
ipv6[4]*256 + ipv6[5],
ipv6[6]*256 + ipv6[7],
ipv6[8]*256 + ipv6[9],
ipv6[10]*256 + ipv6[11],
ipv6[12]*256 + ipv6[13],
ipv6[14]*256 + ipv6[15]);

if (memcmp(m_primary_dns_server_ipv6.ipv6, zero, sizeof m_primary_dns_server_ipv6.ipv6)
PUBNUB_LOG_TRACE(
"pubnub_dns_get_primary_server_ipv6(%u:%u:%u:%u:%u:%u:%u:%u).\n",
ipv6[0]*256 + ipv6[1],
ipv6[2]*256 + ipv6[3],
ipv6[4]*256 + ipv6[5],
ipv6[6]*256 + ipv6[7],
ipv6[8]*256 + ipv6[9],
ipv6[10]*256 + ipv6[11],
ipv6[12]*256 + ipv6[13],
ipv6[14]*256 + ipv6[15]);

if (memcmp(m_primary_dns_server_ipv6.ipv6,
zero,
sizeof m_primary_dns_server_ipv6.ipv6)
== 0) {
ret = -1;
}
Expand All @@ -285,24 +298,27 @@ int pubnub_get_dns_secondary_server_ipv6(struct pubnub_ipv6_address* o_ipv6)
{
int ret;
const uint8_t* ipv6 = m_secondary_dns_server_ipv6.ipv6;
uint8_t zero[sizeof m_secondary_dns_server_ipv6.ipv6] = {0};
uint8_t zero[sizeof m_secondary_dns_server_ipv6.ipv6] = { 0 };

PUBNUB_ASSERT_OPT(o_ipv6 != NULL);

pubnub_mutex_init_static(m_lock);
pubnub_mutex_lock(m_lock);

PUBNUB_LOG_TRACE("pubnub_dns_get_secondary_server_ipv6(%u:%u:%u:%u:%u:%u:%u:%u).\n",
ipv6[0]*256 + ipv6[1],
ipv6[2]*256 + ipv6[3],
ipv6[4]*256 + ipv6[5],
ipv6[6]*256 + ipv6[7],
ipv6[8]*256 + ipv6[9],
ipv6[10]*256 + ipv6[11],
ipv6[12]*256 + ipv6[13],
ipv6[14]*256 + ipv6[15]);

if (memcmp(m_secondary_dns_server_ipv6.ipv6, zero, sizeof m_secondary_dns_server_ipv6.ipv6)
PUBNUB_LOG_TRACE(
"pubnub_dns_get_secondary_server_ipv6(%u:%u:%u:%u:%u:%u:%u:%u).\n",
ipv6[0]*256 + ipv6[1],
ipv6[2]*256 + ipv6[3],
ipv6[4]*256 + ipv6[5],
ipv6[6]*256 + ipv6[7],
ipv6[8]*256 + ipv6[9],
ipv6[10]*256 + ipv6[11],
ipv6[12]*256 + ipv6[13],
ipv6[14]*256 + ipv6[15]);

if (memcmp(m_secondary_dns_server_ipv6.ipv6,
zero,
sizeof m_secondary_dns_server_ipv6.ipv6)
== 0) {
ret = -1;
}
Expand Down
11 changes: 6 additions & 5 deletions core/pubnub_fetch_history.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
#include "lib/pb_extern.h"

/** Options for fetch history. */
struct pubnub_fetch_history_options {
struct pubnub_fetch_history_options
{
/** The maximum number of messages to return per channel if multiple channels provided.
* Has to be between 1 and 25 messages. Default is 25.
* If single channel is provided, maximum 100 messages. Default is 100.
Expand Down Expand Up @@ -50,7 +51,7 @@ struct pubnub_fetch_history_options {
* false.
*/
bool include_user_id;
/** If true to recieve message actions with each history
/** If true to receive message actions with each history
* message. If false, no message actions per message. Defaults to
* false.
*/
Expand Down Expand Up @@ -83,9 +84,9 @@ PUBNUB_EXTERN struct pubnub_fetch_history_options pubnub_fetch_history_defopts(v
@param opt Options for this fetch history transaction
@return #PNR_STARTED on success, an error otherwise
*/
PUBNUB_EXTERN enum pubnub_res pubnub_fetch_history(pubnub_t* pb,
char const* channel,
struct pubnub_fetch_history_options opt);
PUBNUB_EXTERN enum pubnub_res pubnub_fetch_history(pubnub_t* pb,
char const* channel,
struct pubnub_fetch_history_options opt);

PUBNUB_EXTERN pubnub_chamebl_t pubnub_get_fetch_history(pubnub_t* pb);

Expand Down
1 change: 1 addition & 0 deletions core/samples/pubnub_fetch_history_sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ int main(int argc, char* argv[])
struct pubnub_fetch_history_options opt = pubnub_fetch_history_defopts();
opt.include_custom_message_type = true;
opt.include_message_type = true;
opt.include_user_id = true;
opt.include_meta = true;
res = pubnub_fetch_history(pbp, string_channels, opt);
if (res == PNR_STARTED) {
Expand Down
Loading

0 comments on commit 6db8881

Please sign in to comment.