diff options
author | kpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b> | 2006-02-12 04:28:58 +0000 |
---|---|---|
committer | kpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b> | 2006-02-12 04:28:58 +0000 |
commit | 5d9ed5739aab2b302efc178d21e6c75672369db3 (patch) | |
tree | 5c4270c1ac3d265b96361d98722a75b947f2f8c6 /funcs | |
parent | 9f87dd693e9e74816b913a157fdcdefa3d7a2e56 (diff) |
major dialplan functions update
deprecate LANGUAGE() and MUSICCLASS(), in favor of CHANNEL()
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@9674 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'funcs')
-rw-r--r-- | funcs/func_base64.c | 41 | ||||
-rw-r--r-- | funcs/func_callerid.c | 92 | ||||
-rw-r--r-- | funcs/func_cdr.c | 80 | ||||
-rw-r--r-- | funcs/func_channel.c | 152 | ||||
-rw-r--r-- | funcs/func_cut.c | 16 | ||||
-rw-r--r-- | funcs/func_db.c | 114 | ||||
-rw-r--r-- | funcs/func_enum.c | 221 | ||||
-rw-r--r-- | funcs/func_env.c | 77 | ||||
-rw-r--r-- | funcs/func_groupcount.c | 83 | ||||
-rw-r--r-- | funcs/func_language.c | 49 | ||||
-rw-r--r-- | funcs/func_logic.c | 73 | ||||
-rw-r--r-- | funcs/func_math.c | 210 | ||||
-rw-r--r-- | funcs/func_md5.c | 55 | ||||
-rw-r--r-- | funcs/func_moh.c | 30 | ||||
-rw-r--r-- | funcs/func_odbc.c | 70 | ||||
-rw-r--r-- | funcs/func_rand.c | 42 | ||||
-rw-r--r-- | funcs/func_sha1.c | 26 | ||||
-rw-r--r-- | funcs/func_strings.c | 225 | ||||
-rw-r--r-- | funcs/func_timeout.c | 98 | ||||
-rw-r--r-- | funcs/func_uri.c | 29 |
20 files changed, 934 insertions, 849 deletions
diff --git a/funcs/func_base64.c b/funcs/func_base64.c index 09ed69136..a50221996 100644 --- a/funcs/func_base64.c +++ b/funcs/func_base64.c @@ -36,31 +36,30 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/utils.h" #include "asterisk/app.h" -static char *base64_encode(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int base64_encode(struct ast_channel *chan, char *cmd, char *data, + char *buf, size_t len) { - int res = 0; - - if (ast_strlen_zero(data) ) { + if (ast_strlen_zero(data)) { ast_log(LOG_WARNING, "Syntax: BASE64_ENCODE(<data>) - missing argument!\n"); - return NULL; + return -1; } - ast_log(LOG_DEBUG, "data=%s\n",data); - res = ast_base64encode(buf, (unsigned char *)data, strlen(data), len); - ast_log(LOG_DEBUG, "res=%d\n", res); - return buf; + ast_base64encode(buf, (unsigned char *) data, strlen(data), len); + + return 0; } -static char *base64_decode(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int base64_decode(struct ast_channel *chan, char *cmd, char *data, + char *buf, size_t len) { - if (ast_strlen_zero(data) ) { + if (ast_strlen_zero(data)) { ast_log(LOG_WARNING, "Syntax: BASE64_DECODE(<base_64 string>) - missing argument!\n"); - return NULL; + return -1; } - ast_log(LOG_DEBUG, "data=%s\n", data); - ast_base64decode((unsigned char *)buf, data, len); - return buf; + ast_base64decode((unsigned char *) buf, data, len); + + return 0; } static struct ast_custom_function base64_encode_function = { @@ -83,13 +82,13 @@ static char *tdesc = "base64 encode/decode dialplan functions"; int unload_module(void) { - return ast_custom_function_unregister(&base64_encode_function) || + return ast_custom_function_unregister(&base64_encode_function) | ast_custom_function_unregister(&base64_decode_function); } int load_module(void) { - return ast_custom_function_register(&base64_encode_function) || + return ast_custom_function_register(&base64_encode_function) | ast_custom_function_register(&base64_decode_function); } @@ -107,11 +106,3 @@ char *key() { return ASTERISK_GPL_KEY; } - -/* -Local Variables: -mode: C -c-file-style: "linux" -indent-tabs-mode: nil -End: -*/ diff --git a/funcs/func_callerid.c b/funcs/func_callerid.c index c907d96a9..056999e88 100644 --- a/funcs/func_callerid.c +++ b/funcs/func_callerid.c @@ -1,7 +1,7 @@ /* * Asterisk -- An open source telephony toolkit. * - * Copyright (C) 1999 - 2005, Digium, Inc. + * Copyright (C) 1999-2006, Digium, Inc. * * See http://www.asterisk.org for more information about * the Asterisk project. Please do not directly contact @@ -28,7 +28,6 @@ #include "asterisk.h" ASTERISK_FILE_VERSION(__FILE__, "$Revision$") - #include "asterisk/module.h" #include "asterisk/channel.h" #include "asterisk/pbx.h" @@ -38,7 +37,8 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/options.h" #include "asterisk/callerid.h" -static char *callerid_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int callerid_read(struct ast_channel *chan, char *cmd, char *data, + char *buf, size_t len) { char *opt = data; @@ -49,22 +49,27 @@ static char *callerid_read(struct ast_channel *chan, char *cmd, char *data, char ast_callerid_split(opt, name, sizeof(name), num, sizeof(num)); if (!strncasecmp("all", data, 3)) { - snprintf(buf, len, "\"%s\" <%s>", name, num); + snprintf(buf, len, "\"%s\" <%s>", name, num); } else if (!strncasecmp("name", data, 4)) { ast_copy_string(buf, name, len); - } else if (!strncasecmp("num", data, 3) || !strncasecmp("number", data, 6)) { + } else if (!strncasecmp("num", data, 3) || + !strncasecmp("number", data, 6)) { + ast_copy_string(buf, num, len); } else { ast_log(LOG_ERROR, "Unknown callerid data type.\n"); } } else { if (!strncasecmp("all", data, 3)) { - snprintf(buf, len, "\"%s\" <%s>", chan->cid.cid_name ? chan->cid.cid_name : "", chan->cid.cid_num ? chan->cid.cid_num : ""); + snprintf(buf, len, "\"%s\" <%s>", + chan->cid.cid_name ? chan->cid.cid_name : "", + chan->cid.cid_num ? chan->cid.cid_num : ""); } else if (!strncasecmp("name", data, 4)) { if (chan->cid.cid_name) { ast_copy_string(buf, chan->cid.cid_name, len); } - } else if (!strncasecmp("num", data, 3) || !strncasecmp("number", data, 6)) { + } else if (!strncasecmp("num", data, 3) + || !strncasecmp("number", data, 6)) { if (chan->cid.cid_num) { ast_copy_string(buf, chan->cid.cid_num, len); } @@ -84,47 +89,54 @@ static char *callerid_read(struct ast_channel *chan, char *cmd, char *data, char ast_log(LOG_ERROR, "Unknown callerid data type.\n"); } } - return buf; + + return 0; } -static void callerid_write(struct ast_channel *chan, char *cmd, char *data, const char *value) +static int callerid_write(struct ast_channel *chan, char *cmd, char *data, + const char *value) { if (!value) - return; - + return -1; + if (!strncasecmp("all", data, 3)) { char name[256]; char num[256]; + if (!ast_callerid_split(value, name, sizeof(name), num, sizeof(num))) - ast_set_callerid(chan, num, name, num); - } else if (!strncasecmp("name", data, 4)) { - ast_set_callerid(chan, NULL, value, NULL); - } else if (!strncasecmp("num", data, 3) || !strncasecmp("number", data, 6)) { - ast_set_callerid(chan, value, NULL, NULL); - } else if (!strncasecmp("ani", data, 3)) { - ast_set_callerid(chan, NULL, NULL, value); - } else if (!strncasecmp("dnid", data, 4)) { - /* do we need to lock chan here? */ - if (chan->cid.cid_dnid) - free(chan->cid.cid_dnid); - chan->cid.cid_dnid = ast_strlen_zero(value) ? NULL : strdup(value); - } else if (!strncasecmp("rdnis", data, 5)) { - /* do we need to lock chan here? */ - if (chan->cid.cid_rdnis) - free(chan->cid.cid_rdnis); - chan->cid.cid_rdnis = ast_strlen_zero(value) ? NULL : strdup(value); - } else { - ast_log(LOG_ERROR, "Unknown callerid data type.\n"); - } + ast_set_callerid(chan, num, name, num); + } else if (!strncasecmp("name", data, 4)) { + ast_set_callerid(chan, NULL, value, NULL); + } else if (!strncasecmp("num", data, 3) || + !strncasecmp("number", data, 6)) { + ast_set_callerid(chan, value, NULL, NULL); + } else if (!strncasecmp("ani", data, 3)) { + ast_set_callerid(chan, NULL, NULL, value); + } else if (!strncasecmp("dnid", data, 4)) { + /* do we need to lock chan here? */ + if (chan->cid.cid_dnid) + free(chan->cid.cid_dnid); + chan->cid.cid_dnid = ast_strlen_zero(value) ? NULL : strdup(value); + } else if (!strncasecmp("rdnis", data, 5)) { + /* do we need to lock chan here? */ + if (chan->cid.cid_rdnis) + free(chan->cid.cid_rdnis); + chan->cid.cid_rdnis = ast_strlen_zero(value) ? NULL : strdup(value); + } else { + ast_log(LOG_ERROR, "Unknown callerid data type.\n"); + } + + return 0; } static struct ast_custom_function callerid_function = { .name = "CALLERID", .synopsis = "Gets or sets Caller*ID data on the channel.", .syntax = "CALLERID(datatype[,<optional-CID>])", - .desc = "Gets or sets Caller*ID data on the channel. The allowable datatypes\n" - "are \"all\", \"name\", \"num\", \"ANI\", \"DNID\", \"RDNIS\".\n" - "Uses channel callerid by default or optional callerid, if specified.\n", + .desc = + "Gets or sets Caller*ID data on the channel. The allowable datatypes\n" + "are \"all\", \"name\", \"num\", \"ANI\", \"DNID\", \"RDNIS\".\n" + "Uses channel callerid by default or optional callerid, if specified.\n", .read = callerid_read, .write = callerid_write, }; @@ -133,12 +145,12 @@ static char *tdesc = "Caller ID related dialplan function"; int unload_module(void) { - return ast_custom_function_unregister(&callerid_function); + return ast_custom_function_unregister(&callerid_function); } int load_module(void) { - return ast_custom_function_register(&callerid_function); + return ast_custom_function_register(&callerid_function); } char *description(void) @@ -155,11 +167,3 @@ char *key() { return ASTERISK_GPL_KEY; } - -/* -Local Variables: -mode: C -c-file-style: "linux" -indent-tabs-mode: nil -End: -*/ diff --git a/funcs/func_cdr.c b/funcs/func_cdr.c index 205651a1c..d287ff98a 100644 --- a/funcs/func_cdr.c +++ b/funcs/func_cdr.c @@ -1,7 +1,7 @@ /* * Asterisk -- An open source telephony toolkit. * - * Copyright (C) 1999 - 2005, Digium, Inc. + * Copyright (C) 1999-2006, Digium, Inc. * * Portions Copyright (C) 2005, Anthony Minessale II * @@ -47,71 +47,65 @@ AST_APP_OPTIONS(cdr_func_options, { AST_APP_OPTION('r', OPT_RECURSIVE), }); -static char *cdr_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int cdr_read(struct ast_channel *chan, char *cmd, char *parse, + char *buf, size_t len) { char *ret; - char *parse; - struct ast_flags flags = {0}; - + struct ast_flags flags = { 0 }; AST_DECLARE_APP_ARGS(args, - AST_APP_ARG(variable); - AST_APP_ARG(options); + AST_APP_ARG(variable); + AST_APP_ARG(options); ); - if (ast_strlen_zero(data)) - return NULL; - - if (!chan->cdr) - return NULL; + if (ast_strlen_zero(parse)) + return -1; - if (!(parse = ast_strdupa(data))) - return NULL; + if (!chan->cdr) + return -1; AST_STANDARD_APP_ARGS(args, parse); - - if(!ast_strlen_zero(args.options) ) { + + if (!ast_strlen_zero(args.options)) ast_app_parse_options(cdr_func_options, &flags, NULL, args.options); - } - ast_cdr_getvar(chan->cdr, args.variable, &ret, buf, len, (ast_test_flag(&flags,OPT_RECURSIVE) ) ? 1 : 0 ); - return ret; + ast_cdr_getvar(chan->cdr, args.variable, &ret, buf, len, + ast_test_flag(&flags, OPT_RECURSIVE)); + + return 0; } -static void cdr_write(struct ast_channel *chan, char *cmd, char *data, const char *value) +static int cdr_write(struct ast_channel *chan, char *cmd, char *parse, + const char *value) { - char *parse; - struct ast_flags flags = {0}; - - AST_DECLARE_APP_ARGS(args, - AST_APP_ARG(variable); - AST_APP_ARG(options); - ); + struct ast_flags flags = { 0 }; + AST_DECLARE_APP_ARGS(args, + AST_APP_ARG(variable); + AST_APP_ARG(options); + ); - if (ast_strlen_zero(data) || !value) - return; - - if (!(parse = ast_strdupa(data))) - return; + if (ast_strlen_zero(parse) || !value) + return -1; AST_STANDARD_APP_ARGS(args, parse); - /* check for a trailing flags argument */ - if(!ast_strlen_zero(args.options) ) { + if (!ast_strlen_zero(args.options)) ast_app_parse_options(cdr_func_options, &flags, NULL, args.options); - } if (!strcasecmp(args.variable, "accountcode")) ast_cdr_setaccount(chan, value); else if (!strcasecmp(args.variable, "userfield")) ast_cdr_setuserfield(chan, value); else if (chan->cdr) - ast_cdr_setvar(chan->cdr, args.variable, value, (ast_test_flag(&flags,OPT_RECURSIVE) ) ? 1 : 0 ); + ast_cdr_setvar(chan->cdr, args.variable, value, + ast_test_flag(&flags, OPT_RECURSIVE)); + + return 0; } static struct ast_custom_function cdr_function = { .name = "CDR", .synopsis = "Gets or sets a CDR variable", - .desc= "Option 'r' searches the entire stack of CDRs on the channel\n", + .desc = "Option 'r' searches the entire stack of CDRs on the channel\n", .syntax = "CDR(<name>[|options])", .read = cdr_read, .write = cdr_write, @@ -121,12 +115,12 @@ static char *tdesc = "CDR dialplan function"; int unload_module(void) { - return ast_custom_function_unregister(&cdr_function); + return ast_custom_function_unregister(&cdr_function); } int load_module(void) { - return ast_custom_function_register(&cdr_function); + return ast_custom_function_register(&cdr_function); } char *description(void) @@ -143,11 +137,3 @@ char *key() { return ASTERISK_GPL_KEY; } - -/* -Local Variables: -mode: C -c-file-style: "linux" -indent-tabs-mode: nil -End: -*/ diff --git a/funcs/func_channel.c b/funcs/func_channel.c new file mode 100644 index 000000000..82fbd639b --- /dev/null +++ b/funcs/func_channel.c @@ -0,0 +1,152 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2006, Digium, Inc. + * + * 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 Channel info dialplan function + * + * \author Kevin P. Fleming <kpfleming@digium.com> + * + */ + +#include <stdlib.h> +#include <string.h> +#include <sys/types.h> + +#include "asterisk.h" + +ASTERISK_FILE_VERSION(__FILE__, "$Revision: $") +#include "asterisk/module.h" +#include "asterisk/channel.h" +#include "asterisk/pbx.h" +#include "asterisk/logger.h" +#include "asterisk/utils.h" +#include "asterisk/app.h" +#include "asterisk/indications.h" +#include "asterisk/stringfields.h" +#define locked_copy_string(chan, dest, source, len) \ + do { \ + ast_mutex_lock(&chan->lock); \ + ast_copy_string(dest, source, len); \ + ast_mutex_unlock(&chan->lock); \ + } while (0) +#define locked_string_field_set(chan, field, source) \ + do { \ + ast_mutex_lock(&chan->lock); \ + ast_string_field_set(chan, field, source); \ + ast_mutex_unlock(&chan->lock); \ + } while (0) + +static int func_channel_read(struct ast_channel *chan, char *function, + char *data, char *buf, size_t len) +{ + int ret = 0; + + if (!strcasecmp(data, "audionativeformat")) + /* use the _multiple version when chan->nativeformats holds multiple formats */ + /* ast_getformatname_multiple(buf, len, chan->nativeformats & AST_FORMAT_AUDIO_MASK); */ + ast_copy_string(buf, ast_getformatname(chan->nativeformats & AST_FORMAT_AUDIO_MASK), len); + else if (!strcasecmp(data, "videonativeformat")) + /* use the _multiple version when chan->nativeformats holds multiple formats */ + /* ast_getformatname_multiple(buf, len, chan->nativeformats & AST_FORMAT_VIDEO_MASK); */ + ast_copy_string(buf, ast_getformatname(chan->nativeformats & AST_FORMAT_VIDEO_MASK), len); + else if (!strcasecmp(data, "audioreadformat")) + ast_copy_string(buf, ast_getformatname(chan->readformat), len); + else if (!strcasecmp(data, "audiowriteformat")) + ast_copy_string(buf, ast_getformatname(chan->writeformat), len); + else if (!strcasecmp(data, "tonezone") && chan->zone) + locked_copy_string(chan, buf, chan->zone->country, len); + else if (!strcasecmp(data, "language")) + locked_copy_string(chan, buf, chan->language, len); + else if (!strcasecmp(data, "musicclass")) + locked_copy_string(chan, buf, chan->musicclass, len); + else if (!chan->tech->func_channel_read + || chan->tech->func_channel_read(chan, function, data, buf, len)) { + ast_log(LOG_WARNING, "Unknown or unavailable item requested: '%s'\n", data); + ret = -1; + } + + return ret; +} + +static int func_channel_write(struct ast_channel *chan, char *function, + char *data, const char *value) +{ + int ret = 0; + + if (!strcasecmp(data, "language")) + locked_string_field_set(chan, language, value); + else if (!strcasecmp(data, "musicclass")) + locked_string_field_set(chan, musicclass, value); + else if (!chan->tech->func_channel_write + || chan->tech->func_channel_write(chan, function, data, value)) { + ast_log(LOG_WARNING, "Unknown or unavailable item requested: '%s'\n", + data); + ret = -1; + } + + return ret; +} + +static struct ast_custom_function channel_function = { + .name = "CHANNEL", + .synopsis = "Gets/sets various pieces of information about the channel.", + .syntax = "CHANNEL(item)", + .desc = "Gets/set various pieces of information about the channel.\n" + "Standard items (provided by all channel technologies) are:\n" + "R/O audioreadformat format currently being read\n" + "R/O audionativeformat format used natively for audio\n" + "R/O audiowriteformat format currently being written\n" + "R/W language language for sounds played\n" + "R/W musicclass class (from musiconhold.conf) for hold music\n" + "R/O tonezone zone for indications played\n" + "R/O videonativeformat format used natively for video\n" + "\n" + "Additional items may be available from the channel driver providing\n" + "the channel; see its documentation for details.\n" + "\n" + "Any item requested that is not available on the current channel will\n" + "return an empty string.\n", + .read = func_channel_read, + .write = func_channel_write, +}; + +static char *tdesc = "Channel information dialplan function"; + +int unload_module(void) +{ + return ast_custom_function_unregister(&channel_function); +} + +int load_module(void) +{ + return ast_custom_function_register(&channel_function); +} + +char *description(void) +{ + return tdesc; +} + +int usecount(void) +{ + return 0; +} + +char *key() +{ + return ASTERISK_GPL_KEY; +} diff --git a/funcs/func_cut.c b/funcs/func_cut.c index 7b3d2bff8..c34b7d740 100644 --- a/funcs/func_cut.c +++ b/funcs/func_cut.c @@ -1,7 +1,7 @@ /* * Asterisk -- An open source telephony toolkit. * - * Copyright (c) 2003 Tilghman Lesher. All rights reserved. + * Copyright (c) 2003-2006 Tilghman Lesher. All rights reserved. * * Tilghman Lesher <app_cut__v003@the-tilghman.com> * @@ -228,9 +228,10 @@ static int cut_internal(struct ast_channel *chan, char *data, char *buffer, size return 0; } -static char *acf_sort_exec(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int acf_sort_exec(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) { struct localuser *u; + int ret = -1; LOCAL_USER_ACF_ADD(u); @@ -242,16 +243,19 @@ static char *acf_sort_exec(struct ast_channel *chan, char *cmd, char *data, char ast_log(LOG_ERROR, "Out of memory\n"); break; case 0: + ret = 0; break; default: ast_log(LOG_ERROR, "Unknown internal error\n"); } LOCAL_USER_REMOVE(u); - return buf; + + return ret; } -static char *acf_cut_exec(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int acf_cut_exec(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) { + int ret = -1; struct localuser *u; LOCAL_USER_ACF_ADD(u); @@ -267,12 +271,14 @@ static char *acf_cut_exec(struct ast_channel *chan, char *cmd, char *data, char ast_log(LOG_ERROR, "Usage: CUT(<varname>,<char-delim>,<range-spec>)\n"); break; case 0: + ret = 0; break; default: ast_log(LOG_ERROR, "Unknown internal error\n"); } LOCAL_USER_REMOVE(u); - return buf; + + return ret; } struct ast_custom_function acf_sort = { diff --git a/funcs/func_db.c b/funcs/func_db.c index efce117c8..a519fb0ff 100644 --- a/funcs/func_db.c +++ b/funcs/func_db.c @@ -1,7 +1,7 @@ /* * Asterisk -- An open source telephony toolkit. * - * Copyright (C) 2005, Russell Bryant <russelb@clemson.edu> + * Copyright (C) 2005-2006, Russell Bryant <russelb@clemson.edu> * * func_db.c adapted from the old app_db.c, copyright by the following people * Copyright (C) 2005, Mark Spencer <markster@digium.com> @@ -43,80 +43,69 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/app.h" #include "asterisk/astdb.h" -static char *function_db_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int function_db_read(struct ast_channel *chan, char *cmd, + char *parse, char *buf, size_t len) { - char *parse; AST_DECLARE_APP_ARGS(args, - AST_APP_ARG(family); - AST_APP_ARG(key); + AST_APP_ARG(family); + AST_APP_ARG(key); ); - if (ast_strlen_zero(data)) { + buf[0] = '\0'; + + if (ast_strlen_zero(parse)) { ast_log(LOG_WARNING, "DB requires an argument, DB(<family>/<key>)\n"); - buf[0] = '\0'; - return buf; + return -1; } - parse = ast_strdupa(data); - if (!parse) { - ast_log(LOG_ERROR, "Out of memory!\n"); - buf[0] = '\0'; - return buf; - } - AST_NONSTANDARD_APP_ARGS(args, parse, '/'); - + if (args.argc < 2) { ast_log(LOG_WARNING, "DB requires an argument, DB(<family>/<key>)\n"); - buf[0] = '\0'; - return buf; + return -1; } - if (ast_db_get(args.family, args.key, buf, len-1)) { - ast_log(LOG_DEBUG, "DB: %s/%s not found in database.\n", args.family, args.key); + if (ast_db_get(args.family, args.key, buf, len - 1)) { + ast_log(LOG_DEBUG, "DB: %s/%s not found in database.\n", args.family, + args.key); } else pbx_builtin_setvar_helper(chan, "DB_RESULT", buf); - - return buf; + return 0; } -static void function_db_write(struct ast_channel *chan, char *cmd, char *data, const char *value) +static int function_db_write(struct ast_channel *chan, char *cmd, char *parse, + const char *value) { - char *parse; AST_DECLARE_APP_ARGS(args, - AST_APP_ARG(family); - AST_APP_ARG(key); + AST_APP_ARG(family); + AST_APP_ARG(key); ); - if (ast_strlen_zero(data)) { + if (ast_strlen_zero(parse)) { ast_log(LOG_WARNING, "DB requires an argument, DB(<family>/<key>)=<value>\n"); - return; - } - - parse = ast_strdupa(data); - if (!parse) { - ast_log(LOG_ERROR, "Out of memory!\n"); - return; + return -1; } AST_NONSTANDARD_APP_ARGS(args, parse, '/'); if (args.argc < 2) { ast_log(LOG_WARNING, "DB requires an argument, DB(<family>/<key>)=value\n"); - return; + return -1; } - if (ast_db_put(args.family, args.key, (char*)value)) { + if (ast_db_put(args.family, args.key, (char *) value)) ast_log(LOG_WARNING, "DB: Error writing value to database.\n"); - } + + return 0; } static struct ast_custom_function db_function = { .name = "DB", .synopsis = "Read or Write from/to the Asterisk database", .syntax = "DB(<family>/<key>)", - .desc = "This function will read or write a value from/to the Asterisk database.\n" + .desc = + "This function will read or write a value from/to the Asterisk database.\n" "DB(...) will read a value from the database, while DB(...)=value\n" "will write a value to the database. On a read, this function\n" "returns the value from the datase, or NULL if it does not exist.\n" @@ -126,50 +115,44 @@ static struct ast_custom_function db_function = { .write = function_db_write, }; -static char *function_db_exists(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int function_db_exists(struct ast_channel *chan, char *cmd, + char *parse, char *buf, size_t len) { - char *parse; AST_DECLARE_APP_ARGS(args, - AST_APP_ARG(family); - AST_APP_ARG(key); + AST_APP_ARG(family); + AST_APP_ARG(key); ); - if (ast_strlen_zero(data)) { + buf[0] = '\0'; + + if (ast_strlen_zero(parse)) { ast_log(LOG_WARNING, "DB_EXISTS requires an argument, DB(<family>/<key>)\n"); - buf[0] = '\0'; - return buf; + return -1; } - parse = ast_strdupa(data); - if (!parse) { - ast_log(LOG_ERROR, "Out of memory!\n"); - buf[0] = '\0'; - return buf; - } - AST_NONSTANDARD_APP_ARGS(args, parse, '/'); - + if (args.argc < 2) { ast_log(LOG_WARNING, "DB_EXISTS requires an argument, DB(<family>/<key>)\n"); - buf[0] = '\0'; - return buf; + return -1; } - if (ast_db_get(args.family, args.key, buf, len-1)) - ast_copy_string(buf, "0", len); + if (ast_db_get(args.family, args.key, buf, len - 1)) + strcpy(buf, "0"); else { pbx_builtin_setvar_helper(chan, "DB_RESULT", buf); - ast_copy_string(buf, "1", len); + strcpy(buf, "1"); } - - return buf; + + return 0; } static struct ast_custom_function db_exists_function = { .name = "DB_EXISTS", .synopsis = "Check to see if a key exists in the Asterisk database", .syntax = "DB_EXISTS(<family>/<key>)", - .desc = "This function will check to see if a key exists in the Asterisk\n" + .desc = + "This function will check to see if a key exists in the Asterisk\n" "database. If it exists, the function will return \"1\". If not,\n" "it will return \"0\". Checking for existence of a database key will\n" "also set the variable DB_RESULT to the key's value if it exists.\n", @@ -181,7 +164,7 @@ static char *tdesc = "Database (astdb) related dialplan functions"; int unload_module(void) { int res = 0; - + res |= ast_custom_function_unregister(&db_function); res |= ast_custom_function_unregister(&db_exists_function); @@ -191,7 +174,7 @@ int unload_module(void) int load_module(void) { int res = 0; - + res |= ast_custom_function_register(&db_function); res |= ast_custom_function_register(&db_exists_function); @@ -200,7 +183,7 @@ int load_module(void) char *description(void) { - return tdesc; + return tdesc; } int usecount(void) @@ -210,6 +193,5 @@ int usecount(void) char *key() { - return ASTERISK_GPL_KEY; + return ASTERISK_GPL_KEY; } - diff --git a/funcs/func_enum.c b/funcs/func_enum.c index 8a063bee7..23264408c 100644 --- a/funcs/func_enum.c +++ b/funcs/func_enum.c @@ -1,7 +1,7 @@ /* * Asterisk -- An open source telephony toolkit. * - * Copyright (C) 1999 - 2005 + * Copyright (C) 1999 - 2006 * * Mark Spencer <markster@digium.com> * Oleksiy Krivoshey <oleksiyk@gmail.com> @@ -40,124 +40,100 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/channel.h" #include "asterisk/pbx.h" #include "asterisk/utils.h" - #include "asterisk/lock.h" #include "asterisk/file.h" #include "asterisk/logger.h" - #include "asterisk/pbx.h" #include "asterisk/options.h" - #include "asterisk/enum.h" +#include "asterisk/app.h" -static char* synopsis = "Syntax: ENUMLOOKUP(number[,Method-type[,options|record#[,zone-suffix]]])\n"; + static char *synopsis = "Syntax: ENUMLOOKUP(number[|Method-type[|options[|record#[|zone-suffix]]]])\n"; STANDARD_LOCAL_USER; LOCAL_USER_DECL; -static char *function_enum(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int function_enum(struct ast_channel *chan, char *cmd, char *data, + char *buf, size_t len) { - int res=0; - char tech[80]; - char dest[80] = ""; - char *zone; - char *options; - struct localuser *u; - char *params[4]; - char *p = data; - char *s; - int i = 0; - - - if (ast_strlen_zero(data)) { - ast_log(LOG_WARNING, synopsis); - return ""; - } - - do { - if(i>3){ - ast_log(LOG_WARNING, synopsis); - return ""; - } - params[i++] = p; - p = strchr(p, '|'); - if(p){ - *p = '\0'; - p++; - } - } while(p); - - if(i < 1){ - ast_log(LOG_WARNING, synopsis); - return ""; - } - - if( (i > 1 && strlen(params[1]) == 0) || i < 2){ - ast_copy_string(tech, "sip", sizeof(tech)); - } else { - ast_copy_string(tech, params[1], sizeof(tech)); - } - - if( (i > 3 && strlen(params[3]) == 0) || i<4){ - zone = "e164.arpa"; - } else { - zone = params[3]; - } - - if( (i > 2 && strlen(params[2]) == 0) || i<3){ - options = "1"; - } else { - options = params[2]; - } - - /* strip any '-' signs from number */ - p = params[0]; - /* - while(*p == '+'){ - p++; - } - */ - s = p; - i = 0; - while(*p && *s){ - if(*s == '-'){ - s++; - } else { - p[i++] = *s++; - } - } - p[i] = 0; - - LOCAL_USER_ACF_ADD(u); - - res = ast_get_enum(chan, p, dest, sizeof(dest), tech, sizeof(tech), zone, options); - - LOCAL_USER_REMOVE(u); - - p = strchr(dest, ':'); - if(p && strncasecmp(tech, "ALL", sizeof(tech))) { - ast_copy_string(buf, p+1, sizeof(dest)); - } else { - ast_copy_string(buf, dest, sizeof(dest)); - } - - return buf; + AST_DECLARE_APP_ARGS(args, + AST_APP_ARG(number); + AST_APP_ARG(tech); + AST_APP_ARG(options); + AST_APP_ARG(record); + AST_APP_ARG(zone); + ); + int res = 0; + char tech[80]; + char dest[80] = ""; + char *zone; + char *options; + struct localuser *u; + char *s, *p; + + buf[0] = '\0'; + + if (ast_strlen_zero(data)) { + ast_log(LOG_WARNING, synopsis); + return -1; + } + + AST_STANDARD_APP_ARGS(args, data); + + if (args.argc < 1) { + ast_log(LOG_WARNING, synopsis); + return -1; + } + + ast_copy_string(tech, args.tech ? args.tech : "sip", sizeof(tech)); + + if (!args.zone) + args.zone = "e164.arpa"; + + if (!args.options) + args.options = "1"; + + /* strip any '-' signs from number */ + for (p = args.number, s = p; *s; *s++) { + if (*s != '-') + *p++ = *s; + } + *p = '\0'; + + LOCAL_USER_ACF_ADD(u); + + res = ast_get_enum(chan, p, dest, sizeof(dest), tech, sizeof(tech), zone, + options); + + LOCAL_USER_REMOVE(u); + + p = strchr(dest, ':'); + if (p && strcasecmp(tech, "ALL")) + ast_copy_string(buf, p + 1, len); + else + ast_copy_string(buf, dest, len); + + return 0; } static struct ast_custom_function enum_function = { - .name = "ENUMLOOKUP", - .synopsis = "ENUMLOOKUP allows for general or specific querying of NAPTR records" - " or counts of NAPTR types for ENUM or ENUM-like DNS pointers", - .syntax = "ENUMLOOKUP(number[,Method-type[,options|record#[,zone-suffix]]])", - .desc = "Option 'c' returns an integer count of the number of NAPTRs of a certain RR type.\n" - "Combination of 'c' and Method-type of 'ALL' will return a count of all NAPTRs for the record.\n" - "Defaults are: Method-type=sip, no options, record=1, zone-suffix=e164.arpa\n\n" - "For more information, see README.enum", - .read = function_enum, + .name = "ENUMLOOKUP", + .synopsis = + "ENUMLOOKUP allows for general or specific querying of NAPTR records" + " or counts of NAPTR types for ENUM or ENUM-like DNS pointers", + .syntax = + "ENUMLOOKUP(number[|Method-type[|options[|record#[|zone-suffix]]]])", + .desc = + "Option 'c' returns an integer count of the number of NAPTRs of a certain RR type.\n" + "Combination of 'c' and Method-type of 'ALL' will return a count of all NAPTRs for the record.\n" + "Defaults are: Method-type=sip, no options, record=1, zone-suffix=e164.arpa\n\n" + "For more information, see README.enum", + .read = function_enum, }; -static char *function_txtcidname(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int function_txtcidname(struct ast_channel *chan, char *cmd, + char *data, char *buf, size_t len) { int res; char tech[80]; @@ -165,34 +141,36 @@ static char *function_txtcidname(struct ast_channel *chan, char *cmd, char *data char dest[80]; struct localuser *u; - LOCAL_USER_ACF_ADD(u); - buf[0] = '\0'; + LOCAL_USER_ACF_ADD(u); + if (ast_strlen_zero(data)) { ast_log(LOG_WARNING, "TXTCIDNAME requires an argument (number)\n"); LOCAL_USER_REMOVE(u); - return buf; + return -1; } - res = ast_get_txt(chan, data, dest, sizeof(dest), tech, sizeof(tech), txt, sizeof(txt)); - + 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); - + LOCAL_USER_REMOVE(u); - return buf; + return 0; } static struct ast_custom_function txtcidname_function = { - .name = "TXTCIDNAME", - .synopsis = "TXTCIDNAME looks up a caller name via DNS", - .syntax = "TXTCIDNAME(<number>)", - .desc = "This function looks up the given phone number in DNS to retrieve\n" - "the caller id name. The result will either be blank or be the value\n" - "found in the TXT record in DNS.\n", - .read = function_txtcidname, + .name = "TXTCIDNAME", + .synopsis = "TXTCIDNAME looks up a caller name via DNS", + .syntax = "TXTCIDNAME(<number>)", + .desc = + "This function looks up the given phone number in DNS to retrieve\n" + "the caller id name. The result will either be blank or be the value\n" + "found in the TXT record in DNS.\n", + .read = function_txtcidname, }; static char *tdesc = "ENUM related dialplan functions"; @@ -200,19 +178,19 @@ static char *tdesc = "ENUM related dialplan functions"; int unload_module(void) { int res = 0; - + res |= ast_custom_function_unregister(&enum_function); res |= ast_custom_function_unregister(&txtcidname_function); STANDARD_HANGUP_LOCALUSERS; - + return res; } int load_module(void) { int res = 0; - + res |= ast_custom_function_register(&enum_function); res |= ast_custom_function_register(&txtcidname_function); @@ -221,13 +199,13 @@ int load_module(void) char *description(void) { - return tdesc; + return tdesc; } int usecount(void) { int res; - + STANDARD_USECOUNT(res); return res; @@ -235,6 +213,5 @@ int usecount(void) char *key() { - return ASTERISK_GPL_KEY; + return ASTERISK_GPL_KEY; } - diff --git a/funcs/func_env.c b/funcs/func_env.c index f9d1a665c..87bd96ffc 100644 --- a/funcs/func_env.c +++ b/funcs/func_env.c @@ -1,7 +1,7 @@ /* * Asterisk -- An open source telephony toolkit. * - * Copyright (C) 1999 - 2005, Digium, Inc. + * Copyright (C) 1999 - 2006, Digium, Inc. * * See http://www.asterisk.org for more information about * the Asterisk project. Please do not directly contact @@ -37,21 +37,24 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/utils.h" #include "asterisk/app.h" -static char *env_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int env_read(struct ast_channel *chan, char *cmd, char *data, + char *buf, size_t len) { - char *ret = ""; + char *ret = NULL; - if (data) { + *buf = '\0'; + + if (data) ret = getenv(data); - if (!ret) - ret = ""; - } - ast_copy_string(buf, ret, len); - return buf; + if (ret) + ast_copy_string(buf, ret, len); + + return 0; } -static void env_write(struct ast_channel *chan, char *cmd, char *data, const char *value) +static int env_write(struct ast_channel *chan, char *cmd, char *data, + const char *value) { if (!ast_strlen_zero(data)) { if (!ast_strlen_zero(value)) { @@ -60,29 +63,28 @@ static void env_write(struct ast_channel *chan, char *cmd, char *data, const cha unsetenv(data); } } + + return 0; } -static char *stat_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int stat_read(struct ast_channel *chan, char *cmd, char *data, + char *buf, size_t len) { char *action; struct stat s; - ast_copy_string(buf, "0", len); - if (!data) { - ast_log(LOG_ERROR, "Out of memory\n"); - return buf; - } + *buf = '\0'; action = strsep(&data, "|"); if (stat(data, &s)) { - return buf; + return -1; } else { switch (*action) { case 'e': - ast_copy_string(buf, "1", len); + strcpy(buf, "1"); break; case 's': - snprintf(buf, len, "%d", (unsigned int)s.st_size); + snprintf(buf, len, "%d", (unsigned int) s.st_size); break; case 'f': snprintf(buf, len, "%d", S_ISREG(s.st_mode) ? 1 : 0); @@ -91,20 +93,21 @@ static char *stat_read(struct ast_channel *chan, char *cmd, char *data, char *bu snprintf(buf, len, "%d", S_ISDIR(s.st_mode) ? 1 : 0); break; case 'M': - snprintf(buf, len, "%d", (int)s.st_mtime); + snprintf(buf, len, "%d", (int) s.st_mtime); break; case 'A': - snprintf(buf, len, "%d", (int)s.st_mtime); + snprintf(buf, len, "%d", (int) s.st_mtime); break; case 'C': - snprintf(buf, len, "%d", (int)s.st_ctime); + snprintf(buf, len, "%d", (int) s.st_ctime); break; case 'm': - snprintf(buf, len, "%o", (int)s.st_mode); + snprintf(buf, len, "%o", (int) s.st_mode); break; } } - return buf; + + return 0; } static struct ast_custom_function env_function = { @@ -121,15 +124,15 @@ static struct ast_custom_function stat_function = { .syntax = "STAT(<flag>,<filename>)", .read = stat_read, .desc = -"flag may be one of the following:\n" -" d - Checks if the file is a directory\n" -" e - Checks if the file exists\n" -" f - Checks if the file is a regular file\n" -" m - Returns the file mode (in octal)\n" -" s - Returns the size (in bytes) of the file\n" -" A - Returns the epoch at which the file was last accessed\n" -" C - Returns the epoch at which the inode was last changed\n" -" M - Returns the epoch at which the file was last modified\n", + "flag may be one of the following:\n" + " d - Checks if the file is a directory\n" + " e - Checks if the file exists\n" + " f - Checks if the file is a regular file\n" + " m - Returns the file mode (in octal)\n" + " s - Returns the size (in bytes) of the file\n" + " A - Returns the epoch at which the file was last accessed\n" + " C - Returns the epoch at which the inode was last changed\n" + " M - Returns the epoch at which the file was last modified\n", }; @@ -169,11 +172,3 @@ char *key() { return ASTERISK_GPL_KEY; } - -/* -Local Variables: -mode: C -c-file-style: "linux" -indent-tabs-mode: nil -End: -*/ diff --git a/funcs/func_groupcount.c b/funcs/func_groupcount.c index a4a133056..deb29541c 100644 --- a/funcs/func_groupcount.c +++ b/funcs/func_groupcount.c @@ -1,7 +1,7 @@ /* * Asterisk -- An open source telephony toolkit. * - * Copyright (C) 1999 - 2005, Digium, Inc. + * Copyright (C) 1999 - 2006, Digium, Inc. * * See http://www.asterisk.org for more information about * the Asterisk project. Please do not directly contact @@ -36,70 +36,81 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/utils.h" #include "asterisk/app.h" -static char *group_count_function_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int group_count_function_read(struct ast_channel *chan, char *cmd, + char *data, char *buf, size_t len) { int count; char group[80] = ""; char category[80] = ""; const char *grp; - ast_app_group_split_group(data, group, sizeof(group), category, sizeof(category)); + ast_app_group_split_group(data, group, sizeof(group), category, + sizeof(category)); if (ast_strlen_zero(group)) { if ((grp = pbx_builtin_getvar_helper(chan, category))) ast_copy_string(group, grp, sizeof(group)); else - ast_log(LOG_NOTICE, "No group could be found for channel '%s'\n", chan->name); + ast_log(LOG_NOTICE, "No group could be found for channel '%s'\n", + chan->name); } count = ast_app_group_get_count(group, category); snprintf(buf, len, "%d", count); - return buf; + return 0; } static struct ast_custom_function group_count_function = { .name = "GROUP_COUNT", .syntax = "GROUP_COUNT([groupname][@category])", .synopsis = "Counts the number of channels in the specified group", - .desc = "Calculates the group count for the specified group, or uses the\n" - "channel's current group if not specifed (and non-empty).\n", + .desc = + "Calculates the group count for the specified group, or uses the\n" + "channel's current group if not specifed (and non-empty).\n", .read = group_count_function_read, }; -static char *group_match_count_function_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int group_match_count_function_read(struct ast_channel *chan, + char *cmd, char *data, char *buf, + size_t len) { int count; char group[80] = ""; char category[80] = ""; - ast_app_group_split_group(data, group, sizeof(group), category, sizeof(category)); + ast_app_group_split_group(data, group, sizeof(group), category, + sizeof(category)); if (!ast_strlen_zero(group)) { count = ast_app_group_match_get_count(group, category); snprintf(buf, len, "%d", count); } - return buf; + return 0; } static struct ast_custom_function group_match_count_function = { .name = "GROUP_MATCH_COUNT", .syntax = "GROUP_MATCH_COUNT(groupmatch[@category])", - .synopsis = "Counts the number of channels in the groups matching the specified pattern", - .desc = "Calculates the group count for all groups that match the specified pattern.\n" - "Uses standard regular expression matching (see regex(7)).\n", + .synopsis = + "Counts the number of channels in the groups matching the specified pattern", + .desc = + "Calculates the group count for all groups that match the specified pattern.\n" + "Uses standard regular expression matching (see regex(7)).\n", .read = group_match_count_function_read, .write = NULL, }; -static char *group_function_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int group_function_read(struct ast_channel *chan, char *cmd, + char *data, char *buf, size_t len) { char varname[256]; const char *group; if (!ast_strlen_zero(data)) { - snprintf(varname, sizeof(varname), "%s_%s", GROUP_CATEGORY_PREFIX, data); + snprintf(varname, sizeof(varname), "%s_%s", GROUP_CATEGORY_PREFIX, + data); } else { ast_copy_string(varname, GROUP_CATEGORY_PREFIX, sizeof(varname)); } @@ -108,10 +119,11 @@ static char *group_function_read(struct ast_channel *chan, char *cmd, char *data if (group) ast_copy_string(buf, group, len); - return buf; + return 0; } -static void group_function_write(struct ast_channel *chan, char *cmd, char *data, const char *value) +static int group_function_write(struct ast_channel *chan, char *cmd, + char *data, const char *value) { char grpcat[256]; @@ -121,8 +133,11 @@ static void group_function_write(struct ast_channel *chan, char *cmd, char *data ast_copy_string(grpcat, value, sizeof(grpcat)); } - if (ast_app_group_set_channel(chan, grpcat)) - ast_log(LOG_WARNING, "Setting a group requires an argument (group name)\n"); + if (ast_app_group_set_channel(chan, grpcat)) + ast_log(LOG_WARNING, + "Setting a group requires an argument (group name)\n"); + + return 0; } static struct ast_custom_function group_function = { @@ -134,33 +149,41 @@ static struct ast_custom_function group_function = { .write = group_function_write, }; -static char *group_list_function_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int group_list_function_read(struct ast_channel *chan, char *cmd, + char *data, char *buf, size_t len) { struct ast_var_t *current; struct varshead *headp; char tmp1[1024] = ""; char tmp2[1024] = ""; - headp=&chan->varshead; - AST_LIST_TRAVERSE(headp,current,entries) { + headp = &chan->varshead; + AST_LIST_TRAVERSE(headp, current, entries) { if (!strncmp(ast_var_name(current), GROUP_CATEGORY_PREFIX "_", strlen(GROUP_CATEGORY_PREFIX) + 1)) { if (!ast_strlen_zero(tmp1)) { ast_copy_string(tmp2, tmp1, sizeof(tmp2)); - snprintf(tmp1, sizeof(tmp1), "%s %s@%s", tmp2, ast_var_value(current), (ast_var_name(current) + strlen(GROUP_CATEGORY_PREFIX) + 1)); + snprintf(tmp1, sizeof(tmp1), "%s %s@%s", tmp2, + ast_var_value(current), + (ast_var_name(current) + + strlen(GROUP_CATEGORY_PREFIX) + 1)); } else { - snprintf(tmp1, sizeof(tmp1), "%s@%s", ast_var_value(current), (ast_var_name(current) + strlen(GROUP_CATEGORY_PREFIX) + 1)); + snprintf(tmp1, sizeof(tmp1), "%s@%s", ast_var_value(current), + (ast_var_name(current) + + strlen(GROUP_CATEGORY_PREFIX) + 1)); } } else if (!strcmp(ast_var_name(current), GROUP_CATEGORY_PREFIX)) { if (!ast_strlen_zero(tmp1)) { ast_copy_string(tmp2, tmp1, sizeof(tmp2)); - snprintf(tmp1, sizeof(tmp1), "%s %s", tmp2, ast_var_value(current)); + snprintf(tmp1, sizeof(tmp1), "%s %s", tmp2, + ast_var_value(current)); } else { snprintf(tmp1, sizeof(tmp1), "%s", ast_var_value(current)); } } } ast_copy_string(buf, tmp1, len); - return buf; + + return 0; } static struct ast_custom_function group_list_function = { @@ -212,11 +235,3 @@ char *key() { return ASTERISK_GPL_KEY; } - -/* -Local Variables: -mode: C -c-file-style: "linux" -indent-tabs-mode: nil -End: -*/ diff --git a/funcs/func_language.c b/funcs/func_language.c index f6bc1a4c9..05835d6d3 100644 --- a/funcs/func_language.c +++ b/funcs/func_language.c @@ -1,7 +1,7 @@ /* * Asterisk -- An open source telephony toolkit. * - * Copyright (C) 1999 - 2005, Digium, Inc. + * Copyright (C) 1999 - 2006, Digium, Inc. * * See http://www.asterisk.org for more information about * the Asterisk project. Please do not directly contact @@ -36,31 +36,42 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/app.h" #include "asterisk/stringfields.h" -static char *language_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int depwarning = 0; + +static int language_read(struct ast_channel *chan, char *cmd, char *data, + char *buf, size_t len) { + if (!depwarning) { + depwarning = 1; + ast_log(LOG_WARNING, + "LANGUAGE() is deprecated; use CHANNEL(language) instead.\n"); + } + ast_copy_string(buf, chan->language, len); - return buf; + return 0; } -static void language_write(struct ast_channel *chan, char *cmd, char *data, const char *value) +static int language_write(struct ast_channel *chan, char *cmd, char *data, + const char *value) { + if (!depwarning) { + depwarning = 1; + ast_log(LOG_WARNING, + "LANGUAGE() is deprecated; use CHANNEL(language) instead.\n"); + } + if (value) - ast_string_field_set(chan, language, value); + ast_string_field_set(chan, language, value); + + return 0; } static struct ast_custom_function language_function = { .name = "LANGUAGE", .synopsis = "Gets or sets the channel's language.", .syntax = "LANGUAGE()", - .desc = "Gets or sets the channel language. This information is used for the\n" - "syntax in generation of numbers, and to choose a natural language file\n" - "when available. For example, if language is set to 'fr' and the file\n" - "'demo-congrats' is requested to be played, if the file\n" - "'fr/demo-congrats' exists, then it will play that file, and if not\n" - "will play the normal 'demo-congrats'. For some language codes,\n" - "changing the language also changes the syntax of some Asterisk\n" - "functions, like SayNumber.\n", + .desc = "Deprecated. Use CHANNEL(language) instead.\n", .read = language_read, .write = language_write, }; @@ -69,12 +80,12 @@ static char *tdesc = "Channel language dialplan function"; int unload_module(void) { - return ast_custom_function_unregister(&language_function); + return ast_custom_function_unregister(&language_function); } int load_module(void) { - return ast_custom_function_register(&language_function); + return ast_custom_function_register(&language_function); } char *description(void) @@ -91,11 +102,3 @@ char *key() { return ASTERISK_GPL_KEY; } - -/* -Local Variables: -mode: C -c-file-style: "linux" -indent-tabs-mode: nil -End: -*/ diff --git a/funcs/func_logic.c b/funcs/func_logic.c index b3c7eb2b5..50712b8f7 100644 --- a/funcs/func_logic.c +++ b/funcs/func_logic.c @@ -1,7 +1,7 @@ /* * Asterisk -- An open source telephony toolkit. * - * Copyright (C) 1999 - 2005, Digium, Inc. + * Copyright (C) 1999 - 2006, Digium, Inc. * Portions Copyright (C) 2005, Anthony Minessale II * * See http://www.asterisk.org for more information about @@ -37,40 +37,44 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/utils.h" #include "asterisk/app.h" -static char *isnull(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int isnull(struct ast_channel *chan, char *cmd, char *data, + char *buf, size_t len) { - return data && *data ? "0" : "1"; + strcpy(buf, data && *data ? "0" : "1"); + + return 0; } -static char *exists(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int exists(struct ast_channel *chan, char *cmd, char *data, char *buf, + size_t len) { - return data && *data ? "1" : "0"; + strcpy(buf, data && *data ? "1" : "0"); + + return 0; } -static char *iftime(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int iftime(struct ast_channel *chan, char *cmd, char *data, char *buf, + size_t len) { struct ast_timing timing; - char *ret; char *expr; char *iftrue; char *iffalse; - if (!(data = ast_strdupa(data))) - return NULL; - data = ast_strip_quoted(data, "\"", "\""); expr = strsep(&data, "?"); iftrue = strsep(&data, ":"); iffalse = data; if (ast_strlen_zero(expr) || !(iftrue || iffalse)) { - ast_log(LOG_WARNING, "Syntax IFTIME(<timespec>?[<true>][:<false>])\n"); - return NULL; + ast_log(LOG_WARNING, + "Syntax IFTIME(<timespec>?[<true>][:<false>])\n"); + return -1; } if (!ast_build_timing(&timing, expr)) { ast_log(LOG_WARNING, "Invalid Time Spec.\n"); - return NULL; + return -1; } if (iftrue) @@ -78,24 +82,18 @@ static char *iftime(struct ast_channel *chan, char *cmd, char *data, char *buf, if (iffalse) iffalse = ast_strip_quoted(iffalse, "\"", "\""); - if ((ret = ast_check_timing(&timing) ? iftrue : iffalse)) { - ast_copy_string(buf, ret, len); - ret = buf; - } - - return ret; + ast_copy_string(buf, ast_check_timing(&timing) ? iftrue : iffalse, len); + + return 0; } -static char *acf_if(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int acf_if(struct ast_channel *chan, char *cmd, char *data, char *buf, + size_t len) { - char *ret; char *expr; char *iftrue; char *iffalse; - if (!(data = ast_strdupa(data))) - return NULL; - data = ast_strip_quoted(data, "\"", "\""); expr = strsep(&data, "?"); iftrue = strsep(&data, ":"); @@ -103,7 +101,7 @@ static char *acf_if(struct ast_channel *chan, char *cmd, char *data, char *buf, if (ast_strlen_zero(expr) || !(iftrue || iffalse)) { ast_log(LOG_WARNING, "Syntax IF(<expr>?[<true>][:<false>])\n"); - return NULL; + return -1; } expr = ast_strip(expr); @@ -112,28 +110,23 @@ static char *acf_if(struct ast_channel *chan, char *cmd, char *data, char *buf, if (iffalse) iffalse = ast_strip_quoted(iffalse, "\"", "\""); - if ((ret = ast_true(expr) ? iftrue : iffalse)) { - ast_copy_string(buf, ret, len); - ret = buf; - } - - return ret; + ast_copy_string(buf, ast_true(expr) ? iftrue : iffalse, len); + + return 0; } -static char *set(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int set(struct ast_channel *chan, char *cmd, char *data, char *buf, + size_t len) { char *varname; char *val; - if (!(data = ast_strdupa(data))) - return NULL; - varname = strsep(&data, "="); val = data; if (ast_strlen_zero(varname) || !val) { ast_log(LOG_WARNING, "Syntax SET(<varname>=[<value>])\n"); - return NULL; + return -1; } varname = ast_strip(varname); @@ -141,7 +134,7 @@ static char *set(struct ast_channel *chan, char *cmd, char *data, char *buf, siz pbx_builtin_setvar_helper(chan, varname, val); ast_copy_string(buf, val, len); - return buf; + return 0; } static struct ast_custom_function isnull_function = { @@ -167,14 +160,16 @@ static struct ast_custom_function exists_function = { static struct ast_custom_function if_function = { .name = "IF", - .synopsis = "Conditional: Returns the data following '?' if true else the data following ':'", + .synopsis = + "Conditional: Returns the data following '?' if true else the data following ':'", .syntax = "IF(<expr>?[<true>][:<false>])", .read = acf_if, }; static struct ast_custom_function if_time_function = { .name = "IFTIME", - .synopsis = "Temporal Conditional: Returns the data following '?' if true else the data following ':'", + .synopsis = + "Temporal Conditional: Returns the data following '?' if true else the data following ':'", .syntax = "IFTIME(<timespec>?[<true>][:<false>])", .read = iftime, }; diff --git a/funcs/func_math.c b/funcs/func_math.c index 4ae62499f..7ad4765c6 100644 --- a/funcs/func_math.c +++ b/funcs/func_math.c @@ -1,7 +1,7 @@ /* * Asterisk -- An open source telephony toolkit. * - * Copyright (C) 2004 - 2005, Andy Powell + * Copyright (C) 2004 - 2006, Andy Powell * * Updated by Mark Spencer <markster@digium.com> * @@ -18,7 +18,7 @@ /*! \file * - * \brief Maths relatad dialplan functions + * \brief Math related dialplan function * * \author Andy Powell * \author Mark Spencer <markster@digium.com> @@ -41,65 +41,55 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/app.h" #include "asterisk/config.h" -enum TypeOfFunctions -{ - ADDFUNCTION, - DIVIDEFUNCTION, - MULTIPLYFUNCTION, - SUBTRACTFUNCTION, - MODULUSFUNCTION, - GTFUNCTION, - LTFUNCTION, - GTEFUNCTION, - LTEFUNCTION, - EQFUNCTION +enum TypeOfFunctions { + ADDFUNCTION, + DIVIDEFUNCTION, + MULTIPLYFUNCTION, + SUBTRACTFUNCTION, + MODULUSFUNCTION, + GTFUNCTION, + LTFUNCTION, + GTEFUNCTION, + LTEFUNCTION, + EQFUNCTION }; -enum TypeOfResult -{ - FLOAT_RESULT, - INT_RESULT, - HEX_RESULT, - CHAR_RESULT +enum TypeOfResult { + FLOAT_RESULT, + INT_RESULT, + HEX_RESULT, + CHAR_RESULT }; - -static char *math(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int math(struct ast_channel *chan, char *cmd, char *parse, + char *buf, size_t len) { float fnum1; float fnum2; float ftmp = 0; char *op; - int iaction=-1; - int type_of_result=FLOAT_RESULT; - char *parse; - - /* dunno, big calulations :D */ - char user_result[30]; - - char *mvalue1, *mvalue2=NULL, *mtype_of_result; - + int iaction = -1; + int type_of_result = FLOAT_RESULT; + char *mvalue1, *mvalue2 = NULL, *mtype_of_result; AST_DECLARE_APP_ARGS(args, - AST_APP_ARG(argv0); - AST_APP_ARG(argv1); + AST_APP_ARG(argv0); + AST_APP_ARG(argv1); ); - if (ast_strlen_zero(data)) { + + if (ast_strlen_zero(parse)) { ast_log(LOG_WARNING, "Syntax: Math(<number1><op><number 2>[,<type_of_result>]) - missing argument!\n"); - return NULL; + return -1; } - if (!(parse = ast_strdupa(data))) - return NULL; - AST_STANDARD_APP_ARGS(args, parse); - + if (args.argc < 1) { ast_log(LOG_WARNING, "Syntax: Math(<number1><op><number 2>[,<type_of_result>]) - missing argument!\n"); - return NULL; + return -1; } mvalue1 = args.argv0; - + if ((op = strchr(mvalue1, '+'))) { iaction = ADDFUNCTION; *op = '\0'; @@ -118,123 +108,127 @@ static char *math(struct ast_channel *chan, char *cmd, char *data, char *buf, si } else if ((op = strchr(mvalue1, '>'))) { iaction = GTFUNCTION; *op = '\0'; - if (*(op+1) == '=') { + if (*(op + 1) == '=') { *++op = '\0'; iaction = GTEFUNCTION; } } else if ((op = strchr(mvalue1, '<'))) { iaction = LTFUNCTION; *op = '\0'; - if (*(op+1) == '=') { + if (*(op + 1) == '=') { *++op = '\0'; iaction = LTEFUNCTION; } } else if ((op = strchr(mvalue1, '='))) { iaction = GTFUNCTION; *op = '\0'; - if (*(op+1) == '=') { + if (*(op + 1) == '=') { *++op = '\0'; iaction = EQFUNCTION; } else op = NULL; - } - - if (op) + } + + if (op) mvalue2 = op + 1; /* detect wanted type of result */ mtype_of_result = args.argv1; - if (mtype_of_result) - { - if (!strcasecmp(mtype_of_result,"float") || !strcasecmp(mtype_of_result,"f")) - type_of_result=FLOAT_RESULT; - else if (!strcasecmp(mtype_of_result,"int") || !strcasecmp(mtype_of_result,"i")) - type_of_result=INT_RESULT; - else if (!strcasecmp(mtype_of_result,"hex") || !strcasecmp(mtype_of_result,"h")) - type_of_result=HEX_RESULT; - else if (!strcasecmp(mtype_of_result,"char") || !strcasecmp(mtype_of_result,"c")) - type_of_result=CHAR_RESULT; - else - { - ast_log(LOG_WARNING, "Unknown type of result requested '%s'.\n", mtype_of_result); - return NULL; + if (mtype_of_result) { + if (!strcasecmp(mtype_of_result, "float") + || !strcasecmp(mtype_of_result, "f")) + type_of_result = FLOAT_RESULT; + else if (!strcasecmp(mtype_of_result, "int") + || !strcasecmp(mtype_of_result, "i")) + type_of_result = INT_RESULT; + else if (!strcasecmp(mtype_of_result, "hex") + || !strcasecmp(mtype_of_result, "h")) + type_of_result = HEX_RESULT; + else if (!strcasecmp(mtype_of_result, "char") + || !strcasecmp(mtype_of_result, "c")) + type_of_result = CHAR_RESULT; + else { + ast_log(LOG_WARNING, "Unknown type of result requested '%s'.\n", + mtype_of_result); + return -1; } } - + if (!mvalue1 || !mvalue2) { - ast_log(LOG_WARNING, "Supply all the parameters - just this once, please\n"); - return NULL; + ast_log(LOG_WARNING, + "Supply all the parameters - just this once, please\n"); + return -1; } if (sscanf(mvalue1, "%f", &fnum1) != 1) { ast_log(LOG_WARNING, "'%s' is not a valid number\n", mvalue1); - return NULL; + return -1; } if (sscanf(mvalue2, "%f", &fnum2) != 1) { ast_log(LOG_WARNING, "'%s' is not a valid number\n", mvalue2); - return NULL; + return -1; } switch (iaction) { - case ADDFUNCTION : + case ADDFUNCTION: ftmp = fnum1 + fnum2; break; - case DIVIDEFUNCTION : + case DIVIDEFUNCTION: if (fnum2 <= 0) - ftmp = 0; /* can't do a divide by 0 */ + ftmp = 0; /* can't do a divide by 0 */ else ftmp = (fnum1 / fnum2); break; - case MULTIPLYFUNCTION : + case MULTIPLYFUNCTION: ftmp = (fnum1 * fnum2); break; - case SUBTRACTFUNCTION : + case SUBTRACTFUNCTION: ftmp = (fnum1 - fnum2); break; - case MODULUSFUNCTION : - { - int inum1 = fnum1; - int inum2 = fnum2; - - ftmp = (inum1 % inum2); - + case MODULUSFUNCTION: + { + int inum1 = fnum1; + int inum2 = fnum2; + + ftmp = (inum1 % inum2); + + break; + } + case GTFUNCTION: + ast_copy_string(buf, (fnum1 > fnum2) ? "TRUE" : "FALSE", len); break; - } - case GTFUNCTION : - ast_copy_string (user_result, (fnum1 > fnum2)?"TRUE":"FALSE", sizeof (user_result)); + case LTFUNCTION: + ast_copy_string(buf, (fnum1 < fnum2) ? "TRUE" : "FALSE", len); break; - case LTFUNCTION : - ast_copy_string (user_result, (fnum1 < fnum2)?"TRUE":"FALSE", sizeof (user_result)); + case GTEFUNCTION: + ast_copy_string(buf, (fnum1 >= fnum2) ? "TRUE" : "FALSE", len); break; - case GTEFUNCTION : - ast_copy_string (user_result, (fnum1 >= fnum2)?"TRUE":"FALSE", sizeof (user_result)); + case LTEFUNCTION: + ast_copy_string(buf, (fnum1 <= fnum2) ? "TRUE" : "FALSE", len); break; - case LTEFUNCTION : - ast_copy_string (user_result, (fnum1 <= fnum2)?"TRUE":"FALSE", sizeof (user_result)); - break; - case EQFUNCTION : - ast_copy_string (user_result, (fnum1 == fnum2)?"TRUE":"FALSE", sizeof (user_result)); + case EQFUNCTION: + ast_copy_string(buf, (fnum1 == fnum2) ? "TRUE" : "FALSE", len); break; - default : - ast_log(LOG_WARNING, "Something happened that neither of us should be proud of %d\n", iaction); - return NULL; + default: + ast_log(LOG_WARNING, + "Something happened that neither of us should be proud of %d\n", + iaction); + return -1; } if (iaction < GTFUNCTION || iaction > EQFUNCTION) { - if (type_of_result == FLOAT_RESULT) - snprintf(user_result, sizeof(user_result), "%f", ftmp); - else if (type_of_result == INT_RESULT) - snprintf(user_result, sizeof(user_result), "%i", (int) ftmp); - else if (type_of_result == HEX_RESULT) - snprintf(user_result, sizeof(user_result), "%x", (unsigned int) ftmp); - else if (type_of_result == CHAR_RESULT) - snprintf(user_result, sizeof(user_result), "%c", (unsigned char) ftmp); + if (type_of_result == FLOAT_RESULT) + snprintf(buf, len, "%f", ftmp); + else if (type_of_result == INT_RESULT) + snprintf(buf, len, "%i", (int) ftmp); + else if (type_of_result == HEX_RESULT) + snprintf(buf, len, "%x", (unsigned int) ftmp); + else if (type_of_result == CHAR_RESULT) + snprintf(buf, len, "%c", (unsigned char) ftmp); } - - ast_copy_string(buf, user_result, len); - - return buf; + + return 0; } static struct ast_custom_function math_function = { @@ -242,7 +236,7 @@ static struct ast_custom_function math_function = { .synopsis = "Performs Mathematical Functions", .syntax = "MATH(<number1><op><number 2>[,<type_of_result>])", .desc = "Perform calculation on number 1 to number 2. Valid ops are: \n" - " +,-,/,*,%,<,>,>=,<=,==\n" + " +,-,/,*,%,<,>,>=,<=,==\n" "and behave as their C equivalents.\n" "<type_of_result> - wanted type of result:\n" " f, float - float(default)\n" @@ -257,12 +251,12 @@ static char *tdesc = "Mathematical dialplan function"; int unload_module(void) { - return ast_custom_function_unregister(&math_function); + return ast_custom_function_unregister(&math_function); } int load_module(void) { - return ast_custom_function_register(&math_function); + return ast_custom_function_register(&math_function); } char *description(void) diff --git a/funcs/func_md5.c b/funcs/func_md5.c index 53368d6c9..7e2d9af7a 100644 --- a/funcs/func_md5.c +++ b/funcs/func_md5.c @@ -1,7 +1,7 @@ /* * Asterisk -- An open source telephony toolkit. * - * Copyright (C) 2005, Digium, Inc. + * Copyright (C) 2005-2006, Digium, Inc. * Copyright (C) 2005, Olle E. Johansson, Edvina.net * Copyright (C) 2005, Russell Bryant <russelb@clemson.edu> * @@ -39,44 +39,39 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/utils.h" #include "asterisk/app.h" -static char *md5(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int md5(struct ast_channel *chan, char *cmd, char *data, + char *buf, size_t len) { - char md5[33]; - if (ast_strlen_zero(data)) { ast_log(LOG_WARNING, "Syntax: MD5(<data>) - missing argument!\n"); - return NULL; + return -1; } - ast_md5_hash(md5, data); - ast_copy_string(buf, md5, len); - - return buf; + ast_md5_hash(buf, data); + buf[32] = '\0'; + + return 0; } -static char *checkmd5(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int checkmd5(struct ast_channel *chan, char *cmd, char *parse, + char *buf, size_t len) { char newmd5[33]; - char *parse; static int deprecated = 0; - AST_DECLARE_APP_ARGS(args, - AST_APP_ARG(digest); - AST_APP_ARG(data); - ); + AST_DECLARE_APP_ARGS(args, AST_APP_ARG(digest); AST_APP_ARG(data);); - if (ast_strlen_zero(data)) { - ast_log(LOG_WARNING, "Syntax: CHECK_MD5(<digest>,<data>) - missing argument!\n"); - return NULL; + if (ast_strlen_zero(parse)) { + ast_log(LOG_WARNING, + "Syntax: CHECK_MD5(<digest>,<data>) - missing argument!\n"); + return -1; } - if (!(parse = ast_strdupa(data))) - return NULL; - AST_STANDARD_APP_ARGS(args, parse); - + if (args.argc < 2) { - ast_log(LOG_WARNING, "Syntax: CHECK_MD5(<digest>,<data>) - missing argument!\n"); - return NULL; + ast_log(LOG_WARNING, + "Syntax: CHECK_MD5(<digest>,<data>) - missing argument!\n"); + return -1; } if (!deprecated) { @@ -86,12 +81,12 @@ static char *checkmd5(struct ast_channel *chan, char *cmd, char *data, char *buf ast_md5_hash(newmd5, args.data); - if (!strcasecmp(newmd5, args.digest) ) /* they match */ + if (!strcasecmp(newmd5, args.digest)) /* they match */ ast_copy_string(buf, "1", len); else ast_copy_string(buf, "0", len); - - return buf; + + return 0; } static struct ast_custom_function md5_function = { @@ -113,12 +108,14 @@ static char *tdesc = "MD5 digest dialplan functions"; int unload_module(void) { - return ast_custom_function_unregister(&md5_function) || ast_custom_function_unregister(&checkmd5_function); + return ast_custom_function_unregister(&md5_function) | + ast_custom_function_unregister(&checkmd5_function); } int load_module(void) { - return ast_custom_function_register(&md5_function) || ast_custom_function_register(&checkmd5_function); + return ast_custom_function_register(&md5_function) | + ast_custom_function_register(&checkmd5_function); } char *description(void) diff --git a/funcs/func_moh.c b/funcs/func_moh.c index f7cebff93..d027b75f4 100644 --- a/funcs/func_moh.c +++ b/funcs/func_moh.c @@ -1,7 +1,7 @@ /* * Asterisk -- An open source telephony toolkit. * - * Copyright (C) 1999 - 2005, Digium, Inc. + * Copyright (C) 1999 - 2006, Digium, Inc. * * Russell Bryant <russelb@clemson.edu> * @@ -35,23 +35,39 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/utils.h" #include "asterisk/stringfields.h" -static char *moh_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int depwarning = 0; + +static int moh_read(struct ast_channel *chan, char *cmd, char *data, + char *buf, size_t len) { + if (!depwarning) { + depwarning = 1; + ast_log(LOG_WARNING, "MUSICCLASS() is deprecated; use CHANNEL(musicclass) instead.\n"); + } + ast_copy_string(buf, chan->musicclass, len); - return buf; + return 0; } -static void moh_write(struct ast_channel *chan, char *cmd, char *data, const char *value) +static int moh_write(struct ast_channel *chan, char *cmd, char *data, + const char *value) { + if (!depwarning) { + depwarning = 1; + ast_log(LOG_WARNING, "MUSICCLASS() is deprecated; use CHANNEL(musicclass) instead.\n"); + } + ast_string_field_set(chan, musicclass, value); + + return 0; } static struct ast_custom_function moh_function = { .name = "MUSICCLASS", .synopsis = "Read or Set the MusicOnHold class", .syntax = "MUSICCLASS()", - .desc = "This function will read or set the music on hold class for a channel.\n", + .desc = "Deprecated. Use CHANNEL(musicclass) instead.\n", .read = moh_read, .write = moh_write, }; @@ -60,12 +76,12 @@ static char *tdesc = "Music-on-hold dialplan function"; int unload_module(void) { - return ast_custom_function_unregister(&moh_function); + return ast_custom_function_unregister(&moh_function); } int load_module(void) { - return ast_custom_function_register(&moh_function); + return ast_custom_function_register(&moh_function); } char *description(void) diff --git a/funcs/func_odbc.c b/funcs/func_odbc.c index 2f963c934..29ce4f303 100644 --- a/funcs/func_odbc.c +++ b/funcs/func_odbc.c @@ -1,7 +1,7 @@ /* * Asterisk -- An open source telephony toolkit. * - * Copyright (c) 2005 Tilghman Lesher + * Copyright (c) 2005, 2006 Tilghman Lesher * * Tilghman Lesher <func_odbc__200508@the-tilghman.com> * @@ -75,11 +75,11 @@ static void acf_odbc_error(SQLHSTMT stmt, int res) /* * Master control routine */ -static void acf_odbc_write(struct ast_channel *chan, char *cmd, char *data, const char *value) +static int acf_odbc_write(struct ast_channel *chan, char *cmd, char *s, const char *value) { odbc_obj *obj; struct acf_odbc_query *query; - char *s, *t, *arg, buf[512]="", varname[15]; + char *t, *arg, buf[512]="", varname[15]; int res, argcount=0, valcount=0, i, retry=0; struct ast_channel *ast; SQLHSTMT stmt; @@ -101,7 +101,7 @@ static void acf_odbc_write(struct ast_channel *chan, char *cmd, char *data, cons if (!query) { ast_log(LOG_ERROR, "No such function '%s'\n", cmd); ast_mutex_unlock(&query_lock); - return; + return -1; } obj = fetch_odbc_obj(query->dsn, 0); @@ -109,21 +109,16 @@ static void acf_odbc_write(struct ast_channel *chan, char *cmd, char *data, cons if (!obj) { ast_log(LOG_ERROR, "No such DSN registered: %s (check res_odbc.conf)\n", query->dsn); ast_mutex_unlock(&query_lock); - return; + return -1; } /* Parse our arguments */ - s = ast_strdupa(data); - if (value) { - t = ast_strdupa(value); - } else { - t = ""; - } + t = value ? ast_strdupa(value) : ""; if (!s || !t) { ast_log(LOG_ERROR, "Out of memory\n"); ast_mutex_unlock(&query_lock); - return; + return -1; } /* XXX You might be tempted to change this section into using @@ -184,7 +179,7 @@ retry_write: if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { ast_log(LOG_WARNING, "SQL Alloc Handle failed!\n"); pbx_builtin_setvar_helper(chan, "ODBCROWS", "-1"); - return; + return -1; } res = SQLPrepare(stmt, (unsigned char *)buf, SQL_NTS); @@ -192,7 +187,7 @@ retry_write: ast_log(LOG_WARNING, "SQL Prepare failed![%s]\n", buf); SQLFreeHandle (SQL_HANDLE_STMT, stmt); pbx_builtin_setvar_helper(chan, "ODBCROWS", "-1"); - return; + return -1; } res = SQLExecute(stmt); @@ -234,13 +229,15 @@ retry_write: } SQLFreeHandle(SQL_HANDLE_STMT, stmt); + + return 0; } -static char *acf_odbc_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int acf_odbc_read(struct ast_channel *chan, char *cmd, char *s, char *buf, size_t len) { odbc_obj *obj; struct acf_odbc_query *query; - char *s, *arg, sql[512] = "", varname[15]; + char *arg, sql[512] = "", varname[15]; int count=0, res, x; SQLHSTMT stmt; SQLSMALLINT colcount=0; @@ -260,7 +257,7 @@ static char *acf_odbc_read(struct ast_channel *chan, char *cmd, char *data, char if (!query) { ast_log(LOG_ERROR, "No such function '%s'\n", cmd); ast_mutex_unlock(&query_lock); - return ""; + return -1; } obj = fetch_odbc_obj(query->dsn, 0); @@ -268,7 +265,7 @@ static char *acf_odbc_read(struct ast_channel *chan, char *cmd, char *data, char if (!obj) { ast_log(LOG_ERROR, "No such DSN registered: %s (check res_odbc.conf)\n", query->dsn); ast_mutex_unlock(&query_lock); - return ""; + return -1; } #ifdef NEEDTRACE @@ -276,12 +273,6 @@ static char *acf_odbc_read(struct ast_channel *chan, char *cmd, char *data, char SQLSetConnectAttr(obj->con, SQL_ATTR_TRACEFILE, tracefile, strlen(tracefile)); #endif - /* Parse our arguments */ - if (!(s = ast_strdupa(data))) { - ast_mutex_unlock(&query_lock); - return ""; - } - while ((arg = strsep(&s, "|"))) { count++; snprintf(varname, sizeof(varname), "ARG%d", count); @@ -302,31 +293,31 @@ static char *acf_odbc_read(struct ast_channel *chan, char *cmd, char *data, char res = SQLAllocHandle (SQL_HANDLE_STMT, obj->con, &stmt); if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { ast_log(LOG_WARNING, "SQL Alloc Handle failed!\n"); - return ""; + return -1; } res = SQLPrepare(stmt, (unsigned char *)sql, SQL_NTS); if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { ast_log(LOG_WARNING, "SQL Prepare failed![%s]\n", sql); SQLFreeHandle (SQL_HANDLE_STMT, stmt); - return ""; + return -1; } res = odbc_smart_execute(obj, stmt); if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { ast_log(LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql); SQLFreeHandle (SQL_HANDLE_STMT, stmt); - return ""; + return -1; } res = SQLNumResultCols(stmt, &colcount); if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { ast_log(LOG_WARNING, "SQL Column Count error!\n[%s]\n\n", sql); SQLFreeHandle (SQL_HANDLE_STMT, stmt); - return ""; + return -1; } - memset(buf, 0, len); + *buf = '\0'; res = SQLFetch(stmt); if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { @@ -354,7 +345,7 @@ static char *acf_odbc_read(struct ast_channel *chan, char *cmd, char *data, char if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql); SQLFreeHandle(SQL_HANDLE_STMT, stmt); - return ""; + return -1; } strncat(buf + buflen, coldata, len - buflen); @@ -366,22 +357,23 @@ static char *acf_odbc_read(struct ast_channel *chan, char *cmd, char *data, char acf_out: SQLFreeHandle(SQL_HANDLE_STMT, stmt); - return buf; + return 0; } -static char *acf_escape(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int acf_escape(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) { - char *in, *out = buf; - for (in = data; *in && out - buf < len; in++) { - if (*in == '\'') { + char *out = buf; + + for (; *data && out - buf < len; data++) { + if (*data == '\'') { *out = '\''; out++; } - *out = *in; - out++; + *out++ = *data; } *out = '\0'; - return buf; + + return 0; } static struct ast_custom_function escape_function = { @@ -396,8 +388,6 @@ static struct ast_custom_function escape_function = { .write = NULL, }; - - static int init_acf_query(struct ast_config *cfg, char *catg, struct acf_odbc_query **query) { char *tmp; diff --git a/funcs/func_rand.c b/funcs/func_rand.c index 34bccf573..6ec0f3c93 100644 --- a/funcs/func_rand.c +++ b/funcs/func_rand.c @@ -43,48 +43,42 @@ STANDARD_LOCAL_USER; LOCAL_USER_DECL; -static char *acf_rand_exec(struct ast_channel *chan, char *cmd, char *data, char *buffer, size_t buflen) +static int acf_rand_exec(struct ast_channel *chan, char *cmd, + char *parse, char *buffer, size_t buflen) { struct localuser *u; int min_int, response_int, max_int; - char *parse; - AST_DECLARE_APP_ARGS(args, - AST_APP_ARG(min); - AST_APP_ARG(max); + AST_APP_ARG(min); + AST_APP_ARG(max); ); - - if (!(parse = ast_strdupa(data))) { - *buffer = '\0'; - return buffer; - } LOCAL_USER_ACF_ADD(u); AST_STANDARD_APP_ARGS(args, parse); - - if (ast_strlen_zero(args.min) || sscanf(args.min, "%d", &min_int) != 1) { - min_int = 0; - } + if (ast_strlen_zero(args.min) || sscanf(args.min, "%d", &min_int) != 1) + min_int = 0; - if (ast_strlen_zero(args.max) || sscanf(args.max, "%d", &max_int) != 1) { + if (ast_strlen_zero(args.max) || sscanf(args.max, "%d", &max_int) != 1) max_int = RAND_MAX; - } if (max_int < min_int) { int tmp = max_int; + max_int = min_int; min_int = tmp; ast_log(LOG_DEBUG, "max<min\n"); } response_int = min_int + (ast_random() % (max_int - min_int + 1)); - ast_log(LOG_DEBUG, "%d was the lucky number in range [%d,%d]\n", response_int, min_int, max_int); + ast_log(LOG_DEBUG, "%d was the lucky number in range [%d,%d]\n", + response_int, min_int, max_int); snprintf(buffer, buflen, "%d", response_int); LOCAL_USER_REMOVE(u); - return buffer; + + return 0; } static struct ast_custom_function acf_rand = { @@ -92,10 +86,10 @@ static struct ast_custom_function acf_rand = { .synopsis = "Choose a random number in a range", .syntax = "RAND([min][,max])", .desc = -"Choose a random number between min and max. Min defaults to 0, if not\n" -"specified, while max defaults to RAND_MAX (2147483647 on many systems).\n" -" Example: Set(junky=${RAND(1,8)}); \n" -" Sets junky to a random number between 1 and 8, inclusive.\n", + "Choose a random number between min and max. Min defaults to 0, if not\n" + "specified, while max defaults to RAND_MAX (2147483647 on many systems).\n" + " Example: Set(junky=${RAND(1,8)}); \n" + " Sets junky to a random number between 1 and 8, inclusive.\n", .read = acf_rand_exec, }; @@ -116,7 +110,7 @@ int load_module(void) char *description(void) { - return tdesc; + return tdesc; } int usecount(void) @@ -126,5 +120,5 @@ int usecount(void) char *key() { - return ASTERISK_GPL_KEY; + return ASTERISK_GPL_KEY; } diff --git a/funcs/func_sha1.c b/funcs/func_sha1.c index 9600d20c5..c9805d2a3 100644 --- a/funcs/func_sha1.c +++ b/funcs/func_sha1.c @@ -37,22 +37,26 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/utils.h" #include "asterisk/app.h" -static char *sha1(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int sha1(struct ast_channel *chan, char *cmd, char *data, + char *buf, size_t len) { + *buf = '\0'; + if (ast_strlen_zero(data)) { ast_log(LOG_WARNING, "Syntax: SHA1(<data>) - missing argument!\n"); - return NULL; + return -1; } if (len >= 41) ast_sha1_hash(buf, data); else { - ast_log(LOG_ERROR, "Insufficient space to produce SHA1 hash result (%d < 41)\n", len); - *buf = '\0'; + ast_log(LOG_ERROR, + "Insufficient space to produce SHA1 hash result (%d < 41)\n", + len); } - return buf; -} + return 0; +} static struct ast_custom_function sha1_function = { .name = "SHA1", @@ -60,21 +64,21 @@ static struct ast_custom_function sha1_function = { .syntax = "SHA1(<data>)", .read = sha1, .desc = "Generate a SHA1 digest via the SHA1 algorythm.\n" - " Example: Set(sha1hash=${SHA1(junky)})\n" - " Sets the asterisk variable sha1hash to the string '60fa5675b9303eb62f99a9cd47f9f5837d18f9a0'\n" - " which is known as his hash\n", + " Example: Set(sha1hash=${SHA1(junky)})\n" + " Sets the asterisk variable sha1hash to the string '60fa5675b9303eb62f99a9cd47f9f5837d18f9a0'\n" + " which is known as his hash\n", }; static char *tdesc = "SHA-1 computation dialplan function"; int unload_module(void) { - return ast_custom_function_unregister(&sha1_function); + return ast_custom_function_unregister(&sha1_function); } int load_module(void) { - return ast_custom_function_register(&sha1_function); + return ast_custom_function_register(&sha1_function); } char *description(void) diff --git a/funcs/func_strings.c b/funcs/func_strings.c index 644b9043e..5dafb1f33 100644 --- a/funcs/func_strings.c +++ b/funcs/func_strings.c @@ -1,7 +1,7 @@ /* * Asterisk -- An open source telephony toolkit. * - * Copyright (C) 2005, Digium, Inc. + * Copyright (C) 2005-2006, Digium, Inc. * Portions Copyright (C) 2005, Tilghman Lesher. All rights reserved. * Portions Copyright (C) 2005, Anthony Minessale II * @@ -42,24 +42,19 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/app.h" #include "asterisk/localtime.h" -static char *function_fieldqty(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int function_fieldqty(struct ast_channel *chan, char *cmd, + char *parse, char *buf, size_t len) { - char *varval, workspace[4096]; + char *varval; int fieldcount = 0; - char *parse; AST_DECLARE_APP_ARGS(args, - AST_APP_ARG(varname); - AST_APP_ARG(delim); - ); - - if (!(parse = ast_strdupa(data))) { - ast_copy_string(buf, "0", len); - return buf; - } + AST_APP_ARG(varname); + AST_APP_ARG(delim); + ); AST_STANDARD_APP_ARGS(args, parse); if (args.delim) { - pbx_retrieve_variable(chan, args.varname, &varval, workspace, sizeof(workspace), NULL); + pbx_retrieve_variable(chan, args.varname, &varval, buf, len, NULL); while (strsep(&varval, args.delim)) fieldcount++; } else { @@ -67,7 +62,7 @@ static char *function_fieldqty(struct ast_channel *chan, char *cmd, char *data, } snprintf(buf, len, "%d", fieldcount); - return buf; + return 0; } static struct ast_custom_function fieldqty_function = { @@ -77,34 +72,29 @@ static struct ast_custom_function fieldqty_function = { .read = function_fieldqty, }; -static char *filter(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int filter(struct ast_channel *chan, char *cmd, char *parse, char *buf, + size_t len) { - char *parse; AST_DECLARE_APP_ARGS(args, - AST_APP_ARG(allowed); - AST_APP_ARG(string); + AST_APP_ARG(allowed); + AST_APP_ARG(string); ); - char *outbuf=buf; - - if (!(parse = ast_strdupa(data))) - return ""; + char *outbuf = buf; AST_STANDARD_APP_ARGS(args, parse); - if (!args.string ) { + if (!args.string) { ast_log(LOG_ERROR, "Usage: FILTER(<allowed-chars>,<string>)\n"); - return ""; + return -1; } - for ( ; *(args.string) && (buf + len - 1 > outbuf); (args.string)++) { - if (strchr(args.allowed, *(args.string))) { - *outbuf = *(args.string); - outbuf++; - } + for (; *(args.string) && (buf + len - 1 > outbuf); (args.string)++) { + if (strchr(args.allowed, *(args.string))) + *outbuf++ = *(args.string); } *outbuf = '\0'; - - return buf; + + return 0; } static struct ast_custom_function filter_function = { @@ -114,63 +104,59 @@ static struct ast_custom_function filter_function = { .read = filter, }; -static char *regex(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int regex(struct ast_channel *chan, char *cmd, char *parse, char *buf, + size_t len) { - char *parse; AST_DECLARE_APP_ARGS(args, - AST_APP_ARG(null); - AST_APP_ARG(reg); - AST_APP_ARG(str); + AST_APP_ARG(null); + AST_APP_ARG(reg); + AST_APP_ARG(str); ); - - - char errstr[256] = ""; int errcode; regex_t regexbuf; - ast_copy_string(buf, "0", len); - - if (!(parse = ast_strdupa(data))) - return buf; + buf[0] = '\0'; AST_NONSTANDARD_APP_ARGS(args, parse, '"'); ast_log(LOG_DEBUG, "FUNCTION REGEX (%s)(%s)\n", args.reg, args.str); if ((errcode = regcomp(®exbuf, args.reg, REG_EXTENDED | REG_NOSUB))) { - regerror(errcode, ®exbuf, errstr, sizeof(errstr)); - ast_log(LOG_WARNING, "Malformed input %s(%s): %s\n", cmd, data, errstr); + regerror(errcode, ®exbuf, buf, len); + ast_log(LOG_WARNING, "Malformed input %s(%s): %s\n", cmd, parse, buf); + return -1; } else { if (!regexec(®exbuf, args.str, 0, NULL, 0)) - ast_copy_string(buf, "1", len); + strcpy(buf, "1"); } regfree(®exbuf); - return buf; + return 0; } static struct ast_custom_function regex_function = { .name = "REGEX", - .synopsis = "Regular Expression: Returns 1 if data matches regular expression.", + .synopsis = + "Regular Expression: Returns 1 if data matches regular expression.", .syntax = "REGEX(\"<regular expression>\" <data>)", .read = regex, }; -static void array(struct ast_channel *chan, char *cmd, char *data, const char *value) +static int array(struct ast_channel *chan, char *cmd, char *var, + const char *value) { AST_DECLARE_APP_ARGS(arg1, - AST_APP_ARG(var)[100]; + AST_APP_ARG(var)[100]; ); AST_DECLARE_APP_ARGS(arg2, - AST_APP_ARG(val)[100]; + AST_APP_ARG(val)[100]; ); - char *var, *value2; + char *value2; int i; - var = ast_strdupa(data); value2 = ast_strdupa(value); if (!var || !value2) - return; + return -1; /* The functions this will generally be used with are SORT and ODBC_*, which * both return comma-delimited lists. However, if somebody uses literal lists, @@ -179,20 +165,19 @@ static void array(struct ast_channel *chan, char *cmd, char *data, const char *v * delimiter, but we'll fall back to vertical bars if commas aren't found. */ ast_log(LOG_DEBUG, "array (%s=%s)\n", var, value2); - if (strchr(var, ',')) { + if (strchr(var, ',')) AST_NONSTANDARD_APP_ARGS(arg1, var, ','); - } else { + else AST_STANDARD_APP_ARGS(arg1, var); - } - if (strchr(value2, ',')) { + if (strchr(value2, ',')) AST_NONSTANDARD_APP_ARGS(arg2, value2, ','); - } else { + else AST_STANDARD_APP_ARGS(arg2, value2); - } for (i = 0; i < arg1.argc; i++) { - ast_log(LOG_DEBUG, "array set value (%s=%s)\n", arg1.var[i], arg2.val[i]); + ast_log(LOG_DEBUG, "array set value (%s=%s)\n", arg1.var[i], + arg2.val[i]); if (i < arg2.argc) { pbx_builtin_setvar_helper(chan, arg1.var[i], arg2.val[i]); } else { @@ -201,6 +186,8 @@ static void array(struct ast_channel *chan, char *cmd, char *data, const char *v pbx_builtin_setvar_helper(chan, arg1.var[i], ""); } } + + return 0; } static struct ast_custom_function array_function = { @@ -209,22 +196,25 @@ static struct ast_custom_function array_function = { .syntax = "ARRAY(var1[,var2[...][,varN]])", .write = array, .desc = -"The comma-separated list passed as a value to which the function is set will\n" -"be interpreted as a set of values to which the comma-separated list of\n" -"variable names in the argument should be set.\n" -"Hence, Set(ARRAY(var1,var2)=1,2) will set var1 to 1 and var2 to 2\n" -"Note: remember to either backslash your commas in extensions.conf or quote the\n" -"entire argument, since Set can take multiple arguments itself.\n", + "The comma-separated list passed as a value to which the function is set will\n" + "be interpreted as a set of values to which the comma-separated list of\n" + "variable names in the argument should be set.\n" + "Hence, Set(ARRAY(var1,var2)=1,2) will set var1 to 1 and var2 to 2\n" + "Note: remember to either backslash your commas in extensions.conf or quote the\n" + "entire argument, since Set can take multiple arguments itself.\n", }; -static char *len(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int len(struct ast_channel *chan, char *cmd, char *data, char *buf, + size_t len) { int length = 0; - if (data) { + + if (data) length = strlen(data); - } + snprintf(buf, len, "%d", length); - return buf; + + return 0; } static struct ast_custom_function len_function = { @@ -234,27 +224,25 @@ static struct ast_custom_function len_function = { .read = len, }; -static char *acf_strftime(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int acf_strftime(struct ast_channel *chan, char *cmd, char *parse, + char *buf, size_t len) { - char *parse; AST_DECLARE_APP_ARGS(args, - AST_APP_ARG(epoch); - AST_APP_ARG(timezone); - AST_APP_ARG(format); + AST_APP_ARG(epoch); + AST_APP_ARG(timezone); + AST_APP_ARG(format); ); long epochi; struct tm time; buf[0] = '\0'; - if (ast_strlen_zero(data)) { - ast_log(LOG_ERROR, "Asterisk function STRFTIME() requires an argument.\n"); - return buf; + if (ast_strlen_zero(parse)) { + ast_log(LOG_ERROR, + "Asterisk function STRFTIME() requires an argument.\n"); + return -1; } - - if (!(parse = ast_strdupa(data))) - return buf; - + AST_STANDARD_APP_ARGS(args, parse); if (ast_strlen_zero(args.epoch) || !sscanf(args.epoch, "%ld", &epochi)) { @@ -264,12 +252,12 @@ static char *acf_strftime(struct ast_channel *chan, char *cmd, char *data, char ast_localtime(&epochi, &time, args.timezone); - if (!strftime(buf, len, args.format?args.format:"%c", &time)) { + if (!strftime(buf, len, args.format ? args.format : "%c", &time)) ast_log(LOG_WARNING, "C function strftime() output nothing?!!\n"); - } + buf[len - 1] = '\0'; - return buf; + return 0; } static struct ast_custom_function strftime_function = { @@ -279,66 +267,71 @@ static struct ast_custom_function strftime_function = { .read = acf_strftime, }; -static char *acf_strptime(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int acf_strptime(struct ast_channel *chan, char *cmd, char *data, + char *buf, size_t len) { AST_DECLARE_APP_ARGS(args, - AST_APP_ARG(timestring); - AST_APP_ARG(timezone); - AST_APP_ARG(format); + AST_APP_ARG(timestring); + AST_APP_ARG(timezone); + AST_APP_ARG(format); ); struct tm time; memset(&time, 0, sizeof(struct tm)); - + buf[0] = '\0'; if (!data) { - ast_log(LOG_ERROR, "Asterisk function STRPTIME() requires an argument.\n"); - return buf; + ast_log(LOG_ERROR, + "Asterisk function STRPTIME() requires an argument.\n"); + return -1; } AST_STANDARD_APP_ARGS(args, data); - if (ast_strlen_zero(args.format) ) { - ast_log(LOG_ERROR, "No format supplied to STRPTIME(<timestring>|<timezone>|<format>)"); - return buf; + if (ast_strlen_zero(args.format)) { + ast_log(LOG_ERROR, + "No format supplied to STRPTIME(<timestring>|<timezone>|<format>)"); + return -1; } - + if (!strptime(args.timestring, args.format, &time)) { ast_log(LOG_WARNING, "C function strptime() output nothing?!!\n"); } else { - snprintf(buf, len, "%d", (int)ast_mktime(&time, args.timezone)); + snprintf(buf, len, "%d", (int) ast_mktime(&time, args.timezone)); } - - return buf; + + return 0; } static struct ast_custom_function strptime_function = { .name = "STRPTIME", - .synopsis = "Returns the epoch of the arbitrary date/time string structured as described in the format.", + .synopsis = + "Returns the epoch of the arbitrary date/time string structured as described in the format.", .syntax = "STRPTIME(<datetime>|<timezone>|<format>)", .desc = -"This is useful for converting a date into an EPOCH time, possibly to pass to\n" -"an application like SayUnixTime or to calculate the difference between two\n" -"date strings.\n" -"\n" -"Example:\n" -" ${STRPTIME(2006-03-01 07:30:35|America/Chicago|%Y-%m-%d %H:%M:%S)} returns 1141219835\n", + "This is useful for converting a date into an EPOCH time, possibly to pass to\n" + "an application like SayUnixTime or to calculate the difference between two\n" + "date strings.\n" + "\n" + "Example:\n" + " ${STRPTIME(2006-03-01 07:30:35|America/Chicago|%Y-%m-%d %H:%M:%S)} returns 1141219835\n", .read = acf_strptime, }; -static char *function_eval(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int function_eval(struct ast_channel *chan, char *cmd, char *data, + char *buf, size_t len) { - memset(buf, 0, len); + buf[0] = '\0'; if (ast_strlen_zero(data)) { ast_log(LOG_WARNING, "EVAL requires an argument: EVAL(<string>)\n"); - return buf; + return -1; } pbx_substitute_variables_helper(chan, data, buf, len - 1); - return buf; + return 0; } static struct ast_custom_function eval_function = { @@ -353,7 +346,7 @@ static struct ast_custom_function eval_function = { "contains \"${OTHERVAR}\", then the result of putting ${EVAL(${MYVAR})}\n" "in the dialplan will be the contents of the variable, OTHERVAR.\n" "Normally, by just putting ${MYVAR} in the dialplan, you would be\n" - "left with \"${OTHERVAR}\".\n", + "left with \"${OTHERVAR}\".\n", .read = function_eval, }; @@ -405,11 +398,3 @@ char *key() { return ASTERISK_GPL_KEY; } - -/* -Local Variables: -mode: C -c-file-style: "linux" -indent-tabs-mode: nil -End: -*/ diff --git a/funcs/func_timeout.c b/funcs/func_timeout.c index 547159efe..772343a43 100644 --- a/funcs/func_timeout.c +++ b/funcs/func_timeout.c @@ -1,7 +1,7 @@ /* * Asterisk -- An open source telephony toolkit. * - * Copyright (C) 1999 - 2005, Digium, Inc. + * Copyright (C) 1999 - 2006, Digium, Inc. * * Mark Spencer <markster@digium.com> * @@ -40,16 +40,17 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/app.h" #include "asterisk/options.h" -static char *timeout_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int timeout_read(struct ast_channel *chan, char *cmd, char *data, + char *buf, size_t len) { time_t myt; if (!data) { ast_log(LOG_ERROR, "Must specify type of timeout to get."); - return NULL; + return -1; } - - switch(*data) { + + switch (*data) { case 'a': case 'A': if (chan->whentohangup == 0) { @@ -79,10 +80,11 @@ static char *timeout_read(struct ast_channel *chan, char *cmd, char *data, char break; } - return buf; + return 0; } -static void timeout_write(struct ast_channel *chan, char *cmd, char *data, const char *value) +static int timeout_write(struct ast_channel *chan, char *cmd, char *data, + const char *value) { int x; char timestr[64]; @@ -90,25 +92,27 @@ static void timeout_write(struct ast_channel *chan, char *cmd, char *data, const if (!data) { ast_log(LOG_ERROR, "Must specify type of timeout to set."); - return; + return -1; } - + if (!value) - return; + return -1; x = atoi(value); - switch(*data) { + switch (*data) { case 'a': case 'A': ast_channel_setwhentohangup(chan, x); if (option_verbose > 2) { if (chan->whentohangup) { - strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S UTC", gmtime_r(&chan->whentohangup, &myt)); - ast_verbose( VERBOSE_PREFIX_3 "Channel will hangup at %s.\n", timestr); + strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S UTC", + gmtime_r(&chan->whentohangup, &myt)); + ast_verbose(VERBOSE_PREFIX_3 "Channel will hangup at %s.\n", + timestr); } else { - ast_verbose( VERBOSE_PREFIX_3 "Channel hangup cancelled.\n"); - } + ast_verbose(VERBOSE_PREFIX_3 "Channel hangup cancelled.\n"); + } } break; @@ -117,7 +121,8 @@ static void timeout_write(struct ast_channel *chan, char *cmd, char *data, const if (chan->pbx) { chan->pbx->rtimeout = x; if (option_verbose > 2) - ast_verbose( VERBOSE_PREFIX_3 "Response timeout set to %d\n", chan->pbx->rtimeout); + ast_verbose(VERBOSE_PREFIX_3 "Response timeout set to %d\n", + chan->pbx->rtimeout); } break; @@ -126,7 +131,8 @@ static void timeout_write(struct ast_channel *chan, char *cmd, char *data, const if (chan->pbx) { chan->pbx->dtimeout = x; if (option_verbose > 2) - ast_verbose( VERBOSE_PREFIX_3 "Digit timeout set to %d\n", chan->pbx->dtimeout); + ast_verbose(VERBOSE_PREFIX_3 "Digit timeout set to %d\n", + chan->pbx->dtimeout); } break; @@ -134,35 +140,35 @@ static void timeout_write(struct ast_channel *chan, char *cmd, char *data, const ast_log(LOG_ERROR, "Unknown timeout type specified."); break; } + + return 0; } static struct ast_custom_function timeout_function = { .name = "TIMEOUT", .synopsis = "Gets or sets timeouts on the channel.", .syntax = "TIMEOUT(timeouttype)", - .desc = "Gets or sets various channel timeouts. The timeouts that can be\n" - "manipulated are:\n" - "\n" - "absolute: The absolute maximum amount of time permitted for a call. A\n" - " setting of 0 disables the timeout.\n" - "\n" - "digit: The maximum amount of time permitted between digits when the\n" - " user is typing in an extension. When this timeout expires,\n" - " after the user has started to type in an extension, the\n" - " extension will be considered complete, and will be\n" - " interpreted. Note that if an extension typed in is valid,\n" - " it will not have to timeout to be tested, so typically at\n" - " the expiry of this timeout, the extension will be considered\n" - " invalid (and thus control would be passed to the 'i'\n" - " extension, or if it doesn't exist the call would be\n" - " terminated). The default timeout is 5 seconds.\n" - "\n" - "response: The maximum amount of time permitted after falling through a\n" - " series of priorities for a channel in which the user may\n" - " begin typing an extension. If the user does not type an\n" - " extension in this amount of time, control will pass to the\n" - " 't' extension if it exists, and if not the call would be\n" - " terminated. The default timeout is 10 seconds.\n", + .desc = + "Gets or sets various channel timeouts. The timeouts that can be\n" + "manipulated are:\n" "\n" + "absolute: The absolute maximum amount of time permitted for a call. A\n" + " setting of 0 disables the timeout.\n" "\n" + "digit: The maximum amount of time permitted between digits when the\n" + " user is typing in an extension. When this timeout expires,\n" + " after the user has started to type in an extension, the\n" + " extension will be considered complete, and will be\n" + " interpreted. Note that if an extension typed in is valid,\n" + " it will not have to timeout to be tested, so typically at\n" + " the expiry of this timeout, the extension will be considered\n" + " invalid (and thus control would be passed to the 'i'\n" + " extension, or if it doesn't exist the call would be\n" + " terminated). The default timeout is 5 seconds.\n" "\n" + "response: The maximum amount of time permitted after falling through a\n" + " series of priorities for a channel in which the user may\n" + " begin typing an extension. If the user does not type an\n" + " extension in this amount of time, control will pass to the\n" + " 't' extension if it exists, and if not the call would be\n" + " terminated. The default timeout is 10 seconds.\n", .read = timeout_read, .write = timeout_write, }; @@ -171,12 +177,12 @@ static char *tdesc = "Channel timeout dialplan functions"; int unload_module(void) { - return ast_custom_function_unregister(&timeout_function); + return ast_custom_function_unregister(&timeout_function); } int load_module(void) { - return ast_custom_function_register(&timeout_function); + return ast_custom_function_register(&timeout_function); } char *description(void) @@ -193,11 +199,3 @@ char *key() { return ASTERISK_GPL_KEY; } - -/* -Local Variables: -mode: C -c-file-style: "linux" -indent-tabs-mode: nil -End: -*/ diff --git a/funcs/func_uri.c b/funcs/func_uri.c index 08fdc5b4d..065db5bd7 100644 --- a/funcs/func_uri.c +++ b/funcs/func_uri.c @@ -1,7 +1,7 @@ /* * Asterisk -- An open source telephony toolkit. * - * Copyright (C) 1999 - 2005, Digium, Inc. + * Copyright (C) 1999 - 2006, Digium, Inc. * * Created by Olle E. Johansson, Edvina.net * @@ -44,33 +44,32 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/app.h" /*! \brief uriencode: Encode URL according to RFC 2396 */ -static char *uriencode(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int uriencode(struct ast_channel *chan, char *cmd, char *data, + char *buf, size_t len) { - char uri[BUFSIZ]; - if (ast_strlen_zero(data)) { ast_log(LOG_WARNING, "Syntax: URIENCODE(<data>) - missing argument!\n"); - return NULL; + return -1; } - ast_uri_encode(data, uri, sizeof(uri), 1); - ast_copy_string(buf, uri, len); + ast_uri_encode(data, buf, len, 1); - return buf; + return 0; } /*!\brief uridecode: Decode URI according to RFC 2396 */ -static char *uridecode(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +static int uridecode(struct ast_channel *chan, char *cmd, char *data, + char *buf, size_t len) { if (ast_strlen_zero(data)) { ast_log(LOG_WARNING, "Syntax: URIDECODE(<data>) - missing argument!\n"); - return NULL; + return -1; } - ast_copy_string(buf, data, len); ast_uri_decode(buf); - return buf; + + return 0; } static struct ast_custom_function urldecode_function = { @@ -91,12 +90,14 @@ static char *tdesc = "URI encode/decode dialplan functions"; int unload_module(void) { - return ast_custom_function_unregister(&urldecode_function) || ast_custom_function_unregister(&urlencode_function); + return ast_custom_function_unregister(&urldecode_function) + || ast_custom_function_unregister(&urlencode_function); } int load_module(void) { - return ast_custom_function_register(&urldecode_function) || ast_custom_function_register(&urlencode_function); + return ast_custom_function_register(&urldecode_function) + || ast_custom_function_register(&urlencode_function); } char *description(void) |