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