- tm tcp support (though no timers yet)
authorAndrei Pelinescu-Onciul <andrei@iptel.org>
Wed, 19 Feb 2003 17:16:41 +0000 (17:16 +0000)
committerAndrei Pelinescu-Onciul <andrei@iptel.org>
Wed, 19 Feb 2003 17:16:41 +0000 (17:16 +0000)
 changelist (random order):
  - forward.c: removed calls to upd_send & tcp_send & replaced them with calls
    to msg_send
  - ip_addr.h:  added struct dest_info (used in tm rbs)
  - proxy.c:  all *proxy fucntions require also the protocol
  - resolve.c: added proto to sip_resolvehost, for SRV lookups
  - tags.h: changed TOTAG_LEN into TOTAG_VALUE_LEN, to solve redefinition
  conflict with tm/t_msgbuilder.h
  - modules/sl/sl_funcs.c: modified sl_send_reply to use the transport
    independend  msg_send
  - modules/tm/t_funcs.c: modified send_pr_buffer to use msg_send & rb->dst
  - modules/tm/t_fwd.c: added proto to various functions
  - modules/tm/t_lookup.c: init_rb() is proto indep. & it uses struct
    dest_info
  - modules/tm/t_msgbuilder.c: build_uac_request uses proto
  - modules/tm/t_reply.c: updated to use rb->dst, fixed TOTAG_LEN bug
  - modules/tm/tm.c: added t_forward_nonack_{udp, tcp}, t_relay_to_{udp,tcp},
    t_replicate_{udp, tcp}
  - modules/tm/uac.c: t_uac, t _uac_dlg, gethfblock, uri2proxy changed to use
    proto & rb->dst
  - modules/tm/ut.h: added proto to uri2proxy

old tag & version: pre6-tcp4
new tag & version (current): pre6-tcp5-tm

29 files changed:
Makefile.defs
TODO
action.c
config.h
forward.c
ip_addr.h
modules/tm/h_table.c
modules/tm/h_table.h
modules/tm/t_cancel.c
modules/tm/t_funcs.c
modules/tm/t_funcs.h
modules/tm/t_fwd.c
modules/tm/t_fwd.h
modules/tm/t_lookup.c
modules/tm/t_msgbuilder.c
modules/tm/t_reply.c
modules/tm/tm.c
modules/tm/tm_load.c
modules/tm/tm_load.h
modules/tm/uac.c
modules/tm/uac.h
modules/tm/ut.h
msg_translator.c
proxy.c
proxy.h
resolve.c
resolve.h
route.c
tags.h

index c5c737e..b45f5ed 100644 (file)
@@ -8,7 +8,7 @@
 VERSION = 0
 PATCHLEVEL = 8
 SUBLEVEL =   11
-EXTRAVERSION = pre6-tcp4
+EXTRAVERSION = pre6-tcp5-tm
 
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
diff --git a/TODO b/TODO
index 94ee3bb..f6bba7b 100644 (file)
--- a/TODO
+++ b/TODO
@@ -72,3 +72,10 @@ x generic locking lib
 - force add rport (setflag(rport)???)
 - kill all the fprintf
 
+tm optimizations:
+
+- replace snprintfs int build_uac_request, *_dlg
+- fix the huge param no. in this functions (use structs if neccessary):
+  build_uac_request, build_uac_request_dlg, t_uac, t_uac_dlg
+  
+
index e51023b..eea2709 100644 (file)
--- a/action.c
+++ b/action.c
@@ -129,7 +129,7 @@ int do_action(struct action* a, struct sip_msg* msg)
                                                        goto error_fwd_uri;
                                }
                                /* create a temporary proxy*/
-                               p=mk_proxy(&u->host, port);
+                               p=mk_proxy(&u->host, port, proto);
                                if (p==0){
                                        LOG(L_ERR, "ERROR:  bad host name in uri,"
                                                        " dropping packet\n");
index bfbabd1..4cd5132 100644 (file)
--- a/config.h
+++ b/config.h
@@ -91,7 +91,8 @@
 #define ID_PARAM ";i="
 #define ID_PARAM_LEN 3
 
-#define SRV_PREFIX "_sip._udp."
+#define SRV_UDP_PREFIX "_sip._udp."
+#define SRV_TCP_PREFIX "_sip._tcp."
 #define SRV_PREFIX_LEN 10
 
 /*used only if PKG_MALLOC is defined*/
index f21ac7c..a646b2f 100644 (file)
--- a/forward.c
+++ b/forward.c
@@ -375,7 +375,7 @@ int update_sock_struct_from_via( union sockaddr_union* to,
            sip_resolvehost now accepts str -janakj
        */
        DBG("update_sock_struct_from_via: trying SRV lookup\n");
-       he=sip_resolvehost(name, &port);
+       he=sip_resolvehost(name, &port, via->proto);
        
        if (he==0){
                LOG(L_NOTICE, "ERROR:forward_reply:resolve_host(%.*s) failure\n",
index da9b09f..0dbdde2 100644 (file)
--- a/ip_addr.h
+++ b/ip_addr.h
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
-
+/*
+ * History:
+ * --------
+ *  2003-02-13  added struct dest_info (andrei)
+ */
 
 #ifndef ip_addr_h
 #define ip_addr_h
@@ -40,7 +44,7 @@
 
 #include "dprint.h"
 
-enum sip_protos { PROTO_UDP, PROTO_TCP, PROTO_TLS };
+enum sip_protos { PROTO_NONE, PROTO_UDP, PROTO_TCP, PROTO_TLS };
 
 
 struct ip_addr{
@@ -101,6 +105,15 @@ struct receive_info{
 };
 
 
+struct dest_info{
+       int proto;
+       int proto_reserved1; /* tcp stores the connection id here */ 
+       union sockaddr_union to;
+       struct socket_info* send_sock;
+};
+
+
+
 /* len of the sockaddr */
 #ifdef HAVE_SOCKADDR_SA_LEN
 #define sockaddru_len(su)      ((su).s.sa_len)
index 37dc3a0..6d10409 100644 (file)
@@ -161,7 +161,7 @@ struct cell*  build_cell( struct sip_msg* p_msg )
        new_cell->uas.response.retr_timer.tg=TG_RT;
        new_cell->uas.response.fr_timer.tg=TG_FR;
        new_cell->uas.response.fr_timer.payload =
-               new_cell->uas.response.retr_timer.payload = &(new_cell->uas.response);
+       new_cell->uas.response.retr_timer.payload = &(new_cell->uas.response);
        new_cell->uas.response.my_T=new_cell;
 
        /* bogdan - debug */
@@ -186,8 +186,7 @@ struct cell*  build_cell( struct sip_msg* p_msg )
                uac->request.fr_timer.tg = TG_FR;
                uac->request.retr_timer.tg = TG_RT;
                uac->request.retr_timer.payload = 
-                       uac->request.fr_timer.payload =
-                       &uac->request;
+               uac->request.fr_timer.payload = &uac->request;
                uac->local_cancel=uac->request;
        }
 
index ed37444..d76b225 100644 (file)
@@ -82,9 +82,8 @@ typedef struct retr_buf
 
        char *buffer;
        int   buffer_len;
-
-       union sockaddr_union to;
-       struct socket_info* send_sock;
+       
+       struct dest_info dst;
 
        /* a message can be linked just to retransmission and FR list */
        struct timer_link retr_timer;
index d39785a..d80dbb1 100644 (file)
@@ -94,8 +94,7 @@ void cancel_branch( struct cell *t, int branch )
        /* install cancel now */
        crb->buffer=cancel;
        crb->buffer_len=len;
-       crb->to=irb->to;
-       crb->send_sock=irb->send_sock;
+       crb->dst=irb->dst;
        crb->branch=branch;
 #ifdef _OBSOLETED
        crb->fr_timer.tg=TG_FR;
index 52d85f9..282e9a2 100644 (file)
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+/*
+ * History:
+ * -------
+ *  2003-02-13  modified send_pr_buffer to use msg_send & rb->dst (andrei)
+ */
 
 
 #include "defs.h"
@@ -51,7 +56,8 @@ int send_pr_buffer( struct retr_buf *rb,
        void *buf, int len, char *function, int line )
 {
        if (buf && len && rb )
-               return udp_send( rb->send_sock, buf, len, &rb->to) ;
+               return msg_send( rb->dst.send_sock, rb->dst.proto, &rb->dst.to,
+                                        rb->dst.proto_reserved1, buf, len);
        else {
                LOG(L_CRIT, "ERROR: sending an empty buffer from %s (%d)\n",
                        function, line );
@@ -177,8 +183,8 @@ static int kill_transaction( struct cell *trans )
 
 
 
-int t_relay_to( struct sip_msg  *p_msg , struct proxy_l *proxy,
-       int replicate)
+int t_relay_to( struct sip_msg  *p_msg , struct proxy_l *proxy, int proto,
+                               int replicate)
 {
        int ret;
        int new_tran;
@@ -219,12 +225,12 @@ int t_relay_to( struct sip_msg  *p_msg , struct proxy_l *proxy,
                        uri=(p_msg->new_uri.s==0 || p_msg->new_uri.len==0) ?
                                &p_msg->first_line.u.request.uri :
                                &p_msg->new_uri;
-                       proxy=uri2proxy( uri );
+                       proxy=uri2proxy( uri, proto );
                        if (proxy==0) {
                                        ret=E_BAD_ADDRESS;
                                        goto done;
                        }
-                       ret=forward_request( p_msg , proxy, p_msg->rcv.proto) ;
+                       ret=forward_request( p_msg , proxy, proto) ;
                        free_proxy( proxy );    
                        free( proxy );
 #ifdef ACK_FORKING_HACK
@@ -232,22 +238,22 @@ int t_relay_to( struct sip_msg  *p_msg , struct proxy_l *proxy,
                        init_branch_iterator();
                        while((ack_uri.s=next_branch(&ack_uri.len))) {
                                p_msg->new_uri=ack_uri;
-                               proxy=uri2proxy(ack_uri);
+                               proxy=uri2proxy(ack_uri, proto);
                                if (proxy==0) continue;
-                               forward_request(p_msg, proxy);
+                               forward_request(p_msg, proxy, proto);
                                free_proxy( proxy );    
                                free( proxy );
                        }
                        p_msg->new_uri=backup_uri;
 #endif
                } else {
-                       ret=forward_request( p_msg , proxy, p_msg->rcv.proto ) ;
+                       ret=forward_request( p_msg , proxy, proto ) ;
 #ifdef ACK_FORKING_HACK
                        backup_uri=p_msg->new_uri;
                        init_branch_iterator();
                        while((ack_uri.s=next_branch(&ack_uri.len))) {
                                p_msg->new_uri=ack_uri;
-                               forward_request(p_msg, proxy);
+                               forward_request(p_msg, proxy, proto);
                        }
                        p_msg->new_uri=backup_uri;
 #endif
@@ -272,7 +278,7 @@ int t_relay_to( struct sip_msg  *p_msg , struct proxy_l *proxy,
        } 
 
        /* now go ahead and forward ... */
-       ret=t_forward_nonack(t, p_msg, proxy);
+       ret=t_forward_nonack(t, p_msg, proxy, proto);
        if (ret<=0) {
                DBG( "SER:ERROR: t_forward \n");
                reply_ret=kill_transaction( t );
index 4bf2326..f290a73 100644 (file)
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+ /* History:
+  * --------
+  *  2003-02-18  updated various function prototypes (andrei)
+  */
 
 
 
@@ -127,7 +131,7 @@ void start_retr( struct retr_buf *rb );
 void cleanup_localcancel_timers( struct cell *t );
 
 int t_relay_to( struct sip_msg  *p_msg ,
-       struct proxy_l *proxy, int replicate ) ;
+       struct proxy_l *proxy, int proto, int replicate ) ;
 
 
 #endif
index 0aaa74e..6cf2cf2 100644 (file)
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+/*
+ * History:
+ * -------
+ *  2003-02-13  proto support added (andrei)
+ */
 
 #include "defs.h"
 
@@ -127,10 +132,10 @@ error01:
 
 /* introduce a new uac to transaction; returns its branch id (>=0)
    or error (<0); it doesn't send a message yet -- a reply to it
-   might itnerfere with the processes of adding multiple branches
+   might interfere with the processes of adding multiple branches
 */
 int add_uac( struct cell *t, struct sip_msg *request, str *uri, 
-       struct proxy_l *proxy )
+       struct proxy_l *proxy, int proto )
 {
 
        int ret;
@@ -157,7 +162,7 @@ int add_uac( struct cell *t, struct sip_msg *request, str *uri,
 
        /* check DNS resolution */
        if (proxy) temp_proxy=0; else {
-               proxy=uri2proxy( uri );
+               proxy=uri2proxy( uri, proto );
                if (proxy==0)  {
                        ret=E_BAD_ADDRESS;
                        goto error;
@@ -175,7 +180,7 @@ int add_uac( struct cell *t, struct sip_msg *request, str *uri,
        hostent2su( &to, &proxy->host, proxy->addr_idx, 
                proxy->port ? htons(proxy->port):htons(SIP_PORT));
 
-       send_sock=get_send_socket( &to , request->rcv.proto);
+       send_sock=get_send_socket( &to , proto);
        if (send_sock==0) {
                LOG(L_ERR, "ERROR: add_uac: can't fwd to af %d "
                        " (no corresponding listening socket)\n",
@@ -193,8 +198,10 @@ int add_uac( struct cell *t, struct sip_msg *request, str *uri,
        }
 
        /* things went well, move ahead and install new buffer! */
-       t->uac[branch].request.to=to;
-       t->uac[branch].request.send_sock=send_sock;
+       t->uac[branch].request.dst.to=to;
+       t->uac[branch].request.dst.send_sock=send_sock;
+       t->uac[branch].request.dst.proto=proto;
+       t->uac[branch].request.dst.proto_reserved1=0;
        t->uac[branch].request.buffer=shbuf;
        t->uac[branch].request.buffer_len=len;
        t->uac[branch].uri.s=t->uac[branch].request.buffer+
@@ -238,7 +245,7 @@ int e2e_cancel_branch( struct sip_msg *cancel_msg, struct cell *t_cancel,
        /* print */
        shbuf=print_uac_request( t_cancel, cancel_msg, branch, 
                &t_invite->uac[branch].uri, &len, 
-               t_invite->uac[branch].request.send_sock);
+               t_invite->uac[branch].request.dst.send_sock);
        if (!shbuf) {
                LOG(L_ERR, "ERROR: e2e_cancel_branch: printing e2e cancel failed\n");
                ret=ser_error=E_OUT_OF_MEM;
@@ -246,8 +253,7 @@ int e2e_cancel_branch( struct sip_msg *cancel_msg, struct cell *t_cancel,
        }
        
        /* install buffer */
-       t_cancel->uac[branch].request.to=t_invite->uac[branch].request.to;
-       t_cancel->uac[branch].request.send_sock=t_invite->uac[branch].request.send_sock;
+       t_cancel->uac[branch].request.dst=t_invite->uac[branch].request.dst;
        t_cancel->uac[branch].request.buffer=shbuf;
        t_cancel->uac[branch].request.buffer_len=len;
        t_cancel->uac[branch].uri.s=t_cancel->uac[branch].request.buffer+
@@ -344,7 +350,7 @@ void e2e_cancel( struct sip_msg *cancel_msg,
  *      -1 - error during forward
  */
 int t_forward_nonack( struct cell *t, struct sip_msg* p_msg , 
-       struct proxy_l * proxy )
+       struct proxy_l * proxy, int proto)
 {
        str          backup_uri;
        int branch_ret, lowest_ret;
@@ -384,7 +390,7 @@ int t_forward_nonack( struct cell *t, struct sip_msg* p_msg ,
                branch_ret=add_uac( t, p_msg, 
                        p_msg->new_uri.s ? &p_msg->new_uri :  
                                &p_msg->first_line.u.request.uri,
-                       proxy );
+                               proxy, proto );
                if (branch_ret>=0) 
                        added_branches |= 1<<branch_ret;
                else
@@ -393,7 +399,7 @@ int t_forward_nonack( struct cell *t, struct sip_msg* p_msg ,
 
        init_branch_iterator();
        while((current_uri.s=next_branch( &current_uri.len))) {
-               branch_ret=add_uac( t, p_msg, &current_uri, proxy );
+               branch_ret=add_uac( t, p_msg, &current_uri, proxy, proto);
                /* pick some of the errors in case things go wrong;
                   note that picking lowest error is just as good as
                   any other algorithm which picks any other negative
@@ -431,7 +437,7 @@ int t_forward_nonack( struct cell *t, struct sip_msg* p_msg ,
        return 1;
 }      
 
-int t_replicate(struct sip_msg *p_msg,  struct proxy_l *proxy )
+int t_replicate(struct sip_msg *p_msg,  struct proxy_l *proxy, int proto )
 {
        /* this is a quite horrible hack -- we just take the message
           as is, including Route-s, Record-route-s, and Vias ,
@@ -444,5 +450,5 @@ int t_replicate(struct sip_msg *p_msg,  struct proxy_l *proxy )
                if we want later to make it thoroughly, we need to
                introduce delete lumps for all the header fields above
        */
-       return t_relay_to(p_msg, proxy, 1 /* replicate */);
+       return t_relay_to(p_msg, proxy, proto, 1 /* replicate */);
 }
index dd2c562..8176722 100644 (file)
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+/*
+ * History:
+ * --------
+ *  2003-02-18  added proto to various function prototypes (andrei)
+ */
 
 
 #ifndef _T_FWD_H
 
 typedef int (*tfwd_f)(struct sip_msg* p_msg , struct proxy_l * proxy );
 
-int t_replicate(struct sip_msg *p_msg, struct proxy_l * proxy );
+int t_replicate(struct sip_msg *p_msg, struct proxy_l * proxy, int proto);
 char *print_uac_request( struct cell *t, struct sip_msg *i_req,
     int branch, str *uri, unsigned int *len, struct socket_info *send_sock );
 void e2e_cancel( struct sip_msg *cancel_msg, struct cell *t_cancel, struct cell *t_invite );
 int e2e_cancel_branch( struct sip_msg *cancel_msg, struct cell *t_cancel, struct cell *t_invite, int branch );
-int add_uac( struct cell *t, struct sip_msg *request, str *uri, struct proxy_l *proxy );
-int t_forward_nonack( struct cell *t, struct sip_msg* p_msg, struct proxy_l * p );
+int add_uac(   struct cell *t, struct sip_msg *request, str *uri,
+                               struct proxy_l *proxy, int proto );
+int t_forward_nonack( struct cell *t, struct sip_msg* p_msg,
+                                               struct proxy_l * p, int proto);
 int t_forward_ack( struct sip_msg* p_msg );
 
 
index bc9a074..80774b7 100644 (file)
  *
  * History:
  * ----------
- * 2003-01-28 scratchpad removed (jiri)
- * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri)
- * 2003-01-23 options for disabling r-uri matching introduced (jiri)
+ * 2003-01-28  scratchpad removed (jiri)
+ * 2003-01-27  next baby-step to removing ZT - PRESERVE_ZT (jiri)
+ * 2003-01-23  options for disabling r-uri matching introduced (jiri)
+ * 2003-02-13  init_rb() is proto indep. & it uses struct dest_info (andrei)
  */
 
 
@@ -750,31 +751,37 @@ int t_check( struct sip_msg* p_msg , int *param_branch )
        return ((T)?1:0) ;
 }
 
-int init_rb( struct retr_buf *rb, struct sip_msg *msg )
+int init_rb( struct retr_buf *rb, struct sip_msg *msg)
 {
        struct socket_info* send_sock;
        struct via_body* via;
+       int proto;
 
+       via=msg->via1;
        if (!reply_to_via) {
-               update_sock_struct_from_ip( &rb->to, msg );
+               update_sock_struct_from_ip( &rb->dst.to, msg );
+               proto=msg->rcv.proto;
        } else {
-               via=msg->via1;
                /*init retrans buffer*/
-               if (update_sock_struct_from_via( &(rb->to),via )==-1) {
+               if (update_sock_struct_from_via( &(rb->dst.to),via )==-1) {
                        LOG(L_ERR, "ERROR: init_rb: cannot lookup reply dst: %.*s\n",
                                via->host.len, via->host.s );
                        ser_error=E_BAD_VIA;
                        return 0;
                }
+               proto=via->proto;
        }
-       send_sock=get_send_socket(&rb->to, msg->rcv.proto);
+       rb->dst.proto=proto;
+       rb->dst.proto_reserved1=msg->rcv.proto_reserved1;
+       send_sock=get_send_socket(&rb->dst.to, proto);
        if (send_sock==0) {
                LOG(L_ERR, "ERROR: init_rb: cannot fwd to af %d "
-                       "no socket\n", rb->to.s.sa_family);
+                       "no socket\n", rb->dst.to.s.sa_family);
                ser_error=E_BAD_VIA;
                return 0;
        }
-       rb->send_sock=send_sock;
+       rb->dst.send_sock=send_sock;
+       
     return 1;
 }
 
index c0de419..75831d4 100644 (file)
@@ -29,7 +29,8 @@
  *
  * History:
  * ----------
- * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri)
+ * 2003-01-27  next baby-step to removing ZT - PRESERVE_ZT (jiri)
+ * 2003-02-13  build_uac_request uses proto (andrei)
  */
 
 #include "defs.h"
@@ -91,8 +92,8 @@ char *build_local(struct cell *Trans,unsigned int branch,
                goto error;
        branch_str.s=branch_buf;
        branch_str.len=branch_len;
-       via=via_builder(&via_len, Trans->uac[branch].request.send_sock,
-               &branch_str, 0, Trans->uac[branch].request.send_sock->proto );
+       via=via_builder(&via_len, Trans->uac[branch].request.dst.send_sock,
+               &branch_str, 0, Trans->uac[branch].request.dst.proto );
        if (!via)
        {
                LOG(L_ERR, "ERROR: t_build_and_send_CANCEL: "
@@ -260,7 +261,7 @@ char *build_uac_request(  str msg_type, str dst, str from,
        branch_str.len=branch_len;
        
        via=via_builder(&via_len, t->uac[branch].request.send_sock,
-               &branch_str, 0, t->uac[branch].request.send_sock->proto);
+               &branch_str, 0, t->uac[branch].request.dst.proto);
        
        if (!via) {
                LOG(L_ERR, "ERROR: build_uac_request: via building failed\n");
index 879ef1b..7b974b6 100644 (file)
  *
  * History:
  * --------
- * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri)
- * 2003-01-19 faked lump list created in on_reply handlers
+ * 2003-01-27  next baby-step to removing ZT - PRESERVE_ZT (jiri)
+ * 2003-01-19  faked lump list created in on_reply handlers
+ * 2003-02-13  updated to use rb->dst (andrei)
+ * 2003-02-18  replaced TOTAG_LEN w/ TOTAG_VALUE_LEN (TOTAG_LEN was defined
+ *             twice with different values!)  (andrei)
  */
 
 #include "defs.h"
@@ -62,7 +65,7 @@
 enum route_mode rmode=MODE_REQUEST;
 
 /* private place where we create to-tags for replies */
-static char tm_tags[TOTAG_LEN];
+static char tm_tags[TOTAG_VALUE_LEN];
 static char *tm_tag_suffix;
 
 /* where to go if there is no positive reply */
@@ -397,7 +400,8 @@ static enum rps t_should_relay_response( struct cell *Trans , int new_code,
                init_branch_iterator();
                if (next_branch(&dummy)) {
                        if (t_forward_nonack(Trans, origin_rq,
-                                               (struct proxy_l *) 0 ) <0) {
+                                               (struct proxy_l *) 0,
+                                               Trans->uas.response.dst.proto)<0) {
                                /* error ... behave as if we did not try to
                                   add a new branch */
                                *should_store=0;
@@ -456,7 +460,7 @@ int t_retransmit_reply( struct cell *t )
        /* first check if we managed to resolve topmost Via -- if
           not yet, don't try to retransmit
        */
-       if (!t->uas.response.send_sock) {
+       if (!t->uas.response.dst.send_sock) {
                LOG(L_WARN, "WARNING: t_retransmit_reply: "
                        "no resolved dst to retransmit\n");
                return -1;
@@ -550,12 +554,12 @@ static int _reply( struct cell *trans, struct sip_msg* p_msg,
                            || get_to(p_msg)->tag_value.len==0)) {
                calc_crc_suffix( p_msg, tm_tag_suffix );
                buf = build_res_buf_from_sip_req(code,text, 
-                               tm_tags, TOTAG_LEN, 
+                               tm_tags, TOTAG_VALUE_LEN, 
                                p_msg,&len);
 #ifdef VOICE_MAIL
 
                return _reply_light(trans,buf,len,code,text,
-                                   tm_tags, TOTAG_LEN,
+                                   tm_tags, TOTAG_VALUE_LEN,
                                    lock);
 #endif
        } else {
@@ -654,7 +658,7 @@ static int _reply_light( struct cell *trans, char* buf, unsigned int len,
        /* first check if we managed to resolve topmost Via -- if
           not yet, don't try to retransmit
        */
-       if (!trans->uas.response.send_sock) {
+       if (!trans->uas.response.dst.send_sock) {
                LOG(L_ERR, "ERROR: _reply: no resolved dst to send reply to\n");
        } else {
                SEND_PR_BUFFER( rb, buf, len );
@@ -797,7 +801,7 @@ enum rps relay_reply( struct cell *t, struct sip_msg *p_msg, int branch,
                                buf = build_res_buf_from_sip_req(
                                                relayed_code,
                                                error_text(relayed_code),
-                                               tm_tags, TOTAG_LEN, 
+                                               tm_tags, TOTAG_VALUE_LEN, 
                                                t->uas.request, &res_len );
                        } else {
                                buf = build_res_buf_from_sip_req( relayed_code,
index 60ac37f..8e8f297 100644 (file)
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+/*
+ * History:
+ * --------
+ *  2003-02-18  added t_forward_nonack_{udp, tcp}, t_relay_to_{udp,tcp},
+ *               t_replicate_{udp, tcp} (andrei)
+ */
 
 
 #include "defs.h"
@@ -94,10 +100,22 @@ inline static int w_t_newtran(struct sip_msg* p_msg, char* foo, char* bar );
 inline static int w_t_newdlg( struct sip_msg* p_msg, char* foo, char* bar );
 inline static int w_t_relay( struct sip_msg  *p_msg , char *_foo, char *_bar);
 inline static int w_t_relay_to( struct sip_msg  *p_msg , char *proxy, char *);
+inline static int w_t_relay_to_udp( struct sip_msg  *p_msg , char *proxy, 
+                                                                       char *);
+inline static int w_t_relay_to_tcp( struct sip_msg  *p_msg , char *proxy,
+                                                                       char *);
 inline static int w_t_replicate( struct sip_msg  *p_msg , 
-       char *proxy, /* struct proxy_l *proxy expected */
-       char *_foo       /* nothing expected */ );
+                                                       char *proxy, /* struct proxy_l *proxy expected */
+                                                       char *_foo       /* nothing expected */ );
+inline static int w_t_replicate_udp( struct sip_msg  *p_msg , 
+                                                       char *proxy, /* struct proxy_l *proxy expected */
+                                                       char *_foo       /* nothing expected */ );
+inline static int w_t_replicate_tcp( struct sip_msg  *p_msg , 
+                                                       char *proxy, /* struct proxy_l *proxy expected */
+                                                       char *_foo       /* nothing expected */ );
 inline static int w_t_forward_nonack(struct sip_msg* msg, char* str, char* );
+inline static int w_t_forward_nonack_udp(struct sip_msg* msg, char* str,char*);
+inline static int w_t_forward_nonack_tcp(struct sip_msg* msg, char* str,char*);
 inline static int fixup_hostport2proxy(void** param, int param_no);
 inline static int w_t_on_negative( struct sip_msg* msg, char *go_to, char *foo );
 
@@ -124,9 +142,15 @@ struct module_exports exports= {
                                "t_retransmit_reply",
                                "t_release",
                                T_RELAY_TO,
+                               T_RELAY_TO_UDP,
+                               T_RELAY_TO_TCP,
                                "t_replicate",
+                               "t_replicate_udp",
+                               "t_replicate_tcp",
                                T_RELAY,
                                T_FORWARD_NONACK,
+                               T_FORWARD_NONACK_UDP,
+                               T_FORWARD_NONACK_TCP,
                                "t_on_negative",
 
                                /* not applicable from script ... */
@@ -155,9 +179,15 @@ struct module_exports exports= {
                                        w_t_retransmit_reply,
                                        w_t_release,
                                        w_t_relay_to,
+                                       w_t_relay_to_udp,
+                                       w_t_relay_to_tcp,
                                        w_t_replicate,
+                                       w_t_replicate_udp,
+                                       w_t_replicate_tcp,
                                        w_t_relay,
                                        w_t_forward_nonack,
+                                       w_t_forward_nonack_udp,
+                                       w_t_forward_nonack_tcp,
                                        w_t_on_negative,
 
                                        (cmd_function) register_tmcb,
@@ -184,9 +214,15 @@ struct module_exports exports= {
                                0, /* t_retransmit_reply */
                                0, /* t_release */
                                2, /* t_relay_to */
+                               2, /* t_relay_to_udp */
+                               2, /* t_relay_to_tcp */
                                2, /* t_replicate */
+                               2, /* t_replicate_udp */
+                               2, /* t_replicate_tcp */
                                0, /* t_relay */
                                2, /* t_forward_nonack */
+                               2, /* t_forward_nonack_udp */
+                               2, /* t_forward_nonack_tcp */
                                1, /* t_on_negative */
                                NO_SCRIPT /* register_tmcb */,
 #ifndef DEPRECATE_OLD_STUFF
@@ -212,9 +248,15 @@ struct module_exports exports= {
                                0,                                              /* t_retransmit_reply */
                                0,                                              /* t_release */
                                fixup_hostport2proxy,   /* t_relay_to */
+                               fixup_hostport2proxy,   /* t_relay_to_udp */
+                               fixup_hostport2proxy,   /* t_relay_to_tcp */
                                fixup_hostport2proxy,   /* t_replicate */
+                               fixup_hostport2proxy,   /* t_replicate_udp */
+                               fixup_hostport2proxy,   /* t_replicate_tcp */
                                0,                                              /* t_relay */
                                fixup_hostport2proxy,   /* t_forward_nonack */
+                               fixup_hostport2proxy,   /* t_forward_nonack_udp */
+                               fixup_hostport2proxy,   /* t_forward_nonack_tcp */
                                fixup_str2int,                  /* t_on_negative */
                                0,                                              /* register_tmcb */
 #ifndef DEPRECATE_OLD_STUFF
@@ -240,7 +282,7 @@ struct module_exports exports= {
 #ifdef VOICE_MAIL
        4+
 #endif
-       14,
+       14 + 6 /* *_(UDP|TCP) */,
 
        /* ------------ exported variables ---------- */
        (char *[]) { /* Module parameter names */
@@ -455,7 +497,7 @@ inline static int fixup_hostport2proxy(void** param, int param_no)
                }
                s.s = host;
                s.len = strlen(host);
-               proxy=mk_proxy(&s, port);
+               proxy=mk_proxy(&s, port, 0); /* FIXME: udp or tcp? */
                if (proxy==0) {
                        LOG(L_ERR, "ERROR: fixup_t_forwardv6: bad host name in URI <%s>\n",
                                host );
@@ -506,7 +548,8 @@ inline static int w_t_check(struct sip_msg* msg, char* str, char* str2)
 
 
 
-inline static int w_t_forward_nonack(struct sip_msg* msg, char* proxy, char* _foo)
+inline static int _w_t_forward_nonack(struct sip_msg* msg, char* proxy,
+                                                                        char* _foo, int proto)
 {
        struct cell *t;
        if (t_check( msg , 0 )==-1) return -1;
@@ -516,7 +559,7 @@ inline static int w_t_forward_nonack(struct sip_msg* msg, char* proxy, char* _fo
                        LOG(L_WARN,"WARNING: you don't really want to fwd hbh ACK\n");
                        return -1;
                }
-               return t_forward_nonack(t, msg, ( struct proxy_l *) proxy );
+               return t_forward_nonack(t, msg, ( struct proxy_l *) proxy, proto );
        } else {
                DBG("DEBUG: t_forward_nonack: no transaction found\n");
                return -1;
@@ -524,6 +567,25 @@ inline static int w_t_forward_nonack(struct sip_msg* msg, char* proxy, char* _fo
 }
 
 
+inline static int w_t_forward_nonack( struct sip_msg* msg, char* proxy,
+                                                                               char* foo)
+{
+       return _w_t_forward_nonack(msg, proxy, foo, msg->rcv.proto);
+};
+
+inline static int w_t_forward_nonack_udp( struct sip_msg* msg, char* proxy,
+                                                                               char* foo)
+{
+       return _w_t_forward_nonack(msg, proxy, foo, PROTO_UDP);
+};
+
+inline static int w_t_forward_nonack_tcp( struct sip_msg* msg, char* proxy,
+                                                                               char* foo)
+{
+       return _w_t_forward_nonack(msg, proxy, foo, PROTO_TCP);
+};
+
+
 
 inline static int w_t_reply(struct sip_msg* msg, char* str, char* str2)
 {
@@ -632,22 +694,56 @@ inline static int w_t_relay_to( struct sip_msg  *p_msg ,
        char *proxy, /* struct proxy_l *proxy expected */
        char *_foo       /* nothing expected */ )
 {
-       return t_relay_to( p_msg, ( struct proxy_l *) proxy,
+       return t_relay_to( p_msg, ( struct proxy_l *) proxy, p_msg->rcv.proto,
+       0 /* no replication */ );
+}
+
+inline static int w_t_relay_to_udp( struct sip_msg  *p_msg , 
+       char *proxy, /* struct proxy_l *proxy expected */
+       char *_foo       /* nothing expected */ )
+{
+       return t_relay_to( p_msg, ( struct proxy_l *) proxy, PROTO_UDP,
        0 /* no replication */ );
 }
 
+inline static int w_t_relay_to_tcp( struct sip_msg  *p_msg , 
+       char *proxy, /* struct proxy_l *proxy expected */
+       char *_foo       /* nothing expected */ )
+{
+       return t_relay_to( p_msg, ( struct proxy_l *) proxy, PROTO_TCP,
+       0 /* no replication */ );
+}
+
+
+
 inline static int w_t_replicate( struct sip_msg  *p_msg , 
        char *proxy, /* struct proxy_l *proxy expected */
        char *_foo       /* nothing expected */ )
 {
-       return t_replicate(p_msg, ( struct proxy_l *) proxy );
+       return t_replicate(p_msg, ( struct proxy_l *) proxy, p_msg->rcv.proto );
 }
 
+inline static int w_t_replicate_udp( struct sip_msg  *p_msg , 
+       char *proxy, /* struct proxy_l *proxy expected */
+       char *_foo       /* nothing expected */ )
+{
+       return t_replicate(p_msg, ( struct proxy_l *) proxy, PROTO_UDP );
+}
+
+inline static int w_t_replicate_tcp( struct sip_msg  *p_msg , 
+       char *proxy, /* struct proxy_l *proxy expected */
+       char *_foo       /* nothing expected */ )
+{
+       return t_replicate(p_msg, ( struct proxy_l *) proxy, PROTO_TCP );
+}
+
+
+
 inline static int w_t_relay( struct sip_msg  *p_msg , 
                                                char *_foo, char *_bar)
 {
        return t_relay_to( p_msg, 
-               (struct proxy_l *) 0 /* no proxy */,
+               (struct proxy_l *) 0 /* no proxy */, p_msg->rcv.proto,
                0 /* no replication */ );
 }
 
index 79fda3e..b9aea30 100644 (file)
@@ -68,7 +68,7 @@ int load_tm( struct tm_binds *tmb)
                LOG( L_ERR, LOAD_ERROR "'t_reply' not found\n");
                return -1;
        }
-       if (!(tmb->t_is_local=(tget_ti_f)find_export(T_IS_LOCAL, NO_SCRIPT)) ) {
+       if (!(tmb->t_is_local=(tislocal_f)find_export(T_IS_LOCAL, NO_SCRIPT)) ) {
                LOG( L_ERR, LOAD_ERROR "'t_get_trans_ident' not found\n");
                return -1;
        }
index 948962f..b6af933 100644 (file)
@@ -45,6 +45,8 @@
 #define NO_SCRIPT      -1
 
 #define T_RELAY_TO "t_relay_to"
+#define T_RELAY_TO_UDP "t_relay_to_udp"
+#define T_RELAY_TO_TCP "t_relay_to_tcp"
 #define T_RELAY "t_relay"
 #ifndef DEPRECATE_OLD_STUFF
 #      define T_UAC "t_uac"
@@ -56,6 +58,8 @@
 #endif
 #define T_REPLY_UNSAFE "t_reply_unsafe"
 #define T_FORWARD_NONACK "t_forward_nonack"
+#define T_FORWARD_NONACK_UDP "t_forward_nonack_udp"
+#define T_FORWARD_NONACK_TCP "t_forward_nonack_tcp"
 
 
 
index d534d71..3bb3eae 100644 (file)
  *
  * History:
  * --------
- * 2003-01-29 scratchpad removed (jiri)
- * 2003-01-27 fifo:t_uac_dlg completed (jiri)
- * 2003-01-23 t_uac_dlg now uses get_out_socket (jiri)
+ * 2003-01-29  scratchpad removed (jiri)
+ * 2003-01-27  fifo:t_uac_dlg completed (jiri)
+ * 2003-01-23  t_uac_dlg now uses get_out_socket (jiri)
+ * 2003-02-13  t_uac, t _uac_dlg, gethfblock, uri2proxy changed to use 
+ *              proto & rb->dst (andrei)
  */
 
 
@@ -207,7 +209,7 @@ int uac_child_init( int rank )
 }
 
 #ifndef DEPRECATE_OLD_STUFF
-int t_uac( str *msg_type, str *dst, 
+int t_uac( str *msg_type, str *dst, int proto, 
        str *headers, str *body, str *from, 
        transaction_cb completion_cb, void *cbp, 
        dlg_t dlg)
@@ -230,7 +232,7 @@ int t_uac( str *msg_type, str *dst,
        /* make -Wall shut up */
        ret=0;
 
-       proxy=uri2proxy( dst );
+       proxy=uri2proxy( dst, proto );
        if (proxy==0) {
                ser_error=ret=E_BAD_ADDRESS;
                LOG(L_ERR, "ERROR: t_uac: can't create a dst proxy\n");
@@ -242,7 +244,7 @@ int t_uac( str *msg_type, str *dst,
        hostent2su(&to, &proxy->host, proxy->addr_idx, 
                (proxy->port)?htons(proxy->port):htons(SIP_PORT));
        /* send_sock=get_send_socket( &to, PROTO_UDP ); */
-       send_sock=get_out_socket( &to, PROTO_UDP );
+       send_sock=get_out_socket( &to, proto );
        if (send_sock==0) {
                LOG(L_ERR, "ERROR: t_uac: no corresponding listening socket "
                        "for af %d\n", to.s.sa_family );
@@ -282,8 +284,10 @@ int t_uac( str *msg_type, str *dst,
 
 
        request=&new_cell->uac[branch].request;
-       request->to=to;
-       request->send_sock=send_sock;
+       request->dst.to=to;
+       request->dst.send_sock=send_sock;
+       request->dst.proto=proto;
+       request->dst.proto_reserved1=0; /* no special connection required */
 
        /* need to put in table to calculate label which is needed for printing */
        LOCK_HASH(new_cell->hash_index);
@@ -344,12 +348,13 @@ done:
 }
 #endif
 
-static struct socket_info *uri2sock( str *uri, union sockaddr_union *to_su )
+static struct socket_info *uri2sock( str *uri, union sockaddr_union *to_su,
+                                                                        int proto )
 {
        struct proxy_l *proxy;
        struct socket_info* send_sock;
 
-       proxy = uri2proxy(uri);
+       proxy = uri2proxy(uri, proto);
        if (proxy == 0) {
                ser_error = E_BAD_ADDRESS;
                LOG(L_ERR, "ERROR: uri2sock: Can't create a dst proxy\n");
@@ -358,7 +363,7 @@ static struct socket_info *uri2sock( str *uri, union sockaddr_union *to_su )
 
        hostent2su(to_su, &proxy->host, proxy->addr_idx, 
                        (proxy->port) ? htons(proxy->port) : htons(SIP_PORT));
-       send_sock=get_out_socket(to_su, PROTO_UDP);
+       send_sock=get_out_socket(to_su, proto);
        if (send_sock == 0) {
                LOG(L_ERR, "ERROR: uri2sock: no corresponding socket for af %d\n", 
                                                to_su->s.sa_family );
@@ -428,6 +433,7 @@ static struct socket_info *uri2sock( str *uri, union sockaddr_union *to_su )
  */
 int t_uac_dlg(str* msg,                     /* Type of the message - MESSAGE, OPTIONS etc. */
              str* dst,                     /* Real destination (can be different than R-URI) */
+                 int proto,
              str* ruri,                    /* Request-URI */
              str* to,                      /* To - w/o tag*/
              str* from,                    /* From - w/o tag*/
@@ -464,7 +470,7 @@ int t_uac_dlg(str* msg,                     /* Type of the message - MESSAGE, OP
                goto done;
        }
 
-       send_sock=uri2sock( dst? dst: ruri, &to_su );
+       send_sock=uri2sock( dst? dst: ruri, &to_su, proto );
        if (send_sock==0) {
                LOG(L_ERR, "ERROR: t_uac_dlg: no socket found\n");
                goto error00;
@@ -504,8 +510,10 @@ int t_uac_dlg(str* msg,                     /* Type of the message - MESSAGE, OP
        new_cell->kr = REQ_FWDED;
 
        request = &new_cell->uac[branch].request;
-       request->to = to_su;
-       request->send_sock = send_sock;
+       request->dst.to = to_su;
+       request->dst.send_sock = send_sock;
+       request->dst.proto = proto;
+       request->dst.proto_reserved1 = 0;
 
        /* need to put in table to calculate label which is needed for printing */
        LOCK_HASH(new_cell->hash_index);
@@ -677,7 +685,7 @@ int fifo_uac( FILE *stream, char *response_file )
        } else {
                shmem_file=0;
        }
-       ret=t_uac(&sm,&sd,&sh,&sb, 0 /* default from */,
+       ret=t_uac(&sm,&sd, PROTO_UDP,&sh,&sb, 0 /* default from */,
                fifo_callback,shmem_file,0 /* no dialog */);
        if (ret>0) {
                if (err2reason_phrase(ret, &sip_error, err_buf,
@@ -782,7 +790,7 @@ int fifo_uac_from( FILE *stream, char *response_file )
           will not be triggered and no feedback will be printed
           to shmem_file
        */
-       ret=t_uac(&sm,&sd,&sh,&sb, sf.len==0 ? 0 : &sf /* default from */,
+       ret=t_uac(&sm,&sd, PROTO_UDP, &sh,&sb, sf.len==0 ? 0: &sf/*default from*/,
                fifo_callback,shmem_file,0 /* no dialog */);
        if (ret<=0) {
                err_ret=err2reason_phrase(ret, &sip_error, err_buf,
@@ -821,7 +829,7 @@ static struct str_list *new_str(char *s, int len, struct str_list **last, int *t
 }
 
 
-static char *get_hfblock(str *uri, struct hdr_field *hf, int *l) 
+static char *get_hfblock(str *uri, struct hdr_field *hf, int *l, int proto
 {
        struct str_list sl, *last, *new, *i, *foo;
        int hf_avail, frag_len, total_len;
@@ -859,7 +867,7 @@ static char *get_hfblock(str *uri, struct hdr_field *hf, int *l)
                                                if (!new) goto error;
                                                /* substitute */
                                                if (!sock_name) {
-                                                       send_sock=uri2sock( uri, &to_su );
+                                                       send_sock=uri2sock( uri, &to_su, proto );
                                                        if (!send_sock) {
                                                                LOG(L_ERR, "ERROR: get_hf_block: send_sock failed\n");
                                                                goto error;
@@ -1117,7 +1125,7 @@ int fifo_uac_dlg( FILE *stream, char *response_file )
        }
 
        hfb.s=get_hfblock(outbound.len ? &outbound : &ruri, 
-                                       faked_msg.headers, &hfb.len);
+                                       faked_msg.headers, &hfb.len, PROTO_UDP);
        if (!hfb.s) {
                fifo_uac_error(response_file, 500, "no mem for hf block");
                goto error;
@@ -1144,6 +1152,7 @@ int fifo_uac_dlg( FILE *stream, char *response_file )
        dummy_empty.s=0; dummy_empty.len=0;
        ret=t_uac_dlg( &method, 
                outbound.len ? &outbound: 0,
+               PROTO_UDP,
                &ruri, 
                &faked_msg.to->body,    /* possibly w/to-tag in it */
                &faked_msg.from->body,
index e62562e..1ce99a0 100644 (file)
@@ -76,6 +76,7 @@ int t_uac(
        str *msg_type,  
        /* sip:foo@bar, will be put in r-uri and To */
        str *dst,       
+       int proto, 
        /* all other header fields separated by CRLF, including 
           Content-type if body attached, excluding HFs
           generated by UAC: To, Content_length, CSeq, Call-ID, Via, From
@@ -103,7 +104,9 @@ int t_uac(
  * Send a request within a dialog
  */
 int t_uac_dlg(str* msg,                     /* Type of the message - MESSAGE, OPTIONS etc. */
-             str* dst,                     /* Real destination (can be different than R-URI */
+             str* dst,                     /* Real destination (can be different 
+                                                                                  than R-URI */
+                 int proto,
              str* ruri,                    /* Request-URI */
              str* to,                      /* To - including tag */
              str* from,                    /* From - including tag */
index de29ce6..f309db8 100644 (file)
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+/*
+ * History:
+ * -------
+ *  2003-02-13  added proto to uri2proxy (andrei)
+*/
 
 
 #ifndef _TM_UT_H
@@ -41,7 +46,7 @@
 #include "../../str.h"
 #include "../../parser/msg_parser.h"
 
-inline static struct proxy_l *uri2proxy( str *uri )
+inline static struct proxy_l *uri2proxy( str *uri, int proto )
 {
        struct sip_uri parsed_uri;
        unsigned int  port; 
@@ -63,7 +68,7 @@ inline static struct proxy_l *uri2proxy( str *uri )
        /* fixed use of SRV resolver
        } else port=SIP_PORT; */
        } else port=0;
-       p=mk_proxy(&(parsed_uri.host), port);
+       p=mk_proxy(&(parsed_uri.host), port, proto);
        if (p==0) {
                LOG(L_ERR, "ERROR: t_relay: bad host name in URI <%.*s>\n",
                        uri->len, uri->s);
index 0ab2955..6a524e0 100644 (file)
@@ -175,7 +175,7 @@ static int check_via_address(struct ip_addr* ip, str *name,
        if (resolver&DO_DNS){
                DBG("check_address: doing dns lookup\n");
                /* try all names ips */
-               he=sip_resolvehost(name, &port);
+               he=sip_resolvehost(name, &port, 0); /* FIXME proto? */
                if (he && ip->af==he->h_addrtype){
                        for(i=0;he && he->h_addr_list[i];i++){
                                if ( memcmp(&he->h_addr_list[i], ip->u.addr, ip->len)==0)
diff --git a/proxy.c b/proxy.c
index 00c8079..5da694b 100644 (file)
--- a/proxy.c
+++ b/proxy.c
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+ /*
+  * History:
+  * -------
+  *  2003-02-13  all *proxy fucntions are now proto aware (andrei)
+  */
 
 
 
@@ -55,13 +60,17 @@ struct proxy_l* proxies=0;
 
 
 
-/* searches for the proxy named 'name', on port 'port'
+/* searches for the proxy named 'name', on port 'port' with 
+   proto 'proto'; if proto==0 => proto wildcard (will match any proto)
    returns: pointer to proxy_l on success or 0 if not found */ 
-static struct proxy_l* find_proxy(str *name, unsigned short port)
+static struct proxy_l* find_proxy(str *name, unsigned short port, int proto)
 {
        struct proxy_l* t;
        for(t=proxies; t; t=t->next)
-               if (((t->name.len == name->len) && (strncasecmp(t->name.s, name->s, name->len)==0)) && (t->port==port))
+               if (((t->name.len == name->len) &&
+                        ((proto==PROTO_NONE)||(t->proto==proto))&&
+                       (strncasecmp(t->name.s, name->s, name->len)==0)) &&
+                               (t->port==port))
                        break;
        return t;
 }
@@ -169,12 +178,12 @@ void free_hostent(struct hostent *dst)
 
 
 
-struct proxy_l* add_proxy(str* name, unsigned short port)
+struct proxy_l* add_proxy(str* name, unsigned short port, int proto)
 {
        struct proxy_l* p;
        
-       if ((p=find_proxy(name, port))!=0) return p;
-       if ((p=mk_proxy(name, port))==0) goto error;
+       if ((p=find_proxy(name, port, proto))!=0) return p;
+       if ((p=mk_proxy(name, port, proto))==0) goto error;
        /* add p to the proxy list */
        p->next=proxies;
        proxies=p;
@@ -188,9 +197,9 @@ error:
 
 
 /* same as add_proxy, but it doesn't add the proxy to the list
- * uses also SRV if possible (quick hack) */
+ * uses also SRV if possible & port==0 (quick hack) */
 
-struct proxy_l* mk_proxy(str* name, unsigned short port)
+struct proxy_l* mk_proxy(str* name, unsigned short port, int proto)
 {
        struct proxy_l* p;
        struct hostent* he;
@@ -204,9 +213,10 @@ struct proxy_l* mk_proxy(str* name, unsigned short port)
        memset(p,0,sizeof(struct proxy_l));
        p->name=*name;
        p->port=port;
+       p->proto=proto;
 
        DBG("DEBUG: mk_proxy: doing DNS lookup...\n");
-       he=sip_resolvehost(name, &(p->port));
+       he=sip_resolvehost(name, &(p->port), proto);
        if (he==0){
                ser_error=E_BAD_ADDRESS;
                LOG(L_CRIT, "ERROR: mk_proxy: could not resolve hostname:"
@@ -227,7 +237,8 @@ error:
 
 
 /* same as mk_proxy, but get the host as an ip*/
-struct proxy_l* mk_proxy_from_ip(struct ip_addr* ip, unsigned short port)
+struct proxy_l* mk_proxy_from_ip(struct ip_addr* ip, unsigned short port,
+                                                                       int proto)
 {
        struct proxy_l* p;
 
@@ -239,6 +250,7 @@ struct proxy_l* mk_proxy_from_ip(struct ip_addr* ip, unsigned short port)
        memset(p,0,sizeof(struct proxy_l));
 
        p->port=port;
+       p->proto=proto;
        p->host.h_addrtype=ip->af;
        p->host.h_length=ip->len;
        p->host.h_addr_list=malloc(2*sizeof(char*));
diff --git a/proxy.h b/proxy.h
index fc15b34..f2aa221 100644 (file)
--- a/proxy.h
+++ b/proxy.h
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+ /*
+  * History:
+  * -------
+  *  2003-02-13  added proto to struct proxy_l & to *_proxy fucntions (andrei)
+  */
 
 
 #ifndef proxy_h
@@ -40,6 +45,7 @@ struct proxy_l{
        struct hostent host; /* addresses */
        unsigned short port;
        unsigned short reserved; /*align*/
+       int proto;
        
        /* socket ? */
 
@@ -53,9 +59,10 @@ struct proxy_l{
 
 extern struct proxy_l* proxies;
 
-struct proxy_l* add_proxy(str* name, unsigned short port);
-struct proxy_l* mk_proxy(str* name, unsigned short port);
-struct proxy_l* mk_proxy_from_ip(struct ip_addr* ip, unsigned short port);
+struct proxy_l* add_proxy(str* name, unsigned short port, int proto);
+struct proxy_l* mk_proxy(str* name, unsigned short port, int proto);
+struct proxy_l* mk_proxy_from_ip(struct ip_addr* ip, unsigned short port,
+                                                                       int proto);
 void free_proxy(struct proxy_l* p);
 
 
index 6876d7c..ddf7308 100644 (file)
--- a/resolve.c
+++ b/resolve.c
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+/*
+ * History:
+ * -------
+ *  2003-02-13  added proto to sip_resolvehost, for SRV lookups (andrei)
+ */ 
 
 
 #include <sys/types.h>
@@ -448,10 +453,12 @@ not_found:
 
 /* resolves a host name trying SRV lookup if *port==0 or normal A/AAAA lookup
  * if *port!=0.
+ * when performing SRV lookup (*port==0) it will use proto to look for
+ * tcp or udp hosts, otherwise proto is unused; if proto==0 => no SRV lookup
  * returns: hostent struct & *port filled with the port from the SRV record;
  *  0 on error
  */
-struct hostent* sip_resolvehost(str* name, unsigned short* port)
+struct hostent* sip_resolvehost(str* name, unsigned short* port, int proto)
 {
        struct hostent* he;
        struct rdata* head;
@@ -477,9 +484,24 @@ struct hostent* sip_resolvehost(str* name, unsigned short* port)
                                return ip_addr2he(name,ip);
                        }
                        
-                       memcpy(tmp, SRV_PREFIX, SRV_PREFIX_LEN);
-                       memcpy(tmp+SRV_PREFIX_LEN, name->s, name->len);
-                       tmp[SRV_PREFIX_LEN + name->len] = '\0';
+                       switch(proto){
+                               case PROTO_NONE: /* no proto specified, use udp */
+                                       goto skip_srv;
+                               case PROTO_UDP:
+                                       memcpy(tmp, SRV_UDP_PREFIX, SRV_PREFIX_LEN);
+                                       memcpy(tmp+SRV_PREFIX_LEN, name->s, name->len);
+                                       tmp[SRV_PREFIX_LEN + name->len] = '\0';
+                                       break;
+                               case PROTO_TCP:
+                                       memcpy(tmp, SRV_TCP_PREFIX, SRV_PREFIX_LEN);
+                                       memcpy(tmp+SRV_PREFIX_LEN, name->s, name->len);
+                                       tmp[SRV_PREFIX_LEN + name->len] = '\0';
+                                       break;
+                               default:
+                                       LOG(L_CRIT, "BUG: sip_resolvehost: unknown proto %d\n",
+                                                       proto);
+                                       return 0;
+                       }
 
                        head=get_record(tmp, T_SRV);
                        for(l=head; l; l=l->next){
@@ -504,7 +526,7 @@ struct hostent* sip_resolvehost(str* name, unsigned short* port)
                                        " trying 'normal' lookup...\n", name->len, name->s);
                }
        }
-
+skip_srv:
        if (name->len >= MAX_DNS_NAME) {
                LOG(L_ERR, "sip_resolvehost: domain name too long\n");
                return 0;
index 8e73386..bf223d3 100644 (file)
--- a/resolve.h
+++ b/resolve.h
@@ -260,7 +260,7 @@ error_char:
 
 
 
-struct hostent* sip_resolvehost(str* name, unsigned short* port);
+struct hostent* sip_resolvehost(str* name, unsigned short* port, int proto);
 
 
 
diff --git a/route.c b/route.c
index 69b78c1..302dac9 100644 (file)
--- a/route.c
+++ b/route.c
@@ -169,7 +169,7 @@ static int fix_actions(struct action* a)
                                                case STRING_ST:
                                                        s.s = t->p1.string;
                                                        s.len = strlen(s.s);
-                                                       p=add_proxy(&s, t->p2.number);
+                                                       p=add_proxy(&s, t->p2.number, 0); /* FIXME proto*/
                                                        if (p==0) return E_BAD_ADDRESS;
                                                        t->p1.data=p;
                                                        t->p1_type=PROXY_ST;
diff --git a/tags.h b/tags.h
index 8f30998..a2efc47 100644 (file)
--- a/tags.h
+++ b/tags.h
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+/*
+ * History:
+ * --------
+ *  2003-02-18  changed TOTAG_LEN into TOTAG_VALUE_LEN, to solve
+ *               redefinition conflict with tm/t_msgbuilder.h (andrei)
+ */
 
 
 #ifndef _TAGS_H
@@ -42,7 +48,7 @@
 #include "crc.h"
 #include "str.h"
 
-#define TOTAG_LEN (MD5_LEN+CRC16_LEN+1)
+#define TOTAG_VALUE_LEN (MD5_LEN+CRC16_LEN+1)
 
 /* generate variable part of to-tag for a request;
  * it will have length of CRC16_LEN, sufficiently