mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-07-24 21:22:09 +00:00
Merge branch 'master' into gsmopen01
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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")) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user