Apache HTTPD
Macros | Functions | Variables
h2_session.c File Reference
#include <assert.h>
#include <stddef.h>
#include <apr_thread_cond.h>
#include <apr_atomic.h>
#include <apr_base64.h>
#include <apr_strings.h>
#include <ap_mpm.h>
#include <httpd.h>
#include <http_core.h>
#include <http_config.h>
#include <http_log.h>
#include <http_protocol.h>
#include <scoreboard.h>
#include <mpm_common.h>
#include "h2_private.h"
#include "h2.h"
#include "h2_bucket_beam.h"
#include "h2_bucket_eos.h"
#include "h2_config.h"
#include "h2_conn_ctx.h"
#include "h2_protocol.h"
#include "h2_mplx.h"
#include "h2_push.h"
#include "h2_request.h"
#include "h2_headers.h"
#include "h2_stream.h"
#include "h2_c2.h"
#include "h2_session.h"
#include "h2_util.h"
#include "h2_version.h"
#include "h2_workers.h"

Go to the source code of this file.

Macros

#define NGH2_SET_CALLBACK(callbacks, name, fn)   nghttp2_session_callbacks_set_##name##_callback(callbacks, fn)
 

Functions

static void transit (h2_session *session, const char *action, h2_session_state nstate)
 
static void on_stream_state_enter (void *ctx, h2_stream *stream)
 
static void on_stream_state_event (void *ctx, h2_stream *stream, h2_stream_event_t ev)
 
static void on_stream_event (void *ctx, h2_stream *stream, h2_stream_event_t ev)
 
static int h2_session_status_from_apr_status (apr_status_t rv)
 
static h2_stream * get_stream (h2_session *session, int stream_id)
 
void h2_session_event (h2_session *session, h2_session_event_t ev, int err, const char *msg)
 
static int rst_unprocessed_stream (h2_stream *stream, void *ctx)
 
static void cleanup_unprocessed_streams (h2_session *session)
 
static h2_stream * h2_session_open_stream (h2_session *session, int stream_id, int initiated_on)
 
static int spri_cmp (int sid1, nghttp2_stream *s1, int sid2, nghttp2_stream *s2, h2_session *session)
 
static int stream_pri_cmp (int sid1, int sid2, void *ctx)
 
static ssize_t send_cb (nghttp2_session *ngh2, const uint8_t *data, size_t length, int flags, void *userp)
 
static int on_invalid_frame_recv_cb (nghttp2_session *ngh2, const nghttp2_frame *frame, int error, void *userp)
 
static int on_data_chunk_recv_cb (nghttp2_session *ngh2, uint8_t flags, int32_t stream_id, const uint8_t *data, size_t len, void *userp)
 
static int on_stream_close_cb (nghttp2_session *ngh2, int32_t stream_id, uint32_t error_code, void *userp)
 
static int on_begin_headers_cb (nghttp2_session *ngh2, const nghttp2_frame *frame, void *userp)
 
static int on_header_cb (nghttp2_session *ngh2, const nghttp2_frame *frame, const uint8_t *name, size_t namelen, const uint8_t *value, size_t valuelen, uint8_t flags, void *userp)
 
static int on_frame_recv_cb (nghttp2_session *ng2s, const nghttp2_frame *frame, void *userp)
 
static int on_send_data_cb (nghttp2_session *ngh2, nghttp2_frame *frame, const uint8_t *framehd, size_t length, nghttp2_data_source *source, void *userp)
 
static int on_frame_send_cb (nghttp2_session *ngh2, const nghttp2_frame *frame, void *user_data)
 
static ssize_t select_padding_cb (nghttp2_session *ngh2, const nghttp2_frame *frame, size_t max_payloadlen, void *user_data)
 
static apr_status_t init_callbacks (conn_rec *c, nghttp2_session_callbacks **pcb)
 
static void update_child_status (h2_session *session, int status, const char *msg, const h2_stream *stream)
 
static apr_status_t h2_session_shutdown_notice (h2_session *session)
 
static apr_status_t h2_session_shutdown (h2_session *session, int error, const char *msg, int force_close)
 
static apr_status_t session_cleanup (h2_session *session, const char *trigger)
 
static apr_status_t session_pool_cleanup (void *data)
 
apr_status_t h2_session_create (h2_session **psession, conn_rec *c, request_rec *r, server_rec *s, h2_workers *workers)
 
static apr_status_t h2_session_start (h2_session *session, int *rv)
 
struct h2_stream * h2_session_push (h2_session *session, h2_stream *is, h2_push *push)
 
static int valid_weight (float f)
 
apr_status_t h2_session_set_prio (h2_session *session, h2_stream *stream, const h2_priority *prio)
 
int h2_session_push_enabled (h2_session *session)
 
static int h2_session_want_send (h2_session *session)
 
static apr_status_t h2_session_send (h2_session *session)
 
static void on_stream_input (void *ctx, h2_stream *stream)
 
static void on_stream_output (void *ctx, h2_stream *stream)
 
const char * h2_session_state_str (h2_session_state state)
 
static void h2_session_ev_init (h2_session *session, int arg, const char *msg)
 
static void h2_session_ev_input_pending (h2_session *session, int arg, const char *msg)
 
static void h2_session_ev_input_exhausted (h2_session *session, int arg, const char *msg)
 
static void h2_session_ev_local_goaway (h2_session *session, int arg, const char *msg)
 
static void h2_session_ev_remote_goaway (h2_session *session, int arg, const char *msg)
 
static void h2_session_ev_conn_error (h2_session *session, int arg, const char *msg)
 
static void h2_session_ev_proto_error (h2_session *session, int arg, const char *msg)
 
static void h2_session_ev_conn_timeout (h2_session *session, int arg, const char *msg)
 
static void h2_session_ev_ngh2_done (h2_session *session, int arg, const char *msg)
 
static void h2_session_ev_mpm_stopping (h2_session *session, int arg, const char *msg)
 
static void h2_session_ev_pre_close (h2_session *session, int arg, const char *msg)
 
static void h2_session_ev_no_more_streams (h2_session *session)
 
static void ev_stream_created (h2_session *session, h2_stream *stream)
 
static void ev_stream_open (h2_session *session, h2_stream *stream)
 
static void ev_stream_closed (h2_session *session, h2_stream *stream)
 
void h2_session_dispatch_event (h2_session *session, h2_session_event_t ev, apr_status_t arg, const char *msg)
 
static void unblock_c1_out (h2_session *session)
 
apr_status_t h2_session_process (h2_session *session, int async)
 
apr_status_t h2_session_pre_close (h2_session *session, int async)
 

Variables

static char immortal_zeros [256]
 
static apr_uint32_t next_id
 
static const char * StateNames []
 

Macro Definition Documentation

◆ NGH2_SET_CALLBACK

#define NGH2_SET_CALLBACK (   callbacks,
  name,
  fn 
)    nghttp2_session_callbacks_set_##name##_callback(callbacks, fn)

Definition at line 674 of file h2_session.c.

Function Documentation

◆ cleanup_unprocessed_streams()

static void cleanup_unprocessed_streams ( h2_session *  session)
static

Definition at line 107 of file h2_session.c.

◆ ev_stream_closed()

static void ev_stream_closed ( h2_session *  session,
h2_stream *  stream 
)
static

Definition at line 1612 of file h2_session.c.

◆ ev_stream_created()

static void ev_stream_created ( h2_session *  session,
h2_stream *  stream 
)
static

Definition at line 1586 of file h2_session.c.

◆ ev_stream_open()

static void ev_stream_open ( h2_session *  session,
h2_stream *  stream 
)
static

Definition at line 1591 of file h2_session.c.

◆ get_stream()

static h2_stream * get_stream ( h2_session *  session,
int  stream_id 
)
static

Definition at line 79 of file h2_session.c.

◆ h2_session_create()

apr_status_t h2_session_create ( h2_session **  psession,
conn_rec *  c,
request_rec *  r,
server_rec *  s,
struct h2_workers *  workers 
)

Create a new h2_session for the given connection. The session will apply the configured parameter.

Parameters
psessionpointer receiving the created session on success or NULL
cthe connection to work on
roptional request when protocol was upgraded
cfgthe module config to apply
workersthe worker pool to use
Returns
the created session

Definition at line 875 of file h2_session.c.

◆ h2_session_dispatch_event()

void h2_session_dispatch_event ( h2_session *  session,
h2_session_event_t  ev,
int  arg,
const char *  msg 
)

Dispatch a event happending during session processing.

Parameters
sessionthe sessiont
evthe event that happened
arginteger argument (event type dependant)
msgdestriptive message

Definition at line 1710 of file h2_session.c.

◆ h2_session_ev_conn_error()

static void h2_session_ev_conn_error ( h2_session *  session,
int  arg,
const char *  msg 
)
static

Definition at line 1489 of file h2_session.c.

◆ h2_session_ev_conn_timeout()

static void h2_session_ev_conn_timeout ( h2_session *  session,
int  arg,
const char *  msg 
)
static

Definition at line 1517 of file h2_session.c.

◆ h2_session_ev_init()

static void h2_session_ev_init ( h2_session *  session,
int  arg,
const char *  msg 
)
static

Definition at line 1424 of file h2_session.c.

◆ h2_session_ev_input_exhausted()

static void h2_session_ev_input_exhausted ( h2_session *  session,
int  arg,
const char *  msg 
)
static

Definition at line 1449 of file h2_session.c.

◆ h2_session_ev_input_pending()

static void h2_session_ev_input_pending ( h2_session *  session,
int  arg,
const char *  msg 
)
static

Definition at line 1436 of file h2_session.c.

◆ h2_session_ev_local_goaway()

static void h2_session_ev_local_goaway ( h2_session *  session,
int  arg,
const char *  msg 
)
static

Definition at line 1472 of file h2_session.c.

◆ h2_session_ev_mpm_stopping()

static void h2_session_ev_mpm_stopping ( h2_session *  session,
int  arg,
const char *  msg 
)
static

Definition at line 1537 of file h2_session.c.

◆ h2_session_ev_ngh2_done()

static void h2_session_ev_ngh2_done ( h2_session *  session,
int  arg,
const char *  msg 
)
static

Definition at line 1525 of file h2_session.c.

◆ h2_session_ev_no_more_streams()

static void h2_session_ev_no_more_streams ( h2_session *  session)
static

Definition at line 1557 of file h2_session.c.

◆ h2_session_ev_pre_close()

static void h2_session_ev_pre_close ( h2_session *  session,
int  arg,
const char *  msg 
)
static

Definition at line 1552 of file h2_session.c.

◆ h2_session_ev_proto_error()

static void h2_session_ev_proto_error ( h2_session *  session,
int  arg,
const char *  msg 
)
static

Definition at line 1507 of file h2_session.c.

◆ h2_session_ev_remote_goaway()

static void h2_session_ev_remote_goaway ( h2_session *  session,
int  arg,
const char *  msg 
)
static

Definition at line 1478 of file h2_session.c.

◆ h2_session_event()

void h2_session_event ( h2_session *  session,
h2_session_event_t  ev,
int  err,
const char *  msg 
)

Definition at line 84 of file h2_session.c.

◆ h2_session_open_stream()

static h2_stream * h2_session_open_stream ( h2_session *  session,
int  stream_id,
int  initiated_on 
)
static

Definition at line 112 of file h2_session.c.

◆ h2_session_pre_close()

apr_status_t h2_session_pre_close ( h2_session *  session,
int  async 
)

Last chance to do anything before the connection is closed.

Definition at line 2011 of file h2_session.c.

◆ h2_session_process()

apr_status_t h2_session_process ( h2_session *  session,
int  async 
)

Process the given HTTP/2 session until it is ended or a fatal error occurred.

Parameters
sessionthe sessionm to process

Definition at line 1765 of file h2_session.c.

◆ h2_session_push()

struct h2_stream * h2_session_push ( h2_session *  session,
struct h2_stream *  is,
struct h2_push *  push 
)

Submit a push promise on the stream and schedule the new steam for processing..

Parameters
sessionthe session to work in
isthe stream initiating the push
pushthe push to promise
Returns
the new promised stream or NULL

Definition at line 1136 of file h2_session.c.

◆ h2_session_push_enabled()

int h2_session_push_enabled ( h2_session *  session)

Returns if client settings have push enabled.

Parameters
!=0 iff push is enabled in client settings

Definition at line 1277 of file h2_session.c.

◆ h2_session_send()

static apr_status_t h2_session_send ( h2_session *  session)
static

Definition at line 1292 of file h2_session.c.

◆ h2_session_set_prio()

apr_status_t h2_session_set_prio ( h2_session *  session,
h2_stream *  stream,
const h2_priority *  prio 
)

Definition at line 1184 of file h2_session.c.

◆ h2_session_shutdown()

static apr_status_t h2_session_shutdown ( h2_session *  session,
int  error,
const char *  msg,
int  force_close 
)
static

Definition at line 750 of file h2_session.c.

◆ h2_session_shutdown_notice()

static apr_status_t h2_session_shutdown_notice ( h2_session *  session)
static

Definition at line 730 of file h2_session.c.

◆ h2_session_start()

static apr_status_t h2_session_start ( h2_session *  session,
int *  rv 
)
static

Definition at line 1022 of file h2_session.c.

◆ h2_session_state_str()

const char * h2_session_state_str ( h2_session_state  state)

Definition at line 1374 of file h2_session.c.

◆ h2_session_status_from_apr_status()

static int h2_session_status_from_apr_status ( apr_status_t  rv)
static

Definition at line 65 of file h2_session.c.

◆ h2_session_want_send()

static int h2_session_want_send ( h2_session *  session)
static

Definition at line 1286 of file h2_session.c.

◆ init_callbacks()

static apr_status_t init_callbacks ( conn_rec *  c,
nghttp2_session_callbacks **  pcb 
)
static

Definition at line 677 of file h2_session.c.

◆ on_begin_headers_cb()

static int on_begin_headers_cb ( nghttp2_session *  ngh2,
const nghttp2_frame *  frame,
void *  userp 
)
static

Definition at line 282 of file h2_session.c.

◆ on_data_chunk_recv_cb()

static int on_data_chunk_recv_cb ( nghttp2_session *  ngh2,
uint8_t  flags,
int32_t  stream_id,
const uint8_t *  data,
size_t  len,
void *  userp 
)
static

Definition at line 232 of file h2_session.c.

◆ on_frame_recv_cb()

static int on_frame_recv_cb ( nghttp2_session *  ng2s,
const nghttp2_frame *  frame,
void *  userp 
)
static

nghttp2 session has received a complete frame. Most are used by nghttp2 for processing of internal state. Some, like HEADER and DATA frames, we need to act on.

Definition at line 339 of file h2_session.c.

◆ on_frame_send_cb()

static int on_frame_send_cb ( nghttp2_session *  ngh2,
const nghttp2_frame *  frame,
void *  user_data 
)
static

Definition at line 575 of file h2_session.c.

◆ on_header_cb()

static int on_header_cb ( nghttp2_session *  ngh2,
const nghttp2_frame *  frame,
const uint8_t *  name,
size_t  namelen,
const uint8_t *  value,
size_t  valuelen,
uint8_t  flags,
void *  userp 
)
static

Definition at line 301 of file h2_session.c.

◆ on_invalid_frame_recv_cb()

static int on_invalid_frame_recv_cb ( nghttp2_session *  ngh2,
const nghttp2_frame *  frame,
int  error,
void *  userp 
)
static

Definition at line 212 of file h2_session.c.

◆ on_send_data_cb()

static int on_send_data_cb ( nghttp2_session *  ngh2,
nghttp2_frame *  frame,
const uint8_t *  framehd,
size_t  length,
nghttp2_data_source *  source,
void *  userp 
)
static

Definition at line 491 of file h2_session.c.

◆ on_stream_close_cb()

static int on_stream_close_cb ( nghttp2_session *  ngh2,
int32_t  stream_id,
uint32_t  error_code,
void *  userp 
)
static

Definition at line 262 of file h2_session.c.

◆ on_stream_event()

static void on_stream_event ( void *  ctx,
h2_stream *  stream,
h2_stream_event_t  ev 
)
static

Definition at line 1677 of file h2_session.c.

◆ on_stream_input()

static void on_stream_input ( void *  ctx,
h2_stream *  stream 
)
static

A streams input state has changed.

Definition at line 1331 of file h2_session.c.

◆ on_stream_output()

static void on_stream_output ( void *  ctx,
h2_stream *  stream 
)
static

A streams output state has changed.

Definition at line 1351 of file h2_session.c.

◆ on_stream_state_enter()

static void on_stream_state_enter ( void *  ctx,
h2_stream *  stream 
)
static

Definition at line 1633 of file h2_session.c.

◆ on_stream_state_event()

static void on_stream_state_event ( void *  ctx,
h2_stream *  stream,
h2_stream_event_t  ev 
)
static

Definition at line 1693 of file h2_session.c.

◆ rst_unprocessed_stream()

static int rst_unprocessed_stream ( h2_stream *  stream,
void *  ctx 
)
static

Definition at line 90 of file h2_session.c.

◆ select_padding_cb()

static ssize_t select_padding_cb ( nghttp2_session *  ngh2,
const nghttp2_frame *  frame,
size_t  max_payloadlen,
void *  user_data 
)
static

Definition at line 643 of file h2_session.c.

◆ send_cb()

static ssize_t send_cb ( nghttp2_session *  ngh2,
const uint8_t *  data,
size_t  length,
int  flags,
void *  userp 
)
static

Definition at line 185 of file h2_session.c.

◆ session_cleanup()

static apr_status_t session_cleanup ( h2_session *  session,
const char *  trigger 
)
static

Definition at line 802 of file h2_session.c.

◆ session_pool_cleanup()

static apr_status_t session_pool_cleanup ( void *  data)
static

Definition at line 847 of file h2_session.c.

◆ spri_cmp()

static int spri_cmp ( int  sid1,
nghttp2_stream *  s1,
int  sid2,
nghttp2_stream *  s2,
h2_session *  session 
)
static

Determine the priority order of streams.

  • if both stream depend on the same one, compare weights
  • if one stream is closer to the root, prioritize that one
  • if both are on the same level, use the weight of their root level ancestors

Definition at line 136 of file h2_session.c.

◆ stream_pri_cmp()

static int stream_pri_cmp ( int  sid1,
int  sid2,
void *  ctx 
)
static

Definition at line 162 of file h2_session.c.

◆ transit()

static void transit ( h2_session *  session,
const char *  action,
h2_session_state  nstate 
)
static

Definition at line 1382 of file h2_session.c.

◆ unblock_c1_out()

static void unblock_c1_out ( h2_session *  session)
static

Definition at line 1757 of file h2_session.c.

◆ update_child_status()

static void update_child_status ( h2_session *  session,
int  status,
const char *  msg,
const h2_stream *  stream 
)
static

Definition at line 703 of file h2_session.c.

◆ valid_weight()

static int valid_weight ( float  f)
static

Definition at line 1177 of file h2_session.c.

Variable Documentation

◆ immortal_zeros

char immortal_zeros[256]
static

Definition at line 489 of file h2_session.c.

◆ next_id

apr_uint32_t next_id
static

Definition at line 873 of file h2_session.c.

◆ StateNames

const char* StateNames[]
static
Initial value:
= {
"INIT",
"DONE",
"IDLE",
"BUSY",
"WAIT",
"CLEANUP",
}

Definition at line 1365 of file h2_session.c.