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