Skip to content

Commit

Permalink
Remove submodule_enable because useless and makes angharad crash
Browse files Browse the repository at this point in the history
  • Loading branch information
babelouest committed Mar 6, 2018
1 parent 1f7311e commit a942a2c
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 105 deletions.
86 changes: 0 additions & 86 deletions src/angharad.c
Original file line number Diff line number Diff line change
Expand Up @@ -954,91 +954,6 @@ json_t * submodule_get(struct config_elements * config, const char * submodule)
}
}

/**
* Set the db flag enabled to true or false, and init or close the specified submodule if the status has changed
*/
int submodule_enable(struct config_elements * config, const char * submodule, int enabled) {
json_t * j_submodule = submodule_get(config, submodule), * j_query;
int res;

if (j_submodule != NULL && json_integer_value(json_object_get(j_submodule, "result")) == A_OK) {
if (enabled && json_object_get(json_object_get(j_submodule, "submodule"), "enabled") == json_false()) {
json_decref(j_submodule);
// Enable disabled module
j_query = json_pack("{sss{si}s{ss}}", "table", ANGHARAD_TABLE_SUBMODULE, "set", "as_enabled", 1, "where" ,"as_name", submodule);
res = h_update(config->conn, j_query, NULL);
json_decref(j_query);
if (res == H_OK) {
if (0 == o_strcmp(submodule, ANGHARAD_SUBMODULE_BENOIC)) {
if (init_benoic(config->instance, config->url_prefix_benoic, config->b_config) != B_OK) {
y_log_message(Y_LOG_LEVEL_ERROR, "submodule_enable - Error init benoic");
return A_ERROR;
}
return A_OK;
} else if (0 == o_strcmp(submodule, ANGHARAD_SUBMODULE_CARLEON)) {
if (init_carleon(config->c_config) != C_OK) {
y_log_message(Y_LOG_LEVEL_ERROR, "submodule_enable - Error init carleon");
return A_ERROR;
}
return A_OK;
} else if (0 == o_strcmp(submodule, ANGHARAD_SUBMODULE_GARETH)) {
if (!init_gareth(config->instance, config->url_prefix_gareth, config->conn)) {
y_log_message(Y_LOG_LEVEL_ERROR, "submodule_enable - Error init gareth");
return A_ERROR;
}
return A_OK;
} else {
y_log_message(Y_LOG_LEVEL_ERROR, "submodule_enable - This shouldn't happen unless something ");
return A_ERROR;
}
} else {
y_log_message(Y_LOG_LEVEL_ERROR, "submodule_enable - Error updating submodule status in database");
return A_ERROR_DB;
}
} else if (!enabled && json_object_get(json_object_get(j_submodule, "submodule"), "enabled") == json_true()) {
json_decref(j_submodule);
// Disable enabled module
j_query = json_pack("{sss{si}s{ss}}", "table", ANGHARAD_TABLE_SUBMODULE, "set", "as_enabled", 0, "where" ,"as_name", submodule);
res = h_update(config->conn, j_query, NULL);
json_decref(j_query);
if (res == H_OK) {
if (0 == o_strcmp(submodule, ANGHARAD_SUBMODULE_BENOIC)) {
if (close_benoic(config->instance, config->url_prefix_benoic, config->b_config) != B_OK) {
y_log_message(Y_LOG_LEVEL_ERROR, "submodule_enable - Error closing benoic");
return A_ERROR;
}
return A_OK;
} else if (0 == o_strcmp(submodule, ANGHARAD_SUBMODULE_CARLEON)) {
if (close_carleon(config->c_config) != C_OK) {
y_log_message(Y_LOG_LEVEL_ERROR, "submodule_enable - Error closing carleon");
return A_ERROR;
}
return A_OK;
} else if (0 == o_strcmp(submodule, ANGHARAD_SUBMODULE_GARETH)) {
if (!close_gareth(config->instance, config->url_prefix_gareth)) {
y_log_message(Y_LOG_LEVEL_ERROR, "submodule_enable - Error closing gareth");
return A_ERROR;
}
return A_OK;
} else {
y_log_message(Y_LOG_LEVEL_ERROR, "submodule_enable - This shouldn't happen unless something ");
return A_ERROR;
}
} else {
y_log_message(Y_LOG_LEVEL_ERROR, "submodule_enable - Error updating submodule status in database");
return A_ERROR_DB;
}
} else {
json_decref(j_submodule);
return A_OK;
}
} else {
y_log_message(Y_LOG_LEVEL_ERROR, "submodule_enable - Error getting submodule %s", submodule);
json_decref(j_submodule);
return A_ERROR_NOT_FOUND;
}
}

/**
* Initializes angharad server
* Create all the endpoints
Expand All @@ -1057,7 +972,6 @@ int init_angharad(struct config_elements * config) {

ulfius_add_endpoint_by_val(config->instance, "GET", config->url_prefix_angharad, "/submodule/", ANGHARAD_CALLBACK_PRIORITY_APPLICATION, &callback_angharad_submodule_list, (void*)config);
ulfius_add_endpoint_by_val(config->instance, "GET", config->url_prefix_angharad, "/submodule/@submodule_name", ANGHARAD_CALLBACK_PRIORITY_APPLICATION, &callback_angharad_submodule_get, (void*)config);
ulfius_add_endpoint_by_val(config->instance, "GET", config->url_prefix_angharad, "/submodule/@submodule_name/enable/@enabled", ANGHARAD_CALLBACK_PRIORITY_APPLICATION, &callback_angharad_submodule_enable, (void*)config);

ulfius_add_endpoint_by_val(config->instance, "GET", config->url_prefix_angharad, "/script/", ANGHARAD_CALLBACK_PRIORITY_APPLICATION, &callback_angharad_script_list, (void*)config);
ulfius_add_endpoint_by_val(config->instance, "GET", config->url_prefix_angharad, "/script/@script_name", ANGHARAD_CALLBACK_PRIORITY_APPLICATION, &callback_angharad_script_get, (void*)config);
Expand Down
2 changes: 0 additions & 2 deletions src/angharad.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ char * get_alert_url(struct config_elements * config);
char * get_file_content(const char * file_path);

json_t * submodule_get(struct config_elements * config, const char * submodule);
int submodule_enable(struct config_elements * config, const char * submodule, int enabled);

int init_angharad(struct config_elements * config);
int close_angharad(struct config_elements * config);
Expand Down Expand Up @@ -255,7 +254,6 @@ int callback_angharad_alert (const struct _u_request * request, struct _u_respon

int callback_angharad_submodule_list (const struct _u_request * request, struct _u_response * response, void * user_data);
int callback_angharad_submodule_get (const struct _u_request * request, struct _u_response * response, void * user_data);
int callback_angharad_submodule_enable (const struct _u_request * request, struct _u_response * response, void * user_data);

int callback_angharad_script_list (const struct _u_request * request, struct _u_response * response, void * user_data);
int callback_angharad_script_get (const struct _u_request * request, struct _u_response * response, void * user_data);
Expand Down
17 changes: 0 additions & 17 deletions src/webservice.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,6 @@ int callback_angharad_submodule_get (const struct _u_request * request, struct _
}
}

int callback_angharad_submodule_enable (const struct _u_request * request, struct _u_response * response, void * user_data) {
int res;

if (user_data == NULL) {
y_log_message(Y_LOG_LEVEL_ERROR, "callback_carleon_service_element_remove_tag - Error, user_data is NULL");
return U_CALLBACK_ERROR;
} else {
res = submodule_enable((struct config_elements *)user_data, u_map_get(request->map_url, "submodule_name"), (0 == o_strcmp(u_map_get(request->map_url, "enabled"), "1")));
if (res == A_ERROR_NOT_FOUND) {
response->status = 404;
} else if (res != A_OK) {
response->status = 500;
}
return U_CALLBACK_CONTINUE;
}
}

int callback_angharad_script_list (const struct _u_request * request, struct _u_response * response, void * user_data) {
json_t * j_script;

Expand Down

0 comments on commit a942a2c

Please sign in to comment.