Barracuda Application Server C/C++ Reference
NO
HttpAsynchResp.h
1 /*
2  * ____ _________ __ _
3  * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____
4  * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/
5  * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__
6  * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/
7  * /____/
8  *
9  * Barracuda Embedded Web-Server
10  ****************************************************************************
11  * HEADER
12  *
13  * $Id: HttpAsynchResp.h 4915 2021-12-01 18:26:55Z wini $
14  *
15  * COPYRIGHT: Real Time Logic LLC, 2004-2012
16  *
17  * This software is copyrighted by and is the sole property of Real
18  * Time Logic LLC. All rights, title, ownership, or other interests in
19  * the software remain the property of Real Time Logic LLC. This
20  * software may only be used in accordance with the terms and
21  * conditions stipulated in the corresponding license agreement under
22  * which the software has been supplied. Any unauthorized use,
23  * duplication, transmission, distribution, or disclosure of this
24  * software is expressly forbidden.
25  *
26  * This Copyright notice may not be removed or modified without prior
27  * written consent of Real Time Logic LLC.
28  *
29  * Real Time Logic LLC. reserves the right to modify this software
30  * without notice.
31  *
32  * http://www.realtimelogic.com
33  ****************************************************************************
34  *
35  */
36 
37 #ifndef __HttpAsynchResp_h
38 #define __HttpAsynchResp_h
39 
40 #include <HttpServer.h>
41 
42 
43 #define RESPONSESTATE_IDLE 0
44 #define RESPONSESTATE_WRITEMODE 1
45 #define RESPONSESTATE_WRITEMODE_CHUNK 2
46 #define RESPONSESTATE_BODYSENT 3
47 #define RESPONSESTATE_CLOSED 4
48 
49 
50 
107 typedef struct HttpAsynchResp
108 #ifdef __cplusplus
109 : public HttpConnection
110 {
111  void *operator new(size_t s) { return ::baMalloc(s); }
112  void operator delete(void* d) { if(d) ::baFree(d); }
113  void *operator new(size_t, void *place) { return place; }
114  void operator delete(void*, void *) { }
115 
116  HttpAsynchResp() {}
117 
124  HttpAsynchResp(char* buf, int size, HttpRequest* req);
125 
132  HttpAsynchResp(char* buf,int size,HttpConnection* con);
133 
137  bool isValid();
138 
145  void asynchThreadMode();
146 
149  ~HttpAsynchResp();
150 
157  void close();
158 
163 
171  int setConClose();
172 
189  int setLingeringClose();
190 
191 
199  int setStatus(int statusCode, const char* protocol=0);
200 
207  int setHeader(const char *name, const char *value);
208 
217  int sendData(const void* data, int pktSize, int chunkSize);
218 
223  int sendNextChunk(const void* data,int chunkSize);
224 
233  BufPrint* getWriter();
234 #else
235 {
236  HttpConnection super;
237 #endif
238  BufPrint bufPrint;
239  HttpConnection* con; /* pointer to 'super' or to a HttpAsyncReqResp */
240  ThreadMutex* mutex; /* Can be set so code automatically locks mutex */
241  BaBool statusSent;
242  BaBool headerSent;
243  U8 responseState;
244  U8 doLingeringClose;
246 
247 
248 #ifdef __cplusplus
249 extern "C" {
250 #endif
251 BA_API void HttpAsynchResp_constructor(
252  HttpAsynchResp* o, char* buf, int size, HttpRequest* req);
253 BA_API void HttpAsynchResp_constructor2(
254  HttpAsynchResp* o, char* buf, int size, HttpConnection* con);
255 BA_API void HttpAsynchResp_ReqRespInit(
256  HttpAsynchResp* o, char* buf, int size, HttpConnection* con);
257 BA_API BaBool HttpAsynchResp_isValid(HttpAsynchResp* o);
258 #define HttpAsynchResp_asynchThreadMode(o) \
259  ((o)->mutex=HttpAsynchResp_getMutex(o))
260 BA_API void HttpAsynchResp_close(HttpAsynchResp* o);
261 #define HttpAsynchResp_destructor(o) HttpAsynchResp_close(o)
262 #define HttpAsynchResp_getMutex(o) \
263  SoDisp_getMutex(HttpConnection_getDispatcher((HttpConnection*)(o)))
264 #define HttpAsynchResp_setConClose(o)\
265  HttpConnection_clearKeepAlive((HttpConnection*)(o))
266 #define HttpAsynchResp_setLingeringClose(o) (o)->doLingeringClose=TRUE
267 BA_API int HttpAsynchResp_setStatus(
268  HttpAsynchResp* o, int statusCode, const char* protocol);
269 BA_API int HttpAsynchResp_setHeader(
270  HttpAsynchResp* o,const char *name,const char *value);
271 BA_API int HttpAsynchResp_sendData(
272  HttpAsynchResp* o, const void* data, int pktSize, int chunkSize);
273 BA_API int HttpAsynchResp_sendNextChunk(
274  HttpAsynchResp* o,const void* data,int chunkSize);
275 BA_API BufPrint* HttpAsynchResp_getWriter(HttpAsynchResp* o);
276 #define HttpAsynchResp_isAsynchThreadMode(o) ((o)->mutex ? TRUE : FALSE)
277 #ifdef __cplusplus
278 }
279 inline HttpAsynchResp::HttpAsynchResp(char* buf, int size, HttpRequest* req) {
280  HttpAsynchResp_constructor(this, buf, size, req);
281 }
282 inline HttpAsynchResp::HttpAsynchResp(char* buf,int size,HttpConnection* con) {
283  HttpAsynchResp_constructor2(this, buf, size, con);
284 }
285 inline bool HttpAsynchResp::isValid() {
286  return HttpAsynchResp_isValid(this) ? TRUE : FALSE;
287 }
289  HttpAsynchResp_destructor(this);
290 }
291 inline void HttpAsynchResp::close() {
292  HttpAsynchResp_close(this);
293 }
295  HttpAsynchResp_asynchThreadMode(this);
296 }
298  return HttpAsynchResp_getMutex(this);
299 }
301  return HttpAsynchResp_setConClose(this);
302 }
304  return HttpAsynchResp_setConClose(this);
305 }
306 inline int HttpAsynchResp::setStatus(int statusCode, const char* protocol) {
307  return HttpAsynchResp_setStatus(this, statusCode, protocol);
308 }
309 inline int HttpAsynchResp::setHeader(const char *name,const char *value) {
310  return HttpAsynchResp_setHeader(this, name, value);
311 }
313  const void* data, int pktSize, int chunkSize) {
314  return HttpAsynchResp_sendData(this, data, pktSize, chunkSize);
315 }
316 inline int HttpAsynchResp::sendNextChunk(const void* data,int chunkSize) {
317  return HttpAsynchResp_sendNextChunk(this,data,chunkSize); }
319  return HttpAsynchResp_getWriter(this);
320 }
321 #endif
322  /* end of HttpStack */
324 
325 
326 #endif
HttpRequest
The HttpServer creates an HttpRequest object when the HttpServer parses a client request.
Definition: HttpServer.h:819
HttpAsynchResp::getMutex
ThreadMutex * getMutex()
Get the dispatcher lock.
Definition: HttpAsynchResp.h:297
HttpAsynchResp::setConClose
int setConClose()
Close connection when the HttpAsynchResp object is done.
Definition: HttpAsynchResp.h:300
HttpAsynchResp::isValid
bool isValid()
Returns true if the HttpConnection object is valid – i.e., if the socket connection is alive.
Definition: HttpAsynchResp.h:285
HttpAsynchResp::asynchThreadMode
void asynchThreadMode()
Set in asynchronous thread mode so you can call the methods in this class without having to lock the ...
Definition: HttpAsynchResp.h:294
HttpAsynchResp
Send data asynchronously to a client.
Definition: HttpAsynchResp.h:110
HttpAsynchResp::setHeader
int setHeader(const char *name, const char *value)
Sets a HTTP response header with the given name and value.
Definition: HttpAsynchResp.h:309
HttpAsynchResp::sendNextChunk
int sendNextChunk(const void *data, int chunkSize)
Send next chunk if not all data was sent with sendData.
Definition: HttpAsynchResp.h:316
HttpAsynchResp::setLingeringClose
int setLingeringClose()
Used if a resource must close an active HttpAsynchReq and data is pending.
Definition: HttpAsynchResp.h:303
baFree
void baFree(void *p)
Deallocates space to which it points.
HttpConnection
Contains information about the physical socket connection.
Definition: HttpConnection.h:76
baMalloc
void * baMalloc(size_t size)
Returns pointer to uninitialized newly-allocated space for an object of size "size",...
HttpAsynchResp::close
void close()
Flushes the response, if any, and checks the connection object: A valid and persistent HTTP 1....
Definition: HttpAsynchResp.h:291
BufPrint
The BufPrint class, which implements an ANSI compatible printf method, is a base class used by severa...
Definition: BufPrint.h:122
HttpAsynchResp::getWriter
BufPrint * getWriter()
BufPrint is used when sending data of unknown length.
Definition: HttpAsynchResp.h:318
HttpAsynchResp::~HttpAsynchResp
~HttpAsynchResp()
Calls method close.
Definition: HttpAsynchResp.h:288
HttpAsynchResp::sendData
int sendData(const void *data, int pktSize, int chunkSize)
Send data of known size to client.
Definition: HttpAsynchResp.h:312
ThreadMutex
A mutual exclusion class.
Definition: ThreadLib.h:186
HttpAsynchResp::setStatus
int setStatus(int statusCode, const char *protocol=0)
Set the response status code.
Definition: HttpAsynchResp.h:306