3 ed619ca0 2022-12-14 op * Copyright (c) 2022 Omar Polo <op@openbsd.org>
4 ed619ca0 2022-12-14 op * Copyright (c) 2016, 2019, 2020-2022 Tracey Emery <tracey@traceyemery.net>
6 ed619ca0 2022-12-14 op * Permission to use, copy, modify, and distribute this software for any
7 ed619ca0 2022-12-14 op * purpose with or without fee is hereby granted, provided that the above
8 ed619ca0 2022-12-14 op * copyright notice and this permission notice appear in all copies.
10 ed619ca0 2022-12-14 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 ed619ca0 2022-12-14 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 ed619ca0 2022-12-14 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ed619ca0 2022-12-14 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 ed619ca0 2022-12-14 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ed619ca0 2022-12-14 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 ed619ca0 2022-12-14 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 ed619ca0 2022-12-14 op #include <sys/types.h>
20 ed619ca0 2022-12-14 op #include <sys/queue.h>
22 1abb18e1 2022-12-20 op #include <ctype.h>
23 ed619ca0 2022-12-14 op #include <event.h>
24 ed619ca0 2022-12-14 op #include <stdint.h>
25 ed619ca0 2022-12-14 op #include <stdlib.h>
26 ed619ca0 2022-12-14 op #include <string.h>
27 ed619ca0 2022-12-14 op #include <imsg.h>
29 ed619ca0 2022-12-14 op #include "proc.h"
31 ed619ca0 2022-12-14 op #include "gotwebd.h"
32 ed619ca0 2022-12-14 op #include "tmpl.h"
34 1abb18e1 2022-12-20 op static inline int rss_tag_item(struct template *, struct repo_tag *);
35 1abb18e1 2022-12-20 op static inline int rss_author(struct template *, char *);
38 ed619ca0 2022-12-14 op gotweb_render_age(struct template *tp, time_t time, int ref_tm)
40 ed619ca0 2022-12-14 op const struct got_error *err;
44 ed619ca0 2022-12-14 op err = gotweb_get_time_str(&age, time, ref_tm);
47 ed619ca0 2022-12-14 op r = tp->tp_puts(tp, age);
54 ed619ca0 2022-12-14 op {{ define gotweb_render_header(struct template *tp) }}
56 ed619ca0 2022-12-14 op struct request *c = tp->tp_arg;
57 ed619ca0 2022-12-14 op struct server *srv = c->srv;
58 ed619ca0 2022-12-14 op struct querystring *qs = c->t->qs;
59 ed619ca0 2022-12-14 op struct gotweb_url u_path;
60 d19d9fce 2022-12-20 op const char *prfx = c->document_uri;
61 ed619ca0 2022-12-14 op const char *css = srv->custom_css;
63 ed619ca0 2022-12-14 op memset(&u_path, 0, sizeof(u_path));
64 ed619ca0 2022-12-14 op u_path.index_page = -1;
65 ed619ca0 2022-12-14 op u_path.page = -1;
66 ed619ca0 2022-12-14 op u_path.action = SUMMARY;
68 ed619ca0 2022-12-14 op <!doctype html>
71 ed619ca0 2022-12-14 op <meta charset="utf-8" />
72 ed619ca0 2022-12-14 op <title>{{ srv->site_name }}</title>
73 ed619ca0 2022-12-14 op <meta name="viewport" content="initial-scale=.75" />
74 ed619ca0 2022-12-14 op <meta name="msapplication-TileColor" content="#da532c" />
75 ed619ca0 2022-12-14 op <meta name="theme-color" content="#ffffff"/>
76 ed619ca0 2022-12-14 op <link rel="apple-touch-icon" sizes="180x180" href="{{ prfx }}apple-touch-icon.png" />
77 ed619ca0 2022-12-14 op <link rel="icon" type="image/png" sizes="32x32" href="{{ prfx }}favicon-32x32.png" />
78 ed619ca0 2022-12-14 op <link rel="icon" type="image/png" sizes="16x16" href="{{ prfx }}favicon-16x16.png" />
79 ed619ca0 2022-12-14 op <link rel="manifest" href="{{ prfx }}site.webmanifest"/>
80 ed619ca0 2022-12-14 op <link rel="mask-icon" href="{{ prfx }}safari-pinned-tab.svg" />
81 ed619ca0 2022-12-14 op <link rel="stylesheet" type="text/css" href="{{ prfx }}{{ css }}" />
84 ed619ca0 2022-12-14 op <div id="gw_body">
85 ed619ca0 2022-12-14 op <div id="header">
86 ed619ca0 2022-12-14 op <div id="got_link">
87 ed619ca0 2022-12-14 op <a href="{{ srv->logo_url }}" target="_blank">
88 ed619ca0 2022-12-14 op <img src="{{ prfx }}{{ srv->logo }}" />
92 ed619ca0 2022-12-14 op <div id="site_path">
93 ed619ca0 2022-12-14 op <div id="site_link">
94 ed619ca0 2022-12-14 op <a href="?index_page={{ printf "%d", qs->index_page }}">
95 ed619ca0 2022-12-14 op {{ srv->site_link }}
97 ed619ca0 2022-12-14 op {{ if qs->path }}
98 ed619ca0 2022-12-14 op {! u_path.path = qs->path; !}
100 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &u_path)}}">
101 ed619ca0 2022-12-14 op {{ qs->path }}
104 ed619ca0 2022-12-14 op {{ if qs->action != INDEX }}
105 ed619ca0 2022-12-14 op {{ " / " }}{{ gotweb_action_name(qs->action) }}
109 ed619ca0 2022-12-14 op <div id="content">
112 ed619ca0 2022-12-14 op {{ define gotweb_render_footer(struct template *tp) }}
114 ed619ca0 2022-12-14 op struct request *c = tp->tp_arg;
115 ed619ca0 2022-12-14 op struct server *srv = c->srv;
117 ed619ca0 2022-12-14 op <div id="site_owner_wrapper">
118 ed619ca0 2022-12-14 op <div id="site_owner">
119 ed619ca0 2022-12-14 op {{ if srv->show_site_owner }}
120 ed619ca0 2022-12-14 op {{ srv->site_owner }}
130 ed619ca0 2022-12-14 op {{ define gotweb_render_repo_table_hdr(struct template *tp) }}
132 ed619ca0 2022-12-14 op struct request *c = tp->tp_arg;
133 ed619ca0 2022-12-14 op struct server *srv = c->srv;
135 ed619ca0 2022-12-14 op <div id="index_header">
136 ed619ca0 2022-12-14 op <div id="index_header_project">
139 ed619ca0 2022-12-14 op {{ if srv->show_repo_description }}
140 ed619ca0 2022-12-14 op <div id="index_header_description">
144 ed619ca0 2022-12-14 op {{ if srv->show_repo_owner }}
145 ed619ca0 2022-12-14 op <div id="index_header_owner">
149 ed619ca0 2022-12-14 op {{ if srv->show_repo_age }}
150 ed619ca0 2022-12-14 op <div id="index_header_age">
157 ed619ca0 2022-12-14 op {{ define gotweb_render_repo_fragment(struct template *tp, struct repo_dir *repo_dir) }}
159 ed619ca0 2022-12-14 op struct request *c = tp->tp_arg;
160 ed619ca0 2022-12-14 op struct server *srv = c->srv;
161 ed619ca0 2022-12-14 op struct gotweb_url summary = {
162 ed619ca0 2022-12-14 op .action = SUMMARY,
163 ed619ca0 2022-12-14 op .index_page = -1,
165 ed619ca0 2022-12-14 op .path = repo_dir->name,
166 ed619ca0 2022-12-14 op }, briefs = {
167 ed619ca0 2022-12-14 op .action = BRIEFS,
168 ed619ca0 2022-12-14 op .index_page = -1,
170 ed619ca0 2022-12-14 op .path = repo_dir->name,
171 ed619ca0 2022-12-14 op }, commits = {
172 ed619ca0 2022-12-14 op .action = COMMITS,
173 ed619ca0 2022-12-14 op .index_page = -1,
175 ed619ca0 2022-12-14 op .path = repo_dir->name,
177 ed619ca0 2022-12-14 op .action = TAGS,
178 ed619ca0 2022-12-14 op .index_page = -1,
180 ed619ca0 2022-12-14 op .path = repo_dir->name,
182 ed619ca0 2022-12-14 op .action = TREE,
183 ed619ca0 2022-12-14 op .index_page = -1,
185 ed619ca0 2022-12-14 op .path = repo_dir->name,
187 1abb18e1 2022-12-20 op .action = RSS,
188 1abb18e1 2022-12-20 op .index_page = -1,
190 1abb18e1 2022-12-20 op .path = repo_dir->name,
193 ed619ca0 2022-12-14 op <div class="index_wrapper">
194 ed619ca0 2022-12-14 op <div class="index_project">
195 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">{{ repo_dir->name }}</a>
197 ed619ca0 2022-12-14 op {{ if srv->show_repo_description }}
198 ed619ca0 2022-12-14 op <div class="index_project_description">
199 ed619ca0 2022-12-14 op {{ repo_dir->description }}
202 ed619ca0 2022-12-14 op {{ if srv->show_repo_owner }}
203 ed619ca0 2022-12-14 op <div class="index_project_owner">
204 ed619ca0 2022-12-14 op {{ repo_dir->owner }}
207 ed619ca0 2022-12-14 op {{ if srv->show_repo_age }}
208 ed619ca0 2022-12-14 op <div class="index_project_age">
209 ed619ca0 2022-12-14 op {{ repo_dir->age }}
212 ed619ca0 2022-12-14 op <div class="navs_wrapper">
213 ed619ca0 2022-12-14 op <div class="navs">
214 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &summary) }}">summary</a>
216 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &briefs) }}">briefs</a>
218 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &commits) }}">commits</a>
220 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &tags) }}">tags</a>
222 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &tree) }}">tree</a>
224 1abb18e1 2022-12-20 op <a href="{{ render gotweb_render_url(tp->tp_arg, &rss) }}">rss</a>
226 ed619ca0 2022-12-14 op <div class="dotted_line"></div>
231 ed619ca0 2022-12-14 op {{ define gotweb_render_briefs(struct template *tp) }}
233 ed619ca0 2022-12-14 op const struct got_error *error;
234 ed619ca0 2022-12-14 op struct request *c = tp->tp_arg;
235 ed619ca0 2022-12-14 op struct server *srv = c->srv;
236 ed619ca0 2022-12-14 op struct transport *t = c->t;
237 ed619ca0 2022-12-14 op struct querystring *qs = c->t->qs;
238 ed619ca0 2022-12-14 op struct repo_commit *rc;
239 ed619ca0 2022-12-14 op struct repo_dir *repo_dir = t->repo_dir;
240 ed619ca0 2022-12-14 op struct gotweb_url diff_url, tree_url;
243 ed619ca0 2022-12-14 op diff_url = (struct gotweb_url){
244 ed619ca0 2022-12-14 op .action = DIFF,
245 ed619ca0 2022-12-14 op .index_page = -1,
247 ed619ca0 2022-12-14 op .path = repo_dir->name,
248 ed619ca0 2022-12-14 op .headref = qs->headref,
250 ed619ca0 2022-12-14 op tree_url = (struct gotweb_url){
251 ed619ca0 2022-12-14 op .action = TREE,
252 ed619ca0 2022-12-14 op .index_page = -1,
254 ed619ca0 2022-12-14 op .path = repo_dir->name,
255 ed619ca0 2022-12-14 op .headref = qs->headref,
258 ed619ca0 2022-12-14 op if (qs->action == SUMMARY) {
259 ed619ca0 2022-12-14 op qs->action = BRIEFS;
260 ed619ca0 2022-12-14 op error = got_get_repo_commits(c, D_MAXSLCOMMDISP);
262 ed619ca0 2022-12-14 op error = got_get_repo_commits(c, srv->max_commits_display);
266 ed619ca0 2022-12-14 op <div id="briefs_title_wrapper">
267 ed619ca0 2022-12-14 op <div id="briefs_title">Commit Briefs</div>
269 ed619ca0 2022-12-14 op <div id="briefs_content">
270 ed619ca0 2022-12-14 op {{ tailq-foreach rc &t->repo_commits entry }}
272 ed619ca0 2022-12-14 op diff_url.commit = rc->commit_id;
273 ed619ca0 2022-12-14 op tree_url.commit = rc->commit_id;
275 ed619ca0 2022-12-14 op tmp = strchr(rc->author, '<');
279 ed619ca0 2022-12-14 op tmp = strchr(rc->commit_msg, '\n');
283 ed619ca0 2022-12-14 op <div class="briefs_age">
284 ed619ca0 2022-12-14 op {{ render gotweb_render_age(tp, rc->committer_time, TM_DIFF) }}
286 ed619ca0 2022-12-14 op <div class="briefs_author">
287 ed619ca0 2022-12-14 op {{ rc->author }}
289 ed619ca0 2022-12-14 op <div class="briefs_log">
290 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">
291 ed619ca0 2022-12-14 op {{ rc->commit_msg }}
293 ed619ca0 2022-12-14 op {{ if rc->refs_str }}
294 ed619ca0 2022-12-14 op {{ " " }} <span class="refs_str">({{ rc->refs_str }})</span>
298 ed619ca0 2022-12-14 op <div class="navs_wrapper">
299 ed619ca0 2022-12-14 op <div class="navs">
300 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &diff_url) }}">diff</a>
302 ed619ca0 2022-12-14 op <a href="{{ render gotweb_render_url(tp->tp_arg, &tree_url) }}">tree</a>
305 ed619ca0 2022-12-14 op <div class="dotted_line"></div>
307 ed619ca0 2022-12-14 op {{ if t->next_id || t->prev_id }}
308 b4c0bd72 2022-12-17 op {{ render gotweb_render_navs(tp) }}
313 b4c0bd72 2022-12-17 op {{ define gotweb_render_navs(struct template *tp) }}
315 b4c0bd72 2022-12-17 op struct request *c = tp->tp_arg;
316 b4c0bd72 2022-12-17 op struct transport *t = c->t;
317 b4c0bd72 2022-12-17 op struct gotweb_url prev, next;
318 b4c0bd72 2022-12-17 op int have_prev, have_next;
320 b4c0bd72 2022-12-17 op gotweb_get_navs(c, &prev, &have_prev, &next, &have_next);
322 b4c0bd72 2022-12-17 op <div id="np_wrapper">
323 b4c0bd72 2022-12-17 op <div id="nav_prev">
324 b4c0bd72 2022-12-17 op {{ if have_prev }}
325 b4c0bd72 2022-12-17 op <a href="{{ render gotweb_render_url(c, &prev) }}">
330 b4c0bd72 2022-12-17 op <div id="nav_next">
331 b4c0bd72 2022-12-17 op {{ if have_next }}
332 b4c0bd72 2022-12-17 op <a href="{{ render gotweb_render_url(c, &next) }}">
338 b4c0bd72 2022-12-17 op {{ finally }}
340 b4c0bd72 2022-12-17 op free(t->next_id);
341 b4c0bd72 2022-12-17 op t->next_id = NULL;
342 b4c0bd72 2022-12-17 op free(t->prev_id);
343 b4c0bd72 2022-12-17 op t->prev_id = NULL;
347 156a1144 2022-12-17 op {{ define gotweb_render_commits(struct template *tp) }}
349 156a1144 2022-12-17 op struct request *c = tp->tp_arg;
350 156a1144 2022-12-17 op struct transport *t = c->t;
351 156a1144 2022-12-17 op struct repo_dir *repo_dir = t->repo_dir;
352 156a1144 2022-12-17 op struct repo_commit *rc;
353 156a1144 2022-12-17 op struct gotweb_url diff, tree;
355 156a1144 2022-12-17 op diff = (struct gotweb_url){
356 156a1144 2022-12-17 op .action = DIFF,
357 156a1144 2022-12-17 op .index_page = -1,
359 156a1144 2022-12-17 op .path = repo_dir->name,
361 156a1144 2022-12-17 op tree = (struct gotweb_url){
362 156a1144 2022-12-17 op .action = TREE,
363 156a1144 2022-12-17 op .index_page = -1,
365 156a1144 2022-12-17 op .path = repo_dir->name,
368 156a1144 2022-12-17 op <div class="commits_title_wrapper">
369 156a1144 2022-12-17 op <div class="commits_title">Commits</div>
371 156a1144 2022-12-17 op <div class="commits_content">
372 156a1144 2022-12-17 op {{ tailq-foreach rc &t->repo_commits entry }}
374 156a1144 2022-12-17 op diff.commit = rc->commit_id;
375 156a1144 2022-12-17 op tree.commit = rc->commit_id;
377 156a1144 2022-12-17 op <div class="commits_header_wrapper">
378 156a1144 2022-12-17 op <div class="commits_header">
379 156a1144 2022-12-17 op <div class="header_commit_title">Commit:</div>
380 156a1144 2022-12-17 op <div class="header_commit">{{ rc->commit_id }}</div>
381 156a1144 2022-12-17 op <div class="header_author_title">Author:</div>
382 156a1144 2022-12-17 op <div class="header_author">{{ rc->author }}</div>
383 156a1144 2022-12-17 op <div class="header_age_title">Date:</div>
384 156a1144 2022-12-17 op <div class="header_age">
385 156a1144 2022-12-17 op {{ render gotweb_render_age(tp, rc->committer_time, TM_LONG) }}
389 cf536071 2022-12-31 op <div class="dotted_line"></div>
390 cf536071 2022-12-31 op <div class="commit">
392 cf536071 2022-12-31 op {{ rc->commit_msg }}
394 156a1144 2022-12-17 op <div class="navs_wrapper">
395 156a1144 2022-12-17 op <div class="navs">
396 156a1144 2022-12-17 op <a href="{{ render gotweb_render_url(c, &diff) }}">diff</a>
398 156a1144 2022-12-17 op <a href="{{ render gotweb_render_url(c, &tree) }}">tree</a>
401 156a1144 2022-12-17 op <div class="dotted_line"></div>
403 156a1144 2022-12-17 op {{ if t->next_id || t->prev_id }}
404 156a1144 2022-12-17 op {{ render gotweb_render_navs(tp) }}
409 1abb18e1 2022-12-20 op {{ define gotweb_render_rss(struct template *tp) }}
411 1abb18e1 2022-12-20 op struct request *c = tp->tp_arg;
412 1abb18e1 2022-12-20 op struct server *srv = c->srv;
413 1abb18e1 2022-12-20 op struct transport *t = c->t;
414 1abb18e1 2022-12-20 op struct repo_dir *repo_dir = t->repo_dir;
415 1abb18e1 2022-12-20 op struct repo_tag *rt;
416 1abb18e1 2022-12-20 op struct gotweb_url summary = {
417 1abb18e1 2022-12-20 op .action = SUMMARY,
418 1abb18e1 2022-12-20 op .index_page = -1,
420 1abb18e1 2022-12-20 op .path = repo_dir->name,
423 1abb18e1 2022-12-20 op <?xml version="1.0" encoding="UTF-8"?>
424 1abb18e1 2022-12-20 op <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
426 1abb18e1 2022-12-20 op <title>Tags of {{ repo_dir->name }}</title>
429 1abb18e1 2022-12-20 op {{ render gotweb_render_absolute_url(c, &summary) }}
432 1abb18e1 2022-12-20 op {{ if srv->show_repo_description }}
433 1abb18e1 2022-12-20 op <description>{{ repo_dir->description }}</description>
435 1abb18e1 2022-12-20 op {{ tailq-foreach rt &t->repo_tags entry }}
436 1abb18e1 2022-12-20 op {{ render rss_tag_item(tp, rt) }}
442 1abb18e1 2022-12-20 op {{ define rss_tag_item(struct template *tp, struct repo_tag *rt) }}
444 1abb18e1 2022-12-20 op struct request *c = tp->tp_arg;
445 1abb18e1 2022-12-20 op struct transport *t = c->t;
446 1abb18e1 2022-12-20 op struct repo_dir *repo_dir = t->repo_dir;
447 1abb18e1 2022-12-20 op char *tag_name = rt->tag_name;
448 1abb18e1 2022-12-20 op struct gotweb_url tag = {
449 1abb18e1 2022-12-20 op .action = TAG,
450 1abb18e1 2022-12-20 op .index_page = -1,
452 1abb18e1 2022-12-20 op .path = repo_dir->name,
453 1abb18e1 2022-12-20 op .commit = rt->commit_id,
456 1abb18e1 2022-12-20 op if (strncmp(tag_name, "refs/tags/", 10) == 0)
457 1abb18e1 2022-12-20 op tag_name += 10;
460 1abb18e1 2022-12-20 op <title>{{ repo_dir->name }} {{" "}} {{ tag_name }}</title>
463 1abb18e1 2022-12-20 op {{ render gotweb_render_absolute_url(c, &tag) }}
466 1abb18e1 2022-12-20 op <description>
467 1abb18e1 2022-12-20 op <![CDATA[<pre>{{ rt->tag_commit }}</pre>]]>
468 1abb18e1 2022-12-20 op </description>
469 1abb18e1 2022-12-20 op {{ render rss_author(tp, rt->tagger) }}
470 1abb18e1 2022-12-20 op <guid isPermaLink="false">{{ rt->commit_id }}</guid>
472 1abb18e1 2022-12-20 op {{ render gotweb_render_age(tp, rt->tagger_time, TM_RFC822) }}
477 1abb18e1 2022-12-20 op {{ define rss_author(struct template *tp, char *author) }}
479 1abb18e1 2022-12-20 op char *t, *mail;
481 1abb18e1 2022-12-20 op /* what to do if the author name contains a paren? */
482 1abb18e1 2022-12-20 op if (strchr(author, '(') != NULL || strchr(author, ')') != NULL)
485 1abb18e1 2022-12-20 op t = strchr(author, '<');
486 1abb18e1 2022-12-20 op if (t == NULL)
491 1abb18e1 2022-12-20 op while (isspace((unsigned char)*--t))
494 1abb18e1 2022-12-20 op t = strchr(mail, '>');
495 1abb18e1 2022-12-20 op if (t == NULL)
500 1abb18e1 2022-12-20 op {{ mail }} {{" "}} ({{ author }})