2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2005, Digium, Inc.
6 * Russell Bryant <russell@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
22 * \brief Originate calls via the CLI
32 ASTERISK_FILE_VERSION(__FILE__, "$Revision$");
34 #include "asterisk/channel.h"
35 #include "asterisk/pbx.h"
36 #include "asterisk/logger.h"
37 #include "asterisk/module.h"
38 #include "asterisk/cli.h"
39 #include "asterisk/utils.h"
40 #include "asterisk/frame.h"
42 /*! The timeout for originated calls, in seconds */
45 STANDARD_USECOUNT_DECL;
47 static char *tdesc = "Call origination from the CLI";
49 static char orig_help[] =
50 " There are two ways to use this command. A call can be originated between a\n"
51 "channel and a specific application, or between a channel and an extension in\n"
52 "the dialplan. This is similar to call files or the manager originate action.\n"
53 "Calls originated with this command are given a timeout of 30 seconds.\n\n"
55 "Usage1: originate <tech/data> application <appname> [appdata]\n"
56 " This will originate a call between the specified channel tech/data and the\n"
57 "given application. Arguments to the application are optional. If the given\n"
58 "arguments to the application include spaces, all of the arguments to the\n"
59 "application need to be placed in quotation marks.\n\n"
61 "Usage2: originate <tech/data> extension [exten@][context]\n"
62 " This will originate a call between the specified channel tech/data and the\n"
63 "given extension. If no context is specified, the 'default' context will be\n"
64 "used. If no extension is given, the 's' extension will be used.\n";
66 static int handle_orig(int fd, int argc, char *argv[]);
67 static char *complete_orig(const char *line, const char *word, int pos, int state);
69 struct ast_cli_entry cli_orig = { { "originate", NULL }, handle_orig, "Originate a call", orig_help, complete_orig };
71 static int orig_app(const char *chan, const char *app, const char *appdata)
77 if (ast_strlen_zero(app))
78 return RESULT_SHOWUSAGE;
80 chandata = ast_strdupa(chan);
82 ast_log(LOG_ERROR, "Out of Memory!\n");
83 return RESULT_FAILURE;
85 chantech = strsep(&chandata, "/");
87 ast_log(LOG_ERROR, "No dial string.\n");
88 return RESULT_SHOWUSAGE;
91 ast_pbx_outgoing_app(chantech, AST_FORMAT_SLINEAR, chandata, TIMEOUT * 1000, app, appdata, &reason, 1, NULL, NULL, NULL, NULL);
93 return RESULT_SUCCESS;
96 static int orig_exten(const char *chan, const char *data)
101 char *context = NULL;
104 chandata = ast_strdupa(chan);
106 ast_log(LOG_ERROR, "Out of Memory!\n");
107 return RESULT_FAILURE;
109 chantech = strsep(&chandata, "/");
111 if (!ast_strlen_zero(data)) {
112 context = ast_strdupa(data);
114 ast_log(LOG_ERROR, "Out of Memory!\n");
115 return RESULT_FAILURE;
117 exten = strsep(&context, "@");
120 if (ast_strlen_zero(exten))
122 if (ast_strlen_zero(context))
125 ast_pbx_outgoing_exten(chantech, AST_FORMAT_SLINEAR, chandata, TIMEOUT * 1000, context, exten, 1, &reason, 1, NULL, NULL, NULL, NULL);
127 return RESULT_SUCCESS;
130 static int handle_orig(int fd, int argc, char *argv[])
134 if (ast_strlen_zero(argv[1]) || ast_strlen_zero(argv[2]))
135 return RESULT_SHOWUSAGE;
137 STANDARD_INCREMENT_USECOUNT;
139 if (!strcasecmp("application", argv[2])) {
140 res = orig_app(argv[1], argv[3], argv[4]);
141 } else if (!strcasecmp("extension", argv[2])) {
142 res = orig_exten(argv[1], argv[3]);
144 res = RESULT_SHOWUSAGE;
146 STANDARD_DECREMENT_USECOUNT;
151 static char *complete_orig(const char *line, const char *word, int pos, int state)
154 char *app = "application";
155 char *exten = "extension";
158 if (pos != 2 || state)
161 STANDARD_INCREMENT_USECOUNT;
163 wordlen = strlen(word);
165 if (ast_strlen_zero(word)) {
166 /* show the options in alphabetical order */
171 } else if (!strncasecmp(word, app, wordlen)) {
173 } else if (!strncasecmp(word, exten, wordlen)) {
177 STANDARD_DECREMENT_USECOUNT;
182 int unload_module(void)
184 return ast_cli_unregister(&cli_orig);
187 int load_module(void)
189 return ast_cli_register(&cli_orig);
192 char *description(void)
204 return ASTERISK_GPL_KEY;