diff --git a/src/datamodel.c b/src/datamodel.c index f1e0c5c7c5838987915dcdefe7310de290b8613d..be99ac01a79665b8f70b4712c109b3ba44ba38cf 100644 --- a/src/datamodel.c +++ b/src/datamodel.c @@ -218,7 +218,7 @@ static int get_SoftwareModulesExecEnv_Alias(char *refparam, struct dmctx *ctx, v static int set_SoftwareModulesExecEnv_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - char *ee_name; + char *ee_name = NULL; switch (action) { case VALUECHECK: @@ -228,6 +228,9 @@ static int set_SoftwareModulesExecEnv_Alias(char *refparam, struct dmctx *ctx, v case VALUESET: ee_name = dmjson_get_value((json_object *)data, 1, "ee_name"); + if (DM_STRLEN(ee_name) == 0) + return 0; + dmubus_call_set("swmodules", "set_config", UBUS_ARGS{ {"ee_name", ee_name, String}, {"parameter", "ee_alias", String}, @@ -399,7 +402,7 @@ static int get_SoftwareModulesDeploymentUnit_Alias(char *refparam, struct dmctx static int set_SoftwareModulesDeploymentUnit_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - char *ee_name, *uuid = NULL; + char *ee_name = NULL, *uuid = NULL; switch (action) { case VALUECHECK: @@ -410,13 +413,8 @@ static int set_SoftwareModulesDeploymentUnit_Alias(char *refparam, struct dmctx ee_name = dmjson_get_value((json_object *)data, 1, "ee_name"); uuid = dmjson_get_value((json_object *)data, 1, "uuid"); - if (ee_name == NULL || uuid == NULL) { - return 0; - } - - if (ee_name[0] == '\0' || uuid[0] == '\0') { + if (DM_STRLEN(ee_name) == 0 || DM_STRLEN(uuid) == 0) return 0; - } dmubus_call_set("swmodules", "set_config", UBUS_ARGS{ {"ee_name", ee_name, String}, @@ -597,13 +595,8 @@ static int set_SoftwareModulesExecutionUnit_Alias(char *refparam, struct dmctx * eu_name = dmjson_get_value((json_object *)data, 1, "eu_name"); eu_env = dmjson_get_value((json_object *)data, 1, "ee_name"); - if (eu_name == NULL || eu_env == NULL) { + if (DM_STRLEN(eu_name) == 0 || DM_STRLEN(eu_env) == 0) return 0; - } - - if (eu_name[0] == '\0' || eu_env[0] == '\0') { - return 0; - } dmubus_call_set("swmodules", "set_config", UBUS_ARGS{ {"ee_name", eu_env, String}, @@ -814,12 +807,12 @@ static int get_SoftwareModulesExecutionUnit_ExecutionEnvRef(char *refparam, stru *************************************************************/ static int operate_SoftwareModulesExecEnv_Reset(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - return CMD_FAIL; + return USP_FAULT_COMMAND_FAILURE; } static int operate_SoftwareModulesExecEnv_SetRunLevel(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - return CMD_FAIL; + return USP_FAULT_COMMAND_FAILURE; } static operation_args softwaremodules_installdu_args = { @@ -846,7 +839,7 @@ static int operate_SoftwareModules_InstallDU(char *refparam, struct dmctx *ctx, char *url = dmjson_get_value((json_object *)value, 1, "URL"); if (url[0] == '\0') - return CMD_INVALID_ARGUMENTS; + return USP_FAULT_INVALID_ARGUMENT; char *uuid = dmjson_get_value((json_object *)value, 1, "UUID"); char *username = dmjson_get_value((json_object *)value, 1, "Username"); @@ -859,7 +852,7 @@ static int operate_SoftwareModules_InstallDU(char *refparam, struct dmctx *ctx, } if (eeid == 0) - return CMD_FAIL; + return USP_FAULT_COMMAND_FAILURE; char eeid_str[16] = {0}; snprintf(eeid_str, sizeof(eeid_str), "%u", eeid); @@ -874,7 +867,7 @@ static int operate_SoftwareModules_InstallDU(char *refparam, struct dmctx *ctx, &res); char *status = dmjson_get_value(res, 1, "status"); - return (strcmp(status, "true") == 0) ? CMD_SUCCESS : CMD_FAIL; + return (strcmp(status, "true") == 0) ? 0 : USP_FAULT_COMMAND_FAILURE; } static operation_args softwaremodulesdeploymentunit_update_args = { @@ -899,14 +892,14 @@ int operate_SoftwareModulesDeploymentUnit_Update(char *refparam, struct dmctx *c char *url = dmjson_get_value((json_object *)value, 1, "URL"); if (url[0] == '\0') - return CMD_INVALID_ARGUMENTS; + return USP_FAULT_INVALID_ARGUMENT; char *username = dmjson_get_value((json_object *)value, 1, "Username"); char *password = dmjson_get_value((json_object *)value, 1, "Password"); char *du_uuid = dmjson_get_value((json_object *)data, 1, "uuid"); if (!du_uuid || du_uuid[0] == '\0') - return CMD_FAIL; + return USP_FAULT_COMMAND_FAILURE; // Find the uuid in config uci_foreach_sections_safe("swmodd", "du_eu_assoc", stmp, s) { @@ -919,7 +912,7 @@ int operate_SoftwareModulesDeploymentUnit_Update(char *refparam, struct dmctx *c } if (found == false) - return CMD_FAIL; + return USP_FAULT_COMMAND_FAILURE; dmuci_set_value_by_section(s, "new_url", url); dmuci_set_value_by_section(s, "username", username); @@ -945,7 +938,7 @@ static int operate_SoftwareModulesDeploymentUnit_Uninstall(char *refparam, struc char *status = dmjson_get_value(res, 1, "status"); - return (strcmp(status, "true") == 0) ? CMD_SUCCESS : CMD_FAIL; + return (strcmp(status, "true") == 0) ? 0 : USP_FAULT_COMMAND_FAILURE; } static operation_args softwaremodulesexecutionunit_setrequestedstate_args = { @@ -965,13 +958,13 @@ static int operate_SoftwareModulesExecutionUnit_SetRequestedState(char *refparam { char *req_state = dmjson_get_value((json_object *)value, 1, "RequestedState"); if (strcmp(req_state, "Idle") != 0 && strcmp(req_state, "Active") != 0) - return CMD_INVALID_ARGUMENTS; + return USP_FAULT_INVALID_ARGUMENT; char *eid = dmjson_get_value((json_object *)data, 1, "eeid"); char *name = dmjson_get_value((json_object *)data, 1, "eu_name"); if (!eid || !name) { - return CMD_FAIL; + return USP_FAULT_COMMAND_FAILURE; } dmubus_call_set("swmodules", "set_config", UBUS_ARGS{ @@ -981,7 +974,7 @@ static int operate_SoftwareModulesExecutionUnit_SetRequestedState(char *refparam {"value", req_state, String}}, 4); - return CMD_SUCCESS; + return 0; } /*************************************************************