Blame include/ap_socache.h

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
/**
Packit 90a5c9
 * @file ap_socache.h
Packit 90a5c9
 * @brief Small object cache provider interface.
Packit 90a5c9
 *
Packit 90a5c9
 * @defgroup AP_SOCACHE ap_socache
Packit 90a5c9
 * @ingroup  APACHE_MODS
Packit 90a5c9
 * @{
Packit 90a5c9
 */
Packit 90a5c9
Packit 90a5c9
#ifndef AP_SOCACHE_H
Packit 90a5c9
#define AP_SOCACHE_H
Packit 90a5c9
Packit 90a5c9
#include "httpd.h"
Packit 90a5c9
#include "ap_provider.h"
Packit 90a5c9
#include "apr_pools.h"
Packit 90a5c9
#include "apr_time.h"
Packit 90a5c9
Packit 90a5c9
#ifdef __cplusplus
Packit 90a5c9
extern "C" {
Packit 90a5c9
#endif
Packit 90a5c9
Packit 90a5c9
/** If this flag is set, the store/retrieve/remove/status interfaces
Packit 90a5c9
 * of the provider are NOT safe to be called concurrently from
Packit 90a5c9
 * multiple processes or threads, and an external global mutex must be
Packit 90a5c9
 * used to serialize access to the provider.
Packit 90a5c9
 */
Packit 90a5c9
/* XXX: Even if store/retrieve/remove is atomic, isn't it useful to note
Packit 90a5c9
 * independently that status and iterate may or may not be?
Packit 90a5c9
 */
Packit 90a5c9
#define AP_SOCACHE_FLAG_NOTMPSAFE (0x0001)
Packit 90a5c9
Packit 90a5c9
/** A cache instance. */
Packit 90a5c9
typedef struct ap_socache_instance_t ap_socache_instance_t;
Packit 90a5c9
Packit 90a5c9
/** Hints which may be passed to the init function; providers may
Packit 90a5c9
 * ignore some or all of these hints. */
Packit 90a5c9
struct ap_socache_hints {
Packit 90a5c9
    /** Approximate average length of IDs: */
Packit 90a5c9
    apr_size_t avg_id_len;
Packit 90a5c9
    /** Approximate average size of objects: */
Packit 90a5c9
    apr_size_t avg_obj_size;
Packit 90a5c9
    /** Suggested interval between expiry cleanup runs; */
Packit 90a5c9
    apr_interval_time_t expiry_interval;
Packit 90a5c9
};
Packit 90a5c9
Packit 90a5c9
/**
Packit 90a5c9
 * Iterator callback prototype for the ap_socache_provider_t->iterate() method
Packit 90a5c9
 * @param instance The cache instance
Packit 90a5c9
 * @param s Associated server context (for logging)
Packit 90a5c9
 * @param userctx User defined pointer passed from the iterator call
Packit 90a5c9
 * @param id Unique ID for the object (binary blob)
Packit 90a5c9
 * with a trailing null char for convenience
Packit 90a5c9
 * @param idlen Length of id blob
Packit 90a5c9
 * @param data Output buffer to place retrieved data (binary blob)
Packit 90a5c9
 * with a trailing null char for convenience
Packit 90a5c9
 * @param datalen Length of data buffer
Packit 90a5c9
 * @param pool Pool for temporary allocations
Packit 90a5c9
 * @return APR status value; return APR_SUCCESS or the iteration will halt;
Packit 90a5c9
 * this value is returned to the ap_socache_provider_t->iterate() caller
Packit 90a5c9
 */
Packit 90a5c9
typedef apr_status_t (ap_socache_iterator_t)(ap_socache_instance_t *instance,
Packit 90a5c9
                                             server_rec *s,
Packit 90a5c9
                                             void *userctx,
Packit 90a5c9
                                             const unsigned char *id,
Packit 90a5c9
                                             unsigned int idlen,
Packit 90a5c9
                                             const unsigned char *data,
Packit 90a5c9
                                             unsigned int datalen,
Packit 90a5c9
                                             apr_pool_t *pool);
Packit 90a5c9
Packit 90a5c9
/** A socache provider structure.  socache providers are registered
Packit 90a5c9
 * with the ap_provider.h interface using the AP_SOCACHE_PROVIDER_*
Packit 90a5c9
 * constants. */
Packit 90a5c9
typedef struct ap_socache_provider_t {
Packit 90a5c9
    /** Canonical provider name. */
Packit 90a5c9
    const char *name;
Packit 90a5c9
Packit 90a5c9
    /** Bitmask of AP_SOCACHE_FLAG_* flags. */
Packit 90a5c9
    unsigned int flags;
Packit 90a5c9
Packit 90a5c9
    /**
Packit 90a5c9
     * Create a session cache based on the given configuration string.
Packit 90a5c9
     * The instance pointer returned in the instance parameter will be
Packit 90a5c9
     * passed as the first argument to subsequent invocations.
Packit 90a5c9
     *
Packit 90a5c9
     * @param instance Output parameter to which instance object is written.
Packit 90a5c9
     * @param arg User-specified configuration string.  May be NULL to
Packit 90a5c9
     *        force use of defaults.
Packit 90a5c9
     * @param tmp Pool to be used for any temporary allocations
Packit 90a5c9
     * @param p Pool to be use for any allocations lasting as long as
Packit 90a5c9
     * the created instance
Packit 90a5c9
     * @return NULL on success, or an error string on failure.
Packit 90a5c9
     */
Packit 90a5c9
    const char *(*create)(ap_socache_instance_t **instance, const char *arg,
Packit 90a5c9
                          apr_pool_t *tmp, apr_pool_t *p);
Packit 90a5c9
Packit 90a5c9
    /**
Packit 90a5c9
     * Initialize the cache.  The cname must be of maximum length 16
Packit 90a5c9
     * characters, and uniquely identifies the consumer of the cache
Packit 90a5c9
     * within the server; using the module name is recommended, e.g.
Packit 90a5c9
     * "mod_ssl-sess".  This string may be used within a filesystem
Packit 90a5c9
     * path so use of only alphanumeric [a-z0-9_-] characters is
Packit 90a5c9
     * recommended.  If hints is non-NULL, it gives a set of hints for
Packit 90a5c9
     * the provider.  Returns APR error code.
Packit 90a5c9
     *
Packit 90a5c9
     * @param instance The cache instance
Packit 90a5c9
     * @param cname A unique string identifying the consumer of this API
Packit 90a5c9
     * @param hints Optional hints argument describing expected cache use
Packit 90a5c9
     * @param s Server structure to which the cache is associated
Packit 90a5c9
     * @param pool Pool for long-lived allocations
Packit 90a5c9
     * @return APR status value indicating success.
Packit 90a5c9
     */
Packit 90a5c9
    apr_status_t (*init)(ap_socache_instance_t *instance, const char *cname,
Packit 90a5c9
                         const struct ap_socache_hints *hints,
Packit 90a5c9
                         server_rec *s, apr_pool_t *pool);
Packit 90a5c9
Packit 90a5c9
    /**
Packit 90a5c9
     * Destroy a given cache instance object.
Packit 90a5c9
     * @param instance The cache instance to destroy.
Packit 90a5c9
     * @param s Associated server structure (for logging purposes)
Packit 90a5c9
     */
Packit 90a5c9
    void (*destroy)(ap_socache_instance_t *instance, server_rec *s);
Packit 90a5c9
Packit 90a5c9
    /**
Packit 90a5c9
     * Store an object in a cache instance.
Packit 90a5c9
     * @param instance The cache instance
Packit 90a5c9
     * @param s Associated server structure (for logging purposes)
Packit 90a5c9
     * @param id Unique ID for the object; binary blob
Packit 90a5c9
     * @param idlen Length of id blob
Packit 90a5c9
     * @param expiry Absolute time at which the object expires
Packit 90a5c9
     * @param data Data to store; binary blob
Packit 90a5c9
     * @param datalen Length of data blob
Packit 90a5c9
     * @param pool Pool for temporary allocations.
Packit 90a5c9
     * @return APR status value.
Packit 90a5c9
     */
Packit 90a5c9
    apr_status_t (*store)(ap_socache_instance_t *instance, server_rec *s,
Packit 90a5c9
                          const unsigned char *id, unsigned int idlen,
Packit 90a5c9
                          apr_time_t expiry,
Packit 90a5c9
                          unsigned char *data, unsigned int datalen,
Packit 90a5c9
                          apr_pool_t *pool);
Packit 90a5c9
Packit 90a5c9
    /**
Packit 90a5c9
     * Retrieve a cached object.
Packit 90a5c9
     * 
Packit 90a5c9
     * @param instance The cache instance
Packit 90a5c9
     * @param s Associated server structure (for logging purposes)
Packit 90a5c9
     * @param id Unique ID for the object; binary blob
Packit 90a5c9
     * @param idlen Length of id blob
Packit 90a5c9
     * @param data Output buffer to place retrievd data (binary blob)
Packit 90a5c9
     * @param datalen On entry, length of data buffer; on exit, the
Packit 90a5c9
     * number of bytes written to the data buffer.
Packit 90a5c9
     * @param pool Pool for temporary allocations.
Packit 90a5c9
     * @return APR status value; APR_NOTFOUND if the object was not
Packit 90a5c9
     * found
Packit 90a5c9
     */
Packit 90a5c9
    apr_status_t (*retrieve)(ap_socache_instance_t *instance, server_rec *s,
Packit 90a5c9
                             const unsigned char *id, unsigned int idlen,
Packit 90a5c9
                             unsigned char *data, unsigned int *datalen,
Packit 90a5c9
                             apr_pool_t *pool);
Packit 90a5c9
Packit 90a5c9
    /**
Packit 90a5c9
     * Remove an object from the cache
Packit 90a5c9
     *
Packit 90a5c9
     * @param instance The cache instance
Packit 90a5c9
     * @param s Associated server structure (for logging purposes)
Packit 90a5c9
     * @param id Unique ID for the object; binary blob
Packit 90a5c9
     * @param idlen Length of id blob
Packit 90a5c9
     * @param pool Pool for temporary allocations.
Packit 90a5c9
     */
Packit 90a5c9
    apr_status_t (*remove)(ap_socache_instance_t *instance, server_rec *s,
Packit 90a5c9
                           const unsigned char *id, unsigned int idlen,
Packit 90a5c9
                           apr_pool_t *pool);
Packit 90a5c9
Packit 90a5c9
    /** 
Packit 90a5c9
     * Dump the status of a cache instance for mod_status.  Will use
Packit 90a5c9
     * the ap_r* interfaces to produce appropriate status output.
Packit 90a5c9
     * XXX: ap_r* are deprecated, bad dogfood
Packit 90a5c9
     *
Packit 90a5c9
     * @param instance The cache instance
Packit 90a5c9
     * @param r The request structure
Packit 90a5c9
     * @param flags The AP_STATUS_* constants used (see mod_status.h)
Packit 90a5c9
     */
Packit 90a5c9
    void (*status)(ap_socache_instance_t *instance, request_rec *r, int flags);
Packit 90a5c9
Packit 90a5c9
    /**
Packit 90a5c9
     * Dump all cached objects through an iterator callback.
Packit 90a5c9
     * @param instance The cache instance
Packit 90a5c9
     * @param s Associated server context (for processing and logging)
Packit 90a5c9
     * @param userctx User defined pointer passed through to the iterator
Packit 90a5c9
     * @param iterator The user provided callback function which will receive
Packit 90a5c9
     * individual calls for each unexpired id/data pair
Packit 90a5c9
     * @param pool Pool for temporary allocations.
Packit 90a5c9
     * @return APR status value; APR_NOTFOUND if the object was not
Packit 90a5c9
     * found
Packit 90a5c9
     */
Packit 90a5c9
    apr_status_t (*iterate)(ap_socache_instance_t *instance, server_rec *s,
Packit 90a5c9
                            void *userctx, ap_socache_iterator_t *iterator,
Packit 90a5c9
                            apr_pool_t *pool);
Packit 90a5c9
Packit 90a5c9
} ap_socache_provider_t;
Packit 90a5c9
Packit 90a5c9
/** The provider group used to register socache providers. */
Packit 90a5c9
#define AP_SOCACHE_PROVIDER_GROUP "socache"
Packit 90a5c9
/** The provider version used to register socache providers. */
Packit 90a5c9
#define AP_SOCACHE_PROVIDER_VERSION "0"
Packit 90a5c9
Packit 90a5c9
/** Default provider name. */
Packit 90a5c9
#define AP_SOCACHE_DEFAULT_PROVIDER "default"
Packit 90a5c9
Packit 90a5c9
#ifdef __cplusplus
Packit 90a5c9
}
Packit 90a5c9
#endif
Packit 90a5c9
Packit 90a5c9
#endif /* AP_SOCACHE_H */
Packit 90a5c9
/** @} */