Browse code

Stateless module added!

Bogdan-Andrei Iancu authored on 12/02/2002 16:48:34
Showing 9 changed files
... ...
@@ -60,14 +60,11 @@ ARCH = $(shell uname -m |sed -e s/i.86/i386/ -e s/sun4u/sparc64/ )
60 60
 DEFS+= -DNAME='"$(NAME)"' -DVERSION='"$(RELEASE)"' -DARCH='"$(ARCH)"' \
61 61
 	 -DOS='"$(OS)"' -DCOMPILER='"$(CC_VER)"'\
62 62
 	 -DDNS_IP_HACK  -DPKG_MALLOC -DSHM_MEM  -DSHM_MMAP \
63
-	 -DUSE_SYNONIM \
64
-	 -DF_MALLOC
65
-	# -DVQ_MALLOC
66
-	 #-DBRUT_HACK #-DEXTRA_DEBUG 
67
-	#-DEXTRA_DEBUG -DBRUT_HACK \
68
-	#-DVQ_MALLOC  -DDBG_LOCK  #-DSTATS
69
-	  #-DDBG_QM_MALLOC #-DVQ_MALLOC #-DNO_DEBUG
70
-	  #-DNO_DEBUG #-DDBG_QM_MALLOC
63
+	 -DUSE_SYNONIM -DVQ_MALLOC \
64
+	 #-DFAST_LOCK -Di386
65
+	 #-DEXTRA_DEBUG #-DSTATIC_TM
66
+	 #-DVQ_MALLOC  -DDBG_LOCK  #-DSTATS
67
+	 #-DDBG_QM_MALLOC #-DNO_DEBUG
71 68
 #-DEXTRA_DEBUG
72 69
 # -DUSE_SHM_MEM
73 70
 #-DNO_DEBUG
... ...
@@ -6,7 +6,7 @@
6 6
 #include "h_table.h"
7 7
 #include "../../dprint.h"
8 8
 #include "sh_malloc.h"
9
- #include "../../md5utils.h"
9
+#include "../../md5utils.h"
10 10
 
11 11
 /*   Frees the all the containes of a cell and the cell's body itself
12 12
   */
... ...
@@ -287,7 +287,6 @@ struct sip_msg*  sip_msg_cloner( struct sip_msg *org_msg )
287 287
       lump_anchor = &((*lump_anchor)->next);
288 288
       lump_chain = lump_chain->next;
289 289
    }
290
-   DBG("-----------> len=%d <---> written=%d\n",len,p-foo);
291 290
    return new_msg;
292 291
 }
293 292
 
... ...
@@ -658,7 +658,7 @@ int t_send_reply(  struct sip_msg* p_msg , unsigned int code , char * text )
658 658
 	}
659 659
 	*/
660 660
 
661
-	buf = build_res_buf_from_sip_req( code , text , T->inbound_request , &len );
661
+	buf = build_res_buf_from_sip_req(code,text,0,0,T->inbound_request,&len);
662 662
 	DBG("DEBUG: t_send_reply: buffer computed\n");
663 663
 	if (!buf)
664 664
 	{
... ...
@@ -676,7 +676,7 @@ int t_send_reply(  struct sip_msg* p_msg , unsigned int code , char * text )
676 676
 		{
677 677
 			LOG(L_ERR, "ERROR: t_send_reply: cannot lookup reply dst: %s\n",
678 678
 				p_msg->via1->host.s );
679
-			goto error;
679
+			goto error2;
680 680
 		}
681 681
 
682 682
 		rb->retr_timer.tg=TG_RT;
... ...
@@ -134,13 +134,9 @@ int t_lookup_request( struct sip_msg* p_msg , int leave_new_locked )
134 134
 			&& get_cseq(t_msg)->number.len==get_cseq(p_msg)->number.len
135 135
 			&& /*from length*/ EQ_LEN(from)
136 136
 			&& /*to body*/get_to(t_msg)->body.len==get_to(p_msg)->body.len
137
-			&& printf("------>0.4   %d (%d,%d)\n",p_cell->status,p_cell->tag->len,get_to(p_msg)->tag_value.len)
138 137
 			&& /*to tag*/p_cell->tag->len==get_to(p_msg)->tag_value.len
139
-			&& printf("------>0.5   %d\n",p_cell->status)
140 138
 			&& /*req URI*/(p_cell->status==200 || EQ_REQ_URI_LEN )
141
-			&& printf("------>0.6   %d\n",p_cell->status)
142
-			&& /*VIA*/(p_cell->status==200 || EQ_VIA_LEN(via1))
143
-			&& printf("------>2   %d\n",p_cell->status)  )
139
+			&& /*VIA*/(p_cell->status==200 || EQ_VIA_LEN(via1)) )
144 140
 				/* so far the lengths are the same
145 141
 				-> let's check the contents */
146 142
 				if (/*callid*/!memcmp( t_msg->callid->body.s,
... ...
@@ -152,10 +148,8 @@ int t_lookup_request( struct sip_msg* p_msg , int leave_new_locked )
152 152
 					get_to(p_msg)->body.s,get_to(t_msg)->body.len)
153 153
 				&& /*to tag*/!memcmp(p_cell->tag->s,
154 154
 					get_to(p_msg)->tag_value.s,p_cell->tag->len)
155
-				&& /*req URI*/(p_cell->status==200 || EQ_REQ_URI_STR||
156
-					printf("------>1   %d\n",p_cell->status) )
157
-				&& /*VAI*/(p_cell->status==200 ||EQ_VIA_STR(via1) ||
158
-						printf("------>2   %d\n",p_cell->status) ) )
155
+				&& /*req URI*/(p_cell->status==200 || EQ_REQ_URI_STR)
156
+				&& /*VAI*/(p_cell->status==200 ||EQ_VIA_STR(via1)) )
159 157
 					{ /* WE FOUND THE GOLDEN EGG !!!! */
160 158
 						goto found;
161 159
 					}
... ...
@@ -1,4 +1,4 @@
1 1
 #!/bin/sh
2 2
 
3
-ipcrm sem `ipcs -s |grep $(whoami) | awk '{ print $2; }'`
4
-ipcrm shm `ipcs -m | grep $(whoami) |awk '{ print $2; }'` 
3
+ipcrm sem `cat /proc/sysvipc/sem | awk '{ print $2; }'`
4
+ipcrm shm `cat /proc/sysvipc/shm | awk '{ print $2; }'` 
... ...
@@ -18,6 +18,18 @@
18 18
 #define MAX_RECEIVED_SIZE  57
19 19
 
20 20
 
21
+#define append_str(_dest,_src,_len,_msg) \
22
+	do{\
23
+		memcpy( (_dest) , (_src) , (_len) );\
24
+		(_dest) += (_len) ;\
25
+	}while(0);
26
+
27
+#define append_str_trans(_dest,_src,_len,_msg) \
28
+	do{\
29
+		memcpy( (_dest) , (_msg)->orig+((_src)-(_msg)->buf) , (_len) );\
30
+		(_dest) += (_len) ;\
31
+	}while(0);
32
+
21 33
 
22 34
 
23 35
 /* faster than inet_ntoa */
... ...
@@ -532,15 +544,14 @@ error:
532 532
 
533 533
 
534 534
 char * build_res_buf_from_sip_req(	unsigned int code ,
535
-	char *text , struct sip_msg* msg, unsigned int *returned_len)
535
+	char *text, char *new_tag, unsigned int new_tag_len,
536
+	struct sip_msg* msg, unsigned int *returned_len)
536 537
 {
537 538
 	char                    *buf, *p;
538 539
 	unsigned int       len,foo;
539 540
 	struct hdr_field  *hdr;
540 541
 	int                       i;
541
-#ifdef BRUT_HACK
542
-	struct hdr_field  *to, *from, *callid, *cseq, *via;
543
-#endif
542
+	str                        *tag_str;
544 543
 
545 544
 	/* force parsing all headers -- we want to return all
546 545
 	Via's in the reply and they may be scattered down to the
... ...
@@ -554,27 +565,24 @@ char * build_res_buf_from_sip_req(	unsigned int code ,
554 554
 	len += SIP_VERSION_LEN + 1/*space*/ + 3/*code*/ + 1/*space*/ + strlen(text) + CRLF_LEN/*new line*/;
555 555
 	/*headers that will be copied (TO, FROM, CSEQ,CALLID,VIA)*/
556 556
 	for ( hdr=msg->headers ; hdr ; hdr=hdr->next )
557
-#ifdef BRUT_HACK
558
-	{
559
-		len += ((hdr->body.s+hdr->body.len ) - hdr->name.s ) + CRLF_LEN;
560
-		if ( hdr->type==HDR_VIA ) via = hdr;
561
-		else if ( hdr->type==HDR_FROM) from = hdr;
562
-		else if (hdr->type==HDR_CALLID) callid = hdr;
563
-		else if ( hdr->type==HDR_TO) to = hdr;
564
-		else if ( hdr->type==HDR_CSEQ) cseq = hdr;
565
-		else len-=((hdr->body.s+hdr->body.len ) - hdr->name.s ) + CRLF_LEN;
566
-	}
567
-#else
568
-		if ( hdr->type==HDR_VIA || hdr->type==HDR_FROM ||
569
-				hdr->type==HDR_CALLID || hdr->type==HDR_TO ||
570
-				hdr->type==HDR_CSEQ )
571
-			len += ((hdr->body.s+hdr->body.len ) - hdr->name.s ) + CRLF_LEN;
572
-#endif
557
+		switch (hdr->type)
558
+		{
559
+			case HDR_TO:
560
+				if (new_tag)
561
+					if (get_to(msg)->tag_value.s )
562
+						len+=new_tag_len-get_to(msg)->tag_value.len;
563
+					else
564
+						len+=new_tag_len+5/*";tag="*/;
565
+			case HDR_VIA:
566
+			case HDR_FROM:
567
+			case HDR_CALLID:
568
+			case HDR_CSEQ:
569
+				len += ((hdr->body.s+hdr->body.len )-hdr->name.s )+CRLF_LEN;
570
+		}
573 571
 	/*content length header*/
574 572
 	len +=CONTENT_LEN_LEN + CRLF_LEN;
575 573
 	/* end of message */
576 574
 	len += CRLF_LEN; /*new line*/
577
-
578 575
 	/*allocating mem*/
579 576
 	buf = 0;
580 577
 	buf = (char*) malloc( len+1 );
... ...
@@ -600,32 +608,38 @@ char * build_res_buf_from_sip_req(	unsigned int code ,
600 600
 	memcpy( p, CRLF, CRLF_LEN );
601 601
 	p+=CRLF_LEN;
602 602
 	/* headers*/
603
-#ifdef BRUT_HACK
604
-#define	COPY_HF(_hf) memcpy(p, msg->orig+(_hf->name.s-msg->buf), \
605
-			((_hf->body.s+_hf->body.len ) - \
606
-			_hf->name.s )); \
607
-			p+=((_hf->body.s+_hf->body.len)-_hf->name.s ) ; \
608
-			memcpy( p, CRLF, CRLF_LEN ); \
609
-			p+=CRLF_LEN;
610
-
611
-	COPY_HF(via);
612
-	COPY_HF(from);
613
-	COPY_HF(to);
614
-	COPY_HF(callid);
615
-	COPY_HF(cseq);
616
-#else
617 603
 	for ( hdr=msg->headers ; hdr ; hdr=hdr->next )
618
-		if ( hdr->type==HDR_VIA || hdr->type==HDR_FROM ||
619
-		hdr->type==HDR_CALLID || hdr->type==HDR_TO || hdr->type==HDR_CSEQ )
604
+		switch (hdr->type)
620 605
 		{
621
-			memcpy( p , msg->orig+(hdr->name.s-msg->buf) ,
622
-					((hdr->body.s+hdr->body.len ) -
623
-					hdr->name.s ) );
624
-			p += ((hdr->body.s+hdr->body.len ) - hdr->name.s ) ;
625
-			memcpy( p, CRLF, CRLF_LEN );
626
-			p+=CRLF_LEN;
606
+			case HDR_TO:
607
+				if (new_tag){
608
+					if (get_to(msg)->tag_value.s ) {
609
+						tag_str =&(get_to(msg)->tag_value);
610
+						append_str_trans( p, hdr->name.s ,
611
+							tag_str->s-hdr->name.s,msg);
612
+						append_str( p, new_tag,new_tag_len,msg);
613
+						append_str_trans( p,tag_str->s+tag_str->len,
614
+							((hdr->body.s+hdr->body.len )-
615
+							(tag_str->s+tag_str->len)),msg);
616
+						append_str( p, CRLF,CRLF_LEN,msg);
617
+					}else{
618
+						append_str_trans( p, hdr->name.s ,
619
+							((hdr->body.s+hdr->body.len )-hdr->name.s ),
620
+							msg);
621
+						append_str( p, ";tag=",5,msg);
622
+						append_str( p, new_tag,new_tag_len,msg);
623
+						append_str( p, CRLF,CRLF_LEN,msg);
624
+					}
625
+				break;
626
+				}
627
+			case HDR_VIA:
628
+			case HDR_FROM:
629
+			case HDR_CALLID:
630
+			case HDR_CSEQ:
631
+				append_str_trans( p, hdr->name.s ,
632
+					((hdr->body.s+hdr->body.len )-hdr->name.s ),msg);
633
+				append_str( p, CRLF,CRLF_LEN,msg);
627 634
 		}
628
-#endif
629 635
 
630 636
 	/* content length header*/
631 637
 	memcpy( p, CONTENT_LEN , CONTENT_LEN_LEN );
... ...
@@ -16,8 +16,10 @@ char * build_req_buf_from_sip_req (	struct sip_msg* msg,
16 16
 char * build_res_buf_from_sip_res(	struct sip_msg* msg,
17 17
 				unsigned int *returned_len);
18 18
 
19
-char * build_res_buf_from_sip_req(	unsigned int code , 
19
+char * build_res_buf_from_sip_req(	unsigned int code ,
20 20
 				char *text ,
21
+				char *new_tag ,
22
+				unsigned int new_tag_len ,
21 23
 				struct sip_msg* msg,
22 24
 				unsigned int *returned_len);
23 25
 char* via_builder( 			struct sip_msg *msg ,
... ...
@@ -27,9 +27,14 @@ loop_checks=0
27 27
 loadmodule "modules/tm/tm.so"
28 28
 #loadmodule "modules/rr/rr.so"
29 29
 loadmodule "modules/maxfwd/maxfwd.so"
30
+loadmodule "modules/sl/sl.so"
30 31
 
31 32
 
32 33
 route{
34
+             if ( !sl_filter_ACK() ){
35
+                log("SER : error in sl_filter_ACK!\n");
36
+             };
37
+
33 38
              if ( mf_is_maxfwd_present() )
34 39
              {
35 40
                    if ( !mf_decrement_maxfwd() )
... ...
@@ -39,14 +44,18 @@ route{
39 39
                    if ( mf_is_maxfwd_zero() )
40 40
                    {
41 41
                      log("SER: MAX FORWARD header is zero\n");
42
+                     sl_send_reply("483","Too Many Hops");
42 43
                      drop();
43 44
                    };
44 45
              }else{
45 46
                    mf_add_maxfwd_header( "10" );
46 47
              };
47 48
 
49
+
48 50
              #if (method=="INVITE")
49 51
              #{
52
+                 #sl_send_reply("404","Not found");
53
+                 #drop();
50 54
               #  log("SER : runing CPL!! :)\n");
51 55
               #  if ( !cpl_run_script() )
52 56
                # {
... ...
@@ -63,19 +72,19 @@ route{
63 63
                # };
64 64
              #};
65 65
 
66
-             if ( !rewriteFromRoute() )
67
-             {
68
-                log( " SER : no route found!\n");
69
-                if ( method=="INVITE" )
70
-                {
71
-                   log ("SER : INVITE found - > adding RecordRoute!\n");
72
-                   addRecordRoute();
73
-                };
74
-             }
75
-             else
76
-             {
77
-                log( "SER : ROUTE found! \n");
78
-             };
66
+           #  if ( !rewriteFromRoute() )
67
+            # {
68
+                #log( " SER : no route found!\n");
69
+                #if ( method=="INVITE" )
70
+                #{
71
+                  # log ("SER : INVITE found - > adding RecordRoute!\n");
72
+                   #addRecordRoute();
73
+                #};
74
+             #}
75
+             #else
76
+             #{
77
+                #log( "SER : ROUTE found! \n");
78
+             #};
79 79
 
80 80
              t_relay();
81 81
 }