]> gitweb.ps.run Git - ps-cgit/blob - cgit.h
implement repo.logo and repo.logo-link
[ps-cgit] / cgit.h
1 #ifndef CGIT_H
2 #define CGIT_H
3
4
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>
18 #include <string-list.h>
19 #include <xdiff-interface.h>
20 #include <xdiff/xdiff.h>
21 #include <utf8.h>
22 #include <notes.h>
23
24
25 /*
26  * Dateformats used on misc. pages
27  */
28 #define FMT_LONGDATE "%Y-%m-%d %H:%M:%S (%Z)"
29 #define FMT_SHORTDATE "%Y-%m-%d"
30 #define FMT_ATOMDATE "%Y-%m-%dT%H:%M:%SZ"
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 typedef void (*configfn)(const char *name, const char *value);
50 typedef void (*filepair_fn)(struct diff_filepair *pair);
51 typedef void (*linediff_fn)(char *line, int len);
52
53 struct cgit_filter {
54         char *cmd;
55         char **argv;
56         int old_stdout;
57         int pipe_fh[2];
58         int pid;
59         int exitstatus;
60 };
61
62 struct cgit_repo {
63         char *url;
64         char *name;
65         char *path;
66         char *desc;
67         char *owner;
68         char *defbranch;
69         char *module_link;
70         char *readme;
71         char *section;
72         char *clone_url;
73         char *logo;
74         char *logo_link;
75         int snapshots;
76         int enable_log_filecount;
77         int enable_log_linecount;
78         int enable_remote_branches;
79         int enable_subject_links;
80         int max_stats;
81         time_t mtime;
82         struct cgit_filter *about_filter;
83         struct cgit_filter *commit_filter;
84         struct cgit_filter *source_filter;
85 };
86
87 typedef void (*repo_config_fn)(struct cgit_repo *repo, const char *name,
88               const char *value);
89
90 struct cgit_repolist {
91         int length;
92         int count;
93         struct cgit_repo *repos;
94 };
95
96 struct commitinfo {
97         struct commit *commit;
98         char *author;
99         char *author_email;
100         unsigned long author_date;
101         char *committer;
102         char *committer_email;
103         unsigned long committer_date;
104         char *subject;
105         char *msg;
106         char *msg_encoding;
107 };
108
109 struct taginfo {
110         char *tagger;
111         char *tagger_email;
112         unsigned long tagger_date;
113         char *msg;
114 };
115
116 struct refinfo {
117         const char *refname;
118         struct object *object;
119         union {
120                 struct taginfo *tag;
121                 struct commitinfo *commit;
122         };
123 };
124
125 struct reflist {
126         struct refinfo **refs;
127         int alloc;
128         int count;
129 };
130
131 struct cgit_query {
132         int has_symref;
133         int has_sha1;
134         char *raw;
135         char *repo;
136         char *page;
137         char *search;
138         char *grep;
139         char *head;
140         char *sha1;
141         char *sha2;
142         char *path;
143         char *name;
144         char *mimetype;
145         char *url;
146         char *period;
147         int   ofs;
148         int nohead;
149         char *sort;
150         int showmsg;
151         int ssdiff;
152         int show_all;
153         int context;
154         int ignorews;
155         char *vpath;
156 };
157
158 struct cgit_config {
159         char *agefile;
160         char *cache_root;
161         char *clone_prefix;
162         char *css;
163         char *favicon;
164         char *footer;
165         char *head_include;
166         char *header;
167         char *index_header;
168         char *index_info;
169         char *logo;
170         char *logo_link;
171         char *module_link;
172         char *project_list;
173         char *readme;
174         char *robots;
175         char *root_title;
176         char *root_desc;
177         char *root_readme;
178         char *script_name;
179         char *section;
180         char *virtual_root;
181         char *strict_export;
182         int cache_size;
183         int cache_dynamic_ttl;
184         int cache_max_create_time;
185         int cache_repo_ttl;
186         int cache_root_ttl;
187         int cache_scanrc_ttl;
188         int cache_static_ttl;
189         int embedded;
190         int enable_filter_overrides;
191         int enable_gitweb_owner;
192         int enable_index_links;
193         int enable_log_filecount;
194         int enable_log_linecount;
195         int enable_remote_branches;
196         int enable_subject_links;
197         int enable_tree_linenumbers;
198         int local_time;
199         int max_atom_items;
200         int max_repo_count;
201         int max_commit_count;
202         int max_lock_attempts;
203         int max_msg_len;
204         int max_repodesc_len;
205         int max_blob_size;
206         int max_stats;
207         int nocache;
208         int noplainemail;
209         int noheader;
210         int renamelimit;
211         int remove_suffix;
212         int section_from_path;
213         int snapshots;
214         int summary_branches;
215         int summary_log;
216         int summary_tags;
217         int ssdiff;
218         struct string_list mimetypes;
219         struct cgit_filter *about_filter;
220         struct cgit_filter *commit_filter;
221         struct cgit_filter *source_filter;
222 };
223
224 struct cgit_page {
225         time_t modified;
226         time_t expires;
227         size_t size;
228         char *mimetype;
229         char *charset;
230         char *filename;
231         char *etag;
232         char *title;
233         int status;
234         char *statusmsg;
235 };
236
237 struct cgit_environment {
238         char *cgit_config;
239         char *http_host;
240         char *https;
241         char *no_http;
242         char *path_info;
243         char *query_string;
244         char *request_method;
245         char *script_name;
246         char *server_name;
247         char *server_port;
248 };
249
250 struct cgit_context {
251         struct cgit_environment env;
252         struct cgit_query qry;
253         struct cgit_config cfg;
254         struct cgit_repo *repo;
255         struct cgit_page page;
256 };
257
258 struct cgit_snapshot_format {
259         const char *suffix;
260         const char *mimetype;
261         write_archive_fn_t write_func;
262         int bit;
263 };
264
265 extern const char *cgit_version;
266
267 extern struct cgit_repolist cgit_repolist;
268 extern struct cgit_context ctx;
269 extern const struct cgit_snapshot_format cgit_snapshot_formats[];
270
271 extern struct cgit_repo *cgit_add_repo(const char *url);
272 extern struct cgit_repo *cgit_get_repoinfo(const char *url);
273 extern void cgit_repo_config_cb(const char *name, const char *value);
274
275 extern int chk_zero(int result, char *msg);
276 extern int chk_positive(int result, char *msg);
277 extern int chk_non_negative(int result, char *msg);
278
279 extern char *trim_end(const char *str, char c);
280 extern char *strlpart(char *txt, int maxlen);
281 extern char *strrpart(char *txt, int maxlen);
282
283 extern void cgit_add_ref(struct reflist *list, struct refinfo *ref);
284 extern int cgit_refs_cb(const char *refname, const unsigned char *sha1,
285                         int flags, void *cb_data);
286
287 extern void *cgit_free_commitinfo(struct commitinfo *info);
288
289 extern int cgit_diff_files(const unsigned char *old_sha1,
290                            const unsigned char *new_sha1,
291                            unsigned long *old_size, unsigned long *new_size,
292                            int *binary, int context, int ignorews,
293                            linediff_fn fn);
294
295 extern void cgit_diff_tree(const unsigned char *old_sha1,
296                            const unsigned char *new_sha1,
297                            filepair_fn fn, const char *prefix, int ignorews);
298
299 extern void cgit_diff_commit(struct commit *commit, filepair_fn fn,
300                              const char *prefix);
301
302 __attribute__((format (printf,1,2)))
303 extern char *fmt(const char *format,...);
304
305 extern struct commitinfo *cgit_parse_commit(struct commit *commit);
306 extern struct taginfo *cgit_parse_tag(struct tag *tag);
307 extern void cgit_parse_url(const char *url);
308
309 extern const char *cgit_repobasename(const char *reponame);
310
311 extern int cgit_parse_snapshots_mask(const char *str);
312
313 extern int cgit_open_filter(struct cgit_filter *filter);
314 extern int cgit_close_filter(struct cgit_filter *filter);
315
316 extern int readfile(const char *path, char **buf, size_t *size);
317
318 extern char *expand_macros(const char *txt);
319
320 #endif /* CGIT_H */