Apache HTTPD
apr_dbm_sdbm.c
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17#include "apr_strings.h"
18#define APR_WANT_MEMFUNC
19#define APR_WANT_STRFUNC
20#include "apr_want.h"
21
22#include "apu_config.h"
23#include "apu.h"
24
25#if APU_HAVE_SDBM
26
27#include "apr_dbm_private.h"
28#include "apr_sdbm.h"
29
30#define APR_DBM_DBMODE_RO (APR_FOPEN_READ | APR_FOPEN_BUFFERED)
31#define APR_DBM_DBMODE_RW (APR_FOPEN_READ | APR_FOPEN_WRITE)
32#define APR_DBM_DBMODE_RWCREATE (APR_FOPEN_READ | APR_FOPEN_WRITE | APR_FOPEN_CREATE)
33#define APR_DBM_DBMODE_RWTRUNC (APR_FOPEN_READ | APR_FOPEN_WRITE | APR_FOPEN_CREATE | \
34 APR_FOPEN_TRUNCATE)
35
37{
38 dbm->errcode = dbm_said;
39
40 if (dbm_said != APR_SUCCESS) {
41 dbm->errmsg = apr_psprintf(dbm->pool, "%pm", &dbm_said);
42 } else {
43 dbm->errmsg = NULL;
44 }
45
46 return dbm_said;
47}
48
49/* --------------------------------------------------------------------------
50**
51** DEFINE THE VTABLE FUNCTIONS FOR SDBM
52*/
53
54static apr_status_t vt_sdbm_open(apr_dbm_t **pdb, const char *pathname,
57{
59 int dbmode;
60
61 *pdb = NULL;
62
63 switch (mode) {
66 break;
69 break;
72 break;
73 case APR_DBM_RWTRUNC:
75 break;
76 default:
77 return APR_EINVAL;
78 }
79
80 {
81 apr_status_t rv;
82
84 if (rv != APR_SUCCESS)
85 return rv;
86 }
87
88 /* we have an open database... return it */
89 *pdb = apr_pcalloc(pool, sizeof(**pdb));
90 (*pdb)->pool = pool;
91 (*pdb)->type = &apr_dbm_type_sdbm;
92 (*pdb)->file = file;
93
94 /* ### register a cleanup to close the DBM? */
95
96 return APR_SUCCESS;
97}
98
99static void vt_sdbm_close(apr_dbm_t *dbm)
100{
101 apr_sdbm_close(dbm->file);
102}
103
106{
107 apr_status_t rv;
109
110 kd.dptr = key.dptr;
111 kd.dsize = (int)key.dsize;
112
113 rv = apr_sdbm_fetch(dbm->file, &rd, kd);
114
115 pvalue->dptr = rd.dptr;
116 pvalue->dsize = rd.dsize;
117
118 /* store the error info into DBM, and return a status code. Also, note
119 that *pvalue should have been cleared on error. */
120 return set_error(dbm, rv);
121}
122
125{
126 apr_status_t rv;
128
129 kd.dptr = key.dptr;
130 kd.dsize = (int)key.dsize;
131
132 vd.dptr = value.dptr;
133 vd.dsize = (int)value.dsize;
134
135 rv = apr_sdbm_store(dbm->file, kd, vd, APR_SDBM_REPLACE);
136
137 /* store any error info into DBM, and return a status code. */
138 return set_error(dbm, rv);
139}
140
142{
143 apr_status_t rv;
145
146 kd.dptr = key.dptr;
147 kd.dsize = (int)key.dsize;
148
149 rv = apr_sdbm_delete(dbm->file, kd);
150
151 /* store any error info into DBM, and return a status code. */
152 return set_error(dbm, rv);
153}
154
156{
157 int exists;
159
160 kd.dptr = key.dptr;
161 kd.dsize = (int)key.dsize;
162
163 if (apr_sdbm_fetch(dbm->file, &vd, kd) != APR_SUCCESS)
164 exists = 0;
165 else
166 exists = vd.dptr != NULL;
167
168 return exists;
169}
170
172{
173 apr_status_t rv;
175
176 rv = apr_sdbm_firstkey(dbm->file, &rd);
177
178 pkey->dptr = rd.dptr;
179 pkey->dsize = rd.dsize;
180
181 /* store any error info into DBM, and return a status code. */
182 return set_error(dbm, rv);
183}
184
186{
188
189 (void)apr_sdbm_nextkey(dbm->file, &rd);
190
191 pkey->dptr = rd.dptr;
192 pkey->dsize = rd.dsize;
193
194 /* store any error info into DBM, and return a status code. */
195 return set_error(dbm, APR_SUCCESS);
196}
197
199{
200}
201
202static void vt_sdbm_usednames(apr_pool_t *pool, const char *pathname,
203 const char **used1, const char **used2)
204{
207}
208
210 "sdbm",
221};
222
223#endif /* APU_HAVE_SDBM */
APU_MODULE_DECLARE_DATA const apr_dbm_type_t apr_dbm_type_sdbm
apr-util SDBM library
APR Strings library.
APR Standard Headers Support.
#define APR_EINVAL
Definition apr_errno.h:711
apr_dbd_transaction_t int mode
Definition apr_dbd.h:261
#define APR_SDBM_REPLACE
Definition apr_sdbm.h:65
#define APR_SDBM_PAGFEXT
Definition apr_sdbm.h:61
#define APR_SDBM_DIRFEXT
Definition apr_sdbm.h:59
apr_datum_t * pkey
Definition apr_dbm.h:158
apr_datum_t apr_datum_t * pvalue
Definition apr_dbm.h:128
#define APR_DBM_RWTRUNC
Definition apr_dbm.h:59
#define APR_DBM_RWCREATE
Definition apr_dbm.h:58
#define APR_DBM_READONLY
Definition apr_dbm.h:56
const char const char const char const char ** used2
Definition apr_dbm.h:203
const char const char const char ** used1
Definition apr_dbm.h:202
#define APR_DBM_READWRITE
Definition apr_dbm.h:57
const char const char * pathname
Definition apr_dbm.h:201
apr_size_t size
const char int apr_pool_t * pool
Definition apr_cstr.h:84
const char * value
Definition apr_env.h:51
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
apr_int32_t apr_fileperms_t
const char * key
void * data
const char apr_file_t * file
const char apr_int32_t apr_fileperms_t perm
#define apr_pcalloc(p, size)
Definition apr_pools.h:465
return NULL
Definition mod_so.c:359
apr_size_t dsize
Definition apr_dbm.h:52
char * dptr
Definition apr_dbm.h:50
typedef int(WSAAPI *apr_winapi_fpt_WSAPoll)(IN OUT LPWSAPOLLFD fdArray