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
49#define BIT(x) (1U << (x))
50
51typedef void (*configfn)(const char *name, const char *value);
52typedef void (*filepair_fn)(struct diff_filepair *pair);
53typedef void (*linediff_fn)(char *line, int len);
54
55typedef enum {
56 DIFF_UNIFIED, DIFF_SSDIFF, DIFF_STATONLY
57} diff_type;
58
59typedef enum {
60 ABOUT, COMMIT, SOURCE, EMAIL, AUTH, OWNER
61} filter_type;
62
63struct cgit_filter {
64 int (*open)(struct cgit_filter *, va_list ap);
65 int (*close)(struct cgit_filter *);
66 void (*fprintf)(struct cgit_filter *, FILE *, const char *prefix);
67 void (*cleanup)(struct cgit_filter *);
68 int argument_count;
69};
70
71struct cgit_exec_filter {
72 struct cgit_filter base;
73 char *cmd;
74 char **argv;
75 int old_stdout;
76 int pid;
77};
78
79struct cgit_repo {
80 char *url;
81 char *name;
82 char *path;
83 char *desc;
84 char *owner;
85 char *homepage;
86 char *defbranch;
87 char *module_link;
88 struct string_list readme;
89 char *section;
90 char *clone_url;
91 char *logo;
92 char *logo_link;
93 char *snapshot_prefix;
94 int snapshots;
95 int enable_commit_graph;
96 int enable_log_filecount;
97 int enable_log_linecount;
98 int enable_remote_branches;
99 int enable_subject_links;
100 int enable_html_serving;
101 int max_stats;
102 int branch_sort;
103 int commit_sort;
104 time_t mtime;
105 struct cgit_filter *about_filter;
106 struct cgit_filter *commit_filter;
107 struct cgit_filter *source_filter;
108 struct cgit_filter *email_filter;
109 struct cgit_filter *owner_filter;
110 struct string_list submodules;
111 int hide;
112 int ignore;
113};
114
115typedef void (*repo_config_fn)(struct cgit_repo *repo, const char *name,
116 const char *value);
117
118struct cgit_repolist {
119 int length;
120 int count;
121 struct cgit_repo *repos;
122};
123
124struct commitinfo {
125 struct commit *commit;
126 char *author;
127 char *author_email;
128 unsigned long author_date;
129 int author_tz;
130 char *committer;
131 char *committer_email;
132 unsigned long committer_date;
133 int committer_tz;
134 char *subject;
135 char *msg;
136 char *msg_encoding;
137};
138
139struct taginfo {
140 char *tagger;
141 char *tagger_email;
142 unsigned long tagger_date;
143 int tagger_tz;
144 char *msg;
145};
146
147struct refinfo {
148 const char *refname;
149 struct object *object;
150 union {
151 struct taginfo *tag;
152 struct commitinfo *commit;
153 };
154};
155
156struct reflist {
157 struct refinfo **refs;
158 int alloc;
159 int count;
160};
161
162struct cgit_query {
163 int has_symref;
164 int has_sha1;
165 int has_difftype;
166 char *raw;
167 char *repo;
168 char *page;
169 char *search;
170 char *grep;
171 char *head;
172 char *sha1;
173 char *sha2;
174 char *path;
175 char *name;
176 char *url;
177 char *period;
178 int ofs;
179 int nohead;
180 char *sort;
181 int showmsg;
182 diff_type difftype;
183 int show_all;
184 int context;
185 int ignorews;
186 int follow;
187 char *vpath;
188};
189
190struct cgit_config {
191 char *agefile;
192 char *cache_root;
193 char *clone_prefix;
194 char *clone_url;
195 char *css;
196 char *favicon;
197 char *footer;
198 char *head_include;
199 char *header;
200 char *index_header;
201 char *index_info;
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 nocache;
252 int noplainemail;
253 int noheader;
254 int renamelimit;
255 int remove_suffix;
256 int scan_hidden_path;
257 int section_from_path;
258 int snapshots;
259 int section_sort;
260 int summary_branches;
261 int summary_log;
262 int summary_tags;
263 diff_type difftype;
264 int branch_sort;
265 int commit_sort;
266 struct string_list mimetypes;
267 struct cgit_filter *about_filter;
268 struct cgit_filter *commit_filter;
269 struct cgit_filter *source_filter;
270 struct cgit_filter *email_filter;
271 struct cgit_filter *owner_filter;
272 struct cgit_filter *auth_filter;
273};
274
275struct cgit_page {
276 time_t modified;
277 time_t expires;
278 size_t size;
279 const char *mimetype;
280 const char *charset;
281 const char *filename;
282 const char *etag;
283 const char *title;
284 int status;
285 const char *statusmsg;
286};
287
288struct cgit_environment {
289 const char *cgit_config;
290 const char *http_host;
291 const char *https;
292 const char *no_http;
293 const char *path_info;
294 const char *query_string;
295 const char *request_method;
296 const char *script_name;
297 const char *server_name;
298 const char *server_port;
299 const char *http_cookie;
300 const char *http_referer;
301 unsigned int content_length;
302 int authenticated;
303};
304
305struct cgit_context {
306 struct cgit_environment env;
307 struct cgit_query qry;
308 struct cgit_config cfg;
309 struct cgit_repo *repo;
310 struct cgit_page page;
311};
312
313typedef int (*write_archive_fn_t)(const char *, const char *);
314
315struct cgit_snapshot_format {
316 const char *suffix;
317 const char *mimetype;
318 write_archive_fn_t write_func;
319};
320
321extern const char *cgit_version;
322
323extern struct cgit_repolist cgit_repolist;
324extern struct cgit_context ctx;
325extern const struct cgit_snapshot_format cgit_snapshot_formats[];
326
327extern char *cgit_default_repo_desc;
328extern struct cgit_repo *cgit_add_repo(const char *url);
329extern struct cgit_repo *cgit_get_repoinfo(const char *url);
330extern void cgit_repo_config_cb(const char *name, const char *value);
331
332extern int chk_zero(int result, char *msg);
333extern int chk_positive(int result, char *msg);
334extern int chk_non_negative(int result, char *msg);
335
336extern char *trim_end(const char *str, char c);
337extern char *ensure_end(const char *str, char c);
338
339extern void strbuf_ensure_end(struct strbuf *sb, char c);
340
341extern void cgit_add_ref(struct reflist *list, struct refinfo *ref);
342extern void cgit_free_reflist_inner(struct reflist *list);
343extern int cgit_refs_cb(const char *refname, const struct object_id *oid,
344 int flags, void *cb_data);
345
346extern void cgit_free_commitinfo(struct commitinfo *info);
347extern void cgit_free_taginfo(struct taginfo *info);
348
349void cgit_diff_tree_cb(struct diff_queue_struct *q,
350 struct diff_options *options, void *data);
351
352extern int cgit_diff_files(const struct object_id *old_oid,
353 const struct object_id *new_oid,
354 unsigned long *old_size, unsigned long *new_size,
355 int *binary, int context, int ignorews,
356 linediff_fn fn);
357
358extern void cgit_diff_tree(const struct object_id *old_oid,
359 const struct object_id *new_oid,
360 filepair_fn fn, const char *prefix, int ignorews);
361
362extern void cgit_diff_commit(struct commit *commit, filepair_fn fn,
363 const char *prefix);
364
365__attribute__((format (printf,1,2)))
366extern char *fmt(const char *format,...);
367
368__attribute__((format (printf,1,2)))
369extern char *fmtalloc(const char *format,...);
370
371extern struct commitinfo *cgit_parse_commit(struct commit *commit);
372extern struct taginfo *cgit_parse_tag(struct tag *tag);
373extern void cgit_parse_url(const char *url);
374
375extern const char *cgit_repobasename(const char *reponame);
376
377extern int cgit_parse_snapshots_mask(const char *str);
378extern const struct object_id *cgit_snapshot_get_sig(const char *ref,
379 const struct cgit_snapshot_format *f);
380extern const unsigned cgit_snapshot_format_bit(const struct cgit_snapshot_format *f);
381
382extern int cgit_open_filter(struct cgit_filter *filter, ...);
383extern int cgit_close_filter(struct cgit_filter *filter);
384extern void cgit_fprintf_filter(struct cgit_filter *filter, FILE *f, const char *prefix);
385extern void cgit_exec_filter_init(struct cgit_exec_filter *filter, char *cmd, char **argv);
386extern struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype);
387extern void cgit_cleanup_filters(void);
388extern void cgit_init_filters(void);
389
390extern void cgit_prepare_repo_env(struct cgit_repo * repo);
391
392extern int readfile(const char *path, char **buf, size_t *size);
393
394extern char *expand_macros(const char *txt);
395
396extern char *get_mimetype_for_filename(const char *filename);
397
398#endif /* CGIT_H */