]> gitweb.ps.run Git - ps-cgit/blob - cgit.h
filter: basic write hooking infrastructure
[ps-cgit] / cgit.h
1 #ifndef CGIT_H
2 #define CGIT_H
3
4
5 #include <git-compat-util.h>
6 #include <cache.h>
7 #include <grep.h>
8 #include <object.h>
9 #include <tree.h>
10 #include <commit.h>
11 #include <tag.h>
12 #include <diff.h>
13 #include <diffcore.h>
14 #include <argv-array.h>
15 #include <refs.h>
16 #include <revision.h>
17 #include <log-tree.h>
18 #include <archive.h>
19 #include <string-list.h>
20 #include <xdiff-interface.h>
21 #include <xdiff/xdiff.h>
22 #include <utf8.h>
23 #include <notes.h>
24 #include <graph.h>
25
26
27 /*
28  * Dateformats used on misc. pages
29  */
30 #define FMT_LONGDATE "%Y-%m-%d %H:%M:%S (%Z)"
31 #define FMT_SHORTDATE "%Y-%m-%d"
32 #define FMT_ATOMDATE "%Y-%m-%dT%H:%M:%SZ"
33
34
35 /*
36  * Limits used for relative dates
37  */
38 #define TM_MIN    60
39 #define TM_HOUR  (TM_MIN * 60)
40 #define TM_DAY   (TM_HOUR * 24)
41 #define TM_WEEK  (TM_DAY * 7)
42 #define TM_YEAR  (TM_DAY * 365)
43 #define TM_MONTH (TM_YEAR / 12.0)
44
45
46 /*
47  * Default encoding
48  */
49 #define PAGE_ENCODING "UTF-8"
50
51 typedef void (*configfn)(const char *name, const char *value);
52 typedef void (*filepair_fn)(struct diff_filepair *pair);
53 typedef void (*linediff_fn)(char *line, int len);
54
55 typedef enum {
56         ABOUT, COMMIT, SOURCE
57 } filter_type;
58
59 struct cgit_filter {
60         int (*open)(struct cgit_filter *, va_list ap);
61         int (*close)(struct cgit_filter *);
62         void (*fprintf)(struct cgit_filter *, FILE *, const char *prefix);
63         void (*cleanup)(struct cgit_filter *);
64         int argument_count;
65 };
66
67 struct cgit_exec_filter {
68         struct cgit_filter base;
69         char *cmd;
70         char **argv;
71         int old_stdout;
72         int pipe_fh[2];
73         int pid;
74 };
75
76 struct cgit_repo {
77         char *url;
78         char *name;
79         char *path;
80         char *desc;
81         char *owner;
82         char *defbranch;
83         char *module_link;
84         struct string_list readme;
85         char *section;
86         char *clone_url;
87         char *logo;
88         char *logo_link;
89         int snapshots;
90         int enable_commit_graph;
91         int enable_log_filecount;
92         int enable_log_linecount;
93         int enable_remote_branches;
94         int enable_subject_links;
95         int max_stats;
96         int branch_sort;
97         int commit_sort;
98         time_t mtime;
99         struct cgit_filter *about_filter;
100         struct cgit_filter *commit_filter;
101         struct cgit_filter *source_filter;
102         struct string_list submodules;
103 };
104
105 typedef void (*repo_config_fn)(struct cgit_repo *repo, const char *name,
106               const char *value);
107
108 struct cgit_repolist {
109         int length;
110         int count;
111         struct cgit_repo *repos;
112 };
113
114 struct commitinfo {
115         struct commit *commit;
116         char *author;
117         char *author_email;
118         unsigned long author_date;
119         char *committer;
120         char *committer_email;
121         unsigned long committer_date;
122         char *subject;
123         char *msg;
124         char *msg_encoding;
125 };
126
127 struct taginfo {
128         char *tagger;
129         char *tagger_email;
130         unsigned long tagger_date;
131         char *msg;
132 };
133
134 struct refinfo {
135         const char *refname;
136         struct object *object;
137         union {
138                 struct taginfo *tag;
139                 struct commitinfo *commit;
140         };
141 };
142
143 struct reflist {
144         struct refinfo **refs;
145         int alloc;
146         int count;
147 };
148
149 struct cgit_query {
150         int has_symref;
151         int has_sha1;
152         int has_ssdiff;
153         char *raw;
154         char *repo;
155         char *page;
156         char *search;
157         char *grep;
158         char *head;
159         char *sha1;
160         char *sha2;
161         char *path;
162         char *name;
163         char *mimetype;
164         char *url;
165         char *period;
166         int   ofs;
167         int nohead;
168         char *sort;
169         int showmsg;
170         int ssdiff;
171         int show_all;
172         int context;
173         int ignorews;
174         char *vpath;
175 };
176
177 struct cgit_config {
178         char *agefile;
179         char *cache_root;
180         char *clone_prefix;
181         char *clone_url;
182         char *css;
183         char *favicon;
184         char *footer;
185         char *head_include;
186         char *header;
187         char *index_header;
188         char *index_info;
189         char *logo;
190         char *logo_link;
191         char *mimetype_file;
192         char *module_link;
193         char *project_list;
194         struct string_list readme;
195         char *robots;
196         char *root_title;
197         char *root_desc;
198         char *root_readme;
199         char *script_name;
200         char *section;
201         char *repository_sort;
202         char *virtual_root;     /* Always ends with '/'. */
203         char *strict_export;
204         int cache_size;
205         int cache_dynamic_ttl;
206         int cache_max_create_time;
207         int cache_repo_ttl;
208         int cache_root_ttl;
209         int cache_scanrc_ttl;
210         int cache_static_ttl;
211         int cache_about_ttl;
212         int case_sensitive_sort;
213         int embedded;
214         int enable_filter_overrides;
215         int enable_http_clone;
216         int enable_index_links;
217         int enable_index_owner;
218         int enable_commit_graph;
219         int enable_log_filecount;
220         int enable_log_linecount;
221         int enable_remote_branches;
222         int enable_subject_links;
223         int enable_tree_linenumbers;
224         int enable_git_config;
225         int local_time;
226         int max_atom_items;
227         int max_repo_count;
228         int max_commit_count;
229         int max_lock_attempts;
230         int max_msg_len;
231         int max_repodesc_len;
232         int max_blob_size;
233         int max_stats;
234         int nocache;
235         int noplainemail;
236         int noheader;
237         int renamelimit;
238         int remove_suffix;
239         int scan_hidden_path;
240         int section_from_path;
241         int snapshots;
242         int section_sort;
243         int summary_branches;
244         int summary_log;
245         int summary_tags;
246         int ssdiff;
247         int branch_sort;
248         int commit_sort;
249         struct string_list mimetypes;
250         struct cgit_filter *about_filter;
251         struct cgit_filter *commit_filter;
252         struct cgit_filter *source_filter;
253 };
254
255 struct cgit_page {
256         time_t modified;
257         time_t expires;
258         size_t size;
259         const char *mimetype;
260         const char *charset;
261         const char *filename;
262         const char *etag;
263         const char *title;
264         int status;
265         const char *statusmsg;
266 };
267
268 struct cgit_environment {
269         const char *cgit_config;
270         const char *http_host;
271         const char *https;
272         const char *no_http;
273         const char *path_info;
274         const char *query_string;
275         const char *request_method;
276         const char *script_name;
277         const char *server_name;
278         const char *server_port;
279 };
280
281 struct cgit_context {
282         struct cgit_environment env;
283         struct cgit_query qry;
284         struct cgit_config cfg;
285         struct cgit_repo *repo;
286         struct cgit_page page;
287 };
288
289 typedef int (*write_archive_fn_t)(const char *, const char *);
290
291 struct cgit_snapshot_format {
292         const char *suffix;
293         const char *mimetype;
294         write_archive_fn_t write_func;
295         int bit;
296 };
297
298 extern const char *cgit_version;
299
300 extern struct cgit_repolist cgit_repolist;
301 extern struct cgit_context ctx;
302 extern const struct cgit_snapshot_format cgit_snapshot_formats[];
303
304 extern char *cgit_default_repo_desc;
305 extern struct cgit_repo *cgit_add_repo(const char *url);
306 extern struct cgit_repo *cgit_get_repoinfo(const char *url);
307 extern void cgit_repo_config_cb(const char *name, const char *value);
308
309 extern int chk_zero(int result, char *msg);
310 extern int chk_positive(int result, char *msg);
311 extern int chk_non_negative(int result, char *msg);
312
313 extern char *trim_end(const char *str, char c);
314 extern char *ensure_end(const char *str, char c);
315 extern char *strlpart(char *txt, int maxlen);
316 extern char *strrpart(char *txt, int maxlen);
317
318 extern void strbuf_ensure_end(struct strbuf *sb, char c);
319
320 extern void cgit_add_ref(struct reflist *list, struct refinfo *ref);
321 extern void cgit_free_reflist_inner(struct reflist *list);
322 extern int cgit_refs_cb(const char *refname, const unsigned char *sha1,
323                         int flags, void *cb_data);
324
325 extern void *cgit_free_commitinfo(struct commitinfo *info);
326
327 extern int cgit_diff_files(const unsigned char *old_sha1,
328                            const unsigned char *new_sha1,
329                            unsigned long *old_size, unsigned long *new_size,
330                            int *binary, int context, int ignorews,
331                            linediff_fn fn);
332
333 extern void cgit_diff_tree(const unsigned char *old_sha1,
334                            const unsigned char *new_sha1,
335                            filepair_fn fn, const char *prefix, int ignorews);
336
337 extern void cgit_diff_commit(struct commit *commit, filepair_fn fn,
338                              const char *prefix);
339
340 __attribute__((format (printf,1,2)))
341 extern char *fmt(const char *format,...);
342
343 __attribute__((format (printf,1,2)))
344 extern char *fmtalloc(const char *format,...);
345
346 extern struct commitinfo *cgit_parse_commit(struct commit *commit);
347 extern struct taginfo *cgit_parse_tag(struct tag *tag);
348 extern void cgit_parse_url(const char *url);
349
350 extern const char *cgit_repobasename(const char *reponame);
351
352 extern int cgit_parse_snapshots_mask(const char *str);
353
354 extern int cgit_open_filter(struct cgit_filter *filter, ...);
355 extern int cgit_close_filter(struct cgit_filter *filter);
356 extern void cgit_fprintf_filter(struct cgit_filter *filter, FILE *f, const char *prefix);
357 extern void cgit_exec_filter_init(struct cgit_exec_filter *filter, char *cmd, char **argv);
358 extern struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype);
359 extern void cgit_cleanup_filters(void);
360 extern void cgit_init_filters(void);
361
362 extern void cgit_prepare_repo_env(struct cgit_repo * repo);
363
364 extern int readfile(const char *path, char **buf, size_t *size);
365
366 extern char *expand_macros(const char *txt);
367
368 #endif /* CGIT_H */