static struct mi_root* clusterer_set_status(struct mi_root *cmd, void *param) { unsigned int cluster_id; unsigned int state; int rc; struct mi_node *node; node = cmd->node.kids; if (node == NULL || node->next == NULL || node->next->next != NULL) return init_mi_tree(400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN); 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, &state); if (rc < 0 || (state != STATE_DISABLED && state != STATE_ENABLED)) return init_mi_tree(400, MI_SSTR(MI_BAD_PARM)); rc = cl_set_state(cluster_id, state); if (rc == -1) return init_mi_tree(404, "Cluster id not found", 20); if (rc == 1) return init_mi_tree(404, "Node id not found", 17); return init_mi_tree(200, MI_SSTR(MI_OK)); }
static mi_response_t *clusterer_set_status(const mi_params_t *params, struct mi_handler *async_hdl) { int cluster_id; int state; int rc; 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, "status", &state) < 0) return init_mi_param_error(); if (state != STATE_DISABLED && state != STATE_ENABLED) return init_mi_error(400, MI_SSTR("Bad value for 'status'")); rc = cl_set_state(cluster_id, state); if (rc == -1) return init_mi_error(404, MI_SSTR("Cluster id not found")); if (rc == 1) return init_mi_error(404, MI_SSTR("Node id not found")); return init_mi_result_ok(); }