mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-10-29 06:34:19 +00:00
spring cleaning
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4795 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
1 parent
a021945cef
commit
3a54126261
143 files changed
+22413
-31567
No files matched your search
@@ -44,11 +44,11 @@ static void audio_bridge_function(switch_core_session_t *session, char *data)
|
||||
char *var;
|
||||
uint8_t no_media_bridge = 0;
|
||||
switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING;
|
||||
uint8_t do_continue = 0;
|
||||
uint8_t do_continue = 0;
|
||||
|
||||
if (switch_strlen_zero(data)) {
|
||||
return;
|
||||
}
|
||||
if (switch_strlen_zero(data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
caller_channel = switch_core_session_get_channel(session);
|
||||
assert(caller_channel != NULL);
|
||||
@@ -60,43 +60,50 @@ static void audio_bridge_function(switch_core_session_t *session, char *data)
|
||||
if ((var = switch_channel_get_variable(caller_channel, "continue_on_fail"))) {
|
||||
do_continue = switch_true(var);
|
||||
}
|
||||
|
||||
if (switch_channel_test_flag(caller_channel, CF_NOMEDIA) || ((var = switch_channel_get_variable(caller_channel, "no_media")) && switch_true(var))) {
|
||||
if (!switch_channel_test_flag(caller_channel, CF_ANSWERED) && !switch_channel_test_flag(caller_channel, CF_EARLY_MEDIA)) {
|
||||
|
||||
if (switch_channel_test_flag(caller_channel, CF_NOMEDIA)
|
||||
|| ((var = switch_channel_get_variable(caller_channel, "no_media")) && switch_true(var))) {
|
||||
if (!switch_channel_test_flag(caller_channel, CF_ANSWERED)
|
||||
&& !switch_channel_test_flag(caller_channel, CF_EARLY_MEDIA)) {
|
||||
switch_channel_set_flag(caller_channel, CF_NOMEDIA);
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Channel is already up, delaying point-to-point mode 'till both legs are up.\n");
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
|
||||
"Channel is already up, delaying point-to-point mode 'till both legs are up.\n");
|
||||
no_media_bridge = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (switch_ivr_originate(session, &peer_session, &cause, data, timelimit, NULL, NULL, NULL, NULL) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Originate Failed. Cause: %s\n", switch_channel_cause2str(cause));
|
||||
if (!do_continue && cause != SWITCH_CAUSE_NO_ANSWER) {
|
||||
/* All Causes besides NO_ANSWER terminate the originating session unless continue_on_fail is set.
|
||||
We will pass the fail cause on when we hangup.*/
|
||||
switch_channel_hangup(caller_channel, cause);
|
||||
}
|
||||
/* Otherwise.. nobody answered. Go back to the dialplan instructions in case there was more to do. */
|
||||
if (switch_ivr_originate(session, &peer_session, &cause, data, timelimit, NULL, NULL, NULL, NULL) !=
|
||||
SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Originate Failed. Cause: %s\n",
|
||||
switch_channel_cause2str(cause));
|
||||
if (!do_continue && cause != SWITCH_CAUSE_NO_ANSWER) {
|
||||
/* All Causes besides NO_ANSWER terminate the originating session unless continue_on_fail is set.
|
||||
We will pass the fail cause on when we hangup. */
|
||||
switch_channel_hangup(caller_channel, cause);
|
||||
}
|
||||
/* Otherwise.. nobody answered. Go back to the dialplan instructions in case there was more to do. */
|
||||
return;
|
||||
} else {
|
||||
if (no_media_bridge) {
|
||||
switch_channel_t *peer_channel = switch_core_session_get_channel(peer_session);
|
||||
switch_frame_t *read_frame;
|
||||
/* SIP won't let us redir media until the call has been answered #$^#%& so we will proxy any early media until they do */
|
||||
while(switch_channel_ready(caller_channel) && switch_channel_ready(peer_channel) && !switch_channel_test_flag(peer_channel, CF_ANSWERED)) {
|
||||
switch_status_t status = switch_core_session_read_frame(peer_session, &read_frame, -1, 0);
|
||||
uint8_t bad = 1;
|
||||
switch_channel_t *peer_channel = switch_core_session_get_channel(peer_session);
|
||||
switch_frame_t *read_frame;
|
||||
/* SIP won't let us redir media until the call has been answered #$^#%& so we will proxy any early media until they do */
|
||||
while (switch_channel_ready(caller_channel) && switch_channel_ready(peer_channel)
|
||||
&& !switch_channel_test_flag(peer_channel, CF_ANSWERED)) {
|
||||
switch_status_t status = switch_core_session_read_frame(peer_session, &read_frame, -1, 0);
|
||||
uint8_t bad = 1;
|
||||
|
||||
if (SWITCH_READ_ACCEPTABLE(status) && switch_core_session_write_frame(session, read_frame, -1, 0) == SWITCH_STATUS_SUCCESS) {
|
||||
bad = 0;
|
||||
}
|
||||
if (bad) {
|
||||
switch_channel_hangup(caller_channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
|
||||
switch_channel_hangup(peer_channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (SWITCH_READ_ACCEPTABLE(status)
|
||||
&& switch_core_session_write_frame(session, read_frame, -1, 0) == SWITCH_STATUS_SUCCESS) {
|
||||
bad = 0;
|
||||
}
|
||||
if (bad) {
|
||||
switch_channel_hangup(caller_channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
|
||||
switch_channel_hangup(peer_channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Redirecting media to point-to-point mode.\n");
|
||||
switch_ivr_nomedia(switch_core_session_get_uuid(session), SMF_FORCE);
|
||||
@@ -130,7 +137,8 @@ static const switch_loadable_module_interface_t mod_bridgecall_module_interface
|
||||
/*.application_interface */ &bridge_application_interface
|
||||
};
|
||||
|
||||
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
|
||||
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
|
||||
char *filename)
|
||||
{
|
||||
|
||||
/* connect my internal structure to the blank pointer passed to me */
|
||||
|
||||
@@ -76,18 +76,15 @@ static switch_status_t status_function(char *cmd, switch_core_session_t *session
|
||||
stream->write_function(stream, "<h1>FreeSWITCH Status</h1>\n<b>");
|
||||
}
|
||||
|
||||
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"
|
||||
);
|
||||
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");
|
||||
|
||||
stream->write_function(stream, "%d sessions\n", switch_core_session_count());
|
||||
|
||||
|
||||
if (html) {
|
||||
stream->write_function(stream, "</b>\n");
|
||||
}
|
||||
@@ -98,8 +95,10 @@ static switch_status_t status_function(char *cmd, switch_core_session_t *session
|
||||
int r;
|
||||
refresh++;
|
||||
r = atoi(refresh);
|
||||
if (r > 0) {
|
||||
stream->write_function(stream, "<META HTTP-EQUIV=REFRESH CONTENT=\"%d; URL=/api/status?refresh=%d%s\">\n", r, r, html ? "html=1" : "");
|
||||
if (r > 0) {
|
||||
stream->write_function(stream,
|
||||
"<META HTTP-EQUIV=REFRESH CONTENT=\"%d; URL=/api/status?refresh=%d%s\">\n", r, r,
|
||||
html ? "html=1" : "");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -120,7 +119,7 @@ static switch_status_t ctl_function(char *data, switch_core_session_t *session,
|
||||
|
||||
if ((mydata = strdup(data))) {
|
||||
argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
|
||||
|
||||
|
||||
if (!strcmp(argv[0], "hupall")) {
|
||||
arg = 1;
|
||||
switch_core_session_ctl(SCSC_HUPALL, &arg);
|
||||
@@ -134,19 +133,20 @@ static switch_status_t ctl_function(char *data, switch_core_session_t *session,
|
||||
arg = 0;
|
||||
switch_core_session_ctl(SCSC_SHUTDOWN, &arg);
|
||||
} else {
|
||||
stream->write_function(stream, "INVALID COMMAND [%s]\nUSAGE: fsctl [hupall|pause|resume|shutdown]\n", argv[0]);
|
||||
stream->write_function(stream, "INVALID COMMAND [%s]\nUSAGE: fsctl [hupall|pause|resume|shutdown]\n",
|
||||
argv[0]);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
stream->write_function(stream, "OK\n");
|
||||
end:
|
||||
end:
|
||||
free(mydata);
|
||||
} else {
|
||||
stream->write_function(stream, "MEM ERR\n");
|
||||
}
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
|
||||
}
|
||||
|
||||
static switch_status_t load_function(char *mod, switch_core_session_t *session, switch_stream_handle_t *stream)
|
||||
@@ -161,7 +161,8 @@ static switch_status_t load_function(char *mod, switch_core_session_t *session,
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
if (switch_loadable_module_load_module((char *) SWITCH_GLOBAL_dirs.mod_dir, (char *) mod, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS) {
|
||||
if (switch_loadable_module_load_module((char *) SWITCH_GLOBAL_dirs.mod_dir, (char *) mod, SWITCH_TRUE) ==
|
||||
SWITCH_STATUS_SUCCESS) {
|
||||
stream->write_function(stream, "OK\n");
|
||||
} else {
|
||||
stream->write_function(stream, "ERROR\n");
|
||||
@@ -178,11 +179,11 @@ static switch_status_t reload_function(char *args, switch_core_session_t *sessio
|
||||
if (session) {
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
|
||||
if ((xml_root = switch_xml_open_root(1, &err))) {
|
||||
switch_xml_free(xml_root);
|
||||
}
|
||||
|
||||
|
||||
stream->write_function(stream, "OK [%s]\n", err);
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
@@ -213,13 +214,13 @@ static switch_status_t kill_function(char *dest, switch_core_session_t *isession
|
||||
static switch_status_t transfer_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream)
|
||||
{
|
||||
switch_core_session_t *session = NULL;
|
||||
char *argv[4] = {0};
|
||||
char *argv[4] = { 0 };
|
||||
int argc = 0;
|
||||
|
||||
if (isession) {
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
|
||||
argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
|
||||
|
||||
if (switch_strlen_zero(cmd) || argc < 2 || argc > 4) {
|
||||
@@ -229,11 +230,11 @@ static switch_status_t transfer_function(char *cmd, switch_core_session_t *isess
|
||||
char *dest = argv[1];
|
||||
char *dp = argv[2];
|
||||
char *context = argv[3];
|
||||
|
||||
|
||||
if ((session = switch_core_session_locate(uuid))) {
|
||||
|
||||
if (switch_ivr_session_transfer(session, dest, dp, context) == SWITCH_STATUS_SUCCESS) {
|
||||
stream->write_function(stream, "OK\n");
|
||||
stream->write_function(stream, "OK\n");
|
||||
} else {
|
||||
stream->write_function(stream, "ERROR\n");
|
||||
}
|
||||
@@ -249,16 +250,17 @@ static switch_status_t transfer_function(char *cmd, switch_core_session_t *isess
|
||||
}
|
||||
|
||||
|
||||
static switch_status_t sched_transfer_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream)
|
||||
static switch_status_t sched_transfer_function(char *cmd, switch_core_session_t *isession,
|
||||
switch_stream_handle_t *stream)
|
||||
{
|
||||
switch_core_session_t *session = NULL;
|
||||
char *argv[6] = {0};
|
||||
char *argv[6] = { 0 };
|
||||
int argc = 0;
|
||||
|
||||
if (isession) {
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
|
||||
argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
|
||||
|
||||
if (switch_strlen_zero(cmd) || argc < 2 || argc > 5) {
|
||||
@@ -269,9 +271,9 @@ static switch_status_t sched_transfer_function(char *cmd, switch_core_session_t
|
||||
char *dp = argv[3];
|
||||
char *context = argv[4];
|
||||
time_t when;
|
||||
|
||||
|
||||
if (*argv[0] == '+') {
|
||||
when = time (NULL) + atol(argv[0] + 1);
|
||||
when = time(NULL) + atol(argv[0] + 1);
|
||||
} else {
|
||||
when = atol(argv[0]);
|
||||
}
|
||||
@@ -291,13 +293,13 @@ static switch_status_t sched_transfer_function(char *cmd, switch_core_session_t
|
||||
static switch_status_t sched_hangup_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream)
|
||||
{
|
||||
switch_core_session_t *session = NULL;
|
||||
char *argv[4] = {0};
|
||||
char *argv[4] = { 0 };
|
||||
int argc = 0;
|
||||
|
||||
if (isession) {
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
|
||||
argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
|
||||
|
||||
if (switch_strlen_zero(cmd) || argc < 1) {
|
||||
@@ -309,7 +311,7 @@ static switch_status_t sched_hangup_function(char *cmd, switch_core_session_t *i
|
||||
switch_call_cause_t cause = SWITCH_CAUSE_ALLOTTED_TIMEOUT;
|
||||
|
||||
if (*argv[0] == '+') {
|
||||
when = time (NULL) + atol(argv[0] + 1);
|
||||
when = time(NULL) + atol(argv[0] + 1);
|
||||
} else {
|
||||
when = atol(argv[0]);
|
||||
}
|
||||
@@ -333,14 +335,14 @@ static switch_status_t sched_hangup_function(char *cmd, switch_core_session_t *i
|
||||
|
||||
static switch_status_t uuid_media_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream)
|
||||
{
|
||||
char *argv[4] = {0};
|
||||
char *argv[4] = { 0 };
|
||||
int argc = 0;
|
||||
switch_status_t status = SWITCH_STATUS_FALSE;
|
||||
|
||||
|
||||
if (isession) {
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
|
||||
|
||||
if (switch_strlen_zero(cmd) || argc < 1) {
|
||||
@@ -363,16 +365,17 @@ static switch_status_t uuid_media_function(char *cmd, switch_core_session_t *ise
|
||||
}
|
||||
|
||||
|
||||
static switch_status_t uuid_broadcast_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream)
|
||||
static switch_status_t uuid_broadcast_function(char *cmd, switch_core_session_t *isession,
|
||||
switch_stream_handle_t *stream)
|
||||
{
|
||||
char *argv[4] = {0};
|
||||
char *argv[4] = { 0 };
|
||||
int argc = 0;
|
||||
switch_status_t status = SWITCH_STATUS_FALSE;
|
||||
|
||||
if (isession) {
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
|
||||
|
||||
if (switch_strlen_zero(cmd) || argc < 2) {
|
||||
@@ -391,7 +394,7 @@ static switch_status_t uuid_broadcast_function(char *cmd, switch_core_session_t
|
||||
} else {
|
||||
flags |= SMF_ECHO_ALEG;
|
||||
}
|
||||
|
||||
|
||||
status = switch_ivr_broadcast(argv[0], argv[1], flags);
|
||||
stream->write_function(stream, "+OK Message Sent\n");
|
||||
}
|
||||
@@ -400,16 +403,17 @@ static switch_status_t uuid_broadcast_function(char *cmd, switch_core_session_t
|
||||
}
|
||||
|
||||
|
||||
static switch_status_t sched_broadcast_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream)
|
||||
static switch_status_t sched_broadcast_function(char *cmd, switch_core_session_t *isession,
|
||||
switch_stream_handle_t *stream)
|
||||
{
|
||||
char *argv[4] = {0};
|
||||
char *argv[4] = { 0 };
|
||||
int argc = 0;
|
||||
switch_status_t status = SWITCH_STATUS_FALSE;
|
||||
|
||||
if (isession) {
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
|
||||
|
||||
if (switch_strlen_zero(cmd) || argc < 3) {
|
||||
@@ -419,7 +423,7 @@ static switch_status_t sched_broadcast_function(char *cmd, switch_core_session_t
|
||||
time_t when;
|
||||
|
||||
if (*argv[0] == '+') {
|
||||
when = time (NULL) + atol(argv[0] + 1);
|
||||
when = time(NULL) + atol(argv[0] + 1);
|
||||
} else {
|
||||
when = atol(argv[0]);
|
||||
}
|
||||
@@ -435,7 +439,7 @@ static switch_status_t sched_broadcast_function(char *cmd, switch_core_session_t
|
||||
} else {
|
||||
flags |= SMF_ECHO_ALEG;
|
||||
}
|
||||
|
||||
|
||||
status = switch_ivr_schedule_broadcast(when, argv[1], argv[2], flags);
|
||||
stream->write_function(stream, "+OK Message Scheduled\n");
|
||||
}
|
||||
@@ -445,14 +449,14 @@ static switch_status_t sched_broadcast_function(char *cmd, switch_core_session_t
|
||||
|
||||
static switch_status_t uuid_hold_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream)
|
||||
{
|
||||
char *argv[4] = {0};
|
||||
char *argv[4] = { 0 };
|
||||
int argc = 0;
|
||||
switch_status_t status = SWITCH_STATUS_FALSE;
|
||||
|
||||
|
||||
if (isession) {
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
|
||||
|
||||
if (switch_strlen_zero(cmd) || argc < 1) {
|
||||
@@ -476,13 +480,13 @@ static switch_status_t uuid_hold_function(char *cmd, switch_core_session_t *ises
|
||||
|
||||
static switch_status_t uuid_bridge_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream)
|
||||
{
|
||||
char *argv[4] = {0};
|
||||
char *argv[4] = { 0 };
|
||||
int argc = 0;
|
||||
|
||||
if (isession) {
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
|
||||
argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
|
||||
|
||||
if (switch_strlen_zero(cmd) || argc != 2) {
|
||||
@@ -496,72 +500,73 @@ static switch_status_t uuid_bridge_function(char *cmd, switch_core_session_t *is
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static switch_status_t session_record_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream)
|
||||
static switch_status_t session_record_function(char *cmd, switch_core_session_t *isession,
|
||||
switch_stream_handle_t *stream)
|
||||
{
|
||||
switch_core_session_t *session = NULL;
|
||||
char *argv[4] = {0};
|
||||
char *uuid = NULL, *action = NULL, *path = NULL;
|
||||
switch_core_session_t *session = NULL;
|
||||
char *argv[4] = { 0 };
|
||||
char *uuid = NULL, *action = NULL, *path = NULL;
|
||||
int argc = 0;
|
||||
|
||||
if (isession) {
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
|
||||
if (switch_strlen_zero(cmd)) {
|
||||
goto usage;
|
||||
}
|
||||
goto usage;
|
||||
}
|
||||
|
||||
if ((argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) != 3) {
|
||||
goto usage;
|
||||
}
|
||||
goto usage;
|
||||
}
|
||||
|
||||
uuid = argv[0];
|
||||
action = argv[1];
|
||||
path = argv[2];
|
||||
|
||||
if (!(session = switch_core_session_locate(uuid))) {
|
||||
uuid = argv[0];
|
||||
action = argv[1];
|
||||
path = argv[2];
|
||||
|
||||
if (!(session = switch_core_session_locate(uuid))) {
|
||||
stream->write_function(stream, "-Error Cannot locate session!\n");
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
if (switch_strlen_zero(action) || switch_strlen_zero(path)) {
|
||||
goto usage;
|
||||
}
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
if (!strcasecmp(action, "start")) {
|
||||
switch_ivr_record_session(session, path, NULL);
|
||||
} else if (!strcasecmp(action, "stop")) {
|
||||
switch_ivr_stop_record_session(session, path);
|
||||
} else {
|
||||
goto usage;
|
||||
}
|
||||
if (switch_strlen_zero(action) || switch_strlen_zero(path)) {
|
||||
goto usage;
|
||||
}
|
||||
|
||||
goto done;
|
||||
if (!strcasecmp(action, "start")) {
|
||||
switch_ivr_record_session(session, path, NULL);
|
||||
} else if (!strcasecmp(action, "stop")) {
|
||||
switch_ivr_stop_record_session(session, path);
|
||||
} else {
|
||||
goto usage;
|
||||
}
|
||||
|
||||
usage:
|
||||
goto done;
|
||||
|
||||
stream->write_function(stream, "USAGE: %s\n", session_record_api_interface.syntax);
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
usage:
|
||||
|
||||
done:
|
||||
stream->write_function(stream, "USAGE: %s\n", session_record_api_interface.syntax);
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
|
||||
if (session) {
|
||||
switch_core_session_rwunlock(session);
|
||||
}
|
||||
done:
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
if (session) {
|
||||
switch_core_session_rwunlock(session);
|
||||
}
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static switch_status_t pause_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream)
|
||||
{
|
||||
switch_core_session_t *session = NULL;
|
||||
char *argv[4] = {0};
|
||||
char *argv[4] = { 0 };
|
||||
int argc = 0;
|
||||
|
||||
if (isession) {
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
|
||||
argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
|
||||
|
||||
if (switch_strlen_zero(cmd) || argc < 2) {
|
||||
@@ -569,7 +574,7 @@ static switch_status_t pause_function(char *cmd, switch_core_session_t *isession
|
||||
} else {
|
||||
char *uuid = argv[0];
|
||||
char *dest = argv[1];
|
||||
|
||||
|
||||
if ((session = switch_core_session_locate(uuid))) {
|
||||
switch_channel_t *channel = switch_core_session_get_channel(session);
|
||||
|
||||
@@ -593,7 +598,7 @@ static switch_status_t originate_function(char *cmd, switch_core_session_t *ises
|
||||
{
|
||||
switch_channel_t *caller_channel;
|
||||
switch_core_session_t *caller_session;
|
||||
char *argv[7] = {0};
|
||||
char *argv[7] = { 0 };
|
||||
int i = 0, x, argc = 0;
|
||||
char *aleg, *exten, *dp, *context, *cid_name, *cid_num;
|
||||
uint32_t timeout = 60;
|
||||
@@ -612,12 +617,12 @@ static switch_status_t originate_function(char *cmd, switch_core_session_t *ises
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
for(x = 0; x < argc; x++) {
|
||||
for (x = 0; x < argc; x++) {
|
||||
if (!strcasecmp(argv[x], "undef")) {
|
||||
argv[x] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!strcasecmp(argv[0], "machine")) {
|
||||
machine = 1;
|
||||
i++;
|
||||
@@ -629,7 +634,7 @@ static switch_status_t originate_function(char *cmd, switch_core_session_t *ises
|
||||
context = argv[i++];
|
||||
cid_name = argv[i++];
|
||||
cid_num = argv[i++];
|
||||
|
||||
|
||||
if (!dp) {
|
||||
dp = "XML";
|
||||
}
|
||||
@@ -642,20 +647,22 @@ static switch_status_t originate_function(char *cmd, switch_core_session_t *ises
|
||||
timeout = atoi(argv[6]);
|
||||
}
|
||||
|
||||
if (switch_ivr_originate(NULL, &caller_session, &cause, aleg, timeout, NULL, cid_name, cid_num, NULL) != SWITCH_STATUS_SUCCESS) {
|
||||
if (switch_ivr_originate(NULL, &caller_session, &cause, aleg, timeout, NULL, cid_name, cid_num, NULL) !=
|
||||
SWITCH_STATUS_SUCCESS) {
|
||||
if (machine) {
|
||||
stream->write_function(stream, "fail: %s\n", switch_channel_cause2str(cause));
|
||||
} else {
|
||||
stream->write_function(stream, "Cannot Create Outgoing Channel! [%s] cause: %s\n", aleg, switch_channel_cause2str(cause));
|
||||
stream->write_function(stream, "Cannot Create Outgoing Channel! [%s] cause: %s\n", aleg,
|
||||
switch_channel_cause2str(cause));
|
||||
}
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
caller_channel = switch_core_session_get_channel(caller_session);
|
||||
assert(caller_channel != NULL);
|
||||
switch_channel_clear_state_handler(caller_channel, NULL);
|
||||
|
||||
if (*exten == '&' && *(exten + 1)) {
|
||||
if (*exten == '&' && *(exten + 1)) {
|
||||
switch_caller_extension_t *extension = NULL;
|
||||
char *app_name = switch_core_session_strdup(caller_session, (exten + 1));
|
||||
char *arg = NULL, *e;
|
||||
@@ -696,7 +703,8 @@ struct holder {
|
||||
int print_title;
|
||||
};
|
||||
|
||||
static int show_callback(void *pArg, int argc, char **argv, char **columnNames){
|
||||
static int show_callback(void *pArg, int argc, char **argv, char **columnNames)
|
||||
{
|
||||
struct holder *holder = (struct holder *) pArg;
|
||||
int x;
|
||||
|
||||
@@ -706,26 +714,29 @@ static int show_callback(void *pArg, int argc, char **argv, char **columnNames){
|
||||
holder->stream->write_function(holder->stream, "\n<tr>");
|
||||
}
|
||||
|
||||
for(x = 0; x < argc; x++) {
|
||||
for (x = 0; x < argc; x++) {
|
||||
if (holder->http) {
|
||||
holder->stream->write_function(holder->stream, "<td>");
|
||||
holder->stream->write_function(holder->stream, "<b>%s</b>%s", columnNames[x], x == (argc - 1) ? "</td></tr>\n" : "</td><td>");
|
||||
holder->stream->write_function(holder->stream, "<b>%s</b>%s", columnNames[x],
|
||||
x == (argc - 1) ? "</td></tr>\n" : "</td><td>");
|
||||
} else {
|
||||
holder->stream->write_function(holder->stream, "%s%s", columnNames[x], x == (argc - 1) ? "\n" : ",");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (holder->http) {
|
||||
holder->stream->write_function(holder->stream, "<tr bgcolor=%s>", holder->count % 2 == 0 ? "eeeeee" : "ffffff");
|
||||
}
|
||||
|
||||
for(x = 0; x < argc; x++) {
|
||||
for (x = 0; x < argc; x++) {
|
||||
if (holder->http) {
|
||||
holder->stream->write_function(holder->stream, "<td>");
|
||||
holder->stream->write_function(holder->stream, "%s%s", argv[x] ? argv[x] : "", x == (argc - 1) ? "</td></tr>\n" : "</td><td>");
|
||||
holder->stream->write_function(holder->stream, "%s%s", argv[x] ? argv[x] : "",
|
||||
x == (argc - 1) ? "</td></tr>\n" : "</td><td>");
|
||||
} else {
|
||||
holder->stream->write_function(holder->stream, "%s%s", argv[x] ? argv[x] : "", x == (argc - 1) ? "\n" : ",");
|
||||
holder->stream->write_function(holder->stream, "%s%s", argv[x] ? argv[x] : "",
|
||||
x == (argc - 1) ? "\n" : ",");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -738,7 +749,7 @@ static switch_status_t show_function(char *cmd, switch_core_session_t *session,
|
||||
char sql[1024];
|
||||
char *errmsg;
|
||||
switch_core_db_t *db = switch_core_db_handle();
|
||||
struct holder holder = {0};
|
||||
struct holder holder = { 0 };
|
||||
int help = 0;
|
||||
|
||||
if (session) {
|
||||
@@ -747,7 +758,7 @@ static switch_status_t show_function(char *cmd, switch_core_session_t *session,
|
||||
|
||||
if (stream->event) {
|
||||
holder.http = switch_event_get_header(stream->event, "http-host");
|
||||
}
|
||||
}
|
||||
|
||||
holder.print_title = 1;
|
||||
|
||||
@@ -756,14 +767,14 @@ static switch_status_t show_function(char *cmd, switch_core_session_t *session,
|
||||
if (!cmd) {
|
||||
stream->write_function(stream, "USAGE: %s\n", show_api_interface.syntax);
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
} else if ( !strcmp(cmd,"codec") || !strcmp(cmd,"dialplan") || !strcmp(cmd,"file") || !strcmp(cmd,"timer")) {
|
||||
sprintf (sql, "select type, name from interfaces where type = '%s'", cmd);
|
||||
} else if (!strcmp(cmd,"application") || !strcmp(cmd,"api")) {
|
||||
sprintf (sql, "select name, description, syntax from interfaces where type = '%s' and description != ''" , cmd);
|
||||
} else if ( !strcmp(cmd,"calls")) {
|
||||
sprintf (sql, "select * from calls");
|
||||
} else if ( !strcmp(cmd,"channels")) {
|
||||
sprintf (sql, "select * from channels");
|
||||
} else if (!strcmp(cmd, "codec") || !strcmp(cmd, "dialplan") || !strcmp(cmd, "file") || !strcmp(cmd, "timer")) {
|
||||
sprintf(sql, "select type, name from interfaces where type = '%s'", cmd);
|
||||
} else if (!strcmp(cmd, "application") || !strcmp(cmd, "api")) {
|
||||
sprintf(sql, "select name, description, syntax from interfaces where type = '%s' and description != ''", cmd);
|
||||
} else if (!strcmp(cmd, "calls")) {
|
||||
sprintf(sql, "select * from calls");
|
||||
} else if (!strcmp(cmd, "channels")) {
|
||||
sprintf(sql, "select * from channels");
|
||||
} else if (!strncasecmp(cmd, "help", 4)) {
|
||||
char *cmdname = NULL;
|
||||
|
||||
@@ -771,15 +782,16 @@ static switch_status_t show_function(char *cmd, switch_core_session_t *session,
|
||||
holder.print_title = 0;
|
||||
if ((cmdname = strchr(cmd, ' ')) != 0) {
|
||||
*cmdname++ = '\0';
|
||||
snprintf (sql, sizeof(sql) - 1, "select name, syntax, description from interfaces where type = 'api' and name = '%s'", cmdname);
|
||||
snprintf(sql, sizeof(sql) - 1,
|
||||
"select name, syntax, description from interfaces where type = 'api' and name = '%s'", cmdname);
|
||||
} else {
|
||||
snprintf (sql, sizeof(sql) - 1, "select name, syntax, description from interfaces where type = 'api'");
|
||||
snprintf(sql, sizeof(sql) - 1, "select name, syntax, description from interfaces where type = 'api'");
|
||||
}
|
||||
} else {
|
||||
stream->write_function(stream, "USAGE: %s\n", show_api_interface.syntax);
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
holder.stream = stream;
|
||||
holder.count = 0;
|
||||
|
||||
@@ -794,7 +806,7 @@ static switch_status_t show_function(char *cmd, switch_core_session_t *session,
|
||||
}
|
||||
|
||||
if (errmsg) {
|
||||
stream->write_function(stream, "SQL ERR [%s]\n",errmsg);
|
||||
stream->write_function(stream, "SQL ERR [%s]\n", errmsg);
|
||||
switch_core_db_free(errmsg);
|
||||
errmsg = NULL;
|
||||
} else if (help) {
|
||||
@@ -811,7 +823,7 @@ static switch_status_t show_function(char *cmd, switch_core_session_t *session,
|
||||
static switch_status_t version_function(char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream)
|
||||
{
|
||||
char version_string[1024];
|
||||
snprintf(version_string, sizeof(version_string) - 1, "FreeSwitch Version %s\n", SWITCH_VERSION_FULL);
|
||||
snprintf(version_string, sizeof(version_string) - 1, "FreeSwitch Version %s\n", SWITCH_VERSION_FULL);
|
||||
|
||||
stream->write_function(stream, version_string);
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
@@ -822,10 +834,10 @@ static switch_status_t help_function(char *cmd, switch_core_session_t *session,
|
||||
char showcmd[1024];
|
||||
int all = 0;
|
||||
if (switch_strlen_zero(cmd)) {
|
||||
sprintf (showcmd, "help");
|
||||
sprintf(showcmd, "help");
|
||||
all = 1;
|
||||
} else {
|
||||
snprintf(showcmd, sizeof(showcmd) -1, "help %s", cmd);
|
||||
snprintf(showcmd, sizeof(showcmd) - 1, "help %s", cmd);
|
||||
}
|
||||
|
||||
if (all) {
|
||||
@@ -986,7 +998,8 @@ static switch_api_interface_t originate_api_interface = {
|
||||
/*.interface_name */ "originate",
|
||||
/*.desc */ "Originate a Call",
|
||||
/*.function */ originate_function,
|
||||
/*.syntax */ "<call url> <exten>|&<application_name>(<app_args>) [<dialplan>] [<context>] [<cid_name>] [<cid_num>] [<timeout_sec>]",
|
||||
/*.syntax */
|
||||
"<call url> <exten>|&<application_name>(<app_args>) [<dialplan>] [<context>] [<cid_name>] [<cid_num>] [<timeout_sec>]",
|
||||
/*.next */ &kill_api_interface
|
||||
};
|
||||
|
||||
@@ -1000,7 +1013,8 @@ static const switch_loadable_module_interface_t mod_commands_module_interface =
|
||||
/*.api_interface */ &originate_api_interface
|
||||
};
|
||||
|
||||
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
|
||||
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
|
||||
char *filename)
|
||||
{
|
||||
/* connect my internal structure to the blank pointer passed to me */
|
||||
*module_interface = &mod_commands_module_interface;
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -43,7 +43,8 @@ static void detect_speech_function(switch_core_session_t *session, char *data)
|
||||
int argc;
|
||||
char *lbuf = NULL;
|
||||
|
||||
if (data && (lbuf = switch_core_session_strdup(session, data)) && (argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
|
||||
if (data && (lbuf = switch_core_session_strdup(session, data))
|
||||
&& (argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
|
||||
if (!strcasecmp(argv[0], "grammar") && argc >= 1) {
|
||||
switch_ivr_detect_speech_load_grammar(session, argv[1], argv[2]);
|
||||
} else if (!strcasecmp(argv[0], "nogrammar")) {
|
||||
@@ -58,16 +59,17 @@ static void detect_speech_function(switch_core_session_t *session, char *data)
|
||||
switch_ivr_detect_speech(session, argv[0], argv[1], argv[2], argv[3], NULL);
|
||||
}
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Usage: %s\n", detect_speech_application_interface.syntax);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Usage: %s\n",
|
||||
detect_speech_application_interface.syntax);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
static void ring_ready_function(switch_core_session_t *session, char *data)
|
||||
{
|
||||
switch_channel_t *channel;
|
||||
channel = switch_core_session_get_channel(session);
|
||||
assert(channel != NULL);
|
||||
assert(channel != NULL);
|
||||
switch_channel_ring_ready(channel);
|
||||
}
|
||||
|
||||
@@ -84,7 +86,7 @@ static void queue_dtmf_function(switch_core_session_t *session, char *data)
|
||||
static void transfer_function(switch_core_session_t *session, char *data)
|
||||
{
|
||||
int argc;
|
||||
char *argv[4] = {0};
|
||||
char *argv[4] = { 0 };
|
||||
char *mydata;
|
||||
|
||||
if (data && (mydata = switch_core_session_strdup(session, data))) {
|
||||
@@ -99,15 +101,15 @@ static void transfer_function(switch_core_session_t *session, char *data)
|
||||
static void sched_transfer_function(switch_core_session_t *session, char *data)
|
||||
{
|
||||
int argc;
|
||||
char *argv[4] = {0};
|
||||
char *argv[4] = { 0 };
|
||||
char *mydata;
|
||||
|
||||
|
||||
if (data && (mydata = switch_core_session_strdup(session, data))) {
|
||||
if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) >= 2) {
|
||||
time_t when;
|
||||
|
||||
if (*argv[0] == '+') {
|
||||
when = time (NULL) + atol(argv[0] + 1);
|
||||
when = time(NULL) + atol(argv[0] + 1);
|
||||
} else {
|
||||
when = atol(argv[0]);
|
||||
}
|
||||
@@ -122,7 +124,7 @@ static void sched_transfer_function(switch_core_session_t *session, char *data)
|
||||
static void sched_hangup_function(switch_core_session_t *session, char *data)
|
||||
{
|
||||
int argc;
|
||||
char *argv[5] = {0};
|
||||
char *argv[5] = { 0 };
|
||||
char *mydata;
|
||||
|
||||
if (data && (mydata = switch_core_session_strdup(session, data))) {
|
||||
@@ -132,11 +134,11 @@ static void sched_hangup_function(switch_core_session_t *session, char *data)
|
||||
switch_bool_t bleg = SWITCH_FALSE;
|
||||
|
||||
if (*argv[0] == '+') {
|
||||
when = time (NULL) + atol(argv[0] + 1);
|
||||
when = time(NULL) + atol(argv[0] + 1);
|
||||
} else {
|
||||
when = atol(argv[0]);
|
||||
}
|
||||
|
||||
|
||||
if (argv[1]) {
|
||||
cause = switch_channel_str2cause(argv[1]);
|
||||
}
|
||||
@@ -156,20 +158,20 @@ static void sched_hangup_function(switch_core_session_t *session, char *data)
|
||||
static void sched_broadcast_function(switch_core_session_t *session, char *data)
|
||||
{
|
||||
int argc;
|
||||
char *argv[6] = {0};
|
||||
char *argv[6] = { 0 };
|
||||
char *mydata;
|
||||
|
||||
if (data && (mydata = switch_core_session_strdup(session, data))) {
|
||||
if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) >= 2) {
|
||||
time_t when;
|
||||
switch_media_flag_t flags = SMF_NONE;
|
||||
|
||||
|
||||
if (*argv[0] == '+') {
|
||||
when = time (NULL) + atol(argv[0] + 1);
|
||||
when = time(NULL) + atol(argv[0] + 1);
|
||||
} else {
|
||||
when = atol(argv[0]);
|
||||
}
|
||||
|
||||
|
||||
if (argv[2]) {
|
||||
if (!strcmp(argv[2], "both")) {
|
||||
flags |= (SMF_ECHO_ALEG | SMF_ECHO_BLEG);
|
||||
@@ -207,26 +209,26 @@ static void eval_function(switch_core_session_t *session, char *data)
|
||||
|
||||
static void phrase_function(switch_core_session_t *session, char *data)
|
||||
{
|
||||
switch_channel_t *channel;
|
||||
char *mydata = NULL;
|
||||
switch_channel_t *channel;
|
||||
char *mydata = NULL;
|
||||
|
||||
channel = switch_core_session_get_channel(session);
|
||||
assert(channel != NULL);
|
||||
|
||||
if ((mydata = switch_core_session_strdup(session, data))) {
|
||||
char *lang;
|
||||
char *macro = mydata;
|
||||
char *mdata = NULL;
|
||||
channel = switch_core_session_get_channel(session);
|
||||
assert(channel != NULL);
|
||||
|
||||
if ((mdata = strchr(macro, ','))) {
|
||||
*mdata++ = '\0';
|
||||
}
|
||||
if ((mydata = switch_core_session_strdup(session, data))) {
|
||||
char *lang;
|
||||
char *macro = mydata;
|
||||
char *mdata = NULL;
|
||||
|
||||
lang = switch_channel_get_variable(channel, "language");
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Execute %s(%s) lang %s\n", macro, mdata, lang);
|
||||
switch_ivr_phrase_macro(session, macro, mdata, lang, NULL);
|
||||
}
|
||||
if ((mdata = strchr(macro, ','))) {
|
||||
*mdata++ = '\0';
|
||||
}
|
||||
|
||||
lang = switch_channel_get_variable(channel, "language");
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Execute %s(%s) lang %s\n", macro, mdata, lang);
|
||||
switch_ivr_phrase_macro(session, macro, mdata, lang, NULL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -234,14 +236,14 @@ static void phrase_function(switch_core_session_t *session, char *data)
|
||||
static void hangup_function(switch_core_session_t *session, char *data)
|
||||
{
|
||||
switch_channel_t *channel;
|
||||
switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING;
|
||||
switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING;
|
||||
|
||||
channel = switch_core_session_get_channel(session);
|
||||
assert(channel != NULL);
|
||||
assert(channel != NULL);
|
||||
|
||||
if (!switch_strlen_zero((char *) data)) {
|
||||
cause = switch_channel_str2cause((char *) data);
|
||||
}
|
||||
if (!switch_strlen_zero((char *) data)) {
|
||||
cause = switch_channel_str2cause((char *) data);
|
||||
}
|
||||
|
||||
switch_channel_hangup(channel, cause);
|
||||
}
|
||||
@@ -251,7 +253,7 @@ static void answer_function(switch_core_session_t *session, char *data)
|
||||
switch_channel_t *channel;
|
||||
channel = switch_core_session_get_channel(session);
|
||||
|
||||
assert(channel != NULL);
|
||||
assert(channel != NULL);
|
||||
switch_channel_answer(channel);
|
||||
}
|
||||
|
||||
@@ -260,18 +262,18 @@ static void pre_answer_function(switch_core_session_t *session, char *data)
|
||||
switch_channel_t *channel;
|
||||
channel = switch_core_session_get_channel(session);
|
||||
|
||||
assert(channel != NULL);
|
||||
assert(channel != NULL);
|
||||
switch_channel_pre_answer(channel);
|
||||
}
|
||||
|
||||
static void redirect_function(switch_core_session_t *session, char *data)
|
||||
{
|
||||
switch_core_session_message_t msg = {0};
|
||||
switch_core_session_message_t msg = { 0 };
|
||||
|
||||
/* Tell the channel to redirect */
|
||||
/* Tell the channel to redirect */
|
||||
msg.from = __FILE__;
|
||||
msg.string_arg = data;
|
||||
msg.message_id = SWITCH_MESSAGE_INDICATE_REDIRECT;
|
||||
msg.message_id = SWITCH_MESSAGE_INDICATE_REDIRECT;
|
||||
switch_core_session_receive_message(session, &msg);
|
||||
|
||||
}
|
||||
@@ -283,7 +285,7 @@ static void set_function(switch_core_session_t *session, char *data)
|
||||
char *var, *val = NULL;
|
||||
|
||||
channel = switch_core_session_get_channel(session);
|
||||
assert(channel != NULL);
|
||||
assert(channel != NULL);
|
||||
|
||||
if (switch_strlen_zero(data)) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No variable name specified.\n");
|
||||
@@ -293,11 +295,11 @@ static void set_function(switch_core_session_t *session, char *data)
|
||||
|
||||
if (val) {
|
||||
*val++ = '\0';
|
||||
if (switch_strlen_zero(val)) {
|
||||
val = NULL;
|
||||
}
|
||||
if (switch_strlen_zero(val)) {
|
||||
val = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SET [%s]=[%s]\n", var, val ? val : "UNDEF");
|
||||
switch_channel_set_variable(channel, var, val);
|
||||
}
|
||||
@@ -309,7 +311,7 @@ static void export_function(switch_core_session_t *session, char *data)
|
||||
char *exports, *new_exports = NULL, *new_exports_d = NULL, *var, *val = NULL;
|
||||
|
||||
channel = switch_core_session_get_channel(session);
|
||||
assert(channel != NULL);
|
||||
assert(channel != NULL);
|
||||
|
||||
if (switch_strlen_zero(data)) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No variable name specified.\n");
|
||||
@@ -320,11 +322,11 @@ static void export_function(switch_core_session_t *session, char *data)
|
||||
|
||||
if (val) {
|
||||
*val++ = '\0';
|
||||
if (switch_strlen_zero(val)) {
|
||||
val = NULL;
|
||||
}
|
||||
if (switch_strlen_zero(val)) {
|
||||
val = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "EXPORT [%s]=[%s]\n", var, val ? val : "UNDEF");
|
||||
switch_channel_set_variable(channel, var, val);
|
||||
|
||||
@@ -346,7 +348,7 @@ static void unset_function(switch_core_session_t *session, char *data)
|
||||
switch_channel_t *channel;
|
||||
|
||||
channel = switch_core_session_get_channel(session);
|
||||
assert(channel != NULL);
|
||||
assert(channel != NULL);
|
||||
|
||||
if (switch_strlen_zero(data)) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No variable name specified.\n");
|
||||
@@ -359,43 +361,43 @@ static void unset_function(switch_core_session_t *session, char *data)
|
||||
static void log_function(switch_core_session_t *session, char *data)
|
||||
{
|
||||
switch_channel_t *channel;
|
||||
char *level, *log_str;
|
||||
char *level, *log_str;
|
||||
|
||||
channel = switch_core_session_get_channel(session);
|
||||
assert(channel != NULL);
|
||||
assert(channel != NULL);
|
||||
|
||||
if (data && (level = strdup(data))) {
|
||||
switch_event_types_t etype = SWITCH_LOG_DEBUG;
|
||||
|
||||
if ((log_str = strchr(level, ' '))) {
|
||||
*log_str++ = '\0';
|
||||
switch_name_event(level, &etype);
|
||||
} else {
|
||||
log_str = level;
|
||||
}
|
||||
if (data && (level = strdup(data))) {
|
||||
switch_event_types_t etype = SWITCH_LOG_DEBUG;
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, etype, "%s\n", log_str);
|
||||
switch_safe_free(level);
|
||||
}
|
||||
if ((log_str = strchr(level, ' '))) {
|
||||
*log_str++ = '\0';
|
||||
switch_name_event(level, &etype);
|
||||
} else {
|
||||
log_str = level;
|
||||
}
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, etype, "%s\n", log_str);
|
||||
switch_safe_free(level);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void info_function(switch_core_session_t *session, char *data)
|
||||
{
|
||||
switch_channel_t *channel;
|
||||
switch_event_t *event;
|
||||
char *buf;
|
||||
switch_event_t *event;
|
||||
char *buf;
|
||||
|
||||
channel = switch_core_session_get_channel(session);
|
||||
assert(channel != NULL);
|
||||
assert(channel != NULL);
|
||||
|
||||
if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
|
||||
switch_channel_event_set_data(channel, event);
|
||||
switch_event_serialize(event, &buf);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "CHANNEL_DATA:\n%s\n", buf);
|
||||
switch_event_destroy(&event);
|
||||
}
|
||||
|
||||
if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
|
||||
switch_channel_event_set_data(channel, event);
|
||||
switch_event_serialize(event, &buf);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "CHANNEL_DATA:\n%s\n", buf);
|
||||
switch_event_destroy(&event);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void privacy_function(switch_core_session_t *session, char *data)
|
||||
@@ -405,8 +407,8 @@ static void privacy_function(switch_core_session_t *session, char *data)
|
||||
char *arg;
|
||||
|
||||
channel = switch_core_session_get_channel(session);
|
||||
assert(channel != NULL);
|
||||
|
||||
assert(channel != NULL);
|
||||
|
||||
caller_profile = switch_channel_get_caller_profile(channel);
|
||||
|
||||
if (switch_strlen_zero(data)) {
|
||||
@@ -416,7 +418,7 @@ static void privacy_function(switch_core_session_t *session, char *data)
|
||||
|
||||
switch_set_flag(caller_profile, SWITCH_CPF_SCREEN);
|
||||
|
||||
if(!strcasecmp(arg, "no")) {
|
||||
if (!strcasecmp(arg, "no")) {
|
||||
switch_clear_flag(caller_profile, SWITCH_CPF_HIDE_NAME);
|
||||
switch_clear_flag(caller_profile, SWITCH_CPF_HIDE_NUMBER);
|
||||
} else if (!strcasecmp(arg, "yes")) {
|
||||
@@ -428,7 +430,8 @@ static void privacy_function(switch_core_session_t *session, char *data)
|
||||
} else if (!strcasecmp(arg, "number")) {
|
||||
switch_set_flag(caller_profile, SWITCH_CPF_HIDE_NUMBER);
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "INVALID privacy mode specified. Use a valid mode [no|yes|name|full|number].\n");
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
|
||||
"INVALID privacy mode specified. Use a valid mode [no|yes|name|full|number].\n");
|
||||
}
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Set Privacy to %s [%d]\n", arg, caller_profile->flags);
|
||||
}
|
||||
@@ -440,7 +443,8 @@ static void strftime_function(switch_core_session_t *session, char *data)
|
||||
int argc;
|
||||
char *lbuf;
|
||||
|
||||
if (data && (lbuf = switch_core_session_strdup(session, data)) && (argc = switch_separate_string(lbuf, '=', argv, (sizeof(argv) / sizeof(argv[0])))) > 1) {
|
||||
if (data && (lbuf = switch_core_session_strdup(session, data))
|
||||
&& (argc = switch_separate_string(lbuf, '=', argv, (sizeof(argv) / sizeof(argv[0])))) > 1) {
|
||||
switch_size_t retsize;
|
||||
switch_time_exp_t tm;
|
||||
char date[80] = "";
|
||||
@@ -459,26 +463,26 @@ static void strftime_function(switch_core_session_t *session, char *data)
|
||||
|
||||
static switch_status_t strepoch_api_function(char *data, switch_core_session_t *session, switch_stream_handle_t *stream)
|
||||
{
|
||||
switch_time_t out;
|
||||
|
||||
if (switch_strlen_zero(data)) {
|
||||
out = switch_time_now();
|
||||
} else {
|
||||
out = switch_str_time(data);
|
||||
}
|
||||
switch_time_t out;
|
||||
|
||||
stream->write_function(stream, "%d", (uint32_t)((out) / (int64_t)(1000000)) );
|
||||
if (switch_strlen_zero(data)) {
|
||||
out = switch_time_now();
|
||||
} else {
|
||||
out = switch_str_time(data);
|
||||
}
|
||||
|
||||
stream->write_function(stream, "%d", (uint32_t) ((out) / (int64_t) (1000000)));
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static switch_status_t strftime_api_function(char *fmt, switch_core_session_t *session, switch_stream_handle_t *stream)
|
||||
{
|
||||
|
||||
|
||||
switch_size_t retsize;
|
||||
switch_time_exp_t tm;
|
||||
char date[80] = "";
|
||||
|
||||
|
||||
switch_time_exp_lt(&tm, switch_time_now());
|
||||
switch_strftime(date, &retsize, sizeof(date), fmt ? fmt : "%Y-%m-%d %T", &tm);
|
||||
stream->write_function(stream, "%s", date);
|
||||
@@ -493,14 +497,15 @@ static switch_status_t presence_api_function(char *fmt, switch_core_session_t *s
|
||||
int argc = 0;
|
||||
switch_event_types_t type = SWITCH_EVENT_PRESENCE_IN;
|
||||
|
||||
if (fmt && (lbuf = strdup(fmt)) && (argc = switch_separate_string(lbuf, '|', argv, (sizeof(argv) / sizeof(argv[0])))) > 0) {
|
||||
if (fmt && (lbuf = strdup(fmt))
|
||||
&& (argc = switch_separate_string(lbuf, '|', argv, (sizeof(argv) / sizeof(argv[0])))) > 0) {
|
||||
if (!strcasecmp(argv[0], "out")) {
|
||||
type = SWITCH_EVENT_PRESENCE_OUT;
|
||||
} else if (argc != 4) {
|
||||
stream->write_function(stream, "Invalid");
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
if (switch_event_create(&event, type) == SWITCH_STATUS_SUCCESS) {
|
||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "proto", "dp");
|
||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "login", "%s", __FILE__);
|
||||
@@ -527,9 +532,10 @@ static switch_status_t chat_api_function(char *fmt, switch_core_session_t *sessi
|
||||
char *lbuf, *argv[4];
|
||||
int argc = 0;
|
||||
|
||||
if (fmt && (lbuf = strdup(fmt)) && (argc = switch_separate_string(lbuf, '|', argv, (sizeof(argv) / sizeof(argv[0])))) == 4) {
|
||||
if (fmt && (lbuf = strdup(fmt))
|
||||
&& (argc = switch_separate_string(lbuf, '|', argv, (sizeof(argv) / sizeof(argv[0])))) == 4) {
|
||||
switch_chat_interface_t *ci;
|
||||
|
||||
|
||||
if ((ci = switch_loadable_module_get_chat_interface(argv[0]))) {
|
||||
ci->chat_send("dp", argv[1], argv[2], "", argv[3], "");
|
||||
stream->write_function(stream, "Sent");
|
||||
@@ -539,7 +545,7 @@ static switch_status_t chat_api_function(char *fmt, switch_core_session_t *sessi
|
||||
} else {
|
||||
stream->write_function(stream, "Invalid");
|
||||
}
|
||||
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -551,7 +557,7 @@ static switch_ivr_action_t menu_handler(switch_ivr_menu_t *menu, char *param, ch
|
||||
switch_ivr_action_t action = SWITCH_IVR_ACTION_NOOP;
|
||||
|
||||
if (param != NULL) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "menu_handler '%s'\n",param);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "menu_handler '%s'\n", param);
|
||||
}
|
||||
|
||||
return action;
|
||||
@@ -563,7 +569,7 @@ static void ivr_application_function(switch_core_session_t *session, char *data)
|
||||
switch_channel_t *channel = switch_core_session_get_channel(session);
|
||||
char *params;
|
||||
|
||||
if (channel && data && (params = switch_core_session_strdup(session,data))) {
|
||||
if (channel && data && (params = switch_core_session_strdup(session, data))) {
|
||||
switch_xml_t cxml = NULL, cfg = NULL, xml_menus = NULL, xml_menu = NULL;
|
||||
|
||||
// Open the config from the xml registry
|
||||
@@ -577,16 +583,17 @@ static void ivr_application_function(switch_core_session_t *session, char *data)
|
||||
switch_ivr_menu_t *menu_stack = NULL;
|
||||
|
||||
// build a menu tree and execute it
|
||||
if (switch_ivr_menu_stack_xml_init(&xml_ctx,NULL) == SWITCH_STATUS_SUCCESS
|
||||
if (switch_ivr_menu_stack_xml_init(&xml_ctx, NULL) == SWITCH_STATUS_SUCCESS
|
||||
#ifdef _TEST_CALLBACK_
|
||||
&& switch_ivr_menu_stack_xml_add_custom(xml_ctx, "custom", &menu_handler) == SWITCH_STATUS_SUCCESS
|
||||
&& switch_ivr_menu_stack_xml_add_custom(xml_ctx, "custom",
|
||||
&menu_handler) == SWITCH_STATUS_SUCCESS
|
||||
#endif
|
||||
&& switch_ivr_menu_stack_xml_build(xml_ctx,&menu_stack,xml_menus,xml_menu) == SWITCH_STATUS_SUCCESS)
|
||||
{
|
||||
&& switch_ivr_menu_stack_xml_build(xml_ctx, &menu_stack, xml_menus,
|
||||
xml_menu) == SWITCH_STATUS_SUCCESS) {
|
||||
switch_xml_free(cxml);
|
||||
cxml = NULL;
|
||||
switch_channel_pre_answer(channel);
|
||||
switch_ivr_menu_execute(session,menu_stack,params,NULL);
|
||||
switch_ivr_menu_execute(session, menu_stack, params, NULL);
|
||||
switch_ivr_menu_stack_free(menu_stack);
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to create menu '%s'\n", params);
|
||||
@@ -670,7 +677,7 @@ static switch_application_interface_t sched_hangup_application_interface = {
|
||||
|
||||
static const switch_application_interface_t queuedtmf_application_interface = {
|
||||
/*.interface_name */ "queue_dtmf",
|
||||
/*.application_function */ queue_dtmf_function,
|
||||
/*.application_function */ queue_dtmf_function,
|
||||
/* long_desc */ "Queue dtmf to be sent from a session",
|
||||
/* short_desc */ "Queue dtmf to be sent",
|
||||
/* syntax */ "<dtmf_data>",
|
||||
@@ -680,7 +687,7 @@ static const switch_application_interface_t queuedtmf_application_interface = {
|
||||
|
||||
static const switch_application_interface_t redirect_application_interface = {
|
||||
/*.interface_name */ "redirect",
|
||||
/*.application_function */ redirect_function,
|
||||
/*.application_function */ redirect_function,
|
||||
/* long_desc */ "Send a redirect message to a session.",
|
||||
/* short_desc */ "Send session redirect",
|
||||
/* syntax */ "<redirect_data>",
|
||||
@@ -690,7 +697,7 @@ static const switch_application_interface_t redirect_application_interface = {
|
||||
|
||||
static const switch_application_interface_t ivr_application_interface = {
|
||||
/*.interface_name */ "ivr",
|
||||
/*.application_function */ ivr_application_function,
|
||||
/*.application_function */ ivr_application_function,
|
||||
/* long_desc */ "Run an ivr menu.",
|
||||
/* short_desc */ "Run an ivr menu",
|
||||
/* syntax */ "<menu_name>",
|
||||
@@ -700,7 +707,7 @@ static const switch_application_interface_t ivr_application_interface = {
|
||||
|
||||
static const switch_application_interface_t detect_speech_application_interface = {
|
||||
/*.interface_name */ "detect_speech",
|
||||
/*.application_function */ detect_speech_function,
|
||||
/*.application_function */ detect_speech_function,
|
||||
/* long_desc */ "Detect speech on a channel.",
|
||||
/* short_desc */ "Detect speech",
|
||||
/* syntax */ "<mod_name> <gram_name> <gram_path> [<addr>] OR grammar <gram_name> [<path>] OR pause OR resume",
|
||||
@@ -777,7 +784,6 @@ static const switch_application_interface_t hangup_application_interface = {
|
||||
/* syntax */ "[<cause>]",
|
||||
/* flags */ SAF_SUPPORT_NOMEDIA,
|
||||
/*.next */ &log_application_interface
|
||||
|
||||
};
|
||||
|
||||
static const switch_application_interface_t answer_application_interface = {
|
||||
@@ -788,7 +794,6 @@ static const switch_application_interface_t answer_application_interface = {
|
||||
/* syntax */ "",
|
||||
/* flags */ SAF_SUPPORT_NOMEDIA,
|
||||
/*.next */ &hangup_application_interface
|
||||
|
||||
};
|
||||
|
||||
static const switch_application_interface_t pre_answer_application_interface = {
|
||||
@@ -799,7 +804,6 @@ static const switch_application_interface_t pre_answer_application_interface = {
|
||||
/* syntax */ "",
|
||||
/* flags */ SAF_SUPPORT_NOMEDIA,
|
||||
/*.next */ &answer_application_interface
|
||||
|
||||
};
|
||||
|
||||
static const switch_application_interface_t eval_application_interface = {
|
||||
@@ -810,7 +814,6 @@ static const switch_application_interface_t eval_application_interface = {
|
||||
/* syntax */ "",
|
||||
/* flags */ SAF_SUPPORT_NOMEDIA,
|
||||
/*.next */ &pre_answer_application_interface
|
||||
|
||||
};
|
||||
|
||||
static const switch_application_interface_t phrase_application_interface = {
|
||||
@@ -821,7 +824,6 @@ static const switch_application_interface_t phrase_application_interface = {
|
||||
/* syntax */ "<macro_name>,<data>",
|
||||
/* flags */ SAF_NONE,
|
||||
/*.next */ &eval_application_interface
|
||||
|
||||
};
|
||||
|
||||
static const switch_application_interface_t strftime_application_interface = {
|
||||
@@ -832,13 +834,13 @@ static const switch_application_interface_t strftime_application_interface = {
|
||||
/* syntax */ NULL,
|
||||
/* flags */ SAF_SUPPORT_NOMEDIA,
|
||||
/*.next */ &phrase_application_interface
|
||||
|
||||
};
|
||||
|
||||
static const switch_application_interface_t sleep_application_interface = {
|
||||
/*.interface_name */ "sleep",
|
||||
/*.application_function */ sleep_function,
|
||||
/* long_desc */ "Pause the channel for a given number of milliseconds, consuming the audio for that period of time.",
|
||||
/* long_desc */
|
||||
"Pause the channel for a given number of milliseconds, consuming the audio for that period of time.",
|
||||
/* short_desc */ "Pause a channel",
|
||||
/* syntax */ "<pausemilliseconds>",
|
||||
/* flags */ SAF_NONE,
|
||||
@@ -875,7 +877,8 @@ static const switch_loadable_module_interface_t mod_dptools_module_interface = {
|
||||
/*.api_interface */ &presence_api_interface
|
||||
};
|
||||
|
||||
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
|
||||
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
|
||||
char *filename)
|
||||
{
|
||||
|
||||
/* connect my internal structure to the blank pointer passed to me */
|
||||
|
||||
@@ -38,7 +38,7 @@ static void echo_function(switch_core_session_t *session, char *data)
|
||||
switch_channel_t *channel;
|
||||
|
||||
channel = switch_core_session_get_channel(session);
|
||||
assert(channel != NULL);
|
||||
assert(channel != NULL);
|
||||
|
||||
switch_channel_answer(channel);
|
||||
|
||||
@@ -67,7 +67,8 @@ static switch_loadable_module_interface_t echo_module_interface = {
|
||||
/*.directory_interface */ NULL
|
||||
};
|
||||
|
||||
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
|
||||
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
|
||||
char *filename)
|
||||
{
|
||||
/* connect my internal structure to the blank pointer passed to me */
|
||||
*module_interface = &echo_module_interface;
|
||||
|
||||
@@ -48,10 +48,10 @@ struct enum_record {
|
||||
typedef struct enum_record enum_record_t;
|
||||
|
||||
struct query {
|
||||
const char *name; /* original query string */
|
||||
const char *name; /* original query string */
|
||||
char *number;
|
||||
unsigned char dn[DNS_MAXDN];
|
||||
enum dns_type qtyp; /* type of the query */
|
||||
enum dns_type qtyp; /* type of the query */
|
||||
enum_record_t *results;
|
||||
};
|
||||
typedef struct query enum_query_t;
|
||||
@@ -77,7 +77,7 @@ static struct {
|
||||
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_root, globals.root)
|
||||
|
||||
|
||||
static void add_route(char *service, char *regex, char *replace)
|
||||
static void add_route(char *service, char *regex, char *replace)
|
||||
{
|
||||
enum_route_t *route, *rp;
|
||||
|
||||
@@ -86,11 +86,11 @@ static void add_route(char *service, char *regex, char *replace)
|
||||
}
|
||||
|
||||
memset(route, 0, sizeof(*route));
|
||||
|
||||
|
||||
route->service = strdup(service);
|
||||
route->regex = strdup(regex);
|
||||
route->replace = strdup(replace);
|
||||
|
||||
|
||||
if (!globals.route_order) {
|
||||
globals.route_order = route;
|
||||
} else {
|
||||
@@ -107,8 +107,8 @@ static void add_route(char *service, char *regex, char *replace)
|
||||
static switch_status_t load_config(void)
|
||||
{
|
||||
char *cf = "enum.conf";
|
||||
switch_xml_t cfg, xml = NULL, param, settings, route, routes;
|
||||
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
||||
switch_xml_t cfg, xml = NULL, param, settings, route, routes;
|
||||
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
||||
|
||||
memset(&globals, 0, sizeof(globals));
|
||||
if (switch_core_new_memory_pool(&globals.pool) != SWITCH_STATUS_SUCCESS) {
|
||||
@@ -119,39 +119,39 @@ static switch_status_t load_config(void)
|
||||
|
||||
switch_core_hash_init(&globals.routes, globals.pool);
|
||||
|
||||
if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
|
||||
status = SWITCH_STATUS_FALSE;
|
||||
goto done;
|
||||
}
|
||||
if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
|
||||
status = SWITCH_STATUS_FALSE;
|
||||
goto done;
|
||||
}
|
||||
|
||||
if ((settings = switch_xml_child(cfg, "settings"))) {
|
||||
for (param = switch_xml_child(settings, "param"); param; param = param->next) {
|
||||
char *var = (char *) switch_xml_attr_soft(param, "name");
|
||||
char *val = (char *) switch_xml_attr_soft(param, "value");
|
||||
if (!strcasecmp(var, "default-root")) {
|
||||
if ((settings = switch_xml_child(cfg, "settings"))) {
|
||||
for (param = switch_xml_child(settings, "param"); param; param = param->next) {
|
||||
char *var = (char *) switch_xml_attr_soft(param, "name");
|
||||
char *val = (char *) switch_xml_attr_soft(param, "value");
|
||||
if (!strcasecmp(var, "default-root")) {
|
||||
set_global_root(val);
|
||||
} else if (!strcasecmp(var, "log-level-trace")) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (!strcasecmp(var, "log-level-trace")) {
|
||||
|
||||
if ((routes = switch_xml_child(cfg, "routes"))) {
|
||||
for (route = switch_xml_child(routes, "route"); route; route = route->next) {
|
||||
char *service = (char *) switch_xml_attr_soft(route, "service");
|
||||
char *regex = (char *) switch_xml_attr_soft(route, "regex");
|
||||
char *replace = (char *) switch_xml_attr_soft(route, "replace");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((routes = switch_xml_child(cfg, "routes"))) {
|
||||
for (route = switch_xml_child(routes, "route"); route; route = route->next) {
|
||||
char *service = (char *) switch_xml_attr_soft(route, "service");
|
||||
char *regex = (char *) switch_xml_attr_soft(route, "regex");
|
||||
char *replace = (char *) switch_xml_attr_soft(route, "replace");
|
||||
|
||||
if (service && regex && replace) {
|
||||
add_route(service, regex, replace);
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Route!\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
|
||||
if (xml) {
|
||||
switch_xml_free(xml);
|
||||
@@ -168,20 +168,20 @@ static switch_status_t load_config(void)
|
||||
|
||||
static char *reverse_number(char *in, char *root)
|
||||
{
|
||||
switch_size_t len;
|
||||
char *out = NULL;
|
||||
char *y,*z;
|
||||
switch_size_t len;
|
||||
char *out = NULL;
|
||||
char *y, *z;
|
||||
|
||||
if (!(in && root)) {
|
||||
return NULL;
|
||||
}
|
||||
if (!(in && root)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
len = (strlen(in) * 2) + strlen(root) + 1;
|
||||
if ((out = malloc(len))) {
|
||||
memset(out, 0, len);
|
||||
len = (strlen(in) * 2) + strlen(root) + 1;
|
||||
if ((out = malloc(len))) {
|
||||
memset(out, 0, len);
|
||||
|
||||
z = out;
|
||||
for(y = in + (strlen(in) - 1); y; y--) {
|
||||
z = out;
|
||||
for (y = in + (strlen(in) - 1); y; y--) {
|
||||
if (*y > 47 && *y < 58) {
|
||||
*z++ = *y;
|
||||
*z++ = '.';
|
||||
@@ -189,21 +189,22 @@ static char *reverse_number(char *in, char *root)
|
||||
if (y == in) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
strcat(z, root);
|
||||
}
|
||||
}
|
||||
strcat(z, 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",
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
static void add_result(enum_query_t *q, int order, int preference, char *service, char *route)
|
||||
static void add_result(enum_query_t * q, int order, int preference, char *service, char *route)
|
||||
{
|
||||
enum_record_t *new_result, *rp, *prev = NULL;
|
||||
|
||||
@@ -213,12 +214,12 @@ static void add_result(enum_query_t *q, int order, int preference, char *service
|
||||
}
|
||||
|
||||
memset(new_result, 0, sizeof(*new_result));
|
||||
|
||||
|
||||
new_result->order = order;
|
||||
new_result->preference = preference;
|
||||
new_result->service = strdup(service);
|
||||
new_result->route = strdup(route);
|
||||
|
||||
|
||||
|
||||
if (!q->results) {
|
||||
q->results = new_result;
|
||||
@@ -227,12 +228,12 @@ static void add_result(enum_query_t *q, int order, int preference, char *service
|
||||
|
||||
rp = q->results;
|
||||
|
||||
while(rp && strcmp(rp->service, new_result->service)) {
|
||||
while (rp && strcmp(rp->service, new_result->service)) {
|
||||
prev = rp;
|
||||
rp = rp->next;
|
||||
}
|
||||
|
||||
while(rp && !strcmp(rp->service, new_result->service) && new_result->order > rp->order) {
|
||||
while (rp && !strcmp(rp->service, new_result->service) && new_result->order > rp->order) {
|
||||
prev = rp;
|
||||
rp = rp->next;
|
||||
}
|
||||
@@ -241,7 +242,7 @@ static void add_result(enum_query_t *q, int order, int preference, char *service
|
||||
prev = rp;
|
||||
rp = rp->next;
|
||||
}
|
||||
|
||||
|
||||
if (prev) {
|
||||
new_result->next = rp;
|
||||
prev->next = new_result;
|
||||
@@ -252,11 +253,11 @@ static void add_result(enum_query_t *q, int order, int preference, char *service
|
||||
}
|
||||
|
||||
|
||||
static void free_results(enum_record_t **results)
|
||||
static void free_results(enum_record_t ** results)
|
||||
{
|
||||
enum_record_t *fp, *rp;
|
||||
|
||||
for(rp = *results; rp;) {
|
||||
for (rp = *results; rp;) {
|
||||
fp = rp;
|
||||
rp = rp->next;
|
||||
switch_safe_free(fp->service);
|
||||
@@ -266,7 +267,8 @@ 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;
|
||||
const unsigned char *dptr = rr->dnsrr_dptr;
|
||||
@@ -282,25 +284,26 @@ static void parse_rr(const struct dns_parse *p, enum_query_t *q, struct dns_rr *
|
||||
char *regex = NULL;
|
||||
char *replace = NULL;
|
||||
int argc = 0;
|
||||
char *argv[4] = {0};
|
||||
char *argv[4] = { 0 };
|
||||
int leap;
|
||||
|
||||
switch(rr->dnsrr_typ) {
|
||||
switch (rr->dnsrr_typ) {
|
||||
|
||||
case DNS_T_NAPTR: /* prio weight port targetDN */
|
||||
case DNS_T_NAPTR: /* prio weight port targetDN */
|
||||
c = dptr;
|
||||
c += 2 + 2 + 2;
|
||||
if (dns_getdn(pkt, &c, end, dn, DNS_MAXDN) <= 0 || c != dend) goto xperr;
|
||||
if (dns_getdn(pkt, &c, end, dn, DNS_MAXDN) <= 0 || c != dend)
|
||||
goto xperr;
|
||||
c = dptr;
|
||||
|
||||
|
||||
leap = *dn;
|
||||
nme = (char *)dn+1;
|
||||
nme = (char *) dn + 1;
|
||||
|
||||
order = dns_get16(c+0);
|
||||
preference = dns_get16(c+2);
|
||||
flags = (char) dns_get16(c+4);
|
||||
order = dns_get16(c + 0);
|
||||
preference = dns_get16(c + 2);
|
||||
flags = (char) dns_get16(c + 4);
|
||||
|
||||
if ((ptr = nme+leap)) {
|
||||
if ((ptr = nme + leap)) {
|
||||
service = nme;
|
||||
*ptr++ = '\0';
|
||||
argc = switch_separate_string(ptr, '!', argv, (sizeof(argv) / sizeof(argv[0])));
|
||||
@@ -308,7 +311,7 @@ static void parse_rr(const struct dns_parse *p, enum_query_t *q, struct dns_rr *
|
||||
replace = argv[2];
|
||||
}
|
||||
|
||||
for(ptr = replace; ptr && *ptr; ptr++) {
|
||||
for (ptr = replace; ptr && *ptr; ptr++) {
|
||||
if (*ptr == '\\') {
|
||||
*ptr = '$';
|
||||
}
|
||||
@@ -326,15 +329,17 @@ static void parse_rr(const struct dns_parse *p, enum_query_t *q, struct dns_rr *
|
||||
|
||||
if ((proceed = switch_regex_perform(q->number, regex, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
|
||||
if (strchr(regex, '(')) {
|
||||
switch_perform_substitution(re, proceed, replace, q->number, substituted, sizeof(substituted), ovector);
|
||||
switch_perform_substitution(re, proceed, replace, q->number, substituted, sizeof(substituted),
|
||||
ovector);
|
||||
uri = substituted;
|
||||
} else {
|
||||
uri = replace;
|
||||
}
|
||||
|
||||
if ((route = (enum_route_t *) switch_core_hash_find(globals.routes, service))){
|
||||
if ((route = (enum_route_t *) switch_core_hash_find(globals.routes, service))) {
|
||||
switch_regex_safe_free(re);
|
||||
if ((proceed = switch_regex_perform(uri, route->regex, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
|
||||
if ((proceed =
|
||||
switch_regex_perform(uri, route->regex, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
|
||||
if (strchr(route->regex, '(')) {
|
||||
switch_perform_substitution(re, proceed, route->replace, uri, rbuf, sizeof(rbuf), ovector);
|
||||
uri = rbuf;
|
||||
@@ -343,7 +348,7 @@ static void parse_rr(const struct dns_parse *p, enum_query_t *q, struct dns_rr *
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
add_result(q, order, preference, service, uri);
|
||||
}
|
||||
|
||||
@@ -358,12 +363,13 @@ static void parse_rr(const struct dns_parse *p, enum_query_t *q, struct dns_rr *
|
||||
|
||||
return;
|
||||
|
||||
xperr:
|
||||
xperr:
|
||||
//printf("<parse error>\n");
|
||||
return;
|
||||
}
|
||||
|
||||
static void dnscb(struct dns_ctx *ctx, void *result, void *data) {
|
||||
static void dnscb(struct dns_ctx *ctx, void *result, void *data)
|
||||
{
|
||||
int r = dns_status(ctx);
|
||||
enum_query_t *q = data;
|
||||
struct dns_parse p;
|
||||
@@ -375,25 +381,25 @@ static void dnscb(struct dns_ctx *ctx, void *result, void *data) {
|
||||
dnserror(q, r);
|
||||
return;
|
||||
}
|
||||
pkt = result; end = pkt + r; cur = dns_payload(pkt);
|
||||
pkt = result;
|
||||
end = pkt + r;
|
||||
cur = dns_payload(pkt);
|
||||
dns_getdn(pkt, &cur, end, dn, sizeof(dn));
|
||||
dns_initparse(&p, NULL, pkt, cur, end);
|
||||
p.dnsp_qcls = p.dnsp_qtyp = 0;
|
||||
qdn = dn;
|
||||
nrr = 0;
|
||||
while((r = dns_nextrr(&p, &rr)) > 0) {
|
||||
if (!dns_dnequal(qdn, rr.dnsrr_dn)) continue;
|
||||
if ((qcls == DNS_C_ANY || qcls == rr.dnsrr_cls) &&
|
||||
(q->qtyp == DNS_T_ANY || q->qtyp == rr.dnsrr_typ))
|
||||
while ((r = dns_nextrr(&p, &rr)) > 0) {
|
||||
if (!dns_dnequal(qdn, rr.dnsrr_dn))
|
||||
continue;
|
||||
if ((qcls == DNS_C_ANY || qcls == rr.dnsrr_cls) && (q->qtyp == DNS_T_ANY || q->qtyp == rr.dnsrr_typ))
|
||||
++nrr;
|
||||
else if (rr.dnsrr_typ == DNS_T_CNAME && !nrr) {
|
||||
if (dns_getdn(pkt, &rr.dnsrr_dptr, end,
|
||||
p.dnsp_dnbuf, sizeof(p.dnsp_dnbuf)) <= 0 ||
|
||||
rr.dnsrr_dptr != rr.dnsrr_dend) {
|
||||
p.dnsp_dnbuf, sizeof(p.dnsp_dnbuf)) <= 0 || rr.dnsrr_dptr != rr.dnsrr_dend) {
|
||||
r = DNS_E_PROTOCOL;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
qdn = p.dnsp_dnbuf;
|
||||
}
|
||||
}
|
||||
@@ -409,28 +415,28 @@ static void dnscb(struct dns_ctx *ctx, void *result, void *data) {
|
||||
dns_rewind(&p, NULL);
|
||||
p.dnsp_qtyp = q->qtyp;
|
||||
p.dnsp_qcls = qcls;
|
||||
while(dns_nextrr(&p, &rr)) {
|
||||
while (dns_nextrr(&p, &rr)) {
|
||||
parse_rr(&p, q, &rr);
|
||||
}
|
||||
|
||||
|
||||
free(result);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
switch_status_t sstatus = SWITCH_STATUS_SUCCESS;
|
||||
char *name = NULL;
|
||||
enum_query_t query = {0};
|
||||
enum_query_t query = { 0 };
|
||||
enum dns_type l_qtyp = DNS_T_NAPTR;
|
||||
int i = 0, abs = 0;
|
||||
dns_socket fd = (dns_socket)-1;
|
||||
dns_socket fd = (dns_socket) - 1;
|
||||
fd_set fds;
|
||||
struct timeval tv = {0};
|
||||
struct timeval tv = { 0 };
|
||||
time_t now = 0;
|
||||
struct dns_ctx *nctx = NULL;
|
||||
char *num, *mnum = NULL;
|
||||
|
||||
|
||||
if (*in != '+') {
|
||||
mnum = switch_mprintf("+%s", in);
|
||||
num = mnum;
|
||||
@@ -458,7 +464,7 @@ static switch_status_t enum_lookup(char *root, char *in, enum_record_t **results
|
||||
goto done;
|
||||
}
|
||||
|
||||
dns_ptodn(name, (unsigned int)strlen(name), query.dn, sizeof(query.dn), &abs);
|
||||
dns_ptodn(name, (unsigned int) strlen(name), query.dn, sizeof(query.dn), &abs);
|
||||
query.name = name;
|
||||
query.number = num;
|
||||
query.qtyp = l_qtyp;
|
||||
@@ -466,7 +472,7 @@ static switch_status_t enum_lookup(char *root, char *in, enum_record_t **results
|
||||
if (abs) {
|
||||
abs = DNS_NOSRCH;
|
||||
}
|
||||
|
||||
|
||||
if (!dns_submit_dn(nctx, query.dn, qcls, l_qtyp, abs, 0, dnscb, &query)) {
|
||||
dnserror(&query, dns_status(nctx));
|
||||
}
|
||||
@@ -474,7 +480,7 @@ static switch_status_t enum_lookup(char *root, char *in, enum_record_t **results
|
||||
FD_ZERO(&fds);
|
||||
now = 0;
|
||||
|
||||
while((i = dns_timeouts(nctx, -1, now)) > 0) {
|
||||
while ((i = dns_timeouts(nctx, -1, now)) > 0) {
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 4389 4127)
|
||||
@@ -485,9 +491,10 @@ static switch_status_t enum_lookup(char *root, char *in, enum_record_t **results
|
||||
#endif
|
||||
tv.tv_sec = i;
|
||||
tv.tv_usec = 0;
|
||||
i = select((int)(fd+1), &fds, 0, 0, &tv);
|
||||
i = select((int) (fd + 1), &fds, 0, 0, &tv);
|
||||
now = time(NULL);
|
||||
if (i > 0) dns_ioevent(nctx, now);
|
||||
if (i > 0)
|
||||
dns_ioevent(nctx, now);
|
||||
}
|
||||
|
||||
if (!query.results) {
|
||||
@@ -497,17 +504,17 @@ static switch_status_t enum_lookup(char *root, char *in, enum_record_t **results
|
||||
*results = query.results;
|
||||
query.results = NULL;
|
||||
|
||||
done:
|
||||
done:
|
||||
|
||||
if (fd > -1) {
|
||||
closesocket(fd);
|
||||
fd = (dns_socket)-1;
|
||||
fd = (dns_socket) - 1;
|
||||
}
|
||||
|
||||
if (nctx) {
|
||||
dns_free(nctx);
|
||||
}
|
||||
|
||||
|
||||
switch_safe_free(name);
|
||||
switch_safe_free(mnum);
|
||||
|
||||
@@ -524,34 +531,37 @@ static switch_caller_extension_t *enum_dialplan_hunt(switch_core_session_t *sess
|
||||
enum_route_t *rtp;
|
||||
char *dp = (char *) arg;
|
||||
|
||||
assert(channel != NULL);
|
||||
assert(channel != NULL);
|
||||
|
||||
caller_profile = switch_channel_get_caller_profile(channel);
|
||||
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "ENUM Lookup on %s\n", caller_profile->destination_number);
|
||||
|
||||
if (enum_lookup(switch_strlen_zero(dp) ? globals.root : dp, caller_profile->destination_number, &results) == SWITCH_STATUS_SUCCESS) {
|
||||
if ((extension = switch_caller_extension_new(session, caller_profile->destination_number, caller_profile->destination_number)) == 0) {
|
||||
if (enum_lookup(switch_strlen_zero(dp) ? globals.root : dp, caller_profile->destination_number, &results) ==
|
||||
SWITCH_STATUS_SUCCESS) {
|
||||
if ((extension =
|
||||
switch_caller_extension_new(session, caller_profile->destination_number,
|
||||
caller_profile->destination_number)) == 0) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "memory error!\n");
|
||||
free_results(&results);
|
||||
free_results(&results);
|
||||
return NULL;
|
||||
}
|
||||
switch_channel_set_variable(channel, SWITCH_HANGUP_AFTER_BRIDGE_VARIABLE, "true");
|
||||
|
||||
for(rtp = globals.route_order; rtp; rtp = rtp->next) {
|
||||
for(rp = results; rp; rp = rp->next) {
|
||||
|
||||
for (rtp = globals.route_order; rtp; rtp = rtp->next) {
|
||||
for (rp = results; rp; rp = rp->next) {
|
||||
if (!strcmp(rtp->service, rp->service)) {
|
||||
switch_caller_extension_add_application(session, extension, "bridge", rp->route);
|
||||
switch_caller_extension_add_application(session, extension, "bridge", rp->route);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free_results(&results);
|
||||
free_results(&results);
|
||||
}
|
||||
|
||||
if (extension) {
|
||||
switch_channel_set_state(channel, CS_EXECUTE);
|
||||
}
|
||||
switch_channel_set_state(channel, CS_EXECUTE);
|
||||
}
|
||||
|
||||
return extension;
|
||||
|
||||
@@ -560,7 +570,7 @@ static switch_caller_extension_t *enum_dialplan_hunt(switch_core_session_t *sess
|
||||
static void enum_app_function(switch_core_session_t *session, char *data)
|
||||
{
|
||||
int argc = 0;
|
||||
char *argv[4] = {0};
|
||||
char *argv[4] = { 0 };
|
||||
char *mydata = NULL;
|
||||
char *dest = NULL, *root = NULL;
|
||||
enum_record_t *results, *rp;
|
||||
@@ -575,26 +585,27 @@ static void enum_app_function(switch_core_session_t *session, char *data)
|
||||
assert(channel != NULL);
|
||||
|
||||
if (!(mydata = switch_core_session_strdup(session, data))) {
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
|
||||
if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
|
||||
dest = argv[0];
|
||||
root = argv[1] ? argv[1] : globals.root;
|
||||
root = argv[1] ? argv[1] : globals.root;
|
||||
if (enum_lookup(root, data, &results) == SWITCH_STATUS_SUCCESS) {
|
||||
switch_hash_index_t *hi;
|
||||
void *vval;
|
||||
const void *vvar;
|
||||
|
||||
for (hi = switch_channel_variable_first(channel, switch_core_session_get_pool(session)); hi; hi = switch_hash_next(hi)) {
|
||||
for (hi = switch_channel_variable_first(channel, switch_core_session_get_pool(session)); hi;
|
||||
hi = switch_hash_next(hi)) {
|
||||
switch_hash_this(hi, &vvar, NULL, &vval);
|
||||
if (vvar && !strncmp(vvar, "enum_", 5)) {
|
||||
switch_channel_set_variable(channel, (char *) vvar, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
for(rtp = globals.route_order; rtp; rtp = rtp->next) {
|
||||
for(rp = results; rp; rp = rp->next) {
|
||||
for (rtp = globals.route_order; rtp; rtp = rtp->next) {
|
||||
for (rp = results; rp; rp = rp->next) {
|
||||
if (!strcmp(rtp->service, rp->service)) {
|
||||
snprintf(vbuf, sizeof(vbuf), "enum_route_%d", cnt++);
|
||||
switch_channel_set_variable(channel, vbuf, rp->route);
|
||||
@@ -608,19 +619,19 @@ static void enum_app_function(switch_core_session_t *session, char *data)
|
||||
}
|
||||
snprintf(vbuf, sizeof(vbuf), "%d", cnt);
|
||||
switch_channel_set_variable(channel, "enum_route_count", vbuf);
|
||||
*(rbuf+strlen(rbuf)-1) = '\0';
|
||||
*(rbuf + strlen(rbuf) - 1) = '\0';
|
||||
switch_channel_set_variable(channel, "enum_auto_route", rbuf);
|
||||
free_results(&results);
|
||||
free_results(&results);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
static switch_status_t enum_function(char *data, switch_core_session_t *session, switch_stream_handle_t *stream)
|
||||
{
|
||||
|
||||
int argc = 0;
|
||||
char *argv[4] = {0};
|
||||
char *argv[4] = { 0 };
|
||||
enum_record_t *results, *rp;
|
||||
char *mydata = NULL;
|
||||
char *dest = NULL, *root = NULL;
|
||||
@@ -639,35 +650,36 @@ static switch_status_t enum_function(char *data, switch_core_session_t *session,
|
||||
if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
|
||||
dest = argv[0];
|
||||
root = argv[1] ? argv[1] : globals.root;
|
||||
|
||||
|
||||
if (!enum_lookup(root, data, &results) == SWITCH_STATUS_SUCCESS) {
|
||||
stream->write_function(stream, "No Match!\n");
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
stream->write_function(stream,
|
||||
"\nOffered Routes:\n"
|
||||
"Order\tPref\tService \tRoute\n"
|
||||
"==============================================================================\n");
|
||||
|
||||
for(rp = results; rp; rp = rp->next) {
|
||||
for (rp = results; rp; rp = rp->next) {
|
||||
stream->write_function(stream, "%d\t%d\t%-10s\t%s\n", rp->order, rp->preference, rp->service, rp->route);
|
||||
}
|
||||
|
||||
|
||||
|
||||
stream->write_function(stream,
|
||||
"\nSupported Routes:\n"
|
||||
"Order\tPref\tService \tRoute\n"
|
||||
"==============================================================================\n");
|
||||
|
||||
for(rtp = globals.route_order; rtp; rtp = rtp->next) {
|
||||
for(rp = results; rp; rp = rp->next) {
|
||||
for (rtp = globals.route_order; rtp; rtp = rtp->next) {
|
||||
for (rp = results; rp; rp = rp->next) {
|
||||
if (!strcmp(rtp->service, rp->service)) {
|
||||
stream->write_function(stream, "%d\t%d\t%-10s\t%s\n", rp->order, rp->preference, rp->service, rp->route);
|
||||
stream->write_function(stream, "%d\t%d\t%-10s\t%s\n", rp->order, rp->preference, rp->service,
|
||||
rp->route);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
free_results(&results);
|
||||
} else {
|
||||
stream->write_function(stream, "Invalid Input!\n");
|
||||
@@ -678,14 +690,14 @@ static switch_status_t enum_function(char *data, switch_core_session_t *session,
|
||||
|
||||
|
||||
static const switch_dialplan_interface_t enum_dialplan_interface = {
|
||||
/*.interface_name = */ "enum",
|
||||
/*.hunt_function = */ enum_dialplan_hunt
|
||||
/*.next = NULL */
|
||||
/*.interface_name = */ "enum",
|
||||
/*.hunt_function = */ enum_dialplan_hunt
|
||||
/*.next = NULL */
|
||||
};
|
||||
|
||||
static const switch_application_interface_t enum_application_interface = {
|
||||
/*.interface_name */ "enum",
|
||||
/*.application_function */ enum_app_function,
|
||||
/*.application_function */ enum_app_function,
|
||||
/* long_desc */ "Perform an ENUM lookup",
|
||||
/* short_desc */ "Perform an ENUM lookup",
|
||||
/* syntax */ "<number> [<root>]",
|
||||
@@ -714,7 +726,8 @@ static switch_loadable_module_interface_t enum_module_interface = {
|
||||
/*.directory_interface */ NULL
|
||||
};
|
||||
|
||||
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
|
||||
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
|
||||
char *filename)
|
||||
{
|
||||
|
||||
if (dns_init(0) < 0) {
|
||||
@@ -729,5 +742,3 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod
|
||||
/* indicate that the module should continue to be loaded */
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,16 +39,17 @@ static const char modname[] = "mod_ivrtest";
|
||||
dtmf handler function you can hook up to be executed when a digit is dialed during playback
|
||||
if you return anything but SWITCH_STATUS_SUCCESS the playback will stop.
|
||||
*/
|
||||
static switch_status_t on_dtmf(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf, unsigned int buflen)
|
||||
static switch_status_t on_dtmf(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf,
|
||||
unsigned int buflen)
|
||||
{
|
||||
switch (itype) {
|
||||
case SWITCH_INPUT_TYPE_DTMF: {
|
||||
char *dtmf = (char *) input;
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Digits %s\n", dtmf);
|
||||
|
||||
switch_copy_string((char *)buf, dtmf, buflen);
|
||||
return SWITCH_STATUS_BREAK;
|
||||
}
|
||||
case SWITCH_INPUT_TYPE_DTMF:{
|
||||
char *dtmf = (char *) input;
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Digits %s\n", dtmf);
|
||||
|
||||
switch_copy_string((char *) buf, dtmf, buflen);
|
||||
return SWITCH_STATUS_BREAK;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -72,7 +73,7 @@ static void xml_function(switch_core_session_t *session, char *data)
|
||||
for (team = switch_xml_child(f1, "team"); team; team = team->next) {
|
||||
teamname = switch_xml_attr_soft(team, "name");
|
||||
for (driver = switch_xml_child(team, "driver"); driver; driver = driver->next) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
|
||||
"%s, %s: %s\n", switch_xml_child(driver, "name")->txt, teamname,
|
||||
switch_xml_child(driver, "points")->txt);
|
||||
}
|
||||
@@ -84,7 +85,7 @@ static void xml_function(switch_core_session_t *session, char *data)
|
||||
static void ivr_application_function(switch_core_session_t *session, char *data)
|
||||
{
|
||||
switch_channel_t *channel = switch_core_session_get_channel(session);
|
||||
char *params = switch_core_session_strdup(session,data);
|
||||
char *params = switch_core_session_strdup(session, data);
|
||||
|
||||
if (channel != NULL && params != NULL) {
|
||||
switch_ivr_menu_t *menu = NULL, *sub_menu = NULL;
|
||||
@@ -98,12 +99,7 @@ static void ivr_application_function(switch_core_session_t *session, char *data)
|
||||
"main",
|
||||
"please enter some numbers so i can figure out if I have any bugs or not",
|
||||
"enter some numbers",
|
||||
NULL,
|
||||
"I have no idea what that is",
|
||||
"cepstral",
|
||||
"david",
|
||||
NULL,
|
||||
15000, 10, NULL);
|
||||
NULL, "I have no idea what that is", "cepstral", "david", NULL, 15000, 10, NULL);
|
||||
|
||||
|
||||
status = switch_ivr_menu_init(&sub_menu,
|
||||
@@ -111,12 +107,7 @@ static void ivr_application_function(switch_core_session_t *session, char *data)
|
||||
"sub",
|
||||
"/ram/congrats.wav",
|
||||
"/ram/extension.wav",
|
||||
NULL,
|
||||
"/ram/invalid.wav",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
15000, 10, NULL);
|
||||
NULL, "/ram/invalid.wav", NULL, NULL, NULL, 15000, 10, NULL);
|
||||
|
||||
if (status == SWITCH_STATUS_SUCCESS) {
|
||||
// build the menu
|
||||
@@ -125,10 +116,10 @@ static void ivr_application_function(switch_core_session_t *session, char *data)
|
||||
switch_ivr_menu_bind_action(menu, SWITCH_IVR_ACTION_EXECMENU, "sub", "3");
|
||||
//switch_ivr_menu_bind_action(menu, SWITCH_IVR_ACTION_PLAYSOUND, "/usr/local/freeswitch/sounds/3.wav", "3");
|
||||
|
||||
|
||||
|
||||
switch_ivr_menu_bind_action(sub_menu, SWITCH_IVR_ACTION_PLAYSOUND, "/ram/swimp.raw", "1");
|
||||
switch_ivr_menu_bind_action(sub_menu, SWITCH_IVR_ACTION_BACK, NULL, "2");
|
||||
|
||||
|
||||
|
||||
// start the menu
|
||||
status = switch_ivr_menu_execute(session, menu, "main", NULL);
|
||||
@@ -136,11 +127,11 @@ static void ivr_application_function(switch_core_session_t *session, char *data)
|
||||
// cleaup the menu
|
||||
switch_ivr_menu_stack_free(menu);
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "unable to build menu %s\n",params);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "unable to build menu %s\n", params);
|
||||
}
|
||||
|
||||
|
||||
switch_ivr_play_file(session, NULL,"/ram/goodbye.wav",NULL);
|
||||
|
||||
switch_ivr_play_file(session, NULL, "/ram/goodbye.wav", NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,15 +142,13 @@ static void dirtest_function(switch_core_session_t *session, char *data)
|
||||
switch_directory_handle_t dh;
|
||||
|
||||
channel = switch_core_session_get_channel(session);
|
||||
assert(channel != NULL);
|
||||
assert(channel != NULL);
|
||||
|
||||
|
||||
if (switch_core_directory_open(&dh,
|
||||
if (switch_core_directory_open(&dh,
|
||||
"ldap",
|
||||
"ldap.freeswitch.org",
|
||||
"cn=Manager,dc=freeswitch,dc=org",
|
||||
"test",
|
||||
NULL) != SWITCH_STATUS_SUCCESS) {
|
||||
"cn=Manager,dc=freeswitch,dc=org", "test", NULL) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't connect\n");
|
||||
return;
|
||||
}
|
||||
@@ -177,16 +166,17 @@ static void dirtest_function(switch_core_session_t *session, char *data)
|
||||
|
||||
}
|
||||
|
||||
static switch_status_t show_dtmf(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf, unsigned int buflen)
|
||||
static switch_status_t show_dtmf(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf,
|
||||
unsigned int buflen)
|
||||
{
|
||||
|
||||
switch (itype) {
|
||||
case SWITCH_INPUT_TYPE_DTMF: {
|
||||
char *dtmf = (char *) input;
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Digits %s\n", dtmf);
|
||||
case SWITCH_INPUT_TYPE_DTMF:{
|
||||
char *dtmf = (char *) input;
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Digits %s\n", dtmf);
|
||||
|
||||
switch_copy_string((char *)buf, dtmf, buflen);
|
||||
}
|
||||
switch_copy_string((char *) buf, dtmf, buflen);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -203,9 +193,9 @@ static void tts_function(switch_core_session_t *session, char *data)
|
||||
char buf[10] = "";
|
||||
char *argv[3];
|
||||
int argc;
|
||||
switch_input_args_t args = {0};
|
||||
switch_input_args_t args = { 0 };
|
||||
|
||||
if(!(mydata = switch_core_session_strdup(session, (char *) data))) {
|
||||
if (!(mydata = switch_core_session_strdup(session, (char *) data))) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -221,14 +211,14 @@ static void tts_function(switch_core_session_t *session, char *data)
|
||||
}
|
||||
|
||||
channel = switch_core_session_get_channel(session);
|
||||
assert(channel != NULL);
|
||||
|
||||
switch_channel_answer(channel);
|
||||
assert(channel != NULL);
|
||||
|
||||
switch_channel_answer(channel);
|
||||
|
||||
codec = switch_core_session_get_read_codec(session);
|
||||
args.input_callback = show_dtmf;
|
||||
args.buf = buf;
|
||||
args.buflen = sizeof(buf);
|
||||
args.input_callback = show_dtmf;
|
||||
args.buf = buf;
|
||||
args.buflen = sizeof(buf);
|
||||
switch_ivr_speak_text(session, tts_name, voice_name, codec->implementation->samples_per_second, text, &args);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Done\n");
|
||||
}
|
||||
@@ -236,17 +226,17 @@ static void tts_function(switch_core_session_t *session, char *data)
|
||||
#ifdef BUGTEST
|
||||
static switch_bool_t bug_callback(switch_media_bug_t *bug, void *user_data, switch_abc_type_t type)
|
||||
{
|
||||
switch_frame_t *frame;
|
||||
switch_frame_t *frame;
|
||||
|
||||
switch(type) {
|
||||
switch (type) {
|
||||
case SWITCH_ABC_TYPE_WRITE_REPLACE:
|
||||
frame = switch_core_media_bug_get_replace_frame(bug);
|
||||
switch_core_media_bug_set_replace_frame(bug, frame);
|
||||
printf("W00t\n");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
frame = switch_core_media_bug_get_replace_frame(bug);
|
||||
switch_core_media_bug_set_replace_frame(bug, frame);
|
||||
printf("W00t\n");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return SWITCH_TRUE;
|
||||
}
|
||||
@@ -257,56 +247,46 @@ static void bugtest_function(switch_core_session_t *session, char *data)
|
||||
#ifdef BUGTEST
|
||||
switch_media_bug_t *bug;
|
||||
switch_channel_t *channel = switch_core_session_get_channel(session);
|
||||
switch_status_t status;
|
||||
switch_status_t status;
|
||||
|
||||
if ((status = switch_core_media_bug_add(session,
|
||||
bug_callback,
|
||||
NULL,
|
||||
SMBF_WRITE_REPLACE,
|
||||
&bug)) != SWITCH_STATUS_SUCCESS) {
|
||||
bug_callback, NULL, SMBF_WRITE_REPLACE, &bug)) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
|
||||
return;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
//switch_ivr_schedule_broadcast(time(NULL) + 10, switch_core_session_get_uuid(session), "/Users/anthm/sr8k.wav", SMF_ECHO_ALEG);
|
||||
//switch_ivr_schedule_transfer(time(NULL) + 10, switch_core_session_get_uuid(session), "2000", NULL, NULL);
|
||||
//switch_ivr_schedule_hangup(time(NULL) + 10, switch_core_session_get_uuid(session), SWITCH_CAUSE_ALLOTTED_TIMEOUT);
|
||||
|
||||
switch_ivr_play_file(session, NULL, data, NULL);
|
||||
switch_ivr_play_file(session, NULL, data, NULL);
|
||||
}
|
||||
|
||||
#if 1
|
||||
static void asrtest_function(switch_core_session_t *session, char *data)
|
||||
{
|
||||
switch_ivr_detect_speech(session,
|
||||
"lumenvox",
|
||||
"demo",
|
||||
data,
|
||||
"127.0.0.1",
|
||||
NULL);
|
||||
switch_ivr_detect_speech(session, "lumenvox", "demo", data, "127.0.0.1", NULL);
|
||||
}
|
||||
|
||||
#else
|
||||
#else
|
||||
static void asrtest_function(switch_core_session_t *session, char *data)
|
||||
{
|
||||
switch_asr_handle_t ah = {0};
|
||||
switch_asr_handle_t ah = { 0 };
|
||||
switch_asr_flag_t flags = SWITCH_ASR_FLAG_NONE;
|
||||
switch_channel_t *channel = switch_core_session_get_channel(session);
|
||||
char *codec_name = "L16";
|
||||
switch_codec_t codec = {0}, *read_codec;
|
||||
switch_frame_t write_frame = {0}, *write_frame_p = NULL;
|
||||
switch_codec_t codec = { 0 }, *read_codec;
|
||||
switch_frame_t write_frame = { 0 }, *write_frame_p = NULL;
|
||||
char xdata[1024] = "";
|
||||
|
||||
read_codec = switch_core_session_get_read_codec(session);
|
||||
assert(read_codec != NULL);
|
||||
|
||||
|
||||
|
||||
if (switch_core_asr_open(&ah, "lumenvox",
|
||||
read_codec->implementation->iananame,
|
||||
8000,
|
||||
"127.0.0.1",
|
||||
&flags,
|
||||
switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
|
||||
"127.0.0.1", &flags, switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
|
||||
if (strcmp(ah.codec, read_codec->implementation->iananame)) {
|
||||
if (switch_core_codec_init(&codec,
|
||||
ah.codec,
|
||||
@@ -317,36 +297,39 @@ static void asrtest_function(switch_core_session_t *session, char *data)
|
||||
SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
|
||||
NULL, switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activated\n");
|
||||
switch_core_session_set_read_codec(session, &codec);
|
||||
switch_core_session_set_read_codec(session, &codec);
|
||||
write_frame.data = xdata;
|
||||
write_frame.buflen = sizeof(xdata);
|
||||
write_frame.codec = &codec;
|
||||
write_frame_p = &write_frame;
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec Activation Failed %s@%uhz %u channels %dms\n",
|
||||
codec_name, read_codec->implementation->samples_per_second, read_codec->implementation->number_of_channels,
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
|
||||
"Codec Activation Failed %s@%uhz %u channels %dms\n", codec_name,
|
||||
read_codec->implementation->samples_per_second,
|
||||
read_codec->implementation->number_of_channels,
|
||||
read_codec->implementation->microseconds_per_frame / 1000);
|
||||
switch_core_session_reset(session);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (switch_core_asr_load_grammar(&ah, "demo", "/opt/lumenvox/engine_7.0/Lang/BuiltinGrammars/ABNFPhone.gram") != SWITCH_STATUS_SUCCESS) {
|
||||
|
||||
|
||||
if (switch_core_asr_load_grammar(&ah, "demo", "/opt/lumenvox/engine_7.0/Lang/BuiltinGrammars/ABNFPhone.gram") !=
|
||||
SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error loading Grammar\n");
|
||||
goto end;
|
||||
}
|
||||
|
||||
while(switch_channel_ready(channel)) {
|
||||
|
||||
while (switch_channel_ready(channel)) {
|
||||
switch_frame_t *read_frame;
|
||||
switch_status_t status = switch_core_session_read_frame(session, &read_frame, -1, 0);
|
||||
char *xmlstr = NULL;
|
||||
switch_xml_t xml = NULL, result;
|
||||
|
||||
|
||||
if (!SWITCH_READ_ACCEPTABLE(status)) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (switch_test_flag(read_frame, SFF_CNG)) {
|
||||
continue;
|
||||
}
|
||||
@@ -355,7 +338,7 @@ static void asrtest_function(switch_core_session_t *session, char *data)
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error Feeding Data\n");
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (switch_core_asr_check_results(&ah, &flags) == SWITCH_STATUS_SUCCESS) {
|
||||
if (switch_core_asr_get_results(&ah, &xmlstr, &flags) != SWITCH_STATUS_SUCCESS) {
|
||||
break;
|
||||
@@ -368,7 +351,7 @@ static void asrtest_function(switch_core_session_t *session, char *data)
|
||||
}
|
||||
switch_safe_free(xmlstr);
|
||||
}
|
||||
|
||||
|
||||
if (write_frame_p) {
|
||||
write_frame.datalen = read_frame->datalen;
|
||||
switch_core_session_write_frame(session, write_frame_p, -1, 0);
|
||||
@@ -378,7 +361,7 @@ static void asrtest_function(switch_core_session_t *session, char *data)
|
||||
}
|
||||
}
|
||||
|
||||
end:
|
||||
end:
|
||||
if (write_frame_p) {
|
||||
switch_core_session_set_read_codec(session, read_codec);
|
||||
switch_core_codec_destroy(&codec);
|
||||
@@ -400,9 +383,9 @@ static void ivrtest_function(switch_core_session_t *session, char *data)
|
||||
char buf[10] = "";
|
||||
char term;
|
||||
char say[128] = "";
|
||||
|
||||
|
||||
channel = switch_core_session_get_channel(session);
|
||||
assert(channel != NULL);
|
||||
assert(channel != NULL);
|
||||
|
||||
switch_channel_answer(channel);
|
||||
|
||||
@@ -410,18 +393,19 @@ static void ivrtest_function(switch_core_session_t *session, char *data)
|
||||
|
||||
while (switch_channel_get_state(channel) == CS_EXECUTE) {
|
||||
memset(buf, 0, sizeof(buf));
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Enter up to 10 digits, press # to terminate, * to hangup\n");
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE,
|
||||
"Enter up to 10 digits, press # to terminate, * to hangup\n");
|
||||
|
||||
if (data) {
|
||||
switch_input_args_t args = {0};
|
||||
switch_input_args_t args = { 0 };
|
||||
/* you could have passed NULL instead of on_dtmf to get this exact behaviour (copy the digits to buf and stop playing)
|
||||
but you may want to pass the function if you have something cooler to do...
|
||||
*/
|
||||
args.input_callback = on_dtmf;
|
||||
args.buf = buf;
|
||||
args.buflen = sizeof(buf);
|
||||
*/
|
||||
args.input_callback = on_dtmf;
|
||||
args.buf = buf;
|
||||
args.buflen = sizeof(buf);
|
||||
status = switch_ivr_play_file(session, NULL, data, &args);
|
||||
|
||||
|
||||
if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
|
||||
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
|
||||
break;
|
||||
@@ -440,7 +424,7 @@ static void ivrtest_function(switch_core_session_t *session, char *data)
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, say);
|
||||
switch_ivr_speak_text(session, "cepstral", "david", codec->implementation->samples_per_second, say, NULL);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -449,9 +433,10 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
|
||||
switch_channel_t *channel;
|
||||
|
||||
channel = switch_core_session_get_channel(session);
|
||||
assert(channel != NULL);
|
||||
assert(channel != NULL);
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "I globally hooked to [%s] on the hangup event\n", switch_channel_get_name(channel));
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "I globally hooked to [%s] on the hangup event\n",
|
||||
switch_channel_get_name(channel));
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
|
||||
}
|
||||
@@ -472,7 +457,7 @@ static const switch_application_interface_t bug_application_interface = {
|
||||
/*.application_function */ bugtest_function,
|
||||
NULL, NULL, NULL,
|
||||
/* flags */ SAF_NONE,
|
||||
/*.next*/ NULL
|
||||
/*.next */ NULL
|
||||
};
|
||||
|
||||
static const switch_application_interface_t ivr_application_interface = {
|
||||
@@ -480,7 +465,7 @@ static const switch_application_interface_t ivr_application_interface = {
|
||||
/*.application_function */ ivr_application_function,
|
||||
NULL, NULL, NULL,
|
||||
/* flags */ SAF_NONE,
|
||||
/*.next*/ &bug_application_interface
|
||||
/*.next */ &bug_application_interface
|
||||
};
|
||||
|
||||
static const switch_application_interface_t xml_application_interface = {
|
||||
@@ -488,7 +473,7 @@ static const switch_application_interface_t xml_application_interface = {
|
||||
/*.application_function */ xml_function,
|
||||
NULL, NULL, NULL,
|
||||
/* flags */ SAF_NONE,
|
||||
/*.next*/ &ivr_application_interface
|
||||
/*.next */ &ivr_application_interface
|
||||
};
|
||||
|
||||
static const switch_application_interface_t disast_application_interface = {
|
||||
@@ -496,7 +481,7 @@ static const switch_application_interface_t disast_application_interface = {
|
||||
/*.application_function */ disast_function,
|
||||
NULL, NULL, NULL,
|
||||
/* flags */ SAF_SUPPORT_NOMEDIA,
|
||||
/*.next*/ &xml_application_interface
|
||||
/*.next */ &xml_application_interface
|
||||
};
|
||||
|
||||
static const switch_application_interface_t tts_application_interface = {
|
||||
@@ -504,7 +489,7 @@ static const switch_application_interface_t tts_application_interface = {
|
||||
/*.application_function */ tts_function,
|
||||
NULL, NULL, NULL,
|
||||
/* flags */ SAF_NONE,
|
||||
/*.next*/ &disast_application_interface
|
||||
/*.next */ &disast_application_interface
|
||||
};
|
||||
|
||||
static const switch_application_interface_t dirtest_application_interface = {
|
||||
@@ -512,7 +497,7 @@ static const switch_application_interface_t dirtest_application_interface = {
|
||||
/*.application_function */ dirtest_function,
|
||||
NULL, NULL, NULL,
|
||||
/* flags */ SAF_SUPPORT_NOMEDIA,
|
||||
/*.next*/ &tts_application_interface
|
||||
/*.next */ &tts_application_interface
|
||||
};
|
||||
|
||||
static const switch_application_interface_t ivrtest_application_interface = {
|
||||
@@ -520,7 +505,7 @@ static const switch_application_interface_t ivrtest_application_interface = {
|
||||
/*.application_function */ ivrtest_function,
|
||||
NULL, NULL, NULL,
|
||||
/* flags */ SAF_NONE,
|
||||
/*.next*/ &dirtest_application_interface
|
||||
/*.next */ &dirtest_application_interface
|
||||
};
|
||||
|
||||
static const switch_application_interface_t asrtest_application_interface = {
|
||||
@@ -528,7 +513,7 @@ static const switch_application_interface_t asrtest_application_interface = {
|
||||
/*.application_function */ asrtest_function,
|
||||
NULL, NULL, NULL,
|
||||
/* flags */ SAF_NONE,
|
||||
/*.next*/ &ivrtest_application_interface
|
||||
/*.next */ &ivrtest_application_interface
|
||||
};
|
||||
|
||||
static const switch_loadable_module_interface_t mod_ivrtest_module_interface = {
|
||||
@@ -540,7 +525,8 @@ static const switch_loadable_module_interface_t mod_ivrtest_module_interface = {
|
||||
/*.application_interface */ &asrtest_application_interface
|
||||
};
|
||||
|
||||
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
|
||||
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
|
||||
char *filename)
|
||||
{
|
||||
|
||||
/* connect my internal structure to the blank pointer passed to me */
|
||||
|
||||
@@ -35,13 +35,13 @@ static const char modname[] = "mod_park";
|
||||
static void park_function(switch_core_session_t *session, char *data)
|
||||
{
|
||||
switch_ivr_park(session, NULL);
|
||||
|
||||
|
||||
}
|
||||
|
||||
static const switch_application_interface_t park_application_interface = {
|
||||
/*.interface_name */ "park",
|
||||
/*.application_function */ park_function,
|
||||
NULL,NULL,NULL,
|
||||
NULL, NULL, NULL,
|
||||
/* flags */ SAF_NONE,
|
||||
NULL
|
||||
};
|
||||
@@ -59,7 +59,8 @@ static switch_loadable_module_interface_t park_module_interface = {
|
||||
/*.directory_interface */ NULL
|
||||
};
|
||||
|
||||
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
|
||||
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
|
||||
char *filename)
|
||||
{
|
||||
/* connect my internal structure to the blank pointer passed to me */
|
||||
*module_interface = &park_module_interface;
|
||||
|
||||
@@ -38,24 +38,25 @@ static const char modname[] = "mod_playback";
|
||||
dtmf handler function you can hook up to be executed when a digit is dialed during playback
|
||||
if you return anything but SWITCH_STATUS_SUCCESS the playback will stop.
|
||||
*/
|
||||
static switch_status_t on_dtmf(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf, unsigned int buflen)
|
||||
static switch_status_t on_dtmf(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf,
|
||||
unsigned int buflen)
|
||||
{
|
||||
|
||||
|
||||
|
||||
switch (itype) {
|
||||
case SWITCH_INPUT_TYPE_DTMF: {
|
||||
char *dtmf = (char *) input;
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Digits %s\n", dtmf);
|
||||
|
||||
if (*dtmf == '*') {
|
||||
return SWITCH_STATUS_BREAK;
|
||||
case SWITCH_INPUT_TYPE_DTMF:{
|
||||
char *dtmf = (char *) input;
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Digits %s\n", dtmf);
|
||||
|
||||
if (*dtmf == '*') {
|
||||
return SWITCH_STATUS_BREAK;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -64,28 +65,28 @@ static void speak_function(switch_core_session_t *session, char *data)
|
||||
{
|
||||
switch_channel_t *channel;
|
||||
char buf[10];
|
||||
char *argv[4] = {0};
|
||||
char *argv[4] = { 0 };
|
||||
int argc;
|
||||
char *engine = NULL;
|
||||
char *voice = NULL;
|
||||
char *text = NULL;
|
||||
char *mydata = NULL;
|
||||
switch_codec_t *codec;
|
||||
switch_input_args_t args = {0};
|
||||
switch_input_args_t args = { 0 };
|
||||
|
||||
codec = switch_core_session_get_read_codec(session);
|
||||
assert(codec != NULL);
|
||||
|
||||
channel = switch_core_session_get_channel(session);
|
||||
assert(channel != NULL);
|
||||
assert(channel != NULL);
|
||||
|
||||
mydata = switch_core_session_strdup(session, data);
|
||||
argc = switch_separate_string(mydata, '|', argv, sizeof(argv)/sizeof(argv[0]));
|
||||
argc = switch_separate_string(mydata, '|', argv, sizeof(argv) / sizeof(argv[0]));
|
||||
|
||||
engine = argv[0];
|
||||
voice = argv[1];
|
||||
text = argv[2];
|
||||
|
||||
|
||||
if (!(engine && voice && text)) {
|
||||
if (!engine) {
|
||||
engine = "NULL";
|
||||
@@ -102,27 +103,27 @@ static void speak_function(switch_core_session_t *session, char *data)
|
||||
|
||||
switch_channel_pre_answer(channel);
|
||||
|
||||
args.input_callback = on_dtmf;
|
||||
args.buf = buf;
|
||||
args.buflen = sizeof(buf);
|
||||
args.input_callback = on_dtmf;
|
||||
args.buf = buf;
|
||||
args.buflen = sizeof(buf);
|
||||
switch_ivr_speak_text(session, engine, voice, codec->implementation->samples_per_second, text, &args);
|
||||
|
||||
|
||||
}
|
||||
|
||||
static void playback_function(switch_core_session_t *session, char *data)
|
||||
{
|
||||
switch_channel_t *channel;
|
||||
char *file_name = NULL;
|
||||
switch_input_args_t args = {0};
|
||||
switch_input_args_t args = { 0 };
|
||||
|
||||
file_name = switch_core_session_strdup(session, data);
|
||||
|
||||
channel = switch_core_session_get_channel(session);
|
||||
assert(channel != NULL);
|
||||
assert(channel != NULL);
|
||||
|
||||
switch_channel_pre_answer(channel);
|
||||
|
||||
args.input_callback = on_dtmf;
|
||||
args.input_callback = on_dtmf;
|
||||
switch_ivr_play_file(session, NULL, file_name, &args);
|
||||
|
||||
}
|
||||
@@ -132,21 +133,21 @@ static void record_function(switch_core_session_t *session, char *data)
|
||||
{
|
||||
switch_channel_t *channel;
|
||||
switch_status_t status;
|
||||
uint32_t limit = 0;
|
||||
char *path;
|
||||
char *p;
|
||||
switch_input_args_t args = {0};
|
||||
uint32_t limit = 0;
|
||||
char *path;
|
||||
char *p;
|
||||
switch_input_args_t args = { 0 };
|
||||
|
||||
channel = switch_core_session_get_channel(session);
|
||||
assert(channel != NULL);
|
||||
assert(channel != NULL);
|
||||
|
||||
path = switch_core_session_strdup(session, data);
|
||||
if ((p = strchr(path, '+'))) {
|
||||
*p++ = '\0';
|
||||
limit = atoi(p);
|
||||
}
|
||||
path = switch_core_session_strdup(session, data);
|
||||
if ((p = strchr(path, '+'))) {
|
||||
*p++ = '\0';
|
||||
limit = atoi(p);
|
||||
}
|
||||
|
||||
args.input_callback = on_dtmf;
|
||||
args.input_callback = on_dtmf;
|
||||
status = switch_ivr_record_file(session, NULL, path, &args, limit);
|
||||
|
||||
if (!switch_channel_ready(channel) || (status != SWITCH_STATUS_SUCCESS && !SWITCH_STATUS_IS_BREAK(status))) {
|
||||
@@ -159,9 +160,9 @@ static void record_session_function(switch_core_session_t *session, char *data)
|
||||
{
|
||||
switch_channel_t *channel;
|
||||
channel = switch_core_session_get_channel(session);
|
||||
assert(channel != NULL);
|
||||
assert(channel != NULL);
|
||||
|
||||
switch_ivr_record_session(session, data, NULL);
|
||||
switch_ivr_record_session(session, data, NULL);
|
||||
}
|
||||
|
||||
|
||||
@@ -169,9 +170,9 @@ static void stop_record_session_function(switch_core_session_t *session, char *d
|
||||
{
|
||||
switch_channel_t *channel;
|
||||
channel = switch_core_session_get_channel(session);
|
||||
assert(channel != NULL);
|
||||
assert(channel != NULL);
|
||||
|
||||
switch_ivr_stop_record_session(session, data);
|
||||
switch_ivr_stop_record_session(session, data);
|
||||
}
|
||||
|
||||
|
||||
@@ -223,7 +224,7 @@ static const switch_application_interface_t playback_application_interface = {
|
||||
/* short_desc */ "Playback File",
|
||||
/* syntax */ "<path>",
|
||||
/* flags */ SAF_NONE,
|
||||
/*.next*/ &stop_record_session_application_interface
|
||||
/*.next */ &stop_record_session_application_interface
|
||||
};
|
||||
|
||||
static const switch_loadable_module_interface_t mod_playback_module_interface = {
|
||||
@@ -235,7 +236,8 @@ static const switch_loadable_module_interface_t mod_playback_module_interface =
|
||||
/*.application_interface */ &playback_application_interface
|
||||
};
|
||||
|
||||
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
|
||||
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
|
||||
char *filename)
|
||||
{
|
||||
|
||||
/* connect my internal structure to the blank pointer passed to me */
|
||||
|
||||
@@ -68,9 +68,9 @@ static uint32_t match_count(char *str, uint32_t max)
|
||||
{
|
||||
char tstr[80] = "";
|
||||
uint32_t matches = 0, x = 0;
|
||||
uint32_t len = (uint32_t)strlen(str);
|
||||
uint32_t len = (uint32_t) strlen(str);
|
||||
|
||||
for (x = 0; x < max ; x++) {
|
||||
for (x = 0; x < max; x++) {
|
||||
snprintf(tstr, sizeof(tstr), "%u", x);
|
||||
if (!strncasecmp(str, tstr, len)) {
|
||||
matches++;
|
||||
@@ -85,68 +85,68 @@ static uint32_t match_count(char *str, uint32_t max)
|
||||
dtmf handler function you can hook up to be executed when a digit is dialed during playback
|
||||
if you return anything but SWITCH_STATUS_SUCCESS the playback will stop.
|
||||
*/
|
||||
static switch_status_t on_dtmf(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf, unsigned int buflen)
|
||||
|
||||
static switch_status_t on_dtmf(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf,
|
||||
unsigned int buflen)
|
||||
{
|
||||
switch (itype) {
|
||||
case SWITCH_INPUT_TYPE_DTMF: {
|
||||
char *dtmf = (char *) input;
|
||||
struct dtmf_buffer *dtb;
|
||||
dtb = (struct dtmf_buffer *) buf;
|
||||
|
||||
switch(*dtmf) {
|
||||
case '#':
|
||||
switch_set_flag(dtb, SFLAG_MAIN);
|
||||
return SWITCH_STATUS_BREAK;
|
||||
case '6':
|
||||
dtb->index++;
|
||||
return SWITCH_STATUS_BREAK;
|
||||
case '4':
|
||||
dtb->index--;
|
||||
return SWITCH_STATUS_BREAK;
|
||||
case '*':
|
||||
if (switch_test_flag(dtb->sh, SWITCH_SPEECH_FLAG_PAUSE)) {
|
||||
switch_clear_flag(dtb->sh, SWITCH_SPEECH_FLAG_PAUSE);
|
||||
} else {
|
||||
switch_set_flag(dtb->sh, SWITCH_SPEECH_FLAG_PAUSE);
|
||||
}
|
||||
break;
|
||||
case '5':
|
||||
switch_core_speech_text_param_tts(dtb->sh, "voice", "next");
|
||||
switch_set_flag(dtb, SFLAG_INFO);
|
||||
return SWITCH_STATUS_BREAK;
|
||||
break;
|
||||
case '9':
|
||||
switch_core_speech_text_param_tts(dtb->sh, "voice", dtb->voice);
|
||||
switch_set_flag(dtb, SFLAG_INFO);
|
||||
return SWITCH_STATUS_BREAK;
|
||||
break;
|
||||
case '2':
|
||||
if (dtb->speed < 260) {
|
||||
dtb->speed += 30;
|
||||
case SWITCH_INPUT_TYPE_DTMF:{
|
||||
char *dtmf = (char *) input;
|
||||
struct dtmf_buffer *dtb;
|
||||
dtb = (struct dtmf_buffer *) buf;
|
||||
|
||||
switch (*dtmf) {
|
||||
case '#':
|
||||
switch_set_flag(dtb, SFLAG_MAIN);
|
||||
return SWITCH_STATUS_BREAK;
|
||||
case '6':
|
||||
dtb->index++;
|
||||
return SWITCH_STATUS_BREAK;
|
||||
case '4':
|
||||
dtb->index--;
|
||||
return SWITCH_STATUS_BREAK;
|
||||
case '*':
|
||||
if (switch_test_flag(dtb->sh, SWITCH_SPEECH_FLAG_PAUSE)) {
|
||||
switch_clear_flag(dtb->sh, SWITCH_SPEECH_FLAG_PAUSE);
|
||||
} else {
|
||||
switch_set_flag(dtb->sh, SWITCH_SPEECH_FLAG_PAUSE);
|
||||
}
|
||||
break;
|
||||
case '5':
|
||||
switch_core_speech_text_param_tts(dtb->sh, "voice", "next");
|
||||
switch_set_flag(dtb, SFLAG_INFO);
|
||||
return SWITCH_STATUS_BREAK;
|
||||
break;
|
||||
case '9':
|
||||
switch_core_speech_text_param_tts(dtb->sh, "voice", dtb->voice);
|
||||
switch_set_flag(dtb, SFLAG_INFO);
|
||||
return SWITCH_STATUS_BREAK;
|
||||
break;
|
||||
case '2':
|
||||
if (dtb->speed < 260) {
|
||||
dtb->speed += 30;
|
||||
switch_core_speech_numeric_param_tts(dtb->sh, "speech/rate", dtb->speed);
|
||||
switch_set_flag(dtb, SFLAG_INFO);
|
||||
return SWITCH_STATUS_BREAK;
|
||||
}
|
||||
break;
|
||||
case '7':
|
||||
dtb->speed = TTS_MEAN_SPEED;
|
||||
switch_core_speech_numeric_param_tts(dtb->sh, "speech/rate", dtb->speed);
|
||||
switch_set_flag(dtb, SFLAG_INFO);
|
||||
return SWITCH_STATUS_BREAK;
|
||||
}
|
||||
break;
|
||||
case '7':
|
||||
dtb->speed = TTS_MEAN_SPEED;
|
||||
switch_core_speech_numeric_param_tts(dtb->sh, "speech/rate", dtb->speed);
|
||||
switch_set_flag(dtb, SFLAG_INFO);
|
||||
return SWITCH_STATUS_BREAK;
|
||||
case '8':
|
||||
if (dtb->speed > 80) {
|
||||
dtb->speed -= 30;
|
||||
switch_core_speech_numeric_param_tts(dtb->sh, "speech/rate", dtb->speed);
|
||||
switch_set_flag(dtb, SFLAG_INFO);
|
||||
case '8':
|
||||
if (dtb->speed > 80) {
|
||||
dtb->speed -= 30;
|
||||
switch_core_speech_numeric_param_tts(dtb->sh, "speech/rate", dtb->speed);
|
||||
switch_set_flag(dtb, SFLAG_INFO);
|
||||
return SWITCH_STATUS_BREAK;
|
||||
}
|
||||
break;
|
||||
case '0':
|
||||
switch_set_flag(dtb, SFLAG_INSTRUCT);
|
||||
return SWITCH_STATUS_BREAK;
|
||||
}
|
||||
break;
|
||||
case '0':
|
||||
switch_set_flag(dtb, SFLAG_INSTRUCT);
|
||||
return SWITCH_STATUS_BREAK;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -159,9 +159,9 @@ static void rss_function(switch_core_session_t *session, char *data)
|
||||
switch_channel_t *channel;
|
||||
switch_status_t status;
|
||||
const char *err = NULL;
|
||||
struct dtmf_buffer dtb = {0};
|
||||
struct dtmf_buffer dtb = { 0 };
|
||||
switch_xml_t xml = NULL, item, xchannel = NULL;
|
||||
struct rss_entry entries[TTS_MAX_ENTRIES] = {{0}};
|
||||
struct rss_entry entries[TTS_MAX_ENTRIES] = { {0} };
|
||||
uint32_t i = 0;
|
||||
char *title_txt = "", *description_txt = "", *rights_txt = "";
|
||||
switch_codec_t speech_codec, *codec = switch_core_session_get_read_codec(session);
|
||||
@@ -169,31 +169,32 @@ static void rss_function(switch_core_session_t *session, char *data)
|
||||
char *voice = TTS_DEFAULT_VOICE;
|
||||
char *timer_name = NULL;
|
||||
switch_speech_handle_t sh;
|
||||
switch_speech_flag_t flags = SWITCH_SPEECH_FLAG_NONE;
|
||||
switch_speech_flag_t flags = SWITCH_SPEECH_FLAG_NONE;
|
||||
switch_core_thread_session_t thread_session;
|
||||
uint32_t rate, interval = 20;
|
||||
int stream_id = 0;
|
||||
switch_timer_t timer = {0}, *timerp = NULL;
|
||||
switch_timer_t timer = { 0 }, *timerp = NULL;
|
||||
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;
|
||||
char *cf = "rss.conf";
|
||||
switch_xml_t cfg, cxml, feeds, feed;
|
||||
switch_xml_t cfg, cxml, feeds, feed;
|
||||
char buf[1024];
|
||||
int32_t jumpto = -1;
|
||||
uint32_t matches = 0;
|
||||
switch_input_args_t args = {0};
|
||||
switch_input_args_t args = { 0 };
|
||||
|
||||
channel = switch_core_session_get_channel(session);
|
||||
assert(channel != NULL);
|
||||
assert(channel != NULL);
|
||||
|
||||
|
||||
if (!(cxml = switch_xml_open_cfg(cf, &cfg, NULL))) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
|
||||
return;
|
||||
}
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((feeds = switch_xml_child(cfg, "feeds"))) {
|
||||
for (feed = switch_xml_child(feeds, "feed"); feed; feed = feed->next) {
|
||||
@@ -210,14 +211,14 @@ static void rss_function(switch_core_session_t *session, char *data)
|
||||
}
|
||||
|
||||
switch_xml_free(cxml);
|
||||
|
||||
|
||||
switch_channel_answer(channel);
|
||||
|
||||
|
||||
|
||||
if (!switch_strlen_zero(data)) {
|
||||
if ((mydata = switch_core_session_strdup(session, data))) {
|
||||
argc = switch_separate_string(mydata, ' ', argv, sizeof(argv)/sizeof(argv[0]));
|
||||
argc = switch_separate_string(mydata, ' ', argv, sizeof(argv) / sizeof(argv[0]));
|
||||
|
||||
if (argv[0]) {
|
||||
engine = argv[0];
|
||||
@@ -246,40 +247,40 @@ static void rss_function(switch_core_session_t *session, char *data)
|
||||
memset(&sh, 0, sizeof(sh));
|
||||
if (switch_core_speech_open(&sh,
|
||||
engine,
|
||||
voice,
|
||||
rate,
|
||||
&flags,
|
||||
switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
|
||||
voice, rate, &flags, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid TTS module!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (switch_core_codec_init(&speech_codec,
|
||||
"L16",
|
||||
NULL,
|
||||
(int)rate,
|
||||
(int) rate,
|
||||
interval,
|
||||
1,
|
||||
SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
|
||||
NULL,
|
||||
switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
|
||||
NULL, switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activated\n");
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activation Failed L16@%uhz 1 channel %dms\n", rate, interval);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activation Failed L16@%uhz 1 channel %dms\n",
|
||||
rate, interval);
|
||||
flags = 0;
|
||||
switch_core_speech_close(&sh, &flags);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (timer_name) {
|
||||
if (switch_core_timer_init(&timer, timer_name, interval, (int)(rate / 50), switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
|
||||
if (switch_core_timer_init
|
||||
(&timer, timer_name, interval, (int) (rate / 50),
|
||||
switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "setup timer failed!\n");
|
||||
switch_core_codec_destroy(&speech_codec);
|
||||
flags = 0;
|
||||
switch_core_speech_close(&sh, &flags);
|
||||
return;
|
||||
}
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "setup timer success %u bytes per %d ms!\n", (rate / 50)*2, interval);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "setup timer success %u bytes per %d ms!\n",
|
||||
(rate / 50) * 2, interval);
|
||||
|
||||
/* start a thread to absorb incoming audio */
|
||||
for (stream_id = 0; stream_id < switch_core_session_get_stream_count(session); stream_id++) {
|
||||
@@ -292,7 +293,7 @@ static void rss_function(switch_core_session_t *session, char *data)
|
||||
while (switch_channel_ready(channel)) {
|
||||
int32_t len = 0, idx = 0;
|
||||
char cmd[3];
|
||||
main_menu:
|
||||
main_menu:
|
||||
filename = NULL;
|
||||
len = idx = 0;
|
||||
*cmd = '\0';
|
||||
@@ -304,36 +305,30 @@ static void rss_function(switch_core_session_t *session, char *data)
|
||||
} else {
|
||||
switch_core_speech_flush_tts(&sh);
|
||||
#ifdef MATCH_COUNT
|
||||
snprintf(buf + len, sizeof(buf) - len,
|
||||
snprintf(buf + len, sizeof(buf) - len,
|
||||
",<break time=\"500ms\"/>Main Menu. <break time=\"600ms\"/> "
|
||||
"Select one of the following news sources, or press 0 to exit. "
|
||||
",<break time=\"600ms\"/>");
|
||||
"Select one of the following news sources, or press 0 to exit. " ",<break time=\"600ms\"/>");
|
||||
#else
|
||||
snprintf(buf + len, sizeof(buf) - len,
|
||||
snprintf(buf + len, sizeof(buf) - len,
|
||||
",<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);
|
||||
len = (int32_t) strlen(buf);
|
||||
|
||||
for (idx = 0; idx < feed_index; idx++) {
|
||||
snprintf(buf + len, sizeof(buf) - len, "%d: %s. <break time=\"600ms\"/>", idx + 1, feed_names[idx]);
|
||||
len = (int32_t)strlen(buf);
|
||||
len = (int32_t) strlen(buf);
|
||||
}
|
||||
|
||||
|
||||
snprintf(buf + len, sizeof(buf) - len, "<break time=\"2000ms\"/>");
|
||||
len = (int32_t)strlen(buf);
|
||||
len = (int32_t) strlen(buf);
|
||||
|
||||
args.input_callback = NULL;
|
||||
args.buf = cmd;
|
||||
args.buflen = sizeof(cmd);
|
||||
status = switch_ivr_speak_text_handle(session,
|
||||
&sh,
|
||||
&speech_codec,
|
||||
timerp,
|
||||
buf,
|
||||
&args);
|
||||
status = switch_ivr_speak_text_handle(session, &sh, &speech_codec, timerp, buf, &args);
|
||||
if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
|
||||
goto finished;
|
||||
}
|
||||
@@ -346,31 +341,31 @@ static void rss_function(switch_core_session_t *session, char *data)
|
||||
break;
|
||||
}
|
||||
|
||||
if ((p=strchr(cmd, '#'))) {
|
||||
if ((p = strchr(cmd, '#'))) {
|
||||
*p = '\0';
|
||||
#ifdef MATCH_COUNT
|
||||
/* Hmmm... I know there are no more matches so I don't *need* them to press pound but
|
||||
I already told them to press it. Will this confuse people or not? Let's make em press
|
||||
pound unless this define is enabled for now.
|
||||
*/
|
||||
*/
|
||||
} else if (match_count(cmd, feed_index) > 1) {
|
||||
#else
|
||||
} else {
|
||||
#endif
|
||||
char term;
|
||||
char *cp;
|
||||
int blen = sizeof(cmd) - (int)strlen(cmd);
|
||||
int blen = sizeof(cmd) - (int) strlen(cmd);
|
||||
|
||||
cp = cmd + blen;
|
||||
switch_ivr_collect_digits_count(session, cp, blen, blen, "#", &term, 5000);
|
||||
}
|
||||
|
||||
|
||||
i = atoi(cmd) - 1;
|
||||
|
||||
if (i > -1 && i < feed_index) {
|
||||
filename = feed_list[i];
|
||||
} else if (matches > 1) {
|
||||
|
||||
|
||||
} else {
|
||||
args.input_callback = NULL;
|
||||
args.buf = NULL;
|
||||
@@ -378,19 +373,17 @@ static void rss_function(switch_core_session_t *session, char *data)
|
||||
status = switch_ivr_speak_text_handle(session,
|
||||
&sh,
|
||||
&speech_codec,
|
||||
timerp,
|
||||
"I'm sorry. That is an Invalid Selection. ",
|
||||
&args);
|
||||
timerp, "I'm sorry. That is an Invalid Selection. ", &args);
|
||||
if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!filename) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (!(xml = switch_xml_parse_file(filename))) {
|
||||
@@ -411,7 +404,7 @@ static void rss_function(switch_core_session_t *session, char *data)
|
||||
if ((title = switch_xml_child(xchannel, "title"))) {
|
||||
title_txt = title->txt;
|
||||
}
|
||||
|
||||
|
||||
if ((description = switch_xml_child(xchannel, "description"))) {
|
||||
description_txt = description->txt;
|
||||
}
|
||||
@@ -444,19 +437,19 @@ static void rss_function(switch_core_session_t *session, char *data)
|
||||
if ((title = switch_xml_child(item, "title"))) {
|
||||
entries[i].title_txt = title->txt;
|
||||
}
|
||||
|
||||
|
||||
if ((description = switch_xml_child(item, "description"))) {
|
||||
char *t, *e;
|
||||
entries[i].description_txt = description->txt;
|
||||
for(;;) {
|
||||
for (;;) {
|
||||
if (!(t = strchr(entries[i].description_txt, '<'))) {
|
||||
break;
|
||||
}
|
||||
if (!(e = strchr(t, '>'))) {
|
||||
break;
|
||||
}
|
||||
|
||||
memset(t, 32, ++e-t);
|
||||
|
||||
memset(t, 32, ++e - t);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -471,9 +464,8 @@ static void rss_function(switch_core_session_t *session, char *data)
|
||||
if (entries[i].description_txt && (p = strchr(entries[i].description_txt, '<'))) {
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
#ifdef _STRIP_SOME_CHARS_
|
||||
for(p = entries[i].description_txt; *p; p++) {
|
||||
for (p = entries[i].description_txt; *p; p++) {
|
||||
if (*p == '\'' || *p == '"' || *p == ':') {
|
||||
*p = ' ';
|
||||
}
|
||||
@@ -493,17 +485,13 @@ static void rss_function(switch_core_session_t *session, char *data)
|
||||
switch_strftime(date, &retsize, sizeof(date), "%I:%M %p", &tm);
|
||||
|
||||
|
||||
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. ",
|
||||
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);
|
||||
args.input_callback = NULL;
|
||||
args.buf = cmd;
|
||||
args.buflen = sizeof(cmd);
|
||||
status = switch_ivr_speak_text_handle(session,
|
||||
&sh,
|
||||
&speech_codec,
|
||||
timerp,
|
||||
buf,
|
||||
&args);
|
||||
status = switch_ivr_speak_text_handle(session, &sh, &speech_codec, timerp, buf, &args);
|
||||
if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
|
||||
goto finished;
|
||||
}
|
||||
@@ -519,7 +507,7 @@ static void rss_function(switch_core_session_t *session, char *data)
|
||||
}
|
||||
}
|
||||
|
||||
for(last = 0; last < TTS_MAX_ENTRIES; last++) {
|
||||
for (last = 0; last < TTS_MAX_ENTRIES; last++) {
|
||||
if (!entries[last].inuse) {
|
||||
last--;
|
||||
break;
|
||||
@@ -531,8 +519,8 @@ static void rss_function(switch_core_session_t *session, char *data)
|
||||
dtb.speed = TTS_MEAN_SPEED;
|
||||
switch_set_flag(&dtb, SFLAG_INFO);
|
||||
switch_copy_string(dtb.voice, voice, sizeof(dtb.voice));
|
||||
while(entries[0].inuse && switch_channel_ready(channel)) {
|
||||
while(switch_channel_ready(channel)) {
|
||||
while (entries[0].inuse && switch_channel_ready(channel)) {
|
||||
while (switch_channel_ready(channel)) {
|
||||
uint8_t cont = 0;
|
||||
|
||||
if (dtb.index >= TTS_MAX_ENTRIES) {
|
||||
@@ -557,12 +545,8 @@ static void rss_function(switch_core_session_t *session, char *data)
|
||||
if (switch_test_flag(&dtb, SFLAG_INFO)) {
|
||||
switch_clear_flag(&dtb, SFLAG_INFO);
|
||||
snprintf(buf + len, sizeof(buf) - len,
|
||||
"%s %s. I am speaking at %u words per minute. ",
|
||||
sh.engine,
|
||||
sh.voice,
|
||||
dtb.speed
|
||||
);
|
||||
len = (uint32_t)strlen(buf);
|
||||
"%s %s. I am speaking at %u words per minute. ", sh.engine, sh.voice, dtb.speed);
|
||||
len = (uint32_t) strlen(buf);
|
||||
}
|
||||
|
||||
if (switch_test_flag(&dtb, SFLAG_INSTRUCT)) {
|
||||
@@ -577,33 +561,29 @@ static void rss_function(switch_core_session_t *session, char *data)
|
||||
"To hear these options again, press zero or press pound to return to the main menu. ");
|
||||
} else {
|
||||
snprintf(buf + len, sizeof(buf) - len, "Story %d. ", dtb.index + 1);
|
||||
len = (uint32_t)strlen(buf);
|
||||
len = (uint32_t) strlen(buf);
|
||||
|
||||
if (entries[dtb.index].subject_txt) {
|
||||
snprintf(buf + len, sizeof(buf) - len, "Subject: %s. ", entries[dtb.index].subject_txt);
|
||||
len = (uint32_t)strlen(buf);
|
||||
len = (uint32_t) strlen(buf);
|
||||
}
|
||||
|
||||
|
||||
if (entries[dtb.index].dept_txt) {
|
||||
snprintf(buf + len, sizeof(buf) - len, "From the %s department. ", entries[dtb.index].dept_txt);
|
||||
len = (uint32_t)strlen(buf);
|
||||
snprintf(buf + len, sizeof(buf) - len, "From the %s department. ",
|
||||
entries[dtb.index].dept_txt);
|
||||
len = (uint32_t) strlen(buf);
|
||||
}
|
||||
|
||||
if (entries[dtb.index].title_txt) {
|
||||
snprintf(buf + len, sizeof(buf) - len, "%s", entries[dtb.index].title_txt);
|
||||
len = (uint32_t)strlen(buf);
|
||||
len = (uint32_t) strlen(buf);
|
||||
}
|
||||
}
|
||||
switch_core_speech_flush_tts(&sh);
|
||||
args.input_callback = on_dtmf;
|
||||
args.buf = &dtb;
|
||||
args.buflen = sizeof(dtb);
|
||||
status = switch_ivr_speak_text_handle(session,
|
||||
&sh,
|
||||
&speech_codec,
|
||||
timerp,
|
||||
buf,
|
||||
&args);
|
||||
status = switch_ivr_speak_text_handle(session, &sh, &speech_codec, timerp, buf, &args);
|
||||
if (status == SWITCH_STATUS_BREAK) {
|
||||
continue;
|
||||
} else if (status != SWITCH_STATUS_SUCCESS) {
|
||||
@@ -614,7 +594,7 @@ static void rss_function(switch_core_session_t *session, char *data)
|
||||
cont = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (entries[dtb.index].description_txt) {
|
||||
args.input_callback = on_dtmf;
|
||||
args.buf = &dtb;
|
||||
@@ -622,9 +602,7 @@ static void rss_function(switch_core_session_t *session, char *data)
|
||||
status = switch_ivr_speak_text_handle(session,
|
||||
&sh,
|
||||
&speech_codec,
|
||||
timerp,
|
||||
entries[dtb.index].description_txt,
|
||||
&args);
|
||||
timerp, entries[dtb.index].description_txt, &args);
|
||||
}
|
||||
if (status == SWITCH_STATUS_BREAK) {
|
||||
continue;
|
||||
@@ -638,7 +616,7 @@ static void rss_function(switch_core_session_t *session, char *data)
|
||||
}
|
||||
}
|
||||
|
||||
finished:
|
||||
finished:
|
||||
switch_core_speech_close(&sh, &flags);
|
||||
switch_core_codec_destroy(&speech_codec);
|
||||
|
||||
@@ -659,7 +637,7 @@ static const switch_application_interface_t rss_application_interface = {
|
||||
/*.application_function */ rss_function,
|
||||
NULL, NULL, NULL,
|
||||
/* flags */ SAF_NONE,
|
||||
/*.next*/ NULL
|
||||
/*.next */ NULL
|
||||
};
|
||||
|
||||
|
||||
@@ -677,7 +655,8 @@ static switch_loadable_module_interface_t rss_module_interface = {
|
||||
};
|
||||
|
||||
|
||||
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
|
||||
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
|
||||
char *filename)
|
||||
{
|
||||
/* connect my internal structure to the blank pointer passed to me */
|
||||
*module_interface = &rss_module_interface;
|
||||
|
||||
@@ -47,7 +47,8 @@ static switch_loadable_module_interface_t skel_module_interface = {
|
||||
/*.directory_interface */ NULL
|
||||
};
|
||||
|
||||
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
|
||||
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
|
||||
char *filename)
|
||||
{
|
||||
/* connect my internal structure to the blank pointer passed to me */
|
||||
*module_interface = &skel_module_interface;
|
||||
|
||||
Reference in new issue
Block a user