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