#include "asterisk.h"
#include <ctype.h>
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/utils.h"
#include "asterisk/app.h"
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 | __init_result_buf (void) |
static void | __reg_module (void) |
static void | __unreg_module (void) |
static int | acf_sprintf (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
static int | load_module (void) |
static int | unload_module (void) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "SPRINTF dialplan function" , .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 = "8586c2a7d357cb591cc3a6607a8f62d1" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } |
static struct ast_module_info * | ast_module_info = &__mod_info |
static struct ast_threadstorage | result_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_result_buf , .custom_init = NULL , } |
static struct ast_custom_function | sprintf_function |
Anothony Minessale II
Definition in file func_sprintf.c.
#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().
static void __init_result_buf | ( | void | ) | [static] |
static void __reg_module | ( | void | ) | [static] |
Definition at line 230 of file func_sprintf.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 230 of file func_sprintf.c.
static int acf_sprintf | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
Definition at line 63 of file func_sprintf.c.
References AST_APP_ARG, AST_DECLARE_APP_ARGS, AST_STANDARD_APP_ARGS, format, SPRINTF_CONVERSION, SPRINTF_FLAG, SPRINTF_LENGTH, SPRINTF_PRECISION, SPRINTF_WIDTH, and var.
00064 { 00065 #define SPRINTF_FLAG 0 00066 #define SPRINTF_WIDTH 1 00067 #define SPRINTF_PRECISION 2 00068 #define SPRINTF_LENGTH 3 00069 #define SPRINTF_CONVERSION 4 00070 int i, state = -1, argcount = 0; 00071 char *formatstart = NULL, *bufptr = buf; 00072 char formatbuf[256] = ""; 00073 int tmpi; 00074 double tmpd; 00075 AST_DECLARE_APP_ARGS(arg, 00076 AST_APP_ARG(format); 00077 AST_APP_ARG(var)[100]; 00078 ); 00079 00080 AST_STANDARD_APP_ARGS(arg, data); 00081 00082 /* Scan the format, converting each argument into the requisite format type. */ 00083 for (i = 0; arg.format[i]; i++) { 00084 switch (state) { 00085 case SPRINTF_FLAG: 00086 if (strchr("#0- +'I", arg.format[i])) 00087 break; 00088 state = SPRINTF_WIDTH; 00089 case SPRINTF_WIDTH: 00090 if (arg.format[i] >= '0' && arg.format[i] <= '9') 00091 break; 00092 00093 /* Next character must be a period to go into a precision */ 00094 if (arg.format[i] == '.') { 00095 state = SPRINTF_PRECISION; 00096 } else { 00097 state = SPRINTF_LENGTH; 00098 i--; 00099 } 00100 break; 00101 case SPRINTF_PRECISION: 00102 if (arg.format[i] >= '0' && arg.format[i] <= '9') 00103 break; 00104 state = SPRINTF_LENGTH; 00105 case SPRINTF_LENGTH: 00106 if (strchr("hl", arg.format[i])) { 00107 if (arg.format[i + 1] == arg.format[i]) 00108 i++; 00109 state = SPRINTF_CONVERSION; 00110 break; 00111 } else if (strchr("Lqjzt", arg.format[i])) { 00112 state = SPRINTF_CONVERSION; 00113 break; 00114 } 00115 state = SPRINTF_CONVERSION; 00116 case SPRINTF_CONVERSION: 00117 if (strchr("diouxXc", arg.format[i])) { 00118 /* Integer */ 00119 00120 /* Isolate this format alone */ 00121 ast_copy_string(formatbuf, formatstart, sizeof(formatbuf)); 00122 formatbuf[&arg.format[i] - formatstart + 1] = '\0'; 00123 00124 /* Convert the argument into the required type */ 00125 if (arg.var[argcount]) { 00126 if (sscanf(arg.var[argcount++], "%30d", &tmpi) != 1) { 00127 ast_log(LOG_ERROR, "Argument '%s' is not an integer number for format '%s'\n", arg.var[argcount - 1], formatbuf); 00128 goto sprintf_fail; 00129 } 00130 } else { 00131 ast_log(LOG_ERROR, "SPRINTF() has more format specifiers than arguments!\n"); 00132 goto sprintf_fail; 00133 } 00134 00135 /* Format the argument */ 00136 snprintf(bufptr, buf + len - bufptr, formatbuf, tmpi); 00137 00138 /* Update the position of the next parameter to print */ 00139 bufptr = strchr(buf, '\0'); 00140 } else if (strchr("eEfFgGaA", arg.format[i])) { 00141 /* Double */ 00142 00143 /* Isolate this format alone */ 00144 ast_copy_string(formatbuf, formatstart, sizeof(formatbuf)); 00145 formatbuf[&arg.format[i] - formatstart + 1] = '\0'; 00146 00147 /* Convert the argument into the required type */ 00148 if (arg.var[argcount]) { 00149 if (sscanf(arg.var[argcount++], "%30lf", &tmpd) != 1) { 00150 ast_log(LOG_ERROR, "Argument '%s' is not a floating point number for format '%s'\n", arg.var[argcount - 1], formatbuf); 00151 goto sprintf_fail; 00152 } 00153 } else { 00154 ast_log(LOG_ERROR, "SPRINTF() has more format specifiers than arguments!\n"); 00155 goto sprintf_fail; 00156 } 00157 00158 /* Format the argument */ 00159 snprintf(bufptr, buf + len - bufptr, formatbuf, tmpd); 00160 00161 /* Update the position of the next parameter to print */ 00162 bufptr = strchr(buf, '\0'); 00163 } else if (arg.format[i] == 's') { 00164 /* String */ 00165 00166 /* Isolate this format alone */ 00167 ast_copy_string(formatbuf, formatstart, sizeof(formatbuf)); 00168 formatbuf[&arg.format[i] - formatstart + 1] = '\0'; 00169 00170 /* Format the argument */ 00171 snprintf(bufptr, buf + len - bufptr, formatbuf, arg.var[argcount++]); 00172 00173 /* Update the position of the next parameter to print */ 00174 bufptr = strchr(buf, '\0'); 00175 } else if (arg.format[i] == '%') { 00176 /* Literal data to copy */ 00177 *bufptr++ = arg.format[i]; 00178 } else { 00179 /* Not supported */ 00180 00181 /* Isolate this format alone */ 00182 ast_copy_string(formatbuf, formatstart, sizeof(formatbuf)); 00183 formatbuf[&arg.format[i] - formatstart + 1] = '\0'; 00184 00185 ast_log(LOG_ERROR, "Format type not supported: '%s' with argument '%s'\n", formatbuf, arg.var[argcount++]); 00186 goto sprintf_fail; 00187 } 00188 state = -1; 00189 break; 00190 default: 00191 if (arg.format[i] == '%') { 00192 state = SPRINTF_FLAG; 00193 formatstart = &arg.format[i]; 00194 break; 00195 } else { 00196 /* Literal data to copy */ 00197 *bufptr++ = arg.format[i]; 00198 } 00199 } 00200 } 00201 *bufptr = '\0'; 00202 return 0; 00203 sprintf_fail: 00204 return -1; 00205 }
static int load_module | ( | void | ) | [static] |
Definition at line 221 of file func_sprintf.c.
References ast_custom_function_register, and sprintf_function.
00222 { 00223 int res = 0; 00224 00225 res |= ast_custom_function_register(&sprintf_function); 00226 00227 return res; 00228 }
static int unload_module | ( | void | ) | [static] |
Definition at line 212 of file func_sprintf.c.
References ast_custom_function_unregister(), and sprintf_function.
00213 { 00214 int res = 0; 00215 00216 res |= ast_custom_function_unregister(&sprintf_function); 00217 00218 return res; 00219 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "SPRINTF dialplan function" , .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 = "8586c2a7d357cb591cc3a6607a8f62d1" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } [static] |
Definition at line 230 of file func_sprintf.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 230 of file func_sprintf.c.
struct ast_threadstorage result_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_result_buf , .custom_init = NULL , } [static] |
Definition at line 40 of file func_sprintf.c.
Referenced by config_curl(), destroy_curl(), function_fieldnum_helper(), function_fieldqty_helper(), listfilter(), realtime_curl(), realtime_multi_curl(), replace(), require_curl(), shift_pop(), store_curl(), unshift_push(), update2_curl(), and update_curl().
struct ast_custom_function sprintf_function [static] |
Initial value:
{ .name = "SPRINTF", .read = acf_sprintf, }
Definition at line 207 of file func_sprintf.c.
Referenced by load_module(), and unload_module().