chiark / gitweb /
Fiddle with CSS+HTML in effort to get more consistent buttons
[disorder] / lib / 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
05b75f8d
RK
24#include <db.h>
25
fdca70ee
RK
26#include "kvp.h"
27
c3be4f19
RK
28struct vector; /* forward declaration */
29
460b9539 30extern DB_ENV *trackdb_env;
31
32extern DB *trackdb_tracksdb;
33extern DB *trackdb_prefsdb;
34extern DB *trackdb_searchdb;
3dc3d7db 35extern DB *trackdb_tagsdb;
2a10b70b 36extern DB *trackdb_noticeddb;
3dc3d7db 37extern DB *trackdb_globaldb;
a745dd43 38extern DB *trackdb_usersdb;
fdca70ee 39extern DB *trackdb_scheduledb;
460b9539 40
41DBC *trackdb_opencursor(DB *db, DB_TXN *tid);
42/* open a transaction */
43
44int trackdb_closecursor(DBC *c);
45/* close transaction, returns 0 or DB_LOCK_DEADLOCK */
46
47int trackdb_notice(const char *track,
48 const char *path);
49int trackdb_notice_tid(const char *track,
50 const char *path,
51 DB_TXN *tid);
52/* notice a track; return DB_NOTFOUND if new, else 0. _tid can return
53 * DB_LOCK_DEADLOCK too. */
54
55int trackdb_obsolete(const char *track, DB_TXN *tid);
56/* obsolete a track */
57
58DB_TXN *trackdb_begin_transaction(void);
59void trackdb_abort_transaction(DB_TXN *tid);
60void trackdb_commit_transaction(DB_TXN *tid);
61/* begin, abort or commit a transaction */
62
f0feb22e
RK
63/** @brief Evaluate @p expr in a transaction, looping on deadlock
64 *
65 * @c tid will be the transaction handle. @p e will be the error code.
66 */
67#define WITH_TRANSACTION(expr) do { \
68 DB_TXN *tid; \
69 \
70 tid = trackdb_begin_transaction(); \
71 while((e = (expr)) == DB_LOCK_DEADLOCK) { \
72 trackdb_abort_transaction(tid); \
73 tid = trackdb_begin_transaction(); \
74 } \
75 if(e) \
76 trackdb_abort_transaction(tid); \
77 else \
78 trackdb_commit_transaction(tid); \
79} while(0)
80
460b9539 81int trackdb_getdata(DB *db,
82 const char *track,
83 struct kvp **kp,
84 DB_TXN *tid);
85/* fetch and decode a database entry. Returns 0, DB_NOTFOUND or
86 * DB_LOCK_DEADLOCK. */
87
88int trackdb_putdata(DB *db,
89 const char *track,
90 const struct kvp *k,
91 DB_TXN *tid,
92 u_int32_t flags);
93/* encode and store a database entry. Returns 0, DB_KEYEXIST or
94 * DB_LOCK_DEADLOCK. */
95
96int trackdb_delkey(DB *db,
97 const char *track,
98 DB_TXN *tid);
99/* delete a database entry. Returns 0, DB_NOTFOUND or DB_LOCK_DEADLOCK. */
100
101int trackdb_delkeydata(DB *db,
102 const char *word,
103 const char *track,
104 DB_TXN *tid);
105/* delete a (key,data) pair. Returns 0, DB_NOTFOUND or DB_LOCK_DEADLOCK. */
106
107int trackdb_scan(const char *root,
108 int (*callback)(const char *track,
109 struct kvp *data,
bea6f6d5 110 struct kvp *prefs,
460b9539 111 void *u,
112 DB_TXN *tid),
113 void *u,
114 DB_TXN *tid);
d1694464 115/* Call CALLBACK for each non-alias track below ROOT (or all tracks if ROOT is
116 * 0). Return 0 or DB_LOCK_DEADLOCK. CALLBACK should return 0 on success or
117 * EINTR to cancel the scan. */
460b9539 118
c3be4f19 119int trackdb_listkeys(DB *db, struct vector *v, DB_TXN *tid);
2a10b70b 120
c3be4f19 121/* fill KEY in with S, returns KEY */
460b9539 122static inline DBT *make_key(DBT *key, const char *s) {
123 memset(key, 0, sizeof *key);
124 key->data = (void *)s;
125 key->size = strlen(s);
126 return key;
127}
128
129/* set DATA up to receive data, returns DATA */
130static inline DBT *prepare_data(DBT *data) {
131 memset(data, 0, sizeof *data);
132 data->flags = DB_DBT_MALLOC;
133 return data;
134}
135
136/* encode K and store in DATA, returns DATA */
137static inline DBT *encode_data(DBT *data, const struct kvp *k) {
138 size_t size;
139
140 memset(data, 0, sizeof *data);
141 data->data = kvp_urlencode(k, &size);
142 data->size = size;
143 return data;
144}
145
f9635e06
RK
146int trackdb_set_global_tid(const char *name,
147 const char *value,
148 DB_TXN *tid);
149int trackdb_get_global_tid(const char *name,
150 DB_TXN *tid,
151 const char **rp);
152
91c9324a
RK
153char **parsetags(const char *s);
154int tag_intersection(char **a, char **b);
155
460b9539 156#endif /* TRACKDB_INT_H */
157
158/*
159Local Variables:
160c-basic-offset:2
161comment-column:40
162fill-column:79
163indent-tabs-mode:nil
164End:
165*/