]> git.cameronkatri.com Git - cgit.git/blob - cgit.h
extra-head-content: introduce another option for meta tags
[cgit.git] / cgit.h
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
51 typedef void (*configfn)(const char *name, const char *value);
52 typedef void (*filepair_fn)(struct diff_filepair *pair);
53 typedef void (*linediff_fn)(char *line, int len);
54
55 typedef enum {
56 DIFF_UNIFIED, DIFF_SSDIFF, DIFF_STATONLY
57 } diff_type;
58
59 typedef enum {
60 ABOUT, COMMIT, SOURCE, EMAIL, AUTH, OWNER
61 } filter_type;
62
63 struct 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
71 struct cgit_exec_filter {
72 struct cgit_filter base;
73 char *cmd;
74 char **argv;
75 int old_stdout;
76 int pid;
77 };
78
79 struct cgit_repo {
80 char *url;
81 char *name;
82 char *path;
83 char *desc;
84 char *extra_head_content;
85 char *owner;
86 char *homepage;
87 char *defbranch;
88 char *module_link;
89 struct string_list readme;
90 char *section;
91 char *clone_url;
92 char *logo;
93 char *logo_link;
94 char *snapshot_prefix;
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 enable_html_serving;
102 int max_stats;
103 int branch_sort;
104 int commit_sort;
105 time_t mtime;
106 struct cgit_filter *about_filter;
107 struct cgit_filter *commit_filter;
108 struct cgit_filter *source_filter;
109 struct cgit_filter *email_filter;
110 struct cgit_filter *owner_filter;
111 struct string_list submodules;
112 int hide;
113 int ignore;
114 };
115
116 typedef void (*repo_config_fn)(struct cgit_repo *repo, const char *name,
117 const char *value);
118
119 struct cgit_repolist {
120 int length;
121 int count;
122 struct cgit_repo *repos;
123 };
124
125 struct commitinfo {
126 struct commit *commit;
127 char *author;
128 char *author_email;
129 unsigned long author_date;
130 int author_tz;
131 char *committer;
132 char *committer_email;
133 unsigned long committer_date;
134 int committer_tz;
135 char *subject;
136 char *msg;
137 char *msg_encoding;
138 };
139
140 struct taginfo {
141 char *tagger;
142 char *tagger_email;
143 unsigned long tagger_date;
144 int tagger_tz;
145 char *msg;
146 };
147
148 struct refinfo {
149 const char *refname;
150 struct object *object;
151 union {
152 struct taginfo *tag;
153 struct commitinfo *commit;
154 };
155 };
156
157 struct reflist {
158 struct refinfo **refs;
159 int alloc;
160 int count;
161 };
162
163 struct cgit_query {
164 int has_symref;
165 int has_sha1;
166 int has_difftype;
167 char *raw;
168 char *repo;
169 char *page;
170 char *search;
171 char *grep;
172 char *head;
173 char *sha1;
174 char *sha2;
175 char *path;
176 char *name;
177 char *url;
178 char *period;
179 int ofs;
180 int nohead;
181 char *sort;
182 int showmsg;
183 diff_type difftype;
184 int show_all;
185 int context;
186 int ignorews;
187 int follow;
188 char *vpath;
189 };
190
191 struct cgit_config {
192 char *agefile;
193 char *cache_root;
194 char *clone_prefix;
195 char *clone_url;
196 char *css;
197 char *favicon;
198 char *footer;
199 char *head_include;
200 char *header;
201 char *logo;
202 char *logo_link;
203 char *mimetype_file;
204 char *module_link;
205 char *project_list;
206 struct string_list readme;
207 char *robots;
208 char *root_title;
209 char *root_desc;
210 char *root_readme;
211 char *script_name;
212 char *section;
213 char *repository_sort;
214 char *virtual_root; /* Always ends with '/'. */
215 char *strict_export;
216 int cache_size;
217 int cache_dynamic_ttl;
218 int cache_max_create_time;
219 int cache_repo_ttl;
220 int cache_root_ttl;
221 int cache_scanrc_ttl;
222 int cache_static_ttl;
223 int cache_about_ttl;
224 int cache_snapshot_ttl;
225 int case_sensitive_sort;
226 int embedded;
227 int enable_filter_overrides;
228 int enable_follow_links;
229 int enable_http_clone;
230 int enable_index_links;
231 int enable_index_owner;
232 int enable_blame;
233 int enable_commit_graph;
234 int enable_log_filecount;
235 int enable_log_linecount;
236 int enable_remote_branches;
237 int enable_subject_links;
238 int enable_html_serving;
239 int enable_tree_linenumbers;
240 int enable_git_config;
241 int local_time;
242 int max_atom_items;
243 int max_repo_count;
244 int max_commit_count;
245 int max_lock_attempts;
246 int max_msg_len;
247 int max_repodesc_len;
248 int max_blob_size;
249 int max_stats;
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
273 struct 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
286 struct 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
303 struct 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
311 typedef int (*write_archive_fn_t)(const char *, const char *);
312
313 struct cgit_snapshot_format {
314 const char *suffix;
315 const char *mimetype;
316 write_archive_fn_t write_func;
317 };
318
319 extern const char *cgit_version;
320
321 extern struct cgit_repolist cgit_repolist;
322 extern struct cgit_context ctx;
323 extern const struct cgit_snapshot_format cgit_snapshot_formats[];
324
325 extern char *cgit_default_repo_desc;
326 extern struct cgit_repo *cgit_add_repo(const char *url);
327 extern struct cgit_repo *cgit_get_repoinfo(const char *url);
328 extern void cgit_repo_config_cb(const char *name, const char *value);
329
330 extern int chk_zero(int result, char *msg);
331 extern int chk_positive(int result, char *msg);
332 extern int chk_non_negative(int result, char *msg);
333
334 extern char *trim_end(const char *str, char c);
335 extern char *ensure_end(const char *str, char c);
336
337 extern void strbuf_ensure_end(struct strbuf *sb, char c);
338
339 extern void cgit_add_ref(struct reflist *list, struct refinfo *ref);
340 extern void cgit_free_reflist_inner(struct reflist *list);
341 extern int cgit_refs_cb(const char *refname, const struct object_id *oid,
342 int flags, void *cb_data);
343
344 extern void cgit_free_commitinfo(struct commitinfo *info);
345 extern void cgit_free_taginfo(struct taginfo *info);
346
347 void cgit_diff_tree_cb(struct diff_queue_struct *q,
348 struct diff_options *options, void *data);
349
350 extern int cgit_diff_files(const struct object_id *old_oid,
351 const struct object_id *new_oid,
352 unsigned long *old_size, unsigned long *new_size,
353 int *binary, int context, int ignorews,
354 linediff_fn fn);
355
356 extern void cgit_diff_tree(const struct object_id *old_oid,
357 const struct object_id *new_oid,
358 filepair_fn fn, const char *prefix, int ignorews);
359
360 extern void cgit_diff_commit(struct commit *commit, filepair_fn fn,
361 const char *prefix);
362
363 __attribute__((format (printf,1,2)))
364 extern char *fmt(const char *format,...);
365
366 __attribute__((format (printf,1,2)))
367 extern char *fmtalloc(const char *format,...);
368
369 extern struct commitinfo *cgit_parse_commit(struct commit *commit);
370 extern struct taginfo *cgit_parse_tag(struct tag *tag);
371 extern void cgit_parse_url(const char *url);
372
373 extern const char *cgit_repobasename(const char *reponame);
374
375 extern int cgit_parse_snapshots_mask(const char *str);
376 extern const struct object_id *cgit_snapshot_get_sig(const char *ref,
377 const struct cgit_snapshot_format *f);
378 extern const unsigned cgit_snapshot_format_bit(const struct cgit_snapshot_format *f);
379
380 extern int cgit_open_filter(struct cgit_filter *filter, ...);
381 extern int cgit_close_filter(struct cgit_filter *filter);
382 extern void cgit_fprintf_filter(struct cgit_filter *filter, FILE *f, const char *prefix);
383 extern void cgit_exec_filter_init(struct cgit_exec_filter *filter, char *cmd, char **argv);
384 extern struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype);
385 extern void cgit_cleanup_filters(void);
386 extern void cgit_init_filters(void);
387
388 extern void cgit_prepare_repo_env(struct cgit_repo * repo);
389
390 extern int readfile(const char *path, char **buf, size_t *size);
391
392 extern char *expand_macros(const char *txt);
393
394 extern char *get_mimetype_for_filename(const char *filename);
395
396 #endif /* CGIT_H */