| 
									
										
										
										
											2006-01-18 15:42:48 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Asterisk -- An open source telephony toolkit. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2006-04-29 05:02:17 +00:00
										 |  |  |  * Copyright (C) 2005 - 2006, Digium, Inc. | 
					
						
							| 
									
										
										
										
											2006-01-18 15:42:48 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Russell Bryant <russell@digium.com> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * See http://www.asterisk.org for more information about
 | 
					
						
							|  |  |  |  * the Asterisk project. Please do not directly contact | 
					
						
							|  |  |  |  * any of the maintainers of this project for assistance; | 
					
						
							|  |  |  |  * the project provides a web site, mailing lists and IRC | 
					
						
							|  |  |  |  * channels for your use. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software, distributed under the terms of | 
					
						
							|  |  |  |  * the GNU General Public License Version 2. See the LICENSE file | 
					
						
							|  |  |  |  * at the top of the source tree. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*! 
 | 
					
						
							|  |  |  |  * \file | 
					
						
							| 
									
										
										
										
											2006-04-29 05:02:17 +00:00
										 |  |  |  * \author Russell Bryant <russell@digium.com> | 
					
						
							| 
									
										
										
										
											2006-01-18 15:42:48 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * \brief Originate calls via the CLI | 
					
						
							|  |  |  |  *  | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "asterisk.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-11 16:15:11 +00:00
										 |  |  | ASTERISK_FILE_VERSION(__FILE__, "$Revision$"); | 
					
						
							| 
									
										
										
										
											2006-01-18 15:42:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-07 18:54:56 +00:00
										 |  |  | #include <stdlib.h>
 | 
					
						
							|  |  |  | #include <stdio.h>
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-18 15:42:48 +00:00
										 |  |  | #include "asterisk/channel.h"
 | 
					
						
							|  |  |  | #include "asterisk/pbx.h"
 | 
					
						
							|  |  |  | #include "asterisk/logger.h"
 | 
					
						
							|  |  |  | #include "asterisk/module.h"
 | 
					
						
							|  |  |  | #include "asterisk/cli.h"
 | 
					
						
							|  |  |  | #include "asterisk/utils.h"
 | 
					
						
							|  |  |  | #include "asterisk/frame.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*! The timeout for originated calls, in seconds */ | 
					
						
							|  |  |  | #define TIMEOUT 30
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char orig_help[] =  | 
					
						
							|  |  |  | "  There are two ways to use this command. A call can be originated between a\n" | 
					
						
							|  |  |  | "channel and a specific application, or between a channel and an extension in\n" | 
					
						
							|  |  |  | "the dialplan. This is similar to call files or the manager originate action.\n" | 
					
						
							|  |  |  | "Calls originated with this command are given a timeout of 30 seconds.\n\n" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | "Usage1: originate <tech/data> application <appname> [appdata]\n" | 
					
						
							|  |  |  | "  This will originate a call between the specified channel tech/data and the\n" | 
					
						
							|  |  |  | "given application. Arguments to the application are optional. If the given\n" | 
					
						
							|  |  |  | "arguments to the application include spaces, all of the arguments to the\n" | 
					
						
							|  |  |  | "application need to be placed in quotation marks.\n\n" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | "Usage2: originate <tech/data> extension [exten@][context]\n" | 
					
						
							|  |  |  | "  This will originate a call between the specified channel tech/data and the\n" | 
					
						
							|  |  |  | "given extension. If no context is specified, the 'default' context will be\n" | 
					
						
							|  |  |  | "used. If no extension is given, the 's' extension will be used.\n"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int handle_orig(int fd, int argc, char *argv[]); | 
					
						
							| 
									
										
										
										
											2006-01-18 22:17:31 +00:00
										 |  |  | static char *complete_orig(const char *line, const char *word, int pos, int state); | 
					
						
							| 
									
										
										
										
											2006-01-18 15:42:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-09-18 19:54:18 +00:00
										 |  |  | struct ast_cli_entry cli_cliorig[] = { | 
					
						
							|  |  |  | 	{ { "originate", NULL }, | 
					
						
							|  |  |  | 	handle_orig, "Originate a call", | 
					
						
							|  |  |  | 	orig_help, complete_orig }, | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2006-01-18 15:42:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-29 05:02:17 +00:00
										 |  |  | static int orig_app(int fd, const char *chan, const char *app, const char *appdata) | 
					
						
							| 
									
										
										
										
											2006-01-18 15:42:48 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	char *chantech; | 
					
						
							|  |  |  | 	char *chandata; | 
					
						
							|  |  |  | 	int reason = 0; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if (ast_strlen_zero(app)) | 
					
						
							|  |  |  | 		return RESULT_SHOWUSAGE; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-05-10 13:22:15 +00:00
										 |  |  | 	chandata = ast_strdupa(chan); | 
					
						
							| 
									
										
										
										
											2006-04-29 05:02:17 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2006-01-18 15:42:48 +00:00
										 |  |  | 	chantech = strsep(&chandata, "/"); | 
					
						
							| 
									
										
										
										
											2006-02-02 14:04:29 +00:00
										 |  |  | 	if (!chandata) { | 
					
						
							| 
									
										
										
										
											2006-04-29 05:02:17 +00:00
										 |  |  | 		ast_cli(fd, "*** No data provided after channel type! ***\n"); | 
					
						
							| 
									
										
										
										
											2006-02-02 14:04:29 +00:00
										 |  |  | 		return RESULT_SHOWUSAGE; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-01-18 15:42:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-11 18:31:59 +00:00
										 |  |  | 	ast_pbx_outgoing_app(chantech, AST_FORMAT_SLINEAR, chandata, TIMEOUT * 1000, app, appdata, &reason, 1, NULL, NULL, NULL, NULL, NULL); | 
					
						
							| 
									
										
										
										
											2006-01-18 15:42:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return RESULT_SUCCESS; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-29 05:02:17 +00:00
										 |  |  | static int orig_exten(int fd, const char *chan, const char *data) | 
					
						
							| 
									
										
										
										
											2006-01-18 15:42:48 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	char *chantech; | 
					
						
							|  |  |  | 	char *chandata; | 
					
						
							|  |  |  | 	char *exten = NULL; | 
					
						
							|  |  |  | 	char *context = NULL; | 
					
						
							|  |  |  | 	int reason = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-05-10 13:22:15 +00:00
										 |  |  | 	chandata = ast_strdupa(chan); | 
					
						
							| 
									
										
										
										
											2006-04-29 05:02:17 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2006-01-18 15:42:48 +00:00
										 |  |  | 	chantech = strsep(&chandata, "/"); | 
					
						
							| 
									
										
										
										
											2006-04-29 05:02:17 +00:00
										 |  |  | 	if (!chandata) { | 
					
						
							|  |  |  | 		ast_cli(fd, "*** No data provided after channel type! ***\n"); | 
					
						
							|  |  |  | 		return RESULT_SHOWUSAGE; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-01-18 15:42:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!ast_strlen_zero(data)) { | 
					
						
							| 
									
										
										
										
											2006-05-10 13:22:15 +00:00
										 |  |  | 		context = ast_strdupa(data); | 
					
						
							| 
									
										
										
										
											2006-01-18 15:42:48 +00:00
										 |  |  | 		exten = strsep(&context, "@"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (ast_strlen_zero(exten)) | 
					
						
							|  |  |  | 		exten = "s"; | 
					
						
							|  |  |  | 	if (ast_strlen_zero(context)) | 
					
						
							|  |  |  | 		context = "default"; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2006-02-11 18:31:59 +00:00
										 |  |  | 	ast_pbx_outgoing_exten(chantech, AST_FORMAT_SLINEAR, chandata, TIMEOUT * 1000, context, exten, 1, &reason, 1, NULL, NULL, NULL, NULL, NULL); | 
					
						
							| 
									
										
										
										
											2006-01-18 15:42:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return RESULT_SUCCESS; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int handle_orig(int fd, int argc, char *argv[]) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int res; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (ast_strlen_zero(argv[1]) || ast_strlen_zero(argv[2])) | 
					
						
							|  |  |  | 		return RESULT_SHOWUSAGE; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | 	/* ugly, can be removed when CLI entries have ast_module pointers */ | 
					
						
							|  |  |  | 	ast_module_ref(ast_module_info->self); | 
					
						
							| 
									
										
										
										
											2006-01-18 15:42:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!strcasecmp("application", argv[2])) { | 
					
						
							| 
									
										
										
										
											2006-04-29 05:02:17 +00:00
										 |  |  | 		res = orig_app(fd, argv[1], argv[3], argv[4]);	 | 
					
						
							| 
									
										
										
										
											2006-01-18 15:42:48 +00:00
										 |  |  | 	} else if (!strcasecmp("extension", argv[2])) { | 
					
						
							| 
									
										
										
										
											2006-04-29 05:02:17 +00:00
										 |  |  | 		res = orig_exten(fd, argv[1], argv[3]); | 
					
						
							| 
									
										
										
										
											2006-01-18 15:42:48 +00:00
										 |  |  | 	} else | 
					
						
							|  |  |  | 		res = RESULT_SHOWUSAGE; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | 	ast_module_unref(ast_module_info->self); | 
					
						
							| 
									
										
										
										
											2006-01-18 15:42:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-18 22:17:31 +00:00
										 |  |  | static char *complete_orig(const char *line, const char *word, int pos, int state) | 
					
						
							| 
									
										
										
										
											2006-01-18 15:42:48 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2006-03-28 23:06:46 +00:00
										 |  |  | 	static char *choices[] = { "application", "extension", NULL }; | 
					
						
							|  |  |  | 	char *ret; | 
					
						
							| 
									
										
										
										
											2006-01-18 15:42:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-03-28 23:06:46 +00:00
										 |  |  | 	if (pos != 2) | 
					
						
							| 
									
										
										
										
											2006-01-18 15:42:48 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | 	/* ugly, can be removed when CLI entries have ast_module pointers */ | 
					
						
							|  |  |  | 	ast_module_ref(ast_module_info->self); | 
					
						
							| 
									
										
										
										
											2006-03-28 23:06:46 +00:00
										 |  |  | 	ret = ast_cli_complete(word, choices, state); | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | 	ast_module_unref(ast_module_info->self); | 
					
						
							| 
									
										
										
										
											2006-01-18 15:42:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int unload_module(void) | 
					
						
							| 
									
										
										
										
											2006-01-18 15:42:48 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2006-09-18 19:54:18 +00:00
										 |  |  | 	ast_cli_unregister_multiple(cli_cliorig, sizeof(cli_cliorig) / sizeof(struct ast_cli_entry)); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2006-01-18 15:42:48 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int load_module(void) | 
					
						
							| 
									
										
										
										
											2006-01-18 15:42:48 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2006-09-18 19:54:18 +00:00
										 |  |  | 	ast_cli_register_multiple(cli_cliorig, sizeof(cli_cliorig) / sizeof(struct ast_cli_entry)); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2006-01-18 15:42:48 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Call origination from the CLI"); |