Apply PIE to nghttpx
[platform/upstream/nghttp2.git] / doc / nghttp2_hd_inflate_hd2.rst
1
2 nghttp2_hd_inflate_hd2
3 ======================
4
5 Synopsis
6 --------
7
8 *#include <nghttp2/nghttp2.h>*
9
10 .. function:: ssize_t nghttp2_hd_inflate_hd2(nghttp2_hd_inflater *inflater, nghttp2_nv *nv_out, int *inflate_flags, const uint8_t *in, size_t inlen, int in_final)
11
12     
13     Inflates name/value block stored in *in* with length *inlen*.  This
14     function performs decompression.  For each successful emission of
15     header name/value pair, :macro:`NGHTTP2_HD_INFLATE_EMIT` is set in
16     *\*inflate_flags* and name/value pair is assigned to the *nv_out*
17     and the function returns.  The caller must not free the members of
18     *nv_out*.
19     
20     The *nv_out* may include pointers to the memory region in the *in*.
21     The caller must retain the *in* while the *nv_out* is used.
22     
23     The application should call this function repeatedly until the
24     ``(*inflate_flags) & NGHTTP2_HD_INFLATE_FINAL`` is nonzero and
25     return value is non-negative.  If that happens, all given input
26     data (*inlen* bytes) are processed successfully.  Then the
27     application must call `nghttp2_hd_inflate_end_headers()` to prepare
28     for the next header block input.
29     
30     In other words, if *in_final* is nonzero, and this function returns
31     *inlen*, you can assert that :macro:`NGHTTP2_HD_INFLATE_FINAL` is
32     set in *\*inflate_flags*.
33     
34     The caller can feed complete compressed header block.  It also can
35     feed it in several chunks.  The caller must set *in_final* to
36     nonzero if the given input is the last block of the compressed
37     header.
38     
39     This function returns the number of bytes processed if it succeeds,
40     or one of the following negative error codes:
41     
42     :macro:`NGHTTP2_ERR_NOMEM`
43         Out of memory.
44     :macro:`NGHTTP2_ERR_HEADER_COMP`
45         Inflation process has failed.
46     :macro:`NGHTTP2_ERR_BUFFER_ERROR`
47         The header field name or value is too large.
48     
49     Example follows::
50     
51         int inflate_header_block(nghttp2_hd_inflater *hd_inflater,
52                                  uint8_t *in, size_t inlen, int final)
53         {
54             ssize_t rv;
55     
56             for(;;) {
57                 nghttp2_nv nv;
58                 int inflate_flags = 0;
59     
60                 rv = nghttp2_hd_inflate_hd2(hd_inflater, &nv, &inflate_flags,
61                                             in, inlen, final);
62     
63                 if(rv < 0) {
64                     fprintf(stderr, "inflate failed with error code %zd", rv);
65                     return -1;
66                 }
67     
68                 in += rv;
69                 inlen -= rv;
70     
71                 if(inflate_flags & NGHTTP2_HD_INFLATE_EMIT) {
72                     fwrite(nv.name, nv.namelen, 1, stderr);
73                     fprintf(stderr, ": ");
74                     fwrite(nv.value, nv.valuelen, 1, stderr);
75                     fprintf(stderr, "\n");
76                 }
77                 if(inflate_flags & NGHTTP2_HD_INFLATE_FINAL) {
78                     nghttp2_hd_inflate_end_headers(hd_inflater);
79                     break;
80                 }
81                 if((inflate_flags & NGHTTP2_HD_INFLATE_EMIT) == 0 &&
82                    inlen == 0) {
83                    break;
84                 }
85             }
86     
87             return 0;
88         }
89