Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / apps / JAWS / server / HTTP_Handler.h
blobcc0226fe81af3338933697a59c709cd702db1ef0
1 /* -*- c++ -*- */
3 //=============================================================================
4 /**
5 * @file HTTP_Handler.h
7 * @author James Hu and Irfan Pyarali
8 */
9 //=============================================================================
12 #ifndef HTTP_HANDLER_H
13 #define HTTP_HANDLER_H
15 // = Forward declarations
16 class Message_Block;
17 class HTTP_Handler_Factory;
19 #include "ace/Asynch_IO.h"
21 #if !defined (ACE_LACKS_PRAGMA_ONCE)
22 # pragma once
23 #endif /* ACE_LACKS_PRAGMA_ONCE */
25 #include "HTTP_Request.h"
26 #include "HTTP_Response.h"
27 #include "JAWS_IO.h"
29 /**
30 * @class HTTP_Handler
32 * @brief This class is used to implement the HTTP protocol
34 * The HTTP_Handler class is a state based implementation of the
35 * HTTP protocol. Therefore, it can be used synchronously and
36 * asynchronously. It uses an abstract IO class to move between
37 * different HTTP protocol states. It is up to the IO class to
38 * decide on synchronous or asynchronous I/O.
40 class HTTP_Handler : protected JAWS_IO_Handler
42 // Friend I/O classes. Can call protected methods.
43 friend class JAWS_Synch_IO;
44 friend class JAWS_Synch_IO_No_Cache;
45 friend class JAWS_Asynch_IO;
47 // Factories
48 friend class Asynch_HTTP_Handler_Factory;
49 friend class Synch_HTTP_Handler_Factory;
50 friend class No_Cache_Synch_HTTP_Handler_Factory;
52 public:
53 /**
54 * The handler is initialized with a connection <handle> of a new
55 * client and any <initial_data> that came across. The
56 * <initial_data> block will be of MAX_REQUEST_SIZE and the number
57 * of bytes in <initial_data> can be found from
58 * <initial_data>.length ()
60 virtual void open (ACE_HANDLE handle,
61 ACE_Message_Block &initial_data);
63 protected:
64 /// The constructor is passed the factory that created <this> and the
65 /// IO mechanism that the handler should use.
66 HTTP_Handler (JAWS_IO &io,
67 HTTP_Handler_Factory &factory);
69 /// Destructor
70 virtual ~HTTP_Handler ();
72 /// This method is called by the framework when there is a timeout.
73 virtual void timeout ();
75 /**
76 * This is the termination state of the handler. After successful or
77 * unsuccessful completions, the handler will end up in this state
78 * (method).
80 virtual void done ();
82 /// Request too long.
83 virtual void request_too_long ();
85 /// Reference to the creating factory.
86 HTTP_Handler_Factory &factory_;
88 protected:
89 // = Completion methods inherited from <JAWS_IO_Handler>.
91 virtual void read_complete (ACE_Message_Block &data);
92 virtual void read_error ();
93 virtual void transmit_file_complete ();
94 virtual void transmit_file_error (int result);
95 virtual void receive_file_complete ();
96 virtual void receive_file_error (int result);
97 virtual void write_error ();
98 virtual void confirmation_message_complete ();
99 virtual void error_message_complete ();
101 public:
102 enum
104 MAX_SOCKBUFSIZE = 64 * 1024,
105 MAX_REQUEST_SIZE = 8192,
106 METHODSIZ = 10,
107 VERSIONSIZ = 10
110 private:
111 /// This points to the request sent by the client
112 ACE_Message_Block *request_data_;
114 /// I/O handle to the client
115 ACE_HANDLE handle_;
117 HTTP_Request request_;
118 HTTP_Response response_;
120 /// IO class used by the handler
121 JAWS_IO &io_;
125 * @class HTTP_Handler_Factory
127 * @brief This class is used to create new HTTP handlers
129 * This is an abstract factory for creating new HTTP handlers.
131 class HTTP_Handler_Factory
133 public:
134 /// Destructor
135 virtual ~HTTP_Handler_Factory ();
137 /// This creates a new HTTP_Handler
138 virtual HTTP_Handler *create_http_handler () = 0;
141 * The HTTP handler will call this method from HTTP_Handler::done to
142 * tell the factory to reap up the handler as it is now done with
143 * the protocol
145 virtual void destroy_http_handler (HTTP_Handler &handler,
146 JAWS_IO &io) = 0;
150 * @class Synch_HTTP_Handler_Factory
152 * @brief This class is used to create new HTTP handlers that will use
153 * Synch IO
155 class Synch_HTTP_Handler_Factory : public HTTP_Handler_Factory
157 public:
158 /// This creates a new HTTP_Handler
159 HTTP_Handler *create_http_handler ();
162 * The HTTP handler will call this method from HTTP_Handler::done to
163 * tell the factory to reap up the handler as it is now done with
164 * the protocol
166 void destroy_http_handler (HTTP_Handler &handler,
167 JAWS_IO &io);
170 //--------------Added a factory for SYNCH IO without caching
173 * @class No_Cache_Synch_HTTP_Handler_Factory
175 * @brief This class is used to create new HTTP handlers that will use
176 * Synch IO without caching
178 class No_Cache_Synch_HTTP_Handler_Factory : public HTTP_Handler_Factory
180 public:
181 /// This creates a new HTTP_Handler
182 HTTP_Handler *create_http_handler ();
185 * The HTTP handler will call this method from HTTP_Handler::done to
186 * tell the factory to reap up the handler as it is now done with
187 * the protocol
189 void destroy_http_handler (HTTP_Handler &handler,
190 JAWS_IO &io);
193 //--------------
195 #if defined (ACE_HAS_WIN32_OVERLAPPED_IO)
197 * @class Asynch_HTTP_Handler_Factory
199 * @brief This class is used to create new HTTP handlers that will use
200 * Asynchronous IO. This only works on Win32.
202 class Asynch_HTTP_Handler_Factory : public HTTP_Handler_Factory, public ACE_Service_Handler
204 public:
206 * The HTTP handler will call this method from HTTP_Handler::done to
207 * tell the factory to reap up the handler as it is now done with
208 * the protocol
210 void destroy_http_handler (HTTP_Handler &handler,
211 JAWS_IO &io);
214 * <open> is called by <ACE_Asynch_Acceptor> to initialize a new
215 * instance of ACE_Service_Handler that has been created after the a
216 * new connection is accepted.
218 * This will act as a creation point for new handlers.
220 virtual void open (ACE_HANDLE handle,
221 ACE_Message_Block &message_block);
223 private:
225 * This method is private as users are not allowed to create new
226 * handlers. New handlers can only be created by the framework when
227 * new client connections arrive.
229 HTTP_Handler *create_http_handler ();
231 #endif /* ACE_HAS_WIN32_OVERLAPPED_IO */
232 #endif /* HTTP_HANDLER_H */