Browse code

- added cseq_body and prototype cseq parser - fixed some missing #ifdef STATS

Andrei Pelinescu-Onciul authored on 23/11/2001 00:47:19
Showing 6 changed files
... ...
@@ -28,7 +28,7 @@ NAME=ser
28 28
 # DEBUG compiles in some extra debugging code
29 29
 # OLD_PARSER uses the old and stable parser (from ser 8.3.2)
30 30
 # DNS_IP_HACK faster ip address resolver for ip strings (e.g "127.0.0.1")
31
-DEFS=-DNOCR -DMACROEATER -DSTATS -DDNS_IP_HACK #-DNO_DEBUG 
31
+DEFS=-DNOCR -DMACROEATER -DDNS_IP_HACK #-DSTATS -DNO_DEBUG 
32 32
 #-DNO_LOG
33 33
 
34 34
 PROFILE=  # -pg #set this if you want profiling
... ...
@@ -2,6 +2,7 @@ $Id$
2 2
 
3 3
 ( - todo, x - done)
4 4
 
5
+- fix parse_cseq!!! (it doesnt parse 1234\n INVITE a.s.o)
5 6
 - better Via parsing (handle ' ' in uri, eg: foo.bar : 1234 ; received=) and
6 7
  ipv6 addresses ([fec0:aa::01]).
7 8
 - fix format string vulnerability in log()
... ...
@@ -149,7 +149,11 @@ assign_stm:	DEBUG EQUAL NUMBER { debug=$3; }
149 149
 		| REV_DNS EQUAL NUMBER { received_dns|= ($3)?DO_REV_DNS:0; }
150 150
 		| REV_DNS EQUAL error { yyerror("boolean value expected"); }
151 151
 		| PORT EQUAL NUMBER   { port_no=$3; }
152
-		| STAT EQUAL STRING { stat_file=$3; }
152
+		| STAT EQUAL STRING {
153
+					#ifdef STATS
154
+							stat_file=$3;
155
+					#endif
156
+							}
153 157
 		| MAXBUFFER EQUAL NUMBER { maxbuffer=$3; }
154 158
 		| MAXBUFFER EQUAL error { yyerror("number expected"); }
155 159
 		| PORT EQUAL error    { yyerror("number expected"); } 
... ...
@@ -288,7 +288,9 @@ static void sig_usr(int signo)
288 288
 		DPrint("Thank you for flying ser\n");
289 289
 		exit(0);
290 290
 	} else if (signo==SIGUSR1) { /* statistic */
291
+#ifdef STATS
291 292
 		dump_all_statistic();
293
+#endif
292 294
 	}
293 295
 }
294 296
 	
... ...
@@ -329,7 +331,9 @@ int main(int argc, char** argv)
329 329
 					cfg_file=optarg;
330 330
 					break;
331 331
 			case 's':
332
+				#ifdef STATS
332 333
 					stat_file=optarg;
334
+				#endif
333 335
 					break;
334 336
 			case 'p':
335 337
 					port_no=strtol(optarg, &tmp, 10);
... ...
@@ -209,6 +209,7 @@ char* get_hdr_field(char* buf, char* end, struct hdr_field* hdr)
209 209
 	char* tmp;
210 210
 	char *match;
211 211
 	struct via_body *vb;
212
+	struct cseq_body* cseq_b;
212 213
 
213 214
 	if ((*buf)=='\n' || (*buf)=='\r'){
214 215
 		/* double crlf or lflf or crcr */
... ...
@@ -241,12 +242,29 @@ char* get_hdr_field(char* buf, char* end, struct hdr_field* hdr)
241 241
 			hdr->parsed=vb;
242 242
 			vb->hdr.s=hdr->name.s;
243 243
 			vb->hdr.len=hdr->name.len;
244
-			/*vb->size=tmp-hdr->name.s;*/
245 244
 			hdr->body.len=tmp-hdr->body.s;
246 245
 			break;
246
+		case HDR_CSEQ:
247
+			cseq_b=malloc(sizeof(struct cseq_body));
248
+			if (cseq_b==0){
249
+				LOG(L_ERR, "get_hdr_field: out of memory\n");
250
+				goto error;
251
+			}
252
+			memset(cseq_b, 0, sizeof(struct cseq_body));
253
+			hdr->body.s=tmp;
254
+			tmp=parse_cseq(tmp, end, cseq_b);
255
+			if (cseq_b->error==PARSE_ERROR){
256
+				LOG(L_ERR, "ERROR: get_hdr_field: bad cseq\n");
257
+				free(cseq_b);
258
+				goto error;
259
+			}
260
+			hdr->parsed=cseq_b;
261
+			hdr->body.len=tmp-hdr->body.s;
262
+			DBG("get_hdr_field: cseq <%s>: <%s> <%s>\n",
263
+					hdr->name.s, cseq_b->number.s, cseq_b->method.s);
264
+			break;
247 265
 		case HDR_TO:
248 266
 		case HDR_FROM:
249
-		case HDR_CSEQ:
250 267
 		case HDR_CALLID:
251 268
 		case HDR_CONTACT:
252 269
 		case HDR_OTHER:
... ...
@@ -268,7 +286,8 @@ char* get_hdr_field(char* buf, char* end, struct hdr_field* hdr)
268 268
 				#endif
269 269
 				}else {
270 270
 					tmp=end;
271
-					LOG(L_ERR, "ERROR: get_hdr_field: bad body for <%s>(%d)\n",
271
+					LOG(L_ERR,
272
+							"ERROR: get_hdr_field: bad body for <%s>(%d)\n",
272 273
 							hdr->name.s, hdr->type);
273 274
 					goto error;
274 275
 				}
... ...
@@ -402,6 +421,54 @@ char* parse_hostport(char* buf, str* host, short int* port)
402 402
 
403 403
 
404 404
 
405
+/*BUGGY*/
406
+char * parse_cseq(char *buf, char* end, struct cseq_body* cb)
407
+{
408
+	char *t;
409
+	char c;
410
+
411
+	cb->error=PARSE_ERROR;
412
+	t=eat_space_end(buf, end);
413
+	if (t>=end) goto error;
414
+	
415
+	cb->number.s=t;
416
+	t=eat_token_end(t, end);
417
+	if (t>=end) goto error;
418
+	*t=0; /*null terminate it*/
419
+	cb->number.len=t-cb->number.s;
420
+	t++;
421
+	t=eat_space_end(t, end);
422
+	if (t>=end) goto error;
423
+	cb->method.s=t;
424
+	t=eat_token_end(t, end);
425
+	if (t>=end) goto error;
426
+	c=*t;
427
+	*t=0; /*null terminate it*/
428
+	cb->method.len=t-cb->method.s;
429
+	t++;
430
+	/*check if the header ends here*/
431
+	if (c=='\n') goto check_continue;
432
+	do{
433
+		for (;(t<end)&&((*t==' ')||(*t=='\t')||(*t=='\r'));t++);
434
+		if (t>=end) goto error;
435
+		if (*t!='\n'){
436
+			LOG(L_ERR, "ERROR:parse_cseq: unexpected char <%c> at end of"
437
+					" cseq\n", *t);
438
+			goto error;
439
+		}
440
+		t++;
441
+check_continue:
442
+	}while( (t<end) && ((*t==' ')||(*t=='\t')) );
443
+
444
+	cb->error=PARSE_OK;
445
+	return t;
446
+error:
447
+	LOG(L_ERR, "ERROR: parse_cseq: bad cseq\n");
448
+	return t;
449
+}
450
+
451
+
452
+
405 453
 /* buf= pointer to begining of uri (sip:x@foo.bar:5060;a=b?h=i)
406 454
    len= len of uri
407 455
 returns: fills uri & returns <0 on error or 0 if ok */
... ...
@@ -957,6 +1024,9 @@ void clean_hdr_field(struct hdr_field* hf)
957 957
 			case HDR_VIA:
958 958
 				free_via_list(hf->parsed);
959 959
 				break;
960
+			case HDR_CSEQ:
961
+				free(hf->parsed);
962
+				break;
960 963
 			default:
961 964
 				LOG(L_CRIT, "BUG: clean_hdr_field: unknown header type %d\n",
962 965
 						hf->type);
... ...
@@ -48,6 +48,8 @@ if (  (*tmp==(firstchar) || *tmp==((firstchar) | 32)) &&                  \
48 48
 
49 49
 #define VIA_PARSE_OK	1
50 50
 #define VIA_PARSE_ERROR -1
51
+#define PARSE_ERROR -1
52
+#define PARSE_OK 1
51 53
 
52 54
 #define SIP_VERSION	"SIP/2.0"
53 55
 #define SIP_VERSION_LEN 7
... ...
@@ -95,6 +97,16 @@ struct via_body{  /* format: name/version/transport host:port;params comment */
95 95
 							  compact via or null */
96 96
 };
97 97
 
98
+
99
+
100
+struct cseq_body{
101
+	int error;
102
+	str number;
103
+	str method;
104
+};
105
+
106
+
107
+
98 108
 struct sip_msg{
99 109
 	unsigned int id; /* message id, unique/process*/
100 110
 	struct msg_start first_line;
... ...
@@ -155,12 +167,15 @@ char* parse_via_body(char* buffer,unsigned int len, struct via_body * vb);
155 155
 #endif
156 156
 int parse_msg(char* buf, unsigned int len, struct sip_msg* msg);
157 157
 int parse_uri(char *buf, int len, struct sip_uri* uri);
158
+int parse_headers(struct sip_msg* msg, int flags);
159
+
158 160
 void free_uri(struct sip_uri* u);
159 161
 
160 162
 
161 163
 #ifndef OLD_PARSER
162 164
 char* parse_hname(char* buf, char* end, struct hdr_field* hdr);
163 165
 char* parse_via(char* buffer, char* end, struct via_body *vb);
166
+char* parse_cseq(char* buffer, char* end, struct cseq_body *cb);
164 167
 #endif
165 168
 
166 169
 void free_via_list(struct via_body *vb);