10
10
#include "pubnub_url_encode.h"
11
11
12
12
#include "pubnub_assert.h"
13
+ #include "pubnub_helper.h"
13
14
#include "pubnub_log.h"
14
15
#else
15
16
#error this module can only be used if PUBNUB_USE_ADVANCED_HISTORY is defined and set to 1
@@ -543,3 +544,131 @@ enum pubnub_res pbcc_message_counts_prep(
543
544
PUBNUB_LOG_DEBUG ("pbcc_message_counts_prep. REQUEST =%s\n" , p -> http_buf );
544
545
return (rslt != PNR_OK ) ? rslt : PNR_STARTED ;
545
546
}
547
+
548
+ enum pubnub_res pbcc_delete_messages_prep (struct pbcc_context * pb ,
549
+ char const * channel ,
550
+ char const * start ,
551
+ char const * end )
552
+ {
553
+ char const * const uname = pubnub_uname ();
554
+ char const * user_id = pbcc_user_id_get (pb );
555
+ #if PUBNUB_CRYPTO_API
556
+ enum pubnub_res rslt = PNR_OK ;
557
+ #endif
558
+
559
+ PUBNUB_ASSERT_OPT (NULL != user_id );
560
+
561
+ pb -> msg_ofs = pb -> msg_end = 0 ;
562
+ pb -> http_content_len = 0 ;
563
+
564
+ pb -> http_buf_len =
565
+ snprintf (pb -> http_buf ,
566
+ sizeof pb -> http_buf ,
567
+ "/v3/history/sub-key/%s/channel/" ,
568
+ pb -> subscribe_key );
569
+ APPEND_URL_ENCODED_M (pb , channel );
570
+
571
+ URL_PARAMS_INIT (qparam , PUBNUB_MAX_URL_PARAMS );
572
+ if (uname ) { ADD_URL_PARAM (qparam , pnsdk , uname ); }
573
+ ADD_URL_PARAM (qparam , uuid , user_id );
574
+ #if PUBNUB_CRYPTO_API
575
+ if (pb -> secret_key == NULL ) { ADD_URL_AUTH_PARAM (pb , qparam , auth ); }
576
+ ADD_TS_TO_URL_PARAM ();
577
+ #else
578
+ ADD_URL_AUTH_PARAM (pb , qparam , auth );
579
+ #endif
580
+ if (start ) { ADD_URL_PARAM (qparam , start , start ); }
581
+ if (end ) { ADD_URL_PARAM (qparam , end , end ); }
582
+
583
+ #if PUBNUB_CRYPTO_API
584
+ SORT_URL_PARAMETERS (qparam );
585
+ #endif
586
+ ENCODE_URL_PARAMETERS (pb , qparam );
587
+ #if PUBNUB_CRYPTO_API
588
+ if (pb -> secret_key != NULL ) {
589
+ rslt = pbcc_sign_url (pb , "" , pubnubSendViaGET , true);
590
+ }
591
+ #endif
592
+
593
+ PUBNUB_LOG_DEBUG ("pbcc_delete_messages_prep. REQUEST =%s\n" , pb -> http_buf );
594
+ #if PUBNUB_CRYPTO_API
595
+ return (rslt != PNR_OK ) ? rslt : PNR_STARTED ;
596
+ #else
597
+ return PNR_STARTED ;
598
+ #endif
599
+ }
600
+
601
+ pubnub_chamebl_t pbcc_get_delete_messages_response (struct pbcc_context * pb )
602
+ {
603
+ pubnub_chamebl_t resp ;
604
+ char const * reply = pb -> http_reply ;
605
+ int reply_len = pb -> http_buf_len ;
606
+
607
+ if (PNR_OK != pb -> last_result ) {
608
+ PUBNUB_LOG_ERROR ("pbcc_get_delete_messages_response(pb=%p) can be "
609
+ "called only if previous transactin "
610
+ "PBTT_DELETE_MESSAGES(%d) is finished successfully. "
611
+ "Transaction result was: %d('%s')\n" ,
612
+ pb ,
613
+ PBTT_DELETE_MESSAGES ,
614
+ pb -> last_result ,
615
+ pubnub_res_2_string (pb -> last_result ));
616
+ resp .ptr = NULL ;
617
+ resp .size = 0 ;
618
+ return resp ;
619
+ }
620
+
621
+ resp .ptr = (char * )reply ;
622
+ resp .size = reply_len ;
623
+ return resp ;
624
+ }
625
+
626
+ enum pubnub_res pbcc_parse_delete_messages_response (struct pbcc_context * pb )
627
+ {
628
+ enum pbjson_object_name_parse_result jpresult ;
629
+ struct pbjson_elem el ;
630
+ struct pbjson_elem found ;
631
+ char * reply = pb -> http_reply ;
632
+ int reply_len = pb -> http_buf_len ;
633
+
634
+ if ((reply [0 ] != '{' ) || (reply [reply_len - 1 ] != '}' )) {
635
+ PUBNUB_LOG_ERROR (
636
+ "Error: pbcc_parse_delete_messages_response(pbcc=%p) - "
637
+ "Response is not json object: response='%.*s'\n" ,
638
+ pb ,
639
+ reply_len ,
640
+ reply );
641
+ return PNR_FORMAT_ERROR ;
642
+ }
643
+ el .start = reply ;
644
+ el .end = reply + reply_len ;
645
+ if (pbjson_value_for_field_found (& el , "status" , "403" )) {
646
+ PUBNUB_LOG_ERROR (
647
+ "Error: pbcc_parse_delete_messages_response(pbcc=%p) - "
648
+ "Access Denied: response='%.*s'\n" ,
649
+ pb ,
650
+ reply_len ,
651
+ reply );
652
+ return PNR_ACCESS_DENIED ;
653
+ }
654
+ jpresult = pbjson_get_object_value (& el , "error" , & found );
655
+ if (jonmpOK == jpresult ) {
656
+ if (pbjson_elem_equals_string (& found , "true" )) {
657
+ return PNR_ERROR_ON_SERVER ;
658
+ }
659
+ }
660
+ else {
661
+ PUBNUB_LOG_ERROR (
662
+ "Error: pbcc_parse_delete_messages_response(pbcc=%p) - "
663
+ "'error' atribute not found in the response. error=%d\n"
664
+ "response='%.*s'\n" ,
665
+ pb ,
666
+ jpresult ,
667
+ reply_len ,
668
+ reply );
669
+ return PNR_FORMAT_ERROR ;
670
+ }
671
+ pb -> chan_ofs = pb -> chan_end = 0 ;
672
+
673
+ return PNR_OK ;
674
+ }
0 commit comments