}
}
- end:
+ end:
switch_mutex_unlock(tech_pvt->sofia_mutex);
const char *var, *header, *ua = switch_channel_get_variable(tech_pvt->channel, "sip_user_agent");
char *pai = NULL;
- if (!sofia_test_pflag(tech_pvt->profile, PFLAG_CID_IN_1XX) ||
+ if (!sofia_test_pflag(tech_pvt->profile, PFLAG_CID_IN_1XX) ||
((var = switch_channel_get_variable(tech_pvt->channel, "sip_cid_in_1xx")) && switch_false(var))) {
return NULL;
}
}
if (!sofia_test_flag(tech_pvt, TFLAG_BYE)) {
char *cid = generate_pai_str(session);
-
+
nua_respond(tech_pvt->nh, sip_cause, sip_status_phrase(sip_cause),
TAG_IF(!zstr(reason), SIPTAG_REASON_STR(reason)),
TAG_IF(cid, SIPTAG_HEADER_STR(cid)), TAG_IF(!zstr(bye_headers), SIPTAG_HEADER_STR(bye_headers)), TAG_END());
if (switch_channel_test_flag(tech_pvt->channel, CF_PROXY_MODE) && tech_pvt->early_sdp && strcmp(tech_pvt->early_sdp, tech_pvt->local_sdp_str)) {
/* The SIP RFC for SOA forbids sending a 183 with one sdp then a 200 with another but it won't do us much good unless
we do so in this case we will abandon the SOA rules and go rogue.
- */
+ */
sofia_clear_flag(tech_pvt, TFLAG_ENABLE_SOA);
}
tech_pvt->mismatch_count = 0;
tech_pvt->last_ts = 0;
}
- skip:
+ skip:
if ((bytes = tech_pvt->read_impl.encoded_bytes_per_packet)) {
frames = (tech_pvt->read_frame.datalen / bytes);
tech_pvt->early_sdp && strcmp(tech_pvt->early_sdp, tech_pvt->local_sdp_str)) {
/* The SIP RFC for SOA forbids sending a 183 with one sdp then a 200 with another but it won't do us much good unless
we do so in this case we will abandon the SOA rules and go rogue.
- */
+ */
sofia_clear_flag(tech_pvt, TFLAG_ENABLE_SOA);
}
break;
}
- end_lock:
+ end_lock:
//if (msg->message_id == SWITCH_MESSAGE_INDICATE_ANSWER || msg->message_id == SWITCH_MESSAGE_INDICATE_PROGRESS) {
//sofia_send_callee_id(session, NULL, NULL);
switch_mutex_unlock(tech_pvt->sofia_mutex);
- end:
+ end:
if (switch_channel_down(channel) || !tech_pvt || sofia_test_flag(tech_pvt, TFLAG_BYE)) {
status = SWITCH_STATUS_FALSE;
stream->write_function(stream, "-ERR Unknown command!\n");
- done:
+ done:
if (profile) {
sofia_glue_release_profile(profile);
}
sofia_reg_release_gateway(gateway);
- end:
+ end:
switch_safe_free(mydata);
return SWITCH_STATUS_SUCCESS;
}
stream->write_function(stream, "Unknown Command [%s]\n", argv[0]);
}
- done:
+ done:
switch_safe_free(mycmd);
return status;
}
if (switch_core_session_compare(session, nsession)) {
/* It's another sofia channel! so lets cache what they use as a pt for telephone event so
we can keep it the same
- */
+ */
private_object_t *ctech_pvt;
ctech_pvt = switch_core_session_get_private(session);
switch_assert(ctech_pvt != NULL);
goto done;
- error:
+ error:
if (nsession) {
switch_core_session_destroy(&nsession);
}
if (pool) {
*pool = NULL;
}
- done:
+ done:
if (profile) {
if (cause == SWITCH_CAUSE_SUCCESS) {
sql = switch_mprintf("select sip_user,sip_host,contact,profile_name,'%q','%q','%q' "
"from sip_registrations where mwi_user='%s' and mwi_host='%q'",
ct, es, switch_str_nil(body), switch_str_nil(user), switch_str_nil(host)
- );
+ );
} else {
sql = switch_mprintf("select sip_user,sip_host,contact,profile_name,'%q','%q','%q' "
"from sip_registrations where sip_user='%s' and sip_host='%q'",
ct, es, switch_str_nil(body), switch_str_nil(user), switch_str_nil(host)
- );
+ );
}
}
sofia_glue_release_profile(profile);
}
- done:
+ done:
switch_safe_free(local_dup);
status = SWITCH_STATUS_SUCCESS;
}
- end:
+ end:
switch_safe_free(dup);
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) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
+ return SWITCH_STATUS_GENERR;
+ }
+
if (switch_event_bind(modname, SWITCH_EVENT_TRAP, SWITCH_EVENT_SUBCLASS_ANY, general_event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
return SWITCH_STATUS_GENERR;
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(general_event_handler);
while (mod_sofia_globals.threads) {
#define MY_EVENT_REINVITE "sofia::reinvite"
#define MY_EVENT_GATEWAY_ADD "sofia::gateway_add"
#define MY_EVENT_GATEWAY_DEL "sofia::gateway_delete"
+#define MY_EVENT_RECOVERY "sofia::recovery"
+#define MY_EVENT_RECOVERY_SEND "sofia::recovery_send"
#define MULTICAST_EVENT "multicast::event"
#define SOFIA_REPLACES_HEADER "_sofia_replaces_"
PFLAG_PASS_CALLEE_ID,
PFLAG_LOG_AUTH_FAIL,
PFLAG_TRACK_CALLS,
+ PFLAG_TRACK_CALLS_EVENTS,
PFLAG_DESTROY,
PFLAG_EXTENDED_INFO_PARSING,
PFLAG_T38_PASSTHRU,
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;
void sofia_handle_sip_i_info(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, switch_core_session_t *session, sip_t const *sip, tagi_t tags[]);
-void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
- tagi_t tags[]);
+void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[]);
void sofia_reg_handle_sip_i_register(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
tagi_t tags[]);
void event_handler(switch_event_t *event);
void sofia_presence_event_handler(switch_event_t *event);
void sofia_presence_mwi_event_handler(switch_event_t *event);
+void sofia_glue_track_event_handler(switch_event_t *event);
void sofia_presence_cancel(void);
switch_status_t config_sofia(int reload, char *profile_name);
void sofia_reg_auth_challenge(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_regtype_t regtype, const char *realm, int stale);
/*
* Transport handling helper functions
*/
-sofia_transport_t sofia_glue_via2transport(const sip_via_t *via);
+sofia_transport_t sofia_glue_via2transport(const sip_via_t * via);
sofia_transport_t sofia_glue_url2transport(const url_t *url);
sofia_transport_t sofia_glue_str2transport(const char *str);
int sofia_glue_check_nat(sofia_profile_t *profile, const char *network_ip);
int sofia_glue_transport_has_tls(const sofia_transport_t tp);
const char *sofia_glue_get_unknown_header(sip_t const *sip, const char *name);
-switch_status_t sofia_glue_build_crypto(private_object_t *tech_pvt, int index, switch_rtp_crypto_key_type_t type,
- switch_rtp_crypto_direction_t direction);
+switch_status_t sofia_glue_build_crypto(private_object_t *tech_pvt, int index, switch_rtp_crypto_key_type_t type, switch_rtp_crypto_direction_t direction);
void sofia_glue_tech_patch_sdp(private_object_t *tech_pvt);
switch_status_t sofia_glue_tech_proxy_remote_addr(private_object_t *tech_pvt);
void sofia_presence_event_thread_start(void);
} else {
sofia_clear_pflag(profile, PFLAG_UUID_AS_CALLID);
}
- } else if (!strcasecmp(var, "track-calls") && switch_true(val)) {
- sofia_set_pflag(profile, PFLAG_TRACK_CALLS);
+ } else if (!strcasecmp(var, "track-calls")) {
+ if (switch_true(val)) {
+ sofia_set_pflag(profile, PFLAG_TRACK_CALLS);
+ } else if (!strcasecmp(val, "events")) {
+ sofia_set_pflag(profile, PFLAG_TRACK_CALLS);
+ sofia_set_pflag(profile, PFLAG_TRACK_CALLS_EVENTS);
+ }
} else if (!strcasecmp(var, "NDLB-received-in-nat-reg-contact") && switch_true(val)) {
sofia_set_pflag(profile, PFLAG_RECIEVED_IN_NAT_REG_CONTACT);
} else if (!strcasecmp(var, "aggressive-nat-detection") && switch_true(val)) {
}
switch_channel_set_variable(channel, "sip_invite_call_id", switch_channel_get_variable(channel, "sip_call_id"));
- switch_channel_set_variable(channel, "sip_invite_cseq", switch_channel_get_variable(channel, "sip_cseq"));
if (switch_true(switch_channel_get_variable(channel, "sip_nat_detected"))) {
switch_channel_set_variable_printf(channel, "sip_route_uri", "sip:%s@%s:%s",
return r;
}
+void sofia_glue_track_event_handler(switch_event_t *event)
+{
+ char *sql, *buf = NULL;
+ char *profile_name = NULL;
+
+ switch_assert(event); // Just a sanity check
+
+ if ((buf = switch_event_get_header_nil(event, "sql")) && (profile_name = switch_event_get_header_nil(event, "profile_name"))) {
+ sofia_profile_t *profile;
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s\n", switch_event_get_header_nil(event, "Event-Calling-Function"));
+ if ((profile = sofia_glue_find_profile(profile_name))) {
+ sql = switch_mprintf("%s", buf);
+ sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
+ sofia_glue_release_profile(profile);
+ }
+ }
+
+ return;
+}
void sofia_glue_tech_untrack(sofia_profile_t *profile, switch_core_session_t *session, switch_bool_t force)
{
- char *sql;
+ char *sql = NULL;
private_object_t *tech_pvt = (private_object_t *) switch_core_session_get_private(session);
if (!sofia_test_pflag(profile, PFLAG_TRACK_CALLS) || (sofia_test_flag(tech_pvt, TFLAG_RECOVERING))) {
}
if (sofia_test_pflag(profile, PFLAG_TRACK_CALLS) && (sofia_test_flag(tech_pvt, TFLAG_TRACKED) || force)) {
+ switch_event_t *event = NULL;
if (force) {
sql = switch_mprintf("delete from sip_recovery where uuid='%q'", switch_core_session_get_uuid(session));
-
+
} else {
sql = switch_mprintf("delete from sip_recovery where runtime_uuid='%q' and uuid='%q'",
switch_core_get_uuid(), switch_core_session_get_uuid(session));
}
+
+ if (sofia_test_pflag(profile, PFLAG_TRACK_CALLS_EVENTS)) {
+ if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, MY_EVENT_RECOVERY_SEND) == SWITCH_STATUS_SUCCESS) {
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "sql", sql);
+ switch_event_fire(&event);
+ }
+ }
+
sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
sofia_clear_flag(tech_pvt, TFLAG_TRACKED);
+
+ switch_safe_free(sql);
}
+
+
}
void sofia_glue_tech_track(sofia_profile_t *profile, switch_core_session_t *session)
{
- switch_event_t *event;
private_object_t *tech_pvt = (private_object_t *) switch_core_session_get_private(session);
+ switch_xml_t cdr = NULL;
+ char *xml_cdr_text = NULL;
+ char *sql = NULL;
if (!sofia_test_pflag(profile, PFLAG_TRACK_CALLS) || sofia_test_flag(tech_pvt, TFLAG_RECOVERING)) {
return;
sofia_glue_tech_untrack(profile, session, SWITCH_TRUE);
}
- if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_DATA) == SWITCH_STATUS_SUCCESS) {
- switch_xml_t cdr = NULL;
- char *xml_cdr_text = NULL;
-
- if (switch_ivr_generate_xml_cdr(session, &cdr) == SWITCH_STATUS_SUCCESS) {
- xml_cdr_text = switch_xml_toxml(cdr, SWITCH_FALSE);
- switch_xml_free(cdr);
- }
-
- if (xml_cdr_text) {
- char *sql;
- sql = switch_mprintf("insert into sip_recovery (runtime_uuid, profile_name, hostname, uuid, metadata) values ('%q','%q','%q','%q','%q')",
- switch_core_get_uuid(), profile->name, mod_sofia_globals.hostname, switch_core_session_get_uuid(session), xml_cdr_text);
+ if (switch_ivr_generate_xml_cdr(session, &cdr) == SWITCH_STATUS_SUCCESS) {
+ xml_cdr_text = switch_xml_toxml(cdr, SWITCH_FALSE);
+ switch_xml_free(cdr);
+ }
- sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
- free(xml_cdr_text);
- sofia_set_flag(tech_pvt, TFLAG_TRACKED);
+ if (xml_cdr_text) {
+ sql = switch_mprintf("insert into sip_recovery (runtime_uuid, profile_name, hostname, uuid, metadata) values ('%q','%q','%q','%q','%q')",
+ switch_core_get_uuid(), profile->name, mod_sofia_globals.hostname, switch_core_session_get_uuid(session), xml_cdr_text);
+
+ if (sofia_test_pflag(profile, PFLAG_TRACK_CALLS_EVENTS)) {
+ switch_event_t *event = NULL;
+
+ if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, MY_EVENT_RECOVERY_SEND) == SWITCH_STATUS_SUCCESS) {
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "sql", sql);
+ switch_event_fire(&event);
+ }
}
+
+ sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
+ free(xml_cdr_text);
+ sofia_set_flag(tech_pvt, TFLAG_TRACKED);
+
}
+
+
+ switch_safe_free(sql);
}
switch_cache_db_persistant_execute_trans(dbh, sql, 1);
- end:
+ end:
switch_cache_db_release_db_handle(&dbh);
switch_cache_db_execute_sql(dbh, sql, NULL);
- end:
+ end:
switch_cache_db_release_db_handle(&dbh);
free(errmsg);
}
- end:
+ end:
switch_cache_db_release_db_handle(&dbh);
dst->route_uri = route_uri;
return dst;
- mem_fail:
+ mem_fail:
switch_safe_free(contact);
switch_safe_free(to);
switch_safe_free(route);
/*!
\brief Open the default system database
*/
-SWITCH_DECLARE(switch_status_t) _switch_core_db_handle(switch_cache_db_handle_t ** dbh, const char *file, const char *func, int line)
+SWITCH_DECLARE(switch_status_t) _switch_core_db_handle(switch_cache_db_handle_t **dbh, const char *file, const char *func, int line)
{
switch_cache_db_connection_options_t options = { {0} };
switch_status_t r;
-SWITCH_DECLARE(void) switch_cache_db_release_db_handle(switch_cache_db_handle_t ** dbh)
+SWITCH_DECLARE(void) switch_cache_db_release_db_handle(switch_cache_db_handle_t **dbh)
{
if (dbh && *dbh) {
default:
break;
}
-
+
switch_mutex_unlock((*dbh)->mutex);
*dbh = NULL;
}
}
-SWITCH_DECLARE(void) switch_cache_db_dismiss_db_handle(switch_cache_db_handle_t ** dbh)
+SWITCH_DECLARE(void) switch_cache_db_dismiss_db_handle(switch_cache_db_handle_t **dbh)
{
if (dbh && *dbh) {
}
-SWITCH_DECLARE(void) switch_cache_db_destroy_db_handle(switch_cache_db_handle_t ** dbh)
+SWITCH_DECLARE(void) switch_cache_db_destroy_db_handle(switch_cache_db_handle_t **dbh)
{
if (dbh && *dbh) {
switch_mutex_lock(sql_manager.dbh_mutex);
switch_mutex_unlock(sql_manager.dbh_mutex);
}
-SWITCH_DECLARE(switch_status_t) _switch_cache_db_get_db_handle(switch_cache_db_handle_t ** dbh,
+SWITCH_DECLARE(switch_status_t) _switch_cache_db_get_db_handle(switch_cache_db_handle_t **dbh,
switch_cache_db_handle_type_t type,
switch_cache_db_connection_options_t *connection_options,
const char *file, const char *func, int line)
if ((new_dbh = (switch_cache_db_handle_t *) val)) {
if (hash == new_dbh->hash && !strncasecmp(new_dbh->name, db_str, strlen(db_str)) &&
- !switch_test_flag(new_dbh, CDF_INUSE) && !switch_test_flag(new_dbh, CDF_PRUNE)
+ !switch_test_flag(new_dbh, CDF_INUSE) && !switch_test_flag(new_dbh, CDF_PRUNE)
&& switch_mutex_trylock(new_dbh->mutex) == SWITCH_STATUS_SUCCESS) {
switch_set_flag(new_dbh, CDF_INUSE);
switch_set_string(new_dbh->name, thread_str);
}
while (!sql_manager.event_db) {
- if (switch_core_db_handle(&sql_manager.event_db) == SWITCH_STATUS_SUCCESS && sql_manager.event_db) break;
+ if (switch_core_db_handle(&sql_manager.event_db) == SWITCH_STATUS_SUCCESS && sql_manager.event_db)
+ break;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Error getting core db, Retrying\n");
switch_yield(500000);
sanity--;
}
#define MAX_SQL 5
-#define new_sql() switch_assert(sql_idx+1 < MAX_SQL); sql[sql_idx++]
+#define new_sql() switch_assert(sql_idx+1 < MAX_SQL); sql[sql_idx++]
static void core_event_handler(switch_event_t *event)
{
if (id) {
new_sql() = switch_mprintf("update tasks set task_desc='%q',task_group='%q', task_sql_manager=%q where task_id=%q and hostname='%q'",
switch_event_get_header_nil(event, "task-desc"),
- switch_event_get_header_nil(event, "task-group"), manager ? manager : "0", id, switch_core_get_variable("hostname"));
+ switch_event_get_header_nil(event, "task-group"), manager ? manager : "0", id,
+ switch_core_get_variable("hostname"));
}
}
break;
if (!name) {
name = switch_event_get_header(event, "caller-callee-id-name");
}
-
+
if (!number) {
number = switch_event_get_header(event, "caller-callee-id-number");
}
{
new_sql() = switch_mprintf("update channels set callstate='%q' where uuid='%q' and hostname='%q'",
switch_event_get_header_nil(event, "channel-call-state"),
- switch_event_get_header_nil(event, "unique-id"),
- switch_core_get_variable("hostname"));
-
+ switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname"));
+
}
break;
case SWITCH_EVENT_CHANNEL_STATE:
if (sql_idx) {
int i = 0;
- for(i = 0; i < sql_idx; i++) {
+ for (i = 0; i < sql_idx; i++) {
if (switch_stristr("update channels", sql[i]) || switch_stristr("delete from channels", sql[i])) {
switch_queue_push(sql_manager.sql_queue[1], sql[i]);
} else {
" callee_chan_name VARCHAR(1024),\n"
" callee_uuid VARCHAR(256),\n"
" hostname VARCHAR(256)\n"
- ");\n" "create index eruuindex on calls (caller_uuid,hostname);\n"
+ ");\n"
+ "create index eruuindex on calls (caller_uuid,hostname);\n"
"create index eeuuindex on calls (callee_uuid,hostname);\n"
- "create index eeuuindex2 on calls (call_uuid,hostname);\n"
- ;
+ "create index eeuuindex2 on calls (call_uuid,hostname);\n";
static char create_interfaces_sql[] =
"CREATE TABLE interfaces (\n"