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

@ -671,7 +671,7 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session)
//switch_core_media_set_local_sdp //switch_core_media_set_local_sdp
if(sofia_test_flag(tech_pvt, TFLAG_3PCC_INVITE)) { if(sofia_test_flag(tech_pvt, TFLAG_3PCC_INVITE)) {
// SNARK: complete hack to get final ack sent when a 3pcc invite has been passed from the other leg in bypass_media mode. // SNARK: complete hack to get final ack sent when a 3pcc invite has been passed from the other leg in bypass_media mode.
// This code handles the pass_indication sent after the 3pcc ack is received by the other leg in the is_3pcc && is_proxy case below. // This code handles the pass_indication sent after the 3pcc ack is received by the other leg in the is_3pcc && is_proxy case below.
// Is there a better place to hang this...? // Is there a better place to hang this...?
b_sdp = switch_channel_get_variable(channel, SWITCH_B_SDP_VARIABLE); b_sdp = switch_channel_get_variable(channel, SWITCH_B_SDP_VARIABLE);
switch_core_media_set_local_sdp(session, b_sdp, SWITCH_TRUE); switch_core_media_set_local_sdp(session, b_sdp, SWITCH_TRUE);
@ -3199,16 +3199,16 @@ static switch_status_t cmd_profile(char **argv, int argc, switch_stream_handle_t
goto done; goto done;
} }
if (!strcasecmp(argv[1], "capture")) { if (!strcasecmp(argv[1], "capture")) {
if (argc > 2) { if (argc > 2) {
int value = switch_true(argv[2]); int value = switch_true(argv[2]);
nua_set_params(profile->nua, TPTAG_CAPT(value ? mod_sofia_globals.capture_server : NULL), TAG_END()); nua_set_params(profile->nua, TPTAG_CAPT(value ? mod_sofia_globals.capture_server : NULL), TAG_END());
stream->write_function(stream, "%s sip capturing on %s", value ? "Enabled" : "Disabled", profile->name); stream->write_function(stream, "%s sip capturing on %s", value ? "Enabled" : "Disabled", profile->name);
} else { } else {
stream->write_function(stream, "Usage: sofia profile <name> capture <on/off>\n"); stream->write_function(stream, "Usage: sofia profile <name> capture <on/off>\n");
} }
goto done; goto done;
} }
if (!strcasecmp(argv[1], "watchdog")) { if (!strcasecmp(argv[1], "watchdog")) {
if (argc > 2) { if (argc > 2) {
@ -3966,10 +3966,10 @@ SWITCH_STANDARD_API(sofia_function)
} }
if (!strcasecmp(argv[1], "capture")) { if (!strcasecmp(argv[1], "capture")) {
if (argc > 2) { if (argc > 2) {
cton = switch_true(argv[2]); cton = switch_true(argv[2]);
} }
} }
if (!strcasecmp(argv[1], "watchdog")) { if (!strcasecmp(argv[1], "watchdog")) {
if (argc > 2) { if (argc > 2) {
@ -4891,7 +4891,7 @@ static void general_event_handler(switch_event_t *event)
const char *user = switch_event_get_header(event, "user"); const char *user = switch_event_get_header(event, "user");
const char *host = switch_event_get_header(event, "host"); const char *host = switch_event_get_header(event, "host");
const char *call_id = switch_event_get_header(event, "call-id"); 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"; 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); ct = switch_mprintf("multipart/mixed; boundary=\"%s\"", boundary_string);
} else { } 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 // 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,30 +5259,35 @@ void write_csta_xml_chunk(switch_event_t *event, switch_stream_handle_t stream,
stream.write_function(&stream, " <doNotDisturbOn>%s</doNotDisturbOn>\n", dndstatus); stream.write_function(&stream, " <doNotDisturbOn>%s</doNotDisturbOn>\n", dndstatus);
} }
} else if(!strcmp(csta_event, "ForwardingEvent")) { } 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 *fwdto = NULL;
const char *ringcount = NULL; const char *ringcount = NULL;
if (strcmp("forwardImmediate", fwdtype)) { if (fwdtype && !zstr(fwdtype)) {
fwdto = switch_event_get_header(event, "forward_immediate"); if (!strcmp("forwardImmediate", fwdtype)) {
} else if (strcmp("forwardBusy", fwdtype)) { fwdto = switch_event_get_header(event, "forward_immediate");
fwdto = switch_event_get_header(event, "forward_busy"); fwdstatus = switch_event_get_header(event, "forward_immediate_enabled");
} else if (strcmp("fowardNoAns", fwdtype)) { } else if (!strcmp("forwardBusy", fwdtype)) {
fwdto = switch_event_get_header(event, "forward_no_answer"); fwdto = switch_event_get_header(event, "forward_busy");
ringcount = switch_event_get_header(event, "ringCount"); 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");
}
if (fwdtype) { if (fwdtype) {
stream.write_function(&stream, " <forwardingType>%s</forwardingType>\n", fwdtype); stream.write_function(&stream, " <forwardingType>%s</forwardingType>\n", fwdtype);
} }
if (fwdstatus) { if (fwdstatus) {
stream.write_function(&stream, " <forwardStatus>%s</forwardStatus>\n", fwdstatus); stream.write_function(&stream, " <forwardStatus>%s</forwardStatus>\n", fwdstatus);
} }
if (fwdto) { if (fwdto) {
stream.write_function(&stream, " <forwardTo>%s</forwardTo>\n", fwdto); stream.write_function(&stream, " <forwardTo>%s</forwardTo>\n", fwdto);
} }
if (ringcount) { if (ringcount) {
stream.write_function(&stream, " <ringCount>%s</ringCount>\n", ringcount); stream.write_function(&stream, " <ringCount>%s</ringCount>\n", ringcount);
}
} }
} }
@ -5709,4 +5725,3 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_sofia_shutdown)
* For VIM: * For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet: * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
*/ */

View File

@ -962,14 +962,14 @@ static void send_conference_data(sofia_profile_t *profile, switch_event_t *event
if (call_id) { if (call_id) {
if (switch_true(final)) { if (switch_true(final)) {
sql = switch_mprintf("update sip_subscriptions set expires=%ld where " sql = switch_mprintf("update sip_subscriptions set expires=%ld where "
"hostname='%q' and profile_name='%q' and sub_to_user='%q' and sub_to_host='%q' and event='%q' " "hostname='%q' and profile_name='%q' and sub_to_user='%q' and sub_to_host='%q' and event='%q' "
"and call_id = '%q' ", "and call_id = '%q' ",
(long)0, (long)0,
mod_sofia_globals.hostname, profile->name, mod_sofia_globals.hostname, profile->name,
from_user, from_host, event_str, call_id); from_user, from_host, event_str, call_id);
sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE); sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
} }
sql = switch_mprintf("select full_to, full_from, contact %q ';_;isfocus', expires, call_id, event, network_ip, network_port, " sql = switch_mprintf("select full_to, full_from, contact %q ';_;isfocus', expires, call_id, event, network_ip, network_port, "
@ -983,15 +983,15 @@ static void send_conference_data(sofia_profile_t *profile, switch_event_t *event
mod_sofia_globals.hostname, profile->name, mod_sofia_globals.hostname, profile->name,
from_user, from_host, event_str, call_id); from_user, from_host, event_str, call_id);
} else { } else {
if (switch_true(final)) { if (switch_true(final)) {
sql = switch_mprintf("update sip_subscriptions set expires=%ld where " sql = switch_mprintf("update sip_subscriptions set expires=%ld where "
"hostname='%q' and profile_name='%q' and sub_to_user='%q' and sub_to_host='%q' and event='%q'", "hostname='%q' and profile_name='%q' and sub_to_user='%q' and sub_to_host='%q' and event='%q'",
(long)0, (long)0,
mod_sofia_globals.hostname, profile->name, mod_sofia_globals.hostname, profile->name,
from_user, from_host, event_str); from_user, from_host, event_str);
sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE); sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
} }
sql = switch_mprintf("select full_to, full_from, contact %q ';_;isfocus', expires, call_id, event, network_ip, network_port, " sql = switch_mprintf("select full_to, full_from, contact %q ';_;isfocus', expires, call_id, event, network_ip, network_port, "
"'%q' as ct,'%q' as pt " "'%q' as ct,'%q' as pt "
@ -3104,7 +3104,7 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
const char *register_source = switch_event_get_header_nil(helper->event, "register-source"); const char *register_source = switch_event_get_header_nil(helper->event, "register-source");
if (!zstr(uuid) && strchr(uuid, '-') && !zstr(status_line) && !zstr(rpid) && (zstr(register_source) || strcasecmp(register_source, "register"))) { if (!zstr(uuid) && strchr(uuid, '-') && !zstr(status_line) && !zstr(rpid) && (zstr(register_source) || strcasecmp(register_source, "register"))) {
char *sql = switch_mprintf("update sip_dialogs set rpid='%q',status='%q' where hostname='%q' and profile_name='%q' and uuid='%q'", char *sql = switch_mprintf("update sip_dialogs set rpid='%q',status='%q' where hostname='%q' and profile_name='%q' and uuid='%q'",
rpid, status_line, rpid, status_line,
mod_sofia_globals.hostname, profile->name, uuid); mod_sofia_globals.hostname, profile->name, uuid);
sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE); sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
@ -3828,14 +3828,14 @@ void sofia_presence_handle_sip_i_subscribe(int status,
uri = switch_mprintf("sip:%s", contact_host); uri = switch_mprintf("sip:%s", contact_host);
} }
if ( uri ) { if ( uri ) {
switch_event_t *params = NULL; switch_event_t *params = NULL;
/* Grandstream REALLY uses a header called Message Body */ /* Grandstream REALLY uses a header called Message Body */
extra_headers = switch_mprintf("MessageBody: %s\r\n", profile->pnp_prov_url); extra_headers = switch_mprintf("MessageBody: %s\r\n", profile->pnp_prov_url);
nua_respond(nh, SIP_202_ACCEPTED, NUTAG_WITH_THIS_MSG(de->data->e_msg), TAG_END()); nua_respond(nh, SIP_202_ACCEPTED, NUTAG_WITH_THIS_MSG(de->data->e_msg), TAG_END());
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "sending pnp NOTIFY for %s to provision to %s\n", uri, profile->pnp_prov_url); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "sending pnp NOTIFY for %s to provision to %s\n", uri, profile->pnp_prov_url);
switch_event_create(&params, SWITCH_EVENT_NOTIFY); switch_event_create(&params, SWITCH_EVENT_NOTIFY);
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "profile", profile->name); switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "profile", profile->name);
@ -3848,10 +3848,10 @@ void sofia_presence_handle_sip_i_subscribe(int status,
switch_event_fire(&params); switch_event_fire(&params);
switch_safe_free(uri); switch_safe_free(uri);
switch_safe_free(extra_headers); switch_safe_free(extra_headers);
goto end; goto end;
} }
} }
if (status < 200) { if (status < 200) {
@ -4037,6 +4037,7 @@ void sofia_presence_handle_sip_i_subscribe(int status,
if (!strcasecmp(event, "as-feature-event")) { if (!strcasecmp(event, "as-feature-event")) {
switch_event_t *event; switch_event_t *event;
char sip_cseq[40] = ""; char sip_cseq[40] = "";
switch_snprintf(sip_cseq, sizeof(sip_cseq), "%d", sip->sip_cseq->cs_seq); switch_snprintf(sip_cseq, sizeof(sip_cseq), "%d", sip->sip_cseq->cs_seq);
switch_event_create(&event, SWITCH_EVENT_PHONE_FEATURE_SUBSCRIBE); switch_event_create(&event, SWITCH_EVENT_PHONE_FEATURE_SUBSCRIBE);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "user", from_user); 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, "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, "profile_name", profile->name);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "hostname", mod_sofia_globals.hostname); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "hostname", mod_sofia_globals.hostname);
if (sip->sip_payload) { 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); switch_event_fire(&event);
} else if (!strcasecmp(event, "message-summary")) { } else if (!strcasecmp(event, "message-summary")) {