2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2005 - 2006, 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.
21 * \author Russell Bryant <russell@digium.com>
23 * \brief Originate calls via the CLI
29 ASTERISK_FILE_VERSION(__FILE__, "$Revision$");
35 #include "asterisk/channel.h"
36 #include "asterisk/pbx.h"
37 #include "asterisk/logger.h"
38 #include "asterisk/module.h"
39 #include "asterisk/cli.h"
40 #include "asterisk/utils.h"
41 #include "asterisk/frame.h"
43 /*! The timeout for originated calls, in seconds */
46 static char orig_help[] =
47 " There are two ways to use this command. A call can be originated between a\n"
48 "channel and a specific application, or between a channel and an extension in\n"
49 "the dialplan. This is similar to call files or the manager originate action.\n"
50 "Calls originated with this command are given a timeout of 30 seconds.\n\n"
52 "Usage1: originate <tech/data> application <appname> [appdata]\n"
53 " This will originate a call between the specified channel tech/data and the\n"
54 "given application. Arguments to the application are optional. If the given\n"
55 "arguments to the application include spaces, all of the arguments to the\n"
56 "application need to be placed in quotation marks.\n\n"
58 "Usage2: originate <tech/data> extension [exten@][context]\n"
59 " This will originate a call between the specified channel tech/data and the\n"
60 "given extension. If no context is specified, the 'default' context will be\n"
61 "used. If no extension is given, the 's' extension will be used.\n";
63 static int handle_orig(int fd, int argc, char *argv[]);
64 static char *complete_orig(const char *line, const char *word, int pos, int state);
66 struct ast_cli_entry cli_orig = { { "originate", NULL }, handle_orig, "Originate a call", orig_help, complete_orig };
68 static int orig_app(int fd, const char *chan, const char *app, const char *appdata)
74 if (ast_strlen_zero(app))
75 return RESULT_SHOWUSAGE;
77 chandata = ast_strdupa(chan);
79 chantech = strsep(&chandata, "/");
81 ast_cli(fd, "*** No data provided after channel type! ***\n");
82 return RESULT_SHOWUSAGE;
85 ast_pbx_outgoing_app(chantech, AST_FORMAT_SLINEAR, chandata, TIMEOUT * 1000, app, appdata, &reason, 1, NULL, NULL, NULL, NULL, NULL);
87 return RESULT_SUCCESS;
90 static int orig_exten(int fd, const char *chan, const char *data)
98 chandata = ast_strdupa(chan);
100 chantech = strsep(&chandata, "/");
102 ast_cli(fd, "*** No data provided after channel type! ***\n");
103 return RESULT_SHOWUSAGE;
106 if (!ast_strlen_zero(data)) {
107 context = ast_strdupa(data);
108 exten = strsep(&context, "@");
111 if (ast_strlen_zero(exten))
113 if (ast_strlen_zero(context))
116 ast_pbx_outgoing_exten(chantech, AST_FORMAT_SLINEAR, chandata, TIMEOUT * 1000, context, exten, 1, &reason, 1, NULL, NULL, NULL, NULL, NULL);
118 return RESULT_SUCCESS;
121 static int handle_orig(int fd, int argc, char *argv[])
125 if (ast_strlen_zero(argv[1]) || ast_strlen_zero(argv[2]))
126 return RESULT_SHOWUSAGE;
128 /* ugly, can be removed when CLI entries have ast_module pointers */
129 ast_module_ref(ast_module_info->self);
131 if (!strcasecmp("application", argv[2])) {
132 res = orig_app(fd, argv[1], argv[3], argv[4]);
133 } else if (!strcasecmp("extension", argv[2])) {
134 res = orig_exten(fd, argv[1], argv[3]);
136 res = RESULT_SHOWUSAGE;
138 ast_module_unref(ast_module_info->self);
143 static char *complete_orig(const char *line, const char *word, int pos, int state)
145 static char *choices[] = { "application", "extension", NULL };
151 /* ugly, can be removed when CLI entries have ast_module pointers */
152 ast_module_ref(ast_module_info->self);
153 ret = ast_cli_complete(word, choices, state);
154 ast_module_unref(ast_module_info->self);
159 static int unload_module(void)
161 return ast_cli_unregister(&cli_orig);
164 static int load_module(void)
166 return ast_cli_register(&cli_orig);
169 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Call origination from the CLI");