Fri Jul 3 20:38:23 2009

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 <ctype.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 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 function_tolower (struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
static int function_toupper (struct ast_channel *chan, char *cmd, char *data, 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 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
static struct ast_custom_function tolower_function
static struct ast_custom_function toupper_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 706 of file func_strings.c.

static void __unreg_module ( void   )  [static]

Definition at line 706 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 233 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.

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

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

Definition at line 438 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.

00440 {
00441    AST_DECLARE_APP_ARGS(args,
00442               AST_APP_ARG(epoch);
00443               AST_APP_ARG(timezone);
00444               AST_APP_ARG(format);
00445    );
00446    time_t epochi;
00447    struct tm tm;
00448 
00449    buf[0] = '\0';
00450 
00451    AST_STANDARD_APP_ARGS(args, parse);
00452 
00453    ast_get_time_t(args.epoch, &epochi, time(NULL), NULL);
00454    ast_localtime(&epochi, &tm, args.timezone);
00455 
00456    if (!args.format)
00457       args.format = "%c";
00458 
00459    if (!strftime(buf, len, args.format, &tm))
00460       ast_log(LOG_WARNING, "C function strftime() output nothing?!!\n");
00461 
00462    buf[len - 1] = '\0';
00463 
00464    return 0;
00465 }

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

Definition at line 474 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.

00476 {
00477    AST_DECLARE_APP_ARGS(args,
00478               AST_APP_ARG(timestring);
00479               AST_APP_ARG(timezone);
00480               AST_APP_ARG(format);
00481    );
00482    struct tm time;
00483 
00484    memset(&time, 0, sizeof(struct tm));
00485 
00486    buf[0] = '\0';
00487 
00488    if (!data) {
00489       ast_log(LOG_ERROR,
00490             "Asterisk function STRPTIME() requires an argument.\n");
00491       return -1;
00492    }
00493 
00494    AST_STANDARD_APP_ARGS(args, data);
00495 
00496    if (ast_strlen_zero(args.format)) {
00497       ast_log(LOG_ERROR,
00498             "No format supplied to STRPTIME(<timestring>|<timezone>|<format>)");
00499       return -1;
00500    }
00501 
00502    if (!strptime(args.timestring, args.format, &time)) {
00503       ast_log(LOG_WARNING, "C function strptime() output nothing?!!\n");
00504    } else {
00505       /* Since strptime(3) does not check DST, force ast_mktime() to calculate it. */
00506       time.tm_isdst = -1;
00507       snprintf(buf, len, "%d", (int) ast_mktime(&time, args.timezone));
00508    }
00509 
00510    return 0;
00511 }

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

Definition at line 169 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().

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

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

Definition at line 87 of file func_strings.c.

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

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

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

Definition at line 528 of file func_strings.c.

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

00530 {
00531    memset(buf, 0, len);
00532 
00533    if (ast_strlen_zero(data)) {
00534       ast_log(LOG_WARNING, "EVAL requires an argument: EVAL(<string>)\n");
00535       return -1;
00536    }
00537 
00538    pbx_substitute_variables_helper(chan, data, buf, len - 1);
00539 
00540    return 0;
00541 }

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

Definition at line 47 of file func_strings.c.

References AST_APP_ARG, ast_copy_string(), AST_DECLARE_APP_ARGS, AST_STANDARD_APP_ARGS, and pbx_retrieve_variable().

00049 {
00050    char *varsubst, varval[8192] = "", *varval2 = varval;
00051    int fieldcount = 0;
00052    AST_DECLARE_APP_ARGS(args,
00053               AST_APP_ARG(varname);
00054               AST_APP_ARG(delim);
00055       );
00056 
00057    AST_STANDARD_APP_ARGS(args, parse);
00058    if (args.delim) {
00059       pbx_retrieve_variable(chan, args.varname, &varval, buf, len, NULL);
00060       if (args.delim[0] == '\\') {
00061          if (args.delim[1] == 'n')
00062             ast_copy_string(args.delim, "\n", 2);
00063          else if (args.delim[1] == 't')
00064             ast_copy_string(args.delim, "\t", 2);
00065          else if (args.delim[1])
00066             ast_copy_string(args.delim, &args.delim[1], 2);
00067          else
00068             ast_copy_string(args.delim, "-", 2);
00069       }
00070       while (strsep(&varval, args.delim))
00071          fieldcount++;
00072    } else {
00073       fieldcount = 1;
00074    }
00075    snprintf(buf, len, "%d", fieldcount);
00076 
00077    return 0;
00078 }

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

Definition at line 606 of file func_strings.c.

References ast_copy_string().

00607 {
00608    int i = 0;
00609 
00610    while (data[i]) {
00611       if (data[i] & 0x80) {
00612          unsigned char c = data[i];
00613          if (c >= 192 && c <= 223) {
00614             c += 32;
00615             data[i] = (char) c;
00616          }
00617       } else {
00618          data[i] = tolower(data[i]);
00619       }
00620       i++;
00621    }
00622    ast_copy_string(buf, data, len);
00623    return 0;
00624 }

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

Definition at line 635 of file func_strings.c.

References ast_copy_string().

00636 {
00637    int i = 0;
00638    while (data[i]) {
00639       if (data[i] & 0x80) {
00640          unsigned char c = data[i];
00641          if (c >= 224) {
00642             c -= 32;
00643             data[i] = (char)c;
00644          }
00645       } else {
00646          data[i] = toupper(data[i]);
00647       }
00648       i++;
00649    }
00650    ast_copy_string(buf, data, len);
00651    return 0;
00652 }

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

Definition at line 559 of file func_strings.c.

00560 {
00561    char *bufptr, *dataptr;
00562 
00563    for (bufptr = buf, dataptr = data; bufptr < buf + len - 1; dataptr++) {
00564       if (*dataptr == '\0') {
00565          *bufptr++ = '\0';
00566          break;
00567       } else if (*dataptr == '1') {
00568          *bufptr++ = '1';
00569       } else if (strchr("AaBbCc2", *dataptr)) {
00570          *bufptr++ = '2';
00571       } else if (strchr("DdEeFf3", *dataptr)) {
00572          *bufptr++ = '3';
00573       } else if (strchr("GgHhIi4", *dataptr)) {
00574          *bufptr++ = '4';
00575       } else if (strchr("JjKkLl5", *dataptr)) {
00576          *bufptr++ = '5';
00577       } else if (strchr("MmNnOo6", *dataptr)) {
00578          *bufptr++ = '6';
00579       } else if (strchr("PpQqRrSs7", *dataptr)) {
00580          *bufptr++ = '7';
00581       } else if (strchr("TtUuVv8", *dataptr)) {
00582          *bufptr++ = '8';
00583       } else if (strchr("WwXxYyZz9", *dataptr)) {
00584          *bufptr++ = '9';
00585       } else if (*dataptr == '*') {
00586          *bufptr++ = '*';
00587       } else if (*dataptr == '#') {
00588          *bufptr++ = '#';
00589       } else if (*dataptr == '0') {
00590          *bufptr++ = '0';
00591       }
00592    }
00593    buf[len - 1] = '\0';
00594 
00595    return 0;
00596 }

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

Definition at line 418 of file func_strings.c.

Referenced by __ast_cli_register(), __get_header(), _parse(), add_sdp(), add_t38_sdp(), aji_act_hook(), alsa_write(), append_interface(), ast_app_group_set_channel(), ast_cdr_appenduserfield(), ast_cli_complete(), ast_codec_get_len(), ast_dsp_digitdetect(), ast_dsp_process(), ast_dsp_silence(), ast_feature_request_and_dial(), 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_ge(), ast_smoother_read(), ast_translate(), ast_udptl_read(), ast_udptl_write(), auth_exec(), authenticate(), build_facility(), build_route(), 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_setoption(), dictate_exec(), dundi_encrypt(), dundi_parse_ies(), dundi_send(), expr2_token_subst(), generic_http_callback(), get_body(), get_sdp(), get_sdp_iterate(), gsm_write(), gsmtolin_framein(), h263_read(), h263_write(), h264_read(), h264_write(), handle_commandmatchesarray(), handle_message(), handle_request(), handle_response(), handle_uri(), help1(), html_translate(), iax_parse_ies(), iax_str2flags(), launch_monitor_thread(), listener(), local_call(), lpc10tolin_framein(), method_match(), mgcp_ss(), mgcpsock_read(), misdn_read(), monitor_main(), monmp3thread(), mwanalyze_exec(), 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(), sip_show_channel(), sip_show_history(), sipsock_read(), skinny_ss(), socket_read(), ss_thread(), static_callback(), term_filter_escapes(), transfer_exec(), udptl_build_packet(), vmwi_generate(), wav_write(), and xml_translate().

00420 {
00421    int length = 0;
00422 
00423    if (data)
00424       length = strlen(data);
00425 
00426    snprintf(buf, len, "%d", length);
00427 
00428    return 0;
00429 }

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 388 of file func_strings.c.

Referenced by ast_app_separate_args().

00389 {
00390    char *bufptr = buf, *dataptr = data;
00391    *bufptr++ = '"';
00392    for (; bufptr < buf + len - 1; dataptr++) {
00393       if (*dataptr == '\\') {
00394          *bufptr++ = '\\';
00395          *bufptr++ = '\\';
00396       } else if (*dataptr == '"') {
00397          *bufptr++ = '\\';
00398          *bufptr++ = '"';
00399       } else if (*dataptr == '\0') {
00400          break;
00401       } else {
00402          *bufptr++ = *dataptr;
00403       }
00404    }
00405    *bufptr++ = '"';
00406    *bufptr = '\0';
00407    return 0;
00408 }

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

Definition at line 119 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.

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

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 706 of file func_strings.c.

Definition at line 219 of file func_strings.c.

const struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 706 of file func_strings.c.

Definition at line 543 of file func_strings.c.

Definition at line 80 of file func_strings.c.

Definition at line 112 of file func_strings.c.

Definition at line 598 of file func_strings.c.

Definition at line 431 of file func_strings.c.

Definition at line 410 of file func_strings.c.

Definition at line 157 of file func_strings.c.

Definition at line 377 of file func_strings.c.

Definition at line 467 of file func_strings.c.

Definition at line 513 of file func_strings.c.

Definition at line 626 of file func_strings.c.

Definition at line 655 of file func_strings.c.


Generated on Fri Jul 3 20:38:24 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.9