1818
1919
2020enum pubnub_res pbcc_fetch_history_prep (struct pbcc_context * pb ,
21- const char * channel ,
22- unsigned int max_per_channel ,
23- enum pubnub_tribool include_meta ,
24- enum pubnub_tribool include_custom_message_type ,
25- enum pubnub_tribool include_message_type ,
26- enum pubnub_tribool include_user_id ,
27- enum pubnub_tribool include_message_actions ,
28- enum pubnub_tribool reverse ,
29- char const * start ,
30- char const * end )
21+ const char * channel ,
22+ unsigned int max_per_channel ,
23+ enum pubnub_tribool include_meta ,
24+ enum pubnub_tribool
25+ include_custom_message_type ,
26+ enum pubnub_tribool
27+ include_message_type ,
28+ enum pubnub_tribool include_user_id ,
29+ enum pubnub_tribool
30+ include_message_actions ,
31+ enum pubnub_tribool reverse ,
32+ char const * start ,
33+ char const * end )
3134{
3235 char const * const uname = pubnub_uname ();
33- enum pubnub_res rslt = PNR_OK ;
36+ enum pubnub_res rslt = PNR_OK ;
3437
3538 pb -> http_content_len = 0 ;
36- pb -> msg_ofs = pb -> msg_end = 0 ;
39+ pb -> msg_ofs = pb -> msg_end = 0 ;
3740
3841 pb -> http_buf_len = snprintf (pb -> http_buf ,
3942 sizeof pb -> http_buf ,
4043 "/v3/%s/sub-key/%s/channel/" ,
41- (include_message_actions == pbccTrue ) ? "history-with-actions" : "history" ,
44+ (include_message_actions == pbccTrue )
45+ ? "history-with-actions"
46+ : "history" ,
4247 pb -> subscribe_key );
4348 APPEND_URL_ENCODED_M (pb , channel );
4449
4550 URL_PARAMS_INIT (qparam , PUBNUB_MAX_URL_PARAMS );
4651 if (uname ) { ADD_URL_PARAM (qparam , pnsdk , uname ); }
4752
48- int ch_count = 0 ;
49- char * ch_lst = (char * )strtok ((char * )channel , "," );
53+ int ch_count = 0 ;
54+ char * ch_lst = (char * )strtok ((char * )channel , "," );
5055 while (ch_lst != NULL ) {
5156 ch_count ++ ;
5257 ch_lst = (char * )strtok (NULL , "," );
5358 }
5459 if (max_per_channel <= 0 ) {
55- if (include_message_actions == pbccTrue || ch_count > 1 ) { max_per_channel = 25 ; }
56- else {max_per_channel = 100 ; }
60+ if (include_message_actions == pbccTrue || ch_count > 1 ) {
61+ max_per_channel = 25 ;
62+ }
63+ else { max_per_channel = 100 ; }
5764 }
5865 char max_per_ch_cnt_buf [sizeof (int ) * 4 + 1 ];
59- sprintf (max_per_ch_cnt_buf , "%d" , max_per_channel );
66+ snprintf (max_per_ch_cnt_buf ,
67+ sizeof (max_per_ch_cnt_buf ),
68+ "%d" ,
69+ max_per_channel );
6070 if (max_per_channel ) { ADD_URL_PARAM (qparam , max , max_per_ch_cnt_buf ); }
6171
62- if (include_meta != pbccNotSet ) { ADD_URL_PARAM (qparam , include_meta , include_meta == pbccTrue ? "true" : "false" ); }
63- if (include_custom_message_type != pbccNotSet ) { ADD_URL_PARAM (qparam , include_custom_message_type , include_custom_message_type == pbccTrue ? "true" : "false" ); }
64- if (include_message_type != pbccNotSet ) { ADD_URL_PARAM (qparam , include_message_type , include_message_type == pbccTrue ? "true" : "false" ); }
65- if (include_user_id != pbccNotSet ) { ADD_URL_PARAM (qparam , include_uuid , include_user_id == pbccTrue ? "true" : "false" ); }
72+ if (include_meta != pbccNotSet ) {
73+ ADD_URL_PARAM (qparam ,
74+ include_meta ,
75+ include_meta == pbccTrue ? "true" : "false" );
76+ }
77+ if (include_custom_message_type != pbccNotSet ) {
78+ ADD_URL_PARAM (qparam ,
79+ include_custom_message_type ,
80+ include_custom_message_type == pbccTrue ? "true" :
81+ "false" );
82+ }
83+ if (include_message_type != pbccNotSet ) {
84+ ADD_URL_PARAM (qparam ,
85+ include_message_type ,
86+ include_message_type == pbccTrue ? "true" : "false" );
87+ }
88+ if (include_user_id != pbccNotSet ) {
89+ ADD_URL_PARAM (qparam ,
90+ include_uuid ,
91+ include_user_id == pbccTrue ? "true" : "false" );
92+ }
6693#if PUBNUB_CRYPTO_API
6794 if (pb -> secret_key == NULL ) { ADD_URL_AUTH_PARAM (pb , qparam , auth ); }
6895 ADD_TS_TO_URL_PARAM ();
6996#else
7097 ADD_URL_AUTH_PARAM (pb , qparam , auth );
7198#endif
72- if (reverse != pbccNotSet ) { ADD_URL_PARAM (qparam , reverse , reverse == pbccTrue ? "true" : "false" ); }
99+ if (reverse != pbccNotSet ) {
100+ ADD_URL_PARAM (qparam , reverse , reverse == pbccTrue ? "true" : "false" );
101+ }
73102 if (start ) { ADD_URL_PARAM (qparam , start , start ); }
74103 if (end ) { ADD_URL_PARAM (qparam , end , end ); }
75104
@@ -89,37 +118,39 @@ enum pubnub_res pbcc_fetch_history_prep(struct pbcc_context* pb,
89118
90119enum pubnub_res pbcc_parse_fetch_history_response (struct pbcc_context * pb )
91120{
92- char * reply = pb -> http_reply ;
93- int replylen = pb -> http_buf_len ;
121+ char * reply = pb -> http_reply ;
122+ int replylen = pb -> http_buf_len ;
94123 struct pbjson_elem elem ;
95124
96125 if ((replylen < 2 ) || (reply [0 ] != '{' )) {
97126 return PNR_FORMAT_ERROR ;
98127 }
99-
128+
100129 pb -> msg_end = replylen + 1 ;
101130
102131 elem .end = pbjson_find_end_element (reply , reply + replylen );
103132 /* elem.end has to be just behind end curly brace */
104133 if ((* reply != '{' ) || (* (elem .end ++ ) != '}' )) {
105- PUBNUB_LOG_ERROR ("pbcc_parse_fetch_history_response(pbcc=%p) - Invalid: "
106- "response from server is not JSON - response='%s'\n" ,
107- pb ,
108- reply );
134+ PUBNUB_LOG_ERROR (
135+ "pbcc_parse_fetch_history_response(pbcc=%p) - Invalid: "
136+ "response from server is not JSON - response='%s'\n" ,
137+ pb ,
138+ reply );
109139
110140 return PNR_FORMAT_ERROR ;
111141 }
112142 elem .start = reply ;
113143
114- if (pbjson_value_for_field_found (& elem , "status" , "403" )){
115- PUBNUB_LOG_ERROR ("pbcc_parse_fetch_history_response(pbcc=%p) - AccessDenied: "
116- "response from server - response='%s'\n" ,
117- pb ,
118- reply );
144+ if (pbjson_value_for_field_found (& elem , "status" , "403" )) {
145+ PUBNUB_LOG_ERROR (
146+ "pbcc_parse_fetch_history_response(pbcc=%p) - AccessDenied: "
147+ "response from server - response='%s'\n" ,
148+ pb ,
149+ reply );
119150 return PNR_ACCESS_DENIED ;
120151 }
121152
122- if (pbjson_value_for_field_found (& elem , "error" , "true" )){
153+ if (pbjson_value_for_field_found (& elem , "error" , "true" )) {
123154 PUBNUB_LOG_ERROR ("pbcc_parse_fetch_history_response(pbcc=%p) - Error: "
124155 "response from server - response='%s'\n" ,
125156 pb ,
@@ -132,9 +163,9 @@ enum pubnub_res pbcc_parse_fetch_history_response(struct pbcc_context* pb)
132163
133164pubnub_chamebl_t pbcc_get_fetch_history (struct pbcc_context * pb )
134165{
135- pubnub_chamebl_t result ;
136- char const * reply = pb -> http_reply ;
137- int replylen = pb -> http_buf_len ;
166+ pubnub_chamebl_t result ;
167+ char const * reply = pb -> http_reply ;
168+ int replylen = pb -> http_buf_len ;
138169 struct pbjson_elem elem ;
139170 if (pb -> last_result != PNR_OK ) {
140171 PUBNUB_LOG_ERROR ("pbcc_get_fetch_history(pb=%p) can be called only if "
@@ -144,16 +175,16 @@ pubnub_chamebl_t pbcc_get_fetch_history(struct pbcc_context* pb)
144175 PBTT_FETCH_HISTORY ,
145176 pb -> last_result ,
146177 pubnub_res_2_string (pb -> last_result ));
147- result .ptr = NULL ;
178+ result .ptr = NULL ;
148179 result .size = 0 ;
149180 return result ;
150181 }
151-
182+
152183 elem .start = reply ;
153- elem .end = pbjson_find_end_element (reply , reply + replylen ) + 1 ;
184+ elem .end = pbjson_find_end_element (reply , reply + replylen ) + 1 ;
154185
155- result .size = elem .end - elem .start ;
156- result .ptr = (char * )elem .start ;
186+ result .size = elem .end - elem .start ;
187+ result .ptr = (char * )elem .start ;
157188 result .ptr [result .size ] = '\0' ;
158189
159190 return result ;
0 commit comments