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