1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef NET_TOOLS_FLIP_SERVER_STREAMER_INTERFACE_ 6 #define NET_TOOLS_FLIP_SERVER_STREAMER_INTERFACE_ 7 8 #include <string> 9 10 #include "net/tools/flip_server/balsa_headers.h" 11 #include "net/tools/flip_server/balsa_visitor_interface.h" 12 #include "net/tools/flip_server/sm_interface.h" 13 14 namespace net { 15 16 class BalsaFrame; 17 class FlipAcceptor; 18 class MemCacheIter; 19 class SMConnection; 20 class EpollServer; 21 22 class StreamerSM : public BalsaVisitorInterface, 23 public SMInterface { 24 public: 25 StreamerSM(SMConnection* connection, 26 SMInterface* sm_other_interface, 27 EpollServer* epoll_server, 28 FlipAcceptor* acceptor); 29 virtual ~StreamerSM(); 30 31 void AddToOutputOrder(const MemCacheIter& mci) {} 32 33 virtual void InitSMInterface(SMInterface* sm_other_interface, 34 int32 server_idx); 35 virtual void InitSMConnection(SMConnectionPoolInterface* connection_pool, 36 SMInterface* sm_interface, 37 EpollServer* epoll_server, 38 int fd, 39 std::string server_ip, 40 std::string server_port, 41 std::string remote_ip, 42 bool use_ssl); 43 44 virtual size_t ProcessReadInput(const char* data, size_t len); 45 virtual size_t ProcessWriteInput(const char* data, size_t len); 46 virtual bool MessageFullyRead() const; 47 virtual void SetStreamID(uint32 stream_id) {} 48 virtual bool Error() const; 49 virtual const char* ErrorAsString() const; 50 virtual void Reset(); 51 virtual void ResetForNewInterface(int32 server_idx) {} 52 virtual void ResetForNewConnection(); 53 virtual void Cleanup(); 54 virtual int PostAcceptHook(); 55 virtual void NewStream(uint32 stream_id, uint32 priority, 56 const std::string& filename) {} 57 virtual void SendEOF(uint32 stream_id) {} 58 virtual void SendErrorNotFound(uint32 stream_id) {} 59 virtual void SendOKResponse(uint32 stream_id, std::string output) {} 60 virtual size_t SendSynStream(uint32 stream_id, const BalsaHeaders& headers); 61 virtual size_t SendSynReply(uint32 stream_id, const BalsaHeaders& headers); 62 virtual void SendDataFrame(uint32 stream_id, const char* data, int64 len, 63 uint32 flags, bool compress) {} 64 virtual void set_is_request(); 65 static std::string forward_ip_header() { return forward_ip_header_; } 66 static void set_forward_ip_header(std::string value) { 67 forward_ip_header_ = value; 68 } 69 70 private: 71 void SendEOFImpl(uint32 stream_id) {} 72 void SendErrorNotFoundImpl(uint32 stream_id) {} 73 void SendOKResponseImpl(uint32 stream_id, std::string* output) {} 74 size_t SendSynReplyImpl(uint32 stream_id, const BalsaHeaders& headers) { 75 return 0; 76 } 77 size_t SendSynStreamImpl(uint32 stream_id, const BalsaHeaders& headers) { 78 return 0; 79 } 80 void SendDataFrameImpl(uint32 stream_id, const char* data, int64 len, 81 uint32 flags, bool compress) {} 82 virtual void GetOutput() {} 83 84 virtual void ProcessBodyInput(const char *input, size_t size); 85 virtual void MessageDone(); 86 virtual void ProcessHeaders(const BalsaHeaders& headers); 87 virtual void ProcessBodyData(const char *input, size_t size) {} 88 virtual void ProcessHeaderInput(const char *input, size_t size) {} 89 virtual void ProcessTrailerInput(const char *input, size_t size) {} 90 virtual void ProcessRequestFirstLine(const char* line_input, 91 size_t line_length, 92 const char* method_input, 93 size_t method_length, 94 const char* request_uri_input, 95 size_t request_uri_length, 96 const char* version_input, 97 size_t version_length) {} 98 virtual void ProcessResponseFirstLine(const char *line_input, 99 size_t line_length, 100 const char *version_input, 101 size_t version_length, 102 const char *status_input, 103 size_t status_length, 104 const char *reason_input, 105 size_t reason_length) {} 106 virtual void ProcessChunkLength(size_t chunk_length) {} 107 virtual void ProcessChunkExtensions(const char *input, size_t size) {} 108 virtual void HeaderDone() {} 109 virtual void HandleHeaderError(BalsaFrame* framer); 110 virtual void HandleHeaderWarning(BalsaFrame* framer) {} 111 virtual void HandleChunkingError(BalsaFrame* framer); 112 virtual void HandleBodyError(BalsaFrame* framer); 113 void HandleError(); 114 115 SMConnection* connection_; 116 SMInterface* sm_other_interface_; 117 EpollServer* epoll_server_; 118 FlipAcceptor* acceptor_; 119 bool is_request_; 120 BalsaFrame* http_framer_; 121 BalsaHeaders headers_; 122 static std::string forward_ip_header_; 123 }; 124 125 } // namespace net 126 127 #endif // NET_TOOLS_FLIP_SERVER_STREAMER_INTERFACE_ 128 129