Mon Mar 31 07:38:02 2008

Asterisk developer's documentation


func_strings.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 2005-2006, Digium, Inc.
00005  * Portions Copyright (C) 2005, Tilghman Lesher.  All rights reserved.
00006  * Portions Copyright (C) 2005, Anthony Minessale II
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*! \file
00020  *
00021  * \brief String manipulation dialplan functions
00022  *
00023  * \author Tilghman Lesher
00024  * \author Anothony Minessale II 
00025  * \ingroup functions
00026  */
00027 
00028 #include "asterisk.h"
00029 
00030 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
00031 
00032 #include <stdlib.h>
00033 #include <stdio.h>
00034 #include <string.h>
00035 #include <sys/types.h>
00036 #include <regex.h>
00037 #include <ctype.h>
00038 
00039 #include "asterisk/module.h"
00040 #include "asterisk/options.h"
00041 #include "asterisk/channel.h"
00042 #include "asterisk/pbx.h"
00043 #include "asterisk/logger.h"
00044 #include "asterisk/utils.h"
00045 #include "asterisk/app.h"
00046 #include "asterisk/localtime.h"
00047 
00048 static int function_fieldqty(struct ast_channel *chan, char *cmd,
00049               char *parse, char *buf, size_t len)
00050 {
00051    char *varsubst, varval[8192] = "", *varval2 = varval;
00052    int fieldcount = 0;
00053    AST_DECLARE_APP_ARGS(args,
00054               AST_APP_ARG(varname);
00055               AST_APP_ARG(delim);
00056       );
00057 
00058    if (chan)
00059       ast_autoservice_start(chan);
00060 
00061    AST_STANDARD_APP_ARGS(args, parse);
00062    if (args.delim) {
00063       pbx_retrieve_variable(chan, args.varname, &varval, buf, len, NULL);
00064       if (args.delim[0] == '\\') {
00065          if (args.delim[1] == 'n')
00066             ast_copy_string(args.delim, "\n", 2);
00067          else if (args.delim[1] == 't')
00068             ast_copy_string(args.delim, "\t", 2);
00069          else if (args.delim[1])
00070             ast_copy_string(args.delim, &args.delim[1], 2);
00071          else
00072             ast_copy_string(args.delim, "-", 2);
00073       }
00074       while (strsep(&varval, args.delim))
00075          fieldcount++;
00076    } else {
00077       fieldcount = 1;
00078    }
00079    snprintf(buf, len, "%d", fieldcount);
00080 
00081    if (chan)
00082       ast_autoservice_stop(chan);
00083 
00084    return 0;
00085 }
00086 
00087 static struct ast_custom_function fieldqty_function = {
00088    .name = "FIELDQTY",
00089    .synopsis = "Count the fields, with an arbitrary delimiter",
00090    .syntax = "FIELDQTY(<varname>|<delim>)",
00091    .read = function_fieldqty,
00092 };
00093 
00094 static int filter(struct ast_channel *chan, char *cmd, char *parse, char *buf,
00095         size_t len)
00096 {
00097    AST_DECLARE_APP_ARGS(args,
00098               AST_APP_ARG(allowed);
00099               AST_APP_ARG(string);
00100    );
00101    char *outbuf = buf;
00102 
00103    AST_STANDARD_APP_ARGS(args, parse);
00104 
00105    if (!args.string) {
00106       ast_log(LOG_ERROR, "Usage: FILTER(<allowed-chars>|<string>)\n");
00107       return -1;
00108    }
00109 
00110    for (; *(args.string) && (buf + len - 1 > outbuf); (args.string)++) {
00111       if (strchr(args.allowed, *(args.string)))
00112          *outbuf++ = *(args.string);
00113    }
00114    *outbuf = '\0';
00115 
00116    return 0;
00117 }
00118 
00119 static struct ast_custom_function filter_function = {
00120    .name = "FILTER",
00121    .synopsis = "Filter the string to include only the allowed characters",
00122    .syntax = "FILTER(<allowed-chars>|<string>)",
00123    .read = filter,
00124 };
00125 
00126 static int regex(struct ast_channel *chan, char *cmd, char *parse, char *buf,
00127        size_t len)
00128 {
00129    AST_DECLARE_APP_ARGS(args,
00130               AST_APP_ARG(null);
00131               AST_APP_ARG(reg);
00132               AST_APP_ARG(str);
00133    );
00134    int errcode;
00135    regex_t regexbuf;
00136 
00137    buf[0] = '\0';
00138 
00139    AST_NONSTANDARD_APP_ARGS(args, parse, '"');
00140 
00141    if (args.argc != 3) {
00142       ast_log(LOG_ERROR, "Unexpected arguments: should have been in the form '\"<regex>\" <string>'\n");
00143       return -1;
00144    }
00145    if ((*args.str == ' ') || (*args.str == '\t'))
00146       args.str++;
00147 
00148    if (option_debug)
00149       ast_log(LOG_DEBUG, "FUNCTION REGEX (%s)(%s)\n", args.reg, args.str);
00150 
00151    if ((errcode = regcomp(&regexbuf, args.reg, REG_EXTENDED | REG_NOSUB))) {
00152       regerror(errcode, &regexbuf, buf, len);
00153       ast_log(LOG_WARNING, "Malformed input %s(%s): %s\n", cmd, parse, buf);
00154       return -1;
00155    }
00156    
00157    strcpy(buf, regexec(&regexbuf, args.str, 0, NULL, 0) ? "0" : "1");
00158 
00159    regfree(&regexbuf);
00160 
00161    return 0;
00162 }
00163 
00164 static struct ast_custom_function regex_function = {
00165    .name = "REGEX",
00166    .synopsis = "Regular Expression",
00167    .desc =  
00168       "Returns 1 if data matches regular expression, or 0 otherwise.\n"
00169       "Please note that the space following the double quotes separating the regex from the data\n"
00170       "is optional and if present, is skipped. If a space is desired at the beginning of the data,\n"
00171            "then put two spaces there; the second will not be skipped.\n",
00172    .syntax = "REGEX(\"<regular expression>\" <data>)",
00173    .read = regex,
00174 };
00175 
00176 static int array(struct ast_channel *chan, char *cmd, char *var,
00177        const char *value)
00178 {
00179    AST_DECLARE_APP_ARGS(arg1,
00180               AST_APP_ARG(var)[100];
00181    );
00182    AST_DECLARE_APP_ARGS(arg2,
00183               AST_APP_ARG(val)[100];
00184    );
00185    char *value2;
00186    int i;
00187 
00188    value2 = ast_strdupa(value);
00189    if (!var || !value2)
00190       return -1;
00191 
00192    if (chan)
00193       ast_autoservice_start(chan);
00194 
00195    /* The functions this will generally be used with are SORT and ODBC_*, which
00196     * both return comma-delimited lists.  However, if somebody uses literal lists,
00197     * their commas will be translated to vertical bars by the load, and I don't
00198     * want them to be surprised by the result.  Hence, we prefer commas as the
00199     * delimiter, but we'll fall back to vertical bars if commas aren't found.
00200     */
00201    if (option_debug)
00202       ast_log(LOG_DEBUG, "array (%s=%s)\n", var, value2);
00203    if (strchr(var, ','))
00204       AST_NONSTANDARD_APP_ARGS(arg1, var, ',');
00205    else
00206       AST_STANDARD_APP_ARGS(arg1, var);
00207 
00208    if (strchr(value2, ','))
00209       AST_NONSTANDARD_APP_ARGS(arg2, value2, ',');
00210    else
00211       AST_STANDARD_APP_ARGS(arg2, value2);
00212 
00213    for (i = 0; i < arg1.argc; i++) {
00214       if (option_debug)
00215          ast_log(LOG_DEBUG, "array set value (%s=%s)\n", arg1.var[i],
00216             arg2.val[i]);
00217       if (i < arg2.argc) {
00218          pbx_builtin_setvar_helper(chan, arg1.var[i], arg2.val[i]);
00219       } else {
00220          /* We could unset the variable, by passing a NULL, but due to
00221           * pushvar semantics, that could create some undesired behavior. */
00222          pbx_builtin_setvar_helper(chan, arg1.var[i], "");
00223       }
00224    }
00225 
00226    if (chan)
00227       ast_autoservice_stop(chan);
00228 
00229    return 0;
00230 }
00231 
00232 static struct ast_custom_function array_function = {
00233    .name = "ARRAY",
00234    .synopsis = "Allows setting multiple variables at once",
00235    .syntax = "ARRAY(var1[|var2[...][|varN]])",
00236    .write = array,
00237    .desc =
00238       "The comma-separated list passed as a value to which the function is set will\n"
00239       "be interpreted as a set of values to which the comma-separated list of\n"
00240       "variable names in the argument should be set.\n"
00241       "Hence, Set(ARRAY(var1|var2)=1\\,2) will set var1 to 1 and var2 to 2\n"
00242       "Note: remember to either backslash your commas in extensions.conf or quote the\n"
00243       "entire argument, since Set can take multiple arguments itself.\n",
00244 };
00245 
00246 static int acf_sprintf(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
00247 {
00248 #define SPRINTF_FLAG 0
00249 #define SPRINTF_WIDTH   1
00250 #define SPRINTF_PRECISION  2
00251 #define SPRINTF_LENGTH  3
00252 #define SPRINTF_CONVERSION 4
00253    int i, state = -1, argcount = 0;
00254    char *formatstart = NULL, *bufptr = buf;
00255    char formatbuf[256] = "";
00256    int tmpi;
00257    double tmpd;
00258    AST_DECLARE_APP_ARGS(arg,
00259             AST_APP_ARG(format);
00260             AST_APP_ARG(var)[100];
00261    );
00262 
00263    AST_STANDARD_APP_ARGS(arg, data);
00264 
00265    /* Scan the format, converting each argument into the requisite format type. */
00266    for (i = 0; arg.format[i]; i++) {
00267       switch (state) {
00268       case SPRINTF_FLAG:
00269          if (strchr("#0- +'I", arg.format[i]))
00270             break;
00271          state = SPRINTF_WIDTH;
00272       case SPRINTF_WIDTH:
00273          if (arg.format[i] >= '0' && arg.format[i] <= '9')
00274             break;
00275 
00276          /* Next character must be a period to go into a precision */
00277          if (arg.format[i] == '.') {
00278             state = SPRINTF_PRECISION;
00279          } else {
00280             state = SPRINTF_LENGTH;
00281             i--;
00282          }
00283          break;
00284       case SPRINTF_PRECISION:
00285          if (arg.format[i] >= '0' && arg.format[i] <= '9')
00286             break;
00287          state = SPRINTF_LENGTH;
00288       case SPRINTF_LENGTH:
00289          if (strchr("hl", arg.format[i])) {
00290             if (arg.format[i + 1] == arg.format[i])
00291                i++;
00292             state = SPRINTF_CONVERSION;
00293             break;
00294          } else if (strchr("Lqjzt", arg.format[i])) {
00295             state = SPRINTF_CONVERSION;
00296             break;
00297          }
00298          state = SPRINTF_CONVERSION;
00299       case SPRINTF_CONVERSION:
00300          if (strchr("diouxXc", arg.format[i])) {
00301             /* Integer */
00302 
00303             /* Isolate this format alone */
00304             ast_copy_string(formatbuf, formatstart, sizeof(formatbuf));
00305             formatbuf[&arg.format[i] - formatstart + 1] = '\0';
00306 
00307             /* Convert the argument into the required type */
00308             if (sscanf(arg.var[argcount++], "%d", &tmpi) != 1) {
00309                ast_log(LOG_ERROR, "Argument '%s' is not an integer number for format '%s'\n", arg.var[argcount - 1], formatbuf);
00310                goto sprintf_fail;
00311             }
00312 
00313             /* Format the argument */
00314             snprintf(bufptr, buf + len - bufptr, formatbuf, tmpi);
00315 
00316             /* Update the position of the next parameter to print */
00317             bufptr = strchr(buf, '\0');
00318          } else if (strchr("eEfFgGaA", arg.format[i])) {
00319             /* Double */
00320 
00321             /* Isolate this format alone */
00322             ast_copy_string(formatbuf, formatstart, sizeof(formatbuf));
00323             formatbuf[&arg.format[i] - formatstart + 1] = '\0';
00324 
00325             /* Convert the argument into the required type */
00326             if (sscanf(arg.var[argcount++], "%lf", &tmpd) != 1) {
00327                ast_log(LOG_ERROR, "Argument '%s' is not a floating point number for format '%s'\n", arg.var[argcount - 1], formatbuf);
00328                goto sprintf_fail;
00329             }
00330 
00331             /* Format the argument */
00332             snprintf(bufptr, buf + len - bufptr, formatbuf, tmpd);
00333 
00334             /* Update the position of the next parameter to print */
00335             bufptr = strchr(buf, '\0');
00336          } else if (arg.format[i] == 's') {
00337             /* String */
00338 
00339             /* Isolate this format alone */
00340             ast_copy_string(formatbuf, formatstart, sizeof(formatbuf));
00341             formatbuf[&arg.format[i] - formatstart + 1] = '\0';
00342 
00343             /* Format the argument */
00344             snprintf(bufptr, buf + len - bufptr, formatbuf, arg.var[argcount++]);
00345 
00346             /* Update the position of the next parameter to print */
00347             bufptr = strchr(buf, '\0');
00348          } else if (arg.format[i] == '%') {
00349             /* Literal data to copy */
00350             *bufptr++ = arg.format[i];
00351          } else {
00352             /* Not supported */
00353 
00354             /* Isolate this format alone */
00355             ast_copy_string(formatbuf, formatstart, sizeof(formatbuf));
00356             formatbuf[&arg.format[i] - formatstart + 1] = '\0';
00357 
00358             ast_log(LOG_ERROR, "Format type not supported: '%s' with argument '%s'\n", formatbuf, arg.var[argcount++]);
00359             goto sprintf_fail;
00360          }
00361          state = -1;
00362          break;
00363       default:
00364          if (arg.format[i] == '%') {
00365             state = SPRINTF_FLAG;
00366             formatstart = &arg.format[i];
00367             break;
00368          } else {
00369             /* Literal data to copy */
00370             *bufptr++ = arg.format[i];
00371          }
00372       }
00373    }
00374    return 0;
00375 sprintf_fail:
00376    return -1;
00377 }
00378 
00379 static struct ast_custom_function sprintf_function = {
00380    .name = "SPRINTF",
00381    .synopsis = "Format a variable according to a format string",
00382    .syntax = "SPRINTF(<format>|<arg1>[|...<argN>])",
00383    .read = acf_sprintf,
00384    .desc =
00385 "Parses the format string specified and returns a string matching that format.\n"
00386 "Supports most options supported by sprintf(3).  Returns a shortened string if\n"
00387 "a format specifier is not recognized.\n",
00388 };
00389 
00390 static int quote(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
00391 {
00392    char *bufptr = buf, *dataptr = data;
00393    *bufptr++ = '"';
00394    for (; bufptr < buf + len - 1; dataptr++) {
00395       if (*dataptr == '\\') {
00396          *bufptr++ = '\\';
00397          *bufptr++ = '\\';
00398       } else if (*dataptr == '"') {
00399          *bufptr++ = '\\';
00400          *bufptr++ = '"';
00401       } else if (*dataptr == '\0') {
00402          break;
00403       } else {
00404          *bufptr++ = *dataptr;
00405       }
00406    }
00407    *bufptr++ = '"';
00408    *bufptr = '\0';
00409    return 0;
00410 }
00411 
00412 static struct ast_custom_function quote_function = {
00413    .name = "QUOTE",
00414    .synopsis = "Quotes a given string, escaping embedded quotes as necessary",
00415    .syntax = "QUOTE(<string>)",
00416    .read = quote,
00417 };
00418 
00419 
00420 static int len(struct ast_channel *chan, char *cmd, char *data, char *buf,
00421           size_t len)
00422 {
00423    int length = 0;
00424 
00425    if (data)
00426       length = strlen(data);
00427 
00428    snprintf(buf, len, "%d", length);
00429 
00430    return 0;
00431 }
00432 
00433 static struct ast_custom_function len_function = {
00434    .name = "LEN",
00435    .synopsis = "Returns the length of the argument given",
00436    .syntax = "LEN(<string>)",
00437    .read = len,
00438 };
00439 
00440 static int acf_strftime(struct ast_channel *chan, char *cmd, char *parse,
00441          char *buf, size_t len)
00442 {
00443    AST_DECLARE_APP_ARGS(args,
00444               AST_APP_ARG(epoch);
00445               AST_APP_ARG(timezone);
00446               AST_APP_ARG(format);
00447    );
00448    time_t epochi;
00449    struct tm tm;
00450 
00451    buf[0] = '\0';
00452 
00453    AST_STANDARD_APP_ARGS(args, parse);
00454 
00455    ast_get_time_t(args.epoch, &epochi, time(NULL), NULL);
00456    ast_localtime(&epochi, &tm, args.timezone);
00457 
00458    if (!args.format)
00459       args.format = "%c";
00460 
00461    if (!strftime(buf, len, args.format, &tm))
00462       ast_log(LOG_WARNING, "C function strftime() output nothing?!!\n");
00463 
00464    buf[len - 1] = '\0';
00465 
00466    return 0;
00467 }
00468 
00469 static struct ast_custom_function strftime_function = {
00470    .name = "STRFTIME",
00471    .synopsis = "Returns the current date/time in a specified format.",
00472    .syntax = "STRFTIME([<epoch>][|[timezone][|format]])",
00473    .read = acf_strftime,
00474 };
00475 
00476 static int acf_strptime(struct ast_channel *chan, char *cmd, char *data,
00477          char *buf, size_t len)
00478 {
00479    AST_DECLARE_APP_ARGS(args,
00480               AST_APP_ARG(timestring);
00481               AST_APP_ARG(timezone);
00482               AST_APP_ARG(format);
00483    );
00484    struct tm time;
00485 
00486    memset(&time, 0, sizeof(struct tm));
00487 
00488    buf[0] = '\0';
00489 
00490    if (!data) {
00491       ast_log(LOG_ERROR,
00492             "Asterisk function STRPTIME() requires an argument.\n");
00493       return -1;
00494    }
00495 
00496    AST_STANDARD_APP_ARGS(args, data);
00497 
00498    if (ast_strlen_zero(args.format)) {
00499       ast_log(LOG_ERROR,
00500             "No format supplied to STRPTIME(<timestring>|<timezone>|<format>)");
00501       return -1;
00502    }
00503 
00504    if (!strptime(args.timestring, args.format, &time)) {
00505       ast_log(LOG_WARNING, "C function strptime() output nothing?!!\n");
00506    } else {
00507       snprintf(buf, len, "%d", (int) ast_mktime(&time, args.timezone));
00508    }
00509 
00510    return 0;
00511 }
00512 
00513 static struct ast_custom_function strptime_function = {
00514    .name = "STRPTIME",
00515    .synopsis =
00516       "Returns the epoch of the arbitrary date/time string structured as described in the format.",
00517    .syntax = "STRPTIME(<datetime>|<timezone>|<format>)",
00518    .desc =
00519       "This is useful for converting a date into an EPOCH time, possibly to pass to\n"
00520       "an application like SayUnixTime or to calculate the difference between two\n"
00521       "date strings.\n"
00522       "\n"
00523       "Example:\n"
00524       "  ${STRPTIME(2006-03-01 07:30:35|America/Chicago|%Y-%m-%d %H:%M:%S)} returns 1141219835\n",
00525    .read = acf_strptime,
00526 };
00527 
00528 static int function_eval(struct ast_channel *chan, char *cmd, char *data,
00529           char *buf, size_t len)
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    if (chan)
00539       ast_autoservice_start(chan);
00540    pbx_substitute_variables_helper(chan, data, buf, len - 1);
00541    if (chan)
00542       ast_autoservice_stop(chan);
00543 
00544    return 0;
00545 }
00546 
00547 static struct ast_custom_function eval_function = {
00548    .name = "EVAL",
00549    .synopsis = "Evaluate stored variables.",
00550    .syntax = "EVAL(<variable>)",
00551    .desc = "Using EVAL basically causes a string to be evaluated twice.\n"
00552       "When a variable or expression is in the dialplan, it will be\n"
00553       "evaluated at runtime. However, if the result of the evaluation\n"
00554       "is in fact a variable or expression, using EVAL will have it\n"
00555       "evaluated a second time. For example, if the variable ${MYVAR}\n"
00556       "contains \"${OTHERVAR}\", then the result of putting ${EVAL(${MYVAR})}\n"
00557       "in the dialplan will be the contents of the variable, OTHERVAR.\n"
00558       "Normally, by just putting ${MYVAR} in the dialplan, you would be\n"
00559       "left with \"${OTHERVAR}\".\n",
00560    .read = function_eval,
00561 };
00562 
00563 static int keypadhash(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
00564 {
00565    char *bufptr, *dataptr;
00566 
00567    for (bufptr = buf, dataptr = data; bufptr < buf + len - 1; dataptr++) {
00568       if (*dataptr == '1') {
00569          *bufptr++ = '1';
00570       } else if (strchr("AaBbCc2", *dataptr)) {
00571          *bufptr++ = '2';
00572       } else if (strchr("DdEeFf3", *dataptr)) {
00573          *bufptr++ = '3';
00574       } else if (strchr("GgHhIi4", *dataptr)) {
00575          *bufptr++ = '4';
00576       } else if (strchr("JjKkLl5", *dataptr)) {
00577          *bufptr++ = '5';
00578       } else if (strchr("MmNnOo6", *dataptr)) {
00579          *bufptr++ = '6';
00580       } else if (strchr("PpQqRrSs7", *dataptr)) {
00581          *bufptr++ = '7';
00582       } else if (strchr("TtUuVv8", *dataptr)) {
00583          *bufptr++ = '8';
00584       } else if (strchr("WwXxYyZz9", *dataptr)) {
00585          *bufptr++ = '9';
00586       } else if (*dataptr == '*') {
00587          *bufptr++ = '*';
00588       } else if (*dataptr == '#') {
00589          *bufptr++ = '#';
00590       } else if (*dataptr == '0') {
00591          *bufptr++ = '0';
00592       } else if (*dataptr == '\0') {
00593          *bufptr++ = '\0';
00594          break;
00595       }
00596    }
00597    buf[len - 1] = '\0';
00598 
00599    return 0;
00600 }
00601 
00602 static struct ast_custom_function keypadhash_function = {
00603    .name = "KEYPADHASH",
00604    .synopsis = "Hash the letters in the string into the equivalent keypad numbers.",
00605    .syntax = "KEYPADHASH(<string>)",
00606    .read = keypadhash,
00607    .desc = "Example:  ${KEYPADHASH(Les)} returns \"537\"\n",
00608 };
00609 
00610 static int function_tolower(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
00611 {
00612    int i = 0;
00613 
00614    while (data[i]) {
00615       if (data[i] & 0x80) {
00616          unsigned char c = data[i];
00617          if (c >= 192 && c <= 223) {
00618             c += 32;
00619             data[i] = (char) c;
00620          }
00621       } else {
00622          data[i] = tolower(data[i]);
00623       }
00624       i++;
00625    }
00626    ast_copy_string(buf, data, len);
00627    return 0;
00628 }
00629 
00630 static struct ast_custom_function tolower_function = {
00631    .name = "TOLOWER",
00632    .synopsis = "Returns the string in lowercase",
00633    .syntax = "TOLOWER(<string>)",
00634    .desc = "Using TOLOWER convert all ASCII characters from A to Z\n"
00635       "to lowercase a to z.\n",
00636    .read = function_tolower,
00637 };
00638 
00639 static int function_toupper(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
00640 {
00641    int i = 0;
00642    while (data[i]) {
00643       if (data[i] & 0x80) {
00644          unsigned char c = data[i];
00645          if (c >= 224) {
00646             c -= 32;
00647             data[i] = (char)c;
00648          }
00649       } else {
00650          data[i] = toupper(data[i]);
00651       }
00652       i++;
00653    }
00654    ast_copy_string(buf, data, len);
00655    return 0;
00656 }
00657 
00658 
00659 static struct ast_custom_function toupper_function = {
00660    .name = "TOUPPER",
00661    .synopsis = "Returns the string in uppercase",
00662    .syntax = "TOUPPER(<string>)",
00663    .desc = "Using TOUPPER convert all ASCII characters from a to z\n"
00664          "to uppercase A to Z.\n",
00665    .read = function_toupper,
00666 };
00667 
00668 static int unload_module(void)
00669 {
00670    int res = 0;
00671 
00672    res |= ast_custom_function_unregister(&fieldqty_function);
00673    res |= ast_custom_function_unregister(&filter_function);
00674    res |= ast_custom_function_unregister(&regex_function);
00675    res |= ast_custom_function_unregister(&array_function);
00676    res |= ast_custom_function_unregister(&quote_function);
00677    res |= ast_custom_function_unregister(&len_function);
00678    res |= ast_custom_function_unregister(&strftime_function);
00679    res |= ast_custom_function_unregister(&strptime_function);
00680    res |= ast_custom_function_unregister(&eval_function);
00681    res |= ast_custom_function_unregister(&keypadhash_function);
00682    res |= ast_custom_function_unregister(&tolower_function);
00683    res |= ast_custom_function_unregister(&toupper_function);
00684    res |= ast_custom_function_unregister(&sprintf_function);
00685 
00686    return res;
00687 }
00688 
00689 static int load_module(void)
00690 {
00691    int res = 0;
00692 
00693    res |= ast_custom_function_register(&fieldqty_function);
00694    res |= ast_custom_function_register(&filter_function);
00695    res |= ast_custom_function_register(&regex_function);
00696    res |= ast_custom_function_register(&array_function);
00697    res |= ast_custom_function_register(&quote_function);
00698    res |= ast_custom_function_register(&len_function);
00699    res |= ast_custom_function_register(&strftime_function);
00700    res |= ast_custom_function_register(&strptime_function);
00701    res |= ast_custom_function_register(&eval_function);
00702    res |= ast_custom_function_register(&keypadhash_function);
00703         res |= ast_custom_function_register(&tolower_function);
00704         res |= ast_custom_function_register(&toupper_function);
00705    res |= ast_custom_function_register(&sprintf_function);
00706 
00707    return res;
00708 }
00709 
00710 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "String handling dialplan functions");

Generated on Mon Mar 31 07:38:02 2008 for Asterisk - the Open Source PBX by  doxygen 1.5.1