bref
API 2014 of the Zia HTTP server.
|
00001 00010 #ifndef BREF_API_PIPELINE_H 00011 #define BREF_API_PIPELINE_H 00012 00013 #include "Function.hpp" 00014 #include "IConfHelper.h" 00015 #include "BrefValue.h" 00016 #include "ILogger.h" 00017 #include "HttpRequest.h" 00018 #include "HttpResponse.h" 00019 #include "IpAddress.h" 00020 #include "Buffer.h" 00021 #include "IDisposable.h" 00022 00023 #include <list> 00024 #include <vector> 00025 #include <utility> 00026 #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) 00027 # include <windows.h> 00028 #endif 00029 00030 namespace bref { 00109 typedef BrefValue ServerConfig; 00110 00116 #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) 00117 typedef HANDLE FdType; 00118 #else 00119 typedef int FdType; 00120 #endif 00121 00132 struct Environment 00133 { 00134 const ServerConfig & serverConfig; 00135 const IConfHelper & serverConfigHelper; 00136 ILogger *logger; 00141 struct Client 00142 { 00143 IpAddress Ip; 00144 short Port; 00145 SocketType Socket; 00146 } client; 00148 Environment(const ServerConfig & theServerConfig, 00149 const IConfHelper & theServerConfigHelper, 00150 ILogger *theLogger, 00151 Client theClient) 00152 : serverConfig(theServerConfig) 00153 , serverConfigHelper(theServerConfigHelper) 00154 , logger(theLogger) 00155 , client(theClient) 00156 { } 00157 }; 00158 00164 struct Pipeline 00165 { 00200 typedef Function<bool (HttpResponse & response, 00201 const Environment & environment)> ConnectionRequestHandler; 00202 00216 typedef Function<ConnectionRequestHandler (const Environment & environment)> ConnectionHook; 00217 00229 std::list<std::pair<ConnectionHook, float> > connectionHooks; 00230 00251 typedef Function<bool (SocketType socket, 00252 Buffer & buffer)> OnReceiveRequestHandler; 00253 00266 typedef Function<OnReceiveRequestHandler (const Environment & environment)> OnReceiveHook; 00267 00280 std::list<std::pair<OnReceiveHook, float> > onReceiveHooks; 00281 00297 typedef Function<bool (SocketType socket, 00298 const Buffer & buffer)> OnSendRequestHandler; 00299 00312 typedef Function<OnSendRequestHandler (const Environment & environment)> OnSendHook; 00313 00322 std::list<std::pair<OnSendHook, float> > onSendHooks; 00323 00355 typedef Function<void (HttpResponse & response, 00356 const Buffer & inBuffer, 00357 Buffer & outBuffer)> PostReceiveRequestHandler; 00358 00370 typedef Function<PostReceiveRequestHandler (const Environment & environment)> PostReceiveHook; 00371 00381 std::list<std::pair<PostReceiveHook, float> > postReceiveHooks; 00382 00408 typedef Function<Buffer::const_iterator (HttpResponse & response, 00409 const Buffer & buff, 00410 HttpRequest & request)> ParsingRequestHandler; 00411 00420 typedef Function<ParsingRequestHandler (Environment &)> ParsingHook; 00421 00431 std::list<std::pair<ParsingHook, float> > parsingHooks; 00432 00443 typedef Function<void (HttpResponse & response)> PostParsingRequestHandler; 00444 00459 typedef Function<PostParsingRequestHandler (const Environment & environment, 00460 HttpRequest & httpRequest, 00461 HttpResponse & response)> PostParsingHook; 00462 00470 std::list<std::pair<PostParsingHook, float> > postParsingHooks; 00471 00493 class IContentRequestHandler : public IDisposable 00494 { 00495 public: 00511 virtual bool inContent(HttpResponse & response, const Buffer & inBuffer) = 0; 00512 00528 virtual bool outContent(HttpResponse & response, Buffer & outBuffer) = 0; 00529 00530 protected: 00542 virtual ~IContentRequestHandler() {} 00543 }; 00544 00561 typedef Function<IContentRequestHandler *(const Environment & environment, 00562 const HttpRequest & request, 00563 HttpResponse & response, 00564 FdType & fd)> ContentHook; 00565 00566 00576 std::list<std::pair<ContentHook, float> > contentHooks; 00577 00606 typedef Function<void (HttpResponse & reponse, 00607 const Buffer & inBuffer, 00608 Buffer & outBuffer)> PostContentRequestHandler; 00609 00618 typedef Function<PostContentRequestHandler (const Environment & environment, 00619 const HttpRequest & request, 00620 HttpResponse & response)> PostContentHook; 00621 00630 std::list<std::pair<PostContentHook, float> > postContentHooks; 00631 00632 00647 typedef Function<void (HttpResponse & response, 00648 const Buffer & inBuffer, 00649 Buffer & outBuffer)> TransformRequestHandler; 00650 00660 typedef Function<TransformRequestHandler (const Environment & environment, 00661 const HttpRequest & request, 00662 HttpResponse & response)> TransformHook; 00663 00671 std::list<std::pair<TransformHook, float> > transformHooks; 00672 00685 typedef Function<void (HttpResponse & response, 00686 const Buffer & inBuffer, 00687 Buffer & outBuffer)> PreSendRequestHandler; 00688 00697 typedef Function<PreSendRequestHandler (const Environment & environment, 00698 const HttpRequest & request, 00699 HttpResponse & response)> PreSendHook; 00700 00709 std::list<std::pair<PreSendHook, float> > preSendHooks; 00710 00713 }; 00714 00717 } // ! bref 00718 00719 #endif /* !BREF_API_PIPELINE_H */