/** init pv api (optional). * @return 0 on success, -1 on error */ int pv_init_api(void) { pv_init_table(); tr_init_table(); if(pv_init_buffer()<0) return -1; if(register_pvars_mod("core", _core_pvs)<0) return -1; return 0; }
/** init pv api (optional). * @return 0 on success, -1 on error */ int pv_init_api(void) { pv_init_table(); tr_init_table(); if(pv_init_buffer()<0) return -1; pv_str_empty_buf[0] = '\0'; pv_str_empty_buf[1] = '\0'; pv_str_empty.s = pv_str_empty_buf; strcpy(pv_str_null_buf, "<null>"); pv_str_null.s = pv_str_null_buf; if(register_pvars_mod("core", _core_pvs)<0) return -1; return 0; }
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; }