-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathpubnub_ccore.c
662 lines (558 loc) · 20.9 KB
/
pubnub_ccore.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
/* -*- c-file-style:"stroustrup"; indent-tabs-mode: nil -*- */
#include "pubnub_internal.h"
#include "pubnub_ccore.h"
#include "pubnub_ccore_pubsub.h"
#include "pubnub_version.h"
#include "pubnub_assert.h"
#include "pubnub_json_parse.h"
#include "pubnub_log.h"
#include "pubnub_memory_block.h"
#include <stdio.h>
static enum pubnub_res simple_parse_response(struct pbcc_context* p)
{
struct pbjson_elem el;
char* reply = p->http_reply;
int replylen = p->http_buf_len;
if (replylen < 2) {
return PNR_FORMAT_ERROR;
}
el.start = reply;
el.end = reply + replylen;
if (pbjson_value_for_field_found(&el, "status", "403")) {
PUBNUB_LOG_ERROR("simple_parse_response(pbcc=%p) - AccessDenied: "
"response from server - response='%s'\n",
p,
reply);
return PNR_ACCESS_DENIED;
}
if ((reply[0] != '[') || (reply[replylen - 1] != ']')) {
return PNR_FORMAT_ERROR;
}
p->chan_ofs = p->chan_end = 0;
p->msg_ofs = 1;
p->msg_end = replylen - 1;
reply[replylen - 1] = '\0';
return pbcc_split_array(reply + p->msg_ofs) ? PNR_OK : PNR_FORMAT_ERROR;
}
enum pubnub_res pbcc_parse_time_response(struct pbcc_context* p)
{
return simple_parse_response(p);
}
enum pubnub_res pbcc_parse_history_response(struct pbcc_context* p)
{
return simple_parse_response(p);
}
enum pubnub_res pbcc_parse_presence_response(struct pbcc_context* p)
{
struct pbjson_elem el;
char* reply = p->http_reply;
int replylen = p->http_buf_len;
if (replylen < 2) {
return PNR_FORMAT_ERROR;
}
el.start = reply;
el.end = reply + replylen;
if (pbjson_value_for_field_found(&el, "status", "403")) {
PUBNUB_LOG_ERROR(
"pbcc_parse_presence_response(pbcc=%p) - AccessDenied: "
"response from server - response='%s'\n",
p,
reply);
return PNR_ACCESS_DENIED;
}
if ((reply[0] != '{') || (reply[replylen - 1] != '}')) {
return PNR_FORMAT_ERROR;
}
p->chan_ofs = p->chan_end = 0;
p->msg_ofs = 0;
p->msg_end = replylen;
return PNR_OK;
}
enum pubnub_res pbcc_parse_channel_registry_response(struct pbcc_context* p)
{
enum pbjson_object_name_parse_result result;
struct pbjson_elem el;
struct pbjson_elem found;
el.start = p->http_reply;
el.end = p->http_reply + p->http_buf_len;
if (pbjson_value_for_field_found(&el, "status", "403")) {
PUBNUB_LOG_ERROR(
"pbcc_parse_channel_registry_response(pbcc=%p) - AccessDenied: "
"response from server - response='%s'\n",
p,
p->http_reply);
return PNR_ACCESS_DENIED;
}
p->chan_ofs = 0;
p->chan_end = p->http_buf_len;
p->msg_ofs = p->msg_end = 0;
/* We should probably also check that there is a key "service"
with value "channel-registry". Maybe even that there is a key
"status" (with value 200).
*/
result = pbjson_get_object_value(&el, "error", &found);
if (jonmpOK == result) {
if (pbjson_elem_equals_string(&found, "false")) {
return PNR_OK;
}
else {
return PNR_CHANNEL_REGISTRY_ERROR;
}
}
else {
return PNR_FORMAT_ERROR;
}
}
enum pubnub_res pbcc_leave_prep(struct pbcc_context* pb,
const char* channel,
const char* channel_group)
{
char const* user_id = pbcc_user_id_get(pb);
PUBNUB_ASSERT_OPT(user_id != NULL);
enum pubnub_res rslt = PNR_OK;
if (NULL == channel) {
if (NULL == channel_group) {
return PNR_INVALID_CHANNEL;
}
channel = ",";
}
pb->http_content_len = 0;
/* Make sure next subscribe() will be a join. */
pb->timetoken[0] = '0';
pb->timetoken[1] = '\0';
pb->http_buf_len = snprintf(pb->http_buf,
sizeof pb->http_buf,
"/v2/presence/sub-key/%s/channel/",
pb->subscribe_key);
APPEND_URL_ENCODED_M(pb, channel);
pb->http_buf_len += snprintf(pb->http_buf + pb->http_buf_len,
sizeof pb->http_buf - pb->http_buf_len,
"/leave");
char const* const uname = pubnub_uname();
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 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 (channel_group) { ADD_URL_PARAM(qparam, channel-group, channel_group); }
#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_leave_prep. REQUEST =%s\n", pb->http_buf);
return (rslt != PNR_OK) ? rslt : PNR_STARTED;
}
enum pubnub_res pbcc_time_prep(struct pbcc_context* pb)
{
char const* user_id = pbcc_user_id_get(pb);
char const* const uname = pubnub_uname();
PUBNUB_ASSERT_OPT(user_id != NULL);
if (pb->msg_ofs < pb->msg_end) {
return PNR_RX_BUFF_NOT_EMPTY;
}
pb->http_content_len = 0;
pb->msg_ofs = pb->msg_end = 0;
pb->http_buf_len = snprintf(pb->http_buf, sizeof pb->http_buf, "/time/0");
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); }
ADD_URL_AUTH_PARAM(pb, qparam, auth);
ENCODE_URL_PARAMETERS(pb, qparam);
PUBNUB_LOG_DEBUG("pbcc_time_prep. REQUEST =%s\n", pb->http_buf);
return PNR_STARTED;
}
enum pubnub_res pbcc_history_prep(struct pbcc_context* pb,
const char* channel,
unsigned int count,
bool include_token,
enum pubnub_tribool string_token,
enum pubnub_tribool reverse,
enum pubnub_tribool include_meta,
char const* start,
char const* end)
{
char const* const uname = pubnub_uname();
char const* user_id = pbcc_user_id_get(pb);
enum pubnub_res rslt = PNR_OK;
PUBNUB_ASSERT_OPT(user_id != NULL);
pb->http_content_len = 0;
pb->msg_ofs = pb->msg_end = 0;
#if PUBNUB_CRYPTO_API
for (size_t i = 0; i < pb->decrypted_message_count; i++) {
free(pb->decrypted_messages[i]);
}
pb->decrypted_message_count = 0;
#endif
pb->http_buf_len = snprintf(pb->http_buf,
sizeof pb->http_buf,
"/v2/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); }
if (user_id) { ADD_URL_PARAM(qparam, uuid, user_id); }
char cnt_buf[sizeof(int) * 4 + 1];
snprintf(cnt_buf, sizeof(cnt_buf), "%d", count);
if (count) { ADD_URL_PARAM(qparam, count, cnt_buf); }
ADD_URL_PARAM(qparam, include_token, include_token ? "true" : "false");
if (string_token != pbccNotSet) {
ADD_URL_PARAM(qparam,
stringtoken,
string_token == pbccTrue ? "1" : "0");
}
#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 (reverse != pbccNotSet) {
ADD_URL_PARAM(qparam, reverse, reverse == pbccTrue ? "1" : "0");
}
if (include_meta != pbccNotSet) {
ADD_URL_PARAM(qparam,
include_meta,
include_meta == pbccTrue ? "1" : "0");
}
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_history_prep. REQUEST =%s\n", pb->http_buf);
return (rslt != PNR_OK) ? rslt : PNR_STARTED;
}
enum pubnub_res pbcc_heartbeat_prep(struct pbcc_context* pb,
const char* channel,
const char* channel_group)
{
char const* user_id = pbcc_user_id_get(pb);
char const* const uname = pubnub_uname();
enum pubnub_res rslt = PNR_OK;
PUBNUB_ASSERT_OPT(user_id != NULL);
if (NULL == channel) {
if (NULL == channel_group) {
return PNR_INVALID_CHANNEL;
}
channel = ",";
}
if (pb->msg_ofs < pb->msg_end) {
return PNR_RX_BUFF_NOT_EMPTY;
}
pb->http_content_len = 0;
pb->msg_ofs = pb->msg_end = 0;
pb->http_buf_len = snprintf(pb->http_buf,
sizeof pb->http_buf,
"/v2/presence/sub-key/%s/channel/",
pb->subscribe_key);
APPEND_URL_ENCODED_M(pb, channel);
pb->http_buf_len += snprintf(pb->http_buf + pb->http_buf_len,
sizeof pb->http_buf - pb->http_buf_len,
"/heartbeat");
URL_PARAMS_INIT(qparam, PUBNUB_MAX_URL_PARAMS);
if (uname) { ADD_URL_PARAM(qparam, pnsdk, uname); }
if (channel_group) { ADD_URL_PARAM(qparam, channel-group, channel_group); }
if (user_id) { ADD_URL_PARAM(qparam, uuid, user_id); }
if (pb->state) { ADD_URL_PARAM(qparam, state, pb->state); }
#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 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_heartbeat_prep. REQUEST =%s\n", pb->http_buf);
return (rslt != PNR_OK) ? rslt : PNR_STARTED;
}
enum pubnub_res pbcc_here_now_prep(struct pbcc_context* pb,
const char* channel,
const char* channel_group,
enum pubnub_tribool disable_uuids,
enum pubnub_tribool state)
{
char const* const uname = pubnub_uname();
char const* user_id = pbcc_user_id_get(pb);
enum pubnub_res rslt = PNR_OK;
PUBNUB_ASSERT_OPT(user_id != NULL);
if (NULL == channel) {
if (channel_group != NULL) {
channel = ",";
}
}
pb->http_content_len = 0;
pb->msg_ofs = pb->msg_end = 0;
pb->http_buf_len = snprintf(pb->http_buf,
sizeof pb->http_buf,
"/v2/presence/sub-key/%s%s",
pb->subscribe_key,
channel ? "/channel/" : "");
APPEND_URL_ENCODED_M(pb, channel);
URL_PARAMS_INIT(qparam, PUBNUB_MAX_URL_PARAMS);
if (uname) { ADD_URL_PARAM(qparam, pnsdk, uname); }
if (channel_group) { ADD_URL_PARAM(qparam, channel-group, channel_group); }
if (user_id) { 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 (disable_uuids != pbccNotSet) {
ADD_URL_PARAM(qparam,
disable_uuids,
disable_uuids == pbccTrue ? "1" : "0");
}
if (state != pbccNotSet) {
ADD_URL_PARAM(qparam, state, state == pbccTrue ? "1" : "0");
}
#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_here_now_prep. REQUEST =%s\n", pb->http_buf);
return (rslt != PNR_OK) ? rslt : PNR_STARTED;
}
enum pubnub_res pbcc_where_now_prep(struct pbcc_context* pb,
const char* user_id)
{
PUBNUB_ASSERT_OPT(user_id != NULL);
enum pubnub_res rslt = PNR_OK;
char const* const uname = pubnub_uname();
char const* pb_user_id = pbcc_user_id_get(pb);
PUBNUB_ASSERT_OPT(pb_user_id != NULL);
pb->http_content_len = 0;
pb->msg_ofs = pb->msg_end = 0;
pb->http_buf_len = snprintf(pb->http_buf,
sizeof pb->http_buf,
"/v2/presence/sub-key/%s/uuid/%s",
pb->subscribe_key,
user_id);
URL_PARAMS_INIT(qparam, PUBNUB_MAX_URL_PARAMS);
if (uname) { ADD_URL_PARAM(qparam, pnsdk, uname); }
if (pb_user_id) { ADD_URL_PARAM(qparam, uuid, pb_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 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_where_now_prep. REQUEST =%s\n", pb->http_buf);
return (rslt != PNR_OK) ? rslt : PNR_STARTED;
}
enum pubnub_res pbcc_set_state_prep(struct pbcc_context* pb,
char const* channel,
char const* channel_group,
const char* user_id,
char const* state)
{
PUBNUB_ASSERT_OPT(user_id != NULL);
PUBNUB_ASSERT_OPT(state != NULL);
enum pubnub_res rslt = PNR_OK;
char const* pb_user_id = pbcc_user_id_get(pb);
char const* const uname = pubnub_uname();
PUBNUB_ASSERT_OPT(pb_user_id != NULL);
if (NULL == channel) {
if (NULL == channel_group) {
return PNR_INVALID_CHANNEL;
}
channel = ",";
}
if (pb->msg_ofs < pb->msg_end) {
return PNR_RX_BUFF_NOT_EMPTY;
}
pb->http_buf_len = snprintf(pb->http_buf,
sizeof pb->http_buf,
"/v2/presence/sub-key/%s/channel/",
pb->subscribe_key);
APPEND_URL_ENCODED_M(pb, channel);
pb->http_buf_len += snprintf(pb->http_buf + pb->http_buf_len,
sizeof pb->http_buf - pb->http_buf_len,
"/uuid/%s/data",
user_id);
URL_PARAMS_INIT(qparam, PUBNUB_MAX_URL_PARAMS);
if (uname) { ADD_URL_PARAM(qparam, pnsdk, uname); }
if (channel_group) { ADD_URL_PARAM(qparam, channel-group, channel_group); }
if (pb_user_id) { ADD_URL_PARAM(qparam, uuid, pb_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 (state) { ADD_URL_PARAM(qparam, state, state); }
#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_set_state_prep. REQUEST =%s\n", pb->http_buf);
return (rslt != PNR_OK) ? rslt : PNR_STARTED;
}
enum pubnub_res pbcc_state_get_prep(struct pbcc_context* pb,
char const* channel,
char const* channel_group,
const char* user_id)
{
PUBNUB_ASSERT_OPT(user_id != NULL);
enum pubnub_res rslt = PNR_OK;
char const* pb_user_id = pbcc_user_id_get(pb);
char const* const uname = pubnub_uname();
PUBNUB_ASSERT_OPT(pb_user_id != NULL);
if (NULL == channel) {
if (NULL == channel_group) {
return PNR_INVALID_CHANNEL;
}
channel = ",";
}
if (pb->msg_ofs < pb->msg_end) {
return PNR_RX_BUFF_NOT_EMPTY;
}
pb->http_buf_len = snprintf(pb->http_buf,
sizeof pb->http_buf,
"/v2/presence/sub-key/%s/channel/",
pb->subscribe_key);
APPEND_URL_ENCODED_M(pb, channel);
pb->http_buf_len += snprintf(pb->http_buf + pb->http_buf_len,
sizeof pb->http_buf - pb->http_buf_len,
"/uuid/%s",
user_id);
URL_PARAMS_INIT(qparam, PUBNUB_MAX_URL_PARAMS);
if (uname) { ADD_URL_PARAM(qparam, pnsdk, uname); }
if (channel_group) { ADD_URL_PARAM(qparam, channel-group, channel_group); }
if (pb_user_id) { ADD_URL_PARAM(qparam, uuid, pb_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 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_state_get_prep. REQUEST =%s\n", pb->http_buf);
return (rslt != PNR_OK) ? rslt : PNR_STARTED;
}
enum pubnub_res pbcc_remove_channel_group_prep(struct pbcc_context* pb,
char const* channel_group)
{
PUBNUB_ASSERT_OPT(channel_group != NULL);
enum pubnub_res rslt = PNR_OK;
char const* user_id = pbcc_user_id_get(pb);
char const* const uname = pubnub_uname();
PUBNUB_ASSERT_OPT(user_id != NULL);
pb->http_buf_len = snprintf(
pb->http_buf,
sizeof pb->http_buf,
"/v1/channel-registration/sub-key/%s/channel-group/%s/remove",
pb->subscribe_key,
channel_group);
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 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 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_remove_channel_group_prep. REQUEST =%s\n",
pb->http_buf);
return (rslt != PNR_OK) ? rslt : PNR_STARTED;
}
enum pubnub_res pbcc_channel_registry_prep(struct pbcc_context* pb,
char const* channel_group,
char const* param,
char const* channel)
{
PUBNUB_ASSERT_OPT(channel_group != NULL);
enum pubnub_res rslt = PNR_OK;
char const* user_id = pbcc_user_id_get(pb);
char const* const uname = pubnub_uname();
PUBNUB_ASSERT_OPT(user_id != NULL);
pb->http_buf_len = snprintf(
pb->http_buf,
sizeof pb->http_buf,
"/v1/channel-registration/sub-key/%s/channel-group/%s",
pb->subscribe_key,
channel_group);
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 (NULL != param) {
PUBNUB_ASSERT_OPT(channel != NULL);
ADD_URL_PARAM_TRUE_KEY(qparam, param, channel);
}
#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 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_channel_registry_prep. REQUEST =%s\n", pb->http_buf);
return (rslt != PNR_OK) ? rslt : PNR_STARTED;
}