Beispiel #1
0
static mi_response_t *cluster_send_mi(const mi_params_t *params,
								struct mi_handler *async_hdl)
{
	int cluster_id, node_id;
	int rc;
	str cmd_name;
	mi_item_t *cmd_params_arr = NULL;
	int no_params = 0;

	if (get_mi_int_param(params, "cluster_id", &cluster_id) < 0)
		return init_mi_param_error();
	if (cluster_id < 1)
		return init_mi_error(400, MI_SSTR("Bad value for 'cluster_id'"));

	if (get_mi_int_param(params, "destination", &node_id) < 0)
		return init_mi_param_error();
	if (node_id < 1)
		return init_mi_error(400, MI_SSTR("Bad value for 'destination'"));
	if (node_id == current_id)
		return init_mi_error(400, MI_SSTR("Local node specified as destination"));

	if (get_mi_string_param(params, "cmd_name", &cmd_name.s, &cmd_name.len) < 0)
		return init_mi_param_error();

	rc = try_get_mi_array_param(params, "cmd_params", &cmd_params_arr, &no_params);
	if (rc < 0) {
		cmd_params_arr = NULL;
		if (rc == -2)
			return init_mi_param_error();
	}

	rc = send_mi_cmd(cluster_id, node_id, cmd_name, cmd_params_arr, no_params);
	switch (rc) {
		case CLUSTERER_SEND_SUCCES:
			LM_DBG("MI command <%.*s> sent\n", cmd_name.len, cmd_name.s);
			return init_mi_result_ok();
		case CLUSTERER_CURR_DISABLED:
			LM_INFO("Local node disabled, MI command <%.*s> not sent\n",
				cmd_name.len, cmd_name.s);
			return init_mi_result_string(MI_SSTR("Local node disabled"));
		case CLUSTERER_DEST_DOWN:
			LM_ERR("Destination down, MI command <%.*s> not sent\n",
				cmd_name.len, cmd_name.s);
			return init_mi_error(400, MI_SSTR("Destination down"));
		case CLUSTERER_SEND_ERR:
			LM_ERR("Error sending MI command <%.*s>+\n",
				cmd_name.len, cmd_name.s);
			return init_mi_error(400, MI_SSTR("Send error"));
		default:
			LM_BUG("Bad send error code\n");
			return init_mi_error(400, MI_SSTR("Internal error"));
	}
}
Beispiel #2
0
static struct mi_root* cluster_bcast_mi(struct mi_root *cmd, void *param)
{
	struct mi_node *node, *cmd_params_n;
	struct mi_cmd *f;
	unsigned int cluster_id;
	int rc;
	str cl_cmd_name;
	str cl_cmd_params[MI_CMD_MAX_NR_PARAMS];
	int no_params = 0;

	node = cmd->node.kids;

	if (node == NULL || node->next == NULL || node->next->next == NULL)
		return init_mi_tree(400, MI_SSTR(MI_MISSING_PARM));

	rc = str2int(&node->value, &cluster_id);
	if (rc < 0 || cluster_id < 1)
		return init_mi_tree(400, MI_SSTR(MI_BAD_PARM));

	cl_cmd_name = node->next->value;

	f = lookup_mi_cmd(cl_cmd_name.s, cl_cmd_name.len);
	if (!f)
		return init_mi_tree(400, MI_SSTR("MI command to be run not found"));

	cmd_params_n = node->next->next;
	for (; cmd_params_n; cmd_params_n = cmd_params_n->next, no_params++)
		cl_cmd_params[no_params] = cmd_params_n->value;

	/* send MI cmd in cluster */
	rc = send_mi_cmd(cluster_id, 0, cl_cmd_name, cl_cmd_params, no_params);
	switch (rc) {
		case CLUSTERER_SEND_SUCCES:
			LM_DBG("MI command <%.*s> sent\n", cl_cmd_name.len, cl_cmd_name.s);
			break;
		case CLUSTERER_CURR_DISABLED:
			LM_INFO("Local node disabled, MI command <%.*s> not sent\n",
				cl_cmd_name.len, cl_cmd_name.s);
			break;
		case CLUSTERER_DEST_DOWN:
			LM_ERR("All nodes down, MI command <%.*s> not sent\n",
				cl_cmd_name.len, cl_cmd_name.s);
			break;
		case CLUSTERER_SEND_ERR:
			LM_ERR("Error sending MI command <%.*s>+\n",
				cl_cmd_name.len, cl_cmd_name.s);
			break;
	}

	/* run MI cmd locally */
	return run_mi_cmd_local(f, cl_cmd_params, no_params, cmd->async_hdl);
}
Beispiel #3
0
static struct mi_root* cluster_send_mi(struct mi_root *cmd, void *param)
{
	struct mi_node *node, *cmd_params_n;
	unsigned int cluster_id, node_id;
	int rc;
	str cl_cmd_name;
	str cl_cmd_params[MI_CMD_MAX_NR_PARAMS];
	int no_params = 0;

	node = cmd->node.kids;

	if (node == NULL || node->next == NULL || node->next->next == NULL)
		return init_mi_tree(400, MI_SSTR(MI_MISSING_PARM));

	rc = str2int(&node->value, &cluster_id);
	if (rc < 0 || cluster_id < 1)
		return init_mi_tree(400, MI_SSTR(MI_BAD_PARM));

	rc = str2int(&node->next->value, &node_id);
	if (rc < 0 || node_id < 1)
		return init_mi_tree(400, MI_SSTR(MI_BAD_PARM));
	if (node_id == current_id)
		return init_mi_tree(400, MI_SSTR("Local node specified as destination"));

	cl_cmd_name = node->next->next->value;

	cmd_params_n = node->next->next->next;
	for (; cmd_params_n; cmd_params_n = cmd_params_n->next, no_params++)
		cl_cmd_params[no_params] = cmd_params_n->value;

	/* send MI cmd in cluster */
	rc = send_mi_cmd(cluster_id, node_id, cl_cmd_name, cl_cmd_params, no_params);
	switch (rc) {
		case CLUSTERER_SEND_SUCCES:
			LM_DBG("MI command <%.*s> sent\n", cl_cmd_name.len, cl_cmd_name.s);
			break;
		case CLUSTERER_CURR_DISABLED:
			LM_INFO("Local node disabled, MI command <%.*s> not sent\n",
				cl_cmd_name.len, cl_cmd_name.s);
			break;
		case CLUSTERER_DEST_DOWN:
			LM_ERR("Destination down, MI command <%.*s> not sent\n",
				cl_cmd_name.len, cl_cmd_name.s);
			break;
		case CLUSTERER_SEND_ERR:
			LM_ERR("Error sending MI command <%.*s>+\n",
				cl_cmd_name.len, cl_cmd_name.s);
			break;
	}

	return init_mi_tree(200, MI_SSTR(MI_OK));
}
Beispiel #4
0
static mi_response_t *cluster_bcast_mi(const mi_params_t *params,
								struct mi_handler *async_hdl)
{
	int cluster_id;
	int rc;
	str cmd_name;
	mi_item_t *cmd_params_arr = NULL;
	int no_params = 0;

	if (get_mi_int_param(params, "cluster_id", &cluster_id) < 0)
		return init_mi_param_error();
	if (cluster_id < 1)
		return init_mi_error(400, MI_SSTR("Bad value for 'cluster_id'"));

	if (get_mi_string_param(params, "cmd_name", &cmd_name.s, &cmd_name.len) < 0)
		return init_mi_param_error();

	rc = try_get_mi_array_param(params, "cmd_params", &cmd_params_arr, &no_params);
	if (rc < 0) {
		cmd_params_arr = NULL;
		if (rc == -2)
			return init_mi_param_error();
	}

	rc = send_mi_cmd(cluster_id, 0, cmd_name, cmd_params_arr, no_params);
	switch (rc) {
		case CLUSTERER_SEND_SUCCES:
			LM_DBG("MI command <%.*s> sent\n", cmd_name.len, cmd_name.s);
			break;
		case CLUSTERER_CURR_DISABLED:
			LM_INFO("Local node disabled, MI command <%.*s> not sent\n",
				cmd_name.len, cmd_name.s);
			break;
		case CLUSTERER_DEST_DOWN:
			LM_ERR("All nodes down, MI command <%.*s> not sent\n",
				cmd_name.len, cmd_name.s);
			break;
		case CLUSTERER_SEND_ERR:
			LM_ERR("Error sending MI command <%.*s>+\n",
				cmd_name.len, cmd_name.s);
			break;
	}

	return run_mi_cmd_local(&cmd_name, cmd_params_arr, no_params);
}