aboutsummaryrefslogtreecommitdiffstats
path: root/funcs
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2006-05-28 15:10:19 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2006-05-28 15:10:19 +0000
commit42d036b2d19fea144f004efb7822821c99ad2a2d (patch)
tree12fe06076c0a473f066a3047bc8cf238b9f367c3 /funcs
parent7c08dc20b84e358b08fe232086630e675a55423c (diff)
Deprecate SetGlobalVar, replacing it with a dialplan function
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@30677 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'funcs')
-rw-r--r--funcs/func_global.c198
1 files changed, 198 insertions, 0 deletions
diff --git a/funcs/func_global.c b/funcs/func_global.c
new file mode 100644
index 000000000..c5e9d9aef
--- /dev/null
+++ b/funcs/func_global.c
@@ -0,0 +1,198 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2006, Tilghman Lesher
+ *
+ * Tilghman Lesher <func_global__200605@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@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@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@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);