Csilk 0.2.1
A lightweight, high-performance C HTTP web framework
Loading...
Searching...
No Matches
multipart.c File Reference

Multipart/form-data request body parsing implementation. More...

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "csilk/core/internal.h"
#include "csilk/csilk.h"
Include dependency graph for multipart.c:

Macros

#define CSILK_MAX_PART_HEADERS   32
 
#define CSILK_MAX_PART_NAME   128
 
#define CSILK_MAX_PART_FILENAME   256
 

Functions

void csilk_multipart_parse (csilk_ctx_t *c, csilk_multipart_handler_t handler)
 Parse a multipart/form-data request body and invoke a handler for each part.
 

Detailed Description

Multipart/form-data request body parsing implementation.

Macro Definition Documentation

◆ CSILK_MAX_PART_FILENAME

#define CSILK_MAX_PART_FILENAME   256

◆ CSILK_MAX_PART_HEADERS

#define CSILK_MAX_PART_HEADERS   32

◆ CSILK_MAX_PART_NAME

#define CSILK_MAX_PART_NAME   128

Function Documentation

◆ csilk_multipart_parse()

void csilk_multipart_parse ( csilk_ctx_t *  c,
csilk_multipart_handler_t  handler 
)

Parse a multipart/form-data request body and invoke a handler for each part.

Parse a multipart/form-data request body.

Extracts the boundary string from the Content-Type header, then iterates through the request body looking for boundary-delimited parts. For each part, the function parses the Content-Disposition header (extracting name and optional filename), the optional Content-Type header, and the part body. A csilk_multipart_part_t struct is populated and passed to the caller-supplied handler callback.

Parameters
cThe request context containing the parsed body.
handlerCallback invoked once per parsed part. Receives a pointer to a csilk_multipart_part_t describing the part. Must not be NULL.
Note
The part data pointers reference memory within the request body buffer directly — they are NOT copies. The handler must not modify or store the pointers beyond its invocation.
Warning
Part body data is NOT null-terminated. Use part.data_len to determine the bounds.
Maximum part name length is 127 bytes, maximum filename length is 255 bytes, and maximum part headers per section is 32. Parts exceeding these limits will be silently truncated.