Thu Oct 11 06:43:45 2012

Asterisk developer's documentation


func_strings.c File Reference

String manipulation dialplan functions. More...

#include "asterisk.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <regex.h>
#include "asterisk/module.h"
#include "asterisk/options.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/logger.h"
#include "asterisk/utils.h"
#include "asterisk/app.h"
#include "asterisk/localtime.h"

Include dependency graph for func_strings.c:

Go to the source code of this file.

Defines

#define SPRINTF_CONVERSION   4
#define SPRINTF_FLAG   0
#define SPRINTF_LENGTH   3
#define SPRINTF_PRECISION   2
#define SPRINTF_WIDTH   1

Functions

static void __reg_module (void)
static void __unreg_module (void)
static int acf_sprintf (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)
static int acf_strptime (struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
static int array (struct ast_channel *chan, char *cmd, char *var, const char *value)
static int csv_quote (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)
static int function_eval (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)
static int keypadhash (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)
static int load_module (void)
static int quote (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)
static int unload_module (void)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = "String handling dialplan functions" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, }
static struct ast_custom_function array_function
static const struct
ast_module_info
ast_module_info = &__mod_info
static struct ast_custom_function csv_quote_function
static struct ast_custom_function eval_function
static struct ast_custom_function fieldqty_function
static struct ast_custom_function filter_function
static struct ast_custom_function keypadhash_function
static struct ast_custom_function len_function
static struct ast_custom_function quote_function
static struct ast_custom_function regex_function
static struct ast_custom_function sprintf_function
static struct ast_custom_function strftime_function
static struct ast_custom_function strptime_function


Detailed Description

String manipulation dialplan functions.

Author:
Tilghman Lesher

Anothony Minessale II

Definition in file func_strings.c.


Define Documentation

#define SPRINTF_CONVERSION   4

Referenced by acf_sprintf().

#define SPRINTF_FLAG   0

Referenced by acf_sprintf().

#define SPRINTF_LENGTH   3

Referenced by acf_sprintf().

#define SPRINTF_PRECISION   2

Referenced by acf_sprintf().

#define SPRINTF_WIDTH   1

Referenced by acf_sprintf().


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 687 of file func_strings.c.

static void __unreg_module ( void   )  [static]

Definition at line 687 of file func_strings.c.

static int acf_sprintf ( struct ast_channel chan,
char *  cmd,
char *  data,
char *  buf,
size_t  len 
) [static]

Definition at line 229 of file func_strings.c.

References AST_APP_ARG, ast_copy_string(), AST_DECLARE_APP_ARGS, ast_log(), AST_STANDARD_APP_ARGS, format, LOG_ERROR, SPRINTF_CONVERSION, SPRINTF_FLAG, SPRINTF_LENGTH, SPRINTF_PRECISION, SPRINTF_WIDTH, and var.

00230 {
00231 #define SPRINTF_FLAG 0
00232 #define SPRINTF_WIDTH   1
00233 #define SPRINTF_PRECISION  2
00234 #define SPRINTF_LENGTH  3
00235 #define SPRINTF_CONVERSION 4
00236    int i, state = -1, argcount = 0;
00237    char *formatstart = NULL, *bufptr = buf;
00238    char formatbuf[256] = "";
00239    int tmpi;
00240    double tmpd;
00241    AST_DECLARE_APP_ARGS(arg,
00242             AST_APP_ARG(format);
00243             AST_APP_ARG(var)[100];
00244    );
00245 
00246    AST_STANDARD_APP_ARGS(arg, data);
00247 
00248    /* Scan the format, converting each argument into the requisite format type. */
00249    for (i = 0; arg.format[i]; i++) {
00250       switch (state) {
00251       case SPRINTF_FLAG:
00252          if (strchr("#0- +'I", arg.format[i]))
00253             break;
00254          state = SPRINTF_WIDTH;
00255       case SPRINTF_WIDTH:
00256          if (arg.format[i] >= '0' && arg.format[i] <= '9')
00257             break;
00258 
00259          /* Next character must be a period to go into a precision */
00260          if (arg.format[i] == '.') {
00261             state = SPRINTF_PRECISION;
00262          } else {
00263             state = SPRINTF_LENGTH;
00264             i--;
00265          }
00266          break;
00267       case SPRINTF_PRECISION:
00268          if (arg.format[i] >= '0' && arg.format[i] <= '9')
00269             break;
00270          state = SPRINTF_LENGTH;
00271       case SPRINTF_LENGTH:
00272          if (strchr("hl", arg.format[i])) {
00273             if (arg.format[i + 1] == arg.format[i])
00274                i++;
00275             state = SPRINTF_CONVERSION;
00276             break;
00277          } else if (strchr("Lqjzt", arg.format[i])) {
00278             state = SPRINTF_CONVERSION;
00279             break;
00280          }
00281          state = SPRINTF_CONVERSION;
00282       case SPRINTF_CONVERSION:
00283          if (strchr("diouxXc", arg.format[i])) {
00284             /* Integer */
00285 
00286             /* Isolate this format alone */
00287             ast_copy_string(formatbuf, formatstart, sizeof(formatbuf));
00288             formatbuf[&arg.format[i] - formatstart + 1] = '\0';
00289 
00290             /* Convert the argument into the required type */
00291             if (arg.var[argcount]) {
00292                if (sscanf(arg.var[argcount++], "%30d", &tmpi) != 1) {
00293                   ast_log(LOG_ERROR, "Argument '%s' is not an integer number for format '%s'\n", arg.var[argcount - 1], formatbuf);
00294                   goto sprintf_fail;
00295                }
00296             } else {
00297                ast_log(LOG_ERROR, "SPRINTF() has more format specifiers than arguments!\n");
00298                goto sprintf_fail;
00299             }
00300 
00301             /* Format the argument */
00302             snprintf(bufptr, buf + len - bufptr, formatbuf, tmpi);
00303 
00304             /* Update the position of the next parameter to print */
00305             bufptr = strchr(buf, '\0');
00306          } else if (strchr("eEfFgGaA", arg.format[i])) {
00307             /* Double */
00308 
00309             /* Isolate this format alone */
00310             ast_copy_string(formatbuf, formatstart, sizeof(formatbuf));
00311             formatbuf[&arg.format[i] - formatstart + 1] = '\0';
00312 
00313             /* Convert the argument into the required type */
00314             if (arg.var[argcount]) {
00315                if (sscanf(arg.var[argcount++], "%30lf", &tmpd) != 1) {
00316                   ast_log(LOG_ERROR, "Argument '%s' is not a floating point number for format '%s'\n", arg.var[argcount - 1], formatbuf);
00317                   goto sprintf_fail;
00318                }
00319             } else {
00320                ast_log(LOG_ERROR, "SPRINTF() has more format specifiers than arguments!\n");
00321                goto sprintf_fail;
00322             }
00323 
00324             /* Format the argument */
00325             snprintf(bufptr, buf + len - bufptr, formatbuf, tmpd);
00326 
00327             /* Update the position of the next parameter to print */
00328             bufptr = strchr(buf, '\0');
00329          } else if (arg.format[i] == 's') {
00330             /* String */
00331 
00332             /* Isolate this format alone */
00333             ast_copy_string(formatbuf, formatstart, sizeof(formatbuf));
00334             formatbuf[&arg.format[i] - formatstart + 1] = '\0';
00335 
00336             /* Format the argument */
00337             snprintf(bufptr, buf + len - bufptr, formatbuf, arg.var[argcount++]);
00338 
00339             /* Update the position of the next parameter to print */
00340             bufptr = strchr(buf, '\0');
00341          } else if (arg.format[i] == '%') {
00342             /* Literal data to copy */
00343             *bufptr++ = arg.format[i];
00344          } else {
00345             /* Not supported */
00346 
00347             /* Isolate this format alone */
00348             ast_copy_string(formatbuf, formatstart, sizeof(formatbuf));
00349             formatbuf[&arg.format[i] - formatstart + 1] = '\0';
00350 
00351             ast_log(LOG_ERROR, "Format type not supported: '%s' with argument '%s'\n", formatbuf, arg.var[argcount++]);
00352             goto sprintf_fail;
00353          }
00354          state = -1;
00355          break;
00356       default:
00357          if (arg.format[i] == '%') {
00358             state = SPRINTF_FLAG;
00359             formatstart = &arg.format[i];
00360             break;
00361          } else {
00362             /* Literal data to copy */
00363             *bufptr++ = arg.format[i];
00364          }
00365       }
00366    }
00367    *bufptr = '\0';
00368    return 0;
00369 sprintf_fail:
00370    return -1;
00371 }

static int acf_strftime ( struct ast_channel chan,
char *  cmd,
char *  parse,
char *  buf,
size_t  len 
) [static]

Definition at line 483 of file func_strings.c.

References AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_get_time_t(), ast_localtime(), ast_log(), AST_STANDARD_APP_ARGS, format, and LOG_WARNING.

00485 {
00486    AST_DECLARE_APP_ARGS(args,
00487               AST_APP_ARG(epoch);
00488               AST_APP_ARG(timezone);
00489               AST_APP_ARG(format);
00490    );
00491    time_t epochi;
00492    struct tm tm;
00493 
00494    buf[0] = '\0';
00495 
00496    AST_STANDARD_APP_ARGS(args, parse);
00497 
00498    ast_get_time_t(args.epoch, &epochi, time(NULL), NULL);
00499    ast_localtime(&epochi, &tm, args.timezone);
00500 
00501    if (!args.format)
00502       args.format = "%c";
00503 
00504    if (!strftime(buf, len, args.format, &tm))
00505       ast_log(LOG_WARNING, "C function strftime() output nothing?!!\n");
00506 
00507    buf[len - 1] = '\0';
00508 
00509    return 0;
00510 }

static int acf_strptime ( struct ast_channel chan,
char *  cmd,
char *  data,
char *  buf,
size_t  len 
) [static]

Definition at line 519 of file func_strings.c.

References AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_log(), ast_mktime(), AST_STANDARD_APP_ARGS, ast_strlen_zero(), format, LOG_ERROR, and LOG_WARNING.

00521 {
00522    AST_DECLARE_APP_ARGS(args,
00523               AST_APP_ARG(timestring);
00524               AST_APP_ARG(timezone);
00525               AST_APP_ARG(format);
00526    );
00527    struct tm time;
00528 
00529    memset(&time, 0, sizeof(struct tm));
00530 
00531    buf[0] = '\0';
00532 
00533    if (!data) {
00534       ast_log(LOG_ERROR,
00535             "Asterisk function STRPTIME() requires an argument.\n");
00536       return -1;
00537    }
00538 
00539    AST_STANDARD_APP_ARGS(args, data);
00540 
00541    if (ast_strlen_zero(args.format)) {
00542       ast_log(LOG_ERROR,
00543             "No format supplied to STRPTIME(<timestring>|<timezone>|<format>)");
00544       return -1;
00545    }
00546 
00547    if (!strptime(args.timestring, args.format, &time)) {
00548       ast_log(LOG_WARNING, "C function strptime() output nothing?!!\n");
00549    } else {
00550       /* Since strptime(3) does not check DST, force ast_mktime() to calculate it. */
00551       time.tm_isdst = -1;
00552       snprintf(buf, len, "%d", (int) ast_mktime(&time, args.timezone));
00553    }
00554 
00555    return 0;
00556 }

static int array ( struct ast_channel chan,
char *  cmd,
char *  var,
const char *  value 
) [static]

Definition at line 165 of file func_strings.c.

References AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_log(), AST_NONSTANDARD_APP_ARGS, AST_STANDARD_APP_ARGS, ast_strdupa, LOG_DEBUG, option_debug, and pbx_builtin_setvar_helper().

00167 {
00168    AST_DECLARE_APP_ARGS(arg1,
00169               AST_APP_ARG(var)[100];
00170    );
00171    AST_DECLARE_APP_ARGS(arg2,
00172               AST_APP_ARG(val)[100];
00173    );
00174    char *value2;
00175    int i;
00176 
00177    value2 = ast_strdupa(value);
00178    if (!var || !value2)
00179       return -1;
00180 
00181    /* The functions this will generally be used with are SORT and ODBC_*, which
00182     * both return comma-delimited lists.  However, if somebody uses literal lists,
00183     * their commas will be translated to vertical bars by the load, and I don't
00184     * want them to be surprised by the result.  Hence, we prefer commas as the
00185     * delimiter, but we'll fall back to vertical bars if commas aren't found.
00186     */
00187    if (option_debug)
00188       ast_log(LOG_DEBUG, "array (%s=%s)\n", var, value2);
00189    if (strchr(var, ','))
00190       AST_NONSTANDARD_APP_ARGS(arg1, var, ',');
00191    else
00192       AST_STANDARD_APP_ARGS(arg1, var);
00193 
00194    if (strchr(value2, ','))
00195       AST_NONSTANDARD_APP_ARGS(arg2, value2, ',');
00196    else
00197       AST_STANDARD_APP_ARGS(arg2, value2);
00198 
00199    for (i = 0; i < arg1.argc; i++) {
00200       if (option_debug)
00201          ast_log(LOG_DEBUG, "array set value (%s=%s)\n", arg1.var[i],
00202             arg2.val[i]);
00203       if (i < arg2.argc) {
00204          pbx_builtin_setvar_helper(chan, arg1.var[i], arg2.val[i]);
00205       } else {
00206          /* We could unset the variable, by passing a NULL, but due to
00207           * pushvar semantics, that could create some undesired behavior. */
00208          pbx_builtin_setvar_helper(chan, arg1.var[i], "");
00209       }
00210    }
00211 
00212    return 0;
00213 }

static int csv_quote ( struct ast_channel chan,
char *  cmd,
char *  data,
char *  buf,
size_t  len 
) [static]

Definition at line 425 of file func_strings.c.

References ast_copy_string(), ast_log(), ast_strlen_zero(), LOG_ERROR, and LOG_WARNING.

00426 {
00427    char *bufptr = buf, *dataptr = data;
00428 
00429    if (len < 3){ /* at least two for quotes and one for binary zero */
00430       ast_log(LOG_ERROR, "Not enough buffer");
00431       return -1;
00432    }
00433 
00434    if (ast_strlen_zero(data)) {
00435       ast_log(LOG_WARNING, "No argument specified!\n");
00436       ast_copy_string(buf,"\"\"",len);
00437       return 0;
00438    }
00439 
00440    *bufptr++ = '"';
00441    for (; bufptr < buf + len - 3; dataptr++){
00442       if (*dataptr == '"') {
00443          *bufptr++ = '"';
00444          *bufptr++ = '"';
00445       } else if (*dataptr == '\0') {
00446          break;
00447       } else {
00448          *bufptr++ = *dataptr;
00449       }
00450    }
00451    *bufptr++ = '"';
00452    *bufptr='\0';
00453    return 0;
00454 }

static int filter ( struct ast_channel chan,
char *  cmd,
char *  parse,
char *  buf,
size_t  len 
) [static]

Definition at line 83 of file func_strings.c.

References AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_log(), AST_STANDARD_APP_ARGS, and LOG_ERROR.

00085 {
00086    AST_DECLARE_APP_ARGS(args,
00087               AST_APP_ARG(allowed);
00088               AST_APP_ARG(string);
00089    );
00090    char *outbuf = buf;
00091 
00092    AST_STANDARD_APP_ARGS(args, parse);
00093 
00094    if (!args.string) {
00095       ast_log(LOG_ERROR, "Usage: FILTER(<allowed-chars>|<string>)\n");
00096       return -1;
00097    }
00098 
00099    for (; *(args.string) && (buf + len - 1 > outbuf); (args.string)++) {
00100       if (strchr(args.allowed, *(args.string)))
00101          *outbuf++ = *(args.string);
00102    }
00103    *outbuf = '\0';
00104 
00105    return 0;
00106 }

static int function_eval ( struct ast_channel chan,
char *  cmd,
char *  data,
char *  buf,
size_t  len 
) [static]

Definition at line 573 of file func_strings.c.

References ast_log(), ast_strlen_zero(), LOG_WARNING, and pbx_substitute_variables_helper().

00575 {
00576    memset(buf, 0, len);
00577 
00578    if (ast_strlen_zero(data)) {
00579       ast_log(LOG_WARNING, "EVAL requires an argument: EVAL(<string>)\n");
00580       return -1;
00581    }
00582 
00583    pbx_substitute_variables_helper(chan, data, buf, len - 1);
00584 
00585    return 0;
00586 }

static int function_fieldqty ( struct ast_channel chan,
char *  cmd,
char *  parse,
char *  buf,
size_t  len 
) [static]

Definition at line 46 of file func_strings.c.

References AST_APP_ARG, AST_DECLARE_APP_ARGS, AST_STANDARD_APP_ARGS, ast_strlen_zero(), and pbx_substitute_variables_helper().

00048 {
00049    char *varsubst, varval[8192] = "", *varval2 = varval;
00050    int fieldcount = 0;
00051    AST_DECLARE_APP_ARGS(args,
00052               AST_APP_ARG(varname);
00053               AST_APP_ARG(delim);
00054       );
00055 
00056    AST_STANDARD_APP_ARGS(args, parse);
00057    if (args.delim) {
00058       varsubst = alloca(strlen(args.varname) + 4);
00059 
00060       sprintf(varsubst, "${%s}", args.varname);
00061       pbx_substitute_variables_helper(chan, varsubst, varval, sizeof(varval) - 1);
00062       if (ast_strlen_zero(varval2))
00063          fieldcount = 0;
00064       else {
00065          while (strsep(&varval2, args.delim))
00066             fieldcount++;
00067       }
00068    } else {
00069       fieldcount = 1;
00070    }
00071    snprintf(buf, len, "%d", fieldcount);
00072 
00073    return 0;
00074 }

static int keypadhash ( struct ast_channel chan,
char *  cmd,
char *  data,
char *  buf,
size_t  len 
) [static]

Definition at line 604 of file func_strings.c.

00605 {
00606    char *bufptr, *dataptr;
00607 
00608    for (bufptr = buf, dataptr = data; bufptr < buf + len - 1; dataptr++) {
00609       if (*dataptr == '\0') {
00610          *bufptr++ = '\0';
00611          break;
00612       } else if (*dataptr == '1') {
00613          *bufptr++ = '1';
00614       } else if (strchr("AaBbCc2", *dataptr)) {
00615          *bufptr++ = '2';
00616       } else if (strchr("DdEeFf3", *dataptr)) {
00617          *bufptr++ = '3';
00618       } else if (strchr("GgHhIi4", *dataptr)) {
00619          *bufptr++ = '4';
00620       } else if (strchr("JjKkLl5", *dataptr)) {
00621          *bufptr++ = '5';
00622       } else if (strchr("MmNnOo6", *dataptr)) {
00623          *bufptr++ = '6';
00624       } else if (strchr("PpQqRrSs7", *dataptr)) {
00625          *bufptr++ = '7';
00626       } else if (strchr("TtUuVv8", *dataptr)) {
00627          *bufptr++ = '8';
00628       } else if (strchr("WwXxYyZz9", *dataptr)) {
00629          *bufptr++ = '9';
00630       } else if (*dataptr == '0') {
00631          *bufptr++ = '0';
00632       }
00633    }
00634    buf[len - 1] = '\0';
00635 
00636    return 0;
00637 }

static int len ( struct ast_channel chan,
char *  cmd,
char *  data,
char *  buf,
size_t  len 
) [static]

Definition at line 463 of file func_strings.c.

Referenced by __ast_cli_register(), __get_header(), _parse(), add_sdp(), aji_act_hook(), alsa_write(), append_interface(), ast_app_group_set_channel(), ast_callerid_vmwi_generate(), ast_cdr_appenduserfield(), ast_cli_complete(), ast_codec_get_len(), ast_dsp_digitdetect(), ast_dsp_process(), ast_dsp_silence(), ast_format_str_reduce(), ast_frdup(), ast_getformatname_multiple(), ast_read_image(), ast_rtcp_read(), ast_rtcp_write_rr(), ast_rtcp_write_sr(), ast_rtp_lookup_mime_multiple(), ast_rtp_read(), ast_safe_string_alloc(), ast_say_number_full_ka(), ast_smoother_read(), ast_translate(), ast_udptl_read(), ast_udptl_write(), auth_exec(), authenticate(), build_facility(), builtin_automonitor(), callerid_generate(), cli_complete(), complete_agent_logoff_cmd(), complete_context_add_extension(), complete_context_add_extension_deprecated(), complete_context_add_ignorepat(), complete_context_add_ignorepat_deprecated(), complete_context_add_include(), complete_context_add_include_deprecated(), complete_context_dont_include_deprecated(), complete_context_remove_extension(), complete_context_remove_extension_deprecated(), complete_context_remove_ignorepat(), complete_context_remove_ignorepat_deprecated(), complete_context_remove_include(), complete_meetmecmd(), complete_peer_helper(), conf_play(), config_jitterbuffer(), copy(), dahdi_digit_begin(), dahdi_setoption(), dictate_exec(), dundi_encrypt(), dundi_parse_ies(), dundi_send(), expr2_token_subst(), feature_request_and_dial(), generic_http_callback(), get_sdp(), get_sdp_iterate(), gsm_write(), gsmtolin_framein(), h263_read(), h263_write(), h264_read(), h264_write(), handle_commandmatchesarray(), handle_message(), handle_response(), handle_uri(), help1(), html_translate(), iax_parse_ies(), iax_str2flags(), launch_monitor_thread(), listener(), local_call(), lpc10tolin_framein(), mgcp_ss(), mgcpsock_read(), misdn_read(), monmp3thread(), newpvt(), ogg_vorbis_read(), parse_ie(), pbx_load_users(), pbx_substitute_variables_helper_full(), process_sdp(), readfile_exec(), realtime_exec(), reschedule_precache(), run_agi(), set(), skinny_ss(), socket_read(), ss_thread(), static_callback(), term_filter_escapes(), transfer_exec(), udptl_build_packet(), wav_write(), and xml_translate().

00465 {
00466    int length = 0;
00467 
00468    if (data)
00469       length = strlen(data);
00470 
00471    snprintf(buf, len, "%d", length);
00472 
00473    return 0;
00474 }

static int load_module ( void   )  [static]

static int quote ( struct ast_channel chan,
char *  cmd,
char *  data,
char *  buf,
size_t  len 
) [static]

Definition at line 384 of file func_strings.c.

References ast_copy_string(), ast_log(), ast_strlen_zero(), LOG_ERROR, and LOG_WARNING.

Referenced by ast_app_parse_options(), ast_app_separate_args(), and make_email_file().

00385 {
00386    char *bufptr = buf, *dataptr = data;
00387 
00388    if (len < 3){ /* at least two for quotes and one for binary zero */
00389       ast_log(LOG_ERROR, "Not enough buffer");
00390       return -1;
00391    }
00392 
00393    if (ast_strlen_zero(data)) {
00394       ast_log(LOG_WARNING, "No argument specified!\n");
00395       ast_copy_string(buf, "\"\"", len);
00396       return 0;
00397    }
00398 
00399    *bufptr++ = '"';
00400    for (; bufptr < buf + len - 3; dataptr++) {
00401       if (*dataptr == '\\') {
00402          *bufptr++ = '\\';
00403          *bufptr++ = '\\';
00404       } else if (*dataptr == '"') {
00405          *bufptr++ = '\\';
00406          *bufptr++ = '"';
00407       } else if (*dataptr == '\0') {
00408          break;
00409       } else {
00410          *bufptr++ = *dataptr;
00411       }
00412    }
00413    *bufptr++ = '"';
00414    *bufptr = '\0';
00415    return 0;
00416 }

static int regex ( struct ast_channel chan,
char *  cmd,
char *  parse,
char *  buf,
size_t  len 
) [static]

Definition at line 115 of file func_strings.c.

References AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_log(), AST_NONSTANDARD_APP_ARGS, LOG_DEBUG, LOG_ERROR, LOG_WARNING, and option_debug.

00117 {
00118    AST_DECLARE_APP_ARGS(args,
00119               AST_APP_ARG(null);
00120               AST_APP_ARG(reg);
00121               AST_APP_ARG(str);
00122    );
00123    int errcode;
00124    regex_t regexbuf;
00125 
00126    buf[0] = '\0';
00127 
00128    AST_NONSTANDARD_APP_ARGS(args, parse, '"');
00129 
00130    if (args.argc != 3) {
00131       ast_log(LOG_ERROR, "Unexpected arguments: should have been in the form '\"<regex>\" <string>'\n");
00132       return -1;
00133    }
00134    if ((*args.str == ' ') || (*args.str == '\t'))
00135       args.str++;
00136 
00137    if (option_debug)
00138       ast_log(LOG_DEBUG, "FUNCTION REGEX (%s)(%s)\n", args.reg, args.str);
00139 
00140    if ((errcode = regcomp(&regexbuf, args.reg, REG_EXTENDED | REG_NOSUB))) {
00141       regerror(errcode, &regexbuf, buf, len);
00142       ast_log(LOG_WARNING, "Malformed input %s(%s): %s\n", cmd, parse, buf);
00143       return -1;
00144    }
00145    
00146    strcpy(buf, regexec(&regexbuf, args.str, 0, NULL, 0) ? "0" : "1");
00147 
00148    regfree(&regexbuf);
00149 
00150    return 0;
00151 }

static int unload_module ( void   )  [static]


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = "String handling dialplan functions" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, } [static]

Definition at line 687 of file func_strings.c.

Definition at line 215 of file func_strings.c.

const struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 687 of file func_strings.c.

Definition at line 456 of file func_strings.c.

Definition at line 588 of file func_strings.c.

Definition at line 76 of file func_strings.c.

Definition at line 108 of file func_strings.c.

Definition at line 639 of file func_strings.c.

Definition at line 476 of file func_strings.c.

Definition at line 418 of file func_strings.c.

Definition at line 153 of file func_strings.c.

Definition at line 373 of file func_strings.c.

Definition at line 512 of file func_strings.c.

Definition at line 558 of file func_strings.c.


Generated on Thu Oct 11 06:43:45 2012 for Asterisk - the Open Source PBX by  doxygen 1.5.6