[asterisk-commits] tilghman: branch tilghman/str_substitution r185908 - in /team/tilghman/str_su...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Apr 1 14:36:15 CDT 2009
Author: tilghman
Date: Wed Apr 1 14:35:55 2009
New Revision: 185908
URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=185908
Log:
Change substitution API to use ssize_t, instead of int.
Partially addresses Russell's review comments.
Modified:
team/tilghman/str_substitution/funcs/func_aes.c
team/tilghman/str_substitution/funcs/func_base64.c
team/tilghman/str_substitution/funcs/func_blacklist.c
team/tilghman/str_substitution/funcs/func_curl.c
team/tilghman/str_substitution/funcs/func_cut.c
team/tilghman/str_substitution/funcs/func_logic.c
team/tilghman/str_substitution/funcs/func_strings.c
team/tilghman/str_substitution/include/asterisk/astobj2.h
team/tilghman/str_substitution/include/asterisk/pbx.h
team/tilghman/str_substitution/main/pbx.c
Modified: team/tilghman/str_substitution/funcs/func_aes.c
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/str_substitution/funcs/func_aes.c?view=diff&rev=185908&r1=185907&r2=185908
==============================================================================
--- team/tilghman/str_substitution/funcs/func_aes.c (original)
+++ team/tilghman/str_substitution/funcs/func_aes.c Wed Apr 1 14:35:55 2009
@@ -72,12 +72,12 @@
static int aes_helper(struct ast_channel *chan, const char *cmd, char *data,
- char *buf, struct ast_str **str, int maxlen)
+ char *buf, struct ast_str **str, ssize_t maxlen)
{
unsigned char curblock[AES_BLOCK_SIZE] = { 0, };
char *tmp = NULL;
char *tmpP;
- int data_len, encrypt, i;
+ int data_len, encrypt;
int keylen, len, tmplen, elen = 0;
ast_aes_encrypt_key ecx; /* AES 128 Encryption context */
ast_aes_decrypt_key dcx;
@@ -95,17 +95,7 @@
if ((keylen = strlen(args.key)) != AES_BLOCK_SIZE) { /* key must be of 16 characters in length, 128 bits */
ast_log(LOG_WARNING, "Syntax: %s(<key>,<data>) - <key> parameter must be exactly 16 characters%s!\n", cmd, keylen < 16 ? " - padding" : "");
- if (keylen < 16) {
- char *newkey = alloca(17);
- strcpy(newkey, args.key);
- for (i = keylen; i < 16; i++) {
- newkey[i] = ' ';
- }
- newkey[16] = '\0';
- args.key = newkey;
- } else {
- return -1;
- }
+ return -1;
}
if (buf) {
@@ -186,7 +176,7 @@
}
static int aes_str_helper(struct ast_channel *chan, const char *cmd, char *data,
- struct ast_str **buf, int maxlen)
+ struct ast_str **buf, ssize_t maxlen)
{
return aes_helper(chan, cmd, data, NULL, buf, maxlen);
}
Modified: team/tilghman/str_substitution/funcs/func_base64.c
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/str_substitution/funcs/func_base64.c?view=diff&rev=185908&r1=185907&r2=185908
==============================================================================
--- team/tilghman/str_substitution/funcs/func_base64.c (original)
+++ team/tilghman/str_substitution/funcs/func_base64.c Wed Apr 1 14:35:55 2009
@@ -61,7 +61,7 @@
***/
static int base64_helper(struct ast_channel *chan, const char *cmd, char *data,
- char *buf, struct ast_str **str, int len)
+ char *buf, struct ast_str **str, ssize_t len)
{
if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "Syntax: %s(<data>) - missing argument!\n", cmd);
@@ -100,7 +100,7 @@
}
static int base64_str_helper(struct ast_channel *chan, const char *cmd, char *data,
- struct ast_str **buf, int len)
+ struct ast_str **buf, ssize_t len)
{
return base64_helper(chan, cmd, data, NULL, buf, len);
}
Modified: team/tilghman/str_substitution/funcs/func_blacklist.c
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/str_substitution/funcs/func_blacklist.c?view=diff&rev=185908&r1=185907&r2=185908
==============================================================================
--- team/tilghman/str_substitution/funcs/func_blacklist.c (original)
+++ team/tilghman/str_substitution/funcs/func_blacklist.c Wed Apr 1 14:35:55 2009
@@ -70,7 +70,7 @@
return 0;
}
-static int blacklist_read2(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **str, int len)
+static int blacklist_read2(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **str, ssize_t len)
{
/* 2 bytes is a single integer, plus terminating null */
if (ast_str_size(*str) - ast_str_strlen(*str) < 2) {
Modified: team/tilghman/str_substitution/funcs/func_curl.c
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/str_substitution/funcs/func_curl.c?view=diff&rev=185908&r1=185907&r2=185908
==============================================================================
--- team/tilghman/str_substitution/funcs/func_curl.c (original)
+++ team/tilghman/str_substitution/funcs/func_curl.c Wed Apr 1 14:35:55 2009
@@ -276,7 +276,7 @@
return 0;
}
-static int acf_curlopt_helper(struct ast_channel *chan, const char *cmd, char *data, char *buf, struct ast_str **bufstr, int len)
+static int acf_curlopt_helper(struct ast_channel *chan, const char *cmd, char *data, char *buf, struct ast_str **bufstr, ssize_t len)
{
struct ast_datastore *store;
struct global_curl_info *list[2] = { &global_curl_info, NULL };
@@ -394,7 +394,7 @@
return acf_curlopt_helper(chan, cmd, data, buf, NULL, len);
}
-static int acf_curlopt_read2(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, int len)
+static int acf_curlopt_read2(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len)
{
return acf_curlopt_helper(chan, cmd, data, NULL, buf, len);
}
@@ -441,7 +441,7 @@
AST_THREADSTORAGE_CUSTOM(curl_instance, curl_instance_init, curl_instance_cleanup);
-static int acf_curl_helper(struct ast_channel *chan, const char *cmd, char *info, char *buf, struct ast_str **input_str, int len)
+static int acf_curl_helper(struct ast_channel *chan, const char *cmd, char *info, char *buf, struct ast_str **input_str, ssize_t len)
{
struct ast_str *str = ast_str_create(16);
int ret = -1;
@@ -564,7 +564,7 @@
return acf_curl_helper(chan, cmd, info, buf, NULL, len);
}
-static int acf_curl2_exec(struct ast_channel *chan, const char *cmd, char *info, struct ast_str **buf, int len)
+static int acf_curl2_exec(struct ast_channel *chan, const char *cmd, char *info, struct ast_str **buf, ssize_t len)
{
return acf_curl_helper(chan, cmd, info, NULL, buf, len);
}
Modified: team/tilghman/str_substitution/funcs/func_cut.c
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/str_substitution/funcs/func_cut.c?view=diff&rev=185908&r1=185907&r2=185908
==============================================================================
--- team/tilghman/str_substitution/funcs/func_cut.c (original)
+++ team/tilghman/str_substitution/funcs/func_cut.c Wed Apr 1 14:35:55 2009
@@ -148,7 +148,7 @@
return 0;
}
-static int cut_internal(struct ast_channel *chan, char *data, struct ast_str **buf, int buflen)
+static int cut_internal(struct ast_channel *chan, char *data, struct ast_str **buf, ssize_t buflen)
{
char *parse;
size_t delim_consumed;
@@ -279,7 +279,7 @@
return ret;
}
-static int acf_cut_exec2(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, int len)
+static int acf_cut_exec2(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len)
{
int ret = -1;
Modified: team/tilghman/str_substitution/funcs/func_logic.c
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/str_substitution/funcs/func_logic.c?view=diff&rev=185908&r1=185907&r2=185908
==============================================================================
--- team/tilghman/str_substitution/funcs/func_logic.c (original)
+++ team/tilghman/str_substitution/funcs/func_logic.c Wed Apr 1 14:35:55 2009
@@ -223,7 +223,7 @@
return 0;
}
-static int set2(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **str, int len)
+static int set2(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **str, ssize_t len)
{
if (len > -1) {
ast_str_make_space(str, len == 0 ? strlen(data) : len);
@@ -231,7 +231,7 @@
return set(chan, cmd, data, ast_str_buffer(*str), ast_str_size(*str));
}
-static int import_helper(struct ast_channel *chan, const char *cmd, char *data, char *buf, struct ast_str **str, int len)
+static int import_helper(struct ast_channel *chan, const char *cmd, char *data, char *buf, struct ast_str **str, ssize_t len)
{
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(channel);
@@ -264,7 +264,7 @@
return import_helper(chan, cmd, data, buf, NULL, len);
}
-static int import_read2(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **str, int len)
+static int import_read2(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **str, ssize_t len)
{
return import_helper(chan, cmd, data, NULL, str, len);
}
Modified: team/tilghman/str_substitution/funcs/func_strings.c
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/str_substitution/funcs/func_strings.c?view=diff&rev=185908&r1=185907&r2=185908
==============================================================================
--- team/tilghman/str_substitution/funcs/func_strings.c (original)
+++ team/tilghman/str_substitution/funcs/func_strings.c Wed Apr 1 14:35:55 2009
@@ -274,7 +274,7 @@
***/
static int function_fieldqty_helper(struct ast_channel *chan, const char *cmd,
- char *parse, char *buf, struct ast_str **sbuf, int len)
+ char *parse, char *buf, struct ast_str **sbuf, ssize_t len)
{
char *varsubst;
struct ast_str *str = ast_str_create(16);
@@ -326,7 +326,7 @@
}
static int function_fieldqty_str(struct ast_channel *chan, const char *cmd,
- char *parse, struct ast_str **buf, int len)
+ char *parse, struct ast_str **buf, ssize_t len)
{
return function_fieldqty_helper(chan, cmd, parse, NULL, buf, len);
}
@@ -337,7 +337,7 @@
.read2 = function_fieldqty_str,
};
-static int listfilter(struct ast_channel *chan, const char *cmd, char *parse, char *buf, struct ast_str **bufstr, int len)
+static int listfilter(struct ast_channel *chan, const char *cmd, char *parse, char *buf, struct ast_str **bufstr, ssize_t len)
{
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(listname);
@@ -448,7 +448,7 @@
return listfilter(chan, cmd, parse, buf, NULL, len);
}
-static int listfilter_read2(struct ast_channel *chan, const char *cmd, char *parse, struct ast_str **buf, int len)
+static int listfilter_read2(struct ast_channel *chan, const char *cmd, char *parse, struct ast_str **buf, ssize_t len)
{
return listfilter(chan, cmd, parse, NULL, buf, len);
}
@@ -678,7 +678,7 @@
return 0;
}
-static int hashkeys_read2(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, int len)
+static int hashkeys_read2(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len)
{
struct ast_var_t *newvar;
struct ast_str *prefix = ast_str_alloca(80);
@@ -921,7 +921,7 @@
}
static int function_eval2(struct ast_channel *chan, const char *cmd, char *data,
- struct ast_str **buf, int buflen)
+ struct ast_str **buf, ssize_t buflen)
{
if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "EVAL requires an argument: EVAL(<string>)\n");
@@ -988,7 +988,7 @@
return 0;
}
-static int string_toupper2(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, int buflen)
+static int string_toupper2(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t buflen)
{
char *bufptr, *dataptr = data;
@@ -1017,7 +1017,7 @@
return 0;
}
-static int string_tolower2(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, int buflen)
+static int string_tolower2(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t buflen)
{
char *bufptr, *dataptr = data;
Modified: team/tilghman/str_substitution/include/asterisk/astobj2.h
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/str_substitution/include/asterisk/astobj2.h?view=diff&rev=185908&r1=185907&r2=185908
==============================================================================
--- team/tilghman/str_substitution/include/asterisk/astobj2.h (original)
+++ team/tilghman/str_substitution/include/asterisk/astobj2.h Wed Apr 1 14:35:55 2009
@@ -411,7 +411,7 @@
#else
#define ao2_t_alloc(data_size, destructor_fn, debug_msg) __ao2_alloc((data_size), (destructor_fn))
-#define ao2_alloc((data_size), (destructor_fn)) __ao2_alloc((data_size), (destructor_fn))
+#define ao2_alloc(data_size, destructor_fn) __ao2_alloc((data_size), (destructor_fn))
#endif
void *__ao2_alloc_debug(const size_t data_size, ao2_destructor_fn destructor_fn, char *tag, char *file, int line, const char *funcname);
Modified: team/tilghman/str_substitution/include/asterisk/pbx.h
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/str_substitution/include/asterisk/pbx.h?view=diff&rev=185908&r1=185907&r2=185908
==============================================================================
--- team/tilghman/str_substitution/include/asterisk/pbx.h (original)
+++ team/tilghman/str_substitution/include/asterisk/pbx.h Wed Apr 1 14:35:55 2009
@@ -98,7 +98,7 @@
* read function is handed a 16-byte buffer, and the result is 17 bytes
* long, then the first 15 bytes (remember NULL terminator) should be
* the same for both the read and the read2 methods. */
- int (*read2)(struct ast_channel *, const char *, char *, struct ast_str **, int);
+ int (*read2)(struct ast_channel *, const char *, char *, struct ast_str **, ssize_t);
/*! If no read2 function is provided, what maximum size? */
size_t read_max;
/*! Write function, if write is supported */
@@ -147,7 +147,8 @@
/*!\brief Deallocates memory structures associated with a timing bitmap.
* \param i Pointer to an ast_timing structure.
- * \retval Returns 0 on success or a number suitable for passing into strerror, otherwise.
+ * \retval 0 success
+ * \retval non-zero failure (number suitable to pass to \see strerror)
*/
int ast_destroy_timing(struct ast_timing *i);
@@ -165,7 +166,8 @@
* This function registers a populated ast_switch structure with the
* asterisk switching architecture.
*
- * \return 0 on success, and other than 0 on failure
+ * \retval 0 success
+ * \retval non-zero failure
*/
int ast_register_switch(struct ast_switch *sw);
@@ -204,7 +206,8 @@
* saves the stack and executes the given application passing in
* the given data.
*
- * \return 0 on success, and -1 on failure
+ * \retval 0 success
+ * \retval -1 failure
*/
int pbx_exec(struct ast_channel *c, struct ast_app *app, void *data);
@@ -445,7 +448,7 @@
* is found, a non zero value will be returned.
* Otherwise, 0 is returned.
*/
-int ast_str_get_hint(struct ast_str **hint, int hintsize, struct ast_str **name, int namesize,
+int ast_str_get_hint(struct ast_str **hint, ssize_t hintsize, struct ast_str **name, ssize_t namesize,
struct ast_channel *c, const char *context, const char *exten);
/*!
@@ -997,7 +1000,7 @@
* \param headp If no channel is specified, a channel list from which to extract variable values
* \param var Variable name to retrieve.
*/
-char *ast_str_retrieve_variable(struct ast_str **buf, int maxlen, struct ast_channel *chan, struct varshead *headp, const char *var);
+const char *ast_str_retrieve_variable(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, struct varshead *headp, const char *var);
/*!
* \param buf Result will be placed in this buffer.
@@ -1005,7 +1008,7 @@
* \param chan Channel variables from which to extract values, and channel to pass to any dialplan functions.
* \param templ Variable template to expand.
*/
-void ast_str_substitute_variables(struct ast_str **buf, int maxlen, struct ast_channel *chan, const char *templ);
+void ast_str_substitute_variables(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ);
/*!
* \param buf Result will be placed in this buffer.
@@ -1013,7 +1016,7 @@
* \param headp If no channel is specified, a channel list from which to extract variable values
* \param templ Variable template to expand.
*/
-void ast_str_substitute_variables_varshead(struct ast_str **buf, int maxlen, struct varshead *headp, const char *templ);
+void ast_str_substitute_variables_varshead(struct ast_str **buf, ssize_t maxlen, struct varshead *headp, const char *templ);
/*!
* \param buf Result will be placed in this buffer.
@@ -1023,7 +1026,7 @@
* \param templ Variable template to expand.
* \param used Number of bytes read from the template.
*/
-void ast_str_substitute_variables_full(struct ast_str **buf, int maxlen, struct ast_channel *c, struct varshead *headp, const char *templ, size_t *used);
+void ast_str_substitute_variables_full(struct ast_str **buf, ssize_t maxlen, struct ast_channel *c, struct varshead *headp, const char *templ, size_t *used);
/*! @} */
int ast_extension_patmatch(const char *pattern, const char *data);
@@ -1107,7 +1110,8 @@
*
* This application executes a function in read mode on a given channel.
*
- * \return zero on success, non-zero on failure
+ * \retval 0 success
+ * \retval non-zero failure
*/
int ast_func_read(struct ast_channel *chan, const char *function, char *workspace, size_t len);
@@ -1121,9 +1125,10 @@
*
* This application executes a function in read mode on a given channel.
*
- * \return zero on success, non-zero on failure
- */
-int ast_func_read2(struct ast_channel *chan, const char *function, struct ast_str **str, int maxlen);
+ * \retval 0 success
+ * \retval non-zero failure
+ */
+int ast_func_read2(struct ast_channel *chan, const char *function, struct ast_str **str, ssize_t maxlen);
/*!
* \brief executes a write operation on a function
@@ -1134,7 +1139,8 @@
*
* This application executes a function in write mode on a given channel.
*
- * \return zero on success, non-zero on failure
+ * \retval 0 success
+ * \retval non-zero failure
*/
int ast_func_write(struct ast_channel *chan, const char *function, const char *value);
Modified: team/tilghman/str_substitution/main/pbx.c
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/str_substitution/main/pbx.c?view=diff&rev=185908&r1=185907&r2=185908
==============================================================================
--- team/tilghman/str_substitution/main/pbx.c (original)
+++ team/tilghman/str_substitution/main/pbx.c Wed Apr 1 14:35:55 2009
@@ -2836,7 +2836,7 @@
return ret;
}
-static char *ast_str_substring(struct ast_str *value, int offset, int length)
+static const char *ast_str_substring(struct ast_str *value, int offset, int length)
{
int lr; /* length of the input string after the copy */
@@ -2893,17 +2893,19 @@
void pbx_retrieve_variable(struct ast_channel *c, const char *var, char **ret, char *workspace, int workspacelen, struct varshead *headp)
{
struct ast_str *str = ast_str_create(16);
-
- *ret = ast_str_retrieve_variable(&str, 0, c, headp, var);
+ const char *cret;
+
+ cret = ast_str_retrieve_variable(&str, 0, c, headp, var);
ast_copy_string(workspace, ast_str_buffer(str), workspacelen);
- *ret = *ret ? workspace : NULL;
+ *ret = cret ? workspace : NULL;
ast_free(str);
}
-char *ast_str_retrieve_variable(struct ast_str **str, int maxlen, struct ast_channel *c, struct varshead *headp, const char *var)
+const char *ast_str_retrieve_variable(struct ast_str **str, ssize_t maxlen, struct ast_channel *c, struct varshead *headp, const char *var)
{
const char not_found = '\0';
- char *tmpvar, *ret;
+ char *tmpvar;
+ const char *ret;
const char *s; /* the result */
int offset, length;
int i, need_substring;
@@ -3431,7 +3433,7 @@
return -1;
}
-int ast_func_read2(struct ast_channel *chan, const char *function, struct ast_str **str, int maxlen)
+int ast_func_read2(struct ast_channel *chan, const char *function, struct ast_str **str, ssize_t maxlen)
{
char *copy = ast_strdupa(function);
char *args = func_args(copy);
@@ -3500,7 +3502,7 @@
return -1;
}
-void ast_str_substitute_variables_full(struct ast_str **buf, int maxlen, struct ast_channel *c, struct varshead *headp, const char *templ, size_t *used)
+void ast_str_substitute_variables_full(struct ast_str **buf, ssize_t maxlen, struct ast_channel *c, struct varshead *headp, const char *templ, size_t *used)
{
/* Substitutes variables into buf, based on string templ */
char *cp4 = NULL;
@@ -3676,13 +3678,13 @@
ast_free(substr3);
}
-void ast_str_substitute_variables(struct ast_str **buf, int maxlen, struct ast_channel *chan, const char *templ)
+void ast_str_substitute_variables(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ)
{
size_t used;
ast_str_substitute_variables_full(buf, maxlen, chan, NULL, templ, &used);
}
-void ast_str_substitute_variables_varshead(struct ast_str **buf, int maxlen, struct varshead *headp, const char *templ)
+void ast_str_substitute_variables_varshead(struct ast_str **buf, ssize_t maxlen, struct varshead *headp, const char *templ)
{
size_t used;
ast_str_substitute_variables_full(buf, maxlen, NULL, headp, templ, &used);
@@ -4421,23 +4423,24 @@
}
/*! \brief Get hint for channel */
-int ast_str_get_hint(struct ast_str **hint, int hintsize, struct ast_str **name, int namesize, struct ast_channel *c, const char *context, const char *exten)
+int ast_str_get_hint(struct ast_str **hint, ssize_t hintsize, struct ast_str **name, ssize_t namesize, struct ast_channel *c, const char *context, const char *exten)
{
struct ast_exten *e = ast_hint_extension(c, context, exten);
- if (e) {
- if (hint) {
- ast_str_set(hint, hintsize, "%s", ast_get_extension_app(e));
- }
- if (name) {
- const char *tmp = ast_get_extension_app_data(e);
- if (tmp) {
- ast_str_set(name, namesize, "%s", tmp);
- }
- }
- return -1;
- }
- return 0;
+ if (!e) {
+ return 0;
+ }
+
+ if (hint) {
+ ast_str_set(hint, hintsize, "%s", ast_get_extension_app(e));
+ }
+ if (name) {
+ const char *tmp = ast_get_extension_app_data(e);
+ if (tmp) {
+ ast_str_set(name, namesize, "%s", tmp);
+ }
+ }
+ return -1;
}
int ast_exists_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
More information about the asterisk-commits
mailing list