Exemple #1
0
/* NOTE: assumes that the pipe has been locked. If fails, releases the lock */
static int rl_get_counter(str *name, rl_pipe_t * pipe)
{
	str res;
	unsigned int hid = RL_GET_INDEX(*name);
	int new_counter;

	RL_SET_PENDING(pipe);
	RL_RELEASE_LOCK(hid);

	if (rl_set_name(name) < 0)
		return -1;
	if (cdbf.get(cdbc, &rl_name_buffer, &res) < 0) {
		LM_ERR("cannot retrieve key\n");
		return -1;
	}
	if (str2sint(&res, &new_counter) < 0) {
		LM_ERR("invalid value %.*s - should be integer\n", res.len, res.s);
		return -1;
	}
	if (res.s)
		pkg_free(res.s);
	RL_GET_LOCK(hid);
	RL_RESET_PENDING(pipe);
	pipe->counter = new_counter;
	return 0;
}
Exemple #2
0
/* gets value from cache for the corresponding entry
 * Params : 
 * name - what is wished to be resolved - binary IP for PTR and strings for other queries
 * r_type - type of DNS query
 * name_len - only used in case of PTR
 */
int get_dnscache_strvalue(char *name,int r_type,int name_len,str *res)
{
	str key;
	
	/* generate key */
	key.s=create_keyname_for_record(name,r_type,name_len,&key.len);
	if (key.s == NULL) {
		LM_ERR("failed to create key\n");
		return -1;
	}
	
	LM_DBG("gen key [%.*s]\n",key.len,key.s);
	
	/* fetch from backend */
	if (cdbf.get(cdbc, &key, res) < 0) {
		LM_DBG("cannot retrieve key\n");
		return -1;
	}

	return 0;
}