aboutsummaryrefslogtreecommitdiffstats
path: root/pbx.c
diff options
context:
space:
mode:
authorrizzo <rizzo@f38db490-d61c-443f-a65b-d21fe96a405b>2006-05-08 22:15:31 +0000
committerrizzo <rizzo@f38db490-d61c-443f-a65b-d21fe96a405b>2006-05-08 22:15:31 +0000
commit4bed039734f0a229a6258b05e55af2b9176ac441 (patch)
treefb68ec031417fc62df46fce78479454cce48cdaa /pbx.c
parentcd9ab535b1c2fbc87c6ddd959575b0d425b44174 (diff)
remove some common code in parsing function calls
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@25747 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'pbx.c')
-rw-r--r--pbx.c65
1 files changed, 29 insertions, 36 deletions
diff --git a/pbx.c b/pbx.c
index 527b2ef8e..e7777be04 100644
--- a/pbx.c
+++ b/pbx.c
@@ -1197,58 +1197,51 @@ int ast_custom_function_register(struct ast_custom_function *acf)
return 0;
}
-int ast_func_read(struct ast_channel *chan, char *function, char *workspace, size_t len)
+/*! \brief return a pointer to the arguments of the function,
+ * and terminates the function name with '\0'
+ */
+static char *func_args(char *function)
{
- char *args = NULL, *p;
- struct ast_custom_function *acfptr;
+ char *args = strchr(function, '(');
- if ((args = strchr(function, '('))) {
+ if (!args)
+ ast_log(LOG_WARNING, "Function doesn't contain parentheses. Assuming null argument.\n");
+ else {
+ char *p;
*args++ = '\0';
- if ((p = strrchr(args, ')')))
+ if ((p = strrchr(args, ')')) )
*p = '\0';
else
ast_log(LOG_WARNING, "Can't find trailing parenthesis?\n");
- } else {
- ast_log(LOG_WARNING, "Function doesn't contain parentheses. Assuming null argument.\n");
}
+ return args;
+}
- if ((acfptr = ast_custom_function_find(function))) {
- /* run the custom function */
- if (acfptr->read)
- return acfptr->read(chan, function, args, workspace, len);
- else
- ast_log(LOG_ERROR, "Function %s cannot be read\n", function);
- } else {
- ast_log(LOG_ERROR, "Function %s not registered\n", function);
- }
+int ast_func_read(struct ast_channel *chan, char *function, char *workspace, size_t len)
+{
+ char *args = func_args(function);
+ struct ast_custom_function *acfptr = ast_custom_function_find(function);
+ if (acfptr == NULL)
+ ast_log(LOG_ERROR, "Function %s not registered\n", function);
+ else if (!acfptr->read)
+ ast_log(LOG_ERROR, "Function %s cannot be read\n", function);
+ else
+ return acfptr->read(chan, function, args, workspace, len);
return -1;
}
int ast_func_write(struct ast_channel *chan, char *function, const char *value)
{
- char *args = NULL, *p;
- struct ast_custom_function *acfptr;
+ char *args = func_args(function);
+ struct ast_custom_function *acfptr = ast_custom_function_find(function);
- if ((args = strchr(function, '('))) {
- *args++ = '\0';
- if ((p = strrchr(args, ')')))
- *p = '\0';
- else
- ast_log(LOG_WARNING, "Can't find trailing parenthesis?\n");
- } else {
- ast_log(LOG_WARNING, "Function doesn't contain parentheses. Assuming null argument.\n");
- }
-
- if ((acfptr = ast_custom_function_find(function))) {
- /* run the custom function */
- if (acfptr->write)
- return acfptr->write(chan, function, args, value);
- else
- ast_log(LOG_ERROR, "Function %s is read-only, it cannot be written to\n", function);
- } else {
+ if (acfptr == NULL)
ast_log(LOG_ERROR, "Function %s not registered\n", function);
- }
+ else if (!acfptr->write)
+ ast_log(LOG_ERROR, "Function %s cannot be written to\n", function);
+ else
+ return acfptr->write(chan, function, args, value);
return -1;
}