]> granicus.if.org Git - apache/blob - modules/ssl/ssl_util_table.h
fa8220a11e1f6ebb853e9227c7bb408c0bb69374
[apache] / modules / ssl / ssl_util_table.h
1 /*                      _             _
2 **  _ __ ___   ___   __| |    ___ ___| |  mod_ssl
3 ** | '_ ` _ \ / _ \ / _` |   / __/ __| |  Apache Interface to OpenSSL
4 ** | | | | | | (_) | (_| |   \__ \__ \ |  www.modssl.org
5 ** |_| |_| |_|\___/ \__,_|___|___/___/_|  ftp.modssl.org
6 **                      |_____|
7 **  ssl_util_table.h
8 **  High Performance Hash Table Header
9 */
10
11 /* ====================================================================
12  * The Apache Software License, Version 1.1
13  *
14  * Copyright (c) 2000-2001 The Apache Software Foundation.  All rights
15  * reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions
19  * are met:
20  *
21  * 1. Redistributions of source code must retain the above copyright
22  *    notice, this list of conditions and the following disclaimer.
23  *
24  * 2. Redistributions in binary form must reproduce the above copyright
25  *    notice, this list of conditions and the following disclaimer in
26  *    the documentation and/or other materials provided with the
27  *    distribution.
28  *
29  * 3. The end-user documentation included with the redistribution,
30  *    if any, must include the following acknowledgment:
31  *       "This product includes software developed by the
32  *        Apache Software Foundation (http://www.apache.org/)."
33  *    Alternately, this acknowledgment may appear in the software itself,
34  *    if and wherever such third-party acknowledgments normally appear.
35  *
36  * 4. The names "Apache" and "Apache Software Foundation" must
37  *    not be used to endorse or promote products derived from this
38  *    software without prior written permission. For written
39  *    permission, please contact apache@apache.org.
40  *
41  * 5. Products derived from this software may not be called "Apache",
42  *    nor may "Apache" appear in their name, without prior written
43  *    permission of the Apache Software Foundation.
44  *
45  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
46  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
47  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
48  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
49  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
50  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
51  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
52  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
53  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
54  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
55  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56  * SUCH DAMAGE.
57  * ====================================================================
58  */
59
60 /*
61  * Generic hash table defines
62  * Table 4.1.0 July-28-1998
63  *
64  * This library is a generic open hash table with buckets and
65  * linked lists.  It is pretty high performance.  Each element
66  * has a key and a data.  The user indexes on the key to find the
67  * data.
68  *
69  * Copyright 1998 by Gray Watson <gray@letters.com>
70  *
71  * Permission to use, copy, modify, and distribute this software for any
72  * purpose and without fee is hereby granted, provided that the above
73  * copyright notice and this permission notice appear in all copies,
74  * and that the name of Gray Watson not be used in advertising or
75  * publicity pertaining to distribution of the document or software
76  * without specific, written prior permission.
77  *
78  * Gray Watson makes no representations about the suitability of the
79  * software described herein for any purpose.  It is provided "as is"
80  * without express or implied warranty.
81  */
82
83 #ifndef SSL_UTIL_TABLE_H
84 #define SSL_UTIL_TABLE_H
85
86 #ifdef __cplusplus
87 extern "C" {
88 #endif /* __cplusplus */
89
90 /*
91  * To build a "key" in any of the below routines, pass in a pointer to
92  * the key and its size [i.e. sizeof(int), etc].  With any of the
93  * "key" or "data" arguments, if their size is < 0, it will do an
94  * internal strlen of the item and add 1 for the \0.
95  *
96  * If you are using firstkey() and nextkey() functions, be careful if,
97  * after starting your firstkey loop, you use delete or insert, it
98  * will not crash but may produce interesting results.  If you are
99  * deleting from firstkey to NULL it will work fine.
100  */
101
102 /* return types for table functions */
103 #define TABLE_ERROR_NONE    1   /* no error from function */
104 #define TABLE_ERROR_PNT     2   /* bad table pointer */
105 #define TABLE_ERROR_ARG_NULL    3   /* buffer args were null */
106 #define TABLE_ERROR_SIZE    4   /* size of data was bad */
107 #define TABLE_ERROR_OVERWRITE   5   /* key exists and we cant overwrite */
108 #define TABLE_ERROR_NOT_FOUND   6   /* key does not exist */
109 #define TABLE_ERROR_ALLOC   7   /* memory allocation error */
110 #define TABLE_ERROR_LINEAR  8   /* no linear access started */
111 #define TABLE_ERROR_OPEN    9   /* could not open file */
112 #define TABLE_ERROR_SEEK    10  /* could not seek to pos in file */
113 #define TABLE_ERROR_READ    11  /* could not read from file */
114 #define TABLE_ERROR_WRITE   12  /* could not write to file */
115 #define TABLE_ERROR_EMPTY   13  /* table is empty */
116 #define TABLE_ERROR_NOT_EMPTY   14  /* table contains data */
117 #define TABLE_ERROR_ALIGNMENT   15  /* invalid alignment value */
118
119 /*
120  * Table flags set with table_attr.
121  */
122
123 /*
124  * Automatically adjust the number of table buckets on the fly.
125  * Whenever the number of entries gets above some threshold, the
126  * number of buckets is realloced to a new size and each entry is
127  * re-hashed.  Although this may take some time when it re-hashes, the
128  * table will perform better over time.
129  */
130 #define TABLE_FLAG_AUTO_ADJUST  (1<<0)
131
132 /*
133  * If the above auto-adjust flag is set, also adjust the number of
134  * table buckets down as we delete entries.
135  */
136 #define TABLE_FLAG_ADJUST_DOWN  (1<<1)
137
138 /* structure to walk through the fields in a linear order */
139 typedef struct {
140   unsigned int  tl_magic;   /* magic structure to ensure correct init */
141   unsigned int  tl_bucket_c;    /* where in the table buck array we are */
142   unsigned int  tl_entry_c; /* in the bucket, which entry we are on */
143 } table_linear_t;
144
145 typedef int (*table_compare_t)(const void *key1, const int key1_size,
146                    const void *data1, const int data1_size,
147                    const void *key2, const int key2_size,
148                    const void *data2, const int data2_size);
149
150 #ifndef TABLE_PRIVATE
151 typedef void    table_t;
152 typedef void    table_entry_t;
153 #endif
154
155 /*
156  * Prototypes
157  */
158 extern table_t        *table_alloc(const unsigned int bucket_n, int *error_p, void *(*malloc_f)(size_t size), void *(*calloc_f)(size_t number, size_t size), void *(*realloc_f)(void *ptr, size_t size), void (*free_f)(void *ptr));
159 extern int             table_attr(table_t *table_p, const int attr);
160 extern int             table_set_data_alignment(table_t *table_p, const int alignment);
161 extern int             table_clear(table_t *table_p);
162 extern int             table_free(table_t *table_p);
163 extern int             table_insert_kd(table_t *table_p, const void *key_buf, const int key_size, const void *data_buf, const int data_size, void **key_buf_p, void **data_buf_p, const char overwrite_b);
164 extern int             table_insert(table_t *table_p, const void *key_buf, const int key_size, const void *data_buf, const int data_size, void **data_buf_p, const char overwrite_b);
165 extern int             table_retrieve(table_t *table_p, const void *key_buf, const int key_size, void **data_buf_p, int *data_size_p);
166 extern int             table_delete(table_t *table_p, const void *key_buf, const int key_size, void **data_buf_p, int *data_size_p);
167 extern int             table_delete_first(table_t *table_p, void **key_buf_p, int *key_size_p, void **data_buf_p, int *data_size_p);
168 extern int             table_info(table_t *table_p, int *num_buckets_p, int *num_entries_p);
169 extern int             table_adjust(table_t *table_p, const int bucket_n);
170 extern const char     *table_strerror(const int error);
171 extern int             table_type_size(void);
172 extern int             table_first(table_t *table_p, void **key_buf_p, int *key_size_p, void **data_buf_p, int *data_size_p);
173 extern int             table_next(table_t *table_p, void **key_buf_p, int *key_size_p, void **data_buf_p, int *data_size_p);
174 extern int             table_this(table_t *table_p, void **key_buf_p, int *key_size_p, void **data_buf_p, int *data_size_p);
175 extern int             table_first_r(table_t *table_p, table_linear_t *linear_p, void **key_buf_p, int *key_size_p, void **data_buf_p, int *data_size_p);
176 extern int             table_next_r(table_t *table_p, table_linear_t *linear_p, void **key_buf_p, int *key_size_p, void **data_buf_p, int *data_size_p);
177 extern int             table_this_r(table_t *table_p, table_linear_t *linear_p, void **key_buf_p, int *key_size_p, void **data_buf_p, int *data_size_p);
178 extern table_t        *table_read(const char *path, int *error_p, void *(*malloc_f)(size_t size), void *(*calloc_f)(size_t number, size_t size), void *(*realloc_f)(void *ptr, size_t size), void (*free_f)(void *ptr));
179 extern int             table_write(const table_t *table_p, const char *path, const int mode);
180 extern table_entry_t **table_order(table_t *table_p, table_compare_t compare, int *num_entries_p, int *error_p);
181 extern int             table_entry_info(table_t *table_p, table_entry_t *entry_p, void **key_buf_p, int *key_size_p, void **data_buf_p, int *data_size_p);
182
183 #ifdef __cplusplus
184 }
185 #endif /* __cplusplus */
186
187 #endif /* ! SSL_UTIL_TABLE_H */