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