Apache HTTPD
Classes | Macros | Functions | Variables
h2_stream.c File Reference
#include <assert.h>
#include <stddef.h>
#include "apr.h"
#include "apr_strings.h"
#include "apr_lib.h"
#include "apr_strmatch.h"
#include <httpd.h>
#include <http_core.h>
#include <http_connection.h>
#include <http_log.h>
#include <http_protocol.h>
#include <http_ssl.h>
#include <nghttp2/nghttp2.h>
#include "h2_private.h"
#include "h2.h"
#include "h2_bucket_beam.h"
#include "h2_c1.h"
#include "h2_config.h"
#include "h2_protocol.h"
#include "h2_mplx.h"
#include "h2_push.h"
#include "h2_request.h"
#include "h2_headers.h"
#include "h2_session.h"
#include "h2_stream.h"
#include "h2_c2.h"
#include "h2_conn_ctx.h"
#include "h2_util.h"

Go to the source code of this file.

Classes

struct  val_len_check_ctx
 

Macros

#define S_XXX   (-2) /* Programming Error */
 
#define S_ERR   (-1) /* Protocol Error */
 
#define S_NOP   (0) /* No Change */
 
#define S_IDL   (H2_SS_IDL + 1)
 
#define S_RS_L   (H2_SS_RSVD_L + 1)
 
#define S_RS_R   (H2_SS_RSVD_R + 1)
 
#define S_OPEN   (H2_SS_OPEN + 1)
 
#define S_CL_L   (H2_SS_CLOSED_L + 1)
 
#define S_CL_R   (H2_SS_CLOSED_R + 1)
 
#define S_CLS   (H2_SS_CLOSED + 1)
 
#define S_CLN   (H2_SS_CLEANUP + 1)
 

Functions

static const charh2_ss_str (const h2_stream_state_t state)
 
const charh2_stream_state_str (const h2_stream *stream)
 
static int on_map (h2_stream_state_t state, int map[H2_SS_MAX])
 
static int on_frame (h2_stream_state_t state, int frame_type, int frame_map[][H2_SS_MAX], apr_size_t maxlen)
 
static int on_frame_send (h2_stream_state_t state, int frame_type)
 
static int on_frame_recv (h2_stream_state_t state, int frame_type)
 
static int on_event (h2_stream *stream, h2_stream_event_t ev)
 
static ssize_t stream_data_cb (nghttp2_session *ng2s, int32_t stream_id, uint8_t *buf, size_t length, uint32_t *data_flags, nghttp2_data_source *source, void *puser)
 
static void H2_STREAM_OUT_LOG (int lvl, h2_stream *s, const char *tag)
 
static void stream_setup_input (h2_stream *stream)
 
apr_status_t h2_stream_prepare_processing (h2_stream *stream)
 
static int input_buffer_is_empty (h2_stream *stream)
 
static apr_status_t input_flush (h2_stream *stream)
 
static void input_append_bucket (h2_stream *stream, apr_bucket *b)
 
static void input_append_data (h2_stream *stream, const char *data, apr_size_t len)
 
static apr_status_t close_input (h2_stream *stream)
 
static void on_state_enter (h2_stream *stream)
 
static void on_state_event (h2_stream *stream, h2_stream_event_t ev)
 
static void on_state_invalid (h2_stream *stream)
 
static apr_status_t transit (h2_stream *stream, int new_state)
 
void h2_stream_set_monitor (h2_stream *stream, h2_stream_monitor *monitor)
 
void h2_stream_dispatch (h2_stream *stream, h2_stream_event_t ev)
 
static void set_policy_for (h2_stream *stream, h2_request *r)
 
apr_status_t h2_stream_send_frame (h2_stream *stream, int ftype, int flags, size_t frame_len)
 
apr_status_t h2_stream_recv_frame (h2_stream *stream, int ftype, int flags, size_t frame_len)
 
apr_status_t h2_stream_recv_DATA (h2_stream *stream, uint8_t flags, const uint8_t *data, size_t len)
 
h2_streamh2_stream_create (int id, apr_pool_t *pool, h2_session *session, h2_stream_monitor *monitor, int initiated_on)
 
void h2_stream_cleanup (h2_stream *stream)
 
void h2_stream_destroy (h2_stream *stream)
 
void h2_stream_rst (h2_stream *stream, int error_code)
 
apr_status_t h2_stream_set_request_rec (h2_stream *stream, request_rec *r, int eos)
 
void h2_stream_set_request (h2_stream *stream, const h2_request *r)
 
static void set_error_response (h2_stream *stream, int http_status)
 
static apr_status_t add_trailer (h2_stream *stream, const char *name, size_t nlen, const char *value, size_t vlen, size_t max_field_len, int *pwas_added)
 
apr_status_t h2_stream_add_header (h2_stream *stream, const char *name, size_t nlen, const char *value, size_t vlen)
 
static int table_check_val_len (void *baton, const char *key, const char *value)
 
apr_status_t h2_stream_end_headers (h2_stream *stream, int eos, size_t raw_bytes)
 
static apr_bucketget_first_response_bucket (apr_bucket_brigade *bb)
 
static void stream_do_error_bucket (h2_stream *stream, apr_bucket *b)
 
static apr_status_t buffer_output_receive (h2_stream *stream)
 
static int bucket_pass_to_c1 (apr_bucket *b)
 
apr_status_t h2_stream_read_to (h2_stream *stream, apr_bucket_brigade *bb, apr_off_t *plen, int *peos)
 
static apr_status_t stream_do_trailers (h2_stream *stream)
 
apr_status_t h2_stream_submit_pushes (h2_stream *stream, h2_headers *response)
 
apr_table_th2_stream_get_trailers (h2_stream *stream)
 
const h2_priorityh2_stream_get_priority (h2_stream *stream, h2_headers *response)
 
int h2_stream_is_ready (h2_stream *stream)
 
int h2_stream_wants_send_data (h2_stream *stream)
 
int h2_stream_is_at (const h2_stream *stream, h2_stream_state_t state)
 
int h2_stream_is_at_or_past (const h2_stream *stream, h2_stream_state_t state)
 
apr_status_t h2_stream_in_consumed (h2_stream *stream, apr_off_t amount)
 
static apr_off_t output_data_buffered (h2_stream *stream, int *peos, int *pheader_blocked)
 
static apr_status_t stream_do_response (h2_stream *stream)
 
static void stream_do_responses (h2_stream *stream)
 
void h2_stream_on_output_change (h2_stream *stream)
 
void h2_stream_on_input_change (h2_stream *stream)
 

Variables

static int trans_on_send [][H2_SS_MAX]
 
static int trans_on_recv [][H2_SS_MAX]
 
static int trans_on_event [][H2_SS_MAX]
 

Macro Definition Documentation

◆ S_CL_L

#define S_CL_L   (H2_SS_CLOSED_L + 1)

Definition at line 89 of file h2_stream.c.

◆ S_CL_R

#define S_CL_R   (H2_SS_CLOSED_R + 1)

Definition at line 90 of file h2_stream.c.

◆ S_CLN

#define S_CLN   (H2_SS_CLEANUP + 1)

Definition at line 92 of file h2_stream.c.

◆ S_CLS

#define S_CLS   (H2_SS_CLOSED + 1)

Definition at line 91 of file h2_stream.c.

◆ S_ERR

#define S_ERR   (-1) /* Protocol Error */

Definition at line 83 of file h2_stream.c.

◆ S_IDL

#define S_IDL   (H2_SS_IDL + 1)

Definition at line 85 of file h2_stream.c.

◆ S_NOP

#define S_NOP   (0) /* No Change */

Definition at line 84 of file h2_stream.c.

◆ S_OPEN

#define S_OPEN   (H2_SS_OPEN + 1)

Definition at line 88 of file h2_stream.c.

◆ S_RS_L

#define S_RS_L   (H2_SS_RSVD_L + 1)

Definition at line 86 of file h2_stream.c.

◆ S_RS_R

#define S_RS_R   (H2_SS_RSVD_R + 1)

Definition at line 87 of file h2_stream.c.

◆ S_XXX

#define S_XXX   (-2) /* Programming Error */

Definition at line 82 of file h2_stream.c.

Function Documentation

◆ add_trailer()

static apr_status_t add_trailer ( h2_stream stream,
const char name,
size_t  nlen,
const char value,
size_t  vlen,
size_t  max_field_len,
int pwas_added 
)
static

Definition at line 691 of file h2_stream.c.

◆ bucket_pass_to_c1()

static int bucket_pass_to_c1 ( apr_bucket b)
static

Definition at line 1101 of file h2_stream.c.

◆ buffer_output_receive()

static apr_status_t buffer_output_receive ( h2_stream stream)
static

Definition at line 1015 of file h2_stream.c.

◆ close_input()

static apr_status_t close_input ( h2_stream stream)
static

Definition at line 268 of file h2_stream.c.

◆ get_first_response_bucket()

static apr_bucket * get_first_response_bucket ( apr_bucket_brigade bb)
static

Definition at line 978 of file h2_stream.c.

◆ h2_ss_str()

static const char * h2_ss_str ( const h2_stream_state_t  state)
static

Definition at line 52 of file h2_stream.c.

◆ h2_stream_add_header()

apr_status_t h2_stream_add_header ( h2_stream stream,
const char name,
size_t  nlen,
const char value,
size_t  vlen 
)

Definition at line 730 of file h2_stream.c.

◆ h2_stream_cleanup()

void h2_stream_cleanup ( h2_stream stream)

Cleanup references into requst processing.

Parameters
streamthe stream to cleanup

Definition at line 615 of file h2_stream.c.

◆ h2_stream_create()

h2_stream * h2_stream_create ( int  id,
apr_pool_t pool,
struct h2_session session,
h2_stream_monitor monitor,
int  initiated_on 
)

Create a stream in H2_SS_IDLE state.

Parameters
idthe stream identifier
poolthe memory pool to use for this stream
sessionthe session this stream belongs to
monitoran optional monitor to be called for events and state transisitions
initiated_onthe id of the stream this one was initiated on (PUSH)
Returns
the newly opened stream

Definition at line 582 of file h2_stream.c.

◆ h2_stream_destroy()

void h2_stream_destroy ( h2_stream stream)

Destroy memory pool if still owned by the stream.

Definition at line 628 of file h2_stream.c.

◆ h2_stream_dispatch()

void h2_stream_dispatch ( h2_stream stream,
h2_stream_event_t  ev 
)

Dispatch (handle) an event on the given stream.

Parameters
streamthe streama the event happened on
evthe type of event

Definition at line 392 of file h2_stream.c.

◆ h2_stream_end_headers()

apr_status_t h2_stream_end_headers ( h2_stream stream,
int  eos,
size_t  raw_bytes 
)

Definition at line 842 of file h2_stream.c.

◆ h2_stream_get_priority()

const h2_priority * h2_stream_get_priority ( h2_stream stream,
struct h2_headers response 
)

Get priority information set for this stream.

Definition at line 1240 of file h2_stream.c.

◆ h2_stream_get_trailers()

apr_table_t * h2_stream_get_trailers ( h2_stream stream)

Get optional trailers for this stream, may be NULL. Meaningful results can only be expected when the end of the response body has been reached.

Parameters
streamto ask for trailers
Returns
trailers for NULL

Definition at line 1230 of file h2_stream.c.

◆ h2_stream_in_consumed()

apr_status_t h2_stream_in_consumed ( h2_stream stream,
apr_off_t  amount 
)

Notify the stream that amount bytes have been consumed of its input since the last invocation of this method (delta amount).

Definition at line 1303 of file h2_stream.c.

◆ h2_stream_is_at()

int h2_stream_is_at ( const h2_stream stream,
h2_stream_state_t  state 
)

Determine if stream is at given state.

Parameters
streamthe stream to check
statethe state to look for
Returns
!= 0 iff stream is at given state.

Definition at line 1276 of file h2_stream.c.

◆ h2_stream_is_at_or_past()

int h2_stream_is_at_or_past ( const h2_stream stream,
h2_stream_state_t  state 
)

Determine if stream is reached given state or is past this state.

Parameters
streamthe stream to check
statethe state to look for
Returns
!= 0 iff stream is at or past given state.

Definition at line 1282 of file h2_stream.c.

◆ h2_stream_is_ready()

int h2_stream_is_ready ( h2_stream stream)

Determine if stream is ready for submitting a response or a RST

Parameters
streamthe stream to check

Definition at line 1255 of file h2_stream.c.

◆ h2_stream_on_input_change()

void h2_stream_on_input_change ( h2_stream stream)

Stream input signals change. Take necessary actions.

Parameters
streamthe stream to read output for

Definition at line 1817 of file h2_stream.c.

◆ h2_stream_on_output_change()

void h2_stream_on_output_change ( h2_stream stream)

Stream output signals change. Take necessary actions.

Parameters
streamthe stream to read output for

Definition at line 1763 of file h2_stream.c.

◆ H2_STREAM_OUT_LOG()

static void H2_STREAM_OUT_LOG ( int  lvl,
h2_stream s,
const char tag 
)
static

Definition at line 187 of file h2_stream.c.

◆ h2_stream_prepare_processing()

apr_status_t h2_stream_prepare_processing ( h2_stream stream)

Perform any late initialization before stream starts processing.

Definition at line 211 of file h2_stream.c.

◆ h2_stream_read_to()

apr_status_t h2_stream_read_to ( h2_stream stream,
apr_bucket_brigade bb,
apr_off_t plen,
int peos 
)

Read a maximum number of bytes into the bucket brigade.

Parameters
streamthe stream to read from
bbthe brigade to append output to
plen(in-/out) max. number of bytes to append and on return actual number of bytes appended to brigade
peos(out) != 0 iff end of stream has been reached while reading
Returns
APR_SUCCESS if out information was computed successfully. APR_EAGAIN if not data is available and end of stream has not been reached yet.

Definition at line 1112 of file h2_stream.c.

◆ h2_stream_recv_DATA()

apr_status_t h2_stream_recv_DATA ( h2_stream stream,
uint8_t  flags,
const uint8_t data,
size_t  len 
)

Definition at line 529 of file h2_stream.c.

◆ h2_stream_recv_frame()

apr_status_t h2_stream_recv_frame ( h2_stream stream,
int  ftype,
int  flags,
size_t  frame_len 
)

Definition at line 475 of file h2_stream.c.

◆ h2_stream_rst()

void h2_stream_rst ( h2_stream stream,
int  error_code 
)

Reset the stream. Stream write/reads will return errors afterwards.

Parameters
streamthe stream to reset
error_codethe HTTP/2 error code

Definition at line 638 of file h2_stream.c.

◆ h2_stream_send_frame()

apr_status_t h2_stream_send_frame ( h2_stream stream,
int  ftype,
int  flags,
size_t  frame_len 
)

Definition at line 425 of file h2_stream.c.

◆ h2_stream_set_monitor()

void h2_stream_set_monitor ( h2_stream stream,
h2_stream_monitor monitor 
)

Definition at line 387 of file h2_stream.c.

◆ h2_stream_set_request()

void h2_stream_set_request ( h2_stream stream,
const h2_request r 
)

Set complete stream headers from given h2_request.

Parameters
streamstream to write request to
rthe request with all the meta data
eos!= 0 iff stream input is closed

Definition at line 676 of file h2_stream.c.

◆ h2_stream_set_request_rec()

apr_status_t h2_stream_set_request_rec ( h2_stream stream,
request_rec r,
int  eos 
)

Set complete stream header from given request_rec.

Parameters
streamstream to write request to
rthe request with all the meta data
eos!= 0 iff stream input is closed

Definition at line 650 of file h2_stream.c.

◆ h2_stream_state_str()

const char * h2_stream_state_str ( const h2_stream stream)

Return a textual representation of the stream state as in RFC 7540 nomenclator, all caps, underscores.

Definition at line 76 of file h2_stream.c.

◆ h2_stream_submit_pushes()

apr_status_t h2_stream_submit_pushes ( h2_stream stream,
struct h2_headers response 
)

Submit any server push promises on this stream and schedule the streams for these.

Parameters
streamthe stream for which to submit

Definition at line 1205 of file h2_stream.c.

◆ h2_stream_wants_send_data()

int h2_stream_wants_send_data ( h2_stream stream)

Definition at line 1268 of file h2_stream.c.

◆ input_append_bucket()

static void input_append_bucket ( h2_stream stream,
apr_bucket b 
)
static

Definition at line 247 of file h2_stream.c.

◆ input_append_data()

static void input_append_data ( h2_stream stream,
const char data,
apr_size_t  len 
)
static

Definition at line 257 of file h2_stream.c.

◆ input_buffer_is_empty()

static int input_buffer_is_empty ( h2_stream stream)
static

Definition at line 221 of file h2_stream.c.

◆ input_flush()

static apr_status_t input_flush ( h2_stream stream)
static

Definition at line 226 of file h2_stream.c.

◆ on_event()

static int on_event ( h2_stream stream,
h2_stream_event_t  ev 
)
static

Definition at line 167 of file h2_stream.c.

◆ on_frame()

static int on_frame ( h2_stream_state_t  state,
int  frame_type,
int  frame_map[][H2_SS_MAX],
apr_size_t  maxlen 
)
static

Definition at line 146 of file h2_stream.c.

◆ on_frame_recv()

static int on_frame_recv ( h2_stream_state_t  state,
int  frame_type 
)
static

Definition at line 162 of file h2_stream.c.

◆ on_frame_send()

static int on_frame_send ( h2_stream_state_t  state,
int  frame_type 
)
static

Definition at line 157 of file h2_stream.c.

◆ on_map()

static int on_map ( h2_stream_state_t  state,
int  map[H2_SS_MAX] 
)
static

Definition at line 132 of file h2_stream.c.

◆ on_state_enter()

static void on_state_enter ( h2_stream stream)
static

Definition at line 309 of file h2_stream.c.

◆ on_state_event()

static void on_state_event ( h2_stream stream,
h2_stream_event_t  ev 
)
static

Definition at line 316 of file h2_stream.c.

◆ on_state_invalid()

static void on_state_invalid ( h2_stream stream)
static

Definition at line 323 of file h2_stream.c.

◆ output_data_buffered()

static apr_off_t output_data_buffered ( h2_stream stream,
int peos,
int pheader_blocked 
)
static

Definition at line 1364 of file h2_stream.c.

◆ set_error_response()

static void set_error_response ( h2_stream stream,
int  http_status 
)
static

Definition at line 684 of file h2_stream.c.

◆ set_policy_for()

static void set_policy_for ( h2_stream stream,
h2_request r 
)
static

Definition at line 419 of file h2_stream.c.

◆ stream_data_cb()

static ssize_t stream_data_cb ( nghttp2_session ng2s,
int32_t  stream_id,
uint8_t buf,
size_t  length,
uint32_t data_flags,
nghttp2_data_source source,
void *  puser 
)
static

Definition at line 1403 of file h2_stream.c.

◆ stream_do_error_bucket()

static void stream_do_error_bucket ( h2_stream stream,
apr_bucket b 
)
static

Definition at line 998 of file h2_stream.c.

◆ stream_do_response()

static apr_status_t stream_do_response ( h2_stream stream)
static

Definition at line 1565 of file h2_stream.c.

◆ stream_do_responses()

static void stream_do_responses ( h2_stream stream)
static

Definition at line 1737 of file h2_stream.c.

◆ stream_do_trailers()

static apr_status_t stream_do_trailers ( h2_stream stream)
static

Definition at line 1128 of file h2_stream.c.

◆ stream_setup_input()

static void stream_setup_input ( h2_stream stream)
static

Definition at line 200 of file h2_stream.c.

◆ table_check_val_len()

static int table_check_val_len ( void *  baton,
const char key,
const char value 
)
static

Definition at line 833 of file h2_stream.c.

◆ transit()

static apr_status_t transit ( h2_stream stream,
int  new_state 
)
static

Definition at line 344 of file h2_stream.c.

Variable Documentation

◆ trans_on_event

int trans_on_event[][H2_SS_MAX]
static
Initial value:
= {
{ (-2) , (-1) , (-1) , (H2_SS_CLOSED_L + 1) , (H2_SS_CLOSED + 1) , (-2) , (-2) , (-2) , },
{ (-1) , (-1) , (-1) , (H2_SS_CLOSED_R + 1) , (-1) , (H2_SS_CLOSED + 1) , (0) , (0) , },
{ (H2_SS_CLOSED + 1) , (H2_SS_CLOSED + 1) , (H2_SS_CLOSED + 1) , (H2_SS_CLOSED + 1) , (H2_SS_CLOSED + 1) , (H2_SS_CLOSED + 1) , (0) , (0) , },
{ (0) , (-2) , (-2) , (-2) , (-2) , (H2_SS_CLOSED + 1) , (H2_SS_CLEANUP + 1) , (0) , },
{ (0) , (-2) , (H2_SS_CLOSED + 1) , (-2) , (-2) , (H2_SS_CLOSED + 1) , (-2) , (-2) , },
}
@ H2_SS_CLOSED
Definition h2.h:148
@ H2_SS_CLOSED_R
Definition h2.h:146
@ H2_SS_CLOSED_L
Definition h2.h:147
@ H2_SS_CLEANUP
Definition h2.h:149

Definition at line 123 of file h2_stream.c.

◆ trans_on_recv

int trans_on_recv[][H2_SS_MAX]
static
Initial value:
= {
{ (-1) , (-1) , (-1) , (0) , (-1) , (0) , (0) , (0) , },
{ (H2_SS_OPEN + 1) , (H2_SS_CLOSED_L + 1) , (-1) , (0) , (-1) , (0) , (0) , (0) , },
{ (0) , (0) , (0) , (0) , (0) , (0) , (0) , (0) , },
{ (-1) , (H2_SS_CLOSED + 1) , (H2_SS_CLOSED + 1) , (H2_SS_CLOSED + 1) , (H2_SS_CLOSED + 1) , (H2_SS_CLOSED + 1) , (0) , (0) , },
{ (-1) , (-1) , (-1) , (-1) , (-1) , (-1) , (-1) , (-1) , },
{ (H2_SS_RSVD_R + 1) , (-1) , (-1) , (-1) , (-1) , (-1) , (-1) , (-1) , },
{ (-1) , (-1) , (-1) , (-1) , (-1) , (-1) , (-1) , (-1) , },
{ (-1) , (-1) , (-1) , (-1) , (-1) , (-1) , (-1) , (-1) , },
{ (0) , (0) , (0) , (0) , (0) , (0) , (0) , (0) , },
{ (0) , (0) , (0) , (0) , (0) , (0) , (0) , (0) , },
}
@ H2_SS_OPEN
Definition h2.h:145
@ H2_SS_RSVD_R
Definition h2.h:143

Definition at line 109 of file h2_stream.c.

◆ trans_on_send

int trans_on_send[][H2_SS_MAX]
static
Initial value:
= {
{ (-1) , (-1) , (-1) , (0) , (0) , (-1) , (0) , (0) , },
{ (-1) , (-1) , (H2_SS_CLOSED_R + 1) , (0) , (0) , (-1) , (0) , (0) , },
{ (0) , (0) , (0) , (0) , (0) , (0) , (0) , (0) , },
{ (H2_SS_CLOSED + 1) , (H2_SS_CLOSED + 1) , (H2_SS_CLOSED + 1) , (H2_SS_CLOSED + 1) , (H2_SS_CLOSED + 1) , (H2_SS_CLOSED + 1) , (0) , (0) , },
{ (-1) , (-1) , (-1) , (-1) , (-1) , (-1) , (-1) , (-1) , },
{ (H2_SS_RSVD_L + 1) , (-1) , (-1) , (-1) , (-1) , (-1) , (-1) , (-1) , },
{ (-1) , (-1) , (-1) , (-1) , (-1) , (-1) , (-1) , (-1) , },
{ (-1) , (-1) , (-1) , (-1) , (-1) , (-1) , (-1) , (-1) , },
{ (0) , (0) , (0) , (0) , (0) , (0) , (0) , (0) , },
{ (0) , (0) , (0) , (0) , (0) , (0) , (0) , (0) , },
}
@ H2_SS_RSVD_L
Definition h2.h:144

Definition at line 95 of file h2_stream.c.