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

HTTP/1.1 request-head parser (see n_http_req.h). More...

#include "nilorea/n_http_req.h"
#include <string.h>
Include dependency graph for n_http_req.c:

Go to the source code of this file.

Functions

static int lc (int c)
n_http_req_status n_http_request_parse (const char *buf, size_t len, n_http_request *out)
 parse an HTTP/1.1 request head from [buf, buf+len)
static int name_eq (const char *s, size_t n, const char *lit)
static int name_token_ok (const char *s, size_t n)
static int parse_body_len (const char *s, size_t n, long long *out)
static int target_ok (unsigned char c)

Detailed Description

HTTP/1.1 request-head parser (see n_http_req.h).

A small, strict scanner, bounded and over-read safe on every path.

Author
Castagnier Mickael
Version
1.0

Definition in file n_http_req.c.

Function Documentation

◆ lc()

int lc ( int c)
static

Definition at line 31 of file n_http_req.c.

Referenced by name_eq().

Here is the caller graph for this function:

◆ n_http_request_parse()

n_http_req_status n_http_request_parse ( const char * buf,
size_t len,
n_http_request * out )

parse an HTTP/1.1 request head from [buf, buf+len)

Returns N_HTTP_REQ_OK only when a complete head (through CRLFCRLF) is present and every rule holds: the method is GET or POST; the target is origin-form ('/'-prefixed, no spaces or control bytes, no fragment, within N_HTTP_REQ_PATH_MAX); the version is HTTP/1.0 or 1.1; at most N_HTTP_REQ_HEADERS_MAX headers; no Transfer-Encoding; at most one Content-Length, a valid non-negative integer within N_HTTP_REQ_BODY_MAX. On OK, out is filled and out->head_len marks the body start.

Returns N_HTTP_REQ_INCOMPLETE when no CRLFCRLF has arrived yet and the buffered bytes are still under N_HTTP_REQ_HEAD_MAX (read more), and N_HTTP_REQ_ERROR for anything malformed, unsupported, or over the head cap. Bounded and over-read safe on every path.

Parameters
bufthe received bytes (may be NULL)
lennumber of bytes in buf
outthe request head to fill (zeroed first)
Returns
one of n_http_req_status
Examples
ex_http_req.c.

Definition at line 83 of file n_http_req.c.

References n_http_request::authorization, n_http_request::content_length, n_http_request::head_len, le(), n_http_request::method, N_HTTP_REQ_AUTH_MAX, N_HTTP_REQ_ERROR, N_HTTP_REQ_GET, N_HTTP_REQ_HEAD_MAX, N_HTTP_REQ_HEADERS_MAX, N_HTTP_REQ_INCOMPLETE, N_HTTP_REQ_OK, N_HTTP_REQ_PATH_MAX, N_HTTP_REQ_POST, name_eq(), name_token_ok(), parse_body_len(), n_http_request::path, and target_ok().

Referenced by main(), and parse().

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

◆ name_eq()

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

Definition at line 37 of file n_http_req.c.

References lc().

Referenced by n_http_request_parse().

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

◆ name_token_ok()

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

Definition at line 48 of file n_http_req.c.

Referenced by n_http_request_parse().

Here is the caller graph for this function:

◆ parse_body_len()

int parse_body_len ( const char * s,
size_t n,
long long * out )
static

Definition at line 61 of file n_http_req.c.

References N_HTTP_REQ_BODY_MAX.

Referenced by n_http_request_parse().

Here is the caller graph for this function:

◆ target_ok()

int target_ok ( unsigned char c)
static

Definition at line 79 of file n_http_req.c.

Referenced by n_http_request_parse().

Here is the caller graph for this function: