?? pval.c
字號:
/* Check for all days */ if (ast_strlen_zero(dow) || !strcmp(dow, "*")) return; /* Get start and ending days */ c = strchr(dow, '-'); if (c) { *c = '\0'; c++; } else c = NULL; /* Find the start */ s = 0; while ((s < 7) && strcasecmp(dow, days[s])) s++; if (s >= 7) { ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The day (%s) must be one of 'sun', 'mon', 'tue', 'wed', 'thu', 'fri', or 'sat'!\n", DOW->filename, DOW->startline, DOW->endline, dow); warns++; } if (c) { e = 0; while ((e < 7) && strcasecmp(c, days[e])) e++; if (e >= 7) { ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The end day (%s) must be one of 'sun', 'mon', 'tue', 'wed', 'thu', 'fri', or 'sat'!\n", DOW->filename, DOW->startline, DOW->endline, c); warns++; } } else e = s;}static void check_day(pval *DAY){ char *day; char *c; /* The following line is coincidence, really! */ int s, e; day = ast_strdupa(DAY->u1.str); /* Check for all days */ if (ast_strlen_zero(day) || !strcmp(day, "*")) { return; } /* Get start and ending days */ c = strchr(day, '-'); if (c) { *c = '\0'; c++; } /* Find the start */ if (sscanf(day, "%d", &s) != 1) { ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The start day of month (%s) must be a number!\n", DAY->filename, DAY->startline, DAY->endline, day); warns++; } else if ((s < 1) || (s > 31)) { ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The start day of month (%s) must be a number in the range [1-31]!\n", DAY->filename, DAY->startline, DAY->endline, day); warns++; } s--; if (c) { if (sscanf(c, "%d", &e) != 1) { ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The end day of month (%s) must be a number!\n", DAY->filename, DAY->startline, DAY->endline, c); warns++; } else if ((e < 1) || (e > 31)) { ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The end day of month (%s) must be a number in the range [1-31]!\n", DAY->filename, DAY->startline, DAY->endline, day); warns++; } e--; } else e = s;}static char *months[] ={ "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec",};static void check_month(pval *MON){ char *mon; char *c; /* The following line is coincidence, really! */ int s, e; mon = ast_strdupa(MON->u1.str); /* Check for all days */ if (ast_strlen_zero(mon) || !strcmp(mon, "*")) return ; /* Get start and ending days */ c = strchr(mon, '-'); if (c) { *c = '\0'; c++; } /* Find the start */ s = 0; while ((s < 12) && strcasecmp(mon, months[s])) s++; if (s >= 12) { ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The start month (%s) must be a one of: 'jan', 'feb', ..., 'dec'!\n", MON->filename, MON->startline, MON->endline, mon); warns++; } if (c) { e = 0; while ((e < 12) && strcasecmp(mon, months[e])) e++; if (e >= 12) { ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: The end month (%s) must be a one of: 'jan', 'feb', ..., 'dec'!\n", MON->filename, MON->startline, MON->endline, c); warns++; } } else e = s;}static int check_break(pval *item){ pval *p = item; while( p && p->type != PV_MACRO && p->type != PV_CONTEXT ) /* early cutout, sort of */ { /* a break is allowed in WHILE, FOR, CASE, DEFAULT, PATTERN; otherwise, it don't make no sense */ if( p->type == PV_CASE || p->type == PV_DEFAULT || p->type == PV_PATTERN || p->type == PV_WHILE || p->type == PV_FOR ) { return 1; } p = p->dad; } ast_log(LOG_ERROR,"Error: file %s, line %d-%d: 'break' not in switch, for, or while statement!\n", item->filename, item->startline, item->endline); errs++; return 0;}static int check_continue(pval *item){ pval *p = item; while( p && p->type != PV_MACRO && p->type != PV_CONTEXT ) /* early cutout, sort of */ { /* a break is allowed in WHILE, FOR, CASE, DEFAULT, PATTERN; otherwise, it don't make no sense */ if( p->type == PV_WHILE || p->type == PV_FOR ) { return 1; } p = p->dad; } ast_log(LOG_ERROR,"Error: file %s, line %d-%d: 'continue' not in 'for' or 'while' statement!\n", item->filename, item->startline, item->endline); errs++; return 0;}static struct pval *in_macro(pval *item){ struct pval *curr; curr = item; while( curr ) { if( curr->type == PV_MACRO ) { return curr; } curr = curr->dad; } return 0;}static struct pval *in_context(pval *item){ struct pval *curr; curr = item; while( curr ) { if( curr->type == PV_MACRO || curr->type == PV_CONTEXT ) { return curr; } curr = curr->dad; } return 0;}/* general purpose goto finder */static void check_label(pval *item){ struct pval *curr; struct pval *x; int alright = 0; /* A label outside an extension just plain does not make sense! */ curr = item; while( curr ) { if( curr->type == PV_MACRO || curr->type == PV_EXTENSION ) { alright = 1; break; } curr = curr->dad; } if( !alright ) { ast_log(LOG_ERROR,"Error: file %s, line %d-%d: Label %s is not within an extension or macro!\n", item->filename, item->startline, item->endline, item->u1.str); errs++; } /* basically, ensure that a label is not repeated in a context. Period. The method: well, for each label, find the first label in the context with the same name. If it's not the current label, then throw an error. */ /* printf("==== check_label: ====\n"); */ if( !current_extension ) curr = current_context; else curr = current_extension; x = find_first_label_in_current_context((char *)item->u1.str, curr); /* printf("Hey, check_label found with item = %x, and x is %x, and currcont is %x, label name is %s\n", item,x, current_context, (char *)item->u1.str); */ if( x && x != item ) { ast_log(LOG_ERROR,"Error: file %s, line %d-%d: Duplicate label %s! Previously defined at file %s, line %d.\n", item->filename, item->startline, item->endline, item->u1.str, x->filename, x->startline); errs++; } /* printf("<<<<< check_label: ====\n"); */}static pval *get_goto_target(pval *item){ /* just one item-- the label should be in the current extension */ pval *curr_ext = get_extension_or_contxt(item); /* containing exten, or macro */ pval *curr_cont; if (item->u1.list && !item->u1.list->next && !strstr((item->u1.list)->u1.str,"${")) { struct pval *x = find_label_in_current_extension((char*)((item->u1.list)->u1.str), curr_ext); return x; } curr_cont = get_contxt(item); /* TWO items */ if (item->u1.list->next && !item->u1.list->next->next) { if (!strstr((item->u1.list)->u1.str,"${") && !strstr(item->u1.list->next->u1.str,"${") ) /* Don't try to match variables */ { struct pval *x = find_label_in_current_context((char *)item->u1.list->u1.str, (char *)item->u1.list->next->u1.str, curr_cont); return x; } } /* All 3 items! */ if (item->u1.list->next && item->u1.list->next->next) { /* all three */ pval *first = item->u1.list; pval *second = item->u1.list->next; pval *third = item->u1.list->next->next; if (!strstr((item->u1.list)->u1.str,"${") && !strstr(item->u1.list->next->u1.str,"${") && !strstr(item->u1.list->next->next->u1.str,"${")) /* Don't try to match variables */ { struct pval *x = find_label_in_current_db((char*)first->u1.str, (char*)second->u1.str, (char*)third->u1.str); if (!x) { struct pval *p3; struct pval *that_context = find_context(item->u1.list->u1.str); /* the target of the goto could be in an included context!! Fancy that!! */ /* look for includes in the current context */ if (that_context) { for (p3=that_context->u2.statements; p3; p3=p3->next) { if (p3->type == PV_INCLUDES) { struct pval *p4; for (p4=p3->u1.list; p4; p4=p4->next) { /* for each context pointed to, find it, then find a context/label that matches the target here! */ char *incl_context = p4->u1.str; /* find a matching context name */ struct pval *that_other_context = find_context(incl_context); if (that_other_context) { struct pval *x3; x3 = find_label_in_current_context((char *)item->u1.list->next->u1.str, (char *)item->u1.list->next->next->u1.str, that_other_context); if (x3) { return x3; } } } } } } } return x; } } return 0;}static void check_goto(pval *item){ /* check for the target of the goto-- does it exist? */ if ( !(item->u1.list)->next && !(item->u1.list)->u1.str ) { ast_log(LOG_ERROR,"Error: file %s, line %d-%d: goto: empty label reference found!\n", item->filename, item->startline, item->endline); errs++; } /* just one item-- the label should be in the current extension */ if (item->u1.list && !item->u1.list->next && !strstr((item->u1.list)->u1.str,"${")) { struct pval *z = get_extension_or_contxt(item); struct pval *x = 0; if (z) x = find_label_in_current_extension((char*)((item->u1.list)->u1.str), z); /* if in macro, use current context instead */ /* printf("Called find_label_in_current_extension with arg %s; current_extension is %x: %d\n", (char*)((item->u1.list)->u1.str), current_extension?current_extension:current_context, current_extension?current_extension->type:current_context->type); */ if (!x) { ast_log(LOG_ERROR,"Error: file %s, line %d-%d: goto: no label %s exists in the current extension!\n", item->filename, item->startline, item->endline, item->u1.list->u1.str); errs++; } else return; } /* TWO items */ if (item->u1.list->next && !item->u1.list->next->next) { /* two items */ /* printf("Calling find_label_in_current_context with args %s, %s\n", (char*)((item->u1.list)->u1.str), (char *)item->u1.list->next->u1.str); */ if (!strstr((item->u1.list)->u1.str,"${") && !strstr(item->u1.list->next->u1.str,"${") ) /* Don't try to match variables */ { struct pval *z = get_contxt(item); struct pval *x = 0; if (z) x = find_label_in_current_context((char *)item->u1.list->u1.str, (char *)item->u1.list->next->u1.str, z); if (!x) { ast_log(LOG_ERROR,"Error: file %s, line %d-%d: goto: no label '%s,%s' exists in the current context, or any of its inclusions!\n", item->filename, item->startline, item->endline, item->u1.list->u1.str, item->u1.list->next->u1.str ); errs++; } else return; } } /* All 3 items! */ if (item->u1.list->next && item->u1.list->next->next) { /* all three */ pval *first = item->u1.list; pval *second = item->u1.list->next; pval *third = item->u1.list->next->next; /* printf("Calling find_label_in_current_db with args %s, %s, %s\n", (char*)first->u1.str, (char*)second->u1.str, (char*)third->u1.str); */ if (!strstr((item->u1.list)->u1.str,"${") && !strstr(item->u1.list->next->u1.str,"${") && !strstr(item->u1.list->next->next->u1.str,"${")) /* Don't try to match variables */ { struct pval *x = find_label_in_current_db((char*)first->u1.str, (char*)second->u1.str, (char*)third->u1.str); if (!x) { struct pval *p3; struct pval *found = 0; struct pval *that_context = find_context(item->u1.list->u1.str); /* the target of the goto could be in an included context!! Fancy that!! */ /* look for includes in the current context */ if (that_context) { for (p3=that_context->u2.statements; p3; p3=p3->next) { if (p3->type == PV_INCLUDES) { struct pval *p4; for (p4=p3->u1.list; p4; p4=p4->next) { /* for each context pointed to, find it, then find a context/label that matches the target here! */ char *incl_context = p4->u1.str; /* find a matching context name */ struct pval *that_other_context = find_context(incl_context); if (that_other_context) { struct pval *x3; x3 = find_label_in_current_context((char *)item->u1.list->next->u1.str, (char *)item->u1.list->next->next->u1.str, that_other_context); if (x3) { found = x3; break; } } } } } if (!found) { ast_log(LOG_ERROR,"Error: file %s, line %d-%d: goto: no label %s|%s exists in the context %s or its inclusions!\n", item->filename, item->startline, item->endline, item->u1.list->next->u1.str, item->u1.list->next->next->u1.str, item->u1.list->u1.str ); errs++; } else { struct pval *mac = in_macro(item); /* is this goto inside a macro? */ if( mac ) { /* yes! */ struct pval *targ = in_context(found); if( mac != targ ) { ast_log(LOG_WARNING, "Warning: file %s, line %d-%d: It's bad form to have a goto in a macro to a target outside the macro!\n", item->filename, item->startline, item->endline); warns++; } } } } else { /* here is where code would go to check for target existence in extensions.conf files */#ifdef STANDALONE struct pbx_find_info pfiq = {.stacklen = 0 }; extern int localized_pbx_load_module(void); /* if this is a standalone, we will need to make sure the localized load of extensions.conf is done */ if (!extensions_dot_conf_loaded) { localized_pbx_load_module(); extensions_dot_conf_loaded++; } pbx_find_extension(NULL, NULL, &pfiq, first->u1.str, second->u1.str, atoi(third->u1.str), atoi(third->u1.str) ? NULL : third->u1.str, NULL, atoi(third->u1.str) ? E_MATCH : E_FINDLABEL); if (pfiq.status != STATUS_SUCCESS) { ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: goto: Couldn't find goto target %s|%s|%s, not even in extensions.conf!\n", item->filename, item->startline, item->endline, first->u1.str, second->u1.str, third->u1.str); warns++; }#else ast_log(LOG_WARNING,"Warning: file %s, line %d-%d: goto: Couldn't find goto target %s|%s|%s in the AEL code!\n", item->filename, item->startline, item->endline, first->u1.str, second->u1.str, third->u1.str); warns++;#endif } } else { struct pval *mac = in_macro(item); /* is this goto inside a macro? */ if( mac ) { /* yes! */ struct pval *targ = in_context(x); if( mac != targ ) {
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -