8 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
10 #include "asterisk/channel.h"
11 #include "asterisk/ast_expr.h"
12 #include "asterisk/module.h"
13 #include "asterisk/app.h"
14 #include "asterisk/ael_structs.h"
15 #include "asterisk/extconf.h"
18 <depend>res_ael_share</depend>
25 struct namelist *next;
33 struct namelist *includes;
34 struct namelist *ignorepats;
35 struct namelist *switches;
36 struct namelist *eswitches;
38 struct namelist *includes_last;
39 struct namelist *ignorepats_last;
40 struct namelist *switches_last;
41 struct namelist *eswitches_last;
43 struct ast_context *next;
46 #define ADD_LAST(headptr,memptr) if(!headptr){ headptr=(memptr); (headptr##_last)=(memptr);} else {(headptr##_last)->next = (memptr); (headptr##_last) = (memptr);}
48 void destroy_namelist(struct namelist *x);
49 void destroy_namelist(struct namelist *x)
51 struct namelist *z,*z2;
60 struct namelist *create_name(const char *name);
61 struct namelist *create_name(const char *name)
63 struct namelist *x = calloc(1, sizeof(*x));
66 strncpy(x->name, name, sizeof(x->name) - 1);
70 struct ast_context *context_list;
71 struct ast_context *last_context;
72 struct namelist *globalvars;
73 struct namelist *globalvars_last;
75 int conts=0, extens=0, priors=0;
76 char last_exten[18000];
77 char ast_config_AST_CONFIG_DIR[PATH_MAX];
78 char ast_config_AST_VAR_DIR[PATH_MAX];
80 void ast_cli_register_multiple(void);
81 int ast_add_extension2(struct ast_context *con,
82 int replace, const char *extension, int priority, const char *label, const char *callerid,
83 const char *application, void *data, void (*datad)(void *),
84 const char *registrar);
85 void pbx_builtin_setvar(void *chan, void *data);
86 struct ast_context * ast_context_create(void **extcontexts, const char *name, const char *registrar);
87 struct ast_context * ast_context_find_or_create(void **extcontexts, const char *name, const char *registrar);
88 void ast_context_add_ignorepat2(struct ast_context *con, const char *value, const char *registrar);
89 void ast_context_add_include2(struct ast_context *con, const char *value, const char *registrar);
90 void ast_context_add_switch2(struct ast_context *con, const char *value, const char *data, int eval, const char *registrar);
91 void ast_merge_contexts_and_delete(void);
92 void ast_context_verify_includes(void);
93 struct ast_context * ast_walk_contexts(void);
94 void ast_cli_unregister_multiple(void);
95 void ast_context_destroy(void);
96 void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...);
97 char *ast_process_quotes_and_slashes(char *start, char find, char replace_with);
98 void ast_verbose(const char *fmt, ...);
99 struct ast_app *pbx_findapp(const char *app);
100 void filter_leading_space_from_exprs(char *str);
101 void filter_newlines(char *str);
102 static int quiet = 0;
103 static int no_comp = 0;
104 static int use_curr_dir = 0;
105 static int dump_extensions = 0;
106 static int FIRST_TIME = 0;
107 static FILE *dumpfile;
109 void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
114 printf("LOG: lev:%d file:%s line:%d func: %s ",
115 level, file, line, function);
121 struct ast_exten *pbx_find_extension(struct ast_channel *chan,
122 struct ast_context *bypass,
123 struct pbx_find_info *q,
128 const char *callerid,
129 enum ext_match_t action);
131 struct ast_exten *pbx_find_extension(struct ast_channel *chan,
132 struct ast_context *bypass,
133 struct pbx_find_info *q,
138 const char *callerid,
139 enum ext_match_t action)
141 return localized_find_extension(bypass, q, context, exten, priority, label, callerid, action);
144 struct ast_app *pbx_findapp(const char *app)
146 return (struct ast_app*)1; /* so as not to trigger an error */
149 struct ast_custom_function *ast_custom_function_find(const char *name);
152 struct ast_custom_function *ast_custom_function_find(const char *name)
154 return 0; /* in "standalone" mode, functions are just not avail */
157 void ast_register_file_version(const char *file, const char *version)
161 void ast_unregister_file_version(const char *file)
165 int ast_add_profile(const char *x, uint64_t scale)
168 printf("Executed ast_add_profile();\n");
173 int ast_loader_register(int (*updater)(void))
178 int ast_loader_unregister(int (*updater)(void))
182 void ast_module_register(const struct ast_module_info *x)
186 void ast_module_unregister(const struct ast_module_info *x)
191 void ast_cli_register_multiple(void)
194 printf("Executed ast_cli_register_multiple();\n");
197 void pbx_substitute_variables_helper(struct ast_channel *c,const char *cp1,char *cp2,int count);
198 void pbx_substitute_variables_helper(struct ast_channel *c,const char *cp1,char *cp2,int count)
201 strncpy(cp2,cp1,AST_MAX_EXTENSION); /* Right now, this routine is ONLY being called for
202 a possible var substitution on extension names,
208 int ast_add_extension2(struct ast_context *con,
209 int replace, const char *extension, int priority, const char *label, const char *callerid,
210 const char *application, void *data, void (*datad)(void *),
211 const char *registrar)
214 con->extension_count++;
215 if (strcmp(extension,last_exten) != 0) {
217 strcpy(last_exten, extension);
226 application = "(null)";
230 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",
231 con->name, replace, extension, priority, label, callerid, application, (data?(char*)data:"(null)"), registrar);
233 if( dump_extensions && dumpfile ) {
235 char *data2,*data3=0;
242 fprintf(dumpfile,"[globals]\n");
244 for(n=globalvars;n;n=n->next) {
245 fprintf(dumpfile, "%s\n", n->name);
249 /* print out each extension , possibly the context header also */
250 if( con != last_context ) {
251 fprintf(dumpfile,"\n\n[%s]\n", con->name);
253 for(n=con->ignorepats;n;n=n->next) {
254 fprintf(dumpfile, "ignorepat => %s\n", n->name);
256 for(n=con->includes;n;n=n->next) {
257 fprintf(dumpfile, "include => %s\n", n->name);
259 for(n=con->switches;n;n=n->next) {
260 fprintf(dumpfile, "switch => %s/%s\n", n->name, n->name2);
262 for(n=con->eswitches;n;n=n->next) {
263 fprintf(dumpfile, "eswitch => %s/%s\n", n->name, n->name2);
268 filter_newlines((char*)data);
269 filter_leading_space_from_exprs((char*)data);
271 /* compiling turns commas into vertical bars in the app data, and also removes the backslash from before escaped commas;
272 we have to restore the escaping backslash in front of any commas; the vertical bars are OK to leave as-is */
273 for (data2 = data; *data2; data2++) {
275 commacount++; /* we need to know how much bigger the string will grow-- one backslash for each comma */
281 data2 = (char*)malloc(strlen(data)+commacount+1);
287 *d4++ = '\\'; /* put a backslash in front of each comma */
290 *d4++ = *d3++; /* or just copy the char */
292 *d4++ = 0; /* cap off the new string */
297 if( strcmp(label,"(null)") != 0 )
298 fprintf(dumpfile,"exten => %s,%d(%s),%s(%s)\n", extension, priority, label, application, (char*)data);
300 fprintf(dumpfile,"exten => %s,%d,%s(%s)\n", extension, priority, application, (char*)data);
305 data = data3; /* restore data to pre-messedup state */
310 if( strcmp(label,"(null)") != 0 )
311 fprintf(dumpfile,"exten => %s,%d(%s),%s\n", extension, priority, label, application);
313 fprintf(dumpfile,"exten => %s,%d,%s\n", extension, priority, application);
317 /* since add_extension2 is responsible for the malloc'd data stuff */
323 void pbx_builtin_setvar(void *chan, void *data)
325 struct namelist *x = create_name(data);
327 printf("Executed pbx_builtin_setvar(chan, data=%s);\n", (char*)data);
329 if( dump_extensions ) {
330 x = create_name(data);
331 ADD_LAST(globalvars,x);
336 struct ast_context * ast_context_create(void **extcontexts, const char *name, const char *registrar)
338 struct ast_context *x = calloc(1, sizeof(*x));
341 x->next = context_list;
344 printf("Executed ast_context_create(conts, name=%s, registrar=%s);\n", name, registrar);
346 strncpy(x->name, name, sizeof(x->name) - 1);
347 strncpy(x->registrar, registrar, sizeof(x->registrar) - 1);
351 struct ast_context * ast_context_find_or_create(void **extcontexts, const char *name, const char *registrar)
353 struct ast_context *x = calloc(1, sizeof(*x));
356 x->next = context_list;
359 printf("Executed ast_context_find_or_create(conts, name=%s, registrar=%s);\n", name, registrar);
361 strncpy(x->name, name, sizeof(x->name) - 1);
362 strncpy(x->registrar, registrar, sizeof(x->registrar) - 1);
366 void ast_context_add_ignorepat2(struct ast_context *con, const char *value, const char *registrar)
369 printf("Executed ast_context_add_ignorepat2(con, value=%s, registrar=%s);\n", value, registrar);
370 if( dump_extensions ) {
372 x = create_name(value);
373 ADD_LAST(con->ignorepats,x);
377 void ast_context_add_include2(struct ast_context *con, const char *value, const char *registrar)
380 printf("Executed ast_context_add_include2(con, value=%s, registrar=%s);\n", value, registrar);
381 if( dump_extensions ) {
383 x = create_name((char*)value);
384 ADD_LAST(con->includes,x);
388 void ast_context_add_switch2(struct ast_context *con, const char *value, const char *data, int eval, const char *registrar)
391 printf("Executed ast_context_add_switch2(con, value=%s, data=%s, eval=%d, registrar=%s);\n", value, data, eval, registrar);
392 if( dump_extensions ) {
394 x = create_name((char*)value);
395 strncpy(x->name2,data,100);
398 ADD_LAST(con->switches,x);
402 ADD_LAST(con->eswitches,x);
407 void ast_merge_contexts_and_delete(void)
410 printf("Executed ast_merge_contexts_and_delete();\n");
413 void ast_context_verify_includes(void)
416 printf("Executed ast_context_verify_includes();\n");
419 struct ast_context * ast_walk_contexts(void)
422 printf("Executed ast_walk_contexts();\n");
426 void ast_cli_unregister_multiple(void)
429 printf("Executed ast_cli_unregister_multiple();\n");
432 void ast_context_destroy(void)
435 printf("Executed ast_context_destroy();\n");
438 void filter_leading_space_from_exprs(char *str)
440 /* Mainly for aesthetics */
441 char *t, *v, *u = str;
445 if( *u == '$' && *(u+1) == '[' ) {
447 while( *t == '\n' || *t == '\r' || *t == '\t' || *t == ' ' ) {
460 void filter_newlines(char *str)
462 /* remove all newlines, returns */
465 if( *t == '\n' || *t == '\r' ) {
466 *t = ' '; /* just replace newlines and returns with spaces; they act as
467 token separators, and just blindly removing them could be
475 extern struct module_symbols mod_data;
476 int ael_external_load_module(void);
479 int main(int argc, char **argv)
483 struct ast_context *lp,*lp2;
485 for(i=1;i<argc;i++) {
486 if( argv[i][0] == '-' && argv[i][1] == 'n' )
488 if( argv[i][0] == '-' && argv[i][1] == 'q' ) {
492 if( argv[i][0] == '-' && argv[i][1] == 'd' )
494 if( argv[i][0] == '-' && argv[i][1] == 'w' )
499 printf("\n(If you find progress and other non-error messages irritating, you can use -q to suppress them)\n");
501 printf("\n(You can use the -n option if you aren't interested in seeing all the instructions generated by the compiler)\n\n");
503 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");
504 if( !dump_extensions )
505 printf("\n(You can use the -w option to dump extensions.conf format to extensions.conf.aeldump)\n");
509 strcpy(ast_config_AST_CONFIG_DIR, ".");
510 localized_use_local_dir();
513 strcpy(ast_config_AST_CONFIG_DIR, "/etc/asterisk");
514 localized_use_conf_dir();
516 strcpy(ast_config_AST_VAR_DIR, "/var/lib/asterisk");
518 if( dump_extensions ) {
519 dumpfile = fopen("extensions.conf.aeldump","w");
521 printf("\n\nSorry, cannot open extensions.conf.aeldump for writing! Correct the situation and try again!\n\n");
529 ael_external_load_module();
531 ast_log(4, "ael2_parse", __LINE__, "main", "%d contexts, %d extensions, %d priorities\n", conts, extens, priors);
533 if( dump_extensions && dumpfile ) {
535 for( lp = context_list; lp; lp = lp->next ) { /* print out any contexts that didn't have any
536 extensions in them */
537 if( lp->extension_count == 0 ) {
539 fprintf(dumpfile,"\n\n[%s]\n", lp->name);
541 for(n=lp->ignorepats;n;n=n->next) {
542 fprintf(dumpfile, "ignorepat => %s\n", n->name);
544 for(n=lp->includes;n;n=n->next) {
545 fprintf(dumpfile, "include => %s\n", n->name);
547 for(n=lp->switches;n;n=n->next) {
548 fprintf(dumpfile, "switch => %s/%s\n", n->name, n->name2);
550 for(n=lp->eswitches;n;n=n->next) {
551 fprintf(dumpfile, "eswitch => %s/%s\n", n->name, n->name2);
557 if( dump_extensions && dumpfile )
560 for( lp = context_list; lp; lp = lp2 ) { /* free the ast_context structs */
564 destroy_namelist(lp->includes);
565 destroy_namelist(lp->ignorepats);
566 destroy_namelist(lp->switches);
567 destroy_namelist(lp->eswitches);