chiark / gitweb /
Commit 2.4.5-5 as unpacked
[innduct.git] / storage / tradindexed / tdx-private.h
1 /*  $Id: tdx-private.h 5465 2002-05-06 05:46:15Z rra $
2 **
3 **  Private APIs for the tradindexed overview method.
4 */
5
6 #ifndef INN_TDX_PRIVATE_H
7 #define INN_TDX_PRIVATE_H 1
8
9 #include "config.h"
10 #include <stdio.h>
11 #include <sys/types.h>
12
13 #include "libinn.h"
14 #include "storage.h"
15
16 /* Forward declarations to avoid unnecessary includes. */
17 struct history;
18
19 /* Opaque data structure used by the cache. */
20 struct cache;
21
22 /* Opaque data structure returned by group index functions. */
23 struct group_index;
24
25 /* Opaque data structure returned by search functions. */
26 struct search;
27
28 /* All of the information about an open set of group data files. */
29 struct group_data {
30     char *path;
31     bool writable;
32     ARTNUM high;
33     ARTNUM base;
34     int indexfd;
35     int datafd;
36     struct index_entry *index;
37     char *data;
38     off_t indexlen;
39     off_t datalen;
40     ino_t indexinode;
41     int refcount;
42 };
43
44 /* All of the data about an article, used as the return of the search
45    functions.  This is just cleaner than passing back all of the information
46    that's used by the regular interface. */
47 struct article {
48     ARTNUM number;
49     const char *overview;
50     size_t overlen;
51     TOKEN token;
52     time_t arrived;
53     time_t expires;
54 };
55
56 BEGIN_DECLS
57
58 /* tdx-cache.c */
59
60 /* Create a new cache with the given number of entries. */
61 struct cache *tdx_cache_create(unsigned int size);
62
63 /* Look up a given newsgroup hash in the cache, returning the group_data
64    struct for its open data files if present. */
65 struct group_data *tdx_cache_lookup(struct cache *, HASH);
66
67 /* Insert a new group_data struct into the cache. */
68 void tdx_cache_insert(struct cache *, HASH, struct group_data *);
69
70 /* Delete a group entry from the cache. */
71 void tdx_cache_delete(struct cache *, HASH);
72
73 /* Free the cache and its resources. */
74 void tdx_cache_free(struct cache *);
75
76
77 /* tdx-group.c */
78
79 /* Open the group index and return an opaque data structure to use for further
80    queries. */
81 struct group_index *tdx_index_open(bool writable);
82
83 /* Return the stored information about a single newsgroup. */
84 struct group_entry *tdx_index_entry(struct group_index *, const char *group);
85
86 /* Print the contents of a single group entry in human-readable form. */
87 void tdx_index_print(const char *name, const struct group_entry *, FILE *);
88
89 /* Add a new newsgroup to the index file. */
90 bool tdx_index_add(struct group_index *, const char *group, ARTNUM low,
91                    ARTNUM high, const char *flag);
92
93 /* Delete a newsgroup from the index file. */
94 bool tdx_index_delete(struct group_index *, const char *group);
95
96 /* Dump the contents of the index file to stdout in human-readable form. */
97 void tdx_index_dump(struct group_index *, FILE *);
98
99 /* Audit all of the overview data, optionally trying to fix it. */
100 void tdx_index_audit(bool fix);
101
102 /* Close the open index file and dispose of the opaque data structure. */
103 void tdx_index_close(struct group_index *);
104
105 /* Open the overview information for a particular group. */
106 struct group_data *tdx_data_open(struct group_index *, const char *group,
107                                  struct group_entry *);
108
109 /* Add a new overview entry. */
110 bool tdx_data_add(struct group_index *, struct group_entry *,
111                   struct group_data *, const struct article *);
112
113 /* Handle rebuilds of the data for a particular group.  Call _start first and
114    then _finish when done, with the new group_entry information. */
115 bool tdx_index_rebuild_start(struct group_index *, struct group_entry *);
116 bool tdx_index_rebuild_finish(struct group_index *, struct group_entry *,
117                               struct group_entry *new);
118
119 /* Expire a single group. */
120 bool tdx_expire(const char *group, ARTNUM *low, struct history *);
121
122
123 /* tdx-data.c */
124
125 /* Create a new group data structure. */
126 struct group_data *tdx_data_new(const char *group, bool writable);
127
128 /* Open the data files for a group. */
129 bool tdx_data_open_files(struct group_data *);
130
131 /* Return the metadata about a particular article in a group. */
132 const struct index_entry *tdx_article_entry(struct group_data *,
133                                             ARTNUM article, ARTNUM high);
134
135 /* Create, perform, and close a search. */
136 struct search *tdx_search_open(struct group_data *, ARTNUM start, ARTNUM end,
137                                ARTNUM high);
138 bool tdx_search(struct search *, struct article *);
139 void tdx_search_close(struct search *);
140
141 /* Store article data. */
142 bool tdx_data_store(struct group_data *, const struct article *);
143
144 /* Start a repack of the files for a newsgroup. */
145 bool tdx_data_pack_start(struct group_data *, ARTNUM);
146
147 /* Complete a repack of the files for a newsgroup. */
148 bool tdx_data_pack_finish(struct group_data *);
149
150 /* Manage a rebuild of the data files for a particular group.  Until
151    tdx_data_rebuild_finish is called, anything stored into the returned struct
152    group_data will have no effect on the data for that group.  Does not handle
153    updating the index entries; that must be done separately. */
154 struct group_data *tdx_data_rebuild_start(const char *group);
155 bool tdx_data_rebuild_finish(const char *group);
156
157 /* Start the expiration of a newsgroup and do most of the work, filling out
158    the provided group_entry struct.  Complete with tdx_data_rebuild_finish. */
159 bool tdx_data_expire_start(const char *group, struct group_data *,
160                            struct group_entry *, struct history *);
161
162 /* Dump the contents of the index file for a group. */
163 void tdx_data_index_dump(struct group_data *, FILE *);
164
165 /* Audit the data for a particular group, optionally trying to fix it. */
166 void tdx_data_audit(const char *group, struct group_entry *, bool fix);
167
168 /* Close the open data files for a group and free the structure. */
169 void tdx_data_close(struct group_data *);
170
171 /* Delete the data files for a group. */
172 void tdx_data_delete(const char *group, const char *suffix);
173
174 END_DECLS
175
176 #endif /* INN_TDX_PRIVATE_H */