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 enum PROTO_ENUM_PACKED ParseState
 
typedef enum PROTO_ENUM_PACKED HttpVersion
 
typedef struct HttpReq HttpReq
 
typedef proto_bool(* HttpStreamBeginCb) (HttpReq *req)
 
typedef void(* HttpStreamDataCb) (HttpReq *req, const uint8_t *data, size_t len)
 
typedef void(* HttpStreamAbortCb) (HttpReq *req)
 

Enumerations

enum  PROTO_ENUM_PACKED {
  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 , HTTP_UNKNOWN = 0 , HTTP_10 , HTTP_11
}
 
enum  PROTO_ENUM_PACKED {
  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 , HTTP_UNKNOWN = 0 , HTTP_10 , HTTP_11
}
 

Functions

 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 (uint8_t *work, const HttpReq *req, const char *key)
 Get_header.
 
proto_bool protocore_http_parser_get_cookie (uint8_t *work, const HttpReq *req, const char *name, char *out, size_t out_size)
 Get_cookie.
 
proto_bool protocore_http_parser_forwarded_client (uint8_t *work, const HttpReq *req, char *ip_out, size_t ip_cap, proto_bool *is_https)
 Forwarded_client.
 
const char * protocore_http_parser_get_query (uint8_t *work, const HttpReq *req, const char *key)
 Get_query.
 
proto_bool protocore_http_parser_get_form (uint8_t *work, const HttpReq *req, const char *key, char *out, size_t out_size)
 Get_form.
 
const char * protocore_http_parser_get_param (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

◆ ParseState

◆ HttpVersion

◆ HttpReq

typedef struct HttpReq HttpReq

◆ HttpStreamBeginCb

typedef proto_bool(* HttpStreamBeginCb)(HttpReq *req)

Definition at line 100 of file http_parser.h.

◆ HttpStreamDataCb

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

Definition at line 102 of file http_parser.h.

◆ HttpStreamAbortCb

typedef void(* HttpStreamAbortCb) (HttpReq *req)

Definition at line 104 of file http_parser.h.

Enumeration Type Documentation

◆ PROTO_ENUM_PACKED [1/2]

Enumerator
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 
HTTP_UNKNOWN 
HTTP_10 
HTTP_11 

Definition at line 19 of file http_parser.h.

◆ PROTO_ENUM_PACKED [2/2]

Enumerator
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 
HTTP_UNKNOWN 
HTTP_10 
HTTP_11 

Definition at line 36 of file http_parser.h.

Function Documentation

◆ 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 ( 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()

proto_bool protocore_http_parser_get_cookie ( 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
PROTO_TRUE on success.

◆ protocore_http_parser_forwarded_client()

proto_bool protocore_http_parser_forwarded_client ( uint8_t *  work,
const HttpReq *  req,
char *  ip_out,
size_t  ip_cap,
proto_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
PROTO_TRUE on success.

◆ protocore_http_parser_get_query()

const char * protocore_http_parser_get_query ( 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()

proto_bool protocore_http_parser_get_form ( 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
PROTO_TRUE on success.

◆ protocore_http_parser_get_param()

const char * protocore_http_parser_get_param ( 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:
const char * protocore_http_parser_get_param(uint8_t *work, const HttpReq *req, const char *key)
Get_param.
proto_bool protocore_http_parser_get_cookie(uint8_t *work, const HttpReq *req, const char *name, char *out, size_t out_size)
Get_cookie.
void protocore_http_parser_reset(uint8_t *work, HttpReq *req)
Reset.
const char * protocore_http_parser_get_query(uint8_t *work, const HttpReq *req, const char *key)
Get_query.
proto_bool protocore_http_parser_get_form(uint8_t *work, const HttpReq *req, const char *key, char *out, size_t out_size)
Get_form.
const char * protocore_http_parser_get_header(uint8_t *work, const HttpReq *req, const char *key)
Get_header.
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.
proto_bool protocore_http_parser_forwarded_client(uint8_t *work, const HttpReq *req, char *ip_out, size_t ip_cap, proto_bool *is_https)
Forwarded_client.

Module namespace.

Definition at line 224 of file http_parser.h.