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 *next_prev_id;
71 55e46400 2020-02-18 tracey char *prev_id;
72 55e46400 2020-02-18 tracey char *prev_prev_id;
73 4d6abe2b 2020-02-13 stsp const char *repo_file;
74 ec46ccd7 2020-01-15 tracey char *repo_folder;
75 742ba378 2020-02-14 stsp const char *headref;
76 2c251c14 2020-01-15 tracey unsigned int action;
77 2c251c14 2020-01-15 tracey unsigned int page;
78 2c251c14 2020-01-15 tracey unsigned int repos_total;
79 387a29ba 2020-01-15 tracey enum kmime mime;
82 f2f46662 2020-01-23 tracey struct gw_header {
83 f2f46662 2020-01-23 tracey TAILQ_ENTRY(gw_header) entry;
84 f2f46662 2020-01-23 tracey struct got_reflist_head refs;
85 f2f46662 2020-01-23 tracey char *path;
87 f2f46662 2020-01-23 tracey char *refs_str;
88 f2f46662 2020-01-23 tracey char *commit_id; /* id_str1 */
89 f2f46662 2020-01-23 tracey char *parent_id; /* id_str2 */
90 f2f46662 2020-01-23 tracey char *tree_id;
91 4e8d6e3e 2020-02-14 tracey char *author;
92 4e8d6e3e 2020-02-14 tracey char *committer;
93 f2f46662 2020-01-23 tracey char *commit_msg;
94 f2f46662 2020-01-23 tracey time_t committer_time;
97 2c251c14 2020-01-15 tracey struct gw_dir {
98 2c251c14 2020-01-15 tracey TAILQ_ENTRY(gw_dir) entry;
99 2c251c14 2020-01-15 tracey char *name;
100 2c251c14 2020-01-15 tracey char *owner;
101 2c251c14 2020-01-15 tracey char *description;
102 2c251c14 2020-01-15 tracey char *url;
103 2c251c14 2020-01-15 tracey char *age;
104 2c251c14 2020-01-15 tracey char *path;
107 f2f46662 2020-01-23 tracey enum gw_key {
108 f2f46662 2020-01-23 tracey KEY_ACTION,
109 f2f46662 2020-01-23 tracey KEY_COMMIT_ID,
110 f2f46662 2020-01-23 tracey KEY_FILE,
111 f2f46662 2020-01-23 tracey KEY_FOLDER,
112 f2f46662 2020-01-23 tracey KEY_HEADREF,
113 f2f46662 2020-01-23 tracey KEY_PAGE,
114 f2f46662 2020-01-23 tracey KEY_PATH,
115 55e46400 2020-02-18 tracey KEY_PREV_ID,
116 55e46400 2020-02-18 tracey KEY_PREV_PREV_ID,
117 f2f46662 2020-01-23 tracey KEY__ZMAX
120 54415d85 2020-01-15 tracey enum gw_tmpl {
121 f2f46662 2020-01-23 tracey TEMPL_CONTENT,
122 2c251c14 2020-01-15 tracey TEMPL_HEAD,
123 2c251c14 2020-01-15 tracey TEMPL_HEADER,
124 f2f46662 2020-01-23 tracey TEMPL_SEARCH,
125 2c251c14 2020-01-15 tracey TEMPL_SITEPATH,
126 2c251c14 2020-01-15 tracey TEMPL_SITEOWNER,
127 2c251c14 2020-01-15 tracey TEMPL_TITLE,
128 2c251c14 2020-01-15 tracey TEMPL__MAX
131 54415d85 2020-01-15 tracey enum gw_ref_tm {
136 ff4bb25f 2020-02-19 tracey enum gw_tags_type {
137 87f9ebf5 2020-01-15 tracey TAGBRIEF,
141 54415d85 2020-01-15 tracey static const char *const gw_templs[TEMPL__MAX] = {
142 f2f46662 2020-01-23 tracey "content",
144 2c251c14 2020-01-15 tracey "header",
145 f2f46662 2020-01-23 tracey "search",
146 2c251c14 2020-01-15 tracey "sitepath",
147 2c251c14 2020-01-15 tracey "siteowner",
151 ec46ccd7 2020-01-15 tracey static const struct kvalid gw_keys[KEY__ZMAX] = {
152 2c251c14 2020-01-15 tracey { kvalid_stringne, "action" },
153 2c251c14 2020-01-15 tracey { kvalid_stringne, "commit" },
154 2c251c14 2020-01-15 tracey { kvalid_stringne, "file" },
155 ec46ccd7 2020-01-15 tracey { kvalid_stringne, "folder" },
156 8087c3c5 2020-01-15 tracey { kvalid_stringne, "headref" },
157 ec46ccd7 2020-01-15 tracey { kvalid_int, "page" },
158 ec46ccd7 2020-01-15 tracey { kvalid_stringne, "path" },
159 55e46400 2020-02-18 tracey { kvalid_stringne, "prev" },
160 55e46400 2020-02-18 tracey { kvalid_stringne, "prev_prev" },
163 f2f46662 2020-01-23 tracey static struct gw_header *gw_init_header(void);
165 b0a1bc86 2020-02-14 stsp static void gw_free_header(struct gw_header *);
167 00f13350 2020-02-10 tracey static int gw_template(size_t, void *);
169 f1200fe3 2020-02-13 tracey static const struct got_error *gw_error(struct gw_trans *);
170 f1200fe3 2020-02-13 tracey static const struct got_error *gw_init_gw_dir(struct gw_dir **, const char *);
171 185ba3ba 2020-02-04 tracey static const struct got_error *gw_get_repo_description(char **,
172 185ba3ba 2020-02-04 tracey struct gw_trans *, char *);
173 9a1cc63f 2020-02-03 stsp static const struct got_error *gw_get_repo_owner(char **, struct gw_trans *,
175 55ccf528 2020-02-03 stsp static const struct got_error *gw_get_time_str(char **, time_t, int);
176 d126c1b7 2020-01-29 stsp static const struct got_error *gw_get_repo_age(char **, struct gw_trans *,
177 2011c142 2020-02-14 stsp char *, const char *, int);
178 84de9106 2020-12-26 stsp static const struct got_error *gw_output_file_blame(struct gw_trans *,
179 84de9106 2020-12-26 stsp struct gw_header *);
180 84de9106 2020-12-26 stsp static const struct got_error *gw_output_blob_buf(struct gw_trans *,
181 84de9106 2020-12-26 stsp struct gw_header *);
182 84de9106 2020-12-26 stsp static const struct got_error *gw_output_repo_tree(struct gw_trans *,
183 84de9106 2020-12-26 stsp struct gw_header *);
184 38b240fb 2020-02-06 tracey static const struct got_error *gw_output_diff(struct gw_trans *,
185 f2f46662 2020-01-23 tracey struct gw_header *);
186 38b240fb 2020-02-06 tracey static const struct got_error *gw_output_repo_tags(struct gw_trans *,
187 4ff7391f 2020-01-28 tracey struct gw_header *, int, int);
188 9eed6f10 2020-02-08 tracey static const struct got_error *gw_output_repo_heads(struct gw_trans *);
189 4ae179a2 2020-02-08 tracey static const struct got_error *gw_output_site_link(struct gw_trans *);
190 185ba3ba 2020-02-04 tracey static const struct got_error *gw_get_clone_url(char **, struct gw_trans *,
192 f7cc9480 2020-02-05 tracey static const struct got_error *gw_colordiff_line(struct gw_trans *, char *);
194 21a55cc7 2020-02-04 tracey static const struct got_error *gw_gen_commit_header(struct gw_trans *, char *,
196 f7cc9480 2020-02-05 tracey static const struct got_error *gw_gen_diff_header(struct gw_trans *, char *,
198 21a55cc7 2020-02-04 tracey static const struct got_error *gw_gen_author_header(struct gw_trans *,
199 21a55cc7 2020-02-04 tracey const char *);
200 21a55cc7 2020-02-04 tracey static const struct got_error *gw_gen_age_header(struct gw_trans *,
201 21a55cc7 2020-02-04 tracey const char *);
202 21a55cc7 2020-02-04 tracey static const struct got_error *gw_gen_committer_header(struct gw_trans *,
203 21a55cc7 2020-02-04 tracey const char *);
204 f7cc9480 2020-02-05 tracey static const struct got_error *gw_gen_commit_msg_header(struct gw_trans*,
206 f7cc9480 2020-02-05 tracey static const struct got_error *gw_gen_tree_header(struct gw_trans *, char *);
207 00f13350 2020-02-10 tracey static const struct got_error *gw_display_open(struct gw_trans *, enum khttp,
208 2c251c14 2020-01-15 tracey enum kmime);
209 00f13350 2020-02-10 tracey static const struct got_error *gw_display_index(struct gw_trans *);
210 00f13350 2020-02-10 tracey static const struct got_error *gw_get_header(struct gw_trans *,
211 f2f46662 2020-01-23 tracey struct gw_header *, int);
212 00f13350 2020-02-10 tracey static const struct got_error *gw_get_commits(struct gw_trans *,
213 3c245a0e 2020-02-14 tracey struct gw_header *, int,
214 3c245a0e 2020-02-14 tracey struct got_object_id *);
215 00f13350 2020-02-10 tracey static const struct got_error *gw_get_commit(struct gw_trans *,
216 4e8d6e3e 2020-02-14 tracey struct gw_header *,
217 4e8d6e3e 2020-02-14 tracey struct got_commit_object *,
218 3c245a0e 2020-02-14 tracey struct got_object_id *);
219 d4159696 2020-02-13 stsp static const struct got_error *gw_apply_unveil(const char *);
220 00f13350 2020-02-10 tracey static const struct got_error *gw_blame_cb(void *, int, int,
221 ec46ccd7 2020-01-15 tracey struct got_object_id *);
222 00f13350 2020-02-10 tracey static const struct got_error *gw_load_got_paths(struct gw_trans *);
223 00f13350 2020-02-10 tracey static const struct got_error *gw_load_got_path(struct gw_trans *,
224 2c251c14 2020-01-15 tracey struct gw_dir *);
225 00f13350 2020-02-10 tracey static const struct got_error *gw_parse_querystring(struct gw_trans *);
226 00f13350 2020-02-10 tracey static const struct got_error *gw_blame(struct gw_trans *);
227 00f13350 2020-02-10 tracey static const struct got_error *gw_blob(struct gw_trans *);
228 00f13350 2020-02-10 tracey static const struct got_error *gw_diff(struct gw_trans *);
229 00f13350 2020-02-10 tracey static const struct got_error *gw_index(struct gw_trans *);
230 00f13350 2020-02-10 tracey static const struct got_error *gw_commits(struct gw_trans *);
231 00f13350 2020-02-10 tracey static const struct got_error *gw_briefs(struct gw_trans *);
232 00f13350 2020-02-10 tracey static const struct got_error *gw_summary(struct gw_trans *);
233 00f13350 2020-02-10 tracey static const struct got_error *gw_tree(struct gw_trans *);
234 00f13350 2020-02-10 tracey static const struct got_error *gw_tag(struct gw_trans *);
235 ff4bb25f 2020-02-19 tracey static const struct got_error *gw_tags(struct gw_trans *);
237 2c251c14 2020-01-15 tracey struct gw_query_action {
238 2c251c14 2020-01-15 tracey unsigned int func_id;
239 2c251c14 2020-01-15 tracey const char *func_name;
240 54415d85 2020-01-15 tracey const struct got_error *(*func_main)(struct gw_trans *);
241 2c251c14 2020-01-15 tracey char *template;
244 2c251c14 2020-01-15 tracey enum gw_query_actions {
245 2c251c14 2020-01-15 tracey GW_BLAME,
247 f2f46662 2020-01-23 tracey GW_BRIEFS,
248 f2f46662 2020-01-23 tracey GW_COMMITS,
251 2c251c14 2020-01-15 tracey GW_INDEX,
252 2c251c14 2020-01-15 tracey GW_SUMMARY,
258 2c251c14 2020-01-15 tracey static struct gw_query_action gw_query_funcs[] = {
259 f2f46662 2020-01-23 tracey { GW_BLAME, "blame", gw_blame, "gw_tmpl/blame.tmpl" },
260 017d6da3 2020-01-29 tracey { GW_BLOB, "blob", NULL, NULL },
261 f2f46662 2020-01-23 tracey { GW_BRIEFS, "briefs", gw_briefs, "gw_tmpl/briefs.tmpl" },
262 f2f46662 2020-01-23 tracey { GW_COMMITS, "commits", gw_commits, "gw_tmpl/commit.tmpl" },
263 f2f46662 2020-01-23 tracey { GW_DIFF, "diff", gw_diff, "gw_tmpl/diff.tmpl" },
264 f1200fe3 2020-02-13 tracey { GW_ERR, "error", gw_error, "gw_tmpl/err.tmpl" },
265 f2f46662 2020-01-23 tracey { GW_INDEX, "index", gw_index, "gw_tmpl/index.tmpl" },
266 f2f46662 2020-01-23 tracey { GW_SUMMARY, "summary", gw_summary, "gw_tmpl/summry.tmpl" },
267 4ff7391f 2020-01-28 tracey { GW_TAG, "tag", gw_tag, "gw_tmpl/tag.tmpl" },
268 ff4bb25f 2020-02-19 tracey { GW_TAGS, "tags", gw_tags, "gw_tmpl/tags.tmpl" },
269 f2f46662 2020-01-23 tracey { GW_TREE, "tree", gw_tree, "gw_tmpl/tree.tmpl" },
272 5d1296de 2020-02-13 stsp static const char *
273 5d1296de 2020-02-13 stsp gw_get_action_name(struct gw_trans *gw_trans)
275 5d1296de 2020-02-13 stsp return gw_query_funcs[gw_trans->action].func_name;
278 c25c2314 2020-01-28 stsp static const struct got_error *
279 c25c2314 2020-01-28 stsp gw_kcgi_error(enum kcgi_err kerr)
281 c25c2314 2020-01-28 stsp if (kerr == KCGI_OK)
282 c25c2314 2020-01-28 stsp return NULL;
284 c25c2314 2020-01-28 stsp if (kerr == KCGI_EXIT || kerr == KCGI_HUP)
285 c25c2314 2020-01-28 stsp return got_error(GOT_ERR_CANCELLED);
287 c25c2314 2020-01-28 stsp if (kerr == KCGI_ENOMEM)
288 f7cc9480 2020-02-05 tracey return got_error_set_errno(ENOMEM,
289 7afec891 2020-02-06 stsp kcgi_strerror(kerr));
291 c25c2314 2020-01-28 stsp if (kerr == KCGI_ENFILE)
292 f7cc9480 2020-02-05 tracey return got_error_set_errno(ENFILE,
293 7afec891 2020-02-06 stsp kcgi_strerror(kerr));
295 c25c2314 2020-01-28 stsp if (kerr == KCGI_EAGAIN)
296 f7cc9480 2020-02-05 tracey return got_error_set_errno(EAGAIN,
297 7afec891 2020-02-06 stsp kcgi_strerror(kerr));
299 c25c2314 2020-01-28 stsp if (kerr == KCGI_FORM)
300 f7cc9480 2020-02-05 tracey return got_error_msg(GOT_ERR_IO,
301 7afec891 2020-02-06 stsp kcgi_strerror(kerr));
303 7afec891 2020-02-06 stsp return got_error_from_errno(kcgi_strerror(kerr));
306 2c251c14 2020-01-15 tracey static const struct got_error *
307 d4159696 2020-02-13 stsp gw_apply_unveil(const char *repo_path)
309 2c251c14 2020-01-15 tracey const struct got_error *err;
311 245c7240 2021-06-17 stsp #ifdef PROFILE
312 245c7240 2021-06-17 stsp if (unveil("gmon.out", "rwc") != 0)
313 245c7240 2021-06-17 stsp return got_error_from_errno2("unveil", "gmon.out");
315 2c251c14 2020-01-15 tracey if (repo_path && unveil(repo_path, "r") != 0)
316 2c251c14 2020-01-15 tracey return got_error_from_errno2("unveil", repo_path);
318 bb63914a 2020-02-17 stsp if (unveil(GOT_TMPDIR_STR, "rwc") != 0)
319 bb63914a 2020-02-17 stsp return got_error_from_errno2("unveil", GOT_TMPDIR_STR);
321 2c251c14 2020-01-15 tracey err = got_privsep_unveil_exec_helpers();
322 2c251c14 2020-01-15 tracey if (err != NULL)
323 2c251c14 2020-01-15 tracey return err;
325 2c251c14 2020-01-15 tracey if (unveil(NULL, NULL) != 0)
326 2c251c14 2020-01-15 tracey return got_error_from_errno("unveil");
328 32cd4d18 2020-02-03 stsp return NULL;
332 e0857cfe 2020-02-06 tracey isbinary(const uint8_t *buf, size_t n)
334 e0857cfe 2020-02-06 tracey size_t i;
336 e0857cfe 2020-02-06 tracey for (i = 0; i < n; i++)
337 e0857cfe 2020-02-06 tracey if (buf[i] == 0)
338 e0857cfe 2020-02-06 tracey return 1;
339 e0857cfe 2020-02-06 tracey return 0;
342 32cd4d18 2020-02-03 stsp static const struct got_error *
343 54415d85 2020-01-15 tracey gw_blame(struct gw_trans *gw_trans)
345 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
346 f2f46662 2020-01-23 tracey struct gw_header *header = NULL;
347 78a9dab5 2020-02-07 tracey char *age = NULL;
348 1b33afc0 2020-02-14 tracey enum kcgi_err kerr = KCGI_OK;
350 7a6dddae 2021-06-18 stsp #ifndef PROFILE
351 6bee13de 2020-01-16 tracey if (pledge("stdio rpath wpath cpath proc exec sendfd unveil",
352 f2f46662 2020-01-23 tracey NULL) == -1)
353 f2f46662 2020-01-23 tracey return got_error_from_errno("pledge");
355 f2f46662 2020-01-23 tracey if ((header = gw_init_header()) == NULL)
356 f2f46662 2020-01-23 tracey return got_error_from_errno("malloc");
358 d4159696 2020-02-13 stsp error = gw_apply_unveil(gw_trans->gw_dir->path);
359 ec46ccd7 2020-01-15 tracey if (error)
362 1b33afc0 2020-02-14 tracey /* check querystring */
363 1b33afc0 2020-02-14 tracey if (gw_trans->repo_file == NULL) {
364 1b33afc0 2020-02-14 tracey error = got_error_msg(GOT_ERR_QUERYSTRING,
365 1b33afc0 2020-02-14 tracey "file required in querystring");
366 1b33afc0 2020-02-14 tracey goto done;
368 1b33afc0 2020-02-14 tracey if (gw_trans->commit_id == NULL) {
369 1b33afc0 2020-02-14 tracey error = got_error_msg(GOT_ERR_QUERYSTRING,
370 1b33afc0 2020-02-14 tracey "commit required in querystring");
371 1b33afc0 2020-02-14 tracey goto done;
374 f2f46662 2020-01-23 tracey error = gw_get_header(gw_trans, header, 1);
375 f2f46662 2020-01-23 tracey if (error)
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_wrapper", 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 kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
382 9a9d12ca 2020-02-06 tracey "blame_header", KATTR__MAX);
383 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
384 9a9d12ca 2020-02-06 tracey goto done;
385 9a9d12ca 2020-02-06 tracey error = gw_get_time_str(&age, header->committer_time,
386 9a9d12ca 2020-02-06 tracey TM_LONG);
389 9a9d12ca 2020-02-06 tracey error = gw_gen_age_header(gw_trans, age ?age : "");
392 9a9d12ca 2020-02-06 tracey error = gw_gen_commit_msg_header(gw_trans, header->commit_msg);
393 9a9d12ca 2020-02-06 tracey if (error)
395 9a9d12ca 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
396 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
398 9a9d12ca 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
399 9a9d12ca 2020-02-06 tracey "dotted_line", KATTR__MAX);
400 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
401 9a9d12ca 2020-02-06 tracey goto done;
402 9a9d12ca 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
403 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
404 9a9d12ca 2020-02-06 tracey goto done;
406 9a9d12ca 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
407 9a9d12ca 2020-02-06 tracey "blame", KATTR__MAX);
408 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
409 9a9d12ca 2020-02-06 tracey goto done;
410 84de9106 2020-12-26 stsp error = gw_output_file_blame(gw_trans, header);
411 9a9d12ca 2020-02-06 tracey if (error)
412 9a9d12ca 2020-02-06 tracey goto done;
413 9a9d12ca 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
415 b0a1bc86 2020-02-14 stsp gw_free_header(header);
416 9a9d12ca 2020-02-06 tracey if (error == NULL && kerr != KCGI_OK)
417 9a9d12ca 2020-02-06 tracey error = gw_kcgi_error(kerr);
418 2c251c14 2020-01-15 tracey return error;
421 2c251c14 2020-01-15 tracey static const struct got_error *
422 e46f587c 2020-01-29 tracey gw_blob(struct gw_trans *gw_trans)
424 3b7fdcf4 2020-02-14 tracey const struct got_error *error = NULL, *err = NULL;
425 e46f587c 2020-01-29 tracey struct gw_header *header = NULL;
426 3b7fdcf4 2020-02-14 tracey enum kcgi_err kerr = KCGI_OK;
428 7a6dddae 2021-06-18 stsp #ifndef PROFILE
429 e46f587c 2020-01-29 tracey if (pledge("stdio rpath wpath cpath proc exec sendfd unveil",
430 e46f587c 2020-01-29 tracey NULL) == -1)
431 e46f587c 2020-01-29 tracey return got_error_from_errno("pledge");
433 e46f587c 2020-01-29 tracey if ((header = gw_init_header()) == NULL)
434 e46f587c 2020-01-29 tracey return got_error_from_errno("malloc");
436 d4159696 2020-02-13 stsp error = gw_apply_unveil(gw_trans->gw_dir->path);
437 e46f587c 2020-01-29 tracey if (error)
438 e46f587c 2020-01-29 tracey goto done;
440 3b7fdcf4 2020-02-14 tracey /* check querystring */
441 3b7fdcf4 2020-02-14 tracey if (gw_trans->repo_file == NULL) {
442 3b7fdcf4 2020-02-14 tracey error = got_error_msg(GOT_ERR_QUERYSTRING,
443 3b7fdcf4 2020-02-14 tracey "file required in querystring");
444 3b7fdcf4 2020-02-14 tracey goto done;
446 3b7fdcf4 2020-02-14 tracey if (gw_trans->commit_id == NULL) {
447 3b7fdcf4 2020-02-14 tracey error = got_error_msg(GOT_ERR_QUERYSTRING,
448 3b7fdcf4 2020-02-14 tracey "commit required in querystring");
449 3b7fdcf4 2020-02-14 tracey goto done;
451 e46f587c 2020-01-29 tracey error = gw_get_header(gw_trans, header, 1);
452 e46f587c 2020-01-29 tracey if (error)
453 e46f587c 2020-01-29 tracey goto done;
455 84de9106 2020-12-26 stsp error = gw_output_blob_buf(gw_trans, header);
458 3b7fdcf4 2020-02-14 tracey if (error) {
459 3b7fdcf4 2020-02-14 tracey gw_trans->mime = KMIME_TEXT_PLAIN;
460 3b7fdcf4 2020-02-14 tracey err = gw_display_index(gw_trans);
461 3b7fdcf4 2020-02-14 tracey if (err) {
462 3b7fdcf4 2020-02-14 tracey error = err;
463 3b7fdcf4 2020-02-14 tracey goto errored;
465 3b7fdcf4 2020-02-14 tracey kerr = khttp_puts(gw_trans->gw_req, error->msg);
468 b0a1bc86 2020-02-14 stsp gw_free_header(header);
469 3b7fdcf4 2020-02-14 tracey if (error == NULL && kerr != KCGI_OK)
470 3b7fdcf4 2020-02-14 tracey error = gw_kcgi_error(kerr);
471 e46f587c 2020-01-29 tracey return error;
474 e46f587c 2020-01-29 tracey static const struct got_error *
475 f2f46662 2020-01-23 tracey gw_diff(struct gw_trans *gw_trans)
477 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
478 f2f46662 2020-01-23 tracey struct gw_header *header = NULL;
479 78a9dab5 2020-02-07 tracey char *age = NULL;
480 f7cc9480 2020-02-05 tracey enum kcgi_err kerr = KCGI_OK;
482 7a6dddae 2021-06-18 stsp #ifndef PROFILE
483 f2f46662 2020-01-23 tracey if (pledge("stdio rpath wpath cpath proc exec sendfd unveil",
484 f2f46662 2020-01-23 tracey NULL) == -1)
485 f2f46662 2020-01-23 tracey return got_error_from_errno("pledge");
487 ae36ed87 2020-01-28 stsp if ((header = gw_init_header()) == NULL)
488 f2f46662 2020-01-23 tracey return got_error_from_errno("malloc");
490 d4159696 2020-02-13 stsp error = gw_apply_unveil(gw_trans->gw_dir->path);
491 8087c3c5 2020-01-15 tracey if (error)
494 f2f46662 2020-01-23 tracey error = gw_get_header(gw_trans, header, 1);
495 f2f46662 2020-01-23 tracey if (error)
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_wrapper", 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 kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
503 f7cc9480 2020-02-05 tracey "diff_header", KATTR__MAX);
504 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
505 f7cc9480 2020-02-05 tracey goto done;
506 f7cc9480 2020-02-05 tracey error = gw_gen_diff_header(gw_trans, header->parent_id,
507 f7cc9480 2020-02-05 tracey header->commit_id);
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_commit_header(gw_trans, header->commit_id,
511 f7cc9480 2020-02-05 tracey header->refs_str);
512 f7cc9480 2020-02-05 tracey if (error)
513 f7cc9480 2020-02-05 tracey goto done;
514 f7cc9480 2020-02-05 tracey error = gw_gen_tree_header(gw_trans, header->tree_id);
515 f7cc9480 2020-02-05 tracey if (error)
516 f7cc9480 2020-02-05 tracey goto done;
517 f7cc9480 2020-02-05 tracey error = gw_gen_author_header(gw_trans, header->author);
518 f7cc9480 2020-02-05 tracey if (error)
519 f7cc9480 2020-02-05 tracey goto done;
520 f7cc9480 2020-02-05 tracey error = gw_gen_committer_header(gw_trans, header->author);
521 f7cc9480 2020-02-05 tracey if (error)
522 f7cc9480 2020-02-05 tracey goto done;
523 f7cc9480 2020-02-05 tracey error = gw_get_time_str(&age, header->committer_time,
524 f7cc9480 2020-02-05 tracey TM_LONG);
525 f7cc9480 2020-02-05 tracey if (error)
526 f7cc9480 2020-02-05 tracey goto done;
527 f7cc9480 2020-02-05 tracey error = gw_gen_age_header(gw_trans, age ?age : "");
530 f7cc9480 2020-02-05 tracey error = gw_gen_commit_msg_header(gw_trans, header->commit_msg);
531 f7cc9480 2020-02-05 tracey if (error)
533 f7cc9480 2020-02-05 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
534 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
536 f7cc9480 2020-02-05 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
537 f7cc9480 2020-02-05 tracey "dotted_line", KATTR__MAX);
538 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
539 f7cc9480 2020-02-05 tracey goto done;
540 f7cc9480 2020-02-05 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
541 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
542 f7cc9480 2020-02-05 tracey goto done;
544 f7cc9480 2020-02-05 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
545 f7cc9480 2020-02-05 tracey "diff", KATTR__MAX);
546 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
547 f7cc9480 2020-02-05 tracey goto done;
548 38b240fb 2020-02-06 tracey error = gw_output_diff(gw_trans, header);
549 f7cc9480 2020-02-05 tracey if (error)
550 f7cc9480 2020-02-05 tracey goto done;
552 b4fba448 2020-02-05 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
554 b0a1bc86 2020-02-14 stsp gw_free_header(header);
556 f7cc9480 2020-02-05 tracey if (error == NULL && kerr != KCGI_OK)
557 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
558 2204c934 2020-01-15 tracey return error;
561 2204c934 2020-01-15 tracey static const struct got_error *
562 54415d85 2020-01-15 tracey gw_index(struct gw_trans *gw_trans)
564 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
565 46b9c89b 2020-01-15 tracey struct gw_dir *gw_dir = NULL;
566 b3f1f953 2020-02-09 tracey char *href_next = NULL, *href_prev = NULL, *href_summary = NULL;
567 b3f1f953 2020-02-09 tracey char *href_briefs = NULL, *href_commits = NULL, *href_tree = NULL;
568 ff4bb25f 2020-02-19 tracey char *href_tags = NULL;
569 387a29ba 2020-01-15 tracey unsigned int prev_disp = 0, next_disp = 1, dir_c = 0;
570 795c10a4 2020-02-20 tracey enum kcgi_err kerr = KCGI_OK;
572 7a6dddae 2021-06-18 stsp #ifndef PROFILE
573 6bee13de 2020-01-16 tracey if (pledge("stdio rpath proc exec sendfd unveil",
574 6bee13de 2020-01-16 tracey NULL) == -1) {
575 6bee13de 2020-01-16 tracey error = got_error_from_errno("pledge");
576 6bee13de 2020-01-16 tracey return error;
579 d4159696 2020-02-13 stsp error = gw_apply_unveil(gw_trans->gw_conf->got_repos_path);
580 46b9c89b 2020-01-15 tracey if (error)
581 46b9c89b 2020-01-15 tracey return error;
583 2c251c14 2020-01-15 tracey error = gw_load_got_paths(gw_trans);
584 46b9c89b 2020-01-15 tracey if (error)
585 2c251c14 2020-01-15 tracey return error;
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", 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_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
592 b3f1f953 2020-02-09 tracey "index_header_project", KATTR__MAX);
593 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
594 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
595 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Project");
596 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
597 2447adad 2020-02-06 stsp return gw_kcgi_error(kerr);
598 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
599 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
600 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
602 b3f1f953 2020-02-09 tracey if (gw_trans->gw_conf->got_show_repo_description) {
603 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
604 b3f1f953 2020-02-09 tracey "index_header_description", KATTR__MAX);
605 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
606 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
607 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Description");
608 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
609 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
610 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
611 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
612 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
615 b3f1f953 2020-02-09 tracey if (gw_trans->gw_conf->got_show_repo_owner) {
616 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
617 b3f1f953 2020-02-09 tracey "index_header_owner", KATTR__MAX);
618 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
619 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
620 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Owner");
621 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
622 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
623 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
624 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
625 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
628 b3f1f953 2020-02-09 tracey if (gw_trans->gw_conf->got_show_repo_age) {
629 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
630 b3f1f953 2020-02-09 tracey "index_header_age", KATTR__MAX);
631 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
632 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
633 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Last Change");
634 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
635 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
636 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
637 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
638 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
641 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
642 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
643 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
645 b3f1f953 2020-02-09 tracey if (TAILQ_EMPTY(&gw_trans->gw_dirs)) {
646 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
647 b3f1f953 2020-02-09 tracey "index_wrapper", KATTR__MAX);
648 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
649 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
650 32b9f7ed 2020-04-14 tracey kerr = khtml_printf(gw_trans->gw_html_req,
651 32b9f7ed 2020-04-14 tracey "No repositories found in %s",
652 b3f1f953 2020-02-09 tracey gw_trans->gw_conf->got_repos_path);
653 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
654 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
655 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
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_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
659 b3f1f953 2020-02-09 tracey "dotted_line", KATTR__MAX);
660 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
661 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
662 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
663 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
664 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
665 c25c2314 2020-01-28 stsp return error;
668 46b9c89b 2020-01-15 tracey TAILQ_FOREACH(gw_dir, &gw_trans->gw_dirs, entry)
671 46b9c89b 2020-01-15 tracey TAILQ_FOREACH(gw_dir, &gw_trans->gw_dirs, entry) {
672 2c251c14 2020-01-15 tracey if (gw_trans->page > 0 && (gw_trans->page *
673 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_max_repos_display) > prev_disp) {
674 2c251c14 2020-01-15 tracey prev_disp++;
675 2c251c14 2020-01-15 tracey continue;
678 2c251c14 2020-01-15 tracey prev_disp++;
680 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
681 b3f1f953 2020-02-09 tracey "index_wrapper", KATTR__MAX);
682 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
685 2796ac23 2020-04-14 tracey href_summary = khttp_urlpart(NULL, NULL, "gotweb", "path",
686 2796ac23 2020-04-14 tracey gw_dir->name, "action", "summary", NULL);
687 19ff7638 2020-04-14 tracey if (href_summary == NULL) {
688 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
689 19ff7638 2020-04-14 tracey goto done;
691 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
692 b3f1f953 2020-02-09 tracey "index_project", 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_attr(gw_trans->gw_html_req, KELEM_A, KATTR_HREF,
696 b3f1f953 2020-02-09 tracey href_summary, KATTR__MAX);
697 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
698 b3f1f953 2020-02-09 tracey goto done;
699 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req, gw_dir->name);
700 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
701 b3f1f953 2020-02-09 tracey goto done;
702 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
703 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
704 b3f1f953 2020-02-09 tracey goto done;
705 b3f1f953 2020-02-09 tracey if (gw_trans->gw_conf->got_show_repo_description) {
706 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
707 b3f1f953 2020-02-09 tracey KATTR_ID, "index_project_description", KATTR__MAX);
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_puts(gw_trans->gw_html_req,
711 b3f1f953 2020-02-09 tracey gw_dir->description ? gw_dir->description : "");
712 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
713 b3f1f953 2020-02-09 tracey goto done;
714 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
715 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
716 b3f1f953 2020-02-09 tracey goto done;
718 b3f1f953 2020-02-09 tracey if (gw_trans->gw_conf->got_show_repo_owner) {
719 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
720 b3f1f953 2020-02-09 tracey KATTR_ID, "index_project_owner", KATTR__MAX);
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_puts(gw_trans->gw_html_req,
724 b3f1f953 2020-02-09 tracey gw_dir->owner ? gw_dir->owner : "");
725 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
726 b3f1f953 2020-02-09 tracey goto done;
727 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
728 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
729 b3f1f953 2020-02-09 tracey goto done;
731 b3f1f953 2020-02-09 tracey if (gw_trans->gw_conf->got_show_repo_age) {
732 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
733 b3f1f953 2020-02-09 tracey KATTR_ID, "index_project_age", KATTR__MAX);
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_puts(gw_trans->gw_html_req,
737 b3f1f953 2020-02-09 tracey gw_dir->age ? gw_dir->age : "");
738 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
739 b3f1f953 2020-02-09 tracey goto done;
740 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
741 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
742 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_wrapper", KATTR__MAX);
747 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
748 b3f1f953 2020-02-09 tracey goto done;
749 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
750 b3f1f953 2020-02-09 tracey "navs", KATTR__MAX);
751 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
752 b3f1f953 2020-02-09 tracey goto done;
754 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A, KATTR_HREF,
755 b3f1f953 2020-02-09 tracey href_summary, KATTR__MAX);
756 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
757 b3f1f953 2020-02-09 tracey goto done;
758 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req, "summary");
759 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
760 b3f1f953 2020-02-09 tracey goto done;
761 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
762 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
763 b3f1f953 2020-02-09 tracey goto done;
765 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req, " | ");
766 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
767 b3f1f953 2020-02-09 tracey goto done;
769 2796ac23 2020-04-14 tracey href_briefs = khttp_urlpart(NULL, NULL, "gotweb", "path",
770 2796ac23 2020-04-14 tracey gw_dir->name, "action", "briefs", NULL);
771 19ff7638 2020-04-14 tracey if (href_briefs == NULL) {
772 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
773 19ff7638 2020-04-14 tracey goto done;
775 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A, KATTR_HREF,
776 b3f1f953 2020-02-09 tracey href_briefs, KATTR__MAX);
777 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
778 b3f1f953 2020-02-09 tracey goto done;
779 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req, "commit briefs");
780 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
781 b3f1f953 2020-02-09 tracey goto done;
782 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
783 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
784 b3f1f953 2020-02-09 tracey error = gw_kcgi_error(kerr);
786 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req, " | ");
787 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
788 b3f1f953 2020-02-09 tracey goto done;
790 2796ac23 2020-04-14 tracey href_commits = khttp_urlpart(NULL, NULL, "gotweb", "path",
791 2796ac23 2020-04-14 tracey gw_dir->name, "action", "commits", NULL);
792 19ff7638 2020-04-14 tracey if (href_commits == NULL) {
793 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
794 19ff7638 2020-04-14 tracey goto done;
796 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A, KATTR_HREF,
797 b3f1f953 2020-02-09 tracey href_commits, KATTR__MAX);
798 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
799 b3f1f953 2020-02-09 tracey goto done;
800 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req, "commits");
801 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
802 b3f1f953 2020-02-09 tracey goto done;
803 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
804 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
805 b3f1f953 2020-02-09 tracey goto done;
807 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req, " | ");
808 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
809 b3f1f953 2020-02-09 tracey goto done;
811 2796ac23 2020-04-14 tracey href_tags = khttp_urlpart(NULL, NULL, "gotweb", "path",
812 2796ac23 2020-04-14 tracey gw_dir->name, "action", "tags", NULL);
813 19ff7638 2020-04-14 tracey if (href_tags == NULL) {
814 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
815 19ff7638 2020-04-14 tracey goto done;
817 ff4bb25f 2020-02-19 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A, KATTR_HREF,
818 ff4bb25f 2020-02-19 tracey href_tags, KATTR__MAX);
819 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
820 ff4bb25f 2020-02-19 tracey goto done;
821 ff4bb25f 2020-02-19 tracey kerr = khtml_puts(gw_trans->gw_html_req, "tags");
822 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
823 ff4bb25f 2020-02-19 tracey goto done;
824 ff4bb25f 2020-02-19 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
825 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
826 ff4bb25f 2020-02-19 tracey goto done;
828 ff4bb25f 2020-02-19 tracey kerr = khtml_puts(gw_trans->gw_html_req, " | ");
829 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
830 ff4bb25f 2020-02-19 tracey goto done;
832 2796ac23 2020-04-14 tracey href_tree = khttp_urlpart(NULL, NULL, "gotweb", "path",
833 2796ac23 2020-04-14 tracey gw_dir->name, "action", "tree", NULL);
834 19ff7638 2020-04-14 tracey if (href_tree == NULL) {
835 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
836 19ff7638 2020-04-14 tracey goto done;
838 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A, KATTR_HREF,
839 b3f1f953 2020-02-09 tracey href_tree, KATTR__MAX);
840 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
841 b3f1f953 2020-02-09 tracey goto done;
842 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req, "tree");
843 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
844 b3f1f953 2020-02-09 tracey goto done;
846 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 4);
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_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
850 b3f1f953 2020-02-09 tracey "dotted_line", KATTR__MAX);
851 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
852 b3f1f953 2020-02-09 tracey goto done;
853 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
854 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
855 b3f1f953 2020-02-09 tracey goto done;
857 b3f1f953 2020-02-09 tracey free(href_summary);
858 b3f1f953 2020-02-09 tracey href_summary = NULL;
859 b3f1f953 2020-02-09 tracey free(href_briefs);
860 b3f1f953 2020-02-09 tracey href_briefs = NULL;
861 b3f1f953 2020-02-09 tracey free(href_commits);
862 b3f1f953 2020-02-09 tracey href_commits = NULL;
863 ff4bb25f 2020-02-19 tracey free(href_tags);
864 ff4bb25f 2020-02-19 tracey href_tags = NULL;
865 b3f1f953 2020-02-09 tracey free(href_tree);
866 b3f1f953 2020-02-09 tracey href_tree = NULL;
868 2c251c14 2020-01-15 tracey if (gw_trans->gw_conf->got_max_repos_display == 0)
869 2c251c14 2020-01-15 tracey continue;
871 75f21c89 2020-02-18 tracey if ((next_disp == gw_trans->gw_conf->got_max_repos_display) ||
872 75f21c89 2020-02-18 tracey ((gw_trans->gw_conf->got_max_repos_display > 0) &&
873 2c251c14 2020-01-15 tracey (gw_trans->page > 0) &&
874 2c251c14 2020-01-15 tracey (next_disp == gw_trans->gw_conf->got_max_repos_display ||
875 75f21c89 2020-02-18 tracey prev_disp == gw_trans->repos_total))) {
876 63ee0dca 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
877 63ee0dca 2020-02-08 tracey KATTR_ID, "np_wrapper", KATTR__MAX);
878 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
879 b3f1f953 2020-02-09 tracey goto done;
880 63ee0dca 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
881 63ee0dca 2020-02-08 tracey KATTR_ID, "nav_prev", KATTR__MAX);
882 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
883 b3f1f953 2020-02-09 tracey goto done;
886 2c251c14 2020-01-15 tracey if ((gw_trans->gw_conf->got_max_repos_display > 0) &&
887 2c251c14 2020-01-15 tracey (gw_trans->page > 0) &&
888 2c251c14 2020-01-15 tracey (next_disp == gw_trans->gw_conf->got_max_repos_display ||
889 2c251c14 2020-01-15 tracey prev_disp == gw_trans->repos_total)) {
890 2796ac23 2020-04-14 tracey href_prev = khttp_urlpartx(NULL, NULL, "gotweb", "page",
891 2796ac23 2020-04-14 tracey KATTRX_INT, (int64_t)(gw_trans->page - 1), NULL);
892 19ff7638 2020-04-14 tracey if (href_prev == NULL) {
893 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpartx");
894 19ff7638 2020-04-14 tracey goto done;
896 63ee0dca 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
897 63ee0dca 2020-02-08 tracey KATTR_HREF, href_prev, KATTR__MAX);
898 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
899 565d9dcb 2020-02-09 tracey goto done;
900 63ee0dca 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Previous");
901 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
902 b3f1f953 2020-02-09 tracey goto done;
903 63ee0dca 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
904 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
905 b3f1f953 2020-02-09 tracey goto done;
908 63ee0dca 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
909 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
910 2447adad 2020-02-06 stsp return gw_kcgi_error(kerr);
912 2c251c14 2020-01-15 tracey if (gw_trans->gw_conf->got_max_repos_display > 0 &&
913 2c251c14 2020-01-15 tracey next_disp == gw_trans->gw_conf->got_max_repos_display &&
914 2c251c14 2020-01-15 tracey dir_c != (gw_trans->page + 1) *
915 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_max_repos_display) {
916 63ee0dca 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
917 63ee0dca 2020-02-08 tracey KATTR_ID, "nav_next", KATTR__MAX);
918 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
919 b3f1f953 2020-02-09 tracey goto done;
920 2796ac23 2020-04-14 tracey href_next = khttp_urlpartx(NULL, NULL, "gotweb", "page",
921 2796ac23 2020-04-14 tracey KATTRX_INT, (int64_t)(gw_trans->page + 1), NULL);
922 19ff7638 2020-04-14 tracey if (href_next == NULL) {
923 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpartx");
924 19ff7638 2020-04-14 tracey goto done;
926 63ee0dca 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
927 63ee0dca 2020-02-08 tracey KATTR_HREF, href_next, KATTR__MAX);
928 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
929 b3f1f953 2020-02-09 tracey goto done;
930 63ee0dca 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Next");
931 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
932 b3f1f953 2020-02-09 tracey goto done;
933 63ee0dca 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 3);
934 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
935 b3f1f953 2020-02-09 tracey goto done;
936 2c251c14 2020-01-15 tracey next_disp = 0;
940 2c251c14 2020-01-15 tracey if ((gw_trans->gw_conf->got_max_repos_display > 0) &&
941 2c251c14 2020-01-15 tracey (gw_trans->page > 0) &&
942 2c251c14 2020-01-15 tracey (next_disp == gw_trans->gw_conf->got_max_repos_display ||
943 c25c2314 2020-01-28 stsp prev_disp == gw_trans->repos_total)) {
944 63ee0dca 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
945 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
946 b3f1f953 2020-02-09 tracey goto done;
948 2c251c14 2020-01-15 tracey next_disp++;
951 00f13350 2020-02-10 tracey free(href_prev);
952 00f13350 2020-02-10 tracey free(href_next);
953 b3f1f953 2020-02-09 tracey free(href_summary);
954 b3f1f953 2020-02-09 tracey free(href_briefs);
955 b3f1f953 2020-02-09 tracey free(href_commits);
956 ff4bb25f 2020-02-19 tracey free(href_tags);
957 b3f1f953 2020-02-09 tracey free(href_tree);
958 565d9dcb 2020-02-09 tracey if (error == NULL && kerr != KCGI_OK)
959 565d9dcb 2020-02-09 tracey error = gw_kcgi_error(kerr);
960 2c251c14 2020-01-15 tracey return error;
963 2c251c14 2020-01-15 tracey static const struct got_error *
964 f2f46662 2020-01-23 tracey gw_commits(struct gw_trans *gw_trans)
966 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
967 f2f46662 2020-01-23 tracey struct gw_header *header = NULL, *n_header = NULL;
968 038dfa29 2020-04-14 tracey char *age = NULL, *href_diff = NULL, *href_tree = NULL;
969 55e46400 2020-02-18 tracey char *href_prev = NULL, *href_next = NULL;
970 21a55cc7 2020-02-04 tracey enum kcgi_err kerr = KCGI_OK;
972 ae36ed87 2020-01-28 stsp if ((header = gw_init_header()) == NULL)
973 f2f46662 2020-01-23 tracey return got_error_from_errno("malloc");
975 7a6dddae 2021-06-18 stsp #ifndef PROFILE
976 6bee13de 2020-01-16 tracey if (pledge("stdio rpath proc exec sendfd unveil",
977 6bee13de 2020-01-16 tracey NULL) == -1) {
978 6bee13de 2020-01-16 tracey error = got_error_from_errno("pledge");
982 d4159696 2020-02-13 stsp error = gw_apply_unveil(gw_trans->gw_dir->path);
983 8087c3c5 2020-01-15 tracey if (error)
986 f2f46662 2020-01-23 tracey error = gw_get_header(gw_trans, header,
987 f2f46662 2020-01-23 tracey gw_trans->gw_conf->got_max_commits_display);
991 f2f46662 2020-01-23 tracey TAILQ_FOREACH(n_header, &gw_trans->gw_headers, entry) {
992 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
993 21a55cc7 2020-02-04 tracey "commits_line_wrapper", KATTR__MAX);
994 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
996 21a55cc7 2020-02-04 tracey error = gw_gen_commit_header(gw_trans, n_header->commit_id,
997 21a55cc7 2020-02-04 tracey n_header->refs_str);
998 f7cc9480 2020-02-05 tracey if (error)
999 f7cc9480 2020-02-05 tracey goto done;
1000 21a55cc7 2020-02-04 tracey error = gw_gen_author_header(gw_trans, n_header->author);
1001 21a55cc7 2020-02-04 tracey if (error)
1002 21a55cc7 2020-02-04 tracey goto done;
1003 21a55cc7 2020-02-04 tracey error = gw_gen_committer_header(gw_trans, n_header->author);
1004 21a55cc7 2020-02-04 tracey if (error)
1005 21a55cc7 2020-02-04 tracey goto done;
1006 55ccf528 2020-02-03 stsp error = gw_get_time_str(&age, n_header->committer_time,
1008 55ccf528 2020-02-03 stsp if (error)
1009 55ccf528 2020-02-03 stsp goto done;
1010 21a55cc7 2020-02-04 tracey error = gw_gen_age_header(gw_trans, age ?age : "");
1011 21a55cc7 2020-02-04 tracey if (error)
1012 55ccf528 2020-02-03 stsp goto done;
1013 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
1014 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1015 21a55cc7 2020-02-04 tracey goto done;
1017 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1018 21a55cc7 2020-02-04 tracey "dotted_line", KATTR__MAX);
1019 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1020 21a55cc7 2020-02-04 tracey goto done;
1021 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1022 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1023 21a55cc7 2020-02-04 tracey goto done;
1025 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1026 21a55cc7 2020-02-04 tracey "commit", KATTR__MAX);
1027 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1028 21a55cc7 2020-02-04 tracey goto done;
1029 78a9dab5 2020-02-07 tracey kerr = khttp_puts(gw_trans->gw_req, n_header->commit_msg);
1030 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1031 21a55cc7 2020-02-04 tracey goto done;
1032 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1033 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1034 21a55cc7 2020-02-04 tracey goto done;
1036 038dfa29 2020-04-14 tracey href_diff = khttp_urlpart(NULL, NULL, "gotweb", "path",
1037 038dfa29 2020-04-14 tracey gw_trans->repo_name, "action", "diff", "commit",
1038 038dfa29 2020-04-14 tracey n_header->commit_id, NULL);
1039 19ff7638 2020-04-14 tracey if (href_diff == NULL) {
1040 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
1041 19ff7638 2020-04-14 tracey goto done;
1043 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1044 21a55cc7 2020-02-04 tracey KATTR_ID, "navs_wrapper", KATTR__MAX);
1045 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1046 21a55cc7 2020-02-04 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", 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_A,
1052 21a55cc7 2020-02-04 tracey KATTR_HREF, href_diff, 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_puts(gw_trans->gw_html_req, "diff");
1056 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1057 21a55cc7 2020-02-04 tracey goto done;
1058 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1059 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1060 21a55cc7 2020-02-04 tracey goto done;
1062 21a55cc7 2020-02-04 tracey kerr = khtml_puts(gw_trans->gw_html_req, " | ");
1063 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1064 21a55cc7 2020-02-04 tracey goto done;
1066 038dfa29 2020-04-14 tracey href_tree = khttp_urlpart(NULL, NULL, "gotweb", "path",
1067 038dfa29 2020-04-14 tracey gw_trans->repo_name, "action", "tree", "commit",
1068 19ff7638 2020-04-14 tracey n_header->commit_id, NULL);
1069 19ff7638 2020-04-14 tracey if (href_tree == NULL) {
1070 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
1071 19ff7638 2020-04-14 tracey goto done;
1073 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
1074 038dfa29 2020-04-14 tracey KATTR_HREF, href_tree, KATTR__MAX);
1075 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1076 21a55cc7 2020-02-04 tracey goto done;
1077 21a55cc7 2020-02-04 tracey khtml_puts(gw_trans->gw_html_req, "tree");
1078 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1079 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1080 21a55cc7 2020-02-04 tracey goto done;
1081 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1082 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1083 21a55cc7 2020-02-04 tracey goto done;
1085 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1086 21a55cc7 2020-02-04 tracey "solid_line", KATTR__MAX);
1087 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1088 21a55cc7 2020-02-04 tracey goto done;
1089 b4fba448 2020-02-05 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
1090 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1091 21a55cc7 2020-02-04 tracey goto done;
1093 55ccf528 2020-02-03 stsp free(age);
1094 55ccf528 2020-02-03 stsp age = NULL;
1097 55e46400 2020-02-18 tracey if (gw_trans->next_id || gw_trans->page > 0) {
1098 55e46400 2020-02-18 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1099 55e46400 2020-02-18 tracey KATTR_ID, "np_wrapper", KATTR__MAX);
1100 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1101 55e46400 2020-02-18 tracey goto done;
1102 55e46400 2020-02-18 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1103 55e46400 2020-02-18 tracey KATTR_ID, "nav_prev", KATTR__MAX);
1104 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1105 55e46400 2020-02-18 tracey goto done;
1108 bf4484a3 2020-02-18 tracey if (gw_trans->page > 0 && gw_trans->prev_id) {
1109 038dfa29 2020-04-14 tracey href_prev = khttp_urlpartx(NULL, NULL, "gotweb", "path",
1110 038dfa29 2020-04-14 tracey KATTRX_STRING, gw_trans->repo_name, "page",
1111 038dfa29 2020-04-14 tracey KATTRX_INT, (int64_t) (gw_trans->page - 1), "action",
1112 038dfa29 2020-04-14 tracey KATTRX_STRING, "commits", "commit", KATTRX_STRING,
1113 038dfa29 2020-04-14 tracey gw_trans->prev_id ? gw_trans->prev_id : "", "prev",
1114 038dfa29 2020-04-14 tracey KATTRX_STRING, gw_trans->prev_prev_id ?
1115 038dfa29 2020-04-14 tracey gw_trans->prev_prev_id : "", NULL);
1116 19ff7638 2020-04-14 tracey if (href_prev == NULL) {
1117 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpartx");
1118 19ff7638 2020-04-14 tracey goto done;
1120 55e46400 2020-02-18 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
1121 55e46400 2020-02-18 tracey KATTR_HREF, href_prev, KATTR__MAX);
1122 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1123 55e46400 2020-02-18 tracey goto done;
1124 55e46400 2020-02-18 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Previous");
1125 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1126 55e46400 2020-02-18 tracey goto done;
1127 55e46400 2020-02-18 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1128 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1129 55e46400 2020-02-18 tracey goto done;
1132 55e46400 2020-02-18 tracey if (gw_trans->next_id || gw_trans->page > 0) {
1133 55e46400 2020-02-18 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1134 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1135 55e46400 2020-02-18 tracey return gw_kcgi_error(kerr);
1138 55e46400 2020-02-18 tracey if (gw_trans->next_id) {
1139 55e46400 2020-02-18 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1140 55e46400 2020-02-18 tracey KATTR_ID, "nav_next", KATTR__MAX);
1141 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1142 55e46400 2020-02-18 tracey goto done;
1143 038dfa29 2020-04-14 tracey href_next = khttp_urlpartx(NULL, NULL, "gotweb", "path",
1144 038dfa29 2020-04-14 tracey KATTRX_STRING, gw_trans->repo_name, "page",
1145 038dfa29 2020-04-14 tracey KATTRX_INT, (int64_t) (gw_trans->page + 1), "action",
1146 038dfa29 2020-04-14 tracey KATTRX_STRING, "commits", "commit", KATTRX_STRING,
1147 038dfa29 2020-04-14 tracey gw_trans->next_id, "prev", KATTRX_STRING,
1148 55e46400 2020-02-18 tracey gw_trans->next_prev_id ? gw_trans->next_prev_id : "",
1149 038dfa29 2020-04-14 tracey "prev_prev", KATTRX_STRING, gw_trans->prev_prev_id ?
1150 19ff7638 2020-04-14 tracey gw_trans->prev_prev_id : "", NULL);
1151 19ff7638 2020-04-14 tracey if (href_next == NULL) {
1152 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpartx");
1153 19ff7638 2020-04-14 tracey goto done;
1155 55e46400 2020-02-18 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
1156 55e46400 2020-02-18 tracey KATTR_HREF, href_next, KATTR__MAX);
1157 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1158 55e46400 2020-02-18 tracey goto done;
1159 55e46400 2020-02-18 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Next");
1160 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1161 55e46400 2020-02-18 tracey goto done;
1162 55e46400 2020-02-18 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 3);
1163 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1164 55e46400 2020-02-18 tracey goto done;
1167 55e46400 2020-02-18 tracey if (gw_trans->next_id || gw_trans->page > 0) {
1168 55e46400 2020-02-18 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
1169 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1170 55e46400 2020-02-18 tracey goto done;
1173 b0a1bc86 2020-02-14 stsp gw_free_header(header);
1174 f2f46662 2020-01-23 tracey TAILQ_FOREACH(n_header, &gw_trans->gw_headers, entry)
1175 b0a1bc86 2020-02-14 stsp gw_free_header(n_header);
1176 55ccf528 2020-02-03 stsp free(age);
1177 55e46400 2020-02-18 tracey free(href_next);
1178 55e46400 2020-02-18 tracey free(href_prev);
1179 21a55cc7 2020-02-04 tracey free(href_diff);
1180 038dfa29 2020-04-14 tracey free(href_tree);
1181 21a55cc7 2020-02-04 tracey if (error == NULL && kerr != KCGI_OK)
1182 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
1183 2c251c14 2020-01-15 tracey return error;
1186 2c251c14 2020-01-15 tracey static const struct got_error *
1187 f2f46662 2020-01-23 tracey gw_briefs(struct gw_trans *gw_trans)
1189 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
1190 bd275801 2020-02-03 tracey struct gw_header *header = NULL, *n_header = NULL;
1191 9ba68833 2020-04-14 tracey char *age = NULL, *href_diff = NULL, *href_tree = NULL;
1192 55e46400 2020-02-18 tracey char *href_prev = NULL, *href_next = NULL;
1193 bd275801 2020-02-03 tracey char *newline, *smallerthan;
1194 ef72fe2c 2020-02-04 stsp enum kcgi_err kerr = KCGI_OK;
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 bd275801 2020-02-03 tracey error = gw_get_time_str(&age, n_header->committer_time,
1222 bd275801 2020-02-03 tracey TM_DIFF);
1223 bd275801 2020-02-03 tracey if (error)
1224 bd275801 2020-02-03 tracey goto done;
1226 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1227 bd275801 2020-02-03 tracey KATTR_ID, "briefs_wrapper", KATTR__MAX);
1228 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1229 bd275801 2020-02-03 tracey goto done;
1231 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1232 bd275801 2020-02-03 tracey KATTR_ID, "briefs_age", KATTR__MAX);
1233 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1234 bd275801 2020-02-03 tracey goto done;
1235 53e81e48 2020-02-13 tracey kerr = khtml_puts(gw_trans->gw_html_req, age ? age : "");
1236 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1237 bd275801 2020-02-03 tracey goto done;
1238 bd275801 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1239 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1240 bd275801 2020-02-03 tracey goto done;
1242 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1243 bd275801 2020-02-03 tracey KATTR_ID, "briefs_author", KATTR__MAX);
1244 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1245 bd275801 2020-02-03 tracey goto done;
1246 bd275801 2020-02-03 tracey smallerthan = strchr(n_header->author, '<');
1247 bd275801 2020-02-03 tracey if (smallerthan)
1248 bd275801 2020-02-03 tracey *smallerthan = '\0';
1249 bd275801 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req, n_header->author);
1250 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1251 bd275801 2020-02-03 tracey goto done;
1252 bd275801 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1253 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1254 bd275801 2020-02-03 tracey goto done;
1256 9ba68833 2020-04-14 tracey href_diff = khttp_urlpart(NULL, NULL, "gotweb", "path",
1257 9ba68833 2020-04-14 tracey gw_trans->repo_name, "action", "diff", "commit",
1258 9ba68833 2020-04-14 tracey n_header->commit_id, NULL);
1259 19ff7638 2020-04-14 tracey if (href_diff == NULL) {
1260 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
1261 19ff7638 2020-04-14 tracey goto done;
1263 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1264 bd275801 2020-02-03 tracey KATTR_ID, "briefs_log", KATTR__MAX);
1265 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1266 bd275801 2020-02-03 tracey goto done;
1267 f2f46662 2020-01-23 tracey newline = strchr(n_header->commit_msg, '\n');
1268 f2f46662 2020-01-23 tracey if (newline)
1269 f2f46662 2020-01-23 tracey *newline = '\0';
1270 52f8346c 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
1271 52f8346c 2020-02-03 tracey KATTR_HREF, href_diff, KATTR__MAX);
1272 52f8346c 2020-02-03 tracey if (kerr != KCGI_OK)
1273 52f8346c 2020-02-03 tracey goto done;
1274 bd275801 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req, n_header->commit_msg);
1275 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1276 55ccf528 2020-02-03 stsp goto done;
1277 bf93a5c0 2020-02-15 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1278 bf93a5c0 2020-02-15 tracey if (kerr != KCGI_OK)
1279 bf93a5c0 2020-02-15 tracey goto done;
1281 bf93a5c0 2020-02-15 tracey if (n_header->refs_str) {
1282 bf93a5c0 2020-02-15 tracey kerr = khtml_puts(gw_trans->gw_html_req, " ");
1283 bf93a5c0 2020-02-15 tracey if (kerr != KCGI_OK)
1284 bf93a5c0 2020-02-15 tracey goto done;
1285 bf93a5c0 2020-02-15 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_SPAN,
1286 bf93a5c0 2020-02-15 tracey KATTR_ID, "refs_str", KATTR__MAX);
1287 bf93a5c0 2020-02-15 tracey if (kerr != KCGI_OK)
1288 bf93a5c0 2020-02-15 tracey goto done;
1289 32b9f7ed 2020-04-14 tracey kerr = khtml_printf(gw_trans->gw_html_req, "(%s)",
1290 bf93a5c0 2020-02-15 tracey n_header->refs_str);
1291 bf93a5c0 2020-02-15 tracey if (kerr != KCGI_OK)
1292 bf93a5c0 2020-02-15 tracey goto done;
1293 bf93a5c0 2020-02-15 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1294 bf93a5c0 2020-02-15 tracey if (kerr != KCGI_OK)
1295 bf93a5c0 2020-02-15 tracey goto done;
1298 bf93a5c0 2020-02-15 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1299 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1300 bd275801 2020-02-03 tracey goto done;
1302 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1303 bd275801 2020-02-03 tracey KATTR_ID, "navs_wrapper", KATTR__MAX);
1304 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1305 bd275801 2020-02-03 tracey goto done;
1306 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1307 bd275801 2020-02-03 tracey KATTR_ID, "navs", KATTR__MAX);
1308 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1309 bd275801 2020-02-03 tracey goto done;
1310 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
1311 bd275801 2020-02-03 tracey KATTR_HREF, href_diff, KATTR__MAX);
1312 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1313 070fee27 2020-02-03 stsp goto done;
1314 bd275801 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req, "diff");
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_closeelem(gw_trans->gw_html_req, 1);
1318 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1319 bd275801 2020-02-03 tracey goto done;
1321 bd275801 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req, " | ");
1322 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1323 bd275801 2020-02-03 tracey goto done;
1325 9ba68833 2020-04-14 tracey href_tree = khttp_urlpart(NULL, NULL, "gotweb", "path",
1326 9ba68833 2020-04-14 tracey gw_trans->repo_name, "action", "tree", "commit",
1327 9ba68833 2020-04-14 tracey n_header->commit_id, NULL);
1328 19ff7638 2020-04-14 tracey if (href_tree == NULL) {
1329 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
1330 19ff7638 2020-04-14 tracey goto done;
1332 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
1333 9ba68833 2020-04-14 tracey KATTR_HREF, href_tree, KATTR__MAX);
1334 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1335 bd275801 2020-02-03 tracey goto done;
1336 bd275801 2020-02-03 tracey khtml_puts(gw_trans->gw_html_req, "tree");
1337 bd275801 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1338 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1339 bd275801 2020-02-03 tracey goto done;
1340 bd275801 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1341 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1342 bd275801 2020-02-03 tracey goto done;
1344 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1345 bd275801 2020-02-03 tracey KATTR_ID, "dotted_line", KATTR__MAX);
1346 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1347 bd275801 2020-02-03 tracey goto done;
1348 bd275801 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 3);
1349 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1350 bd275801 2020-02-03 tracey goto done;
1352 55ccf528 2020-02-03 stsp free(age);
1353 55ccf528 2020-02-03 stsp age = NULL;
1354 bd275801 2020-02-03 tracey free(href_diff);
1355 bd275801 2020-02-03 tracey href_diff = NULL;
1356 9ba68833 2020-04-14 tracey free(href_tree);
1357 9ba68833 2020-04-14 tracey href_tree = NULL;
1360 55e46400 2020-02-18 tracey if (gw_trans->next_id || gw_trans->page > 0) {
1361 55e46400 2020-02-18 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1362 55e46400 2020-02-18 tracey KATTR_ID, "np_wrapper", KATTR__MAX);
1363 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1364 55e46400 2020-02-18 tracey goto done;
1365 55e46400 2020-02-18 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1366 55e46400 2020-02-18 tracey KATTR_ID, "nav_prev", KATTR__MAX);
1367 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1368 55e46400 2020-02-18 tracey goto done;
1371 bf4484a3 2020-02-18 tracey if (gw_trans->page > 0 && gw_trans->prev_id) {
1372 9ba68833 2020-04-14 tracey href_prev = khttp_urlpartx(NULL, NULL, "gotweb", "path",
1373 9ba68833 2020-04-14 tracey KATTRX_STRING, gw_trans->repo_name, "page",
1374 9ba68833 2020-04-14 tracey KATTRX_INT, (int64_t) (gw_trans->page - 1), "action",
1375 9ba68833 2020-04-14 tracey KATTRX_STRING, "briefs", "commit", KATTRX_STRING,
1376 9ba68833 2020-04-14 tracey gw_trans->prev_id ? gw_trans->prev_id : "", "prev",
1377 9ba68833 2020-04-14 tracey KATTRX_STRING, gw_trans->prev_prev_id ?
1378 9ba68833 2020-04-14 tracey gw_trans->prev_prev_id : "", NULL);
1379 19ff7638 2020-04-14 tracey if (href_prev == NULL) {
1380 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpartx");
1381 19ff7638 2020-04-14 tracey goto done;
1383 55e46400 2020-02-18 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
1384 55e46400 2020-02-18 tracey KATTR_HREF, href_prev, KATTR__MAX);
1385 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1386 55e46400 2020-02-18 tracey goto done;
1387 55e46400 2020-02-18 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Previous");
1388 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1389 55e46400 2020-02-18 tracey goto done;
1390 55e46400 2020-02-18 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1391 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1392 55e46400 2020-02-18 tracey goto done;
1395 55e46400 2020-02-18 tracey if (gw_trans->next_id || gw_trans->page > 0) {
1396 55e46400 2020-02-18 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1397 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1398 55e46400 2020-02-18 tracey return gw_kcgi_error(kerr);
1401 55e46400 2020-02-18 tracey if (gw_trans->next_id) {
1402 55e46400 2020-02-18 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1403 55e46400 2020-02-18 tracey KATTR_ID, "nav_next", KATTR__MAX);
1404 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1405 55e46400 2020-02-18 tracey goto done;
1407 9ba68833 2020-04-14 tracey href_next = khttp_urlpartx(NULL, NULL, "gotweb", "path",
1408 9ba68833 2020-04-14 tracey KATTRX_STRING, gw_trans->repo_name, "page",
1409 9ba68833 2020-04-14 tracey KATTRX_INT, (int64_t) (gw_trans->page + 1), "action",
1410 9ba68833 2020-04-14 tracey KATTRX_STRING, "briefs", "commit", KATTRX_STRING,
1411 9ba68833 2020-04-14 tracey gw_trans->next_id, "prev", KATTRX_STRING,
1412 55e46400 2020-02-18 tracey gw_trans->next_prev_id ? gw_trans->next_prev_id : "",
1413 9ba68833 2020-04-14 tracey "prev_prev", KATTRX_STRING, gw_trans->prev_id ?
1414 19ff7638 2020-04-14 tracey gw_trans->prev_id : "", NULL);
1415 19ff7638 2020-04-14 tracey if (href_next == NULL) {
1416 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpartx");
1417 19ff7638 2020-04-14 tracey goto done;
1419 55e46400 2020-02-18 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
1420 55e46400 2020-02-18 tracey KATTR_HREF, href_next, KATTR__MAX);
1421 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1422 55e46400 2020-02-18 tracey goto done;
1423 55e46400 2020-02-18 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Next");
1424 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1425 55e46400 2020-02-18 tracey goto done;
1426 55e46400 2020-02-18 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 3);
1427 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1428 55e46400 2020-02-18 tracey goto done;
1431 55e46400 2020-02-18 tracey if (gw_trans->next_id || gw_trans->page > 0) {
1432 55e46400 2020-02-18 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
1433 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1434 55e46400 2020-02-18 tracey goto done;
1437 b0a1bc86 2020-02-14 stsp gw_free_header(header);
1438 f2f46662 2020-01-23 tracey TAILQ_FOREACH(n_header, &gw_trans->gw_headers, entry)
1439 b0a1bc86 2020-02-14 stsp gw_free_header(n_header);
1440 55ccf528 2020-02-03 stsp free(age);
1441 55e46400 2020-02-18 tracey free(href_next);
1442 55e46400 2020-02-18 tracey free(href_prev);
1443 bd275801 2020-02-03 tracey free(href_diff);
1444 9ba68833 2020-04-14 tracey free(href_tree);
1445 ef72fe2c 2020-02-04 stsp if (error == NULL && kerr != KCGI_OK)
1446 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
1447 2c251c14 2020-01-15 tracey return error;
1450 2c251c14 2020-01-15 tracey static const struct got_error *
1451 54415d85 2020-01-15 tracey gw_summary(struct gw_trans *gw_trans)
1453 387a29ba 2020-01-15 tracey const struct got_error *error = NULL;
1454 9eed6f10 2020-02-08 tracey char *age = NULL;
1455 21a55cc7 2020-02-04 tracey enum kcgi_err kerr = KCGI_OK;
1457 7a6dddae 2021-06-18 stsp #ifndef PROFILE
1458 f4df82f9 2020-01-29 stsp if (pledge("stdio rpath proc exec sendfd unveil", NULL) == -1)
1459 f4df82f9 2020-01-29 stsp return got_error_from_errno("pledge");
1461 85993e64 2020-02-17 tracey error = gw_apply_unveil(gw_trans->gw_dir->path);
1462 85993e64 2020-02-17 tracey if (error)
1463 85993e64 2020-02-17 tracey goto done;
1465 783ec107 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1466 783ec107 2020-02-03 tracey "summary_wrapper", KATTR__MAX);
1467 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
1468 2447adad 2020-02-06 stsp return gw_kcgi_error(kerr);
1470 783ec107 2020-02-03 tracey if (gw_trans->gw_conf->got_show_repo_description &&
1471 783ec107 2020-02-03 tracey gw_trans->gw_dir->description != NULL &&
1472 783ec107 2020-02-03 tracey (strcmp(gw_trans->gw_dir->description, "") != 0)) {
1473 783ec107 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1474 783ec107 2020-02-03 tracey KATTR_ID, "description_title", KATTR__MAX);
1475 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1476 783ec107 2020-02-03 tracey goto done;
1477 783ec107 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Description: ");
1478 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1479 783ec107 2020-02-03 tracey goto done;
1480 783ec107 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1481 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1482 783ec107 2020-02-03 tracey goto done;
1483 783ec107 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1484 783ec107 2020-02-03 tracey KATTR_ID, "description", KATTR__MAX);
1485 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1486 783ec107 2020-02-03 tracey goto done;
1487 783ec107 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req,
1488 783ec107 2020-02-03 tracey gw_trans->gw_dir->description);
1489 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1490 783ec107 2020-02-03 tracey goto done;
1491 783ec107 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1492 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1493 783ec107 2020-02-03 tracey goto done;
1496 9a1cc63f 2020-02-03 stsp if (gw_trans->gw_conf->got_show_repo_owner &&
1497 a942aa37 2020-02-10 tracey gw_trans->gw_dir->owner != NULL &&
1498 a942aa37 2020-02-10 tracey (strcmp(gw_trans->gw_dir->owner, "") != 0)) {
1499 783ec107 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1500 783ec107 2020-02-03 tracey KATTR_ID, "repo_owner_title", KATTR__MAX);
1501 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1502 9a1cc63f 2020-02-03 stsp goto done;
1503 783ec107 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Owner: ");
1504 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1505 9a1cc63f 2020-02-03 stsp goto done;
1506 783ec107 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1507 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1508 783ec107 2020-02-03 tracey goto done;
1509 783ec107 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1510 783ec107 2020-02-03 tracey KATTR_ID, "repo_owner", KATTR__MAX);
1511 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1512 783ec107 2020-02-03 tracey goto done;
1513 783ec107 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req,
1514 62d463ca 2020-10-20 naddy gw_trans->gw_dir->owner);
1515 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1516 783ec107 2020-02-03 tracey goto done;
1517 783ec107 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1518 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1519 783ec107 2020-02-03 tracey goto done;
1522 46b9c89b 2020-01-15 tracey if (gw_trans->gw_conf->got_show_repo_age) {
1523 d126c1b7 2020-01-29 stsp error = gw_get_repo_age(&age, gw_trans, gw_trans->gw_dir->path,
1524 2011c142 2020-02-14 stsp NULL, TM_LONG);
1525 d126c1b7 2020-01-29 stsp if (error)
1526 20f34652 2020-01-29 stsp goto done;
1527 55ccf528 2020-02-03 stsp if (age != NULL) {
1528 783ec107 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1529 783ec107 2020-02-03 tracey KATTR_ID, "last_change_title", KATTR__MAX);
1530 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1531 20f34652 2020-01-29 stsp goto done;
1532 783ec107 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req,
1533 783ec107 2020-02-03 tracey "Last Change: ");
1534 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1535 20f34652 2020-01-29 stsp goto done;
1536 783ec107 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1537 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1538 20f34652 2020-01-29 stsp goto done;
1539 783ec107 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1540 783ec107 2020-02-03 tracey KATTR_ID, "last_change", KATTR__MAX);
1541 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1542 20f34652 2020-01-29 stsp goto done;
1543 783ec107 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req, age);
1544 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1545 783ec107 2020-02-03 tracey goto done;
1546 783ec107 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1547 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1548 783ec107 2020-02-03 tracey goto done;
1552 783ec107 2020-02-03 tracey if (gw_trans->gw_conf->got_show_repo_cloneurl &&
1553 783ec107 2020-02-03 tracey gw_trans->gw_dir->url != NULL &&
1554 783ec107 2020-02-03 tracey (strcmp(gw_trans->gw_dir->url, "") != 0)) {
1555 783ec107 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1556 783ec107 2020-02-03 tracey KATTR_ID, "cloneurl_title", KATTR__MAX);
1557 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1558 783ec107 2020-02-03 tracey goto done;
1559 783ec107 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Clone URL: ");
1560 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1561 783ec107 2020-02-03 tracey goto done;
1562 783ec107 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1563 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1564 783ec107 2020-02-03 tracey goto done;
1565 783ec107 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1566 783ec107 2020-02-03 tracey KATTR_ID, "cloneurl", KATTR__MAX);
1567 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1568 783ec107 2020-02-03 tracey goto done;
1569 783ec107 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req, gw_trans->gw_dir->url);
1570 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1571 21a55cc7 2020-02-04 tracey goto done;
1572 783ec107 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1573 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1574 783ec107 2020-02-03 tracey goto done;
1577 783ec107 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1578 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1579 bd275801 2020-02-03 tracey goto done;
1581 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1582 bd275801 2020-02-03 tracey "briefs_title_wrapper", KATTR__MAX);
1583 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1584 bd275801 2020-02-03 tracey goto done;
1585 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1586 bd275801 2020-02-03 tracey "briefs_title", KATTR__MAX);
1587 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1588 20f34652 2020-01-29 stsp goto done;
1589 bd275801 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Commit Briefs");
1590 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1591 bd275801 2020-02-03 tracey goto done;
1592 bd275801 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
1593 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1594 bd275801 2020-02-03 tracey goto done;
1595 f2f46662 2020-01-23 tracey error = gw_briefs(gw_trans);
1596 f2f46662 2020-01-23 tracey if (error)
1597 20f34652 2020-01-29 stsp goto done;
1599 ff4bb25f 2020-02-19 tracey error = gw_tags(gw_trans);
1600 6eccd105 2020-02-03 stsp if (error)
1601 6eccd105 2020-02-03 stsp goto done;
1603 9eed6f10 2020-02-08 tracey error = gw_output_repo_heads(gw_trans);
1605 20f34652 2020-01-29 stsp free(age);
1606 f7cc9480 2020-02-05 tracey if (error == NULL && kerr != KCGI_OK)
1607 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
1608 2204c934 2020-01-15 tracey return error;
1611 2204c934 2020-01-15 tracey static const struct got_error *
1612 f2f46662 2020-01-23 tracey gw_tree(struct gw_trans *gw_trans)
1614 b772de24 2020-01-15 tracey const struct got_error *error = NULL;
1615 f2f46662 2020-01-23 tracey struct gw_header *header = NULL;
1616 f2f46662 2020-01-23 tracey char *tree = NULL, *tree_html = NULL, *tree_html_disp = NULL;
1617 53e81e48 2020-02-13 tracey char *age = NULL;
1618 795c10a4 2020-02-20 tracey enum kcgi_err kerr = KCGI_OK;
1620 7a6dddae 2021-06-18 stsp #ifndef PROFILE
1621 f2f46662 2020-01-23 tracey if (pledge("stdio rpath proc exec sendfd unveil", NULL) == -1)
1622 f2f46662 2020-01-23 tracey return got_error_from_errno("pledge");
1624 ae36ed87 2020-01-28 stsp if ((header = gw_init_header()) == NULL)
1625 f2f46662 2020-01-23 tracey return got_error_from_errno("malloc");
1627 d4159696 2020-02-13 stsp error = gw_apply_unveil(gw_trans->gw_dir->path);
1628 b772de24 2020-01-15 tracey if (error)
1629 5ddf0079 2020-01-29 stsp goto done;
1631 f2f46662 2020-01-23 tracey error = gw_get_header(gw_trans, header, 1);
1632 f2f46662 2020-01-23 tracey if (error)
1633 42281175 2020-01-29 stsp goto done;
1635 626b25b6 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1636 626b25b6 2020-02-06 tracey "tree_header_wrapper", KATTR__MAX);
1637 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
1638 55ccf528 2020-02-03 stsp goto done;
1639 626b25b6 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1640 626b25b6 2020-02-06 tracey "tree_header", KATTR__MAX);
1641 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
1642 55ccf528 2020-02-03 stsp goto done;
1643 626b25b6 2020-02-06 tracey error = gw_gen_tree_header(gw_trans, header->tree_id);
1644 626b25b6 2020-02-06 tracey if (error)
1645 626b25b6 2020-02-06 tracey goto done;
1646 626b25b6 2020-02-06 tracey error = gw_get_time_str(&age, header->committer_time,
1647 626b25b6 2020-02-06 tracey TM_LONG);
1648 626b25b6 2020-02-06 tracey if (error)
1649 626b25b6 2020-02-06 tracey goto done;
1650 626b25b6 2020-02-06 tracey error = gw_gen_age_header(gw_trans, age ?age : "");
1651 070fee27 2020-02-03 stsp if (error)
1652 070fee27 2020-02-03 stsp goto done;
1653 626b25b6 2020-02-06 tracey error = gw_gen_commit_msg_header(gw_trans, header->commit_msg);
1654 626b25b6 2020-02-06 tracey if (error)
1655 42281175 2020-01-29 stsp goto done;
1656 626b25b6 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
1657 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
1658 42281175 2020-01-29 stsp goto done;
1659 626b25b6 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1660 626b25b6 2020-02-06 tracey "dotted_line", KATTR__MAX);
1661 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
1662 626b25b6 2020-02-06 tracey goto done;
1663 626b25b6 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1664 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
1665 626b25b6 2020-02-06 tracey goto done;
1667 626b25b6 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1668 626b25b6 2020-02-06 tracey "tree", KATTR__MAX);
1669 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
1670 626b25b6 2020-02-06 tracey goto done;
1671 84de9106 2020-12-26 stsp error = gw_output_repo_tree(gw_trans, header);
1672 626b25b6 2020-02-06 tracey if (error)
1673 626b25b6 2020-02-06 tracey goto done;
1675 626b25b6 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1677 b0a1bc86 2020-02-14 stsp gw_free_header(header);
1678 f2f46662 2020-01-23 tracey free(tree_html_disp);
1679 f2f46662 2020-01-23 tracey free(tree_html);
1680 f2f46662 2020-01-23 tracey free(tree);
1681 55ccf528 2020-02-03 stsp free(age);
1682 ff4bb25f 2020-02-19 tracey if (error == NULL && kerr != KCGI_OK)
1683 ff4bb25f 2020-02-19 tracey error = gw_kcgi_error(kerr);
1684 ff4bb25f 2020-02-19 tracey return error;
1687 ff4bb25f 2020-02-19 tracey static const struct got_error *
1688 ff4bb25f 2020-02-19 tracey gw_tags(struct gw_trans *gw_trans)
1690 ff4bb25f 2020-02-19 tracey const struct got_error *error = NULL;
1691 ff4bb25f 2020-02-19 tracey struct gw_header *header = NULL;
1692 ff4bb25f 2020-02-19 tracey char *href_next = NULL, *href_prev = NULL;
1693 ff4bb25f 2020-02-19 tracey enum kcgi_err kerr = KCGI_OK;
1695 7a6dddae 2021-06-18 stsp #ifndef PROFILE
1696 ff4bb25f 2020-02-19 tracey if (pledge("stdio rpath proc exec sendfd unveil", NULL) == -1)
1697 ff4bb25f 2020-02-19 tracey return got_error_from_errno("pledge");
1699 ff4bb25f 2020-02-19 tracey if ((header = gw_init_header()) == NULL)
1700 ff4bb25f 2020-02-19 tracey return got_error_from_errno("malloc");
1702 ff4bb25f 2020-02-19 tracey if (gw_trans->action != GW_SUMMARY) {
1703 ff4bb25f 2020-02-19 tracey error = gw_apply_unveil(gw_trans->gw_dir->path);
1704 ff4bb25f 2020-02-19 tracey if (error)
1705 ff4bb25f 2020-02-19 tracey goto done;
1708 ff4bb25f 2020-02-19 tracey error = gw_get_header(gw_trans, header, 1);
1709 ff4bb25f 2020-02-19 tracey if (error)
1710 ff4bb25f 2020-02-19 tracey goto done;
1712 ff4bb25f 2020-02-19 tracey if (gw_trans->action == GW_SUMMARY) {
1713 7b1f04a6 2020-03-11 tracey gw_trans->next_id = NULL;
1714 ff4bb25f 2020-02-19 tracey error = gw_output_repo_tags(gw_trans, header,
1715 ff4bb25f 2020-02-19 tracey D_MAXSLCOMMDISP, TAGBRIEF);
1716 ff4bb25f 2020-02-19 tracey if (error)
1717 ff4bb25f 2020-02-19 tracey goto done;
1718 ff4bb25f 2020-02-19 tracey } else {
1719 ff4bb25f 2020-02-19 tracey error = gw_output_repo_tags(gw_trans, header,
1720 ff4bb25f 2020-02-19 tracey gw_trans->gw_conf->got_max_commits_display, TAGBRIEF);
1721 ff4bb25f 2020-02-19 tracey if (error)
1722 ff4bb25f 2020-02-19 tracey goto done;
1725 ff4bb25f 2020-02-19 tracey if (gw_trans->next_id || gw_trans->page > 0) {
1726 ff4bb25f 2020-02-19 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1727 ff4bb25f 2020-02-19 tracey KATTR_ID, "np_wrapper", KATTR__MAX);
1728 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
1729 ff4bb25f 2020-02-19 tracey goto done;
1730 ff4bb25f 2020-02-19 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1731 ff4bb25f 2020-02-19 tracey KATTR_ID, "nav_prev", KATTR__MAX);
1732 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
1733 ff4bb25f 2020-02-19 tracey goto done;
1736 ff4bb25f 2020-02-19 tracey if (gw_trans->page > 0 && gw_trans->prev_id) {
1737 f7632464 2020-04-14 tracey href_prev = khttp_urlpartx(NULL, NULL, "gotweb", "path",
1738 f7632464 2020-04-14 tracey KATTRX_STRING, gw_trans->repo_name, "page",
1739 f7632464 2020-04-14 tracey KATTRX_INT, (int64_t) (gw_trans->page - 1), "action",
1740 f7632464 2020-04-14 tracey KATTRX_STRING, "tags", "commit", KATTRX_STRING,
1741 f7632464 2020-04-14 tracey gw_trans->prev_id ? gw_trans->prev_id : "", "prev",
1742 f7632464 2020-04-14 tracey KATTRX_STRING, gw_trans->prev_prev_id ?
1743 f7632464 2020-04-14 tracey gw_trans->prev_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 f7632464 2020-04-14 tracey gw_trans->next_id, "prev", KATTRX_STRING,
1776 ff4bb25f 2020-02-19 tracey gw_trans->next_prev_id ? gw_trans->next_prev_id : "",
1777 f7632464 2020-04-14 tracey "prev_prev", KATTRX_STRING, gw_trans->prev_id ?
1778 f7632464 2020-04-14 tracey gw_trans->prev_id : "", NULL);
1779 19ff7638 2020-04-14 tracey if (href_next == NULL) {
1780 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpartx");
1781 19ff7638 2020-04-14 tracey goto done;
1783 ff4bb25f 2020-02-19 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
1784 ff4bb25f 2020-02-19 tracey KATTR_HREF, href_next, KATTR__MAX);
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_puts(gw_trans->gw_html_req, "Next");
1788 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
1789 ff4bb25f 2020-02-19 tracey goto done;
1790 ff4bb25f 2020-02-19 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 3);
1791 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
1792 ff4bb25f 2020-02-19 tracey goto done;
1795 ff4bb25f 2020-02-19 tracey if (gw_trans->next_id || gw_trans->page > 0) {
1796 ff4bb25f 2020-02-19 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
1797 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
1798 ff4bb25f 2020-02-19 tracey goto done;
1801 ff4bb25f 2020-02-19 tracey gw_free_header(header);
1802 ff4bb25f 2020-02-19 tracey free(href_next);
1803 ff4bb25f 2020-02-19 tracey free(href_prev);
1804 626b25b6 2020-02-06 tracey if (error == NULL && kerr != KCGI_OK)
1805 626b25b6 2020-02-06 tracey error = gw_kcgi_error(kerr);
1806 4ff7391f 2020-01-28 tracey return error;
1809 4ff7391f 2020-01-28 tracey static const struct got_error *
1810 4ff7391f 2020-01-28 tracey gw_tag(struct gw_trans *gw_trans)
1812 4ff7391f 2020-01-28 tracey const struct got_error *error = NULL;
1813 4ff7391f 2020-01-28 tracey struct gw_header *header = NULL;
1814 795c10a4 2020-02-20 tracey enum kcgi_err kerr = KCGI_OK;
1816 7a6dddae 2021-06-18 stsp #ifndef PROFILE
1817 4ff7391f 2020-01-28 tracey if (pledge("stdio rpath proc exec sendfd unveil", NULL) == -1)
1818 4ff7391f 2020-01-28 tracey return got_error_from_errno("pledge");
1820 4ff7391f 2020-01-28 tracey if ((header = gw_init_header()) == NULL)
1821 4ff7391f 2020-01-28 tracey return got_error_from_errno("malloc");
1823 d4159696 2020-02-13 stsp error = gw_apply_unveil(gw_trans->gw_dir->path);
1824 4ff7391f 2020-01-28 tracey if (error)
1825 5ddf0079 2020-01-29 stsp goto done;
1827 9f33591a 2020-02-14 tracey if (gw_trans->commit_id == NULL) {
1828 9f33591a 2020-02-14 tracey error = got_error_msg(GOT_ERR_QUERYSTRING,
1829 9f33591a 2020-02-14 tracey "commit required in querystring");
1830 9f33591a 2020-02-14 tracey goto done;
1833 4ff7391f 2020-01-28 tracey error = gw_get_header(gw_trans, header, 1);
1834 4ff7391f 2020-01-28 tracey if (error)
1835 470cd826 2020-01-29 stsp goto done;
1837 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1838 38b240fb 2020-02-06 tracey "tag_header_wrapper", KATTR__MAX);
1839 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
1840 38b240fb 2020-02-06 tracey goto done;
1841 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1842 38b240fb 2020-02-06 tracey "tag_header", KATTR__MAX);
1843 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
1844 38b240fb 2020-02-06 tracey goto done;
1845 38b240fb 2020-02-06 tracey error = gw_gen_commit_header(gw_trans, header->commit_id,
1846 38b240fb 2020-02-06 tracey header->refs_str);
1847 6eccd105 2020-02-03 stsp if (error)
1848 6eccd105 2020-02-03 stsp goto done;
1849 38b240fb 2020-02-06 tracey error = gw_gen_commit_msg_header(gw_trans, header->commit_msg);
1850 38b240fb 2020-02-06 tracey if (error)
1851 470cd826 2020-01-29 stsp goto done;
1852 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
1853 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
1854 470cd826 2020-01-29 stsp goto done;
1855 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1856 38b240fb 2020-02-06 tracey "dotted_line", KATTR__MAX);
1857 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
1858 38b240fb 2020-02-06 tracey goto done;
1859 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1860 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
1861 38b240fb 2020-02-06 tracey goto done;
1863 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1864 38b240fb 2020-02-06 tracey "tree", KATTR__MAX);
1865 4ff7391f 2020-01-28 tracey if (kerr != KCGI_OK)
1866 38b240fb 2020-02-06 tracey goto done;
1868 38b240fb 2020-02-06 tracey error = gw_output_repo_tags(gw_trans, header, 1, TAGFULL);
1869 38b240fb 2020-02-06 tracey if (error)
1870 38b240fb 2020-02-06 tracey goto done;
1872 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1874 b0a1bc86 2020-02-14 stsp gw_free_header(header);
1875 38b240fb 2020-02-06 tracey if (error == NULL && kerr != KCGI_OK)
1876 38b240fb 2020-02-06 tracey error = gw_kcgi_error(kerr);
1877 2c251c14 2020-01-15 tracey return error;
1880 2c251c14 2020-01-15 tracey static const struct got_error *
1881 54415d85 2020-01-15 tracey gw_load_got_path(struct gw_trans *gw_trans, struct gw_dir *gw_dir)
1883 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
1884 2c251c14 2020-01-15 tracey DIR *dt;
1885 2c251c14 2020-01-15 tracey char *dir_test;
1886 4ceb8155 2020-01-15 tracey int opened = 0;
1888 88d59c36 2020-01-29 stsp if (asprintf(&dir_test, "%s/%s/%s",
1889 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_repos_path, gw_dir->name,
1890 88d59c36 2020-01-29 stsp GOTWEB_GIT_DIR) == -1)
1891 2c251c14 2020-01-15 tracey return got_error_from_errno("asprintf");
1893 2c251c14 2020-01-15 tracey dt = opendir(dir_test);
1894 2c251c14 2020-01-15 tracey if (dt == NULL) {
1895 2c251c14 2020-01-15 tracey free(dir_test);
1896 2c251c14 2020-01-15 tracey } else {
1897 d1635ae4 2020-02-13 tracey gw_dir->path = strdup(dir_test);
1898 d1635ae4 2020-02-13 tracey if (gw_dir->path == NULL) {
1899 d1635ae4 2020-02-13 tracey opened = 1;
1900 d1635ae4 2020-02-13 tracey error = got_error_from_errno("strdup");
1901 a942aa37 2020-02-10 tracey goto errored;
1903 d1635ae4 2020-02-13 tracey opened = 1;
1904 2c251c14 2020-01-15 tracey goto done;
1907 88d59c36 2020-01-29 stsp if (asprintf(&dir_test, "%s/%s/%s",
1908 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_repos_path, gw_dir->name,
1909 d81f9039 2020-02-13 stsp GOTWEB_GOT_DIR) == -1) {
1910 d81f9039 2020-02-13 stsp dir_test = NULL;
1911 d81f9039 2020-02-13 stsp error = got_error_from_errno("asprintf");
1912 d81f9039 2020-02-13 stsp goto errored;
1915 2c251c14 2020-01-15 tracey dt = opendir(dir_test);
1916 2c251c14 2020-01-15 tracey if (dt == NULL)
1917 2c251c14 2020-01-15 tracey free(dir_test);
1919 4ceb8155 2020-01-15 tracey opened = 1;
1920 2c251c14 2020-01-15 tracey error = got_error(GOT_ERR_NOT_GIT_REPO);
1921 2c251c14 2020-01-15 tracey goto errored;
1924 88d59c36 2020-01-29 stsp if (asprintf(&dir_test, "%s/%s",
1925 d81f9039 2020-02-13 stsp gw_trans->gw_conf->got_repos_path, gw_dir->name) == -1) {
1926 d81f9039 2020-02-13 stsp error = got_error_from_errno("asprintf");
1927 d81f9039 2020-02-13 stsp dir_test = NULL;
1928 d81f9039 2020-02-13 stsp goto errored;
1931 d1635ae4 2020-02-13 tracey gw_dir->path = strdup(dir_test);
1932 d1635ae4 2020-02-13 tracey if (gw_dir->path == NULL) {
1933 a942aa37 2020-02-10 tracey opened = 1;
1934 d1635ae4 2020-02-13 tracey error = got_error_from_errno("strdup");
1935 a942aa37 2020-02-10 tracey goto errored;
1938 cc18a904 2020-02-13 tracey dt = opendir(dir_test);
1939 cc18a904 2020-02-13 tracey if (dt == NULL) {
1940 d90bcdd6 2020-02-17 stsp error = got_error_path(gw_dir->name, GOT_ERR_NOT_GIT_REPO);
1941 cc18a904 2020-02-13 tracey goto errored;
1943 7ecc73af 2020-02-13 tracey opened = 1;
1945 32cd4d18 2020-02-03 stsp error = gw_get_repo_description(&gw_dir->description, gw_trans,
1946 2c251c14 2020-01-15 tracey gw_dir->path);
1947 32cd4d18 2020-02-03 stsp if (error)
1948 32cd4d18 2020-02-03 stsp goto errored;
1949 9a1cc63f 2020-02-03 stsp error = gw_get_repo_owner(&gw_dir->owner, gw_trans, gw_dir->path);
1950 9a1cc63f 2020-02-03 stsp if (error)
1951 9a1cc63f 2020-02-03 stsp goto errored;
1952 d126c1b7 2020-01-29 stsp error = gw_get_repo_age(&gw_dir->age, gw_trans, gw_dir->path,
1953 2011c142 2020-02-14 stsp NULL, TM_DIFF);
1954 d126c1b7 2020-01-29 stsp if (error)
1955 d126c1b7 2020-01-29 stsp goto errored;
1956 59d3c40e 2020-02-03 stsp error = gw_get_clone_url(&gw_dir->url, gw_trans, gw_dir->path);
1957 2c251c14 2020-01-15 tracey errored:
1958 2c251c14 2020-01-15 tracey free(dir_test);
1959 2c251c14 2020-01-15 tracey if (opened)
1960 795c5bd7 2020-02-17 tracey if (dt && closedir(dt) == -1 && error == NULL)
1961 e227880d 2020-02-17 tracey error = got_error_from_errno("closedir");
1962 2c251c14 2020-01-15 tracey return error;
1965 2c251c14 2020-01-15 tracey static const struct got_error *
1966 54415d85 2020-01-15 tracey gw_load_got_paths(struct gw_trans *gw_trans)
1968 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
1970 2c251c14 2020-01-15 tracey struct dirent **sd_dent;
1971 2c251c14 2020-01-15 tracey struct gw_dir *gw_dir;
1972 2c251c14 2020-01-15 tracey struct stat st;
1973 2c251c14 2020-01-15 tracey unsigned int d_cnt, d_i;
1975 2c251c14 2020-01-15 tracey d = opendir(gw_trans->gw_conf->got_repos_path);
1976 2c251c14 2020-01-15 tracey if (d == NULL) {
1977 2c251c14 2020-01-15 tracey error = got_error_from_errno2("opendir",
1978 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_repos_path);
1979 2c251c14 2020-01-15 tracey return error;
1982 2c251c14 2020-01-15 tracey d_cnt = scandir(gw_trans->gw_conf->got_repos_path, &sd_dent, NULL,
1983 2c251c14 2020-01-15 tracey alphasort);
1984 2c251c14 2020-01-15 tracey if (d_cnt == -1) {
1985 2c251c14 2020-01-15 tracey error = got_error_from_errno2("scandir",
1986 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_repos_path);
1987 8182bd34 2020-02-17 tracey goto done;
1990 2c251c14 2020-01-15 tracey for (d_i = 0; d_i < d_cnt; d_i++) {
1991 2c251c14 2020-01-15 tracey if (gw_trans->gw_conf->got_max_repos > 0 &&
1992 2c251c14 2020-01-15 tracey (d_i - 2) == gw_trans->gw_conf->got_max_repos)
1993 2c251c14 2020-01-15 tracey break; /* account for parent and self */
1995 2c251c14 2020-01-15 tracey if (strcmp(sd_dent[d_i]->d_name, ".") == 0 ||
1996 2c251c14 2020-01-15 tracey strcmp(sd_dent[d_i]->d_name, "..") == 0)
1997 2c251c14 2020-01-15 tracey continue;
1999 4619e1f2 2020-02-13 stsp error = gw_init_gw_dir(&gw_dir, sd_dent[d_i]->d_name);
2000 4619e1f2 2020-02-13 stsp if (error)
2001 8182bd34 2020-02-17 tracey goto done;
2003 2c251c14 2020-01-15 tracey error = gw_load_got_path(gw_trans, gw_dir);
2004 7bf16821 2020-02-07 stsp if (error && error->code == GOT_ERR_NOT_GIT_REPO) {
2005 7bf16821 2020-02-07 stsp error = NULL;
2006 2c251c14 2020-01-15 tracey continue;
2008 2c251c14 2020-01-15 tracey else if (error)
2009 8182bd34 2020-02-17 tracey goto done;
2011 2c251c14 2020-01-15 tracey if (lstat(gw_dir->path, &st) == 0 && S_ISDIR(st.st_mode) &&
2012 2c251c14 2020-01-15 tracey !got_path_dir_is_empty(gw_dir->path)) {
2013 2c251c14 2020-01-15 tracey TAILQ_INSERT_TAIL(&gw_trans->gw_dirs, gw_dir,
2015 2c251c14 2020-01-15 tracey gw_trans->repos_total++;
2019 e227880d 2020-02-17 tracey if (d && closedir(d) == -1 && error == NULL)
2020 e227880d 2020-02-17 tracey error = got_error_from_errno("closedir");
2021 2c251c14 2020-01-15 tracey return error;
2024 2c251c14 2020-01-15 tracey static const struct got_error *
2025 54415d85 2020-01-15 tracey gw_parse_querystring(struct gw_trans *gw_trans)
2027 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
2028 2c251c14 2020-01-15 tracey struct kpair *p;
2029 2c251c14 2020-01-15 tracey struct gw_query_action *action = NULL;
2030 2c251c14 2020-01-15 tracey unsigned int i;
2032 2c251c14 2020-01-15 tracey if (gw_trans->gw_req->fieldnmap[0]) {
2033 8f214b62 2020-02-17 stsp return got_error(GOT_ERR_QUERYSTRING);
2034 2c251c14 2020-01-15 tracey } else if ((p = gw_trans->gw_req->fieldmap[KEY_PATH])) {
2035 2c251c14 2020-01-15 tracey /* define gw_trans->repo_path */
2036 f652ec0c 2020-02-13 stsp gw_trans->repo_name = p->parsed.s;
2038 88d59c36 2020-01-29 stsp if (asprintf(&gw_trans->repo_path, "%s/%s",
2039 88d59c36 2020-01-29 stsp gw_trans->gw_conf->got_repos_path, p->parsed.s) == -1)
2040 2c251c14 2020-01-15 tracey return got_error_from_errno("asprintf");
2042 2c251c14 2020-01-15 tracey /* get action and set function */
2043 f1200fe3 2020-02-13 tracey if ((p = gw_trans->gw_req->fieldmap[KEY_ACTION])) {
2044 2c251c14 2020-01-15 tracey for (i = 0; i < nitems(gw_query_funcs); i++) {
2045 2c251c14 2020-01-15 tracey action = &gw_query_funcs[i];
2046 f1200fe3 2020-02-13 tracey if (action->func_name == NULL)
2047 2c251c14 2020-01-15 tracey continue;
2048 f1200fe3 2020-02-13 tracey if (strcmp(action->func_name,
2049 f1200fe3 2020-02-13 tracey p->parsed.s) == 0) {
2050 f1200fe3 2020-02-13 tracey gw_trans->action = i;
2055 6f6f771f 2020-02-13 tracey if (gw_trans->action == -1) {
2056 6f6f771f 2020-02-13 tracey gw_trans->action = GW_ERR;
2057 8f214b62 2020-02-17 stsp gw_trans->error = got_error_msg(GOT_ERR_QUERYSTRING,
2058 8f214b62 2020-02-17 stsp p != NULL ? "bad action in querystring" :
2059 8f214b62 2020-02-17 stsp "no action in querystring");
2060 cc18a904 2020-02-13 tracey return error;
2063 26dc3004 2020-02-13 stsp if ((p = gw_trans->gw_req->fieldmap[KEY_COMMIT_ID])) {
2064 56997cd3 2020-02-14 tracey if (asprintf(&gw_trans->commit_id, "%s",
2065 88d59c36 2020-01-29 stsp p->parsed.s) == -1)
2066 ec46ccd7 2020-01-15 tracey return got_error_from_errno("asprintf");
2069 4d6abe2b 2020-02-13 stsp if ((p = gw_trans->gw_req->fieldmap[KEY_FILE]))
2070 4d6abe2b 2020-02-13 stsp gw_trans->repo_file = p->parsed.s;
2072 26dc3004 2020-02-13 stsp if ((p = gw_trans->gw_req->fieldmap[KEY_FOLDER])) {
2073 88d59c36 2020-01-29 stsp if (asprintf(&gw_trans->repo_folder, "%s",
2074 55e46400 2020-02-18 tracey p->parsed.s) == -1)
2075 55e46400 2020-02-18 tracey return got_error_from_errno("asprintf");
2078 55e46400 2020-02-18 tracey if ((p = gw_trans->gw_req->fieldmap[KEY_PREV_ID])) {
2079 55e46400 2020-02-18 tracey if (asprintf(&gw_trans->prev_id, "%s",
2080 55e46400 2020-02-18 tracey p->parsed.s) == -1)
2081 55e46400 2020-02-18 tracey return got_error_from_errno("asprintf");
2084 55e46400 2020-02-18 tracey if ((p = gw_trans->gw_req->fieldmap[KEY_PREV_PREV_ID])) {
2085 55e46400 2020-02-18 tracey if (asprintf(&gw_trans->prev_prev_id, "%s",
2086 88d59c36 2020-01-29 stsp p->parsed.s) == -1)
2087 ec46ccd7 2020-01-15 tracey return got_error_from_errno("asprintf");
2090 742ba378 2020-02-14 stsp if ((p = gw_trans->gw_req->fieldmap[KEY_HEADREF]))
2091 742ba378 2020-02-14 stsp gw_trans->headref = p->parsed.s;
2093 4619e1f2 2020-02-13 stsp error = gw_init_gw_dir(&gw_trans->gw_dir, gw_trans->repo_name);
2094 4619e1f2 2020-02-13 stsp if (error)
2095 4619e1f2 2020-02-13 stsp return error;
2097 cc18a904 2020-02-13 tracey gw_trans->error = gw_load_got_path(gw_trans, gw_trans->gw_dir);
2099 2c251c14 2020-01-15 tracey gw_trans->action = GW_INDEX;
2101 2c251c14 2020-01-15 tracey if ((p = gw_trans->gw_req->fieldmap[KEY_PAGE]))
2102 2c251c14 2020-01-15 tracey gw_trans->page = p->parsed.i;
2104 2c251c14 2020-01-15 tracey return error;
2107 4619e1f2 2020-02-13 stsp static const struct got_error *
2108 f652ec0c 2020-02-13 stsp gw_init_gw_dir(struct gw_dir **gw_dir, const char *dir)
2110 4619e1f2 2020-02-13 stsp const struct got_error *error;
2112 4619e1f2 2020-02-13 stsp *gw_dir = malloc(sizeof(**gw_dir));
2113 4619e1f2 2020-02-13 stsp if (*gw_dir == NULL)
2114 4619e1f2 2020-02-13 stsp return got_error_from_errno("malloc");
2116 4619e1f2 2020-02-13 stsp if (asprintf(&(*gw_dir)->name, "%s", dir) == -1) {
2117 4619e1f2 2020-02-13 stsp error = got_error_from_errno("asprintf");
2118 4619e1f2 2020-02-13 stsp free(*gw_dir);
2119 4619e1f2 2020-02-13 stsp *gw_dir = NULL;
2120 e9a8bbf7 2020-05-29 tracey return error;
2123 4619e1f2 2020-02-13 stsp return NULL;
2126 c25c2314 2020-01-28 stsp static const struct got_error *
2127 54415d85 2020-01-15 tracey gw_display_open(struct gw_trans *gw_trans, enum khttp code, enum kmime mime)
2129 795c10a4 2020-02-20 tracey enum kcgi_err kerr = KCGI_OK;
2131 c25c2314 2020-01-28 stsp kerr = khttp_head(gw_trans->gw_req, kresps[KRESP_ALLOW], "GET");
2132 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
2133 2447adad 2020-02-06 stsp return gw_kcgi_error(kerr);
2134 c25c2314 2020-01-28 stsp kerr = khttp_head(gw_trans->gw_req, kresps[KRESP_STATUS], "%s",
2135 2c251c14 2020-01-15 tracey khttps[code]);
2136 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
2137 2447adad 2020-02-06 stsp return gw_kcgi_error(kerr);
2138 c25c2314 2020-01-28 stsp kerr = khttp_head(gw_trans->gw_req, kresps[KRESP_CONTENT_TYPE], "%s",
2139 2c251c14 2020-01-15 tracey kmimetypes[mime]);
2140 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
2141 2447adad 2020-02-06 stsp return gw_kcgi_error(kerr);
2142 017d6da3 2020-01-29 tracey kerr = khttp_head(gw_trans->gw_req, "X-Content-Type-Options",
2143 017d6da3 2020-01-29 tracey "nosniff");
2144 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
2145 2447adad 2020-02-06 stsp return gw_kcgi_error(kerr);
2146 c25c2314 2020-01-28 stsp kerr = khttp_head(gw_trans->gw_req, "X-Frame-Options", "DENY");
2147 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
2148 2447adad 2020-02-06 stsp return gw_kcgi_error(kerr);
2149 017d6da3 2020-01-29 tracey kerr = khttp_head(gw_trans->gw_req, "X-XSS-Protection",
2150 017d6da3 2020-01-29 tracey "1; mode=block");
2151 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
2152 2447adad 2020-02-06 stsp return gw_kcgi_error(kerr);
2154 017d6da3 2020-01-29 tracey if (gw_trans->mime == KMIME_APP_OCTET_STREAM) {
2155 017d6da3 2020-01-29 tracey kerr = khttp_head(gw_trans->gw_req,
2156 017d6da3 2020-01-29 tracey kresps[KRESP_CONTENT_DISPOSITION],
2157 017d6da3 2020-01-29 tracey "attachment; filename=%s", gw_trans->repo_file);
2158 017d6da3 2020-01-29 tracey if (kerr != KCGI_OK)
2159 2447adad 2020-02-06 stsp return gw_kcgi_error(kerr);
2162 c25c2314 2020-01-28 stsp kerr = khttp_body(gw_trans->gw_req);
2163 2447adad 2020-02-06 stsp return gw_kcgi_error(kerr);
2166 c25c2314 2020-01-28 stsp static const struct got_error *
2167 6d8d8a26 2020-01-29 stsp gw_display_index(struct gw_trans *gw_trans)
2169 4bec7539 2020-01-29 stsp const struct got_error *error;
2170 795c10a4 2020-02-20 tracey enum kcgi_err kerr = KCGI_OK;
2172 cc18a904 2020-02-13 tracey /* catch early querystring errors */
2173 cc18a904 2020-02-13 tracey if (gw_trans->error)
2174 cc18a904 2020-02-13 tracey gw_trans->action = GW_ERR;
2176 4bec7539 2020-01-29 stsp error = gw_display_open(gw_trans, KHTTP_200, gw_trans->mime);
2177 4bec7539 2020-01-29 stsp if (error)
2178 4bec7539 2020-01-29 stsp return error;
2180 f7cc9480 2020-02-05 tracey kerr = khtml_open(gw_trans->gw_html_req, gw_trans->gw_req, 0);
2181 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2182 2447adad 2020-02-06 stsp return gw_kcgi_error(kerr);
2184 017d6da3 2020-01-29 tracey if (gw_trans->action != GW_BLOB) {
2185 017d6da3 2020-01-29 tracey kerr = khttp_template(gw_trans->gw_req, gw_trans->gw_tmpl,
2186 017d6da3 2020-01-29 tracey gw_query_funcs[gw_trans->action].template);
2187 017d6da3 2020-01-29 tracey if (kerr != KCGI_OK) {
2188 017d6da3 2020-01-29 tracey khtml_close(gw_trans->gw_html_req);
2189 2447adad 2020-02-06 stsp return gw_kcgi_error(kerr);
2193 7a9bfbff 2020-01-29 stsp return gw_kcgi_error(khtml_close(gw_trans->gw_html_req));
2196 f1200fe3 2020-02-13 tracey static const struct got_error *
2197 f1200fe3 2020-02-13 tracey gw_error(struct gw_trans *gw_trans)
2199 795c10a4 2020-02-20 tracey enum kcgi_err kerr = KCGI_OK;
2201 f1200fe3 2020-02-13 tracey kerr = khtml_puts(gw_trans->gw_html_req, gw_trans->error->msg);
2203 f1200fe3 2020-02-13 tracey return gw_kcgi_error(kerr);
2206 2c251c14 2020-01-15 tracey static int
2207 2c251c14 2020-01-15 tracey gw_template(size_t key, void *arg)
2209 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
2210 795c10a4 2020-02-20 tracey enum kcgi_err kerr = KCGI_OK;
2211 54415d85 2020-01-15 tracey struct gw_trans *gw_trans = arg;
2212 9f6f3943 2020-09-24 tracey char *ati = NULL, *fic32 = NULL, *fic16 = NULL;
2213 9f6f3943 2020-09-24 tracey char *swm = NULL, *spt = NULL, *css = NULL, *logo = NULL;
2215 9f6f3943 2020-09-24 tracey if (asprintf(&ati, "%s%s", gw_trans->gw_conf->got_www_path,
2216 9f6f3943 2020-09-24 tracey "/apple-touch-icon.png") == -1)
2217 9f6f3943 2020-09-24 tracey goto err;
2218 9f6f3943 2020-09-24 tracey if (asprintf(&fic32, "%s%s", gw_trans->gw_conf->got_www_path,
2219 62d463ca 2020-10-20 naddy "/favicon-32x32.png") == -1)
2220 9f6f3943 2020-09-24 tracey goto err;
2221 9f6f3943 2020-09-24 tracey if (asprintf(&fic16, "%s%s", gw_trans->gw_conf->got_www_path,
2222 9f6f3943 2020-09-24 tracey "/favicon-16x16.png") == -1)
2223 9f6f3943 2020-09-24 tracey goto err;
2224 9f6f3943 2020-09-24 tracey if (asprintf(&swm, "%s%s", gw_trans->gw_conf->got_www_path,
2225 9f6f3943 2020-09-24 tracey "/site.webmanifest") == -1)
2226 9f6f3943 2020-09-24 tracey goto err;
2227 9f6f3943 2020-09-24 tracey if (asprintf(&spt, "%s%s", gw_trans->gw_conf->got_www_path,
2228 9f6f3943 2020-09-24 tracey "/safari-pinned-tab.svg") == -1)
2229 9f6f3943 2020-09-24 tracey goto err;
2230 9f6f3943 2020-09-24 tracey if (asprintf(&css, "%s%s", gw_trans->gw_conf->got_www_path,
2231 9f6f3943 2020-09-24 tracey "/gotweb.css") == -1)
2232 9f6f3943 2020-09-24 tracey goto err;
2233 9f6f3943 2020-09-24 tracey if (asprintf(&logo, "%s%s%s", gw_trans->gw_conf->got_www_path,
2234 9f6f3943 2020-09-24 tracey gw_trans->gw_conf->got_www_path ? "/" : "",
2235 9f6f3943 2020-09-24 tracey gw_trans->gw_conf->got_logo) == -1)
2236 9f6f3943 2020-09-24 tracey goto err;
2238 2c251c14 2020-01-15 tracey switch (key) {
2239 2c251c14 2020-01-15 tracey case (TEMPL_HEAD):
2240 aaed5792 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_META,
2241 1dcb8908 2020-02-12 tracey KATTR_NAME, "viewport",
2242 1dcb8908 2020-02-12 tracey KATTR_CONTENT, "initial-scale=.75, user-scalable=yes",
2243 aaed5792 2020-02-08 tracey KATTR__MAX);
2244 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
2245 bd275801 2020-02-03 tracey return 0;
2246 aaed5792 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2247 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2248 aaed5792 2020-02-08 tracey return 0;
2249 aaed5792 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_META,
2250 aaed5792 2020-02-08 tracey KATTR_CHARSET, "utf-8",
2251 aaed5792 2020-02-08 tracey KATTR__MAX);
2252 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2253 aaed5792 2020-02-08 tracey return 0;
2254 aaed5792 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2255 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2256 aaed5792 2020-02-08 tracey return 0;
2257 aaed5792 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_META,
2258 aaed5792 2020-02-08 tracey KATTR_NAME, "msapplication-TileColor",
2259 aaed5792 2020-02-08 tracey KATTR_CONTENT, "#da532c", KATTR__MAX);
2260 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2261 aaed5792 2020-02-08 tracey return 0;
2262 aaed5792 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2263 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2264 aaed5792 2020-02-08 tracey return 0;
2265 aaed5792 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_META,
2266 aaed5792 2020-02-08 tracey KATTR_NAME, "theme-color",
2267 aaed5792 2020-02-08 tracey KATTR_CONTENT, "#ffffff", KATTR__MAX);
2268 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2269 aaed5792 2020-02-08 tracey return 0;
2270 aaed5792 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2271 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2272 aaed5792 2020-02-08 tracey return 0;
2273 aaed5792 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_LINK,
2274 aaed5792 2020-02-08 tracey KATTR_REL, "apple-touch-icon", KATTR_SIZES, "180x180",
2275 9f6f3943 2020-09-24 tracey KATTR_HREF, ati, KATTR__MAX);
2276 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2277 aaed5792 2020-02-08 tracey return 0;
2278 aaed5792 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2279 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2280 aaed5792 2020-02-08 tracey return 0;
2281 aaed5792 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_LINK,
2282 aaed5792 2020-02-08 tracey KATTR_REL, "icon", KATTR_TYPE, "image/png", KATTR_SIZES,
2283 9f6f3943 2020-09-24 tracey "32x32", KATTR_HREF, fic32, KATTR__MAX);
2284 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2285 aaed5792 2020-02-08 tracey return 0;
2286 aaed5792 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2287 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2288 aaed5792 2020-02-08 tracey return 0;
2289 aaed5792 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_LINK,
2290 aaed5792 2020-02-08 tracey KATTR_REL, "icon", KATTR_TYPE, "image/png", KATTR_SIZES,
2291 9f6f3943 2020-09-24 tracey "16x16", KATTR_HREF, fic16, KATTR__MAX);
2292 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2293 aaed5792 2020-02-08 tracey return 0;
2294 aaed5792 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2295 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2296 aaed5792 2020-02-08 tracey return 0;
2297 aaed5792 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_LINK,
2298 9f6f3943 2020-09-24 tracey KATTR_REL, "manifest", KATTR_HREF, swm,
2299 aaed5792 2020-02-08 tracey KATTR__MAX);
2300 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2301 aaed5792 2020-02-08 tracey return 0;
2302 aaed5792 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2303 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2304 aaed5792 2020-02-08 tracey return 0;
2305 aaed5792 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_LINK,
2306 aaed5792 2020-02-08 tracey KATTR_REL, "mask-icon", KATTR_HREF,
2307 9f6f3943 2020-09-24 tracey spt, KATTR__MAX);
2308 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2309 aaed5792 2020-02-08 tracey return 0;
2310 aaed5792 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2311 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2312 aaed5792 2020-02-08 tracey return 0;
2313 aaed5792 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_LINK,
2314 aaed5792 2020-02-08 tracey KATTR_REL, "stylesheet", KATTR_TYPE, "text/css",
2315 9f6f3943 2020-09-24 tracey KATTR_HREF, css, KATTR__MAX);
2316 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2317 aaed5792 2020-02-08 tracey return 0;
2318 aaed5792 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2319 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2320 aaed5792 2020-02-08 tracey return 0;
2322 2c251c14 2020-01-15 tracey case(TEMPL_HEADER):
2323 185ba3ba 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2324 185ba3ba 2020-02-04 tracey KATTR_ID, "got_link", KATTR__MAX);
2325 185ba3ba 2020-02-04 tracey if (kerr != KCGI_OK)
2326 185ba3ba 2020-02-04 tracey return 0;
2327 185ba3ba 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
2328 185ba3ba 2020-02-04 tracey KATTR_HREF, gw_trans->gw_conf->got_logo_url,
2329 185ba3ba 2020-02-04 tracey KATTR_TARGET, "_sotd", KATTR__MAX);
2330 185ba3ba 2020-02-04 tracey if (kerr != KCGI_OK)
2331 185ba3ba 2020-02-04 tracey return 0;
2332 185ba3ba 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_IMG,
2333 9f6f3943 2020-09-24 tracey KATTR_SRC, logo, KATTR__MAX);
2334 9f6f3943 2020-09-24 tracey if (kerr != KCGI_OK)
2335 185ba3ba 2020-02-04 tracey return 0;
2336 185ba3ba 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 3);
2337 9f6f3943 2020-09-24 tracey if (kerr != KCGI_OK)
2338 185ba3ba 2020-02-04 tracey return 0;
2340 2c251c14 2020-01-15 tracey case (TEMPL_SITEPATH):
2341 4ae179a2 2020-02-08 tracey error = gw_output_site_link(gw_trans);
2342 4ae179a2 2020-02-08 tracey if (error)
2343 4ae179a2 2020-02-08 tracey return 0;
2345 2c251c14 2020-01-15 tracey case(TEMPL_TITLE):
2346 bd275801 2020-02-03 tracey if (gw_trans->gw_conf->got_site_name != NULL) {
2347 bd275801 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req,
2348 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_site_name);
2349 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
2350 bd275801 2020-02-03 tracey return 0;
2353 2c251c14 2020-01-15 tracey case (TEMPL_SEARCH):
2355 63ee0dca 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
2356 63ee0dca 2020-02-08 tracey "search", KATTR__MAX);
2357 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
2358 bd275801 2020-02-03 tracey return 0;
2359 63ee0dca 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_FORM,
2360 63ee0dca 2020-02-08 tracey KATTR_METHOD, "POST", 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_attr(gw_trans->gw_html_req, KELEM_INPUT, KATTR_ID,
2364 63ee0dca 2020-02-08 tracey "got-search", KATTR_NAME, "got-search", KATTR_SIZE, "15",
2365 63ee0dca 2020-02-08 tracey KATTR_MAXLENGTH, "50", KATTR__MAX);
2366 63ee0dca 2020-02-08 tracey if (kerr != KCGI_OK)
2367 63ee0dca 2020-02-08 tracey return 0;
2368 63ee0dca 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_BUTTON,
2369 63ee0dca 2020-02-08 tracey KATTR__MAX);
2370 63ee0dca 2020-02-08 tracey if (kerr != KCGI_OK)
2371 63ee0dca 2020-02-08 tracey return 0;
2372 63ee0dca 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Search");
2373 63ee0dca 2020-02-08 tracey if (kerr != KCGI_OK)
2374 63ee0dca 2020-02-08 tracey return 0;
2375 63ee0dca 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 4);
2376 63ee0dca 2020-02-08 tracey if (kerr != KCGI_OK)
2377 63ee0dca 2020-02-08 tracey return 0;
2379 2c251c14 2020-01-15 tracey case(TEMPL_SITEOWNER):
2380 2c251c14 2020-01-15 tracey if (gw_trans->gw_conf->got_site_owner != NULL &&
2381 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_show_site_owner) {
2382 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2383 bd275801 2020-02-03 tracey KATTR_ID, "site_owner_wrapper", KATTR__MAX);
2384 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
2386 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2387 bd275801 2020-02-03 tracey KATTR_ID, "site_owner", KATTR__MAX);
2388 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
2389 2c251c14 2020-01-15 tracey return 0;
2390 bd275801 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req,
2391 bd275801 2020-02-03 tracey gw_trans->gw_conf->got_site_owner);
2392 bd275801 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
2393 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
2394 bd275801 2020-02-03 tracey return 0;
2397 2c251c14 2020-01-15 tracey case(TEMPL_CONTENT):
2398 2c251c14 2020-01-15 tracey error = gw_query_funcs[gw_trans->action].func_main(gw_trans);
2399 bd275801 2020-02-03 tracey if (error) {
2400 0d100d0b 2020-02-07 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2401 0d100d0b 2020-02-07 tracey KATTR_ID, "tmpl_err", KATTR__MAX);
2402 0d100d0b 2020-02-07 tracey if (kerr != KCGI_OK)
2403 0d100d0b 2020-02-07 tracey return 0;
2404 f08447b0 2020-04-14 tracey kerr = khttp_printf(gw_trans->gw_req, "Error: %s",
2405 f08447b0 2020-04-14 tracey error->msg);
2406 0d100d0b 2020-02-07 tracey if (kerr != KCGI_OK)
2407 0d100d0b 2020-02-07 tracey return 0;
2408 0d100d0b 2020-02-07 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2409 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
2410 bd275801 2020-02-03 tracey return 0;
2413 2c251c14 2020-01-15 tracey default:
2414 2c251c14 2020-01-15 tracey return 0;
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 2c251c14 2020-01-15 tracey return 1;
2425 9f6f3943 2020-09-24 tracey free(ati);
2426 9f6f3943 2020-09-24 tracey free(fic32);
2427 9f6f3943 2020-09-24 tracey free(fic16);
2428 9f6f3943 2020-09-24 tracey free(swm);
2429 9f6f3943 2020-09-24 tracey free(spt);
2430 9f6f3943 2020-09-24 tracey free(css);
2431 9f6f3943 2020-09-24 tracey free(logo);
2432 9f6f3943 2020-09-24 tracey return 0;
2435 21a55cc7 2020-02-04 tracey static const struct got_error *
2436 21a55cc7 2020-02-04 tracey gw_gen_commit_header(struct gw_trans *gw_trans, char *str1, char *str2)
2438 21a55cc7 2020-02-04 tracey const struct got_error *error = NULL;
2439 21a55cc7 2020-02-04 tracey enum kcgi_err kerr = KCGI_OK;
2441 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2442 21a55cc7 2020-02-04 tracey KATTR_ID, "header_commit_title", KATTR__MAX);
2443 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2444 21a55cc7 2020-02-04 tracey goto done;
2445 21a55cc7 2020-02-04 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Commit: ");
2446 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2447 21a55cc7 2020-02-04 tracey goto done;
2448 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2449 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2450 21a55cc7 2020-02-04 tracey goto done;
2451 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2452 21a55cc7 2020-02-04 tracey KATTR_ID, "header_commit", KATTR__MAX);
2453 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2454 21a55cc7 2020-02-04 tracey goto done;
2455 32b9f7ed 2020-04-14 tracey kerr = khtml_printf(gw_trans->gw_html_req, "%s ", str1);
2456 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2457 21a55cc7 2020-02-04 tracey goto done;
2458 5c65becf 2020-02-13 tracey if (str2 != NULL) {
2459 bf93a5c0 2020-02-15 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_SPAN,
2460 bf93a5c0 2020-02-15 tracey KATTR_ID, "refs_str", KATTR__MAX);
2461 5c65becf 2020-02-13 tracey if (kerr != KCGI_OK)
2462 5c65becf 2020-02-13 tracey goto done;
2463 32b9f7ed 2020-04-14 tracey kerr = khtml_printf(gw_trans->gw_html_req, "(%s)", str2);
2464 bf93a5c0 2020-02-15 tracey if (kerr != KCGI_OK)
2465 bf93a5c0 2020-02-15 tracey goto done;
2466 bf93a5c0 2020-02-15 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2467 5c65becf 2020-02-13 tracey if (kerr != KCGI_OK)
2468 5c65becf 2020-02-13 tracey goto done;
2470 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2472 21a55cc7 2020-02-04 tracey if (error == NULL && kerr != KCGI_OK)
2473 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
2474 21a55cc7 2020-02-04 tracey return error;
2477 f7cc9480 2020-02-05 tracey static const struct got_error *
2478 f7cc9480 2020-02-05 tracey gw_gen_diff_header(struct gw_trans *gw_trans, char *str1, char *str2)
2480 27192be7 2020-02-04 tracey const struct got_error *error = NULL;
2481 f7cc9480 2020-02-05 tracey enum kcgi_err kerr = KCGI_OK;
2483 f7cc9480 2020-02-05 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2484 f7cc9480 2020-02-05 tracey KATTR_ID, "header_diff_title", KATTR__MAX);
2485 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2486 f7cc9480 2020-02-05 tracey goto done;
2487 f7cc9480 2020-02-05 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Diff: ");
2488 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2489 f7cc9480 2020-02-05 tracey goto done;
2490 f7cc9480 2020-02-05 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2491 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2492 f7cc9480 2020-02-05 tracey goto done;
2493 f7cc9480 2020-02-05 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2494 f7cc9480 2020-02-05 tracey KATTR_ID, "header_diff", KATTR__MAX);
2495 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2496 f7cc9480 2020-02-05 tracey goto done;
2497 5c65becf 2020-02-13 tracey if (str1 != NULL) {
2498 5c65becf 2020-02-13 tracey kerr = khtml_puts(gw_trans->gw_html_req, str1);
2499 5c65becf 2020-02-13 tracey if (kerr != KCGI_OK)
2500 5c65becf 2020-02-13 tracey goto done;
2502 f7cc9480 2020-02-05 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_BR, KATTR__MAX);
2503 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2504 f7cc9480 2020-02-05 tracey goto done;
2505 f7cc9480 2020-02-05 tracey kerr = khtml_puts(gw_trans->gw_html_req, str2);
2506 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2507 f7cc9480 2020-02-05 tracey goto done;
2508 f7cc9480 2020-02-05 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2510 f7cc9480 2020-02-05 tracey if (error == NULL && kerr != KCGI_OK)
2511 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
2512 f7cc9480 2020-02-05 tracey return error;
2515 21a55cc7 2020-02-04 tracey static const struct got_error *
2516 21a55cc7 2020-02-04 tracey gw_gen_age_header(struct gw_trans *gw_trans, const char *str)
2518 21a55cc7 2020-02-04 tracey const struct got_error *error = NULL;
2519 21a55cc7 2020-02-04 tracey enum kcgi_err kerr = KCGI_OK;
2521 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2522 21a55cc7 2020-02-04 tracey KATTR_ID, "header_age_title", KATTR__MAX);
2523 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2524 21a55cc7 2020-02-04 tracey goto done;
2525 21a55cc7 2020-02-04 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Date: ");
2526 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2527 21a55cc7 2020-02-04 tracey goto done;
2528 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2529 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2530 21a55cc7 2020-02-04 tracey goto done;
2531 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2532 21a55cc7 2020-02-04 tracey KATTR_ID, "header_age", KATTR__MAX);
2533 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2534 21a55cc7 2020-02-04 tracey goto done;
2535 21a55cc7 2020-02-04 tracey kerr = khtml_puts(gw_trans->gw_html_req, str);
2536 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2537 21a55cc7 2020-02-04 tracey goto done;
2538 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2540 21a55cc7 2020-02-04 tracey if (error == NULL && kerr != KCGI_OK)
2541 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
2542 21a55cc7 2020-02-04 tracey return error;
2545 21a55cc7 2020-02-04 tracey static const struct got_error *
2546 21a55cc7 2020-02-04 tracey gw_gen_author_header(struct gw_trans *gw_trans, const char *str)
2548 21a55cc7 2020-02-04 tracey const struct got_error *error = NULL;
2549 795c10a4 2020-02-20 tracey enum kcgi_err kerr = KCGI_OK;
2551 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2552 21a55cc7 2020-02-04 tracey KATTR_ID, "header_author_title", KATTR__MAX);
2553 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2554 21a55cc7 2020-02-04 tracey goto done;
2555 21a55cc7 2020-02-04 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Author: ");
2556 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2557 21a55cc7 2020-02-04 tracey goto done;
2558 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2559 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2560 21a55cc7 2020-02-04 tracey goto done;
2561 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2562 21a55cc7 2020-02-04 tracey KATTR_ID, "header_author", KATTR__MAX);
2563 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2564 21a55cc7 2020-02-04 tracey goto done;
2565 21a55cc7 2020-02-04 tracey kerr = khtml_puts(gw_trans->gw_html_req, str);
2566 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2567 21a55cc7 2020-02-04 tracey goto done;
2568 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2570 21a55cc7 2020-02-04 tracey if (error == NULL && kerr != KCGI_OK)
2571 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
2572 21a55cc7 2020-02-04 tracey return error;
2575 21a55cc7 2020-02-04 tracey static const struct got_error *
2576 21a55cc7 2020-02-04 tracey gw_gen_committer_header(struct gw_trans *gw_trans, const char *str)
2578 21a55cc7 2020-02-04 tracey const struct got_error *error = NULL;
2579 795c10a4 2020-02-20 tracey enum kcgi_err kerr = KCGI_OK;
2581 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2582 21a55cc7 2020-02-04 tracey KATTR_ID, "header_committer_title", KATTR__MAX);
2583 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2584 21a55cc7 2020-02-04 tracey goto done;
2585 87ca24ac 2020-02-04 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Committer: ");
2586 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2587 21a55cc7 2020-02-04 tracey goto done;
2588 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2589 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2590 21a55cc7 2020-02-04 tracey goto done;
2591 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2592 21a55cc7 2020-02-04 tracey KATTR_ID, "header_committer", KATTR__MAX);
2593 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2594 21a55cc7 2020-02-04 tracey goto done;
2595 21a55cc7 2020-02-04 tracey kerr = khtml_puts(gw_trans->gw_html_req, str);
2596 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2597 21a55cc7 2020-02-04 tracey goto done;
2598 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2600 21a55cc7 2020-02-04 tracey if (error == NULL && kerr != KCGI_OK)
2601 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
2602 21a55cc7 2020-02-04 tracey return error;
2605 f7cc9480 2020-02-05 tracey static const struct got_error *
2606 f7cc9480 2020-02-05 tracey gw_gen_commit_msg_header(struct gw_trans *gw_trans, char *str)
2608 27192be7 2020-02-04 tracey const struct got_error *error = NULL;
2609 795c10a4 2020-02-20 tracey enum kcgi_err kerr = KCGI_OK;
2611 f7cc9480 2020-02-05 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2612 f7cc9480 2020-02-05 tracey KATTR_ID, "header_commit_msg_title", KATTR__MAX);
2613 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2614 f7cc9480 2020-02-05 tracey goto done;
2615 f7cc9480 2020-02-05 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Message: ");
2616 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2617 f7cc9480 2020-02-05 tracey goto done;
2618 f7cc9480 2020-02-05 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2619 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2620 f7cc9480 2020-02-05 tracey goto done;
2621 f7cc9480 2020-02-05 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2622 f7cc9480 2020-02-05 tracey KATTR_ID, "header_commit_msg", KATTR__MAX);
2623 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2624 f7cc9480 2020-02-05 tracey goto done;
2625 f7cc9480 2020-02-05 tracey kerr = khttp_puts(gw_trans->gw_req, str);
2626 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2627 f7cc9480 2020-02-05 tracey goto done;
2628 f7cc9480 2020-02-05 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2630 f7cc9480 2020-02-05 tracey if (error == NULL && kerr != KCGI_OK)
2631 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
2632 f7cc9480 2020-02-05 tracey return error;
2635 f7cc9480 2020-02-05 tracey static const struct got_error *
2636 f7cc9480 2020-02-05 tracey gw_gen_tree_header(struct gw_trans *gw_trans, char *str)
2638 f7cc9480 2020-02-05 tracey const struct got_error *error = NULL;
2639 795c10a4 2020-02-20 tracey enum kcgi_err kerr = KCGI_OK;
2641 f7cc9480 2020-02-05 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2642 f7cc9480 2020-02-05 tracey KATTR_ID, "header_tree_title", KATTR__MAX);
2643 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2644 f7cc9480 2020-02-05 tracey goto done;
2645 f7cc9480 2020-02-05 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Tree: ");
2646 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2647 f7cc9480 2020-02-05 tracey goto done;
2648 f7cc9480 2020-02-05 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2649 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2650 f7cc9480 2020-02-05 tracey goto done;
2651 f7cc9480 2020-02-05 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2652 f7cc9480 2020-02-05 tracey KATTR_ID, "header_tree", KATTR__MAX);
2653 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2654 f7cc9480 2020-02-05 tracey goto done;
2655 f7cc9480 2020-02-05 tracey kerr = khtml_puts(gw_trans->gw_html_req, str);
2656 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2657 f7cc9480 2020-02-05 tracey goto done;
2658 f7cc9480 2020-02-05 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2660 f7cc9480 2020-02-05 tracey if (error == NULL && kerr != KCGI_OK)
2661 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
2662 f7cc9480 2020-02-05 tracey return error;
2665 32cd4d18 2020-02-03 stsp static const struct got_error *
2666 32cd4d18 2020-02-03 stsp gw_get_repo_description(char **description, struct gw_trans *gw_trans,
2667 32cd4d18 2020-02-03 stsp char *dir)
2669 32cd4d18 2020-02-03 stsp const struct got_error *error = NULL;
2670 b8b04565 2020-02-02 tracey FILE *f = NULL;
2671 32cd4d18 2020-02-03 stsp char *d_file = NULL;
2672 2c251c14 2020-01-15 tracey unsigned int len;
2675 32cd4d18 2020-02-03 stsp *description = NULL;
2676 0b20762b 2020-01-29 stsp if (gw_trans->gw_conf->got_show_repo_description == 0)
2677 a942aa37 2020-02-10 tracey return NULL;
2679 88d59c36 2020-01-29 stsp if (asprintf(&d_file, "%s/description", dir) == -1)
2680 32cd4d18 2020-02-03 stsp return got_error_from_errno("asprintf");
2682 32cd4d18 2020-02-03 stsp f = fopen(d_file, "r");
2683 32cd4d18 2020-02-03 stsp if (f == NULL) {
2684 32cd4d18 2020-02-03 stsp if (errno == ENOENT || errno == EACCES)
2685 a942aa37 2020-02-10 tracey return NULL;
2686 32cd4d18 2020-02-03 stsp error = got_error_from_errno2("fopen", d_file);
2687 32cd4d18 2020-02-03 stsp goto done;
2690 32cd4d18 2020-02-03 stsp if (fseek(f, 0, SEEK_END) == -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 len = ftell(f);
2695 32cd4d18 2020-02-03 stsp if (len == -1) {
2696 32cd4d18 2020-02-03 stsp error = got_ferror(f, GOT_ERR_IO);
2697 32cd4d18 2020-02-03 stsp goto done;
2699 32cd4d18 2020-02-03 stsp if (fseek(f, 0, SEEK_SET) == -1) {
2700 32cd4d18 2020-02-03 stsp error = got_ferror(f, GOT_ERR_IO);
2701 32cd4d18 2020-02-03 stsp goto done;
2703 32cd4d18 2020-02-03 stsp *description = calloc(len + 1, sizeof(**description));
2704 32cd4d18 2020-02-03 stsp if (*description == NULL) {
2705 32cd4d18 2020-02-03 stsp error = got_error_from_errno("calloc");
2706 32cd4d18 2020-02-03 stsp goto done;
2709 32cd4d18 2020-02-03 stsp n = fread(*description, 1, len, f);
2710 1ab830c1 2020-02-03 stsp if (n == 0 && ferror(f))
2711 32cd4d18 2020-02-03 stsp error = got_ferror(f, GOT_ERR_IO);
2713 56b63ca4 2021-01-22 stsp if (f != NULL && fclose(f) == EOF && error == NULL)
2714 32cd4d18 2020-02-03 stsp error = got_error_from_errno("fclose");
2715 2c251c14 2020-01-15 tracey free(d_file);
2716 32cd4d18 2020-02-03 stsp return error;
2719 55ccf528 2020-02-03 stsp static const struct got_error *
2720 55ccf528 2020-02-03 stsp gw_get_time_str(char **repo_age, time_t committer_time, int ref_tm)
2722 474370cb 2020-01-15 tracey struct tm tm;
2723 474370cb 2020-01-15 tracey time_t diff_time;
2724 474370cb 2020-01-15 tracey char *years = "years ago", *months = "months ago";
2725 474370cb 2020-01-15 tracey char *weeks = "weeks ago", *days = "days ago", *hours = "hours ago";
2726 474370cb 2020-01-15 tracey char *minutes = "minutes ago", *seconds = "seconds ago";
2727 474370cb 2020-01-15 tracey char *now = "right now";
2729 6c6c85af 2020-01-15 tracey char datebuf[29];
2731 55ccf528 2020-02-03 stsp *repo_age = NULL;
2733 474370cb 2020-01-15 tracey switch (ref_tm) {
2734 474370cb 2020-01-15 tracey case TM_DIFF:
2735 474370cb 2020-01-15 tracey diff_time = time(NULL) - committer_time;
2736 474370cb 2020-01-15 tracey if (diff_time > 60 * 60 * 24 * 365 * 2) {
2737 55ccf528 2020-02-03 stsp if (asprintf(repo_age, "%lld %s",
2738 88d59c36 2020-01-29 stsp (diff_time / 60 / 60 / 24 / 365), years) == -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 * (365 / 12) * 2) {
2741 55ccf528 2020-02-03 stsp if (asprintf(repo_age, "%lld %s",
2742 474370cb 2020-01-15 tracey (diff_time / 60 / 60 / 24 / (365 / 12)),
2743 88d59c36 2020-01-29 stsp months) == -1)
2744 55ccf528 2020-02-03 stsp return got_error_from_errno("asprintf");
2745 474370cb 2020-01-15 tracey } else if (diff_time > 60 * 60 * 24 * 7 * 2) {
2746 55ccf528 2020-02-03 stsp if (asprintf(repo_age, "%lld %s",
2747 88d59c36 2020-01-29 stsp (diff_time / 60 / 60 / 24 / 7), weeks) == -1)
2748 55ccf528 2020-02-03 stsp return got_error_from_errno("asprintf");
2749 474370cb 2020-01-15 tracey } else if (diff_time > 60 * 60 * 24 * 2) {
2750 55ccf528 2020-02-03 stsp if (asprintf(repo_age, "%lld %s",
2751 88d59c36 2020-01-29 stsp (diff_time / 60 / 60 / 24), days) == -1)
2752 55ccf528 2020-02-03 stsp return got_error_from_errno("asprintf");
2753 474370cb 2020-01-15 tracey } else if (diff_time > 60 * 60 * 2) {
2754 55ccf528 2020-02-03 stsp if (asprintf(repo_age, "%lld %s",
2755 88d59c36 2020-01-29 stsp (diff_time / 60 / 60), hours) == -1)
2756 55ccf528 2020-02-03 stsp return got_error_from_errno("asprintf");
2757 474370cb 2020-01-15 tracey } else if (diff_time > 60 * 2) {
2758 55ccf528 2020-02-03 stsp if (asprintf(repo_age, "%lld %s", (diff_time / 60),
2759 88d59c36 2020-01-29 stsp minutes) == -1)
2760 55ccf528 2020-02-03 stsp return got_error_from_errno("asprintf");
2761 474370cb 2020-01-15 tracey } else if (diff_time > 2) {
2762 55ccf528 2020-02-03 stsp if (asprintf(repo_age, "%lld %s", diff_time,
2763 88d59c36 2020-01-29 stsp seconds) == -1)
2764 55ccf528 2020-02-03 stsp return got_error_from_errno("asprintf");
2765 474370cb 2020-01-15 tracey } else {
2766 55ccf528 2020-02-03 stsp if (asprintf(repo_age, "%s", now) == -1)
2767 55ccf528 2020-02-03 stsp return got_error_from_errno("asprintf");
2770 474370cb 2020-01-15 tracey case TM_LONG:
2771 474370cb 2020-01-15 tracey if (gmtime_r(&committer_time, &tm) == NULL)
2772 55ccf528 2020-02-03 stsp return got_error_from_errno("gmtime_r");
2774 474370cb 2020-01-15 tracey s = asctime_r(&tm, datebuf);
2775 474370cb 2020-01-15 tracey if (s == NULL)
2776 55ccf528 2020-02-03 stsp return got_error_from_errno("asctime_r");
2778 55ccf528 2020-02-03 stsp if (asprintf(repo_age, "%s UTC", datebuf) == -1)
2779 55ccf528 2020-02-03 stsp return got_error_from_errno("asprintf");
2782 55ccf528 2020-02-03 stsp return NULL;
2785 d126c1b7 2020-01-29 stsp static const struct got_error *
2786 d126c1b7 2020-01-29 stsp gw_get_repo_age(char **repo_age, struct gw_trans *gw_trans, char *dir,
2787 2011c142 2020-02-14 stsp const char *refname, int ref_tm)
2789 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
2790 2c251c14 2020-01-15 tracey struct got_repository *repo = NULL;
2791 2c251c14 2020-01-15 tracey struct got_commit_object *commit = NULL;
2792 2c251c14 2020-01-15 tracey struct got_reflist_head refs;
2793 2c251c14 2020-01-15 tracey struct got_reflist_entry *re;
2794 474370cb 2020-01-15 tracey time_t committer_time = 0, cmp_time = 0;
2796 d126c1b7 2020-01-29 stsp *repo_age = NULL;
2797 d9dff0e5 2020-12-26 stsp TAILQ_INIT(&refs);
2799 55ccf528 2020-02-03 stsp if (gw_trans->gw_conf->got_show_repo_age == 0)
2800 d126c1b7 2020-01-29 stsp return NULL;
2802 deac617c 2020-02-14 tracey if (gw_trans->repo)
2803 deac617c 2020-02-14 tracey repo = gw_trans->repo;
2805 deac617c 2020-02-14 tracey error = got_repo_open(&repo, dir, NULL);
2806 deac617c 2020-02-14 tracey if (error)
2807 deac617c 2020-02-14 tracey return error;
2810 2011c142 2020-02-14 stsp error = got_ref_list(&refs, repo, "refs/heads",
2811 2011c142 2020-02-14 stsp got_ref_cmp_by_name, NULL);
2812 ec46ccd7 2020-01-15 tracey if (error)
2813 d126c1b7 2020-01-29 stsp goto done;
2816 2011c142 2020-02-14 stsp * Find the youngest branch tip in the repository, or the age of
2817 2011c142 2020-02-14 stsp * the a specific branch tip if a name was provided by the caller.
2819 d9dff0e5 2020-12-26 stsp TAILQ_FOREACH(re, &refs, entry) {
2820 2011c142 2020-02-14 stsp struct got_object_id *id = NULL;
2822 2011c142 2020-02-14 stsp if (refname && strcmp(got_ref_get_name(re->ref), refname) != 0)
2825 2011c142 2020-02-14 stsp error = got_ref_resolve(&id, repo, re->ref);
2826 ec46ccd7 2020-01-15 tracey if (error)
2827 d126c1b7 2020-01-29 stsp goto done;
2829 2c251c14 2020-01-15 tracey error = got_object_open_as_commit(&commit, repo, id);
2831 ec46ccd7 2020-01-15 tracey if (error)
2832 d126c1b7 2020-01-29 stsp goto done;
2834 2c251c14 2020-01-15 tracey committer_time =
2835 2c251c14 2020-01-15 tracey got_object_commit_get_committer_time(commit);
2836 2011c142 2020-02-14 stsp got_object_commit_close(commit);
2837 387a29ba 2020-01-15 tracey if (cmp_time < committer_time)
2838 2c251c14 2020-01-15 tracey cmp_time = committer_time;
2840 2011c142 2020-02-14 stsp if (refname)
2844 474370cb 2020-01-15 tracey if (cmp_time != 0) {
2845 2c251c14 2020-01-15 tracey committer_time = cmp_time;
2846 55ccf528 2020-02-03 stsp error = gw_get_time_str(repo_age, committer_time, ref_tm);
2849 2c251c14 2020-01-15 tracey got_ref_list_free(&refs);
2850 1d0f4054 2021-06-17 stsp if (gw_trans->repo == NULL) {
2851 1d0f4054 2021-06-17 stsp const struct got_error *close_err = got_repo_close(repo);
2852 1d0f4054 2021-06-17 stsp if (error == NULL)
2853 1d0f4054 2021-06-17 stsp error = close_err;
2855 d126c1b7 2020-01-29 stsp return error;
2858 83eb9a68 2020-02-03 stsp static const struct got_error *
2859 38b240fb 2020-02-06 tracey gw_output_diff(struct gw_trans *gw_trans, struct gw_header *header)
2861 ec46ccd7 2020-01-15 tracey const struct got_error *error;
2862 ec46ccd7 2020-01-15 tracey FILE *f = NULL;
2863 ec46ccd7 2020-01-15 tracey struct got_object_id *id1 = NULL, *id2 = NULL;
2864 f7cc9480 2020-02-05 tracey char *label1 = NULL, *label2 = NULL, *line = NULL;
2865 05ce9a79 2020-01-24 tracey int obj_type;
2866 f7cc9480 2020-02-05 tracey size_t linesize = 0;
2867 83eb9a68 2020-02-03 stsp ssize_t linelen;
2868 f7cc9480 2020-02-05 tracey enum kcgi_err kerr = KCGI_OK;
2870 ec46ccd7 2020-01-15 tracey f = got_opentemp();
2871 ec46ccd7 2020-01-15 tracey if (f == NULL)
2872 ec46ccd7 2020-01-15 tracey return NULL;
2874 5c65becf 2020-02-13 tracey if (header->parent_id != NULL &&
2875 5c65becf 2020-02-13 tracey strncmp(header->parent_id, "/dev/null", 9) != 0) {
2876 05ce9a79 2020-01-24 tracey error = got_repo_match_object_id(&id1, &label1,
2877 84de9106 2020-12-26 stsp header->parent_id, GOT_OBJ_TYPE_ANY,
2878 84de9106 2020-12-26 stsp &header->refs, gw_trans->repo);
2879 05ce9a79 2020-01-24 tracey if (error)
2880 05ce9a79 2020-01-24 tracey goto done;
2883 90f16cb8 2020-01-24 tracey error = got_repo_match_object_id(&id2, &label2,
2884 84de9106 2020-12-26 stsp header->commit_id, GOT_OBJ_TYPE_ANY, &header->refs,
2885 84de9106 2020-12-26 stsp gw_trans->repo);
2886 90f16cb8 2020-01-24 tracey if (error)
2887 90f16cb8 2020-01-24 tracey goto done;
2889 deac617c 2020-02-14 tracey error = got_object_get_type(&obj_type, gw_trans->repo, id2);
2890 90f16cb8 2020-01-24 tracey if (error)
2891 90f16cb8 2020-01-24 tracey goto done;
2892 05ce9a79 2020-01-24 tracey switch (obj_type) {
2893 ec46ccd7 2020-01-15 tracey case GOT_OBJ_TYPE_BLOB:
2894 c9d2b263 2020-11-11 stsp error = got_diff_objects_as_blobs(NULL, NULL, id1, id2,
2895 22c0f09d 2020-11-22 stsp NULL, NULL, 3, 0, 0, gw_trans->repo, f);
2897 ec46ccd7 2020-01-15 tracey case GOT_OBJ_TYPE_TREE:
2898 c9d2b263 2020-11-11 stsp error = got_diff_objects_as_trees(NULL, NULL, id1, id2,
2899 22c0f09d 2020-11-22 stsp "", "", 3, 0, 0, gw_trans->repo, f);
2901 ec46ccd7 2020-01-15 tracey case GOT_OBJ_TYPE_COMMIT:
2902 22c0f09d 2020-11-22 stsp error = got_diff_objects_as_commits(NULL, NULL, id1, id2,
2903 22c0f09d 2020-11-22 stsp 3, 0, 0, gw_trans->repo, f);
2905 ec46ccd7 2020-01-15 tracey default:
2906 ec46ccd7 2020-01-15 tracey error = got_error(GOT_ERR_OBJ_TYPE);
2908 b8b04565 2020-02-02 tracey if (error)
2909 b8b04565 2020-02-02 tracey goto done;
2911 d4729381 2020-02-03 stsp if (fseek(f, 0, SEEK_SET) == -1) {
2912 d4729381 2020-02-03 stsp error = got_ferror(f, GOT_ERR_IO);
2913 ec46ccd7 2020-01-15 tracey goto done;
2916 83eb9a68 2020-02-03 stsp while ((linelen = getline(&line, &linesize, f)) != -1) {
2917 f7cc9480 2020-02-05 tracey error = gw_colordiff_line(gw_trans, line);
2918 ec46ccd7 2020-01-15 tracey if (error)
2919 b8b04565 2020-02-02 tracey goto done;
2920 f7cc9480 2020-02-05 tracey /* XXX: KHTML_PRETTY breaks this */
2921 f7cc9480 2020-02-05 tracey kerr = khtml_puts(gw_trans->gw_html_req, line);
2922 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2923 83eb9a68 2020-02-03 stsp goto done;
2924 f7cc9480 2020-02-05 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2925 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2926 b8b04565 2020-02-02 tracey goto done;
2928 f7cc9480 2020-02-05 tracey if (linelen == -1 && ferror(f))
2929 83eb9a68 2020-02-03 stsp error = got_error_from_errno("getline");
2931 56b63ca4 2021-01-22 stsp if (f && fclose(f) == EOF && error == NULL)
2932 d4729381 2020-02-03 stsp error = got_error_from_errno("fclose");
2933 d4729381 2020-02-03 stsp free(line);
2934 ec46ccd7 2020-01-15 tracey free(label1);
2935 ec46ccd7 2020-01-15 tracey free(label2);
2936 ec46ccd7 2020-01-15 tracey free(id1);
2937 ec46ccd7 2020-01-15 tracey free(id2);
2939 f7cc9480 2020-02-05 tracey if (error == NULL && kerr != KCGI_OK)
2940 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
2941 83eb9a68 2020-02-03 stsp return error;
2944 9a1cc63f 2020-02-03 stsp static const struct got_error *
2945 9a1cc63f 2020-02-03 stsp gw_get_repo_owner(char **owner, struct gw_trans *gw_trans, char *dir)
2947 1d0f4054 2021-06-17 stsp const struct got_error *error = NULL, *close_err;
2948 9a1cc63f 2020-02-03 stsp struct got_repository *repo;
2949 9a1cc63f 2020-02-03 stsp const char *gitconfig_owner;
2951 9a1cc63f 2020-02-03 stsp *owner = NULL;
2953 9a1cc63f 2020-02-03 stsp if (gw_trans->gw_conf->got_show_repo_owner == 0)
2954 9a1cc63f 2020-02-03 stsp return NULL;
2956 9a1cc63f 2020-02-03 stsp error = got_repo_open(&repo, dir, NULL);
2957 9a1cc63f 2020-02-03 stsp if (error)
2958 9a1cc63f 2020-02-03 stsp return error;
2959 9a1cc63f 2020-02-03 stsp gitconfig_owner = got_repo_get_gitconfig_owner(repo);
2960 d1635ae4 2020-02-13 tracey if (gitconfig_owner) {
2961 d1635ae4 2020-02-13 tracey *owner = strdup(gitconfig_owner);
2962 d1635ae4 2020-02-13 tracey if (*owner == NULL)
2963 d1635ae4 2020-02-13 tracey error = got_error_from_errno("strdup");
2965 1d0f4054 2021-06-17 stsp close_err = got_repo_close(repo);
2966 1d0f4054 2021-06-17 stsp if (error == NULL)
2967 1d0f4054 2021-06-17 stsp error = close_err;
2968 9a1cc63f 2020-02-03 stsp return error;
2971 59d3c40e 2020-02-03 stsp static const struct got_error *
2972 59d3c40e 2020-02-03 stsp gw_get_clone_url(char **url, struct gw_trans *gw_trans, char *dir)
2974 59d3c40e 2020-02-03 stsp const struct got_error *error = NULL;
2975 2c251c14 2020-01-15 tracey FILE *f;
2976 59d3c40e 2020-02-03 stsp char *d_file = NULL;
2977 2c251c14 2020-01-15 tracey unsigned int len;
2980 59d3c40e 2020-02-03 stsp *url = NULL;
2982 59d3c40e 2020-02-03 stsp if (asprintf(&d_file, "%s/cloneurl", dir) == -1)
2983 59d3c40e 2020-02-03 stsp return got_error_from_errno("asprintf");
2985 59d3c40e 2020-02-03 stsp f = fopen(d_file, "r");
2986 59d3c40e 2020-02-03 stsp if (f == NULL) {
2987 59d3c40e 2020-02-03 stsp if (errno != ENOENT && errno != EACCES)
2988 59d3c40e 2020-02-03 stsp error = got_error_from_errno2("fopen", d_file);
2989 59d3c40e 2020-02-03 stsp goto done;
2992 59d3c40e 2020-02-03 stsp if (fseek(f, 0, SEEK_END) == -1) {
2993 59d3c40e 2020-02-03 stsp error = got_ferror(f, GOT_ERR_IO);
2994 59d3c40e 2020-02-03 stsp goto done;
2996 59d3c40e 2020-02-03 stsp len = ftell(f);
2997 59d3c40e 2020-02-03 stsp if (len == -1) {
2998 59d3c40e 2020-02-03 stsp error = got_ferror(f, GOT_ERR_IO);
2999 59d3c40e 2020-02-03 stsp goto done;
3001 59d3c40e 2020-02-03 stsp if (fseek(f, 0, SEEK_SET) == -1) {
3002 59d3c40e 2020-02-03 stsp error = got_ferror(f, GOT_ERR_IO);
3003 59d3c40e 2020-02-03 stsp goto done;
3006 59d3c40e 2020-02-03 stsp *url = calloc(len + 1, sizeof(**url));
3007 59d3c40e 2020-02-03 stsp if (*url == NULL) {
3008 59d3c40e 2020-02-03 stsp error = got_error_from_errno("calloc");
3009 59d3c40e 2020-02-03 stsp goto done;
3012 59d3c40e 2020-02-03 stsp n = fread(*url, 1, len, f);
3013 59d3c40e 2020-02-03 stsp if (n == 0 && ferror(f))
3014 59d3c40e 2020-02-03 stsp error = got_ferror(f, GOT_ERR_IO);
3016 56b63ca4 2021-01-22 stsp if (f && fclose(f) == EOF && error == NULL)
3017 59d3c40e 2020-02-03 stsp error = got_error_from_errno("fclose");
3018 2c251c14 2020-01-15 tracey free(d_file);
3019 59d3c40e 2020-02-03 stsp return NULL;
3022 6eccd105 2020-02-03 stsp static const struct got_error *
3023 38b240fb 2020-02-06 tracey gw_output_repo_tags(struct gw_trans *gw_trans, struct gw_header *header,
3024 38b240fb 2020-02-06 tracey int limit, int tag_type)
3026 87f9ebf5 2020-01-15 tracey const struct got_error *error = NULL;
3027 87f9ebf5 2020-01-15 tracey struct got_reflist_head refs;
3028 87f9ebf5 2020-01-15 tracey struct got_reflist_entry *re;
3029 38b240fb 2020-02-06 tracey char *age = NULL;
3030 ef2c200c 2020-02-07 tracey char *id_str = NULL, *newline, *href_commits = NULL;
3031 38b240fb 2020-02-06 tracey char *tag_commit0 = NULL, *href_tag = NULL, *href_briefs = NULL;
3032 6eccd105 2020-02-03 stsp struct got_tag_object *tag = NULL;
3033 38b240fb 2020-02-06 tracey enum kcgi_err kerr = KCGI_OK;
3034 ff4bb25f 2020-02-19 tracey int summary_header_displayed = 0, start_tag = 0, chk_next = 0;
3035 ff4bb25f 2020-02-19 tracey int prev_set = 0, tag_count = 0;
3037 d9dff0e5 2020-12-26 stsp TAILQ_INIT(&refs);
3039 deac617c 2020-02-14 tracey error = got_ref_list(&refs, gw_trans->repo, "refs/tags",
3040 deac617c 2020-02-14 tracey got_ref_cmp_tags, gw_trans->repo);
3041 ec46ccd7 2020-01-15 tracey if (error)
3042 87f9ebf5 2020-01-15 tracey goto done;
3044 d9dff0e5 2020-12-26 stsp TAILQ_FOREACH(re, &refs, entry) {
3045 87f9ebf5 2020-01-15 tracey const char *refname;
3046 4ff7391f 2020-01-28 tracey const char *tagger;
3047 6eccd105 2020-02-03 stsp const char *tag_commit;
3048 87f9ebf5 2020-01-15 tracey time_t tagger_time;
3049 87f9ebf5 2020-01-15 tracey struct got_object_id *id;
3050 ef2c200c 2020-02-07 tracey struct got_commit_object *commit = NULL;
3052 87f9ebf5 2020-01-15 tracey refname = got_ref_get_name(re->ref);
3053 87f9ebf5 2020-01-15 tracey if (strncmp(refname, "refs/tags/", 10) != 0)
3054 87f9ebf5 2020-01-15 tracey continue;
3055 87f9ebf5 2020-01-15 tracey refname += 10;
3057 deac617c 2020-02-14 tracey error = got_ref_resolve(&id, gw_trans->repo, re->ref);
3058 87f9ebf5 2020-01-15 tracey if (error)
3059 87f9ebf5 2020-01-15 tracey goto done;
3061 deac617c 2020-02-14 tracey error = got_object_open_as_tag(&tag, gw_trans->repo, id);
3062 38b240fb 2020-02-06 tracey if (error) {
3063 ef2c200c 2020-02-07 tracey if (error->code != GOT_ERR_OBJ_TYPE) {
3064 ef2c200c 2020-02-07 tracey free(id);
3065 ef2c200c 2020-02-07 tracey goto done;
3067 ef2c200c 2020-02-07 tracey /* "lightweight" tag */
3068 deac617c 2020-02-14 tracey error = got_object_open_as_commit(&commit,
3069 deac617c 2020-02-14 tracey gw_trans->repo, id);
3070 ef2c200c 2020-02-07 tracey if (error) {
3071 ef2c200c 2020-02-07 tracey free(id);
3072 ef2c200c 2020-02-07 tracey goto done;
3074 ef2c200c 2020-02-07 tracey tagger = got_object_commit_get_committer(commit);
3075 ef2c200c 2020-02-07 tracey tagger_time =
3076 ef2c200c 2020-02-07 tracey got_object_commit_get_committer_time(commit);
3077 ef2c200c 2020-02-07 tracey error = got_object_id_str(&id_str, id);
3078 ef2c200c 2020-02-07 tracey free(id);
3079 ef2c200c 2020-02-07 tracey } else {
3080 ef2c200c 2020-02-07 tracey free(id);
3081 ef2c200c 2020-02-07 tracey tagger = got_object_tag_get_tagger(tag);
3082 ef2c200c 2020-02-07 tracey tagger_time = got_object_tag_get_tagger_time(tag);
3083 ef2c200c 2020-02-07 tracey error = got_object_id_str(&id_str,
3084 ef2c200c 2020-02-07 tracey got_object_tag_get_object_id(tag));
3086 87f9ebf5 2020-01-15 tracey if (error)
3087 87f9ebf5 2020-01-15 tracey goto done;
3089 38b240fb 2020-02-06 tracey if (tag_type == TAGFULL && strncmp(id_str, header->commit_id,
3090 38b240fb 2020-02-06 tracey strlen(id_str)) != 0)
3091 38b240fb 2020-02-06 tracey continue;
3093 ff4bb25f 2020-02-19 tracey if (tag_type == TAGBRIEF && gw_trans->commit_id &&
3094 ff4bb25f 2020-02-19 tracey start_tag == 0 && strncmp(id_str, header->commit_id,
3095 ff4bb25f 2020-02-19 tracey strlen(id_str)) != 0) {
3096 ff4bb25f 2020-02-19 tracey continue;
3097 ff4bb25f 2020-02-19 tracey } else {
3098 ff4bb25f 2020-02-19 tracey start_tag = 1;
3101 ff4bb25f 2020-02-19 tracey tag_count++;
3103 ff4bb25f 2020-02-19 tracey if (prev_set == 0 && start_tag == 1) {
3104 ff4bb25f 2020-02-19 tracey gw_trans->next_prev_id = strdup(id_str);
3105 ff4bb25f 2020-02-19 tracey if (gw_trans->next_prev_id == NULL) {
3106 ff4bb25f 2020-02-19 tracey error = got_error_from_errno("strdup");
3107 ff4bb25f 2020-02-19 tracey goto done;
3109 ff4bb25f 2020-02-19 tracey prev_set = 1;
3112 ff4bb25f 2020-02-19 tracey if (chk_next) {
3113 ff4bb25f 2020-02-19 tracey gw_trans->next_id = strdup(id_str);
3114 ff4bb25f 2020-02-19 tracey if (gw_trans->next_id == NULL)
3115 ff4bb25f 2020-02-19 tracey error = got_error_from_errno("strdup");
3116 ff4bb25f 2020-02-19 tracey goto done;
3119 ef2c200c 2020-02-07 tracey if (commit) {
3120 ef2c200c 2020-02-07 tracey error = got_object_commit_get_logmsg(&tag_commit0,
3121 ef2c200c 2020-02-07 tracey commit);
3122 ef2c200c 2020-02-07 tracey if (error)
3123 ef2c200c 2020-02-07 tracey goto done;
3124 ef2c200c 2020-02-07 tracey got_object_commit_close(commit);
3125 ef2c200c 2020-02-07 tracey } else {
3126 ef2c200c 2020-02-07 tracey tag_commit0 = strdup(got_object_tag_get_message(tag));
3127 ef2c200c 2020-02-07 tracey if (tag_commit0 == NULL) {
3128 ef2c200c 2020-02-07 tracey error = got_error_from_errno("strdup");
3129 ef2c200c 2020-02-07 tracey goto done;
3133 f2f46662 2020-01-23 tracey tag_commit = tag_commit0;
3134 f2f46662 2020-01-23 tracey while (*tag_commit == '\n')
3135 f2f46662 2020-01-23 tracey tag_commit++;
3137 87f9ebf5 2020-01-15 tracey switch (tag_type) {
3138 87f9ebf5 2020-01-15 tracey case TAGBRIEF:
3139 f2f46662 2020-01-23 tracey newline = strchr(tag_commit, '\n');
3140 87f9ebf5 2020-01-15 tracey if (newline)
3141 87f9ebf5 2020-01-15 tracey *newline = '\0';
3143 38b240fb 2020-02-06 tracey if (summary_header_displayed == 0) {
3144 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req,
3145 38b240fb 2020-02-06 tracey KELEM_DIV, KATTR_ID,
3146 38b240fb 2020-02-06 tracey "summary_tags_title_wrapper", KATTR__MAX);
3147 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3148 38b240fb 2020-02-06 tracey goto done;
3149 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req,
3150 38b240fb 2020-02-06 tracey KELEM_DIV, KATTR_ID,
3151 38b240fb 2020-02-06 tracey "summary_tags_title", KATTR__MAX);
3152 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3153 38b240fb 2020-02-06 tracey goto done;
3154 38b240fb 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req,
3155 38b240fb 2020-02-06 tracey "Tags");
3156 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3157 38b240fb 2020-02-06 tracey goto done;
3158 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req,
3160 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3161 38b240fb 2020-02-06 tracey goto done;
3162 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req,
3163 38b240fb 2020-02-06 tracey KELEM_DIV, KATTR_ID,
3164 38b240fb 2020-02-06 tracey "summary_tags_content", KATTR__MAX);
3165 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3166 38b240fb 2020-02-06 tracey goto done;
3167 38b240fb 2020-02-06 tracey summary_header_displayed = 1;
3170 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
3171 ff4bb25f 2020-02-19 tracey KATTR_ID, "tag_wrapper", KATTR__MAX);
3172 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3173 38b240fb 2020-02-06 tracey goto done;
3174 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
3175 ff4bb25f 2020-02-19 tracey KATTR_ID, "tag_age", KATTR__MAX);
3176 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3177 38b240fb 2020-02-06 tracey goto done;
3178 55ccf528 2020-02-03 stsp error = gw_get_time_str(&age, tagger_time, TM_DIFF);
3179 55ccf528 2020-02-03 stsp if (error)
3180 87f9ebf5 2020-01-15 tracey goto done;
3181 38b240fb 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req,
3182 38b240fb 2020-02-06 tracey age ? age : "");
3183 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3184 38b240fb 2020-02-06 tracey goto done;
3185 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
3186 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3187 38b240fb 2020-02-06 tracey goto done;
3188 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
3189 ff4bb25f 2020-02-19 tracey KATTR_ID, "tag", KATTR__MAX);
3190 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3191 38b240fb 2020-02-06 tracey goto done;
3192 38b240fb 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req, refname);
3193 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3194 38b240fb 2020-02-06 tracey goto done;
3195 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
3196 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3197 38b240fb 2020-02-06 tracey goto done;
3198 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
3199 ff4bb25f 2020-02-19 tracey KATTR_ID, "tag_name", KATTR__MAX);
3200 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3201 dad0fde4 2020-02-06 tracey goto done;
3203 12003b6a 2020-04-14 tracey href_tag = khttp_urlpart(NULL, NULL, "gotweb", "path",
3204 12003b6a 2020-04-14 tracey gw_trans->repo_name, "action", "tag", "commit",
3205 12003b6a 2020-04-14 tracey id_str, NULL);
3206 19ff7638 2020-04-14 tracey if (href_tag == NULL) {
3207 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
3208 19ff7638 2020-04-14 tracey goto done;
3210 056e30c8 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
3211 056e30c8 2020-02-06 tracey KATTR_HREF, href_tag, KATTR__MAX);
3212 056e30c8 2020-02-06 tracey if (kerr != KCGI_OK)
3213 056e30c8 2020-02-06 tracey goto done;
3214 38b240fb 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req, tag_commit);
3215 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3216 38b240fb 2020-02-06 tracey goto done;
3217 dad0fde4 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 3);
3218 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3219 38b240fb 2020-02-06 tracey goto done;
3221 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
3222 38b240fb 2020-02-06 tracey KATTR_ID, "navs_wrapper", KATTR__MAX);
3223 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3224 38b240fb 2020-02-06 tracey goto done;
3225 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
3226 38b240fb 2020-02-06 tracey KATTR_ID, "navs", KATTR__MAX);
3227 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3228 38b240fb 2020-02-06 tracey goto done;
3230 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
3231 38b240fb 2020-02-06 tracey KATTR_HREF, href_tag, KATTR__MAX);
3232 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3233 38b240fb 2020-02-06 tracey goto done;
3234 38b240fb 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req, "tag");
3235 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3236 38b240fb 2020-02-06 tracey goto done;
3237 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
3238 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3239 38b240fb 2020-02-06 tracey goto done;
3241 38b240fb 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req, " | ");
3242 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3243 87f9ebf5 2020-01-15 tracey goto done;
3245 12003b6a 2020-04-14 tracey href_briefs = khttp_urlpart(NULL, NULL, "gotweb",
3246 12003b6a 2020-04-14 tracey "path", gw_trans->repo_name, "action", "briefs",
3247 12003b6a 2020-04-14 tracey "commit", id_str, NULL);
3248 19ff7638 2020-04-14 tracey if (href_briefs == NULL) {
3249 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
3250 19ff7638 2020-04-14 tracey goto done;
3252 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
3253 38b240fb 2020-02-06 tracey KATTR_HREF, href_briefs, KATTR__MAX);
3254 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3255 38b240fb 2020-02-06 tracey goto done;
3256 38b240fb 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req,
3257 38b240fb 2020-02-06 tracey "commit briefs");
3258 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3259 38b240fb 2020-02-06 tracey goto done;
3260 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
3261 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3262 38b240fb 2020-02-06 tracey goto done;
3264 38b240fb 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req, " | ");
3265 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3266 38b240fb 2020-02-06 tracey goto done;
3268 12003b6a 2020-04-14 tracey href_commits = khttp_urlpart(NULL, NULL, "gotweb",
3269 12003b6a 2020-04-14 tracey "path", gw_trans->repo_name, "action", "commits",
3270 12003b6a 2020-04-14 tracey "commit", id_str, NULL);
3271 19ff7638 2020-04-14 tracey if (href_commits == NULL) {
3272 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
3273 19ff7638 2020-04-14 tracey goto done;
3275 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
3276 38b240fb 2020-02-06 tracey KATTR_HREF, href_commits, KATTR__MAX);
3277 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3278 38b240fb 2020-02-06 tracey goto done;
3279 32b9f7ed 2020-04-14 tracey kerr = khtml_puts(gw_trans->gw_html_req, "commits");
3280 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3281 38b240fb 2020-02-06 tracey goto done;
3282 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 3);
3283 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3284 38b240fb 2020-02-06 tracey goto done;
3286 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
3287 38b240fb 2020-02-06 tracey KATTR_ID, "dotted_line", KATTR__MAX);
3288 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3289 38b240fb 2020-02-06 tracey goto done;
3290 ef2c200c 2020-02-07 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
3291 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3292 38b240fb 2020-02-06 tracey goto done;
3294 87f9ebf5 2020-01-15 tracey case TAGFULL:
3295 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
3296 38b240fb 2020-02-06 tracey KATTR_ID, "tag_info_date_title", KATTR__MAX);
3297 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3298 38b240fb 2020-02-06 tracey goto done;
3299 38b240fb 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Tag Date:");
3300 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3301 38b240fb 2020-02-06 tracey goto done;
3302 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
3303 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3304 38b240fb 2020-02-06 tracey goto done;
3305 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
3306 38b240fb 2020-02-06 tracey KATTR_ID, "tag_info_date", KATTR__MAX);
3307 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3308 38b240fb 2020-02-06 tracey goto done;
3309 55ccf528 2020-02-03 stsp error = gw_get_time_str(&age, tagger_time, TM_LONG);
3310 55ccf528 2020-02-03 stsp if (error)
3311 4ff7391f 2020-01-28 tracey goto done;
3312 38b240fb 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req,
3313 38b240fb 2020-02-06 tracey age ? age : "");
3314 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3315 070fee27 2020-02-03 stsp goto done;
3316 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
3317 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3318 38b240fb 2020-02-06 tracey goto done;
3320 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
3321 38b240fb 2020-02-06 tracey KATTR_ID, "tag_info_tagger_title", KATTR__MAX);
3322 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3323 38b240fb 2020-02-06 tracey goto done;
3324 38b240fb 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Tagger:");
3325 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3326 38b240fb 2020-02-06 tracey goto done;
3327 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
3328 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3329 38b240fb 2020-02-06 tracey goto done;
3330 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
3331 38b240fb 2020-02-06 tracey KATTR_ID, "tag_info_date", KATTR__MAX);
3332 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3333 38b240fb 2020-02-06 tracey goto done;
3334 38b240fb 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req, tagger);
3335 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3336 38b240fb 2020-02-06 tracey goto done;
3337 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
3338 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3339 38b240fb 2020-02-06 tracey goto done;
3341 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
3342 38b240fb 2020-02-06 tracey KATTR_ID, "tag_info", KATTR__MAX);
3343 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3344 38b240fb 2020-02-06 tracey goto done;
3345 78a9dab5 2020-02-07 tracey kerr = khttp_puts(gw_trans->gw_req, tag_commit);
3346 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3347 4ff7391f 2020-01-28 tracey goto done;
3349 87f9ebf5 2020-01-15 tracey default:
3352 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
3353 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3354 6eccd105 2020-02-03 stsp goto done;
3356 6eccd105 2020-02-03 stsp if (limit && --limit == 0)
3357 ff4bb25f 2020-02-19 tracey chk_next = 1;
3359 ef2c200c 2020-02-07 tracey if (tag)
3360 ef2c200c 2020-02-07 tracey got_object_tag_close(tag);
3361 6eccd105 2020-02-03 stsp tag = NULL;
3362 6c6c85af 2020-01-15 tracey free(id_str);
3363 6eccd105 2020-02-03 stsp id_str = NULL;
3364 6c6c85af 2020-01-15 tracey free(age);
3365 55ccf528 2020-02-03 stsp age = NULL;
3366 f2f46662 2020-01-23 tracey free(tag_commit0);
3367 6eccd105 2020-02-03 stsp tag_commit0 = NULL;
3368 38b240fb 2020-02-06 tracey free(href_tag);
3369 38b240fb 2020-02-06 tracey href_tag = NULL;
3370 38b240fb 2020-02-06 tracey free(href_briefs);
3371 38b240fb 2020-02-06 tracey href_briefs = NULL;
3372 38b240fb 2020-02-06 tracey free(href_commits);
3373 38b240fb 2020-02-06 tracey href_commits = NULL;
3375 ff4bb25f 2020-02-19 tracey if (tag_count == 0) {
3376 ff4bb25f 2020-02-19 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
3377 ff4bb25f 2020-02-19 tracey "summary_tags_title_wrapper", KATTR__MAX);
3378 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
3379 ff4bb25f 2020-02-19 tracey goto done;
3380 ff4bb25f 2020-02-19 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
3381 ff4bb25f 2020-02-19 tracey "summary_tags_title", KATTR__MAX);
3382 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
3383 ff4bb25f 2020-02-19 tracey goto done;
3384 ff4bb25f 2020-02-19 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Tags");
3385 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
3386 ff4bb25f 2020-02-19 tracey goto done;
3387 ff4bb25f 2020-02-19 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
3388 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
3389 ff4bb25f 2020-02-19 tracey goto done;
3390 ff4bb25f 2020-02-19 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
3391 ff4bb25f 2020-02-19 tracey "summary_tags_content", KATTR__MAX);
3392 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
3393 ff4bb25f 2020-02-19 tracey goto done;
3394 ff4bb25f 2020-02-19 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
3395 ff4bb25f 2020-02-19 tracey "tags_info", KATTR__MAX);
3396 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
3397 ff4bb25f 2020-02-19 tracey goto done;
3398 ff4bb25f 2020-02-19 tracey kerr = khttp_puts(gw_trans->gw_req,
3399 ff4bb25f 2020-02-19 tracey "There are no tags for this repo.");
3400 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
3401 ff4bb25f 2020-02-19 tracey goto done;
3402 ff4bb25f 2020-02-19 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
3406 6eccd105 2020-02-03 stsp got_object_tag_close(tag);
3407 6eccd105 2020-02-03 stsp free(id_str);
3408 55ccf528 2020-02-03 stsp free(age);
3409 6eccd105 2020-02-03 stsp free(tag_commit0);
3410 38b240fb 2020-02-06 tracey free(href_tag);
3411 38b240fb 2020-02-06 tracey free(href_briefs);
3412 38b240fb 2020-02-06 tracey free(href_commits);
3413 6eccd105 2020-02-03 stsp got_ref_list_free(&refs);
3414 38b240fb 2020-02-06 tracey if (error == NULL && kerr != KCGI_OK)
3415 38b240fb 2020-02-06 tracey error = gw_kcgi_error(kerr);
3416 6eccd105 2020-02-03 stsp return error;
3419 f2f46662 2020-01-23 tracey static void
3420 b0a1bc86 2020-02-14 stsp gw_free_header(struct gw_header *header)
3422 f2f46662 2020-01-23 tracey free(header->path);
3423 4e8d6e3e 2020-02-14 tracey free(header->author);
3424 4e8d6e3e 2020-02-14 tracey free(header->committer);
3425 f2f46662 2020-01-23 tracey free(header->refs_str);
3426 f2f46662 2020-01-23 tracey free(header->commit_id);
3427 f2f46662 2020-01-23 tracey free(header->parent_id);
3428 f2f46662 2020-01-23 tracey free(header->tree_id);
3429 f2f46662 2020-01-23 tracey free(header->commit_msg);
3432 f2f46662 2020-01-23 tracey static struct gw_header *
3433 f2f46662 2020-01-23 tracey gw_init_header()
3435 f2f46662 2020-01-23 tracey struct gw_header *header;
3437 ae36ed87 2020-01-28 stsp header = malloc(sizeof(*header));
3438 ae36ed87 2020-01-28 stsp if (header == NULL)
3439 f2f46662 2020-01-23 tracey return NULL;
3441 f2f46662 2020-01-23 tracey header->path = NULL;
3442 d9dff0e5 2020-12-26 stsp TAILQ_INIT(&header->refs);
3444 5c65becf 2020-02-13 tracey header->refs_str = NULL;
3445 5c65becf 2020-02-13 tracey header->commit_id = NULL;
3446 f9315db0 2020-02-14 tracey header->committer = NULL;
3447 f9315db0 2020-02-14 tracey header->author = NULL;
3448 5c65becf 2020-02-13 tracey header->parent_id = NULL;
3449 5c65becf 2020-02-13 tracey header->tree_id = NULL;
3450 5c65becf 2020-02-13 tracey header->commit_msg = NULL;
3452 f2f46662 2020-01-23 tracey return header;
3455 f2f46662 2020-01-23 tracey static const struct got_error *
3456 f2f46662 2020-01-23 tracey gw_get_commits(struct gw_trans * gw_trans, struct gw_header *header,
3457 3c245a0e 2020-02-14 tracey int limit, struct got_object_id *id)
3459 f2f46662 2020-01-23 tracey const struct got_error *error = NULL;
3460 f2f46662 2020-01-23 tracey struct got_commit_graph *graph = NULL;
3461 4e8d6e3e 2020-02-14 tracey struct got_commit_object *commit = NULL;
3462 55e46400 2020-02-18 tracey int chk_next = 0, chk_multi = 0, prev_set = 0;
3464 f2f46662 2020-01-23 tracey error = got_commit_graph_open(&graph, header->path, 0);
3465 f2f46662 2020-01-23 tracey if (error)
3466 00f13350 2020-02-10 tracey return error;
3468 deac617c 2020-02-14 tracey error = got_commit_graph_iter_start(graph, id, gw_trans->repo, NULL,
3470 f2f46662 2020-01-23 tracey if (error)
3471 f2f46662 2020-01-23 tracey goto done;
3473 f2f46662 2020-01-23 tracey for (;;) {
3474 deac617c 2020-02-14 tracey error = got_commit_graph_iter_next(&id, graph, gw_trans->repo,
3475 3c245a0e 2020-02-14 tracey NULL, NULL);
3476 f2f46662 2020-01-23 tracey if (error) {
3477 f2f46662 2020-01-23 tracey if (error->code == GOT_ERR_ITER_COMPLETED)
3478 f2f46662 2020-01-23 tracey error = NULL;
3479 f2f46662 2020-01-23 tracey goto done;
3481 3c245a0e 2020-02-14 tracey if (id == NULL)
3482 f2f46662 2020-01-23 tracey goto done;
3484 deac617c 2020-02-14 tracey error = got_object_open_as_commit(&commit, gw_trans->repo, id);
3485 4e8d6e3e 2020-02-14 tracey if (error)
3486 4e8d6e3e 2020-02-14 tracey goto done;
3487 bf4484a3 2020-02-18 tracey if (limit == 1 && chk_multi == 0 &&
3488 bf4484a3 2020-02-18 tracey gw_trans->gw_conf->got_max_commits_display != 1) {
3489 3c245a0e 2020-02-14 tracey error = gw_get_commit(gw_trans, header, commit, id);
3490 4e8d6e3e 2020-02-14 tracey if (error)
3491 4e8d6e3e 2020-02-14 tracey goto done;
3492 4e8d6e3e 2020-02-14 tracey } else {
3493 55e46400 2020-02-18 tracey chk_multi = 1;
3494 f2f46662 2020-01-23 tracey struct gw_header *n_header = NULL;
3495 5147ab56 2020-01-29 stsp if ((n_header = gw_init_header()) == NULL) {
3496 f2f46662 2020-01-23 tracey error = got_error_from_errno("malloc");
3497 a942aa37 2020-02-10 tracey goto done;
3499 bf93a5c0 2020-02-15 tracey error = got_ref_list(&n_header->refs, gw_trans->repo,
3500 bf93a5c0 2020-02-15 tracey NULL, got_ref_cmp_by_name, NULL);
3501 bf93a5c0 2020-02-15 tracey if (error)
3502 bf93a5c0 2020-02-15 tracey goto done;
3504 3c245a0e 2020-02-14 tracey error = gw_get_commit(gw_trans, n_header, commit, id);
3505 4e8d6e3e 2020-02-14 tracey if (error)
3506 d1635ae4 2020-02-13 tracey goto done;
3507 bc8c6114 2020-02-17 tracey got_ref_list_free(&n_header->refs);
3510 55e46400 2020-02-18 tracey * we have a commit_id now, so copy it to next_prev_id
3511 55e46400 2020-02-18 tracey * for navigation through gw_briefs and gw_commits
3513 55e46400 2020-02-18 tracey if (gw_trans->next_prev_id == NULL && prev_set == 0 &&
3514 55e46400 2020-02-18 tracey (gw_trans->action == GW_BRIEFS ||
3515 55e46400 2020-02-18 tracey gw_trans->action == GW_COMMITS ||
3516 55e46400 2020-02-18 tracey gw_trans->action == GW_SUMMARY)) {
3517 55e46400 2020-02-18 tracey prev_set = 1;
3518 55e46400 2020-02-18 tracey gw_trans->next_prev_id =
3519 55e46400 2020-02-18 tracey strdup(n_header->commit_id);
3520 55e46400 2020-02-18 tracey if (gw_trans->next_prev_id == NULL) {
3521 55e46400 2020-02-18 tracey error = got_error_from_errno("strdup");
3522 55e46400 2020-02-18 tracey goto done;
3527 55e46400 2020-02-18 tracey * check for one more commit before breaking,
3528 55e46400 2020-02-18 tracey * so we know whether to navicate through gw_briefs
3529 55e46400 2020-02-18 tracey * gw_commits and gw_summary
3531 55e46400 2020-02-18 tracey if (chk_next && (gw_trans->action == GW_BRIEFS||
3532 55e46400 2020-02-18 tracey gw_trans->action == GW_COMMITS ||
3533 55e46400 2020-02-18 tracey gw_trans->action == GW_SUMMARY)) {
3534 55e46400 2020-02-18 tracey gw_trans->next_id = strdup(n_header->commit_id);
3535 55e46400 2020-02-18 tracey if (gw_trans->next_id == NULL)
3536 55e46400 2020-02-18 tracey error = got_error_from_errno("strdup");
3537 55e46400 2020-02-18 tracey goto done;
3540 f2f46662 2020-01-23 tracey TAILQ_INSERT_TAIL(&gw_trans->gw_headers, n_header,
3543 55e46400 2020-02-18 tracey if (error || (limit && --limit == 0)) {
3544 55e46400 2020-02-18 tracey if (chk_multi == 0)
3546 55e46400 2020-02-18 tracey chk_next = 1;
3550 4e8d6e3e 2020-02-14 tracey if (commit != NULL)
3551 4e8d6e3e 2020-02-14 tracey got_object_commit_close(commit);
3552 f2f46662 2020-01-23 tracey if (graph)
3553 f2f46662 2020-01-23 tracey got_commit_graph_close(graph);
3554 f2f46662 2020-01-23 tracey return error;
3557 f2f46662 2020-01-23 tracey static const struct got_error *
3558 4e8d6e3e 2020-02-14 tracey gw_get_commit(struct gw_trans *gw_trans, struct gw_header *header,
3559 4e8d6e3e 2020-02-14 tracey struct got_commit_object *commit, struct got_object_id *id)
3561 f2f46662 2020-01-23 tracey const struct got_error *error = NULL;
3562 f2f46662 2020-01-23 tracey struct got_reflist_entry *re;
3563 f2f46662 2020-01-23 tracey struct got_object_id *id2 = NULL;
3564 f2f46662 2020-01-23 tracey struct got_object_qid *parent_id;
3565 a81394a7 2020-02-13 stsp char *commit_msg = NULL, *commit_msg0;
3567 f2f46662 2020-01-23 tracey /*print commit*/
3568 d9dff0e5 2020-12-26 stsp TAILQ_FOREACH(re, &header->refs, entry) {
3569 f2f46662 2020-01-23 tracey char *s;
3570 f2f46662 2020-01-23 tracey const char *name;
3571 f2f46662 2020-01-23 tracey struct got_tag_object *tag = NULL;
3572 3721d310 2020-09-23 stsp struct got_object_id *ref_id;
3573 f2f46662 2020-01-23 tracey int cmp;
3575 eb4f3ad3 2020-02-14 stsp if (got_ref_is_symbolic(re->ref))
3576 f2f46662 2020-01-23 tracey continue;
3578 eb4f3ad3 2020-02-14 stsp name = got_ref_get_name(re->ref);
3579 f2f46662 2020-01-23 tracey if (strncmp(name, "refs/", 5) == 0)
3580 f2f46662 2020-01-23 tracey name += 5;
3581 f2f46662 2020-01-23 tracey if (strncmp(name, "got/", 4) == 0)
3582 f2f46662 2020-01-23 tracey continue;
3583 f2f46662 2020-01-23 tracey if (strncmp(name, "heads/", 6) == 0)
3584 f2f46662 2020-01-23 tracey name += 6;
3585 abdd569e 2020-09-23 stsp if (strncmp(name, "remotes/", 8) == 0) {
3586 f2f46662 2020-01-23 tracey name += 8;
3587 abdd569e 2020-09-23 stsp s = strstr(name, "/" GOT_REF_HEAD);
3588 abdd569e 2020-09-23 stsp if (s != NULL && s[strlen(s)] == '\0')
3591 3721d310 2020-09-23 stsp error = got_ref_resolve(&ref_id, gw_trans->repo, re->ref);
3592 3721d310 2020-09-23 stsp if (error)
3593 3721d310 2020-09-23 stsp return error;
3594 f2f46662 2020-01-23 tracey if (strncmp(name, "tags/", 5) == 0) {
3595 deac617c 2020-02-14 tracey error = got_object_open_as_tag(&tag, gw_trans->repo,
3597 f2f46662 2020-01-23 tracey if (error) {
3598 3721d310 2020-09-23 stsp if (error->code != GOT_ERR_OBJ_TYPE) {
3599 3721d310 2020-09-23 stsp free(ref_id);
3600 f2f46662 2020-01-23 tracey continue;
3603 f2f46662 2020-01-23 tracey * Ref points at something other
3604 f2f46662 2020-01-23 tracey * than a tag.
3606 f2f46662 2020-01-23 tracey error = NULL;
3607 f2f46662 2020-01-23 tracey tag = NULL;
3610 f2f46662 2020-01-23 tracey cmp = got_object_id_cmp(tag ?
3611 3721d310 2020-09-23 stsp got_object_tag_get_object_id(tag) : ref_id, id);
3612 3721d310 2020-09-23 stsp free(ref_id);
3613 f2f46662 2020-01-23 tracey if (tag)
3614 f2f46662 2020-01-23 tracey got_object_tag_close(tag);
3615 f2f46662 2020-01-23 tracey if (cmp != 0)
3616 f2f46662 2020-01-23 tracey continue;
3617 a81394a7 2020-02-13 stsp s = header->refs_str;
3618 a81394a7 2020-02-13 stsp if (asprintf(&header->refs_str, "%s%s%s", s ? s : "",
3619 88d59c36 2020-01-29 stsp s ? ", " : "", name) == -1) {
3620 f2f46662 2020-01-23 tracey error = got_error_from_errno("asprintf");
3621 f2f46662 2020-01-23 tracey free(s);
3622 a81394a7 2020-02-13 stsp header->refs_str = NULL;
3623 f2f46662 2020-01-23 tracey return error;
3625 f2f46662 2020-01-23 tracey free(s);
3628 4e8d6e3e 2020-02-14 tracey error = got_object_id_str(&header->commit_id, id);
3629 f2f46662 2020-01-23 tracey if (error)
3630 f2f46662 2020-01-23 tracey return error;
3632 f2f46662 2020-01-23 tracey error = got_object_id_str(&header->tree_id,
3633 4e8d6e3e 2020-02-14 tracey got_object_commit_get_tree_id(commit));
3634 f2f46662 2020-01-23 tracey if (error)
3635 f2f46662 2020-01-23 tracey return error;
3637 f2f46662 2020-01-23 tracey if (gw_trans->action == GW_DIFF) {
3638 f2f46662 2020-01-23 tracey parent_id = SIMPLEQ_FIRST(
3639 4e8d6e3e 2020-02-14 tracey got_object_commit_get_parent_ids(commit));
3640 f2f46662 2020-01-23 tracey if (parent_id != NULL) {
3641 f2f46662 2020-01-23 tracey id2 = got_object_id_dup(parent_id->id);
3642 f2f46662 2020-01-23 tracey free (parent_id);
3643 f2f46662 2020-01-23 tracey error = got_object_id_str(&header->parent_id, id2);
3644 f2f46662 2020-01-23 tracey if (error)
3645 f2f46662 2020-01-23 tracey return error;
3646 f2f46662 2020-01-23 tracey free(id2);
3647 a942aa37 2020-02-10 tracey } else {
3648 d1635ae4 2020-02-13 tracey header->parent_id = strdup("/dev/null");
3649 d1635ae4 2020-02-13 tracey if (header->parent_id == NULL) {
3650 d1635ae4 2020-02-13 tracey error = got_error_from_errno("strdup");
3651 a942aa37 2020-02-10 tracey return error;
3656 f2f46662 2020-01-23 tracey header->committer_time =
3657 4e8d6e3e 2020-02-14 tracey got_object_commit_get_committer_time(commit);
3659 d1635ae4 2020-02-13 tracey header->author =
3660 4e8d6e3e 2020-02-14 tracey strdup(got_object_commit_get_author(commit));
3661 4e8d6e3e 2020-02-14 tracey if (header->author == NULL) {
3662 4e8d6e3e 2020-02-14 tracey error = got_error_from_errno("strdup");
3663 4e8d6e3e 2020-02-14 tracey return error;
3665 d1635ae4 2020-02-13 tracey header->committer =
3666 4e8d6e3e 2020-02-14 tracey strdup(got_object_commit_get_committer(commit));
3667 4e8d6e3e 2020-02-14 tracey if (header->committer == NULL) {
3668 4e8d6e3e 2020-02-14 tracey error = got_error_from_errno("strdup");
3669 a942aa37 2020-02-10 tracey return error;
3671 4e8d6e3e 2020-02-14 tracey error = got_object_commit_get_logmsg(&commit_msg0, commit);
3672 f2f46662 2020-01-23 tracey if (error)
3673 f2f46662 2020-01-23 tracey return error;
3675 f2f46662 2020-01-23 tracey commit_msg = commit_msg0;
3676 f2f46662 2020-01-23 tracey while (*commit_msg == '\n')
3677 f2f46662 2020-01-23 tracey commit_msg++;
3679 d1635ae4 2020-02-13 tracey header->commit_msg = strdup(commit_msg);
3680 d1635ae4 2020-02-13 tracey if (header->commit_msg == NULL)
3681 d1635ae4 2020-02-13 tracey error = got_error_from_errno("strdup");
3682 f2f46662 2020-01-23 tracey free(commit_msg0);
3683 f2f46662 2020-01-23 tracey return error;
3686 f2f46662 2020-01-23 tracey static const struct got_error *
3687 f2f46662 2020-01-23 tracey gw_get_header(struct gw_trans *gw_trans, struct gw_header *header, int limit)
3689 f2f46662 2020-01-23 tracey const struct got_error *error = NULL;
3690 f2f46662 2020-01-23 tracey char *in_repo_path = NULL;
3691 3c245a0e 2020-02-14 tracey struct got_object_id *id = NULL;
3693 deac617c 2020-02-14 tracey error = got_repo_open(&gw_trans->repo, gw_trans->repo_path, NULL);
3694 f2f46662 2020-01-23 tracey if (error)
3695 f2f46662 2020-01-23 tracey return error;
3697 56997cd3 2020-02-14 tracey if (gw_trans->commit_id == NULL) {
3698 f2f46662 2020-01-23 tracey struct got_reference *head_ref;
3699 deac617c 2020-02-14 tracey error = got_ref_open(&head_ref, gw_trans->repo,
3700 f2f46662 2020-01-23 tracey gw_trans->headref, 0);
3701 f2f46662 2020-01-23 tracey if (error)
3702 f2f46662 2020-01-23 tracey return error;
3704 deac617c 2020-02-14 tracey error = got_ref_resolve(&id, gw_trans->repo, head_ref);
3705 f2f46662 2020-01-23 tracey got_ref_close(head_ref);
3706 f2f46662 2020-01-23 tracey if (error)
3707 f2f46662 2020-01-23 tracey return error;
3708 f2f46662 2020-01-23 tracey } else {
3709 f2f46662 2020-01-23 tracey struct got_reference *ref;
3711 56997cd3 2020-02-14 tracey error = got_ref_open(&ref, gw_trans->repo,
3712 56997cd3 2020-02-14 tracey gw_trans->commit_id, 0);
3713 f2f46662 2020-01-23 tracey if (error == NULL) {
3714 f2f46662 2020-01-23 tracey int obj_type;
3715 deac617c 2020-02-14 tracey error = got_ref_resolve(&id, gw_trans->repo, ref);
3716 f2f46662 2020-01-23 tracey got_ref_close(ref);
3717 f2f46662 2020-01-23 tracey if (error)
3718 f2f46662 2020-01-23 tracey return error;
3719 deac617c 2020-02-14 tracey error = got_object_get_type(&obj_type, gw_trans->repo,
3721 f2f46662 2020-01-23 tracey if (error)
3722 4e8d6e3e 2020-02-14 tracey goto done;
3723 f2f46662 2020-01-23 tracey if (obj_type == GOT_OBJ_TYPE_TAG) {
3724 f2f46662 2020-01-23 tracey struct got_tag_object *tag;
3725 f2f46662 2020-01-23 tracey error = got_object_open_as_tag(&tag,
3726 deac617c 2020-02-14 tracey gw_trans->repo, id);
3727 f2f46662 2020-01-23 tracey if (error)
3728 4e8d6e3e 2020-02-14 tracey goto done;
3729 f2f46662 2020-01-23 tracey if (got_object_tag_get_object_type(tag) !=
3730 f2f46662 2020-01-23 tracey GOT_OBJ_TYPE_COMMIT) {
3731 f2f46662 2020-01-23 tracey got_object_tag_close(tag);
3732 f2f46662 2020-01-23 tracey error = got_error(GOT_ERR_OBJ_TYPE);
3733 4e8d6e3e 2020-02-14 tracey goto done;
3735 3c245a0e 2020-02-14 tracey free(id);
3736 3c245a0e 2020-02-14 tracey id = got_object_id_dup(
3737 f2f46662 2020-01-23 tracey got_object_tag_get_object_id(tag));
3738 3c245a0e 2020-02-14 tracey if (id == NULL)
3739 f2f46662 2020-01-23 tracey error = got_error_from_errno(
3740 f2f46662 2020-01-23 tracey "got_object_id_dup");
3741 f2f46662 2020-01-23 tracey got_object_tag_close(tag);
3742 f2f46662 2020-01-23 tracey if (error)
3743 4e8d6e3e 2020-02-14 tracey goto done;
3744 f2f46662 2020-01-23 tracey } else if (obj_type != GOT_OBJ_TYPE_COMMIT) {
3745 f2f46662 2020-01-23 tracey error = got_error(GOT_ERR_OBJ_TYPE);
3746 4e8d6e3e 2020-02-14 tracey goto done;
3749 3c245a0e 2020-02-14 tracey error = got_repo_match_object_id_prefix(&id,
3750 56997cd3 2020-02-14 tracey gw_trans->commit_id, GOT_OBJ_TYPE_COMMIT,
3751 deac617c 2020-02-14 tracey gw_trans->repo);
3752 122f3af5 2020-02-14 stsp if (error)
3753 4e8d6e3e 2020-02-14 tracey goto done;
3756 deac617c 2020-02-14 tracey error = got_repo_map_path(&in_repo_path, gw_trans->repo,
3757 8b4e047e 2020-11-15 stsp gw_trans->repo_path);
3758 f2f46662 2020-01-23 tracey if (error)
3759 4e8d6e3e 2020-02-14 tracey goto done;
3761 f2f46662 2020-01-23 tracey if (in_repo_path) {
3762 d1635ae4 2020-02-13 tracey header->path = strdup(in_repo_path);
3763 d1635ae4 2020-02-13 tracey if (header->path == NULL) {
3764 d1635ae4 2020-02-13 tracey error = got_error_from_errno("strdup");
3765 4e8d6e3e 2020-02-14 tracey goto done;
3769 deac617c 2020-02-14 tracey error = got_ref_list(&header->refs, gw_trans->repo, NULL,
3770 f2f46662 2020-01-23 tracey got_ref_cmp_by_name, NULL);
3771 f2f46662 2020-01-23 tracey if (error)
3772 4e8d6e3e 2020-02-14 tracey goto done;
3774 3c245a0e 2020-02-14 tracey error = gw_get_commits(gw_trans, header, limit, id);
3776 4e8d6e3e 2020-02-14 tracey got_ref_list_free(&header->refs);
3777 3c245a0e 2020-02-14 tracey free(id);
3778 4e8d6e3e 2020-02-14 tracey free(in_repo_path);
3779 f2f46662 2020-01-23 tracey return error;
3782 ec46ccd7 2020-01-15 tracey struct blame_line {
3783 ec46ccd7 2020-01-15 tracey int annotated;
3784 ec46ccd7 2020-01-15 tracey char *id_str;
3785 ec46ccd7 2020-01-15 tracey char *committer;
3786 ec46ccd7 2020-01-15 tracey char datebuf[11]; /* YYYY-MM-DD + NUL */
3789 147269d5 2020-01-15 tracey struct gw_blame_cb_args {
3790 ec46ccd7 2020-01-15 tracey struct blame_line *lines;
3791 ec46ccd7 2020-01-15 tracey int nlines;
3792 ec46ccd7 2020-01-15 tracey int nlines_prec;
3793 ec46ccd7 2020-01-15 tracey int lineno_cur;
3794 ec46ccd7 2020-01-15 tracey off_t *line_offsets;
3795 ec46ccd7 2020-01-15 tracey FILE *f;
3796 ec46ccd7 2020-01-15 tracey struct got_repository *repo;
3797 54415d85 2020-01-15 tracey struct gw_trans *gw_trans;
3800 ec46ccd7 2020-01-15 tracey static const struct got_error *
3801 147269d5 2020-01-15 tracey gw_blame_cb(void *arg, int nlines, int lineno, struct got_object_id *id)
3803 ec46ccd7 2020-01-15 tracey const struct got_error *err = NULL;
3804 147269d5 2020-01-15 tracey struct gw_blame_cb_args *a = arg;
3805 ec46ccd7 2020-01-15 tracey struct blame_line *bline;
3806 ec46ccd7 2020-01-15 tracey char *line = NULL;
3807 9a9d12ca 2020-02-06 tracey size_t linesize = 0;
3808 ec46ccd7 2020-01-15 tracey struct got_commit_object *commit = NULL;
3809 ec46ccd7 2020-01-15 tracey off_t offset;
3810 ec46ccd7 2020-01-15 tracey struct tm tm;
3811 ec46ccd7 2020-01-15 tracey time_t committer_time;
3812 9a9d12ca 2020-02-06 tracey enum kcgi_err kerr = KCGI_OK;
3814 ec46ccd7 2020-01-15 tracey if (nlines != a->nlines ||
3815 ec46ccd7 2020-01-15 tracey (lineno != -1 && lineno < 1) || lineno > a->nlines)
3816 ec46ccd7 2020-01-15 tracey return got_error(GOT_ERR_RANGE);
3818 ec46ccd7 2020-01-15 tracey if (lineno == -1)
3819 ec46ccd7 2020-01-15 tracey return NULL; /* no change in this commit */
3821 ec46ccd7 2020-01-15 tracey /* Annotate this line. */
3822 ec46ccd7 2020-01-15 tracey bline = &a->lines[lineno - 1];
3823 ec46ccd7 2020-01-15 tracey if (bline->annotated)
3824 ec46ccd7 2020-01-15 tracey return NULL;
3825 ec46ccd7 2020-01-15 tracey err = got_object_id_str(&bline->id_str, id);
3826 ec46ccd7 2020-01-15 tracey if (err)
3827 ec46ccd7 2020-01-15 tracey return err;
3829 ec46ccd7 2020-01-15 tracey err = got_object_open_as_commit(&commit, a->repo, id);
3830 ec46ccd7 2020-01-15 tracey if (err)
3831 ec46ccd7 2020-01-15 tracey goto done;
3833 d1635ae4 2020-02-13 tracey bline->committer = strdup(got_object_commit_get_committer(commit));
3834 d1635ae4 2020-02-13 tracey if (bline->committer == NULL) {
3835 d1635ae4 2020-02-13 tracey err = got_error_from_errno("strdup");
3836 ec46ccd7 2020-01-15 tracey goto done;
3839 ec46ccd7 2020-01-15 tracey committer_time = got_object_commit_get_committer_time(commit);
3840 ec46ccd7 2020-01-15 tracey if (localtime_r(&committer_time, &tm) == NULL)
3841 ec46ccd7 2020-01-15 tracey return got_error_from_errno("localtime_r");
3842 ec46ccd7 2020-01-15 tracey if (strftime(bline->datebuf, sizeof(bline->datebuf), "%G-%m-%d",
3843 ec6d1a36 2021-03-21 jrick &tm) == 0) {
3844 ec46ccd7 2020-01-15 tracey err = got_error(GOT_ERR_NO_SPACE);
3845 ec46ccd7 2020-01-15 tracey goto done;
3847 ec46ccd7 2020-01-15 tracey bline->annotated = 1;
3849 ec46ccd7 2020-01-15 tracey /* Print lines annotated so far. */
3850 ec46ccd7 2020-01-15 tracey bline = &a->lines[a->lineno_cur - 1];
3851 ec46ccd7 2020-01-15 tracey if (!bline->annotated)
3852 ec46ccd7 2020-01-15 tracey goto done;
3854 ec46ccd7 2020-01-15 tracey offset = a->line_offsets[a->lineno_cur - 1];
3855 ec46ccd7 2020-01-15 tracey if (fseeko(a->f, offset, SEEK_SET) == -1) {
3856 ec46ccd7 2020-01-15 tracey err = got_error_from_errno("fseeko");
3857 ec46ccd7 2020-01-15 tracey goto done;
3860 ec46ccd7 2020-01-15 tracey while (bline->annotated) {
3861 9a9d12ca 2020-02-06 tracey char *smallerthan, *at, *nl, *committer;
3862 32b9f7ed 2020-04-14 tracey char *href_diff = NULL;
3863 ec46ccd7 2020-01-15 tracey size_t len;
3865 ec46ccd7 2020-01-15 tracey if (getline(&line, &linesize, a->f) == -1) {
3866 ec46ccd7 2020-01-15 tracey if (ferror(a->f))
3867 ec46ccd7 2020-01-15 tracey err = got_error_from_errno("getline");
3871 ec46ccd7 2020-01-15 tracey committer = bline->committer;
3872 ec46ccd7 2020-01-15 tracey smallerthan = strchr(committer, '<');
3873 ec46ccd7 2020-01-15 tracey if (smallerthan && smallerthan[1] != '\0')
3874 ec46ccd7 2020-01-15 tracey committer = smallerthan + 1;
3875 ec46ccd7 2020-01-15 tracey at = strchr(committer, '@');
3877 ec46ccd7 2020-01-15 tracey *at = '\0';
3878 ec46ccd7 2020-01-15 tracey len = strlen(committer);
3879 ec46ccd7 2020-01-15 tracey if (len >= 9)
3880 ec46ccd7 2020-01-15 tracey committer[8] = '\0';
3882 ec46ccd7 2020-01-15 tracey nl = strchr(line, '\n');
3884 ec46ccd7 2020-01-15 tracey *nl = '\0';
3886 9a9d12ca 2020-02-06 tracey kerr = khtml_attr(a->gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
3887 9a9d12ca 2020-02-06 tracey "blame_wrapper", KATTR__MAX);
3888 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
3889 9a9d12ca 2020-02-06 tracey goto err;
3890 9a9d12ca 2020-02-06 tracey kerr = khtml_attr(a->gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
3891 9a9d12ca 2020-02-06 tracey "blame_number", KATTR__MAX);
3892 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
3893 9a9d12ca 2020-02-06 tracey goto err;
3894 32b9f7ed 2020-04-14 tracey kerr = khtml_printf(a->gw_trans->gw_html_req, "%.*d",
3895 32b9f7ed 2020-04-14 tracey a->nlines_prec, a->lineno_cur);
3896 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
3897 9a9d12ca 2020-02-06 tracey goto err;
3898 9a9d12ca 2020-02-06 tracey kerr = khtml_closeelem(a->gw_trans->gw_html_req, 1);
3899 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
3900 9a9d12ca 2020-02-06 tracey goto err;
3902 9a9d12ca 2020-02-06 tracey kerr = khtml_attr(a->gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
3903 9a9d12ca 2020-02-06 tracey "blame_hash", KATTR__MAX);
3904 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
3905 9a9d12ca 2020-02-06 tracey goto err;
3907 ebc6542a 2020-04-14 tracey href_diff = khttp_urlpart(NULL, NULL, "gotweb", "path",
3908 ebc6542a 2020-04-14 tracey a->gw_trans->repo_name, "action", "diff", "commit",
3909 ebc6542a 2020-04-14 tracey bline->id_str, NULL);
3910 19ff7638 2020-04-14 tracey if (href_diff == NULL) {
3911 19ff7638 2020-04-14 tracey err = got_error_from_errno("khttp_urlpart");
3912 19ff7638 2020-04-14 tracey goto done;
3914 9a9d12ca 2020-02-06 tracey kerr = khtml_attr(a->gw_trans->gw_html_req, KELEM_A,
3915 9a9d12ca 2020-02-06 tracey KATTR_HREF, href_diff, KATTR__MAX);
3916 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
3917 9a9d12ca 2020-02-06 tracey goto done;
3918 32b9f7ed 2020-04-14 tracey kerr = khtml_printf(a->gw_trans->gw_html_req, "%.8s",
3919 32b9f7ed 2020-04-14 tracey bline->id_str);
3920 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
3921 9a9d12ca 2020-02-06 tracey goto err;
3922 9a9d12ca 2020-02-06 tracey kerr = khtml_closeelem(a->gw_trans->gw_html_req, 2);
3923 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
3924 9a9d12ca 2020-02-06 tracey goto err;
3926 9a9d12ca 2020-02-06 tracey kerr = khtml_attr(a->gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
3927 9a9d12ca 2020-02-06 tracey "blame_date", KATTR__MAX);
3928 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
3929 9a9d12ca 2020-02-06 tracey goto err;
3930 9a9d12ca 2020-02-06 tracey kerr = khtml_puts(a->gw_trans->gw_html_req, bline->datebuf);
3931 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
3932 9a9d12ca 2020-02-06 tracey goto err;
3933 9a9d12ca 2020-02-06 tracey kerr = khtml_closeelem(a->gw_trans->gw_html_req, 1);
3934 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
3935 9a9d12ca 2020-02-06 tracey goto err;
3937 9a9d12ca 2020-02-06 tracey kerr = khtml_attr(a->gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
3938 9a9d12ca 2020-02-06 tracey "blame_author", KATTR__MAX);
3939 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
3940 9a9d12ca 2020-02-06 tracey goto err;
3941 9a9d12ca 2020-02-06 tracey kerr = khtml_puts(a->gw_trans->gw_html_req, committer);
3942 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
3943 9a9d12ca 2020-02-06 tracey goto err;
3944 9a9d12ca 2020-02-06 tracey kerr = khtml_closeelem(a->gw_trans->gw_html_req, 1);
3945 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
3946 9a9d12ca 2020-02-06 tracey goto err;
3948 9a9d12ca 2020-02-06 tracey kerr = khtml_attr(a->gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
3949 9a9d12ca 2020-02-06 tracey "blame_code", KATTR__MAX);
3950 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
3951 9a9d12ca 2020-02-06 tracey goto err;
3952 9a9d12ca 2020-02-06 tracey kerr = khtml_puts(a->gw_trans->gw_html_req, line);
3953 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
3954 9a9d12ca 2020-02-06 tracey goto err;
3955 9a9d12ca 2020-02-06 tracey kerr = khtml_closeelem(a->gw_trans->gw_html_req, 1);
3956 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
3957 9a9d12ca 2020-02-06 tracey goto err;
3959 9a9d12ca 2020-02-06 tracey kerr = khtml_closeelem(a->gw_trans->gw_html_req, 1);
3960 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
3961 9a9d12ca 2020-02-06 tracey goto err;
3963 9a9d12ca 2020-02-06 tracey a->lineno_cur++;
3964 ec46ccd7 2020-01-15 tracey bline = &a->lines[a->lineno_cur - 1];
3966 9a9d12ca 2020-02-06 tracey free(href_diff);
3969 ec46ccd7 2020-01-15 tracey if (commit)
3970 ec46ccd7 2020-01-15 tracey got_object_commit_close(commit);
3971 ec46ccd7 2020-01-15 tracey free(line);
3972 9a9d12ca 2020-02-06 tracey if (err == NULL && kerr != KCGI_OK)
3973 9a9d12ca 2020-02-06 tracey err = gw_kcgi_error(kerr);
3974 ec46ccd7 2020-01-15 tracey return err;
3977 a81f3554 2020-02-03 stsp static const struct got_error *
3978 84de9106 2020-12-26 stsp gw_output_file_blame(struct gw_trans *gw_trans, struct gw_header *header)
3980 bcbc97d8 2020-01-15 tracey const struct got_error *error = NULL;
3981 ec46ccd7 2020-01-15 tracey struct got_object_id *obj_id = NULL;
3982 ec46ccd7 2020-01-15 tracey struct got_object_id *commit_id = NULL;
3983 ec46ccd7 2020-01-15 tracey struct got_blob_object *blob = NULL;
3984 a81f3554 2020-02-03 stsp char *path = NULL, *in_repo_path = NULL;
3985 147269d5 2020-01-15 tracey struct gw_blame_cb_args bca;
3986 119bf4ed 2020-01-15 tracey int i, obj_type;
3987 be659d10 2020-11-18 stsp off_t filesize;
3989 a81f3554 2020-02-03 stsp if (asprintf(&path, "%s%s%s",
3990 a81f3554 2020-02-03 stsp gw_trans->repo_folder ? gw_trans->repo_folder : "",
3991 4fd4726a 2020-02-03 stsp gw_trans->repo_folder ? "/" : "",
3992 a81f3554 2020-02-03 stsp gw_trans->repo_file) == -1) {
3993 2e676fc5 2020-01-15 tracey error = got_error_from_errno("asprintf");
3994 2e676fc5 2020-01-15 tracey goto done;
3997 8b4e047e 2020-11-15 stsp error = got_repo_map_path(&in_repo_path, gw_trans->repo, path);
3998 ec46ccd7 2020-01-15 tracey if (error)
3999 ec46ccd7 2020-01-15 tracey goto done;
4001 56997cd3 2020-02-14 tracey error = got_repo_match_object_id(&commit_id, NULL, gw_trans->commit_id,
4002 84de9106 2020-12-26 stsp GOT_OBJ_TYPE_COMMIT, &header->refs, gw_trans->repo);
4003 ec46ccd7 2020-01-15 tracey if (error)
4004 ec46ccd7 2020-01-15 tracey goto done;
4006 deac617c 2020-02-14 tracey error = got_object_id_by_path(&obj_id, gw_trans->repo, commit_id,
4007 deac617c 2020-02-14 tracey in_repo_path);
4008 ec46ccd7 2020-01-15 tracey if (error)
4009 ec46ccd7 2020-01-15 tracey goto done;
4011 ec46ccd7 2020-01-15 tracey if (obj_id == NULL) {
4012 ec46ccd7 2020-01-15 tracey error = got_error(GOT_ERR_NO_OBJ);
4013 ec46ccd7 2020-01-15 tracey goto done;
4016 deac617c 2020-02-14 tracey error = got_object_get_type(&obj_type, gw_trans->repo, obj_id);
4017 ec46ccd7 2020-01-15 tracey if (error)
4018 ec46ccd7 2020-01-15 tracey goto done;
4020 ec46ccd7 2020-01-15 tracey if (obj_type != GOT_OBJ_TYPE_BLOB) {
4021 ec46ccd7 2020-01-15 tracey error = got_error(GOT_ERR_OBJ_TYPE);
4022 ec46ccd7 2020-01-15 tracey goto done;
4025 deac617c 2020-02-14 tracey error = got_object_open_as_blob(&blob, gw_trans->repo, obj_id, 8192);
4026 ec46ccd7 2020-01-15 tracey if (error)
4027 ec46ccd7 2020-01-15 tracey goto done;
4029 ec46ccd7 2020-01-15 tracey bca.f = got_opentemp();
4030 ec46ccd7 2020-01-15 tracey if (bca.f == NULL) {
4031 ec46ccd7 2020-01-15 tracey error = got_error_from_errno("got_opentemp");
4032 ec46ccd7 2020-01-15 tracey goto done;
4034 ec46ccd7 2020-01-15 tracey error = got_object_blob_dump_to_file(&filesize, &bca.nlines,
4035 ec46ccd7 2020-01-15 tracey &bca.line_offsets, bca.f, blob);
4036 ec46ccd7 2020-01-15 tracey if (error || bca.nlines == 0)
4037 ec46ccd7 2020-01-15 tracey goto done;
4039 ec46ccd7 2020-01-15 tracey /* Don't include \n at EOF in the blame line count. */
4040 ec46ccd7 2020-01-15 tracey if (bca.line_offsets[bca.nlines - 1] == filesize)
4041 ec46ccd7 2020-01-15 tracey bca.nlines--;
4043 ec46ccd7 2020-01-15 tracey bca.lines = calloc(bca.nlines, sizeof(*bca.lines));
4044 ec46ccd7 2020-01-15 tracey if (bca.lines == NULL) {
4045 ec46ccd7 2020-01-15 tracey error = got_error_from_errno("calloc");
4046 ec46ccd7 2020-01-15 tracey goto done;
4048 ec46ccd7 2020-01-15 tracey bca.lineno_cur = 1;
4049 ec46ccd7 2020-01-15 tracey bca.nlines_prec = 0;
4050 ec46ccd7 2020-01-15 tracey i = bca.nlines;
4051 ec46ccd7 2020-01-15 tracey while (i > 0) {
4052 ec46ccd7 2020-01-15 tracey i /= 10;
4053 ec46ccd7 2020-01-15 tracey bca.nlines_prec++;
4055 deac617c 2020-02-14 tracey bca.repo = gw_trans->repo;
4056 2e676fc5 2020-01-15 tracey bca.gw_trans = gw_trans;
4058 deac617c 2020-02-14 tracey error = got_blame(in_repo_path, commit_id, gw_trans->repo, gw_blame_cb,
4059 deac617c 2020-02-14 tracey &bca, NULL, NULL);
4061 2e676fc5 2020-01-15 tracey free(in_repo_path);
4062 2e676fc5 2020-01-15 tracey free(commit_id);
4063 2e676fc5 2020-01-15 tracey free(obj_id);
4064 2e676fc5 2020-01-15 tracey free(path);
4066 1b33afc0 2020-02-14 tracey if (blob) {
4067 1b33afc0 2020-02-14 tracey free(bca.line_offsets);
4068 1b33afc0 2020-02-14 tracey for (i = 0; i < bca.nlines; i++) {
4069 1b33afc0 2020-02-14 tracey struct blame_line *bline = &bca.lines[i];
4070 1b33afc0 2020-02-14 tracey free(bline->id_str);
4071 1b33afc0 2020-02-14 tracey free(bline->committer);
4073 1b33afc0 2020-02-14 tracey free(bca.lines);
4074 1b33afc0 2020-02-14 tracey if (bca.f && fclose(bca.f) == EOF && error == NULL)
4075 1b33afc0 2020-02-14 tracey error = got_error_from_errno("fclose");
4078 4fd4726a 2020-02-03 stsp got_object_blob_close(blob);
4079 4fd4726a 2020-02-03 stsp return error;
4082 4fd4726a 2020-02-03 stsp static const struct got_error *
4083 84de9106 2020-12-26 stsp gw_output_blob_buf(struct gw_trans *gw_trans, struct gw_header *header)
4085 4fd4726a 2020-02-03 stsp const struct got_error *error = NULL;
4086 4fd4726a 2020-02-03 stsp struct got_object_id *obj_id = NULL;
4087 4fd4726a 2020-02-03 stsp struct got_object_id *commit_id = NULL;
4088 4fd4726a 2020-02-03 stsp struct got_blob_object *blob = NULL;
4089 4fd4726a 2020-02-03 stsp char *path = NULL, *in_repo_path = NULL;
4090 e0857cfe 2020-02-06 tracey int obj_type, set_mime = 0;
4091 e0857cfe 2020-02-06 tracey size_t len, hdrlen;
4092 e0857cfe 2020-02-06 tracey const uint8_t *buf;
4093 e0857cfe 2020-02-06 tracey enum kcgi_err kerr = KCGI_OK;
4095 4fd4726a 2020-02-03 stsp if (asprintf(&path, "%s%s%s",
4096 4fd4726a 2020-02-03 stsp gw_trans->repo_folder ? gw_trans->repo_folder : "",
4097 4fd4726a 2020-02-03 stsp gw_trans->repo_folder ? "/" : "",
4098 4fd4726a 2020-02-03 stsp gw_trans->repo_file) == -1) {
4099 4fd4726a 2020-02-03 stsp error = got_error_from_errno("asprintf");
4100 4fd4726a 2020-02-03 stsp goto done;
4103 8b4e047e 2020-11-15 stsp error = got_repo_map_path(&in_repo_path, gw_trans->repo, path);
4104 4fd4726a 2020-02-03 stsp if (error)
4105 4fd4726a 2020-02-03 stsp goto done;
4107 56997cd3 2020-02-14 tracey error = got_repo_match_object_id(&commit_id, NULL, gw_trans->commit_id,
4108 84de9106 2020-12-26 stsp GOT_OBJ_TYPE_COMMIT, &header->refs, gw_trans->repo);
4109 4fd4726a 2020-02-03 stsp if (error)
4110 4fd4726a 2020-02-03 stsp goto done;
4112 deac617c 2020-02-14 tracey error = got_object_id_by_path(&obj_id, gw_trans->repo, commit_id,
4113 deac617c 2020-02-14 tracey in_repo_path);
4114 4fd4726a 2020-02-03 stsp if (error)
4115 4fd4726a 2020-02-03 stsp goto done;
4117 4fd4726a 2020-02-03 stsp if (obj_id == NULL) {
4118 4fd4726a 2020-02-03 stsp error = got_error(GOT_ERR_NO_OBJ);
4119 4fd4726a 2020-02-03 stsp goto done;
4122 deac617c 2020-02-14 tracey error = got_object_get_type(&obj_type, gw_trans->repo, obj_id);
4123 4fd4726a 2020-02-03 stsp if (error)
4124 4fd4726a 2020-02-03 stsp goto done;
4126 4fd4726a 2020-02-03 stsp if (obj_type != GOT_OBJ_TYPE_BLOB) {
4127 4fd4726a 2020-02-03 stsp error = got_error(GOT_ERR_OBJ_TYPE);
4128 4fd4726a 2020-02-03 stsp goto done;
4131 deac617c 2020-02-14 tracey error = got_object_open_as_blob(&blob, gw_trans->repo, obj_id, 8192);
4132 4fd4726a 2020-02-03 stsp if (error)
4133 4fd4726a 2020-02-03 stsp goto done;
4135 e0857cfe 2020-02-06 tracey hdrlen = got_object_blob_get_hdrlen(blob);
4137 e0857cfe 2020-02-06 tracey error = got_object_blob_read_block(&len, blob);
4138 e0857cfe 2020-02-06 tracey if (error)
4139 e0857cfe 2020-02-06 tracey goto done;
4140 e0857cfe 2020-02-06 tracey buf = got_object_blob_get_read_buf(blob);
4143 e0857cfe 2020-02-06 tracey * Skip blob object header first time around,
4144 e0857cfe 2020-02-06 tracey * which also contains a zero byte.
4146 e0857cfe 2020-02-06 tracey buf += hdrlen;
4147 e0857cfe 2020-02-06 tracey if (set_mime == 0) {
4148 e0857cfe 2020-02-06 tracey if (isbinary(buf, len - hdrlen))
4149 e0857cfe 2020-02-06 tracey gw_trans->mime = KMIME_APP_OCTET_STREAM;
4151 e0857cfe 2020-02-06 tracey gw_trans->mime = KMIME_TEXT_PLAIN;
4152 e0857cfe 2020-02-06 tracey set_mime = 1;
4153 e0857cfe 2020-02-06 tracey error = gw_display_index(gw_trans);
4154 e0857cfe 2020-02-06 tracey if (error)
4155 e0857cfe 2020-02-06 tracey goto done;
4157 3b7fdcf4 2020-02-14 tracey kerr = khttp_write(gw_trans->gw_req, buf, len - hdrlen);
4158 c56af3fd 2020-02-17 stsp if (kerr != KCGI_OK)
4159 c56af3fd 2020-02-17 stsp goto done;
4160 e0857cfe 2020-02-06 tracey hdrlen = 0;
4161 e0857cfe 2020-02-06 tracey } while (len != 0);
4163 4fd4726a 2020-02-03 stsp free(in_repo_path);
4164 4fd4726a 2020-02-03 stsp free(commit_id);
4165 4fd4726a 2020-02-03 stsp free(obj_id);
4166 4fd4726a 2020-02-03 stsp free(path);
4167 e46f587c 2020-01-29 tracey if (blob)
4168 a81f3554 2020-02-03 stsp got_object_blob_close(blob);
4169 e0857cfe 2020-02-06 tracey if (error == NULL && kerr != KCGI_OK)
4170 e0857cfe 2020-02-06 tracey error = gw_kcgi_error(kerr);
4171 a81f3554 2020-02-03 stsp return error;
4174 84bf4df2 2020-02-03 stsp static const struct got_error *
4175 84de9106 2020-12-26 stsp gw_output_repo_tree(struct gw_trans *gw_trans, struct gw_header *header)
4177 ec46ccd7 2020-01-15 tracey const struct got_error *error = NULL;
4178 bcbc97d8 2020-01-15 tracey struct got_object_id *tree_id = NULL, *commit_id = NULL;
4179 bcbc97d8 2020-01-15 tracey struct got_tree_object *tree = NULL;
4180 626b25b6 2020-02-06 tracey char *path = NULL, *in_repo_path = NULL;
4181 84bf4df2 2020-02-03 stsp char *id_str = NULL;
4182 84bf4df2 2020-02-03 stsp char *build_folder = NULL;
4183 626b25b6 2020-02-06 tracey char *href_blob = NULL, *href_blame = NULL;
4184 84bf4df2 2020-02-03 stsp const char *class = NULL;
4185 c3bcdfd5 2020-01-29 tracey int nentries, i, class_flip = 0;
4186 626b25b6 2020-02-06 tracey enum kcgi_err kerr = KCGI_OK;
4188 a942aa37 2020-02-10 tracey if (gw_trans->repo_folder != NULL) {
4189 d1635ae4 2020-02-13 tracey path = strdup(gw_trans->repo_folder);
4190 d1635ae4 2020-02-13 tracey if (path == NULL) {
4191 d1635ae4 2020-02-13 tracey error = got_error_from_errno("strdup");
4192 a942aa37 2020-02-10 tracey goto done;
4194 a942aa37 2020-02-10 tracey } else {
4195 deac617c 2020-02-14 tracey error = got_repo_map_path(&in_repo_path, gw_trans->repo,
4196 8b4e047e 2020-11-15 stsp gw_trans->repo_path);
4197 84bf4df2 2020-02-03 stsp if (error)
4198 84bf4df2 2020-02-03 stsp goto done;
4199 bcbc97d8 2020-01-15 tracey free(path);
4200 bcbc97d8 2020-01-15 tracey path = in_repo_path;
4203 56997cd3 2020-02-14 tracey if (gw_trans->commit_id == NULL) {
4204 ec46ccd7 2020-01-15 tracey struct got_reference *head_ref;
4205 deac617c 2020-02-14 tracey error = got_ref_open(&head_ref, gw_trans->repo,
4206 deac617c 2020-02-14 tracey gw_trans->headref, 0);
4207 ec46ccd7 2020-01-15 tracey if (error)
4208 ec46ccd7 2020-01-15 tracey goto done;
4209 deac617c 2020-02-14 tracey error = got_ref_resolve(&commit_id, gw_trans->repo, head_ref);
4210 84bf4df2 2020-02-03 stsp if (error)
4211 84bf4df2 2020-02-03 stsp goto done;
4212 ec46ccd7 2020-01-15 tracey got_ref_close(head_ref);
4214 56997cd3 2020-02-14 tracey * gw_trans->commit_id was not parsed from the querystring
4215 56997cd3 2020-02-14 tracey * we hit this code path from gw_index, where we don't know the
4216 56997cd3 2020-02-14 tracey * commit values for the tree link yet, so set
4217 56997cd3 2020-02-14 tracey * gw_trans->commit_id here to continue further into the tree
4219 56997cd3 2020-02-14 tracey error = got_object_id_str(&gw_trans->commit_id, commit_id);
4220 56997cd3 2020-02-14 tracey if (error)
4221 56997cd3 2020-02-14 tracey goto done;
4224 f2f46662 2020-01-23 tracey error = got_repo_match_object_id(&commit_id, NULL,
4225 84de9106 2020-12-26 stsp gw_trans->commit_id, GOT_OBJ_TYPE_COMMIT, &header->refs,
4226 56997cd3 2020-02-14 tracey gw_trans->repo);
4227 84bf4df2 2020-02-03 stsp if (error)
4228 84bf4df2 2020-02-03 stsp goto done;
4231 56997cd3 2020-02-14 tracey error = got_object_id_by_path(&tree_id, gw_trans->repo, commit_id,
4233 bcbc97d8 2020-01-15 tracey if (error)
4234 bcbc97d8 2020-01-15 tracey goto done;
4236 deac617c 2020-02-14 tracey error = got_object_open_as_tree(&tree, gw_trans->repo, tree_id);
4237 bcbc97d8 2020-01-15 tracey if (error)
4238 bcbc97d8 2020-01-15 tracey goto done;
4240 bcbc97d8 2020-01-15 tracey nentries = got_object_tree_get_nentries(tree);
4241 bcbc97d8 2020-01-15 tracey for (i = 0; i < nentries; i++) {
4242 bcbc97d8 2020-01-15 tracey struct got_tree_entry *te;
4243 ec46ccd7 2020-01-15 tracey const char *modestr = "";
4244 84bf4df2 2020-02-03 stsp mode_t mode;
4246 bcbc97d8 2020-01-15 tracey te = got_object_tree_get_entry(tree, i);
4248 bcbc97d8 2020-01-15 tracey error = got_object_id_str(&id_str, got_tree_entry_get_id(te));
4249 bcbc97d8 2020-01-15 tracey if (error)
4250 bcbc97d8 2020-01-15 tracey goto done;
4252 84bf4df2 2020-02-03 stsp mode = got_tree_entry_get_mode(te);
4253 bcbc97d8 2020-01-15 tracey if (got_object_tree_entry_is_submodule(te))
4254 bcbc97d8 2020-01-15 tracey modestr = "$";
4255 bcbc97d8 2020-01-15 tracey else if (S_ISLNK(mode))
4256 bcbc97d8 2020-01-15 tracey modestr = "@";
4257 bcbc97d8 2020-01-15 tracey else if (S_ISDIR(mode))
4258 bcbc97d8 2020-01-15 tracey modestr = "/";
4259 bcbc97d8 2020-01-15 tracey else if (mode & S_IXUSR)
4260 bcbc97d8 2020-01-15 tracey modestr = "*";
4262 c3bcdfd5 2020-01-29 tracey if (class_flip == 0) {
4263 84bf4df2 2020-02-03 stsp class = "back_lightgray";
4264 c3bcdfd5 2020-01-29 tracey class_flip = 1;
4265 c3bcdfd5 2020-01-29 tracey } else {
4266 84bf4df2 2020-02-03 stsp class = "back_white";
4267 c3bcdfd5 2020-01-29 tracey class_flip = 0;
4270 84bf4df2 2020-02-03 stsp if (S_ISDIR(mode)) {
4271 a5594e37 2020-02-05 tracey if (asprintf(&build_folder, "%s/%s",
4272 84bf4df2 2020-02-03 stsp gw_trans->repo_folder ? gw_trans->repo_folder : "",
4273 84bf4df2 2020-02-03 stsp got_tree_entry_get_name(te)) == -1) {
4274 53e81e48 2020-02-13 tracey error = got_error_from_errno("asprintf");
4275 84bf4df2 2020-02-03 stsp goto done;
4278 c6eb96ac 2020-04-14 tracey href_blob = khttp_urlpart(NULL, NULL, "gotweb", "path",
4279 c6eb96ac 2020-04-14 tracey gw_trans->repo_name, "action",
4280 c6eb96ac 2020-04-14 tracey gw_get_action_name(gw_trans), "commit",
4281 c6eb96ac 2020-04-14 tracey gw_trans->commit_id, "folder", build_folder, NULL);
4282 19ff7638 2020-04-14 tracey if (href_blob == NULL) {
4283 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
4284 19ff7638 2020-04-14 tracey goto done;
4286 626b25b6 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
4287 626b25b6 2020-02-06 tracey KATTR_ID, "tree_wrapper", KATTR__MAX);
4288 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4289 626b25b6 2020-02-06 tracey goto done;
4290 626b25b6 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
4291 626b25b6 2020-02-06 tracey KATTR_ID, "tree_line", KATTR_CLASS, class,
4292 626b25b6 2020-02-06 tracey KATTR__MAX);
4293 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4294 626b25b6 2020-02-06 tracey goto done;
4295 626b25b6 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
4296 626b25b6 2020-02-06 tracey KATTR_HREF, href_blob, KATTR_CLASS,
4297 626b25b6 2020-02-06 tracey "diff_directory", KATTR__MAX);
4298 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4299 626b25b6 2020-02-06 tracey goto done;
4300 32b9f7ed 2020-04-14 tracey kerr = khtml_printf(gw_trans->gw_html_req, "%s%s",
4301 32b9f7ed 2020-04-14 tracey got_tree_entry_get_name(te), modestr);
4302 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4303 626b25b6 2020-02-06 tracey goto done;
4304 626b25b6 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
4305 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4306 626b25b6 2020-02-06 tracey goto done;
4307 626b25b6 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
4308 626b25b6 2020-02-06 tracey KATTR_ID, "tree_line_blank", KATTR_CLASS, class,
4309 626b25b6 2020-02-06 tracey KATTR__MAX);
4310 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4311 84bf4df2 2020-02-03 stsp goto done;
4312 626b25b6 2020-02-06 tracey kerr = khtml_entity(gw_trans->gw_html_req,
4313 626b25b6 2020-02-06 tracey KENTITY_nbsp);
4314 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4315 626b25b6 2020-02-06 tracey goto done;
4316 626b25b6 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
4317 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4318 626b25b6 2020-02-06 tracey goto done;
4319 ec46ccd7 2020-01-15 tracey } else {
4320 c6eb96ac 2020-04-14 tracey href_blob = khttp_urlpart(NULL, NULL, "gotweb", "path",
4321 c6eb96ac 2020-04-14 tracey gw_trans->repo_name, "action", "blob", "commit",
4322 c6eb96ac 2020-04-14 tracey gw_trans->commit_id, "file",
4323 c6eb96ac 2020-04-14 tracey got_tree_entry_get_name(te), "folder",
4324 c6eb96ac 2020-04-14 tracey gw_trans->repo_folder ? gw_trans->repo_folder : "",
4326 19ff7638 2020-04-14 tracey if (href_blob == NULL) {
4327 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
4328 19ff7638 2020-04-14 tracey goto done;
4330 c6eb96ac 2020-04-14 tracey href_blame = khttp_urlpart(NULL, NULL, "gotweb", "path",
4331 c6eb96ac 2020-04-14 tracey gw_trans->repo_name, "action", "blame", "commit",
4332 c6eb96ac 2020-04-14 tracey gw_trans->commit_id, "file",
4333 c6eb96ac 2020-04-14 tracey got_tree_entry_get_name(te), "folder",
4334 c6eb96ac 2020-04-14 tracey gw_trans->repo_folder ? gw_trans->repo_folder : "",
4336 19ff7638 2020-04-14 tracey if (href_blame == NULL) {
4337 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
4338 19ff7638 2020-04-14 tracey goto done;
4340 626b25b6 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
4341 626b25b6 2020-02-06 tracey KATTR_ID, "tree_wrapper", KATTR__MAX);
4342 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4343 626b25b6 2020-02-06 tracey goto done;
4344 626b25b6 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
4345 626b25b6 2020-02-06 tracey KATTR_ID, "tree_line", KATTR_CLASS, class,
4346 626b25b6 2020-02-06 tracey KATTR__MAX);
4347 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4348 626b25b6 2020-02-06 tracey goto done;
4349 626b25b6 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
4350 626b25b6 2020-02-06 tracey KATTR_HREF, href_blob, KATTR__MAX);
4351 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4352 626b25b6 2020-02-06 tracey goto done;
4353 32b9f7ed 2020-04-14 tracey kerr = khtml_printf(gw_trans->gw_html_req, "%s%s",
4354 32b9f7ed 2020-04-14 tracey got_tree_entry_get_name(te), modestr);
4355 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4356 626b25b6 2020-02-06 tracey goto done;
4357 626b25b6 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
4358 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4359 626b25b6 2020-02-06 tracey goto done;
4360 626b25b6 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
4361 626b25b6 2020-02-06 tracey KATTR_ID, "tree_line_navs", KATTR_CLASS, class,
4362 626b25b6 2020-02-06 tracey KATTR__MAX);
4363 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4364 626b25b6 2020-02-06 tracey goto done;
4366 626b25b6 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
4367 626b25b6 2020-02-06 tracey KATTR_HREF, href_blob, KATTR__MAX);
4368 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4369 626b25b6 2020-02-06 tracey goto done;
4370 626b25b6 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req, "blob");
4371 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4372 626b25b6 2020-02-06 tracey goto done;
4373 626b25b6 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
4374 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4375 626b25b6 2020-02-06 tracey goto done;
4377 626b25b6 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req, " | ");
4378 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4379 626b25b6 2020-02-06 tracey goto done;
4381 626b25b6 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
4382 626b25b6 2020-02-06 tracey KATTR_HREF, href_blame, KATTR__MAX);
4383 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4384 626b25b6 2020-02-06 tracey goto done;
4385 626b25b6 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req, "blame");
4386 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4387 626b25b6 2020-02-06 tracey goto done;
4389 626b25b6 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 3);
4390 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4391 626b25b6 2020-02-06 tracey goto done;
4393 bcbc97d8 2020-01-15 tracey free(id_str);
4394 84bf4df2 2020-02-03 stsp id_str = NULL;
4395 626b25b6 2020-02-06 tracey free(href_blob);
4396 626b25b6 2020-02-06 tracey href_blob = NULL;
4397 84bf4df2 2020-02-03 stsp free(build_folder);
4398 84bf4df2 2020-02-03 stsp build_folder = NULL;
4401 bcbc97d8 2020-01-15 tracey if (tree)
4402 bcbc97d8 2020-01-15 tracey got_object_tree_close(tree);
4403 84bf4df2 2020-02-03 stsp free(id_str);
4404 626b25b6 2020-02-06 tracey free(href_blob);
4405 626b25b6 2020-02-06 tracey free(href_blame);
4406 2e676fc5 2020-01-15 tracey free(in_repo_path);
4407 bcbc97d8 2020-01-15 tracey free(tree_id);
4408 84bf4df2 2020-02-03 stsp free(build_folder);
4409 626b25b6 2020-02-06 tracey if (error == NULL && kerr != KCGI_OK)
4410 626b25b6 2020-02-06 tracey error = gw_kcgi_error(kerr);
4411 84bf4df2 2020-02-03 stsp return error;
4414 51d4a92d 2020-02-03 tracey static const struct got_error *
4415 9eed6f10 2020-02-08 tracey gw_output_repo_heads(struct gw_trans *gw_trans)
4417 87f9ebf5 2020-01-15 tracey const struct got_error *error = NULL;
4418 87f9ebf5 2020-01-15 tracey struct got_reflist_head refs;
4419 87f9ebf5 2020-01-15 tracey struct got_reflist_entry *re;
4420 9eed6f10 2020-02-08 tracey char *age = NULL, *href_summary = NULL, *href_briefs = NULL;
4421 9eed6f10 2020-02-08 tracey char *href_commits = NULL;
4422 9eed6f10 2020-02-08 tracey enum kcgi_err kerr = KCGI_OK;
4424 d9dff0e5 2020-12-26 stsp TAILQ_INIT(&refs);
4426 deac617c 2020-02-14 tracey error = got_ref_list(&refs, gw_trans->repo, "refs/heads",
4427 deac617c 2020-02-14 tracey got_ref_cmp_by_name, NULL);
4428 87f9ebf5 2020-01-15 tracey if (error)
4429 87f9ebf5 2020-01-15 tracey goto done;
4431 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
4432 9eed6f10 2020-02-08 tracey KATTR_ID, "summary_heads_title_wrapper", KATTR__MAX);
4433 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4434 9eed6f10 2020-02-08 tracey goto done;
4435 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
4436 9eed6f10 2020-02-08 tracey KATTR_ID, "summary_heads_title", KATTR__MAX);
4437 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4438 9eed6f10 2020-02-08 tracey goto done;
4439 9eed6f10 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Heads");
4440 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4441 9eed6f10 2020-02-08 tracey goto done;
4442 9eed6f10 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
4443 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4444 9eed6f10 2020-02-08 tracey goto done;
4445 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
4446 9eed6f10 2020-02-08 tracey KATTR_ID, "summary_heads_content", KATTR__MAX);
4447 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4448 9eed6f10 2020-02-08 tracey goto done;
4450 d9dff0e5 2020-12-26 stsp TAILQ_FOREACH(re, &refs, entry) {
4451 7eb2c8df 2020-02-14 stsp const char *refname;
4453 eb4f3ad3 2020-02-14 stsp if (got_ref_is_symbolic(re->ref))
4456 7eb2c8df 2020-02-14 stsp refname = got_ref_get_name(re->ref);
4457 7eb2c8df 2020-02-14 stsp if (strncmp(refname, "refs/heads/", 11) != 0)
4458 87f9ebf5 2020-01-15 tracey continue;
4460 017d6da3 2020-01-29 tracey error = gw_get_repo_age(&age, gw_trans, gw_trans->gw_dir->path,
4461 017d6da3 2020-01-29 tracey refname, TM_DIFF);
4462 d126c1b7 2020-01-29 stsp if (error)
4463 d126c1b7 2020-01-29 stsp goto done;
4465 9eed6f10 2020-02-08 tracey if (strncmp(refname, "refs/heads/", 11) == 0)
4466 9eed6f10 2020-02-08 tracey refname += 11;
4468 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
4469 9eed6f10 2020-02-08 tracey KATTR_ID, "heads_wrapper", KATTR__MAX);
4470 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4471 9eed6f10 2020-02-08 tracey goto done;
4472 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
4473 9eed6f10 2020-02-08 tracey KATTR_ID, "heads_age", KATTR__MAX);
4474 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4475 9eed6f10 2020-02-08 tracey goto done;
4476 9eed6f10 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req, age ? age : "");
4477 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4478 9eed6f10 2020-02-08 tracey goto done;
4479 9eed6f10 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
4480 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4481 9eed6f10 2020-02-08 tracey goto done;
4482 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
4483 9eed6f10 2020-02-08 tracey KATTR_ID, "heads_space", KATTR__MAX);
4484 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4485 9eed6f10 2020-02-08 tracey goto done;
4486 9eed6f10 2020-02-08 tracey kerr = khtml_entity(gw_trans->gw_html_req, KENTITY_nbsp);
4487 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4488 9eed6f10 2020-02-08 tracey goto done;
4489 9eed6f10 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
4490 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4491 9eed6f10 2020-02-08 tracey goto done;
4492 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
4493 9eed6f10 2020-02-08 tracey KATTR_ID, "head", KATTR__MAX);
4494 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4495 9eed6f10 2020-02-08 tracey goto done;
4497 e6789209 2020-04-14 tracey href_summary = khttp_urlpart(NULL, NULL, "gotweb", "path",
4498 e6789209 2020-04-14 tracey gw_trans->repo_name, "action", "summary", "headref",
4499 19ff7638 2020-04-14 tracey refname, NULL);
4500 19ff7638 2020-04-14 tracey if (href_summary == NULL) {
4501 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
4502 19ff7638 2020-04-14 tracey goto done;
4504 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A, KATTR_HREF,
4505 9eed6f10 2020-02-08 tracey href_summary, KATTR__MAX);
4506 9eed6f10 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req, refname);
4507 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4508 9eed6f10 2020-02-08 tracey goto done;
4509 9eed6f10 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 3);
4510 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4511 9eed6f10 2020-02-08 tracey goto done;
4513 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
4514 9eed6f10 2020-02-08 tracey "navs_wrapper", KATTR__MAX);
4515 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4516 9eed6f10 2020-02-08 tracey goto done;
4517 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
4518 9eed6f10 2020-02-08 tracey "navs", KATTR__MAX);
4519 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4520 9eed6f10 2020-02-08 tracey goto done;
4522 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A, KATTR_HREF,
4523 9eed6f10 2020-02-08 tracey href_summary, KATTR__MAX);
4524 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4525 9eed6f10 2020-02-08 tracey goto done;
4526 9eed6f10 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req, "summary");
4527 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4528 9eed6f10 2020-02-08 tracey goto done;
4529 9eed6f10 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
4530 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4531 9eed6f10 2020-02-08 tracey goto done;
4533 9eed6f10 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req, " | ");
4534 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4535 87f9ebf5 2020-01-15 tracey goto done;
4537 e6789209 2020-04-14 tracey href_briefs = khttp_urlpart(NULL, NULL, "gotweb", "path",
4538 e6789209 2020-04-14 tracey gw_trans->repo_name, "action", "briefs", "headref",
4539 e6789209 2020-04-14 tracey refname, NULL);
4540 19ff7638 2020-04-14 tracey if (href_briefs == NULL) {
4541 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
4542 19ff7638 2020-04-14 tracey goto done;
4544 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A, KATTR_HREF,
4545 9eed6f10 2020-02-08 tracey href_briefs, KATTR__MAX);
4546 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4547 9eed6f10 2020-02-08 tracey goto done;
4548 9eed6f10 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req, "commit briefs");
4549 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4550 9eed6f10 2020-02-08 tracey goto done;
4551 9eed6f10 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
4552 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4553 9eed6f10 2020-02-08 tracey goto done;
4555 9eed6f10 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req, " | ");
4556 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4557 9eed6f10 2020-02-08 tracey goto done;
4559 e6789209 2020-04-14 tracey href_commits = khttp_urlpart(NULL, NULL, "gotweb", "path",
4560 e6789209 2020-04-14 tracey gw_trans->repo_name, "action", "commits", "headref",
4561 19ff7638 2020-04-14 tracey refname, NULL);
4562 19ff7638 2020-04-14 tracey if (href_commits == NULL) {
4563 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
4564 19ff7638 2020-04-14 tracey goto done;
4566 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A, KATTR_HREF,
4567 9eed6f10 2020-02-08 tracey href_commits, KATTR__MAX);
4568 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4569 9eed6f10 2020-02-08 tracey goto done;
4570 9eed6f10 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req, "commits");
4571 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4572 9eed6f10 2020-02-08 tracey goto done;
4573 9eed6f10 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 3);
4574 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4575 9eed6f10 2020-02-08 tracey goto done;
4577 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
4578 9eed6f10 2020-02-08 tracey "dotted_line", KATTR__MAX);
4579 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4580 9eed6f10 2020-02-08 tracey goto done;
4581 9eed6f10 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
4582 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4583 9eed6f10 2020-02-08 tracey goto done;
4584 9eed6f10 2020-02-08 tracey free(href_summary);
4585 9eed6f10 2020-02-08 tracey href_summary = NULL;
4586 9eed6f10 2020-02-08 tracey free(href_briefs);
4587 9eed6f10 2020-02-08 tracey href_briefs = NULL;
4588 9eed6f10 2020-02-08 tracey free(href_commits);
4589 9eed6f10 2020-02-08 tracey href_commits = NULL;
4592 87f9ebf5 2020-01-15 tracey got_ref_list_free(&refs);
4593 9eed6f10 2020-02-08 tracey free(href_summary);
4594 9eed6f10 2020-02-08 tracey free(href_briefs);
4595 9eed6f10 2020-02-08 tracey free(href_commits);
4596 51d4a92d 2020-02-03 tracey return error;
4599 4ae179a2 2020-02-08 tracey static const struct got_error *
4600 4ae179a2 2020-02-08 tracey gw_output_site_link(struct gw_trans *gw_trans)
4602 4ae179a2 2020-02-08 tracey const struct got_error *error = NULL;
4603 4ae179a2 2020-02-08 tracey char *href_summary = NULL;
4604 4ae179a2 2020-02-08 tracey enum kcgi_err kerr = KCGI_OK;
4606 4ae179a2 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
4607 4ae179a2 2020-02-08 tracey "site_link", KATTR__MAX);
4608 4ae179a2 2020-02-08 tracey if (kerr != KCGI_OK)
4609 4ae179a2 2020-02-08 tracey goto done;
4610 4ae179a2 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A, KATTR_HREF, GOTWEB,
4611 4ae179a2 2020-02-08 tracey KATTR__MAX);
4612 4ae179a2 2020-02-08 tracey if (kerr != KCGI_OK)
4613 4ae179a2 2020-02-08 tracey goto done;
4614 4ae179a2 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req,
4615 62d463ca 2020-10-20 naddy gw_trans->gw_conf->got_site_link);
4616 4ae179a2 2020-02-08 tracey if (kerr != KCGI_OK)
4617 4ae179a2 2020-02-08 tracey goto done;
4618 4ae179a2 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
4619 4ae179a2 2020-02-08 tracey if (kerr != KCGI_OK)
4620 4ae179a2 2020-02-08 tracey goto done;
4622 4ae179a2 2020-02-08 tracey if (gw_trans->repo_name != NULL) {
4623 4ae179a2 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req, " / ");
4624 4ae179a2 2020-02-08 tracey if (kerr != KCGI_OK)
4625 4ae179a2 2020-02-08 tracey goto done;
4627 6918c609 2020-04-14 tracey href_summary = khttp_urlpart(NULL, NULL, "gotweb", "path",
4628 19ff7638 2020-04-14 tracey gw_trans->repo_name, "action", "summary", NULL);
4629 19ff7638 2020-04-14 tracey if (href_summary == NULL) {
4630 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
4631 19ff7638 2020-04-14 tracey goto done;
4633 4ae179a2 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A, KATTR_HREF,
4634 4ae179a2 2020-02-08 tracey href_summary, KATTR__MAX);
4635 4ae179a2 2020-02-08 tracey if (kerr != KCGI_OK)
4636 4ae179a2 2020-02-08 tracey goto done;
4637 4ae179a2 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req, gw_trans->repo_name);
4638 4ae179a2 2020-02-08 tracey if (kerr != KCGI_OK)
4639 4ae179a2 2020-02-08 tracey goto done;
4640 4ae179a2 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
4641 4ae179a2 2020-02-08 tracey if (kerr != KCGI_OK)
4642 4ae179a2 2020-02-08 tracey goto done;
4643 32b9f7ed 2020-04-14 tracey kerr = khtml_printf(gw_trans->gw_html_req, " / %s",
4644 5d1296de 2020-02-13 stsp gw_get_action_name(gw_trans));
4645 4ae179a2 2020-02-08 tracey if (kerr != KCGI_OK)
4646 4ae179a2 2020-02-08 tracey goto done;
4649 4ae179a2 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
4650 4ae179a2 2020-02-08 tracey if (kerr != KCGI_OK)
4651 4ae179a2 2020-02-08 tracey goto done;
4653 4ae179a2 2020-02-08 tracey free(href_summary);
4654 6918c609 2020-04-14 tracey if (error == NULL && kerr != KCGI_OK)
4655 6918c609 2020-04-14 tracey error = gw_kcgi_error(kerr);
4656 4ae179a2 2020-02-08 tracey return error;
4659 83eb9a68 2020-02-03 stsp static const struct got_error *
4660 f7cc9480 2020-02-05 tracey gw_colordiff_line(struct gw_trans *gw_trans, char *buf)
4662 ec46ccd7 2020-01-15 tracey const struct got_error *error = NULL;
4663 f7cc9480 2020-02-05 tracey char *color = NULL;
4664 f7cc9480 2020-02-05 tracey enum kcgi_err kerr = KCGI_OK;
4666 ec46ccd7 2020-01-15 tracey if (strncmp(buf, "-", 1) == 0)
4667 ec46ccd7 2020-01-15 tracey color = "diff_minus";
4668 83eb9a68 2020-02-03 stsp else if (strncmp(buf, "+", 1) == 0)
4669 ec46ccd7 2020-01-15 tracey color = "diff_plus";
4670 83eb9a68 2020-02-03 stsp else if (strncmp(buf, "@@", 2) == 0)
4671 ec46ccd7 2020-01-15 tracey color = "diff_chunk_header";
4672 83eb9a68 2020-02-03 stsp else if (strncmp(buf, "@@", 2) == 0)
4673 ec46ccd7 2020-01-15 tracey color = "diff_chunk_header";
4674 83eb9a68 2020-02-03 stsp else if (strncmp(buf, "commit +", 8) == 0)
4675 ec46ccd7 2020-01-15 tracey color = "diff_meta";
4676 83eb9a68 2020-02-03 stsp else if (strncmp(buf, "commit -", 8) == 0)
4677 ec46ccd7 2020-01-15 tracey color = "diff_meta";
4678 83eb9a68 2020-02-03 stsp else if (strncmp(buf, "blob +", 6) == 0)
4679 ec46ccd7 2020-01-15 tracey color = "diff_meta";
4680 83eb9a68 2020-02-03 stsp else if (strncmp(buf, "blob -", 6) == 0)
4681 ec46ccd7 2020-01-15 tracey color = "diff_meta";
4682 83eb9a68 2020-02-03 stsp else if (strncmp(buf, "file +", 6) == 0)
4683 ec46ccd7 2020-01-15 tracey color = "diff_meta";
4684 83eb9a68 2020-02-03 stsp else if (strncmp(buf, "file -", 6) == 0)
4685 ec46ccd7 2020-01-15 tracey color = "diff_meta";
4686 83eb9a68 2020-02-03 stsp else if (strncmp(buf, "from:", 5) == 0)
4687 ec46ccd7 2020-01-15 tracey color = "diff_author";
4688 83eb9a68 2020-02-03 stsp else if (strncmp(buf, "via:", 4) == 0)
4689 ec46ccd7 2020-01-15 tracey color = "diff_author";
4690 83eb9a68 2020-02-03 stsp else if (strncmp(buf, "date:", 5) == 0)
4691 ec46ccd7 2020-01-15 tracey color = "diff_date";
4692 f7cc9480 2020-02-05 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
4693 f7cc9480 2020-02-05 tracey "diff_line", KATTR_CLASS, color ? color : "", KATTR__MAX);
4694 f7cc9480 2020-02-05 tracey if (error == NULL && kerr != KCGI_OK)
4695 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
4696 070fee27 2020-02-03 stsp return error;
4700 c08369d7 2020-01-15 tracey main(int argc, char *argv[])
4702 6648f956 2021-04-26 tracey const struct got_error *error = NULL, *error2 = NULL;
4703 54415d85 2020-01-15 tracey struct gw_trans *gw_trans;
4704 2c251c14 2020-01-15 tracey struct gw_dir *dir = NULL, *tdir;
4705 2c251c14 2020-01-15 tracey const char *page = "index";
4706 795c10a4 2020-02-20 tracey enum kcgi_err kerr = KCGI_OK;
4708 54415d85 2020-01-15 tracey if ((gw_trans = malloc(sizeof(struct gw_trans))) == NULL)
4709 2c251c14 2020-01-15 tracey errx(1, "malloc");
4711 2c251c14 2020-01-15 tracey if ((gw_trans->gw_req = malloc(sizeof(struct kreq))) == NULL)
4712 2c251c14 2020-01-15 tracey errx(1, "malloc");
4714 2c251c14 2020-01-15 tracey if ((gw_trans->gw_html_req = malloc(sizeof(struct khtmlreq))) == NULL)
4715 2c251c14 2020-01-15 tracey errx(1, "malloc");
4717 2c251c14 2020-01-15 tracey if ((gw_trans->gw_tmpl = malloc(sizeof(struct ktemplate))) == NULL)
4718 2c251c14 2020-01-15 tracey errx(1, "malloc");
4720 c25c2314 2020-01-28 stsp kerr = khttp_parse(gw_trans->gw_req, gw_keys, KEY__ZMAX, &page, 1, 0);
4721 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK) {
4722 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
4723 c119608e 2020-01-28 stsp goto done;
4726 2c251c14 2020-01-15 tracey TAILQ_INIT(&gw_trans->gw_dirs);
4727 f2f46662 2020-01-23 tracey TAILQ_INIT(&gw_trans->gw_headers);
4729 f1200fe3 2020-02-13 tracey gw_trans->action = -1;
4730 2c251c14 2020-01-15 tracey gw_trans->page = 0;
4731 2c251c14 2020-01-15 tracey gw_trans->repos_total = 0;
4732 2c251c14 2020-01-15 tracey gw_trans->repo_path = NULL;
4733 56997cd3 2020-02-14 tracey gw_trans->commit_id = NULL;
4734 55e46400 2020-02-18 tracey gw_trans->next_id = NULL;
4735 55e46400 2020-02-18 tracey gw_trans->next_prev_id = NULL;
4736 55e46400 2020-02-18 tracey gw_trans->prev_id = NULL;
4737 55e46400 2020-02-18 tracey gw_trans->prev_prev_id = NULL;
4738 742ba378 2020-02-14 stsp gw_trans->headref = GOT_REF_HEAD;
4739 2c251c14 2020-01-15 tracey gw_trans->mime = KMIME_TEXT_HTML;
4740 54415d85 2020-01-15 tracey gw_trans->gw_tmpl->key = gw_templs;
4741 2c251c14 2020-01-15 tracey gw_trans->gw_tmpl->keysz = TEMPL__MAX;
4742 2c251c14 2020-01-15 tracey gw_trans->gw_tmpl->arg = gw_trans;
4743 2c251c14 2020-01-15 tracey gw_trans->gw_tmpl->cb = gw_template;
4745 c34ec417 2020-06-22 tracey error = parse_gotweb_config(&gw_trans->gw_conf, GOTWEB_CONF);
4746 c119608e 2020-01-28 stsp if (error)
4747 2c251c14 2020-01-15 tracey goto done;
4749 2c251c14 2020-01-15 tracey error = gw_parse_querystring(gw_trans);
4750 2c251c14 2020-01-15 tracey if (error)
4751 c119608e 2020-01-28 stsp goto done;
4753 017d6da3 2020-01-29 tracey if (gw_trans->action == GW_BLOB)
4754 017d6da3 2020-01-29 tracey error = gw_blob(gw_trans);
4756 017d6da3 2020-01-29 tracey error = gw_display_index(gw_trans);
4758 1d0f4054 2021-06-17 stsp if (gw_trans->repo) {
4759 1d0f4054 2021-06-17 stsp const struct got_error *close_err;
4760 1d0f4054 2021-06-17 stsp close_err = got_repo_close(gw_trans->repo);
4761 1d0f4054 2021-06-17 stsp if (error == NULL)
4762 1d0f4054 2021-06-17 stsp error = close_err;
4764 6648f956 2021-04-26 tracey if (error) {
4765 6648f956 2021-04-26 tracey gw_trans->error = error;
4766 6648f956 2021-04-26 tracey gw_trans->action = GW_ERR;
4767 6648f956 2021-04-26 tracey error2 = gw_display_open(gw_trans, KHTTP_200, gw_trans->mime);
4768 6648f956 2021-04-26 tracey if (error2)
4769 6648f956 2021-04-26 tracey goto cleanup; /* we can't display an error page */
4770 6648f956 2021-04-26 tracey kerr = khtml_open(gw_trans->gw_html_req, gw_trans->gw_req, 0);
4771 6648f956 2021-04-26 tracey if (kerr != KCGI_OK)
4772 6648f956 2021-04-26 tracey goto cleanup; /* we can't display an error page */
4773 6648f956 2021-04-26 tracey kerr = khttp_template(gw_trans->gw_req, gw_trans->gw_tmpl,
4774 6648f956 2021-04-26 tracey gw_query_funcs[gw_trans->action].template);
4775 6648f956 2021-04-26 tracey if (kerr != KCGI_OK) {
4776 6648f956 2021-04-26 tracey khtml_close(gw_trans->gw_html_req);
4777 6648f956 2021-04-26 tracey goto cleanup; /* we can't display an error page */
4781 6648f956 2021-04-26 tracey cleanup:
4782 a5a8a332 2020-11-09 tracey free(gw_trans->gw_conf->got_repos_path);
4783 a5a8a332 2020-11-09 tracey free(gw_trans->gw_conf->got_www_path);
4784 a5a8a332 2020-11-09 tracey free(gw_trans->gw_conf->got_site_name);
4785 a5a8a332 2020-11-09 tracey free(gw_trans->gw_conf->got_site_owner);
4786 a5a8a332 2020-11-09 tracey free(gw_trans->gw_conf->got_site_link);
4787 a5a8a332 2020-11-09 tracey free(gw_trans->gw_conf->got_logo);
4788 a5a8a332 2020-11-09 tracey free(gw_trans->gw_conf->got_logo_url);
4789 a5a8a332 2020-11-09 tracey free(gw_trans->gw_conf);
4790 a5a8a332 2020-11-09 tracey free(gw_trans->commit_id);
4791 a5a8a332 2020-11-09 tracey free(gw_trans->next_id);
4792 a5a8a332 2020-11-09 tracey free(gw_trans->next_prev_id);
4793 a5a8a332 2020-11-09 tracey free(gw_trans->prev_id);
4794 a5a8a332 2020-11-09 tracey free(gw_trans->prev_prev_id);
4795 a5a8a332 2020-11-09 tracey free(gw_trans->repo_path);
4796 a5a8a332 2020-11-09 tracey TAILQ_FOREACH_SAFE(dir, &gw_trans->gw_dirs, entry, tdir) {
4797 a5a8a332 2020-11-09 tracey free(dir->name);
4798 a5a8a332 2020-11-09 tracey free(dir->description);
4799 a5a8a332 2020-11-09 tracey free(dir->age);
4800 a5a8a332 2020-11-09 tracey free(dir->url);
4801 a5a8a332 2020-11-09 tracey free(dir->path);
4802 a5a8a332 2020-11-09 tracey free(dir);
4805 2c251c14 2020-01-15 tracey khttp_free(gw_trans->gw_req);