Blame modules/http2/h2_ctx.c

Packit 90a5c9
/* Licensed to the Apache Software Foundation (ASF) under one or more
Packit 90a5c9
 * contributor license agreements.  See the NOTICE file distributed with
Packit 90a5c9
 * this work for additional information regarding copyright ownership.
Packit 90a5c9
 * The ASF licenses this file to You under the Apache License, Version 2.0
Packit 90a5c9
 * (the "License"); you may not use this file except in compliance with
Packit 90a5c9
 * the License.  You may obtain a copy of the License at
Packit 90a5c9
 *
Packit 90a5c9
 *     http://www.apache.org/licenses/LICENSE-2.0
Packit 90a5c9
 *
Packit 90a5c9
 * Unless required by applicable law or agreed to in writing, software
Packit 90a5c9
 * distributed under the License is distributed on an "AS IS" BASIS,
Packit 90a5c9
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Packit 90a5c9
 * See the License for the specific language governing permissions and
Packit 90a5c9
 * limitations under the License.
Packit 90a5c9
 */
Packit 90a5c9
 
Packit 90a5c9
#include <assert.h>
Packit 90a5c9
Packit 90a5c9
#include <httpd.h>
Packit 90a5c9
#include <http_core.h>
Packit 90a5c9
#include <http_config.h>
Packit 90a5c9
Packit 90a5c9
#include "h2_private.h"
Packit 90a5c9
#include "h2_session.h"
Packit 90a5c9
#include "h2_task.h"
Packit 90a5c9
#include "h2_ctx.h"
Packit 90a5c9
Packit 90a5c9
static h2_ctx *h2_ctx_create(const conn_rec *c)
Packit 90a5c9
{
Packit 90a5c9
    h2_ctx *ctx = apr_pcalloc(c->pool, sizeof(h2_ctx));
Packit 90a5c9
    ap_assert(ctx);
Packit 90a5c9
    ap_set_module_config(c->conn_config, &http2_module, ctx);
Packit 90a5c9
    h2_ctx_server_set(ctx, c->base_server);
Packit 90a5c9
    return ctx;
Packit 90a5c9
}
Packit 90a5c9
Packit 90a5c9
void h2_ctx_clear(const conn_rec *c)
Packit 90a5c9
{
Packit 90a5c9
    ap_assert(c);
Packit 90a5c9
    ap_set_module_config(c->conn_config, &http2_module, NULL);
Packit 90a5c9
}
Packit 90a5c9
Packit 90a5c9
h2_ctx *h2_ctx_create_for(const conn_rec *c, h2_task *task)
Packit 90a5c9
{
Packit 90a5c9
    h2_ctx *ctx = h2_ctx_create(c);
Packit 90a5c9
    if (ctx) {
Packit 90a5c9
        ctx->task = task;
Packit 90a5c9
    }
Packit 90a5c9
    return ctx;
Packit 90a5c9
}
Packit 90a5c9
Packit 90a5c9
h2_ctx *h2_ctx_get(const conn_rec *c, int create)
Packit 90a5c9
{
Packit 90a5c9
    h2_ctx *ctx = (h2_ctx*)ap_get_module_config(c->conn_config, &http2_module);
Packit 90a5c9
    if (ctx == NULL && create) {
Packit 90a5c9
        ctx = h2_ctx_create(c);
Packit 90a5c9
    }
Packit 90a5c9
    return ctx;
Packit 90a5c9
}
Packit 90a5c9
Packit 90a5c9
h2_ctx *h2_ctx_rget(const request_rec *r)
Packit 90a5c9
{
Packit 90a5c9
    return h2_ctx_get(r->connection, 0);
Packit 90a5c9
}
Packit 90a5c9
Packit 90a5c9
const char *h2_ctx_protocol_get(const conn_rec *c)
Packit 90a5c9
{
Packit 90a5c9
    h2_ctx *ctx;
Packit 90a5c9
    if (c->master) {
Packit 90a5c9
        c = c->master;
Packit 90a5c9
    }
Packit 90a5c9
    ctx = (h2_ctx*)ap_get_module_config(c->conn_config, &http2_module);
Packit 90a5c9
    return ctx? ctx->protocol : NULL;
Packit 90a5c9
}
Packit 90a5c9
Packit 90a5c9
h2_ctx *h2_ctx_protocol_set(h2_ctx *ctx, const char *proto)
Packit 90a5c9
{
Packit 90a5c9
    ctx->protocol = proto;
Packit 90a5c9
    return ctx;
Packit 90a5c9
}
Packit 90a5c9
Packit 90a5c9
h2_session *h2_ctx_session_get(h2_ctx *ctx)
Packit 90a5c9
{
Packit 90a5c9
    return ctx? ctx->session : NULL;
Packit 90a5c9
}
Packit 90a5c9
Packit 90a5c9
void h2_ctx_session_set(h2_ctx *ctx, struct h2_session *session)
Packit 90a5c9
{
Packit 90a5c9
    ctx->session = session;
Packit 90a5c9
}
Packit 90a5c9
Packit 90a5c9
server_rec *h2_ctx_server_get(h2_ctx *ctx)
Packit 90a5c9
{
Packit 90a5c9
    return ctx? ctx->server : NULL;
Packit 90a5c9
}
Packit 90a5c9
Packit 90a5c9
h2_ctx *h2_ctx_server_set(h2_ctx *ctx, server_rec *s)
Packit 90a5c9
{
Packit 90a5c9
    ctx->server = s;
Packit 90a5c9
    return ctx;
Packit 90a5c9
}
Packit 90a5c9
Packit 90a5c9
int h2_ctx_is_task(h2_ctx *ctx)
Packit 90a5c9
{
Packit 90a5c9
    return ctx && ctx->task;
Packit 90a5c9
}
Packit 90a5c9
Packit 90a5c9
h2_task *h2_ctx_get_task(h2_ctx *ctx)
Packit 90a5c9
{
Packit 90a5c9
    return ctx? ctx->task : NULL;
Packit 90a5c9
}
Packit 90a5c9
Packit 90a5c9
h2_task *h2_ctx_cget_task(conn_rec *c)
Packit 90a5c9
{
Packit 90a5c9
    return h2_ctx_get_task(h2_ctx_get(c, 0));
Packit 90a5c9
}
Packit 90a5c9
Packit 90a5c9
h2_task *h2_ctx_rget_task(request_rec *r)
Packit 90a5c9
{
Packit 90a5c9
    return h2_ctx_get_task(h2_ctx_rget(r));
Packit 90a5c9
}