Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 09:19:48

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) ||                                                        \
0061   (__has_declspec_attribute(dllexport) && __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  * .. warning::
3137  *
3138  *   Deprecated.  Closed streams are not retained anymore.
3139  *
3140  * This function works as before, but it does not take any effect
3141  * against :type:`nghttp2_session`.
3142  */
3143 NGHTTP2_EXTERN void nghttp2_option_set_no_closed_streams(nghttp2_option *option,
3144                                                          int val);
3145 
3146 /**
3147  * @function
3148  *
3149  * This function sets the maximum number of outgoing SETTINGS ACK and
3150  * PING ACK frames retained in :type:`nghttp2_session` object.  If
3151  * more than those frames are retained, the peer is considered to be
3152  * misbehaving and session will be closed.  The default value is 1000.
3153  */
3154 NGHTTP2_EXTERN void nghttp2_option_set_max_outbound_ack(nghttp2_option *option,
3155                                                         size_t val);
3156 
3157 /**
3158  * @function
3159  *
3160  * This function sets the maximum number of SETTINGS entries per
3161  * SETTINGS frame that will be accepted. If more than those entries
3162  * are received, the peer is considered to be misbehaving and session
3163  * will be closed. The default value is 32.
3164  */
3165 NGHTTP2_EXTERN void nghttp2_option_set_max_settings(nghttp2_option *option,
3166                                                     size_t val);
3167 
3168 /**
3169  * @function
3170  *
3171  * .. warning::
3172  *    Deprecated.  :rfc:`7540` priorities have been removed.
3173  *
3174  * This function works as before, but it does not take any effect
3175  * against :type:`nghttp2_session`.
3176  */
3177 NGHTTP2_EXTERN void
3178 nghttp2_option_set_server_fallback_rfc7540_priorities(nghttp2_option *option,
3179                                                       int val);
3180 
3181 /**
3182  * @function
3183  *
3184  * This option, if set to nonzero, turns off RFC 9113 leading and
3185  * trailing white spaces validation against HTTP field value.  Some
3186  * important fields, such as HTTP/2 pseudo header fields, are
3187  * validated more strictly and this option does not apply to them.
3188  */
3189 NGHTTP2_EXTERN void
3190 nghttp2_option_set_no_rfc9113_leading_and_trailing_ws_validation(
3191   nghttp2_option *option, int val);
3192 
3193 /**
3194  * @function
3195  *
3196  * This function sets the rate limit for the incoming stream reset
3197  * (RST_STREAM frame).  It is server use only.  It is a token-bucket
3198  * based rate limiter.  |burst| specifies the number of tokens that is
3199  * initially available.  The maximum number of tokens is capped to
3200  * this value.  |rate| specifies the number of tokens that are
3201  * regenerated per second.  An incoming RST_STREAM consumes one token.
3202  * If there is no token available, GOAWAY is sent to tear down the
3203  * connection.  |burst| and |rate| default to 1000 and 33
3204  * respectively.
3205  */
3206 NGHTTP2_EXTERN void
3207 nghttp2_option_set_stream_reset_rate_limit(nghttp2_option *option,
3208                                            uint64_t burst, uint64_t rate);
3209 
3210 /**
3211  * @function
3212  *
3213  * This function sets the maximum number of CONTINUATION frames
3214  * following an incoming HEADER frame.  If more than those frames are
3215  * received, the remote endpoint is considered to be misbehaving and
3216  * session will be closed.  The default value is 8.
3217  */
3218 NGHTTP2_EXTERN void nghttp2_option_set_max_continuations(nghttp2_option *option,
3219                                                          size_t val);
3220 
3221 /**
3222  * @function
3223  *
3224  * Initializes |*session_ptr| for client use.  The all members of
3225  * |callbacks| are copied to |*session_ptr|.  Therefore |*session_ptr|
3226  * does not store |callbacks|.  The |user_data| is an arbitrary user
3227  * supplied data, which will be passed to the callback functions.
3228  *
3229  * The :type:`nghttp2_send_callback2` must be specified.  If the
3230  * application code uses `nghttp2_session_recv()`, the
3231  * :type:`nghttp2_recv_callback` must be specified.  The other members
3232  * of |callbacks| can be ``NULL``.
3233  *
3234  * If this function fails, |*session_ptr| is left untouched.
3235  *
3236  * This function returns 0 if it succeeds, or one of the following
3237  * negative error codes:
3238  *
3239  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
3240  *     Out of memory.
3241  */
3242 NGHTTP2_EXTERN int
3243 nghttp2_session_client_new(nghttp2_session **session_ptr,
3244                            const nghttp2_session_callbacks *callbacks,
3245                            void *user_data);
3246 
3247 /**
3248  * @function
3249  *
3250  * Initializes |*session_ptr| for server use.  The all members of
3251  * |callbacks| are copied to |*session_ptr|. Therefore |*session_ptr|
3252  * does not store |callbacks|.  The |user_data| is an arbitrary user
3253  * supplied data, which will be passed to the callback functions.
3254  *
3255  * The :type:`nghttp2_send_callback2` must be specified.  If the
3256  * application code uses `nghttp2_session_recv()`, the
3257  * :type:`nghttp2_recv_callback` must be specified.  The other members
3258  * of |callbacks| can be ``NULL``.
3259  *
3260  * If this function fails, |*session_ptr| is left untouched.
3261  *
3262  * This function returns 0 if it succeeds, or one of the following
3263  * negative error codes:
3264  *
3265  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
3266  *     Out of memory.
3267  */
3268 NGHTTP2_EXTERN int
3269 nghttp2_session_server_new(nghttp2_session **session_ptr,
3270                            const nghttp2_session_callbacks *callbacks,
3271                            void *user_data);
3272 
3273 /**
3274  * @function
3275  *
3276  * Like `nghttp2_session_client_new()`, but with additional options
3277  * specified in the |option|.
3278  *
3279  * The |option| can be ``NULL`` and the call is equivalent to
3280  * `nghttp2_session_client_new()`.
3281  *
3282  * This function does not take ownership |option|.  The application is
3283  * responsible for freeing |option| if it finishes using the object.
3284  *
3285  * The library code does not refer to |option| after this function
3286  * returns.
3287  *
3288  * This function returns 0 if it succeeds, or one of the following
3289  * negative error codes:
3290  *
3291  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
3292  *     Out of memory.
3293  */
3294 NGHTTP2_EXTERN int
3295 nghttp2_session_client_new2(nghttp2_session **session_ptr,
3296                             const nghttp2_session_callbacks *callbacks,
3297                             void *user_data, const nghttp2_option *option);
3298 
3299 /**
3300  * @function
3301  *
3302  * Like `nghttp2_session_server_new()`, but with additional options
3303  * specified in the |option|.
3304  *
3305  * The |option| can be ``NULL`` and the call is equivalent to
3306  * `nghttp2_session_server_new()`.
3307  *
3308  * This function does not take ownership |option|.  The application is
3309  * responsible for freeing |option| if it finishes using the object.
3310  *
3311  * The library code does not refer to |option| after this function
3312  * returns.
3313  *
3314  * This function returns 0 if it succeeds, or one of the following
3315  * negative error codes:
3316  *
3317  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
3318  *     Out of memory.
3319  */
3320 NGHTTP2_EXTERN int
3321 nghttp2_session_server_new2(nghttp2_session **session_ptr,
3322                             const nghttp2_session_callbacks *callbacks,
3323                             void *user_data, const nghttp2_option *option);
3324 
3325 /**
3326  * @function
3327  *
3328  * Like `nghttp2_session_client_new2()`, but with additional custom
3329  * memory allocator specified in the |mem|.
3330  *
3331  * The |mem| can be ``NULL`` and the call is equivalent to
3332  * `nghttp2_session_client_new2()`.
3333  *
3334  * This function does not take ownership |mem|.  The application is
3335  * responsible for freeing |mem|.
3336  *
3337  * The library code does not refer to |mem| pointer after this
3338  * function returns, so the application can safely free it.
3339  *
3340  * This function returns 0 if it succeeds, or one of the following
3341  * negative error codes:
3342  *
3343  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
3344  *     Out of memory.
3345  */
3346 NGHTTP2_EXTERN int nghttp2_session_client_new3(
3347   nghttp2_session **session_ptr, const nghttp2_session_callbacks *callbacks,
3348   void *user_data, const nghttp2_option *option, nghttp2_mem *mem);
3349 
3350 /**
3351  * @function
3352  *
3353  * Like `nghttp2_session_server_new2()`, but with additional custom
3354  * memory allocator specified in the |mem|.
3355  *
3356  * The |mem| can be ``NULL`` and the call is equivalent to
3357  * `nghttp2_session_server_new2()`.
3358  *
3359  * This function does not take ownership |mem|.  The application is
3360  * responsible for freeing |mem|.
3361  *
3362  * The library code does not refer to |mem| pointer after this
3363  * function returns, so the application can safely free it.
3364  *
3365  * This function returns 0 if it succeeds, or one of the following
3366  * negative error codes:
3367  *
3368  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
3369  *     Out of memory.
3370  */
3371 NGHTTP2_EXTERN int nghttp2_session_server_new3(
3372   nghttp2_session **session_ptr, const nghttp2_session_callbacks *callbacks,
3373   void *user_data, const nghttp2_option *option, nghttp2_mem *mem);
3374 
3375 /**
3376  * @function
3377  *
3378  * Frees any resources allocated for |session|.  If |session| is
3379  * ``NULL``, this function does nothing.
3380  */
3381 NGHTTP2_EXTERN void nghttp2_session_del(nghttp2_session *session);
3382 
3383 /**
3384  * @function
3385  *
3386  * Sends pending frames to the remote peer.
3387  *
3388  * This function retrieves the highest prioritized frame from the
3389  * outbound queue and sends it to the remote peer.  It does this as
3390  * many times as possible until the user callback
3391  * :type:`nghttp2_send_callback2` returns
3392  * :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`, the outbound queue
3393  * becomes empty or flow control is triggered (remote window size
3394  * becomes depleted or maximum number of concurrent streams is
3395  * reached).  This function calls several callback functions which are
3396  * passed when initializing the |session|.  Here is the simple time
3397  * chart which tells when each callback is invoked:
3398  *
3399  * 1. Get the next frame to send from outbound queue.
3400  *
3401  * 2. Prepare transmission of the frame.
3402  *
3403  * 3. If the control frame cannot be sent because some preconditions
3404  *    are not met (e.g., request HEADERS cannot be sent after GOAWAY),
3405  *    :type:`nghttp2_on_frame_not_send_callback` is invoked.  Abort
3406  *    the following steps.
3407  *
3408  * 4. If the frame is HEADERS, PUSH_PROMISE or DATA,
3409  *    :type:`nghttp2_select_padding_callback` is invoked.
3410  *
3411  * 5. If the frame is request HEADERS, the stream is opened here.
3412  *
3413  * 6. :type:`nghttp2_before_frame_send_callback` is invoked.
3414  *
3415  * 7. If :enum:`nghttp2_error.NGHTTP2_ERR_CANCEL` is returned from
3416  *    :type:`nghttp2_before_frame_send_callback`, the current frame
3417  *    transmission is canceled, and
3418  *    :type:`nghttp2_on_frame_not_send_callback` is invoked.  Abort
3419  *    the following steps.
3420  *
3421  * 8. :type:`nghttp2_send_callback2` is invoked one or more times to
3422  *    send the frame.
3423  *
3424  * 9. :type:`nghttp2_on_frame_send_callback` is invoked.
3425  *
3426  * 10. If the transmission of the frame triggers closure of the
3427  *     stream, the stream is closed and
3428  *     :type:`nghttp2_on_stream_close_callback` is invoked.
3429  *
3430  * This function returns 0 if it succeeds, or one of the following
3431  * negative error codes:
3432  *
3433  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
3434  *     Out of memory.
3435  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`
3436  *     The callback function failed.
3437  */
3438 NGHTTP2_EXTERN int nghttp2_session_send(nghttp2_session *session);
3439 
3440 #ifndef NGHTTP2_NO_SSIZE_T
3441 /**
3442  * @function
3443  *
3444  * .. warning::
3445  *
3446  *   Deprecated.  Use `nghttp2_session_mem_send2()` instead.
3447  *
3448  * Returns the serialized data to send.
3449  *
3450  * This function behaves like `nghttp2_session_send()` except that it
3451  * does not use :type:`nghttp2_send_callback` to transmit data.
3452  * Instead, it assigns the pointer to the serialized data to the
3453  * |*data_ptr| and returns its length.  The other callbacks are called
3454  * in the same way as they are in `nghttp2_session_send()`.
3455  *
3456  * If no data is available to send, this function returns 0.
3457  *
3458  * This function may not return all serialized data in one invocation.
3459  * To get all data, call this function repeatedly until it returns 0
3460  * or one of negative error codes.
3461  *
3462  * The assigned |*data_ptr| is valid until the next call of
3463  * `nghttp2_session_mem_send()` or `nghttp2_session_send()`.
3464  *
3465  * The caller must send all data before sending the next chunk of
3466  * data.
3467  *
3468  * This function returns the length of the data pointed by the
3469  * |*data_ptr| if it succeeds, or one of the following negative error
3470  * codes:
3471  *
3472  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
3473  *     Out of memory.
3474  *
3475  * .. note::
3476  *
3477  *   This function may produce very small byte string.  If that is the
3478  *   case, and application disables Nagle algorithm (``TCP_NODELAY``),
3479  *   then writing this small chunk leads to very small packet, and it
3480  *   is very inefficient.  An application should be responsible to
3481  *   buffer up small chunks of data as necessary to avoid this
3482  *   situation.
3483  */
3484 NGHTTP2_EXTERN ssize_t nghttp2_session_mem_send(nghttp2_session *session,
3485                                                 const uint8_t **data_ptr);
3486 
3487 #endif /* NGHTTP2_NO_SSIZE_T */
3488 
3489 /**
3490  * @function
3491  *
3492  * Returns the serialized data to send.
3493  *
3494  * This function behaves like `nghttp2_session_send()` except that it
3495  * does not use :type:`nghttp2_send_callback2` to transmit data.
3496  * Instead, it assigns the pointer to the serialized data to the
3497  * |*data_ptr| and returns its length.  The other callbacks are called
3498  * in the same way as they are in `nghttp2_session_send()`.
3499  *
3500  * If no data is available to send, this function returns 0.
3501  *
3502  * This function may not return all serialized data in one invocation.
3503  * To get all data, call this function repeatedly until it returns 0
3504  * or one of negative error codes.
3505  *
3506  * The assigned |*data_ptr| is valid until the next call of
3507  * `nghttp2_session_mem_send2()` or `nghttp2_session_send()`.
3508  *
3509  * The caller must send all data before sending the next chunk of
3510  * data.
3511  *
3512  * This function returns the length of the data pointed by the
3513  * |*data_ptr| if it succeeds, or one of the following negative error
3514  * codes:
3515  *
3516  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
3517  *     Out of memory.
3518  *
3519  * .. note::
3520  *
3521  *   This function may produce very small byte string.  If that is the
3522  *   case, and application disables Nagle algorithm (``TCP_NODELAY``),
3523  *   then writing this small chunk leads to very small packet, and it
3524  *   is very inefficient.  An application should be responsible to
3525  *   buffer up small chunks of data as necessary to avoid this
3526  *   situation.
3527  */
3528 NGHTTP2_EXTERN nghttp2_ssize
3529 nghttp2_session_mem_send2(nghttp2_session *session, const uint8_t **data_ptr);
3530 
3531 /**
3532  * @function
3533  *
3534  * Receives frames from the remote peer.
3535  *
3536  * This function receives as many frames as possible until the user
3537  * callback :type:`nghttp2_recv_callback` returns
3538  * :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`.  This function calls
3539  * several callback functions which are passed when initializing the
3540  * |session|.  Here is the simple time chart which tells when each
3541  * callback is invoked:
3542  *
3543  * 1. :type:`nghttp2_recv_callback` is invoked one or more times to
3544  *    receive frame header.
3545  *
3546  * 2. When frame header is received,
3547  *    :type:`nghttp2_on_begin_frame_callback` is invoked.
3548  *
3549  * 3. If the frame is DATA frame:
3550  *
3551  *    1. :type:`nghttp2_recv_callback` is invoked to receive DATA
3552  *       payload. For each chunk of data,
3553  *       :type:`nghttp2_on_data_chunk_recv_callback` is invoked.
3554  *
3555  *    2. If one DATA frame is completely received,
3556  *       :type:`nghttp2_on_frame_recv_callback` is invoked.  If the
3557  *       reception of the frame triggers the closure of the stream,
3558  *       :type:`nghttp2_on_stream_close_callback` is invoked.
3559  *
3560  * 4. If the frame is the control frame:
3561  *
3562  *    1. :type:`nghttp2_recv_callback` is invoked one or more times to
3563  *       receive whole frame.
3564  *
3565  *    2. If the received frame is valid, then following actions are
3566  *       taken.  If the frame is either HEADERS or PUSH_PROMISE,
3567  *       :type:`nghttp2_on_begin_headers_callback` is invoked.  Then
3568  *       :type:`nghttp2_on_header_callback` is invoked for each header
3569  *       name/value pair.  For invalid header field,
3570  *       :type:`nghttp2_on_invalid_header_callback` is called.  After
3571  *       all name/value pairs are emitted successfully,
3572  *       :type:`nghttp2_on_frame_recv_callback` is invoked.  For other
3573  *       frames, :type:`nghttp2_on_frame_recv_callback` is invoked.
3574  *       If the reception of the frame triggers the closure of the
3575  *       stream, :type:`nghttp2_on_stream_close_callback` is invoked.
3576  *
3577  *    3. If the received frame is unpacked but is interpreted as
3578  *       invalid, :type:`nghttp2_on_invalid_frame_recv_callback` is
3579  *       invoked.
3580  *
3581  * This function returns 0 if it succeeds, or one of the following
3582  * negative error codes:
3583  *
3584  * :enum:`nghttp2_error.NGHTTP2_ERR_EOF`
3585  *     The remote peer did shutdown on the connection.
3586  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
3587  *     Out of memory.
3588  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`
3589  *     The callback function failed.
3590  * :enum:`nghttp2_error.NGHTTP2_ERR_BAD_CLIENT_MAGIC`
3591  *     Invalid client magic was detected.  This error only returns
3592  *     when |session| was configured as server and
3593  *     `nghttp2_option_set_no_recv_client_magic()` is not used with
3594  *     nonzero value.
3595  * :enum:`nghttp2_error.NGHTTP2_ERR_FLOODED`
3596  *     Flooding was detected in this HTTP/2 session, and it must be
3597  *     closed.  This is most likely caused by misbehaviour of peer.
3598  */
3599 NGHTTP2_EXTERN int nghttp2_session_recv(nghttp2_session *session);
3600 
3601 #ifndef NGHTTP2_NO_SSIZE_T
3602 /**
3603  * @function
3604  *
3605  * .. warning::
3606  *
3607  *   Deprecated.  Use `nghttp2_session_mem_recv2()` instead.
3608  *
3609  * Processes data |in| as an input from the remote endpoint.  The
3610  * |inlen| indicates the number of bytes to receive in the |in|.
3611  *
3612  * This function behaves like `nghttp2_session_recv()` except that it
3613  * does not use :type:`nghttp2_recv_callback` to receive data; the
3614  * |in| is the only data for the invocation of this function.  If all
3615  * bytes are processed, this function returns.  The other callbacks
3616  * are called in the same way as they are in `nghttp2_session_recv()`.
3617  *
3618  * In the current implementation, this function always tries to
3619  * processes |inlen| bytes of input data unless either an error occurs or
3620  * :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` is returned from
3621  * :type:`nghttp2_on_header_callback` or
3622  * :type:`nghttp2_on_data_chunk_recv_callback`.  If
3623  * :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` is used, the return value
3624  * includes the number of bytes which was used to produce the data or
3625  * frame for the callback.
3626  *
3627  * This function returns the number of processed bytes, or one of the
3628  * following negative error codes:
3629  *
3630  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
3631  *     Out of memory.
3632  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`
3633  *     The callback function failed.
3634  * :enum:`nghttp2_error.NGHTTP2_ERR_BAD_CLIENT_MAGIC`
3635  *     Invalid client magic was detected.  This error only returns
3636  *     when |session| was configured as server and
3637  *     `nghttp2_option_set_no_recv_client_magic()` is not used with
3638  *     nonzero value.
3639  * :enum:`nghttp2_error.NGHTTP2_ERR_FLOODED`
3640  *     Flooding was detected in this HTTP/2 session, and it must be
3641  *     closed.  This is most likely caused by misbehaviour of peer.
3642  */
3643 NGHTTP2_EXTERN ssize_t nghttp2_session_mem_recv(nghttp2_session *session,
3644                                                 const uint8_t *in,
3645                                                 size_t inlen);
3646 
3647 #endif /* NGHTTP2_NO_SSIZE_T */
3648 
3649 /**
3650  * @function
3651  *
3652  * Processes data |in| as an input from the remote endpoint.  The
3653  * |inlen| indicates the number of bytes to receive in the |in|.
3654  *
3655  * This function behaves like `nghttp2_session_recv()` except that it
3656  * does not use :type:`nghttp2_recv_callback` to receive data; the
3657  * |in| is the only data for the invocation of this function.  If all
3658  * bytes are processed, this function returns.  The other callbacks
3659  * are called in the same way as they are in `nghttp2_session_recv()`.
3660  *
3661  * In the current implementation, this function always tries to
3662  * processes |inlen| bytes of input data unless either an error occurs or
3663  * :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` is returned from
3664  * :type:`nghttp2_on_header_callback` or
3665  * :type:`nghttp2_on_data_chunk_recv_callback`.  If
3666  * :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` is used, the return value
3667  * includes the number of bytes which was used to produce the data or
3668  * frame for the callback.
3669  *
3670  * This function returns the number of processed bytes, or one of the
3671  * following negative error codes:
3672  *
3673  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
3674  *     Out of memory.
3675  * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`
3676  *     The callback function failed.
3677  * :enum:`nghttp2_error.NGHTTP2_ERR_BAD_CLIENT_MAGIC`
3678  *     Invalid client magic was detected.  This error only returns
3679  *     when |session| was configured as server and
3680  *     `nghttp2_option_set_no_recv_client_magic()` is not used with
3681  *     nonzero value.
3682  * :enum:`nghttp2_error.NGHTTP2_ERR_FLOODED`
3683  *     Flooding was detected in this HTTP/2 session, and it must be
3684  *     closed.  This is most likely caused by misbehaviour of peer.
3685  */
3686 NGHTTP2_EXTERN nghttp2_ssize nghttp2_session_mem_recv2(nghttp2_session *session,
3687                                                        const uint8_t *in,
3688                                                        size_t inlen);
3689 
3690 /**
3691  * @function
3692  *
3693  * Puts back previously deferred DATA frame in the stream |stream_id|
3694  * to the outbound queue.
3695  *
3696  * This function returns 0 if it succeeds, or one of the following
3697  * negative error codes:
3698  *
3699  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
3700  *     The stream does not exist; or no deferred data exist.
3701  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
3702  *     Out of memory.
3703  */
3704 NGHTTP2_EXTERN int nghttp2_session_resume_data(nghttp2_session *session,
3705                                                int32_t stream_id);
3706 
3707 /**
3708  * @function
3709  *
3710  * Returns nonzero value if |session| wants to receive data from the
3711  * remote peer.
3712  *
3713  * If both `nghttp2_session_want_read()` and
3714  * `nghttp2_session_want_write()` return 0, the application should
3715  * drop the connection.
3716  */
3717 NGHTTP2_EXTERN int nghttp2_session_want_read(nghttp2_session *session);
3718 
3719 /**
3720  * @function
3721  *
3722  * Returns nonzero value if |session| wants to send data to the remote
3723  * peer.
3724  *
3725  * If both `nghttp2_session_want_read()` and
3726  * `nghttp2_session_want_write()` return 0, the application should
3727  * drop the connection.
3728  */
3729 NGHTTP2_EXTERN int nghttp2_session_want_write(nghttp2_session *session);
3730 
3731 /**
3732  * @function
3733  *
3734  * Returns stream_user_data for the stream |stream_id|.  The
3735  * stream_user_data is provided by `nghttp2_submit_request2()`,
3736  * `nghttp2_submit_headers()` or
3737  * `nghttp2_session_set_stream_user_data()`.  Unless it is set using
3738  * `nghttp2_session_set_stream_user_data()`, if the stream is
3739  * initiated by the remote endpoint, stream_user_data is always
3740  * ``NULL``.  If the stream does not exist, this function returns
3741  * ``NULL``.
3742  */
3743 NGHTTP2_EXTERN void *
3744 nghttp2_session_get_stream_user_data(nghttp2_session *session,
3745                                      int32_t stream_id);
3746 
3747 /**
3748  * @function
3749  *
3750  * Sets the |stream_user_data| to the stream denoted by the
3751  * |stream_id|.  If a stream user data is already set to the stream,
3752  * it is replaced with the |stream_user_data|.  It is valid to specify
3753  * ``NULL`` in the |stream_user_data|, which nullifies the associated
3754  * data pointer.
3755  *
3756  * It is valid to set the |stream_user_data| to the stream reserved by
3757  * PUSH_PROMISE frame.
3758  *
3759  * This function returns 0 if it succeeds, or one of following
3760  * negative error codes:
3761  *
3762  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
3763  *     The stream does not exist
3764  */
3765 NGHTTP2_EXTERN int
3766 nghttp2_session_set_stream_user_data(nghttp2_session *session,
3767                                      int32_t stream_id, void *stream_user_data);
3768 
3769 /**
3770  * @function
3771  *
3772  * Sets |user_data| to |session|, overwriting the existing user data
3773  * specified in `nghttp2_session_client_new()`, or
3774  * `nghttp2_session_server_new()`.
3775  */
3776 NGHTTP2_EXTERN void nghttp2_session_set_user_data(nghttp2_session *session,
3777                                                   void *user_data);
3778 
3779 /**
3780  * @function
3781  *
3782  * Returns the number of frames in the outbound queue.  This does not
3783  * include the deferred DATA frames.
3784  */
3785 NGHTTP2_EXTERN size_t
3786 nghttp2_session_get_outbound_queue_size(nghttp2_session *session);
3787 
3788 /**
3789  * @function
3790  *
3791  * Returns the number of DATA payload in bytes received without
3792  * WINDOW_UPDATE transmission for the stream |stream_id|.  The local
3793  * (receive) window size can be adjusted by
3794  * `nghttp2_submit_window_update()`.  This function takes into account
3795  * that and returns effective data length.  In particular, if the
3796  * local window size is reduced by submitting negative
3797  * window_size_increment with `nghttp2_submit_window_update()`, this
3798  * function returns the number of bytes less than actually received.
3799  *
3800  * This function returns -1 if it fails.
3801  */
3802 NGHTTP2_EXTERN int32_t nghttp2_session_get_stream_effective_recv_data_length(
3803   nghttp2_session *session, int32_t stream_id);
3804 
3805 /**
3806  * @function
3807  *
3808  * Returns the local (receive) window size for the stream |stream_id|.
3809  * The local window size can be adjusted by
3810  * `nghttp2_submit_window_update()`.  This function takes into account
3811  * that and returns effective window size.
3812  *
3813  * This function does not take into account the amount of received
3814  * data from the remote endpoint.  Use
3815  * `nghttp2_session_get_stream_local_window_size()` to know the amount
3816  * of data the remote endpoint can send without receiving stream level
3817  * WINDOW_UPDATE frame.  Note that each stream is still subject to the
3818  * connection level flow control.
3819  *
3820  * This function returns -1 if it fails.
3821  */
3822 NGHTTP2_EXTERN int32_t nghttp2_session_get_stream_effective_local_window_size(
3823   nghttp2_session *session, int32_t stream_id);
3824 
3825 /**
3826  * @function
3827  *
3828  * Returns the amount of flow-controlled payload (e.g., DATA) that the
3829  * remote endpoint can send without receiving stream level
3830  * WINDOW_UPDATE frame.  It is also subject to the connection level
3831  * flow control.  So the actual amount of data to send is
3832  * min(`nghttp2_session_get_stream_local_window_size()`,
3833  * `nghttp2_session_get_local_window_size()`).
3834  *
3835  * This function returns -1 if it fails.
3836  */
3837 NGHTTP2_EXTERN int32_t nghttp2_session_get_stream_local_window_size(
3838   nghttp2_session *session, int32_t stream_id);
3839 
3840 /**
3841  * @function
3842  *
3843  * Returns the number of DATA payload in bytes received without
3844  * WINDOW_UPDATE transmission for a connection.  The local (receive)
3845  * window size can be adjusted by `nghttp2_submit_window_update()`.
3846  * This function takes into account that and returns effective data
3847  * length.  In particular, if the local window size is reduced by
3848  * submitting negative window_size_increment with
3849  * `nghttp2_submit_window_update()`, this function returns the number
3850  * of bytes less than actually received.
3851  *
3852  * This function returns -1 if it fails.
3853  */
3854 NGHTTP2_EXTERN int32_t
3855 nghttp2_session_get_effective_recv_data_length(nghttp2_session *session);
3856 
3857 /**
3858  * @function
3859  *
3860  * Returns the local (receive) window size for a connection.  The
3861  * local window size can be adjusted by
3862  * `nghttp2_submit_window_update()`.  This function takes into account
3863  * that and returns effective window size.
3864  *
3865  * This function does not take into account the amount of received
3866  * data from the remote endpoint.  Use
3867  * `nghttp2_session_get_local_window_size()` to know the amount of
3868  * data the remote endpoint can send without receiving
3869  * connection-level WINDOW_UPDATE frame.  Note that each stream is
3870  * still subject to the stream level flow control.
3871  *
3872  * This function returns -1 if it fails.
3873  */
3874 NGHTTP2_EXTERN int32_t
3875 nghttp2_session_get_effective_local_window_size(nghttp2_session *session);
3876 
3877 /**
3878  * @function
3879  *
3880  * Returns the amount of flow-controlled payload (e.g., DATA) that the
3881  * remote endpoint can send without receiving connection level
3882  * WINDOW_UPDATE frame.  Note that each stream is still subject to the
3883  * stream level flow control (see
3884  * `nghttp2_session_get_stream_local_window_size()`).
3885  *
3886  * This function returns -1 if it fails.
3887  */
3888 NGHTTP2_EXTERN int32_t
3889 nghttp2_session_get_local_window_size(nghttp2_session *session);
3890 
3891 /**
3892  * @function
3893  *
3894  * Returns the remote window size for a given stream |stream_id|.
3895  *
3896  * This is the amount of flow-controlled payload (e.g., DATA) that the
3897  * local endpoint can send without stream level WINDOW_UPDATE.  There
3898  * is also connection level flow control, so the effective size of
3899  * payload that the local endpoint can actually send is
3900  * min(`nghttp2_session_get_stream_remote_window_size()`,
3901  * `nghttp2_session_get_remote_window_size()`).
3902  *
3903  * This function returns -1 if it fails.
3904  */
3905 NGHTTP2_EXTERN int32_t nghttp2_session_get_stream_remote_window_size(
3906   nghttp2_session *session, int32_t stream_id);
3907 
3908 /**
3909  * @function
3910  *
3911  * Returns the remote window size for a connection.
3912  *
3913  * This function always succeeds.
3914  */
3915 NGHTTP2_EXTERN int32_t
3916 nghttp2_session_get_remote_window_size(nghttp2_session *session);
3917 
3918 /**
3919  * @function
3920  *
3921  * Returns 1 if local peer half closed the given stream |stream_id|.
3922  * Returns 0 if it did not.  Returns -1 if no such stream exists.
3923  */
3924 NGHTTP2_EXTERN int
3925 nghttp2_session_get_stream_local_close(nghttp2_session *session,
3926                                        int32_t stream_id);
3927 
3928 /**
3929  * @function
3930  *
3931  * Returns 1 if remote peer half closed the given stream |stream_id|.
3932  * Returns 0 if it did not.  Returns -1 if no such stream exists.
3933  */
3934 NGHTTP2_EXTERN int
3935 nghttp2_session_get_stream_remote_close(nghttp2_session *session,
3936                                         int32_t stream_id);
3937 
3938 /**
3939  * @function
3940  *
3941  * Returns the current dynamic table size of HPACK inflater, including
3942  * the overhead 32 bytes per entry described in RFC 7541.
3943  */
3944 NGHTTP2_EXTERN size_t
3945 nghttp2_session_get_hd_inflate_dynamic_table_size(nghttp2_session *session);
3946 
3947 /**
3948  * @function
3949  *
3950  * Returns the current dynamic table size of HPACK deflater including
3951  * the overhead 32 bytes per entry described in RFC 7541.
3952  */
3953 NGHTTP2_EXTERN size_t
3954 nghttp2_session_get_hd_deflate_dynamic_table_size(nghttp2_session *session);
3955 
3956 /**
3957  * @function
3958  *
3959  * Signals the session so that the connection should be terminated.
3960  *
3961  * The last stream ID is the minimum value between the stream ID of a
3962  * stream for which :type:`nghttp2_on_frame_recv_callback` was called
3963  * most recently and the last stream ID we have sent to the peer
3964  * previously.
3965  *
3966  * The |error_code| is the error code of this GOAWAY frame.  The
3967  * pre-defined error code is one of :enum:`nghttp2_error_code`.
3968  *
3969  * After the transmission, both `nghttp2_session_want_read()` and
3970  * `nghttp2_session_want_write()` return 0.
3971  *
3972  * This function should be called when the connection should be
3973  * terminated after sending GOAWAY.  If the remaining streams should
3974  * be processed after GOAWAY, use `nghttp2_submit_goaway()` instead.
3975  *
3976  * This function returns 0 if it succeeds, or one of the following
3977  * negative error codes:
3978  *
3979  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
3980  *     Out of memory.
3981  */
3982 NGHTTP2_EXTERN int nghttp2_session_terminate_session(nghttp2_session *session,
3983                                                      uint32_t error_code);
3984 
3985 /**
3986  * @function
3987  *
3988  * Signals the session so that the connection should be terminated.
3989  *
3990  * This function behaves like `nghttp2_session_terminate_session()`,
3991  * but the last stream ID can be specified by the application for fine
3992  * grained control of stream.  The HTTP/2 specification does not allow
3993  * last_stream_id to be increased.  So the actual value sent as
3994  * last_stream_id is the minimum value between the given
3995  * |last_stream_id| and the last_stream_id we have previously sent to
3996  * the peer.
3997  *
3998  * The |last_stream_id| is peer's stream ID or 0.  So if |session| is
3999  * initialized as client, |last_stream_id| must be even or 0.  If
4000  * |session| is initialized as server, |last_stream_id| must be odd or
4001  * 0.
4002  *
4003  * This function returns 0 if it succeeds, or one of the following
4004  * negative error codes:
4005  *
4006  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
4007  *     Out of memory.
4008  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
4009  *     The |last_stream_id| is invalid.
4010  */
4011 NGHTTP2_EXTERN int nghttp2_session_terminate_session2(nghttp2_session *session,
4012                                                       int32_t last_stream_id,
4013                                                       uint32_t error_code);
4014 
4015 /**
4016  * @function
4017  *
4018  * Signals to the client that the server started graceful shutdown
4019  * procedure.
4020  *
4021  * This function is only usable for server.  If this function is
4022  * called with client side session, this function returns
4023  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`.
4024  *
4025  * To gracefully shutdown HTTP/2 session, server should call this
4026  * function to send GOAWAY with last_stream_id (1u << 31) - 1.  And
4027  * after some delay (e.g., 1 RTT), send another GOAWAY with the stream
4028  * ID that the server has some processing using
4029  * `nghttp2_submit_goaway()`.  See also
4030  * `nghttp2_session_get_last_proc_stream_id()`.
4031  *
4032  * Unlike `nghttp2_submit_goaway()`, this function just sends GOAWAY
4033  * and does nothing more.  This is a mere indication to the client
4034  * that session shutdown is imminent.  The application should call
4035  * `nghttp2_submit_goaway()` with appropriate last_stream_id after
4036  * this call.
4037  *
4038  * If one or more GOAWAY frame have been already sent by either
4039  * `nghttp2_submit_goaway()` or `nghttp2_session_terminate_session()`,
4040  * this function has no effect.
4041  *
4042  * This function returns 0 if it succeeds, or one of the following
4043  * negative error codes:
4044  *
4045  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
4046  *     Out of memory.
4047  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`
4048  *     The |session| is initialized as client.
4049  */
4050 NGHTTP2_EXTERN int nghttp2_submit_shutdown_notice(nghttp2_session *session);
4051 
4052 /**
4053  * @function
4054  *
4055  * Returns the value of SETTINGS |id| notified by a remote endpoint.
4056  * The |id| must be one of values defined in
4057  * :enum:`nghttp2_settings_id`.
4058  */
4059 NGHTTP2_EXTERN uint32_t nghttp2_session_get_remote_settings(
4060   nghttp2_session *session, nghttp2_settings_id id);
4061 
4062 /**
4063  * @function
4064  *
4065  * Returns the value of SETTINGS |id| of local endpoint acknowledged
4066  * by the remote endpoint.  The |id| must be one of the values defined
4067  * in :enum:`nghttp2_settings_id`.
4068  */
4069 NGHTTP2_EXTERN uint32_t nghttp2_session_get_local_settings(
4070   nghttp2_session *session, nghttp2_settings_id id);
4071 
4072 /**
4073  * @function
4074  *
4075  * Tells the |session| that next stream ID is |next_stream_id|.  The
4076  * |next_stream_id| must be equal or greater than the value returned
4077  * by `nghttp2_session_get_next_stream_id()`.
4078  *
4079  * This function returns 0 if it succeeds, or one of the following
4080  * negative error codes:
4081  *
4082  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
4083  *     The |next_stream_id| is strictly less than the value
4084  *     `nghttp2_session_get_next_stream_id()` returns; or
4085  *     |next_stream_id| is invalid (e.g., even integer for client, or
4086  *     odd integer for server).
4087  */
4088 NGHTTP2_EXTERN int nghttp2_session_set_next_stream_id(nghttp2_session *session,
4089                                                       int32_t next_stream_id);
4090 
4091 /**
4092  * @function
4093  *
4094  * Returns the next outgoing stream ID.  Notice that return type is
4095  * uint32_t.  If we run out of stream ID for this session, this
4096  * function returns 1 << 31.
4097  */
4098 NGHTTP2_EXTERN uint32_t
4099 nghttp2_session_get_next_stream_id(nghttp2_session *session);
4100 
4101 /**
4102  * @function
4103  *
4104  * Tells the |session| that |size| bytes for a stream denoted by
4105  * |stream_id| were consumed by application and are ready to
4106  * WINDOW_UPDATE.  The consumed bytes are counted towards both
4107  * connection and stream level WINDOW_UPDATE (see
4108  * `nghttp2_session_consume_connection()` and
4109  * `nghttp2_session_consume_stream()` to update consumption
4110  * independently).  This function is intended to be used without
4111  * automatic window update (see
4112  * `nghttp2_option_set_no_auto_window_update()`).
4113  *
4114  * This function returns 0 if it succeeds, or one of the following
4115  * negative error codes:
4116  *
4117  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
4118  *     Out of memory.
4119  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
4120  *     The |stream_id| is 0.
4121  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`
4122  *     Automatic WINDOW_UPDATE is not disabled.
4123  */
4124 NGHTTP2_EXTERN int nghttp2_session_consume(nghttp2_session *session,
4125                                            int32_t stream_id, size_t size);
4126 
4127 /**
4128  * @function
4129  *
4130  * Like `nghttp2_session_consume()`, but this only tells library that
4131  * |size| bytes were consumed only for connection level.  Note that
4132  * HTTP/2 maintains connection and stream level flow control windows
4133  * independently.
4134  *
4135  * This function returns 0 if it succeeds, or one of the following
4136  * negative error codes:
4137  *
4138  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
4139  *     Out of memory.
4140  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`
4141  *     Automatic WINDOW_UPDATE is not disabled.
4142  */
4143 NGHTTP2_EXTERN int nghttp2_session_consume_connection(nghttp2_session *session,
4144                                                       size_t size);
4145 
4146 /**
4147  * @function
4148  *
4149  * Like `nghttp2_session_consume()`, but this only tells library that
4150  * |size| bytes were consumed only for stream denoted by |stream_id|.
4151  * Note that HTTP/2 maintains connection and stream level flow control
4152  * windows independently.
4153  *
4154  * This function returns 0 if it succeeds, or one of the following
4155  * negative error codes:
4156  *
4157  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
4158  *     Out of memory.
4159  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
4160  *     The |stream_id| is 0.
4161  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`
4162  *     Automatic WINDOW_UPDATE is not disabled.
4163  */
4164 NGHTTP2_EXTERN int nghttp2_session_consume_stream(nghttp2_session *session,
4165                                                   int32_t stream_id,
4166                                                   size_t size);
4167 
4168 /**
4169  * @function
4170  *
4171  * .. warning::
4172  *
4173  *   Deprecated.  :rfc:`7540` priorities are deprecated by
4174  *   :rfc:`9113`.  Consider migrating to :rfc:`9218` extensible
4175  *   prioritization scheme.
4176  *
4177  * This function is noop.  It always returns 0.
4178  */
4179 NGHTTP2_EXTERN int
4180 nghttp2_session_change_stream_priority(nghttp2_session *session,
4181                                        int32_t stream_id,
4182                                        const nghttp2_priority_spec *pri_spec);
4183 
4184 /**
4185  * @function
4186  *
4187  * .. warning::
4188  *
4189  *   Deprecated.  :rfc:`7540` priorities are deprecated by
4190  *   :rfc:`9113`.  Consider migrating to :rfc:`9218` extensible
4191  *   prioritization scheme.
4192  *
4193  * This function is noop.  It always returns 0.
4194  */
4195 NGHTTP2_EXTERN int
4196 nghttp2_session_create_idle_stream(nghttp2_session *session, int32_t stream_id,
4197                                    const nghttp2_priority_spec *pri_spec);
4198 
4199 /**
4200  * @function
4201  *
4202  * .. warning::
4203  *
4204  *   This function is deprecated in favor of
4205  *   `nghttp2_session_upgrade2()`, because this function lacks the
4206  *   parameter to tell the library the request method used in the
4207  *   original HTTP request.  This information is required for client
4208  *   to validate actual response body length against content-length
4209  *   header field (see `nghttp2_option_set_no_http_messaging()`).  If
4210  *   HEAD is used in request, the length of response body must be 0
4211  *   regardless of value included in content-length header field.
4212  *
4213  * Performs post-process of HTTP Upgrade request.  This function can
4214  * be called from both client and server, but the behavior is very
4215  * different in each other.
4216  *
4217  * If called from client side, the |settings_payload| must be the
4218  * value sent in ``HTTP2-Settings`` header field and must be decoded
4219  * by base64url decoder.  The |settings_payloadlen| is the length of
4220  * |settings_payload|.  The |settings_payload| is unpacked and its
4221  * setting values will be submitted using `nghttp2_submit_settings()`.
4222  * This means that the client application code does not need to submit
4223  * SETTINGS by itself.  The stream with stream ID=1 is opened and the
4224  * |stream_user_data| is used for its stream_user_data.  The opened
4225  * stream becomes half-closed (local) state.
4226  *
4227  * If called from server side, the |settings_payload| must be the
4228  * value received in ``HTTP2-Settings`` header field and must be
4229  * decoded by base64url decoder.  The |settings_payloadlen| is the
4230  * length of |settings_payload|.  It is treated as if the SETTINGS
4231  * frame with that payload is received.  Thus, callback functions for
4232  * the reception of SETTINGS frame will be invoked.  The stream with
4233  * stream ID=1 is opened.  The |stream_user_data| is ignored.  The
4234  * opened stream becomes half-closed (remote).
4235  *
4236  * This function returns 0 if it succeeds, or one of the following
4237  * negative error codes:
4238  *
4239  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
4240  *     Out of memory.
4241  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
4242  *     The |settings_payload| is badly formed.
4243  * :enum:`nghttp2_error.NGHTTP2_ERR_PROTO`
4244  *     The stream ID 1 is already used or closed; or is not available.
4245  */
4246 NGHTTP2_EXTERN int nghttp2_session_upgrade(nghttp2_session *session,
4247                                            const uint8_t *settings_payload,
4248                                            size_t settings_payloadlen,
4249                                            void *stream_user_data);
4250 
4251 /**
4252  * @function
4253  *
4254  * Performs post-process of HTTP Upgrade request.  This function can
4255  * be called from both client and server, but the behavior is very
4256  * different in each other.
4257  *
4258  * If called from client side, the |settings_payload| must be the
4259  * value sent in ``HTTP2-Settings`` header field and must be decoded
4260  * by base64url decoder.  The |settings_payloadlen| is the length of
4261  * |settings_payload|.  The |settings_payload| is unpacked and its
4262  * setting values will be submitted using `nghttp2_submit_settings()`.
4263  * This means that the client application code does not need to submit
4264  * SETTINGS by itself.  The stream with stream ID=1 is opened and the
4265  * |stream_user_data| is used for its stream_user_data.  The opened
4266  * stream becomes half-closed (local) state.
4267  *
4268  * If called from server side, the |settings_payload| must be the
4269  * value received in ``HTTP2-Settings`` header field and must be
4270  * decoded by base64url decoder.  The |settings_payloadlen| is the
4271  * length of |settings_payload|.  It is treated as if the SETTINGS
4272  * frame with that payload is received.  Thus, callback functions for
4273  * the reception of SETTINGS frame will be invoked.  The stream with
4274  * stream ID=1 is opened.  The |stream_user_data| is ignored.  The
4275  * opened stream becomes half-closed (remote).
4276  *
4277  * If the request method is HEAD, pass nonzero value to
4278  * |head_request|.  Otherwise, pass 0.
4279  *
4280  * This function returns 0 if it succeeds, or one of the following
4281  * negative error codes:
4282  *
4283  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
4284  *     Out of memory.
4285  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
4286  *     The |settings_payload| is badly formed.
4287  * :enum:`nghttp2_error.NGHTTP2_ERR_PROTO`
4288  *     The stream ID 1 is already used or closed; or is not available.
4289  */
4290 NGHTTP2_EXTERN int nghttp2_session_upgrade2(nghttp2_session *session,
4291                                             const uint8_t *settings_payload,
4292                                             size_t settings_payloadlen,
4293                                             int head_request,
4294                                             void *stream_user_data);
4295 
4296 #ifndef NGHTTP2_NO_SSIZE_T
4297 /**
4298  * @function
4299  *
4300  * .. warning::
4301  *
4302  *   Deprecated.  Use `nghttp2_pack_settings_payload2()` instead.
4303  *
4304  * Serializes the SETTINGS values |iv| in the |buf|.  The size of the
4305  * |buf| is specified by |buflen|.  The number of entries in the |iv|
4306  * array is given by |niv|.  The required space in |buf| for the |niv|
4307  * entries is ``6*niv`` bytes and if the given buffer is too small, an
4308  * error is returned.  This function is used mainly for creating a
4309  * SETTINGS payload to be sent with the ``HTTP2-Settings`` header
4310  * field in an HTTP Upgrade request.  The data written in |buf| is NOT
4311  * base64url encoded and the application is responsible for encoding.
4312  *
4313  * This function returns the number of bytes written in |buf|, or one
4314  * of the following negative error codes:
4315  *
4316  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
4317  *     The |iv| contains duplicate settings ID or invalid value.
4318  *
4319  * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE`
4320  *     The provided |buflen| size is too small to hold the output.
4321  */
4322 NGHTTP2_EXTERN ssize_t nghttp2_pack_settings_payload(
4323   uint8_t *buf, size_t buflen, const nghttp2_settings_entry *iv, size_t niv);
4324 
4325 #endif /* NGHTTP2_NO_SSIZE_T */
4326 
4327 /**
4328  * @function
4329  *
4330  * Serializes the SETTINGS values |iv| in the |buf|.  The size of the
4331  * |buf| is specified by |buflen|.  The number of entries in the |iv|
4332  * array is given by |niv|.  The required space in |buf| for the |niv|
4333  * entries is ``6*niv`` bytes and if the given buffer is too small, an
4334  * error is returned.  This function is used mainly for creating a
4335  * SETTINGS payload to be sent with the ``HTTP2-Settings`` header
4336  * field in an HTTP Upgrade request.  The data written in |buf| is NOT
4337  * base64url encoded and the application is responsible for encoding.
4338  *
4339  * This function returns the number of bytes written in |buf|, or one
4340  * of the following negative error codes:
4341  *
4342  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
4343  *     The |iv| contains duplicate settings ID or invalid value.
4344  *
4345  * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE`
4346  *     The provided |buflen| size is too small to hold the output.
4347  */
4348 NGHTTP2_EXTERN nghttp2_ssize nghttp2_pack_settings_payload2(
4349   uint8_t *buf, size_t buflen, const nghttp2_settings_entry *iv, size_t niv);
4350 
4351 /**
4352  * @function
4353  *
4354  * Returns string describing the |lib_error_code|.  The
4355  * |lib_error_code| must be one of the :enum:`nghttp2_error`.
4356  */
4357 NGHTTP2_EXTERN const char *nghttp2_strerror(int lib_error_code);
4358 
4359 /**
4360  * @function
4361  *
4362  * Returns string representation of HTTP/2 error code |error_code|
4363  * (e.g., ``PROTOCOL_ERROR`` is returned if ``error_code ==
4364  * NGHTTP2_PROTOCOL_ERROR``).  If string representation is unknown for
4365  * given |error_code|, this function returns string ``unknown``.
4366  */
4367 NGHTTP2_EXTERN const char *nghttp2_http2_strerror(uint32_t error_code);
4368 
4369 /**
4370  * @function
4371  *
4372  * .. warning::
4373  *
4374  *   Deprecated.  :rfc:`7540` priorities are deprecated by
4375  *   :rfc:`9113`.  Consider migrating to :rfc:`9218` extensible
4376  *   prioritization scheme.
4377  *
4378  * Initializes |pri_spec| with the |stream_id| of the stream to depend
4379  * on with |weight| and its exclusive flag.  If |exclusive| is
4380  * nonzero, exclusive flag is set.
4381  *
4382  * The |weight| must be in [:macro:`NGHTTP2_MIN_WEIGHT`,
4383  * :macro:`NGHTTP2_MAX_WEIGHT`], inclusive.
4384  */
4385 NGHTTP2_EXTERN void nghttp2_priority_spec_init(nghttp2_priority_spec *pri_spec,
4386                                                int32_t stream_id,
4387                                                int32_t weight, int exclusive);
4388 
4389 /**
4390  * @function
4391  *
4392  * .. warning::
4393  *
4394  *   Deprecated.  :rfc:`7540` priorities are deprecated by
4395  *   :rfc:`9113`.  Consider migrating to :rfc:`9218` extensible
4396  *   prioritization scheme.
4397  *
4398  * Initializes |pri_spec| with the default values.  The default values
4399  * are: stream_id = 0, weight = :macro:`NGHTTP2_DEFAULT_WEIGHT` and
4400  * exclusive = 0.
4401  */
4402 NGHTTP2_EXTERN void
4403 nghttp2_priority_spec_default_init(nghttp2_priority_spec *pri_spec);
4404 
4405 /**
4406  * @function
4407  *
4408  * .. warning::
4409  *
4410  *   Deprecated.  :rfc:`7540` priorities are deprecated by
4411  *   :rfc:`9113`.  Consider migrating to :rfc:`9218` extensible
4412  *   prioritization scheme.
4413  *
4414  * Returns nonzero if the |pri_spec| is filled with default values.
4415  */
4416 NGHTTP2_EXTERN int
4417 nghttp2_priority_spec_check_default(const nghttp2_priority_spec *pri_spec);
4418 
4419 #ifndef NGHTTP2_NO_SSIZE_T
4420 /**
4421  * @function
4422  *
4423  * .. warning::
4424  *
4425  *   Deprecated.  Use `nghttp2_submit_request2()` instead.
4426  *
4427  * Submits HEADERS frame and optionally one or more DATA frames.
4428  *
4429  * The |pri_spec| is ignored.
4430  *
4431  * The |nva| is an array of name/value pair :type:`nghttp2_nv` with
4432  * |nvlen| elements.  The application is responsible to include
4433  * required pseudo-header fields (header field whose name starts with
4434  * ":") in |nva| and must place pseudo-headers before regular header
4435  * fields.
4436  *
4437  * This function creates copies of all name/value pairs in |nva|.  It
4438  * also lower-cases all names in |nva|.  The order of elements in
4439  * |nva| is preserved.  For header fields with
4440  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME` and
4441  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set,
4442  * header field name and value are not copied respectively.  With
4443  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME`, application
4444  * is responsible to pass header field name in lowercase.  The
4445  * application should maintain the references to them until
4446  * :type:`nghttp2_on_frame_send_callback` or
4447  * :type:`nghttp2_on_frame_not_send_callback` is called.
4448  *
4449  * HTTP/2 specification has requirement about header fields in the
4450  * request HEADERS.  See the specification for more details.
4451  *
4452  * If |data_prd| is not ``NULL``, it provides data which will be sent
4453  * in subsequent DATA frames.  In this case, a method that allows
4454  * request message bodies
4455  * (https://tools.ietf.org/html/rfc7231#section-4) must be specified
4456  * with ``:method`` key in |nva| (e.g. ``POST``).  This function does
4457  * not take ownership of the |data_prd|.  The function copies the
4458  * members of the |data_prd|.  If |data_prd| is ``NULL``, HEADERS have
4459  * END_STREAM set.  The |stream_user_data| is data associated to the
4460  * stream opened by this request and can be an arbitrary pointer,
4461  * which can be retrieved later by
4462  * `nghttp2_session_get_stream_user_data()`.
4463  *
4464  * This function returns assigned stream ID if it succeeds, or one of
4465  * the following negative error codes:
4466  *
4467  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
4468  *     Out of memory.
4469  * :enum:`nghttp2_error.NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE`
4470  *     No stream ID is available because maximum stream ID was
4471  *     reached.
4472  * :enum:`nghttp2_error.NGHTTP2_ERR_PROTO`
4473  *     The |session| is server session.
4474  *
4475  * .. warning::
4476  *
4477  *   This function returns assigned stream ID if it succeeds.  But
4478  *   that stream is not created yet.  The application must not submit
4479  *   frame to that stream ID before
4480  *   :type:`nghttp2_before_frame_send_callback` is called for this
4481  *   frame.  This means `nghttp2_session_get_stream_user_data()` does
4482  *   not work before the callback.  But
4483  *   `nghttp2_session_set_stream_user_data()` handles this situation
4484  *   specially, and it can set data to a stream during this period.
4485  *
4486  */
4487 NGHTTP2_EXTERN int32_t nghttp2_submit_request(
4488   nghttp2_session *session, const nghttp2_priority_spec *pri_spec,
4489   const nghttp2_nv *nva, size_t nvlen, const nghttp2_data_provider *data_prd,
4490   void *stream_user_data);
4491 
4492 #endif /* NGHTTP2_NO_SSIZE_T */
4493 
4494 /**
4495  * @function
4496  *
4497  * Submits HEADERS frame and optionally one or more DATA frames.
4498  *
4499  * The |pri_spec| is ignored.
4500  *
4501  * The |nva| is an array of name/value pair :type:`nghttp2_nv` with
4502  * |nvlen| elements.  The application is responsible to include
4503  * required pseudo-header fields (header field whose name starts with
4504  * ":") in |nva| and must place pseudo-headers before regular header
4505  * fields.
4506  *
4507  * This function creates copies of all name/value pairs in |nva|.  It
4508  * also lower-cases all names in |nva|.  The order of elements in
4509  * |nva| is preserved.  For header fields with
4510  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME` and
4511  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set,
4512  * header field name and value are not copied respectively.  With
4513  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME`, application
4514  * is responsible to pass header field name in lowercase.  The
4515  * application should maintain the references to them until
4516  * :type:`nghttp2_on_frame_send_callback` or
4517  * :type:`nghttp2_on_frame_not_send_callback` is called.
4518  *
4519  * HTTP/2 specification has requirement about header fields in the
4520  * request HEADERS.  See the specification for more details.
4521  *
4522  * If |data_prd| is not ``NULL``, it provides data which will be sent
4523  * in subsequent DATA frames.  In this case, a method that allows
4524  * request message bodies
4525  * (https://tools.ietf.org/html/rfc7231#section-4) must be specified
4526  * with ``:method`` key in |nva| (e.g. ``POST``).  This function does
4527  * not take ownership of the |data_prd|.  The function copies the
4528  * members of the |data_prd|.  If |data_prd| is ``NULL``, HEADERS have
4529  * END_STREAM set.  The |stream_user_data| is data associated to the
4530  * stream opened by this request and can be an arbitrary pointer,
4531  * which can be retrieved later by
4532  * `nghttp2_session_get_stream_user_data()`.
4533  *
4534  * This function returns assigned stream ID if it succeeds, or one of
4535  * the following negative error codes:
4536  *
4537  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
4538  *     Out of memory.
4539  * :enum:`nghttp2_error.NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE`
4540  *     No stream ID is available because maximum stream ID was
4541  *     reached.
4542  * :enum:`nghttp2_error.NGHTTP2_ERR_PROTO`
4543  *     The |session| is server session.
4544  *
4545  * .. warning::
4546  *
4547  *   This function returns assigned stream ID if it succeeds.  But
4548  *   that stream is not created yet.  The application must not submit
4549  *   frame to that stream ID before
4550  *   :type:`nghttp2_before_frame_send_callback` is called for this
4551  *   frame.  This means `nghttp2_session_get_stream_user_data()` does
4552  *   not work before the callback.  But
4553  *   `nghttp2_session_set_stream_user_data()` handles this situation
4554  *   specially, and it can set data to a stream during this period.
4555  *
4556  */
4557 NGHTTP2_EXTERN int32_t nghttp2_submit_request2(
4558   nghttp2_session *session, const nghttp2_priority_spec *pri_spec,
4559   const nghttp2_nv *nva, size_t nvlen, const nghttp2_data_provider2 *data_prd,
4560   void *stream_user_data);
4561 
4562 #ifndef NGHTTP2_NO_SSIZE_T
4563 /**
4564  * @function
4565  *
4566  * .. warning::
4567  *
4568  *   Deprecated.  Use `nghttp2_submit_response2()` instead.
4569  *
4570  * Submits response HEADERS frame and optionally one or more DATA
4571  * frames against the stream |stream_id|.
4572  *
4573  * The |nva| is an array of name/value pair :type:`nghttp2_nv` with
4574  * |nvlen| elements.  The application is responsible to include
4575  * required pseudo-header fields (header field whose name starts with
4576  * ":") in |nva| and must place pseudo-headers before regular header
4577  * fields.
4578  *
4579  * This function creates copies of all name/value pairs in |nva|.  It
4580  * also lower-cases all names in |nva|.  The order of elements in
4581  * |nva| is preserved.  For header fields with
4582  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME` and
4583  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set,
4584  * header field name and value are not copied respectively.  With
4585  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME`, application
4586  * is responsible to pass header field name in lowercase.  The
4587  * application should maintain the references to them until
4588  * :type:`nghttp2_on_frame_send_callback` or
4589  * :type:`nghttp2_on_frame_not_send_callback` is called.
4590  *
4591  * HTTP/2 specification has requirement about header fields in the
4592  * response HEADERS.  See the specification for more details.
4593  *
4594  * If |data_prd| is not ``NULL``, it provides data which will be sent
4595  * in subsequent DATA frames.  This function does not take ownership
4596  * of the |data_prd|.  The function copies the members of the
4597  * |data_prd|.  If |data_prd| is ``NULL``, HEADERS will have
4598  * END_STREAM flag set.
4599  *
4600  * This method can be used as normal HTTP response and push response.
4601  * When pushing a resource using this function, the |session| must be
4602  * configured using `nghttp2_session_server_new()` or its variants and
4603  * the target stream denoted by the |stream_id| must be reserved using
4604  * `nghttp2_submit_push_promise()`.
4605  *
4606  * To send non-final response headers (e.g., HTTP status 101), don't
4607  * use this function because this function half-closes the outbound
4608  * stream.  Instead, use `nghttp2_submit_headers()` for this purpose.
4609  *
4610  * This function returns 0 if it succeeds, or one of the following
4611  * negative error codes:
4612  *
4613  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
4614  *     Out of memory.
4615  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
4616  *     The |stream_id| is 0.
4617  * :enum:`nghttp2_error.NGHTTP2_ERR_DATA_EXIST`
4618  *     DATA or HEADERS has been already submitted and not fully
4619  *     processed yet.  Normally, this does not happen, but when
4620  *     application wrongly calls `nghttp2_submit_response()` twice,
4621  *     this may happen.
4622  * :enum:`nghttp2_error.NGHTTP2_ERR_PROTO`
4623  *     The |session| is client session.
4624  *
4625  * .. warning::
4626  *
4627  *   Calling this function twice for the same stream ID may lead to
4628  *   program crash.  It is generally considered to a programming error
4629  *   to commit response twice.
4630  */
4631 NGHTTP2_EXTERN int
4632 nghttp2_submit_response(nghttp2_session *session, int32_t stream_id,
4633                         const nghttp2_nv *nva, size_t nvlen,
4634                         const nghttp2_data_provider *data_prd);
4635 
4636 #endif /* NGHTTP2_NO_SSIZE_T */
4637 
4638 /**
4639  * @function
4640  *
4641  * Submits response HEADERS frame and optionally one or more DATA
4642  * frames against the stream |stream_id|.
4643  *
4644  * The |nva| is an array of name/value pair :type:`nghttp2_nv` with
4645  * |nvlen| elements.  The application is responsible to include
4646  * required pseudo-header fields (header field whose name starts with
4647  * ":") in |nva| and must place pseudo-headers before regular header
4648  * fields.
4649  *
4650  * This function creates copies of all name/value pairs in |nva|.  It
4651  * also lower-cases all names in |nva|.  The order of elements in
4652  * |nva| is preserved.  For header fields with
4653  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME` and
4654  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set,
4655  * header field name and value are not copied respectively.  With
4656  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME`, application
4657  * is responsible to pass header field name in lowercase.  The
4658  * application should maintain the references to them until
4659  * :type:`nghttp2_on_frame_send_callback` or
4660  * :type:`nghttp2_on_frame_not_send_callback` is called.
4661  *
4662  * HTTP/2 specification has requirement about header fields in the
4663  * response HEADERS.  See the specification for more details.
4664  *
4665  * If |data_prd| is not ``NULL``, it provides data which will be sent
4666  * in subsequent DATA frames.  This function does not take ownership
4667  * of the |data_prd|.  The function copies the members of the
4668  * |data_prd|.  If |data_prd| is ``NULL``, HEADERS will have
4669  * END_STREAM flag set.
4670  *
4671  * This method can be used as normal HTTP response and push response.
4672  * When pushing a resource using this function, the |session| must be
4673  * configured using `nghttp2_session_server_new()` or its variants and
4674  * the target stream denoted by the |stream_id| must be reserved using
4675  * `nghttp2_submit_push_promise()`.
4676  *
4677  * To send non-final response headers (e.g., HTTP status 101), don't
4678  * use this function because this function half-closes the outbound
4679  * stream.  Instead, use `nghttp2_submit_headers()` for this purpose.
4680  *
4681  * This function returns 0 if it succeeds, or one of the following
4682  * negative error codes:
4683  *
4684  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
4685  *     Out of memory.
4686  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
4687  *     The |stream_id| is 0.
4688  * :enum:`nghttp2_error.NGHTTP2_ERR_DATA_EXIST`
4689  *     DATA or HEADERS has been already submitted and not fully
4690  *     processed yet.  Normally, this does not happen, but when
4691  *     application wrongly calls `nghttp2_submit_response2()` twice,
4692  *     this may happen.
4693  * :enum:`nghttp2_error.NGHTTP2_ERR_PROTO`
4694  *     The |session| is client session.
4695  *
4696  * .. warning::
4697  *
4698  *   Calling this function twice for the same stream ID may lead to
4699  *   program crash.  It is generally considered to a programming error
4700  *   to commit response twice.
4701  */
4702 NGHTTP2_EXTERN int
4703 nghttp2_submit_response2(nghttp2_session *session, int32_t stream_id,
4704                          const nghttp2_nv *nva, size_t nvlen,
4705                          const nghttp2_data_provider2 *data_prd);
4706 
4707 /**
4708  * @function
4709  *
4710  * Submits trailer fields HEADERS against the stream |stream_id|.
4711  *
4712  * The |nva| is an array of name/value pair :type:`nghttp2_nv` with
4713  * |nvlen| elements.  The application must not include pseudo-header
4714  * fields (headers whose names starts with ":") in |nva|.
4715  *
4716  * This function creates copies of all name/value pairs in |nva|.  It
4717  * also lower-cases all names in |nva|.  The order of elements in
4718  * |nva| is preserved.  For header fields with
4719  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME` and
4720  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set,
4721  * header field name and value are not copied respectively.  With
4722  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME`, application
4723  * is responsible to pass header field name in lowercase.  The
4724  * application should maintain the references to them until
4725  * :type:`nghttp2_on_frame_send_callback` or
4726  * :type:`nghttp2_on_frame_not_send_callback` is called.
4727  *
4728  * For server, trailer fields must follow response HEADERS or response
4729  * DATA without END_STREAM flat set.  The library does not enforce
4730  * this requirement, and applications should do this for themselves.
4731  * If `nghttp2_submit_trailer()` is called before any response HEADERS
4732  * submission (usually by `nghttp2_submit_response2()`), the content
4733  * of |nva| will be sent as response headers, which will result in
4734  * error.
4735  *
4736  * This function has the same effect with `nghttp2_submit_headers()`,
4737  * with flags = :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM` and both
4738  * pri_spec and stream_user_data to NULL.
4739  *
4740  * To submit trailer fields after `nghttp2_submit_response2()` is
4741  * called, the application has to specify
4742  * :type:`nghttp2_data_provider2` to `nghttp2_submit_response2()`.
4743  * Inside of :type:`nghttp2_data_source_read_callback2`, when setting
4744  * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_EOF`, also set
4745  * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_END_STREAM`.  After
4746  * that, the application can send trailer fields using
4747  * `nghttp2_submit_trailer()`.  `nghttp2_submit_trailer()` can be used
4748  * inside :type:`nghttp2_data_source_read_callback2`.
4749  *
4750  * This function returns 0 if it succeeds and |stream_id| is -1.
4751  * Otherwise, this function returns 0 if it succeeds, or one of the
4752  * following negative error codes:
4753  *
4754  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
4755  *     Out of memory.
4756  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
4757  *     The |stream_id| is 0.
4758  */
4759 NGHTTP2_EXTERN int nghttp2_submit_trailer(nghttp2_session *session,
4760                                           int32_t stream_id,
4761                                           const nghttp2_nv *nva, size_t nvlen);
4762 
4763 /**
4764  * @function
4765  *
4766  * Submits HEADERS frame. The |flags| is bitwise OR of the
4767  * following values:
4768  *
4769  * * :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM`
4770  *
4771  * If |flags| includes :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM`,
4772  * this frame has END_STREAM flag set.
4773  *
4774  * The library handles the CONTINUATION frame internally and it
4775  * correctly sets END_HEADERS to the last sequence of the PUSH_PROMISE
4776  * or CONTINUATION frame.
4777  *
4778  * If the |stream_id| is -1, this frame is assumed as request (i.e.,
4779  * request HEADERS frame which opens new stream).  In this case, the
4780  * assigned stream ID will be returned.  Otherwise, specify stream ID
4781  * in |stream_id|.
4782  *
4783  * The |pri_spec| is ignored.
4784  *
4785  * The |nva| is an array of name/value pair :type:`nghttp2_nv` with
4786  * |nvlen| elements.  The application is responsible to include
4787  * required pseudo-header fields (header field whose name starts with
4788  * ":") in |nva| and must place pseudo-headers before regular header
4789  * fields.
4790  *
4791  * This function creates copies of all name/value pairs in |nva|.  It
4792  * also lower-cases all names in |nva|.  The order of elements in
4793  * |nva| is preserved.  For header fields with
4794  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME` and
4795  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set,
4796  * header field name and value are not copied respectively.  With
4797  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME`, application
4798  * is responsible to pass header field name in lowercase.  The
4799  * application should maintain the references to them until
4800  * :type:`nghttp2_on_frame_send_callback` or
4801  * :type:`nghttp2_on_frame_not_send_callback` is called.
4802  *
4803  * The |stream_user_data| is a pointer to an arbitrary data which is
4804  * associated to the stream this frame will open.  Therefore it is
4805  * only used if this frame opens streams, in other words, it changes
4806  * stream state from idle or reserved to open.
4807  *
4808  * This function is low-level in a sense that the application code can
4809  * specify flags directly.  For usual HTTP request,
4810  * `nghttp2_submit_request2()` is useful.  Likewise, for HTTP
4811  * response, prefer `nghttp2_submit_response2()`.
4812  *
4813  * This function returns newly assigned stream ID if it succeeds and
4814  * |stream_id| is -1.  Otherwise, this function returns 0 if it
4815  * succeeds, or one of the following negative error codes:
4816  *
4817  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
4818  *     Out of memory.
4819  * :enum:`nghttp2_error.NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE`
4820  *     No stream ID is available because maximum stream ID was
4821  *     reached.
4822  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
4823  *     The |stream_id| is 0.
4824  * :enum:`nghttp2_error.NGHTTP2_ERR_DATA_EXIST`
4825  *     DATA or HEADERS has been already submitted and not fully
4826  *     processed yet.  This happens if stream denoted by |stream_id|
4827  *     is in reserved state.
4828  * :enum:`nghttp2_error.NGHTTP2_ERR_PROTO`
4829  *     The |stream_id| is -1, and |session| is server session.
4830  *
4831  * .. warning::
4832  *
4833  *   This function returns assigned stream ID if it succeeds and
4834  *   |stream_id| is -1.  But that stream is not opened yet.  The
4835  *   application must not submit frame to that stream ID before
4836  *   :type:`nghttp2_before_frame_send_callback` is called for this
4837  *   frame.
4838  *
4839  */
4840 NGHTTP2_EXTERN int32_t nghttp2_submit_headers(
4841   nghttp2_session *session, uint8_t flags, int32_t stream_id,
4842   const nghttp2_priority_spec *pri_spec, const nghttp2_nv *nva, size_t nvlen,
4843   void *stream_user_data);
4844 
4845 #ifndef NGHTTP2_NO_SSIZE_T
4846 /**
4847  * @function
4848  *
4849  * .. warning::
4850  *
4851  *   Deprecated.  Use `nghttp2_submit_data2()` instead.
4852  *
4853  * Submits one or more DATA frames to the stream |stream_id|.  The
4854  * data to be sent are provided by |data_prd|.  If |flags| contains
4855  * :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM`, the last DATA frame
4856  * has END_STREAM flag set.
4857  *
4858  * This function does not take ownership of the |data_prd|.  The
4859  * function copies the members of the |data_prd|.
4860  *
4861  * This function returns 0 if it succeeds, or one of the following
4862  * negative error codes:
4863  *
4864  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
4865  *     Out of memory.
4866  * :enum:`nghttp2_error.NGHTTP2_ERR_DATA_EXIST`
4867  *     DATA or HEADERS has been already submitted and not fully
4868  *     processed yet.
4869  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
4870  *     The |stream_id| is 0.
4871  * :enum:`nghttp2_error.NGHTTP2_ERR_STREAM_CLOSED`
4872  *     The stream was already closed; or the |stream_id| is invalid.
4873  *
4874  * .. note::
4875  *
4876  *   Currently, only one DATA or HEADERS is allowed for a stream at a
4877  *   time.  Submitting these frames more than once before first DATA
4878  *   or HEADERS is finished results in
4879  *   :enum:`nghttp2_error.NGHTTP2_ERR_DATA_EXIST` error code.  The
4880  *   earliest callback which tells that previous frame is done is
4881  *   :type:`nghttp2_on_frame_send_callback`.  In side that callback,
4882  *   new data can be submitted using `nghttp2_submit_data()`.  Of
4883  *   course, all data except for last one must not have
4884  *   :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM` flag set in |flags|.
4885  *   This sounds a bit complicated, and we recommend to use
4886  *   `nghttp2_submit_request()` and `nghttp2_submit_response()` to
4887  *   avoid this cascading issue.  The experience shows that for HTTP
4888  *   use, these two functions are enough to implement both client and
4889  *   server.
4890  */
4891 NGHTTP2_EXTERN int nghttp2_submit_data(nghttp2_session *session, uint8_t flags,
4892                                        int32_t stream_id,
4893                                        const nghttp2_data_provider *data_prd);
4894 
4895 #endif /* NGHTTP2_NO_SSIZE_T */
4896 
4897 /**
4898  * @function
4899  *
4900  * Submits one or more DATA frames to the stream |stream_id|.  The
4901  * data to be sent are provided by |data_prd|.  If |flags| contains
4902  * :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM`, the last DATA frame
4903  * has END_STREAM flag set.
4904  *
4905  * This function does not take ownership of the |data_prd|.  The
4906  * function copies the members of the |data_prd|.
4907  *
4908  * This function returns 0 if it succeeds, or one of the following
4909  * negative error codes:
4910  *
4911  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
4912  *     Out of memory.
4913  * :enum:`nghttp2_error.NGHTTP2_ERR_DATA_EXIST`
4914  *     DATA or HEADERS has been already submitted and not fully
4915  *     processed yet.
4916  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
4917  *     The |stream_id| is 0.
4918  * :enum:`nghttp2_error.NGHTTP2_ERR_STREAM_CLOSED`
4919  *     The stream was already closed; or the |stream_id| is invalid.
4920  *
4921  * .. note::
4922  *
4923  *   Currently, only one DATA or HEADERS is allowed for a stream at a
4924  *   time.  Submitting these frames more than once before first DATA
4925  *   or HEADERS is finished results in
4926  *   :enum:`nghttp2_error.NGHTTP2_ERR_DATA_EXIST` error code.  The
4927  *   earliest callback which tells that previous frame is done is
4928  *   :type:`nghttp2_on_frame_send_callback`.  In side that callback,
4929  *   new data can be submitted using `nghttp2_submit_data2()`.  Of
4930  *   course, all data except for last one must not have
4931  *   :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM` flag set in |flags|.
4932  *   This sounds a bit complicated, and we recommend to use
4933  *   `nghttp2_submit_request2()` and `nghttp2_submit_response2()` to
4934  *   avoid this cascading issue.  The experience shows that for HTTP
4935  *   use, these two functions are enough to implement both client and
4936  *   server.
4937  */
4938 NGHTTP2_EXTERN int nghttp2_submit_data2(nghttp2_session *session, uint8_t flags,
4939                                         int32_t stream_id,
4940                                         const nghttp2_data_provider2 *data_prd);
4941 
4942 /**
4943  * @function
4944  *
4945  * .. warning::
4946  *
4947  *   Deprecated.  :rfc:`7540` priorities are deprecated by
4948  *   :rfc:`9113`.  Consider migrating to :rfc:`9218` extensible
4949  *   prioritization scheme.
4950  *
4951  * This function is noop.  It always returns 0.
4952  */
4953 NGHTTP2_EXTERN int
4954 nghttp2_submit_priority(nghttp2_session *session, uint8_t flags,
4955                         int32_t stream_id,
4956                         const nghttp2_priority_spec *pri_spec);
4957 
4958 /**
4959  * @macro
4960  *
4961  * :macro:`NGHTTP2_EXTPRI_DEFAULT_URGENCY` is the default urgency
4962  * level for :rfc:`9218` extensible priorities.
4963  */
4964 #define NGHTTP2_EXTPRI_DEFAULT_URGENCY 3
4965 
4966 /**
4967  * @macro
4968  *
4969  * :macro:`NGHTTP2_EXTPRI_URGENCY_HIGH` is the highest urgency level
4970  * for :rfc:`9218` extensible priorities.
4971  */
4972 #define NGHTTP2_EXTPRI_URGENCY_HIGH 0
4973 
4974 /**
4975  * @macro
4976  *
4977  * :macro:`NGHTTP2_EXTPRI_URGENCY_LOW` is the lowest urgency level for
4978  * :rfc:`9218` extensible priorities.
4979  */
4980 #define NGHTTP2_EXTPRI_URGENCY_LOW 7
4981 
4982 /**
4983  * @macro
4984  *
4985  * :macro:`NGHTTP2_EXTPRI_URGENCY_LEVELS` is the number of urgency
4986  * levels for :rfc:`9218` extensible priorities.
4987  */
4988 #define NGHTTP2_EXTPRI_URGENCY_LEVELS (NGHTTP2_EXTPRI_URGENCY_LOW + 1)
4989 
4990 /**
4991  * @struct
4992  *
4993  * :type:`nghttp2_extpri` is :rfc:`9218` extensible priorities
4994  * specification for a stream.
4995  */
4996 typedef struct nghttp2_extpri {
4997   /**
4998    * :member:`urgency` is the urgency of a stream, it must be in
4999    * [:macro:`NGHTTP2_EXTPRI_URGENCY_HIGH`,
5000    * :macro:`NGHTTP2_EXTPRI_URGENCY_LOW`], inclusive, and 0 is the
5001    * highest urgency.
5002    */
5003   uint32_t urgency;
5004   /**
5005    * :member:`inc` indicates that a content can be processed
5006    * incrementally or not.  If inc is 0, it cannot be processed
5007    * incrementally.  If inc is 1, it can be processed incrementally.
5008    * Other value is not permitted.
5009    */
5010   int inc;
5011 } nghttp2_extpri;
5012 
5013 /**
5014  * @function
5015  *
5016  * Submits RST_STREAM frame to cancel/reject the stream |stream_id|
5017  * with the error code |error_code|.
5018  *
5019  * The pre-defined error code is one of :enum:`nghttp2_error_code`.
5020  *
5021  * The |flags| is currently ignored and should be
5022  * :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`.
5023  *
5024  * This function returns 0 if it succeeds, or one of the following
5025  * negative error codes:
5026  *
5027  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
5028  *     Out of memory.
5029  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
5030  *     The |stream_id| is 0.
5031  */
5032 NGHTTP2_EXTERN int nghttp2_submit_rst_stream(nghttp2_session *session,
5033                                              uint8_t flags, int32_t stream_id,
5034                                              uint32_t error_code);
5035 
5036 /**
5037  * @function
5038  *
5039  * Stores local settings and submits SETTINGS frame.  The |iv| is the
5040  * pointer to the array of :type:`nghttp2_settings_entry`.  The |niv|
5041  * indicates the number of :type:`nghttp2_settings_entry`.
5042  *
5043  * The |flags| is currently ignored and should be
5044  * :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`.
5045  *
5046  * This function does not take ownership of the |iv|.  This function
5047  * copies all the elements in the |iv|.
5048  *
5049  * While updating individual stream's local window size, if the window
5050  * size becomes strictly larger than NGHTTP2_MAX_WINDOW_SIZE,
5051  * RST_STREAM is issued against such a stream.
5052  *
5053  * SETTINGS with :enum:`nghttp2_flag.NGHTTP2_FLAG_ACK` is
5054  * automatically submitted by the library and application could not
5055  * send it at its will.
5056  *
5057  * This function returns 0 if it succeeds, or one of the following
5058  * negative error codes:
5059  *
5060  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
5061  *     The |iv| contains invalid value (e.g., initial window size
5062  *     strictly greater than (1 << 31) - 1.
5063  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
5064  *     Out of memory.
5065  */
5066 NGHTTP2_EXTERN int nghttp2_submit_settings(nghttp2_session *session,
5067                                            uint8_t flags,
5068                                            const nghttp2_settings_entry *iv,
5069                                            size_t niv);
5070 
5071 /**
5072  * @function
5073  *
5074  * Submits PUSH_PROMISE frame.
5075  *
5076  * The |flags| is currently ignored.  The library handles the
5077  * CONTINUATION frame internally and it correctly sets END_HEADERS to
5078  * the last sequence of the PUSH_PROMISE or CONTINUATION frame.
5079  *
5080  * The |stream_id| must be client initiated stream ID.
5081  *
5082  * The |nva| is an array of name/value pair :type:`nghttp2_nv` with
5083  * |nvlen| elements.  The application is responsible to include
5084  * required pseudo-header fields (header field whose name starts with
5085  * ":") in |nva| and must place pseudo-headers before regular header
5086  * fields.
5087  *
5088  * This function creates copies of all name/value pairs in |nva|.  It
5089  * also lower-cases all names in |nva|.  The order of elements in
5090  * |nva| is preserved.  For header fields with
5091  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME` and
5092  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set,
5093  * header field name and value are not copied respectively.  With
5094  * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME`, application
5095  * is responsible to pass header field name in lowercase.  The
5096  * application should maintain the references to them until
5097  * :type:`nghttp2_on_frame_send_callback` or
5098  * :type:`nghttp2_on_frame_not_send_callback` is called.
5099  *
5100  * The |promised_stream_user_data| is a pointer to an arbitrary data
5101  * which is associated to the promised stream this frame will open and
5102  * make it in reserved state.  It is available using
5103  * `nghttp2_session_get_stream_user_data()`.  The application can
5104  * access it in :type:`nghttp2_before_frame_send_callback` and
5105  * :type:`nghttp2_on_frame_send_callback` of this frame.
5106  *
5107  * The client side is not allowed to use this function.
5108  *
5109  * To submit response headers and data, use
5110  * `nghttp2_submit_response2()`.
5111  *
5112  * This function returns assigned promised stream ID if it succeeds,
5113  * or one of the following negative error codes:
5114  *
5115  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
5116  *     Out of memory.
5117  * :enum:`nghttp2_error.NGHTTP2_ERR_PROTO`
5118  *     This function was invoked when |session| is initialized as
5119  *     client.
5120  * :enum:`nghttp2_error.NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE`
5121  *     No stream ID is available because maximum stream ID was
5122  *     reached.
5123  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
5124  *     The |stream_id| is 0; The |stream_id| does not designate stream
5125  *     that peer initiated.
5126  * :enum:`nghttp2_error.NGHTTP2_ERR_STREAM_CLOSED`
5127  *     The stream was already closed; or the |stream_id| is invalid.
5128  *
5129  * .. warning::
5130  *
5131  *   This function returns assigned promised stream ID if it succeeds.
5132  *   As of 1.16.0, stream object for pushed resource is created when
5133  *   this function succeeds.  In that case, the application can submit
5134  *   push response for the promised frame.
5135  *
5136  *   In 1.15.0 or prior versions, pushed stream is not opened yet when
5137  *   this function succeeds.  The application must not submit frame to
5138  *   that stream ID before :type:`nghttp2_before_frame_send_callback`
5139  *   is called for this frame.
5140  *
5141  */
5142 NGHTTP2_EXTERN int32_t nghttp2_submit_push_promise(
5143   nghttp2_session *session, uint8_t flags, int32_t stream_id,
5144   const nghttp2_nv *nva, size_t nvlen, void *promised_stream_user_data);
5145 
5146 /**
5147  * @function
5148  *
5149  * Submits PING frame.  You don't have to send PING back when you
5150  * received PING frame.  The library automatically submits PING frame
5151  * in this case.
5152  *
5153  * The |flags| is bitwise OR of 0 or more of the following value.
5154  *
5155  * * :enum:`nghttp2_flag.NGHTTP2_FLAG_ACK`
5156  *
5157  * Unless `nghttp2_option_set_no_auto_ping_ack()` is used, the |flags|
5158  * should be :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`.
5159  *
5160  * If the |opaque_data| is non ``NULL``, then it should point to the 8
5161  * bytes array of memory to specify opaque data to send with PING
5162  * frame.  If the |opaque_data| is ``NULL``, zero-cleared 8 bytes will
5163  * be sent as opaque data.
5164  *
5165  * This function returns 0 if it succeeds, or one of the following
5166  * negative error codes:
5167  *
5168  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
5169  *     Out of memory.
5170  */
5171 NGHTTP2_EXTERN int nghttp2_submit_ping(nghttp2_session *session, uint8_t flags,
5172                                        const uint8_t *opaque_data);
5173 
5174 /**
5175  * @function
5176  *
5177  * Submits GOAWAY frame with the last stream ID |last_stream_id| and
5178  * the error code |error_code|.
5179  *
5180  * The pre-defined error code is one of :enum:`nghttp2_error_code`.
5181  *
5182  * The |flags| is currently ignored and should be
5183  * :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`.
5184  *
5185  * The |last_stream_id| is peer's stream ID or 0.  So if |session| is
5186  * initialized as client, |last_stream_id| must be even or 0.  If
5187  * |session| is initialized as server, |last_stream_id| must be odd or
5188  * 0.
5189  *
5190  * The HTTP/2 specification says last_stream_id must not be increased
5191  * from the value previously sent.  So the actual value sent as
5192  * last_stream_id is the minimum value between the given
5193  * |last_stream_id| and the last_stream_id previously sent to the
5194  * peer.
5195  *
5196  * If the |opaque_data| is not ``NULL`` and |opaque_data_len| is not
5197  * zero, those data will be sent as additional debug data.  The
5198  * library makes a copy of the memory region pointed by |opaque_data|
5199  * with the length |opaque_data_len|, so the caller does not need to
5200  * keep this memory after the return of this function.  If the
5201  * |opaque_data_len| is 0, the |opaque_data| could be ``NULL``.
5202  *
5203  * After successful transmission of GOAWAY, following things happen.
5204  * All incoming streams having strictly more than |last_stream_id| are
5205  * closed.  All incoming HEADERS which starts new stream are simply
5206  * ignored.  After all active streams are handled, both
5207  * `nghttp2_session_want_read()` and `nghttp2_session_want_write()`
5208  * return 0 and the application can close session.
5209  *
5210  * This function returns 0 if it succeeds, or one of the following
5211  * negative error codes:
5212  *
5213  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
5214  *     Out of memory.
5215  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
5216  *     The |opaque_data_len| is too large; the |last_stream_id| is
5217  *     invalid.
5218  */
5219 NGHTTP2_EXTERN int nghttp2_submit_goaway(nghttp2_session *session,
5220                                          uint8_t flags, int32_t last_stream_id,
5221                                          uint32_t error_code,
5222                                          const uint8_t *opaque_data,
5223                                          size_t opaque_data_len);
5224 
5225 /**
5226  * @function
5227  *
5228  * Returns the last stream ID of a stream for which
5229  * :type:`nghttp2_on_frame_recv_callback` was invoked most recently.
5230  * The returned value can be used as last_stream_id parameter for
5231  * `nghttp2_submit_goaway()` and
5232  * `nghttp2_session_terminate_session2()`.
5233  *
5234  * This function always succeeds.
5235  */
5236 NGHTTP2_EXTERN int32_t
5237 nghttp2_session_get_last_proc_stream_id(nghttp2_session *session);
5238 
5239 /**
5240  * @function
5241  *
5242  * Returns nonzero if new request can be sent from local endpoint.
5243  *
5244  * This function return 0 if request is not allowed for this session.
5245  * There are several reasons why request is not allowed.  Some of the
5246  * reasons are: session is server; stream ID has been spent; GOAWAY
5247  * has been sent or received.
5248  *
5249  * The application can call `nghttp2_submit_request2()` without
5250  * consulting this function.  In that case,
5251  * `nghttp2_submit_request2()` may return error.  Or, request is
5252  * failed to sent, and :type:`nghttp2_on_stream_close_callback` is
5253  * called.
5254  */
5255 NGHTTP2_EXTERN int
5256 nghttp2_session_check_request_allowed(nghttp2_session *session);
5257 
5258 /**
5259  * @function
5260  *
5261  * Returns nonzero if |session| is initialized as server side session.
5262  */
5263 NGHTTP2_EXTERN int
5264 nghttp2_session_check_server_session(nghttp2_session *session);
5265 
5266 /**
5267  * @function
5268  *
5269  * Submits WINDOW_UPDATE frame.
5270  *
5271  * The |flags| is currently ignored and should be
5272  * :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`.
5273  *
5274  * The |stream_id| is the stream ID to send this WINDOW_UPDATE.  To
5275  * send connection level WINDOW_UPDATE, specify 0 to |stream_id|.
5276  *
5277  * If the |window_size_increment| is positive, the WINDOW_UPDATE with
5278  * that value as window_size_increment is queued.  If the
5279  * |window_size_increment| is larger than the received bytes from the
5280  * remote endpoint, the local window size is increased by that
5281  * difference.  If the sole purpose is to increase the local window
5282  * size, consider to use `nghttp2_session_set_local_window_size()`.
5283  *
5284  * If the |window_size_increment| is negative, the local window size
5285  * is decreased by -|window_size_increment|.  If automatic
5286  * WINDOW_UPDATE is enabled
5287  * (`nghttp2_option_set_no_auto_window_update()`), and the library
5288  * decided that the WINDOW_UPDATE should be submitted, then
5289  * WINDOW_UPDATE is queued with the current received bytes count.  If
5290  * the sole purpose is to decrease the local window size, consider to
5291  * use `nghttp2_session_set_local_window_size()`.
5292  *
5293  * If the |window_size_increment| is 0, the function does nothing and
5294  * returns 0.
5295  *
5296  * This function returns 0 if it succeeds, or one of the following
5297  * negative error codes:
5298  *
5299  * :enum:`nghttp2_error.NGHTTP2_ERR_FLOW_CONTROL`
5300  *     The local window size overflow or gets negative.
5301  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
5302  *     Out of memory.
5303  */
5304 NGHTTP2_EXTERN int nghttp2_submit_window_update(nghttp2_session *session,
5305                                                 uint8_t flags,
5306                                                 int32_t stream_id,
5307                                                 int32_t window_size_increment);
5308 
5309 /**
5310  * @function
5311  *
5312  * Set local window size (local endpoints's window size) to the given
5313  * |window_size| for the given stream denoted by |stream_id|.  To
5314  * change connection level window size, specify 0 to |stream_id|.  To
5315  * increase window size, this function may submit WINDOW_UPDATE frame
5316  * to transmission queue.
5317  *
5318  * The |flags| is currently ignored and should be
5319  * :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`.
5320  *
5321  * This sounds similar to `nghttp2_submit_window_update()`, but there
5322  * are 2 differences.  The first difference is that this function
5323  * takes the absolute value of window size to set, rather than the
5324  * delta.  To change the window size, this may be easier to use since
5325  * the application just declares the intended window size, rather than
5326  * calculating delta.  The second difference is that
5327  * `nghttp2_submit_window_update()` affects the received bytes count
5328  * which has not acked yet.  By the specification of
5329  * `nghttp2_submit_window_update()`, to strictly increase the local
5330  * window size, we have to submit delta including all received bytes
5331  * count, which might not be desirable in some cases.  On the other
5332  * hand, this function does not affect the received bytes count.  It
5333  * just sets the local window size to the given value.
5334  *
5335  * This function returns 0 if it succeeds, or one of the following
5336  * negative error codes:
5337  *
5338  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
5339  *     The |stream_id| is negative.
5340  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
5341  *     Out of memory.
5342  */
5343 NGHTTP2_EXTERN int
5344 nghttp2_session_set_local_window_size(nghttp2_session *session, uint8_t flags,
5345                                       int32_t stream_id, int32_t window_size);
5346 
5347 /**
5348  * @function
5349  *
5350  * Submits extension frame.
5351  *
5352  * Application can pass arbitrary frame flags and stream ID in |flags|
5353  * and |stream_id| respectively.  The |payload| is opaque pointer, and
5354  * it can be accessible though ``frame->ext.payload`` in
5355  * :type:`nghttp2_pack_extension_callback2`.  The library will not own
5356  * passed |payload| pointer.
5357  *
5358  * The application must set :type:`nghttp2_pack_extension_callback2`
5359  * using `nghttp2_session_callbacks_set_pack_extension_callback2()`.
5360  *
5361  * The application should retain the memory pointed by |payload| until
5362  * the transmission of extension frame is done (which is indicated by
5363  * :type:`nghttp2_on_frame_send_callback`), or transmission fails
5364  * (which is indicated by :type:`nghttp2_on_frame_not_send_callback`).
5365  * If application does not touch this memory region after packing it
5366  * into a wire format, application can free it inside
5367  * :type:`nghttp2_pack_extension_callback2`.
5368  *
5369  * The standard HTTP/2 frame cannot be sent with this function, so
5370  * |type| must be strictly grater than 0x9.  Otherwise, this function
5371  * will fail with error code
5372  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`.
5373  *
5374  * This function returns 0 if it succeeds, or one of the following
5375  * negative error codes:
5376  *
5377  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`
5378  *     If :type:`nghttp2_pack_extension_callback2` is not set.
5379  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
5380  *     If  |type| specifies  standard  HTTP/2 frame  type.  The  frame
5381  *     types  in the  rage [0x0,  0x9], both  inclusive, are  standard
5382  *     HTTP/2 frame type, and cannot be sent using this function.
5383  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
5384  *     Out of memory
5385  */
5386 NGHTTP2_EXTERN int nghttp2_submit_extension(nghttp2_session *session,
5387                                             uint8_t type, uint8_t flags,
5388                                             int32_t stream_id, void *payload);
5389 
5390 /**
5391  * @struct
5392  *
5393  * The payload of ALTSVC frame.  ALTSVC frame is a non-critical
5394  * extension to HTTP/2.  If this frame is received, and
5395  * `nghttp2_option_set_user_recv_extension_type()` is not set, and
5396  * `nghttp2_option_set_builtin_recv_extension_type()` is set for
5397  * :enum:`nghttp2_frame_type.NGHTTP2_ALTSVC`,
5398  * ``nghttp2_extension.payload`` will point to this struct.
5399  *
5400  * It has the following members:
5401  */
5402 typedef struct {
5403   /**
5404    * The pointer to origin which this alternative service is
5405    * associated with.  This is not necessarily NULL-terminated.
5406    */
5407   uint8_t *origin;
5408   /**
5409    * The length of the |origin|.
5410    */
5411   size_t origin_len;
5412   /**
5413    * The pointer to Alt-Svc field value contained in ALTSVC frame.
5414    * This is not necessarily NULL-terminated.
5415    */
5416   uint8_t *field_value;
5417   /**
5418    * The length of the |field_value|.
5419    */
5420   size_t field_value_len;
5421 } nghttp2_ext_altsvc;
5422 
5423 /**
5424  * @function
5425  *
5426  * Submits ALTSVC frame.
5427  *
5428  * ALTSVC frame is a non-critical extension to HTTP/2, and defined in
5429  * `RFC 7383 <https://tools.ietf.org/html/rfc7838#section-4>`_.
5430  *
5431  * The |flags| is currently ignored and should be
5432  * :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`.
5433  *
5434  * The |origin| points to the origin this alternative service is
5435  * associated with.  The |origin_len| is the length of the origin.  If
5436  * |stream_id| is 0, the origin must be specified.  If |stream_id| is
5437  * not zero, the origin must be empty (in other words, |origin_len|
5438  * must be 0).
5439  *
5440  * The ALTSVC frame is only usable from server side.  If this function
5441  * is invoked with client side session, this function returns
5442  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`.
5443  *
5444  * This function returns 0 if it succeeds, or one of the following
5445  * negative error codes:
5446  *
5447  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
5448  *     Out of memory
5449  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`
5450  *     The function is called from client side session
5451  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
5452  *     The sum of |origin_len| and |field_value_len| is larger than
5453  *     16382; or |origin_len| is 0 while |stream_id| is 0; or
5454  *     |origin_len| is not 0 while |stream_id| is not 0.
5455  */
5456 NGHTTP2_EXTERN int nghttp2_submit_altsvc(nghttp2_session *session,
5457                                          uint8_t flags, int32_t stream_id,
5458                                          const uint8_t *origin,
5459                                          size_t origin_len,
5460                                          const uint8_t *field_value,
5461                                          size_t field_value_len);
5462 
5463 /**
5464  * @struct
5465  *
5466  * The single entry of an origin.
5467  */
5468 typedef struct {
5469   /**
5470    * The pointer to origin.  No validation is made against this field
5471    * by the library.  This is not necessarily NULL-terminated.
5472    */
5473   uint8_t *origin;
5474   /**
5475    * The length of the |origin|.
5476    */
5477   size_t origin_len;
5478 } nghttp2_origin_entry;
5479 
5480 /**
5481  * @struct
5482  *
5483  * The payload of ORIGIN frame.  ORIGIN frame is a non-critical
5484  * extension to HTTP/2 and defined by `RFC 8336
5485  * <https://tools.ietf.org/html/rfc8336>`_.
5486  *
5487  * If this frame is received, and
5488  * `nghttp2_option_set_user_recv_extension_type()` is not set, and
5489  * `nghttp2_option_set_builtin_recv_extension_type()` is set for
5490  * :enum:`nghttp2_frame_type.NGHTTP2_ORIGIN`,
5491  * ``nghttp2_extension.payload`` will point to this struct.
5492  *
5493  * It has the following members:
5494  */
5495 typedef struct {
5496   /**
5497    * The number of origins contained in |ov|.
5498    */
5499   size_t nov;
5500   /**
5501    * The pointer to the array of origins contained in ORIGIN frame.
5502    */
5503   nghttp2_origin_entry *ov;
5504 } nghttp2_ext_origin;
5505 
5506 /**
5507  * @function
5508  *
5509  * Submits ORIGIN frame.
5510  *
5511  * ORIGIN frame is a non-critical extension to HTTP/2 and defined by
5512  * `RFC 8336 <https://tools.ietf.org/html/rfc8336>`_.
5513  *
5514  * The |flags| is currently ignored and should be
5515  * :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`.
5516  *
5517  * The |ov| points to the array of origins.  The |nov| specifies the
5518  * number of origins included in |ov|.  This function creates copies
5519  * of all elements in |ov|.
5520  *
5521  * The ORIGIN frame is only usable by a server.  If this function is
5522  * invoked with client side session, this function returns
5523  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`.
5524  *
5525  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
5526  *     Out of memory
5527  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`
5528  *     The function is called from client side session.
5529  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
5530  *     There are too many origins, or an origin is too large to fit
5531  *     into a default frame payload.
5532  */
5533 NGHTTP2_EXTERN int nghttp2_submit_origin(nghttp2_session *session,
5534                                          uint8_t flags,
5535                                          const nghttp2_origin_entry *ov,
5536                                          size_t nov);
5537 
5538 /**
5539  * @struct
5540  *
5541  * The payload of PRIORITY_UPDATE frame.  PRIORITY_UPDATE frame is a
5542  * non-critical extension to HTTP/2.  If this frame is received, and
5543  * `nghttp2_option_set_user_recv_extension_type()` is not set, and
5544  * `nghttp2_option_set_builtin_recv_extension_type()` is set for
5545  * :enum:`nghttp2_frame_type.NGHTTP2_PRIORITY_UPDATE`,
5546  * ``nghttp2_extension.payload`` will point to this struct.
5547  *
5548  * It has the following members:
5549  */
5550 typedef struct {
5551   /**
5552    * The stream ID of the stream whose priority is updated.
5553    */
5554   int32_t stream_id;
5555   /**
5556    * The pointer to Priority field value.  It is not necessarily
5557    * NULL-terminated.
5558    */
5559   uint8_t *field_value;
5560   /**
5561    * The length of the :member:`field_value`.
5562    */
5563   size_t field_value_len;
5564 } nghttp2_ext_priority_update;
5565 
5566 /**
5567  * @function
5568  *
5569  * Submits PRIORITY_UPDATE frame.
5570  *
5571  * PRIORITY_UPDATE frame is a non-critical extension to HTTP/2, and
5572  * defined in :rfc:`9218#section-7.1`.
5573  *
5574  * The |flags| is currently ignored and should be
5575  * :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`.
5576  *
5577  * The |stream_id| is the ID of stream which is prioritized.  The
5578  * |field_value| points to the Priority field value.  The
5579  * |field_value_len| is the length of the Priority field value.
5580  *
5581  * If this function is called by server,
5582  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE` is returned.
5583  *
5584  * If
5585  * :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES`
5586  * of value of 0 is received by a remote endpoint (or it is omitted),
5587  * this function does nothing and returns 0.
5588  *
5589  * This function returns 0 if it succeeds, or one of the following
5590  * negative error codes:
5591  *
5592  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
5593  *     Out of memory
5594  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`
5595  *     The function is called from server side session
5596  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
5597  *     The |field_value_len| is larger than 16380; or |stream_id| is
5598  *     0.
5599  */
5600 NGHTTP2_EXTERN int nghttp2_submit_priority_update(nghttp2_session *session,
5601                                                   uint8_t flags,
5602                                                   int32_t stream_id,
5603                                                   const uint8_t *field_value,
5604                                                   size_t field_value_len);
5605 
5606 /**
5607  * @function
5608  *
5609  * Changes the priority of the existing stream denoted by |stream_id|.
5610  * The new priority is |extpri|.  This function is meant to be used by
5611  * server for :rfc:`9218` extensible prioritization scheme.
5612  *
5613  * If |session| is initialized as client, this function returns
5614  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`.  For client, use
5615  * `nghttp2_submit_priority_update()` instead.
5616  *
5617  * If :member:`extpri->urgency <nghttp2_extpri.urgency>` is out of
5618  * bound, it is set to :macro:`NGHTTP2_EXTPRI_URGENCY_LOW`.
5619  *
5620  * If |ignore_client_signal| is nonzero, server starts to ignore
5621  * client priority signals for this stream.
5622  *
5623  * If
5624  * :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES`
5625  * of value of 1 is not submitted via `nghttp2_submit_settings()`,
5626  * this function does nothing and returns 0.
5627  *
5628  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
5629  *     Out of memory.
5630  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`
5631  *     The |session| is initialized as client.
5632  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
5633  *     |stream_id| is zero; or a stream denoted by |stream_id| is not
5634  *     found.
5635  */
5636 NGHTTP2_EXTERN int nghttp2_session_change_extpri_stream_priority(
5637   nghttp2_session *session, int32_t stream_id, const nghttp2_extpri *extpri,
5638   int ignore_client_signal);
5639 
5640 /**
5641  * @function
5642  *
5643  * Stores the stream priority of the existing stream denoted by
5644  * |stream_id| in the object pointed by |extpri|.  This function is
5645  * meant to be used by server for :rfc:`9218` extensible
5646  * prioritization scheme.
5647  *
5648  * If |session| is initialized as client, this function returns
5649  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`.
5650  *
5651  * If
5652  * :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES`
5653  * of value of 1 is not submitted via `nghttp2_submit_settings()`,
5654  * this function does nothing and returns 0.
5655  *
5656  * This function returns 0 if it succeeds, or one of the following
5657  * negative error codes:
5658  *
5659  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`
5660  *     The |session| is initialized as client.
5661  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
5662  *     |stream_id| is zero; or a stream denoted by |stream_id| is not
5663  *     found.
5664  */
5665 NGHTTP2_EXTERN int nghttp2_session_get_extpri_stream_priority(
5666   nghttp2_session *session, nghttp2_extpri *extpri, int32_t stream_id);
5667 
5668 /**
5669  * @function
5670  *
5671  * Parses Priority header field value pointed by |value| of length
5672  * |len|, and stores the result in the object pointed by |extpri|.
5673  * Priority header field is defined in :rfc:`9218`.
5674  *
5675  * This function does not initialize the object pointed by |extpri|
5676  * before storing the result.  It only assigns the values that the
5677  * parser correctly extracted to fields.
5678  *
5679  * This function returns 0 if it succeeds, or one of the following
5680  * negative error codes:
5681  *
5682  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT`
5683  *     Failed to parse the header field value.
5684  */
5685 NGHTTP2_EXTERN int nghttp2_extpri_parse_priority(nghttp2_extpri *extpri,
5686                                                  const uint8_t *value,
5687                                                  size_t len);
5688 
5689 /**
5690  * @function
5691  *
5692  * Compares ``lhs->name`` of length ``lhs->namelen`` bytes and
5693  * ``rhs->name`` of length ``rhs->namelen`` bytes.  Returns negative
5694  * integer if ``lhs->name`` is found to be less than ``rhs->name``; or
5695  * returns positive integer if ``lhs->name`` is found to be greater
5696  * than ``rhs->name``; or returns 0 otherwise.
5697  */
5698 NGHTTP2_EXTERN int nghttp2_nv_compare_name(const nghttp2_nv *lhs,
5699                                            const nghttp2_nv *rhs);
5700 
5701 /**
5702  * @function
5703  *
5704  * .. warning::
5705  *
5706  *   Deprecated.  Use `nghttp2_select_alpn` instead.
5707  *
5708  * A helper function for dealing with ALPN in server side.  The |in|
5709  * contains peer's protocol list in preferable order.  The format of
5710  * |in| is length-prefixed and not null-terminated.  For example,
5711  * ``h2`` and ``http/1.1`` stored in |in| like this::
5712  *
5713  *     in[0] = 2
5714  *     in[1..2] = "h2"
5715  *     in[3] = 8
5716  *     in[4..11] = "http/1.1"
5717  *     inlen = 12
5718  *
5719  * The selection algorithm is as follows:
5720  *
5721  * 1. If peer's list contains HTTP/2 protocol the library supports,
5722  *    it is selected and returns 1. The following step is not taken.
5723  *
5724  * 2. If peer's list contains ``http/1.1``, this function selects
5725  *    ``http/1.1`` and returns 0.  The following step is not taken.
5726  *
5727  * 3. This function selects nothing and returns -1 (So called
5728  *    non-overlap case).  In this case, |out| and |outlen| are left
5729  *    untouched.
5730  *
5731  * Selecting ``h2`` means that ``h2`` is written into |*out| and its
5732  * length (which is 2) is assigned to |*outlen|.
5733  *
5734  * For ALPN, refer to https://tools.ietf.org/html/rfc7301
5735  *
5736  * To use this method you should do something like::
5737  *
5738  *     static int alpn_select_proto_cb(SSL* ssl,
5739  *                                     const unsigned char **out,
5740  *                                     unsigned char *outlen,
5741  *                                     const unsigned char *in,
5742  *                                     unsigned int inlen,
5743  *                                     void *arg)
5744  *     {
5745  *         int rv;
5746  *         rv = nghttp2_select_next_protocol((unsigned char**)out, outlen,
5747  *                                           in, inlen);
5748  *         if (rv == -1) {
5749  *             return SSL_TLSEXT_ERR_NOACK;
5750  *         }
5751  *         if (rv == 1) {
5752  *             ((MyType*)arg)->http2_selected = 1;
5753  *         }
5754  *         return SSL_TLSEXT_ERR_OK;
5755  *     }
5756  *     ...
5757  *     SSL_CTX_set_alpn_select_cb(ssl_ctx, alpn_select_proto_cb, my_obj);
5758  *
5759  */
5760 NGHTTP2_EXTERN int nghttp2_select_next_protocol(unsigned char **out,
5761                                                 unsigned char *outlen,
5762                                                 const unsigned char *in,
5763                                                 unsigned int inlen);
5764 
5765 /**
5766  * @function
5767  *
5768  * A helper function for dealing with ALPN in server side.  The |in|
5769  * contains peer's protocol list in preferable order.  The format of
5770  * |in| is length-prefixed and not null-terminated.  For example,
5771  * ``h2`` and ``http/1.1`` stored in |in| like this::
5772  *
5773  *     in[0] = 2
5774  *     in[1..2] = "h2"
5775  *     in[3] = 8
5776  *     in[4..11] = "http/1.1"
5777  *     inlen = 12
5778  *
5779  * The selection algorithm is as follows:
5780  *
5781  * 1. If peer's list contains HTTP/2 protocol the library supports,
5782  *    it is selected and returns 1. The following step is not taken.
5783  *
5784  * 2. If peer's list contains ``http/1.1``, this function selects
5785  *    ``http/1.1`` and returns 0.  The following step is not taken.
5786  *
5787  * 3. This function selects nothing and returns -1 (So called
5788  *    non-overlap case).  In this case, |out| and |outlen| are left
5789  *    untouched.
5790  *
5791  * Selecting ``h2`` means that ``h2`` is written into |*out| and its
5792  * length (which is 2) is assigned to |*outlen|.
5793  *
5794  * For ALPN, refer to https://tools.ietf.org/html/rfc7301
5795  *
5796  * To use this method you should do something like::
5797  *
5798  *     static int alpn_select_proto_cb(SSL* ssl,
5799  *                                     const unsigned char **out,
5800  *                                     unsigned char *outlen,
5801  *                                     const unsigned char *in,
5802  *                                     unsigned int inlen,
5803  *                                     void *arg)
5804  *     {
5805  *         int rv;
5806  *         rv = nghttp2_select_alpn(out, outlen, in, inlen);
5807  *         if (rv == -1) {
5808  *             return SSL_TLSEXT_ERR_NOACK;
5809  *         }
5810  *         if (rv == 1) {
5811  *             ((MyType*)arg)->http2_selected = 1;
5812  *         }
5813  *         return SSL_TLSEXT_ERR_OK;
5814  *     }
5815  *     ...
5816  *     SSL_CTX_set_alpn_select_cb(ssl_ctx, alpn_select_proto_cb, my_obj);
5817  *
5818  */
5819 NGHTTP2_EXTERN int nghttp2_select_alpn(const unsigned char **out,
5820                                        unsigned char *outlen,
5821                                        const unsigned char *in,
5822                                        unsigned int inlen);
5823 
5824 /**
5825  * @function
5826  *
5827  * Returns a pointer to a nghttp2_info struct with version information
5828  * about the run-time library in use.  The |least_version| argument
5829  * can be set to a 24 bit numerical value for the least accepted
5830  * version number and if the condition is not met, this function will
5831  * return a ``NULL``.  Pass in 0 to skip the version checking.
5832  */
5833 NGHTTP2_EXTERN nghttp2_info *nghttp2_version(int least_version);
5834 
5835 /**
5836  * @function
5837  *
5838  * Returns nonzero if the :type:`nghttp2_error` library error code
5839  * |lib_error| is fatal.
5840  */
5841 NGHTTP2_EXTERN int nghttp2_is_fatal(int lib_error_code);
5842 
5843 /**
5844  * @function
5845  *
5846  * Returns nonzero if HTTP header field name |name| of length |len| is
5847  * valid according to http://tools.ietf.org/html/rfc7230#section-3.2
5848  *
5849  * Because this is a header field name in HTTP2, the upper cased alphabet
5850  * is treated as error.
5851  */
5852 NGHTTP2_EXTERN int nghttp2_check_header_name(const uint8_t *name, size_t len);
5853 
5854 /**
5855  * @function
5856  *
5857  * Returns nonzero if HTTP header field value |value| of length |len|
5858  * is valid according to
5859  * http://tools.ietf.org/html/rfc7230#section-3.2
5860  *
5861  * This function is considered obsolete, and application should
5862  * consider to use `nghttp2_check_header_value_rfc9113()` instead.
5863  */
5864 NGHTTP2_EXTERN int nghttp2_check_header_value(const uint8_t *value, size_t len);
5865 
5866 /**
5867  * @function
5868  *
5869  * Returns nonzero if HTTP header field value |value| of length |len|
5870  * is valid according to
5871  * http://tools.ietf.org/html/rfc7230#section-3.2, plus
5872  * https://datatracker.ietf.org/doc/html/rfc9113#section-8.2.1
5873  */
5874 NGHTTP2_EXTERN int nghttp2_check_header_value_rfc9113(const uint8_t *value,
5875                                                       size_t len);
5876 
5877 /**
5878  * @function
5879  *
5880  * Returns nonzero if the |value| which is supposed to be the value of
5881  * the :method header field is valid according to
5882  * https://datatracker.ietf.org/doc/html/rfc7231#section-4 and
5883  * https://datatracker.ietf.org/doc/html/rfc7230#section-3.2.6
5884  */
5885 NGHTTP2_EXTERN int nghttp2_check_method(const uint8_t *value, size_t len);
5886 
5887 /**
5888  * @function
5889  *
5890  * Returns nonzero if the |value| which is supposed to be the value of
5891  * the :path header field is valid according to
5892  * https://datatracker.ietf.org/doc/html/rfc7540#section-8.1.2.3
5893  *
5894  * |value| is valid if it merely consists of the allowed characters.
5895  * In particular, it does not check whether |value| follows the syntax
5896  * of path.  The allowed characters are all characters valid by
5897  * `nghttp2_check_header_value` minus SPC and HT.
5898  */
5899 NGHTTP2_EXTERN int nghttp2_check_path(const uint8_t *value, size_t len);
5900 
5901 /**
5902  * @function
5903  *
5904  * Returns nonzero if the |value| which is supposed to be the value of the
5905  * :authority or host header field is valid according to
5906  * https://tools.ietf.org/html/rfc3986#section-3.2
5907  *
5908  * Note that :authority and host field values are not authority.  They
5909  * do not include userinfo in RFC 3986, see
5910  * https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2, that
5911  * is, it does not include '@'.  This function treats '@' as a valid
5912  * character.
5913  *
5914  * |value| is valid if it merely consists of the allowed characters.
5915  * In particular, it does not check whether |value| follows the syntax
5916  * of authority.
5917  */
5918 NGHTTP2_EXTERN int nghttp2_check_authority(const uint8_t *value, size_t len);
5919 
5920 /* HPACK API */
5921 
5922 struct nghttp2_hd_deflater;
5923 
5924 /**
5925  * @struct
5926  *
5927  * HPACK deflater object.
5928  */
5929 typedef struct nghttp2_hd_deflater nghttp2_hd_deflater;
5930 
5931 /**
5932  * @function
5933  *
5934  * Initializes |*deflater_ptr| for deflating name/values pairs.
5935  *
5936  * The |max_deflate_dynamic_table_size| is the upper bound of header
5937  * table size the deflater will use.
5938  *
5939  * If this function fails, |*deflater_ptr| is left untouched.
5940  *
5941  * This function returns 0 if it succeeds, or one of the following
5942  * negative error codes:
5943  *
5944  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
5945  *     Out of memory.
5946  */
5947 NGHTTP2_EXTERN int
5948 nghttp2_hd_deflate_new(nghttp2_hd_deflater **deflater_ptr,
5949                        size_t max_deflate_dynamic_table_size);
5950 
5951 /**
5952  * @function
5953  *
5954  * Like `nghttp2_hd_deflate_new()`, but with additional custom memory
5955  * allocator specified in the |mem|.
5956  *
5957  * The |mem| can be ``NULL`` and the call is equivalent to
5958  * `nghttp2_hd_deflate_new()`.
5959  *
5960  * This function does not take ownership |mem|.  The application is
5961  * responsible for freeing |mem|.
5962  *
5963  * The library code does not refer to |mem| pointer after this
5964  * function returns, so the application can safely free it.
5965  */
5966 NGHTTP2_EXTERN int
5967 nghttp2_hd_deflate_new2(nghttp2_hd_deflater **deflater_ptr,
5968                         size_t max_deflate_dynamic_table_size,
5969                         nghttp2_mem *mem);
5970 
5971 /**
5972  * @function
5973  *
5974  * Deallocates any resources allocated for |deflater|.
5975  */
5976 NGHTTP2_EXTERN void nghttp2_hd_deflate_del(nghttp2_hd_deflater *deflater);
5977 
5978 /**
5979  * @function
5980  *
5981  * Changes header table size of the |deflater| to
5982  * |settings_max_dynamic_table_size| bytes.  This may trigger eviction
5983  * in the dynamic table.
5984  *
5985  * The |settings_max_dynamic_table_size| should be the value received
5986  * in SETTINGS_HEADER_TABLE_SIZE.
5987  *
5988  * The deflater never uses more memory than
5989  * ``max_deflate_dynamic_table_size`` bytes specified in
5990  * `nghttp2_hd_deflate_new()`.  Therefore, if
5991  * |settings_max_dynamic_table_size| >
5992  * ``max_deflate_dynamic_table_size``, resulting maximum table size
5993  * becomes ``max_deflate_dynamic_table_size``.
5994  *
5995  * This function returns 0 if it succeeds, or one of the following
5996  * negative error codes:
5997  *
5998  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
5999  *     Out of memory.
6000  */
6001 NGHTTP2_EXTERN int
6002 nghttp2_hd_deflate_change_table_size(nghttp2_hd_deflater *deflater,
6003                                      size_t settings_max_dynamic_table_size);
6004 
6005 #ifndef NGHTTP2_NO_SSIZE_T
6006 /**
6007  * @function
6008  *
6009  * .. warning::
6010  *
6011  *   Deprecated.  Use `nghttp2_hd_deflate_hd2()` instead.
6012  *
6013  * Deflates the |nva|, which has the |nvlen| name/value pairs, into
6014  * the |buf| of length |buflen|.
6015  *
6016  * If |buf| is not large enough to store the deflated header block,
6017  * this function fails with
6018  * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE`.  The caller
6019  * should use `nghttp2_hd_deflate_bound()` to know the upper bound of
6020  * buffer size required to deflate given header name/value pairs.
6021  *
6022  * Once this function fails, subsequent call of this function always
6023  * returns :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`.
6024  *
6025  * After this function returns, it is safe to delete the |nva|.
6026  *
6027  * This function returns the number of bytes written to |buf| if it
6028  * succeeds, or one of the following negative error codes:
6029  *
6030  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
6031  *     Out of memory.
6032  * :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`
6033  *     Deflation process has failed.
6034  * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE`
6035  *     The provided |buflen| size is too small to hold the output.
6036  */
6037 NGHTTP2_EXTERN ssize_t nghttp2_hd_deflate_hd(nghttp2_hd_deflater *deflater,
6038                                              uint8_t *buf, size_t buflen,
6039                                              const nghttp2_nv *nva,
6040                                              size_t nvlen);
6041 
6042 #endif /* NGHTTP2_NO_SSIZE_T */
6043 
6044 /**
6045  * @function
6046  *
6047  * Deflates the |nva|, which has the |nvlen| name/value pairs, into
6048  * the |buf| of length |buflen|.
6049  *
6050  * If |buf| is not large enough to store the deflated header block,
6051  * this function fails with
6052  * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE`.  The caller
6053  * should use `nghttp2_hd_deflate_bound()` to know the upper bound of
6054  * buffer size required to deflate given header name/value pairs.
6055  *
6056  * Once this function fails, subsequent call of this function always
6057  * returns :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`.
6058  *
6059  * After this function returns, it is safe to delete the |nva|.
6060  *
6061  * This function returns the number of bytes written to |buf| if it
6062  * succeeds, or one of the following negative error codes:
6063  *
6064  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
6065  *     Out of memory.
6066  * :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`
6067  *     Deflation process has failed.
6068  * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE`
6069  *     The provided |buflen| size is too small to hold the output.
6070  */
6071 NGHTTP2_EXTERN nghttp2_ssize
6072 nghttp2_hd_deflate_hd2(nghttp2_hd_deflater *deflater, uint8_t *buf,
6073                        size_t buflen, const nghttp2_nv *nva, size_t nvlen);
6074 
6075 #ifndef NGHTTP2_NO_SSIZE_T
6076 /**
6077  * @function
6078  *
6079  * .. warning::
6080  *
6081  *   Deprecated.  Use `nghttp2_hd_deflate_hd_vec2()` instead.
6082  *
6083  * Deflates the |nva|, which has the |nvlen| name/value pairs, into
6084  * the |veclen| size of buf vector |vec|.  The each size of buffer
6085  * must be set in len field of :type:`nghttp2_vec`.  If and only if
6086  * one chunk is filled up completely, next chunk will be used.  If
6087  * |vec| is not large enough to store the deflated header block, this
6088  * function fails with
6089  * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE`.  The caller
6090  * should use `nghttp2_hd_deflate_bound()` to know the upper bound of
6091  * buffer size required to deflate given header name/value pairs.
6092  *
6093  * Once this function fails, subsequent call of this function always
6094  * returns :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`.
6095  *
6096  * After this function returns, it is safe to delete the |nva|.
6097  *
6098  * This function returns the number of bytes written to |vec| if it
6099  * succeeds, or one of the following negative error codes:
6100  *
6101  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
6102  *     Out of memory.
6103  * :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`
6104  *     Deflation process has failed.
6105  * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE`
6106  *     The provided |buflen| size is too small to hold the output.
6107  */
6108 NGHTTP2_EXTERN ssize_t nghttp2_hd_deflate_hd_vec(nghttp2_hd_deflater *deflater,
6109                                                  const nghttp2_vec *vec,
6110                                                  size_t veclen,
6111                                                  const nghttp2_nv *nva,
6112                                                  size_t nvlen);
6113 
6114 #endif /* NGHTTP2_NO_SSIZE_T */
6115 
6116 /**
6117  * @function
6118  *
6119  * Deflates the |nva|, which has the |nvlen| name/value pairs, into
6120  * the |veclen| size of buf vector |vec|.  The each size of buffer
6121  * must be set in len field of :type:`nghttp2_vec`.  If and only if
6122  * one chunk is filled up completely, next chunk will be used.  If
6123  * |vec| is not large enough to store the deflated header block, this
6124  * function fails with
6125  * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE`.  The caller
6126  * should use `nghttp2_hd_deflate_bound()` to know the upper bound of
6127  * buffer size required to deflate given header name/value pairs.
6128  *
6129  * Once this function fails, subsequent call of this function always
6130  * returns :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`.
6131  *
6132  * After this function returns, it is safe to delete the |nva|.
6133  *
6134  * This function returns the number of bytes written to |vec| if it
6135  * succeeds, or one of the following negative error codes:
6136  *
6137  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
6138  *     Out of memory.
6139  * :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`
6140  *     Deflation process has failed.
6141  * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE`
6142  *     The provided |buflen| size is too small to hold the output.
6143  */
6144 NGHTTP2_EXTERN nghttp2_ssize nghttp2_hd_deflate_hd_vec2(
6145   nghttp2_hd_deflater *deflater, const nghttp2_vec *vec, size_t veclen,
6146   const nghttp2_nv *nva, size_t nvlen);
6147 
6148 /**
6149  * @function
6150  *
6151  * Returns an upper bound on the compressed size after deflation of
6152  * |nva| of length |nvlen|.
6153  */
6154 NGHTTP2_EXTERN size_t nghttp2_hd_deflate_bound(nghttp2_hd_deflater *deflater,
6155                                                const nghttp2_nv *nva,
6156                                                size_t nvlen);
6157 
6158 /**
6159  * @function
6160  *
6161  * Returns the number of entries that header table of |deflater|
6162  * contains.  This is the sum of the number of static table and
6163  * dynamic table, so the return value is at least 61.
6164  */
6165 NGHTTP2_EXTERN
6166 size_t nghttp2_hd_deflate_get_num_table_entries(nghttp2_hd_deflater *deflater);
6167 
6168 /**
6169  * @function
6170  *
6171  * Returns the table entry denoted by |idx| from header table of
6172  * |deflater|.  The |idx| is 1-based, and idx=1 returns first entry of
6173  * static table.  idx=62 returns first entry of dynamic table if it
6174  * exists.  Specifying idx=0 is error, and this function returns NULL.
6175  * If |idx| is strictly greater than the number of entries the tables
6176  * contain, this function returns NULL.
6177  */
6178 NGHTTP2_EXTERN
6179 const nghttp2_nv *
6180 nghttp2_hd_deflate_get_table_entry(nghttp2_hd_deflater *deflater, size_t idx);
6181 
6182 /**
6183  * @function
6184  *
6185  * Returns the used dynamic table size, including the overhead 32
6186  * bytes per entry described in RFC 7541.
6187  */
6188 NGHTTP2_EXTERN
6189 size_t nghttp2_hd_deflate_get_dynamic_table_size(nghttp2_hd_deflater *deflater);
6190 
6191 /**
6192  * @function
6193  *
6194  * Returns the maximum dynamic table size.
6195  */
6196 NGHTTP2_EXTERN
6197 size_t
6198 nghttp2_hd_deflate_get_max_dynamic_table_size(nghttp2_hd_deflater *deflater);
6199 
6200 struct nghttp2_hd_inflater;
6201 
6202 /**
6203  * @struct
6204  *
6205  * HPACK inflater object.
6206  */
6207 typedef struct nghttp2_hd_inflater nghttp2_hd_inflater;
6208 
6209 /**
6210  * @function
6211  *
6212  * Initializes |*inflater_ptr| for inflating name/values pairs.
6213  *
6214  * If this function fails, |*inflater_ptr| is left untouched.
6215  *
6216  * This function returns 0 if it succeeds, or one of the following
6217  * negative error codes:
6218  *
6219  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
6220  *     Out of memory.
6221  */
6222 NGHTTP2_EXTERN int nghttp2_hd_inflate_new(nghttp2_hd_inflater **inflater_ptr);
6223 
6224 /**
6225  * @function
6226  *
6227  * Like `nghttp2_hd_inflate_new()`, but with additional custom memory
6228  * allocator specified in the |mem|.
6229  *
6230  * The |mem| can be ``NULL`` and the call is equivalent to
6231  * `nghttp2_hd_inflate_new()`.
6232  *
6233  * This function does not take ownership |mem|.  The application is
6234  * responsible for freeing |mem|.
6235  *
6236  * The library code does not refer to |mem| pointer after this
6237  * function returns, so the application can safely free it.
6238  */
6239 NGHTTP2_EXTERN int nghttp2_hd_inflate_new2(nghttp2_hd_inflater **inflater_ptr,
6240                                            nghttp2_mem *mem);
6241 
6242 /**
6243  * @function
6244  *
6245  * Deallocates any resources allocated for |inflater|.
6246  */
6247 NGHTTP2_EXTERN void nghttp2_hd_inflate_del(nghttp2_hd_inflater *inflater);
6248 
6249 /**
6250  * @function
6251  *
6252  * Changes header table size in the |inflater|.  This may trigger
6253  * eviction in the dynamic table.
6254  *
6255  * The |settings_max_dynamic_table_size| should be the value
6256  * transmitted in SETTINGS_HEADER_TABLE_SIZE.
6257  *
6258  * This function must not be called while header block is being
6259  * inflated.  In other words, this function must be called after
6260  * initialization of |inflater|, but before calling
6261  * `nghttp2_hd_inflate_hd3()`, or after
6262  * `nghttp2_hd_inflate_end_headers()`.  Otherwise,
6263  * `NGHTTP2_ERR_INVALID_STATE` was returned.
6264  *
6265  * This function returns 0 if it succeeds, or one of the following
6266  * negative error codes:
6267  *
6268  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
6269  *     Out of memory.
6270  * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE`
6271  *     The function is called while header block is being inflated.
6272  *     Probably, application missed to call
6273  *     `nghttp2_hd_inflate_end_headers()`.
6274  */
6275 NGHTTP2_EXTERN int
6276 nghttp2_hd_inflate_change_table_size(nghttp2_hd_inflater *inflater,
6277                                      size_t settings_max_dynamic_table_size);
6278 
6279 /**
6280  * @enum
6281  *
6282  * The flags for header inflation.
6283  */
6284 typedef enum {
6285   /**
6286    * No flag set.
6287    */
6288   NGHTTP2_HD_INFLATE_NONE = 0,
6289   /**
6290    * Indicates all headers were inflated.
6291    */
6292   NGHTTP2_HD_INFLATE_FINAL = 0x01,
6293   /**
6294    * Indicates a header was emitted.
6295    */
6296   NGHTTP2_HD_INFLATE_EMIT = 0x02
6297 } nghttp2_hd_inflate_flag;
6298 
6299 #ifndef NGHTTP2_NO_SSIZE_T
6300 /**
6301  * @function
6302  *
6303  * .. warning::
6304  *
6305  *   Deprecated.  Use `nghttp2_hd_inflate_hd2()` instead.
6306  *
6307  * Inflates name/value block stored in |in| with length |inlen|.  This
6308  * function performs decompression.  For each successful emission of
6309  * header name/value pair,
6310  * :enum:`nghttp2_hd_inflate_flag.NGHTTP2_HD_INFLATE_EMIT` is set in
6311  * |*inflate_flags| and name/value pair is assigned to the |nv_out|
6312  * and the function returns.  The caller must not free the members of
6313  * |nv_out|.
6314  *
6315  * The |nv_out| may include pointers to the memory region in the |in|.
6316  * The caller must retain the |in| while the |nv_out| is used.
6317  *
6318  * The application should call this function repeatedly until the
6319  * ``(*inflate_flags) & NGHTTP2_HD_INFLATE_FINAL`` is nonzero and
6320  * return value is non-negative.  This means the all input values are
6321  * processed successfully.  Then the application must call
6322  * `nghttp2_hd_inflate_end_headers()` to prepare for the next header
6323  * block input.
6324  *
6325  * The caller can feed complete compressed header block.  It also can
6326  * feed it in several chunks.  The caller must set |in_final| to
6327  * nonzero if the given input is the last block of the compressed
6328  * header.
6329  *
6330  * This function returns the number of bytes processed if it succeeds,
6331  * or one of the following negative error codes:
6332  *
6333  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
6334  *     Out of memory.
6335  * :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`
6336  *     Inflation process has failed.
6337  * :enum:`nghttp2_error.NGHTTP2_ERR_BUFFER_ERROR`
6338  *     The header field name or value is too large.
6339  *
6340  * Example follows::
6341  *
6342  *     int inflate_header_block(nghttp2_hd_inflater *hd_inflater,
6343  *                              uint8_t *in, size_t inlen, int final)
6344  *     {
6345  *         ssize_t rv;
6346  *
6347  *         for(;;) {
6348  *             nghttp2_nv nv;
6349  *             int inflate_flags = 0;
6350  *
6351  *             rv = nghttp2_hd_inflate_hd(hd_inflater, &nv, &inflate_flags,
6352  *                                        in, inlen, final);
6353  *
6354  *             if(rv < 0) {
6355  *                 fprintf(stderr, "inflate failed with error code %zd", rv);
6356  *                 return -1;
6357  *             }
6358  *
6359  *             in += rv;
6360  *             inlen -= rv;
6361  *
6362  *             if(inflate_flags & NGHTTP2_HD_INFLATE_EMIT) {
6363  *                 fwrite(nv.name, nv.namelen, 1, stderr);
6364  *                 fprintf(stderr, ": ");
6365  *                 fwrite(nv.value, nv.valuelen, 1, stderr);
6366  *                 fprintf(stderr, "\n");
6367  *             }
6368  *             if(inflate_flags & NGHTTP2_HD_INFLATE_FINAL) {
6369  *                 nghttp2_hd_inflate_end_headers(hd_inflater);
6370  *                 break;
6371  *             }
6372  *             if((inflate_flags & NGHTTP2_HD_INFLATE_EMIT) == 0 &&
6373  *                inlen == 0) {
6374  *                break;
6375  *             }
6376  *         }
6377  *
6378  *         return 0;
6379  *     }
6380  *
6381  */
6382 NGHTTP2_EXTERN ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_inflater *inflater,
6383                                              nghttp2_nv *nv_out,
6384                                              int *inflate_flags, uint8_t *in,
6385                                              size_t inlen, int in_final);
6386 
6387 #endif /* NGHTTP2_NO_SSIZE_T */
6388 
6389 #ifndef NGHTTP2_NO_SSIZE_T
6390 /**
6391  * @function
6392  *
6393  * .. warning::
6394  *
6395  *   Deprecated.  Use `nghttp2_hd_inflate_hd3()` instead.
6396  *
6397  * Inflates name/value block stored in |in| with length |inlen|.  This
6398  * function performs decompression.  For each successful emission of
6399  * header name/value pair,
6400  * :enum:`nghttp2_hd_inflate_flag.NGHTTP2_HD_INFLATE_EMIT` is set in
6401  * |*inflate_flags| and name/value pair is assigned to the |nv_out|
6402  * and the function returns.  The caller must not free the members of
6403  * |nv_out|.
6404  *
6405  * The |nv_out| may include pointers to the memory region in the |in|.
6406  * The caller must retain the |in| while the |nv_out| is used.
6407  *
6408  * The application should call this function repeatedly until the
6409  * ``(*inflate_flags) & NGHTTP2_HD_INFLATE_FINAL`` is nonzero and
6410  * return value is non-negative.  If that happens, all given input
6411  * data (|inlen| bytes) are processed successfully.  Then the
6412  * application must call `nghttp2_hd_inflate_end_headers()` to prepare
6413  * for the next header block input.
6414  *
6415  * In other words, if |in_final| is nonzero, and this function returns
6416  * |inlen|, you can assert that
6417  * :enum:`nghttp2_hd_inflate_final.NGHTTP2_HD_INFLATE_FINAL` is set in
6418  * |*inflate_flags|.
6419  *
6420  * The caller can feed complete compressed header block.  It also can
6421  * feed it in several chunks.  The caller must set |in_final| to
6422  * nonzero if the given input is the last block of the compressed
6423  * header.
6424  *
6425  * This function returns the number of bytes processed if it succeeds,
6426  * or one of the following negative error codes:
6427  *
6428  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
6429  *     Out of memory.
6430  * :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`
6431  *     Inflation process has failed.
6432  * :enum:`nghttp2_error.NGHTTP2_ERR_BUFFER_ERROR`
6433  *     The header field name or value is too large.
6434  *
6435  * Example follows::
6436  *
6437  *     int inflate_header_block(nghttp2_hd_inflater *hd_inflater,
6438  *                              uint8_t *in, size_t inlen, int final)
6439  *     {
6440  *         ssize_t rv;
6441  *
6442  *         for(;;) {
6443  *             nghttp2_nv nv;
6444  *             int inflate_flags = 0;
6445  *
6446  *             rv = nghttp2_hd_inflate_hd2(hd_inflater, &nv, &inflate_flags,
6447  *                                         in, inlen, final);
6448  *
6449  *             if(rv < 0) {
6450  *                 fprintf(stderr, "inflate failed with error code %zd", rv);
6451  *                 return -1;
6452  *             }
6453  *
6454  *             in += rv;
6455  *             inlen -= rv;
6456  *
6457  *             if(inflate_flags & NGHTTP2_HD_INFLATE_EMIT) {
6458  *                 fwrite(nv.name, nv.namelen, 1, stderr);
6459  *                 fprintf(stderr, ": ");
6460  *                 fwrite(nv.value, nv.valuelen, 1, stderr);
6461  *                 fprintf(stderr, "\n");
6462  *             }
6463  *             if(inflate_flags & NGHTTP2_HD_INFLATE_FINAL) {
6464  *                 nghttp2_hd_inflate_end_headers(hd_inflater);
6465  *                 break;
6466  *             }
6467  *             if((inflate_flags & NGHTTP2_HD_INFLATE_EMIT) == 0 &&
6468  *                inlen == 0) {
6469  *                break;
6470  *             }
6471  *         }
6472  *
6473  *         return 0;
6474  *     }
6475  *
6476  */
6477 NGHTTP2_EXTERN ssize_t nghttp2_hd_inflate_hd2(nghttp2_hd_inflater *inflater,
6478                                               nghttp2_nv *nv_out,
6479                                               int *inflate_flags,
6480                                               const uint8_t *in, size_t inlen,
6481                                               int in_final);
6482 
6483 #endif /* NGHTTP2_NO_SSIZE_T */
6484 
6485 /**
6486  * @function
6487  *
6488  * Inflates name/value block stored in |in| with length |inlen|.  This
6489  * function performs decompression.  For each successful emission of
6490  * header name/value pair,
6491  * :enum:`nghttp2_hd_inflate_flag.NGHTTP2_HD_INFLATE_EMIT` is set in
6492  * |*inflate_flags| and name/value pair is assigned to the |nv_out|
6493  * and the function returns.  The caller must not free the members of
6494  * |nv_out|.
6495  *
6496  * The |nv_out| may include pointers to the memory region in the |in|.
6497  * The caller must retain the |in| while the |nv_out| is used.
6498  *
6499  * The application should call this function repeatedly until the
6500  * ``(*inflate_flags) & NGHTTP2_HD_INFLATE_FINAL`` is nonzero and
6501  * return value is non-negative.  If that happens, all given input
6502  * data (|inlen| bytes) are processed successfully.  Then the
6503  * application must call `nghttp2_hd_inflate_end_headers()` to prepare
6504  * for the next header block input.
6505  *
6506  * In other words, if |in_final| is nonzero, and this function returns
6507  * |inlen|, you can assert that
6508  * :enum:`nghttp2_hd_inflate_final.NGHTTP2_HD_INFLATE_FINAL` is set in
6509  * |*inflate_flags|.
6510  *
6511  * The caller can feed complete compressed header block.  It also can
6512  * feed it in several chunks.  The caller must set |in_final| to
6513  * nonzero if the given input is the last block of the compressed
6514  * header.
6515  *
6516  * This function returns the number of bytes processed if it succeeds,
6517  * or one of the following negative error codes:
6518  *
6519  * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM`
6520  *     Out of memory.
6521  * :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`
6522  *     Inflation process has failed.
6523  * :enum:`nghttp2_error.NGHTTP2_ERR_BUFFER_ERROR`
6524  *     The header field name or value is too large.
6525  *
6526  * Example follows::
6527  *
6528  *     int inflate_header_block(nghttp2_hd_inflater *hd_inflater,
6529  *                              uint8_t *in, size_t inlen, int final)
6530  *     {
6531  *         nghttp2_ssize rv;
6532  *
6533  *         for(;;) {
6534  *             nghttp2_nv nv;
6535  *             int inflate_flags = 0;
6536  *
6537  *             rv = nghttp2_hd_inflate_hd3(hd_inflater, &nv, &inflate_flags,
6538  *                                         in, inlen, final);
6539  *
6540  *             if(rv < 0) {
6541  *                 fprintf(stderr, "inflate failed with error code %td", rv);
6542  *                 return -1;
6543  *             }
6544  *
6545  *             in += rv;
6546  *             inlen -= rv;
6547  *
6548  *             if(inflate_flags & NGHTTP2_HD_INFLATE_EMIT) {
6549  *                 fwrite(nv.name, nv.namelen, 1, stderr);
6550  *                 fprintf(stderr, ": ");
6551  *                 fwrite(nv.value, nv.valuelen, 1, stderr);
6552  *                 fprintf(stderr, "\n");
6553  *             }
6554  *             if(inflate_flags & NGHTTP2_HD_INFLATE_FINAL) {
6555  *                 nghttp2_hd_inflate_end_headers(hd_inflater);
6556  *                 break;
6557  *             }
6558  *             if((inflate_flags & NGHTTP2_HD_INFLATE_EMIT) == 0 &&
6559  *                inlen == 0) {
6560  *                break;
6561  *             }
6562  *         }
6563  *
6564  *         return 0;
6565  *     }
6566  *
6567  */
6568 NGHTTP2_EXTERN nghttp2_ssize nghttp2_hd_inflate_hd3(
6569   nghttp2_hd_inflater *inflater, nghttp2_nv *nv_out, int *inflate_flags,
6570   const uint8_t *in, size_t inlen, int in_final);
6571 
6572 /**
6573  * @function
6574  *
6575  * Signals the end of decompression for one header block.
6576  *
6577  * This function returns 0 if it succeeds. Currently this function
6578  * always succeeds.
6579  */
6580 NGHTTP2_EXTERN int
6581 nghttp2_hd_inflate_end_headers(nghttp2_hd_inflater *inflater);
6582 
6583 /**
6584  * @function
6585  *
6586  * Returns the number of entries that header table of |inflater|
6587  * contains.  This is the sum of the number of static table and
6588  * dynamic table, so the return value is at least 61.
6589  */
6590 NGHTTP2_EXTERN
6591 size_t nghttp2_hd_inflate_get_num_table_entries(nghttp2_hd_inflater *inflater);
6592 
6593 /**
6594  * @function
6595  *
6596  * Returns the table entry denoted by |idx| from header table of
6597  * |inflater|.  The |idx| is 1-based, and idx=1 returns first entry of
6598  * static table.  idx=62 returns first entry of dynamic table if it
6599  * exists.  Specifying idx=0 is error, and this function returns NULL.
6600  * If |idx| is strictly greater than the number of entries the tables
6601  * contain, this function returns NULL.
6602  */
6603 NGHTTP2_EXTERN
6604 const nghttp2_nv *
6605 nghttp2_hd_inflate_get_table_entry(nghttp2_hd_inflater *inflater, size_t idx);
6606 
6607 /**
6608  * @function
6609  *
6610  * Returns the used dynamic table size, including the overhead 32
6611  * bytes per entry described in RFC 7541.
6612  */
6613 NGHTTP2_EXTERN
6614 size_t nghttp2_hd_inflate_get_dynamic_table_size(nghttp2_hd_inflater *inflater);
6615 
6616 /**
6617  * @function
6618  *
6619  * Returns the maximum dynamic table size.
6620  */
6621 NGHTTP2_EXTERN
6622 size_t
6623 nghttp2_hd_inflate_get_max_dynamic_table_size(nghttp2_hd_inflater *inflater);
6624 
6625 struct nghttp2_stream;
6626 
6627 /**
6628  * @struct
6629  *
6630  * The structure to represent HTTP/2 stream.  The details of this
6631  * structure are intentionally hidden from the public API.
6632  */
6633 typedef struct nghttp2_stream nghttp2_stream;
6634 
6635 /**
6636  * @function
6637  *
6638  * Returns pointer to :type:`nghttp2_stream` object denoted by
6639  * |stream_id|.  If stream was not found, returns NULL.
6640  *
6641  * Returns imaginary root stream (see
6642  * `nghttp2_session_get_root_stream()`) if 0 is given in |stream_id|.
6643  *
6644  * Unless |stream_id| == 0, the returned pointer is valid until next
6645  * call of `nghttp2_session_send()`, `nghttp2_session_mem_send2()`,
6646  * `nghttp2_session_recv()`, and `nghttp2_session_mem_recv2()`.
6647  */
6648 NGHTTP2_EXTERN nghttp2_stream *
6649 nghttp2_session_find_stream(nghttp2_session *session, int32_t stream_id);
6650 
6651 /**
6652  * @enum
6653  *
6654  * State of stream as described in RFC 7540.
6655  */
6656 typedef enum {
6657   /**
6658    * idle state.
6659    */
6660   NGHTTP2_STREAM_STATE_IDLE = 1,
6661   /**
6662    * open state.
6663    */
6664   NGHTTP2_STREAM_STATE_OPEN,
6665   /**
6666    * reserved (local) state.
6667    */
6668   NGHTTP2_STREAM_STATE_RESERVED_LOCAL,
6669   /**
6670    * reserved (remote) state.
6671    */
6672   NGHTTP2_STREAM_STATE_RESERVED_REMOTE,
6673   /**
6674    * half closed (local) state.
6675    */
6676   NGHTTP2_STREAM_STATE_HALF_CLOSED_LOCAL,
6677   /**
6678    * half closed (remote) state.
6679    */
6680   NGHTTP2_STREAM_STATE_HALF_CLOSED_REMOTE,
6681   /**
6682    * closed state.
6683    */
6684   NGHTTP2_STREAM_STATE_CLOSED
6685 } nghttp2_stream_proto_state;
6686 
6687 /**
6688  * @function
6689  *
6690  * Returns state of |stream|.  The root stream retrieved by
6691  * `nghttp2_session_get_root_stream()` will have stream state
6692  * :enum:`nghttp2_stream_proto_state.NGHTTP2_STREAM_STATE_IDLE`.
6693  */
6694 NGHTTP2_EXTERN nghttp2_stream_proto_state
6695 nghttp2_stream_get_state(nghttp2_stream *stream);
6696 
6697 /**
6698  * @function
6699  *
6700  * .. warning::
6701  *
6702  *   Deprecated.  :rfc:`7540` priorities are deprecated by
6703  *   :rfc:`9113`.  Consider migrating to :rfc:`9218` extensible
6704  *   prioritization scheme.
6705  *
6706  * Returns root of dependency tree, which is imaginary stream with
6707  * stream ID 0.  The returned pointer is valid until |session| is
6708  * freed by `nghttp2_session_del()`.
6709  */
6710 NGHTTP2_EXTERN nghttp2_stream *
6711 nghttp2_session_get_root_stream(nghttp2_session *session);
6712 
6713 /**
6714  * @function
6715  *
6716  * .. warning::
6717  *
6718  *   Deprecated.  :rfc:`7540` priorities are deprecated by
6719  *   :rfc:`9113`.  Consider migrating to :rfc:`9218` extensible
6720  *   prioritization scheme.
6721  *
6722  * This function always returns NULL.
6723  */
6724 NGHTTP2_EXTERN nghttp2_stream *
6725 nghttp2_stream_get_parent(nghttp2_stream *stream);
6726 
6727 NGHTTP2_EXTERN int32_t nghttp2_stream_get_stream_id(nghttp2_stream *stream);
6728 
6729 /**
6730  * @function
6731  *
6732  * .. warning::
6733  *
6734  *   Deprecated.  :rfc:`7540` priorities are deprecated by
6735  *   :rfc:`9113`.  Consider migrating to :rfc:`9218` extensible
6736  *   prioritization scheme.
6737  *
6738  * This function always returns NULL.
6739  */
6740 NGHTTP2_EXTERN nghttp2_stream *
6741 nghttp2_stream_get_next_sibling(nghttp2_stream *stream);
6742 
6743 /**
6744  * @function
6745  *
6746  * .. warning::
6747  *
6748  *   Deprecated.  :rfc:`7540` priorities are deprecated by
6749  *   :rfc:`9113`.  Consider migrating to :rfc:`9218` extensible
6750  *   prioritization scheme.
6751  *
6752  * This function always returns NULL.
6753  */
6754 NGHTTP2_EXTERN nghttp2_stream *
6755 nghttp2_stream_get_previous_sibling(nghttp2_stream *stream);
6756 
6757 /**
6758  * @function
6759  *
6760  * .. warning::
6761  *
6762  *   Deprecated.  :rfc:`7540` priorities are deprecated by
6763  *   :rfc:`9113`.  Consider migrating to :rfc:`9218` extensible
6764  *   prioritization scheme.
6765  *
6766  * This function always returns NULL.
6767  */
6768 NGHTTP2_EXTERN nghttp2_stream *
6769 nghttp2_stream_get_first_child(nghttp2_stream *stream);
6770 
6771 /**
6772  * @function
6773  *
6774  * .. warning::
6775  *
6776  *   Deprecated.  :rfc:`7540` priorities are deprecated by
6777  *   :rfc:`9113`.  Consider migrating to :rfc:`9218` extensible
6778  *   prioritization scheme.
6779  *
6780  * This function always returns :macro:`NGHTTP2_DEFAULT_WEIGHT`.
6781  */
6782 NGHTTP2_EXTERN int32_t nghttp2_stream_get_weight(nghttp2_stream *stream);
6783 
6784 /**
6785  * @function
6786  *
6787  * .. warning::
6788  *
6789  *   Deprecated.  :rfc:`7540` priorities are deprecated by
6790  *   :rfc:`9113`.  Consider migrating to :rfc:`9218` extensible
6791  *   prioritization scheme.
6792  *
6793  * This function always returns 0.
6794  */
6795 NGHTTP2_EXTERN int32_t
6796 nghttp2_stream_get_sum_dependency_weight(nghttp2_stream *stream);
6797 
6798 /**
6799  * @functypedef
6800  *
6801  * Callback function invoked when the library outputs debug logging.
6802  * The function is called with arguments suitable for ``vfprintf(3)``
6803  *
6804  * The debug output is only enabled if the library is built with
6805  * ``DEBUGBUILD`` macro defined.
6806  */
6807 typedef void (*nghttp2_debug_vprintf_callback)(const char *format,
6808                                                va_list args);
6809 
6810 /**
6811  * @function
6812  *
6813  * Sets a debug output callback called by the library when built with
6814  * ``DEBUGBUILD`` macro defined.  If this option is not used, debug
6815  * log is written into standard error output.
6816  *
6817  * For builds without ``DEBUGBUILD`` macro defined, this function is
6818  * noop.
6819  *
6820  * Note that building with ``DEBUGBUILD`` may cause significant
6821  * performance penalty to libnghttp2 because of extra processing.  It
6822  * should be used for debugging purpose only.
6823  *
6824  * .. Warning::
6825  *
6826  *   Building with ``DEBUGBUILD`` may cause significant performance
6827  *   penalty to libnghttp2 because of extra processing.  It should be
6828  *   used for debugging purpose only.  We write this two times because
6829  *   this is important.
6830  */
6831 NGHTTP2_EXTERN void nghttp2_set_debug_vprintf_callback(
6832   nghttp2_debug_vprintf_callback debug_vprintf_callback);
6833 
6834 #ifdef __cplusplus
6835 }
6836 #endif
6837 
6838 #endif /* NGHTTP2_H */