ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
http_parser.h File Reference

HttpParser.. More...

#include "protocore_config.h"

Go to the source code of this file.

Classes

struct  Header
struct  QueryParam
struct  HttpReq
struct  HttpParserNs
 Dispatch table. Addressed by offset, so the layout is asserted below. More...

Typedefs

typedef struct HttpReq HttpReq
typedef embed_bool(* HttpStreamBeginCb) (HttpReq *req)
typedef void(* HttpStreamDataCb) (HttpReq *req, const uint8_t *data, size_t len)
typedef void(* HttpStreamAbortCb) (HttpReq *req)

Functions

 EMBED_ENUM_BYTE (ParseState, PARSE_METHOD, PARSE_PATH, PARSE_QUERY, PARSE_VERSION, PARSE_HEADER_KEY, PARSE_HEADER_VAL, PARSE_EXPECT_LF, PARSE_EXPECT_BODY_LF, PARSE_BODY, PARSE_COMPLETE, PARSE_ERROR, PARSE_ENTITY_TOO_LARGE, PARSE_URI_TOO_LONG)
 EMBED_ENUM_BYTE (HttpVersion, HTTP_UNKNOWN=0, HTTP_10, HTTP_11)
 PROTOCORE_NS_LAYOUT (HttpParserNs, set_stream_hooks, reset, feed, get_header, get_cookie, forwarded_client, get_query, get_form, get_param)
void protocore_http_parser_set_stream_hooks (uint8_t *work, HttpStreamBeginCb begin, HttpStreamDataCb data, HttpStreamAbortCb abort)
 Set_stream_hooks.
void protocore_http_parser_reset (uint8_t *work, HttpReq *req)
 Reset.
void protocore_http_parser_feed (uint8_t *work, HttpReq *req, uint8_t byte)
 Feed.
const char * protocore_http_parser_get_header (const uint8_t *work, const HttpReq *req, const char *key)
 Get_header.
embed_bool protocore_http_parser_get_cookie (const uint8_t *work, const HttpReq *req, const char *name, char *out, size_t out_size)
 Get_cookie.
embed_bool protocore_http_parser_forwarded_client (const uint8_t *work, const HttpReq *req, char *ip_out, size_t ip_cap, embed_bool *is_https)
 Forwarded_client.
const char * protocore_http_parser_get_query (const uint8_t *work, const HttpReq *req, const char *key)
 Get_query.
embed_bool protocore_http_parser_get_form (const uint8_t *work, const HttpReq *req, const char *key, char *out, size_t out_size)
 Get_form.
const char * protocore_http_parser_get_param (const uint8_t *work, const HttpReq *req, const char *key)
 Get_param.
uint8_t * protocore_http_parser_span (void)
 The PROTOCORE_HTTP_PARSER_BORROW bytes this module's state lives in.

Variables

HttpReq http_pool [CONN_POOL_SLOTS]
 The per-slot request table every HTTP layer parses into and reads back out of.
PROTOCORE_NS HttpParserNs HttpParser PROTOCORE_UNUSED
 Module namespace.

Detailed Description

HttpParser..

work is PROTOCORE_HTTP_PARSER_BORROW bytes the CALLER took, at an address it knows. It is not held past the call, so nothing here aliases it. How those bytes are carved is this module's and is never named here.

Definition in file http_parser.h.

Typedef Documentation

◆ HttpReq

typedef struct HttpReq HttpReq

◆ HttpStreamBeginCb

typedef embed_bool(* HttpStreamBeginCb)(HttpReq *req)

Definition at line 82 of file http_parser.h.

◆ HttpStreamDataCb

typedef void(* HttpStreamDataCb)(HttpReq *req, const uint8_t *data, size_t len)

Definition at line 84 of file http_parser.h.

◆ HttpStreamAbortCb

typedef void(* HttpStreamAbortCb) (HttpReq *req)

Definition at line 86 of file http_parser.h.

Function Documentation

◆ EMBED_ENUM_BYTE() [1/2]

EMBED_ENUM_BYTE ( ParseState ,
PARSE_METHOD ,
PARSE_PATH ,
PARSE_QUERY ,
PARSE_VERSION ,
PARSE_HEADER_KEY ,
PARSE_HEADER_VAL ,
PARSE_EXPECT_LF ,
PARSE_EXPECT_BODY_LF ,
PARSE_BODY ,
PARSE_COMPLETE ,
PARSE_ERROR ,
PARSE_ENTITY_TOO_LARGE ,
PARSE_URI_TOO_LONG  )

◆ EMBED_ENUM_BYTE() [2/2]

EMBED_ENUM_BYTE ( HttpVersion ,
HTTP_UNKNOWN = 0,
HTTP_10 ,
HTTP_11  )

◆ PROTOCORE_NS_LAYOUT()

PROTOCORE_NS_LAYOUT ( HttpParserNs ,
set_stream_hooks ,
reset ,
feed ,
get_header ,
get_cookie ,
forwarded_client ,
get_query ,
get_form ,
get_param  )

◆ protocore_http_parser_set_stream_hooks()

void protocore_http_parser_set_stream_hooks ( uint8_t * work,
HttpStreamBeginCb begin,
HttpStreamDataCb data,
HttpStreamAbortCb abort )

Set_stream_hooks.

Parameters
workPROTOCORE_HTTP_PARSER_BORROW bytes the caller took. Not held past the call.
beginBegin
dataData
abortAbort

◆ protocore_http_parser_reset()

void protocore_http_parser_reset ( uint8_t * work,
HttpReq * req )

Reset.

Parameters
workPROTOCORE_HTTP_PARSER_BORROW bytes the caller took. Not held past the call.
reqReq

◆ protocore_http_parser_feed()

void protocore_http_parser_feed ( uint8_t * work,
HttpReq * req,
uint8_t byte )

Feed.

Parameters
workPROTOCORE_HTTP_PARSER_BORROW bytes the caller took. Not held past the call.
reqReq
byteByte

◆ protocore_http_parser_get_header()

const char * protocore_http_parser_get_header ( const uint8_t * work,
const HttpReq * req,
const char * key )

Get_header.

Parameters
workPROTOCORE_HTTP_PARSER_BORROW bytes the caller took. Not held past the call.
reqReq
keyKey
Returns
The const char *.

◆ protocore_http_parser_get_cookie()

embed_bool protocore_http_parser_get_cookie ( const uint8_t * work,
const HttpReq * req,
const char * name,
char * out,
size_t out_size )

Get_cookie.

Parameters
workPROTOCORE_HTTP_PARSER_BORROW bytes the caller took. Not held past the call.
reqReq
nameName
outOut
out_sizeOut size
Returns
EMBED_TRUE on success.

◆ protocore_http_parser_forwarded_client()

embed_bool protocore_http_parser_forwarded_client ( const uint8_t * work,
const HttpReq * req,
char * ip_out,
size_t ip_cap,
embed_bool * is_https )

Forwarded_client.

Parameters
workPROTOCORE_HTTP_PARSER_BORROW bytes the caller took. Not held past the call.
reqReq
ip_outIp out
ip_capIp cap
is_httpsIs https
Returns
EMBED_TRUE on success.

◆ protocore_http_parser_get_query()

const char * protocore_http_parser_get_query ( const uint8_t * work,
const HttpReq * req,
const char * key )

Get_query.

Parameters
workPROTOCORE_HTTP_PARSER_BORROW bytes the caller took. Not held past the call.
reqReq
keyKey
Returns
The const char *.

◆ protocore_http_parser_get_form()

embed_bool protocore_http_parser_get_form ( const uint8_t * work,
const HttpReq * req,
const char * key,
char * out,
size_t out_size )

Get_form.

Parameters
workPROTOCORE_HTTP_PARSER_BORROW bytes the caller took. Not held past the call.
reqReq
keyKey
outOut
out_sizeOut size
Returns
EMBED_TRUE on success.

◆ protocore_http_parser_get_param()

const char * protocore_http_parser_get_param ( const uint8_t * work,
const HttpReq * req,
const char * key )

Get_param.

Parameters
workPROTOCORE_HTTP_PARSER_BORROW bytes the caller took. Not held past the call.
reqReq
keyKey
Returns
The const char *.

◆ protocore_http_parser_span()

uint8_t * protocore_http_parser_span ( void )

The PROTOCORE_HTTP_PARSER_BORROW bytes this module's state lives in.

Stated beside the namespace rather than on it: an entry takes a borrow, and this is where that borrow comes from. Taken once from the end of the pool, which no mark and no release walks, so the state lasts the life of the program.

Returns
the span.

Variable Documentation

◆ http_pool

HttpReq http_pool[CONN_POOL_SLOTS]
extern

The per-slot request table every HTTP layer parses into and reads back out of.

Not an entry: it is the shared cross-TU substrate a caller indexes by slot, not something the namespace hands out, so it is reached by name.

◆ PROTOCORE_UNUSED

PROTOCORE_NS HttpParserNs HttpParser PROTOCORE_UNUSED
Initial value:
embed_bool protocore_http_parser_get_form(const uint8_t *work, const HttpReq *req, const char *key, char *out, size_t out_size)
Get_form.
void protocore_http_parser_reset(uint8_t *work, HttpReq *req)
Reset.
const char * protocore_http_parser_get_param(const uint8_t *work, const HttpReq *req, const char *key)
Get_param.
const char * protocore_http_parser_get_query(const uint8_t *work, const HttpReq *req, const char *key)
Get_query.
embed_bool protocore_http_parser_forwarded_client(const uint8_t *work, const HttpReq *req, char *ip_out, size_t ip_cap, embed_bool *is_https)
Forwarded_client.
void protocore_http_parser_set_stream_hooks(uint8_t *work, HttpStreamBeginCb begin, HttpStreamDataCb data, HttpStreamAbortCb abort)
Set_stream_hooks.
void protocore_http_parser_feed(uint8_t *work, HttpReq *req, uint8_t byte)
Feed.
embed_bool protocore_http_parser_get_cookie(const uint8_t *work, const HttpReq *req, const char *name, char *out, size_t out_size)
Get_cookie.
const char * protocore_http_parser_get_header(const uint8_t *work, const HttpReq *req, const char *key)
Get_header.

Module namespace.

Definition at line 206 of file http_parser.h.