]> gitweb.ps.run Git - ps-cgit/blob - cgit.h
config: make empty js= omit script tag
[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 <object-store.h>
12 #include <tree.h>
13 #include <commit.h>
14 #include <tag.h>
15 #include <diff.h>
16 #include <diffcore.h>
17 #include <strvec.h>
18 #include <refs.h>
19 #include <revision.h>
20 #include <log-tree.h>
21 #include <archive.h>
22 #include <string-list.h>
23 #include <xdiff-interface.h>
24 #include <xdiff/xdiff.h>
25 #include <utf8.h>
26 #include <notes.h>
27 #include <graph.h>
28 #include <inttypes.h>
29
30 /* Add isgraph(x) to Git's sane ctype support (see git-compat-util.h) */
31 #undef isgraph
32 #define isgraph(x) (isprint((x)) && !isspace((x)))
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 #define BIT(x)  (1U << (x))
52
53 typedef void (*configfn)(const char *name, const char *value);
54 typedef void (*filepair_fn)(struct diff_filepair *pair);
55 typedef void (*linediff_fn)(char *line, int len);
56
57 typedef enum {
58         DIFF_UNIFIED, DIFF_SSDIFF, DIFF_STATONLY
59 } diff_type;
60
61 typedef enum {
62         ABOUT, COMMIT, SOURCE, EMAIL, AUTH, OWNER
63 } filter_type;
64
65 struct cgit_filter {
66         int (*open)(struct cgit_filter *, va_list ap);
67         int (*close)(struct cgit_filter *);
68         void (*fprintf)(struct cgit_filter *, FILE *, const char *prefix);
69         void (*cleanup)(struct cgit_filter *);
70         int argument_count;
71 };
72
73 struct cgit_exec_filter {
74         struct cgit_filter base;
75         char *cmd;
76         char **argv;
77         int old_stdout;
78         int pid;
79 };
80
81 struct cgit_repo {
82         char *url;
83         char *name;
84         char *path;
85         char *desc;
86         char *extra_head_content;
87         char *owner;
88         char *homepage;
89         char *defbranch;
90         char *module_link;
91         struct string_list readme;
92         char *section;
93         char *clone_url;
94         char *logo;
95         char *logo_link;
96         char *snapshot_prefix;
97         int snapshots;
98         int enable_blame;
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         int author_tz;
134         char *committer;
135         char *committer_email;
136         unsigned long committer_date;
137         int committer_tz;
138         char *subject;
139         char *msg;
140         char *msg_encoding;
141 };
142
143 struct taginfo {
144         char *tagger;
145         char *tagger_email;
146         unsigned long tagger_date;
147         int tagger_tz;
148         char *msg;
149 };
150
151 struct refinfo {
152         const char *refname;
153         struct object *object;
154         union {
155                 struct taginfo *tag;
156                 struct commitinfo *commit;
157         };
158 };
159
160 struct reflist {
161         struct refinfo **refs;
162         int alloc;
163         int count;
164 };
165
166 struct cgit_query {
167         int has_symref;
168         int has_oid;
169         int has_difftype;
170         char *raw;
171         char *repo;
172         char *page;
173         char *search;
174         char *grep;
175         char *head;
176         char *oid;
177         char *oid2;
178         char *path;
179         char *name;
180         char *url;
181         char *period;
182         int   ofs;
183         int nohead;
184         char *sort;
185         int showmsg;
186         diff_type difftype;
187         int show_all;
188         int context;
189         int ignorews;
190         int follow;
191         char *vpath;
192 };
193
194 struct cgit_config {
195         char *agefile;
196         char *cache_root;
197         char *clone_prefix;
198         char *clone_url;
199         char *favicon;
200         char *footer;
201         char *head_include;
202         char *header;
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         struct string_list css;
210         char *robots;
211         char *root_title;
212         char *root_desc;
213         char *root_readme;
214         char *script_name;
215         char *section;
216         char *repository_sort;
217         char *virtual_root;     /* Always ends with '/'. */
218         char *strict_export;
219         int cache_size;
220         int cache_dynamic_ttl;
221         int cache_max_create_time;
222         int cache_repo_ttl;
223         int cache_root_ttl;
224         int cache_scanrc_ttl;
225         int cache_static_ttl;
226         int cache_about_ttl;
227         int cache_snapshot_ttl;
228         int case_sensitive_sort;
229         int embedded;
230         int enable_filter_overrides;
231         int enable_follow_links;
232         int enable_http_clone;
233         int enable_index_links;
234         int enable_index_owner;
235         int enable_blame;
236         int enable_commit_graph;
237         int enable_log_filecount;
238         int enable_log_linecount;
239         int enable_remote_branches;
240         int enable_subject_links;
241         int enable_html_serving;
242         int enable_tree_linenumbers;
243         int enable_git_config;
244         int local_time;
245         int max_atom_items;
246         int max_repo_count;
247         int max_commit_count;
248         int max_lock_attempts;
249         int max_msg_len;
250         int max_repodesc_len;
251         int max_blob_size;
252         int max_stats;
253         int noplainemail;
254         int noheader;
255         int renamelimit;
256         int remove_suffix;
257         int scan_hidden_path;
258         int section_from_path;
259         int snapshots;
260         int section_sort;
261         int summary_branches;
262         int summary_log;
263         int summary_tags;
264         diff_type difftype;
265         int branch_sort;
266         int commit_sort;
267         struct string_list mimetypes;
268         struct string_list js;
269         struct cgit_filter *about_filter;
270         struct cgit_filter *commit_filter;
271         struct cgit_filter *source_filter;
272         struct cgit_filter *email_filter;
273         struct cgit_filter *owner_filter;
274         struct cgit_filter *auth_filter;
275 };
276
277 struct cgit_page {
278         time_t modified;
279         time_t expires;
280         size_t size;
281         const char *mimetype;
282         const char *charset;
283         const char *filename;
284         const char *etag;
285         const char *title;
286         int status;
287         const char *statusmsg;
288 };
289
290 struct cgit_environment {
291         const char *cgit_config;
292         const char *http_host;
293         const char *https;
294         const char *no_http;
295         const char *path_info;
296         const char *query_string;
297         const char *request_method;
298         const char *script_name;
299         const char *server_name;
300         const char *server_port;
301         const char *http_cookie;
302         const char *http_referer;
303         unsigned int content_length;
304         int authenticated;
305 };
306
307 struct cgit_context {
308         struct cgit_environment env;
309         struct cgit_query qry;
310         struct cgit_config cfg;
311         struct cgit_repo *repo;
312         struct cgit_page page;
313 };
314
315 typedef int (*write_archive_fn_t)(const char *, const char *);
316
317 struct cgit_snapshot_format {
318         const char *suffix;
319         const char *mimetype;
320         write_archive_fn_t write_func;
321 };
322
323 extern const char *cgit_version;
324
325 extern struct cgit_repolist cgit_repolist;
326 extern struct cgit_context ctx;
327 extern const struct cgit_snapshot_format cgit_snapshot_formats[];
328
329 extern char *cgit_default_repo_desc;
330 extern struct cgit_repo *cgit_add_repo(const char *url);
331 extern struct cgit_repo *cgit_get_repoinfo(const char *url);
332 extern void cgit_repo_config_cb(const char *name, const char *value);
333
334 extern int chk_zero(int result, char *msg);
335 extern int chk_positive(int result, char *msg);
336 extern int chk_non_negative(int result, char *msg);
337
338 extern char *trim_end(const char *str, char c);
339 extern char *ensure_end(const char *str, char c);
340
341 extern void strbuf_ensure_end(struct strbuf *sb, char c);
342
343 extern void cgit_add_ref(struct reflist *list, struct refinfo *ref);
344 extern void cgit_free_reflist_inner(struct reflist *list);
345 extern int cgit_refs_cb(const char *refname, const struct object_id *oid,
346                         int flags, void *cb_data);
347
348 extern void cgit_free_commitinfo(struct commitinfo *info);
349 extern void cgit_free_taginfo(struct taginfo *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 struct object_id *old_oid,
355                            const struct object_id *new_oid,
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 struct object_id *old_oid,
361                            const struct object_id *new_oid,
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 extern const struct object_id *cgit_snapshot_get_sig(const char *ref,
381                                                      const struct cgit_snapshot_format *f);
382 extern const unsigned cgit_snapshot_format_bit(const struct cgit_snapshot_format *f);
383
384 extern int cgit_open_filter(struct cgit_filter *filter, ...);
385 extern int cgit_close_filter(struct cgit_filter *filter);
386 extern void cgit_fprintf_filter(struct cgit_filter *filter, FILE *f, const char *prefix);
387 extern void cgit_exec_filter_init(struct cgit_exec_filter *filter, char *cmd, char **argv);
388 extern struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype);
389 extern void cgit_cleanup_filters(void);
390 extern void cgit_init_filters(void);
391
392 extern void cgit_prepare_repo_env(struct cgit_repo * repo);
393
394 extern int readfile(const char *path, char **buf, size_t *size);
395
396 extern char *expand_macros(const char *txt);
397
398 extern char *get_mimetype_for_filename(const char *filename);
399
400 #endif /* CGIT_H */