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