2 * This file is part of DisOrder
3 * Copyright (C) 2005-2008 Richard Kettlewell
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 3 of the License, or
8 * (at your option) any later version.
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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 /** @file lib/trackdb.h
19 * @brief Track database public interface */
29 extern const struct cache_type cache_files_type;
30 extern unsigned long cache_files_hits, cache_files_misses;
31 /* Cache entry type and tracking for regexp-based lookups */
33 /** @brief Do not attempt database recovery (trackdb_init()) */
34 #define TRACKDB_NO_RECOVER 0x0000
36 /** @brief Attempt normal recovery (trackdb_init()) */
37 #define TRACKDB_NORMAL_RECOVER 0x0001
39 /** @brief Attempt catastrophic trcovery (trackdb_init()) */
40 #define TRACKDB_FATAL_RECOVER 0x0002
42 /** @brief Mask of recovery bits (trackdb_init()) */
43 #define TRACKDB_RECOVER_MASK 0x0003
45 /** @brief Open for database upgrade (trackdb_open()) */
46 #define TRACKDB_OPEN_FOR_UPGRADE 0x0004
48 /** @brief Permit upgrade (trackdb_open()) */
49 #define TRACKDB_CAN_UPGRADE 0x0008
51 /** @brief Do not permit upgrade (trackdb_open()) */
52 #define TRACKDB_NO_UPGRADE 0x0000
54 /** @brief Mask of upgrade bits (trackdb_open()) */
55 #define TRACKDB_UPGRADE_MASK 0x000C
57 /** @brief May create database environment (trackdb_init()) */
58 #define TRACKDB_MAY_CREATE 0x0010
60 /** @brief Read-only access (trackdb_open()) */
61 #define TRACKDB_READ_ONLY 0x0020
63 void trackdb_init(int flags);
64 void trackdb_deinit(ev_source *ev);
65 /* close/close environment */
67 void trackdb_master(struct ev_source *ev);
68 /* start deadlock manager */
70 void trackdb_open(int flags);
71 void trackdb_close(void);
72 /* open/close track databases */
74 extern int trackdb_existing_database;
76 char **trackdb_stats(int *nstatsp);
77 /* return a list of database stats */
79 void trackdb_stats_subprocess(struct ev_source *ev,
80 void (*done)(char *data, void *u),
82 /* collect stats in background and call done() with results */
84 int trackdb_set(const char *track,
87 /* set a pref (remove if value=0). Return 0 t */
89 const char *trackdb_get(const char *track,
93 struct kvp *trackdb_get_all(const char *track);
96 const char *trackdb_resolve(const char *track);
97 /* resolve alias - returns a null pointer if not found */
99 int trackdb_isalias(const char *track);
100 /* return true if TRACK is an alias */
102 int trackdb_exists(const char *track);
103 /* test whether a track exists (perhaps an alias) */
105 const char *trackdb_random(int tries);
106 /* Pick a random non-alias track, making at most TRIES attempts. Returns a
107 * null pointer on failure. */
109 char **trackdb_alltags(void);
110 /* Return the list of all tags */
112 const char *trackdb_getpart(const char *track,
115 /* get a track name part, like trackname_part(), but taking the database into
118 const char *trackdb_rawpath(const char *track);
119 /* get the raw path name for TRACK (might be an alias); returns a null pointer
122 enum trackdb_listable {
124 trackdb_directories = 2
127 char **trackdb_list(const char *dir, int *np, enum trackdb_listable what,
129 /* Return the directories and/or files below DIR. If DIR is a null pointer
130 * then concatenate the listing of all collections.
132 * If REC is not a null pointer then only names where the basename matches the
133 * regexp are returned.
136 char **trackdb_search(char **wordlist, int nwordlist, int *ntracks);
137 /* return a list of tracks containing all of the words given. If you
138 * ask for only stopwords you get no tracks. */
140 void trackdb_rescan(struct ev_source *ev, int recheck,
141 void (*rescanned)(void *ru),
143 /* Start a rescan, if one is not running already */
145 int trackdb_rescan_cancel(void);
146 /* interrupt any running rescan. Return 1 if one was running, else 0. */
148 void trackdb_gc(void);
149 /* tidy up old database log files */
151 int trackdb_set_global(const char *name,
154 /* set a global pref (remove if value=0). */
156 const char *trackdb_get_global(const char *name);
157 /* get a global pref */
159 char **trackdb_new(int *ntracksp, int maxtracks);
161 void trackdb_expire_noticed(time_t when);
162 void trackdb_create_root(void);
163 const char *trackdb_get_password(const char *user);
164 int trackdb_adduser(const char *user,
165 const char *password,
168 const char *confirmation);
169 int trackdb_deluser(const char *user);
170 struct kvp *trackdb_getuserinfo(const char *user);
171 int trackdb_edituserinfo(const char *user,
172 const char *key, const char *value);
173 char **trackdb_listusers(void);
174 int trackdb_confirm(const char *user, const char *confirmation,
175 rights_type *rightsp);
176 int trackdb_readable(void);
178 typedef void random_callback(struct ev_source *ev,
180 int trackdb_request_random(struct ev_source *ev,
181 random_callback *callback);
182 void trackdb_add_rescanned(void (*rescanned)(void *ru),
184 int trackdb_rescan_underway(void);
186 int trackdb_playlist_get(const char *name,
191 int trackdb_playlist_set(const char *name,
196 void trackdb_playlist_list(const char *who,
199 int trackdb_playlist_delete(const char *name,
202 #endif /* TRACKDB_H */