Loading...
Searching...
No Matches
root_handler.h
1/*
2* Nebula Atom
3
4* This program is free software: you can redistribute it and/or modify
5* it under the terms of the GNU General Public License as published by
6* the Free Software Foundation, either version 3 of the License, or
7* (at your option) any later version.
8*
9* This program is distributed in the hope that it will be useful,
10* but WITHOUT ANY WARRANTY; without even the implied warranty of
11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12* GNU General Public License for more details.
13*
14* You should have received a copy of the GNU General Public License
15* along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#ifndef NAF_HANDLERS_ROOTHANDLER
19#define NAF_HANDLERS_ROOTHANDLER
20
21
22#include <istream>
23#include <string>
24#include <list>
25#include <map>
26#include <vector>
27#include <algorithm>
28#include <functional>
29#include <stdexcept>
30#include <memory>
31
32#include "functions/action.h"
33#include "yaml-cpp/yaml.h"
34#include "Poco/Exception.h"
35#include <Poco/Net/HTTPRequestHandler.h>
36#include <Poco/Net/HTTPServerRequest.h>
37#include <Poco/Net/HTTPResponse.h>
38#include <Poco/Net/HTTPServerResponse.h>
39#include <Poco/URI.h>
40#include <Poco/StreamCopier.h>
41#include "Poco/Data/Session.h"
42#include "Poco/Data/MySQL/Connector.h"
43#include <Poco/Data/MySQL/MySQLException.h>
44#include <Poco/Data/Statement.h>
45#include <Poco/Format.h>
46#include <Poco/NumberFormatter.h>
47#include <Poco/JSON/JSON.h>
48#include <Poco/JSON/JSONException.h>
49#include <Poco/JSON/Array.h>
50#include <Poco/JSON/Object.h>
51#include <Poco/JSON/Parser.h>
52#include <Poco/Dynamic/Var.h>
53#include <Poco/Dynamic/Struct.h>
54#include "Poco/Net/HTTPServerRequestImpl.h"
55#include "Poco/Net/SecureStreamSocket.h"
56#include "Poco/Net/SecureServerSocket.h"
57#include "Poco/Net/X509Certificate.h"
58
59#include "nebulaatomConfig.h"
60#include "tools/sessions_manager.h"
61#include "query/database_manager.h"
62#include "tools/route.h"
63#include "http/common_responses.h"
64#include "security/security_verification.h"
65#include "tools/manage_json.h"
66#include "security/user.h"
67#include "functions/functions_manager.h"
68#include "query/condition.h"
69#include "tools/settings_manager.h"
70#include "tools/output_logger.h"
71#include "http/methods.h"
72#include "http/body.h"
73
74
75namespace NAF
76{
77 namespace Handlers
78 {
79 class ReferenceContainer;
80 class RootHandler;
81 }
82}
83
84using namespace Poco;
85using namespace Poco::Net;
86using namespace Poco::Data::Keywords;
87
88using Poco::Data::Session;
89using Poco::Data::Statement;
90
91
93 public HTTPRequestHandler
95 ,public HTTP::Methods
97 ,public HTTP::Body
98{
99 public:
101 {
102 std::string method;
103 std::string uri;
104 std::string content_type;
105 Net::NameValueCollection content_type_parameters;
106 };
107
108 RootHandler();
109 virtual ~RootHandler();
110
111 struct Properties& get_properties()
112 {
113 auto& var = properties_;
114 return var;
115 }
116 std::shared_ptr<NAF::Tools::Route>& get_requested_route()
117 {
118 auto& var = requested_route_;
119 return var;
120 }
121 Functions::FunctionsManager& get_functions_manager()
122 {
123 auto& var = functions_manager_;
124 return var;
125 }
126 Functions::Function::Ptr& get_current_function()
127 {
128 auto& var = current_function_;
129 return var;
130 }
131
132 void set_current_function(Functions::Function::Ptr function) {current_function_ = function; }
133
134 virtual void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response);
135 bool SetupSSL_();
136 Functions::Function::Ptr AddFunction_(std::string endpoint, HTTP::EnumMethods method);
137 virtual void Process_() = 0;
138 bool VerifySession_();
139 bool VerifyPermissions_();
140 bool IdentifyRoute_();
141 void ManageRequestBody_();
142 void IdentifyParameters_();
143
144 protected:
145 void SetupProperties_();
146 void IdentifyParameters_(std::shared_ptr<Net::HTMLForm> form);
147 void IdentifyParameters_(Files::FileManager& files_parameters);
148 void IdentifyParameters_(JSON::Array::Ptr json_array);
149 void IdentifyParameters_(URI::QueryParameters& query_parameters);
150
151 private:
152 struct Properties properties_;
153 std::list<std::string> targets_;
154 std::shared_ptr<NAF::Tools::Route> requested_route_;
155 Functions::FunctionsManager functions_manager_;
156 Functions::Function::Ptr current_function_;
157};
158
159#endif // NAF_HANDLERS_ROOTHANDLER
Definition security_verification.h:53
Definition functions_manager.h:23
Definition body.h:52
Definition common_responses.h:69
Definition methods.h:60
Definition root_handler.h:98
Definition root_handler.h:101