35 #include "asterisk/file.h"
92 if (one->
value < two->value)
94 else if (one->
value == two->value)
100 #define ERROR_NOARG (-1)
101 #define ERROR_NOMEM (-2)
102 #define ERROR_USAGE (-3)
106 char *strings, *ptrkey, *ptrvalue;
107 int count=1, count2, element_count=0;
117 for (ptrkey = strings; *ptrkey; ptrkey++) {
122 sortable_keys =
ast_alloca(count *
sizeof(
struct sortable_keys));
124 memset(sortable_keys, 0, count *
sizeof(
struct sortable_keys));
128 while ((ptrkey =
strsep(&strings,
","))) {
129 ptrvalue = strchr(ptrkey,
':');
135 sortable_keys[count2].
key = ptrkey;
136 sscanf(ptrvalue,
"%30f", &sortable_keys[count2].
value);
141 qsort(sortable_keys, count,
sizeof(
struct sortable_keys),
sort_subroutine);
143 for (count2 = 0; count2 < count; count2++) {
144 int blen = strlen(buffer);
145 if (element_count++) {
146 strncat(buffer + blen,
",", buflen - blen - 1);
149 strncat(buffer + blen, sortable_keys[count2].
key, buflen - blen - 1);
157 char *
parse, ds[2], *var_expr;
158 size_t delim_consumed;
177 snprintf(var_expr, strlen(
args.varname) + 4,
"${%s}",
args.varname);
190 int out_field_count = 0;
192 while (curfieldptr != NULL &&
args.field != NULL) {
193 char *next_range =
strsep(&(
args.field),
"&");
194 int start_field, stop_field;
197 if (sscanf(next_range,
"%30d-%30d", &start_field, &stop_field) == 2) {
199 }
else if (sscanf(next_range,
"-%30d", &stop_field) == 1) {
202 }
else if ((sscanf(next_range,
"%30d%1c", &start_field, &trashchar) == 2) && (trashchar ==
'-')) {
204 stop_field = INT_MAX;
205 }
else if (sscanf(next_range,
"%30d", &start_field) == 1) {
207 stop_field = start_field;
215 while (curfieldptr != NULL && curfieldnum < start_field) {
221 if (curfieldnum > start_field) {
226 while (curfieldptr != NULL && curfieldnum <= stop_field) {
227 char *field_value =
strsep(&curfieldptr, ds);
228 ast_str_append(buf, buflen,
"%s%s", out_field_count++ ? ds :
"", field_value);
265 ast_log(
LOG_ERROR,
"Syntax: CUT(<varname>,<char-delim>,<range-spec>) - missing argument!\n");
290 ast_log(
LOG_ERROR,
"Syntax: CUT(<varname>,<char-delim>,<range-spec>) - missing argument!\n");
Main Channel structure associated with a channel.
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Asterisk main include file. File version handling, generic pbx functions.
static int acf_cut_exec(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
char * strsep(char **str, const char *delims)
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
void ast_str_substitute_variables(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ)
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
struct ast_str * ast_str_create(size_t init_len)
Create a malloc'ed dynamic length string.
static struct ast_custom_function acf_sort
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
General Asterisk PBX channel definitions.
Data structure associated with a custom dialplan function.
Core PBX routines and definitions.
#define ast_strdupa(s)
duplicate a string in memory from the stack
static int cut_internal(struct ast_channel *chan, char *data, struct ast_str **buf, ssize_t buflen)
int ast_get_encoded_char(const char *stream, char *result, size_t *consumed)
Decode an encoded control or extended ASCII character.
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
static int load_module(void)
static void parse(struct mgcp_request *req)
static int acf_sort_exec(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
static struct ast_custom_function acf_cut
static int unload_module(void)
#define AST_APP_ARG(name)
Define an application argument.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
static int sort_internal(struct ast_channel *chan, char *data, char *buffer, size_t buflen)
static int acf_cut_exec2(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len)
static int sort_subroutine(const void *arg1, const void *arg2)
#define ast_custom_function_register(acf)
Register a custom function.
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.