Apache2
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 
40 struct h2_mplx;
41 struct h2_priority;
42 struct h2_request;
43 struct h2_session;
44 struct h2_bucket_beam;
45 
46 typedef struct h2_stream h2_stream;
47 
48 typedef void h2_stream_state_cb(void *ctx, h2_stream *stream);
49 typedef void h2_stream_event_cb(void *ctx, h2_stream *stream,
51 
55 typedef 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 
78 struct h2_stream {
79 #ifdef AP_DEBUG
80  uint32_t magic;
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 
95 #if AP_HAS_RESPONSE_BUCKETS
96  ap_bucket_response *response; /* the final, non-interim response or NULL */
97 #else
98  struct h2_headers *response; /* the final, non-interim response or NULL */
99 #endif
100 
105 
108 
109  int rst_error; /* stream error for RST_STREAM */
110  unsigned int aborted : 1; /* was aborted */
111  unsigned int scheduled : 1; /* stream has been scheduled */
112  unsigned int input_closed : 1; /* no more request data/trailers coming */
113  unsigned int push_policy; /* which push policy to use for this request */
114  unsigned int sent_trailers : 1; /* trailers have been submitted */
115  unsigned int output_eos : 1; /* output EOS in buffer/sent */
116 
117  conn_rec *c2; /* connection processing stream */
118 
119  const h2_priority *pref_priority; /* preferred priority for this stream */
120  apr_off_t out_frames; /* # of frames sent out */
121  apr_off_t out_frame_octets; /* # of RAW frame octets sent out */
122  apr_off_t out_data_frames; /* # of DATA frames sent */
123  apr_off_t out_data_octets; /* # of DATA octets (payload) sent */
124  apr_off_t in_data_frames; /* # of DATA frames received */
125  apr_off_t in_data_octets; /* # of DATA octets (payload) received */
126  apr_off_t in_trailer_octets; /* # of HEADER octets (payload) received in trailers */
127 
128  h2_stream_monitor *monitor; /* optional monitor for stream states */
129 };
130 
131 
132 #define H2_STREAM_RST(s, def) (s->rst_error? s->rst_error : (def))
133 
146  struct h2_session *session,
148  int initiated_on);
149 
154 
159 
160 /*
161  * Set a new monitor for this stream, replacing any existing one. Can
162  * be called with NULL to have no monitor installed.
163  */
165 
172 
179 int h2_stream_is_at(const h2_stream *stream, h2_stream_state_t state);
180 
188 
195 
201 
210 
219  request_rec *r, int eos);
220 
221 /*
222  * Add a HTTP/2 header (including pseudo headers) or trailer
223  * to the given stream, depending on stream state.
224  *
225  * @param stream stream to write the header to
226  * @param name the name of the HTTP/2 header
227  * @param nlen the number of characters in name
228  * @param value the header value
229  * @param vlen the number of characters in value
230  */
232  const char *name, size_t nlen,
233  const char *value, size_t vlen);
234 
235 /* End the construction of request headers */
236 apr_status_t h2_stream_end_headers(h2_stream *stream, int eos, size_t raw_bytes);
237 
238 
239 apr_status_t h2_stream_send_frame(h2_stream *stream, int frame_type, int flags, size_t frame_len);
240 apr_status_t h2_stream_recv_frame(h2_stream *stream, int frame_type, int flags, size_t frame_len);
241 
242 /*
243  * Process a frame of received DATA.
244  *
245  * @param stream stream to write the data to
246  * @param flags the frame flags
247  * @param data the beginning of the bytes to write
248  * @param len the number of bytes to write
249  */
251  const uint8_t *data, size_t len);
252 
259 void h2_stream_rst(h2_stream *stream, int error_code);
260 
266 
272 
286  apr_off_t *plen, int *peos);
287 
297 
304 #if AP_HAS_RESPONSE_BUCKETS
307 #else
309  struct h2_headers *response);
310 #endif
311 
315 #if AP_HAS_RESPONSE_BUCKETS
316 const struct h2_priority *h2_stream_get_priority(h2_stream *stream,
318 #else
320  struct h2_headers *response);
321 #endif
322 
327 const char *h2_stream_state_str(const h2_stream *stream);
328 
334 
336 
337 #define H2_STRM_MSG(s, msg) \
338  "h2_stream(%d-%lu-%d,%s): "msg, s->session->child_num, \
339  (unsigned long)s->session->id, s->id, h2_stream_state_str(s)
340 
341 #define H2_STRM_LOG(aplogno, s, msg) aplogno H2_STRM_MSG(s, msg)
342 
343 #endif /* defined(__mod_h2__h2_stream__) */
dav_resource int dav_locktoken dav_response int flags
Definition: mod_dav.h:1458
request_rec * r
Definition: mod_dav.h:518
dav_error dav_response * response
Definition: mod_dav.h:204
apr_bucket_brigade * bb
Definition: mod_dav.h:555
apr_bucket_brigade request_rec apr_pool_t * pool
Definition: mod_dav.h:557
const char * name
Definition: mod_dav.h:805
int apr_status_t
Definition: apr_errno.h:44
off_t apr_off_t
Definition: apr.h:396
struct apr_pool_t apr_pool_t
Definition: apr_pools.h:60
struct apr_table_t apr_table_t
Definition: apr_tables.h:56
apr_int64_t apr_time_t
Definition: apr_time.h:45
int monitor(apr_pool_t *p, server_rec *s)
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)
apr_table_t * h2_stream_get_trailers(h2_stream *stream)
apr_status_t h2_stream_set_request_rec(h2_stream *stream, request_rec *r, int eos)
void h2_stream_dispatch(h2_stream *stream, h2_stream_event_t ev)
void h2_stream_set_request(h2_stream *stream, const h2_request *r)
apr_status_t h2_stream_recv_DATA(h2_stream *stream, uint8_t flags, const uint8_t *data, size_t len)
apr_status_t h2_stream_submit_pushes(h2_stream *stream, struct h2_headers *response)
const char * h2_stream_state_str(const h2_stream *stream)
apr_status_t h2_stream_in_consumed(h2_stream *stream, apr_off_t amount)
int h2_stream_is_at(const h2_stream *stream, h2_stream_state_t state)
void h2_stream_destroy(h2_stream *stream)
h2_stream * h2_stream_create(int id, apr_pool_t *pool, struct h2_session *session, h2_stream_monitor *monitor, int initiated_on)
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)
const struct h2_priority * h2_stream_get_priority(h2_stream *stream, struct h2_headers *response)
void h2_stream_cleanup(h2_stream *stream)
void h2_stream_on_output_change(h2_stream *stream)
struct h2_stream_monitor h2_stream_monitor
void h2_stream_rst(h2_stream *stream, int error_code)
apr_status_t h2_stream_end_headers(h2_stream *stream, int eos, size_t raw_bytes)
apr_status_t h2_stream_send_frame(h2_stream *stream, int frame_type, int flags, size_t frame_len)
int h2_stream_is_at_or_past(const h2_stream *stream, h2_stream_state_t state)
void h2_stream_on_input_change(h2_stream *stream)
apr_status_t h2_stream_prepare_processing(h2_stream *stream)
apr_status_t h2_stream_recv_frame(h2_stream *stream, int frame_type, int flags, size_t frame_len)
int h2_stream_is_ready(h2_stream *stream)
int h2_stream_wants_send_data(h2_stream *stream)
apr_status_t h2_stream_read_to(h2_stream *stream, apr_bucket_brigade *bb, apr_off_t *plen, int *peos)
void h2_stream_state_cb(void *ctx, h2_stream *stream)
Definition: h2_stream.h:48
HTTP protocol handling.
A bucket referring to a HTTP response.
Definition: http_protocol.h:1199
Definition: apr_buckets.h:263
Structure to store things which are per connection.
Definition: httpd.h:1193
Definition: h2_bucket_beam.h:44
Definition: h2_headers.h:27
Definition: h2_mplx.h:58
Definition: h2.h:109
Definition: h2.h:169
Definition: h2_session.h:64
Definition: h2_stream.h:55
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
void * ctx
Definition: h2_stream.h:56
Definition: h2_stream.h:78
conn_rec * c2
Definition: h2_stream.h:117
apr_off_t in_data_frames
Definition: h2_stream.h:124
struct h2_headers * response
Definition: h2_stream.h:98
struct h2_bucket_beam * output
Definition: h2_stream.h:106
unsigned int push_policy
Definition: h2_stream.h:113
unsigned int input_closed
Definition: h2_stream.h:112
apr_off_t in_trailer_octets
Definition: h2_stream.h:126
struct h2_request * rtmp
Definition: h2_stream.h:91
h2_stream_monitor * monitor
Definition: h2_stream.h:128
int rst_error
Definition: h2_stream.h:109
struct h2_bucket_beam * input
Definition: h2_stream.h:101
unsigned int scheduled
Definition: h2_stream.h:111
unsigned int output_eos
Definition: h2_stream.h:115
const h2_priority * pref_priority
Definition: h2_stream.h:119
unsigned int aborted
Definition: h2_stream.h:110
int in_window_size
Definition: h2_stream.h:103
apr_table_t * trailers_in
Definition: h2_stream.h:92
h2_stream_state_t state
Definition: h2_stream.h:86
int id
Definition: h2_stream.h:82
apr_bucket_brigade * out_buffer
Definition: h2_stream.h:107
apr_off_t out_data_octets
Definition: h2_stream.h:123
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:114
apr_off_t out_frame_octets
Definition: h2_stream.h:121
apr_off_t out_data_frames
Definition: h2_stream.h:122
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:120
apr_bucket_brigade * in_buffer
Definition: h2_stream.h:102
struct h2_session * session
Definition: h2_stream.h:85
apr_off_t in_data_octets
Definition: h2_stream.h:125
apr_time_t in_last_write
Definition: h2_stream.h:104
A structure that represents the current request.
Definition: httpd.h:856