/* * Convert a single threshold string or paren groups of thresh's as * described below. All thresh's are saved to an allocated list at * *vlistp; the caller will need to free that space. On return: * *vcntp is the count of the vlist array, and vlist is either * a single thresh or N groups of thresh's with a trailing zero: * (cnt_1 thr_1a thr_1b [...]) ... (cnt_N thr_Na thr_Nb [...]) 0. * Returns 0 when all conversions were OK, and 1 for any syntax, * conversion, or alloc error. */ static int get_thresh(int **vlistp, int *vcntp) { int argn, value, gci = 0, grp_cnt = 0, paren = 0, nerr = 0; char *rp, *src; for (argn = 2; (src = LINEARG(argn)) != NULL; argn++) { if (*src == LPAREN) { gci = *vcntp; if ((nerr = vlist_append(vlistp, vcntp, 0)) != 0) break; paren = 1; src++; } if (*(rp = LASTBYTE(src)) == RPAREN) { if (paren) { grp_cnt = *vcntp - gci; *(*vlistp + gci) = grp_cnt; paren = 0; *rp = '\0'; } else { nerr = 1; break; } } value = get_scaled_value(src, &nerr); if (nerr || (nerr = vlist_append(vlistp, vcntp, value))) break; } if (nerr == 0 && grp_cnt) nerr = vlist_append(vlistp, vcntp, 0); return (nerr); }
static var_t * exp_eval_list(exp_t *exp, var_t *mailspec) { ll_t *exp_list = exp->ex_data; ll_entry_t *pos; exp_t *exp_item; var_t *var_item, *var_list = NULL; var_list = vlist_create(NULL, VF_EXP_FREE); if (var_list == NULL) { log_sys_error("exp_eval_list: malloc"); goto error; } pos = LL_START(exp_list); while ((exp_item = ll_next(exp_list, &pos))) { var_item = exp_eval(exp_item, mailspec); if (vlist_append(var_list, var_item)) { log_sys_error("exp_eval_list: malloc"); goto error; } } return var_list; error: if (var_list) { var_delete(var_list); } return NULL; }
int vlist_append_new(var_t *list, var_type_t type, char *name, void *data, int flags) { var_t *v; v = var_create(type, name, data, flags); if (v == NULL) { log_warning("vlist_append_new: var_create failed"); return -1; } if (vlist_append(list, v) == 0) { return 0; } log_error("vlist_append_new: vlist_append failed"); var_delete(v); return -1; }