1 #include "asterisk/autoconfig.h"
10 #if !defined(SOLARIS) && !defined(__CYGWIN__)
17 #include "asterisk/ast_expr.h"
18 #include "asterisk/channel.h"
19 #include "asterisk/module.h"
20 #include "asterisk/app.h"
21 #include "asterisk/ael_structs.h"
27 struct namelist *next;
35 struct namelist *includes;
36 struct namelist *ignorepats;
37 struct namelist *switches;
38 struct namelist *eswitches;
40 struct namelist *includes_last;
41 struct namelist *ignorepats_last;
42 struct namelist *switches_last;
43 struct namelist *eswitches_last;
45 struct ast_context *next;
48 #define ADD_LAST(headptr,memptr) if(!headptr){ headptr=(memptr); (headptr##_last)=(memptr);} else {(headptr##_last)->next = (memptr); (headptr##_last) = (memptr);}
50 void destroy_namelist(struct namelist *x);
51 void destroy_namelist(struct namelist *x)
53 struct namelist *z,*z2;
62 struct namelist *create_name(char *name);
63 struct namelist *create_name(char *name)
65 struct namelist *x = (struct namelist *)calloc(sizeof(struct namelist),1);
66 strncpy(x->name,name,100);
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_add_profile(void);
81 void ast_cli_register_multiple(void);
82 void ast_register_file_version(void);
83 void ast_unregister_file_version(void);
84 int ast_add_extension2(struct ast_context *con,
85 int replace, const char *extension, int priority, const char *label, const char *callerid,
86 const char *application, void *data, void (*datad)(void *),
87 const char *registrar);
88 void pbx_builtin_setvar(void *chan, void *data);
89 struct ast_context * ast_context_create(void **extcontexts, const char *name, const char *registrar);
90 void ast_context_add_ignorepat2(struct ast_context *con, const char *value, const char *registrar);
91 void ast_context_add_include2(struct ast_context *con, const char *value, const char *registrar);
92 void ast_context_add_switch2(struct ast_context *con, const char *value, const char *data, int eval, const char *registrar);
93 void ast_merge_contexts_and_delete(void);
94 void ast_context_verify_includes(void);
95 struct ast_context * ast_walk_contexts(void);
96 void ast_cli_unregister_multiple(void);
97 void ast_context_destroy(void);
98 void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...);
99 char *ast_process_quotes_and_slashes(char *start, char find, char replace_with);
100 void ast_verbose(const char *fmt, ...);
101 struct ast_app *pbx_findapp(const char *app);
102 void filter_leading_space_from_exprs(char *str);
103 void filter_newlines(char *str);
104 static int quiet = 0;
105 static int no_comp = 0;
106 static int use_curr_dir = 0;
107 static int dump_extensions = 0;
108 static int FIRST_TIME = 0;
109 static FILE *dumpfile;
111 struct ast_app *pbx_findapp(const char *app)
113 return (struct ast_app*)1; /* so as not to trigger an error */
116 void ast_add_profile(void)
119 printf("Executed ast_add_profile();\n");
122 int ast_loader_register(int (*updater)(void))
127 int ast_loader_unregister(int (*updater)(void))
131 void ast_module_register(const struct ast_module_info *x)
135 void ast_module_unregister(const struct ast_module_info *x)
140 void ast_cli_register_multiple(void)
143 printf("Executed ast_cli_register_multiple();\n");
146 void ast_register_file_version(void)
149 printf("Executed ast_register_file_version();\n"); */
150 /* I'm erasing this, because I don't think anyone really ever needs to see it anyway */
153 void ast_unregister_file_version(void)
156 printf("Executed ast_unregister_file_version();\n"); */
157 /* I'm erasing this, because I don't think anyone really ever needs to see it anyway */
160 int ast_add_extension2(struct ast_context *con,
161 int replace, const char *extension, int priority, const char *label, const char *callerid,
162 const char *application, void *data, void (*datad)(void *),
163 const char *registrar)
166 con->extension_count++;
167 if (strcmp(extension,last_exten) != 0) {
169 strcpy(last_exten, extension);
178 application = "(null)";
182 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",
183 con->name, replace, extension, priority, label, callerid, application, (data?(char*)data:"(null)"), registrar);
185 if( dump_extensions && dumpfile ) {
192 fprintf(dumpfile,"[globals]\n");
194 for(n=globalvars;n;n=n->next) {
195 fprintf(dumpfile, "%s\n", n->name);
199 /* print out each extension , possibly the context header also */
200 if( con != last_context ) {
201 fprintf(dumpfile,"\n\n[%s]\n", con->name);
203 for(n=con->ignorepats;n;n=n->next) {
204 fprintf(dumpfile, "ignorepat => %s\n", n->name);
206 for(n=con->includes;n;n=n->next) {
207 fprintf(dumpfile, "include => %s\n", n->name);
209 for(n=con->switches;n;n=n->next) {
210 fprintf(dumpfile, "switch => %s/%s\n", n->name, n->name2);
212 for(n=con->eswitches;n;n=n->next) {
213 fprintf(dumpfile, "eswitch => %s/%s\n", n->name, n->name2);
218 filter_newlines((char*)data);
219 filter_leading_space_from_exprs((char*)data);
221 if( strcmp(label,"(null)") != 0 )
222 fprintf(dumpfile,"exten => %s,%d(%s),%s(%s)\n", extension, priority, label, application, (char*)data);
224 fprintf(dumpfile,"exten => %s,%d,%s(%s)\n", extension, priority, application, (char*)data);
228 if( strcmp(label,"(null)") != 0 )
229 fprintf(dumpfile,"exten => %s,%d(%s),%s\n", extension, priority, label, application);
231 fprintf(dumpfile,"exten => %s,%d,%s\n", extension, priority, application);
235 /* since add_extension2 is responsible for the malloc'd data stuff */
241 void pbx_builtin_setvar(void *chan, void *data)
243 struct namelist *x = create_name((char*)data);
245 printf("Executed pbx_builtin_setvar(chan, data=%s);\n", (char*)data);
247 if( dump_extensions ) {
248 x = create_name((char*)data);
249 ADD_LAST(globalvars,x);
254 struct ast_context * ast_context_create(void **extcontexts, const char *name, const char *registrar)
256 struct ast_context *x = (struct ast_context *)calloc(sizeof(struct ast_context),1);
257 x->next = context_list;
260 printf("Executed ast_context_create(conts, name=%s, registrar=%s);\n", name, registrar);
262 strncpy(x->name,name,100);
263 strncpy(x->registrar,registrar,100);
267 void ast_context_add_ignorepat2(struct ast_context *con, const char *value, const char *registrar)
270 printf("Executed ast_context_add_ignorepat2(con, value=%s, registrar=%s);\n", value, registrar);
271 if( dump_extensions ) {
273 x = create_name((char*)value);
274 ADD_LAST(con->ignorepats,x);
278 void ast_context_add_include2(struct ast_context *con, const char *value, const char *registrar)
281 printf("Executed ast_context_add_include2(con, value=%s, registrar=%s);\n", value, registrar);
282 if( dump_extensions ) {
284 x = create_name((char*)value);
285 ADD_LAST(con->includes,x);
289 void ast_context_add_switch2(struct ast_context *con, const char *value, const char *data, int eval, const char *registrar)
292 printf("Executed ast_context_add_switch2(con, value=%s, data=%s, eval=%d, registrar=%s);\n", value, data, eval, registrar);
293 if( dump_extensions ) {
295 x = create_name((char*)value);
296 strncpy(x->name2,data,100);
299 ADD_LAST(con->switches,x);
303 ADD_LAST(con->eswitches,x);
308 void ast_merge_contexts_and_delete(void)
311 printf("Executed ast_merge_contexts_and_delete();\n");
314 void ast_context_verify_includes(void)
317 printf("Executed ast_context_verify_includes();\n");
320 struct ast_context * ast_walk_contexts(void)
323 printf("Executed ast_walk_contexts();\n");
327 void ast_cli_unregister_multiple(void)
330 printf("Executed ast_cli_unregister_multiple();\n");
333 void ast_context_destroy(void)
336 printf("Executed ast_context_destroy();\n");
339 void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
343 if( !quiet || level > 2 ) {
344 printf("LOG: lev:%d file:%s line:%d func: %s ",
345 level, file, line, function);
352 void ast_verbose(const char *fmt, ...)
363 char *ast_process_quotes_and_slashes(char *start, char find, char replace_with)
365 char *dataPut = start;
369 for (; *start; start++) {
371 *dataPut++ = *start; /* Always goes verbatim */
374 if (*start == '\\') {
375 inEscape = 1; /* Do not copy \ into the data */
376 } else if (*start == '\'') {
377 inQuotes = 1-inQuotes; /* Do not copy ' into the data */
379 /* Replace , with |, unless in quotes */
380 *dataPut++ = inQuotes ? *start : ((*start==find) ? replace_with : *start);
384 if (start != dataPut)
389 void filter_leading_space_from_exprs(char *str)
391 /* Mainly for aesthetics */
392 char *t, *v, *u = str;
396 if( *u == '$' && *(u+1) == '[' ) {
398 while( *t == '\n' || *t == '\r' || *t == '\t' || *t == ' ' ) {
411 void filter_newlines(char *str)
413 /* remove all newlines, returns */
416 if( *t == '\n' || *t == '\r' ) {
417 *t = ' '; /* just replace newlines and returns with spaces; they act as
418 token separators, and just blindly removing them could be
426 extern struct module_symbols mod_data;
427 extern int ael_external_load_module(void);
429 int main(int argc, char **argv)
433 struct ast_context *lp,*lp2;
435 for(i=1;i<argc;i++) {
436 if( argv[i][0] == '-' && argv[i][1] == 'n' )
438 if( argv[i][0] == '-' && argv[i][1] == 'q' ) {
442 if( argv[i][0] == '-' && argv[i][1] == 'd' )
444 if( argv[i][0] == '-' && argv[i][1] == 'w' )
449 printf("\n(If you find progress and other non-error messages irritating, you can use -q to suppress them)\n");
451 printf("\n(You can use the -n option if you aren't interested in seeing all the instructions generated by the compiler)\n\n");
453 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");
454 if( !dump_extensions )
455 printf("\n(You can use the -w option to dump extensions.conf format to extensions.conf.aeldump)\n");
459 strcpy(ast_config_AST_CONFIG_DIR, ".");
462 strcpy(ast_config_AST_CONFIG_DIR, "/etc/asterisk");
464 strcpy(ast_config_AST_VAR_DIR, "/var/lib/asterisk");
466 if( dump_extensions ) {
467 dumpfile = fopen("extensions.conf.aeldump","w");
469 printf("\n\nSorry, cannot open extensions.conf.aeldump for writing! Correct the situation and try again!\n\n");
477 ael_external_load_module();
479 ast_log(4, "ael2_parse", __LINE__, "main", "%d contexts, %d extensions, %d priorities\n", conts, extens, priors);
481 if( dump_extensions && dumpfile ) {
483 for( lp = context_list; lp; lp = lp->next ) { /* print out any contexts that didn't have any
484 extensions in them */
485 if( lp->extension_count == 0 ) {
487 fprintf(dumpfile,"\n\n[%s]\n", lp->name);
489 for(n=lp->ignorepats;n;n=n->next) {
490 fprintf(dumpfile, "ignorepat => %s\n", n->name);
492 for(n=lp->includes;n;n=n->next) {
493 fprintf(dumpfile, "include => %s\n", n->name);
495 for(n=lp->switches;n;n=n->next) {
496 fprintf(dumpfile, "switch => %s/%s\n", n->name, n->name2);
498 for(n=lp->eswitches;n;n=n->next) {
499 fprintf(dumpfile, "eswitch => %s/%s\n", n->name, n->name2);
505 if( dump_extensions && dumpfile )
508 for( lp = context_list; lp; lp = lp2 ) { /* free the ast_context structs */
512 destroy_namelist(lp->includes);
513 destroy_namelist(lp->ignorepats);
514 destroy_namelist(lp->switches);
515 destroy_namelist(lp->eswitches);