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 pipe_fh[2];
75 int pid;
76};
77
78struct cgit_repo {
79 char *url;
80 char *name;
81 char *path;
82 char *desc;
83 char *owner;
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 int snapshots;
92 int enable_commit_graph;
93 int enable_log_filecount;
94 int enable_log_linecount;
95 int enable_remote_branches;
96 int enable_subject_links;
97 int enable_html_serving;
98 int max_stats;
99 int branch_sort;
100 int commit_sort;
101 time_t mtime;
102 struct cgit_filter *about_filter;
103 struct cgit_filter *commit_filter;
104 struct cgit_filter *source_filter;
105 struct cgit_filter *email_filter;
106 struct cgit_filter *owner_filter;
107 struct string_list submodules;
108 int hide;
109 int ignore;
110};
111
112typedef void (*repo_config_fn)(struct cgit_repo *repo, const char *name,
113 const char *value);
114
115struct cgit_repolist {
116 int length;
117 int count;
118 struct cgit_repo *repos;
119};
120
121struct commitinfo {
122 struct commit *commit;
123 char *author;
124 char *author_email;
125 unsigned long author_date;
126 int author_tz;
127 char *committer;
128 char *committer_email;
129 unsigned long committer_date;
130 int committer_tz;
131 char *subject;
132 char *msg;
133 char *msg_encoding;
134};
135
136struct taginfo {
137 char *tagger;
138 char *tagger_email;
139 unsigned long tagger_date;
140 int tagger_tz;
141 char *msg;
142};
143
144struct refinfo {
145 const char *refname;
146 struct object *object;
147 union {
148 struct taginfo *tag;
149 struct commitinfo *commit;
150 };
151};
152
153struct reflist {
154 struct refinfo **refs;
155 int alloc;
156 int count;
157};
158
159struct cgit_query {
160 int has_symref;
161 int has_sha1;
162 int has_difftype;
163 char *raw;
164 char *repo;
165 char *page;
166 char *search;
167 char *grep;
168 char *head;
169 char *sha1;
170 char *sha2;
171 char *path;
172 char *name;
173 char *url;
174 char *period;
175 int ofs;
176 int nohead;
177 char *sort;
178 int showmsg;
179 diff_type difftype;
180 int show_all;
181 int context;
182 int ignorews;
183 int follow;
184 char *vpath;
185};
186
187struct cgit_config {
188 char *agefile;
189 char *cache_root;
190 char *clone_prefix;
191 char *clone_url;
192 char *css;
193 char *favicon;
194 char *footer;
195 char *head_include;
196 char *header;
197 char *index_header;
198 char *index_info;
199 char *logo;
200 char *logo_link;
201 char *mimetype_file;
202 char *module_link;
203 char *project_list;
204 struct string_list readme;
205 char *robots;
206 char *root_title;
207 char *root_desc;
208 char *root_readme;
209 char *script_name;
210 char *section;
211 char *repository_sort;
212 char *virtual_root; /* Always ends with '/'. */
213 char *strict_export;
214 int cache_size;
215 int cache_dynamic_ttl;
216 int cache_max_create_time;
217 int cache_repo_ttl;
218 int cache_root_ttl;
219 int cache_scanrc_ttl;
220 int cache_static_ttl;
221 int cache_about_ttl;
222 int cache_snapshot_ttl;
223 int case_sensitive_sort;
224 int embedded;
225 int enable_filter_overrides;
226 int enable_follow_links;
227 int enable_http_clone;
228 int enable_index_links;
229 int enable_index_owner;
230 int enable_commit_graph;
231 int enable_log_filecount;
232 int enable_log_linecount;
233 int enable_remote_branches;
234 int enable_subject_links;
235 int enable_html_serving;
236 int enable_tree_linenumbers;
237 int enable_git_config;
238 int local_time;
239 int max_atom_items;
240 int max_repo_count;
241 int max_commit_count;
242 int max_lock_attempts;
243 int max_msg_len;
244 int max_repodesc_len;
245 int max_blob_size;
246 int max_stats;
247 int nocache;
248 int noplainemail;
249 int noheader;
250 int renamelimit;
251 int remove_suffix;
252 int scan_hidden_path;
253 int section_from_path;
254 int snapshots;
255 int section_sort;
256 int summary_branches;
257 int summary_log;
258 int summary_tags;
259 diff_type difftype;
260 int branch_sort;
261 int commit_sort;
262 struct string_list mimetypes;
263 struct cgit_filter *about_filter;
264 struct cgit_filter *commit_filter;
265 struct cgit_filter *source_filter;
266 struct cgit_filter *email_filter;
267 struct cgit_filter *owner_filter;
268 struct cgit_filter *auth_filter;
269};
270
271struct cgit_page {
272 time_t modified;
273 time_t expires;
274 size_t size;
275 const char *mimetype;
276 const char *charset;
277 const char *filename;
278 const char *etag;
279 const char *title;
280 int status;
281 const char *statusmsg;
282};
283
284struct cgit_environment {
285 const char *cgit_config;
286 const char *http_host;
287 const char *https;
288 const char *no_http;
289 const char *path_info;
290 const char *query_string;
291 const char *request_method;
292 const char *script_name;
293 const char *server_name;
294 const char *server_port;
295 const char *http_cookie;
296 const char *http_referer;
297 unsigned int content_length;
298 int authenticated;
299};
300
301struct cgit_context {
302 struct cgit_environment env;
303 struct cgit_query qry;
304 struct cgit_config cfg;
305 struct cgit_repo *repo;
306 struct cgit_page page;
307};
308
309typedef int (*write_archive_fn_t)(const char *, const char *);
310
311struct cgit_snapshot_format {
312 const char *suffix;
313 const char *mimetype;
314 write_archive_fn_t write_func;
315 int bit;
316};
317
318extern const char *cgit_version;
319
320extern struct cgit_repolist cgit_repolist;
321extern struct cgit_context ctx;
322extern const struct cgit_snapshot_format cgit_snapshot_formats[];
323
324extern char *cgit_default_repo_desc;
325extern struct cgit_repo *cgit_add_repo(const char *url);
326extern struct cgit_repo *cgit_get_repoinfo(const char *url);
327extern void cgit_repo_config_cb(const char *name, const char *value);
328
329extern int chk_zero(int result, char *msg);
330extern int chk_positive(int result, char *msg);
331extern int chk_non_negative(int result, char *msg);
332
333extern char *trim_end(const char *str, char c);
334extern char *ensure_end(const char *str, char c);
335extern char *strlpart(char *txt, int maxlen);
336extern char *strrpart(char *txt, int maxlen);
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);
346
347void cgit_diff_tree_cb(struct diff_queue_struct *q,
348 struct diff_options *options, void *data);
349
350extern int cgit_diff_files(const unsigned char *old_sha1,
351 const unsigned char *new_sha1,
352 unsigned long *old_size, unsigned long *new_size,
353 int *binary, int context, int ignorews,
354 linediff_fn fn);
355
356extern void cgit_diff_tree(const unsigned char *old_sha1,
357 const unsigned char *new_sha1,
358 filepair_fn fn, const char *prefix, int ignorews);
359
360extern void cgit_diff_commit(struct commit *commit, filepair_fn fn,
361 const char *prefix);
362
363__attribute__((format (printf,1,2)))
364extern char *fmt(const char *format,...);
365
366__attribute__((format (printf,1,2)))
367extern char *fmtalloc(const char *format,...);
368
369extern struct commitinfo *cgit_parse_commit(struct commit *commit);
370extern struct taginfo *cgit_parse_tag(struct tag *tag);
371extern void cgit_parse_url(const char *url);
372
373extern const char *cgit_repobasename(const char *reponame);
374
375extern int cgit_parse_snapshots_mask(const char *str);
376
377extern int cgit_open_filter(struct cgit_filter *filter, ...);
378extern int cgit_close_filter(struct cgit_filter *filter);
379extern void cgit_fprintf_filter(struct cgit_filter *filter, FILE *f, const char *prefix);
380extern void cgit_exec_filter_init(struct cgit_exec_filter *filter, char *cmd, char **argv);
381extern struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype);
382extern void cgit_cleanup_filters(void);
383extern void cgit_init_filters(void);
384
385extern void cgit_prepare_repo_env(struct cgit_repo * repo);
386
387extern int readfile(const char *path, char **buf, size_t *size);
388
389extern char *expand_macros(const char *txt);
390
391extern char *get_mimetype_for_filename(const char *filename);
392
393#endif /* CGIT_H */