Changeset 5714

pbx_ael should not abuse cw_expr() as a syntax checker

Expression evaluation is a two stage process, substitution then
evaluation. Just calling cw_expr() is simply wrong because it isn't
parsing what it would under true evaluation. Worse, you don't want to
expand or evaluate things with possible side effects when simply loading
a dialplan!

Removing this means that some syntax errors will only be detectable at
run-time rather than (possibly) load-time. But that's the nature of the
beast. Dialplan isn't a language. AEL is a text transformation tool that
transforms text into dialplan. AEL is not a language either. IMHO no one
should use AEL and it shouldn't even exist. At the very least it should
exist as a separate "compiler" and not be embedded.

Comitted by:  mjagdis
Date:  Jun 05 2010 * 12:57 (about 1 year ago)

Affected files:

callweaver/trunk/pbx/pbx_ael.c (unified diff)

r5688r5714
5050
5151 #include "ael/ael_structs.h"
5252
53 static struct cw_dynstr expr_output = CW_DYNSTR_INIT;
5453
55 /* these functions are in ../cw_expr2.fl */
56
57
5854 #ifdef __CW_DEBUG_MALLOC
5955 static void FREE(void *ptr)
6056 {
------
10197 void check_pval(struct pval *item, struct argapp *apps, int in_globals);
10298 void check_pval_item(struct pval *item, struct argapp *apps, int in_globals);
10399 void check_switch_expr(struct pval *item, struct argapp *apps);
104 extern CW_API_PUBLIC void cw_expr_register_extra_error_info(char *errmsg);
105 extern CW_API_PUBLIC void cw_expr_clear_extra_error_info(void);
106 extern CW_API_PUBLIC int cw_expr(struct cw_channel *chan, char *expr, struct cw_dynstr *result);
107100 struct pval *find_proc(char *name);
108101 struct pval *find_context(char *name);
109102 struct ael_priority *new_prio(void);
------
20072000 #endif
20082001 struct pval *proc_def;
20092002 struct pval *app_def;
2010
2011 char errmsg[4096];
2012 char *strp;
2013
2003
20142004 switch (item->type) {
20152005 case PV_WORD:
20162006 /* fields: item->u1.str == string associated with this (word).
------
22032193 */
22042194 /* the RHS of a vardec is encapsulated in a $[] expr. Is it legal? */
22052195 if( !in_globals ) { /* don't check stuff inside the globals context; no wrapping in $[ ] there... */
2206 snprintf(errmsg,sizeof(errmsg), "file %s, line %d, columns %d-%d, variable declaration expr '%s':", config, item->startline, item->startcol, item->endcol, item->u2.val);
2207 cw_expr_register_extra_error_info(errmsg);
2208 cw_expr(NULL, item->u2.val, &expr_output);
2209 cw_expr_clear_extra_error_info();
22102196 if ( strpbrk(item->u2.val,"~!-+<>=*/&^") && !strstr(item->u2.val,"${") ) {
22112197 cw_log(CW_LOG_WARNING,"Warning: file %s, line %d-%d: expression %s has operators, but no variables. Interesting...\n",
22122198 item->filename, item->startline, item->endline, item->u2.val);
------
22442230
22452231 item->u4.for_statements == a struct pval list of statements in the for ()
22462232 */
2247 snprintf(errmsg,sizeof(errmsg),"file %s, line %d, columns %d-%d, for test expr '%s':", config, item->startline, item->startcol, item->endcol, item->u2.for_test);
2248 cw_expr_register_extra_error_info(errmsg);
2249
2250 strp = strchr(item->u1.for_init, '=');
2251 if (strp) {
2252 cw_expr(NULL, strp+1, &expr_output);
2253 }
2254 cw_expr(NULL, item->u2.for_test, &expr_output);
2255 strp = strchr(item->u3.for_inc, '=');
2256 if (strp) {
2257 cw_expr(NULL, strp+1, &expr_output);
2258 }
22592233 if ( strpbrk(item->u2.for_test,"~!-+<>=*/&^") && !strstr(item->u2.for_test,"${") ) {
22602234 cw_log(CW_LOG_WARNING,"Warning: file %s, line %d-%d: expression %s has operators, but no variables. Interesting...\n",
22612235 item->filename, item->startline, item->endline, item->u2.for_test);
------
22692243 check_expr2_input(item,item->u2.for_test);
22702244 check_expr2_input(item,item->u3.for_inc);
22712245
2272 cw_expr_clear_extra_error_info();
22732246 check_pval(item->u4.for_statements, apps,in_globals);
22742247 break;
22752248
------
22782251
22792252 item->u2.statements == a struct pval list of statements in the while ()
22802253 */
2281 snprintf(errmsg,sizeof(errmsg),"file %s, line %d, columns %d-%d, while expr '%s':", config, item->startline, item->startcol, item->endcol, item->u1.str);
2282 cw_expr_register_extra_error_info(errmsg);
2283 cw_expr(NULL, item->u1.str, &expr_output);
2284 cw_expr_clear_extra_error_info();
22852254 if ( strpbrk(item->u1.str,"~!-+<>=*/&^") && !strstr(item->u1.str,"${") ) {
22862255 cw_log(CW_LOG_WARNING,"Warning: file %s, line %d-%d: expression %s has operators, but no variables. Interesting...\n",
22872256 item->filename, item->startline, item->endline, item->u1.str);
------
23132282 item->u3.else_statements == a struct pval list of statements in the else
23142283 (could be zero)
23152284 */
2316 snprintf(errmsg,sizeof(errmsg),"file %s, line %d, columns %d-%d, random expr '%s':", config, item->startline, item->startcol, item->endcol, item->u1.str);
2317 cw_expr_register_extra_error_info(errmsg);
2318 cw_expr(NULL, item->u1.str, &expr_output);
2319 cw_expr_clear_extra_error_info();
23202285 if ( strpbrk(item->u1.str,"~!-+<>=*/&^") && !strstr(item->u1.str,"${") ) {
23212286 cw_log(CW_LOG_WARNING,"Warning: file %s, line %d-%d: random expression '%s' has operators, but no variables. Interesting...\n",
23222287 item->filename, item->startline, item->endline, item->u1.str);
------
23562321 item->u3.else_statements == a struct pval list of statements in the else
23572322 (could be zero)
23582323 */
2359 snprintf(errmsg,sizeof(errmsg),"file %s, line %d, columns %d-%d, if expr '%s':", config, item->startline, item->startcol, item->endcol, item->u1.str);
2360 cw_expr_register_extra_error_info(errmsg);
2361 cw_expr(NULL, item->u1.str, &expr_output);
2362 cw_expr_clear_extra_error_info();
23632324 if ( strpbrk(item->u1.str,"~!-+<>=*/&^") && !strstr(item->u1.str,"${") ) {
23642325 cw_log(CW_LOG_WARNING,"Warning: file %s, line %d-%d: expression '%s' has operators, but no variables. Interesting...\n",
23652326 item->filename, item->startline, item->endline, item->u1.str);
------
24102371 default:
24112372 break;
24122373 }
2413
2414 cw_dynstr_reset(&expr_output);
24152374 }
24162375
24172376 void check_pval(struct pval *item, struct argapp *apps, int in_globals)