[asterisk-commits] tilghman: trunk r87103 - in /trunk: funcs/ include/asterisk/ main/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Oct 25 19:11:32 CDT 2007
Author: tilghman
Date: Thu Oct 25 19:11:31 2007
New Revision: 87103
URL: http://svn.digium.com/view/asterisk?view=rev&rev=87103
Log:
Use the same delimited character as the FILTER function in FIELDQTY and CUT.
Modified:
trunk/funcs/func_cut.c
trunk/funcs/func_strings.c
trunk/include/asterisk/app.h
trunk/main/app.c
Modified: trunk/funcs/func_cut.c
URL: http://svn.digium.com/view/asterisk/trunk/funcs/func_cut.c?view=diff&rev=87103&r1=87102&r2=87103
==============================================================================
--- trunk/funcs/func_cut.c (original)
+++ trunk/funcs/func_cut.c Thu Oct 25 19:11:31 2007
@@ -118,6 +118,7 @@
static int cut_internal(struct ast_channel *chan, char *data, char *buffer, size_t buflen)
{
char *parse;
+ size_t delim_consumed;
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(varname);
AST_APP_ARG(delimiter);
@@ -134,7 +135,7 @@
if (args.argc < 3) {
return ERROR_NOARG;
} else {
- char d, ds[2];
+ char d, ds[2] = "";
char *tmp = alloca(strlen(args.varname) + 4);
char varvalue[MAXRESULT], *tmp2=varvalue;
@@ -145,22 +146,11 @@
return ERROR_NOMEM;
}
- if (args.delimiter[0] == '\\') {
- if (args.delimiter[1] == 'n')
- d = '\n';
- else if (args.delimiter[1] == 't')
- d = '\t';
- else if (args.delimiter[1])
- d = args.delimiter[1];
- else
- d = '-';
- } else if (args.delimiter[0])
- d = args.delimiter[0];
- else
- d = '-';
+ if (ast_get_encoded_char(args.delimiter, ds, &delim_consumed))
+ return ERROR_NOARG;
/* String form of the delimiter, for use with strsep(3) */
- snprintf(ds, sizeof(ds), "%c", d);
+ d = *ds;
pbx_substitute_variables_helper(chan, tmp, tmp2, MAXRESULT - 1);
Modified: trunk/funcs/func_strings.c
URL: http://svn.digium.com/view/asterisk/trunk/funcs/func_strings.c?view=diff&rev=87103&r1=87102&r2=87103
==============================================================================
--- trunk/funcs/func_strings.c (original)
+++ trunk/funcs/func_strings.c Thu Oct 25 19:11:31 2007
@@ -54,19 +54,13 @@
AST_APP_ARG(varname);
AST_APP_ARG(delim);
);
+ char delim[2] = "";
+ size_t delim_used;
AST_STANDARD_APP_ARGS(args, parse);
if (args.delim) {
- if (args.delim[0] == '\\') {
- if (args.delim[1] == 'n')
- ast_copy_string(args.delim, "\n", 2);
- else if (args.delim[1] == 't')
- ast_copy_string(args.delim, "\t", 2);
- else if (args.delim[1])
- ast_copy_string(args.delim, &args.delim[1], 2);
- else
- ast_copy_string(args.delim, "-", 2);
- }
+ ast_get_encoded_char(args.delim, delim, &delim_used);
+
varsubst = alloca(strlen(args.varname) + 4);
sprintf(varsubst, "${%s}", args.varname);
@@ -74,7 +68,7 @@
if (ast_strlen_zero(varval2))
fieldcount = 0;
else {
- while (strsep(&varval2, args.delim))
+ while (strsep(&varval2, delim))
fieldcount++;
}
} else {
@@ -91,73 +85,6 @@
.syntax = "FIELDQTY(<varname>,<delim>)",
.read = function_fieldqty,
};
-
-static int get_filter_char(const char *stream, char *result, size_t *consumed)
-{
- int i;
- *consumed = 1;
- *result = 0;
- if (*stream == '\\') {
- *consumed = 2;
- switch (*(stream + 1)) {
- case 'n':
- *result = '\n';
- break;
- case 'r':
- *result = '\r';
- break;
- case 't':
- *result = '\t';
- break;
- case 'x':
- /* Hexadecimal */
- if (strchr("0123456789ABCDEFabcdef", *(stream + 2)) && *(stream + 2) != '\0') {
- *consumed = 3;
- if (*(stream + 2) <= '9')
- *result = *(stream + 2) - '0';
- else if (*(stream + 2) <= 'F')
- *result = *(stream + 2) - 'A' + 10;
- else
- *result = *(stream + 2) - 'a' + 10;
- } else {
- ast_log(LOG_ERROR, "Illegal character '%c' in hexadecimal string\n", *(stream + 2));
- return -1;
- }
-
- if (strchr("0123456789ABCDEFabcdef", *(stream + 3)) && *(stream + 3) != '\0') {
- *consumed = 4;
- *result <<= 4;
- if (*(stream + 3) <= '9')
- *result += *(stream + 3) - '0';
- else if (*(stream + 3) <= 'F')
- *result += *(stream + 3) - 'A' + 10;
- else
- *result += *(stream + 3) - 'a' + 10;
- }
- break;
- case '0':
- /* Octal */
- *consumed = 2;
- for (i = 2; ; i++) {
- if (strchr("01234567", *(stream + i)) && *(stream + i) != '\0') {
- (*consumed)++;
- ast_debug(5, "result was %d, ", *result);
- *result <<= 3;
- *result += *(stream + i) - '0';
- ast_debug(5, "is now %d\n", *result);
- } else
- break;
- }
- break;
- default:
- *result = *(stream + 1);
- }
- } else {
- *result = *stream;
- *consumed = 1;
- }
- return 0;
-}
static int filter(struct ast_channel *chan, const char *cmd, char *parse, char *buf,
size_t len)
@@ -182,12 +109,12 @@
char c1 = 0, c2 = 0;
size_t consumed = 0;
- if (get_filter_char(args.allowed, &c1, &consumed))
+ if (ast_get_encoded_char(args.allowed, &c1, &consumed))
return -1;
args.allowed += consumed;
if (*(args.allowed) == '-') {
- if (get_filter_char(args.allowed + 1, &c2, &consumed))
+ if (ast_get_encoded_char(args.allowed + 1, &c2, &consumed))
c2 = -1;
args.allowed += consumed + 1;
Modified: trunk/include/asterisk/app.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/app.h?view=diff&rev=87103&r1=87102&r2=87103
==============================================================================
--- trunk/include/asterisk/app.h (original)
+++ trunk/include/asterisk/app.h Thu Oct 25 19:11:31 2007
@@ -457,6 +457,9 @@
/*! Allow to record message and have a review option */
int ast_record_review(struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration, const char *path);
+/*! Decode an encoded control or extended ASCII character */
+int ast_get_encoded_char(const char *stream, char *result, size_t *consumed);
+
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif
Modified: trunk/main/app.c
URL: http://svn.digium.com/view/asterisk/trunk/main/app.c?view=diff&rev=87103&r1=87102&r2=87103
==============================================================================
--- trunk/main/app.c (original)
+++ trunk/main/app.c Thu Oct 25 19:11:31 2007
@@ -1664,3 +1664,70 @@
return res;
}
+int ast_get_encoded_char(const char *stream, char *result, size_t *consumed)
+{
+ int i;
+ *consumed = 1;
+ *result = 0;
+ if (*stream == '\\') {
+ *consumed = 2;
+ switch (*(stream + 1)) {
+ case 'n':
+ *result = '\n';
+ break;
+ case 'r':
+ *result = '\r';
+ break;
+ case 't':
+ *result = '\t';
+ break;
+ case 'x':
+ /* Hexadecimal */
+ if (strchr("0123456789ABCDEFabcdef", *(stream + 2)) && *(stream + 2) != '\0') {
+ *consumed = 3;
+ if (*(stream + 2) <= '9')
+ *result = *(stream + 2) - '0';
+ else if (*(stream + 2) <= 'F')
+ *result = *(stream + 2) - 'A' + 10;
+ else
+ *result = *(stream + 2) - 'a' + 10;
+ } else {
+ ast_log(LOG_ERROR, "Illegal character '%c' in hexadecimal string\n", *(stream + 2));
+ return -1;
+ }
+
+ if (strchr("0123456789ABCDEFabcdef", *(stream + 3)) && *(stream + 3) != '\0') {
+ *consumed = 4;
+ *result <<= 4;
+ if (*(stream + 3) <= '9')
+ *result += *(stream + 3) - '0';
+ else if (*(stream + 3) <= 'F')
+ *result += *(stream + 3) - 'A' + 10;
+ else
+ *result += *(stream + 3) - 'a' + 10;
+ }
+ break;
+ case '0':
+ /* Octal */
+ *consumed = 2;
+ for (i = 2; ; i++) {
+ if (strchr("01234567", *(stream + i)) && *(stream + i) != '\0') {
+ (*consumed)++;
+ ast_debug(5, "result was %d, ", *result);
+ *result <<= 3;
+ *result += *(stream + i) - '0';
+ ast_debug(5, "is now %d\n", *result);
+ } else
+ break;
+ }
+ break;
+ default:
+ *result = *(stream + 1);
+ }
+ } else {
+ *result = *stream;
+ *consumed = 1;
+ }
+ return 0;
+}
+
More information about the asterisk-commits
mailing list