From f23c1fcb31d157f2653b05381f425392d703caeb Mon Sep 17 00:00:00 2001 From: tilghman Date: Thu, 15 Dec 2005 19:05:41 +0000 Subject: Properly move these functions over to the funcs directory (since they no longer contain apps) git-svn-id: http://svn.digium.com/svn/asterisk/trunk@7496 f38db490-d61c-443f-a65b-d21fe96a405b --- apps/Makefile | 3 +- apps/app_cut.c | 344 --------------------------------------------------------- 2 files changed, 1 insertion(+), 346 deletions(-) delete mode 100644 apps/app_cut.c (limited to 'apps') diff --git a/apps/Makefile b/apps/Makefile index 841977b29..28ce6d8ef 100644 --- a/apps/Makefile +++ b/apps/Makefile @@ -24,8 +24,7 @@ APPS=app_adsiprog.so app_alarmreceiver.so app_authenticate.so app_cdr.so \ app_setcdruserfield.so app_settransfercapability.so app_softhangup.so \ app_stack.so app_system.so app_talkdetect.so app_test.so app_transfer.so \ app_userevent.so app_url.so app_verbose.so app_voicemail.so \ - app_waitforring.so app_waitforsilence.so app_while.so app_zapateller.so \ - app_cut.so + app_waitforring.so app_waitforsilence.so app_while.so app_zapateller.so # # Obsolete things... diff --git a/apps/app_cut.c b/apps/app_cut.c deleted file mode 100644 index 6922fc313..000000000 --- a/apps/app_cut.c +++ /dev/null @@ -1,344 +0,0 @@ -/* - * Asterisk -- An open source telephony toolkit. - * - * Copyright (c) 2003 Tilghman Lesher. All rights reserved. - * - * Tilghman Lesher - * - * This code is released by the author with no restrictions on usage. - * - * See http://www.asterisk.org for more information about - * the Asterisk project. Please do not directly contact - * any of the maintainers of this project for assistance; - * the project provides a web site, mailing lists and IRC - * channels for your use. - * - */ - -/*! \file - * \brief Cut application - * - * \ingroup applications - */ - -#include -#include -#include -#include - -#include "asterisk.h" - -ASTERISK_FILE_VERSION(__FILE__, "$Revision$") - -#include "asterisk/file.h" -#include "asterisk/logger.h" -#include "asterisk/options.h" -#include "asterisk/channel.h" -#include "asterisk/pbx.h" -#include "asterisk/module.h" -#include "asterisk/app.h" - -/* Maximum length of any variable */ -#define MAXRESULT 1024 - -static char *tdesc = "Cut out information from a string"; - -STANDARD_LOCAL_USER; - -LOCAL_USER_DECL; - -struct sortable_keys { - char *key; - float value; -}; - -static int sort_subroutine(const void *arg1, const void *arg2) -{ - const struct sortable_keys *one=arg1, *two=arg2; - if (one->value < two->value) { - return -1; - } else if (one->value == two->value) { - return 0; - } else { - return 1; - } -} - -#define ERROR_NOARG (-1) -#define ERROR_NOMEM (-2) -#define ERROR_USAGE (-3) - -static int sort_internal(struct ast_channel *chan, char *data, char *buffer, size_t buflen) -{ - char *strings, *ptrkey, *ptrvalue; - int count=1, count2, element_count=0; - struct sortable_keys *sortable_keys; - - memset(buffer, 0, buflen); - - if (!data) { - return ERROR_NOARG; - } - - strings = ast_strdupa((char *)data); - if (!strings) { - return ERROR_NOMEM; - } - - for (ptrkey = strings; *ptrkey; ptrkey++) { - if (*ptrkey == '|') { - count++; - } - } - - sortable_keys = alloca(count * sizeof(struct sortable_keys)); - if (!sortable_keys) { - return ERROR_NOMEM; - } - - memset(sortable_keys, 0, count * sizeof(struct sortable_keys)); - - /* Parse each into a struct */ - count2 = 0; - while ((ptrkey = strsep(&strings, "|"))) { - ptrvalue = index(ptrkey, ':'); - if (!ptrvalue) { - count--; - continue; - } - *ptrvalue = '\0'; - ptrvalue++; - sortable_keys[count2].key = ptrkey; - sscanf(ptrvalue, "%f", &sortable_keys[count2].value); - count2++; - } - - /* Sort the structs */ - qsort(sortable_keys, count, sizeof(struct sortable_keys), sort_subroutine); - - for (count2 = 0; count2 < count; count2++) { - int blen = strlen(buffer); - if (element_count++) { - strncat(buffer + blen, ",", buflen - blen - 1); - } - strncat(buffer + blen + 1, sortable_keys[count2].key, buflen - blen - 2); - } - - return 0; -} - -static int cut_internal(struct ast_channel *chan, char *data, char *buffer, size_t buflen) -{ - char *s, *args[3], *varname=NULL, *delimiter=NULL, *field=NULL; - int args_okay = 0; - - memset(buffer, 0, buflen); - - /* Check and parse arguments */ - if (data) { - s = ast_strdupa((char *)data); - if (s) { - ast_app_separate_args(s, '|', args, 3); - varname = args[0]; - delimiter = args[1]; - field = args[2]; - - if (field) { - args_okay = 1; - } - } else { - return ERROR_NOMEM; - } - } - - if (args_okay) { - char d, ds[2]; - char *tmp = alloca(strlen(varname) + 4); - char varvalue[MAXRESULT], *tmp2=varvalue; - - if (tmp) { - snprintf(tmp, strlen(varname) + 4, "${%s}", varname); - memset(varvalue, 0, sizeof(varvalue)); - } else { - return ERROR_NOMEM; - } - - if (delimiter[0]) - d = delimiter[0]; - else - d = '-'; - - /* String form of the delimiter, for use with strsep(3) */ - snprintf(ds, sizeof(ds), "%c", d); - - pbx_substitute_variables_helper(chan, tmp, tmp2, MAXRESULT - 1); - - if (tmp2) { - int curfieldnum = 1; - while ((tmp2 != NULL) && (field != NULL)) { - char *nextgroup = strsep(&field, "&"); - int num1 = 0, num2 = MAXRESULT; - char trashchar; - - if (sscanf(nextgroup, "%d-%d", &num1, &num2) == 2) { - /* range with both start and end */ - } else if (sscanf(nextgroup, "-%d", &num2) == 1) { - /* range with end */ - num1 = 0; - } else if ((sscanf(nextgroup, "%d%c", &num1, &trashchar) == 2) && (trashchar == '-')) { - /* range with start */ - num2 = MAXRESULT; - } else if (sscanf(nextgroup, "%d", &num1) == 1) { - /* single number */ - num2 = num1; - } else { - return ERROR_USAGE; - } - - /* Get to start, if any */ - if (num1 > 0) { - while ((tmp2 != (char *)NULL + 1) && (curfieldnum < num1)) { - tmp2 = index(tmp2, d) + 1; - curfieldnum++; - } - } - - /* Most frequent problem is the expectation of reordering fields */ - if ((num1 > 0) && (curfieldnum > num1)) { - ast_log(LOG_WARNING, "We're already past the field you wanted?\n"); - } - - /* Re-null tmp2 if we added 1 to NULL */ - if (tmp2 == (char *)NULL + 1) - tmp2 = NULL; - - /* Output fields until we either run out of fields or num2 is reached */ - while ((tmp2 != NULL) && (curfieldnum <= num2)) { - char *tmp3 = strsep(&tmp2, ds); - int curlen = strlen(buffer); - - if (curlen) { - snprintf(buffer + curlen, buflen - curlen, "%c%s", d, tmp3); - } else { - snprintf(buffer, buflen, "%s", tmp3); - } - - curfieldnum++; - } - } - } - } else { - return ERROR_NOARG; - } - return 0; -} - -static char *acf_sort_exec(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) -{ - struct localuser *u; - - LOCAL_USER_ACF_ADD(u); - - switch (sort_internal(chan, data, buf, len)) { - case ERROR_NOARG: - ast_log(LOG_ERROR, "SORT() requires an argument\n"); - break; - case ERROR_NOMEM: - ast_log(LOG_ERROR, "Out of memory\n"); - break; - case 0: - break; - default: - ast_log(LOG_ERROR, "Unknown internal error\n"); - } - LOCAL_USER_REMOVE(u); - return buf; -} - -static char *acf_cut_exec(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) -{ - struct localuser *u; - - LOCAL_USER_ACF_ADD(u); - - switch (cut_internal(chan, data, buf, len)) { - case ERROR_NOARG: - ast_log(LOG_ERROR, "CUT() requires an argument\n"); - break; - case ERROR_NOMEM: - ast_log(LOG_ERROR, "Out of memory\n"); - break; - case ERROR_USAGE: - ast_log(LOG_ERROR, "Usage: %s\n", cut_synopsis); - break; - case 0: - break; - default: - ast_log(LOG_ERROR, "Unknown internal error\n"); - } - LOCAL_USER_REMOVE(u); - return buf; -} - -struct ast_custom_function acf_sort = { - .name = "SORT", - .synopsis = "Sorts a list of key/vals into a list of keys, based upon the vals", - .syntax = "SORT(key1:val1[...][,keyN:valN])", - .desc = -"Takes a comma-separated list of keys and values, each separated by a colon, and returns a\n" -"comma-separated list of the keys, sorted by their values. Values will be evaluated as\n" -"floating-point numbers.\n", - .read = acf_sort_exec, -}; - -struct ast_custom_function acf_cut = { - .name = "CUT", - .synopsis = "Slices and dices strings, based upon a named delimiter.", - .syntax = "CUT(,,)", - .desc = -" varname - variable you want cut\n" -" char-delim - defaults to '-'\n" -" range-spec - number of the field you want (1-based offset)\n" -" may also be specified as a range (with -)\n" -" or group of ranges and fields (with &)\n", - .read = acf_cut_exec, -}; - -int unload_module(void) -{ - int res; - - res = ast_custom_function_unregister(&acf_cut); - res |= ast_custom_function_unregister(&acf_sort); - - STANDARD_HANGUP_LOCALUSERS; - - return res; -} - -int load_module(void) -{ - int res; - - res = ast_custom_function_register(&acf_cut); - res |= ast_custom_function_register(&acf_sort); - - return res; -} - -char *description(void) -{ - return tdesc; -} - -int usecount(void) -{ - int res; - STANDARD_USECOUNT(res); - return res; -} - -char *key() -{ - return ASTERISK_GPL_KEY; -} -- cgit v1.2.3