static int h2_alt_svc_handler(request_rec *r)
{
- h2_ctx *ctx;
const h2_config *cfg;
int i;
return DECLINED;
}
- ctx = h2_ctx_rget(r);
- if (h2_ctx_is_active(ctx) || h2_ctx_is_task(ctx)) {
+ if (h2_ctx_rget(r)) {
return DECLINED;
}
const h2_config *h2_config_get(conn_rec *c)
{
- h2_ctx *ctx = h2_ctx_get(c);
+ h2_ctx *ctx = h2_ctx_get(c, 0);
- if (ctx->config) {
- return ctx->config;
- }
- else if (ctx->server) {
- ctx->config = h2_config_sget(ctx->server);
- return ctx->config;
+ if (ctx) {
+ if (ctx->config) {
+ return ctx->config;
+ }
+ else if (ctx->server) {
+ ctx->config = h2_config_sget(ctx->server);
+ return ctx->config;
+ }
}
return h2_config_sget(c->base_server);
#include <http_config.h>
#include "h2_private.h"
+#include "h2_session.h"
#include "h2_task.h"
#include "h2_ctx.h"
#include "h2_private.h"
return ctx;
}
-h2_ctx *h2_ctx_get(const conn_rec *c)
+h2_ctx *h2_ctx_get(const conn_rec *c, int create)
{
h2_ctx *ctx = (h2_ctx*)ap_get_module_config(c->conn_config, &http2_module);
- if (ctx == NULL) {
+ if (ctx == NULL && create) {
ctx = h2_ctx_create(c);
}
return ctx;
h2_ctx *h2_ctx_rget(const request_rec *r)
{
- return h2_ctx_get(r->connection);
+ return h2_ctx_get(r->connection, 0);
}
const char *h2_ctx_protocol_get(const conn_rec *c)
h2_ctx *h2_ctx_protocol_set(h2_ctx *ctx, const char *proto)
{
ctx->protocol = proto;
- ctx->is_h2 = (proto != NULL);
return ctx;
}
+h2_session *h2_ctx_session_get(h2_ctx *ctx)
+{
+ return ctx? ctx->session : NULL;
+}
+
+void h2_ctx_session_set(h2_ctx *ctx, struct h2_session *session)
+{
+ ctx->session = session;
+}
+
h2_ctx *h2_ctx_server_set(h2_ctx *ctx, server_rec *s)
{
ctx->server = s;
return ctx && !!ctx->task;
}
-int h2_ctx_is_active(h2_ctx *ctx)
-{
- return ctx && ctx->is_h2;
-}
-
struct h2_task *h2_ctx_get_task(h2_ctx *ctx)
{
- return ctx->task;
+ return ctx? ctx->task : NULL;
}
#ifndef __mod_h2__h2_ctx__
#define __mod_h2__h2_ctx__
+struct h2_session;
struct h2_task;
struct h2_config;
* - those created by ourself to perform work on HTTP/2 streams
*/
typedef struct h2_ctx {
- int is_h2; /* h2 engine is used */
const char *protocol; /* the protocol negotiated */
+ struct h2_session *session; /* the session established */
struct h2_task *task; /* the h2_task executing or NULL */
const char *hostname; /* hostname negotiated via SNI, optional */
server_rec *server; /* httpd server config selected. */
const struct h2_config *config; /* effective config in this context */
} h2_ctx;
-h2_ctx *h2_ctx_get(const conn_rec *c);
+/**
+ * Get (or create) a h2 context record for this connection.
+ * @param c the connection to look at
+ * @param create != 0 iff missing context shall be created
+ * @return h2 context of this connection
+ */
+h2_ctx *h2_ctx_get(const conn_rec *c, int create);
+
h2_ctx *h2_ctx_rget(const request_rec *r);
h2_ctx *h2_ctx_create_for(const conn_rec *c, struct h2_task *task);
*/
h2_ctx *h2_ctx_server_set(h2_ctx *ctx, server_rec *s);
+struct h2_session *h2_ctx_session_get(h2_ctx *ctx);
+void h2_ctx_session_set(h2_ctx *ctx, struct h2_session *session);
+
/**
* Get the h2 protocol negotiated for this connection, or NULL.
*/
const char *h2_ctx_protocol_get(const conn_rec *c);
int h2_ctx_is_task(h2_ctx *ctx);
-int h2_ctx_is_active(h2_ctx *ctx);
struct h2_task *h2_ctx_get_task(h2_ctx *ctx);
int h2_h2_process_conn(conn_rec* c)
{
- h2_ctx *ctx = h2_ctx_get(c);
+ h2_ctx *ctx;
+ if (c->master) {
+ return DECLINED;
+ }
+
+ ctx = h2_ctx_get(c, 0);
ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, c, "h2_h2, process_conn");
if (h2_ctx_is_task(ctx)) {
/* our stream pseudo connection */
if ((slen >= 24) && !memcmp(H2_MAGIC_TOKEN, s, 24)) {
ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, c,
"h2_h2, direct mode detected");
+ if (!ctx) {
+ ctx = h2_ctx_get(c, 1);
+ }
h2_ctx_protocol_set(ctx, h2_h2_is_tls(c)? "h2" : "h2c");
}
else {
/* If "h2" was selected as protocol (by whatever mechanism), take over
* the connection.
*/
- if (h2_ctx_is_active(ctx)) {
+ if (ctx) {
ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, c,
"h2_h2, connection, h2 active");
}
if (found) {
- h2_ctx *ctx = h2_ctx_get(c);
+ h2_ctx *ctx = h2_ctx_get(c, 1);
ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, c,
"switching protocol to '%s'", protocol);
static int h2_task_pre_conn(conn_rec* c, void *arg)
{
- h2_ctx *ctx = h2_ctx_get(c);
+ h2_ctx *ctx;
+ if (!c->master) {
+ return OK;
+ }
+
+ ctx = h2_ctx_get(c, 0);
(void)arg;
if (h2_ctx_is_task(ctx)) {
h2_task *task = h2_ctx_get_task(ctx);
static int h2_task_process_conn(conn_rec* c)
{
- h2_ctx *ctx = h2_ctx_get(c);
+ h2_ctx *ctx;
+
+ if (!c->master) {
+ return DECLINED;
+ }
+ ctx = h2_ctx_get(c, 0);
if (h2_ctx_is_task(ctx)) {
if (!ctx->task->serialize_headers) {
ap_log_cerror(APLOG_MARK, APLOG_TRACE2, 0, c,