Update of /usr/cvsroot/asterisk/channels
In directory mongoose.digium.com:/tmp/cvs-serv5847/channels

Modified Files:
        chan_sip.c 
Log Message:
various niteroperability fixes (issue #5221)


Index: chan_sip.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v
retrieving revision 1.855
retrieving revision 1.856
diff -u -d -r1.855 -r1.856
--- chan_sip.c  14 Sep 2005 20:46:49 -0000      1.855
+++ chan_sip.c  14 Sep 2005 21:41:02 -0000      1.856
@@ -3876,16 +3876,18 @@
        copy_header(resp, req, "CSeq");
        add_header(resp, "User-Agent", default_useragent);
        add_header(resp, "Allow", ALLOWED_METHODS);
-       if (p->expiry) {
+       if (msg[0] == '2' && (p->method == SIP_SUBSCRIBE || p->method == 
SIP_REGISTER)) {
                /* For registration responses, we also need expiry and
                   contact info */
-               char contact[256];
                char tmp[256];
 
-               snprintf(contact, sizeof(contact), "%s;expires=%d", 
p->our_contact, p->expiry);
                snprintf(tmp, sizeof(tmp), "%d", p->expiry);
                add_header(resp, "Expires", tmp);
-               add_header(resp, "Contact", contact);
+               if (p->expiry) {        /* Only add contact if we have an 
expiry time */
+                       char contact[256];
+                       snprintf(contact, sizeof(contact), "%s;expires=%d", 
p->our_contact, p->expiry);
+                       add_header(resp, "Contact", contact);   /* Not when we 
unregister */
+               }
        } else if (p->our_contact[0]) {
                add_header(resp, "Contact", p->our_contact);
        }
@@ -4798,7 +4800,10 @@
                break;
                break;
        default:
-               add_header(&req, "Subscription-State", "active");
+               if (p->expiry)
+                       add_header(&req, "Subscription-State", "active");
+               else    /* Expired */
+                       add_header(&req, "Subscription-State", 
"terminated;reason=timeout");
        }
        switch (p->subscribed) {
        case XPIDF_XML:
@@ -5523,9 +5528,12 @@
        struct sockaddr_in oldsin;
 
        if (ast_strlen_zero(expires)) { /* No expires header */
-               expires = strcasestr(get_header(req, "Contact"), "expires=");
+               expires = strcasestr(get_header(req, "Contact"), ";expires=");
                if (expires) {
-                       if (sscanf(expires + 8, "%d;", &expiry) != 1)
+                       char *ptr;
+                       if ((ptr = strchr(expires, ';')))
+                               *ptr = '\0';
+                       if (sscanf(expires + 9, "%d", &expiry) != 1)
                                expiry = default_expiry;
                } else {
                        /* Nothing has been specified */
@@ -5534,6 +5542,11 @@
        }
        /* Look for brackets */
        ast_copy_string(contact, get_header(req, "Contact"), sizeof(contact));
+       if (strchr(contact, '<') == NULL) {     /* No <, check for ; and strip 
it */
+               char *ptr = strchr(contact, ';');       /* This is Header 
options, not URI options */
+               if (ptr)
+                       *ptr = '\0';
+       }
        c = get_in_brackets(contact);
 
        if (!strcasecmp(c, "*") || !expiry) {   /* Unregister this peer */
@@ -10242,7 +10255,6 @@
                                } else if (strstr(accept, 
"application/dialog-info+xml")) {
                                        p->subscribed = DIALOG_INFO_XML;
                                        /* IETF draft: 
draft-ietf-sipping-dialog-package-05.txt */
-                                       /* Should not be used for SUBSCRIBE, 
but anyway */
                                } else if (strstr(accept, 
"application/cpim-pidf+xml")) {
                                        p->subscribed = CPIM_PIDF_XML;    /* 
RFC 3863 format */
                                } else if (strstr(accept, 
"application/xpidf+xml")) {
@@ -10297,11 +10309,8 @@
        if (!ignore && p)
                p->lastinvite = seqno;
        if (p && !ast_test_flag(p, SIP_NEEDDESTROY)) {
-               if (!(p->expiry = atoi(get_header(req, "Expires")))) {
-                       transmit_response(p, "200 OK", req);
-                       ast_set_flag(p, SIP_NEEDDESTROY);       
-                       return 0;
-               }
+               p->expiry = atoi(get_header(req, "Expires"));
+
                /* The next 4 lines can be removed if the SNOM Expires bug is 
fixed */
                if (p->subscribed == DIALOG_INFO_XML) {  
                        if (p->expiry > max_expiry)
@@ -10323,6 +10332,8 @@
                        transmit_state_notify(p, firststate, 1, 1);     /* Send 
first notification */
                        append_history(p, "Subscribestatus", 
ast_extension_state2str(firststate));
                }
+               if (!p->expiry)
+                       ast_set_flag(p, SIP_NEEDDESTROY);       
        }
        return 1;
 }

_______________________________________________
Asterisk-Cvs mailing list
[email protected]
http://lists.digium.com/mailman/listinfo/asterisk-cvs

Reply via email to