[asterisk-commits] branch oej/test-this-branch r11812 - in /team/oej/test-this-branch: ./ funcs/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Sat Mar 4 06:25:42 MST 2006


Author: oej
Date: Sat Mar  4 07:25:39 2006
New Revision: 11812

URL: http://svn.digium.com/view/asterisk?rev=11812&view=rev
Log:
Adding bweschkes realtime dialplan function - #5695

Added:
    team/oej/test-this-branch/funcs/func_realtime.c   (with props)
Modified:
    team/oej/test-this-branch/README.test-this-branch

Modified: team/oej/test-this-branch/README.test-this-branch
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/README.test-this-branch?rev=11812&r1=11811&r2=11812&view=diff
==============================================================================
--- team/oej/test-this-branch/README.test-this-branch (original)
+++ team/oej/test-this-branch/README.test-this-branch Sat Mar  4 07:25:39 2006
@@ -25,6 +25,7 @@
 - multiparking: Multiple parking lots (#6113)
 - cdr_radius: CDR support for Radius (#6639, phsultan). See doc/cdrdriver.txt
 - amieventhook-561 rev 11712: Support for manager event hooks (#5161, anthm)
+- func_realtime: Realtime dialplan function (bweschke, #5695)
 
 And the following stand-alone patches
 - New CLI commands for global variables (oej, #6506)

Added: team/oej/test-this-branch/funcs/func_realtime.c
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/funcs/func_realtime.c?rev=11812&view=auto
==============================================================================
--- team/oej/test-this-branch/funcs/func_realtime.c (added)
+++ team/oej/test-this-branch/funcs/func_realtime.c Sat Mar  4 07:25:39 2006
@@ -1,0 +1,137 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2005, Digium, Inc.
+ * Copyright (C) 2005, BJ Weschke <bweschke at btwtech.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 RealTime related dialplan functions
+ * 
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+#include "asterisk.h"
+
+/* ASTERISK_FILE_VERSION(__FILE__, "$Revision$") */
+
+#include "asterisk/file.h"
+#include "asterisk/channel.h"
+#include "asterisk/pbx.h"
+#include "asterisk/options.h"
+#include "asterisk/config.h"
+#include "asterisk/module.h"
+#include "asterisk/lock.h"
+#include "asterisk/logger.h"
+#include "asterisk/utils.h"
+#include "asterisk/app.h"
+
+static char *function_realtime_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) 
+{
+
+	struct ast_variable *var=NULL,*head=NULL;
+	char *results;
+	unsigned int resultslen=0;
+	AST_DECLARE_APP_ARGS(args,
+		AST_APP_ARG(family);
+		AST_APP_ARG(metamatch);
+		AST_APP_ARG(value);
+		AST_APP_ARG(delim1);
+		AST_APP_ARG(delim2);
+	);
+
+	if (ast_strlen_zero(data)) {
+		ast_log(LOG_WARNING, "Syntax: REALTIME(family|metamatch[|value[|delim1[|delim2]]]) - missing argument!\n");
+		return NULL;
+	} else
+		AST_STANDARD_APP_ARGS(args, data);
+
+	if (!args.delim1)
+		args.delim1 = "|";
+	if (!args.delim2)
+		args.delim2 = "=";
+
+	var = ast_load_realtime(args.family, args.metamatch, args.value, NULL);
+
+	if (var) {
+		head = var;
+		while (var) {
+			resultslen += strlen(var->name) + strlen(var->value) + 2;
+			var = var->next;
+		}
+		var = head;
+		results = alloca(resultslen);
+		while (var) {
+			ast_build_string(&results, &resultslen, "%s%s%s%s", var->name, args.delim2, var->value, args.delim1);
+			var = var->next;
+		}	
+	}
+	else
+		return NULL;
+	ast_copy_string(buf, results, len);
+	
+	return buf;
+}
+
+static void function_realtime_write(struct ast_channel *chan, char *cmd, char *data, const char *value)
+{
+	int res = 0;
+	AST_DECLARE_APP_ARGS(args,
+		AST_APP_ARG(family);
+		AST_APP_ARG(metamatch);
+		AST_APP_ARG(value);
+		AST_APP_ARG(newcol);
+	);
+
+	if (ast_strlen_zero(data)) {
+		ast_log(LOG_WARNING, "Syntax: REALTIME(family|metamatch|value|newcol) - missing argument!\n");
+		return;
+	} else
+		AST_STANDARD_APP_ARGS(args, data);
+
+	res = ast_update_realtime(args.family, args.metamatch, args.value, args.newcol, (char *)value, NULL);
+
+	if (res < 0) {
+		ast_log(LOG_WARNING, "Failed to update. Check the debug log for possible data repository related entries.\n");
+	}
+
+	return;
+}
+
+#ifndef BUILTIN_FUNC
+static
+#endif
+struct ast_custom_function realtime_function = {
+	.name = "REALTIME",
+	.synopsis = "RealTime Read/Write Functions",
+	.syntax = "REALTIME(family|metamatch[|value[|delim1[|delim2]]]) on read\n"
+		  "REALTIME(family|metamatch|value|newmeta) on write\n",
+	.desc = "This function will read or write values from/to a RealTime repository.\n"
+		"REALTIME(....) will read names/values from the repository, and \n"
+		"REALTIME(....)= will write a new value/meta to the repository. On a\n"
+		"read, this function returns a delimited text string. The name/value \n"
+		"pairs are delimited by delim1, and the name and value are delimited \n"
+		"between each other with delim2. The default for delim1 is '=' and   \n"
+		"the default for delim2 is '|'. If there is no match, NULL will be   \n"
+		"returned by the function. On a write, this function will always     \n"
+		"return NULL. \n",
+	.read = function_realtime_read,
+	.write = function_realtime_write,
+};
+

Propchange: team/oej/test-this-branch/funcs/func_realtime.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/oej/test-this-branch/funcs/func_realtime.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/oej/test-this-branch/funcs/func_realtime.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain



More information about the asterisk-commits mailing list