chiark / gitweb /
clients/playrtp.c: Improve message reporting a unicast stream request.
[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 *
e7eb3a27 5 * This program is free software: you can redistribute it and/or modify
460b9539 6 * it under the terms of the GNU General Public License as published by
e7eb3a27 7 * the Free Software Foundation, either version 3 of the License, or
460b9539 8 * (at your option) any later version.
e7eb3a27
RK
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
460b9539 15 * You should have received a copy of the GNU General Public License
e7eb3a27 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
460b9539 17 */
132a5a4a
RK
18/** @file lib/trackdb-int.h
19 * @brief Track database internals */
460b9539 20#ifndef TRACKDB_INT_H
21#define TRACKDB_INT_H
22
05b75f8d
RK
23#include <db.h>
24
2563dc1f 25#include "trackdb.h"
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;
2563dc1f 40extern DB *trackdb_playlistsdb;
460b9539 41
42DBC *trackdb_opencursor(DB *db, DB_TXN *tid);
43/* open a transaction */
44
45int trackdb_closecursor(DBC *c);
46/* close transaction, returns 0 or DB_LOCK_DEADLOCK */
47
48int trackdb_notice(const char *track,
49 const char *path);
50int trackdb_notice_tid(const char *track,
51 const char *path,
52 DB_TXN *tid);
53/* notice a track; return DB_NOTFOUND if new, else 0. _tid can return
54 * DB_LOCK_DEADLOCK too. */
55
56int trackdb_obsolete(const char *track, DB_TXN *tid);
57/* obsolete a track */
58
59DB_TXN *trackdb_begin_transaction(void);
60void trackdb_abort_transaction(DB_TXN *tid);
61void trackdb_commit_transaction(DB_TXN *tid);
62/* begin, abort or commit a transaction */
63
f0feb22e
RK
64/** @brief Evaluate @p expr in a transaction, looping on deadlock
65 *
66 * @c tid will be the transaction handle. @p e will be the error code.
67 */
68#define WITH_TRANSACTION(expr) do { \
69 DB_TXN *tid; \
70 \
71 tid = trackdb_begin_transaction(); \
72 while((e = (expr)) == DB_LOCK_DEADLOCK) { \
73 trackdb_abort_transaction(tid); \
74 tid = trackdb_begin_transaction(); \
75 } \
76 if(e) \
77 trackdb_abort_transaction(tid); \
78 else \
79 trackdb_commit_transaction(tid); \
80} while(0)
81
460b9539 82int trackdb_getdata(DB *db,
83 const char *track,
84 struct kvp **kp,
85 DB_TXN *tid);
86/* fetch and decode a database entry. Returns 0, DB_NOTFOUND or
87 * DB_LOCK_DEADLOCK. */
88
89int trackdb_putdata(DB *db,
90 const char *track,
91 const struct kvp *k,
92 DB_TXN *tid,
93 u_int32_t flags);
94/* encode and store a database entry. Returns 0, DB_KEYEXIST or
95 * DB_LOCK_DEADLOCK. */
96
97int trackdb_delkey(DB *db,
98 const char *track,
99 DB_TXN *tid);
100/* delete a database entry. Returns 0, DB_NOTFOUND or DB_LOCK_DEADLOCK. */
101
102int trackdb_delkeydata(DB *db,
103 const char *word,
104 const char *track,
105 DB_TXN *tid);
106/* delete a (key,data) pair. Returns 0, DB_NOTFOUND or DB_LOCK_DEADLOCK. */
107
108int trackdb_scan(const char *root,
109 int (*callback)(const char *track,
110 struct kvp *data,
bea6f6d5 111 struct kvp *prefs,
460b9539 112 void *u,
113 DB_TXN *tid),
114 void *u,
115 DB_TXN *tid);
d1694464 116/* Call CALLBACK for each non-alias track below ROOT (or all tracks if ROOT is
117 * 0). Return 0 or DB_LOCK_DEADLOCK. CALLBACK should return 0 on success or
118 * EINTR to cancel the scan. */
460b9539 119
c3be4f19 120int trackdb_listkeys(DB *db, struct vector *v, DB_TXN *tid);
2a10b70b 121
c3be4f19 122/* fill KEY in with S, returns KEY */
460b9539 123static inline DBT *make_key(DBT *key, const char *s) {
124 memset(key, 0, sizeof *key);
125 key->data = (void *)s;
126 key->size = strlen(s);
127 return key;
128}
129
130/* set DATA up to receive data, returns DATA */
131static inline DBT *prepare_data(DBT *data) {
132 memset(data, 0, sizeof *data);
133 data->flags = DB_DBT_MALLOC;
134 return data;
135}
136
137/* encode K and store in DATA, returns DATA */
138static inline DBT *encode_data(DBT *data, const struct kvp *k) {
139 size_t size;
140
141 memset(data, 0, sizeof *data);
142 data->data = kvp_urlencode(k, &size);
143 data->size = size;
144 return data;
145}
146
f9635e06
RK
147int trackdb_set_global_tid(const char *name,
148 const char *value,
149 DB_TXN *tid);
150int trackdb_get_global_tid(const char *name,
151 DB_TXN *tid,
152 const char **rp);
153
91c9324a
RK
154char **parsetags(const char *s);
155int tag_intersection(char **a, char **b);
156
460b9539 157#endif /* TRACKDB_INT_H */
158
159/*
160Local Variables:
161c-basic-offset:2
162comment-column:40
163fill-column:79
164indent-tabs-mode:nil
165End:
166*/