ssl_util_sdbm.h
上传用户:njrhmy
上传日期:2009-04-13
资源大小:801k
文件大小:7k
源码类别:

CA认证

开发平台:

Visual C++

  1. /*                      _             _
  2. **  _ __ ___   ___   __| |    ___ ___| |  mod_ssl
  3. ** | '_ ` _  / _  / _` |   / __/ __| |  Apache Interface to OpenSSL
  4. ** | | | | | | (_) | (_| |   __ __  |  www.modssl.org
  5. ** |_| |_| |_|___/ __,_|___|___/___/_|  ftp.modssl.org
  6. **                      |_____|
  7. **  ssl_util_sdbm.c
  8. **  Built-in Simple DBM (Header)
  9. */
  10. /* ====================================================================
  11.  * Copyright (c) 1998-2006 Ralf S. Engelschall. All rights reserved.
  12.  *
  13.  * Redistribution and use in source and binary forms, with or without
  14.  * modification, are permitted provided that the following conditions
  15.  * are met:
  16.  *
  17.  * 1. Redistributions of source code must retain the above copyright
  18.  *    notice, this list of conditions and the following disclaimer.
  19.  *
  20.  * 2. Redistributions in binary form must reproduce the above copyright
  21.  *    notice, this list of conditions and the following
  22.  *    disclaimer in the documentation and/or other materials
  23.  *    provided with the distribution.
  24.  *
  25.  * 3. All advertising materials mentioning features or use of this
  26.  *    software must display the following acknowledgment:
  27.  *    "This product includes software developed by
  28.  *     Ralf S. Engelschall <rse@engelschall.com> for use in the
  29.  *     mod_ssl project (http://www.modssl.org/)."
  30.  *
  31.  * 4. The names "mod_ssl" must not be used to endorse or promote
  32.  *    products derived from this software without prior written
  33.  *    permission. For written permission, please contact
  34.  *    rse@engelschall.com.
  35.  *
  36.  * 5. Products derived from this software may not be called "mod_ssl"
  37.  *    nor may "mod_ssl" appear in their names without prior
  38.  *    written permission of Ralf S. Engelschall.
  39.  *
  40.  * 6. Redistributions of any form whatsoever must retain the following
  41.  *    acknowledgment:
  42.  *    "This product includes software developed by
  43.  *     Ralf S. Engelschall <rse@engelschall.com> for use in the
  44.  *     mod_ssl project (http://www.modssl.org/)."
  45.  *
  46.  * THIS SOFTWARE IS PROVIDED BY RALF S. ENGELSCHALL ``AS IS'' AND ANY
  47.  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  48.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  49.  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL RALF S. ENGELSCHALL OR
  50.  * HIS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  51.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  52.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  53.  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  54.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  55.  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  56.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  57.  * OF THE POSSIBILITY OF SUCH DAMAGE.
  58.  * ====================================================================
  59.  */
  60. /*
  61.  * sdbm - ndbm work-alike hashed database library
  62.  * based on Per-Ake Larson's Dynamic Hashing algorithms. BIT 18 (1978).
  63.  * author: oz@nexus.yorku.ca
  64.  * status: public domain.
  65.  */
  66. #ifndef SSL_UTIL_SDBM_H
  67. #define SSL_UTIL_SDBM_H
  68. #define DUFF    /* go ahead and use the loop-unrolled version */
  69. #include <stdio.h>
  70. #ifdef MOD_SSL
  71. #define DBLKSIZ 16384                   /* SSL cert chains require more */
  72. #define PBLKSIZ 8192                    /* SSL cert chains require more */
  73. #define PAIRMAX 8008                    /* arbitrary on PBLKSIZ-N */
  74. #else
  75. #define DBLKSIZ 4096
  76. #define PBLKSIZ 1024
  77. #define PAIRMAX 1008                    /* arbitrary on PBLKSIZ-N */
  78. #endif
  79. #define SPLTMAX 10                      /* maximum allowed splits */
  80.                                         /* for a single insertion */
  81. #define DIRFEXT ".dir"
  82. #define PAGFEXT ".pag"
  83. typedef struct {
  84.         int dirf;                      /* directory file descriptor */
  85.         int pagf;                      /* page file descriptor */
  86.         int flags;                     /* status/error flags, see below */
  87.         long maxbno;                   /* size of dirfile in bits */
  88.         long curbit;                   /* current bit number */
  89.         long hmask;                    /* current hash mask */
  90.         long blkptr;                   /* current block for nextkey */
  91.         int keyptr;                    /* current key for nextkey */
  92.         long blkno;                    /* current page to read/write */
  93.         long pagbno;                   /* current page in pagbuf */
  94.         char pagbuf[PBLKSIZ];          /* page file block buffer */
  95.         long dirbno;                   /* current block in dirbuf */
  96.         char dirbuf[DBLKSIZ];          /* directory file block buffer */
  97. } DBM;
  98. #define DBM_RDONLY      0x1            /* data base open read-only */
  99. #define DBM_IOERR       0x2            /* data base I/O error */
  100. /*
  101.  * utility macros
  102.  */
  103. #define sdbm_rdonly(db)         ((db)->flags & DBM_RDONLY)
  104. #define sdbm_error(db)          ((db)->flags & DBM_IOERR)
  105. #define sdbm_clearerr(db)       ((db)->flags &= ~DBM_IOERR)  /* ouch */
  106. #define sdbm_dirfno(db) ((db)->dirf)
  107. #define sdbm_pagfno(db) ((db)->pagf)
  108. typedef struct {
  109.         char *dptr;
  110.         int dsize;
  111. } datum;
  112. extern datum nullitem;
  113. #ifdef __STDC__
  114. #define proto(p) p
  115. #else
  116. #define proto(p) ()
  117. #endif
  118. /*
  119.  * flags to sdbm_store
  120.  */
  121. #define DBM_INSERT      0
  122. #define DBM_REPLACE     1
  123. /*
  124.  * ndbm interface
  125.  */
  126. extern DBM *sdbm_open proto((char *, int, int));
  127. extern void sdbm_close proto((DBM *));
  128. extern datum sdbm_fetch proto((DBM *, datum));
  129. extern int sdbm_delete proto((DBM *, datum));
  130. extern int sdbm_store proto((DBM *, datum, datum, int));
  131. extern datum sdbm_firstkey proto((DBM *));
  132. extern datum sdbm_nextkey proto((DBM *));
  133. /*
  134.  * other
  135.  */
  136. extern DBM *sdbm_prep proto((char *, char *, int, int));
  137. extern long sdbm_hash proto((char *, int));
  138. /* pair.h */
  139. extern int fitpair proto((char *, int));
  140. extern void  putpair proto((char *, datum, datum));
  141. extern datum    getpair proto((char *, datum));
  142. extern int  delpair proto((char *, datum));
  143. extern int  chkpage proto((char *));
  144. extern datum getnkey proto((char *, int));
  145. extern void splpage proto((char *, char *, long));
  146. extern int duppair proto((char *, datum));
  147. /* tune.h */
  148. /*
  149.  * sdbm - ndbm work-alike hashed database library
  150.  * tuning and portability constructs [not nearly enough]
  151.  * author: oz@nexus.yorku.ca
  152.  */
  153. #define BYTESIZ         8
  154. /*
  155.  * important tuning parms (hah)
  156.  */
  157. #define SEEDUPS                 /* always detect duplicates */
  158. #define BADMESS                 /* generate a message for worst case:
  159.                                    cannot make room after SPLTMAX splits */
  160. /*
  161.  * misc
  162.  */
  163. #ifdef DEBUG
  164. #define debug(x)        printf x
  165. #else
  166. #define debug(x)
  167. #endif
  168. #endif /* SSL_UTIL_SDBM_H */