Blob


1 /*
2 * Copyright (c) 2019 Tracey Emery <tracey@traceyemery.net>
3 * Copyright (c) 2018, 2019 Stefan Sperling <stsp@openbsd.org>
4 * Copyright (c) 2014, 2015, 2017 Kristaps Dzonsons <kristaps@bsd.lv>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
19 #include <sys/queue.h>
20 #include <sys/stat.h>
21 #include <sys/types.h>
23 #include <dirent.h>
24 #include <err.h>
25 #include <regex.h>
26 #include <stdarg.h>
27 #include <stdbool.h>
28 #include <stdint.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <unistd.h>
34 #include <got_object.h>
35 #include <got_reference.h>
36 #include <got_repository.h>
37 #include <got_path.h>
38 #include <got_cancel.h>
39 #include <got_worktree.h>
40 #include <got_diff.h>
41 #include <got_commit_graph.h>
42 #include <got_blame.h>
43 #include <got_privsep.h>
44 #include <got_opentemp.h>
46 #include <kcgi.h>
47 #include <kcgihtml.h>
49 #include "buf.h"
50 #include "gotweb.h"
51 #include "gotweb_ui.h"
53 #ifndef nitems
54 #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
55 #endif
57 struct trans {
58 TAILQ_HEAD(dirs, gw_dir) gw_dirs;
59 struct gw_dir *gw_dir;
60 struct gotweb_conf *gw_conf;
61 struct ktemplate *gw_tmpl;
62 struct khtmlreq *gw_html_req;
63 struct kreq *gw_req;
64 char *repo_name;
65 char *repo_path;
66 char *commit;
67 char *repo_file;
68 char *action_name;
69 unsigned int action;
70 unsigned int page;
71 unsigned int repos_total;
72 enum kmime mime;
73 };
75 enum gw_key {
76 KEY_PATH,
77 KEY_ACTION,
78 KEY_COMMIT_ID,
79 KEY_FILE,
80 KEY_PAGE,
81 KEY__MAX
82 };
84 struct gw_dir {
85 TAILQ_ENTRY(gw_dir) entry;
86 char *name;
87 char *owner;
88 char *description;
89 char *url;
90 char *age;
91 char *path;
92 };
94 enum tmpl {
95 TEMPL_HEAD,
96 TEMPL_HEADER,
97 TEMPL_SITEPATH,
98 TEMPL_SITEOWNER,
99 TEMPL_TITLE,
100 TEMPL_SEARCH,
101 TEMPL_CONTENT,
102 TEMPL__MAX
103 };
105 enum ref_tm {
106 TM_DIFF,
107 TM_LONG,
108 };
110 struct buf {
111 /* buffer handle, buffer size, and data length */
112 u_char *cb_buf;
113 size_t cb_size;
114 size_t cb_len;
115 };
117 static const char *const templs[TEMPL__MAX] = {
118 "head",
119 "header",
120 "sitepath",
121 "siteowner",
122 "title",
123 "search",
124 "content",
125 };
127 static const struct kvalid gw_keys[KEY__MAX] = {
128 { kvalid_stringne, "path" },
129 { kvalid_stringne, "action" },
130 { kvalid_stringne, "commit" },
131 { kvalid_stringne, "file" },
132 { kvalid_int, "page" },
133 };
135 static struct gw_dir *gw_init_gw_dir(char *);
137 static char *gw_get_repo_description(struct trans *,
138 char *);
139 static char *gw_get_repo_owner(struct trans *,
140 char *);
141 static char *gw_get_time_str(time_t, int);
142 static char *gw_get_repo_age(struct trans *,
143 char *, char *, int);
144 static char *gw_get_repo_shortlog(struct trans *,
145 const char *);
146 static char *gw_get_repo_tags(struct trans *);
147 static char *gw_get_repo_heads(struct trans *);
148 static char *gw_get_clone_url(struct trans *, char *);
149 static char *gw_get_got_link(struct trans *);
150 static char *gw_get_site_link(struct trans *);
151 static char *gw_html_escape(const char *);
153 static void gw_display_open(struct trans *, enum khttp,
154 enum kmime);
155 static void gw_display_index(struct trans *,
156 const struct got_error *);
158 static int gw_template(size_t, void *);
160 static const struct got_error* apply_unveil(const char *, const char *);
161 static const struct got_error* gw_load_got_paths(struct trans *);
162 static const struct got_error* gw_load_got_path(struct trans *,
163 struct gw_dir *);
164 static const struct got_error* gw_parse_querystring(struct trans *);
165 static const struct got_error* match_logmsg(int *, struct got_object_id *,
166 struct got_commit_object *, regex_t *);
168 static const struct got_error* gw_blame(struct trans *);
169 static const struct got_error* gw_blob(struct trans *);
170 static const struct got_error* gw_blob_diff(struct trans *);
171 static const struct got_error* gw_commit(struct trans *);
172 static const struct got_error* gw_commit_diff(struct trans *);
173 static const struct got_error* gw_history(struct trans *);
174 static const struct got_error* gw_index(struct trans *);
175 static const struct got_error* gw_log(struct trans *);
176 static const struct got_error* gw_raw(struct trans *);
177 static const struct got_error* gw_shortlog(struct trans *);
178 static const struct got_error* gw_snapshot(struct trans *);
179 static const struct got_error* gw_summary(struct trans *);
180 static const struct got_error* gw_tree(struct trans *);
182 struct gw_query_action {
183 unsigned int func_id;
184 const char *func_name;
185 const struct got_error *(*func_main)(struct trans *);
186 char *template;
187 };
189 enum gw_query_actions {
190 GW_BLAME,
191 GW_BLOB,
192 GW_BLOBDIFF,
193 GW_COMMIT,
194 GW_COMMITDIFF,
195 GW_ERR,
196 GW_HISTORY,
197 GW_INDEX,
198 GW_LOG,
199 GW_RAW,
200 GW_SHORTLOG,
201 GW_SNAPSHOT,
202 GW_SUMMARY,
203 GW_TREE
204 };
206 static struct gw_query_action gw_query_funcs[] = {
207 { GW_BLAME, "blame", gw_blame, "gw_tmpl/index.tmpl" },
208 { GW_BLOB, "blob", gw_blob, "gw_tmpl/index.tmpl" },
209 { GW_BLOBDIFF, "blobdiff", gw_blob_diff, "gw_tmpl/index.tmpl" },
210 { GW_COMMIT, "commit", gw_commit, "gw_tmpl/index.tmpl" },
211 { GW_COMMITDIFF, "commit_diff", gw_commit_diff, "gw_tmpl/index.tmpl" },
212 { GW_ERR, NULL, NULL, "gw_tmpl/index.tmpl" },
213 { GW_HISTORY, "history", gw_history, "gw_tmpl/index.tmpl" },
214 { GW_INDEX, "index", gw_index, "gw_tmpl/index.tmpl" },
215 { GW_LOG, "log", gw_log, "gw_tmpl/index.tmpl" },
216 { GW_RAW, "raw", gw_raw, "gw_tmpl/index.tmpl" },
217 { GW_SHORTLOG, "shortlog", gw_shortlog, "gw_tmpl/index.tmpl" },
218 { GW_SNAPSHOT, "snapshot", gw_snapshot, "gw_tmpl/index.tmpl" },
219 { GW_SUMMARY, "summary", gw_summary, "gw_tmpl/index.tmpl" },
220 { GW_TREE, "tree", gw_tree, "gw_tmpl/index.tmpl" },
221 };
223 static const struct got_error *
224 apply_unveil(const char *repo_path, const char *repo_file)
226 const struct got_error *err;
228 if (repo_path && repo_file) {
229 char *full_path;
230 if ((asprintf(&full_path, "%s/%s", repo_path, repo_file)) == -1)
231 return got_error_from_errno("asprintf unveil");
232 if (unveil(full_path, "r") != 0)
233 return got_error_from_errno2("unveil", full_path);
236 if (repo_path && unveil(repo_path, "r") != 0)
237 return got_error_from_errno2("unveil", repo_path);
239 if (unveil("/tmp", "rwc") != 0)
240 return got_error_from_errno2("unveil", "/tmp");
242 err = got_privsep_unveil_exec_helpers();
243 if (err != NULL)
244 return err;
246 if (unveil(NULL, NULL) != 0)
247 return got_error_from_errno("unveil");
249 return NULL;
252 static const struct got_error *
253 gw_blame(struct trans *gw_trans)
255 const struct got_error *error = NULL;
257 return error;
260 static const struct got_error *
261 gw_blob(struct trans *gw_trans)
263 const struct got_error *error = NULL;
265 return error;
268 static const struct got_error *
269 gw_blob_diff(struct trans *gw_trans)
271 const struct got_error *error = NULL;
273 return error;
276 static const struct got_error *
277 gw_commit(struct trans *gw_trans)
279 const struct got_error *error = NULL;
281 return error;
284 static const struct got_error *
285 gw_commit_diff(struct trans *gw_trans)
287 const struct got_error *error = NULL;
289 return error;
292 static const struct got_error *
293 gw_history(struct trans *gw_trans)
295 const struct got_error *error = NULL;
297 return error;
300 static const struct got_error *
301 gw_index(struct trans *gw_trans)
303 const struct got_error *error = NULL;
304 struct gw_dir *gw_dir = NULL;
305 char *html, *navs, *next, *prev;
306 unsigned int prev_disp = 0, next_disp = 1, dir_c = 0;
308 error = apply_unveil(gw_trans->gw_conf->got_repos_path, NULL);
309 if (error)
310 return error;
312 error = gw_load_got_paths(gw_trans);
313 if (error)
314 return error;
316 khttp_puts(gw_trans->gw_req, index_projects_header);
318 TAILQ_FOREACH(gw_dir, &gw_trans->gw_dirs, entry)
319 dir_c++;
321 TAILQ_FOREACH(gw_dir, &gw_trans->gw_dirs, entry) {
322 if (gw_trans->page > 0 && (gw_trans->page *
323 gw_trans->gw_conf->got_max_repos_display) > prev_disp) {
324 prev_disp++;
325 continue;
328 prev_disp++;
329 if((asprintf(&navs, index_navs, gw_dir->name, gw_dir->name,
330 gw_dir->name, gw_dir->name)) == -1)
331 return got_error_from_errno("asprintf");
333 if ((asprintf(&html, index_projects, gw_dir->name, gw_dir->name,
334 gw_dir->description, gw_dir->owner, gw_dir->age,
335 navs)) == -1)
336 return got_error_from_errno("asprintf");
338 khttp_puts(gw_trans->gw_req, html);
340 free(navs);
341 free(html);
343 if (gw_trans->gw_conf->got_max_repos_display == 0)
344 continue;
346 if (next_disp == gw_trans->gw_conf->got_max_repos_display)
347 khttp_puts(gw_trans->gw_req, np_wrapper_start);
348 else if ((gw_trans->gw_conf->got_max_repos_display > 0) &&
349 (gw_trans->page > 0) &&
350 (next_disp == gw_trans->gw_conf->got_max_repos_display ||
351 prev_disp == gw_trans->repos_total))
352 khttp_puts(gw_trans->gw_req, np_wrapper_start);
354 if ((gw_trans->gw_conf->got_max_repos_display > 0) &&
355 (gw_trans->page > 0) &&
356 (next_disp == gw_trans->gw_conf->got_max_repos_display ||
357 prev_disp == gw_trans->repos_total)) {
358 if ((asprintf(&prev, nav_prev,
359 gw_trans->page - 1)) == -1)
360 return got_error_from_errno("asprintf");
361 khttp_puts(gw_trans->gw_req, prev);
362 free(prev);
365 khttp_puts(gw_trans->gw_req, div_end);
367 if (gw_trans->gw_conf->got_max_repos_display > 0 &&
368 next_disp == gw_trans->gw_conf->got_max_repos_display &&
369 dir_c != (gw_trans->page + 1) *
370 gw_trans->gw_conf->got_max_repos_display) {
371 if ((asprintf(&next, nav_next,
372 gw_trans->page + 1)) == -1)
373 return got_error_from_errno("calloc");
374 khttp_puts(gw_trans->gw_req, next);
375 khttp_puts(gw_trans->gw_req, div_end);
376 free(next);
377 next_disp = 0;
378 break;
381 if ((gw_trans->gw_conf->got_max_repos_display > 0) &&
382 (gw_trans->page > 0) &&
383 (next_disp == gw_trans->gw_conf->got_max_repos_display ||
384 prev_disp == gw_trans->repos_total))
385 khttp_puts(gw_trans->gw_req, div_end);
387 next_disp++;
389 return error;
392 static const struct got_error *
393 gw_log(struct trans *gw_trans)
395 const struct got_error *error = NULL;
397 return error;
400 static const struct got_error *
401 gw_raw(struct trans *gw_trans)
403 const struct got_error *error = NULL;
405 return error;
408 static const struct got_error *
409 gw_shortlog(struct trans *gw_trans)
411 const struct got_error *error = NULL;
413 return error;
416 static const struct got_error *
417 gw_snapshot(struct trans *gw_trans)
419 const struct got_error *error = NULL;
421 return error;
424 static const struct got_error *
425 gw_summary(struct trans *gw_trans)
427 const struct got_error *error = NULL;
428 char *description_html, *repo_owner_html, *repo_age_html,
429 *cloneurl_html, *shortlog, *tags, *heads, *shortlog_html,
430 *tags_html, *heads_html, *age;
432 error = apply_unveil(gw_trans->gw_dir->path, NULL);
433 if (error)
434 return error;
436 khttp_puts(gw_trans->gw_req, summary_wrapper);
437 if (gw_trans->gw_conf->got_show_repo_description) {
438 if (gw_trans->gw_dir->description != NULL &&
439 (strcmp(gw_trans->gw_dir->description, "") != 0)) {
440 if ((asprintf(&description_html, description,
441 gw_trans->gw_dir->description)) == -1)
442 return got_error_from_errno("asprintf");
444 khttp_puts(gw_trans->gw_req, description_html);
445 free(description_html);
449 if (gw_trans->gw_conf->got_show_repo_owner) {
450 if (gw_trans->gw_dir->owner != NULL &&
451 (strcmp(gw_trans->gw_dir->owner, "") != 0)) {
452 if ((asprintf(&repo_owner_html, repo_owner,
453 gw_trans->gw_dir->owner)) == -1)
454 return got_error_from_errno("asprintf");
456 khttp_puts(gw_trans->gw_req, repo_owner_html);
457 free(repo_owner_html);
461 if (gw_trans->gw_conf->got_show_repo_age) {
462 age = gw_get_repo_age(gw_trans, gw_trans->gw_dir->path,
463 "refs/heads", TM_LONG);
464 if (age != NULL && (strcmp(age, "") != 0)) {
465 if ((asprintf(&repo_age_html, last_change, age)) == -1)
466 return got_error_from_errno("asprintf");
468 khttp_puts(gw_trans->gw_req, repo_age_html);
469 free(repo_age_html);
470 free(age);
474 if (gw_trans->gw_conf->got_show_repo_cloneurl) {
475 if (gw_trans->gw_dir->url != NULL &&
476 (strcmp(gw_trans->gw_dir->url, "") != 0)) {
477 if ((asprintf(&cloneurl_html, cloneurl,
478 gw_trans->gw_dir->url)) == -1)
479 return got_error_from_errno("asprintf");
481 khttp_puts(gw_trans->gw_req, cloneurl_html);
482 free(cloneurl_html);
485 khttp_puts(gw_trans->gw_req, div_end);
487 shortlog = gw_get_repo_shortlog(gw_trans, NULL);
488 tags = gw_get_repo_tags(gw_trans);
489 heads = gw_get_repo_heads(gw_trans);
491 if (shortlog != NULL && strcmp(shortlog, "") != 0) {
492 if ((asprintf(&shortlog_html, summary_shortlog,
493 shortlog)) == -1)
494 return got_error_from_errno("asprintf");
495 khttp_puts(gw_trans->gw_req, shortlog_html);
496 free(shortlog_html);
497 free(shortlog);
500 if (tags != NULL && strcmp(tags, "") != 0) {
501 if ((asprintf(&tags_html, summary_tags,
502 tags)) == -1)
503 return got_error_from_errno("asprintf");
504 khttp_puts(gw_trans->gw_req, tags_html);
505 free(tags_html);
506 free(tags);
509 if (heads != NULL && strcmp(heads, "") != 0) {
510 if ((asprintf(&heads_html, summary_heads,
511 heads)) == -1)
512 return got_error_from_errno("asprintf");
513 khttp_puts(gw_trans->gw_req, heads_html);
514 free(heads_html);
515 free(heads);
518 return error;
521 static const struct got_error *
522 gw_tree(struct trans *gw_trans)
524 const struct got_error *error = NULL;
526 return error;
529 static const struct got_error *
530 gw_load_got_path(struct trans *gw_trans, struct gw_dir *gw_dir)
532 const struct got_error *error = NULL;
533 DIR *dt;
534 char *dir_test;
535 bool opened = false;
537 if ((asprintf(&dir_test, "%s/%s/%s",
538 gw_trans->gw_conf->got_repos_path, gw_dir->name,
539 GOTWEB_GIT_DIR)) == -1)
540 return got_error_from_errno("asprintf");
542 dt = opendir(dir_test);
543 if (dt == NULL) {
544 free(dir_test);
545 } else {
546 gw_dir->path = strdup(dir_test);
547 opened = true;
548 goto done;
551 if ((asprintf(&dir_test, "%s/%s/%s",
552 gw_trans->gw_conf->got_repos_path, gw_dir->name,
553 GOTWEB_GOT_DIR)) == -1)
554 return got_error_from_errno("asprintf");
556 dt = opendir(dir_test);
557 if (dt == NULL)
558 free(dir_test);
559 else {
560 opened = true;
561 error = got_error(GOT_ERR_NOT_GIT_REPO);
562 goto errored;
565 if ((asprintf(&dir_test, "%s/%s",
566 gw_trans->gw_conf->got_repos_path, gw_dir->name)) == -1)
567 return got_error_from_errno("asprintf");
569 gw_dir->path = strdup(dir_test);
571 done:
572 gw_dir->description = gw_get_repo_description(gw_trans,
573 gw_dir->path);
574 gw_dir->owner = gw_get_repo_owner(gw_trans, gw_dir->path);
575 gw_dir->age = gw_get_repo_age(gw_trans, gw_dir->path, "refs/heads",
576 TM_DIFF);
577 gw_dir->url = gw_get_clone_url(gw_trans, gw_dir->path);
579 errored:
580 free(dir_test);
581 if (opened)
582 closedir(dt);
583 return error;
586 static const struct got_error *
587 gw_load_got_paths(struct trans *gw_trans)
589 const struct got_error *error = NULL;
590 DIR *d;
591 struct dirent **sd_dent;
592 struct gw_dir *gw_dir;
593 struct stat st;
594 unsigned int d_cnt, d_i;
596 d = opendir(gw_trans->gw_conf->got_repos_path);
597 if (d == NULL) {
598 error = got_error_from_errno2("opendir",
599 gw_trans->gw_conf->got_repos_path);
600 return error;
603 d_cnt = scandir(gw_trans->gw_conf->got_repos_path, &sd_dent, NULL,
604 alphasort);
605 if (d_cnt == -1) {
606 error = got_error_from_errno2("scandir",
607 gw_trans->gw_conf->got_repos_path);
608 return error;
611 for (d_i = 0; d_i < d_cnt; d_i++) {
612 if (gw_trans->gw_conf->got_max_repos > 0 &&
613 (d_i - 2) == gw_trans->gw_conf->got_max_repos)
614 break; /* account for parent and self */
616 if (strcmp(sd_dent[d_i]->d_name, ".") == 0 ||
617 strcmp(sd_dent[d_i]->d_name, "..") == 0)
618 continue;
620 if ((gw_dir = gw_init_gw_dir(sd_dent[d_i]->d_name)) == NULL)
621 return got_error_from_errno("gw_dir malloc");
623 error = gw_load_got_path(gw_trans, gw_dir);
624 if (error && error->code == GOT_ERR_NOT_GIT_REPO)
625 continue;
626 else if (error)
627 return error;
629 if (lstat(gw_dir->path, &st) == 0 && S_ISDIR(st.st_mode) &&
630 !got_path_dir_is_empty(gw_dir->path)) {
631 TAILQ_INSERT_TAIL(&gw_trans->gw_dirs, gw_dir,
632 entry);
633 gw_trans->repos_total++;
637 closedir(d);
638 return error;
641 static const struct got_error *
642 gw_parse_querystring(struct trans *gw_trans)
644 const struct got_error *error = NULL;
645 struct kpair *p;
646 struct gw_query_action *action = NULL;
647 unsigned int i;
649 if (gw_trans->gw_req->fieldnmap[0]) {
650 error = got_error_from_errno("bad parse");
651 return error;
652 } else if ((p = gw_trans->gw_req->fieldmap[KEY_PATH])) {
653 /* define gw_trans->repo_path */
654 if ((asprintf(&gw_trans->repo_name, "%s", p->parsed.s)) == -1)
655 return got_error_from_errno("asprintf");
657 if ((asprintf(&gw_trans->repo_path, "%s/%s",
658 gw_trans->gw_conf->got_repos_path, p->parsed.s)) == -1)
659 return got_error_from_errno("asprintf");
661 if ((p = gw_trans->gw_req->fieldmap[KEY_COMMIT_ID]))
662 if ((asprintf(&gw_trans->commit, "%s",
663 p->parsed.s)) == -1)
664 return got_error_from_errno("asprintf");
666 /* get action and set function */
667 if ((p = gw_trans->gw_req->fieldmap[KEY_ACTION]))
668 for (i = 0; i < nitems(gw_query_funcs); i++) {
669 action = &gw_query_funcs[i];
670 if (action->func_name == NULL)
671 continue;
673 if (strcmp(action->func_name,
674 p->parsed.s) == 0) {
675 gw_trans->action = i;
676 if ((asprintf(&gw_trans->action_name,
677 "%s", action->func_name)) == -1)
678 return
679 got_error_from_errno(
680 "asprintf");
682 break;
685 action = NULL;
688 if ((p = gw_trans->gw_req->fieldmap[KEY_FILE]))
689 if ((asprintf(&gw_trans->repo_file, "%s",
690 p->parsed.s)) == -1)
691 return got_error_from_errno("asprintf");
693 if (action == NULL) {
694 error = got_error_from_errno("invalid action");
695 return error;
697 if ((gw_trans->gw_dir =
698 gw_init_gw_dir(gw_trans->repo_name)) == NULL)
699 return got_error_from_errno("gw_dir malloc");
701 error = gw_load_got_path(gw_trans, gw_trans->gw_dir);
702 if (error)
703 return error;
704 } else
705 gw_trans->action = GW_INDEX;
707 if ((p = gw_trans->gw_req->fieldmap[KEY_PAGE]))
708 gw_trans->page = p->parsed.i;
710 if (gw_trans->action == GW_RAW)
711 gw_trans->mime = KMIME_TEXT_PLAIN;
713 return error;
716 static struct gw_dir *
717 gw_init_gw_dir(char *dir)
719 struct gw_dir *gw_dir;
721 if ((gw_dir = malloc(sizeof(*gw_dir))) == NULL)
722 return NULL;
724 if ((asprintf(&gw_dir->name, "%s", dir)) == -1)
725 return NULL;
727 return gw_dir;
730 static const struct got_error*
731 match_logmsg(int *have_match, struct got_object_id *id,
732 struct got_commit_object *commit, regex_t *regex)
734 const struct got_error *err = NULL;
735 regmatch_t regmatch;
736 char *id_str = NULL, *logmsg = NULL;
738 *have_match = 0;
740 err = got_object_id_str(&id_str, id);
741 if (err)
742 return err;
744 err = got_object_commit_get_logmsg(&logmsg, commit);
745 if (err)
746 goto done;
748 if (regexec(regex, logmsg, 1, &regmatch, 0) == 0)
749 *have_match = 1;
750 done:
751 free(id_str);
752 free(logmsg);
753 return err;
756 static void
757 gw_display_open(struct trans *gw_trans, enum khttp code, enum kmime mime)
759 khttp_head(gw_trans->gw_req, kresps[KRESP_ALLOW], "GET");
760 khttp_head(gw_trans->gw_req, kresps[KRESP_STATUS], "%s",
761 khttps[code]);
762 khttp_head(gw_trans->gw_req, kresps[KRESP_CONTENT_TYPE], "%s",
763 kmimetypes[mime]);
764 khttp_head(gw_trans->gw_req, "X-Content-Type-Options", "nosniff");
765 khttp_head(gw_trans->gw_req, "X-Frame-Options", "DENY");
766 khttp_head(gw_trans->gw_req, "X-XSS-Protection", "1; mode=block");
767 khttp_body(gw_trans->gw_req);
770 static void
771 gw_display_index(struct trans *gw_trans, const struct got_error *err)
773 gw_display_open(gw_trans, KHTTP_200, gw_trans->mime);
774 khtml_open(gw_trans->gw_html_req, gw_trans->gw_req, 0);
776 if (err)
777 khttp_puts(gw_trans->gw_req, err->msg);
778 else
779 khttp_template(gw_trans->gw_req, gw_trans->gw_tmpl,
780 gw_query_funcs[gw_trans->action].template);
782 khtml_close(gw_trans->gw_html_req);
785 static int
786 gw_template(size_t key, void *arg)
788 const struct got_error *error = NULL;
789 struct trans *gw_trans = arg;
790 char *gw_got_link, *gw_site_link;
791 char *site_owner_name, *site_owner_name_h;
793 switch (key) {
794 case (TEMPL_HEAD):
795 khttp_puts(gw_trans->gw_req, head);
796 break;
797 case(TEMPL_HEADER):
798 gw_got_link = gw_get_got_link(gw_trans);
799 if (gw_got_link != NULL)
800 khttp_puts(gw_trans->gw_req, gw_got_link);
802 free(gw_got_link);
803 break;
804 case (TEMPL_SITEPATH):
805 gw_site_link = gw_get_site_link(gw_trans);
806 if (gw_site_link != NULL)
807 khttp_puts(gw_trans->gw_req, gw_site_link);
809 free(gw_site_link);
810 break;
811 case(TEMPL_TITLE):
812 if (gw_trans->gw_conf->got_site_name != NULL)
813 khtml_puts(gw_trans->gw_html_req,
814 gw_trans->gw_conf->got_site_name);
816 break;
817 case (TEMPL_SEARCH):
818 khttp_puts(gw_trans->gw_req, search);
819 break;
820 case(TEMPL_SITEOWNER):
821 if (gw_trans->gw_conf->got_site_owner != NULL &&
822 gw_trans->gw_conf->got_show_site_owner) {
823 site_owner_name =
824 gw_html_escape(gw_trans->gw_conf->got_site_owner);
825 if ((asprintf(&site_owner_name_h, site_owner,
826 site_owner_name))
827 == -1)
828 return 0;
830 khttp_puts(gw_trans->gw_req, site_owner_name_h);
831 free(site_owner_name);
832 free(site_owner_name_h);
834 break;
835 case(TEMPL_CONTENT):
836 error = gw_query_funcs[gw_trans->action].func_main(gw_trans);
837 if (error)
838 khttp_puts(gw_trans->gw_req, error->msg);
840 break;
841 default:
842 return 0;
843 break;
845 return 1;
848 static char *
849 gw_get_repo_description(struct trans *gw_trans, char *dir)
851 FILE *f;
852 char *description = NULL, *d_file = NULL;
853 unsigned int len;
855 if (gw_trans->gw_conf->got_show_repo_description == false)
856 goto err;
858 if ((asprintf(&d_file, "%s/description", dir)) == -1)
859 goto err;
861 if ((f = fopen(d_file, "r")) == NULL)
862 goto err;
864 fseek(f, 0, SEEK_END);
865 len = ftell(f) + 1;
866 fseek(f, 0, SEEK_SET);
867 if ((description = calloc(len, sizeof(char *))) == NULL)
868 goto err;
870 fread(description, 1, len, f);
871 fclose(f);
872 free(d_file);
873 return description;
874 err:
875 if ((asprintf(&description, "%s", "")) == -1)
876 return NULL;
878 return description;
881 static char *
882 gw_get_time_str(time_t committer_time, int ref_tm)
884 struct tm tm;
885 time_t diff_time;
886 char *years = "years ago", *months = "months ago";
887 char *weeks = "weeks ago", *days = "days ago", *hours = "hours ago";
888 char *minutes = "minutes ago", *seconds = "seconds ago";
889 char *now = "right now";
890 char *repo_age, *s;
891 char datebuf[BUFFER_SIZE];
893 switch (ref_tm) {
894 case TM_DIFF:
895 diff_time = time(NULL) - committer_time;
896 if (diff_time > 60 * 60 * 24 * 365 * 2) {
897 if ((asprintf(&repo_age, "%lld %s",
898 (diff_time / 60 / 60 / 24 / 365), years)) == -1)
899 return NULL;
900 } else if (diff_time > 60 * 60 * 24 * (365 / 12) * 2) {
901 if ((asprintf(&repo_age, "%lld %s",
902 (diff_time / 60 / 60 / 24 / (365 / 12)),
903 months)) == -1)
904 return NULL;
905 } else if (diff_time > 60 * 60 * 24 * 7 * 2) {
906 if ((asprintf(&repo_age, "%lld %s",
907 (diff_time / 60 / 60 / 24 / 7), weeks)) == -1)
908 return NULL;
909 } else if (diff_time > 60 * 60 * 24 * 2) {
910 if ((asprintf(&repo_age, "%lld %s",
911 (diff_time / 60 / 60 / 24), days)) == -1)
912 return NULL;
913 } else if (diff_time > 60 * 60 * 2) {
914 if ((asprintf(&repo_age, "%lld %s",
915 (diff_time / 60 / 60), hours)) == -1)
916 return NULL;
917 } else if (diff_time > 60 * 2) {
918 if ((asprintf(&repo_age, "%lld %s", (diff_time / 60),
919 minutes)) == -1)
920 return NULL;
921 } else if (diff_time > 2) {
922 if ((asprintf(&repo_age, "%lld %s", diff_time,
923 seconds)) == -1)
924 return NULL;
925 } else {
926 if ((asprintf(&repo_age, "%s", now)) == -1)
927 return NULL;
929 break;
930 case TM_LONG:
931 if (gmtime_r(&committer_time, &tm) == NULL)
932 return NULL;
934 s = asctime_r(&tm, datebuf);
935 if (s == NULL)
936 return NULL;
938 if ((asprintf(&repo_age, "%s UTC", datebuf)) == -1)
939 return NULL;
940 break;
942 return repo_age;
945 static char *
946 gw_get_repo_age(struct trans *gw_trans, char *dir, char *repo_ref, int ref_tm)
948 const struct got_error *error = NULL;
949 struct got_object_id *id = NULL;
950 struct got_repository *repo = NULL;
951 struct got_commit_object *commit = NULL;
952 struct got_reflist_head refs;
953 struct got_reflist_entry *re;
954 struct got_reference *head_ref;
955 time_t committer_time = 0, cmp_time = 0;
956 char *repo_age = NULL;
958 if (repo_ref == NULL)
959 return NULL;
961 SIMPLEQ_INIT(&refs);
962 if (gw_trans->gw_conf->got_show_repo_age == false) {
963 asprintf(&repo_age, "");
964 return repo_age;
966 error = got_repo_open(&repo, dir, NULL);
967 if (error != NULL)
968 goto err;
970 error = got_ref_list(&refs, repo, repo_ref, got_ref_cmp_by_name,
971 NULL);
972 if (error != NULL)
973 goto err;
975 const char *refname;
976 SIMPLEQ_FOREACH(re, &refs, entry) {
977 refname = got_ref_get_name(re->ref);
978 error = got_ref_open(&head_ref, repo, refname, 0);
979 if (error != NULL)
980 goto err;
982 error = got_ref_resolve(&id, repo, head_ref);
983 got_ref_close(head_ref);
984 if (error != NULL)
985 goto err;
987 /* here is what breaks tags, so adjust */
988 error = got_object_open_as_commit(&commit, repo, id);
989 if (error != NULL)
990 goto err;
992 committer_time =
993 got_object_commit_get_committer_time(commit);
995 if (cmp_time < committer_time)
996 cmp_time = committer_time;
999 if (cmp_time != 0) {
1000 committer_time = cmp_time;
1001 repo_age = gw_get_time_str(committer_time, ref_tm);
1002 } else
1003 if ((asprintf(&repo_age, "")) == -1)
1004 return NULL;
1005 got_ref_list_free(&refs);
1006 free(id);
1007 return repo_age;
1008 err:
1009 if ((asprintf(&repo_age, "%s", error->msg)) == -1)
1010 return NULL;
1012 return repo_age;
1015 static char *
1016 gw_get_repo_owner(struct trans *gw_trans, char *dir)
1018 FILE *f;
1019 char *owner = NULL, *d_file = NULL;
1020 char *gotweb = "[gotweb]", *gitweb = "[gitweb]", *gw_owner = "owner";
1021 char *comp, *pos, *buf;
1022 unsigned int i;
1024 if (gw_trans->gw_conf->got_show_repo_owner == false)
1025 goto err;
1027 if ((asprintf(&d_file, "%s/config", dir)) == -1)
1028 goto err;
1030 if ((f = fopen(d_file, "r")) == NULL)
1031 goto err;
1033 if ((buf = calloc(BUFFER_SIZE, sizeof(char *))) == NULL)
1034 goto err;
1036 while ((fgets(buf, BUFFER_SIZE, f)) != NULL) {
1037 if ((pos = strstr(buf, gotweb)) != NULL)
1038 break;
1040 if ((pos = strstr(buf, gitweb)) != NULL)
1041 break;
1044 if (pos == NULL)
1045 goto err;
1047 do {
1048 fgets(buf, BUFFER_SIZE, f);
1049 } while ((comp = strcasestr(buf, gw_owner)) == NULL);
1051 if (comp == NULL)
1052 goto err;
1054 if (strncmp(gw_owner, comp, strlen(gw_owner)) != 0)
1055 goto err;
1057 for (i = 0; i < 2; i++) {
1058 owner = strsep(&buf, "\"");
1061 if (owner == NULL)
1062 goto err;
1064 fclose(f);
1065 free(d_file);
1066 return owner;
1067 err:
1068 if ((asprintf(&owner, "%s", "")) == -1)
1069 return NULL;
1071 return owner;
1074 static char *
1075 gw_get_clone_url(struct trans *gw_trans, char *dir)
1077 FILE *f;
1078 char *url = NULL, *d_file = NULL;
1079 unsigned int len;
1081 if ((asprintf(&d_file, "%s/cloneurl", dir)) == -1)
1082 return NULL;
1084 if ((f = fopen(d_file, "r")) == NULL)
1085 return NULL;
1087 fseek(f, 0, SEEK_END);
1088 len = ftell(f) + 1;
1089 fseek(f, 0, SEEK_SET);
1091 if ((url = calloc(len, sizeof(char *))) == NULL)
1092 return NULL;
1094 fread(url, 1, len, f);
1095 fclose(f);
1096 free(d_file);
1097 return url;
1100 static char *
1101 gw_get_repo_shortlog(struct trans *gw_trans, const char *search_pattern)
1103 const struct got_error *error;
1104 struct got_repository *repo = NULL;
1105 struct got_reflist_head refs;
1106 struct got_reflist_entry *re;
1107 struct got_commit_object *commit = NULL;
1108 struct got_object_id *id = NULL;
1109 struct got_commit_graph *graph = NULL;
1110 char *start_commit = NULL, *shortlog = NULL, *id_str = NULL,
1111 *path = NULL, *in_repo_path = NULL, *commit_row = NULL,
1112 *commit_age = NULL, *commit_author = NULL, *commit_log = NULL,
1113 *shortlog_navs_html = NULL;
1114 regex_t regex;
1115 int have_match, limit = D_MAXSLCOMMDISP;
1116 size_t newsize;
1117 struct buf *diffbuf;
1118 time_t committer_time;
1120 if (search_pattern &&
1121 regcomp(&regex, search_pattern, REG_EXTENDED | REG_NOSUB |
1122 REG_NEWLINE))
1123 return NULL;
1125 SIMPLEQ_INIT(&refs);
1127 error = got_repo_open(&repo, gw_trans->repo_path, NULL);
1128 if (error != NULL)
1129 goto done;
1131 error = buf_alloc(&diffbuf, BUFFER_SIZE);
1132 if (error != NULL)
1133 goto done;
1135 if (start_commit == NULL) {
1136 struct got_reference *head_ref;
1137 error = got_ref_open(&head_ref, repo, GOT_REF_HEAD, 0);
1138 if (error != NULL)
1139 return NULL;
1140 error = got_ref_resolve(&id, repo, head_ref);
1141 got_ref_close(head_ref);
1142 if (error != NULL)
1143 return NULL;
1144 error = got_object_open_as_commit(&commit, repo, id);
1145 } else {
1146 struct got_reference *ref;
1147 error = got_ref_open(&ref, repo, start_commit, 0);
1148 if (error == NULL) {
1149 int obj_type;
1150 error = got_ref_resolve(&id, repo, ref);
1151 got_ref_close(ref);
1152 if (error != NULL)
1153 goto done;
1154 error = got_object_get_type(&obj_type, repo, id);
1155 if (error != NULL)
1156 goto done;
1157 if (obj_type == GOT_OBJ_TYPE_TAG) {
1158 struct got_tag_object *tag;
1159 error = got_object_open_as_tag(&tag, repo, id);
1160 if (error != NULL)
1161 goto done;
1162 if (got_object_tag_get_object_type(tag) !=
1163 GOT_OBJ_TYPE_COMMIT) {
1164 got_object_tag_close(tag);
1165 error = got_error(GOT_ERR_OBJ_TYPE);
1166 goto done;
1168 free(id);
1169 id = got_object_id_dup(
1170 got_object_tag_get_object_id(tag));
1171 if (id == NULL)
1172 error = got_error_from_errno(
1173 "got_object_id_dup");
1174 got_object_tag_close(tag);
1175 if (error)
1176 goto done;
1177 } else if (obj_type != GOT_OBJ_TYPE_COMMIT) {
1178 error = got_error(GOT_ERR_OBJ_TYPE);
1179 goto done;
1181 error = got_object_open_as_commit(&commit, repo, id);
1182 if (error != NULL)
1183 goto done;
1185 if (commit == NULL) {
1186 error = got_repo_match_object_id_prefix(&id,
1187 start_commit, GOT_OBJ_TYPE_COMMIT, repo);
1188 if (error != NULL)
1189 return NULL;
1193 if (error != NULL)
1194 goto done;
1196 error = got_repo_map_path(&in_repo_path, repo, gw_trans->repo_path, 1);
1197 if (error != NULL)
1198 goto done;
1200 if (in_repo_path) {
1201 free(path);
1202 path = in_repo_path;
1205 error = got_ref_list(&refs, repo, NULL, got_ref_cmp_by_name, NULL);
1206 if (error)
1207 goto done;
1209 error = got_commit_graph_open(&graph, id, path, 0, repo);
1210 if (error)
1211 goto done;
1213 error = got_commit_graph_iter_start(graph, id, repo, NULL, NULL);
1214 if (error)
1215 goto done;
1217 for (;;) {
1218 struct got_commit_object *commit_disp;
1220 error = got_commit_graph_iter_next(&id, graph);
1221 if (error) {
1222 if (error->code == GOT_ERR_ITER_COMPLETED) {
1223 error = NULL;
1224 break;
1226 if (error->code != GOT_ERR_ITER_NEED_MORE)
1227 break;
1228 error = got_commit_graph_fetch_commits(graph, 1, repo,
1229 NULL, NULL);
1230 if (error)
1231 break;
1232 else
1233 continue;
1235 if (id == NULL)
1236 break;
1238 error = got_object_open_as_commit(&commit_disp, repo, id);
1239 if (error)
1240 break;
1242 if (search_pattern) {
1243 error = match_logmsg(&have_match, id, commit_disp,
1244 &regex);
1245 if (error) {
1246 got_object_commit_close(commit_disp);
1247 break;
1249 if (have_match == 0) {
1250 got_object_commit_close(commit_disp);
1251 continue;
1255 SIMPLEQ_FOREACH(re, &refs, entry) {
1256 const char *name;
1257 struct got_tag_object *tag = NULL;
1258 int cmp;
1260 name = got_ref_get_name(re->ref);
1261 if (strcmp(name, GOT_REF_HEAD) == 0)
1262 continue;
1263 if (strncmp(name, "refs/", 5) == 0)
1264 name += 5;
1265 if (strncmp(name, "got/", 4) == 0)
1266 continue;
1267 if (strncmp(name, "heads/", 6) == 0)
1268 name += 6;
1269 if (strncmp(name, "remotes/", 8) == 0)
1270 name += 8;
1271 if (strncmp(name, "tags/", 5) == 0) {
1272 error = got_object_open_as_tag(&tag, repo,
1273 re->id);
1274 if (error) {
1275 if (error->code != GOT_ERR_OBJ_TYPE)
1276 continue;
1278 * Ref points at something other
1279 * than a tag.
1281 error = NULL;
1282 tag = NULL;
1285 cmp = got_object_id_cmp(tag ?
1286 got_object_tag_get_object_id(tag) : re->id, id);
1287 if (tag)
1288 got_object_tag_close(tag);
1289 if (cmp != 0)
1290 continue;
1293 /* commit id */
1294 error = got_object_id_str(&id_str, id);
1295 if (error)
1296 break;
1298 committer_time =
1299 got_object_commit_get_committer_time(commit_disp);
1300 asprintf(&commit_age, "%s", gw_get_time_str(committer_time,
1301 TM_DIFF));
1302 asprintf(&commit_author, "%s",
1303 got_object_commit_get_author(commit_disp));
1304 error = got_object_commit_get_logmsg(&commit_log, commit_disp);
1305 if (error)
1306 commit_log = strdup("");
1307 asprintf(&shortlog_navs_html, shortlog_navs,
1308 gw_trans->repo_name, id_str, gw_trans->repo_name, id_str,
1309 gw_trans->repo_name, id_str, gw_trans->repo_name, id_str);
1310 asprintf(&commit_row, shortlog_row, commit_age, commit_author,
1311 commit_log, shortlog_navs_html);
1312 error = buf_append(&newsize, diffbuf, commit_row,
1313 strlen(commit_row));
1315 free(commit_age);
1316 free(commit_author);
1317 free(commit_log);
1318 free(shortlog_navs_html);
1319 free(commit_row);
1320 free(id_str);
1321 commit_age = NULL;
1322 commit_author = NULL;
1323 commit_log = NULL;
1324 shortlog_navs_html = NULL;
1325 commit_row = NULL;
1326 id_str = NULL;
1328 got_object_commit_close(commit_disp);
1329 if (error || (limit && --limit == 0))
1330 break;
1332 shortlog = strdup(diffbuf->cb_buf);
1333 got_object_commit_close(commit);
1335 free(path);
1336 free(id);
1337 buf_free(diffbuf);
1339 if (repo) {
1340 error = got_repo_close(repo);
1341 if (error != NULL)
1342 return NULL;
1345 got_ref_list_free(&refs);
1346 return shortlog;
1347 done:
1348 if (repo)
1349 got_repo_close(repo);
1350 got_ref_list_free(&refs);
1352 if (search_pattern)
1353 regfree(&regex);
1354 got_commit_graph_close(graph);
1355 return NULL;
1358 static char *
1359 gw_get_repo_tags(struct trans *gw_trans)
1361 char *tags = NULL;
1363 asprintf(&tags, tags_row, "30 min ago", "1.0.0", "tag 1.0.0", tags_navs);
1364 return tags;
1367 static char *
1368 gw_get_repo_heads(struct trans *gw_trans)
1370 char *heads = NULL;
1372 asprintf(&heads, heads_row, "30 min ago", "master", heads_navs);
1373 return heads;
1376 static char *
1377 gw_get_got_link(struct trans *gw_trans)
1379 char *link;
1381 if ((asprintf(&link, got_link, gw_trans->gw_conf->got_logo_url,
1382 gw_trans->gw_conf->got_logo)) == -1)
1383 return NULL;
1385 return link;
1388 static char *
1389 gw_get_site_link(struct trans *gw_trans)
1391 char *link, *repo = "", *action = "";
1393 if (gw_trans->repo_name != NULL)
1394 if ((asprintf(&repo, " / <a href='?path=%s&action=summary'>%s" \
1395 "</a>", gw_trans->repo_name, gw_trans->repo_name)) == -1)
1396 return NULL;
1398 if (gw_trans->action_name != NULL)
1399 if ((asprintf(&action, " / %s", gw_trans->action_name)) == -1)
1400 return NULL;
1402 if ((asprintf(&link, site_link, GOTWEB,
1403 gw_trans->gw_conf->got_site_link, repo, action)) == -1)
1404 return NULL;
1406 return link;
1409 static char *
1410 gw_html_escape(const char *html)
1412 char *escaped_str = NULL, *buf;
1413 char c[1];
1414 size_t sz, i;
1416 if ((buf = calloc(BUFFER_SIZE, sizeof(char *))) == NULL)
1417 return NULL;
1419 if (html == NULL)
1420 return NULL;
1421 else
1422 if ((sz = strlen(html)) == 0)
1423 return NULL;
1425 /* only work with BUFFER_SIZE */
1426 if (BUFFER_SIZE < sz)
1427 sz = BUFFER_SIZE;
1429 for (i = 0; i < sz; i++) {
1430 c[0] = html[i];
1431 switch (c[0]) {
1432 case ('>'):
1433 strcat(buf, "&gt;");
1434 break;
1435 case ('&'):
1436 strcat(buf, "&amp;");
1437 break;
1438 case ('<'):
1439 strcat(buf, "&lt;");
1440 break;
1441 case ('"'):
1442 strcat(buf, "&quot;");
1443 break;
1444 case ('\''):
1445 strcat(buf, "&apos;");
1446 break;
1447 case ('\n'):
1448 strcat(buf, "<br />");
1449 default:
1450 strcat(buf, &c[0]);
1451 break;
1454 asprintf(&escaped_str, "%s", buf);
1455 free(buf);
1456 return escaped_str;
1459 int
1460 main()
1462 const struct got_error *error = NULL;
1463 struct trans *gw_trans;
1464 struct gw_dir *dir = NULL, *tdir;
1465 const char *page = "index";
1466 bool gw_malloc = true;
1468 if ((gw_trans = malloc(sizeof(struct trans))) == NULL)
1469 errx(1, "malloc");
1471 if ((gw_trans->gw_req = malloc(sizeof(struct kreq))) == NULL)
1472 errx(1, "malloc");
1474 if ((gw_trans->gw_html_req = malloc(sizeof(struct khtmlreq))) == NULL)
1475 errx(1, "malloc");
1477 if ((gw_trans->gw_tmpl = malloc(sizeof(struct ktemplate))) == NULL)
1478 errx(1, "malloc");
1480 if (KCGI_OK != khttp_parse(gw_trans->gw_req, gw_keys, KEY__MAX,
1481 &page, 1, 0))
1482 errx(1, "khttp_parse");
1484 if ((gw_trans->gw_conf =
1485 malloc(sizeof(struct gotweb_conf))) == NULL) {
1486 gw_malloc = false;
1487 error = got_error_from_errno("malloc");
1488 goto err;
1491 if (pledge("stdio rpath proc exec sendfd unveil", NULL) == -1) {
1492 error = got_error_from_errno("pledge");
1493 goto err;
1496 TAILQ_INIT(&gw_trans->gw_dirs);
1498 gw_trans->page = 0;
1499 gw_trans->repos_total = 0;
1500 gw_trans->repo_path = NULL;
1501 gw_trans->commit = NULL;
1502 gw_trans->mime = KMIME_TEXT_HTML;
1503 gw_trans->gw_tmpl->key = templs;
1504 gw_trans->gw_tmpl->keysz = TEMPL__MAX;
1505 gw_trans->gw_tmpl->arg = gw_trans;
1506 gw_trans->gw_tmpl->cb = gw_template;
1507 error = parse_conf(GOTWEB_CONF, gw_trans->gw_conf);
1509 err:
1510 if (error) {
1511 gw_trans->mime = KMIME_TEXT_PLAIN;
1512 gw_trans->action = GW_ERR;
1513 gw_display_index(gw_trans, error);
1514 goto done;
1517 error = gw_parse_querystring(gw_trans);
1518 if (error)
1519 goto err;
1521 gw_display_index(gw_trans, error);
1523 done:
1524 if (gw_malloc) {
1525 free(gw_trans->gw_conf->got_repos_path);
1526 free(gw_trans->gw_conf->got_www_path);
1527 free(gw_trans->gw_conf->got_site_name);
1528 free(gw_trans->gw_conf->got_site_owner);
1529 free(gw_trans->gw_conf->got_site_link);
1530 free(gw_trans->gw_conf->got_logo);
1531 free(gw_trans->gw_conf->got_logo_url);
1532 free(gw_trans->gw_conf);
1533 free(gw_trans->commit);
1534 free(gw_trans->repo_path);
1535 free(gw_trans->repo_name);
1536 free(gw_trans->repo_file);
1537 free(gw_trans->action_name);
1539 TAILQ_FOREACH_SAFE(dir, &gw_trans->gw_dirs, entry, tdir) {
1540 free(dir->name);
1541 free(dir->description);
1542 free(dir->age);
1543 free(dir->url);
1544 free(dir->path);
1545 free(dir);
1550 khttp_free(gw_trans->gw_req);
1551 return EXIT_SUCCESS;