842ae4bd224140319ae7feec1872b93dfd491143fielding/* Licensed to the Apache Software Foundation (ASF) under one or more
842ae4bd224140319ae7feec1872b93dfd491143fielding * contributor license agreements. See the NOTICE file distributed with
842ae4bd224140319ae7feec1872b93dfd491143fielding * this work for additional information regarding copyright ownership.
842ae4bd224140319ae7feec1872b93dfd491143fielding * The ASF licenses this file to You under the Apache License, Version 2.0
842ae4bd224140319ae7feec1872b93dfd491143fielding * (the "License"); you may not use this file except in compliance with
842ae4bd224140319ae7feec1872b93dfd491143fielding * the License. You may obtain a copy of the License at
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse *
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * http://www.apache.org/licenses/LICENSE-2.0
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse *
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * Unless required by applicable law or agreed to in writing, software
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * distributed under the License is distributed on an "AS IS" BASIS,
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * See the License for the specific language governing permissions and
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * limitations under the License.
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd */
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh#ifndef SLOTMEM_H
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh#define SLOTMEM_H
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh/* Memory handler for a shared memory divided in slot.
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh */
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh/**
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh * @file ap_slotmem.h
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh * @brief Memory Slot Extension Storage Module for Apache
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh *
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh * @defgroup MEM mem
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh * @ingroup APACHE_MODS
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh * @{
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh */
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh#include "httpd.h"
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse#include "http_config.h"
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse#include "http_log.h"
60c1c6006c048e5009ae91fa2ba4cd35e5f78e10rse#include "ap_provider.h"
60c1c6006c048e5009ae91fa2ba4cd35e5f78e10rse
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse#include "apr.h"
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh#include "apr_strings.h"
4281cf6a722c99ae21394dc2000bd48efcebdb3akbrand#include "apr_pools.h"
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse#include "apr_shm.h"
e5106092b7fae78cec4898042a78a10acccb4cacwrowe#include "apr_global_mutex.h"
d1795b4b9ec996109b46845376bdfb82989218dbstsp#include "apr_file_io.h"
d1795b4b9ec996109b46845376bdfb82989218dbstsp#include "apr_md5.h"
d1795b4b9ec996109b46845376bdfb82989218dbstsp
d1795b4b9ec996109b46845376bdfb82989218dbstsp#if APR_HAVE_UNISTD_H
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse#include <unistd.h> /* for getpid() */
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh#endif
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse#ifdef __cplusplus
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrseextern "C" {
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse#endif
d1795b4b9ec996109b46845376bdfb82989218dbstsp
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse#define AP_SLOTMEM_PROVIDER_GROUP "slotmem"
d1795b4b9ec996109b46845376bdfb82989218dbstsp#define AP_SLOTMEM_PROVIDER_VERSION "0"
d1795b4b9ec996109b46845376bdfb82989218dbstsp
bdec92dd2c27b079aebb91250204febb4c59d7eadougmtypedef unsigned int ap_slotmem_type_t;
bdec92dd2c27b079aebb91250204febb4c59d7eadougm
742318b93e89c311f66b55f426c4d9cf2c14628bjim/*
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * Values for ap_slotmem_type_t::
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse *
726be39314e1b2ede8378630efccce4cdeb88a31dougm * AP_SLOTMEM_TYPE_PERSIST: For transitory providers, persist
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * the data on the file-system
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse *
60998c490ad3334eb07ae63b23b479ac564dec94kbrand * AP_SLOTMEM_TYPE_NOTMPSAFE:
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse *
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * AP_SLOTMEM_TYPE_PREALLOC: Access to slots require they be grabbed 1st
032982212dbcc7c3cce95bf89c503bb56e185ac7kbrand *
1b1621900bd89ddc496d721c865a726f635ebd7esf * AP_SLOTMEM_TYPE_CLEARINUSE: If persisting, clear 'inuse' array before
41cfeab1b7ec1ed81de039e811565b1c6df999f9kbrand * storing
032982212dbcc7c3cce95bf89c503bb56e185ac7kbrand */
2c238b83c08ac2d040d9057b1ba83ba7f71138b7kbrand#define AP_SLOTMEM_TYPE_PERSIST (1 << 0)
d58a822aff1dfda25384d3d009f88f1883c95436kbrand#define AP_SLOTMEM_TYPE_NOTMPSAFE (1 << 1)
9d0d2ad2438f2e8c9ff1dd64b243605170d739aedougm#define AP_SLOTMEM_TYPE_PREGRAB (1 << 2)
9d0d2ad2438f2e8c9ff1dd64b243605170d739aedougm#define AP_SLOTMEM_TYPE_CLEARINUSE (1 << 3)
070235bcb25af37efebf6405b082413144968289kbrand
bdec92dd2c27b079aebb91250204febb4c59d7eadougmtypedef struct ap_slotmem_instance_t ap_slotmem_instance_t;
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse
60c1c6006c048e5009ae91fa2ba4cd35e5f78e10rse/**
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh * callback function used for slotmem doall.
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh * @param mem is the memory associated with a worker.
* @param data is what is passed to slotmem.
* @param pool is pool used
* @return APR_SUCCESS if all went well
*/
typedef apr_status_t ap_slotmem_callback_fn_t(void* mem, void *data, apr_pool_t *pool);
struct ap_slotmem_provider_t {
/*
* Name of the provider method
*/
const char *name;
/**
* call the callback on all worker slots
* @param s ap_slotmem_instance_t to use.
* @param funct callback function to call for each element.
* @param data parameter for the callback function.
* @param pool is pool used
* @return APR_SUCCESS if all went well
*/
apr_status_t (* doall)(ap_slotmem_instance_t *s, ap_slotmem_callback_fn_t *func, void *data, apr_pool_t *pool);
/**
* create a new slotmem with each item size is item_size.
* This would create shared memory, basically.
* @param inst where to store pointer to slotmem
* @param name a key used for debugging and in mod_status output or allow another process to share this space.
* @param item_size size of each item
* @param item_num number of item to create.
* @param type type of slotmem.
* @param pool is pool used
* @return APR_SUCCESS if all went well
*/
apr_status_t (* create)(ap_slotmem_instance_t **inst, const char *name, apr_size_t item_size, unsigned int item_num, ap_slotmem_type_t type, apr_pool_t *pool);
/**
* attach to an existing slotmem.
* This would attach to shared memory, basically.
* @param inst where to store pointer to slotmem
* @param name a key used for debugging and in mod_status output or allow another process to share this space.
* @param item_size size of each item
* @param item_num max number of item.
* @param pool is pool to memory allocate.
* @return APR_SUCCESS if all went well
*/
apr_status_t (* attach)(ap_slotmem_instance_t **inst, const char *name, apr_size_t *item_size, unsigned int *item_num, apr_pool_t *pool);
/**
* get the memory ptr associated with this worker slot.
* @param s ap_slotmem_instance_t to use.
* @param item_id item to return for 0 to item_num
* @param mem address to store the pointer to the slot
* @return APR_SUCCESS if all went well
*/
apr_status_t (* dptr)(ap_slotmem_instance_t *s, unsigned int item_id, void**mem);
/**
* get/read the data associated with this worker slot.
* @param s ap_slotmem_instance_t to use.
* @param item_id item to return for 0 to item_num
* @param dest address to store the data
* @param dest_len length of dataset to retrieve
* @return APR_SUCCESS if all went well
*/
apr_status_t (* get)(ap_slotmem_instance_t *s, unsigned int item_id, unsigned char *dest, apr_size_t dest_len);
/**
* put/write the data associated with this worker slot.
* @param s ap_slotmem_instance_t to use.
* @param item_id item to return for 0 to item_num
* @param src address of the data to store in the slot
* @param src_len length of dataset to store in the slot
* @return APR_SUCCESS if all went well
*/
apr_status_t (* put)(ap_slotmem_instance_t *slot, unsigned int item_id, unsigned char *src, apr_size_t src_len);
/**
* return number of slots allocated for this entry.
* @param s ap_slotmem_instance_t to use.
* @return number of slots
*/
unsigned int (* num_slots)(ap_slotmem_instance_t *s);
/**
* return number of free (not used) slots allocated for this entry.
* Valid for slots which are AP_SLOTMEM_TYPE_PREGRAB as well as
* any which use get/release.
* @param s ap_slotmem_instance_t to use.
* @return number of slots
*/
unsigned int (* num_free_slots)(ap_slotmem_instance_t *s);
/**
* return slot size allocated for this entry.
* @param s ap_slotmem_instance_t to use.
* @return size of slot
*/
apr_size_t (* slot_size)(ap_slotmem_instance_t *s);
/**
* grab (or alloc) a free slot
* @param s ap_slotmem_instance_t to use.
* @param item_id ptr to the available slot id and marked as in-use
* @return APR_SUCCESS if all went well
*/
apr_status_t (* grab)(ap_slotmem_instance_t *s, unsigned int *item_id);
/**
* release (or free) the slot associated with this item_id
* @param s ap_slotmem_instance_t to use.
* @param item_id slot id to free and mark as no longer in-use
* @return APR_SUCCESS if all went well
*/
apr_status_t (* release)(ap_slotmem_instance_t *s, unsigned int item_id);
/**
* forced grab (or alloc) a slot associated with this item_id
* @param s ap_slotmem_instance_t to use.
* @param item_id to the specified slot id and marked as in-use
* @return APR_SUCCESS if all went well
*/
apr_status_t (* fgrab)(ap_slotmem_instance_t *s, unsigned int item_id);
};
typedef struct ap_slotmem_provider_t ap_slotmem_provider_t;
#ifdef __cplusplus
}
#endif
#endif
/** @} */