cwist
Modern C web framework with libttak runtime
Loading...
Searching...
No Matches
multipart.h File Reference

RFC 7578 multipart/form-data parser. More...

#include <stddef.h>
Include dependency graph for multipart.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  cwist_multipart_field
 
struct  cwist_multipart_result
 

Typedefs

typedef struct cwist_multipart_field cwist_multipart_field
 
typedef struct cwist_multipart_result cwist_multipart_result
 

Functions

cwist_multipart_result * cwist_multipart_parse (const char *body, size_t body_len, const char *boundary)
 Parse a multipart/form-data body.
 
void cwist_multipart_result_destroy (cwist_multipart_result *result)
 Free all memory associated with a multipart parse result.
 
char * cwist_multipart_extract_boundary (const char *content_type)
 Extract the boundary string from a Content-Type header value.
 

Detailed Description

RFC 7578 multipart/form-data parser.

Definition in file multipart.h.

Typedef Documentation

◆ cwist_multipart_field

◆ cwist_multipart_result

Function Documentation

◆ cwist_multipart_extract_boundary()

char * cwist_multipart_extract_boundary ( const char *  content_type)

Extract the boundary string from a Content-Type header value.

Parameters
content_typeContent-Type header value, e.g. "multipart/form-data; boundary=----WebKitFormBoundary..."
Returns
Heap-allocated boundary string (caller must free), or NULL if not found.

Extract the boundary string from a Content-Type header value.

Scans semicolon-separated parameters of content_type, skipping optional whitespace, and accepts both quoted and unquoted boundary values.

Parameters
content_typeContent-Type header value, e.g. from the request; may be NULL.
Returns
Newly allocated NUL-terminated boundary string (caller frees with cwist_free), or NULL if no boundary parameter is present or allocation failed.

Definition at line 363 of file multipart.c.

References cap, and cwist_alloc().

◆ cwist_multipart_parse()

cwist_multipart_result * cwist_multipart_parse ( const char *  body,
size_t  body_len,
const char *  boundary 
)

Parse a multipart/form-data body.

Parameters
bodyRaw body buffer (may contain binary data).
body_lenLength of body in bytes.
boundaryBoundary string (without leading hyphens).
Returns
Parsed result, or NULL on allocation failure or malformed input.

Parse a multipart/form-data body.

Runs the multipart-parser-c state machine over body with boundary (the boundary without leading dashes). On malformed or truncated input the parser stops early and NULL is returned, with all intermediate state freed.

Parameters
bodyRaw body bytes; must not be NULL.
body_lenLength of body in bytes.
boundaryMIME boundary string, without the leading "--".
Returns
Newly allocated cwist_multipart_result on success (caller owns it, release with cwist_multipart_result_destroy), NULL on invalid arguments, malformed input, or allocation failure.

Definition at line 269 of file multipart.c.

References cap, cwist_alloc(), cwist_free(), cwist_multipart_result_destroy(), CWIST_SCRATCH_DEFER, and cwist_multipart_result::fields.

◆ cwist_multipart_result_destroy()

void cwist_multipart_result_destroy ( cwist_multipart_result *  result)

Free all memory associated with a multipart parse result.

Parameters
resultResult to destroy. NULL is ignored.

Free all memory associated with a multipart parse result.

Frees every field's name, filename, content_type, and data, then the field nodes and the result itself. Safe to call with NULL.

Parameters
resultResult returned by cwist_multipart_parse, or NULL.

Definition at line 336 of file multipart.c.

References cap, cwist_free(), cwist_multipart_result::fields, and cwist_multipart_field::next.

Referenced by cwist_multipart_parse().