]> gitweb.ps.run Git - ps-cgit/blob - cgit.h
ui-shared: fix broken sizeof in title setting and rewrite
[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 <argv-array.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
29 /* Add isgraph(x) to Git's sane ctype support (see git-compat-util.h) */
30 #undef isgraph
31 #define isgraph(x) (isprint((x)) && !isspace((x)))
32
33
34 /*
35  * Limits used for relative dates
36  */
37 #define TM_MIN    60
38 #define TM_HOUR  (TM_MIN * 60)
39 #define TM_DAY   (TM_HOUR * 24)
40 #define TM_WEEK  (TM_DAY * 7)
41 #define TM_YEAR  (TM_DAY * 365)
42 #define TM_MONTH (TM_YEAR / 12.0)
43
44
45 /*
46  * Default encoding
47  */
48 #define PAGE_ENCODING "UTF-8"
49
50 #define BIT(x)  (1U << (x))
51
52 typedef void (*configfn)(const char *name, const char *value);
53 typedef void (*filepair_fn)(struct diff_filepair *pair);
54 typedef void (*linediff_fn)(char *line, int len);
55
56 typedef enum {
57         DIFF_UNIFIED, DIFF_SSDIFF, DIFF_STATONLY
58 } diff_type;
59
60 typedef enum {
61         ABOUT, COMMIT, SOURCE, EMAIL, AUTH, OWNER
62 } filter_type;
63
64 struct cgit_filter {
65         int (*open)(struct cgit_filter *, va_list ap);
66         int (*close)(struct cgit_filter *);
67         void (*fprintf)(struct cgit_filter *, FILE *, const char *prefix);
68         void (*cleanup)(struct cgit_filter *);
69         int argument_count;
70 };
71
72 struct cgit_exec_filter {
73         struct cgit_filter base;
74         char *cmd;
75         char **argv;
76         int old_stdout;
77         int pid;
78 };
79
80 struct cgit_repo {
81         char *url;
82         char *name;
83         char *path;
84         char *desc;
85         char *extra_head_content;
86         char *owner;
87         char *homepage;
88         char *defbranch;
89         char *module_link;
90         struct string_list readme;
91         char *section;
92         char *clone_url;
93         char *logo;
94         char *logo_link;
95         char *snapshot_prefix;
96         int snapshots;
97         int enable_commit_graph;
98         int enable_log_filecount;
99         int enable_log_linecount;
100         int enable_remote_branches;
101         int enable_subject_links;
102         int enable_html_serving;
103         int max_stats;
104         int branch_sort;
105         int commit_sort;
106         time_t mtime;
107         struct cgit_filter *about_filter;
108         struct cgit_filter *commit_filter;
109         struct cgit_filter *source_filter;
110         struct cgit_filter *email_filter;
111         struct cgit_filter *owner_filter;
112         struct string_list submodules;
113         int hide;
114         int ignore;
115 };
116
117 typedef void (*repo_config_fn)(struct cgit_repo *repo, const char *name,
118               const char *value);
119
120 struct cgit_repolist {
121         int length;
122         int count;
123         struct cgit_repo *repos;
124 };
125
126 struct commitinfo {
127         struct commit *commit;
128         char *author;
129         char *author_email;
130         unsigned long author_date;
131         int author_tz;
132         char *committer;
133         char *committer_email;
134         unsigned long committer_date;
135         int committer_tz;
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         int tagger_tz;
146         char *msg;
147 };
148
149 struct refinfo {
150         const char *refname;
151         struct object *object;
152         union {
153                 struct taginfo *tag;
154                 struct commitinfo *commit;
155         };
156 };
157
158 struct reflist {
159         struct refinfo **refs;
160         int alloc;
161         int count;
162 };
163
164 struct cgit_query {
165         int has_symref;
166         int has_sha1;
167         int has_difftype;
168         char *raw;
169         char *repo;
170         char *page;
171         char *search;
172         char *grep;
173         char *head;
174         char *sha1;
175         char *sha2;
176         char *path;
177         char *name;
178         char *url;
179         char *period;
180         int   ofs;
181         int nohead;
182         char *sort;
183         int showmsg;
184         diff_type difftype;
185         int show_all;
186         int context;
187         int ignorews;
188         int follow;
189         char *vpath;
190 };
191
192 struct cgit_config {
193         char *agefile;
194         char *cache_root;
195         char *clone_prefix;
196         char *clone_url;
197         char *css;
198         char *favicon;
199         char *footer;
200         char *head_include;
201         char *header;
202         char *logo;
203         char *logo_link;
204         char *mimetype_file;
205         char *module_link;
206         char *project_list;
207         struct string_list readme;
208         char *robots;
209         char *root_title;
210         char *root_desc;
211         char *root_readme;
212         char *script_name;
213         char *section;
214         char *repository_sort;
215         char *virtual_root;     /* Always ends with '/'. */
216         char *strict_export;
217         int cache_size;
218         int cache_dynamic_ttl;
219         int cache_max_create_time;
220         int cache_repo_ttl;
221         int cache_root_ttl;
222         int cache_scanrc_ttl;
223         int cache_static_ttl;
224         int cache_about_ttl;
225         int cache_snapshot_ttl;
226         int case_sensitive_sort;
227         int embedded;
228         int enable_filter_overrides;
229         int enable_follow_links;
230         int enable_http_clone;
231         int enable_index_links;
232         int enable_index_owner;
233         int enable_blame;
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 noplainemail;
252         int noheader;
253         int renamelimit;
254         int remove_suffix;
255         int scan_hidden_path;
256         int section_from_path;
257         int snapshots;
258         int section_sort;
259         int summary_branches;
260         int summary_log;
261         int summary_tags;
262         diff_type difftype;
263         int branch_sort;
264         int commit_sort;
265         struct string_list mimetypes;
266         struct cgit_filter *about_filter;
267         struct cgit_filter *commit_filter;
268         struct cgit_filter *source_filter;
269         struct cgit_filter *email_filter;
270         struct cgit_filter *owner_filter;
271         struct cgit_filter *auth_filter;
272 };
273
274 struct cgit_page {
275         time_t modified;
276         time_t expires;
277         size_t size;
278         const char *mimetype;
279         const char *charset;
280         const char *filename;
281         const char *etag;
282         const char *title;
283         int status;
284         const char *statusmsg;
285 };
286
287 struct cgit_environment {
288         const char *cgit_config;
289         const char *http_host;
290         const char *https;
291         const char *no_http;
292         const char *path_info;
293         const char *query_string;
294         const char *request_method;
295         const char *script_name;
296         const char *server_name;
297         const char *server_port;
298         const char *http_cookie;
299         const char *http_referer;
300         unsigned int content_length;
301         int authenticated;
302 };
303
304 struct cgit_context {
305         struct cgit_environment env;
306         struct cgit_query qry;
307         struct cgit_config cfg;
308         struct cgit_repo *repo;
309         struct cgit_page page;
310 };
311
312 typedef int (*write_archive_fn_t)(const char *, const char *);
313
314 struct cgit_snapshot_format {
315         const char *suffix;
316         const char *mimetype;
317         write_archive_fn_t write_func;
318 };
319
320 extern const char *cgit_version;
321
322 extern struct cgit_repolist cgit_repolist;
323 extern struct cgit_context ctx;
324 extern const struct cgit_snapshot_format cgit_snapshot_formats[];
325
326 extern char *cgit_default_repo_desc;
327 extern struct cgit_repo *cgit_add_repo(const char *url);
328 extern struct cgit_repo *cgit_get_repoinfo(const char *url);
329 extern void cgit_repo_config_cb(const char *name, const char *value);
330
331 extern int chk_zero(int result, char *msg);
332 extern int chk_positive(int result, char *msg);
333 extern int chk_non_negative(int result, char *msg);
334
335 extern char *trim_end(const char *str, char c);
336 extern char *ensure_end(const char *str, char c);
337
338 extern void strbuf_ensure_end(struct strbuf *sb, char c);
339
340 extern void cgit_add_ref(struct reflist *list, struct refinfo *ref);
341 extern void cgit_free_reflist_inner(struct reflist *list);
342 extern int cgit_refs_cb(const char *refname, const struct object_id *oid,
343                         int flags, void *cb_data);
344
345 extern void cgit_free_commitinfo(struct commitinfo *info);
346 extern void cgit_free_taginfo(struct taginfo *info);
347
348 void cgit_diff_tree_cb(struct diff_queue_struct *q,
349                        struct diff_options *options, void *data);
350
351 extern int cgit_diff_files(const struct object_id *old_oid,
352                            const struct object_id *new_oid,
353                            unsigned long *old_size, unsigned long *new_size,
354                            int *binary, int context, int ignorews,
355                            linediff_fn fn);
356
357 extern void cgit_diff_tree(const struct object_id *old_oid,
358                            const struct object_id *new_oid,
359                            filepair_fn fn, const char *prefix, int ignorews);
360
361 extern void cgit_diff_commit(struct commit *commit, filepair_fn fn,
362                              const char *prefix);
363
364 __attribute__((format (printf,1,2)))
365 extern char *fmt(const char *format,...);
366
367 __attribute__((format (printf,1,2)))
368 extern char *fmtalloc(const char *format,...);
369
370 extern struct commitinfo *cgit_parse_commit(struct commit *commit);
371 extern struct taginfo *cgit_parse_tag(struct tag *tag);
372 extern void cgit_parse_url(const char *url);
373
374 extern const char *cgit_repobasename(const char *reponame);
375
376 extern int cgit_parse_snapshots_mask(const char *str);
377 extern const struct object_id *cgit_snapshot_get_sig(const char *ref,
378                                                      const struct cgit_snapshot_format *f);
379 extern const unsigned cgit_snapshot_format_bit(const struct cgit_snapshot_format *f);
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 */