Barracuda Application Server C/C++ Reference
Native APIs, integration guides, and platform interfaces
MultipartUpload.h
Go to the documentation of this file.
1/*
2 * ____ _________ __ _
3 * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____
4 * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/
5 * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__
6 * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/
7 * /____/
8 *
9 * Barracuda Embedded Web-Server
10 *
11 ****************************************************************************
12 * HEADER
13 *
14 * $Id: MultipartUpload.h 6056 2026-09-20 05:09:33Z wini $
15 *
16 * COPYRIGHT: Real Time Logic LLC, 2006 - 2026
17 *
18 * This software is copyrighted by and is the sole property of Real
19 * Time Logic LLC. All rights, title, ownership, or other interests in
20 * the software remain the property of Real Time Logic LLC. This
21 * software may only be used in accordance with the terms and
22 * conditions stipulated in the corresponding license agreement under
23 * which the software has been supplied. Any unauthorized use,
24 * duplication, transmission, distribution, or disclosure of this
25 * software is expressly forbidden.
26 *
27 * This Copyright notice may not be removed or modified without prior
28 * written consent of Real Time Logic LLC.
29 *
30 * Real Time Logic LLC. reserves the right to modify this software
31 * without notice.
32 *
33 * http://www.realtimelogic.com
34 ****************************************************************************
35 *
36 *
37 */
38
41#ifndef __HttpMultipartUpload_h
42#define __HttpMultipartUpload_h
43
44#include "HttpServer.h"
45#include "BaServerLib.h"
46
56typedef enum
57{
58 MultipartUpload_NoError=0,
59 MultipartUpload_ConnectionTerminated=-100,
60 MultipartUpload_NoMemory,
61 MultipartUpload_ParseError1,
62 MultipartUpload_ParseError2,
63 MultipartUpload_ParseError3,
64 MultipartUpload_ParseError4,
65 MultipartUpload_ParseError5,
66 MultipartUpload_ParseError6,
67 MultipartUpload_UserRetErr
69
70#ifndef __DOXYGEN__
71struct MultipartUpload;
72#endif
73
81 struct MultipartUpload* o);
82
83
103 struct MultipartUpload* o,
104 const char* name,
105 const char* value);
106
130 struct MultipartUpload* o,
131 const char* name,
132 const char* fileName,
133 const char* contentType,
134 const char* contentTransferEncoding);
135
155 struct MultipartUpload* o,
156 const U8* data,
157 U16 len);
158
168typedef void (*MultipartUpload_Error)(
169 struct MultipartUpload* o,
171
172
173
174typedef enum {
175 MultipartUpload_ReadBoundaryTag,
176 MultipartUpload_ReadHeaders,
177 MultipartUpload_ReadFormData,
178 MultipartUpload_ReadFileData,
179 MultipartUpload_DrainBody
180} MultipartUpload_States;
181
182
195typedef struct MultipartUpload
196{
197#ifdef __cplusplus
200
234 MultipartUpload_EndOfReq onEndOfReq,
235 MultipartUpload_FormData onFormData,
236 MultipartUpload_FileBegin onFileBegin,
237 MultipartUpload_FileData onFileData,
238 MultipartUpload_Error onError,
239 U32 bufferSize,
240 AllocatorIntf* allocator = 0);
241
247
259 int start(HttpRequest *req);
260
261
271 int run(HttpRequest *req, bool setKeepAlive=true);
272
284
289
290 private:
291#endif
292 HttpConnection super; /* Inherits from HttpConnection */
293
294 /* List used as a stack, containing Boundary tags. */
295 DoubleList boundaryStack;
300 MultipartUpload_Error onError;
301 HttpConnection* con; /* Set if in blocking mode. NULL for asynch mode. */
302 char* dataBuffer;
303 char* name;
304 char* fileName;
305 char* contentType;
306 char* contentTransferEncoding;
307 char* currBName;
308 AllocatorIntf* alloc;
309 MultipartUpload_States state;
310 U32 chunkLineLen;
311 U32 readI;
312 U32 lineStartI;
313 U32 lineEndI;
314 U32 dataBufferSize;
315 U32 expandSize;
316 U32 maxFormSize;
317 BaBool newBoundaryTag;
318 BaBool chunked;
319 SBaFileSize bodyLeft; /* Bytes left, or chunk metadata state. */
320 HttpRequest* request; /* Borrowed during blocking run(); NULL otherwise. */
322
323
324#ifdef __cplusplus
325extern "C" {
326#endif
338void
341 HttpServer* server,
346 MultipartUpload_Error onError,
347 U32 bufferSize,
348 AllocatorIntf* allocator);
361 MultipartUpload* o, HttpRequest *req, BaBool setKeepAlive);
370#define MultipartUpload_getServer(o) \
371 HttpConnection_getServer((HttpConnection*)(o))
372#ifdef __cplusplus
373}
375 HttpServer* server,
380 MultipartUpload_Error onError,
381 U32 size,
382 AllocatorIntf* allocator) {
383 MultipartUpload_constructor(this, server, endOfReq, formData,
384 fileBegin, fileData, onError, size, allocator);
385}
388}
390 return MultipartUpload_start(this,req);
391}
392inline int MultipartUpload::run(HttpRequest *req, bool setKeepAlive) {
393 return MultipartUpload_run(this,req,setKeepAlive?TRUE:FALSE);
394}
396 return MultipartUpload_getCon(this); }
398 return MultipartUpload_getServer(this);
399}
400#endif
401 /* end of HttpStack */
403
404
405#endif
struct MultipartUpload MultipartUpload
Parser for multipart/form-data POST requests.
BA_API HttpConnection * MultipartUpload_getCon(MultipartUpload *o)
Detach and prepare an asynchronous connection handoff.
int(* MultipartUpload_FileData)(struct MultipartUpload *o, const U8 *data, U16 len)
Executed by MultipartUpload when a data chunk is available.
Definition: MultipartUpload.h:154
BA_API int MultipartUpload_run(MultipartUpload *o, HttpRequest *req, BaBool setKeepAlive)
Parse multipart input synchronously, blocking for additional bytes.
int run(HttpRequest *req, bool setKeepAlive=true)
Parse multipart input synchronously, blocking for additional bytes.
Definition: MultipartUpload.h:392
HttpConnection * getCon(MultipartUpload *o)
Detach the asynchronous parser and release parsing buffers for a handoff.
Definition: MultipartUpload.h:395
~MultipartUpload()
Detach from the dispatcher, free parsing storage, and close the embedded asynchronous connection if s...
Definition: MultipartUpload.h:386
BA_API void MultipartUpload_destructor(MultipartUpload *o)
Detach from the dispatcher, free parsing storage, and close the embedded asynchronous connection if s...
void(* MultipartUpload_EndOfReq)(struct MultipartUpload *o)
Report the final multipart boundary.
Definition: MultipartUpload.h:80
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 d...
Definition: MultipartUpload.h:102
void(* MultipartUpload_Error)(struct MultipartUpload *o, MultipartUpload_ErrorType e)
Executed by MultipartUpload if any errors are detected during parsing of the multipart data stream.
Definition: MultipartUpload.h:168
HttpServer * getServer()
Get the server supplied to the constructor.
Definition: MultipartUpload.h:397
BA_API int MultipartUpload_start(MultipartUpload *o, HttpRequest *req)
Start asynchronous multipart input, taking the request connection.
#define MultipartUpload_getServer(o)
Get the server supplied to the constructor.
Definition: MultipartUpload.h:370
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.
Definition: MultipartUpload.h:129
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.
MultipartUpload_ErrorType
Error codes used by the callback function MultipartUpload_Error in interface class MultipartUpload.
Definition: MultipartUpload.h:57
int start(HttpRequest *req)
Start asynchronous multipart input, taking the request connection.
Definition: MultipartUpload.h:389
uint16_t U16
Unsigned 16-bit integer.
Definition: GenPrimT.h:91
S32 SBaFileSize
Signed file-size value in bytes; 32 bits without BA_FILESIZE64.
Definition: GenPrimT.h:138
uint32_t U32
Unsigned 32-bit integer.
Definition: GenPrimT.h:93
uint8_t U8
Unsigned 8-bit integer.
Definition: GenPrimT.h:89
U8 BaBool
Boolean stored in an unsigned byte; FALSE is zero and TRUE is one.
Definition: GenPrimT.h:118
Memory allocation and deallocation Interface class.
Definition: AllocatorIntf.h:98
Contains information about the physical socket connection.
Definition: HttpConnection.h:80
The HttpServer creates an HttpRequest object when the HttpServer parses a client request.
Definition: HttpServer.h:950
The Web Server.
Definition: HttpServer.h:3393
Parser for multipart/form-data POST requests.
Definition: MultipartUpload.h:196
MultipartUpload()
Uninitialized storage; call MultipartUpload_constructor before use.
Definition: MultipartUpload.h:199