Browse code

parse_hname2 identify now also Content-Type and Content-Length

Bogdan-Andrei Iancu authored on 22/05/2002 12:24:24
Showing 7 changed files
... ...
@@ -10,7 +10,7 @@ auto_gen=lex.yy.c cfg.tab.c   #lexx, yacc etc
10 10
 #include  source related defs
11 11
 include Makefile.sources
12 12
 
13
-exclude_modules=CVS 
13
+exclude_modules=CVS mysql 
14 14
 #mysql auth rr
15 15
 static_modules=
16 16
 static_modules_path=$(addprefix modules/, $(static_modules))
... ...
@@ -227,7 +227,6 @@ char* get_hdr_field(char* buf, char* end, struct hdr_field* hdr)
227 227
 				goto error;
228 228
 			}
229 229
 			memset(vb,0,sizeof(struct via_body));
230
-
231 230
 			hdr->body.s=tmp;
232 231
 			tmp=parse_via(tmp, end, vb);
233 232
 			if (vb->error==VIA_PARSE_ERROR){
... ...
@@ -279,17 +278,18 @@ char* get_hdr_field(char* buf, char* end, struct hdr_field* hdr)
279 278
 				hdr->name.s, hdr->body.len, to_b->uri.len,to_b->uri.s);
280 279
 			DBG("DEBUG: to body [%.*s]\n",to_b->body.len,to_b->body.s);
281 280
 			break;
281
+		case HDR_CONTENTTYPE:
282
+		case HDR_CONTENTLENGTH:
282 283
 		case HDR_FROM:
283 284
 		case HDR_CALLID:
284 285
 		case HDR_CONTACT:
285 286
 		case HDR_ROUTE:   /* janakj, HDR_ROUTE was missing here */
286
-	        case HDR_RECORDROUTE:
287
+		case HDR_RECORDROUTE:
287 288
 		case HDR_MAXFORWARDS:
288 289
 		case HDR_OTHER:
289 290
 			/* just skip over it */
290 291
 			hdr->body.s=tmp;
291 292
 			/* find end of header */
292
-
293 293
 			/* find lf */
294 294
 			do{
295 295
 				match=q_memchr(tmp, '\n', end-tmp);
... ...
@@ -312,7 +312,6 @@ char* get_hdr_field(char* buf, char* end, struct hdr_field* hdr)
312 312
 					hdr->type);
313 313
 			goto error;
314 314
 	}
315
-
316 315
 	/* jku: if \r covered by current length, shrink it */
317 316
 	trim_r( hdr->body );
318 317
 	return tmp;
... ...
@@ -636,6 +635,14 @@ int parse_headers(struct sip_msg* msg, int flags)
636 635
 				if (msg->record_route==0) msg->record_route = hf;
637 636
 				msg->parsed_flag|=HDR_RECORDROUTE;
638 637
 				break;
638
+			case HDR_CONTENTTYPE:
639
+				if (msg->content_type==0) msg->content_type = hf;
640
+				msg->parsed_flag|=HDR_CONTENTTYPE;
641
+				break;
642
+			case HDR_CONTENTLENGTH:
643
+				if (msg->content_length==0) msg->content_length = hf;
644
+				msg->parsed_flag|=HDR_CONTENTLENGTH;
645
+				break;
639 646
 			case HDR_VIA:
640 647
 				msg->parsed_flag|=HDR_VIA;
641 648
 				DBG("parse_headers: Via found, flags=%d\n", flags);
... ...
@@ -16,20 +16,22 @@
16 16
 
17 17
 
18 18
 /*header types and flags*/
19
-#define HDR_EOH           -1
20
-#define HDR_ERROR          0
21
-#define HDR_VIA            1
22
-#define HDR_VIA1           1
23
-#define HDR_VIA2           2  /*only used as flag*/
24
-#define HDR_TO             4
25
-#define HDR_FROM           8
26
-#define HDR_CSEQ          16
27
-#define HDR_CALLID        32
28
-#define HDR_CONTACT       64
29
-#define HDR_MAXFORWARDS  128
30
-#define HDR_ROUTE        256
31
-#define HDR_RECORDROUTE  512
32
-#define HDR_OTHER       65536 /*unknown header type*/
19
+#define HDR_EOH             -1
20
+#define HDR_ERROR            0
21
+#define HDR_VIA              1
22
+#define HDR_VIA1             1
23
+#define HDR_VIA2             2  /*only used as flag*/
24
+#define HDR_TO               4
25
+#define HDR_FROM             8
26
+#define HDR_CSEQ            16
27
+#define HDR_CALLID          32
28
+#define HDR_CONTACT         64
29
+#define HDR_MAXFORWARDS    128
30
+#define HDR_ROUTE          256
31
+#define HDR_RECORDROUTE    512
32
+#define HDR_CONTENTTYPE   1024
33
+#define HDR_CONTENTLENGTH 2048
34
+#define HDR_OTHER        65536 /*unknown header type*/
33 35
 
34 36
 
35 37
 /* maximum length of values appended to Via-branch parameter */
... ...
@@ -192,6 +194,8 @@ struct sip_msg{
192 194
 	struct hdr_field* maxforwards;
193 195
 	struct hdr_field* route;
194 196
 	struct hdr_field* record_route;
197
+	struct hdr_field* content_type;
198
+	struct hdr_field* content_length;
195 199
 	char* eoh; /* pointer to the end of header (if found) or null */
196 200
 	char* unparsed; /* here we stopped parsing*/
197 201
 
... ...
@@ -139,8 +139,8 @@ static inline int unify(int key)
139 139
 #define From_CASE          \
140 140
      hdr->type = HDR_FROM; \
141 141
      p += 4;               \
142
-     goto dc_end          
143
-                                                             
142
+     goto dc_end
143
+
144 144
 
145 145
 #define To12_CASE        \
146 146
      hdr->type = HDR_TO; \
... ...
@@ -189,6 +189,62 @@ static inline int unify(int key)
189 189
      break
190 190
 
191 191
 
192
+/* added by Bogdan - for Content-Type and -Length headers */
193
+#define Ent__CASE \
194
+	p += 4;\
195
+	val = READ(p);\
196
+	switch(val) {\
197
+	case xType:\
198
+		hdr->type = HDR_CONTENTTYPE;\
199
+		p += 4;\
200
+		goto dc_end;\
201
+	case Leng:\
202
+		p += 4;\
203
+		val = READ(p);\
204
+		if (val==th12){\
205
+			hdr->type = HDR_CONTENTLENGTH;\
206
+			hdr->name.len = 14;\
207
+			*(p + 2) = '\0';\
208
+			return (p + 3);\
209
+		}\
210
+		val = unify(val);\
211
+		if (val==th12){\
212
+			hdr->type = HDR_CONTENTLENGTH;\
213
+			hdr->name.len = 14;\
214
+			*(p + 2) = '\0';\
215
+			return (p + 3);\
216
+		}else\
217
+			goto other;\
218
+	}\
219
+	val = unify(val);\
220
+	switch(val) {\
221
+	case xType:\
222
+		hdr->type = HDR_CONTENTTYPE;\
223
+		p += 4;\
224
+		goto dc_end;\
225
+	case Leng:\
226
+		p += 4;\
227
+		val = READ(p);\
228
+		if (val==th12){\
229
+			hdr->type = HDR_CONTENTLENGTH;\
230
+			hdr->name.len = 14;\
231
+			*(p + 2) = '\0';\
232
+			return (p + 3);\
233
+		}\
234
+		val = unify(val);\
235
+		if (val==th12){\
236
+			hdr->type = HDR_CONTENTLENGTH;\
237
+			hdr->name.len = 14;\
238
+			*(p + 2) = '\0';\
239
+			return (p + 3);\
240
+		}else\
241
+			goto other;\
242
+	default:\
243
+		goto other;\
244
+	}\
245
+	break
246
+
247
+
192 248
 #define Cont_CASE                     \
193 249
      p += 4;                          \
194 250
      val = READ(p);                   \
... ...
@@ -203,6 +259,9 @@ static inline int unify(int key)
203 259
 	     hdr->type = HDR_CONTACT; \
204 260
 	     p += 4;                  \
205 261
 	     goto dc_end;             \
262
+	                              \
263
+     case ent_:                   \
264
+	     Ent__CASE;               \
206 265
      }                                \
207 266
                                       \
208 267
      val = unify(val);                \
... ...
@@ -217,7 +276,8 @@ static inline int unify(int key)
217 276
 	     hdr->type = HDR_CONTACT; \
218 277
 	     p += 4;                  \
219 278
 	     goto dc_end;             \
220
-                                      \
279
+                                  \
280
+                                  \
221 281
      default: goto other;             \
222 282
      }                                \
223 283
      break
... ...
@@ -363,7 +423,7 @@ char* parse_hname2(char* begin, char* end, struct hdr_field* hdr)
363 423
 	case Rout: Rout_CASE;
364 424
 	case Max_: Max_CASE;
365 425
 	case Reco: Reco_CASE;
366
-        case Via2: Via2_CASE;
426
+	case Via2: Via2_CASE;
367 427
 
368 428
 	default:
369 429
 		switch(*p) {
... ...
@@ -447,6 +507,38 @@ char* parse_hname2(char* begin, char* end, struct hdr_field* hdr)
447 507
 				return (p + 2);
448 508
 			}
449 509
 			break;
510
+
511
+        case 'C':
512
+		case 'c':
513
+			switch(*(p + 1)) {
514
+			case ' ':
515
+				hdr->type = HDR_CONTENTTYPE;
516
+				p += 2;
517
+				goto dc_end;
518
+				
519
+			case ':':
520
+				hdr->type = HDR_CONTENTTYPE;
521
+				hdr->name.len = 1;
522
+				*(p + 1) = '\0';
523
+				return (p + 2);
524
+			}
525
+			break;
526
+
527
+        case 'L':
528
+		case 'l':
529
+			switch(*(p + 1)) {
530
+			case ' ':
531
+				hdr->type = HDR_CONTENTLENGTH;
532
+				p += 2;
533
+				goto dc_end;
534
+				
535
+			case ':':
536
+				hdr->type = HDR_CONTENTLENGTH;
537
+				hdr->name.len = 1;
538
+				*(p + 1) = '\0';
539
+				return (p + 2);
540
+			}
541
+			break;
450 542
 		}
451 543
 		
452 544
 		val = unify(val);
... ...
@@ -454,10 +546,10 @@ char* parse_hname2(char* begin, char* end, struct hdr_field* hdr)
454 546
 		case Via1: Via1_CASE;
455 547
 		case From: From_CASE;
456 548
 		case To12: To12_CASE;
457
-		case CSeq: CSeq_CASE;                                                             
549
+		case CSeq: CSeq_CASE;
458 550
 		case Call: Call_CASE;
459 551
 		case Cont: Cont_CASE;
460
-		case Rout: Rout_CASE;                                                             
552
+		case Rout: Rout_CASE;
461 553
 		case Max_: Max_CASE;
462 554
 		case Reco: Reco_CASE;
463 555
 		case Via2: Via2_CASE;
... ...
@@ -512,16 +604,16 @@ void init_htable(void)
512 604
 		set_entry(HASH_EMPTY, HASH_EMPTY);
513 605
 	}
514 606
 
515
-        set_entry(via1, Via1);
607
+	set_entry(via1, Via1);
516 608
 	set_entry(viA1, Via1);
517 609
 	set_entry(vIa1, Via1);
518
-        set_entry(vIA1, Via1);
519
-        set_entry(Via1, Via1);
520
-        set_entry(ViA1, Via1);
610
+	set_entry(vIA1, Via1);
611
+	set_entry(Via1, Via1);
612
+	set_entry(ViA1, Via1);
521 613
 	set_entry(VIa1, Via1);
522 614
 	set_entry(VIA1, Via1);
523 615
 	
524
-        set_entry(via2, Via2);
616
+	set_entry(via2, Via2);
525 617
 	set_entry(viA2, Via2);
526 618
 	set_entry(vIa2, Via2);
527 619
 	set_entry(vIA2, Via2);
... ...
@@ -738,6 +830,61 @@ void init_htable(void)
738 830
 	set_entry(OUtE, oute);
739 831
 	set_entry(OUTe, oute);
740 832
 	set_entry(OUTE, oute);
833
+
834
+	set_entry(ent_, ent_);
835
+    set_entry(enT_, ent_);
836
+	set_entry(eNt_, ent_);
837
+	set_entry(eNT_, ent_);
838
+	set_entry(Ent_, ent_);
839
+	set_entry(EnT_, ent_);
840
+	set_entry(ENt_, ent_);
841
+	set_entry(ENT_, ent_);
842
+
843
+	set_entry(xtype, xType);
844
+	set_entry(xtypE, xType);
845
+	set_entry(xtyPe, xType);
846
+	set_entry(xtyPE, xType);
847
+	set_entry(xtYpe, xType);
848
+	set_entry(xtYpE, xType);
849
+	set_entry(xtYPe, xType);
850
+	set_entry(xtYPE, xType);
851
+	set_entry(xType, xType);
852
+	set_entry(xTypE, xType);
853
+	set_entry(xTyPe, xType);
854
+	set_entry(xTyPE, xType);
855
+	set_entry(xTYpe, xType);
856
+	set_entry(xTYpE, xType);
857
+	set_entry(xTYPe, xType);
858
+	set_entry(xTYPE, xType);
859
+
860
+
861
+	set_entry(leng, Leng);
862
+	set_entry(lenG, Leng);
863
+	set_entry(leNg, Leng);
864
+	set_entry(leNG, Leng);
865
+	set_entry(lEng, Leng);
866
+	set_entry(lEnG, Leng);
867
+	set_entry(lENg, Leng);
868
+	set_entry(lENG, Leng);
869
+	set_entry(Leng, Leng);
870
+	set_entry(LenG, Leng);
871
+	set_entry(LeNg, Leng);
872
+	set_entry(LeNG, Leng);
873
+	set_entry(LEng, Leng);
874
+	set_entry(LEnG, Leng);
875
+	set_entry(LENg, Leng);
876
+	set_entry(LENG, Leng);
877
+
878
+	set_entry(th12, th12);
879
+	set_entry(tH12, th12);
880
+	set_entry(Th12, th12);
881
+	set_entry(TH12, th12);
882
+
883
+	set_entry(th21, th21);
884
+	set_entry(tH21, th21);
885
+	set_entry(Th21, th21);
886
+	set_entry(TH21, th21);
887
+	
741 888
 }
742 889
 
743 890
 
... ...
@@ -228,4 +228,60 @@
228 228
 #define OUTe 0x6554554f   /* "OUTe" */
229 229
 #define OUTE 0x4554554f   /* "OUTE" */
230 230
 
231
+
232
+#define ent_ 0x2d746e65   /* "ent-" */
233
+#define enT_ 0x2d546e65   /* "enT-" */
234
+#define eNt_ 0x2d744e65   /* "eNt-" */
235
+#define eNT_ 0x2d544e65   /* "eNT-" */
236
+#define Ent_ 0x2d746e45   /* "Ent-" */
237
+#define EnT_ 0x2d546e45   /* "EnT-" */
238
+#define ENt_ 0x2d744e45   /* "ENt-" */
239
+#define ENT_ 0x2d544e45   /* "ENT-" */
240
+
241
+#define xtype 0x65707974   /* "type" */
242
+#define xtypE 0x45707974   /* "typE" */
243
+#define xtyPe 0x65507974   /* "tyPe" */
244
+#define xtyPE 0x45507974   /* "tyPE" */
245
+#define xtYpe 0x65705974   /* "tYpe" */
246
+#define xtYpE 0x45705974   /* "tYpE" */
247
+#define xtYPe 0x65505974   /* "tYPe" */
248
+#define xtYPE 0x45505974   /* "tYPE" */
249
+#define xType 0x65707954   /* "Type" */
250
+#define xTypE 0x45707954   /* "TypE" */
251
+#define xTyPe 0x65507954   /* "TyPe" */
252
+#define xTyPE 0x45507954   /* "TyPE" */
253
+#define xTYpe 0x65705954   /* "TYpe" */
254
+#define xTYpE 0x45705954   /* "TYpE" */
255
+#define xTYPe 0x65505954   /* "TYPe" */
256
+#define xTYPE 0x45505954   /* "TYPE" */
257
+
258
+#define leng 0x676e656c   /* "leng" */
259
+#define lenG 0x476e656c   /* "lenG" */
260
+#define leNg 0x674e656c   /* "leNg" */
261
+#define leNG 0x474e656c   /* "leNG" */
262
+#define lEng 0x676e456c   /* "lEng" */
263
+#define lEnG 0x476e456c   /* "lEnG" */
264
+#define lENg 0x674e456c   /* "lENg" */
265
+#define lENG 0x474e456c   /* "lENG" */
266
+#define Leng 0x676e654c   /* "Leng" */
267
+#define LenG 0x476e654c   /* "LenG" */
268
+#define LeNg 0x674e654c   /* "LeNg" */
269
+#define LeNG 0x474e654c   /* "LeNG" */
270
+#define LEng 0x676e454c   /* "LEng" */
271
+#define LEnG 0x476e454c   /* "LEnG" */
272
+#define LENg 0x674e454c   /* "LENg" */
273
+#define LENG 0x474e454c   /* "LENG" */
274
+
275
+#define th12 0x203a6874   /* "th: " */
276
+#define tH12 0x203a4874   /* "tH: " */
277
+#define Th12 0x203a6854   /* "Th: " */
278
+#define TH12 0x203a4854   /* "TH: " */
279
+
280
+#define th21 0x3a206874   /* "th :" */
281
+#define tH21 0x3a204874   /* "tH :" */
282
+#define Th21 0x3a206854   /* "Th :" */
283
+#define TH21 0x3a204854   /* "TH :" */
284
+
285
+
231 286
 #endif
287
+
... ...
@@ -1,7 +1,7 @@
1 1
 INVITE sip:p2@195.37.78.126 SIP/2.0
2 2
 Via: SIP/2.0/UDP 192.168.99.100:5040
3 3
 From: "GMD FOKUS iptlab" <sip:jiri@iptel.org>;tag=b96b0300ed30f1286-2f5d
4
-To: <sip:p2@iptel.org>
4
+To:<sip:p2@iptel.org>
5 5
 Call-ID: b96b0300-88d30f-66da-63aa@195.37.78.190
6 6
 CSeq: 101 INVITE
7 7
 Expires: 180
... ...
@@ -23,12 +23,13 @@ loop_checks=0
23 23
 # for more info: sip_router -h
24 24
 
25 25
 #modules
26
-#loadmodule "modules/print/print.so"
26
+loadmodule "modules/print/print.so"
27 27
 loadmodule "modules/textops/textops.so"
28 28
 loadmodule "modules/tm/tm.so"
29 29
 #loadmodule "modules/rr/rr.so"
30 30
 loadmodule "modules/maxfwd/maxfwd.so"
31 31
 loadmodule "modules/sl/sl.so"
32
+loadmodule "modules/sms/sms.so"
32 33
 #loadmodule "modules/cpl/cpl.so"
33 34
 
34 35
 
... ...
@@ -73,6 +74,25 @@ route{
73 74
 	{
74 75
 		t_fork_to_uri("sip:bogdan@iptel.org");
75 76
 	};
76
-*/	
77
+*/
78
+
79
+	if (uri=="sip:sms@iptel.org")
80
+	{
81
+		if (method=="MESSAGE")
82
+		{
83
+			log("MESSAGE received -> sending as sms\n");
84
+			if (sms_send_message())
85
+			{
86
+				sl_send_reply("202","Accepted");
87
+			}else{
88
+				sl_send_reply("502","Bad gateway");
89
+			};
90
+		}else{
91
+			log("NON_Message request received for sms gateway->dropt!\n");
92
+			sl_send_reply("501","Not implemented");
93
+		};
94
+		break;
95
+	};
96
+
77 97
 	t_relay();
78 98
 }