2 * XXX this file probably need a fair amount of cleanup, at the very least:
4 * - documenting its purpose;
5 * - removing all unnecessary headers and other stuff from the sources
7 * - fixing the formatting
11 <support_level>extended</support_level>
21 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
23 #include "asterisk/channel.h"
24 #include "asterisk/ast_expr.h"
25 #include "asterisk/module.h"
26 #include "asterisk/app.h"
27 #include "asterisk/lock.h"
28 #include "asterisk/hashtab.h"
29 #include "asterisk/ael_structs.h"
30 #include "asterisk/extconf.h"
33 int option_verbose = 0;
34 #if !defined(LOW_MEMORY)
35 void ast_register_file_version(const char *file, const char *version) { }
36 void ast_unregister_file_version(const char *file) { }
39 struct ast_flags ast_compat = { 7 };
42 <depend>res_ael_share</depend>
49 struct namelist *next;
57 struct namelist *includes;
58 struct namelist *ignorepats;
59 struct namelist *switches;
60 struct namelist *eswitches;
62 struct namelist *includes_last;
63 struct namelist *ignorepats_last;
64 struct namelist *switches_last;
65 struct namelist *eswitches_last;
67 struct ast_context *next;
70 #define ADD_LAST(headptr,memptr) if(!headptr){ headptr=(memptr); (headptr##_last)=(memptr);} else {(headptr##_last)->next = (memptr); (headptr##_last) = (memptr);}
72 void destroy_namelist(struct namelist *x);
73 void destroy_namelist(struct namelist *x)
75 struct namelist *z,*z2;
84 struct namelist *create_name(const char *name);
85 struct namelist *create_name(const char *name)
87 struct namelist *x = calloc(1, sizeof(*x));
90 strncpy(x->name, name, sizeof(x->name) - 1);
94 struct ast_context *context_list;
95 struct ast_context *last_context;
96 struct namelist *globalvars;
97 struct namelist *globalvars_last;
99 int conts=0, extens=0, priors=0;
100 char last_exten[18000];
102 static char config_dir[PATH_MAX];
103 static char var_dir[PATH_MAX];
104 const char *ast_config_AST_CONFIG_DIR = config_dir;
105 const char *ast_config_AST_VAR_DIR = var_dir;
107 void ast_cli_register_multiple(void);
108 int ast_add_extension2(struct ast_context *con,
109 int replace, const char *extension, int priority, const char *label, const char *callerid,
110 const char *application, void *data, void (*datad)(void *),
111 const char *registrar);
112 void pbx_builtin_setvar(void *chan, void *data);
113 struct ast_context * ast_context_create(void **extcontexts, const char *name, const char *registrar);
114 struct ast_context * ast_context_find_or_create(void **extcontexts, void *tab, const char *name, const char *registrar);
115 void ast_context_add_ignorepat2(struct ast_context *con, const char *value, const char *registrar);
116 void ast_context_add_include2(struct ast_context *con, const char *value, const char *registrar);
117 void ast_context_add_switch2(struct ast_context *con, const char *value, const char *data, int eval, const char *registrar);
118 void ast_merge_contexts_and_delete(void);
119 void ast_context_verify_includes(void);
120 struct ast_context * ast_walk_contexts(void);
121 void ast_cli_unregister_multiple(void);
122 void ast_context_destroy(void);
123 void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...);
124 char *ast_process_quotes_and_slashes(char *start, char find, char replace_with);
125 void __ast_verbose(const char *file, int line, const char *func, int level, const char *fmt, ...);
126 struct ast_app *pbx_findapp(const char *app);
127 void filter_leading_space_from_exprs(char *str);
128 void filter_newlines(char *str);
129 static int quiet = 0;
130 static int no_comp = 0;
131 static int use_curr_dir = 0;
132 static int dump_extensions = 0;
133 static int FIRST_TIME = 0;
134 static FILE *dumpfile;
136 void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
141 printf("LOG: lev:%d file:%s line:%d func: %s ",
142 level, file, line, function);
148 struct ast_exten *pbx_find_extension(struct ast_channel *chan,
149 struct ast_context *bypass,
150 struct pbx_find_info *q,
155 const char *callerid,
156 enum ext_match_t action);
158 struct ast_exten *pbx_find_extension(struct ast_channel *chan,
159 struct ast_context *bypass,
160 struct pbx_find_info *q,
165 const char *callerid,
166 enum ext_match_t action)
168 return localized_find_extension(bypass, q, context, exten, priority, label, callerid, action);
171 struct ast_app *pbx_findapp(const char *app)
173 return (struct ast_app*)1; /* so as not to trigger an error */
176 struct ast_custom_function *ast_custom_function_find(const char *name);
179 struct ast_custom_function *ast_custom_function_find(const char *name)
181 return 0; /* in "standalone" mode, functions are just not avail */
184 #if !defined(LOW_MEMORY)
185 int ast_add_profile(const char *x, uint64_t scale)
188 printf("Executed ast_add_profile();\n");
194 int ast_loader_register(int (*updater)(void))
199 int ast_loader_unregister(int (*updater)(void))
203 void ast_module_register(const struct ast_module_info *x)
207 void ast_module_unregister(const struct ast_module_info *x)
212 void ast_cli_register_multiple(void)
215 printf("Executed ast_cli_register_multiple();\n");
218 void pbx_substitute_variables_helper(struct ast_channel *c,const char *cp1,char *cp2,int count);
219 void pbx_substitute_variables_helper(struct ast_channel *c,const char *cp1,char *cp2,int count)
222 strncpy(cp2,cp1,AST_MAX_EXTENSION); /* Right now, this routine is ONLY being called for
223 a possible var substitution on extension names,
229 int ast_add_extension2(struct ast_context *con,
230 int replace, const char *extension, int priority, const char *label, const char *callerid,
231 const char *application, void *data, void (*datad)(void *),
232 const char *registrar)
235 con->extension_count++;
236 if (strcmp(extension,last_exten) != 0) {
238 strcpy(last_exten, extension);
247 application = "(null)";
251 printf("Executed ast_add_extension2(context=%s, rep=%d, exten=%s, priority=%d, label=%s, callerid=%s, appl=%s, data=%s, FREE, registrar=%s);\n",
252 con->name, replace, extension, priority, label, callerid, application, (data?(char*)data:"(null)"), registrar);
254 if( dump_extensions && dumpfile ) {
261 fprintf(dumpfile,"[globals]\n");
263 for(n=globalvars;n;n=n->next) {
264 fprintf(dumpfile, "%s\n", n->name);
268 /* print out each extension , possibly the context header also */
269 if( con != last_context ) {
270 fprintf(dumpfile,"\n\n[%s]\n", con->name);
272 for(n=con->ignorepats;n;n=n->next) {
273 fprintf(dumpfile, "ignorepat => %s\n", n->name);
275 for(n=con->includes;n;n=n->next) {
276 fprintf(dumpfile, "include => %s\n", n->name);
278 for(n=con->switches;n;n=n->next) {
279 fprintf(dumpfile, "switch => %s/%s\n", n->name, n->name2);
281 for(n=con->eswitches;n;n=n->next) {
282 fprintf(dumpfile, "eswitch => %s/%s\n", n->name, n->name2);
287 filter_newlines((char*)data);
288 filter_leading_space_from_exprs((char*)data);
289 /* in previous versions, commas were converted to '|' to separate
290 args in app calls, but now, commas are used. There used to be
291 code here to insert backslashes (escapes) before any commas
292 that may have been embedded in the app args. This code is no more. */
294 if( strcmp(label,"(null)") != 0 )
295 fprintf(dumpfile,"exten => %s,%d(%s),%s(%s)\n", extension, priority, label, application, (char*)data);
297 fprintf(dumpfile,"exten => %s,%d,%s(%s)\n", extension, priority, application, (char*)data);
301 if( strcmp(label,"(null)") != 0 )
302 fprintf(dumpfile,"exten => %s,%d(%s),%s\n", extension, priority, label, application);
304 fprintf(dumpfile,"exten => %s,%d,%s\n", extension, priority, application);
308 /* since add_extension2 is responsible for the malloc'd data stuff */
313 void pbx_builtin_setvar(void *chan, void *data)
315 struct namelist *x = create_name(data);
317 printf("Executed pbx_builtin_setvar(chan, data=%s);\n", (char*)data);
319 if( dump_extensions ) {
320 x = create_name(data);
321 ADD_LAST(globalvars,x);
326 struct ast_context * ast_context_create(void **extcontexts, const char *name, const char *registrar)
328 struct ast_context *x = calloc(1, sizeof(*x));
331 x->next = context_list;
334 printf("Executed ast_context_create(conts, name=%s, registrar=%s);\n", name, registrar);
336 strncpy(x->name, name, sizeof(x->name) - 1);
337 strncpy(x->registrar, registrar, sizeof(x->registrar) - 1);
341 struct ast_context * ast_context_find_or_create(void **extcontexts, void *tab, const char *name, const char *registrar)
343 struct ast_context *x = calloc(1, sizeof(*x));
346 x->next = context_list;
349 printf("Executed ast_context_find_or_create(conts, name=%s, registrar=%s);\n", name, registrar);
351 strncpy(x->name, name, sizeof(x->name) - 1);
352 strncpy(x->registrar, registrar, sizeof(x->registrar) - 1);
356 void ast_context_add_ignorepat2(struct ast_context *con, const char *value, const char *registrar)
359 printf("Executed ast_context_add_ignorepat2(con, value=%s, registrar=%s);\n", value, registrar);
360 if( dump_extensions ) {
362 x = create_name(value);
363 ADD_LAST(con->ignorepats,x);
367 void ast_context_add_include2(struct ast_context *con, const char *value, const char *registrar)
370 printf("Executed ast_context_add_include2(con, value=%s, registrar=%s);\n", value, registrar);
371 if( dump_extensions ) {
373 x = create_name((char*)value);
374 ADD_LAST(con->includes,x);
378 void ast_context_add_switch2(struct ast_context *con, const char *value, const char *data, int eval, const char *registrar)
381 printf("Executed ast_context_add_switch2(con, value=%s, data=%s, eval=%d, registrar=%s);\n", value, data, eval, registrar);
382 if( dump_extensions ) {
384 x = create_name((char*)value);
385 strncpy(x->name2,data,100);
388 ADD_LAST(con->switches,x);
392 ADD_LAST(con->eswitches,x);
397 void ast_merge_contexts_and_delete(void)
400 printf("Executed ast_merge_contexts_and_delete();\n");
403 void ast_context_verify_includes(void)
406 printf("Executed ast_context_verify_includes();\n");
409 struct ast_context * ast_walk_contexts(void)
412 printf("Executed ast_walk_contexts();\n");
416 void ast_cli_unregister_multiple(void)
419 printf("Executed ast_cli_unregister_multiple();\n");
422 void ast_context_destroy(void)
425 printf("Executed ast_context_destroy();\n");
428 const char *ast_get_context_name(struct ast_context *con);
429 const char *ast_get_context_name(struct ast_context *con)
431 return con ? con->name : NULL;
434 struct ast_exten *ast_walk_context_extensions(struct ast_context *con, struct ast_exten *exten);
435 struct ast_exten *ast_walk_context_extensions(struct ast_context *con, struct ast_exten *exten)
440 struct ast_include *ast_walk_context_includes(struct ast_context *con, struct ast_include *inc);
441 struct ast_include *ast_walk_context_includes(struct ast_context *con, struct ast_include *inc)
446 struct ast_ignorepat *ast_walk_context_ignorepats(struct ast_context *con, struct ast_ignorepat *ip);
447 struct ast_ignorepat *ast_walk_context_ignorepats(struct ast_context *con, struct ast_ignorepat *ip)
452 struct ast_sw *ast_walk_context_switches(struct ast_context *con, struct ast_sw *sw);
453 struct ast_sw *ast_walk_context_switches(struct ast_context *con, struct ast_sw *sw)
458 void filter_leading_space_from_exprs(char *str)
460 /* Mainly for aesthetics */
461 char *t, *v, *u = str;
465 if( *u == '$' && *(u+1) == '[' ) {
467 while( *t == '\n' || *t == '\r' || *t == '\t' || *t == ' ' ) {
480 void filter_newlines(char *str)
482 /* remove all newlines, returns */
485 if( *t == '\n' || *t == '\r' ) {
486 *t = ' '; /* just replace newlines and returns with spaces; they act as
487 token separators, and just blindly removing them could be
495 extern struct module_symbols mod_data;
496 int ael_external_load_module(void);
499 int main(int argc, char **argv)
503 struct ast_context *lp,*lp2;
505 for(i=1;i<argc;i++) {
506 if( argv[i][0] == '-' && argv[i][1] == 'n' )
508 if( argv[i][0] == '-' && argv[i][1] == 'q' ) {
512 if( argv[i][0] == '-' && argv[i][1] == 'd' )
514 if( argv[i][0] == '-' && argv[i][1] == 'w' )
519 printf("\n(If you find progress and other non-error messages irritating, you can use -q to suppress them)\n");
521 printf("\n(You can use the -n option if you aren't interested in seeing all the instructions generated by the compiler)\n\n");
523 printf("\n(You can use the -d option if you want to use the current working directory as the CONFIG_DIR. I will look in this dir for extensions.ael* and its included files)\n\n");
524 if( !dump_extensions )
525 printf("\n(You can use the -w option to dump extensions.conf format to extensions.conf.aeldump)\n");
529 strcpy(config_dir, ".");
530 localized_use_local_dir();
533 strcpy(config_dir, "/etc/asterisk");
534 localized_use_conf_dir();
536 strcpy(var_dir, "/var/lib/asterisk");
538 if( dump_extensions ) {
539 dumpfile = fopen("extensions.conf.aeldump","w");
541 printf("\n\nSorry, cannot open extensions.conf.aeldump for writing! Correct the situation and try again!\n\n");
549 ael_external_load_module();
551 ast_log(4, "ael2_parse", __LINE__, "main", "%d contexts, %d extensions, %d priorities\n", conts, extens, priors);
553 if( dump_extensions && dumpfile ) {
555 for( lp = context_list; lp; lp = lp->next ) { /* print out any contexts that didn't have any
556 extensions in them */
557 if( lp->extension_count == 0 ) {
559 fprintf(dumpfile,"\n\n[%s]\n", lp->name);
561 for(n=lp->ignorepats;n;n=n->next) {
562 fprintf(dumpfile, "ignorepat => %s\n", n->name);
564 for(n=lp->includes;n;n=n->next) {
565 fprintf(dumpfile, "include => %s\n", n->name);
567 for(n=lp->switches;n;n=n->next) {
568 fprintf(dumpfile, "switch => %s/%s\n", n->name, n->name2);
570 for(n=lp->eswitches;n;n=n->next) {
571 fprintf(dumpfile, "eswitch => %s/%s\n", n->name, n->name2);
577 if( dump_extensions && dumpfile )
580 for( lp = context_list; lp; lp = lp2 ) { /* free the ast_context structs */
584 destroy_namelist(lp->includes);
585 destroy_namelist(lp->ignorepats);
586 destroy_namelist(lp->switches);
587 destroy_namelist(lp->eswitches);
595 int ast_hashtab_compare_contexts(const void *ah_a, const void *ah_b);
597 int ast_hashtab_compare_contexts(const void *ah_a, const void *ah_b)
602 unsigned int ast_hashtab_hash_contexts(const void *obj);
604 unsigned int ast_hashtab_hash_contexts(const void *obj)
610 #if !defined(LOW_MEMORY)
611 void ast_mark_lock_acquired(void *lock_addr)
615 void ast_remove_lock_info(void *lock_addr, struct ast_bt *bt)
619 void ast_store_lock_info(enum ast_lock_type type, const char *filename,
620 int line_num, const char *func, const char *lock_name, void *lock_addr, struct ast_bt *bt)
624 int ast_bt_get_addresses(struct ast_bt *bt)
629 char **ast_bt_get_symbols(void **addresses, size_t num_frames)
631 char **foo = calloc(num_frames, sizeof(char *) + 1);
634 for (i = 0; i < num_frames; i++) {
635 foo[i] = (char *) foo + sizeof(char *) * num_frames;
641 void ast_remove_lock_info(void *lock_addr)
645 void ast_store_lock_info(enum ast_lock_type type, const char *filename,
646 int line_num, const char *func, const char *lock_name, void *lock_addr)
649 #endif /* HAVE_BKTR */
650 #endif /* !defined(LOW_MEMORY) */
651 #endif /* DEBUG_THREADS */