Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_http_form.c File Reference

Strict percent-decoding, query strings and urlencoded forms (see n_http_form.h). More...

#include "nilorea/n_http_form.h"
#include "nilorea/n_common.h"
#include "nilorea/n_log.h"
#include "nilorea/n_str.h"
#include <stdlib.h>
#include <string.h>
Include dependency graph for n_http_form.c:

Go to the source code of this file.

Data Structures

struct  _mp_param

Macros

#define _MP_PREAMBLE_MAX   1024

Functions

static char * _form_decode_dup (const char *s, size_t len, int flags, size_t *out_len)
static size_t _form_decode_into (const char *s, size_t len, int flags, char *dst)
static int _form_hex (unsigned char c)
static int _mp_bchar (unsigned char c)
static size_t _mp_find_delim (const char *b, size_t len, size_t from, const char *boundary, size_t blen, size_t *after, int *closing)
static int _mp_ieq (const char *s, size_t n, const char *lit)
static int _mp_lc (int c)
static int _mp_next_param (const char *v, size_t n, size_t *pos, _mp_param *p)
static int _mp_part_headers (const char *h, size_t n, N_HTTP_FORM_PART *part)
static int _mp_tchar (unsigned char c)
static int _mp_text_ok (const char *s, size_t n)
size_t n_http_form_count (const N_HTTP_FORM *form, const char *name)
 number of fields named name (exact, case-sensitive)
void n_http_form_free (N_HTTP_FORM **form)
 free a form and set *form to NULL
const char * n_http_form_get (const N_HTTP_FORM *form, const char *name, size_t *value_len)
 value of the LAST field named name (PHP semantics)
int n_http_form_multipart_boundary (const char *content_type, size_t len, char *out)
 boundary of a multipart/form-data Content-Type, parsed strictly
size_t n_http_form_multipart_count (const N_HTTP_FORM_MULTIPART *mp, const char *name)
 number of parts named name
void n_http_form_multipart_free (N_HTTP_FORM_MULTIPART **mp)
 free a parsed body and set *mp to NULL
const N_HTTP_FORM_PART * n_http_form_multipart_get (const N_HTTP_FORM_MULTIPART *mp, const char *name)
 the LAST part named name (PHP semantics)
N_HTTP_FORM_MULTIPART * n_http_form_multipart_parse (const char *buf, size_t len, const char *boundary, size_t max_parts)
 parse a multipart/form-data body strictly, without copying it
N_HTTP_FORM * n_http_form_parse (const char *s, size_t len, size_t max_fields, int flags)
 decode a query string or an urlencoded body into fields
int n_http_percent_decode (const char *s, size_t len, int flags, N_STR **out)
 percent-decode [s, s+len), appending to *out; malformed escapes, a decoded NUL and (without N_HTTP_FORM_RAW_BYTES) ill-formed UTF-8 refused

Detailed Description

Strict percent-decoding, query strings and urlencoded forms (see n_http_form.h).

Author
Castagnier Mickael
Version
1.0
Date
2026

Definition in file n_http_form.c.


Data Structure Documentation

◆ _mp_param

struct _mp_param

Definition at line 285 of file n_http_form.c.

Collaboration diagram for _mp_param:
Data Fields
const char * name
size_t name_len
char value[255+2]
size_t value_len

Macro Definition Documentation

◆ _MP_PREAMBLE_MAX

#define _MP_PREAMBLE_MAX   1024

Definition at line 254 of file n_http_form.c.

Referenced by n_http_form_multipart_parse().

Function Documentation

◆ _form_decode_dup()

char * _form_decode_dup ( const char * s,
size_t len,
int flags,
size_t * out_len )
static

Definition at line 77 of file n_http_form.c.

References __n_assert, _form_decode_into(), Free, Malloc, N_HTTP_FORM_RAW_BYTES, and n_str_utf8_valid().

Referenced by n_http_form_parse(), and n_http_percent_decode().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _form_decode_into()

size_t _form_decode_into ( const char * s,
size_t len,
int flags,
char * dst )
static

Definition at line 51 of file n_http_form.c.

References _form_hex(), and N_HTTP_FORM_PLUS_SPACE.

Referenced by _form_decode_dup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _form_hex()

int _form_hex ( unsigned char c)
static

Definition at line 39 of file n_http_form.c.

Referenced by _form_decode_into().

Here is the caller graph for this function:

◆ _mp_bchar()

int _mp_bchar ( unsigned char c)
static

Definition at line 278 of file n_http_form.c.

Referenced by n_http_form_multipart_boundary().

Here is the caller graph for this function:

◆ _mp_find_delim()

size_t _mp_find_delim ( const char * b,
size_t len,
size_t from,
const char * boundary,
size_t blen,
size_t * after,
int * closing )
static

Definition at line 402 of file n_http_form.c.

Referenced by n_http_form_multipart_parse().

Here is the caller graph for this function:

◆ _mp_ieq()

int _mp_ieq ( const char * s,
size_t n,
const char * lit )
static

Definition at line 261 of file n_http_form.c.

References _mp_lc().

Referenced by _mp_part_headers(), and n_http_form_multipart_boundary().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _mp_lc()

int _mp_lc ( int c)
static

Definition at line 256 of file n_http_form.c.

Referenced by _mp_ieq().

Here is the caller graph for this function:

◆ _mp_next_param()

int _mp_next_param ( const char * v,
size_t n,
size_t * pos,
_mp_param * p )
static

Definition at line 295 of file n_http_form.c.

References _mp_tchar(), _mp_param::name, _mp_param::name_len, _mp_param::value, and _mp_param::value_len.

Referenced by _mp_part_headers(), and n_http_form_multipart_boundary().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _mp_part_headers()

◆ _mp_tchar()

int _mp_tchar ( unsigned char c)
static

Definition at line 271 of file n_http_form.c.

Referenced by _mp_next_param(), and _mp_part_headers().

Here is the caller graph for this function:

◆ _mp_text_ok()

int _mp_text_ok ( const char * s,
size_t n )
static

Definition at line 388 of file n_http_form.c.

References n_str_utf8_valid().

Referenced by _mp_part_headers().

Here is the call graph for this function:
Here is the caller graph for this function: