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 = calloc(1, sizeof(*x));
68 strncpy(x->name, name, sizeof(x->name) - 1);
72 struct ast_context *context_list;
73 struct ast_context *last_context;
74 struct namelist *globalvars;
75 struct namelist *globalvars_last;
77 int conts=0, extens=0, priors=0;
78 char last_exten[18000];
79 char ast_config_AST_CONFIG_DIR[PATH_MAX];
80 char ast_config_AST_VAR_DIR[PATH_MAX];
82 void ast_add_profile(void);
83 void ast_cli_register_multiple(void);
84 void ast_register_file_version(void);
85 void ast_unregister_file_version(void);
86 int ast_add_extension2(struct ast_context *con,
87 int replace, const char *extension, int priority, const char *label, const char *callerid,
88 const char *application, void *data, void (*datad)(void *),
89 const char *registrar);
90 void pbx_builtin_setvar(void *chan, void *data);
91 struct ast_context * ast_context_create(void **extcontexts, const char *name, const char *registrar);
92 void ast_context_add_ignorepat2(struct ast_context *con, const char *value, const char *registrar);
93 void ast_context_add_include2(struct ast_context *con, const char *value, const char *registrar);
94 void ast_context_add_switch2(struct ast_context *con, const char *value, const char *data, int eval, const char *registrar);
95 void ast_merge_contexts_and_delete(void);
96 void ast_context_verify_includes(void);
97 struct ast_context * ast_walk_contexts(void);
98 void ast_cli_unregister_multiple(void);
99 void ast_context_destroy(void);
100 void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...);
101 char *ast_process_quotes_and_slashes(char *start, char find, char replace_with);
102 void ast_verbose(const char *fmt, ...);
103 struct ast_app *pbx_findapp(const char *app);
104 void filter_leading_space_from_exprs(char *str);
105 void filter_newlines(char *str);
106 static int quiet = 0;
107 static int no_comp = 0;
108 static int use_curr_dir = 0;
109 static int dump_extensions = 0;
110 static int FIRST_TIME = 0;
111 static FILE *dumpfile;
113 struct ast_app *pbx_findapp(const char *app)
115 return (struct ast_app*)1; /* so as not to trigger an error */
118 void ast_add_profile(void)
121 printf("Executed ast_add_profile();\n");
124 int ast_loader_register(int (*updater)(void))
129 int ast_loader_unregister(int (*updater)(void))
133 void ast_module_register(const struct ast_module_info *x)
137 void ast_module_unregister(const struct ast_module_info *x)
142 void ast_cli_register_multiple(void)
145 printf("Executed ast_cli_register_multiple();\n");
148 void ast_register_file_version(void)
151 printf("Executed ast_register_file_version();\n"); */
152 /* I'm erasing this, because I don't think anyone really ever needs to see it anyway */
155 void ast_unregister_file_version(void)
158 printf("Executed ast_unregister_file_version();\n"); */
159 /* I'm erasing this, because I don't think anyone really ever needs to see it anyway */
162 int ast_add_extension2(struct ast_context *con,
163 int replace, const char *extension, int priority, const char *label, const char *callerid,
164 const char *application, void *data, void (*datad)(void *),
165 const char *registrar)
168 con->extension_count++;
169 if (strcmp(extension,last_exten) != 0) {
171 strcpy(last_exten, extension);
180 application = "(null)";
184 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",
185 con->name, replace, extension, priority, label, callerid, application, (data?(char*)data:"(null)"), registrar);
187 if( dump_extensions && dumpfile ) {
194 fprintf(dumpfile,"[globals]\n");
196 for(n=globalvars;n;n=n->next) {
197 fprintf(dumpfile, "%s\n", n->name);
201 /* print out each extension , possibly the context header also */
202 if( con != last_context ) {
203 fprintf(dumpfile,"\n\n[%s]\n", con->name);
205 for(n=con->ignorepats;n;n=n->next) {
206 fprintf(dumpfile, "ignorepat => %s\n", n->name);
208 for(n=con->includes;n;n=n->next) {
209 fprintf(dumpfile, "include => %s\n", n->name);
211 for(n=con->switches;n;n=n->next) {
212 fprintf(dumpfile, "switch => %s/%s\n", n->name, n->name2);
214 for(n=con->eswitches;n;n=n->next) {
215 fprintf(dumpfile, "eswitch => %s/%s\n", n->name, n->name2);
220 filter_newlines((char*)data);
221 filter_leading_space_from_exprs((char*)data);
223 if( strcmp(label,"(null)") != 0 )
224 fprintf(dumpfile,"exten => %s,%d(%s),%s(%s)\n", extension, priority, label, application, (char*)data);
226 fprintf(dumpfile,"exten => %s,%d,%s(%s)\n", extension, priority, application, (char*)data);
230 if( strcmp(label,"(null)") != 0 )
231 fprintf(dumpfile,"exten => %s,%d(%s),%s\n", extension, priority, label, application);
233 fprintf(dumpfile,"exten => %s,%d,%s\n", extension, priority, application);
237 /* since add_extension2 is responsible for the malloc'd data stuff */
243 void pbx_builtin_setvar(void *chan, void *data)
245 struct namelist *x = create_name((char*)data);
247 printf("Executed pbx_builtin_setvar(chan, data=%s);\n", (char*)data);
249 if( dump_extensions ) {
250 x = create_name((char*)data);
251 ADD_LAST(globalvars,x);
256 struct ast_context * ast_context_create(void **extcontexts, const char *name, const char *registrar)
258 struct ast_context *x = calloc(1, sizeof(*x));
261 x->next = context_list;
264 printf("Executed ast_context_create(conts, name=%s, registrar=%s);\n", name, registrar);
266 strncpy(x->name, name, sizeof(x->name) - 1);
267 strncpy(x->registrar, registrar, sizeof(x->registrar) - 1);
271 void ast_context_add_ignorepat2(struct ast_context *con, const char *value, const char *registrar)
274 printf("Executed ast_context_add_ignorepat2(con, value=%s, registrar=%s);\n", value, registrar);
275 if( dump_extensions ) {
277 x = create_name((char*)value);
278 ADD_LAST(con->ignorepats,x);
282 void ast_context_add_include2(struct ast_context *con, const char *value, const char *registrar)
285 printf("Executed ast_context_add_include2(con, value=%s, registrar=%s);\n", value, registrar);
286 if( dump_extensions ) {
288 x = create_name((char*)value);
289 ADD_LAST(con->includes,x);
293 void ast_context_add_switch2(struct ast_context *con, const char *value, const char *data, int eval, const char *registrar)
296 printf("Executed ast_context_add_switch2(con, value=%s, data=%s, eval=%d, registrar=%s);\n", value, data, eval, registrar);
297 if( dump_extensions ) {
299 x = create_name((char*)value);
300 strncpy(x->name2,data,100);
303 ADD_LAST(con->switches,x);
307 ADD_LAST(con->eswitches,x);
312 void ast_merge_contexts_and_delete(void)
315 printf("Executed ast_merge_contexts_and_delete();\n");
318 void ast_context_verify_includes(void)
321 printf("Executed ast_context_verify_includes();\n");
324 struct ast_context * ast_walk_contexts(void)
327 printf("Executed ast_walk_contexts();\n");
331 void ast_cli_unregister_multiple(void)
334 printf("Executed ast_cli_unregister_multiple();\n");
337 void ast_context_destroy(void)
340 printf("Executed ast_context_destroy();\n");
343 void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
347 if( !quiet || level > 2 ) {
348 printf("LOG: lev:%d file:%s line:%d func: %s ",
349 level, file, line, function);
356 void ast_verbose(const char *fmt, ...)
367 char *ast_process_quotes_and_slashes(char *start, char find, char replace_with)
369 char *dataPut = start;
373 for (; *start; start++) {
375 *dataPut++ = *start; /* Always goes verbatim */
378 if (*start == '\\') {
379 inEscape = 1; /* Do not copy \ into the data */
380 } else if (*start == '\'') {
381 inQuotes = 1-inQuotes; /* Do not copy ' into the data */
383 /* Replace , with |, unless in quotes */
384 *dataPut++ = inQuotes ? *start : ((*start==find) ? replace_with : *start);
388 if (start != dataPut)
393 void filter_leading_space_from_exprs(char *str)
395 /* Mainly for aesthetics */
396 char *t, *v, *u = str;
400 if( *u == '$' && *(u+1) == '[' ) {
402 while( *t == '\n' || *t == '\r' || *t == '\t' || *t == ' ' ) {
415 void filter_newlines(char *str)
417 /* remove all newlines, returns */
420 if( *t == '\n' || *t == '\r' ) {
421 *t = ' '; /* just replace newlines and returns with spaces; they act as
422 token separators, and just blindly removing them could be
430 extern struct module_symbols mod_data;
431 extern int ael_external_load_module(void);
433 int main(int argc, char **argv)
437 struct ast_context *lp,*lp2;
439 for(i=1;i<argc;i++) {
440 if( argv[i][0] == '-' && argv[i][1] == 'n' )
442 if( argv[i][0] == '-' && argv[i][1] == 'q' ) {
446 if( argv[i][0] == '-' && argv[i][1] == 'd' )
448 if( argv[i][0] == '-' && argv[i][1] == 'w' )
453 printf("\n(If you find progress and other non-error messages irritating, you can use -q to suppress them)\n");
455 printf("\n(You can use the -n option if you aren't interested in seeing all the instructions generated by the compiler)\n\n");
457 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");
458 if( !dump_extensions )
459 printf("\n(You can use the -w option to dump extensions.conf format to extensions.conf.aeldump)\n");
463 strcpy(ast_config_AST_CONFIG_DIR, ".");
466 strcpy(ast_config_AST_CONFIG_DIR, "/etc/asterisk");
468 strcpy(ast_config_AST_VAR_DIR, "/var/lib/asterisk");
470 if( dump_extensions ) {
471 dumpfile = fopen("extensions.conf.aeldump","w");
473 printf("\n\nSorry, cannot open extensions.conf.aeldump for writing! Correct the situation and try again!\n\n");
481 ael_external_load_module();
483 ast_log(4, "ael2_parse", __LINE__, "main", "%d contexts, %d extensions, %d priorities\n", conts, extens, priors);
485 if( dump_extensions && dumpfile ) {
487 for( lp = context_list; lp; lp = lp->next ) { /* print out any contexts that didn't have any
488 extensions in them */
489 if( lp->extension_count == 0 ) {
491 fprintf(dumpfile,"\n\n[%s]\n", lp->name);
493 for(n=lp->ignorepats;n;n=n->next) {
494 fprintf(dumpfile, "ignorepat => %s\n", n->name);
496 for(n=lp->includes;n;n=n->next) {
497 fprintf(dumpfile, "include => %s\n", n->name);
499 for(n=lp->switches;n;n=n->next) {
500 fprintf(dumpfile, "switch => %s/%s\n", n->name, n->name2);
502 for(n=lp->eswitches;n;n=n->next) {
503 fprintf(dumpfile, "eswitch => %s/%s\n", n->name, n->name2);
509 if( dump_extensions && dumpfile )
512 for( lp = context_list; lp; lp = lp2 ) { /* free the ast_context structs */
516 destroy_namelist(lp->includes);
517 destroy_namelist(lp->ignorepats);
518 destroy_namelist(lp->switches);
519 destroy_namelist(lp->eswitches);