#ifndef __FcgiFrontEnd_h_ #define __FcgiFrontEnd_h_ #include "../shared/MiscSupport.h" typedef unsigned short FcgiRequestId; class FcgiExternalActions { public: // The web server requested some action from us. virtual void newResponderRequest(FcgiRequestId id, PropertyList const ¶ms, std::string stdin) =0; virtual void abort(FcgiRequestId id) =0; // lighttpd-1.4.13 doesn't ever appear to call this! virtual void assertionFailed(std::string message) =0; virtual void debugInformation(std::string message) { } // We are sending bytes to the web server. virtual void sendBytes(std::string) =0; virtual ~FcgiExternalActions() { } }; class FcgiFrontEnd { public: typedef unsigned int AppStatus; private: class Record { public: unsigned char type; FcgiRequestId id; std::string content; std::string asString(); bool read(std::string &from); // On success return true. }; class Request { private: FcgiExternalActions * const _actions; std::string _stdIn; std::string _paramsInProgress; PropertyList _params; PropertyList _headers; FcgiRequestId _id; bool _receivedParams; bool _receivedStdIn; bool _sentSomeStdErr; bool _sentHeaders; void sendStream(unsigned char type, std::string s); void sendStdOut(std::string s); void sendStdErr(std::string s); void ensureHeadersSent(); public: Request(FcgiExternalActions * actions, FcgiRequestId id) : _actions(actions), _id(id), _receivedParams(false), _receivedStdIn(false), _sentSomeStdErr(false), _sentHeaders(false) { } void paramRecord(Record const &r); void stdInRecord(Record const &r); void setHeader(std::string name, std::string value); void clearHeader(std::string name); void sendError(std::string text); void sendBody(std::string text); void flush(); void close(AppStatus status); }; FcgiExternalActions * const _actions; std::map< FcgiRequestId, Request * > _allRequests; std::string _incoming; PropertyList _valuesForGetValues; static std::string endRequestMessage(int id, int appStatus, int protocolStatus); public: // The web server is sending bytes to us. void bytesReceived(std::string b); // We are sending something back to the web server. void setHeader(FcgiRequestId id, std::string name, std::string value); void clearHeader(FcgiRequestId id, std::string name); void sendError(FcgiRequestId id, std::string text); void sendBody(FcgiRequestId id, std::string text); void flush(FcgiRequestId id); void close(FcgiRequestId id, AppStatus status); FcgiFrontEnd(FcgiExternalActions * actions); }; #endif