00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "asterisk.h"
00028
00029 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 102378 $");
00030
00031 #include <stdlib.h>
00032 #include <stdio.h>
00033 #include <string.h>
00034
00035 #include "asterisk/channel.h"
00036 #include "asterisk/pbx.h"
00037 #include "asterisk/logger.h"
00038 #include "asterisk/module.h"
00039 #include "asterisk/cli.h"
00040 #include "asterisk/utils.h"
00041 #include "asterisk/frame.h"
00042
00043
00044 #define TIMEOUT 30
00045
00046 static char orig_help[] =
00047 " There are two ways to use this command. A call can be originated between a\n"
00048 "channel and a specific application, or between a channel and an extension in\n"
00049 "the dialplan. This is similar to call files or the manager originate action.\n"
00050 "Calls originated with this command are given a timeout of 30 seconds.\n\n"
00051
00052 "Usage1: originate <tech/data> application <appname> [appdata]\n"
00053 " This will originate a call between the specified channel tech/data and the\n"
00054 "given application. Arguments to the application are optional. If the given\n"
00055 "arguments to the application include spaces, all of the arguments to the\n"
00056 "application need to be placed in quotation marks.\n\n"
00057
00058 "Usage2: originate <tech/data> extension [exten@][context]\n"
00059 " This will originate a call between the specified channel tech/data and the\n"
00060 "given extension. If no context is specified, the 'default' context will be\n"
00061 "used. If no extension is given, the 's' extension will be used.\n";
00062
00063 static int handle_orig(int fd, int argc, char *argv[]);
00064 static char *complete_orig(const char *line, const char *word, int pos, int state);
00065
00066 struct ast_cli_entry cli_cliorig[] = {
00067 { { "originate", NULL },
00068 handle_orig, "Originate a call",
00069 orig_help, complete_orig },
00070 };
00071
00072 static int orig_app(int fd, const char *chan, const char *app, const char *appdata)
00073 {
00074 char *chantech;
00075 char *chandata;
00076 int reason = 0;
00077
00078 if (ast_strlen_zero(app))
00079 return RESULT_SHOWUSAGE;
00080
00081 chandata = ast_strdupa(chan);
00082
00083 chantech = strsep(&chandata, "/");
00084 if (!chandata) {
00085 ast_cli(fd, "*** No data provided after channel type! ***\n");
00086 return RESULT_SHOWUSAGE;
00087 }
00088
00089 ast_pbx_outgoing_app(chantech, AST_FORMAT_SLINEAR, chandata, TIMEOUT * 1000, app, appdata, &reason, 0, NULL, NULL, NULL, NULL, NULL);
00090
00091 return RESULT_SUCCESS;
00092 }
00093
00094 static int orig_exten(int fd, const char *chan, const char *data)
00095 {
00096 char *chantech;
00097 char *chandata;
00098 char *exten = NULL;
00099 char *context = NULL;
00100 int reason = 0;
00101
00102 chandata = ast_strdupa(chan);
00103
00104 chantech = strsep(&chandata, "/");
00105 if (!chandata) {
00106 ast_cli(fd, "*** No data provided after channel type! ***\n");
00107 return RESULT_SHOWUSAGE;
00108 }
00109
00110 if (!ast_strlen_zero(data)) {
00111 context = ast_strdupa(data);
00112 exten = strsep(&context, "@");
00113 }
00114
00115 if (ast_strlen_zero(exten))
00116 exten = "s";
00117 if (ast_strlen_zero(context))
00118 context = "default";
00119
00120 ast_pbx_outgoing_exten(chantech, AST_FORMAT_SLINEAR, chandata, TIMEOUT * 1000, context, exten, 1, &reason, 0, NULL, NULL, NULL, NULL, NULL);
00121
00122 return RESULT_SUCCESS;
00123 }
00124
00125 static int handle_orig(int fd, int argc, char *argv[])
00126 {
00127 int res;
00128
00129 if (ast_strlen_zero(argv[1]) || ast_strlen_zero(argv[2]))
00130 return RESULT_SHOWUSAGE;
00131
00132
00133 ast_module_ref(ast_module_info->self);
00134
00135 if (!strcasecmp("application", argv[2])) {
00136 res = orig_app(fd, argv[1], argv[3], argv[4]);
00137 } else if (!strcasecmp("extension", argv[2])) {
00138 res = orig_exten(fd, argv[1], argv[3]);
00139 } else
00140 res = RESULT_SHOWUSAGE;
00141
00142 ast_module_unref(ast_module_info->self);
00143
00144 return res;
00145 }
00146
00147 static char *complete_orig(const char *line, const char *word, int pos, int state)
00148 {
00149 static char *choices[] = { "application", "extension", NULL };
00150 char *ret;
00151
00152 if (pos != 2)
00153 return NULL;
00154
00155
00156 ast_module_ref(ast_module_info->self);
00157 ret = ast_cli_complete(word, choices, state);
00158 ast_module_unref(ast_module_info->self);
00159
00160 return ret;
00161 }
00162
00163 static int unload_module(void)
00164 {
00165 ast_cli_unregister_multiple(cli_cliorig, sizeof(cli_cliorig) / sizeof(struct ast_cli_entry));
00166 return 0;
00167 }
00168
00169 static int load_module(void)
00170 {
00171 ast_cli_register_multiple(cli_cliorig, sizeof(cli_cliorig) / sizeof(struct ast_cli_entry));
00172 return 0;
00173 }
00174
00175 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Call origination from the CLI");