first pass on some new stuff

This commit is contained in:
Anthony Minessale committed 2012-07-11 15:15:50 -05:00
1 parent 90cdc718ec
commit 2aebe2456f
12 files changed
+740 -97

No files matched your search

+26 -22
View File
@@ -665,7 +665,10 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session)
int is_3pcc = 0;
char *sticky = NULL;
const char *call_info = switch_channel_get_variable(channel, "presence_call_info_full");
if (switch_channel_test_flag(channel, CF_CONFERENCE)) {
tech_pvt->reply_contact = switch_core_session_sprintf(session, "%s;isfocus", tech_pvt->reply_contact);
}
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.
@@ -5554,44 +5557,48 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sofia_load)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Waiting for profiles to start\n");
switch_yield(1500000);
if (switch_event_bind_removable(modname, SWITCH_EVENT_CUSTOM, MULTICAST_EVENT, event_handler, NULL,
&mod_sofia_globals.custom_node) != SWITCH_STATUS_SUCCESS) {
if (switch_event_bind(modname, SWITCH_EVENT_CUSTOM, MULTICAST_EVENT, event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
return SWITCH_STATUS_TERM;
}
if (switch_event_bind_removable(modname, SWITCH_EVENT_PRESENCE_IN, SWITCH_EVENT_SUBCLASS_ANY, sofia_presence_event_handler, NULL,
&mod_sofia_globals.in_node) != SWITCH_STATUS_SUCCESS) {
if (switch_event_bind(modname, SWITCH_EVENT_CONFERENCE_DATA, SWITCH_EVENT_SUBCLASS_ANY, sofia_presence_event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
return SWITCH_STATUS_GENERR;
}
if (switch_event_bind_removable(modname, SWITCH_EVENT_PRESENCE_OUT, SWITCH_EVENT_SUBCLASS_ANY, sofia_presence_event_handler, NULL,
&mod_sofia_globals.out_node) != SWITCH_STATUS_SUCCESS) {
if (switch_event_bind(modname, SWITCH_EVENT_PRESENCE_IN, SWITCH_EVENT_SUBCLASS_ANY, sofia_presence_event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
return SWITCH_STATUS_GENERR;
}
if (switch_event_bind_removable(modname, SWITCH_EVENT_PRESENCE_PROBE, SWITCH_EVENT_SUBCLASS_ANY, sofia_presence_event_handler, NULL,
&mod_sofia_globals.probe_node) != SWITCH_STATUS_SUCCESS) {
if (switch_event_bind(modname, SWITCH_EVENT_PRESENCE_OUT, SWITCH_EVENT_SUBCLASS_ANY, sofia_presence_event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
return SWITCH_STATUS_GENERR;
}
if (switch_event_bind_removable(modname, SWITCH_EVENT_ROSTER, SWITCH_EVENT_SUBCLASS_ANY, sofia_presence_event_handler, NULL,
&mod_sofia_globals.roster_node) != SWITCH_STATUS_SUCCESS) {
if (switch_event_bind(modname, SWITCH_EVENT_PRESENCE_PROBE, SWITCH_EVENT_SUBCLASS_ANY, sofia_presence_event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
return SWITCH_STATUS_GENERR;
}
if (switch_event_bind_removable(modname, SWITCH_EVENT_MESSAGE_WAITING, SWITCH_EVENT_SUBCLASS_ANY, sofia_presence_mwi_event_handler, NULL,
&mod_sofia_globals.mwi_node) != SWITCH_STATUS_SUCCESS) {
if (switch_event_bind(modname, SWITCH_EVENT_ROSTER, SWITCH_EVENT_SUBCLASS_ANY, sofia_presence_event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
return SWITCH_STATUS_GENERR;
}
if (switch_event_bind_removable(modname, SWITCH_EVENT_CUSTOM, MY_EVENT_RECOVERY, sofia_glue_track_event_handler, NULL,
&mod_sofia_globals.recovery_node) != SWITCH_STATUS_SUCCESS) {
if (switch_event_bind(modname, SWITCH_EVENT_MESSAGE_WAITING, SWITCH_EVENT_SUBCLASS_ANY, sofia_presence_mwi_event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
return SWITCH_STATUS_GENERR;
}
if (switch_event_bind(modname, SWITCH_EVENT_CUSTOM, MY_EVENT_RECOVERY, sofia_glue_track_event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
return SWITCH_STATUS_GENERR;
}
@@ -5709,14 +5716,11 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_sofia_shutdown)
}
switch_mutex_unlock(mod_sofia_globals.mutex);
switch_event_unbind(&mod_sofia_globals.in_node);
switch_event_unbind(&mod_sofia_globals.probe_node);
switch_event_unbind(&mod_sofia_globals.out_node);
switch_event_unbind(&mod_sofia_globals.roster_node);
switch_event_unbind(&mod_sofia_globals.custom_node);
switch_event_unbind(&mod_sofia_globals.mwi_node);
switch_event_unbind(&mod_sofia_globals.recovery_node);
switch_event_unbind_callback(sofia_presence_event_handler);
switch_event_unbind_callback(sofia_presence_mwi_event_handler);
switch_event_unbind_callback(sofia_glue_track_event_handler);
switch_event_unbind_callback(general_event_handler);
switch_event_unbind_callback(event_handler);
while (mod_sofia_globals.threads) {
switch_cond_next();
-7
View File
@@ -368,13 +368,6 @@ struct mod_sofia_globals {
int msg_queue_len;
struct sofia_private destroy_private;
struct sofia_private keep_private;
switch_event_node_t *in_node;
switch_event_node_t *probe_node;
switch_event_node_t *out_node;
switch_event_node_t *roster_node;
switch_event_node_t *custom_node;
switch_event_node_t *mwi_node;
switch_event_node_t *recovery_node;
int guess_mask;
char guess_mask_str[16];
int debug_presence;
+75 -11
View File
@@ -1189,8 +1189,59 @@ static void our_sofia_event_callback(nua_event_t event,
case nua_r_refer:
break;
case nua_i_refer:
if (session)
if (session) {
sofia_handle_sip_i_refer(nua, profile, nh, session, sip, de, tags);
} else {
const char *req_user = NULL, *req_host = NULL, *action = NULL, *ref_by_user = NULL;
char *refer_to = NULL, *referred_by = NULL, *method = NULL;
char *params = NULL;
switch_event_t *event;
if (sip->sip_refer_to) {
refer_to = sip_header_as_string(nua_handle_home(nh), (void *) sip->sip_refer_to);
if ((params = strchr(refer_to, ';'))) {
*params++ = '\0';
if ((method = switch_find_parameter(params, "method", NULL))) {
if (!strcasecmp(method, "INVITE")) {
action = "call";
} else if (!strcasecmp(method, "BYE")) {
action = "end";
} else {
action = method;
}
}
}
refer_to = sofia_glue_get_url_from_contact(refer_to, 0);
}
if (sip->sip_referred_by) {
referred_by = sofia_glue_get_url_from_contact(sip_header_as_string(nua_handle_home(nh), (void *) sip->sip_referred_by), 0);
ref_by_user = sip->sip_referred_by->b_url->url_user;
}
if (sip->sip_request && sip->sip_request->rq_url) {
req_user = sip->sip_request->rq_url->url_user;
req_host = sip->sip_request->rq_url->url_host;
}
if (switch_event_create(&event, SWITCH_EVENT_CALL_SETUP_REQ) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Requesting-Component", "mod_sofia");
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Target-Component", req_user);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Target-Domain", req_host);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Request-Action", action);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Request-Target", "sofia/%s/%s", profile->name, refer_to);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Request-Sender", "sofia/%s/%s", profile->name, referred_by);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "var_origination_caller_id_number", ref_by_user);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "var_origination_caller_id_name", ref_by_user);
switch_event_fire(&event);
}
nua_respond(nh, SIP_202_ACCEPTED, NUTAG_WITH_THIS_MSG(de->data->e_msg), TAG_END());
switch_safe_free(method);
}
break;
case nua_r_subscribe:
sofia_presence_handle_sip_r_subscribe(status, phrase, nua, profile, nh, sofia_private, sip, de, tags);
@@ -2112,13 +2163,6 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void
nua_set_params(profile->nua,
SIPTAG_ALLOW_STR("INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, UPDATE, INFO"),
NUTAG_APPL_METHOD("OPTIONS"),
NUTAG_APPL_METHOD("REFER"),
NUTAG_APPL_METHOD("REGISTER"),
NUTAG_APPL_METHOD("NOTIFY"), NUTAG_APPL_METHOD("INFO"), NUTAG_APPL_METHOD("ACK"), NUTAG_APPL_METHOD("SUBSCRIBE"),
#ifdef MANUAL_BYE
NUTAG_APPL_METHOD("BYE"),
#endif
NUTAG_AUTOANSWER(0),
NUTAG_AUTOACK(0),
NUTAG_AUTOALERT(0),
@@ -2131,6 +2175,15 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void
NUTAG_ALLOW("NOTIFY"),
NUTAG_ALLOW_EVENTS("talk"),
NUTAG_ALLOW_EVENTS("hold"),
NUTAG_ALLOW_EVENTS("conference"),
NUTAG_APPL_METHOD("OPTIONS"),
NUTAG_APPL_METHOD("REFER"),
NUTAG_APPL_METHOD("REGISTER"),
NUTAG_APPL_METHOD("NOTIFY"), NUTAG_APPL_METHOD("INFO"), NUTAG_APPL_METHOD("ACK"), NUTAG_APPL_METHOD("SUBSCRIBE"),
#ifdef MANUAL_BYE
NUTAG_APPL_METHOD("BYE"),
#endif
NUTAG_SESSION_TIMER(profile->session_timeout),
NTATAG_MAX_PROCEEDING(profile->max_proceeding),
TAG_IF(profile->pres_type, NUTAG_ALLOW("PUBLISH")),
@@ -6829,11 +6882,13 @@ void sofia_handle_sip_i_refer(nua_t *nua, sofia_profile_t *profile, nua_handle_t
goto done;
}
printf("DICK %d\n", __LINE__);
if (!sip->sip_cseq || !(etmp = switch_mprintf("refer;id=%u", sip->sip_cseq->cs_seq))) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Memory Error!\n");
goto done;
}
printf("DICK %d\n", __LINE__);
from = sip->sip_from;
//to = sip->sip_to;
@@ -6850,7 +6905,7 @@ void sofia_handle_sip_i_refer(nua_t *nua, sofia_profile_t *profile, nua_handle_t
}
if ((refer_to = sip->sip_refer_to)) {
char *rep;
char *rep = NULL;
full_ref_to = sip_header_as_string(home, (void *) sip->sip_refer_to);
if (sofia_test_pflag(profile, PFLAG_FULL_ID)) {
@@ -6861,7 +6916,16 @@ void sofia_handle_sip_i_refer(nua_t *nua, sofia_profile_t *profile, nua_handle_t
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Process REFER to [%s@%s]\n", exten, (char *) refer_to->r_url->url_host);
if (refer_to->r_url->url_headers && (rep = (char *) switch_stristr("Replaces=", refer_to->r_url->url_headers))) {
if (refer_to->r_url && refer_to->r_url->url_headers) {
rep = (char *) switch_stristr("Replaces=", refer_to->r_url->url_headers);
}
printf("WTFX %s\n", rep);
if (!rep) {
printf("WTF [%s]\n", refer_to->r_url->url_headers);
} else {
sip_replaces_t *replaces;
nua_handle_t *bnh = NULL;
+129 -5
View File
@@ -862,7 +862,102 @@ static void do_dialog_probe(switch_event_t *event)
switch_safe_free(probe_user);
}
static void send_conference_data(sofia_profile_t *profile, switch_event_t *event)
{
char *sql;
struct pres_sql_cb cb = {profile, 0};
const char *call_id = switch_event_get_header(event, "call_id");
const char *from_user = switch_event_get_header(event, "conference-name");
const char *from_host = switch_event_get_header(event, "conference-domain");
const char *notfound = switch_event_get_header(event, "notfound");
const char *body = switch_event_get_body(event);
if (!(from_user && from_host)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Event information not given\n");
return;
}
if (switch_true(notfound)) {
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='conference'",
(long)switch_epoch_time_now(NULL),
mod_sofia_globals.hostname, profile->name,
from_user, from_host);
sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
}
if (call_id) {
sql = switch_mprintf("select full_to, full_from, contact %q ';_;isfocus', expires, call_id, event, network_ip, network_port, "
"'application/conference-info+xml' as ct,'%q' as pt "
" from sip_subscriptions where "
"hostname='%q' and profile_name='%q' and sub_to_user='%q' and sub_to_host='%q' and event='conference'"
"and call_id = '%q' ",
switch_sql_concat(),
switch_str_nil(body),
mod_sofia_globals.hostname, profile->name,
from_user, from_host, call_id);
} else {
sql = switch_mprintf("select full_to, full_from, contact %q ';_;isfocus', expires, call_id, event, network_ip, network_port, "
"'application/conference-info+xml' as ct,'%q' as pt "
" from sip_subscriptions where "
"hostname='%q' and profile_name='%q' and sub_to_user='%q' and sub_to_host='%q' and event='conference'",
switch_sql_concat(),
switch_str_nil(body),
mod_sofia_globals.hostname, profile->name,
from_user, from_host);
}
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_send_sql, &cb);
switch_safe_free(sql);
}
static void conference_data_event_handler(switch_event_t *event)
{
const char *pname;
//const char *from_user = switch_event_get_header(event, "conference-name");
//const char *from_host = switch_event_get_header(event, "conference-domain");
const char *host = switch_event_get_header(event, "conference-domain");
char *dup_domain = NULL;
sofia_profile_t *profile = NULL;
if (zstr(host)) {
dup_domain = switch_core_get_variable_dup("domain");
host = dup_domain;
}
if ((pname = switch_event_get_header(event, "sofia-profile"))) {
profile = sofia_glue_find_profile(pname);
}
if (host && !profile) {
profile = sofia_glue_find_profile(host);
}
if (profile) {
send_conference_data(profile, event);
sofia_glue_release_profile(profile);
} else {
switch_console_callback_match_t *matches;
if (list_profiles_full(NULL, NULL, &matches, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS) {
switch_console_callback_match_node_t *m;
for (m = matches->head; m; m = m->next) {
if ((profile = sofia_glue_find_profile(m->val))) {
send_conference_data(profile, event);
sofia_glue_release_profile(profile);
}
}
switch_console_free_matches(&matches);
}
}
switch_safe_free(dup_domain);
}
static void actual_sofia_presence_event_handler(switch_event_t *event)
{
@@ -1374,7 +1469,13 @@ void *SWITCH_THREAD_FUNC sofia_presence_event_thread_run(switch_thread_t *thread
if (!pop) {
break;
}
actual_sofia_presence_event_handler(event);
if (event->event_id == SWITCH_EVENT_CONFERENCE_DATA) {
conference_data_event_handler(event);
} else {
actual_sofia_presence_event_handler(event);
}
switch_event_destroy(&event);
count++;
}
@@ -1871,14 +1972,22 @@ static void _send_presence_notify(sofia_profile_t *profile,
char *our_contact = profile->url, *our_contact_dup = NULL;
sofia_destination_t *dst = NULL;
char *contact_str, *contact, *user_via = NULL;
char *contact_str, *contact, *user_via = NULL, *send_contact = NULL;
char *route_uri = NULL, *o_contact_dup = NULL, *tmp, *to_uri, *dcs = NULL;
const char *tp;
char *cparams = NULL;
if (zstr(full_to) || zstr(full_from) || zstr(o_contact)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "MISSING DATA TO SEND NOTIFY.\n");
return;
}
if ((cparams = strstr(o_contact, ";_;"))) {
cparams += 3;
}
tmp = (char *)o_contact;
o_contact_dup = sofia_glue_get_url_from_contact(tmp, 1);
@@ -2012,6 +2121,12 @@ static void _send_presence_notify(sofia_profile_t *profile,
callsequence = ++profile->cseq_base;
switch_mutex_unlock(profile->ireg_mutex);
if (cparams) {
send_contact = switch_mprintf("%s;%s", contact_str, cparams);
contact_str = send_contact;
}
nh = nua_handle(profile->nua, NULL, NUTAG_URL(contact), SIPTAG_CONTACT_STR(contact_str), TAG_END());
cseq = sip_cseq_create(nh->nh_home, callsequence, SIP_METHOD_NOTIFY);
@@ -2047,6 +2162,7 @@ static void _send_presence_notify(sofia_profile_t *profile,
sofia_glue_free_destination(dst);
switch_safe_free(user_via);
switch_safe_free(o_contact_dup);
switch_safe_free(send_contact);
switch_safe_free(our_contact_dup);
@@ -3649,9 +3765,17 @@ void sofia_presence_handle_sip_i_subscribe(int status,
switch_safe_free(sql);
}
}
if ( sip->sip_event && sip->sip_event->o_type && !strcasecmp(sip->sip_event->o_type, "ua-profile") && contact_host ) {
} else if (!strcasecmp(event, "conference")) {
switch_event_t *event;
switch_event_create(&event, SWITCH_EVENT_CONFERENCE_DATA_QUERY);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Conference-Name", to_user);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Conference-Domain", to_host);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Query-From", from_user);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Query-From-Domain", from_host);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Call-Id", call_id);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Sofia-Profile", profile->name);
switch_event_fire(&event);
} else if ( sip->sip_event && sip->sip_event->o_type && !strcasecmp(sip->sip_event->o_type, "ua-profile") && contact_host ) {
switch_event_t *params;
char *uri = NULL;
char *extra_headers = NULL;