Ejemplo n.º 1
0
/*! \brief
 * Duplicate a single rr_t structure using pkg_malloc or shm_malloc
 */
static inline int do_duplicate_rr(rr_t** _new, rr_t* _r, int _shm)
{
	int len, ret;
	rr_t* res, *prev, *it;

	if (!_new || !_r) {
		LOG(L_ERR, "duplicate_rr(): Invalid parameter value\n");
		return -1;
	}
	prev  = NULL;
	*_new = NULL;
	it    = _r;
	while(it)
	{
		if (it->params) {
			len = it->params->name.s + it->params->len - it->nameaddr.name.s;
		} else {
			len = it->nameaddr.len;
		}

		if (_shm) res = shm_malloc(sizeof(rr_t) + len);
		else res = pkg_malloc(sizeof(rr_t) + len);
		if (!res) {
			LOG(L_ERR, "duplicate_rr(): No memory left\n");
			return -2;
		}
		memcpy(res, it, sizeof(rr_t));

		res->nameaddr.name.s = (char*)res + sizeof(rr_t);
		memcpy(res->nameaddr.name.s, it->nameaddr.name.s, len);

		if (_shm) {
			ret = shm_duplicate_params(&res->params, it->params);
		} else {
			ret = duplicate_params(&res->params, it->params);
		}

		if (ret < 0) {
			LOG(L_ERR, "duplicate_rr(): Error while duplicating parameters\n");
			if (_shm) shm_free(res);
			else pkg_free(res);
			return -3;
		}

		xlate_pointers(it, res);

		res->next=NULL;
		if(*_new==NULL)
			*_new = res;
		if(prev)
			prev->next = res;
		prev = res;
		it = it->next;
	}
	return 0;
}
Ejemplo n.º 2
0
/*
 * Duplicate a single rr_t structure using pkg_malloc or shm_malloc
 */
static inline int do_duplicate_rr(rr_t** _new, rr_t* _r, int _shm)
{
	int len, ret;
	rr_t* res;

	if (!_new || !_r) {
		LOG(L_ERR, "duplicate_rr(): Invalid parameter value\n");
		return -1;
	}

	if (_r->params) {
		len = _r->params->name.s + _r->params->len - _r->nameaddr.name.s;
	} else {
		len = _r->nameaddr.len;
	}

	if (_shm) res = shm_malloc(sizeof(rr_t) + len);
	else res = pkg_malloc(sizeof(rr_t) + len);
	if (!res) {
		LOG(L_ERR, "duplicate_rr(): No memory left\n");
		return -2;
	}
	memcpy(res, _r, sizeof(rr_t));

        res->nameaddr.name.s = (char*)res + sizeof(rr_t);
	memcpy(res->nameaddr.name.s, _r->nameaddr.name.s, len);

	if (_shm) {
		ret = shm_duplicate_params(&res->params, _r->params);
	} else {
		ret = duplicate_params(&res->params, _r->params);
	}

	if (ret < 0) {
		LOG(L_ERR, "Error while duplicating parameters\n");
		if (_shm) shm_free(res);
		else pkg_free(res);
		return -3;
	}

	xlate_pointers(_r, res);
	*_new = res;
	return 0;
}
Ejemplo n.º 3
0
/*
 * Duplicate a single rr_t structure using pkg_malloc or shm_malloc
 */
static inline int do_duplicate_rr(rr_t** _new, rr_t* _r, int _shm, int _first)
{
	int len, ret;
	rr_t* res, *prev, *it;

	if (!_new || !_r) {
		LM_ERR("invalid parameter value\n");
		return -1;
	}
	prev  = NULL;
	*_new = NULL;
	it    = _r;
	while(it)
	{
		if (it->params) {
			len = it->params->name.s + it->params->len - it->nameaddr.name.s;
		} else {
			len = it->nameaddr.len;
		}

		if (_shm) res = shm_malloc(sizeof(rr_t) + len);
		else res = pkg_malloc(sizeof(rr_t) + len);
		if (!res) {
			LM_ERR("no shm memory left\n");
			goto error;
		}
		memcpy(res, it, sizeof(rr_t));

		res->nameaddr.name.s = (char*)res + sizeof(rr_t);
		memcpy(res->nameaddr.name.s, it->nameaddr.name.s, len);

		if (_shm) {
			ret = shm_duplicate_params(&res->params, it->params);
		} else {
			ret = duplicate_params(&res->params, it->params);
		}

		if (ret < 0) {
			LM_ERR("failed to duplicate parameters\n");
			if (_shm) shm_free(res);
			else pkg_free(res);
			goto error;
		}

		xlate_pointers(it, res);

		res->next=NULL;
		if(*_new==NULL)
			*_new = res;

		if (_first)
			return 0;

		if(prev)
			prev->next = res;
		prev = res;
		it = it->next;
	}
	return 0;
error:
	if (_shm) shm_free_rr(_new);
	else free_rr(_new);
	*_new = NULL;
	return -1;
}