pv_spec_t* pv_cache_add(str *name) { pv_cache_t *pvn; unsigned int pvid; char *p; if(_pv_cache_set==0) { LM_DBG("PV cache not initialized, doing it now\n"); pv_init_cache(); } if(_pv_cache_counter+1>=cfg_get(core, core_cfg, pv_cache_limit)) { if(_pv_cache_counter+1==cfg_get(core, core_cfg, pv_cache_limit)) { LM_WARN("pv cache limit is going to be exceeded" " - pkg memory may get filled with pv declarations\n"); } else { if(cfg_get(core, core_cfg, pv_cache_action)==1) { pv_cache_drop(); } } } pvid = get_hash1_raw(name->s, name->len); pvn = (pv_cache_t*)pkg_malloc(sizeof(pv_cache_t) + name->len + 1); if(pvn==0) { LM_ERR("no more memory\n"); return NULL; } memset(pvn, 0, sizeof(pv_cache_t) + name->len + 1); pvn->pvname.len = name->len; pvn->pvname.s = (char*)pvn + sizeof(pv_cache_t); memcpy(pvn->pvname.s, name->s, name->len); p = pv_parse_spec(&pvn->pvname, &pvn->spec); if(p==NULL) { pkg_free(pvn); return NULL; } pvn->pvid = pvid; pvn->next = _pv_cache[pvid%PV_CACHE_SIZE]; _pv_cache[pvid%PV_CACHE_SIZE] = pvn; LM_DBG("pvar [%.*s] added in cache\n", name->len, name->s); return &pvn->spec; }
pv_spec_t* pv_cache_add(str *name) { pv_cache_t *pvn; unsigned int pvid; char *p; if(_pv_cache_set==0) { LM_DBG("PV cache not initialized, doing it now\n"); pv_init_cache(); } pvid = get_hash1_raw(name->s, name->len); pvn = (pv_cache_t*)pkg_malloc(sizeof(pv_cache_t) + name->len + 1); if(pvn==0) { LM_ERR("no more memory\n"); return NULL; } memset(pvn, 0, sizeof(pv_item_t) + name->len + 1); p = pv_parse_spec(name, &pvn->spec); if(p==NULL) { pkg_free(pvn); return NULL; } pvn->pvname.len = name->len; pvn->pvname.s = (char*)pvn + sizeof(pv_cache_t); memcpy(pvn->pvname.s, name->s, name->len); pvn->pvid = pvid; pvn->next = _pv_cache[pvid%PV_CACHE_SIZE]; _pv_cache[pvid%PV_CACHE_SIZE] = pvn; LM_DBG("pvar [%.*s] added in cache\n", name->len, name->s); return &pvn->spec; }