static int fixup_avp_prefix(void **param) { str st, *name, *prefix; char *p; prefix = pkg_malloc(sizeof(*prefix)); if (!prefix) { LM_ERR("No more pkg\n"); return -1; } prefix->s = (char *)*param; prefix->len = strlen(prefix->s); name = get_avp_name_id(dbp_fixup->a.u.sval.pvp.pvn.u.isname.name.n); if (name && dbp_fixup->a.type == AVPOPS_VAL_PVAR) { p = pkg_malloc(name->len + prefix->len + 7); if (!p) { LM_ERR("No more pkg mem!\n"); return -1; } memcpy(p, "$avp(", 5); memcpy(p + 5, prefix->s, prefix->len); memcpy(p + 5 + prefix->len, name->s, name->len); p[name->len + prefix->len + 5] = ')'; p[name->len + prefix->len + 6] = '\0'; st.s = p; st.len = prefix->len + name->len + 6; pv_parse_spec(&st, &dbp_fixup->a.u.sval); } *param = prefix; return 0; }
int parse_avp_db(char *s, struct db_param *dbp, int allow_scheme) { str tmp; str s0; str *s1; char have_scheme; char *p; char *p0; unsigned int flags; LM_DBG("parse: %s\n", s); tmp.s = s; /* parse the attribute name - check first if it's not an alias */ p0=strchr(tmp.s, '/'); if(p0!=NULL) *p0=0; if ( *s!='$') { if(strlen(s)<1) { LM_ERR("bad param - expected : $avp(name), *, s or i value\n"); return E_UNSPEC; } switch(*s) { /* deteleted because of the new avp format */ case 's': case 'S': case 'i': case 'I': case '*': case 'a': case 'A': dbp->a.opd = AVPOPS_VAL_NONE; break; default: LM_ERR("bad param - expected : *, s or i AVP flag\n"); return E_UNSPEC; } /* flags */ flags = 0; if(*(s+1)!='\0') { s0.s = s+1; s0.len = strlen(s0.s); if(str2int(&s0, &flags)!=0) { LM_ERR("error - bad avp flags\n"); goto error; } } dbp->a.u.sval.pvp.pvn.u.isname.type |= (flags<<8)&0xff00; dbp->a.type = AVPOPS_VAL_NONE; } else { s0.s = s; s0.len = strlen(s0.s); p = pv_parse_spec(&s0, &dbp->a.u.sval); if (p==0 || *p!='\0' || dbp->a.u.sval.type!=PVT_AVP) { LM_ERR("bad param - expected : $avp(name) or int/str value\n"); return E_UNSPEC; } dbp->a.type = AVPOPS_VAL_PVAR; } /* optimize and keep the attribute name as str also to * speed up db querie builds */ if (dbp->a.type == AVPOPS_VAL_PVAR) { dbp->a.opd = AVPOPS_VAL_PVAR; if(pv_has_iname(&dbp->a.u.sval)) { s1 = get_avp_name_id(dbp->a.u.sval.pvp.pvn.u.isname.name.n); if (!s1) { LM_ERR("cannot find avp name\n"); goto error; } dbp->sa.s=(char*)pkg_malloc(s1->len + 1); if (dbp->sa.s==0) { LM_ERR("no more pkg mem\n"); goto error; } memcpy(dbp->sa.s, s1->s, s1->len); dbp->sa.len = s1->len; dbp->sa.s[dbp->sa.len] = 0; dbp->a.opd = AVPOPS_VAL_PVAR|AVPOPS_VAL_STR; } } /* restore '/' */ if(p0) *p0 = '/'; /* is there a table name ? */ s = p0; if (s && *s) { s++; if (*s=='$') { if (allow_scheme==0) { LM_ERR("function doesn't support DB schemes\n"); goto error; } if (dbp->a.opd&AVPOPS_VAL_NONE) { LM_ERR("inconsistent usage of " "DB scheme without complet specification of AVP name\n"); goto error; } have_scheme = 1; s++; } else { have_scheme = 0; } tmp.s = s; tmp.len = 0; while ( *s ) s++; tmp.len = s - tmp.s; if (tmp.len==0) { LM_ERR("empty scheme/table name\n"); goto error; } if (have_scheme) { dbp->scheme = avp_get_db_scheme( &tmp ); if (dbp->scheme==0) { LM_ERR("scheme <%s> not found\n", tmp.s); goto error; } /* update scheme flags with AVP name type*/ dbp->scheme->db_flags|=dbp->a.opd&AVPOPS_VAL_STR?AVP_NAME_STR:0; } else { /* duplicate table str into the db_param struct */ pkg_str_dup( &dbp->table, &tmp); } } return 0; error: return -1; }
inline str* get_avp_name(struct usr_avp *avp) { return get_avp_name_id(avp->id); }