Add steven's SIP update

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@761 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.0
Mark Spencer 22 years ago
parent 201246ea7f
commit c42b5f915d

@ -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) static void set_destination(struct sip_pvt *p, char *uri)
{ {
char *h, *maddr, hostname[256] = ""; char *h, *maddr, hostname[256];
int port, hn; int port, hn;
struct hostent *hp; struct hostent *hp;
@ -1751,16 +1751,22 @@ static void set_destination(struct sip_pvt *p, char *uri)
if (sipdebug) if (sipdebug)
ast_verbose("set_destination: Parsing <%s> for address/port to send to\n", uri); ast_verbose("set_destination: Parsing <%s> for address/port to send to\n", uri);
/* Find and parse hostname */
h = strchr(uri, '@'); h = strchr(uri, '@');
if (!h) { if (h)
ast_log(LOG_WARNING, "set_destination: Can't parse sip URI '%s'\n", uri); ++h;
return; else {
h = uri;
if (strncmp(h, "sip:", 4) == 0)
h += 4;
else if (strncmp(h, "sips:", 5) == 0)
h += 5;
} }
++h;
hn = strcspn(h, ":;>"); hn = strcspn(h, ":;>");
strncpy(hostname, h, (hn>255)?255:hn); if (hn>255) hn=255;
hostname[(hn > 255) ? 255 : hn] = '\0'; strncpy(hostname, h, hn); hostname[hn] = '\0';
h+=hn; h+=hn;
/* Is "port" present? if not default to 5060 */ /* Is "port" present? if not default to 5060 */
if (*h == ':') { if (*h == ':') {
/* Parse port */ /* Parse port */
@ -1770,13 +1776,13 @@ static void set_destination(struct sip_pvt *p, char *uri)
else else
port = 5060; port = 5060;
/* Got the hostname:port - but maybe there's a ";maddr=" to override address? */ /* Got the hostname:port - but maybe there's a "maddr=" to override address? */
maddr = strstr(h, ";maddr="); maddr = strstr(h, "maddr=");
if (maddr) { if (maddr) {
maddr += 7; maddr += 6;
hn = strspn(maddr, "0123456789."); hn = strspn(maddr, "0123456789.");
strncpy(hostname, maddr, (hn>255)?255:hn); if (hn>255) hn=255;
hostname[(hn > 255) ? 255 : hn] = '\0'; strncpy(hostname, maddr, hn); hostname[hn] = '\0';
} }
hp = gethostbyname(hostname); hp = gethostbyname(hostname);
@ -1787,7 +1793,8 @@ static void set_destination(struct sip_pvt *p, char *uri)
p->sa.sin_family = AF_INET; p->sa.sin_family = AF_INET;
memcpy(&p->sa.sin_addr, hp->h_addr, sizeof(p->sa.sin_addr)); memcpy(&p->sa.sin_addr, hp->h_addr, sizeof(p->sa.sin_addr));
p->sa.sin_port = htons(port); 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) 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 */ /* We build up head, then assign it to p->route when we're done */
head = NULL; tail = head; 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 (;;) { for (;;) {
/* Each Record-Route header */ /* Each Record-Route header */
rr = __get_header(req, "Record-Route", &start); rr = __get_header(req, "Record-Route", &start);
/*ast_verbose("Record-Route: %s\n", rr);*/
if (*rr == '\0') break; if (*rr == '\0') break;
for (;;) { for (;;) {
/* Each route entry */ /* Each route entry */
@ -2695,7 +2701,7 @@ static void build_route(struct sip_pvt *p, struct sip_request *req, int backward
if (thishop) { if (thishop) {
strncpy(thishop->hop, rr, len); strncpy(thishop->hop, rr, len);
thishop->hop[len] = '\0'; 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 */ /* Link in */
if (backwards) { if (backwards) {
/* Link in at head so they end up in reverse order */ /* 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); c = contact; len = strlen(contact);
} }
thishop = (struct sip_route *)malloc(sizeof(struct sip_route)+len+1); thishop = (struct sip_route *)malloc(sizeof(struct sip_route)+len+1);
strncpy(thishop->hop, c, len); if (thishop) {
thishop->hop[len] = '\0'; strncpy(thishop->hop, c, len);
thishop->next = NULL; thishop->hop[len] = '\0';
/* Goes at the end */ thishop->next = NULL;
if (tail) /* Goes at the end */
tail->next = thishop; if (tail)
else tail->next = thishop;
head = thishop; else
head = thishop;
}
} }
/* Store as new route */ /* Store as new route */
p->route = head; p->route = head;

@ -677,6 +677,13 @@ int ast_manager_unregister( char *action ) {
return 0; 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 ast_manager_register( char *action, int auth,
int (*func)(struct mansession *s, struct message *m), char *synopsis) 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_mancmds_cli);
ast_cli_register(&show_manconn_cli); ast_cli_register(&show_manconn_cli);
ast_extension_state_add(NULL, NULL, manager_state_cb, NULL);
registered = 1; registered = 1;
} }
portno = DEFAULT_MANAGER_PORT; portno = DEFAULT_MANAGER_PORT;

Loading…
Cancel
Save