Apache HTTPD
h2_stream.h
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef __mod_h2__h2_stream__
18#define __mod_h2__h2_stream__
19
20#include <http_protocol.h>
21
22#include "h2.h"
23#include "h2_headers.h"
24
40struct h2_mplx;
41struct h2_priority;
42struct h2_request;
43struct h2_session;
44struct h2_bucket_beam;
45
46typedef struct h2_stream h2_stream;
47
48typedef void h2_stream_state_cb(void *ctx, h2_stream *stream);
49typedef void h2_stream_event_cb(void *ctx, h2_stream *stream,
51
55typedef struct h2_stream_monitor {
56 void *ctx;
57 h2_stream_state_cb *on_state_enter; /* called when a state is entered */
58 h2_stream_state_cb *on_state_invalid; /* called when an invalid state change
59 was detected */
60 h2_stream_event_cb *on_state_event; /* called right before the given event
61 result in a new stream state */
62 h2_stream_event_cb *on_event; /* called for events that do not
63 trigger a state change */
65
66#ifdef AP_DEBUG
67#define H2_STRM_MAGIC_OK 0x5354524d
68#define H2_STRM_MAGIC_SDEL 0x5344454c
69#define H2_STRM_MAGIC_PDEL 0x5044454c
70
71#define H2_STRM_ASSIGN_MAGIC(s,m) ((s)->magic = m)
72#define H2_STRM_ASSERT_MAGIC(s,m) ap_assert((s)->magic == m)
73#else
74#define H2_STRM_ASSIGN_MAGIC(s,m) ((void)0)
75#define H2_STRM_ASSERT_MAGIC(s,m) ((void)0)
76#endif
77
78struct h2_stream {
79#ifdef AP_DEBUG
81#endif
82 int id; /* http2 stream identifier */
83 int initiated_on; /* initiating stream id (PUSH) or 0 */
84 apr_pool_t *pool; /* the memory pool for this stream */
85 struct h2_session *session; /* the session this stream belongs to */
86 h2_stream_state_t state; /* state of this stream */
87
88 apr_time_t created; /* when stream was created */
89
90 const struct h2_request *request; /* the request made in this stream */
91 struct h2_request *rtmp; /* request being assembled */
92 apr_table_t *trailers_in; /* optional, incoming trailers */
93 int request_headers_added; /* number of request headers added */
94 int request_headers_failed; /* number of request headers failed to add */
95
96#if AP_HAS_RESPONSE_BUCKETS
97 ap_bucket_response *response; /* the final, non-interim response or NULL */
98#else
99 struct h2_headers *response; /* the final, non-interim response or NULL */
100#endif
101
106
109
110 int rst_error; /* stream error for RST_STREAM */
111 unsigned int aborted : 1; /* was aborted */
112 unsigned int scheduled : 1; /* stream has been scheduled */
113 unsigned int input_closed : 1; /* no more request data/trailers coming */
114 unsigned int push_policy; /* which push policy to use for this request */
115 unsigned int sent_trailers : 1; /* trailers have been submitted */
116 unsigned int output_eos : 1; /* output EOS in buffer/sent */
117
118 conn_rec *c2; /* connection processing stream */
119
120 const h2_priority *pref_priority; /* preferred priority for this stream */
121 apr_off_t out_frames; /* # of frames sent out */
122 apr_off_t out_frame_octets; /* # of RAW frame octets sent out */
123 apr_off_t out_data_frames; /* # of DATA frames sent */
124 apr_off_t out_data_octets; /* # of DATA octets (payload) sent */
125 apr_off_t in_data_frames; /* # of DATA frames received */
126 apr_off_t in_data_octets; /* # of DATA octets (payload) received */
127 apr_off_t in_trailer_octets; /* # of HEADER octets (payload) received in trailers */
128
129 h2_stream_monitor *monitor; /* optional monitor for stream states */
130};
131
132
133#define H2_STREAM_RST(s, def) (s->rst_error? s->rst_error : (def))
134
147 struct h2_session *session,
148 h2_stream_monitor *monitor,
149 int initiated_on);
150
154void h2_stream_destroy(h2_stream *stream);
155
160
161/*
162 * Set a new monitor for this stream, replacing any existing one. Can
163 * be called with NULL to have no monitor installed.
164 */
166
173
180int h2_stream_is_at(const h2_stream *stream, h2_stream_state_t state);
181
188int h2_stream_is_at_or_past(const h2_stream *stream, h2_stream_state_t state);
189
195void h2_stream_cleanup(h2_stream *stream);
196
202
210void h2_stream_set_request(h2_stream *stream, const h2_request *r);
211
220 request_rec *r, int eos);
221
222/*
223 * Add a HTTP/2 header (including pseudo headers) or trailer
224 * to the given stream, depending on stream state.
225 *
226 * @param stream stream to write the header to
227 * @param name the name of the HTTP/2 header
228 * @param nlen the number of characters in name
229 * @param value the header value
230 * @param vlen the number of characters in value
231 */
233 const char *name, size_t nlen,
234 const char *value, size_t vlen);
235
236/* End the construction of request headers */
237apr_status_t h2_stream_end_headers(h2_stream *stream, int eos, size_t raw_bytes);
238
239
242
243/*
244 * Process a frame of received DATA.
245 *
246 * @param stream stream to write the data to
247 * @param flags the frame flags
248 * @param data the beginning of the bytes to write
249 * @param len the number of bytes to write
250 */
252 const uint8_t *data, size_t len);
253
260void h2_stream_rst(h2_stream *stream, int error_code);
261
267
273
287 apr_off_t *plen, int *peos);
288
298
305#if AP_HAS_RESPONSE_BUCKETS
307 ap_bucket_response *response);
308#else
310 struct h2_headers *response);
311#endif
312
316#if AP_HAS_RESPONSE_BUCKETS
317const struct h2_priority *h2_stream_get_priority(h2_stream *stream,
318 ap_bucket_response *response);
319#else
320const struct h2_priority *h2_stream_get_priority(h2_stream *stream,
321 struct h2_headers *response);
322#endif
323
328const char *h2_stream_state_str(const h2_stream *stream);
329
334int h2_stream_is_ready(h2_stream *stream);
335
337
338#define H2_STRM_MSG(s, msg) \
339 "h2_stream(%d-%lu-%d,%s): "msg, s->session->child_num, \
340 (unsigned long)s->session->id, s->id, h2_stream_state_str(s)
341
342#define H2_STRM_LOG(aplogno, s, msg) aplogno H2_STRM_MSG(s, msg)
343
344#endif /* defined(__mod_h2__h2_stream__) */
const char apr_size_t len
Definition ap_regex.h:187
request_rec * r
apr_brigade_flush void * ctx
const char apr_ssize_t int flags
Definition apr_encode.h:168
apr_size_t size
const char int apr_pool_t * pool
Definition apr_cstr.h:84
const char * value
Definition apr_env.h:51
int apr_status_t
Definition apr_errno.h:44
void * data
apr_int64_t apr_time_t
Definition apr_time.h:45
h2_stream_state_t
Definition h2.h:141
h2_stream_event_t
Definition h2.h:153
apr_status_t h2_stream_add_header(h2_stream *stream, const char *name, size_t nlen, const char *value, size_t vlen)
Definition h2_stream.c:730
apr_status_t h2_stream_set_request_rec(h2_stream *stream, request_rec *r, int eos)
Definition h2_stream.c:650
void h2_stream_dispatch(h2_stream *stream, h2_stream_event_t ev)
Definition h2_stream.c:392
void h2_stream_set_request(h2_stream *stream, const h2_request *r)
Definition h2_stream.c:676
apr_status_t h2_stream_recv_DATA(h2_stream *stream, uint8_t flags, const uint8_t *data, size_t len)
Definition h2_stream.c:529
apr_status_t h2_stream_submit_pushes(h2_stream *stream, struct h2_headers *response)
Definition h2_stream.c:1205
const char * h2_stream_state_str(const h2_stream *stream)
Definition h2_stream.c:76
apr_status_t h2_stream_in_consumed(h2_stream *stream, apr_off_t amount)
Definition h2_stream.c:1303
int h2_stream_is_at(const h2_stream *stream, h2_stream_state_t state)
Definition h2_stream.c:1276
void h2_stream_destroy(h2_stream *stream)
Definition h2_stream.c:628
void h2_stream_event_cb(void *ctx, h2_stream *stream, h2_stream_event_t ev)
Definition h2_stream.h:49
void h2_stream_set_monitor(h2_stream *stream, h2_stream_monitor *monitor)
Definition h2_stream.c:387
void h2_stream_cleanup(h2_stream *stream)
Definition h2_stream.c:615
void h2_stream_on_output_change(h2_stream *stream)
Definition h2_stream.c:1763
h2_stream * h2_stream_create(int id, apr_pool_t *pool, struct h2_session *session, h2_stream_monitor *monitor, int initiated_on)
Definition h2_stream.c:582
void h2_stream_rst(h2_stream *stream, int error_code)
Definition h2_stream.c:638
apr_status_t h2_stream_end_headers(h2_stream *stream, int eos, size_t raw_bytes)
Definition h2_stream.c:842
apr_status_t h2_stream_send_frame(h2_stream *stream, int frame_type, int flags, size_t frame_len)
Definition h2_stream.c:425
int h2_stream_is_at_or_past(const h2_stream *stream, h2_stream_state_t state)
Definition h2_stream.c:1282
void h2_stream_on_input_change(h2_stream *stream)
Definition h2_stream.c:1817
apr_status_t h2_stream_prepare_processing(h2_stream *stream)
Definition h2_stream.c:211
apr_status_t h2_stream_recv_frame(h2_stream *stream, int frame_type, int flags, size_t frame_len)
Definition h2_stream.c:475
int h2_stream_is_ready(h2_stream *stream)
Definition h2_stream.c:1255
int h2_stream_wants_send_data(h2_stream *stream)
Definition h2_stream.c:1268
apr_table_t * h2_stream_get_trailers(h2_stream *stream)
Definition h2_stream.c:1230
apr_status_t h2_stream_read_to(h2_stream *stream, apr_bucket_brigade *bb, apr_off_t *plen, int *peos)
Definition h2_stream.c:1112
const struct h2_priority * h2_stream_get_priority(h2_stream *stream, struct h2_headers *response)
Definition h2_stream.c:1240
void h2_stream_state_cb(void *ctx, h2_stream *stream)
Definition h2_stream.h:48
HTTP protocol handling.
char * name
Structure to store things which are per connection.
Definition httpd.h:1152
h2_stream_state_cb * on_state_enter
Definition h2_stream.h:57
h2_stream_event_cb * on_state_event
Definition h2_stream.h:60
h2_stream_event_cb * on_event
Definition h2_stream.h:62
h2_stream_state_cb * on_state_invalid
Definition h2_stream.h:58
conn_rec * c2
Definition h2_stream.h:118
apr_off_t in_data_frames
Definition h2_stream.h:125
struct h2_headers * response
Definition h2_stream.h:99
struct h2_bucket_beam * output
Definition h2_stream.h:107
unsigned int push_policy
Definition h2_stream.h:114
unsigned int input_closed
Definition h2_stream.h:113
apr_off_t in_trailer_octets
Definition h2_stream.h:127
struct h2_request * rtmp
Definition h2_stream.h:91
h2_stream_monitor * monitor
Definition h2_stream.h:129
int rst_error
Definition h2_stream.h:110
struct h2_bucket_beam * input
Definition h2_stream.h:102
unsigned int scheduled
Definition h2_stream.h:112
int request_headers_failed
Definition h2_stream.h:94
unsigned int output_eos
Definition h2_stream.h:116
const h2_priority * pref_priority
Definition h2_stream.h:120
unsigned int aborted
Definition h2_stream.h:111
int in_window_size
Definition h2_stream.h:104
apr_table_t * trailers_in
Definition h2_stream.h:92
h2_stream_state_t state
Definition h2_stream.h:86
apr_bucket_brigade * out_buffer
Definition h2_stream.h:108
apr_off_t out_data_octets
Definition h2_stream.h:124
apr_time_t created
Definition h2_stream.h:88
int initiated_on
Definition h2_stream.h:83
int request_headers_added
Definition h2_stream.h:93
unsigned int sent_trailers
Definition h2_stream.h:115
apr_off_t out_frame_octets
Definition h2_stream.h:122
apr_off_t out_data_frames
Definition h2_stream.h:123
const struct h2_request * request
Definition h2_stream.h:90
apr_pool_t * pool
Definition h2_stream.h:84
apr_off_t out_frames
Definition h2_stream.h:121
apr_bucket_brigade * in_buffer
Definition h2_stream.h:103
struct h2_session * session
Definition h2_stream.h:85
apr_off_t in_data_octets
Definition h2_stream.h:126
apr_time_t in_last_write
Definition h2_stream.h:105
A structure that represents the current request.
Definition httpd.h:845