Barracuda Application Server C/C++ Reference
NO
MultipartUpload.h
1 /*
2  * ____ _________ __ _
3  * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____
4  * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/
5  * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__
6  * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/
7  * /____/
8  *
9  * Barracuda Embedded Web-Server
10  *
11  ****************************************************************************
12  * HEADER
13  *
14  * $Id: MultipartUpload.h 4915 2021-12-01 18:26:55Z wini $
15  *
16  * COPYRIGHT: Real Time Logic LLC, 2003 - 2008
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 
39 #ifndef __HttpMultipartUpload_h
40 #define __HttpMultipartUpload_h
41 
42 #include "HttpServer.h"
43 #include "BaServerLib.h"
44 
54 typedef enum
55 {
56  MultipartUpload_NoError=0,
57  MultipartUpload_ConnectionTerminated=-100,
58  MultipartUpload_NoMemory,
59  MultipartUpload_ParseError1,
60  MultipartUpload_ParseError2,
61  MultipartUpload_ParseError3,
62  MultipartUpload_ParseError4,
63  MultipartUpload_ParseError5,
64  MultipartUpload_ParseError6,
65  MultipartUpload_UserRetErr
67 
68 #ifndef __DOXYGEN__
69 struct MultipartUpload;
70 #endif
71 
78 typedef void (*MultipartUpload_EndOfReq)(
79  struct MultipartUpload* o);
80 
81 
97 typedef int (*MultipartUpload_FormData)(
98  struct MultipartUpload* o,
99  const char* name,
100  const char* value);
101 
118  struct MultipartUpload* o,
119  const char* name,
120  const char* fileName,
121  const char* contentType,
122  const char* contentTransferEncoding);
123 
136  struct MultipartUpload* o,
137  const U8* data,
138  U16 len);
139 
145 typedef void (*MultipartUpload_Error)(
146  struct MultipartUpload* o,
148 
149 
150 
151 typedef enum {
152  MultipartUpload_ReadBoundaryTag,
153  MultipartUpload_ReadHeaders,
154  MultipartUpload_ReadFormData,
155  MultipartUpload_ReadFileData
156 } MultipartUpload_States;
157 
158 
186 typedef struct MultipartUpload
187 {
188 #ifdef __cplusplus
189  MultipartUpload() {}
190 
221  MultipartUpload(HttpServer* server,
222  MultipartUpload_EndOfReq onEndOfReq,
223  MultipartUpload_FormData onFormData,
224  MultipartUpload_FileBegin onFileBegin,
225  MultipartUpload_FileData onFileData,
226  MultipartUpload_Error onError,
227  U32 bufferSize,
228  AllocatorIntf* allocator = 0);
229 
232 
241  int start(HttpRequest *req);
242 
243 
244  int run(HttpRequest *req, bool setKeepAlive=true);
245 
259 
263 
264  private:
265 #endif
266  HttpConnection super; /* Inherits from HttpConnection */
267 
268  /* List used as a stack, containing Boundary tags. */
269  DoubleList boundaryStack;
270  MultipartUpload_EndOfReq endOfReq;
271  MultipartUpload_FormData formData;
272  MultipartUpload_FileBegin fileBegin;
273  MultipartUpload_FileData fileData;
274  MultipartUpload_Error onError;
275  HttpConnection* con; /* Set if in blocking mode. NULL for asynch mode. */
276  char* dataBuffer;
277  char* name;
278  char* fileName;
279  char* contentType;
280  char* contentTransferEncoding;
281  char* currBName;
282  AllocatorIntf* alloc;
283  MultipartUpload_States state;
284  U32 currentI;
285  U32 readI;
286  U32 lineStartI;
287  U32 lineEndI;
288  U32 dataBufferSize;
289  U32 expandSize;
290  U32 maxFormSize;
291  BaBool newBoundaryTag;
292  BaBool copyingHttpReqData;
294 
295 
296 #ifdef __cplusplus
297 extern "C" {
298 #endif
299 void
300 BA_API MultipartUpload_constructor(
301  MultipartUpload* o,
302  HttpServer* server,
303  MultipartUpload_EndOfReq endOfReq,
304  MultipartUpload_FormData formData,
305  MultipartUpload_FileBegin fileBegin,
306  MultipartUpload_FileData fileData,
307  MultipartUpload_Error onError,
308  U32 bufferSize,
309  AllocatorIntf* allocator);
310 BA_API void MultipartUpload_destructor(MultipartUpload* o);
311 BA_API int MultipartUpload_start(MultipartUpload* o, HttpRequest *req);
312 BA_API int MultipartUpload_run(
313  MultipartUpload* o, HttpRequest *req, BaBool setKeepAlive);
314 BA_API HttpConnection* MultipartUpload_getCon(MultipartUpload* o);
315 #define MultipartUpload_getServer(o) \
316  HttpConnection_getServer((HttpConnection*)(o))
317 #ifdef __cplusplus
318 }
319 inline MultipartUpload::MultipartUpload(
320  HttpServer* server,
321  MultipartUpload_EndOfReq endOfReq,
322  MultipartUpload_FormData formData,
323  MultipartUpload_FileBegin fileBegin,
324  MultipartUpload_FileData fileData,
325  MultipartUpload_Error onError,
326  U32 size,
327  AllocatorIntf* allocator) {
328  MultipartUpload_constructor(this, server, endOfReq, formData,
329  fileBegin, fileData, onError, size, allocator);
330 }
332  MultipartUpload_destructor(this);
333 }
335  return MultipartUpload_start(this,req);
336 }
337 inline int MultipartUpload::run(HttpRequest *req, bool setKeepAlive) {
338  return MultipartUpload_run(this,req,setKeepAlive?TRUE:FALSE);
339 }
341  return MultipartUpload_getCon(this); }
343  return MultipartUpload_getServer(this);
344 }
345 #endif
346  /* end of HttpStack */
348 
349 
350 #endif
HttpRequest
The HttpServer creates an HttpRequest object when the HttpServer parses a client request.
Definition: HttpServer.h:819
AllocatorIntf
Memory allocation and deallocation Interface class.
Definition: AllocatorIntf.h:83
MultipartUpload_EndOfReq
void(* MultipartUpload_EndOfReq)(struct MultipartUpload *o)
Executed by MultipartUpload when a multipart upload is completed.
Definition: MultipartUpload.h:78
MultipartUpload::getServer
HttpServer * getServer()
Get the HttpServer instance.
Definition: MultipartUpload.h:342
MultipartUpload_FormData
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:97
MultipartUpload_FileBegin
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:117
HttpConnection
Contains information about the physical socket connection.
Definition: HttpConnection.h:76
MultipartUpload_Error
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:145
MultipartUpload::getCon
HttpConnection * getCon(MultipartUpload *o)
Returns the internal active connection object.
Definition: MultipartUpload.h:340
MultipartUpload_FileData
int(* MultipartUpload_FileData)(struct MultipartUpload *o, const U8 *data, U16 len)
Executed by MultipartUpload when a data chunk is available.
Definition: MultipartUpload.h:135
MultipartUpload::start
int start(HttpRequest *req)
Start receiving data asynchronously.
Definition: MultipartUpload.h:334
MultipartUpload
The MultipartUpload, which is an abstract base class, implements the functionality as specified in RF...
Definition: MultipartUpload.h:187
MultipartUpload::~MultipartUpload
~MultipartUpload()
Release buffers used during parsing the multipart stream.
Definition: MultipartUpload.h:331
MultipartUpload
struct MultipartUpload MultipartUpload
The MultipartUpload, which is an abstract base class, implements the functionality as specified in RF...
HttpServer
The Web Server.
Definition: HttpServer.h:2887
MultipartUpload_ErrorType
MultipartUpload_ErrorType
Error codes used by the callback function MultipartUpload_Error in interface class MultipartUpload.
Definition: MultipartUpload.h:55