Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- channels/chan_sip.c.keep 2014-07-14 15:28:59.739985497 -0400
- +++ channels/chan_sip.c 2014-07-14 22:02:50.186709816 -0400
- @@ -267,6 +267,7 @@
- #include "asterisk/data.h"
- #include "asterisk/aoc.h"
- #include "asterisk/message.h"
- +#include "asterisk/dial.h"
- #include "sip/include/sip.h"
- #include "sip/include/globals.h"
- #include "sip/include/config_parser.h"
- @@ -663,6 +664,7 @@
- { CPIM_PIDF_XML, "presence", "application/cpim-pidf+xml", "cpim-pidf+xml" }, /* RFC 3863 */
- { PIDF_XML, "presence", "application/pidf+xml", "pidf+xml" }, /* RFC 3863 */
- { XPIDF_XML, "presence", "application/xpidf+xml", "xpidf+xml" }, /* Pre-RFC 3863 with MS additions */
- + { FEATURE_XML, "as-feature-event", "application/x-as-feature-event+xml", "x-as-feature-event+xml" }, /* Broadsoft feature key synchronization */
- { MWI_NOTIFICATION, "message-summary", "application/simple-message-summary", "mwi" } /* RFC 3842: Mailbox notification */
- };
- @@ -1640,6 +1642,7 @@
- static int handle_request_cancel(struct sip_pvt *p, struct sip_request *req);
- static int handle_request_message(struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, const char *e);
- static int handle_request_subscribe(struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, uint32_t seqno, const char *e);
- +static void do_feature_call(char *channel, ast_string_field username);
- static void handle_request_info(struct sip_pvt *p, struct sip_request *req);
- static int handle_request_options(struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, const char *e);
- static int handle_invite_replaces(struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, uint32_t seqno, int *nounlock);
- @@ -14542,6 +14545,14 @@
- }
- ast_str_append(tmp, 0, "</dialog>\n</dialog-info>\n");
- break;
- + case FEATURE_XML:
- + ast_str_append(tmp, 0,
- + "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
- + "<DoNotDisturbEvent xmlns=\"http://www.ecma-international.org/standards/ecma-323/csta/ed3\">\n");
- + ast_str_append(tmp, 0, "<device>%s</device>\n", exten);
- + ast_str_append(tmp, 0, "<doNotDisturbOn>%s</doNotDisturbOn>", (local_state == NOTIFY_OPEN) ? "false" : (local_state == NOTIFY_INUSE) ? "false" : "true");
- + ast_str_append(tmp, 0, "</DoNotDisturbEvent>\n");
- + break;
- case NONE:
- default:
- break;
- @@ -14655,6 +14666,12 @@
- add_header(&req, "Content-Type", subscriptiontype->mediatype);
- p->dialogver++;
- break;
- + case FEATURE_XML: /* Broadsoft feature key synchronization */
- + add_header(&req, "Event", subscriptiontype->event);
- + state_notify_build_xml(data, full, p->exten, p->context, &tmp, p, p->subscribed, mfrom, mto);
- + add_header(&req, "Content-Type", subscriptiontype->mediatype);
- + p->dialogver++;
- + break;
- case NONE:
- default:
- break;
- @@ -27500,7 +27517,7 @@
- make_our_tag(p);
- }
- - if (!strcmp(event, "presence") || !strcmp(event, "dialog")) { /* Presence, RFC 3842 */
- + if (!strcmp(event, "presence") || !strcmp(event, "dialog") || !strcmp(event, "as-feature-event")) { /* Presence, RFC 3842 */
- int gotdest;
- const char *accept;
- int start = 0;
- @@ -27538,9 +27555,12 @@
- subscribed = CPIM_PIDF_XML; /* RFC 3863 format */
- } else if (strstr(accept, "application/xpidf+xml")) {
- subscribed = XPIDF_XML; /* Early pre-RFC 3863 format with MSN additions (Microsoft Messenger) */
- + } else if (strstr(accept, "application/x-as-feature-event+xml")) {
- + subscribed = FEATURE_XML;
- } else {
- unknown_accept = accept;
- }
- +
- /* check to see if there is another Accept header present */
- accept = __get_header(req, "Accept", &start);
- }
- @@ -27719,6 +27739,25 @@
- sip_unref_peer(peer, "release a peer ref now that MWI is sent");
- }
- } else if (p->subscribed != CALL_COMPLETION) {
- +
- + if(p->subscribed == FEATURE_XML) {
- + char *feature_body;
- +
- + if (!(feature_body = get_content(req))) {
- + ast_log(LOG_WARNING, "Unable to get feature-event body\n");
- + } else if (!ast_strlen_zero(feature_body)) {
- + ast_verb(3, "Found feature-event body %s\n", feature_body);
- +
- + if (strstr(feature_body, "<doNotDisturbOn>true</doNotDisturbOn>")) {
- + ast_verb(3, "Found feature-event DND status true\n");
- + do_feature_call("Local/*78@from-internal", p->username);
- + } else if (strstr(feature_body, "<doNotDisturbOn>false</doNotDisturbOn>")) {
- + ast_verb(3, "Found feature-event DND status false\n");
- + do_feature_call("Local/*79@from-internal", p->username);
- + }
- + }
- + }
- +
- struct state_notify_data data = { 0, };
- char *subtype = NULL;
- char *message = NULL;
- @@ -27795,6 +27834,95 @@
- return 1;
- }
- +static int null_chan_write(struct ast_channel *chan, struct ast_frame *frame)
- +{
- + return 0;
- +}
- +
- +static const struct ast_channel_tech null_tech = {
- + .type = "NULL",
- + .description = "Null channel (should not see this)",
- + .write = null_chan_write,
- +};
- +
- +static void do_feature_call(char *channel, ast_string_field username)
- +{
- + struct ast_dial *dial = NULL;
- + struct ast_str *apptext = NULL, *tmpstr = NULL;
- + enum ast_dial_result res;
- + struct ast_channel *chan = NULL;
- + char *tech, *dest;
- + char buf[8];
- +
- + tech = ast_strdupa(channel);
- +
- + if ((dest = strchr(tech, '/'))) {
- + *dest = '\0';
- + dest++;
- + } else {
- + ast_log(LOG_WARNING, "Channel should be in form Tech/Dest (was '%s')\n", tech);
- + goto notify_cleanup;
- + }
- +
- + if (!(dial = ast_dial_create())) {
- + ast_log(LOG_ERROR, "Could not create dial structure\n");
- + goto notify_cleanup;
- + }
- +
- + if (ast_dial_append(dial, tech, dest) < 0) {
- + ast_log(LOG_ERROR, "Could not append channel\n");
- + goto notify_cleanup;
- + }
- +
- + ast_dial_set_global_timeout(dial, 5);
- + generate_random_string(buf, sizeof(buf));
- +
- + if (!(chan = ast_channel_alloc(1, AST_STATE_DOWN, 0, 0, 0, 0, 0, 0, 0, "SIP/%s-%s", username, buf))) {
- + ast_log(LOG_ERROR, "Could not allocate notification channel\n");
- + goto notify_cleanup;
- + }
- +
- + ast_channel_tech_set(chan, &null_tech);
- + ast_format_set(ast_channel_writeformat(chan), AST_FORMAT_SLINEAR, 0);
- + ast_format_set(ast_channel_readformat(chan), AST_FORMAT_SLINEAR, 0);
- + ast_format_set(ast_channel_rawwriteformat(chan), AST_FORMAT_SLINEAR, 0);
- + ast_format_set(ast_channel_rawreadformat(chan), AST_FORMAT_SLINEAR, 0);
- + /* clear native formats and set to slinear. write format is signlear so just use that to set it */
- + ast_format_cap_set(ast_channel_nativeformats(chan), ast_channel_writeformat(chan));
- +
- + ast_set_callerid(chan, username, username, username);
- +
- + ast_verb(3, "Dialing %s for activation of feature key\n", channel);
- + res = ast_dial_run(dial, chan, 0);
- +
- + if (res != AST_DIAL_RESULT_ANSWERED) {
- + ast_verb(3, "Dialing %s was not completed\n", channel);
- + } else {
- + struct ast_channel *answered;
- +
- + answered = ast_dial_answered_steal(dial);
- +
- + ast_channel_context_set(answered, "sip-feature-xml");
- + ast_channel_exten_set(answered, "s");
- + ast_channel_priority_set(answered, 1);
- + ast_pbx_run(answered);
- + }
- +
- +notify_cleanup:
- + if (apptext) {
- + ast_free(apptext);
- + }
- + if (tmpstr) {
- + ast_free(tmpstr);
- + }
- + if (dial) {
- + ast_dial_destroy(dial);
- + }
- + if (chan) {
- + ast_channel_release(chan);
- + }
- +}
- +
- /*! \brief Handle incoming REGISTER request */
- static int handle_request_register(struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, const char *e)
- {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement