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