wip plugin

This commit is contained in:
2018-05-10 23:30:07 +02:00
parent f00b7fefb0
commit 49972f892b
10 changed files with 69 additions and 71 deletions

View File

@@ -59,7 +59,7 @@ extern "C" {
/*------------------------------- GLOBALS ----------------------------------*/
#define kControllerKey "controller"
#define kResourcesKey "resources"
#define kEtagControllerKey "etag_controller"
#define kNotificationKey "notification"
@@ -242,12 +242,6 @@ UhttpServer::~UhttpServer(void)
{
ConnectionIterator the_cnx_it;
for (std::vector< WebController *>::iterator the_it = m_controllers.begin();
the_it != m_controllers.end(); ++the_it)
{
delete *the_it;
}
m_controllers.clear();
for (the_cnx_it = m_connections.begin(); the_cnx_it != m_connections.end(); ++the_cnx_it)
@@ -288,12 +282,12 @@ struct ubus_context *UhttpServer::get_context(void)
*/
bool UhttpServer::check_url(const std::string &an_url)
{
std::vector<WebController *>::iterator the_it;
ControllerIterator the_it;
printf("UhttpServer::check_url: %s\n", an_url.c_str());
for (the_it = m_controllers.begin(); the_it != m_controllers.end(); ++the_it)
{
if ( (*the_it)->find(an_url))
if ( the_it->second.get()->find(0, an_url))
{
return true;
}
@@ -328,7 +322,7 @@ void UhttpServer::handle_request(struct client *a_cl, const std::string &an_url,
the_url = an_url;
}
the_controller = get_controller(the_url);
the_controller = get_controller(a_cl->request.method, the_url);
if (the_controller == NULL)
{
printf ("not found :( \n");
@@ -474,7 +468,7 @@ int UhttpServer::add_controller_from_json(struct json_object *a_root_node)
int the_len;
int i;
if (json_object_object_get_ex(a_root_node, kControllerKey, &the_ctr_array_node))
if (json_object_object_get_ex(a_root_node, kResourcesKey, &the_ctr_array_node))
{
RestController *the_rest_controller;
the_len = json_object_array_length(the_ctr_array_node);
@@ -487,7 +481,7 @@ int UhttpServer::add_controller_from_json(struct json_object *a_root_node)
if (the_rest_controller->from_json(the_ctrl_node))
{
//new RestController(the_model_name, the_get_method, the_set_method, kDefaultTimeout, the_raw_response)
add_controller("", the_rest_controller);
add_controller(the_rest_controller->get_endpoint(), the_rest_controller);
}
}
}
@@ -660,18 +654,12 @@ int UhttpServer::add_controller(const std::string &an_uri, WebController *a_cont
{
std::string the_path;
std::size_t the_pos;
if (a_controller == NULL)
return -1;
if (an_uri.empty())
{
m_controllers.push_back(a_controller);
}
else {
a_controller->set_name(an_uri);
// TODO
}
a_controller->set_name(an_uri);
m_controllers[an_uri] = std::unique_ptr<WebController>(a_controller);
//m_controller_array[an_uri] = a_controller;
@@ -698,17 +686,17 @@ int UhttpServer::add_controller(const std::string &an_uri, WebController *a_cont
*
* @brief Send an error message to the client.
*/
WebController *UhttpServer::get_controller(const std::string &an_url)
WebController *UhttpServer::get_controller(uint8_t a_method, const std::string &an_url)
{
std::vector<WebController *>::iterator the_it;
ControllerIterator the_it;
WebController *the_controller = NULL;
for (the_it = m_controllers.begin(); the_it != m_controllers.end(); ++the_it)
{
if ((*the_it)->find(an_url))
if (the_it->second.get()->find(a_method, an_url))
{
printf ("return the controller.\n");
return (*the_it);
return the_it->second.get();
}
}