~ubuntu-branches/ubuntu/feisty/apache2/feisty

« back to all changes in this revision

Viewing changes to srclib/apr-util/dbm/apr_dbm.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Barth
  • Date: 2006-12-09 21:05:45 UTC
  • mfrom: (0.6.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061209210545-h70s0xaqc2v8vqr2
Tags: 2.2.3-3.2
* Non-maintainer upload.
* 043_ajp_connection_reuse: Patch from upstream Bugzilla, fixing a critical
  issue with regard to connection reuse in mod_proxy_ajp.
  Closes: #396265

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
 
2
 * applicable.
 
3
 *
 
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
 
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.h"
 
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
 
23
#include "apr_want.h"
 
24
#include "apr_general.h"
 
25
 
 
26
#include "apu.h"
 
27
#include "apu_select_dbm.h"
 
28
#include "apr_dbm.h"
 
29
#include "apr_dbm_private.h"
 
30
 
 
31
/* ### note: the setting of DBM_VTABLE will go away once we have multiple
 
32
   ### DBMs in here. 
 
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. */
 
36
 
 
37
#if APU_USE_SDBM
 
38
#define DBM_VTABLE apr_dbm_type_sdbm
 
39
#elif APU_USE_GDBM
 
40
#define DBM_VTABLE apr_dbm_type_gdbm
 
41
#elif APU_USE_DB
 
42
#define DBM_VTABLE apr_dbm_type_db
 
43
#elif APU_USE_NDBM
 
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
 
47
#endif
 
48
 
 
49
APU_DECLARE(apr_status_t) apr_dbm_open_ex(apr_dbm_t **pdb, const char*type, 
 
50
                                       const char *pathname, 
 
51
                                       apr_int32_t mode, apr_fileperms_t perm,
 
52
                                       apr_pool_t *pool)
 
53
{
 
54
#if APU_HAVE_GDBM
 
55
    if (!strcasecmp(type, "GDBM")) {
 
56
        return (*apr_dbm_type_gdbm.open)(pdb, pathname, mode, perm, pool);
 
57
    }
 
58
#endif
 
59
#if APU_HAVE_SDBM
 
60
    if (!strcasecmp(type, "SDBM")) {
 
61
        return (*apr_dbm_type_sdbm.open)(pdb, pathname, mode, perm, pool);
 
62
    }
 
63
#endif
 
64
#if APU_HAVE_DB
 
65
    if (!strcasecmp(type, "DB")) {
 
66
        return (*apr_dbm_type_db.open)(pdb, pathname, mode, perm, pool);
 
67
    }
 
68
#endif
 
69
#if APU_HAVE_NDBM
 
70
    if (!strcasecmp(type, "NDBM")) {
 
71
        return (*apr_dbm_type_ndbm.open)(pdb, pathname, mode, perm, pool);
 
72
    }
 
73
#endif
 
74
 
 
75
    if (!strcasecmp(type, "default")) {
 
76
        return (*DBM_VTABLE.open)(pdb, pathname, mode, perm, pool);
 
77
    }
 
78
 
 
79
    return APR_ENOTIMPL;
 
80
 
81
 
 
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,
 
84
                                       apr_pool_t *pool)
 
85
{
 
86
    return (*DBM_VTABLE.open)(pdb, pathname, mode, perm, pool);
 
87
}
 
88
 
 
89
APU_DECLARE(void) apr_dbm_close(apr_dbm_t *dbm)
 
90
{
 
91
    (*dbm->type->close)(dbm);
 
92
}
 
93
 
 
94
APU_DECLARE(apr_status_t) apr_dbm_fetch(apr_dbm_t *dbm, apr_datum_t key,
 
95
                                        apr_datum_t *pvalue)
 
96
{
 
97
    return (*dbm->type->fetch)(dbm, key, pvalue);
 
98
}
 
99
 
 
100
APU_DECLARE(apr_status_t) apr_dbm_store(apr_dbm_t *dbm, apr_datum_t key,
 
101
                                        apr_datum_t value)
 
102
{
 
103
    return (*dbm->type->store)(dbm, key, value);
 
104
}
 
105
 
 
106
APU_DECLARE(apr_status_t) apr_dbm_delete(apr_dbm_t *dbm, apr_datum_t key)
 
107
{
 
108
    return (*dbm->type->del)(dbm, key);
 
109
}
 
110
 
 
111
APU_DECLARE(int) apr_dbm_exists(apr_dbm_t *dbm, apr_datum_t key)
 
112
{
 
113
    return (*dbm->type->exists)(dbm, key);
 
114
}
 
115
 
 
116
APU_DECLARE(apr_status_t) apr_dbm_firstkey(apr_dbm_t *dbm, apr_datum_t *pkey)
 
117
{
 
118
    return (*dbm->type->firstkey)(dbm, pkey);
 
119
}
 
120
 
 
121
APU_DECLARE(apr_status_t) apr_dbm_nextkey(apr_dbm_t *dbm, apr_datum_t *pkey)
 
122
{
 
123
    return (*dbm->type->nextkey)(dbm, pkey);
 
124
}
 
125
 
 
126
APU_DECLARE(void) apr_dbm_freedatum(apr_dbm_t *dbm, apr_datum_t data)
 
127
{
 
128
    (*dbm->type->freedatum)(dbm, data);
 
129
}
 
130
 
 
131
APU_DECLARE(char *) apr_dbm_geterror(apr_dbm_t *dbm, int *errcode,
 
132
                                     char *errbuf, apr_size_t errbufsize)
 
133
{
 
134
    if (errcode != NULL)
 
135
        *errcode = dbm->errcode;
 
136
 
 
137
    /* assert: errbufsize > 0 */
 
138
 
 
139
    if (dbm->errmsg == NULL)
 
140
        *errbuf = '\0';
 
141
    else
 
142
        (void) apr_cpystrn(errbuf, dbm->errmsg, errbufsize);
 
143
    return errbuf;
 
144
}
 
145
 
 
146
APU_DECLARE(apr_status_t) apr_dbm_get_usednames_ex(apr_pool_t *p, 
 
147
                                                   const char *type, 
 
148
                                                   const char *pathname,
 
149
                                                   const char **used1,
 
150
                                                   const char **used2)
 
151
{
 
152
#if APU_HAVE_GDBM
 
153
    if (!strcasecmp(type, "GDBM")) {
 
154
        (*apr_dbm_type_gdbm.getusednames)(p,pathname,used1,used2);
 
155
        return APR_SUCCESS;
 
156
    }
 
157
#endif
 
158
#if APU_HAVE_SDBM
 
159
    if (!strcasecmp(type, "SDBM")) {
 
160
        (*apr_dbm_type_sdbm.getusednames)(p,pathname,used1,used2);
 
161
        return APR_SUCCESS;
 
162
    }
 
163
#endif
 
164
#if APU_HAVE_DB
 
165
    if (!strcasecmp(type, "DB")) {
 
166
        (*apr_dbm_type_db.getusednames)(p,pathname,used1,used2);
 
167
        return APR_SUCCESS;
 
168
    }
 
169
#endif
 
170
#if APU_HAVE_NDBM
 
171
    if (!strcasecmp(type, "NDBM")) {
 
172
        (*apr_dbm_type_ndbm.getusednames)(p,pathname,used1,used2);
 
173
        return APR_SUCCESS;
 
174
    }
 
175
#endif
 
176
 
 
177
    if (!strcasecmp(type, "default")) {
 
178
        (*DBM_VTABLE.getusednames)(p, pathname, used1, used2);
 
179
        return APR_SUCCESS;
 
180
    }
 
181
 
 
182
    return APR_ENOTIMPL;
 
183
 
184
 
 
185
APU_DECLARE(void) apr_dbm_get_usednames(apr_pool_t *p,
 
186
                                        const char *pathname,
 
187
                                        const char **used1,
 
188
                                        const char **used2)
 
189
{
 
190
    /* ### one day, a DBM type name will be passed and we'll need to look it
 
191
       ### up. for now, it is constant. */
 
192
 
 
193
    (*DBM_VTABLE.getusednames)(p, pathname, used1, used2);
 
194
}
 
195
 
 
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.
 
198
 */
 
199
APU_DECLARE(int) apr_posix_perms2mode(apr_fileperms_t perm)
 
200
{
 
201
    int mode = 0;
 
202
 
 
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 */
 
206
    return mode;
 
207
}