Index: channel.c =================================================================== RCS file: /usr/cvsroot/asterisk/channel.c,v retrieving revision 1.179 diff -u -B -r1.179 channel.c --- channel.c 27 Mar 2005 21:58:10 -0000 1.179 +++ channel.c 28 Mar 2005 10:56:08 -0000 @@ -2050,8 +2050,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.215 diff -u -B -r1.215 pbx.c --- pbx.c 26 Mar 2005 21:01:59 -0000 1.215 +++ pbx.c 28 Mar 2005 10:56:27 -0000 @@ -1682,6 +1682,8 @@ int res = -1; int allunavailable = 1, allbusy = 1, allfree = 1; int busy = 0; + int inuse = 0; + int ring = 0; if (!e) return -1; @@ -1703,7 +1705,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; @@ -1722,7 +1732,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.696 diff -u -B -r1.696 chan_sip.c --- channels/chan_sip.c 28 Mar 2005 07:06:28 -0000 1.696 +++ channels/chan_sip.c 28 Mar 2005 10:56:53 -0000 @@ -4167,6 +4167,22 @@ char *mfrom, *mto; struct sip_request req; char clen[20]; + char *statestring; + + switch(state) { + case AST_EXTENSION_RINGING: + case AST_EXTENSION_RINGING_AND_INUSE: + statestring = "early"; + break; + case AST_EXTENSION_INUSE: + case AST_EXTENSION_BUSY: + statestring = "confirmed"; + break; + case AST_EXTENSION_UNAVAILABLE: + case AST_EXTENSION_NOT_INUSE: + default: + statestring = "terminated"; + } memset(from, 0, sizeof(from)); memset(to, 0, sizeof(to)); @@ -4184,26 +4200,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; @@ -4244,13 +4261,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) { + 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"); Index: include/asterisk/channel.h =================================================================== RCS file: /usr/cvsroot/asterisk/include/asterisk/channel.h,v retrieving revision 1.79 diff -u -B -r1.79 channel.h --- include/asterisk/channel.h 23 Mar 2005 21:52:31 -0000 1.79 +++ include/asterisk/channel.h 28 Mar 2005 10:56:56 -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.42 diff -u -B -r1.42 pbx.h --- include/asterisk/pbx.h 4 Mar 2005 06:36:18 -0000 1.42 +++ include/asterisk/pbx.h 28 Mar 2005 10:56:57 -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;