| 1 | /* |
| 2 | * This file is part of DisOrder |
| 3 | * Copyright (C) 2005, 2006, 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 | /** @file lib/trackdb.h |
| 21 | * @brief Track database public interface */ |
| 22 | |
| 23 | #ifndef TRACKDB_H |
| 24 | #define TRACKDB_H |
| 25 | |
| 26 | struct ev_source; |
| 27 | |
| 28 | extern const struct cache_type cache_files_type; |
| 29 | extern unsigned long cache_files_hits, cache_files_misses; |
| 30 | /* Cache entry type and tracking for regexp-based lookups */ |
| 31 | |
| 32 | /** @brief User can perform read-only operations */ |
| 33 | #define RIGHT_READ 0x00000001 |
| 34 | |
| 35 | /** @brief User can add tracks to the queue */ |
| 36 | #define RIGHT_PLAY 0x00000002 |
| 37 | |
| 38 | /** @brief User can move any track */ |
| 39 | #define RIGHT_MOVE_ANY 0x00000004 |
| 40 | |
| 41 | /** @brief User can move their own tracks */ |
| 42 | #define RIGHT_MOVE_MINE 0x00000008 |
| 43 | |
| 44 | /** @brief User can move randomly chosen tracks */ |
| 45 | #define RIGHT_MOVE_RANDOM 0x00000010 |
| 46 | |
| 47 | #define RIGHT_MOVE__MASK 0x0000001c |
| 48 | |
| 49 | /** @brief User can remove any track */ |
| 50 | #define RIGHT_REMOVE_ANY 0x00000020 |
| 51 | |
| 52 | /** @brief User can remove their own tracks */ |
| 53 | #define RIGHT_REMOVE_MINE 0x00000040 |
| 54 | |
| 55 | /** @brief User can remove randomly chosen tracks */ |
| 56 | #define RIGHT_REMOVE_RANDOM 0x00000080 |
| 57 | |
| 58 | #define RIGHT_REMOVE__MASK 0x000000e0 |
| 59 | |
| 60 | /** @brief User can scratch any track */ |
| 61 | #define RIGHT_SCRATCH_ANY 0x00000100 |
| 62 | |
| 63 | /** @brief User can scratch their own tracks */ |
| 64 | #define RIGHT_SCRATCH_MINE 0x00000200 |
| 65 | |
| 66 | /** @brief User can scratch randomly chosen tracks */ |
| 67 | #define RIGHT_SCRATCH_RANDOM 0x00000400 |
| 68 | |
| 69 | #define RIGHT_SCRATCH__MASK 0x00000700 |
| 70 | |
| 71 | /** @brief User can change the volume */ |
| 72 | #define RIGHT_VOLUME 0x00000800 |
| 73 | |
| 74 | /** @brief User can perform admin operations */ |
| 75 | #define RIGHT_ADMIN 0x00001000 |
| 76 | |
| 77 | /** @brief User can initiate a rescan */ |
| 78 | #define RIGHT_RESCAN 0x00002000 |
| 79 | |
| 80 | /** @brief User can register new users */ |
| 81 | #define RIGHT_REGISTER 0x00004000 |
| 82 | |
| 83 | /** @brief User can edit their own userinfo */ |
| 84 | #define RIGHT_USERINFO 0x00008000 |
| 85 | |
| 86 | /** @brief User can modify track preferences */ |
| 87 | #define RIGHT_PREFS 0x00010000 |
| 88 | |
| 89 | /** @brief User can modify global preferences */ |
| 90 | #define RIGHT_GLOBAL_PREFS 0x00020000 |
| 91 | |
| 92 | /** @brief Current rights mask */ |
| 93 | #define RIGHTS__MASK 0x0003ffff |
| 94 | |
| 95 | /** @brief Unsigned type big enough for rights */ |
| 96 | typedef uint32_t rights_type; |
| 97 | |
| 98 | /** @brief Do not attempt database recovery (trackdb_init()) */ |
| 99 | #define TRACKDB_NO_RECOVER 0x0000 |
| 100 | |
| 101 | /** @brief Attempt normal recovery (trackdb_init()) */ |
| 102 | #define TRACKDB_NORMAL_RECOVER 0x0001 |
| 103 | |
| 104 | /** @brief Attempt catastrophic trcovery (trackdb_init()) */ |
| 105 | #define TRACKDB_FATAL_RECOVER 0x0002 |
| 106 | |
| 107 | /** @brief Mask of recovery bits (trackdb_init()) */ |
| 108 | #define TRACKDB_RECOVER_MASK 0x0003 |
| 109 | |
| 110 | /** @brief Open for database upgrade (trackdb_open()) */ |
| 111 | #define TRACKDB_OPEN_FOR_UPGRADE 0x0004 |
| 112 | |
| 113 | /** @brief Permit upgrade (trackdb_open()) */ |
| 114 | #define TRACKDB_CAN_UPGRADE 0x0008 |
| 115 | |
| 116 | /** @brief Do not permit upgrade (trackdb_open()) */ |
| 117 | #define TRACKDB_NO_UPGRADE 0x0000 |
| 118 | |
| 119 | /** @brief Mask of upgrade bits (trackdb_open()) */ |
| 120 | #define TRACKDB_UPGRADE_MASK 0x000C |
| 121 | |
| 122 | /** @brief May create database environment (trackdb_init()) */ |
| 123 | #define TRACKDB_MAY_CREATE 0x0010 |
| 124 | |
| 125 | /** @brief Read-only access (trackdb_open()) */ |
| 126 | #define TRACKDB_READ_ONLY 0x0020 |
| 127 | |
| 128 | void trackdb_init(int flags); |
| 129 | void trackdb_deinit(void); |
| 130 | /* close/close environment */ |
| 131 | |
| 132 | void trackdb_master(struct ev_source *ev); |
| 133 | /* start deadlock manager */ |
| 134 | |
| 135 | void trackdb_open(int flags); |
| 136 | void trackdb_close(void); |
| 137 | /* open/close track databases */ |
| 138 | |
| 139 | extern int trackdb_existing_database; |
| 140 | |
| 141 | char **trackdb_stats(int *nstatsp); |
| 142 | /* return a list of database stats */ |
| 143 | |
| 144 | void trackdb_stats_subprocess(struct ev_source *ev, |
| 145 | void (*done)(char *data, void *u), |
| 146 | void *u); |
| 147 | /* collect stats in background and call done() with results */ |
| 148 | |
| 149 | int trackdb_set(const char *track, |
| 150 | const char *name, |
| 151 | const char *value); |
| 152 | /* set a pref (remove if value=0). Return 0 t */ |
| 153 | |
| 154 | const char *trackdb_get(const char *track, |
| 155 | const char *name); |
| 156 | /* get a pref */ |
| 157 | |
| 158 | struct kvp *trackdb_get_all(const char *track); |
| 159 | /* get all prefs */ |
| 160 | |
| 161 | const char *trackdb_resolve(const char *track); |
| 162 | /* resolve alias - returns a null pointer if not found */ |
| 163 | |
| 164 | int trackdb_isalias(const char *track); |
| 165 | /* return true if TRACK is an alias */ |
| 166 | |
| 167 | int trackdb_exists(const char *track); |
| 168 | /* test whether a track exists (perhaps an alias) */ |
| 169 | |
| 170 | const char *trackdb_random(int tries); |
| 171 | /* Pick a random non-alias track, making at most TRIES attempts. Returns a |
| 172 | * null pointer on failure. */ |
| 173 | |
| 174 | char **trackdb_alltags(void); |
| 175 | /* Return the list of all tags */ |
| 176 | |
| 177 | const char *trackdb_getpart(const char *track, |
| 178 | const char *context, |
| 179 | const char *part); |
| 180 | /* get a track name part, like trackname_part(), but taking the database into |
| 181 | * account. */ |
| 182 | |
| 183 | const char *trackdb_rawpath(const char *track); |
| 184 | /* get the raw path name for TRACK (might be an alias); returns a null pointer |
| 185 | * if not found. */ |
| 186 | |
| 187 | enum trackdb_listable { |
| 188 | trackdb_files = 1, |
| 189 | trackdb_directories = 2 |
| 190 | }; |
| 191 | |
| 192 | char **trackdb_list(const char *dir, int *np, enum trackdb_listable what, |
| 193 | const pcre *rec); |
| 194 | /* Return the directories and/or files below DIR. If DIR is a null pointer |
| 195 | * then concatenate the listing of all collections. |
| 196 | * |
| 197 | * If REC is not a null pointer then only names where the basename matches the |
| 198 | * regexp are returned. |
| 199 | */ |
| 200 | |
| 201 | char **trackdb_search(char **wordlist, int nwordlist, int *ntracks); |
| 202 | /* return a list of tracks containing all of the words given. If you |
| 203 | * ask for only stopwords you get no tracks. */ |
| 204 | |
| 205 | void trackdb_rescan(struct ev_source *ev); |
| 206 | /* Start a rescan, if one is not running already */ |
| 207 | |
| 208 | int trackdb_rescan_cancel(void); |
| 209 | /* interrupt any running rescan. Return 1 if one was running, else 0. */ |
| 210 | |
| 211 | void trackdb_gc(void); |
| 212 | /* tidy up old database log files */ |
| 213 | |
| 214 | void trackdb_set_global(const char *name, |
| 215 | const char *value, |
| 216 | const char *who); |
| 217 | /* set a global pref (remove if value=0). */ |
| 218 | |
| 219 | const char *trackdb_get_global(const char *name); |
| 220 | /* get a global pref */ |
| 221 | |
| 222 | char **trackdb_new(int *ntracksp, int maxtracks); |
| 223 | |
| 224 | void trackdb_expire_noticed(time_t when); |
| 225 | void trackdb_old_users(void); |
| 226 | void trackdb_create_root(void); |
| 227 | const char *trackdb_get_password(const char *user); |
| 228 | int trackdb_adduser(const char *user, |
| 229 | const char *password, |
| 230 | rights_type rights, |
| 231 | const char *email); |
| 232 | int trackdb_deluser(const char *user); |
| 233 | struct kvp *trackdb_getuserinfo(const char *user); |
| 234 | int trackdb_edituserinfo(const char *user, |
| 235 | const char *key, const char *value); |
| 236 | |
| 237 | rights_type default_rights(void); |
| 238 | |
| 239 | #endif /* TRACKDB_H */ |
| 240 | |
| 241 | /* |
| 242 | Local Variables: |
| 243 | c-basic-offset:2 |
| 244 | comment-column:40 |
| 245 | fill-column:79 |
| 246 | indent-tabs-mode:nil |
| 247 | End: |
| 248 | */ |