Index: channel.c =================================================================== RCS file: /usr/cvsroot/asterisk/channel.c,v retrieving revision 1.183 diff -u -B -r1.183 channel.c --- channel.c 31 Mar 2005 03:00:37 -0000 1.183 +++ channel.c 31 Mar 2005 16:22:43 -0000 @@ -2052,8 +2052,13 @@ cut = strchr(name,'-'); if (cut) *cut = 0; - if (!strcmp(name, device)) - return AST_DEVICE_INUSE; + if (!strcmp(name, device)) { + if (chan->_state == AST_STATE_RINGING) { + return AST_DEVICE_RINGING; + } else { + return AST_DEVICE_INUSE; + } + } chan = ast_channel_walk_locked(chan); } return AST_DEVICE_UNKNOWN; Index: pbx.c =================================================================== RCS file: /usr/cvsroot/asterisk/pbx.c,v retrieving revision 1.217 diff -u -B -r1.217 pbx.c --- pbx.c 29 Mar 2005 06:18:58 -0000 1.217 +++ pbx.c 31 Mar 2005 16:22:43 -0000 @@ -1691,6 +1691,8 @@ int res = -1; int allunavailable = 1, allbusy = 1, allfree = 1; int busy = 0; + int inuse = 0; + int ring = 0; if (!e) return -1; @@ -1712,7 +1714,15 @@ allbusy = 0; break; case AST_DEVICE_INUSE: - return AST_EXTENSION_INUSE; + inuse = 1; + allunavailable = 0; + allfree = 0; + break; + case AST_DEVICE_RINGING: + ring = 1; + allunavailable = 0; + allfree = 0; + break; case AST_DEVICE_BUSY: allunavailable = 0; allfree = 0; @@ -1731,7 +1741,13 @@ cur = rest; } while (cur); - if (allfree) + if (!inuse && ring) { + return AST_EXTENSION_RINGING;} + if (inuse && ring) { + return AST_EXTENSION_RINGING_AND_INUSE;} + if (inuse) + return AST_EXTENSION_INUSE; + if (allfree) return AST_EXTENSION_NOT_INUSE; if (allbusy) return AST_EXTENSION_BUSY; Index: channels/chan_sip.c =================================================================== RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v retrieving revision 1.700 diff -u -B -r1.700 chan_sip.c --- channels/chan_sip.c 30 Mar 2005 16:28:28 -0000 1.700 +++ channels/chan_sip.c 31 Mar 2005 16:22:44 -0000 @@ -172,6 +172,7 @@ #define DEFAULT_NOTIFYMIME "application/simple-message-summary" static char default_notifymime[AST_MAX_EXTENSION] = DEFAULT_NOTIFYMIME; +static int global_notifyringing = 0; static int default_qualify = 0; /* Default Qualify= setting */ @@ -4166,6 +4167,28 @@ char *mfrom, *mto; struct sip_request req; char clen[20]; + char *statestring; + + switch(state) { + case AST_EXTENSION_RINGING_AND_INUSE: + if (global_notifyringing) { + statestring = "confirmed"; + } else { + statestring = "early"; + } + break; + case AST_EXTENSION_RINGING: + statestring = "early"; + break; + case AST_EXTENSION_INUSE: + case AST_EXTENSION_BUSY: + case AST_EXTENSION_UNAVAILABLE: + statestring = "confirmed"; + break; + case AST_EXTENSION_NOT_INUSE: + default: + statestring = "terminated"; + } memset(from, 0, sizeof(from)); memset(to, 0, sizeof(to)); @@ -4183,26 +4206,27 @@ reqprep(&req, p, SIP_NOTIFY, 0, 1); - if (p->subscribed == 1) { - strncpy(to, get_header(&p->initreq, "To"), sizeof(to)-1); + strncpy(to, get_header(&p->initreq, "To"), sizeof(to)-1); + + c = ditch_braces(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; - c = ditch_braces(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) { 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) + else if (state==AST_EXTENSION_INUSE || state==AST_EXTENSION_RINGING || state==AST_EXTENSION_RINGING_AND_INUSE) state = 1; else state = 0; @@ -4243,13 +4267,17 @@ bytes = snprintf(t, maxbytes, "\n"); t += bytes; maxbytes -= bytes; - bytes = snprintf(t, maxbytes, "\n", p->dialogver++, full ? "full":"partial", mfrom); + bytes = snprintf(t, maxbytes, "\n", p->dialogver++, full ? "full":"partial", mto); t += bytes; maxbytes -= bytes; - bytes = snprintf(t, maxbytes, "\n", p->exten); + if (state == AST_EXTENSION_RINGING || (state==AST_EXTENSION_RINGING_AND_INUSE && !global_notifyringing)) { + bytes = snprintf(t, maxbytes, "\n", p->exten); + } else { + bytes = snprintf(t, maxbytes, "\n", p->exten); + } t += bytes; maxbytes -= bytes; - bytes = snprintf(t, maxbytes, "%s\n", state ? "confirmed" : "terminated"); + bytes = snprintf(t, maxbytes, "%s\n", statestring); t += bytes; maxbytes -= bytes; bytes = snprintf(t, maxbytes, "\n\n"); @@ -10108,6 +10136,7 @@ externrefresh = 10; strncpy(default_useragent, DEFAULT_USERAGENT, sizeof(default_useragent) - 1); strncpy(default_notifymime, DEFAULT_NOTIFYMIME, sizeof(default_notifymime) - 1); + global_notifyringing = 0; strncpy(global_realm, DEFAULT_REALM, sizeof(global_realm) - 1); strncpy(global_musicclass, "default", sizeof(global_musicclass) - 1); strncpy(default_callerid, DEFAULT_CALLERID, sizeof(default_callerid) - 1); @@ -10195,6 +10224,8 @@ compactheaders = ast_true(v->value); } else if (!strcasecmp(v->name, "notifymimetype")) { strncpy(default_notifymime, v->value, sizeof(default_notifymime) - 1); + } else if (!strcasecmp(v->name, "notifyringing")) { + global_notifyringing = ast_true(v->value); } else if (!strcasecmp(v->name, "musicclass") || !strcasecmp(v->name, "musiconhold")) { strncpy(global_musicclass, v->value, sizeof(global_musicclass) - 1); } else if (!strcasecmp(v->name, "language")) { Index: configs/sip.conf.sample =================================================================== RCS file: /usr/cvsroot/asterisk/configs/sip.conf.sample,v retrieving revision 1.61 diff -u -B -r1.61 sip.conf.sample --- configs/sip.conf.sample 24 Mar 2005 23:06:21 -0000 1.61 +++ configs/sip.conf.sample 31 Mar 2005 16:22:44 -0000 @@ -48,6 +48,9 @@ ;maxexpirey=3600 ; Max length of incoming registration we allow ;defaultexpirey=120 ; Default length of incoming/outoing registration ;notifymimetype=text/plain ; Allow overriding of mime type in MWI NOTIFY +;notifyringing ; Sent ringing (no) or inuse (yes) as state in + ; NOTIFY messages when observed extension is + ; in state RINGING_AND_INUSE (defaults to "no") ;checkmwi=10 ; Default time between mailbox checks for peers ;videosupport=yes ; Turn on support for SIP video ;recordhistory=yes ; Record SIP history by default Index: include/asterisk/channel.h =================================================================== RCS file: /usr/cvsroot/asterisk/include/asterisk/channel.h,v retrieving revision 1.80 diff -u -B -r1.80 channel.h --- include/asterisk/channel.h 28 Mar 2005 20:48:24 -0000 1.80 +++ include/asterisk/channel.h 31 Mar 2005 16:22:44 -0000 @@ -447,6 +447,8 @@ #define AST_DEVICE_INVALID 4 /*! Device is unavailable */ #define AST_DEVICE_UNAVAILABLE 5 +/*! Device is ringing */ +#define AST_DEVICE_RINGING 6 /*! Create a channel structure */ /*! Returns NULL on failure to allocate */ Index: include/asterisk/pbx.h =================================================================== RCS file: /usr/cvsroot/asterisk/include/asterisk/pbx.h,v retrieving revision 1.43 diff -u -B -r1.43 pbx.h --- include/asterisk/pbx.h 29 Mar 2005 06:16:49 -0000 1.43 +++ include/asterisk/pbx.h 31 Mar 2005 16:22:44 -0000 @@ -42,6 +42,10 @@ #define AST_EXTENSION_BUSY 2 /*! All devices UNAVAILABLE/UNREGISTERED */ #define AST_EXTENSION_UNAVAILABLE 3 +/*! One or more devices are RINGING and none are INUSE */ +#define AST_EXTENSION_RINGING 4 +/*! One or more devices are RINGING and one or more are INUSE */ +#define AST_EXTENSION_RINGING_AND_INUSE 5 struct ast_context; struct ast_exten;