source: mod_gnutls/src/gnutls_cache.h

mod_gnutls/0.9.1
Last change on this file was 3aff94d, checked in by Fiona Klute <fiona.klute@…>, 14 months ago

Include cache status in mod_status reports

  • Property mode set to 100644
File size: 5.5 KB
RevLine 
[14548b9]1/*
[04e6e65]2 *  Copyright 2004-2005 Paul Querna
3 *  Copyright 2014 Nikos Mavrogiannopoulos
[a85de63]4 *  Copyright 2015-2018 Fiona Klute
[04e6e65]5 *
6 *  Licensed under the Apache License, Version 2.0 (the "License");
7 *  you may not use this file except in compliance with the License.
8 *  You may obtain a copy of the License at
9 *
10 *      http://www.apache.org/licenses/LICENSE-2.0
11 *
12 *  Unless required by applicable law or agreed to in writing, software
13 *  distributed under the License is distributed on an "AS IS" BASIS,
14 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 *  See the License for the specific language governing permissions and
16 *  limitations under the License.
[14548b9]17 */
18
19/**
20 * @file
[04e6e65]21 *
[104e881]22 * Generic object cache for mod_gnutls.
[04e6e65]23 */
24
25#ifndef __MOD_GNUTLS_CACHE_H__
26#define __MOD_GNUTLS_CACHE_H__
27
28#include "mod_gnutls.h"
29#include <httpd.h>
[de1ceab]30#include <ap_socache.h>
[04e6e65]31
[14548b9]32/** Name of the mod_gnutls cache access mutex, for use with Apache's
33 * `Mutex` directive */
[c005645]34#define MGS_CACHE_MUTEX_NAME "gnutls-cache"
35
[04e6e65]36/**
[ce5f776]37 * Configure a cache instance
38 *
39 * This function is supposed to be called during config and
40 * initializes an mgs_cache_t by finding the named socache provider
41 * and creating a cache instance with the given configuration. Note
42 * that the socache instance is only created, not initialized, which
43 * is supposed to happen during post_config.
44 *
[3358887]45 * @param cache pointer to the mgs_cache_t, will be assigned only if
46 * configuration succeeds
[ce5f776]47 *
48 * @param server associated server for logging purposes
49 *
50 * @param type socache provider type
51 *
52 * @param config configuration string for the socache provider, may be
53 * `NULL` if the provider accepts an empty configuration
54 *
[3358887]55 * @param pconf configuration memory pool, used to store cache
56 * configuration
[ce5f776]57 *
58 * @param ptemp temporary memory pool
59 */
60const char *mgs_cache_inst_config(mgs_cache_t *cache, server_rec *server,
61                                  const char* type, const char* config,
62                                  apr_pool_t *pconf, apr_pool_t *ptemp);
63
64/**
[14548b9]65 * Initialize the internal cache configuration structure. This
66 * function is called after the configuration file(s) have been
67 * parsed.
[104e881]68 *
[de1ceab]69 * @param pconf configuration memory pool
70 * @param ptemp temporary memory pool
[104e881]71 * @param s default server of the Apache configuration, head of the
72 * server list
73 * @param sc mod_gnutls data associated with `s`
[04e6e65]74 */
[de1ceab]75int mgs_cache_post_config(apr_pool_t *pconf, apr_pool_t *ptemp,
76                          server_rec *s, mgs_srvconf_rec *sc);
[04e6e65]77
78/**
[104e881]79 * (Re-)Initialize the cache in a child process after forking.
80 *
81 * @param p child memory pool provided by Apache
82 * @param s default server of the Apache configuration, head of the
83 * server list
[babdb29]84 * @param cache the cache to reinit
85 * @param mutex_name name of the mutex associated with the cache for
86 * logging purposes
[04e6e65]87 */
[babdb29]88int mgs_cache_child_init(apr_pool_t *p, server_rec *server,
89                         mgs_cache_t cache, const char *mutex_name);
[04e6e65]90
91/**
[104e881]92 * Set up caching for the given TLS session.
[14548b9]93 *
94 * @param ctxt mod_gnutls session context
[104e881]95 *
[14548b9]96 * @return 0
[04e6e65]97 */
98int mgs_cache_session_init(mgs_handle_t *ctxt);
99
100
101
102/**
[14548b9]103 * Convert a `time_t` into a null terminated string in a format
[104e881]104 * compatible with OpenSSL's `ASN1_TIME_print()`.
[0831437]105 *
[04e6e65]106 * @param t time_t time
[0831437]107 * @param str Location to store the time string
[14548b9]108 * @param strsize The maximum length that can be stored in `str`
[104e881]109 *
[14548b9]110 * @return `str`
[04e6e65]111 */
112char *mgs_time2sz(time_t t, char *str, int strsize);
113
[14548b9]114/**
[ded2291]115 * Store function for the mod_gnutls object caches.
[14548b9]116 *
[ded2291]117 * @param cache the cache to store the entry in
[14548b9]118 * @param s server associated with the cache entry
119 * @param key key for the cache entry
120 * @param data data to be cached
121 * @param expiry expiration time
[104e881]122 *
123 * @return `-1` on error, `0` on success
[6b4136c]124 */
[ded2291]125int mgs_cache_store(mgs_cache_t cache, server_rec *server, gnutls_datum_t key,
126                    gnutls_datum_t data, apr_time_t expiry);
127
[14548b9]128/**
[ded2291]129 * Fetch function for the mod_gnutls object caches.
[104e881]130 *
131 * *Warning*: The `data` element of the returned `gnutls_datum_t` is
132 * allocated using `gnutls_malloc()` for compatibility with the GnuTLS
133 * session caching API, and must be released using `gnutls_free()`.
[14548b9]134 *
[ded2291]135 * @param cache the cache to fetch from
136 *
[a85de63]137 * @param server server context for the request
138 *
[14548b9]139 * @param key key for the cache entry to be fetched
[104e881]140 *
[a85de63]141 * @param pool pool to allocate the response and other temporary
142 * memory from
143 *
[14548b9]144 * @return the requested cache entry, or `{NULL, 0}`
145 */
[ded2291]146gnutls_datum_t mgs_cache_fetch(mgs_cache_t cache, server_rec *server,
147                               gnutls_datum_t key, apr_pool_t *pool);
148
[14548b9]149/**
150 * Internal cache configuration structure
151 */
[e809fb3]152struct mgs_cache {
[de1ceab]153    /** Socache provider to use for this cache */
154    const ap_socache_provider_t *prov;
155    /** The actual socache instance */
156    ap_socache_instance_t *socache;
[a314ec9]157    /** Cache configuration string (as passed to the socache create
158     * function, for logging) */
159    const char *config;
[14548b9]160    /** Mutex for cache access (used only if the cache type is not
[aa68232]161     * thread-safe) */
162    apr_global_mutex_t *mutex;
[e809fb3]163};
[6b4136c]164
[3aff94d]165/**
166 * Write cache status to a mod_status report
167 *
168 * @param cache the cache to report on
169 *
170 * @param header_title string to prefix the report with to distinguish
171 * caches
172 *
173 * @param r status output is added to the response for this request
174 *
175 * @param flags request flags, used to toggle "short status" mode
176 *
177 * @return request status, currently always `OK`
178 */
179int mgs_cache_status(mgs_cache_t cache, const char *header_title,
180                     request_rec *r, int flags);
181
[04e6e65]182#endif /** __MOD_GNUTLS_CACHE_H__ */
Note: See TracBrowser for help on using the repository browser.