int h2_alpn_pre_conn(conn_rec* c, void *arg)
{
- (void)arg;
+ h2_ctx *ctx = h2_ctx_get(c);
+
ap_log_cerror(APLOG_MARK, APLOG_TRACE2, 0, c,
"h2_h2, pre_connection, start");
- h2_ctx *ctx = h2_ctx_get(c);
if (h2_ctx_is_task(ctx)) {
/* our stream pseudo connection */
return DECLINED;
static int h2_alt_svc_request_handler(request_rec *r)
{
h2_ctx *ctx = h2_ctx_rget(r);
+ h2_config *cfg;
if (h2_ctx_is_active(ctx) || h2_ctx_is_task(ctx)) {
return DECLINED;
}
- h2_config *cfg = h2_config_rget(r);
+ cfg = h2_config_rget(r);
if (r->hostname && cfg && cfg->alt_svcs && cfg->alt_svcs->nelts > 0) {
const char *alt_svc_used = apr_table_get(r->headers_in, "Alt-Svc-Used");
if (!alt_svc_used /*|| (alt_svc_used[0] == '0')*/) {
* the vhost matching stuff.
*/
apr_uri_t uri;
+ request_rec r;
memset(&uri, 0, sizeof(uri));
uri.scheme = (char*)"https";
uri.hostinfo = (char*)ctx->hostname;
uri.port = c->local_addr->port;
uri.path = (char*)"/";
- request_rec r;
memset(&r, 0, sizeof(r));
r.uri = (char*)"/";
r.connection = c;
int maxw = h2_config_geti(config, H2_CONF_MAX_WORKERS);
int max_threads_per_child = 0;
- ap_mpm_query(AP_MPMQ_MAX_THREADS, &max_threads_per_child);
int threads_limit = 0;
+ int idle_secs = 0;
+
+ ap_mpm_query(AP_MPMQ_MAX_THREADS, &max_threads_per_child);
ap_mpm_query(AP_MPMQ_HARD_LIMIT_THREADS, &threads_limit);
if (minw <= 0) {
minw, maxw, max_threads_per_child, threads_limit);
workers = h2_workers_create(s, pool, minw, maxw);
- int idle_secs = h2_config_geti(config, H2_CONF_MAX_WORKER_IDLE_SECS);
+ idle_secs = h2_config_geti(config, H2_CONF_MAX_WORKER_IDLE_SECS);
h2_workers_set_max_idle_secs(workers, idle_secs);
return status;
apr_status_t h2_conn_rprocess(request_rec *r)
{
h2_config *config = h2_config_rget(r);
+ h2_session *session;
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "h2_conn_process start");
if (!workers) {
return APR_EGENERAL;
}
- h2_session *session = h2_session_rcreate(r, config, workers);
+ session = h2_session_rcreate(r, config, workers);
if (!session) {
return APR_EGENERAL;
}
apr_status_t h2_conn_main(conn_rec *c)
{
h2_config *config = h2_config_get(c);
+ h2_session *session;
ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, c, "h2_conn_main start");
if (!workers) {
return APR_EGENERAL;
}
- h2_session *session = h2_session_create(c, config, workers);
+ session = h2_session_create(c, config, workers);
if (!session) {
return APR_EGENERAL;
}
{
apr_status_t status = APR_SUCCESS;
int rv = 0;
+ apr_interval_time_t wait_micros = 0;
+ static const int MAX_WAIT_MICROS = 200 * 1000;
/* Start talking to the client. Apart from protocol meta data,
* we mainly will see new http/2 streams opened by the client, which
return status;
}
- apr_interval_time_t wait_micros = 0;
- static const int MAX_WAIT_MICROS = 200 * 1000;
-
while (!h2_session_is_done(session)) {
int have_written = 0;
int have_read = 0;
+ int got_streams;
status = h2_session_write(session, wait_micros);
if (status == APR_SUCCESS) {
* * h2c will count the header settings as one frame and we
* submit our settings and need the ACK.
*/
- int got_streams = !h2_stream_set_is_empty(session->streams);
+ got_streams = !h2_stream_set_is_empty(session->streams);
status = h2_session_read(session,
(!got_streams
|| session->frames_received <= 1)?
conn_rec *h2_conn_create(conn_rec *master, apr_pool_t *pool)
{
apr_socket_t *socket;
+ conn_rec *c;
AP_DEBUG_ASSERT(master);
* TODO
*/
socket = ap_get_module_config(master->conn_config, &core_module);
- conn_rec *c = ap_run_create_connection(pool, master->base_server,
+ c = ap_run_create_connection(pool, master->base_server,
socket,
master->id^((long)pool),
master->sbh,
static apr_status_t flush_out(apr_bucket_brigade *bb, void *ctx)
{
h2_conn_io *io = (h2_conn_io*)ctx;
+ apr_status_t status;
ap_update_child_status(io->connection->sbh, SERVER_BUSY_WRITE, NULL);
- apr_status_t status = ap_pass_brigade(io->connection->output_filters, bb);
+ status = ap_pass_brigade(io->connection->output_filters, bb);
apr_brigade_cleanup(bb);
return status;
}
apr_status_t h2_conn_io_flush(h2_conn_io *io)
{
if (io->unflushed) {
+ apr_status_t status;
if (io->buflen > 0) {
+ apr_bucket *b;
ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, io->connection,
"h2_conn_io: flush, flushing %ld bytes", (long)io->buflen);
- apr_bucket *b = apr_bucket_transient_create(io->buffer, io->buflen,
+ b = apr_bucket_transient_create(io->buffer, io->buflen,
io->output->bucket_alloc);
APR_BRIGADE_INSERT_TAIL(io->output, b);
io->buflen = 0;
apr_bucket_flush_create(io->output->bucket_alloc));
/* Send it out through installed filters (TLS) to the client */
- apr_status_t status = flush_out(io->output, io);
+ status = flush_out(io->output, io);
if (status == APR_SUCCESS
|| APR_STATUS_IS_ECONNABORTED(status)
(void)f;
if (line[0] == ' ' || line[0] == '\t') {
+ char **plast;
/* continuation line from the header before this */
while (line[0] == ' ' || line[0] == '\t') {
++line;
}
- char **plast = apr_array_pop(from_h1->hlines);
+ plast = apr_array_pop(from_h1->hlines);
if (plast == NULL) {
/* not well formed */
return APR_EINVAL;
static apr_status_t get_line(h2_from_h1 *from_h1, apr_bucket_brigade *bb,
ap_filter_t* f, char *line, apr_size_t len)
{
+ apr_status_t status;
if (!from_h1->bb) {
from_h1->bb = apr_brigade_create(from_h1->pool, f->c->bucket_alloc);
}
else {
apr_brigade_cleanup(from_h1->bb);
}
- apr_status_t status = apr_brigade_split_line(from_h1->bb, bb,
+ status = apr_brigade_split_line(from_h1->bb, bb,
APR_BLOCK_READ,
HUGE_STRING_LEN);
if (status == APR_SUCCESS) {
apr_status_t status = APR_SUCCESS;
const char *clheader;
const char *ctype;
+ apr_table_t *headers;
/*
* Now that we are ready to send a response, we need to combine the two
* header field tables into a single table. If we don't do this, our
apr_table_unset(r->headers_out, "Content-Length");
}
- apr_table_t *headers = apr_table_make(r->pool, 10);
+ headers = apr_table_make(r->pool, 10);
set_basic_http_header(r, headers);
if (r->status == HTTP_NOT_MODIFIED) {
apr_size_t maxlen)
{
apr_off_t start_len = 0;
+ apr_bucket *last;
+ apr_status_t status;
if (!io->bbin || APR_BRIGADE_EMPTY(io->bbin)) {
return io->eos_in? APR_EOF : APR_EAGAIN;
}
apr_brigade_length(bb, 1, &start_len);
- apr_bucket *last = APR_BRIGADE_LAST(bb);
- apr_status_t status = h2_util_move(bb, io->bbin, maxlen, 0,
+ last = APR_BRIGADE_LAST(bb);
+ status = h2_util_move(bb, io->bbin, maxlen, 0,
"h2_io_in_read");
if (status == APR_SUCCESS) {
apr_bucket *nlast = APR_BRIGADE_LAST(bb);
{
h2_io *existing = h2_io_set_get(sp, io->id);
if (!existing) {
+ int last;
APR_ARRAY_PUSH(sp->list, h2_io*) = io;
/* Normally, streams get added in ascending order if id. We
* keep the array sorted, so we just need to check of the newly
* appended stream has a lower id than the last one. if not,
* sorting is not necessary.
*/
- int last = sp->list->nelts - 1;
+ last = sp->list->nelts - 1;
if (last > 0
&& (h2_io_IDX(sp->list, last)->id
< h2_io_IDX(sp->list, last-1)->id)) {
for (int i = 0; i < sp->list->nelts; ++i) {
h2_io *e = h2_io_IDX(sp->list, i);
if (e == io) {
+ int n;
--sp->list->nelts;
- int n = sp->list->nelts - i;
+ n = sp->list->nelts - i;
if (n > 0) {
/* Close the hole in the array by moving the upper
* parts down one step.
{
apr_status_t status = APR_SUCCESS;
h2_config *conf = h2_config_get(c);
+ apr_allocator_t *allocator = NULL;
+ h2_mplx *m;
AP_DEBUG_ASSERT(conf);
- apr_allocator_t *allocator = NULL;
status = apr_allocator_create(&allocator);
if (status != APR_SUCCESS) {
return NULL;
}
- h2_mplx *m = apr_pcalloc(parent, sizeof(h2_mplx));
+ m = apr_pcalloc(parent, sizeof(h2_mplx));
if (m) {
m->id = c->id;
APR_RING_ELEM_INIT(m, link);
apr_status_t h2_mplx_release_and_join(h2_mplx *m, apr_thread_cond_t *wait)
{
+ apr_status_t status;
workers_unregister(m);
- apr_status_t status = apr_thread_mutex_lock(m->lock);
+ status = apr_thread_mutex_lock(m->lock);
if (APR_SUCCESS == status) {
int attempts = 0;
void h2_mplx_abort(h2_mplx *m)
{
+ apr_status_t status;
AP_DEBUG_ASSERT(m);
- apr_status_t status = apr_thread_mutex_lock(m->lock);
+ status = apr_thread_mutex_lock(m->lock);
if (APR_SUCCESS == status) {
m->aborted = 1;
h2_io_set_destroy_all(m->stream_ios);
h2_stream *h2_mplx_open_io(h2_mplx *m, int stream_id)
{
h2_stream *stream = NULL;
+ apr_status_t status;
+ h2_io *io;
if (m->aborted) {
return NULL;
}
- apr_status_t status = apr_thread_mutex_lock(m->lock);
+ status = apr_thread_mutex_lock(m->lock);
if (APR_SUCCESS == status) {
apr_pool_t *stream_pool = m->spare_pool;
stream = h2_stream_create(stream_id, stream_pool, m);
stream->state = H2_STREAM_ST_OPEN;
- h2_io *io = h2_io_set_get(m->stream_ios, stream_id);
+ io = h2_io_set_get(m->stream_ios, stream_id);
if (!io) {
io = h2_io_create(stream_id, stream_pool, m->bucket_alloc);
h2_io_set_add(m->stream_ios, io);
apr_status_t h2_mplx_cleanup_stream(h2_mplx *m, h2_stream *stream)
{
+ apr_status_t status;
AP_DEBUG_ASSERT(m);
- apr_status_t status = apr_thread_mutex_lock(m->lock);
+ status = apr_thread_mutex_lock(m->lock);
if (APR_SUCCESS == status) {
h2_io *io = h2_io_set_get(m->stream_ios, stream->id);
if (!io || io->task_done) {
int stream_id, apr_bucket_brigade *bb,
struct apr_thread_cond_t *iowait)
{
+ apr_status_t status;
AP_DEBUG_ASSERT(m);
if (m->aborted) {
return APR_ECONNABORTED;
}
- apr_status_t status = apr_thread_mutex_lock(m->lock);
+ status = apr_thread_mutex_lock(m->lock);
if (APR_SUCCESS == status) {
h2_io *io = h2_io_set_get(m->stream_ios, stream_id);
if (io) {
apr_status_t h2_mplx_in_write(h2_mplx *m, int stream_id,
apr_bucket_brigade *bb)
{
+ apr_status_t status;
AP_DEBUG_ASSERT(m);
if (m->aborted) {
return APR_ECONNABORTED;
}
- apr_status_t status = apr_thread_mutex_lock(m->lock);
+ status = apr_thread_mutex_lock(m->lock);
if (APR_SUCCESS == status) {
h2_io *io = h2_io_set_get(m->stream_ios, stream_id);
if (io) {
apr_status_t h2_mplx_in_close(h2_mplx *m, int stream_id)
{
+ apr_status_t status;
AP_DEBUG_ASSERT(m);
if (m->aborted) {
return APR_ECONNABORTED;
}
- apr_status_t status = apr_thread_mutex_lock(m->lock);
+ status = apr_thread_mutex_lock(m->lock);
if (APR_SUCCESS == status) {
h2_io *io = h2_io_set_get(m->stream_ios, stream_id);
if (io) {
apr_status_t h2_mplx_in_update_windows(h2_mplx *m,
h2_mplx_consumed_cb *cb, void *cb_ctx)
{
+ apr_status_t status;
AP_DEBUG_ASSERT(m);
if (m->aborted) {
return APR_ECONNABORTED;
}
- apr_status_t status = apr_thread_mutex_lock(m->lock);
+ status = apr_thread_mutex_lock(m->lock);
if (APR_SUCCESS == status) {
update_ctx ctx = { cb, cb_ctx, 0 };
status = APR_EAGAIN;
h2_io_data_cb *cb, void *ctx,
apr_size_t *plen, int *peos)
{
+ apr_status_t status;
AP_DEBUG_ASSERT(m);
if (m->aborted) {
return APR_ECONNABORTED;
}
- apr_status_t status = apr_thread_mutex_lock(m->lock);
+ status = apr_thread_mutex_lock(m->lock);
if (APR_SUCCESS == status) {
h2_io *io = h2_io_set_get(m->stream_ios, stream_id);
if (io) {
h2_stream *h2_mplx_next_submit(h2_mplx *m, h2_stream_set *streams)
{
+ apr_status_t status;
+ h2_stream *stream = NULL;
AP_DEBUG_ASSERT(m);
if (m->aborted) {
return NULL;
}
- h2_stream *stream = NULL;
- apr_status_t status = apr_thread_mutex_lock(m->lock);
+ status = apr_thread_mutex_lock(m->lock);
if (APR_SUCCESS == status) {
h2_io *io = h2_io_set_get_highest_prio(m->ready_ios);
if (io) {
ap_filter_t* f, apr_bucket_brigade *bb,
struct apr_thread_cond_t *iowait)
{
+ apr_status_t status;
AP_DEBUG_ASSERT(m);
if (m->aborted) {
return APR_ECONNABORTED;
}
- apr_status_t status = apr_thread_mutex_lock(m->lock);
+ status = apr_thread_mutex_lock(m->lock);
if (APR_SUCCESS == status) {
status = out_open(m, stream_id, response, f, bb, iowait);
if (m->aborted) {
ap_filter_t* f, apr_bucket_brigade *bb,
struct apr_thread_cond_t *iowait)
{
+ apr_status_t status;
AP_DEBUG_ASSERT(m);
if (m->aborted) {
return APR_ECONNABORTED;
}
- apr_status_t status = apr_thread_mutex_lock(m->lock);
+ status = apr_thread_mutex_lock(m->lock);
if (APR_SUCCESS == status) {
if (!m->aborted) {
h2_io *io = h2_io_set_get(m->stream_ios, stream_id);
apr_status_t h2_mplx_out_close(h2_mplx *m, int stream_id)
{
+ apr_status_t status;
AP_DEBUG_ASSERT(m);
if (m->aborted) {
return APR_ECONNABORTED;
}
- apr_status_t status = apr_thread_mutex_lock(m->lock);
+ status = apr_thread_mutex_lock(m->lock);
if (APR_SUCCESS == status) {
if (!m->aborted) {
h2_io *io = h2_io_set_get(m->stream_ios, stream_id);
int h2_mplx_in_has_eos_for(h2_mplx *m, int stream_id)
{
+ int has_eos = 0;
+ apr_status_t status;
AP_DEBUG_ASSERT(m);
if (m->aborted) {
return 0;
}
- int has_eos = 0;
- apr_status_t status = apr_thread_mutex_lock(m->lock);
+ status = apr_thread_mutex_lock(m->lock);
if (APR_SUCCESS == status) {
h2_io *io = h2_io_set_get(m->stream_ios, stream_id);
if (io) {
int h2_mplx_out_has_data_for(h2_mplx *m, int stream_id)
{
+ apr_status_t status;
+ int has_data = 0;
AP_DEBUG_ASSERT(m);
if (m->aborted) {
return 0;
}
- int has_data = 0;
- apr_status_t status = apr_thread_mutex_lock(m->lock);
+ status = apr_thread_mutex_lock(m->lock);
if (APR_SUCCESS == status) {
h2_io *io = h2_io_set_get(m->stream_ios, stream_id);
if (io) {
apr_status_t h2_mplx_out_trywait(h2_mplx *m, apr_interval_time_t timeout,
apr_thread_cond_t *iowait)
{
+ apr_status_t status;
AP_DEBUG_ASSERT(m);
if (m->aborted) {
return APR_ECONNABORTED;
}
- apr_status_t status = apr_thread_mutex_lock(m->lock);
+ status = apr_thread_mutex_lock(m->lock);
if (APR_SUCCESS == status) {
m->added_output = iowait;
status = apr_thread_cond_timedwait(m->added_output, m->lock, timeout);
apr_status_t h2_mplx_do_task(h2_mplx *m, struct h2_task *task)
{
+ apr_status_t status;
AP_DEBUG_ASSERT(m);
if (m->aborted) {
return APR_ECONNABORTED;
}
- apr_status_t status = apr_thread_mutex_lock(m->lock);
+ status = apr_thread_mutex_lock(m->lock);
if (APR_SUCCESS == status) {
/* TODO: needs to sort queue by priority */
ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, m->c,
h2_task *h2_mplx_pop_task(h2_mplx *m, int *has_more)
{
h2_task *task = NULL;
+ apr_status_t status;
AP_DEBUG_ASSERT(m);
if (m->aborted) {
*has_more = 0;
return NULL;
}
- apr_status_t status = apr_thread_mutex_lock(m->lock);
+ status = apr_thread_mutex_lock(m->lock);
if (APR_SUCCESS == status) {
task = h2_tq_pop_first(m->q);
if (task) {
apr_status_t h2_mplx_create_task(h2_mplx *m, struct h2_stream *stream)
{
+ apr_status_t status;
AP_DEBUG_ASSERT(m);
if (m->aborted) {
return APR_ECONNABORTED;
}
- apr_status_t status = apr_thread_mutex_lock(m->lock);
+ status = apr_thread_mutex_lock(m->lock);
if (APR_SUCCESS == status) {
conn_rec *c = h2_conn_create(m->c, stream->pool);
apr_status_t h2_request_rwrite(h2_request *req, request_rec *r, h2_mplx *m)
{
+ apr_status_t status;
req->method = r->method;
req->path = r->uri;
req->authority = r->hostname;
req->scheme = NULL;
- apr_status_t status = insert_request_line(req, m);
+ status = insert_request_line(req, m);
if (status == APR_SUCCESS) {
status = h2_to_h1_add_headers(req->to_h1, r->headers_in);
}
static void convert_header(h2_response *response, apr_table_t *headers,
const char *status, request_rec *r)
{
+ size_t n;
+ h2_headers *h;
nvctx_t ctx = { NULL, 1, strlen(status) + 1, 0, NULL,
response, r? APLOGrdebug(r) : 0, r };
apr_table_do(count_headers, &ctx, headers, NULL);
- size_t n = (sizeof(h2_headers)
+ n = (sizeof(h2_headers)
+ (ctx.nvlen * sizeof(nghttp2_nv)) + ctx.nvstrlen);
- h2_headers *h = calloc(1, n);
+ /* XXX: Why calloc, Why not on the pool of the request? */
+ h = calloc(1, n);
if (h) {
ctx.nv = (nghttp2_nv*)(h + 1);
ctx.strbuf = (char*)&ctx.nv[ctx.nvlen];
static int stream_open(h2_session *session, int stream_id)
{
+ h2_stream * stream;
if (session->aborted) {
return NGHTTP2_ERR_CALLBACK_FAILURE;
}
- h2_stream * stream = h2_mplx_open_io(session->mplx, stream_id);
+ stream = h2_mplx_open_io(session->mplx, stream_id);
if (stream) {
h2_stream_set_add(session->streams, stream);
{
h2_session *session = (h2_session *)userp;
apr_status_t status = send_data(session, (const char *)data, length);
- (void)ngh2; (void)flags;
if (status == APR_SUCCESS) {
return length;
{
int rv;
h2_session *session = (h2_session *)userp;
- (void)flags;
+ h2_stream * stream;
+ apr_status_t status;
if (session->aborted) {
return NGHTTP2_ERR_CALLBACK_FAILURE;
}
- h2_stream * stream = h2_stream_set_get(session->streams, stream_id);
+ stream = h2_stream_set_get(session->streams, stream_id);
if (!stream) {
ap_log_cerror(APLOG_MARK, APLOG_ERR, 0, session->c,
"h2_session: stream(%ld-%d): on_data_chunk for unknown stream",
return 0;
}
- apr_status_t status = h2_stream_write_data(stream, (const char *)data, len);
+ status = h2_stream_write_data(stream, (const char *)data, len);
ap_log_cerror(APLOG_MARK, APLOG_TRACE1, status, session->c,
"h2_stream(%ld-%d): written DATA, length %d",
session->id, stream_id, (int)len);
uint32_t error_code, void *userp)
{
h2_session *session = (h2_session *)userp;
- (void)ngh2;
+ h2_stream *stream;
if (session->aborted) {
return NGHTTP2_ERR_CALLBACK_FAILURE;
}
- h2_stream *stream = h2_stream_set_get(session->streams, stream_id);
+ stream = h2_stream_set_get(session->streams, stream_id);
if (stream) {
stream_destroy(session, stream);
}
static int on_begin_headers_cb(nghttp2_session *ngh2,
const nghttp2_frame *frame, void *userp)
{
- (void)ngh2;
/* This starts a new stream. */
int rv = stream_open((h2_session *)userp, frame->hd.stream_id);
if (rv != NGHTTP2_ERR_CALLBACK_FAILURE) {
void *userp)
{
h2_session *session = (h2_session *)userp;
- (void)ngh2; (void)flags;
+ h2_stream * stream;
+ apr_status_t status;
if (session->aborted) {
return NGHTTP2_ERR_CALLBACK_FAILURE;
}
- h2_stream * stream = h2_stream_set_get(session->streams,
+ stream = h2_stream_set_get(session->streams,
frame->hd.stream_id);
if (!stream) {
ap_log_cerror(APLOG_MARK, APLOG_ERR, 0, session->c,
return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE;
}
- apr_status_t status = h2_stream_write_header(stream,
+ status = h2_stream_write_header(stream,
(const char *)name, namelen,
(const char *)value, valuelen);
if (status != APR_SUCCESS) {
{
int rv;
h2_session *session = (h2_session *)userp;
+ apr_status_t status = APR_SUCCESS;
if (session->aborted) {
return NGHTTP2_ERR_CALLBACK_FAILURE;
}
- apr_status_t status = APR_SUCCESS;
++session->frames_received;
ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, session->c,
(long)session->frames_received, frame->hd.type);
switch (frame->hd.type) {
case NGHTTP2_HEADERS: {
+ int eos;
h2_stream * stream = h2_stream_set_get(session->streams,
frame->hd.stream_id);
if (stream == NULL) {
return 0;
}
- int eos = (frame->hd.flags & NGHTTP2_FLAG_END_STREAM);
+ eos = (frame->hd.flags & NGHTTP2_FLAG_END_STREAM);
status = stream_end_headers(session, stream, eos);
break;
apr_pool_t *pool = NULL;
apr_status_t status = apr_pool_create(&pool, r? r->pool : c->pool);
+ h2_session *session;
if (status != APR_SUCCESS) {
return NULL;
}
- h2_session *session = apr_pcalloc(pool, sizeof(h2_session));
+ session = apr_pcalloc(pool, sizeof(h2_session));
if (session) {
+ int rv;
session->id = c->id;
session->c = c;
session->r = r;
return NULL;
}
- int rv = nghttp2_option_new(&options);
+ rv = nghttp2_option_new(&options);
if (rv != 0) {
ap_log_cerror(APLOG_MARK, APLOG_ERR, APR_EGENERAL, c,
"nghttp2_option_new: %s", nghttp2_strerror(rv));
apr_status_t h2_session_goaway(h2_session *session, apr_status_t reason)
{
- AP_DEBUG_ASSERT(session);
apr_status_t status = APR_SUCCESS;
+ int rv;
+ AP_DEBUG_ASSERT(session);
if (session->aborted) {
return APR_EINVAL;
}
- int rv = 0;
+ rv = 0;
if (reason == APR_SUCCESS) {
rv = nghttp2_submit_shutdown_notice(session->ngh2);
}
apr_status_t h2_session_start(h2_session *session, int *rv)
{
+ apr_status_t status = APR_SUCCESS;
+ h2_config *config;
+ nghttp2_settings_entry settings[3];
AP_DEBUG_ASSERT(session);
/* Start the conversation by submitting our SETTINGS frame */
- apr_status_t status = APR_SUCCESS;
*rv = 0;
- h2_config *config = h2_config_get(session->c);
+ config = h2_config_get(session->c);
if (session->r) {
+ const char *s, *cs;
+ apr_size_t dlen;
+ h2_stream * stream;
+
/* better for vhost matching */
config = h2_config_rget(session->r);
/* 'h2c' mode: we should have a 'HTTP2-Settings' header with
* base64 encoded client settings. */
- const char *s = apr_table_get(session->r->headers_in, "HTTP2-Settings");
+ s = apr_table_get(session->r->headers_in, "HTTP2-Settings");
if (!s) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, APR_EINVAL, session->r,
"HTTP2-Settings header missing in request");
return APR_EINVAL;
}
- unsigned char *cs = NULL;
- apr_size_t dlen = h2_util_base64url_decode(&cs, s, session->pool);
+ cs = NULL;
+ dlen = h2_util_base64url_decode(&cs, s, session->pool);
if (APLOGrdebug(session->r)) {
char buffer[128];
return status;
}
- h2_stream * stream = h2_stream_set_get(session->streams, 1);
+ stream = h2_stream_set_get(session->streams, 1);
if (stream == NULL) {
status = APR_EGENERAL;
ap_log_rerror(APLOG_MARK, APLOG_ERR, status, session->r,
}
}
- nghttp2_settings_entry settings[] = {
- { NGHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE,
- h2_config_geti(config, H2_CONF_MAX_HL_SIZE) },
- { NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE,
- h2_config_geti(config, H2_CONF_WIN_SIZE) },
- {NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS,
- (uint32_t)session->max_stream_count },
- };
+ settings[0].settings_id = NGHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE;
+ settings[0].value = h2_config_geti(config, H2_CONF_MAX_HL_SIZE);
+ settings[1].settings_id = NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE;
+ settings[1].value = h2_config_geti(config, H2_CONF_WIN_SIZE);
+ settings[2].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS;
+ settings[2].value = (uint32_t)session->max_stream_count;
+
*rv = nghttp2_submit_settings(session->ngh2, NGHTTP2_FLAG_NONE,
settings,
sizeof(settings)/sizeof(settings[0]));
if (h2_stream_is_suspended(stream)) {
if (h2_mplx_out_has_data_for(stream->m, stream->id)) {
+ int rv;
h2_stream_set_suspended(stream, 0);
++rctx->resume_count;
- int rv = nghttp2_session_resume_data(session->ngh2, stream->id);
+ rv = nghttp2_session_resume_data(session->ngh2, stream->id);
ap_log_cerror(APLOG_MARK, nghttp2_is_fatal(rv)?
APLOG_ERR : APLOG_DEBUG, 0, session->c,
"h2_stream(%ld-%d): resuming stream %s",
}
if (h2_session_want_write(session)) {
+ int rv;
status = APR_SUCCESS;
- int rv = nghttp2_session_send(session->ngh2);
+ rv = nghttp2_session_send(session->ngh2);
if (rv != 0) {
ap_log_cerror( APLOG_MARK, APLOG_DEBUG, 0, session->c,
"h2_session: send: %s", nghttp2_strerror(rv));
}
if (h2_session_want_write(session)) {
+ int rv;
status = APR_SUCCESS;
- int rv = nghttp2_session_send(session->ngh2);
+ rv = nghttp2_session_send(session->ngh2);
if (rv != 0) {
ap_log_cerror( APLOG_MARK, APLOG_DEBUG, 0, session->c,
"h2_session: send2: %s", nghttp2_strerror(rv));
void *puser)
{
h2_session *session = (h2_session *)puser;
+ apr_size_t nread = length;
+ int eos = 0;
+ apr_status_t status;
+ h2_stream *stream;
AP_DEBUG_ASSERT(session);
- (void)ng2s;(void)source;(void)buf;
- h2_stream *stream = h2_stream_set_get(session->streams, stream_id);
+ stream = h2_stream_set_get(session->streams, stream_id);
if (!stream) {
ap_log_cerror(APLOG_MARK, APLOG_ERR, APR_NOTFOUND, session->c,
"h2_stream(%ld-%d): data requested but stream not found",
}
AP_DEBUG_ASSERT(!h2_stream_is_suspended(stream));
- apr_size_t nread = length;
- int eos = 0;
- apr_status_t status = h2_stream_prep_read(stream, &nread, &eos);
+ status = h2_stream_prep_read(stream, &nread, &eos);
if (nread) {
*data_flags |= NGHTTP2_DATA_FLAG_NO_COPY;
}
static int submit_response(h2_session *session, h2_response *response)
{
+ int rv;
nghttp2_data_provider provider = {
(nghttp2_data_source) response->stream_id,
(nghttp2_data_source_read_callback) stream_data_cb
"h2_stream(%ld-%d): submitting response %s",
session->id, response->stream_id, response->headers->status);
- int rv = nghttp2_submit_response(session->ngh2, response->stream_id,
+ rv = nghttp2_submit_response(session->ngh2, response->stream_id,
response->headers->nv,
response->headers->nvlen, &provider);
*/
apr_status_t h2_session_handle_response(h2_session *session, h2_stream *stream)
{
+ apr_status_t status = APR_SUCCESS;
+ int rv = 0;
AP_DEBUG_ASSERT(session);
AP_DEBUG_ASSERT(stream);
AP_DEBUG_ASSERT(stream->response);
- apr_status_t status = APR_SUCCESS;
- int rv = 0;
if (stream->response->headers) {
rv = submit_response(session, stream->response);
}
apr_status_t h2_stream_rwrite(h2_stream *stream, request_rec *r)
{
+ apr_status_t status;
AP_DEBUG_ASSERT(stream);
set_state(stream, H2_STREAM_ST_OPEN);
- apr_status_t status = h2_request_rwrite(stream->request, r, stream->m);
+ status = h2_request_rwrite(stream->request, r, stream->m);
return status;
}
* by bsearch.
*/
h2_stream key;
+ h2_stream *pkey, **ps;
memset(&key, 0, sizeof(key));
key.id = stream_id;
- h2_stream *pkey = &key;
- h2_stream **ps = bsearch(&pkey, sp->list->elts, sp->list->nelts,
+ pkey = &key;
+ ps = bsearch(&pkey, sp->list->elts, sp->list->nelts,
sp->list->elt_size, h2_stream_id_cmp);
return ps? *ps : NULL;
}
{
h2_stream *existing = h2_stream_set_get(sp, stream->id);
if (!existing) {
+ int last;
APR_ARRAY_PUSH(sp->list, h2_stream*) = stream;
/* Normally, streams get added in ascending order if id. We
* keep the array sorted, so we just need to check of the newly
* appended stream has a lower id than the last one. if not,
* sorting is not necessary.
*/
- int last = sp->list->nelts - 1;
+ last = sp->list->nelts - 1;
if (last > 0
&& (H2_STREAM_IDX(sp->list, last)->id
< H2_STREAM_IDX(sp->list, last-1)->id)) {
for (int i = 0; i < sp->list->nelts; ++i) {
h2_stream *s = H2_STREAM_IDX(sp->list, i);
if (s == stream) {
+ int n;
--sp->list->nelts;
- int n = sp->list->nelts - i;
+ n = sp->list->nelts - i;
if (n > 0) {
/* Close the hole in the array by moving the upper
* parts down one step.
static int h2_task_pre_conn(conn_rec* c, void *arg)
{
- (void)arg;
h2_ctx *ctx = h2_ctx_get(c);
if (h2_ctx_is_task(ctx)) {
h2_task_output *h2_task_output_create(h2_task_env *env, apr_pool_t *pool,
apr_bucket_alloc_t *bucket_alloc)
{
- (void)bucket_alloc;
h2_task_output *output = apr_pcalloc(pool, sizeof(h2_task_output));
if (output) {
output->env = env;
apr_bucket_brigade *bb)
{
if (output->state == H2_TASK_OUT_INIT) {
+ h2_response *response;
output->state = H2_TASK_OUT_STARTED;
- h2_response *response = h2_from_h1_get_response(output->from_h1);
+ response = h2_from_h1_get_response(output->from_h1);
if (!response) {
if (f) {
/* This happens currently when ap_die(status, r) is invoked
apr_status_t h2_task_output_write(h2_task_output *output,
ap_filter_t* f, apr_bucket_brigade* bb)
{
+ apr_status_t status;
if (APR_BRIGADE_EMPTY(bb)) {
ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, f->c,
"h2_task_output(%s): empty write", output->env->id);
return APR_SUCCESS;
}
- apr_status_t status = open_if_needed(output, f, bb);
+ status = open_if_needed(output, f, bb);
if (status != APR_EOF) {
ap_log_cerror(APLOG_MARK, APLOG_TRACE1, status, f->c,
"h2_task_output(%s): opened and passed brigade",
const char *method, const char *path,
const char *authority, struct h2_mplx *m)
{
+ h2_to_h1 *to_h1;
if (!method) {
ap_log_cerror(APLOG_MARK, APLOG_ERR, 0, m->c,
"h2_to_h1: header start but :method missing");
return NULL;
}
- h2_to_h1 *to_h1 = apr_pcalloc(pool, sizeof(h2_to_h1));
+ to_h1 = apr_pcalloc(pool, sizeof(h2_to_h1));
if (to_h1) {
to_h1->stream_id = stream_id;
to_h1->pool = pool;
const char *name, size_t nlen,
const char *value, size_t vlen)
{
+ char *hname, *hvalue;
if (H2_HD_MATCH_LIT("transfer-encoding", name, nlen)) {
if (!apr_strnatcasecmp("chunked", value)) {
/* This should never arrive here in a HTTP/2 request */
to_h1->seen_host = 1;
}
- char *hname = apr_pstrndup(to_h1->pool, name, nlen);
- char *hvalue = apr_pstrndup(to_h1->pool, value, vlen);
+ hname = apr_pstrndup(to_h1->pool, name, nlen);
+ hvalue = apr_pstrndup(to_h1->pool, value, vlen);
h2_util_camel_case_header(hname, nlen);
apr_table_mergen(to_h1->headers, hname, hvalue);
/* Check for the start of an h2c Upgrade dance. */
const char *proto = h2_get_upgrade_proto(r);
if (proto) {
+ const char *clen;
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
"seeing %s upgrade invitation", proto);
/* We do not handle upgradeable requests with a body.
* This seems to be consensus among server implemntations and
* clients are advised to use an "OPTIONS *" before a POST.
*/
- const char *clen = apr_table_get(r->headers_in, "Content-Length");
+ clen = apr_table_get(r->headers_in, "Content-Length");
if (clen && strcmp(clen, "0")) {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
"upgrade with content-length: %s, declined", clen);
{
conn_rec *c = r->connection;
h2_ctx *ctx = h2_ctx_rget(r);
+ apr_status_t status;
h2_ctx_pnego_set_done(ctx, proto);
ap_remove_input_filter_byhandle(r->input_filters, "reqtimeout");
/* Ok, start an h2_conn on this one. */
- apr_status_t status = h2_conn_rprocess(r);
+ status = h2_conn_rprocess(r);
if (status != DONE) {
/* Nothing really to do about this. */
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r,
{
const unsigned char *e = (const unsigned char *)encoded;
const unsigned char *p = e;
+ unsigned char *d;
int n;
+ apr_size_t len, mlen, remain, i;
while (*p && BASE64URL_TABLE[ *p ] == -1) {
++p;
}
- apr_size_t len = p - e;
- apr_size_t mlen = (len/4)*4;
+ len = p - e;
+ mlen = (len/4)*4;
*decoded = apr_pcalloc(pool, len+1);
- apr_size_t i = 0;
- unsigned char *d = *decoded;
+ i = 0;
+ d = *decoded;
for (; i < mlen; i += 4) {
n = ((BASE64URL_TABLE[ e[i+0] ] << 18) +
(BASE64URL_TABLE[ e[i+1] ] << 12) +
*d++ = n >> 8 & 0xffu;
*d++ = n & 0xffu;
}
- apr_size_t remain = len - mlen;
+ remain = len - mlen;
switch (remain) {
case 2:
n = ((BASE64URL_TABLE[ e[mlen+0] ] << 18) +
const char *msg)
{
apr_status_t status = APR_SUCCESS;
+ int same_alloc;
AP_DEBUG_ASSERT(to);
AP_DEBUG_ASSERT(from);
- int same_alloc = (to->bucket_alloc == from->bucket_alloc);
+ same_alloc = (to->bucket_alloc == from->bucket_alloc);
if (!FILE_MOVE) {
pfile_handles_allowed = NULL;
apr_size_t maxlen, const char *msg)
{
apr_status_t status = APR_SUCCESS;
- (void)msg;
+ int same_alloc;
AP_DEBUG_ASSERT(to);
AP_DEBUG_ASSERT(from);
- int same_alloc = (to->bucket_alloc == from->bucket_alloc);
+ same_alloc = (to->bucket_alloc == from->bucket_alloc);
if (!APR_BRIGADE_EMPTY(from)) {
apr_bucket *b, *end, *cpy;
{
apr_allocator_t *allocator = NULL;
apr_pool_t *pool = NULL;
+ h2_worker *w;
apr_status_t status = apr_allocator_create(&allocator);
if (status != APR_SUCCESS) {
}
apr_allocator_owner_set(allocator, pool);
- h2_worker *w = apr_pcalloc(pool, sizeof(h2_worker));
+ w = apr_pcalloc(pool, sizeof(h2_worker));
if (w) {
APR_RING_ELEM_INIT(w, link);
h2_workers *h2_workers_create(server_rec *s, apr_pool_t *pool,
int min_size, int max_size)
{
+ apr_status_t status;
+ h2_workers *workers;
AP_DEBUG_ASSERT(s);
AP_DEBUG_ASSERT(pool);
- apr_status_t status = APR_SUCCESS;
+ status = APR_SUCCESS;
- h2_workers *workers = apr_pcalloc(pool, sizeof(h2_workers));
+ workers = apr_pcalloc(pool, sizeof(h2_workers));
if (workers) {
workers->s = s;
workers->pool = pool;
*/
static void h2_hooks(apr_pool_t *pool)
{
- ap_log_perror(APLOG_MARK, APLOG_INFO, 0, pool, "installing hooks");
-
static const char *const mod_ssl[] = { "mod_ssl.c", NULL};
+ ap_log_perror(APLOG_MARK, APLOG_INFO, 0, pool, "installing hooks");
+
/* Run once after configuration is set, but before mpm children initialize.
*/
ap_hook_post_config(h2_post_config, mod_ssl, NULL, APR_HOOK_MIDDLE);