Przeglądaj źródła

core: added helper function pv_cache_get_name() in order
to get the name of a pv_spec_t on pv_cache.

Victor Seva 12 lat temu
rodzic
commit
a21137507b
2 zmienionych plików z 31 dodań i 0 usunięć
  1. 30 0
      pvapi.c
  2. 1 0
      pvar.h

+ 30 - 0
pvapi.c

@@ -357,6 +357,36 @@ pv_spec_t* pv_cache_get(str *name)
 	return pv_cache_add(&tname);
 }
 
+str* pv_cache_get_name(pv_spec_t *spec)
+{
+	int i;
+	pv_cache_t *pvi;
+	if(spec==NULL)
+	{
+		LM_ERR("invalid parameters\n");
+		return NULL;
+	}
+
+	if(_pv_cache_set==0)
+		return NULL;
+
+	for(i=0;i<PV_CACHE_SIZE;i++)
+	{
+		pvi = _pv_cache[i];
+		while(pvi)
+		{
+			if(&pvi->spec == spec)
+			{
+				LM_DBG("pvar[%p]->name[%.*s] found in cache\n", spec,
+					pvi->pvname.len, pvi->pvname.s);
+				return &pvi->pvname;
+			}
+			pvi = pvi->next;
+		}
+	}
+	return NULL;
+}
+
 /**
  *
  */

+ 1 - 0
pvar.h

@@ -207,6 +207,7 @@ int pv_free_extra_list(void);
 
 int pv_locate_name(str *in);
 pv_spec_t* pv_cache_get(str *name);
+str* pv_cache_get_name(pv_spec_t *spec);
 
 /*! \brief PV helper functions */
 int pv_get_null(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);