Beispiel #1
0
int fixup_int_list(void **param)
{
	str input = {(char*)(*param), strlen((char*)(*param))};
	int_list_t *lst;
	if (set_list_from_string(input, &lst) != 0 || lst == NULL)
		return -1;
	*param = (void*)(lst);
	return 0;
}
Beispiel #2
0
/* Load setids this proxy is responsible for probing into list */
static int set_probing_list(unsigned int type, void *val) {
	str input = {(char*)val, strlen(val)};

        if (set_list_from_string(input, &ds_probing_list) != 0 ||
            ds_probing_list == NULL)
        {
            LM_ERR("Invalid set_probing_list input\n");
            return -1;
        }

        return 0;
}
Beispiel #3
0
static int fixup_partition_sets_null(void **param)
{
	str s_param = {(char*)*param, strlen(*param)};
	str part_name = {NULL, 0};

	char *delim = q_memchr(s_param.s, DS_PARTITION_DELIM, s_param.len);

	if (delim) {
		part_name.s = s_param.s;
		part_name.len = delim - s_param.s;
		s_param.s = delim + 1;
		s_param.len -= part_name.len + 1;
		trim(&part_name);
	}

	trim(&s_param);

	ds_param_t *final_param = shm_malloc(sizeof (ds_param_t));

	if (final_param == NULL) {
		LM_CRIT ("no more shared memory!\n");
		return -1;
	}

	if (get_gpart(&part_name, &final_param->partition) != 0) {
		shm_free(final_param);
		return -1;
	}

	if ((set_list_from_string(s_param, &final_param->sets)) != 0){
		shm_free(final_param);
		return -1;
	}

	*param = (void*)final_param;
	return 0;
}
Beispiel #4
0
static int w_ds_select(struct sip_msg* msg, char* part_set, char* alg,
											char* max_results_flags, int mode)
{
	int ret = -1;
	int _ret;
	int run_prev_ds_select = 0;
	ds_select_ctl_t prev_ds_select_ctl, ds_select_ctl;
	char selected_dst_sock_buf[PTR_STRING_SIZE]; /* a hexa string */
	ds_selected_dst selected_dst;
	struct socket_info *sock = NULL;

	if(msg==NULL)
		return -1;

	ds_select_ctl.mode = mode;
	ds_select_ctl.max_results = 1000;
	ds_select_ctl.reset_AVP = 1;
	ds_select_ctl.set_destination = 1;
	ds_select_ctl.ds_flags = 0;

	memset(&selected_dst, 0, sizeof(ds_selected_dst));
	selected_dst.socket.s = selected_dst_sock_buf;

	/* Retrieve dispatcher set */
	ds_param_t *part_set_param = (ds_param_t*)part_set;

	if (fixup_get_partition(msg, &part_set_param->partition,
			&ds_select_ctl.partition) != 0 ||ds_select_ctl.partition == NULL) {
		LM_ERR("unknown partition\n");
		return -1;
	}

	int_list_t *set_list = part_set_param->sets;
	int_list_t *set_list_exp_start = NULL, *set_list_exp_end = NULL;

	/* Retrieve dispatcher algorithm */
	int_list_t *alg_list = (int_list_t *)alg;
	int_list_t *alg_list_exp_start = NULL, *alg_list_exp_end = NULL;

	/* In case this parameter is not specified */
	max_list_param_p max_param = (max_list_param_p)max_results_flags;
	str max_list_str;

	int_list_t *max_list=NULL, *max_list_free;
	if (max_param && max_param->type == MAX_LIST_TYPE_STR) {
		max_list = (int_list_t*)max_param->lst.list;
	} else if (max_param && max_param->type == MAX_LIST_TYPE_PV) {
		if (pv_printf_s(msg, max_param->lst.elem, &max_list_str) != 0) {
			LM_ERR("cannot get max list from pv\n");
			return -1;
		}

		if (set_list_from_string(max_list_str, &max_list) != 0
				|| max_list == NULL)
			return -1;
	}

	/* Avoid compiler warning */
	memset(&prev_ds_select_ctl, 0, sizeof(ds_select_ctl_t));

	ds_select_ctl.set_destination = 0;

	/* Parse the params in reverse order.
	 * We need to runt the first entry last to properly populate ds_select_dst
	 *  AVPs.
	 * On the first ds_select_dst run we need to reset AVPs.
	 * On the last ds_select_dst run we need to set destination.  */
	do {
		CHECK_AND_EXPAND_LIST(set_list);
		ds_select_ctl.set = set_list->v.ival;

		CHECK_AND_EXPAND_LIST(alg_list);
		ds_select_ctl.alg = alg_list->v.ival;

		if (max_results_flags) {
			ds_select_ctl.max_results = max_list->v.ival;
			ds_select_ctl.ds_flags    = max_list->flags;
		}

		if (run_prev_ds_select) {
			LM_DBG("ds_select: %d %d %d %d %d\n",
				prev_ds_select_ctl.set, prev_ds_select_ctl.alg,
				prev_ds_select_ctl.max_results,
				prev_ds_select_ctl.reset_AVP,
				prev_ds_select_ctl.set_destination);
			_ret = ds_select_dst(msg, &prev_ds_select_ctl, &selected_dst,
				prev_ds_select_ctl.ds_flags);
			if (_ret>=0) ret = _ret;
			/* stop resetting AVPs. */
			ds_select_ctl.reset_AVP = 0;
		} else {
			/* Enable running ds_select_dst on next loop. */
			run_prev_ds_select = 1;
		}
		prev_ds_select_ctl = ds_select_ctl;

		set_list = set_list->next;
		alg_list = alg_list->next;
		if (max_results_flags) {
			max_list_free = max_list;
			max_list = max_list->next;

			if (max_param->type == MAX_LIST_TYPE_PV)
				pkg_free(max_list_free);
		}

		TRY_FREE_EXPANDED_LIST(set_list);
		TRY_FREE_EXPANDED_LIST(alg_list);

	} while (set_list && alg_list &&
			(max_results_flags ? max_list : set_list));

	if (max_results_flags &&  max_list != NULL) {
		LM_ERR("extra max slot(s) and/or flag(s)\n");
		ret = -2;
		goto error;
	}

	if (set_list != NULL) {
		LM_ERR("extra set(s)\n");
		ret = -2;
		goto error;
	}

	if (alg_list != NULL) {
		LM_ERR("extra algorithm(s)\n");
		ret = -2;
		goto error;
	}

	/* last ds_select_dst run: setting destination. */
	ds_select_ctl.set_destination = 1;
	LM_DBG("ds_select: %d %d %d %d %d\n",
		ds_select_ctl.set, ds_select_ctl.alg, ds_select_ctl.max_results,
		ds_select_ctl.reset_AVP, ds_select_ctl.set_destination);
	_ret = ds_select_dst(msg, &ds_select_ctl, &selected_dst,
		ds_select_ctl.ds_flags);
	if (_ret>=0) {
		ret = _ret;
	}
	else {
		if (selected_dst.uri.s != NULL) {
			if (selected_dst.socket.len != 0) {
				if (sscanf( selected_dst.socket.s, "%p", (void**)&sock ) != 1){
					LM_ERR("unable to read forced destination socket\n");
					ret = -4;
					goto error;
				}
			}
			if (ds_update_dst(msg, &selected_dst.uri, sock, ds_select_ctl.mode)
			!= 0) {
				LM_ERR("cannot set dst addr\n");
				ret = -3;
				goto error;
			}
		}
		else {
			ret = -1;
			goto error;
		}
	}

error:
	if (selected_dst.uri.s != NULL) pkg_free(selected_dst.uri.s);
	return ret;
}