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 
75 namespace NAF
76 {
77  namespace Handlers
78  {
79  class ReferenceContainer;
80  class RootHandler;
81  }
82 }
83 
84 using namespace Poco;
85 using namespace Poco::Net;
86 using namespace Poco::Data::Keywords;
87 
88 using Poco::Data::Session;
89 using Poco::Data::Statement;
90 
91 
93  public HTTPRequestHandler
94  ,public HTTP::CommonResponses
95  ,public HTTP::Methods
97  ,public HTTP::Body
98 {
99  public:
100  struct Properties
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  virtual void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response);
133  bool SetupSSL_();
134  Functions::Function::Ptr AddFunction_(std::string endpoint, HTTP::EnumMethods method);
135  virtual void Process_() = 0;
136  bool VerifySession_();
137  bool VerifyPermissions_();
138  bool IdentifyRoute_();
139  void ManageRequestBody_();
140 
141  protected:
142  void SetupProperties_();
143  void IdentifyParameters_(Functions::Action::Ptr action);
144  void IdentifyParameters_();
145 
146  private:
147  struct Properties properties_;
148  std::list<std::string> targets_;
149  std::shared_ptr<NAF::Tools::Route> requested_route_;
150  Functions::FunctionsManager functions_manager_;
151  Functions::Function::Ptr current_function_;
152 };
153 
154 #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