2012-01-24 14:02:24 +01:00
|
|
|
/*
|
2013-07-12 17:19:03 +02:00
|
|
|
* nghttp2 - HTTP/2.0 C Library
|
2012-01-24 14:02:24 +01:00
|
|
|
*
|
|
|
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
#ifndef NGHTTP2_SESSION_H
|
|
|
|
#define NGHTTP2_SESSION_H
|
2012-01-24 14:02:24 +01:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif /* HAVE_CONFIG_H */
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
#include <nghttp2/nghttp2.h>
|
|
|
|
#include "nghttp2_pq.h"
|
|
|
|
#include "nghttp2_map.h"
|
|
|
|
#include "nghttp2_frame.h"
|
|
|
|
#include "nghttp2_zlib.h"
|
|
|
|
#include "nghttp2_stream.h"
|
|
|
|
#include "nghttp2_buffer.h"
|
|
|
|
#include "nghttp2_outbound_item.h"
|
|
|
|
#include "nghttp2_client_cert_vector.h"
|
2012-01-24 14:02:24 +01:00
|
|
|
|
2012-03-26 16:35:20 +02:00
|
|
|
/**
|
|
|
|
* @macro
|
|
|
|
* Lowest priority value in SPDY/2, which is 3.
|
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
#define NGHTTP2_PRI_LOWEST_SPDY2 3
|
2012-03-26 16:35:20 +02:00
|
|
|
/**
|
|
|
|
* @macro
|
|
|
|
* Lowest priority value in SPDY/3, which is 7.
|
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
#define NGHTTP2_PRI_LOWEST_SPDY3 7
|
2012-03-26 16:35:20 +02:00
|
|
|
|
2012-05-08 15:59:34 +02:00
|
|
|
/*
|
|
|
|
* Option flags.
|
|
|
|
*/
|
|
|
|
typedef enum {
|
2013-07-12 17:19:03 +02:00
|
|
|
NGHTTP2_OPTMASK_NO_AUTO_WINDOW_UPDATE = 1 << 0
|
|
|
|
} nghttp2_optmask;
|
2012-05-08 15:59:34 +02:00
|
|
|
|
2012-01-24 14:02:24 +01:00
|
|
|
typedef struct {
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_outbound_item *item;
|
2012-02-16 12:54:30 +01:00
|
|
|
/* Buffer for outbound frames. Used to pack one frame. The memory
|
|
|
|
pointed by framebuf is initially allocated by
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_session_{client,server}_new() and deallocated by
|
|
|
|
nghttp2_session_del() */
|
2012-01-24 14:02:24 +01:00
|
|
|
uint8_t *framebuf;
|
2012-02-16 12:54:30 +01:00
|
|
|
/* The capacity of framebuf in bytes */
|
|
|
|
size_t framebufmax;
|
|
|
|
/* The length of the frame stored in framebuf */
|
2012-01-24 14:02:24 +01:00
|
|
|
size_t framebuflen;
|
2012-02-16 12:54:30 +01:00
|
|
|
/* The number of bytes has been sent */
|
2012-01-24 14:02:24 +01:00
|
|
|
size_t framebufoff;
|
2013-07-12 17:19:03 +02:00
|
|
|
} nghttp2_active_outbound_item;
|
2012-01-24 14:02:24 +01:00
|
|
|
|
2012-03-17 15:39:38 +01:00
|
|
|
/* Buffer length for inbound raw byte stream. */
|
2013-07-12 17:19:03 +02:00
|
|
|
#define NGHTTP2_INBOUND_BUFFER_LENGTH 16384
|
2012-02-07 17:25:26 +01:00
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
#define NGHTTP2_INITIAL_OUTBOUND_FRAMEBUF_LENGTH (NGHTTP2_DATA_PAYLOAD_LENGTH+8)
|
|
|
|
#define NGHTTP2_INITIAL_INBOUND_FRAMEBUF_LENGTH \
|
|
|
|
NGHTTP2_INITIAL_OUTBOUND_FRAMEBUF_LENGTH
|
|
|
|
#define NGHTTP2_INITIAL_NV_BUFFER_LENGTH 4096
|
2012-02-16 12:54:30 +01:00
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
#define NGHTTP2_INITIAL_WINDOW_SIZE 65536
|
2012-02-25 16:12:32 +01:00
|
|
|
|
2012-04-05 18:45:39 +02:00
|
|
|
/* Initial size of client certificate vector */
|
2013-07-12 17:19:03 +02:00
|
|
|
#define NGHTTP2_INITIAL_CLIENT_CERT_VECTOR_LENGTH 8
|
2012-04-05 18:45:39 +02:00
|
|
|
/* Maxmum size of client certificate vector */
|
2013-07-12 17:19:03 +02:00
|
|
|
#define NGHTTP2_MAX_CLIENT_CERT_VECTOR_LENGTH 255
|
2012-04-05 18:45:39 +02:00
|
|
|
|
2012-05-25 03:46:40 +02:00
|
|
|
/* Internal state when receiving incoming frame */
|
2012-01-24 14:02:24 +01:00
|
|
|
typedef enum {
|
2012-05-25 03:46:40 +02:00
|
|
|
/* Receiving frame header */
|
2013-07-12 17:19:03 +02:00
|
|
|
NGHTTP2_RECV_HEAD,
|
2012-05-25 03:46:40 +02:00
|
|
|
/* Receiving frame payload (comes after length field) */
|
2013-07-12 17:19:03 +02:00
|
|
|
NGHTTP2_RECV_PAYLOAD,
|
2012-05-25 06:49:18 +02:00
|
|
|
/* Receiving frame payload, but the received bytes are discarded. */
|
2013-07-12 17:19:03 +02:00
|
|
|
NGHTTP2_RECV_PAYLOAD_IGN,
|
2012-05-25 03:46:40 +02:00
|
|
|
/* Receiving frame payload that comes before name/value header
|
|
|
|
block. Applied only for SYN_STREAM, SYN_REPLY and HEADERS. */
|
2013-07-12 17:19:03 +02:00
|
|
|
NGHTTP2_RECV_PAYLOAD_PRE_NV,
|
2012-05-25 03:46:40 +02:00
|
|
|
/* Receiving name/value header block in frame payload. Applied only
|
|
|
|
for SYN_STREAM, SYN_REPLY and HEADERS. */
|
2013-07-12 17:19:03 +02:00
|
|
|
NGHTTP2_RECV_PAYLOAD_NV
|
|
|
|
} nghttp2_inbound_state;
|
2012-01-24 14:02:24 +01:00
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
#define NGHTTP2_HEAD_LEN 8
|
2012-01-24 14:02:24 +01:00
|
|
|
|
2012-01-27 15:05:29 +01:00
|
|
|
/* Maximum unique ID in use for PING. If unique ID exeeds this number,
|
|
|
|
it wraps to 1 (client) or 2 (server) */
|
2013-07-12 17:19:03 +02:00
|
|
|
#define NGHTTP2_MAX_UNIQUE_ID ((1u << 31)-1)
|
2012-01-27 15:05:29 +01:00
|
|
|
|
2012-01-24 14:02:24 +01:00
|
|
|
typedef struct {
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_inbound_state state;
|
|
|
|
uint8_t headbuf[NGHTTP2_HEAD_LEN];
|
2012-03-17 15:39:38 +01:00
|
|
|
/* How many bytes are filled in headbuf */
|
|
|
|
size_t headbufoff;
|
2012-02-16 15:09:06 +01:00
|
|
|
/* Payload for control frames. It is not used for DATA frames */
|
2012-01-24 14:02:24 +01:00
|
|
|
uint8_t *buf;
|
2012-02-16 15:09:06 +01:00
|
|
|
/* Capacity of buf */
|
|
|
|
size_t bufmax;
|
2012-05-25 03:46:40 +02:00
|
|
|
/* For frames without name/value header block, this is how many
|
|
|
|
bytes are going to filled in buf. For frames with the block, buf
|
|
|
|
only contains bytes that come before ther block, but this value
|
|
|
|
includes the length of the block. buflen <= bufmax must be
|
|
|
|
fulfilled. */
|
|
|
|
size_t buflen;
|
2012-01-24 14:02:24 +01:00
|
|
|
/* length in Length field */
|
2012-05-25 03:46:40 +02:00
|
|
|
size_t payloadlen;
|
|
|
|
/* How many bytes are received for this frame. off <= payloadlen
|
|
|
|
must be fulfilled. */
|
2012-01-24 14:02:24 +01:00
|
|
|
size_t off;
|
2012-05-25 03:46:40 +02:00
|
|
|
/* Buffer used to store name/value pairs while inflating them using
|
|
|
|
zlib on unpack */
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_buffer inflatebuf;
|
2012-05-25 03:46:40 +02:00
|
|
|
/* Error code */
|
|
|
|
int error_code;
|
2013-07-12 17:19:03 +02:00
|
|
|
} nghttp2_inbound_frame;
|
2012-01-24 14:02:24 +01:00
|
|
|
|
2012-01-28 11:22:38 +01:00
|
|
|
typedef enum {
|
2013-07-12 17:19:03 +02:00
|
|
|
NGHTTP2_GOAWAY_NONE = 0,
|
2012-01-28 11:22:38 +01:00
|
|
|
/* Flag means GOAWAY frame is sent to the remote peer. */
|
2013-07-12 17:19:03 +02:00
|
|
|
NGHTTP2_GOAWAY_SEND = 0x1,
|
2012-01-28 11:22:38 +01:00
|
|
|
/* Flag means GOAWAY frame is received from the remote peer. */
|
2013-07-12 17:19:03 +02:00
|
|
|
NGHTTP2_GOAWAY_RECV = 0x2,
|
2012-02-18 13:55:40 +01:00
|
|
|
/* Flag means connection should be dropped after sending GOAWAY. */
|
2013-07-12 17:19:03 +02:00
|
|
|
NGHTTP2_GOAWAY_FAIL_ON_SEND = 0x4
|
|
|
|
} nghttp2_goaway_flag;
|
2012-01-28 11:22:38 +01:00
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
struct nghttp2_session {
|
|
|
|
/* The protocol version: either NGHTTP2_PROTO_SPDY2 or
|
|
|
|
NGHTTP2_PROTO_SPDY3 */
|
2012-02-24 15:33:06 +01:00
|
|
|
uint16_t version;
|
2012-01-24 14:02:24 +01:00
|
|
|
uint8_t server;
|
2012-03-07 16:18:18 +01:00
|
|
|
/* Next Stream ID. Made unsigned int to detect >= (1 << 31). */
|
|
|
|
uint32_t next_stream_id;
|
2012-01-25 13:31:28 +01:00
|
|
|
int32_t last_recv_stream_id;
|
2012-01-27 15:05:29 +01:00
|
|
|
/* Counter of unique ID of PING. Wraps when it exceeds
|
2013-07-12 17:19:03 +02:00
|
|
|
NGHTTP2_MAX_UNIQUE_ID */
|
2012-01-27 15:05:29 +01:00
|
|
|
uint32_t next_unique_id;
|
|
|
|
|
2012-01-31 14:48:09 +01:00
|
|
|
/* Sequence number of outbound frame to maintain the order of
|
|
|
|
enqueue if priority is equal. */
|
|
|
|
int64_t next_seq;
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_map /* <nghttp2_stream*> */ streams;
|
2012-05-07 17:59:26 +02:00
|
|
|
/* The number of outgoing streams. This will be capped by
|
2013-07-12 17:19:03 +02:00
|
|
|
remote_settings[NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS]. */
|
2012-05-07 17:59:26 +02:00
|
|
|
size_t num_outgoing_streams;
|
|
|
|
/* The number of incoming streams. This will be capped by
|
2013-07-12 17:19:03 +02:00
|
|
|
local_settings[NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS]. */
|
2012-05-07 17:59:26 +02:00
|
|
|
size_t num_incoming_streams;
|
|
|
|
|
2012-02-05 16:14:19 +01:00
|
|
|
/* Queue for outbound frames other than SYN_STREAM */
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_pq /* <nghttp2_outbound_item*> */ ob_pq;
|
2012-02-05 16:14:19 +01:00
|
|
|
/* Queue for outbound SYN_STREAM frame */
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_pq /* <nghttp2_outbound_item*> */ ob_ss_pq;
|
2012-01-24 14:02:24 +01:00
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_active_outbound_item aob;
|
2012-01-24 14:02:24 +01:00
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_inbound_frame iframe;
|
2012-01-24 14:02:24 +01:00
|
|
|
|
2012-02-16 12:54:30 +01:00
|
|
|
/* Buffer used to store inflated name/value pairs in wire format
|
|
|
|
temporarily on pack/unpack. */
|
|
|
|
uint8_t *nvbuf;
|
|
|
|
/* The number of bytes allocated for nvbuf */
|
|
|
|
size_t nvbuflen;
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_zlib hd_deflater;
|
|
|
|
nghttp2_zlib hd_inflater;
|
2012-01-24 14:02:24 +01:00
|
|
|
|
2012-01-27 15:05:29 +01:00
|
|
|
/* The last unique ID sent to the peer. */
|
|
|
|
uint32_t last_ping_unique_id;
|
|
|
|
|
2012-01-28 11:22:38 +01:00
|
|
|
/* Flags indicating GOAWAY is sent and/or recieved. The flags are
|
2013-07-12 17:19:03 +02:00
|
|
|
composed by bitwise OR-ing nghttp2_goaway_flag. */
|
2012-01-28 11:22:38 +01:00
|
|
|
uint8_t goaway_flags;
|
|
|
|
/* This is the value in GOAWAY frame sent by remote endpoint. */
|
|
|
|
int32_t last_good_stream_id;
|
|
|
|
|
2012-02-25 16:12:32 +01:00
|
|
|
/* Flag to indicate whether this session enforces flow
|
|
|
|
control. Nonzero for flow control enabled. */
|
|
|
|
uint8_t flow_control;
|
|
|
|
|
2012-03-09 16:10:11 +01:00
|
|
|
/* Settings value received from the remote endpoint. We just use ID
|
|
|
|
as index. The index = 0 is unused. */
|
2013-07-12 17:19:03 +02:00
|
|
|
uint32_t remote_settings[NGHTTP2_SETTINGS_MAX+1];
|
2012-03-09 16:10:11 +01:00
|
|
|
/* Settings value of the local endpoint. */
|
2013-07-12 17:19:03 +02:00
|
|
|
uint32_t local_settings[NGHTTP2_SETTINGS_MAX+1];
|
2012-02-05 16:14:19 +01:00
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
/* Option flags. This is bitwise-OR of 0 or more of nghttp2_optmask. */
|
2012-05-08 15:59:34 +02:00
|
|
|
uint32_t opt_flags;
|
2012-05-25 06:49:18 +02:00
|
|
|
/* Maxmum size of buffer to use when receving control frame. */
|
|
|
|
uint32_t max_recv_ctrl_frame_buf;
|
2012-05-08 15:59:34 +02:00
|
|
|
|
2012-04-05 18:45:39 +02:00
|
|
|
/* Client certificate vector */
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_client_cert_vector cli_certvec;
|
2012-04-05 18:45:39 +02:00
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_session_callbacks callbacks;
|
2012-01-24 14:02:24 +01:00
|
|
|
void *user_data;
|
2012-01-31 13:32:46 +01:00
|
|
|
};
|
2012-01-24 14:02:24 +01:00
|
|
|
|
2012-05-11 15:58:12 +02:00
|
|
|
/* Struct used when updating initial window size of each active
|
|
|
|
stream. */
|
|
|
|
typedef struct {
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_session *session;
|
2012-05-11 15:58:12 +02:00
|
|
|
int32_t new_window_size, old_window_size;
|
2013-07-12 17:19:03 +02:00
|
|
|
} nghttp2_update_window_size_arg;
|
2012-05-11 15:58:12 +02:00
|
|
|
|
2012-01-24 14:02:24 +01:00
|
|
|
/* TODO stream timeout etc */
|
|
|
|
|
2012-02-02 15:19:01 +01:00
|
|
|
/*
|
2012-02-22 15:39:30 +01:00
|
|
|
* Returns nonzero value if |stream_id| is initiated by local
|
|
|
|
* endpoint.
|
2012-02-02 15:19:01 +01:00
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
int nghttp2_session_is_my_stream_id(nghttp2_session *session,
|
2012-02-02 15:19:01 +01:00
|
|
|
int32_t stream_id);
|
|
|
|
|
2012-01-29 11:07:31 +01:00
|
|
|
/*
|
2012-03-29 16:59:51 +02:00
|
|
|
* Adds frame |frame| to the outbound queue in |session|. The
|
2013-07-12 17:19:03 +02:00
|
|
|
* |frame_cat| must be either NGHTTP2_CTRL or NGHTTP2_DATA. If the
|
|
|
|
* |frame_cat| is NGHTTP2_CTRL, the |frame| must be a pointer to
|
|
|
|
* nghttp2_frame. If the |frame_cat| is NGHTTP2_DATA, it must be a
|
|
|
|
* pointer to nghttp2_data. |aux_data| is a pointer to the arbitrary
|
2012-03-29 16:59:51 +02:00
|
|
|
* data. Its interpretation is defined per the type of the frame. When
|
|
|
|
* this function succeeds, it takes ownership of |frame| and
|
|
|
|
* |aux_data|, so caller must not free them on success.
|
2012-02-22 15:39:30 +01:00
|
|
|
*
|
|
|
|
* This function returns 0 if it succeeds, or one of the following
|
|
|
|
* negative error codes:
|
|
|
|
*
|
2013-07-12 17:19:03 +02:00
|
|
|
* NGHTTP2_ERR_NOMEM
|
2012-02-22 15:39:30 +01:00
|
|
|
* Out of memory.
|
2012-01-29 11:07:31 +01:00
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
int nghttp2_session_add_frame(nghttp2_session *session,
|
|
|
|
nghttp2_frame_category frame_cat,
|
2012-03-29 16:59:51 +02:00
|
|
|
void *abs_frame, void *aux_data);
|
2012-01-24 14:02:24 +01:00
|
|
|
|
2012-02-22 15:39:30 +01:00
|
|
|
/*
|
|
|
|
* Adds RST_STREAM frame for the stream |stream_id| with status code
|
|
|
|
* |status_code|. This is a convenient function built on top of
|
2013-07-12 17:19:03 +02:00
|
|
|
* nghttp2_session_add_frame() to add RST_STREAM easily.
|
2012-02-22 15:39:30 +01:00
|
|
|
*
|
|
|
|
* This function returns 0 if it succeeds, or one of the following
|
|
|
|
* negative error codes:
|
|
|
|
*
|
2013-07-12 17:19:03 +02:00
|
|
|
* NGHTTP2_ERR_NOMEM
|
2012-02-22 15:39:30 +01:00
|
|
|
* Out of memory.
|
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
int nghttp2_session_add_rst_stream(nghttp2_session *session,
|
2012-01-25 13:31:28 +01:00
|
|
|
int32_t stream_id, uint32_t status_code);
|
|
|
|
|
2012-02-22 15:39:30 +01:00
|
|
|
/*
|
|
|
|
* Adds PING frame with unique ID |unique_id|. This is a convenient
|
2013-07-12 17:19:03 +02:00
|
|
|
* functin built on top of nghttp2_session_add_frame() to add PING
|
2012-02-22 15:39:30 +01:00
|
|
|
* easily.
|
|
|
|
*
|
|
|
|
* This function returns 0 if it succeeds, or one of the following
|
|
|
|
* negative error codes:
|
|
|
|
*
|
2013-07-12 17:19:03 +02:00
|
|
|
* NGHTTP2_ERR_NOMEM
|
2012-02-22 15:39:30 +01:00
|
|
|
* Out of memory.
|
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
int nghttp2_session_add_ping(nghttp2_session *session, uint32_t unique_id);
|
2012-01-27 15:05:29 +01:00
|
|
|
|
2012-02-22 15:39:30 +01:00
|
|
|
/*
|
2012-02-26 08:26:38 +01:00
|
|
|
* Adds GOAWAY frame with last-good-stream-ID |last_good_stream_id|
|
|
|
|
* and the status code |status_code|. The |status_code| is ignored if
|
2013-07-12 17:19:03 +02:00
|
|
|
* the protocol version is NGHTTP2_PROTO_SPDY2. This is a convenient
|
|
|
|
* function built on top of nghttp2_session_add_frame() to add GOAWAY
|
2012-02-26 08:26:38 +01:00
|
|
|
* easily.
|
2012-02-22 15:39:30 +01:00
|
|
|
*
|
|
|
|
* This function returns 0 if it succeeds, or one of the following
|
|
|
|
* negative error codes:
|
|
|
|
*
|
2013-07-12 17:19:03 +02:00
|
|
|
* NGHTTP2_ERR_NOMEM
|
2012-02-22 15:39:30 +01:00
|
|
|
* Out of memory.
|
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
int nghttp2_session_add_goaway(nghttp2_session *session,
|
2012-02-26 08:26:38 +01:00
|
|
|
int32_t last_good_stream_id,
|
|
|
|
uint32_t status_code);
|
2012-01-28 11:22:38 +01:00
|
|
|
|
2012-02-25 16:12:32 +01:00
|
|
|
/*
|
|
|
|
* Adds WINDOW_UPDATE frame with stream ID |stream_id| and
|
|
|
|
* delta-window-size |delta_window_size|. This is a convenient
|
2013-07-12 17:19:03 +02:00
|
|
|
* function built on top of nghttp2_session_add_frame() to add
|
2012-02-25 16:12:32 +01:00
|
|
|
* WINDOW_UPDATE easily.
|
|
|
|
*
|
|
|
|
* This function returns 0 if it succeeds, or one of the following
|
|
|
|
* negative error codes:
|
|
|
|
*
|
2013-07-12 17:19:03 +02:00
|
|
|
* NGHTTP2_ERR_NOMEM
|
2012-02-25 16:12:32 +01:00
|
|
|
* Out of memory.
|
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
int nghttp2_session_add_window_update(nghttp2_session *session,
|
2012-02-25 16:12:32 +01:00
|
|
|
int32_t stream_id,
|
|
|
|
int32_t delta_window_size);
|
|
|
|
|
2012-01-25 15:46:07 +01:00
|
|
|
/*
|
|
|
|
* Creates new stream in |session| with stream ID |stream_id|,
|
2013-07-12 17:19:03 +02:00
|
|
|
* priority |pri| and flags |flags|. NGHTTP2_CTRL_FLAG_UNIDIRECTIONAL
|
2012-02-24 13:40:13 +01:00
|
|
|
* flag is set in |flags|, this stream is
|
2013-07-12 17:19:03 +02:00
|
|
|
* unidirectional. NGHTTP2_CTRL_FLAG_FIN flag is set in |flags|, the
|
2012-02-24 13:40:13 +01:00
|
|
|
* sender of SYN_STREAM will not send any further data in this
|
|
|
|
* stream. Since this function is called when SYN_STREAM is sent or
|
|
|
|
* received, these flags are taken from SYN_STREAM. The state of
|
|
|
|
* stream is set to |initial_state|. |stream_user_data| is a pointer
|
|
|
|
* to the arbitrary user supplied data to be associated to this
|
|
|
|
* stream.
|
2012-02-22 15:39:30 +01:00
|
|
|
*
|
|
|
|
* This function returns a pointer to created new stream object, or
|
|
|
|
* NULL.
|
2012-01-25 15:46:07 +01:00
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_stream* nghttp2_session_open_stream(nghttp2_session *session,
|
2012-01-28 16:16:51 +01:00
|
|
|
int32_t stream_id,
|
|
|
|
uint8_t flags, uint8_t pri,
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_stream_state initial_state,
|
2012-02-03 17:37:21 +01:00
|
|
|
void *stream_user_data);
|
2012-01-24 14:02:24 +01:00
|
|
|
|
2012-01-25 17:04:01 +01:00
|
|
|
/*
|
2012-01-29 15:00:33 +01:00
|
|
|
* Closes stream whose stream ID is |stream_id|. The reason of closure
|
2012-02-22 15:39:30 +01:00
|
|
|
* is indicated by |status_code|. When closing the stream,
|
|
|
|
* on_stream_close_callback will be called.
|
|
|
|
*
|
|
|
|
* This function returns 0 if it succeeds, or one the following
|
|
|
|
* negative error codes:
|
|
|
|
*
|
2013-07-12 17:19:03 +02:00
|
|
|
* NGHTTP2_ERR_INVALID_ARGUMENT
|
2012-02-22 15:39:30 +01:00
|
|
|
* The specified stream does not exist.
|
2012-01-25 17:04:01 +01:00
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
int nghttp2_session_close_stream(nghttp2_session *session, int32_t stream_id,
|
|
|
|
nghttp2_status_code status_code);
|
2012-01-24 14:02:24 +01:00
|
|
|
|
2012-02-02 15:19:01 +01:00
|
|
|
/*
|
|
|
|
* Closes all pushed streams which associate them to stream
|
|
|
|
* |stream_id| with the status code |status_code|.
|
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
void nghttp2_session_close_pushed_streams(nghttp2_session *session,
|
2012-02-02 15:19:01 +01:00
|
|
|
int32_t stream_id,
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_status_code status_code);
|
2012-02-02 15:19:01 +01:00
|
|
|
|
2012-01-28 16:08:51 +01:00
|
|
|
/*
|
2012-02-22 15:39:30 +01:00
|
|
|
* If further receptions and transmissions over the stream |stream_id|
|
|
|
|
* are disallowed, close the stream with status code |status_code|.
|
|
|
|
*
|
|
|
|
* This function returns 0 if it
|
|
|
|
* succeeds, or one of the following negative error codes:
|
|
|
|
*
|
2013-07-12 17:19:03 +02:00
|
|
|
* NGHTTP2_ERR_INVALID_ARGUMENT
|
2012-02-22 15:39:30 +01:00
|
|
|
* The specified stream does not exist.
|
2012-01-28 16:08:51 +01:00
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
int nghttp2_session_close_stream_if_shut_rdwr(nghttp2_session *session,
|
|
|
|
nghttp2_stream *stream);
|
2012-01-28 16:08:51 +01:00
|
|
|
|
2012-01-25 15:46:07 +01:00
|
|
|
/*
|
2012-02-22 15:39:30 +01:00
|
|
|
* Called when SYN_STREAM is received, assuming |frame.syn_stream| is
|
|
|
|
* properly initialized. This function does first validate received
|
|
|
|
* frame and then open stream and call callback functions. This
|
|
|
|
* function does not return error if frame is not valid.
|
|
|
|
*
|
|
|
|
* This function returns 0 if it succeeds, or one of the following
|
|
|
|
* negative error codes:
|
|
|
|
*
|
2013-07-12 17:19:03 +02:00
|
|
|
* NGHTTP2_ERR_NOMEM
|
2012-02-22 15:39:30 +01:00
|
|
|
* Out of memory.
|
2012-01-25 15:46:07 +01:00
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
int nghttp2_session_on_syn_stream_received(nghttp2_session *session,
|
|
|
|
nghttp2_frame *frame);
|
2012-01-25 15:46:07 +01:00
|
|
|
|
|
|
|
/*
|
2012-02-22 15:39:30 +01:00
|
|
|
* Called when SYN_REPLY is received, assuming |frame.syn_reply| is
|
|
|
|
* properly initialized.
|
|
|
|
*
|
|
|
|
* This function returns 0 if it succeeds, or one of the following
|
|
|
|
* negative error codes:
|
|
|
|
*
|
2013-07-12 17:19:03 +02:00
|
|
|
* NGHTTP2_ERR_NOMEM
|
2012-02-22 15:39:30 +01:00
|
|
|
* Out of memory.
|
2012-01-25 15:46:07 +01:00
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
int nghttp2_session_on_syn_reply_received(nghttp2_session *session,
|
|
|
|
nghttp2_frame *frame);
|
2012-01-25 15:46:07 +01:00
|
|
|
|
|
|
|
|
2012-01-27 15:22:27 +01:00
|
|
|
/*
|
2012-02-22 15:39:30 +01:00
|
|
|
* Called when RST_STREAM is received, assuming |frame.rst_stream| is
|
|
|
|
* properly initialized.
|
|
|
|
*
|
|
|
|
* This function returns 0 and never fail.
|
2012-01-27 15:22:27 +01:00
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
int nghttp2_session_on_rst_stream_received(nghttp2_session *session,
|
|
|
|
nghttp2_frame *frame);
|
2012-01-27 15:22:27 +01:00
|
|
|
|
2012-01-31 17:12:26 +01:00
|
|
|
/*
|
2012-02-22 15:39:30 +01:00
|
|
|
* Called when SETTINGS is received, assuming |frame.settings| is
|
|
|
|
* properly initialized.
|
|
|
|
*
|
|
|
|
* This function returns 0 and never fail.
|
2012-01-31 17:12:26 +01:00
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
int nghttp2_session_on_settings_received(nghttp2_session *session,
|
|
|
|
nghttp2_frame *frame);
|
2012-01-31 17:12:26 +01:00
|
|
|
|
2012-01-27 15:37:47 +01:00
|
|
|
/*
|
2012-02-22 15:39:30 +01:00
|
|
|
* Called when PING is received, assuming |frame.ping| is properly
|
|
|
|
* initialized.
|
|
|
|
*
|
|
|
|
* This function returns 0 if it succeeds, or one of the following
|
|
|
|
* negative error codes:
|
|
|
|
*
|
2013-07-12 17:19:03 +02:00
|
|
|
* NGHTTP2_ERR_NOMEM
|
2012-02-22 15:39:30 +01:00
|
|
|
* Out of memory.
|
2012-01-27 15:37:47 +01:00
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
int nghttp2_session_on_ping_received(nghttp2_session *session,
|
|
|
|
nghttp2_frame *frame);
|
2012-01-27 15:37:47 +01:00
|
|
|
|
2012-01-28 11:22:38 +01:00
|
|
|
/*
|
2012-02-22 15:39:30 +01:00
|
|
|
* Called when GOAWAY is received, assuming |frame.goaway| is properly
|
|
|
|
* initialized.
|
|
|
|
*
|
|
|
|
* This function returns 0 and never fail.
|
2012-01-28 11:22:38 +01:00
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
int nghttp2_session_on_goaway_received(nghttp2_session *session,
|
|
|
|
nghttp2_frame *frame);
|
2012-01-28 11:22:38 +01:00
|
|
|
|
2012-01-27 11:10:13 +01:00
|
|
|
/*
|
2012-02-22 15:39:30 +01:00
|
|
|
* Called when HEADERS is recieved, assuming |frame.headers| is
|
|
|
|
* properly initialized.
|
|
|
|
*
|
|
|
|
* This function returns 0 if it succeeds, or one of the following
|
|
|
|
* negative error codes:
|
|
|
|
*
|
2013-07-12 17:19:03 +02:00
|
|
|
* NGHTTP2_ERR_NOMEM
|
2012-02-22 15:39:30 +01:00
|
|
|
* Out of memory.
|
2012-01-27 11:10:13 +01:00
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
int nghttp2_session_on_headers_received(nghttp2_session *session,
|
|
|
|
nghttp2_frame *frame);
|
2012-01-27 11:10:13 +01:00
|
|
|
|
2012-02-25 16:12:32 +01:00
|
|
|
/*
|
|
|
|
* Called when WINDOW_UPDATE is recieved, assuming
|
|
|
|
* |frame.window_update| is properly initialized.
|
|
|
|
*
|
|
|
|
* This function returns 0 if it succeeds, or one of the following
|
|
|
|
* negative error codes:
|
|
|
|
*
|
2013-07-12 17:19:03 +02:00
|
|
|
* NGHTTP2_ERR_NOMEM
|
2012-02-25 16:12:32 +01:00
|
|
|
* Out of memory.
|
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
int nghttp2_session_on_window_update_received(nghttp2_session *session,
|
|
|
|
nghttp2_frame *frame);
|
2012-02-25 16:12:32 +01:00
|
|
|
|
2012-04-05 18:45:39 +02:00
|
|
|
/*
|
|
|
|
* Called when CREDENTIAL is received, assuming |frame.credential| is
|
|
|
|
* properly initialized.
|
|
|
|
*
|
|
|
|
* Currently, this function always succeeds and returns 0.
|
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
int nghttp2_session_on_credential_received(nghttp2_session *session,
|
|
|
|
nghttp2_frame *frame);
|
2012-04-05 18:45:39 +02:00
|
|
|
|
2012-01-29 08:27:00 +01:00
|
|
|
/*
|
|
|
|
* Called when DATA is received.
|
2012-02-22 15:39:30 +01:00
|
|
|
*
|
|
|
|
* This function returns 0 if it succeeds, or one of the following
|
|
|
|
* negative error codes:
|
|
|
|
*
|
2013-07-12 17:19:03 +02:00
|
|
|
* NGHTTP2_ERR_NOMEM
|
2012-02-22 15:39:30 +01:00
|
|
|
* Out of memory.
|
2012-01-29 08:27:00 +01:00
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
int nghttp2_session_on_data_received(nghttp2_session *session,
|
2012-01-29 08:27:00 +01:00
|
|
|
uint8_t flags, int32_t length,
|
|
|
|
int32_t stream_id);
|
|
|
|
|
2012-01-25 17:04:01 +01:00
|
|
|
/*
|
2013-07-12 17:19:03 +02:00
|
|
|
* Returns nghttp2_stream* object whose stream ID is |stream_id|. It
|
2012-01-25 17:04:01 +01:00
|
|
|
* could be NULL if such stream does not exist.
|
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_stream* nghttp2_session_get_stream(nghttp2_session *session,
|
2012-01-25 17:04:01 +01:00
|
|
|
int32_t stream_id);
|
|
|
|
|
2012-01-26 17:17:40 +01:00
|
|
|
/*
|
2012-02-22 15:39:30 +01:00
|
|
|
* Packs DATA frame |frame| in wire frame format and stores it in
|
2012-02-16 12:54:30 +01:00
|
|
|
* |*buf_ptr|. The capacity of |*buf_ptr| is |*buflen_ptr|
|
|
|
|
* length. This function expands |*buf_ptr| as necessary to store
|
|
|
|
* given |frame|. It packs header in first 8 bytes. Remaining bytes
|
2012-02-22 15:58:33 +01:00
|
|
|
* are the DATA apyload and are filled using |frame->data_prd|. The
|
|
|
|
* length of payload is at most |datamax| bytes.
|
2012-02-22 15:39:30 +01:00
|
|
|
*
|
|
|
|
* This function returns the size of packed frame if it succeeds, or
|
|
|
|
* one of the following negative error codes:
|
|
|
|
*
|
2013-07-12 17:19:03 +02:00
|
|
|
* NGHTTP2_ERR_DEFERRED
|
2012-02-22 15:39:30 +01:00
|
|
|
* The DATA frame is postponed.
|
2013-07-12 17:19:03 +02:00
|
|
|
* NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE
|
2012-05-12 11:19:05 +02:00
|
|
|
* The read_callback failed (stream error).
|
2013-07-12 17:19:03 +02:00
|
|
|
* NGHTTP2_ERR_NOMEM
|
2012-05-12 11:19:05 +02:00
|
|
|
* Out of memory.
|
2013-07-12 17:19:03 +02:00
|
|
|
* NGHTTP2_ERR_CALLBACK_FAILURE
|
2012-05-12 11:19:05 +02:00
|
|
|
* The read_callback failed (session error).
|
2012-01-26 17:17:40 +01:00
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
ssize_t nghttp2_session_pack_data(nghttp2_session *session,
|
2012-02-16 12:54:30 +01:00
|
|
|
uint8_t **buf_ptr, size_t *buflen_ptr,
|
2012-02-22 15:58:33 +01:00
|
|
|
size_t datamax,
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_data *frame);
|
2012-01-26 17:17:40 +01:00
|
|
|
|
2012-01-27 15:05:29 +01:00
|
|
|
/*
|
|
|
|
* Returns next unique ID which can be used with PING.
|
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
uint32_t nghttp2_session_get_next_unique_id(nghttp2_session *session);
|
2012-01-27 15:05:29 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns top of outbound frame queue. This function returns NULL if
|
|
|
|
* queue is empty.
|
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_outbound_item* nghttp2_session_get_ob_pq_top(nghttp2_session *session);
|
2012-01-27 15:05:29 +01:00
|
|
|
|
2012-02-05 16:14:19 +01:00
|
|
|
/*
|
|
|
|
* Pops and returns next item to send. If there is no such item,
|
|
|
|
* returns NULL. This function takes into account max concurrent
|
|
|
|
* streams. That means if session->ob_pq is empty but
|
|
|
|
* session->ob_ss_pq has item and max concurrent streams is reached,
|
|
|
|
* then this function returns NULL.
|
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_outbound_item* nghttp2_session_pop_next_ob_item
|
|
|
|
(nghttp2_session *session);
|
2012-02-05 16:14:19 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns next item to send. If there is no such item, this function
|
|
|
|
* returns NULL. This function takes into account max concurrent
|
|
|
|
* streams. That means if session->ob_pq is empty but
|
|
|
|
* session->ob_ss_pq has item and max concurrent streams is reached,
|
|
|
|
* then this function returns NULL.
|
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_outbound_item* nghttp2_session_get_next_ob_item
|
|
|
|
(nghttp2_session *session);
|
2012-02-05 16:14:19 +01:00
|
|
|
|
2012-03-10 10:41:01 +01:00
|
|
|
/*
|
|
|
|
* Updates local settings with the |iv|. The number of elements in the
|
|
|
|
* array pointed by the |iv| is given by the |niv|. This function
|
|
|
|
* assumes that the all settings_id member in |iv| are in range 1 to
|
2013-07-12 17:19:03 +02:00
|
|
|
* NGHTTP2_SETTINGS_MAX, inclusive.
|
2012-03-10 10:41:01 +01:00
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
void nghttp2_session_update_local_settings(nghttp2_session *session,
|
|
|
|
nghttp2_settings_entry *iv,
|
2012-03-10 10:41:01 +01:00
|
|
|
size_t niv);
|
|
|
|
|
2012-04-05 18:45:39 +02:00
|
|
|
/*
|
|
|
|
* Returns the index in the client certificate vector for the
|
|
|
|
* |syn_stream|. The origin is computed from |syn_stream->nv|. If no
|
|
|
|
* client certificate is required, return 0. If CREDENTIAL frame needs
|
|
|
|
* to be sent before the |syn_stream|, this function returns
|
2013-07-12 17:19:03 +02:00
|
|
|
* :macro:`NGHTTP2_ERR_CREDENTIAL_PENDING`. In this case, CREDENTIAL
|
2012-04-05 18:45:39 +02:00
|
|
|
* frame has been already queued. This function returns one of the
|
|
|
|
* following negative error codes:
|
|
|
|
*
|
2013-07-12 17:19:03 +02:00
|
|
|
* NGHTTP2_ERR_NOMEM
|
2012-04-05 18:45:39 +02:00
|
|
|
* Out of memory.
|
2013-07-12 17:19:03 +02:00
|
|
|
* NGHTTP2_ERR_CREDENTIAL_PENDING
|
2012-04-05 18:45:39 +02:00
|
|
|
* The CREDENTIAL frame must be sent before the |syn_stream|.
|
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
int nghttp2_session_prep_credential(nghttp2_session *session,
|
|
|
|
nghttp2_syn_stream *syn_stream);
|
2012-04-05 18:45:39 +02:00
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
#endif /* NGHTTP2_SESSION_H */
|