indent pass 2

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8689 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale committed 2008-05-27 04:54:52 +00:00
1 parent 9bbcabbbdd
commit f930eaeec7
101 files changed
+31644 -31458

No files matched your search

@@ -43,7 +43,7 @@ SWITCH_MODULE_DEFINITION(mod_commands, mod_commands_load, NULL, NULL);
SWITCH_STANDARD_API(user_data_function)
{
switch_xml_t x_domain, xml = NULL, x_user = NULL, x_param, x_params;
switch_xml_t x_domain, xml = NULL, x_user = NULL, x_param, x_params;
int argc;
char *mydata = NULL, *argv[3], *key = NULL, *type = NULL, *user, *domain;
char delim = ' ';
@@ -94,7 +94,7 @@ SWITCH_STANDARD_API(user_data_function)
}
}
end:
end:
switch_xml_free(xml);
free(mydata);
switch_event_destroy(&params);
@@ -115,7 +115,7 @@ static switch_status_t _find_user(const char *cmd, switch_core_session_t *sessio
const char *err = NULL;
if (stream->param_event && (host = switch_event_get_header(stream->param_event, "http-host"))) {
stream->write_function(stream, "Content-Type: text/xml\r\n\r\n");
stream->write_function(stream, "Content-Type: text/xml\r\n\r\n");
if ((path_info = switch_event_get_header(stream->param_event, "http-path-info"))) {
cmd = path_info;
delim = '/';
@@ -151,16 +151,16 @@ static switch_status_t _find_user(const char *cmd, switch_core_session_t *sessio
goto end;
}
end:
end:
if (session || tf) {
stream->write_function(stream, err ? "false" : "true");
switch_xml_free(xml);
} else {
if (err) {
if (host) {
stream->write_function(stream, "<error>%s</error>\n", err);
stream->write_function(stream, "<error>%s</error>\n", err);
} else {
stream->write_function(stream, "-Error %s\n", err);
stream->write_function(stream, "-Error %s\n", err);
}
}
@@ -168,7 +168,7 @@ end:
xmlstr = switch_xml_toxml(x_user, SWITCH_FALSE);
switch_assert(xmlstr);
stream->write_function(stream, "%s", xmlstr);
stream->write_function(stream, "%s", xmlstr);
free(xmlstr);
switch_xml_free(xml);
}
@@ -201,7 +201,7 @@ SWITCH_STANDARD_API(xml_locate_function)
const char *err = NULL;
if (stream->param_event && (host = switch_event_get_header(stream->param_event, "http-host"))) {
stream->write_function(stream, "Content-Type: text/xml\r\n\r\n");
stream->write_function(stream, "Content-Type: text/xml\r\n\r\n");
if ((path_info = switch_event_get_header(stream->param_event, "http-path-info"))) {
cmd = path_info;
delim = '/';
@@ -243,16 +243,16 @@ SWITCH_STANDARD_API(xml_locate_function)
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "tag_attr_val", tag_attr_val);
if (switch_xml_locate(section, tag, tag_attr_name, tag_attr_val, &xml, &obj, params) != SWITCH_STATUS_SUCCESS) {
stream->write_function(stream, "can't find anything\n");
stream->write_function(stream, "can't find anything\n");
goto end;
}
end:
end:
if (err) {
if (host) {
stream->write_function(stream, "<error>%s</error>\n", err);
stream->write_function(stream, "<error>%s</error>\n", err);
} else {
stream->write_function(stream, "-Error %s\n", err);
stream->write_function(stream, "-Error %s\n", err);
}
}
@@ -260,7 +260,7 @@ end:
xmlstr = switch_xml_toxml(obj, SWITCH_FALSE);
switch_assert(xmlstr);
stream->write_function(stream, "%s", xmlstr);
stream->write_function(stream, "%s", xmlstr);
free(xmlstr);
switch_xml_free(xml);
@@ -274,11 +274,11 @@ end:
SWITCH_STANDARD_API(reload_acl_function)
{
const char *err;
switch_xml_t xml_root;
switch_xml_t xml_root;
if (session) {
return SWITCH_STATUS_FALSE;
}
if (session) {
return SWITCH_STATUS_FALSE;
}
if (cmd && !strcmp(cmd, "reloadxml")) {
if ((xml_root = switch_xml_open_root(1, &err))) {
@@ -311,15 +311,15 @@ SWITCH_STANDARD_API(acl_function)
}
if (switch_check_network_list_ip(argv[0], argv[1])) {
stream->write_function(stream, "true");
stream->write_function(stream, "true");
goto ok;
}
error:
error:
stream->write_function(stream, "false");
stream->write_function(stream, "false");
ok:
ok:
switch_safe_free(mydata);
@@ -357,10 +357,10 @@ SWITCH_STANDARD_API(regex_function)
substituted = malloc(len);
switch_assert(substituted);
memset(substituted, 0, len);
switch_replace_char(argv[2], '%','$', SWITCH_FALSE);
switch_replace_char(argv[2], '%', '$', SWITCH_FALSE);
switch_perform_substitution(re, proceed, argv[2], argv[0], substituted, len, ovector);
stream->write_function(stream, "%s", substituted);
stream->write_function(stream, "%s", substituted);
free(substituted);
} else {
stream->write_function(stream, "true");
@@ -370,9 +370,9 @@ SWITCH_STANDARD_API(regex_function)
}
goto ok;
error:
stream->write_function(stream, "-ERR");
ok:
error:
stream->write_function(stream, "-ERR");
ok:
switch_regex_safe_free(re);
switch_safe_free(mydata);
return SWITCH_STATUS_SUCCESS;
@@ -426,14 +426,14 @@ SWITCH_STANDARD_API(cond_function)
o = O_NE;
}
} else if ((expr = strchr(a, '>'))) {
if (*(expr+1) == '=') {
if (*(expr + 1) == '=') {
*expr++ = '\0';
o = O_GE;
} else {
o = O_GT;
}
} else if ((expr = strchr(a, '<'))) {
if (*(expr+1) == '=') {
if (*(expr + 1) == '=') {
*expr++ = '\0';
o = O_LE;
} else {
@@ -493,11 +493,11 @@ SWITCH_STANDARD_API(cond_function)
switch_safe_free(s_b);
stream->write_function(stream, "%s", is_true ? argv[1] : argv[2]);
goto ok;
}
}
error:
stream->write_function(stream, "-ERR");
ok:
error:
stream->write_function(stream, "-ERR");
ok:
switch_safe_free(mydata);
return SWITCH_STATUS_SUCCESS;
@@ -512,7 +512,7 @@ SWITCH_STANDARD_API(lan_addr_function)
SWITCH_STANDARD_API(status_function)
{
uint8_t html = 0;
switch_core_time_duration_t duration = {0};
switch_core_time_duration_t duration = { 0 };
char *http = NULL;
int sps = 0, last_sps = 0;
@@ -532,13 +532,13 @@ SWITCH_STANDARD_API(status_function)
}
stream->write_function(stream,
"UP %u year%s, %u day%s, %u hour%s, %u minute%s, %u second%s, %u millisecond%s, %u microsecond%s\n",
duration.yr, duration.yr == 1 ? "" : "s", duration.day, duration.day == 1 ? "" : "s",
duration.hr, duration.hr == 1 ? "" : "s", duration.min, duration.min == 1 ? "" : "s",
duration.sec, duration.sec == 1 ? "" : "s", duration.ms, duration.ms == 1 ? "" : "s", duration.mms,
duration.mms == 1 ? "" : "s");
"UP %u year%s, %u day%s, %u hour%s, %u minute%s, %u second%s, %u millisecond%s, %u microsecond%s\n",
duration.yr, duration.yr == 1 ? "" : "s", duration.day, duration.day == 1 ? "" : "s",
duration.hr, duration.hr == 1 ? "" : "s", duration.min, duration.min == 1 ? "" : "s",
duration.sec, duration.sec == 1 ? "" : "s", duration.ms, duration.ms == 1 ? "" : "s", duration.mms,
duration.mms == 1 ? "" : "s");
stream->write_function(stream, "%"SWITCH_SIZE_T_FMT" session(s) since startup\n", switch_core_session_id() - 1 );
stream->write_function(stream, "%" SWITCH_SIZE_T_FMT " session(s) since startup\n", switch_core_session_id() - 1);
switch_core_session_ctl(SCSC_LAST_SPS, &last_sps);
switch_core_session_ctl(SCSC_SPS, &sps);
stream->write_function(stream, "%d session(s) %d/%d\n", switch_core_session_count(), last_sps, sps);
@@ -644,10 +644,10 @@ SWITCH_STANDARD_API(ctl_function)
} else {
stream->write_function(stream, "-ERR INVALID COMMAND\nUSAGE: fsctl %s", CTL_SYNTAX);
goto end;
}
}
stream->write_function(stream, "+OK\n");
end:
end:
free(mydata);
} else {
stream->write_function(stream, "-ERR Memory error\n");
@@ -831,7 +831,7 @@ SWITCH_STANDARD_API(transfer_function)
switch_core_session_rwunlock(tsession);
done:
done:
switch_safe_free(mycmd);
return SWITCH_STATUS_SUCCESS;
}
@@ -866,7 +866,7 @@ SWITCH_STANDARD_API(tone_detect_session_function)
if (argv[4]) {
uint32_t mto;
if (*argv[4] == '+') {
if ((mto = atoi(argv[4]+1)) > 0) {
if ((mto = atoi(argv[4] + 1)) > 0) {
to = switch_timestamp(NULL) + mto;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "INVALID Timeout!\n");
@@ -884,7 +884,7 @@ SWITCH_STANDARD_API(tone_detect_session_function)
switch_ivr_tone_detect_session(rsession, argv[1], argv[2], argv[3], to, argv[5], argv[6]);
stream->write_function(stream, "+OK Enabling tone detection '%s' '%s' '%s'\n", argv[1], argv[2], argv[3]);
done:
done:
free(mydata);
switch_core_session_rwunlock(rsession);
@@ -1246,13 +1246,13 @@ SWITCH_STANDARD_API(uuid_bridge_function)
} else {
switch_status_t status;
char *who = NULL;
if ((status = switch_ivr_uuid_bridge(argv[0], argv[1])) != SWITCH_STATUS_SUCCESS) {
if (argv[2]) {
if ((status = switch_ivr_uuid_bridge(argv[0], argv[2])) == SWITCH_STATUS_SUCCESS) {
who = argv[2];
}
}
}
} else {
who = argv[1];
}
@@ -1317,11 +1317,11 @@ SWITCH_STANDARD_API(session_record_function)
goto done;
usage:
usage:
stream->write_function(stream, "-USAGE: %s\n", SESS_REC_SYNTAX);
switch_safe_free(mycmd);
done:
done:
if (rsession) {
switch_core_session_rwunlock(rsession);
}
@@ -1377,11 +1377,11 @@ SWITCH_STANDARD_API(session_displace_function)
goto done;
usage:
usage:
stream->write_function(stream, "-USAGE: %s\n", DISPLACE_SYNTAX);
switch_safe_free(mycmd);
done:
done:
if (rsession) {
switch_core_session_rwunlock(rsession);
}
@@ -1513,7 +1513,8 @@ SWITCH_STANDARD_API(originate_function)
timeout = atoi(argv[6]);
}
if (switch_ivr_originate(NULL, &caller_session, &cause, aleg, timeout, NULL, cid_name, cid_num, NULL, SOF_NONE) != SWITCH_STATUS_SUCCESS || !caller_session) {
if (switch_ivr_originate(NULL, &caller_session, &cause, aleg, timeout, NULL, cid_name, cid_num, NULL, SOF_NONE) != SWITCH_STATUS_SUCCESS
|| !caller_session) {
if (machine) {
stream->write_function(stream, "-ERR %s\n", switch_channel_cause2str(cause));
} else {
@@ -1557,7 +1558,7 @@ SWITCH_STANDARD_API(originate_function)
switch_core_session_rwunlock(caller_session);
done:
done:
switch_safe_free(mycmd);
return status;
}
@@ -1594,7 +1595,7 @@ SWITCH_STANDARD_API(sched_del_function)
int64_t tmp;
tmp = (uint32_t) atoi(cmd);
if (tmp > 0) {
cnt = switch_scheduler_del_task_id((uint32_t)tmp);
cnt = switch_scheduler_del_task_id((uint32_t) tmp);
}
} else {
cnt = switch_scheduler_del_task_group(cmd);
@@ -1643,14 +1644,7 @@ SWITCH_STANDARD_API(xml_wrap_api_function)
}
}
stream->write_function(stream,
"<result>\n"
" <row id=\"1\">\n"
" <data>%s</data>\n"
" </row>\n"
"</result>\n",
send ? send : "ERROR"
);
stream->write_function(stream, "<result>\n" " <row id=\"1\">\n" " <data>%s</data>\n" " </row>\n" "</result>\n", send ? send : "ERROR");
switch_safe_free(mystream.data);
switch_safe_free(edata);
free(dcommand);
@@ -1688,12 +1682,12 @@ SWITCH_STANDARD_API(sched_api_function)
id = switch_scheduler_add_task(when, sch_api_callback, (char *) __SWITCH_FUNC__, group, 0, strdup(dcmd), SSHF_FREE_ARG);
stream->write_function(stream, "+OK Added: %u\n", id);
goto good;
}
}
}
stream->write_function(stream, "-ERR Invalid syntax\n");
good:
good:
switch_safe_free(tm);
return SWITCH_STATUS_SUCCESS;
}
@@ -1701,7 +1695,7 @@ good:
struct bg_job {
char *cmd;
char *arg;
char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
switch_memory_pool_t *pool;
};
@@ -1715,7 +1709,8 @@ static void *SWITCH_THREAD_FUNC bgapi_exec(switch_thread_t *thread, void *obj)
char *arg;
switch_memory_pool_t *pool;
if (!job) return NULL;
if (!job)
return NULL;
pool = job->pool;
@@ -1817,7 +1812,7 @@ static int show_as_xml_callback(void *pArg, int argc, char **argv, char **column
switch_xml_set_attr(switch_xml_set_flag(row, SWITCH_XML_DUP), strdup("row_id"), strdup(id));
for(x = 0; x < argc; x++) {
for (x = 0; x < argc; x++) {
char *name = columnNames[x];
char *val = switch_str_nil(argv[x]);
@@ -1896,7 +1891,7 @@ SWITCH_STANDARD_API(complete_function)
} else {
stream->write_function(stream, "-USAGE: %s\n", COMPLETE_SYNTAX);
}
return SWITCH_STATUS_SUCCESS;
}
@@ -1912,7 +1907,7 @@ SWITCH_STANDARD_API(alias_function)
} else {
stream->write_function(stream, "-USAGE: %s\n", ALIAS_SYNTAX);
}
return SWITCH_STATUS_SUCCESS;
}
@@ -1924,7 +1919,7 @@ SWITCH_STANDARD_API(show_function)
switch_core_db_t *db;
struct holder holder = { 0 };
int help = 0;
char *mydata = NULL, *argv[6] = {0};
char *mydata = NULL, *argv[6] = { 0 };
int argc;
char *command = NULL, *as = NULL;
switch_core_flag_t cflags = switch_core_flags();
@@ -1980,7 +1975,8 @@ SWITCH_STANDARD_API(show_function)
holder.print_title = 0;
if ((cmdname = strchr(command, ' ')) != 0) {
*cmdname++ = '\0';
switch_snprintf(sql, sizeof(sql) - 1, "select name, syntax, description from interfaces where type = 'api' and name = '%s' order by name", cmdname);
switch_snprintf(sql, sizeof(sql) - 1, "select name, syntax, description from interfaces where type = 'api' and name = '%s' order by name",
cmdname);
} else {
switch_snprintf(sql, sizeof(sql) - 1, "select name, syntax, description from interfaces where type = 'api' order by name");
}
@@ -2127,10 +2123,10 @@ SWITCH_STANDARD_API(uuid_setvar_function)
stream->write_function(stream, "-USAGE: %s\n", SETVAR_SYNTAX);
done:
done:
switch_safe_free(mycmd);
return SWITCH_STATUS_SUCCESS;
}
}
#define GETVAR_SYNTAX "<uuid> <var>"
SWITCH_STANDARD_API(uuid_getvar_function)
@@ -2177,7 +2173,7 @@ SWITCH_STANDARD_API(uuid_getvar_function)
stream->write_function(stream, "-USAGE: %s\n", GETVAR_SYNTAX);
done:
done:
switch_safe_free(mycmd);
return SWITCH_STATUS_SUCCESS;
}
@@ -2224,7 +2220,7 @@ SWITCH_STANDARD_API(uuid_dump_function)
}
switch_assert(buf);
stream->raw_write_function(stream, (unsigned char *)buf, strlen(buf));
stream->raw_write_function(stream, (unsigned char *) buf, strlen(buf));
switch_event_destroy(&event);
free(buf);
} else {
@@ -2242,7 +2238,7 @@ SWITCH_STANDARD_API(uuid_dump_function)
stream->write_function(stream, "-USAGE: %s\n", DUMP_SYNTAX);
done:
done:
switch_safe_free(mycmd);
return SWITCH_STATUS_SUCCESS;
}
@@ -2270,10 +2266,10 @@ SWITCH_STANDARD_API(global_setvar_function)
stream->write_function(stream, "-USAGE: %s\n", GLOBAL_SETVAR_SYNTAX);
done:
done:
switch_safe_free(mycmd);
return SWITCH_STATUS_SUCCESS;
}
}
#define GLOBAL_GETVAR_SYNTAX "<var>"
SWITCH_STANDARD_API(global_getvar_function)
@@ -2285,7 +2281,7 @@ SWITCH_STANDARD_API(global_getvar_function)
}
stream->write_function(stream, "-USAGE: %s\n", GLOBAL_GETVAR_SYNTAX);
done:
done:
return SWITCH_STATUS_SUCCESS;
}
@@ -2325,8 +2321,10 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
SWITCH_ADD_API(commands_api_interface, "help", "Show help for all the api commands", help_function, "");
SWITCH_ADD_API(commands_api_interface, "version", "Show version of the switch", version_function, "");
SWITCH_ADD_API(commands_api_interface, "sched_hangup", "Schedule a running call to hangup", sched_hangup_function, SCHED_HANGUP_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "sched_broadcast", "Schedule a broadcast event to a running call", sched_broadcast_function, SCHED_BROADCAST_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "sched_transfer", "Schedule a broadcast event to a running call", sched_transfer_function, SCHED_TRANSFER_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "sched_broadcast", "Schedule a broadcast event to a running call", sched_broadcast_function,
SCHED_BROADCAST_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "sched_transfer", "Schedule a broadcast event to a running call", sched_transfer_function,
SCHED_TRANSFER_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "create_uuid", "Create a uuid", uuid_function, UUID_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "sched_api", "Schedule an api command", sched_api_function, "[+]<time> <group_name> <command_string>");
SWITCH_ADD_API(commands_api_interface, "bgapi", "Execute an api command in a thread", bgapi_function, "<command>[ <arg>]");
File diff suppressed because it is too large. Load diff
+159 -135
View File
@@ -49,7 +49,7 @@ SWITCH_STANDARD_DIALPLAN(inline_dialplan_hunt)
if (!caller_profile) {
caller_profile = switch_channel_get_caller_profile(channel);
}
}
if ((extension = switch_caller_extension_new(session, "inline", "inline")) == 0) {
abort();
@@ -58,26 +58,26 @@ SWITCH_STANDARD_DIALPLAN(inline_dialplan_hunt)
if (switch_strlen_zero(target)) {
target = caller_profile->destination_number;
}
if (!switch_strlen_zero(target) && (lbuf = switch_core_session_strdup(session, target))
&& (argc = switch_separate_string(lbuf, ',', argv, (sizeof(argv) / sizeof(argv[0]))))) {
} else {
return NULL;
}
for(x = 0; x < argc; x++) {
for (x = 0; x < argc; x++) {
char *app = argv[x];
char *data = strchr(app, ':');
if (data) {
*data++ = '\0';
}
while(*app == ' ') {
while (*app == ' ') {
app++;
}
switch_caller_extension_add_application(session, extension, app, data);
}
@@ -119,7 +119,7 @@ SWITCH_STANDARD_APP(exe_function)
char *argv[4] = { 0 };
int argc;
char *lbuf = NULL;
if (!switch_strlen_zero(data) && (lbuf = switch_core_session_strdup(session, data))
&& (argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
switch_core_session_execute_exten(session, argv[0], argv[1], argv[2]);
@@ -135,13 +135,13 @@ SWITCH_STANDARD_APP(say_function)
char *argv[4] = { 0 };
int argc;
char *lbuf = NULL;
if (!switch_strlen_zero(data) && (lbuf = switch_core_session_strdup(session, data))
&& (argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) == 4) {
switch_ivr_say(session, argv[3], argv[0], argv[1], argv[2], NULL);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Usage: %s\n", SAY_SYNTAX);
}
}
}
@@ -151,7 +151,7 @@ SWITCH_STANDARD_APP(soft_hold_function)
char *argv[3] = { 0 };
int argc;
char *lbuf = NULL;
if (!switch_strlen_zero(data) && (lbuf = switch_core_session_strdup(session, data))
&& (argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) >= 1) {
switch_ivr_soft_hold(session, argv[0], argv[1], argv[2]);
@@ -166,7 +166,7 @@ SWITCH_STANDARD_APP(dtmf_bind_function)
char *argv[4] = { 0 };
int argc;
char *lbuf = NULL;
if (!switch_strlen_zero(data) && (lbuf = switch_core_session_strdup(session, data))
&& (argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) == 4) {
int kval = atoi(argv[0]);
@@ -239,7 +239,7 @@ SWITCH_STANDARD_APP(intercept_function)
} else {
uuid = argv[0];
}
switch_ivr_intercept_session(session, uuid, bleg);
}
return;
@@ -275,10 +275,10 @@ SWITCH_STANDARD_APP(eavesdrop_function)
} else {
switch_channel_t *channel = switch_core_session_get_channel(session);
const char *require_group = switch_channel_get_variable(channel, "eavesdrop_require_group");
if (!strcasecmp((char *)data, "all")) {
if (!strcasecmp((char *) data, "all")) {
switch_core_db_t *db = switch_core_db_handle();
char *errmsg = NULL;
struct e_data e_data = {{ 0 }};
struct e_data e_data = { {0} };
char *sql = switch_mprintf("select uuid from channels where uuid != '%q'", switch_core_session_get_uuid(session));
const char *file = NULL;
int x = 0;
@@ -286,9 +286,9 @@ SWITCH_STANDARD_APP(eavesdrop_function)
switch_size_t buflen = sizeof(buf);
char terminator;
switch_status_t status;
while(switch_channel_ready(channel)) {
for(x = 0; x < MAX_SPY; x++) {
while (switch_channel_ready(channel)) {
for (x = 0; x < MAX_SPY; x++) {
switch_safe_free(e_data.uuid_list[x]);
}
e_data.total = 0;
@@ -326,12 +326,12 @@ SWITCH_STANDARD_APP(eavesdrop_function)
}
}
for(x = 0; x < MAX_SPY; x++) {
for (x = 0; x < MAX_SPY; x++) {
switch_safe_free(e_data.uuid_list[x]);
}
switch_core_db_close(db);
} else {
switch_ivr_eavesdrop_session(session, data, require_group, ED_DTMF);
}
@@ -352,7 +352,7 @@ SWITCH_STANDARD_APP(three_way_function)
#define SET_USER_SYNTAX "<user>@<domain>"
SWITCH_STANDARD_APP(set_user_function)
{
switch_xml_t x_domain, xml = NULL, x_user, x_param, x_params;
switch_xml_t x_domain, xml = NULL, x_user, x_param, x_params;
char *user, *mailbox, *domain;
switch_channel_t *channel = switch_core_session_get_channel(session);
@@ -367,21 +367,21 @@ SWITCH_STANDARD_APP(set_user_function)
}
*domain++ = '\0';
if (switch_xml_locate_user("id", user, domain, NULL, &xml, &x_domain, &x_user, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "can't find user [%s@%s]\n", user, domain);
goto done;
}
if ((mailbox = (char *)switch_xml_attr(x_user, "mailbox"))) {
if ((mailbox = (char *) switch_xml_attr(x_user, "mailbox"))) {
switch_channel_set_variable(channel, "mailbox", mailbox);
}
if ((x_params = switch_xml_child(x_user, "variables"))) {
for (x_param = switch_xml_child(x_params, "variable"); x_param; x_param = x_param->next) {
const char *var = switch_xml_attr(x_param, "name");
const char *val = switch_xml_attr(x_param, "value");
if (var && val) {
switch_channel_set_variable(channel, var, val);
}
@@ -393,10 +393,10 @@ SWITCH_STANDARD_APP(set_user_function)
goto done;
error:
error:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No user@domain specified.\n");
done:
done:
if (xml) {
switch_xml_free(xml);
}
@@ -425,7 +425,7 @@ SWITCH_STANDARD_APP(send_dtmf_function)
SWITCH_STANDARD_APP(check_acl_function)
{
int argc;
char *argv[3] = { 0 };
char *argv[3] = { 0 };
char *mydata;
switch_call_cause_t cause = SWITCH_CAUSE_CALL_REJECTED;
@@ -441,7 +441,7 @@ SWITCH_STANDARD_APP(check_acl_function)
}
}
}
}
SWITCH_STANDARD_APP(transfer_function)
@@ -451,7 +451,7 @@ SWITCH_STANDARD_APP(transfer_function)
char *mydata;
int bleg = 0, both = 0;
if (!switch_strlen_zero(data) && (mydata = switch_core_session_strdup(session, data))) {
if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) >= 1) {
bleg = !strcasecmp(argv[0], "-bleg");
@@ -459,7 +459,7 @@ SWITCH_STANDARD_APP(transfer_function)
if (bleg || both) {
const char *uuid;
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_channel_t *channel = switch_core_session_get_channel(session);
if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))) {
switch_core_session_t *b_session;
if ((b_session = switch_core_session_locate(uuid))) {
@@ -592,7 +592,7 @@ SWITCH_STANDARD_APP(delay_function)
} else {
len = atoi(data);
}
switch_ivr_delay_echo(session, len);
}
@@ -776,16 +776,16 @@ SWITCH_STANDARD_APP(set_profile_var_function)
caller_profile->caller_id_number = val;
}
if (val && !strcasecmp(name, "caller_ton")) {
caller_profile->caller_ton = (uint8_t)atoi(val);
caller_profile->caller_ton = (uint8_t) atoi(val);
}
if (val && !strcasecmp(name, "caller_numplan")) {
caller_profile->caller_numplan = (uint8_t)atoi(val);
caller_profile->caller_numplan = (uint8_t) atoi(val);
}
if (val && !strcasecmp(name, "destination_number_ton")) {
caller_profile->destination_number_ton = (uint8_t)atoi(val);
caller_profile->destination_number_ton = (uint8_t) atoi(val);
}
if (val && !strcasecmp(name, "destination_number_numplan")) {
caller_profile->destination_number_numplan = (uint8_t)atoi(val);
caller_profile->destination_number_numplan = (uint8_t) atoi(val);
}
if (!strcasecmp(name, "ani")) {
caller_profile->ani = val;
@@ -846,7 +846,8 @@ SWITCH_STANDARD_APP(export_function)
}
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "EXPORT %s[%s]=[%s]\n", local ? "" : "(REMOTE ONLY) ", var_name ? var_name : "", val ? val : "UNDEF");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "EXPORT %s[%s]=[%s]\n", local ? "" : "(REMOTE ONLY) ", var_name ? var_name : "",
val ? val : "UNDEF");
switch_channel_set_variable(channel, var, val);
if (var && val) {
@@ -929,17 +930,20 @@ SWITCH_STANDARD_APP(event_function)
if (this) {
char *var, *val;
p = this;
while(*p == ' ') *p++ = '\0';
while (*p == ' ')
*p++ = '\0';
this = p;
var = this;
val = NULL;
if ((val = strchr(var, '='))) {
p = val - 1;
*val++ = '\0';
while(*p == ' ') *p-- = '\0';
while (*p == ' ')
*p-- = '\0';
p = val;
while(*p == ' ') *p++ = '\0';
while (*p == ' ')
*p++ = '\0';
val = p;
switch_event_add_header(event, SWITCH_STACK_BOTTOM, var, "%s", val);
}
@@ -1019,8 +1023,8 @@ SWITCH_STANDARD_API(strftime_api_function)
switch_time_t thetime;
char *p;
if (!switch_strlen_zero(cmd) && (p = strchr(cmd, '|'))) {
thetime = switch_time_make(atoi(cmd),0);
cmd = p+1;
thetime = switch_time_make(atoi(cmd), 0);
cmd = p + 1;
} else {
thetime = switch_timestamp_now();
}
@@ -1091,7 +1095,7 @@ SWITCH_STANDARD_API(chat_api_function)
static char *ivr_cf_name = "ivr.conf";
#ifdef _TEST_CALLBACK_
static switch_ivr_action_t menu_handler(switch_ivr_menu_t * menu, char *param, char *buf, size_t buflen, void *obj)
static switch_ivr_action_t menu_handler(switch_ivr_menu_t *menu, char *param, char *buf, size_t buflen, void *obj)
{
switch_ivr_action_t action = SWITCH_IVR_ACTION_NOOP;
@@ -1107,7 +1111,7 @@ SWITCH_STANDARD_APP(ivr_application_function)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_event_t *params;
if (channel) {
switch_xml_t cxml = NULL, cfg = NULL, xml_menus = NULL, xml_menu = NULL;
@@ -1118,7 +1122,7 @@ SWITCH_STANDARD_APP(ivr_application_function)
if ((cxml = switch_xml_open_cfg(ivr_cf_name, &cfg, params)) != NULL) {
if ((xml_menus = switch_xml_child(cfg, "menus"))) {
xml_menu = switch_xml_find_child(xml_menus, "menu", "name", (char *)data);
xml_menu = switch_xml_find_child(xml_menus, "menu", "name", (char *) data);
// if the menu was found
if (xml_menu != NULL) {
@@ -1134,7 +1138,7 @@ SWITCH_STANDARD_APP(ivr_application_function)
switch_xml_free(cxml);
cxml = NULL;
switch_channel_pre_answer(channel);
switch_ivr_menu_execute(session, menu_stack, (char *)data, NULL);
switch_ivr_menu_execute(session, menu_stack, (char *) data, NULL);
switch_ivr_menu_stack_free(menu_stack);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to create menu\n");
@@ -1164,12 +1168,12 @@ SWITCH_STANDARD_APP(stop_dtmf_session_function)
SWITCH_STANDARD_APP(dtmf_session_generate_function)
{
switch_bool_t do_read = SWITCH_TRUE;
if (!switch_strlen_zero(data)) {
if (!strcasecmp(data, "write")) {
do_read = SWITCH_FALSE;
}
}
}
switch_ivr_inband_dtmf_generate_session(session, do_read);
}
@@ -1185,9 +1189,9 @@ SWITCH_STANDARD_APP(fax_detect_session_function)
SWITCH_STANDARD_APP(system_session_function)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Executing command: %s\n",data);
if (!system(data)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Failed to execute command: %s\n",data);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Executing command: %s\n", data);
if (!system(data)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Failed to execute command: %s\n", data);
}
}
@@ -1211,7 +1215,7 @@ SWITCH_STANDARD_APP(tone_detect_session_function)
if (argv[3]) {
uint32_t mto;
if (*argv[3] == '+') {
if ((mto = atol(argv[3]+1)) > 0) {
if ((mto = atol(argv[3] + 1)) > 0) {
to = switch_timestamp(NULL) + mto;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "INVALID Timeout!\n");
@@ -1225,7 +1229,7 @@ SWITCH_STANDARD_APP(tone_detect_session_function)
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Enabling tone detection '%s' '%s'\n", argv[0], argv[1]);
switch_ivr_tone_detect_session(session, argv[0], argv[1], argv[2], to, argv[4], argv[5]);
}
@@ -1261,7 +1265,7 @@ SWITCH_STANDARD_APP(park_state_function)
static switch_status_t bridge_on_dtmf(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf, unsigned int buflen)
{
char *str = (char *) buf;
if (str && input && itype == SWITCH_INPUT_TYPE_DTMF) {
switch_dtmf_t *dtmf = (switch_dtmf_t *) input;
if (strchr(str, dtmf->digit)) {
@@ -1288,7 +1292,7 @@ static switch_status_t on_dtmf(switch_core_session_t *session, void *input, swit
terminators = NULL;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Digit %c\n", dtmf->digit);
for (p = terminators; p && *p; p++) {
if (*p == dtmf->digit) {
return SWITCH_STATUS_BREAK;
@@ -1326,7 +1330,7 @@ SWITCH_STANDARD_APP(speak_function)
}
argc = switch_separate_string(mydata, '|', argv, sizeof(argv) / sizeof(argv[0]));
if (argc == 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Params!\n");
return;
@@ -1381,11 +1385,11 @@ static switch_status_t xfer_on_dtmf(switch_core_session_t *session, void *input,
switch (itype) {
case SWITCH_INPUT_TYPE_DTMF:
{
{
switch_dtmf_t *dtmf = (switch_dtmf_t *) input;
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_channel_t *peer_channel = switch_core_session_get_channel(peer_session);
if (dtmf->digit == '#') {
return SWITCH_STATUS_FALSE;
}
@@ -1404,12 +1408,12 @@ static switch_status_t xfer_on_dtmf(switch_core_session_t *session, void *input,
}
switch_core_session_rwunlock(b_session);
}
if ((extension = switch_caller_extension_new(peer_session, app, app_arg)) == 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "memory error!\n");
abort();
}
switch_caller_extension_add_application(peer_session, extension, app, app_arg);
switch_channel_set_caller_extension(peer_channel, extension);
switch_channel_set_flag(peer_channel, CF_TRANSFER);
@@ -1418,7 +1422,7 @@ static switch_status_t xfer_on_dtmf(switch_core_session_t *session, void *input,
return SWITCH_STATUS_FALSE;
}
}
break;
default:
@@ -1444,7 +1448,7 @@ static switch_status_t hanguphook(switch_core_session_t *session)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "\nHangup Command uuid_bridge(%s):\n%s\n", id, switch_str_nil((char *) stream.data));
switch_safe_free(stream.data);
}
switch_core_event_hook_remove_state_change(session, hanguphook);
}
return SWITCH_STATUS_SUCCESS;
@@ -1468,8 +1472,8 @@ SWITCH_STANDARD_APP(att_xfer_function)
}
switch_channel_set_variable(channel, SWITCH_HOLDING_UUID_VARIABLE, bond);
if ((var = switch_channel_get_variable(channel, SWITCH_CALL_TIMEOUT_VARIABLE))) {
timelimit = atoi(var);
}
@@ -1481,9 +1485,9 @@ SWITCH_STANDARD_APP(att_xfer_function)
peer_channel = switch_core_session_get_channel(peer_session);
switch_channel_set_flag(peer_channel, CF_INNER_BRIDGE);
switch_channel_set_flag(channel, CF_INNER_BRIDGE);
switch_ivr_multi_threaded_bridge(session, peer_session, xfer_on_dtmf, peer_session, NULL);
switch_channel_clear_flag(peer_channel, CF_INNER_BRIDGE);
switch_channel_clear_flag(channel, CF_INNER_BRIDGE);
@@ -1510,13 +1514,13 @@ SWITCH_STANDARD_APP(att_xfer_function)
switch_core_session_rwunlock(b_session);
}
switch_channel_set_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE, bond);
}
switch_core_session_rwunlock(peer_session);
end:
end:
switch_channel_set_variable(channel, SWITCH_HOLDING_UUID_VARIABLE, NULL);
}
@@ -1538,12 +1542,12 @@ SWITCH_STANDARD_APP(read_function)
if (!switch_strlen_zero(data) && (mydata = switch_core_session_strdup(session, data))) {
argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No arguements specified.\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No arguements specified.\n");
return;
}
min_digits = atoi(argv[0]);
if (argc > 1) {
max_digits = atoi(argv[1]);
}
@@ -1551,19 +1555,19 @@ SWITCH_STANDARD_APP(read_function)
if (argc > 2) {
prompt_audio_file = argv[2];
}
if (argc > 3) {
var_name = argv[3];
}
if (argc > 4) {
timeout = atoi(argv[4]);
}
if (argc > 5) {
valid_terminators = argv[5];
}
if (min_digits <= 1) {
min_digits = 1;
}
@@ -1571,7 +1575,7 @@ SWITCH_STANDARD_APP(read_function)
if (max_digits < min_digits) {
max_digits = min_digits;
}
if (timeout <= 1000) {
timeout = 1000;
}
@@ -1634,7 +1638,7 @@ SWITCH_STANDARD_APP(displace_session_function)
if (!switch_strlen_zero(data) && (lbuf = switch_core_session_strdup(session, data))
&& (argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
path = argv[0];
for(x = 1; x < argc; x++) {
for (x = 1; x < argc; x++) {
if (strchr(argv[x], '+')) {
limit = atoi(argv[x]);
} else if (!switch_strlen_zero(argv[x])) {
@@ -1659,7 +1663,7 @@ SWITCH_STANDARD_APP(record_function)
switch_input_args_t args = { 0 };
switch_file_handle_t fh = { 0 };
int argc;
char *mydata, *argv[4] = { 0 };
char *mydata, *argv[4] = { 0 };
char *l = NULL;
const char *tmp;
int rate;
@@ -1667,10 +1671,10 @@ SWITCH_STANDARD_APP(record_function)
if (!switch_strlen_zero(data) && (mydata = switch_core_session_strdup(session, data))) {
argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No file specified.\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No file specified.\n");
return;
}
path = argv[0];
l = argv[1];
@@ -1726,11 +1730,12 @@ SWITCH_STANDARD_APP(record_session_function)
path = switch_core_session_strdup(session, data);
if (!path) return;
if (!path)
return;
if ((p = strchr(path, '+'))) {
char *q = p - 1;
while(q && *q == ' ') {
while (q && *q == ' ') {
*q = '\0';
q--;
}
@@ -1767,11 +1772,11 @@ SWITCH_STANDARD_APP(audio_bridge_function)
}
continue_on_fail = switch_channel_get_variable(caller_channel, "continue_on_fail");
if ((var = switch_channel_get_variable(caller_channel, SWITCH_PROXY_MEDIA_VARIABLE)) && switch_true(var)) {
switch_channel_set_flag(caller_channel, CF_PROXY_MEDIA);
}
if (switch_channel_test_flag(caller_channel, CF_PROXY_MODE)
|| ((var = switch_channel_get_variable(caller_channel, SWITCH_BYPASS_MEDIA_VARIABLE)) && switch_true(var))) {
if (!switch_channel_test_flag(caller_channel, CF_ANSWERED)
@@ -1801,7 +1806,7 @@ SWITCH_STANDARD_APP(audio_bridge_function)
'true' to continue on all failures.
'false' to not continue.
A list of codes either names or numbers eg "user_busy,normal_temporary_failure,603"
*/
*/
if (continue_on_fail) {
const char *cause_str;
char cause_num[35] = "";
@@ -1850,11 +1855,11 @@ SWITCH_STANDARD_APP(audio_bridge_function)
} else {
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_channel_t *peer_channel = switch_core_session_get_channel(peer_session);
char *a_key = (char *)switch_channel_get_variable(channel, "bridge_terminate_key");
char *b_key = (char *)switch_channel_get_variable(peer_channel, "bridge_terminate_key");
char *a_key = (char *) switch_channel_get_variable(channel, "bridge_terminate_key");
char *b_key = (char *) switch_channel_get_variable(peer_channel, "bridge_terminate_key");
int ok = 0;
switch_input_callback_function_t func = NULL;
if (a_key) {
a_key = switch_core_session_strdup(session, a_key);
ok++;
@@ -1873,7 +1878,7 @@ SWITCH_STANDARD_APP(audio_bridge_function)
switch_ivr_multi_threaded_bridge(session, peer_session, func, a_key, a_key);
}
}
end:
end:
if (peer_session) {
switch_core_session_rwunlock(peer_session);
}
@@ -1885,9 +1890,7 @@ switch_endpoint_interface_t *user_endpoint_interface;
static switch_call_cause_t user_outgoing_channel(switch_core_session_t *session,
switch_event_t *var_event,
switch_caller_profile_t *outbound_profile,
switch_core_session_t **new_session,
switch_memory_pool_t **pool,
switch_originate_flag_t flags);
switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags);
switch_io_routines_t user_io_routines = {
/*.outgoing_channel */ user_outgoing_channel
};
@@ -1895,11 +1898,9 @@ switch_io_routines_t user_io_routines = {
static switch_call_cause_t user_outgoing_channel(switch_core_session_t *session,
switch_event_t *var_event,
switch_caller_profile_t *outbound_profile,
switch_core_session_t **new_session,
switch_memory_pool_t **pool,
switch_originate_flag_t flags)
switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags)
{
switch_xml_t x_domain = NULL, xml = NULL, x_user = NULL, x_param, x_params;
switch_xml_t x_domain = NULL, xml = NULL, x_user = NULL, x_param, x_params;
char *user = NULL, *domain = NULL;
const char *dest = NULL;
static switch_call_cause_t cause = SWITCH_CAUSE_UNALLOCATED;
@@ -1912,7 +1913,8 @@ static switch_call_cause_t user_outgoing_channel(switch_core_session_t *session,
user = strdup(outbound_profile->destination_number);
if (!user) goto done;
if (!user)
goto done;
if (!(domain = strchr(user, '@'))) {
goto done;
@@ -1934,7 +1936,7 @@ static switch_call_cause_t user_outgoing_channel(switch_core_session_t *session,
for (x_param = switch_xml_child(x_params, "param"); x_param; x_param = x_param->next) {
const char *var = switch_xml_attr(x_param, "name");
const char *val = switch_xml_attr(x_param, "value");
if (!strcasecmp(var, "dial-string")) {
dest = val;
break;
@@ -1946,7 +1948,7 @@ static switch_call_cause_t user_outgoing_channel(switch_core_session_t *session,
for (x_param = switch_xml_child(x_params, "param"); x_param; x_param = x_param->next) {
const char *var = switch_xml_attr(x_param, "name");
const char *val = switch_xml_attr(x_param, "value");
if (!strcasecmp(var, "dial-string")) {
dest = val;
break;
@@ -1965,10 +1967,10 @@ static switch_call_cause_t user_outgoing_channel(switch_core_session_t *session,
if ((var = switch_channel_get_variable(channel, SWITCH_CALL_TIMEOUT_VARIABLE))) {
timelimit = atoi(var);
}
switch_channel_set_variable(channel, "dialed_user", user);
switch_channel_set_variable(channel, "dialed_domain", domain);
d_dest = switch_channel_expand_variables(channel, dest);
} else {
@@ -1977,7 +1979,7 @@ static switch_call_cause_t user_outgoing_channel(switch_core_session_t *session,
switch_event_create(&event, SWITCH_EVENT_MESSAGE);
switch_assert(event);
}
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "dialed_user", user);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "dialed_domain", domain);
d_dest = switch_event_expand_headers(event, dest);
@@ -1985,7 +1987,7 @@ static switch_call_cause_t user_outgoing_channel(switch_core_session_t *session,
switch_event_destroy(&event);
}
}
if ((flags & SOF_FORKED_DIAL)) {
myflags |= SOF_NOBLOCK;
}
@@ -1995,7 +1997,7 @@ static switch_call_cause_t user_outgoing_channel(switch_core_session_t *session,
switch_caller_profile_t *cp;
new_channel = switch_core_session_get_channel(*new_session);
if ((context = switch_channel_get_variable(new_channel, "user_context"))) {
if ((cp = switch_channel_get_caller_profile(new_channel))) {
cp->context = switch_core_strdup(cp->pool, context);
@@ -2027,12 +2029,12 @@ static switch_call_cause_t user_outgoing_channel(switch_core_session_t *session,
}
}
done:
done:
if (xml) {
switch_xml_free(xml);
}
if (params) {
switch_event_destroy(&params);
}
@@ -2080,20 +2082,22 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_dptools_load)
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
user_endpoint_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE);
user_endpoint_interface->interface_name = "USER";
user_endpoint_interface->io_routines = &user_io_routines;
user_endpoint_interface->interface_name = "USER";
user_endpoint_interface->io_routines = &user_io_routines;
SWITCH_ADD_API(api_interface, "strepoch", "Convert a date string into epoch time", strepoch_api_function, "<string>");
SWITCH_ADD_API(api_interface, "chat", "chat", chat_api_function, "<proto>|<from>|<to>|<message>");
SWITCH_ADD_API(api_interface, "strftime", "strftime", strftime_api_function, "<format_string>");
SWITCH_ADD_API(api_interface, "presence", "presence", presence_api_function, "<user> <rpid> <message>");
SWITCH_ADD_APP(app_interface, "privacy", "Set privacy on calls", "Set caller privacy on calls.", privacy_function, "off|on|name|full|number", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "privacy", "Set privacy on calls", "Set caller privacy on calls.", privacy_function, "off|on|name|full|number",
SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "hold", "Send a hold message", "Send a hold message", hold_function, HOLD_SYNTAX, SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "unhold", "Send a un-hold message", "Send a un-hold message", unhold_function, UNHOLD_SYNTAX, SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "transfer", "Transfer a channel", TRANSFER_LONG_DESC, transfer_function, "<exten> [<dialplan> <context>]", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "check_acl", "Check an ip against an ACL list",
"Check an ip against an ACL list", check_acl_function, "<ip> <acl | cidr> [<hangup_cause>]", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "transfer", "Transfer a channel", TRANSFER_LONG_DESC, transfer_function, "<exten> [<dialplan> <context>]",
SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "check_acl", "Check an ip against an ACL list", "Check an ip against an ACL list", check_acl_function,
"<ip> <acl | cidr> [<hangup_cause>]", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "sleep", "Pause a channel", SLEEP_LONG_DESC, sleep_function, "<pausemilliseconds>", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "delay_echo", "echo audio at a specified delay", "Delay n ms", delay_function, "<delay ms>", SAF_NONE);
SWITCH_ADD_APP(app_interface, "strftime", NULL, NULL, strftime_function, NULL, SAF_SUPPORT_NOMEDIA);
@@ -2106,36 +2110,50 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_dptools_load)
SWITCH_ADD_APP(app_interface, "log", "Logs a channel variable", LOG_LONG_DESC, log_function, "<varname>", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "info", "Display Call Info", "Display Call Info", info_function, "", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "event", "Fire an event", "Fire an event", event_function, "", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "export", "Export a channel variable across a bridge", EXPORT_LONG_DESC, export_function, "<varname>=<value>", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "export", "Export a channel variable across a bridge", EXPORT_LONG_DESC, export_function, "<varname>=<value>",
SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "set", "Set a channel variable", SET_LONG_DESC, set_function, "<varname>=<value>", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "set_global", "Set a global variable", SET_GLOBAL_LONG_DESC, set_global_function, "<varname>=<value>", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "set_profile_var", "Set a caller profile variable", SET_PROFILE_VAR_LONG_DESC, set_profile_var_function, "<varname>=<value>", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "set_global", "Set a global variable", SET_GLOBAL_LONG_DESC, set_global_function, "<varname>=<value>",
SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "set_profile_var", "Set a caller profile variable", SET_PROFILE_VAR_LONG_DESC, set_profile_var_function,
"<varname>=<value>", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "unset", "Unset a channel variable", UNSET_LONG_DESC, unset_function, "<varname>", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "ring_ready", "Indicate Ring_Ready", "Indicate Ring_Ready on a channel.", ring_ready_function, "", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "break", "Break", "Set the break flag.", break_function, "", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "detect_speech", "Detect speech", "Detect speech on a channel.", detect_speech_function, DETECT_SPEECH_SYNTAX, SAF_NONE);
SWITCH_ADD_APP(app_interface, "ivr", "Run an ivr menu", "Run an ivr menu.", ivr_application_function, "<menu_name>", SAF_NONE);
SWITCH_ADD_APP(app_interface, "redirect", "Send session redirect", "Send a redirect message to a session.", redirect_function, "<redirect_data>", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "send_display", "Send session a new display", "Send session a new display.", display_function, "<text>", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "respond", "Send session respond", "Send a respond message to a session.", respond_function, "<respond_data>", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "redirect", "Send session redirect", "Send a redirect message to a session.", redirect_function, "<redirect_data>",
SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "send_display", "Send session a new display", "Send session a new display.", display_function, "<text>",
SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "respond", "Send session respond", "Send a respond message to a session.", respond_function, "<respond_data>",
SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "deflect", "Send call deflect", "Send a call deflect.", deflect_function, "<deflect_data>", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "queue_dtmf", "Queue dtmf to be sent", "Queue dtmf to be sent from a session", queue_dtmf_function, "<dtmf_data>", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "send_dtmf", "Send dtmf to be sent", "Send dtmf to be sent from a session", send_dtmf_function, "<dtmf_data>", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "sched_hangup", SCHED_HANGUP_DESCR, SCHED_HANGUP_DESCR, sched_hangup_function, "[+]<time> [<cause>]", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "sched_broadcast", SCHED_BROADCAST_DESCR, SCHED_BROADCAST_DESCR, sched_broadcast_function, "[+]<time> <path> [aleg|bleg|both]", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "sched_transfer", SCHED_TRANSF_DESCR, SCHED_TRANSF_DESCR, sched_transfer_function, "[+]<time> <extension> <dialplan> <context>", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "queue_dtmf", "Queue dtmf to be sent", "Queue dtmf to be sent from a session", queue_dtmf_function, "<dtmf_data>",
SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "send_dtmf", "Send dtmf to be sent", "Send dtmf to be sent from a session", send_dtmf_function, "<dtmf_data>",
SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "sched_hangup", SCHED_HANGUP_DESCR, SCHED_HANGUP_DESCR, sched_hangup_function, "[+]<time> [<cause>]",
SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "sched_broadcast", SCHED_BROADCAST_DESCR, SCHED_BROADCAST_DESCR, sched_broadcast_function,
"[+]<time> <path> [aleg|bleg|both]", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "sched_transfer", SCHED_TRANSF_DESCR, SCHED_TRANSF_DESCR, sched_transfer_function,
"[+]<time> <extension> <dialplan> <context>", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "execute_extension", "Execute an extension", "Execute an extension", exe_function, EXE_SYNTAX, SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "soft_hold", "Put a bridged channel on hold", "Put a bridged channel on hold", soft_hold_function, SOFT_HOLD_SYNTAX, SAF_NONE);
SWITCH_ADD_APP(app_interface, "bind_meta_app", "Bind a key to an application", "Bind a key to an application", dtmf_bind_function, BIND_SYNTAX, SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "soft_hold", "Put a bridged channel on hold", "Put a bridged channel on hold", soft_hold_function, SOFT_HOLD_SYNTAX,
SAF_NONE);
SWITCH_ADD_APP(app_interface, "bind_meta_app", "Bind a key to an application", "Bind a key to an application", dtmf_bind_function, BIND_SYNTAX,
SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "intercept", "intercept", "intercept", intercept_function, INTERCEPT_SYNTAX, SAF_NONE);
SWITCH_ADD_APP(app_interface, "eavesdrop", "eavesdrop on a uuid", "eavesdrop on a uuid", eavesdrop_function, eavesdrop_SYNTAX, SAF_NONE);
SWITCH_ADD_APP(app_interface, "three_way", "three way call with a uuid", "three way call with a uuid", three_way_function, threeway_SYNTAX, SAF_NONE);
SWITCH_ADD_APP(app_interface, "set_user", "Set a User", "Set a User", set_user_function, SET_USER_SYNTAX, SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "stop_dtmf", "stop inband dtmf", "Stop detecting inband dtmf.", stop_dtmf_session_function, "", SAF_NONE);
SWITCH_ADD_APP(app_interface, "start_dtmf", "Detect dtmf", "Detect inband dtmf on the session", dtmf_session_function, "", SAF_NONE);
SWITCH_ADD_APP(app_interface, "stop_dtmf_generate", "stop inband dtmf generation", "Stop generating inband dtmf.",
SWITCH_ADD_APP(app_interface, "stop_dtmf_generate", "stop inband dtmf generation", "Stop generating inband dtmf.",
stop_dtmf_session_generate_function, "[write]", SAF_NONE);
SWITCH_ADD_APP(app_interface, "start_dtmf_generate", "Generate dtmf", "Generate inband dtmf on the session", dtmf_session_generate_function, "", SAF_NONE);
SWITCH_ADD_APP(app_interface, "start_dtmf_generate", "Generate dtmf", "Generate inband dtmf on the session", dtmf_session_generate_function, "",
SAF_NONE);
SWITCH_ADD_APP(app_interface, "stop_tone_detect", "stop detecting tones", "Stop detecting tones", stop_fax_detect_session_function, "", SAF_NONE);
SWITCH_ADD_APP(app_interface, "fax_detect", "Detect faxes", "Detect fax send tone", fax_detect_session_function, "", SAF_NONE);
SWITCH_ADD_APP(app_interface, "tone_detect", "Detect tones", "Detect tones", tone_detect_session_function, "", SAF_NONE);
@@ -2148,13 +2166,19 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_dptools_load)
SWITCH_ADD_APP(app_interface, "read", "Read Digits", "Read Digits", read_function, "<min> <max> <file> <var name> <timeout> <terminators>", SAF_NONE);
SWITCH_ADD_APP(app_interface, "stop_record_session", "Stop Record Session", STOP_SESS_REC_DESC, stop_record_session_function, "<path>", SAF_NONE);
SWITCH_ADD_APP(app_interface, "record_session", "Record Session", SESS_REC_DESC, record_session_function, "<path>", SAF_NONE);
SWITCH_ADD_APP(app_interface, "record", "Record File", "Record a file from the channels input", record_function, "<path> [<time_limit_secs>] [<silence_thresh>] [<silence_hits>]", SAF_NONE);
SWITCH_ADD_APP(app_interface, "stop_displace_session", "Stop Displace File", "Stop Displacing to a file", stop_displace_session_function, "<path>", SAF_NONE);
SWITCH_ADD_APP(app_interface, "displace_session", "Displace File", DISPLACE_DESC, displace_session_function, "<path> [+time_limit_ms] [mux]", SAF_NONE);
SWITCH_ADD_APP(app_interface, "record", "Record File", "Record a file from the channels input", record_function,
"<path> [<time_limit_secs>] [<silence_thresh>] [<silence_hits>]", SAF_NONE);
SWITCH_ADD_APP(app_interface, "stop_displace_session", "Stop Displace File", "Stop Displacing to a file", stop_displace_session_function, "<path>",
SAF_NONE);
SWITCH_ADD_APP(app_interface, "displace_session", "Displace File", DISPLACE_DESC, displace_session_function, "<path> [+time_limit_ms] [mux]",
SAF_NONE);
SWITCH_ADD_APP(app_interface, "speak", "Speak text", SPEAK_DESC, speak_function, "<engine>|<voice>|<text>", SAF_NONE);
SWITCH_ADD_APP(app_interface, "clear_speech_cache", "Clear Speech Handle Cache", "Clear Speech Handle Cache", clear_speech_cache_function, "", SAF_NONE);
SWITCH_ADD_APP(app_interface, "bridge", "Bridge Audio", "Bridge the audio between two sessions", audio_bridge_function, "<channel_url>", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "system", "Execute a system command", "Execute a system command", system_session_function, "<command>", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "clear_speech_cache", "Clear Speech Handle Cache", "Clear Speech Handle Cache", clear_speech_cache_function, "",
SAF_NONE);
SWITCH_ADD_APP(app_interface, "bridge", "Bridge Audio", "Bridge the audio between two sessions", audio_bridge_function, "<channel_url>",
SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "system", "Execute a system command", "Execute a system command", system_session_function, "<command>",
SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "say", "say", "say", say_function, SAY_SYNTAX, SAF_NONE);
SWITCH_ADD_DIALPLAN(dp_interface, "inline", inline_dialplan_hunt);
+31 -30
View File
@@ -200,16 +200,16 @@ static char *reverse_number(char *in, char *root)
return out;
}
static void dnserror(enum_query_t * q, int errnum)
static void dnserror(enum_query_t *q, int errnum)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "unable to lookup %s record for %s: %s\n",
dns_typename(q->qtyp), dns_dntosp(q->dn), dns_strerror(errnum));
q->errs++;
}
static void add_result(enum_query_t * q, int order, int preference, char *service, char *route, int supported)
static void add_result(enum_query_t *q, int order, int preference, char *service, char *route, int supported)
{
enum_record_t *new_result, *rp, *prev = NULL;
@@ -255,7 +255,7 @@ static void add_result(enum_query_t * q, int order, int preference, char *servic
}
static void free_results(enum_record_t ** results)
static void free_results(enum_record_t **results)
{
enum_record_t *fp, *rp;
@@ -269,7 +269,7 @@ static void free_results(enum_record_t ** results)
*results = NULL;
}
static void parse_rr(const struct dns_parse *p, enum_query_t * q, struct dns_rr *rr)
static void parse_rr(const struct dns_parse *p, enum_query_t *q, struct dns_rr *rr)
{
const unsigned char *pkt = p->dnsp_pkt;
const unsigned char *end = p->dnsp_end;
@@ -287,17 +287,17 @@ static void parse_rr(const struct dns_parse *p, enum_query_t * q, struct dns_rr
int argc = 0;
char *argv[4] = { 0 };
int n;
char string_arg[3][256] = {{0}};
char string_arg[3][256] = { {0} };
switch (rr->dnsrr_typ) {
case DNS_T_NAPTR:/* prio weight port targetDN */
case DNS_T_NAPTR: /* prio weight port targetDN */
c = dptr;
c += 4; /* order, pref */
c += 4; /* order, pref */
for (n = 0; n < 3; ++n) {
if (c >= dend) {
goto xperr;
} else {
} else {
c += *c + 1;
}
}
@@ -307,18 +307,18 @@ static void parse_rr(const struct dns_parse *p, enum_query_t * q, struct dns_rr
}
c = dptr;
order = dns_get16(c+0);
preference = dns_get16(c+2);
order = dns_get16(c + 0);
preference = dns_get16(c + 2);
flags = (char) dns_get16(c + 4);
c += 4;
for(n = 0; n < 3; n++) {
for (n = 0; n < 3; n++) {
uint32_t len = *c++, cpylen = len;
switch_assert(string_arg[n]);
if (len > sizeof(string_arg[n]) - 1) {
cpylen = sizeof(string_arg[n]) - 1;
}
strncpy(string_arg[n], (char *)c, cpylen);
strncpy(string_arg[n], (char *) c, cpylen);
*(string_arg[n] + len) = '\0';
c += len;
}
@@ -357,7 +357,7 @@ static void parse_rr(const struct dns_parse *p, enum_query_t * q, struct dns_rr
}
switch_mutex_lock(MUTEX);
for(route = globals.route_order; route; route = route->next) {
for (route = globals.route_order; route; route = route->next) {
if (strcasecmp(service, route->service)) {
continue;
}
@@ -377,9 +377,9 @@ static void parse_rr(const struct dns_parse *p, enum_query_t * q, struct dns_rr
if (!supported) {
add_result(q, order, preference, service, uri, 0);
}
}
}
switch_mutex_unlock(MUTEX);
switch_regex_safe_free(re);
}
@@ -392,7 +392,7 @@ static void parse_rr(const struct dns_parse *p, enum_query_t * q, struct dns_rr
return;
xperr:
xperr:
//printf("<parse error>\n");
return;
}
@@ -452,7 +452,7 @@ static void dnscb(struct dns_ctx *ctx, void *result, void *data)
}
static switch_status_t enum_lookup(char *root, char *in, enum_record_t ** results)
static switch_status_t enum_lookup(char *root, char *in, enum_record_t **results)
{
switch_status_t sstatus = SWITCH_STATUS_SUCCESS;
char *name = NULL;
@@ -467,7 +467,7 @@ static switch_status_t enum_lookup(char *root, char *in, enum_record_t ** result
char *num, *mnum = NULL, *mroot = NULL, *p;
mnum = switch_mprintf("%s%s", *in == '+' ? "" : "+", in);
if ((p = strchr(mnum, '*'))) {
*p++ = '\0';
mroot = switch_mprintf("%s.%s", p, root ? root : globals.isn_root);
@@ -587,15 +587,15 @@ SWITCH_STANDARD_DIALPLAN(enum_dialplan_hunt)
}
switch_channel_set_variable(channel, SWITCH_HANGUP_AFTER_BRIDGE_VARIABLE, "true");
for (rp = results; rp; rp = rp->next) {
if (!rp->supported) {
continue;
}
switch_caller_extension_add_application(session, extension, "bridge", rp->route);
switch_caller_extension_add_application(session, extension, "bridge", rp->route);
}
free_results(&results);
}
@@ -644,7 +644,7 @@ SWITCH_STANDARD_APP(enum_app_function)
continue;
}
switch_snprintf(vbuf, sizeof(vbuf), "enum_route_%d", cnt++);
switch_channel_set_variable(channel, vbuf, rp->route);
switch_channel_set_variable(channel, vbuf, rp->route);
if (rp->preference == last_pref && rp->order == last_order) {
*last_delim = ',';
}
@@ -656,7 +656,7 @@ SWITCH_STANDARD_APP(enum_app_function)
rbp += l;
rbl -= l;
}
switch_snprintf(vbuf, sizeof(vbuf), "%d", cnt);
switch_channel_set_variable(channel, "enum_route_count", vbuf);
*(rbuf + strlen(rbuf) - 1) = '\0';
@@ -681,7 +681,7 @@ SWITCH_STANDARD_API(enum_api)
int last_order = -1, last_pref = -2;
char *last_delim = "|";
int ok = 0;
if (switch_strlen_zero(cmd)) {
stream->write_function(stream, "%s", "none");
return SWITCH_STATUS_SUCCESS;
@@ -709,7 +709,7 @@ SWITCH_STANDARD_API(enum_api)
l = strlen(rp->route) + 1;
rbp += l;
rbl -= l;
}
*(rbuf + strlen(rbuf) - 1) = '\0';
stream->write_function(stream, "%s", rbuf);
@@ -738,7 +738,7 @@ static void do_load(void)
memset(&globals, 0, sizeof(globals));
switch_core_new_memory_pool(&globals.pool);
globals.timeout = 10;
load_config();
load_config();
switch_mutex_unlock(MUTEX);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "ENUM Reloaded\n");
@@ -772,7 +772,7 @@ SWITCH_STANDARD_API(enum_function)
if (!strcasecmp(dest, "reload")) {
do_load();
stream->write_function(stream, "+OK ENUM Reloaded.\n");
return SWITCH_STATUS_SUCCESS;
return SWITCH_STATUS_SUCCESS;
}
@@ -843,10 +843,11 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_enum_load)
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
SWITCH_ADD_API(api_interface, "enum", "ENUM", enum_function, "");
SWITCH_ADD_API(api_interface, "enum_auto", "ENUM", enum_api, "");
SWITCH_ADD_APP(app_interface, "enum", "Perform an ENUM lookup", "Perform an ENUM lookup", enum_app_function, "[reload | <number> [<root>]]", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "enum", "Perform an ENUM lookup", "Perform an ENUM lookup", enum_app_function, "[reload | <number> [<root>]]",
SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_DIALPLAN(dp_interface, "enum", enum_dialplan_hunt);
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
+47 -48
View File
@@ -63,7 +63,7 @@ SWITCH_STANDARD_APP(bcast_function)
switch_status_t status;
switch_size_t bytes;
ls_control_packet_t control_packet;
switch_codec_t codec = { 0}, *read_codec, *orig_codec = NULL;
switch_codec_t codec = { 0 }, *read_codec, *orig_codec = NULL;
uint32_t flags = 0;
const char *err;
switch_rtp_t *rtp_session = NULL;
@@ -71,7 +71,7 @@ SWITCH_STANDARD_APP(bcast_function)
char guess_ip[25];
ls_how_t ready = SEND_TYPE_UNKNOWN;
int argc;
char *mydata, *argv[5];
char *mydata, *argv[5];
char *mcast_ip = "224.168.168.168";
switch_port_t mcast_port = 34567;
switch_port_t mcast_control_port = 6061;
@@ -84,7 +84,7 @@ SWITCH_STANDARD_APP(bcast_function)
assert(mydata != NULL);
argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
if ((var = switch_channel_get_variable(channel, "esf_multicast_ip"))) {
mcast_ip = switch_core_session_strdup(session, var);
}
@@ -95,23 +95,23 @@ SWITCH_STANDARD_APP(bcast_function)
if (!switch_strlen_zero(argv[1])) {
mcast_port_str = argv[1];
mcast_port = (switch_port_t)atoi(mcast_port_str);
mcast_port = (switch_port_t) atoi(mcast_port_str);
}
if (!switch_strlen_zero(argv[2])) {
mcast_control_port = (switch_port_t)atoi(argv[2]);
mcast_control_port = (switch_port_t) atoi(argv[2]);
}
}
if (switch_true(switch_channel_get_variable(channel, SWITCH_BYPASS_MEDIA_VARIABLE))) {
switch_core_session_message_t msg = { 0 };
ready = SEND_TYPE_NOMEDIA;
switch_channel_set_variable(channel, SWITCH_REMOTE_MEDIA_IP_VARIABLE, mcast_ip);
switch_channel_set_variable(channel, SWITCH_REMOTE_MEDIA_PORT_VARIABLE, mcast_port_str);
/* special answer with the mcast addr */
msg.from = __FILE__;
msg.string_arg = "recvonly";
@@ -119,7 +119,7 @@ SWITCH_STANDARD_APP(bcast_function)
switch_core_session_receive_message(session, &msg);
} else {
switch_channel_answer(channel);
}
}
read_codec = switch_core_session_get_read_codec(session);
@@ -128,14 +128,14 @@ SWITCH_STANDARD_APP(bcast_function)
goto fail;
}
if (switch_sockaddr_info_get(&control_packet_addr, mcast_ip, SWITCH_UNSPEC,
if (switch_sockaddr_info_get(&control_packet_addr, mcast_ip, SWITCH_UNSPEC,
mcast_control_port, 0, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Socket Error 3\n");
goto fail;
}
while(!ready) {
while (!ready) {
status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
if (read_frame && switch_test_flag(read_frame, SFF_CNG)) {
continue;
@@ -144,7 +144,7 @@ SWITCH_STANDARD_APP(bcast_function)
if (!SWITCH_READ_ACCEPTABLE(status) || !read_frame) {
goto fail;
}
if (read_frame->packet && read_frame->packetlen && read_codec->implementation->ianacode == 0) {
ready = SEND_TYPE_RAW;
} else {
@@ -153,23 +153,23 @@ SWITCH_STANDARD_APP(bcast_function)
}
if (ready == SEND_TYPE_RTP) {
if (read_codec->implementation->ianacode != 0) {
if (switch_core_codec_init(&codec,
"PCMU",
NULL,
8000,
20,
1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
NULL, switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
orig_codec = read_codec;
read_codec = &codec;
switch_core_session_set_read_codec(session, read_codec);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Codec Activation Success\n");
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec Activation Fail\n");
goto fail;
}
}
if (read_codec->implementation->ianacode != 0) {
if (switch_core_codec_init(&codec,
"PCMU",
NULL,
8000,
20,
1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
NULL, switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
orig_codec = read_codec;
read_codec = &codec;
switch_core_session_set_read_codec(session, read_codec);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Codec Activation Success\n");
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec Activation Fail\n");
goto fail;
}
}
if ((var = switch_channel_get_variable(channel, "esf_broadcast_ip"))) {
esf_broadcast_ip = switch_core_session_strdup(session, var);
@@ -191,9 +191,8 @@ SWITCH_STANDARD_APP(bcast_function)
read_codec->implementation->ianacode,
read_codec->implementation->samples_per_frame,
read_codec->implementation->microseconds_per_frame,
(switch_rtp_flag_t) flags,
"soft", &err, switch_core_session_get_pool(session));
(switch_rtp_flag_t) flags, "soft", &err, switch_core_session_get_pool(session));
if (!switch_rtp_ready(rtp_session)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "RTP Error\n");
goto fail;
@@ -207,23 +206,23 @@ SWITCH_STANDARD_APP(bcast_function)
}
}
control_packet.unique_id = htonl((u_long)switch_timestamp(NULL));
control_packet.unique_id = htonl((u_long) switch_timestamp(NULL));
control_packet.command = htonl(LS_START_BCAST);
control_packet.ip = inet_addr(mcast_ip);
control_packet.port = htonl(mcast_port);
bytes = 16;
switch_socket_sendto(socket, control_packet_addr, 0, (void *)&control_packet, &bytes);
switch_socket_sendto(socket, control_packet_addr, 0, (void *) &control_packet, &bytes);
bytes = 16;
switch_socket_sendto(socket, control_packet_addr, 0, (void *)&control_packet, &bytes);
switch_socket_sendto(socket, control_packet_addr, 0, (void *) &control_packet, &bytes);
for(;;) {
for (;;) {
status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
if (!SWITCH_READ_ACCEPTABLE(status)) {
break;
}
if (!SWITCH_READ_ACCEPTABLE(status)) {
break;
}
if (switch_test_flag(read_frame, SFF_CNG)) {
continue;
}
@@ -235,23 +234,23 @@ SWITCH_STANDARD_APP(bcast_function)
}
}
control_packet.unique_id = htonl((u_long)switch_timestamp(NULL));
control_packet.unique_id = htonl((u_long) switch_timestamp(NULL));
control_packet.command = htonl(LS_STOP_BCAST);
bytes = 8;
switch_socket_sendto(socket, control_packet_addr, 0, (void *)&control_packet, &bytes);
switch_socket_sendto(socket, control_packet_addr, 0, (void *) &control_packet, &bytes);
bytes = 8;
switch_socket_sendto(socket, control_packet_addr, 0, (void *)&control_packet, &bytes);
switch_socket_sendto(socket, control_packet_addr, 0, (void *) &control_packet, &bytes);
fail:
fail:
if (orig_codec) {
switch_core_session_set_read_codec(session, orig_codec);
switch_core_codec_destroy(&codec);
}
if (orig_codec) {
switch_core_session_set_read_codec(session, orig_codec);
switch_core_codec_destroy(&codec);
}
if (rtp_session && ready == SEND_TYPE_RTP && switch_rtp_ready(rtp_session)) {
switch_rtp_destroy(&rtp_session);
}
}
if (socket) {
switch_socket_close(socket);
+179 -199
View File
@@ -25,244 +25,224 @@
/* This routine will evaluate an expression */
int exprEval(exprObj *obj, EXPRTYPE *val)
{
EXPRTYPE dummy;
int exprEval(exprObj * obj, EXPRTYPE * val)
{
EXPRTYPE dummy;
if(val == NULL)
val = &dummy;
if (val == NULL)
val = &dummy;
/* Make sure it was parsed successfully */
if(!obj->parsedbad && obj->parsedgood && obj->headnode)
{
/* Do NOT reset the break count. Let is accumulate
between calls until breaker function is called */
return exprEvalNode(obj, obj->headnode, 0, val);
}
else
return EXPR_ERROR_BADEXPR;
}
/* Make sure it was parsed successfully */
if (!obj->parsedbad && obj->parsedgood && obj->headnode) {
/* Do NOT reset the break count. Let is accumulate
between calls until breaker function is called */
return exprEvalNode(obj, obj->headnode, 0, val);
} else
return EXPR_ERROR_BADEXPR;
}
/* Evaluate a node */
int exprEvalNode(exprObj *obj, exprNode *nodes, int curnode, EXPRTYPE *val)
{
int err;
int pos;
EXPRTYPE d1, d2;
int exprEvalNode(exprObj * obj, exprNode * nodes, int curnode, EXPRTYPE * val)
{
int err;
int pos;
EXPRTYPE d1, d2;
if(obj == NULL || nodes == NULL)
return EXPR_ERROR_NULLPOINTER;
if (obj == NULL || nodes == NULL)
return EXPR_ERROR_NULLPOINTER;
/* Update n to point to correct node */
nodes += curnode;
/* Update n to point to correct node */
nodes += curnode;
/* Check breaker count */
if(obj->breakcur-- <= 0)
{
/* Reset count before returning */
obj->breakcur = obj->breakcount;
if(exprGetBreakResult(obj))
{
return EXPR_ERROR_BREAK;
}
}
/* Check breaker count */
if (obj->breakcur-- <= 0) {
/* Reset count before returning */
obj->breakcur = obj->breakcount;
switch(nodes->type)
{
case EXPR_NODETYPE_MULTI:
{
/* Multi for multiple expressions in one string */
for(pos = 0; pos < nodes->data.oper.nodecount; pos++)
{
err = exprEvalNode(obj, nodes->data.oper.nodes, pos, val);
if(err)
return err;
}
break;
}
if (exprGetBreakResult(obj)) {
return EXPR_ERROR_BREAK;
}
}
case EXPR_NODETYPE_ADD:
{
/* Addition */
err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
switch (nodes->type) {
case EXPR_NODETYPE_MULTI:
{
/* Multi for multiple expressions in one string */
for (pos = 0; pos < nodes->data.oper.nodecount; pos++) {
err = exprEvalNode(obj, nodes->data.oper.nodes, pos, val);
if (err)
return err;
}
break;
}
if(!err)
err = exprEvalNode(obj, nodes->data.oper.nodes, 1, &d2);
case EXPR_NODETYPE_ADD:
{
/* Addition */
err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
if(!err)
*val = d1 + d2;
else
return err;
if (!err)
err = exprEvalNode(obj, nodes->data.oper.nodes, 1, &d2);
break;
}
if (!err)
*val = d1 + d2;
else
return err;
case EXPR_NODETYPE_SUBTRACT:
{
/* Subtraction */
err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
if(!err)
err = exprEvalNode(obj, nodes->data.oper.nodes, 1, &d2);
break;
}
if(!err)
*val = d1 - d2;
else
return err;
case EXPR_NODETYPE_SUBTRACT:
{
/* Subtraction */
err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
break;
}
if (!err)
err = exprEvalNode(obj, nodes->data.oper.nodes, 1, &d2);
case EXPR_NODETYPE_MULTIPLY:
{
/* Multiplication */
err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
if (!err)
*val = d1 - d2;
else
return err;
if(!err)
err = exprEvalNode(obj, nodes->data.oper.nodes, 1, &d2);
break;
}
if(!err)
*val = d1 * d2;
else
return err;
case EXPR_NODETYPE_MULTIPLY:
{
/* Multiplication */
err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
break;
}
if (!err)
err = exprEvalNode(obj, nodes->data.oper.nodes, 1, &d2);
case EXPR_NODETYPE_DIVIDE:
{
/* Division */
err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
if (!err)
*val = d1 * d2;
else
return err;
if(!err)
err = exprEvalNode(obj, nodes->data.oper.nodes, 1, &d2);
break;
}
if(!err)
{
if(d2 != 0.0)
*val = d1 / d2;
else
{
case EXPR_NODETYPE_DIVIDE:
{
/* Division */
err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
if (!err)
err = exprEvalNode(obj, nodes->data.oper.nodes, 1, &d2);
if (!err) {
if (d2 != 0.0)
*val = d1 / d2;
else {
#if(EXPR_ERROR_LEVEL >= EXPR_ERROR_LEVEL_CHECK)
return EXPR_ERROR_DIVBYZERO;
return EXPR_ERROR_DIVBYZERO;
#else
*val = 0.0;
return EXPR_ERROR_NOERROR;
*val = 0.0;
return EXPR_ERROR_NOERROR;
#endif
}
}
else
return err;
}
} else
return err;
break;
}
break;
}
case EXPR_NODETYPE_EXPONENT:
{
/* Exponent */
err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
case EXPR_NODETYPE_EXPONENT:
{
/* Exponent */
err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
if(!err)
err = exprEvalNode(obj, nodes->data.oper.nodes, 1, &d2);
if (!err)
err = exprEvalNode(obj, nodes->data.oper.nodes, 1, &d2);
if(!err)
{
EXPR_RESET_ERR();
*val = pow(d1, d2);
EXPR_CHECK_ERR();
}
else
return err;
if (!err) {
EXPR_RESET_ERR();
*val = pow(d1, d2);
EXPR_CHECK_ERR();
} else
return err;
break;
}
break;
}
case EXPR_NODETYPE_NEGATE:
{
/* Negative value */
err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
case EXPR_NODETYPE_NEGATE:
{
/* Negative value */
err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
if(!err)
*val = -d1;
else
return err;
break;
}
if (!err)
*val = -d1;
else
return err;
break;
}
case EXPR_NODETYPE_VALUE:
{
/* Directly access the value */
*val = nodes->data.value.value;
break;
}
case EXPR_NODETYPE_VALUE:
{
/* Directly access the value */
*val = nodes->data.value.value;
break;
}
case EXPR_NODETYPE_VARIABLE:
{
/* Directly access the variable or constant */
*val = *(nodes->data.variable.vaddr);
break;
}
case EXPR_NODETYPE_VARIABLE:
{
/* Directly access the variable or constant */
*val = *(nodes->data.variable.vaddr);
break;
}
case EXPR_NODETYPE_ASSIGN:
{
/* Evaluate assignment subnode */
err = exprEvalNode(obj, nodes->data.assign.node, 0, val);
case EXPR_NODETYPE_ASSIGN:
{
/* Evaluate assignment subnode */
err = exprEvalNode(obj, nodes->data.assign.node, 0, val);
if(!err)
{
/* Directly assign the variable */
*(nodes->data.assign.vaddr) = *val;
}
else
return err;
break;
}
if (!err) {
/* Directly assign the variable */
*(nodes->data.assign.vaddr) = *val;
} else
return err;
case EXPR_NODETYPE_FUNCTION:
{
/* Evaluate the function */
if(nodes->data.function.fptr == NULL)
{
/* No function pointer means we are not using
function solvers. See if the function has a
type to solve directly. */
switch(nodes->data.function.type)
{
/* This is to keep the file from being too crowded.
See exprilfs.h for the definitions. */
break;
}
case EXPR_NODETYPE_FUNCTION:
{
/* Evaluate the function */
if (nodes->data.function.fptr == NULL) {
/* No function pointer means we are not using
function solvers. See if the function has a
type to solve directly. */
switch (nodes->data.function.type) {
/* This is to keep the file from being too crowded.
See exprilfs.h for the definitions. */
#include "exprilfs.h"
default:
{
return EXPR_ERROR_UNKNOWN;
}
}
}
else
{
/* Call the correct function */
return (*(nodes->data.function.fptr))(obj,
nodes->data.function.nodes, nodes->data.function.nodecount,
nodes->data.function.refs, nodes->data.function.refcount, val);
}
break;
}
default:
{
/* Unknown node type */
return EXPR_ERROR_UNKNOWN;
}
}
return EXPR_ERROR_NOERROR;
}
default:
{
return EXPR_ERROR_UNKNOWN;
}
}
} else {
/* Call the correct function */
return (*(nodes->data.function.fptr)) (obj,
nodes->data.function.nodes, nodes->data.function.nodecount,
nodes->data.function.refs, nodes->data.function.refcount, val);
}
break;
}
default:
{
/* Unknown node type */
return EXPR_ERROR_UNKNOWN;
}
}
return EXPR_ERROR_NOERROR;
}
+226 -243
View File
@@ -17,313 +17,296 @@
/* Internal functions */
static exprFunc *exprCreateFunc(char *name, exprFuncType ptr, int type, int min, int max, int refmin, int refmax);
static void exprFuncListFreeData(exprFunc *func);
static void exprFuncListFreeData(exprFunc * func);
/* This function creates the function list, */
int exprFuncListCreate(exprFuncList **flist)
{
exprFuncList *tmp;
int exprFuncListCreate(exprFuncList ** flist)
{
exprFuncList *tmp;
if(flist == NULL)
return EXPR_ERROR_NULLPOINTER;
if (flist == NULL)
return EXPR_ERROR_NULLPOINTER;
*flist = NULL; /* Set to NULL initially */
*flist = NULL; /* Set to NULL initially */
tmp = exprAllocMem(sizeof(exprFuncList));
tmp = exprAllocMem(sizeof(exprFuncList));
if(tmp == NULL)
return EXPR_ERROR_MEMORY; /* Could not allocate memory */
if (tmp == NULL)
return EXPR_ERROR_MEMORY; /* Could not allocate memory */
/* Update pointer */
*flist = tmp;
/* Update pointer */
*flist = tmp;
return EXPR_ERROR_NOERROR;
}
return EXPR_ERROR_NOERROR;
}
/* Add a function to the list */
int exprFuncListAdd(exprFuncList *flist, char *name, exprFuncType ptr, int min, int max, int refmin, int refmax)
{
exprFunc *tmp;
exprFunc *cur;
int result;
int exprFuncListAdd(exprFuncList * flist, char *name, exprFuncType ptr, int min, int max, int refmin, int refmax)
{
exprFunc *tmp;
exprFunc *cur;
int result;
if(flist == NULL)
return EXPR_ERROR_NULLPOINTER;
if (flist == NULL)
return EXPR_ERROR_NULLPOINTER;
/* Make sure the name is valid */
if(!exprValidIdent(name))
return EXPR_ERROR_BADIDENTIFIER;
/* Make sure the name is valid */
if (!exprValidIdent(name))
return EXPR_ERROR_BADIDENTIFIER;
/* Fix values only if none are negative (negative values mean no limit) */
/* Fix values only if none are negative (negative values mean no limit) */
/* if both are neg, no min or max number of args */
/* if min is neg, max pos, no min number of args but a maximum */
/* if min is pos, max neg, there is a min number of args, but no max */
/* if both pos, then a min and max limit. We swap to make sure it works
right. I.E. Min of 3 and max of 2 would make function unusable */
if(min >= 0 && max >= 0)
{
if(min > max)
{
result = min;
min = max;
max = result;
}
}
/* if both are neg, no min or max number of args */
/* if min is neg, max pos, no min number of args but a maximum */
/* if min is pos, max neg, there is a min number of args, but no max */
/* if both pos, then a min and max limit. We swap to make sure it works
right. I.E. Min of 3 and max of 2 would make function unusable */
if (min >= 0 && max >= 0) {
if (min > max) {
result = min;
min = max;
max = result;
}
}
if(refmin >= 0 && refmax >= 0)
{
if(refmin > refmax)
{
result = refmin;
refmin = max;
refmax = result;
}
}
if (refmin >= 0 && refmax >= 0) {
if (refmin > refmax) {
result = refmin;
refmin = max;
refmax = result;
}
}
if(flist->head == NULL)
{
/* Create the node right here */
tmp = exprCreateFunc(name, ptr, EXPR_NODETYPE_FUNCTION, min, max, refmin, refmax);
if (flist->head == NULL) {
/* Create the node right here */
tmp = exprCreateFunc(name, ptr, EXPR_NODETYPE_FUNCTION, min, max, refmin, refmax);
if(tmp == NULL)
return EXPR_ERROR_MEMORY;
if (tmp == NULL)
return EXPR_ERROR_MEMORY;
flist->head = tmp;
return EXPR_ERROR_NOERROR;
}
flist->head = tmp;
return EXPR_ERROR_NOERROR;
}
/* See if it already exists */
cur = flist->head;
while(cur)
{
result = strcmp(name, cur->fname);
if(result == 0)
return EXPR_ERROR_ALREADYEXISTS;
cur = cur->next;
}
/* It did not exist, so add it at the head */
tmp = exprCreateFunc(name, ptr, EXPR_NODETYPE_FUNCTION, min, max, refmin, refmax);
if(tmp == NULL)
return EXPR_ERROR_MEMORY;
tmp->next = flist->head;
flist->head = tmp;
return EXPR_ERROR_NOERROR;
}
/* See if it already exists */
cur = flist->head;
while (cur) {
result = strcmp(name, cur->fname);
if (result == 0)
return EXPR_ERROR_ALREADYEXISTS;
cur = cur->next;
}
/* It did not exist, so add it at the head */
tmp = exprCreateFunc(name, ptr, EXPR_NODETYPE_FUNCTION, min, max, refmin, refmax);
if (tmp == NULL)
return EXPR_ERROR_MEMORY;
tmp->next = flist->head;
flist->head = tmp;
return EXPR_ERROR_NOERROR;
}
/* Add a function node type to the list
This works pretty much the same way, except the function
pointer is NULL and the node type specifies the function
to do. exprEvalNode handles this, instead of calling
a function solver. */
int exprFuncListAddType(exprFuncList *flist, char *name, int type, int min, int max, int refmin, int refmax)
{
exprFunc *tmp;
exprFunc *cur;
int result;
int exprFuncListAddType(exprFuncList * flist, char *name, int type, int min, int max, int refmin, int refmax)
{
exprFunc *tmp;
exprFunc *cur;
int result;
if(flist == NULL)
return EXPR_ERROR_NULLPOINTER;
if (flist == NULL)
return EXPR_ERROR_NULLPOINTER;
/* Make sure the name is valid */
if(!exprValidIdent(name))
return EXPR_ERROR_BADIDENTIFIER;
/* Make sure the name is valid */
if (!exprValidIdent(name))
return EXPR_ERROR_BADIDENTIFIER;
/* Fix values only if none are negative (negative values mean no limit) */
/* Fix values only if none are negative (negative values mean no limit) */
/* if both are neg, no min or max number of args */
/* if min is neg, max pos, no min number of args but a maximum */
/* if min is pos, max neg, there is a min number of args, but no max */
/* if both pos, then a min and max limit. We swap to make sure it works
right. I.E. Min of 3 and max of 2 would make function unusable */
if(min >= 0 && max >= 0)
{
if(min > max)
{
result = min;
min = max;
max = result;
}
}
/* if both are neg, no min or max number of args */
/* if min is neg, max pos, no min number of args but a maximum */
/* if min is pos, max neg, there is a min number of args, but no max */
/* if both pos, then a min and max limit. We swap to make sure it works
right. I.E. Min of 3 and max of 2 would make function unusable */
if (min >= 0 && max >= 0) {
if (min > max) {
result = min;
min = max;
max = result;
}
}
if(refmin >= 0 && refmax >= 0)
{
if(refmin > refmax)
{
result = refmin;
refmin = max;
refmax = result;
}
}
if (refmin >= 0 && refmax >= 0) {
if (refmin > refmax) {
result = refmin;
refmin = max;
refmax = result;
}
}
if(flist->head == NULL)
{
/* Create the node right here */
tmp = exprCreateFunc(name, NULL, type, min, max, refmin, refmax);
if (flist->head == NULL) {
/* Create the node right here */
tmp = exprCreateFunc(name, NULL, type, min, max, refmin, refmax);
if(tmp == NULL)
return EXPR_ERROR_MEMORY;
if (tmp == NULL)
return EXPR_ERROR_MEMORY;
flist->head = tmp;
return EXPR_ERROR_NOERROR;
}
flist->head = tmp;
return EXPR_ERROR_NOERROR;
}
/* See if it already exists */
cur = flist->head;
while(cur)
{
result = strcmp(name, cur->fname);
if(result == 0)
return EXPR_ERROR_ALREADYEXISTS;
cur = cur->next;
}
/* It did not exist, so add it at the head */
tmp = exprCreateFunc(name, NULL, type, min, max, refmin, refmax);
if(tmp == NULL)
return EXPR_ERROR_MEMORY;
tmp->next = flist->head;
flist->head = tmp;
return EXPR_ERROR_NOERROR;
}
/* See if it already exists */
cur = flist->head;
while (cur) {
result = strcmp(name, cur->fname);
if (result == 0)
return EXPR_ERROR_ALREADYEXISTS;
cur = cur->next;
}
/* It did not exist, so add it at the head */
tmp = exprCreateFunc(name, NULL, type, min, max, refmin, refmax);
if (tmp == NULL)
return EXPR_ERROR_MEMORY;
tmp->next = flist->head;
flist->head = tmp;
return EXPR_ERROR_NOERROR;
}
/* Get the function from a list along with it's min an max data */
int exprFuncListGet(exprFuncList *flist, char *name, exprFuncType *ptr, int *type, int *min, int *max, int *refmin, int *refmax)
{
exprFunc *cur;
int result;
int exprFuncListGet(exprFuncList * flist, char *name, exprFuncType * ptr, int *type, int *min, int *max, int *refmin, int *refmax)
{
exprFunc *cur;
int result;
if(flist == NULL)
return EXPR_ERROR_NULLPOINTER;
if (flist == NULL)
return EXPR_ERROR_NULLPOINTER;
if(name == NULL || name[0] == '\0')
return EXPR_ERROR_NOTFOUND;
if (name == NULL || name[0] == '\0')
return EXPR_ERROR_NOTFOUND;
/* Search for the item */
cur = flist->head;
while(cur)
{
result = strcmp(name, cur->fname);
/* Search for the item */
cur = flist->head;
if(result == 0)
{
/* We found it. */
*ptr = cur->fptr;
*min = cur->min;
*max = cur->max;
*refmin = cur->refmin;
*refmax = cur->refmax;
*type = cur->type;
while (cur) {
result = strcmp(name, cur->fname);
/* return now */
return EXPR_ERROR_NOERROR;
}
cur = cur->next;
}
if (result == 0) {
/* We found it. */
*ptr = cur->fptr;
*min = cur->min;
*max = cur->max;
*refmin = cur->refmin;
*refmax = cur->refmax;
*type = cur->type;
/* If we got here, we did not find the item in the list */
return EXPR_ERROR_NOTFOUND;
}
/* return now */
return EXPR_ERROR_NOERROR;
}
cur = cur->next;
}
/* If we got here, we did not find the item in the list */
return EXPR_ERROR_NOTFOUND;
}
/* This routine will free the function list */
int exprFuncListFree(exprFuncList *flist)
{
/* Make sure it exists, if not it is not error */
if(flist == NULL)
return EXPR_ERROR_NOERROR;
int exprFuncListFree(exprFuncList * flist)
{
/* Make sure it exists, if not it is not error */
if (flist == NULL)
return EXPR_ERROR_NOERROR;
/* Free the nodes */
exprFuncListFreeData(flist->head);
/* Free the nodes */
exprFuncListFreeData(flist->head);
/* Free the container */
exprFreeMem(flist);
/* Free the container */
exprFreeMem(flist);
return EXPR_ERROR_NOERROR;
}
return EXPR_ERROR_NOERROR;
}
/* This routine will clear the function list */
int exprFuncListClear(exprFuncList *flist)
{
if(flist == NULL)
return EXPR_ERROR_NOERROR;
int exprFuncListClear(exprFuncList * flist)
{
if (flist == NULL)
return EXPR_ERROR_NOERROR;
/* Free the nodes only */
if(flist->head)
{
exprFuncListFreeData(flist->head);
/* Free the nodes only */
if (flist->head) {
exprFuncListFreeData(flist->head);
flist->head = NULL;
}
flist->head = NULL;
}
return EXPR_ERROR_NOERROR;
}
return EXPR_ERROR_NOERROR;
}
/* This routine will free any child nodes, and then free itself */
void exprFuncListFreeData(exprFunc *func)
{
exprFunc *next;
while(func)
{
/* Remember the next item */
next = func->next;
void exprFuncListFreeData(exprFunc * func)
{
exprFunc *next;
/* Free name */
exprFreeMem(func->fname);
while (func) {
/* Remember the next item */
next = func->next;
/* Free ourself */
exprFreeMem(func);
func = next;
}
}
/* Free name */
exprFreeMem(func->fname);
/* Free ourself */
exprFreeMem(func);
func = next;
}
}
/* This routine will create the function object */
exprFunc *exprCreateFunc(char *name, exprFuncType ptr, int type, int min, int max, int refmin, int refmax)
{
exprFunc *tmp;
char *vtmp;
{
exprFunc *tmp;
char *vtmp;
/* We already checked the name in exprFuncListAdd */
/* We already checked the name in exprFuncListAdd */
/* Create it */
tmp = exprAllocMem(sizeof(exprFunc));
if(tmp == NULL)
return NULL;
/* Create it */
tmp = exprAllocMem(sizeof(exprFunc));
if (tmp == NULL)
return NULL;
/* Allocate space for the name */
vtmp = exprAllocMem(strlen(name) + 1);
/* Allocate space for the name */
vtmp = exprAllocMem(strlen(name) + 1);
if(vtmp == NULL)
{
exprFreeMem(tmp);
return NULL;
}
if (vtmp == NULL) {
exprFreeMem(tmp);
return NULL;
}
/* Copy the data over */
strcpy(vtmp, name);
tmp->fname = vtmp;
tmp->fptr = ptr;
tmp->min = min;
tmp->max = max;
tmp->refmin = refmin;
tmp->refmax = refmax;
tmp->type = type;
/* Copy the data over */
strcpy(vtmp, name);
tmp->fname = vtmp;
tmp->fptr = ptr;
tmp->min = min;
tmp->max = max;
tmp->refmin = refmin;
tmp->refmax = refmax;
tmp->type = type;
return tmp;
}
return tmp;
}
+77 -79
View File
@@ -26,90 +26,88 @@ if(err != EXPR_ERROR_NOERROR) \
return err;
/* Call this function to initialize these functions into a function list */
int exprFuncListInit(exprFuncList *flist)
{
int err;
int exprFuncListInit(exprFuncList * flist)
{
int err;
if(flist == NULL)
return EXPR_ERROR_NULLPOINTER;
if (flist == NULL)
return EXPR_ERROR_NULLPOINTER;
EXPR_ADDFUNC_TYPE("abs", EXPR_NODEFUNC_ABS, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("mod", EXPR_NODEFUNC_MOD, 2, 2, 0, 0);
EXPR_ADDFUNC_TYPE("ipart", EXPR_NODEFUNC_IPART, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("fpart", EXPR_NODEFUNC_FPART, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("min", EXPR_NODEFUNC_MIN, 1, -1, 0, 0);
EXPR_ADDFUNC_TYPE("max", EXPR_NODEFUNC_MAX, 1, -1, 0, 0);
EXPR_ADDFUNC_TYPE("pow", EXPR_NODEFUNC_POW, 2, 2, 0, 0);
EXPR_ADDFUNC_TYPE("sqrt", EXPR_NODEFUNC_SQRT, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("sin", EXPR_NODEFUNC_SIN, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("sinh", EXPR_NODEFUNC_SINH, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("asin", EXPR_NODEFUNC_ASIN, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("cos", EXPR_NODEFUNC_COS, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("cosh", EXPR_NODEFUNC_COSH, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("acos", EXPR_NODEFUNC_ACOS, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("tan", EXPR_NODEFUNC_TAN, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("tanh", EXPR_NODEFUNC_TANH, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("atan", EXPR_NODEFUNC_ATAN, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("atan2", EXPR_NODEFUNC_ATAN2, 2, 2, 0, 0);
EXPR_ADDFUNC_TYPE("log", EXPR_NODEFUNC_LOG, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("pow10", EXPR_NODEFUNC_POW10, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("ln", EXPR_NODEFUNC_LN, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("exp", EXPR_NODEFUNC_EXP, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("logn", EXPR_NODEFUNC_LOGN, 2, 2, 0, 0);
EXPR_ADDFUNC_TYPE("ceil", EXPR_NODEFUNC_CEIL, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("floor", EXPR_NODEFUNC_FLOOR, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("rand", EXPR_NODEFUNC_RAND, 0, 0, 1, 1);
EXPR_ADDFUNC_TYPE("random", EXPR_NODEFUNC_RANDOM, 2, 2, 1, 1);
EXPR_ADDFUNC_TYPE("randomize", EXPR_NODEFUNC_RANDOMIZE, 0, 0, 1, 1);
EXPR_ADDFUNC_TYPE("deg", EXPR_NODEFUNC_DEG, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("rad", EXPR_NODEFUNC_RAD, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("recttopolr", EXPR_NODEFUNC_RECTTOPOLR, 2, 2, 0, 0);
EXPR_ADDFUNC_TYPE("recttopola", EXPR_NODEFUNC_RECTTOPOLA, 2, 2, 0, 0);
EXPR_ADDFUNC_TYPE("poltorectx", EXPR_NODEFUNC_POLTORECTX, 2, 2, 0, 0);
EXPR_ADDFUNC_TYPE("poltorecty", EXPR_NODEFUNC_POLTORECTY, 2, 2, 0, 0);
EXPR_ADDFUNC_TYPE("if", EXPR_NODEFUNC_IF, 3, 3, 0, 0);
EXPR_ADDFUNC_TYPE("select", EXPR_NODEFUNC_SELECT, 3, 4, 0, 0);
EXPR_ADDFUNC_TYPE("equal", EXPR_NODEFUNC_EQUAL, 2, 2, 0, 0);
EXPR_ADDFUNC_TYPE("above", EXPR_NODEFUNC_ABOVE, 2, 2, 0, 0);
EXPR_ADDFUNC_TYPE("below", EXPR_NODEFUNC_BELOW, 2, 2, 0, 0);
EXPR_ADDFUNC_TYPE("avg", EXPR_NODEFUNC_AVG, 1, -1, 0, 0);
EXPR_ADDFUNC_TYPE("clip", EXPR_NODEFUNC_CLIP, 3, 3, 0, 0);
EXPR_ADDFUNC_TYPE("clamp", EXPR_NODEFUNC_CLAMP, 3, 3, 0, 0);
EXPR_ADDFUNC_TYPE("pntchange", EXPR_NODEFUNC_PNTCHANGE, 5, 5, 0, 0);
EXPR_ADDFUNC_TYPE("poly", EXPR_NODEFUNC_POLY, 2, -1, 0, 0);
EXPR_ADDFUNC_TYPE("and", EXPR_NODEFUNC_AND, 2, 2, 0, 0);
EXPR_ADDFUNC_TYPE("or", EXPR_NODEFUNC_OR, 2, 2, 0, 0);
EXPR_ADDFUNC_TYPE("not", EXPR_NODEFUNC_NOT, 1 ,1, 0, 0);
EXPR_ADDFUNC_TYPE("for", EXPR_NODEFUNC_FOR, 4, -1, 0, 0);
EXPR_ADDFUNC_TYPE("many", EXPR_NODEFUNC_MANY, 1, -1, 0, 0);
EXPR_ADDFUNC_TYPE("abs", EXPR_NODEFUNC_ABS, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("mod", EXPR_NODEFUNC_MOD, 2, 2, 0, 0);
EXPR_ADDFUNC_TYPE("ipart", EXPR_NODEFUNC_IPART, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("fpart", EXPR_NODEFUNC_FPART, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("min", EXPR_NODEFUNC_MIN, 1, -1, 0, 0);
EXPR_ADDFUNC_TYPE("max", EXPR_NODEFUNC_MAX, 1, -1, 0, 0);
EXPR_ADDFUNC_TYPE("pow", EXPR_NODEFUNC_POW, 2, 2, 0, 0);
EXPR_ADDFUNC_TYPE("sqrt", EXPR_NODEFUNC_SQRT, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("sin", EXPR_NODEFUNC_SIN, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("sinh", EXPR_NODEFUNC_SINH, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("asin", EXPR_NODEFUNC_ASIN, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("cos", EXPR_NODEFUNC_COS, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("cosh", EXPR_NODEFUNC_COSH, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("acos", EXPR_NODEFUNC_ACOS, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("tan", EXPR_NODEFUNC_TAN, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("tanh", EXPR_NODEFUNC_TANH, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("atan", EXPR_NODEFUNC_ATAN, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("atan2", EXPR_NODEFUNC_ATAN2, 2, 2, 0, 0);
EXPR_ADDFUNC_TYPE("log", EXPR_NODEFUNC_LOG, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("pow10", EXPR_NODEFUNC_POW10, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("ln", EXPR_NODEFUNC_LN, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("exp", EXPR_NODEFUNC_EXP, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("logn", EXPR_NODEFUNC_LOGN, 2, 2, 0, 0);
EXPR_ADDFUNC_TYPE("ceil", EXPR_NODEFUNC_CEIL, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("floor", EXPR_NODEFUNC_FLOOR, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("rand", EXPR_NODEFUNC_RAND, 0, 0, 1, 1);
EXPR_ADDFUNC_TYPE("random", EXPR_NODEFUNC_RANDOM, 2, 2, 1, 1);
EXPR_ADDFUNC_TYPE("randomize", EXPR_NODEFUNC_RANDOMIZE, 0, 0, 1, 1);
EXPR_ADDFUNC_TYPE("deg", EXPR_NODEFUNC_DEG, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("rad", EXPR_NODEFUNC_RAD, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("recttopolr", EXPR_NODEFUNC_RECTTOPOLR, 2, 2, 0, 0);
EXPR_ADDFUNC_TYPE("recttopola", EXPR_NODEFUNC_RECTTOPOLA, 2, 2, 0, 0);
EXPR_ADDFUNC_TYPE("poltorectx", EXPR_NODEFUNC_POLTORECTX, 2, 2, 0, 0);
EXPR_ADDFUNC_TYPE("poltorecty", EXPR_NODEFUNC_POLTORECTY, 2, 2, 0, 0);
EXPR_ADDFUNC_TYPE("if", EXPR_NODEFUNC_IF, 3, 3, 0, 0);
EXPR_ADDFUNC_TYPE("select", EXPR_NODEFUNC_SELECT, 3, 4, 0, 0);
EXPR_ADDFUNC_TYPE("equal", EXPR_NODEFUNC_EQUAL, 2, 2, 0, 0);
EXPR_ADDFUNC_TYPE("above", EXPR_NODEFUNC_ABOVE, 2, 2, 0, 0);
EXPR_ADDFUNC_TYPE("below", EXPR_NODEFUNC_BELOW, 2, 2, 0, 0);
EXPR_ADDFUNC_TYPE("avg", EXPR_NODEFUNC_AVG, 1, -1, 0, 0);
EXPR_ADDFUNC_TYPE("clip", EXPR_NODEFUNC_CLIP, 3, 3, 0, 0);
EXPR_ADDFUNC_TYPE("clamp", EXPR_NODEFUNC_CLAMP, 3, 3, 0, 0);
EXPR_ADDFUNC_TYPE("pntchange", EXPR_NODEFUNC_PNTCHANGE, 5, 5, 0, 0);
EXPR_ADDFUNC_TYPE("poly", EXPR_NODEFUNC_POLY, 2, -1, 0, 0);
EXPR_ADDFUNC_TYPE("and", EXPR_NODEFUNC_AND, 2, 2, 0, 0);
EXPR_ADDFUNC_TYPE("or", EXPR_NODEFUNC_OR, 2, 2, 0, 0);
EXPR_ADDFUNC_TYPE("not", EXPR_NODEFUNC_NOT, 1, 1, 0, 0);
EXPR_ADDFUNC_TYPE("for", EXPR_NODEFUNC_FOR, 4, -1, 0, 0);
EXPR_ADDFUNC_TYPE("many", EXPR_NODEFUNC_MANY, 1, -1, 0, 0);
return EXPR_ERROR_NOERROR;
}
return EXPR_ERROR_NOERROR;
}
/* Call this function to initialize some constants into a value list */
int exprValListInit(exprValList *vlist)
{
int err;
int exprValListInit(exprValList * vlist)
{
int err;
if(vlist == NULL)
return EXPR_ERROR_NULLPOINTER;
EXPR_ADDCONST("M_E", M_E);
EXPR_ADDCONST("M_LOG2E", M_LOG2E);
EXPR_ADDCONST("M_LOG10E", M_LOG10E);
EXPR_ADDCONST("M_LN2", M_LN2);
EXPR_ADDCONST("M_LN10", M_LN10);
EXPR_ADDCONST("M_PI", M_PI);
EXPR_ADDCONST("M_PI_2", M_PI_2);
EXPR_ADDCONST("M_PI_4", M_PI_4);
EXPR_ADDCONST("M_1_PI", M_1_PI);
EXPR_ADDCONST("M_2_PI", M_2_PI);
EXPR_ADDCONST("M_1_SQRTPI", M_1_SQRTPI);
EXPR_ADDCONST("M_2_SQRTPI", M_2_SQRTPI);
EXPR_ADDCONST("M_SQRT2", M_SQRT2);
EXPR_ADDCONST("M_1_SQRT2", M_1_SQRT2);
return EXPR_ERROR_NOERROR;
}
if (vlist == NULL)
return EXPR_ERROR_NULLPOINTER;
EXPR_ADDCONST("M_E", M_E);
EXPR_ADDCONST("M_LOG2E", M_LOG2E);
EXPR_ADDCONST("M_LOG10E", M_LOG10E);
EXPR_ADDCONST("M_LN2", M_LN2);
EXPR_ADDCONST("M_LN10", M_LN10);
EXPR_ADDCONST("M_PI", M_PI);
EXPR_ADDCONST("M_PI_2", M_PI_2);
EXPR_ADDCONST("M_PI_4", M_PI_4);
EXPR_ADDCONST("M_1_PI", M_1_PI);
EXPR_ADDCONST("M_2_PI", M_2_PI);
EXPR_ADDCONST("M_1_SQRTPI", M_1_SQRTPI);
EXPR_ADDCONST("M_2_SQRTPI", M_2_SQRTPI);
EXPR_ADDCONST("M_SQRT2", M_SQRT2);
EXPR_ADDCONST("M_1_SQRT2", M_1_SQRT2);
return EXPR_ERROR_NOERROR;
}
+17 -18
View File
@@ -13,27 +13,26 @@
#include "exprmem.h"
/* Allocate memory and zero it */
void* exprAllocMem(size_t size)
{
void *data = malloc(size);
if(data)
{
memset(data, 0, size);
}
return data;
}
void *exprAllocMem(size_t size)
{
void *data = malloc(size);
if (data) {
memset(data, 0, size);
}
return data;
}
/* Free memory */
void exprFreeMem(void *data)
{
if(data)
free(data);
}
{
if (data)
free(data);
}
/* Allocate a list of nodes */
exprNode *exprAllocNodes(size_t count)
{
return exprAllocMem(count * sizeof(exprNode));
}
{
return exprAllocMem(count * sizeof(exprNode));
}
+146 -155
View File
@@ -14,224 +14,215 @@
#include "exprmem.h"
/* Internal functions */
static void exprFreeNodeData(exprNode *node);
static void exprFreeNodeData(exprNode * node);
/* Function to create an expression object */
int exprCreate(exprObj **obj, exprFuncList *flist, exprValList *vlist, exprValList *clist,
exprBreakFuncType breaker, void *userdata)
{
exprObj *tmp;
int exprCreate(exprObj ** obj, exprFuncList * flist, exprValList * vlist, exprValList * clist, exprBreakFuncType breaker, void *userdata)
{
exprObj *tmp;
/* Allocate memory for the object */
tmp = exprAllocMem(sizeof(exprObj));
/* Allocate memory for the object */
tmp = exprAllocMem(sizeof(exprObj));
if(tmp == NULL)
return EXPR_ERROR_MEMORY;
if (tmp == NULL)
return EXPR_ERROR_MEMORY;
/* Assign data */
tmp->flist = flist;
tmp->vlist = vlist;
tmp->clist = clist;
tmp->breakerfunc = breaker;
tmp->userdata = userdata;
tmp->breakcount = 100000; /* Default breaker count setting */
tmp->breakcur = 0;
/* Assign data */
tmp->flist = flist;
tmp->vlist = vlist;
tmp->clist = clist;
tmp->breakerfunc = breaker;
tmp->userdata = userdata;
tmp->breakcount = 100000; /* Default breaker count setting */
tmp->breakcur = 0;
/* Update pointer */
*obj = tmp;
/* Update pointer */
*obj = tmp;
return EXPR_ERROR_NOERROR;
}
return EXPR_ERROR_NOERROR;
}
/* Free the expression */
int exprFree(exprObj *obj)
{
if(obj == NULL)
return EXPR_ERROR_NOERROR;
int exprFree(exprObj * obj)
{
if (obj == NULL)
return EXPR_ERROR_NOERROR;
/* First free the node data */
exprFreeNodeData(obj->headnode);
exprFreeMem(obj->headnode);
/* First free the node data */
exprFreeNodeData(obj->headnode);
exprFreeMem(obj->headnode);
/* Free ourself */
exprFreeMem(obj);
/* Free ourself */
exprFreeMem(obj);
return EXPR_ERROR_NOERROR;
}
return EXPR_ERROR_NOERROR;
}
/* Clear expression, keep lists, etc */
int exprClear(exprObj *obj)
{
if(obj == NULL)
return EXPR_ERROR_NOERROR;
int exprClear(exprObj * obj)
{
if (obj == NULL)
return EXPR_ERROR_NOERROR;
/* Free the node data only, keep function, variable, constant lists */
exprFreeNodeData(obj->headnode);
exprFreeMem(obj->headnode);
/* Free the node data only, keep function, variable, constant lists */
exprFreeNodeData(obj->headnode);
exprFreeMem(obj->headnode);
obj->headnode = NULL;
obj->parsedbad = 0;
obj->parsedgood = 0;
obj->headnode = NULL;
obj->parsedbad = 0;
obj->parsedgood = 0;
return EXPR_ERROR_NOERROR;
}
return EXPR_ERROR_NOERROR;
}
/* Get functions to get information about the expression object */
/* Get the function list */
exprFuncList *exprGetFuncList(exprObj *obj)
{
return (obj == NULL) ? NULL : obj->flist;
}
exprFuncList *exprGetFuncList(exprObj * obj)
{
return (obj == NULL) ? NULL : obj->flist;
}
/* Get the variable list */
exprValList *exprGetVarList(exprObj *obj)
{
return (obj == NULL) ? NULL : obj->vlist;
}
exprValList *exprGetVarList(exprObj * obj)
{
return (obj == NULL) ? NULL : obj->vlist;
}
/* Get the constant list */
exprValList *exprGetConstList(exprObj *obj)
{
return (obj == NULL) ? NULL : obj->clist;
}
exprValList *exprGetConstList(exprObj * obj)
{
return (obj == NULL) ? NULL : obj->clist;
}
/* Get the breaker function */
exprBreakFuncType exprGetBreakFunc(exprObj *obj)
{
return (obj == NULL) ? NULL : obj->breakerfunc;
}
exprBreakFuncType exprGetBreakFunc(exprObj * obj)
{
return (obj == NULL) ? NULL : obj->breakerfunc;
}
/* Check for break status */
int exprGetBreakResult(exprObj *obj)
{
if(obj == NULL)
return 0;
int exprGetBreakResult(exprObj * obj)
{
if (obj == NULL)
return 0;
if(obj->breakerfunc == NULL)
return 0;
if (obj->breakerfunc == NULL)
return 0;
return (*(obj->breakerfunc))(obj);
}
return (*(obj->breakerfunc)) (obj);
}
/* Get the user data */
void *exprGetUserData(exprObj *obj)
{
return (obj == NULL) ? NULL : obj->userdata;
}
void *exprGetUserData(exprObj * obj)
{
return (obj == NULL) ? NULL : obj->userdata;
}
/* Set functions to set certain data */
/* Set user data */
void exprSetUserData(exprObj *obj, void *userdata)
{
if(obj)
obj->userdata = userdata;
}
void exprSetUserData(exprObj * obj, void *userdata)
{
if (obj)
obj->userdata = userdata;
}
/* Set breaker count */
void exprSetBreakCount(exprObj *obj, int count)
{
if(obj)
{
/* If count is negative, make it positive */
if(count < 0)
count = -count;
void exprSetBreakCount(exprObj * obj, int count)
{
if (obj) {
/* If count is negative, make it positive */
if (count < 0)
count = -count;
obj->breakcount = count;
obj->breakcount = count;
/* Make sure the current value is not bigger than count */
if(obj->breakcur > count)
obj->breakcur = count;
}
}
/* Make sure the current value is not bigger than count */
if (obj->breakcur > count)
obj->breakcur = count;
}
}
/* Get error position */
void exprGetErrorPosition(exprObj *obj, int *start, int *end)
{
if(obj)
{
if(start)
*start = obj->starterr;
void exprGetErrorPosition(exprObj * obj, int *start, int *end)
{
if (obj) {
if (start)
*start = obj->starterr;
if(end)
*end = obj->enderr;
}
}
if (end)
*end = obj->enderr;
}
}
/* This function will free a node's data */
static void exprFreeNodeData(exprNode *node)
{
int pos;
static void exprFreeNodeData(exprNode * node)
{
int pos;
if(node == NULL)
return;
if (node == NULL)
return;
/* free data based on type */
switch(node->type)
{
case EXPR_NODETYPE_ADD:
case EXPR_NODETYPE_SUBTRACT:
case EXPR_NODETYPE_MULTIPLY:
case EXPR_NODETYPE_DIVIDE:
case EXPR_NODETYPE_EXPONENT:
case EXPR_NODETYPE_NEGATE:
case EXPR_NODETYPE_MULTI:
/* Free operation data */
if(node->data.oper.nodes)
{
for(pos = 0; pos < node->data.oper.nodecount; pos++)
exprFreeNodeData(&(node->data.oper.nodes[pos]));
/* free data based on type */
switch (node->type) {
case EXPR_NODETYPE_ADD:
case EXPR_NODETYPE_SUBTRACT:
case EXPR_NODETYPE_MULTIPLY:
case EXPR_NODETYPE_DIVIDE:
case EXPR_NODETYPE_EXPONENT:
case EXPR_NODETYPE_NEGATE:
case EXPR_NODETYPE_MULTI:
/* Free operation data */
if (node->data.oper.nodes) {
for (pos = 0; pos < node->data.oper.nodecount; pos++)
exprFreeNodeData(&(node->data.oper.nodes[pos]));
exprFreeMem(node->data.oper.nodes);
}
exprFreeMem(node->data.oper.nodes);
}
break;
break;
case EXPR_NODETYPE_VALUE:
/* Nothing to free for value */
break;
case EXPR_NODETYPE_VALUE:
/* Nothing to free for value */
break;
case EXPR_NODETYPE_VARIABLE:
/* Nothing to free for variable */
break;
case EXPR_NODETYPE_VARIABLE:
/* Nothing to free for variable */
break;
case EXPR_NODETYPE_FUNCTION:
/* Free data of each subnode */
if(node->data.function.nodes)
{
for(pos = 0; pos < node->data.function.nodecount; pos++)
exprFreeNodeData(&(node->data.function.nodes[pos]));
case EXPR_NODETYPE_FUNCTION:
/* Free data of each subnode */
if (node->data.function.nodes) {
for (pos = 0; pos < node->data.function.nodecount; pos++)
exprFreeNodeData(&(node->data.function.nodes[pos]));
/* Free the subnode array */
exprFreeMem(node->data.function.nodes);
}
/* Free the subnode array */
exprFreeMem(node->data.function.nodes);
}
/* Free reference variable list */
if(node->data.function.refs)
exprFreeMem(node->data.function.refs);
/* Free reference variable list */
if (node->data.function.refs)
exprFreeMem(node->data.function.refs);
break;
break;
case EXPR_NODETYPE_ASSIGN:
/* Free subnode data */
if(node->data.assign.node)
{
exprFreeNodeData(node->data.assign.node);
/* Free the subnode */
exprFreeMem(node->data.assign.node);
}
break;
}
}
case EXPR_NODETYPE_ASSIGN:
/* Free subnode data */
if (node->data.assign.node) {
exprFreeNodeData(node->data.assign.node);
/* Free the subnode */
exprFreeMem(node->data.assign.node);
}
break;
}
}
File diff suppressed because it is too large. Load diff
+18 -20
View File
@@ -15,29 +15,27 @@
/* Return the version number */
void exprGetVersion(int *major, int *minor)
{
*major = EXPR_VERSIONMAJOR;
*minor = EXPR_VERSIONMINOR;
}
{
*major = EXPR_VERSIONMAJOR;
*minor = EXPR_VERSIONMINOR;
}
/* This utility function determines if an identifier is valid */
int exprValidIdent(char *name)
{
if(name == NULL) /* Null string */
return 0;
{
if (name == NULL) /* Null string */
return 0;
/* First must be letter or underscore */
if(isalpha(*name) || *name == '_')
name++; /* Point to next letter */
else
return 0; /* Not letter or underscore, maybe empty*/
/* others can be letter, number, or underscore */
while(isalnum(*name) || *name == '_')
name++;
/* When the while breaks out, we should be at the end */
return (*name == '\0') ? 1 : 0;
}
/* First must be letter or underscore */
if (isalpha(*name) || *name == '_')
name++; /* Point to next letter */
else
return 0; /* Not letter or underscore, maybe empty */
/* others can be letter, number, or underscore */
while (isalnum(*name) || *name == '_')
name++;
/* When the while breaks out, we should be at the end */
return (*name == '\0') ? 1 : 0;
}
+285 -301
View File
@@ -15,381 +15,365 @@
/* Internal functions */
static exprVal *exprCreateVal(char *name, EXPRTYPE val, EXPRTYPE *addr);
static void exprValListFreeData(exprVal *val);
static void exprValListResetData(exprVal *val);
static exprVal *exprCreateVal(char *name, EXPRTYPE val, EXPRTYPE * addr);
static void exprValListFreeData(exprVal * val);
static void exprValListResetData(exprVal * val);
/* This function creates the value list, */
int exprValListCreate(exprValList **vlist)
{
exprValList *tmp;
int exprValListCreate(exprValList ** vlist)
{
exprValList *tmp;
if(vlist == NULL)
return EXPR_ERROR_NULLPOINTER;
if (vlist == NULL)
return EXPR_ERROR_NULLPOINTER;
*vlist = NULL; /* Set to NULL initially */
*vlist = NULL; /* Set to NULL initially */
tmp = exprAllocMem(sizeof(exprValList));
tmp = exprAllocMem(sizeof(exprValList));
if(tmp == NULL)
return EXPR_ERROR_MEMORY; /* Could not allocate memory */
if (tmp == NULL)
return EXPR_ERROR_MEMORY; /* Could not allocate memory */
/* Update pointer */
*vlist = tmp;
/* Update pointer */
*vlist = tmp;
return EXPR_ERROR_NOERROR;
}
return EXPR_ERROR_NOERROR;
}
/* Add a value to the list */
int exprValListAdd(exprValList *vlist, char *name, EXPRTYPE val)
{
exprVal *tmp;
exprVal *cur;
int result;
int exprValListAdd(exprValList * vlist, char *name, EXPRTYPE val)
{
exprVal *tmp;
exprVal *cur;
int result;
if(vlist == NULL)
return EXPR_ERROR_NULLPOINTER;
if (vlist == NULL)
return EXPR_ERROR_NULLPOINTER;
/* Make sure the name is valid */
if(!exprValidIdent(name))
return EXPR_ERROR_BADIDENTIFIER;
/* Make sure the name is valid */
if (!exprValidIdent(name))
return EXPR_ERROR_BADIDENTIFIER;
if(vlist->head == NULL)
{
/* Create the node right here */
tmp = exprCreateVal(name, val, NULL);
if (vlist->head == NULL) {
/* Create the node right here */
tmp = exprCreateVal(name, val, NULL);
if(tmp == NULL)
return EXPR_ERROR_MEMORY;
if (tmp == NULL)
return EXPR_ERROR_MEMORY;
vlist->head = tmp;
return EXPR_ERROR_NOERROR;
}
vlist->head = tmp;
return EXPR_ERROR_NOERROR;
}
/* See if already exists */
cur = vlist->head;
/* See if already exists */
cur = vlist->head;
while(cur)
{
result = strcmp(name, cur->vname);
if(result == 0)
return EXPR_ERROR_ALREADYEXISTS;
cur = cur->next;
}
/* We did not find it, create it and add it to the beginning */
tmp = exprCreateVal(name, val, NULL);
while (cur) {
result = strcmp(name, cur->vname);
if (result == 0)
return EXPR_ERROR_ALREADYEXISTS;
cur = cur->next;
}
/* We did not find it, create it and add it to the beginning */
tmp = exprCreateVal(name, val, NULL);
if (tmp == NULL)
return EXPR_ERROR_MEMORY;
tmp->next = vlist->head;
vlist->head = tmp;
return EXPR_ERROR_NOERROR;
}
if(tmp == NULL)
return EXPR_ERROR_MEMORY;
tmp->next = vlist->head;
vlist->head = tmp;
return EXPR_ERROR_NOERROR;
}
/* Set a value in the list */
int exprValListSet(exprValList *vlist, char *name, EXPRTYPE val)
{
exprVal *cur;
int result;
int exprValListSet(exprValList * vlist, char *name, EXPRTYPE val)
{
exprVal *cur;
int result;
if(vlist == NULL)
return EXPR_ERROR_NULLPOINTER;
if (vlist == NULL)
return EXPR_ERROR_NULLPOINTER;
if(name == NULL || name[0] == '\0')
return EXPR_ERROR_NOTFOUND;
if (name == NULL || name[0] == '\0')
return EXPR_ERROR_NOTFOUND;
/* Find and set it */
cur = vlist->head;
/* Find and set it */
cur = vlist->head;
while(cur)
{
result = strcmp(name, cur->vname);
if(result == 0)
{
if(cur->vptr)
*(cur->vptr) = val;
else
cur->vval = val;
return EXPR_ERROR_NOERROR;
}
cur = cur->next;
}
return EXPR_ERROR_NOTFOUND;
}
while (cur) {
result = strcmp(name, cur->vname);
if (result == 0) {
if (cur->vptr)
*(cur->vptr) = val;
else
cur->vval = val;
return EXPR_ERROR_NOERROR;
}
cur = cur->next;
}
return EXPR_ERROR_NOTFOUND;
}
/* Get the value from a list */
int exprValListGet(exprValList *vlist, char *name, EXPRTYPE *val)
{
exprVal *cur;
int result;
int exprValListGet(exprValList * vlist, char *name, EXPRTYPE * val)
{
exprVal *cur;
int result;
if(vlist == NULL)
return EXPR_ERROR_NULLPOINTER;
if (vlist == NULL)
return EXPR_ERROR_NULLPOINTER;
if(name == NULL || name[0] == '\0')
return EXPR_ERROR_NOTFOUND;
if (name == NULL || name[0] == '\0')
return EXPR_ERROR_NOTFOUND;
/* Search for the item */
cur = vlist->head;
/* Search for the item */
cur = vlist->head;
while(cur)
{
result = strcmp(name, cur->vname);
while (cur) {
result = strcmp(name, cur->vname);
if(result == 0)
{
/* We found it. */
if(cur->vptr)
*val = *(cur->vptr);
else
*val = cur->vval;
if (result == 0) {
/* We found it. */
if (cur->vptr)
*val = *(cur->vptr);
else
*val = cur->vval;
/* return now */
return EXPR_ERROR_NOERROR;
}
/* return now */
return EXPR_ERROR_NOERROR;
}
cur = cur->next;
}
cur = cur->next;
}
/* If we got here, we did not find the item in the list */
return EXPR_ERROR_NOTFOUND;
}
/* If we got here, we did not find the item in the list */
return EXPR_ERROR_NOTFOUND;
}
/* Add an address to the list */
int exprValListAddAddress(exprValList *vlist, char *name, EXPRTYPE *addr)
{
exprVal *tmp;
exprVal *cur;
int result;
int exprValListAddAddress(exprValList * vlist, char *name, EXPRTYPE * addr)
{
exprVal *tmp;
exprVal *cur;
int result;
if(vlist == NULL)
return EXPR_ERROR_NULLPOINTER;
if (vlist == NULL)
return EXPR_ERROR_NULLPOINTER;
/* Make sure the name is valid */
if(!exprValidIdent(name))
return EXPR_ERROR_BADIDENTIFIER;
/* Make sure the name is valid */
if (!exprValidIdent(name))
return EXPR_ERROR_BADIDENTIFIER;
if(vlist->head == NULL)
{
/* Create the node right here */
tmp = exprCreateVal(name, (EXPRTYPE)0.0, addr);
if (vlist->head == NULL) {
/* Create the node right here */
tmp = exprCreateVal(name, (EXPRTYPE) 0.0, addr);
if(tmp == NULL)
return EXPR_ERROR_MEMORY;
if (tmp == NULL)
return EXPR_ERROR_MEMORY;
vlist->head = tmp;
return EXPR_ERROR_NOERROR;
}
vlist->head = tmp;
return EXPR_ERROR_NOERROR;
}
/* See if it already exists */
cur = vlist->head;
while(cur)
{
result = strcmp(name, cur->vname);
/* See if it already exists */
cur = vlist->head;
if(result == 0)
return EXPR_ERROR_ALREADYEXISTS;
cur = cur->next;
}
/* Add it to the list */
tmp = exprCreateVal(name, (EXPRTYPE)0.0, addr);
while (cur) {
result = strcmp(name, cur->vname);
if(tmp == NULL)
return EXPR_ERROR_MEMORY;
tmp->next = vlist->head;
vlist->head = tmp;
if (result == 0)
return EXPR_ERROR_ALREADYEXISTS;
return EXPR_ERROR_NOERROR;
}
cur = cur->next;
}
/* Add it to the list */
tmp = exprCreateVal(name, (EXPRTYPE) 0.0, addr);
if (tmp == NULL)
return EXPR_ERROR_MEMORY;
tmp->next = vlist->head;
vlist->head = tmp;
return EXPR_ERROR_NOERROR;
}
/* Get memory address of a variable value in a value list */
int exprValListGetAddress(exprValList *vlist, char *name, EXPRTYPE **addr)
{
exprVal *cur;
int result;
int exprValListGetAddress(exprValList * vlist, char *name, EXPRTYPE ** addr)
{
exprVal *cur;
int result;
/* Not found yet */
*addr = NULL;
/* Not found yet */
*addr = NULL;
if(vlist == NULL || addr == NULL)
return EXPR_ERROR_NULLPOINTER;
if (vlist == NULL || addr == NULL)
return EXPR_ERROR_NULLPOINTER;
if(name == NULL || name[0] == '\0')
return EXPR_ERROR_NOTFOUND;
if (name == NULL || name[0] == '\0')
return EXPR_ERROR_NOTFOUND;
/* Search for the item */
cur = vlist->head;
/* Search for the item */
cur = vlist->head;
while(cur)
{
result = strcmp(name, cur->vname);
while (cur) {
result = strcmp(name, cur->vname);
if(result == 0)
{
/* We found it. */
if(cur->vptr)
*addr = cur->vptr;
else
*addr = &(cur->vval);
if (result == 0) {
/* We found it. */
if (cur->vptr)
*addr = cur->vptr;
else
*addr = &(cur->vval);
/* return now */
return EXPR_ERROR_NOERROR;
}
cur = cur->next;
}
/* return now */
return EXPR_ERROR_NOERROR;
}
cur = cur->next;
}
/* If we got here, we did not find it in the list */
return EXPR_ERROR_NOTFOUND;
}
/* If we got here, we did not find it in the list */
return EXPR_ERROR_NOTFOUND;
}
/* This function is used to enumerate the values in a value list */
void *exprValListGetNext(exprValList *vlist, char **name, EXPRTYPE *value, EXPRTYPE** addr, void *cookie)
{
exprVal *cur;
if(vlist == NULL)
return NULL;
/* Get the current item */
cur = (exprVal*)cookie;
/* Find the next item */
if(cur == NULL)
cur = vlist->head;
else
cur = cur->next;
/* Set up the data */
if(cur)
{
if(name)
*name = cur->vname;
if(value)
{
if(cur->vptr)
*value = *(cur->vptr);
else
*value = cur->vval;
}
if(addr)
{
if(cur->vptr)
*addr = cur->vptr;
else
*addr = &(cur->vval);
}
}
/* If there was no value, return NULL, otherwise, return the item */
return (void*)cur;
}
void *exprValListGetNext(exprValList * vlist, char **name, EXPRTYPE * value, EXPRTYPE ** addr, void *cookie)
{
exprVal *cur;
if (vlist == NULL)
return NULL;
/* Get the current item */
cur = (exprVal *) cookie;
/* Find the next item */
if (cur == NULL)
cur = vlist->head;
else
cur = cur->next;
/* Set up the data */
if (cur) {
if (name)
*name = cur->vname;
if (value) {
if (cur->vptr)
*value = *(cur->vptr);
else
*value = cur->vval;
}
if (addr) {
if (cur->vptr)
*addr = cur->vptr;
else
*addr = &(cur->vval);
}
}
/* If there was no value, return NULL, otherwise, return the item */
return (void *) cur;
}
/* This routine will free the value list */
int exprValListFree(exprValList *vlist)
{
/* Make sure it exists, if not it is not error */
if(vlist == NULL)
return EXPR_ERROR_NOERROR;
int exprValListFree(exprValList * vlist)
{
/* Make sure it exists, if not it is not error */
if (vlist == NULL)
return EXPR_ERROR_NOERROR;
/* Free the nodes */
exprValListFreeData(vlist->head);
/* Free the nodes */
exprValListFreeData(vlist->head);
/* Freethe container */
exprFreeMem(vlist);
/* Freethe container */
exprFreeMem(vlist);
return EXPR_ERROR_NOERROR;
}
return EXPR_ERROR_NOERROR;
}
/* This routine will reset the value list to 0.0 */
int exprValListClear(exprValList *vlist)
{
if(vlist == NULL)
return EXPR_ERROR_NOERROR;
int exprValListClear(exprValList * vlist)
{
if (vlist == NULL)
return EXPR_ERROR_NOERROR;
exprValListResetData(vlist->head);
exprValListResetData(vlist->head);
return EXPR_ERROR_NOERROR;
}
return EXPR_ERROR_NOERROR;
}
/* This routine will free any child nodes, and then free itself */
static void exprValListFreeData(exprVal *val)
{
exprVal *next;
while(val)
{
/* Remember the next */
next = val->next;
/* Free name */
exprFreeMem(val->vname);
static void exprValListFreeData(exprVal * val)
{
exprVal *next;
/* Free ourself */
exprFreeMem(val);
val = next;
}
}
while (val) {
/* Remember the next */
next = val->next;
/* Free name */
exprFreeMem(val->vname);
/* Free ourself */
exprFreeMem(val);
val = next;
}
}
/* This routine will reset variables to 0.0 */
static void exprValListResetData(exprVal *val)
{
while(val)
{
/* Reset data */
if(val->vptr)
*(val->vptr) = 0.0;
val->vval = 0.0;
val = val->next;
}
}
static void exprValListResetData(exprVal * val)
{
while (val) {
/* Reset data */
if (val->vptr)
*(val->vptr) = 0.0;
val->vval = 0.0;
val = val->next;
}
}
/* This routine will create the value object */
static exprVal *exprCreateVal(char *name, EXPRTYPE val, EXPRTYPE *addr)
{
exprVal *tmp;
char *vtmp;
static exprVal *exprCreateVal(char *name, EXPRTYPE val, EXPRTYPE * addr)
{
exprVal *tmp;
char *vtmp;
/* Name already tested in exprValListAdd */
/* Name already tested in exprValListAdd */
/* Create it */
tmp = exprAllocMem(sizeof(exprVal));
if(tmp == NULL)
return NULL;
/* Create it */
tmp = exprAllocMem(sizeof(exprVal));
if (tmp == NULL)
return NULL;
/* Allocate space for the name */
vtmp = exprAllocMem(strlen(name) + 1);
/* Allocate space for the name */
vtmp = exprAllocMem(strlen(name) + 1);
if(vtmp == NULL)
{
exprFreeMem(tmp);
return NULL;
}
if (vtmp == NULL) {
exprFreeMem(tmp);
return NULL;
}
/* Copy the data over */
strcpy(vtmp, name);
tmp->vname = vtmp;
tmp->vval = val;
tmp->vptr = addr;
/* Copy the data over */
strcpy(vtmp, name);
tmp->vname = vtmp;
tmp->vval = val;
tmp->vptr = addr;
return tmp;
}
return tmp;
}
+101 -101
View File
@@ -33,145 +33,145 @@
/* Breaker function to break out of long expression functions
such as the 'for' function */
int breaker(exprObj *o)
int breaker(exprObj * o)
{
/* Return nonzero to break out */
return -1;
/* Return nonzero to break out */
return -1;
}
SWITCH_STANDARD_API(expr_function)
{
exprObj *e = NULL;
exprFuncList *f = NULL;
exprValList *v = NULL;
exprValList *c = NULL;
EXPRTYPE last_expr;
exprObj *e = NULL;
exprFuncList *f = NULL;
exprValList *v = NULL;
exprValList *c = NULL;
EXPRTYPE last_expr;
const char *expr;
int err;
char val[512] = "", *p;
char *m_cmd = NULL;
size_t len;
char val[512] = "", *p;
char *m_cmd = NULL;
size_t len;
if (switch_strlen_zero(cmd)) {
goto error;
}
if (switch_strlen_zero(cmd)) {
goto error;
}
len = strlen(cmd) + 3;
len = strlen(cmd) + 3;
m_cmd = malloc(len);
switch_assert(m_cmd);
switch_copy_string(m_cmd, cmd, len);
for (p = m_cmd; p && *p; p++) {
if (*p == '|') {
*p = ';';
}
}
m_cmd = malloc(len);
switch_assert(m_cmd);
switch_copy_string(m_cmd, cmd, len);
p = m_cmd + (strlen(m_cmd) - 1);
if (*p != ';') {
p++;
*p = ';';
p++;
*p = '\0';
}
for (p = m_cmd; p && *p; p++) {
if (*p == '|') {
*p = ';';
}
}
expr = m_cmd;
p = m_cmd + (strlen(m_cmd) - 1);
if (*p != ';') {
p++;
*p = ';';
p++;
*p = '\0';
}
/* Create function list */
err = exprFuncListCreate(&f);
if (err != EXPR_ERROR_NOERROR)
goto error;
expr = m_cmd;
/* Init function list with internal functions */
err = exprFuncListInit(f);
if (err != EXPR_ERROR_NOERROR)
goto error;
/* Create function list */
err = exprFuncListCreate(&f);
if (err != EXPR_ERROR_NOERROR)
goto error;
/* Add custom function */
//err = exprFuncListAdd(f, my_func, "myfunc", 1, 1, 1, 1);
//if (err != EXPR_ERROR_NOERROR)
/* Init function list with internal functions */
err = exprFuncListInit(f);
if (err != EXPR_ERROR_NOERROR)
goto error;
/* Add custom function */
//err = exprFuncListAdd(f, my_func, "myfunc", 1, 1, 1, 1);
//if (err != EXPR_ERROR_NOERROR)
//goto error;
/* Create constant list */
err = exprValListCreate(&c);
if (err != EXPR_ERROR_NOERROR)
goto error;
/* Create constant list */
err = exprValListCreate(&c);
if (err != EXPR_ERROR_NOERROR)
goto error;
/* Init constant list with internal constants */
err = exprValListInit(c);
if (err != EXPR_ERROR_NOERROR)
goto error;
/* Init constant list with internal constants */
err = exprValListInit(c);
if (err != EXPR_ERROR_NOERROR)
goto error;
/* Create variable list */
err = exprValListCreate(&v);
if (err != EXPR_ERROR_NOERROR)
goto error;
/* Create variable list */
err = exprValListCreate(&v);
if (err != EXPR_ERROR_NOERROR)
goto error;
/* Create expression object */
err = exprCreate(&e, f, v, c, breaker, NULL);
if (err != EXPR_ERROR_NOERROR)
goto error;
/* Create expression object */
err = exprCreate(&e, f, v, c, breaker, NULL);
if (err != EXPR_ERROR_NOERROR)
goto error;
/* Parse expression */
err = exprParse(e, (char *)expr);
/* Parse expression */
err = exprParse(e, (char *) expr);
if (err != EXPR_ERROR_NOERROR)
goto error;
if (err != EXPR_ERROR_NOERROR)
goto error;
/* Enable soft errors */
//exprSetSoftErrors(e, 1);
/* Enable soft errors */
//exprSetSoftErrors(e, 1);
do {
err = exprEval(e, &last_expr);
} while (err);
switch_snprintf(val, sizeof(val), "%0.10f", last_expr);
for (p = (val + strlen(val) - 1); p != val; p--) {
if (*p != '0') {
*(p+1) = '\0';
break;
}
}
switch_snprintf(val, sizeof(val), "%0.10f", last_expr);
for (p = (val + strlen(val) - 1); p != val; p--) {
if (*p != '0') {
*(p + 1) = '\0';
break;
}
}
p = val + strlen(val) - 1;
if (*p == '.') {
*p = '\0';
}
p = val + strlen(val) - 1;
if (*p == '.') {
*p = '\0';
}
stream->write_function(stream, "%s", val);
stream->write_function(stream, "%s", val);
goto done;
goto done;
error:
/* Alert user of error */
stream->write_function(stream, "!err!");
error:
/* Alert user of error */
stream->write_function(stream, "!err!");
done:
/* Do cleanup */
if (e) {
exprFree(e);
}
done:
/* Do cleanup */
if (e) {
exprFree(e);
}
if (f) {
exprFuncListFree(f);
}
if (f) {
exprFuncListFree(f);
}
if (v) {
exprValListFree(v);
}
if (v) {
exprValListFree(v);
}
if (c) {
exprValListFree(c);
}
if (c) {
exprValListFree(c);
}
switch_safe_free(m_cmd);
switch_safe_free(m_cmd);
return SWITCH_STATUS_SUCCESS;
return SWITCH_STATUS_SUCCESS;
}
@@ -181,10 +181,10 @@ SWITCH_MODULE_DEFINITION(mod_expr, mod_expr_load, NULL, NULL);
SWITCH_MODULE_LOAD_FUNCTION(mod_expr_load)
{
switch_api_interface_t *commands_api_interface;
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
SWITCH_ADD_API(commands_api_interface, "expr", "Eval an expession", expr_function, "<expr>");
File diff suppressed because it is too large. Load diff
+56 -54
View File
@@ -61,35 +61,35 @@ static void *SWITCH_THREAD_FUNC record_video_thread(switch_thread_t *thread, voi
switch_status_t status;
switch_frame_t *read_frame;
int bytes;
eh->up = 1;
while(switch_channel_ready(channel)) {
eh->up = 1;
while (switch_channel_ready(channel)) {
status = switch_core_session_read_video_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
if (!SWITCH_READ_ACCEPTABLE(status)) {
break;
}
if (switch_test_flag(read_frame, SFF_CNG)) {
continue;
}
bytes = read_frame->packetlen |VID_BIT;
bytes = read_frame->packetlen | VID_BIT;
switch_mutex_lock(eh->mutex);
if (write(eh->fd, &bytes, sizeof(bytes)) != (int)sizeof(bytes)) {
if (write(eh->fd, &bytes, sizeof(bytes)) != (int) sizeof(bytes)) {
switch_mutex_unlock(eh->mutex);
break;
}
if (write(eh->fd, read_frame->packet, read_frame->packetlen) != (int)read_frame->packetlen) {
if (write(eh->fd, read_frame->packet, read_frame->packetlen) != (int) read_frame->packetlen) {
switch_mutex_unlock(eh->mutex);
break;
}
switch_mutex_unlock(eh->mutex);
switch_core_session_write_video_frame(session, read_frame, SWITCH_IO_FLAG_NONE, 0);
}
eh->up = 0;
@@ -101,24 +101,24 @@ SWITCH_STANDARD_APP(record_fsv_function)
switch_status_t status;
switch_frame_t *read_frame;
switch_channel_t *channel = switch_core_session_get_channel(session);
struct record_helper eh = {0};
struct record_helper eh = { 0 };
switch_thread_t *thread;
switch_threadattr_t *thd_attr = NULL;
int fd;
switch_mutex_t *mutex = NULL;
switch_codec_t codec, *read_codec, *vid_codec;
switch_channel_answer(channel);
if ((fd = open((char *)data, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) < 0) {
if ((fd = open((char *) data, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error opening file %s\n", (char *) data);
return;
}
switch_channel_answer(channel);
read_codec = switch_core_session_get_read_codec(session);
if (switch_core_codec_init(&codec,
"L16",
NULL,
@@ -131,14 +131,14 @@ SWITCH_STANDARD_APP(record_fsv_function)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Audio Codec Activation Fail\n");
goto end;
}
switch_core_session_set_read_codec(session, &codec);
if (switch_channel_test_flag(channel, CF_VIDEO)) {
struct file_header h;
memset(&h, 0, sizeof(h));
vid_codec = switch_core_session_get_video_read_codec(session);
h.version = VERSION;
h.created = switch_timestamp_now();
switch_set_string(h.video_codec_name, vid_codec->implementation->iananame);
@@ -147,11 +147,11 @@ SWITCH_STANDARD_APP(record_fsv_function)
}
h.audio_rate = read_codec->implementation->samples_per_second;
h.audio_ptime = read_codec->implementation->microseconds_per_frame / 1000;
if (write(fd, &h, sizeof(h)) != sizeof(h)) {
goto end;
}
switch_mutex_init(&mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
eh.mutex = mutex;
eh.fd = fd;
@@ -161,12 +161,12 @@ SWITCH_STANDARD_APP(record_fsv_function)
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
switch_thread_create(&thread, thd_attr, record_video_thread, &eh, switch_core_session_get_pool(session));
}
while(switch_channel_ready(channel)) {
while (switch_channel_ready(channel)) {
status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
if (!SWITCH_READ_ACCEPTABLE(status)) {
break;
}
@@ -186,7 +186,7 @@ SWITCH_STANDARD_APP(record_fsv_function)
break;
}
if (write(fd, read_frame->data, read_frame->datalen) != (int)read_frame->datalen) {
if (write(fd, read_frame->data, read_frame->datalen) != (int) read_frame->datalen) {
if (mutex) {
switch_mutex_unlock(mutex);
}
@@ -198,42 +198,44 @@ SWITCH_STANDARD_APP(record_fsv_function)
}
}
end:
end:
if (eh.up) {
while(eh.up) {
while (eh.up) {
switch_yield(1000);
}
}
switch_core_session_set_read_codec(session, read_codec);
switch_core_codec_destroy(&codec);
}
SWITCH_STANDARD_APP(play_fsv_function)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_frame_t write_frame = {0}, vid_frame = {0};
switch_frame_t write_frame = { 0 }, vid_frame = {
0};
int fd = -1;
int bytes;
switch_codec_t *read_codec = NULL, codec = {0}, vid_codec = {0}, *read_vid_codec;
switch_codec_t *read_codec = NULL, codec = { 0 }, vid_codec = {
0}, *read_vid_codec;
unsigned char *aud_buffer;
unsigned char *vid_buffer;
struct file_header h;
uint32_t ts = 0, last = 0;
switch_timer_t timer = {0};
uint32_t ts = 0, last = 0;
switch_timer_t timer = { 0 };
switch_payload_t pt = 0;
aud_buffer = switch_core_session_alloc(session, SWITCH_RECOMMENDED_BUFFER_SIZE);
vid_buffer = switch_core_session_alloc(session, SWITCH_RECOMMENDED_BUFFER_SIZE);
if ((fd = open((char *)data, O_RDONLY)) < 0) {
if ((fd = open((char *) data, O_RDONLY)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error opening file %s\n", (char *) data);
return;
}
if (read(fd, &h, sizeof(h)) != sizeof(h)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "error reading file header\n");
goto end;
@@ -246,7 +248,7 @@ SWITCH_STANDARD_APP(play_fsv_function)
switch_channel_set_variable(channel, "sip_force_video_fmtp", h.video_fmtp);
switch_channel_answer(channel);
if ((read_vid_codec = switch_core_session_get_video_read_codec(session))) {
pt = read_vid_codec->agreed_pt;
}
@@ -254,16 +256,16 @@ SWITCH_STANDARD_APP(play_fsv_function)
write_frame.codec = &codec;
write_frame.data = aud_buffer;
write_frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE;
vid_frame.codec = &vid_codec;
vid_frame.packet = vid_buffer;
vid_frame.data = vid_buffer + 12;
vid_frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE - 12;
switch_set_flag((&vid_frame), SFF_RAW_RTP);
read_codec = switch_core_session_get_read_codec(session);
if (switch_core_timer_init(&timer, "soft", read_codec->implementation->microseconds_per_frame / 1000,
if (switch_core_timer_init(&timer, "soft", read_codec->implementation->microseconds_per_frame / 1000,
read_codec->implementation->samples_per_frame, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "timer Activation Fail\n");
goto end;
@@ -281,7 +283,7 @@ SWITCH_STANDARD_APP(play_fsv_function)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Audio Codec Activation Fail\n");
goto end;
}
if (switch_core_codec_init(&vid_codec,
h.video_codec_name,
NULL,
@@ -296,20 +298,20 @@ SWITCH_STANDARD_APP(play_fsv_function)
}
switch_core_session_set_read_codec(session, &codec);
while(switch_channel_ready(channel)) {
while (switch_channel_ready(channel)) {
if (read(fd, &bytes, sizeof(bytes)) != sizeof(bytes)) {
break;
}
if (bytes & VID_BIT) {
switch_rtp_hdr_t *hdr = vid_frame.packet;
bytes &= ~VID_BIT;
if ((vid_frame.packetlen = read(fd, vid_frame.packet, bytes)) != (uint32_t)bytes) {
if ((vid_frame.packetlen = read(fd, vid_frame.packet, bytes)) != (uint32_t) bytes) {
break;
}
ts = ntohl(hdr->ts);
if (pt) {
hdr->pt = pt;
@@ -322,7 +324,7 @@ SWITCH_STANDARD_APP(play_fsv_function)
}
last = ts;
} else {
if (bytes > (int)write_frame.buflen) {
if (bytes > (int) write_frame.buflen) {
bytes = write_frame.buflen;
}
if ((write_frame.datalen = read(fd, write_frame.data, bytes)) <= 0) {
@@ -333,9 +335,9 @@ SWITCH_STANDARD_APP(play_fsv_function)
}
}
end:
end:
if (timer.interval) {
switch_core_timer_destroy(&timer);
}
@@ -343,15 +345,15 @@ SWITCH_STANDARD_APP(play_fsv_function)
if (read_codec) {
switch_core_session_set_read_codec(session, read_codec);
}
if (codec.implementation) {
switch_core_codec_destroy(&codec);
}
if (vid_codec.implementation) {
switch_core_codec_destroy(&vid_codec);
}
if (fd > -1) {
close(fd);
}
@@ -362,7 +364,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_fsv_load)
switch_application_interface_t *app_interface;
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
SWITCH_ADD_APP(app_interface, "play_fsv", "play an fsv file", "play an fsv file", play_fsv_function, "<file>", SAF_NONE);
SWITCH_ADD_APP(app_interface, "record_fsv", "record an fsv file", "record an fsv file", record_fsv_function, "<file>", SAF_NONE);
+47 -59
View File
@@ -53,28 +53,16 @@ static struct {
static char limit_sql[] =
"CREATE TABLE limit_data (\n"
" hostname VARCHAR(255),\n"
" realm VARCHAR(255),\n"
" id VARCHAR(255),\n"
" uuid VARCHAR(255)\n"
");\n";
" hostname VARCHAR(255),\n" " realm VARCHAR(255),\n" " id VARCHAR(255),\n" " uuid VARCHAR(255)\n" ");\n";
static char db_sql[] =
"CREATE TABLE db_data (\n"
" hostname VARCHAR(255),\n"
" realm VARCHAR(255),\n"
" data_key VARCHAR(255),\n"
" data VARCHAR(255)\n"
");\n";
" hostname VARCHAR(255),\n" " realm VARCHAR(255),\n" " data_key VARCHAR(255),\n" " data VARCHAR(255)\n" ");\n";
static char group_sql[] =
"CREATE TABLE group_data (\n"
" hostname VARCHAR(255),\n"
" groupname VARCHAR(255),\n"
" url VARCHAR(255)\n"
");\n";
"CREATE TABLE group_data (\n" " hostname VARCHAR(255),\n" " groupname VARCHAR(255),\n" " url VARCHAR(255)\n" ");\n";
@@ -86,9 +74,8 @@ static switch_status_t limit_execute_sql(char *sql, switch_mutex_t *mutex)
if (mutex) {
switch_mutex_lock(mutex);
}
#ifdef SWITCH_HAVE_ODBC
if (globals.odbc_dsn) {
if (globals.odbc_dsn) {
SQLHSTMT stmt;
if (switch_odbc_handle_exec(globals.master_odbc, sql, &stmt) != SWITCH_ODBC_SUCCESS) {
char *err_str;
@@ -110,33 +97,29 @@ static switch_status_t limit_execute_sql(char *sql, switch_mutex_t *mutex)
switch_core_db_close(db);
#ifdef SWITCH_HAVE_ODBC
}
}
#endif
end:
end:
if (mutex) {
switch_mutex_unlock(mutex);
}
return status;
return status;
}
static switch_bool_t limit_execute_sql_callback(switch_mutex_t *mutex,
char *sql,
switch_core_db_callback_func_t callback,
void *pdata)
static switch_bool_t limit_execute_sql_callback(switch_mutex_t *mutex, char *sql, switch_core_db_callback_func_t callback, void *pdata)
{
switch_bool_t ret = SWITCH_FALSE;
switch_core_db_t *db;
char *errmsg = NULL;
if (mutex) {
switch_mutex_lock(mutex);
}
#ifdef SWITCH_HAVE_ODBC
if (globals.odbc_dsn) {
switch_odbc_handle_callback_exec(globals.master_odbc, sql, callback, pdata);
@@ -161,7 +144,7 @@ static switch_bool_t limit_execute_sql_callback(switch_mutex_t *mutex,
}
#endif
end:
end:
if (mutex) {
switch_mutex_unlock(mutex);
}
@@ -185,12 +168,12 @@ static switch_status_t do_config()
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
return SWITCH_STATUS_TERM;
}
if ((settings = switch_xml_child(cfg, "settings"))) {
for (param = switch_xml_child(settings, "param"); param; param = param->next) {
char *var = NULL;
char *val = NULL;
var = (char *) switch_xml_attr_soft(param, "name");
val = (char *) switch_xml_attr_soft(param, "value");
@@ -198,9 +181,9 @@ static switch_status_t do_config()
#ifdef SWITCH_HAVE_ODBC
globals.odbc_dsn = switch_core_strdup(globals.pool, val);
if ((odbc_user = strchr(globals.odbc_dsn, ':'))) {
*odbc_user++ = '\0';
*odbc_user++ = '\0';
if ((odbc_pass = strchr(odbc_user, ':'))) {
*odbc_pass++ = '\0';
*odbc_pass++ = '\0';
}
}
#else
@@ -214,7 +197,6 @@ static switch_status_t do_config()
if (switch_strlen_zero(globals.odbc_dsn) || switch_strlen_zero(odbc_user) || switch_strlen_zero(odbc_pass)) {
globals.dbname = "call_limit";
}
#ifdef SWITCH_HAVE_ODBC
if (globals.odbc_dsn) {
@@ -228,11 +210,11 @@ static switch_status_t do_config()
status = SWITCH_STATUS_FALSE;
goto done;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Connected ODBC DSN: %s\n", globals.odbc_dsn);
if (switch_odbc_handle_exec(globals.master_odbc, "select count(*) from limit_data", NULL) != SWITCH_STATUS_SUCCESS) {
if (switch_odbc_handle_exec(globals.master_odbc, limit_sql, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Create SQL Database!\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Create SQL Database!\n");
}
}
if (switch_odbc_handle_exec(globals.master_odbc, "select count(*) from db_data", NULL) != SWITCH_STATUS_SUCCESS) {
@@ -258,10 +240,10 @@ static switch_status_t do_config()
}
switch_core_db_close(db);
#ifdef SWITCH_HAVE_ODBC
}
}
#endif
done:
done:
sql = switch_mprintf("delete from limit_data where hostname='%q';", globals.hostname);
limit_execute_sql(sql, globals.mutex);
@@ -284,8 +266,8 @@ static switch_status_t hanguphook(switch_core_session_t *session)
if (state == CS_HANGUP || state == CS_ROUTING) {
id = switch_channel_get_variable(channel, "limit_id");
realm = switch_channel_get_variable(channel, "limit_realm");
sql = switch_mprintf("delete from limit_data where uuid='%q' and hostname='%q' and realm='%q'and id='%q';",
switch_core_session_get_uuid(session), globals.hostname, realm, id);
sql = switch_mprintf("delete from limit_data where uuid='%q' and hostname='%q' and realm='%q'and id='%q';",
switch_core_session_get_uuid(session), globals.hostname, realm, id);
limit_execute_sql(sql, globals.mutex);
switch_safe_free(sql);
switch_core_event_hook_remove_state_change(session, hanguphook);
@@ -343,8 +325,10 @@ SWITCH_STANDARD_API(db_api_function)
sql = switch_mprintf("delete from db_data where realm='%q' and data_key='%q'", argv[1], argv[2]);
assert(sql);
limit_execute_sql(sql, NULL);
switch_safe_free(sql);
sql = switch_mprintf("insert into db_data (hostname, realm, data_key, data) values('%q','%q','%q','%q');", globals.hostname, argv[1], argv[2], argv[3]);
switch_safe_free(sql);
sql =
switch_mprintf("insert into db_data (hostname, realm, data_key, data) values('%q','%q','%q','%q');", globals.hostname, argv[1], argv[2],
argv[3]);
assert(sql);
limit_execute_sql(sql, NULL);
switch_safe_free(sql);
@@ -357,7 +341,7 @@ SWITCH_STANDARD_API(db_api_function)
sql = switch_mprintf("delete from db_data where realm='%q' and data_key='%q'", argv[1], argv[2]);
assert(sql);
limit_execute_sql(sql, NULL);
switch_safe_free(sql);
switch_safe_free(sql);
stream->write_function(stream, "+OK");
goto done;
} else if (!strcasecmp(argv[0], "select")) {
@@ -372,18 +356,18 @@ SWITCH_STANDARD_API(db_api_function)
limit_execute_sql_callback(NULL, sql, sql2str_callback, &cbt);
stream->write_function(stream, "%s", buf);
goto done;
}
}
error:
error:
stream->write_function(stream, "!err!");
done:
done:
switch_mutex_unlock(globals.mutex);
switch_safe_free(mydata);
return SWITCH_STATUS_SUCCESS;
}
@@ -411,8 +395,10 @@ SWITCH_STANDARD_APP(db_function)
switch_assert(sql);
limit_execute_sql(sql, globals.mutex);
switch_safe_free(sql);
sql = switch_mprintf("insert into db_data (hostname, realm, data_key, data) values('%q','%q','%q','%q');", globals.hostname, argv[1], argv[2], argv[3]);
sql =
switch_mprintf("insert into db_data (hostname, realm, data_key, data) values('%q','%q','%q','%q');", globals.hostname, argv[1], argv[2],
argv[3]);
} else if (!strcasecmp(argv[0], "delete")) {
sql = switch_mprintf("delete from db_data where realm='%q' and data_key='%q'", argv[1], argv[2]);
}
@@ -422,7 +408,7 @@ SWITCH_STANDARD_APP(db_function)
switch_safe_free(sql);
return;
error:
error:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "USAGE: db %s\n", DB_USAGE);
}
@@ -481,7 +467,7 @@ SWITCH_STANDARD_API(group_api_function)
callback_t cbt = { 0 };
cbt.buf = buf;
cbt.len = sizeof(buf);
if (argc > 2) {
if (!strcasecmp(argv[2], "order")) {
how = "|";
@@ -497,15 +483,15 @@ SWITCH_STANDARD_API(group_api_function)
goto done;
}
error:
error:
stream->write_function(stream, "!err!");
done:
done:
switch_mutex_unlock(globals.mutex);
switch_safe_free(mydata);
return SWITCH_STATUS_SUCCESS;
}
#define GROUP_USAGE "[insert|delete]:<group name>:<val>"
@@ -544,7 +530,7 @@ SWITCH_STANDARD_APP(group_function)
#define LIMIT_USAGE "<realm> <id> <max> [transfer_destination_number]"
#define LIMIT_DESC "limit access to an extension"
static char *limit_def_xfer_exten="limit_exceeded";
static char *limit_def_xfer_exten = "limit_exceeded";
SWITCH_STANDARD_APP(limit_function)
{
@@ -585,7 +571,7 @@ SWITCH_STANDARD_APP(limit_function)
if (max < 0) {
max = 0;
}
switch_channel_set_variable(channel, "limit_realm", realm);
switch_channel_set_variable(channel, "limit_id", id);
switch_channel_set_variable(channel, "limit_max", argv[2]);
@@ -602,11 +588,13 @@ SWITCH_STANDARD_APP(limit_function)
}
switch_core_event_hook_add_state_change(session, hanguphook);
sql = switch_mprintf("insert into limit_data (hostname, realm, id, uuid) values('%q','%q','%q','%q');", globals.hostname, realm, id, switch_core_session_get_uuid(session));
sql =
switch_mprintf("insert into limit_data (hostname, realm, id, uuid) values('%q','%q','%q','%q');", globals.hostname, realm, id,
switch_core_session_get_uuid(session));
limit_execute_sql(sql, NULL);
switch_safe_free(sql);
done:
done:
switch_mutex_unlock(globals.mutex);
}
@@ -626,7 +614,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_limit_load)
}
switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, globals.pool);
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
+17 -15
View File
@@ -91,7 +91,7 @@ static switch_status_t on_dtmf(switch_core_session_t *session, void *input, swit
{
switch (itype) {
case SWITCH_INPUT_TYPE_DTMF:{
switch_dtmf_t *dtmf = (switch_dtmf_t *) input;
switch_dtmf_t *dtmf = (switch_dtmf_t *) input;
struct dtmf_buffer *dtb;
dtb = (struct dtmf_buffer *) buf;
@@ -175,7 +175,8 @@ SWITCH_STANDARD_APP(rss_function)
uint32_t last;
char *mydata = NULL;
char *filename = NULL;
char *argv[3], *feed_list[TTS_MAX_ENTRIES] = { 0 }, *feed_names[TTS_MAX_ENTRIES] = {0};
char *argv[3], *feed_list[TTS_MAX_ENTRIES] = { 0 }, *feed_names[TTS_MAX_ENTRIES] = {
0};
int argc, feed_index = 0;
const char *cf = "rss.conf";
switch_xml_t cfg, cxml, feeds, feed;
@@ -311,12 +312,12 @@ SWITCH_STANDARD_APP(rss_function)
switch_core_speech_flush_tts(&sh);
#ifdef MATCH_COUNT
switch_snprintf(buf + len, sizeof(buf) - len, "%s",
",<break time=\"500ms\"/>Main Menu. <break time=\"600ms\"/> "
"Select one of the following news sources, or press 0 to exit. " ",<break time=\"600ms\"/>");
",<break time=\"500ms\"/>Main Menu. <break time=\"600ms\"/> "
"Select one of the following news sources, or press 0 to exit. " ",<break time=\"600ms\"/>");
#else
switch_snprintf(buf + len, sizeof(buf) - len, "%s",
",<break time=\"500ms\"/>Main Menu. <break time=\"600ms\"/> "
"Select one of the following news sources, followed by the pound key or press 0 to exit. " ",<break time=\"600ms\"/>");
",<break time=\"500ms\"/>Main Menu. <break time=\"600ms\"/> "
"Select one of the following news sources, followed by the pound key or press 0 to exit. " ",<break time=\"600ms\"/>");
#endif
len = (int32_t) strlen(buf);
@@ -482,8 +483,8 @@ SWITCH_STANDARD_APP(rss_function)
switch_snprintf(buf, sizeof(buf),
",<break time=\"500ms\"/>%s. %s. %s. local time: %s, Press 0 for options, 5 to change voice, or pound to return to the main menu. ",
title_txt, description_txt, rights_txt, date);
",<break time=\"500ms\"/>%s. %s. %s. local time: %s, Press 0 for options, 5 to change voice, or pound to return to the main menu. ",
title_txt, description_txt, rights_txt, date);
args.input_callback = NULL;
args.buf = dtmf;
args.buflen = sizeof(dtmf);
@@ -539,7 +540,8 @@ SWITCH_STANDARD_APP(rss_function)
}
if (switch_test_flag(&dtb, SFLAG_INFO)) {
switch_clear_flag(&dtb, SFLAG_INFO);
switch_snprintf(tmpbuf + tmplen, sizeof(tmpbuf) - tmplen, "%s %s. I am speaking at %u words per minute. ", sh.engine, sh.voice, dtb.speed);
switch_snprintf(tmpbuf + tmplen, sizeof(tmpbuf) - tmplen, "%s %s. I am speaking at %u words per minute. ", sh.engine, sh.voice,
dtb.speed);
tmplen = (uint32_t) strlen(tmpbuf);
}
@@ -547,12 +549,12 @@ SWITCH_STANDARD_APP(rss_function)
switch_clear_flag(&dtb, SFLAG_INSTRUCT);
cont = 1;
switch_snprintf(tmpbuf + tmplen, sizeof(tmpbuf) - tmplen, "%s",
"Press star to pause or resume speech. "
"To go to the next item, press six. "
"To go back, press 4. "
"Press two to go faster, eight to slow down, or 7 to resume normal speed. "
"To change voices, press five. To restore the original voice press 9. "
"To hear these options again, press zero or press pound to return to the main menu. ");
"Press star to pause or resume speech. "
"To go to the next item, press six. "
"To go back, press 4. "
"Press two to go faster, eight to slow down, or 7 to resume normal speed. "
"To change voices, press five. To restore the original voice press 9. "
"To hear these options again, press zero or press pound to return to the main menu. ");
} else {
switch_snprintf(tmpbuf + tmplen, sizeof(tmpbuf) - tmplen, "Story %d. ", dtb.index + 1);
tmplen = (uint32_t) strlen(tmpbuf);
+1 -1
View File
@@ -41,7 +41,7 @@ SWITCH_MODULE_DEFINITION(mod_skel, mod_skel_load, NULL, NULL);
SWITCH_MODULE_LOAD_FUNCTION(mod_skel_load)
{
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Hello World!\n");
@@ -43,107 +43,107 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_soundtouch_load);
SWITCH_MODULE_DEFINITION(mod_soundtouch, mod_soundtouch_load, NULL, NULL);
struct soundtouch_helper {
SoundTouch *st;
switch_core_session_t *session;
int send;
int read;
float pitch;
float octaves;
float semi;
float rate;
float tempo;
int literal;
SoundTouch *st;
switch_core_session_t *session;
int send;
int read;
float pitch;
float octaves;
float semi;
float rate;
float tempo;
int literal;
};
static switch_status_t on_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf, switch_dtmf_direction_t direction)
{
switch_media_bug_t *bug;
switch_channel_t *channel = switch_core_session_get_channel(session);
if ((bug = (switch_media_bug_t *) switch_channel_get_private(channel, "_soundtouch_"))) {
struct soundtouch_helper *sth = (struct soundtouch_helper *) switch_core_media_bug_get_user_data(bug);
if (sth) {
if (sth->literal) {
sth->literal = 0;
return SWITCH_STATUS_SUCCESS;
}
switch_media_bug_t *bug;
switch_channel_t *channel = switch_core_session_get_channel(session);
switch(dtmf->digit) {
case '*':
sth->literal++;
break;
case '3':
sth->semi += .5;
sth->st->setPitchSemiTones(sth->semi);
sth->st->flush();
break;
case '2':
sth->semi = 0;
sth->st->setPitchSemiTones(sth->semi);
sth->st->flush();
break;
case '1':
sth->semi -= .5;
sth->st->setPitchSemiTones(sth->semi);
sth->st->flush();
break;
if ((bug = (switch_media_bug_t *) switch_channel_get_private(channel, "_soundtouch_"))) {
struct soundtouch_helper *sth = (struct soundtouch_helper *) switch_core_media_bug_get_user_data(bug);
case '6':
sth->pitch += .2;
sth->st->setPitch(sth->pitch);
sth->st->flush();
break;
case '5':
sth->pitch = 1;
sth->st->setPitch(sth->pitch);
sth->st->flush();
break;
case '4':
sth->pitch -= .2;
if (sth->pitch <= 0) {
sth->pitch = .2;
}
sth->st->setPitch(sth->pitch);
sth->st->flush();
break;
case '9':
sth->octaves += .2;
sth->st->setPitchOctaves(sth->octaves);
sth->st->flush();
break;
case '8':
sth->octaves = 0;
sth->st->setPitchOctaves(sth->octaves);
sth->st->flush();
break;
case '7':
sth->octaves -= .2;
sth->st->setPitchOctaves(sth->octaves);
sth->st->flush();
break;
if (sth) {
if (sth->literal) {
sth->literal = 0;
return SWITCH_STATUS_SUCCESS;
}
case '0':
sth->octaves = 0;
sth->st->setPitchOctaves(sth->octaves);
sth->pitch = 1;
sth->st->setPitch(sth->pitch);
sth->semi = 0;
sth->st->setPitchSemiTones(sth->semi);
sth->st->flush();
}
switch (dtmf->digit) {
case '*':
sth->literal++;
break;
case '3':
sth->semi += .5;
sth->st->setPitchSemiTones(sth->semi);
sth->st->flush();
break;
case '2':
sth->semi = 0;
sth->st->setPitchSemiTones(sth->semi);
sth->st->flush();
break;
case '1':
sth->semi -= .5;
sth->st->setPitchSemiTones(sth->semi);
sth->st->flush();
break;
}
case '6':
sth->pitch += .2;
sth->st->setPitch(sth->pitch);
sth->st->flush();
break;
case '5':
sth->pitch = 1;
sth->st->setPitch(sth->pitch);
sth->st->flush();
break;
case '4':
sth->pitch -= .2;
if (sth->pitch <= 0) {
sth->pitch = .2;
}
sth->st->setPitch(sth->pitch);
sth->st->flush();
break;
return SWITCH_STATUS_FALSE;
}
return SWITCH_STATUS_SUCCESS;
case '9':
sth->octaves += .2;
sth->st->setPitchOctaves(sth->octaves);
sth->st->flush();
break;
case '8':
sth->octaves = 0;
sth->st->setPitchOctaves(sth->octaves);
sth->st->flush();
break;
case '7':
sth->octaves -= .2;
sth->st->setPitchOctaves(sth->octaves);
sth->st->flush();
break;
case '0':
sth->octaves = 0;
sth->st->setPitchOctaves(sth->octaves);
sth->pitch = 1;
sth->st->setPitch(sth->pitch);
sth->semi = 0;
sth->st->setPitchSemiTones(sth->semi);
sth->st->flush();
}
}
return SWITCH_STATUS_FALSE;
}
return SWITCH_STATUS_SUCCESS;
}
@@ -153,85 +153,85 @@ static switch_bool_t soundtouch_callback(switch_media_bug_t *bug, void *user_dat
switch (type) {
case SWITCH_ABC_TYPE_INIT:
{
switch_codec_t *read_codec = switch_core_session_get_read_codec(sth->session);
sth->st = new SoundTouch();
sth->st->setSampleRate(read_codec->implementation->samples_per_second);
sth->st->setChannels(read_codec->implementation->number_of_channels);
sth->st->setSetting(SETTING_USE_QUICKSEEK, 1);
sth->st->setSetting(SETTING_USE_AA_FILTER, 1);
{
switch_codec_t *read_codec = switch_core_session_get_read_codec(sth->session);
sth->st = new SoundTouch();
sth->st->setSampleRate(read_codec->implementation->samples_per_second);
sth->st->setChannels(read_codec->implementation->number_of_channels);
if (sth->semi) {
sth->st->setPitchSemiTones(sth->semi);
}
sth->st->setSetting(SETTING_USE_QUICKSEEK, 1);
sth->st->setSetting(SETTING_USE_AA_FILTER, 1);
if (sth->pitch) {
sth->st->setPitch(sth->pitch);
}
if (sth->semi) {
sth->st->setPitchSemiTones(sth->semi);
}
if (sth->octaves) {
sth->st->setPitchOctaves(sth->octaves);
}
if (sth->pitch) {
sth->st->setPitch(sth->pitch);
}
if (sth->rate) {
sth->st->setRate(sth->rate);
}
if (sth->octaves) {
sth->st->setPitchOctaves(sth->octaves);
}
if (sth->tempo) {
sth->st->setRate(sth->tempo);
}
if (sth->send) {
switch_core_event_hook_add_send_dtmf(sth->session, on_dtmf);
} else {
switch_core_event_hook_add_recv_dtmf(sth->session, on_dtmf);
}
}
break;
if (sth->rate) {
sth->st->setRate(sth->rate);
}
if (sth->tempo) {
sth->st->setRate(sth->tempo);
}
if (sth->send) {
switch_core_event_hook_add_send_dtmf(sth->session, on_dtmf);
} else {
switch_core_event_hook_add_recv_dtmf(sth->session, on_dtmf);
}
}
break;
case SWITCH_ABC_TYPE_CLOSE:
{
delete sth->st;
if (sth->send) {
switch_core_event_hook_remove_send_dtmf(sth->session, on_dtmf);
} else {
switch_core_event_hook_remove_recv_dtmf(sth->session, on_dtmf);
}
}
{
delete sth->st;
if (sth->send) {
switch_core_event_hook_remove_send_dtmf(sth->session, on_dtmf);
} else {
switch_core_event_hook_remove_recv_dtmf(sth->session, on_dtmf);
}
}
break;
case SWITCH_ABC_TYPE_READ:
case SWITCH_ABC_TYPE_WRITE:
break;
break;
case SWITCH_ABC_TYPE_READ_REPLACE:
case SWITCH_ABC_TYPE_WRITE_REPLACE:
{
switch_frame_t *frame;
assert(sth != NULL);
assert(sth->st != NULL);
{
switch_frame_t *frame;
if (sth->read) {
frame = switch_core_media_bug_get_read_replace_frame(bug);
} else {
frame = switch_core_media_bug_get_write_replace_frame(bug);
}
assert(sth != NULL);
assert(sth->st != NULL);
sth->st->putSamples((SAMPLETYPE *)frame->data, frame->samples);
if (sth->read) {
frame = switch_core_media_bug_get_read_replace_frame(bug);
} else {
frame = switch_core_media_bug_get_write_replace_frame(bug);
}
if (sth->st->numSamples() >= frame->samples * 2) {
frame->samples = sth->st->receiveSamples((SAMPLETYPE *)frame->data, frame->samples);
frame->datalen = frame->samples * 2;
} else {
memset(frame->data, 0, frame->datalen);
}
sth->st->putSamples((SAMPLETYPE *) frame->data, frame->samples);
if (sth->read) {
switch_core_media_bug_set_read_replace_frame(bug, frame);
} else {
switch_core_media_bug_set_write_replace_frame(bug, frame);
}
}
if (sth->st->numSamples() >= frame->samples * 2) {
frame->samples = sth->st->receiveSamples((SAMPLETYPE *) frame->data, frame->samples);
frame->datalen = frame->samples * 2;
} else {
memset(frame->data, 0, frame->datalen);
}
if (sth->read) {
switch_core_media_bug_set_read_replace_frame(bug, frame);
} else {
switch_core_media_bug_set_write_replace_frame(bug, frame);
}
}
default:
break;
}
@@ -241,68 +241,68 @@ static switch_bool_t soundtouch_callback(switch_media_bug_t *bug, void *user_dat
SWITCH_STANDARD_APP(soundtouch_start_function)
{
switch_media_bug_t *bug;
switch_status_t status;
switch_channel_t *channel = switch_core_session_get_channel(session);
struct soundtouch_helper *sth;
char *argv[6];
switch_media_bug_t *bug;
switch_status_t status;
switch_channel_t *channel = switch_core_session_get_channel(session);
struct soundtouch_helper *sth;
char *argv[6];
int argc;
char *lbuf = NULL;
int x;
if ((bug = (switch_media_bug_t *) switch_channel_get_private(channel, "_soundtouch_"))) {
if (!switch_strlen_zero(data) && !strcasecmp(data, "stop")) {
switch_channel_set_private(channel, "_soundtouch_", NULL);
switch_core_media_bug_remove(session, &bug);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cannot run 2 at once on the same channel!\n");
}
return;
}
int x;
sth = (struct soundtouch_helper *) switch_core_session_alloc(session, sizeof(*sth));
assert(sth != NULL);
if ((bug = (switch_media_bug_t *) switch_channel_get_private(channel, "_soundtouch_"))) {
if (!switch_strlen_zero(data) && !strcasecmp(data, "stop")) {
switch_channel_set_private(channel, "_soundtouch_", NULL);
switch_core_media_bug_remove(session, &bug);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cannot run 2 at once on the same channel!\n");
}
return;
}
sth = (struct soundtouch_helper *) switch_core_session_alloc(session, sizeof(*sth));
assert(sth != NULL);
if (data && (lbuf = switch_core_session_strdup(session, data))
&& (argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
sth->send = 0;
sth->read = 0;
sth->pitch = 1;
for(x = 0; x < argc; x++) {
if (!strncasecmp(argv[x], "send", 4)) {
sth->send = 1;
} else if (!strncasecmp(argv[x], "read", 4)) {
sth->read = 1;
} else if (strchr(argv[x], 'p')) {
if ((sth->pitch = atof(argv[x]) < 0)) {
sth->pitch = 0;
}
} else if (strchr(argv[x], 'r')) {
sth->rate = atof(argv[x]);
} else if (strchr(argv[x], 'o')) {
sth->octaves = atof(argv[x]);
} else if (strchr(argv[x], 's')) {
sth->semi = atof(argv[x]);
} else if (strchr(argv[x], 't')) {
if ((sth->tempo = atof(argv[x]) < 0)) {
sth->tempo = 0;
}
}
}
}
sth->send = 0;
sth->read = 0;
sth->pitch = 1;
for (x = 0; x < argc; x++) {
if (!strncasecmp(argv[x], "send", 4)) {
sth->send = 1;
} else if (!strncasecmp(argv[x], "read", 4)) {
sth->read = 1;
} else if (strchr(argv[x], 'p')) {
if ((sth->pitch = atof(argv[x]) < 0)) {
sth->pitch = 0;
}
} else if (strchr(argv[x], 'r')) {
sth->rate = atof(argv[x]);
} else if (strchr(argv[x], 'o')) {
sth->octaves = atof(argv[x]);
} else if (strchr(argv[x], 's')) {
sth->semi = atof(argv[x]);
} else if (strchr(argv[x], 't')) {
if ((sth->tempo = atof(argv[x]) < 0)) {
sth->tempo = 0;
}
}
}
}
sth->session = session;
if ((status = switch_core_media_bug_add(session, soundtouch_callback, sth, 0,
sth->read ? SMBF_READ_REPLACE : SMBF_WRITE_REPLACE, &bug)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failure!\n");
sth->session = session;
if ((status = switch_core_media_bug_add(session, soundtouch_callback, sth, 0,
sth->read ? SMBF_READ_REPLACE : SMBF_WRITE_REPLACE, &bug)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failure!\n");
return;
}
switch_channel_set_private(channel, "_soundtouch_", bug);
}
static switch_application_interface_t soundtouch_application_interface = {
/*.interface_name */ "soundtouch",
@@ -311,8 +311,8 @@ static switch_application_interface_t soundtouch_application_interface = {
/* short_desc */ "Alter the audio stream",
/* syntax */ "[send|recv] [-]<X>s [.]<X>p",
/* flags */ SAF_NONE,
/* next*/
/* next */
};
static switch_loadable_module_interface_t soundtouch_module_interface = {
File diff suppressed because it is too large. Load diff
+1 -1
View File
@@ -257,7 +257,7 @@ static void cepstral_speech_flush_tts(switch_speech_handle_t *sh)
swift_port_stop(cepstral->port, SWIFT_ASYNC_ANY, SWIFT_EVENT_NOW);
}
static switch_status_t cepstral_speech_read_tts(switch_speech_handle_t *sh, void *data, size_t *datalen, uint32_t * rate, switch_speech_flag_t *flags)
static switch_status_t cepstral_speech_read_tts(switch_speech_handle_t *sh, void *data, size_t *datalen, uint32_t *rate, switch_speech_flag_t *flags)
{
cepstral_t *cepstral;
size_t desired = *datalen;
+99 -107
View File
@@ -56,7 +56,7 @@ typedef struct {
switch_mutex_t *flag_mutex;
} lumenvox_t;
static void log_callback(const char* message, void* userdata)
static void log_callback(const char *message, void *userdata)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s\n", message);
}
@@ -72,50 +72,47 @@ static const char *state_names[] = {
"BEEP"
};
std::ostream& operator << (std::ostream& os ,const LVSemanticData& Data)
std::ostream & operator <<(std::ostream & os, const LVSemanticData & Data)
{
int i;
LVSemanticObject Obj;
switch (Data.Type())
{
case SI_TYPE_BOOL:
os << Data.GetBool();
break;
case SI_TYPE_INT:
os << Data.GetInt();
break;
case SI_TYPE_DOUBLE:
os << Data.GetDouble();
break;
case SI_TYPE_STRING:
os << Data.GetString();
break;
case SI_TYPE_OBJECT:
Obj = Data.GetSemanticObject();
for (i = 0; i < Obj.NumberOfProperties(); ++i)
{
os << "<" << Obj.PropertyName(i) << ">";
os << Obj.PropertyValue(i);
os << "</" << Obj.PropertyName(i) << ">";
}
break;
case SI_TYPE_ARRAY:
for (i = 0; i < Data.GetSemanticArray().Size(); ++i)
{
os << Data.GetArray().At(i);
}
break;
switch (Data.Type()) {
case SI_TYPE_BOOL:
os << Data.GetBool();
break;
case SI_TYPE_INT:
os << Data.GetInt();
break;
case SI_TYPE_DOUBLE:
os << Data.GetDouble();
break;
case SI_TYPE_STRING:
os << Data.GetString();
break;
case SI_TYPE_OBJECT:
Obj = Data.GetSemanticObject();
for (i = 0; i < Obj.NumberOfProperties(); ++i) {
os << "<" << Obj.PropertyName(i) << ">";
os << Obj.PropertyValue(i);
os << "</" << Obj.PropertyName(i) << ">";
}
break;
case SI_TYPE_ARRAY:
for (i = 0; i < Data.GetSemanticArray().Size(); ++i) {
os << Data.GetArray().At(i);
}
break;
}
return os;
}
//==============================================================================================
// code to plug LVInterpretation into any standard stream
std::ostream& operator << (std::ostream& os, const LVInterpretation& Interp)
std::ostream & operator <<(std::ostream & os, const LVInterpretation & Interp)
{
os << "<interpretation grammar=\""<<Interp.GrammarLabel()
<<"\" score=\""<<Interp.Score()<<"\">";
os << "<result name=\""<<Interp.ResultName()<<"\">";
os << "<interpretation grammar=\"" << Interp.GrammarLabel()
<< "\" score=\"" << Interp.Score() << "\">";
os << "<result name=\"" << Interp.ResultName() << "\">";
os << Interp.ResultData();
os << "</result>";
os << "<input>";
@@ -126,30 +123,26 @@ std::ostream& operator << (std::ostream& os, const LVInterpretation& Interp)
}
static void state_change_callback(long new_state, unsigned long total_bytes,
unsigned long recorded_bytes, void *user_data)
static void state_change_callback(long new_state, unsigned long total_bytes, unsigned long recorded_bytes, void *user_data)
{
lumenvox_t *lv = (lumenvox_t *) user_data;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "State: [%s] total bytes: [%ld] recorded bytes: [%ld]\n",
state_names[new_state],
total_bytes,
recorded_bytes);
switch (new_state)
{
case STREAM_STATUS_READY:
break;
case STREAM_STATUS_STOPPED:
switch_clear_flag_locked(lv, LVFLAG_READY);
break;
case STREAM_STATUS_END_SPEECH:
switch_set_flag_locked(lv, LVFLAG_HAS_TEXT);
break;
case STREAM_STATUS_BARGE_IN:
switch_set_flag_locked(lv, LVFLAG_BARGE);
break;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "State: [%s] total bytes: [%ld] recorded bytes: [%ld]\n",
state_names[new_state], total_bytes, recorded_bytes);
switch (new_state) {
case STREAM_STATUS_READY:
break;
case STREAM_STATUS_STOPPED:
switch_clear_flag_locked(lv, LVFLAG_READY);
break;
case STREAM_STATUS_END_SPEECH:
switch_set_flag_locked(lv, LVFLAG_HAS_TEXT);
break;
case STREAM_STATUS_BARGE_IN:
switch_set_flag_locked(lv, LVFLAG_BARGE);
break;
}
}
static switch_status_t lumenvox_asr_pause(switch_asr_handle_t *ah)
@@ -177,20 +170,20 @@ static switch_status_t lumenvox_asr_resume(switch_asr_handle_t *ah)
lv->port.ClosePort();
return SWITCH_STATUS_GENERR;
}
switch_set_flag_locked(lv, LVFLAG_READY);
switch_set_flag_locked(lv, LVFLAG_READY);
return SWITCH_STATUS_SUCCESS;
}
return SWITCH_STATUS_GENERR;
}
/*! function to open the asr interface */
static switch_status_t lumenvox_asr_open(switch_asr_handle_t *ah, char *codec, int rate, char *dest, switch_asr_flag_t *flags)
static switch_status_t lumenvox_asr_open(switch_asr_handle_t *ah, char *codec, int rate, char *dest, switch_asr_flag_t *flags)
{
lumenvox_t *lv;
int error_code;
if (!(lv = (lumenvox_t *) switch_core_alloc(ah->memory_pool, sizeof(*lv)))) {
return SWITCH_STATUS_MEMERR;
}
@@ -199,7 +192,7 @@ static switch_status_t lumenvox_asr_open(switch_asr_handle_t *ah, char *codec, i
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Rate: Pick 8000 or 16000\n");
return SWITCH_STATUS_FALSE;
}
if (!strcasecmp(codec, "PCMU")) {
switch (rate) {
case 8000:
@@ -238,36 +231,35 @@ static switch_status_t lumenvox_asr_open(switch_asr_handle_t *ah, char *codec, i
if (!lv->sound_format) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot negotiate sound format.\n");
return SWITCH_STATUS_FALSE;
}
}
ah->rate = rate;
ah->codec = switch_core_strdup(ah->memory_pool, codec);
lv->port.OpenPort(log_callback, NULL, 5);
error_code = lv->port.GetOpenPortStatus();
switch(error_code)
{
case LV_FAILURE:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Licenses Exceeded!\n");
return SWITCH_STATUS_GENERR;
case LV_OPEN_PORT_FAILED__PRIMARY_SERVER_NOT_RESPONDING:
case LV_NO_SERVER_RESPONDING:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SRE Server Unavailable!\n");
return SWITCH_STATUS_GENERR;
case LV_SUCCESS:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Port Opened %d %dkhz.\n", lv->sound_format, rate);
break;
}
switch (error_code) {
case LV_FAILURE:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Licenses Exceeded!\n");
return SWITCH_STATUS_GENERR;
case LV_OPEN_PORT_FAILED__PRIMARY_SERVER_NOT_RESPONDING:
case LV_NO_SERVER_RESPONDING:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SRE Server Unavailable!\n");
return SWITCH_STATUS_GENERR;
case LV_SUCCESS:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Port Opened %d %dkhz.\n", lv->sound_format, rate);
break;
}
// turn on sound and response file logging
/*
int save_sound_files = 1;
lv->port.SetPropertyEx(PROP_EX_SAVE_SOUND_FILES,
PROP_EX_VALUE_TYPE_INT_PTR,
&save_sound_files);
*/
int save_sound_files = 1;
lv->port.SetPropertyEx(PROP_EX_SAVE_SOUND_FILES,
PROP_EX_VALUE_TYPE_INT_PTR,
&save_sound_files);
*/
lv->channel = 1;
lv->flags = *flags;
lv->port.StreamSetParameter(STREAM_PARM_DETECT_BARGE_IN, 1);
@@ -275,9 +267,9 @@ static switch_status_t lumenvox_asr_open(switch_asr_handle_t *ah, char *codec, i
lv->port.StreamSetParameter(STREAM_PARM_AUTO_DECODE, 1);
lv->port.StreamSetParameter(STREAM_PARM_DECODE_FLAGS, LV_DECODE_SEMANTIC_INTERPRETATION);
lv->port.StreamSetParameter(STREAM_PARM_VOICE_CHANNEL, lv->channel);
lv->port.StreamSetParameter(STREAM_PARM_GRAMMAR_SET, (long unsigned int) LV_ACTIVE_GRAMMAR_SET);
lv->port.StreamSetParameter(STREAM_PARM_GRAMMAR_SET, (long unsigned int) LV_ACTIVE_GRAMMAR_SET);
lv->port.StreamSetStateChangeCallBack(state_change_callback, lv);
lv->port.StreamSetParameter(STREAM_PARM_SOUND_FORMAT, lv->sound_format);
@@ -292,7 +284,7 @@ static switch_status_t lumenvox_asr_open(switch_asr_handle_t *ah, char *codec, i
lv->port.ClosePort();
return SWITCH_STATUS_GENERR;
}
ah->private_info = lv;
return SWITCH_STATUS_SUCCESS;
@@ -347,13 +339,13 @@ static switch_status_t lumenvox_asr_feed(switch_asr_handle_t *ah, void *data, un
{
lumenvox_t *lv = (lumenvox_t *) ah->private_info;
if (!switch_test_flag(lv, LVFLAG_HAS_TEXT) && switch_test_flag(lv, LVFLAG_READY)) {
if (lv->port.StreamSendData(data, len)) {
return SWITCH_STATUS_FALSE;
return SWITCH_STATUS_FALSE;
}
}
return SWITCH_STATUS_SUCCESS;
}
@@ -384,21 +376,21 @@ static switch_status_t lumenvox_asr_get_results(switch_asr_handle_t *ah, char **
lv->port.StreamStop();
code = lv->port.WaitForEngineToIdle(3000, lv->channel);
if (code == LV_TIME_OUT) {
return SWITCH_STATUS_FALSE;
}
numInterp = lv->port.GetNumberOfInterpretations(lv->channel);
for (int t = 0; t < numInterp; ++t) {
ss << lv->port.GetInterpretation(lv->channel, t);
}
*xmlstr = strdup((char *)ss.str().c_str());
*xmlstr = strdup((char *) ss.str().c_str());
switch_clear_flag_locked(lv, LVFLAG_HAS_TEXT);
if (switch_test_flag(lv, SWITCH_ASR_FLAG_AUTO_RESUME)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Auto Resuming\n");
switch_set_flag_locked(lv, LVFLAG_READY);
@@ -410,21 +402,21 @@ static switch_status_t lumenvox_asr_get_results(switch_asr_handle_t *ah, char **
ret = SWITCH_STATUS_SUCCESS;
}
return ret;
}
static const switch_asr_interface_t lumenvox_asr_interface = {
/*.interface_name*/ "lumenvox",
/*.asr_open*/ lumenvox_asr_open,
/*.asr_load_grammar*/ lumenvox_asr_load_grammar,
/*.asr_unload_grammar*/ lumenvox_asr_unload_grammar,
/*.asr_close*/ lumenvox_asr_close,
/*.asr_feed*/ lumenvox_asr_feed,
/*.asr_resume*/ lumenvox_asr_resume,
/*.asr_pause*/ lumenvox_asr_pause,
/*.asr_check_results*/ lumenvox_asr_check_results,
/*.asr_get_results*/ lumenvox_asr_get_results
/*.interface_name */ "lumenvox",
/*.asr_open */ lumenvox_asr_open,
/*.asr_load_grammar */ lumenvox_asr_load_grammar,
/*.asr_unload_grammar */ lumenvox_asr_unload_grammar,
/*.asr_close */ lumenvox_asr_close,
/*.asr_feed */ lumenvox_asr_feed,
/*.asr_resume */ lumenvox_asr_resume,
/*.asr_pause */ lumenvox_asr_pause,
/*.asr_check_results */ lumenvox_asr_check_results,
/*.asr_get_results */ lumenvox_asr_get_results
};
static const switch_loadable_module_interface_t lumenvox_module_interface = {
@@ -447,7 +439,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_lumenvox_load)
{
LVSpeechPort::RegisterAppLogMsg(log_callback, NULL, 5);
//LVSpeechPort::SetClientPropertyEx(PROP_EX_SRE_SERVERS, PROP_EX_VALUE_TYPE_STRING, (void *)"127.0.0.1");
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &lumenvox_module_interface;
+103 -125
View File
@@ -66,40 +66,39 @@
#include "mrcp_synthesizer.h"
#include "mrcp_generic_header.h"
SWITCH_MODULE_LOAD_FUNCTION(mod_openmrcp_load);
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_openmrcp_shutdown);
SWITCH_MODULE_DEFINITION(mod_openmrcp, mod_openmrcp_load,
mod_openmrcp_shutdown, NULL);
SWITCH_MODULE_DEFINITION(mod_openmrcp, mod_openmrcp_load, mod_openmrcp_shutdown, NULL);
typedef struct {
char *name;
char *name;
openmrcp_client_options_t *mrcp_options;
mrcp_client_t *mrcp_client;
mrcp_client_context_t *mrcp_context;
mrcp_client_t *mrcp_client;
mrcp_client_context_t *mrcp_context;
} openmrcp_profile_t;
typedef struct {
openmrcp_profile_t *profile;
mrcp_session_t *client_session;
openmrcp_profile_t *profile;
mrcp_session_t *client_session;
mrcp_client_channel_t *control_channel;
mrcp_audio_channel_t *audio_channel;
mrcp_message_t *mrcp_message_last_rcvd;
apr_pool_t *pool;
switch_speech_flag_t flags;
switch_mutex_t *flag_mutex;
switch_thread_cond_t *wait_object;
mrcp_audio_channel_t *audio_channel;
mrcp_message_t *mrcp_message_last_rcvd;
apr_pool_t *pool;
switch_speech_flag_t flags;
switch_mutex_t *flag_mutex;
switch_thread_cond_t *wait_object;
} openmrcp_session_t;
typedef enum {
FLAG_HAS_MESSAGE = (1 << 0),
FLAG_FEED_STARTED = (1 << 1),
FLAG_TERMINATING = (1 << 2)
FLAG_HAS_MESSAGE = (1 << 0),
FLAG_FEED_STARTED = (1 << 1),
FLAG_TERMINATING = (1 << 2)
} mrcp_flag_t;
typedef struct {
switch_memory_pool_t *pool;
switch_hash_t *profile_hash;
switch_hash_t *profile_hash;
char *asr_profile_name;
char *tts_profile_name;
//openmrcp_profile_t *asr_profile;
@@ -109,7 +108,7 @@ typedef struct {
static openmrcp_module_t openmrcp_module;
static switch_status_t openmrcp_profile_run(openmrcp_profile_t *profile);
static openmrcp_session_t* openmrcp_session_create(openmrcp_profile_t *profile)
static openmrcp_session_t *openmrcp_session_create(openmrcp_profile_t *profile)
{
openmrcp_session_t *openmrcp_session;
apr_pool_t *session_pool;
@@ -172,14 +171,14 @@ static mrcp_status_t openmrcp_on_session_terminate(mrcp_client_context_t *contex
if (switch_test_flag(openmrcp_session, FLAG_TERMINATING)) {
openmrcp_session_destroy(openmrcp_session);
}
else {
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "abnormal session terminate\n");
}
return MRCP_STATUS_SUCCESS;
}
static mrcp_status_t openmrcp_on_channel_add(mrcp_client_context_t *context, mrcp_session_t *session, mrcp_client_channel_t *control_channel, mrcp_audio_channel_t *audio_channel)
static mrcp_status_t openmrcp_on_channel_add(mrcp_client_context_t *context, mrcp_session_t *session, mrcp_client_channel_t *control_channel,
mrcp_audio_channel_t *audio_channel)
{
openmrcp_session_t *openmrcp_session = mrcp_client_context_session_object_get(session);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "on_channel_add called\n");
@@ -242,8 +241,9 @@ static mrcp_status_t openmrcp_recog_start(mrcp_client_context_t *context, openmr
apr_finfo_t finfo;
char *buf1;
apr_size_t bytes2read = 0;
mrcp_message_t *mrcp_message = mrcp_client_context_message_get(context, asr_session->client_session, asr_session->control_channel, RECOGNIZER_RECOGNIZE);
mrcp_message_t *mrcp_message =
mrcp_client_context_message_get(context, asr_session->client_session, asr_session->control_channel, RECOGNIZER_RECOGNIZE);
if (!mrcp_message) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not create mrcp msg\n");
@@ -257,9 +257,9 @@ static mrcp_status_t openmrcp_recog_start(mrcp_client_context_t *context, openmr
return -1;
}
rv = apr_file_info_get(&finfo, APR_FINFO_NORM, fp);
buf1 = apr_palloc(mp, (apr_size_t)finfo.size + 1);
bytes2read = (apr_size_t)finfo.size;
buf1 = apr_palloc(mp, (apr_size_t) finfo.size + 1);
bytes2read = (apr_size_t) finfo.size;
rv = apr_file_read(fp, buf1, &bytes2read);
buf1[bytes2read] = '\0';
@@ -286,27 +286,23 @@ static mrcp_status_t openmrcp_recog_start(mrcp_client_context_t *context, openmr
* This code expects certain one-time initialization of the openmrcp client
* engine/systeme to have already taken place.function to open the asr interface
*/
static switch_status_t openmrcp_asr_open(switch_asr_handle_t *ah,
const char *codec,
int rate,
const char *dest,
switch_asr_flag_t *flags)
static switch_status_t openmrcp_asr_open(switch_asr_handle_t *ah, const char *codec, int rate, const char *dest, switch_asr_flag_t *flags)
{
openmrcp_session_t *asr_session;
mrcp_client_channel_t *asr_channel;
char *profile_name = openmrcp_module.asr_profile_name;
openmrcp_profile_t *asr_profile = NULL;
openmrcp_profile_t *asr_profile = NULL;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "asr_open called, codec: %s, rate: %d\n", codec, rate);
if (strcmp(codec, "L16")) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Sorry, only L16 codec supported\n");
return SWITCH_STATUS_GENERR;
return SWITCH_STATUS_GENERR;
}
if (rate != 8000) {
// TODO: look into supporting other sample rates
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Sorry, only 8kz supported\n");
return SWITCH_STATUS_GENERR;
return SWITCH_STATUS_GENERR;
}
if (!switch_strlen_zero(ah->param)) {
@@ -315,7 +311,7 @@ static switch_status_t openmrcp_asr_open(switch_asr_handle_t *ah,
if (!(asr_profile = switch_core_hash_find(openmrcp_module.profile_hash, profile_name))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot locate profile %s\n", profile_name);
return SWITCH_STATUS_GENERR;
return SWITCH_STATUS_GENERR;
}
/* create session */
@@ -336,7 +332,7 @@ static switch_status_t openmrcp_asr_open(switch_asr_handle_t *ah,
switch_mutex_lock(asr_session->flag_mutex);
mrcp_client_context_channel_add(asr_session->profile->mrcp_context, asr_session->client_session, asr_channel, NULL);
if (switch_thread_cond_timedwait(asr_session->wait_object, asr_session->flag_mutex, 5000*1000) != APR_SUCCESS) {
if (switch_thread_cond_timedwait(asr_session->wait_object, asr_session->flag_mutex, 5000 * 1000) != APR_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No response from client stack\n");
}
switch_mutex_unlock(asr_session->flag_mutex);
@@ -358,15 +354,15 @@ static switch_status_t openmrcp_asr_load_grammar(switch_asr_handle_t *ah, const
TODO: - how does DEFINE-GRAMMAR fit into the picture here? (if at all)
*/
openmrcp_session_t *asr_session = (openmrcp_session_t *) ah->private_info;
mrcp_client_context_t *context = asr_session->profile->mrcp_context;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Loading grammar\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Start Recognizer\n");
openmrcp_recog_start(context, asr_session, path);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Finished loading grammar\n");
return SWITCH_STATUS_SUCCESS;
}
@@ -387,22 +383,22 @@ static switch_status_t openmrcp_asr_feed(switch_asr_handle_t *ah, void *data, un
/* sampling rate and frame size should be retrieved from audio sink */
media_frame.codec_frame.size = 160;
media_frame.codec_frame.buffer = data;
while(len >= media_frame.codec_frame.size) {
while (len >= media_frame.codec_frame.size) {
if (!audio_sink) {
/*!
If there is no audio_sink established yet, discard the audio and
return SUCCESS. returning anything other than success causes freeswitch
to abort the call and tear down the channel. One reason there might
not be an audio sink is that the openmrcp client lib is still in the startup
process.
*/
If there is no audio_sink established yet, discard the audio and
return SUCCESS. returning anything other than success causes freeswitch
to abort the call and tear down the channel. One reason there might
not be an audio sink is that the openmrcp client lib is still in the startup
process.
*/
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "!audio_sink\n");
return SWITCH_STATUS_SUCCESS;
return SWITCH_STATUS_SUCCESS;
}
audio_sink->method_set->write_frame(audio_sink, &media_frame);
len -= (unsigned int)media_frame.codec_frame.size;
media_frame.codec_frame.buffer = (char*)media_frame.codec_frame.buffer + media_frame.codec_frame.size;
len -= (unsigned int) media_frame.codec_frame.size;
media_frame.codec_frame.buffer = (char *) media_frame.codec_frame.buffer + media_frame.codec_frame.size;
}
if (len > 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "None frame alligned data len [%d]\n", len);
@@ -452,9 +448,9 @@ static switch_status_t openmrcp_asr_close(switch_asr_handle_t *ah, switch_asr_fl
// terminate client session
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Going to TERMINATE SESSION\n");
switch_set_flag_locked(asr_session, FLAG_TERMINATING);
switch_set_flag_locked(asr_session, FLAG_TERMINATING);
mrcp_client_context_session_terminate(context, asr_session->client_session);
switch_set_flag(ah, SWITCH_ASR_FLAG_CLOSED);
return SWITCH_STATUS_SUCCESS;
@@ -470,7 +466,7 @@ static switch_status_t openmrcp_asr_close(switch_asr_handle_t *ah, switch_asr_fl
static switch_status_t openmrcp_asr_check_results(switch_asr_handle_t *ah, switch_asr_flag_t *flags)
{
openmrcp_session_t *asr_session = (openmrcp_session_t *) ah->private_info;
switch_status_t rv = (switch_test_flag(asr_session, FLAG_HAS_MESSAGE)) ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
return rv;
@@ -491,49 +487,44 @@ static switch_status_t openmrcp_asr_get_results(switch_asr_handle_t *ah, char **
switch_clear_flag_locked(asr_session, FLAG_HAS_MESSAGE);
if (message->start_line.message_type == MRCP_MESSAGE_TYPE_RESPONSE) {
if (message->start_line.status_code != MRCP_STATUS_CODE_SUCCESS &&
message->start_line.status_code != MRCP_STATUS_CODE_SUCCESS_WITH_IGNORE) {
if (message->start_line.status_code != MRCP_STATUS_CODE_SUCCESS && message->start_line.status_code != MRCP_STATUS_CODE_SUCCESS_WITH_IGNORE) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "error code received [%d]\n", message->start_line.status_code);
ret = SWITCH_STATUS_FALSE;
}
}
else if (message->start_line.message_type == MRCP_MESSAGE_TYPE_EVENT) {
} else if (message->start_line.message_type == MRCP_MESSAGE_TYPE_EVENT) {
if (message->start_line.method_id == RECOGNIZER_RECOGNITION_COMPLETE) {
/*!
we have to extract the XML but stripping off the <?xml version="1.0"?>
header. the body looks like:
Completion-Cause:001 no-match
Content-Type: application/nlsml+xml
Content-Length: 260
<?xml version="1.0"?>
<result xmlns="http://www.ietf.org/xml/ns/mrcpv2" xmlns:ex="http://www.example.com/example" score="100" grammar="session:request1@form-level.store">
<interpretation> <input mode="speech">open a</input>
</interpretation>
</result>
*/
<?xml version="1.0"?>
<result xmlns="http://www.ietf.org/xml/ns/mrcpv2" xmlns:ex="http://www.example.com/example" score="100" grammar="session:request1@form-level.store">
<interpretation> <input mode="speech">open a</input>
</interpretation>
</result>
*/
if (message->body) {
char *marker = "?>"; // FIXME -- lame and brittle way of doing this. use regex or better.
char *marker = "?>"; // FIXME -- lame and brittle way of doing this. use regex or better.
char *position = strstr(message->body, marker);
if (!position) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Bad result received from mrcp server: %s", message->body);
ret = SWITCH_STATUS_FALSE;
}
else {
} else {
position += strlen(marker);
*xmlstr = strdup(position);
}
}
else {
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No result received from mrcp server\n");
ret = SWITCH_STATUS_FALSE;
}
ret = SWITCH_STATUS_SUCCESS;
}
else if (message->start_line.method_id == RECOGNIZER_START_OF_INPUT) {
ret = SWITCH_STATUS_SUCCESS;
} else if (message->start_line.method_id == RECOGNIZER_START_OF_INPUT) {
ret = SWITCH_STATUS_BREAK;
}
}
@@ -546,23 +537,17 @@ static mrcp_status_t synth_speak(mrcp_client_context_t *context, openmrcp_sessio
mrcp_generic_header_t *generic_header;
mrcp_message_t *mrcp_message;
mrcp_status_t status = MRCP_STATUS_FAILURE;
char *text2speak;
const char v2_xml_head[] =
"<?xml version=\"1.0\"?>\r\n"
"<speak>\r\n"
"<paragraph>\r\n"
" <sentence><break time=\"1000ms\"/>";
const char v2_xml_head[] = "<?xml version=\"1.0\"?>\r\n" "<speak>\r\n" "<paragraph>\r\n" " <sentence><break time=\"1000ms\"/>";
const char v2_xml_tail[] = "<break time=\"1000ms\"/></sentence>\r\n"
"</paragraph>\r\n"
"</speak>\r\n";
const char v2_xml_tail[] = "<break time=\"1000ms\"/></sentence>\r\n" "</paragraph>\r\n" "</speak>\r\n";
const char v1_xml_head[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<speak version=\"1.0\" xmlns=\"http://www.w3.org/2001/10/synthesis\">\n<break time=\"1000ms\"/>";
const char v1_xml_head[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<speak version=\"1.0\" xmlns=\"http://www.w3.org/2001/10/synthesis\">\n<break time=\"1000ms\"/>";
const char v1_xml_tail[] = "<break time=\"1000ms\"/>\n</speak>\n";
const char v1_xml_tail[] = "<break time=\"1000ms\"/>\n</speak>\n";
const char *xml_head, *xml_tail;
@@ -592,7 +577,7 @@ static mrcp_status_t synth_speak(mrcp_client_context_t *context, openmrcp_sessio
status = mrcp_client_context_channel_modify(context, tts_session->client_session, mrcp_message);
end:
end:
return status;
@@ -609,12 +594,12 @@ static mrcp_status_t synth_stop(mrcp_client_context_t *context, openmrcp_session
}
static switch_status_t openmrcp_tts_open(switch_speech_handle_t *sh, const char *voice_name, int rate, switch_speech_flag_t *flags)
static switch_status_t openmrcp_tts_open(switch_speech_handle_t *sh, const char *voice_name, int rate, switch_speech_flag_t *flags)
{
openmrcp_session_t *tts_session;
mrcp_client_channel_t *tts_channel;
char *profile_name = openmrcp_module.tts_profile_name;
openmrcp_profile_t *tts_profile = NULL;
openmrcp_profile_t *tts_profile = NULL;
if (!switch_strlen_zero(sh->param)) {
profile_name = sh->param;
@@ -622,7 +607,7 @@ static switch_status_t openmrcp_tts_open(switch_speech_handle_t *sh, const char
if (!(tts_profile = switch_core_hash_find(openmrcp_module.profile_hash, profile_name))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot locate profile %s\n", profile_name);
return SWITCH_STATUS_GENERR;
return SWITCH_STATUS_GENERR;
}
/* create session */
@@ -642,7 +627,7 @@ static switch_status_t openmrcp_tts_open(switch_speech_handle_t *sh, const char
}
switch_mutex_lock(tts_session->flag_mutex);
mrcp_client_context_channel_add(tts_session->profile->mrcp_context, tts_session->client_session, tts_channel, NULL);
if (switch_thread_cond_timedwait(tts_session->wait_object, tts_session->flag_mutex, 5000*1000) != APR_SUCCESS) {
if (switch_thread_cond_timedwait(tts_session->wait_object, tts_session->flag_mutex, 5000 * 1000) != APR_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No response from client stack\n");
}
switch_mutex_unlock(tts_session->flag_mutex);
@@ -665,7 +650,7 @@ static switch_status_t openmrcp_tts_close(switch_speech_handle_t *sh, switch_spe
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "terminate tts_session\n");
switch_set_flag_locked(tts_session, FLAG_TERMINATING);
mrcp_client_context_session_terminate(context, tts_session->client_session);
return SWITCH_STATUS_SUCCESS;
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t openmrcp_feed_tts(switch_speech_handle_t *sh, char *text, switch_speech_flag_t *flags)
@@ -677,11 +662,11 @@ static switch_status_t openmrcp_feed_tts(switch_speech_handle_t *sh, char *text,
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "no synthesizer channel too feed tts\n");
return SWITCH_STATUS_FALSE;
}
synth_speak(context, tts_session, text);
synth_speak(context, tts_session, text);
switch_clear_flag(tts_session, FLAG_FEED_STARTED);
return SWITCH_STATUS_SUCCESS;
return SWITCH_STATUS_SUCCESS;
}
/**
@@ -693,7 +678,7 @@ static switch_status_t openmrcp_feed_tts(switch_speech_handle_t *sh, char *text,
static switch_status_t openmrcp_read_tts(switch_speech_handle_t *sh, void *data, size_t *datalen, uint32_t *rate, switch_speech_flag_t *flags)
{
openmrcp_session_t *tts_session = (openmrcp_session_t *) sh->private_info;
size_t return_len=0;
size_t return_len = 0;
media_frame_t media_frame;
audio_source_t *audio_source;
@@ -703,13 +688,11 @@ static switch_status_t openmrcp_read_tts(switch_speech_handle_t *sh, void *data,
switch_clear_flag_locked(tts_session, FLAG_HAS_MESSAGE);
if (message->start_line.message_type == MRCP_MESSAGE_TYPE_RESPONSE) {
if (message->start_line.status_code != MRCP_STATUS_CODE_SUCCESS &&
message->start_line.status_code != MRCP_STATUS_CODE_SUCCESS_WITH_IGNORE) {
if (message->start_line.status_code != MRCP_STATUS_CODE_SUCCESS && message->start_line.status_code != MRCP_STATUS_CODE_SUCCESS_WITH_IGNORE) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "error code received [%d]\n", message->start_line.status_code);
return SWITCH_STATUS_BREAK;
}
}
else if (message->start_line.message_type == MRCP_MESSAGE_TYPE_EVENT) {
} else if (message->start_line.message_type == MRCP_MESSAGE_TYPE_EVENT) {
if (message->start_line.method_id == SYNTHESIZER_SPEAK_COMPLETE) {
/* tell fs we are done */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "FLAG_SPEAK_COMPLETE\n");
@@ -724,7 +707,7 @@ static switch_status_t openmrcp_read_tts(switch_speech_handle_t *sh, void *data,
}
if (!switch_test_flag(tts_session, FLAG_FEED_STARTED)) {
switch_set_flag(tts_session, FLAG_FEED_STARTED); // shouldn't this use set_flag_locked? -tl
switch_set_flag(tts_session, FLAG_FEED_STARTED); // shouldn't this use set_flag_locked? -tl
if (audio_source->method_set->open) {
audio_source->method_set->open(audio_source);
}
@@ -733,8 +716,8 @@ static switch_status_t openmrcp_read_tts(switch_speech_handle_t *sh, void *data,
/* sampling rate and frame size should be retrieved from audio source */
*rate = 8000;
media_frame.codec_frame.size = 160;
while(return_len < *datalen) {
media_frame.codec_frame.buffer = (char*)data + return_len;
while (return_len < *datalen) {
media_frame.codec_frame.buffer = (char *) data + return_len;
audio_source->method_set->read_frame(audio_source, &media_frame);
if (media_frame.type != MEDIA_FRAME_TYPE_AUDIO) {
memset(media_frame.codec_frame.buffer, 0, media_frame.codec_frame.size);
@@ -742,7 +725,7 @@ static switch_status_t openmrcp_read_tts(switch_speech_handle_t *sh, void *data,
return_len += media_frame.codec_frame.size;
}
*datalen = return_len;
return SWITCH_STATUS_SUCCESS;
return SWITCH_STATUS_SUCCESS;
}
@@ -752,7 +735,7 @@ static void openmrcp_flush_tts(switch_speech_handle_t *sh)
mrcp_client_context_t *context = tts_session->profile->mrcp_context;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "flush_tts called\n");
synth_stop(context, tts_session); // TODO
synth_stop(context, tts_session); // TODO
}
static void openmrcp_text_param_tts(switch_speech_handle_t *sh, char *param, const char *val)
@@ -797,8 +780,7 @@ static switch_status_t do_config()
apt_log_priority_set(atoi(val));
}
}
}
else {
} else {
goto error;
}
if ((profiles = switch_xml_child(cfg, "profiles"))) {
@@ -818,9 +800,8 @@ static switch_status_t do_config()
const char *val = switch_xml_attr_soft(param, "value");
if (!strcasecmp(var, "proto_version")) {
mrcp_options->proto_version =(mrcp_version_t) atoi(val);
}
else if (!strcasecmp(var, "client_ip")) {
mrcp_options->proto_version = (mrcp_version_t) atoi(val);
} else if (!strcasecmp(var, "client_ip")) {
mrcp_options->client_ip = switch_core_strdup(openmrcp_module.pool, val);
} else if (!strcasecmp(var, "server_ip")) {
mrcp_options->server_ip = switch_core_strdup(openmrcp_module.pool, val);
@@ -835,27 +816,24 @@ static switch_status_t do_config()
}
}
mrcp_profile->mrcp_options = mrcp_options;
/* add profile */
if (!switch_core_hash_find(openmrcp_module.profile_hash, mrcp_profile->name)) {
if (openmrcp_profile_run(mrcp_profile) == SWITCH_STATUS_SUCCESS) {
switch_core_hash_insert(openmrcp_module.profile_hash, mrcp_profile->name, mrcp_profile);
}
}
else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
"profile with the name [%s] already exists\n", mrcp_profile->name);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "profile with the name [%s] already exists\n", mrcp_profile->name);
}
}
}
else {
} else {
goto error;
}
switch_xml_free(xml);
return SWITCH_STATUS_SUCCESS;
error:
error:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to load module configuration\n");
switch_xml_free(xml);
return SWITCH_STATUS_TERM;
@@ -867,10 +845,10 @@ static switch_status_t openmrcp_profile_run(openmrcp_profile_t *profile)
mrcp_client_event_handler_t *mrcp_event_handler;
mrcp_client_t *mrcp_client;
mrcp_client_context_t *mrcp_context;
/*!
Perform one-time initialization of mrcp client library
*/
Perform one-time initialization of mrcp client library
*/
mrcp_event_handler = switch_core_alloc(openmrcp_module.pool, sizeof(mrcp_client_event_handler_t));
mrcp_event_handler->on_session_initiate = openmrcp_on_session_initiate;
mrcp_event_handler->on_session_terminate = openmrcp_on_session_terminate;
@@ -902,7 +880,7 @@ static switch_status_t openmrcp_profile_run(openmrcp_profile_t *profile)
static switch_status_t openmrcp_init()
{
/* one-time mrcp global initialization */
if(apr_pool_create(&openmrcp_module.pool,NULL) != APR_SUCCESS) {
if (apr_pool_create(&openmrcp_module.pool, NULL) != APR_SUCCESS) {
return SWITCH_STATUS_FALSE;
}
@@ -931,7 +909,7 @@ static switch_status_t openmrcp_destroy()
/* shutdown client engine */
openmrcp_client_shutdown(mrcp_profile->mrcp_client);
/* destroy client context */
mrcp_client_context_destroy(mrcp_profile->mrcp_context);
mrcp_client_context_destroy(mrcp_profile->mrcp_context);
}
switch_core_hash_destroy(&openmrcp_module.profile_hash);
openmrcp_module.profile_hash = NULL;
@@ -973,7 +951,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_openmrcp_load)
/* initialize openmrcp */
if (openmrcp_init() != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_FALSE;
return SWITCH_STATUS_FALSE;
}
/* indicate that the module should continue to be loaded */
+9 -11
View File
@@ -139,8 +139,8 @@ static switch_status_t switch_amr_init(switch_codec_t *codec, switch_codec_flag_
if (!(encoding || decoding) || (!(context = switch_core_alloc(codec->memory_pool, sizeof(struct amr_context))))) {
return SWITCH_STATUS_FALSE;
} else {
} else {
context->dtx_mode = AMR_DTX_ENABLED;
if (codec->fmtp_in) {
argc = switch_separate_string(codec->fmtp_in, ';', argv, (sizeof(argv) / sizeof(argv[0])));
@@ -207,7 +207,8 @@ static switch_status_t switch_amr_init(switch_codec_t *codec, switch_codec_flag_
context->enc_mode = globals.default_bitrate;
}
switch_snprintf(fmtptmp, sizeof(fmtptmp), "octet-align=%d; mode-set=%d", switch_test_flag(context, AMR_OPT_OCTET_ALIGN) ? 1 : 0, context->enc_mode);
switch_snprintf(fmtptmp, sizeof(fmtptmp), "octet-align=%d; mode-set=%d", switch_test_flag(context, AMR_OPT_OCTET_ALIGN) ? 1 : 0,
context->enc_mode);
codec->fmtp_out = switch_core_strdup(codec->memory_pool, fmtptmp);
context->enc_mode = AMR_DEFAULT_BITRATE;
@@ -249,8 +250,7 @@ static switch_status_t switch_amr_encode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *decoded_data,
uint32_t decoded_data_len,
uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate,
unsigned int *flag)
uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate, unsigned int *flag)
{
#ifdef AMR_PASSTHROUGH
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "This codec is only usable in passthrough mode!\n");
@@ -272,8 +272,7 @@ static switch_status_t switch_amr_decode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *encoded_data,
uint32_t encoded_data_len,
uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate,
unsigned int *flag)
uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate, unsigned int *flag)
{
#ifdef AMR_PASSTHROUGH
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "This codec is only usable in passthrough mode!\n");
@@ -320,10 +319,9 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_amr_load)
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
SWITCH_ADD_CODEC(codec_interface, "AMR");
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 96, "AMR", "octet-align=0", 8000, 8000, 12200,
20000, 160, 320, 0, 1, 1, 1,
switch_amr_init, switch_amr_encode, switch_amr_decode, switch_amr_destroy);
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 96, "AMR", "octet-align=0", 8000, 8000, 12200,
20000, 160, 320, 0, 1, 1, 1, switch_amr_init, switch_amr_encode, switch_amr_decode, switch_amr_destroy);
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
+9 -9
View File
@@ -110,7 +110,7 @@ static switch_status_t switch_g723_encode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *decoded_data,
uint32_t decoded_data_len,
uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate,
uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate,
unsigned int *flag)
{
#ifdef G723_PASSTHROUGH
@@ -141,7 +141,7 @@ static switch_status_t switch_g723_decode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *encoded_data,
uint32_t encoded_data_len,
uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate,
uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate,
unsigned int *flag)
{
#ifdef G723_PASSTHROUGH
@@ -170,16 +170,16 @@ static switch_status_t switch_g723_decode(switch_codec_t *codec,
SWITCH_MODULE_LOAD_FUNCTION(mod_g723_1_load)
{
switch_codec_interface_t *codec_interface;
int mpf = 30000, spf = 240, bpf = 480, ebpf = 24, count;
int mpf = 30000, spf = 240, bpf = 480, ebpf = 24, count;
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
SWITCH_ADD_CODEC(codec_interface, "G.723.1 6.3k");
for (count = 1; count > 0; count--) {
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 4, "G723", NULL, 8000, 8000, 6300,
mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 4,
switch_g723_init, switch_g723_encode, switch_g723_decode, switch_g723_destroy);
}
for (count = 1; count > 0; count--) {
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 4, "G723", NULL, 8000, 8000, 6300,
mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 4,
switch_g723_init, switch_g723_encode, switch_g723_decode, switch_g723_destroy);
}
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
+10 -10
View File
@@ -95,7 +95,7 @@ static switch_status_t switch_g729_encode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *decoded_data,
uint32_t decoded_data_len,
uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate,
uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate,
unsigned int *flag)
{
#ifdef G729_PASSTHROUGH
@@ -138,7 +138,7 @@ static switch_status_t switch_g729_decode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *encoded_data,
uint32_t encoded_data_len,
uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate,
uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate,
unsigned int *flag)
{
#ifdef G729_PASSTHROUGH
@@ -154,7 +154,7 @@ static switch_status_t switch_g729_decode(switch_codec_t *codec,
}
if (encoded_data_len % 2 == 0) {
if (encoded_data_len == 2 || encoded_data_len % 12 == 0) {
return SWITCH_STATUS_BREAK;
//divisor = 12;
@@ -209,18 +209,18 @@ static switch_status_t switch_g729_decode(switch_codec_t *codec,
SWITCH_MODULE_LOAD_FUNCTION(mod_g729_load)
{
switch_codec_interface_t *codec_interface;
int mpf = 10000, spf = 80, bpf = 160, ebpf = 10, count;
int mpf = 10000, spf = 80, bpf = 160, ebpf = 10, count;
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
SWITCH_ADD_CODEC(codec_interface, "G.729");
for (count = 12; count > 0; count--) {
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 18, "G729", NULL, 8000, 8000, 8000,
mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
switch_g729_init, switch_g729_encode, switch_g729_decode, switch_g729_destroy);
}
for (count = 12; count > 0; count--) {
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 18, "G729", NULL, 8000, 8000, 8000,
mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
switch_g729_init, switch_g729_encode, switch_g729_decode, switch_g729_destroy);
}
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
+26 -31
View File
@@ -45,7 +45,7 @@ static switch_status_t switch_h26x_init(switch_codec_t *codec, switch_codec_flag
if (!(encoding || decoding)) {
return SWITCH_STATUS_FALSE;
} else {
if (codec->fmtp_in) {
if (codec->fmtp_in) {
codec->fmtp_out = switch_core_strdup(codec->memory_pool, codec->fmtp_in);
}
return SWITCH_STATUS_SUCCESS;
@@ -53,21 +53,21 @@ static switch_status_t switch_h26x_init(switch_codec_t *codec, switch_codec_flag
}
static switch_status_t switch_h26x_encode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *decoded_data,
uint32_t decoded_data_len,
uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate,
unsigned int *flag)
switch_codec_t *other_codec,
void *decoded_data,
uint32_t decoded_data_len,
uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate,
unsigned int *flag)
{
return SWITCH_STATUS_FALSE;
}
static switch_status_t switch_h26x_decode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *encoded_data,
uint32_t encoded_data_len,
uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate,
unsigned int *flag)
switch_codec_t *other_codec,
void *encoded_data,
uint32_t encoded_data_len,
uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate,
unsigned int *flag)
{
return SWITCH_STATUS_FALSE;
}
@@ -83,30 +83,25 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_h26x_load)
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
SWITCH_ADD_CODEC(codec_interface, "H.264 Video (passthru)");
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_VIDEO, 99, "H264", NULL, 90000, 90000, 0,
0, 0, 0, 0, 1, 1, 1,
switch_h26x_init, switch_h26x_encode, switch_h26x_decode, switch_h26x_destroy);
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_VIDEO, 99, "H264", NULL, 90000, 90000, 0,
0, 0, 0, 0, 1, 1, 1, switch_h26x_init, switch_h26x_encode, switch_h26x_decode, switch_h26x_destroy);
SWITCH_ADD_CODEC(codec_interface, "H.263 Video (passthru)");
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_VIDEO, 34, "H263", NULL, 90000, 90000, 0,
0, 0, 0, 0, 1, 1, 1,
switch_h26x_init, switch_h26x_encode, switch_h26x_decode, switch_h26x_destroy);
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_VIDEO, 34, "H263", NULL, 90000, 90000, 0,
0, 0, 0, 0, 1, 1, 1, switch_h26x_init, switch_h26x_encode, switch_h26x_decode, switch_h26x_destroy);
SWITCH_ADD_CODEC(codec_interface, "H.263+ Video (passthru)");
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_VIDEO, 115, "H263-1998", NULL, 90000, 90000, 0,
0, 0, 0, 0, 1, 1, 1,
switch_h26x_init, switch_h26x_encode, switch_h26x_decode, switch_h26x_destroy);
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_VIDEO, 115, "H263-1998", NULL, 90000, 90000, 0,
0, 0, 0, 0, 1, 1, 1, switch_h26x_init, switch_h26x_encode, switch_h26x_decode, switch_h26x_destroy);
SWITCH_ADD_CODEC(codec_interface, "H.263++ Video (passthru)");
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_VIDEO, 121, "H263-2000", NULL, 90000, 90000, 0,
0, 0, 0, 0, 1, 1, 1,
switch_h26x_init, switch_h26x_encode, switch_h26x_decode, switch_h26x_destroy);
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_VIDEO, 121, "H263-2000", NULL, 90000, 90000, 0,
0, 0, 0, 0, 1, 1, 1, switch_h26x_init, switch_h26x_encode, switch_h26x_decode, switch_h26x_destroy);
SWITCH_ADD_CODEC(codec_interface, "H.261 Video (passthru)");
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_VIDEO, 31, "H261", NULL, 90000, 90000, 0,
0, 0, 0, 0, 1, 1, 1,
switch_h26x_init, switch_h26x_encode, switch_h26x_decode, switch_h26x_destroy);
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_VIDEO, 31, "H261", NULL, 90000, 90000, 0,
0, 0, 0, 0, 1, 1, 1, switch_h26x_init, switch_h26x_encode, switch_h26x_decode, switch_h26x_destroy);
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
+27 -27
View File
@@ -97,7 +97,7 @@ static switch_status_t switch_ilbc_encode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *decoded_data,
uint32_t decoded_data_len,
uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate,
uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate,
unsigned int *flag)
{
struct ilbc_context *context = codec->private_info;
@@ -137,7 +137,7 @@ static switch_status_t switch_ilbc_decode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *encoded_data,
uint32_t encoded_data_len,
uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate,
uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate,
unsigned int *flag)
{
struct ilbc_context *context = codec->private_info;
@@ -187,31 +187,31 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_ilbc_load)
SWITCH_ADD_CODEC(codec_interface, "iLBC");
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 97, "iLBC", "mode=20", 8000, 8000, NO_OF_BYTES_20MS * 8 * 8000 / BLOCKL_20MS,
20000, 160, 320, NO_OF_BYTES_20MS, 1, 1, 1,
switch_ilbc_init, switch_ilbc_encode, switch_ilbc_decode, switch_ilbc_destroy);
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 102, "iLBC", "mode=20", 8000, 8000, NO_OF_BYTES_20MS * 8 * 8000 / BLOCKL_20MS,
20000, 160, 320, NO_OF_BYTES_20MS, 1, 1, 1,
switch_ilbc_init, switch_ilbc_encode, switch_ilbc_decode, switch_ilbc_destroy);
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 102, "iLBC102", "mode=20", 8000, 8000, NO_OF_BYTES_20MS * 8 * 8000 / BLOCKL_20MS,
20000, 160, 320, NO_OF_BYTES_20MS, 1, 1, 1,
switch_ilbc_init, switch_ilbc_encode, switch_ilbc_decode, switch_ilbc_destroy);
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 102, "iLBC20ms", "mode=20", 8000, 8000, NO_OF_BYTES_20MS * 8 * 8000 / BLOCKL_20MS,
20000, 160, 320, NO_OF_BYTES_20MS, 1, 1, 1,
switch_ilbc_init, switch_ilbc_encode, switch_ilbc_decode, switch_ilbc_destroy);
/* 30ms variants */
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 98, "iLBC", "mode=30", 8000, 8000, NO_OF_BYTES_30MS * 8 * 8000 / BLOCKL_30MS,
30000, 240, 480, NO_OF_BYTES_30MS, 1, 1, 1,
switch_ilbc_init, switch_ilbc_encode, switch_ilbc_decode, switch_ilbc_destroy);
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 102, "iLBC", "mode=30", 8000, 8000, NO_OF_BYTES_30MS * 8 * 8000 / BLOCKL_30MS,
30000, 240, 480, NO_OF_BYTES_30MS, 1, 1, 1,
switch_ilbc_init, switch_ilbc_encode, switch_ilbc_decode, switch_ilbc_destroy);
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 97, "iLBC", "mode=20", 8000, 8000, NO_OF_BYTES_20MS * 8 * 8000 / BLOCKL_20MS,
20000, 160, 320, NO_OF_BYTES_20MS, 1, 1, 1,
switch_ilbc_init, switch_ilbc_encode, switch_ilbc_decode, switch_ilbc_destroy);
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 102, "iLBC", "mode=20", 8000, 8000, NO_OF_BYTES_20MS * 8 * 8000 / BLOCKL_20MS,
20000, 160, 320, NO_OF_BYTES_20MS, 1, 1, 1,
switch_ilbc_init, switch_ilbc_encode, switch_ilbc_decode, switch_ilbc_destroy);
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 102, "iLBC102", "mode=20", 8000, 8000, NO_OF_BYTES_20MS * 8 * 8000 / BLOCKL_20MS,
20000, 160, 320, NO_OF_BYTES_20MS, 1, 1, 1,
switch_ilbc_init, switch_ilbc_encode, switch_ilbc_decode, switch_ilbc_destroy);
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 102, "iLBC20ms", "mode=20", 8000, 8000, NO_OF_BYTES_20MS * 8 * 8000 / BLOCKL_20MS,
20000, 160, 320, NO_OF_BYTES_20MS, 1, 1, 1,
switch_ilbc_init, switch_ilbc_encode, switch_ilbc_decode, switch_ilbc_destroy);
/* 30ms variants */
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 98, "iLBC", "mode=30", 8000, 8000, NO_OF_BYTES_30MS * 8 * 8000 / BLOCKL_30MS,
30000, 240, 480, NO_OF_BYTES_30MS, 1, 1, 1,
switch_ilbc_init, switch_ilbc_encode, switch_ilbc_decode, switch_ilbc_destroy);
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 102, "iLBC", "mode=30", 8000, 8000, NO_OF_BYTES_30MS * 8 * 8000 / BLOCKL_30MS,
30000, 240, 480, NO_OF_BYTES_30MS, 1, 1, 1,
switch_ilbc_init, switch_ilbc_encode, switch_ilbc_decode, switch_ilbc_destroy);
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
+17 -17
View File
@@ -159,7 +159,7 @@ static switch_status_t switch_speex_encode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *decoded_data,
uint32_t decoded_data_len,
uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate,
uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate,
unsigned int *flag)
{
struct speex_context *context = codec->private_info;
@@ -211,7 +211,7 @@ static switch_status_t switch_speex_decode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *encoded_data,
uint32_t encoded_data_len,
uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate,
uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate,
unsigned int *flag)
{
struct speex_context *context = codec->private_info;
@@ -264,24 +264,24 @@ static switch_status_t switch_speex_destroy(switch_codec_t *codec)
SWITCH_MODULE_LOAD_FUNCTION(mod_speex_load)
{
switch_codec_interface_t *codec_interface;
int mpf = 20000, spf = 160, bpf = 320, ebpf = 0, rate = 8000, counta, countb;
switch_payload_t ianacode[4] = { 0, 98, 99, 103};
int bps[4] = { 0, 24600, 42200, 44000 };
int mpf = 20000, spf = 160, bpf = 320, ebpf = 0, rate = 8000, counta, countb;
switch_payload_t ianacode[4] = { 0, 98, 99, 103 };
int bps[4] = { 0, 24600, 42200, 44000 };
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
SWITCH_ADD_CODEC(codec_interface, "Speex");
for (counta = 1; counta <= 3; counta++) {
for (countb = 1; countb > 0; countb--) {
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, ianacode[counta], "SPEEX", NULL, rate, rate, bps[counta],
mpf * countb, spf * countb, bpf * countb, ebpf * countb, 1, 1, 6,
switch_speex_init, switch_speex_encode, switch_speex_decode, switch_speex_destroy);
}
rate = rate * 2;
spf = spf * 2;
bpf = bpf * 2;
ebpf = ebpf * 2;
}
for (counta = 1; counta <= 3; counta++) {
for (countb = 1; countb > 0; countb--) {
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, ianacode[counta], "SPEEX", NULL, rate, rate, bps[counta],
mpf * countb, spf * countb, bpf * countb, ebpf * countb, 1, 1, 6,
switch_speex_init, switch_speex_encode, switch_speex_decode, switch_speex_destroy);
}
rate = rate * 2;
spf = spf * 2;
bpf = bpf * 2;
ebpf = ebpf * 2;
}
+120 -122
View File
@@ -81,7 +81,7 @@ static switch_status_t switch_lpc10_encode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *decoded_data,
uint32_t decoded_data_len,
uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate,
uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate,
unsigned int *flag)
{
struct lpc10_context *context = codec->private_info;
@@ -99,7 +99,7 @@ static switch_status_t switch_lpc10_decode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *encoded_data,
uint32_t encoded_data_len,
uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate,
uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate,
unsigned int *flag)
{
struct lpc10_context *context = codec->private_info;
@@ -138,8 +138,8 @@ static switch_status_t switch_gsm_init(switch_codec_t *codec, switch_codec_flag_
}
if (decoding) {
gsm0610_init(&context->decoder_object, GSM0610_PACKING_VOIP);
}
}
codec->private_info = context;
return SWITCH_STATUS_SUCCESS;
}
@@ -149,8 +149,7 @@ static switch_status_t switch_gsm_encode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *decoded_data,
uint32_t decoded_data_len,
uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate,
unsigned int *flag)
uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate, unsigned int *flag)
{
struct gsm_context *context = codec->private_info;
@@ -167,8 +166,7 @@ static switch_status_t switch_gsm_decode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *encoded_data,
uint32_t encoded_data_len,
uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate,
unsigned int *flag)
uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate, unsigned int *flag)
{
struct gsm_context *context = codec->private_info;
@@ -187,6 +185,7 @@ static switch_status_t switch_gsm_destroy(switch_codec_t *codec)
codec->private_info = NULL;
return SWITCH_STATUS_SUCCESS;
}
/* GSM - END */
#ifdef ENABLE_G711
@@ -209,7 +208,7 @@ static switch_status_t switch_g711u_encode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *decoded_data,
uint32_t decoded_data_len,
uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate,
uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate,
unsigned int *flag)
{
short *dbuf;
@@ -232,7 +231,7 @@ static switch_status_t switch_g711u_decode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *encoded_data,
uint32_t encoded_data_len,
uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate,
uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate,
unsigned int *flag)
{
short *dbuf;
@@ -280,7 +279,7 @@ static switch_status_t switch_g711a_encode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *decoded_data,
uint32_t decoded_data_len,
uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate,
uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate,
unsigned int *flag)
{
short *dbuf;
@@ -303,7 +302,7 @@ static switch_status_t switch_g711a_decode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *encoded_data,
uint32_t encoded_data_len,
uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate,
uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate,
unsigned int *flag)
{
short *dbuf;
@@ -370,7 +369,7 @@ static switch_status_t switch_g722_encode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *decoded_data,
uint32_t decoded_data_len,
uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate,
uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate,
unsigned int *flag)
{
struct g722_context *context = codec->private_info;
@@ -388,7 +387,7 @@ static switch_status_t switch_g722_decode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *encoded_data,
uint32_t encoded_data_len,
uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate,
uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate,
unsigned int *flag)
{
struct g722_context *context = codec->private_info;
@@ -416,8 +415,8 @@ static switch_status_t switch_g722_destroy(switch_codec_t *codec)
static switch_status_t switch_g726_init(switch_codec_t *codec, switch_codec_flag_t flags, const switch_codec_settings_t *codec_settings)
{
uint32_t encoding, decoding;
int packing = G726_PACKING_RIGHT;
g726_state_t *context;
int packing = G726_PACKING_RIGHT;
g726_state_t *context;
encoding = (flags & SWITCH_CODEC_FLAG_ENCODE);
decoding = (flags & SWITCH_CODEC_FLAG_DECODE);
@@ -426,10 +425,10 @@ static switch_status_t switch_g726_init(switch_codec_t *codec, switch_codec_flag
return SWITCH_STATUS_FALSE;
} else {
if ((flags & SWITCH_CODEC_FLAG_AAL2 || strstr(codec->implementation->iananame, "AAL2"))) {
packing = G726_PACKING_LEFT;
}
packing = G726_PACKING_LEFT;
}
g726_init(context, codec->implementation->bits_per_second, G726_ENCODING_LINEAR, packing);
g726_init(context, codec->implementation->bits_per_second, G726_ENCODING_LINEAR, packing);
codec->private_info = context;
return SWITCH_STATUS_SUCCESS;
@@ -446,7 +445,7 @@ static switch_status_t switch_g726_encode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *decoded_data,
uint32_t decoded_data_len,
uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate,
uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate,
unsigned int *flag)
{
g726_state_t *context = codec->private_info;
@@ -455,7 +454,7 @@ static switch_status_t switch_g726_encode(switch_codec_t *codec,
return SWITCH_STATUS_FALSE;
}
*encoded_data_len = g726_encode(context, (uint8_t *) encoded_data, (int16_t *) decoded_data, decoded_data_len / 2);
*encoded_data_len = g726_encode(context, (uint8_t *) encoded_data, (int16_t *) decoded_data, decoded_data_len / 2);
return SWITCH_STATUS_SUCCESS;
}
@@ -464,16 +463,16 @@ static switch_status_t switch_g726_decode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *encoded_data,
uint32_t encoded_data_len,
uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate,
uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate,
unsigned int *flag)
{
g726_state_t *context = codec->private_info;
g726_state_t *context = codec->private_info;
if (!context) {
return SWITCH_STATUS_FALSE;
}
*decoded_data_len = (2 * g726_decode(context, (int16_t *) decoded_data, (uint8_t *) encoded_data, encoded_data_len));
*decoded_data_len = (2 * g726_decode(context, (int16_t *) decoded_data, (uint8_t *) encoded_data, encoded_data_len));
return SWITCH_STATUS_SUCCESS;
}
@@ -503,8 +502,8 @@ static switch_status_t switch_adpcm_init(switch_codec_t *codec, switch_codec_fla
}
if (decoding) {
ima_adpcm_init(&context->decoder_object, IMA_ADPCM_DVI4, 0);
}
}
codec->private_info = context;
return SWITCH_STATUS_SUCCESS;
}
@@ -514,7 +513,7 @@ static switch_status_t switch_adpcm_encode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *decoded_data,
uint32_t decoded_data_len,
uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate,
uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate,
unsigned int *flag)
{
struct ima_adpcm_context *context = codec->private_info;
@@ -532,7 +531,7 @@ static switch_status_t switch_adpcm_decode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *encoded_data,
uint32_t encoded_data_len,
uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate,
uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate,
unsigned int *flag)
{
struct ima_adpcm_context *context = codec->private_info;
@@ -559,7 +558,7 @@ static switch_status_t switch_adpcm_destroy(switch_codec_t *codec)
SWITCH_MODULE_LOAD_FUNCTION(mod_voipcodecs_load)
{
switch_codec_interface_t *codec_interface;
int mpf, spf, bpf, ebpf, count;
int mpf, spf, bpf, ebpf, count;
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
@@ -567,134 +566,133 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_voipcodecs_load)
/* IMA_ADPCM */
mpf = 10000, spf = 80, bpf = 160, ebpf = 80;
SWITCH_ADD_CODEC(codec_interface, "ADPCM (IMA)");
for (count = 12; count > 0; count--) {
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 5, "DVI4", NULL, 8000, 8000, 32000,
mpf * count, spf * count, bpf * count, (ebpf * count) + 4, 1, 1, 12,
switch_adpcm_init, switch_adpcm_encode, switch_adpcm_decode, switch_adpcm_destroy);
}
for (count = 12; count > 0; count--) {
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 5, "DVI4", NULL, 8000, 8000, 32000,
mpf * count, spf * count, bpf * count, (ebpf * count) + 4, 1, 1, 12,
switch_adpcm_init, switch_adpcm_encode, switch_adpcm_decode, switch_adpcm_destroy);
}
mpf = 10000, spf = 160, bpf = 320, ebpf = 160;
for (count = 12; count > 0; count--) {
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 6, "DVI4", NULL, 16000, 16000, 64000,
mpf * count, spf * count, bpf * count, (ebpf * count) + 4, 1, 1, 12,
switch_adpcm_init, switch_adpcm_encode, switch_adpcm_decode, switch_adpcm_destroy);
}
for (count = 12; count > 0; count--) {
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 6, "DVI4", NULL, 16000, 16000, 64000,
mpf * count, spf * count, bpf * count, (ebpf * count) + 4, 1, 1, 12,
switch_adpcm_init, switch_adpcm_encode, switch_adpcm_decode, switch_adpcm_destroy);
}
/* G726 */
mpf = 10000, spf = 80, bpf = 160, ebpf = 20;
SWITCH_ADD_CODEC(codec_interface, "G.726 16k (AAL2)");
for (count = 12; count > 0; count--) {
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 124, "AAL2-G726-16", NULL, 8000, 8000, 16000,
mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
switch_g726_init, switch_g726_encode, switch_g726_decode, switch_g726_destroy);
}
for (count = 12; count > 0; count--) {
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 124, "AAL2-G726-16", NULL, 8000, 8000, 16000,
mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
switch_g726_init, switch_g726_encode, switch_g726_decode, switch_g726_destroy);
}
SWITCH_ADD_CODEC(codec_interface, "G.726 16k");
for (count = 12; count > 0; count--) {
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 127, "G726-16", NULL, 8000, 8000, 16000,
mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
switch_g726_init, switch_g726_encode, switch_g726_decode, switch_g726_destroy);
}
/* Increase encoded bytes per frame by 10 */
ebpf = ebpf + 10;
for (count = 12; count > 0; count--) {
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 127, "G726-16", NULL, 8000, 8000, 16000,
mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
switch_g726_init, switch_g726_encode, switch_g726_decode, switch_g726_destroy);
}
/* Increase encoded bytes per frame by 10 */
ebpf = ebpf + 10;
SWITCH_ADD_CODEC(codec_interface, "G.726 24k (AAL2)");
for (count = 12; count > 0; count--) {
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 123, "AAL2-G726-24", NULL, 8000, 8000, 24000,
mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
switch_g726_init, switch_g726_encode, switch_g726_decode, switch_g726_destroy);
}
for (count = 12; count > 0; count--) {
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 123, "AAL2-G726-24", NULL, 8000, 8000, 24000,
mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
switch_g726_init, switch_g726_encode, switch_g726_decode, switch_g726_destroy);
}
SWITCH_ADD_CODEC(codec_interface, "G.726 24k");
for (count = 12; count > 0; count--) {
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 126, "G726-24", NULL, 8000, 8000, 24000,
mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
switch_g726_init, switch_g726_encode, switch_g726_decode, switch_g726_destroy);
}
/* Increase encoded bytes per frame by 10 */
ebpf = ebpf + 10;
for (count = 12; count > 0; count--) {
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 126, "G726-24", NULL, 8000, 8000, 24000,
mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
switch_g726_init, switch_g726_encode, switch_g726_decode, switch_g726_destroy);
}
/* Increase encoded bytes per frame by 10 */
ebpf = ebpf + 10;
SWITCH_ADD_CODEC(codec_interface, "G.726 32k (AAL2)");
for (count = 12; count > 0; count--) {
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 2, "AAL2-G726-32", NULL, 8000, 8000, 32000,
mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
switch_g726_init, switch_g726_encode, switch_g726_decode, switch_g726_destroy);
}
for (count = 12; count > 0; count--) {
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 2, "AAL2-G726-32", NULL, 8000, 8000, 32000,
mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
switch_g726_init, switch_g726_encode, switch_g726_decode, switch_g726_destroy);
}
SWITCH_ADD_CODEC(codec_interface, "G.726 32k");
for (count = 12; count > 0; count--) {
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 2, "G726-32", NULL, 8000, 8000, 32000,
mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
switch_g726_init, switch_g726_encode, switch_g726_decode, switch_g726_destroy);
}
/* Increase encoded bytes per frame by 10 */
ebpf = ebpf + 10;
for (count = 12; count > 0; count--) {
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 2, "G726-32", NULL, 8000, 8000, 32000,
mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
switch_g726_init, switch_g726_encode, switch_g726_decode, switch_g726_destroy);
}
/* Increase encoded bytes per frame by 10 */
ebpf = ebpf + 10;
SWITCH_ADD_CODEC(codec_interface, "G.726 40k (AAL2)");
for (count = 12; count > 0; count--) {
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 122, "AAL2-G726-40", NULL, 8000, 8000, 40000,
mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
switch_g726_init, switch_g726_encode, switch_g726_decode, switch_g726_destroy);
}
for (count = 12; count > 0; count--) {
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 122, "AAL2-G726-40", NULL, 8000, 8000, 40000,
mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
switch_g726_init, switch_g726_encode, switch_g726_decode, switch_g726_destroy);
}
SWITCH_ADD_CODEC(codec_interface, "G.726 40k");
for (count = 12; count > 0; count--) {
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 125, "G726-40", NULL, 8000, 8000, 40000,
mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
switch_g726_init, switch_g726_encode, switch_g726_decode, switch_g726_destroy);
}
for (count = 12; count > 0; count--) {
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 125, "G726-40", NULL, 8000, 8000, 40000,
mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
switch_g726_init, switch_g726_encode, switch_g726_decode, switch_g726_destroy);
}
/* G722 */
mpf = 10000, spf = 80, bpf = 320, ebpf = 80;
SWITCH_ADD_CODEC(codec_interface, "G.722");
for (count = 12; count > 0; count--) {
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 9, "G722", NULL, 8000, 16000, 64000,
mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
switch_g722_init, switch_g722_encode, switch_g722_decode, switch_g722_destroy);
}
for (count = 12; count > 0; count--) {
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 9, "G722", NULL, 8000, 16000, 64000,
mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
switch_g722_init, switch_g722_encode, switch_g722_decode, switch_g722_destroy);
}
#ifdef ENABLE_G711
/* G711 */
mpf = 10000, spf = 80, bpf = 160, ebpf = 80;
SWITCH_ADD_CODEC(codec_interface, "G.711 ulaw");
for (count = 12; count > 0; count--) {
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 0, "PCMU", NULL, 8000, 8000, 64000,
mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
switch_g711u_init, switch_g711u_encode, switch_g711u_decode, switch_g711u_destroy);
}
for (count = 12; count > 0; count--) {
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 0, "PCMU", NULL, 8000, 8000, 64000,
mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
switch_g711u_init, switch_g711u_encode, switch_g711u_decode, switch_g711u_destroy);
}
SWITCH_ADD_CODEC(codec_interface, "G.711 alaw");
for (count = 12; count > 0; count--) {
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 8, "PCMA", NULL, 8000, 8000, 64000,
mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
switch_g711a_init, switch_g711a_encode, switch_g711a_decode, switch_g711a_destroy);
}
for (count = 12; count > 0; count--) {
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 8, "PCMA", NULL, 8000, 8000, 64000,
mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
switch_g711a_init, switch_g711a_encode, switch_g711a_decode, switch_g711a_destroy);
}
#endif
/* GSM */
mpf = 20000, spf = 160, bpf = 320, ebpf = 33;
SWITCH_ADD_CODEC(codec_interface, "GSM");
for (count = 6; count > 0; count--) {
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 3, "GSM", NULL, 8000, 8000, 13200,
mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 6,
switch_gsm_init, switch_gsm_encode, switch_gsm_decode, switch_gsm_destroy);
}
for (count = 6; count > 0; count--) {
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 3, "GSM", NULL, 8000, 8000, 13200,
mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 6,
switch_gsm_init, switch_gsm_encode, switch_gsm_decode, switch_gsm_destroy);
}
/* LPC10 */
#if SWITCH_MAX_INTERVAL >= 90
SWITCH_ADD_CODEC(codec_interface, "LPC-10");
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 7, "LPC", NULL, 8000, 8000, 2400,
90000, 720, 1440, 28, 1, 1, 1,
switch_lpc10_init, switch_lpc10_encode, switch_lpc10_decode, switch_lpc10_destroy);
90000, 720, 1440, 28, 1, 1, 1, switch_lpc10_init, switch_lpc10_encode, switch_lpc10_decode, switch_lpc10_destroy);
#endif
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
@@ -58,31 +58,31 @@ SWITCH_STANDARD_APP(dial_function)
if ((argc = switch_separate_string(mydata, '|', argv, (sizeof(argv) / sizeof(argv[0])))) < 2) {
goto error;
}
if (argc > 1) {
switch_channel_set_variable(channel, "call_timeout", argv[1]);
}
switch_replace_char(argv[0], '&',',', SWITCH_FALSE);
switch_replace_char(argv[0], '&', ',', SWITCH_FALSE);
if (exec_app(session, "bridge", argv[0]) != SWITCH_STATUS_SUCCESS) {
goto error;
}
goto ok;
}
error:
error:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error!\n");
ok:
ok:
return;
}
SWITCH_STANDARD_APP(avoid_function)
{
void *y = NULL;
void *y = NULL;
int x = 0;
switch_channel_t *channel = switch_core_session_get_channel(session);
@@ -92,7 +92,7 @@ SWITCH_STANDARD_APP(avoid_function)
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "I should never be called!.\n");
memset((void *) y, 0, 1000);
memset((void *) y, 0, 1000);
}
SWITCH_STANDARD_APP(goto_function)
@@ -105,16 +105,16 @@ SWITCH_STANDARD_APP(goto_function)
if ((argc = switch_separate_string(mydata, '|', argv, (sizeof(argv) / sizeof(argv[0])))) < 1) {
goto error;
}
switch_ivr_session_transfer(session, argv[1], "asterisk", argv[0]);
goto ok;
}
error:
error:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error!\n");
ok:
ok:
return;
}
@@ -134,14 +134,14 @@ SWITCH_STANDARD_DIALPLAN(asterisk_dialplan_hunt)
if (!caller_profile) {
caller_profile = switch_channel_get_caller_profile(channel);
}
if (!caller_profile || switch_strlen_zero(caller_profile->destination_number)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Obtaining Profile!\n");
return NULL;
}
context = caller_profile->context ? caller_profile->context : "default";
if (!switch_config_open_file(&cfg, cf)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
@@ -166,11 +166,11 @@ SWITCH_STANDARD_DIALPLAN(asterisk_dialplan_hunt)
const char *field_data = caller_profile->destination_number;
int proceed = 0;
switch_regex_t *re = NULL;
int ovector[30] = {0};
int ovector[30] = { 0 };
char *cid = NULL;
expression = expression_buf;
argc = switch_separate_string(val, ',', argv, (sizeof(argv) / sizeof(argv[0])));
if (argc < 3) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "parse error line %d!\n", cfg.lineno);
@@ -178,14 +178,14 @@ SWITCH_STANDARD_DIALPLAN(asterisk_dialplan_hunt)
}
pattern = argv[0];
if (!strcasecmp(var, "exten")) {
char *p;
if (pattern && (p = strchr(pattern, '/'))) {
*p++ = '\0';
cid = pattern;
pattern = p;
}
}
} else {
if (strchr(var, '$')) {
if ((field_expanded = switch_channel_expand_variables(channel, var)) == var) {
@@ -198,19 +198,19 @@ SWITCH_STANDARD_DIALPLAN(asterisk_dialplan_hunt)
field_data = switch_caller_get_field_by_name(caller_profile, var);
}
}
if (pattern && (*pattern == '_' || *pattern == '~')) {
if (*pattern == '_') {
pattern++;
if (switch_ast2regex(pattern, expression_buf, sizeof(expression_buf))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "converting [%s] to real regex [%s] you should try them!\n",
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "converting [%s] to real regex [%s] you should try them!\n",
pattern, expression_buf);
}
} else {
pattern++;
expression = pattern;
}
if (!field_data) {
field_data = "";
}
@@ -225,7 +225,7 @@ SWITCH_STANDARD_DIALPLAN(asterisk_dialplan_hunt)
continue;
}
}
if (cid) {
if (strcasecmp(cid, caller_profile->caller_id_number)) {
continue;
@@ -235,21 +235,21 @@ SWITCH_STANDARD_DIALPLAN(asterisk_dialplan_hunt)
switch_channel_set_variable(channel, "EXTEN", caller_profile->destination_number);
switch_channel_set_variable(channel, "CHANNEL", switch_channel_get_name(channel));
switch_channel_set_variable(channel, "UNIQUEID", switch_core_session_get_uuid(session));
pri = argv[1];
app = argv[2];
if ((argument = strchr(app, '('))) {
char *p;
*argument++ = '\0';
p = strrchr(argument, ')');
if (p) {
*p = '\0';
*p = '\0';
}
} else if ((argument = strchr(app, ','))) {
*argument++ = '\0';
}
if (!argument) {
argument = "";
}
@@ -274,10 +274,10 @@ SWITCH_STANDARD_DIALPLAN(asterisk_dialplan_hunt)
break;
}
}
switch_caller_extension_add_application(session, extension, app, argument);
}
switch_safe_free(field_expanded);
}
}
@@ -291,18 +291,14 @@ SWITCH_STANDARD_DIALPLAN(asterisk_dialplan_hunt)
switch_endpoint_interface_t *sip_endpoint_interface;
static switch_call_cause_t sip_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event,
switch_caller_profile_t *outbound_profile,
switch_core_session_t **new_session,
switch_memory_pool_t **pool,
switch_originate_flag_t flags);
switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags);
switch_io_routines_t sip_io_routines = {
/*.outgoing_channel */ sip_outgoing_channel
};
static switch_call_cause_t sip_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event,
switch_caller_profile_t *outbound_profile,
switch_core_session_t **new_session,
switch_memory_pool_t **pool,
switch_originate_flag_t flags)
switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags)
{
const char *profile;
@@ -326,18 +322,14 @@ static switch_call_cause_t sip_outgoing_channel(switch_core_session_t *session,
switch_endpoint_interface_t *iax2_endpoint_interface;
static switch_call_cause_t iax2_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event,
switch_caller_profile_t *outbound_profile,
switch_core_session_t **new_session,
switch_memory_pool_t **pool,
switch_originate_flag_t flags);
switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags);
switch_io_routines_t iax2_io_routines = {
/*.outgoing_channel */ iax2_outgoing_channel
};
static switch_call_cause_t iax2_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event,
switch_caller_profile_t *outbound_profile,
switch_core_session_t **new_session,
switch_memory_pool_t **pool,
switch_originate_flag_t flags)
switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags)
{
return switch_core_session_outgoing_channel(session, var_event, "iax", outbound_profile, new_session, pool, SOF_NONE);
}
@@ -346,7 +338,7 @@ static switch_call_cause_t iax2_outgoing_channel(switch_core_session_t *session,
#define WE_DONT_NEED_NO_STINKIN_KEY "true"
static char *key()
{
return WE_DONT_NEED_NO_STINKIN_KEY;
return WE_DONT_NEED_NO_STINKIN_KEY;
}
SWITCH_MODULE_LOAD_FUNCTION(mod_dialplan_asterisk_load)
@@ -359,7 +351,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_dialplan_asterisk_load)
if ((mykey = key())) {
mykey = NULL;
}
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
/* add a dialplan interface */
@@ -369,7 +361,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_dialplan_asterisk_load)
SWITCH_ADD_APP(app_interface, "Dial", "Dial", "Dial", dial_function, "Dial", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "Goto", "Goto", "Goto", goto_function, "Goto", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "AvoidingDeadlock", "Avoid", "Avoid", avoid_function, "Avoid", SAF_SUPPORT_NOMEDIA);
/* fake chan_sip facade */
sip_endpoint_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE);
sip_endpoint_interface->interface_name = "SIP";
@@ -379,7 +371,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_dialplan_asterisk_load)
iax2_endpoint_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE);
iax2_endpoint_interface->interface_name = "IAX2";
iax2_endpoint_interface->io_routines = &iax2_io_routines;
if (getenv("FAITHFUL_EMULATION")) {
for (x = 0; x < 10; x++) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Avoiding Deadlock.\n");
@@ -96,7 +96,7 @@ SWITCH_STANDARD_DIALPLAN(directory_dialplan_hunt)
if (!caller_profile) {
caller_profile = switch_channel_get_caller_profile(channel);
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Hello %s You Dialed %s!\n", caller_profile->caller_id_name,
caller_profile->destination_number);
@@ -134,7 +134,7 @@ SWITCH_STANDARD_DIALPLAN(directory_dialplan_hunt)
}
}
}
out:
out:
switch_core_directory_close(&dh);
@@ -185,15 +185,14 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t *
return proceed;
}
static switch_status_t dialplan_xml_locate(switch_core_session_t *session, switch_caller_profile_t *caller_profile, switch_xml_t * root,
switch_xml_t * node)
static switch_status_t dialplan_xml_locate(switch_core_session_t *session, switch_caller_profile_t *caller_profile, switch_xml_t *root, switch_xml_t *node)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_status_t status = SWITCH_STATUS_GENERR;
switch_event_t *params = NULL;
switch_event_create(&params, SWITCH_EVENT_MESSAGE);
switch_assert(params);
switch_assert(params);
switch_channel_event_set_data(channel, params);
@@ -215,7 +214,7 @@ SWITCH_STANDARD_DIALPLAN(dialplan_hunt)
goto done;
}
}
if (!caller_profile->context) {
caller_profile->context = "default";
}
@@ -265,7 +264,7 @@ SWITCH_STANDARD_DIALPLAN(dialplan_hunt)
proceed = parse_exten(session, caller_profile, xexten, &extension);
if (proceed && !switch_true(cont)) {
if (proceed && !switch_true(cont)) {
break;
}
+115 -155
View File
@@ -139,8 +139,8 @@ SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_timer_name, globals.timer_name);
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_device_name, globals.device_name);
#define is_master(t) switch_test_flag(t, TFLAG_MASTER)
static void add_pvt(private_t * tech_pvt, int master);
static void remove_pvt(private_t * tech_pvt);
static void add_pvt(private_t *tech_pvt, int master);
static void remove_pvt(private_t *tech_pvt);
static switch_status_t channel_on_init(switch_core_session_t *session);
static switch_status_t channel_on_hangup(switch_core_session_t *session);
static switch_status_t channel_on_routing(switch_core_session_t *session);
@@ -356,7 +356,7 @@ static void deactivate_audio_device(void)
static void add_pvt(private_t * tech_pvt, int master)
static void add_pvt(private_t *tech_pvt, int master)
{
private_t *tp;
uint8_t in_list = 0;
@@ -399,7 +399,7 @@ static void add_pvt(private_t * tech_pvt, int master)
switch_mutex_unlock(globals.pvt_lock);
}
static void remove_pvt(private_t * tech_pvt)
static void remove_pvt(private_t *tech_pvt)
{
private_t *tp, *last = NULL;
@@ -562,8 +562,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
tech_pvt->hold_file,
globals.read_codec.implementation->number_of_channels,
globals.read_codec.implementation->actual_samples_per_second,
SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT,
NULL) != SWITCH_STATUS_SUCCESS) {
SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
switch_core_codec_destroy(&tech_pvt->write_codec);
tech_pvt->hold_file = NULL;
goto cng;
@@ -578,12 +577,12 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
goto hold;
}
cng:
cng:
switch_yield(globals.read_codec.implementation->microseconds_per_frame);
*frame = &globals.cng_frame;
return SWITCH_STATUS_SUCCESS;
hold:
hold:
{
switch_size_t olen = globals.read_codec.implementation->samples_per_frame;
@@ -612,7 +611,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
}
switch_mutex_lock(globals.device_lock);
if ((samples = snd_pcm_readi (globals.audio_stream_in, globals.read_frame.data, globals.read_codec.implementation->samples_per_frame)) > 0) {
if ((samples = snd_pcm_readi(globals.audio_stream_in, globals.read_frame.data, globals.read_codec.implementation->samples_per_frame)) > 0) {
globals.read_frame.datalen = samples * 2;
globals.read_frame.samples = samples;
@@ -887,7 +886,7 @@ static switch_status_t load_config(void)
globals.codec_ms = tmp;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
"codec-ms must be multipe of 10 and less than %d, Using default of 20\n", SWITCH_MAX_INTERVAL);
"codec-ms must be multipe of 10 and less than %d, Using default of 20\n", SWITCH_MAX_INTERVAL);
}
} else if (!strcmp(var, "dialplan")) {
set_global_dialplan(val);
@@ -951,18 +950,18 @@ static switch_status_t engage_device(unsigned int sample_rate, int codec_ms)
int err = 0;
snd_pcm_hw_params_t *hw_params = NULL;
char *device = globals.device_name;
if (globals.audio_stream_in && globals.audio_stream_out) {
return SWITCH_STATUS_SUCCESS;
}
}
if (globals.audio_stream_in) {
snd_pcm_close (globals.audio_stream_in);
snd_pcm_close(globals.audio_stream_in);
globals.audio_stream_in = NULL;
}
if (globals.audio_stream_out) {
snd_pcm_close (globals.audio_stream_out);
snd_pcm_close(globals.audio_stream_out);
globals.audio_stream_out = NULL;
}
@@ -976,33 +975,30 @@ static switch_status_t engage_device(unsigned int sample_rate, int codec_ms)
if (switch_core_codec_init(&globals.read_codec,
"L16",
NULL, sample_rate, codec_ms, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
NULL) != SWITCH_STATUS_SUCCESS) {
NULL, sample_rate, codec_ms, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n");
return SWITCH_STATUS_FALSE;
} else {
if (switch_core_codec_init(&globals.write_codec,
"L16",
NULL,
sample_rate, codec_ms, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
NULL) != SWITCH_STATUS_SUCCESS) {
sample_rate, codec_ms, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n");
switch_core_codec_destroy(&globals.read_codec);
return SWITCH_STATUS_FALSE;
}
}
if (switch_core_timer_init(&globals.timer,
globals.timer_name, codec_ms, globals.read_codec.implementation->samples_per_frame,
module_pool) != SWITCH_STATUS_SUCCESS) {
globals.timer_name, codec_ms, globals.read_codec.implementation->samples_per_frame, module_pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "setup timer failed!\n");
switch_core_codec_destroy(&globals.read_codec);
switch_core_codec_destroy(&globals.write_codec);
return SWITCH_STATUS_FALSE;
}
globals.read_frame.rate = sample_rate;
globals.read_frame.codec = &globals.read_codec;
@@ -1011,176 +1007,152 @@ static switch_status_t engage_device(unsigned int sample_rate, int codec_ms)
switch_mutex_lock(globals.device_lock);
/* LOCKED ************************************************************************************************** */
if ((err = snd_pcm_open (&globals.audio_stream_out, device, SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot open audio device %s (%s)\n",
device,
snd_strerror (err));
if ((err = snd_pcm_open(&globals.audio_stream_out, device, SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot open audio device %s (%s)\n", device, snd_strerror(err));
goto fail;
}
if ((err = snd_pcm_hw_params_malloc (&hw_params)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot allocate hardware parameter structure (%s)\n",
snd_strerror (err));
if ((err = snd_pcm_hw_params_malloc(&hw_params)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot allocate hardware parameter structure (%s)\n", snd_strerror(err));
goto fail;
}
if ((err = snd_pcm_hw_params_any (globals.audio_stream_out, hw_params)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot initialize hardware parameter structure (%s)\n",
snd_strerror (err));
if ((err = snd_pcm_hw_params_any(globals.audio_stream_out, hw_params)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot initialize hardware parameter structure (%s)\n", snd_strerror(err));
goto fail;
}
if ((err = snd_pcm_hw_params_set_access (globals.audio_stream_out, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot set access type (%s)\n",
snd_strerror (err));
if ((err = snd_pcm_hw_params_set_access(globals.audio_stream_out, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot set access type (%s)\n", snd_strerror(err));
goto fail;
}
if ((err = snd_pcm_hw_params_set_format (globals.audio_stream_out, hw_params, SND_PCM_FORMAT_S16_LE)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot set sample format (%s)\n",
snd_strerror (err));
if ((err = snd_pcm_hw_params_set_format(globals.audio_stream_out, hw_params, SND_PCM_FORMAT_S16_LE)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot set sample format (%s)\n", snd_strerror(err));
goto fail;
}
if ((err = snd_pcm_hw_params_set_rate_near (globals.audio_stream_out, hw_params, &sample_rate, 0)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot set sample rate (%s)\n",
snd_strerror (err));
if ((err = snd_pcm_hw_params_set_rate_near(globals.audio_stream_out, hw_params, &sample_rate, 0)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot set sample rate (%s)\n", snd_strerror(err));
goto fail;
}
if ((err = snd_pcm_hw_params_set_channels (globals.audio_stream_out, hw_params, 1)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot set channel count (%s)\n",
snd_strerror (err));
if ((err = snd_pcm_hw_params_set_channels(globals.audio_stream_out, hw_params, 1)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot set channel count (%s)\n", snd_strerror(err));
goto fail;
}
if ((err = snd_pcm_hw_params (globals.audio_stream_out, hw_params)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot set parameters (%s)\n",
snd_strerror (err));
if ((err = snd_pcm_hw_params(globals.audio_stream_out, hw_params)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot set parameters (%s)\n", snd_strerror(err));
goto fail;
}
snd_pcm_hw_params_free (hw_params);
snd_pcm_hw_params_free(hw_params);
hw_params = NULL;
if ((err = snd_pcm_open (&globals.audio_stream_in, device, SND_PCM_STREAM_CAPTURE, 0)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot open audio device %s (%s)\n",
device,
snd_strerror (err));
goto fail;
}
if ((err = snd_pcm_hw_params_malloc (&hw_params)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot allocate hardware parameter structure (%s)\n",
snd_strerror (err));
goto fail;
}
if ((err = snd_pcm_hw_params_any (globals.audio_stream_in, hw_params)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot initialize hardware parameter structure (%s)\n",
snd_strerror (err));
goto fail;
}
if ((err = snd_pcm_hw_params_set_access (globals.audio_stream_in, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot set access type (%s)\n",
snd_strerror (err));
goto fail;
}
if ((err = snd_pcm_hw_params_set_format (globals.audio_stream_in, hw_params, SND_PCM_FORMAT_S16_LE)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot set sample format (%s)\n",
snd_strerror (err));
goto fail;
}
if ((err = snd_pcm_hw_params_set_rate_near (globals.audio_stream_in, hw_params, &sample_rate, 0)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot set sample rate (%s)\n",
snd_strerror (err));
goto fail;
}
if ((err = snd_pcm_hw_params_set_channels (globals.audio_stream_in, hw_params, 1)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot set channel count (%s)\n",
snd_strerror (err));
if ((err = snd_pcm_open(&globals.audio_stream_in, device, SND_PCM_STREAM_CAPTURE, 0)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot open audio device %s (%s)\n", device, snd_strerror(err));
goto fail;
}
if ((err = snd_pcm_hw_params_set_period_time (globals.audio_stream_in, hw_params, globals.read_codec.implementation->microseconds_per_frame, 0)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot set period time (%s)\n",
snd_strerror (err));
if ((err = snd_pcm_hw_params_malloc(&hw_params)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot allocate hardware parameter structure (%s)\n", snd_strerror(err));
goto fail;
}
if ((err = snd_pcm_hw_params_set_period_size (globals.audio_stream_in, hw_params, globals.read_codec.implementation->samples_per_frame, 0)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot set period size (%s)\n",
snd_strerror (err));
if ((err = snd_pcm_hw_params_any(globals.audio_stream_in, hw_params)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot initialize hardware parameter structure (%s)\n", snd_strerror(err));
goto fail;
}
if ((err = snd_pcm_hw_params (globals.audio_stream_in, hw_params)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot set parameters (%s)\n",
snd_strerror (err));
if ((err = snd_pcm_hw_params_set_access(globals.audio_stream_in, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot set access type (%s)\n", snd_strerror(err));
goto fail;
}
if ((err = snd_pcm_hw_params_set_format(globals.audio_stream_in, hw_params, SND_PCM_FORMAT_S16_LE)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot set sample format (%s)\n", snd_strerror(err));
goto fail;
}
if ((err = snd_pcm_hw_params_set_rate_near(globals.audio_stream_in, hw_params, &sample_rate, 0)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot set sample rate (%s)\n", snd_strerror(err));
goto fail;
}
if ((err = snd_pcm_hw_params_set_channels(globals.audio_stream_in, hw_params, 1)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot set channel count (%s)\n", snd_strerror(err));
goto fail;
}
if ((err = snd_pcm_hw_params_set_period_time(globals.audio_stream_in, hw_params, globals.read_codec.implementation->microseconds_per_frame, 0)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot set period time (%s)\n", snd_strerror(err));
goto fail;
}
if ((err = snd_pcm_hw_params_set_period_size(globals.audio_stream_in, hw_params, globals.read_codec.implementation->samples_per_frame, 0)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot set period size (%s)\n", snd_strerror(err));
goto fail;
}
if ((err = snd_pcm_hw_params(globals.audio_stream_in, hw_params)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot set parameters (%s)\n", snd_strerror(err));
goto fail;
}
if (hw_params) {
snd_pcm_hw_params_free (hw_params);
snd_pcm_hw_params_free(hw_params);
hw_params = NULL;
}
if ((err = snd_pcm_prepare (globals.audio_stream_out)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot prepare audio interface for use (%s)\n",
snd_strerror (err));
if ((err = snd_pcm_prepare(globals.audio_stream_out)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot prepare audio interface for use (%s)\n", snd_strerror(err));
goto fail;
}
if ((err = snd_pcm_start (globals.audio_stream_out)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot start audio interface for use (%s)\n",
snd_strerror (err));
if ((err = snd_pcm_start(globals.audio_stream_out)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot start audio interface for use (%s)\n", snd_strerror(err));
goto fail;
}
if ((err = snd_pcm_prepare (globals.audio_stream_in)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot prepare audio interface for use (%s)\n",
snd_strerror (err));
if ((err = snd_pcm_prepare(globals.audio_stream_in)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot prepare audio interface for use (%s)\n", snd_strerror(err));
goto fail;
}
if ((err = snd_pcm_start (globals.audio_stream_in)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot start audio interface for use (%s)\n",
snd_strerror (err));
if ((err = snd_pcm_start(globals.audio_stream_in)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot start audio interface for use (%s)\n", snd_strerror(err));
goto fail;
}
switch_mutex_unlock(globals.device_lock);
return SWITCH_STATUS_SUCCESS;
fail:
fail:
if (hw_params) {
snd_pcm_hw_params_free (hw_params);
snd_pcm_hw_params_free(hw_params);
hw_params = NULL;
}
switch_mutex_unlock(globals.device_lock);
if (globals.audio_stream_in) {
snd_pcm_close (globals.audio_stream_in);
snd_pcm_close(globals.audio_stream_in);
}
if (globals.audio_stream_out) {
snd_pcm_close (globals.audio_stream_out);
snd_pcm_close(globals.audio_stream_out);
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open audio device!\n");
switch_core_codec_destroy(&globals.read_codec);
switch_core_codec_destroy(&globals.write_codec);
return SWITCH_STATUS_FALSE;
return SWITCH_STATUS_FALSE;
@@ -1189,8 +1161,8 @@ static switch_status_t engage_device(unsigned int sample_rate, int codec_ms)
static switch_status_t dtmf_call(char **argv, int argc, switch_stream_handle_t *stream)
{
char *dtmf_str = argv[0];
switch_dtmf_t dtmf = {0, switch_core_default_dtmf_duration(0)};
switch_dtmf_t dtmf = { 0, switch_core_default_dtmf_duration(0) };
if (switch_strlen_zero(dtmf_str)) {
stream->write_function(stream, "No DTMF Supplied!\n");
} else {
@@ -1198,7 +1170,7 @@ static switch_status_t dtmf_call(char **argv, int argc, switch_stream_handle_t *
if (globals.call_list) {
switch_channel_t *channel = switch_core_session_get_channel(globals.call_list->session);
char *p = dtmf_str;
while(p && *p) {
while (p && *p) {
dtmf.digit = *p;
switch_channel_queue_dtmf(channel, &dtmf);
p++;
@@ -1250,7 +1222,7 @@ static switch_status_t switch_call(char **argv, int argc, switch_stream_handle_t
stream->write_function(stream, "NO SUCH CALL\n");
}
done:
done:
switch_mutex_unlock(globals.pvt_lock);
return SWITCH_STATUS_SUCCESS;
@@ -1317,7 +1289,7 @@ static switch_status_t answer_call(char **argv, int argc, switch_stream_handle_t
break;
}
}
done:
done:
switch_mutex_unlock(globals.pvt_lock);
stream->write_function(stream, "Answered %d channels.\n", x);
@@ -1371,7 +1343,7 @@ static switch_status_t do_flags(char **argv, int argc, switch_stream_handle_t *s
goto bad;
}
desc:
desc:
x = 0;
stream->write_function(stream, "FLAGS: ");
if (switch_test_flag((&globals), GFLAG_EAR)) {
@@ -1388,9 +1360,9 @@ static switch_status_t do_flags(char **argv, int argc, switch_stream_handle_t *s
goto done;
bad:
bad:
stream->write_function(stream, "Usage: flags [on|off] <flags>\n");
done:
done:
return SWITCH_STATUS_SUCCESS;
}
@@ -1487,12 +1459,9 @@ static switch_status_t place_call(char **argv, int argc, switch_stream_handle_t
if ((tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
NULL,
dialplan, cid_name, cid_num,
ip, NULL, NULL, NULL, (char *) modname, NULL,
dest)) != 0) {
dialplan, cid_name, cid_num, ip, NULL, NULL, NULL, (char *) modname, NULL, dest)) != 0) {
char name[128];
snprintf(name, sizeof(name), "Alsa/%s",
tech_pvt->caller_profile->destination_number ? tech_pvt->caller_profile->destination_number : modname);
snprintf(name, sizeof(name), "Alsa/%s", tech_pvt->caller_profile->destination_number ? tech_pvt->caller_profile->destination_number : modname);
switch_channel_set_name(channel, name);
switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
@@ -1504,7 +1473,7 @@ static switch_status_t place_call(char **argv, int argc, switch_stream_handle_t
switch_channel_set_state(channel, CS_INIT);
if (switch_core_session_thread_launch(tech_pvt->session) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error spawning thread\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error spawning thread\n");
switch_core_session_destroy(&session);
stream->write_function(stream, "FAIL:Thread Error!\n");
} else {
@@ -1536,7 +1505,7 @@ SWITCH_STANDARD_API(pa_cmd)
http = switch_event_get_header(stream->param_event, "http-host");
}
const char *usage_string = "USAGE:\n"
"--------------------------------------------------------------------------------\n"
"alsa help\n"
@@ -1546,8 +1515,7 @@ SWITCH_STANDARD_API(pa_cmd)
"alsa list\n"
"alsa switch [<call_id>|none]\n"
"alsa dtmf <digit string>\n"
"alsa flags [on|off] [ear] [mouth]\n"
"--------------------------------------------------------------------------------\n";
"alsa flags [on|off] [ear] [mouth]\n" "--------------------------------------------------------------------------------\n";
if (http) {
#if 0
@@ -1638,14 +1606,13 @@ SWITCH_STANDARD_API(pa_cmd)
stream->write_function(stream, "Unknown Command [%s]\n", argv[0]);
}
done:
done:
if (http) {
stream->write_function(stream,
"<br><br><table align=center><tr><td><center><form method=post>\n"
"<input type=text name=wcmd size=40><br><br>\n"
"<input name=action type=submit value=\"call\"> "
"<input name=action type=submit value=\"hangup\"> "
"<input name=action type=submit value=\"list\"> "
@@ -1658,25 +1625,18 @@ SWITCH_STANDARD_API(pa_cmd)
"<td><input name=action type=submit value=\"2\"></td>"
"<td><input name=action type=submit value=\"3\"></td>\n"
"<td><input name=action type=submit value=\"A\"></td></tr>\n"
"<tr><td><input name=action type=submit value=\"4\"></td>"
"<td><input name=action type=submit value=\"5\"></td>"
"<td><input name=action type=submit value=\"6\"></td>\n"
"<td><input name=action type=submit value=\"B\"></td></tr>\n"
"<tr><td><input name=action type=submit value=\"7\"></td>"
"<td><input name=action type=submit value=\"8\"></td>"
"<td><input name=action type=submit value=\"9\"></td>\n"
"<td><input name=action type=submit value=\"C\"></td></tr>\n"
"<tr><td><input name=action type=submit value=\"*\"></td>"
"<td><input name=action type=submit value=\"0\"></td>"
"<td><input name=action type=submit value=\"#\"></td>\n"
"<td><input name=action type=submit value=\"D\"></td></tr>\n"
"</table>"
"</form><br></center></td></tr></table>\n"
);
"<td><input name=action type=submit value=\"D\"></td></tr>\n" "</table>" "</form><br></center></td></tr></table>\n");
}
+111 -130
View File
@@ -53,11 +53,7 @@ switch_endpoint_interface_t *dingaling_endpoint_interface;
static char sub_sql[] =
"CREATE TABLE jabber_subscriptions (\n"
" sub_from VARCHAR(255),\n"
" sub_to VARCHAR(255),\n"
" show_pres VARCHAR(255),\n"
" status VARCHAR(255)\n"
");\n";
" sub_from VARCHAR(255),\n" " sub_to VARCHAR(255),\n" " show_pres VARCHAR(255),\n" " status VARCHAR(255)\n" ");\n";
typedef enum {
@@ -215,9 +211,9 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id);
static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig);
static ldl_status handle_signalling(ldl_handle_t * handle, ldl_session_t * dlsession, ldl_signal_t dl_signal,
static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsession, ldl_signal_t dl_signal,
char *to, char *from, char *subject, char *msg);
static ldl_status handle_response(ldl_handle_t * handle, char *id);
static ldl_status handle_response(ldl_handle_t *handle, char *id);
static switch_status_t load_config(void);
static int sin_callback(void *pArg, int argc, char **argv, char **columnNames);
@@ -270,9 +266,8 @@ static void mdl_execute_sql(mdl_profile_t *profile, char *sql, switch_mutex_t *m
if (mutex) {
switch_mutex_lock(mutex);
}
#ifdef SWITCH_HAVE_ODBC
if (profile->odbc_dsn) {
if (profile->odbc_dsn) {
SQLHSTMT stmt;
if (switch_odbc_handle_exec(profile->master_odbc, sql, &stmt) != SWITCH_ODBC_SUCCESS) {
char *err_str;
@@ -292,11 +287,11 @@ static void mdl_execute_sql(mdl_profile_t *profile, char *sql, switch_mutex_t *m
switch_core_db_close(db);
#ifdef SWITCH_HAVE_ODBC
}
}
#endif
end:
end:
if (mutex) {
switch_mutex_unlock(mutex);
}
@@ -304,22 +299,18 @@ static void mdl_execute_sql(mdl_profile_t *profile, char *sql, switch_mutex_t *m
static switch_bool_t mdl_execute_sql_callback(mdl_profile_t *profile,
switch_mutex_t *mutex,
char *sql,
switch_core_db_callback_func_t callback,
void *pdata)
switch_mutex_t *mutex, char *sql, switch_core_db_callback_func_t callback, void *pdata)
{
switch_bool_t ret = SWITCH_FALSE;
switch_core_db_t *db;
char *errmsg = NULL;
if (mutex) {
switch_mutex_lock(mutex);
}
if (mutex) {
switch_mutex_lock(mutex);
}
#ifdef SWITCH_HAVE_ODBC
if (profile->odbc_dsn) {
if (profile->odbc_dsn) {
switch_odbc_handle_callback_exec(profile->master_odbc, sql, callback, pdata);
} else {
#endif
@@ -331,7 +322,7 @@ static switch_bool_t mdl_execute_sql_callback(mdl_profile_t *profile,
goto end;
}
switch_core_db_exec(db, sql, callback, pdata, &errmsg);
if (errmsg) {
@@ -342,18 +333,17 @@ static switch_bool_t mdl_execute_sql_callback(mdl_profile_t *profile,
if (db) {
switch_core_db_close(db);
}
#ifdef SWITCH_HAVE_ODBC
}
}
#endif
end:
end:
if (mutex) {
switch_mutex_unlock(mutex);
}
switch_mutex_unlock(mutex);
}
return ret;
@@ -418,11 +408,11 @@ static void pres_event_handler(switch_event_t *event)
char *rpid = switch_event_get_header(event, "rpid");
char *type = switch_event_get_header(event, "event_subtype");
char *sql;
if (globals.running != 1) {
return;
}
if (globals.running != 1) {
return;
}
if (!proto) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Missing 'proto' header\n");
return;
@@ -481,7 +471,8 @@ static void pres_event_handler(switch_event_t *event)
}
sql = switch_mprintf("select sub_from, sub_to,'%q','%q','%q','%q' from jabber_subscriptions where sub_to like '%%%q'", type, rpid, status, proto, from);
sql =
switch_mprintf("select sub_from, sub_to,'%q','%q','%q','%q' from jabber_subscriptions where sub_to like '%%%q'", type, rpid, status, proto, from);
for (hi = switch_hash_first(NULL, globals.profile_hash); hi; hi = switch_hash_next(hi)) {
@@ -495,7 +486,7 @@ static void pres_event_handler(switch_event_t *event)
if (sql) {
switch_bool_t worked = mdl_execute_sql_callback(profile, profile->mutex, sql, sub_callback, profile);
if (!worked) {
continue;
}
@@ -564,9 +555,9 @@ static void roster_event_handler(switch_event_t *event)
void *val;
char *sql;
if (globals.running != 1) {
return;
}
if (globals.running != 1) {
return;
}
if (status && !strcasecmp(status, "n/a")) {
status = NULL;
@@ -697,7 +688,7 @@ static void terminate_session(switch_core_session_t **session, int line, switch_
tech_pvt = switch_core_session_get_private(*session);
if (tech_pvt && tech_pvt->profile && tech_pvt->profile->ip && tech_pvt->local_port) {
switch_rtp_release_port(tech_pvt->profile->ip, tech_pvt->local_port);
}
@@ -748,8 +739,7 @@ static void dl_logger(char *file, const char *func, int line, int level, char *f
xml = switch_xml_parse_str(xmltxt, strlen(xmltxt));
form = switch_xml_toxml(xml, SWITCH_FALSE);
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, level,
"%s:\n-------------------------------------------------------------------------------\n"
"%s\n", ll, form);
"%s:\n-------------------------------------------------------------------------------\n" "%s\n", ll, form);
switch_xml_free(xml);
free(data);
}
@@ -774,8 +764,7 @@ static int get_codecs(struct private_object *tech_pvt)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "NO codecs?\n");
return 0;
}
} else if (((tech_pvt->num_codecs =
switch_loadable_module_get_codecs(tech_pvt->codecs, SWITCH_MAX_CODECS))) <= 0) {
} else if (((tech_pvt->num_codecs = switch_loadable_module_get_codecs(tech_pvt->codecs, SWITCH_MAX_CODECS))) <= 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "NO codecs?\n");
return 0;
}
@@ -786,7 +775,7 @@ static int get_codecs(struct private_object *tech_pvt)
static void *SWITCH_THREAD_FUNC handle_thread_run(switch_thread_t * thread, void *obj)
static void *SWITCH_THREAD_FUNC handle_thread_run(switch_thread_t *thread, void *obj)
{
ldl_handle_t *handle = obj;
mdl_profile_t *profile = NULL;
@@ -805,7 +794,7 @@ static void *SWITCH_THREAD_FUNC handle_thread_run(switch_thread_t * thread, void
return NULL;
}
static void handle_thread_launch(ldl_handle_t * handle)
static void handle_thread_launch(ldl_handle_t *handle)
{
switch_thread_t *thread;
switch_threadattr_t *thd_attr = NULL;
@@ -873,7 +862,7 @@ static int activate_rtp(struct private_object *tech_pvt)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SETUP RTP %s:%d -> %s:%d\n", tech_pvt->profile->ip,
tech_pvt->local_port, tech_pvt->remote_ip, tech_pvt->remote_port);
flags = SWITCH_RTP_FLAG_DATAWAIT | SWITCH_RTP_FLAG_GOOGLEHACK | SWITCH_RTP_FLAG_AUTOADJ | SWITCH_RTP_FLAG_RAW_WRITE | SWITCH_RTP_FLAG_AUTO_CNG;
if (switch_test_flag(tech_pvt->profile, TFLAG_TIMER)) {
@@ -1089,8 +1078,7 @@ static switch_status_t negotiate_media(switch_core_session_t *session)
while (!(switch_test_flag(tech_pvt, TFLAG_CODEC_READY) &&
switch_test_flag(tech_pvt, TFLAG_RTP_READY) &&
switch_test_flag(tech_pvt, TFLAG_ANSWER) && switch_test_flag(tech_pvt, TFLAG_TRANSPORT_ACCEPT) &&
tech_pvt->remote_ip && tech_pvt->remote_port
&& switch_test_flag(tech_pvt, TFLAG_TRANSPORT))) {
tech_pvt->remote_ip && tech_pvt->remote_port && switch_test_flag(tech_pvt, TFLAG_TRANSPORT))) {
now = switch_timestamp_now();
elapsed = (unsigned int) ((now - started) / 1000);
@@ -1140,9 +1128,9 @@ static switch_status_t negotiate_media(switch_core_session_t *session)
goto done;
out:
out:
terminate_session(&session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
done:
done:
return ret;
}
@@ -1222,7 +1210,7 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session)
/* Dunno why, but if googletalk calls us for the first time, as soon as the call ends
they think we are offline for no reason so we send this presence packet to stop it from happening
We should find out why.....
*/
*/
if ((tech_pvt->profile->user_flags & LDL_FLAG_COMPONENT) && is_special(tech_pvt->them)) {
ldl_handle_send_presence(tech_pvt->profile->handle, tech_pvt->them, tech_pvt->us, NULL, NULL, "Click To Call", tech_pvt->profile->avatar);
}
@@ -1497,21 +1485,21 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s
break;
case SWITCH_MESSAGE_INDICATE_BRIDGE:
/*
if (tech_pvt->rtp_session && switch_test_flag(tech_pvt->profile, TFLAG_TIMER)) {
switch_rtp_clear_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_USE_TIMER);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "De-activate timed RTP!\n");
//switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_TIMER_RECLOCK);
}
*/
if (tech_pvt->rtp_session && switch_test_flag(tech_pvt->profile, TFLAG_TIMER)) {
switch_rtp_clear_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_USE_TIMER);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "De-activate timed RTP!\n");
//switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_TIMER_RECLOCK);
}
*/
break;
case SWITCH_MESSAGE_INDICATE_UNBRIDGE:
/*
if (tech_pvt->rtp_session && switch_test_flag(tech_pvt->profile, TFLAG_TIMER)) {
switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_USE_TIMER);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Re-activate timed RTP!\n");
//switch_rtp_clear_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_TIMER_RECLOCK);
}
*/
if (tech_pvt->rtp_session && switch_test_flag(tech_pvt->profile, TFLAG_TIMER)) {
switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_USE_TIMER);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Re-activate timed RTP!\n");
//switch_rtp_clear_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_TIMER_RECLOCK);
}
*/
break;
default:
break;
@@ -1618,7 +1606,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi
} else {
if (!user) {
const char *id_num;
if (!(id_num = outbound_profile->caller_id_number)) {
if (!(id_num = outbound_profile->caller_id_name)) {
id_num = "nobody";
@@ -1810,7 +1798,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_dingaling_load)
return SWITCH_STATUS_SUCCESS;
}
static ldl_status handle_loop(ldl_handle_t * handle)
static ldl_status handle_loop(ldl_handle_t *handle)
{
if (!globals.running) {
return LDL_STATUS_FALSE;
@@ -1829,7 +1817,7 @@ static switch_status_t init_profile(mdl_profile_t *profile, uint8_t login)
if (!(profile->login && profile->password && profile->dialplan && profile->message && profile->ip && profile->name && profile->exten)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
"Invalid Profile\n" "login[%s]\n" "pass[%s]\n" "dialplan[%s]\n"
"Invalid Profile\n" "login[%s]\n" "pass[%s]\n" "dialplan[%s]\n"
"message[%s]\n" "rtp-ip[%s]\n" "name[%s]\n" "exten[%s]\n",
profile->login, profile->password, profile->dialplan, profile->message, profile->ip, profile->name, profile->exten);
@@ -1886,7 +1874,8 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_dingaling_shutdown)
static void set_profile_val(mdl_profile_t *profile, char *var, char *val)
{
if (!var) return;
if (!var)
return;
if (!strcasecmp(var, "login")) {
profile->login = switch_core_strdup(module_pool, val);
@@ -1903,8 +1892,7 @@ static void set_profile_val(mdl_profile_t *profile, char *var, char *val)
*profile->odbc_pass++ = '\0';
}
}
#else
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n");
#endif
@@ -1912,7 +1900,7 @@ static void set_profile_val(mdl_profile_t *profile, char *var, char *val)
switch_set_flag(profile, TFLAG_TIMER);
} else if (!strcasecmp(var, "dialplan") && !switch_strlen_zero(val)) {
profile->dialplan = switch_core_strdup(module_pool, val);
#ifdef AUTO_REPLY // gotta fix looping on this
#ifdef AUTO_REPLY // gotta fix looping on this
} else if (!strcasecmp(var, "auto-reply")) {
profile->auto_reply = switch_core_strdup(module_pool, val);
#endif
@@ -2182,7 +2170,7 @@ static switch_status_t load_config(void)
if (!(profile->master_odbc = switch_odbc_handle_new(profile->odbc_dsn, profile->odbc_user, profile->odbc_pass))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open ODBC Database!\n");
continue;
}
if (switch_odbc_handle_connect(profile->master_odbc) != SWITCH_ODBC_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open ODBC Database!\n");
@@ -2292,7 +2280,7 @@ static void do_vcard(ldl_handle_t *handle, char *to, char *from, char *id)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
}
end:
end:
switch_event_destroy(&params);
@@ -2307,8 +2295,7 @@ static void do_vcard(ldl_handle_t *handle, char *to, char *from, char *id)
switch_safe_free(xmlstr);
}
static ldl_status handle_signalling(ldl_handle_t * handle, ldl_session_t * dlsession, ldl_signal_t dl_signal, char *to, char *from, char *subject,
char *msg)
static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsession, ldl_signal_t dl_signal, char *to, char *from, char *subject, char *msg)
{
mdl_profile_t *profile = NULL;
switch_core_session_t *session = NULL;
@@ -2350,11 +2337,8 @@ static ldl_status handle_signalling(ldl_handle_t * handle, ldl_session_t * dlses
mdl_execute_sql(profile, sql, NULL);
switch_core_db_free(sql);
}
if ((sql = switch_mprintf("insert into jabber_subscriptions values('%q','%q','%q','%q');\n",
switch_str_nil(from),
switch_str_nil(to),
switch_str_nil(msg),
switch_str_nil(subject)))) {
if ((sql = switch_mprintf("insert into jabber_subscriptions values('%q','%q','%q','%q');\n",
switch_str_nil(from), switch_str_nil(to), switch_str_nil(msg), switch_str_nil(subject)))) {
mdl_execute_sql(profile, sql, NULL);
switch_core_db_free(sql);
}
@@ -2362,7 +2346,8 @@ static ldl_status handle_signalling(ldl_handle_t * handle, ldl_session_t * dlses
if (is_special(to)) {
ldl_handle_send_presence(profile->handle, to, from, NULL, NULL, "Click To Call", profile->avatar);
} else {
ldl_handle_send_presence(profile->handle, to, from, NULL, NULL, "Authenticated.\nCome to ClueCon!\nhttp://www.cluecon.com", profile->avatar);
ldl_handle_send_presence(profile->handle, to, from, NULL, NULL, "Authenticated.\nCome to ClueCon!\nhttp://www.cluecon.com",
profile->avatar);
}
#if 0
if (is_special(to)) {
@@ -2400,7 +2385,7 @@ static ldl_status handle_signalling(ldl_handle_t * handle, ldl_session_t * dlses
break;
case LDL_SIGNAL_PRESENCE_IN:
if ((sql = switch_mprintf("update jabber_subscriptions set show_pres='%q', status='%q' where sub_from='%q'",
if ((sql = switch_mprintf("update jabber_subscriptions set show_pres='%q', status='%q' where sub_from='%q'",
switch_str_nil(msg), switch_str_nil(subject), switch_str_nil(from)))) {
mdl_execute_sql(profile, sql, profile->mutex);
switch_core_db_free(sql);
@@ -2435,7 +2420,7 @@ static ldl_status handle_signalling(ldl_handle_t * handle, ldl_session_t * dlses
case LDL_SIGNAL_PRESENCE_OUT:
if ((sql = switch_mprintf("update jabber_subscriptions set show_pres='%q', status='%q' where sub_from='%q'",
if ((sql = switch_mprintf("update jabber_subscriptions set show_pres='%q', status='%q' where sub_from='%q'",
switch_str_nil(msg), switch_str_nil(subject), switch_str_nil(from)))) {
mdl_execute_sql(profile, sql, profile->mutex);
switch_core_db_free(sql);
@@ -2454,45 +2439,45 @@ static ldl_status handle_signalling(ldl_handle_t * handle, ldl_session_t * dlses
switch (dl_signal) {
case LDL_SIGNAL_MSG:{
switch_chat_interface_t *ci;
char *proto = MDL_CHAT_PROTO;
char *pproto = NULL, *ffrom = NULL;
char *hint;
switch_chat_interface_t *ci;
char *proto = MDL_CHAT_PROTO;
char *pproto = NULL, *ffrom = NULL;
char *hint;
#ifdef AUTO_REPLY
if (profile->auto_reply) {
ldl_handle_send_msg(handle,
(profile->user_flags & LDL_FLAG_COMPONENT) ? to : ldl_handle_get_login(profile->handle), from, "",
profile->auto_reply);
}
if (profile->auto_reply) {
ldl_handle_send_msg(handle,
(profile->user_flags & LDL_FLAG_COMPONENT) ? to : ldl_handle_get_login(profile->handle), from, "",
profile->auto_reply);
}
#endif
if (strchr(to, '+')) {
pproto = strdup(to);
if ((to = strchr(pproto, '+'))) {
*to++ = '\0';
if (strchr(to, '+')) {
pproto = strdup(to);
if ((to = strchr(pproto, '+'))) {
*to++ = '\0';
}
proto = pproto;
}
proto = pproto;
}
hint = from;
hint = from;
if (strchr(from, '/') && (ffrom = strdup(from))) {
char *p;
if ((p = strchr(ffrom, '/'))) {
*p = '\0';
if (strchr(from, '/') && (ffrom = strdup(from))) {
char *p;
if ((p = strchr(ffrom, '/'))) {
*p = '\0';
}
from = ffrom;
}
from = ffrom;
}
if ((ci = switch_loadable_module_get_chat_interface(proto))) {
ci->chat_send(MDL_CHAT_PROTO, from, to, subject, msg, hint);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Chat Interface [%s]!\n", proto);
}
if ((ci = switch_loadable_module_get_chat_interface(proto))) {
ci->chat_send(MDL_CHAT_PROTO, from, to, subject, msg, hint);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Chat Interface [%s]!\n", proto);
}
switch_safe_free(pproto);
switch_safe_free(ffrom);
}
switch_safe_free(pproto);
switch_safe_free(ffrom);
}
break;
case LDL_SIGNAL_LOGIN_SUCCESS:
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, DL_EVENT_LOGIN_SUCCESS) == SWITCH_STATUS_SUCCESS) {
@@ -2547,7 +2532,7 @@ static ldl_status handle_signalling(ldl_handle_t * handle, ldl_session_t * dlses
}
if ((session = switch_core_session_request(dingaling_endpoint_interface, NULL)) != 0) {
switch_core_session_add_stream(session, NULL);
if ((tech_pvt = (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object))) != 0) {
char *exten;
char *context;
@@ -2641,10 +2626,7 @@ static ldl_status handle_signalling(ldl_handle_t * handle, ldl_session_t * dlses
ldl_session_get_ip(dlsession),
ldl_session_get_value(dlsession, "ani"),
ldl_session_get_value(dlsession, "aniii"),
ldl_session_get_value(dlsession, "rdnis"),
modname,
context,
exten)) != 0) {
ldl_session_get_value(dlsession, "rdnis"), modname, context, exten)) != 0) {
char name[128];
switch_snprintf(name, sizeof(name), "DingaLing/%s", tech_pvt->caller_profile->destination_number);
switch_channel_set_name(channel, name);
@@ -2669,8 +2651,8 @@ static ldl_status handle_signalling(ldl_handle_t * handle, ldl_session_t * dlses
if (switch_core_session_thread_launch(session) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error spawning thread\n");
terminate_session(&session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
status = LDL_STATUS_FALSE;
goto done;
status = LDL_STATUS_FALSE;
goto done;
}
} else {
status = LDL_STATUS_FALSE;
@@ -2832,7 +2814,7 @@ static ldl_status handle_signalling(ldl_handle_t * handle, ldl_session_t * dlses
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%u candidates\n", len);
if (profile->acl_count) {
for (x = 0; x < len; x++) {
uint32_t y = 0;
@@ -2843,18 +2825,18 @@ static ldl_status handle_signalling(ldl_handle_t * handle, ldl_session_t * dlses
}
if (ok) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "candidate %s:%d PASS ACL %s\n",
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "candidate %s:%d PASS ACL %s\n",
candidates[x].address, candidates[x].port, profile->acl[y]);
break;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "candidate %s:%d FAIL ACL %s\n",
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "candidate %s:%d FAIL ACL %s\n",
candidates[x].address, candidates[x].port, profile->acl[y]);
}
}
}
} else {
for (x = 0; x < len; x++) {
if (profile->lanaddr) {
lanaddr = strncasecmp(candidates[x].address, profile->lanaddr, strlen(profile->lanaddr)) ? 0 : 1;
}
@@ -2879,9 +2861,8 @@ static ldl_status handle_signalling(ldl_handle_t * handle, ldl_session_t * dlses
strncasecmp(candidates[x].address, "172.2", 5) &&
strncasecmp(candidates[x].address, "172.30.", 7) &&
strncasecmp(candidates[x].address, "172.31.", 7) &&
strncasecmp(candidates[x].address, "192.0.2.", 8) &&
strncasecmp(candidates[x].address, "169.254.", 8)
))) {
strncasecmp(candidates[x].address, "192.0.2.", 8) && strncasecmp(candidates[x].address, "169.254.", 8)
))) {
choice = x;
ok = 1;
}
@@ -2893,7 +2874,7 @@ static ldl_status handle_signalling(ldl_handle_t * handle, ldl_session_t * dlses
memset(payloads, 0, sizeof(payloads));
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
"Acceptable Candidate %s:%d\n", candidates[choice].address, candidates[choice].port);
if (!switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) {
@@ -2934,7 +2915,7 @@ static ldl_status handle_signalling(ldl_handle_t * handle, ldl_session_t * dlses
status = LDL_STATUS_SUCCESS;
}
goto done;
goto done;
}
break;
@@ -2961,14 +2942,14 @@ static ldl_status handle_signalling(ldl_handle_t * handle, ldl_session_t * dlses
break;
}
done:
done:
return status;
}
static ldl_status handle_response(ldl_handle_t * handle, char *id)
static ldl_status handle_response(ldl_handle_t *handle, char *id)
{
return LDL_STATUS_SUCCESS;
}
+6 -6
View File
@@ -47,7 +47,7 @@ mutex_status_t iax_mutex_create(mutex_t **mutex)
#endif
mutex_t *check = NULL;
check = (mutex_t *)malloc(sizeof(**mutex));
check = (mutex_t *) malloc(sizeof(**mutex));
if (!check)
goto done;
#ifdef WIN32
@@ -64,16 +64,16 @@ mutex_status_t iax_mutex_create(mutex_t **mutex)
goto success;
fail:
pthread_mutexattr_destroy(&attr);
goto done;
fail:
pthread_mutexattr_destroy(&attr);
goto done;
success:
success:
#endif
*mutex = check;
status = MUTEX_SUCCESS;
done:
done:
return status;
}
File diff suppressed because it is too large. Load diff
+193 -181
View File
@@ -40,12 +40,12 @@ static int oframes = 0;
#ifdef ALIGN32
static unsigned int get_uint32(unsigned char *p)
{
return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
}
static unsigned short get_uint16(unsigned char *p)
{
return (p[0] << 8) | p[1] ;
return (p[0] << 8) | p[1];
}
#else
@@ -64,8 +64,8 @@ static void internalerror(const char *str)
fprintf(stderr, "WARNING: %s", str);
}
static void (*outputf)(const char *str) = internaloutput;
static void (*errorf)(const char *str) = internalerror;
static void (*outputf) (const char *str) = internaloutput;
static void (*errorf) (const char *str) = internalerror;
static void dump_addr(char *output, int maxlen, void *value, int len)
{
@@ -83,21 +83,21 @@ static void dump_string(char *output, int maxlen, void *value, int len)
maxlen--;
if (maxlen > len)
maxlen = len;
strncpy(output,value, maxlen);
strncpy(output, value, maxlen);
output[maxlen] = '\0';
}
static void dump_int(char *output, int maxlen, void *value, int len)
{
if (len == (int)sizeof(unsigned int))
snprintf(output, maxlen, "%lu", (unsigned long)ntohl(get_uint32(value)));
if (len == (int) sizeof(unsigned int))
snprintf(output, maxlen, "%lu", (unsigned long) ntohl(get_uint32(value)));
else
snprintf(output, maxlen, "Invalid INT");
}
static void dump_short(char *output, int maxlen, void *value, int len)
{
if (len == (int)sizeof(unsigned short))
if (len == (int) sizeof(unsigned short))
snprintf(output, maxlen, "%d", ntohs(get_uint16(value)));
else
snprintf(output, maxlen, "Invalid SHORT");
@@ -105,8 +105,8 @@ static void dump_short(char *output, int maxlen, void *value, int len)
static void dump_byte(char *output, int maxlen, void *value, int len)
{
if (len == (int)sizeof(unsigned char))
snprintf(output, maxlen, "%d", *((unsigned char *)value));
if (len == (int) sizeof(unsigned char))
snprintf(output, maxlen, "%d", *((unsigned char *) value));
else
snprintf(output, maxlen, "Invalid BYTE");
}
@@ -115,7 +115,7 @@ static void dump_byte(char *output, int maxlen, void *value, int len)
static void dump_ipaddr(char *output, int maxlen, void *value, int len)
{
struct sockaddr_in sin;
if (len == (int)sizeof(unsigned int)) {
if (len == (int) sizeof(unsigned int)) {
memcpy(&sin.sin_addr, value, len);
snprintf(output, maxlen, "%s", inet_ntoa(sin.sin_addr));
} else
@@ -124,9 +124,8 @@ static void dump_ipaddr(char *output, int maxlen, void *value, int len)
static void dump_prov_flags(char *output, int maxlen, void *value, int len)
{
if (len == (int)sizeof(unsigned int))
snprintf(output, maxlen, "%lu (%s)", (unsigned long)ntohl(get_uint32(value)),
"PROVISION_PARSING_NOT_IMPLEMENTED");
if (len == (int) sizeof(unsigned int))
snprintf(output, maxlen, "%lu (%s)", (unsigned long) ntohl(get_uint32(value)), "PROVISION_PARSING_NOT_IMPLEMENTED");
else
snprintf(output, maxlen, "Invalid INT");
}
@@ -134,10 +133,10 @@ static void dump_prov_flags(char *output, int maxlen, void *value, int len)
static void dump_samprate(char *output, int maxlen, void *value, int len)
{
char tmp[256]="";
char tmp[256] = "";
int sr;
if (len == (int)sizeof(unsigned short)) {
sr = ntohs(*((unsigned short *)value));
if (len == (int) sizeof(unsigned short)) {
sr = ntohs(*((unsigned short *) value));
if (sr & IAX_RATE_8KHZ)
strcat(tmp, ",8khz");
if (sr & IAX_RATE_11KHZ)
@@ -170,61 +169,61 @@ static void dump_prov(char *output, int maxlen, void *value, int len)
static struct iax2_ie {
int ie;
char *name;
void (*dump)(char *output, int maxlen, void *value, int len);
void (*dump) (char *output, int maxlen, void *value, int len);
} ies[] = {
{ IAX_IE_CALLED_NUMBER, "CALLED NUMBER", dump_string },
{ IAX_IE_CALLING_NUMBER, "CALLING NUMBER", dump_string },
{ IAX_IE_CALLING_ANI, "ANI", dump_string },
{ IAX_IE_CALLING_NAME, "CALLING NAME", dump_string },
{ IAX_IE_CALLED_CONTEXT, "CALLED CONTEXT", dump_string },
{ IAX_IE_USERNAME, "USERNAME", dump_string },
{ IAX_IE_PASSWORD, "PASSWORD", dump_string },
{ IAX_IE_CAPABILITY, "CAPABILITY", dump_int },
{ IAX_IE_FORMAT, "FORMAT", dump_int },
{ IAX_IE_LANGUAGE, "LANGUAGE", dump_string },
{ IAX_IE_CODEC_PREFS, "CODEC_PREFS", dump_string },
{ IAX_IE_VERSION, "VERSION", dump_short },
{ IAX_IE_ADSICPE, "ADSICPE", dump_short },
{ IAX_IE_DNID, "DNID", dump_string },
{ IAX_IE_AUTHMETHODS, "AUTHMETHODS", dump_short },
{ IAX_IE_CHALLENGE, "CHALLENGE", dump_string },
{ IAX_IE_MD5_RESULT, "MD5 RESULT", dump_string },
{ IAX_IE_RSA_RESULT, "RSA RESULT", dump_string },
{ IAX_IE_APPARENT_ADDR, "APPARENT ADDRESS", dump_addr },
{ IAX_IE_REFRESH, "REFRESH", dump_short },
{ IAX_IE_DPSTATUS, "DIALPLAN STATUS", dump_short },
{ IAX_IE_CALLNO, "CALL NUMBER", dump_short },
{ IAX_IE_CAUSE, "CAUSE", dump_string },
{ IAX_IE_IAX_UNKNOWN, "UNKNOWN IAX CMD", dump_byte },
{ IAX_IE_MSGCOUNT, "MESSAGE COUNT", dump_short },
{ IAX_IE_AUTOANSWER, "AUTO ANSWER REQ" },
{ IAX_IE_TRANSFERID, "TRANSFER ID", dump_int },
{ IAX_IE_RDNIS, "REFERRING DNIS", dump_string },
{ IAX_IE_PROVISIONING, "PROVISIONING", dump_prov },
{ IAX_IE_AESPROVISIONING, "AES PROVISIONG" },
{ IAX_IE_DATETIME, "DATE TIME", dump_int },
{ IAX_IE_DEVICETYPE, "DEVICE TYPE", dump_string },
{ IAX_IE_SERVICEIDENT, "SERVICE IDENT", dump_string },
{ IAX_IE_FIRMWAREVER, "FIRMWARE VER", dump_short },
{ IAX_IE_FWBLOCKDESC, "FW BLOCK DESC", dump_int },
{ IAX_IE_FWBLOCKDATA, "FW BLOCK DATA" },
{ IAX_IE_PROVVER, "PROVISIONG VER", dump_int },
{ IAX_IE_CALLINGPRES, "CALLING PRESNTN", dump_byte },
{ IAX_IE_CALLINGTON, "CALLING TYPEOFNUM", dump_byte },
{ IAX_IE_CALLINGTNS, "CALLING TRANSITNET", dump_short },
{ IAX_IE_SAMPLINGRATE, "SAMPLINGRATE", dump_samprate },
{ IAX_IE_RR_JITTER, "RR_JITTER", dump_int },
{ IAX_IE_RR_LOSS, "RR_LOSS", dump_int },
{ IAX_IE_RR_PKTS, "RR_PKTS", dump_int },
{ IAX_IE_RR_DELAY, "RR_DELAY", dump_short },
{ IAX_IE_RR_DROPPED, "RR_DROPPED", dump_int },
{ IAX_IE_RR_OOO, "RR_OOO", dump_int },
};
{
IAX_IE_CALLED_NUMBER, "CALLED NUMBER", dump_string}, {
IAX_IE_CALLING_NUMBER, "CALLING NUMBER", dump_string}, {
IAX_IE_CALLING_ANI, "ANI", dump_string}, {
IAX_IE_CALLING_NAME, "CALLING NAME", dump_string}, {
IAX_IE_CALLED_CONTEXT, "CALLED CONTEXT", dump_string}, {
IAX_IE_USERNAME, "USERNAME", dump_string}, {
IAX_IE_PASSWORD, "PASSWORD", dump_string}, {
IAX_IE_CAPABILITY, "CAPABILITY", dump_int}, {
IAX_IE_FORMAT, "FORMAT", dump_int}, {
IAX_IE_LANGUAGE, "LANGUAGE", dump_string}, {
IAX_IE_CODEC_PREFS, "CODEC_PREFS", dump_string}, {
IAX_IE_VERSION, "VERSION", dump_short}, {
IAX_IE_ADSICPE, "ADSICPE", dump_short}, {
IAX_IE_DNID, "DNID", dump_string}, {
IAX_IE_AUTHMETHODS, "AUTHMETHODS", dump_short}, {
IAX_IE_CHALLENGE, "CHALLENGE", dump_string}, {
IAX_IE_MD5_RESULT, "MD5 RESULT", dump_string}, {
IAX_IE_RSA_RESULT, "RSA RESULT", dump_string}, {
IAX_IE_APPARENT_ADDR, "APPARENT ADDRESS", dump_addr}, {
IAX_IE_REFRESH, "REFRESH", dump_short}, {
IAX_IE_DPSTATUS, "DIALPLAN STATUS", dump_short}, {
IAX_IE_CALLNO, "CALL NUMBER", dump_short}, {
IAX_IE_CAUSE, "CAUSE", dump_string}, {
IAX_IE_IAX_UNKNOWN, "UNKNOWN IAX CMD", dump_byte}, {
IAX_IE_MSGCOUNT, "MESSAGE COUNT", dump_short}, {
IAX_IE_AUTOANSWER, "AUTO ANSWER REQ"}, {
IAX_IE_TRANSFERID, "TRANSFER ID", dump_int}, {
IAX_IE_RDNIS, "REFERRING DNIS", dump_string}, {
IAX_IE_PROVISIONING, "PROVISIONING", dump_prov}, {
IAX_IE_AESPROVISIONING, "AES PROVISIONG"}, {
IAX_IE_DATETIME, "DATE TIME", dump_int}, {
IAX_IE_DEVICETYPE, "DEVICE TYPE", dump_string}, {
IAX_IE_SERVICEIDENT, "SERVICE IDENT", dump_string}, {
IAX_IE_FIRMWAREVER, "FIRMWARE VER", dump_short}, {
IAX_IE_FWBLOCKDESC, "FW BLOCK DESC", dump_int}, {
IAX_IE_FWBLOCKDATA, "FW BLOCK DATA"}, {
IAX_IE_PROVVER, "PROVISIONG VER", dump_int}, {
IAX_IE_CALLINGPRES, "CALLING PRESNTN", dump_byte}, {
IAX_IE_CALLINGTON, "CALLING TYPEOFNUM", dump_byte}, {
IAX_IE_CALLINGTNS, "CALLING TRANSITNET", dump_short}, {
IAX_IE_SAMPLINGRATE, "SAMPLINGRATE", dump_samprate}, {
IAX_IE_RR_JITTER, "RR_JITTER", dump_int}, {
IAX_IE_RR_LOSS, "RR_LOSS", dump_int}, {
IAX_IE_RR_PKTS, "RR_PKTS", dump_int}, {
IAX_IE_RR_DELAY, "RR_DELAY", dump_short}, {
IAX_IE_RR_DROPPED, "RR_DROPPED", dump_int}, {
IAX_IE_RR_OOO, "RR_OOO", dump_int},};
const char *iax_ie2str(int ie)
{
int x;
for (x=0;x<(int)sizeof(ies) / (int)sizeof(ies[0]); x++) {
for (x = 0; x < (int) sizeof(ies) / (int) sizeof(ies[0]); x++) {
if (ies[x].ie == ie)
return ies[x].name;
}
@@ -240,22 +239,25 @@ static void dump_prov_ies(char *output, int maxlen, unsigned char *iedata, int l
char tmp[256];
if (len < 2)
return;
strcpy(output, "\n");
maxlen -= (int)strlen(output); output += strlen(output);
while(len > 2) {
strcpy(output, "\n");
maxlen -= (int) strlen(output);
output += strlen(output);
while (len > 2) {
ie = iedata[0];
ielen = iedata[1];
if (ielen + 2> len) {
snprintf(tmp, (int)sizeof(tmp), "Total Prov IE length of %d bytes exceeds remaining prov frame length of %d bytes\n", ielen + 2, len);
if (ielen + 2 > len) {
snprintf(tmp, (int) sizeof(tmp), "Total Prov IE length of %d bytes exceeds remaining prov frame length of %d bytes\n", ielen + 2, len);
strncpy(output, tmp, maxlen - 1);
maxlen -= (int)strlen(output); output += strlen(output);
maxlen -= (int) strlen(output);
output += strlen(output);
return;
}
found = 0;
if (!found) {
snprintf(tmp, (int)sizeof(tmp), " Unknown Prov IE %03d : Present\n", ie);
snprintf(tmp, (int) sizeof(tmp), " Unknown Prov IE %03d : Present\n", ie);
strncpy(output, tmp, maxlen - 1);
maxlen -= (int)strlen(output); output += strlen(output);
maxlen -= (int) strlen(output);
output += strlen(output);
}
iedata += (2 + ielen);
len -= (2 + ielen);
@@ -272,34 +274,34 @@ static void dump_ies(unsigned char *iedata, int len)
char tmp[1024];
if (len < 2)
return;
while(len > 2) {
while (len > 2) {
ie = iedata[0];
ielen = iedata[1];
if (ielen + 2> len) {
snprintf(tmp, (int)sizeof(tmp), "Total IE length of %d bytes exceeds remaining frame length of %d bytes\n", ielen + 2, len);
if (ielen + 2 > len) {
snprintf(tmp, (int) sizeof(tmp), "Total IE length of %d bytes exceeds remaining frame length of %d bytes\n", ielen + 2, len);
outputf(tmp);
return;
}
found = 0;
for (x=0;x<(int)sizeof(ies) / (int)sizeof(ies[0]); x++) {
for (x = 0; x < (int) sizeof(ies) / (int) sizeof(ies[0]); x++) {
if (ies[x].ie == ie) {
if (ies[x].dump) {
ies[x].dump(interp, (int)sizeof(interp), iedata + 2, ielen);
snprintf(tmp, (int)sizeof(tmp), " %-15.15s : %s\n", ies[x].name, interp);
ies[x].dump(interp, (int) sizeof(interp), iedata + 2, ielen);
snprintf(tmp, (int) sizeof(tmp), " %-15.15s : %s\n", ies[x].name, interp);
outputf(tmp);
} else {
if (ielen)
snprintf(interp, (int)sizeof(interp), "%d bytes", ielen);
snprintf(interp, (int) sizeof(interp), "%d bytes", ielen);
else
strcpy(interp, "Present");
snprintf(tmp, (int)sizeof(tmp), " %-15.15s : %s\n", ies[x].name, interp);
snprintf(tmp, (int) sizeof(tmp), " %-15.15s : %s\n", ies[x].name, interp);
outputf(tmp);
}
found++;
}
}
if (!found) {
snprintf(tmp, (int)sizeof(tmp), " Unknown IE %03d : Present\n", ie);
snprintf(tmp, (int) sizeof(tmp), " Unknown IE %03d : Present\n", ie);
outputf(tmp);
}
iedata += (2 + ielen);
@@ -319,7 +321,8 @@ void iax_showframe(struct iax_frame *f, struct ast_iax2_full_hdr *fhi, int rx, s
"NULL ",
"IAX ",
"TEXT ",
"IMAGE " };
"IMAGE "
};
const char *iaxs[] = {
"(0?)",
"NEW ",
@@ -368,7 +371,8 @@ void iax_showframe(struct iax_frame *f, struct ast_iax2_full_hdr *fhi, int rx, s
"ANSWER ",
"BUSY ",
"TKOFFHK ",
"OFFHOOK" };
"OFFHOOK"
};
struct ast_iax2_full_hdr *fh;
char retries[20];
char class2[20];
@@ -379,7 +383,7 @@ void iax_showframe(struct iax_frame *f, struct ast_iax2_full_hdr *fhi, int rx, s
if (f) {
fh = f->data;
snprintf(retries, (int)sizeof(retries), "%03d", f->retries);
snprintf(retries, (int) sizeof(retries), "%03d", f->retries);
} else {
fh = fhi;
if (ntohs(fh->dcallno) & IAX_FLAG_RETRANS)
@@ -391,43 +395,41 @@ void iax_showframe(struct iax_frame *f, struct ast_iax2_full_hdr *fhi, int rx, s
/* Don't mess with mini-frames */
return;
}
if (fh->type > ((int)sizeof(frames)/(int)sizeof(char *)) - 1) {
snprintf(class2, (int)sizeof(class2), "(%d?)", fh->type);
if (fh->type > ((int) sizeof(frames) / (int) sizeof(char *)) - 1) {
snprintf(class2, (int) sizeof(class2), "(%d?)", fh->type);
class = class2;
} else {
class = frames[(int)fh->type];
class = frames[(int) fh->type];
}
if (fh->type == AST_FRAME_DTMF) {
sprintf(subclass2, "%c", fh->csub);
subclass = subclass2;
} else if (fh->type == AST_FRAME_IAX) {
if (fh->csub >= (int)sizeof(iaxs)/(int)sizeof(iaxs[0])) {
snprintf(subclass2, (int)sizeof(subclass2), "(%d?)", fh->csub);
if (fh->csub >= (int) sizeof(iaxs) / (int) sizeof(iaxs[0])) {
snprintf(subclass2, (int) sizeof(subclass2), "(%d?)", fh->csub);
subclass = subclass2;
} else {
subclass = iaxs[(int)fh->csub];
subclass = iaxs[(int) fh->csub];
}
} else if (fh->type == AST_FRAME_CONTROL) {
if (fh->csub > (int)sizeof(cmds)/(int)sizeof(char *)) {
snprintf(subclass2, (int)sizeof(subclass2), "(%d?)", fh->csub);
if (fh->csub > (int) sizeof(cmds) / (int) sizeof(char *)) {
snprintf(subclass2, (int) sizeof(subclass2), "(%d?)", fh->csub);
subclass = subclass2;
} else {
subclass = cmds[(int)fh->csub];
subclass = cmds[(int) fh->csub];
}
} else {
snprintf(subclass2, (int)sizeof(subclass2), "%d", fh->csub);
snprintf(subclass2, (int) sizeof(subclass2), "%d", fh->csub);
subclass = subclass2;
}
snprintf(tmp, (int)sizeof(tmp),
"%s-Frame Retry[%s] -- OSeqno: %3.3d ISeqno: %3.3d Type: %s Subclass: %s\n",
(rx ? "Rx" : "Tx"),
retries, fh->oseqno, fh->iseqno, class, subclass);
snprintf(tmp, (int) sizeof(tmp),
"%s-Frame Retry[%s] -- OSeqno: %3.3d ISeqno: %3.3d Type: %s Subclass: %s\n",
(rx ? "Rx" : "Tx"), retries, fh->oseqno, fh->iseqno, class, subclass);
outputf(tmp);
snprintf(tmp, (int)sizeof(tmp),
" Timestamp: %05lums SCall: %5.5d DCall: %5.5d [%s:%d]\n",
(unsigned long)ntohl(fh->ts),
ntohs(fh->scallno) & ~IAX_FLAG_FULL, ntohs(fh->dcallno) & ~IAX_FLAG_RETRANS,
inet_ntoa(sin->sin_addr), ntohs(sin->sin_port));
snprintf(tmp, (int) sizeof(tmp),
" Timestamp: %05lums SCall: %5.5d DCall: %5.5d [%s:%d]\n",
(unsigned long) ntohl(fh->ts),
ntohs(fh->scallno) & ~IAX_FLAG_FULL, ntohs(fh->dcallno) & ~IAX_FLAG_RETRANS, inet_ntoa(sin->sin_addr), ntohs(sin->sin_port));
outputf(tmp);
if (fh->type == AST_FRAME_IAX)
dump_ies(fh->iedata, datalen);
@@ -436,13 +438,14 @@ snprintf(tmp, (int)sizeof(tmp),
int iax_ie_append_raw(struct iax_ie_data *ied, unsigned char ie, const void *data, int datalen)
{
char tmp[256];
if (datalen > ((int)sizeof(ied->buf) - ied->pos)) {
snprintf(tmp, (int)sizeof(tmp), "Out of space for ie '%s' (%d), need %d have %d\n", iax_ie2str(ie), ie, datalen, (int)sizeof(ied->buf) - ied->pos);
if (datalen > ((int) sizeof(ied->buf) - ied->pos)) {
snprintf(tmp, (int) sizeof(tmp), "Out of space for ie '%s' (%d), need %d have %d\n", iax_ie2str(ie), ie, datalen,
(int) sizeof(ied->buf) - ied->pos);
errorf(tmp);
return -1;
}
ied->buf[ied->pos++] = ie;
ied->buf[ied->pos++] = (unsigned char)datalen;
ied->buf[ied->pos++] = (unsigned char) datalen;
memcpy(ied->buf + ied->pos, data, datalen);
ied->pos += datalen;
return 0;
@@ -450,26 +453,26 @@ int iax_ie_append_raw(struct iax_ie_data *ied, unsigned char ie, const void *dat
int iax_ie_append_addr(struct iax_ie_data *ied, unsigned char ie, struct sockaddr_in *sin)
{
return iax_ie_append_raw(ied, ie, sin, (int)sizeof(struct sockaddr_in));
return iax_ie_append_raw(ied, ie, sin, (int) sizeof(struct sockaddr_in));
}
int iax_ie_append_int(struct iax_ie_data *ied, unsigned char ie, unsigned int value)
int iax_ie_append_int(struct iax_ie_data *ied, unsigned char ie, unsigned int value)
{
unsigned int newval;
newval = htonl(value);
return iax_ie_append_raw(ied, ie, &newval, (int)sizeof(newval));
return iax_ie_append_raw(ied, ie, &newval, (int) sizeof(newval));
}
int iax_ie_append_short(struct iax_ie_data *ied, unsigned char ie, unsigned short value)
int iax_ie_append_short(struct iax_ie_data *ied, unsigned char ie, unsigned short value)
{
unsigned short newval;
newval = htons(value);
return iax_ie_append_raw(ied, ie, &newval, (int)sizeof(newval));
return iax_ie_append_raw(ied, ie, &newval, (int) sizeof(newval));
}
int iax_ie_append_str(struct iax_ie_data *ied, unsigned char ie, const unsigned char *str)
{
return iax_ie_append_raw(ied, ie, str, (int)strlen((char *) str));
return iax_ie_append_raw(ied, ie, str, (int) strlen((char *) str));
}
int iax_ie_append_byte(struct iax_ie_data *ied, unsigned char ie, unsigned char dat)
@@ -477,17 +480,17 @@ int iax_ie_append_byte(struct iax_ie_data *ied, unsigned char ie, unsigned char
return iax_ie_append_raw(ied, ie, &dat, 1);
}
int iax_ie_append(struct iax_ie_data *ied, unsigned char ie)
int iax_ie_append(struct iax_ie_data *ied, unsigned char ie)
{
return iax_ie_append_raw(ied, ie, NULL, 0);
}
void iax_set_output(void (*func)(const char *))
void iax_set_output(void (*func) (const char *))
{
outputf = func;
}
void iax_set_error(void (*func)(const char *))
void iax_set_error(void (*func) (const char *))
{
errorf = func;
}
@@ -498,21 +501,21 @@ int iax_parse_ies(struct iax_ies *my_ies, unsigned char *data, int datalen)
int len;
int ie;
char tmp[256];
memset(my_ies, 0, (int)sizeof(struct iax_ies));
memset(my_ies, 0, (int) sizeof(struct iax_ies));
my_ies->msgcount = -1;
my_ies->firmwarever = -1;
my_ies->calling_ton = -1;
my_ies->calling_tns = -1;
my_ies->calling_pres = -1;
my_ies->samprate = IAX_RATE_8KHZ;
while(datalen >= 2) {
while (datalen >= 2) {
ie = data[0];
len = data[1];
if (len > datalen - 2) {
errorf("Information element length exceeds message size\n");
return -1;
}
switch(ie) {
switch (ie) {
case IAX_IE_CALLED_NUMBER:
my_ies->called_number = (char *) data + 2;
break;
@@ -535,15 +538,15 @@ int iax_parse_ies(struct iax_ies *my_ies, unsigned char *data, int datalen)
my_ies->password = (char *) data + 2;
break;
case IAX_IE_CAPABILITY:
if (len != (int)sizeof(unsigned int)) {
snprintf(tmp, (int)sizeof(tmp), "Expecting capability to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
if (len != (int) sizeof(unsigned int)) {
snprintf(tmp, (int) sizeof(tmp), "Expecting capability to be %d bytes long but was %d\n", (int) sizeof(unsigned int), len);
errorf(tmp);
} else
my_ies->capability = ntohl(get_uint32(data + 2));
break;
case IAX_IE_FORMAT:
if (len != (int)sizeof(unsigned int)) {
snprintf(tmp, (int)sizeof(tmp), "Expecting format to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
if (len != (int) sizeof(unsigned int)) {
snprintf(tmp, (int) sizeof(tmp), "Expecting format to be %d bytes long but was %d\n", (int) sizeof(unsigned int), len);
errorf(tmp);
} else
my_ies->format = ntohl(get_uint32(data + 2));
@@ -555,22 +558,22 @@ int iax_parse_ies(struct iax_ies *my_ies, unsigned char *data, int datalen)
my_ies->codec_prefs = (char *) data + 2;
break;
case IAX_IE_VERSION:
if (len != (int)sizeof(unsigned short)) {
snprintf(tmp, (int)sizeof(tmp), "Expecting version to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
if (len != (int) sizeof(unsigned short)) {
snprintf(tmp, (int) sizeof(tmp), "Expecting version to be %d bytes long but was %d\n", (int) sizeof(unsigned short), len);
errorf(tmp);
} else
my_ies->version = ntohs(get_uint16(data + 2));
break;
case IAX_IE_ADSICPE:
if (len != (int)sizeof(unsigned short)) {
snprintf(tmp, (int)sizeof(tmp), "Expecting adsicpe to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
if (len != (int) sizeof(unsigned short)) {
snprintf(tmp, (int) sizeof(tmp), "Expecting adsicpe to be %d bytes long but was %d\n", (int) sizeof(unsigned short), len);
errorf(tmp);
} else
my_ies->adsicpe = ntohs(get_uint16(data + 2));
break;
case IAX_IE_SAMPLINGRATE:
if (len != (int)sizeof(unsigned short)) {
snprintf(tmp, (int)sizeof(tmp), "Expecting samplingrate to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
if (len != (int) sizeof(unsigned short)) {
snprintf(tmp, (int) sizeof(tmp), "Expecting samplingrate to be %d bytes long but was %d\n", (int) sizeof(unsigned short), len);
errorf(tmp);
} else
my_ies->samprate = ntohs(get_uint16(data + 2));
@@ -582,8 +585,8 @@ int iax_parse_ies(struct iax_ies *my_ies, unsigned char *data, int datalen)
my_ies->rdnis = (char *) data + 2;
break;
case IAX_IE_AUTHMETHODS:
if (len != (int)sizeof(unsigned short)) {
snprintf(tmp, (int)sizeof(tmp), "Expecting authmethods to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
if (len != (int) sizeof(unsigned short)) {
snprintf(tmp, (int) sizeof(tmp), "Expecting authmethods to be %d bytes long but was %d\n", (int) sizeof(unsigned short), len);
errorf(tmp);
} else
my_ies->authmethods = ntohs(get_uint16(data + 2));
@@ -598,25 +601,25 @@ int iax_parse_ies(struct iax_ies *my_ies, unsigned char *data, int datalen)
my_ies->rsa_result = (char *) data + 2;
break;
case IAX_IE_APPARENT_ADDR:
my_ies->apparent_addr = ((struct sockaddr_in *)(data + 2));
my_ies->apparent_addr = ((struct sockaddr_in *) (data + 2));
break;
case IAX_IE_REFRESH:
if (len != (int)sizeof(unsigned short)) {
snprintf(tmp, (int)sizeof(tmp), "Expecting refresh to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
if (len != (int) sizeof(unsigned short)) {
snprintf(tmp, (int) sizeof(tmp), "Expecting refresh to be %d bytes long but was %d\n", (int) sizeof(unsigned short), len);
errorf(tmp);
} else
my_ies->refresh = ntohs(get_uint16(data + 2));
break;
case IAX_IE_DPSTATUS:
if (len != (int)sizeof(unsigned short)) {
snprintf(tmp, (int)sizeof(tmp), "Expecting dpstatus to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
if (len != (int) sizeof(unsigned short)) {
snprintf(tmp, (int) sizeof(tmp), "Expecting dpstatus to be %d bytes long but was %d\n", (int) sizeof(unsigned short), len);
errorf(tmp);
} else
my_ies->dpstatus = ntohs(get_uint16(data + 2));
break;
case IAX_IE_CALLNO:
if (len != (int)sizeof(unsigned short)) {
snprintf(tmp, (int)sizeof(tmp), "Expecting callno to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
if (len != (int) sizeof(unsigned short)) {
snprintf(tmp, (int) sizeof(tmp), "Expecting callno to be %d bytes long but was %d\n", (int) sizeof(unsigned short), len);
errorf(tmp);
} else
my_ies->callno = ntohs(get_uint16(data + 2));
@@ -626,7 +629,7 @@ int iax_parse_ies(struct iax_ies *my_ies, unsigned char *data, int datalen)
break;
case IAX_IE_CAUSECODE:
if (len != 1) {
snprintf(tmp, (int)sizeof(tmp), "Expecting causecode to be single byte but was %d\n", len);
snprintf(tmp, (int) sizeof(tmp), "Expecting causecode to be single byte but was %d\n", len);
errorf(tmp);
} else {
my_ies->causecode = data[2];
@@ -636,16 +639,16 @@ int iax_parse_ies(struct iax_ies *my_ies, unsigned char *data, int datalen)
if (len == 1)
my_ies->iax_unknown = data[2];
else {
snprintf(tmp, (int)sizeof(tmp), "Expected single byte Unknown command, but was %d long\n", len);
snprintf(tmp, (int) sizeof(tmp), "Expected single byte Unknown command, but was %d long\n", len);
errorf(tmp);
}
break;
case IAX_IE_MSGCOUNT:
if (len != (int)sizeof(unsigned short)) {
snprintf(tmp, (int)sizeof(tmp), "Expecting msgcount to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
if (len != (int) sizeof(unsigned short)) {
snprintf(tmp, (int) sizeof(tmp), "Expecting msgcount to be %d bytes long but was %d\n", (int) sizeof(unsigned short), len);
errorf(tmp);
} else
my_ies->msgcount = ntohs(get_uint16(data + 2));
my_ies->msgcount = ntohs(get_uint16(data + 2));
break;
case IAX_IE_AUTOANSWER:
my_ies->autoanswer = 1;
@@ -654,25 +657,25 @@ int iax_parse_ies(struct iax_ies *my_ies, unsigned char *data, int datalen)
my_ies->musiconhold = 1;
break;
case IAX_IE_TRANSFERID:
if (len != (int)sizeof(unsigned int)) {
snprintf(tmp, (int)sizeof(tmp), "Expecting transferid to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
if (len != (int) sizeof(unsigned int)) {
snprintf(tmp, (int) sizeof(tmp), "Expecting transferid to be %d bytes long but was %d\n", (int) sizeof(unsigned int), len);
errorf(tmp);
} else
my_ies->transferid = ntohl(get_uint32(data + 2));
break;
case IAX_IE_DATETIME:
if (len != (int)sizeof(unsigned int)) {
snprintf(tmp, (int)sizeof(tmp), "Expecting date/time to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
if (len != (int) sizeof(unsigned int)) {
snprintf(tmp, (int) sizeof(tmp), "Expecting date/time to be %d bytes long but was %d\n", (int) sizeof(unsigned int), len);
errorf(tmp);
} else
my_ies->datetime = ntohl(get_uint32(data + 2));
break;
case IAX_IE_FIRMWAREVER:
if (len != (int)sizeof(unsigned short)) {
snprintf(tmp, (int)sizeof(tmp), "Expecting firmwarever to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
if (len != (int) sizeof(unsigned short)) {
snprintf(tmp, (int) sizeof(tmp), "Expecting firmwarever to be %d bytes long but was %d\n", (int) sizeof(unsigned short), len);
errorf(tmp);
} else
my_ies->firmwarever = ntohs(get_uint16(data + 2));
my_ies->firmwarever = ntohs(get_uint16(data + 2));
break;
case IAX_IE_DEVICETYPE:
my_ies->devicetype = (char *) data + 2;
@@ -681,19 +684,19 @@ int iax_parse_ies(struct iax_ies *my_ies, unsigned char *data, int datalen)
my_ies->serviceident = (char *) data + 2;
break;
case IAX_IE_FWBLOCKDESC:
if (len != (int)sizeof(unsigned int)) {
snprintf(tmp, (int)sizeof(tmp), "Expected block desc to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
if (len != (int) sizeof(unsigned int)) {
snprintf(tmp, (int) sizeof(tmp), "Expected block desc to be %d bytes long but was %d\n", (int) sizeof(unsigned int), len);
errorf(tmp);
} else
my_ies->fwdesc = ntohl(get_uint32(data + 2));
break;
case IAX_IE_FWBLOCKDATA:
my_ies->fwdata = data + 2;
my_ies->fwdatalen = (unsigned char)len;
my_ies->fwdatalen = (unsigned char) len;
break;
case IAX_IE_PROVVER:
if (len != (int)sizeof(unsigned int)) {
snprintf(tmp, (int)sizeof(tmp), "Expected provisioning version to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
if (len != (int) sizeof(unsigned int)) {
snprintf(tmp, (int) sizeof(tmp), "Expected provisioning version to be %d bytes long but was %d\n", (int) sizeof(unsigned int), len);
errorf(tmp);
} else {
my_ies->provverpres = 1;
@@ -704,7 +707,7 @@ int iax_parse_ies(struct iax_ies *my_ies, unsigned char *data, int datalen)
if (len == 1)
my_ies->calling_pres = data[2];
else {
snprintf(tmp, (int)sizeof(tmp), "Expected single byte callingpres, but was %d long\n", len);
snprintf(tmp, (int) sizeof(tmp), "Expected single byte callingpres, but was %d long\n", len);
errorf(tmp);
}
break;
@@ -712,67 +715,67 @@ int iax_parse_ies(struct iax_ies *my_ies, unsigned char *data, int datalen)
if (len == 1)
my_ies->calling_ton = data[2];
else {
snprintf(tmp, (int)sizeof(tmp), "Expected single byte callington, but was %d long\n", len);
snprintf(tmp, (int) sizeof(tmp), "Expected single byte callington, but was %d long\n", len);
errorf(tmp);
}
break;
case IAX_IE_CALLINGTNS:
if (len != (int)sizeof(unsigned short)) {
snprintf(tmp, (int)sizeof(tmp), "Expecting callingtns to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
if (len != (int) sizeof(unsigned short)) {
snprintf(tmp, (int) sizeof(tmp), "Expecting callingtns to be %d bytes long but was %d\n", (int) sizeof(unsigned short), len);
errorf(tmp);
} else
my_ies->calling_tns = ntohs(get_uint16(data + 2));
my_ies->calling_tns = ntohs(get_uint16(data + 2));
break;
case IAX_IE_RR_JITTER:
if (len != (int)sizeof(unsigned int)) {
snprintf(tmp, (int)sizeof(tmp), "Expected jitter rr to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
if (len != (int) sizeof(unsigned int)) {
snprintf(tmp, (int) sizeof(tmp), "Expected jitter rr to be %d bytes long but was %d\n", (int) sizeof(unsigned int), len);
errorf(tmp);
} else {
my_ies->rr_jitter = ntohl(get_uint32(data + 2));
}
break;
case IAX_IE_RR_LOSS:
if (len != (int)sizeof(unsigned int)) {
snprintf(tmp, (int)sizeof(tmp), "Expected loss rr to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
if (len != (int) sizeof(unsigned int)) {
snprintf(tmp, (int) sizeof(tmp), "Expected loss rr to be %d bytes long but was %d\n", (int) sizeof(unsigned int), len);
errorf(tmp);
} else {
my_ies->rr_loss = ntohl(get_uint32(data + 2));
}
break;
case IAX_IE_RR_PKTS:
if (len != (int)sizeof(unsigned int)) {
snprintf(tmp, (int)sizeof(tmp), "Expected packets rr to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
if (len != (int) sizeof(unsigned int)) {
snprintf(tmp, (int) sizeof(tmp), "Expected packets rr to be %d bytes long but was %d\n", (int) sizeof(unsigned int), len);
errorf(tmp);
} else {
my_ies->rr_pkts = ntohl(get_uint32(data + 2));
}
break;
case IAX_IE_RR_DELAY:
if (len != (int)sizeof(unsigned short)) {
snprintf(tmp, (int)sizeof(tmp), "Expected loss rr to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
if (len != (int) sizeof(unsigned short)) {
snprintf(tmp, (int) sizeof(tmp), "Expected loss rr to be %d bytes long but was %d\n", (int) sizeof(unsigned short), len);
errorf(tmp);
} else {
my_ies->rr_delay = ntohs(get_uint16(data + 2));
}
break;
case IAX_IE_RR_DROPPED:
if (len != (int)sizeof(unsigned int)) {
snprintf(tmp, (int)sizeof(tmp), "Expected packets rr to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
if (len != (int) sizeof(unsigned int)) {
snprintf(tmp, (int) sizeof(tmp), "Expected packets rr to be %d bytes long but was %d\n", (int) sizeof(unsigned int), len);
errorf(tmp);
} else {
my_ies->rr_dropped = ntohl(get_uint32(data + 2));
}
break;
case IAX_IE_RR_OOO:
if (len != (int)sizeof(unsigned int)) {
snprintf(tmp, (int)sizeof(tmp), "Expected packets rr to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
if (len != (int) sizeof(unsigned int)) {
snprintf(tmp, (int) sizeof(tmp), "Expected packets rr to be %d bytes long but was %d\n", (int) sizeof(unsigned int), len);
errorf(tmp);
} else {
my_ies->rr_ooo = ntohl(get_uint32(data + 2));
}
break;
default:
snprintf(tmp, (int)sizeof(tmp), "Ignoring unknown information element '%s' (%d) of length %d\n", iax_ie2str(ie), ie, len);
snprintf(tmp, (int) sizeof(tmp), "Ignoring unknown information element '%s' (%d) of length %d\n", iax_ie2str(ie), ie, len);
outputf(tmp);
}
/* Overwrite information element with 0, to null terminate previous portion */
@@ -793,20 +796,20 @@ void iax_frame_wrap(struct iax_frame *fr, struct ast_frame *f)
{
fr->af.frametype = f->frametype;
fr->af.subclass = f->subclass;
fr->af.mallocd = 0; /* Our frame is static relative to the container */
fr->af.mallocd = 0; /* Our frame is static relative to the container */
fr->af.datalen = f->datalen;
fr->af.samples = f->samples;
fr->af.offset = AST_FRIENDLY_OFFSET;
fr->af.src = f->src;
fr->af.data = fr->afdata;
if (fr->af.datalen)
if (fr->af.datalen)
memcpy(fr->af.data, f->data, fr->af.datalen);
}
struct iax_frame *iax_frame_new(int direction, int datalen)
{
struct iax_frame *fr;
fr = malloc((int)sizeof(struct iax_frame) + datalen);
fr = malloc((int) sizeof(struct iax_frame) + datalen);
if (fr) {
fr->direction = direction;
fr->retrans = -1;
@@ -835,6 +838,15 @@ void iax_frame_free(struct iax_frame *fr)
frame_count--;
}
int iax_get_frames(void) { return frame_count; }
int iax_get_iframes(void) { return iframes; }
int iax_get_oframes(void) { return oframes; }
int iax_get_frames(void)
{
return frame_count;
}
int iax_get_iframes(void)
{
return iframes;
}
int iax_get_oframes(void)
{
return oframes;
}
+90 -100
View File
@@ -32,9 +32,9 @@
#define jb_dbg if (dbgf) dbgf
#ifdef DEEP_DEBUG
#define jb_dbg2 if (dbgf) dbgf
#define jb_dbg2 if (dbgf) dbgf
#else
#define jb_dbg2 if (0) dbgf
#define jb_dbg2 if (0) dbgf
#endif
#else
@@ -60,17 +60,17 @@ void jb_setoutput(jb_output_function_t err, jb_output_function_t warn, jb_output
dbgf = dbg;
}
static void increment_losspct(jitterbuf *jb)
static void increment_losspct(jitterbuf * jb)
{
jb->info.losspct = (100000 + 499 * jb->info.losspct)/500;
jb->info.losspct = (100000 + 499 * jb->info.losspct) / 500;
}
static void decrement_losspct(jitterbuf *jb)
static void decrement_losspct(jitterbuf * jb)
{
jb->info.losspct = (499 * jb->info.losspct)/500;
jb->info.losspct = (499 * jb->info.losspct) / 500;
}
void jb_reset(jitterbuf *jb)
void jb_reset(jitterbuf * jb)
{
/* only save settings */
jb_conf s = jb->info.conf;
@@ -82,11 +82,12 @@ void jb_reset(jitterbuf *jb)
jb->info.silence_begin_ts = -1;
}
jitterbuf * jb_new()
jitterbuf *jb_new()
{
jitterbuf *jb = (jitterbuf *)malloc(sizeof(*jb));
jitterbuf *jb = (jitterbuf *) malloc(sizeof(*jb));
if (!jb) return NULL;
if (!jb)
return NULL;
jb->info.conf.target_extra = JB_TARGET_EXTRA;
@@ -95,7 +96,7 @@ jitterbuf * jb_new()
return jb;
}
void jb_destroy(jitterbuf *jb)
void jb_destroy(jitterbuf * jb)
{
jb_frame *frame;
@@ -116,7 +117,7 @@ void jb_destroy(jitterbuf *jb)
#if 0
static int longcmp(const void *a, const void *b)
{
return *(long *)a - *(long *)b;
return *(long *) a - *(long *) b;
}
#endif
@@ -124,7 +125,7 @@ static int longcmp(const void *a, const void *b)
/* maybe later we can make the history buckets variable size, or something? */
/* drop parameter determines whether we will drop outliers to minimize
* delay */
static int history_put(jitterbuf *jb, time_in_ms_t ts, time_in_ms_t now)
static int history_put(jitterbuf * jb, time_in_ms_t ts, time_in_ms_t now)
{
time_in_ms_t delay = now - (ts - jb->info.resync_offset);
time_in_ms_t threshold = 2 * jb->info.jitter + jb->info.conf.resync_threshold;
@@ -144,9 +145,10 @@ static int history_put(jitterbuf *jb, time_in_ms_t ts, time_in_ms_t now)
jb->hist_ptr = 0;
jb->hist_maxbuf_valid = 0;
jb_warn("Resyncing the jb. last_delay %ld, this delay %ld, threshold %ld, new offset %ld\n", jb->info.last_delay, delay, threshold, ts - now);
jb_warn("Resyncing the jb. last_delay %ld, this delay %ld, threshold %ld, new offset %ld\n", jb->info.last_delay, delay, threshold,
ts - now);
jb->info.resync_offset = ts - now;
jb->info.last_delay = delay = 0; /* after resync, frame is right on time */
jb->info.last_delay = delay = 0; /* after resync, frame is right on time */
} else {
return -1;
}
@@ -176,18 +178,18 @@ static int history_put(jitterbuf *jb, time_in_ms_t ts, time_in_ms_t now)
goto invalidate;
/* if the new delay would go into min */
if (delay < jb->hist_minbuf[JB_HISTORY_MAXBUF_SZ-1])
if (delay < jb->hist_minbuf[JB_HISTORY_MAXBUF_SZ - 1])
goto invalidate;
/* or max.. */
if (delay > jb->hist_maxbuf[JB_HISTORY_MAXBUF_SZ-1])
if (delay > jb->hist_maxbuf[JB_HISTORY_MAXBUF_SZ - 1])
goto invalidate;
/* or the kicked delay would be in min */
if (kicked <= jb->hist_minbuf[JB_HISTORY_MAXBUF_SZ-1])
if (kicked <= jb->hist_minbuf[JB_HISTORY_MAXBUF_SZ - 1])
goto invalidate;
if (kicked >= jb->hist_maxbuf[JB_HISTORY_MAXBUF_SZ-1])
if (kicked >= jb->hist_maxbuf[JB_HISTORY_MAXBUF_SZ - 1])
goto invalidate;
/* if we got here, we don't need to invalidate, 'cause this delay didn't
@@ -196,21 +198,21 @@ static int history_put(jitterbuf *jb, time_in_ms_t ts, time_in_ms_t now)
/* end optimization */
invalidate:
invalidate:
jb->hist_maxbuf_valid = 0;
return 0;
}
static void history_calc_maxbuf(jitterbuf *jb)
static void history_calc_maxbuf(jitterbuf * jb)
{
int i,j;
int i, j;
if (jb->hist_ptr == 0)
return;
/* initialize maxbuf/minbuf to the latest value */
for (i=0;i<JB_HISTORY_MAXBUF_SZ;i++) {
for (i = 0; i < JB_HISTORY_MAXBUF_SZ; i++) {
/*
* jb->hist_maxbuf[i] = jb->history[(jb->hist_ptr-1) % JB_HISTORY_SZ];
* jb->hist_minbuf[i] = jb->history[(jb->hist_ptr-1) % JB_HISTORY_SZ];
@@ -225,14 +227,14 @@ static void history_calc_maxbuf(jitterbuf *jb)
/* start at the beginning, or JB_HISTORY_SZ frames ago */
i = (jb->hist_ptr > JB_HISTORY_SZ) ? (jb->hist_ptr - JB_HISTORY_SZ) : 0;
for (;i<jb->hist_ptr;i++) {
time_in_ms_t toins = jb->history[i % JB_HISTORY_SZ];
for (; i < jb->hist_ptr; i++) {
time_in_ms_t toins = jb->history[i % JB_HISTORY_SZ];
/* if the maxbuf should get this */
if (toins > jb->hist_maxbuf[JB_HISTORY_MAXBUF_SZ-1]) {
if (toins > jb->hist_maxbuf[JB_HISTORY_MAXBUF_SZ - 1]) {
/* insertion-sort it into the maxbuf */
for (j=0;j<JB_HISTORY_MAXBUF_SZ;j++) {
for (j = 0; j < JB_HISTORY_MAXBUF_SZ; j++) {
/* found where it fits */
if (toins > jb->hist_maxbuf[j]) {
/* move over */
@@ -246,10 +248,10 @@ static void history_calc_maxbuf(jitterbuf *jb)
}
/* if the minbuf should get this */
if (toins < jb->hist_minbuf[JB_HISTORY_MAXBUF_SZ-1]) {
if (toins < jb->hist_minbuf[JB_HISTORY_MAXBUF_SZ - 1]) {
/* insertion-sort it into the maxbuf */
for (j=0;j<JB_HISTORY_MAXBUF_SZ;j++) {
for (j = 0; j < JB_HISTORY_MAXBUF_SZ; j++) {
/* found where it fits */
if (toins < jb->hist_minbuf[j]) {
/* move over */
@@ -261,15 +263,14 @@ static void history_calc_maxbuf(jitterbuf *jb)
}
}
}
#if 0
int k;
fprintf(stderr, "toins = %ld\n", toins);
fprintf(stderr, "maxbuf =");
for (k=0;k<JB_HISTORY_MAXBUF_SZ;k++)
for (k = 0; k < JB_HISTORY_MAXBUF_SZ; k++)
fprintf(stderr, "%ld ", jb->hist_maxbuf[k]);
fprintf(stderr, "\nminbuf =");
for (k=0;k<JB_HISTORY_MAXBUF_SZ;k++)
for (k = 0; k < JB_HISTORY_MAXBUF_SZ; k++)
fprintf(stderr, "%ld ", jb->hist_minbuf[k]);
fprintf(stderr, "\n");
#endif
@@ -278,9 +279,9 @@ static void history_calc_maxbuf(jitterbuf *jb)
jb->hist_maxbuf_valid = 1;
}
static void history_get(jitterbuf *jb)
static void history_get(jitterbuf * jb)
{
time_in_ms_t max, min, jitter;
time_in_ms_t max, min, jitter;
int index;
int count;
@@ -312,16 +313,16 @@ static void history_get(jitterbuf *jb)
/* these debug stmts compare the difference between looking at the absolute jitter, and the
* values we get by throwing away the outliers */
/*
fprintf(stderr, "[%d] min=%d, max=%d, jitter=%d\n", index, min, max, jitter);
fprintf(stderr, "[%d] min=%d, max=%d, jitter=%d\n", 0, jb->hist_minbuf[0], jb->hist_maxbuf[0], jb->hist_maxbuf[0]-jb->hist_minbuf[0]);
*/
fprintf(stderr, "[%d] min=%d, max=%d, jitter=%d\n", index, min, max, jitter);
fprintf(stderr, "[%d] min=%d, max=%d, jitter=%d\n", 0, jb->hist_minbuf[0], jb->hist_maxbuf[0], jb->hist_maxbuf[0]-jb->hist_minbuf[0]);
*/
jb->info.min = min;
jb->info.jitter = jitter;
}
/* returns 1 if frame was inserted into head of queue, 0 otherwise */
static int queue_put(jitterbuf *jb, void *data, const enum jb_frame_type type, long ms, time_in_ms_t ts)
static int queue_put(jitterbuf * jb, void *data, const enum jb_frame_type type, long ms, time_in_ms_t ts)
{
jb_frame *frame = jb->free;
jb_frame *p;
@@ -331,7 +332,7 @@ static int queue_put(jitterbuf *jb, void *data, const enum jb_frame_type type, l
if (frame) {
jb->free = frame->next;
} else {
frame = (jb_frame *)malloc(sizeof(*frame));
frame = (jb_frame *) malloc(sizeof(*frame));
if (!frame) {
jb_err("cannot allocate frame\n");
return 0;
@@ -350,7 +351,7 @@ static int queue_put(jitterbuf *jb, void *data, const enum jb_frame_type type, l
* jb->frames->prev points to the highest ts
*/
if (!jb->frames) { /* queue is empty */
if (!jb->frames) { /* queue is empty */
jb->frames = frame;
frame->next = frame;
frame->prev = frame;
@@ -371,7 +372,8 @@ static int queue_put(jitterbuf *jb, void *data, const enum jb_frame_type type, l
p = jb->frames;
/* frame is out of order */
if (resync_ts < p->prev->ts) jb->info.frames_ooo++;
if (resync_ts < p->prev->ts)
jb->info.frames_ooo++;
while (resync_ts < p->prev->ts && p->prev != jb->frames)
p = p->prev;
@@ -385,7 +387,7 @@ static int queue_put(jitterbuf *jb, void *data, const enum jb_frame_type type, l
return head;
}
static time_in_ms_t queue_next(jitterbuf *jb)
static time_in_ms_t queue_next(jitterbuf * jb)
{
if (jb->frames)
return jb->frames->ts;
@@ -393,7 +395,7 @@ static time_in_ms_t queue_next(jitterbuf *jb)
return -1;
}
static time_in_ms_t queue_last(jitterbuf *jb)
static time_in_ms_t queue_last(jitterbuf * jb)
{
if (jb->frames)
return jb->frames->prev->ts;
@@ -401,7 +403,7 @@ static time_in_ms_t queue_last(jitterbuf *jb)
return -1;
}
static jb_frame *_queue_get(jitterbuf *jb, time_in_ms_t ts, int all)
static jb_frame *_queue_get(jitterbuf * jb, time_in_ms_t ts, int all)
{
jb_frame *frame;
frame = jb->frames;
@@ -436,46 +438,41 @@ static jb_frame *_queue_get(jitterbuf *jb, time_in_ms_t ts, int all)
return NULL;
}
static jb_frame *queue_get(jitterbuf *jb, time_in_ms_t ts)
static jb_frame *queue_get(jitterbuf * jb, time_in_ms_t ts)
{
return _queue_get(jb,ts,0);
return _queue_get(jb, ts, 0);
}
static jb_frame *queue_getall(jitterbuf *jb)
static jb_frame *queue_getall(jitterbuf * jb)
{
return _queue_get(jb,0,1);
return _queue_get(jb, 0, 1);
}
#if 0
/* some diagnostics */
static void jb_dbginfo(jitterbuf *jb)
static void jb_dbginfo(jitterbuf * jb)
{
if (dbgf == NULL)
return;
jb_dbg("\njb info: fin=%ld fout=%ld flate=%ld flost=%ld fdrop=%ld fcur=%ld\n",
jb->info.frames_in, jb->info.frames_out, jb->info.frames_late, jb->info.frames_lost, jb->info.frames_dropped, jb->info.frames_cur);
jb->info.frames_in, jb->info.frames_out, jb->info.frames_late, jb->info.frames_lost, jb->info.frames_dropped, jb->info.frames_cur);
jb_dbg("jitter=%ld current=%ld target=%ld min=%ld sil=%d len=%d len/fcur=%ld\n",
jb->info.jitter, jb->info.current, jb->info.target, jb->info.min, jb->info.silence_begin_ts, jb->info.current - jb->info.min,
jb->info.frames_cur ? (jb->info.current - jb->info.min)/jb->info.frames_cur : -8);
jb->info.jitter, jb->info.current, jb->info.target, jb->info.min, jb->info.silence_begin_ts, jb->info.current - jb->info.min,
jb->info.frames_cur ? (jb->info.current - jb->info.min) / jb->info.frames_cur : -8);
if (jb->info.frames_in > 0)
jb_dbg("jb info: Loss PCT = %ld%%, Late PCT = %ld%%\n",
jb->info.frames_lost * 100/(jb->info.frames_in + jb->info.frames_lost),
jb->info.frames_late * 100/jb->info.frames_in);
jb->info.frames_lost * 100 / (jb->info.frames_in + jb->info.frames_lost), jb->info.frames_late * 100 / jb->info.frames_in);
jb_dbg("jb info: queue %d -> %d. last_ts %d (queue len: %d) last_ms %d\n",
queue_next(jb),
queue_last(jb),
jb->info.next_voice_ts,
queue_last(jb) - queue_next(jb),
jb->info.last_voice_ms);
queue_next(jb), queue_last(jb), jb->info.next_voice_ts, queue_last(jb) - queue_next(jb), jb->info.last_voice_ms);
}
#endif
#ifdef DEEP_DEBUG
static void jb_chkqueue(jitterbuf *jb)
static void jb_chkqueue(jitterbuf * jb)
{
int i=0;
int i = 0;
jb_frame *p = jb->frames;
if (!p) {
@@ -483,17 +480,17 @@ static void jb_chkqueue(jitterbuf *jb)
}
do {
if (p->next == NULL) {
if (p->next == NULL) {
jb_err("Queue is BROKEN at item [%d]", i);
}
i++;
p=p->next;
p = p->next;
} while (p->next != jb->frames);
}
static void jb_dbgqueue(jitterbuf *jb)
static void jb_dbgqueue(jitterbuf * jb)
{
int i=0;
int i = 0;
jb_frame *p = jb->frames;
jb_dbg("queue: ");
@@ -505,14 +502,14 @@ static void jb_dbgqueue(jitterbuf *jb)
do {
jb_dbg("[%d]=%ld ", i++, p->ts);
p=p->next;
p = p->next;
} while (p->next != jb->frames);
jb_dbg("\n");
}
#endif
enum jb_return_code jb_put(jitterbuf *jb, void *data, const enum jb_frame_type type, long ms, time_in_ms_t ts, time_in_ms_t now)
enum jb_return_code jb_put(jitterbuf * jb, void *data, const enum jb_frame_type type, long ms, time_in_ms_t ts, time_in_ms_t now)
{
jb->info.frames_in++;
@@ -522,12 +519,12 @@ enum jb_return_code jb_put(jitterbuf *jb, void *data, const enum jb_frame_type t
* sending retransmitted control frames with their awkward
* timestamps through
*/
if (history_put(jb,ts,now))
if (history_put(jb, ts, now))
return JB_DROP;
}
/* if put into head of queue, caller needs to reschedule */
if (queue_put(jb,data,type,ms,ts)) {
if (queue_put(jb, data, type, ms, ts)) {
return JB_SCHED;
}
@@ -535,7 +532,7 @@ enum jb_return_code jb_put(jitterbuf *jb, void *data, const enum jb_frame_type t
}
static enum jb_return_code _jb_get(jitterbuf *jb, jb_frame *frameout, time_in_ms_t now, long interpl)
static enum jb_return_code _jb_get(jitterbuf * jb, jb_frame * frameout, time_in_ms_t now, long interpl)
{
jb_frame *frame;
time_in_ms_t diff;
@@ -557,7 +554,7 @@ static enum jb_return_code _jb_get(jitterbuf *jb, jb_frame *frameout, time_in_ms
diff = jb->info.target - jb->info.current;
/* jb_warn("diff = %d lms=%d last = %d now = %d\n", diff, */
/* jb->info.last_voice_ms, jb->info.last_adjustment, now); */
/* jb->info.last_voice_ms, jb->info.last_adjustment, now); */
/* let's work on non-silent case first */
if (!jb->info.silence_begin_ts) {
@@ -565,8 +562,8 @@ static enum jb_return_code _jb_get(jitterbuf *jb, jb_frame *frameout, time_in_ms
if ((diff > 0) &&
/* we haven't grown in the delay length */
(((jb->info.last_adjustment + JB_ADJUST_DELAY) < now) ||
/* we need to grow more than the "length" we have left */
(diff > queue_last(jb) - queue_next(jb)) ) ) {
/* we need to grow more than the "length" we have left */
(diff > queue_last(jb) - queue_next(jb)))) {
/* grow by interp frame length */
jb->info.current += interpl;
jb->info.next_voice_ts += interpl;
@@ -619,7 +616,7 @@ static enum jb_return_code _jb_get(jitterbuf *jb, jb_frame *frameout, time_in_ms
jb->info.frames_lost--;
jb_dbg("l");
/*jb_warn("\nlate: wanted=%ld, this=%ld, next=%ld\n", jb->info.next_voice_ts - jb->info.current, frame->ts, queue_next(jb));
jb_warninfo(jb); */
jb_warninfo(jb); */
return JB_DROP;
}
}
@@ -633,9 +630,7 @@ static enum jb_return_code _jb_get(jitterbuf *jb, jb_frame *frameout, time_in_ms
/* unless we don't have a frame, then shrink 1 frame */
/* every 80ms (though perhaps we can shrink even faster */
/* in this case) */
if (diff < -jb->info.conf.target_extra &&
((!frame && jb->info.last_adjustment + 80 < now) ||
(jb->info.last_adjustment + 500 < now))) {
if (diff < -jb->info.conf.target_extra && ((!frame && jb->info.last_adjustment + 80 < now) || (jb->info.last_adjustment + 500 < now))) {
jb->info.last_adjustment = now;
jb->info.cnt_contig_interp = 0;
@@ -677,11 +672,11 @@ static enum jb_return_code _jb_get(jitterbuf *jb, jb_frame *frameout, time_in_ms
* lost frame get interpolated two or more times, when there was "room" to grow, so it might
* be a bit of a bad idea overall */
/*if (diff > -1 * jb->info.last_voice_ms) {
jb->info.current += jb->info.last_voice_ms;
jb->info.last_adjustment = now;
jb_warn("g");
return JB_INTERP;
} */
jb->info.current += jb->info.last_voice_ms;
jb->info.last_adjustment = now;
jb_warn("g");
return JB_INTERP;
} */
jb->info.frames_lost++;
increment_losspct(jb);
jb->info.next_voice_ts += interpl;
@@ -712,8 +707,7 @@ static enum jb_return_code _jb_get(jitterbuf *jb, jb_frame *frameout, time_in_ms
/* jb->info.silence_begin_ts = 0; */
/* shrink interpl len every 10ms during silence */
if (diff < -jb->info.conf.target_extra &&
jb->info.last_adjustment + 10 <= now) {
if (diff < -jb->info.conf.target_extra && jb->info.last_adjustment + 10 <= now) {
jb->info.current -= interpl;
jb->info.last_adjustment = now;
}
@@ -736,7 +730,7 @@ static enum jb_return_code _jb_get(jitterbuf *jb, jb_frame *frameout, time_in_ms
jb->info.frames_lost--;
jb_dbg("l");
/*jb_warn("\nlate: wanted=%ld, this=%ld, next=%ld\n", jb->info.next_voice_ts - jb->info.current, frame->ts, queue_next(jb));
jb_warninfo(jb); */
jb_warninfo(jb); */
return JB_DROP;
} else {
/* voice frame */
@@ -754,7 +748,7 @@ static enum jb_return_code _jb_get(jitterbuf *jb, jb_frame *frameout, time_in_ms
}
}
time_in_ms_t jb_next(jitterbuf *jb)
time_in_ms_t jb_next(jitterbuf * jb)
{
if (jb->info.silence_begin_ts) {
if (jb->frames) {
@@ -764,28 +758,28 @@ time_in_ms_t jb_next(jitterbuf *jb)
if (jb->info.target - jb->info.current < -jb->info.conf.target_extra)
return jb->info.last_adjustment + 10;
return next + jb->info.target;
}
else
} else
return JB_LONGMAX;
} else {
return jb->info.next_voice_ts;
}
}
enum jb_return_code jb_get(jitterbuf *jb, jb_frame *frameout, time_in_ms_t now, long interpl)
enum jb_return_code jb_get(jitterbuf * jb, jb_frame * frameout, time_in_ms_t now, long interpl)
{
enum jb_return_code ret = _jb_get(jb, frameout, now, interpl);
#if 0
static int lastts=0;
static int lastts = 0;
int thists = ((ret == JB_OK) || (ret == JB_DROP)) ? frameout->ts : 0;
jb_warn("jb_get(%x,%x,%ld) = %d (%d)\n", jb, frameout, now, ret, thists);
if (thists && thists < lastts) jb_warn("XXXX timestamp roll-back!!!\n");
if (thists && thists < lastts)
jb_warn("XXXX timestamp roll-back!!!\n");
lastts = thists;
#endif
return ret;
}
enum jb_return_code jb_getall(jitterbuf *jb, jb_frame *frameout)
enum jb_return_code jb_getall(jitterbuf * jb, jb_frame * frameout)
{
jb_frame *frame;
frame = queue_getall(jb);
@@ -799,7 +793,7 @@ enum jb_return_code jb_getall(jitterbuf *jb, jb_frame *frameout)
}
enum jb_return_code jb_getinfo(jitterbuf *jb, jb_info *stats)
enum jb_return_code jb_getinfo(jitterbuf * jb, jb_info * stats)
{
history_get(jb);
@@ -808,7 +802,7 @@ enum jb_return_code jb_getinfo(jitterbuf *jb, jb_info *stats)
return JB_OK;
}
enum jb_return_code jb_setconf(jitterbuf *jb, jb_conf *conf)
enum jb_return_code jb_setconf(jitterbuf * jb, jb_conf * conf)
{
/* take selected settings from the struct */
@@ -817,10 +811,8 @@ enum jb_return_code jb_setconf(jitterbuf *jb, jb_conf *conf)
jb->info.conf.max_contig_interp = conf->max_contig_interp;
/* -1 indicates use of the default JB_TARGET_EXTRA value */
jb->info.conf.target_extra = ( conf->target_extra == -1 )
? JB_TARGET_EXTRA
: conf->target_extra
;
jb->info.conf.target_extra = (conf->target_extra == -1)
? JB_TARGET_EXTRA : conf->target_extra;
/* update these to match new target_extra setting */
jb->info.current = jb->info.conf.target_extra;
@@ -828,5 +820,3 @@ enum jb_return_code jb_setconf(jitterbuf *jb, jb_conf *conf)
return JB_OK;
}
+150 -151
View File
@@ -3,13 +3,13 @@
#ifdef FREEBSD
# include <machine/endian.h>
#elif defined(LINUX)
#elif defined(LINUX)
# include <endian.h>
# include <features.h>
# include <sys/types.h>
#elif defined(SOLARIS)
/* each solaris is different -- this won't work on 2.6 or 2.7 */
# include <sys/isa_defs.h> /* Defines either _LITTLE_ENDIAN or _BIG_ENDIAN */
# include <sys/isa_defs.h> /* Defines either _LITTLE_ENDIAN or _BIG_ENDIAN */
# define __BIG_ENDIAN 4321
# define __LITTLE_ENDIAN 1234
# define BIG_ENDIAN 4321
@@ -59,7 +59,7 @@
* needed on buffers full of bytes, and then call MD5Final, which
* will fill a supplied 16-byte array with the digest.
*/
#include <string.h> /* for memcpy() */
#include <string.h> /* for memcpy() */
#include "md5.h"
#ifndef HIGHFIRST
@@ -73,13 +73,12 @@ void byteReverse(unsigned char *buf, unsigned longs);
*/
void byteReverse(unsigned char *buf, unsigned longs)
{
uint32 t;
do {
t = (uint32) ((unsigned) buf[3] << 8 | buf[2]) << 16 |
((unsigned) buf[1] << 8 | buf[0]);
*(uint32 *) buf = t;
buf += 4;
} while (--longs);
uint32 t;
do {
t = (uint32) ((unsigned) buf[3] << 8 | buf[2]) << 16 | ((unsigned) buf[1] << 8 | buf[0]);
*(uint32 *) buf = t;
buf += 4;
} while (--longs);
}
#endif
#endif
@@ -90,13 +89,13 @@ void byteReverse(unsigned char *buf, unsigned longs)
*/
void MD5Init(struct MD5Context *ctx)
{
ctx->buf[0] = 0x67452301;
ctx->buf[1] = 0xefcdab89;
ctx->buf[2] = 0x98badcfe;
ctx->buf[3] = 0x10325476;
ctx->buf[0] = 0x67452301;
ctx->buf[1] = 0xefcdab89;
ctx->buf[2] = 0x98badcfe;
ctx->buf[3] = 0x10325476;
ctx->bits[0] = 0;
ctx->bits[1] = 0;
ctx->bits[0] = 0;
ctx->bits[1] = 0;
}
/*
@@ -105,46 +104,46 @@ void MD5Init(struct MD5Context *ctx)
*/
void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
{
uint32 t;
uint32 t;
/* Update bitcount */
/* Update bitcount */
t = ctx->bits[0];
if ((ctx->bits[0] = t + ((uint32) len << 3)) < t)
ctx->bits[1]++; /* Carry from low to high */
ctx->bits[1] += len >> 29;
t = ctx->bits[0];
if ((ctx->bits[0] = t + ((uint32) len << 3)) < t)
ctx->bits[1]++; /* Carry from low to high */
ctx->bits[1] += len >> 29;
t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */
t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */
/* Handle any leading odd-sized chunks */
/* Handle any leading odd-sized chunks */
if (t) {
unsigned char *p = (unsigned char *) ctx->in + t;
if (t) {
unsigned char *p = (unsigned char *) ctx->in + t;
t = 64 - t;
if (len < t) {
memcpy(p, buf, len);
return;
t = 64 - t;
if (len < t) {
memcpy(p, buf, len);
return;
}
memcpy(p, buf, t);
byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (uint32 *) ctx->in);
buf += t;
len -= t;
}
memcpy(p, buf, t);
byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (uint32 *) ctx->in);
buf += t;
len -= t;
}
/* Process data in 64-byte chunks */
/* Process data in 64-byte chunks */
while (len >= 64) {
memcpy(ctx->in, buf, 64);
byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (uint32 *) ctx->in);
buf += 64;
len -= 64;
}
while (len >= 64) {
memcpy(ctx->in, buf, 64);
byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (uint32 *) ctx->in);
buf += 64;
len -= 64;
}
/* Handle any remaining bytes of data. */
/* Handle any remaining bytes of data. */
memcpy(ctx->in, buf, len);
memcpy(ctx->in, buf, len);
}
/*
@@ -153,43 +152,43 @@ void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
*/
void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
{
unsigned count;
unsigned char *p;
unsigned count;
unsigned char *p;
/* Compute number of bytes mod 64 */
count = (ctx->bits[0] >> 3) & 0x3F;
/* Compute number of bytes mod 64 */
count = (ctx->bits[0] >> 3) & 0x3F;
/* Set the first char of padding to 0x80. This is safe since there is
always at least one byte free */
p = ctx->in + count;
*p++ = 0x80;
/* Set the first char of padding to 0x80. This is safe since there is
always at least one byte free */
p = ctx->in + count;
*p++ = 0x80;
/* Bytes of padding needed to make 64 bytes */
count = 64 - 1 - count;
/* Bytes of padding needed to make 64 bytes */
count = 64 - 1 - count;
/* Pad out to 56 mod 64 */
if (count < 8) {
/* Two lots of padding: Pad the first block to 64 bytes */
memset(p, 0, count);
byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (uint32 *) ctx->in);
/* Now fill the next block with 56 bytes */
memset(ctx->in, 0, 56);
} else {
/* Pad block to 56 bytes */
memset(p, 0, count - 8);
}
byteReverse(ctx->in, 14);
/* Append length in bits and transform */
((uint32 *) ctx->in)[14] = ctx->bits[0];
((uint32 *) ctx->in)[15] = ctx->bits[1];
/* Pad out to 56 mod 64 */
if (count < 8) {
/* Two lots of padding: Pad the first block to 64 bytes */
memset(p, 0, count);
byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (uint32 *) ctx->in);
/* Now fill the next block with 56 bytes */
memset(ctx->in, 0, 56);
} else {
/* Pad block to 56 bytes */
memset(p, 0, count - 8);
}
byteReverse(ctx->in, 14);
/* Append length in bits and transform */
((uint32 *) ctx->in)[14] = ctx->bits[0];
((uint32 *) ctx->in)[15] = ctx->bits[1];
MD5Transform(ctx->buf, (uint32 *) ctx->in);
byteReverse((unsigned char *) ctx->buf, 4);
memcpy(digest, ctx->buf, 16);
memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
byteReverse((unsigned char *) ctx->buf, 4);
memcpy(digest, ctx->buf, 16);
memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
}
#ifndef ASM_MD5
@@ -213,85 +212,85 @@ void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
*/
void MD5Transform(uint32 buf[4], uint32 const in[16])
{
register uint32 a, b, c, d;
register uint32 a, b, c, d;
a = buf[0];
b = buf[1];
c = buf[2];
d = buf[3];
a = buf[0];
b = buf[1];
c = buf[2];
d = buf[3];
MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
buf[0] += a;
buf[1] += b;
buf[2] += c;
buf[3] += d;
buf[0] += a;
buf[1] += b;
buf[2] += c;
buf[3] += d;
}
#endif
+37 -38
View File
@@ -110,14 +110,14 @@ SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_ip, globals.ip);
static char *IAXNAMES[] = { "IAX_EVENT_CONNECT", "IAX_EVENT_ACCEPT", "IAX_EVENT_HANGUP", "IAX_EVENT_REJECT", "IAX_EVENT_VOICE",
"IAX_EVENT_DTMF", "IAX_EVENT_TIMEOUT", "IAX_EVENT_LAGRQ", "IAX_EVENT_LAGRP", "IAX_EVENT_RINGA",
"IAX_EVENT_PING", "IAX_EVENT_PONG", "IAX_EVENT_BUSY", "IAX_EVENT_ANSWER", "IAX_EVENT_IMAGE",
"IAX_EVENT_AUTHRQ", "IAX_EVENT_AUTHRP", "IAX_EVENT_REGREQ", "IAX_EVENT_REGACK",
"IAX_EVENT_URL", "IAX_EVENT_LDCOMPLETE", "IAX_EVENT_TRANSFER", "IAX_EVENT_DPREQ",
"IAX_EVENT_DPREP", "IAX_EVENT_DIAL", "IAX_EVENT_QUELCH", "IAX_EVENT_UNQUELCH",
"IAX_EVENT_UNLINK", "IAX_EVENT_LINKREJECT", "IAX_EVENT_TEXT", "IAX_EVENT_REGREJ",
"IAX_EVENT_LINKURL", "IAX_EVENT_CNG", "IAX_EVENT_REREQUEST", "IAX_EVENT_TXREPLY",
"IAX_EVENT_TXREJECT", "IAX_EVENT_TXACCEPT", "IAX_EVENT_TXREADY"
"IAX_EVENT_DTMF", "IAX_EVENT_TIMEOUT", "IAX_EVENT_LAGRQ", "IAX_EVENT_LAGRP", "IAX_EVENT_RINGA",
"IAX_EVENT_PING", "IAX_EVENT_PONG", "IAX_EVENT_BUSY", "IAX_EVENT_ANSWER", "IAX_EVENT_IMAGE",
"IAX_EVENT_AUTHRQ", "IAX_EVENT_AUTHRP", "IAX_EVENT_REGREQ", "IAX_EVENT_REGACK",
"IAX_EVENT_URL", "IAX_EVENT_LDCOMPLETE", "IAX_EVENT_TRANSFER", "IAX_EVENT_DPREQ",
"IAX_EVENT_DPREP", "IAX_EVENT_DIAL", "IAX_EVENT_QUELCH", "IAX_EVENT_UNQUELCH",
"IAX_EVENT_UNLINK", "IAX_EVENT_LINKREJECT", "IAX_EVENT_TEXT", "IAX_EVENT_REGREJ",
"IAX_EVENT_LINKURL", "IAX_EVENT_CNG", "IAX_EVENT_REREQUEST", "IAX_EVENT_TXREPLY",
"IAX_EVENT_TXREJECT", "IAX_EVENT_TXACCEPT", "IAX_EVENT_TXREADY"
};
@@ -129,24 +129,24 @@ struct ast_iana {
//999 means it's wrong nad i dont know the real one
static struct ast_iana AST_IANA[] = { {AST_FORMAT_G723_1, 4, "g723.1"},
{AST_FORMAT_GSM, 3, "gsm"},
{AST_FORMAT_ULAW, 0, "ulaw"},
{AST_FORMAT_ALAW, 8, "alaw"},
{AST_FORMAT_G726, 999, "g726"},
{AST_FORMAT_ADPCM, 999, "adpcm"},
{AST_FORMAT_SLINEAR, 10, "slinear"},
{AST_FORMAT_LPC10, 7, "lpc10"},
{AST_FORMAT_G729A, 18, "g729"},
{AST_FORMAT_SPEEX, 97, "speex"},
{AST_FORMAT_SPEEX, 98, "speex"},
{AST_FORMAT_ILBC, 102, "ilbc"},
{AST_FORMAT_MAX_AUDIO, 999, ""},
{AST_FORMAT_JPEG, 999, ""},
{AST_FORMAT_PNG, 999, ""},
{AST_FORMAT_H261, 999, ""},
{AST_FORMAT_H263, 999, ""},
{AST_FORMAT_MAX_VIDEO, 999, ""},
{0, 0}
{AST_FORMAT_GSM, 3, "gsm"},
{AST_FORMAT_ULAW, 0, "ulaw"},
{AST_FORMAT_ALAW, 8, "alaw"},
{AST_FORMAT_G726, 999, "g726"},
{AST_FORMAT_ADPCM, 999, "adpcm"},
{AST_FORMAT_SLINEAR, 10, "slinear"},
{AST_FORMAT_LPC10, 7, "lpc10"},
{AST_FORMAT_G729A, 18, "g729"},
{AST_FORMAT_SPEEX, 97, "speex"},
{AST_FORMAT_SPEEX, 98, "speex"},
{AST_FORMAT_ILBC, 102, "ilbc"},
{AST_FORMAT_MAX_AUDIO, 999, ""},
{AST_FORMAT_JPEG, 999, ""},
{AST_FORMAT_PNG, 999, ""},
{AST_FORMAT_H261, 999, ""},
{AST_FORMAT_H263, 999, ""},
{AST_FORMAT_MAX_VIDEO, 999, ""},
{0, 0}
};
static char *ast2str(int ast)
@@ -214,7 +214,7 @@ typedef enum {
IAX_QUERY = 2
} iax_io_t;
static switch_status_t iax_set_codec(private_t * tech_pvt, struct iax_session *iax_session,
static switch_status_t iax_set_codec(private_t *tech_pvt, struct iax_session *iax_session,
unsigned int *format, unsigned int *cababilities, unsigned short *samprate, iax_io_t io)
{
char *dname = NULL;
@@ -281,8 +281,8 @@ static switch_status_t iax_set_codec(private_t * tech_pvt, struct iax_session *i
char pref_str[256] = "(";
for (x = 0; x < len; x++) {
strncat(pref_str, ast2str(prefs[x]), sizeof(pref_str)-1);
strncat(pref_str, x == len - 1 ? ")" : ",", sizeof(pref_str)-1);
strncat(pref_str, ast2str(prefs[x]), sizeof(pref_str) - 1);
strncat(pref_str, x == len - 1 ? ")" : ",", sizeof(pref_str) - 1);
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Codec Prefs Detected: %s\n", pref_str);
@@ -439,7 +439,7 @@ static void iax_out_cb(const char *s)
}
}
static void tech_init(private_t * tech_pvt, switch_core_session_t *session)
static void tech_init(private_t *tech_pvt, switch_core_session_t *session)
{
tech_pvt->read_frame.data = tech_pvt->databuf;
tech_pvt->read_frame.buflen = sizeof(tech_pvt->databuf);
@@ -619,7 +619,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
return SWITCH_STATUS_FALSE;
cng:
cng:
data = (switch_byte_t *) tech_pvt->read_frame.data;
data[0] = 65;
data[1] = 0;
@@ -791,7 +791,7 @@ switch_io_routines_t iax_io_routines = {
/*.write_frame */ channel_write_frame,
/*.kill_channel */ channel_kill_channel,
/*.send_dtmf */ channel_send_dtmf,
/*.receive_message*/ channel_receive_message,
/*.receive_message */ channel_receive_message,
/*.receive_event */ channel_receive_event
};
@@ -867,7 +867,7 @@ static switch_status_t load_config(void)
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t tech_media(private_t * tech_pvt, struct iax_event *iaxevent)
static switch_status_t tech_media(private_t *tech_pvt, struct iax_event *iaxevent)
{
unsigned int cap = iax_session_get_capability(iaxevent->session);
unsigned int format = iaxevent->ies.format;
@@ -1025,8 +1025,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_iax_runtime)
NULL,
NULL,
modname,
iaxevent->ies.called_context,
iaxevent->ies.called_number)) != 0) {
iaxevent->ies.called_context, iaxevent->ies.called_number)) != 0) {
char name[128];
switch_snprintf(name, sizeof(name), "IAX/%s-%04x", tech_pvt->caller_profile->destination_number, rand() & 0xffff);
switch_channel_set_name(channel, name);
@@ -1062,7 +1061,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_iax_runtime)
switch_clear_flag(tech_pvt, TFLAG_VOICE);
switch_mutex_unlock(tech_pvt->flag_mutex);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Hangup %s\n", switch_channel_get_name(channel));
switch_set_flag_locked(tech_pvt, TFLAG_HANGUP);
switch_channel_hangup(channel, iaxevent->etype == IAX_EVENT_HANGUP ? SWITCH_CAUSE_NORMAL_CLEARING : SWITCH_CAUSE_FACILITY_REJECTED);
@@ -1102,7 +1101,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_iax_runtime)
break;
case IAX_EVENT_DTMF:
if (channel) {
switch_dtmf_t dtmf = { (char) iaxevent->subclass , switch_core_default_dtmf_duration(0) };
switch_dtmf_t dtmf = { (char) iaxevent->subclass, switch_core_default_dtmf_duration(0) };
if (globals.debug) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%c DTMF %s\n", dtmf.digit, switch_channel_get_name(channel));
}
@@ -1118,7 +1117,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_iax_runtime)
break;
}
iax_event_free(iaxevent);
switch_mutex_unlock(globals.mutex);
switch_mutex_unlock(globals.mutex);
if (tech_pvt && tech_pvt->session) {
switch_core_session_signal_unlock(tech_pvt->session);
}
+37 -49
View File
@@ -136,8 +136,8 @@ SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_hold_file, globals.hold_file);
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_timer_name, globals.timer_name);
#define is_master(t) switch_test_flag(t, TFLAG_MASTER)
static void add_pvt(private_t * tech_pvt, int master);
static void remove_pvt(private_t * tech_pvt);
static void add_pvt(private_t *tech_pvt, int master);
static void remove_pvt(private_t *tech_pvt);
static switch_status_t channel_on_init(switch_core_session_t *session);
static switch_status_t channel_on_hangup(switch_core_session_t *session);
static switch_status_t channel_on_routing(switch_core_session_t *session);
@@ -234,7 +234,7 @@ static switch_status_t channel_on_init(switch_core_session_t *session)
while (switch_channel_get_state(channel) == CS_INIT && !switch_test_flag(tech_pvt, TFLAG_ANSWER)) {
switch_size_t olen = globals.timer.samples;
if (switch_timestamp_now() - last >= waitsec) {
char buf[512];
switch_event_t *event;
@@ -250,7 +250,7 @@ static switch_status_t channel_on_init(switch_core_session_t *session)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s\n", buf);
last = switch_timestamp_now();
}
if (ring_file) {
if (switch_core_timer_next(&globals.timer) != SWITCH_STATUS_SUCCESS) {
switch_core_file_close(&fh);
@@ -324,7 +324,7 @@ static void deactivate_ring_device(void)
static void add_pvt(private_t * tech_pvt, int master)
static void add_pvt(private_t *tech_pvt, int master)
{
private_t *tp;
uint8_t in_list = 0;
@@ -367,7 +367,7 @@ static void add_pvt(private_t * tech_pvt, int master)
switch_mutex_unlock(globals.pvt_lock);
}
static void remove_pvt(private_t * tech_pvt)
static void remove_pvt(private_t *tech_pvt)
{
private_t *tp, *last = NULL;
@@ -485,8 +485,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
tech_pvt->hold_file,
globals.read_codec.implementation->number_of_channels,
globals.read_codec.implementation->actual_samples_per_second,
SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT,
NULL) != SWITCH_STATUS_SUCCESS) {
SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
tech_pvt->hold_file = NULL;
goto cng;
}
@@ -500,12 +499,12 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
goto hold;
}
cng:
cng:
switch_yield(globals.read_codec.implementation->microseconds_per_frame);
*frame = &globals.cng_frame;
return SWITCH_STATUS_SUCCESS;
hold:
hold:
{
switch_size_t olen = globals.read_codec.implementation->samples_per_frame;
if (switch_core_timer_next(&globals.timer) != SWITCH_STATUS_SUCCESS) {
@@ -531,13 +530,12 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
switch_mutex_lock(globals.device_lock);
get_samples:
get_samples:
if ((samples = ReadAudioStream(globals.audio_stream, globals.read_frame.data,
globals.read_codec.implementation->samples_per_frame,
&globals.timer)) == 0) {
switch_yield(1000);
goto get_samples;
if ((samples = ReadAudioStream(globals.audio_stream, globals.read_frame.data,
globals.read_codec.implementation->samples_per_frame, &globals.timer)) == 0) {
switch_yield(1000);
goto get_samples;
} else {
globals.read_frame.datalen = samples * 2;
globals.read_frame.samples = samples;
@@ -576,8 +574,7 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc
if (globals.audio_stream) {
if (switch_test_flag((&globals), GFLAG_EAR)) {
WriteAudioStream(globals.audio_stream, (short *) frame->data, (int) (frame->datalen / sizeof(SAMPLE)),
&globals.timer);
WriteAudioStream(globals.audio_stream, (short *) frame->data, (int) (frame->datalen / sizeof(SAMPLE)), &globals.timer);
}
status = SWITCH_STATUS_SUCCESS;
}
@@ -667,7 +664,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi
if (outbound_profile->destination_number && !strcasecmp(outbound_profile->destination_number, "auto_answer")) {
switch_set_flag(tech_pvt, TFLAG_ANSWER);
}
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Doh! no caller profile\n");
switch_core_session_destroy(new_session);
@@ -775,7 +772,7 @@ static switch_status_t load_config(void)
globals.codec_ms = tmp;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
"codec-ms must be multipe of 10 and less than %d, Using default of 20\n", SWITCH_MAX_INTERVAL);
"codec-ms must be multipe of 10 and less than %d, Using default of 20\n", SWITCH_MAX_INTERVAL);
}
} else if (!strcmp(var, "dialplan")) {
set_global_dialplan(val);
@@ -936,7 +933,8 @@ static void PrintSupportedStandardSampleRates(const PaStreamParameters * inputPa
int i, printCount, cr = 7;
PaError err;
static double standardSampleRates[] = { 8000.0, 9600.0, 11025.0, 12000.0, 16000.0, 22050.0, 24000.0, 32000.0,
44100.0, 48000.0, 88200.0, 96000.0, 192000.0, -1};
44100.0, 48000.0, 88200.0, 96000.0, 192000.0, -1
};
printCount = cr;
for (i = 0; standardSampleRates[i] > 0; i++) {
@@ -1077,7 +1075,7 @@ static int dump_info(void)
return 0;
error:
error:
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, "An error occured while using the portaudio stream\n");
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, "Error number: %d\n", err);
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, "Error message: %s\n", Pa_GetErrorText(err));
@@ -1140,7 +1138,7 @@ static switch_status_t engage_device(int sample_rate, int codec_ms)
outputParameters.sampleFormat = SAMPLE_TYPE;
outputParameters.suggestedLatency = Pa_GetDeviceInfo(outputParameters.device)->defaultLowOutputLatency;
outputParameters.hostApiSpecificStreamInfo = NULL;
err = OpenAudioStream(&globals.audio_stream, &inputParameters, &outputParameters, sample_rate, paClipOff,
err = OpenAudioStream(&globals.audio_stream, &inputParameters, &outputParameters, sample_rate, paClipOff,
globals.read_codec.implementation->samples_per_frame);
/* UNLOCKED ************************************************************************************************* */
switch_mutex_unlock(globals.device_lock);
@@ -1174,8 +1172,7 @@ static switch_status_t engage_ring_device(int sample_rate, int channels)
outputParameters.sampleFormat = SAMPLE_TYPE;
outputParameters.suggestedLatency = Pa_GetDeviceInfo(outputParameters.device)->defaultLowOutputLatency;
outputParameters.hostApiSpecificStreamInfo = NULL;
err = OpenAudioStream(&globals.ring_stream, NULL, &outputParameters, sample_rate, paClipOff,
globals.read_codec.implementation->samples_per_frame);
err = OpenAudioStream(&globals.ring_stream, NULL, &outputParameters, sample_rate, paClipOff, globals.read_codec.implementation->samples_per_frame);
/* UNLOCKED ************************************************************************************************* */
switch_mutex_unlock(globals.device_lock);
@@ -1192,8 +1189,8 @@ static switch_status_t engage_ring_device(int sample_rate, int channels)
static switch_status_t dtmf_call(char **argv, int argc, switch_stream_handle_t *stream)
{
char *dtmf_str = argv[0];
switch_dtmf_t dtmf = {0, switch_core_default_dtmf_duration(0)};
switch_dtmf_t dtmf = { 0, switch_core_default_dtmf_duration(0) };
if (switch_strlen_zero(dtmf_str)) {
stream->write_function(stream, "No DTMF Supplied!\n");
} else {
@@ -1201,7 +1198,7 @@ static switch_status_t dtmf_call(char **argv, int argc, switch_stream_handle_t *
if (globals.call_list) {
switch_channel_t *channel = switch_core_session_get_channel(globals.call_list->session);
char *p = dtmf_str;
while(p && *p) {
while (p && *p) {
dtmf.digit = *p;
switch_channel_queue_dtmf(channel, &dtmf);
p++;
@@ -1253,7 +1250,7 @@ static switch_status_t switch_call(char **argv, int argc, switch_stream_handle_t
stream->write_function(stream, "NO SUCH CALL\n");
}
done:
done:
switch_mutex_unlock(globals.pvt_lock);
return SWITCH_STATUS_SUCCESS;
@@ -1317,7 +1314,7 @@ static switch_status_t answer_call(char **argv, int argc, switch_stream_handle_t
break;
}
}
done:
done:
switch_mutex_unlock(globals.pvt_lock);
stream->write_function(stream, "Answered %d channels.\n", x);
@@ -1368,7 +1365,7 @@ static switch_status_t do_flags(char **argv, int argc, switch_stream_handle_t *s
goto bad;
}
desc:
desc:
x = 0;
stream->write_function(stream, "FLAGS: ");
if (switch_test_flag((&globals), GFLAG_EAR)) {
@@ -1385,9 +1382,9 @@ static switch_status_t do_flags(char **argv, int argc, switch_stream_handle_t *s
goto done;
bad:
bad:
stream->write_function(stream, "Usage: flags [on|off] <flags>\n");
done:
done:
return SWITCH_STATUS_SUCCESS;
}
@@ -1474,20 +1471,18 @@ static switch_status_t place_call(char **argv, int argc, switch_stream_handle_t
if (!switch_strlen_zero(argv[4])) {
tech_pvt->sample_rate = atoi(argv[4]);
}
if (!switch_strlen_zero(argv[5])) {
tech_pvt->codec_ms = atoi(argv[5]);
}
switch_find_local_ip(ip, sizeof(ip), AF_INET);
if ((tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
NULL, dialplan, cid_name, cid_num,
ip, NULL, NULL, NULL, modname, NULL,
dest)) != 0) {
NULL, dialplan, cid_name, cid_num, ip, NULL, NULL, NULL, modname, NULL, dest)) != 0) {
char name[128];
switch_snprintf(name, sizeof(name), "PortAudio/%s",
tech_pvt->caller_profile->destination_number ? tech_pvt->caller_profile->destination_number : modname);
tech_pvt->caller_profile->destination_number ? tech_pvt->caller_profile->destination_number : modname);
switch_channel_set_name(channel, name);
switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
@@ -1498,7 +1493,7 @@ static switch_status_t place_call(char **argv, int argc, switch_stream_handle_t
switch_channel_mark_answered(channel);
switch_channel_set_state(channel, CS_INIT);
if (switch_core_session_thread_launch(tech_pvt->session) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error spawning thread\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error spawning thread\n");
switch_core_session_destroy(&session);
stream->write_function(stream, "FAIL:Thread Error!\n");
} else {
@@ -1674,7 +1669,7 @@ SWITCH_STANDARD_API(pa_cmd)
}
}
done:
done:
if (http) {
stream->write_function(stream,
"<br><br><table align=center><tr><td><center><form method=post>\n"
@@ -1691,25 +1686,18 @@ SWITCH_STANDARD_API(pa_cmd)
"<td><input name=action type=submit value=\"2\"></td>"
"<td><input name=action type=submit value=\"3\"></td>\n"
"<td><input name=action type=submit value=\"A\"></td></tr>\n"
"<tr><td><input name=action type=submit value=\"4\"></td>"
"<td><input name=action type=submit value=\"5\"></td>"
"<td><input name=action type=submit value=\"6\"></td>\n"
"<td><input name=action type=submit value=\"B\"></td></tr>\n"
"<tr><td><input name=action type=submit value=\"7\"></td>"
"<td><input name=action type=submit value=\"8\"></td>"
"<td><input name=action type=submit value=\"9\"></td>\n"
"<td><input name=action type=submit value=\"C\"></td></tr>\n"
"<tr><td><input name=action type=submit value=\"*\"></td>"
"<td><input name=action type=submit value=\"0\"></td>"
"<td><input name=action type=submit value=\"#\"></td>\n"
"<td><input name=action type=submit value=\"D\"></td></tr>\n"
"</table>"
"</form><br></center></td></tr></table>\n"
);
"<td><input name=action type=submit value=\"D\"></td></tr>\n" "</table>" "</form><br></center></td></tr></table>\n");
}
switch_safe_free(mycmd);
+11 -14
View File
@@ -72,7 +72,7 @@ static int blockingIOCallback(const void *inputBuffer, void *outputBuffer,
{
PABLIO_Stream *data = (PABLIO_Stream *) userData;
long numBytes = data->bytesPerFrame * framesPerBuffer;
/* This may get called with NULL inputBuffer during initial setup. */
if (inputBuffer != NULL) {
if (PaUtil_WriteRingBuffer(&data->inFIFO, inputBuffer, numBytes) != numBytes) {
@@ -146,26 +146,26 @@ long ReadAudioStream(PABLIO_Stream * aStream, void *data, long numFrames, switch
long bytesRead = 0;
char *p = (char *) data;
long avail, totalBytes = 0, neededBytes = aStream->bytesPerFrame * numFrames;
for(;;) {
for (;;) {
avail = PaUtil_GetRingBufferReadAvailable(&aStream->inFIFO);
if (switch_core_timer_check(timer, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS) {
break;
}
if (avail >= neededBytes * 6) {
if (avail >= neededBytes * 6) {
PaUtil_FlushRingBuffer(&aStream->inFIFO);
avail = 0;
}
bytesRead = 0;
if (totalBytes < neededBytes && avail >= neededBytes) {
bytesRead = PaUtil_ReadRingBuffer(&aStream->inFIFO, p, neededBytes);
totalBytes += bytesRead;
}
if (bytesRead) {
p += bytesRead;
} else {
@@ -201,7 +201,7 @@ static unsigned long RoundUpToNextPowerOf2(unsigned long n)
{
long numBits = 0;
if (((n - 1) & n) == 0)
return n;
return n;
while (n > 0) {
n = n >> 1;
numBits++;
@@ -217,11 +217,8 @@ static unsigned long RoundUpToNextPowerOf2(unsigned long n)
*
*/
PaError OpenAudioStream(PABLIO_Stream ** rwblPtr,
const PaStreamParameters *inputParameters,
const PaStreamParameters *outputParameters,
double sampleRate,
PaStreamFlags streamFlags,
long samples_per_frame)
const PaStreamParameters * inputParameters,
const PaStreamParameters * outputParameters, double sampleRate, PaStreamFlags streamFlags, long samples_per_frame)
{
long bytesPerSample = 2;
PaError err;
+12 -12
View File
@@ -34,7 +34,7 @@
SWITCH_MODULE_LOAD_FUNCTION(mod_reference_load);
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_reference_shutdown);
//SWITCH_MODULE_RUNTIME_FUNCTION(mod_reference_runtime);
SWITCH_MODULE_DEFINITION(mod_reference, mod_reference_load, mod_reference_shutdown, NULL);//mod_reference_runtime);
SWITCH_MODULE_DEFINITION(mod_reference, mod_reference_load, mod_reference_shutdown, NULL); //mod_reference_runtime);
switch_endpoint_interface_t *reference_endpoint_interface;
@@ -112,7 +112,7 @@ static switch_status_t channel_kill_channel(switch_core_session_t *session, int
static void tech_init(private_t * tech_pvt, switch_core_session_t *session)
static void tech_init(private_t *tech_pvt, switch_core_session_t *session)
{
tech_pvt->read_frame.data = tech_pvt->databuf;
tech_pvt->read_frame.buflen = sizeof(tech_pvt->databuf);
@@ -140,9 +140,9 @@ static switch_status_t channel_on_init(switch_core_session_t *session)
switch_set_flag_locked(tech_pvt, TFLAG_IO);
/* Move channel's state machine to ROUTING. This means the call is trying
to get from the initial start where the call because, to the point
where a destination has been identified. If the channel is simply
left in the initial state, nothing will happen. */
to get from the initial start where the call because, to the point
where a destination has been identified. If the channel is simply
left in the initial state, nothing will happen. */
switch_channel_set_state(channel, CS_ROUTING);
switch_mutex_lock(globals.mutex);
globals.calls++;
@@ -315,7 +315,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
return SWITCH_STATUS_FALSE;
cng:
cng:
data = (switch_byte_t *) tech_pvt->read_frame.data;
data[0] = 65;
data[1] = 0;
@@ -346,7 +346,7 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc
switch_swap_linear(frame->data, (int) frame->datalen / 2);
}
#endif
return SWITCH_STATUS_SUCCESS;
@@ -363,7 +363,7 @@ static switch_status_t channel_answer_channel(switch_core_session_t *session)
tech_pvt = switch_core_session_get_private(session);
assert(tech_pvt != NULL);
return SWITCH_STATUS_SUCCESS;
}
@@ -375,7 +375,7 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
tech_pvt = (private_t *) switch_core_session_get_private(session);
assert(tech_pvt != NULL);
@@ -471,7 +471,7 @@ switch_io_routines_t reference_io_routines = {
/*.write_frame */ channel_write_frame,
/*.kill_channel */ channel_kill_channel,
/*.send_dtmf */ channel_send_dtmf,
/*.receive_message*/ channel_receive_message,
/*.receive_message */ channel_receive_message,
/*.receive_event */ channel_receive_event
};
@@ -531,7 +531,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_reference_load)
{
module_pool = pool;
load_config();
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
@@ -540,7 +540,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_reference_load)
reference_endpoint_interface->io_routines = &reference_io_routines;
reference_endpoint_interface->state_handler = &reference_state_handlers;
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
+130 -157
View File
@@ -98,14 +98,14 @@ static switch_status_t sofia_on_init(switch_core_session_t *session)
if (sofia_glue_do_invite(session) != SWITCH_STATUS_SUCCESS) {
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
assert( switch_channel_get_state(channel) != CS_INIT);
assert(switch_channel_get_state(channel) != CS_INIT);
return SWITCH_STATUS_FALSE;
}
}
/* Move channel's state machine to ROUTING */
switch_channel_set_state(channel, CS_ROUTING);
assert( switch_channel_get_state(channel) != CS_INIT);
assert(switch_channel_get_state(channel) != CS_INIT);
return SWITCH_STATUS_SUCCESS;
}
@@ -115,7 +115,7 @@ static switch_status_t sofia_on_routing(switch_core_session_t *session)
switch_assert(tech_pvt != NULL);
switch_clear_flag_locked(tech_pvt, TFLAG_SIP_HOLD);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s SOFIA ROUTING\n", switch_channel_get_name(switch_core_session_get_channel(session)));
return SWITCH_STATUS_SUCCESS;
@@ -128,7 +128,7 @@ static switch_status_t sofia_on_reset(switch_core_session_t *session)
switch_assert(tech_pvt != NULL);
switch_clear_flag_locked(tech_pvt, TFLAG_SIP_HOLD);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s SOFIA RESET\n", switch_channel_get_name(switch_core_session_get_channel(session)));
return SWITCH_STATUS_SUCCESS;
@@ -141,7 +141,7 @@ static switch_status_t sofia_on_hibernate(switch_core_session_t *session)
switch_assert(tech_pvt != NULL);
switch_clear_flag_locked(tech_pvt, TFLAG_SIP_HOLD);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s SOFIA HIBERNATE\n", switch_channel_get_name(switch_core_session_get_channel(session)));
return SWITCH_STATUS_SUCCESS;
@@ -160,7 +160,7 @@ static switch_status_t sofia_on_execute(switch_core_session_t *session)
/* map QSIG cause codes to SIP from RFC4497 section 8.4.1 */
static int hangup_cause_to_sip(switch_call_cause_t cause)
{
{
switch (cause) {
case SWITCH_CAUSE_NO_ROUTE_TRANSIT_NET:
case SWITCH_CAUSE_NO_ROUTE_DESTINATION:
@@ -223,11 +223,11 @@ switch_status_t sofia_on_hangup(switch_core_session_t *session)
switch_call_cause_t cause = switch_channel_get_cause(channel);
int sip_cause = hangup_cause_to_sip(cause);
const char *ps_cause = switch_channel_get_variable(channel, SWITCH_PROTO_SPECIFIC_HANGUP_CAUSE_VARIABLE);
if (!switch_strlen_zero(ps_cause) && !strncasecmp(ps_cause, "sip:", 4)) {
int new_cause = atoi(ps_cause + 4);
if (new_cause) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s Overriding SIP cause %d with %d from the other leg\n",
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s Overriding SIP cause %d with %d from the other leg\n",
switch_channel_get_name(channel), sip_cause, new_cause);
sip_cause = new_cause;
}
@@ -262,7 +262,7 @@ switch_status_t sofia_on_hangup(switch_core_session_t *session)
sofia_glue_deactivate_rtp(tech_pvt);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Channel %s hanging up, cause: %s\n",
switch_channel_get_name(channel), switch_channel_cause2str(cause));
switch_channel_get_name(channel), switch_channel_cause2str(cause));
if (tech_pvt->hash_key) {
switch_core_hash_delete(tech_pvt->profile->chat_hash, tech_pvt->hash_key);
@@ -282,7 +282,7 @@ switch_status_t sofia_on_hangup(switch_core_session_t *session)
switch_mutex_lock(tech_pvt->profile->flag_mutex);
if (tech_pvt->nh && !switch_test_flag(tech_pvt, TFLAG_BYE)) {
if (tech_pvt->nh && !switch_test_flag(tech_pvt, TFLAG_BYE)) {
char reason[128] = "";
if (cause > 1 && cause < 128) {
switch_snprintf(reason, sizeof(reason), "Q.850;cause=%d;text=\"%s\"", cause, switch_channel_cause2str(cause));
@@ -291,7 +291,7 @@ switch_status_t sofia_on_hangup(switch_core_session_t *session)
} else {
switch_snprintf(reason, sizeof(reason), "FreeSWITCH;cause=%d;text=\"%s\"", cause, switch_channel_cause2str(cause));
}
if (switch_test_flag(tech_pvt, TFLAG_ANS)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Sending BYE to %s\n", switch_channel_get_name(channel));
nua_bye(tech_pvt->nh, SIPTAG_REASON_STR(reason), TAG_END());
@@ -349,7 +349,7 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session)
b_sdp = switch_channel_get_variable(channel, SWITCH_B_SDP_VARIABLE);
is_proxy = (switch_channel_test_flag(channel, CF_PROXY_MODE) || switch_channel_test_flag(channel, CF_PROXY_MEDIA));
if (b_sdp && is_proxy) {
tech_pvt->local_sdp_str = switch_core_session_strdup(session, b_sdp);
@@ -373,7 +373,7 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session)
const char *r_sdp = switch_channel_get_variable(channel, SWITCH_R_SDP_VARIABLE);
tech_pvt->num_codecs = 0;
sofia_glue_tech_prepare_codecs(tech_pvt);
if (sofia_glue_tech_media(tech_pvt, r_sdp) != SWITCH_STATUS_SUCCESS) {
switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "CODEC NEGOTIATION ERROR");
//nua_respond(tech_pvt->nh, SIP_488_NOT_ACCEPTABLE, TAG_END());
@@ -394,8 +394,7 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session)
if (tech_pvt->nh) {
if (tech_pvt->local_sdp_str) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Local SDP %s:\n%s\n", switch_channel_get_name(channel),
tech_pvt->local_sdp_str);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Local SDP %s:\n%s\n", switch_channel_get_name(channel), tech_pvt->local_sdp_str);
}
}
}
@@ -406,16 +405,16 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session)
session_timeout = v_session_timeout;
}
}
if (switch_test_flag(tech_pvt, TFLAG_NAT) ||
(val = switch_channel_get_variable(channel, "sip-force-contact")) ||
(val = switch_channel_get_variable(channel, "sip-force-contact")) ||
((val = switch_channel_get_variable(channel, "sip_sticky_contact")) && switch_true(val))) {
sticky = tech_pvt->record_route;
session_timeout = SOFIA_NAT_SESSION_TIMEOUT;
switch_channel_set_variable(channel, "sip_nat_detected", "true");
}
nua_respond(tech_pvt->nh, SIP_200_OK,
NUTAG_AUTOANSWER(0),
@@ -423,11 +422,7 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session)
NUTAG_SESSION_TIMER(session_timeout),
SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
SOATAG_REUSE_REJECTED(1),
SOATAG_ORDERED_USER(1),
SOATAG_AUDIO_AUX("cn telephone-event"),
NUTAG_INCLUDE_EXTRA_SDP(1),
TAG_END());
SOATAG_REUSE_REJECTED(1), SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"), NUTAG_INCLUDE_EXTRA_SDP(1), TAG_END());
return SWITCH_STATUS_SUCCESS;
}
@@ -474,7 +469,7 @@ static switch_status_t sofia_read_video_frame(switch_core_session_t *session, sw
}
return status;
}
payload = tech_pvt->video_read_frame.payload;
if (tech_pvt->video_read_frame.datalen > 0) {
@@ -524,13 +519,13 @@ static switch_status_t sofia_write_video_frame(switch_core_session_t *session, s
if (!switch_test_flag(frame, SFF_CNG)) {
switch_rtp_write_frame(tech_pvt->video_rtp_session, frame);
}
return status;
}
static switch_status_t sofia_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id)
{
private_object_t *tech_pvt = switch_core_session_get_private(session);
private_object_t *tech_pvt = switch_core_session_get_private(session);
switch_channel_t *channel = switch_core_session_get_channel(session);
int payload = 0;
@@ -558,7 +553,7 @@ static switch_status_t sofia_read_frame(switch_core_session_t *session, switch_f
if (switch_test_flag(tech_pvt, TFLAG_IO)) {
switch_status_t status;
if (!switch_test_flag(tech_pvt, TFLAG_RTP)) {
return SWITCH_STATUS_GENERR;
}
@@ -570,22 +565,22 @@ static switch_status_t sofia_read_frame(switch_core_session_t *session, switch_f
tech_pvt->read_frame.flags = SFF_NONE;
status = switch_rtp_zerocopy_read_frame(tech_pvt->rtp_session, &tech_pvt->read_frame, flags);
if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
if (status == SWITCH_STATUS_TIMEOUT) {
switch_channel_hangup(tech_pvt->channel, SWITCH_CAUSE_MEDIA_TIMEOUT);
}
return status;
}
payload = tech_pvt->read_frame.payload;
if (switch_rtp_has_dtmf(tech_pvt->rtp_session)) {
switch_dtmf_t dtmf = {0};
switch_dtmf_t dtmf = { 0 };
switch_rtp_dequeue_dtmf(tech_pvt->rtp_session, &dtmf);
switch_channel_queue_dtmf(channel, &dtmf);
}
if (tech_pvt->read_frame.datalen > 0) {
size_t bytes = 0;
int frames = 1;
@@ -712,10 +707,7 @@ static switch_status_t sofia_send_dtmf(switch_core_session_t *session, const swi
case DTMF_INFO:
snprintf(message, sizeof(message), "Signal=%c\r\nDuration=%d\r\n", dtmf->digit, dtmf->duration / 8);
nua_info(tech_pvt->nh,
SIPTAG_CONTENT_TYPE_STR("application/dtmf-relay"),
SIPTAG_PAYLOAD_STR(message),
TAG_END());
nua_info(tech_pvt->nh, SIPTAG_CONTENT_TYPE_STR("application/dtmf-relay"), SIPTAG_PAYLOAD_STR(message), TAG_END());
break;
default:
break;
@@ -750,18 +742,11 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
" <media_control>\r\n"
" <vc_primitive>\r\n"
" <to_encoder>\r\n"
" <picture_fast_update>\r\n"
" </picture_fast_update>\r\n"
" </to_encoder>\r\n"
" </vc_primitive>\r\n"
" </media_control>\r\n";
nua_info(tech_pvt->nh,
SIPTAG_CONTENT_TYPE_STR("application/media_control+xml"),
SIPTAG_PAYLOAD_STR(pl),
TAG_END());
" <picture_fast_update>\r\n" " </picture_fast_update>\r\n" " </to_encoder>\r\n" " </vc_primitive>\r\n" " </media_control>\r\n";
nua_info(tech_pvt->nh, SIPTAG_CONTENT_TYPE_STR("application/media_control+xml"), SIPTAG_PAYLOAD_STR(pl), TAG_END());
}
break;
case SWITCH_MESSAGE_INDICATE_TRANSCODING_NECESSARY:
@@ -770,31 +755,27 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
switch_rtp_clear_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_PASS_RFC2833);
}
break;
case SWITCH_MESSAGE_INDICATE_BROADCAST: {
const char *ip = NULL, *port = NULL;
ip = switch_channel_get_variable(channel, SWITCH_REMOTE_MEDIA_IP_VARIABLE);
port = switch_channel_get_variable(channel, SWITCH_REMOTE_MEDIA_PORT_VARIABLE);
if (ip && port) {
sofia_glue_set_local_sdp(tech_pvt, ip, atoi(port), msg->string_arg, 1);
case SWITCH_MESSAGE_INDICATE_BROADCAST:{
const char *ip = NULL, *port = NULL;
ip = switch_channel_get_variable(channel, SWITCH_REMOTE_MEDIA_IP_VARIABLE);
port = switch_channel_get_variable(channel, SWITCH_REMOTE_MEDIA_PORT_VARIABLE);
if (ip && port) {
sofia_glue_set_local_sdp(tech_pvt, ip, atoi(port), msg->string_arg, 1);
}
nua_respond(tech_pvt->nh, SIP_200_OK,
SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
SOATAG_REUSE_REJECTED(1), SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"), NUTAG_INCLUDE_EXTRA_SDP(1), TAG_END());
switch_channel_mark_answered(channel);
}
nua_respond(tech_pvt->nh, SIP_200_OK,
SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
SOATAG_REUSE_REJECTED(1),
SOATAG_ORDERED_USER(1),
SOATAG_AUDIO_AUX("cn telephone-event"),
NUTAG_INCLUDE_EXTRA_SDP(1),
TAG_END());
switch_channel_mark_answered(channel);
}
break;
case SWITCH_MESSAGE_INDICATE_NOMEDIA:
case SWITCH_MESSAGE_INDICATE_NOMEDIA:
{
const char *uuid;
switch_core_session_t *other_session;
switch_channel_t *other_channel;
const char *ip = NULL, *port = NULL;
switch_channel_set_flag(channel, CF_PROXY_MODE);
tech_pvt->local_sdp_str = NULL;
if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))
@@ -826,14 +807,14 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
case SWITCH_MESSAGE_INDICATE_MEDIA:
{
uint32_t send_invite = 1;
switch_channel_clear_flag(channel, CF_PROXY_MODE);
tech_pvt->local_sdp_str = NULL;
if (!switch_channel_media_ready(channel)) {
if (!switch_channel_test_flag(tech_pvt->channel, CF_OUTBOUND)) {
const char *r_sdp = switch_channel_get_variable(channel, SWITCH_R_SDP_VARIABLE);
tech_pvt->num_codecs = 0;
sofia_glue_tech_prepare_codecs(tech_pvt);
if (sofia_glue_tech_media(tech_pvt, r_sdp) != SWITCH_STATUS_SUCCESS) {
@@ -882,7 +863,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
}
}
break;
case SWITCH_MESSAGE_INDICATE_UNHOLD:
{
switch_clear_flag_locked(tech_pvt, TFLAG_SIP_HOLD);
@@ -890,7 +871,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
}
break;
case SWITCH_MESSAGE_INDICATE_BRIDGE:
if (switch_test_flag(tech_pvt, TFLAG_XFER)) {
switch_clear_flag_locked(tech_pvt, TFLAG_XFER);
if (msg->pointer_arg) {
@@ -918,19 +899,19 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
}
}
/*
if (tech_pvt->rtp_session && switch_test_flag(tech_pvt, TFLAG_TIMER)) {
switch_rtp_clear_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_USE_TIMER);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "De-activate timed RTP!\n");
}
*/
if (tech_pvt->rtp_session && switch_test_flag(tech_pvt, TFLAG_TIMER)) {
switch_rtp_clear_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_USE_TIMER);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "De-activate timed RTP!\n");
}
*/
break;
case SWITCH_MESSAGE_INDICATE_UNBRIDGE:
/*
if (tech_pvt->rtp_session && switch_test_flag(tech_pvt, TFLAG_TIMER)) {
switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_USE_TIMER);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Re-activate timed RTP!\n");
}
*/
if (tech_pvt->rtp_session && switch_test_flag(tech_pvt, TFLAG_TIMER)) {
switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_USE_TIMER);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Re-activate timed RTP!\n");
}
*/
break;
case SWITCH_MESSAGE_INDICATE_REDIRECT:
if (msg->string_arg) {
@@ -962,7 +943,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
if (code) {
reason = msg->string_arg;
} else {
if (!switch_strlen_zero(msg->string_arg)){
if (!switch_strlen_zero(msg->string_arg)) {
if ((code = atoi(msg->string_arg))) {
if ((reason = strchr(msg->string_arg, ' '))) {
reason++;
@@ -974,14 +955,14 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
if (!code) {
code = 488;
}
if (switch_strlen_zero(reason) && code != 407) {
reason = sip_status_phrase(code);
if (switch_strlen_zero(reason)) {
reason = "Because";
}
}
if (code == 407 && !msg->numeric_arg) {
const char *to_uri = switch_channel_get_variable(channel, "sip_to_uri");
const char *to_host = reason;
@@ -990,14 +971,14 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
to_host = switch_channel_get_variable(channel, "sip_to_host");
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Challenging call %s\n", to_uri);
sofia_reg_auth_challange(NULL, tech_pvt->profile, tech_pvt->nh, REG_INVITE, to_host, 0);
sofia_reg_auth_challange(NULL, tech_pvt->profile, tech_pvt->nh, REG_INVITE, to_host, 0);
switch_channel_hangup(channel, SWITCH_CAUSE_USER_CHALLENGE);
} else if (code == 484 && msg->numeric_arg) {
const char *to = switch_channel_get_variable(channel, "sip_to_uri");
const char *max_forwards = switch_channel_get_variable(channel, SWITCH_MAX_FORWARDS_VARIABLE);
char *to_uri = NULL;
if (to) {
char *p;
to_uri = switch_core_session_sprintf(session, "sip:%s", to);
@@ -1015,9 +996,9 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
}
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Responding with %d [%s]\n", code, reason);
if (!switch_strlen_zero(((char *)msg->pointer_arg))) {
tech_pvt->local_sdp_str = switch_core_session_strdup(tech_pvt->session, (char *)msg->pointer_arg);
if (!switch_strlen_zero(((char *) msg->pointer_arg))) {
tech_pvt->local_sdp_str = switch_core_session_strdup(tech_pvt->session, (char *) msg->pointer_arg);
if (switch_channel_test_flag(channel, CF_PROXY_MEDIA)) {
sofia_glue_tech_patch_sdp(tech_pvt);
sofia_glue_tech_proxy_remote_addr(tech_pvt);
@@ -1025,10 +1006,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
nua_respond(tech_pvt->nh, code, reason, SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
SOATAG_REUSE_REJECTED(1),
SOATAG_ORDERED_USER(1),
SOATAG_AUDIO_AUX("cn telephone-event"),
NUTAG_INCLUDE_EXTRA_SDP(1),
TAG_END());
SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"), NUTAG_INCLUDE_EXTRA_SDP(1), TAG_END());
} else {
nua_respond(tech_pvt->nh, code, reason, SIPTAG_CONTACT_STR(tech_pvt->reply_contact), TAG_END());
}
@@ -1036,11 +1014,11 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
switch_set_flag_locked(tech_pvt, TFLAG_BYE);
}
}
}
break;
case SWITCH_MESSAGE_INDICATE_RINGING:
if (!switch_channel_test_flag(channel, CF_RING_READY) &&
if (!switch_channel_test_flag(channel, CF_RING_READY) &&
!switch_channel_test_flag(channel, CF_EARLY_MEDIA) && !switch_channel_test_flag(channel, CF_ANSWERED)) {
nua_respond(tech_pvt->nh, SIP_180_RINGING, SIPTAG_CONTACT_STR(tech_pvt->reply_contact), TAG_END());
switch_channel_mark_ring_ready(channel);
@@ -1055,10 +1033,10 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
const char *val = NULL;
if (!switch_test_flag(tech_pvt, TFLAG_ANS) && !switch_test_flag(tech_pvt, TFLAG_EARLY_MEDIA)) {
switch_set_flag_locked(tech_pvt, TFLAG_EARLY_MEDIA);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Asked to send early media by %s\n", msg->from);
/* Transmit 183 Progress with SDP */
if (switch_channel_test_flag(channel, CF_PROXY_MODE) || switch_channel_test_flag(channel, CF_PROXY_MEDIA)) {
const char *sdp = NULL;
@@ -1105,7 +1083,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
if (switch_test_flag(tech_pvt, TFLAG_NAT) ||
(val = switch_channel_get_variable(channel, "sip-force-contact")) ||
(val = switch_channel_get_variable(channel, "sip-force-contact")) ||
((val = switch_channel_get_variable(channel, "sip_sticky_contact")) && switch_true(val))) {
sticky = tech_pvt->record_route;
switch_channel_set_variable(channel, "sip_nat_detected", "true");
@@ -1117,8 +1095,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
TAG_IF(sticky, NUTAG_PROXY(tech_pvt->record_route)),
SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
SOATAG_REUSE_REJECTED(1),
SOATAG_ORDERED_USER(1),
SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str), SOATAG_AUDIO_AUX("cn telephone-event"), TAG_END());
SOATAG_ORDERED_USER(1), SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str), SOATAG_AUDIO_AUX("cn telephone-event"), TAG_END());
}
}
break;
@@ -1126,10 +1103,10 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
break;
}
end:
end:
return status;
}
static switch_status_t sofia_receive_event(switch_core_session_t *session, switch_event_t *event)
@@ -1158,14 +1135,15 @@ static switch_status_t sofia_receive_event(switch_core_session_t *session, switc
typedef switch_status_t (*sofia_command_t) (char **argv, int argc, switch_stream_handle_t *stream);
static const char *sofia_state_names[] = { "UNREGED",
"TRYING",
"REGISTER",
"REGED",
"UNREGISTER",
"FAILED",
"EXPIRED",
"NOREG",
NULL};
"TRYING",
"REGISTER",
"REGED",
"UNREGISTER",
"FAILED",
"EXPIRED",
"NOREG",
NULL
};
struct cb_helper {
sofia_profile_t *profile;
@@ -1188,17 +1166,14 @@ static int show_reg_callback(void *pArg, int argc, char **argv, char **columnNam
switch_strftime(exp_buf, &retsize, sizeof(exp_buf), "%Y-%m-%d %T", &tm);
}
cb->stream->write_function(cb->stream,
cb->stream->write_function(cb->stream,
"Call-ID \t%s\n"
"User \t%s@%s\n"
"Contact \t%s\n"
"Agent \t%s\n"
"Status \t%s(%s) EXP(%s)\n\n",
switch_str_nil(argv[0]), switch_str_nil(argv[1]), switch_str_nil(argv[2]), switch_str_nil(argv[3]),
switch_str_nil(argv[7]),
switch_str_nil(argv[4]),
switch_str_nil(argv[5]),
exp_buf);
"Status \t%s(%s) EXP(%s)\n\n",
switch_str_nil(argv[0]), switch_str_nil(argv[1]), switch_str_nil(argv[2]), switch_str_nil(argv[3]),
switch_str_nil(argv[7]), switch_str_nil(argv[4]), switch_str_nil(argv[5]), exp_buf);
return 0;
}
@@ -1254,24 +1229,24 @@ static switch_status_t cmd_status(char **argv, int argc, switch_stream_handle_t
stream->write_function(stream, "Name \t%s\n", switch_str_nil(argv[1]));
stream->write_function(stream, "Domain Name\t%s\n", switch_str_nil(profile->domain_name));
if (strcasecmp(argv[1], profile->name)) {
stream->write_function(stream, "Alias Of \t%s\n", switch_str_nil(profile->name));
stream->write_function(stream, "Alias Of \t%s\n", switch_str_nil(profile->name));
}
stream->write_function(stream, "DBName \t%s\n", switch_str_nil(profile->dbname));
stream->write_function(stream, "Dialplan \t%s\n", switch_str_nil(profile->dialplan));
stream->write_function(stream, "RTP-IP \t%s\n", switch_str_nil(profile->rtpip));
if (profile->extrtpip) {
stream->write_function(stream, "Ext-RTP-IP \t%s\n", profile->extrtpip);
stream->write_function(stream, "Ext-RTP-IP \t%s\n", profile->extrtpip);
}
stream->write_function(stream, "SIP-IP \t%s\n", switch_str_nil(profile->sipip));
if (profile->extsipip) {
stream->write_function(stream, "Ext-SIP-IP \t%s\n", profile->extsipip);
stream->write_function(stream, "Ext-SIP-IP \t%s\n", profile->extsipip);
}
stream->write_function(stream, "URL \t%s\n", switch_str_nil(profile->url));
stream->write_function(stream, "BIND-URL \t%s\n", switch_str_nil(profile->bindurl));
if (sofia_test_pflag(profile, PFLAG_TLS)) {
stream->write_function(stream, "TLS-URL \t%s\n", switch_str_nil(profile->tls_url));
stream->write_function(stream, "TLS-BIND-URL \t%s\n", switch_str_nil(profile->tls_bindurl));
stream->write_function(stream, "TLS-URL \t%s\n", switch_str_nil(profile->tls_url));
stream->write_function(stream, "TLS-BIND-URL \t%s\n", switch_str_nil(profile->tls_bindurl));
}
stream->write_function(stream, "HOLD-MUSIC \t%s\n", switch_str_nil(profile->hold_music));
stream->write_function(stream, "CODECS \t%s\n", switch_str_nil(profile->codec_string));
@@ -1283,10 +1258,8 @@ static switch_status_t cmd_status(char **argv, int argc, switch_stream_handle_t
cb.profile = profile;
cb.stream = stream;
sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex,
"select * from sip_registrations",
show_reg_callback, &cb);
sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex, "select * from sip_registrations", show_reg_callback, &cb);
stream->write_function(stream, "%s\n", line);
@@ -1308,7 +1281,7 @@ static switch_status_t cmd_status(char **argv, int argc, switch_stream_handle_t
switch_hash_this(hi, &vvar, NULL, &val);
profile = (sofia_profile_t *) val;
if (sofia_test_pflag(profile, PFLAG_RUNNING)) {
if (strcmp(vvar, profile->name)) {
ac++;
stream->write_function(stream, "%25s\t%s\t %32s\t%s\n", vvar, " alias", profile->name, "ALIASED");
@@ -1317,8 +1290,8 @@ static switch_status_t cmd_status(char **argv, int argc, switch_stream_handle_t
sofia_test_pflag(profile, PFLAG_RUNNING) ? "RUNNING" : "DOWN", profile->inuse);
if (sofia_test_pflag(profile, PFLAG_TLS)) {
stream->write_function(stream, "%25s\t%s\t %32s\t%s (%u) (TLS)\n", profile->name, "profile", profile->tls_url,
sofia_test_pflag(profile, PFLAG_RUNNING) ? "RUNNING" : "DOWN", profile->inuse);
stream->write_function(stream, "%25s\t%s\t %32s\t%s (%u) (TLS)\n", profile->name, "profile", profile->tls_url,
sofia_test_pflag(profile, PFLAG_RUNNING) ? "RUNNING" : "DOWN", profile->inuse);
}
c++;
@@ -1366,12 +1339,12 @@ static switch_status_t cmd_profile(char **argv, int argc, switch_stream_handle_t
}
return SWITCH_STATUS_SUCCESS;
}
if (switch_strlen_zero(profile_name) || !(profile = sofia_glue_find_profile(profile_name))) {
stream->write_function(stream, "Invalid Profile [%s]", switch_str_nil(profile_name));
return SWITCH_STATUS_SUCCESS;
}
if (!strcasecmp(argv[1], "flush_inbound_reg")) {
if (argc > 2) {
sofia_reg_expire_call_id(profile, argv[2]);
@@ -1407,7 +1380,7 @@ static switch_status_t cmd_profile(char **argv, int argc, switch_stream_handle_t
} else {
stream->write_function(stream, "Invalid gateway!\n");
}
goto done;
}
@@ -1442,7 +1415,7 @@ static switch_status_t cmd_profile(char **argv, int argc, switch_stream_handle_t
int diff = (int) (switch_timestamp(NULL) - profile->started);
int remain = rsec - diff;
if (diff < rsec) {
stream->write_function(stream, "Profile %s must be up for at least %d seconds to stop/restart.\nPlease wait %d second%s\n",
stream->write_function(stream, "Profile %s must be up for at least %d seconds to stop/restart.\nPlease wait %d second%s\n",
profile->name, rsec, remain, remain == 1 ? "" : "s");
} else {
@@ -1467,7 +1440,7 @@ static switch_status_t cmd_profile(char **argv, int argc, switch_stream_handle_t
stream->write_function(stream, "-ERR Unknown command!\n");
done:
done:
if (profile) {
sofia_glue_release_profile(profile);
}
@@ -1524,14 +1497,14 @@ SWITCH_STANDARD_API(sofia_contact_function)
if ((domain = strchr(user, '@'))) {
*domain++ = '\0';
}
if (!profile_name && domain) {
profile_name = domain;
}
if (user && profile_name) {
char *sql;
if (!(profile = sofia_glue_find_profile(profile_name))) {
profile_name = domain;
domain = NULL;
@@ -1544,7 +1517,7 @@ SWITCH_STANDARD_API(sofia_contact_function)
if (profile) {
struct cb_helper cb;
switch_stream_handle_t mystream = { 0 };
if (!domain || !strchr(domain, '.')) {
domain = profile->name;
}
@@ -1553,9 +1526,9 @@ SWITCH_STANDARD_API(sofia_contact_function)
switch_assert(mystream.data);
cb.profile = profile;
cb.stream = &mystream;
if (exclude_contact) {
sql = switch_mprintf("select contact from sip_registrations where sip_user='%q' and sip_host='%q' and contact not like '%%%s%%'",
sql = switch_mprintf("select contact from sip_registrations where sip_user='%q' and sip_host='%q' and contact not like '%%%s%%'",
user, domain, exclude_contact);
} else {
sql = switch_mprintf("select contact from sip_registrations where sip_user='%q' and sip_host='%q'", user, domain);
@@ -1573,7 +1546,7 @@ SWITCH_STANDARD_API(sofia_contact_function)
switch_safe_free(mystream.data);
}
}
if (reply) {
stream->write_function(stream, "%s", reply);
}
@@ -1600,13 +1573,12 @@ SWITCH_STANDARD_API(sofia_function)
"sofia help\n"
"sofia profile <profile_name> [start|stop|restart|flush_inbound_reg [<call_id>]|[register|unregister] [<gateway name>|all]] [reloadxml]\n"
"sofia status [[profile | gateway] <name>]\n"
"sofia loglevel [0-9]\n"
"--------------------------------------------------------------------------------\n";
"sofia loglevel [0-9]\n" "--------------------------------------------------------------------------------\n";
if (session) {
return SWITCH_STATUS_FALSE;
}
if (switch_strlen_zero(cmd)) {
stream->write_function(stream, "%s", usage_string);
goto done;
@@ -1621,7 +1593,7 @@ SWITCH_STANDARD_API(sofia_function)
stream->write_function(stream, "%s", usage_string);
goto done;
}
if (!strcasecmp(argv[0], "profile")) {
func = cmd_profile;
} else if (!strcasecmp(argv[0], "status")) {
@@ -1664,9 +1636,9 @@ switch_io_routines_t sofia_io_routines = {
/*.send_dtmf */ sofia_send_dtmf,
/*.receive_message */ sofia_receive_message,
/*.receive_event */ sofia_receive_event,
/*.state_change*/ NULL,
/*.read_video_frame*/ sofia_read_video_frame,
/*.write_video_frame*/ sofia_write_video_frame
/*.state_change */ NULL,
/*.read_video_frame */ sofia_read_video_frame,
/*.write_video_frame */ sofia_write_video_frame
};
switch_state_handler_table_t sofia_event_handlers = {
@@ -1677,8 +1649,8 @@ switch_state_handler_table_t sofia_event_handlers = {
/*.on_exchange_media */ sofia_on_exchange_media,
/*.on_soft_execute */ sofia_on_soft_execute,
/*.on_consume_media */ NULL,
/*.on_hibernate*/ sofia_on_hibernate,
/*.on_reset*/ sofia_on_reset
/*.on_hibernate */ sofia_on_hibernate,
/*.on_reset */ sofia_on_reset
};
static switch_status_t sofia_manage(char *relative_oid, switch_management_action_t action, char *data, switch_size_t datalen)
@@ -1698,7 +1670,7 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
private_object_t *tech_pvt = NULL;
switch_channel_t *nchannel;
char *host = NULL, *dest_to = NULL;
*new_session = NULL;
if (!(nsession = switch_core_session_request(sofia_endpoint_interface, pool))) {
@@ -1758,14 +1730,14 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
* invite contact.
*
* TODO:
* - Add parameters back to destination url?
* - Add parameters back to destination url?
*/
if ((params = strchr(dest, ';'))) {
char *tp_param;
*params++ = '\0';
if ((tp_param = (char *)switch_stristr("port=", params))) {
if ((tp_param = (char *) switch_stristr("port=", params))) {
tp_param += 5;
tech_pvt->transport = sofia_glue_str2transport(tp_param);
if (tech_pvt->transport == SOFIA_TRANSPORT_UNKNOWN) {
@@ -1776,7 +1748,8 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
}
if (tech_pvt->transport != gateway_ptr->register_transport) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "You are trying to use a different transport type for this gateway (overriding the register-transport), this is unsupported!\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"You are trying to use a different transport type for this gateway (overriding the register-transport), this is unsupported!\n");
cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
goto error;
}
@@ -1860,7 +1833,7 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
tech_pvt->dest_to = switch_core_session_sprintf(nsession, "sip:%s@%s", dest_to, host);
}
}
if (!tech_pvt->dest_to) {
tech_pvt->dest_to = tech_pvt->dest;
@@ -1961,7 +1934,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sofia_load)
switch_core_hash_init(&mod_sofia_globals.profile_hash, mod_sofia_globals.pool);
switch_core_hash_init(&mod_sofia_globals.gateway_hash, mod_sofia_globals.pool);
switch_mutex_init(&mod_sofia_globals.hash_mutex, SWITCH_MUTEX_NESTED, mod_sofia_globals.pool);
switch_mutex_lock(mod_sofia_globals.mutex);
mod_sofia_globals.running = 1;
switch_mutex_unlock(mod_sofia_globals.mutex);
@@ -2034,7 +2007,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sofia_load)
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_sofia_shutdown)
{
int sanity = 0;
switch_mutex_lock(mod_sofia_globals.mutex);
if (mod_sofia_globals.running == 1) {
mod_sofia_globals.running = 0;
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+147 -193
View File
@@ -127,7 +127,8 @@ void sofia_presence_cancel(void)
void *val;
struct presence_helper helper = { 0 };
if (!mod_sofia_globals.profile_hash) return;
if (!mod_sofia_globals.profile_hash)
return;
if ((sql = switch_mprintf("select *,-1,'unavailable','unavailable' from sip_subscriptions where event='presence'"))) {
switch_mutex_lock(mod_sofia_globals.hash_mutex);
@@ -151,16 +152,15 @@ void sofia_presence_cancel(void)
void sofia_presence_establish_presence(sofia_profile_t *profile)
{
if (sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex,
"select sip_user,sip_host,'Registered','unknown','' from sip_registrations",
if (sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex,
"select sip_user,sip_host,'Registered','unknown','' from sip_registrations",
sofia_presence_resub_callback, profile) != SWITCH_TRUE) {
return;
}
if (sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex,
"select sub_to_user,sub_to_host,'Online','unknown',proto from sip_subscriptions "
"where proto='ext' or proto='user' or proto='conf'",
sofia_presence_resub_callback, profile) != SWITCH_TRUE) {
"where proto='ext' or proto='user' or proto='conf'", sofia_presence_resub_callback, profile) != SWITCH_TRUE) {
return;
}
}
@@ -172,7 +172,7 @@ char *sofia_presence_translate_rpid(char *in, char *ext)
if (in && (switch_stristr("null", in))) {
in = NULL;
}
if (!in) {
in = ext;
}
@@ -233,7 +233,7 @@ static void actual_sofia_presence_mwi_event_handler(switch_event_t *event)
return;
}
}
if (profile->domain_name && profile->domain_name != host) {
host = profile->domain_name;
}
@@ -251,43 +251,32 @@ static void actual_sofia_presence_mwi_event_handler(switch_event_t *event)
if (!strcasecmp(hp->name, "mwi-message-account") && strncasecmp(hp->value, "sip:", 4)) {
tmp = switch_mprintf("sip:%s", hp->value);
value = tmp;
}
}
stream.write_function(&stream, "%s: %s\r\n", hp->name + 4, value);
switch_safe_free(tmp);
}
}
stream.write_function(&stream, "\r\n");
sql = switch_mprintf("select *,'%q' from sip_subscriptions where event='message-summary' and sub_to_user='%q' and sub_to_host='%q'",
stream.data, user, host);
switch_assert (sql != NULL);
sofia_glue_execute_sql_callback(profile,
SWITCH_FALSE,
profile->ireg_mutex,
sql,
sofia_presence_mwi_callback,
&h);
sql = switch_mprintf("select *,'%q' from sip_subscriptions where event='message-summary' and sub_to_user='%q' and sub_to_host='%q'",
stream.data, user, host);
switch_assert(sql != NULL);
sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex, sql, sofia_presence_mwi_callback, &h);
switch_safe_free(sql);
sql = switch_mprintf("select sip_user,sip_host,contact,'%q' from sip_registrations where sip_user='%q' and sip_host='%q'",
stream.data, user, host);
switch_assert (sql != NULL);
sofia_glue_execute_sql_callback(profile,
SWITCH_FALSE,
profile->ireg_mutex,
sql,
sofia_presence_mwi_callback2,
&h);
sql = switch_mprintf("select sip_user,sip_host,contact,'%q' from sip_registrations where sip_user='%q' and sip_host='%q'", stream.data, user, host);
switch_assert(sql != NULL);
sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex, sql, sofia_presence_mwi_callback2, &h);
switch_safe_free(sql);
switch_safe_free(stream.data);
@@ -312,11 +301,11 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
char *sql = NULL;
char *euser = NULL, *user = NULL, *host = NULL;
if (!mod_sofia_globals.running) {
return;
}
if (rpid && !strcasecmp(rpid, "n/a")) {
rpid = NULL;
}
@@ -350,8 +339,9 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
if (event->event_id == SWITCH_EVENT_ROSTER) {
struct presence_helper helper = { 0 };
if (!mod_sofia_globals.profile_hash) return;
if (!mod_sofia_globals.profile_hash)
return;
if (from) {
sql = switch_mprintf("select *,1,'%q','%q' from sip_subscriptions where event='presence' and full_from like '%%%q%%'", status, rpid, from);
} else {
@@ -367,13 +357,8 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
continue;
}
helper.profile = profile;
helper.event = NULL;
sofia_glue_execute_sql_callback(profile,
SWITCH_FALSE,
profile->ireg_mutex,
sql,
sofia_presence_sub_callback,
&helper);
helper.event = NULL;
sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex, sql, sofia_presence_sub_callback, &helper);
}
switch_mutex_unlock(mod_sofia_globals.hash_mutex);
free(sql);
@@ -387,7 +372,7 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
if (switch_strlen_zero(alt_event_type)) {
alt_event_type = "presence";
}
if ((user = strdup(from))) {
if ((host = strchr(user, '@'))) {
char *p;
@@ -432,15 +417,9 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
"from sip_registrations left join sip_dialogs on "
"(sip_dialogs.sip_from_user = sip_registrations.sip_user) "
"and sip_dialogs.sip_from_host = sip_registrations.sip_host "
"where sip_registrations.sip_user='%q' and sip_registrations.sip_host='%q'",
probe_euser, probe_host);
"where sip_registrations.sip_user='%q' and sip_registrations.sip_host='%q'", probe_euser, probe_host);
switch_assert(sql);
sofia_glue_execute_sql_callback(profile,
SWITCH_FALSE,
profile->ireg_mutex,
sql,
sofia_presence_resub_callback,
profile);
sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex, sql, sofia_presence_resub_callback, profile);
sofia_glue_release_profile(profile);
switch_safe_free(sql);
@@ -465,7 +444,8 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
break;
}
if (!mod_sofia_globals.profile_hash) goto done;
if (!mod_sofia_globals.profile_hash)
goto done;
switch_mutex_lock(mod_sofia_globals.hash_mutex);
for (hi = switch_hash_first(NULL, mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) {
@@ -478,31 +458,27 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
if (sql) {
struct presence_helper helper = { 0 };
helper.profile = profile;
helper.event = event;
helper.event = event;
SWITCH_STANDARD_STREAM(helper.stream);
switch_assert(helper.stream.data);
sofia_glue_execute_sql_callback(profile,
SWITCH_FALSE,
sofia_glue_execute_sql_callback(profile, SWITCH_FALSE,
//profile->ireg_mutex,
NULL,
sql,
sofia_presence_sub_callback,
&helper);
if (!switch_strlen_zero((char *)helper.stream.data)) {
char *this = (char *)helper.stream.data;
NULL, sql, sofia_presence_sub_callback, &helper);
if (!switch_strlen_zero((char *) helper.stream.data)) {
char *this = (char *) helper.stream.data;
char *next = NULL;
char *last = NULL;
do {
if ((next = strchr(this, ';'))) {
*next++ = '\0';
while(*next == '\n' || *next == ' ' || *next == '\r') {
while (*next == '\n' || *next == ' ' || *next == '\r') {
*next++ = '\0';
}
}
if (!switch_strlen_zero(this) && (!last || strcmp(last, this))) {
sofia_glue_execute_sql(profile, &this, SWITCH_FALSE);
last = this;
@@ -516,7 +492,7 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
}
switch_mutex_unlock(mod_sofia_globals.hash_mutex);
done:
done:
switch_safe_free(sql);
switch_safe_free(user);
}
@@ -543,10 +519,10 @@ void *SWITCH_THREAD_FUNC sofia_presence_event_thread_run(switch_thread_t *thread
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Event Thread Started\n");
while (mod_sofia_globals.running == 1) {
int count = 0;
if (switch_queue_trypop(mod_sofia_globals.presence_queue, &pop) == SWITCH_STATUS_SUCCESS) {
switch_event_t *event = (switch_event_t *) pop;
@@ -580,7 +556,7 @@ void *SWITCH_THREAD_FUNC sofia_presence_event_thread_run(switch_thread_t *thread
switch_event_t *event = (switch_event_t *) pop;
switch_event_destroy(&event);
}
while (switch_queue_trypop(mod_sofia_globals.mwi_queue, &pop) == SWITCH_STATUS_SUCCESS && pop) {
switch_event_t *event = (switch_event_t *) pop;
switch_event_destroy(&event);
@@ -592,7 +568,7 @@ void *SWITCH_THREAD_FUNC sofia_presence_event_thread_run(switch_thread_t *thread
mod_sofia_globals.threads--;
EVENT_THREAD_RUNNING = EVENT_THREAD_STARTED = 0;
switch_mutex_unlock(mod_sofia_globals.mutex);
return NULL;
}
@@ -728,7 +704,7 @@ static int sofia_presence_resub_callback(void *pArg, int argc, char **argv, char
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "astate", "%s", state);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "call-direction", "%s", direction);
}
switch_event_fire(&event);
}
@@ -738,7 +714,7 @@ static int sofia_presence_resub_callback(void *pArg, int argc, char **argv, char
static char *translate_rpid(char *in)
{
char *r = in;
if (in && (strstr(in, "null") || strstr(in, "NULL"))) {
in = NULL;
}
@@ -762,7 +738,7 @@ static char *translate_rpid(char *in)
r = "busy";
}
end:
end:
return r;
}
@@ -792,17 +768,17 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
char *prpid;
int done = 0;
const char *ct = "no/idea";
time_t exptime = switch_timestamp(NULL) + 3600;
char exp[80] = "";
time_t exptime = switch_timestamp(NULL) + 3600;
char exp[80] = "";
int is_dialog = 0;
if (expires) {
long tmp = atol(expires);
if (tmp > 0) {
exptime = tmp - switch_timestamp(NULL);
if (expires) {
long tmp = atol(expires);
if (tmp > 0) {
exptime = tmp - switch_timestamp(NULL);
}
}
if (!(nh = nua_handle_by_call_id(profile->nua, call_id))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Cannot find handle for %s\n", call_id);
return 0;
@@ -817,7 +793,7 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
if (in < 0) {
done = 1;
in = 0;
}
}
if (!strcasecmp(proto, SOFIA_CHAT_PROTO)) {
clean_id = switch_mprintf("sip:%s@%s", sub_to_user, sub_to_host);
@@ -838,7 +814,7 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
to = switch_mprintf("sip:%s@%s", user, host);
is_dialog = !strcmp(event, "dialog");
if (helper->event) {
switch_stream_handle_t stream = { 0 };
const char *direction = switch_str_nil(switch_event_get_header(helper->event, "call-direction"));
@@ -854,7 +830,7 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
const char *clean_to_user = NULL;
const char *clean_from_user = NULL;
if (is_dialog) {
SWITCH_STANDARD_STREAM(stream);
}
@@ -866,43 +842,43 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
direction = "initiator";
dft_state = "confirmed";
}
if (!strcasecmp(state, "cs_execute") && !strstr(event_status, "hold")) {
goto end;
}
}
if (!strcasecmp(event_status, "Registered")) {
answer_state = "resubscribe";
}
if (is_dialog) {
stream.write_function(&stream,
stream.write_function(&stream,
"<?xml version=\"1.0\"?>\n"
"<dialog-info xmlns=\"urn:ietf:params:xml:ns:dialog-info\" "
"version=\"%s\" state=\"%s\" entity=\"%s\">\n",
"version=\"%s\" state=\"%s\" entity=\"%s\">\n",
switch_str_nil(switch_event_get_header(helper->event, "event_count")),
!strcasecmp(answer_state, "resubscribe") ? "partial" : "full", clean_id);
}
if (strcasecmp(answer_state, "resubscribe")) {
if (!strcasecmp(state, "cs_hangup")) {
astate = "terminated";
} else if (switch_strlen_zero(astate)) {
} else if (switch_strlen_zero(astate)) {
astate = switch_str_nil(switch_event_get_header(helper->event, "answer-state"));
if (switch_strlen_zero(astate)) {
if (switch_strlen_zero(astate)) {
astate = dft_state;
}
}
}
if (!strcasecmp(event_status, "hold")) {
astate = "early";
}
if (!strcasecmp(astate, "answered")) {
astate = "confirmed";
}
if (!strcasecmp(astate, "ringing")) {
if (!strcasecmp(direction, "recipient")) {
astate = "early";
@@ -915,7 +891,7 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
stream.write_function(&stream, "<state>%s</state>\n", astate);
}
if (!strcasecmp(astate, "early") || !strcasecmp(astate, "confirmed")) {
clean_to_user = switch_mprintf("%s", sub_to_user ? sub_to_user : to_user);
clean_from_user = switch_mprintf("%s", from_id ? from_id : from_user);
@@ -923,24 +899,26 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
if (!switch_strlen_zero(clean_to_user) && !switch_strlen_zero(clean_from_user)) {
stream.write_function(&stream, "<local>\n<identity display=\"%s\">sip:%s@%s</identity>\n", clean_to_user, clean_to_user, host);
stream.write_function(&stream, "<target uri=\"sip:%s@%s\">\n", clean_to_user, host);
stream.write_function(&stream, "<param pname=\"+sip.rendering\" pvalue=\"%s\"/>\n", !strcasecmp(event_status, "hold") ? "no" : "yes" );
stream.write_function(&stream, "</target>\n</local>\n");
stream.write_function(&stream, "<remote>\n<identity display=\"%s\">sip:%s@%s</identity>\n", clean_from_user, clean_from_user, host);
stream.write_function(&stream, "<param pname=\"+sip.rendering\" pvalue=\"%s\"/>\n",
!strcasecmp(event_status, "hold") ? "no" : "yes");
stream.write_function(&stream, "</target>\n</local>\n");
stream.write_function(&stream, "<remote>\n<identity display=\"%s\">sip:%s@%s</identity>\n", clean_from_user, clean_from_user,
host);
stream.write_function(&stream, "<target uri=\"sip:**%s@%s\"/>\n", clean_to_user, host);
stream.write_function(&stream, "</remote>\n");
} else if (!strcasecmp(proto, "park")) {
stream.write_function(&stream, "<local>\n<identity display=\"parking\">sip:parking@%s;fifo=%s</identity>\n",
stream.write_function(&stream, "<local>\n<identity display=\"parking\">sip:parking@%s;fifo=%s</identity>\n",
host, !switch_strlen_zero(clean_to_user) ? clean_to_user : "unknown");
stream.write_function(&stream, "<target uri=\"sip:parking@%s\">\n", host);
stream.write_function(&stream, "<param pname=\"+sip.rendering\" pvalue=\"no\"/>\n</target>\n</local>\n");
stream.write_function(&stream, "<param pname=\"+sip.rendering\" pvalue=\"no\"/>\n</target>\n</local>\n");
stream.write_function(&stream, "<remote>\n<identity display=\"parking\">sip:%s</identity>\n", uuid);
stream.write_function(&stream, "<target uri=\"sip:park+%s\"/>\n", uuid);
stream.write_function(&stream, "</remote>\n");
} else if (!strcasecmp(proto, "conf")) {
stream.write_function(&stream, "<local>\n<identity display=\"conference\">sip:conference@%s;conference=%s</identity>\n",
stream.write_function(&stream, "<local>\n<identity display=\"conference\">sip:conference@%s;conference=%s</identity>\n",
host, !switch_strlen_zero(clean_to_user) ? clean_to_user : "unknown");
stream.write_function(&stream, "<target uri=\"sip:conference@%s\">\n", host);
stream.write_function(&stream, "<param pname=\"+sip.rendering\" pvalue=\"yes\"/>\n</target>\n</local>\n");
stream.write_function(&stream, "<param pname=\"+sip.rendering\" pvalue=\"yes\"/>\n</target>\n</local>\n");
stream.write_function(&stream, "<remote>\n<identity display=\"conference\">sip:%s@%s</identity>\n", uuid, host);
stream.write_function(&stream, "<target uri=\"sip:conf+%s@%s\"/>\n", uuid, host);
stream.write_function(&stream, "</remote>\n");
@@ -948,7 +926,7 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
}
}
if (is_dialog) {
stream.write_function(&stream, "</dialog>\n");
stream.write_function(&stream, "</dialog>\n");
}
}
@@ -957,10 +935,10 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
pl = stream.data;
ct = "application/dialog-info+xml";
}
if (!switch_strlen_zero(astate) && !switch_strlen_zero(uuid) && helper && helper->stream.data && strcmp(helper->last_uuid, uuid)) {
helper->stream.write_function(&helper->stream, "update sip_dialogs set state='%s' where uuid='%s';", astate, uuid);
switch_copy_string(helper->last_uuid, uuid, sizeof(helper->last_uuid));
}
@@ -968,7 +946,7 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
if (!is_dialog) {
if (in) {
char status_line[256] = "";
if (!strcmp(astate, "early")) {
switch_snprintf(status_line, sizeof(status_line), "R %s", switch_str_nil(from_id));
rpid = "on-the-phone";
@@ -976,8 +954,8 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
char *dest = switch_event_get_header(helper->event, "Caller-Destination-Number");
if (switch_strlen_zero(from_id) && !switch_strlen_zero(dest)) {
from_id = dest;
}
}
if (switch_strlen_zero(from_id)) {
switch_snprintf(status_line, sizeof(status_line), "Available");
} else {
@@ -994,7 +972,7 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
note = NULL;
open = "closed";
}
prpid = translate_rpid(rpid);
pl = switch_mprintf("<?xml version='1.0' encoding='UTF-8'?>\r\n"
"<presence xmlns='urn:ietf:params:xml:ns:pidf'\r\n"
@@ -1017,11 +995,8 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
"</status>\r\n"
"</tuple>\r\n"
"<dm:person id='p06360c4a'>\r\n"
"<rpid:activities>\r\n" "<rpid:%s/>\r\n"
"</rpid:activities>%s</dm:person>\r\n"
"</presence>", id,
id, profile->url, open, status, prpid,
open, rpid, note);
"<rpid:activities>\r\n" "<rpid:%s/>\r\n"
"</rpid:activities>%s</dm:person>\r\n" "</presence>", id, id, profile->url, open, status, prpid, open, rpid, note);
ct = "application/pidf+xml";
}
@@ -1055,21 +1030,16 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
"</status>\r\n"
"</tuple>\r\n"
"<dm:person id='p06360c4a'>\r\n"
"<rpid:activities>\r\n" "<rpid:%s/>\r\n"
"</rpid:activities>%s</dm:person>\r\n"
"</presence>", id,
id, profile->url, open, status, prpid,
open, rpid, note);
"<rpid:activities>\r\n" "<rpid:%s/>\r\n"
"</rpid:activities>%s</dm:person>\r\n" "</presence>", id, id, profile->url, open, status, prpid, open, rpid, note);
ct = "application/pidf+xml";
}
switch_snprintf(exp, sizeof(exp), "active;expires=%ld", (long) exptime);
switch_snprintf(exp, sizeof(exp), "active;expires=%ld", (long) exptime);
nua_handle_bind(nh, &mod_sofia_globals.keep_private);
nua_notify(nh,
SIPTAG_SUBSCRIPTION_STATE_STR(exp),
SIPTAG_EVENT_STR(event), SIPTAG_CONTENT_TYPE_STR(ct), SIPTAG_PAYLOAD_STR(pl), TAG_END());
nua_notify(nh, SIPTAG_SUBSCRIPTION_STATE_STR(exp), SIPTAG_EVENT_STR(event), SIPTAG_CONTENT_TYPE_STR(ct), SIPTAG_PAYLOAD_STR(pl), TAG_END());
end:
end:
switch_safe_free(id);
switch_safe_free(clean_id);
@@ -1101,15 +1071,15 @@ static int sofia_presence_mwi_callback(void *pArg, int argc, char **argv, char *
int expire_sec = atoi(expires);
//int *total = (int *) pArg;
struct mwi_helper *h = (struct mwi_helper *) pArg;
if (!(nh = nua_handle_by_call_id(h->profile->nua, call_id))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find handle for %s\n", call_id);
return 0;
}
id = switch_mprintf("sip:%s@%s", sub_to_user, sub_to_host);
expire_sec = (int)(expire_sec - switch_timestamp(NULL));
expire_sec = (int) (expire_sec - switch_timestamp(NULL));
if (expire_sec < 0) {
expire_sec = 3600;
}
@@ -1118,7 +1088,7 @@ static int sofia_presence_mwi_callback(void *pArg, int argc, char **argv, char *
nua_notify(nh,
SIPTAG_SUBSCRIPTION_STATE_STR(exp),
SIPTAG_EVENT_STR(event), SIPTAG_CONTENT_TYPE_STR("application/simple-message-summary"), SIPTAG_PAYLOAD_STR(body), TAG_END());
switch_safe_free(id);
switch_safe_free(exp);
@@ -1139,33 +1109,29 @@ static int sofia_presence_mwi_callback2(void *pArg, int argc, char **argv, char
char *id = NULL;
nua_handle_t *nh;
struct mwi_helper *h = (struct mwi_helper *) pArg;
id = switch_mprintf("sip:%s@%s", sub_to_user, sub_to_host);
contact = sofia_glue_get_url_from_contact(o_contact, 1);
nh = nua_handle(h->profile->nua, NULL,
NUTAG_URL(contact),
SIPTAG_FROM_STR(id),
SIPTAG_TO_STR(id),
SIPTAG_CONTACT_STR(h->profile->url),
TAG_END());
nh = nua_handle(h->profile->nua, NULL, NUTAG_URL(contact), SIPTAG_FROM_STR(id), SIPTAG_TO_STR(id), SIPTAG_CONTACT_STR(h->profile->url), TAG_END());
nua_notify(nh,
NUTAG_NEWSUB(1),
TAG_IF(strstr(o_contact, ";nat"), NUTAG_PROXY(contact)),
SIPTAG_EVENT_STR(event), SIPTAG_CONTENT_TYPE_STR("application/simple-message-summary"), SIPTAG_PAYLOAD_STR(body), TAG_END());
switch_safe_free(contact);
switch_safe_free(id);
return 0;
}
void sofia_presence_handle_sip_i_subscribe(int status,
char const *phrase,
nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[])
char const *phrase,
nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
tagi_t tags[])
{
if (sip) {
long exp, exp_raw;
@@ -1205,15 +1171,14 @@ void sofia_presence_handle_sip_i_subscribe(int status,
get_addr(network_ip, sizeof(network_ip), &((struct sockaddr_in *) my_addrinfo->ai_addr)->sin_addr);
network_port = ntohs(((struct sockaddr_in *) msg_addrinfo(nua_current_request(nua))->ai_addr)->sin_port);
tl_gets(tags,
NUTAG_SUBSTATE_REF(sub_state), TAG_END());
tl_gets(tags, NUTAG_SUBSTATE_REF(sub_state), TAG_END());
event = sip_header_as_string(profile->home, (void *) sip->sip_event);
port = (char *) contact->m_url->url_port;
contact_host = sip->sip_contact->m_url->url_host;
contact_user = sip->sip_contact->m_url->url_user;
display = contact->m_display;
if (switch_strlen_zero(display)) {
@@ -1226,12 +1191,12 @@ void sofia_presence_handle_sip_i_subscribe(int status,
} else {
display = "\"user\"";
}
if ((profile->pflags & PFLAG_AGGRESSIVE_NAT_DETECTION)) {
if (sip && sip->sip_via) {
const char *v_port = sip->sip_via->v_port;
const char *v_host = sip->sip_via->v_host;
if (v_host && sip->sip_via->v_received) {
is_nat = "via received";
} else if (v_host && strcmp(network_ip, v_host)) {
@@ -1241,27 +1206,27 @@ void sofia_presence_handle_sip_i_subscribe(int status,
}
}
}
if (!is_nat && profile->nat_acl_count) {
uint32_t x = 0;
int ok = 1;
char *last_acl = NULL;
if (!switch_strlen_zero(contact_host)) {
for (x = 0 ; x < profile->nat_acl_count; x++) {
for (x = 0; x < profile->nat_acl_count; x++) {
last_acl = profile->nat_acl[x];
if (!(ok = switch_check_network_list_ip(contact_host, last_acl))) {
break;
}
}
if (ok) {
is_nat = last_acl;
}
}
}
if (is_nat) {
contact_host = network_ip;
switch_snprintf(new_port, sizeof(new_port), ":%d", network_port);
@@ -1272,14 +1237,14 @@ void sofia_presence_handle_sip_i_subscribe(int status,
if (port) {
switch_snprintf(new_port, sizeof(new_port), ":%s", port);
}
if (contact->m_url->url_params) {
contact_str = switch_mprintf("%s <sip:%s@%s%s;%s>%s",
display, contact->m_url->url_user, contact_host, new_port, contact->m_url->url_params, is_nat ? ";nat" : "");
} else {
contact_str = switch_mprintf("%s <sip:%s@%s%s>%s", display, contact->m_url->url_user, contact_host, new_port, is_nat ? ";nat" : "");
}
if (to) {
to_str = switch_mprintf("sip:%s@%s", to->a_url->url_user, to->a_url->url_host); //, to->a_url->url_port);
@@ -1306,7 +1271,7 @@ void sofia_presence_handle_sip_i_subscribe(int status,
if ((p = strchr(protocol, '+'))) {
*p = '\0';
}
if (switch_event_create(&sevent, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "proto", protocol);
switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "login", "%s", profile->name);
@@ -1315,7 +1280,7 @@ void sofia_presence_handle_sip_i_subscribe(int status,
switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "status", "Click To Call");
switch_event_fire(&sevent);
}
} else {
if (switch_event_create(&sevent, SWITCH_EVENT_PRESENCE_PROBE) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
@@ -1358,12 +1323,7 @@ void sofia_presence_handle_sip_i_subscribe(int status,
} else {
sql = switch_mprintf("delete from sip_subscriptions where "
"proto='%q' and sip_user='%q' and sip_host='%q' and sub_to_user='%q' and sub_to_host='%q' and event='%q'",
proto,
from_user,
from_host,
to_user,
to_host, event
);
proto, from_user, from_host, to_user, to_host, event);
}
@@ -1377,34 +1337,30 @@ void sofia_presence_handle_sip_i_subscribe(int status,
sip_accept_t *ap = sip->sip_accept;
char accept[256] = "";
full_agent = sip_header_as_string(profile->home, (void *) sip->sip_user_agent);
while(ap) {
while (ap) {
switch_snprintf(accept + strlen(accept), sizeof(accept) - strlen(accept), "%s%s ", ap->ac_type, ap->ac_next ? "," : "");
ap = ap->ac_next;
}
sql = switch_mprintf("insert into sip_subscriptions values ('%q','%q','%q','%q','%q','%q','%q','%q','%q','%q',%ld,'%q','%q')",
proto, from_user, from_host, to_user, to_host, event,
contact_str, call_id, full_from, full_via, exp, full_agent, accept);
proto, from_user, from_host, to_user, to_host, event, contact_str, call_id, full_from, full_via, exp, full_agent, accept);
switch_assert(sql != NULL);
sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
sstr = switch_mprintf("active;expires=%ld", exp_raw);
}
switch_mutex_unlock(profile->ireg_mutex);
if (status < 200) {
char *sticky = NULL;
if (is_nat) {
sticky = switch_mprintf("sip:%s@%s:%d", contact_user, network_ip, network_port);
}
nua_respond(nh, SIP_202_ACCEPTED,
NUTAG_WITH_THIS(nua),
SIPTAG_SUBSCRIPTION_STATE_STR(sstr),
TAG_IF(sticky, NUTAG_PROXY(sticky)),
nua_respond(nh, SIP_202_ACCEPTED, NUTAG_WITH_THIS(nua), SIPTAG_SUBSCRIPTION_STATE_STR(sstr), TAG_IF(sticky, NUTAG_PROXY(sticky)),
//SIPTAG_FROM(sip->sip_to),
//SIPTAG_TO(sip->sip_from),
//SIPTAG_CONTACT_STR(contact_str),
@@ -1413,32 +1369,26 @@ void sofia_presence_handle_sip_i_subscribe(int status,
switch_safe_free(sticky);
}
sent_reply++;
#if 0
nua_notify(nh,
nua_notify(nh,
NUTAG_NEWSUB(1),
SIPTAG_SUBSCRIPTION_STATE_STR(sstr), SIPTAG_EVENT_STR(event),
SIPTAG_SUBSCRIPTION_STATE_STR(sstr), SIPTAG_EVENT_STR(event),
SIPTAG_CONTENT_TYPE_STR("application/simple-message-summary"),
SIPTAG_PAYLOAD_STR("Note: Come to ClueCon http://www.cluecon.com\n\n"),
TAG_END());
SIPTAG_PAYLOAD_STR("Note: Come to ClueCon http://www.cluecon.com\n\n"), TAG_END());
#endif
switch_safe_free(sstr);
if ((sql = switch_mprintf("select * from sip_subscriptions where sip_user='%q' and sip_host='%q'", to_user, to_host))) {
sofia_glue_execute_sql_callback(profile,
SWITCH_FALSE,
profile->ireg_mutex,
sql,
sofia_presence_sub_reg_callback,
profile);
sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex, sql, sofia_presence_sub_reg_callback, profile);
switch_safe_free(sql);
}
end:
end:
if (event) {
su_free(profile->home, event);
@@ -1466,13 +1416,15 @@ void sofia_presence_handle_sip_i_subscribe(int status,
}
void sofia_presence_handle_sip_r_subscribe(int status,
char const *phrase,
nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[])
char const *phrase,
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_presence_handle_sip_i_publish(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_presence_handle_sip_i_publish(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
tagi_t tags[])
{
if (sip) {
sip_from_t const *from = sip->sip_from;
@@ -1573,8 +1525,9 @@ void sofia_presence_set_hash_key(char *hash_key, int32_t len, sip_t const *sip)
}
void sofia_presence_handle_sip_i_message(int status,
char const *phrase,
nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[])
char const *phrase,
nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
tagi_t tags[])
{
if (sip) {
sip_from_t const *from = sip->sip_from;
@@ -1692,7 +1645,7 @@ void sofia_presence_set_chat_hash(private_object_t *tech_pvt, sip_t const *sip)
if (sofia_reg_find_reg_url(tech_pvt->profile, sip->sip_from->a_url->url_user, sip->sip_from->a_url->url_host, buf, sizeof(buf))) {
home = su_home_new(sizeof(*home));
switch_assert(home != NULL);
switch_assert(home != NULL);
tech_pvt->chat_from = sip_header_as_string(home, (const sip_header_t *) sip->sip_to);
tech_pvt->chat_to = switch_core_session_strdup(tech_pvt->session, buf);
sofia_presence_set_hash_key(hash_key, sizeof(hash_key), sip);
@@ -1706,6 +1659,7 @@ void sofia_presence_set_chat_hash(private_object_t *tech_pvt, sip_t const *sip)
switch_core_hash_insert(tech_pvt->profile->chat_hash, tech_pvt->hash_key, tech_pvt);
}
/* For Emacs:
* Local Variables:
* mode:c
+162 -208
View File
@@ -38,21 +38,21 @@
static void sofia_reg_kill_reg(sofia_gateway_t *gateway_ptr, int unreg)
{
if (gateway_ptr->nh) {
if (unreg) {
nua_unregister(gateway_ptr->nh,
NUTAG_URL(gateway_ptr->register_url),
SIPTAG_FROM_STR(gateway_ptr->register_from),
SIPTAG_TO_STR(gateway_ptr->register_from),
SIPTAG_CONTACT_STR(gateway_ptr->register_contact),
SIPTAG_EXPIRES_STR(gateway_ptr->expires_str),
NUTAG_REGISTRAR(gateway_ptr->register_proxy),
NUTAG_OUTBOUND("no-options-keepalive"), NUTAG_OUTBOUND("no-validate"), NUTAG_KEEPALIVE(0), TAG_NULL());
}
nua_handle_bind(gateway_ptr->nh, NULL);
nua_handle_destroy(gateway_ptr->nh);
gateway_ptr->nh = NULL;
}
if (gateway_ptr->nh) {
if (unreg) {
nua_unregister(gateway_ptr->nh,
NUTAG_URL(gateway_ptr->register_url),
SIPTAG_FROM_STR(gateway_ptr->register_from),
SIPTAG_TO_STR(gateway_ptr->register_from),
SIPTAG_CONTACT_STR(gateway_ptr->register_contact),
SIPTAG_EXPIRES_STR(gateway_ptr->expires_str),
NUTAG_REGISTRAR(gateway_ptr->register_proxy),
NUTAG_OUTBOUND("no-options-keepalive"), NUTAG_OUTBOUND("no-validate"), NUTAG_KEEPALIVE(0), TAG_NULL());
}
nua_handle_bind(gateway_ptr->nh, NULL);
nua_handle_destroy(gateway_ptr->nh);
gateway_ptr->nh = NULL;
}
}
@@ -64,7 +64,7 @@ void sofia_reg_unregister(sofia_profile_t *profile)
free(gateway_ptr->sofia_private);
gateway_ptr->sofia_private = NULL;
}
sofia_reg_kill_reg(gateway_ptr, 1);
sofia_reg_kill_reg(gateway_ptr, 1);
}
}
@@ -94,7 +94,7 @@ void sofia_reg_check_gateway(sofia_profile_t *profile, time_t now)
gateway_ptr->pinging = 1;
nua_options(nh, TAG_END());
}
switch (ostate) {
case REG_STATE_NOREG:
gateway_ptr->status = SOFIA_GATEWAY_UP;
@@ -107,12 +107,12 @@ void sofia_reg_check_gateway(sofia_profile_t *profile, time_t now)
break;
case REG_STATE_UNREGISTER:
sofia_reg_kill_reg(gateway_ptr, 1);
sofia_reg_kill_reg(gateway_ptr, 1);
gateway_ptr->state = REG_STATE_NOREG;
break;
case REG_STATE_UNREGED:
gateway_ptr->status = SOFIA_GATEWAY_DOWN;
sofia_reg_kill_reg(gateway_ptr, 1);
sofia_reg_kill_reg(gateway_ptr, 1);
if ((gateway_ptr->nh = nua_handle(gateway_ptr->profile->nua, NULL,
NUTAG_URL(gateway_ptr->register_proxy),
@@ -120,10 +120,10 @@ void sofia_reg_check_gateway(sofia_profile_t *profile, time_t now)
NUTAG_CALLSTATE_REF(ss_state), SIPTAG_FROM_STR(gateway_ptr->register_from), TAG_END()))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "registering %s\n", gateway_ptr->name);
if (!gateway_ptr->sofia_private) {
gateway_ptr->sofia_private = malloc(sizeof(*gateway_ptr->sofia_private));
switch_assert(gateway_ptr->sofia_private);
}
if (!gateway_ptr->sofia_private) {
gateway_ptr->sofia_private = malloc(sizeof(*gateway_ptr->sofia_private));
switch_assert(gateway_ptr->sofia_private);
}
memset(gateway_ptr->sofia_private, 0, sizeof(*gateway_ptr->sofia_private));
gateway_ptr->sofia_private->gateway = gateway_ptr;
@@ -159,7 +159,7 @@ void sofia_reg_check_gateway(sofia_profile_t *profile, time_t now)
break;
case REG_STATE_FAILED:
sofia_reg_kill_reg(gateway_ptr, 0);
sofia_reg_kill_reg(gateway_ptr, 0);
gateway_ptr->status = SOFIA_GATEWAY_DOWN;
case REG_STATE_TRYING:
if (gateway_ptr->retry && now >= gateway_ptr->retry) {
@@ -201,7 +201,7 @@ int sofia_reg_nat_callback(void *pArg, int argc, char **argv, char **columnNames
nua_options(nh, TAG_END());
switch_safe_free(contact);
return 0;
}
@@ -242,15 +242,10 @@ void sofia_reg_expire_call_id(sofia_profile_t *profile, const char *call_id)
{
char sql[1024];
char *psql = sql;
switch_snprintf(sql, sizeof(sql), "select *,'%s' from sip_registrations where call_id='%s'", profile->name, call_id);
switch_mutex_lock(profile->ireg_mutex);
sofia_glue_execute_sql_callback(profile,
SWITCH_TRUE,
NULL,
sql,
sofia_reg_del_callback,
NULL);
sofia_glue_execute_sql_callback(profile, SWITCH_TRUE, NULL, sql, sofia_reg_del_callback, NULL);
switch_mutex_unlock(profile->ireg_mutex);
switch_snprintf(sql, sizeof(sql), "delete from sip_registrations where call_id='%s'", call_id);
@@ -262,19 +257,19 @@ void sofia_reg_check_expire(sofia_profile_t *profile, time_t now)
char sql[1024];
#ifdef SWITCH_HAVE_ODBC
if (profile->odbc_dsn) {
if (!profile->master_odbc) {
if (profile->odbc_dsn) {
if (!profile->master_odbc) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
return;
}
} else {
}
} else {
#endif
if (!profile->master_db) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
return;
}
#ifdef SWITCH_HAVE_ODBC
}
}
#endif
@@ -286,12 +281,7 @@ void sofia_reg_check_expire(sofia_profile_t *profile, time_t now)
switch_snprintf(sql, sizeof(sql), "select *,'%s' from sip_registrations where expires > 0", profile->name);
}
sofia_glue_execute_sql_callback(profile,
SWITCH_TRUE,
NULL,
sql,
sofia_reg_del_callback,
NULL);
sofia_glue_execute_sql_callback(profile, SWITCH_TRUE, NULL, sql, sofia_reg_del_callback, NULL);
if (now) {
switch_snprintf(sql, sizeof(sql), "delete from sip_registrations where expires > 0 and expires <= %ld", (long) now);
} else {
@@ -299,7 +289,7 @@ void sofia_reg_check_expire(sofia_profile_t *profile, time_t now)
}
sofia_glue_actually_execute_sql(profile, SWITCH_FALSE, sql, NULL);
if (now) {
switch_snprintf(sql, sizeof(sql), "delete from sip_authentication where expires > 0 and expires <= %ld", (long) now);
} else {
@@ -307,7 +297,7 @@ void sofia_reg_check_expire(sofia_profile_t *profile, time_t now)
}
sofia_glue_actually_execute_sql(profile, SWITCH_FALSE, sql, NULL);
if (now) {
@@ -316,12 +306,7 @@ void sofia_reg_check_expire(sofia_profile_t *profile, time_t now)
switch_snprintf(sql, sizeof(sql), "select call_id from sip_subscriptions where expires > 0");
}
sofia_glue_execute_sql_callback(profile,
SWITCH_TRUE,
NULL,
sql,
sofia_sub_del_callback,
profile);
sofia_glue_execute_sql_callback(profile, SWITCH_TRUE, NULL, sql, sofia_sub_del_callback, profile);
if (now) {
switch_snprintf(sql, sizeof(sql), "delete from sip_subscriptions where expires > 0 and expires <= %ld", (long) now);
@@ -330,16 +315,11 @@ void sofia_reg_check_expire(sofia_profile_t *profile, time_t now)
}
sofia_glue_actually_execute_sql(profile, SWITCH_FALSE, sql, NULL);
if (now) {
switch_snprintf(sql, sizeof(sql), "select * from sip_registrations where status like '%%AUTO-NAT%%'");
sofia_glue_execute_sql_callback(profile,
SWITCH_TRUE,
NULL,
sql,
sofia_reg_nat_callback,
profile);
sofia_glue_execute_sql_callback(profile, SWITCH_TRUE, NULL, sql, sofia_reg_nat_callback, profile);
}
switch_mutex_unlock(profile->ireg_mutex);
@@ -365,12 +345,7 @@ char *sofia_reg_find_reg_url(sofia_profile_t *profile, const char *user, const c
}
sofia_glue_execute_sql_callback(profile,
SWITCH_FALSE,
profile->ireg_mutex,
val,
sofia_reg_find_callback,
&cbt);
sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex, val, sofia_reg_find_callback, &cbt);
if (cbt.matches) {
@@ -390,30 +365,24 @@ void sofia_reg_auth_challange(nua_t *nua, sofia_profile_t *profile, nua_handle_t
switch_uuid_get(&uuid);
switch_uuid_format(uuid_str, &uuid);
sql = switch_mprintf("insert into sip_authentication (nonce, expires) values('%q', %ld)",
uuid_str, switch_timestamp(NULL) + profile->nonce_ttl);
sql = switch_mprintf("insert into sip_authentication (nonce, expires) values('%q', %ld)", uuid_str, switch_timestamp(NULL) + profile->nonce_ttl);
switch_assert(sql != NULL);
sofia_glue_actually_execute_sql(profile, SWITCH_FALSE, sql, profile->ireg_mutex);
switch_safe_free(sql);
//sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
auth_str =
switch_mprintf("Digest realm=\"%q\", nonce=\"%q\",%s algorithm=MD5, qop=\"auth\"", realm, uuid_str, stale ? " stale=\"true\"," : "");
auth_str = switch_mprintf("Digest realm=\"%q\", nonce=\"%q\",%s algorithm=MD5, qop=\"auth\"", realm, uuid_str, stale ? " stale=\"true\"," : "");
if (regtype == REG_REGISTER) {
nua_respond(nh,
SIP_401_UNAUTHORIZED,
TAG_IF(nua, NUTAG_WITH_THIS(nua)), SIPTAG_WWW_AUTHENTICATE_STR(auth_str), TAG_END());
nua_respond(nh, SIP_401_UNAUTHORIZED, TAG_IF(nua, NUTAG_WITH_THIS(nua)), SIPTAG_WWW_AUTHENTICATE_STR(auth_str), TAG_END());
} else if (regtype == REG_INVITE) {
nua_respond(nh,
SIP_407_PROXY_AUTH_REQUIRED,
TAG_IF(nua, NUTAG_WITH_THIS(nua)), SIPTAG_PROXY_AUTHENTICATE_STR(auth_str), TAG_END());
nua_respond(nh, SIP_407_PROXY_AUTH_REQUIRED, TAG_IF(nua, NUTAG_WITH_THIS(nua)), SIPTAG_PROXY_AUTHENTICATE_STR(auth_str), TAG_END());
}
switch_safe_free(auth_str);
}
uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_handle_t * nh, sip_t const *sip, sofia_regtype_t regtype, char *key,
uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sip_t const *sip, sofia_regtype_t regtype, char *key,
uint32_t keylen, switch_event_t **v_event, const char *is_nat)
{
sip_to_t const *to = NULL;
@@ -446,7 +415,7 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
get_addr(network_ip, sizeof(network_ip), &((struct sockaddr_in *) msg_addrinfo(nua_current_request(nua))->ai_addr)->sin_addr);
network_port = ntohs(((struct sockaddr_in *) msg_addrinfo(nua_current_request(nua))->ai_addr)->sin_port);
expires = sip->sip_expires;
authorization = sip->sip_authorization;
contact = sip->sip_contact;
@@ -468,14 +437,14 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
char new_port[25] = "";
const char *contact_host = contact->m_url->url_host;
display = contact->m_display;
if (is_nat) {
reg_desc = "Registered(AUTO-NAT)";
contact_host = network_ip;
switch_snprintf(new_port, sizeof(new_port), ":%d", network_port);
port = NULL;
}
if (switch_strlen_zero(display)) {
if (to) {
display = to->a_display;
@@ -495,13 +464,10 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
if (contact->m_url->url_params) {
switch_snprintf(contact_str, sizeof(contact_str), "%s <sip:%s@%s%s;%s>%s%s",
display, contact->m_url->url_user, contact_host, new_port, contact->m_url->url_params,
received_data,
is_nat ? ";nat" : "");
display, contact->m_url->url_user, contact_host, new_port, contact->m_url->url_params, received_data, is_nat ? ";nat" : "");
} else {
switch_snprintf(contact_str, sizeof(contact_str), "%s <sip:%s@%s%s>%s%s", display, contact->m_url->url_user, contact_host, new_port,
received_data,
is_nat ? ";nat" : "");
switch_snprintf(contact_str, sizeof(contact_str), "%s <sip:%s@%s%s>%s%s", display, contact->m_url->url_user, contact_host, new_port,
received_data, is_nat ? ";nat" : "");
}
}
@@ -524,37 +490,38 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
if (authorization) {
char *v_contact_str;
if ((auth_res = sofia_reg_parse_auth(profile, authorization, sip, sip->sip_request->rq_method_name,
if ((auth_res = sofia_reg_parse_auth(profile, authorization, sip, sip->sip_request->rq_method_name,
key, keylen, network_ip, v_event, exptime, regtype, to_user)) == AUTH_STALE) {
stale = 1;
}
if (exptime && v_event && *v_event) {
char *exp_var;
register_gateway = switch_event_get_header(*v_event, "sip-register-gateway");
/* Allow us to force the SIP user to be something specific - needed if
* we - for example - want to be able to ensure that the username a UA can
* be contacted at is the same one that they used for authentication.
*/
*/
if ((force_user = switch_event_get_header(*v_event, "sip-force-user"))) {
to_user = force_user;
}
if ((v_contact_str = switch_event_get_header(*v_event, "sip-force-contact"))) {
if (*received_data && (profile->pflags & PFLAG_RECIEVED_IN_NAT_REG_CONTACT)) {
switch_snprintf(received_data, sizeof(received_data), ";received=\"%s:%d\"", network_ip, network_port);
}
if (!strcasecmp(v_contact_str, "nat-connectile-dysfunction") ||
if (!strcasecmp(v_contact_str, "nat-connectile-dysfunction") ||
!strcasecmp(v_contact_str, "NDLB-connectile-dysfunction") || !strcasecmp(v_contact_str, "NDLB-tls-connectile-dysfunction")) {
if (contact->m_url->url_params) {
switch_snprintf(contact_str, sizeof(contact_str), "%s <sip:%s@%s:%d;%s>%s;nat",
display, contact->m_url->url_user, network_ip, network_port, contact->m_url->url_params, received_data);
} else {
switch_snprintf(contact_str, sizeof(contact_str), "%s <sip:%s@%s:%d>%s;nat", display, contact->m_url->url_user, network_ip, network_port, received_data);
switch_snprintf(contact_str, sizeof(contact_str), "%s <sip:%s@%s:%d>%s;nat", display, contact->m_url->url_user, network_ip,
network_port, received_data);
}
if (strstr(v_contact_str, "tls")) {
reg_desc = "Registered(TLSHACK)";
@@ -566,14 +533,14 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
} else {
char *p;
switch_copy_string(contact_str, v_contact_str, sizeof(contact_str));
for(p = contact_str; p && *p; p++) {
for (p = contact_str; p && *p; p++) {
if (*p == '\'' || *p == '[' || *p == ']') {
*p = '"';
}
}
}
}
if ((exp_var = switch_event_get_header(*v_event, "sip-force-expires"))) {
int tmp = atoi(exp_var);
if (tmp > 0) {
@@ -585,13 +552,9 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
if (auth_res != AUTH_OK && !stale) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "send %s for [%s@%s]\n", forbidden ? "forbidden" : "challange", to_user, to_host);
if (auth_res == AUTH_FORBIDDEN) {
nua_respond(nh,
SIP_403_FORBIDDEN,
NUTAG_WITH_THIS(nua), TAG_END());
nua_respond(nh, SIP_403_FORBIDDEN, NUTAG_WITH_THIS(nua), TAG_END());
} else {
nua_respond(nh,
SIP_401_UNAUTHORIZED,
NUTAG_WITH_THIS(nua), TAG_END());
nua_respond(nh, SIP_401_UNAUTHORIZED, NUTAG_WITH_THIS(nua), TAG_END());
}
return 1;
}
@@ -604,13 +567,13 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
}
return 1;
}
reg:
reg:
if (regtype != REG_REGISTER) {
return 0;
}
call_id = sip->sip_call_id->i_id; //sip_header_as_string(profile->home, (void *) sip->sip_call_id);
call_id = sip->sip_call_id->i_id; //sip_header_as_string(profile->home, (void *) sip->sip_call_id);
switch_assert(call_id);
if (exptime) {
@@ -627,10 +590,9 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
}
switch_mutex_lock(profile->ireg_mutex);
sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
sql = switch_mprintf("insert into sip_registrations values ('%q', '%q','%q','%q','%q', '%q', %ld, '%q')", call_id,
to_user, to_host, contact_str, reg_desc,
rpid, (long) switch_timestamp(NULL) + (long) exptime * 2, agent);
to_user, to_host, contact_str, reg_desc, rpid, (long) switch_timestamp(NULL) + (long) exptime * 2, agent);
if (sql) {
sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
}
@@ -647,7 +609,7 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
switch_event_fire(&s_event);
}
if (profile->debug) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
@@ -676,7 +638,7 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
if ((sql = switch_mprintf("delete from sip_subscriptions where call_id='%q'", call_id))) {
sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
}
if ((sql = switch_mprintf("delete from sip_registrations where call_id='%q'", call_id))) {
sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
}
@@ -685,7 +647,7 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
if ((sql = switch_mprintf("delete from sip_subscriptions where sip_user='%q' and sip_host='%q'", to_user, to_host))) {
sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
}
if ((sql = switch_mprintf("delete from sip_registrations where sip_user='%q' and sip_host='%q'", to_user, to_host))) {
sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
}
@@ -709,22 +671,22 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
switch_event_fire(&event);
}
/*
if (call_id) {
su_free(profile->home, call_id);
}
*/
if (call_id) {
su_free(profile->home, call_id);
}
*/
if (regtype == REG_REGISTER) {
char *new_contact = NULL;
char new_port[30] = "";
char exp_param[128] = "";
if (exptime) {
switch_snprintf(exp_param, sizeof(exp_param), ";expires=%ld", exptime);
}
if (contact->m_url->url_port) {
switch_snprintf(new_port, sizeof(new_port), ":%s", contact->m_url->url_port);
@@ -732,17 +694,12 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
if (contact->m_url->url_params) {
new_contact = switch_mprintf("%s <sip:%s@%s%s;%s>%s",
display, contact->m_url->url_user, contact->m_url->url_host, new_port, contact->m_url->url_params,
exp_param);
display, contact->m_url->url_user, contact->m_url->url_host, new_port, contact->m_url->url_params, exp_param);
} else {
new_contact = switch_mprintf("%s <sip:%s@%s%s>%s",
display, contact->m_url->url_user, contact->m_url->url_host, new_port,
exp_param);
new_contact = switch_mprintf("%s <sip:%s@%s%s>%s", display, contact->m_url->url_user, contact->m_url->url_host, new_port, exp_param);
}
nua_respond(nh,
SIP_200_OK,
SIPTAG_CONTACT_STR(new_contact), NUTAG_WITH_THIS(nua), TAG_END());
nua_respond(nh, SIP_200_OK, SIPTAG_CONTACT_STR(new_contact), NUTAG_WITH_THIS(nua), TAG_END());
switch_safe_free(new_contact);
if (exptime) {
@@ -763,7 +720,7 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
}
}
}
return 1;
}
@@ -773,7 +730,8 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
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 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[])
{
char key[128] = "";
switch_event_t *v_event = NULL;
@@ -785,7 +743,7 @@ void sofia_reg_handle_sip_i_register(nua_t * nua, sofia_profile_t *profile, nua_
get_addr(network_ip, sizeof(network_ip), &((struct sockaddr_in *) my_addrinfo->ai_addr)->sin_addr);
network_port = ntohs(((struct sockaddr_in *) msg_addrinfo(nua_current_request(nua))->ai_addr)->sin_port);
if (!(sip->sip_contact && sip->sip_contact->m_url)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "NO CONTACT!\n");
@@ -794,9 +752,7 @@ void sofia_reg_handle_sip_i_register(nua_t * nua, sofia_profile_t *profile, nua_
}
if (!(profile->mflags & MFLAG_REGISTER)) {
nua_respond(nh,
SIP_403_FORBIDDEN,
NUTAG_WITH_THIS(nua), TAG_END());
nua_respond(nh, SIP_403_FORBIDDEN, NUTAG_WITH_THIS(nua), TAG_END());
goto end;
}
@@ -804,7 +760,7 @@ void sofia_reg_handle_sip_i_register(nua_t * nua, sofia_profile_t *profile, nua_
if (sip && sip->sip_via) {
const char *port = sip->sip_via->v_port;
const char *host = sip->sip_via->v_host;
if (host && sip->sip_via->v_received) {
is_nat = "via received";
} else if (host && strcmp(network_ip, host)) {
@@ -826,13 +782,13 @@ void sofia_reg_handle_sip_i_register(nua_t * nua, sofia_profile_t *profile, nua_
}
if (!switch_strlen_zero(contact_host)) {
for (x = 0 ; x < profile->nat_acl_count; x++) {
for (x = 0; x < profile->nat_acl_count; x++) {
last_acl = profile->nat_acl[x];
if (!(ok = switch_check_network_list_ip(contact_host, last_acl))) {
break;
}
}
if (ok) {
is_nat = last_acl;
}
@@ -844,29 +800,25 @@ void sofia_reg_handle_sip_i_register(nua_t * nua, sofia_profile_t *profile, nua_
int ok = 1;
char *last_acl = NULL;
for (x = 0 ; x < profile->reg_acl_count; x++) {
for (x = 0; x < profile->reg_acl_count; x++) {
last_acl = profile->reg_acl[x];
if (!(ok = switch_check_network_list_ip(network_ip, last_acl))) {
break;
}
}
if (ok && !(profile->pflags & PFLAG_BLIND_REG)) {
type = REG_AUTO_REGISTER;
} else if (!ok) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "IP %s Rejected by acl %s\n", network_ip, profile->reg_acl[x]);
nua_respond(nh,
SIP_403_FORBIDDEN,
NUTAG_WITH_THIS(nua), TAG_END());
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "IP %s Rejected by acl %s\n", network_ip, profile->reg_acl[x]);
nua_respond(nh, SIP_403_FORBIDDEN, NUTAG_WITH_THIS(nua), TAG_END());
goto end;
}
}
if (!sip || !sip->sip_request || !sip->sip_request->rq_method_name) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Received an invalid packet!\n");
nua_respond(nh,
SIP_500_INTERNAL_SERVER_ERROR,
TAG_END());
nua_respond(nh, SIP_500_INTERNAL_SERVER_ERROR, TAG_END());
goto end;
}
@@ -876,7 +828,7 @@ void sofia_reg_handle_sip_i_register(nua_t * nua, sofia_profile_t *profile, nua_
switch_event_fire(&v_event);
}
end:
end:
nua_handle_destroy(nh);
@@ -885,7 +837,8 @@ void sofia_reg_handle_sip_i_register(nua_t * nua, sofia_profile_t *profile, nua_
void sofia_reg_handle_sip_r_register(int status,
char const *phrase,
nua_t * nua, sofia_profile_t *profile, nua_handle_t * nh, sofia_private_t * sofia_private, sip_t const *sip, tagi_t tags[])
nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
tagi_t tags[])
{
if (sofia_private && sofia_private->gateway) {
switch (status) {
@@ -915,7 +868,7 @@ void sofia_reg_handle_sip_r_register(int status,
void sofia_reg_handle_sip_r_challenge(int status,
char const *phrase,
nua_t * nua, sofia_profile_t *profile, nua_handle_t * nh,
nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh,
switch_core_session_t *session, sofia_gateway_t *gateway, sip_t const *sip, tagi_t tags[])
{
sip_www_authenticate_t const *authenticate = NULL;
@@ -976,17 +929,17 @@ void sofia_reg_handle_sip_r_challenge(int status,
return;
cancel:
cancel:
if (session) {
switch_channel_hangup(switch_core_session_get_channel(session), SWITCH_CAUSE_MANDATORY_IE_MISSING);
} else {
nua_cancel(nh, TAG_END());
}
}
auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t const *authorization, sip_t const *sip, const char *regstr,
auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t const *authorization, sip_t const *sip, const char *regstr,
char *np, size_t nplen, char *ip, switch_event_t **v_event, long exptime, sofia_regtype_t regtype, const char *to_user)
{
int indexnum;
@@ -1001,13 +954,13 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co
const char *a1_hash = NULL;
char *sql;
char *mailbox = NULL;
switch_xml_t domain, xml = NULL, user, param, uparams, dparams;
switch_xml_t domain, xml = NULL, user, param, uparams, dparams;
char hexdigest[2 * SU_MD5_DIGEST_SIZE + 1] = "";
char *domain_name = NULL;
switch_event_t *params = NULL;
username = realm = nonce = uri = qop = cnonce = nc = response = NULL;
if (authorization->au_params) {
for (indexnum = 0; (cur = authorization->au_params[indexnum]); indexnum++) {
char *var, *val, *p, *work;
@@ -1052,7 +1005,7 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co
ret = AUTH_STALE;
goto end;
}
/* Optional check that auth name == SIP username */
if ((regtype == REG_REGISTER) && (profile->pflags & PFLAG_CHECKUSER)) {
if (switch_strlen_zero(username) || switch_strlen_zero(to_user) || strcasecmp(to_user, username)) {
@@ -1072,44 +1025,45 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co
goto end;
}
free(sql);
}
}
switch_event_create(&params, SWITCH_EVENT_MESSAGE);
switch_assert(params);
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "action", "sip_auth");
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_profile", profile->name);
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_user_agent", (sip && sip->sip_user_agent) ? sip->sip_user_agent->g_string : "unknown");
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_user_agent",
(sip && sip->sip_user_agent) ? sip->sip_user_agent->g_string : "unknown");
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_auth_username", username);
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_auth_realm", realm);
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_auth_nonce", nonce);
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_auth_uri", uri);
if (qop) {
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_auth_qop", qop);
}
if (cnonce) {
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_auth_cnonce", cnonce);
}
if (nc) {
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_auth_nc", nc);
}
if (qop) {
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_auth_qop", qop);
}
if (cnonce) {
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_auth_cnonce", cnonce);
}
if (nc) {
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_auth_nc", nc);
}
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_auth_response", response);
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_auth_method", (sip && sip->sip_request) ? sip->sip_request->rq_method_name : NULL);
if (!switch_strlen_zero(profile->reg_domain)) {
domain_name = profile->reg_domain;
} else {
domain_name = realm;
}
if (switch_xml_locate_user("id", username, domain_name, ip, &xml, &domain, &user, params) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "can't find user [%s@%s]\n", username, domain_name);
ret = AUTH_FORBIDDEN;
goto end;
}
if (!(mailbox = (char *)switch_xml_attr(user, "mailbox"))) {
if (!(mailbox = (char *) switch_xml_attr(user, "mailbox"))) {
mailbox = username;
}
@@ -1125,11 +1079,11 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co
for (param = switch_xml_child(dparams, "param"); param; param = param->next) {
const char *var = switch_xml_attr_soft(param, "name");
const char *val = switch_xml_attr_soft(param, "value");
if (!strcasecmp(var, "password")) {
passwd = val;
}
if (!strcasecmp(var, "a1-hash")) {
a1_hash = val;
}
@@ -1140,11 +1094,11 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co
for (param = switch_xml_child(uparams, "param"); param; param = param->next) {
const char *var = switch_xml_attr_soft(param, "name");
const char *val = switch_xml_attr_soft(param, "value");
if (!strcasecmp(var, "password")) {
passwd = val;
}
if (!strcasecmp(var, "a1-hash")) {
a1_hash = val;
}
@@ -1164,10 +1118,10 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co
su_md5_deinit(&ctx);
switch_safe_free(input);
a1_hash = hexdigest;
}
for_the_sake_of_interop:
for_the_sake_of_interop:
if ((input = switch_mprintf("%s:%q", regstr, uri))) {
su_md5_init(&ctx);
@@ -1176,38 +1130,38 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co
su_md5_deinit(&ctx);
}
if (nc && cnonce && qop) {
input2 = switch_mprintf("%q:%q:%q:%q:%q:%q", a1_hash, nonce, nc, cnonce, qop, uridigest);
} else {
input2 = switch_mprintf("%q:%q:%q", a1_hash, nonce, uridigest);
}
if (nc && cnonce && qop) {
input2 = switch_mprintf("%q:%q:%q:%q:%q:%q", a1_hash, nonce, nc, cnonce, qop, uridigest);
} else {
input2 = switch_mprintf("%q:%q:%q", a1_hash, nonce, uridigest);
}
switch_assert(input2);
switch_assert(input2);
memset(&ctx, 0, sizeof(ctx));
su_md5_init(&ctx);
su_md5_strupdate(&ctx, input2);
su_md5_hexdigest(&ctx, bigdigest);
su_md5_deinit(&ctx);
memset(&ctx, 0, sizeof(ctx));
su_md5_init(&ctx);
su_md5_strupdate(&ctx, input2);
su_md5_hexdigest(&ctx, bigdigest);
su_md5_deinit(&ctx);
if (!strcasecmp(bigdigest, response)) {
ret = AUTH_OK;
} else {
if ((profile->ndlb & PFLAG_NDLB_BROKEN_AUTH_HASH) && strcasecmp(regstr, "REGISTER") && strcasecmp(regstr, "INVITE")) {
/* some clients send an ACK with the method 'INVITE' in the hash which will break auth so we will
try again with INVITE so we don't get people complaining to us when someone else's client has a bug......
*/
switch_safe_free(input);
switch_safe_free(input2);
regstr = "INVITE";
goto for_the_sake_of_interop;
}
if (!strcasecmp(bigdigest, response)) {
ret = AUTH_OK;
} else {
if ((profile->ndlb & PFLAG_NDLB_BROKEN_AUTH_HASH) && strcasecmp(regstr, "REGISTER") && strcasecmp(regstr, "INVITE")) {
/* some clients send an ACK with the method 'INVITE' in the hash which will break auth so we will
try again with INVITE so we don't get people complaining to us when someone else's client has a bug......
*/
switch_safe_free(input);
switch_safe_free(input2);
regstr = "INVITE";
goto for_the_sake_of_interop;
}
ret = AUTH_FORBIDDEN;
}
ret = AUTH_FORBIDDEN;
}
skip_auth:
skip_auth:
if (first && ret == AUTH_OK) {
if (v_event) {
@@ -1223,7 +1177,7 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co
switch_event_add_header(*v_event, SWITCH_STACK_BOTTOM, "mailbox", "%s", mailbox);
switch_event_add_header(*v_event, SWITCH_STACK_BOTTOM, "user_name", "%s", username);
switch_event_add_header(*v_event, SWITCH_STACK_BOTTOM, "domain_name", "%s", realm);
if ((dparams = switch_xml_child(domain, "variables"))) {
xparams[i++] = dparams;
}
@@ -1243,7 +1197,7 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co
if (!switch_strlen_zero(var) && !switch_strlen_zero(val)) {
switch_event_add_header(*v_event, SWITCH_STACK_BOTTOM, var, "%s", val);
if (!strcasecmp(var, "register-gateway")) {
if (!strcasecmp(val, "all")) {
switch_xml_t gateways_tag, gateway_tag;
@@ -1253,7 +1207,7 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co
if (switch_strlen_zero(name)) {
name = "anonymous";
}
if ((gateway_ptr = sofia_reg_find_gateway(name))) {
gateway_ptr->retry = 0;
if (exptime) {
@@ -1263,7 +1217,7 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co
}
sofia_reg_release_gateway(gateway_ptr);
}
}
}
} else {
@@ -1272,11 +1226,11 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co
mydata = strdup(val);
switch_assert(mydata != NULL);
argc = switch_separate_string(mydata, ',', argv, (sizeof(argv) / sizeof(argv[0])));
for (x = 0; x < argc; x++) {
if ((gateway_ptr = sofia_reg_find_gateway((char *)argv[x]))) {
if ((gateway_ptr = sofia_reg_find_gateway((char *) argv[x]))) {
gateway_ptr->retry = 0;
if (exptime) {
gateway_ptr->state = REG_STATE_UNREGED;
@@ -1298,7 +1252,7 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co
}
}
}
end:
end:
switch_event_destroy(&params);
@@ -1329,7 +1283,7 @@ sofia_gateway_t *sofia_reg_find_gateway__(const char *file, const char *func, in
switch_mutex_lock(mod_sofia_globals.hash_mutex);
if ((gateway = (sofia_gateway_t *) switch_core_hash_find(mod_sofia_globals.gateway_hash, key))) {
if (!(gateway->profile->pflags & PFLAG_RUNNING)) {
gateway = NULL;
gateway = NULL;
goto done;
}
if (switch_thread_rwlock_tryrdlock(gateway->profile->rwlock) != SWITCH_STATUS_SUCCESS) {
@@ -1343,7 +1297,7 @@ sofia_gateway_t *sofia_reg_find_gateway__(const char *file, const char *func, in
#endif
}
done:
done:
switch_mutex_unlock(mod_sofia_globals.hash_mutex);
return gateway;
}
+254 -257
View File
@@ -39,16 +39,16 @@
#define RANGE_CHANNEL 0x1
char read_enable=0;
char write_enable=0;
char primary_enable=0;
int tx_cnt=1;
int rx_cnt=0;
int tx_size=10;
int tx_delay=0;
int tx_data=-1;
int tx_ss7_type=0;
int rx_ss7_timer=0;
char read_enable = 0;
char write_enable = 0;
char primary_enable = 0;
int tx_cnt = 1;
int rx_cnt = 0;
int tx_size = 10;
int tx_delay = 0;
int tx_data = -1;
int tx_ss7_type = 0;
int rx_ss7_timer = 0;
unsigned char card_name[WAN_IFNAME_SZ];
unsigned char if_name[WAN_IFNAME_SZ];
@@ -63,343 +63,343 @@ unsigned char daddr[TX_ADDR_STR_SZ];
unsigned char saddr[TX_ADDR_STR_SZ];
unsigned char udata[TX_ADDR_STR_SZ];
int files_used=0;
int verbose=0;
int files_used = 0;
int verbose = 0;
int tx_connections;
int tx_connections;
int ds_prot=0;
int ds_prot_opt=0;
int ds_max_mult_cnt=0;
unsigned int ds_active_ch=0;
int ds_7bit_hdlc=0;
int direction=-1;
int ds_prot = 0;
int ds_prot_opt = 0;
int ds_max_mult_cnt = 0;
unsigned int ds_active_ch = 0;
int ds_7bit_hdlc = 0;
int direction = -1;
int tx_channels=1;
int cause=0;
int diagn=0;
int tx_channels = 1;
int cause = 0;
int diagn = 0;
int card_cnt=0;
int i_cnt=0;
int card_cnt = 0;
int i_cnt = 0;
unsigned long parse_active_channel(char* val);
unsigned long parse_active_channel(char *val);
int init_args(int argc, char *argv[])
{
int i;
int c_cnt=0;
int c_cnt = 0;
sprintf(daddr,"111");
sprintf(saddr,"222");
sprintf(udata,"C9");
for (i = 0; i < argc; i++){
if (!strcmp(argv[i],"-i")){
sprintf(daddr, "111");
sprintf(saddr, "222");
sprintf(udata, "C9");
if (i+1 > argc-1){
for (i = 0; i < argc; i++) {
if (!strcmp(argv[i], "-i")) {
if (i + 1 > argc - 1) {
printf("ERROR: Invalid Interface Name!\n");
return WAN_FALSE;
}
strncpy(if_name, argv[i+1],WAN_IFNAME_SZ);
i_cnt=1;
}else if (!strcmp(argv[i],"-si")){
if (i+1 > argc-1){
strncpy(if_name, argv[i + 1], WAN_IFNAME_SZ);
i_cnt = 1;
} else if (!strcmp(argv[i], "-si")) {
if (i + 1 > argc - 1) {
printf("ERROR: Invalid Switch Interface Name!\n");
return WAN_FALSE;
}
strncpy(sw_if_name, argv[i+1], WAN_IFNAME_SZ);
}else if (!strcmp(argv[i],"-c")){
if (i+1 > argc-1){
strncpy(sw_if_name, argv[i + 1], WAN_IFNAME_SZ);
} else if (!strcmp(argv[i], "-c")) {
if (i + 1 > argc - 1) {
printf("ERROR: Invalid Card Name!\n");
return WAN_FALSE;
}
strncpy(card_name, argv[i+1], WAN_IFNAME_SZ);
card_cnt=1;
}else if (!strcmp(argv[i],"-sc")){
if (i+1 > argc-1){
strncpy(card_name, argv[i + 1], WAN_IFNAME_SZ);
card_cnt = 1;
} else if (!strcmp(argv[i], "-sc")) {
if (i + 1 > argc - 1) {
printf("ERROR: Invalid Switch Card Name!\n");
return WAN_FALSE;
}
strncpy(sw_card_name, argv[i+1], WAN_IFNAME_SZ);
}else if (!strcmp(argv[i],"-r")){
read_enable=1;
c_cnt=1;
}else if (!strcmp(argv[i],"-w")){
write_enable=1;
c_cnt=1;
strncpy(sw_card_name, argv[i + 1], WAN_IFNAME_SZ);
}else if (!strcmp(argv[i],"-pri")){
primary_enable=1;
}else if (!strcmp(argv[i],"-txcnt")){
if (i+1 > argc-1){
printf("ERROR: Invalid tx cnt!\n");
return WAN_FALSE;
}
} else if (!strcmp(argv[i], "-r")) {
read_enable = 1;
c_cnt = 1;
if(isdigit(argv[i+1][0])){
tx_cnt = atoi(argv[i+1]);
}else{
} else if (!strcmp(argv[i], "-w")) {
write_enable = 1;
c_cnt = 1;
} else if (!strcmp(argv[i], "-pri")) {
primary_enable = 1;
} else if (!strcmp(argv[i], "-txcnt")) {
if (i + 1 > argc - 1) {
printf("ERROR: Invalid tx cnt!\n");
return WAN_FALSE;
}
}else if (!strcmp(argv[i],"-rxcnt")){
if (i+1 > argc-1){
printf("ERROR: Invalid rx cnt!\n");
if (isdigit(argv[i + 1][0])) {
tx_cnt = atoi(argv[i + 1]);
} else {
printf("ERROR: Invalid tx cnt!\n");
return WAN_FALSE;
}
}
if(isdigit(argv[i+1][0])){
rx_cnt = atoi(argv[i+1]);
}else{
} else if (!strcmp(argv[i], "-rxcnt")) {
if (i + 1 > argc - 1) {
printf("ERROR: Invalid rx cnt!\n");
return WAN_FALSE;
}
}else if (!strcmp(argv[i],"-txsize")){
if (i+1 > argc-1){
if (isdigit(argv[i + 1][0])) {
rx_cnt = atoi(argv[i + 1]);
} else {
printf("ERROR: Invalid rx cnt!\n");
return WAN_FALSE;
}
} else if (!strcmp(argv[i], "-txsize")) {
if (i + 1 > argc - 1) {
printf("ERROR: Invalid tx size!\n");
return WAN_FALSE;
}
}
if(isdigit(argv[i+1][0])){
tx_size = atoi(argv[i+1]);
}else{
if (isdigit(argv[i + 1][0])) {
tx_size = atoi(argv[i + 1]);
} else {
printf("ERROR: Invalid tx size, must be a digit!\n");
return WAN_FALSE;
}
}else if (!strcmp(argv[i],"-txdelay")){
if (i+1 > argc-1){
} else if (!strcmp(argv[i], "-txdelay")) {
if (i + 1 > argc - 1) {
printf("ERROR: Invalid tx delay!\n");
return WAN_FALSE;
}
}
if(isdigit(argv[i+1][0])){
tx_delay = atoi(argv[i+1]);
}else{
if (isdigit(argv[i + 1][0])) {
tx_delay = atoi(argv[i + 1]);
} else {
printf("ERROR: Invalid tx delay, must be a digit!\n");
return WAN_FALSE;
}
}else if (!strcmp(argv[i],"-txdata")){
if (i+1 > argc-1){
} else if (!strcmp(argv[i], "-txdata")) {
if (i + 1 > argc - 1) {
printf("ERROR: Invalid tx data!\n");
return WAN_FALSE;
}
}
if(isdigit(argv[i+1][0])){
tx_data = atoi(argv[i+1]);
}else{
if (isdigit(argv[i + 1][0])) {
tx_data = atoi(argv[i + 1]);
} else {
printf("ERROR: Invalid tx data, must be a digit!\n");
return WAN_FALSE;
}
}else if (!strcmp(argv[i],"-tx_ss7_type")){
if (i+1 > argc-1){
} else if (!strcmp(argv[i], "-tx_ss7_type")) {
if (i + 1 > argc - 1) {
printf("ERROR: Invalid tx ss7 type!\n");
return WAN_FALSE;
}
if(isdigit(argv[i+1][0])){
tx_ss7_type = atoi(argv[i+1]);
}else{
if (isdigit(argv[i + 1][0])) {
tx_ss7_type = atoi(argv[i + 1]);
} else {
printf("ERROR: Invalid tx ss7 type, must be a digit!\n");
return WAN_FALSE;
}
}else if (!strcmp(argv[i],"-rx_ss7_timer")){
if (i+1 > argc-1){
} else if (!strcmp(argv[i], "-rx_ss7_timer")) {
if (i + 1 > argc - 1) {
printf("ERROR: Invalid rx ss7 timer!\n");
return WAN_FALSE;
}
if(isdigit(argv[i+1][0])){
rx_ss7_timer = atoi(argv[i+1]);
}else{
if (isdigit(argv[i + 1][0])) {
rx_ss7_timer = atoi(argv[i + 1]);
} else {
printf("ERROR: Invalid tx ss7 type, must be a digit!\n");
return WAN_FALSE;
}
}else if (!strcmp(argv[i],"-txfile")){
if (i+1 > argc-1){
} else if (!strcmp(argv[i], "-txfile")) {
if (i + 1 > argc - 1) {
printf("ERROR: Invalid Tx File Name!\n");
return WAN_FALSE;
}
strncpy(tx_file, argv[i+1],WAN_IFNAME_SZ);
strncpy(tx_file, argv[i + 1], WAN_IFNAME_SZ);
files_used |= TX_FILE_USED;
}else if (!strcmp(argv[i],"-rxfile")){
if (i+1 > argc-1){
} else if (!strcmp(argv[i], "-rxfile")) {
if (i + 1 > argc - 1) {
printf("ERROR: Invalid Rx File Name!\n");
return WAN_FALSE;
}
strncpy(rx_file, argv[i+1],WAN_IFNAME_SZ);
strncpy(rx_file, argv[i + 1], WAN_IFNAME_SZ);
files_used |= RX_FILE_USED;
}else if (!strcmp(argv[i],"-daddr")){
} else if (!strcmp(argv[i], "-daddr")) {
if (i+1 > argc-1){
if (i + 1 > argc - 1) {
printf("ERROR: Invalid daddr str!\n");
return WAN_FALSE;
}
strncpy(daddr, argv[i+1],TX_ADDR_STR_SZ);
}else if (!strcmp(argv[i],"-saddr")){
strncpy(daddr, argv[i + 1], TX_ADDR_STR_SZ);
if (i+1 > argc-1){
} else if (!strcmp(argv[i], "-saddr")) {
if (i + 1 > argc - 1) {
printf("ERROR: Invalid saddr str!\n");
return WAN_FALSE;
}
strncpy(saddr, argv[i+1],TX_ADDR_STR_SZ);
}else if (!strcmp(argv[i],"-udata")){
strncpy(saddr, argv[i + 1], TX_ADDR_STR_SZ);
if (i+1 > argc-1){
} else if (!strcmp(argv[i], "-udata")) {
if (i + 1 > argc - 1) {
printf("ERROR: Invalid udata str!\n");
return WAN_FALSE;
}
strncpy(udata, argv[i+1],TX_ADDR_STR_SZ);
strncpy(udata, argv[i + 1], TX_ADDR_STR_SZ);
}else if (!strcmp(argv[i],"-verbose")){
verbose=1;
} else if (!strcmp(argv[i], "-verbose")) {
verbose = 1;
}else if (!strcmp(argv[i],"-prot")){
if (i+1 > argc-1){
} else if (!strcmp(argv[i], "-prot")) {
if (i + 1 > argc - 1) {
printf("ERROR: Invalid prot!\n");
return WAN_FALSE;
}
}
if(isdigit(argv[i+1][0])){
ds_prot = atoi(argv[i+1]);
}else{
if (isdigit(argv[i + 1][0])) {
ds_prot = atoi(argv[i + 1]);
} else {
printf("ERROR: Invalid prot, must be a digit!\n");
return WAN_FALSE;
}
}else if (!strcmp(argv[i],"-prot_opt")){
if (i+1 > argc-1){
} else if (!strcmp(argv[i], "-prot_opt")) {
if (i + 1 > argc - 1) {
printf("ERROR: Invalid prot_opt!\n");
return WAN_FALSE;
}
}
if(isdigit(argv[i+1][0])){
ds_prot_opt = atoi(argv[i+1]);
}else{
if (isdigit(argv[i + 1][0])) {
ds_prot_opt = atoi(argv[i + 1]);
} else {
printf("ERROR: Invalid prot_opt, must be a digit!\n");
return WAN_FALSE;
}
}else if (!strcmp(argv[i],"-max_mult_cnt")){
if (i+1 > argc-1){
} else if (!strcmp(argv[i], "-max_mult_cnt")) {
if (i + 1 > argc - 1) {
printf("ERROR: Invalid max_mult_cnt!\n");
return WAN_FALSE;
}
}
if(isdigit(argv[i+1][0])){
ds_max_mult_cnt = atoi(argv[i+1]);
}else{
if (isdigit(argv[i + 1][0])) {
ds_max_mult_cnt = atoi(argv[i + 1]);
} else {
printf("ERROR: Invalid max_mult_cnt, must be a digit!\n");
return WAN_FALSE;
}
}else if (!strcmp(argv[i],"-active_ch")){
if (i+1 > argc-1){
} else if (!strcmp(argv[i], "-active_ch")) {
if (i + 1 > argc - 1) {
printf("ERROR: Invalid active ch!\n");
return WAN_FALSE;
}
}
ds_active_ch = parse_active_channel(argv[i+1]);
}else if (!strcmp(argv[i],"-txchan")){
if (i+1 > argc-1){
ds_active_ch = parse_active_channel(argv[i + 1]);
} else if (!strcmp(argv[i], "-txchan")) {
if (i + 1 > argc - 1) {
printf("ERROR: Invalid channels!\n");
return WAN_FALSE;
}
}
if(isdigit(argv[i+1][0])){
tx_channels = atoi(argv[i+1]);
}else{
if (isdigit(argv[i + 1][0])) {
tx_channels = atoi(argv[i + 1]);
} else {
printf("ERROR: Invalid channels, must be a digit!\n");
return WAN_FALSE;
}
}else if (!strcmp(argv[i],"-diagn")){
if (i+1 > argc-1){
} else if (!strcmp(argv[i], "-diagn")) {
if (i + 1 > argc - 1) {
printf("ERROR: Invalid diagn!\n");
return WAN_FALSE;
}
}
if(isdigit(argv[i+1][0])){
diagn = atoi(argv[i+1]);
}else{
if (isdigit(argv[i + 1][0])) {
diagn = atoi(argv[i + 1]);
} else {
printf("ERROR: Invalid diagn, must be a digit!\n");
return WAN_FALSE;
}
}else if (!strcmp(argv[i],"-cause")){
if (i+1 > argc-1){
} else if (!strcmp(argv[i], "-cause")) {
if (i + 1 > argc - 1) {
printf("ERROR: Invalid cause!\n");
return WAN_FALSE;
}
}
if(isdigit(argv[i+1][0])){
cause = atoi(argv[i+1]);
}else{
if (isdigit(argv[i + 1][0])) {
cause = atoi(argv[i + 1]);
} else {
printf("ERROR: Invalid cause, must be a digit!\n");
return WAN_FALSE;
}
}else if (!strcmp(argv[i],"-7bit_hdlc")){
if (i+1 > argc-1){
} else if (!strcmp(argv[i], "-7bit_hdlc")) {
if (i + 1 > argc - 1) {
printf("ERROR: Invalid 7bit hdlc value!\n");
return WAN_FALSE;
}
}
if(isdigit(argv[i+1][0])){
ds_7bit_hdlc = atoi(argv[i+1]);
}else{
if (isdigit(argv[i + 1][0])) {
ds_7bit_hdlc = atoi(argv[i + 1]);
} else {
printf("ERROR: Invalid 7bit hdlc, must be a digit!\n");
return WAN_FALSE;
}
}else if (!strcmp(argv[i],"-dir")){
if (i+1 > argc-1){
} else if (!strcmp(argv[i], "-dir")) {
if (i + 1 > argc - 1) {
printf("ERROR: Invalid direction value!\n");
return WAN_FALSE;
}
}
if(isdigit(argv[i+1][0])){
direction = atoi(argv[i+1]);
}else{
if (isdigit(argv[i + 1][0])) {
direction = atoi(argv[i + 1]);
} else {
printf("ERROR: Invalid direction, must be a digit!\n");
return WAN_FALSE;
}
}
}
if (!i_cnt){
if (!i_cnt) {
printf("ERROR: No Interface Name!\n");
return WAN_FALSE;
}
if (!card_cnt){
if (!card_cnt) {
printf("ERROR: No Card name!\n");
return WAN_FALSE;
}
if (!c_cnt){
if (!c_cnt) {
printf("ERROR: No Read or Write Command!\n");
return WAN_FALSE;
}
@@ -407,69 +407,66 @@ int init_args(int argc, char *argv[])
return WAN_TRUE;
}
static unsigned char api_usage[]="\n"
"\n"
"<options>:\n"
" -i <ifname> #interface name\n"
" -c <card name> #card name\n"
" -r #read enable\n"
" -w #write eable\n"
"\n"
"<extra options>\n"
" -txcnt <digit> #number of tx packets (Dflt: 1)\n"
" -txsize <digit> #tx packet size (Dflt: 10)\n"
" -txdelay <digit> #delay in sec after each tx packet (Dflt: 0)\n"
" -txdata <digit> #data to tx <1-255>\n"
"\n"
" -txfile <file> #Use file to tx instead\n"
" -rxfile <file> #Save all rx data to a file\n"
" \n"
"\n"
" -tx_ss7_type <digit> # 1=FISU 2=LSSU (repeating)\n"
" -rx_ss7_timer <digit> #Force receive timeout value \n"
"\n"
" -rxcnt <digit> #number of rx packets before exit\n"
" #this number overwrites the txcnt\n"
" #Thus, app will only exit after it\n"
" #receives the rxcnt number of packets.\n"
" \n"
" -verbose #Enable verbose mode\n"
"\n"
"<datascope options>\n"
"\n"
" -prot <digit> #Protocol Bit map: \n"
" #1=FISU, 2=LSSU, 4=MSU, 8=RAW HDLC\n"
" \n"
" -prot_opt <digit> #Protocol bit map\n"
" #0=None, 1=Delta, 2=Max Multiple\n"
"\n"
" -active_ch <digit> #Active channel\n"
" #ALL = all channels \n"
" #1 24 = 1 to 24 \n"
" #1.24 = 1 and 24 \n"
" #1-4.7-15 = 1 to 4 and 7 to 15\n"
" \n"
" -max_mult_cnt <digit> #If Prot_opt == 2 \n"
" #max_mult_cnt is the number of \n"
" #consecutive duplicate frames \n"
" #received before pass up the stack.\n"
" \n"
" -7bit_hdlc <digit> #Enable 7 Bit Hdlc Engine\n"
" #1=Enable 0=Disable\n"
" \n"
" -dir <digit> #Direction 0: Rx 1: Tx none: All\n"
"\n"
"<x25 protocol options>\n"
"\n"
" -txchan <digit> #Number of channels (dflt=1)\n"
" -cause <digit> #disconnect cause (dflt=0)\n"
" -diagn <digit> #disconnect diagnostic (dflt=0)\n"
"\n";
static unsigned char api_usage[] = "\n"
"\n"
"<options>:\n"
" -i <ifname> #interface name\n"
" -c <card name> #card name\n"
" -r #read enable\n"
" -w #write eable\n"
"\n"
"<extra options>\n"
" -txcnt <digit> #number of tx packets (Dflt: 1)\n"
" -txsize <digit> #tx packet size (Dflt: 10)\n"
" -txdelay <digit> #delay in sec after each tx packet (Dflt: 0)\n"
" -txdata <digit> #data to tx <1-255>\n"
"\n"
" -txfile <file> #Use file to tx instead\n"
" -rxfile <file> #Save all rx data to a file\n"
" \n"
"\n"
" -tx_ss7_type <digit> # 1=FISU 2=LSSU (repeating)\n"
" -rx_ss7_timer <digit> #Force receive timeout value \n"
"\n"
" -rxcnt <digit> #number of rx packets before exit\n"
" #this number overwrites the txcnt\n"
" #Thus, app will only exit after it\n"
" #receives the rxcnt number of packets.\n"
" \n"
" -verbose #Enable verbose mode\n"
"\n"
"<datascope options>\n"
"\n"
" -prot <digit> #Protocol Bit map: \n"
" #1=FISU, 2=LSSU, 4=MSU, 8=RAW HDLC\n"
" \n"
" -prot_opt <digit> #Protocol bit map\n"
" #0=None, 1=Delta, 2=Max Multiple\n"
"\n"
" -active_ch <digit> #Active channel\n"
" #ALL = all channels \n"
" #1 24 = 1 to 24 \n"
" #1.24 = 1 and 24 \n"
" #1-4.7-15 = 1 to 4 and 7 to 15\n"
" \n"
" -max_mult_cnt <digit> #If Prot_opt == 2 \n"
" #max_mult_cnt is the number of \n"
" #consecutive duplicate frames \n"
" #received before pass up the stack.\n"
" \n"
" -7bit_hdlc <digit> #Enable 7 Bit Hdlc Engine\n"
" #1=Enable 0=Disable\n"
" \n"
" -dir <digit> #Direction 0: Rx 1: Tx none: All\n"
"\n"
"<x25 protocol options>\n"
"\n"
" -txchan <digit> #Number of channels (dflt=1)\n"
" -cause <digit> #disconnect cause (dflt=0)\n" " -diagn <digit> #disconnect diagnostic (dflt=0)\n" "\n";
void usage(unsigned char *api_name)
{
printf ("\n\nAPI %s USAGE:\n\n%s <options> <extra options>\n\n%s\n",
api_name,api_name,api_usage);
printf("\n\nAPI %s USAGE:\n\n%s <options> <extra options>\n\n%s\n", api_name, api_name, api_usage);
}
@@ -483,30 +480,30 @@ unsigned long get_active_channels(int channel_flag, int start_channel, int stop_
if ((channel_flag & (SINGLE_CHANNEL | RANGE_CHANNEL)) == 0)
return tmp;
if (channel_flag & RANGE_CHANNEL) { /* Range of channels */
for(i = start_channel; i <= stop_channel; i++) {
if (channel_flag & RANGE_CHANNEL) { /* Range of channels */
for (i = start_channel; i <= stop_channel; i++) {
mask = 1 << (i - 1);
tmp |=mask;
tmp |= mask;
}
} else { /* Single channel */
} else { /* Single channel */
mask = 1 << (stop_channel - 1);
tmp |= mask;
tmp |= mask;
}
return tmp;
}
unsigned long parse_active_channel(char* val)
unsigned long parse_active_channel(char *val)
{
int channel_flag = 0;
char* ptr = val;
char *ptr = val;
int channel = 0, start_channel = 0;
unsigned long tmp = 0;
if (strcmp(val,"ALL") == 0)
if (strcmp(val, "ALL") == 0)
return ENABLE_ALL_CHANNELS;
while(*ptr != '\0') {
while (*ptr != '\0') {
if (isdigit(*ptr)) {
channel = strtoul(ptr, &ptr, 10);
channel_flag |= SINGLE_CHANNEL;
@@ -521,7 +518,7 @@ unsigned long parse_active_channel(char* val)
ptr++;
}
}
if (channel_flag){
if (channel_flag) {
tmp |= get_active_channels(channel_flag, start_channel, channel);
}
return tmp;
@@ -531,7 +528,7 @@ void u_delay(int usec)
{
struct timeval tv;
tv.tv_usec = usec;
tv.tv_sec=0;
tv.tv_sec = 0;
select(0,NULL,NULL, NULL, &tv);
select(0, NULL, NULL, NULL, &tv);
}
File diff suppressed because it is too large. Load diff
@@ -56,7 +56,7 @@ static struct ss7boost_client_map ss7boost_client_table[] = {
static switch_status_t create_udp_socket(ss7boost_client_connection_t * mcon, char *local_ip, int local_port, char *ip, int port)
static switch_status_t create_udp_socket(ss7boost_client_connection_t *mcon, char *local_ip, int local_port, char *ip, int port)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "connect %s:%d->%s:%d\n", local_ip, local_port, ip, port);
@@ -88,7 +88,7 @@ static switch_status_t create_udp_socket(ss7boost_client_connection_t * mcon, ch
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_close(ss7boost_client_connection_t * mcon)
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_close(ss7boost_client_connection_t *mcon)
{
switch_socket_close(mcon->socket);
mcon->socket = NULL;
@@ -97,7 +97,7 @@ SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_close(ss7boost_client
return SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_open(ss7boost_client_connection_t * mcon,
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_open(ss7boost_client_connection_t *mcon,
char *local_ip, int local_port, char *ip, int port, switch_memory_pool_t *pool)
{
memset(mcon, 0, sizeof(*mcon));
@@ -112,7 +112,7 @@ SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_open(ss7boost_client_
return SWITCH_STATUS_FALSE;
}
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_read(ss7boost_client_connection_t * mcon, ss7boost_client_event_t ** event)
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_read(ss7boost_client_connection_t *mcon, ss7boost_client_event_t **event)
{
unsigned int fromlen = sizeof(struct sockaddr_in);
switch_size_t bytes = 0;
@@ -138,7 +138,7 @@ SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_read(ss7boost_client_
return SWITCH_STATUS_FALSE;
}
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_write(ss7boost_client_connection_t * mcon, ss7boost_client_event_t * event)
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_write(ss7boost_client_connection_t *mcon, ss7boost_client_event_t *event)
{
int err;
switch_size_t len;
@@ -200,7 +200,7 @@ SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_write(ss7boost_client
return err ? SWITCH_STATUS_FALSE : SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(void) ss7boost_client_call_init(ss7boost_client_event_t * event, char *calling, char *called, int setup_id)
SWITCH_DECLARE(void) ss7boost_client_call_init(ss7boost_client_event_t *event, char *calling, char *called, int setup_id)
{
memset(event, 0, sizeof(ss7boost_client_event_t));
event->event_id = SIGBOOST_EVENT_CALL_START;
@@ -219,7 +219,7 @@ SWITCH_DECLARE(void) ss7boost_client_call_init(ss7boost_client_event_t * event,
}
SWITCH_DECLARE(void) ss7boost_client_event_init(ss7boost_client_event_t * event, ss7boost_client_event_id_t event_id, int chan, int span)
SWITCH_DECLARE(void) ss7boost_client_event_init(ss7boost_client_event_t *event, ss7boost_client_event_id_t event_id, int chan, int span)
{
memset(event, 0, sizeof(ss7boost_client_event_t));
event->event_id = event_id;
+137 -160
View File
@@ -34,8 +34,8 @@
#include <libsangoma.h>
#include "lib_api.h"
#define MAX_TX_DATA 5000 /* Size of tx data */
#define MAX_FRAMES 5000 /* Number of frames to transmit */
#define MAX_TX_DATA 5000 /* Size of tx data */
#define MAX_FRAMES 5000 /* Number of frames to transmit */
#define MAX_RX_DATA 5000
@@ -46,12 +46,12 @@ unsigned char Tx_data[MAX_TX_DATA + sizeof(wp_tdm_api_rx_hdr_t)];
/* Prototypes */
int MakeConnection(void);
void handle_span_chan( void);
void handle_span_chan(void);
void sig_end(int sigid);
int dev_fd;
FILE *tx_fd=NULL,*rx_fd=NULL;
wanpipe_tdm_api_t tdm_api;
FILE *tx_fd = NULL, *rx_fd = NULL;
wanpipe_tdm_api_t tdm_api;
/***************************************************
@@ -114,263 +114,246 @@ wanpipe_tdm_api_t tdm_api;
*
*/
void handle_span_chan(void)
void handle_span_chan(void)
{
unsigned int Rx_count,Tx_count,Tx_length;
wp_tdm_api_rx_element_t* api_rx_el;
wp_tdm_api_tx_element_t * api_tx_el;
fd_set ready,write,oob;
int err,i;
unsigned int Rx_count, Tx_count, Tx_length;
wp_tdm_api_rx_element_t *api_rx_el;
wp_tdm_api_tx_element_t *api_tx_el;
fd_set ready, write, oob;
int err, i;
#if 0
int rlen;
int stream_sync=0;
int stream_sync = 0;
#endif
Rx_count = 0;
Tx_count = 0;
if (tdm_api.wp_tdm_cmd.hdlc) {
Tx_length = tx_size;
Tx_length = tx_size;
} else {
Tx_length = tdm_api.wp_tdm_cmd.usr_mtu_mru;
}
printf("\n\nSocket Handler: Rx=%d Tx=%i TxCnt=%i TxLen=%i TxDelay=%i\n",
read_enable,write_enable,tx_cnt,tx_size,tx_delay);
printf("\n\nSocket Handler: Rx=%d Tx=%i TxCnt=%i TxLen=%i TxDelay=%i\n", read_enable, write_enable, tx_cnt, tx_size, tx_delay);
/* Initialize the Tx Data buffer */
memset(&Tx_data[0],0,MAX_TX_DATA + sizeof(wp_tdm_api_rx_hdr_t));
memset(&Tx_data[0], 0, MAX_TX_DATA + sizeof(wp_tdm_api_rx_hdr_t));
/* Cast the Tx data packet with the tx element
* structure. We must insert a 16 byte
* driver header, which driver will remove
* before passing packet out the physical port */
api_tx_el = (wp_tdm_api_tx_element_t*)&Tx_data[0];
api_tx_el = (wp_tdm_api_tx_element_t *) &Tx_data[0];
/* Create a Tx packet based on user info, or
* by deafult incrementing number starting from 0 */
for (i=0;i<Tx_length;i++){
if (tx_data == -1){
api_tx_el->data[i] = (unsigned char)i;
}else{
for (i = 0; i < Tx_length; i++) {
if (tx_data == -1) {
api_tx_el->data[i] = (unsigned char) i;
} else {
#if 0
api_tx_el->data[i] = (unsigned char)tx_data+(i%4);
api_tx_el->data[i] = (unsigned char) tx_data + (i % 4);
#else
api_tx_el->data[i] = (unsigned char)tx_data;
api_tx_el->data[i] = (unsigned char) tx_data;
#endif
}
}
sangoma_tdm_enable_rxhook_events(dev_fd, &tdm_api);
sangoma_tdm_enable_rxhook_events(dev_fd, &tdm_api);
/* Main Rx Tx OOB routine */
for(;;) {
for (;;) {
/* Initialize all select() descriptors */
FD_ZERO(&ready);
FD_ZERO(&write);
FD_ZERO(&oob);
FD_SET(dev_fd,&oob);
FD_SET(dev_fd,&ready);
FD_SET(dev_fd, &oob);
FD_SET(dev_fd, &ready);
if (write_enable){
FD_SET(dev_fd,&write);
if (write_enable) {
FD_SET(dev_fd, &write);
}
/* Select will block, until:
* 1: OOB event, link level change
* 2: Rx data available
* 3: Interface able to Tx */
if(select(dev_fd + 1,&ready, &write, &oob, NULL)){
* 1: OOB event, link level change
* 2: Rx data available
* 3: Interface able to Tx */
if (select(dev_fd + 1, &ready, &write, &oob, NULL)) {
fflush(stdout);
if (FD_ISSET(dev_fd, &oob)) {
fflush(stdout);
if (FD_ISSET(dev_fd,&oob)){
/* An OOB event is pending, usually indicating
* a link level change */
err=sangoma_tdm_read_event(dev_fd,&tdm_api);
if(err < 0 ) {
err = sangoma_tdm_read_event(dev_fd, &tdm_api);
if (err < 0) {
printf("Failed to receive OOB %i , %i\n", Rx_count, err);
err = ioctl(dev_fd,SIOC_WANPIPE_SOCK_STATE,0);
printf("Sock state is %s\n",
(err == 0) ? "CONNECTED" :
(err == 1) ? "DISCONNECTED" :
"CONNECTING");
err = ioctl(dev_fd, SIOC_WANPIPE_SOCK_STATE, 0);
printf("Sock state is %s\n", (err == 0) ? "CONNECTED" : (err == 1) ? "DISCONNECTED" : "CONNECTING");
break;
}
printf("GOT OOB EXCEPTION CMD Exiting\n");
}
if (FD_ISSET(dev_fd,&ready)){
if (FD_ISSET(dev_fd, &ready)) {
/* An Rx packet is pending
* 1: Read the rx packet into the Rx_data
* buffer. Confirm len > 0
* 1: Read the rx packet into the Rx_data
* buffer. Confirm len > 0
*
* 2: Cast Rx_data to the api_rx_element.
* Thus, removing a 16 byte header
* attached by the driver.
* 2: Cast Rx_data to the api_rx_element.
* Thus, removing a 16 byte header
* attached by the driver.
*
* 3. Check error_flag:
* CRC,Abort..etc
* 3. Check error_flag:
* CRC,Abort..etc
*/
memset(Rx_data, 0, sizeof(Rx_data));
err = sangoma_readmsg_tdm(dev_fd,
Rx_data,
sizeof(wp_tdm_api_rx_hdr_t),
&Rx_data[sizeof(wp_tdm_api_rx_hdr_t)],
MAX_RX_DATA, 0);
err = sangoma_readmsg_tdm(dev_fd, Rx_data, sizeof(wp_tdm_api_rx_hdr_t), &Rx_data[sizeof(wp_tdm_api_rx_hdr_t)], MAX_RX_DATA, 0);
if (!read_enable){
if (!read_enable) {
goto bitstrm_skip_read;
}
/* err indicates bytes received */
if(err <= 0) {
if (err <= 0) {
printf("\nError receiving data\n");
break;
}
api_rx_el = (wp_tdm_api_rx_element_t*)&Rx_data[0];
api_rx_el = (wp_tdm_api_rx_element_t *) & Rx_data[0];
/* Check the packet length */
Rx_lgth = err;
if(Rx_lgth<=0) {
printf("\nShort frame received (%d)\n",
Rx_lgth);
if (Rx_lgth <= 0) {
printf("\nShort frame received (%d)\n", Rx_lgth);
return;
}
#if 0
if (api_rx_el->data[0] == tx_data && api_rx_el->data[1] == (tx_data+1)){
if (!stream_sync){
printf("GOT SYNC %x\n",api_rx_el->data[0]);
if (api_rx_el->data[0] == tx_data && api_rx_el->data[1] == (tx_data + 1)) {
if (!stream_sync) {
printf("GOT SYNC %x\n", api_rx_el->data[0]);
}
stream_sync=1;
}else{
if (stream_sync){
printf("OUT OF SYNC: %x\n",api_rx_el->data[0]);
stream_sync = 1;
} else {
if (stream_sync) {
printf("OUT OF SYNC: %x\n", api_rx_el->data[0]);
}
}
#endif
#endif
++Rx_count;
if (verbose){
if (verbose) {
#if 0
printf("Received %i Length = %i\n",
Rx_count,Rx_lgth);
printf("Received %i Length = %i\n", Rx_count, Rx_lgth);
printf("Data: ");
for(i=0;i<Rx_lgth; i ++) {
for (i = 0; i < Rx_lgth; i++) {
printf("0x%02X ", api_rx_el->data[i]);
}
printf("\n");
#endif
}else{
} else {
//putchar('R');
}
#if 0
switch(api_rx_el->hdr.wp_api_event_type){
switch (api_rx_el->hdr.wp_api_event_type) {
case WP_TDM_EVENT_DTMF:
printf("DTMV Event: %c (%s:%s)!\n",
api_rx_el->hdr.wp_api_event_dtmf_digit,
(api_rx_el->hdr.wp_api_event_dtmf_type&WP_TDM_EVENT_DTMF_ROUT)?"ROUT":"SOUT",
(api_rx_el->hdr.wp_api_event_dtmf_type&WP_TDM_EVENT_DTMF_PRESET)?"PRESET":"STOP");
api_rx_el->hdr.wp_api_event_dtmf_digit,
(api_rx_el->hdr.wp_api_event_dtmf_type & WP_TDM_EVENT_DTMF_ROUT) ? "ROUT" : "SOUT",
(api_rx_el->hdr.wp_api_event_dtmf_type & WP_TDM_EVENT_DTMF_PRESET) ? "PRESET" : "STOP");
break;
case WP_TDM_EVENT_RXHOOK:
printf("RXHOOK Event: %s!\n",
(api_rx_el->hdr.wp_api_event_rxhook_state&WP_TDM_EVENT_RXHOOK_OFF)?"OFF-HOOK":"ON-HOOK");
printf("RXHOOK Event: %s!\n", (api_rx_el->hdr.wp_api_event_rxhook_state & WP_TDM_EVENT_RXHOOK_OFF) ? "OFF-HOOK" : "ON-HOOK");
break;
case WP_TDM_EVENT_RING:
printf("RING Event: %s!\n",
(api_rx_el->hdr.wp_api_event_ring_state&WP_TDM_EVENT_RING_PRESENT)?"PRESENT":"STOP");
printf("RING Event: %s!\n", (api_rx_el->hdr.wp_api_event_ring_state & WP_TDM_EVENT_RING_PRESENT) ? "PRESENT" : "STOP");
break;
}
#endif
if (rx_cnt > 0 && Rx_count >= rx_cnt){
if (rx_cnt > 0 && Rx_count >= rx_cnt) {
break;
}
bitstrm_skip_read:
;
}
if (FD_ISSET(dev_fd,&write)){
bitstrm_skip_read:
;
}
if (FD_ISSET(dev_fd, &write)) {
err = sangoma_writemsg_tdm(dev_fd,
Tx_data,16,
&Tx_data[16], Tx_length,
0);
if (err <= 0){
if (errno == EBUSY){
if (verbose){
err = sangoma_writemsg_tdm(dev_fd, Tx_data, 16, &Tx_data[16], Tx_length, 0);
if (err <= 0) {
if (errno == EBUSY) {
if (verbose) {
printf("Sock busy try again!\n");
}
/* Socket busy try sending again !*/
}else{
printf("Faild to send %i \n",errno);
/* Socket busy try sending again ! */
} else {
printf("Faild to send %i \n", errno);
perror("Send: ");
break;
}
}else{
} else {
++Tx_count;
if (verbose){
if (verbose) {
//printf("Packet sent: Sent %i : %i\n",
// err,Tx_count);
}else{
// err,Tx_count);
} else {
//putchar('T');
}
}
}
}
if (tx_delay){
if (tx_delay) {
usleep(tx_delay);
}
if (tx_cnt && tx_size && Tx_count >= tx_cnt && !(files_used & TX_FILE_USED)){
write_enable=0;
if (rx_cnt > 0){
if (tx_cnt && tx_size && Tx_count >= tx_cnt && !(files_used & TX_FILE_USED)) {
write_enable = 0;
if (rx_cnt > 0) {
/* Dont break let rx finish */
}else{
} else {
break;
}
}
}
}
sangoma_tdm_disable_rxhook_events(dev_fd, &tdm_api);
if (tx_fd){
sangoma_tdm_disable_rxhook_events(dev_fd, &tdm_api);
if (tx_fd) {
fclose(tx_fd);
}
if (rx_fd){
if (rx_fd) {
fclose(rx_fd);
}
close (dev_fd);
close(dev_fd);
return;
}
}
int rxhook_event (int fd, unsigned char state)
int rxhook_event(int fd, unsigned char state)
{
printf("%d: RXHOOK Event: %s!\n",
fd, (state & WAN_EVENT_RXHOOK_OFF)?"OFF-HOOK":"ON-HOOK");
printf("%d: RXHOOK Event: %s!\n", fd, (state & WAN_EVENT_RXHOOK_OFF) ? "OFF-HOOK" : "ON-HOOK");
return 0;
}
@@ -383,37 +366,34 @@ int rxhook_event (int fd, unsigned char state)
**************************************************************/
int main(int argc, char* argv[])
int main(int argc, char *argv[])
{
int proceed;
proceed=init_args(argc,argv);
if (proceed != WAN_TRUE){
proceed = init_args(argc, argv);
if (proceed != WAN_TRUE) {
usage(argv[0]);
return -1;
}
signal(SIGINT,&sig_end);
memset(&tdm_api,0,sizeof(tdm_api));
signal(SIGINT, &sig_end);
memset(&tdm_api, 0, sizeof(tdm_api));
tdm_api.wp_tdm_event.wp_rxhook_event = &rxhook_event;
printf("TDM RXHOOK PTR = %p\n",tdm_api.wp_tdm_event.wp_rxhook_event);
dev_fd =-1;
dev_fd = sangoma_open_tdmapi_span_chan(atoi(card_name),atoi(if_name));
if( dev_fd < 0){
printf("Failed to open span chan (%s:%s:%d:%d)\n",
card_name, if_name,
atoi(card_name),atoi(if_name));
exit (1);
printf("TDM RXHOOK PTR = %p\n", tdm_api.wp_tdm_event.wp_rxhook_event);
dev_fd = -1;
dev_fd = sangoma_open_tdmapi_span_chan(atoi(card_name), atoi(if_name));
if (dev_fd < 0) {
printf("Failed to open span chan (%s:%s:%d:%d)\n", card_name, if_name, atoi(card_name), atoi(if_name));
exit(1);
}
printf("HANDLING SPAN %i CHAN %i FD=%i\n",
atoi(card_name),atoi(if_name),dev_fd);
sangoma_tdm_set_codec(dev_fd,&tdm_api,WP_NONE);
printf("HANDLING SPAN %i CHAN %i FD=%i\n", atoi(card_name), atoi(if_name), dev_fd);
sangoma_tdm_set_codec(dev_fd, &tdm_api, WP_NONE);
sangoma_get_full_cfg(dev_fd, &tdm_api);
handle_span_chan();
close(dev_fd);
return 0;
@@ -425,24 +405,21 @@ int main(int argc, char* argv[])
void sig_end(int sigid)
{
printf("Got Signal %i\n",sigid);
printf("Got Signal %i\n", sigid);
sangoma_tdm_disable_rxhook_events(dev_fd, &tdm_api);
if (tx_fd){
if (tx_fd) {
fclose(tx_fd);
}
if (rx_fd){
if (rx_fd) {
fclose(rx_fd);
}
if (dev_fd){
close (dev_fd);
if (dev_fd) {
close(dev_fd);
}
exit(1);
}
+15 -23
View File
@@ -180,16 +180,16 @@ static switch_status_t woomera_read_frame(switch_core_session_t *session, switch
static switch_status_t woomera_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id);
static switch_status_t woomera_kill_channel(switch_core_session_t *session, int sig);
static void tech_destroy(private_object * tech_pvt);
static void woomera_printf(woomera_profile * profile, switch_socket_t * socket, char *fmt, ...);
static void woomera_printf(woomera_profile * profile, switch_socket_t *socket, char *fmt, ...);
static char *woomera_message_header(woomera_message * wmsg, char *key);
static int woomera_enqueue_event(woomera_event_queue * event_queue, woomera_message * wmsg);
static int woomera_dequeue_event(woomera_event_queue * event_queue, woomera_message * wmsg);
static int woomera_message_parse(switch_socket_t * fd, woomera_message * wmsg, int timeout, woomera_profile * profile, woomera_event_queue * event_queue);
static int connect_woomera(switch_socket_t ** new_sock, woomera_profile * profile, int flags);
static int woomera_message_parse(switch_socket_t *fd, woomera_message * wmsg, int timeout, woomera_profile * profile, woomera_event_queue * event_queue);
static int connect_woomera(switch_socket_t **new_sock, woomera_profile * profile, int flags);
static int woomera_profile_thread_running(woomera_profile * profile, int set, int new);
static int woomera_locate_socket(woomera_profile * profile, switch_socket_t ** woomera_socket);
static int woomera_locate_socket(woomera_profile * profile, switch_socket_t **woomera_socket);
static int tech_create_read_socket(private_object * tech_pvt);
static void *woomera_channel_thread_run(switch_thread_t * thread, void *obj);
static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj);
static void *woomera_thread_run(void *obj);
static int tech_activate(private_object * tech_pvt);
@@ -264,7 +264,7 @@ static switch_status_t woomera_on_hangup(switch_core_session_t *session)
return SWITCH_STATUS_SUCCESS;
}
static void woomera_socket_close(switch_socket_t ** socket)
static void woomera_socket_close(switch_socket_t **socket)
{
if (*socket) {
switch_socket_close(*socket);
@@ -330,7 +330,7 @@ static switch_status_t woomera_read_frame(switch_core_session_t *session, switch
switch_assert(tech_pvt != NULL);
for(;;) {
for (;;) {
if (switch_test_flag(tech_pvt, TFLAG_ABORT) || !tech_pvt->udp_socket) {
return SWITCH_STATUS_GENERR;
}
@@ -364,7 +364,7 @@ static switch_status_t woomera_write_frame(switch_core_session_t *session, switc
switch_size_t len;
switch_assert(tech_pvt != NULL);
if (switch_test_flag(tech_pvt, TFLAG_ABORT) || !tech_pvt->udp_socket) {
return SWITCH_STATUS_GENERR;
}
@@ -469,7 +469,7 @@ static void tech_destroy(private_object * tech_pvt)
}
static void woomera_printf(woomera_profile * profile, switch_socket_t * socket, char *fmt, ...)
static void woomera_printf(woomera_profile * profile, switch_socket_t *socket, char *fmt, ...)
{
char *stuff = NULL;
size_t res = 0, len = 0;
@@ -558,7 +558,7 @@ static int woomera_dequeue_event(woomera_event_queue * event_queue, woomera_mess
return 0;
}
static int woomera_message_parse(switch_socket_t * fd, woomera_message * wmsg, int timeout, woomera_profile * profile, woomera_event_queue * event_queue)
static int woomera_message_parse(switch_socket_t *fd, woomera_message * wmsg, int timeout, woomera_profile * profile, woomera_event_queue * event_queue)
{
char *cur, *cr, *next = NULL;
char buf[2048] = "", *ptr;
@@ -719,7 +719,7 @@ static int woomera_message_parse(switch_socket_t * fd, woomera_message * wmsg, i
}
static int connect_woomera(switch_socket_t ** new_sock, woomera_profile * profile, int flags)
static int connect_woomera(switch_socket_t **new_sock, woomera_profile * profile, int flags)
{
switch_sockaddr_t *sa;
@@ -764,7 +764,7 @@ static int woomera_profile_thread_running(woomera_profile * profile, int set, in
}
static int woomera_locate_socket(woomera_profile * profile, switch_socket_t ** woomera_socket)
static int woomera_locate_socket(woomera_profile * profile, switch_socket_t **woomera_socket)
{
woomera_message wmsg;
@@ -823,7 +823,7 @@ static int tech_create_read_socket(private_object * tech_pvt)
} else {
switch_set_flag_locked(tech_pvt, TFLAG_ABORT);
}
return 0;
}
@@ -872,7 +872,7 @@ static int tech_activate(private_object * tech_pvt)
static void *woomera_channel_thread_run(switch_thread_t * thread, void *obj)
static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj)
{
switch_core_session_t *session = obj;
switch_channel_t *channel = switch_core_session_get_channel(session);
@@ -976,15 +976,7 @@ static void *woomera_channel_thread_run(switch_thread_t * thread, void *obj)
if ((tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
NULL,
tech_pvt->profile->dialplan,
cid_name,
cid_num,
ip,
NULL,
NULL,
NULL,
modname,
NULL,
exten)) != 0) {
cid_name, cid_num, ip, NULL, NULL, NULL, modname, NULL, exten)) != 0) {
char name[128];
switch_snprintf(name, sizeof(name), "Woomera/%s-%04x", tech_pvt->caller_profile->destination_number, rand() & 0xffff);
switch_channel_set_name(channel, name);
@@ -37,7 +37,7 @@ struct cdr_fd {
};
typedef struct cdr_fd cdr_fd_t;
const char *default_template =
const char *default_template =
"\"${caller_id_name}\",\"${caller_id_number}\",\"${destination_number}\",\"${context}\",\"${start_stamp}\","
"\"${answer_stamp}\",\"${end_stamp}\",\"${duration}\",\"${billsec}\",\"${hangup_cause}\",\"${uuid}\",\"${bleg_uuid}\", \"${accountcode}\"\n";
@@ -58,12 +58,12 @@ SWITCH_MODULE_DEFINITION(mod_cdr_csv, mod_cdr_csv_load, NULL, NULL);
static off_t fd_size(int fd)
{
struct stat s = {0};
struct stat s = { 0 };
fstat(fd, &s);
return s.st_size;
}
static void do_reopen(cdr_fd_t *fd)
static void do_reopen(cdr_fd_t *fd)
{
int x = 0;
@@ -72,7 +72,7 @@ static void do_reopen(cdr_fd_t *fd)
fd->fd = -1;
}
for (x = 0 ; x < 10; x++) {
for (x = 0; x < 10; x++) {
if ((fd->fd = open(fd->path, O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR)) > -1) {
fd->bytes = fd_size(fd->fd);
break;
@@ -95,7 +95,7 @@ static void do_rotate(cdr_fd_t *fd)
if (globals.rotate) {
switch_time_exp_lt(&tm, switch_timestamp_now());
switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d-%H-%M-%S", &tm);
len = strlen(fd->path) + strlen(date) + 2;
p = switch_mprintf("%s.%s", fd->path, date);
assert(p);
@@ -104,7 +104,7 @@ static void do_rotate(cdr_fd_t *fd)
}
do_reopen(fd);
if (fd->fd < 0) {
switch_event_t *event;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error opening %s\n", fd->path);
@@ -115,14 +115,14 @@ static void do_rotate(cdr_fd_t *fd)
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "%s CDR logfile %s\n", globals.rotate ? "Rotated" : "Re-opened", fd->path);
}
}
static void write_cdr(const char *path, const char *log_line)
{
cdr_fd_t *fd = NULL;
unsigned int bytes_in, bytes_out;
if (!(fd = switch_core_hash_find(globals.fd_hash, path))) {
fd = switch_core_alloc(globals.pool, sizeof(*fd));
switch_assert(fd);
@@ -132,10 +132,10 @@ static void write_cdr(const char *path, const char *log_line)
fd->path = switch_core_strdup(globals.pool, path);
switch_core_hash_insert(globals.fd_hash, path, fd);
}
switch_mutex_lock(fd->mutex);
bytes_out = (unsigned)strlen(log_line);
bytes_out = (unsigned) strlen(log_line);
if (fd->fd < 0) {
do_reopen(fd);
if (fd->fd < 0) {
@@ -143,18 +143,18 @@ static void write_cdr(const char *path, const char *log_line)
goto end;
}
}
if (fd->bytes + bytes_out > UINT_MAX) {
do_rotate(fd);
}
if ((bytes_in = write(fd->fd, log_line, bytes_out)) != bytes_out) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Write error to file %s %d/%d\n", path, (int)bytes_in, (int)bytes_out);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Write error to file %s %d/%d\n", path, (int) bytes_in, (int) bytes_out);
}
fd->bytes += bytes_in;
end:
end:
switch_mutex_unlock(fd->mutex);
}
@@ -164,7 +164,7 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_status_t status = SWITCH_STATUS_SUCCESS;
const char *log_dir = NULL, *accountcode = NULL, *a_template_str = NULL, *g_template_str = NULL;
char *log_line, *path = NULL;
char *log_line, *path = NULL;
if (switch_channel_get_originator_caller_profile(channel)) {
return SWITCH_STATUS_SUCCESS;
@@ -173,7 +173,7 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
if (!(log_dir = switch_channel_get_variable(channel, "cdr_csv_base"))) {
log_dir = globals.log_dir;
}
if (switch_dir_make_recursive(log_dir, SWITCH_DEFAULT_DIR_PERMS, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating %s\n", log_dir);
return SWITCH_STATUS_FALSE;
@@ -193,15 +193,15 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
}
g_template_str = (const char *) switch_core_hash_find(globals.template_hash, globals.default_template);
if ((accountcode = switch_channel_get_variable(channel, "ACCOUNTCODE"))) {
a_template_str = (const char *) switch_core_hash_find(globals.template_hash, accountcode);
}
if (!a_template_str) {
a_template_str = g_template_str;
}
log_line = switch_channel_expand_variables(channel, a_template_str);
if (accountcode) {
@@ -210,21 +210,21 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
write_cdr(path, log_line);
free(path);
}
if (g_template_str != a_template_str) {
if (log_line && log_line != a_template_str) {
switch_safe_free(log_line);
}
log_line = switch_channel_expand_variables(channel, g_template_str);
}
path = switch_mprintf("%s%sMaster.csv", log_dir, SWITCH_PATH_SEPARATOR);
assert(path);
write_cdr(path, log_line);
free(path);
if (log_line && log_line != g_template_str) {
free(log_line);
@@ -237,7 +237,7 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
static void event_handler(switch_event_t *event)
{
const char *sig = switch_event_get_header(event, "Trapped-Signal");
switch_hash_index_t *hi;
switch_hash_index_t *hi;
void *val;
cdr_fd_t *fd;
@@ -269,18 +269,18 @@ static switch_status_t load_config(switch_memory_pool_t *pool)
char *cf = "cdr_csv.conf";
switch_xml_t cfg, xml, settings, param;
switch_status_t status = SWITCH_STATUS_SUCCESS;
memset(&globals,0,sizeof(globals));
memset(&globals, 0, sizeof(globals));
switch_core_hash_init(&globals.fd_hash, pool);
switch_core_hash_init(&globals.template_hash, pool);
globals.pool = pool;
switch_core_hash_insert(globals.template_hash, "default", default_template);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Adding default template.\n");
if ((xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
if ((settings = switch_xml_child(cfg, "settings"))) {
for (param = switch_xml_child(settings, "param"); param; param = param->next) {
char *var = (char *) switch_xml_attr_soft(param, "name");
@@ -317,7 +317,7 @@ static switch_status_t load_config(switch_memory_pool_t *pool)
}
switch_xml_free(xml);
}
if (switch_strlen_zero(globals.default_template)) {
globals.default_template = switch_core_strdup(pool, "default");
@@ -326,7 +326,7 @@ static switch_status_t load_config(switch_memory_pool_t *pool)
if (!globals.log_dir) {
globals.log_dir = switch_core_sprintf(pool, "%s%scdr-csv", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR);
}
return status;
}
@@ -344,20 +344,20 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_cdr_csv_load)
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
load_config(pool);
if ((status = switch_dir_make_recursive(globals.log_dir, SWITCH_DEFAULT_DIR_PERMS, pool)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating %s\n", globals.log_dir);
}
return status;
}
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_cdr_csv_shutdown)
{
globals.shutdown=1;
return SWITCH_STATUS_SUCCESS;
globals.shutdown = 1;
return SWITCH_STATUS_SUCCESS;
}
@@ -283,10 +283,10 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_event_multicast_runtime)
uint64_t host_hash = 0;
switch_status_t status;
memset(buf, 0, len);
switch_sockaddr_ip_get(&myaddr, globals.addr);
status = switch_socket_recvfrom(addr, globals.udp_socket, 0, buf, &len);
if (!len) {
if (SWITCH_STATUS_IS_BREAK(status)) {
switch_yield(100000);
@@ -334,7 +334,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_event_multicast_runtime)
switch_event_fire(&local_event);
}
}
globals.running = 0;
@@ -103,8 +103,8 @@ static struct {
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_pref_ip, prefs.ip);
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_pref_pass, prefs.password);
static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t * thread, void *obj);
static void launch_listener_thread(listener_t * listener);
static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t *thread, void *obj);
static void launch_listener_thread(listener_t *listener);
static switch_status_t socket_logger(const switch_log_node_t *node, switch_log_level_t level)
{
@@ -117,7 +117,7 @@ static switch_status_t socket_logger(const switch_log_node_t *node, switch_log_l
if (data) {
if (switch_queue_trypush(l->log_queue, data) == SWITCH_STATUS_SUCCESS) {
if (l->lost_logs) {
int ll = l->lost_logs;
int ll = l->lost_logs;
switch_event_t *event;
l->lost_logs = 0;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Lost %d log lines!\n", ll);
@@ -158,7 +158,7 @@ static void event_handler(switch_event_t *event)
if (!switch_test_flag(l, LFLAG_EVENTS)) {
continue;
}
if (l->event_list[SWITCH_EVENT_ALL]) {
send = 1;
} else if ((l->event_list[event->event_id])) {
@@ -300,7 +300,7 @@ SWITCH_STANDARD_APP(socket_function)
}
static void close_socket(switch_socket_t ** sock)
static void close_socket(switch_socket_t **sock)
{
switch_mutex_lock(listen_list.sock_mutex);
if (*sock) {
@@ -320,7 +320,7 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_event_socket_shutdown)
close_socket(&listen_list.sock);
while(prefs.threads) {
while (prefs.threads) {
switch_yield(10000);
if (++sanity == 1000) {
break;
@@ -350,7 +350,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_event_socket_load)
return SWITCH_STATUS_SUCCESS;
}
static void add_listener(listener_t * listener)
static void add_listener(listener_t *listener)
{
/* add me to the listeners so I get events */
switch_mutex_lock(listen_list.mutex);
@@ -359,7 +359,7 @@ static void add_listener(listener_t * listener)
switch_mutex_unlock(listen_list.mutex);
}
static void remove_listener(listener_t * listener)
static void remove_listener(listener_t *listener)
{
listener_t *l, *last = NULL;
@@ -385,7 +385,7 @@ static void strip_cr(char *s)
}
}
static switch_status_t read_packet(listener_t * listener, switch_event_t **event, uint32_t timeout)
static switch_status_t read_packet(listener_t *listener, switch_event_t **event, uint32_t timeout)
{
switch_size_t mlen, bytes = 0;
char mbuf[2048] = "";
@@ -543,8 +543,8 @@ static switch_status_t read_packet(listener_t * listener, switch_event_t **event
switch_socket_send(listener->sock, listener->ebuf, &len);
switch_safe_free(listener->ebuf);
endloop:
endloop:
switch_event_destroy(&pevent);
}
}
@@ -569,7 +569,7 @@ struct api_command_struct {
switch_memory_pool_t *pool;
};
static void *SWITCH_THREAD_FUNC api_exec(switch_thread_t * thread, void *obj)
static void *SWITCH_THREAD_FUNC api_exec(switch_thread_t *thread, void *obj)
{
struct api_command_struct *acs = (struct api_command_struct *) obj;
@@ -630,7 +630,7 @@ static void *SWITCH_THREAD_FUNC api_exec(switch_thread_t * thread, void *obj)
switch_thread_rwlock_unlock(acs->listener->rwlock);
}
done:
done:
if (acs && acs->bg) {
switch_memory_pool_t *pool = acs->pool;
acs = NULL;
@@ -640,7 +640,7 @@ static void *SWITCH_THREAD_FUNC api_exec(switch_thread_t * thread, void *obj)
return NULL;
}
static switch_status_t parse_command(listener_t * listener, switch_event_t *event, char *reply, uint32_t reply_len)
static switch_status_t parse_command(listener_t *listener, switch_event_t *event, char *reply, uint32_t reply_len)
{
switch_status_t status = SWITCH_STATUS_SUCCESS;
char *cmd = switch_event_get_header(event, "command");
@@ -866,7 +866,7 @@ static switch_status_t parse_command(listener_t * listener, switch_event_t *even
switch_snprintf(reply, reply_len, "+OK Job-UUID: %s", acs->uuid_str);
switch_thread_create(&thread, thd_attr, api_exec, acs, acs->pool);
return SWITCH_STATUS_SUCCESS;
} else if (!strncasecmp(cmd, "log", 3)) {
@@ -950,7 +950,7 @@ static switch_status_t parse_command(listener_t * listener, switch_event_t *even
}
}
end:
end:
cur = next;
}
}
@@ -1039,7 +1039,7 @@ static switch_status_t parse_command(listener_t * listener, switch_event_t *even
}
}
done:
done:
if (event) {
switch_event_destroy(&event);
}
@@ -1051,7 +1051,7 @@ static switch_status_t parse_command(listener_t * listener, switch_event_t *even
return status;
}
static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t * thread, void *obj)
static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t *thread, void *obj)
{
listener_t *listener = (listener_t *) obj;
char buf[1024];
@@ -1071,13 +1071,13 @@ static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t * thread, void *obj
if (prefs.acl_count && listener->sa && !switch_strlen_zero(listener->remote_ip)) {
uint32_t x = 0;
for (x = 0 ; x < prefs.acl_count; x++) {
for (x = 0; x < prefs.acl_count; x++) {
if (!switch_check_network_list_ip(listener->remote_ip, prefs.acl[x])) {
const char message[] = "Access Denied, go away.\n";
int mlen = strlen(message);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "IP %s Rejected by acl %s\n", listener->remote_ip, prefs.acl[x]);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "IP %s Rejected by acl %s\n", listener->remote_ip, prefs.acl[x]);
switch_snprintf(buf, sizeof(buf), "Content-Type: rude/rejection\nContent-Length %d\n\n", mlen);
len = strlen(buf);
@@ -1203,7 +1203,7 @@ static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t * thread, void *obj
}
done:
done:
remove_listener(listener);
@@ -1234,7 +1234,7 @@ static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t * thread, void *obj
/* Create a thread for the socket and launch it */
static void launch_listener_thread(listener_t * listener)
static void launch_listener_thread(listener_t *listener)
{
switch_thread_t *thread;
switch_threadattr_t *thd_attr = NULL;
@@ -1333,7 +1333,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_event_socket_runtime)
goto sock_fail;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Socket up listening on %s:%u\n", prefs.ip, prefs.port);
break;
sock_fail:
sock_fail:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Socket Error! Could not listen on %s:%u\n", prefs.ip, prefs.port);
switch_yield(100000);
}
@@ -1348,7 +1348,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_event_socket_runtime)
switch_log_bind_logger(socket_logger, SWITCH_LOG_DEBUG);
for(;;) {
for (;;) {
if (switch_core_new_memory_pool(&listener_pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "OH OH no pool\n");
goto fail;
@@ -1396,11 +1396,11 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_event_socket_runtime)
}
for (x = 0 ; x < prefs.acl_count; x++) {
for (x = 0; x < prefs.acl_count; x++) {
switch_safe_free(prefs.acl[x]);
}
fail:
fail:
return SWITCH_STATUS_TERM;
}
@@ -77,7 +77,7 @@ static void event_handler(switch_event_t *event)
#define TTHREADS 500
static int THREADS = 0;
static void *torture_thread(switch_thread_t * thread, void *obj)
static void *torture_thread(switch_thread_t *thread, void *obj)
{
int y = 0;
int z = 0;
@@ -38,17 +38,17 @@
SWITCH_MODULE_LOAD_FUNCTION(mod_radius_cdr_load);
SWITCH_MODULE_DEFINITION(mod_radius_cdr, mod_radius_cdr_load, NULL, NULL);
static char cf[] = "mod_radius_cdr.conf";
static char my_dictionary[PATH_MAX];
static char my_seqfile[PATH_MAX];
static char * my_deadtime; /* 0 */
static char * my_timeout; /* 5 */
static char * my_retries; /* 3 */
static char my_servers[SERVER_MAX][255];
static char cf[] = "mod_radius_cdr.conf";
static char my_dictionary[PATH_MAX];
static char my_seqfile[PATH_MAX];
static char *my_deadtime; /* 0 */
static char *my_timeout; /* 5 */
static char *my_retries; /* 3 */
static char my_servers[SERVER_MAX][255];
static rc_handle * my_radius_init(void)
static rc_handle *my_radius_init(void)
{
rc_handle *rad_config;
rc_handle *rad_config;
rad_config = rc_new();
@@ -63,19 +63,17 @@ static rc_handle * my_radius_init(void)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error initializing radius config!\n");
rc_destroy(rad_config);
return NULL;
}
}
/* Some hardcoded ( for now ) defaults needed to initialize radius */
if (rc_add_config(rad_config, "auth_order", "radius", "mod_radius_cdr.c", 0) != 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"setting auth_order = radius failed\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "setting auth_order = radius failed\n");
rc_destroy(rad_config);
return NULL;
}
if (rc_add_config(rad_config, "seqfile", my_seqfile, "mod_radius_cdr.c", 0) != 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"setting seqfile = %s failed\n", my_seqfile);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "setting seqfile = %s failed\n", my_seqfile);
rc_destroy(rad_config);
return NULL;
}
@@ -92,37 +90,32 @@ static rc_handle * my_radius_init(void)
}
if (rc_add_config(rad_config, "dictionary", my_dictionary, cf, 0) != 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed setting dictionary = %s failed\n", my_dictionary);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed setting dictionary = %s failed\n", my_dictionary);
rc_destroy(rad_config);
return NULL;
}
if (rc_add_config(rad_config, "radius_deadtime", my_deadtime, cf, 0) != 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"setting radius_deadtime = %s failed\n", my_deadtime);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "setting radius_deadtime = %s failed\n", my_deadtime);
rc_destroy(rad_config);
return NULL;
}
if (rc_add_config(rad_config, "radius_timeout", my_timeout, cf, 0) != 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"setting radius_timeout = %s failed\n", my_timeout);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "setting radius_timeout = %s failed\n", my_timeout);
rc_destroy(rad_config);
return NULL;
}
if (rc_add_config(rad_config, "radius_retries", my_retries, cf, 0) != 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"setting radius_retries = %s failed\n", my_retries);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "setting radius_retries = %s failed\n", my_retries);
rc_destroy(rad_config);
return NULL;
return NULL;
}
/* Read the dictionary file(s) */
if (rc_read_dictionary(rad_config, rc_conf_str(rad_config, "dictionary")) != 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"reading dictionary file(s): %s\n", my_dictionary);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "reading dictionary file(s): %s\n", my_dictionary);
rc_destroy(rad_config);
return NULL;
}
@@ -132,20 +125,20 @@ static rc_handle * my_radius_init(void)
static switch_status_t my_on_routing(switch_core_session_t *session)
{
switch_xml_t cdr;
switch_xml_t cdr;
switch_channel_t *channel = switch_core_session_get_channel(session);
rc_handle *rad_config;
int retval = 0;
VALUE_PAIR *send = NULL;
uint32_t client_port = 0;
uint32_t status_type = PW_STATUS_START;
switch_time_t callstartdate = 0;
switch_time_t callanswerdate = 0;
switch_time_t callenddate = 0;
switch_time_t calltransferdate = 0;
rc_handle *rad_config;
int retval = 0;
VALUE_PAIR *send = NULL;
uint32_t client_port = 0;
uint32_t status_type = PW_STATUS_START;
switch_time_t callstartdate = 0;
switch_time_t callanswerdate = 0;
switch_time_t callenddate = 0;
switch_time_t calltransferdate = 0;
char *uuid_str;
char *uuid_str;
switch_time_exp_t tm;
char buffer[32];
@@ -162,7 +155,7 @@ static switch_status_t my_on_routing(switch_core_session_t *session)
uuid_str = switch_core_session_get_uuid(session);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "[mod_radius_cdr] Error Generating Data!\n");
return SWITCH_STATUS_TERM;
return SWITCH_STATUS_TERM;
}
/* Create the radius packet */
@@ -172,135 +165,122 @@ static switch_status_t my_on_routing(switch_core_session_t *session)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "[mod_radius_cdr] Failed setting Acct-Status-Type: Start\n");
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
if (rc_avpair_add(rad_config, &send, PW_ACCT_SESSION_ID, uuid_str, -1, 0) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "[mod_radius_cdr] Failed adding Acct-Session-ID: %s\n", uuid_str);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
/* Add VSAs */
if (channel) {
/*switch_call_cause_t cause;*/
switch_caller_profile_t *profile;
/*switch_call_cause_t cause; */
switch_caller_profile_t *profile;
/*
cause = switch_channel_get_cause(channel);
if (rc_avpair_add(rad_config, &send, PW_FS_HANGUPCAUSE, &cause, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Hangupcause: %d\n", cause);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
*/
cause = switch_channel_get_cause(channel);
if (rc_avpair_add(rad_config, &send, PW_FS_HANGUPCAUSE, &cause, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Hangupcause: %d\n", cause);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
*/
profile = switch_channel_get_caller_profile(channel);
if (profile) {
callstartdate = profile->times->created;
callanswerdate = profile->times->answered;
calltransferdate = profile->times->transferred;
callenddate = profile->times->hungup;
if (profile->username) {
if (rc_avpair_add(rad_config, &send, PW_USER_NAME, (void *)profile->username, -1, 0) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding User-Name: %s\n", profile->username);
if (rc_avpair_add(rad_config, &send, PW_USER_NAME, (void *) profile->username, -1, 0) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding User-Name: %s\n", profile->username);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->caller_id_number) {
if (rc_avpair_add(rad_config, &send, PW_FS_SRC, (void *)profile->caller_id_number, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Src: %s\n", profile->caller_id_number);
if (rc_avpair_add(rad_config, &send, PW_FS_SRC, (void *) profile->caller_id_number, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Src: %s\n", profile->caller_id_number);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->caller_id_name) {
if (rc_avpair_add(rad_config, &send, PW_FS_CLID, (void *)profile->caller_id_name, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-CLID: %s\n", profile->caller_id_name);
if (rc_avpair_add(rad_config, &send, PW_FS_CLID, (void *) profile->caller_id_name, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-CLID: %s\n", profile->caller_id_name);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->destination_number) {
if (rc_avpair_add(rad_config, &send, PW_FS_DST, (void *)profile->destination_number, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Dst: %s\n", profile->destination_number);
if (rc_avpair_add(rad_config, &send, PW_FS_DST, (void *) profile->destination_number, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Dst: %s\n", profile->destination_number);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->dialplan) {
if (rc_avpair_add(rad_config, &send, PW_FS_DIALPLAN, (void *)profile->dialplan, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Dialplan: %s\n", profile->dialplan);
if (rc_avpair_add(rad_config, &send, PW_FS_DIALPLAN, (void *) profile->dialplan, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Dialplan: %s\n", profile->dialplan);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->network_addr) {
if (rc_avpair_add(rad_config, &send, PW_FRAMED_IP_ADDRESS, (void *)profile->network_addr, -1, 0) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Framed-IP-Address: %s\n", profile->network_addr);
if (rc_avpair_add(rad_config, &send, PW_FRAMED_IP_ADDRESS, (void *) profile->network_addr, -1, 0) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Framed-IP-Address: %s\n", profile->network_addr);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->rdnis) {
if (rc_avpair_add(rad_config, &send, PW_FS_RDNIS, (void *)profile->rdnis, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-RDNIS: %s\n", profile->rdnis);
if (rc_avpair_add(rad_config, &send, PW_FS_RDNIS, (void *) profile->rdnis, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-RDNIS: %s\n", profile->rdnis);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->context) {
if (rc_avpair_add(rad_config, &send, PW_FS_CONTEXT, (void *)profile->context, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Context: %s\n", profile->context);
if (rc_avpair_add(rad_config, &send, PW_FS_CONTEXT, (void *) profile->context, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Context: %s\n", profile->context);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->ani) {
if (rc_avpair_add(rad_config, &send, PW_FS_ANI, (void *)profile->ani, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-ANI: %s\n", profile->ani);
if (rc_avpair_add(rad_config, &send, PW_FS_ANI, (void *) profile->ani, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-ANI: %s\n", profile->ani);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->aniii) {
if (rc_avpair_add(rad_config, &send, PW_FS_ANIII, (void *)profile->aniii, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-ANIII: %s\n", profile->aniii);
if (rc_avpair_add(rad_config, &send, PW_FS_ANIII, (void *) profile->aniii, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-ANIII: %s\n", profile->aniii);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->source) {
if (rc_avpair_add(rad_config, &send, PW_FS_SOURCE, (void *)profile->source, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Source: %s\n", profile->source);
if (rc_avpair_add(rad_config, &send, PW_FS_SOURCE, (void *) profile->source, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Source: %s\n", profile->source);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (callstartdate > 0) {
switch_time_exp_lt(&tm, callstartdate);
switch_snprintf(buffer, sizeof(buffer), "%04u-%02u-%02uT%02u:%02u:%02u.%06u%+03d%02d",
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec,
tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec, tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
if (rc_avpair_add(rad_config, &send, PW_FS_CALLSTARTDATE, &buffer, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Callstartdate: %s\n", buffer);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Callstartdate: %s\n", buffer);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
@@ -309,12 +289,10 @@ static switch_status_t my_on_routing(switch_core_session_t *session)
if (callanswerdate > 0) {
switch_time_exp_lt(&tm, callanswerdate);
switch_snprintf(buffer, sizeof(buffer), "%04u-%02u-%02uT%02u:%02u:%02u.%06u%+03d%02d",
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec,
tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec, tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
if (rc_avpair_add(rad_config, &send, PW_FS_CALLANSWERDATE, &buffer, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Callanswerdate: %s\n", buffer);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Callanswerdate: %s\n", buffer);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
@@ -323,12 +301,10 @@ static switch_status_t my_on_routing(switch_core_session_t *session)
if (calltransferdate > 0) {
switch_time_exp_lt(&tm, calltransferdate);
switch_snprintf(buffer, sizeof(buffer), "%04u-%02u-%02uT%02u:%02u:%02u.%06u%+03d%02d",
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec,
tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec, tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
if (rc_avpair_add(rad_config, &send, PW_FS_CALLTRANSFERDATE, &buffer, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Calltransferdate: %s\n", buffer);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Calltransferdate: %s\n", buffer);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
@@ -337,26 +313,23 @@ static switch_status_t my_on_routing(switch_core_session_t *session)
if (callenddate > 0) {
switch_time_exp_lt(&tm, callenddate);
switch_snprintf(buffer, sizeof(buffer), "%04u-%02u-%02uT%02u:%02u:%02u.%06u%+03d%02d",
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec,
tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec, tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
if (rc_avpair_add(rad_config, &send, PW_FS_CALLENDDATE, &buffer, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Callenddate: %s\n", buffer);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Callenddate: %s\n", buffer);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
if (profile->caller_extension && profile->caller_extension->last_application->application_name) {
if (rc_avpair_add(rad_config, &send, PW_FS_LASTAPP,
(void *)profile->caller_extension->last_application->application_name, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Lastapp: %s\n", profile->source);
if (rc_avpair_add(rad_config, &send, PW_FS_LASTAPP,
(void *) profile->caller_extension->last_application->application_name, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Lastapp: %s\n", profile->source);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "profile == NULL\n");
}
@@ -371,27 +344,27 @@ static switch_status_t my_on_routing(switch_core_session_t *session)
}
rc_avpair_free(send);
return(retval);
return (retval);
}
static switch_status_t my_on_hangup(switch_core_session_t *session)
{
switch_xml_t cdr;
switch_xml_t cdr;
switch_channel_t *channel = switch_core_session_get_channel(session);
rc_handle *rad_config;
int retval = 0;
VALUE_PAIR *send = NULL;
uint32_t client_port = 0;
uint32_t status_type = PW_STATUS_STOP;
switch_time_t callstartdate = 0;
switch_time_t callanswerdate = 0;
switch_time_t callenddate = 0;
switch_time_t calltransferdate = 0;
switch_time_t billusec = 0;
uint32_t billsec = 0;
char *uuid_str;
switch_time_exp_t tm;
rc_handle *rad_config;
int retval = 0;
VALUE_PAIR *send = NULL;
uint32_t client_port = 0;
uint32_t status_type = PW_STATUS_STOP;
switch_time_t callstartdate = 0;
switch_time_t callanswerdate = 0;
switch_time_t callenddate = 0;
switch_time_t calltransferdate = 0;
switch_time_t billusec = 0;
uint32_t billsec = 0;
char *uuid_str;
switch_time_exp_t tm;
char buffer[32] = "";
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "[mod_radius_cdr] Entering my_on_hangup\n");
@@ -407,7 +380,7 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
uuid_str = switch_core_session_get_uuid(session);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "[mod_radius_cdr] Error Generating Data!\n");
return SWITCH_STATUS_TERM;
return SWITCH_STATUS_TERM;
}
/* Create the radius packet */
@@ -417,19 +390,19 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Acct-Session-ID: %s\n", uuid_str);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
if (rc_avpair_add(rad_config, &send, PW_ACCT_SESSION_ID, uuid_str, -1, 0) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Acct-Session-ID: %s\n", uuid_str);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
/* Add VSAs */
if (channel) {
switch_call_cause_t cause;
switch_caller_profile_t *profile;
switch_call_cause_t cause;
switch_caller_profile_t *profile;
cause = switch_channel_get_cause(channel);
if (rc_avpair_add(rad_config, &send, PW_FS_HANGUPCAUSE, &cause, -1, PW_FS_PEC) == NULL) {
@@ -437,7 +410,7 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
profile = switch_channel_get_caller_profile(channel);
if (profile) {
@@ -449,16 +422,15 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
callanswerdate = profile->times->answered;
calltransferdate = profile->times->transferred;
callenddate = profile->times->hungup;
if (switch_channel_test_flag(channel,CF_ANSWERED)) {
if (switch_channel_test_flag(channel, CF_ANSWERED)) {
if (callstartdate && callanswerdate) {
if (callenddate)
billusec = callenddate - callanswerdate;
else if (calltransferdate)
billusec = calltransferdate - callanswerdate;
}
}
else if (switch_channel_test_flag(channel,CF_TRANSFER)) {
} else if (switch_channel_test_flag(channel, CF_TRANSFER)) {
if (callanswerdate && calltransferdate)
billusec = calltransferdate - callanswerdate;
}
@@ -467,105 +439,92 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "[mod_radius_cdr] Finished calculating billable time\n");
if (profile->username) {
if (rc_avpair_add(rad_config, &send, PW_USER_NAME, (void *)profile->username, -1, 0) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding User-Name: %s\n", profile->username);
if (rc_avpair_add(rad_config, &send, PW_USER_NAME, (void *) profile->username, -1, 0) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding User-Name: %s\n", profile->username);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->caller_id_number) {
if (rc_avpair_add(rad_config, &send, PW_FS_SRC, (void *)profile->caller_id_number, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Src: %s\n", profile->caller_id_number);
if (rc_avpair_add(rad_config, &send, PW_FS_SRC, (void *) profile->caller_id_number, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Src: %s\n", profile->caller_id_number);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->caller_id_name) {
if (rc_avpair_add(rad_config, &send, PW_FS_CLID, (void *)profile->caller_id_name, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-CLID: %s\n", profile->caller_id_name);
if (rc_avpair_add(rad_config, &send, PW_FS_CLID, (void *) profile->caller_id_name, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-CLID: %s\n", profile->caller_id_name);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->destination_number) {
if (rc_avpair_add(rad_config, &send, PW_FS_DST, (void *)profile->destination_number, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Dst: %s\n", profile->destination_number);
if (rc_avpair_add(rad_config, &send, PW_FS_DST, (void *) profile->destination_number, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Dst: %s\n", profile->destination_number);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->dialplan) {
if (rc_avpair_add(rad_config, &send, PW_FS_DIALPLAN, (void *)profile->dialplan, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Dialplan: %s\n", profile->dialplan);
if (rc_avpair_add(rad_config, &send, PW_FS_DIALPLAN, (void *) profile->dialplan, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Dialplan: %s\n", profile->dialplan);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->network_addr) {
if (rc_avpair_add(rad_config, &send, PW_FRAMED_IP_ADDRESS, (void *)profile->network_addr, -1, 0) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Framed-IP-Address: %s\n", profile->network_addr);
if (rc_avpair_add(rad_config, &send, PW_FRAMED_IP_ADDRESS, (void *) profile->network_addr, -1, 0) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Framed-IP-Address: %s\n", profile->network_addr);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->rdnis) {
if (rc_avpair_add(rad_config, &send, PW_FS_RDNIS, (void *)profile->rdnis, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-RDNIS: %s\n", profile->rdnis);
if (rc_avpair_add(rad_config, &send, PW_FS_RDNIS, (void *) profile->rdnis, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-RDNIS: %s\n", profile->rdnis);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->context) {
if (rc_avpair_add(rad_config, &send, PW_FS_CONTEXT, (void *)profile->context, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Context: %s\n", profile->context);
if (rc_avpair_add(rad_config, &send, PW_FS_CONTEXT, (void *) profile->context, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Context: %s\n", profile->context);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->ani) {
if (rc_avpair_add(rad_config, &send, PW_FS_ANI, (void *)profile->ani, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-ANI: %s\n", profile->ani);
if (rc_avpair_add(rad_config, &send, PW_FS_ANI, (void *) profile->ani, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-ANI: %s\n", profile->ani);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->aniii) {
if (rc_avpair_add(rad_config, &send, PW_FS_ANIII, (void *)profile->aniii, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-ANIII: %s\n", profile->aniii);
if (rc_avpair_add(rad_config, &send, PW_FS_ANIII, (void *) profile->aniii, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-ANIII: %s\n", profile->aniii);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->source) {
if (rc_avpair_add(rad_config, &send, PW_FS_SOURCE, (void *)profile->source, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Source: %s\n", profile->source);
if (rc_avpair_add(rad_config, &send, PW_FS_SOURCE, (void *) profile->source, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Source: %s\n", profile->source);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (profile->caller_extension && profile->caller_extension->last_application->application_name) {
if (rc_avpair_add(rad_config, &send, PW_FS_LASTAPP,
(void *)profile->caller_extension->last_application->application_name, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Lastapp: %s\n", profile->source);
if (rc_avpair_add(rad_config, &send, PW_FS_LASTAPP,
(void *) profile->caller_extension->last_application->application_name, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Lastapp: %s\n", profile->source);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
}
if (rc_avpair_add(rad_config, &send, PW_FS_BILLUSEC, &billusec, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Billusec: %u\n", (uint32_t)billusec);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Billusec: %u\n", (uint32_t) billusec);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
@@ -573,12 +532,10 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
if (callstartdate > 0) {
switch_time_exp_lt(&tm, callstartdate);
switch_snprintf(buffer, sizeof(buffer), "%04u-%02u-%02uT%02u:%02u:%02u.%06u%+03d%02d",
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec,
tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec, tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
if (rc_avpair_add(rad_config, &send, PW_FS_CALLSTARTDATE, &buffer, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Callstartdate: %s\n", buffer);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Callstartdate: %s\n", buffer);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
@@ -587,12 +544,10 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
if (callanswerdate > 0) {
switch_time_exp_lt(&tm, callanswerdate);
switch_snprintf(buffer, sizeof(buffer), "%04u-%02u-%02uT%02u:%02u:%02u.%06u%+03d%02d",
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec,
tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec, tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
if (rc_avpair_add(rad_config, &send, PW_FS_CALLANSWERDATE, &buffer, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Callanswerdate: %s\n", buffer);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Callanswerdate: %s\n", buffer);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
@@ -601,12 +556,10 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
if (calltransferdate > 0) {
switch_time_exp_lt(&tm, calltransferdate);
switch_snprintf(buffer, sizeof(buffer), "%04u-%02u-%02uT%02u:%02u:%02u.%06u%+03d%02d",
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec,
tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec, tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
if (rc_avpair_add(rad_config, &send, PW_FS_CALLTRANSFERDATE, &buffer, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Calltransferdate: %s\n", buffer);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Calltransferdate: %s\n", buffer);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
@@ -615,25 +568,22 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
if (callenddate > 0) {
switch_time_exp_lt(&tm, callenddate);
switch_snprintf(buffer, sizeof(buffer), "%04u-%02u-%02uT%02u:%02u:%02u.%06u%+03d%02d",
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec,
tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec, tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
if (rc_avpair_add(rad_config, &send, PW_FS_CALLENDDATE, &buffer, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Freeswitch-Callenddate: %s\n", buffer);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Callenddate: %s\n", buffer);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
}
if (rc_avpair_add(rad_config, &send, PW_ACCT_SESSION_TIME, &billsec, -1, 0) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"failed adding Acct-Session-Time: %u\n", billsec);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Acct-Session-Time: %u\n", billsec);
rc_destroy(rad_config);
return SWITCH_STATUS_TERM;
}
} else { /* no profile, can't create data to send */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "profile == NULL\n");
} else { /* no profile, can't create data to send */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "profile == NULL\n");
}
}
@@ -646,57 +596,52 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
}
rc_avpair_free(send);
return(retval);
return (retval);
}
static switch_status_t load_config(void)
{
switch_xml_t cfg, xml, settings, param;
switch_xml_t cfg, xml, settings, param;
int num_servers = 0;
my_timeout = "5";
my_retries = "3";
my_deadtime = "0";
strncpy(my_seqfile, "/var/run/radius.seq", PATH_MAX-1);
strncpy(my_dictionary, "/usr/local/freeswitch/conf/radius/dictionary", PATH_MAX-1);
strncpy(my_seqfile, "/var/run/radius.seq", PATH_MAX - 1);
strncpy(my_dictionary, "/usr/local/freeswitch/conf/radius/dictionary", PATH_MAX - 1);
for( int i = 0; i < SERVER_MAX; i++ ) {
for (int i = 0; i < SERVER_MAX; i++) {
my_servers[i][0] = '\0';
}
if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
return SWITCH_STATUS_TERM;
}
if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
return SWITCH_STATUS_TERM;
}
if ((settings = switch_xml_child(cfg, "settings"))) {
for (param = switch_xml_child(settings, "param"); param; param = param->next) {
if ((settings = switch_xml_child(cfg, "settings"))) {
for (param = switch_xml_child(settings, "param"); param; param = param->next) {
char *var = (char *) switch_xml_attr_soft(param, "name");
char *val = (char *) switch_xml_attr_soft(param, "value");
if (!strcmp(var, "acctserver")) {
if (num_servers < SERVER_MAX) {
strncpy(my_servers[num_servers],val,255-1);
strncpy(my_servers[num_servers], val, 255 - 1);
num_servers++;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"you can only specify %d radius servers, ignoring excess server entry\n", SERVER_MAX);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"you can only specify %d radius servers, ignoring excess server entry\n", SERVER_MAX);
}
}
else if (!strcmp(var, "dictionary")) {
strncpy(my_dictionary,val,PATH_MAX-1);
}
else if (!strcmp(var, "seqfile")) {
strncpy(my_seqfile,val,PATH_MAX-1);
}
else if (!strcmp(var, "radius_timeout")) {
} else if (!strcmp(var, "dictionary")) {
strncpy(my_dictionary, val, PATH_MAX - 1);
} else if (!strcmp(var, "seqfile")) {
strncpy(my_seqfile, val, PATH_MAX - 1);
} else if (!strcmp(var, "radius_timeout")) {
my_timeout = strdup(val);
}
else if (!strcmp(var, "radius_retries")) {
} else if (!strcmp(var, "radius_retries")) {
my_retries = strdup(val);
}
else if (!strcmp(var, "radius_deadtime")) {
} else if (!strcmp(var, "radius_deadtime")) {
my_deadtime = strdup(val);
}
}
@@ -705,8 +650,7 @@ static switch_status_t load_config(void)
switch_xml_free(xml);
if (num_servers < 1) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"you must specify at least 1 radius server\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "you must specify at least 1 radius server\n");
return SWITCH_STATUS_TERM;
}
@@ -726,8 +670,8 @@ static const switch_state_handler_table_t state_handlers = {
SWITCH_MODULE_LOAD_FUNCTION(mod_radius_cdr_load)
{
if (load_config() != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_TERM;
}
return SWITCH_STATUS_TERM;
}
/* test global state handlers */
switch_core_add_state_handler(&state_handlers);
@@ -50,7 +50,7 @@ struct local_stream_context {
struct local_stream_source *source;
switch_mutex_t *audio_mutex;
switch_buffer_t *audio_buffer;
int err;
int err;
const char *file;
const char *func;
int line;
@@ -86,18 +86,18 @@ static int do_rand(void)
double r;
int index;
srand(getpid() + ++S);
r = ((double)rand() / ((double)(RAND_MAX)+(double)(1)));
index = (int)(r * 9) + 1;
r = ((double) rand() / ((double) (RAND_MAX) + (double) (1)));
index = (int) (r * 9) + 1;
return index;
}
static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void *obj)
{
local_stream_source_t *source = obj;
switch_file_handle_t fh = {0};
switch_file_handle_t fh = { 0 };
local_stream_context_t *cp;
char file_buf[128] = "", path_buf[512] = "";
switch_timer_t timer = {0};
switch_timer_t timer = { 0 };
int fd = -1;
switch_buffer_t *audio_buffer;
switch_byte_t *dist_buf;
@@ -110,12 +110,12 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void
switch_buffer_create_dynamic(&audio_buffer, 1024, source->prebuf + 10, 0);
dist_buf = switch_core_alloc(source->pool, source->prebuf + 10);
if (source->shuffle) {
skip = do_rand();
}
while(RUNNING) {
while (RUNNING) {
const char *fname;
if (switch_dir_open(&source->dir_handle, source->location, source->pool) != SWITCH_STATUS_SUCCESS) {
@@ -125,15 +125,14 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void
switch_yield(1000000);
while(RUNNING) {
while (RUNNING) {
switch_size_t olen;
uint8_t abuf[SWITCH_RECOMMENDED_BUFFER_SIZE] = {0};
uint8_t abuf[SWITCH_RECOMMENDED_BUFFER_SIZE] = { 0 };
if (fd > -1) {
char *p;
if (switch_fd_read_line(fd, path_buf, sizeof(path_buf))) {
if ((p = strchr(path_buf, '\r')) ||
(p = strchr(path_buf, '\n'))) {
if ((p = strchr(path_buf, '\r')) || (p = strchr(path_buf, '\n'))) {
*p = '\0';
}
} else {
@@ -164,20 +163,18 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void
fname = path_buf;
fh.prebuf = source->prebuf;
if (switch_core_file_open(&fh,
(char *)fname,
source->channels,
source->rate,
SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
(char *) fname,
source->channels, source->rate, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open %s\n", fname);
switch_yield(1000000);
continue;
}
source->rate = fh.samplerate;
source->samples = switch_samples_per_frame(fh.native_rate, source->interval);
if (switch_core_timer_init(&timer, source->timer_name, source->interval, source->samples, source->pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Can't start timer.\n");
switch_dir_close(source->dir_handle);
@@ -196,11 +193,11 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void
switch_buffer_write(audio_buffer, abuf, olen * 2);
used = switch_buffer_inuse(audio_buffer);
if (used >= source->prebuf || (source->total && used > source->samples * 2)) {
used = switch_buffer_read(audio_buffer, dist_buf, source->samples * 2);
if (source->total) {
switch_mutex_lock(source->mutex);
for (cp = source->context_list; cp; cp = cp->next) {
if (switch_test_flag(cp->handle, SWITCH_FILE_CALLBACK)) {
@@ -208,7 +205,8 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void
}
switch_mutex_lock(cp->audio_mutex);
if (switch_buffer_inuse(cp->audio_buffer) > source->samples * 768) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Leaking stream handle! [%s() %s:%d]\n", cp->func, cp->file, cp->line);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Leaking stream handle! [%s() %s:%d]\n", cp->func, cp->file,
cp->line);
switch_buffer_zero(cp->audio_buffer);
} else {
switch_buffer_write(cp->audio_buffer, dist_buf, used);
@@ -230,13 +228,13 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void
source->dir_handle = NULL;
}
done:
done:
switch_buffer_destroy(&audio_buffer);
if (fd > -1) {
close(fd);
}
switch_core_destroy_memory_pool(&source->pool);
return NULL;
@@ -248,12 +246,12 @@ static switch_status_t local_stream_file_open(switch_file_handle_t *handle, cons
local_stream_source_t *source;
char *alt_path = NULL;
switch_status_t status = SWITCH_STATUS_SUCCESS;
if (switch_test_flag(handle, SWITCH_FILE_FLAG_WRITE)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "This format does not support writing!\n");
return SWITCH_STATUS_FALSE;
}
alt_path = switch_mprintf("%s/%d", path, handle->samplerate);
switch_mutex_lock(globals.mutex);
@@ -273,7 +271,7 @@ static switch_status_t local_stream_file_open(switch_file_handle_t *handle, cons
if ((context = switch_core_alloc(handle->memory_pool, sizeof(*context))) == 0) {
status = SWITCH_STATUS_MEMERR;
goto end;
}
}
handle->samples = 0;
handle->samplerate = source->rate;
@@ -285,14 +283,14 @@ static switch_status_t local_stream_file_open(switch_file_handle_t *handle, cons
handle->private_info = context;
handle->interval = source->interval;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Opening Stream [%s] %dhz\n", path, handle->samplerate);
switch_mutex_init(&context->audio_mutex, SWITCH_MUTEX_NESTED, handle->memory_pool);
if (switch_buffer_create_dynamic(&context->audio_buffer, 512, 1024, 0) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error!\n");
status = SWITCH_STATUS_MEMERR;
goto end;
}
context->source = source;
context->file = handle->file;
context->func = handle->func;
@@ -304,7 +302,7 @@ static switch_status_t local_stream_file_open(switch_file_handle_t *handle, cons
source->total++;
switch_mutex_unlock(source->mutex);
end:
end:
switch_safe_free(alt_path);
return status;
}
@@ -328,29 +326,29 @@ static switch_status_t local_stream_file_close(switch_file_handle_t *handle)
context->source->total--;
switch_mutex_unlock(context->source->mutex);
switch_buffer_destroy(&context->audio_buffer);
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t local_stream_file_read(switch_file_handle_t *handle, void *data, size_t *len)
{
local_stream_context_t *context = handle->private_info;
switch_size_t bytes = 0;
size_t need = *len * 2;
local_stream_context_t *context = handle->private_info;
switch_size_t bytes = 0;
size_t need = *len * 2;
switch_mutex_lock(context->audio_mutex);
if ((bytes = switch_buffer_read(context->audio_buffer, data, need))) {
*len = bytes / 2;
} else {
if (need > 2560) {
need = 2560;
}
memset(data, 255, need);
*len = need / 2;
}
switch_mutex_unlock(context->audio_mutex);
handle->sample_count += *len;
return SWITCH_STATUS_SUCCESS;
switch_mutex_lock(context->audio_mutex);
if ((bytes = switch_buffer_read(context->audio_buffer, data, need))) {
*len = bytes / 2;
} else {
if (need > 2560) {
need = 2560;
}
memset(data, 255, need);
*len = need / 2;
}
switch_mutex_unlock(context->audio_mutex);
handle->sample_count += *len;
return SWITCH_STATUS_SUCCESS;
}
/* Registration */
@@ -374,7 +372,7 @@ static void launch_threads(void)
for (directory = switch_xml_child(cfg, "directory"); directory; directory = directory->next) {
char *path = (char *) switch_xml_attr(directory, "path");
char *name = (char *) switch_xml_attr(directory, "name");
if (!(name && path)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "invalid config!\n");
continue;
@@ -388,7 +386,7 @@ static void launch_threads(void)
source = switch_core_alloc(pool, sizeof(*source));
assert(source != NULL);
source->pool = pool;
source->name = switch_core_strdup(source->pool, name);
source->location = switch_core_strdup(source->pool, path);
source->rate = 8000;
@@ -396,7 +394,7 @@ static void launch_threads(void)
source->channels = 1;
source->timer_name = "soft";
source->prebuf = DEFAULT_PREBUFFER_SIZE;
for (param = switch_xml_child(directory, "param"); param; param = param->next) {
char *var = (char *) switch_xml_attr_soft(param, "name");
char *val = (char *) switch_xml_attr_soft(param, "value");
@@ -416,7 +414,7 @@ static void launch_threads(void)
} else if (!strcasecmp(var, "channels")) {
int tmp = atoi(val);
if (tmp == 1 || tmp == 2) {
source->channels = (uint8_t)tmp;
source->channels = (uint8_t) tmp;
}
} else if (!strcasecmp(var, "interval")) {
int tmp = atoi(val);
@@ -424,19 +422,19 @@ static void launch_threads(void)
source->interval = tmp;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
"Interval must be multipe of 10 and less than %d, Using default of 20\n", SWITCH_MAX_INTERVAL);
"Interval must be multipe of 10 and less than %d, Using default of 20\n", SWITCH_MAX_INTERVAL);
}
} else if (!strcasecmp(var, "timer-name")) {
source->timer_name = switch_core_strdup(source->pool, val);
}
}
source->samples = switch_samples_per_frame(source->rate, source->interval);
switch_core_hash_insert(globals.source_hash, source->name, source);
switch_mutex_init(&source->mutex, SWITCH_MUTEX_NESTED, source->pool);
switch_threadattr_create(&thd_attr, source->pool);
switch_threadattr_detach_set(thd_attr, 1);
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
@@ -450,7 +448,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_local_stream_load)
{
switch_file_interface_t *file_interface;
supported_formats[0] = "local_stream";
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
file_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_FILE_INTERFACE);
file_interface->interface_name = modname;
@@ -463,7 +461,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_local_stream_load)
switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, pool);
switch_core_hash_init(&globals.source_hash, pool);
launch_threads();
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
+5 -5
View File
@@ -37,7 +37,7 @@ static inline real find_pow(int i)
{
return (i > 0 && i < 8207) ? __ispow[i] : 1;
}
@@ -854,9 +854,9 @@ static int III_dequantize_sample(struct mpstr *mp, real xr[SBLIMIT][SSLIMIT], in
if (!mc) {
unsigned sanity;
mc = *m++;
if ((unsigned)*scf < 100 && (unsigned)*pretab < 100) {
if ((unsigned) *scf < 100 && (unsigned) *pretab < 100) {
sanity = (((*scf++) + (*pretab++)) << shift);
//v = gr_info->pow2gain[((*scf++) + (*pretab++)) << shift];
if (sanity < 100) {
v = gr_info->pow2gain[sanity];
@@ -993,8 +993,8 @@ static int III_dequantize_sample(struct mpstr *mp, real xr[SBLIMIT][SSLIMIT], in
#if 0
static int III_dequantize_sample_ms(real xr[2][SBLIMIT][SSLIMIT], int *scf, struct gr_info_s *gr_info, int sfreq, int part2bits)
{ma
int shift = 1 + gr_info->scalefac_scale;
{
ma int shift = 1 + gr_info->scalefac_scale;
real *xrpnt = (real *) xr[1];
real *xr0pnt = (real *) xr[0];
int l[3], l3;
File diff suppressed because it is too large. Load diff
+4 -5
View File
@@ -147,7 +147,7 @@ static switch_status_t sndfile_file_open(switch_file_handle_t *handle, const cha
alt_len = strlen(path) + 10;
switch_zmalloc(alt_path, alt_len);
switch_copy_string(alt_path, path, alt_len);
if ((last = strrchr(alt_path, '/'))) {
next = ++last;
@@ -177,7 +177,6 @@ static switch_status_t sndfile_file_open(switch_file_handle_t *handle, const cha
goto end;
}
}
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Opening File [%s] rate %dhz\n", path, context->sfinfo.samplerate);
handle->samples = (unsigned int) context->sfinfo.frames;
handle->samplerate = context->sfinfo.samplerate;
@@ -188,8 +187,8 @@ static switch_status_t sndfile_file_open(switch_file_handle_t *handle, const cha
handle->speed = 0;
handle->private_info = context;
end:
end:
switch_safe_free(alt_path);
switch_safe_free(ldup);
@@ -334,7 +333,7 @@ static switch_status_t setup_formats(void)
char *p;
struct format_map *map = switch_core_permanent_alloc(sizeof(*map));
switch_assert(map);
map->ext = switch_core_permanent_strdup(info.extension);
map->uext = switch_core_permanent_strdup(info.extension);
map->format = info.format;
@@ -79,9 +79,9 @@ static switch_status_t tone_stream_file_open(switch_file_handle_t *handle, const
}
teletone_init_session(&ts, 0, teletone_handler, audio_buffer);
ts.rate = handle->samplerate;
ts.channels = 1;
ts.rate = handle->samplerate;
ts.channels = 1;
if (!strncasecmp(tonespec, "path=", 5)) {
tmp = tonespec + 5;
if ((fd = open(tmp, O_RDONLY)) < 0) {
@@ -89,7 +89,7 @@ static switch_status_t tone_stream_file_open(switch_file_handle_t *handle, const
return SWITCH_STATUS_FALSE;
}
while((len = switch_fd_read_line(fd, buf, sizeof(buf)))) {
while ((len = switch_fd_read_line(fd, buf, sizeof(buf)))) {
teletone_run(&ts, buf);
}
close(fd);
@@ -99,7 +99,7 @@ static switch_status_t tone_stream_file_open(switch_file_handle_t *handle, const
}
teletone_destroy_session(&ts);
handle->private_info = audio_buffer;
return SWITCH_STATUS_SUCCESS;
@@ -108,7 +108,7 @@ static switch_status_t tone_stream_file_open(switch_file_handle_t *handle, const
static switch_status_t tone_stream_file_close(switch_file_handle_t *handle)
{
switch_buffer_t *audio_buffer = handle->private_info;
switch_buffer_destroy(&audio_buffer);
return SWITCH_STATUS_SUCCESS;
}
@@ -117,7 +117,7 @@ static switch_status_t tone_stream_file_read(switch_file_handle_t *handle, void
{
switch_buffer_t *audio_buffer = handle->private_info;
switch_size_t bytes;
if ((bytes = switch_buffer_read_loop(audio_buffer, data, *len * 2)) <= 0) {
*len = 0;
return SWITCH_STATUS_FALSE;
@@ -135,7 +135,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_tone_stream_load)
{
switch_file_interface_t *file_interface;
supported_formats[0] = "tone_stream";
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
file_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_FILE_INTERFACE);
file_interface->interface_name = modname;
+41 -38
View File
@@ -3,19 +3,19 @@
#include "freeswitch_lua.h"
using namespace LUA;
Session::Session() : CoreSession()
Session::Session():CoreSession()
{
cb_function = cb_arg = hangup_func_str = hangup_func_arg = NULL;
hh = mark = 0;
}
Session::Session(char *uuid) : CoreSession(uuid)
Session::Session(char *uuid):CoreSession(uuid)
{
cb_function = cb_arg = hangup_func_str = hangup_func_arg = NULL;
hh = mark = 0;
}
Session::Session(switch_core_session_t *new_session) : CoreSession(new_session)
Session::Session(switch_core_session_t *new_session):CoreSession(new_session)
{
cb_function = cb_arg = hangup_func_str = hangup_func_arg = NULL;
hh = mark = 0;
@@ -30,25 +30,25 @@ Session::~Session()
}
free(hangup_func_str);
}
switch_safe_free(hangup_func_arg);
switch_safe_free(cb_function);
switch_safe_free(cb_arg);
}
bool Session::begin_allow_threads()
bool Session::begin_allow_threads()
{
do_hangup_hook();
return true;
}
bool Session::end_allow_threads()
bool Session::end_allow_threads()
{
do_hangup_hook();
return true;
}
void Session::setLUA(lua_State *state)
void Session::setLUA(lua_State * state)
{
L = state;
}
@@ -56,30 +56,31 @@ void Session::setLUA(lua_State *state)
lua_State *Session::getLUA()
{
if (!L) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Doh!\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Doh!\n");
}
return L;
}
bool Session::ready() {
bool Session::ready()
{
bool r;
sanity_check(false);
sanity_check(false);
r = switch_channel_ready(channel) != 0;
do_hangup_hook();
return r;
}
void Session::check_hangup_hook()
void Session::check_hangup_hook()
{
if (hangup_func_str && (hook_state == CS_HANGUP || hook_state == CS_ROUTING)) {
hh++;
}
}
void Session::do_hangup_hook()
void Session::do_hangup_hook()
{
if (hh && !mark) {
const char *err = NULL;
@@ -90,25 +91,25 @@ void Session::do_hangup_hook()
return;
}
lua_getfield(L, LUA_GLOBALSINDEX, (char *)hangup_func_str);
lua_getfield(L, LUA_GLOBALSINDEX, (char *) hangup_func_str);
lua_pushstring(L, hook_state == CS_HANGUP ? "hangup" : "transfer");
if (hangup_func_arg) {
lua_getfield(L, LUA_GLOBALSINDEX, (char *)hangup_func_arg);
lua_getfield(L, LUA_GLOBALSINDEX, (char *) hangup_func_arg);
arg_count++;
}
lua_call(L, arg_count, 1);
err = lua_tostring(L, -1);
if (!switch_strlen_zero(err)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s\n", err);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s\n", err);
}
}
}
static switch_status_t lua_hanguphook(switch_core_session_t *session_hungup)
static switch_status_t lua_hanguphook(switch_core_session_t *session_hungup)
{
switch_channel_t *channel = switch_core_session_get_channel(session_hungup);
CoreSession *coresession = NULL;
@@ -125,13 +126,14 @@ static switch_status_t lua_hanguphook(switch_core_session_t *session_hungup)
}
void Session::setHangupHook(char *func, char *arg) {
void Session::setHangupHook(char *func, char *arg)
{
sanity_check_noreturn;
switch_safe_free(hangup_func_str);
switch_safe_free(hangup_func_arg);
if (func) {
hangup_func_str = strdup(func);
if (!switch_strlen_zero(arg)) {
@@ -143,7 +145,8 @@ void Session::setHangupHook(char *func, char *arg) {
}
}
void Session::setInputCallback(char *cbfunc, char *funcargs) {
void Session::setInputCallback(char *cbfunc, char *funcargs)
{
sanity_check_noreturn;
@@ -156,15 +159,15 @@ void Session::setInputCallback(char *cbfunc, char *funcargs) {
if (funcargs) {
cb_arg = strdup(funcargs);
}
args.buf = this;
switch_channel_set_private(channel, "CoreSession", this);
args.input_callback = dtmf_callback;
args.input_callback = dtmf_callback;
ap = &args;
}
switch_status_t Session::run_dtmf_callback(void *input, switch_input_type_t itype)
switch_status_t Session::run_dtmf_callback(void *input, switch_input_type_t itype)
{
const char *ret;
@@ -173,27 +176,27 @@ switch_status_t Session::run_dtmf_callback(void *input, switch_input_type_t ityp
}
switch (itype) {
case SWITCH_INPUT_TYPE_DTMF:
case SWITCH_INPUT_TYPE_DTMF:
{
switch_dtmf_t *dtmf = (switch_dtmf_t *) input;
char str[2] = "";
int arg_count = 2;
lua_getfield(L, LUA_GLOBALSINDEX, (char *)cb_function);
lua_pushstring(L, "dtmf");
lua_newtable(L);
lua_getfield(L, LUA_GLOBALSINDEX, (char *) cb_function);
lua_pushstring(L, "dtmf");
lua_newtable(L);
lua_pushstring(L, "digit");
str[0] = dtmf->digit;
lua_pushstring(L, str);
lua_rawset(L, -3);
lua_pushstring(L, "duration");
lua_pushnumber(L, dtmf->duration);
lua_rawset(L, -3);
if (cb_arg) {
lua_getfield(L, LUA_GLOBALSINDEX, (char *)cb_arg);
lua_getfield(L, LUA_GLOBALSINDEX, (char *) cb_arg);
arg_count++;
}
@@ -201,30 +204,30 @@ switch_status_t Session::run_dtmf_callback(void *input, switch_input_type_t ityp
ret = lua_tostring(L, -1);
lua_pop(L, 1);
return process_callback_result((char *)ret);
return process_callback_result((char *) ret);
}
break;
case SWITCH_INPUT_TYPE_EVENT:
case SWITCH_INPUT_TYPE_EVENT:
{
switch_event_t *event = (switch_event_t *) input;
int arg_count = 2;
lua_getfield(L, LUA_GLOBALSINDEX, (char *)cb_function);
lua_getfield(L, LUA_GLOBALSINDEX, (char *) cb_function);
lua_pushstring(L, "event");
mod_lua_conjure_event(L, event, "__Input_Event__", 1);
lua_getfield(L, LUA_GLOBALSINDEX, "__Input_Event__");
if (cb_arg) {
lua_getfield(L, LUA_GLOBALSINDEX, (char *)cb_arg);
lua_getfield(L, LUA_GLOBALSINDEX, (char *) cb_arg);
arg_count++;
}
lua_call(L, 2, 1);
ret = lua_tostring(L, -1);
ret = lua_tostring(L, -1);
lua_pop(L, 1);
return process_callback_result((char *)ret);
return process_callback_result((char *) ret);
}
break;
}
+43 -44
View File
@@ -45,23 +45,23 @@ static struct {
char *xml_handler;
} globals;
int luaopen_freeswitch(lua_State* L);
int luaopen_freeswitch(lua_State * L);
static int panic (lua_State *L)
static int panic(lua_State * L)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "unprotected error in call to Lua API (%s)\n",
lua_tostring(L, -1));
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "unprotected error in call to Lua API (%s)\n", lua_tostring(L, -1));
return 0;
}
static void lua_uninit(lua_State *L)
static void lua_uninit(lua_State * L)
{
lua_gc(L, LUA_GCCOLLECT, 0);
lua_close(L);
}
static int traceback (lua_State *L) {
static int traceback(lua_State * L)
{
lua_getfield(L, LUA_GLOBALSINDEX, "debug");
if (!lua_istable(L, -1)) {
lua_pop(L, 1);
@@ -72,30 +72,32 @@ static int traceback (lua_State *L) {
lua_pop(L, 2);
return 1;
}
lua_pushvalue(L, 1); /* pass error message */
lua_pushinteger(L, 2); /* skip this function and traceback */
lua_call(L, 2, 1); /* call debug.traceback */
lua_pushvalue(L, 1); /* pass error message */
lua_pushinteger(L, 2); /* skip this function and traceback */
lua_call(L, 2, 1); /* call debug.traceback */
return 1;
}
static int docall (lua_State *L, int narg, int clear) {
static int docall(lua_State * L, int narg, int clear)
{
int status;
int base = lua_gettop(L) - narg; /* function index */
lua_pushcfunction(L, traceback); /* push traceback function */
lua_insert(L, base); /* put it under chunk and args */
int base = lua_gettop(L) - narg; /* function index */
lua_pushcfunction(L, traceback); /* push traceback function */
lua_insert(L, base); /* put it under chunk and args */
status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base);
lua_remove(L, base); /* remove traceback function */
lua_remove(L, base); /* remove traceback function */
/* force a complete garbage collection in case of errors */
if (status != 0) lua_gc(L, LUA_GCCOLLECT, 0);
if (status != 0)
lua_gc(L, LUA_GCCOLLECT, 0);
return status;
}
static lua_State *lua_init(void)
static lua_State *lua_init(void)
{
lua_State *L = lua_open();
int error = 0;
@@ -108,12 +110,12 @@ static lua_State *lua_init(void)
lua_gc(L, LUA_GCRESTART, 0);
lua_atpanic(L, panic);
error = luaL_loadbuffer(L, buff, strlen(buff), "line") || docall(L, 0, 1);
}
}
return L;
}
static int lua_parse_and_execute(lua_State *L, char *input_code)
static int lua_parse_and_execute(lua_State * L, char *input_code)
{
int error = 0;
@@ -124,7 +126,7 @@ static int lua_parse_and_execute(lua_State *L, char *input_code)
if (*input_code == '~') {
char *buff = input_code + 1;
error = luaL_loadbuffer(L, buff, strlen(buff), "line") || docall(L, 0, 1); //lua_pcall(L, 0, 0, 0);
error = luaL_loadbuffer(L, buff, strlen(buff), "line") || docall(L, 0, 1); //lua_pcall(L, 0, 0, 0);
} else {
char *args = strchr(input_code, ' ');
if (args) {
@@ -136,13 +138,13 @@ static int lua_parse_and_execute(lua_State *L, char *input_code)
if ((argc = switch_separate_string(args, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
switch_stream_handle_t stream = { 0 };
SWITCH_STANDARD_STREAM(stream);
stream.write_function(&stream, " argv = { ");
for (x = 0; x < argc; x++) {
stream.write_function(&stream, "'%s'%s", argv[x], x == argc-1 ? "" : ", ");
stream.write_function(&stream, "'%s'%s", argv[x], x == argc - 1 ? "" : ", ");
}
stream.write_function(&stream, " };");
code = (char *)stream.data;
code = (char *) stream.data;
} else {
code = switch_mprintf("argv = {};");
}
@@ -154,7 +156,7 @@ static int lua_parse_and_execute(lua_State *L, char *input_code)
}
if (!error) {
char *file = input_code, *fdup = NULL;
if (!switch_is_file_path(file)) {
fdup = switch_mprintf("%s/%s", SWITCH_GLOBAL_dirs.script_dir, file);
switch_assert(fdup);
@@ -170,7 +172,7 @@ static int lua_parse_and_execute(lua_State *L, char *input_code)
if (!switch_strlen_zero(err)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s\n", err);
}
lua_pop(L, 1); /* pop error message from the stack */
lua_pop(L, 1); /* pop error message from the stack */
}
return error;
@@ -179,10 +181,10 @@ static int lua_parse_and_execute(lua_State *L, char *input_code)
static void *SWITCH_THREAD_FUNC lua_thread_run(switch_thread_t *thread, void *obj)
{
char *input_code = (char *) obj;
lua_State *L = lua_init(); /* opens Lua */
lua_State *L = lua_init(); /* opens Lua */
lua_parse_and_execute(L, input_code);
if (input_code) {
free(input_code);
}
@@ -193,12 +195,8 @@ static void *SWITCH_THREAD_FUNC lua_thread_run(switch_thread_t *thread, void *ob
}
static switch_xml_t lua_fetch(const char *section,
const char *tag_name,
const char *key_name,
const char *key_value,
switch_event_t *params,
void *user_data)
static switch_xml_t lua_fetch(const char *section,
const char *tag_name, const char *key_name, const char *key_value, switch_event_t *params, void *user_data)
{
switch_xml_t xml = NULL;
@@ -238,11 +236,11 @@ static switch_xml_t lua_fetch(const char *section,
if (str) {
if (switch_strlen_zero(str)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Result\n");
} else if (!(xml = switch_xml_parse_str((char *)str, strlen(str)))) {
} else if (!(xml = switch_xml_parse_str((char *) str, strlen(str)))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Parsing XML Result!\n");
}
}
lua_uninit(L);
free(mycmd);
}
@@ -304,13 +302,13 @@ SWITCH_STANDARD_APP(lua_function)
if (switch_strlen_zero(data)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "no args specified!\n");
return;
}
return;
}
snprintf(code, sizeof(code), "~session = freeswitch.Session(\"%s\");", switch_core_session_get_uuid(session));
error = lua_parse_and_execute(L, code);
mycmd = strdup((char *)data);
mycmd = strdup((char *) data);
switch_assert(mycmd);
lua_parse_and_execute(L, mycmd);
@@ -319,8 +317,9 @@ SWITCH_STANDARD_APP(lua_function)
}
SWITCH_STANDARD_API(luarun_api_function) {
SWITCH_STANDARD_API(luarun_api_function)
{
if (switch_strlen_zero(cmd)) {
stream->write_function(stream, "-ERR no args specified!\n");
} else {
@@ -332,7 +331,8 @@ SWITCH_STANDARD_API(luarun_api_function) {
}
SWITCH_STANDARD_API(lua_api_function) {
SWITCH_STANDARD_API(lua_api_function)
{
lua_State *L = lua_init();
char *mycmd;
@@ -370,13 +370,13 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_lua_load)
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
SWITCH_ADD_API(api_interface, "luarun", "run a script", luarun_api_function, "<script>");
SWITCH_ADD_API(api_interface, "lua", "run a script as an api function", lua_api_function, "<script>");
SWITCH_ADD_APP(app_interface, "lua", "Launch LUA ivr", "Run a lua ivr on a channel", lua_function, "<script>", SAF_SUPPORT_NOMEDIA);
globals.pool = pool;
do_config();
@@ -385,7 +385,6 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_lua_load)
}
SWITCH_END_EXTERN_C
/* For Emacs:
* Local Variables:
* mode:c
+4 -7
View File
@@ -1,18 +1,15 @@
SWITCH_BEGIN_EXTERN_C
void mod_lua_conjure_event(lua_State *L, switch_event_t *event, const char *name, int destroy_me)
SWITCH_BEGIN_EXTERN_C void mod_lua_conjure_event(lua_State * L, switch_event_t *event, const char *name, int destroy_me)
{
Event *result = new Event(event);
SWIG_NewPointerObj(L,result,SWIGTYPE_p_Event, destroy_me);
SWIG_NewPointerObj(L, result, SWIGTYPE_p_Event, destroy_me);
lua_setglobal(L, name);
}
void mod_lua_conjure_stream(lua_State *L, switch_stream_handle_t *stream, const char *name, int destroy_me)
void mod_lua_conjure_stream(lua_State * L, switch_stream_handle_t *stream, const char *name, int destroy_me)
{
Stream *result = new Stream(stream);
SWIG_NewPointerObj(L,result,SWIGTYPE_p_Stream, destroy_me);
SWIG_NewPointerObj(L, result, SWIGTYPE_p_Stream, destroy_me);
lua_setglobal(L, name);
}
File diff suppressed because it is too large. Load diff
+69 -75
View File
@@ -27,8 +27,8 @@
*
* freeswitch_mono.cpp -- Mono-specific CoreSession subclass
*
*/
*/
#include <switch.h>
#include <switch_cpp.h>
#include <glib.h>
@@ -38,77 +38,71 @@
#include <mono/metadata/threads.h>
#include <mono/metadata/metadata.h>
#include "freeswitch_mono.h"
MonoSession::MonoSession():CoreSession()
{
} MonoSession::MonoSession(char *uuid):CoreSession(uuid)
{
} MonoSession::MonoSession(switch_core_session_t *session):CoreSession(session)
{
} MonoSession::~MonoSession()
{
mono_thread_attach(globals.domain);
if (dtmfDelegateHandle)
mono_gchandle_free(dtmfDelegateHandle);
if (hangupDelegateHandle)
mono_gchandle_free(hangupDelegateHandle);
}
bool MonoSession::begin_allow_threads()
{
return true;
}
bool MonoSession::end_allow_threads()
{
return true;
}
void MonoSession::check_hangup_hook()
{
mono_thread_attach(globals.domain);
if (!hangupDelegateHandle) {
return;
}
MonoObject * hangupDelegate = mono_gchandle_get_target(hangupDelegateHandle);
if (!hangupDelegate) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "hangupDelegateHandle didn't get an object.");
return;
}
MonoObject * ex = NULL;
mono_runtime_delegate_invoke(hangupDelegate, NULL, &ex);
if (ex) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "hangupDelegate threw an exception.");
}
}
switch_status_t MonoSession::run_dtmf_callback(void *input, switch_input_type_t itype)
{
mono_thread_attach(globals.domain);
if (!dtmfDelegateHandle) {
return SWITCH_STATUS_SUCCESS;
}
MonoObject * dtmfDelegate = mono_gchandle_get_target(dtmfDelegateHandle);
if (!dtmfDelegate) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "dtmfDelegateHandle didn't get an object.");
return SWITCH_STATUS_SUCCESS;
}
void *args[2];
args[0] = &input;
args[1] = &itype;
MonoObject * ex = NULL;
MonoObject * res = mono_runtime_delegate_invoke(dtmfDelegate, args, &ex);
if (ex) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "dtmfDelegate threw an exception.");
return SWITCH_STATUS_FALSE;
}
char *resPtr = mono_string_to_utf8((MonoString *) res);
switch_status_t status = process_callback_result(resPtr);
g_free(resPtr);
return status;
}
MonoSession::MonoSession() : CoreSession()
{
}
MonoSession::MonoSession(char *uuid) : CoreSession(uuid)
{
}
MonoSession::MonoSession(switch_core_session_t *session) : CoreSession(session)
{
}
MonoSession::~MonoSession()
{
mono_thread_attach(globals.domain);
if (dtmfDelegateHandle) mono_gchandle_free(dtmfDelegateHandle);
if (hangupDelegateHandle) mono_gchandle_free(hangupDelegateHandle);
}
bool MonoSession::begin_allow_threads()
{
return true;
}
bool MonoSession::end_allow_threads()
{
return true;
}
void MonoSession::check_hangup_hook()
{
mono_thread_attach(globals.domain);
if (!hangupDelegateHandle) {
return;
}
MonoObject *hangupDelegate = mono_gchandle_get_target(hangupDelegateHandle);
if (!hangupDelegate) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "hangupDelegateHandle didn't get an object.");
return;
}
MonoObject *ex = NULL;
mono_runtime_delegate_invoke(hangupDelegate, NULL, &ex);
if (ex) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "hangupDelegate threw an exception.");
}
}
switch_status_t MonoSession::run_dtmf_callback(void *input, switch_input_type_t itype)
{
mono_thread_attach(globals.domain);
if (!dtmfDelegateHandle) {
return SWITCH_STATUS_SUCCESS;
}
MonoObject *dtmfDelegate = mono_gchandle_get_target(dtmfDelegateHandle);
if (!dtmfDelegate) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "dtmfDelegateHandle didn't get an object.");
return SWITCH_STATUS_SUCCESS;
}
void *args[2];
args[0] = &input;
args[1] = &itype;
MonoObject *ex = NULL;
MonoObject *res = mono_runtime_delegate_invoke(dtmfDelegate, args, &ex);
if (ex) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "dtmfDelegate threw an exception.");
return SWITCH_STATUS_FALSE;
}
char *resPtr = mono_string_to_utf8((MonoString*)res);
switch_status_t status = process_callback_result(resPtr);
g_free(resPtr);
return status;
}
+264 -273
View File
@@ -30,13 +30,10 @@
* Most of mod_mono is implmented in the mod_mono_managed Loader class.
* The native code just handles getting the Mono runtime up and down
* and passing pointers into managed code.
*/
*/
#include <switch.h>
SWITCH_BEGIN_EXTERN_C
SWITCH_BEGIN_EXTERN_C
#include "freeswitch_mono.h"
#include <glib.h>
#include <mono/jit/jit.h>
@@ -44,284 +41,278 @@ SWITCH_BEGIN_EXTERN_C
#include <mono/metadata/environment.h>
#include <mono/metadata/threads.h>
#include <mono/metadata/debug-helpers.h>
#ifdef WIN32
#include <shlobj.h>
#define EXPORT __declspec(dllexport)
#elif
#define EXPORT
#endif
#endif /* */
#define MOD_MONO_MANAGED_DLL "mod_mono_managed.dll"
mod_mono_globals globals = { 0 };
SWITCH_MODULE_LOAD_FUNCTION(mod_mono_load);
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_mono_shutdown);
SWITCH_MODULE_DEFINITION(mod_mono, mod_mono_load, mod_mono_shutdown, NULL);
SWITCH_STANDARD_API(monorun_api_function); /* ExecuteBackground */
SWITCH_STANDARD_API(mono_api_function); /* Execute */
SWITCH_STANDARD_APP(mono_app_function); /* Run */
mod_mono_globals globals = {
0};
SWITCH_MODULE_LOAD_FUNCTION(mod_mono_load);
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_mono_shutdown);
SWITCH_MODULE_DEFINITION(mod_mono, mod_mono_load, mod_mono_shutdown, NULL);
SWITCH_STANDARD_API(monorun_api_function); /* ExecuteBackground */
SWITCH_STANDARD_API(mono_api_function); /* Execute */
SWITCH_STANDARD_APP(mono_app_function); /* Run */
// Sets up delegates (and anything else needed) on the MonoSession object
// Called via internalcall
SWITCH_MOD_DECLARE(void) InitMonoSession(MonoSession *session, MonoObject *dtmfDelegate, MonoObject *hangupDelegate)
{
switch_assert(session);
if (!session) return;
session->setDTMFCallback(NULL, "");
session->setHangupHook(NULL);
session->dtmfDelegateHandle = mono_gchandle_new(dtmfDelegate, FALSE);
session->hangupDelegateHandle = mono_gchandle_new(hangupDelegate, FALSE);
}
switch_status_t setMonoDirs()
{
SWITCH_MOD_DECLARE(void) InitMonoSession(MonoSession * session, MonoObject * dtmfDelegate, MonoObject * hangupDelegate)
{
switch_assert(session);
if (!session)
return;
session->setDTMFCallback(NULL, "");
session->setHangupHook(NULL);
session->dtmfDelegateHandle = mono_gchandle_new(dtmfDelegate, FALSE);
session->hangupDelegateHandle = mono_gchandle_new(hangupDelegate, FALSE);
}
switch_status_t setMonoDirs()
{
#ifdef WIN32
/* Win32 Mono installs can't figure out their own path
// Guys in #mono say we should just deploy all the libs we need
// I think it's much nicer to let the user deal with installing Mono
// and we'll just look for it in program files. */
HANDLE hFind;
WIN32_FIND_DATA findData;
char progFilesPath[MAX_PATH];
char findPath[MAX_PATH];
SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES, NULL, SHGFP_TYPE_CURRENT, progFilesPath);
switch_snprintf(findPath, MAX_PATH, "%s\\Mono-*", progFilesPath);
hFind = FindFirstFile(findPath, &findData);
if (hFind == INVALID_HANDLE_VALUE) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error looking for Mono in Program Files.\n");
return SWITCH_STATUS_FALSE;
}
while((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY) {
if (FindNextFile(hFind, &findData) == 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not find Mono directory in Program Files.\n");
FindClose(hFind);
return SWITCH_STATUS_FALSE;
}
}
/* Got it */
{
char libPath[MAX_PATH];
char etcPath[MAX_PATH];
switch_snprintf(libPath, MAX_PATH, "%s\\%s\\lib", progFilesPath, findData.cFileName);
switch_snprintf(etcPath, MAX_PATH, "%s\\%s\\etc", progFilesPath, findData.cFileName);
FindClose(hFind);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Using Mono paths '%s' and '%s'.\n", libPath, etcPath);
mono_set_dirs(libPath, etcPath);
return SWITCH_STATUS_SUCCESS;
}
/* Win32 Mono installs can't figure out their own path
// Guys in #mono say we should just deploy all the libs we need
// I think it's much nicer to let the user deal with installing Mono
// and we'll just look for it in program files. */
HANDLE hFind;
WIN32_FIND_DATA findData;
char progFilesPath[MAX_PATH];
char findPath[MAX_PATH];
SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES, NULL, SHGFP_TYPE_CURRENT, progFilesPath);
switch_snprintf(findPath, MAX_PATH, "%s\\Mono-*", progFilesPath);
hFind = FindFirstFile(findPath, &findData);
if (hFind == INVALID_HANDLE_VALUE) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error looking for Mono in Program Files.\n");
return SWITCH_STATUS_FALSE;
}
while ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY) {
if (FindNextFile(hFind, &findData) == 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not find Mono directory in Program Files.\n");
FindClose(hFind);
return SWITCH_STATUS_FALSE;
}
}
/* Got it */
{
char libPath[MAX_PATH];
char etcPath[MAX_PATH];
switch_snprintf(libPath, MAX_PATH, "%s\\%s\\lib", progFilesPath, findData.cFileName);
switch_snprintf(etcPath, MAX_PATH, "%s\\%s\\etc", progFilesPath, findData.cFileName);
FindClose(hFind);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Using Mono paths '%s' and '%s'.\n", libPath, etcPath);
mono_set_dirs(libPath, etcPath);
return SWITCH_STATUS_SUCCESS;
}
#elif
// On other platforms, it should just work if it hasn't been relocated
mono_set_dirs(NULL, NULL);
return SWITCH_STATUS_SUCCESS;
#endif
}
switch_status_t loadModMonoManaged()
{
/* Find and load mod_mono_managed.exe */
char filename[256];
switch_snprintf(filename, 256, "%s%s%s", SWITCH_GLOBAL_dirs.mod_dir, SWITCH_PATH_SEPARATOR, MOD_MONO_MANAGED_DLL);
globals.domain = mono_jit_init(filename);
if (!globals.domain) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "mono_jit_init failed.\n");
return SWITCH_STATUS_FALSE;
}
/* Open the assembly */
globals.mod_mono_asm = mono_domain_assembly_open(globals.domain, filename);
if (!globals.mod_mono_asm) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "mono_domain_assembly_open failed.\n");
return SWITCH_STATUS_FALSE;
}
return SWITCH_STATUS_SUCCESS;
}
MonoMethod *getMethod(const char *name, MonoClass *klass)
{
MonoMethodDesc *desc;
MonoMethod *method;
desc = mono_method_desc_new(name, TRUE);
method = mono_method_desc_search_in_class(desc, klass);
if (!method) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not find %s method.\n", name);
return NULL;
}
return method;
}
switch_status_t findLoader()
{
/* Find loader class and methods*/
MonoImage* img;
MonoClass* loaderClass;
img = mono_assembly_get_image(globals.mod_mono_asm);
loaderClass = mono_class_from_name(img, "FreeSWITCH", "Loader");
if (!loaderClass) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not find FreeSWITCH.Loader class.\n");
return SWITCH_STATUS_FALSE;
}
globals.loadMethod = getMethod("FreeSWITCH.Loader:Load()", loaderClass);
if (!globals.loadMethod) return SWITCH_STATUS_FALSE;
globals.unloadMethod = getMethod("FreeSWITCH.Loader:Unload()", loaderClass);
if (!globals.unloadMethod) return SWITCH_STATUS_FALSE;
globals.runMethod = getMethod("FreeSWITCH.Loader:Run(string,intptr)", loaderClass);
if (!globals.runMethod) return SWITCH_STATUS_FALSE;
globals.executeMethod = getMethod("FreeSWITCH.Loader:Execute(string,intptr,intptr)", loaderClass);
if (!globals.executeMethod) return SWITCH_STATUS_FALSE;
// On other platforms, it should just work if it hasn't been relocated
mono_set_dirs(NULL, NULL);
return SWITCH_STATUS_SUCCESS;
globals.executeBackgroundMethod = getMethod("FreeSWITCH.Loader:ExecuteBackground(string)", loaderClass);
if (!globals.executeBackgroundMethod) return SWITCH_STATUS_FALSE;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Found all loader functions.\n");
return SWITCH_STATUS_SUCCESS;
}
SWITCH_MODULE_LOAD_FUNCTION(mod_mono_load)
{
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
globals.pool = pool;
if (setMonoDirs() != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_FALSE;
}
if (loadModMonoManaged() != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_FALSE;
}
if (findLoader() != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_FALSE;
}
/* Not sure if this is necesary on the loading thread */
mono_thread_attach(globals.domain);
mono_add_internal_call("FreeSWITCH.Native.MonoSession::InitMonoSession", InitMonoSession);
/* Run loader */
MonoObject *objResult;
MonoObject *exception = NULL;
objResult = mono_runtime_invoke(globals.loadMethod, NULL, NULL, &exception);
if (exception) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Load threw an exception.\n");
mono_print_unhandled_exception(exception);
return SWITCH_STATUS_FALSE;
}
if (*(int*)mono_object_unbox(objResult)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Load completed successfully.\n");
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Load did not return true.\n");
return SWITCH_STATUS_FALSE;
}
/* We're good to register */
switch_api_interface_t *api_interface;
switch_application_interface_t *app_interface;
SWITCH_ADD_API(api_interface, "monorun", "Run a module (ExecuteBackground)", monorun_api_function, "<module> [<args>]");
SWITCH_ADD_API(api_interface, "mono", "Run a module as an API function (Execute)", mono_api_function, "<module> [<args>]");
SWITCH_ADD_APP(app_interface, "mono", "Run Mono IVR", "Run a Mono IVR on a channel", mono_app_function, "<modulename> [<args>]", SAF_NONE);
#endif /* */
}
switch_status_t loadModMonoManaged()
{
return SWITCH_STATUS_SUCCESS;
}
SWITCH_STANDARD_API(monorun_api_function)
{
// TODO: Should we be detaching after all this?
mono_thread_attach(globals.domain);
if (switch_strlen_zero(cmd)) {
stream->write_function(stream, "-ERR no args specified!\n");
return SWITCH_STATUS_SUCCESS;
}
// ExecuteBackground(string command)
void *args[1];
args[0] = mono_string_new(globals.domain, cmd);
MonoObject *exception = NULL;
MonoObject *objResult = mono_runtime_invoke(globals.executeBackgroundMethod, NULL, args, &exception);
if (exception) {
stream->write_function(stream, "-ERR FreeSWITCH.Loader.ExecuteBackground threw an exception.\n");
mono_print_unhandled_exception(exception);
return SWITCH_STATUS_SUCCESS;
}
if (*(int*)mono_object_unbox(objResult)) {
stream->write_function(stream, "+OK\n");
} else {
stream->write_function(stream, "-ERR ExecuteBackground returned false (unknown module?).\n");
}
return SWITCH_STATUS_SUCCESS;
}
SWITCH_STANDARD_API(mono_api_function)
{
mono_thread_attach(globals.domain);
if (switch_strlen_zero(cmd)) {
stream->write_function(stream, "-ERR no args specified!\n");
return SWITCH_STATUS_SUCCESS;
}
/* Find and load mod_mono_managed.exe */
char filename[256];
switch_snprintf(filename, 256, "%s%s%s", SWITCH_GLOBAL_dirs.mod_dir, SWITCH_PATH_SEPARATOR, MOD_MONO_MANAGED_DLL);
globals.domain = mono_jit_init(filename);
if (!globals.domain) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "mono_jit_init failed.\n");
return SWITCH_STATUS_FALSE;
}
/* Open the assembly */
globals.mod_mono_asm = mono_domain_assembly_open(globals.domain, filename);
if (!globals.mod_mono_asm) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "mono_domain_assembly_open failed.\n");
return SWITCH_STATUS_FALSE;
}
return SWITCH_STATUS_SUCCESS;
}
MonoMethod * getMethod(const char *name, MonoClass * klass)
{
MonoMethodDesc * desc;
MonoMethod * method;
desc = mono_method_desc_new(name, TRUE);
method = mono_method_desc_search_in_class(desc, klass);
if (!method) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not find %s method.\n", name);
return NULL;
}
return method;
}
switch_status_t findLoader()
{
// Method is: Execute(string command, IntPtr streamPtr, IntPtr eventPtr)
void *args[3];
args[0] = mono_string_new(globals.domain, cmd);
args[1] = &stream; // Address of the arguments
args[2] = &(stream->param_event);
/* Find loader class and methods */
MonoImage * img;
MonoClass * loaderClass;
img = mono_assembly_get_image(globals.mod_mono_asm);
loaderClass = mono_class_from_name(img, "FreeSWITCH", "Loader");
if (!loaderClass) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not find FreeSWITCH.Loader class.\n");
return SWITCH_STATUS_FALSE;
}
globals.loadMethod = getMethod("FreeSWITCH.Loader:Load()", loaderClass);
if (!globals.loadMethod)
return SWITCH_STATUS_FALSE;
globals.unloadMethod = getMethod("FreeSWITCH.Loader:Unload()", loaderClass);
if (!globals.unloadMethod)
return SWITCH_STATUS_FALSE;
globals.runMethod = getMethod("FreeSWITCH.Loader:Run(string,intptr)", loaderClass);
if (!globals.runMethod)
return SWITCH_STATUS_FALSE;
globals.executeMethod = getMethod("FreeSWITCH.Loader:Execute(string,intptr,intptr)", loaderClass);
if (!globals.executeMethod)
return SWITCH_STATUS_FALSE;
globals.executeBackgroundMethod = getMethod("FreeSWITCH.Loader:ExecuteBackground(string)", loaderClass);
if (!globals.executeBackgroundMethod)
return SWITCH_STATUS_FALSE;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Found all loader functions.\n");
return SWITCH_STATUS_SUCCESS;
}
SWITCH_MODULE_LOAD_FUNCTION(mod_mono_load)
{
MonoObject *exception = NULL;
MonoObject *objResult = mono_runtime_invoke(globals.executeMethod, NULL, args, &exception);
if (exception) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Exception trying to execute mono %s.\n", cmd);
mono_print_unhandled_exception(exception);
}
if (!(*(int*)mono_object_unbox(objResult))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Execute failed for %s (unknown module?).\n", cmd);
}
return SWITCH_STATUS_SUCCESS;
}
SWITCH_STANDARD_APP(mono_app_function)
{
mono_thread_attach(globals.domain);
if (switch_strlen_zero(data)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No args specified!\n");
}
// bool Run(string command, IntPtr sessionHandle)
void *args[2];
args[0] = mono_string_new(globals.domain, data);
args[1] = &session;
MonoObject *exception = NULL;
MonoObject *objResult = mono_runtime_invoke(globals.runMethod, NULL, args, &exception);
if (exception) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Exception trying to execute application mono %s.\n", data);
mono_print_unhandled_exception(exception);
}
if (!(*(int*)mono_object_unbox(objResult))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Application run failed for %s (unknown module?).\n", data);
}
}
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_mono_shutdown)
{
mono_thread_attach(globals.domain);
MonoObject *ex;
mono_runtime_invoke(globals.unloadMethod, NULL, NULL, &ex);
if (ex) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Exception occurred in Loader::Unload.\n");
mono_print_unhandled_exception(ex);
}
mono_runtime_set_shutting_down();
mono_runtime_cleanup(globals.domain);
mono_runtime_quit();
return SWITCH_STATUS_SUCCESS;
}
SWITCH_END_EXTERN_C
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
globals.pool = pool;
if (setMonoDirs() != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_FALSE;
}
if (loadModMonoManaged() != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_FALSE;
}
if (findLoader() != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_FALSE;
}
/* Not sure if this is necesary on the loading thread */
mono_thread_attach(globals.domain);
mono_add_internal_call("FreeSWITCH.Native.MonoSession::InitMonoSession", InitMonoSession);
/* Run loader */
MonoObject * objResult;
MonoObject * exception = NULL;
objResult = mono_runtime_invoke(globals.loadMethod, NULL, NULL, &exception);
if (exception) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Load threw an exception.\n");
mono_print_unhandled_exception(exception);
return SWITCH_STATUS_FALSE;
}
if (*(int *) mono_object_unbox(objResult)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Load completed successfully.\n");
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Load did not return true.\n");
return SWITCH_STATUS_FALSE;
}
/* We're good to register */
switch_api_interface_t *api_interface;
switch_application_interface_t *app_interface;
SWITCH_ADD_API(api_interface, "monorun", "Run a module (ExecuteBackground)", monorun_api_function, "<module> [<args>]");
SWITCH_ADD_API(api_interface, "mono", "Run a module as an API function (Execute)", mono_api_function, "<module> [<args>]");
SWITCH_ADD_APP(app_interface, "mono", "Run Mono IVR", "Run a Mono IVR on a channel", mono_app_function, "<modulename> [<args>]", SAF_NONE);
return SWITCH_STATUS_SUCCESS;
}
SWITCH_STANDARD_API(monorun_api_function)
{
// TODO: Should we be detaching after all this?
mono_thread_attach(globals.domain);
if (switch_strlen_zero(cmd)) {
stream->write_function(stream, "-ERR no args specified!\n");
return SWITCH_STATUS_SUCCESS;
}
// ExecuteBackground(string command)
void *args[1];
args[0] = mono_string_new(globals.domain, cmd);
MonoObject * exception = NULL;
MonoObject * objResult = mono_runtime_invoke(globals.executeBackgroundMethod, NULL, args, &exception);
if (exception) {
stream->write_function(stream, "-ERR FreeSWITCH.Loader.ExecuteBackground threw an exception.\n");
mono_print_unhandled_exception(exception);
return SWITCH_STATUS_SUCCESS;
}
if (*(int *) mono_object_unbox(objResult)) {
stream->write_function(stream, "+OK\n");
} else {
stream->write_function(stream, "-ERR ExecuteBackground returned false (unknown module?).\n");
}
return SWITCH_STATUS_SUCCESS;
}
SWITCH_STANDARD_API(mono_api_function)
{
mono_thread_attach(globals.domain);
if (switch_strlen_zero(cmd)) {
stream->write_function(stream, "-ERR no args specified!\n");
return SWITCH_STATUS_SUCCESS;
}
// Method is: Execute(string command, IntPtr streamPtr, IntPtr eventPtr)
void *args[3];
args[0] = mono_string_new(globals.domain, cmd);
args[1] = &stream; // Address of the arguments
args[2] = &(stream->param_event);
MonoObject * exception = NULL;
MonoObject * objResult = mono_runtime_invoke(globals.executeMethod, NULL, args, &exception);
if (exception) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Exception trying to execute mono %s.\n", cmd);
mono_print_unhandled_exception(exception);
}
if (!(*(int *) mono_object_unbox(objResult))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Execute failed for %s (unknown module?).\n", cmd);
}
return SWITCH_STATUS_SUCCESS;
}
SWITCH_STANDARD_APP(mono_app_function)
{
mono_thread_attach(globals.domain);
if (switch_strlen_zero(data)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No args specified!\n");
}
// bool Run(string command, IntPtr sessionHandle)
void *args[2];
args[0] = mono_string_new(globals.domain, data);
args[1] = &session;
MonoObject * exception = NULL;
MonoObject * objResult = mono_runtime_invoke(globals.runMethod, NULL, args, &exception);
if (exception) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Exception trying to execute application mono %s.\n", data);
mono_print_unhandled_exception(exception);
}
if (!(*(int *) mono_object_unbox(objResult))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Application run failed for %s (unknown module?).\n", data);
}
} SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_mono_shutdown)
{
mono_thread_attach(globals.domain);
MonoObject * ex;
mono_runtime_invoke(globals.unloadMethod, NULL, NULL, &ex);
if (ex) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Exception occurred in Loader::Unload.\n");
mono_print_unhandled_exception(ex);
}
mono_runtime_set_shutting_down();
mono_runtime_cleanup(globals.domain);
mono_runtime_quit();
return SWITCH_STATUS_SUCCESS;
}
SWITCH_END_EXTERN_C
+27 -24
View File
@@ -8,17 +8,17 @@ static STRLEN n_a;
using namespace PERL;
Session::Session() : CoreSession()
Session::Session():CoreSession()
{
init_me();
}
Session::Session(char *uuid) : CoreSession(uuid)
Session::Session(char *uuid):CoreSession(uuid)
{
init_me();
}
Session::Session(switch_core_session_t *new_session) : CoreSession(new_session)
Session::Session(switch_core_session_t *new_session):CoreSession(new_session)
{
init_me();
}
@@ -37,19 +37,19 @@ Session::~Session()
}
bool Session::begin_allow_threads()
bool Session::begin_allow_threads()
{
do_hangup_hook();
return true;
}
bool Session::end_allow_threads()
bool Session::end_allow_threads()
{
do_hangup_hook();
return true;
}
void Session::setPERL(PerlInterpreter *pi)
void Session::setPERL(PerlInterpreter * pi)
{
my_perl = pi;
}
@@ -57,30 +57,31 @@ void Session::setPERL(PerlInterpreter *pi)
PerlInterpreter *Session::getPERL()
{
if (!my_perl) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Doh!\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Doh!\n");
}
return my_perl;
}
bool Session::ready() {
bool Session::ready()
{
bool r;
sanity_check(false);
sanity_check(false);
r = switch_channel_ready(channel) != 0;
do_hangup_hook();
return r;
}
void Session::check_hangup_hook()
void Session::check_hangup_hook()
{
if (hangup_func_str && (hook_state == CS_HANGUP || hook_state == CS_ROUTING)) {
hh++;
}
}
void Session::do_hangup_hook()
void Session::do_hangup_hook()
{
if (hh && !mark) {
const char *err = NULL;
@@ -101,7 +102,7 @@ void Session::do_hangup_hook()
}
}
static switch_status_t perl_hanguphook(switch_core_session_t *session_hungup)
static switch_status_t perl_hanguphook(switch_core_session_t *session_hungup)
{
switch_channel_t *channel = switch_core_session_get_channel(session_hungup);
CoreSession *coresession = NULL;
@@ -118,7 +119,8 @@ static switch_status_t perl_hanguphook(switch_core_session_t *session_hungup)
}
void Session::setHangupHook(char *func, char *arg) {
void Session::setHangupHook(char *func, char *arg)
{
sanity_check_noreturn;
@@ -135,7 +137,8 @@ void Session::setHangupHook(char *func, char *arg) {
}
}
void Session::setInputCallback(char *cbfunc, char *funcargs) {
void Session::setInputCallback(char *cbfunc, char *funcargs)
{
sanity_check_noreturn;
@@ -148,22 +151,22 @@ void Session::setInputCallback(char *cbfunc, char *funcargs) {
if (funcargs) {
cb_arg = strdup(funcargs);
}
args.buf = this;
switch_channel_set_private(channel, "CoreSession", this);
args.input_callback = dtmf_callback;
args.input_callback = dtmf_callback;
ap = &args;
}
switch_status_t Session::run_dtmf_callback(void *input, switch_input_type_t itype)
switch_status_t Session::run_dtmf_callback(void *input, switch_input_type_t itype)
{
if (!getPERL()) {
return SWITCH_STATUS_FALSE;;
}
switch (itype) {
case SWITCH_INPUT_TYPE_DTMF:
case SWITCH_INPUT_TYPE_DTMF:
{
switch_dtmf_t *dtmf = (switch_dtmf_t *) input;
char str[32] = "";
@@ -177,14 +180,14 @@ switch_status_t Session::run_dtmf_callback(void *input, switch_input_type_t ityp
}
str[0] = dtmf->digit;
this_sv = newSV(strlen(str)+1);
this_sv = newSV(strlen(str) + 1);
sv_setpv(this_sv, str);
hv_store(hash, "digit", 5, this_sv, 0);
switch_snprintf(str, sizeof(str), "%d", dtmf->duration);
this_sv = newSV(strlen(str)+1);
this_sv = newSV(strlen(str) + 1);
sv_setpv(this_sv, str);
hv_store(hash, "duration", 8, this_sv, 0);
hv_store(hash, "duration", 8, this_sv, 0);
code = switch_mprintf("$__RV = %s('dtmf', \\%%__dtmf, %s);", cb_function, switch_str_nil(cb_arg));
Perl_eval_pv(my_perl, code, FALSE);
@@ -193,18 +196,18 @@ switch_status_t Session::run_dtmf_callback(void *input, switch_input_type_t ityp
return process_callback_result(SvPV(get_sv("__RV", TRUE), n_a));
}
break;
case SWITCH_INPUT_TYPE_EVENT:
case SWITCH_INPUT_TYPE_EVENT:
{
switch_event_t *event = (switch_event_t *) input;
int arg_count = 2;
char *code;
mod_perl_conjure_event(my_perl, event, "__Input_Event__");
code = switch_mprintf("$__RV = %s('event', $__Input_Event__, %s);", cb_function, switch_str_nil(cb_arg));
Perl_eval_pv(my_perl, code, TRUE);
free(code);
return process_callback_result(SvPV(get_sv("__RV", TRUE), n_a));
}
break;
+41 -58
View File
@@ -58,7 +58,7 @@ static struct {
static int Perl_safe_eval(PerlInterpreter *my_perl, const char *string)
static int Perl_safe_eval(PerlInterpreter * my_perl, const char *string)
{
char *err = NULL;
@@ -73,7 +73,7 @@ static int Perl_safe_eval(PerlInterpreter *my_perl, const char *string)
static int perl_parse_and_execute(PerlInterpreter *my_perl, char *input_code, char *setup_code)
static int perl_parse_and_execute(PerlInterpreter * my_perl, char *input_code, char *setup_code)
{
int error = 0;
@@ -103,10 +103,10 @@ static int perl_parse_and_execute(PerlInterpreter *my_perl, char *input_code, ch
if ((argc = switch_separate_string(args, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
switch_stream_handle_t stream = { 0 };
SWITCH_STANDARD_STREAM(stream);
stream.write_function(&stream, " @ARGV = ( ");
for (x = 0; x < argc; x++) {
stream.write_function(&stream, "'%s'%s", argv[x], x == argc-1 ? "" : ", ");
stream.write_function(&stream, "'%s'%s", argv[x], x == argc - 1 ? "" : ", ");
}
stream.write_function(&stream, " );");
code = stream.data;
@@ -130,7 +130,7 @@ static int perl_parse_and_execute(PerlInterpreter *my_perl, char *input_code, ch
file = switch_mprintf("require '%s';", file);
switch_assert(file);
}
error = Perl_safe_eval(my_perl, file);
switch_safe_free(file);
}
@@ -154,14 +154,15 @@ static PerlInterpreter *clone_perl(void)
}
#if 0
static perl_parse_and_execute (PerlInterpreter *my_perl, char *input_code, char *setup_code)
static perl_parse_and_execute(PerlInterpreter * my_perl, char *input_code, char *setup_code)
{
int error = 0;
if (*input_code == '~') {
char *buff = input_code + 1;
perl_parse(my_perl, xs_init, 3, embedding, NULL);
if (setup_code) Perl_safe_eval(my_perl, setup_code);
if (setup_code)
Perl_safe_eval(my_perl, setup_code);
Perl_safe_eval(my_perl, buff);
} else {
int argc = 0;
@@ -169,43 +170,38 @@ static perl_parse_and_execute (PerlInterpreter *my_perl, char *input_code, char
char *err;
argv[0] = "FreeSWITCH";
argc++;
argc += switch_separate_string(input_code, ' ', &argv[1], (sizeof(argv) / sizeof(argv[0])) - 1);
if (!perl_parse(my_perl, xs_init, argc, argv, (char **)NULL)) {
if (!perl_parse(my_perl, xs_init, argc, argv, (char **) NULL)) {
if (setup_code) {
if (!Perl_safe_eval(my_perl, setup_code)) {
perl_run(my_perl);
}
}
}
if ((err = SvPV(get_sv("@", TRUE), n_a)) && !switch_strlen_zero(err)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s\n", err);
}
}
}
#endif
#endif
static void perl_function(switch_core_session_t *session, char *data)
{
char *uuid = switch_core_session_get_uuid(session);
PerlInterpreter *my_perl = clone_perl();
char code[1024];
perl_parse(my_perl, xs_init, 3, embedding, NULL);
Perl_safe_eval(my_perl, code);
switch_snprintf(code, sizeof(code),
"use lib '%s/perl';\n"
"use freeswitch;\n"
"$SWITCH_ENV{UUID} = \"%s\";\n"
"$session = new freeswitch::Session(\"%s\")"
,
SWITCH_GLOBAL_dirs.base_dir,
uuid,
uuid);
switch_snprintf(code, sizeof(code),
"use lib '%s/perl';\n"
"use freeswitch;\n"
"$SWITCH_ENV{UUID} = \"%s\";\n" "$session = new freeswitch::Session(\"%s\")", SWITCH_GLOBAL_dirs.base_dir, uuid, uuid);
perl_parse_and_execute(my_perl, data, code);
Perl_safe_eval(my_perl, "undef $session;");
@@ -244,16 +240,10 @@ static void *SWITCH_THREAD_FUNC perl_thread_run(switch_thread_t *thread, void *o
if (session) {
uuid = switch_core_session_get_uuid(session);
}
switch_snprintf(code, sizeof(code),
"use lib '%s/perl';\n"
"use freeswitch;\n"
"$SWITCH_ENV{UUID} = \"%s\";\n"
,
SWITCH_GLOBAL_dirs.base_dir,
switch_str_nil(uuid)
);
switch_snprintf(code, sizeof(code),
"use lib '%s/perl';\n" "use freeswitch;\n" "$SWITCH_ENV{UUID} = \"%s\";\n", SWITCH_GLOBAL_dirs.base_dir, switch_str_nil(uuid)
);
perl_parse(my_perl, xs_init, 3, embedding, NULL);
Perl_safe_eval(my_perl, code);
@@ -273,7 +263,7 @@ static void *SWITCH_THREAD_FUNC perl_thread_run(switch_thread_t *thread, void *o
//Perl_safe_eval(my_perl, cmd);
perl_parse_and_execute(my_perl, cmd, NULL);
}
if (uuid) {
switch_snprintf(code, sizeof(code), "undef $session;", uuid);
Perl_safe_eval(my_perl, code);
@@ -301,7 +291,7 @@ int perl_thread(const char *text)
memset(po, 0, sizeof(*po));
po->cmd = strdup(text);
po->d = 1;
switch_threadattr_create(&thd_attr, globals.pool);
switch_threadattr_detach_set(thd_attr, 1);
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
@@ -310,7 +300,8 @@ int perl_thread(const char *text)
return 0;
}
SWITCH_STANDARD_API(perlrun_api_function) {
SWITCH_STANDARD_API(perlrun_api_function)
{
if (switch_strlen_zero(cmd)) {
stream->write_function(stream, "-ERR Missing args.\n");
@@ -322,7 +313,8 @@ SWITCH_STANDARD_API(perlrun_api_function) {
return SWITCH_STATUS_SUCCESS;
}
SWITCH_STANDARD_API(perl_api_function) {
SWITCH_STANDARD_API(perl_api_function)
{
struct perl_o po = { 0 };
@@ -337,12 +329,8 @@ SWITCH_STANDARD_API(perl_api_function) {
perl_thread_run(NULL, &po);
}
static switch_xml_t perl_fetch(const char *section,
const char *tag_name,
const char *key_name,
const char *key_value,
switch_event_t *params,
void *user_data)
static switch_xml_t perl_fetch(const char *section,
const char *tag_name, const char *key_name, const char *key_value, switch_event_t *params, void *user_data)
{
char *argv[128] = { 0 };
@@ -359,10 +347,10 @@ static switch_xml_t perl_fetch(const char *section,
argv[argc++] = "FreeSWITCH";
argv[argc++] = globals.xml_handler;
PERL_SET_CONTEXT(my_perl);
if (perl_parse(my_perl, xs_init, argc, argv, (char **)NULL)) {
if (perl_parse(my_perl, xs_init, argc, argv, (char **) NULL)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Parsing Result!\n");
return NULL;
}
@@ -375,15 +363,15 @@ static switch_xml_t perl_fetch(const char *section,
section = "";
}
this = newSV(strlen(section)+1);
this = newSV(strlen(section) + 1);
sv_setpv(this, section);
hv_store(hash, "section", 7, this, 0);
if (switch_strlen_zero(tag_name)) {
tag_name = "";
}
this = newSV(strlen(tag_name)+1);
this = newSV(strlen(tag_name) + 1);
sv_setpv(this, tag_name);
hv_store(hash, "tag_name", 8, this, 0);
@@ -391,7 +379,7 @@ static switch_xml_t perl_fetch(const char *section,
key_name = "";
}
this = newSV(strlen(key_name)+1);
this = newSV(strlen(key_name) + 1);
sv_setpv(this, key_name);
hv_store(hash, "key_name", 8, this, 0);
@@ -399,28 +387,23 @@ static switch_xml_t perl_fetch(const char *section,
key_value = "";
}
this = newSV(strlen(key_value)+1);
this = newSV(strlen(key_value) + 1);
sv_setpv(this, key_value);
hv_store(hash, "key_value", 9, this, 0);
if (!(hash = get_hv("XML_DATA", TRUE))) {
abort();
}
if (params) {
for (hp = params->headers; hp; hp = hp->next) {
this = newSV(strlen(hp->value)+1);
this = newSV(strlen(hp->value) + 1);
sv_setpv(this, hp->value);
hv_store(hash, hp->name, strlen(hp->name), this, 0);
}
}
switch_snprintf(code, sizeof(code),
"use lib '%s/perl';\n"
"use freeswitch;\n"
,
SWITCH_GLOBAL_dirs.base_dir
);
switch_snprintf(code, sizeof(code), "use lib '%s/perl';\n" "use freeswitch;\n", SWITCH_GLOBAL_dirs.base_dir);
Perl_safe_eval(my_perl, code);
if (params) {
@@ -437,7 +420,7 @@ static switch_xml_t perl_fetch(const char *section,
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Parsing XML Result!\n");
}
}
destroy_perl(&my_perl);
}
+8 -11
View File
@@ -1,24 +1,21 @@
SWITCH_BEGIN_EXTERN_C
void mod_perl_conjure_event(PerlInterpreter *my_perl, switch_event_t *event, const char *name)
SWITCH_BEGIN_EXTERN_C void mod_perl_conjure_event(PerlInterpreter * my_perl, switch_event_t *event, const char *name)
{
Event *result = 0 ;
Event *result = 0;
SV *sv;
PERL_SET_CONTEXT(my_perl);
sv = sv_2mortal(get_sv(name, TRUE));
result = (Event *)new Event(event);
sv = sv_2mortal(get_sv(name, TRUE));
result = (Event *) new Event(event);
SWIG_Perl_MakePtr(sv, result, SWIGTYPE_p_Event, SWIG_OWNER | SWIG_SHADOW);
}
void mod_perl_conjure_stream(PerlInterpreter *my_perl, switch_stream_handle_t *stream, const char *name)
void mod_perl_conjure_stream(PerlInterpreter * my_perl, switch_stream_handle_t *stream, const char *name)
{
Stream *result = 0 ;
Stream *result = 0;
SV *sv;
PERL_SET_CONTEXT(my_perl);
sv = sv_2mortal(get_sv(name, TRUE));
result = (Stream *)new Stream(stream);
sv = sv_2mortal(get_sv(name, TRUE));
result = (Stream *) new Stream(stream);
SWIG_Perl_MakePtr(sv, result, SWIGTYPE_p_Stream, SWIG_OWNER | SWIG_SHADOW);
}
File diff suppressed because it is too large. Load diff
+4 -5
View File
@@ -1,13 +1,12 @@
#include <EXTERN.h>
#include <perl.h>
EXTERN_C void xs_init (pTHX);
EXTERN_C void xs_init(pTHX);
EXTERN_C void boot_DynaLoader (pTHX_ CV* cv);
EXTERN_C void boot_freeswitch (pTHX_ CV* cv);
EXTERN_C void boot_DynaLoader(pTHX_ CV * cv);
EXTERN_C void boot_freeswitch(pTHX_ CV * cv);
EXTERN_C void
xs_init(pTHX)
EXTERN_C void xs_init(pTHX)
{
char *file = __FILE__;
dXSUB_SYS;
+282 -301
View File
@@ -3,336 +3,317 @@
#define sanity_check(x) do { if (!session) { switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "session is not initalized\n"); return x;}} while(0)
#define init_vars() do { caller_profile.source = "mod_python"; swapstate = S_SWAPPED_IN; } while(0)
PySession::PySession() : CoreSession()
PySession::PySession():CoreSession()
{
init_vars();
}
PySession::PySession(char *uuid) : CoreSession(uuid)
PySession::PySession(char *uuid):CoreSession(uuid)
{
init_vars();
}
PySession::PySession(switch_core_session_t *new_session) : CoreSession(new_session)
PySession::PySession(switch_core_session_t *new_session):CoreSession(new_session)
{
init_vars();
}
void PySession::setDTMFCallback(PyObject *pyfunc, char *funcargs)
void PySession::setDTMFCallback(PyObject * pyfunc, char *funcargs)
{
sanity_check();
sanity_check();
if (!PyCallable_Check(pyfunc)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "DTMF function is not a python function.\n");
return;
}
Py_XINCREF(pyfunc);
CoreSession::setDTMFCallback((void *) pyfunc, funcargs);
}
void PySession::setHangupHook(PyObject * pyfunc)
{
if (!PyCallable_Check(pyfunc)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Hangup hook is not a python function.\n");
return;
}
// without this Py_XINCREF, there will be segfaults. basically the python
// interpreter will not know that it should not GC this object.
// callback example: http://docs.python.org/ext/callingPython.html
Py_XINCREF(pyfunc);
CoreSession::setHangupHook((void *) pyfunc);
}
void PySession::check_hangup_hook()
{
PyObject *func;
PyObject *result;
char *resultStr;
bool did_swap_in = false;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
"check_hangup_hook has been DISABLED, please do not use hangup hooks in python code until further notice!\n");
if (!session) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "No valid session\n");
return;
}
if (!PyCallable_Check(pyfunc)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "DTMF function is not a python function.\n");
return;
}
Py_XINCREF(pyfunc);
CoreSession::setDTMFCallback((void *) pyfunc, funcargs);
/*! NEEDS TO BE FIXED:
// The did_swap_in boolean was added to fix the following problem:
// Design flaw - we swap in threadstate based on the assumption that thread state
// is currently _swapped out_ when this hangup hook is called. However, nothing known to
// guarantee that, and if thread state is already swapped in when this is invoked,
// bad things will happen.
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "check hangup hook end_allow_threads\n");
did_swap_in = end_allow_threads();
if (on_hangup == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "on_hangup is null\n");
return;
}
func = (PyObject *) on_hangup;
// TODO: to match js implementation, should pass the _python_ PySession
// object instance wrapping this C++ PySession instance. but how do we do that?
// for now, pass the uuid since its better than nothing
PyObject* func_arg = Py_BuildValue("(s)", uuid);
result = PyEval_CallObject(func, func_arg);
Py_XDECREF(func_arg);
if (result) {
resultStr = (char *) PyString_AsString(result);
// currently just ignore the result
}
else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to call python hangup callback\n");
PyErr_Print();
PyErr_Clear();
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "check hangup hook begin_allow_threads\n");
if (did_swap_in) {
begin_allow_threads();
}
Py_XDECREF(result);
*/
}
switch_status_t PySession::run_dtmf_callback(void *input, switch_input_type_t itype)
{
PyObject *func, *arglist;
PyObject *pyresult;
PyObject *headerdict;
char *resultStr;
char *funcargs;
switch_file_handle_t *fh = NULL;
bool did_swap_in = false;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "run_dtmf_callback\n");
if (!cb_state.function) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "cb_state->function is null\n");
return SWITCH_STATUS_FALSE;
}
func = (PyObject *) cb_state.function;
if (!func) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "cb_state->function is null\n");
return SWITCH_STATUS_FALSE;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "cb_state->function is NOT null\n");
}
if (!PyCallable_Check(func)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "function not callable\n");
return SWITCH_STATUS_FALSE;
}
funcargs = (char *) cb_state.funcargs;
if (itype == SWITCH_INPUT_TYPE_DTMF) {
arglist = Py_BuildValue("(sis)", input, itype, funcargs);
} else if (itype == SWITCH_INPUT_TYPE_EVENT) {
// DUNNO if this is correct in the case we have an event
// will be of type switch_event_t *event;
// http://www.freeswitch.org/docs/structswitch__event.html
switch_event_t *event = (switch_event_t *) input;
arglist = Py_BuildValue("({s:s}is)", "body", event->body, itype, funcargs);
// build a dictionary with all the headers
switch_event_header_t *hp;
headerdict = PyDict_New();
for (hp = event->headers; hp; hp = hp->next) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Adding event header to result");
// TODO: create PyObject pointers for name and value
// and explicitly decref them. all ref counting stuff is
// a mess and needs to be tested and looked at closer.
PyDict_SetItem(headerdict, Py_BuildValue("s", hp->name), Py_BuildValue("s", hp->value));
}
// add it to the main event dictionary (first arg in list)
// under key 'headers'
PyObject *dict = PyTuple_GetItem(arglist, 0);
PyDict_SetItemString(dict, "headers", headerdict);
Py_XDECREF(headerdict);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unknown input type: %d\n", itype);
return SWITCH_STATUS_FALSE;
}
if (!arglist) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error building arglist");
return SWITCH_STATUS_FALSE;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "run_dtmf_callback end_allow_threads\n");
did_swap_in = end_allow_threads();
pyresult = PyEval_CallObject(func, arglist);
Py_XDECREF(arglist); // Trash arglist
if (pyresult && pyresult != Py_None) {
resultStr = (char *) PyString_AsString(pyresult);
switch_status_t cbresult = process_callback_result(resultStr);
return cbresult;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Python callback\n returned None");
PyErr_Print();
PyErr_Clear();
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "run_dtmf_callback begin_allow_threads\n");
if (did_swap_in) {
begin_allow_threads();
}
Py_XDECREF(pyresult);
return SWITCH_STATUS_SUCCESS;
}
bool PySession::begin_allow_threads(void)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "PySession::begin_allow_threads() called\n");
if (!session) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "No valid session\n");
return false;
}
// swap out threadstate and store in instance variable
switch_channel_t *channel = switch_core_session_get_channel(session);
PyThreadState *swapin_tstate = (PyThreadState *) switch_channel_get_private(channel, "SwapInThreadState");
// so lets assume the thread state was swapped in when the python script was started,
// therefore swapin_tstate will be NULL (because there is nothing to swap in, since its
// _already_ swapped in.)
if (swapin_tstate == NULL) {
// currently swapped in
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Threadstate swap-out!\n");
swapin_tstate = PyEval_SaveThread();
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "swapin_tstate: %p\n", swapin_tstate);
// give future swapper-inners something to actually swap in
switch_channel_set_private(channel, "SwapInThreadState", (void *) swapin_tstate);
cb_state.threadState = threadState; // TODO: get rid of this
args.buf = &cb_state;
ap = &args;
return true;
} else {
// currently swapped out
return false;
}
}
bool PySession::end_allow_threads(void)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "PySession::end_allow_threads() called\n");
// swap in threadstate from instance variable saved earlier
if (!session) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "No valid session\n");
return false;
}
switch_channel_t *channel = switch_core_session_get_channel(session);
PyThreadState *swapin_tstate = (PyThreadState *) switch_channel_get_private(channel, "SwapInThreadState");
if (swapin_tstate == NULL) {
// currently swapped in
return false;
} else {
// currently swapped out
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Threadstate swap-in!\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "swapin_tstate: %p\n", swapin_tstate);
PyEval_RestoreThread(swapin_tstate);
// dont give any swapper-inners the opportunity to do a double swap
switch_channel_set_private(channel, "SwapInThreadState", NULL);
return true;
}
}
void PySession::setHangupHook(PyObject *pyfunc) {
void PySession::hangup(char *cause)
{
if (!PyCallable_Check(pyfunc)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Hangup hook is not a python function.\n");
return;
}
// without this Py_XINCREF, there will be segfaults. basically the python
// interpreter will not know that it should not GC this object.
// callback example: http://docs.python.org/ext/callingPython.html
Py_XINCREF(pyfunc);
CoreSession::setHangupHook((void *) pyfunc);
// since we INCREF'd this function pointer earlier (so the py gc didnt reclaim it)
// we have to DECREF it, or else the PySession dtor will never get called and
// a zombie channel will be left over using up resources
if (cb_state.function != NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "xdecref on cb_state_function\n");
PyObject *func = (PyObject *) cb_state.function;
Py_XDECREF(func);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "cb_state.function is null\n");
}
CoreSession::hangup(cause);
}
void PySession::check_hangup_hook() {
PyObject *func;
PyObject *result;
char *resultStr;
bool did_swap_in = false;
PySession::~PySession()
{
// Should we do any cleanup here?
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "PySession::~PySession started\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "check_hangup_hook has been DISABLED, please do not use hangup hooks in python code until further notice!\n");
if (!session) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "No valid session\n");
return;
}
return;
/*! NEEDS TO BE FIXED:
// The did_swap_in boolean was added to fix the following problem:
// Design flaw - we swap in threadstate based on the assumption that thread state
// is currently _swapped out_ when this hangup hook is called. However, nothing known to
// guarantee that, and if thread state is already swapped in when this is invoked,
// bad things will happen.
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "check hangup hook end_allow_threads\n");
did_swap_in = end_allow_threads();
if (on_hangup == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "on_hangup is null\n");
return;
}
func = (PyObject *) on_hangup;
// TODO: to match js implementation, should pass the _python_ PySession
// object instance wrapping this C++ PySession instance. but how do we do that?
// for now, pass the uuid since its better than nothing
PyObject* func_arg = Py_BuildValue("(s)", uuid);
result = PyEval_CallObject(func, func_arg);
Py_XDECREF(func_arg);
if (result) {
resultStr = (char *) PyString_AsString(result);
// currently just ignore the result
}
else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to call python hangup callback\n");
PyErr_Print();
PyErr_Clear();
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "check hangup hook begin_allow_threads\n");
if (did_swap_in) {
begin_allow_threads();
}
Py_XDECREF(result);
*/
}
switch_status_t PySession::run_dtmf_callback(void *input,
switch_input_type_t itype) {
PyObject *func, *arglist;
PyObject *pyresult;
PyObject *headerdict;
char *resultStr;
char *funcargs;
switch_file_handle_t *fh = NULL;
bool did_swap_in = false;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "run_dtmf_callback\n");
if (on_hangup) {
PyObject *func = (PyObject *) on_hangup;
Py_XDECREF(func);
}
if (!cb_state.function) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "cb_state->function is null\n");
return SWITCH_STATUS_FALSE;
}
if (cb_state.function != NULL) {
PyObject *func = (PyObject *) cb_state.function;
Py_XDECREF(func);
}
func = (PyObject *) cb_state.function;
if (!func) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "cb_state->function is null\n");
return SWITCH_STATUS_FALSE;
}
else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "cb_state->function is NOT null\n");
}
if (!PyCallable_Check(func)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "function not callable\n");
return SWITCH_STATUS_FALSE;
}
funcargs = (char *) cb_state.funcargs;
if (itype == SWITCH_INPUT_TYPE_DTMF) {
arglist = Py_BuildValue("(sis)", input, itype, funcargs);
}
else if (itype == SWITCH_INPUT_TYPE_EVENT) {
// DUNNO if this is correct in the case we have an event
// will be of type switch_event_t *event;
// http://www.freeswitch.org/docs/structswitch__event.html
switch_event_t *event = (switch_event_t *) input;
arglist = Py_BuildValue("({s:s}is)",
"body", event->body,
itype,
funcargs);
// build a dictionary with all the headers
switch_event_header_t *hp;
headerdict = PyDict_New();
for (hp = event->headers; hp; hp = hp->next) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Adding event header to result");
// TODO: create PyObject pointers for name and value
// and explicitly decref them. all ref counting stuff is
// a mess and needs to be tested and looked at closer.
PyDict_SetItem(headerdict,
Py_BuildValue("s", hp->name),
Py_BuildValue("s", hp->value));
}
// add it to the main event dictionary (first arg in list)
// under key 'headers'
PyObject *dict = PyTuple_GetItem(arglist, 0);
PyDict_SetItemString(dict,
"headers",
headerdict);
Py_XDECREF(headerdict);
}
else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unknown input type: %d\n", itype);
return SWITCH_STATUS_FALSE;
}
if (!arglist) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error building arglist");
return SWITCH_STATUS_FALSE;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "run_dtmf_callback end_allow_threads\n");
did_swap_in = end_allow_threads();
pyresult = PyEval_CallObject(func, arglist);
Py_XDECREF(arglist); // Trash arglist
if (pyresult && pyresult != Py_None) {
resultStr = (char *) PyString_AsString(pyresult);
switch_status_t cbresult = process_callback_result(resultStr);
return cbresult;
}
else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Python callback\n returned None");
PyErr_Print();
PyErr_Clear();
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "run_dtmf_callback begin_allow_threads\n");
if (did_swap_in) {
begin_allow_threads();
}
Py_XDECREF(pyresult);
return SWITCH_STATUS_SUCCESS;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "PySession::~PySession finished\n");
}
bool PySession::begin_allow_threads(void) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "PySession::begin_allow_threads() called\n");
if (!session) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "No valid session\n");
return false;
}
// swap out threadstate and store in instance variable
switch_channel_t *channel = switch_core_session_get_channel(session);
PyThreadState *swapin_tstate = (PyThreadState *) switch_channel_get_private(channel, "SwapInThreadState");
// so lets assume the thread state was swapped in when the python script was started,
// therefore swapin_tstate will be NULL (because there is nothing to swap in, since its
// _already_ swapped in.)
if (swapin_tstate == NULL) {
// currently swapped in
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Threadstate swap-out!\n");
swapin_tstate = PyEval_SaveThread();
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "swapin_tstate: %p\n", swapin_tstate);
// give future swapper-inners something to actually swap in
switch_channel_set_private(channel, "SwapInThreadState", (void *) swapin_tstate);
cb_state.threadState = threadState; // TODO: get rid of this
args.buf = &cb_state;
ap = &args;
return true;
}
else {
// currently swapped out
return false;
}
}
bool PySession::end_allow_threads(void) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "PySession::end_allow_threads() called\n");
// swap in threadstate from instance variable saved earlier
if (!session) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "No valid session\n");
return false;
}
switch_channel_t *channel = switch_core_session_get_channel(session);
PyThreadState *swapin_tstate = (PyThreadState *) switch_channel_get_private(channel, "SwapInThreadState");
if (swapin_tstate == NULL) {
// currently swapped in
return false;
}
else {
// currently swapped out
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Threadstate swap-in!\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "swapin_tstate: %p\n", swapin_tstate);
PyEval_RestoreThread(swapin_tstate);
// dont give any swapper-inners the opportunity to do a double swap
switch_channel_set_private(channel, "SwapInThreadState", NULL);
return true;
}
}
void PySession::hangup(char *cause) {
// since we INCREF'd this function pointer earlier (so the py gc didnt reclaim it)
// we have to DECREF it, or else the PySession dtor will never get called and
// a zombie channel will be left over using up resources
if (cb_state.function != NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "xdecref on cb_state_function\n");
PyObject * func = (PyObject *) cb_state.function;
Py_XDECREF(func);
}
else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "cb_state.function is null\n");
}
CoreSession::hangup(cause);
}
PySession::~PySession() {
// Should we do any cleanup here?
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "PySession::~PySession started\n");
if (on_hangup) {
PyObject * func = (PyObject *) on_hangup;
Py_XDECREF(func);
}
if (cb_state.function != NULL) {
PyObject * func = (PyObject *) cb_state.function;
Py_XDECREF(func);
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "PySession::~PySession finished\n");
}
+76 -82
View File
@@ -58,7 +58,7 @@ static void eval_some_python(char *uuid, char *args, switch_core_session_t *sess
{
PyThreadState *tstate = NULL;
char *dupargs = NULL;
char *argv[128] = {0};
char *argv[128] = { 0 };
int argc;
int lead = 0;
char *script = NULL;
@@ -68,16 +68,16 @@ static void eval_some_python(char *uuid, char *args, switch_core_session_t *sess
PyObject *result = NULL;
if (args) {
dupargs = strdup(args);
dupargs = strdup(args);
} else {
return;
return;
}
assert(dupargs != NULL);
if (!(argc = switch_separate_string(dupargs, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No module name specified!\n");
goto done;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No module name specified!\n");
goto done;
}
script = argv[0];
@@ -87,80 +87,76 @@ static void eval_some_python(char *uuid, char *args, switch_core_session_t *sess
tstate = PyThreadState_New(mainThreadState->interp);
if (!tstate) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error acquiring tstate\n");
goto done;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error acquiring tstate\n");
goto done;
}
// swap in thread state
PyEval_AcquireThread(tstate);
if (session) {
// record the fact that thread state is swapped in
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_channel_set_private(channel, "SwapInThreadState", NULL);
// record the fact that thread state is swapped in
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_channel_set_private(channel, "SwapInThreadState", NULL);
}
init_freeswitch();
init_freeswitch();
// import the module
module = PyImport_ImportModule( (char *) script);
module = PyImport_ImportModule((char *) script);
if (!module) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error importing module\n");
PyErr_Print();
PyErr_Clear();
goto done_swap_out;
}
// reload the module
module = PyImport_ReloadModule(module);
if (!module) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error reloading module\n");
PyErr_Print();
PyErr_Clear();
goto done_swap_out;
}
// get the handler function to be called
function = PyObject_GetAttrString(module, "handler");
if (!function) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Module does not define handler(uuid)\n");
PyErr_Print();
PyErr_Clear();
goto done_swap_out;
}
if (uuid) {
// build a tuple to pass the args, the uuid of session
arg = Py_BuildValue("(s)", uuid);
if (!arg) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error building args\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error importing module\n");
PyErr_Print();
PyErr_Clear();
goto done_swap_out;
}
}
else {
arg = PyTuple_New(1);
PyObject *nada = Py_BuildValue("");
PyTuple_SetItem(arg, 0, nada);
// reload the module
module = PyImport_ReloadModule(module);
if (!module) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error reloading module\n");
PyErr_Print();
PyErr_Clear();
goto done_swap_out;
}
// get the handler function to be called
function = PyObject_GetAttrString(module, "handler");
if (!function) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Module does not define handler(uuid)\n");
PyErr_Print();
PyErr_Clear();
goto done_swap_out;
}
if (uuid) {
// build a tuple to pass the args, the uuid of session
arg = Py_BuildValue("(s)", uuid);
if (!arg) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error building args\n");
PyErr_Print();
PyErr_Clear();
goto done_swap_out;
}
} else {
arg = PyTuple_New(1);
PyObject *nada = Py_BuildValue("");
PyTuple_SetItem(arg, 0, nada);
}
// invoke the handler
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Call python script \n");
result = PyEval_CallObjectWithKeywords(function, arg, (PyObject *)NULL);
result = PyEval_CallObjectWithKeywords(function, arg, (PyObject *) NULL);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Finished calling python script \n");
// check the result and print out any errors
if (!result) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error calling python script\n");
PyErr_Print();
PyErr_Clear();
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error calling python script\n");
PyErr_Print();
PyErr_Clear();
}
goto done_swap_out;
done:
done:
switch_safe_free(dupargs);
done_swap_out:
done_swap_out:
// decrement ref counts
Py_XDECREF(module);
Py_XDECREF(function);
@@ -183,14 +179,12 @@ static void eval_some_python(char *uuid, char *args, switch_core_session_t *sess
PyThreadState *cur_tstate = PyThreadState_Get();
PyThreadState_Clear(cur_tstate);
PyEval_ReleaseThread(cur_tstate);
PyThreadState_Delete(cur_tstate);
}
else {
PyThreadState_Delete(cur_tstate);
} else {
// thread state is already swapped out, so, nothing for us to do
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "according to chan priv data, already swapped out \n");
}
}
else {
} else {
// they ran python script from cmd line, behave a bit differently (untested)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "No session: Threadstate mod_python.c swap-out! \n");
PyEval_ReleaseThread(tstate);
@@ -203,8 +197,8 @@ static void eval_some_python(char *uuid, char *args, switch_core_session_t *sess
SWITCH_STANDARD_APP(python_function)
{
eval_some_python(switch_core_session_get_uuid(session), (char *)data, session);
eval_some_python(switch_core_session_get_uuid(session), (char *) data, session);
}
struct switch_py_thread {
@@ -228,7 +222,7 @@ static void *SWITCH_THREAD_FUNC py_thread_run(switch_thread_t *thread, void *obj
SWITCH_STANDARD_API(launch_python)
{
switch_thread_t *thread;
switch_threadattr_t *thd_attr = NULL;
switch_threadattr_t *thd_attr = NULL;
switch_memory_pool_t *pool;
struct switch_py_thread *pt;
@@ -236,7 +230,7 @@ SWITCH_STANDARD_API(launch_python)
stream->write_function(stream, "USAGE: %s\n", python_run_interface.syntax);
return SWITCH_STATUS_SUCCESS;
}
switch_core_new_memory_pool(&pool);
assert(pool != NULL);
@@ -245,11 +239,11 @@ SWITCH_STANDARD_API(launch_python)
pt->pool = pool;
pt->args = switch_core_strdup(pt->pool, cmd);
switch_threadattr_create(&thd_attr, pt->pool);
switch_threadattr_detach_set(thd_attr, 1);
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
switch_thread_create(&thread, thd_attr, py_thread_run, pt, pt->pool);
switch_threadattr_create(&thd_attr, pt->pool);
switch_threadattr_detach_set(thd_attr, 1);
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
switch_thread_create(&thread, thd_attr, py_thread_run, pt, pt->pool);
stream->write_function(stream, "OK\n");
return SWITCH_STATUS_SUCCESS;
@@ -290,7 +284,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_python_load)
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &python_module_interface;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Python Framework Loading...\n");
if (!Py_IsInitialized()) {
// initialize python system
@@ -302,13 +296,13 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_python_load)
// save threadstate since it's interp field will be needed
// to create new threadstates, and will be needed for shutdown
mainThreadState = PyThreadState_Get();
// swap out threadstate since the call threads will create
// their own and swap in their threadstate
PyThreadState_Swap(NULL);
PyThreadState_Swap(NULL);
// release GIL
PyEval_ReleaseLock();
PyEval_ReleaseLock();
}
/* indicate that the module should continue to be loaded */
@@ -319,18 +313,18 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_python_load)
Called when the system shuts down*/
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_python_shutdown)
{
PyInterpreterState *mainInterpreterState;
PyThreadState *myThreadState;
PyInterpreterState *mainInterpreterState;
PyThreadState *myThreadState;
PyEval_AcquireLock();
mainInterpreterState = mainThreadState->interp;
myThreadState = PyThreadState_New(mainInterpreterState);
PyThreadState_Swap(myThreadState);
PyEval_ReleaseLock();
PyEval_AcquireLock();
mainInterpreterState = mainThreadState->interp;
myThreadState = PyThreadState_New(mainInterpreterState);
PyThreadState_Swap(myThreadState);
PyEval_ReleaseLock();
Py_Finalize();
PyEval_ReleaseLock();
return SWITCH_STATUS_SUCCESS;
Py_Finalize();
PyEval_ReleaseLock();
return SWITCH_STATUS_SUCCESS;
}
File diff suppressed because it is too large. Load diff
@@ -571,7 +571,7 @@ extern "C" {
* type checking.
*
* Author : David Beazley (beazley@cs.uchicago.edu)
************************************************************************//* Common SWIG API */
************************************************************************//* Common SWIG API */
#define SWIG_ConvertPtr(obj, pp, type, flags) SWIG_Python_ConvertPtr(obj, pp, type, flags)
#define SWIG_NewPointerObj(p, type, flags) SWIG_Python_NewPointerObj(p, type, flags)
#define SWIG_MustGetPtr(p, type, argnum, flags) SWIG_Python_MustGetPtr(p, type, argnum, flags)
@@ -583,11 +583,11 @@ extern "C" {
#define SWIG_SetModule(clientdata, pointer) SWIG_Python_SetModule(pointer)
/* -----------------------------------------------------------------------------
* Pointer declarations
* ----------------------------------------------------------------------------- *//*
Use SWIG_NO_COBJECT_TYPES to force the use of strings to represent
C/C++ pointers in the python side. Very useful for debugging, but
not always safe.
*/
* ----------------------------------------------------------------------------- *//*
Use SWIG_NO_COBJECT_TYPES to force the use of strings to represent
C/C++ pointers in the python side. Very useful for debugging, but
not always safe.
*/
#if !defined(SWIG_NO_COBJECT_TYPES) && !defined(SWIG_COBJECT_TYPES)
# define SWIG_COBJECT_TYPES
#endif
@@ -1538,8 +1538,7 @@ extern "C" {
resultobj = Py_None;
return resultobj;
fail:return NULL;
}
static PyObject *_wrap_fs_core_init(PyObject * self, PyObject * args) {
} static PyObject *_wrap_fs_core_init(PyObject * self, PyObject * args) {
PyObject *resultobj = NULL;
char *arg1 = (char *) 0;
int result;
@@ -2683,8 +2682,7 @@ extern "C" {
SWIGINTERN PyObject *swig_varlink_repr(swig_varlinkobject * v) {
v = v;
return PyString_FromString("<Swig global variables>");
}
SWIGINTERN int swig_varlink_print(swig_varlinkobject * v, FILE * fp, int flags) {
} SWIGINTERN int swig_varlink_print(swig_varlinkobject * v, FILE * fp, int flags) {
swig_globalvar *var;
flags = flags;
fprintf(fp, "Swig global variables { ");
@@ -184,7 +184,7 @@ static JSBool request_write(JSContext * cx, JSObject * obj, uintN argc, jsval *
return JS_TRUE;
}
static JSBool request_add_header(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool request_add_header(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
struct request_obj *ro = JS_GetPrivate(cx, obj);
@@ -226,7 +226,7 @@ static JSBool request_get_header(JSContext * cx, JSObject * obj, uintN argc, jsv
return JS_TRUE;
}
static JSBool request_dump_env(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool request_dump_env(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
struct request_obj *ro = JS_GetPrivate(cx, obj);
char *how = "text";
@@ -244,10 +244,10 @@ static JSBool request_dump_env(JSContext *cx, JSObject *obj, uintN argc, jsval *
switch_xml_t xml;
char *xmlstr;
if ((xml = switch_event_xmlize(ro->stream->param_event, SWITCH_VA_NONE))) {
xmlstr = switch_xml_toxml(xml, SWITCH_FALSE);
xmlstr = switch_xml_toxml(xml, SWITCH_FALSE);
*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, xmlstr));
return JS_TRUE;
}
}
} else {
char *buf;
switch_event_serialize(ro->stream->param_event, &buf, SWITCH_TRUE);
@@ -264,7 +264,7 @@ static JSBool request_dump_env(JSContext *cx, JSObject *obj, uintN argc, jsval *
static void request_destroy(JSContext * cx, JSObject * obj)
{
}
enum request_tinyid {
@@ -284,7 +284,7 @@ static JSPropertySpec request_props[] = {
{0}
};
static JSBool request_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
static JSBool request_getProperty(JSContext * cx, JSObject * obj, jsval id, jsval * vp)
{
JSBool res = JS_TRUE;
struct request_obj *ro = JS_GetPrivate(cx, obj);
@@ -320,12 +320,11 @@ JSClass request_class = {
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, request_destroy, NULL, NULL, NULL, NULL
};
static JSObject *new_request(JSContext *cx, JSObject *obj, struct request_obj *ro)
static JSObject *new_request(JSContext * cx, JSObject * obj, struct request_obj *ro)
{
JSObject *Request;
if ((Request = JS_DefineObject(cx, obj, "request", &request_class, NULL, 0))) {
if ((JS_SetPrivate(cx, Request, ro) &&
JS_DefineProperties(cx, Request, request_props) && JS_DefineFunctions(cx, Request, request_methods))) {
if ((JS_SetPrivate(cx, Request, ro) && JS_DefineProperties(cx, Request, request_props) && JS_DefineFunctions(cx, Request, request_methods))) {
return Request;
}
}
@@ -375,12 +374,12 @@ static JSBool pcre_compile(JSContext * cx, JSObject * obj, uintN argc, jsval * a
char *string, *regex_string;
if (argc > 1) {
string = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
regex_string = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
string = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
regex_string = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
switch_regex_safe_free(pcre_obj->re);
switch_safe_free(pcre_obj->string);
pcre_obj->string = strdup(string);
pcre_obj->proceed = switch_regex_perform(pcre_obj->string, regex_string, &pcre_obj->re, pcre_obj->ovector,
pcre_obj->proceed = switch_regex_perform(pcre_obj->string, regex_string, &pcre_obj->re, pcre_obj->ovector,
sizeof(pcre_obj->ovector) / sizeof(pcre_obj->ovector[0]));
*rval = BOOLEAN_TO_JSVAL(pcre_obj->proceed ? JS_TRUE : JS_FALSE);
} else {
@@ -401,10 +400,10 @@ static JSBool pcre_substitute(JSContext * cx, JSObject * obj, uintN argc, jsval
eval_some_js("~throw new Error(\"REGEX is not compiled or has no matches\");", cx, obj, rval);
return JS_FALSE;
}
if (argc > 0) {
uint32_t len;
subst_string = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
subst_string = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
len = (uint32_t) (strlen(pcre_obj->string) + strlen(subst_string) + 10);
substituted = malloc(len);
switch_assert(substituted != NULL);
@@ -841,7 +840,7 @@ static JSBool dtmf_getProperty(JSContext * cx, JSObject * obj, jsval id, jsval *
case DTMF_DURATION:
{
*vp = INT_TO_JSVAL((int)dtmf->duration);
*vp = INT_TO_JSVAL((int) dtmf->duration);
}
break;
}
@@ -1097,10 +1096,10 @@ static switch_status_t js_common_callback(switch_core_session_t *session, void *
uintN argc = 0;
jsval argv[4];
JSObject *Event = NULL;
jsval nval , *rval = &nval;
jsval nval, *rval = &nval;
JSContext *cx = cb_state->cx;
JSObject *obj = cb_state->obj;
METHOD_SANITY_CHECK();
jss->stack_depth++;
@@ -1126,10 +1125,10 @@ static switch_status_t js_common_callback(switch_core_session_t *session, void *
return SWITCH_STATUS_FALSE;
}
break;
case SWITCH_INPUT_TYPE_DTMF:
case SWITCH_INPUT_TYPE_DTMF:
{
switch_dtmf_t *dtmf = (switch_dtmf_t *) input;
if (dtmf) {
if ((Event = new_js_dtmf(dtmf, "_XX_DTMF_XX_", cb_state->cx, cb_state->obj))) {
argv[argc++] = STRING_TO_JSVAL(JS_NewStringCopyZ(cb_state->cx, "dtmf"));
@@ -1624,7 +1623,7 @@ static JSBool session_streamfile(JSContext * cx, JSObject * obj, uintN argc, jsv
switch_input_args_t args = { 0 };
const char *prebuf;
char posbuf[35] = "";
METHOD_SANITY_CHECK();
channel = switch_core_session_get_channel(jss->session);
CHANNEL_SANITY_CHECK();
@@ -1660,13 +1659,13 @@ static JSBool session_streamfile(JSContext * cx, JSObject * obj, uintN argc, jsv
JS_ValueToInt32(cx, argv[3], &samps);
fh.samples = samps;
}
if ((prebuf = switch_channel_get_variable(channel, "stream_prebuffer"))) {
int maybe = atoi(prebuf);
if (maybe > 0) {
fh.prebuf = maybe;
}
}
if ((prebuf = switch_channel_get_variable(channel, "stream_prebuffer"))) {
int maybe = atoi(prebuf);
if (maybe > 0) {
fh.prebuf = maybe;
}
}
cb_state.extra = &fh;
cb_state.ret = BOOLEAN_TO_JSVAL(JS_FALSE);
@@ -1825,7 +1824,7 @@ static JSBool session_speak(JSContext * cx, JSObject * obj, uintN argc, jsval *
if (jss->speech && strcasecmp(jss->speech->sh.name, tts_name)) {
destroy_speech_engine(jss);
}
if (jss->speech) {
switch_core_speech_text_param_tts(&jss->speech->sh, "voice", voice_name);
} else {
@@ -1861,7 +1860,7 @@ static JSBool session_speak(JSContext * cx, JSObject * obj, uintN argc, jsval *
args.input_callback = dtmf_func;
args.buf = bp;
args.buflen = len;
switch_core_speech_flush_tts(&jss->speech->sh);
switch_ivr_speak_text_handle(jss->session, &jss->speech->sh, &jss->speech->codec, NULL, text, &args);
JS_ResumeRequest(cx, cb_state.saveDepth);
@@ -2174,12 +2173,11 @@ static JSBool session_hangup(JSContext * cx, JSObject * obj, uintN argc, jsval *
CHANNEL_SANITY_CHECK();
if (argc > 1) {
if(JSVAL_IS_INT(argv[0])) {
if (JSVAL_IS_INT(argv[0])) {
int32 i = 0;
JS_ValueToInt32(cx, argv[0], &i);
cause = i;
}
else {
} else {
cause_name = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
cause = switch_channel_str2cause(cause_name);
}
@@ -2204,7 +2202,7 @@ struct fetch_url_data {
JSObject *obj;
switch_size_t buffer_size;
switch_size_t data_len;
char* buffer;
char *buffer;
};
static size_t hash_callback(void *ptr, size_t size, size_t nmemb, void *data)
@@ -2257,7 +2255,7 @@ static size_t file_callback(void *ptr, size_t size, size_t nmemb, void *data)
register unsigned int realsize = (unsigned int) (size * nmemb);
struct config_data *config_data = data;
if ((write(config_data->fd, ptr, realsize) != (int)realsize)) {
if ((write(config_data->fd, ptr, realsize) != (int) realsize)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to write all bytes!\n");
}
return realsize;
@@ -2412,7 +2410,7 @@ static JSBool js_fetchurl(JSContext * cx, JSObject * obj, uintN argc, jsval * ar
*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, config_data.buffer));
} else {
char errmsg[256];
switch_snprintf(errmsg, 256, "~throw new Error(\"Curl returned error %u.\");", (unsigned)code);
switch_snprintf(errmsg, 256, "~throw new Error(\"Curl returned error %u.\");", (unsigned) code);
eval_some_js(errmsg, cx, obj, rval);
}
@@ -2593,7 +2591,7 @@ static JSObject *new_js_session(JSContext * cx, JSObject * obj, switch_core_sess
*jss = malloc(sizeof(**jss));
switch_assert(*jss);
memset(*jss, 0, sizeof(**jss));
(*jss)->session = session;
(*jss)->flags = flags;
(*jss)->cx = cx;
@@ -2628,7 +2626,7 @@ static JSBool session_construct(JSContext * cx, JSObject * obj, uintN argc, jsva
jss->cx = cx;
jss->obj = obj;
JS_SetPrivate(cx, obj, jss);
if (argc > 0) {
char *uuid = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
if (uuid) {
@@ -2649,7 +2647,7 @@ static JSBool session_set_callerdata(JSContext * cx, JSObject * obj, uintN argc,
char *var, *val, **toset = NULL;
var = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
val = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
if (!strcasecmp(var, "dialplan")) {
toset = &jss->dialplan;
} else if (!strcasecmp(var, "username")) {
@@ -2670,15 +2668,15 @@ static JSBool session_set_callerdata(JSContext * cx, JSObject * obj, uintN argc,
toset = &jss->destination_number;
} else if (!strcasecmp(var, "context")) {
toset = &jss->context;
}
}
if (toset) {
switch_safe_free(*toset);
*toset = strdup(val);
}
}
return JS_TRUE;
}
@@ -2727,14 +2725,22 @@ static JSBool session_originate(JSContext * cx, JSObject * obj, uintN argc, jsva
}
}
if (!switch_strlen_zero(jss->dialplan)) dialplan = jss->dialplan;
if (!switch_strlen_zero(jss->caller_id_name)) cid_name = jss->caller_id_name;
if (!switch_strlen_zero(jss->caller_id_number)) cid_num = jss->caller_id_number;
if (!switch_strlen_zero(jss->ani)) ani = jss->ani;
if (!switch_strlen_zero(jss->aniii)) aniii = jss->aniii;
if (!switch_strlen_zero(jss->rdnis)) rdnis = jss->rdnis;
if (!switch_strlen_zero(jss->context)) context = jss->context;
if (!switch_strlen_zero(jss->username)) username = jss->username;
if (!switch_strlen_zero(jss->dialplan))
dialplan = jss->dialplan;
if (!switch_strlen_zero(jss->caller_id_name))
cid_name = jss->caller_id_name;
if (!switch_strlen_zero(jss->caller_id_number))
cid_num = jss->caller_id_number;
if (!switch_strlen_zero(jss->ani))
ani = jss->ani;
if (!switch_strlen_zero(jss->aniii))
aniii = jss->aniii;
if (!switch_strlen_zero(jss->rdnis))
rdnis = jss->rdnis;
if (!switch_strlen_zero(jss->context))
context = jss->context;
if (!switch_strlen_zero(jss->username))
username = jss->username;
dest = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
@@ -2747,16 +2753,15 @@ static JSBool session_originate(JSContext * cx, JSObject * obj, uintN argc, jsva
tmp = JS_GetStringBytes(JS_ValueToString(cx, argv[2]));
if (!switch_strlen_zero(tmp)) {
to = tmp;
}
}
}
if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "OH OH no pool\n");
return JS_FALSE;
}
caller_profile = switch_caller_profile_new(pool,username, dialplan, cid_name, cid_num, network_addr,
ani, aniii, rdnis, modname, context, dest);
caller_profile = switch_caller_profile_new(pool, username, dialplan, cid_name, cid_num, network_addr, ani, aniii, rdnis, modname, context, dest);
saveDepth = JS_SuspendRequest(cx);
status = switch_ivr_originate(session, &peer_session, &jss->cause, dest, to ? atoi(to) : 60, NULL, NULL, NULL, caller_profile, SOF_NONE);
@@ -2766,7 +2771,7 @@ static JSBool session_originate(JSContext * cx, JSObject * obj, uintN argc, jsva
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cannot Create Outgoing Channel! [%s]\n", dest);
goto done;
}
jss->session = peer_session;
switch_set_flag(jss, S_HUP);
*rval = BOOLEAN_TO_JSVAL(JS_TRUE);
@@ -2783,21 +2788,21 @@ static JSBool session_originate(JSContext * cx, JSObject * obj, uintN argc, jsva
static void session_destroy(JSContext * cx, JSObject * obj)
{
struct js_session *jss;
if (cx && obj) {
if ((jss = JS_GetPrivate(cx, obj))) {
JS_SetPrivate(cx, obj, NULL);
if (jss->speech && *jss->speech->sh.name) {
destroy_speech_engine(jss);
}
if (jss->session) {
switch_core_session_t *session = jss->session;
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_channel_set_private(channel, "jss", NULL);
switch_core_event_hook_remove_state_change(session, hanguphook);
if (switch_test_flag(jss, S_HUP)) {
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
}
@@ -2816,7 +2821,7 @@ static void session_destroy(JSContext * cx, JSObject * obj)
}
free(jss);
}
}
@@ -3025,7 +3030,7 @@ JSClass fileio_class = {
static JSBool js_exit(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
char *supplied_error, code_buf[256] = "";
if (argc > 0 && (supplied_error = JS_GetStringBytes(JS_ValueToString(cx, argv[0])))) {
switch_snprintf(code_buf, sizeof(code_buf), "~throw new Error(\"%s\");", supplied_error);
eval_some_js(code_buf, cx, obj, rval);
@@ -3078,7 +3083,7 @@ static JSBool js_global_set(JSContext * cx, JSObject * obj, uintN argc, jsval *
char *var_name = NULL, *val = NULL;
if (argc > 1) {
var_name = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
val = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
val = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
switch_core_set_variable(var_name, val);
return JS_TRUE;
}
@@ -3153,7 +3158,7 @@ static JSBool js_api_execute(JSContext * cx, JSObject * obj, uintN argc, jsval *
if (argc > 1) {
arg = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
}
if (argc > 2) {
JSObject *session_obj;
struct js_session *jss;
@@ -3384,7 +3389,7 @@ SWITCH_STANDARD_APP(js_dp_function)
js_parse_and_execute(session, data, NULL);
}
static void *SWITCH_THREAD_FUNC js_thread_run(switch_thread_t * thread, void *obj)
static void *SWITCH_THREAD_FUNC js_thread_run(switch_thread_t *thread, void *obj)
{
char *input_code = obj;
@@ -3419,17 +3424,17 @@ static void js_thread_launch(const char *text)
SWITCH_STANDARD_API(jsapi_function)
{
struct request_obj ro = {0};
struct request_obj ro = { 0 };
char *path_info = NULL;
if (stream->param_event) {
if (stream->param_event) {
path_info = switch_event_get_header(stream->param_event, "http-path-info");
}
if (switch_strlen_zero(cmd) && path_info) {
cmd = path_info;
}
if (switch_strlen_zero(cmd)) {
stream->write_function(stream, "USAGE: %s\n", jsapi_interface.syntax);
return SWITCH_STATUS_SUCCESS;
@@ -3456,14 +3461,14 @@ SWITCH_STANDARD_API(launch_async)
return SWITCH_STATUS_SUCCESS;
}
static void message_query_handler(switch_event_t *event)
static void message_query_handler(switch_event_t *event)
{
char *account = switch_event_get_header(event, "message-account");
if (account) {
char *path, *cmd;
path = switch_mprintf("%s%smwi.js", SWITCH_GLOBAL_dirs.script_dir, SWITCH_PATH_SEPARATOR);
path = switch_mprintf("%s%smwi.js", SWITCH_GLOBAL_dirs.script_dir, SWITCH_PATH_SEPARATOR);
switch_assert(path != NULL);
if (switch_file_exists(path, NULL) == SWITCH_STATUS_SUCCESS) {
@@ -3497,7 +3502,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_spidermonkey_load)
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
SWITCH_ADD_API(api_interface, "jsrun", "run a script", launch_async, "jsrun <script> [additional_vars [...]]");
SWITCH_ADD_API(api_interface, "jsapi", "execute an api call", jsapi_function, "jsapi <script> [additional_vars [...]]");
SWITCH_ADD_APP(app_interface, "javascript", "Launch JS ivr", "Run a javascript ivr on a channel", js_dp_function, "<script> [additional_vars [...]]", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "javascript", "Launch JS ivr", "Run a javascript ivr on a channel", js_dp_function, "<script> [additional_vars [...]]",
SAF_SUPPORT_NOMEDIA);
curl_global_init(CURL_GLOBAL_ALL);
@@ -73,10 +73,10 @@ static JSBool db_construct(JSContext * cx, JSObject * obj, uintN argc, jsval * a
return JS_FALSE;
}
static JSBool db_close(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool db_close(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
struct db_obj *dbo = JS_GetPrivate(cx, obj);
if (dbo) {
if (dbo->stmt) {
switch_core_db_finalize(dbo->stmt);
@@ -91,7 +91,7 @@ static JSBool db_close(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, js
return JS_TRUE;
}
static void db_destroy(JSContext *cx, JSObject *obj)
static void db_destroy(JSContext * cx, JSObject * obj)
{
struct db_obj *dbo = JS_GetPrivate(cx, obj);
@@ -215,7 +215,7 @@ static JSBool db_fetch(JSContext * cx, JSObject * obj, uintN argc, jsval * argv,
}
for (x = 0; x < colcount; x++) {
switch_snprintf(code, sizeof(code), "~_dB_RoW_DaTa_[\"%s\"] = \"%s\"",
(char *) switch_core_db_column_name(dbo->stmt, x), (char *) switch_core_db_column_text(dbo->stmt, x));
(char *) switch_core_db_column_name(dbo->stmt, x), (char *) switch_core_db_column_text(dbo->stmt, x));
eval_some_js(code, dbo->cx, dbo->obj, rval);
if (*rval == JS_FALSE) {
@@ -275,7 +275,7 @@ static JSPropertySpec db_props[] = {
};
static JSBool db_setProperty(JSContext * cx, JSObject * obj, jsval id, jsval *vp)
static JSBool db_setProperty(JSContext * cx, JSObject * obj, jsval id, jsval * vp)
{
char *name = JS_GetStringBytes(JS_ValueToString(cx, id));
@@ -332,7 +332,7 @@ const sm_module_interface_t DB_module_interface = {
/*.next */ NULL
};
SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t ** module_interface)
SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t **module_interface)
{
*module_interface = &DB_module_interface;
return SWITCH_STATUS_SUCCESS;
@@ -41,7 +41,7 @@ struct curl_obj {
JSFunction *function;
JSObject *user_data;
jsrefcount saveDepth;
jsval ret;
jsval ret;
};
@@ -51,21 +51,21 @@ static size_t file_callback(void *ptr, size_t size, size_t nmemb, void *data)
struct curl_obj *co = data;
uintN argc = 0;
jsval argv[4];
if (!co) {
return 0;
}
if (co->function) {
char *ret;
argv[argc++] = STRING_TO_JSVAL(JS_NewStringCopyZ(co->cx, (char *)ptr));
argv[argc++] = STRING_TO_JSVAL(JS_NewStringCopyZ(co->cx, (char *) ptr));
if (co->user_data) {
argv[argc++] = OBJECT_TO_JSVAL(co->user_data);
}
JS_ResumeRequest(co->cx, co->saveDepth);
JS_CallFunction(co->cx, co->obj, co->function, argc, argv, &co->ret);
co->saveDepth = JS_SuspendRequest(co->cx);
if ((ret = JS_GetStringBytes(JS_ValueToString(co->cx, co->ret)))) {
if (!strcmp(ret, "true") || !strcmp(ret, "undefined")) {
return realsize;
@@ -81,7 +81,7 @@ static size_t file_callback(void *ptr, size_t size, size_t nmemb, void *data)
/* Curl Object */
/*********************************************************************************/
static JSBool curl_construct(JSContext *cx, JSObject *obj, uintN argc, jsval * argv, jsval * rval)
static JSBool curl_construct(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
struct curl_obj *co = NULL;
@@ -98,14 +98,14 @@ static JSBool curl_construct(JSContext *cx, JSObject *obj, uintN argc, jsval * a
return JS_TRUE;
}
static void curl_destroy(JSContext *cx, JSObject *obj)
static void curl_destroy(JSContext * cx, JSObject * obj)
{
struct curl_obj *co = JS_GetPrivate(cx, obj);
switch_safe_free(co);
JS_SetPrivate(cx, obj, NULL);
}
static JSBool curl_run(JSContext *cx, JSObject *obj, uintN argc, jsval * argv, jsval * rval)
static JSBool curl_run(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
struct curl_obj *co = JS_GetPrivate(cx, obj);
char *method = NULL, *url, *cred = NULL;
@@ -127,11 +127,11 @@ static JSBool curl_run(JSContext *cx, JSObject *obj, uintN argc, jsval * argv, j
curl_easy_setopt(co->curl_handle, CURLOPT_SSL_VERIFYHOST, 0);
}
headers = curl_slist_append(headers, "Content-Type: application/x-www-form-urlencoded");
if (argc > 2) {
data = JS_GetStringBytes(JS_ValueToString(cx, argv[2]));
}
if (argc > 3) {
co->function = JS_ValueToFunction(cx, argv[3]);
}
@@ -148,7 +148,7 @@ static JSBool curl_run(JSContext *cx, JSObject *obj, uintN argc, jsval * argv, j
}
}
curl_easy_setopt(co->curl_handle, CURLOPT_HTTPHEADER, headers);
url_p = url;
@@ -164,7 +164,7 @@ static JSBool curl_run(JSContext *cx, JSObject *obj, uintN argc, jsval * argv, j
url_p = durl;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Running: method: [%s] url: [%s] data: [%s] cred=[%s] cb: [%s]\n",
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Running: method: [%s] url: [%s] data: [%s] cred=[%s] cb: [%s]\n",
method, url_p, data, switch_str_nil(cred), co->function ? "yes" : "no");
curl_easy_setopt(co->curl_handle, CURLOPT_URL, url_p);
@@ -172,7 +172,7 @@ static JSBool curl_run(JSContext *cx, JSObject *obj, uintN argc, jsval * argv, j
curl_easy_setopt(co->curl_handle, CURLOPT_WRITEDATA, (void *) co);
curl_easy_setopt(co->curl_handle, CURLOPT_USERAGENT, "freeswitch-spidermonkey-curl/1.0");
co->saveDepth = JS_SuspendRequest(cx);
curl_easy_perform(co->curl_handle);
@@ -183,7 +183,7 @@ static JSBool curl_run(JSContext *cx, JSObject *obj, uintN argc, jsval * argv, j
co->function = NULL;
JS_ResumeRequest(cx, co->saveDepth);
switch_safe_free(durl);
return JS_TRUE;
}
@@ -198,7 +198,7 @@ static JSPropertySpec curl_props[] = {
{0}
};
static JSBool curl_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval * vp)
static JSBool curl_getProperty(JSContext * cx, JSObject * obj, jsval id, jsval * vp)
{
JSBool res = JS_TRUE;
return res;
@@ -212,7 +212,7 @@ JSClass curl_class = {
};
switch_status_t curl_load(JSContext *cx, JSObject *obj)
switch_status_t curl_load(JSContext * cx, JSObject * obj)
{
JS_InitClass(cx, obj, NULL, &curl_class, curl_construct, 3, curl_props, curl_methods, curl_props, curl_methods);
return SWITCH_STATUS_SUCCESS;
@@ -225,7 +225,7 @@ const sm_module_interface_t curl_module_interface = {
/*.next */ NULL
};
SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t ** module_interface)
SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t **module_interface)
{
curl_global_init(CURL_GLOBAL_ALL);
*module_interface = &curl_module_interface;
@@ -42,7 +42,7 @@ struct odbc_obj {
SQLCHAR *code;
int32 codelen;
};
typedef struct odbc_obj odbc_obj_t;
typedef struct odbc_obj odbc_obj_t;
static odbc_obj_t *new_odbc_obj(char *dsn, char *username, char *password)
{
@@ -56,7 +56,7 @@ static odbc_obj_t *new_odbc_obj(char *dsn, char *username, char *password)
if (!(new_obj->handle = switch_odbc_handle_new(dsn, username, password))) {
goto err;
}
return new_obj;
err:
@@ -72,29 +72,30 @@ static odbc_obj_t *new_odbc_obj(char *dsn, char *username, char *password)
switch_odbc_status_t odbc_obj_connect(odbc_obj_t *obj)
{
return switch_odbc_handle_connect(obj->handle);
}
static void destroy_odbc_obj(odbc_obj_t ** objp)
static void destroy_odbc_obj(odbc_obj_t **objp)
{
odbc_obj_t *obj = *objp;
if (obj == NULL) return;
if (obj == NULL)
return;
if (obj->stmt) {
SQLFreeHandle(SQL_HANDLE_STMT, obj->stmt);
}
if (obj->handle) {
switch_odbc_handle_destroy(&obj->handle);
}
switch_safe_free(obj->colbuf);
switch_safe_free(obj->code);
if (obj->handle) {
switch_odbc_handle_destroy(&obj->handle);
}
switch_safe_free(obj->colbuf);
switch_safe_free(obj->code);
switch_safe_free(obj);
}
/* ODBC Object */
/*********************************************************************************/
static JSBool odbc_construct(JSContext * cx, JSObject * obj, uintN argc, jsval *argv, jsval *rval)
static JSBool odbc_construct(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
odbc_obj_t *odbc_obj = NULL;
char *dsn, *username, *password;
@@ -156,16 +157,17 @@ static JSBool odbc_construct(JSContext * cx, JSObject * obj, uintN argc, jsval *
static void odbc_destroy(JSContext * cx, JSObject * obj)
{
odbc_obj_t *odbc_obj;
if (obj == NULL) return;
odbc_obj_t *odbc_obj;
if (obj == NULL)
return;
odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
if (odbc_obj) {
destroy_odbc_obj(&odbc_obj);
JS_SetPrivate(cx, obj, NULL);
}
JS_SetPrivate(cx, obj, NULL);
}
}
static JSBool odbc_connect(JSContext * cx, JSObject * obj, uintN argc, jsval *argv, jsval *rval)
static JSBool odbc_connect(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
JSBool tf = JS_TRUE;
@@ -183,7 +185,7 @@ static JSBool odbc_connect(JSContext * cx, JSObject * obj, uintN argc, jsval *ar
return JS_TRUE;
}
static JSBool odbc_execute(JSContext * cx, JSObject * obj, uintN argc, jsval *argv, jsval *rval)
static JSBool odbc_execute(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
char *sql;
@@ -217,7 +219,7 @@ static JSBool odbc_execute(JSContext * cx, JSObject * obj, uintN argc, jsval *ar
return JS_TRUE;
}
static JSBool odbc_exec(JSContext * cx, JSObject * obj, uintN argc, jsval *argv, jsval *rval)
static JSBool odbc_exec(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
char *sql;
@@ -253,7 +255,7 @@ static JSBool odbc_exec(JSContext * cx, JSObject * obj, uintN argc, jsval *argv,
return JS_TRUE;
}
static JSBool odbc_num_rows(JSContext * cx, JSObject * obj, uintN argc, jsval *argv, jsval *rval)
static JSBool odbc_num_rows(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
@@ -277,7 +279,7 @@ static JSBool odbc_num_rows(JSContext * cx, JSObject * obj, uintN argc, jsval *a
}
static JSBool odbc_next_row(JSContext * cx, JSObject * obj, uintN argc, jsval *argv, jsval *rval)
static JSBool odbc_next_row(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
int result = 0;
@@ -285,8 +287,8 @@ static JSBool odbc_next_row(JSContext * cx, JSObject * obj, uintN argc, jsval *a
if (switch_odbc_handle_get_state(odbc_obj->handle) != SWITCH_ODBC_STATE_CONNECTED) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Database is not connected!\n");
goto done;
}
goto done;
}
if (odbc_obj->stmt) {
@@ -345,7 +347,7 @@ static char *escape_data(char *in, char escapeChar)
}
static JSBool odbc_get_data(JSContext * cx, JSObject * obj, uintN argc, jsval *argv, jsval *rval)
static JSBool odbc_get_data(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
@@ -353,8 +355,8 @@ static JSBool odbc_get_data(JSContext * cx, JSObject * obj, uintN argc, jsval *a
if (switch_odbc_handle_get_state(odbc_obj->handle) != SWITCH_ODBC_STATE_CONNECTED) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Database is not connected!\n");
goto done;
}
goto done;
}
if (odbc_obj->stmt) {
SQLSMALLINT c = 0, x = 0;
@@ -374,7 +376,7 @@ static JSBool odbc_get_data(JSContext * cx, JSObject * obj, uintN argc, jsval *a
SQLCHAR name[1024] = "";
SQLCHAR *data = odbc_obj->colbuf;
SQLCHAR *esc = NULL;
SQLDescribeCol(odbc_obj->stmt, x, name, sizeof(name), &NameLength, &DataType, &ColumnSize, &DecimalDigits, &Nullable);
SQLGetData(odbc_obj->stmt, x, SQL_C_CHAR, odbc_obj->colbuf, odbc_obj->cblen, NULL);
@@ -407,10 +409,10 @@ static JSBool odbc_get_data(JSContext * cx, JSObject * obj, uintN argc, jsval *a
}
static JSBool odbc_close(JSContext * cx, JSObject * obj, uintN argc, jsval *argv, jsval *rval)
static JSBool odbc_close(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
odbc_destroy(cx, obj);
return JS_TRUE;
odbc_destroy(cx, obj);
return JS_TRUE;
}
enum odbc_tinyid {
@@ -425,17 +427,17 @@ static JSFunctionSpec odbc_methods[] = {
{"numRows", odbc_num_rows, 1},
{"nextRow", odbc_next_row, 1},
{"getData", odbc_get_data, 1},
{"close", odbc_close, 1},
{"close", odbc_close, 1},
{0}
};
static JSPropertySpec odbc_props[] = {
{"name", odbc_NAME, JSPROP_READONLY|JSPROP_PERMANENT},
{"name", odbc_NAME, JSPROP_READONLY | JSPROP_PERMANENT},
{0}
};
static JSBool odbc_setProperty(JSContext * cx, JSObject * obj, jsval id, jsval *vp)
static JSBool odbc_setProperty(JSContext * cx, JSObject * obj, jsval id, jsval * vp)
{
char *name = JS_GetStringBytes(JS_ValueToString(cx, id));
@@ -446,11 +448,11 @@ static JSBool odbc_setProperty(JSContext * cx, JSObject * obj, jsval id, jsval *
return JS_TRUE;
}
static JSBool odbc_getProperty(JSContext * cx, JSObject * obj, jsval id, jsval *vp)
static JSBool odbc_getProperty(JSContext * cx, JSObject * obj, jsval id, jsval * vp)
{
int param;
char *name = JS_GetStringBytes(JS_ValueToString(cx, id));
/* numbers are our props anything else is a method */
if (name[0] >= 48 && name[0] <= 57) {
param = atoi(name);
@@ -483,7 +485,7 @@ const sm_module_interface_t odbc_module_interface = {
/*.next */ NULL
};
SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t ** module_interface)
SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t **module_interface)
{
*module_interface = &odbc_module_interface;
return SWITCH_STATUS_SUCCESS;
@@ -93,7 +93,7 @@ const sm_module_interface_t skel_module_interface = {
/*.next */ NULL
};
SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t ** module_interface)
SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t **module_interface)
{
*module_interface = &skel_module_interface;
return SWITCH_STATUS_SUCCESS;
@@ -34,7 +34,7 @@ static const char modname[] = "Socket";
struct js_socket_obj {
switch_socket_t *socket;
switch_memory_pool_t *pool;
char* read_buffer;
char *read_buffer;
switch_size_t buffer_size;
int state;
};
@@ -44,20 +44,18 @@ typedef struct js_socket_obj js_socket_obj_t;
/*********************************************************************************/
static JSBool socket_construct(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
js_socket_obj_t* js_socket_obj = 0;
js_socket_obj_t *js_socket_obj = 0;
switch_memory_pool_t *pool;
switch_socket_t *socket;
switch_status_t ret;
switch_core_new_memory_pool(&pool);
ret = switch_socket_create(&socket, AF_INET, SOCK_STREAM, SWITCH_PROTO_TCP, pool);
if (ret != SWITCH_STATUS_SUCCESS)
{
if (ret != SWITCH_STATUS_SUCCESS) {
switch_core_destroy_memory_pool(&pool);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Failed to create socket, reason: %d.\n", ret);
return JS_FALSE;
}
// allocate information needed by JS to be able to write to the log.
// (needed since multitple js sessions can write to the same log)
js_socket_obj = switch_core_alloc(pool, sizeof(js_socket_obj_t));
@@ -73,8 +71,7 @@ static void socket_destroy(JSContext * cx, JSObject * obj)
if (socket == NULL)
return;
if (socket->socket != 0)
{
if (socket->socket != 0) {
switch_socket_shutdown(socket->socket, SWITCH_SHUTDOWN_READWRITE);
switch_socket_close(socket->socket);
switch_core_destroy_memory_pool(&socket->pool);
@@ -84,14 +81,12 @@ static void socket_destroy(JSContext * cx, JSObject * obj)
static JSBool socket_connect(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
js_socket_obj_t *socket = JS_GetPrivate(cx, obj);
if (socket == NULL)
{
if (socket == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to find js object.\n");
return JS_FALSE;
}
if (argc == 2)
{
if (argc == 2) {
char *host = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
int32 port;
switch_sockaddr_t *addr;
@@ -99,21 +94,18 @@ static JSBool socket_connect(JSContext * cx, JSObject * obj, uintN argc, jsval *
JS_ValueToInt32(cx, argv[1], &port);
ret = switch_sockaddr_info_get(&addr, host, AF_INET, (switch_port_t)port, 0, socket->pool);
if (ret != SWITCH_STATUS_SUCCESS)
{
ret = switch_sockaddr_info_get(&addr, host, AF_INET, (switch_port_t) port, 0, socket->pool);
if (ret != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "switch_sockaddr_info_get failed: %d.\n", ret);
return JS_FALSE;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Connecting to: %s:%d.\n", host, port);
ret = switch_socket_connect(socket->socket, addr);
if (ret != SWITCH_STATUS_SUCCESS)
{
if (ret != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "switch_socket_connect failed: %d.\n", ret);
*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
}
else
} else
*rval = BOOLEAN_TO_JSVAL(JS_TRUE);
}
@@ -124,23 +116,19 @@ static JSBool socket_connect(JSContext * cx, JSObject * obj, uintN argc, jsval *
static JSBool socket_send(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
js_socket_obj_t *socket = JS_GetPrivate(cx, obj);
if (socket == NULL)
{
if (socket == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to find js object.\n");
return JS_FALSE;
}
if (argc == 1)
{
if (argc == 1) {
char *buffer = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
switch_size_t len = strlen(buffer);
switch_status_t ret = switch_socket_send(socket->socket, buffer, &len);
if (ret != SWITCH_STATUS_SUCCESS)
{
if (ret != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "switch_socket_send failed: %d.\n", ret);
*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
}
else
} else
*rval = BOOLEAN_TO_JSVAL(JS_TRUE);
}
@@ -150,35 +138,29 @@ static JSBool socket_send(JSContext * cx, JSObject * obj, uintN argc, jsval * ar
static JSBool socket_read_bytes(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
js_socket_obj_t *socket = JS_GetPrivate(cx, obj);
if (socket == NULL)
{
if (socket == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to find js object.\n");
return JS_FALSE;
}
if (argc == 1)
{
if (argc == 1) {
int32 bytes_to_read;
switch_status_t ret;
switch_size_t len;
JS_ValueToInt32(cx, argv[0], &bytes_to_read);
len = (switch_size_t)bytes_to_read;
len = (switch_size_t) bytes_to_read;
if (socket->buffer_size < len)
{
socket->read_buffer = switch_core_alloc(socket->pool, len+1);
if (socket->buffer_size < len) {
socket->read_buffer = switch_core_alloc(socket->pool, len + 1);
socket->buffer_size = bytes_to_read + 1;
}
ret = switch_socket_recv(socket->socket, socket->read_buffer, &len);
if (ret != SWITCH_STATUS_SUCCESS)
{
if (ret != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "switch_socket_send failed: %d.\n", ret);
*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
}
else
{
} else {
socket->read_buffer[len] = 0;
*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, socket->read_buffer));
}
@@ -190,15 +172,13 @@ static JSBool socket_read_bytes(JSContext * cx, JSObject * obj, uintN argc, jsva
static JSBool socket_read(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
js_socket_obj_t *socket = JS_GetPrivate(cx, obj);
if (socket == NULL)
{
if (socket == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to find js object.\n");
return JS_FALSE;
}
if (argc >= 0)
{
char* delimiter = "\n";
if (argc >= 0) {
char *delimiter = "\n";
switch_status_t ret = SWITCH_STATUS_FALSE;
switch_size_t len = 1;
switch_size_t total_length = 0;
@@ -212,8 +192,7 @@ static JSBool socket_read(JSContext * cx, JSObject * obj, uintN argc, jsval * ar
if (socket->read_buffer == 0)
socket->read_buffer = switch_core_alloc(socket->pool, socket->buffer_size);
while (can_run == TRUE)
{
while (can_run == TRUE) {
ret = switch_socket_recv(socket->socket, tempbuf, &len);
if (ret != SWITCH_STATUS_SUCCESS)
break;
@@ -223,13 +202,11 @@ static JSBool socket_read(JSContext * cx, JSObject * obj, uintN argc, jsval * ar
break;
else if (tempbuf[0] == '\r' && delimiter[0] == '\n')
continue;
else
{
else {
// Buffer is full, let's increase it.
if (total_length == socket->buffer_size - 1)
{
if (total_length == socket->buffer_size - 1) {
switch_size_t new_size = socket->buffer_size + 4196;
char* new_buffer = switch_core_alloc(socket->pool, socket->buffer_size);
char *new_buffer = switch_core_alloc(socket->pool, socket->buffer_size);
memcpy(new_buffer, socket->read_buffer, total_length);
socket->buffer_size = new_size;
socket->read_buffer = new_buffer;
@@ -238,13 +215,10 @@ static JSBool socket_read(JSContext * cx, JSObject * obj, uintN argc, jsval * ar
++total_length;
}
}
if (ret != SWITCH_STATUS_SUCCESS)
{
if (ret != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "socket receive failed: %d.\n", ret);
*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
}
else
{
} else {
socket->read_buffer[total_length] = 0;
*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, socket->read_buffer));
}
@@ -256,8 +230,7 @@ static JSBool socket_read(JSContext * cx, JSObject * obj, uintN argc, jsval * ar
static JSBool socket_close(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
js_socket_obj_t *socket = JS_GetPrivate(cx, obj);
if (socket == NULL)
{
if (socket == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to find js object.\n");
return JS_FALSE;
}
@@ -290,7 +263,7 @@ static JSPropertySpec socket_props[] = {
static JSBool socket_getProperty(JSContext * cx, JSObject * obj, jsval id, jsval * vp)
{
JSBool res = JS_TRUE;
// js_socket_obj_t *socket = JS_GetPrivate(cx, obj);
// js_socket_obj_t *socket = JS_GetPrivate(cx, obj);
char *name;
int param = 0;
@@ -335,7 +308,7 @@ const sm_module_interface_t socket_module_interface = {
/*.next */ NULL
};
SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t ** module_interface)
SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t **module_interface)
{
*module_interface = &socket_module_interface;
return SWITCH_STATUS_SUCCESS;
@@ -56,7 +56,7 @@ struct teletone_obj {
};
static int teletone_handler(teletone_generation_session_t * ts, teletone_tone_map_t * map)
static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map_t *map)
{
struct teletone_obj *tto = ts->user_data;
int wrote;
@@ -249,7 +249,7 @@ static JSBool teletone_generate(JSContext * cx, JSObject * obj, uintN argc, jsva
if (switch_test_flag(tto, TTF_DTMF)) {
char dtmf[128];
char *ret;
if (switch_channel_has_dtmf(channel)) {
uintN aargc = 0;
jsval aargv[4];
@@ -345,7 +345,7 @@ const sm_module_interface_t teletone_module_interface = {
/*.next */ NULL
};
SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t ** module_interface)
SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t **module_interface)
{
*module_interface = &teletone_module_interface;
return SWITCH_STATUS_SUCCESS;
+30 -31
View File
@@ -84,14 +84,14 @@ static void add_mapping(char *var, char *val, int cumlative)
} else {
m = switch_log_str2mask(val);
}
if (!strcasecmp(var, "all")) {
all_level |= m;
return;
}
del_mapping(var);
switch_core_hash_insert(log_hash, var, (void *)(intptr_t) m);
switch_core_hash_insert(log_hash, var, (void *) (intptr_t) m);
}
static switch_status_t config_logger(void)
@@ -149,7 +149,7 @@ static switch_status_t config_logger(void)
return SWITCH_STATUS_SUCCESS;
}
static int can_write(FILE *handle, int ms)
static int can_write(FILE * handle, int ms)
{
#ifndef WIN32
int aok = 1;
@@ -166,14 +166,14 @@ static int can_write(FILE *handle, int ms)
FD_SET(fd, &can_write);
to.tv_sec = sec;
to.tv_usec = usec;
if (select(fd+1, NULL, &can_write, NULL, &to) > 0) {
if (select(fd + 1, NULL, &can_write, NULL, &to) > 0) {
aok = FD_ISSET(fd, &can_write);
} else {
aok = 0;
}
return aok;
#else
#else
return 1;
#endif
}
@@ -182,11 +182,10 @@ static int can_write(FILE *handle, int ms)
static switch_status_t switch_console_logger(const switch_log_node_t *node, switch_log_level_t level)
{
FILE *handle;
if (!RUNNING) {
return SWITCH_STATUS_SUCCESS;
}
#if 0
if (failed_write) {
if ((handle = switch_core_data_channel(SWITCH_CHANNEL_ID_LOG))) {
@@ -197,7 +196,7 @@ static switch_status_t switch_console_logger(const switch_log_node_t *node, swit
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "%s", msg);
#else
if (COLORIZE) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "%s%s%s", COLORS[1], msg, SWITCH_SEQ_DEFAULT_COLOR);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "%s%s%s", COLORS[1], msg, SWITCH_SEQ_DEFAULT_COLOR);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "%s", msg);
}
@@ -213,11 +212,11 @@ static switch_status_t switch_console_logger(const switch_log_node_t *node, swit
}
if ((handle = switch_core_data_channel(SWITCH_CHANNEL_ID_LOG))) {
size_t mask = 0;
size_t ok = 0;
ok = switch_log_check_mask(all_level, level);
size_t mask = 0;
size_t ok = 0;
ok = switch_log_check_mask(all_level, level);
if (log_hash) {
if (!ok) {
mask = (size_t) switch_core_hash_find(log_hash, node->file);
@@ -233,7 +232,7 @@ static switch_status_t switch_console_logger(const switch_log_node_t *node, swit
if (ok) {
#ifndef WIN32
int aok = can_write(handle, 10000);
if (!aok) {
//hard_log_level = 0;
//failed_write++;
@@ -261,18 +260,18 @@ static switch_status_t switch_console_logger(const switch_log_node_t *node, swit
SWITCH_STANDARD_API(console_api_function)
{
int argc;
char *mydata = NULL, *argv[3];
char *mydata = NULL, *argv[3];
const char *err = NULL;
if (!cmd) {
err = "bad args";
goto end;
}
goto end;
}
mydata = strdup(cmd);
assert(mydata);
argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
mydata = strdup(cmd);
assert(mydata);
argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
if (argc > 0) {
@@ -283,7 +282,7 @@ SWITCH_STANDARD_API(console_api_function)
if (!strcasecmp(argv[0], "loglevel")) {
int level = hard_log_level;
if (argc > 1) {
if (*argv[1] > 47 && *argv[1] < 58) {
level = atoi(argv[1]);
@@ -296,26 +295,26 @@ SWITCH_STANDARD_API(console_api_function)
stream->write_function(stream, "-ERR syntax error, console log level not set!\n");
} else {
hard_log_level = level;
stream->write_function(stream, "+OK console log level set to %s\n", switch_log_level2str(hard_log_level));
stream->write_function(stream, "+OK console log level set to %s\n", switch_log_level2str(hard_log_level));
}
goto end;
} else if (!strcasecmp(argv[0], "colorize")) {
if (argc > 1) {
COLORIZE = switch_true(argv[1]);
}
stream->write_function(stream, "+OK console color %s\n", COLORIZE ? "enabled" : "disabled");
stream->write_function(stream, "+OK console color %s\n", COLORIZE ? "enabled" : "disabled");
goto end;
}
err = "invalid command";
}
end:
end:
if (err) {
stream->write_function(stream, "-Error %s\n", err);
stream->write_function(stream, "-Error %s\n", err);
}
@@ -328,10 +327,10 @@ SWITCH_STANDARD_API(console_api_function)
SWITCH_MODULE_LOAD_FUNCTION(mod_console_load)
{
switch_api_interface_t *api_interface;
module_pool = pool;
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
+90 -90
View File
@@ -36,9 +36,9 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_logfile_load);
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_logfile_shutdown);
SWITCH_MODULE_DEFINITION(mod_logfile, mod_logfile_load, mod_logfile_shutdown, NULL);
#define DEFAULT_LIMIT 0xA00000 /* About 10 MB */
#define DEFAULT_LIMIT 0xA00000 /* About 10 MB */
#define WARM_FUZZY_OFFSET 256
#define MAX_ROT 4096 /* why not */
#define MAX_ROT 4096 /* why not */
static switch_memory_pool_t *module_pool = NULL;
static switch_hash_t *profile_hash = NULL;
@@ -50,12 +50,12 @@ static struct {
struct logfile_profile {
char *name;
switch_size_t log_size; /* keep the log size in check for rotation */
switch_size_t roll_size; /* the size that we want to rotate the file at */
switch_size_t log_size; /* keep the log size in check for rotation */
switch_size_t roll_size; /* the size that we want to rotate the file at */
char *logfile;
switch_file_t *log_afd;
switch_hash_t *log_hash;
uint32_t all_level;
switch_hash_t *log_hash;
uint32_t all_level;
};
typedef struct logfile_profile logfile_profile_t;
@@ -76,7 +76,7 @@ static void add_mapping(logfile_profile_t *profile, char *var, char *val)
return;
}
switch_core_hash_insert(profile->log_hash, var, (void *)(intptr_t) switch_log_str2mask(val));
switch_core_hash_insert(profile->log_hash, var, (void *) (intptr_t) switch_log_str2mask(val));
}
static switch_status_t mod_logfile_rotate(logfile_profile_t *profile);
@@ -92,7 +92,7 @@ static switch_status_t mod_logfile_openlogfile(logfile_profile_t *profile, switc
flags |= SWITCH_FOPEN_WRITE;
flags |= SWITCH_FOPEN_APPEND;
stat = switch_file_open(&afd, profile->logfile, flags, SWITCH_FPROT_UREAD|SWITCH_FPROT_UWRITE, module_pool);
stat = switch_file_open(&afd, profile->logfile, flags, SWITCH_FPROT_UREAD | SWITCH_FPROT_UWRITE, module_pool);
if (stat != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_FALSE;
}
@@ -136,15 +136,15 @@ static switch_status_t mod_logfile_rotate(logfile_profile_t *profile)
}
p = malloc(strlen(profile->logfile)+WARM_FUZZY_OFFSET);
p = malloc(strlen(profile->logfile) + WARM_FUZZY_OFFSET);
switch_assert(p);
memset(p, '\0', strlen(profile->logfile)+WARM_FUZZY_OFFSET);
memset(p, '\0', strlen(profile->logfile) + WARM_FUZZY_OFFSET);
switch_core_new_memory_pool(&pool);
for (i=1; i < MAX_ROT; i++) {
sprintf((char *)p, "%s.%s.%i", profile->logfile, date, i);
for (i = 1; i < MAX_ROT; i++) {
sprintf((char *) p, "%s.%s.%i", profile->logfile, date, i);
if (switch_file_exists(p, pool) == SWITCH_STATUS_SUCCESS) {
continue;
}
@@ -152,9 +152,9 @@ static switch_status_t mod_logfile_rotate(logfile_profile_t *profile)
switch_file_close(profile->log_afd);
switch_file_rename(profile->logfile, p, pool);
if ((status = mod_logfile_openlogfile(profile, SWITCH_FALSE)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error Rotating Log!\n");
goto end;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error Rotating Log!\n");
goto end;
}
break;
}
@@ -164,7 +164,7 @@ static switch_status_t mod_logfile_rotate(logfile_profile_t *profile)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "New log started.\n");
end:
end:
switch_mutex_unlock(globals.mutex);
@@ -175,7 +175,7 @@ end:
static switch_status_t mod_logfile_raw_write(logfile_profile_t *profile, char *log_data)
{
switch_size_t len;
switch_status_t status = SWITCH_STATUS_SUCCESS;
switch_status_t status = SWITCH_STATUS_SUCCESS;
len = strlen(log_data);
if (len <= 0 || !profile->log_afd) {
@@ -187,96 +187,96 @@ static switch_status_t mod_logfile_raw_write(logfile_profile_t *profile, char *l
if (switch_file_write(profile->log_afd, log_data, &len) != SWITCH_STATUS_SUCCESS) {
switch_file_close(profile->log_afd);
if ((status = mod_logfile_openlogfile(profile, SWITCH_TRUE)) == SWITCH_STATUS_SUCCESS) {
len = strlen(log_data);
switch_file_write(profile->log_afd, log_data, &len);
}
len = strlen(log_data);
switch_file_write(profile->log_afd, log_data, &len);
}
}
switch_mutex_unlock(globals.mutex);
if (status == SWITCH_STATUS_SUCCESS) {
profile->log_size += len;
if (status == SWITCH_STATUS_SUCCESS) {
profile->log_size += len;
if (profile->roll_size && profile->log_size >= profile->roll_size) {
mod_logfile_rotate(profile);
}
}
if (profile->roll_size && profile->log_size >= profile->roll_size) {
mod_logfile_rotate(profile);
}
}
return status;
}
static switch_status_t process_node(const switch_log_node_t *node, switch_log_level_t level)
{
switch_hash_index_t *hi;
switch_hash_index_t *hi;
void *val;
const void *var;
logfile_profile_t *profile;
for (hi = switch_hash_first(NULL, profile_hash); hi; hi = switch_hash_next(hi)) {
size_t mask = 0;
size_t ok = 0;
switch_hash_this(hi, &var, NULL, &val);
profile = val;
ok = switch_log_check_mask(profile->all_level, level);
if (!ok) {
mask = (size_t) switch_core_hash_find(profile->log_hash, node->file);
ok = switch_log_check_mask(mask, level);
}
if (!ok) {
mask = (size_t) switch_core_hash_find(profile->log_hash, node->func);
ok = switch_log_check_mask(mask, level);
}
for (hi = switch_hash_first(NULL, profile_hash); hi; hi = switch_hash_next(hi)) {
size_t mask = 0;
size_t ok = 0;
if (ok) {
mod_logfile_raw_write(profile, node->data);
}
switch_hash_this(hi, &var, NULL, &val);
profile = val;
}
ok = switch_log_check_mask(profile->all_level, level);
if (!ok) {
mask = (size_t) switch_core_hash_find(profile->log_hash, node->file);
ok = switch_log_check_mask(mask, level);
}
if (!ok) {
mask = (size_t) switch_core_hash_find(profile->log_hash, node->func);
ok = switch_log_check_mask(mask, level);
}
if (ok) {
mod_logfile_raw_write(profile, node->data);
}
}
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t mod_logfile_logger(const switch_log_node_t *node, switch_log_level_t level)
{
return process_node(node, level);
return process_node(node, level);
}
static switch_status_t load_profile(switch_xml_t xml)
{
switch_xml_t param, settings;
char *name = (char *) switch_xml_attr_soft(xml, "name");
logfile_profile_t *new_profile;
char *name = (char *) switch_xml_attr_soft(xml, "name");
logfile_profile_t *new_profile;
new_profile = switch_core_alloc(module_pool, sizeof(*new_profile));
memset(new_profile, 0, sizeof(*new_profile));
switch_core_hash_init(&(new_profile->log_hash), module_pool);
new_profile->name = switch_core_strdup(module_pool, switch_str_nil(name));
new_profile = switch_core_alloc(module_pool, sizeof(*new_profile));
memset(new_profile, 0, sizeof(*new_profile));
switch_core_hash_init(&(new_profile->log_hash), module_pool);
new_profile->name = switch_core_strdup(module_pool, switch_str_nil(name));
if ((settings = switch_xml_child(xml, "settings"))) {
for (param = switch_xml_child(settings, "param"); param; param = param->next) {
char *var = (char *) switch_xml_attr_soft(param, "name");
char *val = (char *) switch_xml_attr_soft(param, "value");
if (!strcmp(var, "logfile")) {
new_profile->logfile = strdup(val);
} else if (!strcmp(var, "rollover")) {
new_profile->roll_size = atoi(val);
if (new_profile->roll_size < 0) {
new_profile->roll_size = 0;
}
}
}
}
for (param = switch_xml_child(settings, "param"); param; param = param->next) {
char *var = (char *) switch_xml_attr_soft(param, "name");
char *val = (char *) switch_xml_attr_soft(param, "value");
if (!strcmp(var, "logfile")) {
new_profile->logfile = strdup(val);
} else if (!strcmp(var, "rollover")) {
new_profile->roll_size = atoi(val);
if (new_profile->roll_size < 0) {
new_profile->roll_size = 0;
}
}
}
}
if ((settings = switch_xml_child(xml, "mappings"))) {
for (param = switch_xml_child(settings, "map"); param; param = param->next) {
char *var = (char *) switch_xml_attr_soft(param, "name");
char *val = (char *) switch_xml_attr_soft(param, "value");
add_mapping(new_profile, var, val);
}
}
@@ -286,40 +286,40 @@ static switch_status_t load_profile(switch_xml_t xml)
switch_snprintf(logfile, sizeof(logfile), "%s%s%s", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR, "freeswitch.log");
new_profile->logfile = strdup(logfile);
}
if (mod_logfile_openlogfile(new_profile, SWITCH_TRUE) != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_GENERR;
}
switch_core_hash_insert(profile_hash, new_profile->name, (void *) new_profile);
return SWITCH_STATUS_SUCCESS;
if (mod_logfile_openlogfile(new_profile, SWITCH_TRUE) != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_GENERR;
}
switch_core_hash_insert(profile_hash, new_profile->name, (void *) new_profile);
return SWITCH_STATUS_SUCCESS;
}
static void event_handler(switch_event_t *event)
{
const char *sig = switch_event_get_header(event, "Trapped-Signal");
switch_hash_index_t *hi;
switch_hash_index_t *hi;
void *val;
const void *var;
logfile_profile_t *profile;
if (sig && !strcmp(sig, "HUP")) {
if (globals.rotate) {
for (hi = switch_hash_first(NULL, profile_hash); hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, &var, NULL, &val);
for (hi = switch_hash_first(NULL, profile_hash); hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, &var, NULL, &val);
profile = val;
mod_logfile_rotate(profile);
}
} else {
switch_mutex_lock(globals.mutex);
for (hi = switch_hash_first(NULL, profile_hash); hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, &var, NULL, &val);
for (hi = switch_hash_first(NULL, profile_hash); hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, &var, NULL, &val);
profile = val;
switch_file_close(profile->log_afd);
if (mod_logfile_openlogfile(profile, SWITCH_TRUE) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error Re-opening Log!\n");
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error Re-opening Log!\n");
}
}
switch_mutex_unlock(globals.mutex);
}
@@ -364,11 +364,11 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_logfile_load)
if ((profiles = switch_xml_child(cfg, "profiles"))) {
for (xprofile = switch_xml_child(profiles, "profile"); xprofile; xprofile = xprofile->next) {
if (load_profile(xprofile) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error loading profile.");
}
}
}
if (load_profile(xprofile) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error loading profile.");
}
}
}
switch_xml_free(xml);
}
+34 -34
View File
@@ -54,16 +54,16 @@ SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_ident, globals.ident);
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_format, globals.format);
static switch_loadable_module_interface_t console_module_interface = {
/*.module_name */ modname,
/*.endpoint_interface */ NULL,
/*.timer_interface */ NULL,
/*.dialplan_interface */ NULL,
/*.codec_interface */ NULL,
/*.application_interface */ NULL,
/*.api_interface */ NULL,
/*.file_interface */ NULL,
/*.speech_interface */ NULL,
/*.directory_interface */ NULL
/*.module_name */ modname,
/*.endpoint_interface */ NULL,
/*.timer_interface */ NULL,
/*.dialplan_interface */ NULL,
/*.codec_interface */ NULL,
/*.application_interface */ NULL,
/*.api_interface */ NULL,
/*.file_interface */ NULL,
/*.speech_interface */ NULL,
/*.directory_interface */ NULL
};
static switch_status_t mod_syslog_logger(const switch_log_node_t *node, switch_log_level_t level)
@@ -72,30 +72,30 @@ static switch_status_t mod_syslog_logger(const switch_log_node_t *node, switch_l
int syslog_level;
switch (level) {
case SWITCH_LOG_DEBUG:
syslog_level = LOG_DEBUG;
break;
case SWITCH_LOG_INFO:
syslog_level = LOG_INFO;
break;
case SWITCH_LOG_NOTICE:
syslog_level = LOG_NOTICE;
break;
case SWITCH_LOG_WARNING:
syslog_level = LOG_WARNING;
break;
case SWITCH_LOG_ERROR:
syslog_level = LOG_ERR;
break;
case SWITCH_LOG_CRIT:
syslog_level = LOG_CRIT;
break;
case SWITCH_LOG_ALERT:
syslog_level = LOG_ALERT;
break;
default:
syslog_level = LOG_NOTICE;
break;
case SWITCH_LOG_DEBUG:
syslog_level = LOG_DEBUG;
break;
case SWITCH_LOG_INFO:
syslog_level = LOG_INFO;
break;
case SWITCH_LOG_NOTICE:
syslog_level = LOG_NOTICE;
break;
case SWITCH_LOG_WARNING:
syslog_level = LOG_WARNING;
break;
case SWITCH_LOG_ERROR:
syslog_level = LOG_ERR;
break;
case SWITCH_LOG_CRIT:
syslog_level = LOG_CRIT;
break;
case SWITCH_LOG_ALERT:
syslog_level = LOG_ALERT;
break;
default:
syslog_level = LOG_NOTICE;
break;
}
if (!switch_strlen_zero(message)) {
+2 -2
View File
@@ -196,8 +196,8 @@ static switch_status_t de_say_general_count(switch_core_session_t *session,
if (in != 0) {
for (x = 8; x >= 0; x--) {
int num = (int) pow(10, x);
if ((places[(uint32_t)x] = in / num)) {
in -= places[(uint32_t)x] * num;
if ((places[(uint32_t) x] = in / num)) {
in -= places[(uint32_t) x] * num;
}
}
+2 -2
View File
@@ -185,8 +185,8 @@ static switch_status_t en_say_general_count(switch_core_session_t *session,
if (in != 0) {
for (x = 8; x >= 0; x--) {
int num = (int) pow(10, x);
if ((places[(uint32_t)x] = in / num)) {
in -= places[(uint32_t)x] * num;
if ((places[(uint32_t) x] = in / num)) {
in -= places[(uint32_t) x] * num;
}
}
+2 -2
View File
@@ -185,8 +185,8 @@ static switch_status_t es_say_general_count(switch_core_session_t *session,
if (in != 0) {
for (x = 8; x >= 0; x--) {
int num = (int) pow(10, x);
if ((places[(uint32_t)x] = in / num)) {
in -= places[(uint32_t)x] * num;
if ((places[(uint32_t) x] = in / num)) {
in -= places[(uint32_t) x] * num;
}
}
+2 -2
View File
@@ -185,8 +185,8 @@ static switch_status_t fr_say_general_count(switch_core_session_t *session,
if (in != 0) {
for (x = 8; x >= 0; x--) {
int num = (int) pow(10, x);
if ((places[(uint32_t)x] = in / num)) {
in -= places[(uint32_t)x] * num;
if ((places[(uint32_t) x] = in / num)) {
in -= places[(uint32_t) x] * num;
}
}
+2 -2
View File
@@ -185,8 +185,8 @@ static switch_status_t it_say_general_count(switch_core_session_t *session,
if (in != 0) {
for (x = 8; x >= 0; x--) {
int num = (int) pow(10, x);
if ((places[(uint32_t)x] = in / num)) {
in -= places[(uint32_t)x] * num;
if ((places[(uint32_t) x] = in / num)) {
in -= places[(uint32_t) x] * num;
}
}
+2 -2
View File
@@ -185,8 +185,8 @@ static switch_status_t nl_say_general_count(switch_core_session_t *session,
if (in != 0) {
for (x = 8; x >= 0; x--) {
int num = (int) pow(10, x);
if ((places[(uint32_t)x] = in / num)) {
in -= places[(uint32_t)x] * num;
if ((places[(uint32_t) x] = in / num)) {
in -= places[(uint32_t) x] * num;
}
}
+2 -2
View File
@@ -185,8 +185,8 @@ static switch_status_t zh_say_general_count(switch_core_session_t *session,
if (in != 0) {
for (x = 8; x >= 0; x--) {
int num = (int) pow(10, x);
if ((places[(uint32_t)x] = in / num)) {
in -= places[(uint32_t)x] * num;
if ((places[(uint32_t) x] = in / num)) {
in -= places[(uint32_t) x] * num;
}
}
+23 -41
View File
@@ -99,10 +99,7 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
}
if (!switch_strlen_zero(logdir)) {
if ((path = switch_mprintf("%s%s%s.cdr.xml",
logdir,
SWITCH_PATH_SEPARATOR,
switch_core_session_get_uuid(session)))) {
if ((path = switch_mprintf("%s%s%s.cdr.xml", logdir, SWITCH_PATH_SEPARATOR, switch_core_session_get_uuid(session)))) {
if ((fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) > -1) {
int wrote;
wrote = write(fd, xml_text, (unsigned) strlen(xml_text));
@@ -124,7 +121,7 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
/* try to post it to the web server */
if (!switch_strlen_zero(globals.url)) {
curl_handle = curl_easy_init();
if (globals.encode) {
switch_size_t need_bytes = strlen(xml_text) * 3;
@@ -136,14 +133,14 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
switch_url_encode(xml_text, xml_text_escaped, need_bytes);
} else {
headers = curl_slist_append(headers, "Content-Type: application/x-www-form-base64-encoded");
switch_b64_encode((unsigned char *)xml_text, need_bytes / 3, (unsigned char *)xml_text_escaped, need_bytes);
switch_b64_encode((unsigned char *) xml_text, need_bytes / 3, (unsigned char *) xml_text_escaped, need_bytes);
}
switch_safe_free(xml_text);
xml_text = xml_text_escaped;
} else {
headers = curl_slist_append(headers, "Content-Type: application/x-www-form-plaintext");
}
if (!(curl_xml_text = switch_mprintf("cdr=%s", xml_text))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
goto error;
@@ -165,15 +162,15 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
slist = curl_slist_append(slist, "Expect:");
curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, slist);
}
if (globals.ignore_cacert_check) {
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, FALSE);
}
/* these were used for testing, optionally they may be enabled if someone desires
curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, 120); // tcp timeout
curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1); // 302 recursion level
*/
curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, 120); // tcp timeout
curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1); // 302 recursion level
*/
for (cur_try = 0; cur_try < globals.retries; cur_try++) {
if (cur_try > 0) {
@@ -184,7 +181,7 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
if (httpRes == 200) {
goto success;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Got error [%ld] posting to web server [%s]\n",httpRes, globals.url);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Got error [%ld] posting to web server [%s]\n", httpRes, globals.url);
}
}
curl_easy_cleanup(curl_handle);
@@ -197,10 +194,7 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
/* if we are here the web post failed for some reason */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to post to web server, writing to file\n");
if ((path = switch_mprintf("%s%s%s.cdr.xml",
globals.err_log_dir,
SWITCH_PATH_SEPARATOR,
switch_core_session_get_uuid(session)))) {
if ((path = switch_mprintf("%s%s%s.cdr.xml", globals.err_log_dir, SWITCH_PATH_SEPARATOR, switch_core_session_get_uuid(session)))) {
if ((fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) > -1) {
int wrote;
wrote = write(fd, xml_text, (unsigned) strlen(xml_text));
@@ -218,11 +212,11 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
}
}
success:
success:
status = SWITCH_STATUS_SUCCESS;
error:
if (curl_handle) {
error:
if (curl_handle) {
curl_easy_cleanup(curl_handle);
}
if (headers) {
@@ -259,7 +253,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_xml_cdr_load)
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
memset(&globals,0,sizeof(globals));
memset(&globals, 0, sizeof(globals));
globals.log_b = 1;
globals.disable100continue = 0;
@@ -294,32 +288,22 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_xml_cdr_load)
globals.retries = (uint32_t) atoi(val);
} else if (!strcasecmp(var, "log-dir")) {
if (switch_strlen_zero(val)) {
globals.log_dir = switch_mprintf("%s%sxml_cdr",
SWITCH_GLOBAL_dirs.log_dir,
SWITCH_PATH_SEPARATOR);
globals.log_dir = switch_mprintf("%s%sxml_cdr", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR);
} else {
if (switch_is_file_path(val)) {
globals.log_dir = strdup(val);
} else {
globals.log_dir = switch_mprintf("%s%s%s",
SWITCH_GLOBAL_dirs.log_dir,
SWITCH_PATH_SEPARATOR,
val);
globals.log_dir = switch_mprintf("%s%s%s", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR, val);
}
}
} else if (!strcasecmp(var, "err-log-dir")) {
if (switch_strlen_zero(val)) {
globals.err_log_dir = switch_mprintf("%s%sxml_cdr",
SWITCH_GLOBAL_dirs.log_dir,
SWITCH_PATH_SEPARATOR);
globals.err_log_dir = switch_mprintf("%s%sxml_cdr", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR);
} else {
if (switch_is_file_path(val)) {
globals.err_log_dir = strdup(val);
} else {
globals.err_log_dir = switch_mprintf("%s%s%s",
SWITCH_GLOBAL_dirs.log_dir,
SWITCH_PATH_SEPARATOR,
val);
globals.err_log_dir = switch_mprintf("%s%s%s", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR, val);
}
}
} else if (!strcasecmp(var, "ignore-cacert-check") && switch_true(val)) {
@@ -330,9 +314,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_xml_cdr_load)
if (!switch_strlen_zero(globals.log_dir)) {
globals.err_log_dir = strdup(globals.log_dir);
} else {
globals.err_log_dir = switch_mprintf("%s%sxml_cdr",
SWITCH_GLOBAL_dirs.log_dir,
SWITCH_PATH_SEPARATOR);
globals.err_log_dir = switch_mprintf("%s%sxml_cdr", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR);
}
}
}
@@ -342,7 +324,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_xml_cdr_load)
globals.retries = 0;
}
if (globals.retries && globals.delay<=0) {
if (globals.retries && globals.delay <= 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "retries set but delay 0 setting to 5000ms\n");
globals.delay = 5000;
}
@@ -355,9 +337,9 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_xml_cdr_load)
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_xml_cdr_shutdown)
{
globals.shutdown=1;
return SWITCH_STATUS_SUCCESS;
globals.shutdown = 1;
return SWITCH_STATUS_SUCCESS;
}
/* For Emacs:
+34 -37
View File
@@ -43,8 +43,8 @@ struct xml_binding {
char *cred;
int disable100continue;
uint32_t ignore_cacert_check;
switch_hash_t* vars_map;
switch_memory_pool_t* vars_map_pool;
switch_hash_t *vars_map;
switch_memory_pool_t *vars_map_pool;
};
static int keep_files_around = 0;
@@ -78,7 +78,7 @@ SWITCH_STANDARD_API(xml_curl_function)
stream->write_function(stream, "OK\n");
return SWITCH_STATUS_SUCCESS;
usage:
usage:
stream->write_function(stream, "USAGE: %s\n", XML_CURL_SYNTAX);
return SWITCH_STATUS_SUCCESS;
}
@@ -89,7 +89,7 @@ static size_t file_callback(void *ptr, size_t size, size_t nmemb, void *data)
struct config_data *config_data = data;
int x;
x = write(config_data->fd, ptr, realsize);
if ( x != (int)realsize) {
if (x != (int) realsize) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Short write! %d out of %d\n", x, realsize);
}
return x;
@@ -130,13 +130,9 @@ static switch_xml_t xml_url_fetch(const char *section, const char *tag_name, con
}
switch_snprintf(basic_data, sizeof(basic_data), "hostname=%s&section=%s&tag_name=%s&key_name=%s&key_value=%s",
hostname,
section,
switch_str_nil(tag_name),
switch_str_nil(key_name),
switch_str_nil(key_value));
hostname, section, switch_str_nil(tag_name), switch_str_nil(key_name), switch_str_nil(key_value));
data = switch_event_build_param_string(params, basic_data,binding->vars_map);
data = switch_event_build_param_string(params, basic_data, binding->vars_map);
switch_assert(data);
switch_uuid_get(&uuid);
@@ -166,8 +162,8 @@ static switch_xml_t xml_url_fetch(const char *section, const char *tag_name, con
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "freeswitch-xml/1.0");
if (binding->disable100continue) {
slist = curl_slist_append(slist, "Expect:");
curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, slist);
slist = curl_slist_append(slist, "Expect:");
curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, slist);
}
if (binding->ignore_cacert_check) {
@@ -206,6 +202,7 @@ static switch_xml_t xml_url_fetch(const char *section, const char *tag_name, con
return xml;
}
#define ENABLE_PARAM_VALUE "enabled"
static switch_status_t do_config(void)
{
@@ -214,9 +211,9 @@ static switch_status_t do_config(void)
xml_binding_t *binding = NULL;
int x = 0;
int need_vars_map = 0;
switch_hash_t* vars_map = NULL;
switch_memory_pool_t* vars_map_pool = NULL;
switch_hash_t *vars_map = NULL;
switch_memory_pool_t *vars_map_pool = NULL;
if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
return SWITCH_STATUS_TERM;
@@ -249,29 +246,29 @@ static switch_status_t do_config(void)
disable100continue = 1;
} else if (!strcasecmp(var, "ignore-cacert-check") && switch_true(val)) {
ignore_cacert_check = 1;
} else if(!strcasecmp(var, "enable-post-var")) {
} else if (!strcasecmp(var, "enable-post-var")) {
if (!vars_map && need_vars_map == 0) {
if (switch_core_new_memory_pool(&vars_map_pool) != SWITCH_STATUS_SUCCESS) {
need_vars_map = -1;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cant create memory pool!\n");
continue;
}
if (switch_core_hash_init(&vars_map,vars_map_pool) != SWITCH_STATUS_SUCCESS) {
need_vars_map = -1;
switch_core_destroy_memory_pool(&vars_map_pool);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cant init params hash!\n");
continue;
}
need_vars_map = 1;
if (switch_core_new_memory_pool(&vars_map_pool) != SWITCH_STATUS_SUCCESS) {
need_vars_map = -1;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cant create memory pool!\n");
continue;
}
if (switch_core_hash_init(&vars_map, vars_map_pool) != SWITCH_STATUS_SUCCESS) {
need_vars_map = -1;
switch_core_destroy_memory_pool(&vars_map_pool);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cant init params hash!\n");
continue;
}
need_vars_map = 1;
}
if (vars_map && val)
if (switch_core_hash_insert(vars_map, val, ENABLE_PARAM_VALUE) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cant add %s to params hash!\n",val);
}
}
if (switch_core_hash_insert(vars_map, val, ENABLE_PARAM_VALUE) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cant add %s to params hash!\n", val);
}
}
}
if (!url) {
@@ -296,7 +293,7 @@ static switch_status_t do_config(void)
binding->disable100continue = disable100continue;
binding->ignore_cacert_check = ignore_cacert_check;
binding->vars_map = vars_map;
binding->vars_map_pool = vars_map_pool;
@@ -307,7 +304,7 @@ static switch_status_t do_config(void)
binding = NULL;
}
done:
done:
switch_xml_free(xml);
return x ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
+38 -47
View File
@@ -96,17 +96,15 @@ SWITCH_STANDARD_API(xml_ldap_function)
}
if (!strcasecmp(cmd, "debug_on")) {
}
else if (!strcasecmp(cmd, "debug_off")) {
}
else {
} else if (!strcasecmp(cmd, "debug_off")) {
} else {
goto usage;
}
stream->write_function(stream, "OK\n");
return SWITCH_STATUS_SUCCESS;
usage:
usage:
stream->write_function(stream, "USAGE: %s\n", XML_LDAP_SYNTAX);
return SWITCH_STATUS_SUCCESS;
}
@@ -144,11 +142,10 @@ static switch_status_t xml_ldap_directory_result(void *ldap_connection, xml_bind
ldap->val = ldap_first_attribute(ldap->ld, ldap->entry, &ldap->berval);
do {
if (strstr(ldap->val, "value")) {
if (strstr(ldap->val, ldap->key) && strcmp(ldap->val, ldap->key) ) {
if (strstr(ldap->val, ldap->key) && strcmp(ldap->val, ldap->key)) {
if (!strcmp(ldap->key, "param")) {
params = switch_xml_add_child_d(asdf, "params", loff++);
}
else if (!strcmp(ldap->key, "variable")) {
} else if (!strcmp(ldap->key, "variable")) {
variables = switch_xml_add_child_d(asdf, "variables", loff++);
}
@@ -162,8 +159,7 @@ static switch_status_t xml_ldap_directory_result(void *ldap_connection, xml_bind
param = switch_xml_add_child_d(params, "param", loff++);
switch_xml_set_attr_d(param, "name", ldap->keyvals[i]);
switch_xml_set_attr_d(param, "value", ldap->valvals[i]);
}
else if (!strcmp(ldap->key, "variable")) {
} else if (!strcmp(ldap->key, "variable")) {
variable = switch_xml_add_child_d(variables, "variable", loff++);
switch_xml_set_attr_d(variable, "name", ldap->keyvals[i]);
switch_xml_set_attr_d(variable, "value", ldap->valvals[i]);
@@ -177,9 +173,9 @@ static switch_status_t xml_ldap_directory_result(void *ldap_connection, xml_bind
if (ldap->valvals) {
ldap_value_free(ldap->valvals);
}
}
else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "seems the values %d and %d are not the same??\n",ldap_count_values(ldap->valvals), ldap_count_values(ldap->keyvals));
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "seems the values %d and %d are not the same??\n",
ldap_count_values(ldap->valvals), ldap_count_values(ldap->keyvals));
}
}
}
@@ -200,7 +196,7 @@ static switch_status_t xml_ldap_directory_result(void *ldap_connection, xml_bind
ber_free(ldap->berval, 0);
}
ldap->key = ldap_next_attribute(ldap->ld, ldap->entry, ldap->berkey );
ldap->key = ldap_next_attribute(ldap->ld, ldap->entry, ldap->berkey);
} while (ldap->key != NULL);
@@ -212,9 +208,10 @@ static switch_status_t xml_ldap_directory_result(void *ldap_connection, xml_bind
}
static switch_xml_t xml_ldap_search(const char *section, const char *tag_name, const char *key_name, const char *key_value, switch_event_t *params, void *user_data)
static switch_xml_t xml_ldap_search(const char *section, const char *tag_name, const char *key_name, const char *key_value, switch_event_t *params,
void *user_data)
{
xml_binding_t *binding = (xml_binding_t *)user_data;
xml_binding_t *binding = (xml_binding_t *) user_data;
switch_event_header_t *hi;
switch_xml_t xml = NULL, sub = NULL;
@@ -222,7 +219,7 @@ static switch_xml_t xml_ldap_search(const char *section, const char *tag_name, c
struct ldap_c ldap_connection;
struct ldap_c *ldap = &ldap_connection;
int auth_method = LDAP_AUTH_SIMPLE;
int auth_method = LDAP_AUTH_SIMPLE;
int desired_version = LDAP_VERSION3;
xml_ldap_query_type_t query_type;
char *dir_exten = NULL, *dir_domain = NULL;
@@ -237,16 +234,13 @@ static switch_xml_t xml_ldap_search(const char *section, const char *tag_name, c
return NULL;
}
if (!strcmp(section,"configuration")) {
if (!strcmp(section, "configuration")) {
query_type = XML_LDAP_CONFIG;
}
else if (!strcmp(section,"directory")) {
} else if (!strcmp(section, "directory")) {
query_type = XML_LDAP_DIRECTORY;
}
else if (!strcmp(section,"dialplan")) {
} else if (!strcmp(section, "dialplan")) {
query_type = XML_LDAP_DIALPLAN;
}
else if (!strcmp(section,"phrases")) {
} else if (!strcmp(section, "phrases")) {
query_type = XML_LDAP_PHRASE;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "invalid section\n");
@@ -256,15 +250,14 @@ static switch_xml_t xml_ldap_search(const char *section, const char *tag_name, c
if (params) {
if ((hi = params->headers)) {
for (; hi; hi = hi->next) {
switch(query_type) {
switch (query_type) {
case XML_LDAP_CONFIG:
break;
case XML_LDAP_DIRECTORY:
if (!strcmp(hi->name,"user")) {
if (!strcmp(hi->name, "user")) {
dir_exten = strdup(hi->value);
}
else if (!strcmp(hi->name,"domain")) {
} else if (!strcmp(hi->name, "domain")) {
dir_domain = strdup(hi->value);
}
break;
@@ -274,7 +267,7 @@ static switch_xml_t xml_ldap_search(const char *section, const char *tag_name, c
break;
}
}
switch(query_type) {
switch (query_type) {
case XML_LDAP_CONFIG:
break;
@@ -282,7 +275,7 @@ static switch_xml_t xml_ldap_search(const char *section, const char *tag_name, c
if (dir_exten && dir_domain) {
if ((xml = switch_xml_new("directory"))) {
switch_xml_set_attr_d(xml, "type", "freeswitch/xml");
if ((sub = switch_xml_add_child_d(xml, "section", off++))) {
switch_xml_set_attr_d(sub, "name", "directory");
}
@@ -290,21 +283,23 @@ static switch_xml_t xml_ldap_search(const char *section, const char *tag_name, c
if ((sub = switch_xml_add_child_d(sub, "domain", off++))) {
switch_xml_set_attr_d(sub, "name", dir_domain);
}
if ((sub = switch_xml_add_child_d(sub, "user", off++))) {
switch_xml_set_attr_d(sub, "id", dir_exten);
}
}
search_base = switch_mprintf(binding->queryfmt, dir_exten, dir_domain, binding->ldap_base);
free(dir_exten);
dir_exten = NULL;
free(dir_domain);
dir_domain = NULL;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "something bad happened during the query construction phase likely exten(%s) or domain(%s) is null\n", dir_exten, dir_domain);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"something bad happened during the query construction phase likely exten(%s) or domain(%s) is null\n", dir_exten,
dir_domain);
goto cleanup;
}
break;
@@ -325,8 +320,7 @@ static switch_xml_t xml_ldap_search(const char *section, const char *tag_name, c
case XML_LDAP_PHRASE:
break;
}
}
else {
} else {
goto cleanup;
}
}
@@ -359,7 +353,7 @@ static switch_xml_t xml_ldap_search(const char *section, const char *tag_name, c
goto cleanup;
}
cleanup:
cleanup:
if (ldap->msg) {
ldap_msgfree(ldap->msg);
}
@@ -409,28 +403,25 @@ static switch_status_t do_config(void)
if (val) {
binding->queryfmt = strdup(val);
}
}
else if (!strcasecmp(var, "base")) {
} else if (!strcasecmp(var, "base")) {
binding->ldap_base = strdup(val);
}
else if (!strcasecmp(var, "binddn")) {
} else if (!strcasecmp(var, "binddn")) {
binding->binddn = strdup(val);
}
else if (!strcasecmp(var, "bindpass")) {
} else if (!strcasecmp(var, "bindpass")) {
binding->bindpass = strdup(val);
}
else if (!strcasecmp(var, "host")) {
} else if (!strcasecmp(var, "host")) {
binding->host = strdup(val);
}
}
if (!binding->ldap_base || !binding->binddn || !binding->bindpass || !binding->queryfmt) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "You must define \"base\", \"binddn\", \"bindpass\", and \"queryfmt\" in mod_xml_ldap.conf.xml\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"You must define \"base\", \"binddn\", \"bindpass\", and \"queryfmt\" in mod_xml_ldap.conf.xml\n");
continue;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Binding [%s] XML Fetch Function [%s] [%s]\n",
switch_strlen_zero(bname) ? "N/A" : bname, binding->ldap_base, binding->bindings ? binding->bindings : "all");
switch_strlen_zero(bname) ? "N/A" : bname, binding->ldap_base, binding->bindings ? binding->bindings : "all");
switch_xml_bind_search_function(xml_ldap_search, switch_xml_parse_section_string(bname), binding);
@@ -438,7 +429,7 @@ static switch_status_t do_config(void)
binding = NULL;
}
done:
done:
switch_xml_free(xml);
return SWITCH_STATUS_SUCCESS;
Loaded 100 of 101 files, more files were not shown because too many files have changed in this diff. Show more