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