/** 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 tr_table_add(tr_export_t *e) { tr_item_t *tri = NULL; tr_item_t *trj = NULL; tr_item_t *trn = NULL; int found; unsigned int trid; if(e==NULL || e->tclass.s==NULL) { LM_ERR("invalid parameters\n"); return -1; } if(_tr_table_set==0) { LM_DBG("TR table not initialized, doing it now\n"); tr_init_table(); } found = 0; // trid = get_hash1_raw(e->tclass.s, e->tclass.len); trid = get_hash1_raw(e->tclass.s, e->tclass.len); tri = _tr_table[trid%TR_TABLE_SIZE]; while(tri) { if(tri->tre.tclass.len==e->tclass.len) { found = strncmp(tri->tre.tclass.s, e->tclass.s, e->tclass.len); if(found==0) { LM_ERR("TR class [%.*s] already exists\n", e->tclass.len, e->tclass.s); return -1; } } trj = tri; tri = tri->next; } trn = (tr_item_t*)pkg_malloc(sizeof(tr_item_t)); if(trn==0) { LM_ERR("no more memory\n"); return -1; } memset(trn, 0, sizeof(tr_item_t)); memcpy(&(trn->tre), e, sizeof(tr_export_t)); trn->trid = trid; //LM_DBG("TR class [%.*s] added to entry [%d]\n", e->tclass.len, // e->tclass.s, trid%TR_TABLE_SIZE); if(trj==0) { trn->next = _tr_table[trid%TR_TABLE_SIZE]; _tr_table[trid%TR_TABLE_SIZE] = trn; goto done; } trn->next = trj->next; trj->next = trn; done: return 0; }