text_property r_language_rep::advance (tree t, int& pos) { string s= t->label; if (pos==N(s)) { return &tp_normal_rep; } char c= s[pos]; if (c == ' ') { pos++; return &tp_space_rep; } if ( is_number_start(c) ) { int opos =pos ; parse_number (s, pos); if( opos != pos ) return &tp_normal_rep; } if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || is_in_str( c, "_." ) //|| (c == '$') // For some reason, when this is uncommented, TeXmacs gets stuck on entering $. ) { parse_alpha (s, pos); return &tp_normal_rep; } tm_char_forwards (s, pos); return &tp_normal_rep; }
int main(int argc, char **argv) { int everywhere; int i = 0; int j; while (argv[1][i]) { everywhere = 1; j = 2; while (j < argc) { everywhere *= is_in_str(argv[1][i], argv[j]); j++; } if (everywhere && already_shown(argv[1][i]) == 0) my_putchar(argv[1][i]); i++; } my_putchar('\n'); return 0; }
void check_all_params(char *trim, char **inst_line, t_data *data, int *ret) { if (is_in_str(SEPARATOR_CHAR, trim) == 0 && check_opcode_name( inst_line[0]) == 1) inst_one_param(inst_line, data); else if (is_in_str(SEPARATOR_CHAR, trim) == 1 && check_opcode_name( inst_line[0]) == 1) inst_two_params(inst_line, trim, data); else if (is_in_str(SEPARATOR_CHAR, trim) == 2 && check_opcode_name( inst_line[0]) == 1) inst_three_params(inst_line, trim, data); else if (is_in_str(SEPARATOR_CHAR, trim) > 3 && ft_strchr(trim, COMMENT_CHAR) == NULL) error_line(data, "Incorrect number of params"); else *ret = 0; }
/** * check if string has pvs * returns -1 if error, 0 if found, 1 if not found */ int dpl_check_pv(str *in) { char *p; pv_spec_t *spec = NULL; str s; int len; if(in==NULL || in->s==NULL) return -1; LM_DBG("parsing [%.*s]\n", in->len, in->s); if(in->len == 0) return 1; p = in->s; while(is_in_str(p,in)) { while(is_in_str(p,in) && *p!=PV_MARKER) p++; if(*p == '\0' || !is_in_str(p,in)) break; /* last char is $ ? */ if(!is_in_str(p+1, in)) break; s.s = p; s.len = in->s+in->len-p; len = 0; spec = pv_spec_lookup(&s, &len); if(spec!=NULL) { /* found a variable */ LM_DBG("string [%.*s] has variables\n", in->len, in->s); return 0; } if(len) p += len; else p++; } /* not found */ return 1; }
char *check_comm(char *str, t_data *data) { char **comm; comm = NULL; if (is_in_str(COMMENT_CHAR, str) > 0) { if ((comm = ft_strsplit(str, COMMENT_CHAR)) == NULL) error_line(data, "Malloc error"); return (comm[0]); } return (str); }
static inline char* tr_get_class(str *in, char *p, str *tclass) { tclass->s = p; while(is_in_str(p, in) && *p!=TR_CLASS_MARKER) p++; if(*p!=TR_CLASS_MARKER || tclass->s == p) { LM_ERR("invalid transformation: %.*s (%c)!\n", in->len, in->s, *p); return NULL; } tclass->len = p - tclass->s; p++; return p; }
t_list *lexer(char *expr, char *base, char *ops) { int n; t_list *lex; lex = prepare_list(base, my_strlen(base), ops); n = 0; while (expr[n]) { if (is_in_str(expr[n], base)) n += add_nbr(lex, expr + n, 1); else if (is_in_str(expr[n], ops)) n += add_ope(lex, expr + n); else { free_list(lex); free(expr); my_error(SYNTAXE_ERROR_MSG); } } free(expr); check_valid_list(lex); return (lex); }
char* tr_parse_sql(str *in, trans_t *t) { char *p; str name; if(in==NULL || t==NULL) return NULL; p = in->s; name.s = in->s; t->type = TR_SQL; t->trf = tr_eval_sql; /* find next token */ while(is_in_str(p, in) && *p!=TR_PARAM_MARKER && *p!=TR_RBRACKET) p++; if(*p=='\0') { LM_ERR("unable to find transformation start: %.*s\n", in->len, in->s); return NULL; } name.len = p - name.s; trim(&name); if(name.len==3 && strncasecmp(name.s, "val", 3)==0) { t->subtype = TR_SQL_VAL; goto done; } if(name.len==7 && strncasecmp(name.s, "val.int", 7)==0) { t->subtype = TR_SQL_VAL_INT; goto done; } if(name.len==7 && strncasecmp(name.s, "val.str", 7)==0) { t->subtype = TR_SQL_VAL_STR; goto done; } LM_ERR("unknown transformation: %.*s/%.*s/%d!\n", in->len, in->s, name.len, name.s, name.len); return NULL; done: t->name = name; return p; }
int parse_options(int ac, char **av, t_args *args) { int i; int found; i = 0; found = 0; if (ac < 2) print_err("\nErr: invalid arguments.\n"); while (option[i].param && !found) { if (!strcmp(av[1], option[i].param) && strlen(av[1]) == 2) { if (is_in_str(av[1][1], "cv")) get_opt_param(av, args); get_str_param(av, args); return (i); } i++; } print_err("Err: couldn't find [option].\n"); return (-1); }
/*! * \brief Helper fuction to parse a kazoo transformation * \param in parsed string * \param t transformation * \return pointer to the end of the transformation in the string - '}', null on error */ char* kz_tr_parse(str* in, trans_t *t) { char *p; char *p0; char *ps; str name; str s; pv_spec_t *spec = NULL; tr_param_t *tp = NULL; if(in==NULL || t==NULL) return NULL; p = in->s; name.s = in->s; t->type = TR_KAZOO; t->trf = kz_tr_eval; /* find next token */ while(is_in_str(p, in) && *p!=TR_PARAM_MARKER && *p!=TR_RBRACKET) p++; if(*p=='\0') { LM_ERR("invalid transformation: %.*s\n", in->len, in->s); goto error; } name.len = p - name.s; trim(&name); if(name.len==6 && strncasecmp(name.s, "encode", 6)==0) { t->subtype = TR_KAZOO_ENCODE; goto done; } else if(name.len==4 && strncasecmp(name.s, "json", 4)==0) { t->subtype = TR_KAZOO_JSON; if(*p!=TR_PARAM_MARKER) { LM_ERR("invalid json transformation: %.*s!\n", in->len, in->s); goto error; } p++; _kz_tr_parse_sparam(p, p0, tp, spec, ps, in, s); t->params = tp; tp = 0; while(*p && (*p==' ' || *p=='\t' || *p=='\n')) p++; if(*p!=TR_RBRACKET) { LM_ERR("invalid json transformation: %.*s!!\n", in->len, in->s); goto error; } goto done; } LM_ERR("unknown kazoo transformation: %.*s/%.*s/%d!\n", in->len, in->s, name.len, name.s, name.len); error: if(tp) tr_param_free(tp); if(spec) pv_spec_free(spec); return NULL; done: t->name = name; return p; }
pvname_list_t* parse_pvname_list(str *in, unsigned int type) { pvname_list_t* head = NULL; pvname_list_t* al = NULL; pvname_list_t* last = NULL; char *p; pv_spec_t spec; str s; if(in==NULL || in->s==NULL) { LM_ERR("bad parameters\n"); return NULL; } p = in->s; while(is_in_str(p, in)) { while(is_in_str(p, in) && (*p==' '||*p=='\t'||*p==','||*p==';'||*p=='\n')) p++; if(!is_in_str(p, in)) { if(head==NULL) LM_ERR("parse error in name list [%.*s]\n", in->len, in->s); return head; } s.s = p; s.len = in->s + in->len - p; p = pv_parse_spec(&s, &spec); if(p==NULL) { LM_ERR("parse error in item [%.*s]\n", s.len, s.s); goto error; } if(type && spec.type!=type) { LM_ERR("wrong type for item [%.*s]\n", (int)(p-s.s), s.s); goto error; } al = (pvname_list_t*)pkg_malloc(sizeof(pvname_list_t)); if(al==NULL) { LM_ERR("no more memory!\n"); goto error; } memset(al, 0, sizeof(pvname_list_t)); memcpy(&al->sname, &spec, sizeof(pv_spec_t)); if(last==NULL) { head = al; last = al; } else { last->next = al; last = al; } } return head; error: while(head) { al = head; head=head->next; pkg_free(al); } return NULL; }
int pv_parse_format(str *in, pv_elem_p *el) { char *p, *p0; int n = 0; pv_elem_p e, e0; str s; int len; if(in==NULL || in->s==NULL || el==NULL) return -1; /*LM_DBG("parsing [%.*s]\n", in->len, in->s);*/ if(in->len == 0) { *el = pkg_malloc(sizeof(pv_elem_t)); if(*el == NULL) goto error; memset(*el, 0, sizeof(pv_elem_t)); (*el)->text = *in; return 0; } p = in->s; *el = NULL; e = e0 = NULL; while(is_in_str(p,in)) { e0 = e; e = pkg_malloc(sizeof(pv_elem_t)); if(!e) goto error; memset(e, 0, sizeof(pv_elem_t)); n++; if(*el == NULL) *el = e; if(e0) e0->next = e; e->text.s = p; while(is_in_str(p,in) && *p!=PV_MARKER) p++; e->text.len = p - e->text.s; if(*p == '\0' || !is_in_str(p,in)) break; s.s = p; s.len = in->s+in->len-p; e->spec = pv_spec_lookup(&s, &len); if(e->spec==NULL) goto error; p0 = p + len; if(*p0 == '\0') break; p = p0; } /*LM_DBG("format parsed OK: [%d] items\n", n);*/ if(*el == NULL) return -1; return 0; error: pv_elem_free_all(*el); *el = NULL; return -1; }
char* tr_parse_msrpuri(str* in, trans_t *t) { str name; char *p; if(in==NULL || t==NULL) return NULL; p = in->s; name.s = in->s; t->type = TR_MSRPURI; t->trf = tr_msrp_eval_msrpuri; /* find next token */ while(is_in_str(p, in) && *p!=TR_PARAM_MARKER && *p!=TR_RBRACKET) p++; if(*p=='\0') { LM_ERR("invalid transformation: %.*s\n", in->len, in->s); goto error; } name.len = p - name.s; trim(&name); if(name.len==4 && strncasecmp(name.s, "user", 4)==0) { t->subtype = TR_MSRPURI_USER; goto done; } else if(name.len==4 && strncasecmp(name.s, "host", 4)==0) { t->subtype = TR_MSRPURI_HOST; goto done; } else if(name.len==4 && strncasecmp(name.s, "port", 4)==0) { t->subtype = TR_MSRPURI_PORT; goto done; } else if(name.len==7 && strncasecmp(name.s, "session", 7)==0) { t->subtype = TR_MSRPURI_SESSION; goto done; } else if(name.len==5 && strncasecmp(name.s, "proto", 5)==0) { t->subtype = TR_MSRPURI_PROTO; goto done; } else if(name.len==6 && strncasecmp(name.s, "scheme", 6)==0) { t->subtype = TR_MSRPURI_SCHEME; goto done; } else if(name.len==6 && strncasecmp(name.s, "params", 6)==0) { t->subtype = TR_MSRPURI_PARAMS; goto done; } else if(name.len==8 && strncasecmp(name.s, "userinfo", 8)==0) { t->subtype = TR_MSRPURI_USERINFO; goto done; } LM_ERR("unknown transformation: %.*s/%.*s/%d!\n", in->len, in->s, name.len, name.s, name.len); error: return NULL; done: t->name = name; return p; }
int pv_xbuff_parse_name(pv_spec_t *sp, str *in) { char *p; str idx; str name; str attr; int l; if (in->s == NULL || in->len <= 0) return -1; p = in->s; name.s = p; while (is_in_str(p, in)) { if (*p == '[' || *p== '=') break; if (!is_pv_xbuff_valid_char(*p)) { l = p-in->s; LM_ERR("invalid character in var name %.*s at %d\n",STR_FMT(in),l); goto error; } p++; } /* from in->s to p */ name.len = p - in->s; if (pv_parse_avp_name(sp,&name)) goto error; if (is_in_str(p,in) && *p =='[') { idx.s=++p; while (is_in_str(p,in)) { if (*p == ']' || *p == '=') break; p++; } if (is_in_str(p,in) && *p==']') { idx.len = p - idx.s; if (pv_parse_index(sp,&idx)) goto error; } p++; } else { xbuff_set_attr_flag(sp->pvp.pvi.type,XBUFF_NO_IDX); } if (is_in_str(p,in) && *p =='=') { p++; if (!is_in_str(p,in) || *p!='>') { l = p-in->s; LM_ERR("invalid operator (expected =>) for accessing attribute in token %.*s at position %d\n",STR_FMT(in),l); goto error; } attr.s = ++p; while (is_in_str(p,in)) { if (!is_pv_xbuff_valid_char(*p)) { l = p-in->s; LM_ERR("invalid character in attribute name in token %.*s at %d\n",STR_FMT(in),l); goto error; } p++; } attr.len = p - attr.s; if (attr.len > 0 ) { if (STR_EQ(attr,xbuff_attr_name(XBUFF_ATTR_TYPE))) { xbuff_set_attr_flag(sp->pvp.pvi.type,XBUFF_ATTR_TYPE); } else if (STR_EQ(attr,xbuff_attr_name(XBUFF_ATTR_FORMAT))) { xbuff_set_attr_flag(sp->pvp.pvi.type,XBUFF_ATTR_FORMAT); } else if (STR_EQ(attr,xbuff_attr_name(XBUFF_ATTR_LENGTH))) { xbuff_set_attr_flag(sp->pvp.pvi.type,XBUFF_ATTR_LENGTH); } else { LM_ERR("unknown attribute %.*s\n",STR_FMT(&attr)); goto error; } if (sp->pvp.pvi.type & PV_IDX_ALL) { LM_ERR("index [*] (all) isn't compatible with attribute %.*s\n",STR_FMT(&attr)); goto error; } } } if (p < in->s + in->len) { l = p-in->s; LM_ERR("unexpected token in %.*s at %d\n",STR_FMT(in),l); goto error; } return 0; error: return -1; }
static inline bool belongs_to_identifier (char c) { return ( is_digit(c) || is_alpha(c) || is_in_str( c, "_." ) ) ; }
static inline bool is_number_start( char c ) { return( is_digit(c) || is_in_str( c, "." ) ) ; }
char* tr_lookup(str *in, trans_t **tr) { char *p; char *p0; str tclass; tr_export_t *te = NULL; trans_t *t = NULL; trans_t *t0 = NULL; str s; if(in==NULL || in->s==NULL || tr==NULL) return NULL; p = in->s; do { while(is_in_str(p, in) && (*p==' ' || *p=='\t' || *p=='\n')) p++; if(*p != TR_LBRACKET) break; p++; if((t = tr_new())==NULL) return NULL; if(t0==NULL) *tr = t; else t0->next = t; t0 = t; /* find transformation class */ p = tr_get_class(in, p, &tclass); if(p==NULL) goto error; /* locate transformation */ te = tr_lookup_class(&tclass); if(te==NULL) { LM_ERR("unknown transformation: [%.*s] in [%.*s]\n", tclass.len, tclass.s, in->len, in->s); goto error; } s.s = p; s.len = in->s + in->len - p; p0 = te->tparse(&s, t); if(p0==NULL) goto error; p = p0; if(*p != TR_RBRACKET) { LM_ERR("invalid transformation: %.*s | %c !!\n", in->len, in->s, *p); goto error; } p++; if(!is_in_str(p, in)) break; } while(1); return p; error: LM_ERR("error parsing [%.*s]\n", in->len, in->s); t = *tr; while(t) { t0 = t; t = t->next; tr_destroy(t0); pkg_free(t0); } return NULL; }
// TODO: add hex static void parse_number (string s, int& pos) { bool valid_number = false ; bool first= true ; int i ; int possible_exp = 0 ; int possible_hex = 0 ; if (pos>=N(s)) return; for( i=pos; i< N(s); i++ ) { if( first ) { #if 0 // It would be better if +/- were part of the number, but then 10+3 is hard to interpret. if( is_in_str( s[i], "-+" ) ) { possible_hex = 1 ; possible_exp = 1 ; first = false ; // valid_number = true ; // ????? continue ; } #endif if( s[i] == '0' ) { possible_hex = 2 ; possible_exp = 1 ; first = false ; valid_number = true ; continue ; } if( s[i] == '.' ) { first = false ; possible_hex = 0 ; possible_exp = 1 ; valid_number = true ; // ???? continue ; } if( is_digit( s[i] ) ) { first = false ; possible_hex = 0 ; possible_exp = 1 ; valid_number = true ; continue ; } break ; } else { // not first if( (possible_hex == 1) && (s[i] == '0' ) ) { possible_hex = 2 ; valid_number = true ; continue ; } if( (possible_hex == 2 ) && ( is_in_str(s[i], "xX" ) ) ) { possible_hex = 3 ; possible_exp = 0 ; continue ; } if( possible_hex == 3 ) { if( is_in_str( s[i], "0123456789abcdefABCDEF" ) ) { valid_number = true ; continue ; } else break ; } if( (possible_exp > 0) && valid_number && is_in_str( s[i], "eE" ) ) { possible_exp = 3 ; // this means we are in the exponent continue ; } // values for possible_exp: // 0 - no exp possible // 1 - '.' possible // 2 - '.' found // 3 - in exp, // 4 - saw +-or 0-9 in exp (i.e. no -/+ possible ) if( (possible_exp >= 3) ) { // in exponent if( is_digit( s[i] ) ) { possible_exp = 4 ; valid_number = true ; continue ; } if( (possible_exp == 3) && is_in_str( s[i], "+-" ) ) { // valid_number = true ; possible_exp = 4 ; continue ; } break ; } if( (possible_exp == 1) && (s[i] == '.') ) { possible_exp = 2 ; //valid_number = true ; continue ; } if( is_digit( s[i] ) ) { valid_number = true ; continue ; } } // else: not first break ; } if( valid_number ) { if( s[i]=='i' ) i++ ; if( (s[i]=='L') && (possible_exp<2) ) i++ ; pos = i ; } }
int pv_table_add(pv_export_t *e) { char *p; str *in; pv_item_t *pvi = NULL; pv_item_t *pvj = NULL; pv_item_t *pvn = NULL; int found; unsigned int pvid; if(e==NULL || e->name.s==NULL || e->getf==NULL || e->type==PVT_NONE) { LM_ERR("invalid parameters\n"); return -1; } if(_pv_table_set==0) { LM_DBG("PV table not initialized, doing it now\n"); pv_init_table(); } in = &(e->name); p = in->s; while(is_in_str(p,in) && is_pv_valid_char(*p)) p++; if(is_in_str(p,in)) { LM_ERR("invalid char [%c] in [%.*s]\n", *p, in->len, in->s); return -1; } found = 0; //pvid = get_hash1_raw(in->s, in->len); pvid = get_hash1_raw(in->s, in->len); pvi = _pv_table[pvid%PV_TABLE_SIZE]; while(pvi) { if(pvi->pvid > pvid) break; if(pvi->pve.name.len==in->len) { found = strncmp(pvi->pve.name.s, in->s, in->len); if(found==0) { LM_ERR("pvar [%.*s] already exists\n", in->len, in->s); return -1; } } pvj = pvi; pvi = pvi->next; } pvn = (pv_item_t*)pkg_malloc(sizeof(pv_item_t)); if(pvn==0) { LM_ERR("no more memory\n"); return -1; } memset(pvn, 0, sizeof(pv_item_t)); memcpy(&(pvn->pve), e, sizeof(pv_export_t)); pvn->pvid = pvid; if(pvj==0) { pvn->next = _pv_table[pvid%PV_TABLE_SIZE]; _pv_table[pvid%PV_TABLE_SIZE] = pvn; goto done; } pvn->next = pvj->next; pvj->next = pvn; done: return 0; }
char* tr_txt_parse_re(str *in, trans_t *t) { char *p; str name; str tok; struct subst_expr *se = NULL; tr_param_t *tp = NULL; int n; pv_spec_t *spec = NULL; if(in==NULL || t==NULL) return NULL; p = in->s; name.s = in->s; t->type = TR_TXT_RE; t->trf = tr_txt_eval_re; /* find next token */ while(is_in_str(p, in) && *p!=TR_PARAM_MARKER && *p!=TR_RBRACKET) p++; if(*p=='\0') goto error; name.len = p - name.s; trim(&name); if(name.len==5 && strncasecmp(name.s, "subst", 5)==0) { t->subtype = TR_TXT_RE_SUBST; if(*p!=TR_PARAM_MARKER) goto error; p++; if(*p==PV_MARKER) { spec = (pv_spec_t*)pkg_malloc(sizeof(pv_spec_t)); if(spec==NULL) { LM_ERR("no more private memory!\n"); return 0; } tok.s = p; tok.len = in->s + in->len - p; p = pv_parse_spec(&tok, spec); if(p==NULL) { LM_ERR("invalid pv spec in transformation: %.*s!\n", in->len, in->s); pkg_free(spec); return 0; } tp = (tr_param_t*)pkg_malloc(sizeof(tr_param_t)); if(tp==NULL) { LM_ERR("no more private memory!\n"); pkg_free(spec); goto error; } tp->type = TR_PARAM_SPEC; tp->v.data = (void*)spec; } else { /* get trans here */ n = 0; tok.s = p; while(is_in_str(p, in)) { if(*p==TR_RBRACKET) { if(n==0) break; n--; } if(*p == TR_LBRACKET) n++; p++; } if(!is_in_str(p, in)) goto error; if(p==tok.s) goto error; tok.len = p - tok.s; tp = (tr_param_t*)pkg_malloc(sizeof(tr_param_t)); if(tp==NULL) { LM_ERR("no more private memory!\n"); goto error; } se=subst_parser(&tok); if (se==0) goto error; tp->type = TR_PARAM_SUBST; tp->v.data = (void*)se; } t->params = tp; while(*p && (*p==' ' || *p=='\t' || *p=='\n')) p++; if(*p!=TR_RBRACKET) goto error; goto done; } LM_ERR("unknown transformation: %.*s/%.*s/%d!\n", in->len, in->s, name.len, name.s, name.len); error: LM_ERR("invalid transformation [%.*s] <%d>\n", in->len, in->s, (int)(p-in->s)); if(tp!=NULL) pkg_free(tp); if(se!=NULL) subst_expr_free(se); return NULL; done: t->name = name; return p; }
char* pv_parse_spec2(str *in, pv_spec_p e, int silent) { char *p; str s; str pvname; int pvstate; trans_t *tr = NULL; pv_export_t *pte = NULL; int n=0; if(in==NULL || in->s==NULL || e==NULL || *in->s!=PV_MARKER) { if (!silent) LM_ERR("bad parameters\n"); return NULL; } /* LM_DBG("***** input [%.*s] (%d)\n", in->len, in->s, in->len); */ tr = 0; pvstate = 0; memset(e, 0, sizeof(pv_spec_t)); p = in->s; p++; if(*p==PV_LNBRACKET) { p++; pvstate = 1; } pvname.s = p; if(*p == PV_MARKER) { p++; if(pvstate==1) { if(*p!=PV_RNBRACKET) goto error; p++; } e->getf = pv_get_marker; e->type = PVT_MARKER; pvname.len = 1; goto done_all; } while(is_in_str(p,in) && is_pv_valid_char(*p)) p++; pvname.len = p - pvname.s; if(pvstate==1) { if(*p==PV_RNBRACKET) { /* full pv name ended here*/ goto done_inm; } else if(*p==PV_LNBRACKET) { p++; pvstate = 2; } else if(*p==PV_LIBRACKET) { p++; pvstate = 3; } else if(*p==TR_LBRACKET) { p++; pvstate = 4; } else { if (!silent) LM_ERR("invalid char '%c' in [%.*s] (%d)\n", *p, in->len, in->s, pvstate); goto error; } } else { if(!is_in_str(p, in)) { p--; goto done_inm; } else if(*p==PV_LNBRACKET) { p++; pvstate = 5; } else { /* still in input str, but end of PV */ /* p is increased at the end, so decrement here */ p--; goto done_inm; } } done_inm: if((pte = pv_lookup_spec_name(&pvname, e))==NULL) { if (!silent) LM_ERR("error searching pvar \"%.*s\"\n", pvname.len, pvname.s); goto error; } if(pte->parse_name!=NULL && pvstate!=2 && pvstate!=5) { if (!silent) LM_ERR("pvar \"%.*s\" expects an inner name\n", pvname.len, pvname.s); goto error; } if(pvstate==2 || pvstate==5) { if(pte->parse_name==NULL) { if (!silent) LM_ERR("pvar \"%.*s\" does not get name param\n", pvname.len, pvname.s); goto error; } s.s = p; n = 0; while(is_in_str(p, in)) { if(*p==PV_RNBRACKET) { if(n==0) break; n--; } if(*p == PV_LNBRACKET) n++; p++; } if(!is_in_str(p, in)) goto error; if(p==s.s) { if (!silent) LM_ERR("pvar \"%.*s\" does not get empty name param\n", pvname.len, pvname.s); goto error; } s.len = p - s.s; if(pte->parse_name(e, &s)!=0) { if (!silent) LM_ERR("pvar \"%.*s\" has an invalid name param [%.*s]\n", pvname.len, pvname.s, s.len, s.s); goto error; } if(pvstate==2) { p++; if(*p==PV_RNBRACKET) { /* full pv name ended here*/ goto done_vnm; } else if(*p==PV_LIBRACKET) { p++; pvstate = 3; } else if(*p==TR_LBRACKET) { p++; pvstate = 4; } else { if (!silent) LM_ERR("invalid char '%c' in [%.*s] (%d)\n", *p, in->len, in->s, pvstate); goto error; } } else { if(*p==PV_RNBRACKET) { /* full pv name ended here*/ p++; goto done_all; } else { if (!silent) LM_ERR("invalid char '%c' in [%.*s] (%d)\n", *p, in->len, in->s, pvstate); goto error; } } } done_vnm: if(pvstate==3) { if(pte->parse_index==NULL) { if (!silent) LM_ERR("pvar \"%.*s\" does not get index param\n", pvname.len, pvname.s); goto error; } s.s = p; n = 0; while(is_in_str(p, in)) { if(*p==PV_RIBRACKET) { if(n==0) break; n--; } if(*p == PV_LIBRACKET) n++; p++; } if(!is_in_str(p, in)) goto error; if(p==s.s) { if (!silent) LM_ERR("pvar \"%.*s\" does not get empty index param\n", pvname.len, pvname.s); goto error; } s.len = p - s.s; if(pte->parse_index(e, &s)!=0) { if (!silent) LM_ERR("pvar \"%.*s\" has an invalid index param [%.*s]\n", pvname.len, pvname.s, s.len, s.s); goto error; } p++; if(*p==PV_RNBRACKET) { /* full pv name ended here*/ goto done_idx; } else if(*p==TR_LBRACKET) { p++; pvstate = 4; } else { if (!silent) LM_ERR("invalid char '%c' in [%.*s] (%d)\n", *p, in->len, in->s, pvstate); goto error; } } done_idx: if(pvstate==4) { s.s = p-1; n = 0; while(is_in_str(p, in)) { if(*p==TR_RBRACKET) { if(n==0) { /* yet another transformation */ p++; while(is_in_str(p, in) && (*p==' ' || *p=='\t')) p++; if(!is_in_str(p, in) || *p != TR_LBRACKET) { p--; break; } } n--; } if(*p == TR_LBRACKET) n++; p++; } if(!is_in_str(p, in)) goto error; if(p==s.s) { if (!silent) LM_ERR("pvar \"%.*s\" does not get empty index param\n", pvname.len, pvname.s); goto error; } s.len = p - s.s + 1; p = tr_lookup(&s, &tr); if(p==NULL) { if (!silent) LM_ERR("bad tr in pvar name \"%.*s\"\n", pvname.len, pvname.s); goto error; } if(*p!=PV_RNBRACKET) { if (!silent) LM_ERR("bad pvar name \"%.*s\" (%c)!\n", in->len, in->s, *p); goto error; } e->trans = (void*)tr; } p++; done_all: if(pte!=NULL && pte->init_param) pte->init_param(e, pte->iparam); return p; error: if(p!=NULL){ if (!silent) LM_ERR("wrong char [%c/%d] in [%.*s] at [%d (%d)]\n", *p, (int)*p, in->len, in->s, (int)(p-in->s), pvstate); }else{ if (!silent) LM_ERR("invalid parsing in [%.*s] at (%d)\n", in->len, in->s, pvstate); } return NULL; } /* end: pv_parse_spec */