1 /* $OpenBSD: ap_ctx.h,v 1.6 2005/03/28 23:26:51 niallo Exp $ */
2 
3 /* ====================================================================
4  * Copyright (c) 1998-2000 The Apache Group.  All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in
15  *    the documentation and/or other materials provided with the
16  *    distribution.
17  *
18  * 3. All advertising materials mentioning features or use of this
19  *    software must display the following acknowledgment:
20  *    "This product includes software developed by the Apache Group
21  *    for use in the Apache HTTP server project (http://www.apache.org/)."
22  *
23  * 4. The names "Apache Server" and "Apache Group" must not be used to
24  *    endorse or promote products derived from this software without
25  *    prior written permission. For written permission, please contact
26  *    apache@apache.org.
27  *
28  * 5. Products derived from this software may not be called "Apache"
29  *    nor may "Apache" appear in their names without prior written
30  *    permission of the Apache Group.
31  *
32  * 6. Redistributions of any form whatsoever must retain the following
33  *    acknowledgment:
34  *    "This product includes software developed by the Apache Group
35  *    for use in the Apache HTTP server project (http://www.apache.org/)."
36  *
37  * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
38  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
39  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
40  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
41  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
43  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
44  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
45  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
46  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
47  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
48  * OF THE POSSIBILITY OF SUCH DAMAGE.
49  * ====================================================================
50  *
51  * This software consists of voluntary contributions made by many
52  * individuals on behalf of the Apache Group and was originally based
53  * on public domain software written at the National Center for
54  * Supercomputing Applications, University of Illinois, Urbana-Champaign.
55  * For more information on the Apache Group and the Apache HTTP server
56  * project, please see <http://www.apache.org/>.
57  *
58  */
59 
60 /*
61 **  Generic Context Interface for Apache
62 **  Written by Ralf S. Engelschall <rse@engelschall.com>
63 */
64 
65 #ifndef AP_CTX_H
66 #define AP_CTX_H
67 
68 #ifndef FALSE
69 #define FALSE 0
70 #define TRUE  !FALSE
71 #endif
72 
73 /*
74  * Internal Context Record Definition
75  */
76 
77 #define AP_CTX_MAX_ENTRIES 1024
78 
79 typedef struct {
80 	char *ce_key;
81 	void *ce_val;
82 } ap_ctx_entry;
83 
84 typedef struct {
85 	pool          *cr_pool;
86 	ap_ctx_entry **cr_entry;
87 } ap_ctx_rec;
88 
89 typedef ap_ctx_rec ap_ctx;
90 
91 /*
92  * Some convinience macros for storing _numbers_ 0...n in contexts, i.e.
93  * treating numbers as pointers but keeping track of the NULL return code of
94  * ap_ctx_get.
95  */
96 #define AP_CTX_NUM2PTR(n) (void *)(((unsigned long)(n))+1)
97 #define AP_CTX_PTR2NUM(p) (unsigned long)(((char *)(p))-1)
98 
99 /*
100  * Prototypes for Context Handling Functions
101  */
102 
103 API_EXPORT(ap_ctx *)ap_ctx_new(pool *p);
104 API_EXPORT(void)    ap_ctx_set(ap_ctx *ctx, char *key, void *val);
105 API_EXPORT(void *)  ap_ctx_get(ap_ctx *ctx, char *key);
106 API_EXPORT(ap_ctx *)ap_ctx_overlay(pool *p, ap_ctx *over, ap_ctx *base);
107 
108 #endif /* AP_CTX_H */
109