- support for SCTP in contact building
authorDaniel-Constantin Mierla <miconda@gmail.com>
Sun, 8 Mar 2009 18:35:20 +0000 (18:35 +0000)
committerDaniel-Constantin Mierla <miconda@gmail.com>
Sun, 8 Mar 2009 18:35:20 +0000 (18:35 +0000)
- make sure the transport parameter is not added twice

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@5674 689a6050-402a-0410-94f2-e92a70836424

modules_k/presence/subscribe.c
modules_k/presence/utils_func.h

index 6b1880b..e3e3ab2 100644 (file)
@@ -63,6 +63,7 @@ int send_2XX_reply(struct sip_msg * msg, int reply_code, int lexpire,
 {
        str hdr_append = {0, 0};
        str tmp;
+       char *t = NULL;
        
        tmp.s = int2str((unsigned long)lexpire, &tmp.len);
        hdr_append.len = 9 + tmp.len + CRLF_LEN
@@ -80,26 +81,32 @@ int send_2XX_reply(struct sip_msg * msg, int reply_code, int lexpire,
        strncpy(tmp.s, "Contact: <", 10);
        tmp.s += 10;
        strncpy(tmp.s, local_contact->s, local_contact->len);
+       tmp.s[local_contact->len] = '\0';
+       t = strstr(tmp.s, ";transport=");
        tmp.s += local_contact->len;
-       switch (msg->rcv.proto)
-       {
-               case PROTO_TCP:
-                       strncpy(tmp.s, ";transport=tcp", 14);
-                       tmp.s += 14;
-                       hdr_append.len -= 1;
-               break;
-               case PROTO_TLS:
-                       strncpy(tmp.s, ";transport=tls", 14);
-                       tmp.s += 14;
-                       hdr_append.len -= 1;
-               break;
-               case PROTO_SCTP:
-                       strncpy(tmp.s, ";transport=sctp", 15);
-                       tmp.s += 15;
-                       hdr_append.len -= 1;
-               break;
-               default:
-                       hdr_append.len -= 15;
+       if(t==NULL)
+       {
+               switch (msg->rcv.proto)
+               {
+                       case PROTO_TCP:
+                               strncpy(tmp.s, ";transport=tcp", 14);
+                               tmp.s += 14;
+                               hdr_append.len -= 1;
+                       break;
+                       case PROTO_TLS:
+                               strncpy(tmp.s, ";transport=tls", 14);
+                               tmp.s += 14;
+                               hdr_append.len -= 1;
+                       break;
+                       case PROTO_SCTP:
+                               strncpy(tmp.s, ";transport=sctp", 15);
+                               tmp.s += 15;
+                       break;
+                       default:
+                               hdr_append.len -= 15;
+               }
+       } else {
+               hdr_append.len -= 15;
        }
        *tmp.s = '>';
        strncpy(tmp.s+1, CRLF, CRLF_LEN);
index 6b7b98f..19e6917 100644 (file)
@@ -84,6 +84,7 @@ static inline str* get_local_contact(struct sip_msg* msg)
        int port;
        int len;
        str* contact;
+       int plen;
 
        contact= (str*)pkg_malloc(sizeof(str));
        if(contact== NULL)
@@ -102,6 +103,7 @@ static inline str* get_local_contact(struct sip_msg* msg)
        memset(contact->s, 0, LCONTACT_BUF_SIZE);
        contact->len= 0;
        
+       plen = 3;
        if(msg->rcv.proto== PROTO_NONE || msg->rcv.proto==PROTO_UDP)
                proto= "udp";
        else
@@ -110,6 +112,11 @@ static inline str* get_local_contact(struct sip_msg* msg)
        else    
        if(msg->rcv.proto== PROTO_TCP)
                proto= "tcp";
+       else    
+       if(msg->rcv.proto== PROTO_SCTP) {
+               proto= "sctp";
+               plen = 4;
+       }
        else
        {
                LM_ERR("unsupported proto\n");
@@ -153,8 +160,8 @@ static inline str* get_local_contact(struct sip_msg* msg)
                return NULL;
        }       
        contact->len+= len;
-       strncpy(contact->s+ contact->len, proto, 3);
-       contact->len += 3;
+       strncpy(contact->s+ contact->len, proto, plen);
+       contact->len += plen;
        
        return contact;