[svn-commits] branch russell/cli_originate - r7458 in /team/russell/cli_originate: include/...

svn-commits at lists.digium.com svn-commits at lists.digium.com
Tue Dec 13 00:05:57 CST 2005


Author: russell
Date: Tue Dec 13 00:05:54 2005
New Revision: 7458

URL: http://svn.digium.com/view/asterisk?rev=7458&view=rev
Log:
merge the patches for the originate CLI command, reported in issue #5847

Added:
    team/russell/cli_originate/res/res_clioriginate.c
Modified:
    team/russell/cli_originate/include/asterisk/module.h
    team/russell/cli_originate/res/Makefile

Modified: team/russell/cli_originate/include/asterisk/module.h
URL: http://svn.digium.com/view/asterisk/team/russell/cli_originate/include/asterisk/module.h?rev=7458&r1=7457&r2=7458&view=diff
==============================================================================
--- team/russell/cli_originate/include/asterisk/module.h (original)
+++ team/russell/cli_originate/include/asterisk/module.h Tue Dec 13 00:05:54 2005
@@ -289,6 +289,10 @@
 #define LOCAL_USER_DECL AST_MUTEX_DEFINE_STATIC(localuser_lock); \
 						static struct localuser *localusers = NULL; \
 						static int localusecnt = 0;
+
+#define STANDARD_USECOUNT_DECL \
+	AST_MUTEX_DEFINE_STATIC(localuser_lock); \
+	static int localusecnt = 0;	
 
 #define STANDARD_INCREMENT_USECOUNT \
 	ast_mutex_lock(&localuser_lock); \

Modified: team/russell/cli_originate/res/Makefile
URL: http://svn.digium.com/view/asterisk/team/russell/cli_originate/res/Makefile?rev=7458&r1=7457&r2=7458&view=diff
==============================================================================
--- team/russell/cli_originate/res/Makefile (original)
+++ team/russell/cli_originate/res/Makefile Tue Dec 13 00:05:54 2005
@@ -11,7 +11,7 @@
 # the GNU General Public License
 #
 
-MODS=res_indications.so res_monitor.so res_adsi.so res_agi.so res_features.so
+MODS=res_indications.so res_monitor.so res_adsi.so res_agi.so res_features.so res_clioriginate.so
 
 ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/odbcinst.h)$(wildcard $(CROSS_COMPILE_TARGET)/usr/local/include/odbcinst.h),)
   ifneq (${OSARCH},FreeBSD)

Added: team/russell/cli_originate/res/res_clioriginate.c
URL: http://svn.digium.com/view/asterisk/team/russell/cli_originate/res/res_clioriginate.c?rev=7458&view=auto
==============================================================================
--- team/russell/cli_originate/res/res_clioriginate.c (added)
+++ team/russell/cli_originate/res/res_clioriginate.c Tue Dec 13 00:05:54 2005
@@ -1,0 +1,199 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2005, Digium, Inc.
+ *
+ * Russell Bryant <russell at 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
+ *
+ * \brief Originate calls via the CLI
+ * 
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision: 1.1 $");
+
+#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
+
+STANDARD_USECOUNT_DECL;
+
+static char *tdesc = "Call origination from the CLI";
+
+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\n"
+
+"Usage1: originate <channel> application <appname> [appdata]\n"
+"  This will originate a call between the specified channel and the given\n"
+"application. Arguments to the application are optional.\n\n"
+
+"Usage2: originate <channel> extension [exten@][context]\n"
+"  This will originate a call between the specified channel and the given\n"
+"extension. If no context is specified, the 'default' context will be used.\n"
+"If no extension is given, the 's' extension will be used.\n";
+
+static int handle_orig(int fd, int argc, char *argv[]);
+static char *complete_orig(char *line, char *word, int pos, int state);
+
+struct ast_cli_entry cli_orig = { { "originate", NULL }, handle_orig, "Originate a call", orig_help, complete_orig };
+
+static int orig_app(const char *chan, const char *app, const char *appdata)
+{
+	char *chantech;
+	char *chandata;
+	int reason = 0;
+	
+	if (ast_strlen_zero(app))
+		return RESULT_SHOWUSAGE;
+
+	chandata = ast_strdupa(chan);
+	if (!chandata) {
+		ast_log(LOG_ERROR, "Out of Memory!\n");
+		return RESULT_FAILURE;
+	}
+	chantech = strsep(&chandata, "/");
+
+	ast_pbx_outgoing_app(chantech, AST_FORMAT_SLINEAR, chandata, TIMEOUT * 1000, app, appdata, &reason, 1, NULL, NULL, NULL, NULL);
+
+	return RESULT_SUCCESS;
+}
+
+static int orig_exten(const char *chan, const char *data)
+{
+	char *chantech;
+	char *chandata;
+	char *exten = NULL;
+	char *context = NULL;
+	int reason = 0;
+
+	chandata = ast_strdupa(chan);
+	if (!chandata) {
+		ast_log(LOG_ERROR, "Out of Memory!\n");
+		return RESULT_FAILURE;
+	}
+	chantech = strsep(&chandata, "/");
+
+	if (!ast_strlen_zero(data)) {
+		context = ast_strdupa(data);
+		if (!context) {
+			ast_log(LOG_ERROR, "Out of Memory!\n");
+			return RESULT_FAILURE;
+		}
+		exten = strsep(&context, "@");
+	}
+
+	if (ast_strlen_zero(exten))
+		exten = "s";
+	if (ast_strlen_zero(context))
+		context = "default";
+	
+	ast_pbx_outgoing_exten(chantech, AST_FORMAT_SLINEAR, chandata, TIMEOUT * 1000, context, exten, 1, &reason, 1, NULL, NULL, NULL, NULL);
+
+	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;
+
+	STANDARD_INCREMENT_USECOUNT;
+
+	if (!strcasecmp("application", argv[2])) {
+		res = orig_app(argv[1], argv[3], argv[4]);	
+	} else if (!strcasecmp("extension", argv[2])) {
+		res = orig_exten(argv[1], argv[3]);
+	} else
+		res = RESULT_SHOWUSAGE;
+
+	STANDARD_DECREMENT_USECOUNT;
+
+	return res;
+}
+
+static char *complete_orig(char *line, char *word, int pos, int state)
+{
+	int wordlen;
+	char *app = "application";
+	char *exten = "extension";
+	char *ret = NULL;
+
+	if (pos != 2 || state)
+		return NULL;
+
+	STANDARD_INCREMENT_USECOUNT;
+
+	wordlen = strlen(word);
+
+	if (ast_strlen_zero(word)) {
+		/* show the options in alphabetical order */
+		if (!state)
+			ret = strdup(app);
+		else
+			ret = strdup(exten);
+	} else if (!strncasecmp(word, app, wordlen)) {
+		ret = strdup(app);
+	} else if (!strncasecmp(word, exten, wordlen)) {
+		ret = strdup(exten);
+	}
+
+	STANDARD_DECREMENT_USECOUNT;
+
+	return ret;
+}
+
+int unload_module(void)
+{
+	return ast_cli_unregister(&cli_orig);
+}
+
+int load_module(void)
+{
+	return ast_cli_register(&cli_orig);
+}
+
+char *description(void)
+{
+	return tdesc;
+}
+
+int usecount(void)
+{
+	return 0;
+}
+
+char *key()
+{
+	return ASTERISK_GPL_KEY;
+}
+



More information about the svn-commits mailing list