Barracuda Application Server C/C++ Reference
NO
HttpAsynchReq.h
1 /*
2  * ____ _________ __ _
3  * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____
4  * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/
5  * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__
6  * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/
7  * /____/
8  *
9  * Barracuda Embedded Web-Server
10  ****************************************************************************
11  * HEADER
12  *
13  * $Id: HttpAsynchReq.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 __HttpAsynchReq_h
38 #define __HttpAsynchReq_h
39 
40 #include <HttpAsynchResp.h>
41 
42 #ifndef __DOXYGEN__
43 struct HttpAsynchReq;
44 #endif
45 
65 typedef void (*HttpAsynchReq_OnData)(struct HttpAsynchReq* super,
66  void* data, S32 size);
67 
90 typedef struct HttpAsynchReq
91 {
92 #ifdef __cplusplus
93  void *operator new(size_t s) { return ::baMalloc(s); }
94  void operator delete(void* d) { if(d) ::baFree(d); }
95  void *operator new(size_t, void *place) { return place; }
96  void operator delete(void*, void *) { }
97 
98  HttpAsynchReq(){}
99 
107 
109  ~HttpAsynchReq();
110 
126  SBaFileSize getPacketSizeLeft();
127 
132  void* getBuffer();
133 
135  SBaFileSize getBufferSize();
136 
137 
138  bool isChunkEncoding();
139 
159  static SBaFileSize calcPacketSize(HttpRequest* req);
160 
171  int start(HttpRequest* req,void* buffer, S32 bufferSize);
172 
175  void stop();
176 
190 #endif
191  HttpConnection super; /* Inherits from HttpConnection */
192  SBaFileSize bufferSize;
193  SBaFileSize packetSizeLeft;
194  SBaFileSize offset;
196  BaBool* isTerminatedPtr;
197  U8* buffer;
198  BaBool chunkEncoding;
200 
201 #ifdef __cplusplus
202 extern "C" {
203 #endif
204 BA_API void HttpAsynchReq_constructor(HttpAsynchReq* o,
205  HttpServer* server,
206  HttpAsynchReq_OnData data);
207 BA_API void HttpAsynchReq_destructor(HttpAsynchReq* o);
208 #define HttpAsynchReq_getPacketSizeLeft(o) (o)->packetSizeLeft
209 #define HttpAsynchReq_getBuffer(o) (o)->buffer
210 #define HttpAsynchReq_getBufferSize(o) (o)->bufferSize
211 #define HttpAsynchReq_isChunkEncoding(o) (o)->chunkEncoding
212 #define HttpAsynchReq_getServer(o) \
213  HttpConnection_getServer((HttpConnection*)(o))
214 BA_API SBaFileSize HttpAsynchReq_calcPacketSize(HttpRequest* req);
215 BA_API int HttpAsynchReq_start(
216  HttpAsynchReq* o,HttpRequest* req, void* buffer, S32 bufferSize);
217 /* Internal function used by HttpFiber */
218 BA_API void HttpAsynchReq_stop(HttpAsynchReq* o);
219 BA_API HttpConnection* HttpAsynchReq_getCon(HttpAsynchReq* o);
220 #ifdef __cplusplus
221 }
222 inline HttpAsynchReq::HttpAsynchReq(HttpServer* server,
223  HttpAsynchReq_OnData data) {
224  HttpAsynchReq_constructor(this, server, data);
225 }
227  HttpAsynchReq_destructor(this);
228 }
229 inline SBaFileSize HttpAsynchReq::getPacketSizeLeft() {
230  return HttpAsynchReq_getPacketSizeLeft(this);
231 }
232 inline void* HttpAsynchReq::getBuffer() {
233  return HttpAsynchReq_getBuffer(this);
234 }
235 inline SBaFileSize HttpAsynchReq::getBufferSize() {
236  return HttpAsynchReq_getBufferSize(this);
237 }
238 inline bool HttpAsynchReq::isChunkEncoding() {
239  return HttpAsynchReq_isChunkEncoding(this) ? true : false;
240 }
241 inline SBaFileSize HttpAsynchReq::calcPacketSize(HttpRequest* req) {
242  return HttpAsynchReq_calcPacketSize(req);
243 }
244 inline int HttpAsynchReq::start(HttpRequest* req,void* buffer, S32 bufferSize){
245  return HttpAsynchReq_start(this,req,buffer,bufferSize);
246 }
247 inline void HttpAsynchReq::stop() {
248  HttpAsynchReq_stop(this);
249 }
250 
252  return HttpAsynchReq_getCon(this); }
253 #endif
254 
255 
256 
265 typedef struct HttpAsynchReqResp
266 #ifdef __cplusplus
267  :public HttpAsynchReq
268 {
270 
280 
295  int start(HttpRequest* req,void* recBuf,S32 recBufSize,
296  void* sendBuf,S32 sendBufSize);
302  int startResp(HttpRequest* req,void* sendBuf,S32 sendBufSize);
303 
304 #if 0
305 
309  void disableRecEv();
310 
315  void enableRecEv();
316 #endif
317 
321 
324 
328 #else
329 #if 0
330 }
331 #endif
332 {
333  HttpAsynchReq super;
334 #endif
335  HttpAsynchResp resp;
337 
338 #ifdef __cplusplus
339 extern "C" {
340 #endif
341 BA_API void HttpAsynchReqResp_constructor(HttpAsynchReqResp* o,
342  HttpServer* server,
343  HttpAsynchReq_OnData data);
344 #if 0
345 void HttpAsynchReqResp_disableRecEv(HttpAsynchReqResp* o);
346 void HttpAsynchReqResp_enableRecEv(HttpAsynchReqResp* o);
347 #endif
348 BA_API int HttpAsynchReqResp_start(HttpAsynchReqResp* o,
349  HttpRequest* req,
350  void* recBuf,
351  S32 recBufSize,
352  void* sendBuf,
353  S32 sendBufSize);
354 BA_API int HttpAsynchReqResp_startResp(HttpAsynchReqResp* o,
355  HttpRequest* req,
356  void* sendBuf,
357  S32 sendBufSize);
358 #define HttpAsynchReqResp_destructor(o) do {\
359  HttpAsynchResp_destructor(&(o)->resp);\
360  HttpAsynchReq_destructor((HttpAsynchReq*)(o));\
361 }while(0)
362 #define HttpAsynchReqResp_getPacketSizeLeft(o)\
363  HttpAsynchReq_getPacketSizeLeft((HttpAsynchReq*)o)
364 #define HttpAsynchReqResp_getBuffer(o)\
365  HttpAsynchReq_getBuffer((HttpAsynchReq*)o)
366 #define HttpAsynchReqResp_getBufferSize(o)\
367  HttpAsynchReq_getBufferSize((HttpAsynchReq*)o)
368 #define HttpAsynchReqResp_isChunkEncoding(o)\
369  HttpAsynchReq_isChunkEncoding((HttpAsynchReq*)o)
370 #define HttpAsynchReqResp_calcPacketSize(req)\
371  HttpAsynchReq_calcPacketSize(req)
372 
373 #define HttpAsynchReqResp_getCon(o) ((o))->resp.con
374 #define HttpAsynchReqResp_getMutex(o) \
375  SoDisp_getMutex(HttpConnection_getDispatcher( \
376  HttpAsynchReqResp_getCon(o)))
377 #define HttpAsynchReqResp_getServer(o) \
378  HttpConnection_getServer(HttpAsynchReqResp_getCon(o))
379 #define HttpAsynchReqResp_getResponse(o) (&(o)->resp)
380 #ifdef __cplusplus
381 }
382 inline HttpAsynchReqResp::HttpAsynchReqResp(HttpServer* server,
383  HttpAsynchReq_OnData data) {
384  HttpAsynchReqResp_constructor(this, server, data);
385 }
387  void* recBuf,
388  S32 recBufSize,
389  void* sendBuf,
390  S32 sendBufSize) {
391  return HttpAsynchReqResp_start(
392  this,req,recBuf,recBufSize,sendBuf,sendBufSize); }
394  void* sendBuf,
395  S32 sendBufSize) {
396  return HttpAsynchReqResp_startResp(this,req,sendBuf,sendBufSize); }
397 #if 0
398 inline void HttpAsynchReqResp::disableRecEv() {
399  HttpAsynchReqResp_disableRecEv(this); }
400 inline void HttpAsynchReqResp::enableRecEv() {
401  HttpAsynchReqResp_enableRecEv(this); }
402 #endif
404  return HttpAsynchReqResp_getMutex(this);
405 }
407  return HttpAsynchReqResp_getServer(this);
408 }
410  return HttpAsynchReqResp_getResponse(this);
411 }
412 #endif
413 
414  /* end of HttpStack */
416 
417 
418 #endif
HttpRequest
The HttpServer creates an HttpRequest object when the HttpServer parses a client request.
Definition: HttpServer.h:819
HttpAsynchReq::stop
void stop()
Aborts the operation and terminates the active socket connection.
Definition: HttpAsynchReq.h:247
HttpAsynchReq::getBufferSize
SBaFileSize getBufferSize()
Returns the lenght of the internal buffer.
Definition: HttpAsynchReq.h:235
HttpAsynchReqResp::getMutex
ThreadMutex * getMutex()
Get the dispatcher lock.
Definition: HttpAsynchReq.h:403
HttpAsynchResp
Send data asynchronously to a client.
Definition: HttpAsynchResp.h:110
baFree
void baFree(void *p)
Deallocates space to which it points.
HttpAsynchReq::getCon
HttpConnection * getCon(HttpAsynchReq *o)
Returns the internal active connection object.
Definition: HttpAsynchReq.h:251
HttpAsynchReq::getBuffer
void * getBuffer()
Returns a pointer to the internal buffer where the received data is stored.
Definition: HttpAsynchReq.h:232
HttpConnection
Contains information about the physical socket connection.
Definition: HttpConnection.h:76
HttpAsynchReqResp
HttpAsynchReqResp HttpAsynchReqResp
Simultaneously receive and send a stream of data.
baMalloc
void * baMalloc(size_t size)
Returns pointer to uninitialized newly-allocated space for an object of size "size",...
HttpAsynchReq::getPacketSizeLeft
SBaFileSize getPacketSizeLeft()
Returns the remaining packet size if the packet size is known – i.e., if the initial HTTP header had ...
Definition: HttpAsynchReq.h:229
HttpAsynchReq
Asynchronously receive data in a resource such as HttpDir or HttpPage.
Definition: HttpAsynchReq.h:91
HttpAsynchReqResp::getServer
HttpServer * getServer()
Get the HttpServer object.
Definition: HttpAsynchReq.h:406
HttpAsynchReq_OnData
void(* HttpAsynchReq_OnData)(struct HttpAsynchReq *super, void *data, S32 size)
Prototype for the HttpAsynchReq OnRequest callback.
Definition: HttpAsynchReq.h:65
HttpAsynchReq::calcPacketSize
static SBaFileSize calcPacketSize(HttpRequest *req)
Returns the packet size if the length is known.
Definition: HttpAsynchReq.h:241
HttpAsynchReq::~HttpAsynchReq
~HttpAsynchReq()
Terminate a HttpAsynchReq object.
Definition: HttpAsynchReq.h:226
HttpAsynchReqResp::start
int start(HttpRequest *req, void *recBuf, S32 recBufSize, void *sendBuf, S32 sendBufSize)
Start the HttpAsynchReqResp object.
Definition: HttpAsynchReq.h:386
HttpAsynchReq::start
int start(HttpRequest *req, void *buffer, S32 bufferSize)
Start receiving data asynchronously.
Definition: HttpAsynchReq.h:244
HttpAsynchReqResp
Simultaneously receive and send a stream of data.
Definition: HttpAsynchReq.h:268
ThreadMutex
A mutual exclusion class.
Definition: ThreadLib.h:186
HttpAsynchReqResp::getResponse
HttpAsynchResp * getResponse()
Get the response object.
Definition: HttpAsynchReq.h:409
HttpAsynchReq
struct HttpAsynchReq HttpAsynchReq
Asynchronously receive data in a resource such as HttpDir or HttpPage.
HttpServer
The Web Server.
Definition: HttpServer.h:2887
HttpAsynchReqResp::startResp
int startResp(HttpRequest *req, void *sendBuf, S32 sendBufSize)
Start response if you know that all data was received by the web-server.
Definition: HttpAsynchReq.h:393