f728e0ae887b13e3292e490215a10364c9b585d4
[disorder] / server / trackdb-int.h
1 /*
2 * This file is part of DisOrder
3 * Copyright (C) 2005, 2007 Richard Kettlewell
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
24 extern DB_ENV *trackdb_env;
25
26 extern DB *trackdb_tracksdb;
27 extern DB *trackdb_prefsdb;
28 extern DB *trackdb_searchdb;
29 extern DB *trackdb_noticeddb;
30
31 DBC *trackdb_opencursor(DB *db, DB_TXN *tid);
32 /* open a transaction */
33
34 int trackdb_closecursor(DBC *c);
35 /* close transaction, returns 0 or DB_LOCK_DEADLOCK */
36
37 int trackdb_notice(const char *track,
38 const char *path);
39 int trackdb_notice_tid(const char *track,
40 const char *path,
41 DB_TXN *tid);
42 /* notice a track; return DB_NOTFOUND if new, else 0. _tid can return
43 * DB_LOCK_DEADLOCK too. */
44
45 int trackdb_obsolete(const char *track, DB_TXN *tid);
46 /* obsolete a track */
47
48 DB_TXN *trackdb_begin_transaction(void);
49 void trackdb_abort_transaction(DB_TXN *tid);
50 void trackdb_commit_transaction(DB_TXN *tid);
51 /* begin, abort or commit a transaction */
52
53 int trackdb_getdata(DB *db,
54 const char *track,
55 struct kvp **kp,
56 DB_TXN *tid);
57 /* fetch and decode a database entry. Returns 0, DB_NOTFOUND or
58 * DB_LOCK_DEADLOCK. */
59
60 int trackdb_putdata(DB *db,
61 const char *track,
62 const struct kvp *k,
63 DB_TXN *tid,
64 u_int32_t flags);
65 /* encode and store a database entry. Returns 0, DB_KEYEXIST or
66 * DB_LOCK_DEADLOCK. */
67
68 int trackdb_delkey(DB *db,
69 const char *track,
70 DB_TXN *tid);
71 /* delete a database entry. Returns 0, DB_NOTFOUND or DB_LOCK_DEADLOCK. */
72
73 int trackdb_delkeydata(DB *db,
74 const char *word,
75 const char *track,
76 DB_TXN *tid);
77 /* delete a (key,data) pair. Returns 0, DB_NOTFOUND or DB_LOCK_DEADLOCK. */
78
79 int trackdb_scan(const char *root,
80 int (*callback)(const char *track,
81 struct kvp *data,
82 void *u,
83 DB_TXN *tid),
84 void *u,
85 DB_TXN *tid);
86 /* Call CALLBACK for each non-alias track below ROOT (or all tracks if ROOT is
87 * 0). Return 0 or DB_LOCK_DEADLOCK. CALLBACK should return 0 on success or
88 * EINTR to cancel the scan. */
89
90 /* fill KEY in with S, returns KEY */
91
92 static inline DBT *make_key(DBT *key, const char *s) {
93 memset(key, 0, sizeof *key);
94 key->data = (void *)s;
95 key->size = strlen(s);
96 return key;
97 }
98
99 /* set DATA up to receive data, returns DATA */
100 static inline DBT *prepare_data(DBT *data) {
101 memset(data, 0, sizeof *data);
102 data->flags = DB_DBT_MALLOC;
103 return data;
104 }
105
106 /* encode K and store in DATA, returns DATA */
107 static inline DBT *encode_data(DBT *data, const struct kvp *k) {
108 size_t size;
109
110 memset(data, 0, sizeof *data);
111 data->data = kvp_urlencode(k, &size);
112 data->size = size;
113 return data;
114 }
115
116 int trackdb_set_global_tid(const char *name,
117 const char *value,
118 DB_TXN *tid);
119 int trackdb_get_global_tid(const char *name,
120 DB_TXN *tid,
121 const char **rp);
122
123 #endif /* TRACKDB_INT_H */
124
125 /*
126 Local Variables:
127 c-basic-offset:2
128 comment-column:40
129 fill-column:79
130 indent-tabs-mode:nil
131 End:
132 */