mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-10-21 02:34:16 +00:00
indent pass 2
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8689 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
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(¶ms);
|
||||
@@ -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
@@ -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(¶ms);
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
+1151
-1290
File diff suppressed because it is too large.
Load diff
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
Reference in new issue
Block a user