23 #define ASTMM_LIBC ASTMM_IGNORE
28 #define AST_API_MODULE 1
31 #define AST_API_MODULE 1
41 #ifdef DEBUG_THREADLOCALS
42 #define MALLOC_FAILURE_MSG \
43 ast_log(LOG_ERROR, "Memory Allocation Failure in function %s at line %d of %s\n", func, lineno, file);
45 void * attribute_malloc __ast_calloc(
size_t num,
size_t len,
const char *file,
int lineno,
const char *func);
47 void * attribute_malloc __ast_calloc(
size_t num,
size_t len,
const char *file,
int lineno,
const char *func)
51 if (!(p = calloc(num, len)))
59 void ast_store_lock_info(
enum ast_lock_type type,
const char *filename,
60 int line_num,
const char *func,
const char *lock_name,
void *lock_addr,
struct ast_bt *bt);
61 void ast_store_lock_info(
enum ast_lock_type type,
const char *filename,
62 int line_num,
const char *func,
const char *lock_name,
void *lock_addr,
struct ast_bt *bt)
67 void ast_remove_lock_info(
void *lock_addr,
struct ast_bt *bt);
68 void ast_remove_lock_info(
void *lock_addr,
struct ast_bt *bt)
74 int __ast_bt_get_addresses(
struct ast_bt *bt);
75 int __ast_bt_get_addresses(
struct ast_bt *bt)
80 struct ast_vector_string *__ast_bt_get_symbols(
void **addresses,
size_t num_frames);
81 struct ast_vector_string *__ast_bt_get_symbols(
void **addresses,
size_t num_frames)
87 void ast_suspend_lock_info(
void *lock_addr)
90 void ast_restore_lock_info(
void *lock_addr)
93 void ast_mark_lock_acquired(
void *);
94 void ast_mark_lock_acquired(
void *foo)
101 static int global_lineno = 1;
102 static int global_expr_count=0;
103 static int global_expr_max_size=0;
104 static int global_expr_tot_size=0;
105 static int global_warn_count=0;
106 static int global_OK_count=0;
115 struct varz *global_varlist;
119 void ast_log(
int level,
const char *file,
int line,
const char *
function,
const char *fmt, ...) __attribute__((format(printf,5,6)));
121 void ast_log(
int level, const
char *file,
int line, const
char *function, const
char *fmt, ...)
126 printf(
"LOG: lev:%d file:%s line:%d func: %s ",
127 level, file, line,
function);
133 char *find_var(
const char *varname);
134 void set_var(
const char *varname,
const char *varval);
135 unsigned int check_expr(
char* buffer,
char* error_report);
136 int check_eval(
char *buffer,
char *error_report);
137 void parse_file(
const char *fname);
141 char *find_var(
const char *varname)
144 for (t= global_varlist; t; t = t->next) {
145 if (!strcmp(t->varname, varname)) {
152 void set_var(
const char *varname,
const char *varval);
154 void set_var(
const char *varname,
const char *varval)
156 struct varz *t = (
struct varz*)calloc(1,
sizeof(
struct varz));
159 strcpy(t->varname, varname);
160 strcpy(t->varval, varval);
161 t->next = global_varlist;
165 unsigned int check_expr(
char* buffer,
char* error_report)
168 unsigned int warn_found = 0;
172 for (cp = buffer; *cp; ++cp)
178 while (*(++cp) && *cp !=
'"') ;
183 "Trouble? Unterminated double quote found at line %d\n",
191 if ( (*(cp + 1) ==
'=')
192 && ( ( (cp > buffer) && (*(cp - 1) !=
' ') ) || (*(cp + 2) !=
' ') ) )
197 "WARNING: line %d: '%c%c' operator not separated by spaces. This may lead to confusion. You may wish to use double quotes to quote the grouping it is in. Please check!\n",
198 global_lineno, *cp, *(cp + 1));
199 strcat(error_report, msg);
215 if ( ( (cp > buffer) && (*(cp - 1) !=
' ') ) || (*(cp + 1) !=
' ') )
220 "WARNING: line %d: '%c' operator not separated by spaces. This may lead to confusion. You may wish to use double quotes to quote the grouping it is in. Please check!\n",
221 global_lineno, *cp );
222 strcat(error_report, msg);
233 int check_eval(
char *buffer,
char *error_report);
242 int check_eval(
char *buffer,
char *error_report)
252 for (cp=buffer;*cp;cp++) {
253 if (*cp ==
'$' && *(cp+1) ==
'{') {
271 strncpy(varname,cp+2, xp-cp-2);
272 varname[xp-cp-2] = 0;
274 val = find_var(varname);
287 printf(
"Unterminated variable reference at line %d\n", global_lineno);
291 else if (*cp ==
'\\') {
302 result =
ast_expr(evalbuf, s,
sizeof(s),NULL);
304 sprintf(error_report,
"line %d, evaluation of $[ %s ] result: %s\n", global_lineno, evalbuf, s);
307 sprintf(error_report,
"line %d, evaluation of $[ %s ] result: ****SYNTAX ERROR****\n", global_lineno, evalbuf);
313 void parse_file(
const char *fname);
315 void parse_file(
const char *fname)
317 FILE *f = fopen(fname,
"r");
318 FILE *l = fopen(
"expr2_log",
"w");
324 fprintf(stderr,
"Couldn't open %s for reading... need an extensions.conf file to parse!\n",fname);
328 fprintf(stderr,
"Couldn't open 'expr2_log' file for writing... please fix and re-run!\n");
334 while ((c1 = fgetc(f)) != EOF) {
337 else if (c1 ==
'[') {
338 if (last_char ==
'$') {
343 char error_report[30000];
345 while ((c1 = fgetc(f)) != EOF) {
351 fprintf(l,
"ERROR-- A newline in an expression? Weird! ...at line %d\n", global_lineno);
354 printf(
"--- ERROR --- A newline in the middle of an expression at line %d!\n", global_lineno);
359 buffer[bufcount++] = c1;
362 fprintf(l,
"ERROR-- End of File Reached in the middle of an Expr at line %d\n", global_lineno);
365 printf(
"--- ERROR --- EOF reached in middle of an expression at line %d!\n", global_lineno);
369 buffer[bufcount] = 0;
371 global_expr_tot_size += bufcount;
373 if (bufcount > global_expr_max_size)
374 global_expr_max_size = bufcount;
376 retval = check_expr(buffer, error_report);
379 printf(
"Warning(s) at line %d, expression: $[%s]; see expr2_log file for details\n",
380 global_lineno, buffer);
381 fprintf(l,
"%s", error_report);
384 printf(
"OK -- $[%s] at line %d\n", buffer, global_lineno);
388 retval = check_eval(buffer, error_report);
389 fprintf(l,
"%s", error_report);
394 printf(
"Summary:\n Expressions detected: %d\n Expressions OK: %d\n Total # Warnings: %d\n Longest Expr: %d chars\n Ave expr len: %d chars\n",
398 global_expr_max_size,
399 (global_expr_count) ? global_expr_tot_size/global_expr_count : 0);
406 int main(
int argc,
char **argv)
412 printf(
"check_expr -- a program to look thru extensions.conf files for $[...] expressions,\n");
413 printf(
" and run them thru the parser, looking for problems\n");
414 printf(
"Hey-- give me a path to an extensions.conf file!\n");
415 printf(
" You can also follow the file path with a series of variable decls,\n");
416 printf(
" of the form, varname=value, each separated from the next by spaces.\n");
417 printf(
" (this might allow you to avoid division by zero messages, check that math\n");
418 printf(
" is being done correctly, etc.)\n");
419 printf(
" Note that messages about operators not being surrounded by spaces is merely to alert\n");
420 printf(
" you to possible problems where you might be expecting those operators as part of a string.\n");
421 printf(
" (to include operators in a string, wrap with double quotes!)\n");
426 for (argc1=2;argc1 < argc; argc1++) {
427 if ((eq = strchr(argv[argc1],
'='))) {
429 set_var(argv[argc1],eq+1);
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
A structure to hold backtrace information. This structure provides an easy means to store backtrace i...
Inlinable API function macro.
Data structure associated with a custom dialplan function.
int ast_add_profile(const char *, uint64_t scale)
support for event profiling
String vector definitions.
int main(int argc, char *argv[])
int ast_expr(char *expr, char *buf, int length, struct ast_channel *chan)
Evaluate the given expression.