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 331
 					cfg_file=optarg;
330 332
 					break;
331 333
 			case 's':
334
+				#ifdef STATS
332 335
 					stat_file=optarg;
336
+				#endif
333 337
 					break;
334 338
 			case 'p':
335 339
 					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 242
 			hdr->parsed=vb;
242 243
 			vb->hdr.s=hdr->name.s;
243 244
 			vb->hdr.len=hdr->name.len;
244
-			/*vb->size=tmp-hdr->name.s;*/
245 245
 			hdr->body.len=tmp-hdr->body.s;
246 246
 			break;
247
+		case HDR_CSEQ:
248
+			cseq_b=malloc(sizeof(struct cseq_body));
249
+			if (cseq_b==0){
250
+				LOG(L_ERR, "get_hdr_field: out of memory\n");
251
+				goto error;
252
+			}
253
+			memset(cseq_b, 0, sizeof(struct cseq_body));
254
+			hdr->body.s=tmp;
255
+			tmp=parse_cseq(tmp, end, cseq_b);
256
+			if (cseq_b->error==PARSE_ERROR){
257
+				LOG(L_ERR, "ERROR: get_hdr_field: bad cseq\n");
258
+				free(cseq_b);
259
+				goto error;
260
+			}
261
+			hdr->parsed=cseq_b;
262
+			hdr->body.len=tmp-hdr->body.s;
263
+			DBG("get_hdr_field: cseq <%s>: <%s> <%s>\n",
264
+					hdr->name.s, cseq_b->number.s, cseq_b->method.s);
265
+			break;
247 266
 		case HDR_TO:
248 267
 		case HDR_FROM:
249
-		case HDR_CSEQ:
250 268
 		case HDR_CALLID:
251 269
 		case HDR_CONTACT:
252 270
 		case HDR_OTHER:
... ...
@@ -268,7 +286,8 @@ char* get_hdr_field(char* buf, char* end, struct hdr_field* hdr)
268 286
 				#endif
269 287
 				}else {
270 288
 					tmp=end;
271
-					LOG(L_ERR, "ERROR: get_hdr_field: bad body for <%s>(%d)\n",
289
+					LOG(L_ERR,
290
+							"ERROR: get_hdr_field: bad body for <%s>(%d)\n",
272 291
 							hdr->name.s, hdr->type);
273 292
 					goto error;
274 293
 				}
... ...
@@ -402,6 +421,54 @@ char* parse_hostport(char* buf, str* host, short int* port)
402 421
 
403 422
 
404 423
 
424
+/*BUGGY*/
425
+char * parse_cseq(char *buf, char* end, struct cseq_body* cb)
426
+{
427
+	char *t;
428
+	char c;
429
+
430
+	cb->error=PARSE_ERROR;
431
+	t=eat_space_end(buf, end);
432
+	if (t>=end) goto error;
433
+	
434
+	cb->number.s=t;
435
+	t=eat_token_end(t, end);
436
+	if (t>=end) goto error;
437
+	*t=0; /*null terminate it*/
438
+	cb->number.len=t-cb->number.s;
439
+	t++;
440
+	t=eat_space_end(t, end);
441
+	if (t>=end) goto error;
442
+	cb->method.s=t;
443
+	t=eat_token_end(t, end);
444
+	if (t>=end) goto error;
445
+	c=*t;
446
+	*t=0; /*null terminate it*/
447
+	cb->method.len=t-cb->method.s;
448
+	t++;
449
+	/*check if the header ends here*/
450
+	if (c=='\n') goto check_continue;
451
+	do{
452
+		for (;(t<end)&&((*t==' ')||(*t=='\t')||(*t=='\r'));t++);
453
+		if (t>=end) goto error;
454
+		if (*t!='\n'){
455
+			LOG(L_ERR, "ERROR:parse_cseq: unexpected char <%c> at end of"
456
+					" cseq\n", *t);
457
+			goto error;
458
+		}
459
+		t++;
460
+check_continue:
461
+	}while( (t<end) && ((*t==' ')||(*t=='\t')) );
462
+
463
+	cb->error=PARSE_OK;
464
+	return t;
465
+error:
466
+	LOG(L_ERR, "ERROR: parse_cseq: bad cseq\n");
467
+	return t;
468
+}
469
+
470
+
471
+
405 472
 /* buf= pointer to begining of uri (sip:x@foo.bar:5060;a=b?h=i)
406 473
    len= len of uri
407 474
 returns: fills uri & returns <0 on error or 0 if ok */
... ...
@@ -957,6 +1024,9 @@ void clean_hdr_field(struct hdr_field* hf)
957 1024
 			case HDR_VIA:
958 1025
 				free_via_list(hf->parsed);
959 1026
 				break;
1027
+			case HDR_CSEQ:
1028
+				free(hf->parsed);
1029
+				break;
960 1030
 			default:
961 1031
 				LOG(L_CRIT, "BUG: clean_hdr_field: unknown header type %d\n",
962 1032
 						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 97
 							  compact via or null */
96 98
 };
97 99
 
100
+
101
+
102
+struct cseq_body{
103
+	int error;
104
+	str number;
105
+	str method;
106
+};
107
+
108
+
109
+
98 110
 struct sip_msg{
99 111
 	unsigned int id; /* message id, unique/process*/
100 112
 	struct msg_start first_line;
... ...
@@ -155,12 +167,15 @@ char* parse_via_body(char* buffer,unsigned int len, struct via_body * vb);
155 167
 #endif
156 168
 int parse_msg(char* buf, unsigned int len, struct sip_msg* msg);
157 169
 int parse_uri(char *buf, int len, struct sip_uri* uri);
170
+int parse_headers(struct sip_msg* msg, int flags);
171
+
158 172
 void free_uri(struct sip_uri* u);
159 173
 
160 174
 
161 175
 #ifndef OLD_PARSER
162 176
 char* parse_hname(char* buf, char* end, struct hdr_field* hdr);
163 177
 char* parse_via(char* buffer, char* end, struct via_body *vb);
178
+char* parse_cseq(char* buffer, char* end, struct cseq_body *cb);
164 179
 #endif
165 180
 
166 181
 void free_via_list(struct via_body *vb);