OSDN Git Service

Enhance routines for extra commands.
[ffftp/ffftp.git] / contrib / openssl / include / openssl / lhash.h
1 /* crypto/lhash/lhash.h */\r
2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)\r
3  * All rights reserved.\r
4  *\r
5  * This package is an SSL implementation written\r
6  * by Eric Young (eay@cryptsoft.com).\r
7  * The implementation was written so as to conform with Netscapes SSL.\r
8  *\r
9  * This library is free for commercial and non-commercial use as long as\r
10  * the following conditions are aheared to.  The following conditions\r
11  * apply to all code found in this distribution, be it the RC4, RSA,\r
12  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation\r
13  * included with this distribution is covered by the same copyright terms\r
14  * except that the holder is Tim Hudson (tjh@cryptsoft.com).\r
15  *\r
16  * Copyright remains Eric Young's, and as such any Copyright notices in\r
17  * the code are not to be removed.\r
18  * If this package is used in a product, Eric Young should be given attribution\r
19  * as the author of the parts of the library used.\r
20  * This can be in the form of a textual message at program startup or\r
21  * in documentation (online or textual) provided with the package.\r
22  *\r
23  * Redistribution and use in source and binary forms, with or without\r
24  * modification, are permitted provided that the following conditions\r
25  * are met:\r
26  * 1. Redistributions of source code must retain the copyright\r
27  *    notice, this list of conditions and the following disclaimer.\r
28  * 2. Redistributions in binary form must reproduce the above copyright\r
29  *    notice, this list of conditions and the following disclaimer in the\r
30  *    documentation and/or other materials provided with the distribution.\r
31  * 3. All advertising materials mentioning features or use of this software\r
32  *    must display the following acknowledgement:\r
33  *    "This product includes cryptographic software written by\r
34  *     Eric Young (eay@cryptsoft.com)"\r
35  *    The word 'cryptographic' can be left out if the rouines from the library\r
36  *    being used are not cryptographic related :-).\r
37  * 4. If you include any Windows specific code (or a derivative thereof) from\r
38  *    the apps directory (application code) you must include an acknowledgement:\r
39  *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"\r
40  *\r
41  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\r
42  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
43  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
44  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
45  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
46  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
47  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
48  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
49  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
50  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
51  * SUCH DAMAGE.\r
52  *\r
53  * The licence and distribution terms for any publically available version or\r
54  * derivative of this code cannot be changed.  i.e. this code cannot simply be\r
55  * copied and put under another distribution licence\r
56  * [including the GNU Public Licence.]\r
57  */\r
58 \r
59 /* Header for dynamic hash table routines\r
60  * Author - Eric Young\r
61  */\r
62 \r
63 #ifndef HEADER_LHASH_H\r
64 #define HEADER_LHASH_H\r
65 \r
66 #include <openssl/e_os2.h>\r
67 #ifndef OPENSSL_NO_FP_API\r
68 #include <stdio.h>\r
69 #endif\r
70 \r
71 #ifndef OPENSSL_NO_BIO\r
72 #include <openssl/bio.h>\r
73 #endif\r
74 \r
75 #ifdef  __cplusplus\r
76 extern "C" {\r
77 #endif\r
78 \r
79 typedef struct lhash_node_st\r
80         {\r
81         void *data;\r
82         struct lhash_node_st *next;\r
83 #ifndef OPENSSL_NO_HASH_COMP\r
84         unsigned long hash;\r
85 #endif\r
86         } LHASH_NODE;\r
87 \r
88 typedef int (*LHASH_COMP_FN_TYPE)(const void *, const void *);\r
89 typedef unsigned long (*LHASH_HASH_FN_TYPE)(const void *);\r
90 typedef void (*LHASH_DOALL_FN_TYPE)(void *);\r
91 typedef void (*LHASH_DOALL_ARG_FN_TYPE)(void *, void *);\r
92 \r
93 /* Macros for declaring and implementing type-safe wrappers for LHASH callbacks.\r
94  * This way, callbacks can be provided to LHASH structures without function\r
95  * pointer casting and the macro-defined callbacks provide per-variable casting\r
96  * before deferring to the underlying type-specific callbacks. NB: It is\r
97  * possible to place a "static" in front of both the DECLARE and IMPLEMENT\r
98  * macros if the functions are strictly internal. */\r
99 \r
100 /* First: "hash" functions */\r
101 #define DECLARE_LHASH_HASH_FN(name, o_type) \\r
102         unsigned long name##_LHASH_HASH(const void *);\r
103 #define IMPLEMENT_LHASH_HASH_FN(name, o_type) \\r
104         unsigned long name##_LHASH_HASH(const void *arg) { \\r
105                 const o_type *a = arg; \\r
106                 return name##_hash(a); }\r
107 #define LHASH_HASH_FN(name) name##_LHASH_HASH\r
108 \r
109 /* Second: "compare" functions */\r
110 #define DECLARE_LHASH_COMP_FN(name, o_type) \\r
111         int name##_LHASH_COMP(const void *, const void *);\r
112 #define IMPLEMENT_LHASH_COMP_FN(name, o_type) \\r
113         int name##_LHASH_COMP(const void *arg1, const void *arg2) { \\r
114                 const o_type *a = arg1;             \\r
115                 const o_type *b = arg2; \\r
116                 return name##_cmp(a,b); }\r
117 #define LHASH_COMP_FN(name) name##_LHASH_COMP\r
118 \r
119 /* Third: "doall" functions */\r
120 #define DECLARE_LHASH_DOALL_FN(name, o_type) \\r
121         void name##_LHASH_DOALL(void *);\r
122 #define IMPLEMENT_LHASH_DOALL_FN(name, o_type) \\r
123         void name##_LHASH_DOALL(void *arg) { \\r
124                 o_type *a = arg; \\r
125                 name##_doall(a); }\r
126 #define LHASH_DOALL_FN(name) name##_LHASH_DOALL\r
127 \r
128 /* Fourth: "doall_arg" functions */\r
129 #define DECLARE_LHASH_DOALL_ARG_FN(name, o_type, a_type) \\r
130         void name##_LHASH_DOALL_ARG(void *, void *);\r
131 #define IMPLEMENT_LHASH_DOALL_ARG_FN(name, o_type, a_type) \\r
132         void name##_LHASH_DOALL_ARG(void *arg1, void *arg2) { \\r
133                 o_type *a = arg1; \\r
134                 a_type *b = arg2; \\r
135                 name##_doall_arg(a, b); }\r
136 #define LHASH_DOALL_ARG_FN(name) name##_LHASH_DOALL_ARG\r
137 \r
138 typedef struct lhash_st\r
139         {\r
140         LHASH_NODE **b;\r
141         LHASH_COMP_FN_TYPE comp;\r
142         LHASH_HASH_FN_TYPE hash;\r
143         unsigned int num_nodes;\r
144         unsigned int num_alloc_nodes;\r
145         unsigned int p;\r
146         unsigned int pmax;\r
147         unsigned long up_load; /* load times 256 */\r
148         unsigned long down_load; /* load times 256 */\r
149         unsigned long num_items;\r
150 \r
151         unsigned long num_expands;\r
152         unsigned long num_expand_reallocs;\r
153         unsigned long num_contracts;\r
154         unsigned long num_contract_reallocs;\r
155         unsigned long num_hash_calls;\r
156         unsigned long num_comp_calls;\r
157         unsigned long num_insert;\r
158         unsigned long num_replace;\r
159         unsigned long num_delete;\r
160         unsigned long num_no_delete;\r
161         unsigned long num_retrieve;\r
162         unsigned long num_retrieve_miss;\r
163         unsigned long num_hash_comps;\r
164 \r
165         int error;\r
166         } _LHASH;       /* Do not use _LHASH directly, use LHASH_OF\r
167                          * and friends */\r
168 \r
169 #define LH_LOAD_MULT    256\r
170 \r
171 /* Indicates a malloc() error in the last call, this is only bad\r
172  * in lh_insert(). */\r
173 #define lh_error(lh)    ((lh)->error)\r
174 \r
175 _LHASH *lh_new(LHASH_HASH_FN_TYPE h, LHASH_COMP_FN_TYPE c);\r
176 void lh_free(_LHASH *lh);\r
177 void *lh_insert(_LHASH *lh, void *data);\r
178 void *lh_delete(_LHASH *lh, const void *data);\r
179 void *lh_retrieve(_LHASH *lh, const void *data);\r
180 void lh_doall(_LHASH *lh, LHASH_DOALL_FN_TYPE func);\r
181 void lh_doall_arg(_LHASH *lh, LHASH_DOALL_ARG_FN_TYPE func, void *arg);\r
182 unsigned long lh_strhash(const char *c);\r
183 unsigned long lh_num_items(const _LHASH *lh);\r
184 \r
185 #ifndef OPENSSL_NO_FP_API\r
186 void lh_stats(const _LHASH *lh, FILE *out);\r
187 void lh_node_stats(const _LHASH *lh, FILE *out);\r
188 void lh_node_usage_stats(const _LHASH *lh, FILE *out);\r
189 #endif\r
190 \r
191 #ifndef OPENSSL_NO_BIO\r
192 void lh_stats_bio(const _LHASH *lh, BIO *out);\r
193 void lh_node_stats_bio(const _LHASH *lh, BIO *out);\r
194 void lh_node_usage_stats_bio(const _LHASH *lh, BIO *out);\r
195 #endif\r
196 \r
197 /* Type checking... */\r
198 \r
199 #define LHASH_OF(type) struct lhash_st_##type\r
200 \r
201 #define DECLARE_LHASH_OF(type) LHASH_OF(type) { int dummy; }\r
202 \r
203 #define CHECKED_LHASH_OF(type,lh) \\r
204   ((_LHASH *)CHECKED_PTR_OF(LHASH_OF(type),lh))\r
205 \r
206 /* Define wrapper functions. */\r
207 #define LHM_lh_new(type, name) \\r
208   ((LHASH_OF(type) *)lh_new(LHASH_HASH_FN(name), LHASH_COMP_FN(name)))\r
209 #define LHM_lh_error(type, lh) \\r
210   lh_error(CHECKED_LHASH_OF(type,lh))\r
211 #define LHM_lh_insert(type, lh, inst) \\r
212   ((type *)lh_insert(CHECKED_LHASH_OF(type, lh), \\r
213                      CHECKED_PTR_OF(type, inst)))\r
214 #define LHM_lh_retrieve(type, lh, inst) \\r
215   ((type *)lh_retrieve(CHECKED_LHASH_OF(type, lh), \\r
216                        CHECKED_PTR_OF(type, inst)))\r
217 #define LHM_lh_delete(type, lh, inst) \\r
218   ((type *)lh_delete(CHECKED_LHASH_OF(type, lh),                        \\r
219                      CHECKED_PTR_OF(type, inst)))\r
220 #define LHM_lh_doall(type, lh,fn) lh_doall(CHECKED_LHASH_OF(type, lh), fn)\r
221 #define LHM_lh_doall_arg(type, lh, fn, arg_type, arg) \\r
222   lh_doall_arg(CHECKED_LHASH_OF(type, lh), fn, CHECKED_PTR_OF(arg_type, arg))\r
223 #define LHM_lh_num_items(type, lh) lh_num_items(CHECKED_LHASH_OF(type, lh))\r
224 #define LHM_lh_down_load(type, lh) (CHECKED_LHASH_OF(type, lh)->down_load)\r
225 #define LHM_lh_node_stats_bio(type, lh, out) \\r
226   lh_node_stats_bio(CHECKED_LHASH_OF(type, lh), out)\r
227 #define LHM_lh_node_usage_stats_bio(type, lh, out) \\r
228   lh_node_usage_stats_bio(CHECKED_LHASH_OF(type, lh), out)\r
229 #define LHM_lh_stats_bio(type, lh, out) \\r
230   lh_stats_bio(CHECKED_LHASH_OF(type, lh), out)\r
231 #define LHM_lh_free(type, lh) lh_free(CHECKED_LHASH_OF(type, lh))\r
232 \r
233 DECLARE_LHASH_OF(OPENSSL_STRING);\r
234 DECLARE_LHASH_OF(OPENSSL_CSTRING);\r
235 \r
236 #ifdef  __cplusplus\r
237 }\r
238 #endif\r
239 \r
240 #endif\r
241 \r