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