23 |
*/ |
*/ |
24 |
|
|
25 |
#include "headers.h" |
#include "headers.h" |
26 |
|
#if defined(HAVE_LIBGDBM) |
27 |
#include <gdbm.h> |
#include <gdbm.h> |
28 |
|
|
29 |
/* Format of an GDBM record: |
/* Format of an GDBM record: |
36 |
The last two items are optional */ |
The last two items are optional */ |
37 |
|
|
38 |
static int |
static int |
39 |
gdbm_db_open (void **dp, char *arg, enum anubis_db_mode mode) |
gdbm_db_open (void **dp, ANUBIS_URL *url, enum anubis_db_mode mode) |
40 |
{ |
{ |
41 |
GDBM_FILE dbf; |
GDBM_FILE dbf; |
42 |
int flags; |
int flags; |
43 |
|
char *path; |
44 |
|
|
45 |
switch (mode) { |
switch (mode) { |
46 |
case anubis_db_rdonly: |
case anubis_db_rdonly: |
51 |
flags = GDBM_WRCREAT; |
flags = GDBM_WRCREAT; |
52 |
} |
} |
53 |
|
|
54 |
|
path = anubis_url_full_path(url); |
55 |
dbf = gdbm_open(arg, 0, flags, 0644, NULL); |
dbf = gdbm_open(path, 0, flags, 0644, NULL); |
56 |
|
free(path); |
57 |
if (!dbf) |
if (!dbf) |
58 |
return ANUBIS_DB_FAIL; |
return ANUBIS_DB_FAIL; |
59 |
*dp = dbf; |
*dp = dbf; |
141 |
return rc; |
return rc; |
142 |
} |
} |
143 |
|
|
144 |
|
static int |
145 |
|
gdbm_db_delete(void *d, char *keystr, int *ecode) |
146 |
|
{ |
147 |
|
int rc; |
148 |
|
datum key; |
149 |
|
|
150 |
|
key.dptr = keystr; |
151 |
|
key.dsize = strlen(keystr); |
152 |
|
if (gdbm_delete((GDBM_FILE)d, key)) |
153 |
|
rc = ANUBIS_DB_FAIL; |
154 |
|
else |
155 |
|
rc = ANUBIS_DB_SUCCESS; |
156 |
|
return rc; |
157 |
|
} |
158 |
|
|
159 |
void |
void |
160 |
gdbm_db_init() |
gdbm_db_init() |
161 |
{ |
{ |
164 |
gdbm_db_close, |
gdbm_db_close, |
165 |
gdbm_db_get, |
gdbm_db_get, |
166 |
gdbm_db_put, |
gdbm_db_put, |
167 |
|
gdbm_db_delete, |
168 |
NULL); |
NULL); |
169 |
} |
} |
170 |
|
#endif |