]> gitweb.ps.run Git - ps-cgit/blob - cgit.h
Add ui-shared.h
[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 <xdiff/xdiff.h>
19 #include <utf8.h>
20
21
22 /*
23  * Dateformats used on misc. pages
24  */
25 #define FMT_LONGDATE "%Y-%m-%d %H:%M:%S"
26 #define FMT_SHORTDATE "%Y-%m-%d"
27
28
29 /*
30  * Limits used for relative dates
31  */
32 #define TM_MIN    60
33 #define TM_HOUR  (TM_MIN * 60)
34 #define TM_DAY   (TM_HOUR * 24)
35 #define TM_WEEK  (TM_DAY * 7)
36 #define TM_YEAR  (TM_DAY * 365)
37 #define TM_MONTH (TM_YEAR / 12.0)
38
39
40 /*
41  * Default encoding
42  */
43 #define PAGE_ENCODING "UTF-8"
44
45 typedef void (*configfn)(const char *name, const char *value);
46 typedef void (*filepair_fn)(struct diff_filepair *pair);
47 typedef void (*linediff_fn)(char *line, int len);
48
49 struct cacheitem {
50         char *name;
51         struct stat st;
52         int ttl;
53         int fd;
54 };
55
56 struct cgit_repo {
57         char *url;
58         char *name;
59         char *path;
60         char *desc;
61         char *owner;
62         char *defbranch;
63         char *group;
64         char *module_link;
65         char *readme;
66         char *clone_url;
67         int snapshots;
68         int enable_log_filecount;
69         int enable_log_linecount;
70 };
71
72 struct cgit_repolist {
73         int length;
74         int count;
75         struct cgit_repo *repos;
76 };
77
78 struct commitinfo {
79         struct commit *commit;
80         char *author;
81         char *author_email;
82         unsigned long author_date;
83         char *committer;
84         char *committer_email;
85         unsigned long committer_date;
86         char *subject;
87         char *msg;
88         char *msg_encoding;
89 };
90
91 struct taginfo {
92         char *tagger;
93         char *tagger_email;
94         int tagger_date;
95         char *msg;
96 };
97
98 struct refinfo {
99         const char *refname;
100         struct object *object;
101         union {
102                 struct taginfo *tag;
103                 struct commitinfo *commit;
104         };
105 };
106
107 struct reflist {
108         struct refinfo **refs;
109         int alloc;
110         int count;
111 };
112
113 struct cgit_query {
114         int has_symref;
115         int has_sha1;
116         char *raw;
117         char *repo;
118         char *page;
119         char *search;
120         char *grep;
121         char *head;
122         char *sha1;
123         char *sha2;
124         char *path;
125         char *name;
126         int   ofs;
127 };
128
129 struct cgit_config {
130         char *agefile;
131         char *cache_root;
132         char *clone_prefix;
133         char *css;
134         char *index_header;
135         char *index_info;
136         char *logo;
137         char *logo_link;
138         char *module_link;
139         char *repo_group;
140         char *robots;
141         char *root_title;
142         char *script_name;
143         char *virtual_root;
144         int cache_dynamic_ttl;
145         int cache_max_create_time;
146         int cache_repo_ttl;
147         int cache_root_ttl;
148         int cache_static_ttl;
149         int enable_index_links;
150         int enable_log_filecount;
151         int enable_log_linecount;
152         int max_commit_count;
153         int max_lock_attempts;
154         int max_msg_len;
155         int max_repodesc_len;
156         int nocache;
157         int renamelimit;
158         int snapshots;
159         int summary_branches;
160         int summary_log;
161         int summary_tags;
162 };
163
164 struct cgit_page {
165         time_t modified;
166         time_t expires;
167         char *mimetype;
168         char *charset;
169         char *filename;
170         char *title;
171 };
172
173 struct cgit_context {
174         struct cgit_query qry;
175         struct cgit_config cfg;
176         struct cgit_repo *repo;
177         struct cgit_page page;
178 };
179
180 struct cgit_snapshot_format {
181         const char *suffix;
182         const char *mimetype;
183         write_archive_fn_t write_func;
184         int bit;
185 };
186
187 extern const char *cgit_version;
188
189 extern struct cgit_repolist cgit_repolist;
190 extern struct cgit_context ctx;
191 extern const struct cgit_snapshot_format cgit_snapshot_formats[];
192 extern int cgit_cmd;
193
194 extern void cgit_prepare_context(struct cgit_context *ctx);
195 extern struct cgit_repo *cgit_get_repoinfo(const char *url);
196 extern void cgit_global_config_cb(const char *name, const char *value);
197 extern void cgit_repo_config_cb(const char *name, const char *value);
198 extern void cgit_querystring_cb(const char *name, const char *value);
199
200 extern int chk_zero(int result, char *msg);
201 extern int chk_positive(int result, char *msg);
202 extern int chk_non_negative(int result, char *msg);
203
204 extern int hextoint(char c);
205 extern char *trim_end(const char *str, char c);
206 extern char *strlpart(char *txt, int maxlen);
207 extern char *strrpart(char *txt, int maxlen);
208
209 extern void cgit_add_ref(struct reflist *list, struct refinfo *ref);
210 extern int cgit_refs_cb(const char *refname, const unsigned char *sha1,
211                         int flags, void *cb_data);
212
213 extern void *cgit_free_commitinfo(struct commitinfo *info);
214
215 extern int cgit_diff_files(const unsigned char *old_sha1,
216                            const unsigned char *new_sha1,
217                            linediff_fn fn);
218
219 extern void cgit_diff_tree(const unsigned char *old_sha1,
220                            const unsigned char *new_sha1,
221                            filepair_fn fn, const char *prefix);
222
223 extern void cgit_diff_commit(struct commit *commit, filepair_fn fn);
224
225 extern char *fmt(const char *format,...);
226
227 extern int cgit_read_config(const char *filename, configfn fn);
228 extern int cgit_parse_query(char *txt, configfn fn);
229 extern struct commitinfo *cgit_parse_commit(struct commit *commit);
230 extern struct taginfo *cgit_parse_tag(struct tag *tag);
231 extern void cgit_parse_url(const char *url);
232
233 extern char *cache_safe_filename(const char *unsafe);
234 extern int cache_lock(struct cacheitem *item);
235 extern int cache_unlock(struct cacheitem *item);
236 extern int cache_cancel_lock(struct cacheitem *item);
237 extern int cache_exist(struct cacheitem *item);
238 extern int cache_expired(struct cacheitem *item);
239
240 extern const char *cgit_repobasename(const char *reponame);
241
242 extern int cgit_parse_snapshots_mask(const char *str);
243
244 #endif /* CGIT_H */