1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/nss/lib/dbm/include/mcom_db.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,420 @@ 1.4 +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/*- 1.6 + * Copyright (c) 1990, 1993, 1994 1.7 + * The Regents of the University of California. All rights reserved. 1.8 + * 1.9 + * Redistribution and use in source and binary forms, with or without 1.10 + * modification, are permitted provided that the following conditions 1.11 + * are met: 1.12 + * 1. Redistributions of source code must retain the above copyright 1.13 + * notice, this list of conditions and the following disclaimer. 1.14 + * 2. Redistributions in binary form must reproduce the above copyright 1.15 + * notice, this list of conditions and the following disclaimer in the 1.16 + * documentation and/or other materials provided with the distribution. 1.17 + * 3. ***REMOVED*** - see 1.18 + * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change 1.19 + * 4. Neither the name of the University nor the names of its contributors 1.20 + * may be used to endorse or promote products derived from this software 1.21 + * without specific prior written permission. 1.22 + * 1.23 + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 1.24 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1.25 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1.26 + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 1.27 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1.28 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 1.29 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 1.30 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 1.31 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 1.32 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 1.33 + * SUCH DAMAGE. 1.34 + * 1.35 + * @(#)db.h 8.7 (Berkeley) 6/16/94 1.36 + */ 1.37 + 1.38 +#ifndef _DB_H_ 1.39 +#define _DB_H_ 1.40 + 1.41 +#ifndef macintosh 1.42 +#include <sys/types.h> 1.43 +#endif 1.44 +#include "prtypes.h" 1.45 + 1.46 +#if !defined(XP_BEOS) && !defined(XP_OS2) && !defined(XP_UNIX) || defined(NTO) 1.47 +typedef PRUintn uint; 1.48 +#endif 1.49 +typedef PRUint8 uint8; 1.50 +typedef PRUint16 uint16; 1.51 +/* On AIX 5.2, sys/inttypes.h (which is included by sys/types.h) 1.52 + * defines the types int8, int16, int32, and int64. */ 1.53 +#if !defined(AIX) 1.54 +typedef PRInt32 int32; 1.55 +#endif 1.56 +typedef PRUint32 uint32; 1.57 + 1.58 +#include <limits.h> 1.59 + 1.60 +#ifdef __DBINTERFACE_PRIVATE 1.61 + 1.62 +#ifdef HAVE_SYS_CDEFS_H 1.63 +#include <sys/cdefs.h> 1.64 +#else 1.65 +#include "cdefs.h" 1.66 +#endif 1.67 + 1.68 +#ifdef HAVE_SYS_BYTEORDER_H 1.69 +#include <sys/byteorder.h> 1.70 +#endif 1.71 + 1.72 +#if defined(__linux) || defined(__BEOS__) 1.73 +#include <endian.h> 1.74 +#ifndef BYTE_ORDER 1.75 +#define BYTE_ORDER __BYTE_ORDER 1.76 +#define BIG_ENDIAN __BIG_ENDIAN 1.77 +#define LITTLE_ENDIAN __LITTLE_ENDIAN 1.78 +#endif 1.79 +#endif /* __linux */ 1.80 + 1.81 +#ifdef __sgi 1.82 +#define BYTE_ORDER BIG_ENDIAN 1.83 +#define BIG_ENDIAN 4321 1.84 +#define LITTLE_ENDIAN 1234 /* LSB first: i386, vax, all NT risc */ 1.85 +#endif 1.86 + 1.87 +#ifdef __sun 1.88 +#define BIG_ENDIAN 4321 1.89 +#define LITTLE_ENDIAN 1234 /* LSB first: i386, vax, all NT risc */ 1.90 + 1.91 +#ifndef __SVR4 1.92 +/* compat.h is only in 4.1.3 machines. - dp */ 1.93 +#include <compat.h> 1.94 +#endif 1.95 + 1.96 +/* XXX - dp 1.97 + * Need to find a general way of defining endian-ness in SunOS 5.3 1.98 + * SunOS 5.4 defines _BIG_ENDIAN and _LITTLE_ENDIAN 1.99 + * SunOS 5.3 does nothing like this. 1.100 + */ 1.101 + 1.102 +#ifndef BYTE_ORDER 1.103 + 1.104 +#if defined(_BIG_ENDIAN) 1.105 +#define BYTE_ORDER BIG_ENDIAN 1.106 +#elif defined(_LITTLE_ENDIAN) 1.107 +#define BYTE_ORDER LITTLE_ENDIAN 1.108 +#elif !defined(__SVR4) 1.109 +/* 4.1.3 is always BIG_ENDIAN as it was released only on sparc platforms. */ 1.110 +#define BYTE_ORDER BIG_ENDIAN 1.111 +#elif !defined(vax) && !defined(ntohl) && !defined(lint) && !defined(i386) 1.112 +/* 5.3 big endian. Copied this above line from sys/byteorder.h */ 1.113 +/* Now we are in a 5.3 SunOS rather non 5.4 or above SunOS */ 1.114 +#define BYTE_ORDER BIG_ENDIAN 1.115 +#else 1.116 +#define BYTE_ORDER LITTLE_ENDIAN 1.117 +#endif 1.118 + 1.119 +#endif /* !BYTE_ORDER */ 1.120 +#endif /* __sun */ 1.121 + 1.122 +#if defined(__hpux) || defined(__hppa) 1.123 +#define BYTE_ORDER BIG_ENDIAN 1.124 +#define BIG_ENDIAN 4321 1.125 +#define LITTLE_ENDIAN 1234 /* LSB first: i386, vax, all NT risc */ 1.126 +#endif 1.127 + 1.128 +#if defined(AIXV3) || defined(AIX) 1.129 +/* BYTE_ORDER, LITTLE_ENDIAN, BIG_ENDIAN are all defined here */ 1.130 +#include <sys/machine.h> 1.131 +#endif 1.132 + 1.133 +/* Digital Unix */ 1.134 +#ifdef __osf__ 1.135 +#include <machine/endian.h> 1.136 +#endif 1.137 + 1.138 +#ifdef __alpha 1.139 +#ifndef WIN32 1.140 +#else 1.141 +/* Alpha NT */ 1.142 +#define BYTE_ORDER LITTLE_ENDIAN 1.143 +#define BIG_ENDIAN 4321 1.144 +#define LITTLE_ENDIAN 1234 1.145 +#endif 1.146 +#endif 1.147 + 1.148 +#ifdef NCR 1.149 +#include <sys/endian.h> 1.150 +#endif 1.151 + 1.152 +#ifdef __QNX__ 1.153 +#ifdef __QNXNTO__ 1.154 +#include <sys/param.h> 1.155 +#else 1.156 +#define LITTLE_ENDIAN 1234 1.157 +#define BIG_ENDIAN 4321 1.158 +#define BYTE_ORDER LITTLE_ENDIAN 1.159 +#endif 1.160 +#endif 1.161 + 1.162 +#ifdef SNI 1.163 +/* #include <sys/hetero.h> */ 1.164 +#define BYTE_ORDER BIG_ENDIAN 1.165 +#define BIG_ENDIAN 4321 1.166 +#define LITTLE_ENDIAN 1234 1.167 +#endif 1.168 + 1.169 +#ifdef _WINDOWS 1.170 +#ifdef BYTE_ORDER 1.171 +#undef BYTE_ORDER 1.172 +#endif 1.173 + 1.174 +#define BYTE_ORDER LITTLE_ENDIAN 1.175 +#define LITTLE_ENDIAN 1234 /* LSB first: i386, vax, all NT risc */ 1.176 +#define BIG_ENDIAN 4321 1.177 +#endif 1.178 + 1.179 +#ifdef macintosh 1.180 +#define BIG_ENDIAN 4321 1.181 +#define LITTLE_ENDIAN 1234 1.182 +#define BYTE_ORDER BIG_ENDIAN 1.183 +#endif 1.184 + 1.185 +#endif /* __DBINTERFACE_PRIVATE */ 1.186 + 1.187 +#ifdef SCO 1.188 +#define MAXPATHLEN 1024 1.189 +#endif 1.190 + 1.191 +#include <fcntl.h> 1.192 + 1.193 +#if defined(_WINDOWS) || defined(XP_OS2) 1.194 +#include <stdio.h> 1.195 +#include <io.h> 1.196 + 1.197 +#ifndef XP_OS2 1.198 +#define MAXPATHLEN 1024 1.199 +#endif 1.200 + 1.201 +#define EFTYPE EINVAL /* POSIX 1003.1 format errno. */ 1.202 + 1.203 +#ifndef STDERR_FILENO 1.204 +#define STDIN_FILENO 0 /* ANSI C #defines */ 1.205 +#define STDOUT_FILENO 1 1.206 +#define STDERR_FILENO 2 1.207 +#endif 1.208 + 1.209 +#ifndef O_ACCMODE /* POSIX 1003.1 access mode mask. */ 1.210 +#define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR) 1.211 +#endif 1.212 +#endif 1.213 + 1.214 +#ifdef macintosh 1.215 +#include <stdio.h> 1.216 +#include "xp_mcom.h" 1.217 +#define O_ACCMODE 3 /* Mask for file access modes */ 1.218 +#define EFTYPE 2000 1.219 +PR_BEGIN_EXTERN_C 1.220 +int mkstemp(const char *path); 1.221 +PR_END_EXTERN_C 1.222 +#endif /* MACINTOSH */ 1.223 + 1.224 +#if !defined(_WINDOWS) && !defined(macintosh) 1.225 +#include <sys/stat.h> 1.226 +#include <errno.h> 1.227 +#endif 1.228 + 1.229 +/* define EFTYPE since most don't */ 1.230 +#ifndef EFTYPE 1.231 +#define EFTYPE EINVAL /* POSIX 1003.1 format errno. */ 1.232 +#endif 1.233 + 1.234 +#define RET_ERROR -1 /* Return values. */ 1.235 +#define RET_SUCCESS 0 1.236 +#define RET_SPECIAL 1 1.237 + 1.238 +#define MAX_PAGE_NUMBER 0xffffffff /* >= # of pages in a file */ 1.239 + 1.240 +#ifndef __sgi 1.241 +typedef uint32 pgno_t; 1.242 +#endif 1.243 + 1.244 +#define MAX_PAGE_OFFSET 65535 /* >= # of bytes in a page */ 1.245 +typedef uint16 indx_t; 1.246 +#define MAX_REC_NUMBER 0xffffffff /* >= # of records in a tree */ 1.247 +typedef uint32 recno_t; 1.248 + 1.249 +/* Key/data structure -- a Data-Base Thang. */ 1.250 +typedef struct { 1.251 + void *data; /* data */ 1.252 + size_t size; /* data length */ 1.253 +} DBT; 1.254 + 1.255 +/* Routine flags. */ 1.256 +#define R_CURSOR 1 /* del, put, seq */ 1.257 +#define __R_UNUSED 2 /* UNUSED */ 1.258 +#define R_FIRST 3 /* seq */ 1.259 +#define R_IAFTER 4 /* put (RECNO) */ 1.260 +#define R_IBEFORE 5 /* put (RECNO) */ 1.261 +#define R_LAST 6 /* seq (BTREE, RECNO) */ 1.262 +#define R_NEXT 7 /* seq */ 1.263 +#define R_NOOVERWRITE 8 /* put */ 1.264 +#define R_PREV 9 /* seq (BTREE, RECNO) */ 1.265 +#define R_SETCURSOR 10 /* put (RECNO) */ 1.266 +#define R_RECNOSYNC 11 /* sync (RECNO) */ 1.267 + 1.268 +typedef enum { DB_BTREE, DB_HASH, DB_RECNO } DBTYPE; 1.269 + 1.270 +typedef enum { LockOutDatabase, UnlockDatabase } DBLockFlagEnum; 1.271 + 1.272 +/* 1.273 + * !!! 1.274 + * The following flags are included in the dbopen(3) call as part of the 1.275 + * open(2) flags. In order to avoid conflicts with the open flags, start 1.276 + * at the top of the 16 or 32-bit number space and work our way down. If 1.277 + * the open flags were significantly expanded in the future, it could be 1.278 + * a problem. Wish I'd left another flags word in the dbopen call. 1.279 + * 1.280 + * !!! 1.281 + * None of this stuff is implemented yet. The only reason that it's here 1.282 + * is so that the access methods can skip copying the key/data pair when 1.283 + * the DB_LOCK flag isn't set. 1.284 + */ 1.285 +#if UINT_MAX > 65535 1.286 +#define DB_LOCK 0x20000000 /* Do locking. */ 1.287 +#define DB_SHMEM 0x40000000 /* Use shared memory. */ 1.288 +#define DB_TXN 0x80000000 /* Do transactions. */ 1.289 +#else 1.290 +#define DB_LOCK 0x2000 /* Do locking. */ 1.291 +#define DB_SHMEM 0x4000 /* Use shared memory. */ 1.292 +#define DB_TXN 0x8000 /* Do transactions. */ 1.293 +#endif 1.294 + 1.295 +/* Access method description structure. */ 1.296 +typedef struct __db { 1.297 + DBTYPE type; /* Underlying db type. */ 1.298 + int (*close) (struct __db *); 1.299 + int (*del) (const struct __db *, const DBT *, uint); 1.300 + int (*get) (const struct __db *, const DBT *, DBT *, uint); 1.301 + int (*put) (const struct __db *, DBT *, const DBT *, uint); 1.302 + int (*seq) (const struct __db *, DBT *, DBT *, uint); 1.303 + int (*sync) (const struct __db *, uint); 1.304 + void *internal; /* Access method private. */ 1.305 + int (*fd) (const struct __db *); 1.306 +} DB; 1.307 + 1.308 +#define BTREEMAGIC 0x053162 1.309 +#define BTREEVERSION 3 1.310 + 1.311 +/* Structure used to pass parameters to the btree routines. */ 1.312 +typedef struct { 1.313 +#define R_DUP 0x01 /* duplicate keys */ 1.314 + uint32 flags; 1.315 + uint cachesize; /* bytes to cache */ 1.316 + int maxkeypage; /* maximum keys per page */ 1.317 + int minkeypage; /* minimum keys per page */ 1.318 + uint psize; /* page size */ 1.319 + int (*compare) /* comparison function */ 1.320 + (const DBT *, const DBT *); 1.321 + size_t (*prefix) /* prefix function */ 1.322 + (const DBT *, const DBT *); 1.323 + int lorder; /* byte order */ 1.324 +} BTREEINFO; 1.325 + 1.326 +#define HASHMAGIC 0x061561 1.327 +#define HASHVERSION 2 1.328 + 1.329 +/* Structure used to pass parameters to the hashing routines. */ 1.330 +typedef struct { 1.331 + uint bsize; /* bucket size */ 1.332 + uint ffactor; /* fill factor */ 1.333 + uint nelem; /* number of elements */ 1.334 + uint cachesize; /* bytes to cache */ 1.335 + uint32 /* hash function */ 1.336 + (*hash) (const void *, size_t); 1.337 + int lorder; /* byte order */ 1.338 +} HASHINFO; 1.339 + 1.340 +/* Structure used to pass parameters to the record routines. */ 1.341 +typedef struct { 1.342 +#define R_FIXEDLEN 0x01 /* fixed-length records */ 1.343 +#define R_NOKEY 0x02 /* key not required */ 1.344 +#define R_SNAPSHOT 0x04 /* snapshot the input */ 1.345 + uint32 flags; 1.346 + uint cachesize; /* bytes to cache */ 1.347 + uint psize; /* page size */ 1.348 + int lorder; /* byte order */ 1.349 + size_t reclen; /* record length (fixed-length records) */ 1.350 + uint8 bval; /* delimiting byte (variable-length records */ 1.351 + char *bfname; /* btree file name */ 1.352 +} RECNOINFO; 1.353 + 1.354 +#ifdef __DBINTERFACE_PRIVATE 1.355 +/* 1.356 + * Little endian <==> big endian 32-bit swap macros. 1.357 + * M_32_SWAP swap a memory location 1.358 + * P_32_SWAP swap a referenced memory location 1.359 + * P_32_COPY swap from one location to another 1.360 + */ 1.361 +#define M_32_SWAP(a) { \ 1.362 + uint32 _tmp = a; \ 1.363 + ((char *)&a)[0] = ((char *)&_tmp)[3]; \ 1.364 + ((char *)&a)[1] = ((char *)&_tmp)[2]; \ 1.365 + ((char *)&a)[2] = ((char *)&_tmp)[1]; \ 1.366 + ((char *)&a)[3] = ((char *)&_tmp)[0]; \ 1.367 +} 1.368 +#define P_32_SWAP(a) { \ 1.369 + uint32 _tmp = *(uint32 *)a; \ 1.370 + ((char *)a)[0] = ((char *)&_tmp)[3]; \ 1.371 + ((char *)a)[1] = ((char *)&_tmp)[2]; \ 1.372 + ((char *)a)[2] = ((char *)&_tmp)[1]; \ 1.373 + ((char *)a)[3] = ((char *)&_tmp)[0]; \ 1.374 +} 1.375 +#define P_32_COPY(a, b) { \ 1.376 + ((char *)&(b))[0] = ((char *)&(a))[3]; \ 1.377 + ((char *)&(b))[1] = ((char *)&(a))[2]; \ 1.378 + ((char *)&(b))[2] = ((char *)&(a))[1]; \ 1.379 + ((char *)&(b))[3] = ((char *)&(a))[0]; \ 1.380 +} 1.381 + 1.382 +/* 1.383 + * Little endian <==> big endian 16-bit swap macros. 1.384 + * M_16_SWAP swap a memory location 1.385 + * P_16_SWAP swap a referenced memory location 1.386 + * P_16_COPY swap from one location to another 1.387 + */ 1.388 +#define M_16_SWAP(a) { \ 1.389 + uint16 _tmp = a; \ 1.390 + ((char *)&a)[0] = ((char *)&_tmp)[1]; \ 1.391 + ((char *)&a)[1] = ((char *)&_tmp)[0]; \ 1.392 +} 1.393 +#define P_16_SWAP(a) { \ 1.394 + uint16 _tmp = *(uint16 *)a; \ 1.395 + ((char *)a)[0] = ((char *)&_tmp)[1]; \ 1.396 + ((char *)a)[1] = ((char *)&_tmp)[0]; \ 1.397 +} 1.398 +#define P_16_COPY(a, b) { \ 1.399 + ((char *)&(b))[0] = ((char *)&(a))[1]; \ 1.400 + ((char *)&(b))[1] = ((char *)&(a))[0]; \ 1.401 +} 1.402 +#endif 1.403 + 1.404 +PR_BEGIN_EXTERN_C 1.405 + 1.406 +extern DB * 1.407 +dbopen (const char *, int, int, DBTYPE, const void *); 1.408 + 1.409 +/* set or unset a global lock flag to disable the 1.410 + * opening of any DBM file 1.411 + */ 1.412 +void dbSetOrClearDBLock(DBLockFlagEnum type); 1.413 + 1.414 +#ifdef __DBINTERFACE_PRIVATE 1.415 +DB *__bt_open (const char *, int, int, const BTREEINFO *, int); 1.416 +DB *__hash_open (const char *, int, int, const HASHINFO *, int); 1.417 +DB *__rec_open (const char *, int, int, const RECNOINFO *, int); 1.418 +void __dbpanic (DB *dbp); 1.419 +#endif 1.420 + 1.421 +PR_END_EXTERN_C 1.422 + 1.423 +#endif /* !_DB_H_ */