Originate calls via the CLI. More...
#include "asterisk.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/cli.h"
#include "asterisk/utils.h"
#include "asterisk/frame.h"
Go to the source code of this file.
Defines | |
#define | TIMEOUT 30 |
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
ASTERISK_FILE_VERSION (__FILE__,"$Revision: 361471 $") | |
static char * | handle_orig (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
handle for orgination app or exten. | |
static char * | handle_redirect (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static int | load_module (void) |
static char * | orig_app (int fd, const char *chan, const char *app, const char *appdata) |
orginate a call from the CLI | |
static char * | orig_exten (int fd, const char *chan, const char *data) |
orginate from extension | |
static int | unload_module (void) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Call origination and redirection from the CLI" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } |
static struct ast_module_info * | ast_module_info = &__mod_info |
static struct ast_cli_entry | cli_cliorig [] |
Originate calls via the CLI.
Definition in file res_clioriginate.c.
#define TIMEOUT 30 |
The timeout for originated calls, in seconds
Definition at line 43 of file res_clioriginate.c.
Referenced by orig_app(), and orig_exten().
static void __reg_module | ( | void | ) | [static] |
Definition at line 243 of file res_clioriginate.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 243 of file res_clioriginate.c.
ASTERISK_FILE_VERSION | ( | __FILE__ | , | |
"$Revision: 361471 $" | ||||
) |
static char* handle_orig | ( | struct ast_cli_entry * | e, | |
int | cmd, | |||
struct ast_cli_args * | a | |||
) | [static] |
handle for orgination app or exten.
e | pointer to the CLI structure to initialize | |
cmd | operation to execute | |
a | structure that contains either application or extension arguments |
CLI_SUCCESS | on success. | |
CLI_SHOWUSAGE | on failure. |
Definition at line 122 of file res_clioriginate.c.
References ast_cli_args::argv, ast_cli_complete(), ast_complete_applications(), ast_module_ref(), ast_module_unref(), ast_strlen_zero(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, ast_cli_entry::command, ast_cli_args::fd, ast_cli_args::line, ast_cli_args::n, orig_app(), orig_exten(), ast_cli_args::pos, ast_cli_entry::usage, and ast_cli_args::word.
00123 { 00124 static const char * const choices[] = { "application", "extension", NULL }; 00125 char *res = NULL; 00126 switch (cmd) { 00127 case CLI_INIT: 00128 e->command = "channel originate"; 00129 e->usage = 00130 " There are two ways to use this command. A call can be originated between a\n" 00131 "channel and a specific application, or between a channel and an extension in\n" 00132 "the dialplan. This is similar to call files or the manager originate action.\n" 00133 "Calls originated with this command are given a timeout of 30 seconds.\n\n" 00134 00135 "Usage1: channel originate <tech/data> application <appname> [appdata]\n" 00136 " This will originate a call between the specified channel tech/data and the\n" 00137 "given application. Arguments to the application are optional. If the given\n" 00138 "arguments to the application include spaces, all of the arguments to the\n" 00139 "application need to be placed in quotation marks.\n\n" 00140 00141 "Usage2: channel originate <tech/data> extension [exten@][context]\n" 00142 " This will originate a call between the specified channel tech/data and the\n" 00143 "given extension. If no context is specified, the 'default' context will be\n" 00144 "used. If no extension is given, the 's' extension will be used.\n"; 00145 return NULL; 00146 case CLI_GENERATE: 00147 /* ugly, can be removed when CLI entries have ast_module pointers */ 00148 ast_module_ref(ast_module_info->self); 00149 if (a->pos == 3) { 00150 res = ast_cli_complete(a->word, choices, a->n); 00151 } else if (a->pos == 4) { 00152 if (!strcasecmp("application", a->argv[3])) { 00153 res = ast_complete_applications(a->line, a->word, a->n); 00154 } 00155 } 00156 ast_module_unref(ast_module_info->self); 00157 return res; 00158 } 00159 00160 if (ast_strlen_zero(a->argv[2]) || ast_strlen_zero(a->argv[3])) 00161 return CLI_SHOWUSAGE; 00162 00163 /* ugly, can be removed when CLI entries have ast_module pointers */ 00164 ast_module_ref(ast_module_info->self); 00165 00166 if (!strcasecmp("application", a->argv[3])) { 00167 res = orig_app(a->fd, a->argv[2], a->argv[4], a->argv[5]); 00168 } else if (!strcasecmp("extension", a->argv[3])) { 00169 res = orig_exten(a->fd, a->argv[2], a->argv[4]); 00170 } else { 00171 res = CLI_SHOWUSAGE; 00172 } 00173 00174 ast_module_unref(ast_module_info->self); 00175 00176 return res; 00177 }
static char* handle_redirect | ( | struct ast_cli_entry * | e, | |
int | cmd, | |||
struct ast_cli_args * | a | |||
) | [static] |
Definition at line 179 of file res_clioriginate.c.
References ast_cli_args::argc, ast_cli_entry::args, ast_cli_args::argv, ast_async_parseable_goto(), ast_channel_get_by_name(), ast_channel_unref, ast_cli(), ast_complete_channels(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, ast_cli_args::line, ast_cli_args::n, name, ast_cli_args::pos, ast_cli_entry::usage, and ast_cli_args::word.
00180 { 00181 const char *name, *dest; 00182 struct ast_channel *chan; 00183 int res; 00184 00185 switch (cmd) { 00186 case CLI_INIT: 00187 e->command = "channel redirect"; 00188 e->usage = "" 00189 "Usage: channel redirect <channel> <[[context,]exten,]priority>\n" 00190 " Redirect an active channel to a specified extension.\n"; 00191 /*! \todo It would be nice to be able to redirect 2 channels at the same 00192 * time like you can with AMI redirect. However, it is not possible to acquire 00193 * two channels without the potential for a deadlock with how ast_channel structs 00194 * are managed today. Once ast_channel is a refcounted object, this command 00195 * will be able to support that. */ 00196 return NULL; 00197 case CLI_GENERATE: 00198 return ast_complete_channels(a->line, a->word, a->pos, a->n, 2); 00199 } 00200 00201 if (a->argc != e->args + 2) { 00202 return CLI_SHOWUSAGE; 00203 } 00204 00205 name = a->argv[2]; 00206 dest = a->argv[3]; 00207 00208 if (!(chan = ast_channel_get_by_name(name))) { 00209 ast_cli(a->fd, "Channel '%s' not found\n", name); 00210 return CLI_FAILURE; 00211 } 00212 00213 res = ast_async_parseable_goto(chan, dest); 00214 00215 chan = ast_channel_unref(chan); 00216 00217 if (!res) { 00218 ast_cli(a->fd, "Channel '%s' successfully redirected to %s\n", name, dest); 00219 } else { 00220 ast_cli(a->fd, "Channel '%s' failed to be redirected to %s\n", name, dest); 00221 } 00222 00223 return res ? CLI_FAILURE : CLI_SUCCESS; 00224 }
static int load_module | ( | void | ) | [static] |
Definition at line 236 of file res_clioriginate.c.
References ARRAY_LEN, ast_cli_register_multiple(), AST_MODULE_LOAD_DECLINE, and AST_MODULE_LOAD_SUCCESS.
00237 { 00238 int res; 00239 res = ast_cli_register_multiple(cli_cliorig, ARRAY_LEN(cli_cliorig)); 00240 return res ? AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS; 00241 }
static char* orig_app | ( | int | fd, | |
const char * | chan, | |||
const char * | app, | |||
const char * | appdata | |||
) | [static] |
orginate a call from the CLI
fd | file descriptor for cli | |
chan | channel to create type/data | |
app | application you want to run | |
appdata | data for application |
CLI_SUCCESS | on success. | |
CLI_SHOWUSAGE | on failure. |
Definition at line 54 of file res_clioriginate.c.
References ast_cli(), AST_FORMAT_SLINEAR, ast_pbx_outgoing_app(), ast_strdupa, ast_strlen_zero(), CLI_SHOWUSAGE, CLI_SUCCESS, and TIMEOUT.
Referenced by handle_orig().
00055 { 00056 char *chantech; 00057 char *chandata; 00058 int reason = 0; 00059 00060 if (ast_strlen_zero(app)) 00061 return CLI_SHOWUSAGE; 00062 00063 chandata = ast_strdupa(chan); 00064 00065 chantech = strsep(&chandata, "/"); 00066 if (!chandata) { 00067 ast_cli(fd, "*** No data provided after channel type! ***\n"); 00068 return CLI_SHOWUSAGE; 00069 } 00070 00071 ast_pbx_outgoing_app(chantech, AST_FORMAT_SLINEAR, chandata, TIMEOUT * 1000, app, appdata, &reason, 0, NULL, NULL, NULL, NULL, NULL); 00072 00073 return CLI_SUCCESS; 00074 }
static char* orig_exten | ( | int | fd, | |
const char * | chan, | |||
const char * | data | |||
) | [static] |
orginate from extension
fd | file descriptor for cli | |
chan | channel to create type/data | |
data | contains exten@context |
CLI_SUCCESS | on success. | |
CLI_SHOWUSAGE | on failure. |
Definition at line 84 of file res_clioriginate.c.
References ast_cli(), AST_FORMAT_SLINEAR, ast_pbx_outgoing_exten(), ast_strdupa, ast_strlen_zero(), CLI_SHOWUSAGE, CLI_SUCCESS, context, exten, and TIMEOUT.
Referenced by gosub_exec(), handle_orig(), and park_call_exec().
00085 { 00086 char *chantech; 00087 char *chandata; 00088 char *exten = NULL; 00089 char *context = NULL; 00090 int reason = 0; 00091 00092 chandata = ast_strdupa(chan); 00093 00094 chantech = strsep(&chandata, "/"); 00095 if (!chandata) { 00096 ast_cli(fd, "*** No data provided after channel type! ***\n"); 00097 return CLI_SHOWUSAGE; 00098 } 00099 00100 if (!ast_strlen_zero(data)) { 00101 context = ast_strdupa(data); 00102 exten = strsep(&context, "@"); 00103 } 00104 00105 if (ast_strlen_zero(exten)) 00106 exten = "s"; 00107 if (ast_strlen_zero(context)) 00108 context = "default"; 00109 00110 ast_pbx_outgoing_exten(chantech, AST_FORMAT_SLINEAR, chandata, TIMEOUT * 1000, context, exten, 1, &reason, 0, NULL, NULL, NULL, NULL, NULL); 00111 00112 return CLI_SUCCESS; 00113 }
static int unload_module | ( | void | ) | [static] |
Definition at line 231 of file res_clioriginate.c.
References ARRAY_LEN, and ast_cli_unregister_multiple().
00232 { 00233 return ast_cli_unregister_multiple(cli_cliorig, ARRAY_LEN(cli_cliorig)); 00234 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Call origination and redirection from the CLI" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } [static] |
Definition at line 243 of file res_clioriginate.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 243 of file res_clioriginate.c.
struct ast_cli_entry cli_cliorig[] [static] |
{ AST_CLI_DEFINE(handle_orig, "Originate a call"), AST_CLI_DEFINE(handle_redirect, "Redirect a call"), }
Definition at line 226 of file res_clioriginate.c.