Index: channel.c =================================================================== RCS file: /usr/cvsroot/asterisk/channel.c,v retrieving revision 1.182 diff -u -B -b -r1.182 channel.c --- channel.c 30 Mar 2005 22:09:01 -0000 1.182 +++ channel.c 30 Mar 2005 23:55:45 -0000 @@ -2050,8 +2050,13 @@ cut = strchr(name,'-'); if (cut) *cut = 0; - if (!strcmp(name, device)) + 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 -b -r1.217 pbx.c --- pbx.c 29 Mar 2005 06:18:58 -0000 1.217 +++ pbx.c 30 Mar 2005 23:55:56 -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,6 +1741,12 @@ cur = rest; } while (cur); + 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) Index: channels/chan_sip.c =================================================================== RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v retrieving revision 1.700 diff -u -B -b -r1.700 chan_sip.c --- channels/chan_sip.c 30 Mar 2005 16:28:28 -0000 1.700 +++ channels/chan_sip.c 30 Mar 2005 23:56:23 -0000 @@ -4166,6 +4166,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)); @@ -4183,7 +4199,6 @@ reqprep(&req, p, SIP_NOTIFY, 0, 1); - if (p->subscribed == 1) { strncpy(to, get_header(&p->initreq, "To"), sizeof(to)-1); c = ditch_braces(to); @@ -4196,13 +4211,15 @@ } 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 +4260,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.80 diff -u -B -b -r1.80 channel.h --- include/asterisk/channel.h 28 Mar 2005 20:48:24 -0000 1.80 +++ include/asterisk/channel.h 30 Mar 2005 23:56:28 -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 -b -r1.43 pbx.h --- include/asterisk/pbx.h 29 Mar 2005 06:16:49 -0000 1.43 +++ include/asterisk/pbx.h 30 Mar 2005 23:56:29 -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;