Index: chan_sip.c =================================================================== RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v retrieving revision 1.801 diff -u -r1.801 chan_sip.c --- chan_sip.c 3 Aug 2005 04:32:09 -0000 1.801 +++ chan_sip.c 3 Aug 2005 08:58:40 -0000 @@ -4489,11 +4489,11 @@ char *t = tmp, *c, *a, *mfrom, *mto; size_t maxbytes = sizeof(tmp); struct sip_request req; + char hint[AST_MAX_EXTENSION]; + struct sip_pvt *np = NULL; memset(from, 0, sizeof(from)); - memset(to, 0, sizeof(to)); ast_copy_string(from, get_header(&p->initreq, "From"), sizeof(from)); - c = get_in_brackets(from); if (strncmp(c, "sip:", 4)) { ast_log(LOG_WARNING, "Huh? Not a SIP header (%s)?\n", c); @@ -4504,32 +4504,31 @@ } mfrom = c; - reqprep(&req, p, SIP_NOTIFY, 0, 1); + memset(to, 0, sizeof(to)); + ast_copy_string(to, get_header(&p->initreq, "To"), sizeof(to)); + c = get_in_brackets(to); + if (strncmp(c, "sip:", 4)) { + ast_log(LOG_WARNING, "Huh? Not a SIP header (%s)?\n", c); + return -1; + } + if ((a = strchr(c, ';'))) { + *a = '\0'; + } + mto = c; - if (p->subscribed == 1) { - ast_copy_string(to, get_header(&p->initreq, "To"), sizeof(to)); + reqprep(&req, p, SIP_NOTIFY, 0, 1); - c = get_in_brackets(to); - if (strncmp(c, "sip:", 4)) { - ast_log(LOG_WARNING, "Huh? Not a SIP header (%s)?\n", c); - return -1; - } - if ((a = strchr(c, ';'))) { - *a = '\0'; - } - mto = c; + if ((state == AST_EXTENSION_UNAVAILABLE) || (state == AST_EXTENSION_BUSY)) + state = 2; + else if (state == AST_EXTENSION_INUSE) + state = 1; + else + state = 0; + if (p->subscribed == 1) { add_header(&req, "Event", "presence"); add_header(&req, "Subscription-State", "active"); add_header(&req, "Content-Type", "application/xpidf+xml"); - - if ((state==AST_EXTENSION_UNAVAILABLE) || (state==AST_EXTENSION_BUSY)) - state = 2; - else if (state==AST_EXTENSION_INUSE) - state = 1; - else - state = 0; - ast_build_string(&t, &maxbytes, "\n"); ast_build_string(&t, &maxbytes, "\n"); ast_build_string(&t, &maxbytes, "\n"); @@ -4543,9 +4542,47 @@ add_header(&req, "Event", "dialog"); add_header(&req, "Content-Type", "application/dialog-info+xml"); ast_build_string(&t, &maxbytes, "\n"); - ast_build_string(&t, &maxbytes, "\n", p->dialogver++, full ? "full":"partial", mfrom); - ast_build_string(&t, &maxbytes, "\n", p->exten); - ast_build_string(&t, &maxbytes, "%s\n", state ? "confirmed" : "terminated"); + ast_build_string(&t, &maxbytes, "\n", p->dialogver++, full ? "full":"partial", mto); + + /* Check which device/devices we are watching and if they are registered */ + if (ast_get_hint(hint, sizeof(hint), NULL, 0, NULL, p->context, p->exten)) { + /* check if the device is used and if so get the callid to enable pickup functionality (e.g. for snom phones) */ + if (state == AST_EXTENSION_BUSY || state == AST_EXTENSION_INUSE) { + struct ast_channel *chan = NULL; + char *hintp, *ampp = hint, *dashp = NULL; + int hintlen; + + /* take the hint apart (it may consist out of several channels). + * stops after the first matching channel */ + while (!np && (hintp = strsep(&p, "&"))) { + if (strncasecmp(hintp, "SIP", 3)) { /* only take care of hints for SIP channels */ + continue; + } + if ((dashp = strchr(hintp, '-'))) { /* ignore anything after the first dash */ + *dashp = '\0'; + } + hintlen = strlen(hintp); + while (!np && (chan = ast_channel_walk_locked(chan))) { + /* search for a matching channel (ringing, with private channel struct, matching channel name)*/ + if (chan->_state == AST_STATE_RINGING && chan->tech_pvt && !strncasecmp(chan->name, hintp, hintlen)) { + np = chan->tech_pvt; + ast_build_string(&t, &maxbytes, "\n", p->exten, np->callid, np->tag, np->theirtag); + ast_build_string(&t, &maxbytes, "early\n"); + ast_build_string(&t, &maxbytes, "%s\n", p->exten, mfrom, mfrom); + ast_build_string(&t, &maxbytes, "%s\n", np->fromname, mto, mto); + if (option_debug > 1) { + ast_log(LOG_NOTICE, "Transmitting CallID in NOTIFY message - DialogID: %s CallID: %s\n", p->exten, np->callid); + } + } + ast_mutex_unlock(&chan->lock); + } + } + } + } + if (!np) { /* we do not have any channel that we might pickup */ + ast_build_string(&t, &maxbytes, "\n", p->exten); + ast_build_string(&t, &maxbytes, "%s\n", state ? "confirmed" : "terminated"); + } ast_build_string(&t, &maxbytes, "\n\n"); } if (t > tmp + sizeof(tmp))