2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2006, Digium, Inc.
6 * Steve Murphy <murf@parsetree.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
21 * \brief Compile symbolic Asterisk Extension Logic into Asterisk extensions, version 2.
26 <depend>res_ael_share</depend>
31 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
38 #include "asterisk/pbx.h"
39 #include "asterisk/config.h"
40 #include "asterisk/module.h"
41 #include "asterisk/logger.h"
42 #include "asterisk/cli.h"
43 #include "asterisk/app.h"
44 #include "asterisk/callerid.h"
45 #include "asterisk/ael_structs.h"
46 #include "asterisk/pval.h"
48 #include "asterisk/argdesc.h"
51 /* these functions are in ../ast_expr2.fl */
53 #define DEBUG_READ (1 << 0)
54 #define DEBUG_TOKENS (1 << 1)
55 #define DEBUG_MACROS (1 << 2)
56 #define DEBUG_CONTEXTS (1 << 3)
58 static char *config = "extensions.ael";
59 static char *registrar = "pbx_ael";
60 static int pbx_load_module(void);
63 /* for the time being, short circuit all the AAL related structures
64 without permanently removing the code; after/during the AAL
65 development, this code can be properly re-instated
71 int option_matches_j( struct argdesc *should, pval *is, struct argapp *app);
72 int option_matches( struct argdesc *should, pval *is, struct argapp *app);
73 int ael_is_funcname(char *name);
76 int check_app_args(pval *appcall, pval *arglist, struct argapp *app);
77 void check_pval(pval *item, struct argapp *apps, int in_globals);
78 void check_pval_item(pval *item, struct argapp *apps, int in_globals);
79 void check_switch_expr(pval *item, struct argapp *apps);
80 void ast_expr_register_extra_error_info(char *errmsg);
81 void ast_expr_clear_extra_error_info(void);
82 struct pval *find_macro(char *name);
83 struct pval *find_context(char *name);
84 struct pval *find_context(char *name);
85 struct pval *find_macro(char *name);
86 struct ael_priority *new_prio(void);
87 struct ael_extension *new_exten(void);
88 void linkprio(struct ael_extension *exten, struct ael_priority *prio);
89 void destroy_extensions(struct ael_extension *exten);
90 void set_priorities(struct ael_extension *exten);
91 void add_extensions(struct ael_extension *exten);
92 void ast_compile_ael2(struct ast_context **local_contexts, struct pval *root);
93 void destroy_pval(pval *item);
94 void destroy_pval_item(pval *item);
95 int is_float(char *arg );
96 int is_int(char *arg );
97 int is_empty(char *arg);
99 /* static void substitute_commas(char *str); */
101 static int aeldebug = 0;
103 /* interface stuff */
105 /* if all the below are static, who cares if they are present? */
107 static int pbx_load_module(void)
109 int errs=0, sem_err=0, sem_warn=0, sem_note=0;
111 struct ast_context *local_contexts=NULL, *con;
112 struct pval *parse_tree;
114 ast_log(LOG_NOTICE, "Starting AEL load process.\n");
115 if (config[0] == '/')
116 rfilename = (char *)config;
118 rfilename = alloca(strlen(config) + strlen(ast_config_AST_CONFIG_DIR) + 2);
119 sprintf(rfilename, "%s/%s", ast_config_AST_CONFIG_DIR, config);
121 if (access(rfilename,R_OK) != 0) {
122 ast_log(LOG_NOTICE, "File %s not found; AEL declining load\n", rfilename);
123 return AST_MODULE_LOAD_DECLINE;
126 parse_tree = ael2_parse(rfilename, &errs);
127 ast_log(LOG_NOTICE, "AEL load process: parsed config file name '%s'.\n", rfilename);
128 ael2_semantic_check(parse_tree, &sem_err, &sem_warn, &sem_note);
129 if (errs == 0 && sem_err == 0) {
130 ast_log(LOG_NOTICE, "AEL load process: checked config file name '%s'.\n", rfilename);
131 ast_compile_ael2(&local_contexts, parse_tree);
132 ast_log(LOG_NOTICE, "AEL load process: compiled config file name '%s'.\n", rfilename);
134 ast_merge_contexts_and_delete(&local_contexts, registrar);
135 ast_log(LOG_NOTICE, "AEL load process: merged config file name '%s'.\n", rfilename);
136 for (con = ast_walk_contexts(NULL); con; con = ast_walk_contexts(con))
137 ast_context_verify_includes(con);
138 ast_log(LOG_NOTICE, "AEL load process: verified config file name '%s'.\n", rfilename);
140 ast_log(LOG_ERROR, "Sorry, but %d syntax errors and %d semantic errors were detected. It doesn't make sense to compile.\n", errs, sem_err);
141 destroy_pval(parse_tree); /* free up the memory */
142 return AST_MODULE_LOAD_DECLINE;
144 destroy_pval(parse_tree); /* free up the memory */
146 return AST_MODULE_LOAD_SUCCESS;
150 static char *handle_cli_ael_debug_multiple(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
154 e->command = "ael debug [read|tokens|macros|contexts|off]";
156 "Usage: ael debug [read|tokens|macros|contexts|off]\n"
157 " Enable AEL read, token, macro, or context debugging,\n"
158 " or disable all AEL debugging messages. Note: this\n"
159 " currently does nothing.\n";
166 return CLI_SHOWUSAGE;
168 if (!strcasecmp(a->argv[2], "read"))
169 aeldebug |= DEBUG_READ;
170 else if (!strcasecmp(a->argv[2], "tokens"))
171 aeldebug |= DEBUG_TOKENS;
172 else if (!strcasecmp(a->argv[2], "macros"))
173 aeldebug |= DEBUG_MACROS;
174 else if (!strcasecmp(a->argv[2], "contexts"))
175 aeldebug |= DEBUG_CONTEXTS;
176 else if (!strcasecmp(a->argv[2], "off"))
179 return CLI_SHOWUSAGE;
184 static char *handle_cli_ael_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
188 e->command = "ael reload";
190 "Usage: ael reload\n"
191 " Reloads AEL configuration.\n";
198 return CLI_SHOWUSAGE;
200 return (pbx_load_module() ? CLI_FAILURE : CLI_SUCCESS);
203 static struct ast_cli_entry cli_ael[] = {
204 AST_CLI_DEFINE(handle_cli_ael_reload, "Reload AEL configuration"),
205 AST_CLI_DEFINE(handle_cli_ael_debug_multiple, "Enable AEL debugging flags")
208 static int unload_module(void)
210 ast_context_destroy(NULL, registrar);
211 ast_cli_unregister_multiple(cli_ael, sizeof(cli_ael) / sizeof(struct ast_cli_entry));
215 static int load_module(void)
217 ast_cli_register_multiple(cli_ael, sizeof(cli_ael) / sizeof(struct ast_cli_entry));
218 return (pbx_load_module());
221 static int reload(void)
223 return pbx_load_module();
226 #ifdef STANDALONE_AEL
227 #define AST_MODULE "ael"
228 int ael_external_load_module(void);
229 int ael_external_load_module(void)
236 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Asterisk Extension Language Compiler",
238 .unload = unload_module,
243 static char *ael_funclist[] =
280 "QUEUE_MEMBER_COUNT",
302 int ael_is_funcname(char *name)
305 t = sizeof(ael_funclist)/sizeof(char*);
307 while ((s < t) && strcasecmp(name, ael_funclist[s]))