Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
ex_http_form.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "nilorea/n_common.h"
#include "nilorea/n_http_form.h"
#include "nilorea/n_log.h"
#include "nilorea/n_str.h"
Include dependency graph for ex_http_form.c:

Go to the source code of this file.

Macros

#define BND(ct)
 boundary of a NUL-terminated Content-Type literal, into b

Functions

static int decodes_to (const char *in, int flags, const char *want)
 decode a NUL-terminated literal and compare with the expected result
static void expect_true (const char *what, int ok)
 count a failed check
int main (int argc, char **argv)
 run the checks
static N_HTTP_FORM_MULTIPART * mp_parse (const char *body, size_t max)
 parse a NUL-terminated multipart body
static int part_body_is (const char *buf, const N_HTTP_FORM_PART *p, const char *want)
 body of a part as a string comparison
static int process_args (int argc, char **argv)
 read -V
static void test_decode (void)
 percent-decoding
static void test_form (void)
 query strings and urlencoded bodies
static void test_multipart (void)
 multipart/form-data

Variables

static int failures = 0
 failed checks
static int log_level = 3
 log level from -V

Macro Definition Documentation

◆ BND

#define BND ( ct)
Value:
n_http_form_multipart_boundary((ct), strlen(ct), b)
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

boundary of a NUL-terminated Content-Type literal, into b

Examples
ex_http_form.c.

Definition at line 195 of file ex_http_form.c.

Referenced by test_multipart().

Function Documentation

◆ decodes_to()

int decodes_to ( const char * in,
int flags,
const char * want )
static

decode a NUL-terminated literal and compare with the expected result

Parameters
inencoded text
flagsdecode flags
wantexpected decoded text, or NULL when decoding must fail
Returns
non-zero when the outcome is the expected one
Examples
ex_http_form.c.

Definition at line 79 of file ex_http_form.c.

References N_STR::data, free_nstr, n_http_percent_decode(), and N_STR::written.

Referenced by test_decode().

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

◆ expect_true()

void expect_true ( const char * what,
int ok )
static

count a failed check

Parameters
whatthe check
okits result

Definition at line 48 of file ex_http_form.c.

References failures, LOG_ERR, LOG_INFO, and n_log.

◆ main()

int main ( int argc,
char ** argv )

run the checks

Parameters
argcargument count
argvarguments
Returns
0 when every check passes

Definition at line 306 of file ex_http_form.c.

References failures, LOG_ERR, log_level, LOG_NOTICE, n_log, process_args(), set_log_level(), test_decode(), test_form(), and test_multipart().

Here is the call graph for this function:

◆ mp_parse()

N_HTTP_FORM_MULTIPART * mp_parse ( const char * body,
size_t max )
static

parse a NUL-terminated multipart body

Parameters
bodythe body
maxmost parts
Returns
the parse result
Examples
ex_http_form.c.

Definition at line 190 of file ex_http_form.c.

References n_http_form_multipart_parse().

Referenced by test_multipart().

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

◆ part_body_is()

int part_body_is ( const char * buf,
const N_HTTP_FORM_PART * p,
const char * want )
static

body of a part as a string comparison

Parameters
bufthe parsed buffer
pthe part
wantexpected body
Returns
non-zero when equal
Examples
ex_http_form.c.

Definition at line 182 of file ex_http_form.c.

References N_HTTP_FORM_PART::body_len, and N_HTTP_FORM_PART::body_off.

Referenced by test_multipart().

Here is the caller graph for this function:

◆ process_args()

int process_args ( int argc,
char ** argv )
static

read -V

Parameters
argcargument count
argvarguments
Returns
0, or -1 on a bad argument

Definition at line 61 of file ex_http_form.c.

References log_level.

◆ test_decode()

void test_decode ( void )
static

percent-decoding

Examples
ex_http_form.c.

Definition at line 92 of file ex_http_form.c.

References char_to_nstr(), N_STR::data, decodes_to(), expect_true(), free_nstr, N_HTTP_FORM_PLUS_SPACE, N_HTTP_FORM_RAW_BYTES, n_http_percent_decode(), and N_STR::written.

Referenced by main().

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

◆ test_form()

void test_form ( void )
static

query strings and urlencoded bodies

Examples
ex_http_form.c.

Definition at line 122 of file ex_http_form.c.

References expect_true(), N_HTTP_FORM::fields, n_http_form_count(), n_http_form_free(), n_http_form_get(), n_http_form_parse(), N_HTTP_FORM_RAW_BYTES, N_HTTP_FORM_SKIP_INVALID, N_HTTP_FIELD::name, N_HTTP_FORM::nb_fields, N_HTTP_FIELD::value, and N_HTTP_FIELD::value_len.

Referenced by main().

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

◆ test_multipart()

Variable Documentation

◆ failures

int failures = 0
static

failed checks

Definition at line 43 of file ex_http_form.c.

◆ log_level

int log_level = 3
static

log level from -V

Definition at line 41 of file ex_http_form.c.