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