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_cliorig
[] = {
67 { { "originate", NULL
},
68 handle_orig
, "Originate a call",
69 orig_help
, complete_orig
},
72 static int orig_app(int fd
, const char *chan
, const char *app
, const char *appdata
)
78 if (ast_strlen_zero(app
))
79 return RESULT_SHOWUSAGE
;
81 chandata
= ast_strdupa(chan
);
83 chantech
= strsep(&chandata
, "/");
85 ast_cli(fd
, "*** No data provided after channel type! ***\n");
86 return RESULT_SHOWUSAGE
;
89 ast_pbx_outgoing_app(chantech
, AST_FORMAT_SLINEAR
, chandata
, TIMEOUT
* 1000, app
, appdata
, &reason
, 0, NULL
, NULL
, NULL
, NULL
, NULL
);
91 return RESULT_SUCCESS
;
94 static int orig_exten(int fd
, const char *chan
, const char *data
)
102 chandata
= ast_strdupa(chan
);
104 chantech
= strsep(&chandata
, "/");
106 ast_cli(fd
, "*** No data provided after channel type! ***\n");
107 return RESULT_SHOWUSAGE
;
110 if (!ast_strlen_zero(data
)) {
111 context
= ast_strdupa(data
);
112 exten
= strsep(&context
, "@");
115 if (ast_strlen_zero(exten
))
117 if (ast_strlen_zero(context
))
120 ast_pbx_outgoing_exten(chantech
, AST_FORMAT_SLINEAR
, chandata
, TIMEOUT
* 1000, context
, exten
, 1, &reason
, 0, NULL
, NULL
, NULL
, NULL
, NULL
);
122 return RESULT_SUCCESS
;
125 static int handle_orig(int fd
, int argc
, char *argv
[])
129 if (ast_strlen_zero(argv
[1]) || ast_strlen_zero(argv
[2]))
130 return RESULT_SHOWUSAGE
;
132 /* ugly, can be removed when CLI entries have ast_module pointers */
133 ast_module_ref(ast_module_info
->self
);
135 if (!strcasecmp("application", argv
[2])) {
136 res
= orig_app(fd
, argv
[1], argv
[3], argv
[4]);
137 } else if (!strcasecmp("extension", argv
[2])) {
138 res
= orig_exten(fd
, argv
[1], argv
[3]);
140 res
= RESULT_SHOWUSAGE
;
142 ast_module_unref(ast_module_info
->self
);
147 static char *complete_orig(const char *line
, const char *word
, int pos
, int state
)
149 static char *choices
[] = { "application", "extension", NULL
};
155 /* ugly, can be removed when CLI entries have ast_module pointers */
156 ast_module_ref(ast_module_info
->self
);
157 ret
= ast_cli_complete(word
, choices
, state
);
158 ast_module_unref(ast_module_info
->self
);
163 static int unload_module(void)
165 ast_cli_unregister_multiple(cli_cliorig
, sizeof(cli_cliorig
) / sizeof(struct ast_cli_entry
));
169 static int load_module(void)
171 ast_cli_register_multiple(cli_cliorig
, sizeof(cli_cliorig
) / sizeof(struct ast_cli_entry
));
175 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY
, "Call origination from the CLI");