Path: blob/master/Utilities/cmnghttp2/lib/nghttp2_session.h
3153 views
/*1* nghttp2 - HTTP/2 C Library2*3* Copyright (c) 2012 Tatsuhiro Tsujikawa4*5* Permission is hereby granted, free of charge, to any person obtaining6* a copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sublicense, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice shall be14* included in all copies or substantial portions of the Software.15*16* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,17* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF18* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND19* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE20* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION21* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION22* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.23*/24#ifndef NGHTTP2_SESSION_H25#define NGHTTP2_SESSION_H2627#ifdef HAVE_CONFIG_H28# include <config.h>29#endif /* HAVE_CONFIG_H */3031#include <nghttp2/nghttp2.h>32#include "nghttp2_map.h"33#include "nghttp2_frame.h"34#include "nghttp2_hd.h"35#include "nghttp2_stream.h"36#include "nghttp2_outbound_item.h"37#include "nghttp2_int.h"38#include "nghttp2_buf.h"39#include "nghttp2_callbacks.h"40#include "nghttp2_mem.h"4142/* The global variable for tests where we want to disable strict43preface handling. */44extern int nghttp2_enable_strict_preface;4546/*47* Option flags.48*/49typedef enum {50NGHTTP2_OPTMASK_NO_AUTO_WINDOW_UPDATE = 1 << 0,51NGHTTP2_OPTMASK_NO_RECV_CLIENT_MAGIC = 1 << 1,52NGHTTP2_OPTMASK_NO_HTTP_MESSAGING = 1 << 2,53NGHTTP2_OPTMASK_NO_AUTO_PING_ACK = 1 << 3,54NGHTTP2_OPTMASK_NO_CLOSED_STREAMS = 1 << 4,55NGHTTP2_OPTMASK_SERVER_FALLBACK_RFC7540_PRIORITIES = 1 << 5,56NGHTTP2_OPTMASK_NO_RFC9113_LEADING_AND_TRAILING_WS_VALIDATION = 1 << 6,57} nghttp2_optmask;5859/*60* bitmask for built-in type to enable the default handling for that61* type of the frame.62*/63typedef enum {64NGHTTP2_TYPEMASK_NONE = 0,65NGHTTP2_TYPEMASK_ALTSVC = 1 << 0,66NGHTTP2_TYPEMASK_ORIGIN = 1 << 1,67NGHTTP2_TYPEMASK_PRIORITY_UPDATE = 1 << 268} nghttp2_typemask;6970typedef enum {71NGHTTP2_OB_POP_ITEM,72NGHTTP2_OB_SEND_DATA,73NGHTTP2_OB_SEND_NO_COPY,74NGHTTP2_OB_SEND_CLIENT_MAGIC75} nghttp2_outbound_state;7677typedef struct {78nghttp2_outbound_item *item;79nghttp2_bufs framebufs;80nghttp2_outbound_state state;81} nghttp2_active_outbound_item;8283/* Buffer length for inbound raw byte stream used in84nghttp2_session_recv(). */85#define NGHTTP2_INBOUND_BUFFER_LENGTH 163848687/* The default maximum number of incoming reserved streams */88#define NGHTTP2_MAX_INCOMING_RESERVED_STREAMS 2008990/* Even if we have less SETTINGS_MAX_CONCURRENT_STREAMS than this91number, we keep NGHTTP2_MIN_IDLE_STREAMS streams in idle state */92#define NGHTTP2_MIN_IDLE_STREAMS 169394/* The maximum number of items in outbound queue, which is considered95as flooding caused by peer. All frames are not considered here.96We only consider PING + ACK and SETTINGS + ACK. This is because97they both are response to the frame initiated by peer and peer can98send as many of them as they want. If peer does not read network,99response frames are stacked up, which leads to memory exhaustion.100The value selected here is arbitrary, but safe value and if we have101these frames in this number, it is considered suspicious. */102#define NGHTTP2_DEFAULT_MAX_OBQ_FLOOD_ITEM 1000103104/* The default value of maximum number of concurrent streams. */105#define NGHTTP2_DEFAULT_MAX_CONCURRENT_STREAMS 0xffffffffu106107/* Internal state when receiving incoming frame */108typedef enum {109/* Receiving frame header */110NGHTTP2_IB_READ_CLIENT_MAGIC,111NGHTTP2_IB_READ_FIRST_SETTINGS,112NGHTTP2_IB_READ_HEAD,113NGHTTP2_IB_READ_NBYTE,114NGHTTP2_IB_READ_HEADER_BLOCK,115NGHTTP2_IB_IGN_HEADER_BLOCK,116NGHTTP2_IB_IGN_PAYLOAD,117NGHTTP2_IB_FRAME_SIZE_ERROR,118NGHTTP2_IB_READ_SETTINGS,119NGHTTP2_IB_READ_GOAWAY_DEBUG,120NGHTTP2_IB_EXPECT_CONTINUATION,121NGHTTP2_IB_IGN_CONTINUATION,122NGHTTP2_IB_READ_PAD_DATA,123NGHTTP2_IB_READ_DATA,124NGHTTP2_IB_IGN_DATA,125NGHTTP2_IB_IGN_ALL,126NGHTTP2_IB_READ_ALTSVC_PAYLOAD,127NGHTTP2_IB_READ_ORIGIN_PAYLOAD,128NGHTTP2_IB_READ_EXTENSION_PAYLOAD129} nghttp2_inbound_state;130131typedef struct {132nghttp2_frame frame;133/* Storage for extension frame payload. frame->ext.payload points134to this structure to avoid frequent memory allocation. */135nghttp2_ext_frame_payload ext_frame_payload;136/* The received SETTINGS entry. For the standard settings entries,137we only keep the last seen value. For138SETTINGS_HEADER_TABLE_SIZE, we also keep minimum value in the139last index. */140nghttp2_settings_entry *iv;141/* buffer pointers to small buffer, raw_sbuf */142nghttp2_buf sbuf;143/* buffer pointers to large buffer, raw_lbuf */144nghttp2_buf lbuf;145/* Large buffer, malloced on demand */146uint8_t *raw_lbuf;147/* The number of entry filled in |iv| */148size_t niv;149/* The number of entries |iv| can store. */150size_t max_niv;151/* How many bytes we still need to receive for current frame */152size_t payloadleft;153/* padding length for the current frame */154size_t padlen;155nghttp2_inbound_state state;156/* Small fixed sized buffer. */157uint8_t raw_sbuf[32];158} nghttp2_inbound_frame;159160typedef struct {161uint32_t header_table_size;162uint32_t enable_push;163uint32_t max_concurrent_streams;164uint32_t initial_window_size;165uint32_t max_frame_size;166uint32_t max_header_list_size;167uint32_t enable_connect_protocol;168uint32_t no_rfc7540_priorities;169} nghttp2_settings_storage;170171typedef enum {172NGHTTP2_GOAWAY_NONE = 0,173/* Flag means that connection should be terminated after sending GOAWAY. */174NGHTTP2_GOAWAY_TERM_ON_SEND = 0x1,175/* Flag means GOAWAY to terminate session has been sent */176NGHTTP2_GOAWAY_TERM_SENT = 0x2,177/* Flag means GOAWAY was sent */178NGHTTP2_GOAWAY_SENT = 0x4,179/* Flag means GOAWAY was received */180NGHTTP2_GOAWAY_RECV = 0x8181} nghttp2_goaway_flag;182183/* nghttp2_inflight_settings stores the SETTINGS entries which local184endpoint has sent to the remote endpoint, and has not received ACK185yet. */186struct nghttp2_inflight_settings {187struct nghttp2_inflight_settings *next;188nghttp2_settings_entry *iv;189size_t niv;190};191192typedef struct nghttp2_inflight_settings nghttp2_inflight_settings;193194struct nghttp2_session {195nghttp2_map /* <nghttp2_stream*> */ streams;196/* root of dependency tree*/197nghttp2_stream root;198/* Queue for outbound urgent frames (PING and SETTINGS) */199nghttp2_outbound_queue ob_urgent;200/* Queue for non-DATA frames */201nghttp2_outbound_queue ob_reg;202/* Queue for outbound stream-creating HEADERS (request or push203response) frame, which are subject to204SETTINGS_MAX_CONCURRENT_STREAMS limit. */205nghttp2_outbound_queue ob_syn;206/* Queues for DATA frames which is used when207SETTINGS_NO_RFC7540_PRIORITIES is enabled. This implements RFC2089218 extensible prioritization scheme. */209struct {210nghttp2_pq ob_data;211} sched[NGHTTP2_EXTPRI_URGENCY_LEVELS];212nghttp2_active_outbound_item aob;213nghttp2_inbound_frame iframe;214nghttp2_hd_deflater hd_deflater;215nghttp2_hd_inflater hd_inflater;216nghttp2_session_callbacks callbacks;217/* Memory allocator */218nghttp2_mem mem;219void *user_data;220/* Points to the latest incoming closed stream. NULL if there is no221closed stream. Only used when session is initialized as222server. */223nghttp2_stream *closed_stream_head;224/* Points to the oldest incoming closed stream. NULL if there is no225closed stream. Only used when session is initialized as226server. */227nghttp2_stream *closed_stream_tail;228/* Points to the latest idle stream. NULL if there is no idle229stream. Only used when session is initialized as server .*/230nghttp2_stream *idle_stream_head;231/* Points to the oldest idle stream. NULL if there is no idle232stream. Only used when session is initialized as erver. */233nghttp2_stream *idle_stream_tail;234/* Queue of In-flight SETTINGS values. SETTINGS bearing ACK is not235considered as in-flight. */236nghttp2_inflight_settings *inflight_settings_head;237/* Sequential number across all streams to process streams in238FIFO. */239uint64_t stream_seq;240/* The number of outgoing streams. This will be capped by241remote_settings.max_concurrent_streams. */242size_t num_outgoing_streams;243/* The number of incoming streams. This will be capped by244local_settings.max_concurrent_streams. */245size_t num_incoming_streams;246/* The number of incoming reserved streams. This is the number of247streams in reserved (remote) state. RFC 7540 does not limit this248number. nghttp2 offers249nghttp2_option_set_max_reserved_remote_streams() to achieve this.250If it is used, num_incoming_streams is capped by251max_incoming_reserved_streams. Client application should252consider to set this because without that server can send253arbitrary number of PUSH_PROMISE, and exhaust client's memory. */254size_t num_incoming_reserved_streams;255/* The maximum number of incoming reserved streams (reserved256(remote) state). RST_STREAM will be sent for the pushed stream257which exceeds this limit. */258size_t max_incoming_reserved_streams;259/* The number of closed streams still kept in |streams| hash. The260closed streams can be accessed through single linked list261|closed_stream_head|. The current implementation only keeps262incoming streams and session is initialized as server. */263size_t num_closed_streams;264/* The number of idle streams kept in |streams| hash. The idle265streams can be accessed through doubly linked list266|idle_stream_head|. The current implementation only keeps idle267streams if session is initialized as server. */268size_t num_idle_streams;269/* The number of bytes allocated for nvbuf */270size_t nvbuflen;271/* Counter for detecting flooding in outbound queue. If it exceeds272max_outbound_ack, session will be closed. */273size_t obq_flood_counter_;274/* The maximum number of outgoing SETTINGS ACK and PING ACK in275outbound queue. */276size_t max_outbound_ack;277/* The maximum length of header block to send. Calculated by the278same way as nghttp2_hd_deflate_bound() does. */279size_t max_send_header_block_length;280/* The maximum number of settings accepted per SETTINGS frame. */281size_t max_settings;282/* Next Stream ID. Made unsigned int to detect >= (1 << 31). */283uint32_t next_stream_id;284/* The last stream ID this session initiated. For client session,285this is the last stream ID it has sent. For server session, it286is the last promised stream ID sent in PUSH_PROMISE. */287int32_t last_sent_stream_id;288/* The largest stream ID received so far */289int32_t last_recv_stream_id;290/* The largest stream ID which has been processed in some way. This291value will be used as last-stream-id when sending GOAWAY292frame. */293int32_t last_proc_stream_id;294/* Counter of unique ID of PING. Wraps when it exceeds295NGHTTP2_MAX_UNIQUE_ID */296uint32_t next_unique_id;297/* This is the last-stream-ID we have sent in GOAWAY */298int32_t local_last_stream_id;299/* This is the value in GOAWAY frame received from remote endpoint. */300int32_t remote_last_stream_id;301/* Current sender window size. This value is computed against the302current initial window size of remote endpoint. */303int32_t remote_window_size;304/* Keep track of the number of bytes received without305WINDOW_UPDATE. This could be negative after submitting negative306value to WINDOW_UPDATE. */307int32_t recv_window_size;308/* The number of bytes consumed by the application and now is309subject to WINDOW_UPDATE. This is only used when auto310WINDOW_UPDATE is turned off. */311int32_t consumed_size;312/* The amount of recv_window_size cut using submitting negative313value to WINDOW_UPDATE */314int32_t recv_reduction;315/* window size for local flow control. It is initially set to316NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE and could be317increased/decreased by submitting WINDOW_UPDATE. See318nghttp2_submit_window_update(). */319int32_t local_window_size;320/* This flag is used to indicate that the local endpoint received initial321SETTINGS frame from the remote endpoint. */322uint8_t remote_settings_received;323/* Settings value received from the remote endpoint. */324nghttp2_settings_storage remote_settings;325/* Settings value of the local endpoint. */326nghttp2_settings_storage local_settings;327/* Option flags. This is bitwise-OR of 0 or more of nghttp2_optmask. */328uint32_t opt_flags;329/* Unacked local SETTINGS_MAX_CONCURRENT_STREAMS value. We use this330to refuse the incoming stream if it exceeds this value. */331uint32_t pending_local_max_concurrent_stream;332/* The bitwise OR of zero or more of nghttp2_typemask to indicate333that the default handling of extension frame is enabled. */334uint32_t builtin_recv_ext_types;335/* Unacked local ENABLE_PUSH value. We use this to refuse336PUSH_PROMISE before SETTINGS ACK is received. */337uint8_t pending_enable_push;338/* Unacked local ENABLE_CONNECT_PROTOCOL value. We use this to339accept :protocol header field before SETTINGS_ACK is received. */340uint8_t pending_enable_connect_protocol;341/* Unacked local SETTINGS_NO_RFC7540_PRIORITIES value, which is342effective before it is acknowledged. */343uint8_t pending_no_rfc7540_priorities;344/* Turn on fallback to RFC 7540 priorities; for server use only. */345uint8_t fallback_rfc7540_priorities;346/* Nonzero if the session is server side. */347uint8_t server;348/* Flags indicating GOAWAY is sent and/or received. The flags are349composed by bitwise OR-ing nghttp2_goaway_flag. */350uint8_t goaway_flags;351/* This flag is used to reduce excessive queuing of WINDOW_UPDATE to352this session. The nonzero does not necessarily mean353WINDOW_UPDATE is not queued. */354uint8_t window_update_queued;355/* Bitfield of extension frame types that application is willing to356receive. To designate the bit of given frame type i, use357user_recv_ext_types[i / 8] & (1 << (i & 0x7)). First 10 frame358types are standard frame types and not used in this bitfield. If359bit is set, it indicates that incoming frame with that type is360passed to user defined callbacks, otherwise they are ignored. */361uint8_t user_recv_ext_types[32];362};363364/* Struct used when updating initial window size of each active365stream. */366typedef struct {367nghttp2_session *session;368int32_t new_window_size, old_window_size;369} nghttp2_update_window_size_arg;370371typedef struct {372nghttp2_session *session;373/* linked list of streams to close */374nghttp2_stream *head;375int32_t last_stream_id;376/* nonzero if GOAWAY is sent to peer, which means we are going to377close incoming streams. zero if GOAWAY is received from peer and378we are going to close outgoing streams. */379int incoming;380} nghttp2_close_stream_on_goaway_arg;381382/* TODO stream timeout etc */383384/*385* Returns nonzero value if |stream_id| is initiated by local386* endpoint.387*/388int nghttp2_session_is_my_stream_id(nghttp2_session *session,389int32_t stream_id);390391/*392* Adds |item| to the outbound queue in |session|. When this function393* succeeds, it takes ownership of |item|. So caller must not free it394* on success.395*396* This function returns 0 if it succeeds, or one of the following397* negative error codes:398*399* NGHTTP2_ERR_NOMEM400* Out of memory.401* NGHTTP2_ERR_STREAM_CLOSED402* Stream already closed (DATA and PUSH_PROMISE frame only)403*/404int nghttp2_session_add_item(nghttp2_session *session,405nghttp2_outbound_item *item);406407/*408* Adds RST_STREAM frame for the stream |stream_id| with the error409* code |error_code|. This is a convenient function built on top of410* nghttp2_session_add_frame() to add RST_STREAM easily.411*412* This function simply returns 0 without adding RST_STREAM frame if413* given stream is in NGHTTP2_STREAM_CLOSING state, because multiple414* RST_STREAM for a stream is redundant.415*416* This function returns 0 if it succeeds, or one of the following417* negative error codes:418*419* NGHTTP2_ERR_NOMEM420* Out of memory.421*/422int nghttp2_session_add_rst_stream(nghttp2_session *session, int32_t stream_id,423uint32_t error_code);424425/*426* Adds PING frame. This is a convenient function built on top of427* nghttp2_session_add_frame() to add PING easily.428*429* If the |opaque_data| is not NULL, it must point to 8 bytes memory430* region of data. The data pointed by |opaque_data| is copied. It can431* be NULL. In this case, 8 bytes NULL is used.432*433* This function returns 0 if it succeeds, or one of the following434* negative error codes:435*436* NGHTTP2_ERR_NOMEM437* Out of memory.438* NGHTTP2_ERR_FLOODED439* There are too many items in outbound queue; this only happens440* if NGHTTP2_FLAG_ACK is set in |flags|441*/442int nghttp2_session_add_ping(nghttp2_session *session, uint8_t flags,443const uint8_t *opaque_data);444445/*446* Adds GOAWAY frame with the last-stream-ID |last_stream_id| and the447* error code |error_code|. This is a convenient function built on top448* of nghttp2_session_add_frame() to add GOAWAY easily. The449* |aux_flags| are bitwise-OR of one or more of450* nghttp2_goaway_aux_flag.451*452* This function returns 0 if it succeeds, or one of the following453* negative error codes:454*455* NGHTTP2_ERR_NOMEM456* Out of memory.457* NGHTTP2_ERR_INVALID_ARGUMENT458* The |opaque_data_len| is too large.459*/460int nghttp2_session_add_goaway(nghttp2_session *session, int32_t last_stream_id,461uint32_t error_code, const uint8_t *opaque_data,462size_t opaque_data_len, uint8_t aux_flags);463464/*465* Adds WINDOW_UPDATE frame with stream ID |stream_id| and466* window-size-increment |window_size_increment|. This is a convenient467* function built on top of nghttp2_session_add_frame() to add468* WINDOW_UPDATE easily.469*470* This function returns 0 if it succeeds, or one of the following471* negative error codes:472*473* NGHTTP2_ERR_NOMEM474* Out of memory.475*/476int nghttp2_session_add_window_update(nghttp2_session *session, uint8_t flags,477int32_t stream_id,478int32_t window_size_increment);479480/*481* Adds SETTINGS frame.482*483* This function returns 0 if it succeeds, or one of the following484* negative error codes:485*486* NGHTTP2_ERR_NOMEM487* Out of memory.488* NGHTTP2_ERR_FLOODED489* There are too many items in outbound queue; this only happens490* if NGHTTP2_FLAG_ACK is set in |flags|491*/492int nghttp2_session_add_settings(nghttp2_session *session, uint8_t flags,493const nghttp2_settings_entry *iv, size_t niv);494495/*496* Creates new stream in |session| with stream ID |stream_id|,497* priority |pri_spec| and flags |flags|. The |flags| is bitwise OR498* of nghttp2_stream_flag. Since this function is called when initial499* HEADERS is sent or received, these flags are taken from it. The500* state of stream is set to |initial_state|. The |stream_user_data|501* is a pointer to the arbitrary user supplied data to be associated502* to this stream.503*504* If |initial_state| is NGHTTP2_STREAM_RESERVED, this function sets505* NGHTTP2_STREAM_FLAG_PUSH flag set.506*507* This function returns a pointer to created new stream object, or508* NULL.509*510* This function adjusts neither the number of closed streams or idle511* streams. The caller should manually call512* nghttp2_session_adjust_closed_stream() or513* nghttp2_session_adjust_idle_stream() respectively.514*/515nghttp2_stream *nghttp2_session_open_stream(nghttp2_session *session,516int32_t stream_id, uint8_t flags,517nghttp2_priority_spec *pri_spec,518nghttp2_stream_state initial_state,519void *stream_user_data);520521/*522* Closes stream whose stream ID is |stream_id|. The reason of closure523* is indicated by the |error_code|. When closing the stream,524* on_stream_close_callback will be called.525*526* If the session is initialized as server and |stream| is incoming527* stream, stream is just marked closed and this function calls528* nghttp2_session_keep_closed_stream() with |stream|. Otherwise,529* |stream| will be deleted from memory.530*531* This function returns 0 if it succeeds, or one the following532* negative error codes:533*534* NGHTTP2_ERR_NOMEM535* Out of memory536* NGHTTP2_ERR_INVALID_ARGUMENT537* The specified stream does not exist.538* NGHTTP2_ERR_CALLBACK_FAILURE539* The callback function failed.540*/541int nghttp2_session_close_stream(nghttp2_session *session, int32_t stream_id,542uint32_t error_code);543544/*545* Deletes |stream| from memory. After this function returns, stream546* cannot be accessed.547*548* This function returns 0 if it succeeds, or one the following549* negative error codes:550*551* NGHTTP2_ERR_NOMEM552* Out of memory553*/554int nghttp2_session_destroy_stream(nghttp2_session *session,555nghttp2_stream *stream);556557/*558* Tries to keep incoming closed stream |stream|. Due to the559* limitation of maximum number of streams in memory, |stream| is not560* closed and just deleted from memory (see561* nghttp2_session_destroy_stream).562*/563void nghttp2_session_keep_closed_stream(nghttp2_session *session,564nghttp2_stream *stream);565566/*567* Appends |stream| to linked list |session->idle_stream_head|. We568* apply fixed limit for list size. To fit into that limit, one or569* more oldest streams are removed from list as necessary.570*/571void nghttp2_session_keep_idle_stream(nghttp2_session *session,572nghttp2_stream *stream);573574/*575* Detaches |stream| from idle streams linked list.576*/577void nghttp2_session_detach_idle_stream(nghttp2_session *session,578nghttp2_stream *stream);579580/*581* Deletes closed stream to ensure that number of incoming streams582* including active and closed is in the maximum number of allowed583* stream.584*585* This function returns 0 if it succeeds, or one the following586* negative error codes:587*588* NGHTTP2_ERR_NOMEM589* Out of memory590*/591int nghttp2_session_adjust_closed_stream(nghttp2_session *session);592593/*594* Deletes idle stream to ensure that number of idle streams is in595* certain limit.596*597* This function returns 0 if it succeeds, or one the following598* negative error codes:599*600* NGHTTP2_ERR_NOMEM601* Out of memory602*/603int nghttp2_session_adjust_idle_stream(nghttp2_session *session);604605/*606* If further receptions and transmissions over the stream |stream_id|607* are disallowed, close the stream with error code NGHTTP2_NO_ERROR.608*609* This function returns 0 if it610* succeeds, or one of the following negative error codes:611*612* NGHTTP2_ERR_INVALID_ARGUMENT613* The specified stream does not exist.614*/615int nghttp2_session_close_stream_if_shut_rdwr(nghttp2_session *session,616nghttp2_stream *stream);617618int nghttp2_session_on_request_headers_received(nghttp2_session *session,619nghttp2_frame *frame);620621int nghttp2_session_on_response_headers_received(nghttp2_session *session,622nghttp2_frame *frame,623nghttp2_stream *stream);624625int nghttp2_session_on_push_response_headers_received(nghttp2_session *session,626nghttp2_frame *frame,627nghttp2_stream *stream);628629/*630* Called when HEADERS is received, assuming |frame| is properly631* initialized. This function does first validate received frame and632* then open stream and call callback functions.633*634* This function returns 0 if it succeeds, or one of the following635* negative error codes:636*637* NGHTTP2_ERR_NOMEM638* Out of memory.639* NGHTTP2_ERR_IGN_HEADER_BLOCK640* Frame was rejected and header block must be decoded but641* result must be ignored.642* NGHTTP2_ERR_CALLBACK_FAILURE643* The read_callback failed644*/645int nghttp2_session_on_headers_received(nghttp2_session *session,646nghttp2_frame *frame,647nghttp2_stream *stream);648649/*650* Called when PRIORITY is received, assuming |frame| is properly651* initialized.652*653* This function returns 0 if it succeeds, or one of the following654* negative error codes:655*656* NGHTTP2_ERR_NOMEM657* Out of memory.658* NGHTTP2_ERR_CALLBACK_FAILURE659* The read_callback failed660*/661int nghttp2_session_on_priority_received(nghttp2_session *session,662nghttp2_frame *frame);663664/*665* Called when RST_STREAM is received, assuming |frame| is properly666* initialized.667*668* This function returns 0 if it succeeds, or one the following669* negative error codes:670*671* NGHTTP2_ERR_NOMEM672* Out of memory673* NGHTTP2_ERR_CALLBACK_FAILURE674* The read_callback failed675*/676int nghttp2_session_on_rst_stream_received(nghttp2_session *session,677nghttp2_frame *frame);678679/*680* Called when SETTINGS is received, assuming |frame| is properly681* initialized. If |noack| is non-zero, SETTINGS with ACK will not be682* submitted. If |frame| has NGHTTP2_FLAG_ACK flag set, no SETTINGS683* with ACK will not be submitted regardless of |noack|.684*685* This function returns 0 if it succeeds, or one the following686* negative error codes:687*688* NGHTTP2_ERR_NOMEM689* Out of memory690* NGHTTP2_ERR_CALLBACK_FAILURE691* The read_callback failed692* NGHTTP2_ERR_FLOODED693* There are too many items in outbound queue, and this is most694* likely caused by misbehaviour of peer.695*/696int nghttp2_session_on_settings_received(nghttp2_session *session,697nghttp2_frame *frame, int noack);698699/*700* Called when PUSH_PROMISE is received, assuming |frame| is properly701* initialized.702*703* This function returns 0 if it succeeds, or one of the following704* negative error codes:705*706* NGHTTP2_ERR_NOMEM707* Out of memory.708* NGHTTP2_ERR_IGN_HEADER_BLOCK709* Frame was rejected and header block must be decoded but710* result must be ignored.711* NGHTTP2_ERR_CALLBACK_FAILURE712* The read_callback failed713*/714int nghttp2_session_on_push_promise_received(nghttp2_session *session,715nghttp2_frame *frame);716717/*718* Called when PING is received, assuming |frame| is properly719* initialized.720*721* This function returns 0 if it succeeds, or one of the following722* negative error codes:723*724* NGHTTP2_ERR_NOMEM725* Out of memory.726* NGHTTP2_ERR_CALLBACK_FAILURE727* The callback function failed.728* NGHTTP2_ERR_FLOODED729* There are too many items in outbound queue, and this is most730* likely caused by misbehaviour of peer.731*/732int nghttp2_session_on_ping_received(nghttp2_session *session,733nghttp2_frame *frame);734735/*736* Called when GOAWAY is received, assuming |frame| is properly737* initialized.738*739* This function returns 0 if it succeeds, or one of the following740* negative error codes:741*742* NGHTTP2_ERR_NOMEM743* Out of memory.744* NGHTTP2_ERR_CALLBACK_FAILURE745* The callback function failed.746*/747int nghttp2_session_on_goaway_received(nghttp2_session *session,748nghttp2_frame *frame);749750/*751* Called when WINDOW_UPDATE is received, assuming |frame| is properly752* initialized.753*754* This function returns 0 if it succeeds, or one of the following755* negative error codes:756*757* NGHTTP2_ERR_NOMEM758* Out of memory.759* NGHTTP2_ERR_CALLBACK_FAILURE760* The callback function failed.761*/762int nghttp2_session_on_window_update_received(nghttp2_session *session,763nghttp2_frame *frame);764765/*766* Called when ALTSVC is received, assuming |frame| is properly767* initialized.768*769* This function returns 0 if it succeeds, or one of the following770* negative error codes:771*772* NGHTTP2_ERR_CALLBACK_FAILURE773* The callback function failed.774*/775int nghttp2_session_on_altsvc_received(nghttp2_session *session,776nghttp2_frame *frame);777778/*779* Called when ORIGIN is received, assuming |frame| is properly780* initialized.781*782* This function returns 0 if it succeeds, or one of the following783* negative error codes:784*785* NGHTTP2_ERR_CALLBACK_FAILURE786* The callback function failed.787*/788int nghttp2_session_on_origin_received(nghttp2_session *session,789nghttp2_frame *frame);790791/*792* Called when PRIORITY_UPDATE is received, assuming |frame| is793* properly initialized.794*795* This function returns 0 if it succeeds, or one of the following796* negative error codes:797*798* NGHTTP2_ERR_CALLBACK_FAILURE799* The callback function failed.800*/801int nghttp2_session_on_priority_update_received(nghttp2_session *session,802nghttp2_frame *frame);803804/*805* Called when DATA is received, assuming |frame| is properly806* initialized.807*808* This function returns 0 if it succeeds, or one of the following809* negative error codes:810*811* NGHTTP2_ERR_NOMEM812* Out of memory.813* NGHTTP2_ERR_CALLBACK_FAILURE814* The callback function failed.815*/816int nghttp2_session_on_data_received(nghttp2_session *session,817nghttp2_frame *frame);818819/*820* Returns nghttp2_stream* object whose stream ID is |stream_id|. It821* could be NULL if such stream does not exist. This function returns822* NULL if stream is marked as closed.823*/824nghttp2_stream *nghttp2_session_get_stream(nghttp2_session *session,825int32_t stream_id);826827/*828* This function behaves like nghttp2_session_get_stream(), but it829* returns stream object even if it is marked as closed or in830* NGHTTP2_STREAM_IDLE state.831*/832nghttp2_stream *nghttp2_session_get_stream_raw(nghttp2_session *session,833int32_t stream_id);834835/*836* Packs DATA frame |frame| in wire frame format and stores it in837* |bufs|. Payload will be read using |aux_data->data_prd|. The838* length of payload is at most |datamax| bytes.839*840* This function returns 0 if it succeeds, or one of the following841* negative error codes:842*843* NGHTTP2_ERR_DEFERRED844* The DATA frame is postponed.845* NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE846* The read_callback failed (stream error).847* NGHTTP2_ERR_NOMEM848* Out of memory.849* NGHTTP2_ERR_CALLBACK_FAILURE850* The read_callback failed (session error).851*/852int nghttp2_session_pack_data(nghttp2_session *session, nghttp2_bufs *bufs,853size_t datamax, nghttp2_frame *frame,854nghttp2_data_aux_data *aux_data,855nghttp2_stream *stream);856857/*858* Pops and returns next item to send. If there is no such item,859* returns NULL. This function takes into account max concurrent860* streams. That means if session->ob_syn has item and max concurrent861* streams is reached, the even if other queues contain items, then862* this function returns NULL.863*/864nghttp2_outbound_item *865nghttp2_session_pop_next_ob_item(nghttp2_session *session);866867/*868* Returns next item to send. If there is no such item, this function869* returns NULL. This function takes into account max concurrent870* streams. That means if session->ob_syn has item and max concurrent871* streams is reached, the even if other queues contain items, then872* this function returns NULL.873*/874nghttp2_outbound_item *875nghttp2_session_get_next_ob_item(nghttp2_session *session);876877/*878* Updates local settings with the |iv|. The number of elements in the879* array pointed by the |iv| is given by the |niv|. This function880* assumes that the all settings_id member in |iv| are in range 1 to881* NGHTTP2_SETTINGS_MAX, inclusive.882*883* While updating individual stream's local window size, if the window884* size becomes strictly larger than NGHTTP2_MAX_WINDOW_SIZE,885* RST_STREAM is issued against such a stream.886*887* This function returns 0 if it succeeds, or one of the following888* negative error codes:889*890* NGHTTP2_ERR_NOMEM891* Out of memory892*/893int nghttp2_session_update_local_settings(nghttp2_session *session,894nghttp2_settings_entry *iv,895size_t niv);896897/*898* Re-prioritize |stream|. The new priority specification is899* |pri_spec|. Caller must ensure that stream->hd.stream_id !=900* pri_spec->stream_id.901*902* This function does not adjust the number of idle streams. The903* caller should call nghttp2_session_adjust_idle_stream() later.904*905* This function returns 0 if it succeeds, or one of the following906* negative error codes:907*908* NGHTTP2_ERR_NOMEM909* Out of memory910*/911int nghttp2_session_reprioritize_stream(nghttp2_session *session,912nghttp2_stream *stream,913const nghttp2_priority_spec *pri_spec);914915/*916* Terminates current |session| with the |error_code|. The |reason|917* is NULL-terminated debug string.918*919* This function returns 0 if it succeeds, or one of the following920* negative error codes:921*922* NGHTTP2_ERR_NOMEM923* Out of memory.924* NGHTTP2_ERR_INVALID_ARGUMENT925* The |reason| is too long.926*/927int nghttp2_session_terminate_session_with_reason(nghttp2_session *session,928uint32_t error_code,929const char *reason);930931/*932* Accumulates received bytes |delta_size| for connection-level flow933* control and decides whether to send WINDOW_UPDATE to the934* connection. If NGHTTP2_OPT_NO_AUTO_WINDOW_UPDATE is set,935* WINDOW_UPDATE will not be sent.936*937* This function returns 0 if it succeeds, or one of the following938* negative error codes:939*940* NGHTTP2_ERR_NOMEM941* Out of memory.942*/943int nghttp2_session_update_recv_connection_window_size(nghttp2_session *session,944size_t delta_size);945946/*947* Accumulates received bytes |delta_size| for stream-level flow948* control and decides whether to send WINDOW_UPDATE to that stream.949* If NGHTTP2_OPT_NO_AUTO_WINDOW_UPDATE is set, WINDOW_UPDATE will not950* be sent.951*952* This function returns 0 if it succeeds, or one of the following953* negative error codes:954*955* NGHTTP2_ERR_NOMEM956* Out of memory.957*/958int nghttp2_session_update_recv_stream_window_size(nghttp2_session *session,959nghttp2_stream *stream,960size_t delta_size,961int send_window_update);962963#endif /* NGHTTP2_SESSION_H */964965966