[asterisk-commits] russell: branch russell/func_config r107786 - /team/russell/func_config/funcs/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Mar 11 17:13:33 CDT 2008


Author: russell
Date: Tue Mar 11 17:13:33 2008
New Revision: 107786

URL: http://svn.digium.com/view/asterisk?view=rev&rev=107786
Log:
finish implementation ... the easy but less efficient way

i don't think the config file caching is going to work for this module, given
that there will be more than one place loading this file

Modified:
    team/russell/func_config/funcs/func_config.c

Modified: team/russell/func_config/funcs/func_config.c
URL: http://svn.digium.com/view/asterisk/team/russell/func_config/funcs/func_config.c?view=diff&rev=107786&r1=107785&r2=107786
==============================================================================
--- team/russell/func_config/funcs/func_config.c (original)
+++ team/russell/func_config/funcs/func_config.c Tue Mar 11 17:13:33 2008
@@ -33,21 +33,16 @@
 #include "asterisk/channel.h"
 #include "asterisk/pbx.h"
 #include "asterisk/app.h"
-#include "asterisk/astobj2.h"
-
-struct open_config {
-	struct ast_config *cfg;
-	char filename[1];
-};
-
-static struct ao2_container *open_configs;
 
 static int config_function_read(struct ast_channel *chan, const char *cmd, char *data, 
 	char *buf, size_t len) 
 {
+	struct ast_config *cfg;
+	struct ast_flags cfg_flags = { 0 };
+	const char *val;
 	char *parse;
 	AST_DECLARE_APP_ARGS(args,
-		AST_APP_ARG(file);
+		AST_APP_ARG(filename);
 		AST_APP_ARG(category);
 		AST_APP_ARG(variable);
 		AST_APP_ARG(index);
@@ -61,11 +56,11 @@
 	parse = ast_strdupa(data);
 	AST_STANDARD_APP_ARGS(args, parse);
 
-	if (ast_strlen_zero(args.file)) {
+	if (ast_strlen_zero(args.filename)) {
 		ast_log(LOG_ERROR, "AST_CONFIG() requires a filename\n");
 		return -1;
 	}
-	
+
 	if (ast_strlen_zero(args.category)) {
 		ast_log(LOG_ERROR, "AST_CONFIG() requires a category\n");
 		return -1;
@@ -76,23 +71,21 @@
 		return -1;
 	}
 
-	/* XXX */
+	if (!(cfg = ast_config_load(args.filename, cfg_flags))) {
+		return -1;
+	}
+
+	if (!(val = ast_variable_retrieve(cfg, args.category, args.variable))) {
+		ast_log(LOG_ERROR, "'%s' not found in [%s] of '%s'\n", args.variable, 
+			args.category, args.filename);
+		return -1;
+	}
+
+	ast_copy_string(buf, val, len);
+
+	ast_config_destroy(cfg);
 
 	return 0;
-}
-
-static int open_config_hash(const void *obj, const int flags)
-{
-	const struct open_config *oc = obj;
-
-	return ast_str_hash(oc->filename);
-}
-
-static int open_config_cmp(void *obj, void *arg, int flags)
-{
-	struct open_config *oc1 = obj, *oc2 = arg;
-
-	return !strcasecmp(oc1->filename, oc2->filename) ? CMP_MATCH : 0;
 }
 
 static struct ast_custom_function config_function = {
@@ -112,16 +105,11 @@
 
 static int unload_module(void)
 {
-	ao2_ref(open_configs, -1);
-
 	return ast_custom_function_unregister(&config_function);
 }
 
 static int load_module(void)
 {
-	if (!(open_configs = ao2_container_alloc(17, open_config_hash, open_config_cmp)))
-		return AST_MODULE_LOAD_DECLINE;
-
 	return ast_custom_function_register(&config_function);
 }
 




More information about the asterisk-commits mailing list