[asterisk-commits] file: trunk r75255 - in /trunk: funcs/ include/asterisk/ main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jul 16 13:24:30 CDT 2007


Author: file
Date: Mon Jul 16 13:24:29 2007
New Revision: 75255

URL: http://svn.digium.com/view/asterisk?view=rev&rev=75255
Log:
For my next trick I will make it so dialplan functions no longer need to call ast_module_user_add and ast_module_user_remove. These are now called in the ast_func_read and ast_func_write functions outside of the module.

Modified:
    trunk/funcs/func_curl.c
    trunk/funcs/func_cut.c
    trunk/funcs/func_enum.c
    trunk/funcs/func_rand.c
    trunk/funcs/func_realtime.c
    trunk/funcs/func_version.c
    trunk/funcs/func_vmcount.c
    trunk/include/asterisk/pbx.h
    trunk/main/pbx.c

Modified: trunk/funcs/func_curl.c
URL: http://svn.digium.com/view/asterisk/trunk/funcs/func_curl.c?view=diff&rev=75255&r1=75254&r2=75255
==============================================================================
--- trunk/funcs/func_curl.c (original)
+++ trunk/funcs/func_curl.c Mon Jul 16 13:24:29 2007
@@ -135,7 +135,6 @@
 
 static int acf_curl_exec(struct ast_channel *chan, const char *cmd, char *info, char *buf, size_t len)
 {
-	struct ast_module_user *u;
 	struct MemoryStruct chunk = { NULL, 0 };
 	AST_DECLARE_APP_ARGS(args,
 		AST_APP_ARG(url);
@@ -149,8 +148,6 @@
 		return -1;
 	}
 
-	u = ast_module_user_add(chan);
-
 	AST_STANDARD_APP_ARGS(args, info);	
 
 	if (!curl_internal(&chunk, args.url, args.postdata)) {
@@ -165,8 +162,6 @@
 	} else {
 		ast_log(LOG_ERROR, "Cannot allocate curl structure\n");
 	}
-
-	ast_module_user_remove(u);
 
 	return 0;
 }

Modified: trunk/funcs/func_cut.c
URL: http://svn.digium.com/view/asterisk/trunk/funcs/func_cut.c?view=diff&rev=75255&r1=75254&r2=75255
==============================================================================
--- trunk/funcs/func_cut.c (original)
+++ trunk/funcs/func_cut.c Mon Jul 16 13:24:29 2007
@@ -222,10 +222,7 @@
 
 static int acf_sort_exec(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 {
-	struct ast_module_user *u;
 	int ret = -1;
-
-	u = ast_module_user_add(chan);
 
 	switch (sort_internal(chan, data, buf, len)) {
 	case ERROR_NOARG:
@@ -241,17 +238,12 @@
 		ast_log(LOG_ERROR, "Unknown internal error\n");
 	}
 
-	ast_module_user_remove(u);
-
 	return ret;
 }
 
 static int acf_cut_exec(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 {
 	int ret = -1;
-	struct ast_module_user *u;
-
-	u = ast_module_user_add(chan);
 
 	switch (cut_internal(chan, data, buf, len)) {
 	case ERROR_NOARG:
@@ -269,8 +261,6 @@
 	default:
 		ast_log(LOG_ERROR, "Unknown internal error\n");
 	}
-
-	ast_module_user_remove(u);
 
 	return ret;
 }

Modified: trunk/funcs/func_enum.c
URL: http://svn.digium.com/view/asterisk/trunk/funcs/func_enum.c?view=diff&rev=75255&r1=75254&r2=75255
==============================================================================
--- trunk/funcs/func_enum.c (original)
+++ trunk/funcs/func_enum.c Mon Jul 16 13:24:29 2007
@@ -67,7 +67,6 @@
 	int res = 0;
 	char tech[80];
 	char dest[256] = "", tmp[2] = "", num[AST_MAX_EXTENSION] = "";
-	struct ast_module_user *u;
 	char *s, *p;
 	unsigned int record = 1;
 
@@ -84,8 +83,6 @@
 		ast_log(LOG_WARNING, synopsis);
 		return -1;
 	}
-
-	u = ast_module_user_add(chan);
 
 	ast_copy_string(tech, args.tech ? args.tech : "sip", sizeof(tech));
 
@@ -115,8 +112,6 @@
 	else
 		ast_copy_string(buf, dest, len);
 
-	ast_module_user_remove(u);
-
 	return 0;
 }
 
@@ -156,7 +151,6 @@
 {
 	struct enum_result_datastore *erds;
 	struct ast_datastore *datastore;
-	struct ast_module_user *u;
 	char *parse, tech[128], dest[128];
 	int res = -1;
 
@@ -166,8 +160,6 @@
 		AST_APP_ARG(zone);
 	);
 
-	u = ast_module_user_add(chan);
-
 	if (ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "ENUMQUERY requires at least a number as an argument...\n");
 		goto finish;
@@ -214,14 +206,12 @@
 	res = 0;
     
 finish:
-	ast_module_user_remove(u);
 
 	return res;
 }
 
 static int enum_result_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 {
-	struct ast_module_user *u;
 	struct enum_result_datastore *erds;
 	struct ast_datastore *datastore;
 	char *parse, *p;
@@ -232,8 +222,6 @@
 		AST_APP_ARG(resultnum);
 	);
 
-	u = ast_module_user_add(chan);
-
 	if (ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "ENUMRESULT requires two arguments (id and resultnum)\n");
 		goto finish;
@@ -298,7 +286,6 @@
 	res = 0;
 
 finish:
-	ast_module_user_remove(u);
 
 	return res;
 }
@@ -349,7 +336,6 @@
 	char tech[80];
 	char txt[256] = "";
 	char dest[80];
-	struct ast_module_user *u;
 
 	buf[0] = '\0';
 
@@ -359,15 +345,11 @@
 		return -1;
 	}
 
-	u = ast_module_user_add(chan);
-
 	res = ast_get_txt(chan, data, dest, sizeof(dest), tech, sizeof(tech), txt,
 			  sizeof(txt));
 
 	if (!ast_strlen_zero(txt))
 		ast_copy_string(buf, txt, len);
-
-	ast_module_user_remove(u);
 
 	return 0;
 }

Modified: trunk/funcs/func_rand.c
URL: http://svn.digium.com/view/asterisk/trunk/funcs/func_rand.c?view=diff&rev=75255&r1=75254&r2=75255
==============================================================================
--- trunk/funcs/func_rand.c (original)
+++ trunk/funcs/func_rand.c Mon Jul 16 13:24:29 2007
@@ -44,14 +44,11 @@
 static int acf_rand_exec(struct ast_channel *chan, const char *cmd,
 			 char *parse, char *buffer, size_t buflen)
 {
-	struct ast_module_user *u;
 	int min_int, response_int, max_int;
 	AST_DECLARE_APP_ARGS(args,
 			     AST_APP_ARG(min);
 			     AST_APP_ARG(max);
 	);
-
-	u = ast_module_user_add(chan);
 
 	AST_STANDARD_APP_ARGS(args, parse);
 
@@ -72,8 +69,6 @@
 	response_int = min_int + (ast_random() % (max_int - min_int + 1));
 	ast_debug(1, "%d was the lucky number in range [%d,%d]\n", response_int, min_int, max_int);
 	snprintf(buffer, buflen, "%d", response_int);
-
-	ast_module_user_remove(u);
 
 	return 0;
 }

Modified: trunk/funcs/func_realtime.c
URL: http://svn.digium.com/view/asterisk/trunk/funcs/func_realtime.c?view=diff&rev=75255&r1=75254&r2=75255
==============================================================================
--- trunk/funcs/func_realtime.c (original)
+++ trunk/funcs/func_realtime.c Mon Jul 16 13:24:29 2007
@@ -48,7 +48,6 @@
 static int function_realtime_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) 
 {
 	struct ast_variable *var, *head;
-	struct ast_module_user *u;
 	struct ast_str *out;
 	size_t resultslen;
 	int n;
@@ -65,8 +64,6 @@
 		return -1;
 	}
 
-	u = ast_module_user_add(chan);
-
 	AST_STANDARD_APP_ARGS(args, data);
 
 	if (!args.delim1)
@@ -76,10 +73,9 @@
 
 	head = ast_load_realtime_all(args.family, args.fieldmatch, args.value, NULL);
 
-	if (!head) {
-		ast_module_user_remove(u);
+	if (!head)
 		return -1;
-	}
+
 	resultslen = 0;
 	n = 0;
 	for (var = head; var; n++, var = var->next)
@@ -92,14 +88,11 @@
 		ast_str_append(&out, 0, "%s%s%s%s", var->name, args.delim2, var->value, args.delim1);
 	ast_copy_string(buf, out->str, len);
 
-	ast_module_user_remove(u);
-
 	return 0;
 }
 
 static int function_realtime_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
 {
-	struct ast_module_user *u;
 	int res = 0;
 	AST_DECLARE_APP_ARGS(args,
 		AST_APP_ARG(family);
@@ -113,8 +106,6 @@
 		return -1;
 	}
 
-	u = ast_module_user_add(chan);
-
 	AST_STANDARD_APP_ARGS(args, data);
 
 	res = ast_update_realtime(args.family, args.fieldmatch, args.value, args.field, (char *)value, NULL);
@@ -122,8 +113,6 @@
 	if (res < 0) {
 		ast_log(LOG_WARNING, "Failed to update. Check the debug log for possible data repository related entries.\n");
 	}
-
-	ast_module_user_remove(u);
 
 	return 0;
 }

Modified: trunk/funcs/func_version.c
URL: http://svn.digium.com/view/asterisk/trunk/funcs/func_version.c?view=diff&rev=75255&r1=75254&r2=75255
==============================================================================
--- trunk/funcs/func_version.c (original)
+++ trunk/funcs/func_version.c Mon Jul 16 13:24:29 2007
@@ -47,13 +47,10 @@
 static int acf_version_exec(struct ast_channel *chan, const char *cmd,
 			 char *parse, char *buffer, size_t buflen)
 {
-	struct ast_module_user *u;
 	char *response_char = ASTERISK_VERSION;
 	AST_DECLARE_APP_ARGS(args,
 			     AST_APP_ARG(info);
 	);
-
-	u = ast_module_user_add(chan);
 
 	AST_STANDARD_APP_ARGS(args, parse);
 
@@ -78,8 +75,6 @@
 
 	ast_debug(1, "VERSION returns %s result, given %s argument\n", response_char, args.info);
 	snprintf(buffer, buflen, "%s", response_char);
-
-	ast_module_user_remove(u);
 
 	return 0;
 }

Modified: trunk/funcs/func_vmcount.c
URL: http://svn.digium.com/view/asterisk/trunk/funcs/func_vmcount.c?view=diff&rev=75255&r1=75254&r2=75255
==============================================================================
--- trunk/funcs/func_vmcount.c (original)
+++ trunk/funcs/func_vmcount.c Mon Jul 16 13:24:29 2007
@@ -47,14 +47,11 @@
 
 static int acf_vmcount_exec(struct ast_channel *chan, const char *cmd, char *argsstr, char *buf, size_t len)
 {
-	struct ast_module_user *u;
 	char *context;
 	AST_DECLARE_APP_ARGS(args,
 		AST_APP_ARG(vmbox);
 		AST_APP_ARG(folder);
 	);
-
-	u = ast_module_user_add(chan);
 
 	buf[0] = '\0';
 
@@ -72,8 +69,6 @@
 	}
 
 	snprintf(buf, len, "%d", ast_app_messagecount(context, args.vmbox, args.folder));
-
-	ast_module_user_remove(u);
 	
 	return 0;
 }

Modified: trunk/include/asterisk/pbx.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/pbx.h?view=diff&rev=75255&r1=75254&r2=75255
==============================================================================
--- trunk/include/asterisk/pbx.h (original)
+++ trunk/include/asterisk/pbx.h Mon Jul 16 13:24:29 2007
@@ -76,6 +76,7 @@
 	const char *syntax;		/*!< Syntax description */
 	int (*read)(struct ast_channel *, const char *, char *, char *, size_t);	/*!< Read function, if read is supported */
 	int (*write)(struct ast_channel *, const char *, char *, const char *);		/*!< Write function, if write is supported */
+	struct ast_module *mod;         /*!< Module this custom function belongs to */
 	AST_RWLIST_ENTRY(ast_custom_function) acflist;
 };
 
@@ -862,9 +863,14 @@
 int ast_custom_function_unregister(struct ast_custom_function *acf);
 
 /*!
- * \brief Reigster a custom function
- */
-int ast_custom_function_register(struct ast_custom_function *acf);
+ * \brief Register a custom function
+ */
+#define ast_custom_function_register(acf) ast_custom_function_register2(acf, ast_module_info->self)
+
+/*!
+ * \brief Register a custom function
+ */
+int ast_custom_function_register2(struct ast_custom_function *acf, struct ast_module *mod);
 
 /*! 
  * \brief Retrieve the number of active calls

Modified: trunk/main/pbx.c
URL: http://svn.digium.com/view/asterisk/trunk/main/pbx.c?view=diff&rev=75255&r1=75254&r2=75255
==============================================================================
--- trunk/main/pbx.c (original)
+++ trunk/main/pbx.c Mon Jul 16 13:24:29 2007
@@ -1410,12 +1410,14 @@
 	return acf ? 0 : -1;
 }
 
-int ast_custom_function_register(struct ast_custom_function *acf)
+int ast_custom_function_register2(struct ast_custom_function *acf, struct ast_module *mod)
 {
 	struct ast_custom_function *cur;
 
 	if (!acf)
 		return -1;
+
+	acf->mod = mod;
 
 	AST_RWLIST_WRLOCK(&acf_root);
 
@@ -1476,8 +1478,16 @@
 		ast_log(LOG_ERROR, "Function %s not registered\n", copy);
 	else if (!acfptr->read)
 		ast_log(LOG_ERROR, "Function %s cannot be read\n", copy);
-	else
-		return acfptr->read(chan, copy, args, workspace, len);
+	else {
+		int res;
+		struct ast_module_user *u = NULL;
+		if (acfptr->mod)
+			u = __ast_module_user_add(acfptr->mod, chan);
+		res = acfptr->read(chan, copy, args, workspace, len);
+		if (acfptr->mod && u)
+			__ast_module_user_remove(acfptr->mod, u);
+		return res;
+	}
 	return -1;
 }
 
@@ -1491,8 +1501,16 @@
 		ast_log(LOG_ERROR, "Function %s not registered\n", copy);
 	else if (!acfptr->write)
 		ast_log(LOG_ERROR, "Function %s cannot be written to\n", copy);
-	else
-		return acfptr->write(chan, copy, args, value);
+	else {
+		int res;
+		struct ast_module_user *u = NULL;
+		if (acfptr->mod)
+			u = __ast_module_user_add(acfptr->mod, chan);
+		res = acfptr->write(chan, copy, args, value);
+		if (acfptr->mod && u)
+			__ast_module_user_remove(acfptr->mod, u);
+		return res;
+	}
 
 	return -1;
 }




More information about the asterisk-commits mailing list