#define DEBUG_MACROS (1 << 2)
#define DEBUG_CONTEXTS (1 << 3)
+#define BUF_SIZE 2000
+
static char *config = "extensions.ael";
static char *registrar = "pbx_ael";
static int pbx_load_module(void);
struct ael_priority *loop_continue_save;
struct ael_extension *switch_case,*switch_null;
- if (!(buf1 = malloc(2000))) {
+ if (!(buf1 = malloc(BUF_SIZE))) {
return -1;
}
- if (!(buf2 = malloc(2000))) {
+ if (!(buf2 = malloc(BUF_SIZE))) {
return -1;
}
- if (!(new_label = malloc(2000))) {
+ if (!(new_label = malloc(BUF_SIZE))) {
return -1;
}
case PV_VARDEC:
pr = new_prio();
pr->type = AEL_APPCALL;
- snprintf(buf1,sizeof(buf1),"%s=$[%s]", p->u1.str, p->u2.val);
+ snprintf(buf1, BUF_SIZE, "%s=$[%s]", p->u1.str, p->u2.val);
pr->app = strdup("Set");
remove_spaces_before_equals(buf1);
pr->appargs = strdup(buf1);
if (!mother_exten)
pr->appargs = strdup(p->u1.list->u1.str);
else { /* for the case of simple within-extension gotos in case/pattern/default statement blocks: */
- snprintf(buf1,sizeof(buf1),"%s|%s", mother_exten->name, p->u1.list->u1.str);
+ snprintf(buf1, BUF_SIZE, "%s|%s", mother_exten->name, p->u1.list->u1.str);
pr->appargs = strdup(buf1);
}
} else if (p->u1.list->next && !p->u1.list->next->next) /* two */ {
- snprintf(buf1,sizeof(buf1),"%s|%s", p->u1.list->u1.str, p->u1.list->next->u1.str);
+ snprintf(buf1, BUF_SIZE, "%s|%s", p->u1.list->u1.str, p->u1.list->next->u1.str);
pr->app = strdup("Goto");
pr->appargs = strdup(buf1);
} else if (p->u1.list->next && p->u1.list->next->next) {
- snprintf(buf1,sizeof(buf1),"%s|%s|%s", p->u1.list->u1.str,
+ snprintf(buf1, BUF_SIZE, "%s|%s|%s", p->u1.list->u1.str,
p->u1.list->next->u1.str,
p->u1.list->next->next->u1.str);
pr->app = strdup("Goto");
control_statement_count++;
loop_break_save = exten->loop_break; /* save them, then restore before leaving */
loop_continue_save = exten->loop_continue;
- snprintf(new_label,sizeof(new_label),"for-%s-%d", label, control_statement_count);
+ snprintf(new_label, BUF_SIZE, "for-%s-%d", label, control_statement_count);
for_init = new_prio();
for_inc = new_prio();
for_test = new_prio();
strp2 = strchr(p->u1.for_init, '=');
*(strp+1) = 0;
strcat(buf2,"$[");
- strncat(buf2,strp2+1, sizeof(buf2)-strlen(strp2+1)-2);
+ strncat(buf2,strp2+1, BUF_SIZE-strlen(strp2+1)-2);
strcat(buf2,"]");
for_init->appargs = strdup(buf2);
/* for_init->app = strdup("Set"); just set! */
strp2 = strchr(p->u3.for_inc, '=');
*(strp+1) = 0;
strcat(buf2,"$[");
- strncat(buf2,strp2+1, sizeof(buf2)-strlen(strp2+1)-2);
+ strncat(buf2,strp2+1, BUF_SIZE-strlen(strp2+1)-2);
strcat(buf2,"]");
for_inc->appargs = strdup(buf2);
for_inc->app = strdup("Set");
}
}
}
- snprintf(buf1,sizeof(buf1),"$[%s]",p->u2.for_test);
+ snprintf(buf1, BUF_SIZE, "$[%s]",p->u2.for_test);
for_test->app = 0;
for_test->appargs = strdup(buf1);
for_loop->goto_true = for_test;
- snprintf(buf1,sizeof(buf1),"Finish for-%s-%d", label, control_statement_count);
+ snprintf(buf1, BUF_SIZE, "Finish for-%s-%d", label, control_statement_count);
for_end->app = strdup("NoOp");
for_end->appargs = strdup(buf1);
/* link & load! */
control_statement_count++;
loop_break_save = exten->loop_break; /* save them, then restore before leaving */
loop_continue_save = exten->loop_continue;
- snprintf(new_label,sizeof(new_label),"while-%s-%d", label, control_statement_count);
+ snprintf(new_label, BUF_SIZE, "while-%s-%d", label, control_statement_count);
while_test = new_prio();
while_loop = new_prio();
while_end = new_prio();
while_test->goto_false = while_end;
while_loop->type = AEL_CONTROL1; /* simple goto */
while_end->type = AEL_APPCALL;
- snprintf(buf1,sizeof(buf1),"$[%s]",p->u1.str);
+ snprintf(buf1, BUF_SIZE, "$[%s]",p->u1.str);
while_test->app = 0;
while_test->appargs = strdup(buf1);
while_loop->goto_true = while_test;
- snprintf(buf1,sizeof(buf1),"Finish while-%s-%d", label, control_statement_count);
+ snprintf(buf1, BUF_SIZE, "Finish while-%s-%d", label, control_statement_count);
while_end->app = strdup("NoOp");
while_end->appargs = strdup(buf1);
local_control_statement_count = control_statement_count;
loop_break_save = exten->loop_break; /* save them, then restore before leaving */
loop_continue_save = exten->loop_continue;
- snprintf(new_label,sizeof(new_label),"sw-%s-%d", label, control_statement_count);
+ snprintf(new_label, BUF_SIZE, "sw-%s-%d", label, control_statement_count);
switch_test = new_prio();
switch_end = new_prio();
switch_test->type = AEL_APPCALL;
switch_end->type = AEL_APPCALL;
- strncpy(buf2,p->u1.str,sizeof(buf2));
- buf2[sizeof(buf2)-1] = 0; /* just in case */
+ strncpy(buf2, p->u1.str, BUF_SIZE);
+ buf2[BUF_SIZE-1] = 0; /* just in case */
substitute_commas(buf2);
- snprintf(buf1,sizeof(buf1),"sw-%d-%s|10",control_statement_count, buf2);
+ snprintf(buf1, BUF_SIZE, "sw-%d-%s|10",control_statement_count, buf2);
switch_test->app = strdup("Goto");
switch_test->appargs = strdup(buf1);
- snprintf(buf1,sizeof(buf1),"Finish switch-%s-%d", label, control_statement_count);
+ snprintf(buf1, BUF_SIZE, "Finish switch-%s-%d", label, control_statement_count);
switch_end->app = strdup("NoOp");
switch_end->appargs = strdup(buf1);
switch_end->origin = p;
switch_case->loop_continue = exten->loop_continue;
linkexten(exten,switch_case);
- strncpy(buf2,p2->u1.str,sizeof(buf2));
- buf2[sizeof(buf2)-1] = 0; /* just in case */
+ strncpy(buf2,p2->u1.str, BUF_SIZE);
+ buf2[BUF_SIZE-1] = 0; /* just in case */
substitute_commas(buf2);
- snprintf(buf1,sizeof(buf1),"sw-%d-%s", local_control_statement_count, buf2);
+ snprintf(buf1, BUF_SIZE, "sw-%d-%s", local_control_statement_count, buf2);
switch_case->name = strdup(buf1);
- snprintf(new_label,sizeof(new_label),"sw-%s-%s-%d", label, buf2, local_control_statement_count);
+ snprintf(new_label, BUF_SIZE, "sw-%s-%s-%d", label, buf2, local_control_statement_count);
if (gen_prios(switch_case, new_label, p2->u2.statements, exten, this_context)) { /* this will link in all the case body statements here */
return -1;
fall_thru = new_prio();
fall_thru->type = AEL_APPCALL;
fall_thru->app = strdup("Goto");
- strncpy(buf2,p2->next->u1.str,sizeof(buf2));
- buf2[sizeof(buf2)-1] = 0; /* just in case */
+ strncpy(buf2, p2->next->u1.str, BUF_SIZE);
+ buf2[BUF_SIZE-1] = 0; /* just in case */
substitute_commas(buf2);
- snprintf(buf1,sizeof(buf1),"sw-%d-%s|10",local_control_statement_count, buf2);
+ snprintf(buf1, BUF_SIZE, "sw-%d-%s|10", local_control_statement_count, buf2);
fall_thru->appargs = strdup(buf1);
linkprio(switch_case, fall_thru, mother_exten);
} else if (p2->next && p2->next->type == PV_PATTERN) {
fall_thru->app = strdup("Goto");
gen_match_to_pattern(p2->next->u1.str, buf2);
substitute_commas(buf2);
- snprintf(buf1,sizeof(buf1),"sw-%d-%s|10", local_control_statement_count, buf2);
+ snprintf(buf1, BUF_SIZE, "sw-%d-%s|10", local_control_statement_count, buf2);
fall_thru->appargs = strdup(buf1);
linkprio(switch_case, fall_thru, mother_exten);
} else if (p2->next && p2->next->type == PV_DEFAULT) {
fall_thru = new_prio();
fall_thru->type = AEL_APPCALL;
fall_thru->app = strdup("Goto");
- snprintf(buf1,sizeof(buf1),"sw-%d-.|10",local_control_statement_count);
+ snprintf(buf1, BUF_SIZE, "sw-%d-.|10",local_control_statement_count);
fall_thru->appargs = strdup(buf1);
linkprio(switch_case, fall_thru, mother_exten);
} else if (!p2->next) {
struct ael_priority *np2 = new_prio();
np2->type = AEL_APPCALL;
np2->app = strdup("NoOp");
- snprintf(buf,sizeof(buf),"End of Extension %s", switch_case->name);
+ snprintf(buf, BUF_SIZE, "End of Extension %s", switch_case->name);
np2->appargs = strdup(buf);
linkprio(switch_case, np2, mother_exten);
switch_case-> return_target = np2;
switch_case->loop_continue = exten->loop_continue;
linkexten(exten,switch_case);
- strncpy(buf2,p2->u1.str,sizeof(buf2));
- buf2[sizeof(buf2)-1] = 0; /* just in case */
+ strncpy(buf2, p2->u1.str, BUF_SIZE);
+ buf2[BUF_SIZE-1] = 0; /* just in case */
substitute_commas(buf2);
- snprintf(buf1,sizeof(buf1),"_sw-%d-%s", local_control_statement_count, buf2);
+ snprintf(buf1, BUF_SIZE, "_sw-%d-%s", local_control_statement_count, buf2);
switch_case->name = strdup(buf1);
- snprintf(new_label,sizeof(new_label),"sw-%s-%s-%d", label, buf2, local_control_statement_count);
+ snprintf(new_label, BUF_SIZE, "sw-%s-%s-%d", label, buf2, local_control_statement_count);
if (gen_prios(switch_case, new_label, p2->u2.statements, exten, this_context)) { /* this will link in all the while body statements here */
return -1;
fall_thru = new_prio();
fall_thru->type = AEL_APPCALL;
fall_thru->app = strdup("Goto");
- strncpy(buf2,p2->next->u1.str,sizeof(buf2));
- buf2[sizeof(buf2)-1] = 0; /* just in case */
+ strncpy(buf2, p2->next->u1.str, BUF_SIZE);
+ buf2[BUF_SIZE-1] = 0; /* just in case */
substitute_commas(buf2);
- snprintf(buf1,sizeof(buf1),"sw-%d-%s|10",local_control_statement_count, buf2);
+ snprintf(buf1, BUF_SIZE, "sw-%d-%s|10", local_control_statement_count, buf2);
fall_thru->appargs = strdup(buf1);
linkprio(switch_case, fall_thru, mother_exten);
} else if (p2->next && p2->next->type == PV_PATTERN) {
fall_thru->app = strdup("Goto");
gen_match_to_pattern(p2->next->u1.str, buf2);
substitute_commas(buf2);
- snprintf(buf1,sizeof(buf1),"sw-%d-%s|10",local_control_statement_count, buf2);
+ snprintf(buf1, BUF_SIZE, "sw-%d-%s|10", local_control_statement_count, buf2);
fall_thru->appargs = strdup(buf1);
linkprio(switch_case, fall_thru, mother_exten);
} else if (p2->next && p2->next->type == PV_DEFAULT) {
fall_thru = new_prio();
fall_thru->type = AEL_APPCALL;
fall_thru->app = strdup("Goto");
- snprintf(buf1,sizeof(buf1),"sw-%d-.|10",local_control_statement_count);
+ snprintf(buf1, BUF_SIZE, "sw-%d-.|10", local_control_statement_count);
fall_thru->appargs = strdup(buf1);
linkprio(switch_case, fall_thru, mother_exten);
} else if (!p2->next) {
switch_null->context = this_context;
switch_null->is_switch = 1;
switch_empty = new_prio();
- snprintf(buf1,sizeof(buf1),"sw-%d-.|10",local_control_statement_count);
+ snprintf(buf1, BUF_SIZE, "sw-%d-.|10", local_control_statement_count);
switch_empty->app = strdup("Goto");
switch_empty->appargs = strdup(buf1);
linkprio(switch_null, switch_empty, mother_exten);
- snprintf(buf1,sizeof(buf1),"sw-%d-", local_control_statement_count);
+ snprintf(buf1, BUF_SIZE, "sw-%d-", local_control_statement_count);
switch_null->name = strdup(buf1);
switch_null->loop_break = exten->loop_break;
switch_null->loop_continue = exten->loop_continue;
switch_case->loop_break = exten->loop_break;
switch_case->loop_continue = exten->loop_continue;
linkexten(exten,switch_case);
- snprintf(buf1,sizeof(buf1),"_sw-%d-.", local_control_statement_count);
+ snprintf(buf1, BUF_SIZE, "_sw-%d-.", local_control_statement_count);
switch_case->name = strdup(buf1);
- snprintf(new_label,sizeof(new_label),"sw-%s-default-%d", label, local_control_statement_count);
+ snprintf(new_label, BUF_SIZE, "sw-%s-default-%d", label, local_control_statement_count);
if (gen_prios(switch_case, new_label, p2->u2.statements, exten, this_context)) { /* this will link in all the default: body statements here */
return -1;
fall_thru = new_prio();
fall_thru->type = AEL_APPCALL;
fall_thru->app = strdup("Goto");
- strncpy(buf2,p2->next->u1.str,sizeof(buf2));
- buf2[sizeof(buf2)-1] = 0; /* just in case */
+ strncpy(buf2, p2->next->u1.str, BUF_SIZE);
+ buf2[BUF_SIZE-1] = 0; /* just in case */
substitute_commas(buf2);
- snprintf(buf1,sizeof(buf1),"sw-%d-%s|10",local_control_statement_count, buf2);
+ snprintf(buf1, BUF_SIZE, "sw-%d-%s|10", local_control_statement_count, buf2);
fall_thru->appargs = strdup(buf1);
linkprio(switch_case, fall_thru, mother_exten);
} else if (p2->next && p2->next->type == PV_PATTERN) {
fall_thru->app = strdup("Goto");
gen_match_to_pattern(p2->next->u1.str, buf2);
substitute_commas(buf2);
- snprintf(buf1,sizeof(buf1),"sw-%d-%s|10",local_control_statement_count, buf2);
+ snprintf(buf1, BUF_SIZE, "sw-%d-%s|10", local_control_statement_count, buf2);
fall_thru->appargs = strdup(buf1);
linkprio(switch_case, fall_thru, mother_exten);
} else if (p2->next && p2->next->type == PV_DEFAULT) {
fall_thru = new_prio();
fall_thru->type = AEL_APPCALL;
fall_thru->app = strdup("Goto");
- snprintf(buf1,sizeof(buf1),"sw-%d-.|10",local_control_statement_count);
+ snprintf(buf1, BUF_SIZE, "sw-%d-.|10", local_control_statement_count);
fall_thru->appargs = strdup(buf1);
linkprio(switch_case, fall_thru, mother_exten);
} else if (!p2->next) {
case PV_MACRO_CALL:
pr = new_prio();
pr->type = AEL_APPCALL;
- snprintf(buf1,sizeof(buf1),"%s", p->u1.str);
+ snprintf(buf1, BUF_SIZE, "%s", p->u1.str);
for (p2 = p->u2.arglist; p2; p2 = p2->next) {
strcat(buf1,"|");
strcat(buf1,p2->u1.str);
#ifdef OLD_RAND_ACTION
case PV_RANDOM:
control_statement_count++;
- snprintf(new_label,sizeof(new_label),"rand-%s-%d", label, control_statement_count);
+ snprintf(new_label, BUF_SIZE, "rand-%s-%d", label, control_statement_count);
rand_test = new_prio();
rand_test->type = AEL_RAND_CONTROL;
- snprintf(buf1,sizeof(buf1),"$[%s]",
+ snprintf(buf1, BUF_SIZE, "$[%s]",
p->u1.str );
rand_test->app = 0;
rand_test->appargs = strdup(buf1);
rand_end = new_prio();
rand_end->type = AEL_APPCALL;
- snprintf(buf1,sizeof(buf1),"Finish rand-%s-%d", label, control_statement_count);
+ snprintf(buf1, BUF_SIZE, "Finish rand-%s-%d", label, control_statement_count);
rand_end->app = strdup("NoOp");
rand_end->appargs = strdup(buf1);
case PV_IFTIME:
control_statement_count++;
- snprintf(new_label,sizeof(new_label),"iftime-%s-%d", label, control_statement_count);
+ snprintf(new_label, BUF_SIZE, "iftime-%s-%d", label, control_statement_count);
if_test = new_prio();
if_test->type = AEL_IFTIME_CONTROL;
- snprintf(buf1,sizeof(buf1),"%s|%s|%s|%s",
+ snprintf(buf1, BUF_SIZE, "%s|%s|%s|%s",
p->u1.list->u1.str,
p->u1.list->next->u1.str,
p->u1.list->next->next->u1.str,
if_end = new_prio();
if_end->type = AEL_APPCALL;
- snprintf(buf1,sizeof(buf1),"Finish iftime-%s-%d", label, control_statement_count);
+ snprintf(buf1, BUF_SIZE, "Finish iftime-%s-%d", label, control_statement_count);
if_end->app = strdup("NoOp");
if_end->appargs = strdup(buf1);
case PV_RANDOM:
case PV_IF:
control_statement_count++;
- snprintf(new_label,sizeof(new_label),"if-%s-%d", label, control_statement_count);
+ snprintf(new_label, BUF_SIZE, "if-%s-%d", label, control_statement_count);
if_test = new_prio();
if_end = new_prio();
if_test->type = AEL_IF_CONTROL;
if_end->type = AEL_APPCALL;
if ( p->type == PV_RANDOM )
- snprintf(buf1,sizeof(buf1),"$[${RAND(0|99)} < (%s)]",p->u1.str);
+ snprintf(buf1, BUF_SIZE, "$[${RAND(0|99)} < (%s)]", p->u1.str);
else {
char buf[8000];
strcpy(buf,p->u1.str);
substitute_commas(buf);
- snprintf(buf1,sizeof(buf1),"$[%s]",buf);
+ snprintf(buf1, BUF_SIZE, "$[%s]",buf);
}
if_test->app = 0;
if_test->appargs = strdup(buf1);
- snprintf(buf1,sizeof(buf1),"Finish if-%s-%d", label, control_statement_count);
+ snprintf(buf1, BUF_SIZE, "Finish if-%s-%d", label, control_statement_count);
if_end->app = strdup("NoOp");
if_end->appargs = strdup(buf1);
if_test->origin = p;
switch_case->context = this_context;
linkexten(exten,switch_case);
switch_case->name = strdup(p->u1.str);
- snprintf(new_label,sizeof(new_label),"catch-%s-%d",p->u1.str, control_statement_count);
+ snprintf(new_label, BUF_SIZE, "catch-%s-%d",p->u1.str, control_statement_count);
if (gen_prios(switch_case, new_label, p->u2.statements,mother_exten,this_context)) { /* this will link in all the catch body statements here */
return -1;