Browse code

parser: make get_hdr_field(..) and necessary called functions const-correct

Henning Westerholt authored on 05/07/2012 20:35:22
Showing 18 changed files
... ...
@@ -63,7 +63,7 @@
63 63
 /** Frees a hdr_field structure.
64 64
  * WARNING: it frees only parsed (and not name.s, body.s)
65 65
  */
66
-void clean_hdr_field(struct hdr_field* hf)
66
+void clean_hdr_field(struct hdr_field* const hf)
67 67
 {
68 68
 	void** h_parsed;
69 69
 
... ...
@@ -228,7 +228,7 @@ void free_hdr_field_lst(struct hdr_field* hf)
228 228
 }
229 229
 
230 230
 /* print the content of hdr_field */
231
-void dump_hdr_field( struct hdr_field* hf )
231
+void dump_hdr_field(struct hdr_field const* const hf )
232 232
 {
233 233
 	LOG(L_ERR, "DEBUG: dump_hdr_field: type=%d, name=%.*s, "
234 234
 		"body=%.*s, parsed=%p, next=%p\n",
... ...
@@ -258,7 +258,7 @@ static inline int hdr_allocs_parse(struct hdr_field* hdr)
258 258
 /** frees a hdr_field structure.
259 259
  * WARNING: it frees only parsed (and not name.s, body.s)
260 260
  */
261
-void clean_hdr_field(struct hdr_field* hf);
261
+void clean_hdr_field(struct hdr_field* const hf);
262 262
 
263 263
 
264 264
 /** frees a hdr_field list.
... ...
@@ -267,7 +267,7 @@ void clean_hdr_field(struct hdr_field* hf);
267 267
 void free_hdr_field_lst(struct hdr_field* hf);
268 268
 
269 269
 /* print content of hdr_field */
270
-void dump_hdr_field( struct hdr_field* hf );
270
+void dump_hdr_field( struct hdr_field const* const hf);
271 271
 
272 272
 /**
273 273
  * free hdr parsed structure using inner free function
... ...
@@ -88,7 +88,7 @@ unsigned int global_req_flags = 0;
88 88
 
89 89
 /* returns pointer to next header line, and fill hdr_f ;
90 90
  * if at end of header returns pointer to the last crlf  (always buf)*/
91
-char* get_hdr_field(char* buf, char* end, struct hdr_field* hdr)
91
+char* get_hdr_field(char* const buf, char* const end, struct hdr_field* const hdr)
92 92
 {
93 93
 
94 94
 	char* tmp;
... ...
@@ -386,7 +386,7 @@ int parse_msg(char* buf, unsigned int len, struct sip_msg* msg);
386 386
 
387 387
 int parse_headers(struct sip_msg* msg, hdr_flags_t flags, int next);
388 388
 
389
-char* get_hdr_field(char* buf, char* end, struct hdr_field* hdr);
389
+char* get_hdr_field(char* const buf, char* const end, struct hdr_field* const hdr);
390 390
 
391 391
 void free_sip_msg(struct sip_msg* msg);
392 392
 
... ...
@@ -216,7 +216,7 @@ static type_node_t subtype_tree[] = {
216 216
 
217 217
 
218 218
 
219
-char* parse_content_length( char* buffer, char* end, int* length)
219
+char* parse_content_length(char* const buffer, const char* const end, int* const length)
220 220
 {
221 221
 	int number;
222 222
 	char *p;
... ...
@@ -259,7 +259,7 @@ error:
259 259
 
260 260
 
261 261
 
262
-char* decode_mime_type(char *start, char *end, unsigned int *mime_type)
262
+char* decode_mime_type(char* const start, const char* const end, unsigned int* const mime_type)
263 263
 {
264 264
 	int node;
265 265
 	char *mark;
... ...
@@ -385,10 +385,10 @@ error:
385 385
  *  	-   > 0 mime found
386 386
  *      -   = 0 hdr not found
387 387
  *      -   =-1 error */
388
-int parse_content_type_hdr( struct sip_msg *msg )
388
+int parse_content_type_hdr(struct sip_msg* const msg)
389 389
 {
390 390
 	char *end;
391
-	char *ret;
391
+	const char *ret;
392 392
 	unsigned int  mime;
393 393
 
394 394
 	/* is the header already found? */
... ...
@@ -430,7 +430,7 @@ error:
430 430
 	return -1;
431 431
 }
432 432
 
433
-int parse_accept_body(struct hdr_field *hdr)
433
+int parse_accept_body(struct hdr_field* const hdr)
434 434
 {
435 435
 	static unsigned int mimes[MAX_MIMES_NR];
436 436
 	int nr_mimes;
... ...
@@ -492,7 +492,7 @@ error:
492 492
  * returns: > 0 ok
493 493
  *          = 0 hdr not found
494 494
  *          = -1 error */
495
-int parse_accept_hdr( struct sip_msg *msg )
495
+int parse_accept_hdr(struct sip_msg* const msg)
496 496
 {
497 497
 	static unsigned int mimes[MAX_MIMES_NR];
498 498
 	int nr_mimes;
... ...
@@ -105,9 +105,9 @@ struct mime_type {
105 105
  *            0        : hdr not found
106 106
  *           -1        : error (parse error )
107 107
  */
108
-int parse_content_type_hdr( struct sip_msg *msg);
108
+int parse_content_type_hdr(struct sip_msg* const msg);
109 109
 
110
-int parse_accept_body(struct hdr_field *hdr);
110
+int parse_accept_body(struct hdr_field* const hdr);
111 111
 
112 112
 /*! \brief
113 113
  * parse the body of the Accept header. It's values are also converted
... ...
@@ -116,7 +116,7 @@ int parse_accept_body(struct hdr_field *hdr);
116 116
  *            0 : hdr not found
117 117
  *           -1 : error (parse error)
118 118
  */
119
-int parse_accept_hdr( struct sip_msg *msg );
119
+int parse_accept_hdr(struct sip_msg* const msg);
120 120
 
121 121
 
122 122
 /*! \brief
... ...
@@ -124,11 +124,11 @@ int parse_accept_hdr( struct sip_msg *msg );
124 124
  *  type specified by this header (see th above defines).
125 125
  *  Returns the first chr after the end of the header.
126 126
  */
127
-char* parse_content_length( char* buffer, char* end, int* len);
127
+char* parse_content_length(char* const buffer, const char* const end, int* const length);
128 128
 
129 129
 /*! \brief
130 130
  * Sets the mime type from the body of a Content-Type header
131 131
  */
132
-char* decode_mime_type(char *start, char *end, unsigned int *mime_type);
132
+char* decode_mime_type(char* const start, const char* const end, unsigned int* const mime_type);
133 133
 
134 134
 #endif
... ...
@@ -42,7 +42,7 @@
42 42
 #include "../mem/mem.h"
43 43
 
44 44
 /*BUGGY*/
45
-char* parse_cseq(char *buf, char* end, struct cseq_body* cb)
45
+char* parse_cseq(char* const buf, const char* const end, struct cseq_body* const cb)
46 46
 {
47 47
 	char *t, *m, *m_end;
48 48
 	
... ...
@@ -102,7 +102,7 @@ error:
102 102
 }
103 103
 
104 104
 
105
-void free_cseq(struct cseq_body* cb)
105
+void free_cseq(struct cseq_body* const cb)
106 106
 {
107 107
 	pkg_free(cb);
108 108
 }
... ...
@@ -54,13 +54,13 @@ struct cseq_body{
54 54
 /*! \brief
55 55
  * Parse CSeq header field
56 56
  */
57
-char* parse_cseq(char *buf, char* end, struct cseq_body* cb);
57
+char* parse_cseq(char* const buf, const char* const end, struct cseq_body* const cb);
58 58
 
59 59
 
60 60
 /*! \brief
61 61
  * Free all associated memory
62 62
  */
63
-void free_cseq(struct cseq_body* cb);
63
+void free_cseq(struct cseq_body* const cb);
64 64
 
65 65
 
66 66
 #endif
... ...
@@ -192,7 +192,7 @@ int hdr_update_type(struct hdr_field* hdr)
192 192
 }
193 193
 #endif
194 194
 
195
-char* parse_hname2(char* begin, char* end, struct hdr_field* hdr)
195
+char* parse_hname2(char* const begin, const char* const end, struct hdr_field* const hdr)
196 196
 {
197 197
 	register char* p;
198 198
 	register unsigned int val;
... ...
@@ -37,6 +37,6 @@
37 37
 /** Fast 32-bit header field name parser.
38 38
  * @file
39 39
  */
40
-char* parse_hname2(char* begin, char* end, struct hdr_field* hdr);
40
+char* parse_hname2(char* const begin, const char* const end, struct hdr_field* const hdr);
41 41
 
42 42
 #endif /* PARSE_HNAME2_H */
... ...
@@ -53,7 +53,7 @@ static int token_char(char _c)
53 53
  * _must_ contain _only_ the method (without trailing or heading whitespace).
54 54
  * \return 0 on success, -1 on error
55 55
  */
56
-int parse_method_name(str* s, enum request_method* method)
56
+int parse_method_name(const str* const s, enum request_method* const method)
57 57
  {
58 58
 	if (unlikely(!s || !method)) {
59 59
 		LOG(L_ERR, "Invalid parameter value\n");
... ...
@@ -172,7 +172,7 @@ int parse_method_name(str* s, enum request_method* method)
172 172
   * Parse a method pointed by _next, assign its enum bit to _method, and update
173 173
   * _next past the method. Returns 1 if parse succeeded and 0 otherwise.
174 174
   */
175
-static int parse_method_advance(str* _next, enum request_method* _method)
175
+static int parse_method_advance(str* const _next, enum request_method* const _method)
176 176
  {
177 177
 	char* end;
178 178
 	
... ...
@@ -358,7 +358,7 @@ found:
358 358
   * Parse comma separated list of methods pointed by _body and assign their
359 359
   * enum bits to _methods.  Returns 0 on success and -1 on failure.
360 360
   */
361
- int parse_methods(str* _body, unsigned int* _methods)
361
+int parse_methods(const str* const _body, unsigned int* const _methods)
362 362
  {
363 363
  	str next;
364 364
  	unsigned int method;
... ...
@@ -44,9 +44,9 @@
44 44
  * Parse comma separated list of methods pointed by _body and assign their
45 45
  * enum bits to _methods.  Returns 1 on success and 0 on failure.
46 46
  */
47
-int parse_methods(str* _body, unsigned int* _methods);
47
+int parse_methods(const str* const _body, unsigned int* const _methods);
48 48
 
49
-int parse_method_name(str* s, enum request_method* _method);
49
+int parse_method_name(const str* const s, enum request_method* const method);
50 50
 
51 51
 
52 52
 #endif /* PARSE_METHODS_H */
... ...
@@ -39,7 +39,7 @@
39 39
 #include "../mem/mem.h"
40 40
 
41 41
 /*! \brief Parse the Retry-after header field */
42
-char* parse_retry_after(char *buf, char* end, unsigned* after, int* err)
42
+char* parse_retry_after(char* const buf, const char* const end, unsigned* const after, int* const err)
43 43
 {
44 44
 	char *t;
45 45
 	int i;
... ...
@@ -33,7 +33,7 @@
33 33
 
34 34
 
35 35
 /* Parse Retry-After header field */
36
-char* parse_retry_after(char *buf, char* end, unsigned* after, int* err);
36
+char* parse_retry_after(char* const buf, const char* const end, unsigned* const after, int* const err);
37 37
 
38 38
 
39 39
 
... ...
@@ -70,9 +70,9 @@ enum {
70 70
 
71 71
 
72 72
 
73
-static /*inline*/ char* parse_to_param(char *buffer, char *end,
74
-					struct to_body *to_b,
75
-					int *returned_status)
73
+static char* parse_to_param(char* const buffer, const char* const end,
74
+					struct to_body* const to_b,
75
+					int* const returned_status)
76 76
 {
77 77
 	struct to_param *param;
78 78
 	struct to_param *newparam;
... ...
@@ -524,8 +524,7 @@ error:
524 524
 
525 525
 
526 526
 
527
-
528
-char* parse_to(char* buffer, char *end, struct to_body *to_b)
527
+char* parse_to(char* const buffer, const char* const end, struct to_body* const to_b)
529 528
 {
530 529
 	int status;
531 530
 	int saved_status;
... ...
@@ -822,7 +821,7 @@ error:
822 822
 }
823 823
 
824 824
 
825
-void free_to_params(struct to_body* tb)
825
+void free_to_params(struct to_body* const tb)
826 826
 {
827 827
 	struct to_param *tp=tb->param_lst;
828 828
 	struct to_param *foo;
... ...
@@ -834,14 +833,14 @@ void free_to_params(struct to_body* tb)
834 834
 }
835 835
 
836 836
 
837
-void free_to(struct to_body* tb)
837
+void free_to(struct to_body* const tb)
838 838
 {
839 839
 	free_to_params(tb);
840 840
 	pkg_free(tb);
841 841
 }
842 842
 
843 843
 
844
-int parse_to_header(struct sip_msg *msg)
844
+int parse_to_header(struct sip_msg* const msg)
845 845
 {
846 846
 	if ( !msg->to && ( parse_headers(msg,HDR_TO_F,0)==-1 || !msg->to)) {
847 847
 		ERR("bad msg or missing TO header\n");
... ...
@@ -856,7 +855,7 @@ int parse_to_header(struct sip_msg *msg)
856 856
 		return -1;
857 857
 }
858 858
 
859
-sip_uri_t *parse_to_uri(sip_msg_t *msg)
859
+sip_uri_t *parse_to_uri(sip_msg_t* const msg)
860 860
 {
861 861
 	to_body_t *tb = NULL;
862 862
 	
... ...
@@ -65,14 +65,14 @@ typedef struct to_body{
65 65
 /*! \brief
66 66
  * To header field parser
67 67
  */
68
-char* parse_to(char* buffer, char *end, struct to_body *to_b);
68
+char* parse_to(char* const buffer, const char* const end, struct to_body* const to_b);
69 69
 
70
-void free_to_params(struct to_body* tb);
70
+void free_to_params(struct to_body* const tb);
71 71
 
72
-void free_to(struct to_body* tb);
72
+void free_to(struct to_body* const tb);
73 73
 
74
-int parse_to_header(struct sip_msg *msg);
74
+int parse_to_header(struct sip_msg* const msg);
75 75
 
76
-sip_uri_t *parse_to_uri(struct sip_msg* msg);
76
+sip_uri_t *parse_to_uri(struct sip_msg* const msg);
77 77
 
78 78
 #endif
... ...
@@ -141,11 +141,11 @@ enum {
141 141
  * WARNING: param->start must be filled before, it's used in param->size 
142 142
  * computation.
143 143
  */
144
-static /*inline*/ char* parse_via_param(char* p, char* end,
145
-										unsigned char* pstate, 
146
-				    					unsigned char* psaved_state,
147
-										struct via_param* param,
148
-										struct via_body* vb)
144
+static /*inline*/ char* parse_via_param(char* const p, const char* const end,
145
+									unsigned char* const pstate, 
146
+				    					unsigned char* const psaved_state,
147
+									struct via_param* const param,
148
+									const struct via_body* vb)
149 149
 {
150 150
 	char* tmp;
151 151
 	register unsigned char state;
... ...
@@ -1317,7 +1317,7 @@ normal_exit:
1317 1317
  * returns: pointer after the parsed parts and sets vb->error
1318 1318
  * WARNING: don't forget to cleanup on error with free_via_list(vb)!
1319 1319
  */
1320
-char* parse_via(char* buffer, char* end, struct via_body *vbody)
1320
+char* parse_via(char* buffer, const char* const end, struct via_body* const vbody)
1321 1321
 {
1322 1322
 	char* tmp;
1323 1323
 	char* param_start;
... ...
@@ -117,7 +117,7 @@ struct via_body {
117 117
 /*
118 118
  * Main Via header field parser
119 119
  */
120
-char* parse_via(char* buffer, char* end, struct via_body *vb);
120
+char* parse_via(char* buffer, const char* const end, struct via_body* const vbody);
121 121
 
122 122
 
123 123
 /*