2 9460dac0 2020-01-15 tracey * Copyright (c) 2019, 2020 Tracey Emery <tracey@traceyemery.net>
3 2c251c14 2020-01-15 tracey * Copyright (c) 2018, 2019 Stefan Sperling <stsp@openbsd.org>
5 2c251c14 2020-01-15 tracey * Permission to use, copy, modify, and distribute this software for any
6 2c251c14 2020-01-15 tracey * purpose with or without fee is hereby granted, provided that the above
7 2c251c14 2020-01-15 tracey * copyright notice and this permission notice appear in all copies.
9 2c251c14 2020-01-15 tracey * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 2c251c14 2020-01-15 tracey * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 2c251c14 2020-01-15 tracey * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 2c251c14 2020-01-15 tracey * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 2c251c14 2020-01-15 tracey * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 2c251c14 2020-01-15 tracey * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 2c251c14 2020-01-15 tracey * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 2c251c14 2020-01-15 tracey #include <sys/queue.h>
19 2c251c14 2020-01-15 tracey #include <sys/stat.h>
20 2c251c14 2020-01-15 tracey #include <sys/types.h>
22 017d6da3 2020-01-29 tracey #include <ctype.h>
23 2c251c14 2020-01-15 tracey #include <dirent.h>
24 2c251c14 2020-01-15 tracey #include <err.h>
25 c25c2314 2020-01-28 stsp #include <errno.h>
26 474370cb 2020-01-15 tracey #include <regex.h>
27 2c251c14 2020-01-15 tracey #include <stdarg.h>
28 2c251c14 2020-01-15 tracey #include <stdint.h>
29 2c251c14 2020-01-15 tracey #include <stdio.h>
30 2c251c14 2020-01-15 tracey #include <stdlib.h>
31 2c251c14 2020-01-15 tracey #include <string.h>
32 2c251c14 2020-01-15 tracey #include <unistd.h>
34 c34ec417 2020-06-22 tracey #include <got_error.h>
35 2c251c14 2020-01-15 tracey #include <got_object.h>
36 2c251c14 2020-01-15 tracey #include <got_reference.h>
37 2c251c14 2020-01-15 tracey #include <got_repository.h>
38 2c251c14 2020-01-15 tracey #include <got_path.h>
39 2c251c14 2020-01-15 tracey #include <got_cancel.h>
40 2c251c14 2020-01-15 tracey #include <got_worktree.h>
41 2c251c14 2020-01-15 tracey #include <got_diff.h>
42 2c251c14 2020-01-15 tracey #include <got_commit_graph.h>
43 2c251c14 2020-01-15 tracey #include <got_blame.h>
44 2c251c14 2020-01-15 tracey #include <got_privsep.h>
45 2c251c14 2020-01-15 tracey #include <got_opentemp.h>
47 2c251c14 2020-01-15 tracey #include <kcgi.h>
48 2c251c14 2020-01-15 tracey #include <kcgihtml.h>
50 2c251c14 2020-01-15 tracey #include "gotweb.h"
52 2c251c14 2020-01-15 tracey #ifndef nitems
53 2c251c14 2020-01-15 tracey #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
56 54415d85 2020-01-15 tracey struct gw_trans {
57 f2f46662 2020-01-23 tracey TAILQ_HEAD(headers, gw_header) gw_headers;
58 f2f46662 2020-01-23 tracey TAILQ_HEAD(dirs, gw_dir) gw_dirs;
59 deac617c 2020-02-14 tracey struct got_repository *repo;
60 46b9c89b 2020-01-15 tracey struct gw_dir *gw_dir;
61 c34ec417 2020-06-22 tracey struct gotweb_config *gw_conf;
62 2c251c14 2020-01-15 tracey struct ktemplate *gw_tmpl;
63 2c251c14 2020-01-15 tracey struct khtmlreq *gw_html_req;
64 2c251c14 2020-01-15 tracey struct kreq *gw_req;
65 f1200fe3 2020-02-13 tracey const struct got_error *error;
66 f652ec0c 2020-02-13 stsp const char *repo_name;
67 2c251c14 2020-01-15 tracey char *repo_path;
68 56997cd3 2020-02-14 tracey char *commit_id;
69 55e46400 2020-02-18 tracey char *next_id;
70 55e46400 2020-02-18 tracey char *prev_id;
71 4d6abe2b 2020-02-13 stsp const char *repo_file;
72 ec46ccd7 2020-01-15 tracey char *repo_folder;
73 742ba378 2020-02-14 stsp const char *headref;
74 2c251c14 2020-01-15 tracey unsigned int action;
75 2c251c14 2020-01-15 tracey unsigned int page;
76 2c251c14 2020-01-15 tracey unsigned int repos_total;
77 387a29ba 2020-01-15 tracey enum kmime mime;
80 f2f46662 2020-01-23 tracey struct gw_header {
81 f2f46662 2020-01-23 tracey TAILQ_ENTRY(gw_header) entry;
82 f2f46662 2020-01-23 tracey struct got_reflist_head refs;
83 f2f46662 2020-01-23 tracey char *path;
85 f2f46662 2020-01-23 tracey char *refs_str;
86 f2f46662 2020-01-23 tracey char *commit_id; /* id_str1 */
87 f2f46662 2020-01-23 tracey char *parent_id; /* id_str2 */
88 f2f46662 2020-01-23 tracey char *tree_id;
89 4e8d6e3e 2020-02-14 tracey char *author;
90 4e8d6e3e 2020-02-14 tracey char *committer;
91 f2f46662 2020-01-23 tracey char *commit_msg;
92 f2f46662 2020-01-23 tracey time_t committer_time;
95 2c251c14 2020-01-15 tracey struct gw_dir {
96 2c251c14 2020-01-15 tracey TAILQ_ENTRY(gw_dir) entry;
97 2c251c14 2020-01-15 tracey char *name;
98 2c251c14 2020-01-15 tracey char *owner;
99 2c251c14 2020-01-15 tracey char *description;
100 2c251c14 2020-01-15 tracey char *url;
101 2c251c14 2020-01-15 tracey char *age;
102 2c251c14 2020-01-15 tracey char *path;
105 f2f46662 2020-01-23 tracey enum gw_key {
106 f2f46662 2020-01-23 tracey KEY_ACTION,
107 f2f46662 2020-01-23 tracey KEY_COMMIT_ID,
108 f2f46662 2020-01-23 tracey KEY_FILE,
109 f2f46662 2020-01-23 tracey KEY_FOLDER,
110 f2f46662 2020-01-23 tracey KEY_HEADREF,
111 f2f46662 2020-01-23 tracey KEY_PAGE,
112 f2f46662 2020-01-23 tracey KEY_PATH,
113 55e46400 2020-02-18 tracey KEY_PREV_ID,
114 f2f46662 2020-01-23 tracey KEY__ZMAX
117 54415d85 2020-01-15 tracey enum gw_tmpl {
118 f2f46662 2020-01-23 tracey TEMPL_CONTENT,
119 2c251c14 2020-01-15 tracey TEMPL_HEAD,
120 2c251c14 2020-01-15 tracey TEMPL_HEADER,
121 f2f46662 2020-01-23 tracey TEMPL_SEARCH,
122 2c251c14 2020-01-15 tracey TEMPL_SITEPATH,
123 2c251c14 2020-01-15 tracey TEMPL_SITEOWNER,
124 2c251c14 2020-01-15 tracey TEMPL_TITLE,
125 2c251c14 2020-01-15 tracey TEMPL__MAX
128 54415d85 2020-01-15 tracey enum gw_ref_tm {
133 ff4bb25f 2020-02-19 tracey enum gw_tags_type {
134 87f9ebf5 2020-01-15 tracey TAGBRIEF,
138 54415d85 2020-01-15 tracey static const char *const gw_templs[TEMPL__MAX] = {
139 f2f46662 2020-01-23 tracey "content",
141 2c251c14 2020-01-15 tracey "header",
142 f2f46662 2020-01-23 tracey "search",
143 2c251c14 2020-01-15 tracey "sitepath",
144 2c251c14 2020-01-15 tracey "siteowner",
148 ec46ccd7 2020-01-15 tracey static const struct kvalid gw_keys[KEY__ZMAX] = {
149 2c251c14 2020-01-15 tracey { kvalid_stringne, "action" },
150 2c251c14 2020-01-15 tracey { kvalid_stringne, "commit" },
151 2c251c14 2020-01-15 tracey { kvalid_stringne, "file" },
152 ec46ccd7 2020-01-15 tracey { kvalid_stringne, "folder" },
153 8087c3c5 2020-01-15 tracey { kvalid_stringne, "headref" },
154 ec46ccd7 2020-01-15 tracey { kvalid_int, "page" },
155 ec46ccd7 2020-01-15 tracey { kvalid_stringne, "path" },
156 55e46400 2020-02-18 tracey { kvalid_stringne, "prev" },
159 f2f46662 2020-01-23 tracey static struct gw_header *gw_init_header(void);
161 b0a1bc86 2020-02-14 stsp static void gw_free_header(struct gw_header *);
163 00f13350 2020-02-10 tracey static int gw_template(size_t, void *);
165 f1200fe3 2020-02-13 tracey static const struct got_error *gw_error(struct gw_trans *);
166 f1200fe3 2020-02-13 tracey static const struct got_error *gw_init_gw_dir(struct gw_dir **, const char *);
167 185ba3ba 2020-02-04 tracey static const struct got_error *gw_get_repo_description(char **,
168 185ba3ba 2020-02-04 tracey struct gw_trans *, char *);
169 9a1cc63f 2020-02-03 stsp static const struct got_error *gw_get_repo_owner(char **, struct gw_trans *,
171 55ccf528 2020-02-03 stsp static const struct got_error *gw_get_time_str(char **, time_t, int);
172 d126c1b7 2020-01-29 stsp static const struct got_error *gw_get_repo_age(char **, struct gw_trans *,
173 2011c142 2020-02-14 stsp char *, const char *, int);
174 84de9106 2020-12-26 stsp static const struct got_error *gw_output_file_blame(struct gw_trans *,
175 84de9106 2020-12-26 stsp struct gw_header *);
176 84de9106 2020-12-26 stsp static const struct got_error *gw_output_blob_buf(struct gw_trans *,
177 84de9106 2020-12-26 stsp struct gw_header *);
178 84de9106 2020-12-26 stsp static const struct got_error *gw_output_repo_tree(struct gw_trans *,
179 84de9106 2020-12-26 stsp struct gw_header *);
180 38b240fb 2020-02-06 tracey static const struct got_error *gw_output_diff(struct gw_trans *,
181 f2f46662 2020-01-23 tracey struct gw_header *);
182 38b240fb 2020-02-06 tracey static const struct got_error *gw_output_repo_tags(struct gw_trans *,
183 4ff7391f 2020-01-28 tracey struct gw_header *, int, int);
184 9eed6f10 2020-02-08 tracey static const struct got_error *gw_output_repo_heads(struct gw_trans *);
185 4ae179a2 2020-02-08 tracey static const struct got_error *gw_output_site_link(struct gw_trans *);
186 185ba3ba 2020-02-04 tracey static const struct got_error *gw_get_clone_url(char **, struct gw_trans *,
188 f7cc9480 2020-02-05 tracey static const struct got_error *gw_colordiff_line(struct gw_trans *, char *);
190 21a55cc7 2020-02-04 tracey static const struct got_error *gw_gen_commit_header(struct gw_trans *, char *,
192 f7cc9480 2020-02-05 tracey static const struct got_error *gw_gen_diff_header(struct gw_trans *, char *,
194 21a55cc7 2020-02-04 tracey static const struct got_error *gw_gen_author_header(struct gw_trans *,
195 21a55cc7 2020-02-04 tracey const char *);
196 21a55cc7 2020-02-04 tracey static const struct got_error *gw_gen_age_header(struct gw_trans *,
197 21a55cc7 2020-02-04 tracey const char *);
198 21a55cc7 2020-02-04 tracey static const struct got_error *gw_gen_committer_header(struct gw_trans *,
199 21a55cc7 2020-02-04 tracey const char *);
200 f7cc9480 2020-02-05 tracey static const struct got_error *gw_gen_commit_msg_header(struct gw_trans*,
202 f7cc9480 2020-02-05 tracey static const struct got_error *gw_gen_tree_header(struct gw_trans *, char *);
203 00f13350 2020-02-10 tracey static const struct got_error *gw_display_open(struct gw_trans *, enum khttp,
204 2c251c14 2020-01-15 tracey enum kmime);
205 00f13350 2020-02-10 tracey static const struct got_error *gw_display_index(struct gw_trans *);
206 00f13350 2020-02-10 tracey static const struct got_error *gw_get_header(struct gw_trans *,
207 f2f46662 2020-01-23 tracey struct gw_header *, int);
208 00f13350 2020-02-10 tracey static const struct got_error *gw_get_commits(struct gw_trans *,
209 3c245a0e 2020-02-14 tracey struct gw_header *, int,
210 3c245a0e 2020-02-14 tracey struct got_object_id *);
211 00f13350 2020-02-10 tracey static const struct got_error *gw_get_commit(struct gw_trans *,
212 4e8d6e3e 2020-02-14 tracey struct gw_header *,
213 4e8d6e3e 2020-02-14 tracey struct got_commit_object *,
214 3c245a0e 2020-02-14 tracey struct got_object_id *);
215 d4159696 2020-02-13 stsp static const struct got_error *gw_apply_unveil(const char *);
216 00f13350 2020-02-10 tracey static const struct got_error *gw_blame_cb(void *, int, int,
217 ec46ccd7 2020-01-15 tracey struct got_object_id *);
218 00f13350 2020-02-10 tracey static const struct got_error *gw_load_got_paths(struct gw_trans *);
219 00f13350 2020-02-10 tracey static const struct got_error *gw_load_got_path(struct gw_trans *,
220 2c251c14 2020-01-15 tracey struct gw_dir *);
221 00f13350 2020-02-10 tracey static const struct got_error *gw_parse_querystring(struct gw_trans *);
222 00f13350 2020-02-10 tracey static const struct got_error *gw_blame(struct gw_trans *);
223 00f13350 2020-02-10 tracey static const struct got_error *gw_blob(struct gw_trans *);
224 00f13350 2020-02-10 tracey static const struct got_error *gw_diff(struct gw_trans *);
225 00f13350 2020-02-10 tracey static const struct got_error *gw_index(struct gw_trans *);
226 00f13350 2020-02-10 tracey static const struct got_error *gw_commits(struct gw_trans *);
227 00f13350 2020-02-10 tracey static const struct got_error *gw_briefs(struct gw_trans *);
228 00f13350 2020-02-10 tracey static const struct got_error *gw_summary(struct gw_trans *);
229 00f13350 2020-02-10 tracey static const struct got_error *gw_tree(struct gw_trans *);
230 00f13350 2020-02-10 tracey static const struct got_error *gw_tag(struct gw_trans *);
231 ff4bb25f 2020-02-19 tracey static const struct got_error *gw_tags(struct gw_trans *);
233 2c251c14 2020-01-15 tracey struct gw_query_action {
234 2c251c14 2020-01-15 tracey unsigned int func_id;
235 2c251c14 2020-01-15 tracey const char *func_name;
236 54415d85 2020-01-15 tracey const struct got_error *(*func_main)(struct gw_trans *);
237 2c251c14 2020-01-15 tracey char *template;
240 2c251c14 2020-01-15 tracey enum gw_query_actions {
241 2c251c14 2020-01-15 tracey GW_BLAME,
243 f2f46662 2020-01-23 tracey GW_BRIEFS,
244 f2f46662 2020-01-23 tracey GW_COMMITS,
247 2c251c14 2020-01-15 tracey GW_INDEX,
248 2c251c14 2020-01-15 tracey GW_SUMMARY,
254 2c251c14 2020-01-15 tracey static struct gw_query_action gw_query_funcs[] = {
255 f2f46662 2020-01-23 tracey { GW_BLAME, "blame", gw_blame, "gw_tmpl/blame.tmpl" },
256 017d6da3 2020-01-29 tracey { GW_BLOB, "blob", NULL, NULL },
257 f2f46662 2020-01-23 tracey { GW_BRIEFS, "briefs", gw_briefs, "gw_tmpl/briefs.tmpl" },
258 f2f46662 2020-01-23 tracey { GW_COMMITS, "commits", gw_commits, "gw_tmpl/commit.tmpl" },
259 f2f46662 2020-01-23 tracey { GW_DIFF, "diff", gw_diff, "gw_tmpl/diff.tmpl" },
260 f1200fe3 2020-02-13 tracey { GW_ERR, "error", gw_error, "gw_tmpl/err.tmpl" },
261 f2f46662 2020-01-23 tracey { GW_INDEX, "index", gw_index, "gw_tmpl/index.tmpl" },
262 f2f46662 2020-01-23 tracey { GW_SUMMARY, "summary", gw_summary, "gw_tmpl/summry.tmpl" },
263 4ff7391f 2020-01-28 tracey { GW_TAG, "tag", gw_tag, "gw_tmpl/tag.tmpl" },
264 ff4bb25f 2020-02-19 tracey { GW_TAGS, "tags", gw_tags, "gw_tmpl/tags.tmpl" },
265 f2f46662 2020-01-23 tracey { GW_TREE, "tree", gw_tree, "gw_tmpl/tree.tmpl" },
268 5d1296de 2020-02-13 stsp static const char *
269 5d1296de 2020-02-13 stsp gw_get_action_name(struct gw_trans *gw_trans)
271 5d1296de 2020-02-13 stsp return gw_query_funcs[gw_trans->action].func_name;
274 c25c2314 2020-01-28 stsp static const struct got_error *
275 c25c2314 2020-01-28 stsp gw_kcgi_error(enum kcgi_err kerr)
277 c25c2314 2020-01-28 stsp if (kerr == KCGI_OK)
278 c25c2314 2020-01-28 stsp return NULL;
280 c25c2314 2020-01-28 stsp if (kerr == KCGI_EXIT || kerr == KCGI_HUP)
281 c25c2314 2020-01-28 stsp return got_error(GOT_ERR_CANCELLED);
283 c25c2314 2020-01-28 stsp if (kerr == KCGI_ENOMEM)
284 f7cc9480 2020-02-05 tracey return got_error_set_errno(ENOMEM,
285 7afec891 2020-02-06 stsp kcgi_strerror(kerr));
287 c25c2314 2020-01-28 stsp if (kerr == KCGI_ENFILE)
288 f7cc9480 2020-02-05 tracey return got_error_set_errno(ENFILE,
289 7afec891 2020-02-06 stsp kcgi_strerror(kerr));
291 c25c2314 2020-01-28 stsp if (kerr == KCGI_EAGAIN)
292 f7cc9480 2020-02-05 tracey return got_error_set_errno(EAGAIN,
293 7afec891 2020-02-06 stsp kcgi_strerror(kerr));
295 c25c2314 2020-01-28 stsp if (kerr == KCGI_FORM)
296 f7cc9480 2020-02-05 tracey return got_error_msg(GOT_ERR_IO,
297 7afec891 2020-02-06 stsp kcgi_strerror(kerr));
299 7afec891 2020-02-06 stsp return got_error_from_errno(kcgi_strerror(kerr));
302 2c251c14 2020-01-15 tracey static const struct got_error *
303 d4159696 2020-02-13 stsp gw_apply_unveil(const char *repo_path)
305 2c251c14 2020-01-15 tracey const struct got_error *err;
307 245c7240 2021-06-17 stsp #ifdef PROFILE
308 245c7240 2021-06-17 stsp if (unveil("gmon.out", "rwc") != 0)
309 245c7240 2021-06-17 stsp return got_error_from_errno2("unveil", "gmon.out");
311 2c251c14 2020-01-15 tracey if (repo_path && unveil(repo_path, "r") != 0)
312 2c251c14 2020-01-15 tracey return got_error_from_errno2("unveil", repo_path);
314 bb63914a 2020-02-17 stsp if (unveil(GOT_TMPDIR_STR, "rwc") != 0)
315 bb63914a 2020-02-17 stsp return got_error_from_errno2("unveil", GOT_TMPDIR_STR);
317 2c251c14 2020-01-15 tracey err = got_privsep_unveil_exec_helpers();
318 2c251c14 2020-01-15 tracey if (err != NULL)
319 2c251c14 2020-01-15 tracey return err;
321 2c251c14 2020-01-15 tracey if (unveil(NULL, NULL) != 0)
322 2c251c14 2020-01-15 tracey return got_error_from_errno("unveil");
324 32cd4d18 2020-02-03 stsp return NULL;
328 e0857cfe 2020-02-06 tracey isbinary(const uint8_t *buf, size_t n)
330 e0857cfe 2020-02-06 tracey size_t i;
332 e0857cfe 2020-02-06 tracey for (i = 0; i < n; i++)
333 e0857cfe 2020-02-06 tracey if (buf[i] == 0)
334 e0857cfe 2020-02-06 tracey return 1;
335 e0857cfe 2020-02-06 tracey return 0;
338 32cd4d18 2020-02-03 stsp static const struct got_error *
339 54415d85 2020-01-15 tracey gw_blame(struct gw_trans *gw_trans)
341 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
342 f2f46662 2020-01-23 tracey struct gw_header *header = NULL;
343 78a9dab5 2020-02-07 tracey char *age = NULL;
344 1b33afc0 2020-02-14 tracey enum kcgi_err kerr = KCGI_OK;
346 7a6dddae 2021-06-18 stsp #ifndef PROFILE
347 6bee13de 2020-01-16 tracey if (pledge("stdio rpath wpath cpath proc exec sendfd unveil",
348 f2f46662 2020-01-23 tracey NULL) == -1)
349 f2f46662 2020-01-23 tracey return got_error_from_errno("pledge");
351 f2f46662 2020-01-23 tracey if ((header = gw_init_header()) == NULL)
352 f2f46662 2020-01-23 tracey return got_error_from_errno("malloc");
354 d4159696 2020-02-13 stsp error = gw_apply_unveil(gw_trans->gw_dir->path);
355 ec46ccd7 2020-01-15 tracey if (error)
358 1b33afc0 2020-02-14 tracey /* check querystring */
359 1b33afc0 2020-02-14 tracey if (gw_trans->repo_file == NULL) {
360 1b33afc0 2020-02-14 tracey error = got_error_msg(GOT_ERR_QUERYSTRING,
361 1b33afc0 2020-02-14 tracey "file required in querystring");
362 1b33afc0 2020-02-14 tracey goto done;
364 1b33afc0 2020-02-14 tracey if (gw_trans->commit_id == NULL) {
365 1b33afc0 2020-02-14 tracey error = got_error_msg(GOT_ERR_QUERYSTRING,
366 1b33afc0 2020-02-14 tracey "commit required in querystring");
367 1b33afc0 2020-02-14 tracey goto done;
370 f2f46662 2020-01-23 tracey error = gw_get_header(gw_trans, header, 1);
371 f2f46662 2020-01-23 tracey if (error)
373 9a9d12ca 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
374 9a9d12ca 2020-02-06 tracey "blame_header_wrapper", KATTR__MAX);
375 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
376 9a9d12ca 2020-02-06 tracey goto done;
377 9a9d12ca 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
378 9a9d12ca 2020-02-06 tracey "blame_header", KATTR__MAX);
379 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
380 9a9d12ca 2020-02-06 tracey goto done;
381 9a9d12ca 2020-02-06 tracey error = gw_get_time_str(&age, header->committer_time,
382 9a9d12ca 2020-02-06 tracey TM_LONG);
385 9a9d12ca 2020-02-06 tracey error = gw_gen_age_header(gw_trans, age ?age : "");
388 9a9d12ca 2020-02-06 tracey error = gw_gen_commit_msg_header(gw_trans, header->commit_msg);
389 9a9d12ca 2020-02-06 tracey if (error)
391 9a9d12ca 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
392 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
394 9a9d12ca 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
395 9a9d12ca 2020-02-06 tracey "dotted_line", KATTR__MAX);
396 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
397 9a9d12ca 2020-02-06 tracey goto done;
398 9a9d12ca 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
399 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
400 9a9d12ca 2020-02-06 tracey goto done;
402 9a9d12ca 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
403 9a9d12ca 2020-02-06 tracey "blame", KATTR__MAX);
404 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
405 9a9d12ca 2020-02-06 tracey goto done;
406 84de9106 2020-12-26 stsp error = gw_output_file_blame(gw_trans, header);
407 9a9d12ca 2020-02-06 tracey if (error)
408 9a9d12ca 2020-02-06 tracey goto done;
409 9a9d12ca 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
411 b0a1bc86 2020-02-14 stsp gw_free_header(header);
412 9a9d12ca 2020-02-06 tracey if (error == NULL && kerr != KCGI_OK)
413 9a9d12ca 2020-02-06 tracey error = gw_kcgi_error(kerr);
414 2c251c14 2020-01-15 tracey return error;
417 2c251c14 2020-01-15 tracey static const struct got_error *
418 e46f587c 2020-01-29 tracey gw_blob(struct gw_trans *gw_trans)
420 3b7fdcf4 2020-02-14 tracey const struct got_error *error = NULL, *err = NULL;
421 e46f587c 2020-01-29 tracey struct gw_header *header = NULL;
422 3b7fdcf4 2020-02-14 tracey enum kcgi_err kerr = KCGI_OK;
424 7a6dddae 2021-06-18 stsp #ifndef PROFILE
425 e46f587c 2020-01-29 tracey if (pledge("stdio rpath wpath cpath proc exec sendfd unveil",
426 e46f587c 2020-01-29 tracey NULL) == -1)
427 e46f587c 2020-01-29 tracey return got_error_from_errno("pledge");
429 e46f587c 2020-01-29 tracey if ((header = gw_init_header()) == NULL)
430 e46f587c 2020-01-29 tracey return got_error_from_errno("malloc");
432 d4159696 2020-02-13 stsp error = gw_apply_unveil(gw_trans->gw_dir->path);
433 e46f587c 2020-01-29 tracey if (error)
434 e46f587c 2020-01-29 tracey goto done;
436 3b7fdcf4 2020-02-14 tracey /* check querystring */
437 3b7fdcf4 2020-02-14 tracey if (gw_trans->repo_file == NULL) {
438 3b7fdcf4 2020-02-14 tracey error = got_error_msg(GOT_ERR_QUERYSTRING,
439 3b7fdcf4 2020-02-14 tracey "file required in querystring");
440 3b7fdcf4 2020-02-14 tracey goto done;
442 3b7fdcf4 2020-02-14 tracey if (gw_trans->commit_id == NULL) {
443 3b7fdcf4 2020-02-14 tracey error = got_error_msg(GOT_ERR_QUERYSTRING,
444 3b7fdcf4 2020-02-14 tracey "commit required in querystring");
445 3b7fdcf4 2020-02-14 tracey goto done;
447 e46f587c 2020-01-29 tracey error = gw_get_header(gw_trans, header, 1);
448 e46f587c 2020-01-29 tracey if (error)
449 e46f587c 2020-01-29 tracey goto done;
451 84de9106 2020-12-26 stsp error = gw_output_blob_buf(gw_trans, header);
454 3b7fdcf4 2020-02-14 tracey if (error) {
455 3b7fdcf4 2020-02-14 tracey gw_trans->mime = KMIME_TEXT_PLAIN;
456 3b7fdcf4 2020-02-14 tracey err = gw_display_index(gw_trans);
457 3b7fdcf4 2020-02-14 tracey if (err) {
458 3b7fdcf4 2020-02-14 tracey error = err;
459 3b7fdcf4 2020-02-14 tracey goto errored;
461 3b7fdcf4 2020-02-14 tracey kerr = khttp_puts(gw_trans->gw_req, error->msg);
464 b0a1bc86 2020-02-14 stsp gw_free_header(header);
465 3b7fdcf4 2020-02-14 tracey if (error == NULL && kerr != KCGI_OK)
466 3b7fdcf4 2020-02-14 tracey error = gw_kcgi_error(kerr);
467 e46f587c 2020-01-29 tracey return error;
470 e46f587c 2020-01-29 tracey static const struct got_error *
471 f2f46662 2020-01-23 tracey gw_diff(struct gw_trans *gw_trans)
473 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
474 f2f46662 2020-01-23 tracey struct gw_header *header = NULL;
475 78a9dab5 2020-02-07 tracey char *age = NULL;
476 f7cc9480 2020-02-05 tracey enum kcgi_err kerr = KCGI_OK;
478 7a6dddae 2021-06-18 stsp #ifndef PROFILE
479 f2f46662 2020-01-23 tracey if (pledge("stdio rpath wpath cpath proc exec sendfd unveil",
480 f2f46662 2020-01-23 tracey NULL) == -1)
481 f2f46662 2020-01-23 tracey return got_error_from_errno("pledge");
483 ae36ed87 2020-01-28 stsp if ((header = gw_init_header()) == NULL)
484 f2f46662 2020-01-23 tracey return got_error_from_errno("malloc");
486 d4159696 2020-02-13 stsp error = gw_apply_unveil(gw_trans->gw_dir->path);
487 8087c3c5 2020-01-15 tracey if (error)
490 f2f46662 2020-01-23 tracey error = gw_get_header(gw_trans, header, 1);
491 f2f46662 2020-01-23 tracey if (error)
494 f7cc9480 2020-02-05 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
495 f7cc9480 2020-02-05 tracey "diff_header_wrapper", KATTR__MAX);
496 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
497 f7cc9480 2020-02-05 tracey goto done;
498 f7cc9480 2020-02-05 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
499 f7cc9480 2020-02-05 tracey "diff_header", KATTR__MAX);
500 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
501 f7cc9480 2020-02-05 tracey goto done;
502 f7cc9480 2020-02-05 tracey error = gw_gen_diff_header(gw_trans, header->parent_id,
503 f7cc9480 2020-02-05 tracey header->commit_id);
504 f7cc9480 2020-02-05 tracey if (error)
505 f7cc9480 2020-02-05 tracey goto done;
506 f7cc9480 2020-02-05 tracey error = gw_gen_commit_header(gw_trans, header->commit_id,
507 f7cc9480 2020-02-05 tracey header->refs_str);
508 f7cc9480 2020-02-05 tracey if (error)
509 f7cc9480 2020-02-05 tracey goto done;
510 f7cc9480 2020-02-05 tracey error = gw_gen_tree_header(gw_trans, header->tree_id);
511 f7cc9480 2020-02-05 tracey if (error)
512 f7cc9480 2020-02-05 tracey goto done;
513 f7cc9480 2020-02-05 tracey error = gw_gen_author_header(gw_trans, header->author);
514 f7cc9480 2020-02-05 tracey if (error)
515 f7cc9480 2020-02-05 tracey goto done;
516 f7cc9480 2020-02-05 tracey error = gw_gen_committer_header(gw_trans, header->author);
517 f7cc9480 2020-02-05 tracey if (error)
518 f7cc9480 2020-02-05 tracey goto done;
519 f7cc9480 2020-02-05 tracey error = gw_get_time_str(&age, header->committer_time,
520 f7cc9480 2020-02-05 tracey TM_LONG);
521 f7cc9480 2020-02-05 tracey if (error)
522 f7cc9480 2020-02-05 tracey goto done;
523 f7cc9480 2020-02-05 tracey error = gw_gen_age_header(gw_trans, age ?age : "");
526 f7cc9480 2020-02-05 tracey error = gw_gen_commit_msg_header(gw_trans, header->commit_msg);
527 f7cc9480 2020-02-05 tracey if (error)
529 f7cc9480 2020-02-05 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
530 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
532 f7cc9480 2020-02-05 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
533 f7cc9480 2020-02-05 tracey "dotted_line", KATTR__MAX);
534 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
535 f7cc9480 2020-02-05 tracey goto done;
536 f7cc9480 2020-02-05 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
537 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
538 f7cc9480 2020-02-05 tracey goto done;
540 f7cc9480 2020-02-05 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
541 f7cc9480 2020-02-05 tracey "diff", KATTR__MAX);
542 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
543 f7cc9480 2020-02-05 tracey goto done;
544 38b240fb 2020-02-06 tracey error = gw_output_diff(gw_trans, header);
545 f7cc9480 2020-02-05 tracey if (error)
546 f7cc9480 2020-02-05 tracey goto done;
548 b4fba448 2020-02-05 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
550 b0a1bc86 2020-02-14 stsp gw_free_header(header);
552 f7cc9480 2020-02-05 tracey if (error == NULL && kerr != KCGI_OK)
553 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
554 2204c934 2020-01-15 tracey return error;
557 2204c934 2020-01-15 tracey static const struct got_error *
558 54415d85 2020-01-15 tracey gw_index(struct gw_trans *gw_trans)
560 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
561 46b9c89b 2020-01-15 tracey struct gw_dir *gw_dir = NULL;
562 b3f1f953 2020-02-09 tracey char *href_next = NULL, *href_prev = NULL, *href_summary = NULL;
563 b3f1f953 2020-02-09 tracey char *href_briefs = NULL, *href_commits = NULL, *href_tree = NULL;
564 ff4bb25f 2020-02-19 tracey char *href_tags = NULL;
565 387a29ba 2020-01-15 tracey unsigned int prev_disp = 0, next_disp = 1, dir_c = 0;
566 795c10a4 2020-02-20 tracey enum kcgi_err kerr = KCGI_OK;
568 7a6dddae 2021-06-18 stsp #ifndef PROFILE
569 6bee13de 2020-01-16 tracey if (pledge("stdio rpath proc exec sendfd unveil",
570 6bee13de 2020-01-16 tracey NULL) == -1) {
571 6bee13de 2020-01-16 tracey error = got_error_from_errno("pledge");
572 6bee13de 2020-01-16 tracey return error;
575 d4159696 2020-02-13 stsp error = gw_apply_unveil(gw_trans->gw_conf->got_repos_path);
576 46b9c89b 2020-01-15 tracey if (error)
577 46b9c89b 2020-01-15 tracey return error;
579 2c251c14 2020-01-15 tracey error = gw_load_got_paths(gw_trans);
580 46b9c89b 2020-01-15 tracey if (error)
581 2c251c14 2020-01-15 tracey return error;
583 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
584 b3f1f953 2020-02-09 tracey "index_header", KATTR__MAX);
585 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
586 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
587 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
588 b3f1f953 2020-02-09 tracey "index_header_project", KATTR__MAX);
589 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
590 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
591 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Project");
592 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
593 2447adad 2020-02-06 stsp return gw_kcgi_error(kerr);
594 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
595 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
596 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
598 b3f1f953 2020-02-09 tracey if (gw_trans->gw_conf->got_show_repo_description) {
599 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
600 b3f1f953 2020-02-09 tracey "index_header_description", KATTR__MAX);
601 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
602 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
603 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Description");
604 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
605 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
606 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
607 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
608 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
611 b3f1f953 2020-02-09 tracey if (gw_trans->gw_conf->got_show_repo_owner) {
612 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
613 b3f1f953 2020-02-09 tracey "index_header_owner", KATTR__MAX);
614 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
615 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
616 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Owner");
617 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
618 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
619 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
620 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
621 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
624 b3f1f953 2020-02-09 tracey if (gw_trans->gw_conf->got_show_repo_age) {
625 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
626 b3f1f953 2020-02-09 tracey "index_header_age", KATTR__MAX);
627 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
628 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
629 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Last Change");
630 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
631 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
632 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
633 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
634 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
637 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
638 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
639 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
641 b3f1f953 2020-02-09 tracey if (TAILQ_EMPTY(&gw_trans->gw_dirs)) {
642 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
643 b3f1f953 2020-02-09 tracey "index_wrapper", KATTR__MAX);
644 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
645 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
646 32b9f7ed 2020-04-14 tracey kerr = khtml_printf(gw_trans->gw_html_req,
647 32b9f7ed 2020-04-14 tracey "No repositories found in %s",
648 b3f1f953 2020-02-09 tracey gw_trans->gw_conf->got_repos_path);
649 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
650 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
651 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
652 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
653 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
654 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
655 b3f1f953 2020-02-09 tracey "dotted_line", KATTR__MAX);
656 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
657 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
658 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
659 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
660 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
661 c25c2314 2020-01-28 stsp return error;
664 46b9c89b 2020-01-15 tracey TAILQ_FOREACH(gw_dir, &gw_trans->gw_dirs, entry)
667 46b9c89b 2020-01-15 tracey TAILQ_FOREACH(gw_dir, &gw_trans->gw_dirs, entry) {
668 2c251c14 2020-01-15 tracey if (gw_trans->page > 0 && (gw_trans->page *
669 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_max_repos_display) > prev_disp) {
670 2c251c14 2020-01-15 tracey prev_disp++;
671 2c251c14 2020-01-15 tracey continue;
674 2c251c14 2020-01-15 tracey prev_disp++;
676 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
677 b3f1f953 2020-02-09 tracey "index_wrapper", KATTR__MAX);
678 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
681 2796ac23 2020-04-14 tracey href_summary = khttp_urlpart(NULL, NULL, "gotweb", "path",
682 2796ac23 2020-04-14 tracey gw_dir->name, "action", "summary", NULL);
683 19ff7638 2020-04-14 tracey if (href_summary == NULL) {
684 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
685 19ff7638 2020-04-14 tracey goto done;
687 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
688 b3f1f953 2020-02-09 tracey "index_project", KATTR__MAX);
689 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
690 b3f1f953 2020-02-09 tracey goto done;
691 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A, KATTR_HREF,
692 b3f1f953 2020-02-09 tracey href_summary, KATTR__MAX);
693 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
694 b3f1f953 2020-02-09 tracey goto done;
695 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req, gw_dir->name);
696 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
697 b3f1f953 2020-02-09 tracey goto done;
698 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
699 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
700 b3f1f953 2020-02-09 tracey goto done;
701 b3f1f953 2020-02-09 tracey if (gw_trans->gw_conf->got_show_repo_description) {
702 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
703 b3f1f953 2020-02-09 tracey KATTR_ID, "index_project_description", KATTR__MAX);
704 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
705 b3f1f953 2020-02-09 tracey goto done;
706 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req,
707 b3f1f953 2020-02-09 tracey gw_dir->description ? gw_dir->description : "");
708 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
709 b3f1f953 2020-02-09 tracey goto done;
710 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
711 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
712 b3f1f953 2020-02-09 tracey goto done;
714 b3f1f953 2020-02-09 tracey if (gw_trans->gw_conf->got_show_repo_owner) {
715 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
716 b3f1f953 2020-02-09 tracey KATTR_ID, "index_project_owner", KATTR__MAX);
717 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
718 b3f1f953 2020-02-09 tracey goto done;
719 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req,
720 b3f1f953 2020-02-09 tracey gw_dir->owner ? gw_dir->owner : "");
721 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
722 b3f1f953 2020-02-09 tracey goto done;
723 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
724 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
725 b3f1f953 2020-02-09 tracey goto done;
727 b3f1f953 2020-02-09 tracey if (gw_trans->gw_conf->got_show_repo_age) {
728 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
729 b3f1f953 2020-02-09 tracey KATTR_ID, "index_project_age", KATTR__MAX);
730 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
731 b3f1f953 2020-02-09 tracey goto done;
732 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req,
733 b3f1f953 2020-02-09 tracey gw_dir->age ? gw_dir->age : "");
734 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
735 b3f1f953 2020-02-09 tracey goto done;
736 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
737 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
738 b3f1f953 2020-02-09 tracey goto done;
741 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
742 b3f1f953 2020-02-09 tracey "navs_wrapper", KATTR__MAX);
743 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
744 b3f1f953 2020-02-09 tracey goto done;
745 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
746 b3f1f953 2020-02-09 tracey "navs", KATTR__MAX);
747 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
748 b3f1f953 2020-02-09 tracey goto done;
750 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A, KATTR_HREF,
751 b3f1f953 2020-02-09 tracey href_summary, KATTR__MAX);
752 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
753 b3f1f953 2020-02-09 tracey goto done;
754 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req, "summary");
755 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
756 b3f1f953 2020-02-09 tracey goto done;
757 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
758 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
759 b3f1f953 2020-02-09 tracey goto done;
761 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req, " | ");
762 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
763 b3f1f953 2020-02-09 tracey goto done;
765 2796ac23 2020-04-14 tracey href_briefs = khttp_urlpart(NULL, NULL, "gotweb", "path",
766 2796ac23 2020-04-14 tracey gw_dir->name, "action", "briefs", NULL);
767 19ff7638 2020-04-14 tracey if (href_briefs == NULL) {
768 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
769 19ff7638 2020-04-14 tracey goto done;
771 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A, KATTR_HREF,
772 b3f1f953 2020-02-09 tracey href_briefs, KATTR__MAX);
773 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
774 b3f1f953 2020-02-09 tracey goto done;
775 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req, "commit briefs");
776 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
777 b3f1f953 2020-02-09 tracey goto done;
778 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
779 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
780 b3f1f953 2020-02-09 tracey error = gw_kcgi_error(kerr);
782 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req, " | ");
783 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
784 b3f1f953 2020-02-09 tracey goto done;
786 2796ac23 2020-04-14 tracey href_commits = khttp_urlpart(NULL, NULL, "gotweb", "path",
787 2796ac23 2020-04-14 tracey gw_dir->name, "action", "commits", NULL);
788 19ff7638 2020-04-14 tracey if (href_commits == NULL) {
789 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
790 19ff7638 2020-04-14 tracey goto done;
792 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A, KATTR_HREF,
793 b3f1f953 2020-02-09 tracey href_commits, KATTR__MAX);
794 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
795 b3f1f953 2020-02-09 tracey goto done;
796 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req, "commits");
797 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
798 b3f1f953 2020-02-09 tracey goto done;
799 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
800 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
801 b3f1f953 2020-02-09 tracey goto done;
803 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req, " | ");
804 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
805 b3f1f953 2020-02-09 tracey goto done;
807 2796ac23 2020-04-14 tracey href_tags = khttp_urlpart(NULL, NULL, "gotweb", "path",
808 2796ac23 2020-04-14 tracey gw_dir->name, "action", "tags", NULL);
809 19ff7638 2020-04-14 tracey if (href_tags == NULL) {
810 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
811 19ff7638 2020-04-14 tracey goto done;
813 ff4bb25f 2020-02-19 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A, KATTR_HREF,
814 ff4bb25f 2020-02-19 tracey href_tags, KATTR__MAX);
815 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
816 ff4bb25f 2020-02-19 tracey goto done;
817 ff4bb25f 2020-02-19 tracey kerr = khtml_puts(gw_trans->gw_html_req, "tags");
818 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
819 ff4bb25f 2020-02-19 tracey goto done;
820 ff4bb25f 2020-02-19 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
821 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
822 ff4bb25f 2020-02-19 tracey goto done;
824 ff4bb25f 2020-02-19 tracey kerr = khtml_puts(gw_trans->gw_html_req, " | ");
825 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
826 ff4bb25f 2020-02-19 tracey goto done;
828 2796ac23 2020-04-14 tracey href_tree = khttp_urlpart(NULL, NULL, "gotweb", "path",
829 2796ac23 2020-04-14 tracey gw_dir->name, "action", "tree", NULL);
830 19ff7638 2020-04-14 tracey if (href_tree == NULL) {
831 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
832 19ff7638 2020-04-14 tracey goto done;
834 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A, KATTR_HREF,
835 b3f1f953 2020-02-09 tracey href_tree, KATTR__MAX);
836 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
837 b3f1f953 2020-02-09 tracey goto done;
838 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req, "tree");
839 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
840 b3f1f953 2020-02-09 tracey goto done;
842 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 4);
843 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
844 b3f1f953 2020-02-09 tracey goto done;
845 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
846 b3f1f953 2020-02-09 tracey "dotted_line", KATTR__MAX);
847 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
848 b3f1f953 2020-02-09 tracey goto done;
849 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
850 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
851 b3f1f953 2020-02-09 tracey goto done;
853 b3f1f953 2020-02-09 tracey free(href_summary);
854 b3f1f953 2020-02-09 tracey href_summary = NULL;
855 b3f1f953 2020-02-09 tracey free(href_briefs);
856 b3f1f953 2020-02-09 tracey href_briefs = NULL;
857 b3f1f953 2020-02-09 tracey free(href_commits);
858 b3f1f953 2020-02-09 tracey href_commits = NULL;
859 ff4bb25f 2020-02-19 tracey free(href_tags);
860 ff4bb25f 2020-02-19 tracey href_tags = NULL;
861 b3f1f953 2020-02-09 tracey free(href_tree);
862 b3f1f953 2020-02-09 tracey href_tree = NULL;
864 2c251c14 2020-01-15 tracey if (gw_trans->gw_conf->got_max_repos_display == 0)
865 2c251c14 2020-01-15 tracey continue;
867 75f21c89 2020-02-18 tracey if ((next_disp == gw_trans->gw_conf->got_max_repos_display) ||
868 75f21c89 2020-02-18 tracey ((gw_trans->gw_conf->got_max_repos_display > 0) &&
869 2c251c14 2020-01-15 tracey (gw_trans->page > 0) &&
870 2c251c14 2020-01-15 tracey (next_disp == gw_trans->gw_conf->got_max_repos_display ||
871 75f21c89 2020-02-18 tracey prev_disp == gw_trans->repos_total))) {
872 63ee0dca 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
873 63ee0dca 2020-02-08 tracey KATTR_ID, "np_wrapper", KATTR__MAX);
874 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
875 b3f1f953 2020-02-09 tracey goto done;
876 63ee0dca 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
877 63ee0dca 2020-02-08 tracey KATTR_ID, "nav_prev", KATTR__MAX);
878 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
879 b3f1f953 2020-02-09 tracey goto done;
882 2c251c14 2020-01-15 tracey if ((gw_trans->gw_conf->got_max_repos_display > 0) &&
883 2c251c14 2020-01-15 tracey (gw_trans->page > 0) &&
884 2c251c14 2020-01-15 tracey (next_disp == gw_trans->gw_conf->got_max_repos_display ||
885 2c251c14 2020-01-15 tracey prev_disp == gw_trans->repos_total)) {
886 2796ac23 2020-04-14 tracey href_prev = khttp_urlpartx(NULL, NULL, "gotweb", "page",
887 2796ac23 2020-04-14 tracey KATTRX_INT, (int64_t)(gw_trans->page - 1), NULL);
888 19ff7638 2020-04-14 tracey if (href_prev == NULL) {
889 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpartx");
890 19ff7638 2020-04-14 tracey goto done;
892 63ee0dca 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
893 63ee0dca 2020-02-08 tracey KATTR_HREF, href_prev, KATTR__MAX);
894 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
895 565d9dcb 2020-02-09 tracey goto done;
896 63ee0dca 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Previous");
897 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
898 b3f1f953 2020-02-09 tracey goto done;
899 63ee0dca 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
900 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
901 b3f1f953 2020-02-09 tracey goto done;
904 63ee0dca 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
905 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
906 2447adad 2020-02-06 stsp return gw_kcgi_error(kerr);
908 2c251c14 2020-01-15 tracey if (gw_trans->gw_conf->got_max_repos_display > 0 &&
909 2c251c14 2020-01-15 tracey next_disp == gw_trans->gw_conf->got_max_repos_display &&
910 2c251c14 2020-01-15 tracey dir_c != (gw_trans->page + 1) *
911 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_max_repos_display) {
912 63ee0dca 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
913 63ee0dca 2020-02-08 tracey KATTR_ID, "nav_next", KATTR__MAX);
914 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
915 b3f1f953 2020-02-09 tracey goto done;
916 2796ac23 2020-04-14 tracey href_next = khttp_urlpartx(NULL, NULL, "gotweb", "page",
917 2796ac23 2020-04-14 tracey KATTRX_INT, (int64_t)(gw_trans->page + 1), NULL);
918 19ff7638 2020-04-14 tracey if (href_next == NULL) {
919 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpartx");
920 19ff7638 2020-04-14 tracey goto done;
922 63ee0dca 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
923 63ee0dca 2020-02-08 tracey KATTR_HREF, href_next, KATTR__MAX);
924 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
925 b3f1f953 2020-02-09 tracey goto done;
926 63ee0dca 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Next");
927 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
928 b3f1f953 2020-02-09 tracey goto done;
929 63ee0dca 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 3);
930 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
931 b3f1f953 2020-02-09 tracey goto done;
932 2c251c14 2020-01-15 tracey next_disp = 0;
936 2c251c14 2020-01-15 tracey if ((gw_trans->gw_conf->got_max_repos_display > 0) &&
937 2c251c14 2020-01-15 tracey (gw_trans->page > 0) &&
938 2c251c14 2020-01-15 tracey (next_disp == gw_trans->gw_conf->got_max_repos_display ||
939 c25c2314 2020-01-28 stsp prev_disp == gw_trans->repos_total)) {
940 63ee0dca 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
941 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
942 b3f1f953 2020-02-09 tracey goto done;
944 2c251c14 2020-01-15 tracey next_disp++;
947 00f13350 2020-02-10 tracey free(href_prev);
948 00f13350 2020-02-10 tracey free(href_next);
949 b3f1f953 2020-02-09 tracey free(href_summary);
950 b3f1f953 2020-02-09 tracey free(href_briefs);
951 b3f1f953 2020-02-09 tracey free(href_commits);
952 ff4bb25f 2020-02-19 tracey free(href_tags);
953 b3f1f953 2020-02-09 tracey free(href_tree);
954 565d9dcb 2020-02-09 tracey if (error == NULL && kerr != KCGI_OK)
955 565d9dcb 2020-02-09 tracey error = gw_kcgi_error(kerr);
956 2c251c14 2020-01-15 tracey return error;
959 2c251c14 2020-01-15 tracey static const struct got_error *
960 f2f46662 2020-01-23 tracey gw_commits(struct gw_trans *gw_trans)
962 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
963 f2f46662 2020-01-23 tracey struct gw_header *header = NULL, *n_header = NULL;
964 038dfa29 2020-04-14 tracey char *age = NULL, *href_diff = NULL, *href_tree = NULL;
965 55e46400 2020-02-18 tracey char *href_prev = NULL, *href_next = NULL;
966 21a55cc7 2020-02-04 tracey enum kcgi_err kerr = KCGI_OK;
967 5a911940 2021-06-25 tracey int commit_found = 0;
969 ae36ed87 2020-01-28 stsp if ((header = gw_init_header()) == NULL)
970 f2f46662 2020-01-23 tracey return got_error_from_errno("malloc");
972 7a6dddae 2021-06-18 stsp #ifndef PROFILE
973 6bee13de 2020-01-16 tracey if (pledge("stdio rpath proc exec sendfd unveil",
974 6bee13de 2020-01-16 tracey NULL) == -1) {
975 6bee13de 2020-01-16 tracey error = got_error_from_errno("pledge");
979 d4159696 2020-02-13 stsp error = gw_apply_unveil(gw_trans->gw_dir->path);
980 8087c3c5 2020-01-15 tracey if (error)
983 f2f46662 2020-01-23 tracey error = gw_get_header(gw_trans, header,
984 f2f46662 2020-01-23 tracey gw_trans->gw_conf->got_max_commits_display);
988 f2f46662 2020-01-23 tracey TAILQ_FOREACH(n_header, &gw_trans->gw_headers, entry) {
989 5a911940 2021-06-25 tracey if (commit_found == 0 && gw_trans->commit_id != NULL) {
990 5a911940 2021-06-25 tracey if (strcmp(gw_trans->commit_id,
991 5a911940 2021-06-25 tracey n_header->commit_id) != 0)
992 5a911940 2021-06-25 tracey continue;
994 5a911940 2021-06-25 tracey commit_found = 1;
996 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
997 21a55cc7 2020-02-04 tracey "commits_line_wrapper", KATTR__MAX);
998 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1000 21a55cc7 2020-02-04 tracey error = gw_gen_commit_header(gw_trans, n_header->commit_id,
1001 21a55cc7 2020-02-04 tracey n_header->refs_str);
1002 f7cc9480 2020-02-05 tracey if (error)
1003 f7cc9480 2020-02-05 tracey goto done;
1004 21a55cc7 2020-02-04 tracey error = gw_gen_author_header(gw_trans, n_header->author);
1005 21a55cc7 2020-02-04 tracey if (error)
1006 21a55cc7 2020-02-04 tracey goto done;
1007 21a55cc7 2020-02-04 tracey error = gw_gen_committer_header(gw_trans, n_header->author);
1008 21a55cc7 2020-02-04 tracey if (error)
1009 21a55cc7 2020-02-04 tracey goto done;
1010 55ccf528 2020-02-03 stsp error = gw_get_time_str(&age, n_header->committer_time,
1012 55ccf528 2020-02-03 stsp if (error)
1013 55ccf528 2020-02-03 stsp goto done;
1014 21a55cc7 2020-02-04 tracey error = gw_gen_age_header(gw_trans, age ?age : "");
1015 21a55cc7 2020-02-04 tracey if (error)
1016 55ccf528 2020-02-03 stsp goto done;
1017 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
1018 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1019 21a55cc7 2020-02-04 tracey goto done;
1021 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1022 21a55cc7 2020-02-04 tracey "dotted_line", KATTR__MAX);
1023 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1024 21a55cc7 2020-02-04 tracey goto done;
1025 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1026 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1027 21a55cc7 2020-02-04 tracey goto done;
1029 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1030 21a55cc7 2020-02-04 tracey "commit", KATTR__MAX);
1031 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1032 21a55cc7 2020-02-04 tracey goto done;
1033 78a9dab5 2020-02-07 tracey kerr = khttp_puts(gw_trans->gw_req, n_header->commit_msg);
1034 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1035 21a55cc7 2020-02-04 tracey goto done;
1036 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1037 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1038 21a55cc7 2020-02-04 tracey goto done;
1040 038dfa29 2020-04-14 tracey href_diff = khttp_urlpart(NULL, NULL, "gotweb", "path",
1041 038dfa29 2020-04-14 tracey gw_trans->repo_name, "action", "diff", "commit",
1042 038dfa29 2020-04-14 tracey n_header->commit_id, NULL);
1043 19ff7638 2020-04-14 tracey if (href_diff == NULL) {
1044 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
1045 19ff7638 2020-04-14 tracey goto done;
1047 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1048 21a55cc7 2020-02-04 tracey KATTR_ID, "navs_wrapper", KATTR__MAX);
1049 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1050 21a55cc7 2020-02-04 tracey goto done;
1051 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1052 21a55cc7 2020-02-04 tracey KATTR_ID, "navs", KATTR__MAX);
1053 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1054 21a55cc7 2020-02-04 tracey goto done;
1055 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
1056 21a55cc7 2020-02-04 tracey KATTR_HREF, href_diff, KATTR__MAX);
1057 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1058 21a55cc7 2020-02-04 tracey goto done;
1059 21a55cc7 2020-02-04 tracey kerr = khtml_puts(gw_trans->gw_html_req, "diff");
1060 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1061 21a55cc7 2020-02-04 tracey goto done;
1062 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1063 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1064 21a55cc7 2020-02-04 tracey goto done;
1066 21a55cc7 2020-02-04 tracey kerr = khtml_puts(gw_trans->gw_html_req, " | ");
1067 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1068 21a55cc7 2020-02-04 tracey goto done;
1070 038dfa29 2020-04-14 tracey href_tree = khttp_urlpart(NULL, NULL, "gotweb", "path",
1071 038dfa29 2020-04-14 tracey gw_trans->repo_name, "action", "tree", "commit",
1072 19ff7638 2020-04-14 tracey n_header->commit_id, NULL);
1073 19ff7638 2020-04-14 tracey if (href_tree == NULL) {
1074 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
1075 19ff7638 2020-04-14 tracey goto done;
1077 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
1078 038dfa29 2020-04-14 tracey KATTR_HREF, href_tree, KATTR__MAX);
1079 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1080 21a55cc7 2020-02-04 tracey goto done;
1081 21a55cc7 2020-02-04 tracey khtml_puts(gw_trans->gw_html_req, "tree");
1082 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1083 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1084 21a55cc7 2020-02-04 tracey goto done;
1085 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1086 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1087 21a55cc7 2020-02-04 tracey goto done;
1089 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1090 21a55cc7 2020-02-04 tracey "solid_line", KATTR__MAX);
1091 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1092 21a55cc7 2020-02-04 tracey goto done;
1093 b4fba448 2020-02-05 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
1094 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1095 21a55cc7 2020-02-04 tracey goto done;
1097 55ccf528 2020-02-03 stsp free(age);
1098 55ccf528 2020-02-03 stsp age = NULL;
1101 5a911940 2021-06-25 tracey if (gw_trans->next_id || gw_trans->prev_id) {
1102 55e46400 2020-02-18 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1103 55e46400 2020-02-18 tracey KATTR_ID, "np_wrapper", KATTR__MAX);
1104 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1105 55e46400 2020-02-18 tracey goto done;
1106 55e46400 2020-02-18 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1107 55e46400 2020-02-18 tracey KATTR_ID, "nav_prev", KATTR__MAX);
1108 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1109 55e46400 2020-02-18 tracey goto done;
1112 5a911940 2021-06-25 tracey if (gw_trans->prev_id) {
1113 038dfa29 2020-04-14 tracey href_prev = khttp_urlpartx(NULL, NULL, "gotweb", "path",
1114 038dfa29 2020-04-14 tracey KATTRX_STRING, gw_trans->repo_name, "page",
1115 038dfa29 2020-04-14 tracey KATTRX_INT, (int64_t) (gw_trans->page - 1), "action",
1116 038dfa29 2020-04-14 tracey KATTRX_STRING, "commits", "commit", KATTRX_STRING,
1117 5a911940 2021-06-25 tracey gw_trans->prev_id ? gw_trans->prev_id : "", NULL);
1118 19ff7638 2020-04-14 tracey if (href_prev == NULL) {
1119 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpartx");
1120 19ff7638 2020-04-14 tracey goto done;
1122 55e46400 2020-02-18 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
1123 55e46400 2020-02-18 tracey KATTR_HREF, href_prev, KATTR__MAX);
1124 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1125 55e46400 2020-02-18 tracey goto done;
1126 55e46400 2020-02-18 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Previous");
1127 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1128 55e46400 2020-02-18 tracey goto done;
1129 55e46400 2020-02-18 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1130 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1131 55e46400 2020-02-18 tracey goto done;
1134 55e46400 2020-02-18 tracey if (gw_trans->next_id || gw_trans->page > 0) {
1135 55e46400 2020-02-18 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1136 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1137 55e46400 2020-02-18 tracey return gw_kcgi_error(kerr);
1140 55e46400 2020-02-18 tracey if (gw_trans->next_id) {
1141 55e46400 2020-02-18 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1142 55e46400 2020-02-18 tracey KATTR_ID, "nav_next", KATTR__MAX);
1143 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1144 55e46400 2020-02-18 tracey goto done;
1145 038dfa29 2020-04-14 tracey href_next = khttp_urlpartx(NULL, NULL, "gotweb", "path",
1146 038dfa29 2020-04-14 tracey KATTRX_STRING, gw_trans->repo_name, "page",
1147 038dfa29 2020-04-14 tracey KATTRX_INT, (int64_t) (gw_trans->page + 1), "action",
1148 038dfa29 2020-04-14 tracey KATTRX_STRING, "commits", "commit", KATTRX_STRING,
1149 5a911940 2021-06-25 tracey gw_trans->next_id, NULL);
1150 19ff7638 2020-04-14 tracey if (href_next == NULL) {
1151 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpartx");
1152 19ff7638 2020-04-14 tracey goto done;
1154 55e46400 2020-02-18 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
1155 55e46400 2020-02-18 tracey KATTR_HREF, href_next, KATTR__MAX);
1156 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1157 55e46400 2020-02-18 tracey goto done;
1158 55e46400 2020-02-18 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Next");
1159 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1160 55e46400 2020-02-18 tracey goto done;
1161 55e46400 2020-02-18 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 3);
1162 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1163 55e46400 2020-02-18 tracey goto done;
1166 55e46400 2020-02-18 tracey if (gw_trans->next_id || gw_trans->page > 0) {
1167 55e46400 2020-02-18 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
1168 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1169 55e46400 2020-02-18 tracey goto done;
1172 b0a1bc86 2020-02-14 stsp gw_free_header(header);
1173 f2f46662 2020-01-23 tracey TAILQ_FOREACH(n_header, &gw_trans->gw_headers, entry)
1174 b0a1bc86 2020-02-14 stsp gw_free_header(n_header);
1175 55ccf528 2020-02-03 stsp free(age);
1176 55e46400 2020-02-18 tracey free(href_next);
1177 55e46400 2020-02-18 tracey free(href_prev);
1178 21a55cc7 2020-02-04 tracey free(href_diff);
1179 038dfa29 2020-04-14 tracey free(href_tree);
1180 21a55cc7 2020-02-04 tracey if (error == NULL && kerr != KCGI_OK)
1181 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
1182 2c251c14 2020-01-15 tracey return error;
1185 2c251c14 2020-01-15 tracey static const struct got_error *
1186 f2f46662 2020-01-23 tracey gw_briefs(struct gw_trans *gw_trans)
1188 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
1189 bd275801 2020-02-03 tracey struct gw_header *header = NULL, *n_header = NULL;
1190 9ba68833 2020-04-14 tracey char *age = NULL, *href_diff = NULL, *href_tree = NULL;
1191 55e46400 2020-02-18 tracey char *href_prev = NULL, *href_next = NULL;
1192 bd275801 2020-02-03 tracey char *newline, *smallerthan;
1193 ef72fe2c 2020-02-04 stsp enum kcgi_err kerr = KCGI_OK;
1194 5a911940 2021-06-25 tracey int commit_found = 0;
1196 ae36ed87 2020-01-28 stsp if ((header = gw_init_header()) == NULL)
1197 f2f46662 2020-01-23 tracey return got_error_from_errno("malloc");
1199 7a6dddae 2021-06-18 stsp #ifndef PROFILE
1200 6bee13de 2020-01-16 tracey if (pledge("stdio rpath proc exec sendfd unveil",
1201 6bee13de 2020-01-16 tracey NULL) == -1) {
1202 6bee13de 2020-01-16 tracey error = got_error_from_errno("pledge");
1203 5ddf0079 2020-01-29 stsp goto done;
1206 85993e64 2020-02-17 tracey if (gw_trans->action != GW_SUMMARY) {
1207 85993e64 2020-02-17 tracey error = gw_apply_unveil(gw_trans->gw_dir->path);
1208 85993e64 2020-02-17 tracey if (error)
1209 85993e64 2020-02-17 tracey goto done;
1212 f2f46662 2020-01-23 tracey if (gw_trans->action == GW_SUMMARY)
1213 f2f46662 2020-01-23 tracey error = gw_get_header(gw_trans, header, D_MAXSLCOMMDISP);
1215 f2f46662 2020-01-23 tracey error = gw_get_header(gw_trans, header,
1216 f2f46662 2020-01-23 tracey gw_trans->gw_conf->got_max_commits_display);
1217 c25c2314 2020-01-28 stsp if (error)
1218 0e00e8f4 2020-01-29 stsp goto done;
1220 f2f46662 2020-01-23 tracey TAILQ_FOREACH(n_header, &gw_trans->gw_headers, entry) {
1221 5a911940 2021-06-25 tracey if (commit_found == 0 && gw_trans->commit_id != NULL) {
1222 5a911940 2021-06-25 tracey if (strcmp(gw_trans->commit_id,
1223 5a911940 2021-06-25 tracey n_header->commit_id) != 0)
1224 5a911940 2021-06-25 tracey continue;
1226 5a911940 2021-06-25 tracey commit_found = 1;
1228 bd275801 2020-02-03 tracey error = gw_get_time_str(&age, n_header->committer_time,
1229 bd275801 2020-02-03 tracey TM_DIFF);
1230 bd275801 2020-02-03 tracey if (error)
1231 bd275801 2020-02-03 tracey goto done;
1233 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1234 bd275801 2020-02-03 tracey KATTR_ID, "briefs_wrapper", KATTR__MAX);
1235 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1236 bd275801 2020-02-03 tracey goto done;
1238 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1239 bd275801 2020-02-03 tracey KATTR_ID, "briefs_age", KATTR__MAX);
1240 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1241 bd275801 2020-02-03 tracey goto done;
1242 53e81e48 2020-02-13 tracey kerr = khtml_puts(gw_trans->gw_html_req, age ? age : "");
1243 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1244 bd275801 2020-02-03 tracey goto done;
1245 bd275801 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1246 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1247 bd275801 2020-02-03 tracey goto done;
1249 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1250 bd275801 2020-02-03 tracey KATTR_ID, "briefs_author", KATTR__MAX);
1251 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1252 bd275801 2020-02-03 tracey goto done;
1253 bd275801 2020-02-03 tracey smallerthan = strchr(n_header->author, '<');
1254 bd275801 2020-02-03 tracey if (smallerthan)
1255 bd275801 2020-02-03 tracey *smallerthan = '\0';
1256 bd275801 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req, n_header->author);
1257 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1258 bd275801 2020-02-03 tracey goto done;
1259 bd275801 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1260 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1261 bd275801 2020-02-03 tracey goto done;
1263 9ba68833 2020-04-14 tracey href_diff = khttp_urlpart(NULL, NULL, "gotweb", "path",
1264 9ba68833 2020-04-14 tracey gw_trans->repo_name, "action", "diff", "commit",
1265 9ba68833 2020-04-14 tracey n_header->commit_id, NULL);
1266 19ff7638 2020-04-14 tracey if (href_diff == NULL) {
1267 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
1268 19ff7638 2020-04-14 tracey goto done;
1270 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1271 bd275801 2020-02-03 tracey KATTR_ID, "briefs_log", KATTR__MAX);
1272 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1273 bd275801 2020-02-03 tracey goto done;
1274 f2f46662 2020-01-23 tracey newline = strchr(n_header->commit_msg, '\n');
1275 f2f46662 2020-01-23 tracey if (newline)
1276 f2f46662 2020-01-23 tracey *newline = '\0';
1277 52f8346c 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
1278 52f8346c 2020-02-03 tracey KATTR_HREF, href_diff, KATTR__MAX);
1279 52f8346c 2020-02-03 tracey if (kerr != KCGI_OK)
1280 52f8346c 2020-02-03 tracey goto done;
1281 bd275801 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req, n_header->commit_msg);
1282 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1283 55ccf528 2020-02-03 stsp goto done;
1284 bf93a5c0 2020-02-15 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1285 bf93a5c0 2020-02-15 tracey if (kerr != KCGI_OK)
1286 bf93a5c0 2020-02-15 tracey goto done;
1288 bf93a5c0 2020-02-15 tracey if (n_header->refs_str) {
1289 bf93a5c0 2020-02-15 tracey kerr = khtml_puts(gw_trans->gw_html_req, " ");
1290 bf93a5c0 2020-02-15 tracey if (kerr != KCGI_OK)
1291 bf93a5c0 2020-02-15 tracey goto done;
1292 bf93a5c0 2020-02-15 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_SPAN,
1293 bf93a5c0 2020-02-15 tracey KATTR_ID, "refs_str", KATTR__MAX);
1294 bf93a5c0 2020-02-15 tracey if (kerr != KCGI_OK)
1295 bf93a5c0 2020-02-15 tracey goto done;
1296 32b9f7ed 2020-04-14 tracey kerr = khtml_printf(gw_trans->gw_html_req, "(%s)",
1297 bf93a5c0 2020-02-15 tracey n_header->refs_str);
1298 bf93a5c0 2020-02-15 tracey if (kerr != KCGI_OK)
1299 bf93a5c0 2020-02-15 tracey goto done;
1300 bf93a5c0 2020-02-15 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1301 bf93a5c0 2020-02-15 tracey if (kerr != KCGI_OK)
1302 bf93a5c0 2020-02-15 tracey goto done;
1305 bf93a5c0 2020-02-15 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1306 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1307 bd275801 2020-02-03 tracey goto done;
1309 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1310 bd275801 2020-02-03 tracey KATTR_ID, "navs_wrapper", KATTR__MAX);
1311 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1312 bd275801 2020-02-03 tracey goto done;
1313 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1314 bd275801 2020-02-03 tracey KATTR_ID, "navs", KATTR__MAX);
1315 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1316 bd275801 2020-02-03 tracey goto done;
1317 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
1318 bd275801 2020-02-03 tracey KATTR_HREF, href_diff, KATTR__MAX);
1319 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1320 070fee27 2020-02-03 stsp goto done;
1321 bd275801 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req, "diff");
1322 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1323 bd275801 2020-02-03 tracey goto done;
1324 bd275801 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1325 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1326 bd275801 2020-02-03 tracey goto done;
1328 bd275801 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req, " | ");
1329 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1330 bd275801 2020-02-03 tracey goto done;
1332 9ba68833 2020-04-14 tracey href_tree = khttp_urlpart(NULL, NULL, "gotweb", "path",
1333 9ba68833 2020-04-14 tracey gw_trans->repo_name, "action", "tree", "commit",
1334 9ba68833 2020-04-14 tracey n_header->commit_id, NULL);
1335 19ff7638 2020-04-14 tracey if (href_tree == NULL) {
1336 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
1337 19ff7638 2020-04-14 tracey goto done;
1339 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
1340 9ba68833 2020-04-14 tracey KATTR_HREF, href_tree, KATTR__MAX);
1341 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1342 bd275801 2020-02-03 tracey goto done;
1343 bd275801 2020-02-03 tracey khtml_puts(gw_trans->gw_html_req, "tree");
1344 bd275801 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1345 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1346 bd275801 2020-02-03 tracey goto done;
1347 bd275801 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1348 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1349 bd275801 2020-02-03 tracey goto done;
1351 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1352 bd275801 2020-02-03 tracey KATTR_ID, "dotted_line", KATTR__MAX);
1353 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1354 bd275801 2020-02-03 tracey goto done;
1355 bd275801 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 3);
1356 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1357 bd275801 2020-02-03 tracey goto done;
1359 55ccf528 2020-02-03 stsp free(age);
1360 55ccf528 2020-02-03 stsp age = NULL;
1361 bd275801 2020-02-03 tracey free(href_diff);
1362 bd275801 2020-02-03 tracey href_diff = NULL;
1363 9ba68833 2020-04-14 tracey free(href_tree);
1364 9ba68833 2020-04-14 tracey href_tree = NULL;
1367 5a911940 2021-06-25 tracey if (gw_trans->next_id || gw_trans->prev_id) {
1368 55e46400 2020-02-18 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1369 55e46400 2020-02-18 tracey KATTR_ID, "np_wrapper", KATTR__MAX);
1370 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1371 55e46400 2020-02-18 tracey goto done;
1372 55e46400 2020-02-18 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1373 55e46400 2020-02-18 tracey KATTR_ID, "nav_prev", KATTR__MAX);
1374 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1375 55e46400 2020-02-18 tracey goto done;
1378 5a911940 2021-06-25 tracey if (gw_trans->prev_id) {
1379 9ba68833 2020-04-14 tracey href_prev = khttp_urlpartx(NULL, NULL, "gotweb", "path",
1380 9ba68833 2020-04-14 tracey KATTRX_STRING, gw_trans->repo_name, "page",
1381 9ba68833 2020-04-14 tracey KATTRX_INT, (int64_t) (gw_trans->page - 1), "action",
1382 9ba68833 2020-04-14 tracey KATTRX_STRING, "briefs", "commit", KATTRX_STRING,
1383 5a911940 2021-06-25 tracey gw_trans->prev_id ? gw_trans->prev_id : "", NULL);
1384 19ff7638 2020-04-14 tracey if (href_prev == NULL) {
1385 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpartx");
1386 19ff7638 2020-04-14 tracey goto done;
1388 55e46400 2020-02-18 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
1389 55e46400 2020-02-18 tracey KATTR_HREF, href_prev, KATTR__MAX);
1390 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1391 55e46400 2020-02-18 tracey goto done;
1392 55e46400 2020-02-18 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Previous");
1393 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1394 55e46400 2020-02-18 tracey goto done;
1395 55e46400 2020-02-18 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1396 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1397 55e46400 2020-02-18 tracey goto done;
1400 55e46400 2020-02-18 tracey if (gw_trans->next_id || gw_trans->page > 0) {
1401 55e46400 2020-02-18 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1402 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1403 55e46400 2020-02-18 tracey return gw_kcgi_error(kerr);
1406 55e46400 2020-02-18 tracey if (gw_trans->next_id) {
1407 55e46400 2020-02-18 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1408 55e46400 2020-02-18 tracey KATTR_ID, "nav_next", KATTR__MAX);
1409 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1410 55e46400 2020-02-18 tracey goto done;
1412 9ba68833 2020-04-14 tracey href_next = khttp_urlpartx(NULL, NULL, "gotweb", "path",
1413 9ba68833 2020-04-14 tracey KATTRX_STRING, gw_trans->repo_name, "page",
1414 9ba68833 2020-04-14 tracey KATTRX_INT, (int64_t) (gw_trans->page + 1), "action",
1415 9ba68833 2020-04-14 tracey KATTRX_STRING, "briefs", "commit", KATTRX_STRING,
1416 5a911940 2021-06-25 tracey gw_trans->next_id, NULL);
1417 19ff7638 2020-04-14 tracey if (href_next == NULL) {
1418 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpartx");
1419 19ff7638 2020-04-14 tracey goto done;
1421 55e46400 2020-02-18 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
1422 55e46400 2020-02-18 tracey KATTR_HREF, href_next, KATTR__MAX);
1423 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1424 55e46400 2020-02-18 tracey goto done;
1425 55e46400 2020-02-18 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Next");
1426 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1427 55e46400 2020-02-18 tracey goto done;
1428 55e46400 2020-02-18 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 3);
1429 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1430 55e46400 2020-02-18 tracey goto done;
1433 55e46400 2020-02-18 tracey if (gw_trans->next_id || gw_trans->page > 0) {
1434 55e46400 2020-02-18 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
1435 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1436 55e46400 2020-02-18 tracey goto done;
1439 b0a1bc86 2020-02-14 stsp gw_free_header(header);
1440 f2f46662 2020-01-23 tracey TAILQ_FOREACH(n_header, &gw_trans->gw_headers, entry)
1441 b0a1bc86 2020-02-14 stsp gw_free_header(n_header);
1442 55ccf528 2020-02-03 stsp free(age);
1443 55e46400 2020-02-18 tracey free(href_next);
1444 55e46400 2020-02-18 tracey free(href_prev);
1445 bd275801 2020-02-03 tracey free(href_diff);
1446 9ba68833 2020-04-14 tracey free(href_tree);
1447 ef72fe2c 2020-02-04 stsp if (error == NULL && kerr != KCGI_OK)
1448 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
1449 2c251c14 2020-01-15 tracey return error;
1452 2c251c14 2020-01-15 tracey static const struct got_error *
1453 54415d85 2020-01-15 tracey gw_summary(struct gw_trans *gw_trans)
1455 387a29ba 2020-01-15 tracey const struct got_error *error = NULL;
1456 9eed6f10 2020-02-08 tracey char *age = NULL;
1457 21a55cc7 2020-02-04 tracey enum kcgi_err kerr = KCGI_OK;
1459 7a6dddae 2021-06-18 stsp #ifndef PROFILE
1460 f4df82f9 2020-01-29 stsp if (pledge("stdio rpath proc exec sendfd unveil", NULL) == -1)
1461 f4df82f9 2020-01-29 stsp return got_error_from_errno("pledge");
1463 85993e64 2020-02-17 tracey error = gw_apply_unveil(gw_trans->gw_dir->path);
1464 85993e64 2020-02-17 tracey if (error)
1465 85993e64 2020-02-17 tracey goto done;
1467 783ec107 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1468 783ec107 2020-02-03 tracey "summary_wrapper", KATTR__MAX);
1469 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
1470 2447adad 2020-02-06 stsp return gw_kcgi_error(kerr);
1472 783ec107 2020-02-03 tracey if (gw_trans->gw_conf->got_show_repo_description &&
1473 783ec107 2020-02-03 tracey gw_trans->gw_dir->description != NULL &&
1474 783ec107 2020-02-03 tracey (strcmp(gw_trans->gw_dir->description, "") != 0)) {
1475 783ec107 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1476 783ec107 2020-02-03 tracey KATTR_ID, "description_title", KATTR__MAX);
1477 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1478 783ec107 2020-02-03 tracey goto done;
1479 783ec107 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Description: ");
1480 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1481 783ec107 2020-02-03 tracey goto done;
1482 783ec107 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1483 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1484 783ec107 2020-02-03 tracey goto done;
1485 783ec107 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1486 783ec107 2020-02-03 tracey KATTR_ID, "description", KATTR__MAX);
1487 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1488 783ec107 2020-02-03 tracey goto done;
1489 783ec107 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req,
1490 783ec107 2020-02-03 tracey gw_trans->gw_dir->description);
1491 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1492 783ec107 2020-02-03 tracey goto done;
1493 783ec107 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1494 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1495 783ec107 2020-02-03 tracey goto done;
1498 9a1cc63f 2020-02-03 stsp if (gw_trans->gw_conf->got_show_repo_owner &&
1499 a942aa37 2020-02-10 tracey gw_trans->gw_dir->owner != NULL &&
1500 a942aa37 2020-02-10 tracey (strcmp(gw_trans->gw_dir->owner, "") != 0)) {
1501 783ec107 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1502 783ec107 2020-02-03 tracey KATTR_ID, "repo_owner_title", KATTR__MAX);
1503 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1504 9a1cc63f 2020-02-03 stsp goto done;
1505 783ec107 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Owner: ");
1506 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1507 9a1cc63f 2020-02-03 stsp goto done;
1508 783ec107 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1509 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1510 783ec107 2020-02-03 tracey goto done;
1511 783ec107 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1512 783ec107 2020-02-03 tracey KATTR_ID, "repo_owner", KATTR__MAX);
1513 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1514 783ec107 2020-02-03 tracey goto done;
1515 783ec107 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req,
1516 62d463ca 2020-10-20 naddy gw_trans->gw_dir->owner);
1517 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1518 783ec107 2020-02-03 tracey goto done;
1519 783ec107 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1520 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1521 783ec107 2020-02-03 tracey goto done;
1524 46b9c89b 2020-01-15 tracey if (gw_trans->gw_conf->got_show_repo_age) {
1525 d126c1b7 2020-01-29 stsp error = gw_get_repo_age(&age, gw_trans, gw_trans->gw_dir->path,
1526 2011c142 2020-02-14 stsp NULL, TM_LONG);
1527 d126c1b7 2020-01-29 stsp if (error)
1528 20f34652 2020-01-29 stsp goto done;
1529 55ccf528 2020-02-03 stsp if (age != NULL) {
1530 783ec107 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1531 783ec107 2020-02-03 tracey KATTR_ID, "last_change_title", KATTR__MAX);
1532 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1533 20f34652 2020-01-29 stsp goto done;
1534 783ec107 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req,
1535 783ec107 2020-02-03 tracey "Last Change: ");
1536 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1537 20f34652 2020-01-29 stsp goto done;
1538 783ec107 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1539 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1540 20f34652 2020-01-29 stsp goto done;
1541 783ec107 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1542 783ec107 2020-02-03 tracey KATTR_ID, "last_change", KATTR__MAX);
1543 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1544 20f34652 2020-01-29 stsp goto done;
1545 783ec107 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req, age);
1546 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1547 783ec107 2020-02-03 tracey goto done;
1548 783ec107 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1549 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1550 783ec107 2020-02-03 tracey goto done;
1554 783ec107 2020-02-03 tracey if (gw_trans->gw_conf->got_show_repo_cloneurl &&
1555 783ec107 2020-02-03 tracey gw_trans->gw_dir->url != NULL &&
1556 783ec107 2020-02-03 tracey (strcmp(gw_trans->gw_dir->url, "") != 0)) {
1557 783ec107 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1558 783ec107 2020-02-03 tracey KATTR_ID, "cloneurl_title", KATTR__MAX);
1559 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1560 783ec107 2020-02-03 tracey goto done;
1561 783ec107 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Clone URL: ");
1562 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1563 783ec107 2020-02-03 tracey goto done;
1564 783ec107 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1565 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1566 783ec107 2020-02-03 tracey goto done;
1567 783ec107 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1568 783ec107 2020-02-03 tracey KATTR_ID, "cloneurl", KATTR__MAX);
1569 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1570 783ec107 2020-02-03 tracey goto done;
1571 783ec107 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req, gw_trans->gw_dir->url);
1572 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1573 21a55cc7 2020-02-04 tracey goto done;
1574 783ec107 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1575 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1576 783ec107 2020-02-03 tracey goto done;
1579 783ec107 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1580 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1581 bd275801 2020-02-03 tracey goto done;
1583 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1584 bd275801 2020-02-03 tracey "briefs_title_wrapper", KATTR__MAX);
1585 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1586 bd275801 2020-02-03 tracey goto done;
1587 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1588 bd275801 2020-02-03 tracey "briefs_title", KATTR__MAX);
1589 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1590 20f34652 2020-01-29 stsp goto done;
1591 bd275801 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Commit Briefs");
1592 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1593 bd275801 2020-02-03 tracey goto done;
1594 bd275801 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
1595 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1596 bd275801 2020-02-03 tracey goto done;
1597 f2f46662 2020-01-23 tracey error = gw_briefs(gw_trans);
1598 f2f46662 2020-01-23 tracey if (error)
1599 20f34652 2020-01-29 stsp goto done;
1601 ff4bb25f 2020-02-19 tracey error = gw_tags(gw_trans);
1602 6eccd105 2020-02-03 stsp if (error)
1603 6eccd105 2020-02-03 stsp goto done;
1605 9eed6f10 2020-02-08 tracey error = gw_output_repo_heads(gw_trans);
1607 20f34652 2020-01-29 stsp free(age);
1608 f7cc9480 2020-02-05 tracey if (error == NULL && kerr != KCGI_OK)
1609 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
1610 2204c934 2020-01-15 tracey return error;
1613 2204c934 2020-01-15 tracey static const struct got_error *
1614 f2f46662 2020-01-23 tracey gw_tree(struct gw_trans *gw_trans)
1616 b772de24 2020-01-15 tracey const struct got_error *error = NULL;
1617 f2f46662 2020-01-23 tracey struct gw_header *header = NULL;
1618 f2f46662 2020-01-23 tracey char *tree = NULL, *tree_html = NULL, *tree_html_disp = NULL;
1619 53e81e48 2020-02-13 tracey char *age = NULL;
1620 795c10a4 2020-02-20 tracey enum kcgi_err kerr = KCGI_OK;
1622 7a6dddae 2021-06-18 stsp #ifndef PROFILE
1623 f2f46662 2020-01-23 tracey if (pledge("stdio rpath proc exec sendfd unveil", NULL) == -1)
1624 f2f46662 2020-01-23 tracey return got_error_from_errno("pledge");
1626 ae36ed87 2020-01-28 stsp if ((header = gw_init_header()) == NULL)
1627 f2f46662 2020-01-23 tracey return got_error_from_errno("malloc");
1629 d4159696 2020-02-13 stsp error = gw_apply_unveil(gw_trans->gw_dir->path);
1630 b772de24 2020-01-15 tracey if (error)
1631 5ddf0079 2020-01-29 stsp goto done;
1633 f2f46662 2020-01-23 tracey error = gw_get_header(gw_trans, header, 1);
1634 f2f46662 2020-01-23 tracey if (error)
1635 42281175 2020-01-29 stsp goto done;
1637 626b25b6 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1638 626b25b6 2020-02-06 tracey "tree_header_wrapper", KATTR__MAX);
1639 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
1640 55ccf528 2020-02-03 stsp goto done;
1641 626b25b6 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1642 626b25b6 2020-02-06 tracey "tree_header", KATTR__MAX);
1643 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
1644 55ccf528 2020-02-03 stsp goto done;
1645 626b25b6 2020-02-06 tracey error = gw_gen_tree_header(gw_trans, header->tree_id);
1646 626b25b6 2020-02-06 tracey if (error)
1647 626b25b6 2020-02-06 tracey goto done;
1648 626b25b6 2020-02-06 tracey error = gw_get_time_str(&age, header->committer_time,
1649 626b25b6 2020-02-06 tracey TM_LONG);
1650 626b25b6 2020-02-06 tracey if (error)
1651 626b25b6 2020-02-06 tracey goto done;
1652 626b25b6 2020-02-06 tracey error = gw_gen_age_header(gw_trans, age ?age : "");
1653 070fee27 2020-02-03 stsp if (error)
1654 070fee27 2020-02-03 stsp goto done;
1655 626b25b6 2020-02-06 tracey error = gw_gen_commit_msg_header(gw_trans, header->commit_msg);
1656 626b25b6 2020-02-06 tracey if (error)
1657 42281175 2020-01-29 stsp goto done;
1658 626b25b6 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
1659 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
1660 42281175 2020-01-29 stsp goto done;
1661 626b25b6 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1662 626b25b6 2020-02-06 tracey "dotted_line", KATTR__MAX);
1663 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
1664 626b25b6 2020-02-06 tracey goto done;
1665 626b25b6 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1666 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
1667 626b25b6 2020-02-06 tracey goto done;
1669 626b25b6 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1670 626b25b6 2020-02-06 tracey "tree", KATTR__MAX);
1671 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
1672 626b25b6 2020-02-06 tracey goto done;
1673 84de9106 2020-12-26 stsp error = gw_output_repo_tree(gw_trans, header);
1674 626b25b6 2020-02-06 tracey if (error)
1675 626b25b6 2020-02-06 tracey goto done;
1677 626b25b6 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1679 b0a1bc86 2020-02-14 stsp gw_free_header(header);
1680 f2f46662 2020-01-23 tracey free(tree_html_disp);
1681 f2f46662 2020-01-23 tracey free(tree_html);
1682 f2f46662 2020-01-23 tracey free(tree);
1683 55ccf528 2020-02-03 stsp free(age);
1684 ff4bb25f 2020-02-19 tracey if (error == NULL && kerr != KCGI_OK)
1685 ff4bb25f 2020-02-19 tracey error = gw_kcgi_error(kerr);
1686 ff4bb25f 2020-02-19 tracey return error;
1689 ff4bb25f 2020-02-19 tracey static const struct got_error *
1690 ff4bb25f 2020-02-19 tracey gw_tags(struct gw_trans *gw_trans)
1692 ff4bb25f 2020-02-19 tracey const struct got_error *error = NULL;
1693 ff4bb25f 2020-02-19 tracey struct gw_header *header = NULL;
1694 ff4bb25f 2020-02-19 tracey char *href_next = NULL, *href_prev = NULL;
1695 ff4bb25f 2020-02-19 tracey enum kcgi_err kerr = KCGI_OK;
1697 7a6dddae 2021-06-18 stsp #ifndef PROFILE
1698 ff4bb25f 2020-02-19 tracey if (pledge("stdio rpath proc exec sendfd unveil", NULL) == -1)
1699 ff4bb25f 2020-02-19 tracey return got_error_from_errno("pledge");
1701 ff4bb25f 2020-02-19 tracey if ((header = gw_init_header()) == NULL)
1702 ff4bb25f 2020-02-19 tracey return got_error_from_errno("malloc");
1704 ff4bb25f 2020-02-19 tracey if (gw_trans->action != GW_SUMMARY) {
1705 ff4bb25f 2020-02-19 tracey error = gw_apply_unveil(gw_trans->gw_dir->path);
1706 ff4bb25f 2020-02-19 tracey if (error)
1707 ff4bb25f 2020-02-19 tracey goto done;
1710 ff4bb25f 2020-02-19 tracey error = gw_get_header(gw_trans, header, 1);
1711 ff4bb25f 2020-02-19 tracey if (error)
1712 ff4bb25f 2020-02-19 tracey goto done;
1714 ff4bb25f 2020-02-19 tracey if (gw_trans->action == GW_SUMMARY) {
1715 7b1f04a6 2020-03-11 tracey gw_trans->next_id = NULL;
1716 ff4bb25f 2020-02-19 tracey error = gw_output_repo_tags(gw_trans, header,
1717 ff4bb25f 2020-02-19 tracey D_MAXSLCOMMDISP, TAGBRIEF);
1718 ff4bb25f 2020-02-19 tracey if (error)
1719 ff4bb25f 2020-02-19 tracey goto done;
1720 ff4bb25f 2020-02-19 tracey } else {
1721 ff4bb25f 2020-02-19 tracey error = gw_output_repo_tags(gw_trans, header,
1722 ff4bb25f 2020-02-19 tracey gw_trans->gw_conf->got_max_commits_display, TAGBRIEF);
1723 ff4bb25f 2020-02-19 tracey if (error)
1724 ff4bb25f 2020-02-19 tracey goto done;
1727 ff4bb25f 2020-02-19 tracey if (gw_trans->next_id || gw_trans->page > 0) {
1728 ff4bb25f 2020-02-19 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1729 ff4bb25f 2020-02-19 tracey KATTR_ID, "np_wrapper", KATTR__MAX);
1730 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
1731 ff4bb25f 2020-02-19 tracey goto done;
1732 ff4bb25f 2020-02-19 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1733 ff4bb25f 2020-02-19 tracey KATTR_ID, "nav_prev", KATTR__MAX);
1734 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
1735 ff4bb25f 2020-02-19 tracey goto done;
1738 5a911940 2021-06-25 tracey if (gw_trans->prev_id) {
1739 f7632464 2020-04-14 tracey href_prev = khttp_urlpartx(NULL, NULL, "gotweb", "path",
1740 f7632464 2020-04-14 tracey KATTRX_STRING, gw_trans->repo_name, "page",
1741 f7632464 2020-04-14 tracey KATTRX_INT, (int64_t) (gw_trans->page - 1), "action",
1742 f7632464 2020-04-14 tracey KATTRX_STRING, "tags", "commit", KATTRX_STRING,
1743 5a911940 2021-06-25 tracey gw_trans->prev_id ? gw_trans->prev_id : "", NULL);
1744 19ff7638 2020-04-14 tracey if (href_prev == NULL) {
1745 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpartx");
1746 19ff7638 2020-04-14 tracey goto done;
1748 ff4bb25f 2020-02-19 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
1749 ff4bb25f 2020-02-19 tracey KATTR_HREF, href_prev, KATTR__MAX);
1750 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
1751 ff4bb25f 2020-02-19 tracey goto done;
1752 ff4bb25f 2020-02-19 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Previous");
1753 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
1754 ff4bb25f 2020-02-19 tracey goto done;
1755 ff4bb25f 2020-02-19 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1756 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
1757 ff4bb25f 2020-02-19 tracey goto done;
1760 ff4bb25f 2020-02-19 tracey if (gw_trans->next_id || gw_trans->page > 0) {
1761 ff4bb25f 2020-02-19 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1762 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
1763 ff4bb25f 2020-02-19 tracey return gw_kcgi_error(kerr);
1766 ff4bb25f 2020-02-19 tracey if (gw_trans->next_id) {
1767 ff4bb25f 2020-02-19 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1768 ff4bb25f 2020-02-19 tracey KATTR_ID, "nav_next", KATTR__MAX);
1769 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
1770 ff4bb25f 2020-02-19 tracey goto done;
1771 f7632464 2020-04-14 tracey href_next = khttp_urlpartx(NULL, NULL, "gotweb", "path",
1772 f7632464 2020-04-14 tracey KATTRX_STRING, gw_trans->repo_name, "page",
1773 f7632464 2020-04-14 tracey KATTRX_INT, (int64_t) (gw_trans->page + 1), "action",
1774 f7632464 2020-04-14 tracey KATTRX_STRING, "tags", "commit", KATTRX_STRING,
1775 5a911940 2021-06-25 tracey gw_trans->next_id, NULL);
1776 19ff7638 2020-04-14 tracey if (href_next == NULL) {
1777 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpartx");
1778 19ff7638 2020-04-14 tracey goto done;
1780 ff4bb25f 2020-02-19 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
1781 ff4bb25f 2020-02-19 tracey KATTR_HREF, href_next, KATTR__MAX);
1782 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
1783 ff4bb25f 2020-02-19 tracey goto done;
1784 ff4bb25f 2020-02-19 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Next");
1785 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
1786 ff4bb25f 2020-02-19 tracey goto done;
1787 ff4bb25f 2020-02-19 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 3);
1788 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
1789 ff4bb25f 2020-02-19 tracey goto done;
1792 ff4bb25f 2020-02-19 tracey if (gw_trans->next_id || gw_trans->page > 0) {
1793 ff4bb25f 2020-02-19 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
1794 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
1795 ff4bb25f 2020-02-19 tracey goto done;
1798 ff4bb25f 2020-02-19 tracey gw_free_header(header);
1799 ff4bb25f 2020-02-19 tracey free(href_next);
1800 ff4bb25f 2020-02-19 tracey free(href_prev);
1801 626b25b6 2020-02-06 tracey if (error == NULL && kerr != KCGI_OK)
1802 626b25b6 2020-02-06 tracey error = gw_kcgi_error(kerr);
1803 4ff7391f 2020-01-28 tracey return error;
1806 4ff7391f 2020-01-28 tracey static const struct got_error *
1807 4ff7391f 2020-01-28 tracey gw_tag(struct gw_trans *gw_trans)
1809 4ff7391f 2020-01-28 tracey const struct got_error *error = NULL;
1810 4ff7391f 2020-01-28 tracey struct gw_header *header = NULL;
1811 795c10a4 2020-02-20 tracey enum kcgi_err kerr = KCGI_OK;
1813 7a6dddae 2021-06-18 stsp #ifndef PROFILE
1814 4ff7391f 2020-01-28 tracey if (pledge("stdio rpath proc exec sendfd unveil", NULL) == -1)
1815 4ff7391f 2020-01-28 tracey return got_error_from_errno("pledge");
1817 4ff7391f 2020-01-28 tracey if ((header = gw_init_header()) == NULL)
1818 4ff7391f 2020-01-28 tracey return got_error_from_errno("malloc");
1820 d4159696 2020-02-13 stsp error = gw_apply_unveil(gw_trans->gw_dir->path);
1821 4ff7391f 2020-01-28 tracey if (error)
1822 5ddf0079 2020-01-29 stsp goto done;
1824 9f33591a 2020-02-14 tracey if (gw_trans->commit_id == NULL) {
1825 9f33591a 2020-02-14 tracey error = got_error_msg(GOT_ERR_QUERYSTRING,
1826 9f33591a 2020-02-14 tracey "commit required in querystring");
1827 9f33591a 2020-02-14 tracey goto done;
1830 4ff7391f 2020-01-28 tracey error = gw_get_header(gw_trans, header, 1);
1831 4ff7391f 2020-01-28 tracey if (error)
1832 470cd826 2020-01-29 stsp goto done;
1834 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1835 38b240fb 2020-02-06 tracey "tag_header_wrapper", KATTR__MAX);
1836 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
1837 38b240fb 2020-02-06 tracey goto done;
1838 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1839 38b240fb 2020-02-06 tracey "tag_header", KATTR__MAX);
1840 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
1841 38b240fb 2020-02-06 tracey goto done;
1842 38b240fb 2020-02-06 tracey error = gw_gen_commit_header(gw_trans, header->commit_id,
1843 38b240fb 2020-02-06 tracey header->refs_str);
1844 6eccd105 2020-02-03 stsp if (error)
1845 6eccd105 2020-02-03 stsp goto done;
1846 38b240fb 2020-02-06 tracey error = gw_gen_commit_msg_header(gw_trans, header->commit_msg);
1847 38b240fb 2020-02-06 tracey if (error)
1848 470cd826 2020-01-29 stsp goto done;
1849 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
1850 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
1851 470cd826 2020-01-29 stsp goto done;
1852 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1853 38b240fb 2020-02-06 tracey "dotted_line", KATTR__MAX);
1854 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
1855 38b240fb 2020-02-06 tracey goto done;
1856 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1857 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
1858 38b240fb 2020-02-06 tracey goto done;
1860 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1861 38b240fb 2020-02-06 tracey "tree", KATTR__MAX);
1862 4ff7391f 2020-01-28 tracey if (kerr != KCGI_OK)
1863 38b240fb 2020-02-06 tracey goto done;
1865 38b240fb 2020-02-06 tracey error = gw_output_repo_tags(gw_trans, header, 1, TAGFULL);
1866 38b240fb 2020-02-06 tracey if (error)
1867 38b240fb 2020-02-06 tracey goto done;
1869 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1871 b0a1bc86 2020-02-14 stsp gw_free_header(header);
1872 38b240fb 2020-02-06 tracey if (error == NULL && kerr != KCGI_OK)
1873 38b240fb 2020-02-06 tracey error = gw_kcgi_error(kerr);
1874 2c251c14 2020-01-15 tracey return error;
1877 2c251c14 2020-01-15 tracey static const struct got_error *
1878 54415d85 2020-01-15 tracey gw_load_got_path(struct gw_trans *gw_trans, struct gw_dir *gw_dir)
1880 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
1881 2c251c14 2020-01-15 tracey DIR *dt;
1882 2c251c14 2020-01-15 tracey char *dir_test;
1883 4ceb8155 2020-01-15 tracey int opened = 0;
1885 88d59c36 2020-01-29 stsp if (asprintf(&dir_test, "%s/%s/%s",
1886 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_repos_path, gw_dir->name,
1887 88d59c36 2020-01-29 stsp GOTWEB_GIT_DIR) == -1)
1888 2c251c14 2020-01-15 tracey return got_error_from_errno("asprintf");
1890 2c251c14 2020-01-15 tracey dt = opendir(dir_test);
1891 2c251c14 2020-01-15 tracey if (dt == NULL) {
1892 2c251c14 2020-01-15 tracey free(dir_test);
1893 2c251c14 2020-01-15 tracey } else {
1894 d1635ae4 2020-02-13 tracey gw_dir->path = strdup(dir_test);
1895 d1635ae4 2020-02-13 tracey if (gw_dir->path == NULL) {
1896 d1635ae4 2020-02-13 tracey opened = 1;
1897 d1635ae4 2020-02-13 tracey error = got_error_from_errno("strdup");
1898 a942aa37 2020-02-10 tracey goto errored;
1900 d1635ae4 2020-02-13 tracey opened = 1;
1901 2c251c14 2020-01-15 tracey goto done;
1904 88d59c36 2020-01-29 stsp if (asprintf(&dir_test, "%s/%s/%s",
1905 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_repos_path, gw_dir->name,
1906 d81f9039 2020-02-13 stsp GOTWEB_GOT_DIR) == -1) {
1907 d81f9039 2020-02-13 stsp dir_test = NULL;
1908 d81f9039 2020-02-13 stsp error = got_error_from_errno("asprintf");
1909 d81f9039 2020-02-13 stsp goto errored;
1912 2c251c14 2020-01-15 tracey dt = opendir(dir_test);
1913 2c251c14 2020-01-15 tracey if (dt == NULL)
1914 2c251c14 2020-01-15 tracey free(dir_test);
1916 4ceb8155 2020-01-15 tracey opened = 1;
1917 2c251c14 2020-01-15 tracey error = got_error(GOT_ERR_NOT_GIT_REPO);
1918 2c251c14 2020-01-15 tracey goto errored;
1921 88d59c36 2020-01-29 stsp if (asprintf(&dir_test, "%s/%s",
1922 d81f9039 2020-02-13 stsp gw_trans->gw_conf->got_repos_path, gw_dir->name) == -1) {
1923 d81f9039 2020-02-13 stsp error = got_error_from_errno("asprintf");
1924 d81f9039 2020-02-13 stsp dir_test = NULL;
1925 d81f9039 2020-02-13 stsp goto errored;
1928 d1635ae4 2020-02-13 tracey gw_dir->path = strdup(dir_test);
1929 d1635ae4 2020-02-13 tracey if (gw_dir->path == NULL) {
1930 a942aa37 2020-02-10 tracey opened = 1;
1931 d1635ae4 2020-02-13 tracey error = got_error_from_errno("strdup");
1932 a942aa37 2020-02-10 tracey goto errored;
1935 cc18a904 2020-02-13 tracey dt = opendir(dir_test);
1936 cc18a904 2020-02-13 tracey if (dt == NULL) {
1937 d90bcdd6 2020-02-17 stsp error = got_error_path(gw_dir->name, GOT_ERR_NOT_GIT_REPO);
1938 cc18a904 2020-02-13 tracey goto errored;
1940 7ecc73af 2020-02-13 tracey opened = 1;
1942 32cd4d18 2020-02-03 stsp error = gw_get_repo_description(&gw_dir->description, gw_trans,
1943 2c251c14 2020-01-15 tracey gw_dir->path);
1944 32cd4d18 2020-02-03 stsp if (error)
1945 32cd4d18 2020-02-03 stsp goto errored;
1946 9a1cc63f 2020-02-03 stsp error = gw_get_repo_owner(&gw_dir->owner, gw_trans, gw_dir->path);
1947 9a1cc63f 2020-02-03 stsp if (error)
1948 9a1cc63f 2020-02-03 stsp goto errored;
1949 d126c1b7 2020-01-29 stsp error = gw_get_repo_age(&gw_dir->age, gw_trans, gw_dir->path,
1950 2011c142 2020-02-14 stsp NULL, TM_DIFF);
1951 d126c1b7 2020-01-29 stsp if (error)
1952 d126c1b7 2020-01-29 stsp goto errored;
1953 59d3c40e 2020-02-03 stsp error = gw_get_clone_url(&gw_dir->url, gw_trans, gw_dir->path);
1954 2c251c14 2020-01-15 tracey errored:
1955 2c251c14 2020-01-15 tracey free(dir_test);
1956 2c251c14 2020-01-15 tracey if (opened)
1957 795c5bd7 2020-02-17 tracey if (dt && closedir(dt) == -1 && error == NULL)
1958 e227880d 2020-02-17 tracey error = got_error_from_errno("closedir");
1959 2c251c14 2020-01-15 tracey return error;
1962 2c251c14 2020-01-15 tracey static const struct got_error *
1963 54415d85 2020-01-15 tracey gw_load_got_paths(struct gw_trans *gw_trans)
1965 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
1967 2c251c14 2020-01-15 tracey struct dirent **sd_dent;
1968 2c251c14 2020-01-15 tracey struct gw_dir *gw_dir;
1969 2c251c14 2020-01-15 tracey struct stat st;
1970 2c251c14 2020-01-15 tracey unsigned int d_cnt, d_i;
1972 2c251c14 2020-01-15 tracey d = opendir(gw_trans->gw_conf->got_repos_path);
1973 2c251c14 2020-01-15 tracey if (d == NULL) {
1974 2c251c14 2020-01-15 tracey error = got_error_from_errno2("opendir",
1975 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_repos_path);
1976 2c251c14 2020-01-15 tracey return error;
1979 2c251c14 2020-01-15 tracey d_cnt = scandir(gw_trans->gw_conf->got_repos_path, &sd_dent, NULL,
1980 2c251c14 2020-01-15 tracey alphasort);
1981 2c251c14 2020-01-15 tracey if (d_cnt == -1) {
1982 2c251c14 2020-01-15 tracey error = got_error_from_errno2("scandir",
1983 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_repos_path);
1984 8182bd34 2020-02-17 tracey goto done;
1987 2c251c14 2020-01-15 tracey for (d_i = 0; d_i < d_cnt; d_i++) {
1988 2c251c14 2020-01-15 tracey if (gw_trans->gw_conf->got_max_repos > 0 &&
1989 2c251c14 2020-01-15 tracey (d_i - 2) == gw_trans->gw_conf->got_max_repos)
1990 2c251c14 2020-01-15 tracey break; /* account for parent and self */
1992 2c251c14 2020-01-15 tracey if (strcmp(sd_dent[d_i]->d_name, ".") == 0 ||
1993 2c251c14 2020-01-15 tracey strcmp(sd_dent[d_i]->d_name, "..") == 0)
1994 2c251c14 2020-01-15 tracey continue;
1996 4619e1f2 2020-02-13 stsp error = gw_init_gw_dir(&gw_dir, sd_dent[d_i]->d_name);
1997 4619e1f2 2020-02-13 stsp if (error)
1998 8182bd34 2020-02-17 tracey goto done;
2000 2c251c14 2020-01-15 tracey error = gw_load_got_path(gw_trans, gw_dir);
2001 7bf16821 2020-02-07 stsp if (error && error->code == GOT_ERR_NOT_GIT_REPO) {
2002 7bf16821 2020-02-07 stsp error = NULL;
2003 2c251c14 2020-01-15 tracey continue;
2005 2c251c14 2020-01-15 tracey else if (error)
2006 8182bd34 2020-02-17 tracey goto done;
2008 2c251c14 2020-01-15 tracey if (lstat(gw_dir->path, &st) == 0 && S_ISDIR(st.st_mode) &&
2009 2c251c14 2020-01-15 tracey !got_path_dir_is_empty(gw_dir->path)) {
2010 2c251c14 2020-01-15 tracey TAILQ_INSERT_TAIL(&gw_trans->gw_dirs, gw_dir,
2012 2c251c14 2020-01-15 tracey gw_trans->repos_total++;
2016 e227880d 2020-02-17 tracey if (d && closedir(d) == -1 && error == NULL)
2017 e227880d 2020-02-17 tracey error = got_error_from_errno("closedir");
2018 2c251c14 2020-01-15 tracey return error;
2021 2c251c14 2020-01-15 tracey static const struct got_error *
2022 54415d85 2020-01-15 tracey gw_parse_querystring(struct gw_trans *gw_trans)
2024 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
2025 2c251c14 2020-01-15 tracey struct kpair *p;
2026 2c251c14 2020-01-15 tracey struct gw_query_action *action = NULL;
2027 2c251c14 2020-01-15 tracey unsigned int i;
2029 2c251c14 2020-01-15 tracey if (gw_trans->gw_req->fieldnmap[0]) {
2030 8f214b62 2020-02-17 stsp return got_error(GOT_ERR_QUERYSTRING);
2031 2c251c14 2020-01-15 tracey } else if ((p = gw_trans->gw_req->fieldmap[KEY_PATH])) {
2032 2c251c14 2020-01-15 tracey /* define gw_trans->repo_path */
2033 f652ec0c 2020-02-13 stsp gw_trans->repo_name = p->parsed.s;
2035 88d59c36 2020-01-29 stsp if (asprintf(&gw_trans->repo_path, "%s/%s",
2036 88d59c36 2020-01-29 stsp gw_trans->gw_conf->got_repos_path, p->parsed.s) == -1)
2037 2c251c14 2020-01-15 tracey return got_error_from_errno("asprintf");
2039 2c251c14 2020-01-15 tracey /* get action and set function */
2040 f1200fe3 2020-02-13 tracey if ((p = gw_trans->gw_req->fieldmap[KEY_ACTION])) {
2041 2c251c14 2020-01-15 tracey for (i = 0; i < nitems(gw_query_funcs); i++) {
2042 2c251c14 2020-01-15 tracey action = &gw_query_funcs[i];
2043 f1200fe3 2020-02-13 tracey if (action->func_name == NULL)
2044 2c251c14 2020-01-15 tracey continue;
2045 f1200fe3 2020-02-13 tracey if (strcmp(action->func_name,
2046 f1200fe3 2020-02-13 tracey p->parsed.s) == 0) {
2047 f1200fe3 2020-02-13 tracey gw_trans->action = i;
2052 6f6f771f 2020-02-13 tracey if (gw_trans->action == -1) {
2053 6f6f771f 2020-02-13 tracey gw_trans->action = GW_ERR;
2054 8f214b62 2020-02-17 stsp gw_trans->error = got_error_msg(GOT_ERR_QUERYSTRING,
2055 8f214b62 2020-02-17 stsp p != NULL ? "bad action in querystring" :
2056 8f214b62 2020-02-17 stsp "no action in querystring");
2057 cc18a904 2020-02-13 tracey return error;
2060 26dc3004 2020-02-13 stsp if ((p = gw_trans->gw_req->fieldmap[KEY_COMMIT_ID])) {
2061 56997cd3 2020-02-14 tracey if (asprintf(&gw_trans->commit_id, "%s",
2062 88d59c36 2020-01-29 stsp p->parsed.s) == -1)
2063 ec46ccd7 2020-01-15 tracey return got_error_from_errno("asprintf");
2066 4d6abe2b 2020-02-13 stsp if ((p = gw_trans->gw_req->fieldmap[KEY_FILE]))
2067 4d6abe2b 2020-02-13 stsp gw_trans->repo_file = p->parsed.s;
2069 26dc3004 2020-02-13 stsp if ((p = gw_trans->gw_req->fieldmap[KEY_FOLDER])) {
2070 88d59c36 2020-01-29 stsp if (asprintf(&gw_trans->repo_folder, "%s",
2071 55e46400 2020-02-18 tracey p->parsed.s) == -1)
2072 55e46400 2020-02-18 tracey return got_error_from_errno("asprintf");
2075 55e46400 2020-02-18 tracey if ((p = gw_trans->gw_req->fieldmap[KEY_PREV_ID])) {
2076 55e46400 2020-02-18 tracey if (asprintf(&gw_trans->prev_id, "%s",
2077 55e46400 2020-02-18 tracey p->parsed.s) == -1)
2078 55e46400 2020-02-18 tracey return got_error_from_errno("asprintf");
2081 742ba378 2020-02-14 stsp if ((p = gw_trans->gw_req->fieldmap[KEY_HEADREF]))
2082 742ba378 2020-02-14 stsp gw_trans->headref = p->parsed.s;
2084 4619e1f2 2020-02-13 stsp error = gw_init_gw_dir(&gw_trans->gw_dir, gw_trans->repo_name);
2085 4619e1f2 2020-02-13 stsp if (error)
2086 4619e1f2 2020-02-13 stsp return error;
2088 cc18a904 2020-02-13 tracey gw_trans->error = gw_load_got_path(gw_trans, gw_trans->gw_dir);
2090 2c251c14 2020-01-15 tracey gw_trans->action = GW_INDEX;
2092 2c251c14 2020-01-15 tracey if ((p = gw_trans->gw_req->fieldmap[KEY_PAGE]))
2093 2c251c14 2020-01-15 tracey gw_trans->page = p->parsed.i;
2095 2c251c14 2020-01-15 tracey return error;
2098 4619e1f2 2020-02-13 stsp static const struct got_error *
2099 f652ec0c 2020-02-13 stsp gw_init_gw_dir(struct gw_dir **gw_dir, const char *dir)
2101 4619e1f2 2020-02-13 stsp const struct got_error *error;
2103 4619e1f2 2020-02-13 stsp *gw_dir = malloc(sizeof(**gw_dir));
2104 4619e1f2 2020-02-13 stsp if (*gw_dir == NULL)
2105 4619e1f2 2020-02-13 stsp return got_error_from_errno("malloc");
2107 4619e1f2 2020-02-13 stsp if (asprintf(&(*gw_dir)->name, "%s", dir) == -1) {
2108 4619e1f2 2020-02-13 stsp error = got_error_from_errno("asprintf");
2109 4619e1f2 2020-02-13 stsp free(*gw_dir);
2110 4619e1f2 2020-02-13 stsp *gw_dir = NULL;
2111 e9a8bbf7 2020-05-29 tracey return error;
2114 4619e1f2 2020-02-13 stsp return NULL;
2117 c25c2314 2020-01-28 stsp static const struct got_error *
2118 54415d85 2020-01-15 tracey gw_display_open(struct gw_trans *gw_trans, enum khttp code, enum kmime mime)
2120 795c10a4 2020-02-20 tracey enum kcgi_err kerr = KCGI_OK;
2122 c25c2314 2020-01-28 stsp kerr = khttp_head(gw_trans->gw_req, kresps[KRESP_ALLOW], "GET");
2123 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
2124 2447adad 2020-02-06 stsp return gw_kcgi_error(kerr);
2125 c25c2314 2020-01-28 stsp kerr = khttp_head(gw_trans->gw_req, kresps[KRESP_STATUS], "%s",
2126 2c251c14 2020-01-15 tracey khttps[code]);
2127 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
2128 2447adad 2020-02-06 stsp return gw_kcgi_error(kerr);
2129 c25c2314 2020-01-28 stsp kerr = khttp_head(gw_trans->gw_req, kresps[KRESP_CONTENT_TYPE], "%s",
2130 2c251c14 2020-01-15 tracey kmimetypes[mime]);
2131 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
2132 2447adad 2020-02-06 stsp return gw_kcgi_error(kerr);
2133 017d6da3 2020-01-29 tracey kerr = khttp_head(gw_trans->gw_req, "X-Content-Type-Options",
2134 017d6da3 2020-01-29 tracey "nosniff");
2135 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
2136 2447adad 2020-02-06 stsp return gw_kcgi_error(kerr);
2137 c25c2314 2020-01-28 stsp kerr = khttp_head(gw_trans->gw_req, "X-Frame-Options", "DENY");
2138 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
2139 2447adad 2020-02-06 stsp return gw_kcgi_error(kerr);
2140 017d6da3 2020-01-29 tracey kerr = khttp_head(gw_trans->gw_req, "X-XSS-Protection",
2141 017d6da3 2020-01-29 tracey "1; mode=block");
2142 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
2143 2447adad 2020-02-06 stsp return gw_kcgi_error(kerr);
2145 017d6da3 2020-01-29 tracey if (gw_trans->mime == KMIME_APP_OCTET_STREAM) {
2146 017d6da3 2020-01-29 tracey kerr = khttp_head(gw_trans->gw_req,
2147 017d6da3 2020-01-29 tracey kresps[KRESP_CONTENT_DISPOSITION],
2148 017d6da3 2020-01-29 tracey "attachment; filename=%s", gw_trans->repo_file);
2149 017d6da3 2020-01-29 tracey if (kerr != KCGI_OK)
2150 2447adad 2020-02-06 stsp return gw_kcgi_error(kerr);
2153 c25c2314 2020-01-28 stsp kerr = khttp_body(gw_trans->gw_req);
2154 2447adad 2020-02-06 stsp return gw_kcgi_error(kerr);
2157 c25c2314 2020-01-28 stsp static const struct got_error *
2158 6d8d8a26 2020-01-29 stsp gw_display_index(struct gw_trans *gw_trans)
2160 4bec7539 2020-01-29 stsp const struct got_error *error;
2161 795c10a4 2020-02-20 tracey enum kcgi_err kerr = KCGI_OK;
2163 cc18a904 2020-02-13 tracey /* catch early querystring errors */
2164 cc18a904 2020-02-13 tracey if (gw_trans->error)
2165 cc18a904 2020-02-13 tracey gw_trans->action = GW_ERR;
2167 4bec7539 2020-01-29 stsp error = gw_display_open(gw_trans, KHTTP_200, gw_trans->mime);
2168 4bec7539 2020-01-29 stsp if (error)
2169 4bec7539 2020-01-29 stsp return error;
2171 f7cc9480 2020-02-05 tracey kerr = khtml_open(gw_trans->gw_html_req, gw_trans->gw_req, 0);
2172 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2173 2447adad 2020-02-06 stsp return gw_kcgi_error(kerr);
2175 017d6da3 2020-01-29 tracey if (gw_trans->action != GW_BLOB) {
2176 017d6da3 2020-01-29 tracey kerr = khttp_template(gw_trans->gw_req, gw_trans->gw_tmpl,
2177 017d6da3 2020-01-29 tracey gw_query_funcs[gw_trans->action].template);
2178 017d6da3 2020-01-29 tracey if (kerr != KCGI_OK) {
2179 017d6da3 2020-01-29 tracey khtml_close(gw_trans->gw_html_req);
2180 2447adad 2020-02-06 stsp return gw_kcgi_error(kerr);
2184 7a9bfbff 2020-01-29 stsp return gw_kcgi_error(khtml_close(gw_trans->gw_html_req));
2187 f1200fe3 2020-02-13 tracey static const struct got_error *
2188 f1200fe3 2020-02-13 tracey gw_error(struct gw_trans *gw_trans)
2190 795c10a4 2020-02-20 tracey enum kcgi_err kerr = KCGI_OK;
2192 f1200fe3 2020-02-13 tracey kerr = khtml_puts(gw_trans->gw_html_req, gw_trans->error->msg);
2194 f1200fe3 2020-02-13 tracey return gw_kcgi_error(kerr);
2197 2c251c14 2020-01-15 tracey static int
2198 2c251c14 2020-01-15 tracey gw_template(size_t key, void *arg)
2200 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
2201 795c10a4 2020-02-20 tracey enum kcgi_err kerr = KCGI_OK;
2202 54415d85 2020-01-15 tracey struct gw_trans *gw_trans = arg;
2203 9f6f3943 2020-09-24 tracey char *ati = NULL, *fic32 = NULL, *fic16 = NULL;
2204 9f6f3943 2020-09-24 tracey char *swm = NULL, *spt = NULL, *css = NULL, *logo = NULL;
2206 9f6f3943 2020-09-24 tracey if (asprintf(&ati, "%s%s", gw_trans->gw_conf->got_www_path,
2207 9f6f3943 2020-09-24 tracey "/apple-touch-icon.png") == -1)
2208 9f6f3943 2020-09-24 tracey goto err;
2209 9f6f3943 2020-09-24 tracey if (asprintf(&fic32, "%s%s", gw_trans->gw_conf->got_www_path,
2210 62d463ca 2020-10-20 naddy "/favicon-32x32.png") == -1)
2211 9f6f3943 2020-09-24 tracey goto err;
2212 9f6f3943 2020-09-24 tracey if (asprintf(&fic16, "%s%s", gw_trans->gw_conf->got_www_path,
2213 9f6f3943 2020-09-24 tracey "/favicon-16x16.png") == -1)
2214 9f6f3943 2020-09-24 tracey goto err;
2215 9f6f3943 2020-09-24 tracey if (asprintf(&swm, "%s%s", gw_trans->gw_conf->got_www_path,
2216 9f6f3943 2020-09-24 tracey "/site.webmanifest") == -1)
2217 9f6f3943 2020-09-24 tracey goto err;
2218 9f6f3943 2020-09-24 tracey if (asprintf(&spt, "%s%s", gw_trans->gw_conf->got_www_path,
2219 9f6f3943 2020-09-24 tracey "/safari-pinned-tab.svg") == -1)
2220 9f6f3943 2020-09-24 tracey goto err;
2221 9f6f3943 2020-09-24 tracey if (asprintf(&css, "%s%s", gw_trans->gw_conf->got_www_path,
2222 9f6f3943 2020-09-24 tracey "/gotweb.css") == -1)
2223 9f6f3943 2020-09-24 tracey goto err;
2224 9f6f3943 2020-09-24 tracey if (asprintf(&logo, "%s%s%s", gw_trans->gw_conf->got_www_path,
2225 9f6f3943 2020-09-24 tracey gw_trans->gw_conf->got_www_path ? "/" : "",
2226 9f6f3943 2020-09-24 tracey gw_trans->gw_conf->got_logo) == -1)
2227 9f6f3943 2020-09-24 tracey goto err;
2229 2c251c14 2020-01-15 tracey switch (key) {
2230 2c251c14 2020-01-15 tracey case (TEMPL_HEAD):
2231 aaed5792 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_META,
2232 1dcb8908 2020-02-12 tracey KATTR_NAME, "viewport",
2233 1dcb8908 2020-02-12 tracey KATTR_CONTENT, "initial-scale=.75, user-scalable=yes",
2234 aaed5792 2020-02-08 tracey KATTR__MAX);
2235 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
2236 bd275801 2020-02-03 tracey return 0;
2237 aaed5792 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2238 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2239 aaed5792 2020-02-08 tracey return 0;
2240 aaed5792 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_META,
2241 aaed5792 2020-02-08 tracey KATTR_CHARSET, "utf-8",
2242 aaed5792 2020-02-08 tracey KATTR__MAX);
2243 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2244 aaed5792 2020-02-08 tracey return 0;
2245 aaed5792 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2246 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2247 aaed5792 2020-02-08 tracey return 0;
2248 aaed5792 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_META,
2249 aaed5792 2020-02-08 tracey KATTR_NAME, "msapplication-TileColor",
2250 aaed5792 2020-02-08 tracey KATTR_CONTENT, "#da532c", KATTR__MAX);
2251 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2252 aaed5792 2020-02-08 tracey return 0;
2253 aaed5792 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2254 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2255 aaed5792 2020-02-08 tracey return 0;
2256 aaed5792 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_META,
2257 aaed5792 2020-02-08 tracey KATTR_NAME, "theme-color",
2258 aaed5792 2020-02-08 tracey KATTR_CONTENT, "#ffffff", KATTR__MAX);
2259 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2260 aaed5792 2020-02-08 tracey return 0;
2261 aaed5792 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2262 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2263 aaed5792 2020-02-08 tracey return 0;
2264 aaed5792 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_LINK,
2265 aaed5792 2020-02-08 tracey KATTR_REL, "apple-touch-icon", KATTR_SIZES, "180x180",
2266 9f6f3943 2020-09-24 tracey KATTR_HREF, ati, KATTR__MAX);
2267 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2268 aaed5792 2020-02-08 tracey return 0;
2269 aaed5792 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2270 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2271 aaed5792 2020-02-08 tracey return 0;
2272 aaed5792 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_LINK,
2273 aaed5792 2020-02-08 tracey KATTR_REL, "icon", KATTR_TYPE, "image/png", KATTR_SIZES,
2274 9f6f3943 2020-09-24 tracey "32x32", KATTR_HREF, fic32, KATTR__MAX);
2275 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2276 aaed5792 2020-02-08 tracey return 0;
2277 aaed5792 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2278 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2279 aaed5792 2020-02-08 tracey return 0;
2280 aaed5792 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_LINK,
2281 aaed5792 2020-02-08 tracey KATTR_REL, "icon", KATTR_TYPE, "image/png", KATTR_SIZES,
2282 9f6f3943 2020-09-24 tracey "16x16", KATTR_HREF, fic16, KATTR__MAX);
2283 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2284 aaed5792 2020-02-08 tracey return 0;
2285 aaed5792 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2286 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2287 aaed5792 2020-02-08 tracey return 0;
2288 aaed5792 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_LINK,
2289 9f6f3943 2020-09-24 tracey KATTR_REL, "manifest", KATTR_HREF, swm,
2290 aaed5792 2020-02-08 tracey KATTR__MAX);
2291 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2292 aaed5792 2020-02-08 tracey return 0;
2293 aaed5792 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2294 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2295 aaed5792 2020-02-08 tracey return 0;
2296 aaed5792 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_LINK,
2297 aaed5792 2020-02-08 tracey KATTR_REL, "mask-icon", KATTR_HREF,
2298 9f6f3943 2020-09-24 tracey spt, KATTR__MAX);
2299 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2300 aaed5792 2020-02-08 tracey return 0;
2301 aaed5792 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2302 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2303 aaed5792 2020-02-08 tracey return 0;
2304 aaed5792 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_LINK,
2305 aaed5792 2020-02-08 tracey KATTR_REL, "stylesheet", KATTR_TYPE, "text/css",
2306 9f6f3943 2020-09-24 tracey KATTR_HREF, css, KATTR__MAX);
2307 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2308 aaed5792 2020-02-08 tracey return 0;
2309 aaed5792 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2310 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2311 aaed5792 2020-02-08 tracey return 0;
2313 2c251c14 2020-01-15 tracey case(TEMPL_HEADER):
2314 185ba3ba 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2315 185ba3ba 2020-02-04 tracey KATTR_ID, "got_link", KATTR__MAX);
2316 185ba3ba 2020-02-04 tracey if (kerr != KCGI_OK)
2317 185ba3ba 2020-02-04 tracey return 0;
2318 185ba3ba 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
2319 185ba3ba 2020-02-04 tracey KATTR_HREF, gw_trans->gw_conf->got_logo_url,
2320 185ba3ba 2020-02-04 tracey KATTR_TARGET, "_sotd", KATTR__MAX);
2321 185ba3ba 2020-02-04 tracey if (kerr != KCGI_OK)
2322 185ba3ba 2020-02-04 tracey return 0;
2323 185ba3ba 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_IMG,
2324 9f6f3943 2020-09-24 tracey KATTR_SRC, logo, KATTR__MAX);
2325 9f6f3943 2020-09-24 tracey if (kerr != KCGI_OK)
2326 185ba3ba 2020-02-04 tracey return 0;
2327 185ba3ba 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 3);
2328 9f6f3943 2020-09-24 tracey if (kerr != KCGI_OK)
2329 185ba3ba 2020-02-04 tracey return 0;
2331 2c251c14 2020-01-15 tracey case (TEMPL_SITEPATH):
2332 4ae179a2 2020-02-08 tracey error = gw_output_site_link(gw_trans);
2333 4ae179a2 2020-02-08 tracey if (error)
2334 4ae179a2 2020-02-08 tracey return 0;
2336 2c251c14 2020-01-15 tracey case(TEMPL_TITLE):
2337 bd275801 2020-02-03 tracey if (gw_trans->gw_conf->got_site_name != NULL) {
2338 bd275801 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req,
2339 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_site_name);
2340 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
2341 bd275801 2020-02-03 tracey return 0;
2344 2c251c14 2020-01-15 tracey case (TEMPL_SEARCH):
2346 63ee0dca 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
2347 63ee0dca 2020-02-08 tracey "search", KATTR__MAX);
2348 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
2349 bd275801 2020-02-03 tracey return 0;
2350 63ee0dca 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_FORM,
2351 63ee0dca 2020-02-08 tracey KATTR_METHOD, "POST", KATTR__MAX);
2352 63ee0dca 2020-02-08 tracey if (kerr != KCGI_OK)
2353 63ee0dca 2020-02-08 tracey return 0;
2354 63ee0dca 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_INPUT, KATTR_ID,
2355 63ee0dca 2020-02-08 tracey "got-search", KATTR_NAME, "got-search", KATTR_SIZE, "15",
2356 63ee0dca 2020-02-08 tracey KATTR_MAXLENGTH, "50", KATTR__MAX);
2357 63ee0dca 2020-02-08 tracey if (kerr != KCGI_OK)
2358 63ee0dca 2020-02-08 tracey return 0;
2359 63ee0dca 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_BUTTON,
2360 63ee0dca 2020-02-08 tracey KATTR__MAX);
2361 63ee0dca 2020-02-08 tracey if (kerr != KCGI_OK)
2362 63ee0dca 2020-02-08 tracey return 0;
2363 63ee0dca 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Search");
2364 63ee0dca 2020-02-08 tracey if (kerr != KCGI_OK)
2365 63ee0dca 2020-02-08 tracey return 0;
2366 63ee0dca 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 4);
2367 63ee0dca 2020-02-08 tracey if (kerr != KCGI_OK)
2368 63ee0dca 2020-02-08 tracey return 0;
2370 2c251c14 2020-01-15 tracey case(TEMPL_SITEOWNER):
2371 2c251c14 2020-01-15 tracey if (gw_trans->gw_conf->got_site_owner != NULL &&
2372 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_show_site_owner) {
2373 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2374 bd275801 2020-02-03 tracey KATTR_ID, "site_owner_wrapper", KATTR__MAX);
2375 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
2377 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2378 bd275801 2020-02-03 tracey KATTR_ID, "site_owner", KATTR__MAX);
2379 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
2380 2c251c14 2020-01-15 tracey return 0;
2381 bd275801 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req,
2382 bd275801 2020-02-03 tracey gw_trans->gw_conf->got_site_owner);
2383 bd275801 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
2384 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
2385 bd275801 2020-02-03 tracey return 0;
2388 2c251c14 2020-01-15 tracey case(TEMPL_CONTENT):
2389 2c251c14 2020-01-15 tracey error = gw_query_funcs[gw_trans->action].func_main(gw_trans);
2390 bd275801 2020-02-03 tracey if (error) {
2391 0d100d0b 2020-02-07 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2392 0d100d0b 2020-02-07 tracey KATTR_ID, "tmpl_err", KATTR__MAX);
2393 0d100d0b 2020-02-07 tracey if (kerr != KCGI_OK)
2394 0d100d0b 2020-02-07 tracey return 0;
2395 f08447b0 2020-04-14 tracey kerr = khttp_printf(gw_trans->gw_req, "Error: %s",
2396 f08447b0 2020-04-14 tracey error->msg);
2397 0d100d0b 2020-02-07 tracey if (kerr != KCGI_OK)
2398 0d100d0b 2020-02-07 tracey return 0;
2399 0d100d0b 2020-02-07 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2400 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
2401 bd275801 2020-02-03 tracey return 0;
2404 2c251c14 2020-01-15 tracey default:
2405 2c251c14 2020-01-15 tracey return 0;
2407 9f6f3943 2020-09-24 tracey free(ati);
2408 9f6f3943 2020-09-24 tracey free(fic32);
2409 9f6f3943 2020-09-24 tracey free(fic16);
2410 9f6f3943 2020-09-24 tracey free(swm);
2411 9f6f3943 2020-09-24 tracey free(spt);
2412 9f6f3943 2020-09-24 tracey free(css);
2413 9f6f3943 2020-09-24 tracey free(logo);
2414 2c251c14 2020-01-15 tracey return 1;
2416 9f6f3943 2020-09-24 tracey free(ati);
2417 9f6f3943 2020-09-24 tracey free(fic32);
2418 9f6f3943 2020-09-24 tracey free(fic16);
2419 9f6f3943 2020-09-24 tracey free(swm);
2420 9f6f3943 2020-09-24 tracey free(spt);
2421 9f6f3943 2020-09-24 tracey free(css);
2422 9f6f3943 2020-09-24 tracey free(logo);
2423 9f6f3943 2020-09-24 tracey return 0;
2426 21a55cc7 2020-02-04 tracey static const struct got_error *
2427 21a55cc7 2020-02-04 tracey gw_gen_commit_header(struct gw_trans *gw_trans, char *str1, char *str2)
2429 21a55cc7 2020-02-04 tracey const struct got_error *error = NULL;
2430 21a55cc7 2020-02-04 tracey enum kcgi_err kerr = KCGI_OK;
2432 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2433 21a55cc7 2020-02-04 tracey KATTR_ID, "header_commit_title", KATTR__MAX);
2434 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2435 21a55cc7 2020-02-04 tracey goto done;
2436 21a55cc7 2020-02-04 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Commit: ");
2437 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2438 21a55cc7 2020-02-04 tracey goto done;
2439 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2440 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2441 21a55cc7 2020-02-04 tracey goto done;
2442 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2443 21a55cc7 2020-02-04 tracey KATTR_ID, "header_commit", KATTR__MAX);
2444 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2445 21a55cc7 2020-02-04 tracey goto done;
2446 32b9f7ed 2020-04-14 tracey kerr = khtml_printf(gw_trans->gw_html_req, "%s ", str1);
2447 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2448 21a55cc7 2020-02-04 tracey goto done;
2449 5c65becf 2020-02-13 tracey if (str2 != NULL) {
2450 bf93a5c0 2020-02-15 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_SPAN,
2451 bf93a5c0 2020-02-15 tracey KATTR_ID, "refs_str", KATTR__MAX);
2452 5c65becf 2020-02-13 tracey if (kerr != KCGI_OK)
2453 5c65becf 2020-02-13 tracey goto done;
2454 32b9f7ed 2020-04-14 tracey kerr = khtml_printf(gw_trans->gw_html_req, "(%s)", str2);
2455 bf93a5c0 2020-02-15 tracey if (kerr != KCGI_OK)
2456 bf93a5c0 2020-02-15 tracey goto done;
2457 bf93a5c0 2020-02-15 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2458 5c65becf 2020-02-13 tracey if (kerr != KCGI_OK)
2459 5c65becf 2020-02-13 tracey goto done;
2461 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2463 21a55cc7 2020-02-04 tracey if (error == NULL && kerr != KCGI_OK)
2464 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
2465 21a55cc7 2020-02-04 tracey return error;
2468 f7cc9480 2020-02-05 tracey static const struct got_error *
2469 f7cc9480 2020-02-05 tracey gw_gen_diff_header(struct gw_trans *gw_trans, char *str1, char *str2)
2471 27192be7 2020-02-04 tracey const struct got_error *error = NULL;
2472 f7cc9480 2020-02-05 tracey enum kcgi_err kerr = KCGI_OK;
2474 f7cc9480 2020-02-05 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2475 f7cc9480 2020-02-05 tracey KATTR_ID, "header_diff_title", KATTR__MAX);
2476 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2477 f7cc9480 2020-02-05 tracey goto done;
2478 f7cc9480 2020-02-05 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Diff: ");
2479 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2480 f7cc9480 2020-02-05 tracey goto done;
2481 f7cc9480 2020-02-05 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2482 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2483 f7cc9480 2020-02-05 tracey goto done;
2484 f7cc9480 2020-02-05 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2485 f7cc9480 2020-02-05 tracey KATTR_ID, "header_diff", KATTR__MAX);
2486 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2487 f7cc9480 2020-02-05 tracey goto done;
2488 5c65becf 2020-02-13 tracey if (str1 != NULL) {
2489 5c65becf 2020-02-13 tracey kerr = khtml_puts(gw_trans->gw_html_req, str1);
2490 5c65becf 2020-02-13 tracey if (kerr != KCGI_OK)
2491 5c65becf 2020-02-13 tracey goto done;
2493 f7cc9480 2020-02-05 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_BR, KATTR__MAX);
2494 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2495 f7cc9480 2020-02-05 tracey goto done;
2496 f7cc9480 2020-02-05 tracey kerr = khtml_puts(gw_trans->gw_html_req, str2);
2497 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2498 f7cc9480 2020-02-05 tracey goto done;
2499 f7cc9480 2020-02-05 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2501 f7cc9480 2020-02-05 tracey if (error == NULL && kerr != KCGI_OK)
2502 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
2503 f7cc9480 2020-02-05 tracey return error;
2506 21a55cc7 2020-02-04 tracey static const struct got_error *
2507 21a55cc7 2020-02-04 tracey gw_gen_age_header(struct gw_trans *gw_trans, const char *str)
2509 21a55cc7 2020-02-04 tracey const struct got_error *error = NULL;
2510 21a55cc7 2020-02-04 tracey enum kcgi_err kerr = KCGI_OK;
2512 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2513 21a55cc7 2020-02-04 tracey KATTR_ID, "header_age_title", KATTR__MAX);
2514 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2515 21a55cc7 2020-02-04 tracey goto done;
2516 21a55cc7 2020-02-04 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Date: ");
2517 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2518 21a55cc7 2020-02-04 tracey goto done;
2519 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2520 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2521 21a55cc7 2020-02-04 tracey goto done;
2522 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2523 21a55cc7 2020-02-04 tracey KATTR_ID, "header_age", KATTR__MAX);
2524 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2525 21a55cc7 2020-02-04 tracey goto done;
2526 21a55cc7 2020-02-04 tracey kerr = khtml_puts(gw_trans->gw_html_req, str);
2527 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2528 21a55cc7 2020-02-04 tracey goto done;
2529 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2531 21a55cc7 2020-02-04 tracey if (error == NULL && kerr != KCGI_OK)
2532 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
2533 21a55cc7 2020-02-04 tracey return error;
2536 21a55cc7 2020-02-04 tracey static const struct got_error *
2537 21a55cc7 2020-02-04 tracey gw_gen_author_header(struct gw_trans *gw_trans, const char *str)
2539 21a55cc7 2020-02-04 tracey const struct got_error *error = NULL;
2540 795c10a4 2020-02-20 tracey enum kcgi_err kerr = KCGI_OK;
2542 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2543 21a55cc7 2020-02-04 tracey KATTR_ID, "header_author_title", KATTR__MAX);
2544 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2545 21a55cc7 2020-02-04 tracey goto done;
2546 21a55cc7 2020-02-04 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Author: ");
2547 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2548 21a55cc7 2020-02-04 tracey goto done;
2549 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2550 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2551 21a55cc7 2020-02-04 tracey goto done;
2552 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2553 21a55cc7 2020-02-04 tracey KATTR_ID, "header_author", KATTR__MAX);
2554 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2555 21a55cc7 2020-02-04 tracey goto done;
2556 21a55cc7 2020-02-04 tracey kerr = khtml_puts(gw_trans->gw_html_req, str);
2557 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2558 21a55cc7 2020-02-04 tracey goto done;
2559 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2561 21a55cc7 2020-02-04 tracey if (error == NULL && kerr != KCGI_OK)
2562 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
2563 21a55cc7 2020-02-04 tracey return error;
2566 21a55cc7 2020-02-04 tracey static const struct got_error *
2567 21a55cc7 2020-02-04 tracey gw_gen_committer_header(struct gw_trans *gw_trans, const char *str)
2569 21a55cc7 2020-02-04 tracey const struct got_error *error = NULL;
2570 795c10a4 2020-02-20 tracey enum kcgi_err kerr = KCGI_OK;
2572 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2573 21a55cc7 2020-02-04 tracey KATTR_ID, "header_committer_title", KATTR__MAX);
2574 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2575 21a55cc7 2020-02-04 tracey goto done;
2576 87ca24ac 2020-02-04 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Committer: ");
2577 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2578 21a55cc7 2020-02-04 tracey goto done;
2579 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2580 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2581 21a55cc7 2020-02-04 tracey goto done;
2582 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2583 21a55cc7 2020-02-04 tracey KATTR_ID, "header_committer", KATTR__MAX);
2584 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2585 21a55cc7 2020-02-04 tracey goto done;
2586 21a55cc7 2020-02-04 tracey kerr = khtml_puts(gw_trans->gw_html_req, str);
2587 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2588 21a55cc7 2020-02-04 tracey goto done;
2589 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2591 21a55cc7 2020-02-04 tracey if (error == NULL && kerr != KCGI_OK)
2592 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
2593 21a55cc7 2020-02-04 tracey return error;
2596 f7cc9480 2020-02-05 tracey static const struct got_error *
2597 f7cc9480 2020-02-05 tracey gw_gen_commit_msg_header(struct gw_trans *gw_trans, char *str)
2599 27192be7 2020-02-04 tracey const struct got_error *error = NULL;
2600 795c10a4 2020-02-20 tracey enum kcgi_err kerr = KCGI_OK;
2602 f7cc9480 2020-02-05 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2603 f7cc9480 2020-02-05 tracey KATTR_ID, "header_commit_msg_title", KATTR__MAX);
2604 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2605 f7cc9480 2020-02-05 tracey goto done;
2606 f7cc9480 2020-02-05 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Message: ");
2607 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2608 f7cc9480 2020-02-05 tracey goto done;
2609 f7cc9480 2020-02-05 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2610 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2611 f7cc9480 2020-02-05 tracey goto done;
2612 f7cc9480 2020-02-05 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2613 f7cc9480 2020-02-05 tracey KATTR_ID, "header_commit_msg", KATTR__MAX);
2614 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2615 f7cc9480 2020-02-05 tracey goto done;
2616 f7cc9480 2020-02-05 tracey kerr = khttp_puts(gw_trans->gw_req, str);
2617 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2618 f7cc9480 2020-02-05 tracey goto done;
2619 f7cc9480 2020-02-05 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2621 f7cc9480 2020-02-05 tracey if (error == NULL && kerr != KCGI_OK)
2622 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
2623 f7cc9480 2020-02-05 tracey return error;
2626 f7cc9480 2020-02-05 tracey static const struct got_error *
2627 f7cc9480 2020-02-05 tracey gw_gen_tree_header(struct gw_trans *gw_trans, char *str)
2629 f7cc9480 2020-02-05 tracey const struct got_error *error = NULL;
2630 795c10a4 2020-02-20 tracey enum kcgi_err kerr = KCGI_OK;
2632 f7cc9480 2020-02-05 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2633 f7cc9480 2020-02-05 tracey KATTR_ID, "header_tree_title", KATTR__MAX);
2634 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2635 f7cc9480 2020-02-05 tracey goto done;
2636 f7cc9480 2020-02-05 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Tree: ");
2637 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2638 f7cc9480 2020-02-05 tracey goto done;
2639 f7cc9480 2020-02-05 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2640 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2641 f7cc9480 2020-02-05 tracey goto done;
2642 f7cc9480 2020-02-05 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2643 f7cc9480 2020-02-05 tracey KATTR_ID, "header_tree", KATTR__MAX);
2644 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2645 f7cc9480 2020-02-05 tracey goto done;
2646 f7cc9480 2020-02-05 tracey kerr = khtml_puts(gw_trans->gw_html_req, str);
2647 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2648 f7cc9480 2020-02-05 tracey goto done;
2649 f7cc9480 2020-02-05 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2651 f7cc9480 2020-02-05 tracey if (error == NULL && kerr != KCGI_OK)
2652 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
2653 f7cc9480 2020-02-05 tracey return error;
2656 32cd4d18 2020-02-03 stsp static const struct got_error *
2657 32cd4d18 2020-02-03 stsp gw_get_repo_description(char **description, struct gw_trans *gw_trans,
2658 32cd4d18 2020-02-03 stsp char *dir)
2660 32cd4d18 2020-02-03 stsp const struct got_error *error = NULL;
2661 b8b04565 2020-02-02 tracey FILE *f = NULL;
2662 32cd4d18 2020-02-03 stsp char *d_file = NULL;
2663 2c251c14 2020-01-15 tracey unsigned int len;
2666 32cd4d18 2020-02-03 stsp *description = NULL;
2667 0b20762b 2020-01-29 stsp if (gw_trans->gw_conf->got_show_repo_description == 0)
2668 a942aa37 2020-02-10 tracey return NULL;
2670 88d59c36 2020-01-29 stsp if (asprintf(&d_file, "%s/description", dir) == -1)
2671 32cd4d18 2020-02-03 stsp return got_error_from_errno("asprintf");
2673 32cd4d18 2020-02-03 stsp f = fopen(d_file, "r");
2674 32cd4d18 2020-02-03 stsp if (f == NULL) {
2675 32cd4d18 2020-02-03 stsp if (errno == ENOENT || errno == EACCES)
2676 a942aa37 2020-02-10 tracey return NULL;
2677 32cd4d18 2020-02-03 stsp error = got_error_from_errno2("fopen", d_file);
2678 32cd4d18 2020-02-03 stsp goto done;
2681 32cd4d18 2020-02-03 stsp if (fseek(f, 0, SEEK_END) == -1) {
2682 32cd4d18 2020-02-03 stsp error = got_ferror(f, GOT_ERR_IO);
2683 32cd4d18 2020-02-03 stsp goto done;
2685 32cd4d18 2020-02-03 stsp len = ftell(f);
2686 32cd4d18 2020-02-03 stsp if (len == -1) {
2687 32cd4d18 2020-02-03 stsp error = got_ferror(f, GOT_ERR_IO);
2688 32cd4d18 2020-02-03 stsp goto done;
2690 32cd4d18 2020-02-03 stsp if (fseek(f, 0, SEEK_SET) == -1) {
2691 32cd4d18 2020-02-03 stsp error = got_ferror(f, GOT_ERR_IO);
2692 32cd4d18 2020-02-03 stsp goto done;
2694 32cd4d18 2020-02-03 stsp *description = calloc(len + 1, sizeof(**description));
2695 32cd4d18 2020-02-03 stsp if (*description == NULL) {
2696 32cd4d18 2020-02-03 stsp error = got_error_from_errno("calloc");
2697 32cd4d18 2020-02-03 stsp goto done;
2700 32cd4d18 2020-02-03 stsp n = fread(*description, 1, len, f);
2701 1ab830c1 2020-02-03 stsp if (n == 0 && ferror(f))
2702 32cd4d18 2020-02-03 stsp error = got_ferror(f, GOT_ERR_IO);
2704 56b63ca4 2021-01-22 stsp if (f != NULL && fclose(f) == EOF && error == NULL)
2705 32cd4d18 2020-02-03 stsp error = got_error_from_errno("fclose");
2706 2c251c14 2020-01-15 tracey free(d_file);
2707 32cd4d18 2020-02-03 stsp return error;
2710 55ccf528 2020-02-03 stsp static const struct got_error *
2711 55ccf528 2020-02-03 stsp gw_get_time_str(char **repo_age, time_t committer_time, int ref_tm)
2713 474370cb 2020-01-15 tracey struct tm tm;
2714 474370cb 2020-01-15 tracey time_t diff_time;
2715 474370cb 2020-01-15 tracey char *years = "years ago", *months = "months ago";
2716 474370cb 2020-01-15 tracey char *weeks = "weeks ago", *days = "days ago", *hours = "hours ago";
2717 474370cb 2020-01-15 tracey char *minutes = "minutes ago", *seconds = "seconds ago";
2718 474370cb 2020-01-15 tracey char *now = "right now";
2720 6c6c85af 2020-01-15 tracey char datebuf[29];
2722 55ccf528 2020-02-03 stsp *repo_age = NULL;
2724 474370cb 2020-01-15 tracey switch (ref_tm) {
2725 474370cb 2020-01-15 tracey case TM_DIFF:
2726 474370cb 2020-01-15 tracey diff_time = time(NULL) - committer_time;
2727 474370cb 2020-01-15 tracey if (diff_time > 60 * 60 * 24 * 365 * 2) {
2728 55ccf528 2020-02-03 stsp if (asprintf(repo_age, "%lld %s",
2729 88d59c36 2020-01-29 stsp (diff_time / 60 / 60 / 24 / 365), years) == -1)
2730 55ccf528 2020-02-03 stsp return got_error_from_errno("asprintf");
2731 474370cb 2020-01-15 tracey } else if (diff_time > 60 * 60 * 24 * (365 / 12) * 2) {
2732 55ccf528 2020-02-03 stsp if (asprintf(repo_age, "%lld %s",
2733 474370cb 2020-01-15 tracey (diff_time / 60 / 60 / 24 / (365 / 12)),
2734 88d59c36 2020-01-29 stsp months) == -1)
2735 55ccf528 2020-02-03 stsp return got_error_from_errno("asprintf");
2736 474370cb 2020-01-15 tracey } else if (diff_time > 60 * 60 * 24 * 7 * 2) {
2737 55ccf528 2020-02-03 stsp if (asprintf(repo_age, "%lld %s",
2738 88d59c36 2020-01-29 stsp (diff_time / 60 / 60 / 24 / 7), weeks) == -1)
2739 55ccf528 2020-02-03 stsp return got_error_from_errno("asprintf");
2740 474370cb 2020-01-15 tracey } else if (diff_time > 60 * 60 * 24 * 2) {
2741 55ccf528 2020-02-03 stsp if (asprintf(repo_age, "%lld %s",
2742 88d59c36 2020-01-29 stsp (diff_time / 60 / 60 / 24), days) == -1)
2743 55ccf528 2020-02-03 stsp return got_error_from_errno("asprintf");
2744 474370cb 2020-01-15 tracey } else if (diff_time > 60 * 60 * 2) {
2745 55ccf528 2020-02-03 stsp if (asprintf(repo_age, "%lld %s",
2746 88d59c36 2020-01-29 stsp (diff_time / 60 / 60), hours) == -1)
2747 55ccf528 2020-02-03 stsp return got_error_from_errno("asprintf");
2748 474370cb 2020-01-15 tracey } else if (diff_time > 60 * 2) {
2749 55ccf528 2020-02-03 stsp if (asprintf(repo_age, "%lld %s", (diff_time / 60),
2750 88d59c36 2020-01-29 stsp minutes) == -1)
2751 55ccf528 2020-02-03 stsp return got_error_from_errno("asprintf");
2752 474370cb 2020-01-15 tracey } else if (diff_time > 2) {
2753 55ccf528 2020-02-03 stsp if (asprintf(repo_age, "%lld %s", diff_time,
2754 88d59c36 2020-01-29 stsp seconds) == -1)
2755 55ccf528 2020-02-03 stsp return got_error_from_errno("asprintf");
2756 474370cb 2020-01-15 tracey } else {
2757 55ccf528 2020-02-03 stsp if (asprintf(repo_age, "%s", now) == -1)
2758 55ccf528 2020-02-03 stsp return got_error_from_errno("asprintf");
2761 474370cb 2020-01-15 tracey case TM_LONG:
2762 474370cb 2020-01-15 tracey if (gmtime_r(&committer_time, &tm) == NULL)
2763 55ccf528 2020-02-03 stsp return got_error_from_errno("gmtime_r");
2765 474370cb 2020-01-15 tracey s = asctime_r(&tm, datebuf);
2766 474370cb 2020-01-15 tracey if (s == NULL)
2767 55ccf528 2020-02-03 stsp return got_error_from_errno("asctime_r");
2769 55ccf528 2020-02-03 stsp if (asprintf(repo_age, "%s UTC", datebuf) == -1)
2770 55ccf528 2020-02-03 stsp return got_error_from_errno("asprintf");
2773 55ccf528 2020-02-03 stsp return NULL;
2776 d126c1b7 2020-01-29 stsp static const struct got_error *
2777 d126c1b7 2020-01-29 stsp gw_get_repo_age(char **repo_age, struct gw_trans *gw_trans, char *dir,
2778 2011c142 2020-02-14 stsp const char *refname, int ref_tm)
2780 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
2781 2c251c14 2020-01-15 tracey struct got_repository *repo = NULL;
2782 2c251c14 2020-01-15 tracey struct got_commit_object *commit = NULL;
2783 2c251c14 2020-01-15 tracey struct got_reflist_head refs;
2784 2c251c14 2020-01-15 tracey struct got_reflist_entry *re;
2785 474370cb 2020-01-15 tracey time_t committer_time = 0, cmp_time = 0;
2787 d126c1b7 2020-01-29 stsp *repo_age = NULL;
2788 d9dff0e5 2020-12-26 stsp TAILQ_INIT(&refs);
2790 55ccf528 2020-02-03 stsp if (gw_trans->gw_conf->got_show_repo_age == 0)
2791 d126c1b7 2020-01-29 stsp return NULL;
2793 deac617c 2020-02-14 tracey if (gw_trans->repo)
2794 deac617c 2020-02-14 tracey repo = gw_trans->repo;
2796 deac617c 2020-02-14 tracey error = got_repo_open(&repo, dir, NULL);
2797 deac617c 2020-02-14 tracey if (error)
2798 deac617c 2020-02-14 tracey return error;
2801 2011c142 2020-02-14 stsp error = got_ref_list(&refs, repo, "refs/heads",
2802 2011c142 2020-02-14 stsp got_ref_cmp_by_name, NULL);
2803 ec46ccd7 2020-01-15 tracey if (error)
2804 d126c1b7 2020-01-29 stsp goto done;
2807 2011c142 2020-02-14 stsp * Find the youngest branch tip in the repository, or the age of
2808 2011c142 2020-02-14 stsp * the a specific branch tip if a name was provided by the caller.
2810 d9dff0e5 2020-12-26 stsp TAILQ_FOREACH(re, &refs, entry) {
2811 2011c142 2020-02-14 stsp struct got_object_id *id = NULL;
2813 2011c142 2020-02-14 stsp if (refname && strcmp(got_ref_get_name(re->ref), refname) != 0)
2816 2011c142 2020-02-14 stsp error = got_ref_resolve(&id, repo, re->ref);
2817 ec46ccd7 2020-01-15 tracey if (error)
2818 d126c1b7 2020-01-29 stsp goto done;
2820 2c251c14 2020-01-15 tracey error = got_object_open_as_commit(&commit, repo, id);
2822 ec46ccd7 2020-01-15 tracey if (error)
2823 d126c1b7 2020-01-29 stsp goto done;
2825 2c251c14 2020-01-15 tracey committer_time =
2826 2c251c14 2020-01-15 tracey got_object_commit_get_committer_time(commit);
2827 2011c142 2020-02-14 stsp got_object_commit_close(commit);
2828 387a29ba 2020-01-15 tracey if (cmp_time < committer_time)
2829 2c251c14 2020-01-15 tracey cmp_time = committer_time;
2831 2011c142 2020-02-14 stsp if (refname)
2835 474370cb 2020-01-15 tracey if (cmp_time != 0) {
2836 2c251c14 2020-01-15 tracey committer_time = cmp_time;
2837 55ccf528 2020-02-03 stsp error = gw_get_time_str(repo_age, committer_time, ref_tm);
2840 2c251c14 2020-01-15 tracey got_ref_list_free(&refs);
2841 1d0f4054 2021-06-17 stsp if (gw_trans->repo == NULL) {
2842 1d0f4054 2021-06-17 stsp const struct got_error *close_err = got_repo_close(repo);
2843 1d0f4054 2021-06-17 stsp if (error == NULL)
2844 1d0f4054 2021-06-17 stsp error = close_err;
2846 d126c1b7 2020-01-29 stsp return error;
2849 83eb9a68 2020-02-03 stsp static const struct got_error *
2850 38b240fb 2020-02-06 tracey gw_output_diff(struct gw_trans *gw_trans, struct gw_header *header)
2852 ec46ccd7 2020-01-15 tracey const struct got_error *error;
2853 ec46ccd7 2020-01-15 tracey FILE *f = NULL;
2854 ec46ccd7 2020-01-15 tracey struct got_object_id *id1 = NULL, *id2 = NULL;
2855 f7cc9480 2020-02-05 tracey char *label1 = NULL, *label2 = NULL, *line = NULL;
2856 05ce9a79 2020-01-24 tracey int obj_type;
2857 f7cc9480 2020-02-05 tracey size_t linesize = 0;
2858 83eb9a68 2020-02-03 stsp ssize_t linelen;
2859 f7cc9480 2020-02-05 tracey enum kcgi_err kerr = KCGI_OK;
2861 ec46ccd7 2020-01-15 tracey f = got_opentemp();
2862 ec46ccd7 2020-01-15 tracey if (f == NULL)
2863 ec46ccd7 2020-01-15 tracey return NULL;
2865 5c65becf 2020-02-13 tracey if (header->parent_id != NULL &&
2866 5c65becf 2020-02-13 tracey strncmp(header->parent_id, "/dev/null", 9) != 0) {
2867 05ce9a79 2020-01-24 tracey error = got_repo_match_object_id(&id1, &label1,
2868 84de9106 2020-12-26 stsp header->parent_id, GOT_OBJ_TYPE_ANY,
2869 84de9106 2020-12-26 stsp &header->refs, gw_trans->repo);
2870 05ce9a79 2020-01-24 tracey if (error)
2871 05ce9a79 2020-01-24 tracey goto done;
2874 90f16cb8 2020-01-24 tracey error = got_repo_match_object_id(&id2, &label2,
2875 84de9106 2020-12-26 stsp header->commit_id, GOT_OBJ_TYPE_ANY, &header->refs,
2876 84de9106 2020-12-26 stsp gw_trans->repo);
2877 90f16cb8 2020-01-24 tracey if (error)
2878 90f16cb8 2020-01-24 tracey goto done;
2880 deac617c 2020-02-14 tracey error = got_object_get_type(&obj_type, gw_trans->repo, id2);
2881 90f16cb8 2020-01-24 tracey if (error)
2882 90f16cb8 2020-01-24 tracey goto done;
2883 05ce9a79 2020-01-24 tracey switch (obj_type) {
2884 ec46ccd7 2020-01-15 tracey case GOT_OBJ_TYPE_BLOB:
2885 c9d2b263 2020-11-11 stsp error = got_diff_objects_as_blobs(NULL, NULL, id1, id2,
2886 22c0f09d 2020-11-22 stsp NULL, NULL, 3, 0, 0, gw_trans->repo, f);
2888 ec46ccd7 2020-01-15 tracey case GOT_OBJ_TYPE_TREE:
2889 c9d2b263 2020-11-11 stsp error = got_diff_objects_as_trees(NULL, NULL, id1, id2,
2890 22c0f09d 2020-11-22 stsp "", "", 3, 0, 0, gw_trans->repo, f);
2892 ec46ccd7 2020-01-15 tracey case GOT_OBJ_TYPE_COMMIT:
2893 22c0f09d 2020-11-22 stsp error = got_diff_objects_as_commits(NULL, NULL, id1, id2,
2894 22c0f09d 2020-11-22 stsp 3, 0, 0, gw_trans->repo, f);
2896 ec46ccd7 2020-01-15 tracey default:
2897 ec46ccd7 2020-01-15 tracey error = got_error(GOT_ERR_OBJ_TYPE);
2899 b8b04565 2020-02-02 tracey if (error)
2900 b8b04565 2020-02-02 tracey goto done;
2902 d4729381 2020-02-03 stsp if (fseek(f, 0, SEEK_SET) == -1) {
2903 d4729381 2020-02-03 stsp error = got_ferror(f, GOT_ERR_IO);
2904 ec46ccd7 2020-01-15 tracey goto done;
2907 83eb9a68 2020-02-03 stsp while ((linelen = getline(&line, &linesize, f)) != -1) {
2908 f7cc9480 2020-02-05 tracey error = gw_colordiff_line(gw_trans, line);
2909 ec46ccd7 2020-01-15 tracey if (error)
2910 b8b04565 2020-02-02 tracey goto done;
2911 f7cc9480 2020-02-05 tracey /* XXX: KHTML_PRETTY breaks this */
2912 f7cc9480 2020-02-05 tracey kerr = khtml_puts(gw_trans->gw_html_req, line);
2913 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2914 83eb9a68 2020-02-03 stsp goto done;
2915 f7cc9480 2020-02-05 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2916 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2917 b8b04565 2020-02-02 tracey goto done;
2919 f7cc9480 2020-02-05 tracey if (linelen == -1 && ferror(f))
2920 83eb9a68 2020-02-03 stsp error = got_error_from_errno("getline");
2922 56b63ca4 2021-01-22 stsp if (f && fclose(f) == EOF && error == NULL)
2923 d4729381 2020-02-03 stsp error = got_error_from_errno("fclose");
2924 d4729381 2020-02-03 stsp free(line);
2925 ec46ccd7 2020-01-15 tracey free(label1);
2926 ec46ccd7 2020-01-15 tracey free(label2);
2927 ec46ccd7 2020-01-15 tracey free(id1);
2928 ec46ccd7 2020-01-15 tracey free(id2);
2930 f7cc9480 2020-02-05 tracey if (error == NULL && kerr != KCGI_OK)
2931 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
2932 83eb9a68 2020-02-03 stsp return error;
2935 9a1cc63f 2020-02-03 stsp static const struct got_error *
2936 9a1cc63f 2020-02-03 stsp gw_get_repo_owner(char **owner, struct gw_trans *gw_trans, char *dir)
2938 1d0f4054 2021-06-17 stsp const struct got_error *error = NULL, *close_err;
2939 9a1cc63f 2020-02-03 stsp struct got_repository *repo;
2940 9a1cc63f 2020-02-03 stsp const char *gitconfig_owner;
2942 9a1cc63f 2020-02-03 stsp *owner = NULL;
2944 9a1cc63f 2020-02-03 stsp if (gw_trans->gw_conf->got_show_repo_owner == 0)
2945 9a1cc63f 2020-02-03 stsp return NULL;
2947 9a1cc63f 2020-02-03 stsp error = got_repo_open(&repo, dir, NULL);
2948 9a1cc63f 2020-02-03 stsp if (error)
2949 9a1cc63f 2020-02-03 stsp return error;
2950 9a1cc63f 2020-02-03 stsp gitconfig_owner = got_repo_get_gitconfig_owner(repo);
2951 d1635ae4 2020-02-13 tracey if (gitconfig_owner) {
2952 d1635ae4 2020-02-13 tracey *owner = strdup(gitconfig_owner);
2953 d1635ae4 2020-02-13 tracey if (*owner == NULL)
2954 d1635ae4 2020-02-13 tracey error = got_error_from_errno("strdup");
2956 1d0f4054 2021-06-17 stsp close_err = got_repo_close(repo);
2957 1d0f4054 2021-06-17 stsp if (error == NULL)
2958 1d0f4054 2021-06-17 stsp error = close_err;
2959 9a1cc63f 2020-02-03 stsp return error;
2962 59d3c40e 2020-02-03 stsp static const struct got_error *
2963 59d3c40e 2020-02-03 stsp gw_get_clone_url(char **url, struct gw_trans *gw_trans, char *dir)
2965 59d3c40e 2020-02-03 stsp const struct got_error *error = NULL;
2966 2c251c14 2020-01-15 tracey FILE *f;
2967 59d3c40e 2020-02-03 stsp char *d_file = NULL;
2968 2c251c14 2020-01-15 tracey unsigned int len;
2971 59d3c40e 2020-02-03 stsp *url = NULL;
2973 59d3c40e 2020-02-03 stsp if (asprintf(&d_file, "%s/cloneurl", dir) == -1)
2974 59d3c40e 2020-02-03 stsp return got_error_from_errno("asprintf");
2976 59d3c40e 2020-02-03 stsp f = fopen(d_file, "r");
2977 59d3c40e 2020-02-03 stsp if (f == NULL) {
2978 59d3c40e 2020-02-03 stsp if (errno != ENOENT && errno != EACCES)
2979 59d3c40e 2020-02-03 stsp error = got_error_from_errno2("fopen", d_file);
2980 59d3c40e 2020-02-03 stsp goto done;
2983 59d3c40e 2020-02-03 stsp if (fseek(f, 0, SEEK_END) == -1) {
2984 59d3c40e 2020-02-03 stsp error = got_ferror(f, GOT_ERR_IO);
2985 59d3c40e 2020-02-03 stsp goto done;
2987 59d3c40e 2020-02-03 stsp len = ftell(f);
2988 59d3c40e 2020-02-03 stsp if (len == -1) {
2989 59d3c40e 2020-02-03 stsp error = got_ferror(f, GOT_ERR_IO);
2990 59d3c40e 2020-02-03 stsp goto done;
2992 59d3c40e 2020-02-03 stsp if (fseek(f, 0, SEEK_SET) == -1) {
2993 59d3c40e 2020-02-03 stsp error = got_ferror(f, GOT_ERR_IO);
2994 59d3c40e 2020-02-03 stsp goto done;
2997 59d3c40e 2020-02-03 stsp *url = calloc(len + 1, sizeof(**url));
2998 59d3c40e 2020-02-03 stsp if (*url == NULL) {
2999 59d3c40e 2020-02-03 stsp error = got_error_from_errno("calloc");
3000 59d3c40e 2020-02-03 stsp goto done;
3003 59d3c40e 2020-02-03 stsp n = fread(*url, 1, len, f);
3004 59d3c40e 2020-02-03 stsp if (n == 0 && ferror(f))
3005 59d3c40e 2020-02-03 stsp error = got_ferror(f, GOT_ERR_IO);
3007 56b63ca4 2021-01-22 stsp if (f && fclose(f) == EOF && error == NULL)
3008 59d3c40e 2020-02-03 stsp error = got_error_from_errno("fclose");
3009 2c251c14 2020-01-15 tracey free(d_file);
3010 59d3c40e 2020-02-03 stsp return NULL;
3013 6eccd105 2020-02-03 stsp static const struct got_error *
3014 38b240fb 2020-02-06 tracey gw_output_repo_tags(struct gw_trans *gw_trans, struct gw_header *header,
3015 38b240fb 2020-02-06 tracey int limit, int tag_type)
3017 87f9ebf5 2020-01-15 tracey const struct got_error *error = NULL;
3018 87f9ebf5 2020-01-15 tracey struct got_reflist_head refs;
3019 87f9ebf5 2020-01-15 tracey struct got_reflist_entry *re;
3020 38b240fb 2020-02-06 tracey char *age = NULL;
3021 ef2c200c 2020-02-07 tracey char *id_str = NULL, *newline, *href_commits = NULL;
3022 38b240fb 2020-02-06 tracey char *tag_commit0 = NULL, *href_tag = NULL, *href_briefs = NULL;
3023 6eccd105 2020-02-03 stsp struct got_tag_object *tag = NULL;
3024 38b240fb 2020-02-06 tracey enum kcgi_err kerr = KCGI_OK;
3025 5a911940 2021-06-25 tracey int summary_header_displayed = 0, chk_next = 0;
3026 5a911940 2021-06-25 tracey int tag_count = 0, commit_found = 0, c_cnt = 0;
3028 d9dff0e5 2020-12-26 stsp TAILQ_INIT(&refs);
3030 deac617c 2020-02-14 tracey error = got_ref_list(&refs, gw_trans->repo, "refs/tags",
3031 deac617c 2020-02-14 tracey got_ref_cmp_tags, gw_trans->repo);
3032 ec46ccd7 2020-01-15 tracey if (error)
3033 87f9ebf5 2020-01-15 tracey goto done;
3035 d9dff0e5 2020-12-26 stsp TAILQ_FOREACH(re, &refs, entry) {
3036 87f9ebf5 2020-01-15 tracey const char *refname;
3037 4ff7391f 2020-01-28 tracey const char *tagger;
3038 6eccd105 2020-02-03 stsp const char *tag_commit;
3039 87f9ebf5 2020-01-15 tracey time_t tagger_time;
3040 87f9ebf5 2020-01-15 tracey struct got_object_id *id;
3041 ef2c200c 2020-02-07 tracey struct got_commit_object *commit = NULL;
3043 87f9ebf5 2020-01-15 tracey refname = got_ref_get_name(re->ref);
3044 87f9ebf5 2020-01-15 tracey if (strncmp(refname, "refs/tags/", 10) != 0)