blob: fc7c7d59358ea89a5d3b3afe6a8309d7c045eab5 [file] [log] [blame]
Lars Hjemli0d169ad2006-12-09 15:18:17 +01001#ifndef CGIT_H
2#define CGIT_H
3
Lars Hjemli61c3ca92007-05-08 22:40:59 +02004
5#include <git-compat-util.h>
6#include <cache.h>
7#include <grep.h>
8#include <object.h>
9#include <tree.h>
10#include <commit.h>
11#include <tag.h>
12#include <diff.h>
13#include <diffcore.h>
14#include <refs.h>
15#include <revision.h>
16#include <log-tree.h>
17#include <archive.h>
Lars Hjemlic4d46c72009-02-13 20:43:30 +010018#include <string-list.h>
Lars Hjemlic495cf02009-01-31 10:40:40 +010019#include <xdiff-interface.h>
Lars Hjemli61c3ca92007-05-08 22:40:59 +020020#include <xdiff/xdiff.h>
Lars Hjemlia2ebbd62007-11-05 22:27:43 +010021#include <utf8.h>
Lars Hjemli61c3ca92007-05-08 22:40:59 +020022
Lars Hjemli25105d72006-12-10 22:31:36 +010023
Lars Hjemli43d40f22007-05-18 00:50:46 +020024/*
Lars Hjemli5db39172007-05-22 23:08:46 +020025 * Dateformats used on misc. pages
26 */
Stefan Naewe0f0ab142008-08-01 14:54:38 +020027#define FMT_LONGDATE "%Y-%m-%d %H:%M:%S (%Z)"
Lars Hjemli5db39172007-05-22 23:08:46 +020028#define FMT_SHORTDATE "%Y-%m-%d"
Lars Hjemlib2a3d312008-05-21 08:17:54 +020029#define FMT_ATOMDATE "%Y-%m-%dT%H:%M:%SZ"
Lars Hjemli5db39172007-05-22 23:08:46 +020030
31
32/*
33 * Limits used for relative dates
34 */
35#define TM_MIN 60
36#define TM_HOUR (TM_MIN * 60)
37#define TM_DAY (TM_HOUR * 24)
38#define TM_WEEK (TM_DAY * 7)
39#define TM_YEAR (TM_DAY * 365)
40#define TM_MONTH (TM_YEAR / 12.0)
41
42
Jonathan Bastien-Filiatrault3845e172007-10-26 18:09:06 -040043/*
44 * Default encoding
45 */
46#define PAGE_ENCODING "UTF-8"
47
Lars Hjemli25105d72006-12-10 22:31:36 +010048typedef void (*configfn)(const char *name, const char *value);
Lars Hjemli1b49de32007-05-13 11:24:23 +020049typedef void (*filepair_fn)(struct diff_filepair *pair);
Lars Hjemlic4ef6672007-05-13 14:21:19 +020050typedef void (*linediff_fn)(char *line, int len);
Lars Hjemli25105d72006-12-10 22:31:36 +010051
Lars Hjemlie976df22009-08-09 13:22:00 +020052struct cgit_filter {
53 char *cmd;
54 char **argv;
55 int old_stdout;
56 int pipe_fh[2];
57 int pid;
58 int exitstatus;
59};
60
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +010061struct cgit_repo {
Lars Hjemlice1c7332007-02-03 15:02:55 +010062 char *url;
63 char *name;
64 char *path;
65 char *desc;
66 char *owner;
Lars Hjemlib28b1052007-05-16 00:14:51 +020067 char *defbranch;
Lars Hjemlided93932007-05-11 12:12:48 +020068 char *module_link;
Lars Hjemlibbcdc292007-05-23 22:46:54 +020069 char *readme;
Lars Hjemlie7af0022009-08-23 22:58:39 +020070 char *section;
Lars Hjemliafcdd082007-12-03 01:49:38 +010071 char *clone_url;
Lars Hjemliac70cb42007-02-08 14:47:56 +010072 int snapshots;
Lars Hjemlie1893442007-05-18 13:55:52 +020073 int enable_log_filecount;
74 int enable_log_linecount;
Lars Hjemlifb2f3f62008-12-07 13:17:21 +010075 int max_stats;
Lars Hjemli88131702008-11-29 16:46:37 +010076 time_t mtime;
Lars Hjemli537c05f2009-08-09 13:27:21 +020077 struct cgit_filter *about_filter;
Lars Hjemlie976df22009-08-09 13:22:00 +020078 struct cgit_filter *commit_filter;
79 struct cgit_filter *source_filter;
Lars Hjemlice1c7332007-02-03 15:02:55 +010080};
81
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +010082struct cgit_repolist {
Lars Hjemlice1c7332007-02-03 15:02:55 +010083 int length;
84 int count;
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +010085 struct cgit_repo *repos;
Lars Hjemlice1c7332007-02-03 15:02:55 +010086};
87
Lars Hjemli2101e262006-12-15 18:17:36 +010088struct commitinfo {
89 struct commit *commit;
90 char *author;
Lars Hjemli77078ba2006-12-16 14:25:41 +010091 char *author_email;
92 unsigned long author_date;
Lars Hjemli2101e262006-12-15 18:17:36 +010093 char *committer;
Lars Hjemli77078ba2006-12-16 14:25:41 +010094 char *committer_email;
95 unsigned long committer_date;
Lars Hjemli2101e262006-12-15 18:17:36 +010096 char *subject;
97 char *msg;
Jonathan Bastien-Filiatrault3845e172007-10-26 18:09:06 -040098 char *msg_encoding;
Lars Hjemli2101e262006-12-15 18:17:36 +010099};
100
Lars Hjemlia69061f2007-01-17 01:09:51 +0100101struct taginfo {
102 char *tagger;
103 char *tagger_email;
Lars Hjemlia8305a92008-09-14 09:45:37 +0200104 unsigned long tagger_date;
Lars Hjemlia69061f2007-01-17 01:09:51 +0100105 char *msg;
106};
107
Lars Hjemlie397ff72007-10-25 09:30:06 +0200108struct refinfo {
109 const char *refname;
110 struct object *object;
111 union {
112 struct taginfo *tag;
113 struct commitinfo *commit;
114 };
115};
116
117struct reflist {
118 struct refinfo **refs;
119 int alloc;
120 int count;
121};
122
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100123struct cgit_query {
124 int has_symref;
125 int has_sha1;
126 char *raw;
127 char *repo;
128 char *page;
129 char *search;
130 char *grep;
131 char *head;
132 char *sha1;
133 char *sha2;
134 char *path;
135 char *name;
Michael Krelin42effc92008-06-24 23:42:32 +0200136 char *mimetype;
Lars Hjemlie154edd2008-08-09 21:11:41 +0200137 char *url;
Lars Hjemlif86a23f2008-12-06 17:38:19 +0100138 char *period;
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100139 int ofs;
Lars Hjemli5632ba32008-10-11 19:05:50 +0200140 int nohead;
Benjamin Closed71c0c72008-11-25 06:25:35 -0800141 char *sort;
Lars Hjemli0274b572008-11-29 18:39:41 +0100142 int showmsg;
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100143};
144
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100145struct cgit_config {
146 char *agefile;
147 char *cache_root;
148 char *clone_prefix;
149 char *css;
Lars Hjemli502865a2008-07-19 20:40:30 +0200150 char *favicon;
Lars Hjemlide5e9282008-06-26 13:53:30 +0200151 char *footer;
Mark Lodatob5a3a202009-03-15 00:11:54 -0400152 char *head_include;
Lars Hjemlib1159552009-01-29 21:27:39 +0100153 char *header;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100154 char *index_header;
155 char *index_info;
156 char *logo;
157 char *logo_link;
158 char *module_link;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100159 char *robots;
160 char *root_title;
Lars Hjemli4c991602008-04-29 00:55:34 +0200161 char *root_desc;
Lars Hjemlic6431a72008-04-29 01:06:30 +0200162 char *root_readme;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100163 char *script_name;
Lars Hjemlie7af0022009-08-23 22:58:39 +0200164 char *section;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100165 char *virtual_root;
Lars Hjemli939d32f2008-04-28 11:32:42 +0200166 int cache_size;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100167 int cache_dynamic_ttl;
168 int cache_max_create_time;
169 int cache_repo_ttl;
170 int cache_root_ttl;
Lars Hjemlid7468272009-08-20 17:41:54 +0200171 int cache_scanrc_ttl;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100172 int cache_static_ttl;
Lars Hjemli7a8b3b42009-07-25 12:25:06 +0200173 int embedded;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100174 int enable_index_links;
175 int enable_log_filecount;
176 int enable_log_linecount;
Stefan Naewe0f0ab142008-08-01 14:54:38 +0200177 int local_time;
Lars Hjemlic6078b82008-05-03 10:54:39 +0200178 int max_repo_count;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100179 int max_commit_count;
180 int max_lock_attempts;
181 int max_msg_len;
182 int max_repodesc_len;
Lars Hjemlifb2f3f62008-12-07 13:17:21 +0100183 int max_stats;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100184 int nocache;
Martin Szulecki2f56e392009-08-07 14:05:17 +0200185 int noplainemail;
Lars Hjemli7a8b3b42009-07-25 12:25:06 +0200186 int noheader;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100187 int renamelimit;
188 int snapshots;
189 int summary_branches;
190 int summary_log;
191 int summary_tags;
Lars Hjemlic4d46c72009-02-13 20:43:30 +0100192 struct string_list mimetypes;
Lars Hjemli537c05f2009-08-09 13:27:21 +0200193 struct cgit_filter *about_filter;
Lars Hjemlif35db1c2009-07-31 17:42:57 +0200194 struct cgit_filter *commit_filter;
Lars Hjemli46b7abe2009-07-31 16:55:27 +0200195 struct cgit_filter *source_filter;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100196};
197
Lars Hjemlif3c1a182008-03-24 00:51:19 +0100198struct cgit_page {
199 time_t modified;
200 time_t expires;
Lars Hjemlie5da4bc2008-08-06 10:53:50 +0200201 size_t size;
Lars Hjemlif3c1a182008-03-24 00:51:19 +0100202 char *mimetype;
203 char *charset;
204 char *filename;
Lars Hjemli488a2142009-02-19 22:38:36 +0100205 char *etag;
Lars Hjemlif3c1a182008-03-24 00:51:19 +0100206 char *title;
Lars Hjemlie429fb02009-06-07 20:43:08 +0200207 int status;
208 char *statusmsg;
Lars Hjemlif3c1a182008-03-24 00:51:19 +0100209};
210
Lars Hjemli60a26272009-08-10 08:21:09 +0200211struct cgit_environment {
212 char *cgit_config;
213 char *http_host;
214 char *https;
Lars Hjemli8b2252b2009-08-10 09:20:17 +0200215 char *no_http;
Lars Hjemli60a26272009-08-10 08:21:09 +0200216 char *path_info;
217 char *query_string;
218 char *request_method;
219 char *script_name;
220 char *server_name;
221 char *server_port;
222};
223
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100224struct cgit_context {
Lars Hjemli60a26272009-08-10 08:21:09 +0200225 struct cgit_environment env;
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100226 struct cgit_query qry;
Lars Hjemlib228d4f2008-02-16 13:07:13 +0100227 struct cgit_config cfg;
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +0100228 struct cgit_repo *repo;
Lars Hjemlif3c1a182008-03-24 00:51:19 +0100229 struct cgit_page page;
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100230};
231
Lars Hjemlif34478c2008-03-24 16:00:27 +0100232struct cgit_snapshot_format {
233 const char *suffix;
234 const char *mimetype;
235 write_archive_fn_t write_func;
236 int bit;
237};
238
Lars Hjemlif6925032007-06-18 09:42:10 +0200239extern const char *cgit_version;
Lars Hjemli5a106eb2006-12-11 16:38:30 +0100240
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +0100241extern struct cgit_repolist cgit_repolist;
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100242extern struct cgit_context ctx;
Lars Hjemlif34478c2008-03-24 16:00:27 +0100243extern const struct cgit_snapshot_format cgit_snapshot_formats[];
Lars Hjemlice1c7332007-02-03 15:02:55 +0100244
Lars Hjemli163037e2008-03-24 17:26:08 +0100245extern struct cgit_repo *cgit_add_repo(const char *url);
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +0100246extern struct cgit_repo *cgit_get_repoinfo(const char *url);
Lars Hjemli44923f82006-12-11 17:25:41 +0100247extern void cgit_repo_config_cb(const char *name, const char *value);
Lars Hjemli44923f82006-12-11 17:25:41 +0100248
Lars Hjemliab2ab952007-02-08 13:53:13 +0100249extern int chk_zero(int result, char *msg);
250extern int chk_positive(int result, char *msg);
Michael Krelin127f43d2007-07-20 20:56:43 +0200251extern int chk_non_negative(int result, char *msg);
Lars Hjemliab2ab952007-02-08 13:53:13 +0100252
Lars Hjemli382805e2007-06-26 18:04:31 +0200253extern char *trim_end(const char *str, char c);
Lars Hjemli0c8e1842007-10-30 10:47:38 +0100254extern char *strlpart(char *txt, int maxlen);
255extern char *strrpart(char *txt, int maxlen);
Lars Hjemli52e605c2007-01-04 16:53:03 +0100256
Lars Hjemlie397ff72007-10-25 09:30:06 +0200257extern void cgit_add_ref(struct reflist *list, struct refinfo *ref);
258extern int cgit_refs_cb(const char *refname, const unsigned char *sha1,
259 int flags, void *cb_data);
260
Lars Hjemliaaa24bd2006-12-16 14:58:20 +0100261extern void *cgit_free_commitinfo(struct commitinfo *info);
Lars Hjemlic4ef6672007-05-13 14:21:19 +0200262
263extern int cgit_diff_files(const unsigned char *old_sha1,
264 const unsigned char *new_sha1,
Lars Hjemlic495cf02009-01-31 10:40:40 +0100265 unsigned long *old_size, unsigned long *new_size,
266 int *binary, linediff_fn fn);
Lars Hjemlic4ef6672007-05-13 14:21:19 +0200267
Lars Hjemli1b49de32007-05-13 11:24:23 +0200268extern void cgit_diff_tree(const unsigned char *old_sha1,
269 const unsigned char *new_sha1,
Lars Hjemlif527a572007-10-01 11:42:19 +0200270 filepair_fn fn, const char *prefix);
Lars Hjemlic4ef6672007-05-13 14:21:19 +0200271
Lars Hjemli1b49de32007-05-13 11:24:23 +0200272extern void cgit_diff_commit(struct commit *commit, filepair_fn fn);
Lars Hjemliaaa24bd2006-12-16 14:58:20 +0100273
Lars Hjemli0d169ad2006-12-09 15:18:17 +0100274extern char *fmt(const char *format,...);
275
Lars Hjemli2101e262006-12-15 18:17:36 +0100276extern struct commitinfo *cgit_parse_commit(struct commit *commit);
Lars Hjemlia69061f2007-01-17 01:09:51 +0100277extern struct taginfo *cgit_parse_tag(struct tag *tag);
Lars Hjemli30ccdca2007-05-18 03:00:54 +0200278extern void cgit_parse_url(const char *url);
Lars Hjemli0d169ad2006-12-09 15:18:17 +0100279
Michael Krelin1cb8bed2007-07-21 15:24:07 +0200280extern const char *cgit_repobasename(const char *reponame);
281
Michael Krelindc3c9b52007-07-21 18:00:53 +0200282extern int cgit_parse_snapshots_mask(const char *str);
Lars Hjemli74620f12006-12-11 16:48:03 +0100283
Lars Hjemlid6f60722009-07-31 17:38:38 +0200284extern int cgit_open_filter(struct cgit_filter *filter);
285extern int cgit_close_filter(struct cgit_filter *filter);
286
Lars Hjemlie16f1782009-08-18 17:17:41 +0200287extern int readfile(const char *path, char **buf, size_t *size);
Lars Hjemli28d781f2008-04-13 12:42:27 +0200288
Lars Hjemli0d169ad2006-12-09 15:18:17 +0100289#endif /* CGIT_H */