[asterisk-commits] trunk r30677 - in /trunk: UPGRADE.txt funcs/func_global.c pbx.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Sun May 28 08:10:20 MST 2006


Author: tilghman
Date: Sun May 28 10:10:19 2006
New Revision: 30677

URL: http://svn.digium.com/view/asterisk?rev=30677&view=rev
Log:
Deprecate SetGlobalVar, replacing it with a dialplan function

Added:
    trunk/funcs/func_global.c   (with props)
Modified:
    trunk/UPGRADE.txt
    trunk/pbx.c

Modified: trunk/UPGRADE.txt
URL: http://svn.digium.com/view/asterisk/trunk/UPGRADE.txt?rev=30677&r1=30676&r2=30677&view=diff
==============================================================================
--- trunk/UPGRADE.txt (original)
+++ trunk/UPGRADE.txt Sun May 28 10:10:19 2006
@@ -74,6 +74,12 @@
   and GetGroupMatchCount were all deprecated in version 1.2, and therefore have
   been removed in this version.  You should use the equivalent dialplan
   function in places where you have previously used one of these applications.
+
+* The application SetGlobalVar has been deprecated.  You should replace uses
+  of this application with the following combination of Set and GLOBAL():
+  Set(GLOBAL(name)=value).  You may also access global variables exclusively by
+  using the GLOBAL() dialplan function, instead of relying on variable
+  interpolation falling back to globals when no channel variable is set.
 
 * The application SetVar has been renamed to Set.  The syntax SetVar was marked
   deprecated in version 1.2 and is no longer recognized in this version.

Added: trunk/funcs/func_global.c
URL: http://svn.digium.com/view/asterisk/trunk/funcs/func_global.c?rev=30677&view=auto
==============================================================================
--- trunk/funcs/func_global.c (added)
+++ trunk/funcs/func_global.c Sun May 28 10:10:19 2006
@@ -1,0 +1,198 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2006, Tilghman Lesher
+ *
+ * Tilghman Lesher <func_global__200605 at the-tilghman.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 Global variable dialplan functions
+ *
+ * \author Tilghman Lesher <func_global__200605 at the-tilghman.com>
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "asterisk/module.h"
+#include "asterisk/channel.h"
+#include "asterisk/pbx.h"
+#include "asterisk/utils.h"
+
+static int global_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
+{
+	const char *var = pbx_builtin_getvar_helper(NULL, data);
+
+	*buf = '\0';
+
+	if (var)
+		ast_copy_string(buf, var, len);
+
+	return 0;
+}
+
+static int global_write(struct ast_channel *chan, char *cmd, char *data, const char *value)
+{
+	pbx_builtin_setvar_helper(NULL, data, value);
+
+	return 0;
+}
+
+static struct ast_custom_function global_function = {
+	.name = "GLOBAL",
+	.synopsis = "Gets or sets the global variable specified",
+	.syntax = "GLOBAL(<varname>)",
+	.read = global_read,
+	.write = global_write,
+};
+
+static char *tdesc = "Global variable dialplan functions";
+
+static int unload_module(void *mod)
+{
+	int res = 0;
+
+	res |= ast_custom_function_unregister(&global_function);
+
+	return res;
+}
+
+static int load_module(void *mod)
+{
+	int res = 0;
+
+	res |= ast_custom_function_register(&global_function);
+
+	return res;
+}
+
+static const char *description(void)
+{
+	return tdesc;
+}
+
+
+static const char *key(void)
+{
+	return ASTERISK_GPL_KEY;
+}
+
+STD_MOD(MOD_1 | NO_USECOUNT, NULL, NULL, NULL);
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2006, Tilghman Lesher
+ *
+ * Tilghman Lesher <func_global__200605 at the-tilghman.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 Global variable dialplan functions
+ *
+ * \author Tilghman Lesher <func_global__200605 at the-tilghman.com>
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "asterisk/module.h"
+#include "asterisk/channel.h"
+#include "asterisk/pbx.h"
+#include "asterisk/utils.h"
+
+static int global_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
+{
+	const char *var = pbx_builtin_getvar_helper(NULL, data);
+
+	*buf = '\0';
+
+	if (var)
+		ast_copy_string(buf, var, len);
+
+	return 0;
+}
+
+static int global_write(struct ast_channel *chan, char *cmd, char *data, const char *value)
+{
+	pbx_builtin_setvar_helper(NULL, data, value);
+
+	return 0;
+}
+
+static struct ast_custom_function global_function = {
+	.name = "GLOBAL",
+	.synopsis = "Gets or sets the global variable specified",
+	.syntax = "GLOBAL(<varname>)",
+	.read = global_read,
+	.write = global_write,
+};
+
+static char *tdesc = "Global variable dialplan functions";
+
+static int unload_module(void *mod)
+{
+	int res = 0;
+
+	res |= ast_custom_function_unregister(&global_function);
+
+	return res;
+}
+
+static int load_module(void *mod)
+{
+	int res = 0;
+
+	res |= ast_custom_function_register(&global_function);
+
+	return res;
+}
+
+static const char *description(void)
+{
+	return tdesc;
+}
+
+
+static const char *key(void)
+{
+	return ASTERISK_GPL_KEY;
+}
+
+STD_MOD(MOD_1 | NO_USECOUNT, NULL, NULL, NULL);

Propchange: trunk/funcs/func_global.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: trunk/funcs/func_global.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: trunk/funcs/func_global.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: trunk/pbx.c
URL: http://svn.digium.com/view/asterisk/trunk/pbx.c?rev=30677&r1=30676&r2=30677&view=diff
==============================================================================
--- trunk/pbx.c (original)
+++ trunk/pbx.c Sun May 28 10:10:19 2006
@@ -5473,6 +5473,7 @@
 {
 	char *name;
 	char *stringp = data;
+	static int dep_warning = 0;
 
 	if (ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "Ignoring, since there is no variable to set\n");
@@ -5480,6 +5481,12 @@
 	}
 
 	name = strsep(&stringp, "=");
+
+	if (!dep_warning) {
+		dep_warning = 1;
+		ast_log(LOG_WARNING, "SetGlobalVar is deprecated.  Please use Set(GLOBAL(%s)=%s) instead.\n", name, stringp);
+	}
+
 	/*! \todo XXX watch out, leading whitespace ? */
 	pbx_builtin_setvar_helper(NULL, name, stringp);
 



More information about the asterisk-commits mailing list