chiark / gitweb /
tests for cache.c
[disorder] / server / trackdb-int.h
CommitLineData
460b9539 1/*
2 * This file is part of DisOrder
78efa64e 3 * Copyright (C) 2005, 2007 Richard Kettlewell
460b9539 4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18 * USA
19 */
20
21#ifndef TRACKDB_INT_H
22#define TRACKDB_INT_H
23
24extern DB_ENV *trackdb_env;
25
26extern DB *trackdb_tracksdb;
27extern DB *trackdb_prefsdb;
28extern DB *trackdb_searchdb;
3dc3d7db 29extern DB *trackdb_tagsdb;
2a10b70b 30extern DB *trackdb_noticeddb;
3dc3d7db 31extern DB *trackdb_globaldb;
460b9539 32
33DBC *trackdb_opencursor(DB *db, DB_TXN *tid);
34/* open a transaction */
35
36int trackdb_closecursor(DBC *c);
37/* close transaction, returns 0 or DB_LOCK_DEADLOCK */
38
39int trackdb_notice(const char *track,
40 const char *path);
41int trackdb_notice_tid(const char *track,
42 const char *path,
43 DB_TXN *tid);
44/* notice a track; return DB_NOTFOUND if new, else 0. _tid can return
45 * DB_LOCK_DEADLOCK too. */
46
47int trackdb_obsolete(const char *track, DB_TXN *tid);
48/* obsolete a track */
49
50DB_TXN *trackdb_begin_transaction(void);
51void trackdb_abort_transaction(DB_TXN *tid);
52void trackdb_commit_transaction(DB_TXN *tid);
53/* begin, abort or commit a transaction */
54
55int trackdb_getdata(DB *db,
56 const char *track,
57 struct kvp **kp,
58 DB_TXN *tid);
59/* fetch and decode a database entry. Returns 0, DB_NOTFOUND or
60 * DB_LOCK_DEADLOCK. */
61
62int trackdb_putdata(DB *db,
63 const char *track,
64 const struct kvp *k,
65 DB_TXN *tid,
66 u_int32_t flags);
67/* encode and store a database entry. Returns 0, DB_KEYEXIST or
68 * DB_LOCK_DEADLOCK. */
69
70int trackdb_delkey(DB *db,
71 const char *track,
72 DB_TXN *tid);
73/* delete a database entry. Returns 0, DB_NOTFOUND or DB_LOCK_DEADLOCK. */
74
75int trackdb_delkeydata(DB *db,
76 const char *word,
77 const char *track,
78 DB_TXN *tid);
79/* delete a (key,data) pair. Returns 0, DB_NOTFOUND or DB_LOCK_DEADLOCK. */
80
81int trackdb_scan(const char *root,
82 int (*callback)(const char *track,
83 struct kvp *data,
84 void *u,
85 DB_TXN *tid),
86 void *u,
87 DB_TXN *tid);
d1694464 88/* Call CALLBACK for each non-alias track below ROOT (or all tracks if ROOT is
89 * 0). Return 0 or DB_LOCK_DEADLOCK. CALLBACK should return 0 on success or
90 * EINTR to cancel the scan. */
460b9539 91
92/* fill KEY in with S, returns KEY */
2a10b70b 93
460b9539 94static inline DBT *make_key(DBT *key, const char *s) {
95 memset(key, 0, sizeof *key);
96 key->data = (void *)s;
97 key->size = strlen(s);
98 return key;
99}
100
101/* set DATA up to receive data, returns DATA */
102static inline DBT *prepare_data(DBT *data) {
103 memset(data, 0, sizeof *data);
104 data->flags = DB_DBT_MALLOC;
105 return data;
106}
107
108/* encode K and store in DATA, returns DATA */
109static inline DBT *encode_data(DBT *data, const struct kvp *k) {
110 size_t size;
111
112 memset(data, 0, sizeof *data);
113 data->data = kvp_urlencode(k, &size);
114 data->size = size;
115 return data;
116}
117
f9635e06
RK
118int trackdb_set_global_tid(const char *name,
119 const char *value,
120 DB_TXN *tid);
121int trackdb_get_global_tid(const char *name,
122 DB_TXN *tid,
123 const char **rp);
124
460b9539 125#endif /* TRACKDB_INT_H */
126
127/*
128Local Variables:
129c-basic-offset:2
130comment-column:40
131fill-column:79
132indent-tabs-mode:nil
133End:
134*/