Index: channels/chan_sip.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v
retrieving revision 1.759
diff -u -r1.759 chan_sip.c
--- channels/chan_sip.c 9 Jun 2005 22:41:18 -0000 1.759
+++ channels/chan_sip.c 10 Jun 2005 20:00:51 -0000
@@ -193,6 +193,8 @@
#define DEFAULT_CONTEXT "default"
static char default_context[AST_MAX_EXTENSION] = DEFAULT_CONTEXT;
+static char default_subscribecontext[AST_MAX_EXTENSION];
+static char regcontext[AST_MAX_EXTENSION] = ""; /* Context for auto-extensions */
static char default_language[MAX_LANGUAGE] = "";
@@ -204,6 +206,8 @@
#define DEFAULT_NOTIFYMIME "application/simple-message-summary"
static char default_notifymime[AST_MAX_EXTENSION] = DEFAULT_NOTIFYMIME;
+static int global_notifyringing = 1; /* Send notifications on ringing */
+
static int default_qualify = 0; /* Default Qualify= setting */
@@ -281,7 +285,6 @@
static char global_musicclass[MAX_LANGUAGE] = ""; /* Global music on hold class */
#define DEFAULT_REALM "asterisk"
static char global_realm[MAXHOSTNAMELEN] = DEFAULT_REALM; /* Default realm */
-static char regcontext[AST_MAX_EXTENSION] = ""; /* Context for auto-extensions */
/* Expire slowly */
#define DEFAULT_EXPIRY 900
@@ -446,6 +449,7 @@
char from[256]; /* The From: header */
char useragent[256]; /* User agent in SIP request */
char context[AST_MAX_EXTENSION]; /* Context for this call */
+ char subscribecontext[AST_MAX_EXTENSION]; /* Subscribecontext */
char fromdomain[MAXHOSTNAMELEN]; /* Domain to show in the from field */
char fromuser[AST_MAX_EXTENSION]; /* User to show in the user field */
char fromname[AST_MAX_EXTENSION]; /* Name to show in the user field */
@@ -493,7 +497,8 @@
int rtpkeepalive; /* Send RTP packets for keepalive */
int subscribed; /* Is this call a subscription? */
- int stateid;
+ int stateid;
+ int laststate; /* Last known state */
int dialogver;
struct ast_dsp *vad; /* Voice Activation Detection dsp */
@@ -530,6 +535,7 @@
char secret[80]; /* Password */
char md5secret[80]; /* Password in md5 */
char context[AST_MAX_EXTENSION]; /* Default context for incoming calls */
+ char subscribecontext[AST_MAX_EXTENSION]; /* Default context for subscriptions */
char cid_num[80]; /* Caller ID num */
char cid_name[80]; /* Caller ID name */
char accountcode[AST_MAX_ACCOUNT_CODE]; /* Account code */
@@ -560,6 +566,7 @@
char md5secret[80]; /* Password in MD5 */
struct sip_auth *auth; /* Realm authentication list */
char context[AST_MAX_EXTENSION]; /* Default context for incoming calls */
+ char subscribecontext[AST_MAX_EXTENSION]; /* Default context for subscriptions */
char username[80]; /* Temporary username until registration */
char accountcode[AST_MAX_ACCOUNT_CODE]; /* Account code */
int amaflags; /* AMA Flags (for billing) */
@@ -575,6 +582,7 @@
int incominglimit; /* Limit of incoming calls */
int outUse; /* disabled */
int outgoinglimit; /* disabled */
+ char mailbox_exten[AST_MAX_EXTENSION]; /* Message account for MWI checks */
char mailbox[AST_MAX_EXTENSION]; /* Mailbox setting for MWI checks */
char language[MAX_LANGUAGE]; /* Default language for prompts */
char musicclass[MAX_LANGUAGE]; /* Music on Hold class */
@@ -728,6 +736,7 @@
static int clear_realm_authentication(struct sip_auth *authlist); /* Clear realm authentication list (at reload) */
static struct sip_auth *add_realm_authentication(struct sip_auth *authlist, char *configuration, int lineno); /* Add realm authentication in list */
static struct sip_auth *find_realm_authentication(struct sip_auth *authlist, char *realm); /* Find authentication for a specific realm */
+static void append_date(struct sip_request *req);
/* Definition of this channel for channel registration */
static const struct ast_channel_tech sip_tech = {
@@ -3579,7 +3588,7 @@
return 0;
}
-/*--- reqprep: Initialize a SIP request packet ---*/
+/*--- reqprep: Initialize a SIP request response packet ---*/
static int reqprep(struct sip_request *req, struct sip_pvt *p, int sipmethod, int seqno, int newbranch)
{
struct sip_request *orig = &p->initreq;
@@ -3593,7 +3602,7 @@
snprintf(p->lastmsg, sizeof(p->lastmsg), "Tx: %s", sip_methods[sipmethod].text);
- if (!seqno) {
+ if (!seqno) { /* Raise our CSEQ */
p->ocseq++;
seqno = p->ocseq;
}
@@ -3668,7 +3677,12 @@
add_header(req, "From", ot);
add_header(req, "To", of);
}
- add_header(req, "Contact", p->our_contact);
+ if (sipmethod == SIP_MESSAGE) {
+ /* Add date header to MESSAGE */
+ append_date(req);
+ } else {
+ add_header(req, "Contact", p->our_contact);
+ }
copy_header(req, orig, "Call-ID");
add_header(req, "CSeq", tmp);
@@ -4346,12 +4360,73 @@
{
char tmp[4000];
int maxbytes = 0;
- int bytes = 0;
char from[256], to[256];
- char *t, *c, *a;
+ char *t = NULL, *c, *a;
char *mfrom, *mto;
struct sip_request req;
char clen[20];
+ char hint[AST_MAX_EXTENSION];
+ int hintstate = 1;
+ char *statestring;
+ char *pidfstate;
+ char *pidfnote;
+ int local_state = 0;
+
+ /* Check which device/devices we are watching and if they are registred */
+ /* If they are not registred, we will override notification and show no availability */
+ if (ast_get_hint(hint, sizeof(hint), NULL, 0, NULL, p->context, p->exten)) {
+ if(ast_device_state(hint) == AST_DEVICE_UNAVAILABLE)
+ hintstate = 0; /* Not registred */
+ }
+ pidfnote = "Ready";
+ statestring = "terminated";
+ pidfstate = "--";
+
+ switch(state) {
+ case AST_EXTENSION_RINGING_AND_INUSE:
+ if (global_notifyringing) {
+ statestring = "early";
+ } else {
+ statestring = "confirmed";
+ }
+ local_state = 1; /* In use */
+ pidfstate = "busy";
+ pidfnote = "Ringing";
+ break;
+ case AST_EXTENSION_RINGING:
+ statestring = "early";
+ local_state = 1; /* In use */
+ pidfstate = "busy";
+ pidfnote = "Ringing";
+ break;
+ case AST_EXTENSION_INUSE:
+ statestring = "confirmed";
+ local_state = 1; /* In use */
+ pidfstate = "busy";
+ pidfnote = "On the phone";
+ break;
+ case AST_EXTENSION_BUSY:
+ statestring = "confirmed";
+ local_state = 2; /* Closed */
+ pidfstate = "busy";
+ pidfnote = "On the phone";
+ break;
+ case AST_EXTENSION_UNAVAILABLE:
+ statestring = "confirmed";
+ local_state = 2; /* Closed */
+ pidfstate = "away";
+ pidfnote = "Unavailable";
+ break;
+ case AST_EXTENSION_NOT_INUSE:
+ default:
+ /* Default setting */
+ break;
+ }
+ if (!hintstate) { /* Not registred, override */
+ local_state = 2; /* closed */
+ pidfstate = "away";
+ pidfnote = "Not online";
+ }
memset(from, 0, sizeof(from));
memset(to, 0, sizeof(to));
@@ -4369,76 +4444,77 @@
reqprep(&req, p, SIP_NOTIFY, 0, 1);
- if (p->subscribed == 1) {
- ast_copy_string(to, get_header(&p->initreq, "To"), sizeof(to));
-
- 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;
+ ast_copy_string(to, get_header(&p->initreq, "To"), sizeof(to));
+ 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 || p->subscribed == 3) {
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;
-
t = tmp;
maxbytes = sizeof(tmp);
- bytes = snprintf(t, maxbytes, "\n");
- t += bytes;
- maxbytes -= bytes;
- bytes = snprintf(t, maxbytes, "\n");
- t += bytes;
- maxbytes -= bytes;
- bytes = snprintf(t, maxbytes, "\n");
- t += bytes;
- maxbytes -= bytes;
- bytes = snprintf(t, maxbytes, "\n", mfrom);
- t += bytes;
- maxbytes -= bytes;
- bytes = snprintf(t, maxbytes, "\n", p->exten);
- t += bytes;
- maxbytes -= bytes;
- bytes = snprintf(t, maxbytes, "\n", mto);
- t += bytes;
- maxbytes -= bytes;
- bytes = snprintf(t, maxbytes, "\n", !state ? "open" : (state==1) ? "inuse" : "closed");
- t += bytes;
- maxbytes -= bytes;
- bytes = snprintf(t, maxbytes, "\n", !state ? "online" : (state==1) ? "onthephone" : "offline");
- t += bytes;
- maxbytes -= bytes;
- bytes = snprintf(t, maxbytes, "\n\n\n");
- } else {
+ ast_build_string(&t, &maxbytes, "\n");
+ ast_build_string(&t, &maxbytes, "\n");
+ ast_build_string(&t, &maxbytes, "\n");
+ ast_build_string(&t, &maxbytes, "\n", mfrom);
+ ast_build_string(&t, &maxbytes, "\n", p->exten);
+ ast_build_string(&t, &maxbytes, "\n", mto);
+ ast_build_string(&t, &maxbytes, "\n", !local_state ? "open" : (local_state==1) ? "inuse" : "closed");
+ ast_build_string(&t, &maxbytes, "\n", !local_state ? "online" : (local_state==1) ? "onthephone" : "offline");
+ ast_build_string(&t, &maxbytes, "\n\n\n");
+ } else if (p->subscribed == 4) { /* pidf+xml */
+ /* Eyebeam supports this format */
+ add_header(&req, "Event", "presence");
+ add_header(&req, "Subscription-State", "active");
+ add_header(&req, "Content-Type", "application/pidf+xml");
+ t = tmp;
+ maxbytes = sizeof(tmp);
+ ast_build_string(&t, &maxbytes, "\n");
+ ast_build_string(&t, &maxbytes, "\n", mfrom);
+ ast_build_string(&t, &maxbytes, "\n");
+ if (pidfstate[0] != '-') {
+ ast_build_string(&t, &maxbytes, "%s\n", pidfstate);
+ }
+ ast_build_string(&t, &maxbytes, "\n");
+ /* Note */
+ ast_build_string(&t, &maxbytes, "%s\n", pidfnote);
+ /* Tuple start */
+ ast_build_string(&t, &maxbytes, "\n", p->exten);
+ ast_build_string(&t, &maxbytes, "%s\n", mto);
+
+ if (pidfstate[0] == 'b') /* Busy? Still open ... */
+ ast_build_string(&t, &maxbytes, "open\n");
+ else
+ ast_build_string(&t, &maxbytes, "%s\n", local_state != 2 ? "open" : "closed");
+
+
+ ast_build_string(&t, &maxbytes, "\n\n");
+ } else if (p->subscribed == 2) {
+ /* SNOM 360 subscribes in this format */
add_header(&req, "Event", "dialog");
add_header(&req, "Content-Type", "application/dialog-info+xml");
t = tmp;
maxbytes = sizeof(tmp);
- bytes = snprintf(t, maxbytes, "\n");
- t += bytes;
- maxbytes -= bytes;
- bytes = snprintf(t, maxbytes, "\n", p->dialogver++, full ? "full":"partial", mfrom);
- t += bytes;
- maxbytes -= bytes;
- bytes = snprintf(t, maxbytes, "\n\n");
+ ast_build_string(&t, &maxbytes, "\n");
+ ast_build_string(&t, &maxbytes, "\n", p->dialogver++, full ? "full":"partial", mto);
+ if (state == AST_EXTENSION_RINGING || (state==AST_EXTENSION_RINGING_AND_INUSE && global_notifyringing)) {
+ ast_build_string(&t, &maxbytes, "\n");
}
if (t > tmp + sizeof(tmp))
ast_log(LOG_WARNING, "Buffer overflow detected!! (Please file a bug report)\n");
@@ -4456,22 +4532,25 @@
* We use the SIP Event package message-summary
* MIME type defaults to "application/simple-message-summary";
*/
-static int transmit_notify_with_mwi(struct sip_pvt *p, int newmsgs, int oldmsgs)
+static int transmit_notify_with_mwi(struct sip_pvt *p, int newmsgs, int oldmsgs, char *mailbox_exten)
{
struct sip_request req;
char tmp[256];
char tmp2[256];
+ char tmp3[256];
char clen[20];
initreqprep(&req, p, SIP_NOTIFY, NULL);
add_header(&req, "Event", "message-summary");
add_header(&req, "Content-Type", default_notifymime);
- snprintf(tmp, sizeof(tmp), "Messages-Waiting: %s\r\n", newmsgs ? "yes" : "no");
- snprintf(tmp2, sizeof(tmp2), "Voice-Message: %d/%d\r\n", newmsgs, oldmsgs);
- snprintf(clen, sizeof(clen), "%d", (int)(strlen(tmp) + strlen(tmp2)));
+ snprintf(tmp, sizeof(tmp), "Message-Account: sip:%s@%s\r\n", (mailbox_exten && !ast_strlen_zero(mailbox_exten)) ? mailbox_exten : default_callerid, p->fromdomain);
+ snprintf(tmp2, sizeof(tmp2), "Messages-Waiting: %s\r\n", newmsgs ? "yes" : "no");
+ snprintf(tmp3, sizeof(tmp3), "Voice-Message: %d/%d\r\n", newmsgs, oldmsgs);
+ snprintf(clen, sizeof(clen), "%d", (int)(strlen(tmp) + strlen(tmp2) + strlen(tmp3)));
add_header(&req, "Content-Length", clen);
add_line(&req, tmp);
add_line(&req, tmp2);
+ add_line(&req, tmp3);
if (!p->initreq.headers) {
/* Use this as the basis */
@@ -5360,7 +5439,7 @@
#endif
)
return 0;
- if (sipmethod == SIP_REGISTER) {
+ if (sipmethod == SIP_REGISTER || sipmethod == SIP_SUBSCRIBE) {
/* On a REGISTER, we have to use 401 and its family of headers instead of 407 and its family
of headers -- GO SIP! Whoo hoo! Two things that do the same thing but are used in
different circumstances! What a surprise. */
@@ -5544,10 +5623,13 @@
return res;
}
-/*--- cb_extensionstate: Part of thte SUBSCRIBE support subsystem ---*/
+/*--- cb_extensionstate: Callback for the devicestate notification (SUBSCRIBE) support subsystem ---*/
+/* If you add an "hint" priority to the extension in the dial plan,
+ you will get notifications on device state changes */
static int cb_extensionstate(char *context, char* exten, int state, void *data)
{
- struct sip_pvt *p = data;
+ struct sip_pvt *p = data; /* The actual subscription data */
+
if (state == -1) {
sip_scheddestroy(p, 15000);
p->stateid = -1;
@@ -5555,6 +5637,7 @@
}
transmit_state_notify(p, state, 1);
+ p->laststate = state;
if (option_debug > 1)
ast_verbose(VERBOSE_PREFIX_1 "Extension Changed %s new state %d for Notify User %s\n", exten, state, p->username);
@@ -6214,6 +6297,7 @@
ast_copy_string(p->cid_name, user->cid_name, sizeof(p->cid_name));
ast_copy_string(p->username, user->name, sizeof(p->username));
ast_copy_string(p->peersecret, user->secret, sizeof(p->peersecret));
+ ast_copy_string(p->subscribecontext, user->subscribecontext, sizeof(p->subscribecontext));
ast_copy_string(p->peermd5secret, user->md5secret, sizeof(p->peermd5secret));
ast_copy_string(p->accountcode, user->accountcode, sizeof(p->accountcode));
ast_copy_string(p->language, user->language, sizeof(p->language));
@@ -6271,6 +6355,7 @@
}
ast_copy_string(p->peersecret, peer->secret, sizeof(p->peersecret));
p->peersecret[sizeof(p->peersecret)-1] = '\0';
+ ast_copy_string(p->subscribecontext, peer->subscribecontext, sizeof(p->subscribecontext));
ast_copy_string(p->peermd5secret, peer->md5secret, sizeof(p->peermd5secret));
p->peermd5secret[sizeof(p->peermd5secret)-1] = '\0';
p->callingpres = peer->callingpres;
@@ -6377,16 +6462,30 @@
/*--- receive_message: Receive SIP MESSAGE method messages ---*/
-/* we handle messages within current calls currently */
+/* We only handle messages within current calls currently */
+/* Reference: RFC 3428 */
static void receive_message(struct sip_pvt *p, struct sip_request *req)
{
char buf[1024];
struct ast_frame f;
+ char *content_type;
+
+ content_type = get_header(req, "Content-Type");
+
+ if (strcmp(content_type, "text/plain")) {
+ /* No text/plain attachment */
+ transmit_response(p, "415 unsupported media type", req); /* Good enough or? */
+ ast_set_flag(p, SIP_NEEDDESTROY);
+ return;
+ }
if (get_msg_text(buf, sizeof(buf), req)) {
ast_log(LOG_WARNING, "Unable to retrieve text from %s\n", p->callid);
+ transmit_response(p, "202 Accepted", req);
+ ast_set_flag(p, SIP_NEEDDESTROY);
return;
}
+
if (p->owner) {
if (sip_debug_test_pvt(p))
ast_verbose("Message received: '%s'\n", buf);
@@ -6397,7 +6496,16 @@
f.data = buf;
f.datalen = strlen(buf);
ast_queue_frame(p->owner, &f);
+ /* Should we respond somehow? */
+ transmit_response(p, "202 Accepted", req);
+ /* We should respond 202 accepted, since we relay the message */
+ } else {
+ /* Message outside of a call, we do not support that */
+ ast_log(LOG_WARNING,"Received message to %s from %s, dropped it...\n Content-Type:%s\n Message: %s\n", get_header(req,"To"), get_header(req,"From"), content_type, buf);
+ transmit_response(p, "405 Method not allowed", req); /* Good enough or? */
}
+ ast_set_flag(p, SIP_NEEDDESTROY);
+ return;
}
/*--- sip_show_inuse: CLI Command to show calls within limits set by
@@ -7256,6 +7364,7 @@
static int __sip_show_channels(int fd, int argc, char *argv[], int subscriptions)
{
+#define FORMAT4 "%-15.15s %-10.10s %-21.21s %-15.15s %10s\n"
#define FORMAT3 "%-15.15s %-10.10s %-21.21s %-15.15s\n"
#define FORMAT2 "%-15.15s %-10.10s %-11.11s %-11.11s %s %s\n"
#define FORMAT "%-15.15s %-10.10s %-11.11s %5.5d/%5.5d %-6.6s%s %s\n"
@@ -7269,7 +7378,7 @@
if (!subscriptions)
ast_cli(fd, FORMAT2, "Peer", "User/ANR", "Call ID", "Seq (Tx/Rx)", "Format", "Last Msg");
else
- ast_cli(fd, FORMAT3, "Peer", "User", "Call ID", "URI");
+ ast_cli(fd, FORMAT4, "Peer", "User", "Call ID", "Extension", "Last state");
while (cur) {
if (!cur->subscribed && !subscriptions) {
ast_cli(fd, FORMAT, ast_inet_ntoa(iabuf, sizeof(iabuf), cur->sa.sin_addr),
@@ -7282,10 +7391,10 @@
numchans++;
}
if (cur->subscribed && subscriptions) {
- ast_cli(fd, FORMAT3, ast_inet_ntoa(iabuf, sizeof(iabuf), cur->sa.sin_addr),
+ ast_cli(fd, FORMAT4, ast_inet_ntoa(iabuf, sizeof(iabuf), cur->sa.sin_addr),
ast_strlen_zero(cur->username) ? ( ast_strlen_zero(cur->cid_num) ? "(None)" : cur->cid_num ) : cur->username,
- cur->callid, cur->uri);
-
+ cur->callid, cur->exten, ast_state2str(cur->laststate));
+ numchans++;
}
cur = cur->next;
}
@@ -7298,6 +7407,7 @@
#undef FORMAT
#undef FORMAT2
#undef FORMAT3
+#undef FORMAT4
}
/*--- complete_sipch: Support routine for 'sip show channel' CLI ---*/
@@ -8316,7 +8426,7 @@
}
}
if (!peer->lastms)
- statechanged = 1;
+ statechanged = 1;
peer->lastms = pingtime;
peer->call = NULL;
if (statechanged) {
@@ -9200,16 +9310,12 @@
/*--- handle_request_message: Handle incoming MESSAGE request ---*/
static int handle_request_message(struct sip_pvt *p, struct sip_request *req, int debug, int ignore)
{
- if (p->lastinvite) {
- if (!ignore) {
- if (debug)
- ast_verbose("Receiving message!\n");
- receive_message(p, req);
- }
- transmit_response(p, "200 OK", req);
+ if (!ignore) {
+ if (debug)
+ ast_verbose("Receiving message!\n");
+ receive_message(p, req);
} else {
- transmit_response(p, "405 Method Not Allowed", req);
- ast_set_flag(p, SIP_NEEDDESTROY);
+ transmit_response(p, "202 Accepted", req);
}
return 1;
}
@@ -9245,8 +9351,10 @@
return 0;
}
/* Initialize the context if it hasn't been already */
- if (ast_strlen_zero(p->context))
- strcpy(p->context, default_context);
+ if (p->subscribecontext && !ast_strlen_zero(p->subscribecontext))
+ ast_copy_string(p->context, p->subscribecontext, sizeof(p->context));
+ else if (ast_strlen_zero(p->context))
+ ast_copy_string(p->context, default_context, sizeof(p->context));
/* Get destination right away */
gotdest = get_destination(p, NULL);
build_contact(p);
@@ -9254,15 +9362,36 @@
if (gotdest < 0)
transmit_response(p, "404 Not Found", req);
else
- transmit_response(p, "484 Address Incomplete", req);
+ transmit_response(p, "484 Address Incomplete", req); /* Overlap dialing on SUBSCRIBE?? */
ast_set_flag(p, SIP_NEEDDESTROY);
} else {
+ char *event = get_header(req, "Event"); /* Get Event package name */
+ char *accept = get_header(req, "Accept");
+
/* Initialize tag */
p->tag = rand();
- if (!strcmp(get_header(req, "Accept"), "application/dialog-info+xml"))
- p->subscribed = 2;
- else if (!strcmp(get_header(req, "Accept"), "application/simple-message-summary")) {
- /* Looks like they actually want a mailbox */
+ if(!strcmp(event, "presence") || !strcmp(event, "dialog")) { /* Presence, RFC 3842 */
+ /* Header from Xten Eye-beam
+ Accept: multipart/related, application/rlmi+xml, application/pidf+xml, application/xpidf+xml
+ */
+ if (strstr(accept, "application/dialog-info+xml"))
+ p->subscribed = 2;
+ /* IETF draft: draft-ietf-sipping-dialog-package-05.txt */
+ /* Should not be used for SUBSCRIBE, but anyway */
+ else if (!p->subscribed && strstr(accept, "application/cpim-pidf+xml"))
+ p->subscribed = 3; /* RFC 3863 format */
+ else if (!p->subscribed && strstr(accept, "application/pidf+xml"))
+ p->subscribed = 4; /* RFC 3863 format */
+ else if (!p->subscribed && strstr(accept, "application/xpidf+xml"))
+ p->subscribed = 1; /* Early pre-RFC 3863 format with MSN additions (Microsoft Messenger) */
+ else {
+ /* Can't find a format for events that we know about */
+ transmit_response(p, "489 Bad Event", req);
+ ast_set_flag(p, SIP_NEEDDESTROY);
+ return 0;
+ }
+ } else if (!strcmp(event, "message-summary") && !strcmp(accept, "application/simple-message-summary")) {
+ /* Looks like they actually want a mailbox status */
/* At this point, we should check if they subscribe to a mailbox that
has the same extension as the peer or the mailbox id. If we configure
@@ -9288,8 +9417,14 @@
ast_set_flag(p, SIP_NEEDDESTROY);
}
return 0;
- } else
- p->subscribed = 1;
+ } else {
+ /* At this point, Asterisk does not understand the specified event */
+ transmit_response(p, "489 Bad Event", req);
+ if (option_debug > 1)
+ ast_log(LOG_DEBUG, "Received SIP subscribe for unknown event package: %s\n", event);
+ ast_set_flag(p, SIP_NEEDDESTROY);
+ return 0;
+ }
if (p->subscribed)
p->stateid = ast_extension_state_add(p->context, p->exten, cb_extensionstate, p);
}
@@ -9305,7 +9440,7 @@
return 0;
}
/* The next line can be removed if the SNOM200 Expires bug is fixed */
- if (p->subscribed == 1) {
+ if (p->subscribed != 0) {
if (p->expiry>max_expiry)
p->expiry = max_expiry;
}
@@ -9318,8 +9453,12 @@
ast_rtp_destroy(p->vrtp);
p->vrtp = NULL;
}
+ if (sipdebug || option_debug > 1)
+ ast_log(LOG_DEBUG, "Adding subscription for extension %s context %s for peer %s\n", p->exten, p->context, p->username);
transmit_response(p, "200 OK", req);
+ /* Set timer for destruction of call at expiration */
sip_scheddestroy(p, (p->expiry+10)*1000);
+ /* Send first notification */
transmit_state_notify(p, ast_extension_state(NULL, p->context, p->exten),1);
}
return 1;
@@ -9653,7 +9792,7 @@
build_callid(p->callid, sizeof(p->callid), p->ourip, p->fromdomain);
/* Send MWI */
ast_set_flag(p, SIP_OUTGOING);
- transmit_notify_with_mwi(p, newmsgs, oldmsgs);
+ transmit_notify_with_mwi(p, newmsgs, oldmsgs, peer->mailbox_exten);
sip_scheddestroy(p, 15000);
return 0;
}
@@ -9913,7 +10052,7 @@
int res = AST_DEVICE_INVALID;
- ast_copy_string(tmp, dest, sizeof(tmp));
+ strncpy(tmp, dest, sizeof(tmp) - 1);
host = strchr(tmp, '@');
if (host) {
*host = '\0';
@@ -9928,13 +10067,35 @@
if (p) {
found++;
res = AST_DEVICE_UNAVAILABLE;
+ if (option_debug > 2)
+ ast_log(LOG_DEBUG, "Checking device state for peer %s\n", dest);
if ((p->addr.sin_addr.s_addr || p->defaddr.sin_addr.s_addr) &&
(!p->maxms || ((p->lastms > -1) && (p->lastms <= p->maxms)))) {
- /* peer found and valid */
- res = AST_DEVICE_UNKNOWN;
+ /* Peer is registred, or have default IP address
+ and a valid registration */
+
+
+ /* Now check if we know anything about the state. The only way is by implementing
+ call control with incominglimit=X in sip.conf where X > 0
+ Check if the device has incominglimit, and if qualify=on, if the device
+ is reachable
+ */
+ if (p->incominglimit && (p->lastms == 0 || p->lastms <= p->maxms)) {
+ /* Free for a call */
+ res = AST_DEVICE_NOT_INUSE;
+
+ if (p->inUse) { /* On a call */
+ res = AST_DEVICE_BUSY;
+ }
+ } else {
+ /* peer found and valid, state unknown */
+ res = AST_DEVICE_UNKNOWN;
+ }
}
}
if (!p && !found) {
+ if (option_debug > 2)
+ ast_log(LOG_DEBUG, "Checking device state for DNS host %s\n", dest);
hp = ast_gethostbyname(host, &ahp);
if (hp)
res = AST_DEVICE_UNKNOWN;
@@ -9945,6 +10106,7 @@
return res;
}
+
/*--- sip_request: PBX interface function -build SIP pvt structure ---*/
/* SIP calls initiated by the PBX arrive here */
static struct ast_channel *sip_request(const char *type, int format, void *data, int *cause)
@@ -10264,6 +10426,8 @@
if (!strcasecmp(v->name, "context")) {
ast_copy_string(user->context, v->value, sizeof(user->context));
+ } else if (!strcasecmp(v->name, "subscribecontext")) {
+ ast_copy_string(user->subscribecontext, v->value, sizeof(user->subscribecontext));
} else if (!strcasecmp(v->name, "setvar")) {
varname = ast_strdupa(v->value);
if (varname && (varval = strchr(varname,'='))) {
@@ -10332,11 +10496,11 @@
{
struct sip_peer *peer;
- peer = malloc(sizeof(*peer));
+ peer = malloc(sizeof(struct sip_peer));
if (!peer)
return NULL;
- memset(peer, 0, sizeof(*peer));
+ memset(peer, 0, sizeof(struct sip_peer));
apeerobjs++;
ASTOBJ_INIT(peer);
@@ -10348,6 +10512,7 @@
SIP_DTMF | SIP_NAT | SIP_REINVITE | SIP_INSECURE_PORT | SIP_INSECURE_INVITE |
SIP_PROG_INBAND | SIP_OSPAUTH);
strcpy(peer->context, default_context);
+ strcpy(peer->subscribecontext, default_subscribecontext);
strcpy(peer->language, default_language);
strcpy(peer->musicclass, global_musicclass);
peer->addr.sin_port = htons(DEFAULT_SIP_PORT);
@@ -10422,6 +10587,7 @@
peer->chanvars = NULL;
}
strcpy(peer->context, default_context);
+ strcpy(peer->subscribecontext, default_subscribecontext);
strcpy(peer->language, default_language);
strcpy(peer->musicclass, global_musicclass);
ast_copy_flags(peer, &global_flags, SIP_USEREQPHONE);
@@ -10471,7 +10637,9 @@
ast_callerid_split(v->value, peer->cid_name, sizeof(peer->cid_name), peer->cid_num, sizeof(peer->cid_num));
} else if (!strcasecmp(v->name, "context")) {
ast_copy_string(peer->context, v->value, sizeof(peer->context));
- } else if (!strcasecmp(v->name, "fromdomain"))
+ } else if (!strcasecmp(v->name, "subscribecontext"))
+ ast_copy_string(peer->subscribecontext, v->value, sizeof(peer->subscribecontext));
+ else if (!strcasecmp(v->name, "fromdomain"))
ast_copy_string(peer->fromdomain, v->value, sizeof(peer->fromdomain));
else if (!strcasecmp(v->name, "usereqphone"))
ast_set2_flag(peer, ast_true(v->value), SIP_USEREQPHONE);