FS-2731 refactor a bit to make this actually usable and more cross-endpoint compatible

This commit is contained in:
Raymond Chandler 2013-09-18 16:00:03 -04:00
parent 0df6c2d094
commit a7ab24ef4c
2 changed files with 503 additions and 436 deletions

View File

@ -4891,7 +4891,7 @@ static void general_event_handler(switch_event_t *event)
const char *user = switch_event_get_header(event, "user");
const char *host = switch_event_get_header(event, "host");
const char *call_id = switch_event_get_header(event, "call-id");
const char *csta_event = switch_event_get_header(event, "csta-event");
const char *csta_event = switch_event_get_header(event, "Feature-Event");
char *ct = "application/x-as-feature-event+xml";
@ -4948,8 +4948,19 @@ static void general_event_handler(switch_event_t *event)
ct = switch_mprintf("multipart/mixed; boundary=\"%s\"", boundary_string);
} else {
char *fwd_type = NULL;
char *header_name = NULL;
if ((header_name = switch_event_get_header(event, "forward_immediate"))) {
fwd_type = "forwardImmediate";
} else if ((header_name = switch_event_get_header(event, "forward_busy"))) {
fwd_type = "forwardBusy";
} else if ((header_name = switch_event_get_header(event, "forward_no_answer"))) {
fwd_type = "forwardNoAns";
}
// this will need some work to handle the different types of forwarding events
write_csta_xml_chunk(event, stream, csta_event, NULL);
write_csta_xml_chunk(event, stream, csta_event, fwd_type);
}
}
@ -5248,16 +5259,20 @@ void write_csta_xml_chunk(switch_event_t *event, switch_stream_handle_t stream,
stream.write_function(&stream, " <doNotDisturbOn>%s</doNotDisturbOn>\n", dndstatus);
}
} else if(!strcmp(csta_event, "ForwardingEvent")) {
const char *fwdstatus = switch_event_get_header(event, "forwardStatus");
const char *fwdstatus = NULL;
const char *fwdto = NULL;
const char *ringcount = NULL;
if (strcmp("forwardImmediate", fwdtype)) {
if (fwdtype && !zstr(fwdtype)) {
if (!strcmp("forwardImmediate", fwdtype)) {
fwdto = switch_event_get_header(event, "forward_immediate");
} else if (strcmp("forwardBusy", fwdtype)) {
fwdstatus = switch_event_get_header(event, "forward_immediate_enabled");
} else if (!strcmp("forwardBusy", fwdtype)) {
fwdto = switch_event_get_header(event, "forward_busy");
} else if (strcmp("fowardNoAns", fwdtype)) {
fwdstatus = switch_event_get_header(event, "forward_busy_enabled");
} else if (!strcmp("forwardNoAns", fwdtype)) {
fwdto = switch_event_get_header(event, "forward_no_answer");
fwdstatus = switch_event_get_header(event, "forward_no_answer_enabled");
ringcount = switch_event_get_header(event, "ringCount");
}
@ -5274,6 +5289,7 @@ void write_csta_xml_chunk(switch_event_t *event, switch_stream_handle_t stream,
stream.write_function(&stream, " <ringCount>%s</ringCount>\n", ringcount);
}
}
}
if (csta_event) {
stream.write_function(&stream, "</%s>\n", csta_event);
@ -5709,4 +5725,3 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_sofia_shutdown)
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
*/

View File

@ -4037,6 +4037,7 @@ void sofia_presence_handle_sip_i_subscribe(int status,
if (!strcasecmp(event, "as-feature-event")) {
switch_event_t *event;
char sip_cseq[40] = "";
switch_snprintf(sip_cseq, sizeof(sip_cseq), "%d", sip->sip_cseq->cs_seq);
switch_event_create(&event, SWITCH_EVENT_PHONE_FEATURE_SUBSCRIBE);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "user", from_user);
@ -4047,8 +4048,59 @@ void sofia_presence_handle_sip_i_subscribe(int status,
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "cseq", sip_cseq);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "profile_name", profile->name);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "hostname", mod_sofia_globals.hostname);
if (sip->sip_payload) {
switch_event_add_body(event, "%s", sip->sip_payload->pl_data);
switch_xml_t xml = NULL;
char *pd_dup = NULL;
pd_dup = strdup(sip->sip_payload->pl_data);
if ((xml = switch_xml_parse_str(pd_dup, strlen(pd_dup)))) {
switch_xml_t device = NULL;
if ((device = switch_xml_child(xml, "device"))) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "device", device->txt);
}
if (!strcmp(xml->name, "SetDoNotDisturb")) {
switch_xml_t action = NULL;
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Feature-Action", "SetDoNotDisturb");
if ((action = switch_xml_child(xml, "doNotDisturbOn"))) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Feature-Enabled", action->txt);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Action-Name", action->name);
}
}
if (!strcmp(xml->name, "SetForwarding")) {
switch_xml_t cfwd_type, cfwd_enable, cfwd_target;
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Feature-Action", "SetCallForward");
if ((cfwd_type = switch_xml_child(xml, "forwardingType"))
&& (cfwd_enable = switch_xml_child(xml, "activateForward"))
&& (cfwd_target = switch_xml_child(xml, "forwardDN"))) {
if (!strcmp(cfwd_type->txt, "forwardImmediate")) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Feature-Enabled", cfwd_enable->txt);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Action-Name", "forward_immediate");
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Action-Value", cfwd_target->txt);
} else if (!strcmp(cfwd_type->txt, "forwardBusy")) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Feature-Enabled", cfwd_enable->txt);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Action-Name", "forward_busy");
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Action-Value", cfwd_target->txt);
} else if (!strcmp(cfwd_type->txt, "forwardNoAns")) {
switch_xml_t rc;
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Feature-Enabled", cfwd_enable->txt);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Action-Name", "forward_no_answer");
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Action-Value", cfwd_target->txt);
if ((rc = switch_xml_child(xml, "ringCount"))) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "ringCount", rc->txt);
}
}
}
}
}
}
switch_event_fire(&event);
} else if (!strcasecmp(event, "message-summary")) {