Ejemplo n.º 1
0
/*
 * RPC command to print dispatcher destination sets
 */
static void dispatcher_rpc_list(rpc_t *rpc, void *ctx)
{
	void *th;
	void *ih;

	ds_set_t *ds_list = ds_get_list();
	int ds_list_nr = ds_get_list_nr();

	if(ds_list == NULL || ds_list_nr <= 0) {
		LM_ERR("no destination sets\n");
		rpc->fault(ctx, 500, "No Destination Sets");
		return;
	}

	/* add entry node */
	if(rpc->add(ctx, "{", &th) < 0) {
		rpc->fault(ctx, 500, "Internal error root reply");
		return;
	}
	if(rpc->struct_add(th, "d[", "NRSETS", ds_list_nr, "RECORDS", &ih) < 0) {
		rpc->fault(ctx, 500, "Internal error sets structure");
		return;
	}

	ds_rpc_print_set(ds_list, rpc, ctx, ih);

	return;
}
Ejemplo n.º 2
0
/*
 * RPC command to print dispatcher destination sets
 */
static void dispatcher_rpc_list(rpc_t* rpc, void* ctx)
{
	void* th;
	void* ih;
	void* vh;
	int j;
	char c[3];
	str data = {"", 0};
	ds_set_t *ds_list;
	int ds_list_nr;
	ds_set_t *list;

	ds_list = ds_get_list();
	ds_list_nr = ds_get_list_nr();

	if(ds_list==NULL || ds_list_nr<=0)
	{
		LM_ERR("no destination sets\n");
		rpc->fault(ctx, 500, "No Destination Sets");
		return;
	}

	/* add entry node */
	if (rpc->add(ctx, "{", &th) < 0)
	{
		rpc->fault(ctx, 500, "Internal error root reply");
		return;
	}
	if(rpc->struct_add(th, "d{",
				"SET_NO", ds_list_nr,
				"SET",  &ih)<0)
	{
		rpc->fault(ctx, 500, "Internal error set structure");
		return;
	}


	for(list = ds_list; list!= NULL; list= list->next)
	{
		if(rpc->struct_add(ih, "d",
					"SET_ID", list->id)<0)
		{
			rpc->fault(ctx, 500, "Internal error creating set id");
			return;
		}

		for(j=0; j<list->nr; j++)
		{
			if(rpc->struct_add(ih, "{",
						"DEST", &vh)<0)
			{
				rpc->fault(ctx, 500, "Internal error creating dest");
				return;
			}

			memset(&c, 0, sizeof(c));
			if (list->dlist[j].flags & DS_INACTIVE_DST)
				c[0] = 'I';
			else if (list->dlist[j].flags & DS_DISABLED_DST)
				c[0] = 'D';
			else if (list->dlist[j].flags & DS_TRYING_DST)
				c[0] = 'T';
			else
				c[0] = 'A';

			if (list->dlist[j].flags & DS_PROBING_DST)
				c[1] = 'P';
			else
				c[1] = 'X';

			if(rpc->struct_add(vh, "SsdS",
						"URI", &list->dlist[j].uri,
						"FLAGS", c,
						"PRIORITY", list->dlist[j].priority,
						"ATTRS", (list->dlist[j].attrs.body.s)?
						&(list->dlist[j].attrs.body):&data)<0)
			{
				rpc->fault(ctx, 500, "Internal error creating dest struct");
				return;
			}
		}
	}

	return;
}
Ejemplo n.º 3
0
/*
 * RPC command to print dispatcher destination sets
 */
static void dispatcher_rpc_list(rpc_t* rpc, void* ctx)
{
	void* th;
	void* ih;
	void* rh;
	void* sh;
	void* vh;
	void* wh;
	int j;
	char c[3];
	str data = {"", 0};
	ds_set_t *ds_list;
	int ds_list_nr;
	ds_set_t *list;

	ds_list = ds_get_list();
	ds_list_nr = ds_get_list_nr();

	if(ds_list==NULL || ds_list_nr<=0)
	{
		LM_ERR("no destination sets\n");
		rpc->fault(ctx, 500, "No Destination Sets");
		return;
	}

	/* add entry node */
	if (rpc->add(ctx, "{", &th) < 0)
	{
		rpc->fault(ctx, 500, "Internal error root reply");
		return;
	}
	if(rpc->struct_add(th, "d[",
				"NRSETS", ds_list_nr,
				"RECORDS",  &ih)<0)
	{
		rpc->fault(ctx, 500, "Internal error sets structure");
		return;
	}

	for(list = ds_list; list!= NULL; list= list->next)
	{
		if (rpc->struct_add(ih, "{", "SET", &sh) < 0)
		{
			rpc->fault(ctx, 500, "Internal error set structure");
			return;
		}
		if(rpc->struct_add(sh, "d[",
					"ID", list->id,
					"TARGETS", &rh)<0)
		{
			rpc->fault(ctx, 500, "Internal error creating set id");
			return;
		}

		for(j=0; j<list->nr; j++)
		{
			if(rpc->struct_add(rh, "{",
						"DEST", &vh)<0)
			{
				rpc->fault(ctx, 500, "Internal error creating dest");
				return;
			}

			memset(&c, 0, sizeof(c));
			if (list->dlist[j].flags & DS_INACTIVE_DST)
				c[0] = 'I';
			else if (list->dlist[j].flags & DS_DISABLED_DST)
				c[0] = 'D';
			else if (list->dlist[j].flags & DS_TRYING_DST)
				c[0] = 'T';
			else
				c[0] = 'A';

			if (list->dlist[j].flags & DS_PROBING_DST)
				c[1] = 'P';
			else
				c[1] = 'X';

			if (list->dlist[j].attrs.body.s)
			{
				if(rpc->struct_add(vh, "Ssd{",
							"URI", &list->dlist[j].uri,
							"FLAGS", c,
							"PRIORITY", list->dlist[j].priority,
							"ATTRS", &wh)<0)
				{
					rpc->fault(ctx, 500, "Internal error creating dest struct");
					return;
				}
				if(rpc->struct_add(wh, "SSdddS",
							"BODY", &(list->dlist[j].attrs.body),
							"DUID", (list->dlist[j].attrs.duid.s)?
							&(list->dlist[j].attrs.duid):&data,
							"MAXLOAD", list->dlist[j].attrs.maxload,
							"WEIGHT", list->dlist[j].attrs.weight,
							"RWEIGHT", list->dlist[j].attrs.rweight,
							"SOCKET", (list->dlist[j].attrs.socket.s)?
							&(list->dlist[j].attrs.socket):&data)<0)
				{
					rpc->fault(ctx, 500, "Internal error creating attrs struct");
					return;
				}
			} else {
				if(rpc->struct_add(vh, "Ssd",
							"URI", &list->dlist[j].uri,
							"FLAGS", c,
							"PRIORITY", list->dlist[j].priority)<0)
				{
					rpc->fault(ctx, 500, "Internal error creating dest struct");
					return;
				}
			}
		}
	}

	return;
}