Apache HTTPD
h2_util.h
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef __mod_h2__h2_util__
18#define __mod_h2__h2_util__
19
20#include <nghttp2/nghttp2.h>
21#include <http_protocol.h>
22
23#include "h2.h"
24#include "h2_headers.h"
25
26/*******************************************************************************
27 * some debugging/format helpers
28 ******************************************************************************/
29struct h2_request;
30struct nghttp2_frame;
31
32size_t h2_util_hex_dump(char *buffer, size_t maxlen,
33 const char *data, size_t datalen);
34
35void h2_util_camel_case_header(char *s, size_t len);
36
37int h2_util_frame_print(const nghttp2_frame *frame, char *buffer, size_t maxlen);
38
39/*******************************************************************************
40 * ihash - hash for structs with int identifier
41 ******************************************************************************/
42typedef struct h2_ihash_t h2_ihash_t;
43typedef int h2_ihash_iter_t(void *ctx, void *val);
44
51
52unsigned int h2_ihash_count(h2_ihash_t *ih);
54void *h2_ihash_get(h2_ihash_t *ih, int id);
55
64int h2_ihash_iter(h2_ihash_t *ih, h2_ihash_iter_t *fn, void *ctx);
65
66void h2_ihash_add(h2_ihash_t *ih, void *val);
67void h2_ihash_remove(h2_ihash_t *ih, int id);
68void h2_ihash_remove_val(h2_ihash_t *ih, void *val);
70
71size_t h2_ihash_shift(h2_ihash_t *ih, void **buffer, size_t max);
72
73/*******************************************************************************
74 * iqueue - sorted list of int with user defined ordering
75 ******************************************************************************/
76typedef struct h2_iqueue {
77 int *elts;
78 int head;
79 int nelts;
80 int nalloc;
83
95typedef int h2_iq_cmp(int i1, int i2, void *ctx);
96
102h2_iqueue *h2_iq_create(apr_pool_t *pool, int capacity);
103
108int h2_iq_empty(h2_iqueue *q);
109
114int h2_iq_count(h2_iqueue *q);
115
125int h2_iq_add(h2_iqueue *q, int sid, h2_iq_cmp *cmp, void *ctx);
126
134int h2_iq_append(h2_iqueue *q, int sid);
135
142int h2_iq_remove(h2_iqueue *q, int sid);
143
147void h2_iq_clear(h2_iqueue *q);
148
157void h2_iq_sort(h2_iqueue *q, h2_iq_cmp *cmp, void *ctx);
158
166int h2_iq_shift(h2_iqueue *q);
167
176size_t h2_iq_mshift(h2_iqueue *q, int *pint, size_t max);
177
185int h2_iq_contains(h2_iqueue *q, int sid);
186
187/*******************************************************************************
188 * FIFO queue (void* elements)
189 ******************************************************************************/
190
195typedef struct h2_fifo h2_fifo;
196
202
209
211
213
224
227
228typedef enum {
229 H2_FIFO_OP_PULL, /* pull the element from the queue, ie discard it */
230 H2_FIFO_OP_REPUSH, /* pull and immediately re-push it */
232
233typedef h2_fifo_op_t h2_fifo_peek_fn(void *head, void *ctx);
234
244
249
256
257/*******************************************************************************
258 * iFIFO queue (int elements)
259 ******************************************************************************/
260
265typedef struct h2_ififo h2_ififo;
266
272
279
281
283
294
297
299
309
314
321
322/*******************************************************************************
323 * common helpers
324 ******************************************************************************/
325/* h2_log2(n) iff n is a power of 2 */
326unsigned char h2_log2(int n);
327
337
339#define H2_HD_MATCH_LIT(l, name, nlen) \
340 ((nlen == sizeof(l) - 1) && !apr_strnatcasecmp(l, name))
341
342/*******************************************************************************
343 * HTTP/2 header helpers
344 ******************************************************************************/
345int h2_ignore_req_trailer(const char *name, size_t len);
346int h2_ignore_resp_trailer(const char *name, size_t len);
347
359
360/*******************************************************************************
361 * base64 url encoding, different table from normal base64
362 ******************************************************************************/
368 const char *encoded,
370const char *h2_util_base64url_encode(const char *data,
372
373/*******************************************************************************
374 * nghttp2 helpers
375 ******************************************************************************/
376
377int h2_util_ignore_resp_header(const char *name);
378
383
384#if AP_HAS_RESPONSE_BUCKETS
386 ap_bucket_headers *headers);
388 ap_bucket_response *response);
390 const struct h2_request *req);
391#else
393 struct h2_headers *headers);
395 struct h2_headers *headers);
397 const struct h2_request *req);
398#endif
399
405 const char *name, size_t nlen,
406 const char *value, size_t vlen,
407 size_t max_field_len, int *pwas_added);
408
409/*******************************************************************************
410 * apr brigade helpers
411 ******************************************************************************/
412
420
428
430 const char *data, apr_off_t len);
431
437 apr_bucket *b, const char *sep);
438
445 const char *tag, const char *sep,
456#define h2_util_bb_log(c, sid, level, tag, bb) \
457if (APLOG_C_IS_LEVEL(c, level)) { \
458 do { \
459 char buffer[4 * 1024]; \
460 const char *line = "(null)"; \
461 apr_size_t len, bmax = sizeof(buffer)/sizeof(buffer[0]); \
462 len = h2_util_bb_print(buffer, bmax, (tag), "", (bb)); \
463 ap_log_cerror(APLOG_MARK, level, 0, (c), "bb_dump(%ld): %s", \
464 ((c)->master? (c)->master->id : (c)->id), (len? buffer : line)); \
465 } while(0); \
466}
467
468
480 apr_bucket_brigade *from,
482 int *peos,
484
493
498
503
504
505#if AP_HAS_RESPONSE_BUCKETS
511
517#endif /* AP_HAS_RESPONSE_BUCKETS */
518
519#endif /* defined(__mod_h2__h2_util__) */
int n
Definition ap_regex.h:278
const char apr_size_t len
Definition ap_regex.h:187
apr_brigade_flush void * ctx
int apr_off_t * length
const char * src
Definition apr_encode.h:167
apr_size_t size
apr_uint32_t apr_uint32_t cmp
Definition apr_atomic.h:106
apr_uint32_t val
Definition apr_atomic.h:66
const char int apr_pool_t * pool
Definition apr_cstr.h:84
const char * value
Definition apr_env.h:51
int apr_status_t
Definition apr_errno.h:44
void * data
char * buffer
apr_interval_time_t t
apr_pool_t * b
Definition apr_pools.h:529
int to
const char * sep
const char * s
Definition apr_strings.h:95
apr_size_t apr_size_t max
Definition apr_time.h:220
void h2_iq_sort(h2_iqueue *q, h2_iq_cmp *cmp, void *ctx)
Definition h2_util.c:405
void h2_ihash_clear(h2_ihash_t *ih)
Definition h2_util.c:285
size_t h2_util_hex_dump(char *buffer, size_t maxlen, const char *data, size_t datalen)
Definition h2_util.c:64
void h2_ihash_add(h2_ihash_t *ih, void *val)
Definition h2_util.c:268
apr_status_t h2_res_create_ngtrailer(h2_ngheader **ph, apr_pool_t *p, struct h2_headers *headers)
Definition h2_util.c:1544
h2_fifo_op_t
Definition h2_util.h:228
@ H2_FIFO_OP_REPUSH
Definition h2_util.h:230
@ H2_FIFO_OP_PULL
Definition h2_util.h:229
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)
Definition h2_util.c:1320
apr_status_t h2_util_wait_on_pipe(apr_file_t *pipe)
Definition h2_util.c:1907
apr_status_t h2_fifo_peek(h2_fifo *fifo, h2_fifo_peek_fn *fn, void *ctx)
Definition h2_util.c:770
int h2_iq_add(h2_iqueue *q, int sid, h2_iq_cmp *cmp, void *ctx)
Definition h2_util.c:354
apr_status_t h2_ififo_try_peek(h2_ififo *fifo, h2_ififo_peek_fn *fn, void *ctx)
Definition h2_util.c:1092
int h2_iq_cmp(int i1, int i2, void *ctx)
Definition h2_util.h:95
h2_iqueue * h2_iq_create(apr_pool_t *pool, int capacity)
Definition h2_util.c:334
apr_status_t h2_brigade_copy_length(apr_bucket_brigade *dest, apr_bucket_brigade *src, apr_off_t length)
Definition h2_util.c:1228
int h2_ignore_req_trailer(const char *name, size_t len)
Definition h2_util.c:1675
apr_status_t h2_ififo_term(h2_ififo *fifo)
Definition h2_util.c:942
void h2_util_drain_pipe(apr_file_t *pipe)
Definition h2_util.c:1882
apr_status_t h2_res_create_ngheader(h2_ngheader **ph, apr_pool_t *p, struct h2_headers *headers)
Definition h2_util.c:1551
int h2_util_ignore_resp_header(const char *name)
Definition h2_util.c:1660
void h2_ihash_remove_val(h2_ihash_t *ih, void *val)
Definition h2_util.c:278
size_t h2_iq_mshift(h2_iqueue *q, int *pint, size_t max)
Definition h2_util.c:448
apr_status_t h2_fifo_try_pull(h2_fifo *fifo, void **pelem)
Definition h2_util.c:741
void h2_ihash_remove(h2_ihash_t *ih, int id)
Definition h2_util.c:273
int h2_iq_contains(h2_iqueue *q, int sid)
Definition h2_util.c:511
apr_status_t h2_ififo_try_push(h2_ififo *fifo, int id)
Definition h2_util.c:1022
h2_ihash_t * h2_ihash_create(apr_pool_t *pool, size_t offset_of_int)
Definition h2_util.c:225
apr_status_t h2_fifo_create(h2_fifo **pfifo, apr_pool_t *pool, int capacity)
Definition h2_util.c:602
int h2_iq_empty(h2_iqueue *q)
Definition h2_util.c:343
apr_status_t h2_ififo_peek(h2_ififo *fifo, h2_ififo_peek_fn *fn, void *ctx)
Definition h2_util.c:1087
int h2_iq_append(h2_iqueue *q, int sid)
Definition h2_util.c:375
apr_size_t h2_util_bucket_print(char *buffer, apr_size_t bmax, apr_bucket *b, const char *sep)
Definition h2_util.c:1267
apr_status_t h2_fifo_set_create(h2_fifo **pfifo, apr_pool_t *pool, int capacity)
Definition h2_util.c:607
apr_status_t h2_brigade_concat_length(apr_bucket_brigade *dest, apr_bucket_brigade *src, apr_off_t length)
Definition h2_util.c:1193
int h2_bucket_gate(apr_bucket *b)
Definition h2_util.h:469
void h2_util_camel_case_header(char *s, size_t len)
Definition h2_util.c:80
void * h2_ihash_get(h2_ihash_t *ih, int id)
Definition h2_util.c:243
apr_status_t h2_fifo_try_peek(h2_fifo *fifo, h2_fifo_peek_fn *fn, void *ctx)
Definition h2_util.c:775
apr_status_t h2_ififo_remove(h2_ififo *fifo, int id)
Definition h2_util.c:1125
apr_status_t h2_ififo_create(h2_ififo **pfifo, apr_pool_t *pool, int capacity)
Definition h2_util.c:932
apr_status_t h2_util_pass_cb(void *ctx, const char *data, apr_off_t len)
Definition h2_util.h:429
int h2_fifo_count(h2_fifo *fifo)
Definition h2_util.c:624
apr_status_t h2_fifo_term(h2_fifo *fifo)
Definition h2_util.c:612
int h2_util_frame_print(const nghttp2_frame *frame, char *buffer, size_t maxlen)
Definition h2_util.c:1769
int h2_ignore_resp_trailer(const char *name, size_t len)
Definition h2_util.c:1685
int h2_ihash_iter_t(void *ctx, void *val)
Definition h2_util.h:43
apr_status_t h2_req_add_header(apr_table_t *headers, apr_pool_t *pool, const char *name, size_t nlen, const char *value, size_t vlen, size_t max_field_len, int *pwas_added)
Definition h2_util.c:1751
int h2_ihash_iter(h2_ihash_t *ih, h2_ihash_iter_t *fn, void *ctx)
Definition h2_util.c:260
apr_status_t h2_fifo_pull(h2_fifo *fifo, void **pelem)
Definition h2_util.c:736
int h2_iq_remove(h2_iqueue *q, int sid)
Definition h2_util.c:380
size_t h2_ihash_shift(h2_ihash_t *ih, void **buffer, size_t max)
Definition h2_util.c:307
unsigned int h2_ihash_count(h2_ihash_t *ih)
Definition h2_util.c:233
apr_status_t h2_req_create_ngheader(h2_ngheader **ph, apr_pool_t *p, const struct h2_request *req)
Definition h2_util.c:1566
int h2_ififo_count(h2_ififo *fifo)
Definition h2_util.c:954
int h2_push_policy_determine(apr_table_t *headers, apr_pool_t *p, int push_enabled)
Definition h2_util.c:1852
apr_status_t h2_fifo_push(h2_fifo *fifo, void *elem)
Definition h2_util.c:694
apr_status_t h2_fifo_remove(h2_fifo *fifo, void *elem)
Definition h2_util.c:780
apr_size_t h2_util_base64url_decode(const char **decoded, const char *encoded, apr_pool_t *pool)
Definition h2_util.c:133
unsigned char h2_log2(int n)
Definition h2_util.c:35
apr_off_t h2_brigade_mem_size(apr_bucket_brigade *bb)
Definition h2_util.c:1368
apr_size_t h2_util_table_bytes(apr_table_t *t, apr_size_t pair_extra)
Definition h2_util.c:1158
const char * h2_util_base64url_encode(const char *data, apr_size_t len, apr_pool_t *pool)
Definition h2_util.c:182
apr_status_t h2_ififo_set_create(h2_ififo **pfifo, apr_pool_t *pool, int capacity)
Definition h2_util.c:937
apr_status_t h2_ififo_push(h2_ififo *fifo, int id)
Definition h2_util.c:1017
void h2_iq_clear(h2_iqueue *q)
Definition h2_util.c:400
int h2_ihash_empty(h2_ihash_t *ih)
Definition h2_util.c:238
apr_status_t h2_ififo_try_pull(h2_ififo *fifo, int *pi)
Definition h2_util.c:1062
h2_fifo_op_t h2_ififo_peek_fn(int head, void *ctx)
Definition h2_util.h:298
int h2_iq_shift(h2_iqueue *q)
Definition h2_util.c:433
int h2_iq_count(h2_iqueue *q)
Definition h2_util.c:348
apr_status_t h2_fifo_try_push(h2_fifo *fifo, void *elem)
Definition h2_util.c:699
apr_status_t h2_ififo_pull(h2_ififo *fifo, int *pi)
Definition h2_util.c:1057
apr_size_t h2_util_bb_print(char *buffer, apr_size_t bmax, const char *tag, const char *sep, apr_bucket_brigade *bb)
Definition h2_util.c:1290
h2_fifo_op_t h2_fifo_peek_fn(void *head, void *ctx)
Definition h2_util.h:233
HTTP protocol handling.
apr_pool_t * p
Definition md_event.c:32
char * name
int capacity
Definition h2_util.c:528
int head
Definition h2_util.c:856
int capacity
Definition h2_util.c:854
int nelts
Definition h2_util.h:79
int head
Definition h2_util.h:78
apr_pool_t * pool
Definition h2_util.h:81
int * elts
Definition h2_util.h:77
int nalloc
Definition h2_util.h:80
nghttp2_nv * nv
Definition h2_util.h:380
apr_size_t nvlen
Definition h2_util.h:381