17
17
18
18
/* Maximum number of actions to return in response */
19
19
#define MAX_ACTIONS_LIMIT 100
20
+ #define MAX_ACTION_TYPE_LENGTH 15
20
21
21
22
22
23
enum pubnub_res pbcc_form_the_action_object (struct pbcc_context * pb ,
23
24
char * obj_buffer ,
24
25
size_t buffer_size ,
25
26
enum pubnub_action_type actype ,
26
- char const * * val )
27
- {
28
- char const * user_id = pbcc_user_id_get (pb );
27
+ char const * * val ) {
29
28
char const * type_literal ;
30
29
30
+ switch (actype ) {
31
+ case pbactypReaction :
32
+ type_literal = "\"reaction\"" ;
33
+ break ;
34
+ case pbactypReceipt :
35
+ type_literal = "\"receipt\"" ;
36
+ break ;
37
+ case pbactypCustom :
38
+ type_literal = "\"custom\"" ;
39
+ break ;
40
+ default :
41
+ PUBNUB_LOG_ERROR ("pbcc_form_the_action_object(pbcc=%p) - "
42
+ "unknown action type = %d\n" ,
43
+ pb ,
44
+ actype );
45
+ return PNR_INVALID_PARAMETERS ;
46
+ }
47
+
48
+ return pbcc_form_the_action_object_str (pb , obj_buffer , buffer_size , type_literal , val );
49
+ }
50
+
51
+
52
+ enum pubnub_res pbcc_form_the_action_object_str (struct pbcc_context * pb ,
53
+ char * obj_buffer ,
54
+ size_t buffer_size ,
55
+ char const * action_type ,
56
+ char const * * val ) {
57
+ char const * user_id = pbcc_user_id_get (pb );
58
+
31
59
PUBNUB_ASSERT_OPT (user_id != NULL );
32
60
33
61
if (NULL == user_id ) {
@@ -42,25 +70,17 @@ enum pubnub_res pbcc_form_the_action_object(struct pbcc_context* pb,
42
70
* val );
43
71
return PNR_INVALID_PARAMETERS ;
44
72
}
45
- switch (actype ) {
46
- case pbactypReaction :
47
- type_literal = "reaction" ;
48
- break ;
49
- case pbactypReceipt :
50
- type_literal = "receipt" ;
51
- break ;
52
- case pbactypCustom :
53
- type_literal = "custom" ;
54
- break ;
55
- default :
73
+ if (('\"' != * action_type ) || ('\"' != * (action_type + pb_strnlen_s (action_type , MAX_ACTION_TYPE_LENGTH ) - 1 ))) {
56
74
PUBNUB_LOG_ERROR ("pbcc_form_the_action_object(pbcc=%p) - "
57
- "unknown action type = %d\n" ,
75
+ "quotation marks on action type ends are missing: "
76
+ "action_type = %s\n" ,
58
77
pb ,
59
- actype );
78
+ action_type );
60
79
return PNR_INVALID_PARAMETERS ;
61
80
}
81
+
62
82
if (buffer_size < sizeof ("{\"type\":\"\",\"value\":,\"user_id\":\"\"}" ) +
63
- pb_strnlen_s (type_literal , sizeof "reaction" ) +
83
+ pb_strnlen_s (action_type , MAX_ACTION_TYPE_LENGTH ) +
64
84
pb_strnlen_s (* val , PUBNUB_MAX_OBJECT_LENGTH ) +
65
85
pb -> user_id_len ) {
66
86
PUBNUB_LOG_ERROR ("pbcc_form_the_action_object(pbcc=%p) - "
@@ -70,15 +90,15 @@ enum pubnub_res pbcc_form_the_action_object(struct pbcc_context* pb,
70
90
pb ,
71
91
(unsigned long )buffer_size ,
72
92
(unsigned long )(sizeof ("{\"type\":\"\",\"value\":,\"user_id\":\"\"}" ) +
73
- pb_strnlen_s (type_literal , sizeof "reaction" ) +
93
+ pb_strnlen_s (action_type , MAX_ACTION_TYPE_LENGTH ) +
74
94
pb_strnlen_s (* val , PUBNUB_MAX_OBJECT_LENGTH ) +
75
95
pb -> user_id_len ));
76
96
return PNR_TX_BUFF_TOO_SMALL ;
77
97
}
78
98
snprintf (obj_buffer ,
79
99
buffer_size ,
80
- "{\"type\":\"%s\" ,\"value\":%s,\"user_id\":\"%s\"}" ,
81
- type_literal ,
100
+ "{\"type\":%s ,\"value\":%s,\"user_id\":\"%s\"}" ,
101
+ action_type ,
82
102
* val ,
83
103
user_id );
84
104
* val = obj_buffer ;
0 commit comments