Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:02:17

0001 /*
0002  * nghttp2 - HTTP/2 C Library
0003  *
0004  * Copyright (c) 2013, 2014 Tatsuhiro Tsujikawa
0005  *
0006  * Permission is hereby granted, free of charge, to any person obtaining
0007  * a copy of this software and associated documentation files (the
0008  * "Software"), to deal in the Software without restriction, including
0009  * without limitation the rights to use, copy, modify, merge, publish,
0010  * distribute, sublicense, and/or sell copies of the Software, and to
0011  * permit persons to whom the Software is furnished to do so, subject to
0012  * the following conditions:
0013  *
0014  * The above copyright notice and this permission notice shall be
0015  * included in all copies or substantial portions of the Software.
0016  *
0017  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
0018  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
0019  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
0020  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
0021  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
0022  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
0023  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
0024  */
0025 #ifndef NGHTTP2_H
0026 #define NGHTTP2_H
0027 
0028 /* Define WIN32 when build target is Win32 API (borrowed from
0029    libcurl) */
0030 #if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
0031 #  define WIN32
0032 #endif
0033 
0034 /* Compatibility for non-Clang compilers */
0035 #ifndef __has_declspec_attribute
0036 #  define __has_declspec_attribute(x) 0
0037 #endif
0038 
0039 #ifdef __cplusplus
0040 extern "C" {
0041 #endif
0042 
0043 #include <stdlib.h>
0044 #if defined(_MSC_VER) && (_MSC_VER < 1800)
0045 /* MSVC < 2013 does not have inttypes.h because it is not C99
0046    compliant.  See compiler macros and version number in
0047    https://sourceforge.net/p/predef/wiki/Compilers/ */
0048 #  include <stdint.h>
0049 #else /* !defined(_MSC_VER) || (_MSC_VER >= 1800) */
0050 #  include <inttypes.h>
0051 #endif /* !defined(_MSC_VER) || (_MSC_VER >= 1800) */
0052 #include <sys/types.h>
0053 #include <stdarg.h>
0054 #include <stddef.h>
0055 
0056 #include <nghttp2/nghttp2ver.h>
0057 
0058 #ifdef NGHTTP2_STATICLIB
0059 #  define NGHTTP2_EXTERN
0060 #elif defined(WIN32) || (__has_declspec_attribute(dllexport) &&                \
0061                          __has_declspec_attribute(dllimport))
0062 #  ifdef BUILDING_NGHTTP2
0063 #    define NGHTTP2_EXTERN __declspec(dllexport)
0064 #  else /* !BUILDING_NGHTTP2 */
0065 #    define NGHTTP2_EXTERN __declspec(dllimport)
0066 #  endif /* !BUILDING_NGHTTP2 */
0067 #else    /* !defined(WIN32) */
0068 #  ifdef BUILDING_NGHTTP2
0069 #    define NGHTTP2_EXTERN __attribute__((visibility("default")))
0070 #  else /* !BUILDING_NGHTTP2 */
0071 #    define NGHTTP2_EXTERN
0072 #  endif /* !BUILDING_NGHTTP2 */
0073 #endif   /* !defined(WIN32) */
0074 
0075 #ifdef BUILDING_NGHTTP2
0076 #  undef NGHTTP2_NO_SSIZE_T
0077 #endif /* BUILDING_NGHTTP2 */
0078 
0079 /**
0080  * @typedef
0081  *
0082  * :type:`nghttp2_ssize` is a signed counterpart of size_t.
0083  */
0084 typedef ptrdiff_t nghttp2_ssize;
0085 
0086 /**
0087  * @macro
0088  *
0089  * The protocol version identification string of this library
0090  * supports.  This identifier is used if HTTP/2 is used over TLS.
0091  */
0092 #define NGHTTP2_PROTO_VERSION_ID "h2"
0093 /**
0094  * @macro
0095  *
0096  * The length of :macro:`NGHTTP2_PROTO_VERSION_ID`.
0097  */
0098 #define NGHTTP2_PROTO_VERSION_ID_LEN 2
0099 
0100 /**
0101  * @macro
0102  *
0103  * The serialized form of ALPN protocol identifier this library
0104  * supports.  Notice that first byte is the length of following
0105  * protocol identifier.  This is the same wire format of `TLS ALPN
0106  * extension <https://tools.ietf.org/html/rfc7301>`_.  This is useful
0107  * to process incoming ALPN tokens in wire format.
0108  */
0109 #define NGHTTP2_PROTO_ALPN "\x2h2"
0110 
0111 /**
0112  * @macro
0113  *
0114  * The length of :macro:`NGHTTP2_PROTO_ALPN`.
0115  */
0116 #define NGHTTP2_PROTO_ALPN_LEN (sizeof(NGHTTP2_PROTO_ALPN) - 1)
0117 
0118 /**
0119  * @macro
0120  *
0121  * The protocol version identification string of this library
0122  * supports.  This identifier is used if HTTP/2 is used over cleartext
0123  * TCP.
0124  */
0125 #define NGHTTP2_CLEARTEXT_PROTO_VERSION_ID "h2c"
0126 
0127 /**
0128  * @macro
0129  *
0130  * The length of :macro:`NGHTTP2_CLEARTEXT_PROTO_VERSION_ID`.
0131  */
0132 #define NGHTTP2_CLEARTEXT_PROTO_VERSION_ID_LEN 3
0133 
0134 struct nghttp2_session;
0135 /**
0136  * @struct
0137  *
0138  * The primary structure to hold the resources needed for a HTTP/2
0139  * session.  The details of this structure are intentionally hidden
0140  * from the public API.
0141  */
0142 typedef struct nghttp2_session nghttp2_session;
0143 
0144 /**
0145  * @macro
0146  *
0147  * The age of :type:`nghttp2_info`
0148  */
0149 #define NGHTTP2_VERSION_AGE 1
0150 
0151 /**
0152  * @struct
0153  *
0154  * This struct is what `nghttp2_version()` returns.  It holds
0155  * information about the particular nghttp2 version.
0156  */
0157 typedef struct {
0158   /**
0159    * Age of this struct.  This instance of nghttp2 sets it to
0160    * :macro:`NGHTTP2_VERSION_AGE` but a future version may bump it and
0161    * add more struct fields at the bottom
0162    */
0163   int age;
0164   /**
0165    * the :macro:`NGHTTP2_VERSION_NUM` number (since age ==1)
0166    */
0167   int version_num;
0168   /**
0169    * points to the :macro:`NGHTTP2_VERSION` string (since age ==1)
0170    */
0171   const char *version_str;
0172   /**
0173    * points to the :macro:`NGHTTP2_PROTO_VERSION_ID` string this
0174    * instance implements (since age ==1)
0175    */
0176   const char *proto_str;
0177   /* -------- the above fields all exist when age == 1 */
0178 } nghttp2_info;
0179 
0180 /**
0181  * @macro
0182  *
0183  * .. warning::
0184  *
0185  *   Deprecated.  :rfc:`7540` priorities are deprecated by
0186  *   :rfc:`9113`.  Consider migrating to :rfc:`9218` extensible
0187  *   prioritization scheme.
0188  *
0189  * The default weight of stream dependency.
0190  */
0191 #define NGHTTP2_DEFAULT_WEIGHT 16
0192 
0193 /**
0194  * @macro
0195  *
0196  * .. warning::
0197  *
0198  *   Deprecated.  :rfc:`7540` priorities are deprecated by
0199  *   :rfc:`9113`.  Consider migrating to :rfc:`9218` extensible
0200  *   prioritization scheme.
0201  *
0202  * The maximum weight of stream dependency.
0203  */
0204 #define NGHTTP2_MAX_WEIGHT 256
0205 
0206 /**
0207  * @macro
0208  *
0209  * .. warning::
0210  *
0211  *   Deprecated.  :rfc:`7540` priorities are deprecated by
0212  *   :rfc:`9113`.  Consider migrating to :rfc:`9218` extensible
0213  *   prioritization scheme.
0214  *
0215  * The minimum weight of stream dependency.
0216  */
0217 #define NGHTTP2_MIN_WEIGHT 1
0218 
0219 /**
0220  * @macro
0221  *
0222  * The maximum window size
0223  */
0224 #define NGHTTP2_MAX_WINDOW_SIZE ((int32_t)((1U << 31) - 1))
0225 
0226 /**
0227  * @macro
0228  *
0229  * The initial window size for stream level flow control.
0230  */
0231 #define NGHTTP2_INITIAL_WINDOW_SIZE ((1 << 16) - 1)
0232 /**
0233  * @macro
0234  *
0235  * The initial window size for connection level flow control.
0236  */
0237 #define NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE ((1 << 16) - 1)
0238 
0239 /**
0240  * @macro
0241  *
0242  * The default header table size.
0243  */
0244 #define NGHTTP2_DEFAULT_HEADER_TABLE_SIZE (1 << 12)
0245 
0246 /**
0247  * @macro
0248  *
0249  * The client magic string, which is the first 24 bytes byte string of
0250  * client connection preface.
0251  */
0252 #define NGHTTP2_CLIENT_MAGIC "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"
0253 
0254 /**
0255  * @macro
0256  *
0257  * The length of :macro:`NGHTTP2_CLIENT_MAGIC`.
0258  */
0259 #define NGHTTP2_CLIENT_MAGIC_LEN 24
0260 
0261 /**
0262  * @macro
0263  *
0264  * The default max number of settings per SETTINGS frame
0265  */
0266 #define NGHTTP2_DEFAULT_MAX_SETTINGS 32
0267 
0268 /**
0269  * @enum
0270  *
0271  * Error codes used in this library.  The code range is [-999, -500],
0272  * inclusive. The following values are defined:
0273  */
0274 typedef enum {
0275   /**
0276    * Invalid argument passed.
0277    */
0278   NGHTTP2_ERR_INVALID_ARGUMENT = -501,
0279   /**
0280    * Out of buffer space.
0281    */
0282   NGHTTP2_ERR_BUFFER_ERROR = -502,
0283   /**
0284    * The specified protocol version is not supported.
0285    */
0286   NGHTTP2_ERR_UNSUPPORTED_VERSION = -503,
0287   /**
0288    * Used as a return value from :type:`nghttp2_send_callback2`,
0289    * :type:`nghttp2_recv_callback` and
0290    * :type:`nghttp2_send_data_callback` to indicate that the operation
0291    * would block.
0292    */
0293   NGHTTP2_ERR_WOULDBLOCK = -504,
0294   /**
0295    * General protocol error
0296    */
0297   NGHTTP2_ERR_PROTO = -505,
0298   /**
0299    * The frame is invalid.
0300    */
0301   NGHTTP2_ERR_INVALID_FRAME = -506,
0302   /**
0303    * The peer performed a shutdown on the connection.
0304    */
0305   NGHTTP2_ERR_EOF = -507,
0306   /**
0307    * Used as a return value from
0308    * :func:`nghttp2_data_source_read_callback2` to indicate that data
0309    * transfer is postponed.  See
0310    * :func:`nghttp2_data_source_read_callback2` for details.
0311    */
0312   NGHTTP2_ERR_DEFERRED = -508,
0313   /**
0314    * Stream ID has reached the maximum value.  Therefore no stream ID
0315    * is available.
0316    */
0317   NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE = -509,
0318   /**
0319    * The stream is already closed; or the stream ID is invalid.
0320    */
0321   NGHTTP2_ERR_STREAM_CLOSED = -510,
0322   /**
0323    * RST_STREAM has been added to the outbound queue.  The stream is
0324    * in closing state.
0325    */
0326   NGHTTP2_ERR_STREAM_CLOSING = -511,
0327   /**
0328    * The transmission is not allowed for this stream (e.g., a frame
0329    * with END_STREAM flag set has already sent).
0330    */
0331   NGHTTP2_ERR_STREAM_SHUT_WR = -512,
0332   /**
0333    * The stream ID is invalid.
0334    */
0335   NGHTTP2_ERR_INVALID_STREAM_ID = -513,
0336   /**
0337    * The state of the stream is not valid (e.g., DATA cannot be sent
0338    * to the stream if response HEADERS has not been sent).
0339    */
0340   NGHTTP2_ERR_INVALID_STREAM_STATE = -514,
0341   /**
0342    * Another DATA frame has already been deferred.
0343    */
0344   NGHTTP2_ERR_DEFERRED_DATA_EXIST = -515,
0345   /**
0346    * Starting new stream is not allowed (e.g., GOAWAY has been sent
0347    * and/or received).
0348    */
0349   NGHTTP2_ERR_START_STREAM_NOT_ALLOWED = -516,
0350   /**
0351    * GOAWAY has already been sent.
0352    */
0353   NGHTTP2_ERR_GOAWAY_ALREADY_SENT = -517,
0354   /**
0355    * The received frame contains the invalid header block (e.g., There
0356    * are duplicate header names; or the header names are not encoded
0357    * in US-ASCII character set and not lower cased; or the header name
0358    * is zero-length string; or the header value contains multiple
0359    * in-sequence NUL bytes).
0360    */
0361   NGHTTP2_ERR_INVALID_HEADER_BLOCK = -518,
0362   /**
0363    * Indicates that the context is not suitable to perform the
0364    * requested operation.
0365    */
0366   NGHTTP2_ERR_INVALID_STATE = -519,
0367   /**
0368    * The user callback function failed due to the temporal error.
0369    */
0370   NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE = -521,
0371   /**
0372    * The length of the frame is invalid, either too large or too small.
0373    */
0374   NGHTTP2_ERR_FRAME_SIZE_ERROR = -522,
0375   /**
0376    * Header block inflate/deflate error.
0377    */
0378   NGHTTP2_ERR_HEADER_COMP = -523,
0379   /**
0380    * Flow control error
0381    */
0382   NGHTTP2_ERR_FLOW_CONTROL = -524,
0383   /**
0384    * Insufficient buffer size given to function.
0385    */
0386   NGHTTP2_ERR_INSUFF_BUFSIZE = -525,
0387   /**
0388    * Callback was paused by the application
0389    */
0390   NGHTTP2_ERR_PAUSE = -526,
0391   /**
0392    * There are too many in-flight SETTING frame and no more
0393    * transmission of SETTINGS is allowed.
0394    */
0395   NGHTTP2_ERR_TOO_MANY_INFLIGHT_SETTINGS = -527,
0396   /**
0397    * The server push is disabled.
0398    */
0399   NGHTTP2_ERR_PUSH_DISABLED = -528,
0400   /**
0401    * DATA or HEADERS frame for a given stream has been already
0402    * submitted and has not been fully processed yet.  Application
0403    * should wait for the transmission of the previously submitted
0404    * frame before submitting another.
0405    */
0406   NGHTTP2_ERR_DATA_EXIST = -529,
0407   /**
0408    * The current session is closing due to a connection error or
0409    * `nghttp2_session_terminate_session()` is called.
0410    */
0411   NGHTTP2_ERR_SESSION_CLOSING = -530,
0412   /**
0413    * Invalid HTTP header field was received and stream is going to be
0414    * closed.
0415    */
0416   NGHTTP2_ERR_HTTP_HEADER = -531,
0417   /**
0418    * Violation in HTTP messaging rule.
0419    */
0420   NGHTTP2_ERR_HTTP_MESSAGING = -532,
0421   /**
0422    * Stream was refused.
0423    */
0424   NGHTTP2_ERR_REFUSED_STREAM = -533,
0425   /**
0426    * Unexpected internal error, but recovered.
0427    */
0428   NGHTTP2_ERR_INTERNAL = -534,
0429   /**
0430    * Indicates that a processing was canceled.
0431    */
0432   NGHTTP2_ERR_CANCEL = -535,
0433   /**
0434    * When a local endpoint expects to receive SETTINGS frame, it
0435    * receives an other type of frame.
0436    */
0437   NGHTTP2_ERR_SETTINGS_EXPECTED = -536,
0438   /**
0439    * When a local endpoint receives too many settings entries
0440    * in a single SETTINGS frame.
0441    */
0442   NGHTTP2_ERR_TOO_MANY_SETTINGS = -537,
0443   /**
0444    * The errors < :enum:`nghttp2_error.NGHTTP2_ERR_FATAL` mean that
0445    * the library is under unexpected condition and processing was
0446    * terminated (e.g., out of memory).  If application receives this
0447    * error code, it must stop using that :type:`nghttp2_session`
0448    * object and only allowed operation for that object is deallocate
0449    * it using `nghttp2_session_del()`.
0450    */
0451   NGHTTP2_ERR_FATAL = -900,
0452   /**
0453    * Out of memory.  This is a fatal error.
0454    */
0455   NGHTTP2_ERR_NOMEM = -901,
0456   /**
0457    * The user callback function failed.  This is a fatal error.
0458    */
0459   NGHTTP2_ERR_CALLBACK_FAILURE = -902,
0460   /**
0461    * Invalid client magic (see :macro:`NGHTTP2_CLIENT_MAGIC`) was
0462    * received and further processing is not possible.
0463    */
0464   NGHTTP2_ERR_BAD_CLIENT_MAGIC = -903,
0465   /**
0466    * Possible flooding by peer was detected in this HTTP/2 session.
0467    * Flooding is measured by how many PING and SETTINGS frames with
0468    * ACK flag set are queued for transmission.  These frames are
0469    * response for the peer initiated frames, and peer can cause memory
0470    * exhaustion on server side to send these frames forever and does
0471    * not read network.
0472    */
0473   NGHTTP2_ERR_FLOODED = -904,
0474   /**
0475    * When a local endpoint receives too many CONTINUATION frames
0476    * following a HEADER frame.
0477    */
0478   NGHTTP2_ERR_TOO_MANY_CONTINUATIONS = -905,
0479 } nghttp2_error;
0480 
0481 /**
0482  * @struct
0483  *
0484  * The object representing single contiguous buffer.
0485  */
0486 typedef struct {
0487   /**
0488    * The pointer to the buffer.
0489    */
0490   uint8_t *base;
0491   /**
0492    * The length of the buffer.
0493    */
0494   size_t len;
0495 } nghttp2_vec;
0496 
0497 struct nghttp2_rcbuf;
0498 
0499 /**
0500  * @struct
0501  *
0502  * The object representing reference counted buffer.  The details of
0503  * this structure are intentionally hidden from the public API.
0504  */
0505 typedef struct nghttp2_rcbuf nghttp2_rcbuf;
0506 
0507 /**
0508  * @function
0509  *
0510  * Increments the reference count of |rcbuf| by 1.
0511  */
0512 NGHTTP2_EXTERN void nghttp2_rcbuf_incref(nghttp2_rcbuf *rcbuf);
0513 
0514 /**
0515  * @function
0516  *
0517  * Decrements the reference count of |rcbuf| by 1.  If the reference
0518  * count becomes zero, the object pointed by |rcbuf| will be freed.
0519  * In this case, application must not use |rcbuf| again.
0520  */
0521 NGHTTP2_EXTERN void nghttp2_rcbuf_decref(nghttp2_rcbuf *rcbuf);
0522 
0523 /**
0524  * @function
0525  *
0526  * Returns the underlying buffer managed by |rcbuf|.
0527  */
0528 NGHTTP2_EXTERN nghttp2_vec nghttp2_rcbuf_get_buf(nghttp2_rcbuf *rcbuf);
0529 
0530 /**
0531  * @function
0532  *
0533  * Returns nonzero if the underlying buffer is statically allocated,
0534  * and 0 otherwise. This can be useful for language bindings that wish
0535  * to avoid creating duplicate strings for these buffers.
0536  */
0537 NGHTTP2_EXTERN int nghttp2_rcbuf_is_static(const nghttp2_rcbuf *rcbuf);
0538 
0539 /**
0540  * @enum
0541  *
0542  * The flags for header field name/value pair.
0543  */
0544 typedef enum {
0545   /**
0546    * No flag set.
0547    */
0548   NGHTTP2_NV_FLAG_NONE = 0,
0549   /**
0550    * Indicates that this name/value pair must not be indexed ("Literal
0551    * Header Field never Indexed" representation must be used in HPACK
0552    * encoding).  Other implementation calls this bit as "sensitive".
0553    */
0554   NGHTTP2_NV_FLAG_NO_INDEX = 0x01,
0555   /**
0556    * This flag is set solely by application.  If this flag is set, the
0557    * library does not make a copy of header field name.  This could
0558    * improve performance.
0559    */
0560   NGHTTP2_NV_FLAG_NO_COPY_NAME = 0x02,
0561   /**
0562    * This flag is set solely by application.  If this flag is set, the
0563    * library does not make a copy of header field value.  This could
0564    * improve performance.
0565    */
0566   NGHTTP2_NV_FLAG_NO_COPY_VALUE = 0x04
0567 } nghttp2_nv_flag;
0568 
0569 /**
0570  * @struct
0571  *
0572  * The name/value pair, which mainly used to represent header fields.
0573  */
0574 typedef struct {
0575   /**
0576    * The |name| byte string.  If this struct is presented from library
0577    * (e.g., :type:`nghttp2_on_frame_recv_callback`), |name| is
0578    * guaranteed to be NULL-terminated.  For some callbacks
0579    * (:type:`nghttp2_before_frame_send_callback`,
0580    * :type:`nghttp2_on_frame_send_callback`, and
0581    * :type:`nghttp2_on_frame_not_send_callback`), it may not be
0582    * NULL-terminated if header field is passed from application with
0583    * the flag :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME`).
0584    * When application is constructing this struct, |name| is not
0585    * required to be NULL-terminated.
0586    */
0587   uint8_t *name;
0588   /**
0589    * The |value| byte string.  If this struct is presented from
0590    * library (e.g., :type:`nghttp2_on_frame_recv_callback`), |value|
0591    * is guaranteed to be NULL-terminated.  For some callbacks
0592    * (:type:`nghttp2_before_frame_send_callback`,
0593    * :type:`nghttp2_on_frame_send_callback`, and
0594    * :type:`nghttp2_on_frame_not_send_callback`), it may not be
0595    * NULL-terminated if header field is passed from application with
0596    * the flag :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_VALUE`).
0597    * When application is constructing this struct, |value| is not
0598    * required to be NULL-terminated.
0599    */
0600   uint8_t *value;
0601   /**
0602    * The length of the |name|, excluding terminating NULL.
0603    */
0604   size_t namelen;
0605   /**
0606    * The length of the |value|, excluding terminating NULL.
0607    */
0608   size_t valuelen;
0609   /**
0610    * Bitwise OR of one or more of :type:`nghttp2_nv_flag`.
0611    */
0612   uint8_t flags;
0613 } nghttp2_nv;
0614 
0615 /**
0616  * @enum
0617  *
0618  * The frame types in HTTP/2 specification.
0619  */
0620 typedef enum {
0621   /**
0622    * The DATA frame.
0623    */
0624   NGHTTP2_DATA = 0,
0625   /**
0626    * The HEADERS frame.
0627    */
0628   NGHTTP2_HEADERS = 0x01,
0629   /**
0630    * The PRIORITY frame.
0631    */
0632   NGHTTP2_PRIORITY = 0x02,
0633   /**
0634    * The RST_STREAM frame.
0635    */
0636   NGHTTP2_RST_STREAM = 0x03,
0637   /**
0638    * The SETTINGS frame.
0639    */
0640   NGHTTP2_SETTINGS = 0x04,
0641   /**
0642    * The PUSH_PROMISE frame.
0643    */
0644   NGHTTP2_PUSH_PROMISE = 0x05,
0645   /**
0646    * The PING frame.
0647    */
0648   NGHTTP2_PING = 0x06,
0649   /**
0650    * The GOAWAY frame.
0651    */
0652   NGHTTP2_GOAWAY = 0x07,
0653   /**
0654    * The WINDOW_UPDATE frame.
0655    */
0656   NGHTTP2_WINDOW_UPDATE = 0x08,
0657   /**
0658    * The CONTINUATION frame.  This frame type won't be passed to any
0659    * callbacks because the library processes this frame type and its
0660    * preceding HEADERS/PUSH_PROMISE as a single frame.
0661    */
0662   NGHTTP2_CONTINUATION = 0x09,
0663   /**
0664    * The ALTSVC frame, which is defined in `RFC 7383
0665    * <https://tools.ietf.org/html/rfc7838#section-4>`_.
0666    */
0667   NGHTTP2_ALTSVC = 0x0a,
0668   /**
0669    * The ORIGIN frame, which is defined by `RFC 8336
0670    * <https://tools.ietf.org/html/rfc8336>`_.
0671    */
0672   NGHTTP2_ORIGIN = 0x0c,
0673   /**
0674    * The PRIORITY_UPDATE frame, which is defined by :rfc:`9218`.
0675    */
0676   NGHTTP2_PRIORITY_UPDATE = 0x10
0677 } nghttp2_frame_type;
0678 
0679 /**
0680  * @enum
0681  *
0682  * The flags for HTTP/2 frames.  This enum defines all flags for all
0683  * frames.
0684  */
0685 typedef enum {
0686   /**
0687    * No flag set.
0688    */
0689   NGHTTP2_FLAG_NONE = 0,
0690   /**
0691    * The END_STREAM flag.
0692    */
0693   NGHTTP2_FLAG_END_STREAM = 0x01,
0694   /**
0695    * The END_HEADERS flag.
0696    */
0697   NGHTTP2_FLAG_END_HEADERS = 0x04,
0698   /**
0699    * The ACK flag.
0700    */
0701   NGHTTP2_FLAG_ACK = 0x01,
0702   /**
0703    * The PADDED flag.
0704    */
0705   NGHTTP2_FLAG_PADDED = 0x08,
0706   /**
0707    * The PRIORITY flag.
0708    */
0709   NGHTTP2_FLAG_PRIORITY = 0x20
0710 } nghttp2_flag;
0711 
0712 /**
0713  * @enum
0714  * The SETTINGS ID.
0715  */
0716 typedef enum {
0717   /**
0718    * SETTINGS_HEADER_TABLE_SIZE
0719    */
0720   NGHTTP2_SETTINGS_HEADER_TABLE_SIZE = 0x01,
0721   /**
0722    * SETTINGS_ENABLE_PUSH
0723    */
0724   NGHTTP2_SETTINGS_ENABLE_PUSH = 0x02,
0725   /**
0726    * SETTINGS_MAX_CONCURRENT_STREAMS
0727    */
0728   NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS = 0x03,
0729   /**
0730    * SETTINGS_INITIAL_WINDOW_SIZE
0731    */
0732   NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE = 0x04,
0733   /**
0734    * SETTINGS_MAX_FRAME_SIZE
0735    */
0736   NGHTTP2_SETTINGS_MAX_FRAME_SIZE = 0x05,
0737   /**
0738    * SETTINGS_MAX_HEADER_LIST_SIZE
0739    */
0740   NGHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE = 0x06,
0741   /**
0742    * SETTINGS_ENABLE_CONNECT_PROTOCOL
0743    * (`RFC 8441 <https://tools.ietf.org/html/rfc8441>`_)
0744    */
0745   NGHTTP2_SETTINGS_ENABLE_CONNECT_PROTOCOL = 0x08,
0746   /**
0747    * SETTINGS_NO_RFC7540_PRIORITIES (:rfc:`9218`)
0748    */
0749   NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES = 0x09
0750 } nghttp2_settings_id;
0751 /* Note: If we add SETTINGS, update the capacity of
0752    NGHTTP2_INBOUND_NUM_IV as well */
0753 
0754 /**
0755  * @macro
0756  *
0757  * .. warning::
0758  *
0759  *   Deprecated.  The initial max concurrent streams is 0xffffffffu.
0760  *
0761  * Default maximum number of incoming concurrent streams.  Use
0762  * `nghttp2_submit_settings()` with
0763  * :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS`
0764  * to change the maximum number of incoming concurrent streams.
0765  *
0766  * .. note::
0767  *
0768  *   The maximum number of outgoing concurrent streams is 100 by
0769  *   default.
0770  */
0771 #define NGHTTP2_INITIAL_MAX_CONCURRENT_STREAMS ((1U << 31) - 1)
0772 
0773 /**
0774  * @enum
0775  * The status codes for the RST_STREAM and GOAWAY frames.
0776  */
0777 typedef enum {
0778   /**
0779    * No errors.
0780    */
0781   NGHTTP2_NO_ERROR = 0x00,
0782   /**
0783    * PROTOCOL_ERROR
0784    */
0785   NGHTTP2_PROTOCOL_ERROR = 0x01,
0786   /**
0787    * INTERNAL_ERROR
0788    */
0789   NGHTTP2_INTERNAL_ERROR = 0x02,
0790   /**
0791    * FLOW_CONTROL_ERROR
0792    */
0793   NGHTTP2_FLOW_CONTROL_ERROR = 0x03,
0794   /**
0795    * SETTINGS_TIMEOUT
0796    */
0797   NGHTTP2_SETTINGS_TIMEOUT = 0x04,
0798   /**
0799    * STREAM_CLOSED
0800    */
0801   NGHTTP2_STREAM_CLOSED = 0x05,
0802   /**
0803    * FRAME_SIZE_ERROR
0804    */
0805   NGHTTP2_FRAME_SIZE_ERROR = 0x06,
0806   /**
0807    * REFUSED_STREAM
0808    */
0809   NGHTTP2_REFUSED_STREAM = 0x07,
0810   /**
0811    * CANCEL
0812    */
0813   NGHTTP2_CANCEL = 0x08,
0814   /**
0815    * COMPRESSION_ERROR
0816    */
0817   NGHTTP2_COMPRESSION_ERROR = 0x09,
0818   /**
0819    * CONNECT_ERROR
0820    */
0821   NGHTTP2_CONNECT_ERROR = 0x0a,
0822   /**
0823    * ENHANCE_YOUR_CALM
0824    */
0825   NGHTTP2_ENHANCE_YOUR_CALM = 0x0b,
0826   /**
0827    * INADEQUATE_SECURITY
0828    */
0829   NGHTTP2_INADEQUATE_SECURITY = 0x0c,
0830   /**
0831    * HTTP_1_1_REQUIRED
0832    */
0833   NGHTTP2_HTTP_1_1_REQUIRED = 0x0d
0834 } nghttp2_error_code;
0835 
0836 /**
0837  * @struct
0838  * The frame header.
0839  */
0840 typedef struct {
0841   /**
0842    * The length field of this frame, excluding frame header.
0843    */
0844   size_t length;
0845   /**
0846    * The stream identifier (aka, stream ID)
0847    */
0848   int32_t stream_id;
0849   /**
0850    * The type of this frame.  See `nghttp2_frame_type`.
0851    */
0852   uint8_t type;
0853   /**
0854    * The flags.
0855    */
0856   uint8_t flags;
0857   /**
0858    * Reserved bit in frame header.  Currently, this is always set to 0
0859    * and application should not expect something useful in here.
0860    */
0861   uint8_t reserved;
0862 } nghttp2_frame_hd;
0863 
0864 /**
0865  * @union
0866  *
0867  * This union represents the some kind of data source passed to
0868  * :type:`nghttp2_data_source_read_callback2`.
0869  */
0870 typedef union {
0871   /**
0872    * The integer field, suitable for a file descriptor.
0873    */
0874   int fd;
0875   /**
0876    * The pointer to an arbitrary object.
0877    */
0878   void *ptr;
0879 } nghttp2_data_source;
0880 
0881 /**
0882  * @enum
0883  *
0884  * The flags used to set in |data_flags| output parameter in
0885  * :type:`nghttp2_data_source_read_callback2`.
0886  */
0887 typedef enum {
0888   /**
0889    * No flag set.
0890    */
0891   NGHTTP2_DATA_FLAG_NONE = 0,
0892   /**
0893    * Indicates EOF was sensed.
0894    */
0895   NGHTTP2_DATA_FLAG_EOF = 0x01,
0896   /**
0897    * Indicates that END_STREAM flag must not be set even if
0898    * NGHTTP2_DATA_FLAG_EOF is set.  Usually this flag is used to send
0899    * trailer fields with `nghttp2_submit_request2()` or
0900    * `nghttp2_submit_response2()`.
0901    */
0902   NGHTTP2_DATA_FLAG_NO_END_STREAM = 0x02,
0903   /**
0904    * Indicates that application will send complete DATA frame in
0905    * :type:`nghttp2_send_data_callback`.
0906    */
0907   NGHTTP2_DATA_FLAG_NO_COPY = 0x04
0908 } nghttp2_data_flag;
0909 
0910 #ifndef NGHTTP2_NO_SSIZE_T
0911 /**
0912  * @functypedef
0913  *
0914  * .. warning::
0915  *
0916  *   Deprecated.  Use :type:`nghttp2_data_source_read_callback2`
0917  *   instead.
0918  *
0919  * Callback function invoked when the library wants to read data from
0920  * the |source|.  The read data is sent in the stream |stream_id|.
0921  * The implementation of this function must read at most |length|
0922  * bytes of data from |source| (or possibly other places) and store
0923  * them in |buf| and return number of data stored in |buf|.  If EOF is
0924  * reached, set :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_EOF` flag
0925  * in |*data_flags|.
0926  *
0927  * Sometime it is desirable to avoid copying data into |buf| and let
0928  * application to send data directly.  To achieve this, set
0929  * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_COPY` to
0930  * |*data_flags| (and possibly other flags, just like when we do
0931  * copy), and return the number of bytes to send without copying data
0932  * into |buf|.  The library, seeing
0933  * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_COPY`, will invoke
0934  * :type:`nghttp2_send_data_callback`.  The application must send
0935  * complete DATA frame in that callback.
0936  *
0937  * If this callback is set by `nghttp2_submit_request()`,
0938  * `nghttp2_submit_response()` or `nghttp2_submit_headers()` and
0939  * `nghttp2_submit_data()` with flag parameter
0940  * :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM` set, and
0941  * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_EOF` flag is set to
0942  * |*data_flags|, DATA frame will have END_STREAM flag set.  Usually,
0943  * this is expected behaviour and all are fine.  One exception is send
0944  * trailer fields.  You cannot send trailer fields after sending frame
0945  * with END_STREAM set.  To avoid this problem, one can set
0946  * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_END_STREAM` along
0947  * with :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_EOF` to signal the
0948  * library not to set END_STREAM in DATA frame.  Then application can
0949  * use `nghttp2_submit_trailer()` to send trailer fields.
0950  * `nghttp2_submit_trailer()` can be called inside this callback.
0951  *
0952  * If the application wants to postpone DATA frames (e.g.,
0953  * asynchronous I/O, or reading data blocks for long time), it is
0954  * achieved by returning :enum:`nghttp2_error.NGHTTP2_ERR_DEFERRED`
0955  * without reading any data in this invocation.  The library removes
0956  * DATA frame from the outgoing queue temporarily.  To move back
0957  * deferred DATA frame to outgoing queue, call
0958  * `nghttp2_session_resume_data()`.
0959  *
0960  * By default, |length| is limited to 16KiB at maximum.  If peer
0961  * allows larger frames, application can enlarge transmission buffer
0962  * size.  See :type:`nghttp2_data_source_read_length_callback` for
0963  * more details.
0964  *
0965  * If the application just wants to return from
0966  * `nghttp2_session_send()` or `nghttp2_session_mem_send()` without
0967  * sending anything, return :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE`.
0968  *
0969  * In case of error, there are 2 choices. Returning
0970  * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` will
0971  * close the stream by issuing RST_STREAM with
0972  * :enum:`nghttp2_error_code.NGHTTP2_INTERNAL_ERROR`.  If a different
0973  * error code is desirable, use `nghttp2_submit_rst_stream()` with a
0974  * desired error code and then return
0975  * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`.
0976  * Returning :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` will
0977  * signal the entire session failure.
0978  */
0979 typedef ssize_t (*nghttp2_data_source_read_callback)(
0980     nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t length,
0981     uint32_t *data_flags, nghttp2_data_source *source, void *user_data);
0982 
0983 #endif /* NGHTTP2_NO_SSIZE_T */
0984 
0985 /**
0986  * @functypedef
0987  *
0988  * Callback function invoked when the library wants to read data from
0989  * the |source|.  The read data is sent in the stream |stream_id|.
0990  * The implementation of this function must read at most |length|
0991  * bytes of data from |source| (or possibly other places) and store
0992  * them in |buf| and return number of data stored in |buf|.  If EOF is
0993  * reached, set :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_EOF` flag
0994  * in |*data_flags|.
0995  *
0996  * Sometime it is desirable to avoid copying data into |buf| and let
0997  * application to send data directly.  To achieve this, set
0998  * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_COPY` to
0999  * |*data_flags| (and possibly other flags, just like when we do
1000  * copy), and return the number of bytes to send without copying data
1001  * into |buf|.  The library, seeing
1002  * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_COPY`, will invoke
1003  * :type:`nghttp2_send_data_callback`.  The application must send
1004  * complete DATA frame in that callback.
1005  *
1006  * If this callback is set by `nghttp2_submit_request2()`,
1007  * `nghttp2_submit_response2()` or `nghttp2_submit_headers()` and
1008  * `nghttp2_submit_data2()` with flag parameter
1009  * :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM` set, and
1010  * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_EOF` flag is set to
1011  * |*data_flags|, DATA frame will have END_STREAM flag set.  Usually,
1012  * this is expected behaviour and all are fine.  One exception is send
1013  * trailer fields.  You cannot send trailer fields after sending frame
1014  * with END_STREAM set.  To avoid this problem, one can set
1015  * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_END_STREAM` along
1016  * with :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_EOF` to signal the
1017  * library not to set END_STREAM in DATA frame.  Then application can
1018  * use `nghttp2_submit_trailer()` to send trailer fields.
1019  * `nghttp2_submit_trailer()` can be called inside this callback.
1020  *
1021  * If the application wants to postpone DATA frames (e.g.,
1022  * asynchronous I/O, or reading data blocks for long time), it is
1023  * achieved by returning :enum:`nghttp2_error.NGHTTP2_ERR_DEFERRED`
1024  * without reading any data in this invocation.  The library removes
1025  * DATA frame from the outgoing queue temporarily.  To move back
1026  * deferred DATA frame to outgoing queue, call
1027  * `nghttp2_session_resume_data()`.
1028  *
1029  * By default, |length| is limited to 16KiB at maximum.  If peer
1030  * allows larger frames, application can enlarge transmission buffer
1031  * size.  See :type:`nghttp2_data_source_read_length_callback` for
1032  * more details.
1033  *
1034  * If the application just wants to return from
1035  * `nghttp2_session_send()` or `nghttp2_session_mem_send2()` without
1036  * sending anything, return :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE`.
1037  *
1038  * In case of error, there are 2 choices. Returning
1039  * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` will
1040  * close the stream by issuing RST_STREAM with
1041  * :enum:`nghttp2_error_code.NGHTTP2_INTERNAL_ERROR`.  If a different
1042  * error code is desirable, use `nghttp2_submit_rst_stream()` with a
1043  * desired error code and then return
1044  * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`.
1045  * Returning :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` will
1046  * signal the entire session failure.
1047  */
1048 typedef nghttp2_ssize (*nghttp2_data_source_read_callback2)(
1049     nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t length,
1050     uint32_t *data_flags, nghttp2_data_source *source, void *user_data);
1051 
1052 #ifndef NGHTTP2_NO_SSIZE_T
1053 /**
1054  * @struct
1055  *
1056  * .. warning::
1057  *
1058  *   Deprecated.  Use :type:`nghttp2_data_provider2` instead.
1059  *
1060  * This struct represents the data source and the way to read a chunk
1061  * of data from it.
1062  */
1063 typedef struct {
1064   /**
1065    * The data source.
1066    */
1067   nghttp2_data_source source;
1068   /**
1069    * The callback function to read a chunk of data from the |source|.
1070    */
1071   nghttp2_data_source_read_callback read_callback;
1072 } nghttp2_data_provider;
1073 
1074 #endif /* NGHTTP2_NO_SSIZE_T */
1075 
1076 /**
1077  * @struct
1078  *
1079  * This struct represents the data source and the way to read a chunk
1080  * of data from it.
1081  */
1082 typedef struct {
1083   /**
1084    * The data source.
1085    */
1086   nghttp2_data_source source;
1087   /**
1088    * The callback function to read a chunk of data from the |source|.
1089    */
1090   nghttp2_data_source_read_callback2 read_callback;
1091 } nghttp2_data_provider2;
1092 
1093 /**
1094  * @struct
1095  *
1096  * The DATA frame.  The received data is delivered via
1097  * :type:`nghttp2_on_data_chunk_recv_callback`.
1098  */
1099 typedef struct {
1100   nghttp2_frame_hd hd;
1101   /**
1102    * The length of the padding in this frame.  This includes PAD_HIGH
1103    * and PAD_LOW.
1104    */
1105   size_t padlen;
1106 } nghttp2_data;
1107 
1108 /**
1109  * @enum
1110  *
1111  * The category of HEADERS, which indicates the role of the frame.  In
1112  * HTTP/2 spec, request, response, push response and other arbitrary
1113  * headers (e.g., trailer fields) are all called just HEADERS.  To
1114  * give the application the role of incoming HEADERS frame, we define
1115  * several categories.
1116  */
1117 typedef enum {
1118   /**
1119    * The HEADERS frame is opening new stream, which is analogous to
1120    * SYN_STREAM in SPDY.
1121    */
1122   NGHTTP2_HCAT_REQUEST = 0,
1123   /**
1124    * The HEADERS frame is the first response headers, which is
1125    * analogous to SYN_REPLY in SPDY.
1126    */
1127   NGHTTP2_HCAT_RESPONSE = 1,
1128   /**
1129    * The HEADERS frame is the first headers sent against reserved
1130    * stream.
1131    */
1132   NGHTTP2_HCAT_PUSH_RESPONSE = 2,
1133   /**
1134    * The HEADERS frame which does not apply for the above categories,
1135    * which is analogous to HEADERS in SPDY.  If non-final response
1136    * (e.g., status 1xx) is used, final response HEADERS frame will be
1137    * categorized here.
1138    */
1139   NGHTTP2_HCAT_HEADERS = 3
1140 } nghttp2_headers_category;
1141 
1142 /**
1143  * @struct
1144  *
1145  * .. warning::
1146  *
1147  *   Deprecated.  :rfc:`7540` priorities are deprecated by
1148  *   :rfc:`9113`.  Consider migrating to :rfc:`9218` extensible
1149  *   prioritization scheme.
1150  *
1151  * The structure to specify stream dependency.
1152  */
1153 typedef struct {
1154   /**
1155    * The stream ID of the stream to depend on.  Specifying 0 makes
1156    * stream not depend any other stream.
1157    */
1158   int32_t stream_id;
1159   /**
1160    * The weight of this dependency.
1161    */
1162   int32_t weight;
1163   /**
1164    * nonzero means exclusive dependency
1165    */
1166   uint8_t exclusive;
1167 } nghttp2_priority_spec;
1168 
1169 /**
1170  * @struct
1171  *
1172  * The HEADERS frame.  It has the following members:
1173  */
1174 typedef struct {
1175   /**
1176    * The frame header.
1177    */
1178   nghttp2_frame_hd hd;
1179   /**
1180    * The length of the padding in this frame.  This includes PAD_HIGH
1181    * and PAD_LOW.
1182    */
1183   size_t padlen;
1184   /**
1185    * .. warning::
1186    *
1187    *   Deprecated.  :rfc:`7540` priorities are deprecated by
1188    *   :rfc:`9113`.  Consider migrating to :rfc:`9218` extensible
1189    *   prioritization scheme.
1190    *
1191    * The priority specification
1192    */
1193   nghttp2_priority_spec pri_spec;
1194   /**
1195    * The name/value pairs.
1196    */
1197   nghttp2_nv *nva;
1198   /**
1199    * The number of name/value pairs in |nva|.
1200    */
1201   size_t nvlen;
1202   /**
1203    * The category of this HEADERS frame.
1204    */
1205   nghttp2_headers_category cat;
1206 } nghttp2_headers;
1207 
1208 /**
1209  * @struct
1210  *
1211  * .. warning::
1212  *
1213  *   Deprecated.  :rfc:`7540` priorities are deprecated by
1214  *   :rfc:`9113`.  Consider migrating to :rfc:`9218` extensible
1215  *   prioritization scheme.
1216  *
1217  * The PRIORITY frame.  It has the following members:
1218  */
1219 typedef struct {
1220   /**
1221    * The frame header.
1222    */
1223   nghttp2_frame_hd hd;
1224   /**
1225    * The priority specification.
1226    */
1227   nghttp2_priority_spec pri_spec;
1228 } nghttp2_priority;
1229 
1230 /**
1231  * @struct
1232  *
1233  * The RST_STREAM frame.  It has the following members:
1234  */
1235 typedef struct {
1236   /**
1237    * The frame header.
1238    */
1239   nghttp2_frame_hd hd;
1240   /**
1241    * The error code.  See :type:`nghttp2_error_code`.
1242    */
1243   uint32_t error_code;
1244 } nghttp2_rst_stream;
1245 
1246 /**
1247  * @struct
1248  *
1249  * The SETTINGS ID/Value pair.  It has the following members:
1250  */
1251 typedef struct {
1252   /**
1253    * The SETTINGS ID.  See :type:`nghttp2_settings_id`.
1254    */
1255   int32_t settings_id;
1256   /**
1257    * The value of this entry.
1258    */
1259   uint32_t value;
1260 } nghttp2_settings_entry;
1261 
1262 /**
1263  * @struct
1264  *
1265  * The SETTINGS frame.  It has the following members:
1266  */
1267 typedef struct {
1268   /**
1269    * The frame header.
1270    */
1271   nghttp2_frame_hd hd;
1272   /**
1273    * The number of SETTINGS ID/Value pairs in |iv|.
1274    */
1275   size_t niv;
1276   /**
1277    * The pointer to the array of SETTINGS ID/Value pair.
1278    */
1279   nghttp2_settings_entry *iv;
1280 } nghttp2_settings;
1281 
1282 /**
1283  * @struct
1284  *
1285  * The PUSH_PROMISE frame.  It has the following members:
1286  */
1287 typedef struct {
1288   /**
1289    * The frame header.
1290    */
1291   nghttp2_frame_hd hd;
1292   /**
1293    * The length of the padding in this frame.  This includes PAD_HIGH
1294    * and PAD_LOW.
1295    */
1296   size_t padlen;
1297   /**
1298    * The name/value pairs.
1299    */
1300   nghttp2_nv *nva;
1301   /**
1302    * The number of name/value pairs in |nva|.
1303    */
1304   size_t nvlen;
1305   /**
1306    * The promised stream ID
1307    */
1308   int32_t promised_stream_id;
1309   /**
1310    * Reserved bit.  Currently this is always set to 0 and application
1311    * should not expect something useful in here.
1312    */
1313   uint8_t reserved;
1314 } nghttp2_push_promise;
1315 
1316 /**
1317  * @struct
1318  *
1319  * The PING frame.  It has the following members:
1320  */
1321 typedef struct {
1322   /**
1323    * The frame header.
1324    */
1325   nghttp2_frame_hd hd;
1326   /**
1327    * The opaque data
1328    */
1329   uint8_t opaque_data[8];
1330 } nghttp2_ping;
1331 
1332 /**
1333  * @struct
1334  *
1335  * The GOAWAY frame.  It has the following members:
1336  */
1337 typedef struct {
1338   /**
1339    * The frame header.
1340    */
1341   nghttp2_frame_hd hd;
1342   /**
1343    * The last stream stream ID.
1344    */
1345   int32_t last_stream_id;
1346   /**
1347    * The error code.  See :type:`nghttp2_error_code`.
1348    */
1349   uint32_t error_code;
1350   /**
1351    * The additional debug data
1352    */
1353   uint8_t *opaque_data;
1354   /**
1355    * The length of |opaque_data| member.
1356    */
1357   size_t opaque_data_len;
1358   /**
1359    * Reserved bit.  Currently this is always set to 0 and application
1360    * should not expect something useful in here.
1361    */
1362   uint8_t reserved;
1363 } nghttp2_goaway;
1364 
1365 /**
1366  * @struct
1367  *
1368  * The WINDOW_UPDATE frame.  It has the following members:
1369  */
1370 typedef struct {
1371   /**
1372    * The frame header.
1373    */
1374   nghttp2_frame_hd hd;
1375   /**
1376    * The window size increment.
1377    */
1378   int32_t window_size_increment;
1379   /**
1380    * Reserved bit.  Currently this is always set to 0 and application
1381    * should not expect something useful in here.
1382    */
1383   uint8_t reserved;
1384 } nghttp2_window_update;
1385 
1386 /**
1387  * @struct
1388  *
1389  * The extension frame.  It has following members:
1390  */
1391 typedef struct {
1392   /**
1393    * The frame header.
1394    */
1395   nghttp2_frame_hd hd;
1396   /**
1397    * The pointer to extension payload.  The exact pointer type is
1398    * determined by hd.type.
1399    *
1400    * Currently, no extension is supported.  This is a place holder for
1401    * the future extensions.
1402    */
1403   void *payload;
1404 } nghttp2_extension;
1405 
1406 /**
1407  * @union
1408  *
1409  * This union includes all frames to pass them to various function
1410  * calls as nghttp2_frame type.  The CONTINUATION frame is omitted
1411  * from here because the library deals with it internally.
1412  */
1413 typedef union {
1414   /**
1415    * The frame header, which is convenient to inspect frame header.
1416    */
1417   nghttp2_frame_hd hd;
1418   /**
1419    * The DATA frame.
1420    */
1421   nghttp2_data data;
1422   /**
1423    * The HEADERS frame.
1424    */
1425   nghttp2_headers headers;
1426   /**
1427    * The PRIORITY frame.
1428    */
1429   nghttp2_priority priority;
1430   /**
1431    * The RST_STREAM frame.
1432    */
1433   nghttp2_rst_stream rst_stream;
1434   /**
1435    * The SETTINGS frame.
1436    */
1437   nghttp2_settings settings;
1438   /**
1439    * The PUSH_PROMISE frame.
1440    */
1441   nghttp2_push_promise push_promise;
1442   /**
1443    * The PING frame.
1444    */
1445   nghttp2_ping ping;
1446   /**
1447    * The GOAWAY frame.
1448    */
1449   nghttp2_goaway goaway;
1450   /**
1451    * The WINDOW_UPDATE frame.
1452    */
1453   nghttp2_window_update window_update;
1454   /**
1455    * The extension frame.
1456    */
1457   nghttp2_extension ext;
1458 } nghttp2_frame;
1459 
1460 #ifndef NGHTTP2_NO_SSIZE_T
1461 /**
1462  * @functypedef
1463  *
1464  * .. warning::
1465  *
1466  *   Deprecated.  Use :type:`nghttp2_send_callback2` instead.
1467  *
1468  * Callback function invoked when |session| wants to send data to the
1469  * remote peer.  The implementation of this function must send at most
1470  * |length| bytes of data stored in |data|.  The |flags| is currently
1471  * not used and always 0. It must return the number of bytes sent if
1472  * it succeeds.  If it cannot send any single byte without blocking,
1473  * it must return :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`.  For
1474  * other errors, it must return
1475  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.  The
1476  * |user_data| pointer is the third argument passed in to the call to
1477  * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`.
1478  *
1479  * This callback is required if the application uses
1480  * `nghttp2_session_send()` to send data to the remote endpoint.  If
1481  * the application uses solely `nghttp2_session_mem_send()` instead,
1482  * this callback function is unnecessary.
1483  *
1484  * To set this callback to :type:`nghttp2_session_callbacks`, use
1485  * `nghttp2_session_callbacks_set_send_callback()`.
1486  *
1487  * .. note::
1488  *
1489  *   The |length| may be very small.  If that is the case, and
1490  *   application disables Nagle algorithm (``TCP_NODELAY``), then just
1491  *   writing |data| to the network stack leads to very small packet,
1492  *   and it is very inefficient.  An application should be responsible
1493  *   to buffer up small chunks of data as necessary to avoid this
1494  *   situation.
1495  */
1496 typedef ssize_t (*nghttp2_send_callback)(nghttp2_session *session,
1497                                          const uint8_t *data, size_t length,
1498                                          int flags, void *user_data);
1499 
1500 #endif /* NGHTTP2_NO_SSIZE_T */
1501 
1502 /**
1503  * @functypedef
1504  *
1505  * Callback function invoked when |session| wants to send data to the
1506  * remote peer.  The implementation of this function must send at most
1507  * |length| bytes of data stored in |data|.  The |flags| is currently
1508  * not used and always 0. It must return the number of bytes sent if
1509  * it succeeds.  If it cannot send any single byte without blocking,
1510  * it must return :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`.  For
1511  * other errors, it must return
1512  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.  The
1513  * |user_data| pointer is the third argument passed in to the call to
1514  * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`.
1515  *
1516  * This callback is required if the application uses
1517  * `nghttp2_session_send()` to send data to the remote endpoint.  If
1518  * the application uses solely `nghttp2_session_mem_send2()` instead,
1519  * this callback function is unnecessary.
1520  *
1521  * To set this callback to :type:`nghttp2_session_callbacks`, use
1522  * `nghttp2_session_callbacks_set_send_callback2()`.
1523  *
1524  * .. note::
1525  *
1526  *   The |length| may be very small.  If that is the case, and
1527  *   application disables Nagle algorithm (``TCP_NODELAY``), then just
1528  *   writing |data| to the network stack leads to very small packet,
1529  *   and it is very inefficient.  An application should be responsible
1530  *   to buffer up small chunks of data as necessary to avoid this
1531  *   situation.
1532  */
1533 typedef nghttp2_ssize (*nghttp2_send_callback2)(nghttp2_session *session,
1534                                                 const uint8_t *data,
1535                                                 size_t length, int flags,
1536                                                 void *user_data);
1537 
1538 /**
1539  * @functypedef
1540  *
1541  * Callback function invoked when
1542  * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_COPY` is used in
1543  * :type:`nghttp2_data_source_read_callback` to send complete DATA
1544  * frame.
1545  *
1546  * The |frame| is a DATA frame to send.  The |framehd| is the
1547  * serialized frame header (9 bytes). The |length| is the length of
1548  * application data to send (this does not include padding).  The
1549  * |source| is the same pointer passed to
1550  * :type:`nghttp2_data_source_read_callback`.
1551  *
1552  * The application first must send frame header |framehd| of length 9
1553  * bytes.  If ``frame->data.padlen > 0``, send 1 byte of value
1554  * ``frame->data.padlen - 1``.  Then send exactly |length| bytes of
1555  * application data.  Finally, if ``frame->data.padlen > 1``, send
1556  * ``frame->data.padlen - 1`` bytes of zero as padding.
1557  *
1558  * The application has to send complete DATA frame in this callback.
1559  * If all data were written successfully, return 0.
1560  *
1561  * If it cannot send any data at all, just return
1562  * :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`; the library will call
1563  * this callback with the same parameters later (It is recommended to
1564  * send complete DATA frame at once in this function to deal with
1565  * error; if partial frame data has already sent, it is impossible to
1566  * send another data in that state, and all we can do is tear down
1567  * connection).  When data is fully processed, but application wants
1568  * to make `nghttp2_session_mem_send2()` or `nghttp2_session_send()`
1569  * return immediately without processing next frames, return
1570  * :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE`.  If application decided to
1571  * reset this stream, return
1572  * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`, then
1573  * the library will send RST_STREAM with INTERNAL_ERROR as error code.
1574  * The application can also return
1575  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`, which will
1576  * result in connection closure.  Returning any other value is treated
1577  * as :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` is returned.
1578  */
1579 typedef int (*nghttp2_send_data_callback)(nghttp2_session *session,
1580                                           nghttp2_frame *frame,
1581                                           const uint8_t *framehd, size_t length,
1582                                           nghttp2_data_source *source,
1583                                           void *user_data);
1584 
1585 #ifndef NGHTTP2_NO_SSIZE_T
1586 /**
1587  * @functypedef
1588  *
1589  * .. warning::
1590  *
1591  *   Deprecated.  Use :type:`nghttp2_recv_callback2` instead.
1592  *
1593  * Callback function invoked when |session| wants to receive data from
1594  * the remote peer.  The implementation of this function must read at
1595  * most |length| bytes of data and store it in |buf|.  The |flags| is
1596  * currently not used and always 0.  It must return the number of
1597  * bytes written in |buf| if it succeeds.  If it cannot read any
1598  * single byte without blocking, it must return
1599  * :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`.  If it gets EOF
1600  * before it reads any single byte, it must return
1601  * :enum:`nghttp2_error.NGHTTP2_ERR_EOF`.  For other errors, it must
1602  * return :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.
1603  * Returning 0 is treated as
1604  * :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`.  The |user_data|
1605  * pointer is the third argument passed in to the call to
1606  * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`.
1607  *
1608  * This callback is required if the application uses
1609  * `nghttp2_session_recv()` to receive data from the remote endpoint.
1610  * If the application uses solely `nghttp2_session_mem_recv()`
1611  * instead, this callback function is unnecessary.
1612  *
1613  * To set this callback to :type:`nghttp2_session_callbacks`, use
1614  * `nghttp2_session_callbacks_set_recv_callback()`.
1615  */
1616 typedef ssize_t (*nghttp2_recv_callback)(nghttp2_session *session, uint8_t *buf,
1617                                          size_t length, int flags,
1618                                          void *user_data);
1619 
1620 #endif /* NGHTTP2_NO_SSIZE_T */
1621 
1622 /**
1623  * @functypedef
1624  *
1625  * Callback function invoked when |session| wants to receive data from
1626  * the remote peer.  The implementation of this function must read at
1627  * most |length| bytes of data and store it in |buf|.  The |flags| is
1628  * currently not used and always 0.  It must return the number of
1629  * bytes written in |buf| if it succeeds.  If it cannot read any
1630  * single byte without blocking, it must return
1631  * :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`.  If it gets EOF
1632  * before it reads any single byte, it must return
1633  * :enum:`nghttp2_error.NGHTTP2_ERR_EOF`.  For other errors, it must
1634  * return :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.
1635  * Returning 0 is treated as
1636  * :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`.  The |user_data|
1637  * pointer is the third argument passed in to the call to
1638  * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`.
1639  *
1640  * This callback is required if the application uses
1641  * `nghttp2_session_recv()` to receive data from the remote endpoint.
1642  * If the application uses solely `nghttp2_session_mem_recv2()`
1643  * instead, this callback function is unnecessary.
1644  *
1645  * To set this callback to :type:`nghttp2_session_callbacks`, use
1646  * `nghttp2_session_callbacks_set_recv_callback2()`.
1647  */
1648 typedef nghttp2_ssize (*nghttp2_recv_callback2)(nghttp2_session *session,
1649                                                 uint8_t *buf, size_t length,
1650                                                 int flags, void *user_data);
1651 
1652 /**
1653  * @functypedef
1654  *
1655  * Callback function invoked by `nghttp2_session_recv()` and
1656  * `nghttp2_session_mem_recv2()` when a frame is received.  The
1657  * |user_data| pointer is the third argument passed in to the call to
1658  * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`.
1659  *
1660  * If frame is HEADERS or PUSH_PROMISE, the ``nva`` and ``nvlen``
1661  * member of their data structure are always ``NULL`` and 0
1662  * respectively.  The header name/value pairs are emitted via
1663  * :type:`nghttp2_on_header_callback`.
1664  *
1665  * Only HEADERS and DATA frame can signal the end of incoming data.
1666  * If ``frame->hd.flags & NGHTTP2_FLAG_END_STREAM`` is nonzero, the
1667  * |frame| is the last frame from the remote peer in this stream.
1668  *
1669  * This callback won't be called for CONTINUATION frames.
1670  * HEADERS/PUSH_PROMISE + CONTINUATIONs are treated as single frame.
1671  *
1672  * The implementation of this function must return 0 if it succeeds.
1673  * If nonzero value is returned, it is treated as fatal error and
1674  * `nghttp2_session_recv()` and `nghttp2_session_mem_recv2()`
1675  * functions immediately return
1676  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.
1677  *
1678  * To set this callback to :type:`nghttp2_session_callbacks`, use
1679  * `nghttp2_session_callbacks_set_on_frame_recv_callback()`.
1680  */
1681 typedef int (*nghttp2_on_frame_recv_callback)(nghttp2_session *session,
1682                                               const nghttp2_frame *frame,
1683                                               void *user_data);
1684 
1685 /**
1686  * @functypedef
1687  *
1688  * Callback function invoked by `nghttp2_session_recv()` and
1689  * `nghttp2_session_mem_recv2()` when an invalid non-DATA frame is
1690  * received.  The error is indicated by the |lib_error_code|, which is
1691  * one of the values defined in :type:`nghttp2_error`.  When this
1692  * callback function is invoked, the library automatically submits
1693  * either RST_STREAM or GOAWAY frame.  The |user_data| pointer is the
1694  * third argument passed in to the call to
1695  * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`.
1696  *
1697  * If frame is HEADERS or PUSH_PROMISE, the ``nva`` and ``nvlen``
1698  * member of their data structure are always ``NULL`` and 0
1699  * respectively.
1700  *
1701  * The implementation of this function must return 0 if it succeeds.
1702  * If nonzero is returned, it is treated as fatal error and
1703  * `nghttp2_session_recv()` and `nghttp2_session_mem_recv2()`
1704  * functions immediately return
1705  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.
1706  *
1707  * To set this callback to :type:`nghttp2_session_callbacks`, use
1708  * `nghttp2_session_callbacks_set_on_invalid_frame_recv_callback()`.
1709  */
1710 typedef int (*nghttp2_on_invalid_frame_recv_callback)(
1711     nghttp2_session *session, const nghttp2_frame *frame, int lib_error_code,
1712     void *user_data);
1713 
1714 /**
1715  * @functypedef
1716  *
1717  * Callback function invoked when a chunk of data in DATA frame is
1718  * received.  The |stream_id| is the stream ID this DATA frame belongs
1719  * to.  The |flags| is the flags of DATA frame which this data chunk
1720  * is contained.  ``(flags & NGHTTP2_FLAG_END_STREAM) != 0`` does not
1721  * necessarily mean this chunk of data is the last one in the stream.
1722  * You should use :type:`nghttp2_on_frame_recv_callback` to know all
1723  * data frames are received.  The |user_data| pointer is the third
1724  * argument passed in to the call to `nghttp2_session_client_new()` or
1725  * `nghttp2_session_server_new()`.
1726  *
1727  * If the application uses `nghttp2_session_mem_recv2()`, it can
1728  * return :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` to make
1729  * `nghttp2_session_mem_recv2()` return without processing further
1730  * input bytes.  The memory by pointed by the |data| is retained until
1731  * `nghttp2_session_mem_recv2()` or `nghttp2_session_recv()` is
1732  * called.  The application must retain the input bytes which was used
1733  * to produce the |data| parameter, because it may refer to the memory
1734  * region included in the input bytes.
1735  *
1736  * The implementation of this function must return 0 if it succeeds.
1737  * If nonzero is returned, it is treated as fatal error, and
1738  * `nghttp2_session_recv()` and `nghttp2_session_mem_recv2()`
1739  * functions immediately return
1740  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.
1741  *
1742  * To set this callback to :type:`nghttp2_session_callbacks`, use
1743  * `nghttp2_session_callbacks_set_on_data_chunk_recv_callback()`.
1744  */
1745 typedef int (*nghttp2_on_data_chunk_recv_callback)(nghttp2_session *session,
1746                                                    uint8_t flags,
1747                                                    int32_t stream_id,
1748                                                    const uint8_t *data,
1749                                                    size_t len, void *user_data);
1750 
1751 /**
1752  * @functypedef
1753  *
1754  * Callback function invoked just before the non-DATA frame |frame| is
1755  * sent.  The |user_data| pointer is the third argument passed in to
1756  * the call to `nghttp2_session_client_new()` or
1757  * `nghttp2_session_server_new()`.
1758  *
1759  * The implementation of this function must return 0 if it succeeds.
1760  * It can also return :enum:`nghttp2_error.NGHTTP2_ERR_CANCEL` to
1761  * cancel the transmission of the given frame.
1762  *
1763  * If there is a fatal error while executing this callback, the
1764  * implementation should return
1765  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`, which makes
1766  * `nghttp2_session_send()` and `nghttp2_session_mem_send2()`
1767  * functions immediately return
1768  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.
1769  *
1770  * If the other value is returned, it is treated as if
1771  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` is returned.
1772  * But the implementation should not rely on this since the library
1773  * may define new return value to extend its capability.
1774  *
1775  * To set this callback to :type:`nghttp2_session_callbacks`, use
1776  * `nghttp2_session_callbacks_set_before_frame_send_callback()`.
1777  */
1778 typedef int (*nghttp2_before_frame_send_callback)(nghttp2_session *session,
1779                                                   const nghttp2_frame *frame,
1780                                                   void *user_data);
1781 
1782 /**
1783  * @functypedef
1784  *
1785  * Callback function invoked after the frame |frame| is sent.  The
1786  * |user_data| pointer is the third argument passed in to the call to
1787  * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`.
1788  *
1789  * The implementation of this function must return 0 if it succeeds.
1790  * If nonzero is returned, it is treated as fatal error and
1791  * `nghttp2_session_send()` and `nghttp2_session_mem_send2()`
1792  * functions immediately return
1793  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.
1794  *
1795  * To set this callback to :type:`nghttp2_session_callbacks`, use
1796  * `nghttp2_session_callbacks_set_on_frame_send_callback()`.
1797  */
1798 typedef int (*nghttp2_on_frame_send_callback)(nghttp2_session *session,
1799                                               const nghttp2_frame *frame,
1800                                               void *user_data);
1801 
1802 /**
1803  * @functypedef
1804  *
1805  * Callback function invoked after the non-DATA frame |frame| is not
1806  * sent because of the error.  The error is indicated by the
1807  * |lib_error_code|, which is one of the values defined in
1808  * :type:`nghttp2_error`.  The |user_data| pointer is the third
1809  * argument passed in to the call to `nghttp2_session_client_new()` or
1810  * `nghttp2_session_server_new()`.
1811  *
1812  * The implementation of this function must return 0 if it succeeds.
1813  * If nonzero is returned, it is treated as fatal error and
1814  * `nghttp2_session_send()` and `nghttp2_session_mem_send2()`
1815  * functions immediately return
1816  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.
1817  *
1818  * `nghttp2_session_get_stream_user_data()` can be used to get
1819  * associated data.
1820  *
1821  * To set this callback to :type:`nghttp2_session_callbacks`, use
1822  * `nghttp2_session_callbacks_set_on_frame_not_send_callback()`.
1823  */
1824 typedef int (*nghttp2_on_frame_not_send_callback)(nghttp2_session *session,
1825                                                   const nghttp2_frame *frame,
1826                                                   int lib_error_code,
1827                                                   void *user_data);
1828 
1829 /**
1830  * @functypedef
1831  *
1832  * Callback function invoked when the stream |stream_id| is closed.
1833  * The reason of closure is indicated by the |error_code|.  The
1834  * |error_code| is usually one of :enum:`nghttp2_error_code`, but that
1835  * is not guaranteed.  The stream_user_data, which was specified in
1836  * `nghttp2_submit_request2()` or `nghttp2_submit_headers()`, is still
1837  * available in this function.  The |user_data| pointer is the third
1838  * argument passed in to the call to `nghttp2_session_client_new()` or
1839  * `nghttp2_session_server_new()`.
1840  *
1841  * This function is also called for a stream in reserved state.
1842  *
1843  * The implementation of this function must return 0 if it succeeds.
1844  * If nonzero is returned, it is treated as fatal error and
1845  * `nghttp2_session_recv()`, `nghttp2_session_mem_recv2()`,
1846  * `nghttp2_session_send()`, and `nghttp2_session_mem_send2()`
1847  * functions immediately return
1848  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.
1849  *
1850  * To set this callback to :type:`nghttp2_session_callbacks`, use
1851  * `nghttp2_session_callbacks_set_on_stream_close_callback()`.
1852  */
1853 typedef int (*nghttp2_on_stream_close_callback)(nghttp2_session *session,
1854                                                 int32_t stream_id,
1855                                                 uint32_t error_code,
1856                                                 void *user_data);
1857 
1858 /**
1859  * @functypedef
1860  *
1861  * Callback function invoked when the reception of header block in
1862  * HEADERS or PUSH_PROMISE is started.  Each header name/value pair
1863  * will be emitted by :type:`nghttp2_on_header_callback`.
1864  *
1865  * The ``frame->hd.flags`` may not have
1866  * :enum:`nghttp2_flag.NGHTTP2_FLAG_END_HEADERS` flag set, which
1867  * indicates that one or more CONTINUATION frames are involved.  But
1868  * the application does not need to care about that because the header
1869  * name/value pairs are emitted transparently regardless of
1870  * CONTINUATION frames.
1871  *
1872  * The server applications probably create an object to store
1873  * information about new stream if ``frame->hd.type ==
1874  * NGHTTP2_HEADERS`` and ``frame->headers.cat ==
1875  * NGHTTP2_HCAT_REQUEST``.  If |session| is configured as server side,
1876  * ``frame->headers.cat`` is either ``NGHTTP2_HCAT_REQUEST``
1877  * containing request headers or ``NGHTTP2_HCAT_HEADERS`` containing
1878  * trailer fields and never get PUSH_PROMISE in this callback.
1879  *
1880  * For the client applications, ``frame->hd.type`` is either
1881  * ``NGHTTP2_HEADERS`` or ``NGHTTP2_PUSH_PROMISE``.  In case of
1882  * ``NGHTTP2_HEADERS``, ``frame->headers.cat ==
1883  * NGHTTP2_HCAT_RESPONSE`` means that it is the first response
1884  * headers, but it may be non-final response which is indicated by 1xx
1885  * status code.  In this case, there may be zero or more HEADERS frame
1886  * with ``frame->headers.cat == NGHTTP2_HCAT_HEADERS`` which has
1887  * non-final response code and finally client gets exactly one HEADERS
1888  * frame with ``frame->headers.cat == NGHTTP2_HCAT_HEADERS``
1889  * containing final response headers (non-1xx status code).  The
1890  * trailer fields also has ``frame->headers.cat ==
1891  * NGHTTP2_HCAT_HEADERS`` which does not contain any status code.
1892  *
1893  * Returning
1894  * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` will
1895  * close the stream (promised stream if frame is PUSH_PROMISE) by
1896  * issuing RST_STREAM with
1897  * :enum:`nghttp2_error_code.NGHTTP2_INTERNAL_ERROR`.  In this case,
1898  * :type:`nghttp2_on_header_callback` and
1899  * :type:`nghttp2_on_frame_recv_callback` will not be invoked.  If a
1900  * different error code is desirable, use
1901  * `nghttp2_submit_rst_stream()` with a desired error code and then
1902  * return :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`.
1903  * Again, use ``frame->push_promise.promised_stream_id`` as stream_id
1904  * parameter in `nghttp2_submit_rst_stream()` if frame is
1905  * PUSH_PROMISE.
1906  *
1907  * The implementation of this function must return 0 if it succeeds.
1908  * It can return
1909  * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` to
1910  * reset the stream (promised stream if frame is PUSH_PROMISE).  For
1911  * critical errors, it must return
1912  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.  If the other
1913  * value is returned, it is treated as if
1914  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` is returned.  If
1915  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` is returned,
1916  * `nghttp2_session_mem_recv2()` function will immediately return
1917  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.
1918  *
1919  * To set this callback to :type:`nghttp2_session_callbacks`, use
1920  * `nghttp2_session_callbacks_set_on_begin_headers_callback()`.
1921  */
1922 typedef int (*nghttp2_on_begin_headers_callback)(nghttp2_session *session,
1923                                                  const nghttp2_frame *frame,
1924                                                  void *user_data);
1925 
1926 /**
1927  * @functypedef
1928  *
1929  * Callback function invoked when a header name/value pair is received
1930  * for the |frame|.  The |name| of length |namelen| is header name.
1931  * The |value| of length |valuelen| is header value.  The |flags| is
1932  * bitwise OR of one or more of :type:`nghttp2_nv_flag`.
1933  *
1934  * If :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_INDEX` is set in
1935  * |flags|, the receiver must not index this name/value pair when
1936  * forwarding it to the next hop.  More specifically, "Literal Header
1937  * Field never Indexed" representation must be used in HPACK encoding.
1938  *
1939  * When this callback is invoked, ``frame->hd.type`` is either
1940  * :enum:`nghttp2_frame_type.NGHTTP2_HEADERS` or
1941  * :enum:`nghttp2_frame_type.NGHTTP2_PUSH_PROMISE`.  After all header
1942  * name/value pairs are processed with this callback, and no error has
1943  * been detected, :type:`nghttp2_on_frame_recv_callback` will be
1944  * invoked.  If there is an error in decompression,
1945  * :type:`nghttp2_on_frame_recv_callback` for the |frame| will not be
1946  * invoked.
1947  *
1948  * Both |name| and |value| are guaranteed to be NULL-terminated.  The
1949  * |namelen| and |valuelen| do not include terminal NULL.  If
1950  * `nghttp2_option_set_no_http_messaging()` is used with nonzero
1951  * value, NULL character may be included in |name| or |value| before
1952  * terminating NULL.
1953  *
1954  * Please note that unless `nghttp2_option_set_no_http_messaging()` is
1955  * used, nghttp2 library does perform validation against the |name|
1956  * and the |value| using `nghttp2_check_header_name()` and
1957  * `nghttp2_check_header_value()`.  In addition to this, nghttp2
1958  * performs validation based on HTTP Messaging rule, which is briefly
1959  * explained in :ref:`http-messaging` section.
1960  *
1961  * If the application uses `nghttp2_session_mem_recv2()`, it can
1962  * return :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` to make
1963  * `nghttp2_session_mem_recv2()` return without processing further
1964  * input bytes.  The memory pointed by |frame|, |name| and |value|
1965  * parameters are retained until `nghttp2_session_mem_recv2()` or
1966  * `nghttp2_session_recv()` is called.  The application must retain
1967  * the input bytes which was used to produce these parameters, because
1968  * it may refer to the memory region included in the input bytes.
1969  *
1970  * Returning
1971  * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` will
1972  * close the stream (promised stream if frame is PUSH_PROMISE) by
1973  * issuing RST_STREAM with
1974  * :enum:`nghttp2_error_code.NGHTTP2_INTERNAL_ERROR`.  In this case,
1975  * :type:`nghttp2_on_header_callback` and
1976  * :type:`nghttp2_on_frame_recv_callback` will not be invoked.  If a
1977  * different error code is desirable, use
1978  * `nghttp2_submit_rst_stream()` with a desired error code and then
1979  * return :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`.
1980  * Again, use ``frame->push_promise.promised_stream_id`` as stream_id
1981  * parameter in `nghttp2_submit_rst_stream()` if frame is
1982  * PUSH_PROMISE.
1983  *
1984  * The implementation of this function must return 0 if it succeeds.
1985  * It may return :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` or
1986  * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`.  For
1987  * other critical failures, it must return
1988  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.  If the other
1989  * nonzero value is returned, it is treated as
1990  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.  If
1991  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` is returned,
1992  * `nghttp2_session_recv()` and `nghttp2_session_mem_recv2()`
1993  * functions immediately return
1994  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.
1995  *
1996  * To set this callback to :type:`nghttp2_session_callbacks`, use
1997  * `nghttp2_session_callbacks_set_on_header_callback()`.
1998  *
1999  * .. warning::
2000  *
2001  *   Application should properly limit the total buffer size to store
2002  *   incoming header fields.  Without it, peer may send large number
2003  *   of header fields or large header fields to cause out of memory in
2004  *   local endpoint.  Due to how HPACK works, peer can do this
2005  *   effectively without using much memory on their own.
2006  */
2007 typedef int (*nghttp2_on_header_callback)(nghttp2_session *session,
2008                                           const nghttp2_frame *frame,
2009                                           const uint8_t *name, size_t namelen,
2010                                           const uint8_t *value, size_t valuelen,
2011                                           uint8_t flags, void *user_data);
2012 
2013 /**
2014  * @functypedef
2015  *
2016  * Callback function invoked when a header name/value pair is received
2017  * for the |frame|.  The |name| is header name.  The |value| is header
2018  * value.  The |flags| is bitwise OR of one or more of
2019  * :type:`nghttp2_nv_flag`.
2020  *
2021  * This callback behaves like :type:`nghttp2_on_header_callback`,
2022  * except that |name| and |value| are stored in reference counted
2023  * buffer.  If application wishes to keep these references without
2024  * copying them, use `nghttp2_rcbuf_incref()` to increment their
2025  * reference count.  It is the application's responsibility to call
2026  * `nghttp2_rcbuf_decref()` if they called `nghttp2_rcbuf_incref()` so
2027  * as not to leak memory.  If the |session| is created by
2028  * `nghttp2_session_server_new3()` or `nghttp2_session_client_new3()`,
2029  * the function to free memory is the one belongs to the mem
2030  * parameter.  As long as this free function alives, |name| and
2031  * |value| can live after |session| was destroyed.
2032  */
2033 typedef int (*nghttp2_on_header_callback2)(nghttp2_session *session,
2034                                            const nghttp2_frame *frame,
2035                                            nghttp2_rcbuf *name,
2036                                            nghttp2_rcbuf *value, uint8_t flags,
2037                                            void *user_data);
2038 
2039 /**
2040  * @functypedef
2041  *
2042  * Callback function invoked when a invalid header name/value pair is
2043  * received for the |frame|.
2044  *
2045  * The parameter and behaviour are similar to
2046  * :type:`nghttp2_on_header_callback`.  The difference is that this
2047  * callback is only invoked when a invalid header name/value pair is
2048  * received which is treated as stream error if this callback is not
2049  * set.  Only invalid regular header field are passed to this
2050  * callback.  In other words, invalid pseudo header field is not
2051  * passed to this callback.  Also header fields which includes upper
2052  * cased latter are also treated as error without passing them to this
2053  * callback.
2054  *
2055  * This callback is only considered if HTTP messaging validation is
2056  * turned on (which is on by default, see
2057  * `nghttp2_option_set_no_http_messaging()`).
2058  *
2059  * With this callback, application inspects the incoming invalid
2060  * field, and it also can reset stream from this callback by returning
2061  * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`.  By
2062  * default, the error code is
2063  * :enum:`nghttp2_error_code.NGHTTP2_PROTOCOL_ERROR`.  To change the
2064  * error code, call `nghttp2_submit_rst_stream()` with the error code
2065  * of choice in addition to returning
2066  * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`.
2067  *
2068  * If 0 is returned, the header field is ignored, and the stream is
2069  * not reset.
2070  */
2071 typedef int (*nghttp2_on_invalid_header_callback)(
2072     nghttp2_session *session, const nghttp2_frame *frame, const uint8_t *name,
2073     size_t namelen, const uint8_t *value, size_t valuelen, uint8_t flags,
2074     void *user_data);
2075 
2076 /**
2077  * @functypedef
2078  *
2079  * Callback function invoked when a invalid header name/value pair is
2080  * received for the |frame|.
2081  *
2082  * The parameter and behaviour are similar to
2083  * :type:`nghttp2_on_header_callback2`.  The difference is that this
2084  * callback is only invoked when a invalid header name/value pair is
2085  * received which is silently ignored if this callback is not set.
2086  * Only invalid regular header field are passed to this callback.  In
2087  * other words, invalid pseudo header field is not passed to this
2088  * callback.  Also header fields which includes upper cased latter are
2089  * also treated as error without passing them to this callback.
2090  *
2091  * This callback is only considered if HTTP messaging validation is
2092  * turned on (which is on by default, see
2093  * `nghttp2_option_set_no_http_messaging()`).
2094  *
2095  * With this callback, application inspects the incoming invalid
2096  * field, and it also can reset stream from this callback by returning
2097  * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`.  By
2098  * default, the error code is
2099  * :enum:`nghttp2_error_code.NGHTTP2_INTERNAL_ERROR`.  To change the
2100  * error code, call `nghttp2_submit_rst_stream()` with the error code
2101  * of choice in addition to returning
2102  * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`.
2103  */
2104 typedef int (*nghttp2_on_invalid_header_callback2)(
2105     nghttp2_session *session, const nghttp2_frame *frame, nghttp2_rcbuf *name,
2106     nghttp2_rcbuf *value, uint8_t flags, void *user_data);
2107 
2108 #ifndef NGHTTP2_NO_SSIZE_T
2109 /**
2110  * @functypedef
2111  *
2112  * .. warning::
2113  *
2114  *   Deprecated.  Use :type:`nghttp2_select_padding_callback2`
2115  *   instead.
2116  *
2117  * Callback function invoked when the library asks application how
2118  * many padding bytes are required for the transmission of the
2119  * |frame|.  The application must choose the total length of payload
2120  * including padded bytes in range [frame->hd.length, max_payloadlen],
2121  * inclusive.  Choosing number not in this range will be treated as
2122  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.  Returning
2123  * ``frame->hd.length`` means no padding is added.  Returning
2124  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` will make
2125  * `nghttp2_session_send()` and `nghttp2_session_mem_send()` functions
2126  * immediately return
2127  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.
2128  *
2129  * To set this callback to :type:`nghttp2_session_callbacks`, use
2130  * `nghttp2_session_callbacks_set_select_padding_callback()`.
2131  */
2132 typedef ssize_t (*nghttp2_select_padding_callback)(nghttp2_session *session,
2133                                                    const nghttp2_frame *frame,
2134                                                    size_t max_payloadlen,
2135                                                    void *user_data);
2136 
2137 #endif /* NGHTTP2_NO_SSIZE_T */
2138 
2139 /**
2140  * @functypedef
2141  *
2142  * Callback function invoked when the library asks application how
2143  * many padding bytes are required for the transmission of the
2144  * |frame|.  The application must choose the total length of payload
2145  * including padded bytes in range [frame->hd.length, max_payloadlen],
2146  * inclusive.  Choosing number not in this range will be treated as
2147  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.  Returning
2148  * ``frame->hd.length`` means no padding is added.  Returning
2149  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` will make
2150  * `nghttp2_session_send()` and `nghttp2_session_mem_send2()`
2151  * functions immediately return
2152  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.
2153  *
2154  * To set this callback to :type:`nghttp2_session_callbacks`, use
2155  * `nghttp2_session_callbacks_set_select_padding_callback2()`.
2156  */
2157 typedef nghttp2_ssize (*nghttp2_select_padding_callback2)(
2158     nghttp2_session *session, const nghttp2_frame *frame, size_t max_payloadlen,
2159     void *user_data);
2160 
2161 #ifndef NGHTTP2_NO_SSIZE_T
2162 /**
2163  * @functypedef
2164  *
2165  * .. warning::
2166  *
2167  *   Deprecated.  Use
2168  *   :type:`nghttp2_data_source_read_length_callback2` instead.
2169  *
2170  * Callback function invoked when library wants to get max length of
2171  * data to send data to the remote peer.  The implementation of this
2172  * function should return a value in the following range.  [1,
2173  * min(|session_remote_window_size|, |stream_remote_window_size|,
2174  * |remote_max_frame_size|)].  If a value greater than this range is
2175  * returned than the max allow value will be used.  Returning a value
2176  * smaller than this range is treated as
2177  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.  The
2178  * |frame_type| is provided for future extensibility and identifies
2179  * the type of frame (see :type:`nghttp2_frame_type`) for which to get
2180  * the length for.  Currently supported frame types are:
2181  * :enum:`nghttp2_frame_type.NGHTTP2_DATA`.
2182  *
2183  * This callback can be used to control the length in bytes for which
2184  * :type:`nghttp2_data_source_read_callback` is allowed to send to the
2185  * remote endpoint.  This callback is optional.  Returning
2186  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` will signal the
2187  * entire session failure.
2188  *
2189  * To set this callback to :type:`nghttp2_session_callbacks`, use
2190  * `nghttp2_session_callbacks_set_data_source_read_length_callback()`.
2191  */
2192 typedef ssize_t (*nghttp2_data_source_read_length_callback)(
2193     nghttp2_session *session, uint8_t frame_type, int32_t stream_id,
2194     int32_t session_remote_window_size, int32_t stream_remote_window_size,
2195     uint32_t remote_max_frame_size, void *user_data);
2196 
2197 #endif /* NGHTTP2_NO_SSIZE_T */
2198 
2199 /**
2200  * @functypedef
2201  *
2202  * Callback function invoked when library wants to get max length of
2203  * data to send data to the remote peer.  The implementation of this
2204  * function should return a value in the following range.  [1,
2205  * min(|session_remote_window_size|, |stream_remote_window_size|,
2206  * |remote_max_frame_size|)].  If a value greater than this range is
2207  * returned than the max allow value will be used.  Returning a value
2208  * smaller than this range is treated as
2209  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.  The
2210  * |frame_type| is provided for future extensibility and identifies
2211  * the type of frame (see :type:`nghttp2_frame_type`) for which to get
2212  * the length for.  Currently supported frame types are:
2213  * :enum:`nghttp2_frame_type.NGHTTP2_DATA`.
2214  *
2215  * This callback can be used to control the length in bytes for which
2216  * :type:`nghttp2_data_source_read_callback` is allowed to send to the
2217  * remote endpoint.  This callback is optional.  Returning
2218  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` will signal the
2219  * entire session failure.
2220  *
2221  * To set this callback to :type:`nghttp2_session_callbacks`, use
2222  * `nghttp2_session_callbacks_set_data_source_read_length_callback2()`.
2223  */
2224 typedef nghttp2_ssize (*nghttp2_data_source_read_length_callback2)(
2225     nghttp2_session *session, uint8_t frame_type, int32_t stream_id,
2226     int32_t session_remote_window_size, int32_t stream_remote_window_size,
2227     uint32_t remote_max_frame_size, void *user_data);
2228 
2229 /**
2230  * @functypedef
2231  *
2232  * Callback function invoked when a frame header is received.  The
2233  * |hd| points to received frame header.
2234  *
2235  * Unlike :type:`nghttp2_on_frame_recv_callback`, this callback will
2236  * also be called when frame header of CONTINUATION frame is received.
2237  *
2238  * If both :type:`nghttp2_on_begin_frame_callback` and
2239  * :type:`nghttp2_on_begin_headers_callback` are set and HEADERS or
2240  * PUSH_PROMISE is received, :type:`nghttp2_on_begin_frame_callback`
2241  * will be called first.
2242  *
2243  * The implementation of this function must return 0 if it succeeds.
2244  * If nonzero value is returned, it is treated as fatal error and
2245  * `nghttp2_session_recv()` and `nghttp2_session_mem_recv2()`
2246  * functions immediately return
2247  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.
2248  *
2249  * To set this callback to :type:`nghttp2_session_callbacks`, use
2250  * `nghttp2_session_callbacks_set_on_begin_frame_callback()`.
2251  */
2252 typedef int (*nghttp2_on_begin_frame_callback)(nghttp2_session *session,
2253                                                const nghttp2_frame_hd *hd,
2254                                                void *user_data);
2255 
2256 /**
2257  * @functypedef
2258  *
2259  * Callback function invoked when chunk of extension frame payload is
2260  * received.  The |hd| points to frame header.  The received
2261  * chunk is |data| of length |len|.
2262  *
2263  * The implementation of this function must return 0 if it succeeds.
2264  *
2265  * To abort processing this extension frame, return
2266  * :enum:`nghttp2_error.NGHTTP2_ERR_CANCEL`.
2267  *
2268  * If fatal error occurred, application should return
2269  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.  In this case,
2270  * `nghttp2_session_recv()` and `nghttp2_session_mem_recv2()`
2271  * functions immediately return
2272  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.  If the other
2273  * values are returned, currently they are treated as
2274  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.
2275  */
2276 typedef int (*nghttp2_on_extension_chunk_recv_callback)(
2277     nghttp2_session *session, const nghttp2_frame_hd *hd, const uint8_t *data,
2278     size_t len, void *user_data);
2279 
2280 /**
2281  * @functypedef
2282  *
2283  * Callback function invoked when library asks the application to
2284  * unpack extension payload from its wire format.  The extension
2285  * payload has been passed to the application using
2286  * :type:`nghttp2_on_extension_chunk_recv_callback`.  The frame header
2287  * is already unpacked by the library and provided as |hd|.
2288  *
2289  * To receive extension frames, the application must tell desired
2290  * extension frame type to the library using
2291  * `nghttp2_option_set_user_recv_extension_type()`.
2292  *
2293  * The implementation of this function may store the pointer to the
2294  * created object as a result of unpacking in |*payload|, and returns
2295  * 0.  The pointer stored in |*payload| is opaque to the library, and
2296  * the library does not own its pointer.  |*payload| is initialized as
2297  * ``NULL``.  The |*payload| is available as ``frame->ext.payload`` in
2298  * :type:`nghttp2_on_frame_recv_callback`.  Therefore if application
2299  * can free that memory inside :type:`nghttp2_on_frame_recv_callback`
2300  * callback.  Of course, application has a liberty not to use
2301  * |*payload|, and do its own mechanism to process extension frames.
2302  *
2303  * To abort processing this extension frame, return
2304  * :enum:`nghttp2_error.NGHTTP2_ERR_CANCEL`.
2305  *
2306  * If fatal error occurred, application should return
2307  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.  In this case,
2308  * `nghttp2_session_recv()` and `nghttp2_session_mem_recv2()`
2309  * functions immediately return
2310  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.  If the other
2311  * values are returned, currently they are treated as
2312  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.
2313  */
2314 typedef int (*nghttp2_unpack_extension_callback)(nghttp2_session *session,
2315                                                  void **payload,
2316                                                  const nghttp2_frame_hd *hd,
2317                                                  void *user_data);
2318 
2319 #ifndef NGHTTP2_NO_SSIZE_T
2320 /**
2321  * @functypedef
2322  *
2323  * .. warning::
2324  *
2325  *   Deprecated.  Use :type:`nghttp2_pack_extension_callback2`
2326  *   instead.
2327  *
2328  * Callback function invoked when library asks the application to pack
2329  * extension payload in its wire format.  The frame header will be
2330  * packed by library.  Application must pack payload only.
2331  * ``frame->ext.payload`` is the object passed to
2332  * `nghttp2_submit_extension()` as payload parameter.  Application
2333  * must pack extension payload to the |buf| of its capacity |len|
2334  * bytes.  The |len| is at least 16KiB.
2335  *
2336  * The implementation of this function should return the number of
2337  * bytes written into |buf| when it succeeds.
2338  *
2339  * To abort processing this extension frame, return
2340  * :enum:`nghttp2_error.NGHTTP2_ERR_CANCEL`, and
2341  * :type:`nghttp2_on_frame_not_send_callback` will be invoked.
2342  *
2343  * If fatal error occurred, application should return
2344  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.  In this case,
2345  * `nghttp2_session_send()` and `nghttp2_session_mem_send()` functions
2346  * immediately return
2347  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.  If the other
2348  * values are returned, currently they are treated as
2349  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.  If the return
2350  * value is strictly larger than |len|, it is treated as
2351  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.
2352  */
2353 typedef ssize_t (*nghttp2_pack_extension_callback)(nghttp2_session *session,
2354                                                    uint8_t *buf, size_t len,
2355                                                    const nghttp2_frame *frame,
2356                                                    void *user_data);
2357 
2358 #endif /* NGHTTP2_NO_SSIZE_T */
2359 
2360 /**
2361  * @functypedef
2362  *
2363  * Callback function invoked when library asks the application to pack
2364  * extension payload in its wire format.  The frame header will be
2365  * packed by library.  Application must pack payload only.
2366  * ``frame->ext.payload`` is the object passed to
2367  * `nghttp2_submit_extension()` as payload parameter.  Application
2368  * must pack extension payload to the |buf| of its capacity |len|
2369  * bytes.  The |len| is at least 16KiB.
2370  *
2371  * The implementation of this function should return the number of
2372  * bytes written into |buf| when it succeeds.
2373  *
2374  * To abort processing this extension frame, return
2375  * :enum:`nghttp2_error.NGHTTP2_ERR_CANCEL`, and
2376  * :type:`nghttp2_on_frame_not_send_callback` will be invoked.
2377  *
2378  * If fatal error occurred, application should return
2379  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.  In this case,
2380  * `nghttp2_session_send()` and `nghttp2_session_mem_send2()`
2381  * functions immediately return
2382  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.  If the other
2383  * values are returned, currently they are treated as
2384  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.  If the return
2385  * value is strictly larger than |len|, it is treated as
2386  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.
2387  */
2388 typedef nghttp2_ssize (*nghttp2_pack_extension_callback2)(
2389     nghttp2_session *session, uint8_t *buf, size_t len,
2390     const nghttp2_frame *frame, void *user_data);
2391 
2392 /**
2393  * @functypedef
2394  *
2395  * .. warning::
2396  *
2397  *   Deprecated.  Use :type:`nghttp2_error_callback2` instead.
2398  *
2399  * Callback function invoked when library provides the error message
2400  * intended for human consumption.  This callback is solely for
2401  * debugging purpose.  The |msg| is typically NULL-terminated string
2402  * of length |len|.  |len| does not include the sentinel NULL
2403  * character.
2404  *
2405  * The format of error message may change between nghttp2 library
2406  * versions.  The application should not depend on the particular
2407  * format.
2408  *
2409  * Normally, application should return 0 from this callback.  If fatal
2410  * error occurred while doing something in this callback, application
2411  * should return :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.
2412  * In this case, library will return immediately with return value
2413  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.  Currently, if
2414  * nonzero value is returned from this callback, they are treated as
2415  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`, but application
2416  * should not rely on this details.
2417  */
2418 typedef int (*nghttp2_error_callback)(nghttp2_session *session, const char *msg,
2419                                       size_t len, void *user_data);
2420 
2421 /**
2422  * @functypedef
2423  *
2424  * Callback function invoked when library provides the error code, and
2425  * message.  This callback is solely for debugging purpose.
2426  * |lib_error_code| is one of error code defined in
2427  * :enum:`nghttp2_error`.  The |msg| is typically NULL-terminated
2428  * string of length |len|, and intended for human consumption.  |len|
2429  * does not include the sentinel NULL character.
2430  *
2431  * The format of error message may change between nghttp2 library
2432  * versions.  The application should not depend on the particular
2433  * format.
2434  *
2435  * Normally, application should return 0 from this callback.  If fatal
2436  * error occurred while doing something in this callback, application
2437  * should return :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.
2438  * In this case, library will return immediately with return value
2439  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`.  Currently, if
2440  * nonzero value is returned from this callback, they are treated as
2441  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`, but application
2442  * should not rely on this details.
2443  */
2444 typedef int (*nghttp2_error_callback2)(nghttp2_session *session,
2445                                        int lib_error_code, const char *msg,
2446                                        size_t len, void *user_data);
2447 
2448 struct nghttp2_session_callbacks;
2449 
2450 /**
2451  * @struct
2452  *
2453  * Callback functions for :type:`nghttp2_session`.  The details of
2454  * this structure are intentionally hidden from the public API.
2455  */
2456 typedef struct nghttp2_session_callbacks nghttp2_session_callbacks;
2457 
2458 /**
2459  * @function
2460  *
2461  * Initializes |*callbacks_ptr| with NULL values.
2462  *
2463  * The initialized object can be used when initializing multiple
2464  * :type:`nghttp2_session` objects.
2465  *
2466  * When the application finished using this object, it can use
2467  * `nghttp2_session_callbacks_del()` to free its memory.
2468  *
2469  * This function returns 0 if it succeeds, or one of the following
2470  * negative error codes:
2471  *
2472  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
2473  *     Out of memory.
2474  */
2475 NGHTTP2_EXTERN int
2476 nghttp2_session_callbacks_new(nghttp2_session_callbacks **callbacks_ptr);
2477 
2478 /**
2479  * @function
2480  *
2481  * Frees any resources allocated for |callbacks|.  If |callbacks| is
2482  * ``NULL``, this function does nothing.
2483  */
2484 NGHTTP2_EXTERN void
2485 nghttp2_session_callbacks_del(nghttp2_session_callbacks *callbacks);
2486 
2487 #ifndef NGHTTP2_NO_SSIZE_T
2488 /**
2489  * @function
2490  *
2491  * .. warning::
2492  *
2493  *   Deprecated.  Use `nghttp2_session_callbacks_set_send_callback2()`
2494  *   with :type:`nghttp2_send_callback2` instead.
2495  *
2496  * Sets callback function invoked when a session wants to send data to
2497  * the remote peer.  This callback is not necessary if the application
2498  * uses solely `nghttp2_session_mem_send()` to serialize data to
2499  * transmit.
2500  */
2501 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_send_callback(
2502     nghttp2_session_callbacks *cbs, nghttp2_send_callback send_callback);
2503 
2504 #endif /* NGHTTP2_NO_SSIZE_T */
2505 
2506 /**
2507  * @function
2508  *
2509  * Sets callback function invoked when a session wants to send data to
2510  * the remote peer.  This callback is not necessary if the application
2511  * uses solely `nghttp2_session_mem_send2()` to serialize data to
2512  * transmit.
2513  */
2514 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_send_callback2(
2515     nghttp2_session_callbacks *cbs, nghttp2_send_callback2 send_callback);
2516 
2517 #ifndef NGHTTP2_NO_SSIZE_T
2518 /**
2519  * @function
2520  *
2521  * .. warning::
2522  *
2523  *   Deprecated.  Use `nghttp2_session_callbacks_set_recv_callback2()`
2524  *   with :type:`nghttp2_recv_callback2` instead.
2525  *
2526  * Sets callback function invoked when the a session wants to receive
2527  * data from the remote peer.  This callback is not necessary if the
2528  * application uses solely `nghttp2_session_mem_recv()` to process
2529  * received data.
2530  */
2531 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_recv_callback(
2532     nghttp2_session_callbacks *cbs, nghttp2_recv_callback recv_callback);
2533 
2534 #endif /* NGHTTP2_NO_SSIZE_T */
2535 
2536 /**
2537  * @function
2538  *
2539  * Sets callback function invoked when the a session wants to receive
2540  * data from the remote peer.  This callback is not necessary if the
2541  * application uses solely `nghttp2_session_mem_recv2()` to process
2542  * received data.
2543  */
2544 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_recv_callback2(
2545     nghttp2_session_callbacks *cbs, nghttp2_recv_callback2 recv_callback);
2546 
2547 /**
2548  * @function
2549  *
2550  * Sets callback function invoked by `nghttp2_session_recv()` and
2551  * `nghttp2_session_mem_recv2()` when a frame is received.
2552  */
2553 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_frame_recv_callback(
2554     nghttp2_session_callbacks *cbs,
2555     nghttp2_on_frame_recv_callback on_frame_recv_callback);
2556 
2557 /**
2558  * @function
2559  *
2560  * Sets callback function invoked by `nghttp2_session_recv()` and
2561  * `nghttp2_session_mem_recv2()` when an invalid non-DATA frame is
2562  * received.
2563  */
2564 NGHTTP2_EXTERN void
2565 nghttp2_session_callbacks_set_on_invalid_frame_recv_callback(
2566     nghttp2_session_callbacks *cbs,
2567     nghttp2_on_invalid_frame_recv_callback on_invalid_frame_recv_callback);
2568 
2569 /**
2570  * @function
2571  *
2572  * Sets callback function invoked when a chunk of data in DATA frame
2573  * is received.
2574  */
2575 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_data_chunk_recv_callback(
2576     nghttp2_session_callbacks *cbs,
2577     nghttp2_on_data_chunk_recv_callback on_data_chunk_recv_callback);
2578 
2579 /**
2580  * @function
2581  *
2582  * Sets callback function invoked before a non-DATA frame is sent.
2583  */
2584 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_before_frame_send_callback(
2585     nghttp2_session_callbacks *cbs,
2586     nghttp2_before_frame_send_callback before_frame_send_callback);
2587 
2588 /**
2589  * @function
2590  *
2591  * Sets callback function invoked after a frame is sent.
2592  */
2593 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_frame_send_callback(
2594     nghttp2_session_callbacks *cbs,
2595     nghttp2_on_frame_send_callback on_frame_send_callback);
2596 
2597 /**
2598  * @function
2599  *
2600  * Sets callback function invoked when a non-DATA frame is not sent
2601  * because of an error.
2602  */
2603 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_frame_not_send_callback(
2604     nghttp2_session_callbacks *cbs,
2605     nghttp2_on_frame_not_send_callback on_frame_not_send_callback);
2606 
2607 /**
2608  * @function
2609  *
2610  * Sets callback function invoked when the stream is closed.
2611  */
2612 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_stream_close_callback(
2613     nghttp2_session_callbacks *cbs,
2614     nghttp2_on_stream_close_callback on_stream_close_callback);
2615 
2616 /**
2617  * @function
2618  *
2619  * Sets callback function invoked when the reception of header block
2620  * in HEADERS or PUSH_PROMISE is started.
2621  */
2622 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_begin_headers_callback(
2623     nghttp2_session_callbacks *cbs,
2624     nghttp2_on_begin_headers_callback on_begin_headers_callback);
2625 
2626 /**
2627  * @function
2628  *
2629  * Sets callback function invoked when a header name/value pair is
2630  * received.  If both
2631  * `nghttp2_session_callbacks_set_on_header_callback()` and
2632  * `nghttp2_session_callbacks_set_on_header_callback2()` are used to
2633  * set callbacks, the latter has the precedence.
2634  */
2635 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_header_callback(
2636     nghttp2_session_callbacks *cbs,
2637     nghttp2_on_header_callback on_header_callback);
2638 
2639 /**
2640  * @function
2641  *
2642  * Sets callback function invoked when a header name/value pair is
2643  * received.
2644  */
2645 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_header_callback2(
2646     nghttp2_session_callbacks *cbs,
2647     nghttp2_on_header_callback2 on_header_callback2);
2648 
2649 /**
2650  * @function
2651  *
2652  * Sets callback function invoked when a invalid header name/value
2653  * pair is received.  If both
2654  * `nghttp2_session_callbacks_set_on_invalid_header_callback()` and
2655  * `nghttp2_session_callbacks_set_on_invalid_header_callback2()` are
2656  * used to set callbacks, the latter takes the precedence.
2657  */
2658 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_invalid_header_callback(
2659     nghttp2_session_callbacks *cbs,
2660     nghttp2_on_invalid_header_callback on_invalid_header_callback);
2661 
2662 /**
2663  * @function
2664  *
2665  * Sets callback function invoked when a invalid header name/value
2666  * pair is received.
2667  */
2668 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_invalid_header_callback2(
2669     nghttp2_session_callbacks *cbs,
2670     nghttp2_on_invalid_header_callback2 on_invalid_header_callback2);
2671 
2672 #ifndef NGHTTP2_NO_SSIZE_T
2673 /**
2674  * @function
2675  *
2676  * .. warning::
2677  *
2678  *   Deprecated.  Use
2679  *   `nghttp2_session_callbacks_set_select_padding_callback2()` with
2680  *   :type:`nghttp2_select_padding_callback2` instead.
2681  *
2682  * Sets callback function invoked when the library asks application
2683  * how many padding bytes are required for the transmission of the
2684  * given frame.
2685  */
2686 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_select_padding_callback(
2687     nghttp2_session_callbacks *cbs,
2688     nghttp2_select_padding_callback select_padding_callback);
2689 
2690 #endif /* NGHTTP2_NO_SSIZE_T */
2691 
2692 /**
2693  * @function
2694  *
2695  * Sets callback function invoked when the library asks application
2696  * how many padding bytes are required for the transmission of the
2697  * given frame.
2698  */
2699 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_select_padding_callback2(
2700     nghttp2_session_callbacks *cbs,
2701     nghttp2_select_padding_callback2 select_padding_callback);
2702 
2703 #ifndef NGHTTP2_NO_SSIZE_T
2704 /**
2705  * @function
2706  *
2707  * .. warning::
2708  *
2709  *   Deprecated.  Use
2710  *   `nghttp2_session_callbacks_set_data_source_read_length_callback2()`
2711  *   with :type:`nghttp2_data_source_read_length_callback2` instead.
2712  *
2713  * Sets callback function determine the length allowed in
2714  * :type:`nghttp2_data_source_read_callback`.
2715  */
2716 NGHTTP2_EXTERN void
2717 nghttp2_session_callbacks_set_data_source_read_length_callback(
2718     nghttp2_session_callbacks *cbs,
2719     nghttp2_data_source_read_length_callback data_source_read_length_callback);
2720 
2721 #endif /* NGHTTP2_NO_SSIZE_T */
2722 
2723 /**
2724  * @function
2725  *
2726  * Sets callback function determine the length allowed in
2727  * :type:`nghttp2_data_source_read_callback2`.
2728  */
2729 NGHTTP2_EXTERN void
2730 nghttp2_session_callbacks_set_data_source_read_length_callback2(
2731     nghttp2_session_callbacks *cbs,
2732     nghttp2_data_source_read_length_callback2 data_source_read_length_callback);
2733 
2734 /**
2735  * @function
2736  *
2737  * Sets callback function invoked when a frame header is received.
2738  */
2739 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_begin_frame_callback(
2740     nghttp2_session_callbacks *cbs,
2741     nghttp2_on_begin_frame_callback on_begin_frame_callback);
2742 
2743 /**
2744  * @function
2745  *
2746  * Sets callback function invoked when
2747  * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_COPY` is used in
2748  * :type:`nghttp2_data_source_read_callback2` to avoid data copy.
2749  */
2750 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_send_data_callback(
2751     nghttp2_session_callbacks *cbs,
2752     nghttp2_send_data_callback send_data_callback);
2753 
2754 #ifndef NGHTTP2_NO_SSIZE_T
2755 /**
2756  * @function
2757  *
2758  * .. warning::
2759  *
2760  *   Deprecated.  Use
2761  *   `nghttp2_session_callbacks_set_pack_extension_callback2()` with
2762  *   :type:`nghttp2_pack_extension_callback2` instead.
2763  *
2764  * Sets callback function invoked when the library asks the
2765  * application to pack extension frame payload in wire format.
2766  */
2767 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_pack_extension_callback(
2768     nghttp2_session_callbacks *cbs,
2769     nghttp2_pack_extension_callback pack_extension_callback);
2770 
2771 #endif /* NGHTTP2_NO_SSIZE_T */
2772 
2773 /**
2774  * @function
2775  *
2776  * Sets callback function invoked when the library asks the
2777  * application to pack extension frame payload in wire format.
2778  */
2779 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_pack_extension_callback2(
2780     nghttp2_session_callbacks *cbs,
2781     nghttp2_pack_extension_callback2 pack_extension_callback);
2782 
2783 /**
2784  * @function
2785  *
2786  * Sets callback function invoked when the library asks the
2787  * application to unpack extension frame payload from wire format.
2788  */
2789 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_unpack_extension_callback(
2790     nghttp2_session_callbacks *cbs,
2791     nghttp2_unpack_extension_callback unpack_extension_callback);
2792 
2793 /**
2794  * @function
2795  *
2796  * Sets callback function invoked when chunk of extension frame
2797  * payload is received.
2798  */
2799 NGHTTP2_EXTERN void
2800 nghttp2_session_callbacks_set_on_extension_chunk_recv_callback(
2801     nghttp2_session_callbacks *cbs,
2802     nghttp2_on_extension_chunk_recv_callback on_extension_chunk_recv_callback);
2803 
2804 /**
2805  * @function
2806  *
2807  * .. warning::
2808  *
2809  *   Deprecated.  Use
2810  *   `nghttp2_session_callbacks_set_error_callback2()` with
2811  *   :type:`nghttp2_error_callback2` instead.
2812  *
2813  * Sets callback function invoked when library tells error message to
2814  * the application.
2815  *
2816  * If both :type:`nghttp2_error_callback` and
2817  * :type:`nghttp2_error_callback2` are set, the latter takes
2818  * precedence.
2819  */
2820 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_error_callback(
2821     nghttp2_session_callbacks *cbs, nghttp2_error_callback error_callback);
2822 
2823 /**
2824  * @function
2825  *
2826  * Sets callback function invoked when library tells error code, and
2827  * message to the application.
2828  *
2829  * If both :type:`nghttp2_error_callback` and
2830  * :type:`nghttp2_error_callback2` are set, the latter takes
2831  * precedence.
2832  */
2833 NGHTTP2_EXTERN void nghttp2_session_callbacks_set_error_callback2(
2834     nghttp2_session_callbacks *cbs, nghttp2_error_callback2 error_callback2);
2835 
2836 /**
2837  * @functypedef
2838  *
2839  * Custom memory allocator to replace malloc().  The |mem_user_data|
2840  * is the mem_user_data member of :type:`nghttp2_mem` structure.
2841  */
2842 typedef void *(*nghttp2_malloc)(size_t size, void *mem_user_data);
2843 
2844 /**
2845  * @functypedef
2846  *
2847  * Custom memory allocator to replace free().  The |mem_user_data| is
2848  * the mem_user_data member of :type:`nghttp2_mem` structure.
2849  */
2850 typedef void (*nghttp2_free)(void *ptr, void *mem_user_data);
2851 
2852 /**
2853  * @functypedef
2854  *
2855  * Custom memory allocator to replace calloc().  The |mem_user_data|
2856  * is the mem_user_data member of :type:`nghttp2_mem` structure.
2857  */
2858 typedef void *(*nghttp2_calloc)(size_t nmemb, size_t size, void *mem_user_data);
2859 
2860 /**
2861  * @functypedef
2862  *
2863  * Custom memory allocator to replace realloc().  The |mem_user_data|
2864  * is the mem_user_data member of :type:`nghttp2_mem` structure.
2865  */
2866 typedef void *(*nghttp2_realloc)(void *ptr, size_t size, void *mem_user_data);
2867 
2868 /**
2869  * @struct
2870  *
2871  * Custom memory allocator functions and user defined pointer.  The
2872  * |mem_user_data| member is passed to each allocator function.  This
2873  * can be used, for example, to achieve per-session memory pool.
2874  *
2875  * In the following example code, ``my_malloc``, ``my_free``,
2876  * ``my_calloc`` and ``my_realloc`` are the replacement of the
2877  * standard allocators ``malloc``, ``free``, ``calloc`` and
2878  * ``realloc`` respectively::
2879  *
2880  *     void *my_malloc_cb(size_t size, void *mem_user_data) {
2881  *       return my_malloc(size);
2882  *     }
2883  *
2884  *     void my_free_cb(void *ptr, void *mem_user_data) { my_free(ptr); }
2885  *
2886  *     void *my_calloc_cb(size_t nmemb, size_t size, void *mem_user_data) {
2887  *       return my_calloc(nmemb, size);
2888  *     }
2889  *
2890  *     void *my_realloc_cb(void *ptr, size_t size, void *mem_user_data) {
2891  *       return my_realloc(ptr, size);
2892  *     }
2893  *
2894  *     void session_new() {
2895  *       nghttp2_session *session;
2896  *       nghttp2_session_callbacks *callbacks;
2897  *       nghttp2_mem mem = {NULL, my_malloc_cb, my_free_cb, my_calloc_cb,
2898  *                          my_realloc_cb};
2899  *
2900  *       ...
2901  *
2902  *       nghttp2_session_client_new3(&session, callbacks, NULL, NULL, &mem);
2903  *
2904  *       ...
2905  *     }
2906  */
2907 typedef struct {
2908   /**
2909    * An arbitrary user supplied data.  This is passed to each
2910    * allocator function.
2911    */
2912   void *mem_user_data;
2913   /**
2914    * Custom allocator function to replace malloc().
2915    */
2916   nghttp2_malloc malloc;
2917   /**
2918    * Custom allocator function to replace free().
2919    */
2920   nghttp2_free free;
2921   /**
2922    * Custom allocator function to replace calloc().
2923    */
2924   nghttp2_calloc calloc;
2925   /**
2926    * Custom allocator function to replace realloc().
2927    */
2928   nghttp2_realloc realloc;
2929 } nghttp2_mem;
2930 
2931 struct nghttp2_option;
2932 
2933 /**
2934  * @struct
2935  *
2936  * Configuration options for :type:`nghttp2_session`.  The details of
2937  * this structure are intentionally hidden from the public API.
2938  */
2939 typedef struct nghttp2_option nghttp2_option;
2940 
2941 /**
2942  * @function
2943  *
2944  * Initializes |*option_ptr| with default values.
2945  *
2946  * When the application finished using this object, it can use
2947  * `nghttp2_option_del()` to free its memory.
2948  *
2949  * This function returns 0 if it succeeds, or one of the following
2950  * negative error codes:
2951  *
2952  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
2953  *     Out of memory.
2954  */
2955 NGHTTP2_EXTERN int nghttp2_option_new(nghttp2_option **option_ptr);
2956 
2957 /**
2958  * @function
2959  *
2960  * Frees any resources allocated for |option|.  If |option| is
2961  * ``NULL``, this function does nothing.
2962  */
2963 NGHTTP2_EXTERN void nghttp2_option_del(nghttp2_option *option);
2964 
2965 /**
2966  * @function
2967  *
2968  * This option prevents the library from sending WINDOW_UPDATE for a
2969  * connection automatically.  If this option is set to nonzero, the
2970  * library won't send WINDOW_UPDATE for DATA until application calls
2971  * `nghttp2_session_consume()` to indicate the consumed amount of
2972  * data.  Don't use `nghttp2_submit_window_update()` for this purpose.
2973  * By default, this option is set to zero.
2974  */
2975 NGHTTP2_EXTERN void
2976 nghttp2_option_set_no_auto_window_update(nghttp2_option *option, int val);
2977 
2978 /**
2979  * @function
2980  *
2981  * This option sets the SETTINGS_MAX_CONCURRENT_STREAMS value of
2982  * remote endpoint as if it is received in SETTINGS frame.  Without
2983  * specifying this option, the maximum number of outgoing concurrent
2984  * streams is initially limited to 100 to avoid issues when the local
2985  * endpoint submits lots of requests before receiving initial SETTINGS
2986  * frame from the remote endpoint, since sending them at once to the
2987  * remote endpoint could lead to rejection of some of the requests.
2988  * This value will be overwritten when the local endpoint receives
2989  * initial SETTINGS frame from the remote endpoint, either to the
2990  * value advertised in SETTINGS_MAX_CONCURRENT_STREAMS or to the
2991  * default value (unlimited) if none was advertised.
2992  */
2993 NGHTTP2_EXTERN void
2994 nghttp2_option_set_peer_max_concurrent_streams(nghttp2_option *option,
2995                                                uint32_t val);
2996 
2997 /**
2998  * @function
2999  *
3000  * By default, nghttp2 library, if configured as server, requires
3001  * first 24 bytes of client magic byte string (MAGIC).  In most cases,
3002  * this will simplify the implementation of server.  But sometimes
3003  * server may want to detect the application protocol based on first
3004  * few bytes on clear text communication.
3005  *
3006  * If this option is used with nonzero |val|, nghttp2 library does not
3007  * handle MAGIC.  It still checks following SETTINGS frame.  This
3008  * means that applications should deal with MAGIC by themselves.
3009  *
3010  * If this option is not used or used with zero value, if MAGIC does
3011  * not match :macro:`NGHTTP2_CLIENT_MAGIC`, `nghttp2_session_recv()`
3012  * and `nghttp2_session_mem_recv2()` will return error
3013  * :enum:`nghttp2_error.NGHTTP2_ERR_BAD_CLIENT_MAGIC`, which is fatal
3014  * error.
3015  */
3016 NGHTTP2_EXTERN void
3017 nghttp2_option_set_no_recv_client_magic(nghttp2_option *option, int val);
3018 
3019 /**
3020  * @function
3021  *
3022  * By default, nghttp2 library enforces subset of HTTP Messaging rules
3023  * described in `HTTP/2 specification, section 8
3024  * <https://tools.ietf.org/html/rfc7540#section-8>`_.  See
3025  * :ref:`http-messaging` section for details.  For those applications
3026  * who use nghttp2 library as non-HTTP use, give nonzero to |val| to
3027  * disable this enforcement.  Please note that disabling this feature
3028  * does not change the fundamental client and server model of HTTP.
3029  * That is, even if the validation is disabled, only client can send
3030  * requests.
3031  */
3032 NGHTTP2_EXTERN void nghttp2_option_set_no_http_messaging(nghttp2_option *option,
3033                                                          int val);
3034 
3035 /**
3036  * @function
3037  *
3038  * RFC 7540 does not enforce any limit on the number of incoming
3039  * reserved streams (in RFC 7540 terms, streams in reserved (remote)
3040  * state).  This only affects client side, since only server can push
3041  * streams.  Malicious server can push arbitrary number of streams,
3042  * and make client's memory exhausted.  This option can set the
3043  * maximum number of such incoming streams to avoid possible memory
3044  * exhaustion.  If this option is set, and pushed streams are
3045  * automatically closed on reception, without calling user provided
3046  * callback, if they exceed the given limit.  The default value is
3047  * 200.  If session is configured as server side, this option has no
3048  * effect.  Server can control the number of streams to push.
3049  */
3050 NGHTTP2_EXTERN void
3051 nghttp2_option_set_max_reserved_remote_streams(nghttp2_option *option,
3052                                                uint32_t val);
3053 
3054 /**
3055  * @function
3056  *
3057  * Sets extension frame type the application is willing to handle with
3058  * user defined callbacks (see
3059  * :type:`nghttp2_on_extension_chunk_recv_callback` and
3060  * :type:`nghttp2_unpack_extension_callback`).  The |type| is
3061  * extension frame type, and must be strictly greater than 0x9.
3062  * Otherwise, this function does nothing.  The application can call
3063  * this function multiple times to set more than one frame type to
3064  * receive.  The application does not have to call this function if it
3065  * just sends extension frames.
3066  */
3067 NGHTTP2_EXTERN void
3068 nghttp2_option_set_user_recv_extension_type(nghttp2_option *option,
3069                                             uint8_t type);
3070 
3071 /**
3072  * @function
3073  *
3074  * Sets extension frame type the application is willing to receive
3075  * using builtin handler.  The |type| is the extension frame type to
3076  * receive, and must be strictly greater than 0x9.  Otherwise, this
3077  * function does nothing.  The application can call this function
3078  * multiple times to set more than one frame type to receive.  The
3079  * application does not have to call this function if it just sends
3080  * extension frames.
3081  *
3082  * If same frame type is passed to both
3083  * `nghttp2_option_set_builtin_recv_extension_type()` and
3084  * `nghttp2_option_set_user_recv_extension_type()`, the latter takes
3085  * precedence.
3086  */
3087 NGHTTP2_EXTERN void
3088 nghttp2_option_set_builtin_recv_extension_type(nghttp2_option *option,
3089                                                uint8_t type);
3090 
3091 /**
3092  * @function
3093  *
3094  * This option prevents the library from sending PING frame with ACK
3095  * flag set automatically when PING frame without ACK flag set is
3096  * received.  If this option is set to nonzero, the library won't send
3097  * PING frame with ACK flag set in the response for incoming PING
3098  * frame.  The application can send PING frame with ACK flag set using
3099  * `nghttp2_submit_ping()` with :enum:`nghttp2_flag.NGHTTP2_FLAG_ACK`
3100  * as flags parameter.
3101  */
3102 NGHTTP2_EXTERN void nghttp2_option_set_no_auto_ping_ack(nghttp2_option *option,
3103                                                         int val);
3104 
3105 /**
3106  * @function
3107  *
3108  * This option sets the maximum length of header block (a set of
3109  * header fields per one HEADERS frame) to send.  The length of a
3110  * given set of header fields is calculated using
3111  * `nghttp2_hd_deflate_bound()`.  The default value is 64KiB.  If
3112  * application attempts to send header fields larger than this limit,
3113  * the transmission of the frame fails with error code
3114  * :enum:`nghttp2_error.NGHTTP2_ERR_FRAME_SIZE_ERROR`.
3115  */
3116 NGHTTP2_EXTERN void
3117 nghttp2_option_set_max_send_header_block_length(nghttp2_option *option,
3118                                                 size_t val);
3119 
3120 /**
3121  * @function
3122  *
3123  * This option sets the maximum dynamic table size for deflating
3124  * header fields.  The default value is 4KiB.  In HTTP/2, receiver of
3125  * deflated header block can specify maximum dynamic table size.  The
3126  * actual maximum size is the minimum of the size receiver specified
3127  * and this option value.
3128  */
3129 NGHTTP2_EXTERN void
3130 nghttp2_option_set_max_deflate_dynamic_table_size(nghttp2_option *option,
3131                                                   size_t val);
3132 
3133 /**
3134  * @function
3135  *
3136  * This option prevents the library from retaining closed streams to
3137  * maintain the priority tree.  If this option is set to nonzero,
3138  * applications can discard closed stream completely to save memory.
3139  *
3140  * If
3141  * :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES`
3142  * of value of 1 is submitted via `nghttp2_submit_settings()`, any
3143  * closed streams are not retained regardless of this option.
3144  */
3145 NGHTTP2_EXTERN void nghttp2_option_set_no_closed_streams(nghttp2_option *option,
3146                                                          int val);
3147 
3148 /**
3149  * @function
3150  *
3151  * This function sets the maximum number of outgoing SETTINGS ACK and
3152  * PING ACK frames retained in :type:`nghttp2_session` object.  If
3153  * more than those frames are retained, the peer is considered to be
3154  * misbehaving and session will be closed.  The default value is 1000.
3155  */
3156 NGHTTP2_EXTERN void nghttp2_option_set_max_outbound_ack(nghttp2_option *option,
3157                                                         size_t val);
3158 
3159 /**
3160  * @function
3161  *
3162  * This function sets the maximum number of SETTINGS entries per
3163  * SETTINGS frame that will be accepted. If more than those entries
3164  * are received, the peer is considered to be misbehaving and session
3165  * will be closed. The default value is 32.
3166  */
3167 NGHTTP2_EXTERN void nghttp2_option_set_max_settings(nghttp2_option *option,
3168                                                     size_t val);
3169 
3170 /**
3171  * @function
3172  *
3173  * This option, if set to nonzero, allows server to fallback to
3174  * :rfc:`7540` priorities if SETTINGS_NO_RFC7540_PRIORITIES was not
3175  * received from client, and server submitted
3176  * :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES`
3177  * = 1 via `nghttp2_submit_settings()`.  Most of the advanced
3178  * functionality for RFC 7540 priorities are still disabled.  This
3179  * fallback only enables the minimal feature set of RFC 7540
3180  * priorities to deal with priority signaling from client.
3181  *
3182  * Client session ignores this option.
3183  */
3184 NGHTTP2_EXTERN void
3185 nghttp2_option_set_server_fallback_rfc7540_priorities(nghttp2_option *option,
3186                                                       int val);
3187 
3188 /**
3189  * @function
3190  *
3191  * This option, if set to nonzero, turns off RFC 9113 leading and
3192  * trailing white spaces validation against HTTP field value.  Some
3193  * important fields, such as HTTP/2 pseudo header fields, are
3194  * validated more strictly and this option does not apply to them.
3195  */
3196 NGHTTP2_EXTERN void
3197 nghttp2_option_set_no_rfc9113_leading_and_trailing_ws_validation(
3198     nghttp2_option *option, int val);
3199 
3200 /**
3201  * @function
3202  *
3203  * This function sets the rate limit for the incoming stream reset
3204  * (RST_STREAM frame).  It is server use only.  It is a token-bucket
3205  * based rate limiter.  |burst| specifies the number of tokens that is
3206  * initially available.  The maximum number of tokens is capped to
3207  * this value.  |rate| specifies the number of tokens that are
3208  * regenerated per second.  An incoming RST_STREAM consumes one token.
3209  * If there is no token available, GOAWAY is sent to tear down the
3210  * connection.  |burst| and |rate| default to 1000 and 33
3211  * respectively.
3212  */
3213 NGHTTP2_EXTERN void
3214 nghttp2_option_set_stream_reset_rate_limit(nghttp2_option *option,
3215                                            uint64_t burst, uint64_t rate);
3216 
3217 /**
3218  * @function
3219  *
3220  * This function sets the maximum number of CONTINUATION frames
3221  * following an incoming HEADER frame.  If more than those frames are
3222  * received, the remote endpoint is considered to be misbehaving and
3223  * session will be closed.  The default value is 8.
3224  */
3225 NGHTTP2_EXTERN void nghttp2_option_set_max_continuations(nghttp2_option *option,
3226                                                          size_t val);
3227 
3228 /**
3229  * @function
3230  *
3231  * Initializes |*session_ptr| for client use.  The all members of
3232  * |callbacks| are copied to |*session_ptr|.  Therefore |*session_ptr|
3233  * does not store |callbacks|.  The |user_data| is an arbitrary user
3234  * supplied data, which will be passed to the callback functions.
3235  *
3236  * The :type:`nghttp2_send_callback2` must be specified.  If the
3237  * application code uses `nghttp2_session_recv()`, the
3238  * :type:`nghttp2_recv_callback` must be specified.  The other members
3239  * of |callbacks| can be ``NULL``.
3240  *
3241  * If this function fails, |*session_ptr| is left untouched.
3242  *
3243  * This function returns 0 if it succeeds, or one of the following
3244  * negative error codes:
3245  *
3246  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
3247  *     Out of memory.
3248  */
3249 NGHTTP2_EXTERN int
3250 nghttp2_session_client_new(nghttp2_session **session_ptr,
3251                            const nghttp2_session_callbacks *callbacks,
3252                            void *user_data);
3253 
3254 /**
3255  * @function
3256  *
3257  * Initializes |*session_ptr| for server use.  The all members of
3258  * |callbacks| are copied to |*session_ptr|. Therefore |*session_ptr|
3259  * does not store |callbacks|.  The |user_data| is an arbitrary user
3260  * supplied data, which will be passed to the callback functions.
3261  *
3262  * The :type:`nghttp2_send_callback2` must be specified.  If the
3263  * application code uses `nghttp2_session_recv()`, the
3264  * :type:`nghttp2_recv_callback` must be specified.  The other members
3265  * of |callbacks| can be ``NULL``.
3266  *
3267  * If this function fails, |*session_ptr| is left untouched.
3268  *
3269  * This function returns 0 if it succeeds, or one of the following
3270  * negative error codes:
3271  *
3272  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
3273  *     Out of memory.
3274  */
3275 NGHTTP2_EXTERN int
3276 nghttp2_session_server_new(nghttp2_session **session_ptr,
3277                            const nghttp2_session_callbacks *callbacks,
3278                            void *user_data);
3279 
3280 /**
3281  * @function
3282  *
3283  * Like `nghttp2_session_client_new()`, but with additional options
3284  * specified in the |option|.
3285  *
3286  * The |option| can be ``NULL`` and the call is equivalent to
3287  * `nghttp2_session_client_new()`.
3288  *
3289  * This function does not take ownership |option|.  The application is
3290  * responsible for freeing |option| if it finishes using the object.
3291  *
3292  * The library code does not refer to |option| after this function
3293  * returns.
3294  *
3295  * This function returns 0 if it succeeds, or one of the following
3296  * negative error codes:
3297  *
3298  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
3299  *     Out of memory.
3300  */
3301 NGHTTP2_EXTERN int
3302 nghttp2_session_client_new2(nghttp2_session **session_ptr,
3303                             const nghttp2_session_callbacks *callbacks,
3304                             void *user_data, const nghttp2_option *option);
3305 
3306 /**
3307  * @function
3308  *
3309  * Like `nghttp2_session_server_new()`, but with additional options
3310  * specified in the |option|.
3311  *
3312  * The |option| can be ``NULL`` and the call is equivalent to
3313  * `nghttp2_session_server_new()`.
3314  *
3315  * This function does not take ownership |option|.  The application is
3316  * responsible for freeing |option| if it finishes using the object.
3317  *
3318  * The library code does not refer to |option| after this function
3319  * returns.
3320  *
3321  * This function returns 0 if it succeeds, or one of the following
3322  * negative error codes:
3323  *
3324  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
3325  *     Out of memory.
3326  */
3327 NGHTTP2_EXTERN int
3328 nghttp2_session_server_new2(nghttp2_session **session_ptr,
3329                             const nghttp2_session_callbacks *callbacks,
3330                             void *user_data, const nghttp2_option *option);
3331 
3332 /**
3333  * @function
3334  *
3335  * Like `nghttp2_session_client_new2()`, but with additional custom
3336  * memory allocator specified in the |mem|.
3337  *
3338  * The |mem| can be ``NULL`` and the call is equivalent to
3339  * `nghttp2_session_client_new2()`.
3340  *
3341  * This function does not take ownership |mem|.  The application is
3342  * responsible for freeing |mem|.
3343  *
3344  * The library code does not refer to |mem| pointer after this
3345  * function returns, so the application can safely free it.
3346  *
3347  * This function returns 0 if it succeeds, or one of the following
3348  * negative error codes:
3349  *
3350  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
3351  *     Out of memory.
3352  */
3353 NGHTTP2_EXTERN int nghttp2_session_client_new3(
3354     nghttp2_session **session_ptr, const nghttp2_session_callbacks *callbacks,
3355     void *user_data, const nghttp2_option *option, nghttp2_mem *mem);
3356 
3357 /**
3358  * @function
3359  *
3360  * Like `nghttp2_session_server_new2()`, but with additional custom
3361  * memory allocator specified in the |mem|.
3362  *
3363  * The |mem| can be ``NULL`` and the call is equivalent to
3364  * `nghttp2_session_server_new2()`.
3365  *
3366  * This function does not take ownership |mem|.  The application is
3367  * responsible for freeing |mem|.
3368  *
3369  * The library code does not refer to |mem| pointer after this
3370  * function returns, so the application can safely free it.
3371  *
3372  * This function returns 0 if it succeeds, or one of the following
3373  * negative error codes:
3374  *
3375  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
3376  *     Out of memory.
3377  */
3378 NGHTTP2_EXTERN int nghttp2_session_server_new3(
3379     nghttp2_session **session_ptr, const nghttp2_session_callbacks *callbacks,
3380     void *user_data, const nghttp2_option *option, nghttp2_mem *mem);
3381 
3382 /**
3383  * @function
3384  *
3385  * Frees any resources allocated for |session|.  If |session| is
3386  * ``NULL``, this function does nothing.
3387  */
3388 NGHTTP2_EXTERN void nghttp2_session_del(nghttp2_session *session);
3389 
3390 /**
3391  * @function
3392  *
3393  * Sends pending frames to the remote peer.
3394  *
3395  * This function retrieves the highest prioritized frame from the
3396  * outbound queue and sends it to the remote peer.  It does this as
3397  * many times as possible until the user callback
3398  * :type:`nghttp2_send_callback2` returns
3399  * :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`, the outbound queue
3400  * becomes empty or flow control is triggered (remote window size
3401  * becomes depleted or maximum number of concurrent streams is
3402  * reached).  This function calls several callback functions which are
3403  * passed when initializing the |session|.  Here is the simple time
3404  * chart which tells when each callback is invoked:
3405  *
3406  * 1. Get the next frame to send from outbound queue.
3407  *
3408  * 2. Prepare transmission of the frame.
3409  *
3410  * 3. If the control frame cannot be sent because some preconditions
3411  *    are not met (e.g., request HEADERS cannot be sent after GOAWAY),
3412  *    :type:`nghttp2_on_frame_not_send_callback` is invoked.  Abort
3413  *    the following steps.
3414  *
3415  * 4. If the frame is HEADERS, PUSH_PROMISE or DATA,
3416  *    :type:`nghttp2_select_padding_callback` is invoked.
3417  *
3418  * 5. If the frame is request HEADERS, the stream is opened here.
3419  *
3420  * 6. :type:`nghttp2_before_frame_send_callback` is invoked.
3421  *
3422  * 7. If :enum:`nghttp2_error.NGHTTP2_ERR_CANCEL` is returned from
3423  *    :type:`nghttp2_before_frame_send_callback`, the current frame
3424  *    transmission is canceled, and
3425  *    :type:`nghttp2_on_frame_not_send_callback` is invoked.  Abort
3426  *    the following steps.
3427  *
3428  * 8. :type:`nghttp2_send_callback2` is invoked one or more times to
3429  *    send the frame.
3430  *
3431  * 9. :type:`nghttp2_on_frame_send_callback` is invoked.
3432  *
3433  * 10. If the transmission of the frame triggers closure of the
3434  *     stream, the stream is closed and
3435  *     :type:`nghttp2_on_stream_close_callback` is invoked.
3436  *
3437  * This function returns 0 if it succeeds, or one of the following
3438  * negative error codes:
3439  *
3440  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
3441  *     Out of memory.
3442  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`
3443  *     The callback function failed.
3444  */
3445 NGHTTP2_EXTERN int nghttp2_session_send(nghttp2_session *session);
3446 
3447 #ifndef NGHTTP2_NO_SSIZE_T
3448 /**
3449  * @function
3450  *
3451  * .. warning::
3452  *
3453  *   Deprecated.  Use `nghttp2_session_mem_send2()` instead.
3454  *
3455  * Returns the serialized data to send.
3456  *
3457  * This function behaves like `nghttp2_session_send()` except that it
3458  * does not use :type:`nghttp2_send_callback` to transmit data.
3459  * Instead, it assigns the pointer to the serialized data to the
3460  * |*data_ptr| and returns its length.  The other callbacks are called
3461  * in the same way as they are in `nghttp2_session_send()`.
3462  *
3463  * If no data is available to send, this function returns 0.
3464  *
3465  * This function may not return all serialized data in one invocation.
3466  * To get all data, call this function repeatedly until it returns 0
3467  * or one of negative error codes.
3468  *
3469  * The assigned |*data_ptr| is valid until the next call of
3470  * `nghttp2_session_mem_send()` or `nghttp2_session_send()`.
3471  *
3472  * The caller must send all data before sending the next chunk of
3473  * data.
3474  *
3475  * This function returns the length of the data pointed by the
3476  * |*data_ptr| if it succeeds, or one of the following negative error
3477  * codes:
3478  *
3479  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
3480  *     Out of memory.
3481  *
3482  * .. note::
3483  *
3484  *   This function may produce very small byte string.  If that is the
3485  *   case, and application disables Nagle algorithm (``TCP_NODELAY``),
3486  *   then writing this small chunk leads to very small packet, and it
3487  *   is very inefficient.  An application should be responsible to
3488  *   buffer up small chunks of data as necessary to avoid this
3489  *   situation.
3490  */
3491 NGHTTP2_EXTERN ssize_t nghttp2_session_mem_send(nghttp2_session *session,
3492                                                 const uint8_t **data_ptr);
3493 
3494 #endif /* NGHTTP2_NO_SSIZE_T */
3495 
3496 /**
3497  * @function
3498  *
3499  * Returns the serialized data to send.
3500  *
3501  * This function behaves like `nghttp2_session_send()` except that it
3502  * does not use :type:`nghttp2_send_callback2` to transmit data.
3503  * Instead, it assigns the pointer to the serialized data to the
3504  * |*data_ptr| and returns its length.  The other callbacks are called
3505  * in the same way as they are in `nghttp2_session_send()`.
3506  *
3507  * If no data is available to send, this function returns 0.
3508  *
3509  * This function may not return all serialized data in one invocation.
3510  * To get all data, call this function repeatedly until it returns 0
3511  * or one of negative error codes.
3512  *
3513  * The assigned |*data_ptr| is valid until the next call of
3514  * `nghttp2_session_mem_send2()` or `nghttp2_session_send()`.
3515  *
3516  * The caller must send all data before sending the next chunk of
3517  * data.
3518  *
3519  * This function returns the length of the data pointed by the
3520  * |*data_ptr| if it succeeds, or one of the following negative error
3521  * codes:
3522  *
3523  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
3524  *     Out of memory.
3525  *
3526  * .. note::
3527  *
3528  *   This function may produce very small byte string.  If that is the
3529  *   case, and application disables Nagle algorithm (``TCP_NODELAY``),
3530  *   then writing this small chunk leads to very small packet, and it
3531  *   is very inefficient.  An application should be responsible to
3532  *   buffer up small chunks of data as necessary to avoid this
3533  *   situation.
3534  */
3535 NGHTTP2_EXTERN nghttp2_ssize
3536 nghttp2_session_mem_send2(nghttp2_session *session, const uint8_t **data_ptr);
3537 
3538 /**
3539  * @function
3540  *
3541  * Receives frames from the remote peer.
3542  *
3543  * This function receives as many frames as possible until the user
3544  * callback :type:`nghttp2_recv_callback` returns
3545  * :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`.  This function calls
3546  * several callback functions which are passed when initializing the
3547  * |session|.  Here is the simple time chart which tells when each
3548  * callback is invoked:
3549  *
3550  * 1. :type:`nghttp2_recv_callback` is invoked one or more times to
3551  *    receive frame header.
3552  *
3553  * 2. When frame header is received,
3554  *    :type:`nghttp2_on_begin_frame_callback` is invoked.
3555  *
3556  * 3. If the frame is DATA frame:
3557  *
3558  *    1. :type:`nghttp2_recv_callback` is invoked to receive DATA
3559  *       payload. For each chunk of data,
3560  *       :type:`nghttp2_on_data_chunk_recv_callback` is invoked.
3561  *
3562  *    2. If one DATA frame is completely received,
3563  *       :type:`nghttp2_on_frame_recv_callback` is invoked.  If the
3564  *       reception of the frame triggers the closure of the stream,
3565  *       :type:`nghttp2_on_stream_close_callback` is invoked.
3566  *
3567  * 4. If the frame is the control frame:
3568  *
3569  *    1. :type:`nghttp2_recv_callback` is invoked one or more times to
3570  *       receive whole frame.
3571  *
3572  *    2. If the received frame is valid, then following actions are
3573  *       taken.  If the frame is either HEADERS or PUSH_PROMISE,
3574  *       :type:`nghttp2_on_begin_headers_callback` is invoked.  Then
3575  *       :type:`nghttp2_on_header_callback` is invoked for each header
3576  *       name/value pair.  For invalid header field,
3577  *       :type:`nghttp2_on_invalid_header_callback` is called.  After
3578  *       all name/value pairs are emitted successfully,
3579  *       :type:`nghttp2_on_frame_recv_callback` is invoked.  For other
3580  *       frames, :type:`nghttp2_on_frame_recv_callback` is invoked.
3581  *       If the reception of the frame triggers the closure of the
3582  *       stream, :type:`nghttp2_on_stream_close_callback` is invoked.
3583  *
3584  *    3. If the received frame is unpacked but is interpreted as
3585  *       invalid, :type:`nghttp2_on_invalid_frame_recv_callback` is
3586  *       invoked.
3587  *
3588  * This function returns 0 if it succeeds, or one of the following
3589  * negative error codes:
3590  *
3591  * :enum:`nghttp2_error.NGHTTP2_ERR_EOF`
3592  *     The remote peer did shutdown on the connection.
3593  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
3594  *     Out of memory.
3595  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`
3596  *     The callback function failed.
3597  * :enum:`nghttp2_error.NGHTTP2_ERR_BAD_CLIENT_MAGIC`
3598  *     Invalid client magic was detected.  This error only returns
3599  *     when |session| was configured as server and
3600  *     `nghttp2_option_set_no_recv_client_magic()` is not used with
3601  *     nonzero value.
3602  * :enum:`nghttp2_error.NGHTTP2_ERR_FLOODED`
3603  *     Flooding was detected in this HTTP/2 session, and it must be
3604  *     closed.  This is most likely caused by misbehaviour of peer.
3605  */
3606 NGHTTP2_EXTERN int nghttp2_session_recv(nghttp2_session *session);
3607 
3608 #ifndef NGHTTP2_NO_SSIZE_T
3609 /**
3610  * @function
3611  *
3612  * .. warning::
3613  *
3614  *   Deprecated.  Use `nghttp2_session_mem_recv2()` instead.
3615  *
3616  * Processes data |in| as an input from the remote endpoint.  The
3617  * |inlen| indicates the number of bytes to receive in the |in|.
3618  *
3619  * This function behaves like `nghttp2_session_recv()` except that it
3620  * does not use :type:`nghttp2_recv_callback` to receive data; the
3621  * |in| is the only data for the invocation of this function.  If all
3622  * bytes are processed, this function returns.  The other callbacks
3623  * are called in the same way as they are in `nghttp2_session_recv()`.
3624  *
3625  * In the current implementation, this function always tries to
3626  * processes |inlen| bytes of input data unless either an error occurs or
3627  * :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` is returned from
3628  * :type:`nghttp2_on_header_callback` or
3629  * :type:`nghttp2_on_data_chunk_recv_callback`.  If
3630  * :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` is used, the return value
3631  * includes the number of bytes which was used to produce the data or
3632  * frame for the callback.
3633  *
3634  * This function returns the number of processed bytes, or one of the
3635  * following negative error codes:
3636  *
3637  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
3638  *     Out of memory.
3639  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`
3640  *     The callback function failed.
3641  * :enum:`nghttp2_error.NGHTTP2_ERR_BAD_CLIENT_MAGIC`
3642  *     Invalid client magic was detected.  This error only returns
3643  *     when |session| was configured as server and
3644  *     `nghttp2_option_set_no_recv_client_magic()` is not used with
3645  *     nonzero value.
3646  * :enum:`nghttp2_error.NGHTTP2_ERR_FLOODED`
3647  *     Flooding was detected in this HTTP/2 session, and it must be
3648  *     closed.  This is most likely caused by misbehaviour of peer.
3649  */
3650 NGHTTP2_EXTERN ssize_t nghttp2_session_mem_recv(nghttp2_session *session,
3651                                                 const uint8_t *in,
3652                                                 size_t inlen);
3653 
3654 #endif /* NGHTTP2_NO_SSIZE_T */
3655 
3656 /**
3657  * @function
3658  *
3659  * Processes data |in| as an input from the remote endpoint.  The
3660  * |inlen| indicates the number of bytes to receive in the |in|.
3661  *
3662  * This function behaves like `nghttp2_session_recv()` except that it
3663  * does not use :type:`nghttp2_recv_callback` to receive data; the
3664  * |in| is the only data for the invocation of this function.  If all
3665  * bytes are processed, this function returns.  The other callbacks
3666  * are called in the same way as they are in `nghttp2_session_recv()`.
3667  *
3668  * In the current implementation, this function always tries to
3669  * processes |inlen| bytes of input data unless either an error occurs or
3670  * :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` is returned from
3671  * :type:`nghttp2_on_header_callback` or
3672  * :type:`nghttp2_on_data_chunk_recv_callback`.  If
3673  * :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` is used, the return value
3674  * includes the number of bytes which was used to produce the data or
3675  * frame for the callback.
3676  *
3677  * This function returns the number of processed bytes, or one of the
3678  * following negative error codes:
3679  *
3680  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
3681  *     Out of memory.
3682  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`
3683  *     The callback function failed.
3684  * :enum:`nghttp2_error.NGHTTP2_ERR_BAD_CLIENT_MAGIC`
3685  *     Invalid client magic was detected.  This error only returns
3686  *     when |session| was configured as server and
3687  *     `nghttp2_option_set_no_recv_client_magic()` is not used with
3688  *     nonzero value.
3689  * :enum:`nghttp2_error.NGHTTP2_ERR_FLOODED`
3690  *     Flooding was detected in this HTTP/2 session, and it must be
3691  *     closed.  This is most likely caused by misbehaviour of peer.
3692  */
3693 NGHTTP2_EXTERN nghttp2_ssize nghttp2_session_mem_recv2(nghttp2_session *session,
3694                                                        const uint8_t *in,
3695                                                        size_t inlen);
3696 
3697 /**
3698  * @function
3699  *
3700  * Puts back previously deferred DATA frame in the stream |stream_id|
3701  * to the outbound queue.
3702  *
3703  * This function returns 0 if it succeeds, or one of the following
3704  * negative error codes:
3705  *
3706  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
3707  *     The stream does not exist; or no deferred data exist.
3708  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
3709  *     Out of memory.
3710  */
3711 NGHTTP2_EXTERN int nghttp2_session_resume_data(nghttp2_session *session,
3712                                                int32_t stream_id);
3713 
3714 /**
3715  * @function
3716  *
3717  * Returns nonzero value if |session| wants to receive data from the
3718  * remote peer.
3719  *
3720  * If both `nghttp2_session_want_read()` and
3721  * `nghttp2_session_want_write()` return 0, the application should
3722  * drop the connection.
3723  */
3724 NGHTTP2_EXTERN int nghttp2_session_want_read(nghttp2_session *session);
3725 
3726 /**
3727  * @function
3728  *
3729  * Returns nonzero value if |session| wants to send data to the remote
3730  * peer.
3731  *
3732  * If both `nghttp2_session_want_read()` and
3733  * `nghttp2_session_want_write()` return 0, the application should
3734  * drop the connection.
3735  */
3736 NGHTTP2_EXTERN int nghttp2_session_want_write(nghttp2_session *session);
3737 
3738 /**
3739  * @function
3740  *
3741  * Returns stream_user_data for the stream |stream_id|.  The
3742  * stream_user_data is provided by `nghttp2_submit_request2()`,
3743  * `nghttp2_submit_headers()` or
3744  * `nghttp2_session_set_stream_user_data()`.  Unless it is set using
3745  * `nghttp2_session_set_stream_user_data()`, if the stream is
3746  * initiated by the remote endpoint, stream_user_data is always
3747  * ``NULL``.  If the stream does not exist, this function returns
3748  * ``NULL``.
3749  */
3750 NGHTTP2_EXTERN void *
3751 nghttp2_session_get_stream_user_data(nghttp2_session *session,
3752                                      int32_t stream_id);
3753 
3754 /**
3755  * @function
3756  *
3757  * Sets the |stream_user_data| to the stream denoted by the
3758  * |stream_id|.  If a stream user data is already set to the stream,
3759  * it is replaced with the |stream_user_data|.  It is valid to specify
3760  * ``NULL`` in the |stream_user_data|, which nullifies the associated
3761  * data pointer.
3762  *
3763  * It is valid to set the |stream_user_data| to the stream reserved by
3764  * PUSH_PROMISE frame.
3765  *
3766  * This function returns 0 if it succeeds, or one of following
3767  * negative error codes:
3768  *
3769  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
3770  *     The stream does not exist
3771  */
3772 NGHTTP2_EXTERN int
3773 nghttp2_session_set_stream_user_data(nghttp2_session *session,
3774                                      int32_t stream_id, void *stream_user_data);
3775 
3776 /**
3777  * @function
3778  *
3779  * Sets |user_data| to |session|, overwriting the existing user data
3780  * specified in `nghttp2_session_client_new()`, or
3781  * `nghttp2_session_server_new()`.
3782  */
3783 NGHTTP2_EXTERN void nghttp2_session_set_user_data(nghttp2_session *session,
3784                                                   void *user_data);
3785 
3786 /**
3787  * @function
3788  *
3789  * Returns the number of frames in the outbound queue.  This does not
3790  * include the deferred DATA frames.
3791  */
3792 NGHTTP2_EXTERN size_t
3793 nghttp2_session_get_outbound_queue_size(nghttp2_session *session);
3794 
3795 /**
3796  * @function
3797  *
3798  * Returns the number of DATA payload in bytes received without
3799  * WINDOW_UPDATE transmission for the stream |stream_id|.  The local
3800  * (receive) window size can be adjusted by
3801  * `nghttp2_submit_window_update()`.  This function takes into account
3802  * that and returns effective data length.  In particular, if the
3803  * local window size is reduced by submitting negative
3804  * window_size_increment with `nghttp2_submit_window_update()`, this
3805  * function returns the number of bytes less than actually received.
3806  *
3807  * This function returns -1 if it fails.
3808  */
3809 NGHTTP2_EXTERN int32_t nghttp2_session_get_stream_effective_recv_data_length(
3810     nghttp2_session *session, int32_t stream_id);
3811 
3812 /**
3813  * @function
3814  *
3815  * Returns the local (receive) window size for the stream |stream_id|.
3816  * The local window size can be adjusted by
3817  * `nghttp2_submit_window_update()`.  This function takes into account
3818  * that and returns effective window size.
3819  *
3820  * This function does not take into account the amount of received
3821  * data from the remote endpoint.  Use
3822  * `nghttp2_session_get_stream_local_window_size()` to know the amount
3823  * of data the remote endpoint can send without receiving stream level
3824  * WINDOW_UPDATE frame.  Note that each stream is still subject to the
3825  * connection level flow control.
3826  *
3827  * This function returns -1 if it fails.
3828  */
3829 NGHTTP2_EXTERN int32_t nghttp2_session_get_stream_effective_local_window_size(
3830     nghttp2_session *session, int32_t stream_id);
3831 
3832 /**
3833  * @function
3834  *
3835  * Returns the amount of flow-controlled payload (e.g., DATA) that the
3836  * remote endpoint can send without receiving stream level
3837  * WINDOW_UPDATE frame.  It is also subject to the connection level
3838  * flow control.  So the actual amount of data to send is
3839  * min(`nghttp2_session_get_stream_local_window_size()`,
3840  * `nghttp2_session_get_local_window_size()`).
3841  *
3842  * This function returns -1 if it fails.
3843  */
3844 NGHTTP2_EXTERN int32_t nghttp2_session_get_stream_local_window_size(
3845     nghttp2_session *session, int32_t stream_id);
3846 
3847 /**
3848  * @function
3849  *
3850  * Returns the number of DATA payload in bytes received without
3851  * WINDOW_UPDATE transmission for a connection.  The local (receive)
3852  * window size can be adjusted by `nghttp2_submit_window_update()`.
3853  * This function takes into account that and returns effective data
3854  * length.  In particular, if the local window size is reduced by
3855  * submitting negative window_size_increment with
3856  * `nghttp2_submit_window_update()`, this function returns the number
3857  * of bytes less than actually received.
3858  *
3859  * This function returns -1 if it fails.
3860  */
3861 NGHTTP2_EXTERN int32_t
3862 nghttp2_session_get_effective_recv_data_length(nghttp2_session *session);
3863 
3864 /**
3865  * @function
3866  *
3867  * Returns the local (receive) window size for a connection.  The
3868  * local window size can be adjusted by
3869  * `nghttp2_submit_window_update()`.  This function takes into account
3870  * that and returns effective window size.
3871  *
3872  * This function does not take into account the amount of received
3873  * data from the remote endpoint.  Use
3874  * `nghttp2_session_get_local_window_size()` to know the amount of
3875  * data the remote endpoint can send without receiving
3876  * connection-level WINDOW_UPDATE frame.  Note that each stream is
3877  * still subject to the stream level flow control.
3878  *
3879  * This function returns -1 if it fails.
3880  */
3881 NGHTTP2_EXTERN int32_t
3882 nghttp2_session_get_effective_local_window_size(nghttp2_session *session);
3883 
3884 /**
3885  * @function
3886  *
3887  * Returns the amount of flow-controlled payload (e.g., DATA) that the
3888  * remote endpoint can send without receiving connection level
3889  * WINDOW_UPDATE frame.  Note that each stream is still subject to the
3890  * stream level flow control (see
3891  * `nghttp2_session_get_stream_local_window_size()`).
3892  *
3893  * This function returns -1 if it fails.
3894  */
3895 NGHTTP2_EXTERN int32_t
3896 nghttp2_session_get_local_window_size(nghttp2_session *session);
3897 
3898 /**
3899  * @function
3900  *
3901  * Returns the remote window size for a given stream |stream_id|.
3902  *
3903  * This is the amount of flow-controlled payload (e.g., DATA) that the
3904  * local endpoint can send without stream level WINDOW_UPDATE.  There
3905  * is also connection level flow control, so the effective size of
3906  * payload that the local endpoint can actually send is
3907  * min(`nghttp2_session_get_stream_remote_window_size()`,
3908  * `nghttp2_session_get_remote_window_size()`).
3909  *
3910  * This function returns -1 if it fails.
3911  */
3912 NGHTTP2_EXTERN int32_t nghttp2_session_get_stream_remote_window_size(
3913     nghttp2_session *session, int32_t stream_id);
3914 
3915 /**
3916  * @function
3917  *
3918  * Returns the remote window size for a connection.
3919  *
3920  * This function always succeeds.
3921  */
3922 NGHTTP2_EXTERN int32_t
3923 nghttp2_session_get_remote_window_size(nghttp2_session *session);
3924 
3925 /**
3926  * @function
3927  *
3928  * Returns 1 if local peer half closed the given stream |stream_id|.
3929  * Returns 0 if it did not.  Returns -1 if no such stream exists.
3930  */
3931 NGHTTP2_EXTERN int
3932 nghttp2_session_get_stream_local_close(nghttp2_session *session,
3933                                        int32_t stream_id);
3934 
3935 /**
3936  * @function
3937  *
3938  * Returns 1 if remote peer half closed the given stream |stream_id|.
3939  * Returns 0 if it did not.  Returns -1 if no such stream exists.
3940  */
3941 NGHTTP2_EXTERN int
3942 nghttp2_session_get_stream_remote_close(nghttp2_session *session,
3943                                         int32_t stream_id);
3944 
3945 /**
3946  * @function
3947  *
3948  * Returns the current dynamic table size of HPACK inflater, including
3949  * the overhead 32 bytes per entry described in RFC 7541.
3950  */
3951 NGHTTP2_EXTERN size_t
3952 nghttp2_session_get_hd_inflate_dynamic_table_size(nghttp2_session *session);
3953 
3954 /**
3955  * @function
3956  *
3957  * Returns the current dynamic table size of HPACK deflater including
3958  * the overhead 32 bytes per entry described in RFC 7541.
3959  */
3960 NGHTTP2_EXTERN size_t
3961 nghttp2_session_get_hd_deflate_dynamic_table_size(nghttp2_session *session);
3962 
3963 /**
3964  * @function
3965  *
3966  * Signals the session so that the connection should be terminated.
3967  *
3968  * The last stream ID is the minimum value between the stream ID of a
3969  * stream for which :type:`nghttp2_on_frame_recv_callback` was called
3970  * most recently and the last stream ID we have sent to the peer
3971  * previously.
3972  *
3973  * The |error_code| is the error code of this GOAWAY frame.  The
3974  * pre-defined error code is one of :enum:`nghttp2_error_code`.
3975  *
3976  * After the transmission, both `nghttp2_session_want_read()` and
3977  * `nghttp2_session_want_write()` return 0.
3978  *
3979  * This function should be called when the connection should be
3980  * terminated after sending GOAWAY.  If the remaining streams should
3981  * be processed after GOAWAY, use `nghttp2_submit_goaway()` instead.
3982  *
3983  * This function returns 0 if it succeeds, or one of the following
3984  * negative error codes:
3985  *
3986  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
3987  *     Out of memory.
3988  */
3989 NGHTTP2_EXTERN int nghttp2_session_terminate_session(nghttp2_session *session,
3990                                                      uint32_t error_code);
3991 
3992 /**
3993  * @function
3994  *
3995  * Signals the session so that the connection should be terminated.
3996  *
3997  * This function behaves like `nghttp2_session_terminate_session()`,
3998  * but the last stream ID can be specified by the application for fine
3999  * grained control of stream.  The HTTP/2 specification does not allow
4000  * last_stream_id to be increased.  So the actual value sent as
4001  * last_stream_id is the minimum value between the given
4002  * |last_stream_id| and the last_stream_id we have previously sent to
4003  * the peer.
4004  *
4005  * The |last_stream_id| is peer's stream ID or 0.  So if |session| is
4006  * initialized as client, |last_stream_id| must be even or 0.  If
4007  * |session| is initialized as server, |last_stream_id| must be odd or
4008  * 0.
4009  *
4010  * This function returns 0 if it succeeds, or one of the following
4011  * negative error codes:
4012  *
4013  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
4014  *     Out of memory.
4015  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
4016  *     The |last_stream_id| is invalid.
4017  */
4018 NGHTTP2_EXTERN int nghttp2_session_terminate_session2(nghttp2_session *session,
4019                                                       int32_t last_stream_id,
4020                                                       uint32_t error_code);
4021 
4022 /**
4023  * @function
4024  *
4025  * Signals to the client that the server started graceful shutdown
4026  * procedure.
4027  *
4028  * This function is only usable for server.  If this function is
4029  * called with client side session, this function returns
4030  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`.
4031  *
4032  * To gracefully shutdown HTTP/2 session, server should call this
4033  * function to send GOAWAY with last_stream_id (1u << 31) - 1.  And
4034  * after some delay (e.g., 1 RTT), send another GOAWAY with the stream
4035  * ID that the server has some processing using
4036  * `nghttp2_submit_goaway()`.  See also
4037  * `nghttp2_session_get_last_proc_stream_id()`.
4038  *
4039  * Unlike `nghttp2_submit_goaway()`, this function just sends GOAWAY
4040  * and does nothing more.  This is a mere indication to the client
4041  * that session shutdown is imminent.  The application should call
4042  * `nghttp2_submit_goaway()` with appropriate last_stream_id after
4043  * this call.
4044  *
4045  * If one or more GOAWAY frame have been already sent by either
4046  * `nghttp2_submit_goaway()` or `nghttp2_session_terminate_session()`,
4047  * this function has no effect.
4048  *
4049  * This function returns 0 if it succeeds, or one of the following
4050  * negative error codes:
4051  *
4052  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
4053  *     Out of memory.
4054  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`
4055  *     The |session| is initialized as client.
4056  */
4057 NGHTTP2_EXTERN int nghttp2_submit_shutdown_notice(nghttp2_session *session);
4058 
4059 /**
4060  * @function
4061  *
4062  * Returns the value of SETTINGS |id| notified by a remote endpoint.
4063  * The |id| must be one of values defined in
4064  * :enum:`nghttp2_settings_id`.
4065  */
4066 NGHTTP2_EXTERN uint32_t nghttp2_session_get_remote_settings(
4067     nghttp2_session *session, nghttp2_settings_id id);
4068 
4069 /**
4070  * @function
4071  *
4072  * Returns the value of SETTINGS |id| of local endpoint acknowledged
4073  * by the remote endpoint.  The |id| must be one of the values defined
4074  * in :enum:`nghttp2_settings_id`.
4075  */
4076 NGHTTP2_EXTERN uint32_t nghttp2_session_get_local_settings(
4077     nghttp2_session *session, nghttp2_settings_id id);
4078 
4079 /**
4080  * @function
4081  *
4082  * Tells the |session| that next stream ID is |next_stream_id|.  The
4083  * |next_stream_id| must be equal or greater than the value returned
4084  * by `nghttp2_session_get_next_stream_id()`.
4085  *
4086  * This function returns 0 if it succeeds, or one of the following
4087  * negative error codes:
4088  *
4089  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
4090  *     The |next_stream_id| is strictly less than the value
4091  *     `nghttp2_session_get_next_stream_id()` returns; or
4092  *     |next_stream_id| is invalid (e.g., even integer for client, or
4093  *     odd integer for server).
4094  */
4095 NGHTTP2_EXTERN int nghttp2_session_set_next_stream_id(nghttp2_session *session,
4096                                                       int32_t next_stream_id);
4097 
4098 /**
4099  * @function
4100  *
4101  * Returns the next outgoing stream ID.  Notice that return type is
4102  * uint32_t.  If we run out of stream ID for this session, this
4103  * function returns 1 << 31.
4104  */
4105 NGHTTP2_EXTERN uint32_t
4106 nghttp2_session_get_next_stream_id(nghttp2_session *session);
4107 
4108 /**
4109  * @function
4110  *
4111  * Tells the |session| that |size| bytes for a stream denoted by
4112  * |stream_id| were consumed by application and are ready to
4113  * WINDOW_UPDATE.  The consumed bytes are counted towards both
4114  * connection and stream level WINDOW_UPDATE (see
4115  * `nghttp2_session_consume_connection()` and
4116  * `nghttp2_session_consume_stream()` to update consumption
4117  * independently).  This function is intended to be used without
4118  * automatic window update (see
4119  * `nghttp2_option_set_no_auto_window_update()`).
4120  *
4121  * This function returns 0 if it succeeds, or one of the following
4122  * negative error codes:
4123  *
4124  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
4125  *     Out of memory.
4126  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
4127  *     The |stream_id| is 0.
4128  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`
4129  *     Automatic WINDOW_UPDATE is not disabled.
4130  */
4131 NGHTTP2_EXTERN int nghttp2_session_consume(nghttp2_session *session,
4132                                            int32_t stream_id, size_t size);
4133 
4134 /**
4135  * @function
4136  *
4137  * Like `nghttp2_session_consume()`, but this only tells library that
4138  * |size| bytes were consumed only for connection level.  Note that
4139  * HTTP/2 maintains connection and stream level flow control windows
4140  * independently.
4141  *
4142  * This function returns 0 if it succeeds, or one of the following
4143  * negative error codes:
4144  *
4145  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
4146  *     Out of memory.
4147  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`
4148  *     Automatic WINDOW_UPDATE is not disabled.
4149  */
4150 NGHTTP2_EXTERN int nghttp2_session_consume_connection(nghttp2_session *session,
4151                                                       size_t size);
4152 
4153 /**
4154  * @function
4155  *
4156  * Like `nghttp2_session_consume()`, but this only tells library that
4157  * |size| bytes were consumed only for stream denoted by |stream_id|.
4158  * Note that HTTP/2 maintains connection and stream level flow control
4159  * windows independently.
4160  *
4161  * This function returns 0 if it succeeds, or one of the following
4162  * negative error codes:
4163  *
4164  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
4165  *     Out of memory.
4166  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
4167  *     The |stream_id| is 0.
4168  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`
4169  *     Automatic WINDOW_UPDATE is not disabled.
4170  */
4171 NGHTTP2_EXTERN int nghttp2_session_consume_stream(nghttp2_session *session,
4172                                                   int32_t stream_id,
4173                                                   size_t size);
4174 
4175 /**
4176  * @function
4177  *
4178  * .. warning::
4179  *
4180  *   Deprecated.  :rfc:`7540` priorities are deprecated by
4181  *   :rfc:`9113`.  Consider migrating to :rfc:`9218` extensible
4182  *   prioritization scheme.  In the future release after the end of
4183  *   2024, this function will always return 0 without doing anything.
4184  *
4185  * Changes priority of existing stream denoted by |stream_id|.  The
4186  * new priority specification is |pri_spec|.
4187  *
4188  * The priority is changed silently and instantly, and no PRIORITY
4189  * frame will be sent to notify the peer of this change.  This
4190  * function may be useful for server to change the priority of pushed
4191  * stream.
4192  *
4193  * If |session| is initialized as server, and ``pri_spec->stream_id``
4194  * points to the idle stream, the idle stream is created if it does
4195  * not exist.  The created idle stream will depend on root stream
4196  * (stream 0) with weight 16.
4197  *
4198  * Otherwise, if stream denoted by ``pri_spec->stream_id`` is not
4199  * found, we use default priority instead of given |pri_spec|.  That
4200  * is make stream depend on root stream with weight 16.
4201  *
4202  * If
4203  * :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES`
4204  * of value of 1 is submitted via `nghttp2_submit_settings()`, this
4205  * function does nothing and returns 0.
4206  *
4207  * This function returns 0 if it succeeds, or one of the following
4208  * negative error codes:
4209  *
4210  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
4211  *     Out of memory.
4212  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
4213  *     Attempted to depend on itself; or no stream exist for the given
4214  *     |stream_id|; or |stream_id| is 0
4215  */
4216 NGHTTP2_EXTERN int
4217 nghttp2_session_change_stream_priority(nghttp2_session *session,
4218                                        int32_t stream_id,
4219                                        const nghttp2_priority_spec *pri_spec);
4220 
4221 /**
4222  * @function
4223  *
4224  * .. warning::
4225  *
4226  *   Deprecated.  :rfc:`7540` priorities are deprecated by
4227  *   :rfc:`9113`.  Consider migrating to :rfc:`9218` extensible
4228  *   prioritization scheme.  In the future release after the end of
4229  *   2024, this function will always return 0 without doing anything.
4230  *
4231  * Creates idle stream with the given |stream_id|, and priority
4232  * |pri_spec|.
4233  *
4234  * The stream creation is done without sending PRIORITY frame, which
4235  * means that peer does not know about the existence of this idle
4236  * stream in the local endpoint.
4237  *
4238  * RFC 7540 does not disallow the use of creation of idle stream with
4239  * odd or even stream ID regardless of client or server.  So this
4240  * function can create odd or even stream ID regardless of client or
4241  * server.  But probably it is a bit safer to use the stream ID the
4242  * local endpoint can initiate (in other words, use odd stream ID for
4243  * client, and even stream ID for server), to avoid potential
4244  * collision from peer's instruction.  Also we can use
4245  * `nghttp2_session_set_next_stream_id()` to avoid to open created
4246  * idle streams accidentally if we follow this recommendation.
4247  *
4248  * If |session| is initialized as server, and ``pri_spec->stream_id``
4249  * points to the idle stream, the idle stream is created if it does
4250  * not exist.  The created idle stream will depend on root stream
4251  * (stream 0) with weight 16.
4252  *
4253  * Otherwise, if stream denoted by ``pri_spec->stream_id`` is not
4254  * found, we use default priority instead of given |pri_spec|.  That
4255  * is make stream depend on root stream with weight 16.
4256  *
4257  * If
4258  * :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES`
4259  * of value of 1 is submitted via `nghttp2_submit_settings()`, this
4260  * function does nothing and returns 0.
4261  *
4262  * This function returns 0 if it succeeds, or one of the following
4263  * negative error codes:
4264  *
4265  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
4266  *     Out of memory.
4267  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
4268  *     Attempted to depend on itself; or stream denoted by |stream_id|
4269  *     already exists; or |stream_id| cannot be used to create idle
4270  *     stream (in other words, local endpoint has already opened
4271  *     stream ID greater than or equal to the given stream ID; or
4272  *     |stream_id| is 0
4273  */
4274 NGHTTP2_EXTERN int
4275 nghttp2_session_create_idle_stream(nghttp2_session *session, int32_t stream_id,
4276                                    const nghttp2_priority_spec *pri_spec);
4277 
4278 /**
4279  * @function
4280  *
4281  * .. warning::
4282  *
4283  *   This function is deprecated in favor of
4284  *   `nghttp2_session_upgrade2()`, because this function lacks the
4285  *   parameter to tell the library the request method used in the
4286  *   original HTTP request.  This information is required for client
4287  *   to validate actual response body length against content-length
4288  *   header field (see `nghttp2_option_set_no_http_messaging()`).  If
4289  *   HEAD is used in request, the length of response body must be 0
4290  *   regardless of value included in content-length header field.
4291  *
4292  * Performs post-process of HTTP Upgrade request.  This function can
4293  * be called from both client and server, but the behavior is very
4294  * different in each other.
4295  *
4296  * If called from client side, the |settings_payload| must be the
4297  * value sent in ``HTTP2-Settings`` header field and must be decoded
4298  * by base64url decoder.  The |settings_payloadlen| is the length of
4299  * |settings_payload|.  The |settings_payload| is unpacked and its
4300  * setting values will be submitted using `nghttp2_submit_settings()`.
4301  * This means that the client application code does not need to submit
4302  * SETTINGS by itself.  The stream with stream ID=1 is opened and the
4303  * |stream_user_data| is used for its stream_user_data.  The opened
4304  * stream becomes half-closed (local) state.
4305  *
4306  * If called from server side, the |settings_payload| must be the
4307  * value received in ``HTTP2-Settings`` header field and must be
4308  * decoded by base64url decoder.  The |settings_payloadlen| is the
4309  * length of |settings_payload|.  It is treated as if the SETTINGS
4310  * frame with that payload is received.  Thus, callback functions for
4311  * the reception of SETTINGS frame will be invoked.  The stream with
4312  * stream ID=1 is opened.  The |stream_user_data| is ignored.  The
4313  * opened stream becomes half-closed (remote).
4314  *
4315  * This function returns 0 if it succeeds, or one of the following
4316  * negative error codes:
4317  *
4318  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
4319  *     Out of memory.
4320  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
4321  *     The |settings_payload| is badly formed.
4322  * :enum:`nghttp2_error.NGHTTP2_ERR_PROTO`
4323  *     The stream ID 1 is already used or closed; or is not available.
4324  */
4325 NGHTTP2_EXTERN int nghttp2_session_upgrade(nghttp2_session *session,
4326                                            const uint8_t *settings_payload,
4327                                            size_t settings_payloadlen,
4328                                            void *stream_user_data);
4329 
4330 /**
4331  * @function
4332  *
4333  * Performs post-process of HTTP Upgrade request.  This function can
4334  * be called from both client and server, but the behavior is very
4335  * different in each other.
4336  *
4337  * If called from client side, the |settings_payload| must be the
4338  * value sent in ``HTTP2-Settings`` header field and must be decoded
4339  * by base64url decoder.  The |settings_payloadlen| is the length of
4340  * |settings_payload|.  The |settings_payload| is unpacked and its
4341  * setting values will be submitted using `nghttp2_submit_settings()`.
4342  * This means that the client application code does not need to submit
4343  * SETTINGS by itself.  The stream with stream ID=1 is opened and the
4344  * |stream_user_data| is used for its stream_user_data.  The opened
4345  * stream becomes half-closed (local) state.
4346  *
4347  * If called from server side, the |settings_payload| must be the
4348  * value received in ``HTTP2-Settings`` header field and must be
4349  * decoded by base64url decoder.  The |settings_payloadlen| is the
4350  * length of |settings_payload|.  It is treated as if the SETTINGS
4351  * frame with that payload is received.  Thus, callback functions for
4352  * the reception of SETTINGS frame will be invoked.  The stream with
4353  * stream ID=1 is opened.  The |stream_user_data| is ignored.  The
4354  * opened stream becomes half-closed (remote).
4355  *
4356  * If the request method is HEAD, pass nonzero value to
4357  * |head_request|.  Otherwise, pass 0.
4358  *
4359  * This function returns 0 if it succeeds, or one of the following
4360  * negative error codes:
4361  *
4362  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
4363  *     Out of memory.
4364  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
4365  *     The |settings_payload| is badly formed.
4366  * :enum:`nghttp2_error.NGHTTP2_ERR_PROTO`
4367  *     The stream ID 1 is already used or closed; or is not available.
4368  */
4369 NGHTTP2_EXTERN int nghttp2_session_upgrade2(nghttp2_session *session,
4370                                             const uint8_t *settings_payload,
4371                                             size_t settings_payloadlen,
4372                                             int head_request,
4373                                             void *stream_user_data);
4374 
4375 #ifndef NGHTTP2_NO_SSIZE_T
4376 /**
4377  * @function
4378  *
4379  * .. warning::
4380  *
4381  *   Deprecated.  Use `nghttp2_pack_settings_payload2()` instead.
4382  *
4383  * Serializes the SETTINGS values |iv| in the |buf|.  The size of the
4384  * |buf| is specified by |buflen|.  The number of entries in the |iv|
4385  * array is given by |niv|.  The required space in |buf| for the |niv|
4386  * entries is ``6*niv`` bytes and if the given buffer is too small, an
4387  * error is returned.  This function is used mainly for creating a
4388  * SETTINGS payload to be sent with the ``HTTP2-Settings`` header
4389  * field in an HTTP Upgrade request.  The data written in |buf| is NOT
4390  * base64url encoded and the application is responsible for encoding.
4391  *
4392  * This function returns the number of bytes written in |buf|, or one
4393  * of the following negative error codes:
4394  *
4395  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
4396  *     The |iv| contains duplicate settings ID or invalid value.
4397  *
4398  * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE`
4399  *     The provided |buflen| size is too small to hold the output.
4400  */
4401 NGHTTP2_EXTERN ssize_t nghttp2_pack_settings_payload(
4402     uint8_t *buf, size_t buflen, const nghttp2_settings_entry *iv, size_t niv);
4403 
4404 #endif /* NGHTTP2_NO_SSIZE_T */
4405 
4406 /**
4407  * @function
4408  *
4409  * Serializes the SETTINGS values |iv| in the |buf|.  The size of the
4410  * |buf| is specified by |buflen|.  The number of entries in the |iv|
4411  * array is given by |niv|.  The required space in |buf| for the |niv|
4412  * entries is ``6*niv`` bytes and if the given buffer is too small, an
4413  * error is returned.  This function is used mainly for creating a
4414  * SETTINGS payload to be sent with the ``HTTP2-Settings`` header
4415  * field in an HTTP Upgrade request.  The data written in |buf| is NOT
4416  * base64url encoded and the application is responsible for encoding.
4417  *
4418  * This function returns the number of bytes written in |buf|, or one
4419  * of the following negative error codes:
4420  *
4421  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
4422  *     The |iv| contains duplicate settings ID or invalid value.
4423  *
4424  * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE`
4425  *     The provided |buflen| size is too small to hold the output.
4426  */
4427 NGHTTP2_EXTERN nghttp2_ssize nghttp2_pack_settings_payload2(
4428     uint8_t *buf, size_t buflen, const nghttp2_settings_entry *iv, size_t niv);
4429 
4430 /**
4431  * @function
4432  *
4433  * Returns string describing the |lib_error_code|.  The
4434  * |lib_error_code| must be one of the :enum:`nghttp2_error`.
4435  */
4436 NGHTTP2_EXTERN const char *nghttp2_strerror(int lib_error_code);
4437 
4438 /**
4439  * @function
4440  *
4441  * Returns string representation of HTTP/2 error code |error_code|
4442  * (e.g., ``PROTOCOL_ERROR`` is returned if ``error_code ==
4443  * NGHTTP2_PROTOCOL_ERROR``).  If string representation is unknown for
4444  * given |error_code|, this function returns string ``unknown``.
4445  */
4446 NGHTTP2_EXTERN const char *nghttp2_http2_strerror(uint32_t error_code);
4447 
4448 /**
4449  * @function
4450  *
4451  * .. warning::
4452  *
4453  *   Deprecated.  :rfc:`7540` priorities are deprecated by
4454  *   :rfc:`9113`.  Consider migrating to :rfc:`9218` extensible
4455  *   prioritization scheme.
4456  *
4457  * Initializes |pri_spec| with the |stream_id| of the stream to depend
4458  * on with |weight| and its exclusive flag.  If |exclusive| is
4459  * nonzero, exclusive flag is set.
4460  *
4461  * The |weight| must be in [:macro:`NGHTTP2_MIN_WEIGHT`,
4462  * :macro:`NGHTTP2_MAX_WEIGHT`], inclusive.
4463  */
4464 NGHTTP2_EXTERN void nghttp2_priority_spec_init(nghttp2_priority_spec *pri_spec,
4465                                                int32_t stream_id,
4466                                                int32_t weight, int exclusive);
4467 
4468 /**
4469  * @function
4470  *
4471  * .. warning::
4472  *
4473  *   Deprecated.  :rfc:`7540` priorities are deprecated by
4474  *   :rfc:`9113`.  Consider migrating to :rfc:`9218` extensible
4475  *   prioritization scheme.
4476  *
4477  * Initializes |pri_spec| with the default values.  The default values
4478  * are: stream_id = 0, weight = :macro:`NGHTTP2_DEFAULT_WEIGHT` and
4479  * exclusive = 0.
4480  */
4481 NGHTTP2_EXTERN void
4482 nghttp2_priority_spec_default_init(nghttp2_priority_spec *pri_spec);
4483 
4484 /**
4485  * @function
4486  *
4487  * .. warning::
4488  *
4489  *   Deprecated.  :rfc:`7540` priorities are deprecated by
4490  *   :rfc:`9113`.  Consider migrating to :rfc:`9218` extensible
4491  *   prioritization scheme.
4492  *
4493  * Returns nonzero if the |pri_spec| is filled with default values.
4494  */
4495 NGHTTP2_EXTERN int
4496 nghttp2_priority_spec_check_default(const nghttp2_priority_spec *pri_spec);
4497 
4498 #ifndef NGHTTP2_NO_SSIZE_T
4499 /**
4500  * @function
4501  *
4502  * .. warning::
4503  *
4504  *   Deprecated.  Use `nghttp2_submit_request2()` instead.
4505  *
4506  * Submits HEADERS frame and optionally one or more DATA frames.
4507  *
4508  * The |pri_spec| is a deprecated priority specification of this
4509  * request.  ``NULL`` means the default priority (see
4510  * `nghttp2_priority_spec_default_init()`).  To specify the priority,
4511  * use `nghttp2_priority_spec_init()`.  If |pri_spec| is not ``NULL``,
4512  * this function will copy its data members.
4513  *
4514  * The ``pri_spec->weight`` must be in [:macro:`NGHTTP2_MIN_WEIGHT`,
4515  * :macro:`NGHTTP2_MAX_WEIGHT`], inclusive.  If ``pri_spec->weight``
4516  * is strictly less than :macro:`NGHTTP2_MIN_WEIGHT`, it becomes
4517  * :macro:`NGHTTP2_MIN_WEIGHT`.  If it is strictly greater than
4518  * :macro:`NGHTTP2_MAX_WEIGHT`, it becomes
4519  * :macro:`NGHTTP2_MAX_WEIGHT`.
4520  *
4521  * If
4522  * :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES`
4523  * of value of 1 is received by a remote endpoint, |pri_spec| is
4524  * ignored, and treated as if ``NULL`` is specified.
4525  *
4526  * The |nva| is an array of name/value pair :type:`nghttp2_nv` with
4527  * |nvlen| elements.  The application is responsible to include
4528  * required pseudo-header fields (header field whose name starts with
4529  * ":") in |nva| and must place pseudo-headers before regular header
4530  * fields.
4531  *
4532  * This function creates copies of all name/value pairs in |nva|.  It
4533  * also lower-cases all names in |nva|.  The order of elements in
4534  * |nva| is preserved.  For header fields with
4535  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME` and
4536  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set,
4537  * header field name and value are not copied respectively.  With
4538  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME`, application
4539  * is responsible to pass header field name in lowercase.  The
4540  * application should maintain the references to them until
4541  * :type:`nghttp2_on_frame_send_callback` or
4542  * :type:`nghttp2_on_frame_not_send_callback` is called.
4543  *
4544  * HTTP/2 specification has requirement about header fields in the
4545  * request HEADERS.  See the specification for more details.
4546  *
4547  * If |data_prd| is not ``NULL``, it provides data which will be sent
4548  * in subsequent DATA frames.  In this case, a method that allows
4549  * request message bodies
4550  * (https://tools.ietf.org/html/rfc7231#section-4) must be specified
4551  * with ``:method`` key in |nva| (e.g. ``POST``).  This function does
4552  * not take ownership of the |data_prd|.  The function copies the
4553  * members of the |data_prd|.  If |data_prd| is ``NULL``, HEADERS have
4554  * END_STREAM set.  The |stream_user_data| is data associated to the
4555  * stream opened by this request and can be an arbitrary pointer,
4556  * which can be retrieved later by
4557  * `nghttp2_session_get_stream_user_data()`.
4558  *
4559  * This function returns assigned stream ID if it succeeds, or one of
4560  * the following negative error codes:
4561  *
4562  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
4563  *     Out of memory.
4564  * :enum:`nghttp2_error.NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE`
4565  *     No stream ID is available because maximum stream ID was
4566  *     reached.
4567  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
4568  *     Trying to depend on itself (new stream ID equals
4569  *     ``pri_spec->stream_id``).
4570  * :enum:`nghttp2_error.NGHTTP2_ERR_PROTO`
4571  *     The |session| is server session.
4572  *
4573  * .. warning::
4574  *
4575  *   This function returns assigned stream ID if it succeeds.  But
4576  *   that stream is not created yet.  The application must not submit
4577  *   frame to that stream ID before
4578  *   :type:`nghttp2_before_frame_send_callback` is called for this
4579  *   frame.  This means `nghttp2_session_get_stream_user_data()` does
4580  *   not work before the callback.  But
4581  *   `nghttp2_session_set_stream_user_data()` handles this situation
4582  *   specially, and it can set data to a stream during this period.
4583  *
4584  */
4585 NGHTTP2_EXTERN int32_t nghttp2_submit_request(
4586     nghttp2_session *session, const nghttp2_priority_spec *pri_spec,
4587     const nghttp2_nv *nva, size_t nvlen, const nghttp2_data_provider *data_prd,
4588     void *stream_user_data);
4589 
4590 #endif /* NGHTTP2_NO_SSIZE_T */
4591 
4592 /**
4593  * @function
4594  *
4595  * Submits HEADERS frame and optionally one or more DATA frames.
4596  *
4597  * The |pri_spec| is a deprecated priority specification of this
4598  * request.  ``NULL`` means the default priority (see
4599  * `nghttp2_priority_spec_default_init()`).  To specify the priority,
4600  * use `nghttp2_priority_spec_init()`.  If |pri_spec| is not ``NULL``,
4601  * this function will copy its data members.  In the future release
4602  * after the end of 2024, this function will ignore |pri_spec| and
4603  * behave as if ``NULL`` is given.
4604  *
4605  * The ``pri_spec->weight`` must be in [:macro:`NGHTTP2_MIN_WEIGHT`,
4606  * :macro:`NGHTTP2_MAX_WEIGHT`], inclusive.  If ``pri_spec->weight``
4607  * is strictly less than :macro:`NGHTTP2_MIN_WEIGHT`, it becomes
4608  * :macro:`NGHTTP2_MIN_WEIGHT`.  If it is strictly greater than
4609  * :macro:`NGHTTP2_MAX_WEIGHT`, it becomes
4610  * :macro:`NGHTTP2_MAX_WEIGHT`.
4611  *
4612  * If
4613  * :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES`
4614  * of value of 1 is received by a remote endpoint, |pri_spec| is
4615  * ignored, and treated as if ``NULL`` is specified.
4616  *
4617  * The |nva| is an array of name/value pair :type:`nghttp2_nv` with
4618  * |nvlen| elements.  The application is responsible to include
4619  * required pseudo-header fields (header field whose name starts with
4620  * ":") in |nva| and must place pseudo-headers before regular header
4621  * fields.
4622  *
4623  * This function creates copies of all name/value pairs in |nva|.  It
4624  * also lower-cases all names in |nva|.  The order of elements in
4625  * |nva| is preserved.  For header fields with
4626  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME` and
4627  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set,
4628  * header field name and value are not copied respectively.  With
4629  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME`, application
4630  * is responsible to pass header field name in lowercase.  The
4631  * application should maintain the references to them until
4632  * :type:`nghttp2_on_frame_send_callback` or
4633  * :type:`nghttp2_on_frame_not_send_callback` is called.
4634  *
4635  * HTTP/2 specification has requirement about header fields in the
4636  * request HEADERS.  See the specification for more details.
4637  *
4638  * If |data_prd| is not ``NULL``, it provides data which will be sent
4639  * in subsequent DATA frames.  In this case, a method that allows
4640  * request message bodies
4641  * (https://tools.ietf.org/html/rfc7231#section-4) must be specified
4642  * with ``:method`` key in |nva| (e.g. ``POST``).  This function does
4643  * not take ownership of the |data_prd|.  The function copies the
4644  * members of the |data_prd|.  If |data_prd| is ``NULL``, HEADERS have
4645  * END_STREAM set.  The |stream_user_data| is data associated to the
4646  * stream opened by this request and can be an arbitrary pointer,
4647  * which can be retrieved later by
4648  * `nghttp2_session_get_stream_user_data()`.
4649  *
4650  * This function returns assigned stream ID if it succeeds, or one of
4651  * the following negative error codes:
4652  *
4653  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
4654  *     Out of memory.
4655  * :enum:`nghttp2_error.NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE`
4656  *     No stream ID is available because maximum stream ID was
4657  *     reached.
4658  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
4659  *     Trying to depend on itself (new stream ID equals
4660  *     ``pri_spec->stream_id``).
4661  * :enum:`nghttp2_error.NGHTTP2_ERR_PROTO`
4662  *     The |session| is server session.
4663  *
4664  * .. warning::
4665  *
4666  *   This function returns assigned stream ID if it succeeds.  But
4667  *   that stream is not created yet.  The application must not submit
4668  *   frame to that stream ID before
4669  *   :type:`nghttp2_before_frame_send_callback` is called for this
4670  *   frame.  This means `nghttp2_session_get_stream_user_data()` does
4671  *   not work before the callback.  But
4672  *   `nghttp2_session_set_stream_user_data()` handles this situation
4673  *   specially, and it can set data to a stream during this period.
4674  *
4675  */
4676 NGHTTP2_EXTERN int32_t nghttp2_submit_request2(
4677     nghttp2_session *session, const nghttp2_priority_spec *pri_spec,
4678     const nghttp2_nv *nva, size_t nvlen, const nghttp2_data_provider2 *data_prd,
4679     void *stream_user_data);
4680 
4681 #ifndef NGHTTP2_NO_SSIZE_T
4682 /**
4683  * @function
4684  *
4685  * .. warning::
4686  *
4687  *   Deprecated.  Use `nghttp2_submit_response2()` instead.
4688  *
4689  * Submits response HEADERS frame and optionally one or more DATA
4690  * frames against the stream |stream_id|.
4691  *
4692  * The |nva| is an array of name/value pair :type:`nghttp2_nv` with
4693  * |nvlen| elements.  The application is responsible to include
4694  * required pseudo-header fields (header field whose name starts with
4695  * ":") in |nva| and must place pseudo-headers before regular header
4696  * fields.
4697  *
4698  * This function creates copies of all name/value pairs in |nva|.  It
4699  * also lower-cases all names in |nva|.  The order of elements in
4700  * |nva| is preserved.  For header fields with
4701  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME` and
4702  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set,
4703  * header field name and value are not copied respectively.  With
4704  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME`, application
4705  * is responsible to pass header field name in lowercase.  The
4706  * application should maintain the references to them until
4707  * :type:`nghttp2_on_frame_send_callback` or
4708  * :type:`nghttp2_on_frame_not_send_callback` is called.
4709  *
4710  * HTTP/2 specification has requirement about header fields in the
4711  * response HEADERS.  See the specification for more details.
4712  *
4713  * If |data_prd| is not ``NULL``, it provides data which will be sent
4714  * in subsequent DATA frames.  This function does not take ownership
4715  * of the |data_prd|.  The function copies the members of the
4716  * |data_prd|.  If |data_prd| is ``NULL``, HEADERS will have
4717  * END_STREAM flag set.
4718  *
4719  * This method can be used as normal HTTP response and push response.
4720  * When pushing a resource using this function, the |session| must be
4721  * configured using `nghttp2_session_server_new()` or its variants and
4722  * the target stream denoted by the |stream_id| must be reserved using
4723  * `nghttp2_submit_push_promise()`.
4724  *
4725  * To send non-final response headers (e.g., HTTP status 101), don't
4726  * use this function because this function half-closes the outbound
4727  * stream.  Instead, use `nghttp2_submit_headers()` for this purpose.
4728  *
4729  * This function returns 0 if it succeeds, or one of the following
4730  * negative error codes:
4731  *
4732  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
4733  *     Out of memory.
4734  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
4735  *     The |stream_id| is 0.
4736  * :enum:`nghttp2_error.NGHTTP2_ERR_DATA_EXIST`
4737  *     DATA or HEADERS has been already submitted and not fully
4738  *     processed yet.  Normally, this does not happen, but when
4739  *     application wrongly calls `nghttp2_submit_response()` twice,
4740  *     this may happen.
4741  * :enum:`nghttp2_error.NGHTTP2_ERR_PROTO`
4742  *     The |session| is client session.
4743  *
4744  * .. warning::
4745  *
4746  *   Calling this function twice for the same stream ID may lead to
4747  *   program crash.  It is generally considered to a programming error
4748  *   to commit response twice.
4749  */
4750 NGHTTP2_EXTERN int
4751 nghttp2_submit_response(nghttp2_session *session, int32_t stream_id,
4752                         const nghttp2_nv *nva, size_t nvlen,
4753                         const nghttp2_data_provider *data_prd);
4754 
4755 #endif /* NGHTTP2_NO_SSIZE_T */
4756 
4757 /**
4758  * @function
4759  *
4760  * Submits response HEADERS frame and optionally one or more DATA
4761  * frames against the stream |stream_id|.
4762  *
4763  * The |nva| is an array of name/value pair :type:`nghttp2_nv` with
4764  * |nvlen| elements.  The application is responsible to include
4765  * required pseudo-header fields (header field whose name starts with
4766  * ":") in |nva| and must place pseudo-headers before regular header
4767  * fields.
4768  *
4769  * This function creates copies of all name/value pairs in |nva|.  It
4770  * also lower-cases all names in |nva|.  The order of elements in
4771  * |nva| is preserved.  For header fields with
4772  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME` and
4773  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set,
4774  * header field name and value are not copied respectively.  With
4775  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME`, application
4776  * is responsible to pass header field name in lowercase.  The
4777  * application should maintain the references to them until
4778  * :type:`nghttp2_on_frame_send_callback` or
4779  * :type:`nghttp2_on_frame_not_send_callback` is called.
4780  *
4781  * HTTP/2 specification has requirement about header fields in the
4782  * response HEADERS.  See the specification for more details.
4783  *
4784  * If |data_prd| is not ``NULL``, it provides data which will be sent
4785  * in subsequent DATA frames.  This function does not take ownership
4786  * of the |data_prd|.  The function copies the members of the
4787  * |data_prd|.  If |data_prd| is ``NULL``, HEADERS will have
4788  * END_STREAM flag set.
4789  *
4790  * This method can be used as normal HTTP response and push response.
4791  * When pushing a resource using this function, the |session| must be
4792  * configured using `nghttp2_session_server_new()` or its variants and
4793  * the target stream denoted by the |stream_id| must be reserved using
4794  * `nghttp2_submit_push_promise()`.
4795  *
4796  * To send non-final response headers (e.g., HTTP status 101), don't
4797  * use this function because this function half-closes the outbound
4798  * stream.  Instead, use `nghttp2_submit_headers()` for this purpose.
4799  *
4800  * This function returns 0 if it succeeds, or one of the following
4801  * negative error codes:
4802  *
4803  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
4804  *     Out of memory.
4805  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
4806  *     The |stream_id| is 0.
4807  * :enum:`nghttp2_error.NGHTTP2_ERR_DATA_EXIST`
4808  *     DATA or HEADERS has been already submitted and not fully
4809  *     processed yet.  Normally, this does not happen, but when
4810  *     application wrongly calls `nghttp2_submit_response2()` twice,
4811  *     this may happen.
4812  * :enum:`nghttp2_error.NGHTTP2_ERR_PROTO`
4813  *     The |session| is client session.
4814  *
4815  * .. warning::
4816  *
4817  *   Calling this function twice for the same stream ID may lead to
4818  *   program crash.  It is generally considered to a programming error
4819  *   to commit response twice.
4820  */
4821 NGHTTP2_EXTERN int
4822 nghttp2_submit_response2(nghttp2_session *session, int32_t stream_id,
4823                          const nghttp2_nv *nva, size_t nvlen,
4824                          const nghttp2_data_provider2 *data_prd);
4825 
4826 /**
4827  * @function
4828  *
4829  * Submits trailer fields HEADERS against the stream |stream_id|.
4830  *
4831  * The |nva| is an array of name/value pair :type:`nghttp2_nv` with
4832  * |nvlen| elements.  The application must not include pseudo-header
4833  * fields (headers whose names starts with ":") in |nva|.
4834  *
4835  * This function creates copies of all name/value pairs in |nva|.  It
4836  * also lower-cases all names in |nva|.  The order of elements in
4837  * |nva| is preserved.  For header fields with
4838  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME` and
4839  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set,
4840  * header field name and value are not copied respectively.  With
4841  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME`, application
4842  * is responsible to pass header field name in lowercase.  The
4843  * application should maintain the references to them until
4844  * :type:`nghttp2_on_frame_send_callback` or
4845  * :type:`nghttp2_on_frame_not_send_callback` is called.
4846  *
4847  * For server, trailer fields must follow response HEADERS or response
4848  * DATA without END_STREAM flat set.  The library does not enforce
4849  * this requirement, and applications should do this for themselves.
4850  * If `nghttp2_submit_trailer()` is called before any response HEADERS
4851  * submission (usually by `nghttp2_submit_response2()`), the content
4852  * of |nva| will be sent as response headers, which will result in
4853  * error.
4854  *
4855  * This function has the same effect with `nghttp2_submit_headers()`,
4856  * with flags = :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM` and both
4857  * pri_spec and stream_user_data to NULL.
4858  *
4859  * To submit trailer fields after `nghttp2_submit_response2()` is
4860  * called, the application has to specify
4861  * :type:`nghttp2_data_provider2` to `nghttp2_submit_response2()`.
4862  * Inside of :type:`nghttp2_data_source_read_callback2`, when setting
4863  * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_EOF`, also set
4864  * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_END_STREAM`.  After
4865  * that, the application can send trailer fields using
4866  * `nghttp2_submit_trailer()`.  `nghttp2_submit_trailer()` can be used
4867  * inside :type:`nghttp2_data_source_read_callback2`.
4868  *
4869  * This function returns 0 if it succeeds and |stream_id| is -1.
4870  * Otherwise, this function returns 0 if it succeeds, or one of the
4871  * following negative error codes:
4872  *
4873  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
4874  *     Out of memory.
4875  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
4876  *     The |stream_id| is 0.
4877  */
4878 NGHTTP2_EXTERN int nghttp2_submit_trailer(nghttp2_session *session,
4879                                           int32_t stream_id,
4880                                           const nghttp2_nv *nva, size_t nvlen);
4881 
4882 /**
4883  * @function
4884  *
4885  * Submits HEADERS frame. The |flags| is bitwise OR of the
4886  * following values:
4887  *
4888  * * :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM`
4889  *
4890  * If |flags| includes :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM`,
4891  * this frame has END_STREAM flag set.
4892  *
4893  * The library handles the CONTINUATION frame internally and it
4894  * correctly sets END_HEADERS to the last sequence of the PUSH_PROMISE
4895  * or CONTINUATION frame.
4896  *
4897  * If the |stream_id| is -1, this frame is assumed as request (i.e.,
4898  * request HEADERS frame which opens new stream).  In this case, the
4899  * assigned stream ID will be returned.  Otherwise, specify stream ID
4900  * in |stream_id|.
4901  *
4902  * The |pri_spec| is a deprecated priority specification of this
4903  * request.  ``NULL`` means the default priority (see
4904  * `nghttp2_priority_spec_default_init()`).  To specify the priority,
4905  * use `nghttp2_priority_spec_init()`.  If |pri_spec| is not ``NULL``,
4906  * this function will copy its data members.  In the future release
4907  * after the end of 2024, this function will ignore |pri_spec| and
4908  * behave as if ``NULL`` is given.
4909  *
4910  * The ``pri_spec->weight`` must be in [:macro:`NGHTTP2_MIN_WEIGHT`,
4911  * :macro:`NGHTTP2_MAX_WEIGHT`], inclusive.  If ``pri_spec->weight``
4912  * is strictly less than :macro:`NGHTTP2_MIN_WEIGHT`, it becomes
4913  * :macro:`NGHTTP2_MIN_WEIGHT`.  If it is strictly greater than
4914  * :macro:`NGHTTP2_MAX_WEIGHT`, it becomes :macro:`NGHTTP2_MAX_WEIGHT`.
4915  *
4916  * If
4917  * :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES`
4918  * of value of 1 is received by a remote endpoint, |pri_spec| is
4919  * ignored, and treated as if ``NULL`` is specified.
4920  *
4921  * The |nva| is an array of name/value pair :type:`nghttp2_nv` with
4922  * |nvlen| elements.  The application is responsible to include
4923  * required pseudo-header fields (header field whose name starts with
4924  * ":") in |nva| and must place pseudo-headers before regular header
4925  * fields.
4926  *
4927  * This function creates copies of all name/value pairs in |nva|.  It
4928  * also lower-cases all names in |nva|.  The order of elements in
4929  * |nva| is preserved.  For header fields with
4930  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME` and
4931  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set,
4932  * header field name and value are not copied respectively.  With
4933  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME`, application
4934  * is responsible to pass header field name in lowercase.  The
4935  * application should maintain the references to them until
4936  * :type:`nghttp2_on_frame_send_callback` or
4937  * :type:`nghttp2_on_frame_not_send_callback` is called.
4938  *
4939  * The |stream_user_data| is a pointer to an arbitrary data which is
4940  * associated to the stream this frame will open.  Therefore it is
4941  * only used if this frame opens streams, in other words, it changes
4942  * stream state from idle or reserved to open.
4943  *
4944  * This function is low-level in a sense that the application code can
4945  * specify flags directly.  For usual HTTP request,
4946  * `nghttp2_submit_request2()` is useful.  Likewise, for HTTP
4947  * response, prefer `nghttp2_submit_response2()`.
4948  *
4949  * This function returns newly assigned stream ID if it succeeds and
4950  * |stream_id| is -1.  Otherwise, this function returns 0 if it
4951  * succeeds, or one of the following negative error codes:
4952  *
4953  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
4954  *     Out of memory.
4955  * :enum:`nghttp2_error.NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE`
4956  *     No stream ID is available because maximum stream ID was
4957  *     reached.
4958  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
4959  *     The |stream_id| is 0; or trying to depend on itself (stream ID
4960  *     equals ``pri_spec->stream_id``).
4961  * :enum:`nghttp2_error.NGHTTP2_ERR_DATA_EXIST`
4962  *     DATA or HEADERS has been already submitted and not fully
4963  *     processed yet.  This happens if stream denoted by |stream_id|
4964  *     is in reserved state.
4965  * :enum:`nghttp2_error.NGHTTP2_ERR_PROTO`
4966  *     The |stream_id| is -1, and |session| is server session.
4967  *
4968  * .. warning::
4969  *
4970  *   This function returns assigned stream ID if it succeeds and
4971  *   |stream_id| is -1.  But that stream is not opened yet.  The
4972  *   application must not submit frame to that stream ID before
4973  *   :type:`nghttp2_before_frame_send_callback` is called for this
4974  *   frame.
4975  *
4976  */
4977 NGHTTP2_EXTERN int32_t nghttp2_submit_headers(
4978     nghttp2_session *session, uint8_t flags, int32_t stream_id,
4979     const nghttp2_priority_spec *pri_spec, const nghttp2_nv *nva, size_t nvlen,
4980     void *stream_user_data);
4981 
4982 #ifndef NGHTTP2_NO_SSIZE_T
4983 /**
4984  * @function
4985  *
4986  * .. warning::
4987  *
4988  *   Deprecated.  Use `nghttp2_submit_data2()` instead.
4989  *
4990  * Submits one or more DATA frames to the stream |stream_id|.  The
4991  * data to be sent are provided by |data_prd|.  If |flags| contains
4992  * :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM`, the last DATA frame
4993  * has END_STREAM flag set.
4994  *
4995  * This function does not take ownership of the |data_prd|.  The
4996  * function copies the members of the |data_prd|.
4997  *
4998  * This function returns 0 if it succeeds, or one of the following
4999  * negative error codes:
5000  *
5001  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
5002  *     Out of memory.
5003  * :enum:`nghttp2_error.NGHTTP2_ERR_DATA_EXIST`
5004  *     DATA or HEADERS has been already submitted and not fully
5005  *     processed yet.
5006  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
5007  *     The |stream_id| is 0.
5008  * :enum:`nghttp2_error.NGHTTP2_ERR_STREAM_CLOSED`
5009  *     The stream was already closed; or the |stream_id| is invalid.
5010  *
5011  * .. note::
5012  *
5013  *   Currently, only one DATA or HEADERS is allowed for a stream at a
5014  *   time.  Submitting these frames more than once before first DATA
5015  *   or HEADERS is finished results in
5016  *   :enum:`nghttp2_error.NGHTTP2_ERR_DATA_EXIST` error code.  The
5017  *   earliest callback which tells that previous frame is done is
5018  *   :type:`nghttp2_on_frame_send_callback`.  In side that callback,
5019  *   new data can be submitted using `nghttp2_submit_data()`.  Of
5020  *   course, all data except for last one must not have
5021  *   :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM` flag set in |flags|.
5022  *   This sounds a bit complicated, and we recommend to use
5023  *   `nghttp2_submit_request()` and `nghttp2_submit_response()` to
5024  *   avoid this cascading issue.  The experience shows that for HTTP
5025  *   use, these two functions are enough to implement both client and
5026  *   server.
5027  */
5028 NGHTTP2_EXTERN int nghttp2_submit_data(nghttp2_session *session, uint8_t flags,
5029                                        int32_t stream_id,
5030                                        const nghttp2_data_provider *data_prd);
5031 
5032 #endif /* NGHTTP2_NO_SSIZE_T */
5033 
5034 /**
5035  * @function
5036  *
5037  * Submits one or more DATA frames to the stream |stream_id|.  The
5038  * data to be sent are provided by |data_prd|.  If |flags| contains
5039  * :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM`, the last DATA frame
5040  * has END_STREAM flag set.
5041  *
5042  * This function does not take ownership of the |data_prd|.  The
5043  * function copies the members of the |data_prd|.
5044  *
5045  * This function returns 0 if it succeeds, or one of the following
5046  * negative error codes:
5047  *
5048  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
5049  *     Out of memory.
5050  * :enum:`nghttp2_error.NGHTTP2_ERR_DATA_EXIST`
5051  *     DATA or HEADERS has been already submitted and not fully
5052  *     processed yet.
5053  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
5054  *     The |stream_id| is 0.
5055  * :enum:`nghttp2_error.NGHTTP2_ERR_STREAM_CLOSED`
5056  *     The stream was already closed; or the |stream_id| is invalid.
5057  *
5058  * .. note::
5059  *
5060  *   Currently, only one DATA or HEADERS is allowed for a stream at a
5061  *   time.  Submitting these frames more than once before first DATA
5062  *   or HEADERS is finished results in
5063  *   :enum:`nghttp2_error.NGHTTP2_ERR_DATA_EXIST` error code.  The
5064  *   earliest callback which tells that previous frame is done is
5065  *   :type:`nghttp2_on_frame_send_callback`.  In side that callback,
5066  *   new data can be submitted using `nghttp2_submit_data2()`.  Of
5067  *   course, all data except for last one must not have
5068  *   :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM` flag set in |flags|.
5069  *   This sounds a bit complicated, and we recommend to use
5070  *   `nghttp2_submit_request2()` and `nghttp2_submit_response2()` to
5071  *   avoid this cascading issue.  The experience shows that for HTTP
5072  *   use, these two functions are enough to implement both client and
5073  *   server.
5074  */
5075 NGHTTP2_EXTERN int nghttp2_submit_data2(nghttp2_session *session, uint8_t flags,
5076                                         int32_t stream_id,
5077                                         const nghttp2_data_provider2 *data_prd);
5078 
5079 /**
5080  * @function
5081  *
5082  * .. warning::
5083  *
5084  *   Deprecated.  :rfc:`7540` priorities are deprecated by
5085  *   :rfc:`9113`.  Consider migrating to :rfc:`9218` extensible
5086  *   prioritization scheme.  In the future release after the end of
5087  *   2024, this function will always return 0 without doing anything.
5088  *
5089  * Submits PRIORITY frame to change the priority of stream |stream_id|
5090  * to the priority specification |pri_spec|.
5091  *
5092  * The |flags| is currently ignored and should be
5093  * :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`.
5094  *
5095  * The |pri_spec| is a deprecated priority specification of this
5096  * request.  ``NULL`` is not allowed for this function. To specify the
5097  * priority, use `nghttp2_priority_spec_init()`.  This function will
5098  * copy its data members.
5099  *
5100  * The ``pri_spec->weight`` must be in [:macro:`NGHTTP2_MIN_WEIGHT`,
5101  * :macro:`NGHTTP2_MAX_WEIGHT`], inclusive.  If ``pri_spec->weight``
5102  * is strictly less than :macro:`NGHTTP2_MIN_WEIGHT`, it becomes
5103  * :macro:`NGHTTP2_MIN_WEIGHT`.  If it is strictly greater than
5104  * :macro:`NGHTTP2_MAX_WEIGHT`, it becomes
5105  * :macro:`NGHTTP2_MAX_WEIGHT`.
5106  *
5107  * If
5108  * :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES`
5109  * of value of 1 is received by a remote endpoint, this function does
5110  * nothing and returns 0.
5111  *
5112  * This function returns 0 if it succeeds, or one of the following
5113  * negative error codes:
5114  *
5115  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
5116  *     Out of memory.
5117  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
5118  *     The |stream_id| is 0; or the |pri_spec| is NULL; or trying to
5119  *     depend on itself.
5120  */
5121 NGHTTP2_EXTERN int
5122 nghttp2_submit_priority(nghttp2_session *session, uint8_t flags,
5123                         int32_t stream_id,
5124                         const nghttp2_priority_spec *pri_spec);
5125 
5126 /**
5127  * @macro
5128  *
5129  * :macro:`NGHTTP2_EXTPRI_DEFAULT_URGENCY` is the default urgency
5130  * level for :rfc:`9218` extensible priorities.
5131  */
5132 #define NGHTTP2_EXTPRI_DEFAULT_URGENCY 3
5133 
5134 /**
5135  * @macro
5136  *
5137  * :macro:`NGHTTP2_EXTPRI_URGENCY_HIGH` is the highest urgency level
5138  * for :rfc:`9218` extensible priorities.
5139  */
5140 #define NGHTTP2_EXTPRI_URGENCY_HIGH 0
5141 
5142 /**
5143  * @macro
5144  *
5145  * :macro:`NGHTTP2_EXTPRI_URGENCY_LOW` is the lowest urgency level for
5146  * :rfc:`9218` extensible priorities.
5147  */
5148 #define NGHTTP2_EXTPRI_URGENCY_LOW 7
5149 
5150 /**
5151  * @macro
5152  *
5153  * :macro:`NGHTTP2_EXTPRI_URGENCY_LEVELS` is the number of urgency
5154  * levels for :rfc:`9218` extensible priorities.
5155  */
5156 #define NGHTTP2_EXTPRI_URGENCY_LEVELS (NGHTTP2_EXTPRI_URGENCY_LOW + 1)
5157 
5158 /**
5159  * @struct
5160  *
5161  * :type:`nghttp2_extpri` is :rfc:`9218` extensible priorities
5162  * specification for a stream.
5163  */
5164 typedef struct nghttp2_extpri {
5165   /**
5166    * :member:`urgency` is the urgency of a stream, it must be in
5167    * [:macro:`NGHTTP2_EXTPRI_URGENCY_HIGH`,
5168    * :macro:`NGHTTP2_EXTPRI_URGENCY_LOW`], inclusive, and 0 is the
5169    * highest urgency.
5170    */
5171   uint32_t urgency;
5172   /**
5173    * :member:`inc` indicates that a content can be processed
5174    * incrementally or not.  If inc is 0, it cannot be processed
5175    * incrementally.  If inc is 1, it can be processed incrementally.
5176    * Other value is not permitted.
5177    */
5178   int inc;
5179 } nghttp2_extpri;
5180 
5181 /**
5182  * @function
5183  *
5184  * Submits RST_STREAM frame to cancel/reject the stream |stream_id|
5185  * with the error code |error_code|.
5186  *
5187  * The pre-defined error code is one of :enum:`nghttp2_error_code`.
5188  *
5189  * The |flags| is currently ignored and should be
5190  * :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`.
5191  *
5192  * This function returns 0 if it succeeds, or one of the following
5193  * negative error codes:
5194  *
5195  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
5196  *     Out of memory.
5197  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
5198  *     The |stream_id| is 0.
5199  */
5200 NGHTTP2_EXTERN int nghttp2_submit_rst_stream(nghttp2_session *session,
5201                                              uint8_t flags, int32_t stream_id,
5202                                              uint32_t error_code);
5203 
5204 /**
5205  * @function
5206  *
5207  * Stores local settings and submits SETTINGS frame.  The |iv| is the
5208  * pointer to the array of :type:`nghttp2_settings_entry`.  The |niv|
5209  * indicates the number of :type:`nghttp2_settings_entry`.
5210  *
5211  * The |flags| is currently ignored and should be
5212  * :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`.
5213  *
5214  * This function does not take ownership of the |iv|.  This function
5215  * copies all the elements in the |iv|.
5216  *
5217  * While updating individual stream's local window size, if the window
5218  * size becomes strictly larger than NGHTTP2_MAX_WINDOW_SIZE,
5219  * RST_STREAM is issued against such a stream.
5220  *
5221  * SETTINGS with :enum:`nghttp2_flag.NGHTTP2_FLAG_ACK` is
5222  * automatically submitted by the library and application could not
5223  * send it at its will.
5224  *
5225  * This function returns 0 if it succeeds, or one of the following
5226  * negative error codes:
5227  *
5228  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
5229  *     The |iv| contains invalid value (e.g., initial window size
5230  *     strictly greater than (1 << 31) - 1.
5231  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
5232  *     Out of memory.
5233  */
5234 NGHTTP2_EXTERN int nghttp2_submit_settings(nghttp2_session *session,
5235                                            uint8_t flags,
5236                                            const nghttp2_settings_entry *iv,
5237                                            size_t niv);
5238 
5239 /**
5240  * @function
5241  *
5242  * Submits PUSH_PROMISE frame.
5243  *
5244  * The |flags| is currently ignored.  The library handles the
5245  * CONTINUATION frame internally and it correctly sets END_HEADERS to
5246  * the last sequence of the PUSH_PROMISE or CONTINUATION frame.
5247  *
5248  * The |stream_id| must be client initiated stream ID.
5249  *
5250  * The |nva| is an array of name/value pair :type:`nghttp2_nv` with
5251  * |nvlen| elements.  The application is responsible to include
5252  * required pseudo-header fields (header field whose name starts with
5253  * ":") in |nva| and must place pseudo-headers before regular header
5254  * fields.
5255  *
5256  * This function creates copies of all name/value pairs in |nva|.  It
5257  * also lower-cases all names in |nva|.  The order of elements in
5258  * |nva| is preserved.  For header fields with
5259  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME` and
5260  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set,
5261  * header field name and value are not copied respectively.  With
5262  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME`, application
5263  * is responsible to pass header field name in lowercase.  The
5264  * application should maintain the references to them until
5265  * :type:`nghttp2_on_frame_send_callback` or
5266  * :type:`nghttp2_on_frame_not_send_callback` is called.
5267  *
5268  * The |promised_stream_user_data| is a pointer to an arbitrary data
5269  * which is associated to the promised stream this frame will open and
5270  * make it in reserved state.  It is available using
5271  * `nghttp2_session_get_stream_user_data()`.  The application can
5272  * access it in :type:`nghttp2_before_frame_send_callback` and
5273  * :type:`nghttp2_on_frame_send_callback` of this frame.
5274  *
5275  * The client side is not allowed to use this function.
5276  *
5277  * To submit response headers and data, use
5278  * `nghttp2_submit_response2()`.
5279  *
5280  * This function returns assigned promised stream ID if it succeeds,
5281  * or one of the following negative error codes:
5282  *
5283  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
5284  *     Out of memory.
5285  * :enum:`nghttp2_error.NGHTTP2_ERR_PROTO`
5286  *     This function was invoked when |session| is initialized as
5287  *     client.
5288  * :enum:`nghttp2_error.NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE`
5289  *     No stream ID is available because maximum stream ID was
5290  *     reached.
5291  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
5292  *     The |stream_id| is 0; The |stream_id| does not designate stream
5293  *     that peer initiated.
5294  * :enum:`nghttp2_error.NGHTTP2_ERR_STREAM_CLOSED`
5295  *     The stream was already closed; or the |stream_id| is invalid.
5296  *
5297  * .. warning::
5298  *
5299  *   This function returns assigned promised stream ID if it succeeds.
5300  *   As of 1.16.0, stream object for pushed resource is created when
5301  *   this function succeeds.  In that case, the application can submit
5302  *   push response for the promised frame.
5303  *
5304  *   In 1.15.0 or prior versions, pushed stream is not opened yet when
5305  *   this function succeeds.  The application must not submit frame to
5306  *   that stream ID before :type:`nghttp2_before_frame_send_callback`
5307  *   is called for this frame.
5308  *
5309  */
5310 NGHTTP2_EXTERN int32_t nghttp2_submit_push_promise(
5311     nghttp2_session *session, uint8_t flags, int32_t stream_id,
5312     const nghttp2_nv *nva, size_t nvlen, void *promised_stream_user_data);
5313 
5314 /**
5315  * @function
5316  *
5317  * Submits PING frame.  You don't have to send PING back when you
5318  * received PING frame.  The library automatically submits PING frame
5319  * in this case.
5320  *
5321  * The |flags| is bitwise OR of 0 or more of the following value.
5322  *
5323  * * :enum:`nghttp2_flag.NGHTTP2_FLAG_ACK`
5324  *
5325  * Unless `nghttp2_option_set_no_auto_ping_ack()` is used, the |flags|
5326  * should be :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`.
5327  *
5328  * If the |opaque_data| is non ``NULL``, then it should point to the 8
5329  * bytes array of memory to specify opaque data to send with PING
5330  * frame.  If the |opaque_data| is ``NULL``, zero-cleared 8 bytes will
5331  * be sent as opaque data.
5332  *
5333  * This function returns 0 if it succeeds, or one of the following
5334  * negative error codes:
5335  *
5336  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
5337  *     Out of memory.
5338  */
5339 NGHTTP2_EXTERN int nghttp2_submit_ping(nghttp2_session *session, uint8_t flags,
5340                                        const uint8_t *opaque_data);
5341 
5342 /**
5343  * @function
5344  *
5345  * Submits GOAWAY frame with the last stream ID |last_stream_id| and
5346  * the error code |error_code|.
5347  *
5348  * The pre-defined error code is one of :enum:`nghttp2_error_code`.
5349  *
5350  * The |flags| is currently ignored and should be
5351  * :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`.
5352  *
5353  * The |last_stream_id| is peer's stream ID or 0.  So if |session| is
5354  * initialized as client, |last_stream_id| must be even or 0.  If
5355  * |session| is initialized as server, |last_stream_id| must be odd or
5356  * 0.
5357  *
5358  * The HTTP/2 specification says last_stream_id must not be increased
5359  * from the value previously sent.  So the actual value sent as
5360  * last_stream_id is the minimum value between the given
5361  * |last_stream_id| and the last_stream_id previously sent to the
5362  * peer.
5363  *
5364  * If the |opaque_data| is not ``NULL`` and |opaque_data_len| is not
5365  * zero, those data will be sent as additional debug data.  The
5366  * library makes a copy of the memory region pointed by |opaque_data|
5367  * with the length |opaque_data_len|, so the caller does not need to
5368  * keep this memory after the return of this function.  If the
5369  * |opaque_data_len| is 0, the |opaque_data| could be ``NULL``.
5370  *
5371  * After successful transmission of GOAWAY, following things happen.
5372  * All incoming streams having strictly more than |last_stream_id| are
5373  * closed.  All incoming HEADERS which starts new stream are simply
5374  * ignored.  After all active streams are handled, both
5375  * `nghttp2_session_want_read()` and `nghttp2_session_want_write()`
5376  * return 0 and the application can close session.
5377  *
5378  * This function returns 0 if it succeeds, or one of the following
5379  * negative error codes:
5380  *
5381  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
5382  *     Out of memory.
5383  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
5384  *     The |opaque_data_len| is too large; the |last_stream_id| is
5385  *     invalid.
5386  */
5387 NGHTTP2_EXTERN int nghttp2_submit_goaway(nghttp2_session *session,
5388                                          uint8_t flags, int32_t last_stream_id,
5389                                          uint32_t error_code,
5390                                          const uint8_t *opaque_data,
5391                                          size_t opaque_data_len);
5392 
5393 /**
5394  * @function
5395  *
5396  * Returns the last stream ID of a stream for which
5397  * :type:`nghttp2_on_frame_recv_callback` was invoked most recently.
5398  * The returned value can be used as last_stream_id parameter for
5399  * `nghttp2_submit_goaway()` and
5400  * `nghttp2_session_terminate_session2()`.
5401  *
5402  * This function always succeeds.
5403  */
5404 NGHTTP2_EXTERN int32_t
5405 nghttp2_session_get_last_proc_stream_id(nghttp2_session *session);
5406 
5407 /**
5408  * @function
5409  *
5410  * Returns nonzero if new request can be sent from local endpoint.
5411  *
5412  * This function return 0 if request is not allowed for this session.
5413  * There are several reasons why request is not allowed.  Some of the
5414  * reasons are: session is server; stream ID has been spent; GOAWAY
5415  * has been sent or received.
5416  *
5417  * The application can call `nghttp2_submit_request2()` without
5418  * consulting this function.  In that case,
5419  * `nghttp2_submit_request2()` may return error.  Or, request is
5420  * failed to sent, and :type:`nghttp2_on_stream_close_callback` is
5421  * called.
5422  */
5423 NGHTTP2_EXTERN int
5424 nghttp2_session_check_request_allowed(nghttp2_session *session);
5425 
5426 /**
5427  * @function
5428  *
5429  * Returns nonzero if |session| is initialized as server side session.
5430  */
5431 NGHTTP2_EXTERN int
5432 nghttp2_session_check_server_session(nghttp2_session *session);
5433 
5434 /**
5435  * @function
5436  *
5437  * Submits WINDOW_UPDATE frame.
5438  *
5439  * The |flags| is currently ignored and should be
5440  * :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`.
5441  *
5442  * The |stream_id| is the stream ID to send this WINDOW_UPDATE.  To
5443  * send connection level WINDOW_UPDATE, specify 0 to |stream_id|.
5444  *
5445  * If the |window_size_increment| is positive, the WINDOW_UPDATE with
5446  * that value as window_size_increment is queued.  If the
5447  * |window_size_increment| is larger than the received bytes from the
5448  * remote endpoint, the local window size is increased by that
5449  * difference.  If the sole purpose is to increase the local window
5450  * size, consider to use `nghttp2_session_set_local_window_size()`.
5451  *
5452  * If the |window_size_increment| is negative, the local window size
5453  * is decreased by -|window_size_increment|.  If automatic
5454  * WINDOW_UPDATE is enabled
5455  * (`nghttp2_option_set_no_auto_window_update()`), and the library
5456  * decided that the WINDOW_UPDATE should be submitted, then
5457  * WINDOW_UPDATE is queued with the current received bytes count.  If
5458  * the sole purpose is to decrease the local window size, consider to
5459  * use `nghttp2_session_set_local_window_size()`.
5460  *
5461  * If the |window_size_increment| is 0, the function does nothing and
5462  * returns 0.
5463  *
5464  * This function returns 0 if it succeeds, or one of the following
5465  * negative error codes:
5466  *
5467  * :enum:`nghttp2_error.NGHTTP2_ERR_FLOW_CONTROL`
5468  *     The local window size overflow or gets negative.
5469  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
5470  *     Out of memory.
5471  */
5472 NGHTTP2_EXTERN int nghttp2_submit_window_update(nghttp2_session *session,
5473                                                 uint8_t flags,
5474                                                 int32_t stream_id,
5475                                                 int32_t window_size_increment);
5476 
5477 /**
5478  * @function
5479  *
5480  * Set local window size (local endpoints's window size) to the given
5481  * |window_size| for the given stream denoted by |stream_id|.  To
5482  * change connection level window size, specify 0 to |stream_id|.  To
5483  * increase window size, this function may submit WINDOW_UPDATE frame
5484  * to transmission queue.
5485  *
5486  * The |flags| is currently ignored and should be
5487  * :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`.
5488  *
5489  * This sounds similar to `nghttp2_submit_window_update()`, but there
5490  * are 2 differences.  The first difference is that this function
5491  * takes the absolute value of window size to set, rather than the
5492  * delta.  To change the window size, this may be easier to use since
5493  * the application just declares the intended window size, rather than
5494  * calculating delta.  The second difference is that
5495  * `nghttp2_submit_window_update()` affects the received bytes count
5496  * which has not acked yet.  By the specification of
5497  * `nghttp2_submit_window_update()`, to strictly increase the local
5498  * window size, we have to submit delta including all received bytes
5499  * count, which might not be desirable in some cases.  On the other
5500  * hand, this function does not affect the received bytes count.  It
5501  * just sets the local window size to the given value.
5502  *
5503  * This function returns 0 if it succeeds, or one of the following
5504  * negative error codes:
5505  *
5506  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
5507  *     The |stream_id| is negative.
5508  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
5509  *     Out of memory.
5510  */
5511 NGHTTP2_EXTERN int
5512 nghttp2_session_set_local_window_size(nghttp2_session *session, uint8_t flags,
5513                                       int32_t stream_id, int32_t window_size);
5514 
5515 /**
5516  * @function
5517  *
5518  * Submits extension frame.
5519  *
5520  * Application can pass arbitrary frame flags and stream ID in |flags|
5521  * and |stream_id| respectively.  The |payload| is opaque pointer, and
5522  * it can be accessible though ``frame->ext.payload`` in
5523  * :type:`nghttp2_pack_extension_callback2`.  The library will not own
5524  * passed |payload| pointer.
5525  *
5526  * The application must set :type:`nghttp2_pack_extension_callback2`
5527  * using `nghttp2_session_callbacks_set_pack_extension_callback2()`.
5528  *
5529  * The application should retain the memory pointed by |payload| until
5530  * the transmission of extension frame is done (which is indicated by
5531  * :type:`nghttp2_on_frame_send_callback`), or transmission fails
5532  * (which is indicated by :type:`nghttp2_on_frame_not_send_callback`).
5533  * If application does not touch this memory region after packing it
5534  * into a wire format, application can free it inside
5535  * :type:`nghttp2_pack_extension_callback2`.
5536  *
5537  * The standard HTTP/2 frame cannot be sent with this function, so
5538  * |type| must be strictly grater than 0x9.  Otherwise, this function
5539  * will fail with error code
5540  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`.
5541  *
5542  * This function returns 0 if it succeeds, or one of the following
5543  * negative error codes:
5544  *
5545  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`
5546  *     If :type:`nghttp2_pack_extension_callback2` is not set.
5547  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
5548  *     If  |type| specifies  standard  HTTP/2 frame  type.  The  frame
5549  *     types  in the  rage [0x0,  0x9], both  inclusive, are  standard
5550  *     HTTP/2 frame type, and cannot be sent using this function.
5551  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
5552  *     Out of memory
5553  */
5554 NGHTTP2_EXTERN int nghttp2_submit_extension(nghttp2_session *session,
5555                                             uint8_t type, uint8_t flags,
5556                                             int32_t stream_id, void *payload);
5557 
5558 /**
5559  * @struct
5560  *
5561  * The payload of ALTSVC frame.  ALTSVC frame is a non-critical
5562  * extension to HTTP/2.  If this frame is received, and
5563  * `nghttp2_option_set_user_recv_extension_type()` is not set, and
5564  * `nghttp2_option_set_builtin_recv_extension_type()` is set for
5565  * :enum:`nghttp2_frame_type.NGHTTP2_ALTSVC`,
5566  * ``nghttp2_extension.payload`` will point to this struct.
5567  *
5568  * It has the following members:
5569  */
5570 typedef struct {
5571   /**
5572    * The pointer to origin which this alternative service is
5573    * associated with.  This is not necessarily NULL-terminated.
5574    */
5575   uint8_t *origin;
5576   /**
5577    * The length of the |origin|.
5578    */
5579   size_t origin_len;
5580   /**
5581    * The pointer to Alt-Svc field value contained in ALTSVC frame.
5582    * This is not necessarily NULL-terminated.
5583    */
5584   uint8_t *field_value;
5585   /**
5586    * The length of the |field_value|.
5587    */
5588   size_t field_value_len;
5589 } nghttp2_ext_altsvc;
5590 
5591 /**
5592  * @function
5593  *
5594  * Submits ALTSVC frame.
5595  *
5596  * ALTSVC frame is a non-critical extension to HTTP/2, and defined in
5597  * `RFC 7383 <https://tools.ietf.org/html/rfc7838#section-4>`_.
5598  *
5599  * The |flags| is currently ignored and should be
5600  * :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`.
5601  *
5602  * The |origin| points to the origin this alternative service is
5603  * associated with.  The |origin_len| is the length of the origin.  If
5604  * |stream_id| is 0, the origin must be specified.  If |stream_id| is
5605  * not zero, the origin must be empty (in other words, |origin_len|
5606  * must be 0).
5607  *
5608  * The ALTSVC frame is only usable from server side.  If this function
5609  * is invoked with client side session, this function returns
5610  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`.
5611  *
5612  * This function returns 0 if it succeeds, or one of the following
5613  * negative error codes:
5614  *
5615  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
5616  *     Out of memory
5617  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`
5618  *     The function is called from client side session
5619  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
5620  *     The sum of |origin_len| and |field_value_len| is larger than
5621  *     16382; or |origin_len| is 0 while |stream_id| is 0; or
5622  *     |origin_len| is not 0 while |stream_id| is not 0.
5623  */
5624 NGHTTP2_EXTERN int nghttp2_submit_altsvc(nghttp2_session *session,
5625                                          uint8_t flags, int32_t stream_id,
5626                                          const uint8_t *origin,
5627                                          size_t origin_len,
5628                                          const uint8_t *field_value,
5629                                          size_t field_value_len);
5630 
5631 /**
5632  * @struct
5633  *
5634  * The single entry of an origin.
5635  */
5636 typedef struct {
5637   /**
5638    * The pointer to origin.  No validation is made against this field
5639    * by the library.  This is not necessarily NULL-terminated.
5640    */
5641   uint8_t *origin;
5642   /**
5643    * The length of the |origin|.
5644    */
5645   size_t origin_len;
5646 } nghttp2_origin_entry;
5647 
5648 /**
5649  * @struct
5650  *
5651  * The payload of ORIGIN frame.  ORIGIN frame is a non-critical
5652  * extension to HTTP/2 and defined by `RFC 8336
5653  * <https://tools.ietf.org/html/rfc8336>`_.
5654  *
5655  * If this frame is received, and
5656  * `nghttp2_option_set_user_recv_extension_type()` is not set, and
5657  * `nghttp2_option_set_builtin_recv_extension_type()` is set for
5658  * :enum:`nghttp2_frame_type.NGHTTP2_ORIGIN`,
5659  * ``nghttp2_extension.payload`` will point to this struct.
5660  *
5661  * It has the following members:
5662  */
5663 typedef struct {
5664   /**
5665    * The number of origins contained in |ov|.
5666    */
5667   size_t nov;
5668   /**
5669    * The pointer to the array of origins contained in ORIGIN frame.
5670    */
5671   nghttp2_origin_entry *ov;
5672 } nghttp2_ext_origin;
5673 
5674 /**
5675  * @function
5676  *
5677  * Submits ORIGIN frame.
5678  *
5679  * ORIGIN frame is a non-critical extension to HTTP/2 and defined by
5680  * `RFC 8336 <https://tools.ietf.org/html/rfc8336>`_.
5681  *
5682  * The |flags| is currently ignored and should be
5683  * :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`.
5684  *
5685  * The |ov| points to the array of origins.  The |nov| specifies the
5686  * number of origins included in |ov|.  This function creates copies
5687  * of all elements in |ov|.
5688  *
5689  * The ORIGIN frame is only usable by a server.  If this function is
5690  * invoked with client side session, this function returns
5691  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`.
5692  *
5693  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
5694  *     Out of memory
5695  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`
5696  *     The function is called from client side session.
5697  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
5698  *     There are too many origins, or an origin is too large to fit
5699  *     into a default frame payload.
5700  */
5701 NGHTTP2_EXTERN int nghttp2_submit_origin(nghttp2_session *session,
5702                                          uint8_t flags,
5703                                          const nghttp2_origin_entry *ov,
5704                                          size_t nov);
5705 
5706 /**
5707  * @struct
5708  *
5709  * The payload of PRIORITY_UPDATE frame.  PRIORITY_UPDATE frame is a
5710  * non-critical extension to HTTP/2.  If this frame is received, and
5711  * `nghttp2_option_set_user_recv_extension_type()` is not set, and
5712  * `nghttp2_option_set_builtin_recv_extension_type()` is set for
5713  * :enum:`nghttp2_frame_type.NGHTTP2_PRIORITY_UPDATE`,
5714  * ``nghttp2_extension.payload`` will point to this struct.
5715  *
5716  * It has the following members:
5717  */
5718 typedef struct {
5719   /**
5720    * The stream ID of the stream whose priority is updated.
5721    */
5722   int32_t stream_id;
5723   /**
5724    * The pointer to Priority field value.  It is not necessarily
5725    * NULL-terminated.
5726    */
5727   uint8_t *field_value;
5728   /**
5729    * The length of the :member:`field_value`.
5730    */
5731   size_t field_value_len;
5732 } nghttp2_ext_priority_update;
5733 
5734 /**
5735  * @function
5736  *
5737  * Submits PRIORITY_UPDATE frame.
5738  *
5739  * PRIORITY_UPDATE frame is a non-critical extension to HTTP/2, and
5740  * defined in :rfc:`9218#section-7.1`.
5741  *
5742  * The |flags| is currently ignored and should be
5743  * :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`.
5744  *
5745  * The |stream_id| is the ID of stream which is prioritized.  The
5746  * |field_value| points to the Priority field value.  The
5747  * |field_value_len| is the length of the Priority field value.
5748  *
5749  * If this function is called by server,
5750  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE` is returned.
5751  *
5752  * If
5753  * :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES`
5754  * of value of 0 is received by a remote endpoint (or it is omitted),
5755  * this function does nothing and returns 0.
5756  *
5757  * This function returns 0 if it succeeds, or one of the following
5758  * negative error codes:
5759  *
5760  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
5761  *     Out of memory
5762  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`
5763  *     The function is called from server side session
5764  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
5765  *     The |field_value_len| is larger than 16380; or |stream_id| is
5766  *     0.
5767  */
5768 NGHTTP2_EXTERN int nghttp2_submit_priority_update(nghttp2_session *session,
5769                                                   uint8_t flags,
5770                                                   int32_t stream_id,
5771                                                   const uint8_t *field_value,
5772                                                   size_t field_value_len);
5773 
5774 /**
5775  * @function
5776  *
5777  * Changes the priority of the existing stream denoted by |stream_id|.
5778  * The new priority is |extpri|.  This function is meant to be used by
5779  * server for :rfc:`9218` extensible prioritization scheme.
5780  *
5781  * If |session| is initialized as client, this function returns
5782  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`.  For client, use
5783  * `nghttp2_submit_priority_update()` instead.
5784  *
5785  * If :member:`extpri->urgency <nghttp2_extpri.urgency>` is out of
5786  * bound, it is set to :macro:`NGHTTP2_EXTPRI_URGENCY_LOW`.
5787  *
5788  * If |ignore_client_signal| is nonzero, server starts to ignore
5789  * client priority signals for this stream.
5790  *
5791  * If
5792  * :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES`
5793  * of value of 1 is not submitted via `nghttp2_submit_settings()`,
5794  * this function does nothing and returns 0.
5795  *
5796  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
5797  *     Out of memory.
5798  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`
5799  *     The |session| is initialized as client.
5800  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
5801  *     |stream_id| is zero; or a stream denoted by |stream_id| is not
5802  *     found.
5803  */
5804 NGHTTP2_EXTERN int nghttp2_session_change_extpri_stream_priority(
5805     nghttp2_session *session, int32_t stream_id, const nghttp2_extpri *extpri,
5806     int ignore_client_signal);
5807 
5808 /**
5809  * @function
5810  *
5811  * Stores the stream priority of the existing stream denoted by
5812  * |stream_id| in the object pointed by |extpri|.  This function is
5813  * meant to be used by server for :rfc:`9218` extensible
5814  * prioritization scheme.
5815  *
5816  * If |session| is initialized as client, this function returns
5817  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`.
5818  *
5819  * If
5820  * :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES`
5821  * of value of 1 is not submitted via `nghttp2_submit_settings()`,
5822  * this function does nothing and returns 0.
5823  *
5824  * This function returns 0 if it succeeds, or one of the following
5825  * negative error codes:
5826  *
5827  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`
5828  *     The |session| is initialized as client.
5829  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
5830  *     |stream_id| is zero; or a stream denoted by |stream_id| is not
5831  *     found.
5832  */
5833 NGHTTP2_EXTERN int nghttp2_session_get_extpri_stream_priority(
5834     nghttp2_session *session, nghttp2_extpri *extpri, int32_t stream_id);
5835 
5836 /**
5837  * @function
5838  *
5839  * Parses Priority header field value pointed by |value| of length
5840  * |len|, and stores the result in the object pointed by |extpri|.
5841  * Priority header field is defined in :rfc:`9218`.
5842  *
5843  * This function does not initialize the object pointed by |extpri|
5844  * before storing the result.  It only assigns the values that the
5845  * parser correctly extracted to fields.
5846  *
5847  * This function returns 0 if it succeeds, or one of the following
5848  * negative error codes:
5849  *
5850  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
5851  *     Failed to parse the header field value.
5852  */
5853 NGHTTP2_EXTERN int nghttp2_extpri_parse_priority(nghttp2_extpri *extpri,
5854                                                  const uint8_t *value,
5855                                                  size_t len);
5856 
5857 /**
5858  * @function
5859  *
5860  * Compares ``lhs->name`` of length ``lhs->namelen`` bytes and
5861  * ``rhs->name`` of length ``rhs->namelen`` bytes.  Returns negative
5862  * integer if ``lhs->name`` is found to be less than ``rhs->name``; or
5863  * returns positive integer if ``lhs->name`` is found to be greater
5864  * than ``rhs->name``; or returns 0 otherwise.
5865  */
5866 NGHTTP2_EXTERN int nghttp2_nv_compare_name(const nghttp2_nv *lhs,
5867                                            const nghttp2_nv *rhs);
5868 
5869 /**
5870  * @function
5871  *
5872  * .. warning::
5873  *
5874  *   Deprecated.  Use `nghttp2_select_alpn` instead.
5875  *
5876  * A helper function for dealing with ALPN in server side.  The |in|
5877  * contains peer's protocol list in preferable order.  The format of
5878  * |in| is length-prefixed and not null-terminated.  For example,
5879  * ``h2`` and ``http/1.1`` stored in |in| like this::
5880  *
5881  *     in[0] = 2
5882  *     in[1..2] = "h2"
5883  *     in[3] = 8
5884  *     in[4..11] = "http/1.1"
5885  *     inlen = 12
5886  *
5887  * The selection algorithm is as follows:
5888  *
5889  * 1. If peer's list contains HTTP/2 protocol the library supports,
5890  *    it is selected and returns 1. The following step is not taken.
5891  *
5892  * 2. If peer's list contains ``http/1.1``, this function selects
5893  *    ``http/1.1`` and returns 0.  The following step is not taken.
5894  *
5895  * 3. This function selects nothing and returns -1 (So called
5896  *    non-overlap case).  In this case, |out| and |outlen| are left
5897  *    untouched.
5898  *
5899  * Selecting ``h2`` means that ``h2`` is written into |*out| and its
5900  * length (which is 2) is assigned to |*outlen|.
5901  *
5902  * For ALPN, refer to https://tools.ietf.org/html/rfc7301
5903  *
5904  * To use this method you should do something like::
5905  *
5906  *     static int alpn_select_proto_cb(SSL* ssl,
5907  *                                     const unsigned char **out,
5908  *                                     unsigned char *outlen,
5909  *                                     const unsigned char *in,
5910  *                                     unsigned int inlen,
5911  *                                     void *arg)
5912  *     {
5913  *         int rv;
5914  *         rv = nghttp2_select_next_protocol((unsigned char**)out, outlen,
5915  *                                           in, inlen);
5916  *         if (rv == -1) {
5917  *             return SSL_TLSEXT_ERR_NOACK;
5918  *         }
5919  *         if (rv == 1) {
5920  *             ((MyType*)arg)->http2_selected = 1;
5921  *         }
5922  *         return SSL_TLSEXT_ERR_OK;
5923  *     }
5924  *     ...
5925  *     SSL_CTX_set_alpn_select_cb(ssl_ctx, alpn_select_proto_cb, my_obj);
5926  *
5927  */
5928 NGHTTP2_EXTERN int nghttp2_select_next_protocol(unsigned char **out,
5929                                                 unsigned char *outlen,
5930                                                 const unsigned char *in,
5931                                                 unsigned int inlen);
5932 
5933 /**
5934  * @function
5935  *
5936  * A helper function for dealing with ALPN in server side.  The |in|
5937  * contains peer's protocol list in preferable order.  The format of
5938  * |in| is length-prefixed and not null-terminated.  For example,
5939  * ``h2`` and ``http/1.1`` stored in |in| like this::
5940  *
5941  *     in[0] = 2
5942  *     in[1..2] = "h2"
5943  *     in[3] = 8
5944  *     in[4..11] = "http/1.1"
5945  *     inlen = 12
5946  *
5947  * The selection algorithm is as follows:
5948  *
5949  * 1. If peer's list contains HTTP/2 protocol the library supports,
5950  *    it is selected and returns 1. The following step is not taken.
5951  *
5952  * 2. If peer's list contains ``http/1.1``, this function selects
5953  *    ``http/1.1`` and returns 0.  The following step is not taken.
5954  *
5955  * 3. This function selects nothing and returns -1 (So called
5956  *    non-overlap case).  In this case, |out| and |outlen| are left
5957  *    untouched.
5958  *
5959  * Selecting ``h2`` means that ``h2`` is written into |*out| and its
5960  * length (which is 2) is assigned to |*outlen|.
5961  *
5962  * For ALPN, refer to https://tools.ietf.org/html/rfc7301
5963  *
5964  * To use this method you should do something like::
5965  *
5966  *     static int alpn_select_proto_cb(SSL* ssl,
5967  *                                     const unsigned char **out,
5968  *                                     unsigned char *outlen,
5969  *                                     const unsigned char *in,
5970  *                                     unsigned int inlen,
5971  *                                     void *arg)
5972  *     {
5973  *         int rv;
5974  *         rv = nghttp2_select_alpn(out, outlen, in, inlen);
5975  *         if (rv == -1) {
5976  *             return SSL_TLSEXT_ERR_NOACK;
5977  *         }
5978  *         if (rv == 1) {
5979  *             ((MyType*)arg)->http2_selected = 1;
5980  *         }
5981  *         return SSL_TLSEXT_ERR_OK;
5982  *     }
5983  *     ...
5984  *     SSL_CTX_set_alpn_select_cb(ssl_ctx, alpn_select_proto_cb, my_obj);
5985  *
5986  */
5987 NGHTTP2_EXTERN int nghttp2_select_alpn(const unsigned char **out,
5988                                        unsigned char *outlen,
5989                                        const unsigned char *in,
5990                                        unsigned int inlen);
5991 
5992 /**
5993  * @function
5994  *
5995  * Returns a pointer to a nghttp2_info struct with version information
5996  * about the run-time library in use.  The |least_version| argument
5997  * can be set to a 24 bit numerical value for the least accepted
5998  * version number and if the condition is not met, this function will
5999  * return a ``NULL``.  Pass in 0 to skip the version checking.
6000  */
6001 NGHTTP2_EXTERN nghttp2_info *nghttp2_version(int least_version);
6002 
6003 /**
6004  * @function
6005  *
6006  * Returns nonzero if the :type:`nghttp2_error` library error code
6007  * |lib_error| is fatal.
6008  */
6009 NGHTTP2_EXTERN int nghttp2_is_fatal(int lib_error_code);
6010 
6011 /**
6012  * @function
6013  *
6014  * Returns nonzero if HTTP header field name |name| of length |len| is
6015  * valid according to http://tools.ietf.org/html/rfc7230#section-3.2
6016  *
6017  * Because this is a header field name in HTTP2, the upper cased alphabet
6018  * is treated as error.
6019  */
6020 NGHTTP2_EXTERN int nghttp2_check_header_name(const uint8_t *name, size_t len);
6021 
6022 /**
6023  * @function
6024  *
6025  * Returns nonzero if HTTP header field value |value| of length |len|
6026  * is valid according to
6027  * http://tools.ietf.org/html/rfc7230#section-3.2
6028  *
6029  * This function is considered obsolete, and application should
6030  * consider to use `nghttp2_check_header_value_rfc9113()` instead.
6031  */
6032 NGHTTP2_EXTERN int nghttp2_check_header_value(const uint8_t *value, size_t len);
6033 
6034 /**
6035  * @function
6036  *
6037  * Returns nonzero if HTTP header field value |value| of length |len|
6038  * is valid according to
6039  * http://tools.ietf.org/html/rfc7230#section-3.2, plus
6040  * https://datatracker.ietf.org/doc/html/rfc9113#section-8.2.1
6041  */
6042 NGHTTP2_EXTERN int nghttp2_check_header_value_rfc9113(const uint8_t *value,
6043                                                       size_t len);
6044 
6045 /**
6046  * @function
6047  *
6048  * Returns nonzero if the |value| which is supposed to be the value of
6049  * the :method header field is valid according to
6050  * https://datatracker.ietf.org/doc/html/rfc7231#section-4 and
6051  * https://datatracker.ietf.org/doc/html/rfc7230#section-3.2.6
6052  */
6053 NGHTTP2_EXTERN int nghttp2_check_method(const uint8_t *value, size_t len);
6054 
6055 /**
6056  * @function
6057  *
6058  * Returns nonzero if the |value| which is supposed to be the value of
6059  * the :path header field is valid according to
6060  * https://datatracker.ietf.org/doc/html/rfc7540#section-8.1.2.3
6061  *
6062  * |value| is valid if it merely consists of the allowed characters.
6063  * In particular, it does not check whether |value| follows the syntax
6064  * of path.  The allowed characters are all characters valid by
6065  * `nghttp2_check_header_value` minus SPC and HT.
6066  */
6067 NGHTTP2_EXTERN int nghttp2_check_path(const uint8_t *value, size_t len);
6068 
6069 /**
6070  * @function
6071  *
6072  * Returns nonzero if the |value| which is supposed to be the value of the
6073  * :authority or host header field is valid according to
6074  * https://tools.ietf.org/html/rfc3986#section-3.2
6075  *
6076  * |value| is valid if it merely consists of the allowed characters.
6077  * In particular, it does not check whether |value| follows the syntax
6078  * of authority.
6079  */
6080 NGHTTP2_EXTERN int nghttp2_check_authority(const uint8_t *value, size_t len);
6081 
6082 /* HPACK API */
6083 
6084 struct nghttp2_hd_deflater;
6085 
6086 /**
6087  * @struct
6088  *
6089  * HPACK deflater object.
6090  */
6091 typedef struct nghttp2_hd_deflater nghttp2_hd_deflater;
6092 
6093 /**
6094  * @function
6095  *
6096  * Initializes |*deflater_ptr| for deflating name/values pairs.
6097  *
6098  * The |max_deflate_dynamic_table_size| is the upper bound of header
6099  * table size the deflater will use.
6100  *
6101  * If this function fails, |*deflater_ptr| is left untouched.
6102  *
6103  * This function returns 0 if it succeeds, or one of the following
6104  * negative error codes:
6105  *
6106  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
6107  *     Out of memory.
6108  */
6109 NGHTTP2_EXTERN int
6110 nghttp2_hd_deflate_new(nghttp2_hd_deflater **deflater_ptr,
6111                        size_t max_deflate_dynamic_table_size);
6112 
6113 /**
6114  * @function
6115  *
6116  * Like `nghttp2_hd_deflate_new()`, but with additional custom memory
6117  * allocator specified in the |mem|.
6118  *
6119  * The |mem| can be ``NULL`` and the call is equivalent to
6120  * `nghttp2_hd_deflate_new()`.
6121  *
6122  * This function does not take ownership |mem|.  The application is
6123  * responsible for freeing |mem|.
6124  *
6125  * The library code does not refer to |mem| pointer after this
6126  * function returns, so the application can safely free it.
6127  */
6128 NGHTTP2_EXTERN int
6129 nghttp2_hd_deflate_new2(nghttp2_hd_deflater **deflater_ptr,
6130                         size_t max_deflate_dynamic_table_size,
6131                         nghttp2_mem *mem);
6132 
6133 /**
6134  * @function
6135  *
6136  * Deallocates any resources allocated for |deflater|.
6137  */
6138 NGHTTP2_EXTERN void nghttp2_hd_deflate_del(nghttp2_hd_deflater *deflater);
6139 
6140 /**
6141  * @function
6142  *
6143  * Changes header table size of the |deflater| to
6144  * |settings_max_dynamic_table_size| bytes.  This may trigger eviction
6145  * in the dynamic table.
6146  *
6147  * The |settings_max_dynamic_table_size| should be the value received
6148  * in SETTINGS_HEADER_TABLE_SIZE.
6149  *
6150  * The deflater never uses more memory than
6151  * ``max_deflate_dynamic_table_size`` bytes specified in
6152  * `nghttp2_hd_deflate_new()`.  Therefore, if
6153  * |settings_max_dynamic_table_size| >
6154  * ``max_deflate_dynamic_table_size``, resulting maximum table size
6155  * becomes ``max_deflate_dynamic_table_size``.
6156  *
6157  * This function returns 0 if it succeeds, or one of the following
6158  * negative error codes:
6159  *
6160  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
6161  *     Out of memory.
6162  */
6163 NGHTTP2_EXTERN int
6164 nghttp2_hd_deflate_change_table_size(nghttp2_hd_deflater *deflater,
6165                                      size_t settings_max_dynamic_table_size);
6166 
6167 #ifndef NGHTTP2_NO_SSIZE_T
6168 /**
6169  * @function
6170  *
6171  * .. warning::
6172  *
6173  *   Deprecated.  Use `nghttp2_hd_deflate_hd2()` instead.
6174  *
6175  * Deflates the |nva|, which has the |nvlen| name/value pairs, into
6176  * the |buf| of length |buflen|.
6177  *
6178  * If |buf| is not large enough to store the deflated header block,
6179  * this function fails with
6180  * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE`.  The caller
6181  * should use `nghttp2_hd_deflate_bound()` to know the upper bound of
6182  * buffer size required to deflate given header name/value pairs.
6183  *
6184  * Once this function fails, subsequent call of this function always
6185  * returns :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`.
6186  *
6187  * After this function returns, it is safe to delete the |nva|.
6188  *
6189  * This function returns the number of bytes written to |buf| if it
6190  * succeeds, or one of the following negative error codes:
6191  *
6192  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
6193  *     Out of memory.
6194  * :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`
6195  *     Deflation process has failed.
6196  * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE`
6197  *     The provided |buflen| size is too small to hold the output.
6198  */
6199 NGHTTP2_EXTERN ssize_t nghttp2_hd_deflate_hd(nghttp2_hd_deflater *deflater,
6200                                              uint8_t *buf, size_t buflen,
6201                                              const nghttp2_nv *nva,
6202                                              size_t nvlen);
6203 
6204 #endif /* NGHTTP2_NO_SSIZE_T */
6205 
6206 /**
6207  * @function
6208  *
6209  * Deflates the |nva|, which has the |nvlen| name/value pairs, into
6210  * the |buf| of length |buflen|.
6211  *
6212  * If |buf| is not large enough to store the deflated header block,
6213  * this function fails with
6214  * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE`.  The caller
6215  * should use `nghttp2_hd_deflate_bound()` to know the upper bound of
6216  * buffer size required to deflate given header name/value pairs.
6217  *
6218  * Once this function fails, subsequent call of this function always
6219  * returns :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`.
6220  *
6221  * After this function returns, it is safe to delete the |nva|.
6222  *
6223  * This function returns the number of bytes written to |buf| if it
6224  * succeeds, or one of the following negative error codes:
6225  *
6226  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
6227  *     Out of memory.
6228  * :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`
6229  *     Deflation process has failed.
6230  * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE`
6231  *     The provided |buflen| size is too small to hold the output.
6232  */
6233 NGHTTP2_EXTERN nghttp2_ssize
6234 nghttp2_hd_deflate_hd2(nghttp2_hd_deflater *deflater, uint8_t *buf,
6235                        size_t buflen, const nghttp2_nv *nva, size_t nvlen);
6236 
6237 #ifndef NGHTTP2_NO_SSIZE_T
6238 /**
6239  * @function
6240  *
6241  * .. warning::
6242  *
6243  *   Deprecated.  Use `nghttp2_hd_deflate_hd_vec2()` instead.
6244  *
6245  * Deflates the |nva|, which has the |nvlen| name/value pairs, into
6246  * the |veclen| size of buf vector |vec|.  The each size of buffer
6247  * must be set in len field of :type:`nghttp2_vec`.  If and only if
6248  * one chunk is filled up completely, next chunk will be used.  If
6249  * |vec| is not large enough to store the deflated header block, this
6250  * function fails with
6251  * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE`.  The caller
6252  * should use `nghttp2_hd_deflate_bound()` to know the upper bound of
6253  * buffer size required to deflate given header name/value pairs.
6254  *
6255  * Once this function fails, subsequent call of this function always
6256  * returns :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`.
6257  *
6258  * After this function returns, it is safe to delete the |nva|.
6259  *
6260  * This function returns the number of bytes written to |vec| if it
6261  * succeeds, or one of the following negative error codes:
6262  *
6263  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
6264  *     Out of memory.
6265  * :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`
6266  *     Deflation process has failed.
6267  * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE`
6268  *     The provided |buflen| size is too small to hold the output.
6269  */
6270 NGHTTP2_EXTERN ssize_t nghttp2_hd_deflate_hd_vec(nghttp2_hd_deflater *deflater,
6271                                                  const nghttp2_vec *vec,
6272                                                  size_t veclen,
6273                                                  const nghttp2_nv *nva,
6274                                                  size_t nvlen);
6275 
6276 #endif /* NGHTTP2_NO_SSIZE_T */
6277 
6278 /**
6279  * @function
6280  *
6281  * Deflates the |nva|, which has the |nvlen| name/value pairs, into
6282  * the |veclen| size of buf vector |vec|.  The each size of buffer
6283  * must be set in len field of :type:`nghttp2_vec`.  If and only if
6284  * one chunk is filled up completely, next chunk will be used.  If
6285  * |vec| is not large enough to store the deflated header block, this
6286  * function fails with
6287  * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE`.  The caller
6288  * should use `nghttp2_hd_deflate_bound()` to know the upper bound of
6289  * buffer size required to deflate given header name/value pairs.
6290  *
6291  * Once this function fails, subsequent call of this function always
6292  * returns :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`.
6293  *
6294  * After this function returns, it is safe to delete the |nva|.
6295  *
6296  * This function returns the number of bytes written to |vec| if it
6297  * succeeds, or one of the following negative error codes:
6298  *
6299  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
6300  *     Out of memory.
6301  * :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`
6302  *     Deflation process has failed.
6303  * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE`
6304  *     The provided |buflen| size is too small to hold the output.
6305  */
6306 NGHTTP2_EXTERN nghttp2_ssize nghttp2_hd_deflate_hd_vec2(
6307     nghttp2_hd_deflater *deflater, const nghttp2_vec *vec, size_t veclen,
6308     const nghttp2_nv *nva, size_t nvlen);
6309 
6310 /**
6311  * @function
6312  *
6313  * Returns an upper bound on the compressed size after deflation of
6314  * |nva| of length |nvlen|.
6315  */
6316 NGHTTP2_EXTERN size_t nghttp2_hd_deflate_bound(nghttp2_hd_deflater *deflater,
6317                                                const nghttp2_nv *nva,
6318                                                size_t nvlen);
6319 
6320 /**
6321  * @function
6322  *
6323  * Returns the number of entries that header table of |deflater|
6324  * contains.  This is the sum of the number of static table and
6325  * dynamic table, so the return value is at least 61.
6326  */
6327 NGHTTP2_EXTERN
6328 size_t nghttp2_hd_deflate_get_num_table_entries(nghttp2_hd_deflater *deflater);
6329 
6330 /**
6331  * @function
6332  *
6333  * Returns the table entry denoted by |idx| from header table of
6334  * |deflater|.  The |idx| is 1-based, and idx=1 returns first entry of
6335  * static table.  idx=62 returns first entry of dynamic table if it
6336  * exists.  Specifying idx=0 is error, and this function returns NULL.
6337  * If |idx| is strictly greater than the number of entries the tables
6338  * contain, this function returns NULL.
6339  */
6340 NGHTTP2_EXTERN
6341 const nghttp2_nv *
6342 nghttp2_hd_deflate_get_table_entry(nghttp2_hd_deflater *deflater, size_t idx);
6343 
6344 /**
6345  * @function
6346  *
6347  * Returns the used dynamic table size, including the overhead 32
6348  * bytes per entry described in RFC 7541.
6349  */
6350 NGHTTP2_EXTERN
6351 size_t nghttp2_hd_deflate_get_dynamic_table_size(nghttp2_hd_deflater *deflater);
6352 
6353 /**
6354  * @function
6355  *
6356  * Returns the maximum dynamic table size.
6357  */
6358 NGHTTP2_EXTERN
6359 size_t
6360 nghttp2_hd_deflate_get_max_dynamic_table_size(nghttp2_hd_deflater *deflater);
6361 
6362 struct nghttp2_hd_inflater;
6363 
6364 /**
6365  * @struct
6366  *
6367  * HPACK inflater object.
6368  */
6369 typedef struct nghttp2_hd_inflater nghttp2_hd_inflater;
6370 
6371 /**
6372  * @function
6373  *
6374  * Initializes |*inflater_ptr| for inflating name/values pairs.
6375  *
6376  * If this function fails, |*inflater_ptr| is left untouched.
6377  *
6378  * This function returns 0 if it succeeds, or one of the following
6379  * negative error codes:
6380  *
6381  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
6382  *     Out of memory.
6383  */
6384 NGHTTP2_EXTERN int nghttp2_hd_inflate_new(nghttp2_hd_inflater **inflater_ptr);
6385 
6386 /**
6387  * @function
6388  *
6389  * Like `nghttp2_hd_inflate_new()`, but with additional custom memory
6390  * allocator specified in the |mem|.
6391  *
6392  * The |mem| can be ``NULL`` and the call is equivalent to
6393  * `nghttp2_hd_inflate_new()`.
6394  *
6395  * This function does not take ownership |mem|.  The application is
6396  * responsible for freeing |mem|.
6397  *
6398  * The library code does not refer to |mem| pointer after this
6399  * function returns, so the application can safely free it.
6400  */
6401 NGHTTP2_EXTERN int nghttp2_hd_inflate_new2(nghttp2_hd_inflater **inflater_ptr,
6402                                            nghttp2_mem *mem);
6403 
6404 /**
6405  * @function
6406  *
6407  * Deallocates any resources allocated for |inflater|.
6408  */
6409 NGHTTP2_EXTERN void nghttp2_hd_inflate_del(nghttp2_hd_inflater *inflater);
6410 
6411 /**
6412  * @function
6413  *
6414  * Changes header table size in the |inflater|.  This may trigger
6415  * eviction in the dynamic table.
6416  *
6417  * The |settings_max_dynamic_table_size| should be the value
6418  * transmitted in SETTINGS_HEADER_TABLE_SIZE.
6419  *
6420  * This function must not be called while header block is being
6421  * inflated.  In other words, this function must be called after
6422  * initialization of |inflater|, but before calling
6423  * `nghttp2_hd_inflate_hd3()`, or after
6424  * `nghttp2_hd_inflate_end_headers()`.  Otherwise,
6425  * `NGHTTP2_ERR_INVALID_STATE` was returned.
6426  *
6427  * This function returns 0 if it succeeds, or one of the following
6428  * negative error codes:
6429  *
6430  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
6431  *     Out of memory.
6432  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`
6433  *     The function is called while header block is being inflated.
6434  *     Probably, application missed to call
6435  *     `nghttp2_hd_inflate_end_headers()`.
6436  */
6437 NGHTTP2_EXTERN int
6438 nghttp2_hd_inflate_change_table_size(nghttp2_hd_inflater *inflater,
6439                                      size_t settings_max_dynamic_table_size);
6440 
6441 /**
6442  * @enum
6443  *
6444  * The flags for header inflation.
6445  */
6446 typedef enum {
6447   /**
6448    * No flag set.
6449    */
6450   NGHTTP2_HD_INFLATE_NONE = 0,
6451   /**
6452    * Indicates all headers were inflated.
6453    */
6454   NGHTTP2_HD_INFLATE_FINAL = 0x01,
6455   /**
6456    * Indicates a header was emitted.
6457    */
6458   NGHTTP2_HD_INFLATE_EMIT = 0x02
6459 } nghttp2_hd_inflate_flag;
6460 
6461 #ifndef NGHTTP2_NO_SSIZE_T
6462 /**
6463  * @function
6464  *
6465  * .. warning::
6466  *
6467  *   Deprecated.  Use `nghttp2_hd_inflate_hd2()` instead.
6468  *
6469  * Inflates name/value block stored in |in| with length |inlen|.  This
6470  * function performs decompression.  For each successful emission of
6471  * header name/value pair,
6472  * :enum:`nghttp2_hd_inflate_flag.NGHTTP2_HD_INFLATE_EMIT` is set in
6473  * |*inflate_flags| and name/value pair is assigned to the |nv_out|
6474  * and the function returns.  The caller must not free the members of
6475  * |nv_out|.
6476  *
6477  * The |nv_out| may include pointers to the memory region in the |in|.
6478  * The caller must retain the |in| while the |nv_out| is used.
6479  *
6480  * The application should call this function repeatedly until the
6481  * ``(*inflate_flags) & NGHTTP2_HD_INFLATE_FINAL`` is nonzero and
6482  * return value is non-negative.  This means the all input values are
6483  * processed successfully.  Then the application must call
6484  * `nghttp2_hd_inflate_end_headers()` to prepare for the next header
6485  * block input.
6486  *
6487  * The caller can feed complete compressed header block.  It also can
6488  * feed it in several chunks.  The caller must set |in_final| to
6489  * nonzero if the given input is the last block of the compressed
6490  * header.
6491  *
6492  * This function returns the number of bytes processed if it succeeds,
6493  * or one of the following negative error codes:
6494  *
6495  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
6496  *     Out of memory.
6497  * :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`
6498  *     Inflation process has failed.
6499  * :enum:`nghttp2_error.NGHTTP2_ERR_BUFFER_ERROR`
6500  *     The header field name or value is too large.
6501  *
6502  * Example follows::
6503  *
6504  *     int inflate_header_block(nghttp2_hd_inflater *hd_inflater,
6505  *                              uint8_t *in, size_t inlen, int final)
6506  *     {
6507  *         ssize_t rv;
6508  *
6509  *         for(;;) {
6510  *             nghttp2_nv nv;
6511  *             int inflate_flags = 0;
6512  *
6513  *             rv = nghttp2_hd_inflate_hd(hd_inflater, &nv, &inflate_flags,
6514  *                                        in, inlen, final);
6515  *
6516  *             if(rv < 0) {
6517  *                 fprintf(stderr, "inflate failed with error code %zd", rv);
6518  *                 return -1;
6519  *             }
6520  *
6521  *             in += rv;
6522  *             inlen -= rv;
6523  *
6524  *             if(inflate_flags & NGHTTP2_HD_INFLATE_EMIT) {
6525  *                 fwrite(nv.name, nv.namelen, 1, stderr);
6526  *                 fprintf(stderr, ": ");
6527  *                 fwrite(nv.value, nv.valuelen, 1, stderr);
6528  *                 fprintf(stderr, "\n");
6529  *             }
6530  *             if(inflate_flags & NGHTTP2_HD_INFLATE_FINAL) {
6531  *                 nghttp2_hd_inflate_end_headers(hd_inflater);
6532  *                 break;
6533  *             }
6534  *             if((inflate_flags & NGHTTP2_HD_INFLATE_EMIT) == 0 &&
6535  *                inlen == 0) {
6536  *                break;
6537  *             }
6538  *         }
6539  *
6540  *         return 0;
6541  *     }
6542  *
6543  */
6544 NGHTTP2_EXTERN ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_inflater *inflater,
6545                                              nghttp2_nv *nv_out,
6546                                              int *inflate_flags, uint8_t *in,
6547                                              size_t inlen, int in_final);
6548 
6549 #endif /* NGHTTP2_NO_SSIZE_T */
6550 
6551 #ifndef NGHTTP2_NO_SSIZE_T
6552 /**
6553  * @function
6554  *
6555  * .. warning::
6556  *
6557  *   Deprecated.  Use `nghttp2_hd_inflate_hd3()` instead.
6558  *
6559  * Inflates name/value block stored in |in| with length |inlen|.  This
6560  * function performs decompression.  For each successful emission of
6561  * header name/value pair,
6562  * :enum:`nghttp2_hd_inflate_flag.NGHTTP2_HD_INFLATE_EMIT` is set in
6563  * |*inflate_flags| and name/value pair is assigned to the |nv_out|
6564  * and the function returns.  The caller must not free the members of
6565  * |nv_out|.
6566  *
6567  * The |nv_out| may include pointers to the memory region in the |in|.
6568  * The caller must retain the |in| while the |nv_out| is used.
6569  *
6570  * The application should call this function repeatedly until the
6571  * ``(*inflate_flags) & NGHTTP2_HD_INFLATE_FINAL`` is nonzero and
6572  * return value is non-negative.  If that happens, all given input
6573  * data (|inlen| bytes) are processed successfully.  Then the
6574  * application must call `nghttp2_hd_inflate_end_headers()` to prepare
6575  * for the next header block input.
6576  *
6577  * In other words, if |in_final| is nonzero, and this function returns
6578  * |inlen|, you can assert that
6579  * :enum:`nghttp2_hd_inflate_final.NGHTTP2_HD_INFLATE_FINAL` is set in
6580  * |*inflate_flags|.
6581  *
6582  * The caller can feed complete compressed header block.  It also can
6583  * feed it in several chunks.  The caller must set |in_final| to
6584  * nonzero if the given input is the last block of the compressed
6585  * header.
6586  *
6587  * This function returns the number of bytes processed if it succeeds,
6588  * or one of the following negative error codes:
6589  *
6590  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
6591  *     Out of memory.
6592  * :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`
6593  *     Inflation process has failed.
6594  * :enum:`nghttp2_error.NGHTTP2_ERR_BUFFER_ERROR`
6595  *     The header field name or value is too large.
6596  *
6597  * Example follows::
6598  *
6599  *     int inflate_header_block(nghttp2_hd_inflater *hd_inflater,
6600  *                              uint8_t *in, size_t inlen, int final)
6601  *     {
6602  *         ssize_t rv;
6603  *
6604  *         for(;;) {
6605  *             nghttp2_nv nv;
6606  *             int inflate_flags = 0;
6607  *
6608  *             rv = nghttp2_hd_inflate_hd2(hd_inflater, &nv, &inflate_flags,
6609  *                                         in, inlen, final);
6610  *
6611  *             if(rv < 0) {
6612  *                 fprintf(stderr, "inflate failed with error code %zd", rv);
6613  *                 return -1;
6614  *             }
6615  *
6616  *             in += rv;
6617  *             inlen -= rv;
6618  *
6619  *             if(inflate_flags & NGHTTP2_HD_INFLATE_EMIT) {
6620  *                 fwrite(nv.name, nv.namelen, 1, stderr);
6621  *                 fprintf(stderr, ": ");
6622  *                 fwrite(nv.value, nv.valuelen, 1, stderr);
6623  *                 fprintf(stderr, "\n");
6624  *             }
6625  *             if(inflate_flags & NGHTTP2_HD_INFLATE_FINAL) {
6626  *                 nghttp2_hd_inflate_end_headers(hd_inflater);
6627  *                 break;
6628  *             }
6629  *             if((inflate_flags & NGHTTP2_HD_INFLATE_EMIT) == 0 &&
6630  *                inlen == 0) {
6631  *                break;
6632  *             }
6633  *         }
6634  *
6635  *         return 0;
6636  *     }
6637  *
6638  */
6639 NGHTTP2_EXTERN ssize_t nghttp2_hd_inflate_hd2(nghttp2_hd_inflater *inflater,
6640                                               nghttp2_nv *nv_out,
6641                                               int *inflate_flags,
6642                                               const uint8_t *in, size_t inlen,
6643                                               int in_final);
6644 
6645 #endif /* NGHTTP2_NO_SSIZE_T */
6646 
6647 /**
6648  * @function
6649  *
6650  * Inflates name/value block stored in |in| with length |inlen|.  This
6651  * function performs decompression.  For each successful emission of
6652  * header name/value pair,
6653  * :enum:`nghttp2_hd_inflate_flag.NGHTTP2_HD_INFLATE_EMIT` is set in
6654  * |*inflate_flags| and name/value pair is assigned to the |nv_out|
6655  * and the function returns.  The caller must not free the members of
6656  * |nv_out|.
6657  *
6658  * The |nv_out| may include pointers to the memory region in the |in|.
6659  * The caller must retain the |in| while the |nv_out| is used.
6660  *
6661  * The application should call this function repeatedly until the
6662  * ``(*inflate_flags) & NGHTTP2_HD_INFLATE_FINAL`` is nonzero and
6663  * return value is non-negative.  If that happens, all given input
6664  * data (|inlen| bytes) are processed successfully.  Then the
6665  * application must call `nghttp2_hd_inflate_end_headers()` to prepare
6666  * for the next header block input.
6667  *
6668  * In other words, if |in_final| is nonzero, and this function returns
6669  * |inlen|, you can assert that
6670  * :enum:`nghttp2_hd_inflate_final.NGHTTP2_HD_INFLATE_FINAL` is set in
6671  * |*inflate_flags|.
6672  *
6673  * The caller can feed complete compressed header block.  It also can
6674  * feed it in several chunks.  The caller must set |in_final| to
6675  * nonzero if the given input is the last block of the compressed
6676  * header.
6677  *
6678  * This function returns the number of bytes processed if it succeeds,
6679  * or one of the following negative error codes:
6680  *
6681  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
6682  *     Out of memory.
6683  * :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`
6684  *     Inflation process has failed.
6685  * :enum:`nghttp2_error.NGHTTP2_ERR_BUFFER_ERROR`
6686  *     The header field name or value is too large.
6687  *
6688  * Example follows::
6689  *
6690  *     int inflate_header_block(nghttp2_hd_inflater *hd_inflater,
6691  *                              uint8_t *in, size_t inlen, int final)
6692  *     {
6693  *         nghttp2_ssize rv;
6694  *
6695  *         for(;;) {
6696  *             nghttp2_nv nv;
6697  *             int inflate_flags = 0;
6698  *
6699  *             rv = nghttp2_hd_inflate_hd3(hd_inflater, &nv, &inflate_flags,
6700  *                                         in, inlen, final);
6701  *
6702  *             if(rv < 0) {
6703  *                 fprintf(stderr, "inflate failed with error code %td", rv);
6704  *                 return -1;
6705  *             }
6706  *
6707  *             in += rv;
6708  *             inlen -= rv;
6709  *
6710  *             if(inflate_flags & NGHTTP2_HD_INFLATE_EMIT) {
6711  *                 fwrite(nv.name, nv.namelen, 1, stderr);
6712  *                 fprintf(stderr, ": ");
6713  *                 fwrite(nv.value, nv.valuelen, 1, stderr);
6714  *                 fprintf(stderr, "\n");
6715  *             }
6716  *             if(inflate_flags & NGHTTP2_HD_INFLATE_FINAL) {
6717  *                 nghttp2_hd_inflate_end_headers(hd_inflater);
6718  *                 break;
6719  *             }
6720  *             if((inflate_flags & NGHTTP2_HD_INFLATE_EMIT) == 0 &&
6721  *                inlen == 0) {
6722  *                break;
6723  *             }
6724  *         }
6725  *
6726  *         return 0;
6727  *     }
6728  *
6729  */
6730 NGHTTP2_EXTERN nghttp2_ssize nghttp2_hd_inflate_hd3(
6731     nghttp2_hd_inflater *inflater, nghttp2_nv *nv_out, int *inflate_flags,
6732     const uint8_t *in, size_t inlen, int in_final);
6733 
6734 /**
6735  * @function
6736  *
6737  * Signals the end of decompression for one header block.
6738  *
6739  * This function returns 0 if it succeeds. Currently this function
6740  * always succeeds.
6741  */
6742 NGHTTP2_EXTERN int
6743 nghttp2_hd_inflate_end_headers(nghttp2_hd_inflater *inflater);
6744 
6745 /**
6746  * @function
6747  *
6748  * Returns the number of entries that header table of |inflater|
6749  * contains.  This is the sum of the number of static table and
6750  * dynamic table, so the return value is at least 61.
6751  */
6752 NGHTTP2_EXTERN
6753 size_t nghttp2_hd_inflate_get_num_table_entries(nghttp2_hd_inflater *inflater);
6754 
6755 /**
6756  * @function
6757  *
6758  * Returns the table entry denoted by |idx| from header table of
6759  * |inflater|.  The |idx| is 1-based, and idx=1 returns first entry of
6760  * static table.  idx=62 returns first entry of dynamic table if it
6761  * exists.  Specifying idx=0 is error, and this function returns NULL.
6762  * If |idx| is strictly greater than the number of entries the tables
6763  * contain, this function returns NULL.
6764  */
6765 NGHTTP2_EXTERN
6766 const nghttp2_nv *
6767 nghttp2_hd_inflate_get_table_entry(nghttp2_hd_inflater *inflater, size_t idx);
6768 
6769 /**
6770  * @function
6771  *
6772  * Returns the used dynamic table size, including the overhead 32
6773  * bytes per entry described in RFC 7541.
6774  */
6775 NGHTTP2_EXTERN
6776 size_t nghttp2_hd_inflate_get_dynamic_table_size(nghttp2_hd_inflater *inflater);
6777 
6778 /**
6779  * @function
6780  *
6781  * Returns the maximum dynamic table size.
6782  */
6783 NGHTTP2_EXTERN
6784 size_t
6785 nghttp2_hd_inflate_get_max_dynamic_table_size(nghttp2_hd_inflater *inflater);
6786 
6787 struct nghttp2_stream;
6788 
6789 /**
6790  * @struct
6791  *
6792  * The structure to represent HTTP/2 stream.  The details of this
6793  * structure are intentionally hidden from the public API.
6794  */
6795 typedef struct nghttp2_stream nghttp2_stream;
6796 
6797 /**
6798  * @function
6799  *
6800  * Returns pointer to :type:`nghttp2_stream` object denoted by
6801  * |stream_id|.  If stream was not found, returns NULL.
6802  *
6803  * Returns imaginary root stream (see
6804  * `nghttp2_session_get_root_stream()`) if 0 is given in |stream_id|.
6805  *
6806  * Unless |stream_id| == 0, the returned pointer is valid until next
6807  * call of `nghttp2_session_send()`, `nghttp2_session_mem_send2()`,
6808  * `nghttp2_session_recv()`, and `nghttp2_session_mem_recv2()`.
6809  */
6810 NGHTTP2_EXTERN nghttp2_stream *
6811 nghttp2_session_find_stream(nghttp2_session *session, int32_t stream_id);
6812 
6813 /**
6814  * @enum
6815  *
6816  * State of stream as described in RFC 7540.
6817  */
6818 typedef enum {
6819   /**
6820    * idle state.
6821    */
6822   NGHTTP2_STREAM_STATE_IDLE = 1,
6823   /**
6824    * open state.
6825    */
6826   NGHTTP2_STREAM_STATE_OPEN,
6827   /**
6828    * reserved (local) state.
6829    */
6830   NGHTTP2_STREAM_STATE_RESERVED_LOCAL,
6831   /**
6832    * reserved (remote) state.
6833    */
6834   NGHTTP2_STREAM_STATE_RESERVED_REMOTE,
6835   /**
6836    * half closed (local) state.
6837    */
6838   NGHTTP2_STREAM_STATE_HALF_CLOSED_LOCAL,
6839   /**
6840    * half closed (remote) state.
6841    */
6842   NGHTTP2_STREAM_STATE_HALF_CLOSED_REMOTE,
6843   /**
6844    * closed state.
6845    */
6846   NGHTTP2_STREAM_STATE_CLOSED
6847 } nghttp2_stream_proto_state;
6848 
6849 /**
6850  * @function
6851  *
6852  * Returns state of |stream|.  The root stream retrieved by
6853  * `nghttp2_session_get_root_stream()` will have stream state
6854  * :enum:`nghttp2_stream_proto_state.NGHTTP2_STREAM_STATE_IDLE`.
6855  */
6856 NGHTTP2_EXTERN nghttp2_stream_proto_state
6857 nghttp2_stream_get_state(nghttp2_stream *stream);
6858 
6859 /**
6860  * @function
6861  *
6862  * .. warning::
6863  *
6864  *   Deprecated.  :rfc:`7540` priorities are deprecated by
6865  *   :rfc:`9113`.  Consider migrating to :rfc:`9218` extensible
6866  *   prioritization scheme.
6867  *
6868  * Returns root of dependency tree, which is imaginary stream with
6869  * stream ID 0.  The returned pointer is valid until |session| is
6870  * freed by `nghttp2_session_del()`.
6871  */
6872 NGHTTP2_EXTERN nghttp2_stream *
6873 nghttp2_session_get_root_stream(nghttp2_session *session);
6874 
6875 /**
6876  * @function
6877  *
6878  * .. warning::
6879  *
6880  *   Deprecated.  :rfc:`7540` priorities are deprecated by
6881  *   :rfc:`9113`.  Consider migrating to :rfc:`9218` extensible
6882  *   prioritization scheme.  In the future release after the end of
6883  *   2024, this function will always return NULL.
6884  *
6885  * Returns the parent stream of |stream| in dependency tree.  Returns
6886  * NULL if there is no such stream.
6887  */
6888 NGHTTP2_EXTERN nghttp2_stream *
6889 nghttp2_stream_get_parent(nghttp2_stream *stream);
6890 
6891 NGHTTP2_EXTERN int32_t nghttp2_stream_get_stream_id(nghttp2_stream *stream);
6892 
6893 /**
6894  * @function
6895  *
6896  * .. warning::
6897  *
6898  *   Deprecated.  :rfc:`7540` priorities are deprecated by
6899  *   :rfc:`9113`.  Consider migrating to :rfc:`9218` extensible
6900  *   prioritization scheme.  In the future release after the end of
6901  *   2024, this function will always return NULL.
6902  *
6903  * Returns the next sibling stream of |stream| in dependency tree.
6904  * Returns NULL if there is no such stream.
6905  */
6906 NGHTTP2_EXTERN nghttp2_stream *
6907 nghttp2_stream_get_next_sibling(nghttp2_stream *stream);
6908 
6909 /**
6910  * @function
6911  *
6912  * .. warning::
6913  *
6914  *   Deprecated.  :rfc:`7540` priorities are deprecated by
6915  *   :rfc:`9113`.  Consider migrating to :rfc:`9218` extensible
6916  *   prioritization scheme.  In the future release after the end of
6917  *   2024, this function will always return NULL.
6918  *
6919  * Returns the previous sibling stream of |stream| in dependency tree.
6920  * Returns NULL if there is no such stream.
6921  */
6922 NGHTTP2_EXTERN nghttp2_stream *
6923 nghttp2_stream_get_previous_sibling(nghttp2_stream *stream);
6924 
6925 /**
6926  * @function
6927  *
6928  * .. warning::
6929  *
6930  *   Deprecated.  :rfc:`7540` priorities are deprecated by
6931  *   :rfc:`9113`.  Consider migrating to :rfc:`9218` extensible
6932  *   prioritization scheme.  In the future release after the end of
6933  *   2024, this function will always return NULL.
6934  *
6935  * Returns the first child stream of |stream| in dependency tree.
6936  * Returns NULL if there is no such stream.
6937  */
6938 NGHTTP2_EXTERN nghttp2_stream *
6939 nghttp2_stream_get_first_child(nghttp2_stream *stream);
6940 
6941 /**
6942  * @function
6943  *
6944  * .. warning::
6945  *
6946  *   Deprecated.  :rfc:`7540` priorities are deprecated by
6947  *   :rfc:`9113`.  Consider migrating to :rfc:`9218` extensible
6948  *   prioritization scheme.  In the future release after the end of
6949  *   2024, this function will always return
6950  *   :macro:`NGHTTP2_DEFAULT_WEIGHT`.
6951  *
6952  * Returns dependency weight to the parent stream of |stream|.
6953  */
6954 NGHTTP2_EXTERN int32_t nghttp2_stream_get_weight(nghttp2_stream *stream);
6955 
6956 /**
6957  * @function
6958  *
6959  * .. warning::
6960  *
6961  *   Deprecated.  :rfc:`7540` priorities are deprecated by
6962  *   :rfc:`9113`.  Consider migrating to :rfc:`9218` extensible
6963  *   prioritization scheme.  In the future release after the end of
6964  *   2024, this function will always return 0.
6965  *
6966  * Returns the sum of the weight for |stream|'s children.
6967  */
6968 NGHTTP2_EXTERN int32_t
6969 nghttp2_stream_get_sum_dependency_weight(nghttp2_stream *stream);
6970 
6971 /**
6972  * @functypedef
6973  *
6974  * Callback function invoked when the library outputs debug logging.
6975  * The function is called with arguments suitable for ``vfprintf(3)``
6976  *
6977  * The debug output is only enabled if the library is built with
6978  * ``DEBUGBUILD`` macro defined.
6979  */
6980 typedef void (*nghttp2_debug_vprintf_callback)(const char *format,
6981                                                va_list args);
6982 
6983 /**
6984  * @function
6985  *
6986  * Sets a debug output callback called by the library when built with
6987  * ``DEBUGBUILD`` macro defined.  If this option is not used, debug
6988  * log is written into standard error output.
6989  *
6990  * For builds without ``DEBUGBUILD`` macro defined, this function is
6991  * noop.
6992  *
6993  * Note that building with ``DEBUGBUILD`` may cause significant
6994  * performance penalty to libnghttp2 because of extra processing.  It
6995  * should be used for debugging purpose only.
6996  *
6997  * .. Warning::
6998  *
6999  *   Building with ``DEBUGBUILD`` may cause significant performance
7000  *   penalty to libnghttp2 because of extra processing.  It should be
7001  *   used for debugging purpose only.  We write this two times because
7002  *   this is important.
7003  */
7004 NGHTTP2_EXTERN void nghttp2_set_debug_vprintf_callback(
7005     nghttp2_debug_vprintf_callback debug_vprintf_callback);
7006 
7007 #ifdef __cplusplus
7008 }
7009 #endif
7010 
7011 #endif /* NGHTTP2_H */