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 "yaml-cpp/yaml.h"
33 #include "Poco/Exception.h"
34 #include <Poco/Net/HTTPRequestHandler.h>
35 #include <Poco/Net/HTTPServerRequest.h>
36 #include <Poco/Net/HTTPResponse.h>
37 #include <Poco/Net/HTTPServerResponse.h>
38 #include <Poco/URI.h>
39 #include <Poco/StreamCopier.h>
40 #include "Poco/Data/Session.h"
41 #include "Poco/Data/MySQL/Connector.h"
42 #include <Poco/Data/MySQL/MySQLException.h>
43 #include <Poco/Data/Statement.h>
44 #include <Poco/Format.h>
45 #include <Poco/NumberFormatter.h>
46 #include <Poco/JSON/JSON.h>
47 #include <Poco/JSON/JSONException.h>
48 #include <Poco/JSON/Array.h>
49 #include <Poco/JSON/Object.h>
50 #include <Poco/JSON/Parser.h>
51 #include <Poco/Dynamic/Var.h>
52 #include <Poco/Dynamic/Struct.h>
53 #include "Poco/Net/HTTPServerRequestImpl.h"
54 #include "Poco/Net/SecureStreamSocket.h"
55 #include "Poco/Net/SecureServerSocket.h"
56 #include "Poco/Net/X509Certificate.h"
57 
58 #include "nebulaatomConfig.h"
59 #include "tools/sessions_manager.h"
60 #include "query/database_manager.h"
61 #include "tools/route.h"
62 #include "http/common_responses.h"
63 #include "security/security_verification.h"
64 #include "tools/manage_json.h"
65 #include "security/user.h"
66 #include "functions/functions_manager.h"
67 #include "query/condition.h"
68 #include "tools/settings_manager.h"
69 #include "tools/output_logger.h"
70 #include "http/methods.h"
71 #include "http/body.h"
72 
73 
74 namespace NAF
75 {
76  namespace Handlers
77  {
78  class ReferenceContainer;
79  class RootHandler;
80  }
81 }
82 
83 using namespace Poco;
84 using namespace Poco::Net;
85 using namespace Poco::Data::Keywords;
86 
87 using Poco::Data::Session;
88 using Poco::Data::Statement;
89 
90 
92  public HTTPRequestHandler
93  ,public HTTP::CommonResponses
94  ,public HTTP::Methods
96  ,public HTTP::Body
97 {
98  public:
99  struct Properties
100  {
101  std::string method;
102  std::string uri;
103  std::string content_type;
104  Net::NameValueCollection content_type_parameters;
105  };
106 
107  RootHandler();
108  virtual ~RootHandler();
109 
110  struct Properties& get_properties()
111  {
112  auto& var = properties_;
113  return var;
114  }
115  std::shared_ptr<NAF::Tools::Route>& get_requested_route()
116  {
117  auto& var = requested_route_;
118  return var;
119  }
120  Functions::FunctionsManager& get_functions_manager()
121  {
122  auto& var = functions_manager_;
123  return var;
124  }
125  Functions::Function::Ptr& get_current_function()
126  {
127  auto& var = current_function_;
128  return var;
129  }
130 
131  virtual void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response);
132  bool SetupSSL_();
133  Functions::Function::Ptr AddFunction_(std::string endpoint, HTTP::EnumMethods method);
134  virtual void Process_() = 0;
135  bool VerifySession_();
136  bool VerifyPermissions_();
137  bool IdentifyRoute_();
138  void ManageRequestBody_();
139 
140  protected:
141  void SetupProperties_();
142 
143  private:
144  struct Properties properties_;
145  std::list<std::string> targets_;
146  std::shared_ptr<NAF::Tools::Route> requested_route_;
147  Functions::FunctionsManager functions_manager_;
148  Functions::Function::Ptr current_function_;
149 };
150 
151 #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:59
Definition: root_handler.h:97
Definition: root_handler.h:100