|
Barracuda Application Server C/C++ Reference
Native APIs, integration guides, and platform interfaces
|

Modules | |
| HttpUpload | |
| HttpUpload is a collection of classes that makes it easy to implement a remote file manager. | |
Classes | |
| struct | HttpAsynchReq |
| Asynchronously receive data in a resource such as HttpDir or HttpPage. More... | |
| struct | HttpAsynchReqResp |
| Simultaneously receive and send a stream of data. More... | |
| struct | HttpAsynchResp |
| Send data asynchronously to a client. More... | |
| struct | HttpRecData |
| The HttpRecData class makes it easy to upload packets or large data chunks when using Barracuda in multithread mode. More... | |
| struct | MultipartUpload |
| Parser for multipart/form-data POST requests. More... | |
Typedefs | |
| typedef void(* | HttpAsynchReq_OnData) (struct HttpAsynchReq *super, void *data, S32 size) |
| Receive data, completion, or an error. More... | |
| typedef struct HttpAsynchReq | HttpAsynchReq |
| Asynchronously receive data in a resource such as HttpDir or HttpPage. More... | |
| typedef HttpAsynchReqResp | HttpAsynchReqResp |
| Simultaneously receive and send a stream of data. More... | |
| typedef HttpAsynchResp | HttpAsynchResp |
| Send data asynchronously to a client. More... | |
| typedef struct HttpRecData | HttpRecData |
| The HttpRecData class makes it easy to upload packets or large data chunks when using Barracuda in multithread mode. More... | |
| typedef void(* | MultipartUpload_EndOfReq) (struct MultipartUpload *o) |
| Report the final multipart boundary. More... | |
| typedef int(* | MultipartUpload_FormData) (struct MultipartUpload *o, const char *name, const char *value) |
| Executed by MultipartUpload every time a form data element such as "text" is found in the multipart data stream. More... | |
| typedef int(* | MultipartUpload_FileBegin) (struct MultipartUpload *o, const char *name, const char *fileName, const char *contentType, const char *contentTransferEncoding) |
| Executed by MultipartUpload when a file is found in the multipart data stream. More... | |
| typedef int(* | MultipartUpload_FileData) (struct MultipartUpload *o, const U8 *data, U16 len) |
| Executed by MultipartUpload when a data chunk is available. More... | |
| typedef void(* | MultipartUpload_Error) (struct MultipartUpload *o, MultipartUpload_ErrorType e) |
| Executed by MultipartUpload if any errors are detected during parsing of the multipart data stream. More... | |
| typedef struct MultipartUpload | MultipartUpload |
| Parser for multipart/form-data POST requests. More... | |
Enumerations | |
| enum | MultipartUpload_ErrorType |
| Error codes used by the callback function MultipartUpload_Error in interface class MultipartUpload. More... | |
Functions | |
| BA_API void | HttpAsynchReq_constructor (HttpAsynchReq *o, HttpServer *server, HttpAsynchReq_OnData data) |
| Create an instance of HttpAsynchReq. More... | |
| BA_API void | HttpAsynchReq_destructor (HttpAsynchReq *o) |
| BA_API SBaFileSize | HttpAsynchReq_calcPacketSize (HttpRequest *req) |
| Inspect the request's body framing without consuming it. More... | |
| BA_API int | HttpAsynchReq_start (HttpAsynchReq *o, HttpRequest *req, void *buffer, S32 bufferSize) |
| Take over the request connection and start asynchronous reception. More... | |
| BA_API void | HttpAsynchReq_stop (HttpAsynchReq *o) |
| BA_API HttpConnection * | HttpAsynchReq_getCon (HttpAsynchReq *o) |
| Stop receiving and expose the embedded connection for handoff. More... | |
| BA_API void | HttpAsynchReqResp_constructor (HttpAsynchReqResp *o, HttpServer *server, HttpAsynchReq_OnData data) |
| Initialize combined receive/response state. More... | |
| BA_API int | HttpAsynchReqResp_start (HttpAsynchReqResp *o, HttpRequest *req, void *recBuf, S32 recBufSize, void *sendBuf, S32 sendBufSize) |
| Start the HttpAsynchReqResp object. More... | |
| BA_API int | HttpAsynchReqResp_startResp (HttpAsynchReqResp *o, HttpRequest *req, void *sendBuf, S32 sendBufSize) |
| Start response if you know that all data was received by the web-server. More... | |
| BA_API void | HttpAsynchResp_constructor (HttpAsynchResp *o, char *buf, int size, HttpRequest *req) |
| Initialize from a request and take over its connection. More... | |
| BA_API void | HttpAsynchResp_constructor2 (HttpAsynchResp *o, char *buf, int size, HttpConnection *con) |
| Initialize from a connection and take over its socket. More... | |
| BA_API void | HttpAsynchResp_ReqRespInit (HttpAsynchResp *o, char *buf, int size, HttpConnection *con) |
| Initialize the response half of a combined request/response object. More... | |
| BA_API BaBool | HttpAsynchResp_isValid (HttpAsynchResp *o) |
| Check the installed buffer and connection. More... | |
| BA_API void | HttpAsynchResp_close (HttpAsynchResp *o) |
| Flushes the response, if any, and checks the connection object: A valid and persistent HTTP 1.1 socket connection object is moved back into the Web-server's HTTP 1.1 HttpConnection pool such that the connection can be recycled. More... | |
| BA_API int | HttpAsynchResp_setStatus (HttpAsynchResp *o, int statusCode, const char *protocol) |
| Append the HTTP status line and standard Date/Server headers. More... | |
| BA_API int | HttpAsynchResp_setHeader (HttpAsynchResp *o, const char *name, const char *value) |
| Append a response header before starting the body. More... | |
| BA_API int | HttpAsynchResp_sendData (HttpAsynchResp *o, const void *data, int pktSize, int chunkSize) |
| Begin a fixed-length response body. More... | |
| BA_API int | HttpAsynchResp_sendNextChunk (HttpAsynchResp *o, const void *data, int chunkSize) |
| Continue the fixed-length body begun with sendData. More... | |
| BA_API BufPrint * | HttpAsynchResp_getWriter (HttpAsynchResp *o) |
| BufPrint is used when sending data of unknown length. More... | |
| BA_API SBaFileSize | HttpRecData_valid (HttpRequest *req) |
| This method validates the client HTTP request. More... | |
| BA_API void | HttpRecData_constructor (HttpRecData *o, HttpRequest *req) |
| The constructor is typically run by creating an object on the stack. More... | |
| BA_API void | HttpRecData_destructor (HttpRecData *o) |
| Finish reading, terminating the connection if unread body bytes remain. More... | |
| BA_API S32 | HttpRecData_read (HttpRecData *o, void *buf, S32 bufSize) |
| Read data from socket. More... | |
| void BA_API | MultipartUpload_constructor (MultipartUpload *o, HttpServer *server, MultipartUpload_EndOfReq endOfReq, MultipartUpload_FormData formData, MultipartUpload_FileBegin fileBegin, MultipartUpload_FileData fileData, MultipartUpload_Error onError, U32 bufferSize, AllocatorIntf *allocator) |
| Construct a parser as described by MultipartUpload::MultipartUpload. More... | |
| BA_API void | MultipartUpload_destructor (MultipartUpload *o) |
| Detach from the dispatcher, free parsing storage, and close the embedded asynchronous connection if still owned. More... | |
| BA_API int | MultipartUpload_start (MultipartUpload *o, HttpRequest *req) |
| Start asynchronous multipart input, taking the request connection. More... | |
| BA_API int | MultipartUpload_run (MultipartUpload *o, HttpRequest *req, BaBool setKeepAlive) |
| Parse multipart input synchronously, blocking for additional bytes. More... | |
| BA_API HttpConnection * | MultipartUpload_getCon (MultipartUpload *o) |
| Detach and prepare an asynchronous connection handoff. More... | |
| HttpAsynchReq::HttpAsynchReq (HttpServer *server, HttpAsynchReq_OnData data) | |
| Create an instance of HttpAsynchReq. More... | |
| HttpAsynchReq::~HttpAsynchReq () | |
| Stop dispatcher reception and destroy the owned connection. More... | |
| SBaFileSize | HttpAsynchReq::getPacketSizeLeft () |
| Inspect receive progress after successful start. More... | |
| void * | HttpAsynchReq::getBuffer () |
| Returns a pointer to the internal buffer where the received data is stored. More... | |
| SBaFileSize | HttpAsynchReq::getBufferSize () |
| bool | HttpAsynchReq::isChunkEncoding () |
| static SBaFileSize | HttpAsynchReq::calcPacketSize (HttpRequest *req) |
| Inspect the request's body framing without consuming it. More... | |
| int | HttpAsynchReq::start (HttpRequest *req, void *buffer, S32 bufferSize) |
| Take over the request connection and start asynchronous reception. More... | |
| void | HttpAsynchReq::stop () |
| Remove active dispatcher reception, mark an active connection terminated, and clear receive-buffer state. More... | |
| HttpConnection * | HttpAsynchReq::getCon (HttpAsynchReq *o) |
| Stop dispatcher reception and obtain the connection for handoff. More... | |
| HttpAsynchReqResp::HttpAsynchReqResp (HttpServer *server, HttpAsynchReq_OnData onData) | |
| Create a HttpAsynchReqResp instance. More... | |
| int | HttpAsynchReqResp::start (HttpRequest *req, void *recBuf, S32 recBufSize, void *sendBuf, S32 sendBufSize) |
| Start the HttpAsynchReqResp object. More... | |
| int | HttpAsynchReqResp::startResp (HttpRequest *req, void *sendBuf, S32 sendBufSize) |
| Start response if you know that all data was received by the web-server. More... | |
| ThreadMutex * | HttpAsynchReqResp::getMutex () |
| HttpServer * | HttpAsynchReqResp::getServer () |
| HttpAsynchResp * | HttpAsynchReqResp::getResponse () |
| HttpAsynchResp::HttpAsynchResp (char *buf, int size, HttpRequest *req) | |
| Initiate a HttpAsynchResp from a HttpRequest object. More... | |
| HttpAsynchResp::HttpAsynchResp (char *buf, int size, HttpConnection *con) | |
| Initiate a HttpAsynchResp from a HttpConnection object. More... | |
| bool | HttpAsynchResp::isValid () |
| Check the installed buffer and connection. More... | |
| HttpAsynchResp::~HttpAsynchResp () | |
| Calls method close. More... | |
| void | HttpAsynchResp::close () |
| Flushes the response, if any, and checks the connection object: A valid and persistent HTTP 1.1 socket connection object is moved back into the Web-server's HTTP 1.1 HttpConnection pool such that the connection can be recycled. More... | |
| void | HttpAsynchResp::asynchThreadMode () |
| Set in asynchronous thread mode so you can call the methods in this class using its worker-thread send path. More... | |
| ThreadMutex * | HttpAsynchResp::getMutex () |
| Get the dispatcher lock. More... | |
| int | HttpAsynchResp::setConClose () |
| Close connection when the HttpAsynchResp object is done. More... | |
| int | HttpAsynchResp::setLingeringClose () |
| Request connection closure. More... | |
| int | HttpAsynchResp::setStatus (int statusCode, const char *protocol=0) |
| Append the HTTP status line and standard Date/Server headers. More... | |
| int | HttpAsynchResp::setHeader (const char *name, const char *value) |
| Append a response header before starting the body. More... | |
| int | HttpAsynchResp::sendData (const void *data, int pktSize, int chunkSize) |
| Begin a fixed-length response body. More... | |
| int | HttpAsynchResp::sendNextChunk (const void *data, int chunkSize) |
| Continue the fixed-length body begun with sendData. More... | |
| BufPrint * | HttpAsynchResp::getWriter () |
| BufPrint is used when sending data of unknown length. More... | |
| static SBaFileSize | HttpRecData::valid (HttpRequest *req) |
| This method validates the client HTTP request. More... | |
| HttpRecData::HttpRecData (HttpRequest *req) | |
| The constructor is typically run by creating an object on the stack. More... | |
| S32 | HttpRecData::read (void *buf, S32 bufSize) |
| Read data from socket. More... | |
| HttpRecData::~HttpRecData () | |
| Finish using the reader. More... | |
| MultipartUpload::MultipartUpload (HttpServer *server, MultipartUpload_EndOfReq onEndOfReq, MultipartUpload_FormData onFormData, MultipartUpload_FileBegin onFileBegin, MultipartUpload_FileData onFileData, MultipartUpload_Error onError, U32 bufferSize, AllocatorIntf *allocator=0) | |
| MultipartUpload::~MultipartUpload () | |
| Detach from the dispatcher, free parsing storage, and close the embedded asynchronous connection if still owned. More... | |
| int | MultipartUpload::start (HttpRequest *req) |
| Start asynchronous multipart input, taking the request connection. More... | |
| int | MultipartUpload::run (HttpRequest *req, bool setKeepAlive=true) |
| Parse multipart input synchronously, blocking for additional bytes. More... | |
| HttpConnection * | MultipartUpload::getCon (MultipartUpload *o) |
| Detach the asynchronous parser and release parsing buffers for a handoff. More... | |
| HttpServer * | MultipartUpload::getServer () |
| Get the server supplied to the constructor. More... | |
| #define HttpAsynchReq_getBuffer | ( | o | ) | (o)->buffer |
| [in] | o | Initialized receiver. |
| #define HttpAsynchReq_getBufferSize | ( | o | ) | (o)->bufferSize |
| [in] | o | Initialized receiver. |
| #define HttpAsynchReq_getPacketSizeLeft | ( | o | ) | (o)->packetSizeLeft |
| [in] | o | Initialized receiver. |
| #define HttpAsynchReq_getServer | ( | o | ) | HttpConnection_getServer((HttpConnection*)(o)) |
| [in] | o | Initialized receiver. |
| #define HttpAsynchReq_isChunkEncoding | ( | o | ) | (o)->chunkEncoding |
| [in] | o | Initialized receiver. |
| #define HttpAsynchReqResp_calcPacketSize | ( | req | ) | HttpAsynchReq_calcPacketSize(req) |
Inspect the request's body framing without consuming it.
| [in] | req | Required borrowed current request. |
| #define HttpAsynchReqResp_destructor | ( | o | ) |
Close the response and destroy receive state; free neither object nor buffers.
| [in,out] | o | Initialized combined receiver. May be called from OnData. |
| #define HttpAsynchReqResp_getBuffer | ( | o | ) | HttpAsynchReq_getBuffer((HttpAsynchReq*)o) |
| [in] | o | Initialized receiver. |
| #define HttpAsynchReqResp_getBufferSize | ( | o | ) | HttpAsynchReq_getBufferSize((HttpAsynchReq*)o) |
| [in] | o | Initialized receiver. |
| #define HttpAsynchReqResp_getCon | ( | o | ) | ((o))->resp.con |
| [in] | o | Initialized combined receiver. |
| #define HttpAsynchReqResp_getMutex | ( | o | ) |
| [in] | o | Initialized combined receiver. |
| #define HttpAsynchReqResp_getPacketSizeLeft | ( | o | ) | HttpAsynchReq_getPacketSizeLeft((HttpAsynchReq*)o) |
| [in] | o | Initialized receiver. |
| #define HttpAsynchReqResp_getResponse | ( | o | ) | (&(o)->resp) |
| [in] | o | Initialized combined receiver. |
| #define HttpAsynchReqResp_getServer | ( | o | ) | HttpConnection_getServer(HttpAsynchReqResp_getCon(o)) |
| [in] | o | Initialized combined receiver. |
| #define HttpAsynchReqResp_isChunkEncoding | ( | o | ) | HttpAsynchReq_isChunkEncoding((HttpAsynchReq*)o) |
| [in] | o | Initialized receiver. |
| #define HttpAsynchResp_asynchThreadMode | ( | o | ) | ((o)->mutex=HttpAsynchResp_getMutex(o)) |
Select worker-thread send behavior; see HttpAsynchResp::asynchThreadMode.
| [in,out] | o | Initialized response, used by one application thread. |
| #define HttpAsynchResp_destructor | ( | o | ) | HttpAsynchResp_close(o) |
Close the response; no status is returned.
| [in,out] | o | Initialized response. Does not free o or borrowed storage. |
| #define HttpAsynchResp_getMutex | ( | o | ) | SoDisp_getMutex(HttpConnection_getDispatcher((HttpConnection*)(o))) |
| [in] | o | Response with an initialized dispatcher association. |
| #define HttpAsynchResp_isAsynchThreadMode | ( | o | ) | ((o)->mutex ? TRUE : FALSE) |
| [in] | o | Initialized response. |
| #define HttpAsynchResp_setConClose | ( | o | ) | HttpConnection_clearKeepAlive((HttpConnection*)(o)) |
Disable persistent connection reuse before sending headers.
| [in,out] | o | Initialized standalone response. |
| #define HttpAsynchResp_setLingeringClose | ( | o | ) | (o)->doLingeringClose=TRUE |
Enable the lingering-close queue before sending headers.
Use when terminating an upload that still has unread incoming bytes.
| [in,out] | o | Initialized response. |
| #define MultipartUpload_getServer | ( | o | ) | HttpConnection_getServer((HttpConnection*)(o)) |
Get the server supplied to the constructor.
| o | Required initialized parser. |
| typedef struct HttpAsynchReq HttpAsynchReq |
Asynchronously receive data in a resource such as HttpDir or HttpPage.
An instance of the HttpAsynchReq class can be used as a method to receive any kind of data from a client as long as the client does not send the data as a multipart/form-data. A resource receiving multipart/form-data must use the MultipartUpload class.
You typically create an instance of this class in a resource when receiving a request. You can optionally keep instances of this class in a pool. The object is started by calling method start.
HttpAsynchReq is an abstract base class; thus, you must inherit and implement the socket event method. See constructor for how to install the event function.
The detached socket object is installed directly into the SoDisp object, and any socket event is directed to this object. The callback installed by the constructor receives body data and terminal notifications; see HttpAsynchReq_OnData.
| typedef void(* HttpAsynchReq_OnData) (struct HttpAsynchReq *super, void *data, S32 size) |
Receive data, completion, or an error.
| [in,out] | super | Borrowed receiver; upcast to the application's containing type when appropriate. Calls can occur within start or later in the dispatcher. |
| [in] | data | Borrowed bytes, valid only during the callback. Copy retained data. NULL with size zero means completion. Non-NULL with size zero is the preliminary Expect notification before the library sends 100 Continue. |
| [in] | size | Positive byte count, zero as described above, or a negative error with NULL data: -1 receive failure, -10 malformed chunk framing, -11 chunk header does not fit the receive buffer. Fixed-length bodies are delivered when the buffer fills or the body ends; chunked bodies can produce smaller callbacks. A completion notification is separate from the final positive-length data callback. On completion or error, destroy the receiver or use getCon to transfer its connection to response handling. Do not merely retain an idle receiver: some chunked paths require that the callback terminates receive processing. Destruction from the callback is supported; do not access it afterward. |
| typedef HttpAsynchReqResp HttpAsynchReqResp |
Simultaneously receive and send a stream of data.
The HttpAsynchReqResp class makes it possible to asynchronously receive and send data at the same time. The HttpAsynchReqResp can also be used as a replacement for using a HttpAsynchReq and HttpAsynchResp object. An HttpAsynchReqResp instance is easier to use than first using a HttpAsynchReq object for receiving data and then later using a HttpAsynchResp for sending a response message.
| typedef HttpAsynchResp HttpAsynchResp |
Send data asynchronously to a client.
Please see the HTTP protocol stack for an introduction to the HttpAsynchResp class.
You must lock the dispatcher prior to calling any methods in the HttpAsynchResp class unless the object is used from within a Barracuda event callback or you have called method HttpAsynchResp::asynchThreadMode. See using multiple threads in the Barracuda introduction for more information on protecting the Barracuda code.
There is one exception to the above. You can call method HttpAsynchResp::getMutex without locking the dispatcher first. You cannot lock the dispatcher unless you first have a reference to the dispatcher object.
example code
Certain restrictions apply to how you can use this object. This is, after all, a lightweight version of HttpResponse. The HttpAsynchResp object does not have large buffers for storing out data. Thus, the methods must be called in the following order:
Calling methods setConClose, setStatus, and setHeader are optional.
Calling method setHeader implicitly calls method setStatus with status code 200 unless you already called setStatus.
Sending data using method sendData or the methods in BufPrint flushes the HTTP header. Thus, you cannot call method setHeader after the HTTP header is flushed.
You must use one of BufPrint or ( HttpAsynchResp::sendData [ & HttpAsynchResp::sendNextChunk ] ) when sending response data.
| typedef struct HttpRecData HttpRecData |
The HttpRecData class makes it easy to upload packets or large data chunks when using Barracuda in multithread mode.
This class gives similar functionality to HttpAsynchReq and makes it possible to receive any kind of data sent from a client in a CSP page or in a HttpDir/HttpPage.
CSP example
| typedef struct MultipartUpload MultipartUpload |
Parser for multipart/form-data POST requests.
Each field is delivered through formData; files are delivered through fileBegin and fileData callbacks. File bytes are streamed rather than stored as one complete file. Field values must fit in the parser's working storage. The parser does not create files or decode Content-Transfer-Encoding values.
Use start() for dispatcher-driven input or run() for blocking input. All five callbacks are required. Callback cleanup rules differ between these modes: asynchronous completion/error must detach or destroy the parser; synchronous callbacks must keep its storage alive until run() returns. Do not reuse one parser concurrently or switch a completed blocking instance to asynchronous mode.
| typedef void(* MultipartUpload_EndOfReq) (struct MultipartUpload *o) |
Report the final multipart boundary.
| o | Parser whose request has completed. This callback returns no value. In asynchronous mode, destroy the parser or call MultipartUpload_getCon() to detach it and transfer the connection. In synchronous run() mode, leave the object alive until run() returns; getCon() is unavailable in that mode. |
| typedef void(* MultipartUpload_Error) (struct MultipartUpload *o, MultipartUpload_ErrorType e) |
Executed by MultipartUpload if any errors are detected during parsing of the multipart data stream.
This method must call the MultipartUpload destructor or call MultipartUpload::getCon.
| o | the object |
| e | is the error code. The callback returns no value. In synchronous run() mode, leave the object alive and let run() return before freeing it. Not every initialization failure invokes onError; always check the start()/run() result as well. |
| typedef int(* MultipartUpload_FileBegin) (struct MultipartUpload *o, const char *name, const char *fileName, const char *contentType, const char *contentTransferEncoding) |
Executed by MultipartUpload when a file is found in the multipart data stream.
| o | the object |
| name | the name as specified in the HTML "input" type. |
| fileName | is the name and possible path of the file entered by the user. The path separator is platform dependent. |
| contentType | is the content mime type such as "text/plain". This parameter is NULL if not specified in the multipart data stream. |
| contentTransferEncoding | is the part's Content-Transfer-Encoding header value. The parser does not decode this encoding. This parameter is NULL if not specified in the multipart data stream. |
| typedef int(* MultipartUpload_FileData) (struct MultipartUpload *o, const U8 *data, U16 len) |
Executed by MultipartUpload when a data chunk is available.
The servlet first calls MultipartUpload_FileBegin and thereafter calls this method repeatedly until all data is received. End of file is signalled by setting the two input parameters to 0.
| o | the object |
| data | a pointer to the received data. |
| len | Byte count, at most 65535. data=NULL and len=0 mark the end of the current file, not the end of the complete request. |
| typedef int(* MultipartUpload_FormData) (struct MultipartUpload *o, const char *name, const char *value) |
Executed by MultipartUpload every time a form data element such as "text" is found in the multipart data stream.
The browser bundles all data into the multipart stream sent to the server. The MultipartUpload servlet calls the formData callback function when it detects form data.
| o | the object |
| name | the name as specified in the HTML "input" type. |
| value | the text entered by the user. |
Error codes used by the callback function MultipartUpload_Error in interface class MultipartUpload.
| void HttpAsynchResp::asynchThreadMode | ( | ) |
Set in asynchronous thread mode so you can call the methods in this class using its worker-thread send path.
This does not serialize multiple application threads accessing the same response; use one owner. You must not call this method if you are calling the methods in this class from within a callback originating from the socket dispatcher SoDisp – i.e., if the mutex is already locked.
|
static |
Inspect the request's body framing without consuming it.
| [in] | req | Required borrowed current request. |
| void HttpAsynchResp::close | ( | ) |
Flushes the response, if any, and checks the connection object: A valid and persistent HTTP 1.1 socket connection object is moved back into the Web-server's HTTP 1.1 HttpConnection pool such that the connection can be recycled.
A non-persistent HTTP connection such as an HTTP 1.0 connection is terminated. Completes the final chunk for writer mode. This void operation does not report flush/close failure; check preceding output results. It does not free borrowed storage. No further output is allowed after close.
| void * HttpAsynchReq::getBuffer | ( | ) |
Returns a pointer to the internal buffer where the received data is stored.
The buffer is set in method HttpAsynchReq::start.
| SBaFileSize HttpAsynchReq::getBufferSize | ( | ) |
| HttpConnection * HttpAsynchReq::getCon | ( | HttpAsynchReq * | o | ) |
Stop dispatcher reception and obtain the connection for handoff.
| [in] | o | Unused compatibility argument in the C++ method; this method acts on its own instance. The C function uses o as its receiver. |
This method is typically called from within the OnData event method when all data is received and you are moving the active connection object to an HttpAsynchResp object.
C code example:
| HttpConnection * MultipartUpload::getCon | ( | MultipartUpload * | o | ) |
Detach the asynchronous parser and release parsing buffers for a handoff.
| o | Unused argument retained by the C++ wrapper; the operation acts on this. |
| ThreadMutex * HttpAsynchReqResp::getMutex | ( | ) |
| ThreadMutex * HttpAsynchResp::getMutex | ( | ) |
Get the dispatcher lock.
This is the only method in this class that can be called without locking the dispatcher.
| SBaFileSize HttpAsynchReq::getPacketSizeLeft | ( | ) |
Inspect receive progress after successful start.
| HttpAsynchResp * HttpAsynchReqResp::getResponse | ( | ) |
| struct HttpServer * HttpAsynchReqResp::getServer | ( | ) |
| HttpServer * MultipartUpload::getServer | ( | ) |
Get the server supplied to the constructor.
| BufPrint * HttpAsynchResp::getWriter | ( | ) |
BufPrint is used when sending data of unknown length.
For a HTTP/1.1. connection, the data is sent in chunk transfer mode.
This method returns NULL if HttpAsynchResp::sendData was called prior to this method.
| HttpAsynchReq::HttpAsynchReq | ( | HttpServer * | server, |
| HttpAsynchReq_OnData | data | ||
| ) |
Create an instance of HttpAsynchReq.
| server | Required borrowed server, valid throughout receiver use. |
| data | Required callback, valid throughout receiver use. HttpAsynchReq is an abstract class and you must, therefore, implement the OnData socket event method. |
| BA_API SBaFileSize HttpAsynchReq_calcPacketSize | ( | HttpRequest * | req | ) |
Inspect the request's body framing without consuming it.
| [in] | req | Required borrowed current request. |
| BA_API void HttpAsynchReq_constructor | ( | HttpAsynchReq * | o, |
| HttpServer * | server, | ||
| HttpAsynchReq_OnData | data | ||
| ) |
Create an instance of HttpAsynchReq.
| server | Required borrowed server, valid throughout receiver use. | |
| data | Required callback, valid throughout receiver use. HttpAsynchReq is an abstract class and you must, therefore, implement the OnData socket event method. | |
| [in,out] | o | Caller-owned receiver instance. |
| BA_API void HttpAsynchReq_destructor | ( | HttpAsynchReq * | o | ) |
| [in,out] | o | Initialized receiver; closes its owned connection and releases dispatcher registration, but does not free o or the receive buffer. May be called from OnData. See HttpAsynchReq::~HttpAsynchReq. |
| BA_API HttpConnection * HttpAsynchReq_getCon | ( | HttpAsynchReq * | o | ) |
Stop receiving and expose the embedded connection for handoff.
| [in,out] | o | Live receiver. |
| BA_API int HttpAsynchReq_start | ( | HttpAsynchReq * | o, |
| HttpRequest * | req, | ||
| void * | buffer, | ||
| S32 | bufferSize | ||
| ) |
Take over the request connection and start asynchronous reception.
| [in,out] | req | Borrowed current request with an uncommitted response. |
| [in] | buffer | Caller-owned writable storage, valid until reception stops. |
| [in] | bufferSize | Capacity in bytes, at least 255. Chunk header lines must fit this buffer. Chunked trailer fields are not supported. |
| [in,out] | o | Caller-owned receiver instance. |
| BA_API void HttpAsynchReq_stop | ( | HttpAsynchReq * | o | ) |
| [in,out] | o | Initialized receiver. Does not free borrowed buffer storage. Use destruction for final connection cleanup. |
| HttpAsynchReqResp::HttpAsynchReqResp | ( | HttpServer * | server, |
| HttpAsynchReq_OnData | onData | ||
| ) |
Create a HttpAsynchReqResp instance.
| server | Required borrowed server, valid throughout object use. |
| onData | Required asynchronous receive callback method. HttpAsynchReqResp inherits from HttpAsynchReq and it is the HttpAsynchReq object which calls the callback method when the internal buffer is full. End of stream is signaled by setting the two parameters to the callback to null. |
| BA_API void HttpAsynchReqResp_constructor | ( | HttpAsynchReqResp * | o, |
| HttpServer * | server, | ||
| HttpAsynchReq_OnData | data | ||
| ) |
Initialize combined receive/response state.
| [out] | o | Caller-owned object. |
| [in] | server | Required borrowed server, valid throughout use. |
| [in] | data | Required callback; see HttpAsynchReq_OnData. |
| BA_API int HttpAsynchReqResp_start | ( | HttpAsynchReqResp * | o, |
| HttpRequest * | req, | ||
| void * | recBuf, | ||
| S32 | recBufSize, | ||
| void * | sendBuf, | ||
| S32 | sendBufSize | ||
| ) |
Start the HttpAsynchReqResp object.
The onData callback method is called directly if all data was received by the client; otherwise, the HttpAsynchReq object is installed into the SoDisp. The method returns a negative value if the HttpAsynchReq object failed to start. The method returns 0 if the object started successfully or if the destructor was called from within the onData callback.
| req | Required borrowed current request with an uncommitted response. | |
| recBuf | Borrowed writable receive buffer, valid until reception stops. The onData callback is called when the buffer is full. | |
| recBufSize | Receive capacity in bytes, at least 255. | |
| sendBuf | Separate borrowed writable response buffer, valid until close. | |
| sendBufSize | Response capacity in bytes; use at least 256. The buffers must not overlap while sending and receiving concurrently. | |
| [in,out] | o | Caller-owned receiver instance. |
| BA_API int HttpAsynchReqResp_startResp | ( | HttpAsynchReqResp * | o, |
| HttpRequest * | req, | ||
| void * | sendBuf, | ||
| S32 | sendBufSize | ||
| ) |
Start response if you know that all data was received by the web-server.
This is a faster method than calling start if you know that the web-server received all data in its internal buffer before delegating the request to the requested service.
| [in,out] | req | Current request; caller must account for any unread body before selecting this response-only path. No receive callback runs. |
| [in] | sendBuf | Borrowed writable response storage, valid until close. |
| [in] | sendBufSize | Response capacity in bytes; use at least 256. |
| [in,out] | o | Caller-owned receiver instance. |
| HttpAsynchResp::HttpAsynchResp | ( | char * | buf, |
| int | size, | ||
| HttpConnection * | con | ||
| ) |
Initiate a HttpAsynchResp from a HttpConnection object.
| buf | Required borrowed writable output buffer, valid until close. It is not freed by the response. |
| size | Output capacity in bytes. Use at least 256 (the internal minimum check is 200). For chunked writer output, usable payload capacity (size minus 8) must not exceed 65535. |
| con | Source connection whose active socket is moved to this object. NULL creates no active socket. Check isValid before output. For HttpAsynchReq, obtain the source with its getCon handoff method. |
| HttpAsynchResp::HttpAsynchResp | ( | char * | buf, |
| int | size, | ||
| HttpRequest * | req | ||
| ) |
Initiate a HttpAsynchResp from a HttpRequest object.
| buf | Required borrowed writable output buffer, valid until close. It is not freed by the response. |
| size | Output capacity in bytes. Use at least 256 (the internal minimum check is 200). For chunked writer output, usable payload capacity (size minus 8) must not exceed 65535. |
| req | Required current request with an uncommitted response. Its active connection is moved to this object; do not use the original response afterward. Check isValid after construction. |
| BA_API void HttpAsynchResp_close | ( | HttpAsynchResp * | o | ) |
Flushes the response, if any, and checks the connection object: A valid and persistent HTTP 1.1 socket connection object is moved back into the Web-server's HTTP 1.1 HttpConnection pool such that the connection can be recycled.
A non-persistent HTTP connection such as an HTTP 1.0 connection is terminated. Completes the final chunk for writer mode. This void operation does not report flush/close failure; check preceding output results. It does not free borrowed storage. No further output is allowed after close.
| [in,out] | o | Initialized response. |
| BA_API void HttpAsynchResp_constructor | ( | HttpAsynchResp * | o, |
| char * | buf, | ||
| int | size, | ||
| HttpRequest * | req | ||
| ) |
Initialize from a request and take over its connection.
| [out] | o | Caller-owned response storage. |
| [in] | buf | Required borrowed writable buffer, valid until close. |
| [in] | size | Capacity in bytes; use at least 256. See the C++ constructor for the chunked-writer capacity limit. |
| [in,out] | req | Current request with an uncommitted response. Check HttpAsynchResp_isValid after construction. |
| BA_API void HttpAsynchResp_constructor2 | ( | HttpAsynchResp * | o, |
| char * | buf, | ||
| int | size, | ||
| HttpConnection * | con | ||
| ) |
Initialize from a connection and take over its socket.
| [out] | o | Caller-owned response storage. |
| [in] | buf | Required borrowed writable buffer, valid until close. |
| [in] | size | Capacity in bytes; use at least 256. See the C++ constructor for the chunked-writer capacity limit. |
| [in,out] | con | Source connection, or NULL for no active socket. Check HttpAsynchResp_isValid after construction. |
| BA_API BufPrint * HttpAsynchResp_getWriter | ( | HttpAsynchResp * | o | ) |
BufPrint is used when sending data of unknown length.
For a HTTP/1.1. connection, the data is sent in chunk transfer mode.
This method returns NULL if HttpAsynchResp::sendData was called prior to this method.
| [in,out] | o | Initialized response. |
| BA_API BaBool HttpAsynchResp_isValid | ( | HttpAsynchResp * | o | ) |
Check the installed buffer and connection.
| [in,out] | o | Initialized response. |
| BA_API void HttpAsynchResp_ReqRespInit | ( | HttpAsynchResp * | o, |
| char * | buf, | ||
| int | size, | ||
| HttpConnection * | con | ||
| ) |
Initialize the response half of a combined request/response object.
Prefer HttpAsynchReqResp_start to configure both halves together.
| [out] | o | Caller-owned response storage. |
| [in] | buf | Required borrowed writable buffer, valid until close. |
| [in] | size | Capacity in bytes; use at least 256 and respect the chunked-writer limit documented by HttpAsynchResp. |
| [in,out] | con | Required borrowed receive connection, valid until close; this initializer shares it instead of moving its socket. |
| BA_API int HttpAsynchResp_sendData | ( | HttpAsynchResp * | o, |
| const void * | data, | ||
| int | pktSize, | ||
| int | chunkSize | ||
| ) |
Begin a fixed-length response body.
| [in] | data | Borrowed source for this call, or NULL to send headers only. |
| [in] | pktSize | Nonnegative total body length in bytes, fitting int. |
| [in] | chunkSize | Initial byte count, between zero and pktSize; provide this many readable bytes when data is non-NULL. |
| [in,out] | o | Initialized response. |
| BA_API int HttpAsynchResp_sendNextChunk | ( | HttpAsynchResp * | o, |
| const void * | data, | ||
| int | chunkSize | ||
| ) |
Continue the fixed-length body begun with sendData.
| [in] | data | Borrowed source containing chunkSize readable bytes. |
| [in] | chunkSize | Nonnegative byte count; cumulative output must not exceed the pktSize declared by sendData. This is not HTTP chunked transfer coding. |
| [in,out] | o | Initialized response. |
| BA_API int HttpAsynchResp_setHeader | ( | HttpAsynchResp * | o, |
| const char * | name, | ||
| const char * | value | ||
| ) |
Append a response header before starting the body.
| [in] | name | Required NUL-terminated HTTP field name, used during this call. |
| [in] | value | Required NUL-terminated field value, used during this call. Neither string may contain CR or LF. Validation is the caller's responsibility. |
| [in,out] | o | Initialized response. |
| BA_API int HttpAsynchResp_setStatus | ( | HttpAsynchResp * | o, |
| int | statusCode, | ||
| const char * | protocol | ||
| ) |
Append the HTTP status line and standard Date/Server headers.
| [in] | statusCode | Code recognized by HttpServer_getStatusCode; unknown codes produce its fallback text rather than a valid numeric status line. |
| [in] | protocol | Borrowed NUL-terminated HTTP version for this call, normally "1.1" (also selected by NULL); do not include "HTTP/" or line breaks. |
| [in,out] | o | Initialized response. |
| HttpRecData::HttpRecData | ( | HttpRequest * | req | ) |
The constructor is typically run by creating an object on the stack.
| req | Required borrowed request for the current command, valid until this reader is destroyed. Run valid first and handle a negative result before constructing the reader. Construction claims consumption of the body and can send a 100 Continue response. Use from a command worker thread, not the dispatcher thread. The request body must not be read concurrently by another API. |
| BA_API void HttpRecData_constructor | ( | HttpRecData * | o, |
| HttpRequest * | req | ||
| ) |
The constructor is typically run by creating an object on the stack.
| req | Required borrowed request for the current command, valid until this reader is destroyed. Run valid first and handle a negative result before constructing the reader. Construction claims consumption of the body and can send a 100 Continue response. Use from a command worker thread, not the dispatcher thread. The request body must not be read concurrently by another API. | |
| [out] | o | Caller-owned reader storage. |
| BA_API void HttpRecData_destructor | ( | HttpRecData * | o | ) |
Finish reading, terminating the connection if unread body bytes remain.
| [in,out] | o | Initialized reader. Does not free o or its request. |
| BA_API S32 HttpRecData_read | ( | HttpRecData * | o, |
| void * | buf, | ||
| S32 | bufSize | ||
| ) |
Read data from socket.
| buf | Required caller-owned writable buffer of at least bufSize bytes. Returned data is binary and is not NUL-terminated. |
| bufSize | Positive capacity in bytes. Reads block until this many body bytes are obtained, the body ends, or an error occurs. |
| [in,out] | o | Initialized reader for a live command. |
| BA_API SBaFileSize HttpRecData_valid | ( | HttpRequest * | req | ) |
This method validates the client HTTP request.
The data received from the client must have a content-length or be chunk encoded. This is a preliminary body-type check, not complete HTTP framing validation. The caller must ensure that any Transfer-Encoding used here is chunked.
| [in] | req | Required borrowed request for the current command. |
| bool HttpAsynchReq::isChunkEncoding | ( | ) |
| bool HttpAsynchResp::isValid | ( | ) |
Check the installed buffer and connection.
| MultipartUpload::MultipartUpload | ( | HttpServer * | server, |
| MultipartUpload_EndOfReq | onEndOfReq, | ||
| MultipartUpload_FormData | onFormData, | ||
| MultipartUpload_FileBegin | onFileBegin, | ||
| MultipartUpload_FileData | onFileData, | ||
| MultipartUpload_Error | onError, | ||
| U32 | bufferSize, | ||
| AllocatorIntf * | allocator = 0 |
||
| ) |
| server | Required borrowed server; it and its dispatcher must outlive the parser. |
| onEndOfReq | is called when the multipart upload is completed. See MultipartUpload_EndOfReq. |
| onFormData | the function where you process form data. See MultipartUpload_FormData. |
| onFileBegin | is called when a file is found in the input stream. See MultipartUpload_FileBegin. |
| onFileData | is repeatedly called until end of file. See MultipartUpload_FileData. |
| onError | is called if an error is encountered when processing the input stream. See MultipartUpload_Error. |
| bufferSize | Initial buffer size and growth increment in bytes. Initialization uses at least 1024 bytes and may grow to hold buffered request data. Zero disables later growth. Growth increments above 50000 are not used by the current implementation. This is working storage, not a total file-upload size limit. |
| allocator | Borrowed allocator with allocation, reallocation, and free support. NULL selects AllocatorIntf_getDefault(). Keep it alive until parser destruction. The input buffer is allocated by start()/run(), not by this constructor. |
| void BA_API MultipartUpload_constructor | ( | MultipartUpload * | o, |
| HttpServer * | server, | ||
| MultipartUpload_EndOfReq | endOfReq, | ||
| MultipartUpload_FormData | formData, | ||
| MultipartUpload_FileBegin | fileBegin, | ||
| MultipartUpload_FileData | fileData, | ||
| MultipartUpload_Error | onError, | ||
| U32 | bufferSize, | ||
| AllocatorIntf * | allocator | ||
| ) |
Construct a parser as described by MultipartUpload::MultipartUpload.
| o | Required storage to initialize. |
| server | Required borrowed server. |
| endOfReq | Required completion callback. |
| formData | Required form-field callback. |
| fileBegin | Required file-header callback. |
| fileData | Required file-data callback. |
| onError | Required error callback. |
| bufferSize | Initial working-buffer size and growth increment in bytes. |
| allocator | Borrowed allocator, or NULL for the default allocator. |
| BA_API void MultipartUpload_destructor | ( | MultipartUpload * | o | ) |
Detach from the dispatcher, free parsing storage, and close the embedded asynchronous connection if still owned.
In blocking mode the request retains its separate connection. The server and allocator are borrowed and not freed.
| o | Required initialized parser. |
| BA_API HttpConnection * MultipartUpload_getCon | ( | MultipartUpload * | o | ) |
Detach and prepare an asynchronous connection handoff.
| o | Required initialized parser on which to act. |
| BA_API int MultipartUpload_run | ( | MultipartUpload * | o, |
| HttpRequest * | req, | ||
| BaBool | setKeepAlive | ||
| ) |
Parse multipart input synchronously, blocking for additional bytes.
| req | Required current POST multipart/form-data request. |
| setKeepAlive | True (default) enables keep-alive when possible; false does not enable it. This does not force a close or override later errors. |
| o | Required initialized parser. |
| BA_API int MultipartUpload_start | ( | MultipartUpload * | o, |
| HttpRequest * | req | ||
| ) |
Start asynchronous multipart input, taking the request connection.
| req | Required uncommitted POST multipart/form-data request with a live connection. The parser enables keep-alive and can send 100 Continue. |
| o | Required initialized parser. |
Read data from socket.
| buf | Required caller-owned writable buffer of at least bufSize bytes. Returned data is binary and is not NUL-terminated. |
| bufSize | Positive capacity in bytes. Reads block until this many body bytes are obtained, the body ends, or an error occurs. |
| int MultipartUpload::run | ( | HttpRequest * | req, |
| bool | setKeepAlive = true |
||
| ) |
Parse multipart input synchronously, blocking for additional bytes.
| req | Required current POST multipart/form-data request. |
| setKeepAlive | True (default) enables keep-alive when possible; false does not enable it. This does not force a close or override later errors. |
| int HttpAsynchResp::sendData | ( | const void * | data, |
| int | pktSize, | ||
| int | chunkSize | ||
| ) |
Begin a fixed-length response body.
| [in] | data | Borrowed source for this call, or NULL to send headers only. |
| [in] | pktSize | Nonnegative total body length in bytes, fitting int. |
| [in] | chunkSize | Initial byte count, between zero and pktSize; provide this many readable bytes when data is non-NULL. |
| int HttpAsynchResp::sendNextChunk | ( | const void * | data, |
| int | chunkSize | ||
| ) |
Continue the fixed-length body begun with sendData.
| [in] | data | Borrowed source containing chunkSize readable bytes. |
| [in] | chunkSize | Nonnegative byte count; cumulative output must not exceed the pktSize declared by sendData. This is not HTTP chunked transfer coding. |
| int HttpAsynchResp::setConClose | ( | ) |
Close connection when the HttpAsynchResp object is done.
A persistent HTTP 1.1 connection is recycled and sent back to the connection pool in the web-server when the HttpAsynchResp object is done. Calling this method makes sure the connection closes when the HttpAsynchResp object is done.
| int HttpAsynchResp::setHeader | ( | const char * | name, |
| const char * | value | ||
| ) |
Append a response header before starting the body.
| [in] | name | Required NUL-terminated HTTP field name, used during this call. |
| [in] | value | Required NUL-terminated field value, used during this call. Neither string may contain CR or LF. Validation is the caller's responsibility. |
| int HttpAsynchResp::setLingeringClose | ( | ) |
Request connection closure.
| int HttpAsynchResp::setStatus | ( | int | statusCode, |
| const char * | protocol = 0 |
||
| ) |
Append the HTTP status line and standard Date/Server headers.
| [in] | statusCode | Code recognized by HttpServer_getStatusCode; unknown codes produce its fallback text rather than a valid numeric status line. |
| [in] | protocol | Borrowed NUL-terminated HTTP version for this call, normally "1.1" (also selected by NULL); do not include "HTTP/" or line breaks. |
| int MultipartUpload::start | ( | HttpRequest * | req | ) |
Start asynchronous multipart input, taking the request connection.
| req | Required uncommitted POST multipart/form-data request with a live connection. The parser enables keep-alive and can send 100 Continue. |
| int HttpAsynchReq::start | ( | HttpRequest * | req, |
| void * | buffer, | ||
| S32 | bufferSize | ||
| ) |
Take over the request connection and start asynchronous reception.
| [in,out] | req | Borrowed current request with an uncommitted response. |
| [in] | buffer | Caller-owned writable storage, valid until reception stops. |
| [in] | bufferSize | Capacity in bytes, at least 255. Chunk header lines must fit this buffer. Chunked trailer fields are not supported. |
| int HttpAsynchReqResp::start | ( | HttpRequest * | req, |
| void * | recBuf, | ||
| S32 | recBufSize, | ||
| void * | sendBuf, | ||
| S32 | sendBufSize | ||
| ) |
Start the HttpAsynchReqResp object.
The onData callback method is called directly if all data was received by the client; otherwise, the HttpAsynchReq object is installed into the SoDisp. The method returns a negative value if the HttpAsynchReq object failed to start. The method returns 0 if the object started successfully or if the destructor was called from within the onData callback.
| req | Required borrowed current request with an uncommitted response. |
| recBuf | Borrowed writable receive buffer, valid until reception stops. The onData callback is called when the buffer is full. |
| recBufSize | Receive capacity in bytes, at least 255. |
| sendBuf | Separate borrowed writable response buffer, valid until close. |
| sendBufSize | Response capacity in bytes; use at least 256. The buffers must not overlap while sending and receiving concurrently. |
| int HttpAsynchReqResp::startResp | ( | HttpRequest * | req, |
| void * | sendBuf, | ||
| S32 | sendBufSize | ||
| ) |
Start response if you know that all data was received by the web-server.
This is a faster method than calling start if you know that the web-server received all data in its internal buffer before delegating the request to the requested service.
| [in,out] | req | Current request; caller must account for any unread body before selecting this response-only path. No receive callback runs. |
| [in] | sendBuf | Borrowed writable response storage, valid until close. |
| [in] | sendBufSize | Response capacity in bytes; use at least 256. |
| void HttpAsynchReq::stop | ( | ) |
Remove active dispatcher reception, mark an active connection terminated, and clear receive-buffer state.
Does not free borrowed buffer storage. Use destruction for final connection cleanup.
|
static |
This method validates the client HTTP request.
The data received from the client must have a content-length or be chunk encoded. This is a preliminary body-type check, not complete HTTP framing validation. The caller must ensure that any Transfer-Encoding used here is chunked.
| [in] | req | Required borrowed request for the current command. |
| HttpAsynchReq::~HttpAsynchReq | ( | ) |
Stop dispatcher reception and destroy the owned connection.
Does not free this object or the borrowed buffer. May be called from OnData; after a connection handoff, it does not close the moved connection.
| HttpAsynchResp::~HttpAsynchResp | ( | ) |
Calls method close.
| HttpRecData::~HttpRecData | ( | ) |
Finish using the reader.
If body bytes remain unread, mark the connection terminated rather than attempting to drain them. Does not destroy the request. Destroy before its command returns.
| MultipartUpload::~MultipartUpload | ( | ) |
Detach from the dispatcher, free parsing storage, and close the embedded asynchronous connection if still owned.
In blocking mode the request retains its separate connection. The server and allocator are borrowed and not freed.