| 1 | /* |
| 2 | * This file is part of DisOrder |
| 3 | * Copyright (C) 2005-2008 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 3 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, |
| 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 | * |
| 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/>. |
| 17 | */ |
| 18 | /** @file lib/trackdb.h |
| 19 | * @brief Track database public interface */ |
| 20 | |
| 21 | #ifndef TRACKDB_H |
| 22 | #define TRACKDB_H |
| 23 | |
| 24 | #include <pcre.h> |
| 25 | |
| 26 | #include "event.h" |
| 27 | #include "rights.h" |
| 28 | |
| 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 */ |
| 32 | |
| 33 | /** @brief Do not attempt database recovery (trackdb_init()) */ |
| 34 | #define TRACKDB_NO_RECOVER 0x0000 |
| 35 | |
| 36 | /** @brief Attempt normal recovery (trackdb_init()) */ |
| 37 | #define TRACKDB_NORMAL_RECOVER 0x0001 |
| 38 | |
| 39 | /** @brief Attempt catastrophic trcovery (trackdb_init()) */ |
| 40 | #define TRACKDB_FATAL_RECOVER 0x0002 |
| 41 | |
| 42 | /** @brief Mask of recovery bits (trackdb_init()) */ |
| 43 | #define TRACKDB_RECOVER_MASK 0x0003 |
| 44 | |
| 45 | /** @brief Open for database upgrade (trackdb_open()) */ |
| 46 | #define TRACKDB_OPEN_FOR_UPGRADE 0x0004 |
| 47 | |
| 48 | /** @brief Permit upgrade (trackdb_open()) */ |
| 49 | #define TRACKDB_CAN_UPGRADE 0x0008 |
| 50 | |
| 51 | /** @brief Do not permit upgrade (trackdb_open()) */ |
| 52 | #define TRACKDB_NO_UPGRADE 0x0000 |
| 53 | |
| 54 | /** @brief Mask of upgrade bits (trackdb_open()) */ |
| 55 | #define TRACKDB_UPGRADE_MASK 0x000C |
| 56 | |
| 57 | /** @brief May create database environment (trackdb_init()) */ |
| 58 | #define TRACKDB_MAY_CREATE 0x0010 |
| 59 | |
| 60 | /** @brief Read-only access (trackdb_open()) */ |
| 61 | #define TRACKDB_READ_ONLY 0x0020 |
| 62 | |
| 63 | void trackdb_init(int flags); |
| 64 | void trackdb_deinit(void); |
| 65 | /* close/close environment */ |
| 66 | |
| 67 | void trackdb_master(struct ev_source *ev); |
| 68 | /* start deadlock manager */ |
| 69 | |
| 70 | void trackdb_open(int flags); |
| 71 | void trackdb_close(void); |
| 72 | /* open/close track databases */ |
| 73 | |
| 74 | extern int trackdb_existing_database; |
| 75 | |
| 76 | char **trackdb_stats(int *nstatsp); |
| 77 | /* return a list of database stats */ |
| 78 | |
| 79 | void trackdb_stats_subprocess(struct ev_source *ev, |
| 80 | void (*done)(char *data, void *u), |
| 81 | void *u); |
| 82 | /* collect stats in background and call done() with results */ |
| 83 | |
| 84 | int trackdb_set(const char *track, |
| 85 | const char *name, |
| 86 | const char *value); |
| 87 | /* set a pref (remove if value=0). Return 0 t */ |
| 88 | |
| 89 | const char *trackdb_get(const char *track, |
| 90 | const char *name); |
| 91 | /* get a pref */ |
| 92 | |
| 93 | struct kvp *trackdb_get_all(const char *track); |
| 94 | /* get all prefs */ |
| 95 | |
| 96 | const char *trackdb_resolve(const char *track); |
| 97 | /* resolve alias - returns a null pointer if not found */ |
| 98 | |
| 99 | int trackdb_isalias(const char *track); |
| 100 | /* return true if TRACK is an alias */ |
| 101 | |
| 102 | int trackdb_exists(const char *track); |
| 103 | /* test whether a track exists (perhaps an alias) */ |
| 104 | |
| 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. */ |
| 108 | |
| 109 | char **trackdb_alltags(void); |
| 110 | /* Return the list of all tags */ |
| 111 | |
| 112 | const char *trackdb_getpart(const char *track, |
| 113 | const char *context, |
| 114 | const char *part); |
| 115 | /* get a track name part, like trackname_part(), but taking the database into |
| 116 | * account. */ |
| 117 | |
| 118 | const char *trackdb_rawpath(const char *track); |
| 119 | /* get the raw path name for TRACK (might be an alias); returns a null pointer |
| 120 | * if not found. */ |
| 121 | |
| 122 | enum trackdb_listable { |
| 123 | trackdb_files = 1, |
| 124 | trackdb_directories = 2 |
| 125 | }; |
| 126 | |
| 127 | char **trackdb_list(const char *dir, int *np, enum trackdb_listable what, |
| 128 | const pcre *rec); |
| 129 | /* Return the directories and/or files below DIR. If DIR is a null pointer |
| 130 | * then concatenate the listing of all collections. |
| 131 | * |
| 132 | * If REC is not a null pointer then only names where the basename matches the |
| 133 | * regexp are returned. |
| 134 | */ |
| 135 | |
| 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. */ |
| 139 | |
| 140 | void trackdb_rescan(struct ev_source *ev, int recheck, |
| 141 | void (*rescanned)(void *ru), |
| 142 | void *ru); |
| 143 | /* Start a rescan, if one is not running already */ |
| 144 | |
| 145 | int trackdb_rescan_cancel(void); |
| 146 | /* interrupt any running rescan. Return 1 if one was running, else 0. */ |
| 147 | |
| 148 | void trackdb_gc(void); |
| 149 | /* tidy up old database log files */ |
| 150 | |
| 151 | void trackdb_set_global(const char *name, |
| 152 | const char *value, |
| 153 | const char *who); |
| 154 | /* set a global pref (remove if value=0). */ |
| 155 | |
| 156 | const char *trackdb_get_global(const char *name); |
| 157 | /* get a global pref */ |
| 158 | |
| 159 | char **trackdb_new(int *ntracksp, int maxtracks); |
| 160 | |
| 161 | void trackdb_expire_noticed(time_t when); |
| 162 | void trackdb_old_users(void); |
| 163 | void trackdb_create_root(void); |
| 164 | const char *trackdb_get_password(const char *user); |
| 165 | int trackdb_adduser(const char *user, |
| 166 | const char *password, |
| 167 | const char *rights, |
| 168 | const char *email, |
| 169 | const char *confirmation); |
| 170 | int trackdb_deluser(const char *user); |
| 171 | struct kvp *trackdb_getuserinfo(const char *user); |
| 172 | int trackdb_edituserinfo(const char *user, |
| 173 | const char *key, const char *value); |
| 174 | char **trackdb_listusers(void); |
| 175 | int trackdb_confirm(const char *user, const char *confirmation, |
| 176 | rights_type *rightsp); |
| 177 | int trackdb_readable(void); |
| 178 | |
| 179 | typedef void random_callback(struct ev_source *ev, |
| 180 | const char *track); |
| 181 | int trackdb_request_random(struct ev_source *ev, |
| 182 | random_callback *callback); |
| 183 | void trackdb_add_rescanned(void (*rescanned)(void *ru), |
| 184 | void *ru); |
| 185 | int trackdb_rescan_underway(void); |
| 186 | |
| 187 | #endif /* TRACKDB_H */ |
| 188 | |
| 189 | /* |
| 190 | Local Variables: |
| 191 | c-basic-offset:2 |
| 192 | comment-column:40 |
| 193 | fill-column:79 |
| 194 | indent-tabs-mode:nil |
| 195 | End: |
| 196 | */ |