chiark / gitweb /
Switch to GPL v3
[disorder] / lib / trackdb.h
CommitLineData
460b9539 1/*
2 * This file is part of DisOrder
5aff007d 3 * Copyright (C) 2005-2008 Richard Kettlewell
460b9539 4 *
e7eb3a27 5 * This program is free software: you can redistribute it and/or modify
460b9539 6 * it under the terms of the GNU General Public License as published by
e7eb3a27 7 * the Free Software Foundation, either version 3 of the License, or
460b9539 8 * (at your option) any later version.
e7eb3a27
RK
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 *
460b9539 15 * You should have received a copy of the GNU General Public License
e7eb3a27 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
460b9539 17 */
f0feb22e 18/** @file lib/trackdb.h
d25c4615 19 * @brief Track database public interface */
460b9539 20
21#ifndef TRACKDB_H
22#define TRACKDB_H
23
fdca70ee
RK
24#include <pcre.h>
25
26#include "event.h"
27#include "rights.h"
460b9539 28
29extern const struct cache_type cache_files_type;
30extern unsigned long cache_files_hits, cache_files_misses;
31/* Cache entry type and tracking for regexp-based lookups */
32
d25c4615
RK
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
a745dd43
RK
57/** @brief May create database environment (trackdb_init()) */
58#define TRACKDB_MAY_CREATE 0x0010
59
f0feb22e
RK
60/** @brief Read-only access (trackdb_open()) */
61#define TRACKDB_READ_ONLY 0x0020
62
d25c4615 63void trackdb_init(int flags);
460b9539 64void trackdb_deinit(void);
65/* close/close environment */
66
67void trackdb_master(struct ev_source *ev);
68/* start deadlock manager */
69
d25c4615 70void trackdb_open(int flags);
460b9539 71void trackdb_close(void);
72/* open/close track databases */
73
f982b120
RK
74extern int trackdb_existing_database;
75
460b9539 76char **trackdb_stats(int *nstatsp);
77/* return a list of database stats */
78
d6dde5a3
RK
79void 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
460b9539 84int 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
89const char *trackdb_get(const char *track,
90 const char *name);
91/* get a pref */
92
93struct kvp *trackdb_get_all(const char *track);
94/* get all prefs */
95
96const char *trackdb_resolve(const char *track);
97/* resolve alias - returns a null pointer if not found */
98
99int trackdb_isalias(const char *track);
100/* return true if TRACK is an alias */
101
102int trackdb_exists(const char *track);
103/* test whether a track exists (perhaps an alias) */
104
105const 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
109char **trackdb_alltags(void);
110/* Return the list of all tags */
111
112const 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
118const 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
122enum trackdb_listable {
123 trackdb_files = 1,
124 trackdb_directories = 2
125};
126
127char **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
136char **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
dd9af5cb
RK
140void trackdb_rescan(struct ev_source *ev, int recheck,
141 void (*rescanned)(void *ru),
142 void *ru);
460b9539 143/* Start a rescan, if one is not running already */
144
145int trackdb_rescan_cancel(void);
146/* interrupt any running rescan. Return 1 if one was running, else 0. */
147
148void trackdb_gc(void);
149/* tidy up old database log files */
150
151void trackdb_set_global(const char *name,
152 const char *value,
153 const char *who);
154/* set a global pref (remove if value=0). */
155
156const char *trackdb_get_global(const char *name);
157/* get a global pref */
158
2a10b70b
RK
159char **trackdb_new(int *ntracksp, int maxtracks);
160
1e64e9fb 161void trackdb_expire_noticed(time_t when);
f0feb22e
RK
162void trackdb_old_users(void);
163void trackdb_create_root(void);
164const char *trackdb_get_password(const char *user);
165int trackdb_adduser(const char *user,
166 const char *password,
0f55e905 167 const char *rights,
ba39faf6
RK
168 const char *email,
169 const char *confirmation);
f0feb22e
RK
170int trackdb_deluser(const char *user);
171struct kvp *trackdb_getuserinfo(const char *user);
172int trackdb_edituserinfo(const char *user,
173 const char *key, const char *value);
c3be4f19 174char **trackdb_listusers(void);
30365519 175int trackdb_confirm(const char *user, const char *confirmation,
176 rights_type *rightsp);
199c2a23 177int trackdb_readable(void);
f0feb22e 178
49a773eb
RK
179typedef void random_callback(struct ev_source *ev,
180 const char *track);
181int trackdb_request_random(struct ev_source *ev,
182 random_callback *callback);
dd9af5cb
RK
183void trackdb_add_rescanned(void (*rescanned)(void *ru),
184 void *ru);
185int trackdb_rescan_underway(void);
49a773eb 186
460b9539 187#endif /* TRACKDB_H */
188
189/*
190Local Variables:
191c-basic-offset:2
192comment-column:40
193fill-column:79
194indent-tabs-mode:nil
195End:
196*/