summaryrefslogtreecommitdiff
path: root/pbx.c
diff options
context:
space:
mode:
authorLuigi Rizzo <rizzo@icir.org>2006-05-08 22:15:31 +0000
committerLuigi Rizzo <rizzo@icir.org>2006-05-08 22:15:31 +0000
commit3b5fccac94b3b183dac1e87aca5f00280ee34ba0 (patch)
treefb68ec031417fc62df46fce78479454cce48cdaa /pbx.c
parenta8379be5541c12cd4b3b364dd6fd7328f80fb214 (diff)
remove some common code in parsing function calls
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@25747 65c4cc65-6c06-0410-ace0-fbb531ad65f3
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;
}