Add steven's SIP update
authorMark Spencer <markster@digium.com>
Sun, 6 Apr 2003 23:32:31 +0000 (23:32 +0000)
committerMark Spencer <markster@digium.com>
Sun, 6 Apr 2003 23:32:31 +0000 (23:32 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@761 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_sip.c
manager.c

index 272a5a8..b33b269 100755 (executable)
@@ -1741,7 +1741,7 @@ static void add_route(struct sip_request *req, struct sip_route *route)
 
 static void set_destination(struct sip_pvt *p, char *uri)
 {
-       char *h, *maddr, hostname[256] = "";
+       char *h, *maddr, hostname[256];
        int port, hn;
        struct hostent *hp;
 
@@ -1751,16 +1751,22 @@ static void set_destination(struct sip_pvt *p, char *uri)
        if (sipdebug)
                ast_verbose("set_destination: Parsing <%s> for address/port to send to\n", uri);
 
+       /* Find and parse hostname */
        h = strchr(uri, '@');
-       if (!h) {
-               ast_log(LOG_WARNING, "set_destination: Can't parse sip URI '%s'\n", uri);
-               return;
+       if (h)
+               ++h;
+       else {
+               h = uri;
+               if (strncmp(h, "sip:", 4) == 0)
+                       h += 4;
+               else if (strncmp(h, "sips:", 5) == 0)
+                       h += 5;
        }
-       ++h;
        hn = strcspn(h, ":;>");
-       strncpy(hostname, h, (hn>255)?255:hn);
-       hostname[(hn > 255) ? 255 : hn] = '\0';
+       if (hn>255) hn=255;
+       strncpy(hostname, h, hn);  hostname[hn] = '\0';
        h+=hn;
+
        /* Is "port" present? if not default to 5060 */
        if (*h == ':') {
                /* Parse port */
@@ -1770,13 +1776,13 @@ static void set_destination(struct sip_pvt *p, char *uri)
        else
                port = 5060;
 
-       /* Got the hostname:port - but maybe there's a ";maddr=" to override address? */
-       maddr = strstr(h, ";maddr=");
+       /* Got the hostname:port - but maybe there's a "maddr=" to override address? */
+       maddr = strstr(h, "maddr=");
        if (maddr) {
-               maddr += 7;
+               maddr += 6;
                hn = strspn(maddr, "0123456789.");
-               strncpy(hostname, maddr, (hn>255)?255:hn);
-               hostname[(hn > 255) ? 255 : hn] = '\0';
+               if (hn>255) hn=255;
+               strncpy(hostname, maddr, hn);  hostname[hn] = '\0';
        }
        
        hp = gethostbyname(hostname);
@@ -1787,7 +1793,8 @@ static void set_destination(struct sip_pvt *p, char *uri)
        p->sa.sin_family = AF_INET;
        memcpy(&p->sa.sin_addr, hp->h_addr, sizeof(p->sa.sin_addr));
        p->sa.sin_port = htons(port);
-       ast_verbose("set_destination: set destination to %s, port %d\n", inet_ntoa(p->sa.sin_addr), port);
+       if (sipdebug)
+               ast_verbose("set_destination: set destination to %s, port %d\n", inet_ntoa(p->sa.sin_addr), port);
 }
 
 static int init_resp(struct sip_request *req, char *resp, struct sip_request *orig)
@@ -2677,11 +2684,10 @@ static void build_route(struct sip_pvt *p, struct sip_request *req, int backward
        }
        /* We build up head, then assign it to p->route when we're done */
        head = NULL;  tail = head;
-       /* 1st pass through all the hops in any Record-Route headers */
+       /* 1st we pass through all the hops in any Record-Route headers */
        for (;;) {
                /* Each Record-Route header */
                rr = __get_header(req, "Record-Route", &start);
-               /*ast_verbose("Record-Route: %s\n", rr);*/
                if (*rr == '\0') break;
                for (;;) {
                        /* Each route entry */
@@ -2695,7 +2701,7 @@ static void build_route(struct sip_pvt *p, struct sip_request *req, int backward
                        if (thishop) {
                                strncpy(thishop->hop, rr, len);
                                thishop->hop[len] = '\0';
-                               ast_verbose("build_route: Record-Route hop: <%s>\n", thishop->hop);
+                               ast_log(LOG_DEBUG, "build_route: Record-Route hop: <%s>\n", thishop->hop);
                                /* Link in */
                                if (backwards) {
                                        /* Link in at head so they end up in reverse order */
@@ -2732,14 +2738,16 @@ static void build_route(struct sip_pvt *p, struct sip_request *req, int backward
                        c = contact; len = strlen(contact);
                }
                thishop = (struct sip_route *)malloc(sizeof(struct sip_route)+len+1);
-               strncpy(thishop->hop, c, len);
-               thishop->hop[len] = '\0';
-               thishop->next = NULL;
-               /* Goes at the end */
-               if (tail)
-                       tail->next = thishop;
-               else
-                       head = thishop;
+               if (thishop) {
+                       strncpy(thishop->hop, c, len);
+                       thishop->hop[len] = '\0';
+                       thishop->next = NULL;
+                       /* Goes at the end */
+                       if (tail)
+                               tail->next = thishop;
+                       else
+                               head = thishop;
+               }
        }
        /* Store as new route */
        p->route = head;
index dba2144..cbb3c62 100755 (executable)
--- a/manager.c
+++ b/manager.c
@@ -677,6 +677,13 @@ int ast_manager_unregister( char *action ) {
        return 0;
 }
 
+static int manager_state_cb(char *context, char *exten, int state, void *data)
+{
+       /* Notify managers of change */
+       manager_event(EVENT_FLAG_CALL, "ExtensionStatus", "Exten: %s\r\nContext: %s\r\nStatus: %d\r\n", exten, context, state);
+       return 0;
+}
+
 int ast_manager_register( char *action, int auth, 
        int (*func)(struct mansession *s, struct message *m), char *synopsis)
 {
@@ -731,6 +738,7 @@ int init_manager(void)
 
                ast_cli_register(&show_mancmds_cli);
                ast_cli_register(&show_manconn_cli);
+               ast_extension_state_add(NULL, NULL, manager_state_cb, NULL);
                registered = 1;
        }
        portno = DEFAULT_MANAGER_PORT;