2 a596b957 2022-07-14 tracey * Copyright (c) 2016, 2019, 2020-2022 Tracey Emery <tracey@traceyemery.net>
3 a596b957 2022-07-14 tracey * Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org>
4 a596b957 2022-07-14 tracey * Copyright (c) 2013 David Gwynne <dlg@openbsd.org>
5 a596b957 2022-07-14 tracey * Copyright (c) 2013 Florian Obser <florian@openbsd.org>
7 a596b957 2022-07-14 tracey * Permission to use, copy, modify, and distribute this software for any
8 a596b957 2022-07-14 tracey * purpose with or without fee is hereby granted, provided that the above
9 a596b957 2022-07-14 tracey * copyright notice and this permission notice appear in all copies.
11 a596b957 2022-07-14 tracey * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 a596b957 2022-07-14 tracey * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 a596b957 2022-07-14 tracey * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 a596b957 2022-07-14 tracey * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 a596b957 2022-07-14 tracey * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 a596b957 2022-07-14 tracey * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 a596b957 2022-07-14 tracey * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 a596b957 2022-07-14 tracey #include <net/if.h>
21 a596b957 2022-07-14 tracey #include <netinet/in.h>
22 b4c20a19 2022-07-15 naddy #include <sys/queue.h>
23 a596b957 2022-07-14 tracey #include <sys/stat.h>
24 a596b957 2022-07-14 tracey #include <sys/types.h>
26 a596b957 2022-07-14 tracey #include <dirent.h>
27 a596b957 2022-07-14 tracey #include <errno.h>
28 a596b957 2022-07-14 tracey #include <event.h>
29 a596b957 2022-07-14 tracey #include <imsg.h>
30 a596b957 2022-07-14 tracey #include <sha1.h>
31 a596b957 2022-07-14 tracey #include <stdio.h>
32 a596b957 2022-07-14 tracey #include <stdlib.h>
33 a596b957 2022-07-14 tracey #include <string.h>
34 a596b957 2022-07-14 tracey #include <unistd.h>
36 a596b957 2022-07-14 tracey #include "got_error.h"
37 a596b957 2022-07-14 tracey #include "got_object.h"
38 a596b957 2022-07-14 tracey #include "got_reference.h"
39 a596b957 2022-07-14 tracey #include "got_repository.h"
40 a596b957 2022-07-14 tracey #include "got_path.h"
41 a596b957 2022-07-14 tracey #include "got_cancel.h"
42 a596b957 2022-07-14 tracey #include "got_worktree.h"
43 a596b957 2022-07-14 tracey #include "got_diff.h"
44 a596b957 2022-07-14 tracey #include "got_commit_graph.h"
45 a596b957 2022-07-14 tracey #include "got_blame.h"
46 a596b957 2022-07-14 tracey #include "got_privsep.h"
48 a596b957 2022-07-14 tracey #include "proc.h"
49 a596b957 2022-07-14 tracey #include "gotwebd.h"
51 a596b957 2022-07-14 tracey enum gotweb_ref_tm {
56 a596b957 2022-07-14 tracey static const struct querystring_keys querystring_keys[] = {
57 a596b957 2022-07-14 tracey { "action", ACTION },
58 a596b957 2022-07-14 tracey { "commit", COMMIT },
59 a596b957 2022-07-14 tracey { "file", RFILE },
60 a596b957 2022-07-14 tracey { "folder", FOLDER },
61 a596b957 2022-07-14 tracey { "headref", HEADREF },
62 a596b957 2022-07-14 tracey { "index_page", INDEX_PAGE },
63 a596b957 2022-07-14 tracey { "path", PATH },
64 a596b957 2022-07-14 tracey { "page", PAGE },
67 a596b957 2022-07-14 tracey static const struct action_keys action_keys[] = {
68 a596b957 2022-07-14 tracey { "blame", BLAME },
69 a596b957 2022-07-14 tracey { "blob", BLOB },
70 a596b957 2022-07-14 tracey { "briefs", BRIEFS },
71 a596b957 2022-07-14 tracey { "commits", COMMITS },
72 a596b957 2022-07-14 tracey { "diff", DIFF },
73 a596b957 2022-07-14 tracey { "error", ERR },
74 a596b957 2022-07-14 tracey { "index", INDEX },
75 a596b957 2022-07-14 tracey { "summary", SUMMARY },
76 a596b957 2022-07-14 tracey { "tag", TAG },
77 a596b957 2022-07-14 tracey { "tags", TAGS },
78 a596b957 2022-07-14 tracey { "tree", TREE },
81 a596b957 2022-07-14 tracey static const struct got_error *gotweb_init_querystring(struct querystring **);
82 a596b957 2022-07-14 tracey static const struct got_error *gotweb_parse_querystring(struct querystring **,
84 a596b957 2022-07-14 tracey static const struct got_error *gotweb_assign_querystring(struct querystring **,
85 a596b957 2022-07-14 tracey char *, char *);
86 a596b957 2022-07-14 tracey static const struct got_error *gotweb_render_header(struct request *);
87 a596b957 2022-07-14 tracey static const struct got_error *gotweb_render_footer(struct request *);
88 a596b957 2022-07-14 tracey static const struct got_error *gotweb_render_index(struct request *);
89 a596b957 2022-07-14 tracey static const struct got_error *gotweb_init_repo_dir(struct repo_dir **,
90 a596b957 2022-07-14 tracey const char *);
91 a596b957 2022-07-14 tracey static const struct got_error *gotweb_load_got_path(struct request *c,
92 a596b957 2022-07-14 tracey struct repo_dir *);
93 a596b957 2022-07-14 tracey static const struct got_error *gotweb_get_repo_description(char **,
94 a596b957 2022-07-14 tracey struct server *, char *);
95 a596b957 2022-07-14 tracey static const struct got_error *gotweb_get_clone_url(char **, struct server *,
97 a596b957 2022-07-14 tracey static const struct got_error *gotweb_render_navs(struct request *);
98 a596b957 2022-07-14 tracey static const struct got_error *gotweb_render_blame(struct request *);
99 a596b957 2022-07-14 tracey static const struct got_error *gotweb_render_briefs(struct request *);
100 a596b957 2022-07-14 tracey static const struct got_error *gotweb_render_commits(struct request *);
101 a596b957 2022-07-14 tracey static const struct got_error *gotweb_render_diff(struct request *);
102 a596b957 2022-07-14 tracey static const struct got_error *gotweb_render_summary(struct request *);
103 a596b957 2022-07-14 tracey static const struct got_error *gotweb_render_tag(struct request *);
104 a596b957 2022-07-14 tracey static const struct got_error *gotweb_render_tags(struct request *);
105 a596b957 2022-07-14 tracey static const struct got_error *gotweb_render_tree(struct request *);
106 a596b957 2022-07-14 tracey static const struct got_error *gotweb_render_branches(struct request *);
108 a596b957 2022-07-14 tracey static void gotweb_free_querystring(struct querystring *);
109 a596b957 2022-07-14 tracey static void gotweb_free_repo_dir(struct repo_dir *);
111 95a4a5a1 2022-08-30 op struct server *gotweb_get_server(uint8_t *, uint8_t *);
114 a596b957 2022-07-14 tracey gotweb_process_request(struct request *c)
116 a596b957 2022-07-14 tracey const struct got_error *error = NULL, *error2 = NULL;
117 a596b957 2022-07-14 tracey struct server *srv = NULL;
118 a596b957 2022-07-14 tracey struct querystring *qs = NULL;
119 a596b957 2022-07-14 tracey struct repo_dir *repo_dir = NULL;
120 a596b957 2022-07-14 tracey uint8_t err[] = "gotwebd experienced an error: ";
121 01498c42 2022-08-19 op int r, html = 0;
123 a596b957 2022-07-14 tracey /* init the transport */
124 a596b957 2022-07-14 tracey error = gotweb_init_transport(&c->t);
125 a596b957 2022-07-14 tracey if (error) {
126 a596b957 2022-07-14 tracey log_warnx("%s: %s", __func__, error->msg);
129 a596b957 2022-07-14 tracey /* don't process any further if client disconnected */
130 a596b957 2022-07-14 tracey if (c->sock->client_status == CLIENT_DISCONNECT)
132 a596b957 2022-07-14 tracey /* get the gotwebd server */
133 95a4a5a1 2022-08-30 op srv = gotweb_get_server(c->server_name, c->http_host);
134 a596b957 2022-07-14 tracey if (srv == NULL) {
135 a596b957 2022-07-14 tracey log_warnx("%s: error server is NULL", __func__);
136 a596b957 2022-07-14 tracey goto err;
138 a596b957 2022-07-14 tracey c->srv = srv;
139 a596b957 2022-07-14 tracey /* parse our querystring */
140 a596b957 2022-07-14 tracey error = gotweb_init_querystring(&qs);
141 a596b957 2022-07-14 tracey if (error) {
142 a596b957 2022-07-14 tracey log_warnx("%s: %s", __func__, error->msg);
143 a596b957 2022-07-14 tracey goto err;
145 a596b957 2022-07-14 tracey c->t->qs = qs;
146 a596b957 2022-07-14 tracey error = gotweb_parse_querystring(&qs, c->querystring);
147 a596b957 2022-07-14 tracey if (error) {
148 a596b957 2022-07-14 tracey log_warnx("%s: %s", __func__, error->msg);
149 a596b957 2022-07-14 tracey goto err;
153 a596b957 2022-07-14 tracey * certain actions require a commit id in the querystring. this stops
154 a596b957 2022-07-14 tracey * bad actors from exploiting this by manually manipulating the
155 a596b957 2022-07-14 tracey * querystring.
158 a596b957 2022-07-14 tracey if (qs->commit == NULL && (qs->action == BLAME || qs->action == BLOB ||
159 a596b957 2022-07-14 tracey qs->action == DIFF)) {
160 a596b957 2022-07-14 tracey error2 = got_error(GOT_ERR_QUERYSTRING);
161 a596b957 2022-07-14 tracey goto render;
164 a596b957 2022-07-14 tracey if (qs->action != INDEX) {
165 a596b957 2022-07-14 tracey error = gotweb_init_repo_dir(&repo_dir, qs->path);
166 a596b957 2022-07-14 tracey if (error)
167 a596b957 2022-07-14 tracey goto done;
168 a596b957 2022-07-14 tracey error = gotweb_load_got_path(c, repo_dir);
169 a596b957 2022-07-14 tracey c->t->repo_dir = repo_dir;
170 a596b957 2022-07-14 tracey if (error && error->code != GOT_ERR_LONELY_PACKIDX)
171 a596b957 2022-07-14 tracey goto err;
174 a596b957 2022-07-14 tracey /* render top of page */
175 a596b957 2022-07-14 tracey if (qs != NULL && qs->action == BLOB) {
176 a596b957 2022-07-14 tracey error = got_get_repo_commits(c, 1);
177 a596b957 2022-07-14 tracey if (error)
178 a596b957 2022-07-14 tracey goto done;
179 a596b957 2022-07-14 tracey error = got_output_file_blob(c);
180 a596b957 2022-07-14 tracey if (error) {
181 a596b957 2022-07-14 tracey log_warnx("%s: %s", __func__, error->msg);
182 a596b957 2022-07-14 tracey goto err;
184 a596b957 2022-07-14 tracey goto done;
187 a596b957 2022-07-14 tracey error = gotweb_render_content_type(c, "text/html");
188 a596b957 2022-07-14 tracey if (error) {
189 a596b957 2022-07-14 tracey log_warnx("%s: %s", __func__, error->msg);
190 a596b957 2022-07-14 tracey goto err;
192 a596b957 2022-07-14 tracey html = 1;
195 a596b957 2022-07-14 tracey error = gotweb_render_header(c);
196 a596b957 2022-07-14 tracey if (error) {
197 a596b957 2022-07-14 tracey log_warnx("%s: %s", __func__, error->msg);
198 a596b957 2022-07-14 tracey goto err;
201 a596b957 2022-07-14 tracey if (error2) {
202 a596b957 2022-07-14 tracey error = error2;
203 a596b957 2022-07-14 tracey goto err;
206 a596b957 2022-07-14 tracey switch(qs->action) {
207 a596b957 2022-07-14 tracey case BLAME:
208 a596b957 2022-07-14 tracey error = gotweb_render_blame(c);
209 a596b957 2022-07-14 tracey if (error) {
210 a596b957 2022-07-14 tracey log_warnx("%s: %s", __func__, error->msg);
211 a596b957 2022-07-14 tracey goto err;
214 a596b957 2022-07-14 tracey case BRIEFS:
215 a596b957 2022-07-14 tracey error = gotweb_render_briefs(c);
216 a596b957 2022-07-14 tracey if (error) {
217 a596b957 2022-07-14 tracey log_warnx("%s: %s", __func__, error->msg);
218 a596b957 2022-07-14 tracey goto err;
221 a596b957 2022-07-14 tracey case COMMITS:
222 a596b957 2022-07-14 tracey error = gotweb_render_commits(c);
223 a596b957 2022-07-14 tracey if (error) {
224 a596b957 2022-07-14 tracey log_warnx("%s: %s", __func__, error->msg);
225 a596b957 2022-07-14 tracey goto err;
228 a596b957 2022-07-14 tracey case DIFF:
229 a596b957 2022-07-14 tracey error = gotweb_render_diff(c);
230 a596b957 2022-07-14 tracey if (error) {
231 a596b957 2022-07-14 tracey log_warnx("%s: %s", __func__, error->msg);
232 a596b957 2022-07-14 tracey goto err;
235 a596b957 2022-07-14 tracey case INDEX:
236 a596b957 2022-07-14 tracey error = gotweb_render_index(c);
237 a596b957 2022-07-14 tracey if (error) {
238 a596b957 2022-07-14 tracey log_warnx("%s: %s", __func__, error->msg);
239 a596b957 2022-07-14 tracey goto err;
242 a596b957 2022-07-14 tracey case SUMMARY:
243 a596b957 2022-07-14 tracey error = gotweb_render_summary(c);
244 a596b957 2022-07-14 tracey if (error) {
245 a596b957 2022-07-14 tracey log_warnx("%s: %s", __func__, error->msg);
246 a596b957 2022-07-14 tracey goto err;
249 a596b957 2022-07-14 tracey case TAG:
250 a596b957 2022-07-14 tracey error = gotweb_render_tag(c);
251 a596b957 2022-07-14 tracey if (error) {
252 a596b957 2022-07-14 tracey log_warnx("%s: %s", __func__, error->msg);
253 a596b957 2022-07-14 tracey goto err;
256 a596b957 2022-07-14 tracey case TAGS:
257 a596b957 2022-07-14 tracey error = gotweb_render_tags(c);
258 a596b957 2022-07-14 tracey if (error) {
259 a596b957 2022-07-14 tracey log_warnx("%s: %s", __func__, error->msg);
260 a596b957 2022-07-14 tracey goto err;
263 a596b957 2022-07-14 tracey case TREE:
264 a596b957 2022-07-14 tracey error = gotweb_render_tree(c);
265 a596b957 2022-07-14 tracey if (error) {
266 a596b957 2022-07-14 tracey log_warnx("%s: %s", __func__, error->msg);
267 a596b957 2022-07-14 tracey goto err;
270 a596b957 2022-07-14 tracey case ERR:
272 01498c42 2022-08-19 op r = fcgi_printf(c, "<div id='err_content'>%s</div>\n",
273 01498c42 2022-08-19 op "Erorr: Bad Querystring");
275 a596b957 2022-07-14 tracey goto err;
279 a596b957 2022-07-14 tracey goto done;
281 01498c42 2022-08-19 op if (html && fcgi_printf(c, "<div id='err_content'>") == -1)
283 01498c42 2022-08-19 op if (fcgi_printf(c, "%s", err) == -1)
285 a596b957 2022-07-14 tracey if (error) {
286 01498c42 2022-08-19 op if (fcgi_printf(c, "%s", error->msg) == -1)
289 01498c42 2022-08-19 op if (fcgi_printf(c, "see daemon logs for details") == -1)
292 01498c42 2022-08-19 op if (html && fcgi_printf(c, "</div>\n") == -1)
295 a596b957 2022-07-14 tracey if (html && srv != NULL)
296 a596b957 2022-07-14 tracey gotweb_render_footer(c);
299 a596b957 2022-07-14 tracey struct server *
300 95a4a5a1 2022-08-30 op gotweb_get_server(uint8_t *server_name, uint8_t *subdomain)
302 a596b957 2022-07-14 tracey struct server *srv = NULL;
304 95a4a5a1 2022-08-30 op /* check against the server name first */
305 a596b957 2022-07-14 tracey if (strlen(server_name) > 0)
306 2ad48e9a 2022-08-16 stsp TAILQ_FOREACH(srv, &gotwebd_env->servers, entry)
307 a596b957 2022-07-14 tracey if (strcmp(srv->name, server_name) == 0)
308 a596b957 2022-07-14 tracey goto done;
310 95a4a5a1 2022-08-30 op /* check against subdomain second */
311 a596b957 2022-07-14 tracey if (strlen(subdomain) > 0)
312 2ad48e9a 2022-08-16 stsp TAILQ_FOREACH(srv, &gotwebd_env->servers, entry)
313 a596b957 2022-07-14 tracey if (strcmp(srv->name, subdomain) == 0)
314 a596b957 2022-07-14 tracey goto done;
316 a596b957 2022-07-14 tracey /* if those fail, send first server */
317 2ad48e9a 2022-08-16 stsp TAILQ_FOREACH(srv, &gotwebd_env->servers, entry)
318 a596b957 2022-07-14 tracey if (srv != NULL)
321 a596b957 2022-07-14 tracey return srv;
324 a596b957 2022-07-14 tracey const struct got_error *
325 a596b957 2022-07-14 tracey gotweb_init_transport(struct transport **t)
327 a596b957 2022-07-14 tracey const struct got_error *error = NULL;
329 a596b957 2022-07-14 tracey *t = calloc(1, sizeof(**t));
330 a596b957 2022-07-14 tracey if (*t == NULL)
331 a596b957 2022-07-14 tracey return got_error_from_errno2("%s: calloc", __func__);
333 a596b957 2022-07-14 tracey TAILQ_INIT(&(*t)->repo_commits);
334 a596b957 2022-07-14 tracey TAILQ_INIT(&(*t)->repo_tags);
336 a596b957 2022-07-14 tracey (*t)->repo = NULL;
337 a596b957 2022-07-14 tracey (*t)->repo_dir = NULL;
338 a596b957 2022-07-14 tracey (*t)->qs = NULL;
339 a596b957 2022-07-14 tracey (*t)->next_id = NULL;
340 a596b957 2022-07-14 tracey (*t)->prev_id = NULL;
341 a596b957 2022-07-14 tracey (*t)->next_disp = 0;
342 a596b957 2022-07-14 tracey (*t)->prev_disp = 0;
344 a596b957 2022-07-14 tracey return error;
347 a596b957 2022-07-14 tracey static const struct got_error *
348 a596b957 2022-07-14 tracey gotweb_init_querystring(struct querystring **qs)
350 a596b957 2022-07-14 tracey const struct got_error *error = NULL;
352 a596b957 2022-07-14 tracey *qs = calloc(1, sizeof(**qs));
353 a596b957 2022-07-14 tracey if (*qs == NULL)
354 a596b957 2022-07-14 tracey return got_error_from_errno2("%s: calloc", __func__);
356 a596b957 2022-07-14 tracey (*qs)->headref = strdup("HEAD");
357 a596b957 2022-07-14 tracey if ((*qs)->headref == NULL) {
360 a596b957 2022-07-14 tracey return got_error_from_errno2("%s: strdup", __func__);
363 6c37ad7b 2022-09-01 op (*qs)->action = INDEX;
364 6c37ad7b 2022-09-01 op (*qs)->commit = NULL;
365 6c37ad7b 2022-09-01 op (*qs)->file = NULL;
366 6c37ad7b 2022-09-01 op (*qs)->folder = NULL;
367 a596b957 2022-07-14 tracey (*qs)->index_page = 0;
368 a596b957 2022-07-14 tracey (*qs)->index_page_str = NULL;
369 a596b957 2022-07-14 tracey (*qs)->path = NULL;
371 a596b957 2022-07-14 tracey return error;
374 a596b957 2022-07-14 tracey static const struct got_error *
375 a596b957 2022-07-14 tracey gotweb_parse_querystring(struct querystring **qs, char *qst)
377 a596b957 2022-07-14 tracey const struct got_error *error = NULL;
378 a596b957 2022-07-14 tracey char *tok1 = NULL, *tok1_pair = NULL, *tok1_end = NULL;
379 a596b957 2022-07-14 tracey char *tok2 = NULL, *tok2_pair = NULL, *tok2_end = NULL;
381 a596b957 2022-07-14 tracey if (qst == NULL)
382 a596b957 2022-07-14 tracey return error;
384 a596b957 2022-07-14 tracey tok1 = strdup(qst);
385 a596b957 2022-07-14 tracey if (tok1 == NULL)
386 a596b957 2022-07-14 tracey return got_error_from_errno2("%s: strdup", __func__);
388 a596b957 2022-07-14 tracey tok1_pair = tok1;
389 a596b957 2022-07-14 tracey tok1_end = tok1;
391 a596b957 2022-07-14 tracey while (tok1_pair != NULL) {
392 a596b957 2022-07-14 tracey strsep(&tok1_end, "&");
394 a596b957 2022-07-14 tracey tok2 = strdup(tok1_pair);
395 a596b957 2022-07-14 tracey if (tok2 == NULL) {
396 a596b957 2022-07-14 tracey free(tok1);
397 a596b957 2022-07-14 tracey return got_error_from_errno2("%s: strdup", __func__);
400 a596b957 2022-07-14 tracey tok2_pair = tok2;
401 a596b957 2022-07-14 tracey tok2_end = tok2;
403 a596b957 2022-07-14 tracey while (tok2_pair != NULL) {
404 a596b957 2022-07-14 tracey strsep(&tok2_end, "=");
405 a596b957 2022-07-14 tracey if (tok2_end) {
406 a596b957 2022-07-14 tracey error = gotweb_assign_querystring(qs, tok2_pair,
407 a596b957 2022-07-14 tracey tok2_end);
408 a596b957 2022-07-14 tracey if (error)
409 a596b957 2022-07-14 tracey goto err;
411 a596b957 2022-07-14 tracey tok2_pair = tok2_end;
413 a596b957 2022-07-14 tracey free(tok2);
414 a596b957 2022-07-14 tracey tok1_pair = tok1_end;
416 a596b957 2022-07-14 tracey free(tok1);
417 a596b957 2022-07-14 tracey return error;
419 a596b957 2022-07-14 tracey free(tok2);
420 a596b957 2022-07-14 tracey free(tok1);
421 a596b957 2022-07-14 tracey return error;
424 a596b957 2022-07-14 tracey static const struct got_error *
425 a596b957 2022-07-14 tracey gotweb_assign_querystring(struct querystring **qs, char *key, char *value)
427 a596b957 2022-07-14 tracey const struct got_error *error = NULL;
428 a596b957 2022-07-14 tracey const char *errstr;
429 a596b957 2022-07-14 tracey int a_cnt, el_cnt;
431 a596b957 2022-07-14 tracey for (el_cnt = 0; el_cnt < QSELEM__MAX; el_cnt++) {
432 a596b957 2022-07-14 tracey if (strcmp(key, querystring_keys[el_cnt].name) != 0)
433 a596b957 2022-07-14 tracey continue;
435 a596b957 2022-07-14 tracey switch (querystring_keys[el_cnt].element) {
436 a596b957 2022-07-14 tracey case ACTION:
437 a596b957 2022-07-14 tracey for (a_cnt = 0; a_cnt < ACTIONS__MAX; a_cnt++) {
438 a596b957 2022-07-14 tracey if (strcmp(value, action_keys[a_cnt].name) != 0)
439 a596b957 2022-07-14 tracey continue;
440 a596b957 2022-07-14 tracey else if (strcmp(value,
441 a596b957 2022-07-14 tracey action_keys[a_cnt].name) == 0){
442 a596b957 2022-07-14 tracey (*qs)->action =
443 a596b957 2022-07-14 tracey action_keys[a_cnt].action;
444 a596b957 2022-07-14 tracey goto qa_found;
447 a596b957 2022-07-14 tracey (*qs)->action = ERR;
448 a596b957 2022-07-14 tracey qa_found:
450 a596b957 2022-07-14 tracey case COMMIT:
451 a596b957 2022-07-14 tracey (*qs)->commit = strdup(value);
452 a596b957 2022-07-14 tracey if ((*qs)->commit == NULL) {
453 a596b957 2022-07-14 tracey error = got_error_from_errno2("%s: strdup",
454 a596b957 2022-07-14 tracey __func__);
455 a596b957 2022-07-14 tracey goto done;
458 a596b957 2022-07-14 tracey case RFILE:
459 a596b957 2022-07-14 tracey (*qs)->file = strdup(value);
460 a596b957 2022-07-14 tracey if ((*qs)->file == NULL) {
461 a596b957 2022-07-14 tracey error = got_error_from_errno2("%s: strdup",
462 a596b957 2022-07-14 tracey __func__);
463 a596b957 2022-07-14 tracey goto done;
466 a596b957 2022-07-14 tracey case FOLDER:
467 a596b957 2022-07-14 tracey (*qs)->folder = strdup(value);
468 a596b957 2022-07-14 tracey if ((*qs)->folder == NULL) {
469 a596b957 2022-07-14 tracey error = got_error_from_errno2("%s: strdup",
470 a596b957 2022-07-14 tracey __func__);
471 a596b957 2022-07-14 tracey goto done;
474 a596b957 2022-07-14 tracey case HEADREF:
475 f8faf9f1 2022-09-01 op free((*qs)->headref);
476 a596b957 2022-07-14 tracey (*qs)->headref = strdup(value);
477 a596b957 2022-07-14 tracey if ((*qs)->headref == NULL) {
478 a596b957 2022-07-14 tracey error = got_error_from_errno2("%s: strdup",
479 a596b957 2022-07-14 tracey __func__);
480 a596b957 2022-07-14 tracey goto done;
483 a596b957 2022-07-14 tracey case INDEX_PAGE:
484 a596b957 2022-07-14 tracey if (strlen(value) == 0)
486 a596b957 2022-07-14 tracey (*qs)->index_page_str = strdup(value);
487 a596b957 2022-07-14 tracey if ((*qs)->index_page_str == NULL) {
488 a596b957 2022-07-14 tracey error = got_error_from_errno2("%s: strdup",
489 a596b957 2022-07-14 tracey __func__);
490 a596b957 2022-07-14 tracey goto done;
492 a596b957 2022-07-14 tracey (*qs)->index_page = strtonum(value, INT64_MIN,
493 a596b957 2022-07-14 tracey INT64_MAX, &errstr);
494 a596b957 2022-07-14 tracey if (errstr) {
495 a596b957 2022-07-14 tracey error = got_error_from_errno3("%s: strtonum %s",
496 a596b957 2022-07-14 tracey __func__, errstr);
497 a596b957 2022-07-14 tracey goto done;
499 a596b957 2022-07-14 tracey if ((*qs)->index_page < 0) {
500 a596b957 2022-07-14 tracey (*qs)->index_page = 0;
501 a596b957 2022-07-14 tracey sprintf((*qs)->index_page_str, "%d", 0);
504 a596b957 2022-07-14 tracey case PATH:
505 a596b957 2022-07-14 tracey (*qs)->path = strdup(value);
506 a596b957 2022-07-14 tracey if ((*qs)->path == NULL) {
507 a596b957 2022-07-14 tracey error = got_error_from_errno2("%s: strdup",
508 a596b957 2022-07-14 tracey __func__);
509 a596b957 2022-07-14 tracey goto done;
512 a596b957 2022-07-14 tracey case PAGE:
513 a596b957 2022-07-14 tracey if (strlen(value) == 0)
515 a596b957 2022-07-14 tracey (*qs)->page_str = strdup(value);
516 a596b957 2022-07-14 tracey if ((*qs)->page_str == NULL) {
517 a596b957 2022-07-14 tracey error = got_error_from_errno2("%s: strdup",
518 a596b957 2022-07-14 tracey __func__);
519 a596b957 2022-07-14 tracey goto done;
521 a596b957 2022-07-14 tracey (*qs)->page = strtonum(value, INT64_MIN,
522 a596b957 2022-07-14 tracey INT64_MAX, &errstr);
523 a596b957 2022-07-14 tracey if (errstr) {
524 a596b957 2022-07-14 tracey error = got_error_from_errno3("%s: strtonum %s",
525 a596b957 2022-07-14 tracey __func__, errstr);
526 a596b957 2022-07-14 tracey goto done;
528 a596b957 2022-07-14 tracey if ((*qs)->page < 0) {
529 a596b957 2022-07-14 tracey (*qs)->page = 0;
530 a596b957 2022-07-14 tracey sprintf((*qs)->page_str, "%d", 0);
538 a596b957 2022-07-14 tracey return error;
542 a596b957 2022-07-14 tracey gotweb_free_repo_tag(struct repo_tag *rt)
544 a596b957 2022-07-14 tracey if (rt != NULL) {
545 a596b957 2022-07-14 tracey free(rt->commit_id);
546 625e5896 2022-09-01 op free(rt->tag_name);
547 625e5896 2022-09-01 op free(rt->tag_commit);
548 625e5896 2022-09-01 op free(rt->commit_msg);
549 a596b957 2022-07-14 tracey free(rt->tagger);
551 a596b957 2022-07-14 tracey free(rt);
555 a596b957 2022-07-14 tracey gotweb_free_repo_commit(struct repo_commit *rc)
557 a596b957 2022-07-14 tracey if (rc != NULL) {
558 a596b957 2022-07-14 tracey free(rc->path);
559 a596b957 2022-07-14 tracey free(rc->refs_str);
560 a596b957 2022-07-14 tracey free(rc->commit_id);
561 a596b957 2022-07-14 tracey free(rc->parent_id);
562 a596b957 2022-07-14 tracey free(rc->tree_id);
563 a596b957 2022-07-14 tracey free(rc->author);
564 a596b957 2022-07-14 tracey free(rc->committer);
565 a596b957 2022-07-14 tracey free(rc->commit_msg);
567 a596b957 2022-07-14 tracey free(rc);
570 a596b957 2022-07-14 tracey static void
571 a596b957 2022-07-14 tracey gotweb_free_querystring(struct querystring *qs)
573 a596b957 2022-07-14 tracey if (qs != NULL) {
574 a596b957 2022-07-14 tracey free(qs->commit);
575 a596b957 2022-07-14 tracey free(qs->file);
576 a596b957 2022-07-14 tracey free(qs->folder);
577 a596b957 2022-07-14 tracey free(qs->headref);
578 a596b957 2022-07-14 tracey free(qs->index_page_str);
579 a596b957 2022-07-14 tracey free(qs->path);
580 a596b957 2022-07-14 tracey free(qs->page_str);
582 a596b957 2022-07-14 tracey free(qs);
585 a596b957 2022-07-14 tracey static void
586 a596b957 2022-07-14 tracey gotweb_free_repo_dir(struct repo_dir *repo_dir)
588 a596b957 2022-07-14 tracey if (repo_dir != NULL) {
589 a596b957 2022-07-14 tracey free(repo_dir->name);
590 a596b957 2022-07-14 tracey free(repo_dir->owner);
591 a596b957 2022-07-14 tracey free(repo_dir->description);
592 a596b957 2022-07-14 tracey free(repo_dir->url);
593 a596b957 2022-07-14 tracey free(repo_dir->age);
594 a596b957 2022-07-14 tracey free(repo_dir->path);
596 a596b957 2022-07-14 tracey free(repo_dir);
600 a596b957 2022-07-14 tracey gotweb_free_transport(struct transport *t)
602 a596b957 2022-07-14 tracey struct repo_commit *rc = NULL, *trc = NULL;
603 a596b957 2022-07-14 tracey struct repo_tag *rt = NULL, *trt = NULL;
605 a596b957 2022-07-14 tracey TAILQ_FOREACH_SAFE(rc, &t->repo_commits, entry, trc) {
606 a596b957 2022-07-14 tracey TAILQ_REMOVE(&t->repo_commits, rc, entry);
607 a596b957 2022-07-14 tracey gotweb_free_repo_commit(rc);
609 a596b957 2022-07-14 tracey TAILQ_FOREACH_SAFE(rt, &t->repo_tags, entry, trt) {
610 a596b957 2022-07-14 tracey TAILQ_REMOVE(&t->repo_tags, rt, entry);
611 a596b957 2022-07-14 tracey gotweb_free_repo_tag(rt);
613 a596b957 2022-07-14 tracey gotweb_free_repo_dir(t->repo_dir);
614 a596b957 2022-07-14 tracey gotweb_free_querystring(t->qs);
615 341fa7ca 2022-09-01 op free(t->next_id);
616 341fa7ca 2022-09-01 op free(t->prev_id);
620 a596b957 2022-07-14 tracey const struct got_error *
621 a596b957 2022-07-14 tracey gotweb_render_content_type(struct request *c, const uint8_t *type)
623 4d648b92 2022-08-20 op const char *csp = "default-src 'self'; script-src 'none'; "
624 4d648b92 2022-08-20 op "object-src 'none';";
626 4d648b92 2022-08-20 op fcgi_printf(c,
627 4d648b92 2022-08-20 op "Content-Security-Policy: %s\r\n"
628 4d648b92 2022-08-20 op "Content-Type: %s\r\n\r\n",
633 a596b957 2022-07-14 tracey const struct got_error *
634 a596b957 2022-07-14 tracey gotweb_render_content_type_file(struct request *c, const uint8_t *type,
635 a596b957 2022-07-14 tracey char *file)
637 01498c42 2022-08-19 op fcgi_printf(c, "Content-type: %s\r\n"
638 a596b957 2022-07-14 tracey "Content-disposition: attachment; filename=%s\r\n\r\n",
643 a596b957 2022-07-14 tracey static const struct got_error *
644 a596b957 2022-07-14 tracey gotweb_render_header(struct request *c)
646 a596b957 2022-07-14 tracey struct server *srv = c->srv;
647 a596b957 2022-07-14 tracey struct querystring *qs = c->t->qs;
650 01498c42 2022-08-19 op r = fcgi_printf(c, "<!doctype html>\n"
653 01498c42 2022-08-19 op "<title>%s</title>\n"
654 01498c42 2022-08-19 op "<meta charset='utf-8' />\n"
655 01498c42 2022-08-19 op "<meta name='viewport' content='initial-scale=.75' />\n"
656 01498c42 2022-08-19 op "<meta name='msapplication-TileColor' content='#da532c' />\n"
657 01498c42 2022-08-19 op "<meta name='theme-color' content='#ffffff'/>\n"
658 01498c42 2022-08-19 op "<link rel='apple-touch-icon' sizes='180x180'"
659 565bce9b 2022-09-01 op " href='%sapple-touch-icon.png' />\n"
660 01498c42 2022-08-19 op "<link rel='icon' type='image/png' sizes='32x32'"
661 565bce9b 2022-09-01 op " href='%sfavicon-32x32.png' />\n"
662 01498c42 2022-08-19 op "<link rel='icon' type='image/png' sizes='16x16'"
663 565bce9b 2022-09-01 op " href='%sfavicon-16x16.png' />\n"
664 565bce9b 2022-09-01 op "<link rel='manifest' href='%ssite.webmanifest'/>\n"
665 565bce9b 2022-09-01 op "<link rel='mask-icon' href='%ssafari-pinned-tab.svg' />\n"
666 01498c42 2022-08-19 op "<link rel='stylesheet' type='text/css' href='%s%s' />\n"
669 01498c42 2022-08-19 op "<div id='gw_body'>\n"
670 01498c42 2022-08-19 op "<div id='header'>\n"
671 01498c42 2022-08-19 op "<div id='got_link'>"
672 336c64e8 2022-08-20 op "<a href='%s' target='_blank'>"
673 01498c42 2022-08-19 op "<img src='%s%s' alt='logo' id='logo' />"
675 01498c42 2022-08-19 op "</div>\n" /* #got_link */
676 01498c42 2022-08-19 op "</div>\n" /* #header */
677 01498c42 2022-08-19 op "<div id='site_path'>\n"
678 01498c42 2022-08-19 op "<div id='site_link'>\n"
679 95a4a5a1 2022-08-30 op "<a href='?index_page=%d'>%s</a>",
680 565bce9b 2022-09-01 op c->script_name,
681 565bce9b 2022-09-01 op c->script_name,
682 565bce9b 2022-09-01 op c->script_name,
683 565bce9b 2022-09-01 op c->script_name,
684 565bce9b 2022-09-01 op c->script_name,
685 01498c42 2022-08-19 op srv->site_name,
686 95a4a5a1 2022-08-30 op c->script_name, srv->custom_css,
687 01498c42 2022-08-19 op srv->logo_url,
688 95a4a5a1 2022-08-30 op c->script_name, srv->logo,
689 95a4a5a1 2022-08-30 op qs->index_page, srv->site_link);
691 a596b957 2022-07-14 tracey goto done;
693 a596b957 2022-07-14 tracey if (qs != NULL) {
694 a596b957 2022-07-14 tracey if (qs->path != NULL) {
695 01498c42 2022-08-19 op r = fcgi_printf(c, " / "
696 95a4a5a1 2022-08-30 op "<a href='?index_page=%d&path=%s&action=summary'>"
698 95a4a5a1 2022-08-30 op qs->index_page, qs->path, qs->path);
700 a596b957 2022-07-14 tracey goto done;
702 a596b957 2022-07-14 tracey if (qs->action != INDEX) {
703 01498c42 2022-08-19 op const char *action = "";
705 01498c42 2022-08-19 op switch (qs->action) {
707 01498c42 2022-08-19 op action = "blame";
710 01498c42 2022-08-19 op action = "briefs";
712 01498c42 2022-08-19 op case COMMITS:
713 01498c42 2022-08-19 op action = "commits";
716 01498c42 2022-08-19 op action = "diff";
718 01498c42 2022-08-19 op case SUMMARY:
719 01498c42 2022-08-19 op action = "summary";
722 01498c42 2022-08-19 op action = "tag";
725 01498c42 2022-08-19 op action = "tags";
728 01498c42 2022-08-19 op action = "tree";
732 01498c42 2022-08-19 op if (fcgi_printf(c, " / %s", action) == -1)
737 01498c42 2022-08-19 op fcgi_printf(c, "</div>\n" /* #site_path */
738 01498c42 2022-08-19 op "</div>\n" /* #site_link */
739 01498c42 2022-08-19 op "<div id='content'>\n");
745 a596b957 2022-07-14 tracey static const struct got_error *
746 a596b957 2022-07-14 tracey gotweb_render_footer(struct request *c)
748 a596b957 2022-07-14 tracey const struct got_error *error = NULL;
749 a596b957 2022-07-14 tracey struct server *srv = c->srv;
750 01498c42 2022-08-19 op const char *siteowner = " ";
751 01498c42 2022-08-19 op char *escaped_owner = NULL;
753 a596b957 2022-07-14 tracey if (srv->show_site_owner) {
754 01498c42 2022-08-19 op error = gotweb_escape_html(&escaped_owner, srv->site_owner);
755 a596b957 2022-07-14 tracey if (error)
756 01498c42 2022-08-19 op return error;
757 01498c42 2022-08-19 op siteowner = escaped_owner;
760 01498c42 2022-08-19 op fcgi_printf(c, "<div id='site_owner_wrapper'>\n"
761 01498c42 2022-08-19 op "<div id='site_owner'>%s</div>\n"
762 01498c42 2022-08-19 op "</div>\n" /* #site_owner_wrapper */
763 01498c42 2022-08-19 op "</div>\n" /* #content */
764 01498c42 2022-08-19 op "</div>\n" /* #gw_body */
765 01498c42 2022-08-19 op "</body>\n</html>\n", siteowner);
767 01498c42 2022-08-19 op free(escaped_owner);
771 a596b957 2022-07-14 tracey static const struct got_error *
772 a596b957 2022-07-14 tracey gotweb_render_navs(struct request *c)
774 a596b957 2022-07-14 tracey const struct got_error *error = NULL;
775 a596b957 2022-07-14 tracey struct transport *t = c->t;
776 a596b957 2022-07-14 tracey struct querystring *qs = t->qs;
777 a596b957 2022-07-14 tracey struct server *srv = c->srv;
778 a596b957 2022-07-14 tracey char *nhref = NULL, *phref = NULL;
779 01498c42 2022-08-19 op int r, disp = 0;
781 01498c42 2022-08-19 op r = fcgi_printf(c, "<div id='np_wrapper'>\n<div id='nav_prev'>\n");
783 a596b957 2022-07-14 tracey goto done;
785 a596b957 2022-07-14 tracey switch(qs->action) {
786 a596b957 2022-07-14 tracey case INDEX:
787 a596b957 2022-07-14 tracey if (qs->index_page > 0) {
788 a596b957 2022-07-14 tracey if (asprintf(&phref, "index_page=%d",
789 a596b957 2022-07-14 tracey qs->index_page - 1) == -1) {
790 a596b957 2022-07-14 tracey error = got_error_from_errno2("%s: asprintf",
791 a596b957 2022-07-14 tracey __func__);
792 a596b957 2022-07-14 tracey goto done;
794 a596b957 2022-07-14 tracey disp = 1;
797 a596b957 2022-07-14 tracey case BRIEFS:
798 a596b957 2022-07-14 tracey if (t->prev_id && qs->commit != NULL &&
799 a596b957 2022-07-14 tracey strcmp(qs->commit, t->prev_id) != 0) {
800 a596b957 2022-07-14 tracey if (asprintf(&phref, "index_page=%d&path=%s&page=%d"
801 a596b957 2022-07-14 tracey "&action=briefs&commit=%s&headref=%s",
802 a596b957 2022-07-14 tracey qs->index_page, qs->path, qs->page - 1, t->prev_id,
803 a596b957 2022-07-14 tracey qs->headref) == -1) {
804 a596b957 2022-07-14 tracey error = got_error_from_errno2("%s: asprintf",
805 a596b957 2022-07-14 tracey __func__);
806 a596b957 2022-07-14 tracey goto done;
808 a596b957 2022-07-14 tracey disp = 1;
811 a596b957 2022-07-14 tracey case COMMITS:
812 a596b957 2022-07-14 tracey if (t->prev_id && qs->commit != NULL &&
813 a596b957 2022-07-14 tracey strcmp(qs->commit, t->prev_id) != 0) {
814 a596b957 2022-07-14 tracey if (asprintf(&phref, "index_page=%d&path=%s&page=%d"
815 a596b957 2022-07-14 tracey "&action=commits&commit=%s&headref=%s&folder=%s"
816 a596b957 2022-07-14 tracey "&file=%s",
817 a596b957 2022-07-14 tracey qs->index_page, qs->path, qs->page - 1, t->prev_id,
818 a596b957 2022-07-14 tracey qs->headref, qs->folder ? qs->folder : "",
819 a596b957 2022-07-14 tracey qs->file ? qs->file : "") == -1) {
820 a596b957 2022-07-14 tracey error = got_error_from_errno2("%s: asprintf",
821 a596b957 2022-07-14 tracey __func__);
822 a596b957 2022-07-14 tracey goto done;
824 a596b957 2022-07-14 tracey disp = 1;
827 a596b957 2022-07-14 tracey case TAGS:
828 a596b957 2022-07-14 tracey if (t->prev_id && qs->commit != NULL &&
829 a596b957 2022-07-14 tracey strcmp(qs->commit, t->prev_id) != 0) {
830 a596b957 2022-07-14 tracey if (asprintf(&phref, "index_page=%d&path=%s&page=%d"
831 a596b957 2022-07-14 tracey "&action=tags&commit=%s&headref=%s",
832 a596b957 2022-07-14 tracey qs->index_page, qs->path, qs->page - 1, t->prev_id,
833 a596b957 2022-07-14 tracey qs->headref) == -1) {
834 a596b957 2022-07-14 tracey error = got_error_from_errno2("%s: asprintf",
835 a596b957 2022-07-14 tracey __func__);
836 a596b957 2022-07-14 tracey goto done;
838 a596b957 2022-07-14 tracey disp = 1;
842 a596b957 2022-07-14 tracey disp = 0;
846 a596b957 2022-07-14 tracey if (disp) {
847 01498c42 2022-08-19 op r = fcgi_printf(c, "<a href='?%s'>Previous</a>", phref);
849 a596b957 2022-07-14 tracey goto done;
852 01498c42 2022-08-19 op r = fcgi_printf(c, "</div>\n" /* #nav_prev */
853 01498c42 2022-08-19 op "<div id='nav_next'>");
855 a596b957 2022-07-14 tracey goto done;
857 a596b957 2022-07-14 tracey disp = 0;
858 a596b957 2022-07-14 tracey switch(qs->action) {
859 a596b957 2022-07-14 tracey case INDEX:
860 a596b957 2022-07-14 tracey if (t->next_disp == srv->max_repos_display &&
861 a596b957 2022-07-14 tracey t->repos_total != (qs->index_page + 1) *
862 a596b957 2022-07-14 tracey srv->max_repos_display) {
863 a596b957 2022-07-14 tracey if (asprintf(&nhref, "index_page=%d",
864 a596b957 2022-07-14 tracey qs->index_page + 1) == -1) {
865 a596b957 2022-07-14 tracey error = got_error_from_errno2("%s: asprintf",
866 a596b957 2022-07-14 tracey __func__);
867 a596b957 2022-07-14 tracey goto done;
869 a596b957 2022-07-14 tracey disp = 1;
872 a596b957 2022-07-14 tracey case BRIEFS:
873 a596b957 2022-07-14 tracey if (t->next_id) {
874 a596b957 2022-07-14 tracey if (asprintf(&nhref, "index_page=%d&path=%s&page=%d"
875 a596b957 2022-07-14 tracey "&action=briefs&commit=%s&headref=%s",
876 a596b957 2022-07-14 tracey qs->index_page, qs->path, qs->page + 1, t->next_id,
877 a596b957 2022-07-14 tracey qs->headref) == -1) {
878 a596b957 2022-07-14 tracey error = got_error_from_errno2("%s: asprintf",
879 a596b957 2022-07-14 tracey __func__);
880 a596b957 2022-07-14 tracey goto done;
882 a596b957 2022-07-14 tracey disp = 1;
885 a596b957 2022-07-14 tracey case COMMITS:
886 a596b957 2022-07-14 tracey if (t->next_id) {
887 a596b957 2022-07-14 tracey if (asprintf(&nhref, "index_page=%d&path=%s&page=%d"
888 a596b957 2022-07-14 tracey "&action=commits&commit=%s&headref=%s&folder=%s"
889 a596b957 2022-07-14 tracey "&file=%s",
890 a596b957 2022-07-14 tracey qs->index_page, qs->path, qs->page + 1, t->next_id,
891 a596b957 2022-07-14 tracey qs->headref, qs->folder ? qs->folder : "",
892 a596b957 2022-07-14 tracey qs->file ? qs->file : "") == -1) {
893 a596b957 2022-07-14 tracey error = got_error_from_errno2("%s: asprintf",
894 a596b957 2022-07-14 tracey __func__);
895 a596b957 2022-07-14 tracey goto done;
897 a596b957 2022-07-14 tracey disp = 1;
900 a596b957 2022-07-14 tracey case TAGS:
901 a596b957 2022-07-14 tracey if (t->next_id) {
902 a596b957 2022-07-14 tracey if (asprintf(&nhref, "index_page=%d&path=%s&page=%d"
903 a596b957 2022-07-14 tracey "&action=tags&commit=%s&headref=%s",
904 a596b957 2022-07-14 tracey qs->index_page, qs->path, qs->page + 1, t->next_id,
905 a596b957 2022-07-14 tracey qs->headref) == -1) {
906 a596b957 2022-07-14 tracey error = got_error_from_errno2("%s: asprintf",
907 a596b957 2022-07-14 tracey __func__);
908 a596b957 2022-07-14 tracey goto done;
910 a596b957 2022-07-14 tracey disp = 1;
914 a596b957 2022-07-14 tracey disp = 0;
917 a596b957 2022-07-14 tracey if (disp) {
918 01498c42 2022-08-19 op r = fcgi_printf(c, "<a href='?%s'>Next</a>", nhref);
920 a596b957 2022-07-14 tracey goto done;
922 01498c42 2022-08-19 op fcgi_printf(c, "</div>\n"); /* #nav_next */
923 01498c42 2022-08-19 op fcgi_printf(c, "</div>\n"); /* #np_wrapper */
925 a596b957 2022-07-14 tracey free(t->next_id);
926 a596b957 2022-07-14 tracey t->next_id = NULL;
927 a596b957 2022-07-14 tracey free(t->prev_id);
928 a596b957 2022-07-14 tracey t->prev_id = NULL;
929 a596b957 2022-07-14 tracey free(phref);
930 a596b957 2022-07-14 tracey free(nhref);
931 a596b957 2022-07-14 tracey return error;
934 a596b957 2022-07-14 tracey static const struct got_error *
935 a596b957 2022-07-14 tracey gotweb_render_index(struct request *c)
937 a596b957 2022-07-14 tracey const struct got_error *error = NULL;
938 a596b957 2022-07-14 tracey struct server *srv = c->srv;
939 a596b957 2022-07-14 tracey struct transport *t = c->t;
940 a596b957 2022-07-14 tracey struct querystring *qs = t->qs;
941 a596b957 2022-07-14 tracey struct repo_dir *repo_dir = NULL;
943 2db401bd 2022-09-01 op struct dirent **sd_dent = NULL;
944 01498c42 2022-08-19 op const char *index_page_str;
945 a596b957 2022-07-14 tracey char *c_path = NULL;
946 a596b957 2022-07-14 tracey struct stat st;
947 a596b957 2022-07-14 tracey unsigned int d_cnt, d_i, d_disp = 0;
950 01498c42 2022-08-19 op index_page_str = qs->index_page_str ? qs->index_page_str : "";
952 a596b957 2022-07-14 tracey d = opendir(srv->repos_path);
953 a596b957 2022-07-14 tracey if (d == NULL) {
954 a596b957 2022-07-14 tracey error = got_error_from_errno2("opendir", srv->repos_path);
955 a596b957 2022-07-14 tracey return error;
958 a596b957 2022-07-14 tracey d_cnt = scandir(srv->repos_path, &sd_dent, NULL, alphasort);
959 a596b957 2022-07-14 tracey if (d_cnt == -1) {
960 2db401bd 2022-09-01 op sd_dent = NULL;
961 a596b957 2022-07-14 tracey error = got_error_from_errno2("scandir", srv->repos_path);
962 a596b957 2022-07-14 tracey goto done;
965 a596b957 2022-07-14 tracey /* get total count of repos */
966 a596b957 2022-07-14 tracey for (d_i = 0; d_i < d_cnt; d_i++) {
967 a596b957 2022-07-14 tracey if (strcmp(sd_dent[d_i]->d_name, ".") == 0 ||
968 a596b957 2022-07-14 tracey strcmp(sd_dent[d_i]->d_name, "..") == 0)
969 a596b957 2022-07-14 tracey continue;
971 a596b957 2022-07-14 tracey if (asprintf(&c_path, "%s/%s", srv->repos_path,
972 a596b957 2022-07-14 tracey sd_dent[d_i]->d_name) == -1) {
973 a596b957 2022-07-14 tracey error = got_error_from_errno("asprintf");
974 a596b957 2022-07-14 tracey return error;
977 a596b957 2022-07-14 tracey if (lstat(c_path, &st) == 0 && S_ISDIR(st.st_mode) &&
978 a596b957 2022-07-14 tracey !got_path_dir_is_empty(c_path))
979 d52aad14 2022-08-31 op t->repos_total++;
980 a596b957 2022-07-14 tracey free(c_path);
981 a596b957 2022-07-14 tracey c_path = NULL;
984 01498c42 2022-08-19 op r = fcgi_printf(c, "<div id='index_header'>\n"
985 01498c42 2022-08-19 op "<div id='index_header_project'>Project</div>\n");
987 a596b957 2022-07-14 tracey goto done;
989 a596b957 2022-07-14 tracey if (srv->show_repo_description)
990 01498c42 2022-08-19 op if (fcgi_printf(c, "<div id='index_header_description'>"
991 a596b957 2022-07-14 tracey "Description</div>\n") == -1)
992 a596b957 2022-07-14 tracey goto done;
993 a596b957 2022-07-14 tracey if (srv->show_repo_owner)
994 01498c42 2022-08-19 op if (fcgi_printf(c, "<div id='index_header_owner'>"
995 a596b957 2022-07-14 tracey "Owner</div>\n") == -1)
996 a596b957 2022-07-14 tracey goto done;
997 a596b957 2022-07-14 tracey if (srv->show_repo_age)
998 01498c42 2022-08-19 op if (fcgi_printf(c, "<div id='index_header_age'>"
999 a596b957 2022-07-14 tracey "Last Change</div>\n") == -1)
1000 a596b957 2022-07-14 tracey goto done;
1001 01498c42 2022-08-19 op if (fcgi_printf(c, "</div>\n") == -1) /* #index_header */
1002 a596b957 2022-07-14 tracey goto done;
1004 a596b957 2022-07-14 tracey for (d_i = 0; d_i < d_cnt; d_i++) {
1005 a596b957 2022-07-14 tracey if (srv->max_repos > 0 && (d_i - 2) == srv->max_repos)
1006 a596b957 2022-07-14 tracey break; /* account for parent and self */
1008 a596b957 2022-07-14 tracey if (strcmp(sd_dent[d_i]->d_name, ".") == 0 ||
1009 a596b957 2022-07-14 tracey strcmp(sd_dent[d_i]->d_name, "..") == 0)
1010 a596b957 2022-07-14 tracey continue;
1012 a596b957 2022-07-14 tracey if (qs->index_page > 0 && (qs->index_page *
1013 a596b957 2022-07-14 tracey srv->max_repos_display) > t->prev_disp) {
1014 a596b957 2022-07-14 tracey t->prev_disp++;
1015 a596b957 2022-07-14 tracey continue;
1018 a596b957 2022-07-14 tracey error = gotweb_init_repo_dir(&repo_dir, sd_dent[d_i]->d_name);
1019 a596b957 2022-07-14 tracey if (error)
1020 a596b957 2022-07-14 tracey goto done;
1022 a596b957 2022-07-14 tracey error = gotweb_load_got_path(c, repo_dir);
1023 a596b957 2022-07-14 tracey if (error && error->code == GOT_ERR_NOT_GIT_REPO) {
1024 a596b957 2022-07-14 tracey error = NULL;
1025 a596b957 2022-07-14 tracey continue;
1027 a596b957 2022-07-14 tracey else if (error && error->code != GOT_ERR_LONELY_PACKIDX)
1028 a596b957 2022-07-14 tracey goto done;
1030 a596b957 2022-07-14 tracey if (lstat(repo_dir->path, &st) == 0 &&
1031 a596b957 2022-07-14 tracey S_ISDIR(st.st_mode) &&
1032 a596b957 2022-07-14 tracey !got_path_dir_is_empty(repo_dir->path))
1033 a596b957 2022-07-14 tracey goto render;
1035 a596b957 2022-07-14 tracey gotweb_free_repo_dir(repo_dir);
1036 a596b957 2022-07-14 tracey repo_dir = NULL;
1037 a596b957 2022-07-14 tracey continue;
1040 a596b957 2022-07-14 tracey d_disp++;
1041 a596b957 2022-07-14 tracey t->prev_disp++;
1043 01498c42 2022-08-19 op r = fcgi_printf(c, "<div class='index_wrapper'>\n"
1044 01498c42 2022-08-19 op "<div class='index_project'>"
1045 01498c42 2022-08-19 op "<a href='?index_page=%s&path=%s&action=summary'>"
1048 01498c42 2022-08-19 op "</div>", /* .index_project */
1049 01498c42 2022-08-19 op index_page_str, repo_dir->name,
1050 01498c42 2022-08-19 op repo_dir->name);
1051 01498c42 2022-08-19 op if (r == -1)
1052 a596b957 2022-07-14 tracey goto done;
1054 a596b957 2022-07-14 tracey if (srv->show_repo_description) {
1055 01498c42 2022-08-19 op r = fcgi_printf(c,
1056 01498c42 2022-08-19 op "<div class='index_project_description'>\n"
1057 01498c42 2022-08-19 op "%s</div>\n", repo_dir->description);
1058 01498c42 2022-08-19 op if (r == -1)
1059 a596b957 2022-07-14 tracey goto done;
1062 a596b957 2022-07-14 tracey if (srv->show_repo_owner) {
1063 01498c42 2022-08-19 op r = fcgi_printf(c, "<div class='index_project_owner'>"
1064 01498c42 2022-08-19 op "%s</div>\n", repo_dir->owner);
1065 01498c42 2022-08-19 op if (r == -1)
1066 a596b957 2022-07-14 tracey goto done;
1069 a596b957 2022-07-14 tracey if (srv->show_repo_age) {
1070 01498c42 2022-08-19 op r = fcgi_printf(c, "<div class='index_project_age'>"
1071 01498c42 2022-08-19 op "%s</div>\n", repo_dir->age);
1072 01498c42 2022-08-19 op if (r == -1)
1073 a596b957 2022-07-14 tracey goto done;
1076 01498c42 2022-08-19 op r = fcgi_printf(c, "<div class='navs_wrapper'>"
1077 01498c42 2022-08-19 op "<div class='navs'>"
1078 01498c42 2022-08-19 op "<a href='?index_page=%s&path=%s&action=summary'>"
1081 01498c42 2022-08-19 op "<a href='?index_page=%s&path=%s&action=briefs'>"
1082 01498c42 2022-08-19 op "commit briefs"
1084 01498c42 2022-08-19 op "<a href='?index_page=%s&path=%s&action=commits'>"
1087 01498c42 2022-08-19 op "<a href='?index_page=%s&path=%s&action=tags'>"
1090 01498c42 2022-08-19 op "<a href='?index_page=%s&path=%s&action=tree'>"
1093 01498c42 2022-08-19 op "</div>" /* .navs */
1094 01498c42 2022-08-19 op "<div class='dotted_line'></div>\n"
1095 01498c42 2022-08-19 op "</div>\n" /* .navs_wrapper */
1096 01498c42 2022-08-19 op "</div>\n", /* .index_wrapper */
1097 01498c42 2022-08-19 op index_page_str, repo_dir->name,
1098 01498c42 2022-08-19 op index_page_str, repo_dir->name,
1099 01498c42 2022-08-19 op index_page_str, repo_dir->name,
1100 01498c42 2022-08-19 op index_page_str, repo_dir->name,
1101 01498c42 2022-08-19 op index_page_str, repo_dir->name);
1102 01498c42 2022-08-19 op if (r == -1)
1103 a596b957 2022-07-14 tracey goto done;
1105 a596b957 2022-07-14 tracey gotweb_free_repo_dir(repo_dir);
1106 a596b957 2022-07-14 tracey repo_dir = NULL;
1107 a596b957 2022-07-14 tracey t->next_disp++;
1108 a596b957 2022-07-14 tracey if (d_disp == srv->max_repos_display)
1111 a596b957 2022-07-14 tracey if (srv->max_repos_display == 0)
1113 a596b957 2022-07-14 tracey if (srv->max_repos > 0 && srv->max_repos < srv->max_repos_display)
1115 a596b957 2022-07-14 tracey if (t->repos_total <= srv->max_repos ||
1116 a596b957 2022-07-14 tracey t->repos_total <= srv->max_repos_display)
1119 a596b957 2022-07-14 tracey error = gotweb_render_navs(c);
1120 a596b957 2022-07-14 tracey if (error)
1121 a596b957 2022-07-14 tracey goto done;
1123 2db401bd 2022-09-01 op if (sd_dent) {
1124 2db401bd 2022-09-01 op for (d_i = 0; d_i < d_cnt; d_i++)
1125 2db401bd 2022-09-01 op free(sd_dent[d_i]);
1126 2db401bd 2022-09-01 op free(sd_dent);
1128 a596b957 2022-07-14 tracey if (d != NULL && closedir(d) == EOF && error == NULL)
1129 a596b957 2022-07-14 tracey error = got_error_from_errno("closedir");
1130 a596b957 2022-07-14 tracey return error;
1133 a596b957 2022-07-14 tracey static const struct got_error *
1134 a596b957 2022-07-14 tracey gotweb_render_blame(struct request *c)
1136 a596b957 2022-07-14 tracey const struct got_error *error = NULL;
1137 a596b957 2022-07-14 tracey struct transport *t = c->t;
1138 a596b957 2022-07-14 tracey struct repo_commit *rc = NULL;
1139 d927f8c8 2022-08-20 op char *age = NULL, *msg = NULL;
1142 a596b957 2022-07-14 tracey error = got_get_repo_commits(c, 1);
1143 a596b957 2022-07-14 tracey if (error)
1144 a596b957 2022-07-14 tracey return error;
1146 a596b957 2022-07-14 tracey rc = TAILQ_FIRST(&t->repo_commits);
1148 a596b957 2022-07-14 tracey error = gotweb_get_time_str(&age, rc->committer_time, TM_LONG);
1151 d927f8c8 2022-08-20 op error = gotweb_escape_html(&msg, rc->commit_msg);
1152 a596b957 2022-07-14 tracey if (error)
1153 a596b957 2022-07-14 tracey goto done;
1155 01498c42 2022-08-19 op r = fcgi_printf(c, "<div id='blame_title_wrapper'>\n"
1156 01498c42 2022-08-19 op "<div id='blame_title'>Blame</div>\n"
1157 01498c42 2022-08-19 op "</div>\n" /* #blame_title_wrapper */
1158 01498c42 2022-08-19 op "<div id='blame_content'>\n"
1159 01498c42 2022-08-19 op "<div id='blame_header_wrapper'>\n"
1160 01498c42 2022-08-19 op "<div id='blame_header'>\n"
1161 01498c42 2022-08-19 op "<div class='header_age_title'>Date:</div>\n"
1162 01498c42 2022-08-19 op "<div class='header_age'>%s</div>\n"
1163 01498c42 2022-08-19 op "<div id='header_commit_msg_title'>Message:</div>\n"
1164 01498c42 2022-08-19 op "<div id='header_commit_msg'>%s</div>\n"
1165 01498c42 2022-08-19 op "</div>\n" /* #blame_header */
1166 01498c42 2022-08-19 op "</div>\n" /* #blame_header_wrapper */
1167 01498c42 2022-08-19 op "<div class='dotted_line'></div>\n"
1168 01498c42 2022-08-19 op "<div id='blame'>\n",
1171 01498c42 2022-08-19 op if (r == -1)
1172 a596b957 2022-07-14 tracey goto done;
1174 a596b957 2022-07-14 tracey error = got_output_file_blame(c);
1175 a596b957 2022-07-14 tracey if (error)
1176 a596b957 2022-07-14 tracey goto done;
1178 01498c42 2022-08-19 op fcgi_printf(c, "</div>\n" /* #blame */
1179 01498c42 2022-08-19 op "</div>\n"); /* #blame_content */
1183 a596b957 2022-07-14 tracey return error;
1186 a596b957 2022-07-14 tracey static const struct got_error *
1187 a596b957 2022-07-14 tracey gotweb_render_briefs(struct request *c)
1189 a596b957 2022-07-14 tracey const struct got_error *error = NULL;
1190 a596b957 2022-07-14 tracey struct repo_commit *rc = NULL;
1191 a596b957 2022-07-14 tracey struct server *srv = c->srv;
1192 a596b957 2022-07-14 tracey struct transport *t = c->t;
1193 a596b957 2022-07-14 tracey struct querystring *qs = t->qs;
1194 a596b957 2022-07-14 tracey struct repo_dir *repo_dir = t->repo_dir;
1195 01498c42 2022-08-19 op const char *index_page_str;
1196 a596b957 2022-07-14 tracey char *smallerthan, *newline;
1197 d927f8c8 2022-08-20 op char *age = NULL, *author = NULL, *msg = NULL;
1200 01498c42 2022-08-19 op index_page_str = qs->index_page_str ? qs->index_page_str : "";
1202 01498c42 2022-08-19 op r = fcgi_printf(c, "<div id='briefs_title_wrapper'>\n"
1203 01498c42 2022-08-19 op "<div id='briefs_title'>Commit Briefs</div>\n"
1204 01498c42 2022-08-19 op "</div>\n" /* #briefs_title_wrapper */
1205 01498c42 2022-08-19 op "<div id='briefs_content'>\n");
1206 01498c42 2022-08-19 op if (r == -1)
1207 a596b957 2022-07-14 tracey goto done;
1209 a596b957 2022-07-14 tracey if (qs->action == SUMMARY) {
1210 a596b957 2022-07-14 tracey qs->action = BRIEFS;
1211 a596b957 2022-07-14 tracey error = got_get_repo_commits(c, D_MAXSLCOMMDISP);
1213 a596b957 2022-07-14 tracey error = got_get_repo_commits(c, srv->max_commits_display);
1214 a596b957 2022-07-14 tracey if (error)
1215 a596b957 2022-07-14 tracey goto done;
1217 a596b957 2022-07-14 tracey TAILQ_FOREACH(rc, &t->repo_commits, entry) {
1218 a596b957 2022-07-14 tracey error = gotweb_get_time_str(&age, rc->committer_time, TM_DIFF);
1219 a596b957 2022-07-14 tracey if (error)
1220 a596b957 2022-07-14 tracey goto done;
1222 a596b957 2022-07-14 tracey smallerthan = strchr(rc->author, '<');
1223 a596b957 2022-07-14 tracey if (smallerthan)
1224 a596b957 2022-07-14 tracey *smallerthan = '\0';
1226 a596b957 2022-07-14 tracey newline = strchr(rc->commit_msg, '\n');
1227 a596b957 2022-07-14 tracey if (newline)
1228 a596b957 2022-07-14 tracey *newline = '\0';
1230 d927f8c8 2022-08-20 op error = gotweb_escape_html(&author, rc->author);
1233 d927f8c8 2022-08-20 op error = gotweb_escape_html(&msg, rc->commit_msg);
1237 01498c42 2022-08-19 op r = fcgi_printf(c, "<div class='briefs_age'>%s</div>\n"
1238 01498c42 2022-08-19 op "<div class='briefs_author'>%s</div>\n"
1239 01498c42 2022-08-19 op "<div class='briefs_log'>"
1240 01498c42 2022-08-19 op "<a href='?index_page=%s&path=%s&action=diff&commit=%s"
1241 01498c42 2022-08-19 op "&headref=%s'>%s</a>",
1244 01498c42 2022-08-19 op index_page_str, repo_dir->name, rc->commit_id, qs->headref,
1246 01498c42 2022-08-19 op if (r == -1)
1247 a596b957 2022-07-14 tracey goto done;
1249 a596b957 2022-07-14 tracey if (rc->refs_str) {
1252 d927f8c8 2022-08-20 op error = gotweb_escape_html(&refs, rc->refs_str);
1255 01498c42 2022-08-19 op r = fcgi_printf(c,
1256 d927f8c8 2022-08-20 op " <span class='refs_str'>(%s)</span>", refs);
1258 01498c42 2022-08-19 op if (r == -1)
1259 a596b957 2022-07-14 tracey goto done;
1261 01498c42 2022-08-19 op if (fcgi_printf(c, "</div>\n") == -1) /* .briefs_log */
1262 a596b957 2022-07-14 tracey goto done;
1264 01498c42 2022-08-19 op r = fcgi_printf(c, "<div class='navs_wrapper'>\n"
1265 01498c42 2022-08-19 op "<div class='navs'>"
1266 01498c42 2022-08-19 op "<a href='?index_page=%s&path=%s&action=diff&commit=%s"
1267 01498c42 2022-08-19 op "&headref=%s'>diff</a>"
1269 01498c42 2022-08-19 op "<a href='?index_page=%s&path=%s&action=tree&commit=%s"
1270 01498c42 2022-08-19 op "&headref=%s'>tree</a>"
1271 01498c42 2022-08-19 op "</div>\n" /* .navs */
1272 01498c42 2022-08-19 op "</div>\n" /* .navs_wrapper */
1273 01498c42 2022-08-19 op "<div class='dotted_line'></div>\n",
1274 01498c42 2022-08-19 op index_page_str, repo_dir->name, rc->commit_id, qs->headref,
1275 01498c42 2022-08-19 op index_page_str, repo_dir->name, rc->commit_id, qs->headref);
1276 01498c42 2022-08-19 op if (r == -1)
1277 a596b957 2022-07-14 tracey goto done;
1279 a596b957 2022-07-14 tracey free(age);
1280 a596b957 2022-07-14 tracey age = NULL;
1281 d927f8c8 2022-08-20 op free(author);
1282 d927f8c8 2022-08-20 op author = NULL;
1287 a596b957 2022-07-14 tracey if (t->next_id || t->prev_id) {
1288 a596b957 2022-07-14 tracey error = gotweb_render_navs(c);
1289 a596b957 2022-07-14 tracey if (error)
1290 a596b957 2022-07-14 tracey goto done;
1292 01498c42 2022-08-19 op fcgi_printf(c, "</div>\n"); /* #briefs_content */
1294 a596b957 2022-07-14 tracey free(age);
1295 d927f8c8 2022-08-20 op free(author);
1297 a596b957 2022-07-14 tracey return error;
1300 a596b957 2022-07-14 tracey static const struct got_error *
1301 a596b957 2022-07-14 tracey gotweb_render_commits(struct request *c)
1303 a596b957 2022-07-14 tracey const struct got_error *error = NULL;
1304 a596b957 2022-07-14 tracey struct repo_commit *rc = NULL;
1305 a596b957 2022-07-14 tracey struct server *srv = c->srv;
1306 a596b957 2022-07-14 tracey struct transport *t = c->t;
1307 a596b957 2022-07-14 tracey struct querystring *qs = t->qs;
1308 a596b957 2022-07-14 tracey struct repo_dir *repo_dir = t->repo_dir;
1309 01498c42 2022-08-19 op const char *index_page_str;
1310 d927f8c8 2022-08-20 op char *age = NULL, *author = NULL, *msg = NULL;
1313 01498c42 2022-08-19 op index_page_str = qs->index_page_str ? qs->index_page_str : "";
1315 01498c42 2022-08-19 op r = fcgi_printf(c, "<div class='commits_title_wrapper'>\n"
1316 01498c42 2022-08-19 op "<div class='commits_title'>Commits</div>\n"
1317 01498c42 2022-08-19 op "</div>\n" /* .commits_title_wrapper */
1318 01498c42 2022-08-19 op "<div class='commits_content'>\n");
1319 01498c42 2022-08-19 op if (r == -1)
1320 a596b957 2022-07-14 tracey goto done;
1322 a596b957 2022-07-14 tracey error = got_get_repo_commits(c, srv->max_commits_display);
1323 a596b957 2022-07-14 tracey if (error)
1324 a596b957 2022-07-14 tracey goto done;
1326 a596b957 2022-07-14 tracey TAILQ_FOREACH(rc, &t->repo_commits, entry) {
1327 a596b957 2022-07-14 tracey error = gotweb_get_time_str(&age, rc->committer_time, TM_LONG);
1328 a596b957 2022-07-14 tracey if (error)
1329 a596b957 2022-07-14 tracey goto done;
1330 a596b957 2022-07-14 tracey error = gotweb_escape_html(&author, rc->author);
1331 a596b957 2022-07-14 tracey if (error)
1332 a596b957 2022-07-14 tracey goto done;
1333 d927f8c8 2022-08-20 op error = gotweb_escape_html(&msg, rc->commit_msg);
1337 01498c42 2022-08-19 op r = fcgi_printf(c, "<div class='commits_header_wrapper'>\n"
1338 01498c42 2022-08-19 op "<div class='commits_header'>\n"
1339 01498c42 2022-08-19 op "<div class='header_commit_title'>Commit:</div>\n"
1340 01498c42 2022-08-19 op "<div class='header_commit'>%s</div>\n"
1341 01498c42 2022-08-19 op "<div class='header_author_title'>Author:</div>\n"
1342 01498c42 2022-08-19 op "<div class='header_author'>%s</div>\n"
1343 01498c42 2022-08-19 op "<div class='header_age_title'>Date:</div>\n"
1344 01498c42 2022-08-19 op "<div class='header_age'>%s</div>\n"
1345 01498c42 2022-08-19 op "</div>\n" /* .commits_header */
1346 01498c42 2022-08-19 op "</div>\n" /* .commits_header_wrapper */
1347 01498c42 2022-08-19 op "<div class='dotted_line'></div>\n"
1348 01498c42 2022-08-19 op "<div class='commit'>\n%s</div>\n",
1349 01498c42 2022-08-19 op rc->commit_id,
1353 01498c42 2022-08-19 op if (r == -1)
1354 a596b957 2022-07-14 tracey goto done;
1356 01498c42 2022-08-19 op r = fcgi_printf(c, "<div class='navs_wrapper'>\n"
1357 01498c42 2022-08-19 op "<div class='navs'>"
1358 01498c42 2022-08-19 op "<a href='?index_page=%s&path=%s&action=diff&commit=%s'>"
1361 01498c42 2022-08-19 op "<a href='?index_page=%s&path=%s&action=tree&commit=%s'>"
1363 01498c42 2022-08-19 op "</div>\n" /* .navs */
1364 01498c42 2022-08-19 op "</div>\n" /* .navs_wrapper */
1365 01498c42 2022-08-19 op "<div class='dotted_line'></div>\n",
1366 01498c42 2022-08-19 op index_page_str, repo_dir->name, rc->commit_id,
1367 01498c42 2022-08-19 op index_page_str, repo_dir->name, rc->commit_id);
1368 8cf2cdaa 2022-09-01 op if (r == -1)
1371 a596b957 2022-07-14 tracey free(age);
1372 a596b957 2022-07-14 tracey age = NULL;
1373 a596b957 2022-07-14 tracey free(author);
1374 a596b957 2022-07-14 tracey author = NULL;
1379 a596b957 2022-07-14 tracey if (t->next_id || t->prev_id) {
1380 a596b957 2022-07-14 tracey error = gotweb_render_navs(c);
1381 a596b957 2022-07-14 tracey if (error)
1382 a596b957 2022-07-14 tracey goto done;
1384 01498c42 2022-08-19 op fcgi_printf(c, "</div>\n"); /* .commits_content */
1386 a596b957 2022-07-14 tracey free(age);
1387 d927f8c8 2022-08-20 op free(author);
1389 a596b957 2022-07-14 tracey return error;
1392 a596b957 2022-07-14 tracey static const struct got_error *
1393 a596b957 2022-07-14 tracey gotweb_render_branches(struct request *c)
1395 a596b957 2022-07-14 tracey const struct got_error *error = NULL;
1396 a596b957 2022-07-14 tracey struct got_reflist_head refs;
1397 a596b957 2022-07-14 tracey struct got_reflist_entry *re;
1398 a596b957 2022-07-14 tracey struct transport *t = c->t;
1399 a596b957 2022-07-14 tracey struct querystring *qs = t->qs;
1400 a596b957 2022-07-14 tracey struct got_repository *repo = t->repo;
1401 01498c42 2022-08-19 op const char *index_page_str;
1402 a596b957 2022-07-14 tracey char *age = NULL;
1405 01498c42 2022-08-19 op index_page_str = qs->index_page_str ? qs->index_page_str : "";
1407 a596b957 2022-07-14 tracey TAILQ_INIT(&refs);
1409 a596b957 2022-07-14 tracey error = got_ref_list(&refs, repo, "refs/heads",
1410 a596b957 2022-07-14 tracey got_ref_cmp_by_name, NULL);
1411 a596b957 2022-07-14 tracey if (error)
1412 a596b957 2022-07-14 tracey goto done;
1414 01498c42 2022-08-19 op r = fcgi_printf(c, "<div id='branches_title_wrapper'>\n"
1415 01498c42 2022-08-19 op "<div id='branches_title'>Branches</div>\n"
1416 01498c42 2022-08-19 op "</div>\n" /* #branches_title_wrapper */
1417 01498c42 2022-08-19 op "<div id='branches_content'>\n");
1418 01498c42 2022-08-19 op if (r == -1)
1419 a596b957 2022-07-14 tracey goto done;
1421 a596b957 2022-07-14 tracey TAILQ_FOREACH(re, &refs, entry) {
1422 d927f8c8 2022-08-20 op const char *refname = NULL;
1423 d927f8c8 2022-08-20 op char *escaped_refname = NULL;
1425 a596b957 2022-07-14 tracey if (got_ref_is_symbolic(re->ref))
1426 a596b957 2022-07-14 tracey continue;
1428 d927f8c8 2022-08-20 op refname = got_ref_get_name(re->ref);
1429 a596b957 2022-07-14 tracey if (refname == NULL) {
1430 a596b957 2022-07-14 tracey error = got_error_from_errno("strdup");
1431 a596b957 2022-07-14 tracey goto done;
1433 a596b957 2022-07-14 tracey if (strncmp(refname, "refs/heads/", 11) != 0)
1434 a596b957 2022-07-14 tracey continue;
1436 a596b957 2022-07-14 tracey error = got_get_repo_age(&age, c, qs->path, refname,
1437 a596b957 2022-07-14 tracey TM_DIFF);
1438 a596b957 2022-07-14 tracey if (error)
1439 a596b957 2022-07-14 tracey goto done;
1441 a596b957 2022-07-14 tracey if (strncmp(refname, "refs/heads/", 11) == 0)
1442 a596b957 2022-07-14 tracey refname += 11;
1443 d927f8c8 2022-08-20 op error = gotweb_escape_html(&escaped_refname, refname);
1447 01498c42 2022-08-19 op r = fcgi_printf(c, "<div class='branches_wrapper'>\n"
1448 01498c42 2022-08-19 op "<div class='branches_age'>%s</div>\n"
1449 01498c42 2022-08-19 op "<div class='branches_space'> </div>\n"
1450 01498c42 2022-08-19 op "<div class='branch'>"
1451 01498c42 2022-08-19 op "<a href='?index_page=%s&path=%s&action=summary&headref=%s'>"
1453 01498c42 2022-08-19 op "</div>\n" /* .branch */
1454 01498c42 2022-08-19 op "<div class='navs_wrapper'>\n"
1455 01498c42 2022-08-19 op "<div class='navs'>"
1456 01498c42 2022-08-19 op "<a href='?index_page=%s&path=%s&action=summary&headref=%s'>"
1457 01498c42 2022-08-19 op "summary</a>"
1459 01498c42 2022-08-19 op "<a href='?index_page=%s&path=%s&action=briefs&headref=%s'>"
1460 01498c42 2022-08-19 op "commit briefs</a>"
1462 01498c42 2022-08-19 op "<a href='?index_page=%s&path=%s&action=commits&headref=%s'>"
1463 01498c42 2022-08-19 op "commits</a>"
1464 01498c42 2022-08-19 op "</div>\n" /* .navs */
1465 01498c42 2022-08-19 op "</div>\n" /* .navs_wrapper */
1466 01498c42 2022-08-19 op "<div class='dotted_line'></div>\n"
1467 01498c42 2022-08-19 op "</div>\n", /* .branches_wrapper */
1468 01498c42 2022-08-19 op age ? age : "",
1469 01498c42 2022-08-19 op index_page_str, qs->path, refname,
1470 d927f8c8 2022-08-20 op escaped_refname,
1471 01498c42 2022-08-19 op index_page_str, qs->path, refname,
1472 01498c42 2022-08-19 op index_page_str, qs->path, refname,
1473 01498c42 2022-08-19 op index_page_str, qs->path, refname);
1474 d927f8c8 2022-08-20 op free(escaped_refname);
1475 01498c42 2022-08-19 op if (r == -1)
1476 a596b957 2022-07-14 tracey goto done;
1478 a596b957 2022-07-14 tracey free(age);
1479 a596b957 2022-07-14 tracey age = NULL;
1482 01498c42 2022-08-19 op fcgi_printf(c, "</div>\n"); /* #branches_content */
1485 f49cdcf5 2022-09-02 op got_ref_list_free(&refs);
1486 a596b957 2022-07-14 tracey return error;
1489 a596b957 2022-07-14 tracey static const struct got_error *
1490 a596b957 2022-07-14 tracey gotweb_render_tree(struct request *c)
1492 a596b957 2022-07-14 tracey const struct got_error *error = NULL;
1493 a596b957 2022-07-14 tracey struct transport *t = c->t;
1494 a596b957 2022-07-14 tracey struct repo_commit *rc = NULL;
1495 d927f8c8 2022-08-20 op char *age = NULL, *msg = NULL;
1498 a596b957 2022-07-14 tracey error = got_get_repo_commits(c, 1);
1499 a596b957 2022-07-14 tracey if (error)
1500 a596b957 2022-07-14 tracey return error;
1502 a596b957 2022-07-14 tracey rc = TAILQ_FIRST(&t->repo_commits);
1504 a596b957 2022-07-14 tracey error = gotweb_get_time_str(&age, rc->committer_time, TM_LONG);
1505 a596b957 2022-07-14 tracey if (error)
1506 a596b957 2022-07-14 tracey goto done;
1508 d927f8c8 2022-08-20 op error = gotweb_escape_html(&msg, rc->commit_msg);
1512 01498c42 2022-08-19 op r = fcgi_printf(c, "<div id='tree_title_wrapper'>\n"
1513 01498c42 2022-08-19 op "<div id='tree_title'>Tree</div>\n"
1514 01498c42 2022-08-19 op "</div>\n" /* #tree_title_wrapper */
1515 01498c42 2022-08-19 op "<div id='tree_content'>\n"
1516 01498c42 2022-08-19 op "<div id='tree_header_wrapper'>\n"
1517 01498c42 2022-08-19 op "<div id='tree_header'>\n"
1518 01498c42 2022-08-19 op "<div id='header_tree_title'>Tree:</div>\n"
1519 01498c42 2022-08-19 op "<div id='header_tree'>%s</div>\n"
1520 01498c42 2022-08-19 op "<div class='header_age_title'>Date:</div>\n"
1521 01498c42 2022-08-19 op "<div class='header_age'>%s</div>\n"
1522 01498c42 2022-08-19 op "<div id='header_commit_msg_title'>Message:</div>\n"
1523 01498c42 2022-08-19 op "<div id='header_commit_msg'>%s</div>\n"
1524 01498c42 2022-08-19 op "</div>\n" /* #tree_header */
1525 01498c42 2022-08-19 op "</div>\n" /* #tree_header_wrapper */
1526 01498c42 2022-08-19 op "<div class='dotted_line'></div>\n"
1527 01498c42 2022-08-19 op "<div id='tree'>\n",
1528 01498c42 2022-08-19 op rc->tree_id,
1531 01498c42 2022-08-19 op if (r == -1)
1532 a596b957 2022-07-14 tracey goto done;
1534 a596b957 2022-07-14 tracey error = got_output_repo_tree(c);
1535 a596b957 2022-07-14 tracey if (error)
1536 a596b957 2022-07-14 tracey goto done;
1538 01498c42 2022-08-19 op fcgi_printf(c, "</div>\n"); /* #tree */
1539 01498c42 2022-08-19 op fcgi_printf(c, "</div>\n"); /* #tree_content */
1543 a596b957 2022-07-14 tracey return error;
1546 a596b957 2022-07-14 tracey static const struct got_error *
1547 a596b957 2022-07-14 tracey gotweb_render_diff(struct request *c)
1549 a596b957 2022-07-14 tracey const struct got_error *error = NULL;
1550 a596b957 2022-07-14 tracey struct transport *t = c->t;
1551 a596b957 2022-07-14 tracey struct repo_commit *rc = NULL;
1552 d927f8c8 2022-08-20 op char *age = NULL, *author = NULL, *msg = NULL;
1555 a596b957 2022-07-14 tracey error = got_get_repo_commits(c, 1);
1556 a596b957 2022-07-14 tracey if (error)
1557 a596b957 2022-07-14 tracey return error;
1559 a596b957 2022-07-14 tracey rc = TAILQ_FIRST(&t->repo_commits);
1561 a596b957 2022-07-14 tracey error = gotweb_get_time_str(&age, rc->committer_time, TM_LONG);
1562 a596b957 2022-07-14 tracey if (error)
1563 a596b957 2022-07-14 tracey goto done;
1564 a596b957 2022-07-14 tracey error = gotweb_escape_html(&author, rc->author);
1565 a596b957 2022-07-14 tracey if (error)
1566 a596b957 2022-07-14 tracey goto done;
1567 d927f8c8 2022-08-20 op error = gotweb_escape_html(&msg, rc->commit_msg);
1571 01498c42 2022-08-19 op r = fcgi_printf(c, "<div id='diff_title_wrapper'>\n"
1572 01498c42 2022-08-19 op "<div id='diff_title'>Commit Diff</div>\n"
1573 01498c42 2022-08-19 op "</div>\n" /* #diff_title_wrapper */
1574 01498c42 2022-08-19 op "<div id='diff_content'>\n"
1575 01498c42 2022-08-19 op "<div id='diff_header_wrapper'>\n"
1576 01498c42 2022-08-19 op "<div id='diff_header'>\n"
1577 01498c42 2022-08-19 op "<div id='header_diff_title'>Diff:</div>\n"
1578 01498c42 2022-08-19 op "<div id='header_diff'>%s<br />%s</div>\n"
1579 01498c42 2022-08-19 op "<div class='header_commit_title'>Commit:</div>\n"
1580 01498c42 2022-08-19 op "<div class='header_commit'>%s</div>\n"
1581 01498c42 2022-08-19 op "<div id='header_tree_title'>Tree:</div>\n"
1582 01498c42 2022-08-19 op "<div id='header_tree'>%s</div>\n"
1583 01498c42 2022-08-19 op "<div class='header_author_title'>Author:</div>\n"
1584 01498c42 2022-08-19 op "<div class='header_author'>%s</div>\n"
1585 01498c42 2022-08-19 op "<div class='header_age_title'>Date:</div>\n"
1586 01498c42 2022-08-19 op "<div class='header_age'>%s</div>\n"
1587 01498c42 2022-08-19 op "<div id='header_commit_msg_title'>Message:</div>\n"
1588 01498c42 2022-08-19 op "<div id='header_commit_msg'>%s</div>\n"
1589 01498c42 2022-08-19 op "</div>\n" /* #diff_header */
1590 01498c42 2022-08-19 op "</div>\n" /* #diff_header_wrapper */
1591 01498c42 2022-08-19 op "<div class='dotted_line'></div>\n"
1592 01498c42 2022-08-19 op "<div id='diff'>\n",
1593 01498c42 2022-08-19 op rc->parent_id, rc->commit_id,
1594 01498c42 2022-08-19 op rc->commit_id,
1595 01498c42 2022-08-19 op rc->tree_id,
1599 01498c42 2022-08-19 op if (r == -1)
1600 a596b957 2022-07-14 tracey goto done;
1602 a596b957 2022-07-14 tracey error = got_output_repo_diff(c);
1603 a596b957 2022-07-14 tracey if (error)
1604 a596b957 2022-07-14 tracey goto done;
1606 01498c42 2022-08-19 op fcgi_printf(c, "</div>\n"); /* #diff */
1607 01498c42 2022-08-19 op fcgi_printf(c, "</div>\n"); /* #diff_content */
1609 a596b957 2022-07-14 tracey free(age);
1610 a596b957 2022-07-14 tracey free(author);
1612 a596b957 2022-07-14 tracey return error;
1615 a596b957 2022-07-14 tracey static const struct got_error *
1616 a596b957 2022-07-14 tracey gotweb_render_summary(struct request *c)
1618 a596b957 2022-07-14 tracey const struct got_error *error = NULL;
1619 a596b957 2022-07-14 tracey struct transport *t = c->t;
1620 a596b957 2022-07-14 tracey struct server *srv = c->srv;
1623 01498c42 2022-08-19 op if (fcgi_printf(c, "<div id='summary_wrapper'>\n") == -1)
1624 a596b957 2022-07-14 tracey goto done;
1626 01498c42 2022-08-19 op if (srv->show_repo_description) {
1627 01498c42 2022-08-19 op r = fcgi_printf(c,
1628 01498c42 2022-08-19 op "<div id='description_title'>Description:</div>\n"
1629 01498c42 2022-08-19 op "<div id='description'>%s</div>\n",
1630 f897bb24 2022-08-20 op t->repo_dir->description ? t->repo_dir->description : "");
1631 01498c42 2022-08-19 op if (r == -1)
1635 01498c42 2022-08-19 op if (srv->show_repo_owner) {
1636 01498c42 2022-08-19 op r = fcgi_printf(c,
1637 01498c42 2022-08-19 op "<div id='repo_owner_title'>Owner:</div>\n"
1638 01498c42 2022-08-19 op "<div id='repo_owner'>%s</div>\n",
1639 f897bb24 2022-08-20 op t->repo_dir->owner ? t->repo_dir->owner : "");
1640 01498c42 2022-08-19 op if (r == -1)
1644 01498c42 2022-08-19 op if (srv->show_repo_age) {
1645 01498c42 2022-08-19 op r = fcgi_printf(c,
1646 01498c42 2022-08-19 op "<div id='last_change_title'>Last Change:</div>\n"
1647 01498c42 2022-08-19 op "<div id='last_change'>%s</div>\n",
1648 01498c42 2022-08-19 op t->repo_dir->age);
1649 01498c42 2022-08-19 op if (r == -1)
1653 01498c42 2022-08-19 op if (srv->show_repo_cloneurl) {
1654 01498c42 2022-08-19 op r = fcgi_printf(c,
1655 01498c42 2022-08-19 op "<div id='cloneurl_title'>Clone URL:</div>\n"
1656 01498c42 2022-08-19 op "<div id='cloneurl'>%s</div>\n",
1657 01498c42 2022-08-19 op t->repo_dir->url ? t->repo_dir->url : "");
1658 01498c42 2022-08-19 op if (r == -1)
1662 01498c42 2022-08-19 op r = fcgi_printf(c, "</div>\n"); /* #summary_wrapper */
1663 01498c42 2022-08-19 op if (r == -1)
1664 a596b957 2022-07-14 tracey goto done;
1666 a596b957 2022-07-14 tracey error = gotweb_render_briefs(c);
1667 a596b957 2022-07-14 tracey if (error) {
1668 a596b957 2022-07-14 tracey log_warnx("%s: %s", __func__, error->msg);
1669 a596b957 2022-07-14 tracey goto done;
1672 a596b957 2022-07-14 tracey error = gotweb_render_tags(c);
1673 a596b957 2022-07-14 tracey if (error) {
1674 a596b957 2022-07-14 tracey log_warnx("%s: %s", __func__, error->msg);
1675 a596b957 2022-07-14 tracey goto done;
1678 a596b957 2022-07-14 tracey error = gotweb_render_branches(c);
1679 a596b957 2022-07-14 tracey if (error)
1680 a596b957 2022-07-14 tracey log_warnx("%s: %s", __func__, error->msg);
1682 a596b957 2022-07-14 tracey return error;
1685 a596b957 2022-07-14 tracey static const struct got_error *
1686 a596b957 2022-07-14 tracey gotweb_render_tag(struct request *c)
1688 a596b957 2022-07-14 tracey const struct got_error *error = NULL;
1689 a596b957 2022-07-14 tracey struct repo_tag *rt = NULL;
1690 a596b957 2022-07-14 tracey struct transport *t = c->t;
1691 d927f8c8 2022-08-20 op char *tagname = NULL, *age = NULL, *author = NULL, *msg = NULL;
1693 a596b957 2022-07-14 tracey error = got_get_repo_tags(c, 1);
1694 a596b957 2022-07-14 tracey if (error)
1695 a596b957 2022-07-14 tracey goto done;
1697 a596b957 2022-07-14 tracey if (t->tag_count == 0) {
1698 a596b957 2022-07-14 tracey error = got_error_set_errno(GOT_ERR_BAD_OBJ_ID,
1699 a596b957 2022-07-14 tracey "bad commit id");
1700 a596b957 2022-07-14 tracey goto done;
1703 a596b957 2022-07-14 tracey rt = TAILQ_LAST(&t->repo_tags, repo_tags_head);
1705 a596b957 2022-07-14 tracey error = gotweb_get_time_str(&age, rt->tagger_time, TM_LONG);
1706 a596b957 2022-07-14 tracey if (error)
1707 a596b957 2022-07-14 tracey goto done;
1708 a596b957 2022-07-14 tracey error = gotweb_escape_html(&author, rt->tagger);
1709 a596b957 2022-07-14 tracey if (error)
1710 a596b957 2022-07-14 tracey goto done;
1711 d927f8c8 2022-08-20 op error = gotweb_escape_html(&msg, rt->commit_msg);
1715 5fba0750 2022-09-01 stsp tagname = rt->tag_name;
1716 5fba0750 2022-09-01 stsp if (strncmp(tagname, "refs/", 5) == 0)
1717 5fba0750 2022-09-01 stsp tagname += 5;
1718 5fba0750 2022-09-01 stsp error = gotweb_escape_html(&tagname, tagname);
1722 01498c42 2022-08-19 op fcgi_printf(c, "<div id='tags_title_wrapper'>\n"
1723 01498c42 2022-08-19 op "<div id='tags_title'>Tag</div>\n"
1724 01498c42 2022-08-19 op "</div>\n" /* #tags_title_wrapper */
1725 01498c42 2022-08-19 op "<div id='tags_content'>\n"
1726 01498c42 2022-08-19 op "<div id='tag_header_wrapper'>\n"
1727 01498c42 2022-08-19 op "<div id='tag_header'>\n"
1728 01498c42 2022-08-19 op "<div class='header_commit_title'>Commit:</div>\n"
1729 01498c42 2022-08-19 op "<div class='header_commit'>%s"
1730 01498c42 2022-08-19 op " <span class='refs_str'>(%s)</span></div>\n"
1731 01498c42 2022-08-19 op "<div class='header_author_title'>Tagger:</div>\n"
1732 01498c42 2022-08-19 op "<div class='header_author'>%s</div>\n"
1733 01498c42 2022-08-19 op "<div class='header_age_title'>Date:</div>\n"
1734 01498c42 2022-08-19 op "<div class='header_age'>%s</div>\n"
1735 01498c42 2022-08-19 op "<div id='header_commit_msg_title'>Message:</div>\n"
1736 01498c42 2022-08-19 op "<div id='header_commit_msg'>%s</div>\n"
1737 01498c42 2022-08-19 op "</div>\n" /* #tag_header */
1738 01498c42 2022-08-19 op "<div class='dotted_line'></div>\n"
1739 01498c42 2022-08-19 op "<div id='tag_commit'>\n%s</div>"
1740 01498c42 2022-08-19 op "</div>", /* tag_header_wrapper */
1741 01498c42 2022-08-19 op rt->commit_id,
1746 01498c42 2022-08-19 op rt->tag_commit);
1749 a596b957 2022-07-14 tracey free(age);
1750 a596b957 2022-07-14 tracey free(author);
1752 a596b957 2022-07-14 tracey return error;
1755 a596b957 2022-07-14 tracey static const struct got_error *
1756 a596b957 2022-07-14 tracey gotweb_render_tags(struct request *c)
1758 a596b957 2022-07-14 tracey const struct got_error *error = NULL;
1759 a596b957 2022-07-14 tracey struct repo_tag *rt = NULL;
1760 a596b957 2022-07-14 tracey struct server *srv = c->srv;
1761 a596b957 2022-07-14 tracey struct transport *t = c->t;
1762 a596b957 2022-07-14 tracey struct querystring *qs = t->qs;
1763 a596b957 2022-07-14 tracey struct repo_dir *repo_dir = t->repo_dir;
1764 01498c42 2022-08-19 op const char *index_page_str;
1765 d927f8c8 2022-08-20 op char *age = NULL, *tagname = NULL, *msg = NULL, *newline;
1766 01498c42 2022-08-19 op int r, commit_found = 0;
1768 01498c42 2022-08-19 op index_page_str = qs->index_page_str ? qs->index_page_str : "";
1770 a596b957 2022-07-14 tracey if (qs->action == BRIEFS) {
1771 a596b957 2022-07-14 tracey qs->action = TAGS;
1772 a596b957 2022-07-14 tracey error = got_get_repo_tags(c, D_MAXSLCOMMDISP);
1774 a596b957 2022-07-14 tracey error = got_get_repo_tags(c, srv->max_commits_display);
1775 a596b957 2022-07-14 tracey if (error)
1776 a596b957 2022-07-14 tracey goto done;
1778 01498c42 2022-08-19 op r = fcgi_printf(c, "<div id='tags_title_wrapper'>\n"
1779 01498c42 2022-08-19 op "<div id='tags_title'>Tags</div>\n"
1780 01498c42 2022-08-19 op "</div>\n" /* #tags_title_wrapper */
1781 01498c42 2022-08-19 op "<div id='tags_content'>\n");
1782 01498c42 2022-08-19 op if (r == -1)
1783 a596b957 2022-07-14 tracey goto done;
1785 a596b957 2022-07-14 tracey if (t->tag_count == 0) {
1786 01498c42 2022-08-19 op r = fcgi_printf(c, "<div id='err_content'>%s\n</div>\n",
1787 01498c42 2022-08-19 op "This repository contains no tags");
1788 01498c42 2022-08-19 op if (r == -1)
1789 a596b957 2022-07-14 tracey goto done;
1792 a596b957 2022-07-14 tracey TAILQ_FOREACH(rt, &t->repo_tags, entry) {
1793 a596b957 2022-07-14 tracey if (commit_found == 0 && qs->commit != NULL) {
1794 a596b957 2022-07-14 tracey if (strcmp(qs->commit, rt->commit_id) != 0)
1795 a596b957 2022-07-14 tracey continue;
1797 a596b957 2022-07-14 tracey commit_found = 1;
1799 a596b957 2022-07-14 tracey error = gotweb_get_time_str(&age, rt->tagger_time, TM_DIFF);
1800 a596b957 2022-07-14 tracey if (error)
1801 a596b957 2022-07-14 tracey goto done;
1803 5fba0750 2022-09-01 stsp tagname = rt->tag_name;
1804 5fba0750 2022-09-01 stsp if (strncmp(tagname, "refs/tags/", 10) == 0)
1805 5fba0750 2022-09-01 stsp tagname += 10;
1806 5fba0750 2022-09-01 stsp error = gotweb_escape_html(&tagname, tagname);
1810 a596b957 2022-07-14 tracey if (rt->tag_commit != NULL) {
1811 a596b957 2022-07-14 tracey newline = strchr(rt->tag_commit, '\n');
1812 a596b957 2022-07-14 tracey if (newline)
1813 a596b957 2022-07-14 tracey *newline = '\0';
1814 d927f8c8 2022-08-20 op error = gotweb_escape_html(&msg, rt->tag_commit);
1819 01498c42 2022-08-19 op r = fcgi_printf(c, "<div class='tag_age'>%s</div>\n"
1820 01498c42 2022-08-19 op "<div class='tag'>%s</div>\n"
1821 01498c42 2022-08-19 op "<div class='tag_log'>"
1822 01498c42 2022-08-19 op "<a href='?index_page=%s&path=%s&action=tag&commit=%s'>"
1824 01498c42 2022-08-19 op "</div>\n" /* .tag_log */
1825 01498c42 2022-08-19 op "<div class='navs_wrapper'>\n"
1826 01498c42 2022-08-19 op "<div class='navs'>"
1827 01498c42 2022-08-19 op "<a href='?index_page=%s&path=%s&action=tag&commit=%s'>"
1830 01498c42 2022-08-19 op "<a href='?index_page=%s&path=%s&action=briefs&commit=%s'>"
1831 01498c42 2022-08-19 op "commit briefs</a>"
1833 01498c42 2022-08-19 op "<a href='?index_page=%s&path=%s&action=commits&commit=%s'>"
1834 01498c42 2022-08-19 op "commits</a>"
1835 01498c42 2022-08-19 op "</div>\n" /* .navs */
1836 01498c42 2022-08-19 op "</div>\n" /* .navs_wrapper */
1837 01498c42 2022-08-19 op "<div class='dotted_line'></div>\n",
1840 01498c42 2022-08-19 op index_page_str, repo_dir->name, rt->commit_id,
1841 d927f8c8 2022-08-20 op msg ? msg : "",
1842 01498c42 2022-08-19 op index_page_str, repo_dir->name, rt->commit_id,
1843 01498c42 2022-08-19 op index_page_str, repo_dir->name, rt->commit_id,
1844 01498c42 2022-08-19 op index_page_str, repo_dir->name, rt->commit_id);
1845 01498c42 2022-08-19 op if (r == -1)
1846 a596b957 2022-07-14 tracey goto done;
1848 a596b957 2022-07-14 tracey free(age);
1849 a596b957 2022-07-14 tracey age = NULL;
1850 d927f8c8 2022-08-20 op free(tagname);
1851 d927f8c8 2022-08-20 op tagname = NULL;
1855 a596b957 2022-07-14 tracey if (t->next_id || t->prev_id) {
1856 a596b957 2022-07-14 tracey error = gotweb_render_navs(c);
1857 a596b957 2022-07-14 tracey if (error)
1858 a596b957 2022-07-14 tracey goto done;
1860 01498c42 2022-08-19 op fcgi_printf(c, "</div>\n"); /* #tags_content */
1862 a596b957 2022-07-14 tracey free(age);
1863 d927f8c8 2022-08-20 op free(tagname);
1865 a596b957 2022-07-14 tracey return error;
1868 a596b957 2022-07-14 tracey const struct got_error *
1869 a596b957 2022-07-14 tracey gotweb_escape_html(char **escaped_html, const char *orig_html)
1871 a596b957 2022-07-14 tracey const struct got_error *error = NULL;
1872 a596b957 2022-07-14 tracey struct escape_pair {
1874 a596b957 2022-07-14 tracey const char *s;
1875 a596b957 2022-07-14 tracey } esc[] = {
1876 a596b957 2022-07-14 tracey { '>', ">" },
1877 a596b957 2022-07-14 tracey { '<', "<" },
1878 a596b957 2022-07-14 tracey { '&', "&" },
1879 a596b957 2022-07-14 tracey { '"', """ },
1880 a596b957 2022-07-14 tracey { '\'', "'" },
1881 a596b957 2022-07-14 tracey { '\n', "<br />" },
1883 a596b957 2022-07-14 tracey size_t orig_len, len;
1884 a596b957 2022-07-14 tracey int i, j, x;
1886 a596b957 2022-07-14 tracey orig_len = strlen(orig_html);
1887 a596b957 2022-07-14 tracey len = orig_len;
1888 a596b957 2022-07-14 tracey for (i = 0; i < orig_len; i++) {
1889 a596b957 2022-07-14 tracey for (j = 0; j < nitems(esc); j++) {
1890 a596b957 2022-07-14 tracey if (orig_html[i] != esc[j].c)
1891 a596b957 2022-07-14 tracey continue;
1892 a596b957 2022-07-14 tracey len += strlen(esc[j].s) - 1 /* escaped char */;
1896 a596b957 2022-07-14 tracey *escaped_html = calloc(len + 1 /* NUL */, sizeof(**escaped_html));
1897 a596b957 2022-07-14 tracey if (*escaped_html == NULL)
1898 a596b957 2022-07-14 tracey return got_error_from_errno("calloc");
1901 a596b957 2022-07-14 tracey for (i = 0; i < orig_len; i++) {
1902 a596b957 2022-07-14 tracey int escaped = 0;
1903 a596b957 2022-07-14 tracey for (j = 0; j < nitems(esc); j++) {
1904 a596b957 2022-07-14 tracey if (orig_html[i] != esc[j].c)
1905 a596b957 2022-07-14 tracey continue;
1907 a596b957 2022-07-14 tracey if (strlcat(*escaped_html, esc[j].s, len + 1)
1908 a596b957 2022-07-14 tracey >= len + 1) {
1909 a596b957 2022-07-14 tracey error = got_error(GOT_ERR_NO_SPACE);
1910 a596b957 2022-07-14 tracey goto done;
1912 a596b957 2022-07-14 tracey x += strlen(esc[j].s);
1913 a596b957 2022-07-14 tracey escaped = 1;
1916 a596b957 2022-07-14 tracey if (!escaped) {
1917 a596b957 2022-07-14 tracey (*escaped_html)[x] = orig_html[i];
1922 a596b957 2022-07-14 tracey if (error) {
1923 a596b957 2022-07-14 tracey free(*escaped_html);
1924 a596b957 2022-07-14 tracey *escaped_html = NULL;
1925 a596b957 2022-07-14 tracey } else {
1926 a596b957 2022-07-14 tracey (*escaped_html)[x] = '\0';
1929 a596b957 2022-07-14 tracey return error;
1932 b5c757f5 2022-09-01 stsp static struct got_repository *
1933 b5c757f5 2022-09-01 stsp find_cached_repo(struct server *srv, const char *path)
1937 b5c757f5 2022-09-01 stsp for (i = 0; i < srv->ncached_repos; i++) {
1938 b5c757f5 2022-09-01 stsp if (strcmp(srv->cached_repos[i].path, path) == 0)
1939 b5c757f5 2022-09-01 stsp return srv->cached_repos[i].repo;
1942 b5c757f5 2022-09-01 stsp return NULL;
1945 a596b957 2022-07-14 tracey static const struct got_error *
1946 b5c757f5 2022-09-01 stsp cache_repo(struct got_repository **new, struct server *srv,
1947 b5c757f5 2022-09-01 stsp struct repo_dir *repo_dir, struct socket *sock)
1949 b5c757f5 2022-09-01 stsp const struct got_error *error = NULL;
1950 b5c757f5 2022-09-01 stsp struct got_repository *repo;
1951 b5c757f5 2022-09-01 stsp struct cached_repo *cr;
1952 b5c757f5 2022-09-01 stsp int evicted = 0;
1954 b5c757f5 2022-09-01 stsp if (srv->ncached_repos >= nitems(srv->cached_repos)) {
1955 b5c757f5 2022-09-01 stsp cr = &srv->cached_repos[srv->ncached_repos - 1];
1956 b5c757f5 2022-09-01 stsp error = got_repo_close(cr->repo);
1957 b5c757f5 2022-09-01 stsp memset(cr, 0, sizeof(*cr));
1958 b5c757f5 2022-09-01 stsp srv->ncached_repos--;
1959 b5c757f5 2022-09-01 stsp if (error)
1960 b5c757f5 2022-09-01 stsp return error;
1961 b5c757f5 2022-09-01 stsp memmove(&srv->cached_repos[1], &srv->cached_repos[0],
1962 b5c757f5 2022-09-01 stsp srv->ncached_repos * sizeof(srv->cached_repos[0]));
1963 b5c757f5 2022-09-01 stsp cr = &srv->cached_repos[0];
1964 b5c757f5 2022-09-01 stsp evicted = 1;
1966 b5c757f5 2022-09-01 stsp cr = &srv->cached_repos[srv->ncached_repos];
1969 b5c757f5 2022-09-01 stsp error = got_repo_open(&repo, repo_dir->path, NULL, sock->pack_fds);
1970 b5c757f5 2022-09-01 stsp if (error) {
1971 b5c757f5 2022-09-01 stsp if (evicted) {
1972 b5c757f5 2022-09-01 stsp memmove(&srv->cached_repos[0], &srv->cached_repos[1],
1973 b5c757f5 2022-09-01 stsp srv->ncached_repos * sizeof(srv->cached_repos[0]));
1975 b5c757f5 2022-09-01 stsp return error;
1978 b5c757f5 2022-09-01 stsp if (strlcpy(cr->path, repo_dir->path, sizeof(cr->path))
1979 b5c757f5 2022-09-01 stsp >= sizeof(cr->path)) {
1980 b5c757f5 2022-09-01 stsp if (evicted) {
1981 b5c757f5 2022-09-01 stsp memmove(&srv->cached_repos[0], &srv->cached_repos[1],
1982 b5c757f5 2022-09-01 stsp srv->ncached_repos * sizeof(srv->cached_repos[0]));
1984 b5c757f5 2022-09-01 stsp return got_error(GOT_ERR_NO_SPACE);
1987 b5c757f5 2022-09-01 stsp cr->repo = repo;
1988 b5c757f5 2022-09-01 stsp srv->ncached_repos++;
1989 b5c757f5 2022-09-01 stsp *new = repo;
1990 b5c757f5 2022-09-01 stsp return NULL;
1993 b5c757f5 2022-09-01 stsp static const struct got_error *
1994 a596b957 2022-07-14 tracey gotweb_load_got_path(struct request *c, struct repo_dir *repo_dir)
1996 a596b957 2022-07-14 tracey const struct got_error *error = NULL;
1997 a596b957 2022-07-14 tracey struct socket *sock = c->sock;
1998 a596b957 2022-07-14 tracey struct server *srv = c->srv;
1999 a596b957 2022-07-14 tracey struct transport *t = c->t;
2000 b5c757f5 2022-09-01 stsp struct got_repository *repo = NULL;
2001 a596b957 2022-07-14 tracey DIR *dt;
2002 a596b957 2022-07-14 tracey char *dir_test;
2004 a596b957 2022-07-14 tracey if (asprintf(&dir_test, "%s/%s/%s", srv->repos_path, repo_dir->name,
2005 a596b957 2022-07-14 tracey GOTWEB_GIT_DIR) == -1)
2006 a596b957 2022-07-14 tracey return got_error_from_errno("asprintf");
2008 a596b957 2022-07-14 tracey dt = opendir(dir_test);
2009 a596b957 2022-07-14 tracey if (dt == NULL) {
2010 a596b957 2022-07-14 tracey free(dir_test);
2011 a596b957 2022-07-14 tracey } else {
2012 0fad85dd 2022-09-01 op repo_dir->path = dir_test;
2013 a596b957 2022-07-14 tracey dir_test = NULL;
2017 a596b957 2022-07-14 tracey if (asprintf(&dir_test, "%s/%s", srv->repos_path,
2018 0fad85dd 2022-09-01 op repo_dir->name) == -1)
2019 0fad85dd 2022-09-01 op return got_error_from_errno("asprintf");
2021 a596b957 2022-07-14 tracey dt = opendir(dir_test);
2022 a596b957 2022-07-14 tracey if (dt == NULL) {
2023 a596b957 2022-07-14 tracey error = got_error_path(repo_dir->name, GOT_ERR_NOT_GIT_REPO);
2024 a596b957 2022-07-14 tracey goto err;
2026 0fad85dd 2022-09-01 op repo_dir->path = dir_test;
2027 0fad85dd 2022-09-01 op dir_test = NULL;
2031 b5c757f5 2022-09-01 stsp repo = find_cached_repo(srv, repo_dir->path);
2032 b5c757f5 2022-09-01 stsp if (repo == NULL) {
2033 b5c757f5 2022-09-01 stsp error = cache_repo(&repo, srv, repo_dir, sock);
2034 b5c757f5 2022-09-01 stsp if (error)
2037 b5c757f5 2022-09-01 stsp t->repo = repo;
2038 a596b957 2022-07-14 tracey error = gotweb_get_repo_description(&repo_dir->description, srv,
2039 a596b957 2022-07-14 tracey repo_dir->path);
2040 a596b957 2022-07-14 tracey if (error)
2041 a596b957 2022-07-14 tracey goto err;
2042 a596b957 2022-07-14 tracey error = got_get_repo_owner(&repo_dir->owner, c, repo_dir->path);
2043 a596b957 2022-07-14 tracey if (error)
2044 a596b957 2022-07-14 tracey goto err;
2045 a596b957 2022-07-14 tracey error = got_get_repo_age(&repo_dir->age, c, repo_dir->path,
2046 a596b957 2022-07-14 tracey NULL, TM_DIFF);
2047 a596b957 2022-07-14 tracey if (error)
2048 a596b957 2022-07-14 tracey goto err;
2049 a596b957 2022-07-14 tracey error = gotweb_get_clone_url(&repo_dir->url, srv, repo_dir->path);
2051 a596b957 2022-07-14 tracey free(dir_test);
2052 0fad85dd 2022-09-01 op if (dt != NULL && closedir(dt) == EOF && error == NULL)
2053 0fad85dd 2022-09-01 op error = got_error_from_errno("closedir");
2054 a596b957 2022-07-14 tracey return error;
2057 a596b957 2022-07-14 tracey static const struct got_error *
2058 a596b957 2022-07-14 tracey gotweb_init_repo_dir(struct repo_dir **repo_dir, const char *dir)
2060 a596b957 2022-07-14 tracey const struct got_error *error;
2062 a596b957 2022-07-14 tracey *repo_dir = calloc(1, sizeof(**repo_dir));
2063 a596b957 2022-07-14 tracey if (*repo_dir == NULL)
2064 a596b957 2022-07-14 tracey return got_error_from_errno("calloc");
2066 a596b957 2022-07-14 tracey if (asprintf(&(*repo_dir)->name, "%s", dir) == -1) {
2067 a596b957 2022-07-14 tracey error = got_error_from_errno("asprintf");
2068 a596b957 2022-07-14 tracey free(*repo_dir);
2069 a596b957 2022-07-14 tracey *repo_dir = NULL;
2070 a596b957 2022-07-14 tracey return error;
2072 a596b957 2022-07-14 tracey (*repo_dir)->owner = NULL;
2073 a596b957 2022-07-14 tracey (*repo_dir)->description = NULL;
2074 a596b957 2022-07-14 tracey (*repo_dir)->url = NULL;
2075 a596b957 2022-07-14 tracey (*repo_dir)->age = NULL;
2076 a596b957 2022-07-14 tracey (*repo_dir)->path = NULL;
2078 a596b957 2022-07-14 tracey return NULL;
2081 a596b957 2022-07-14 tracey static const struct got_error *
2082 a596b957 2022-07-14 tracey gotweb_get_repo_description(char **description, struct server *srv, char *dir)
2084 a596b957 2022-07-14 tracey const struct got_error *error = NULL;
2085 a596b957 2022-07-14 tracey FILE *f = NULL;
2086 a596b957 2022-07-14 tracey char *d_file = NULL;
2087 a596b957 2022-07-14 tracey unsigned int len;
2088 a596b957 2022-07-14 tracey size_t n;
2090 a596b957 2022-07-14 tracey *description = NULL;
2091 a596b957 2022-07-14 tracey if (srv->show_repo_description == 0)
2092 a596b957 2022-07-14 tracey return NULL;
2094 a596b957 2022-07-14 tracey if (asprintf(&d_file, "%s/description", dir) == -1)
2095 a596b957 2022-07-14 tracey return got_error_from_errno("asprintf");
2097 a596b957 2022-07-14 tracey f = fopen(d_file, "r");
2098 a596b957 2022-07-14 tracey if (f == NULL) {
2099 89ae185c 2022-09-01 op if (errno != ENOENT && errno != EACCES)
2100 89ae185c 2022-09-01 op error = got_error_from_errno2("fopen", d_file);
2101 a596b957 2022-07-14 tracey goto done;
2104 a596b957 2022-07-14 tracey if (fseek(f, 0, SEEK_END) == -1) {
2105 a596b957 2022-07-14 tracey error = got_ferror(f, GOT_ERR_IO);
2106 a596b957 2022-07-14 tracey goto done;
2108 a596b957 2022-07-14 tracey len = ftell(f);
2109 a596b957 2022-07-14 tracey if (len == -1) {
2110 a596b957 2022-07-14 tracey error = got_ferror(f, GOT_ERR_IO);
2111 a596b957 2022-07-14 tracey goto done;
2114 1999985f 2022-08-30 tracey if (len == 0) {
2115 1999985f 2022-08-30 tracey *description = strdup("");
2116 1999985f 2022-08-30 tracey if (*description == NULL)
2117 89ae185c 2022-09-01 op error = got_error_from_errno("strdup");
2118 a596b957 2022-07-14 tracey goto done;
2121 a596b957 2022-07-14 tracey if (fseek(f, 0, SEEK_SET) == -1) {
2122 a596b957 2022-07-14 tracey error = got_ferror(f, GOT_ERR_IO);
2123 a596b957 2022-07-14 tracey goto done;
2125 a596b957 2022-07-14 tracey *description = calloc(len + 1, sizeof(**description));
2126 a596b957 2022-07-14 tracey if (*description == NULL) {
2127 a596b957 2022-07-14 tracey error = got_error_from_errno("calloc");
2128 a596b957 2022-07-14 tracey goto done;
2131 a596b957 2022-07-14 tracey n = fread(*description, 1, len, f);
2132 a596b957 2022-07-14 tracey if (n == 0 && ferror(f))
2133 a596b957 2022-07-14 tracey error = got_ferror(f, GOT_ERR_IO);
2135 a596b957 2022-07-14 tracey if (f != NULL && fclose(f) == EOF && error == NULL)
2136 a596b957 2022-07-14 tracey error = got_error_from_errno("fclose");
2137 a596b957 2022-07-14 tracey free(d_file);
2138 a596b957 2022-07-14 tracey return error;
2141 a596b957 2022-07-14 tracey static const struct got_error *
2142 a596b957 2022-07-14 tracey gotweb_get_clone_url(char **url, struct server *srv, char *dir)
2144 a596b957 2022-07-14 tracey const struct got_error *error = NULL;
2145 a596b957 2022-07-14 tracey FILE *f;
2146 a596b957 2022-07-14 tracey char *d_file = NULL;
2147 a596b957 2022-07-14 tracey unsigned int len;
2148 a596b957 2022-07-14 tracey size_t n;
2150 a596b957 2022-07-14 tracey *url = NULL;
2152 a596b957 2022-07-14 tracey if (srv->show_repo_cloneurl == 0)
2153 a596b957 2022-07-14 tracey return NULL;
2155 a596b957 2022-07-14 tracey if (asprintf(&d_file, "%s/cloneurl", dir) == -1)
2156 a596b957 2022-07-14 tracey return got_error_from_errno("asprintf");
2158 a596b957 2022-07-14 tracey f = fopen(d_file, "r");
2159 a596b957 2022-07-14 tracey if (f == NULL) {
2160 a596b957 2022-07-14 tracey if (errno != ENOENT && errno != EACCES)
2161 a596b957 2022-07-14 tracey error = got_error_from_errno2("fopen", d_file);
2162 a596b957 2022-07-14 tracey goto done;
2165 a596b957 2022-07-14 tracey if (fseek(f, 0, SEEK_END) == -1) {
2166 a596b957 2022-07-14 tracey error = got_ferror(f, GOT_ERR_IO);
2167 a596b957 2022-07-14 tracey goto done;
2169 a596b957 2022-07-14 tracey len = ftell(f);
2170 a596b957 2022-07-14 tracey if (len == -1) {
2171 a596b957 2022-07-14 tracey error = got_ferror(f, GOT_ERR_IO);
2172 a596b957 2022-07-14 tracey goto done;
2174 a596b957 2022-07-14 tracey if (len == 0)
2175 a596b957 2022-07-14 tracey goto done;
2177 a596b957 2022-07-14 tracey if (fseek(f, 0, SEEK_SET) == -1) {
2178 a596b957 2022-07-14 tracey error = got_ferror(f, GOT_ERR_IO);
2179 a596b957 2022-07-14 tracey goto done;
2182 a596b957 2022-07-14 tracey *url = calloc(len + 1, sizeof(**url));
2183 a596b957 2022-07-14 tracey if (*url == NULL) {
2184 a596b957 2022-07-14 tracey error = got_error_from_errno("calloc");
2185 a596b957 2022-07-14 tracey goto done;
2188 a596b957 2022-07-14 tracey n = fread(*url, 1, len, f);
2189 a596b957 2022-07-14 tracey if (n == 0 && ferror(f))
2190 a596b957 2022-07-14 tracey error = got_ferror(f, GOT_ERR_IO);
2192 a596b957 2022-07-14 tracey if (f != NULL && fclose(f) == EOF && error == NULL)
2193 a596b957 2022-07-14 tracey error = got_error_from_errno("fclose");
2194 a596b957 2022-07-14 tracey free(d_file);
2195 a596b957 2022-07-14 tracey return error;
2198 a596b957 2022-07-14 tracey const struct got_error *
2199 a596b957 2022-07-14 tracey gotweb_get_time_str(char **repo_age, time_t committer_time, int ref_tm)
2201 a596b957 2022-07-14 tracey struct tm tm;
2202 fced5a66 2022-07-20 naddy long long diff_time;
2203 a596b957 2022-07-14 tracey const char *years = "years ago", *months = "months ago";
2204 a596b957 2022-07-14 tracey const char *weeks = "weeks ago", *days = "days ago";
2205 a596b957 2022-07-14 tracey const char *hours = "hours ago", *minutes = "minutes ago";
2206 a596b957 2022-07-14 tracey const char *seconds = "seconds ago", *now = "right now";
2207 a596b957 2022-07-14 tracey char *s;
2208 a596b957 2022-07-14 tracey char datebuf[29];
2210 a596b957 2022-07-14 tracey *repo_age = NULL;
2212 a596b957 2022-07-14 tracey switch (ref_tm) {
2213 a596b957 2022-07-14 tracey case TM_DIFF:
2214 a596b957 2022-07-14 tracey diff_time = time(NULL) - committer_time;
2215 a596b957 2022-07-14 tracey if (diff_time > 60 * 60 * 24 * 365 * 2) {
2216 a596b957 2022-07-14 tracey if (asprintf(repo_age, "%lld %s",
2217 a596b957 2022-07-14 tracey (diff_time / 60 / 60 / 24 / 365), years) == -1)
2218 a596b957 2022-07-14 tracey return got_error_from_errno("asprintf");
2219 a596b957 2022-07-14 tracey } else if (diff_time > 60 * 60 * 24 * (365 / 12) * 2) {
2220 a596b957 2022-07-14 tracey if (asprintf(repo_age, "%lld %s",
2221 a596b957 2022-07-14 tracey (diff_time / 60 / 60 / 24 / (365 / 12)),
2222 a596b957 2022-07-14 tracey months) == -1)
2223 a596b957 2022-07-14 tracey return got_error_from_errno("asprintf");
2224 a596b957 2022-07-14 tracey } else if (diff_time > 60 * 60 * 24 * 7 * 2) {
2225 a596b957 2022-07-14 tracey if (asprintf(repo_age, "%lld %s",
2226 a596b957 2022-07-14 tracey (diff_time / 60 / 60 / 24 / 7), weeks) == -1)
2227 a596b957 2022-07-14 tracey return got_error_from_errno("asprintf");
2228 a596b957 2022-07-14 tracey } else if (diff_time > 60 * 60 * 24 * 2) {
2229 a596b957 2022-07-14 tracey if (asprintf(repo_age, "%lld %s",
2230 a596b957 2022-07-14 tracey (diff_time / 60 / 60 / 24), days) == -1)
2231 a596b957 2022-07-14 tracey return got_error_from_errno("asprintf");
2232 a596b957 2022-07-14 tracey } else if (diff_time > 60 * 60 * 2) {
2233 a596b957 2022-07-14 tracey if (asprintf(repo_age, "%lld %s",
2234 a596b957 2022-07-14 tracey (diff_time / 60 / 60), hours) == -1)
2235 a596b957 2022-07-14 tracey return got_error_from_errno("asprintf");
2236 a596b957 2022-07-14 tracey } else if (diff_time > 60 * 2) {
2237 a596b957 2022-07-14 tracey if (asprintf(repo_age, "%lld %s", (diff_time / 60),
2238 a596b957 2022-07-14 tracey minutes) == -1)
2239 a596b957 2022-07-14 tracey return got_error_from_errno("asprintf");
2240 a596b957 2022-07-14 tracey } else if (diff_time > 2) {
2241 a596b957 2022-07-14 tracey if (asprintf(repo_age, "%lld %s", diff_time,
2242 a596b957 2022-07-14 tracey seconds) == -1)
2243 a596b957 2022-07-14 tracey return got_error_from_errno("asprintf");
2244 a596b957 2022-07-14 tracey } else {
2245 a596b957 2022-07-14 tracey if (asprintf(repo_age, "%s", now) == -1)
2246 a596b957 2022-07-14 tracey return got_error_from_errno("asprintf");
2249 a596b957 2022-07-14 tracey case TM_LONG:
2250 a596b957 2022-07-14 tracey if (gmtime_r(&committer_time, &tm) == NULL)
2251 a596b957 2022-07-14 tracey return got_error_from_errno("gmtime_r");
2253 a596b957 2022-07-14 tracey s = asctime_r(&tm, datebuf);
2254 a596b957 2022-07-14 tracey if (s == NULL)
2255 a596b957 2022-07-14 tracey return got_error_from_errno("asctime_r");
2257 a596b957 2022-07-14 tracey if (asprintf(repo_age, "%s UTC", datebuf) == -1)
2258 a596b957 2022-07-14 tracey return got_error_from_errno("asprintf");
2261 a596b957 2022-07-14 tracey return NULL;