| 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 server/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 Do not attempt database recovery (trackdb_init()) */ |
| 33 | #define TRACKDB_NO_RECOVER 0x0000 |
| 34 | |
| 35 | /** @brief Attempt normal recovery (trackdb_init()) */ |
| 36 | #define TRACKDB_NORMAL_RECOVER 0x0001 |
| 37 | |
| 38 | /** @brief Attempt catastrophic trcovery (trackdb_init()) */ |
| 39 | #define TRACKDB_FATAL_RECOVER 0x0002 |
| 40 | |
| 41 | /** @brief Mask of recovery bits (trackdb_init()) */ |
| 42 | #define TRACKDB_RECOVER_MASK 0x0003 |
| 43 | |
| 44 | /** @brief Open for database upgrade (trackdb_open()) */ |
| 45 | #define TRACKDB_OPEN_FOR_UPGRADE 0x0004 |
| 46 | |
| 47 | /** @brief Permit upgrade (trackdb_open()) */ |
| 48 | #define TRACKDB_CAN_UPGRADE 0x0008 |
| 49 | |
| 50 | /** @brief Do not permit upgrade (trackdb_open()) */ |
| 51 | #define TRACKDB_NO_UPGRADE 0x0000 |
| 52 | |
| 53 | /** @brief Mask of upgrade bits (trackdb_open()) */ |
| 54 | #define TRACKDB_UPGRADE_MASK 0x000C |
| 55 | |
| 56 | void trackdb_init(int flags); |
| 57 | void trackdb_deinit(void); |
| 58 | /* close/close environment */ |
| 59 | |
| 60 | void trackdb_master(struct ev_source *ev); |
| 61 | /* start deadlock manager */ |
| 62 | |
| 63 | void trackdb_open(int flags); |
| 64 | void trackdb_close(void); |
| 65 | /* open/close track databases */ |
| 66 | |
| 67 | char **trackdb_stats(int *nstatsp); |
| 68 | /* return a list of database stats */ |
| 69 | |
| 70 | void trackdb_stats_subprocess(struct ev_source *ev, |
| 71 | void (*done)(char *data, void *u), |
| 72 | void *u); |
| 73 | /* collect stats in background and call done() with results */ |
| 74 | |
| 75 | int trackdb_set(const char *track, |
| 76 | const char *name, |
| 77 | const char *value); |
| 78 | /* set a pref (remove if value=0). Return 0 t */ |
| 79 | |
| 80 | const char *trackdb_get(const char *track, |
| 81 | const char *name); |
| 82 | /* get a pref */ |
| 83 | |
| 84 | struct kvp *trackdb_get_all(const char *track); |
| 85 | /* get all prefs */ |
| 86 | |
| 87 | const char *trackdb_resolve(const char *track); |
| 88 | /* resolve alias - returns a null pointer if not found */ |
| 89 | |
| 90 | int trackdb_isalias(const char *track); |
| 91 | /* return true if TRACK is an alias */ |
| 92 | |
| 93 | int trackdb_exists(const char *track); |
| 94 | /* test whether a track exists (perhaps an alias) */ |
| 95 | |
| 96 | const char *trackdb_random(int tries); |
| 97 | /* Pick a random non-alias track, making at most TRIES attempts. Returns a |
| 98 | * null pointer on failure. */ |
| 99 | |
| 100 | char **trackdb_alltags(void); |
| 101 | /* Return the list of all tags */ |
| 102 | |
| 103 | const char *trackdb_getpart(const char *track, |
| 104 | const char *context, |
| 105 | const char *part); |
| 106 | /* get a track name part, like trackname_part(), but taking the database into |
| 107 | * account. */ |
| 108 | |
| 109 | const char *trackdb_rawpath(const char *track); |
| 110 | /* get the raw path name for TRACK (might be an alias); returns a null pointer |
| 111 | * if not found. */ |
| 112 | |
| 113 | enum trackdb_listable { |
| 114 | trackdb_files = 1, |
| 115 | trackdb_directories = 2 |
| 116 | }; |
| 117 | |
| 118 | char **trackdb_list(const char *dir, int *np, enum trackdb_listable what, |
| 119 | const pcre *rec); |
| 120 | /* Return the directories and/or files below DIR. If DIR is a null pointer |
| 121 | * then concatenate the listing of all collections. |
| 122 | * |
| 123 | * If REC is not a null pointer then only names where the basename matches the |
| 124 | * regexp are returned. |
| 125 | */ |
| 126 | |
| 127 | char **trackdb_search(char **wordlist, int nwordlist, int *ntracks); |
| 128 | /* return a list of tracks containing all of the words given. If you |
| 129 | * ask for only stopwords you get no tracks. */ |
| 130 | |
| 131 | void trackdb_rescan(struct ev_source *ev); |
| 132 | /* Start a rescan, if one is not running already */ |
| 133 | |
| 134 | int trackdb_rescan_cancel(void); |
| 135 | /* interrupt any running rescan. Return 1 if one was running, else 0. */ |
| 136 | |
| 137 | void trackdb_gc(void); |
| 138 | /* tidy up old database log files */ |
| 139 | |
| 140 | void trackdb_set_global(const char *name, |
| 141 | const char *value, |
| 142 | const char *who); |
| 143 | /* set a global pref (remove if value=0). */ |
| 144 | |
| 145 | const char *trackdb_get_global(const char *name); |
| 146 | /* get a global pref */ |
| 147 | |
| 148 | char **trackdb_new(int *ntracksp, int maxtracks); |
| 149 | |
| 150 | void trackdb_expire_noticed(time_t when); |
| 151 | |
| 152 | #endif /* TRACKDB_H */ |
| 153 | |
| 154 | /* |
| 155 | Local Variables: |
| 156 | c-basic-offset:2 |
| 157 | comment-column:40 |
| 158 | fill-column:79 |
| 159 | indent-tabs-mode:nil |
| 160 | End: |
| 161 | */ |