Apache2
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
h2_util.h File Reference
#include <nghttp2/nghttp2.h>
Include dependency graph for h2_util.h:

Go to the source code of this file.

Data Structures

struct  h2_iqueue
 
struct  h2_ngheader
 

Macros

#define H2_HD_MATCH_LIT(l, name, nlen)   ((nlen == sizeof(l) - 1) && !apr_strnatcasecmp(l, name))
 
#define H2_HD_MATCH_LIT_CS(l, name)   ((strlen(name) == sizeof(l) - 1) && !apr_strnatcasecmp(l, name))
 
#define H2_CREATE_NV_LIT_CS(nv, NAME, VALUE)
 
#define H2_CREATE_NV_CS_LIT(nv, NAME, VALUE)
 
#define H2_CREATE_NV_CS_CS(nv, NAME, VALUE)
 
#define h2_util_bb_log(c, sid, level, tag, bb)
 

Typedefs

typedef struct h2_ihash_t h2_ihash_t
 
typedef int h2_ihash_iter_t (void *ctx, void *val)
 
typedef struct h2_iqueue h2_iqueue
 
typedef int h2_iq_cmp (int i1, int i2, void *ctx)
 
typedef struct h2_ngheader h2_ngheader
 
typedef apr_status_t h2_util_pass_cb (void *ctx, const char *data, apr_off_t len)
 
typedef int h2_bucket_gate (apr_bucket *b)
 

Functions

size_t h2_util_hex_dump (char *buffer, size_t maxlen, const char *data, size_t datalen)
 
size_t h2_util_header_print (char *buffer, size_t maxlen, const char *name, size_t namelen, const char *value, size_t valuelen)
 
void h2_util_camel_case_header (char *s, size_t len)
 
int h2_util_frame_print (const nghttp2_frame *frame, char *buffer, size_t maxlen)
 
h2_ihash_th2_ihash_create (apr_pool_t *pool, size_t offset_of_int)
 
size_t h2_ihash_count (h2_ihash_t *ih)
 
int h2_ihash_empty (h2_ihash_t *ih)
 
voidh2_ihash_get (h2_ihash_t *ih, int id)
 
int h2_ihash_iter (h2_ihash_t *ih, h2_ihash_iter_t *fn, void *ctx)
 
void h2_ihash_add (h2_ihash_t *ih, void *val)
 
void h2_ihash_remove (h2_ihash_t *ih, int id)
 
void h2_ihash_remove_val (h2_ihash_t *ih, void *val)
 
void h2_ihash_clear (h2_ihash_t *ih)
 
size_t h2_ihash_shift (h2_ihash_t *ih, void **buffer, size_t max)
 
size_t h2_ihash_ishift (h2_ihash_t *ih, int *buffer, size_t max)
 
h2_iqueueh2_iq_create (apr_pool_t *pool, int capacity)
 
int h2_iq_empty (h2_iqueue *q)
 
int h2_iq_count (h2_iqueue *q)
 
void h2_iq_add (h2_iqueue *q, int sid, h2_iq_cmp *cmp, void *ctx)
 
void h2_iq_append (h2_iqueue *q, int sid)
 
int h2_iq_remove (h2_iqueue *q, int sid)
 
void h2_iq_clear (h2_iqueue *q)
 
void h2_iq_sort (h2_iqueue *q, h2_iq_cmp *cmp, void *ctx)
 
int h2_iq_shift (h2_iqueue *q)
 
size_t h2_iq_mshift (h2_iqueue *q, int *pint, size_t max)
 
int h2_iq_contains (h2_iqueue *q, int sid)
 
unsigned char h2_log2 (int n)
 
apr_size_t h2_util_table_bytes (apr_table_t *t, apr_size_t pair_extra)
 
int h2_util_contains_token (apr_pool_t *pool, const char *s, const char *token)
 
const char * h2_util_first_token_match (apr_pool_t *pool, const char *s, const char *tokens[], apr_size_t len)
 
int h2_req_ignore_header (const char *name, size_t len)
 
int h2_req_ignore_trailer (const char *name, size_t len)
 
int h2_res_ignore_trailer (const char *name, size_t len)
 
int h2_push_policy_determine (apr_table_t *headers, apr_pool_t *p, int push_enabled)
 
apr_size_t h2_util_base64url_decode (const char **decoded, const char *encoded, apr_pool_t *pool)
 
const char * h2_util_base64url_encode (const char *data, apr_size_t len, apr_pool_t *pool)
 
int h2_util_ignore_header (const char *name)
 
h2_ngheaderh2_util_ngheader_make (apr_pool_t *p, apr_table_t *header)
 
h2_ngheaderh2_util_ngheader_make_res (apr_pool_t *p, int http_status, apr_table_t *header)
 
h2_ngheaderh2_util_ngheader_make_req (apr_pool_t *p, const struct h2_request *req)
 
apr_status_t h2_headers_add_h1 (apr_table_t *headers, apr_pool_t *pool, const char *name, size_t nlen, const char *value, size_t vlen)
 
struct h2_requesth2_req_create (int id, apr_pool_t *pool, const char *method, const char *scheme, const char *authority, const char *path, apr_table_t *header, int serialize)
 
apr_status_t h2_brigade_concat_length (apr_bucket_brigade *dest, apr_bucket_brigade *src, apr_off_t length)
 
apr_status_t h2_brigade_copy_length (apr_bucket_brigade *dest, apr_bucket_brigade *src, apr_off_t length)
 
int h2_util_has_eos (apr_bucket_brigade *bb, apr_off_t len)
 
apr_status_t h2_util_bb_avail (apr_bucket_brigade *bb, apr_off_t *plen, int *peos)
 
apr_status_t h2_util_bb_readx (apr_bucket_brigade *bb, h2_util_pass_cb *cb, void *ctx, apr_off_t *plen, int *peos)
 
apr_size_t h2_util_bucket_print (char *buffer, apr_size_t bmax, apr_bucket *b, const char *sep)
 
apr_size_t h2_util_bb_print (char *buffer, apr_size_t bmax, const char *tag, const char *sep, apr_bucket_brigade *bb)
 
apr_status_t h2_append_brigade (apr_bucket_brigade *to, apr_bucket_brigade *from, apr_off_t *plen, int *peos, h2_bucket_gate *should_append)
 
apr_off_t h2_brigade_mem_size (apr_bucket_brigade *bb)
 

Macro Definition Documentation

#define H2_CREATE_NV_CS_CS (   nv,
  NAME,
  VALUE 
)
Value:
nv->name = (uint8_t *)NAME; \
nv->namelen = strlen(NAME); \
nv->value = (uint8_t *)VALUE; \
nv->valuelen = strlen(VALUE)
#define H2_CREATE_NV_CS_LIT (   nv,
  NAME,
  VALUE 
)
Value:
nv->name = (uint8_t *)NAME; \
nv->namelen = strlen(NAME); \
nv->value = (uint8_t *)VALUE; \
nv->valuelen = sizeof(VALUE) - 1
#define H2_CREATE_NV_LIT_CS (   nv,
  NAME,
  VALUE 
)
Value:
nv->name = (uint8_t *)NAME; \
nv->namelen = sizeof(NAME) - 1; \
nv->value = (uint8_t *)VALUE; \
nv->valuelen = strlen(VALUE)
#define H2_HD_MATCH_LIT (   l,
  name,
  nlen 
)    ((nlen == sizeof(l) - 1) && !apr_strnatcasecmp(l, name))

Match a header value against a string constance, case insensitive

#define H2_HD_MATCH_LIT_CS (   l,
  name 
)    ((strlen(name) == sizeof(l) - 1) && !apr_strnatcasecmp(l, name))
#define h2_util_bb_log (   c,
  sid,
  level,
  tag,
  bb 
)
Value:
do { \
char buffer[4 * 1024]; \
const char *line = "(null)"; \
apr_size_t len, bmax = sizeof(buffer)/sizeof(buffer[0]); \
len = h2_util_bb_print(buffer, bmax, (tag), "", (bb)); \
ap_log_cerror(APLOG_MARK, level, 0, (c), "bb_dump(%s): %s", \
(c)->log_id, (len? buffer : line)); \
} while(0)
size_t apr_size_t
Definition: apr.h:375
#define APLOG_MARK
Definition: http_log.h:283
apr_bucket_brigade * bb
Definition: mod_dav.h:556
void ap_log_cerror(const char *file, int line, int module_index, int level, apr_status_t status, const conn_rec *c, const char *fmt,...)
apr_size_t h2_util_bb_print(char *buffer, apr_size_t bmax, const char *tag, const char *sep, apr_bucket_brigade *bb)

Logs the bucket brigade (which bucket types with what length) to the log at the given level.

Parameters
cthe connection to log for
sidthe stream identifier this brigade belongs to
levelthe log level (as in APLOG_*)
taga short message text about the context
bbthe brigade to log

Typedef Documentation

typedef int h2_bucket_gate(apr_bucket *b)
typedef int h2_ihash_iter_t(void *ctx, void *val)
typedef struct h2_ihash_t h2_ihash_t
typedef int h2_iq_cmp(int i1, int i2, void *ctx)

Comparator for two int to determine their order.

Parameters
i1first int to compare
i2second int to compare
ctxprovided user data
Returns
value is the same as for strcmp() and has the effect: == 0: s1 and s2 are treated equal in ordering < 0: s1 should be sorted before s2 > 0: s2 should be sorted before s1
typedef struct h2_iqueue h2_iqueue
typedef struct h2_ngheader h2_ngheader
typedef apr_status_t h2_util_pass_cb(void *ctx, const char *data, apr_off_t len)

Function Documentation

apr_status_t h2_append_brigade ( apr_bucket_brigade to,
apr_bucket_brigade from,
apr_off_t plen,
int peos,
h2_bucket_gate should_append 
)

Transfer buckets from one brigade to another with a limit on the maximum amount of bytes transferred. Does no setaside magic, lifetime of brigades must fit.

Parameters
tobrigade to transfer buckets to
frombrigades to remove buckets from
plenmaximum bytes to transfer, actual bytes transferred
peosif an EOS bucket was transferred
apr_status_t h2_brigade_concat_length ( apr_bucket_brigade dest,
apr_bucket_brigade src,
apr_off_t  length 
)

Concatenate at most length bytes from src to dest brigade, splitting buckets if necessary and reading buckets of indeterminate length.

apr_status_t h2_brigade_copy_length ( apr_bucket_brigade dest,
apr_bucket_brigade src,
apr_off_t  length 
)

Copy at most length bytes from src to dest brigade, splitting buckets if necessary and reading buckets of indeterminate length.

apr_off_t h2_brigade_mem_size ( apr_bucket_brigade bb)

Get an approximnation of the memory footprint of the given brigade. This varies from apr_brigade_length as

  • no buckets are ever read
  • only buckets known to allocate memory (HEAP+POOL) are counted
  • the bucket struct itself is counted
apr_status_t h2_headers_add_h1 ( apr_table_t headers,
apr_pool_t pool,
const char *  name,
size_t  nlen,
const char *  value,
size_t  vlen 
)
void h2_ihash_add ( h2_ihash_t ih,
void val 
)
void h2_ihash_clear ( h2_ihash_t ih)
size_t h2_ihash_count ( h2_ihash_t ih)
h2_ihash_t* h2_ihash_create ( apr_pool_t pool,
size_t  offset_of_int 
)

Create a hash for structures that have an identifying int member.

Parameters
poolthe pool to use
offset_of_intthe offsetof() the int member in the struct
int h2_ihash_empty ( h2_ihash_t ih)
void* h2_ihash_get ( h2_ihash_t ih,
int  id 
)
size_t h2_ihash_ishift ( h2_ihash_t ih,
int buffer,
size_t  max 
)
int h2_ihash_iter ( h2_ihash_t ih,
h2_ihash_iter_t fn,
void ctx 
)

Iterate over the hash members (without defined order) and invoke fn for each member until 0 is returned.

Parameters
ihthe hash to iterate over
fnthe function to invoke on each member
ctxuser supplied data passed into each iteration call
Returns
0 if one iteration returned 0, otherwise != 0
void h2_ihash_remove ( h2_ihash_t ih,
int  id 
)
void h2_ihash_remove_val ( h2_ihash_t ih,
void val 
)
size_t h2_ihash_shift ( h2_ihash_t ih,
void **  buffer,
size_t  max 
)
void h2_iq_add ( h2_iqueue q,
int  sid,
h2_iq_cmp cmp,
void ctx 
)

Add a stream id to the queue.

Parameters
qthe queue to append the id to
sidthe stream id to add
cmpthe comparator for sorting
ctxuser data for comparator
void h2_iq_append ( h2_iqueue q,
int  sid 
)

Append the id to the queue if not already present.

Parameters
qthe queue to append the id to
sidthe id to append
void h2_iq_clear ( h2_iqueue q)

Remove all entries in the queue.

int h2_iq_contains ( h2_iqueue q,
int  sid 
)

Determine if int is in the queue already

q the queue

Parameters
sidthe integer id to check for
Returns
!= 0 iff sid is already in the queue
int h2_iq_count ( h2_iqueue q)

Return the number of int in the queue.

Parameters
qthe queue to get size on
h2_iqueue* h2_iq_create ( apr_pool_t pool,
int  capacity 
)

Allocate a new queue from the pool and initialize.

Parameters
idthe identifier of the queue
poolthe memory pool
int h2_iq_empty ( h2_iqueue q)

Return != 0 iff there are no tasks in the queue.

Parameters
qthe queue to check
size_t h2_iq_mshift ( h2_iqueue q,
int pint,
size_t  max 
)

Get the first max ids from the queue. All these ids will be removed.

Parameters
qthe queue to get the first task from
pintthe int array to receive the values
maxthe maximum number of ids to shift
Returns
the actual number of ids shifted
int h2_iq_remove ( h2_iqueue q,
int  sid 
)

Remove the stream id from the queue. Return != 0 iff task was found in queue.

Parameters
qthe task queue
sidthe stream id to remove
Returns
!= 0 iff task was found in queue
int h2_iq_shift ( h2_iqueue q)

Get the first id from the queue or 0 if the queue is empty. The id is being removed.

Parameters
qthe queue to get the first id from
Returns
the first id of the queue, 0 if empty
void h2_iq_sort ( h2_iqueue q,
h2_iq_cmp cmp,
void ctx 
)

Sort the stream idqueue again. Call if the task ordering has changed.

Parameters
qthe queue to sort
cmpthe comparator for sorting
ctxuser data for the comparator
unsigned char h2_log2 ( int  n)
int h2_push_policy_determine ( apr_table_t headers,
apr_pool_t p,
int  push_enabled 
)

Set the push policy for the given request. Takes request headers into account, see draft https://tools.ietf.org/html/draft-ruellan-http-accept-push-policy-00 for details.

Parameters
headersthe http headers to inspect
pthe pool to use
push_enabledif HTTP/2 server push is generally enabled for this request
Returns
the push policy desired
struct h2_request* h2_req_create ( int  id,
apr_pool_t pool,
const char *  method,
const char *  scheme,
const char *  authority,
const char *  path,
apr_table_t header,
int  serialize 
)
int h2_req_ignore_header ( const char *  name,
size_t  len 
)
int h2_req_ignore_trailer ( const char *  name,
size_t  len 
)
int h2_res_ignore_trailer ( const char *  name,
size_t  len 
)
apr_size_t h2_util_base64url_decode ( const char **  decoded,
const char *  encoded,
apr_pool_t pool 
)

I always wanted to write my own base64url decoder...not. See https://tools.ietf.org/html/rfc4648#section-5 for description.

const char* h2_util_base64url_encode ( const char *  data,
apr_size_t  len,
apr_pool_t pool 
)
apr_status_t h2_util_bb_avail ( apr_bucket_brigade bb,
apr_off_t plen,
int peos 
)

Check how many bytes of the desired amount are available and if the end of stream is reached by that amount.

Parameters
bbthe brigade to check
plenthe desired length and, on return, the available length
onreturn, if eos has been reached
apr_size_t h2_util_bb_print ( char *  buffer,
apr_size_t  bmax,
const char *  tag,
const char *  sep,
apr_bucket_brigade bb 
)

Prints the brigade bucket types and lengths into the given buffer up to bmax.

Returns
number of characters printed
apr_status_t h2_util_bb_readx ( apr_bucket_brigade bb,
h2_util_pass_cb cb,
void ctx,
apr_off_t plen,
int peos 
)

Read at most *plen bytes from the brigade and pass them into the given callback. If cb is NULL, just return the amount of data that could have been read. If an EOS was/would be encountered, set *peos != 0.

Parameters
bbthe brigade to read from
cbthe callback to invoke for the read data
ctxoptional data passed to callback
pleninout, as input gives the maximum number of bytes to read, on return specifies the actual/would be number of bytes
peos!= 0 iff an EOS bucket was/would be encountered.
apr_size_t h2_util_bucket_print ( char *  buffer,
apr_size_t  bmax,
apr_bucket b,
const char *  sep 
)

Print a bucket's meta data (type and length) to the buffer.

Returns
number of characters printed
void h2_util_camel_case_header ( char *  s,
size_t  len 
)
int h2_util_contains_token ( apr_pool_t pool,
const char *  s,
const char *  token 
)

Return != 0 iff the string s contains the token, as specified in HTTP header syntax, rfc7230.

const char* h2_util_first_token_match ( apr_pool_t pool,
const char *  s,
const char *  tokens[],
apr_size_t  len 
)
int h2_util_frame_print ( const nghttp2_frame *  frame,
char *  buffer,
size_t  maxlen 
)
int h2_util_has_eos ( apr_bucket_brigade bb,
apr_off_t  len 
)

Return != 0 iff there is a FLUSH or EOS bucket in the brigade.

Parameters
bbthe brigade to check on
Returns
!= 0 iff brigade holds FLUSH or EOS bucket (or both)
size_t h2_util_header_print ( char *  buffer,
size_t  maxlen,
const char *  name,
size_t  namelen,
const char *  value,
size_t  valuelen 
)
size_t h2_util_hex_dump ( char *  buffer,
size_t  maxlen,
const char *  data,
size_t  datalen 
)
int h2_util_ignore_header ( const char *  name)
h2_ngheader* h2_util_ngheader_make ( apr_pool_t p,
apr_table_t header 
)
h2_ngheader* h2_util_ngheader_make_req ( apr_pool_t p,
const struct h2_request req 
)
h2_ngheader* h2_util_ngheader_make_res ( apr_pool_t p,
int  http_status,
apr_table_t header 
)
apr_size_t h2_util_table_bytes ( apr_table_t t,
apr_size_t  pair_extra 
)

Count the bytes that all key/value pairs in a table have in length (exlucding terminating 0s), plus additional extra per pair.

Parameters
tthe table to inspect
pair_extrathe extra amount to add per pair
Returns
the number of bytes all key/value pairs have