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
29/*
30 * Dateformats used on misc. pages
31 */
32#define FMT_LONGDATE "%Y-%m-%d %H:%M:%S (%Z)"
33#define FMT_SHORTDATE "%Y-%m-%d"
34#define FMT_ATOMDATE "%Y-%m-%dT%H:%M:%SZ"
35
36
37/*
38 * Limits used for relative dates
39 */
40#define TM_MIN 60
41#define TM_HOUR (TM_MIN * 60)
42#define TM_DAY (TM_HOUR * 24)
43#define TM_WEEK (TM_DAY * 7)
44#define TM_YEAR (TM_DAY * 365)
45#define TM_MONTH (TM_YEAR / 12.0)
46
47
48/*
49 * Default encoding
50 */
51#define PAGE_ENCODING "UTF-8"
52
53typedef void (*configfn)(const char *name, const char *value);
54typedef void (*filepair_fn)(struct diff_filepair *pair);
55typedef void (*linediff_fn)(char *line, int len);
56
57typedef enum {
58 DIFF_UNIFIED, DIFF_SSDIFF, DIFF_STATONLY
59} diff_type;
60
61typedef enum {
62 ABOUT, COMMIT, SOURCE, EMAIL, AUTH, OWNER
63} filter_type;
64
65struct cgit_filter {
66 int (*open)(struct cgit_filter *, va_list ap);
67 int (*close)(struct cgit_filter *);
68 void (*fprintf)(struct cgit_filter *, FILE *, const char *prefix);
69 void (*cleanup)(struct cgit_filter *);
70 int argument_count;
71};
72
73struct cgit_exec_filter {
74 struct cgit_filter base;
75 char *cmd;
76 char **argv;
77 int old_stdout;
78 int pipe_fh[2];
79 int pid;
80};
81
82struct cgit_repo {
83 char *url;
84 char *name;
85 char *path;
86 char *desc;
87 char *owner;
88 char *defbranch;
89 char *module_link;
90 struct string_list readme;
91 char *section;
92 char *clone_url;
93 char *logo;
94 char *logo_link;
95 int snapshots;
96 int enable_commit_graph;
97 int enable_log_filecount;
98 int enable_log_linecount;
99 int enable_remote_branches;
100 int enable_subject_links;
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 char *committer;
130 char *committer_email;
131 unsigned long committer_date;
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 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 *mimetype;
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_commit_graph;
232 int enable_log_filecount;
233 int enable_log_linecount;
234 int enable_remote_branches;
235 int enable_subject_links;
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
391#endif /* CGIT_H */