提交 c822f941 authored 作者: Michael Jerris's avatar Michael Jerris

add syntax to api structures, use them for usage returns, do more checking on…

add syntax to api structures, use them for usage returns, do more checking on valid usage and cleanup some output of api commands.

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@3001 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 2b53e80e
...@@ -34,6 +34,16 @@ ...@@ -34,6 +34,16 @@
#include <switch.h> #include <switch.h>
static const char modname[] = "mod_commands"; static const char modname[] = "mod_commands";
static switch_api_interface_t ctl_api_interface;
static switch_api_interface_t uuid_bridge_api_interface;
static switch_api_interface_t status_api_interface;
static switch_api_interface_t show_api_interface;
static switch_api_interface_t pause_api_interface;
static switch_api_interface_t transfer_api_interface;
static switch_api_interface_t load_api_interface;
static switch_api_interface_t reload_api_interface;
static switch_api_interface_t kill_api_interface;
static switch_api_interface_t originate_api_interface;
static switch_status_t status_function(char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) static switch_status_t status_function(char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream)
{ {
...@@ -94,7 +104,7 @@ static switch_status_t ctl_function(char *data, switch_core_session_t *session, ...@@ -94,7 +104,7 @@ static switch_status_t ctl_function(char *data, switch_core_session_t *session,
uint32_t arg = 0; uint32_t arg = 0;
if (switch_strlen_zero(data)) { if (switch_strlen_zero(data)) {
stream->write_function(stream, "USAGE: fsctl [hupall|pause|resume|shutdown]\n"); stream->write_function(stream, "USAGE: %s\n", ctl_api_interface.syntax);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
...@@ -137,7 +147,7 @@ static switch_status_t load_function(char *mod, switch_core_session_t *session, ...@@ -137,7 +147,7 @@ static switch_status_t load_function(char *mod, switch_core_session_t *session,
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
if (switch_strlen_zero(mod)) { if (switch_strlen_zero(mod)) {
stream->write_function(stream, "USAGE: load <mod_name>\n"); stream->write_function(stream, "USAGE: %s\n", load_api_interface.syntax);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
switch_loadable_module_load_module((char *) SWITCH_GLOBAL_dirs.mod_dir, (char *) mod); switch_loadable_module_load_module((char *) SWITCH_GLOBAL_dirs.mod_dir, (char *) mod);
...@@ -172,7 +182,7 @@ static switch_status_t kill_function(char *dest, switch_core_session_t *isession ...@@ -172,7 +182,7 @@ static switch_status_t kill_function(char *dest, switch_core_session_t *isession
} }
if (!dest) { if (!dest) {
stream->write_function(stream, "USAGE: killchan <uuid>\n"); stream->write_function(stream, "USAGE: %s\n", kill_api_interface.syntax);
} else if ((session = switch_core_session_locate(dest))) { } else if ((session = switch_core_session_locate(dest))) {
switch_channel_t *channel = switch_core_session_get_channel(session); switch_channel_t *channel = switch_core_session_get_channel(session);
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
...@@ -199,7 +209,7 @@ static switch_status_t transfer_function(char *cmd, switch_core_session_t *isess ...@@ -199,7 +209,7 @@ static switch_status_t transfer_function(char *cmd, switch_core_session_t *isess
argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
if (argc < 2 || argc > 4) { if (argc < 2 || argc > 4) {
stream->write_function(stream, "USAGE: transfer <uuid> <dest-exten> [<dialplan>] [<context>]\n"); stream->write_function(stream, "USAGE: %s\n", transfer_api_interface.syntax);
} else { } else {
char *uuid = argv[0]; char *uuid = argv[0];
char *dest = argv[1]; char *dest = argv[1];
...@@ -238,7 +248,7 @@ static switch_status_t uuid_bridge_function(char *cmd, switch_core_session_t *is ...@@ -238,7 +248,7 @@ static switch_status_t uuid_bridge_function(char *cmd, switch_core_session_t *is
argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
if (argc != 2) { if (argc != 2) {
stream->write_function(stream, "Invalid Parameters\nUSAGE: uuid_bridge <uuid> <other_uuid>\n"); stream->write_function(stream, "USAGE: %s\n", uuid_bridge_api_interface.syntax);
} else { } else {
if (switch_ivr_uuid_bridge(argv[0], argv[1]) != SWITCH_STATUS_SUCCESS) { if (switch_ivr_uuid_bridge(argv[0], argv[1]) != SWITCH_STATUS_SUCCESS) {
stream->write_function(stream, "Invalid uuid\n"); stream->write_function(stream, "Invalid uuid\n");
...@@ -263,7 +273,7 @@ static switch_status_t pause_function(char *cmd, switch_core_session_t *isession ...@@ -263,7 +273,7 @@ static switch_status_t pause_function(char *cmd, switch_core_session_t *isession
argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
if (argc < 2) { if (argc < 2) {
stream->write_function(stream, "USAGE: pause <uuid> <on|off>\n"); stream->write_function(stream, "USAGE: %s\n", pause_api_interface.syntax);
} else { } else {
char *uuid = argv[0]; char *uuid = argv[0];
char *dest = argv[1]; char *dest = argv[1];
...@@ -301,13 +311,13 @@ static switch_status_t originate_function(char *cmd, switch_core_session_t *ises ...@@ -301,13 +311,13 @@ static switch_status_t originate_function(char *cmd, switch_core_session_t *ises
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
if (switch_strlen_zero(cmd) || argc < 2 || argc > 7) { if (switch_strlen_zero(cmd) || argc < 2 || argc > 7) {
stream->write_function(stream, "USAGE: originate <call url> <exten>|&<application_name>(<app_args>) [<dialplan>] [<context>] [<cid_name>] [<cid_num>] [<timeout_sec>]\n"); stream->write_function(stream, "USAGE: %s\n", originate_api_interface.syntax);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
for(x = 0; x < argc; x++) { for(x = 0; x < argc; x++) {
if (!strcasecmp(argv[x], "undef")) { if (!strcasecmp(argv[x], "undef")) {
argv[x] = NULL; argv[x] = NULL;
...@@ -333,11 +343,6 @@ static switch_status_t originate_function(char *cmd, switch_core_session_t *ises ...@@ -333,11 +343,6 @@ static switch_status_t originate_function(char *cmd, switch_core_session_t *ises
timeout = atoi(argv[6]); timeout = atoi(argv[6]);
} }
if (!aleg || !exten) {
stream->write_function(stream, "Invalid Arguements\n");
return SWITCH_STATUS_SUCCESS;
}
if (switch_ivr_originate(NULL, &caller_session, &cause, aleg, timeout, &noop_state_handler, cid_name, cid_num, NULL) != SWITCH_STATUS_SUCCESS) { if (switch_ivr_originate(NULL, &caller_session, &cause, aleg, timeout, &noop_state_handler, cid_name, cid_num, NULL) != SWITCH_STATUS_SUCCESS) {
stream->write_function(stream, "Cannot Create Outgoing Channel! [%s]\n", aleg); stream->write_function(stream, "Cannot Create Outgoing Channel! [%s]\n", aleg);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
...@@ -347,7 +352,6 @@ static switch_status_t originate_function(char *cmd, switch_core_session_t *ises ...@@ -347,7 +352,6 @@ static switch_status_t originate_function(char *cmd, switch_core_session_t *ises
assert(caller_channel != NULL); assert(caller_channel != NULL);
switch_channel_clear_state_handler(caller_channel, NULL); switch_channel_clear_state_handler(caller_channel, NULL);
if (*exten == '&') { if (*exten == '&') {
switch_caller_extension_t *extension = NULL; switch_caller_extension_t *extension = NULL;
char *app_name = switch_core_session_strdup(caller_session, (exten + 1)); char *app_name = switch_core_session_strdup(caller_session, (exten + 1));
...@@ -453,9 +457,7 @@ static switch_status_t show_function(char *cmd, switch_core_session_t *session, ...@@ -453,9 +457,7 @@ static switch_status_t show_function(char *cmd, switch_core_session_t *session,
sprintf (sql, "select * from channels"); sprintf (sql, "select * from channels");
} }
else { else {
stream->write_function(stream, "Invalid interfaces type!\n"); stream->write_function(stream, "USAGE: %s\n", show_api_interface.syntax);
stream->write_function(stream, "USAGE:\n");
stream->write_function(stream, "show <blank>|codec|application|api|dialplan|file|timer|calls|channels\n");
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
...@@ -491,7 +493,7 @@ static switch_api_interface_t ctl_api_interface = { ...@@ -491,7 +493,7 @@ static switch_api_interface_t ctl_api_interface = {
/*.interface_name */ "fsctl", /*.interface_name */ "fsctl",
/*.desc */ "control messages", /*.desc */ "control messages",
/*.function */ ctl_function, /*.function */ ctl_function,
/*.syntax */ NULL, /*.syntax */ "fsctl [hupall|pause|resume|shutdown]",
/*.next */ /*.next */
}; };
...@@ -499,7 +501,7 @@ static switch_api_interface_t uuid_bridge_api_interface = { ...@@ -499,7 +501,7 @@ static switch_api_interface_t uuid_bridge_api_interface = {
/*.interface_name */ "uuid_bridge", /*.interface_name */ "uuid_bridge",
/*.desc */ "uuid_bridge", /*.desc */ "uuid_bridge",
/*.function */ uuid_bridge_function, /*.function */ uuid_bridge_function,
/*.syntax */ NULL, /*.syntax */ "uuid_bridge <uuid> <other_uuid>",
/*.next */ &ctl_api_interface /*.next */ &ctl_api_interface
}; };
...@@ -507,7 +509,7 @@ static switch_api_interface_t status_api_interface = { ...@@ -507,7 +509,7 @@ static switch_api_interface_t status_api_interface = {
/*.interface_name */ "status", /*.interface_name */ "status",
/*.desc */ "status", /*.desc */ "status",
/*.function */ status_function, /*.function */ status_function,
/*.syntax */ NULL, /*.syntax */ "status",
/*.next */ &uuid_bridge_api_interface /*.next */ &uuid_bridge_api_interface
}; };
...@@ -515,7 +517,7 @@ static switch_api_interface_t show_api_interface = { ...@@ -515,7 +517,7 @@ static switch_api_interface_t show_api_interface = {
/*.interface_name */ "show", /*.interface_name */ "show",
/*.desc */ "Show", /*.desc */ "Show",
/*.function */ show_function, /*.function */ show_function,
/*.syntax */ NULL, /*.syntax */ "show <blank>|codec|application|api|dialplan|file|timer|calls|channels",
/*.next */ &status_api_interface /*.next */ &status_api_interface
}; };
...@@ -523,7 +525,7 @@ static switch_api_interface_t pause_api_interface = { ...@@ -523,7 +525,7 @@ static switch_api_interface_t pause_api_interface = {
/*.interface_name */ "pause", /*.interface_name */ "pause",
/*.desc */ "Pause", /*.desc */ "Pause",
/*.function */ pause_function, /*.function */ pause_function,
/*.syntax */ NULL, /*.syntax */ "pause <uuid> <on|off>",
/*.next */ &show_api_interface /*.next */ &show_api_interface
}; };
...@@ -531,7 +533,7 @@ static switch_api_interface_t transfer_api_interface = { ...@@ -531,7 +533,7 @@ static switch_api_interface_t transfer_api_interface = {
/*.interface_name */ "transfer", /*.interface_name */ "transfer",
/*.desc */ "Transfer", /*.desc */ "Transfer",
/*.function */ transfer_function, /*.function */ transfer_function,
/*.syntax */ NULL, /*.syntax */ "transfer <uuid> <dest-exten> [<dialplan>] [<context>]",
/*.next */ &pause_api_interface /*.next */ &pause_api_interface
}; };
...@@ -539,7 +541,7 @@ static switch_api_interface_t load_api_interface = { ...@@ -539,7 +541,7 @@ static switch_api_interface_t load_api_interface = {
/*.interface_name */ "load", /*.interface_name */ "load",
/*.desc */ "Load Module", /*.desc */ "Load Module",
/*.function */ load_function, /*.function */ load_function,
/*.syntax */ NULL, /*.syntax */ "load <mod_name>",
/*.next */ &transfer_api_interface /*.next */ &transfer_api_interface
}; };
...@@ -547,16 +549,16 @@ static switch_api_interface_t reload_api_interface = { ...@@ -547,16 +549,16 @@ static switch_api_interface_t reload_api_interface = {
/*.interface_name */ "reloadxml", /*.interface_name */ "reloadxml",
/*.desc */ "Reload XML", /*.desc */ "Reload XML",
/*.function */ reload_function, /*.function */ reload_function,
/*.syntax */ NULL, /*.syntax */ "reloadxml",
/*.next */ &load_api_interface, /*.next */ &load_api_interface,
}; };
static switch_api_interface_t commands_api_interface = { static switch_api_interface_t kill_api_interface = {
/*.interface_name */ "killchan", /*.interface_name */ "killchan",
/*.desc */ "Kill Channel", /*.desc */ "Kill Channel",
/*.function */ kill_function, /*.function */ kill_function,
/*.syntax */ NULL, /*.syntax */ "killchan <uuid>",
/*.next */ &reload_api_interface /*.next */ &reload_api_interface
}; };
...@@ -564,8 +566,8 @@ static switch_api_interface_t originate_api_interface = { ...@@ -564,8 +566,8 @@ static switch_api_interface_t originate_api_interface = {
/*.interface_name */ "originate", /*.interface_name */ "originate",
/*.desc */ "Originate a Call", /*.desc */ "Originate a Call",
/*.function */ originate_function, /*.function */ originate_function,
/*.syntax */ NULL, /*.syntax */ "originate <call url> <exten>|&<application_name>(<app_args>) [<dialplan>] [<context>] [<cid_name>] [<cid_num>] [<timeout_sec>]",
/*.next */ &commands_api_interface /*.next */ &kill_api_interface
}; };
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
static const char modname[] = "mod_conference"; static const char modname[] = "mod_conference";
static const char global_app_name[] = "conference"; static const char global_app_name[] = "conference";
static char *global_cf_name = "conference.conf"; static char *global_cf_name = "conference.conf";
static switch_api_interface_t conf_api_interface;
/* Size to allocate for audio buffers */ /* Size to allocate for audio buffers */
#define CONF_BUFFER_SIZE 1024 * 128 #define CONF_BUFFER_SIZE 1024 * 128
...@@ -1317,29 +1318,6 @@ static switch_status_t conf_function(char *buf, switch_core_session_t *session, ...@@ -1317,29 +1318,6 @@ static switch_status_t conf_function(char *buf, switch_core_session_t *session,
char *lbuf = NULL; char *lbuf = NULL;
switch_status_t status = SWITCH_STATUS_SUCCESS; switch_status_t status = SWITCH_STATUS_SUCCESS;
char *http = NULL; char *http = NULL;
char *topusage = "Available Commands:\n"
"--------------------------------------------------------------------------------\n"
"conference commands\n"
"conference list [delim <string>]\n"
"conference <confname> list [delim <string>]\n"
"conference <confname> energy <member_id> [<newval>]\n"
"conference <confname> volume_in <member_id> [<newval>]\n"
"conference <confname> volume_out <member_id> [<newval>]\n"
"conference <confname> play <file_path> [<member_id>]\n"
"conference <confname> say <text>\n"
"conference <confname> saymember <member_id><text>\n"
"conference <confname> stop <[current|all]> [<member_id>]\n"
"conference <confname> kick <member_id>\n"
"conference <confname> mute <member_id>\n"
"conference <confname> unmute <member_id>\n"
"conference <confname> deaf <member_id>\n"
"conference <confname> undef <member_id>\n"
"conference <confname> relate <member_id> <other_member_id> [nospeak|nohear]\n"
"conference <confname> lock\n"
"conference <confname> unlock\n"
"conference <confname> dial <endpoint_module_name>/<destination>\n"
"conference <confname> transfer <member_id> <conference_name>\n"
;
if (session) { if (session) {
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
...@@ -1355,7 +1333,7 @@ static switch_status_t conf_function(char *buf, switch_core_session_t *session, ...@@ -1355,7 +1333,7 @@ static switch_status_t conf_function(char *buf, switch_core_session_t *session,
} }
if (!buf) { if (!buf) {
stream->write_function(stream, topusage); stream->write_function(stream, "%s", conf_api_interface.syntax);
return status; return status;
} }
...@@ -1370,7 +1348,7 @@ static switch_status_t conf_function(char *buf, switch_core_session_t *session, ...@@ -1370,7 +1348,7 @@ static switch_status_t conf_function(char *buf, switch_core_session_t *session,
/* Figure out what conference */ /* Figure out what conference */
if (argc) { if (argc) {
if (!strcasecmp(argv[0], "commands")) { if (!strcasecmp(argv[0], "commands")) {
stream->write_function(stream, topusage); stream->write_function(stream, "%s", conf_api_interface.syntax);
goto done; goto done;
} else if (!strcasecmp(argv[0], "list")) { } else if (!strcasecmp(argv[0], "list")) {
switch_hash_index_t *hi; switch_hash_index_t *hi;
...@@ -2020,7 +1998,7 @@ static switch_status_t conf_function(char *buf, switch_core_session_t *session, ...@@ -2020,7 +1998,7 @@ static switch_status_t conf_function(char *buf, switch_core_session_t *session,
goto done; goto done;
} }
} else { } else {
stream->write_function(stream, topusage); stream->write_function(stream, "USAGE: %s\n", conf_api_interface.syntax);
} }
} else { } else {
stream->write_function(stream, "Memory Error!\n"); stream->write_function(stream, "Memory Error!\n");
...@@ -2666,7 +2644,27 @@ static switch_api_interface_t conf_api_interface = { ...@@ -2666,7 +2644,27 @@ static switch_api_interface_t conf_api_interface = {
/*.interface_name */ "conference", /*.interface_name */ "conference",
/*.desc */ "Conference", /*.desc */ "Conference",
/*.function */ conf_function, /*.function */ conf_function,
/*.syntax */ NULL, /*.syntax */
"conference commands\n"
"conference list [delim <string>]\n"
"conference <confname> list [delim <string>]\n"
"conference <confname> energy <member_id> [<newval>]\n"
"conference <confname> volume_in <member_id> [<newval>]\n"
"conference <confname> volume_out <member_id> [<newval>]\n"
"conference <confname> play <file_path> [<member_id>]\n"
"conference <confname> say <text>\n"
"conference <confname> saymember <member_id><text>\n"
"conference <confname> stop <[current|all]> [<member_id>]\n"
"conference <confname> kick <member_id>\n"
"conference <confname> mute <member_id>\n"
"conference <confname> unmute <member_id>\n"
"conference <confname> deaf <member_id>\n"
"conference <confname> undef <member_id>\n"
"conference <confname> relate <member_id> <other_member_id> [nospeak|nohear]\n"
"conference <confname> lock\n"
"conference <confname> unlock\n"
"conference <confname> dial <endpoint_module_name>/<destination>\n"
"conference <confname> transfer <member_id> <conference_name>\n",
/*.next */ /*.next */
}; };
......
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
static const char modname[] = "mod_dptools"; static const char modname[] = "mod_dptools";
static void transfer_function(switch_core_session_t *session, char *data) static void transfer_function(switch_core_session_t *session, char *data)
{ {
int argc; int argc;
...@@ -133,7 +132,7 @@ static switch_api_interface_t dptools_api_interface = { ...@@ -133,7 +132,7 @@ static switch_api_interface_t dptools_api_interface = {
/*.interface_name */ "strftime", /*.interface_name */ "strftime",
/*.desc */ "strftime", /*.desc */ "strftime",
/*.function */ strftime_api_function, /*.function */ strftime_api_function,
/*.syntax */ NULL, /*.syntax */ "strftime <format_string>",
/*.next */ NULL /*.next */ NULL
}; };
......
...@@ -1071,7 +1071,7 @@ static switch_api_interface_t logout_api_interface = { ...@@ -1071,7 +1071,7 @@ static switch_api_interface_t logout_api_interface = {
/*.interface_name */ "dl_logout", /*.interface_name */ "dl_logout",
/*.desc */ "DingaLing Logout", /*.desc */ "DingaLing Logout",
/*.function */ dl_logout, /*.function */ dl_logout,
/*.syntax */ NULL, /*.syntax */ "dl_logout <profile_name>",
/*.next */ NULL /*.next */ NULL
}; };
...@@ -1079,7 +1079,7 @@ static switch_api_interface_t login_api_interface = { ...@@ -1079,7 +1079,7 @@ static switch_api_interface_t login_api_interface = {
/*.interface_name */ "dl_login", /*.interface_name */ "dl_login",
/*.desc */ "DingaLing Login", /*.desc */ "DingaLing Login",
/*.function */ dl_login, /*.function */ dl_login,
/*.syntax */ NULL, /*.syntax */ "dl_login <profile_name>",
/*.next */ &logout_api_interface /*.next */ &logout_api_interface
}; };
...@@ -1400,7 +1400,7 @@ static switch_status_t dl_logout(char *profile_name, switch_core_session_t *sess ...@@ -1400,7 +1400,7 @@ static switch_status_t dl_logout(char *profile_name, switch_core_session_t *sess
} }
if (!profile_name) { if (!profile_name) {
stream->write_function(stream, "NO PROFILE NAME SPECIFIED\n"); stream->write_function(stream, "USAGE: %s\n", logout_api_interface.syntax);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
...@@ -1426,15 +1426,15 @@ static switch_status_t dl_login(char *arg, switch_core_session_t *session, switc ...@@ -1426,15 +1426,15 @@ static switch_status_t dl_login(char *arg, switch_core_session_t *session, switc
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
if (switch_strlen_zero(arg)) {
stream->write_function(stream, "FAIL\n");
return SWITCH_STATUS_SUCCESS;
}
myarg = strdup(arg); myarg = strdup(arg);
argc = switch_separate_string(myarg, ';', argv, (sizeof(argv) / sizeof(argv[0]))); argc = switch_separate_string(myarg, ';', argv, (sizeof(argv) / sizeof(argv[0])));
if (switch_strlen_zero(arg) || argc != 1) {
stream->write_function(stream, "USAGE: %s\n", login_api_interface.syntax);
return SWITCH_STATUS_SUCCESS;
}
if (!strncasecmp(argv[0], "profile=", 8)) { if (!strncasecmp(argv[0], "profile=", 8)) {
char *profile_name = argv[0] + 8; char *profile_name = argv[0] + 8;
profile = switch_core_hash_find(globals.profile_hash, profile_name); profile = switch_core_hash_find(globals.profile_hash, profile_name);
......
...@@ -440,7 +440,7 @@ static switch_api_interface_t send_dtmf_interface = { ...@@ -440,7 +440,7 @@ static switch_api_interface_t send_dtmf_interface = {
/*.interface_name */ "padtmf", /*.interface_name */ "padtmf",
/*.desc */ "PortAudio Dial DTMF", /*.desc */ "PortAudio Dial DTMF",
/*.function */ send_dtmf, /*.function */ send_dtmf,
/*.syntax */ NULL, /*.syntax */ "padtmf <callid> <dtmf_digits>",
/*.next */ NULL /*.next */ NULL
}; };
...@@ -448,7 +448,7 @@ static switch_api_interface_t answer_call_interface = { ...@@ -448,7 +448,7 @@ static switch_api_interface_t answer_call_interface = {
/*.interface_name */ "paoffhook", /*.interface_name */ "paoffhook",
/*.desc */ "PortAudio Answer Call", /*.desc */ "PortAudio Answer Call",
/*.function */ answer_call, /*.function */ answer_call,
/*.syntax */ NULL, /*.syntax */ "paoffhook",
/*.next */ &send_dtmf_interface /*.next */ &send_dtmf_interface
}; };
...@@ -456,7 +456,7 @@ static switch_api_interface_t channel_info_interface = { ...@@ -456,7 +456,7 @@ static switch_api_interface_t channel_info_interface = {
/*.interface_name */ "painfo", /*.interface_name */ "painfo",
/*.desc */ "PortAudio Call Info", /*.desc */ "PortAudio Call Info",
/*.function */ call_info, /*.function */ call_info,
/*.syntax */ NULL, /*.syntax */ "painfo",
/*.next */ &answer_call_interface /*.next */ &answer_call_interface
}; };
...@@ -464,7 +464,7 @@ static switch_api_interface_t channel_hup_interface = { ...@@ -464,7 +464,7 @@ static switch_api_interface_t channel_hup_interface = {
/*.interface_name */ "pahup", /*.interface_name */ "pahup",
/*.desc */ "PortAudio Hangup Call", /*.desc */ "PortAudio Hangup Call",
/*.function */ hup_call, /*.function */ hup_call,
/*.syntax */ NULL, /*.syntax */ "pahup [call_number]",
/*.next */ &channel_info_interface /*.next */ &channel_info_interface
}; };
...@@ -472,7 +472,7 @@ static switch_api_interface_t channel_api_interface = { ...@@ -472,7 +472,7 @@ static switch_api_interface_t channel_api_interface = {
/*.interface_name */ "pacall", /*.interface_name */ "pacall",
/*.desc */ "PortAudio Call", /*.desc */ "PortAudio Call",
/*.function */ place_call, /*.function */ place_call,
/*.syntax */ NULL, /*.syntax */ "pacall <exten>",
/*.next */ &channel_hup_interface /*.next */ &channel_hup_interface
}; };
...@@ -837,11 +837,9 @@ static switch_status_t place_call(char *dest, switch_core_session_t *isession, s ...@@ -837,11 +837,9 @@ static switch_status_t place_call(char *dest, switch_core_session_t *isession, s
} }
if (!dest) { if (!dest) {
stream->write_function(stream, "Usage: pacall <exten>"); stream->write_function(stream, "Usage: %s\n", channel_api_interface.syntax);
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
stream->write_function(stream, "FAIL");
if ((session = switch_core_session_request(&channel_endpoint_interface, NULL)) != 0) { if ((session = switch_core_session_request(&channel_endpoint_interface, NULL)) != 0) {
struct private_object *tech_pvt; struct private_object *tech_pvt;
...@@ -878,6 +876,8 @@ static switch_status_t place_call(char *dest, switch_core_session_t *isession, s ...@@ -878,6 +876,8 @@ static switch_status_t place_call(char *dest, switch_core_session_t *isession, s
switch_channel_set_state(channel, CS_INIT); switch_channel_set_state(channel, CS_INIT);
switch_core_session_thread_launch(tech_pvt->session); switch_core_session_thread_launch(tech_pvt->session);
stream->write_function(stream, "SUCCESS:%s:%s", tech_pvt->call_id, switch_core_session_get_uuid(tech_pvt->session)); stream->write_function(stream, "SUCCESS:%s:%s", tech_pvt->call_id, switch_core_session_get_uuid(tech_pvt->session));
} else {
stream->write_function(stream, "FAIL\n");
} }
} }
return status; return status;
...@@ -936,16 +936,17 @@ static switch_status_t send_dtmf(char *callid, switch_core_session_t *session, s ...@@ -936,16 +936,17 @@ static switch_status_t send_dtmf(char *callid, switch_core_session_t *session, s
{ {
struct private_object *tech_pvt = NULL; struct private_object *tech_pvt = NULL;
switch_channel_t *channel = NULL; switch_channel_t *channel = NULL;
char *dtmf; char *dtmf = NULL;
if (session) { if (session) {
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
if ((dtmf = strchr(callid, ' ')) != 0) { if (switch_strlen_zero(callid) || (dtmf = strchr(callid, ' ')) == 0) {
*dtmf++ = '\0'; stream->write_function(stream, "USAGE: %s\n", send_dtmf_interface.syntax);
return SWITCH_STATUS_SUCCESS;
} else { } else {
dtmf = ""; *dtmf++ = '\0';
} }
if ((tech_pvt = switch_core_hash_find(globals.call_hash, callid)) != 0) { if ((tech_pvt = switch_core_hash_find(globals.call_hash, callid)) != 0) {
......
...@@ -69,6 +69,7 @@ static const char modname[] = "mod_spidermonkey"; ...@@ -69,6 +69,7 @@ static const char modname[] = "mod_spidermonkey";
static int eval_some_js(char *code, JSContext *cx, JSObject *obj, jsval *rval); static int eval_some_js(char *code, JSContext *cx, JSObject *obj, jsval *rval);
static void session_destroy(JSContext *cx, JSObject *obj); static void session_destroy(JSContext *cx, JSObject *obj);
static JSBool session_construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); static JSBool session_construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static switch_api_interface_t js_run_interface;
static struct { static struct {
size_t gStackChunkSize; size_t gStackChunkSize;
...@@ -2675,12 +2676,12 @@ static switch_status_t launch_async(char *text, switch_core_session_t *session, ...@@ -2675,12 +2676,12 @@ static switch_status_t launch_async(char *text, switch_core_session_t *session,
{ {
if (switch_strlen_zero(text)) { if (switch_strlen_zero(text)) {
stream->write_function(stream, "INVALID"); stream->write_function(stream, "USAGE: %s\n", js_run_interface.syntax);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
js_thread_launch(text); js_thread_launch(text);
stream->write_function(stream, "OK"); stream->write_function(stream, "OK\n");
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
...@@ -2696,7 +2697,7 @@ static switch_api_interface_t js_run_interface = { ...@@ -2696,7 +2697,7 @@ static switch_api_interface_t js_run_interface = {
/*.interface_name */ "jsrun", /*.interface_name */ "jsrun",
/*.desc */ "run a script", /*.desc */ "run a script",
/*.function */ launch_async, /*.function */ launch_async,
/*.syntax */ NULL, /*.syntax */ "jsrun <script>",
/*.next */ NULL /*.next */ NULL
}; };
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论