[][src]Function libnghttp2_sys::nghttp2_hd_inflate_hd

pub unsafe extern "C" fn nghttp2_hd_inflate_hd(
    inflater: *mut nghttp2_hd_inflater,
    nv_out: *mut nghttp2_nv,
    inflate_flags: *mut c_int,
    in_: *mut u8,
    inlen: usize,
    in_final: c_int
) -> isize

@function

.. warning::

Deprecated. Use nghttp2_hd_inflate_hd2() instead.

Inflates name/value block stored in |in| with length |inlen|. This function performs decompression. For each successful emission of header name/value pair, :enum:NGHTTP2_HD_INFLATE_EMIT is set in |*inflate_flags| and name/value pair is assigned to the |nv_out| and the function returns. The caller must not free the members of |nv_out|.

The |nv_out| may include pointers to the memory region in the |in|. The caller must retain the |in| while the |nv_out| is used.

The application should call this function repeatedly until the (*inflate_flags) & NGHTTP2_HD_INFLATE_FINAL is nonzero and return value is non-negative. This means the all input values are processed successfully. Then the application must call nghttp2_hd_inflate_end_headers() to prepare for the next header block input.

The caller can feed complete compressed header block. It also can feed it in several chunks. The caller must set |in_final| to nonzero if the given input is the last block of the compressed header.

This function returns the number of bytes processed if it succeeds, or one of the following negative error codes:

:enum:NGHTTP2_ERR_NOMEM Out of memory. :enum:NGHTTP2_ERR_HEADER_COMP Inflation process has failed. :enum:NGHTTP2_ERR_BUFFER_ERROR The header field name or value is too large.

Example follows::

int inflate_header_block(nghttp2_hd_inflater *hd_inflater,
                         uint8_t *in, size_t inlen, int final)
{
    ssize_t rv;

    for(;;) {
        nghttp2_nv nv;
        int inflate_flags = 0;

        rv = nghttp2_hd_inflate_hd(hd_inflater, &nv, &inflate_flags,
                                   in, inlen, final);

        if(rv < 0) {
            fprintf(stderr, "inflate failed with error code %zd", rv);
            return -1;
        }

        in += rv;
        inlen -= rv;

        if(inflate_flags & NGHTTP2_HD_INFLATE_EMIT) {
            fwrite(nv.name, nv.namelen, 1, stderr);
            fprintf(stderr, ": ");
            fwrite(nv.value, nv.valuelen, 1, stderr);
            fprintf(stderr, "\n");
        }
        if(inflate_flags & NGHTTP2_HD_INFLATE_FINAL) {
            nghttp2_hd_inflate_end_headers(hd_inflater);
            break;
        }
        if((inflate_flags & NGHTTP2_HD_INFLATE_EMIT) == 0 &&
           inlen == 0) {
           break;
        }
    }

    return 0;
}