瀏覽代碼

Stateless module added!

Bogdan-Andrei Iancu 23 年之前
父節點
當前提交
340bddb4aa
共有 9 個文件被更改,包括 96 次插入81 次删除
  1. 5 8
      Makefile.defs
  2. 1 1
      modules/tm/h_table.c
  3. 0 1
      modules/tm/sip_msg.c
  4. 2 2
      modules/tm/t_funcs.c
  5. 3 9
      modules/tm/t_lookup.c
  6. 2 2
      modules/tm/test/kill_sem.sh
  7. 58 44
      msg_translator.c
  8. 3 1
      msg_translator.h
  9. 22 13
      test/th-uri.cfg

+ 5 - 8
Makefile.defs

@@ -60,14 +60,11 @@ ARCH = $(shell uname -m |sed -e s/i.86/i386/ -e s/sun4u/sparc64/ )
 DEFS+= -DNAME='"$(NAME)"' -DVERSION='"$(RELEASE)"' -DARCH='"$(ARCH)"' \
 	 -DOS='"$(OS)"' -DCOMPILER='"$(CC_VER)"'\
 	 -DDNS_IP_HACK  -DPKG_MALLOC -DSHM_MEM  -DSHM_MMAP \
-	 -DUSE_SYNONIM \
-	 -DF_MALLOC
-	# -DVQ_MALLOC
-	 #-DBRUT_HACK #-DEXTRA_DEBUG 
-	#-DEXTRA_DEBUG -DBRUT_HACK \
-	#-DVQ_MALLOC  -DDBG_LOCK  #-DSTATS
-	  #-DDBG_QM_MALLOC #-DVQ_MALLOC #-DNO_DEBUG
-	  #-DNO_DEBUG #-DDBG_QM_MALLOC
+	 -DUSE_SYNONIM -DVQ_MALLOC \
+	 #-DFAST_LOCK -Di386
+	 #-DEXTRA_DEBUG #-DSTATIC_TM
+	 #-DVQ_MALLOC  -DDBG_LOCK  #-DSTATS
+	 #-DDBG_QM_MALLOC #-DNO_DEBUG
 #-DEXTRA_DEBUG
 # -DUSE_SHM_MEM
 #-DNO_DEBUG

+ 1 - 1
modules/tm/h_table.c

@@ -6,7 +6,7 @@
 #include "h_table.h"
 #include "../../dprint.h"
 #include "sh_malloc.h"
- #include "../../md5utils.h"
+#include "../../md5utils.h"
 
 /*   Frees the all the containes of a cell and the cell's body itself
   */

+ 0 - 1
modules/tm/sip_msg.c

@@ -287,7 +287,6 @@ struct sip_msg*  sip_msg_cloner( struct sip_msg *org_msg )
       lump_anchor = &((*lump_anchor)->next);
       lump_chain = lump_chain->next;
    }
-   DBG("-----------> len=%d <---> written=%d\n",len,p-foo);
    return new_msg;
 }
 

+ 2 - 2
modules/tm/t_funcs.c

@@ -658,7 +658,7 @@ int t_send_reply(  struct sip_msg* p_msg , unsigned int code , char * text )
 	}
 	*/
 
-	buf = build_res_buf_from_sip_req( code , text , T->inbound_request , &len );
+	buf = build_res_buf_from_sip_req(code,text,0,0,T->inbound_request,&len);
 	DBG("DEBUG: t_send_reply: buffer computed\n");
 	if (!buf)
 	{
@@ -676,7 +676,7 @@ int t_send_reply(  struct sip_msg* p_msg , unsigned int code , char * text )
 		{
 			LOG(L_ERR, "ERROR: t_send_reply: cannot lookup reply dst: %s\n",
 				p_msg->via1->host.s );
-			goto error;
+			goto error2;
 		}
 
 		rb->retr_timer.tg=TG_RT;

+ 3 - 9
modules/tm/t_lookup.c

@@ -134,13 +134,9 @@ int t_lookup_request( struct sip_msg* p_msg , int leave_new_locked )
 			&& get_cseq(t_msg)->number.len==get_cseq(p_msg)->number.len
 			&& /*from length*/ EQ_LEN(from)
 			&& /*to body*/get_to(t_msg)->body.len==get_to(p_msg)->body.len
-			&& printf("------>0.4   %d (%d,%d)\n",p_cell->status,p_cell->tag->len,get_to(p_msg)->tag_value.len)
 			&& /*to tag*/p_cell->tag->len==get_to(p_msg)->tag_value.len
-			&& printf("------>0.5   %d\n",p_cell->status)
 			&& /*req URI*/(p_cell->status==200 || EQ_REQ_URI_LEN )
-			&& printf("------>0.6   %d\n",p_cell->status)
-			&& /*VIA*/(p_cell->status==200 || EQ_VIA_LEN(via1))
-			&& printf("------>2   %d\n",p_cell->status)  )
+			&& /*VIA*/(p_cell->status==200 || EQ_VIA_LEN(via1)) )
 				/* so far the lengths are the same
 				-> let's check the contents */
 				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 )
 					get_to(p_msg)->body.s,get_to(t_msg)->body.len)
 				&& /*to tag*/!memcmp(p_cell->tag->s,
 					get_to(p_msg)->tag_value.s,p_cell->tag->len)
-				&& /*req URI*/(p_cell->status==200 || EQ_REQ_URI_STR||
-					printf("------>1   %d\n",p_cell->status) )
-				&& /*VAI*/(p_cell->status==200 ||EQ_VIA_STR(via1) ||
-						printf("------>2   %d\n",p_cell->status) ) )
+				&& /*req URI*/(p_cell->status==200 || EQ_REQ_URI_STR)
+				&& /*VAI*/(p_cell->status==200 ||EQ_VIA_STR(via1)) )
 					{ /* WE FOUND THE GOLDEN EGG !!!! */
 						goto found;
 					}

+ 2 - 2
modules/tm/test/kill_sem.sh

@@ -1,4 +1,4 @@
 #!/bin/sh
 
-ipcrm sem `ipcs -s |grep $(whoami) | awk '{ print $2; }'`
-ipcrm shm `ipcs -m | grep $(whoami) |awk '{ print $2; }'` 
+ipcrm sem `cat /proc/sysvipc/sem | awk '{ print $2; }'`
+ipcrm shm `cat /proc/sysvipc/shm | awk '{ print $2; }'` 

+ 58 - 44
msg_translator.c

@@ -18,6 +18,18 @@
 #define MAX_RECEIVED_SIZE  57
 
 
+#define append_str(_dest,_src,_len,_msg) \
+	do{\
+		memcpy( (_dest) , (_src) , (_len) );\
+		(_dest) += (_len) ;\
+	}while(0);
+
+#define append_str_trans(_dest,_src,_len,_msg) \
+	do{\
+		memcpy( (_dest) , (_msg)->orig+((_src)-(_msg)->buf) , (_len) );\
+		(_dest) += (_len) ;\
+	}while(0);
+
 
 
 /* faster than inet_ntoa */
@@ -532,15 +544,14 @@ error:
 
 
 char * build_res_buf_from_sip_req(	unsigned int code ,
-	char *text , struct sip_msg* msg, unsigned int *returned_len)
+	char *text, char *new_tag, unsigned int new_tag_len,
+	struct sip_msg* msg, unsigned int *returned_len)
 {
 	char                    *buf, *p;
 	unsigned int       len,foo;
 	struct hdr_field  *hdr;
 	int                       i;
-#ifdef BRUT_HACK
-	struct hdr_field  *to, *from, *callid, *cseq, *via;
-#endif
+	str                        *tag_str;
 
 	/* force parsing all headers -- we want to return all
 	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 ,
 	len += SIP_VERSION_LEN + 1/*space*/ + 3/*code*/ + 1/*space*/ + strlen(text) + CRLF_LEN/*new line*/;
 	/*headers that will be copied (TO, FROM, CSEQ,CALLID,VIA)*/
 	for ( hdr=msg->headers ; hdr ; hdr=hdr->next )
-#ifdef BRUT_HACK
-	{
-		len += ((hdr->body.s+hdr->body.len ) - hdr->name.s ) + CRLF_LEN;
-		if ( hdr->type==HDR_VIA ) via = hdr;
-		else if ( hdr->type==HDR_FROM) from = hdr;
-		else if (hdr->type==HDR_CALLID) callid = hdr;
-		else if ( hdr->type==HDR_TO) to = hdr;
-		else if ( hdr->type==HDR_CSEQ) cseq = hdr;
-		else len-=((hdr->body.s+hdr->body.len ) - hdr->name.s ) + CRLF_LEN;
-	}
-#else
-		if ( hdr->type==HDR_VIA || hdr->type==HDR_FROM ||
-				hdr->type==HDR_CALLID || hdr->type==HDR_TO ||
-				hdr->type==HDR_CSEQ )
-			len += ((hdr->body.s+hdr->body.len ) - hdr->name.s ) + CRLF_LEN;
-#endif
+		switch (hdr->type)
+		{
+			case HDR_TO:
+				if (new_tag)
+					if (get_to(msg)->tag_value.s )
+						len+=new_tag_len-get_to(msg)->tag_value.len;
+					else
+						len+=new_tag_len+5/*";tag="*/;
+			case HDR_VIA:
+			case HDR_FROM:
+			case HDR_CALLID:
+			case HDR_CSEQ:
+				len += ((hdr->body.s+hdr->body.len )-hdr->name.s )+CRLF_LEN;
+		}
 	/*content length header*/
 	len +=CONTENT_LEN_LEN + CRLF_LEN;
 	/* end of message */
 	len += CRLF_LEN; /*new line*/
-
 	/*allocating mem*/
 	buf = 0;
 	buf = (char*) malloc( len+1 );
@@ -600,32 +608,38 @@ char * build_res_buf_from_sip_req(	unsigned int code ,
 	memcpy( p, CRLF, CRLF_LEN );
 	p+=CRLF_LEN;
 	/* headers*/
-#ifdef BRUT_HACK
-#define	COPY_HF(_hf) memcpy(p, msg->orig+(_hf->name.s-msg->buf), \
-			((_hf->body.s+_hf->body.len ) - \
-			_hf->name.s )); \
-			p+=((_hf->body.s+_hf->body.len)-_hf->name.s ) ; \
-			memcpy( p, CRLF, CRLF_LEN ); \
-			p+=CRLF_LEN;
-
-	COPY_HF(via);
-	COPY_HF(from);
-	COPY_HF(to);
-	COPY_HF(callid);
-	COPY_HF(cseq);
-#else
 	for ( hdr=msg->headers ; hdr ; hdr=hdr->next )
-		if ( hdr->type==HDR_VIA || hdr->type==HDR_FROM ||
-		hdr->type==HDR_CALLID || hdr->type==HDR_TO || hdr->type==HDR_CSEQ )
+		switch (hdr->type)
 		{
-			memcpy( p , msg->orig+(hdr->name.s-msg->buf) ,
-					((hdr->body.s+hdr->body.len ) -
-					hdr->name.s ) );
-			p += ((hdr->body.s+hdr->body.len ) - hdr->name.s ) ;
-			memcpy( p, CRLF, CRLF_LEN );
-			p+=CRLF_LEN;
+			case HDR_TO:
+				if (new_tag){
+					if (get_to(msg)->tag_value.s ) {
+						tag_str =&(get_to(msg)->tag_value);
+						append_str_trans( p, hdr->name.s ,
+							tag_str->s-hdr->name.s,msg);
+						append_str( p, new_tag,new_tag_len,msg);
+						append_str_trans( p,tag_str->s+tag_str->len,
+							((hdr->body.s+hdr->body.len )-
+							(tag_str->s+tag_str->len)),msg);
+						append_str( p, CRLF,CRLF_LEN,msg);
+					}else{
+						append_str_trans( p, hdr->name.s ,
+							((hdr->body.s+hdr->body.len )-hdr->name.s ),
+							msg);
+						append_str( p, ";tag=",5,msg);
+						append_str( p, new_tag,new_tag_len,msg);
+						append_str( p, CRLF,CRLF_LEN,msg);
+					}
+				break;
+				}
+			case HDR_VIA:
+			case HDR_FROM:
+			case HDR_CALLID:
+			case HDR_CSEQ:
+				append_str_trans( p, hdr->name.s ,
+					((hdr->body.s+hdr->body.len )-hdr->name.s ),msg);
+				append_str( p, CRLF,CRLF_LEN,msg);
 		}
-#endif
 
 	/* content length header*/
 	memcpy( p, CONTENT_LEN , CONTENT_LEN_LEN );

+ 3 - 1
msg_translator.h

@@ -16,8 +16,10 @@ char * build_req_buf_from_sip_req (	struct sip_msg* msg,
 char * build_res_buf_from_sip_res(	struct sip_msg* msg,
 				unsigned int *returned_len);
 
-char * build_res_buf_from_sip_req(	unsigned int code , 
+char * build_res_buf_from_sip_req(	unsigned int code ,
 				char *text ,
+				char *new_tag ,
+				unsigned int new_tag_len ,
 				struct sip_msg* msg,
 				unsigned int *returned_len);
 char* via_builder( 			struct sip_msg *msg ,

+ 22 - 13
test/th-uri.cfg

@@ -27,9 +27,14 @@ loop_checks=0
 loadmodule "modules/tm/tm.so"
 #loadmodule "modules/rr/rr.so"
 loadmodule "modules/maxfwd/maxfwd.so"
+loadmodule "modules/sl/sl.so"
 
 
 route{
+             if ( !sl_filter_ACK() ){
+                log("SER : error in sl_filter_ACK!\n");
+             };
+
              if ( mf_is_maxfwd_present() )
              {
                    if ( !mf_decrement_maxfwd() )
@@ -39,14 +44,18 @@ route{
                    if ( mf_is_maxfwd_zero() )
                    {
                      log("SER: MAX FORWARD header is zero\n");
+                     sl_send_reply("483","Too Many Hops");
                      drop();
                    };
              }else{
                    mf_add_maxfwd_header( "10" );
              };
 
+
              #if (method=="INVITE")
              #{
+                 #sl_send_reply("404","Not found");
+                 #drop();
               #  log("SER : runing CPL!! :)\n");
               #  if ( !cpl_run_script() )
                # {
@@ -63,19 +72,19 @@ route{
                # };
              #};
 
-             if ( !rewriteFromRoute() )
-             {
-                log( " SER : no route found!\n");
-                if ( method=="INVITE" )
-                {
-                   log ("SER : INVITE found - > adding RecordRoute!\n");
-                   addRecordRoute();
-                };
-             }
-             else
-             {
-                log( "SER : ROUTE found! \n");
-             };
+           #  if ( !rewriteFromRoute() )
+            # {
+                #log( " SER : no route found!\n");
+                #if ( method=="INVITE" )
+                #{
+                  # log ("SER : INVITE found - > adding RecordRoute!\n");
+                   #addRecordRoute();
+                #};
+             #}
+             #else
+             #{
+                #log( "SER : ROUTE found! \n");
+             #};
 
              t_relay();
 }