rest controller update

This commit is contained in:
2018-04-25 00:04:47 +02:00
parent a539a82792
commit 3d48295a46
8 changed files with 199 additions and 17 deletions

View File

@@ -425,7 +425,7 @@ int UhttpServer::load_config_dir(const char *a_config_dir_path)
struct json_object *the_root_node;
the_rep = opendir(a_config_dir_path);
if (the_rep == NULL) {
fprintf (stderr, "Impossible to open the config directory. check your parameters.\n");
fprintf (stderr, "Impossible to open the config directory (%s).\n", a_config_dir_path);
return -1;
}
while ((the_dir_ent = readdir(the_rep)) != NULL)
@@ -469,22 +469,18 @@ int UhttpServer::add_controller_from_json(struct json_object *a_root_node)
if (json_object_object_get_ex(a_root_node, kControllerKey, &the_ctr_array_node))
{
RestController *the_rest_controller;
the_len = json_object_array_length(the_ctr_array_node);
for (i = 0; i < the_len; i++)
{
the_ctrl_node = json_object_array_get_idx(the_ctr_array_node, i);
if (get_controller_fields(the_ctrl_node, the_path, the_model_name, the_event_name, the_etag_key, the_get_method, the_set_method, the_raw_response))
the_rest_controller = new RestController;
if (the_rest_controller->from_json(the_ctrl_node))
{
#if 0
printf("Path: <%s>\n", the_path.c_str());
printf("\t- model name: <%s>\n", the_model_name.c_str());
printf("\t- get: <%s>\n", the_get_method.c_str());
printf("\t- set: <%s>\n", the_set_method.c_str());
printf("\t- raw response: <%s>\n", the_raw_response?"true":"false");
#endif
add_controller(the_path, new RestController(the_model_name, the_get_method, the_set_method, kDefaultTimeout, the_raw_response));
//new RestController(the_model_name, the_get_method, the_set_method, kDefaultTimeout, the_raw_response)
add_controller(the_path, the_rest_controller);
}
}
}
@@ -535,6 +531,7 @@ bool UhttpServer::get_controller_fields(struct json_object *a_node, std::string
std::string &a_get_method, std::string &a_set_method, bool &a_raw_response)
{
bool the_result = false;
struct json_object *the_path_node, *the_ubus_model_node, *the_ubus_event_node, *the_get_method_node, *the_etag_key_node;
struct json_object *the_set_method_node, *the_raw_response_node;