Merge branch 'master' into gsmopen01

This commit is contained in:
Giovanni Maruzzelli
2012-04-06 20:17:54 +02:00
55 changed files with 1173 additions and 763 deletions
+4 -2
View File
@@ -314,7 +314,8 @@ typedef enum {
SCF_CLEAR_SQL = (1 << 17),
SCF_THREADED_SYSTEM_EXEC = (1 << 18),
SCF_SYNC_CLOCK_REQUESTED = (1 << 19),
SCF_CORE_ODBC_REQ = (1 << 20)
SCF_CORE_ODBC_REQ = (1 << 20),
SCF_DEBUG_SQL = (1 << 21)
} switch_core_flag_enum_t;
typedef uint32_t switch_core_flag_t;
@@ -1743,7 +1744,8 @@ typedef enum {
SCSC_PAUSE_CHECK,
SCSC_READY_CHECK,
SCSC_THREADED_SYSTEM_EXEC,
SCSC_SYNC_CLOCK_WHEN_IDLE
SCSC_SYNC_CLOCK_WHEN_IDLE,
SCSC_DEBUG_SQL,
} switch_session_ctl_t;
typedef enum {
+1 -1
View File
@@ -214,7 +214,7 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_get(_In_ switch_xml_t xml,...);
///\param prn_header add <?xml version..> header too
///\return the xml text string
SWITCH_DECLARE(char *) switch_xml_toxml(_In_ switch_xml_t xml, _In_ switch_bool_t prn_header);
SWITCH_DECLARE(char *) switch_xml_toxml_nolock(switch_xml_t xml, _In_ switch_bool_t prn_header);
///\brief Converts an switch_xml structure back to xml using the buffer passed in the parameters.
///\param xml the xml node
///\param buf buffer to use
+1
View File
@@ -14,6 +14,7 @@
/applications/mod_fax/mod_fax.log
/applications/mod_fifo/Makefile
/applications/mod_fsv/Makefile
/applications/mod_httapi/Makefile
/applications/mod_limit/Makefile
/applications/mod_sms/Makefile
/applications/mod_spandsp/Makefile
@@ -1908,6 +1908,12 @@ SWITCH_STANDARD_API(ctl_function)
}
switch_core_session_ctl(command, &arg);
stream->write_function(stream, "+OK\n");
} else if (!strcasecmp(argv[0], "debug_sql")) {
int x = 0;
switch_core_session_ctl(SCSC_DEBUG_SQL, &x);
stream->write_function(stream, "+OK SQL DEBUG [%s]\n", x ? "on" : "off");
} else if (!strcasecmp(argv[0], "reclaim_mem")) {
switch_core_session_ctl(SCSC_RECLAIM, &arg);
stream->write_function(stream, "+OK\n");
@@ -5461,6 +5467,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
switch_console_set_complete("add complete del");
switch_console_set_complete("add db_cache status");
switch_console_set_complete("add fsctl debug_level");
switch_console_set_complete("add fsctl debug_sql");
switch_console_set_complete("add fsctl last_sps");
switch_console_set_complete("add fsctl default_dtmf_duration");
switch_console_set_complete("add fsctl hupall");
+1 -1
View File
@@ -226,7 +226,7 @@ SWITCH_STANDARD_APP(bcast_function)
bytes = 16;
switch_socket_sendto(socket, control_packet_addr, 0, (void *) &control_packet, &bytes);
for (;;) {
while (switch_channel_ready(channel)) {
status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
@@ -319,7 +319,7 @@ user-agent : <string> mod_httapi/1.0 User Agent header value.
<permissions>: * = default
<permission name="" value="">
<permission name="" value="true">
*set-params : <params> tag can be parsed for session params.
set-vars : <variables> tag can be parsed to set channel vars.
+1 -1
View File
@@ -1498,7 +1498,7 @@ static switch_status_t httapi_sync(client_t *client)
switch_curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, headers);
if (method != NULL && strcasecmp(method, "get") && strcasecmp(method, "post")) {
if (!zstr(method)) {
switch_curl_easy_setopt(curl_handle, CURLOPT_CUSTOMREQUEST, method);
}
+7 -5
View File
@@ -87,8 +87,8 @@ void sofia_handle_sip_r_notify(switch_core_session_t *session, int status,
nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
sofia_dispatch_event_t *de, tagi_t tags[])
{
#if 0
if (status >= 300 && sip && !sip->sip_retry_after && sip->sip_call_id && (!sofia_private || !sofia_private->is_call)) {
if (status == 481 && sip && !sip->sip_retry_after && sip->sip_call_id && (!sofia_private || !sofia_private->is_call)) {
char *sql;
sql = switch_mprintf("delete from sip_subscriptions where call_id='%q'", sip->sip_call_id->i_id);
@@ -96,7 +96,7 @@ void sofia_handle_sip_r_notify(switch_core_session_t *session, int status,
sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
nua_handle_destroy(nh);
}
#endif
}
#define url_set_chanvars(session, url, varprefix) _url_set_chanvars(session, url, #varprefix "_user", #varprefix "_host", #varprefix "_port", #varprefix "_uri", #varprefix "_params")
@@ -8282,8 +8282,10 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_
tech_pvt->caller_profile->callee_id_number = switch_core_strdup(tech_pvt->caller_profile->pool, orig_cp->caller_id_number);
}
}
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "Setting NAT mode based on %s\n", is_nat);
if (is_nat) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "Setting NAT mode based on %s\n", is_nat);
}
if (app && data && !strcasecmp(app, "conference")) {
+31 -8
View File
@@ -2439,11 +2439,22 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session)
switch (cid_type) {
case CID_TYPE_PID:
if (switch_test_flag(caller_profile, SWITCH_CPF_SCREEN)) {
tech_pvt->asserted_id = switch_core_session_sprintf(tech_pvt->session, "\"%s\"<sip:%s@%s>", use_name, use_number, rpid_domain);
if (zstr(tech_pvt->caller_profile->caller_id_name) || !strcasecmp(tech_pvt->caller_profile->caller_id_name, "_undef_")) {
tech_pvt->asserted_id = switch_core_session_sprintf(tech_pvt->session, "<sip:%s@%s>",
use_number, rpid_domain);
} else {
tech_pvt->asserted_id = switch_core_session_sprintf(tech_pvt->session, "\"%s\"<sip:%s@%s>",
use_name, use_number, rpid_domain);
}
} else {
tech_pvt->preferred_id = switch_core_session_sprintf(tech_pvt->session, "\"%s\"<sip:%s@%s>",
tech_pvt->caller_profile->caller_id_name,
tech_pvt->caller_profile->caller_id_number, rpid_domain);
if (zstr(tech_pvt->caller_profile->caller_id_name) || !strcasecmp(tech_pvt->caller_profile->caller_id_name, "_undef_")) {
tech_pvt->preferred_id = switch_core_session_sprintf(tech_pvt->session, "<sip:%s@%s>",
tech_pvt->caller_profile->caller_id_number, rpid_domain);
} else {
tech_pvt->preferred_id = switch_core_session_sprintf(tech_pvt->session, "\"%s\"<sip:%s@%s>",
tech_pvt->caller_profile->caller_id_name,
tech_pvt->caller_profile->caller_id_number, rpid_domain);
}
}
if (switch_test_flag(caller_profile, SWITCH_CPF_HIDE_NUMBER)) {
@@ -2604,8 +2615,8 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session)
TAG_IF(invite_full_from, SIPTAG_FROM_STR(invite_full_from)),
TAG_IF(invite_full_to, SIPTAG_TO_STR(invite_full_to)),
TAG_IF(tech_pvt->redirected, NUTAG_URL(tech_pvt->redirected)),
TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)),
TAG_IF(!zstr(recover_via), SIPTAG_VIA_STR(recover_via)),
TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)),
TAG_IF(!zstr(tech_pvt->rpid), SIPTAG_REMOTE_PARTY_ID_STR(tech_pvt->rpid)),
TAG_IF(!zstr(tech_pvt->preferred_id), SIPTAG_P_PREFERRED_IDENTITY_STR(tech_pvt->preferred_id)),
TAG_IF(!zstr(tech_pvt->asserted_id), SIPTAG_P_ASSERTED_IDENTITY_STR(tech_pvt->asserted_id)),
@@ -2638,8 +2649,8 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session)
TAG_IF(invite_full_from, SIPTAG_FROM_STR(invite_full_from)),
TAG_IF(invite_full_to, SIPTAG_TO_STR(invite_full_to)),
TAG_IF(tech_pvt->redirected, NUTAG_URL(tech_pvt->redirected)),
TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)),
TAG_IF(!zstr(recover_via), SIPTAG_VIA_STR(recover_via)),
TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)),
TAG_IF(!zstr(tech_pvt->rpid), SIPTAG_REMOTE_PARTY_ID_STR(tech_pvt->rpid)),
TAG_IF(!zstr(tech_pvt->preferred_id), SIPTAG_P_PREFERRED_IDENTITY_STR(tech_pvt->preferred_id)),
TAG_IF(!zstr(tech_pvt->asserted_id), SIPTAG_P_ASSERTED_IDENTITY_STR(tech_pvt->asserted_id)),
@@ -3881,13 +3892,25 @@ void sofia_glue_set_r_sdp_codec_string(switch_core_session_t *session, const cha
if (zstr(attr->a_name)) {
continue;
}
if (!strcasecmp(attr->a_name, "ptime")) {
dptime = atoi(attr->a_value);
break;
}
}
switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG, "Looking for zrtp-hash to set sdp_zrtp_hash_string\n");
for (m = sdp->sdp_media; m; m = m->m_next) {
for (attr = m->m_attributes; attr; attr = attr->a_next) {
if (zstr(attr->a_name)) continue;
if (!strcasecmp(attr->a_name, "zrtp-hash") && attr->a_value) {
switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG, "Found zrtp-hash, setting sdp_zrtp_hash_string=%s\n", attr->a_value);
switch_channel_set_variable(channel, "sdp_zrtp_hash_string", attr->a_value);
switch_channel_set_flag(channel, CF_ZRTP_HASH);
break;
}
}
}
for (m = sdp->sdp_media; m; m = m->m_next) {
ptime = dptime;
if (m->m_type == sdp_media_image && m->m_port) {
@@ -5948,7 +5971,7 @@ void sofia_glue_tech_track(sofia_profile_t *profile, switch_core_session_t *sess
}
if (switch_ivr_generate_xml_cdr(session, &cdr) == SWITCH_STATUS_SUCCESS) {
xml_cdr_text = switch_xml_toxml(cdr, SWITCH_FALSE);
xml_cdr_text = switch_xml_toxml_nolock(cdr, SWITCH_FALSE);
switch_xml_free(cdr);
}
+5 -2
View File
@@ -2101,7 +2101,8 @@ void sofia_reg_handle_sip_r_challenge(int status,
} else if (gateway) {
switch_snprintf(authentication, sizeof(authentication), "%s:%s:%s:%s", scheme, realm, gateway->auth_username, gateway->register_password);
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot locate any authentication credentials to complete an authentication request for realm '%s'\n", realm);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR,
"Cannot locate any authentication credentials to complete an authentication request for realm '%s'\n", realm);
goto cancel;
}
@@ -2114,7 +2115,9 @@ void sofia_reg_handle_sip_r_challenge(int status,
tl_gets(tags, NUTAG_CALLSTATE_REF(ss_state), SIPTAG_WWW_AUTHENTICATE_REF(authenticate), TAG_END());
nua_authenticate(nh, SIPTAG_EXPIRES_STR(gateway ? gateway->expires_str : "3600"), NUTAG_AUTH(authentication), TAG_END());
nua_authenticate(nh,
TAG_IF(sofia_private && sofia_private->gateway, SIPTAG_EXPIRES_STR(gateway ? gateway->expires_str : "3600")),
NUTAG_AUTH(authentication), TAG_END());
goto end;
@@ -181,60 +181,61 @@ static switch_status_t set_json_cdr_log_dirs()
return status;
}
#define json_object_safe_new_string(str) json_object_new_string(str ? str : "")
#define JSON_ENSURE_SUCCESS(obj) if (is_error(obj)) { return; }
static void set_json_profile_data(struct json_object *json, switch_caller_profile_t *caller_profile)
{
struct json_object *param = NULL;
param = json_object_new_string((char *)caller_profile->username);
param = json_object_safe_new_string((char *)caller_profile->username);
JSON_ENSURE_SUCCESS(param);
json_object_object_add(json, "username", param);
param = json_object_new_string((char *)caller_profile->dialplan);
param = json_object_safe_new_string((char *)caller_profile->dialplan);
JSON_ENSURE_SUCCESS(param);
json_object_object_add(json, "dialplan", param);
param = json_object_new_string((char *)caller_profile->caller_id_name);
param = json_object_safe_new_string((char *)caller_profile->caller_id_name);
JSON_ENSURE_SUCCESS(param);
json_object_object_add(json, "caller_id_name", param);
param = json_object_new_string((char *)caller_profile->ani);
param = json_object_safe_new_string((char *)caller_profile->ani);
JSON_ENSURE_SUCCESS(param);
json_object_object_add(json, "ani", param);
param = json_object_new_string((char *)caller_profile->aniii);
param = json_object_safe_new_string((char *)caller_profile->aniii);
JSON_ENSURE_SUCCESS(param);
json_object_object_add(json, "aniii", param);
param = json_object_new_string((char *)caller_profile->caller_id_number);
param = json_object_safe_new_string((char *)caller_profile->caller_id_number);
JSON_ENSURE_SUCCESS(param);
json_object_object_add(json, "caller_id_number", param);
param = json_object_new_string((char *)caller_profile->network_addr);
param = json_object_safe_new_string((char *)caller_profile->network_addr);
JSON_ENSURE_SUCCESS(param);
json_object_object_add(json, "network_addr", param);
param = json_object_new_string((char *)caller_profile->rdnis);
param = json_object_safe_new_string((char *)caller_profile->rdnis);
JSON_ENSURE_SUCCESS(param);
json_object_object_add(json, "rdnis", param);
param = json_object_new_string(caller_profile->destination_number);
param = json_object_safe_new_string(caller_profile->destination_number);
JSON_ENSURE_SUCCESS(param);
json_object_object_add(json, "destination_number", param);
param = json_object_new_string(caller_profile->uuid);
param = json_object_safe_new_string(caller_profile->uuid);
JSON_ENSURE_SUCCESS(param);
json_object_object_add(json, "uuid", param);
param = json_object_new_string((char *)caller_profile->source);
param = json_object_safe_new_string((char *)caller_profile->source);
JSON_ENSURE_SUCCESS(param);
json_object_object_add(json, "source", param);
param = json_object_new_string((char *)caller_profile->context);
param = json_object_safe_new_string((char *)caller_profile->context);
JSON_ENSURE_SUCCESS(param);
json_object_object_add(json, "context", param);
param = json_object_new_string(caller_profile->chan_name);
param = json_object_safe_new_string(caller_profile->chan_name);
JSON_ENSURE_SUCCESS(param);
json_object_object_add(json, "chan_name", param);
@@ -260,7 +261,7 @@ static void set_json_chan_vars(struct json_object *json, switch_channel_t *chann
}
}
variable = json_object_new_string(data);
variable = json_object_safe_new_string(data);
if (!is_error(variable)) {
json_object_object_add(json, hi->name, variable);
}
@@ -297,10 +298,10 @@ static switch_status_t generate_json_cdr(switch_core_session_t *session, struct
json_object_object_add(cdr, "channel_data", j_channel_data);
j_field = json_object_new_string((char *) switch_channel_state_name(switch_channel_get_state(channel)));
j_field = json_object_safe_new_string((char *) switch_channel_state_name(switch_channel_get_state(channel)));
json_object_object_add(j_channel_data, "state", j_field);
j_field = json_object_new_string(switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND ? "outbound" : "inbound");
j_field = json_object_safe_new_string(switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND ? "outbound" : "inbound");
json_object_object_add(j_channel_data, "direction", j_field);
@@ -311,13 +312,13 @@ static switch_status_t generate_json_cdr(switch_core_session_t *session, struct
if ((f = switch_channel_get_flag_string(channel))) {
j_field = json_object_new_string((char *) f);
j_field = json_object_safe_new_string((char *) f);
json_object_object_add(j_channel_data, "flags", j_field);
free(f);
}
if ((f = switch_channel_get_cap_string(channel))) {
j_field = json_object_new_string((char *) f);
j_field = json_object_safe_new_string((char *) f);
json_object_object_add(j_channel_data, "caps", j_field);
free(f);
}
@@ -351,8 +352,8 @@ static switch_status_t generate_json_cdr(switch_core_session_t *session, struct
goto error;
}
json_object_object_add(j_application, "app_name", json_object_new_string(ap->app));
json_object_object_add(j_application, "app_data", json_object_new_string(ap->arg ? ap->arg : ""));
json_object_object_add(j_application, "app_name", json_object_safe_new_string(ap->app));
json_object_object_add(j_application, "app_data", json_object_safe_new_string(ap->arg));
json_object_object_add(j_apps, "application", j_application);
}
@@ -372,11 +373,11 @@ static switch_status_t generate_json_cdr(switch_core_session_t *session, struct
json_object_object_add(cdr, "callflow", j_callflow);
if (!zstr(caller_profile->dialplan)) {
json_object_object_add(j_callflow, "dialplan", json_object_new_string((char *)caller_profile->dialplan));
json_object_object_add(j_callflow, "dialplan", json_object_safe_new_string((char *)caller_profile->dialplan));
}
if (!zstr(caller_profile->profile_index)) {
json_object_object_add(j_callflow, "profile_index", json_object_new_string((char *)caller_profile->profile_index));
json_object_object_add(j_callflow, "profile_index", json_object_safe_new_string((char *)caller_profile->profile_index));
}
if (caller_profile->caller_extension) {
@@ -390,11 +391,11 @@ static switch_status_t generate_json_cdr(switch_core_session_t *session, struct
json_object_object_add(j_callflow, "extension", j_caller_extension);
json_object_object_add(j_caller_extension, "name", json_object_new_string(caller_profile->caller_extension->extension_name));
json_object_object_add(j_caller_extension, "number", json_object_new_string(caller_profile->caller_extension->extension_number));
json_object_object_add(j_caller_extension, "name", json_object_safe_new_string(caller_profile->caller_extension->extension_name));
json_object_object_add(j_caller_extension, "number", json_object_safe_new_string(caller_profile->caller_extension->extension_number));
if (caller_profile->caller_extension->current_application) {
json_object_object_add(j_caller_extension, "current_app", json_object_new_string(caller_profile->caller_extension->current_application->application_name));
json_object_object_add(j_caller_extension, "current_app", json_object_safe_new_string(caller_profile->caller_extension->current_application->application_name));
}
for (ap = caller_profile->caller_extension->applications; ap; ap = ap->next) {
@@ -410,8 +411,8 @@ static switch_status_t generate_json_cdr(switch_core_session_t *session, struct
if (ap == caller_profile->caller_extension->current_application) {
json_object_object_add(j_application, "last_executed", json_object_new_string("true"));
}
json_object_object_add(j_application, "app_name", json_object_new_string(ap->application_name));
json_object_object_add(j_application, "app_data", json_object_new_string(switch_str_nil(ap->application_data)));
json_object_object_add(j_application, "app_name", json_object_safe_new_string(ap->application_name));
json_object_object_add(j_application, "app_data", json_object_safe_new_string(switch_str_nil(ap->application_data)));
}
if (caller_profile->caller_extension->children) {
@@ -437,13 +438,13 @@ static switch_status_t generate_json_cdr(switch_core_session_t *session, struct
json_object_object_add(j_inner_extension, "extension", j_caller_extension);
json_object_object_add(j_caller_extension, "name", json_object_new_string(cp->caller_extension->extension_name));
json_object_object_add(j_caller_extension, "number", json_object_new_string(cp->caller_extension->extension_number));
json_object_object_add(j_caller_extension, "name", json_object_safe_new_string(cp->caller_extension->extension_name));
json_object_object_add(j_caller_extension, "number", json_object_safe_new_string(cp->caller_extension->extension_number));
json_object_object_add(j_caller_extension, "dialplan", json_object_new_string((char *)cp->dialplan));
json_object_object_add(j_caller_extension, "dialplan", json_object_safe_new_string((char *)cp->dialplan));
if (cp->caller_extension->current_application) {
json_object_object_add(j_caller_extension, "current_app", json_object_new_string(cp->caller_extension->current_application->application_name));
json_object_object_add(j_caller_extension, "current_app", json_object_safe_new_string(cp->caller_extension->current_application->application_name));
}
for (ap = cp->caller_extension->applications; ap; ap = ap->next) {
@@ -457,8 +458,8 @@ static switch_status_t generate_json_cdr(switch_core_session_t *session, struct
if (ap == cp->caller_extension->current_application) {
json_object_object_add(j_application, "last_executed", json_object_new_string("true"));
}
json_object_object_add(j_application, "app_name", json_object_new_string(ap->application_name));
json_object_object_add(j_application, "app_data", json_object_new_string(switch_str_nil(ap->application_data)));
json_object_object_add(j_application, "app_name", json_object_safe_new_string(ap->application_name));
json_object_object_add(j_application, "app_data", json_object_safe_new_string(switch_str_nil(ap->application_data)));
}
}
}
@@ -0,0 +1,6 @@
all:
gcc ../mod_posix_timer.c main.c switch.c -I. -o timer_test -lpthread -lrt -g -DLOG_LEVEL=-1
clean:
-rm timer_test
@@ -0,0 +1,2 @@
Stress test for mod_posix_timer. Runs without FreeSWITCH.
@@ -0,0 +1,44 @@
#include <switch.h>
#include <stdlib.h>
extern SWITCH_MODULE_LOAD_FUNCTION(mod_posix_timer_load);
extern SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_posix_timer_shutdown);
switch_loadable_module_interface_t *mod = NULL;
switch_memory_pool_t pool = { 0 };
int main (int argc, char **argv)
{
int i;
switch_timer_interface_t *timer_if;
switch_timer_t *timer[1000];
mod_posix_timer_load(&mod, &pool);
timer_if = mod->timer;
// TODO create multi-threaded test
// create 10 ms timers
for (i = 0; i < 1000; i++) {
timer[i] = malloc(sizeof(switch_timer_t));
memset(timer[i], 0, sizeof(switch_timer_t));
timer[i]->interval = 1;
timer[i]->samples = 8;
timer_if->timer_init(timer[i]);
}
for (i = 0; i < 50000; i++) {
timer_if->timer_next(timer[0]);
}
// destroy timers
for (i = 0; i < 1000; i++) {
timer_if->timer_destroy(timer[i]);
free(timer[i]);
}
mod_posix_timer_shutdown();
return 0;
}
@@ -0,0 +1,69 @@
#include <switch.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
switch_loadable_module_interface_t * switch_loadable_module_create_module_interface(switch_memory_pool_t *pool, const char *name)
{
return malloc(sizeof(switch_loadable_module_interface_t));
}
void * switch_loadable_module_create_interface(switch_loadable_module_interface_t *mod, int iname)
{
mod->timer = malloc(sizeof(switch_timer_interface_t));
return mod->timer;
}
switch_status_t switch_mutex_lock(switch_mutex_t *mutex)
{
return pthread_mutex_lock(mutex);
}
switch_status_t switch_mutex_unlock(switch_mutex_t *mutex)
{
return pthread_mutex_unlock(mutex);
}
switch_status_t switch_mutex_init(switch_mutex_t **mutex, int flags, switch_memory_pool_t *pool)
{
pthread_mutexattr_t atts = { 0 };
pthread_mutexattr_init(&atts);
if (flags == SWITCH_MUTEX_NESTED) {
pthread_mutexattr_settype(&atts, PTHREAD_MUTEX_RECURSIVE_NP);
}
*mutex = malloc(sizeof(switch_mutex_t));
return pthread_mutex_init(*mutex, &atts);
}
switch_status_t switch_thread_cond_create(switch_thread_cond_t **cond, switch_memory_pool_t *pool)
{
*cond = malloc(sizeof(switch_thread_cond_t));
return pthread_cond_init(*cond, NULL);
}
switch_status_t switch_thread_cond_timedwait(switch_thread_cond_t *cond, switch_mutex_t *mutex, int wait)
{
struct timespec dur = { 0, 0 };
clock_gettime(CLOCK_REALTIME, &dur);
dur.tv_sec = wait / 1000000000;
dur.tv_nsec = wait % 1000000000;
return pthread_cond_timedwait(cond, mutex, &dur);
}
switch_status_t switch_thread_cond_broadcast(switch_thread_cond_t *cond)
{
return pthread_cond_broadcast(cond);
}
void switch_log_printf(int dummy, int level, char *format, ...)
{
va_list vl;
va_start(vl, format);
if (level > LOG_LEVEL) {
vprintf(format, vl);
}
va_end(vl);
}
@@ -0,0 +1,122 @@
#ifndef SWITCH_H
#define SWITCH_H
#include <pthread.h>
#include <time.h>
#include <signal.h>
#include <string.h>
#define SWITCH_STATUS_SUCCESS 0
#define SWITCH_STATUS_GENERR 1
#define SWITCH_STATUS_FALSE 2
#define SWITCH_MUTEX_NESTED 1
#define SWITCH_CHANNEL_LOG 0
#define SWITCH_LOG_INFO 0
typedef int switch_status_t;
typedef size_t switch_size_t;
typedef pthread_mutex_t switch_mutex_t;
typedef pthread_cond_t switch_thread_cond_t;
typedef int switch_memory_pool_t;
typedef int switch_bool_t;
#define SWITCH_TIMER_INTERFACE 0
typedef struct switch_loadable_module_interface switch_loadable_module_interface_t;
typedef struct switch_timer_interface switch_timer_interface_t;
typedef int switch_module_flag_t;
#define SWITCH_API_VERSION 0
#define SWITCH_MOD_DECLARE_DATA
#define SMODF_NONE 0
#define SWITCH_MODULE_LOAD_ARGS (switch_loadable_module_interface_t **module_interface, switch_memory_pool_t *pool)
#define SWITCH_MODULE_RUNTIME_ARGS (void)
#define SWITCH_MODULE_SHUTDOWN_ARGS (void)
typedef switch_status_t (*switch_module_load_t) SWITCH_MODULE_LOAD_ARGS;
typedef switch_status_t (*switch_module_runtime_t) SWITCH_MODULE_RUNTIME_ARGS;
typedef switch_status_t (*switch_module_shutdown_t) SWITCH_MODULE_SHUTDOWN_ARGS;
#define SWITCH_MODULE_LOAD_FUNCTION(name) switch_status_t name SWITCH_MODULE_LOAD_ARGS
#define SWITCH_MODULE_RUNTIME_FUNCTION(name) switch_status_t name SWITCH_MODULE_RUNTIME_ARGS
#define SWITCH_MODULE_SHUTDOWN_FUNCTION(name) switch_status_t name SWITCH_MODULE_SHUTDOWN_ARGS
typedef struct switch_loadable_module_function_table {
int switch_api_version;
switch_module_load_t load;
switch_module_shutdown_t shutdown;
switch_module_runtime_t runtime;
switch_module_flag_t flags;
} switch_loadable_module_function_table_t;
#define SWITCH_MODULE_DEFINITION_EX(name, load, shutdown, runtime, flags) \
static const char modname[] = #name ; \
SWITCH_MOD_DECLARE_DATA switch_loadable_module_function_table_t name##_module_interface = { \
SWITCH_API_VERSION, \
load, \
shutdown, \
runtime, \
flags \
}
#define SWITCH_MODULE_DEFINITION(name, load, shutdown, runtime) \
SWITCH_MODULE_DEFINITION_EX(name, load, shutdown, runtime, SMODF_NONE)
switch_loadable_module_interface_t * switch_loadable_module_create_module_interface(switch_memory_pool_t *pool, const char *name);
typedef struct {
int id;
int interval;
int tick;
int samplecount;
int samples;
int diff;
void *private_info;
} switch_timer_t;
/*! \brief A table of functions that a timer module implements */
struct switch_timer_interface {
/*! the name of the interface */
const char *interface_name;
/*! function to allocate the timer */
switch_status_t (*timer_init) (switch_timer_t *);
/*! function to wait for one cycle to pass */
switch_status_t (*timer_next) (switch_timer_t *);
/*! function to step the timer one step */
switch_status_t (*timer_step) (switch_timer_t *);
/*! function to reset the timer */
switch_status_t (*timer_sync) (switch_timer_t *);
/*! function to check if the current step has expired */
switch_status_t (*timer_check) (switch_timer_t *, switch_bool_t);
/*! function to deallocate the timer */
switch_status_t (*timer_destroy) (switch_timer_t *);
int refs;
switch_mutex_t *reflock;
switch_loadable_module_interface_t *parent;
struct switch_timer_interface *next;
};
struct switch_loadable_module_interface {
switch_timer_interface_t *timer;
};
void * switch_loadable_module_create_interface(switch_loadable_module_interface_t *mod, int iname);
switch_status_t switch_mutex_lock(switch_mutex_t *mutex);
switch_status_t switch_mutex_unlock(switch_mutex_t *mutex);
switch_status_t switch_mutex_init(switch_mutex_t **mutex, int flags, switch_memory_pool_t *pool);
switch_status_t switch_thread_cond_create(switch_thread_cond_t **cond, switch_memory_pool_t *pool);
switch_status_t switch_thread_cond_timedwait(switch_thread_cond_t *cond, switch_mutex_t *mutex, int wait);
switch_status_t switch_thread_cond_broadcast(switch_thread_cond_t *cond);
void switch_log_printf(int dummy, int level, char *format, ...);
#endif
+5 -4
View File
@@ -1380,7 +1380,7 @@ SWITCH_DECLARE(void) switch_channel_wait_for_state(switch_channel_t *channel, sw
for (;;) {
if ((channel->state < CS_HANGUP && channel->state == channel->running_state && channel->running_state == want_state) ||
(other_channel && switch_channel_down_nosig(other_channel)) || switch_channel_down_nosig(channel)) {
(other_channel && switch_channel_down_nosig(other_channel)) || switch_channel_down(channel)) {
break;
}
switch_yield(20000);
@@ -1399,6 +1399,8 @@ SWITCH_DECLARE(void) switch_channel_wait_for_state_timeout(switch_channel_t *cha
break;
}
switch_channel_check_signal(channel, SWITCH_TRUE);
switch_cond_next();
if (++count >= timeout) {
@@ -1866,12 +1868,11 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_set_running_state(
switch_channel_clear_flag(channel, CF_TAGGED);
switch_mutex_lock(channel->state_mutex);
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, switch_channel_get_uuid(channel), SWITCH_LOG_DEBUG, "(%s) Running State Change %s\n",
channel->name, state_names[state]);
switch_mutex_lock(channel->state_mutex);
channel->running_state = state;
if (state == CS_ROUTING || state == CS_HANGUP) {
+13 -1
View File
@@ -1875,6 +1875,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_init_and_modload(switch_core_flag_t
runtime.runlevel++;
switch_core_set_signal_handlers();
switch_load_network_lists(SWITCH_FALSE);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Bringing up environment.\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Loading Modules.\n");
@@ -1884,7 +1885,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_init_and_modload(switch_core_flag_t
return SWITCH_STATUS_GENERR;
}
switch_load_network_lists(SWITCH_FALSE);
switch_load_core_config("post_load_switch.conf");
@@ -2014,6 +2015,17 @@ SWITCH_DECLARE(int32_t) switch_core_session_ctl(switch_session_ctl_t cmd, void *
}
switch (cmd) {
case SCSC_DEBUG_SQL:
{
if (switch_test_flag((&runtime), SCF_DEBUG_SQL)) {
switch_clear_flag((&runtime), SCF_DEBUG_SQL);
newintval = 0;
} else {
switch_set_flag((&runtime), SCF_DEBUG_SQL);
newintval = 1;
}
}
break;
case SCSC_VERBOSE_EVENTS:
if (intval) {
if (oldintval > -1) {
+7 -7
View File
@@ -41,7 +41,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_video_frame(switch_cor
switch_io_event_hook_video_write_frame_t *ptr;
switch_status_t status = SWITCH_STATUS_FALSE;
if (switch_channel_down_nosig(session->channel)) {
if (switch_channel_down(session->channel)) {
return SWITCH_STATUS_FALSE;
}
@@ -65,7 +65,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_video_frame(switch_core
switch_assert(session != NULL);
if (switch_channel_down_nosig(session->channel)) {
if (switch_channel_down(session->channel)) {
return SWITCH_STATUS_FALSE;
}
@@ -153,7 +153,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
}
}
if (switch_channel_down_nosig(session->channel) || !switch_core_codec_ready(session->read_codec)) {
if (switch_channel_down(session->channel) || !switch_core_codec_ready(session->read_codec)) {
*frame = NULL;
status = SWITCH_STATUS_FALSE;
goto even_more_done;
@@ -1114,7 +1114,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
while (switch_buffer_inuse(session->raw_write_buffer) >= session->write_impl.decoded_bytes_per_packet) {
int rate;
if (switch_channel_down_nosig(session->channel) || !session->raw_write_buffer) {
if (switch_channel_down(session->channel) || !session->raw_write_buffer) {
goto error;
}
if ((session->raw_write_frame.datalen = (uint32_t)
@@ -1296,7 +1296,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_recv_dtmf(switch_core_sessio
switch_dtmf_t new_dtmf;
int fed = 0;
if (switch_channel_down_nosig(session->channel)) {
if (switch_channel_down(session->channel)) {
return SWITCH_STATUS_FALSE;
}
@@ -1339,7 +1339,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf(switch_core_sessio
switch_status_t status = SWITCH_STATUS_FALSE;
switch_dtmf_t new_dtmf;
if (switch_channel_down_nosig(session->channel)) {
if (switch_channel_down(session->channel)) {
return SWITCH_STATUS_FALSE;
}
@@ -1418,7 +1418,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf_string(switch_core
dtmf.flags = 0;
}
if (switch_channel_down_nosig(session->channel)) {
if (switch_channel_down(session->channel)) {
return SWITCH_STATUS_FALSE;
}
+30 -28
View File
@@ -34,7 +34,7 @@
#include <switch.h>
#include "private/switch_core_pvt.h"
//#define DEBUG_SQL 1
#define SWITCH_SQL_QUEUE_LEN 100000
#define SWITCH_SQL_QUEUE_PAUSE_LEN 90000
@@ -1019,11 +1019,11 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread,
if (new_mlen < runtime.max_sql_buffer_len) {
sql_len = new_mlen;
#ifdef DEBUG_SQL
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
"REALLOC %ld %d %d\n", (long int)sql_len, switch_queue_size(sql_manager.sql_queue[0]),
switch_queue_size(sql_manager.sql_queue[1]));
#endif
if (switch_test_flag((&runtime), SCF_DEBUG_SQL)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
"REALLOC %ld %d %d\n", (long int)sql_len, switch_queue_size(sql_manager.sql_queue[0]),
switch_queue_size(sql_manager.sql_queue[1]));
}
if (!(tmp = realloc(sqlbuf, sql_len))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "SQL thread ending on mem err\n");
abort();
@@ -1031,10 +1031,10 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread,
}
sqlbuf = tmp;
} else {
#ifdef DEBUG_SQL
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
"SAVE %d %d\n", switch_queue_size(sql_manager.sql_queue[0]), switch_queue_size(sql_manager.sql_queue[1]));
#endif
if (switch_test_flag((&runtime), SCF_DEBUG_SQL)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
"SAVE %d %d\n", switch_queue_size(sql_manager.sql_queue[0]), switch_queue_size(sql_manager.sql_queue[1]));
}
save_sql = sql;
sql = NULL;
lc = 0;
@@ -1077,16 +1077,16 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread,
wrote = 0;
if (trans && iterations && (iterations > target || !lc)) {
#ifdef DEBUG_SQL
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
"RUN %d %d %d\n", switch_queue_size(sql_manager.sql_queue[0]), switch_queue_size(sql_manager.sql_queue[1]), iterations);
#endif
if (switch_test_flag((&runtime), SCF_DEBUG_SQL)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
"RUN %d %d %d\n", switch_queue_size(sql_manager.sql_queue[0]), switch_queue_size(sql_manager.sql_queue[1]), iterations);
}
if (switch_cache_db_persistant_execute_trans(sql_manager.event_db, sqlbuf, 1) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "SQL thread unable to commit transaction, records lost!\n");
}
#ifdef DEBUG_SQL
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "DONE\n");
#endif
if (switch_test_flag((&runtime), SCF_DEBUG_SQL)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "DONE\n");
}
iterations = 0;
@@ -1628,10 +1628,7 @@ static char create_channels_sql[] =
" call_uuid VARCHAR(256),\n"
" sent_callee_name VARCHAR(1024),\n"
" sent_callee_num VARCHAR(256)\n"
");\n"
"create index chidx1 on channels (hostname);\n"
"create index uuindex on channels (uuid);\n"
"create index uuindex2 on channels (call_uuid);\n";
");\n";
static char create_calls_sql[] =
"CREATE TABLE calls (\n"
@@ -1641,11 +1638,7 @@ static char create_calls_sql[] =
" caller_uuid VARCHAR(256),\n"
" callee_uuid VARCHAR(256),\n"
" hostname VARCHAR(256)\n"
");\n"
"create index callsidx1 on calls (hostname);\n"
"create index eruuindex on calls (caller_uuid);\n"
"create index eeuuindex on calls (callee_uuid);\n"
"create index eeuuindex2 on calls (call_uuid);\n";
");\n";
static char create_interfaces_sql[] =
"CREATE TABLE interfaces (\n"
@@ -1688,8 +1681,8 @@ static char create_registrations_sql[] =
" network_port VARCHAR(256),\n"
" network_proto VARCHAR(256),\n"
" hostname VARCHAR(256)\n"
");\n"
"create index regindex1 on registrations (reg_user,realm,hostname);\n";
");\n";
@@ -2051,6 +2044,15 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_
switch_cache_db_execute_sql(dbh, "create index nat_map_port_proto on nat (port,proto,hostname)", NULL);
switch_cache_db_execute_sql(dbh, "create index channels1 on channels(hostname)", NULL);
switch_cache_db_execute_sql(dbh, "create index calls1 on calls(hostname)", NULL);
switch_cache_db_execute_sql(dbh, "create index chidx1 on channels (hostname)", NULL);
switch_cache_db_execute_sql(dbh, "create index uuindex on channels (uuid)", NULL);
switch_cache_db_execute_sql(dbh, "create index uuindex2 on channels (call_uuid)", NULL);
switch_cache_db_execute_sql(dbh, "create index callsidx1 on calls (hostname)", NULL);
switch_cache_db_execute_sql(dbh, "create index eruuindex on calls (caller_uuid)", NULL);
switch_cache_db_execute_sql(dbh, "create index eeuuindex on calls (callee_uuid)", NULL);
switch_cache_db_execute_sql(dbh, "create index eeuuindex2 on calls (call_uuid)", NULL);
switch_cache_db_execute_sql(dbh, "create index regindex1 on registrations (reg_user,realm,hostname)", NULL);
skip:
+1 -1
View File
@@ -1556,7 +1556,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_nomedia(const char *uuid, switch_medi
}
switch_core_session_receive_message(other_session, &msg);
switch_channel_wait_for_flag(other_channel, CF_REQ_MEDIA, SWITCH_FALSE, 10000, NULL);
switch_channel_wait_for_flag(other_channel, CF_MEDIA_ACK, SWITCH_TRUE, 10000, NULL);
//switch_channel_wait_for_flag(other_channel, CF_MEDIA_ACK, SWITCH_TRUE, 10000, NULL);
switch_channel_wait_for_flag(other_channel, CF_MEDIA_SET, SWITCH_TRUE, 10000, NULL);
}
+1 -1
View File
@@ -776,7 +776,7 @@ static switch_status_t uuid_bridge_on_soft_execute(switch_core_session_t *sessio
state = switch_channel_get_state(other_channel);
running_state = switch_channel_get_running_state(other_channel);
if (switch_channel_down_nosig(other_channel) || switch_channel_down_nosig(channel)) {
if (switch_channel_down_nosig(other_channel) || switch_channel_down(channel)) {
break;
}
+10 -5
View File
@@ -2181,6 +2181,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_speak_text_handle(switch_core_session
}
}
switch_channel_audio_sync(channel);
ilen = len;
for (;;) {
switch_event_t *event;
@@ -2346,7 +2348,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_speak_text_handle(switch_core_session
}
}
}
}
done:
@@ -2377,8 +2378,12 @@ SWITCH_DECLARE(void) switch_ivr_clear_speech_cache(switch_core_session_t *sessio
if (cache_obj->timer.interval) {
switch_core_timer_destroy(&cache_obj->timer);
}
switch_core_speech_close(&cache_obj->sh, &flags);
switch_core_codec_destroy(&cache_obj->codec);
if (&cache_obj->sh && cache_obj->sh.speech_interface) {
switch_core_speech_close(&cache_obj->sh, &flags);
}
if (&cache_obj->codec) {
switch_core_codec_destroy(&cache_obj->codec);
}
switch_channel_set_private(channel, SWITCH_CACHE_SPEECH_HANDLES_OBJ_NAME, NULL);
}
}
@@ -2412,7 +2417,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_speak_text(switch_core_session_t *ses
timer = &ltimer;
if ((var = switch_channel_get_variable(channel, SWITCH_CACHE_SPEECH_HANDLES_VARIABLE)) && switch_true(var)) {
if ((cache_obj = switch_channel_get_private(channel, SWITCH_CACHE_SPEECH_HANDLES_OBJ_NAME))) {
if ((cache_obj = (cached_speech_handle_t *) switch_channel_get_private(channel, SWITCH_CACHE_SPEECH_HANDLES_OBJ_NAME))) {
need_create = 0;
if (!strcasecmp(cache_obj->tts_name, tts_name)) {
need_alloc = 0;
@@ -2422,7 +2427,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_speak_text(switch_core_session_t *ses
}
if (!cache_obj) {
cache_obj = switch_core_session_alloc(session, sizeof(*cache_obj));
cache_obj = (cached_speech_handle_t *) switch_core_session_alloc(session, sizeof(*cache_obj));
}
if (need_alloc) {
switch_copy_string(cache_obj->tts_name, tts_name, sizeof(cache_obj->tts_name));
+1 -1
View File
@@ -71,7 +71,7 @@ static switch_mutex_t *port_lock = NULL;
typedef srtp_hdr_t rtp_hdr_t;
#ifdef ENABLE_ZRTP
#include <libzrtp/zrtp.h>
#include "zrtp.h"
static zrtp_global_t *zrtp_global;
static zrtp_zid_t zid = { "FreeSWITCH01" };
static int zrtp_on = 0;
+11 -1
View File
@@ -2451,12 +2451,22 @@ static char *switch_xml_toxml_r(switch_xml_t xml, char **s, switch_size_t *len,
}
}
SWITCH_DECLARE(char *) switch_xml_toxml_nolock(switch_xml_t xml, switch_bool_t prn_header)
{
char *s = (char *) malloc(SWITCH_XML_BUFSIZE);
switch_assert(s);
return switch_xml_toxml_buf(xml, s, SWITCH_XML_BUFSIZE, 0, prn_header);
}
SWITCH_DECLARE(char *) switch_xml_toxml(switch_xml_t xml, switch_bool_t prn_header)
{
char *r, *s;
switch_mutex_lock(XML_GEN_LOCK);
s = (char *) malloc(SWITCH_XML_BUFSIZE);
switch_assert(s);
switch_mutex_lock(XML_GEN_LOCK);
r = switch_xml_toxml_buf(xml, s, SWITCH_XML_BUFSIZE, 0, prn_header);
switch_mutex_unlock(XML_GEN_LOCK);
return r;