diff --git a/src/plugins/uhttpd/uhttpd-rest-api/core/web-controller.cpp b/src/plugins/uhttpd/uhttpd-rest-api/core/web-controller.cpp index de85bd57..1418339b 100644 --- a/src/plugins/uhttpd/uhttpd-rest-api/core/web-controller.cpp +++ b/src/plugins/uhttpd/uhttpd-rest-api/core/web-controller.cpp @@ -94,3 +94,13 @@ WebConnection *WebController::new_connection(struct uhttpd_ops *an_ops, struct c { return new WebConnection(an_ops, a_client); } + +/*! ---------------------------------------------------------------------------- + * @fn find + * + * @brief return true if the controller match with the url. + */ +bool WebController::find(const std::string &an_url) +{ + return true; +} diff --git a/src/plugins/uhttpd/uhttpd-rest-api/core/web-controller.h b/src/plugins/uhttpd/uhttpd-rest-api/core/web-controller.h index 51dfc425..bf6cc48b 100644 --- a/src/plugins/uhttpd/uhttpd-rest-api/core/web-controller.h +++ b/src/plugins/uhttpd/uhttpd-rest-api/core/web-controller.h @@ -44,6 +44,8 @@ class WebController WebController(const std::string &a_path); virtual ~WebController(void); + virtual bool find(const std::string &an_url); + void set_name(const std::string &a_name); const std::string &get_name(void); diff --git a/src/plugins/uhttpd/uhttpd-rest-api/rest/rest-controller.cpp b/src/plugins/uhttpd/uhttpd-rest-api/rest/rest-controller.cpp index 8d1bc8d4..8f671af5 100644 --- a/src/plugins/uhttpd/uhttpd-rest-api/rest/rest-controller.cpp +++ b/src/plugins/uhttpd/uhttpd-rest-api/rest/rest-controller.cpp @@ -142,6 +142,18 @@ bool RestController::from_json(struct json_object *a_node) } + +/*! ---------------------------------------------------------------------------- + * @fn find + * + * @brief return true if the controller match with the url. + */ +bool RestController::find(const std::string &an_url) +{ + return true; +} + + /*! ---------------------------------------------------------------------------- * @fn get_method_get * diff --git a/src/plugins/uhttpd/uhttpd-rest-api/rest/rest-controller.h b/src/plugins/uhttpd/uhttpd-rest-api/rest/rest-controller.h index efe2aae5..365ff15f 100644 --- a/src/plugins/uhttpd/uhttpd-rest-api/rest/rest-controller.h +++ b/src/plugins/uhttpd/uhttpd-rest-api/rest/rest-controller.h @@ -56,6 +56,9 @@ class RestController : public WebController bool from_json(struct json_object *a_node); + bool find(const std::string &an_url); + + std::string get_method_get(void); std::string get_method_put(void); uint16_t get_timeout(void); diff --git a/src/plugins/uhttpd/uhttpd-rest-api/uhttp-server.cpp b/src/plugins/uhttpd/uhttpd-rest-api/uhttp-server.cpp index f8d12843..f3cd70c1 100644 --- a/src/plugins/uhttpd/uhttpd-rest-api/uhttp-server.cpp +++ b/src/plugins/uhttpd/uhttpd-rest-api/uhttp-server.cpp @@ -240,13 +240,16 @@ UhttpServer::UhttpServer(void) : m_ctx(NULL), */ UhttpServer::~UhttpServer(void) { - ControllerIterator it; ConnectionIterator the_cnx_it; - for (it = m_controller_array.begin(); it != m_controller_array.end(); ++it) + + for (std::vector< WebController *>::iterator the_it = m_controllers.begin(); + the_it != m_controllers.end(); ++the_it) { - delete it->second; + delete *the_it; } + m_controllers.clear(); + for (the_cnx_it = m_connections.begin(); the_cnx_it != m_connections.end(); ++the_cnx_it) { delete the_cnx_it->second; @@ -285,13 +288,15 @@ struct ubus_context *UhttpServer::get_context(void) */ bool UhttpServer::check_url(const std::string &an_url) { - std::list::iterator the_it; - // printf("UhttpServer::check_url: %s\n", an_url.c_str()); + std::vector::iterator the_it; + printf("UhttpServer::check_url: %s\n", an_url.c_str()); - for (the_it = m_path_list.begin(); the_it != m_path_list.end(); the_it++) + for (the_it = m_controllers.begin(); the_it != m_controllers.end(); ++the_it) { - if (an_url.find(*the_it) != std::string::npos) + if ( (*the_it)->find(an_url)) + { return true; + } } return false; @@ -307,7 +312,7 @@ void UhttpServer::handle_request(struct client *a_cl, const std::string &an_url, std::string the_url, the_parameters; std::size_t the_pos; WebController *the_controller; - // printf("uhttp_server_handle_request : url: <%s> client: %p\n", an_url.c_str(), a_cl); + printf("uhttp_server_handle_request : url: <%s> client: %p\n", an_url.c_str(), a_cl); // Check if parameters are present on the url. the_pos = an_url.find_first_of("?", 0); @@ -323,7 +328,8 @@ void UhttpServer::handle_request(struct client *a_cl, const std::string &an_url, the_url = an_url; } - the_controller = m_controller_array[the_url]; +#warning todo +// the_controller = m_controller_array[the_url]; if (the_controller == NULL) { std::string the_msg; @@ -657,10 +663,11 @@ int UhttpServer::add_controller(const std::string &an_uri, WebController *a_cont return -1; a_controller->set_name(an_uri); - m_controller_array[an_uri] = a_controller; + //m_controller_array[an_uri] = a_controller; - // printf("add: an_uri:%s\n", an_uri.c_str()); + printf("add: an_uri:%s\n", an_uri.c_str()); +#if 0 // Keep a list of the API root. to check if a controller is managed by this plugin or not. the_pos = an_uri.find_first_of("/", 1); if (the_pos != std::string::npos) @@ -672,7 +679,7 @@ int UhttpServer::add_controller(const std::string &an_uri, WebController *a_cont m_path_list.push_back(the_path); } } - +#endif return 0; } diff --git a/src/plugins/uhttpd/uhttpd-rest-api/uhttp-server.h b/src/plugins/uhttpd/uhttpd-rest-api/uhttp-server.h index de378307..66631d22 100644 --- a/src/plugins/uhttpd/uhttpd-rest-api/uhttp-server.h +++ b/src/plugins/uhttpd/uhttpd-rest-api/uhttp-server.h @@ -80,7 +80,7 @@ class UhttpServer private: struct ubus_context *m_ctx; struct uhttpd_ops *m_ops; - ControllerContainer m_controller_array; + std::vector< WebController *> m_controllers; ConnectionContainer m_connections; std::list m_path_list; };