2
0
Эх сурвалжийг харах

t_forward_uri implemented

Bogdan-Andrei Iancu 24 жил өмнө
parent
commit
5e09da1173
4 өөрчлөгдсөн 33 нэмэгдсэн , 14 устгасан
  1. 1 1
      Makefile
  2. 0 1
      modules/tm/h_table.c
  3. 29 11
      modules/tm/t_funcs.c
  4. 3 1
      t_debug.cfg

+ 1 - 1
Makefile

@@ -40,7 +40,7 @@ NAME=ser
 #                  twice, trying to free a pointer alloc'ed with a different
 #                  malloc etc.)
 DEFS=-DTHREAD -DNOCR -DMACROEATER -DDNS_IP_HACK  -DSHM_MEM \
-	 -DPKG_MALLOC -DDBG_QM_MALLOC #-DNO_DEBUG
+	 -DPKG_MALLOC #-DDBG_QM_MALLOC -DNO_DEBUG
 # -DUSE_SHM_MEM
 #-DNO_DEBUG 
 #-DPKG_MALLOC

+ 0 - 1
modules/tm/h_table.c

@@ -89,7 +89,6 @@ struct s_table* init_hash_table()
 
    /*allocs the table*/
    hash_table = (struct s_table*)sh_malloc(  sizeof( struct s_table ) );
-    printf("XXXXXXXXXXXXXXXXXXXXXXXXXXXX\n");
    if ( !hash_table )
       goto error;
 

+ 29 - 11
modules/tm/t_funcs.c

@@ -2,6 +2,7 @@
 #include "../../dprint.h"
 #include "../../config.h"
 #include "../../parser_f.h"
+#include "../../ut.h"
 
 
 #define stop_RETR_and_FR_timers(h_table,p_cell)    \
@@ -347,9 +348,9 @@ int t_forward_uri( struct sip_msg* p_msg, char* foo, char* bar  )
 {
    struct hostent  *nhost;
    unsigned int     ip, port;
-   char                  backup;
+   struct sip_uri    parsed_uri;
    str                      uri;
-
+   int                      err;
 
    /* it's about the same transaction or not? */
    if ( global_msg_id != p_msg->id )
@@ -372,20 +373,37 @@ int t_forward_uri( struct sip_msg* p_msg, char* foo, char* bar  )
    else
      uri = p_msg->new_uri;
 
-   /*some dirty trick to get the port and ip of destination */
-   backup = *((uri.s)+(uri.len));
-   *((uri.s)+(uri.len)) = 0;
-   nhost = gethostbyname( uri.s );
-   *((uri.s)+(uri.len)) = backup;
+   /* parsing the request uri in order to get host and port */
+   if (parse_uri( uri.s , uri.len , &parsed_uri )<0)
+   {
+        LOG(L_ERR, "ERROR: t_forward_uri: unable to parse destination uri\n");
+        return  -1;
+   }
+
+   /* getting host address*/
+   nhost = gethostbyname( parsed_uri.host.s );
    if ( !nhost )
    {
-      DBG("DEBUG: t_forward_uri: cannot resolve host\n");
+      LOG(L_ERR, "ERROR: t_forward_uri: cannot resolve host\n");
       return -1;
    }
-   /*IP address*/
    memcpy(&ip, nhost->h_addr_list[0], sizeof(unsigned int));
-   /* port */
-   port = 5060;
+
+   /* getting the port */
+   if ( parsed_uri.port.s==0 || parsed_uri.port.len==0 )
+      port = SIP_PORT;
+   else
+   {
+       port = str2s( parsed_uri.port.s , parsed_uri.port.len , &err );
+       if ( err<0 )
+       {
+           LOG(L_ERR, "ERROR: t_forward_uri: converting port from str to int failed; using default SIP port\n");
+           port = SIP_PORT;
+       }
+   }
+   port = htons( port );
+
+   free_uri( &parsed_uri );
 
    return t_forward( p_msg , ip , port );
 }

+ 3 - 1
t_debug.cfg

@@ -14,6 +14,7 @@ loadmodule "modules/print/print.so"
 loadmodule "modules/tm/tm.so"
 
 route{
+	#rewritehost("iptel.org");
 	log("trying forward to uri");
 #	forward(uri:host,uri:port);
 #	forward(127.0.0.1, 5090);
@@ -37,10 +38,11 @@ route{
 			log("SER: new transaction\n");
 			t_send_reply("100", "trying -- your call is important to us");
 		};
-		#rewritehost("xy.com");
+		rewritehost("iptel.org");
 		# XXX ... it wants me to put port nr in ""
 		#t_forward("benetnash.fokus.gmd.de", "5080" );
 		t_forward("iptel.org", "5060" );
+		#t_forward_uri();
 		# XXX ... it doesn't like default port numbers
 		# t_forward("fox.iptel.org" );
 		# XXX t_forward_uri ... not done yet