//////////////////////////////////////////////////////////////////////////////// /// DISCLAIMER /// /// Copyright 2014-2016 ArangoDB GmbH, Cologne, Germany /// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany /// /// Licensed under the Apache License, Version 2.0 (the "License"); /// you may not use this file except in compliance with the License. /// You may obtain a copy of the License at /// /// http://www.apache.org/licenses/LICENSE-2.0 /// /// Unless required by applicable law or agreed to in writing, software /// distributed under the License is distributed on an "AS IS" BASIS, /// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. /// See the License for the specific language governing permissions and /// limitations under the License. /// /// Copyright holder is ArangoDB GmbH, Cologne, Germany /// /// @author Dr. Frank Celler //////////////////////////////////////////////////////////////////////////////// #ifndef ARANGOD_HTTP_SERVER_HTTP_HANDLER_FACTORY_H #define ARANGOD_HTTP_SERVER_HTTP_HANDLER_FACTORY_H 1 #include "Basics/Common.h" #include "Basics/Mutex.h" #include "Basics/ReadWriteLock.h" #include "Rest/HttpResponse.h" namespace triagens { namespace rest { struct ConnectionInfo; class HttpHandler; class HttpRequest; class HttpResponse; //////////////////////////////////////////////////////////////////////////////// /// @brief handler factory //////////////////////////////////////////////////////////////////////////////// class HttpHandlerFactory { public: //////////////////////////////////////////////////////////////////////////////// /// @brief handler //////////////////////////////////////////////////////////////////////////////// typedef HttpHandler GeneralHandler; //////////////////////////////////////////////////////////////////////////////// /// @brief request //////////////////////////////////////////////////////////////////////////////// typedef HttpRequest GeneralRequest; //////////////////////////////////////////////////////////////////////////////// /// @brief response //////////////////////////////////////////////////////////////////////////////// typedef HttpResponse GeneralResponse; //////////////////////////////////////////////////////////////////////////////// /// @brief handler creator //////////////////////////////////////////////////////////////////////////////// typedef HttpHandler* (*create_fptr)(HttpRequest*, void*); //////////////////////////////////////////////////////////////////////////////// /// @brief context handler //////////////////////////////////////////////////////////////////////////////// typedef bool (*context_fptr)(HttpRequest*, void*); public: //////////////////////////////////////////////////////////////////////////////// /// @brief constructs a new handler factory //////////////////////////////////////////////////////////////////////////////// HttpHandlerFactory(std::string const&, int32_t, bool, context_fptr, void*); //////////////////////////////////////////////////////////////////////////////// /// @brief clones a handler factory //////////////////////////////////////////////////////////////////////////////// HttpHandlerFactory(HttpHandlerFactory const&); //////////////////////////////////////////////////////////////////////////////// /// @brief copies a handler factory //////////////////////////////////////////////////////////////////////////////// HttpHandlerFactory& operator=(HttpHandlerFactory const&); //////////////////////////////////////////////////////////////////////////////// /// @brief destructs a handler factory //////////////////////////////////////////////////////////////////////////////// virtual ~HttpHandlerFactory(); public: //////////////////////////////////////////////////////////////////////////////// /// @brief sets maintenance mode //////////////////////////////////////////////////////////////////////////////// static void setMaintenance(bool); public: //////////////////////////////////////////////////////////////////////////////// /// @brief authenticates a new request, wrapper method //////////////////////////////////////////////////////////////////////////////// HttpResponse::HttpResponseCode authenticateRequest(HttpRequest*); //////////////////////////////////////////////////////////////////////////////// /// @brief set request context, wrapper method //////////////////////////////////////////////////////////////////////////////// bool setRequestContext(HttpRequest*); //////////////////////////////////////////////////////////////////////////////// /// @brief returns the authentication realm //////////////////////////////////////////////////////////////////////////////// std::string authenticationRealm(HttpRequest*) const; //////////////////////////////////////////////////////////////////////////////// /// @brief creates a new request //////////////////////////////////////////////////////////////////////////////// HttpRequest* createRequest(ConnectionInfo const&, char const*, size_t); //////////////////////////////////////////////////////////////////////////////// /// @brief creates a new handler //////////////////////////////////////////////////////////////////////////////// HttpHandler* createHandler(HttpRequest*); //////////////////////////////////////////////////////////////////////////////// /// @brief adds a path and constructor to the factory //////////////////////////////////////////////////////////////////////////////// void addHandler(std::string const& path, create_fptr, void* data = 0); //////////////////////////////////////////////////////////////////////////////// /// @brief adds a prefix path and constructor to the factory //////////////////////////////////////////////////////////////////////////////// void addPrefixHandler(std::string const& path, create_fptr, void* data = 0); //////////////////////////////////////////////////////////////////////////////// /// @brief adds a path and constructor to the factory //////////////////////////////////////////////////////////////////////////////// void addNotFoundHandler(create_fptr); private: //////////////////////////////////////////////////////////////////////////////// /// @brief authentication realm //////////////////////////////////////////////////////////////////////////////// std::string _authenticationRealm; //////////////////////////////////////////////////////////////////////////////// /// @brief minimum compatibility /// the value is an ArangoDB version number in the following format: /// 10000 * major + 100 * minor (e.g. 10400 for ArangoDB 1.4) //////////////////////////////////////////////////////////////////////////////// int32_t _minCompatibility; //////////////////////////////////////////////////////////////////////////////// /// @brief allow overriding HTTP request method with custom headers //////////////////////////////////////////////////////////////////////////////// bool _allowMethodOverride; //////////////////////////////////////////////////////////////////////////////// /// @brief set context callback //////////////////////////////////////////////////////////////////////////////// context_fptr _setContext; //////////////////////////////////////////////////////////////////////////////// /// @brief set context data //////////////////////////////////////////////////////////////////////////////// void* _setContextData; //////////////////////////////////////////////////////////////////////////////// /// @brief list of constructors //////////////////////////////////////////////////////////////////////////////// std::unordered_map _constructors; //////////////////////////////////////////////////////////////////////////////// /// @brief list of data pointers for constructors //////////////////////////////////////////////////////////////////////////////// std::unordered_map _datas; //////////////////////////////////////////////////////////////////////////////// /// @brief list of prefix handlers //////////////////////////////////////////////////////////////////////////////// std::vector _prefixes; //////////////////////////////////////////////////////////////////////////////// /// @brief constructor for a not-found handler //////////////////////////////////////////////////////////////////////////////// create_fptr _notFound; }; } } #endif