1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
18
#include "apr_errno.h"
19
#include "apr_pools.h"
20
#include "apr_strings.h"
21
#define APR_WANT_MEMFUNC
22
#define APR_WANT_STRFUNC
24
#include "apr_general.h"
27
#include "apu_select_dbm.h"
29
#include "apr_dbm_private.h"
31
/* ### note: the setting of DBM_VTABLE will go away once we have multiple
33
### Well, that day is here. So, do we remove DBM_VTABLE and the old
34
### API entirely? Oh, what to do. We need an APU_DEFAULT_DBM #define.
35
### Sounds like a job for autoconf. */
38
#define DBM_VTABLE apr_dbm_type_sdbm
40
#define DBM_VTABLE apr_dbm_type_gdbm
42
#define DBM_VTABLE apr_dbm_type_db
44
#define DBM_VTABLE apr_dbm_type_ndbm
45
#else /* Not in the USE_xDBM list above */
46
#error a DBM implementation was not specified
49
APU_DECLARE(apr_status_t) apr_dbm_open_ex(apr_dbm_t **pdb, const char*type,
51
apr_int32_t mode, apr_fileperms_t perm,
55
if (!strcasecmp(type, "GDBM")) {
56
return (*apr_dbm_type_gdbm.open)(pdb, pathname, mode, perm, pool);
60
if (!strcasecmp(type, "SDBM")) {
61
return (*apr_dbm_type_sdbm.open)(pdb, pathname, mode, perm, pool);
65
if (!strcasecmp(type, "DB")) {
66
return (*apr_dbm_type_db.open)(pdb, pathname, mode, perm, pool);
70
if (!strcasecmp(type, "NDBM")) {
71
return (*apr_dbm_type_ndbm.open)(pdb, pathname, mode, perm, pool);
75
if (!strcasecmp(type, "default")) {
76
return (*DBM_VTABLE.open)(pdb, pathname, mode, perm, pool);
82
APU_DECLARE(apr_status_t) apr_dbm_open(apr_dbm_t **pdb, const char *pathname,
83
apr_int32_t mode, apr_fileperms_t perm,
86
return (*DBM_VTABLE.open)(pdb, pathname, mode, perm, pool);
89
APU_DECLARE(void) apr_dbm_close(apr_dbm_t *dbm)
91
(*dbm->type->close)(dbm);
94
APU_DECLARE(apr_status_t) apr_dbm_fetch(apr_dbm_t *dbm, apr_datum_t key,
97
return (*dbm->type->fetch)(dbm, key, pvalue);
100
APU_DECLARE(apr_status_t) apr_dbm_store(apr_dbm_t *dbm, apr_datum_t key,
103
return (*dbm->type->store)(dbm, key, value);
106
APU_DECLARE(apr_status_t) apr_dbm_delete(apr_dbm_t *dbm, apr_datum_t key)
108
return (*dbm->type->del)(dbm, key);
111
APU_DECLARE(int) apr_dbm_exists(apr_dbm_t *dbm, apr_datum_t key)
113
return (*dbm->type->exists)(dbm, key);
116
APU_DECLARE(apr_status_t) apr_dbm_firstkey(apr_dbm_t *dbm, apr_datum_t *pkey)
118
return (*dbm->type->firstkey)(dbm, pkey);
121
APU_DECLARE(apr_status_t) apr_dbm_nextkey(apr_dbm_t *dbm, apr_datum_t *pkey)
123
return (*dbm->type->nextkey)(dbm, pkey);
126
APU_DECLARE(void) apr_dbm_freedatum(apr_dbm_t *dbm, apr_datum_t data)
128
(*dbm->type->freedatum)(dbm, data);
131
APU_DECLARE(char *) apr_dbm_geterror(apr_dbm_t *dbm, int *errcode,
132
char *errbuf, apr_size_t errbufsize)
135
*errcode = dbm->errcode;
137
/* assert: errbufsize > 0 */
139
if (dbm->errmsg == NULL)
142
(void) apr_cpystrn(errbuf, dbm->errmsg, errbufsize);
146
APU_DECLARE(apr_status_t) apr_dbm_get_usednames_ex(apr_pool_t *p,
148
const char *pathname,
153
if (!strcasecmp(type, "GDBM")) {
154
(*apr_dbm_type_gdbm.getusednames)(p,pathname,used1,used2);
159
if (!strcasecmp(type, "SDBM")) {
160
(*apr_dbm_type_sdbm.getusednames)(p,pathname,used1,used2);
165
if (!strcasecmp(type, "DB")) {
166
(*apr_dbm_type_db.getusednames)(p,pathname,used1,used2);
171
if (!strcasecmp(type, "NDBM")) {
172
(*apr_dbm_type_ndbm.getusednames)(p,pathname,used1,used2);
177
if (!strcasecmp(type, "default")) {
178
(*DBM_VTABLE.getusednames)(p, pathname, used1, used2);
185
APU_DECLARE(void) apr_dbm_get_usednames(apr_pool_t *p,
186
const char *pathname,
190
/* ### one day, a DBM type name will be passed and we'll need to look it
191
### up. for now, it is constant. */
193
(*DBM_VTABLE.getusednames)(p, pathname, used1, used2);
196
/* Most DBM libraries take a POSIX mode for creating files. Don't trust
197
* the mode_t type, some platforms may not support it, int is safe.
199
APU_DECLARE(int) apr_posix_perms2mode(apr_fileperms_t perm)
203
mode |= 0700 & (perm >> 2); /* User is off-by-2 bits */
204
mode |= 0070 & (perm >> 1); /* Group is off-by-1 bit */
205
mode |= 0007 & (perm); /* World maps 1 for 1 */