• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_HTTP_INTERFACE_
6 #define NET_TOOLS_FLIP_SERVER_HTTP_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/output_ordering.h"
13 #include "net/tools/flip_server/sm_connection.h"
14 #include "net/tools/flip_server/sm_interface.h"
15 
16 namespace net {
17 
18 class BalsaFrame;
19 class DataFrame;
20 class EpollServer;
21 class FlipAcceptor;
22 class MemoryCache;
23 
24 class HttpSM : public BalsaVisitorInterface,
25                public SMInterface {
26  public:
27   HttpSM(SMConnection* connection,
28          SMInterface* sm_spdy_interface,
29          EpollServer* epoll_server,
30          MemoryCache* memory_cache,
31          FlipAcceptor* acceptor);
32   virtual ~HttpSM();
33 
34  private:
35   // BalsaVisitorInterface:
ProcessBodyInput(const char * input,size_t size)36   virtual void ProcessBodyInput(const char *input, size_t size) {}
37   virtual void ProcessBodyData(const char *input, size_t size);
ProcessHeaderInput(const char * input,size_t size)38   virtual void ProcessHeaderInput(const char *input, size_t size) {}
ProcessTrailerInput(const char * input,size_t size)39   virtual void ProcessTrailerInput(const char *input, size_t size) {}
40   virtual void ProcessHeaders(const BalsaHeaders& headers);
ProcessRequestFirstLine(const char * line_input,size_t line_length,const char * method_input,size_t method_length,const char * request_uri_input,size_t request_uri_length,const char * version_input,size_t version_length)41   virtual void ProcessRequestFirstLine(const char* line_input,
42                                        size_t line_length,
43                                        const char* method_input,
44                                        size_t method_length,
45                                        const char* request_uri_input,
46                                        size_t request_uri_length,
47                                        const char* version_input,
48                                        size_t version_length) {}
ProcessResponseFirstLine(const char * line_input,size_t line_length,const char * version_input,size_t version_length,const char * status_input,size_t status_length,const char * reason_input,size_t reason_length)49   virtual void ProcessResponseFirstLine(const char *line_input,
50                                         size_t line_length,
51                                         const char *version_input,
52                                         size_t version_length,
53                                         const char *status_input,
54                                         size_t status_length,
55                                         const char *reason_input,
56                                         size_t reason_length) {}
ProcessChunkLength(size_t chunk_length)57   virtual void ProcessChunkLength(size_t chunk_length) {}
ProcessChunkExtensions(const char * input,size_t size)58   virtual void ProcessChunkExtensions(const char *input, size_t size) {}
HeaderDone()59   virtual void HeaderDone() {}
60   virtual void MessageDone();
61   virtual void HandleHeaderError(BalsaFrame* framer);
HandleHeaderWarning(BalsaFrame * framer)62   virtual void HandleHeaderWarning(BalsaFrame* framer) {}
63   virtual void HandleChunkingError(BalsaFrame* framer);
64   virtual void HandleBodyError(BalsaFrame* framer);
65 
66   void HandleError();
67 
68  public:
69   void AddToOutputOrder(const MemCacheIter& mci);
70   void SendOKResponse(uint32 stream_id, std::string* output);
spdy_framer()71   BalsaFrame* spdy_framer() { return http_framer_; }
set_is_request()72   virtual void set_is_request() {}
73 
74   // SMInterface:
75   virtual void InitSMInterface(SMInterface* sm_spdy_interface,
76                                int32 server_idx);
77   virtual void InitSMConnection(SMConnectionPoolInterface* connection_pool,
78                                 SMInterface* sm_interface,
79                                 EpollServer* epoll_server,
80                                 int fd,
81                                 std::string server_ip,
82                                 std::string server_port,
83                                 std::string remote_ip,
84                                 bool use_ssl);
85   virtual size_t ProcessReadInput(const char* data, size_t len);
86   virtual size_t ProcessWriteInput(const char* data, size_t len);
87   virtual bool MessageFullyRead() const;
88   virtual void SetStreamID(uint32 stream_id);
89   virtual bool Error() const;
90   virtual const char* ErrorAsString() const;
91   virtual void Reset();
ResetForNewInterface(int32 server_idx)92   virtual void ResetForNewInterface(int32 server_idx) {}
93   virtual void ResetForNewConnection();
94   virtual void Cleanup();
95   virtual int PostAcceptHook();
96 
97   virtual void NewStream(uint32 stream_id, uint32 priority,
98                          const std::string& filename);
99   virtual void SendEOF(uint32 stream_id);
100   virtual void SendErrorNotFound(uint32 stream_id);
101   virtual size_t SendSynStream(uint32 stream_id, const BalsaHeaders& headers);
102   virtual size_t SendSynReply(uint32 stream_id, const BalsaHeaders& headers);
103   virtual void SendDataFrame(uint32 stream_id, const char* data, int64 len,
104                              uint32 flags, bool compress);
105 
106  private:
107   void SendEOFImpl(uint32 stream_id);
108   void SendErrorNotFoundImpl(uint32 stream_id);
109   void SendOKResponseImpl(uint32 stream_id, std::string* output);
110   size_t SendSynReplyImpl(uint32 stream_id, const BalsaHeaders& headers);
111   size_t SendSynStreamImpl(uint32 stream_id, const BalsaHeaders& headers);
112   void SendDataFrameImpl(uint32 stream_id, const char* data, int64 len,
113                          uint32 flags, bool compress);
114   void EnqueueDataFrame(DataFrame* df);
115   virtual void GetOutput();
116 
117  private:
118   uint64 seq_num_;
119   BalsaFrame* http_framer_;
120   BalsaHeaders headers_;
121   uint32 stream_id_;
122   int32 server_idx_;
123 
124   SMConnection* connection_;
125   SMInterface* sm_spdy_interface_;
126   OutputList* output_list_;
127   OutputOrdering output_ordering_;
128   MemoryCache* memory_cache_;
129   FlipAcceptor* acceptor_;
130 };
131 
132 }  // namespace
133 
134 #endif  // NET_TOOLS_FLIP_SERVER_HTTP_INTERFACE_
135 
136