Blame


1 2c251c14 2020-01-15 tracey /*
2 9460dac0 2020-01-15 tracey * Copyright (c) 2019, 2020 Tracey Emery <tracey@traceyemery.net>
3 2c251c14 2020-01-15 tracey * Copyright (c) 2018, 2019 Stefan Sperling <stsp@openbsd.org>
4 2c251c14 2020-01-15 tracey *
5 2c251c14 2020-01-15 tracey * Permission to use, copy, modify, and distribute this software for any
6 2c251c14 2020-01-15 tracey * purpose with or without fee is hereby granted, provided that the above
7 2c251c14 2020-01-15 tracey * copyright notice and this permission notice appear in all copies.
8 2c251c14 2020-01-15 tracey *
9 2c251c14 2020-01-15 tracey * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 2c251c14 2020-01-15 tracey * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 2c251c14 2020-01-15 tracey * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 2c251c14 2020-01-15 tracey * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 2c251c14 2020-01-15 tracey * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 2c251c14 2020-01-15 tracey * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 2c251c14 2020-01-15 tracey * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 2c251c14 2020-01-15 tracey */
17 2c251c14 2020-01-15 tracey
18 2c251c14 2020-01-15 tracey #include <sys/stat.h>
19 2c251c14 2020-01-15 tracey #include <sys/types.h>
20 2c251c14 2020-01-15 tracey
21 017d6da3 2020-01-29 tracey #include <ctype.h>
22 2c251c14 2020-01-15 tracey #include <dirent.h>
23 2c251c14 2020-01-15 tracey #include <err.h>
24 c25c2314 2020-01-28 stsp #include <errno.h>
25 474370cb 2020-01-15 tracey #include <regex.h>
26 ec242592 2022-04-22 thomas #include <sha1.h>
27 2c251c14 2020-01-15 tracey #include <stdarg.h>
28 2c251c14 2020-01-15 tracey #include <stdint.h>
29 2c251c14 2020-01-15 tracey #include <stdio.h>
30 2c251c14 2020-01-15 tracey #include <stdlib.h>
31 2c251c14 2020-01-15 tracey #include <string.h>
32 2c251c14 2020-01-15 tracey #include <unistd.h>
33 2c251c14 2020-01-15 tracey
34 c34ec417 2020-06-22 tracey #include <got_error.h>
35 2c251c14 2020-01-15 tracey #include <got_object.h>
36 2c251c14 2020-01-15 tracey #include <got_reference.h>
37 2c251c14 2020-01-15 tracey #include <got_repository.h>
38 2c251c14 2020-01-15 tracey #include <got_path.h>
39 2c251c14 2020-01-15 tracey #include <got_cancel.h>
40 2c251c14 2020-01-15 tracey #include <got_worktree.h>
41 2c251c14 2020-01-15 tracey #include <got_diff.h>
42 2c251c14 2020-01-15 tracey #include <got_commit_graph.h>
43 2c251c14 2020-01-15 tracey #include <got_blame.h>
44 2c251c14 2020-01-15 tracey #include <got_privsep.h>
45 2c251c14 2020-01-15 tracey #include <got_opentemp.h>
46 2c251c14 2020-01-15 tracey
47 2c251c14 2020-01-15 tracey #include <kcgi.h>
48 2c251c14 2020-01-15 tracey #include <kcgihtml.h>
49 2c251c14 2020-01-15 tracey
50 2c251c14 2020-01-15 tracey #include "gotweb.h"
51 2c251c14 2020-01-15 tracey
52 2c251c14 2020-01-15 tracey #ifndef nitems
53 2c251c14 2020-01-15 tracey #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
54 2c251c14 2020-01-15 tracey #endif
55 2c251c14 2020-01-15 tracey
56 54415d85 2020-01-15 tracey struct gw_trans {
57 f2f46662 2020-01-23 tracey TAILQ_HEAD(headers, gw_header) gw_headers;
58 f2f46662 2020-01-23 tracey TAILQ_HEAD(dirs, gw_dir) gw_dirs;
59 deac617c 2020-02-14 tracey struct got_repository *repo;
60 46b9c89b 2020-01-15 tracey struct gw_dir *gw_dir;
61 c34ec417 2020-06-22 tracey struct gotweb_config *gw_conf;
62 2c251c14 2020-01-15 tracey struct ktemplate *gw_tmpl;
63 2c251c14 2020-01-15 tracey struct khtmlreq *gw_html_req;
64 2c251c14 2020-01-15 tracey struct kreq *gw_req;
65 f1200fe3 2020-02-13 tracey const struct got_error *error;
66 f652ec0c 2020-02-13 stsp const char *repo_name;
67 2c251c14 2020-01-15 tracey char *repo_path;
68 56997cd3 2020-02-14 tracey char *commit_id;
69 55e46400 2020-02-18 tracey char *next_id;
70 55e46400 2020-02-18 tracey char *prev_id;
71 4d6abe2b 2020-02-13 stsp const char *repo_file;
72 ec46ccd7 2020-01-15 tracey char *repo_folder;
73 742ba378 2020-02-14 stsp const char *headref;
74 2c251c14 2020-01-15 tracey unsigned int action;
75 2c251c14 2020-01-15 tracey unsigned int page;
76 2c251c14 2020-01-15 tracey unsigned int repos_total;
77 387a29ba 2020-01-15 tracey enum kmime mime;
78 e0fb2ce2 2022-06-23 thomas int *pack_fds;
79 2c251c14 2020-01-15 tracey };
80 2c251c14 2020-01-15 tracey
81 f2f46662 2020-01-23 tracey struct gw_header {
82 f2f46662 2020-01-23 tracey TAILQ_ENTRY(gw_header) entry;
83 f2f46662 2020-01-23 tracey struct got_reflist_head refs;
84 f2f46662 2020-01-23 tracey char *path;
85 f2f46662 2020-01-23 tracey
86 f2f46662 2020-01-23 tracey char *refs_str;
87 f2f46662 2020-01-23 tracey char *commit_id; /* id_str1 */
88 f2f46662 2020-01-23 tracey char *parent_id; /* id_str2 */
89 f2f46662 2020-01-23 tracey char *tree_id;
90 4e8d6e3e 2020-02-14 tracey char *author;
91 4e8d6e3e 2020-02-14 tracey char *committer;
92 f2f46662 2020-01-23 tracey char *commit_msg;
93 f2f46662 2020-01-23 tracey time_t committer_time;
94 2c251c14 2020-01-15 tracey };
95 2c251c14 2020-01-15 tracey
96 2c251c14 2020-01-15 tracey struct gw_dir {
97 2c251c14 2020-01-15 tracey TAILQ_ENTRY(gw_dir) entry;
98 2c251c14 2020-01-15 tracey char *name;
99 2c251c14 2020-01-15 tracey char *owner;
100 2c251c14 2020-01-15 tracey char *description;
101 2c251c14 2020-01-15 tracey char *url;
102 2c251c14 2020-01-15 tracey char *age;
103 2c251c14 2020-01-15 tracey char *path;
104 2c251c14 2020-01-15 tracey };
105 2c251c14 2020-01-15 tracey
106 f2f46662 2020-01-23 tracey enum gw_key {
107 f2f46662 2020-01-23 tracey KEY_ACTION,
108 f2f46662 2020-01-23 tracey KEY_COMMIT_ID,
109 f2f46662 2020-01-23 tracey KEY_FILE,
110 f2f46662 2020-01-23 tracey KEY_FOLDER,
111 f2f46662 2020-01-23 tracey KEY_HEADREF,
112 f2f46662 2020-01-23 tracey KEY_PAGE,
113 f2f46662 2020-01-23 tracey KEY_PATH,
114 55e46400 2020-02-18 tracey KEY_PREV_ID,
115 f2f46662 2020-01-23 tracey KEY__ZMAX
116 f2f46662 2020-01-23 tracey };
117 f2f46662 2020-01-23 tracey
118 54415d85 2020-01-15 tracey enum gw_tmpl {
119 f2f46662 2020-01-23 tracey TEMPL_CONTENT,
120 2c251c14 2020-01-15 tracey TEMPL_HEAD,
121 2c251c14 2020-01-15 tracey TEMPL_HEADER,
122 f2f46662 2020-01-23 tracey TEMPL_SEARCH,
123 2c251c14 2020-01-15 tracey TEMPL_SITEPATH,
124 2c251c14 2020-01-15 tracey TEMPL_SITEOWNER,
125 2c251c14 2020-01-15 tracey TEMPL_TITLE,
126 2c251c14 2020-01-15 tracey TEMPL__MAX
127 2c251c14 2020-01-15 tracey };
128 2c251c14 2020-01-15 tracey
129 54415d85 2020-01-15 tracey enum gw_ref_tm {
130 387a29ba 2020-01-15 tracey TM_DIFF,
131 387a29ba 2020-01-15 tracey TM_LONG,
132 387a29ba 2020-01-15 tracey };
133 387a29ba 2020-01-15 tracey
134 ff4bb25f 2020-02-19 tracey enum gw_tags_type {
135 87f9ebf5 2020-01-15 tracey TAGBRIEF,
136 87f9ebf5 2020-01-15 tracey TAGFULL,
137 87f9ebf5 2020-01-15 tracey };
138 87f9ebf5 2020-01-15 tracey
139 54415d85 2020-01-15 tracey static const char *const gw_templs[TEMPL__MAX] = {
140 f2f46662 2020-01-23 tracey "content",
141 2c251c14 2020-01-15 tracey "head",
142 2c251c14 2020-01-15 tracey "header",
143 f2f46662 2020-01-23 tracey "search",
144 2c251c14 2020-01-15 tracey "sitepath",
145 2c251c14 2020-01-15 tracey "siteowner",
146 2c251c14 2020-01-15 tracey "title",
147 2c251c14 2020-01-15 tracey };
148 2c251c14 2020-01-15 tracey
149 ec46ccd7 2020-01-15 tracey static const struct kvalid gw_keys[KEY__ZMAX] = {
150 2c251c14 2020-01-15 tracey { kvalid_stringne, "action" },
151 2c251c14 2020-01-15 tracey { kvalid_stringne, "commit" },
152 2c251c14 2020-01-15 tracey { kvalid_stringne, "file" },
153 ec46ccd7 2020-01-15 tracey { kvalid_stringne, "folder" },
154 8087c3c5 2020-01-15 tracey { kvalid_stringne, "headref" },
155 ec46ccd7 2020-01-15 tracey { kvalid_int, "page" },
156 ec46ccd7 2020-01-15 tracey { kvalid_stringne, "path" },
157 55e46400 2020-02-18 tracey { kvalid_stringne, "prev" },
158 2c251c14 2020-01-15 tracey };
159 2c251c14 2020-01-15 tracey
160 f2f46662 2020-01-23 tracey static struct gw_header *gw_init_header(void);
161 2c251c14 2020-01-15 tracey
162 b0a1bc86 2020-02-14 stsp static void gw_free_header(struct gw_header *);
163 00f13350 2020-02-10 tracey
164 00f13350 2020-02-10 tracey static int gw_template(size_t, void *);
165 00f13350 2020-02-10 tracey
166 f1200fe3 2020-02-13 tracey static const struct got_error *gw_error(struct gw_trans *);
167 f1200fe3 2020-02-13 tracey static const struct got_error *gw_init_gw_dir(struct gw_dir **, const char *);
168 185ba3ba 2020-02-04 tracey static const struct got_error *gw_get_repo_description(char **,
169 185ba3ba 2020-02-04 tracey struct gw_trans *, char *);
170 9a1cc63f 2020-02-03 stsp static const struct got_error *gw_get_repo_owner(char **, struct gw_trans *,
171 2c251c14 2020-01-15 tracey char *);
172 55ccf528 2020-02-03 stsp static const struct got_error *gw_get_time_str(char **, time_t, int);
173 d126c1b7 2020-01-29 stsp static const struct got_error *gw_get_repo_age(char **, struct gw_trans *,
174 2011c142 2020-02-14 stsp char *, const char *, int);
175 84de9106 2020-12-26 stsp static const struct got_error *gw_output_file_blame(struct gw_trans *,
176 84de9106 2020-12-26 stsp struct gw_header *);
177 84de9106 2020-12-26 stsp static const struct got_error *gw_output_blob_buf(struct gw_trans *,
178 84de9106 2020-12-26 stsp struct gw_header *);
179 84de9106 2020-12-26 stsp static const struct got_error *gw_output_repo_tree(struct gw_trans *,
180 84de9106 2020-12-26 stsp struct gw_header *);
181 38b240fb 2020-02-06 tracey static const struct got_error *gw_output_diff(struct gw_trans *,
182 f2f46662 2020-01-23 tracey struct gw_header *);
183 38b240fb 2020-02-06 tracey static const struct got_error *gw_output_repo_tags(struct gw_trans *,
184 4ff7391f 2020-01-28 tracey struct gw_header *, int, int);
185 9eed6f10 2020-02-08 tracey static const struct got_error *gw_output_repo_heads(struct gw_trans *);
186 4ae179a2 2020-02-08 tracey static const struct got_error *gw_output_site_link(struct gw_trans *);
187 185ba3ba 2020-02-04 tracey static const struct got_error *gw_get_clone_url(char **, struct gw_trans *,
188 185ba3ba 2020-02-04 tracey char *);
189 f7cc9480 2020-02-05 tracey static const struct got_error *gw_colordiff_line(struct gw_trans *, char *);
190 2c251c14 2020-01-15 tracey
191 21a55cc7 2020-02-04 tracey static const struct got_error *gw_gen_commit_header(struct gw_trans *, char *,
192 21a55cc7 2020-02-04 tracey char*);
193 f7cc9480 2020-02-05 tracey static const struct got_error *gw_gen_diff_header(struct gw_trans *, char *,
194 f7cc9480 2020-02-05 tracey char*);
195 21a55cc7 2020-02-04 tracey static const struct got_error *gw_gen_author_header(struct gw_trans *,
196 21a55cc7 2020-02-04 tracey const char *);
197 21a55cc7 2020-02-04 tracey static const struct got_error *gw_gen_age_header(struct gw_trans *,
198 21a55cc7 2020-02-04 tracey const char *);
199 21a55cc7 2020-02-04 tracey static const struct got_error *gw_gen_committer_header(struct gw_trans *,
200 21a55cc7 2020-02-04 tracey const char *);
201 f7cc9480 2020-02-05 tracey static const struct got_error *gw_gen_commit_msg_header(struct gw_trans*,
202 f7cc9480 2020-02-05 tracey char *);
203 f7cc9480 2020-02-05 tracey static const struct got_error *gw_gen_tree_header(struct gw_trans *, char *);
204 00f13350 2020-02-10 tracey static const struct got_error *gw_display_open(struct gw_trans *, enum khttp,
205 2c251c14 2020-01-15 tracey enum kmime);
206 00f13350 2020-02-10 tracey static const struct got_error *gw_display_index(struct gw_trans *);
207 00f13350 2020-02-10 tracey static const struct got_error *gw_get_header(struct gw_trans *,
208 f2f46662 2020-01-23 tracey struct gw_header *, int);
209 00f13350 2020-02-10 tracey static const struct got_error *gw_get_commits(struct gw_trans *,
210 3c245a0e 2020-02-14 tracey struct gw_header *, int,
211 3c245a0e 2020-02-14 tracey struct got_object_id *);
212 00f13350 2020-02-10 tracey static const struct got_error *gw_get_commit(struct gw_trans *,
213 4e8d6e3e 2020-02-14 tracey struct gw_header *,
214 4e8d6e3e 2020-02-14 tracey struct got_commit_object *,
215 3c245a0e 2020-02-14 tracey struct got_object_id *);
216 d4159696 2020-02-13 stsp static const struct got_error *gw_apply_unveil(const char *);
217 00f13350 2020-02-10 tracey static const struct got_error *gw_blame_cb(void *, int, int,
218 10f173fe 2022-04-16 thomas struct got_commit_object *,
219 ec46ccd7 2020-01-15 tracey struct got_object_id *);
220 00f13350 2020-02-10 tracey static const struct got_error *gw_load_got_paths(struct gw_trans *);
221 00f13350 2020-02-10 tracey static const struct got_error *gw_load_got_path(struct gw_trans *,
222 2c251c14 2020-01-15 tracey struct gw_dir *);
223 00f13350 2020-02-10 tracey static const struct got_error *gw_parse_querystring(struct gw_trans *);
224 00f13350 2020-02-10 tracey static const struct got_error *gw_blame(struct gw_trans *);
225 00f13350 2020-02-10 tracey static const struct got_error *gw_blob(struct gw_trans *);
226 00f13350 2020-02-10 tracey static const struct got_error *gw_diff(struct gw_trans *);
227 00f13350 2020-02-10 tracey static const struct got_error *gw_index(struct gw_trans *);
228 00f13350 2020-02-10 tracey static const struct got_error *gw_commits(struct gw_trans *);
229 00f13350 2020-02-10 tracey static const struct got_error *gw_briefs(struct gw_trans *);
230 00f13350 2020-02-10 tracey static const struct got_error *gw_summary(struct gw_trans *);
231 00f13350 2020-02-10 tracey static const struct got_error *gw_tree(struct gw_trans *);
232 00f13350 2020-02-10 tracey static const struct got_error *gw_tag(struct gw_trans *);
233 ff4bb25f 2020-02-19 tracey static const struct got_error *gw_tags(struct gw_trans *);
234 2c251c14 2020-01-15 tracey
235 2c251c14 2020-01-15 tracey struct gw_query_action {
236 2c251c14 2020-01-15 tracey unsigned int func_id;
237 2c251c14 2020-01-15 tracey const char *func_name;
238 54415d85 2020-01-15 tracey const struct got_error *(*func_main)(struct gw_trans *);
239 0c6f49ba 2022-07-01 thomas const char *template;
240 2c251c14 2020-01-15 tracey };
241 2c251c14 2020-01-15 tracey
242 2c251c14 2020-01-15 tracey enum gw_query_actions {
243 2c251c14 2020-01-15 tracey GW_BLAME,
244 e46f587c 2020-01-29 tracey GW_BLOB,
245 f2f46662 2020-01-23 tracey GW_BRIEFS,
246 f2f46662 2020-01-23 tracey GW_COMMITS,
247 f2f46662 2020-01-23 tracey GW_DIFF,
248 2c251c14 2020-01-15 tracey GW_ERR,
249 2c251c14 2020-01-15 tracey GW_INDEX,
250 2c251c14 2020-01-15 tracey GW_SUMMARY,
251 4ff7391f 2020-01-28 tracey GW_TAG,
252 ff4bb25f 2020-02-19 tracey GW_TAGS,
253 b772de24 2020-01-15 tracey GW_TREE,
254 2c251c14 2020-01-15 tracey };
255 2c251c14 2020-01-15 tracey
256 fa8129f7 2022-03-22 thomas static const struct gw_query_action gw_query_funcs[] = {
257 f2f46662 2020-01-23 tracey { GW_BLAME, "blame", gw_blame, "gw_tmpl/blame.tmpl" },
258 017d6da3 2020-01-29 tracey { GW_BLOB, "blob", NULL, NULL },
259 f2f46662 2020-01-23 tracey { GW_BRIEFS, "briefs", gw_briefs, "gw_tmpl/briefs.tmpl" },
260 f2f46662 2020-01-23 tracey { GW_COMMITS, "commits", gw_commits, "gw_tmpl/commit.tmpl" },
261 f2f46662 2020-01-23 tracey { GW_DIFF, "diff", gw_diff, "gw_tmpl/diff.tmpl" },
262 f1200fe3 2020-02-13 tracey { GW_ERR, "error", gw_error, "gw_tmpl/err.tmpl" },
263 f2f46662 2020-01-23 tracey { GW_INDEX, "index", gw_index, "gw_tmpl/index.tmpl" },
264 f2f46662 2020-01-23 tracey { GW_SUMMARY, "summary", gw_summary, "gw_tmpl/summry.tmpl" },
265 4ff7391f 2020-01-28 tracey { GW_TAG, "tag", gw_tag, "gw_tmpl/tag.tmpl" },
266 ff4bb25f 2020-02-19 tracey { GW_TAGS, "tags", gw_tags, "gw_tmpl/tags.tmpl" },
267 f2f46662 2020-01-23 tracey { GW_TREE, "tree", gw_tree, "gw_tmpl/tree.tmpl" },
268 2c251c14 2020-01-15 tracey };
269 5d1296de 2020-02-13 stsp
270 5d1296de 2020-02-13 stsp static const char *
271 5d1296de 2020-02-13 stsp gw_get_action_name(struct gw_trans *gw_trans)
272 5d1296de 2020-02-13 stsp {
273 5d1296de 2020-02-13 stsp return gw_query_funcs[gw_trans->action].func_name;
274 5d1296de 2020-02-13 stsp }
275 c25c2314 2020-01-28 stsp
276 c25c2314 2020-01-28 stsp static const struct got_error *
277 c25c2314 2020-01-28 stsp gw_kcgi_error(enum kcgi_err kerr)
278 c25c2314 2020-01-28 stsp {
279 c25c2314 2020-01-28 stsp if (kerr == KCGI_OK)
280 c25c2314 2020-01-28 stsp return NULL;
281 c25c2314 2020-01-28 stsp
282 c25c2314 2020-01-28 stsp if (kerr == KCGI_EXIT || kerr == KCGI_HUP)
283 c25c2314 2020-01-28 stsp return got_error(GOT_ERR_CANCELLED);
284 c25c2314 2020-01-28 stsp
285 c25c2314 2020-01-28 stsp if (kerr == KCGI_ENOMEM)
286 f7cc9480 2020-02-05 tracey return got_error_set_errno(ENOMEM,
287 7afec891 2020-02-06 stsp kcgi_strerror(kerr));
288 2c251c14 2020-01-15 tracey
289 c25c2314 2020-01-28 stsp if (kerr == KCGI_ENFILE)
290 f7cc9480 2020-02-05 tracey return got_error_set_errno(ENFILE,
291 7afec891 2020-02-06 stsp kcgi_strerror(kerr));
292 c25c2314 2020-01-28 stsp
293 c25c2314 2020-01-28 stsp if (kerr == KCGI_EAGAIN)
294 f7cc9480 2020-02-05 tracey return got_error_set_errno(EAGAIN,
295 7afec891 2020-02-06 stsp kcgi_strerror(kerr));
296 c25c2314 2020-01-28 stsp
297 c25c2314 2020-01-28 stsp if (kerr == KCGI_FORM)
298 f7cc9480 2020-02-05 tracey return got_error_msg(GOT_ERR_IO,
299 7afec891 2020-02-06 stsp kcgi_strerror(kerr));
300 c25c2314 2020-01-28 stsp
301 7afec891 2020-02-06 stsp return got_error_from_errno(kcgi_strerror(kerr));
302 c25c2314 2020-01-28 stsp }
303 c25c2314 2020-01-28 stsp
304 2c251c14 2020-01-15 tracey static const struct got_error *
305 d4159696 2020-02-13 stsp gw_apply_unveil(const char *repo_path)
306 2c251c14 2020-01-15 tracey {
307 2c251c14 2020-01-15 tracey const struct got_error *err;
308 2c251c14 2020-01-15 tracey
309 245c7240 2021-06-17 stsp #ifdef PROFILE
310 245c7240 2021-06-17 stsp if (unveil("gmon.out", "rwc") != 0)
311 245c7240 2021-06-17 stsp return got_error_from_errno2("unveil", "gmon.out");
312 245c7240 2021-06-17 stsp #endif
313 2c251c14 2020-01-15 tracey if (repo_path && unveil(repo_path, "r") != 0)
314 2c251c14 2020-01-15 tracey return got_error_from_errno2("unveil", repo_path);
315 2c251c14 2020-01-15 tracey
316 bb63914a 2020-02-17 stsp if (unveil(GOT_TMPDIR_STR, "rwc") != 0)
317 bb63914a 2020-02-17 stsp return got_error_from_errno2("unveil", GOT_TMPDIR_STR);
318 2c251c14 2020-01-15 tracey
319 2c251c14 2020-01-15 tracey err = got_privsep_unveil_exec_helpers();
320 2c251c14 2020-01-15 tracey if (err != NULL)
321 2c251c14 2020-01-15 tracey return err;
322 2c251c14 2020-01-15 tracey
323 2c251c14 2020-01-15 tracey if (unveil(NULL, NULL) != 0)
324 2c251c14 2020-01-15 tracey return got_error_from_errno("unveil");
325 65b95fb2 2020-01-15 tracey
326 32cd4d18 2020-02-03 stsp return NULL;
327 5894d523 2020-02-03 stsp }
328 5894d523 2020-02-03 stsp
329 5894d523 2020-02-03 stsp static int
330 e0857cfe 2020-02-06 tracey isbinary(const uint8_t *buf, size_t n)
331 5894d523 2020-02-03 stsp {
332 e0857cfe 2020-02-06 tracey size_t i;
333 e0857cfe 2020-02-06 tracey
334 e0857cfe 2020-02-06 tracey for (i = 0; i < n; i++)
335 e0857cfe 2020-02-06 tracey if (buf[i] == 0)
336 e0857cfe 2020-02-06 tracey return 1;
337 e0857cfe 2020-02-06 tracey return 0;
338 32cd4d18 2020-02-03 stsp }
339 5894d523 2020-02-03 stsp
340 32cd4d18 2020-02-03 stsp static const struct got_error *
341 54415d85 2020-01-15 tracey gw_blame(struct gw_trans *gw_trans)
342 2c251c14 2020-01-15 tracey {
343 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
344 f2f46662 2020-01-23 tracey struct gw_header *header = NULL;
345 78a9dab5 2020-02-07 tracey char *age = NULL;
346 1b33afc0 2020-02-14 tracey enum kcgi_err kerr = KCGI_OK;
347 2c251c14 2020-01-15 tracey
348 7a6dddae 2021-06-18 stsp #ifndef PROFILE
349 6bee13de 2020-01-16 tracey if (pledge("stdio rpath wpath cpath proc exec sendfd unveil",
350 f2f46662 2020-01-23 tracey NULL) == -1)
351 f2f46662 2020-01-23 tracey return got_error_from_errno("pledge");
352 7a6dddae 2021-06-18 stsp #endif
353 f2f46662 2020-01-23 tracey if ((header = gw_init_header()) == NULL)
354 f2f46662 2020-01-23 tracey return got_error_from_errno("malloc");
355 f2f46662 2020-01-23 tracey
356 d4159696 2020-02-13 stsp error = gw_apply_unveil(gw_trans->gw_dir->path);
357 ec46ccd7 2020-01-15 tracey if (error)
358 5ddf0079 2020-01-29 stsp goto done;
359 ec46ccd7 2020-01-15 tracey
360 1b33afc0 2020-02-14 tracey /* check querystring */
361 1b33afc0 2020-02-14 tracey if (gw_trans->repo_file == NULL) {
362 1b33afc0 2020-02-14 tracey error = got_error_msg(GOT_ERR_QUERYSTRING,
363 1b33afc0 2020-02-14 tracey "file required in querystring");
364 1b33afc0 2020-02-14 tracey goto done;
365 1b33afc0 2020-02-14 tracey }
366 1b33afc0 2020-02-14 tracey if (gw_trans->commit_id == NULL) {
367 1b33afc0 2020-02-14 tracey error = got_error_msg(GOT_ERR_QUERYSTRING,
368 1b33afc0 2020-02-14 tracey "commit required in querystring");
369 1b33afc0 2020-02-14 tracey goto done;
370 1b33afc0 2020-02-14 tracey }
371 1b33afc0 2020-02-14 tracey
372 f2f46662 2020-01-23 tracey error = gw_get_header(gw_trans, header, 1);
373 f2f46662 2020-01-23 tracey if (error)
374 5ddf0079 2020-01-29 stsp goto done;
375 9a9d12ca 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
376 9a9d12ca 2020-02-06 tracey "blame_header_wrapper", KATTR__MAX);
377 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
378 9a9d12ca 2020-02-06 tracey goto done;
379 9a9d12ca 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
380 9a9d12ca 2020-02-06 tracey "blame_header", KATTR__MAX);
381 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
382 9a9d12ca 2020-02-06 tracey goto done;
383 9a9d12ca 2020-02-06 tracey error = gw_get_time_str(&age, header->committer_time,
384 9a9d12ca 2020-02-06 tracey TM_LONG);
385 a81f3554 2020-02-03 stsp if (error)
386 a81f3554 2020-02-03 stsp goto done;
387 9a9d12ca 2020-02-06 tracey error = gw_gen_age_header(gw_trans, age ?age : "");
388 55ccf528 2020-02-03 stsp if (error)
389 55ccf528 2020-02-03 stsp goto done;
390 9a9d12ca 2020-02-06 tracey error = gw_gen_commit_msg_header(gw_trans, header->commit_msg);
391 9a9d12ca 2020-02-06 tracey if (error)
392 6d9fc692 2020-01-28 stsp goto done;
393 9a9d12ca 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
394 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
395 6d9fc692 2020-01-28 stsp goto done;
396 9a9d12ca 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
397 9a9d12ca 2020-02-06 tracey "dotted_line", KATTR__MAX);
398 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
399 9a9d12ca 2020-02-06 tracey goto done;
400 9a9d12ca 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
401 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
402 9a9d12ca 2020-02-06 tracey goto done;
403 9a9d12ca 2020-02-06 tracey
404 9a9d12ca 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
405 9a9d12ca 2020-02-06 tracey "blame", KATTR__MAX);
406 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
407 9a9d12ca 2020-02-06 tracey goto done;
408 84de9106 2020-12-26 stsp error = gw_output_file_blame(gw_trans, header);
409 9a9d12ca 2020-02-06 tracey if (error)
410 9a9d12ca 2020-02-06 tracey goto done;
411 9a9d12ca 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
412 6d9fc692 2020-01-28 stsp done:
413 b0a1bc86 2020-02-14 stsp gw_free_header(header);
414 9a9d12ca 2020-02-06 tracey if (error == NULL && kerr != KCGI_OK)
415 9a9d12ca 2020-02-06 tracey error = gw_kcgi_error(kerr);
416 2c251c14 2020-01-15 tracey return error;
417 2c251c14 2020-01-15 tracey }
418 2c251c14 2020-01-15 tracey
419 2c251c14 2020-01-15 tracey static const struct got_error *
420 e46f587c 2020-01-29 tracey gw_blob(struct gw_trans *gw_trans)
421 e46f587c 2020-01-29 tracey {
422 3b7fdcf4 2020-02-14 tracey const struct got_error *error = NULL, *err = NULL;
423 e46f587c 2020-01-29 tracey struct gw_header *header = NULL;
424 3b7fdcf4 2020-02-14 tracey enum kcgi_err kerr = KCGI_OK;
425 e46f587c 2020-01-29 tracey
426 7a6dddae 2021-06-18 stsp #ifndef PROFILE
427 e46f587c 2020-01-29 tracey if (pledge("stdio rpath wpath cpath proc exec sendfd unveil",
428 e46f587c 2020-01-29 tracey NULL) == -1)
429 e46f587c 2020-01-29 tracey return got_error_from_errno("pledge");
430 7a6dddae 2021-06-18 stsp #endif
431 e46f587c 2020-01-29 tracey if ((header = gw_init_header()) == NULL)
432 e46f587c 2020-01-29 tracey return got_error_from_errno("malloc");
433 e46f587c 2020-01-29 tracey
434 d4159696 2020-02-13 stsp error = gw_apply_unveil(gw_trans->gw_dir->path);
435 e46f587c 2020-01-29 tracey if (error)
436 e46f587c 2020-01-29 tracey goto done;
437 e46f587c 2020-01-29 tracey
438 3b7fdcf4 2020-02-14 tracey /* check querystring */
439 3b7fdcf4 2020-02-14 tracey if (gw_trans->repo_file == NULL) {
440 3b7fdcf4 2020-02-14 tracey error = got_error_msg(GOT_ERR_QUERYSTRING,
441 3b7fdcf4 2020-02-14 tracey "file required in querystring");
442 3b7fdcf4 2020-02-14 tracey goto done;
443 3b7fdcf4 2020-02-14 tracey }
444 3b7fdcf4 2020-02-14 tracey if (gw_trans->commit_id == NULL) {
445 3b7fdcf4 2020-02-14 tracey error = got_error_msg(GOT_ERR_QUERYSTRING,
446 3b7fdcf4 2020-02-14 tracey "commit required in querystring");
447 3b7fdcf4 2020-02-14 tracey goto done;
448 3b7fdcf4 2020-02-14 tracey }
449 e46f587c 2020-01-29 tracey error = gw_get_header(gw_trans, header, 1);
450 e46f587c 2020-01-29 tracey if (error)
451 e46f587c 2020-01-29 tracey goto done;
452 e46f587c 2020-01-29 tracey
453 84de9106 2020-12-26 stsp error = gw_output_blob_buf(gw_trans, header);
454 e46f587c 2020-01-29 tracey done:
455 3b7fdcf4 2020-02-14 tracey if (error) {
456 3b7fdcf4 2020-02-14 tracey gw_trans->mime = KMIME_TEXT_PLAIN;
457 3b7fdcf4 2020-02-14 tracey err = gw_display_index(gw_trans);
458 3b7fdcf4 2020-02-14 tracey if (err) {
459 3b7fdcf4 2020-02-14 tracey error = err;
460 3b7fdcf4 2020-02-14 tracey goto errored;
461 3b7fdcf4 2020-02-14 tracey }
462 3b7fdcf4 2020-02-14 tracey kerr = khttp_puts(gw_trans->gw_req, error->msg);
463 3b7fdcf4 2020-02-14 tracey }
464 3b7fdcf4 2020-02-14 tracey errored:
465 b0a1bc86 2020-02-14 stsp gw_free_header(header);
466 3b7fdcf4 2020-02-14 tracey if (error == NULL && kerr != KCGI_OK)
467 3b7fdcf4 2020-02-14 tracey error = gw_kcgi_error(kerr);
468 e46f587c 2020-01-29 tracey return error;
469 e46f587c 2020-01-29 tracey }
470 e46f587c 2020-01-29 tracey
471 e46f587c 2020-01-29 tracey static const struct got_error *
472 f2f46662 2020-01-23 tracey gw_diff(struct gw_trans *gw_trans)
473 2c251c14 2020-01-15 tracey {
474 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
475 f2f46662 2020-01-23 tracey struct gw_header *header = NULL;
476 78a9dab5 2020-02-07 tracey char *age = NULL;
477 f7cc9480 2020-02-05 tracey enum kcgi_err kerr = KCGI_OK;
478 2c251c14 2020-01-15 tracey
479 7a6dddae 2021-06-18 stsp #ifndef PROFILE
480 f2f46662 2020-01-23 tracey if (pledge("stdio rpath wpath cpath proc exec sendfd unveil",
481 f2f46662 2020-01-23 tracey NULL) == -1)
482 f2f46662 2020-01-23 tracey return got_error_from_errno("pledge");
483 7a6dddae 2021-06-18 stsp #endif
484 ae36ed87 2020-01-28 stsp if ((header = gw_init_header()) == NULL)
485 f2f46662 2020-01-23 tracey return got_error_from_errno("malloc");
486 f2f46662 2020-01-23 tracey
487 d4159696 2020-02-13 stsp error = gw_apply_unveil(gw_trans->gw_dir->path);
488 8087c3c5 2020-01-15 tracey if (error)
489 390d412c 2020-01-28 stsp goto done;
490 8087c3c5 2020-01-15 tracey
491 f2f46662 2020-01-23 tracey error = gw_get_header(gw_trans, header, 1);
492 f2f46662 2020-01-23 tracey if (error)
493 55ccf528 2020-02-03 stsp goto done;
494 f7cc9480 2020-02-05 tracey
495 f7cc9480 2020-02-05 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
496 f7cc9480 2020-02-05 tracey "diff_header_wrapper", KATTR__MAX);
497 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
498 f7cc9480 2020-02-05 tracey goto done;
499 f7cc9480 2020-02-05 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
500 f7cc9480 2020-02-05 tracey "diff_header", KATTR__MAX);
501 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
502 f7cc9480 2020-02-05 tracey goto done;
503 f7cc9480 2020-02-05 tracey error = gw_gen_diff_header(gw_trans, header->parent_id,
504 f7cc9480 2020-02-05 tracey header->commit_id);
505 f7cc9480 2020-02-05 tracey if (error)
506 f7cc9480 2020-02-05 tracey goto done;
507 f7cc9480 2020-02-05 tracey error = gw_gen_commit_header(gw_trans, header->commit_id,
508 f7cc9480 2020-02-05 tracey header->refs_str);
509 f7cc9480 2020-02-05 tracey if (error)
510 f7cc9480 2020-02-05 tracey goto done;
511 f7cc9480 2020-02-05 tracey error = gw_gen_tree_header(gw_trans, header->tree_id);
512 f7cc9480 2020-02-05 tracey if (error)
513 f7cc9480 2020-02-05 tracey goto done;
514 f7cc9480 2020-02-05 tracey error = gw_gen_author_header(gw_trans, header->author);
515 f7cc9480 2020-02-05 tracey if (error)
516 f7cc9480 2020-02-05 tracey goto done;
517 f7cc9480 2020-02-05 tracey error = gw_gen_committer_header(gw_trans, header->author);
518 f7cc9480 2020-02-05 tracey if (error)
519 f7cc9480 2020-02-05 tracey goto done;
520 f7cc9480 2020-02-05 tracey error = gw_get_time_str(&age, header->committer_time,
521 f7cc9480 2020-02-05 tracey TM_LONG);
522 f7cc9480 2020-02-05 tracey if (error)
523 f7cc9480 2020-02-05 tracey goto done;
524 f7cc9480 2020-02-05 tracey error = gw_gen_age_header(gw_trans, age ?age : "");
525 070fee27 2020-02-03 stsp if (error)
526 070fee27 2020-02-03 stsp goto done;
527 f7cc9480 2020-02-05 tracey error = gw_gen_commit_msg_header(gw_trans, header->commit_msg);
528 f7cc9480 2020-02-05 tracey if (error)
529 390d412c 2020-01-28 stsp goto done;
530 f7cc9480 2020-02-05 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
531 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
532 390d412c 2020-01-28 stsp goto done;
533 f7cc9480 2020-02-05 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
534 f7cc9480 2020-02-05 tracey "dotted_line", KATTR__MAX);
535 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
536 f7cc9480 2020-02-05 tracey goto done;
537 f7cc9480 2020-02-05 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
538 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
539 f7cc9480 2020-02-05 tracey goto done;
540 87f9ebf5 2020-01-15 tracey
541 f7cc9480 2020-02-05 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
542 f7cc9480 2020-02-05 tracey "diff", KATTR__MAX);
543 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
544 f7cc9480 2020-02-05 tracey goto done;
545 38b240fb 2020-02-06 tracey error = gw_output_diff(gw_trans, header);
546 f7cc9480 2020-02-05 tracey if (error)
547 f7cc9480 2020-02-05 tracey goto done;
548 f7cc9480 2020-02-05 tracey
549 b4fba448 2020-02-05 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
550 390d412c 2020-01-28 stsp done:
551 b0a1bc86 2020-02-14 stsp gw_free_header(header);
552 55ccf528 2020-02-03 stsp free(age);
553 f7cc9480 2020-02-05 tracey if (error == NULL && kerr != KCGI_OK)
554 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
555 2204c934 2020-01-15 tracey return error;
556 2204c934 2020-01-15 tracey }
557 2204c934 2020-01-15 tracey
558 2204c934 2020-01-15 tracey static const struct got_error *
559 54415d85 2020-01-15 tracey gw_index(struct gw_trans *gw_trans)
560 2c251c14 2020-01-15 tracey {
561 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
562 46b9c89b 2020-01-15 tracey struct gw_dir *gw_dir = NULL;
563 b3f1f953 2020-02-09 tracey char *href_next = NULL, *href_prev = NULL, *href_summary = NULL;
564 b3f1f953 2020-02-09 tracey char *href_briefs = NULL, *href_commits = NULL, *href_tree = NULL;
565 ff4bb25f 2020-02-19 tracey char *href_tags = NULL;
566 387a29ba 2020-01-15 tracey unsigned int prev_disp = 0, next_disp = 1, dir_c = 0;
567 795c10a4 2020-02-20 tracey enum kcgi_err kerr = KCGI_OK;
568 2c251c14 2020-01-15 tracey
569 7a6dddae 2021-06-18 stsp #ifndef PROFILE
570 7cd52833 2022-06-23 thomas if (pledge("stdio rpath wpath cpath proc exec sendfd unveil",
571 6bee13de 2020-01-16 tracey NULL) == -1) {
572 6bee13de 2020-01-16 tracey error = got_error_from_errno("pledge");
573 6bee13de 2020-01-16 tracey return error;
574 6bee13de 2020-01-16 tracey }
575 7a6dddae 2021-06-18 stsp #endif
576 d4159696 2020-02-13 stsp error = gw_apply_unveil(gw_trans->gw_conf->got_repos_path);
577 46b9c89b 2020-01-15 tracey if (error)
578 46b9c89b 2020-01-15 tracey return error;
579 46b9c89b 2020-01-15 tracey
580 2c251c14 2020-01-15 tracey error = gw_load_got_paths(gw_trans);
581 46b9c89b 2020-01-15 tracey if (error)
582 2c251c14 2020-01-15 tracey return error;
583 2c251c14 2020-01-15 tracey
584 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
585 b3f1f953 2020-02-09 tracey "index_header", KATTR__MAX);
586 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
587 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
588 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
589 b3f1f953 2020-02-09 tracey "index_header_project", KATTR__MAX);
590 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
591 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
592 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Project");
593 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
594 2447adad 2020-02-06 stsp return gw_kcgi_error(kerr);
595 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
596 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
597 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
598 2c251c14 2020-01-15 tracey
599 b3f1f953 2020-02-09 tracey if (gw_trans->gw_conf->got_show_repo_description) {
600 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
601 b3f1f953 2020-02-09 tracey "index_header_description", KATTR__MAX);
602 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
603 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
604 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Description");
605 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
606 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
607 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
608 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
609 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
610 b3f1f953 2020-02-09 tracey }
611 b3f1f953 2020-02-09 tracey
612 b3f1f953 2020-02-09 tracey if (gw_trans->gw_conf->got_show_repo_owner) {
613 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
614 b3f1f953 2020-02-09 tracey "index_header_owner", KATTR__MAX);
615 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
616 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
617 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Owner");
618 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
619 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
620 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
621 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
622 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
623 b3f1f953 2020-02-09 tracey }
624 b3f1f953 2020-02-09 tracey
625 b3f1f953 2020-02-09 tracey if (gw_trans->gw_conf->got_show_repo_age) {
626 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
627 b3f1f953 2020-02-09 tracey "index_header_age", KATTR__MAX);
628 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
629 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
630 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Last Change");
631 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
632 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
633 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
634 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
635 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
636 b3f1f953 2020-02-09 tracey }
637 b3f1f953 2020-02-09 tracey
638 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
639 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
640 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
641 b3f1f953 2020-02-09 tracey
642 b3f1f953 2020-02-09 tracey if (TAILQ_EMPTY(&gw_trans->gw_dirs)) {
643 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
644 b3f1f953 2020-02-09 tracey "index_wrapper", KATTR__MAX);
645 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
646 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
647 32b9f7ed 2020-04-14 tracey kerr = khtml_printf(gw_trans->gw_html_req,
648 32b9f7ed 2020-04-14 tracey "No repositories found in %s",
649 b3f1f953 2020-02-09 tracey gw_trans->gw_conf->got_repos_path);
650 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
651 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
652 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
653 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
654 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
655 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
656 b3f1f953 2020-02-09 tracey "dotted_line", KATTR__MAX);
657 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
658 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
659 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
660 b3f1f953 2020-02-09 tracey if (kerr != KCGI_OK)
661 b3f1f953 2020-02-09 tracey return gw_kcgi_error(kerr);
662 c25c2314 2020-01-28 stsp return error;
663 bce5dac1 2020-01-28 stsp }
664 bce5dac1 2020-01-28 stsp
665 46b9c89b 2020-01-15 tracey TAILQ_FOREACH(gw_dir, &gw_trans->gw_dirs, entry)
666 2c251c14 2020-01-15 tracey dir_c++;
667 2c251c14 2020-01-15 tracey
668 46b9c89b 2020-01-15 tracey TAILQ_FOREACH(gw_dir, &gw_trans->gw_dirs, entry) {
669 2c251c14 2020-01-15 tracey if (gw_trans->page > 0 && (gw_trans->page *
670 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_max_repos_display) > prev_disp) {
671 2c251c14 2020-01-15 tracey prev_disp++;
672 2c251c14 2020-01-15 tracey continue;
673 2c251c14 2020-01-15 tracey }
674 2c251c14 2020-01-15 tracey
675 2c251c14 2020-01-15 tracey prev_disp++;
676 f2f46662 2020-01-23 tracey
677 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
678 b3f1f953 2020-02-09 tracey "index_wrapper", KATTR__MAX);
679 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
680 a02d5f81 2020-02-13 stsp goto done;
681 b3f1f953 2020-02-09 tracey
682 2796ac23 2020-04-14 tracey href_summary = khttp_urlpart(NULL, NULL, "gotweb", "path",
683 2796ac23 2020-04-14 tracey gw_dir->name, "action", "summary", NULL);
684 19ff7638 2020-04-14 tracey if (href_summary == NULL) {
685 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
686 19ff7638 2020-04-14 tracey goto done;
687 19ff7638 2020-04-14 tracey }
688 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
689 b3f1f953 2020-02-09 tracey "index_project", KATTR__MAX);
690 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
691 b3f1f953 2020-02-09 tracey goto done;
692 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A, KATTR_HREF,
693 b3f1f953 2020-02-09 tracey href_summary, KATTR__MAX);
694 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
695 b3f1f953 2020-02-09 tracey goto done;
696 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req, gw_dir->name);
697 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
698 b3f1f953 2020-02-09 tracey goto done;
699 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
700 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
701 b3f1f953 2020-02-09 tracey goto done;
702 b3f1f953 2020-02-09 tracey if (gw_trans->gw_conf->got_show_repo_description) {
703 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
704 b3f1f953 2020-02-09 tracey KATTR_ID, "index_project_description", KATTR__MAX);
705 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
706 b3f1f953 2020-02-09 tracey goto done;
707 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req,
708 b3f1f953 2020-02-09 tracey gw_dir->description ? gw_dir->description : "");
709 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
710 b3f1f953 2020-02-09 tracey goto done;
711 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
712 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
713 b3f1f953 2020-02-09 tracey goto done;
714 b3f1f953 2020-02-09 tracey }
715 b3f1f953 2020-02-09 tracey if (gw_trans->gw_conf->got_show_repo_owner) {
716 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
717 b3f1f953 2020-02-09 tracey KATTR_ID, "index_project_owner", KATTR__MAX);
718 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
719 b3f1f953 2020-02-09 tracey goto done;
720 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req,
721 b3f1f953 2020-02-09 tracey gw_dir->owner ? gw_dir->owner : "");
722 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
723 b3f1f953 2020-02-09 tracey goto done;
724 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
725 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
726 b3f1f953 2020-02-09 tracey goto done;
727 b3f1f953 2020-02-09 tracey }
728 b3f1f953 2020-02-09 tracey if (gw_trans->gw_conf->got_show_repo_age) {
729 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
730 b3f1f953 2020-02-09 tracey KATTR_ID, "index_project_age", KATTR__MAX);
731 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
732 b3f1f953 2020-02-09 tracey goto done;
733 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req,
734 b3f1f953 2020-02-09 tracey gw_dir->age ? gw_dir->age : "");
735 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
736 b3f1f953 2020-02-09 tracey goto done;
737 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
738 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
739 b3f1f953 2020-02-09 tracey goto done;
740 b3f1f953 2020-02-09 tracey }
741 b3f1f953 2020-02-09 tracey
742 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
743 b3f1f953 2020-02-09 tracey "navs_wrapper", KATTR__MAX);
744 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
745 b3f1f953 2020-02-09 tracey goto done;
746 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
747 b3f1f953 2020-02-09 tracey "navs", KATTR__MAX);
748 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
749 b3f1f953 2020-02-09 tracey goto done;
750 b3f1f953 2020-02-09 tracey
751 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A, KATTR_HREF,
752 b3f1f953 2020-02-09 tracey href_summary, KATTR__MAX);
753 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
754 b3f1f953 2020-02-09 tracey goto done;
755 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req, "summary");
756 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
757 b3f1f953 2020-02-09 tracey goto done;
758 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
759 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
760 b3f1f953 2020-02-09 tracey goto done;
761 2c251c14 2020-01-15 tracey
762 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req, " | ");
763 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
764 b3f1f953 2020-02-09 tracey goto done;
765 b3f1f953 2020-02-09 tracey
766 2796ac23 2020-04-14 tracey href_briefs = khttp_urlpart(NULL, NULL, "gotweb", "path",
767 2796ac23 2020-04-14 tracey gw_dir->name, "action", "briefs", NULL);
768 19ff7638 2020-04-14 tracey if (href_briefs == NULL) {
769 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
770 19ff7638 2020-04-14 tracey goto done;
771 19ff7638 2020-04-14 tracey }
772 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A, KATTR_HREF,
773 b3f1f953 2020-02-09 tracey href_briefs, KATTR__MAX);
774 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
775 b3f1f953 2020-02-09 tracey goto done;
776 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req, "commit briefs");
777 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
778 b3f1f953 2020-02-09 tracey goto done;
779 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
780 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
781 b3f1f953 2020-02-09 tracey error = gw_kcgi_error(kerr);
782 b3f1f953 2020-02-09 tracey
783 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req, " | ");
784 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
785 b3f1f953 2020-02-09 tracey goto done;
786 b3f1f953 2020-02-09 tracey
787 2796ac23 2020-04-14 tracey href_commits = khttp_urlpart(NULL, NULL, "gotweb", "path",
788 2796ac23 2020-04-14 tracey gw_dir->name, "action", "commits", NULL);
789 19ff7638 2020-04-14 tracey if (href_commits == NULL) {
790 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
791 19ff7638 2020-04-14 tracey goto done;
792 19ff7638 2020-04-14 tracey }
793 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A, KATTR_HREF,
794 b3f1f953 2020-02-09 tracey href_commits, KATTR__MAX);
795 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
796 b3f1f953 2020-02-09 tracey goto done;
797 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req, "commits");
798 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
799 b3f1f953 2020-02-09 tracey goto done;
800 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
801 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
802 b3f1f953 2020-02-09 tracey goto done;
803 b3f1f953 2020-02-09 tracey
804 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req, " | ");
805 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
806 b3f1f953 2020-02-09 tracey goto done;
807 b3f1f953 2020-02-09 tracey
808 2796ac23 2020-04-14 tracey href_tags = khttp_urlpart(NULL, NULL, "gotweb", "path",
809 2796ac23 2020-04-14 tracey gw_dir->name, "action", "tags", NULL);
810 19ff7638 2020-04-14 tracey if (href_tags == NULL) {
811 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
812 19ff7638 2020-04-14 tracey goto done;
813 19ff7638 2020-04-14 tracey }
814 ff4bb25f 2020-02-19 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A, KATTR_HREF,
815 ff4bb25f 2020-02-19 tracey href_tags, KATTR__MAX);
816 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
817 ff4bb25f 2020-02-19 tracey goto done;
818 ff4bb25f 2020-02-19 tracey kerr = khtml_puts(gw_trans->gw_html_req, "tags");
819 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
820 ff4bb25f 2020-02-19 tracey goto done;
821 ff4bb25f 2020-02-19 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
822 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
823 ff4bb25f 2020-02-19 tracey goto done;
824 ff4bb25f 2020-02-19 tracey
825 ff4bb25f 2020-02-19 tracey kerr = khtml_puts(gw_trans->gw_html_req, " | ");
826 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
827 ff4bb25f 2020-02-19 tracey goto done;
828 ff4bb25f 2020-02-19 tracey
829 2796ac23 2020-04-14 tracey href_tree = khttp_urlpart(NULL, NULL, "gotweb", "path",
830 2796ac23 2020-04-14 tracey gw_dir->name, "action", "tree", NULL);
831 19ff7638 2020-04-14 tracey if (href_tree == NULL) {
832 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
833 19ff7638 2020-04-14 tracey goto done;
834 19ff7638 2020-04-14 tracey }
835 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A, KATTR_HREF,
836 b3f1f953 2020-02-09 tracey href_tree, KATTR__MAX);
837 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
838 b3f1f953 2020-02-09 tracey goto done;
839 b3f1f953 2020-02-09 tracey kerr = khtml_puts(gw_trans->gw_html_req, "tree");
840 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
841 b3f1f953 2020-02-09 tracey goto done;
842 b3f1f953 2020-02-09 tracey
843 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 4);
844 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
845 b3f1f953 2020-02-09 tracey goto done;
846 b3f1f953 2020-02-09 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
847 b3f1f953 2020-02-09 tracey "dotted_line", KATTR__MAX);
848 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
849 b3f1f953 2020-02-09 tracey goto done;
850 b3f1f953 2020-02-09 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
851 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
852 b3f1f953 2020-02-09 tracey goto done;
853 b3f1f953 2020-02-09 tracey
854 b3f1f953 2020-02-09 tracey free(href_summary);
855 b3f1f953 2020-02-09 tracey href_summary = NULL;
856 b3f1f953 2020-02-09 tracey free(href_briefs);
857 b3f1f953 2020-02-09 tracey href_briefs = NULL;
858 b3f1f953 2020-02-09 tracey free(href_commits);
859 b3f1f953 2020-02-09 tracey href_commits = NULL;
860 ff4bb25f 2020-02-19 tracey free(href_tags);
861 ff4bb25f 2020-02-19 tracey href_tags = NULL;
862 b3f1f953 2020-02-09 tracey free(href_tree);
863 b3f1f953 2020-02-09 tracey href_tree = NULL;
864 b3f1f953 2020-02-09 tracey
865 2c251c14 2020-01-15 tracey if (gw_trans->gw_conf->got_max_repos_display == 0)
866 2c251c14 2020-01-15 tracey continue;
867 2c251c14 2020-01-15 tracey
868 75f21c89 2020-02-18 tracey if ((next_disp == gw_trans->gw_conf->got_max_repos_display) ||
869 75f21c89 2020-02-18 tracey ((gw_trans->gw_conf->got_max_repos_display > 0) &&
870 2c251c14 2020-01-15 tracey (gw_trans->page > 0) &&
871 2c251c14 2020-01-15 tracey (next_disp == gw_trans->gw_conf->got_max_repos_display ||
872 75f21c89 2020-02-18 tracey prev_disp == gw_trans->repos_total))) {
873 63ee0dca 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
874 63ee0dca 2020-02-08 tracey KATTR_ID, "np_wrapper", KATTR__MAX);
875 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
876 b3f1f953 2020-02-09 tracey goto done;
877 63ee0dca 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
878 63ee0dca 2020-02-08 tracey KATTR_ID, "nav_prev", KATTR__MAX);
879 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
880 b3f1f953 2020-02-09 tracey goto done;
881 c25c2314 2020-01-28 stsp }
882 2c251c14 2020-01-15 tracey
883 2c251c14 2020-01-15 tracey if ((gw_trans->gw_conf->got_max_repos_display > 0) &&
884 2c251c14 2020-01-15 tracey (gw_trans->page > 0) &&
885 2c251c14 2020-01-15 tracey (next_disp == gw_trans->gw_conf->got_max_repos_display ||
886 2c251c14 2020-01-15 tracey prev_disp == gw_trans->repos_total)) {
887 2796ac23 2020-04-14 tracey href_prev = khttp_urlpartx(NULL, NULL, "gotweb", "page",
888 2796ac23 2020-04-14 tracey KATTRX_INT, (int64_t)(gw_trans->page - 1), NULL);
889 19ff7638 2020-04-14 tracey if (href_prev == NULL) {
890 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpartx");
891 19ff7638 2020-04-14 tracey goto done;
892 19ff7638 2020-04-14 tracey }
893 63ee0dca 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
894 63ee0dca 2020-02-08 tracey KATTR_HREF, href_prev, KATTR__MAX);
895 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
896 565d9dcb 2020-02-09 tracey goto done;
897 63ee0dca 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Previous");
898 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
899 b3f1f953 2020-02-09 tracey goto done;
900 63ee0dca 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
901 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
902 b3f1f953 2020-02-09 tracey goto done;
903 2c251c14 2020-01-15 tracey }
904 2c251c14 2020-01-15 tracey
905 63ee0dca 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
906 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
907 2447adad 2020-02-06 stsp return gw_kcgi_error(kerr);
908 2c251c14 2020-01-15 tracey
909 2c251c14 2020-01-15 tracey if (gw_trans->gw_conf->got_max_repos_display > 0 &&
910 2c251c14 2020-01-15 tracey next_disp == gw_trans->gw_conf->got_max_repos_display &&
911 2c251c14 2020-01-15 tracey dir_c != (gw_trans->page + 1) *
912 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_max_repos_display) {
913 63ee0dca 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
914 63ee0dca 2020-02-08 tracey KATTR_ID, "nav_next", KATTR__MAX);
915 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
916 b3f1f953 2020-02-09 tracey goto done;
917 2796ac23 2020-04-14 tracey href_next = khttp_urlpartx(NULL, NULL, "gotweb", "page",
918 2796ac23 2020-04-14 tracey KATTRX_INT, (int64_t)(gw_trans->page + 1), NULL);
919 19ff7638 2020-04-14 tracey if (href_next == NULL) {
920 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpartx");
921 19ff7638 2020-04-14 tracey goto done;
922 19ff7638 2020-04-14 tracey }
923 63ee0dca 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
924 63ee0dca 2020-02-08 tracey KATTR_HREF, href_next, KATTR__MAX);
925 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
926 b3f1f953 2020-02-09 tracey goto done;
927 63ee0dca 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Next");
928 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
929 b3f1f953 2020-02-09 tracey goto done;
930 63ee0dca 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 3);
931 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
932 b3f1f953 2020-02-09 tracey goto done;
933 2c251c14 2020-01-15 tracey next_disp = 0;
934 2c251c14 2020-01-15 tracey break;
935 2c251c14 2020-01-15 tracey }
936 2c251c14 2020-01-15 tracey
937 2c251c14 2020-01-15 tracey if ((gw_trans->gw_conf->got_max_repos_display > 0) &&
938 2c251c14 2020-01-15 tracey (gw_trans->page > 0) &&
939 2c251c14 2020-01-15 tracey (next_disp == gw_trans->gw_conf->got_max_repos_display ||
940 c25c2314 2020-01-28 stsp prev_disp == gw_trans->repos_total)) {
941 63ee0dca 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
942 565d9dcb 2020-02-09 tracey if (kerr != KCGI_OK)
943 b3f1f953 2020-02-09 tracey goto done;
944 c25c2314 2020-01-28 stsp }
945 2c251c14 2020-01-15 tracey next_disp++;
946 2c251c14 2020-01-15 tracey }
947 b3f1f953 2020-02-09 tracey done:
948 00f13350 2020-02-10 tracey free(href_prev);
949 00f13350 2020-02-10 tracey free(href_next);
950 b3f1f953 2020-02-09 tracey free(href_summary);
951 b3f1f953 2020-02-09 tracey free(href_briefs);
952 b3f1f953 2020-02-09 tracey free(href_commits);
953 ff4bb25f 2020-02-19 tracey free(href_tags);
954 b3f1f953 2020-02-09 tracey free(href_tree);
955 565d9dcb 2020-02-09 tracey if (error == NULL && kerr != KCGI_OK)
956 565d9dcb 2020-02-09 tracey error = gw_kcgi_error(kerr);
957 2c251c14 2020-01-15 tracey return error;
958 2c251c14 2020-01-15 tracey }
959 2c251c14 2020-01-15 tracey
960 2c251c14 2020-01-15 tracey static const struct got_error *
961 f2f46662 2020-01-23 tracey gw_commits(struct gw_trans *gw_trans)
962 2c251c14 2020-01-15 tracey {
963 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
964 f2f46662 2020-01-23 tracey struct gw_header *header = NULL, *n_header = NULL;
965 038dfa29 2020-04-14 tracey char *age = NULL, *href_diff = NULL, *href_tree = NULL;
966 55e46400 2020-02-18 tracey char *href_prev = NULL, *href_next = NULL;
967 21a55cc7 2020-02-04 tracey enum kcgi_err kerr = KCGI_OK;
968 5a911940 2021-06-25 tracey int commit_found = 0;
969 6bee13de 2020-01-16 tracey
970 ae36ed87 2020-01-28 stsp if ((header = gw_init_header()) == NULL)
971 f2f46662 2020-01-23 tracey return got_error_from_errno("malloc");
972 f2f46662 2020-01-23 tracey
973 7a6dddae 2021-06-18 stsp #ifndef PROFILE
974 7cd52833 2022-06-23 thomas if (pledge("stdio rpath wpath cpath proc exec sendfd unveil",
975 6bee13de 2020-01-16 tracey NULL) == -1) {
976 6bee13de 2020-01-16 tracey error = got_error_from_errno("pledge");
977 5ddf0079 2020-01-29 stsp goto done;
978 6bee13de 2020-01-16 tracey }
979 7a6dddae 2021-06-18 stsp #endif
980 d4159696 2020-02-13 stsp error = gw_apply_unveil(gw_trans->gw_dir->path);
981 8087c3c5 2020-01-15 tracey if (error)
982 5ddf0079 2020-01-29 stsp goto done;
983 2c251c14 2020-01-15 tracey
984 f2f46662 2020-01-23 tracey error = gw_get_header(gw_trans, header,
985 f2f46662 2020-01-23 tracey gw_trans->gw_conf->got_max_commits_display);
986 18da9978 2020-01-29 stsp if (error)
987 18da9978 2020-01-29 stsp goto done;
988 4ceb8155 2020-01-15 tracey
989 f2f46662 2020-01-23 tracey TAILQ_FOREACH(n_header, &gw_trans->gw_headers, entry) {
990 5a911940 2021-06-25 tracey if (commit_found == 0 && gw_trans->commit_id != NULL) {
991 5a911940 2021-06-25 tracey if (strcmp(gw_trans->commit_id,
992 5a911940 2021-06-25 tracey n_header->commit_id) != 0)
993 5a911940 2021-06-25 tracey continue;
994 5a911940 2021-06-25 tracey else
995 5a911940 2021-06-25 tracey commit_found = 1;
996 5a911940 2021-06-25 tracey }
997 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
998 21a55cc7 2020-02-04 tracey "commits_line_wrapper", KATTR__MAX);
999 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1000 18da9978 2020-01-29 stsp goto done;
1001 21a55cc7 2020-02-04 tracey error = gw_gen_commit_header(gw_trans, n_header->commit_id,
1002 21a55cc7 2020-02-04 tracey n_header->refs_str);
1003 f7cc9480 2020-02-05 tracey if (error)
1004 f7cc9480 2020-02-05 tracey goto done;
1005 21a55cc7 2020-02-04 tracey error = gw_gen_author_header(gw_trans, n_header->author);
1006 21a55cc7 2020-02-04 tracey if (error)
1007 21a55cc7 2020-02-04 tracey goto done;
1008 21a55cc7 2020-02-04 tracey error = gw_gen_committer_header(gw_trans, n_header->author);
1009 21a55cc7 2020-02-04 tracey if (error)
1010 21a55cc7 2020-02-04 tracey goto done;
1011 55ccf528 2020-02-03 stsp error = gw_get_time_str(&age, n_header->committer_time,
1012 55ccf528 2020-02-03 stsp TM_LONG);
1013 55ccf528 2020-02-03 stsp if (error)
1014 55ccf528 2020-02-03 stsp goto done;
1015 21a55cc7 2020-02-04 tracey error = gw_gen_age_header(gw_trans, age ?age : "");
1016 21a55cc7 2020-02-04 tracey if (error)
1017 55ccf528 2020-02-03 stsp goto done;
1018 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
1019 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1020 21a55cc7 2020-02-04 tracey goto done;
1021 21a55cc7 2020-02-04 tracey
1022 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1023 21a55cc7 2020-02-04 tracey "dotted_line", KATTR__MAX);
1024 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1025 21a55cc7 2020-02-04 tracey goto done;
1026 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1027 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1028 21a55cc7 2020-02-04 tracey goto done;
1029 21a55cc7 2020-02-04 tracey
1030 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1031 21a55cc7 2020-02-04 tracey "commit", KATTR__MAX);
1032 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1033 21a55cc7 2020-02-04 tracey goto done;
1034 78a9dab5 2020-02-07 tracey kerr = khttp_puts(gw_trans->gw_req, n_header->commit_msg);
1035 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1036 21a55cc7 2020-02-04 tracey goto done;
1037 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1038 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1039 21a55cc7 2020-02-04 tracey goto done;
1040 21a55cc7 2020-02-04 tracey
1041 038dfa29 2020-04-14 tracey href_diff = khttp_urlpart(NULL, NULL, "gotweb", "path",
1042 038dfa29 2020-04-14 tracey gw_trans->repo_name, "action", "diff", "commit",
1043 038dfa29 2020-04-14 tracey n_header->commit_id, NULL);
1044 19ff7638 2020-04-14 tracey if (href_diff == NULL) {
1045 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
1046 19ff7638 2020-04-14 tracey goto done;
1047 19ff7638 2020-04-14 tracey }
1048 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1049 21a55cc7 2020-02-04 tracey KATTR_ID, "navs_wrapper", KATTR__MAX);
1050 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1051 21a55cc7 2020-02-04 tracey goto done;
1052 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1053 21a55cc7 2020-02-04 tracey KATTR_ID, "navs", KATTR__MAX);
1054 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1055 21a55cc7 2020-02-04 tracey goto done;
1056 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
1057 21a55cc7 2020-02-04 tracey KATTR_HREF, href_diff, KATTR__MAX);
1058 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1059 21a55cc7 2020-02-04 tracey goto done;
1060 21a55cc7 2020-02-04 tracey kerr = khtml_puts(gw_trans->gw_html_req, "diff");
1061 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1062 21a55cc7 2020-02-04 tracey goto done;
1063 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1064 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1065 21a55cc7 2020-02-04 tracey goto done;
1066 21a55cc7 2020-02-04 tracey
1067 21a55cc7 2020-02-04 tracey kerr = khtml_puts(gw_trans->gw_html_req, " | ");
1068 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1069 21a55cc7 2020-02-04 tracey goto done;
1070 21a55cc7 2020-02-04 tracey
1071 038dfa29 2020-04-14 tracey href_tree = khttp_urlpart(NULL, NULL, "gotweb", "path",
1072 038dfa29 2020-04-14 tracey gw_trans->repo_name, "action", "tree", "commit",
1073 19ff7638 2020-04-14 tracey n_header->commit_id, NULL);
1074 19ff7638 2020-04-14 tracey if (href_tree == NULL) {
1075 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
1076 19ff7638 2020-04-14 tracey goto done;
1077 19ff7638 2020-04-14 tracey }
1078 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
1079 038dfa29 2020-04-14 tracey KATTR_HREF, href_tree, KATTR__MAX);
1080 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1081 21a55cc7 2020-02-04 tracey goto done;
1082 21a55cc7 2020-02-04 tracey khtml_puts(gw_trans->gw_html_req, "tree");
1083 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1084 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1085 21a55cc7 2020-02-04 tracey goto done;
1086 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1087 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1088 21a55cc7 2020-02-04 tracey goto done;
1089 21a55cc7 2020-02-04 tracey
1090 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1091 21a55cc7 2020-02-04 tracey "solid_line", KATTR__MAX);
1092 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1093 21a55cc7 2020-02-04 tracey goto done;
1094 b4fba448 2020-02-05 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
1095 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1096 21a55cc7 2020-02-04 tracey goto done;
1097 21a55cc7 2020-02-04 tracey
1098 55ccf528 2020-02-03 stsp free(age);
1099 55ccf528 2020-02-03 stsp age = NULL;
1100 55e46400 2020-02-18 tracey }
1101 55e46400 2020-02-18 tracey
1102 5a911940 2021-06-25 tracey if (gw_trans->next_id || gw_trans->prev_id) {
1103 55e46400 2020-02-18 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1104 55e46400 2020-02-18 tracey KATTR_ID, "np_wrapper", KATTR__MAX);
1105 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1106 55e46400 2020-02-18 tracey goto done;
1107 55e46400 2020-02-18 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1108 55e46400 2020-02-18 tracey KATTR_ID, "nav_prev", KATTR__MAX);
1109 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1110 55e46400 2020-02-18 tracey goto done;
1111 f2f46662 2020-01-23 tracey }
1112 55e46400 2020-02-18 tracey
1113 5a911940 2021-06-25 tracey if (gw_trans->prev_id) {
1114 038dfa29 2020-04-14 tracey href_prev = khttp_urlpartx(NULL, NULL, "gotweb", "path",
1115 038dfa29 2020-04-14 tracey KATTRX_STRING, gw_trans->repo_name, "page",
1116 038dfa29 2020-04-14 tracey KATTRX_INT, (int64_t) (gw_trans->page - 1), "action",
1117 038dfa29 2020-04-14 tracey KATTRX_STRING, "commits", "commit", KATTRX_STRING,
1118 5a911940 2021-06-25 tracey gw_trans->prev_id ? gw_trans->prev_id : "", NULL);
1119 19ff7638 2020-04-14 tracey if (href_prev == NULL) {
1120 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpartx");
1121 19ff7638 2020-04-14 tracey goto done;
1122 19ff7638 2020-04-14 tracey }
1123 55e46400 2020-02-18 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
1124 55e46400 2020-02-18 tracey KATTR_HREF, href_prev, KATTR__MAX);
1125 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1126 55e46400 2020-02-18 tracey goto done;
1127 55e46400 2020-02-18 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Previous");
1128 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1129 55e46400 2020-02-18 tracey goto done;
1130 55e46400 2020-02-18 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1131 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1132 55e46400 2020-02-18 tracey goto done;
1133 55e46400 2020-02-18 tracey }
1134 55e46400 2020-02-18 tracey
1135 55e46400 2020-02-18 tracey if (gw_trans->next_id || gw_trans->page > 0) {
1136 55e46400 2020-02-18 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1137 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1138 55e46400 2020-02-18 tracey return gw_kcgi_error(kerr);
1139 55e46400 2020-02-18 tracey }
1140 55e46400 2020-02-18 tracey
1141 55e46400 2020-02-18 tracey if (gw_trans->next_id) {
1142 55e46400 2020-02-18 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1143 55e46400 2020-02-18 tracey KATTR_ID, "nav_next", KATTR__MAX);
1144 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1145 55e46400 2020-02-18 tracey goto done;
1146 038dfa29 2020-04-14 tracey href_next = khttp_urlpartx(NULL, NULL, "gotweb", "path",
1147 038dfa29 2020-04-14 tracey KATTRX_STRING, gw_trans->repo_name, "page",
1148 038dfa29 2020-04-14 tracey KATTRX_INT, (int64_t) (gw_trans->page + 1), "action",
1149 038dfa29 2020-04-14 tracey KATTRX_STRING, "commits", "commit", KATTRX_STRING,
1150 5a911940 2021-06-25 tracey gw_trans->next_id, NULL);
1151 19ff7638 2020-04-14 tracey if (href_next == NULL) {
1152 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpartx");
1153 19ff7638 2020-04-14 tracey goto done;
1154 19ff7638 2020-04-14 tracey }
1155 55e46400 2020-02-18 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
1156 55e46400 2020-02-18 tracey KATTR_HREF, href_next, KATTR__MAX);
1157 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1158 55e46400 2020-02-18 tracey goto done;
1159 55e46400 2020-02-18 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Next");
1160 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1161 55e46400 2020-02-18 tracey goto done;
1162 55e46400 2020-02-18 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 3);
1163 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1164 55e46400 2020-02-18 tracey goto done;
1165 55e46400 2020-02-18 tracey }
1166 55e46400 2020-02-18 tracey
1167 55e46400 2020-02-18 tracey if (gw_trans->next_id || gw_trans->page > 0) {
1168 55e46400 2020-02-18 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
1169 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1170 55e46400 2020-02-18 tracey goto done;
1171 55e46400 2020-02-18 tracey }
1172 18da9978 2020-01-29 stsp done:
1173 b0a1bc86 2020-02-14 stsp gw_free_header(header);
1174 f2f46662 2020-01-23 tracey TAILQ_FOREACH(n_header, &gw_trans->gw_headers, entry)
1175 b0a1bc86 2020-02-14 stsp gw_free_header(n_header);
1176 55ccf528 2020-02-03 stsp free(age);
1177 55e46400 2020-02-18 tracey free(href_next);
1178 55e46400 2020-02-18 tracey free(href_prev);
1179 21a55cc7 2020-02-04 tracey free(href_diff);
1180 038dfa29 2020-04-14 tracey free(href_tree);
1181 21a55cc7 2020-02-04 tracey if (error == NULL && kerr != KCGI_OK)
1182 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
1183 2c251c14 2020-01-15 tracey return error;
1184 2c251c14 2020-01-15 tracey }
1185 2c251c14 2020-01-15 tracey
1186 2c251c14 2020-01-15 tracey static const struct got_error *
1187 f2f46662 2020-01-23 tracey gw_briefs(struct gw_trans *gw_trans)
1188 2c251c14 2020-01-15 tracey {
1189 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
1190 bd275801 2020-02-03 tracey struct gw_header *header = NULL, *n_header = NULL;
1191 9ba68833 2020-04-14 tracey char *age = NULL, *href_diff = NULL, *href_tree = NULL;
1192 55e46400 2020-02-18 tracey char *href_prev = NULL, *href_next = NULL;
1193 bd275801 2020-02-03 tracey char *newline, *smallerthan;
1194 ef72fe2c 2020-02-04 stsp enum kcgi_err kerr = KCGI_OK;
1195 5a911940 2021-06-25 tracey int commit_found = 0;
1196 17a96b9f 2020-01-15 tracey
1197 ae36ed87 2020-01-28 stsp if ((header = gw_init_header()) == NULL)
1198 f2f46662 2020-01-23 tracey return got_error_from_errno("malloc");
1199 f2f46662 2020-01-23 tracey
1200 7a6dddae 2021-06-18 stsp #ifndef PROFILE
1201 7cd52833 2022-06-23 thomas if (pledge("stdio rpath wpath cpath proc exec sendfd unveil",
1202 6bee13de 2020-01-16 tracey NULL) == -1) {
1203 6bee13de 2020-01-16 tracey error = got_error_from_errno("pledge");
1204 5ddf0079 2020-01-29 stsp goto done;
1205 6bee13de 2020-01-16 tracey }
1206 7a6dddae 2021-06-18 stsp #endif
1207 85993e64 2020-02-17 tracey if (gw_trans->action != GW_SUMMARY) {
1208 85993e64 2020-02-17 tracey error = gw_apply_unveil(gw_trans->gw_dir->path);
1209 85993e64 2020-02-17 tracey if (error)
1210 85993e64 2020-02-17 tracey goto done;
1211 85993e64 2020-02-17 tracey }
1212 9d84e7dd 2020-01-15 tracey
1213 f2f46662 2020-01-23 tracey if (gw_trans->action == GW_SUMMARY)
1214 f2f46662 2020-01-23 tracey error = gw_get_header(gw_trans, header, D_MAXSLCOMMDISP);
1215 f2f46662 2020-01-23 tracey else
1216 f2f46662 2020-01-23 tracey error = gw_get_header(gw_trans, header,
1217 f2f46662 2020-01-23 tracey gw_trans->gw_conf->got_max_commits_display);
1218 c25c2314 2020-01-28 stsp if (error)
1219 0e00e8f4 2020-01-29 stsp goto done;
1220 c25c2314 2020-01-28 stsp
1221 f2f46662 2020-01-23 tracey TAILQ_FOREACH(n_header, &gw_trans->gw_headers, entry) {
1222 5a911940 2021-06-25 tracey if (commit_found == 0 && gw_trans->commit_id != NULL) {
1223 5a911940 2021-06-25 tracey if (strcmp(gw_trans->commit_id,
1224 5a911940 2021-06-25 tracey n_header->commit_id) != 0)
1225 5a911940 2021-06-25 tracey continue;
1226 5a911940 2021-06-25 tracey else
1227 5a911940 2021-06-25 tracey commit_found = 1;
1228 5a911940 2021-06-25 tracey }
1229 bd275801 2020-02-03 tracey error = gw_get_time_str(&age, n_header->committer_time,
1230 bd275801 2020-02-03 tracey TM_DIFF);
1231 bd275801 2020-02-03 tracey if (error)
1232 bd275801 2020-02-03 tracey goto done;
1233 bd275801 2020-02-03 tracey
1234 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1235 bd275801 2020-02-03 tracey KATTR_ID, "briefs_wrapper", KATTR__MAX);
1236 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1237 bd275801 2020-02-03 tracey goto done;
1238 bd275801 2020-02-03 tracey
1239 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1240 bd275801 2020-02-03 tracey KATTR_ID, "briefs_age", KATTR__MAX);
1241 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1242 bd275801 2020-02-03 tracey goto done;
1243 53e81e48 2020-02-13 tracey kerr = khtml_puts(gw_trans->gw_html_req, age ? age : "");
1244 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1245 bd275801 2020-02-03 tracey goto done;
1246 bd275801 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1247 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1248 bd275801 2020-02-03 tracey goto done;
1249 bd275801 2020-02-03 tracey
1250 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1251 bd275801 2020-02-03 tracey KATTR_ID, "briefs_author", KATTR__MAX);
1252 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1253 bd275801 2020-02-03 tracey goto done;
1254 bd275801 2020-02-03 tracey smallerthan = strchr(n_header->author, '<');
1255 bd275801 2020-02-03 tracey if (smallerthan)
1256 bd275801 2020-02-03 tracey *smallerthan = '\0';
1257 bd275801 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req, n_header->author);
1258 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1259 bd275801 2020-02-03 tracey goto done;
1260 bd275801 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1261 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1262 bd275801 2020-02-03 tracey goto done;
1263 bd275801 2020-02-03 tracey
1264 9ba68833 2020-04-14 tracey href_diff = khttp_urlpart(NULL, NULL, "gotweb", "path",
1265 9ba68833 2020-04-14 tracey gw_trans->repo_name, "action", "diff", "commit",
1266 9ba68833 2020-04-14 tracey n_header->commit_id, NULL);
1267 19ff7638 2020-04-14 tracey if (href_diff == NULL) {
1268 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
1269 19ff7638 2020-04-14 tracey goto done;
1270 19ff7638 2020-04-14 tracey }
1271 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1272 bd275801 2020-02-03 tracey KATTR_ID, "briefs_log", KATTR__MAX);
1273 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1274 bd275801 2020-02-03 tracey goto done;
1275 f2f46662 2020-01-23 tracey newline = strchr(n_header->commit_msg, '\n');
1276 f2f46662 2020-01-23 tracey if (newline)
1277 f2f46662 2020-01-23 tracey *newline = '\0';
1278 52f8346c 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
1279 52f8346c 2020-02-03 tracey KATTR_HREF, href_diff, KATTR__MAX);
1280 52f8346c 2020-02-03 tracey if (kerr != KCGI_OK)
1281 52f8346c 2020-02-03 tracey goto done;
1282 bd275801 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req, n_header->commit_msg);
1283 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1284 55ccf528 2020-02-03 stsp goto done;
1285 bf93a5c0 2020-02-15 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1286 bf93a5c0 2020-02-15 tracey if (kerr != KCGI_OK)
1287 bf93a5c0 2020-02-15 tracey goto done;
1288 bf93a5c0 2020-02-15 tracey
1289 bf93a5c0 2020-02-15 tracey if (n_header->refs_str) {
1290 bf93a5c0 2020-02-15 tracey kerr = khtml_puts(gw_trans->gw_html_req, " ");
1291 bf93a5c0 2020-02-15 tracey if (kerr != KCGI_OK)
1292 bf93a5c0 2020-02-15 tracey goto done;
1293 bf93a5c0 2020-02-15 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_SPAN,
1294 bf93a5c0 2020-02-15 tracey KATTR_ID, "refs_str", KATTR__MAX);
1295 bf93a5c0 2020-02-15 tracey if (kerr != KCGI_OK)
1296 bf93a5c0 2020-02-15 tracey goto done;
1297 32b9f7ed 2020-04-14 tracey kerr = khtml_printf(gw_trans->gw_html_req, "(%s)",
1298 bf93a5c0 2020-02-15 tracey n_header->refs_str);
1299 bf93a5c0 2020-02-15 tracey if (kerr != KCGI_OK)
1300 bf93a5c0 2020-02-15 tracey goto done;
1301 bf93a5c0 2020-02-15 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1302 bf93a5c0 2020-02-15 tracey if (kerr != KCGI_OK)
1303 bf93a5c0 2020-02-15 tracey goto done;
1304 bf93a5c0 2020-02-15 tracey }
1305 bf93a5c0 2020-02-15 tracey
1306 bf93a5c0 2020-02-15 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1307 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1308 bd275801 2020-02-03 tracey goto done;
1309 bd275801 2020-02-03 tracey
1310 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1311 bd275801 2020-02-03 tracey KATTR_ID, "navs_wrapper", KATTR__MAX);
1312 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1313 bd275801 2020-02-03 tracey goto done;
1314 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1315 bd275801 2020-02-03 tracey KATTR_ID, "navs", KATTR__MAX);
1316 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1317 bd275801 2020-02-03 tracey goto done;
1318 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
1319 bd275801 2020-02-03 tracey KATTR_HREF, href_diff, KATTR__MAX);
1320 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1321 070fee27 2020-02-03 stsp goto done;
1322 bd275801 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req, "diff");
1323 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1324 bd275801 2020-02-03 tracey goto done;
1325 bd275801 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1326 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1327 bd275801 2020-02-03 tracey goto done;
1328 bd275801 2020-02-03 tracey
1329 bd275801 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req, " | ");
1330 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1331 bd275801 2020-02-03 tracey goto done;
1332 bd275801 2020-02-03 tracey
1333 9ba68833 2020-04-14 tracey href_tree = khttp_urlpart(NULL, NULL, "gotweb", "path",
1334 9ba68833 2020-04-14 tracey gw_trans->repo_name, "action", "tree", "commit",
1335 9ba68833 2020-04-14 tracey n_header->commit_id, NULL);
1336 19ff7638 2020-04-14 tracey if (href_tree == NULL) {
1337 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
1338 19ff7638 2020-04-14 tracey goto done;
1339 19ff7638 2020-04-14 tracey }
1340 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
1341 9ba68833 2020-04-14 tracey KATTR_HREF, href_tree, KATTR__MAX);
1342 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1343 bd275801 2020-02-03 tracey goto done;
1344 bd275801 2020-02-03 tracey khtml_puts(gw_trans->gw_html_req, "tree");
1345 bd275801 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1346 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1347 bd275801 2020-02-03 tracey goto done;
1348 bd275801 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1349 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1350 bd275801 2020-02-03 tracey goto done;
1351 bd275801 2020-02-03 tracey
1352 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1353 bd275801 2020-02-03 tracey KATTR_ID, "dotted_line", KATTR__MAX);
1354 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1355 bd275801 2020-02-03 tracey goto done;
1356 bd275801 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 3);
1357 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
1358 bd275801 2020-02-03 tracey goto done;
1359 bd275801 2020-02-03 tracey
1360 55ccf528 2020-02-03 stsp free(age);
1361 55ccf528 2020-02-03 stsp age = NULL;
1362 bd275801 2020-02-03 tracey free(href_diff);
1363 bd275801 2020-02-03 tracey href_diff = NULL;
1364 9ba68833 2020-04-14 tracey free(href_tree);
1365 9ba68833 2020-04-14 tracey href_tree = NULL;
1366 55e46400 2020-02-18 tracey }
1367 55e46400 2020-02-18 tracey
1368 5a911940 2021-06-25 tracey if (gw_trans->next_id || gw_trans->prev_id) {
1369 55e46400 2020-02-18 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1370 55e46400 2020-02-18 tracey KATTR_ID, "np_wrapper", KATTR__MAX);
1371 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1372 55e46400 2020-02-18 tracey goto done;
1373 55e46400 2020-02-18 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1374 55e46400 2020-02-18 tracey KATTR_ID, "nav_prev", KATTR__MAX);
1375 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1376 55e46400 2020-02-18 tracey goto done;
1377 55e46400 2020-02-18 tracey }
1378 55e46400 2020-02-18 tracey
1379 5a911940 2021-06-25 tracey if (gw_trans->prev_id) {
1380 9ba68833 2020-04-14 tracey href_prev = khttp_urlpartx(NULL, NULL, "gotweb", "path",
1381 9ba68833 2020-04-14 tracey KATTRX_STRING, gw_trans->repo_name, "page",
1382 9ba68833 2020-04-14 tracey KATTRX_INT, (int64_t) (gw_trans->page - 1), "action",
1383 9ba68833 2020-04-14 tracey KATTRX_STRING, "briefs", "commit", KATTRX_STRING,
1384 5a911940 2021-06-25 tracey gw_trans->prev_id ? gw_trans->prev_id : "", NULL);
1385 19ff7638 2020-04-14 tracey if (href_prev == NULL) {
1386 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpartx");
1387 19ff7638 2020-04-14 tracey goto done;
1388 19ff7638 2020-04-14 tracey }
1389 55e46400 2020-02-18 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
1390 55e46400 2020-02-18 tracey KATTR_HREF, href_prev, KATTR__MAX);
1391 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1392 55e46400 2020-02-18 tracey goto done;
1393 55e46400 2020-02-18 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Previous");
1394 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1395 55e46400 2020-02-18 tracey goto done;
1396 55e46400 2020-02-18 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1397 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1398 55e46400 2020-02-18 tracey goto done;
1399 9d84e7dd 2020-01-15 tracey }
1400 55e46400 2020-02-18 tracey
1401 55e46400 2020-02-18 tracey if (gw_trans->next_id || gw_trans->page > 0) {
1402 55e46400 2020-02-18 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1403 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1404 55e46400 2020-02-18 tracey return gw_kcgi_error(kerr);
1405 55e46400 2020-02-18 tracey }
1406 55e46400 2020-02-18 tracey
1407 55e46400 2020-02-18 tracey if (gw_trans->next_id) {
1408 55e46400 2020-02-18 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1409 55e46400 2020-02-18 tracey KATTR_ID, "nav_next", KATTR__MAX);
1410 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1411 55e46400 2020-02-18 tracey goto done;
1412 9ba68833 2020-04-14 tracey
1413 9ba68833 2020-04-14 tracey href_next = khttp_urlpartx(NULL, NULL, "gotweb", "path",
1414 9ba68833 2020-04-14 tracey KATTRX_STRING, gw_trans->repo_name, "page",
1415 9ba68833 2020-04-14 tracey KATTRX_INT, (int64_t) (gw_trans->page + 1), "action",
1416 9ba68833 2020-04-14 tracey KATTRX_STRING, "briefs", "commit", KATTRX_STRING,
1417 5a911940 2021-06-25 tracey gw_trans->next_id, NULL);
1418 19ff7638 2020-04-14 tracey if (href_next == NULL) {
1419 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpartx");
1420 19ff7638 2020-04-14 tracey goto done;
1421 19ff7638 2020-04-14 tracey }
1422 55e46400 2020-02-18 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
1423 55e46400 2020-02-18 tracey KATTR_HREF, href_next, KATTR__MAX);
1424 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1425 55e46400 2020-02-18 tracey goto done;
1426 55e46400 2020-02-18 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Next");
1427 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1428 55e46400 2020-02-18 tracey goto done;
1429 55e46400 2020-02-18 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 3);
1430 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1431 55e46400 2020-02-18 tracey goto done;
1432 55e46400 2020-02-18 tracey }
1433 55e46400 2020-02-18 tracey
1434 55e46400 2020-02-18 tracey if (gw_trans->next_id || gw_trans->page > 0) {
1435 55e46400 2020-02-18 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
1436 55e46400 2020-02-18 tracey if (kerr != KCGI_OK)
1437 55e46400 2020-02-18 tracey goto done;
1438 55e46400 2020-02-18 tracey }
1439 0e00e8f4 2020-01-29 stsp done:
1440 b0a1bc86 2020-02-14 stsp gw_free_header(header);
1441 f2f46662 2020-01-23 tracey TAILQ_FOREACH(n_header, &gw_trans->gw_headers, entry)
1442 b0a1bc86 2020-02-14 stsp gw_free_header(n_header);
1443 55ccf528 2020-02-03 stsp free(age);
1444 55e46400 2020-02-18 tracey free(href_next);
1445 55e46400 2020-02-18 tracey free(href_prev);
1446 bd275801 2020-02-03 tracey free(href_diff);
1447 9ba68833 2020-04-14 tracey free(href_tree);
1448 ef72fe2c 2020-02-04 stsp if (error == NULL && kerr != KCGI_OK)
1449 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
1450 2c251c14 2020-01-15 tracey return error;
1451 2c251c14 2020-01-15 tracey }
1452 2c251c14 2020-01-15 tracey
1453 2c251c14 2020-01-15 tracey static const struct got_error *
1454 54415d85 2020-01-15 tracey gw_summary(struct gw_trans *gw_trans)
1455 387a29ba 2020-01-15 tracey {
1456 387a29ba 2020-01-15 tracey const struct got_error *error = NULL;
1457 9eed6f10 2020-02-08 tracey char *age = NULL;
1458 21a55cc7 2020-02-04 tracey enum kcgi_err kerr = KCGI_OK;
1459 387a29ba 2020-01-15 tracey
1460 7a6dddae 2021-06-18 stsp #ifndef PROFILE
1461 7cd52833 2022-06-23 thomas if (pledge("stdio rpath wpath cpath proc exec sendfd unveil",
1462 7cd52833 2022-06-23 thomas NULL) == -1)
1463 f4df82f9 2020-01-29 stsp return got_error_from_errno("pledge");
1464 7a6dddae 2021-06-18 stsp #endif
1465 85993e64 2020-02-17 tracey error = gw_apply_unveil(gw_trans->gw_dir->path);
1466 85993e64 2020-02-17 tracey if (error)
1467 85993e64 2020-02-17 tracey goto done;
1468 46b9c89b 2020-01-15 tracey
1469 783ec107 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1470 783ec107 2020-02-03 tracey "summary_wrapper", KATTR__MAX);
1471 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
1472 2447adad 2020-02-06 stsp return gw_kcgi_error(kerr);
1473 c25c2314 2020-01-28 stsp
1474 783ec107 2020-02-03 tracey if (gw_trans->gw_conf->got_show_repo_description &&
1475 783ec107 2020-02-03 tracey gw_trans->gw_dir->description != NULL &&
1476 783ec107 2020-02-03 tracey (strcmp(gw_trans->gw_dir->description, "") != 0)) {
1477 783ec107 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1478 783ec107 2020-02-03 tracey KATTR_ID, "description_title", KATTR__MAX);
1479 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1480 783ec107 2020-02-03 tracey goto done;
1481 783ec107 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Description: ");
1482 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1483 783ec107 2020-02-03 tracey goto done;
1484 783ec107 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1485 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1486 783ec107 2020-02-03 tracey goto done;
1487 783ec107 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1488 783ec107 2020-02-03 tracey KATTR_ID, "description", KATTR__MAX);
1489 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1490 783ec107 2020-02-03 tracey goto done;
1491 783ec107 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req,
1492 783ec107 2020-02-03 tracey gw_trans->gw_dir->description);
1493 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1494 783ec107 2020-02-03 tracey goto done;
1495 783ec107 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1496 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1497 783ec107 2020-02-03 tracey goto done;
1498 46b9c89b 2020-01-15 tracey }
1499 46b9c89b 2020-01-15 tracey
1500 9a1cc63f 2020-02-03 stsp if (gw_trans->gw_conf->got_show_repo_owner &&
1501 a942aa37 2020-02-10 tracey gw_trans->gw_dir->owner != NULL &&
1502 a942aa37 2020-02-10 tracey (strcmp(gw_trans->gw_dir->owner, "") != 0)) {
1503 783ec107 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1504 783ec107 2020-02-03 tracey KATTR_ID, "repo_owner_title", KATTR__MAX);
1505 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1506 9a1cc63f 2020-02-03 stsp goto done;
1507 783ec107 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Owner: ");
1508 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1509 9a1cc63f 2020-02-03 stsp goto done;
1510 783ec107 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1511 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1512 783ec107 2020-02-03 tracey goto done;
1513 783ec107 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1514 783ec107 2020-02-03 tracey KATTR_ID, "repo_owner", KATTR__MAX);
1515 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1516 783ec107 2020-02-03 tracey goto done;
1517 783ec107 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req,
1518 62d463ca 2020-10-20 naddy gw_trans->gw_dir->owner);
1519 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1520 783ec107 2020-02-03 tracey goto done;
1521 783ec107 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1522 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1523 783ec107 2020-02-03 tracey goto done;
1524 46b9c89b 2020-01-15 tracey }
1525 46b9c89b 2020-01-15 tracey
1526 46b9c89b 2020-01-15 tracey if (gw_trans->gw_conf->got_show_repo_age) {
1527 d126c1b7 2020-01-29 stsp error = gw_get_repo_age(&age, gw_trans, gw_trans->gw_dir->path,
1528 2011c142 2020-02-14 stsp NULL, TM_LONG);
1529 d126c1b7 2020-01-29 stsp if (error)
1530 20f34652 2020-01-29 stsp goto done;
1531 55ccf528 2020-02-03 stsp if (age != NULL) {
1532 783ec107 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1533 783ec107 2020-02-03 tracey KATTR_ID, "last_change_title", KATTR__MAX);
1534 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1535 20f34652 2020-01-29 stsp goto done;
1536 783ec107 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req,
1537 783ec107 2020-02-03 tracey "Last Change: ");
1538 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1539 20f34652 2020-01-29 stsp goto done;
1540 783ec107 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1541 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1542 20f34652 2020-01-29 stsp goto done;
1543 783ec107 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1544 783ec107 2020-02-03 tracey KATTR_ID, "last_change", KATTR__MAX);
1545 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1546 20f34652 2020-01-29 stsp goto done;
1547 783ec107 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req, age);
1548 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1549 783ec107 2020-02-03 tracey goto done;
1550 783ec107 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1551 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1552 783ec107 2020-02-03 tracey goto done;
1553 46b9c89b 2020-01-15 tracey }
1554 46b9c89b 2020-01-15 tracey }
1555 783ec107 2020-02-03 tracey
1556 783ec107 2020-02-03 tracey if (gw_trans->gw_conf->got_show_repo_cloneurl &&
1557 783ec107 2020-02-03 tracey gw_trans->gw_dir->url != NULL &&
1558 783ec107 2020-02-03 tracey (strcmp(gw_trans->gw_dir->url, "") != 0)) {
1559 783ec107 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1560 783ec107 2020-02-03 tracey KATTR_ID, "cloneurl_title", KATTR__MAX);
1561 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1562 783ec107 2020-02-03 tracey goto done;
1563 783ec107 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Clone URL: ");
1564 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1565 783ec107 2020-02-03 tracey goto done;
1566 783ec107 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1567 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1568 783ec107 2020-02-03 tracey goto done;
1569 783ec107 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1570 783ec107 2020-02-03 tracey KATTR_ID, "cloneurl", KATTR__MAX);
1571 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1572 783ec107 2020-02-03 tracey goto done;
1573 783ec107 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req, gw_trans->gw_dir->url);
1574 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1575 21a55cc7 2020-02-04 tracey goto done;
1576 783ec107 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1577 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1578 783ec107 2020-02-03 tracey goto done;
1579 783ec107 2020-02-03 tracey }
1580 783ec107 2020-02-03 tracey
1581 783ec107 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1582 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1583 bd275801 2020-02-03 tracey goto done;
1584 bd275801 2020-02-03 tracey
1585 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1586 bd275801 2020-02-03 tracey "briefs_title_wrapper", KATTR__MAX);
1587 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1588 bd275801 2020-02-03 tracey goto done;
1589 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1590 bd275801 2020-02-03 tracey "briefs_title", KATTR__MAX);
1591 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1592 20f34652 2020-01-29 stsp goto done;
1593 bd275801 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Commit Briefs");
1594 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1595 bd275801 2020-02-03 tracey goto done;
1596 bd275801 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
1597 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
1598 bd275801 2020-02-03 tracey goto done;
1599 f2f46662 2020-01-23 tracey error = gw_briefs(gw_trans);
1600 f2f46662 2020-01-23 tracey if (error)
1601 20f34652 2020-01-29 stsp goto done;
1602 f2f46662 2020-01-23 tracey
1603 ff4bb25f 2020-02-19 tracey error = gw_tags(gw_trans);
1604 6eccd105 2020-02-03 stsp if (error)
1605 6eccd105 2020-02-03 stsp goto done;
1606 8d4d2453 2020-01-15 tracey
1607 9eed6f10 2020-02-08 tracey error = gw_output_repo_heads(gw_trans);
1608 20f34652 2020-01-29 stsp done:
1609 20f34652 2020-01-29 stsp free(age);
1610 f7cc9480 2020-02-05 tracey if (error == NULL && kerr != KCGI_OK)
1611 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
1612 2204c934 2020-01-15 tracey return error;
1613 2204c934 2020-01-15 tracey }
1614 2204c934 2020-01-15 tracey
1615 2204c934 2020-01-15 tracey static const struct got_error *
1616 f2f46662 2020-01-23 tracey gw_tree(struct gw_trans *gw_trans)
1617 b772de24 2020-01-15 tracey {
1618 b772de24 2020-01-15 tracey const struct got_error *error = NULL;
1619 f2f46662 2020-01-23 tracey struct gw_header *header = NULL;
1620 f2f46662 2020-01-23 tracey char *tree = NULL, *tree_html = NULL, *tree_html_disp = NULL;
1621 53e81e48 2020-02-13 tracey char *age = NULL;
1622 795c10a4 2020-02-20 tracey enum kcgi_err kerr = KCGI_OK;
1623 6bee13de 2020-01-16 tracey
1624 7a6dddae 2021-06-18 stsp #ifndef PROFILE
1625 7cd52833 2022-06-23 thomas if (pledge("stdio rpath wpath cpath proc exec sendfd unveil",
1626 7cd52833 2022-06-23 thomas NULL) == -1)
1627 f2f46662 2020-01-23 tracey return got_error_from_errno("pledge");
1628 7a6dddae 2021-06-18 stsp #endif
1629 ae36ed87 2020-01-28 stsp if ((header = gw_init_header()) == NULL)
1630 f2f46662 2020-01-23 tracey return got_error_from_errno("malloc");
1631 f2f46662 2020-01-23 tracey
1632 d4159696 2020-02-13 stsp error = gw_apply_unveil(gw_trans->gw_dir->path);
1633 b772de24 2020-01-15 tracey if (error)
1634 5ddf0079 2020-01-29 stsp goto done;
1635 b772de24 2020-01-15 tracey
1636 f2f46662 2020-01-23 tracey error = gw_get_header(gw_trans, header, 1);
1637 f2f46662 2020-01-23 tracey if (error)
1638 42281175 2020-01-29 stsp goto done;
1639 b772de24 2020-01-15 tracey
1640 626b25b6 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1641 626b25b6 2020-02-06 tracey "tree_header_wrapper", KATTR__MAX);
1642 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
1643 55ccf528 2020-02-03 stsp goto done;
1644 626b25b6 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1645 626b25b6 2020-02-06 tracey "tree_header", KATTR__MAX);
1646 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
1647 55ccf528 2020-02-03 stsp goto done;
1648 626b25b6 2020-02-06 tracey error = gw_gen_tree_header(gw_trans, header->tree_id);
1649 626b25b6 2020-02-06 tracey if (error)
1650 626b25b6 2020-02-06 tracey goto done;
1651 626b25b6 2020-02-06 tracey error = gw_get_time_str(&age, header->committer_time,
1652 626b25b6 2020-02-06 tracey TM_LONG);
1653 626b25b6 2020-02-06 tracey if (error)
1654 626b25b6 2020-02-06 tracey goto done;
1655 626b25b6 2020-02-06 tracey error = gw_gen_age_header(gw_trans, age ?age : "");
1656 070fee27 2020-02-03 stsp if (error)
1657 070fee27 2020-02-03 stsp goto done;
1658 626b25b6 2020-02-06 tracey error = gw_gen_commit_msg_header(gw_trans, header->commit_msg);
1659 626b25b6 2020-02-06 tracey if (error)
1660 42281175 2020-01-29 stsp goto done;
1661 626b25b6 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
1662 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
1663 42281175 2020-01-29 stsp goto done;
1664 626b25b6 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1665 626b25b6 2020-02-06 tracey "dotted_line", KATTR__MAX);
1666 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
1667 626b25b6 2020-02-06 tracey goto done;
1668 626b25b6 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1669 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
1670 626b25b6 2020-02-06 tracey goto done;
1671 626b25b6 2020-02-06 tracey
1672 626b25b6 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1673 626b25b6 2020-02-06 tracey "tree", KATTR__MAX);
1674 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
1675 626b25b6 2020-02-06 tracey goto done;
1676 84de9106 2020-12-26 stsp error = gw_output_repo_tree(gw_trans, header);
1677 626b25b6 2020-02-06 tracey if (error)
1678 626b25b6 2020-02-06 tracey goto done;
1679 626b25b6 2020-02-06 tracey
1680 626b25b6 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1681 4ff7391f 2020-01-28 tracey done:
1682 b0a1bc86 2020-02-14 stsp gw_free_header(header);
1683 f2f46662 2020-01-23 tracey free(tree_html_disp);
1684 f2f46662 2020-01-23 tracey free(tree_html);
1685 f2f46662 2020-01-23 tracey free(tree);
1686 55ccf528 2020-02-03 stsp free(age);
1687 ff4bb25f 2020-02-19 tracey if (error == NULL && kerr != KCGI_OK)
1688 ff4bb25f 2020-02-19 tracey error = gw_kcgi_error(kerr);
1689 ff4bb25f 2020-02-19 tracey return error;
1690 ff4bb25f 2020-02-19 tracey }
1691 ff4bb25f 2020-02-19 tracey
1692 ff4bb25f 2020-02-19 tracey static const struct got_error *
1693 ff4bb25f 2020-02-19 tracey gw_tags(struct gw_trans *gw_trans)
1694 ff4bb25f 2020-02-19 tracey {
1695 ff4bb25f 2020-02-19 tracey const struct got_error *error = NULL;
1696 ff4bb25f 2020-02-19 tracey struct gw_header *header = NULL;
1697 ff4bb25f 2020-02-19 tracey char *href_next = NULL, *href_prev = NULL;
1698 ff4bb25f 2020-02-19 tracey enum kcgi_err kerr = KCGI_OK;
1699 ff4bb25f 2020-02-19 tracey
1700 7a6dddae 2021-06-18 stsp #ifndef PROFILE
1701 7cd52833 2022-06-23 thomas if (pledge("stdio rpath wpath cpath proc exec sendfd unveil",
1702 7cd52833 2022-06-23 thomas NULL) == -1)
1703 ff4bb25f 2020-02-19 tracey return got_error_from_errno("pledge");
1704 7a6dddae 2021-06-18 stsp #endif
1705 ff4bb25f 2020-02-19 tracey if ((header = gw_init_header()) == NULL)
1706 ff4bb25f 2020-02-19 tracey return got_error_from_errno("malloc");
1707 ff4bb25f 2020-02-19 tracey
1708 ff4bb25f 2020-02-19 tracey if (gw_trans->action != GW_SUMMARY) {
1709 ff4bb25f 2020-02-19 tracey error = gw_apply_unveil(gw_trans->gw_dir->path);
1710 ff4bb25f 2020-02-19 tracey if (error)
1711 ff4bb25f 2020-02-19 tracey goto done;
1712 ff4bb25f 2020-02-19 tracey }
1713 ff4bb25f 2020-02-19 tracey
1714 ff4bb25f 2020-02-19 tracey error = gw_get_header(gw_trans, header, 1);
1715 ff4bb25f 2020-02-19 tracey if (error)
1716 ff4bb25f 2020-02-19 tracey goto done;
1717 ff4bb25f 2020-02-19 tracey
1718 ff4bb25f 2020-02-19 tracey if (gw_trans->action == GW_SUMMARY) {
1719 7b1f04a6 2020-03-11 tracey gw_trans->next_id = NULL;
1720 ff4bb25f 2020-02-19 tracey error = gw_output_repo_tags(gw_trans, header,
1721 ff4bb25f 2020-02-19 tracey D_MAXSLCOMMDISP, TAGBRIEF);
1722 ff4bb25f 2020-02-19 tracey if (error)
1723 ff4bb25f 2020-02-19 tracey goto done;
1724 ff4bb25f 2020-02-19 tracey } else {
1725 ff4bb25f 2020-02-19 tracey error = gw_output_repo_tags(gw_trans, header,
1726 ff4bb25f 2020-02-19 tracey gw_trans->gw_conf->got_max_commits_display, TAGBRIEF);
1727 ff4bb25f 2020-02-19 tracey if (error)
1728 ff4bb25f 2020-02-19 tracey goto done;
1729 ff4bb25f 2020-02-19 tracey }
1730 ff4bb25f 2020-02-19 tracey
1731 ff4bb25f 2020-02-19 tracey if (gw_trans->next_id || gw_trans->page > 0) {
1732 ff4bb25f 2020-02-19 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1733 ff4bb25f 2020-02-19 tracey KATTR_ID, "np_wrapper", KATTR__MAX);
1734 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
1735 ff4bb25f 2020-02-19 tracey goto done;
1736 ff4bb25f 2020-02-19 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1737 ff4bb25f 2020-02-19 tracey KATTR_ID, "nav_prev", KATTR__MAX);
1738 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
1739 ff4bb25f 2020-02-19 tracey goto done;
1740 ff4bb25f 2020-02-19 tracey }
1741 ff4bb25f 2020-02-19 tracey
1742 5a911940 2021-06-25 tracey if (gw_trans->prev_id) {
1743 f7632464 2020-04-14 tracey href_prev = khttp_urlpartx(NULL, NULL, "gotweb", "path",
1744 f7632464 2020-04-14 tracey KATTRX_STRING, gw_trans->repo_name, "page",
1745 f7632464 2020-04-14 tracey KATTRX_INT, (int64_t) (gw_trans->page - 1), "action",
1746 f7632464 2020-04-14 tracey KATTRX_STRING, "tags", "commit", KATTRX_STRING,
1747 5a911940 2021-06-25 tracey gw_trans->prev_id ? gw_trans->prev_id : "", NULL);
1748 19ff7638 2020-04-14 tracey if (href_prev == NULL) {
1749 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpartx");
1750 19ff7638 2020-04-14 tracey goto done;
1751 19ff7638 2020-04-14 tracey }
1752 ff4bb25f 2020-02-19 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
1753 ff4bb25f 2020-02-19 tracey KATTR_HREF, href_prev, KATTR__MAX);
1754 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
1755 ff4bb25f 2020-02-19 tracey goto done;
1756 ff4bb25f 2020-02-19 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Previous");
1757 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
1758 ff4bb25f 2020-02-19 tracey goto done;
1759 ff4bb25f 2020-02-19 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1760 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
1761 ff4bb25f 2020-02-19 tracey goto done;
1762 ff4bb25f 2020-02-19 tracey }
1763 ff4bb25f 2020-02-19 tracey
1764 ff4bb25f 2020-02-19 tracey if (gw_trans->next_id || gw_trans->page > 0) {
1765 ff4bb25f 2020-02-19 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1766 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
1767 ff4bb25f 2020-02-19 tracey return gw_kcgi_error(kerr);
1768 ff4bb25f 2020-02-19 tracey }
1769 ff4bb25f 2020-02-19 tracey
1770 ff4bb25f 2020-02-19 tracey if (gw_trans->next_id) {
1771 ff4bb25f 2020-02-19 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
1772 ff4bb25f 2020-02-19 tracey KATTR_ID, "nav_next", KATTR__MAX);
1773 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
1774 ff4bb25f 2020-02-19 tracey goto done;
1775 f7632464 2020-04-14 tracey href_next = khttp_urlpartx(NULL, NULL, "gotweb", "path",
1776 f7632464 2020-04-14 tracey KATTRX_STRING, gw_trans->repo_name, "page",
1777 f7632464 2020-04-14 tracey KATTRX_INT, (int64_t) (gw_trans->page + 1), "action",
1778 f7632464 2020-04-14 tracey KATTRX_STRING, "tags", "commit", KATTRX_STRING,
1779 5a911940 2021-06-25 tracey gw_trans->next_id, NULL);
1780 19ff7638 2020-04-14 tracey if (href_next == NULL) {
1781 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpartx");
1782 19ff7638 2020-04-14 tracey goto done;
1783 19ff7638 2020-04-14 tracey }
1784 ff4bb25f 2020-02-19 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
1785 ff4bb25f 2020-02-19 tracey KATTR_HREF, href_next, KATTR__MAX);
1786 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
1787 ff4bb25f 2020-02-19 tracey goto done;
1788 ff4bb25f 2020-02-19 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Next");
1789 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
1790 ff4bb25f 2020-02-19 tracey goto done;
1791 ff4bb25f 2020-02-19 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 3);
1792 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
1793 ff4bb25f 2020-02-19 tracey goto done;
1794 ff4bb25f 2020-02-19 tracey }
1795 ff4bb25f 2020-02-19 tracey
1796 ff4bb25f 2020-02-19 tracey if (gw_trans->next_id || gw_trans->page > 0) {
1797 ff4bb25f 2020-02-19 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
1798 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
1799 ff4bb25f 2020-02-19 tracey goto done;
1800 ff4bb25f 2020-02-19 tracey }
1801 ff4bb25f 2020-02-19 tracey done:
1802 ff4bb25f 2020-02-19 tracey gw_free_header(header);
1803 ff4bb25f 2020-02-19 tracey free(href_next);
1804 ff4bb25f 2020-02-19 tracey free(href_prev);
1805 626b25b6 2020-02-06 tracey if (error == NULL && kerr != KCGI_OK)
1806 626b25b6 2020-02-06 tracey error = gw_kcgi_error(kerr);
1807 4ff7391f 2020-01-28 tracey return error;
1808 4ff7391f 2020-01-28 tracey }
1809 4ff7391f 2020-01-28 tracey
1810 4ff7391f 2020-01-28 tracey static const struct got_error *
1811 4ff7391f 2020-01-28 tracey gw_tag(struct gw_trans *gw_trans)
1812 4ff7391f 2020-01-28 tracey {
1813 4ff7391f 2020-01-28 tracey const struct got_error *error = NULL;
1814 4ff7391f 2020-01-28 tracey struct gw_header *header = NULL;
1815 795c10a4 2020-02-20 tracey enum kcgi_err kerr = KCGI_OK;
1816 4ff7391f 2020-01-28 tracey
1817 7a6dddae 2021-06-18 stsp #ifndef PROFILE
1818 7cd52833 2022-06-23 thomas if (pledge("stdio rpath wpath cpath proc exec sendfd unveil", NULL) == -1)
1819 4ff7391f 2020-01-28 tracey return got_error_from_errno("pledge");
1820 7a6dddae 2021-06-18 stsp #endif
1821 4ff7391f 2020-01-28 tracey if ((header = gw_init_header()) == NULL)
1822 4ff7391f 2020-01-28 tracey return got_error_from_errno("malloc");
1823 4ff7391f 2020-01-28 tracey
1824 d4159696 2020-02-13 stsp error = gw_apply_unveil(gw_trans->gw_dir->path);
1825 4ff7391f 2020-01-28 tracey if (error)
1826 5ddf0079 2020-01-29 stsp goto done;
1827 4ff7391f 2020-01-28 tracey
1828 9f33591a 2020-02-14 tracey if (gw_trans->commit_id == NULL) {
1829 9f33591a 2020-02-14 tracey error = got_error_msg(GOT_ERR_QUERYSTRING,
1830 9f33591a 2020-02-14 tracey "commit required in querystring");
1831 9f33591a 2020-02-14 tracey goto done;
1832 9f33591a 2020-02-14 tracey }
1833 9f33591a 2020-02-14 tracey
1834 4ff7391f 2020-01-28 tracey error = gw_get_header(gw_trans, header, 1);
1835 4ff7391f 2020-01-28 tracey if (error)
1836 470cd826 2020-01-29 stsp goto done;
1837 4ff7391f 2020-01-28 tracey
1838 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1839 38b240fb 2020-02-06 tracey "tag_header_wrapper", KATTR__MAX);
1840 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
1841 38b240fb 2020-02-06 tracey goto done;
1842 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1843 38b240fb 2020-02-06 tracey "tag_header", KATTR__MAX);
1844 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
1845 38b240fb 2020-02-06 tracey goto done;
1846 38b240fb 2020-02-06 tracey error = gw_gen_commit_header(gw_trans, header->commit_id,
1847 38b240fb 2020-02-06 tracey header->refs_str);
1848 6eccd105 2020-02-03 stsp if (error)
1849 6eccd105 2020-02-03 stsp goto done;
1850 38b240fb 2020-02-06 tracey error = gw_gen_commit_msg_header(gw_trans, header->commit_msg);
1851 38b240fb 2020-02-06 tracey if (error)
1852 470cd826 2020-01-29 stsp goto done;
1853 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
1854 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
1855 470cd826 2020-01-29 stsp goto done;
1856 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1857 38b240fb 2020-02-06 tracey "dotted_line", KATTR__MAX);
1858 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
1859 38b240fb 2020-02-06 tracey goto done;
1860 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1861 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
1862 38b240fb 2020-02-06 tracey goto done;
1863 4ff7391f 2020-01-28 tracey
1864 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
1865 38b240fb 2020-02-06 tracey "tree", KATTR__MAX);
1866 4ff7391f 2020-01-28 tracey if (kerr != KCGI_OK)
1867 38b240fb 2020-02-06 tracey goto done;
1868 38b240fb 2020-02-06 tracey
1869 38b240fb 2020-02-06 tracey error = gw_output_repo_tags(gw_trans, header, 1, TAGFULL);
1870 38b240fb 2020-02-06 tracey if (error)
1871 38b240fb 2020-02-06 tracey goto done;
1872 38b240fb 2020-02-06 tracey
1873 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
1874 4ff7391f 2020-01-28 tracey done:
1875 b0a1bc86 2020-02-14 stsp gw_free_header(header);
1876 38b240fb 2020-02-06 tracey if (error == NULL && kerr != KCGI_OK)
1877 38b240fb 2020-02-06 tracey error = gw_kcgi_error(kerr);
1878 2c251c14 2020-01-15 tracey return error;
1879 2c251c14 2020-01-15 tracey }
1880 2c251c14 2020-01-15 tracey
1881 2c251c14 2020-01-15 tracey static const struct got_error *
1882 54415d85 2020-01-15 tracey gw_load_got_path(struct gw_trans *gw_trans, struct gw_dir *gw_dir)
1883 2c251c14 2020-01-15 tracey {
1884 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
1885 2c251c14 2020-01-15 tracey DIR *dt;
1886 2c251c14 2020-01-15 tracey char *dir_test;
1887 4ceb8155 2020-01-15 tracey int opened = 0;
1888 2c251c14 2020-01-15 tracey
1889 88d59c36 2020-01-29 stsp if (asprintf(&dir_test, "%s/%s/%s",
1890 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_repos_path, gw_dir->name,
1891 88d59c36 2020-01-29 stsp GOTWEB_GIT_DIR) == -1)
1892 2c251c14 2020-01-15 tracey return got_error_from_errno("asprintf");
1893 2c251c14 2020-01-15 tracey
1894 2c251c14 2020-01-15 tracey dt = opendir(dir_test);
1895 2c251c14 2020-01-15 tracey if (dt == NULL) {
1896 2c251c14 2020-01-15 tracey free(dir_test);
1897 2c251c14 2020-01-15 tracey } else {
1898 d1635ae4 2020-02-13 tracey gw_dir->path = strdup(dir_test);
1899 d1635ae4 2020-02-13 tracey if (gw_dir->path == NULL) {
1900 d1635ae4 2020-02-13 tracey opened = 1;
1901 d1635ae4 2020-02-13 tracey error = got_error_from_errno("strdup");
1902 a942aa37 2020-02-10 tracey goto errored;
1903 d1635ae4 2020-02-13 tracey }
1904 d1635ae4 2020-02-13 tracey opened = 1;
1905 2c251c14 2020-01-15 tracey goto done;
1906 2c251c14 2020-01-15 tracey }
1907 2c251c14 2020-01-15 tracey
1908 88d59c36 2020-01-29 stsp if (asprintf(&dir_test, "%s/%s/%s",
1909 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_repos_path, gw_dir->name,
1910 d81f9039 2020-02-13 stsp GOTWEB_GOT_DIR) == -1) {
1911 d81f9039 2020-02-13 stsp dir_test = NULL;
1912 d81f9039 2020-02-13 stsp error = got_error_from_errno("asprintf");
1913 d81f9039 2020-02-13 stsp goto errored;
1914 d81f9039 2020-02-13 stsp }
1915 2c251c14 2020-01-15 tracey
1916 2c251c14 2020-01-15 tracey dt = opendir(dir_test);
1917 2c251c14 2020-01-15 tracey if (dt == NULL)
1918 2c251c14 2020-01-15 tracey free(dir_test);
1919 2c251c14 2020-01-15 tracey else {
1920 4ceb8155 2020-01-15 tracey opened = 1;
1921 2c251c14 2020-01-15 tracey error = got_error(GOT_ERR_NOT_GIT_REPO);
1922 2c251c14 2020-01-15 tracey goto errored;
1923 2c251c14 2020-01-15 tracey }
1924 2c251c14 2020-01-15 tracey
1925 88d59c36 2020-01-29 stsp if (asprintf(&dir_test, "%s/%s",
1926 d81f9039 2020-02-13 stsp gw_trans->gw_conf->got_repos_path, gw_dir->name) == -1) {
1927 d81f9039 2020-02-13 stsp error = got_error_from_errno("asprintf");
1928 d81f9039 2020-02-13 stsp dir_test = NULL;
1929 d81f9039 2020-02-13 stsp goto errored;
1930 d81f9039 2020-02-13 stsp }
1931 2c251c14 2020-01-15 tracey
1932 d1635ae4 2020-02-13 tracey gw_dir->path = strdup(dir_test);
1933 d1635ae4 2020-02-13 tracey if (gw_dir->path == NULL) {
1934 a942aa37 2020-02-10 tracey opened = 1;
1935 d1635ae4 2020-02-13 tracey error = got_error_from_errno("strdup");
1936 a942aa37 2020-02-10 tracey goto errored;
1937 a942aa37 2020-02-10 tracey }
1938 cc18a904 2020-02-13 tracey
1939 cc18a904 2020-02-13 tracey dt = opendir(dir_test);
1940 cc18a904 2020-02-13 tracey if (dt == NULL) {
1941 d90bcdd6 2020-02-17 stsp error = got_error_path(gw_dir->name, GOT_ERR_NOT_GIT_REPO);
1942 cc18a904 2020-02-13 tracey goto errored;
1943 7ecc73af 2020-02-13 tracey } else
1944 7ecc73af 2020-02-13 tracey opened = 1;
1945 2c251c14 2020-01-15 tracey done:
1946 32cd4d18 2020-02-03 stsp error = gw_get_repo_description(&gw_dir->description, gw_trans,
1947 2c251c14 2020-01-15 tracey gw_dir->path);
1948 32cd4d18 2020-02-03 stsp if (error)
1949 32cd4d18 2020-02-03 stsp goto errored;
1950 9a1cc63f 2020-02-03 stsp error = gw_get_repo_owner(&gw_dir->owner, gw_trans, gw_dir->path);
1951 9a1cc63f 2020-02-03 stsp if (error)
1952 9a1cc63f 2020-02-03 stsp goto errored;
1953 d126c1b7 2020-01-29 stsp error = gw_get_repo_age(&gw_dir->age, gw_trans, gw_dir->path,
1954 2011c142 2020-02-14 stsp NULL, TM_DIFF);
1955 d126c1b7 2020-01-29 stsp if (error)
1956 d126c1b7 2020-01-29 stsp goto errored;
1957 59d3c40e 2020-02-03 stsp error = gw_get_clone_url(&gw_dir->url, gw_trans, gw_dir->path);
1958 2c251c14 2020-01-15 tracey errored:
1959 2c251c14 2020-01-15 tracey free(dir_test);
1960 2c251c14 2020-01-15 tracey if (opened)
1961 795c5bd7 2020-02-17 tracey if (dt && closedir(dt) == -1 && error == NULL)
1962 e227880d 2020-02-17 tracey error = got_error_from_errno("closedir");
1963 2c251c14 2020-01-15 tracey return error;
1964 2c251c14 2020-01-15 tracey }
1965 2c251c14 2020-01-15 tracey
1966 2c251c14 2020-01-15 tracey static const struct got_error *
1967 54415d85 2020-01-15 tracey gw_load_got_paths(struct gw_trans *gw_trans)
1968 2c251c14 2020-01-15 tracey {
1969 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
1970 2c251c14 2020-01-15 tracey DIR *d;
1971 2c251c14 2020-01-15 tracey struct dirent **sd_dent;
1972 2c251c14 2020-01-15 tracey struct gw_dir *gw_dir;
1973 2c251c14 2020-01-15 tracey struct stat st;
1974 2c251c14 2020-01-15 tracey unsigned int d_cnt, d_i;
1975 2c251c14 2020-01-15 tracey
1976 2c251c14 2020-01-15 tracey d = opendir(gw_trans->gw_conf->got_repos_path);
1977 2c251c14 2020-01-15 tracey if (d == NULL) {
1978 2c251c14 2020-01-15 tracey error = got_error_from_errno2("opendir",
1979 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_repos_path);
1980 2c251c14 2020-01-15 tracey return error;
1981 2c251c14 2020-01-15 tracey }
1982 2c251c14 2020-01-15 tracey
1983 2c251c14 2020-01-15 tracey d_cnt = scandir(gw_trans->gw_conf->got_repos_path, &sd_dent, NULL,
1984 2c251c14 2020-01-15 tracey alphasort);
1985 2c251c14 2020-01-15 tracey if (d_cnt == -1) {
1986 2c251c14 2020-01-15 tracey error = got_error_from_errno2("scandir",
1987 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_repos_path);
1988 8182bd34 2020-02-17 tracey goto done;
1989 2c251c14 2020-01-15 tracey }
1990 2c251c14 2020-01-15 tracey
1991 2c251c14 2020-01-15 tracey for (d_i = 0; d_i < d_cnt; d_i++) {
1992 2c251c14 2020-01-15 tracey if (gw_trans->gw_conf->got_max_repos > 0 &&
1993 2c251c14 2020-01-15 tracey (d_i - 2) == gw_trans->gw_conf->got_max_repos)
1994 2c251c14 2020-01-15 tracey break; /* account for parent and self */
1995 2c251c14 2020-01-15 tracey
1996 2c251c14 2020-01-15 tracey if (strcmp(sd_dent[d_i]->d_name, ".") == 0 ||
1997 2c251c14 2020-01-15 tracey strcmp(sd_dent[d_i]->d_name, "..") == 0)
1998 2c251c14 2020-01-15 tracey continue;
1999 2c251c14 2020-01-15 tracey
2000 4619e1f2 2020-02-13 stsp error = gw_init_gw_dir(&gw_dir, sd_dent[d_i]->d_name);
2001 4619e1f2 2020-02-13 stsp if (error)
2002 8182bd34 2020-02-17 tracey goto done;
2003 2c251c14 2020-01-15 tracey
2004 2c251c14 2020-01-15 tracey error = gw_load_got_path(gw_trans, gw_dir);
2005 7bf16821 2020-02-07 stsp if (error && error->code == GOT_ERR_NOT_GIT_REPO) {
2006 7bf16821 2020-02-07 stsp error = NULL;
2007 2c251c14 2020-01-15 tracey continue;
2008 0526966e 2022-01-25 thomas } else if (error && error->code != GOT_ERR_LONELY_PACKIDX)
2009 8182bd34 2020-02-17 tracey goto done;
2010 2c251c14 2020-01-15 tracey
2011 2c251c14 2020-01-15 tracey if (lstat(gw_dir->path, &st) == 0 && S_ISDIR(st.st_mode) &&
2012 2c251c14 2020-01-15 tracey !got_path_dir_is_empty(gw_dir->path)) {
2013 2c251c14 2020-01-15 tracey TAILQ_INSERT_TAIL(&gw_trans->gw_dirs, gw_dir,
2014 2c251c14 2020-01-15 tracey entry);
2015 2c251c14 2020-01-15 tracey gw_trans->repos_total++;
2016 2c251c14 2020-01-15 tracey }
2017 2c251c14 2020-01-15 tracey }
2018 8182bd34 2020-02-17 tracey done:
2019 e227880d 2020-02-17 tracey if (d && closedir(d) == -1 && error == NULL)
2020 e227880d 2020-02-17 tracey error = got_error_from_errno("closedir");
2021 2c251c14 2020-01-15 tracey return error;
2022 2c251c14 2020-01-15 tracey }
2023 2c251c14 2020-01-15 tracey
2024 2c251c14 2020-01-15 tracey static const struct got_error *
2025 54415d85 2020-01-15 tracey gw_parse_querystring(struct gw_trans *gw_trans)
2026 2c251c14 2020-01-15 tracey {
2027 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
2028 2c251c14 2020-01-15 tracey struct kpair *p;
2029 fa8129f7 2022-03-22 thomas const struct gw_query_action *action = NULL;
2030 2c251c14 2020-01-15 tracey unsigned int i;
2031 2c251c14 2020-01-15 tracey
2032 2c251c14 2020-01-15 tracey if (gw_trans->gw_req->fieldnmap[0]) {
2033 8f214b62 2020-02-17 stsp return got_error(GOT_ERR_QUERYSTRING);
2034 2c251c14 2020-01-15 tracey } else if ((p = gw_trans->gw_req->fieldmap[KEY_PATH])) {
2035 2c251c14 2020-01-15 tracey /* define gw_trans->repo_path */
2036 f652ec0c 2020-02-13 stsp gw_trans->repo_name = p->parsed.s;
2037 2c251c14 2020-01-15 tracey
2038 88d59c36 2020-01-29 stsp if (asprintf(&gw_trans->repo_path, "%s/%s",
2039 88d59c36 2020-01-29 stsp gw_trans->gw_conf->got_repos_path, p->parsed.s) == -1)
2040 2c251c14 2020-01-15 tracey return got_error_from_errno("asprintf");
2041 2c251c14 2020-01-15 tracey
2042 2c251c14 2020-01-15 tracey /* get action and set function */
2043 f1200fe3 2020-02-13 tracey if ((p = gw_trans->gw_req->fieldmap[KEY_ACTION])) {
2044 2c251c14 2020-01-15 tracey for (i = 0; i < nitems(gw_query_funcs); i++) {
2045 2c251c14 2020-01-15 tracey action = &gw_query_funcs[i];
2046 f1200fe3 2020-02-13 tracey if (action->func_name == NULL)
2047 2c251c14 2020-01-15 tracey continue;
2048 f1200fe3 2020-02-13 tracey if (strcmp(action->func_name,
2049 f1200fe3 2020-02-13 tracey p->parsed.s) == 0) {
2050 f1200fe3 2020-02-13 tracey gw_trans->action = i;
2051 f1200fe3 2020-02-13 tracey break;
2052 f1200fe3 2020-02-13 tracey }
2053 f1200fe3 2020-02-13 tracey }
2054 6f6f771f 2020-02-13 tracey }
2055 6f6f771f 2020-02-13 tracey if (gw_trans->action == -1) {
2056 6f6f771f 2020-02-13 tracey gw_trans->action = GW_ERR;
2057 8f214b62 2020-02-17 stsp gw_trans->error = got_error_msg(GOT_ERR_QUERYSTRING,
2058 8f214b62 2020-02-17 stsp p != NULL ? "bad action in querystring" :
2059 8f214b62 2020-02-17 stsp "no action in querystring");
2060 cc18a904 2020-02-13 tracey return error;
2061 f1200fe3 2020-02-13 tracey }
2062 ec46ccd7 2020-01-15 tracey
2063 abc59930 2021-09-05 naddy if ((p = gw_trans->gw_req->fieldmap[KEY_COMMIT_ID])) {
2064 56997cd3 2020-02-14 tracey if (asprintf(&gw_trans->commit_id, "%s",
2065 88d59c36 2020-01-29 stsp p->parsed.s) == -1)
2066 ec46ccd7 2020-01-15 tracey return got_error_from_errno("asprintf");
2067 26dc3004 2020-02-13 stsp }
2068 2c251c14 2020-01-15 tracey
2069 4d6abe2b 2020-02-13 stsp if ((p = gw_trans->gw_req->fieldmap[KEY_FILE]))
2070 4d6abe2b 2020-02-13 stsp gw_trans->repo_file = p->parsed.s;
2071 8087c3c5 2020-01-15 tracey
2072 26dc3004 2020-02-13 stsp if ((p = gw_trans->gw_req->fieldmap[KEY_FOLDER])) {
2073 88d59c36 2020-01-29 stsp if (asprintf(&gw_trans->repo_folder, "%s",
2074 55e46400 2020-02-18 tracey p->parsed.s) == -1)
2075 55e46400 2020-02-18 tracey return got_error_from_errno("asprintf");
2076 55e46400 2020-02-18 tracey }
2077 55e46400 2020-02-18 tracey
2078 55e46400 2020-02-18 tracey if ((p = gw_trans->gw_req->fieldmap[KEY_PREV_ID])) {
2079 55e46400 2020-02-18 tracey if (asprintf(&gw_trans->prev_id, "%s",
2080 55e46400 2020-02-18 tracey p->parsed.s) == -1)
2081 55e46400 2020-02-18 tracey return got_error_from_errno("asprintf");
2082 55e46400 2020-02-18 tracey }
2083 55e46400 2020-02-18 tracey
2084 742ba378 2020-02-14 stsp if ((p = gw_trans->gw_req->fieldmap[KEY_HEADREF]))
2085 742ba378 2020-02-14 stsp gw_trans->headref = p->parsed.s;
2086 2c251c14 2020-01-15 tracey
2087 4619e1f2 2020-02-13 stsp error = gw_init_gw_dir(&gw_trans->gw_dir, gw_trans->repo_name);
2088 4619e1f2 2020-02-13 stsp if (error)
2089 4619e1f2 2020-02-13 stsp return error;
2090 46b9c89b 2020-01-15 tracey
2091 cc18a904 2020-02-13 tracey gw_trans->error = gw_load_got_path(gw_trans, gw_trans->gw_dir);
2092 2c251c14 2020-01-15 tracey } else
2093 2c251c14 2020-01-15 tracey gw_trans->action = GW_INDEX;
2094 2c251c14 2020-01-15 tracey
2095 2c251c14 2020-01-15 tracey if ((p = gw_trans->gw_req->fieldmap[KEY_PAGE]))
2096 2c251c14 2020-01-15 tracey gw_trans->page = p->parsed.i;
2097 2c251c14 2020-01-15 tracey
2098 2c251c14 2020-01-15 tracey return error;
2099 2c251c14 2020-01-15 tracey }
2100 2c251c14 2020-01-15 tracey
2101 4619e1f2 2020-02-13 stsp static const struct got_error *
2102 f652ec0c 2020-02-13 stsp gw_init_gw_dir(struct gw_dir **gw_dir, const char *dir)
2103 4619e1f2 2020-02-13 stsp {
2104 4619e1f2 2020-02-13 stsp const struct got_error *error;
2105 2c251c14 2020-01-15 tracey
2106 4619e1f2 2020-02-13 stsp *gw_dir = malloc(sizeof(**gw_dir));
2107 4619e1f2 2020-02-13 stsp if (*gw_dir == NULL)
2108 4619e1f2 2020-02-13 stsp return got_error_from_errno("malloc");
2109 2c251c14 2020-01-15 tracey
2110 4619e1f2 2020-02-13 stsp if (asprintf(&(*gw_dir)->name, "%s", dir) == -1) {
2111 4619e1f2 2020-02-13 stsp error = got_error_from_errno("asprintf");
2112 4619e1f2 2020-02-13 stsp free(*gw_dir);
2113 4619e1f2 2020-02-13 stsp *gw_dir = NULL;
2114 e9a8bbf7 2020-05-29 tracey return error;
2115 4619e1f2 2020-02-13 stsp }
2116 2c251c14 2020-01-15 tracey
2117 4619e1f2 2020-02-13 stsp return NULL;
2118 474370cb 2020-01-15 tracey }
2119 474370cb 2020-01-15 tracey
2120 c25c2314 2020-01-28 stsp static const struct got_error *
2121 54415d85 2020-01-15 tracey gw_display_open(struct gw_trans *gw_trans, enum khttp code, enum kmime mime)
2122 2c251c14 2020-01-15 tracey {
2123 795c10a4 2020-02-20 tracey enum kcgi_err kerr = KCGI_OK;
2124 c25c2314 2020-01-28 stsp
2125 c25c2314 2020-01-28 stsp kerr = khttp_head(gw_trans->gw_req, kresps[KRESP_ALLOW], "GET");
2126 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
2127 2447adad 2020-02-06 stsp return gw_kcgi_error(kerr);
2128 c25c2314 2020-01-28 stsp kerr = khttp_head(gw_trans->gw_req, kresps[KRESP_STATUS], "%s",
2129 2c251c14 2020-01-15 tracey khttps[code]);
2130 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
2131 2447adad 2020-02-06 stsp return gw_kcgi_error(kerr);
2132 c25c2314 2020-01-28 stsp kerr = khttp_head(gw_trans->gw_req, kresps[KRESP_CONTENT_TYPE], "%s",
2133 2c251c14 2020-01-15 tracey kmimetypes[mime]);
2134 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
2135 2447adad 2020-02-06 stsp return gw_kcgi_error(kerr);
2136 017d6da3 2020-01-29 tracey kerr = khttp_head(gw_trans->gw_req, "X-Content-Type-Options",
2137 017d6da3 2020-01-29 tracey "nosniff");
2138 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
2139 2447adad 2020-02-06 stsp return gw_kcgi_error(kerr);
2140 c25c2314 2020-01-28 stsp kerr = khttp_head(gw_trans->gw_req, "X-Frame-Options", "DENY");
2141 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
2142 2447adad 2020-02-06 stsp return gw_kcgi_error(kerr);
2143 017d6da3 2020-01-29 tracey kerr = khttp_head(gw_trans->gw_req, "X-XSS-Protection",
2144 017d6da3 2020-01-29 tracey "1; mode=block");
2145 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK)
2146 2447adad 2020-02-06 stsp return gw_kcgi_error(kerr);
2147 c25c2314 2020-01-28 stsp
2148 017d6da3 2020-01-29 tracey if (gw_trans->mime == KMIME_APP_OCTET_STREAM) {
2149 017d6da3 2020-01-29 tracey kerr = khttp_head(gw_trans->gw_req,
2150 017d6da3 2020-01-29 tracey kresps[KRESP_CONTENT_DISPOSITION],
2151 017d6da3 2020-01-29 tracey "attachment; filename=%s", gw_trans->repo_file);
2152 017d6da3 2020-01-29 tracey if (kerr != KCGI_OK)
2153 2447adad 2020-02-06 stsp return gw_kcgi_error(kerr);
2154 017d6da3 2020-01-29 tracey }
2155 017d6da3 2020-01-29 tracey
2156 c25c2314 2020-01-28 stsp kerr = khttp_body(gw_trans->gw_req);
2157 2447adad 2020-02-06 stsp return gw_kcgi_error(kerr);
2158 2c251c14 2020-01-15 tracey }
2159 2c251c14 2020-01-15 tracey
2160 c25c2314 2020-01-28 stsp static const struct got_error *
2161 6d8d8a26 2020-01-29 stsp gw_display_index(struct gw_trans *gw_trans)
2162 2c251c14 2020-01-15 tracey {
2163 4bec7539 2020-01-29 stsp const struct got_error *error;
2164 795c10a4 2020-02-20 tracey enum kcgi_err kerr = KCGI_OK;
2165 c25c2314 2020-01-28 stsp
2166 cc18a904 2020-02-13 tracey /* catch early querystring errors */
2167 cc18a904 2020-02-13 tracey if (gw_trans->error)
2168 cc18a904 2020-02-13 tracey gw_trans->action = GW_ERR;
2169 cc18a904 2020-02-13 tracey
2170 4bec7539 2020-01-29 stsp error = gw_display_open(gw_trans, KHTTP_200, gw_trans->mime);
2171 4bec7539 2020-01-29 stsp if (error)
2172 4bec7539 2020-01-29 stsp return error;
2173 4bec7539 2020-01-29 stsp
2174 f7cc9480 2020-02-05 tracey kerr = khtml_open(gw_trans->gw_html_req, gw_trans->gw_req, 0);
2175 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2176 2447adad 2020-02-06 stsp return gw_kcgi_error(kerr);
2177 2c251c14 2020-01-15 tracey
2178 017d6da3 2020-01-29 tracey if (gw_trans->action != GW_BLOB) {
2179 017d6da3 2020-01-29 tracey kerr = khttp_template(gw_trans->gw_req, gw_trans->gw_tmpl,
2180 017d6da3 2020-01-29 tracey gw_query_funcs[gw_trans->action].template);
2181 017d6da3 2020-01-29 tracey if (kerr != KCGI_OK) {
2182 017d6da3 2020-01-29 tracey khtml_close(gw_trans->gw_html_req);
2183 2447adad 2020-02-06 stsp return gw_kcgi_error(kerr);
2184 017d6da3 2020-01-29 tracey }
2185 7a9bfbff 2020-01-29 stsp }
2186 2c251c14 2020-01-15 tracey
2187 7a9bfbff 2020-01-29 stsp return gw_kcgi_error(khtml_close(gw_trans->gw_html_req));
2188 2c251c14 2020-01-15 tracey }
2189 2c251c14 2020-01-15 tracey
2190 f1200fe3 2020-02-13 tracey static const struct got_error *
2191 f1200fe3 2020-02-13 tracey gw_error(struct gw_trans *gw_trans)
2192 6d8d8a26 2020-01-29 stsp {
2193 795c10a4 2020-02-20 tracey enum kcgi_err kerr = KCGI_OK;
2194 6d8d8a26 2020-01-29 stsp
2195 f1200fe3 2020-02-13 tracey kerr = khtml_puts(gw_trans->gw_html_req, gw_trans->error->msg);
2196 f1200fe3 2020-02-13 tracey
2197 f1200fe3 2020-02-13 tracey return gw_kcgi_error(kerr);
2198 6d8d8a26 2020-01-29 stsp }
2199 6d8d8a26 2020-01-29 stsp
2200 2c251c14 2020-01-15 tracey static int
2201 2c251c14 2020-01-15 tracey gw_template(size_t key, void *arg)
2202 2c251c14 2020-01-15 tracey {
2203 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
2204 795c10a4 2020-02-20 tracey enum kcgi_err kerr = KCGI_OK;
2205 54415d85 2020-01-15 tracey struct gw_trans *gw_trans = arg;
2206 9f6f3943 2020-09-24 tracey char *ati = NULL, *fic32 = NULL, *fic16 = NULL;
2207 9f6f3943 2020-09-24 tracey char *swm = NULL, *spt = NULL, *css = NULL, *logo = NULL;
2208 2c251c14 2020-01-15 tracey
2209 9f6f3943 2020-09-24 tracey if (asprintf(&ati, "%s%s", gw_trans->gw_conf->got_www_path,
2210 9f6f3943 2020-09-24 tracey "/apple-touch-icon.png") == -1)
2211 9f6f3943 2020-09-24 tracey goto err;
2212 9f6f3943 2020-09-24 tracey if (asprintf(&fic32, "%s%s", gw_trans->gw_conf->got_www_path,
2213 62d463ca 2020-10-20 naddy "/favicon-32x32.png") == -1)
2214 9f6f3943 2020-09-24 tracey goto err;
2215 9f6f3943 2020-09-24 tracey if (asprintf(&fic16, "%s%s", gw_trans->gw_conf->got_www_path,
2216 9f6f3943 2020-09-24 tracey "/favicon-16x16.png") == -1)
2217 9f6f3943 2020-09-24 tracey goto err;
2218 9f6f3943 2020-09-24 tracey if (asprintf(&swm, "%s%s", gw_trans->gw_conf->got_www_path,
2219 9f6f3943 2020-09-24 tracey "/site.webmanifest") == -1)
2220 9f6f3943 2020-09-24 tracey goto err;
2221 9f6f3943 2020-09-24 tracey if (asprintf(&spt, "%s%s", gw_trans->gw_conf->got_www_path,
2222 9f6f3943 2020-09-24 tracey "/safari-pinned-tab.svg") == -1)
2223 9f6f3943 2020-09-24 tracey goto err;
2224 9f6f3943 2020-09-24 tracey if (asprintf(&css, "%s%s", gw_trans->gw_conf->got_www_path,
2225 9f6f3943 2020-09-24 tracey "/gotweb.css") == -1)
2226 9f6f3943 2020-09-24 tracey goto err;
2227 9f6f3943 2020-09-24 tracey if (asprintf(&logo, "%s%s%s", gw_trans->gw_conf->got_www_path,
2228 9f6f3943 2020-09-24 tracey gw_trans->gw_conf->got_www_path ? "/" : "",
2229 9f6f3943 2020-09-24 tracey gw_trans->gw_conf->got_logo) == -1)
2230 9f6f3943 2020-09-24 tracey goto err;
2231 9f6f3943 2020-09-24 tracey
2232 2c251c14 2020-01-15 tracey switch (key) {
2233 2c251c14 2020-01-15 tracey case (TEMPL_HEAD):
2234 aaed5792 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_META,
2235 1dcb8908 2020-02-12 tracey KATTR_NAME, "viewport",
2236 1dcb8908 2020-02-12 tracey KATTR_CONTENT, "initial-scale=.75, user-scalable=yes",
2237 aaed5792 2020-02-08 tracey KATTR__MAX);
2238 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
2239 bd275801 2020-02-03 tracey return 0;
2240 aaed5792 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2241 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2242 aaed5792 2020-02-08 tracey return 0;
2243 aaed5792 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_META,
2244 aaed5792 2020-02-08 tracey KATTR_CHARSET, "utf-8",
2245 aaed5792 2020-02-08 tracey KATTR__MAX);
2246 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2247 aaed5792 2020-02-08 tracey return 0;
2248 aaed5792 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2249 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2250 aaed5792 2020-02-08 tracey return 0;
2251 aaed5792 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_META,
2252 aaed5792 2020-02-08 tracey KATTR_NAME, "msapplication-TileColor",
2253 aaed5792 2020-02-08 tracey KATTR_CONTENT, "#da532c", KATTR__MAX);
2254 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2255 aaed5792 2020-02-08 tracey return 0;
2256 aaed5792 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2257 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2258 aaed5792 2020-02-08 tracey return 0;
2259 aaed5792 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_META,
2260 aaed5792 2020-02-08 tracey KATTR_NAME, "theme-color",
2261 aaed5792 2020-02-08 tracey KATTR_CONTENT, "#ffffff", KATTR__MAX);
2262 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2263 aaed5792 2020-02-08 tracey return 0;
2264 aaed5792 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2265 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2266 aaed5792 2020-02-08 tracey return 0;
2267 aaed5792 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_LINK,
2268 aaed5792 2020-02-08 tracey KATTR_REL, "apple-touch-icon", KATTR_SIZES, "180x180",
2269 9f6f3943 2020-09-24 tracey KATTR_HREF, ati, KATTR__MAX);
2270 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2271 aaed5792 2020-02-08 tracey return 0;
2272 aaed5792 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2273 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2274 aaed5792 2020-02-08 tracey return 0;
2275 aaed5792 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_LINK,
2276 aaed5792 2020-02-08 tracey KATTR_REL, "icon", KATTR_TYPE, "image/png", KATTR_SIZES,
2277 9f6f3943 2020-09-24 tracey "32x32", KATTR_HREF, fic32, KATTR__MAX);
2278 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2279 aaed5792 2020-02-08 tracey return 0;
2280 aaed5792 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2281 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2282 aaed5792 2020-02-08 tracey return 0;
2283 aaed5792 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_LINK,
2284 aaed5792 2020-02-08 tracey KATTR_REL, "icon", KATTR_TYPE, "image/png", KATTR_SIZES,
2285 9f6f3943 2020-09-24 tracey "16x16", KATTR_HREF, fic16, KATTR__MAX);
2286 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2287 aaed5792 2020-02-08 tracey return 0;
2288 aaed5792 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2289 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2290 aaed5792 2020-02-08 tracey return 0;
2291 aaed5792 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_LINK,
2292 9f6f3943 2020-09-24 tracey KATTR_REL, "manifest", KATTR_HREF, swm,
2293 aaed5792 2020-02-08 tracey KATTR__MAX);
2294 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2295 aaed5792 2020-02-08 tracey return 0;
2296 aaed5792 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2297 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2298 aaed5792 2020-02-08 tracey return 0;
2299 aaed5792 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_LINK,
2300 aaed5792 2020-02-08 tracey KATTR_REL, "mask-icon", KATTR_HREF,
2301 9f6f3943 2020-09-24 tracey spt, KATTR__MAX);
2302 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2303 aaed5792 2020-02-08 tracey return 0;
2304 aaed5792 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2305 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2306 aaed5792 2020-02-08 tracey return 0;
2307 aaed5792 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_LINK,
2308 aaed5792 2020-02-08 tracey KATTR_REL, "stylesheet", KATTR_TYPE, "text/css",
2309 9f6f3943 2020-09-24 tracey KATTR_HREF, css, KATTR__MAX);
2310 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2311 aaed5792 2020-02-08 tracey return 0;
2312 aaed5792 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2313 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2314 aaed5792 2020-02-08 tracey return 0;
2315 2c251c14 2020-01-15 tracey break;
2316 2c251c14 2020-01-15 tracey case(TEMPL_HEADER):
2317 185ba3ba 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2318 185ba3ba 2020-02-04 tracey KATTR_ID, "got_link", KATTR__MAX);
2319 185ba3ba 2020-02-04 tracey if (kerr != KCGI_OK)
2320 185ba3ba 2020-02-04 tracey return 0;
2321 185ba3ba 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
2322 185ba3ba 2020-02-04 tracey KATTR_HREF, gw_trans->gw_conf->got_logo_url,
2323 185ba3ba 2020-02-04 tracey KATTR_TARGET, "_sotd", KATTR__MAX);
2324 185ba3ba 2020-02-04 tracey if (kerr != KCGI_OK)
2325 185ba3ba 2020-02-04 tracey return 0;
2326 185ba3ba 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_IMG,
2327 9f6f3943 2020-09-24 tracey KATTR_SRC, logo, KATTR__MAX);
2328 9f6f3943 2020-09-24 tracey if (kerr != KCGI_OK)
2329 185ba3ba 2020-02-04 tracey return 0;
2330 185ba3ba 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 3);
2331 9f6f3943 2020-09-24 tracey if (kerr != KCGI_OK)
2332 185ba3ba 2020-02-04 tracey return 0;
2333 2c251c14 2020-01-15 tracey break;
2334 2c251c14 2020-01-15 tracey case (TEMPL_SITEPATH):
2335 4ae179a2 2020-02-08 tracey error = gw_output_site_link(gw_trans);
2336 4ae179a2 2020-02-08 tracey if (error)
2337 4ae179a2 2020-02-08 tracey return 0;
2338 2c251c14 2020-01-15 tracey break;
2339 2c251c14 2020-01-15 tracey case(TEMPL_TITLE):
2340 bd275801 2020-02-03 tracey if (gw_trans->gw_conf->got_site_name != NULL) {
2341 bd275801 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req,
2342 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_site_name);
2343 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
2344 bd275801 2020-02-03 tracey return 0;
2345 bd275801 2020-02-03 tracey }
2346 2c251c14 2020-01-15 tracey break;
2347 2c251c14 2020-01-15 tracey case (TEMPL_SEARCH):
2348 63ee0dca 2020-02-08 tracey break;
2349 63ee0dca 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
2350 63ee0dca 2020-02-08 tracey "search", KATTR__MAX);
2351 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
2352 bd275801 2020-02-03 tracey return 0;
2353 63ee0dca 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_FORM,
2354 63ee0dca 2020-02-08 tracey KATTR_METHOD, "POST", KATTR__MAX);
2355 63ee0dca 2020-02-08 tracey if (kerr != KCGI_OK)
2356 63ee0dca 2020-02-08 tracey return 0;
2357 63ee0dca 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_INPUT, KATTR_ID,
2358 63ee0dca 2020-02-08 tracey "got-search", KATTR_NAME, "got-search", KATTR_SIZE, "15",
2359 63ee0dca 2020-02-08 tracey KATTR_MAXLENGTH, "50", KATTR__MAX);
2360 63ee0dca 2020-02-08 tracey if (kerr != KCGI_OK)
2361 63ee0dca 2020-02-08 tracey return 0;
2362 63ee0dca 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_BUTTON,
2363 63ee0dca 2020-02-08 tracey KATTR__MAX);
2364 63ee0dca 2020-02-08 tracey if (kerr != KCGI_OK)
2365 63ee0dca 2020-02-08 tracey return 0;
2366 63ee0dca 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Search");
2367 63ee0dca 2020-02-08 tracey if (kerr != KCGI_OK)
2368 63ee0dca 2020-02-08 tracey return 0;
2369 63ee0dca 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 4);
2370 63ee0dca 2020-02-08 tracey if (kerr != KCGI_OK)
2371 63ee0dca 2020-02-08 tracey return 0;
2372 2c251c14 2020-01-15 tracey break;
2373 2c251c14 2020-01-15 tracey case(TEMPL_SITEOWNER):
2374 2c251c14 2020-01-15 tracey if (gw_trans->gw_conf->got_site_owner != NULL &&
2375 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_show_site_owner) {
2376 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2377 bd275801 2020-02-03 tracey KATTR_ID, "site_owner_wrapper", KATTR__MAX);
2378 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
2379 070fee27 2020-02-03 stsp return 0;
2380 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2381 bd275801 2020-02-03 tracey KATTR_ID, "site_owner", KATTR__MAX);
2382 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
2383 2c251c14 2020-01-15 tracey return 0;
2384 bd275801 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req,
2385 bd275801 2020-02-03 tracey gw_trans->gw_conf->got_site_owner);
2386 bd275801 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
2387 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
2388 bd275801 2020-02-03 tracey return 0;
2389 2c251c14 2020-01-15 tracey }
2390 2c251c14 2020-01-15 tracey break;
2391 2c251c14 2020-01-15 tracey case(TEMPL_CONTENT):
2392 2c251c14 2020-01-15 tracey error = gw_query_funcs[gw_trans->action].func_main(gw_trans);
2393 bd275801 2020-02-03 tracey if (error) {
2394 0d100d0b 2020-02-07 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2395 0d100d0b 2020-02-07 tracey KATTR_ID, "tmpl_err", KATTR__MAX);
2396 0d100d0b 2020-02-07 tracey if (kerr != KCGI_OK)
2397 0d100d0b 2020-02-07 tracey return 0;
2398 f08447b0 2020-04-14 tracey kerr = khttp_printf(gw_trans->gw_req, "Error: %s",
2399 f08447b0 2020-04-14 tracey error->msg);
2400 0d100d0b 2020-02-07 tracey if (kerr != KCGI_OK)
2401 0d100d0b 2020-02-07 tracey return 0;
2402 0d100d0b 2020-02-07 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2403 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
2404 bd275801 2020-02-03 tracey return 0;
2405 bd275801 2020-02-03 tracey }
2406 2c251c14 2020-01-15 tracey break;
2407 2c251c14 2020-01-15 tracey default:
2408 2c251c14 2020-01-15 tracey return 0;
2409 2c251c14 2020-01-15 tracey }
2410 9f6f3943 2020-09-24 tracey free(ati);
2411 9f6f3943 2020-09-24 tracey free(fic32);
2412 9f6f3943 2020-09-24 tracey free(fic16);
2413 9f6f3943 2020-09-24 tracey free(swm);
2414 9f6f3943 2020-09-24 tracey free(spt);
2415 9f6f3943 2020-09-24 tracey free(css);
2416 9f6f3943 2020-09-24 tracey free(logo);
2417 2c251c14 2020-01-15 tracey return 1;
2418 9f6f3943 2020-09-24 tracey err:
2419 9f6f3943 2020-09-24 tracey free(ati);
2420 9f6f3943 2020-09-24 tracey free(fic32);
2421 9f6f3943 2020-09-24 tracey free(fic16);
2422 9f6f3943 2020-09-24 tracey free(swm);
2423 9f6f3943 2020-09-24 tracey free(spt);
2424 9f6f3943 2020-09-24 tracey free(css);
2425 9f6f3943 2020-09-24 tracey free(logo);
2426 9f6f3943 2020-09-24 tracey return 0;
2427 f2f46662 2020-01-23 tracey }
2428 21a55cc7 2020-02-04 tracey
2429 21a55cc7 2020-02-04 tracey static const struct got_error *
2430 21a55cc7 2020-02-04 tracey gw_gen_commit_header(struct gw_trans *gw_trans, char *str1, char *str2)
2431 21a55cc7 2020-02-04 tracey {
2432 21a55cc7 2020-02-04 tracey const struct got_error *error = NULL;
2433 21a55cc7 2020-02-04 tracey enum kcgi_err kerr = KCGI_OK;
2434 21a55cc7 2020-02-04 tracey
2435 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2436 21a55cc7 2020-02-04 tracey KATTR_ID, "header_commit_title", KATTR__MAX);
2437 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2438 21a55cc7 2020-02-04 tracey goto done;
2439 21a55cc7 2020-02-04 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Commit: ");
2440 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2441 21a55cc7 2020-02-04 tracey goto done;
2442 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2443 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2444 21a55cc7 2020-02-04 tracey goto done;
2445 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2446 21a55cc7 2020-02-04 tracey KATTR_ID, "header_commit", KATTR__MAX);
2447 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2448 21a55cc7 2020-02-04 tracey goto done;
2449 32b9f7ed 2020-04-14 tracey kerr = khtml_printf(gw_trans->gw_html_req, "%s ", str1);
2450 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2451 21a55cc7 2020-02-04 tracey goto done;
2452 5c65becf 2020-02-13 tracey if (str2 != NULL) {
2453 bf93a5c0 2020-02-15 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_SPAN,
2454 bf93a5c0 2020-02-15 tracey KATTR_ID, "refs_str", KATTR__MAX);
2455 5c65becf 2020-02-13 tracey if (kerr != KCGI_OK)
2456 5c65becf 2020-02-13 tracey goto done;
2457 32b9f7ed 2020-04-14 tracey kerr = khtml_printf(gw_trans->gw_html_req, "(%s)", str2);
2458 bf93a5c0 2020-02-15 tracey if (kerr != KCGI_OK)
2459 bf93a5c0 2020-02-15 tracey goto done;
2460 bf93a5c0 2020-02-15 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2461 5c65becf 2020-02-13 tracey if (kerr != KCGI_OK)
2462 5c65becf 2020-02-13 tracey goto done;
2463 5c65becf 2020-02-13 tracey }
2464 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2465 21a55cc7 2020-02-04 tracey done:
2466 21a55cc7 2020-02-04 tracey if (error == NULL && kerr != KCGI_OK)
2467 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
2468 21a55cc7 2020-02-04 tracey return error;
2469 21a55cc7 2020-02-04 tracey }
2470 21a55cc7 2020-02-04 tracey
2471 f7cc9480 2020-02-05 tracey static const struct got_error *
2472 f7cc9480 2020-02-05 tracey gw_gen_diff_header(struct gw_trans *gw_trans, char *str1, char *str2)
2473 f2f46662 2020-01-23 tracey {
2474 27192be7 2020-02-04 tracey const struct got_error *error = NULL;
2475 f7cc9480 2020-02-05 tracey enum kcgi_err kerr = KCGI_OK;
2476 f2f46662 2020-01-23 tracey
2477 f7cc9480 2020-02-05 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2478 f7cc9480 2020-02-05 tracey KATTR_ID, "header_diff_title", KATTR__MAX);
2479 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2480 f7cc9480 2020-02-05 tracey goto done;
2481 f7cc9480 2020-02-05 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Diff: ");
2482 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2483 f7cc9480 2020-02-05 tracey goto done;
2484 f7cc9480 2020-02-05 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2485 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2486 f7cc9480 2020-02-05 tracey goto done;
2487 f7cc9480 2020-02-05 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2488 f7cc9480 2020-02-05 tracey KATTR_ID, "header_diff", KATTR__MAX);
2489 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2490 f7cc9480 2020-02-05 tracey goto done;
2491 5c65becf 2020-02-13 tracey if (str1 != NULL) {
2492 5c65becf 2020-02-13 tracey kerr = khtml_puts(gw_trans->gw_html_req, str1);
2493 5c65becf 2020-02-13 tracey if (kerr != KCGI_OK)
2494 5c65becf 2020-02-13 tracey goto done;
2495 5c65becf 2020-02-13 tracey }
2496 f7cc9480 2020-02-05 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_BR, KATTR__MAX);
2497 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2498 f7cc9480 2020-02-05 tracey goto done;
2499 f7cc9480 2020-02-05 tracey kerr = khtml_puts(gw_trans->gw_html_req, str2);
2500 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2501 f7cc9480 2020-02-05 tracey goto done;
2502 f7cc9480 2020-02-05 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2503 f7cc9480 2020-02-05 tracey done:
2504 f7cc9480 2020-02-05 tracey if (error == NULL && kerr != KCGI_OK)
2505 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
2506 f7cc9480 2020-02-05 tracey return error;
2507 21a55cc7 2020-02-04 tracey }
2508 21a55cc7 2020-02-04 tracey
2509 21a55cc7 2020-02-04 tracey static const struct got_error *
2510 21a55cc7 2020-02-04 tracey gw_gen_age_header(struct gw_trans *gw_trans, const char *str)
2511 21a55cc7 2020-02-04 tracey {
2512 21a55cc7 2020-02-04 tracey const struct got_error *error = NULL;
2513 21a55cc7 2020-02-04 tracey enum kcgi_err kerr = KCGI_OK;
2514 21a55cc7 2020-02-04 tracey
2515 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2516 21a55cc7 2020-02-04 tracey KATTR_ID, "header_age_title", KATTR__MAX);
2517 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2518 21a55cc7 2020-02-04 tracey goto done;
2519 21a55cc7 2020-02-04 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Date: ");
2520 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2521 21a55cc7 2020-02-04 tracey goto done;
2522 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2523 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2524 21a55cc7 2020-02-04 tracey goto done;
2525 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2526 21a55cc7 2020-02-04 tracey KATTR_ID, "header_age", KATTR__MAX);
2527 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2528 21a55cc7 2020-02-04 tracey goto done;
2529 21a55cc7 2020-02-04 tracey kerr = khtml_puts(gw_trans->gw_html_req, str);
2530 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2531 21a55cc7 2020-02-04 tracey goto done;
2532 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2533 21a55cc7 2020-02-04 tracey done:
2534 21a55cc7 2020-02-04 tracey if (error == NULL && kerr != KCGI_OK)
2535 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
2536 21a55cc7 2020-02-04 tracey return error;
2537 21a55cc7 2020-02-04 tracey }
2538 21a55cc7 2020-02-04 tracey
2539 21a55cc7 2020-02-04 tracey static const struct got_error *
2540 21a55cc7 2020-02-04 tracey gw_gen_author_header(struct gw_trans *gw_trans, const char *str)
2541 21a55cc7 2020-02-04 tracey {
2542 21a55cc7 2020-02-04 tracey const struct got_error *error = NULL;
2543 795c10a4 2020-02-20 tracey enum kcgi_err kerr = KCGI_OK;
2544 21a55cc7 2020-02-04 tracey
2545 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2546 21a55cc7 2020-02-04 tracey KATTR_ID, "header_author_title", KATTR__MAX);
2547 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2548 21a55cc7 2020-02-04 tracey goto done;
2549 21a55cc7 2020-02-04 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Author: ");
2550 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2551 21a55cc7 2020-02-04 tracey goto done;
2552 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2553 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2554 21a55cc7 2020-02-04 tracey goto done;
2555 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2556 21a55cc7 2020-02-04 tracey KATTR_ID, "header_author", KATTR__MAX);
2557 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2558 21a55cc7 2020-02-04 tracey goto done;
2559 21a55cc7 2020-02-04 tracey kerr = khtml_puts(gw_trans->gw_html_req, str);
2560 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2561 21a55cc7 2020-02-04 tracey goto done;
2562 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2563 21a55cc7 2020-02-04 tracey done:
2564 21a55cc7 2020-02-04 tracey if (error == NULL && kerr != KCGI_OK)
2565 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
2566 21a55cc7 2020-02-04 tracey return error;
2567 f2f46662 2020-01-23 tracey }
2568 f2f46662 2020-01-23 tracey
2569 21a55cc7 2020-02-04 tracey static const struct got_error *
2570 21a55cc7 2020-02-04 tracey gw_gen_committer_header(struct gw_trans *gw_trans, const char *str)
2571 21a55cc7 2020-02-04 tracey {
2572 21a55cc7 2020-02-04 tracey const struct got_error *error = NULL;
2573 795c10a4 2020-02-20 tracey enum kcgi_err kerr = KCGI_OK;
2574 21a55cc7 2020-02-04 tracey
2575 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2576 21a55cc7 2020-02-04 tracey KATTR_ID, "header_committer_title", KATTR__MAX);
2577 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2578 21a55cc7 2020-02-04 tracey goto done;
2579 87ca24ac 2020-02-04 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Committer: ");
2580 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2581 21a55cc7 2020-02-04 tracey goto done;
2582 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2583 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2584 21a55cc7 2020-02-04 tracey goto done;
2585 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2586 21a55cc7 2020-02-04 tracey KATTR_ID, "header_committer", KATTR__MAX);
2587 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2588 21a55cc7 2020-02-04 tracey goto done;
2589 21a55cc7 2020-02-04 tracey kerr = khtml_puts(gw_trans->gw_html_req, str);
2590 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2591 21a55cc7 2020-02-04 tracey goto done;
2592 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2593 21a55cc7 2020-02-04 tracey done:
2594 21a55cc7 2020-02-04 tracey if (error == NULL && kerr != KCGI_OK)
2595 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
2596 21a55cc7 2020-02-04 tracey return error;
2597 21a55cc7 2020-02-04 tracey }
2598 21a55cc7 2020-02-04 tracey
2599 f7cc9480 2020-02-05 tracey static const struct got_error *
2600 f7cc9480 2020-02-05 tracey gw_gen_commit_msg_header(struct gw_trans *gw_trans, char *str)
2601 f2f46662 2020-01-23 tracey {
2602 27192be7 2020-02-04 tracey const struct got_error *error = NULL;
2603 795c10a4 2020-02-20 tracey enum kcgi_err kerr = KCGI_OK;
2604 f2f46662 2020-01-23 tracey
2605 f7cc9480 2020-02-05 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2606 f7cc9480 2020-02-05 tracey KATTR_ID, "header_commit_msg_title", KATTR__MAX);
2607 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2608 f7cc9480 2020-02-05 tracey goto done;
2609 f7cc9480 2020-02-05 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Message: ");
2610 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2611 f7cc9480 2020-02-05 tracey goto done;
2612 f7cc9480 2020-02-05 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2613 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2614 f7cc9480 2020-02-05 tracey goto done;
2615 f7cc9480 2020-02-05 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2616 f7cc9480 2020-02-05 tracey KATTR_ID, "header_commit_msg", KATTR__MAX);
2617 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2618 f7cc9480 2020-02-05 tracey goto done;
2619 f7cc9480 2020-02-05 tracey kerr = khttp_puts(gw_trans->gw_req, str);
2620 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2621 f7cc9480 2020-02-05 tracey goto done;
2622 f7cc9480 2020-02-05 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2623 f7cc9480 2020-02-05 tracey done:
2624 f7cc9480 2020-02-05 tracey if (error == NULL && kerr != KCGI_OK)
2625 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
2626 f7cc9480 2020-02-05 tracey return error;
2627 f2f46662 2020-01-23 tracey }
2628 f2f46662 2020-01-23 tracey
2629 f7cc9480 2020-02-05 tracey static const struct got_error *
2630 f7cc9480 2020-02-05 tracey gw_gen_tree_header(struct gw_trans *gw_trans, char *str)
2631 f2f46662 2020-01-23 tracey {
2632 f7cc9480 2020-02-05 tracey const struct got_error *error = NULL;
2633 795c10a4 2020-02-20 tracey enum kcgi_err kerr = KCGI_OK;
2634 f2f46662 2020-01-23 tracey
2635 f7cc9480 2020-02-05 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2636 f7cc9480 2020-02-05 tracey KATTR_ID, "header_tree_title", KATTR__MAX);
2637 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2638 f7cc9480 2020-02-05 tracey goto done;
2639 f7cc9480 2020-02-05 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Tree: ");
2640 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2641 f7cc9480 2020-02-05 tracey goto done;
2642 f7cc9480 2020-02-05 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2643 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2644 f7cc9480 2020-02-05 tracey goto done;
2645 f7cc9480 2020-02-05 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2646 f7cc9480 2020-02-05 tracey KATTR_ID, "header_tree", KATTR__MAX);
2647 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2648 f7cc9480 2020-02-05 tracey goto done;
2649 f7cc9480 2020-02-05 tracey kerr = khtml_puts(gw_trans->gw_html_req, str);
2650 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2651 f7cc9480 2020-02-05 tracey goto done;
2652 f7cc9480 2020-02-05 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2653 f7cc9480 2020-02-05 tracey done:
2654 f7cc9480 2020-02-05 tracey if (error == NULL && kerr != KCGI_OK)
2655 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
2656 f7cc9480 2020-02-05 tracey return error;
2657 f2f46662 2020-01-23 tracey }
2658 f2f46662 2020-01-23 tracey
2659 32cd4d18 2020-02-03 stsp static const struct got_error *
2660 32cd4d18 2020-02-03 stsp gw_get_repo_description(char **description, struct gw_trans *gw_trans,
2661 32cd4d18 2020-02-03 stsp char *dir)
2662 2c251c14 2020-01-15 tracey {
2663 32cd4d18 2020-02-03 stsp const struct got_error *error = NULL;
2664 b8b04565 2020-02-02 tracey FILE *f = NULL;
2665 32cd4d18 2020-02-03 stsp char *d_file = NULL;
2666 2c251c14 2020-01-15 tracey unsigned int len;
2667 1ab830c1 2020-02-03 stsp size_t n;
2668 2c251c14 2020-01-15 tracey
2669 32cd4d18 2020-02-03 stsp *description = NULL;
2670 0b20762b 2020-01-29 stsp if (gw_trans->gw_conf->got_show_repo_description == 0)
2671 a942aa37 2020-02-10 tracey return NULL;
2672 2c251c14 2020-01-15 tracey
2673 88d59c36 2020-01-29 stsp if (asprintf(&d_file, "%s/description", dir) == -1)
2674 32cd4d18 2020-02-03 stsp return got_error_from_errno("asprintf");
2675 2c251c14 2020-01-15 tracey
2676 c56c5d8a 2021-12-31 thomas f = fopen(d_file, "re");
2677 32cd4d18 2020-02-03 stsp if (f == NULL) {
2678 32cd4d18 2020-02-03 stsp if (errno == ENOENT || errno == EACCES)
2679 a942aa37 2020-02-10 tracey return NULL;
2680 32cd4d18 2020-02-03 stsp error = got_error_from_errno2("fopen", d_file);
2681 32cd4d18 2020-02-03 stsp goto done;
2682 32cd4d18 2020-02-03 stsp }
2683 2c251c14 2020-01-15 tracey
2684 32cd4d18 2020-02-03 stsp if (fseek(f, 0, SEEK_END) == -1) {
2685 32cd4d18 2020-02-03 stsp error = got_ferror(f, GOT_ERR_IO);
2686 32cd4d18 2020-02-03 stsp goto done;
2687 32cd4d18 2020-02-03 stsp }
2688 32cd4d18 2020-02-03 stsp len = ftell(f);
2689 32cd4d18 2020-02-03 stsp if (len == -1) {
2690 32cd4d18 2020-02-03 stsp error = got_ferror(f, GOT_ERR_IO);
2691 32cd4d18 2020-02-03 stsp goto done;
2692 32cd4d18 2020-02-03 stsp }
2693 32cd4d18 2020-02-03 stsp if (fseek(f, 0, SEEK_SET) == -1) {
2694 32cd4d18 2020-02-03 stsp error = got_ferror(f, GOT_ERR_IO);
2695 32cd4d18 2020-02-03 stsp goto done;
2696 32cd4d18 2020-02-03 stsp }
2697 32cd4d18 2020-02-03 stsp *description = calloc(len + 1, sizeof(**description));
2698 32cd4d18 2020-02-03 stsp if (*description == NULL) {
2699 32cd4d18 2020-02-03 stsp error = got_error_from_errno("calloc");
2700 32cd4d18 2020-02-03 stsp goto done;
2701 32cd4d18 2020-02-03 stsp }
2702 32cd4d18 2020-02-03 stsp
2703 32cd4d18 2020-02-03 stsp n = fread(*description, 1, len, f);
2704 1ab830c1 2020-02-03 stsp if (n == 0 && ferror(f))
2705 32cd4d18 2020-02-03 stsp error = got_ferror(f, GOT_ERR_IO);
2706 32cd4d18 2020-02-03 stsp done:
2707 56b63ca4 2021-01-22 stsp if (f != NULL && fclose(f) == EOF && error == NULL)
2708 32cd4d18 2020-02-03 stsp error = got_error_from_errno("fclose");
2709 2c251c14 2020-01-15 tracey free(d_file);
2710 32cd4d18 2020-02-03 stsp return error;
2711 2c251c14 2020-01-15 tracey }
2712 2c251c14 2020-01-15 tracey
2713 55ccf528 2020-02-03 stsp static const struct got_error *
2714 55ccf528 2020-02-03 stsp gw_get_time_str(char **repo_age, time_t committer_time, int ref_tm)
2715 474370cb 2020-01-15 tracey {
2716 474370cb 2020-01-15 tracey struct tm tm;
2717 474370cb 2020-01-15 tracey time_t diff_time;
2718 0c6f49ba 2022-07-01 thomas const char *years = "years ago", *months = "months ago";
2719 0c6f49ba 2022-07-01 thomas const char *weeks = "weeks ago", *days = "days ago", *hours = "hours ago";
2720 0c6f49ba 2022-07-01 thomas const char *minutes = "minutes ago", *seconds = "seconds ago";
2721 0c6f49ba 2022-07-01 thomas const char *now = "right now";
2722 0c6f49ba 2022-07-01 thomas const char *s;
2723 6c6c85af 2020-01-15 tracey char datebuf[29];
2724 474370cb 2020-01-15 tracey
2725 55ccf528 2020-02-03 stsp *repo_age = NULL;
2726 55ccf528 2020-02-03 stsp
2727 474370cb 2020-01-15 tracey switch (ref_tm) {
2728 474370cb 2020-01-15 tracey case TM_DIFF:
2729 474370cb 2020-01-15 tracey diff_time = time(NULL) - committer_time;
2730 474370cb 2020-01-15 tracey if (diff_time > 60 * 60 * 24 * 365 * 2) {
2731 55ccf528 2020-02-03 stsp if (asprintf(repo_age, "%lld %s",
2732 88d59c36 2020-01-29 stsp (diff_time / 60 / 60 / 24 / 365), years) == -1)
2733 55ccf528 2020-02-03 stsp return got_error_from_errno("asprintf");
2734 474370cb 2020-01-15 tracey } else if (diff_time > 60 * 60 * 24 * (365 / 12) * 2) {
2735 55ccf528 2020-02-03 stsp if (asprintf(repo_age, "%lld %s",
2736 474370cb 2020-01-15 tracey (diff_time / 60 / 60 / 24 / (365 / 12)),
2737 88d59c36 2020-01-29 stsp months) == -1)
2738 55ccf528 2020-02-03 stsp return got_error_from_errno("asprintf");
2739 474370cb 2020-01-15 tracey } else if (diff_time > 60 * 60 * 24 * 7 * 2) {
2740 55ccf528 2020-02-03 stsp if (asprintf(repo_age, "%lld %s",
2741 88d59c36 2020-01-29 stsp (diff_time / 60 / 60 / 24 / 7), weeks) == -1)
2742 55ccf528 2020-02-03 stsp return got_error_from_errno("asprintf");
2743 474370cb 2020-01-15 tracey } else if (diff_time > 60 * 60 * 24 * 2) {
2744 55ccf528 2020-02-03 stsp if (asprintf(repo_age, "%lld %s",
2745 88d59c36 2020-01-29 stsp (diff_time / 60 / 60 / 24), days) == -1)
2746 55ccf528 2020-02-03 stsp return got_error_from_errno("asprintf");
2747 474370cb 2020-01-15 tracey } else if (diff_time > 60 * 60 * 2) {
2748 55ccf528 2020-02-03 stsp if (asprintf(repo_age, "%lld %s",
2749 88d59c36 2020-01-29 stsp (diff_time / 60 / 60), hours) == -1)
2750 55ccf528 2020-02-03 stsp return got_error_from_errno("asprintf");
2751 474370cb 2020-01-15 tracey } else if (diff_time > 60 * 2) {
2752 55ccf528 2020-02-03 stsp if (asprintf(repo_age, "%lld %s", (diff_time / 60),
2753 88d59c36 2020-01-29 stsp minutes) == -1)
2754 55ccf528 2020-02-03 stsp return got_error_from_errno("asprintf");
2755 474370cb 2020-01-15 tracey } else if (diff_time > 2) {
2756 55ccf528 2020-02-03 stsp if (asprintf(repo_age, "%lld %s", diff_time,
2757 88d59c36 2020-01-29 stsp seconds) == -1)
2758 55ccf528 2020-02-03 stsp return got_error_from_errno("asprintf");
2759 474370cb 2020-01-15 tracey } else {
2760 55ccf528 2020-02-03 stsp if (asprintf(repo_age, "%s", now) == -1)
2761 55ccf528 2020-02-03 stsp return got_error_from_errno("asprintf");
2762 474370cb 2020-01-15 tracey }
2763 474370cb 2020-01-15 tracey break;
2764 474370cb 2020-01-15 tracey case TM_LONG:
2765 474370cb 2020-01-15 tracey if (gmtime_r(&committer_time, &tm) == NULL)
2766 55ccf528 2020-02-03 stsp return got_error_from_errno("gmtime_r");
2767 474370cb 2020-01-15 tracey
2768 474370cb 2020-01-15 tracey s = asctime_r(&tm, datebuf);
2769 474370cb 2020-01-15 tracey if (s == NULL)
2770 55ccf528 2020-02-03 stsp return got_error_from_errno("asctime_r");
2771 474370cb 2020-01-15 tracey
2772 55ccf528 2020-02-03 stsp if (asprintf(repo_age, "%s UTC", datebuf) == -1)
2773 55ccf528 2020-02-03 stsp return got_error_from_errno("asprintf");
2774 474370cb 2020-01-15 tracey break;
2775 474370cb 2020-01-15 tracey }
2776 55ccf528 2020-02-03 stsp return NULL;
2777 474370cb 2020-01-15 tracey }
2778 474370cb 2020-01-15 tracey
2779 d126c1b7 2020-01-29 stsp static const struct got_error *
2780 d126c1b7 2020-01-29 stsp gw_get_repo_age(char **repo_age, struct gw_trans *gw_trans, char *dir,
2781 2011c142 2020-02-14 stsp const char *refname, int ref_tm)
2782 2c251c14 2020-01-15 tracey {
2783 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
2784 2c251c14 2020-01-15 tracey struct got_repository *repo = NULL;
2785 2c251c14 2020-01-15 tracey struct got_commit_object *commit = NULL;
2786 2c251c14 2020-01-15 tracey struct got_reflist_head refs;
2787 2c251c14 2020-01-15 tracey struct got_reflist_entry *re;
2788 474370cb 2020-01-15 tracey time_t committer_time = 0, cmp_time = 0;
2789 a0f36e03 2020-01-28 stsp
2790 d126c1b7 2020-01-29 stsp *repo_age = NULL;
2791 d9dff0e5 2020-12-26 stsp TAILQ_INIT(&refs);
2792 387a29ba 2020-01-15 tracey
2793 55ccf528 2020-02-03 stsp if (gw_trans->gw_conf->got_show_repo_age == 0)
2794 d126c1b7 2020-01-29 stsp return NULL;
2795 87f9ebf5 2020-01-15 tracey
2796 deac617c 2020-02-14 tracey if (gw_trans->repo)
2797 deac617c 2020-02-14 tracey repo = gw_trans->repo;
2798 deac617c 2020-02-14 tracey else {
2799 e0fb2ce2 2022-06-23 thomas error = got_repo_open(&repo, dir, NULL, gw_trans->pack_fds);
2800 deac617c 2020-02-14 tracey if (error)
2801 deac617c 2020-02-14 tracey return error;
2802 deac617c 2020-02-14 tracey }
2803 2c251c14 2020-01-15 tracey
2804 2011c142 2020-02-14 stsp error = got_ref_list(&refs, repo, "refs/heads",
2805 2011c142 2020-02-14 stsp got_ref_cmp_by_name, NULL);
2806 ec46ccd7 2020-01-15 tracey if (error)
2807 d126c1b7 2020-01-29 stsp goto done;
2808 2c251c14 2020-01-15 tracey
2809 2011c142 2020-02-14 stsp /*
2810 2011c142 2020-02-14 stsp * Find the youngest branch tip in the repository, or the age of
2811 2011c142 2020-02-14 stsp * the a specific branch tip if a name was provided by the caller.
2812 2011c142 2020-02-14 stsp */
2813 d9dff0e5 2020-12-26 stsp TAILQ_FOREACH(re, &refs, entry) {
2814 2011c142 2020-02-14 stsp struct got_object_id *id = NULL;
2815 17d4bf8d 2020-02-14 stsp
2816 2011c142 2020-02-14 stsp if (refname && strcmp(got_ref_get_name(re->ref), refname) != 0)
2817 2011c142 2020-02-14 stsp continue;
2818 4e8d6e3e 2020-02-14 tracey
2819 2011c142 2020-02-14 stsp error = got_ref_resolve(&id, repo, re->ref);
2820 ec46ccd7 2020-01-15 tracey if (error)
2821 d126c1b7 2020-01-29 stsp goto done;
2822 2c251c14 2020-01-15 tracey
2823 2c251c14 2020-01-15 tracey error = got_object_open_as_commit(&commit, repo, id);
2824 2011c142 2020-02-14 stsp free(id);
2825 ec46ccd7 2020-01-15 tracey if (error)
2826 d126c1b7 2020-01-29 stsp goto done;
2827 2c251c14 2020-01-15 tracey
2828 2c251c14 2020-01-15 tracey committer_time =
2829 2c251c14 2020-01-15 tracey got_object_commit_get_committer_time(commit);
2830 2011c142 2020-02-14 stsp got_object_commit_close(commit);
2831 387a29ba 2020-01-15 tracey if (cmp_time < committer_time)
2832 2c251c14 2020-01-15 tracey cmp_time = committer_time;
2833 2011c142 2020-02-14 stsp
2834 2011c142 2020-02-14 stsp if (refname)
2835 2011c142 2020-02-14 stsp break;
2836 2c251c14 2020-01-15 tracey }
2837 2c251c14 2020-01-15 tracey
2838 474370cb 2020-01-15 tracey if (cmp_time != 0) {
2839 2c251c14 2020-01-15 tracey committer_time = cmp_time;
2840 55ccf528 2020-02-03 stsp error = gw_get_time_str(repo_age, committer_time, ref_tm);
2841 d126c1b7 2020-01-29 stsp }
2842 d126c1b7 2020-01-29 stsp done:
2843 2c251c14 2020-01-15 tracey got_ref_list_free(&refs);
2844 1d0f4054 2021-06-17 stsp if (gw_trans->repo == NULL) {
2845 1d0f4054 2021-06-17 stsp const struct got_error *close_err = got_repo_close(repo);
2846 1d0f4054 2021-06-17 stsp if (error == NULL)
2847 1d0f4054 2021-06-17 stsp error = close_err;
2848 7cd52833 2022-06-23 thomas }
2849 d126c1b7 2020-01-29 stsp return error;
2850 ec46ccd7 2020-01-15 tracey }
2851 ec46ccd7 2020-01-15 tracey
2852 83eb9a68 2020-02-03 stsp static const struct got_error *
2853 38b240fb 2020-02-06 tracey gw_output_diff(struct gw_trans *gw_trans, struct gw_header *header)
2854 ec46ccd7 2020-01-15 tracey {
2855 ec46ccd7 2020-01-15 tracey const struct got_error *error;
2856 a0f32f33 2022-06-13 thomas FILE *f = NULL, *f1 = NULL, *f2 = NULL;
2857 19a6a6b5 2022-07-01 thomas int fd1 = -1, fd2 = -1;
2858 ec46ccd7 2020-01-15 tracey struct got_object_id *id1 = NULL, *id2 = NULL;
2859 f7cc9480 2020-02-05 tracey char *label1 = NULL, *label2 = NULL, *line = NULL;
2860 05ce9a79 2020-01-24 tracey int obj_type;
2861 f7cc9480 2020-02-05 tracey size_t linesize = 0;
2862 83eb9a68 2020-02-03 stsp ssize_t linelen;
2863 f7cc9480 2020-02-05 tracey enum kcgi_err kerr = KCGI_OK;
2864 ec46ccd7 2020-01-15 tracey
2865 ec46ccd7 2020-01-15 tracey f = got_opentemp();
2866 ec46ccd7 2020-01-15 tracey if (f == NULL)
2867 ec46ccd7 2020-01-15 tracey return NULL;
2868 ec46ccd7 2020-01-15 tracey
2869 a0f32f33 2022-06-13 thomas f1 = got_opentemp();
2870 a0f32f33 2022-06-13 thomas if (f1 == NULL) {
2871 a0f32f33 2022-06-13 thomas error = got_error_from_errno("got_opentemp");
2872 a0f32f33 2022-06-13 thomas goto done;
2873 a0f32f33 2022-06-13 thomas }
2874 a0f32f33 2022-06-13 thomas
2875 a0f32f33 2022-06-13 thomas f2 = got_opentemp();
2876 a0f32f33 2022-06-13 thomas if (f2 == NULL) {
2877 a0f32f33 2022-06-13 thomas error = got_error_from_errno("got_opentemp");
2878 a0f32f33 2022-06-13 thomas goto done;
2879 a0f32f33 2022-06-13 thomas }
2880 a0f32f33 2022-06-13 thomas
2881 19a6a6b5 2022-07-01 thomas fd1 = got_opentempfd();
2882 19a6a6b5 2022-07-01 thomas if (fd1 == -1) {
2883 19a6a6b5 2022-07-01 thomas error = got_error_from_errno("got_opentempfd");
2884 19a6a6b5 2022-07-01 thomas goto done;
2885 19a6a6b5 2022-07-01 thomas }
2886 19a6a6b5 2022-07-01 thomas
2887 19a6a6b5 2022-07-01 thomas fd2 = got_opentempfd();
2888 19a6a6b5 2022-07-01 thomas if (fd2 == -1) {
2889 19a6a6b5 2022-07-01 thomas error = got_error_from_errno("got_opentempfd");
2890 19a6a6b5 2022-07-01 thomas goto done;
2891 19a6a6b5 2022-07-01 thomas }
2892 19a6a6b5 2022-07-01 thomas
2893 5c65becf 2020-02-13 tracey if (header->parent_id != NULL &&
2894 5c65becf 2020-02-13 tracey strncmp(header->parent_id, "/dev/null", 9) != 0) {
2895 05ce9a79 2020-01-24 tracey error = got_repo_match_object_id(&id1, &label1,
2896 84de9106 2020-12-26 stsp header->parent_id, GOT_OBJ_TYPE_ANY,
2897 84de9106 2020-12-26 stsp &header->refs, gw_trans->repo);
2898 05ce9a79 2020-01-24 tracey if (error)
2899 05ce9a79 2020-01-24 tracey goto done;
2900 05ce9a79 2020-01-24 tracey }
2901 ec46ccd7 2020-01-15 tracey
2902 90f16cb8 2020-01-24 tracey error = got_repo_match_object_id(&id2, &label2,
2903 84de9106 2020-12-26 stsp header->commit_id, GOT_OBJ_TYPE_ANY, &header->refs,
2904 84de9106 2020-12-26 stsp gw_trans->repo);
2905 90f16cb8 2020-01-24 tracey if (error)
2906 90f16cb8 2020-01-24 tracey goto done;
2907 ec46ccd7 2020-01-15 tracey
2908 deac617c 2020-02-14 tracey error = got_object_get_type(&obj_type, gw_trans->repo, id2);
2909 90f16cb8 2020-01-24 tracey if (error)
2910 90f16cb8 2020-01-24 tracey goto done;
2911 05ce9a79 2020-01-24 tracey switch (obj_type) {
2912 ec46ccd7 2020-01-15 tracey case GOT_OBJ_TYPE_BLOB:
2913 a0f32f33 2022-06-13 thomas error = got_diff_objects_as_blobs(NULL, NULL, f1, f2,
2914 19a6a6b5 2022-07-01 thomas fd1, fd2, id1, id2, NULL, NULL, 3, 0, 0,
2915 19a6a6b5 2022-07-01 thomas gw_trans->repo, f);
2916 ec46ccd7 2020-01-15 tracey break;
2917 ec46ccd7 2020-01-15 tracey case GOT_OBJ_TYPE_TREE:
2918 a0f32f33 2022-06-13 thomas error = got_diff_objects_as_trees(NULL, NULL, f1, f2,
2919 19a6a6b5 2022-07-01 thomas fd1, fd2, id1, id2, NULL, "", "", 3, 0, 0,
2920 19a6a6b5 2022-07-01 thomas gw_trans->repo, f);
2921 ec46ccd7 2020-01-15 tracey break;
2922 ec46ccd7 2020-01-15 tracey case GOT_OBJ_TYPE_COMMIT:
2923 a0f32f33 2022-06-13 thomas error = got_diff_objects_as_commits(NULL, NULL, f1, f2,
2924 19a6a6b5 2022-07-01 thomas fd1, fd2, id1, id2, NULL, 3, 0, 0, gw_trans->repo, f);
2925 ec46ccd7 2020-01-15 tracey break;
2926 ec46ccd7 2020-01-15 tracey default:
2927 ec46ccd7 2020-01-15 tracey error = got_error(GOT_ERR_OBJ_TYPE);
2928 ec46ccd7 2020-01-15 tracey }
2929 b8b04565 2020-02-02 tracey if (error)
2930 b8b04565 2020-02-02 tracey goto done;
2931 b8b04565 2020-02-02 tracey
2932 d4729381 2020-02-03 stsp if (fseek(f, 0, SEEK_SET) == -1) {
2933 d4729381 2020-02-03 stsp error = got_ferror(f, GOT_ERR_IO);
2934 ec46ccd7 2020-01-15 tracey goto done;
2935 d4729381 2020-02-03 stsp }
2936 ec46ccd7 2020-01-15 tracey
2937 83eb9a68 2020-02-03 stsp while ((linelen = getline(&line, &linesize, f)) != -1) {
2938 f7cc9480 2020-02-05 tracey error = gw_colordiff_line(gw_trans, line);
2939 ec46ccd7 2020-01-15 tracey if (error)
2940 b8b04565 2020-02-02 tracey goto done;
2941 f7cc9480 2020-02-05 tracey /* XXX: KHTML_PRETTY breaks this */
2942 f7cc9480 2020-02-05 tracey kerr = khtml_puts(gw_trans->gw_html_req, line);
2943 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2944 83eb9a68 2020-02-03 stsp goto done;
2945 f7cc9480 2020-02-05 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2946 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2947 b8b04565 2020-02-02 tracey goto done;
2948 ec46ccd7 2020-01-15 tracey }
2949 f7cc9480 2020-02-05 tracey if (linelen == -1 && ferror(f))
2950 83eb9a68 2020-02-03 stsp error = got_error_from_errno("getline");
2951 ec46ccd7 2020-01-15 tracey done:
2952 56b63ca4 2021-01-22 stsp if (f && fclose(f) == EOF && error == NULL)
2953 a0f32f33 2022-06-13 thomas error = got_error_from_errno("fclose");
2954 a0f32f33 2022-06-13 thomas if (f1 && fclose(f1) == EOF && error == NULL)
2955 a0f32f33 2022-06-13 thomas error = got_error_from_errno("fclose");
2956 a0f32f33 2022-06-13 thomas if (f2 && fclose(f2) == EOF && error == NULL)
2957 d4729381 2020-02-03 stsp error = got_error_from_errno("fclose");
2958 19a6a6b5 2022-07-01 thomas if (fd1 != -1 && close(fd1) == -1 && error == NULL)
2959 19a6a6b5 2022-07-01 thomas error = got_error_from_errno("close");
2960 19a6a6b5 2022-07-01 thomas if (fd2 != -1 && close(fd2) == -1 && error == NULL)
2961 19a6a6b5 2022-07-01 thomas error = got_error_from_errno("close");
2962 d4729381 2020-02-03 stsp free(line);
2963 ec46ccd7 2020-01-15 tracey free(label1);
2964 ec46ccd7 2020-01-15 tracey free(label2);
2965 ec46ccd7 2020-01-15 tracey free(id1);
2966 ec46ccd7 2020-01-15 tracey free(id2);
2967 ec46ccd7 2020-01-15 tracey
2968 f7cc9480 2020-02-05 tracey if (error == NULL && kerr != KCGI_OK)
2969 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
2970 83eb9a68 2020-02-03 stsp return error;
2971 2c251c14 2020-01-15 tracey }
2972 2c251c14 2020-01-15 tracey
2973 9a1cc63f 2020-02-03 stsp static const struct got_error *
2974 9a1cc63f 2020-02-03 stsp gw_get_repo_owner(char **owner, struct gw_trans *gw_trans, char *dir)
2975 9a1cc63f 2020-02-03 stsp {
2976 1d0f4054 2021-06-17 stsp const struct got_error *error = NULL, *close_err;
2977 9a1cc63f 2020-02-03 stsp struct got_repository *repo;
2978 9a1cc63f 2020-02-03 stsp const char *gitconfig_owner;
2979 2c251c14 2020-01-15 tracey
2980 9a1cc63f 2020-02-03 stsp *owner = NULL;
2981 2c251c14 2020-01-15 tracey
2982 9a1cc63f 2020-02-03 stsp if (gw_trans->gw_conf->got_show_repo_owner == 0)
2983 9a1cc63f 2020-02-03 stsp return NULL;
2984 2c251c14 2020-01-15 tracey
2985 e0fb2ce2 2022-06-23 thomas error = got_repo_open(&repo, dir, NULL, gw_trans->pack_fds);
2986 9a1cc63f 2020-02-03 stsp if (error)
2987 9a1cc63f 2020-02-03 stsp return error;
2988 7cd52833 2022-06-23 thomas
2989 9a1cc63f 2020-02-03 stsp gitconfig_owner = got_repo_get_gitconfig_owner(repo);
2990 d1635ae4 2020-02-13 tracey if (gitconfig_owner) {
2991 d1635ae4 2020-02-13 tracey *owner = strdup(gitconfig_owner);
2992 d1635ae4 2020-02-13 tracey if (*owner == NULL)
2993 d1635ae4 2020-02-13 tracey error = got_error_from_errno("strdup");
2994 d1635ae4 2020-02-13 tracey }
2995 1d0f4054 2021-06-17 stsp close_err = got_repo_close(repo);
2996 1d0f4054 2021-06-17 stsp if (error == NULL)
2997 1d0f4054 2021-06-17 stsp error = close_err;
2998 9a1cc63f 2020-02-03 stsp return error;
2999 2c251c14 2020-01-15 tracey }
3000 2c251c14 2020-01-15 tracey
3001 59d3c40e 2020-02-03 stsp static const struct got_error *
3002 59d3c40e 2020-02-03 stsp gw_get_clone_url(char **url, struct gw_trans *gw_trans, char *dir)
3003 2c251c14 2020-01-15 tracey {
3004 59d3c40e 2020-02-03 stsp const struct got_error *error = NULL;
3005 2c251c14 2020-01-15 tracey FILE *f;
3006 59d3c40e 2020-02-03 stsp char *d_file = NULL;
3007 2c251c14 2020-01-15 tracey unsigned int len;
3008 59d3c40e 2020-02-03 stsp size_t n;
3009 2c251c14 2020-01-15 tracey
3010 59d3c40e 2020-02-03 stsp *url = NULL;
3011 2c251c14 2020-01-15 tracey
3012 59d3c40e 2020-02-03 stsp if (asprintf(&d_file, "%s/cloneurl", dir) == -1)
3013 59d3c40e 2020-02-03 stsp return got_error_from_errno("asprintf");
3014 2c251c14 2020-01-15 tracey
3015 c56c5d8a 2021-12-31 thomas f = fopen(d_file, "re");
3016 59d3c40e 2020-02-03 stsp if (f == NULL) {
3017 59d3c40e 2020-02-03 stsp if (errno != ENOENT && errno != EACCES)
3018 59d3c40e 2020-02-03 stsp error = got_error_from_errno2("fopen", d_file);
3019 59d3c40e 2020-02-03 stsp goto done;
3020 59d3c40e 2020-02-03 stsp }
3021 59d3c40e 2020-02-03 stsp
3022 59d3c40e 2020-02-03 stsp if (fseek(f, 0, SEEK_END) == -1) {
3023 59d3c40e 2020-02-03 stsp error = got_ferror(f, GOT_ERR_IO);
3024 59d3c40e 2020-02-03 stsp goto done;
3025 59d3c40e 2020-02-03 stsp }
3026 59d3c40e 2020-02-03 stsp len = ftell(f);
3027 59d3c40e 2020-02-03 stsp if (len == -1) {
3028 59d3c40e 2020-02-03 stsp error = got_ferror(f, GOT_ERR_IO);
3029 59d3c40e 2020-02-03 stsp goto done;
3030 59d3c40e 2020-02-03 stsp }
3031 59d3c40e 2020-02-03 stsp if (fseek(f, 0, SEEK_SET) == -1) {
3032 59d3c40e 2020-02-03 stsp error = got_ferror(f, GOT_ERR_IO);
3033 59d3c40e 2020-02-03 stsp goto done;
3034 59d3c40e 2020-02-03 stsp }
3035 2c251c14 2020-01-15 tracey
3036 59d3c40e 2020-02-03 stsp *url = calloc(len + 1, sizeof(**url));
3037 59d3c40e 2020-02-03 stsp if (*url == NULL) {
3038 59d3c40e 2020-02-03 stsp error = got_error_from_errno("calloc");
3039 59d3c40e 2020-02-03 stsp goto done;
3040 59d3c40e 2020-02-03 stsp }
3041 2c251c14 2020-01-15 tracey
3042 59d3c40e 2020-02-03 stsp n = fread(*url, 1, len, f);
3043 59d3c40e 2020-02-03 stsp if (n == 0 && ferror(f))
3044 59d3c40e 2020-02-03 stsp error = got_ferror(f, GOT_ERR_IO);
3045 59d3c40e 2020-02-03 stsp done:
3046 56b63ca4 2021-01-22 stsp if (f && fclose(f) == EOF && error == NULL)
3047 59d3c40e 2020-02-03 stsp error = got_error_from_errno("fclose");
3048 2c251c14 2020-01-15 tracey free(d_file);
3049 59d3c40e 2020-02-03 stsp return NULL;
3050 8d4d2453 2020-01-15 tracey }
3051 8d4d2453 2020-01-15 tracey
3052 6eccd105 2020-02-03 stsp static const struct got_error *
3053 38b240fb 2020-02-06 tracey gw_output_repo_tags(struct gw_trans *gw_trans, struct gw_header *header,
3054 38b240fb 2020-02-06 tracey int limit, int tag_type)
3055 8d4d2453 2020-01-15 tracey {
3056 87f9ebf5 2020-01-15 tracey const struct got_error *error = NULL;
3057 87f9ebf5 2020-01-15 tracey struct got_reflist_head refs;
3058 87f9ebf5 2020-01-15 tracey struct got_reflist_entry *re;
3059 38b240fb 2020-02-06 tracey char *age = NULL;
3060 ef2c200c 2020-02-07 tracey char *id_str = NULL, *newline, *href_commits = NULL;
3061 38b240fb 2020-02-06 tracey char *tag_commit0 = NULL, *href_tag = NULL, *href_briefs = NULL;
3062 6eccd105 2020-02-03 stsp struct got_tag_object *tag = NULL;
3063 38b240fb 2020-02-06 tracey enum kcgi_err kerr = KCGI_OK;
3064 5a911940 2021-06-25 tracey int summary_header_displayed = 0, chk_next = 0;
3065 5a911940 2021-06-25 tracey int tag_count = 0, commit_found = 0, c_cnt = 0;
3066 8d4d2453 2020-01-15 tracey
3067 d9dff0e5 2020-12-26 stsp TAILQ_INIT(&refs);
3068 a0f36e03 2020-01-28 stsp
3069 deac617c 2020-02-14 tracey error = got_ref_list(&refs, gw_trans->repo, "refs/tags",
3070 deac617c 2020-02-14 tracey got_ref_cmp_tags, gw_trans->repo);
3071 ec46ccd7 2020-01-15 tracey if (error)
3072 87f9ebf5 2020-01-15 tracey goto done;
3073 87f9ebf5 2020-01-15 tracey
3074 d9dff0e5 2020-12-26 stsp TAILQ_FOREACH(re, &refs, entry) {
3075 87f9ebf5 2020-01-15 tracey const char *refname;
3076 4ff7391f 2020-01-28 tracey const char *tagger;
3077 6eccd105 2020-02-03 stsp const char *tag_commit;
3078 87f9ebf5 2020-01-15 tracey time_t tagger_time;
3079 87f9ebf5 2020-01-15 tracey struct got_object_id *id;
3080 ef2c200c 2020-02-07 tracey struct got_commit_object *commit = NULL;
3081 87f9ebf5 2020-01-15 tracey
3082 87f9ebf5 2020-01-15 tracey refname = got_ref_get_name(re->ref);
3083 87f9ebf5 2020-01-15 tracey if (strncmp(refname, "refs/tags/", 10) != 0)
3084 87f9ebf5 2020-01-15 tracey continue;
3085 87f9ebf5 2020-01-15 tracey refname += 10;
3086 87f9ebf5 2020-01-15 tracey
3087 deac617c 2020-02-14 tracey error = got_ref_resolve(&id, gw_trans->repo, re->ref);
3088 87f9ebf5 2020-01-15 tracey if (error)
3089 87f9ebf5 2020-01-15 tracey goto done;
3090 38b240fb 2020-02-06 tracey
3091 deac617c 2020-02-14 tracey error = got_object_open_as_tag(&tag, gw_trans->repo, id);
3092 38b240fb 2020-02-06 tracey if (error) {
3093 ef2c200c 2020-02-07 tracey if (error->code != GOT_ERR_OBJ_TYPE) {
3094 ef2c200c 2020-02-07 tracey free(id);
3095 ef2c200c 2020-02-07 tracey goto done;
3096 ef2c200c 2020-02-07 tracey }
3097 ef2c200c 2020-02-07 tracey /* "lightweight" tag */
3098 deac617c 2020-02-14 tracey error = got_object_open_as_commit(&commit,
3099 deac617c 2020-02-14 tracey gw_trans->repo, id);
3100 ef2c200c 2020-02-07 tracey if (error) {
3101 ef2c200c 2020-02-07 tracey free(id);
3102 ef2c200c 2020-02-07 tracey goto done;
3103 ef2c200c 2020-02-07 tracey }
3104 ef2c200c 2020-02-07 tracey tagger = got_object_commit_get_committer(commit);
3105 ef2c200c 2020-02-07 tracey tagger_time =
3106 ef2c200c 2020-02-07 tracey got_object_commit_get_committer_time(commit);
3107 ef2c200c 2020-02-07 tracey error = got_object_id_str(&id_str, id);
3108 ef2c200c 2020-02-07 tracey free(id);
3109 ef2c200c 2020-02-07 tracey } else {
3110 ef2c200c 2020-02-07 tracey free(id);
3111 ef2c200c 2020-02-07 tracey tagger = got_object_tag_get_tagger(tag);
3112 ef2c200c 2020-02-07 tracey tagger_time = got_object_tag_get_tagger_time(tag);
3113 ef2c200c 2020-02-07 tracey error = got_object_id_str(&id_str,
3114 ef2c200c 2020-02-07 tracey got_object_tag_get_object_id(tag));
3115 38b240fb 2020-02-06 tracey }
3116 87f9ebf5 2020-01-15 tracey if (error)
3117 87f9ebf5 2020-01-15 tracey goto done;
3118 87f9ebf5 2020-01-15 tracey
3119 38b240fb 2020-02-06 tracey if (tag_type == TAGFULL && strncmp(id_str, header->commit_id,
3120 38b240fb 2020-02-06 tracey strlen(id_str)) != 0)
3121 38b240fb 2020-02-06 tracey continue;
3122 38b240fb 2020-02-06 tracey
3123 ff4bb25f 2020-02-19 tracey if (tag_type == TAGBRIEF && gw_trans->commit_id &&
3124 5a911940 2021-06-25 tracey commit_found == 0 && strncmp(id_str, gw_trans->commit_id,
3125 5a911940 2021-06-25 tracey strlen(id_str)) != 0)
3126 ff4bb25f 2020-02-19 tracey continue;
3127 5a911940 2021-06-25 tracey else
3128 5a911940 2021-06-25 tracey commit_found = 1;
3129 ff4bb25f 2020-02-19 tracey
3130 ff4bb25f 2020-02-19 tracey tag_count++;
3131 ff4bb25f 2020-02-19 tracey
3132 ff4bb25f 2020-02-19 tracey if (chk_next) {
3133 ff4bb25f 2020-02-19 tracey gw_trans->next_id = strdup(id_str);
3134 ff4bb25f 2020-02-19 tracey if (gw_trans->next_id == NULL)
3135 ff4bb25f 2020-02-19 tracey error = got_error_from_errno("strdup");
3136 5a911940 2021-06-25 tracey goto prev;
3137 ff4bb25f 2020-02-19 tracey }
3138 ff4bb25f 2020-02-19 tracey
3139 ef2c200c 2020-02-07 tracey if (commit) {
3140 ef2c200c 2020-02-07 tracey error = got_object_commit_get_logmsg(&tag_commit0,
3141 ef2c200c 2020-02-07 tracey commit);
3142 ef2c200c 2020-02-07 tracey if (error)
3143 ef2c200c 2020-02-07 tracey goto done;
3144 ef2c200c 2020-02-07 tracey got_object_commit_close(commit);
3145 ef2c200c 2020-02-07 tracey } else {
3146 ef2c200c 2020-02-07 tracey tag_commit0 = strdup(got_object_tag_get_message(tag));
3147 ef2c200c 2020-02-07 tracey if (tag_commit0 == NULL) {
3148 ef2c200c 2020-02-07 tracey error = got_error_from_errno("strdup");
3149 ef2c200c 2020-02-07 tracey goto done;
3150 ef2c200c 2020-02-07 tracey }
3151 87f9ebf5 2020-01-15 tracey }
3152 87f9ebf5 2020-01-15 tracey
3153 f2f46662 2020-01-23 tracey tag_commit = tag_commit0;
3154 f2f46662 2020-01-23 tracey while (*tag_commit == '\n')
3155 f2f46662 2020-01-23 tracey tag_commit++;
3156 87f9ebf5 2020-01-15 tracey
3157 87f9ebf5 2020-01-15 tracey switch (tag_type) {
3158 87f9ebf5 2020-01-15 tracey case TAGBRIEF:
3159 f2f46662 2020-01-23 tracey newline = strchr(tag_commit, '\n');
3160 87f9ebf5 2020-01-15 tracey if (newline)
3161 87f9ebf5 2020-01-15 tracey *newline = '\0';
3162 87f9ebf5 2020-01-15 tracey
3163 38b240fb 2020-02-06 tracey if (summary_header_displayed == 0) {
3164 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req,
3165 38b240fb 2020-02-06 tracey KELEM_DIV, KATTR_ID,
3166 38b240fb 2020-02-06 tracey "summary_tags_title_wrapper", KATTR__MAX);
3167 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3168 38b240fb 2020-02-06 tracey goto done;
3169 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req,
3170 38b240fb 2020-02-06 tracey KELEM_DIV, KATTR_ID,
3171 38b240fb 2020-02-06 tracey "summary_tags_title", KATTR__MAX);
3172 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3173 38b240fb 2020-02-06 tracey goto done;
3174 38b240fb 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req,
3175 38b240fb 2020-02-06 tracey "Tags");
3176 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3177 38b240fb 2020-02-06 tracey goto done;
3178 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req,
3179 38b240fb 2020-02-06 tracey 2);
3180 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3181 38b240fb 2020-02-06 tracey goto done;
3182 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req,
3183 38b240fb 2020-02-06 tracey KELEM_DIV, KATTR_ID,
3184 38b240fb 2020-02-06 tracey "summary_tags_content", KATTR__MAX);
3185 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3186 38b240fb 2020-02-06 tracey goto done;
3187 38b240fb 2020-02-06 tracey summary_header_displayed = 1;
3188 38b240fb 2020-02-06 tracey }
3189 38b240fb 2020-02-06 tracey
3190 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
3191 ff4bb25f 2020-02-19 tracey KATTR_ID, "tag_wrapper", KATTR__MAX);
3192 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3193 38b240fb 2020-02-06 tracey goto done;
3194 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
3195 ff4bb25f 2020-02-19 tracey KATTR_ID, "tag_age", KATTR__MAX);
3196 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3197 38b240fb 2020-02-06 tracey goto done;
3198 55ccf528 2020-02-03 stsp error = gw_get_time_str(&age, tagger_time, TM_DIFF);
3199 55ccf528 2020-02-03 stsp if (error)
3200 87f9ebf5 2020-01-15 tracey goto done;
3201 38b240fb 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req,
3202 38b240fb 2020-02-06 tracey age ? age : "");
3203 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3204 38b240fb 2020-02-06 tracey goto done;
3205 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
3206 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3207 38b240fb 2020-02-06 tracey goto done;
3208 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
3209 ff4bb25f 2020-02-19 tracey KATTR_ID, "tag", KATTR__MAX);
3210 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3211 38b240fb 2020-02-06 tracey goto done;
3212 38b240fb 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req, refname);
3213 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3214 38b240fb 2020-02-06 tracey goto done;
3215 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
3216 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3217 38b240fb 2020-02-06 tracey goto done;
3218 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
3219 ff4bb25f 2020-02-19 tracey KATTR_ID, "tag_name", KATTR__MAX);
3220 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3221 dad0fde4 2020-02-06 tracey goto done;
3222 12003b6a 2020-04-14 tracey
3223 12003b6a 2020-04-14 tracey href_tag = khttp_urlpart(NULL, NULL, "gotweb", "path",
3224 12003b6a 2020-04-14 tracey gw_trans->repo_name, "action", "tag", "commit",
3225 12003b6a 2020-04-14 tracey id_str, NULL);
3226 19ff7638 2020-04-14 tracey if (href_tag == NULL) {
3227 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
3228 19ff7638 2020-04-14 tracey goto done;
3229 19ff7638 2020-04-14 tracey }
3230 056e30c8 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
3231 056e30c8 2020-02-06 tracey KATTR_HREF, href_tag, KATTR__MAX);
3232 056e30c8 2020-02-06 tracey if (kerr != KCGI_OK)
3233 056e30c8 2020-02-06 tracey goto done;
3234 38b240fb 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req, tag_commit);
3235 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3236 38b240fb 2020-02-06 tracey goto done;
3237 dad0fde4 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 3);
3238 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3239 38b240fb 2020-02-06 tracey goto done;
3240 87f9ebf5 2020-01-15 tracey
3241 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
3242 38b240fb 2020-02-06 tracey KATTR_ID, "navs_wrapper", KATTR__MAX);
3243 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3244 38b240fb 2020-02-06 tracey goto done;
3245 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
3246 38b240fb 2020-02-06 tracey KATTR_ID, "navs", KATTR__MAX);
3247 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3248 38b240fb 2020-02-06 tracey goto done;
3249 38b240fb 2020-02-06 tracey
3250 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
3251 38b240fb 2020-02-06 tracey KATTR_HREF, href_tag, KATTR__MAX);
3252 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3253 38b240fb 2020-02-06 tracey goto done;
3254 38b240fb 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req, "tag");
3255 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3256 38b240fb 2020-02-06 tracey goto done;
3257 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
3258 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3259 38b240fb 2020-02-06 tracey goto done;
3260 87f9ebf5 2020-01-15 tracey
3261 38b240fb 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req, " | ");
3262 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3263 87f9ebf5 2020-01-15 tracey goto done;
3264 12003b6a 2020-04-14 tracey
3265 12003b6a 2020-04-14 tracey href_briefs = khttp_urlpart(NULL, NULL, "gotweb",
3266 12003b6a 2020-04-14 tracey "path", gw_trans->repo_name, "action", "briefs",
3267 12003b6a 2020-04-14 tracey "commit", id_str, NULL);
3268 19ff7638 2020-04-14 tracey if (href_briefs == NULL) {
3269 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
3270 19ff7638 2020-04-14 tracey goto done;
3271 19ff7638 2020-04-14 tracey }
3272 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
3273 38b240fb 2020-02-06 tracey KATTR_HREF, href_briefs, KATTR__MAX);
3274 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3275 38b240fb 2020-02-06 tracey goto done;
3276 38b240fb 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req,
3277 38b240fb 2020-02-06 tracey "commit briefs");
3278 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3279 38b240fb 2020-02-06 tracey goto done;
3280 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
3281 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3282 38b240fb 2020-02-06 tracey goto done;
3283 87f9ebf5 2020-01-15 tracey
3284 38b240fb 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req, " | ");
3285 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3286 38b240fb 2020-02-06 tracey goto done;
3287 38b240fb 2020-02-06 tracey
3288 12003b6a 2020-04-14 tracey href_commits = khttp_urlpart(NULL, NULL, "gotweb",
3289 12003b6a 2020-04-14 tracey "path", gw_trans->repo_name, "action", "commits",
3290 12003b6a 2020-04-14 tracey "commit", id_str, NULL);
3291 19ff7638 2020-04-14 tracey if (href_commits == NULL) {
3292 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
3293 19ff7638 2020-04-14 tracey goto done;
3294 19ff7638 2020-04-14 tracey }
3295 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
3296 38b240fb 2020-02-06 tracey KATTR_HREF, href_commits, KATTR__MAX);
3297 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3298 38b240fb 2020-02-06 tracey goto done;
3299 32b9f7ed 2020-04-14 tracey kerr = khtml_puts(gw_trans->gw_html_req, "commits");
3300 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3301 38b240fb 2020-02-06 tracey goto done;
3302 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 3);
3303 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3304 38b240fb 2020-02-06 tracey goto done;
3305 38b240fb 2020-02-06 tracey
3306 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
3307 38b240fb 2020-02-06 tracey KATTR_ID, "dotted_line", KATTR__MAX);
3308 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3309 38b240fb 2020-02-06 tracey goto done;
3310 ef2c200c 2020-02-07 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
3311 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3312 38b240fb 2020-02-06 tracey goto done;
3313 87f9ebf5 2020-01-15 tracey break;
3314 87f9ebf5 2020-01-15 tracey case TAGFULL:
3315 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
3316 38b240fb 2020-02-06 tracey KATTR_ID, "tag_info_date_title", KATTR__MAX);
3317 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3318 38b240fb 2020-02-06 tracey goto done;
3319 38b240fb 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Tag Date:");
3320 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3321 38b240fb 2020-02-06 tracey goto done;
3322 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
3323 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3324 38b240fb 2020-02-06 tracey goto done;
3325 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
3326 38b240fb 2020-02-06 tracey KATTR_ID, "tag_info_date", KATTR__MAX);
3327 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3328 38b240fb 2020-02-06 tracey goto done;
3329 55ccf528 2020-02-03 stsp error = gw_get_time_str(&age, tagger_time, TM_LONG);
3330 55ccf528 2020-02-03 stsp if (error)
3331 4ff7391f 2020-01-28 tracey goto done;
3332 38b240fb 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req,
3333 38b240fb 2020-02-06 tracey age ? age : "");
3334 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3335 070fee27 2020-02-03 stsp goto done;
3336 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
3337 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3338 38b240fb 2020-02-06 tracey goto done;
3339 38b240fb 2020-02-06 tracey
3340 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
3341 38b240fb 2020-02-06 tracey KATTR_ID, "tag_info_tagger_title", KATTR__MAX);
3342 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3343 38b240fb 2020-02-06 tracey goto done;
3344 38b240fb 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Tagger:");
3345 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3346 38b240fb 2020-02-06 tracey goto done;
3347 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
3348 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3349 38b240fb 2020-02-06 tracey goto done;
3350 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
3351 38b240fb 2020-02-06 tracey KATTR_ID, "tag_info_date", KATTR__MAX);
3352 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3353 38b240fb 2020-02-06 tracey goto done;
3354 38b240fb 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req, tagger);
3355 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3356 38b240fb 2020-02-06 tracey goto done;
3357 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
3358 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3359 38b240fb 2020-02-06 tracey goto done;
3360 38b240fb 2020-02-06 tracey
3361 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
3362 38b240fb 2020-02-06 tracey KATTR_ID, "tag_info", KATTR__MAX);
3363 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3364 38b240fb 2020-02-06 tracey goto done;
3365 78a9dab5 2020-02-07 tracey kerr = khttp_puts(gw_trans->gw_req, tag_commit);
3366 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3367 4ff7391f 2020-01-28 tracey goto done;
3368 87f9ebf5 2020-01-15 tracey break;
3369 87f9ebf5 2020-01-15 tracey default:
3370 87f9ebf5 2020-01-15 tracey break;
3371 87f9ebf5 2020-01-15 tracey }
3372 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
3373 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3374 6eccd105 2020-02-03 stsp goto done;
3375 87ca24ac 2020-02-04 tracey
3376 6eccd105 2020-02-03 stsp if (limit && --limit == 0)
3377 ff4bb25f 2020-02-19 tracey chk_next = 1;
3378 87f9ebf5 2020-01-15 tracey
3379 ef2c200c 2020-02-07 tracey if (tag)
3380 ef2c200c 2020-02-07 tracey got_object_tag_close(tag);
3381 6eccd105 2020-02-03 stsp tag = NULL;
3382 6c6c85af 2020-01-15 tracey free(id_str);
3383 6eccd105 2020-02-03 stsp id_str = NULL;
3384 6c6c85af 2020-01-15 tracey free(age);
3385 55ccf528 2020-02-03 stsp age = NULL;
3386 f2f46662 2020-01-23 tracey free(tag_commit0);
3387 6eccd105 2020-02-03 stsp tag_commit0 = NULL;
3388 38b240fb 2020-02-06 tracey free(href_tag);
3389 38b240fb 2020-02-06 tracey href_tag = NULL;
3390 38b240fb 2020-02-06 tracey free(href_briefs);
3391 38b240fb 2020-02-06 tracey href_briefs = NULL;
3392 38b240fb 2020-02-06 tracey free(href_commits);
3393 38b240fb 2020-02-06 tracey href_commits = NULL;
3394 ff4bb25f 2020-02-19 tracey }
3395 ff4bb25f 2020-02-19 tracey if (tag_count == 0) {
3396 ff4bb25f 2020-02-19 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
3397 ff4bb25f 2020-02-19 tracey "summary_tags_title_wrapper", KATTR__MAX);
3398 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
3399 ff4bb25f 2020-02-19 tracey goto done;
3400 ff4bb25f 2020-02-19 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
3401 ff4bb25f 2020-02-19 tracey "summary_tags_title", KATTR__MAX);
3402 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
3403 ff4bb25f 2020-02-19 tracey goto done;
3404 ff4bb25f 2020-02-19 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Tags");
3405 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
3406 ff4bb25f 2020-02-19 tracey goto done;
3407 ff4bb25f 2020-02-19 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
3408 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
3409 ff4bb25f 2020-02-19 tracey goto done;
3410 ff4bb25f 2020-02-19 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
3411 ff4bb25f 2020-02-19 tracey "summary_tags_content", KATTR__MAX);
3412 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
3413 ff4bb25f 2020-02-19 tracey goto done;
3414 ff4bb25f 2020-02-19 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
3415 ff4bb25f 2020-02-19 tracey "tags_info", KATTR__MAX);
3416 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
3417 ff4bb25f 2020-02-19 tracey goto done;
3418 ff4bb25f 2020-02-19 tracey kerr = khttp_puts(gw_trans->gw_req,
3419 ff4bb25f 2020-02-19 tracey "There are no tags for this repo.");
3420 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
3421 ff4bb25f 2020-02-19 tracey goto done;
3422 ff4bb25f 2020-02-19 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
3423 5a911940 2021-06-25 tracey goto done;
3424 6c6c85af 2020-01-15 tracey }
3425 5a911940 2021-06-25 tracey prev:
3426 5a911940 2021-06-25 tracey commit_found = 0;
3427 5a911940 2021-06-25 tracey TAILQ_FOREACH_REVERSE(re, &refs, got_reflist_head, entry) {
3428 5a911940 2021-06-25 tracey const char *refname;
3429 5a911940 2021-06-25 tracey struct got_object_id *id;
3430 5a911940 2021-06-25 tracey struct got_commit_object *commit = NULL;
3431 5a911940 2021-06-25 tracey
3432 5a911940 2021-06-25 tracey refname = got_ref_get_name(re->ref);
3433 5a911940 2021-06-25 tracey if (strncmp(refname, "refs/tags/", 10) != 0)
3434 5a911940 2021-06-25 tracey continue;
3435 5a911940 2021-06-25 tracey refname += 10;
3436 5a911940 2021-06-25 tracey
3437 5a911940 2021-06-25 tracey error = got_ref_resolve(&id, gw_trans->repo, re->ref);
3438 5a911940 2021-06-25 tracey if (error)
3439 5a911940 2021-06-25 tracey goto done;
3440 5a911940 2021-06-25 tracey
3441 5a911940 2021-06-25 tracey error = got_object_open_as_tag(&tag, gw_trans->repo, id);
3442 5a911940 2021-06-25 tracey if (error) {
3443 5a911940 2021-06-25 tracey if (error->code != GOT_ERR_OBJ_TYPE) {
3444 5a911940 2021-06-25 tracey free(id);
3445 5a911940 2021-06-25 tracey goto done;
3446 5a911940 2021-06-25 tracey }
3447 5a911940 2021-06-25 tracey /* "lightweight" tag */
3448 5a911940 2021-06-25 tracey error = got_object_open_as_commit(&commit,
3449 5a911940 2021-06-25 tracey gw_trans->repo, id);
3450 5a911940 2021-06-25 tracey if (error) {
3451 5a911940 2021-06-25 tracey free(id);
3452 5a911940 2021-06-25 tracey goto done;
3453 5a911940 2021-06-25 tracey }
3454 5a911940 2021-06-25 tracey error = got_object_id_str(&id_str, id);
3455 5a911940 2021-06-25 tracey free(id);
3456 5a911940 2021-06-25 tracey } else {
3457 5a911940 2021-06-25 tracey free(id);
3458 5a911940 2021-06-25 tracey error = got_object_id_str(&id_str,
3459 5a911940 2021-06-25 tracey got_object_tag_get_object_id(tag));
3460 5a911940 2021-06-25 tracey }
3461 5a911940 2021-06-25 tracey if (error)
3462 5a911940 2021-06-25 tracey goto done;
3463 5a911940 2021-06-25 tracey
3464 5a911940 2021-06-25 tracey if (tag_type == TAGFULL && strncmp(id_str, header->commit_id,
3465 5a911940 2021-06-25 tracey strlen(id_str)) != 0)
3466 5a911940 2021-06-25 tracey continue;
3467 5a911940 2021-06-25 tracey
3468 5a911940 2021-06-25 tracey if (commit_found == 0 && tag_type == TAGBRIEF &&
3469 5a911940 2021-06-25 tracey gw_trans->commit_id != NULL &&
3470 5a911940 2021-06-25 tracey strncmp(id_str, gw_trans->commit_id, strlen(id_str)) != 0)
3471 5a911940 2021-06-25 tracey continue;
3472 5a911940 2021-06-25 tracey else
3473 5a911940 2021-06-25 tracey commit_found = 1;
3474 5a911940 2021-06-25 tracey
3475 5a911940 2021-06-25 tracey if (gw_trans->commit_id != NULL &&
3476 5a911940 2021-06-25 tracey strcmp(id_str, gw_trans->commit_id) != 0 &&
3477 5a911940 2021-06-25 tracey (re == TAILQ_FIRST(&refs) ||
3478 5a911940 2021-06-25 tracey c_cnt == gw_trans->gw_conf->got_max_commits_display)) {
3479 5a911940 2021-06-25 tracey gw_trans->prev_id = strdup(id_str);
3480 5a911940 2021-06-25 tracey if (gw_trans->prev_id == NULL) {
3481 5a911940 2021-06-25 tracey error = got_error_from_errno("strdup");
3482 5a911940 2021-06-25 tracey goto done;
3483 5a911940 2021-06-25 tracey }
3484 5a911940 2021-06-25 tracey break;
3485 5a911940 2021-06-25 tracey }
3486 5a911940 2021-06-25 tracey c_cnt++;
3487 5a911940 2021-06-25 tracey }
3488 87f9ebf5 2020-01-15 tracey done:
3489 6eccd105 2020-02-03 stsp if (tag)
3490 6eccd105 2020-02-03 stsp got_object_tag_close(tag);
3491 6eccd105 2020-02-03 stsp free(id_str);
3492 55ccf528 2020-02-03 stsp free(age);
3493 6eccd105 2020-02-03 stsp free(tag_commit0);
3494 38b240fb 2020-02-06 tracey free(href_tag);
3495 38b240fb 2020-02-06 tracey free(href_briefs);
3496 38b240fb 2020-02-06 tracey free(href_commits);
3497 6eccd105 2020-02-03 stsp got_ref_list_free(&refs);
3498 38b240fb 2020-02-06 tracey if (error == NULL && kerr != KCGI_OK)
3499 38b240fb 2020-02-06 tracey error = gw_kcgi_error(kerr);
3500 6eccd105 2020-02-03 stsp return error;
3501 f2f46662 2020-01-23 tracey }
3502 f2f46662 2020-01-23 tracey
3503 f2f46662 2020-01-23 tracey static void
3504 b0a1bc86 2020-02-14 stsp gw_free_header(struct gw_header *header)
3505 f2f46662 2020-01-23 tracey {
3506 f2f46662 2020-01-23 tracey free(header->path);
3507 4e8d6e3e 2020-02-14 tracey free(header->author);
3508 4e8d6e3e 2020-02-14 tracey free(header->committer);
3509 f2f46662 2020-01-23 tracey free(header->refs_str);
3510 f2f46662 2020-01-23 tracey free(header->commit_id);
3511 f2f46662 2020-01-23 tracey free(header->parent_id);
3512 f2f46662 2020-01-23 tracey free(header->tree_id);
3513 f2f46662 2020-01-23 tracey free(header->commit_msg);
3514 f2f46662 2020-01-23 tracey }
3515 f2f46662 2020-01-23 tracey
3516 f2f46662 2020-01-23 tracey static struct gw_header *
3517 f2f46662 2020-01-23 tracey gw_init_header()
3518 f2f46662 2020-01-23 tracey {
3519 f2f46662 2020-01-23 tracey struct gw_header *header;
3520 f2f46662 2020-01-23 tracey
3521 ae36ed87 2020-01-28 stsp header = malloc(sizeof(*header));
3522 ae36ed87 2020-01-28 stsp if (header == NULL)
3523 f2f46662 2020-01-23 tracey return NULL;
3524 f2f46662 2020-01-23 tracey
3525 f2f46662 2020-01-23 tracey header->path = NULL;
3526 d9dff0e5 2020-12-26 stsp TAILQ_INIT(&header->refs);
3527 5c65becf 2020-02-13 tracey
3528 5c65becf 2020-02-13 tracey header->refs_str = NULL;
3529 5c65becf 2020-02-13 tracey header->commit_id = NULL;
3530 f9315db0 2020-02-14 tracey header->committer = NULL;
3531 f9315db0 2020-02-14 tracey header->author = NULL;
3532 5c65becf 2020-02-13 tracey header->parent_id = NULL;
3533 5c65becf 2020-02-13 tracey header->tree_id = NULL;
3534 5c65becf 2020-02-13 tracey header->commit_msg = NULL;
3535 f2f46662 2020-01-23 tracey
3536 f2f46662 2020-01-23 tracey return header;
3537 f2f46662 2020-01-23 tracey }
3538 f2f46662 2020-01-23 tracey
3539 f2f46662 2020-01-23 tracey static const struct got_error *
3540 f2f46662 2020-01-23 tracey gw_get_commits(struct gw_trans * gw_trans, struct gw_header *header,
3541 3c245a0e 2020-02-14 tracey int limit, struct got_object_id *id)
3542 f2f46662 2020-01-23 tracey {
3543 f2f46662 2020-01-23 tracey const struct got_error *error = NULL;
3544 f2f46662 2020-01-23 tracey struct got_commit_graph *graph = NULL;
3545 4e8d6e3e 2020-02-14 tracey struct got_commit_object *commit = NULL;
3546 5a911940 2021-06-25 tracey int chk_next = 0, chk_multi = 0, c_cnt = 0, commit_found = 0;
3547 5a911940 2021-06-25 tracey struct gw_header *t_header = NULL;
3548 f2f46662 2020-01-23 tracey
3549 f2f46662 2020-01-23 tracey error = got_commit_graph_open(&graph, header->path, 0);
3550 f2f46662 2020-01-23 tracey if (error)
3551 00f13350 2020-02-10 tracey return error;
3552 f2f46662 2020-01-23 tracey
3553 deac617c 2020-02-14 tracey error = got_commit_graph_iter_start(graph, id, gw_trans->repo, NULL,
3554 3c245a0e 2020-02-14 tracey NULL);
3555 f2f46662 2020-01-23 tracey if (error)
3556 c333d3f7 2021-06-25 tracey goto err;
3557 f2f46662 2020-01-23 tracey
3558 f2f46662 2020-01-23 tracey for (;;) {
3559 deac617c 2020-02-14 tracey error = got_commit_graph_iter_next(&id, graph, gw_trans->repo,
3560 3c245a0e 2020-02-14 tracey NULL, NULL);
3561 f2f46662 2020-01-23 tracey if (error) {
3562 f2f46662 2020-01-23 tracey if (error->code == GOT_ERR_ITER_COMPLETED)
3563 f2f46662 2020-01-23 tracey error = NULL;
3564 c333d3f7 2021-06-25 tracey goto done;
3565 f2f46662 2020-01-23 tracey }
3566 3c245a0e 2020-02-14 tracey if (id == NULL)
3567 5a911940 2021-06-25 tracey goto err;
3568 f2f46662 2020-01-23 tracey
3569 deac617c 2020-02-14 tracey error = got_object_open_as_commit(&commit, gw_trans->repo, id);
3570 c333d3f7 2021-06-25 tracey if (error)
3571 c333d3f7 2021-06-25 tracey goto err;
3572 bf4484a3 2020-02-18 tracey if (limit == 1 && chk_multi == 0 &&
3573 bf4484a3 2020-02-18 tracey gw_trans->gw_conf->got_max_commits_display != 1) {
3574 3c245a0e 2020-02-14 tracey error = gw_get_commit(gw_trans, header, commit, id);
3575 4e8d6e3e 2020-02-14 tracey if (error)
3576 5a911940 2021-06-25 tracey goto err;
3577 5a911940 2021-06-25 tracey commit_found = 1;
3578 4e8d6e3e 2020-02-14 tracey } else {
3579 55e46400 2020-02-18 tracey chk_multi = 1;
3580 f2f46662 2020-01-23 tracey struct gw_header *n_header = NULL;
3581 5147ab56 2020-01-29 stsp if ((n_header = gw_init_header()) == NULL) {
3582 f2f46662 2020-01-23 tracey error = got_error_from_errno("malloc");
3583 5a911940 2021-06-25 tracey goto err;
3584 d1635ae4 2020-02-13 tracey }
3585 5a911940 2021-06-25 tracey TAILQ_INSERT_TAIL(&gw_trans->gw_headers, n_header,
3586 5a911940 2021-06-25 tracey entry);
3587 bf93a5c0 2020-02-15 tracey error = got_ref_list(&n_header->refs, gw_trans->repo,
3588 bf93a5c0 2020-02-15 tracey NULL, got_ref_cmp_by_name, NULL);
3589 bf93a5c0 2020-02-15 tracey if (error)
3590 5a911940 2021-06-25 tracey goto err;
3591 bf93a5c0 2020-02-15 tracey
3592 3c245a0e 2020-02-14 tracey error = gw_get_commit(gw_trans, n_header, commit, id);
3593 4e8d6e3e 2020-02-14 tracey if (error)
3594 5a911940 2021-06-25 tracey goto err;
3595 bc8c6114 2020-02-17 tracey got_ref_list_free(&n_header->refs);
3596 55e46400 2020-02-18 tracey
3597 5a911940 2021-06-25 tracey if (gw_trans->commit_id != NULL) {
3598 5a911940 2021-06-25 tracey if (strcmp(gw_trans->commit_id,
3599 5a911940 2021-06-25 tracey n_header->commit_id) == 0)
3600 5a911940 2021-06-25 tracey commit_found = 1;
3601 5a911940 2021-06-25 tracey } else
3602 5a911940 2021-06-25 tracey commit_found = 1;
3603 55e46400 2020-02-18 tracey
3604 55e46400 2020-02-18 tracey /*
3605 55e46400 2020-02-18 tracey * check for one more commit before breaking,
3606 a378df9f 2022-04-16 thomas * so we know whether to navigate through gw_briefs
3607 55e46400 2020-02-18 tracey * gw_commits and gw_summary
3608 55e46400 2020-02-18 tracey */
3609 5a911940 2021-06-25 tracey if (chk_next && (gw_trans->action == GW_BRIEFS ||
3610 55e46400 2020-02-18 tracey gw_trans->action == GW_COMMITS ||
3611 55e46400 2020-02-18 tracey gw_trans->action == GW_SUMMARY)) {
3612 55e46400 2020-02-18 tracey gw_trans->next_id = strdup(n_header->commit_id);
3613 55e46400 2020-02-18 tracey if (gw_trans->next_id == NULL)
3614 55e46400 2020-02-18 tracey error = got_error_from_errno("strdup");
3615 5a911940 2021-06-25 tracey TAILQ_REMOVE(&gw_trans->gw_headers, n_header,
3616 5a911940 2021-06-25 tracey entry);
3617 55e46400 2020-02-18 tracey goto done;
3618 55e46400 2020-02-18 tracey }
3619 55e46400 2020-02-18 tracey
3620 f2f46662 2020-01-23 tracey }
3621 5a911940 2021-06-25 tracey if (commit_found == 1 && (error || (limit && --limit == 0))) {
3622 55e46400 2020-02-18 tracey if (chk_multi == 0)
3623 55e46400 2020-02-18 tracey break;
3624 55e46400 2020-02-18 tracey chk_next = 1;
3625 55e46400 2020-02-18 tracey }
3626 f2f46662 2020-01-23 tracey }
3627 f2f46662 2020-01-23 tracey done:
3628 5a911940 2021-06-25 tracey if (gw_trans->prev_id == NULL && gw_trans->commit_id != NULL &&
3629 178d3e72 2021-06-25 tracey (gw_trans->action == GW_BRIEFS || gw_trans->action == GW_COMMITS)) {
3630 f75a37be 2021-06-25 tracey commit_found = 0;
3631 5a911940 2021-06-25 tracey TAILQ_FOREACH_REVERSE(t_header, &gw_trans->gw_headers,
3632 5a911940 2021-06-25 tracey headers, entry) {
3633 5a911940 2021-06-25 tracey if (commit_found == 0 &&
3634 5a911940 2021-06-25 tracey strcmp(gw_trans->commit_id,
3635 5a911940 2021-06-25 tracey t_header->commit_id) != 0)
3636 5a911940 2021-06-25 tracey continue;
3637 f75a37be 2021-06-25 tracey else
3638 f75a37be 2021-06-25 tracey commit_found = 1;
3639 5a911940 2021-06-25 tracey if (gw_trans->commit_id != NULL &&
3640 5a911940 2021-06-25 tracey strcmp(gw_trans->commit_id,
3641 5a911940 2021-06-25 tracey t_header->commit_id) != 0 &&
3642 5a911940 2021-06-25 tracey (c_cnt == gw_trans->gw_conf->got_max_commits_display
3643 5a911940 2021-06-25 tracey || t_header ==
3644 5a911940 2021-06-25 tracey TAILQ_FIRST(&gw_trans->gw_headers))) {
3645 5a911940 2021-06-25 tracey gw_trans->prev_id = strdup(t_header->commit_id);
3646 5a911940 2021-06-25 tracey if (gw_trans->prev_id == NULL)
3647 5a911940 2021-06-25 tracey error = got_error_from_errno("strdup");
3648 5a911940 2021-06-25 tracey break;
3649 5a911940 2021-06-25 tracey }
3650 5a911940 2021-06-25 tracey c_cnt++;
3651 5a911940 2021-06-25 tracey }
3652 5a911940 2021-06-25 tracey }
3653 5a911940 2021-06-25 tracey err:
3654 4e8d6e3e 2020-02-14 tracey if (commit != NULL)
3655 4e8d6e3e 2020-02-14 tracey got_object_commit_close(commit);
3656 f2f46662 2020-01-23 tracey if (graph)
3657 f2f46662 2020-01-23 tracey got_commit_graph_close(graph);
3658 f2f46662 2020-01-23 tracey return error;
3659 f2f46662 2020-01-23 tracey }
3660 f2f46662 2020-01-23 tracey
3661 f2f46662 2020-01-23 tracey static const struct got_error *
3662 4e8d6e3e 2020-02-14 tracey gw_get_commit(struct gw_trans *gw_trans, struct gw_header *header,
3663 4e8d6e3e 2020-02-14 tracey struct got_commit_object *commit, struct got_object_id *id)
3664 f2f46662 2020-01-23 tracey {
3665 f2f46662 2020-01-23 tracey const struct got_error *error = NULL;
3666 f2f46662 2020-01-23 tracey struct got_reflist_entry *re;
3667 f2f46662 2020-01-23 tracey struct got_object_id *id2 = NULL;
3668 f2f46662 2020-01-23 tracey struct got_object_qid *parent_id;
3669 a81394a7 2020-02-13 stsp char *commit_msg = NULL, *commit_msg0;
3670 f2f46662 2020-01-23 tracey
3671 f2f46662 2020-01-23 tracey /*print commit*/
3672 d9dff0e5 2020-12-26 stsp TAILQ_FOREACH(re, &header->refs, entry) {
3673 f2f46662 2020-01-23 tracey char *s;
3674 f2f46662 2020-01-23 tracey const char *name;
3675 f2f46662 2020-01-23 tracey struct got_tag_object *tag = NULL;
3676 3721d310 2020-09-23 stsp struct got_object_id *ref_id;
3677 f2f46662 2020-01-23 tracey int cmp;
3678 f2f46662 2020-01-23 tracey
3679 eb4f3ad3 2020-02-14 stsp if (got_ref_is_symbolic(re->ref))
3680 f2f46662 2020-01-23 tracey continue;
3681 eb4f3ad3 2020-02-14 stsp
3682 eb4f3ad3 2020-02-14 stsp name = got_ref_get_name(re->ref);
3683 f2f46662 2020-01-23 tracey if (strncmp(name, "refs/", 5) == 0)
3684 f2f46662 2020-01-23 tracey name += 5;
3685 f2f46662 2020-01-23 tracey if (strncmp(name, "got/", 4) == 0)
3686 f2f46662 2020-01-23 tracey continue;
3687 f2f46662 2020-01-23 tracey if (strncmp(name, "heads/", 6) == 0)
3688 f2f46662 2020-01-23 tracey name += 6;
3689 abdd569e 2020-09-23 stsp if (strncmp(name, "remotes/", 8) == 0) {
3690 f2f46662 2020-01-23 tracey name += 8;
3691 abdd569e 2020-09-23 stsp s = strstr(name, "/" GOT_REF_HEAD);
3692 abdd569e 2020-09-23 stsp if (s != NULL && s[strlen(s)] == '\0')
3693 abdd569e 2020-09-23 stsp continue;
3694 abdd569e 2020-09-23 stsp }
3695 3721d310 2020-09-23 stsp error = got_ref_resolve(&ref_id, gw_trans->repo, re->ref);
3696 3721d310 2020-09-23 stsp if (error)
3697 3721d310 2020-09-23 stsp return error;
3698 f2f46662 2020-01-23 tracey if (strncmp(name, "tags/", 5) == 0) {
3699 deac617c 2020-02-14 tracey error = got_object_open_as_tag(&tag, gw_trans->repo,
3700 3721d310 2020-09-23 stsp ref_id);
3701 f2f46662 2020-01-23 tracey if (error) {
3702 3721d310 2020-09-23 stsp if (error->code != GOT_ERR_OBJ_TYPE) {
3703 3721d310 2020-09-23 stsp free(ref_id);
3704 f2f46662 2020-01-23 tracey continue;
3705 3721d310 2020-09-23 stsp }
3706 f2f46662 2020-01-23 tracey /*
3707 f2f46662 2020-01-23 tracey * Ref points at something other
3708 f2f46662 2020-01-23 tracey * than a tag.
3709 f2f46662 2020-01-23 tracey */
3710 f2f46662 2020-01-23 tracey error = NULL;
3711 f2f46662 2020-01-23 tracey tag = NULL;
3712 f2f46662 2020-01-23 tracey }
3713 f2f46662 2020-01-23 tracey }
3714 f2f46662 2020-01-23 tracey cmp = got_object_id_cmp(tag ?
3715 3721d310 2020-09-23 stsp got_object_tag_get_object_id(tag) : ref_id, id);
3716 3721d310 2020-09-23 stsp free(ref_id);
3717 f2f46662 2020-01-23 tracey if (tag)
3718 f2f46662 2020-01-23 tracey got_object_tag_close(tag);
3719 f2f46662 2020-01-23 tracey if (cmp != 0)
3720 f2f46662 2020-01-23 tracey continue;
3721 a81394a7 2020-02-13 stsp s = header->refs_str;
3722 a81394a7 2020-02-13 stsp if (asprintf(&header->refs_str, "%s%s%s", s ? s : "",
3723 88d59c36 2020-01-29 stsp s ? ", " : "", name) == -1) {
3724 f2f46662 2020-01-23 tracey error = got_error_from_errno("asprintf");
3725 f2f46662 2020-01-23 tracey free(s);
3726 a81394a7 2020-02-13 stsp header->refs_str = NULL;
3727 f2f46662 2020-01-23 tracey return error;
3728 f2f46662 2020-01-23 tracey }
3729 f2f46662 2020-01-23 tracey free(s);
3730 f2f46662 2020-01-23 tracey }
3731 f1200fe3 2020-02-13 tracey
3732 4e8d6e3e 2020-02-14 tracey error = got_object_id_str(&header->commit_id, id);
3733 f2f46662 2020-01-23 tracey if (error)
3734 f2f46662 2020-01-23 tracey return error;
3735 f2f46662 2020-01-23 tracey
3736 f2f46662 2020-01-23 tracey error = got_object_id_str(&header->tree_id,
3737 4e8d6e3e 2020-02-14 tracey got_object_commit_get_tree_id(commit));
3738 f2f46662 2020-01-23 tracey if (error)
3739 f2f46662 2020-01-23 tracey return error;
3740 f2f46662 2020-01-23 tracey
3741 f2f46662 2020-01-23 tracey if (gw_trans->action == GW_DIFF) {
3742 dbdddfee 2021-06-23 naddy parent_id = STAILQ_FIRST(
3743 4e8d6e3e 2020-02-14 tracey got_object_commit_get_parent_ids(commit));
3744 f2f46662 2020-01-23 tracey if (parent_id != NULL) {
3745 ec242592 2022-04-22 thomas id2 = got_object_id_dup(&parent_id->id);
3746 f2f46662 2020-01-23 tracey free (parent_id);
3747 f2f46662 2020-01-23 tracey error = got_object_id_str(&header->parent_id, id2);
3748 f2f46662 2020-01-23 tracey if (error)
3749 f2f46662 2020-01-23 tracey return error;
3750 f2f46662 2020-01-23 tracey free(id2);
3751 a942aa37 2020-02-10 tracey } else {
3752 d1635ae4 2020-02-13 tracey header->parent_id = strdup("/dev/null");
3753 d1635ae4 2020-02-13 tracey if (header->parent_id == NULL) {
3754 d1635ae4 2020-02-13 tracey error = got_error_from_errno("strdup");
3755 a942aa37 2020-02-10 tracey return error;
3756 d1635ae4 2020-02-13 tracey }
3757 d1635ae4 2020-02-13 tracey }
3758 a942aa37 2020-02-10 tracey }
3759 f2f46662 2020-01-23 tracey
3760 f2f46662 2020-01-23 tracey header->committer_time =
3761 4e8d6e3e 2020-02-14 tracey got_object_commit_get_committer_time(commit);
3762 1177268c 2020-01-28 tracey
3763 d1635ae4 2020-02-13 tracey header->author =
3764 4e8d6e3e 2020-02-14 tracey strdup(got_object_commit_get_author(commit));
3765 4e8d6e3e 2020-02-14 tracey if (header->author == NULL) {
3766 4e8d6e3e 2020-02-14 tracey error = got_error_from_errno("strdup");
3767 4e8d6e3e 2020-02-14 tracey return error;
3768 4e8d6e3e 2020-02-14 tracey }
3769 d1635ae4 2020-02-13 tracey header->committer =
3770 4e8d6e3e 2020-02-14 tracey strdup(got_object_commit_get_committer(commit));
3771 4e8d6e3e 2020-02-14 tracey if (header->committer == NULL) {
3772 4e8d6e3e 2020-02-14 tracey error = got_error_from_errno("strdup");
3773 a942aa37 2020-02-10 tracey return error;
3774 4e8d6e3e 2020-02-14 tracey }
3775 4e8d6e3e 2020-02-14 tracey error = got_object_commit_get_logmsg(&commit_msg0, commit);
3776 f2f46662 2020-01-23 tracey if (error)
3777 f2f46662 2020-01-23 tracey return error;
3778 f2f46662 2020-01-23 tracey
3779 f2f46662 2020-01-23 tracey commit_msg = commit_msg0;
3780 f2f46662 2020-01-23 tracey while (*commit_msg == '\n')
3781 f2f46662 2020-01-23 tracey commit_msg++;
3782 f2f46662 2020-01-23 tracey
3783 d1635ae4 2020-02-13 tracey header->commit_msg = strdup(commit_msg);
3784 d1635ae4 2020-02-13 tracey if (header->commit_msg == NULL)
3785 d1635ae4 2020-02-13 tracey error = got_error_from_errno("strdup");
3786 f2f46662 2020-01-23 tracey free(commit_msg0);
3787 f2f46662 2020-01-23 tracey return error;
3788 f2f46662 2020-01-23 tracey }
3789 f2f46662 2020-01-23 tracey
3790 f2f46662 2020-01-23 tracey static const struct got_error *
3791 f2f46662 2020-01-23 tracey gw_get_header(struct gw_trans *gw_trans, struct gw_header *header, int limit)
3792 f2f46662 2020-01-23 tracey {
3793 f2f46662 2020-01-23 tracey const struct got_error *error = NULL;
3794 f2f46662 2020-01-23 tracey char *in_repo_path = NULL;
3795 3c245a0e 2020-02-14 tracey struct got_object_id *id = NULL;
3796 5a911940 2021-06-25 tracey struct got_reference *ref;
3797 f2f46662 2020-01-23 tracey
3798 7cd52833 2022-06-23 thomas error = got_repo_open(&gw_trans->repo, gw_trans->repo_path, NULL,
3799 e0fb2ce2 2022-06-23 thomas gw_trans->pack_fds);
3800 f2f46662 2020-01-23 tracey if (error)
3801 f2f46662 2020-01-23 tracey return error;
3802 f2f46662 2020-01-23 tracey
3803 5a911940 2021-06-25 tracey if (gw_trans->commit_id == NULL || gw_trans->action == GW_COMMITS ||
3804 5a911940 2021-06-25 tracey gw_trans->action == GW_BRIEFS || gw_trans->action == GW_SUMMARY ||
3805 5a911940 2021-06-25 tracey gw_trans->action == GW_TAGS) {
3806 5a911940 2021-06-25 tracey error = got_ref_open(&ref, gw_trans->repo,
3807 f2f46662 2020-01-23 tracey gw_trans->headref, 0);
3808 f2f46662 2020-01-23 tracey if (error)
3809 f2f46662 2020-01-23 tracey return error;
3810 f2f46662 2020-01-23 tracey
3811 5a911940 2021-06-25 tracey error = got_ref_resolve(&id, gw_trans->repo, ref);
3812 5a911940 2021-06-25 tracey got_ref_close(ref);
3813 f2f46662 2020-01-23 tracey if (error)
3814 f2f46662 2020-01-23 tracey return error;
3815 f2f46662 2020-01-23 tracey } else {
3816 56997cd3 2020-02-14 tracey error = got_ref_open(&ref, gw_trans->repo,
3817 56997cd3 2020-02-14 tracey gw_trans->commit_id, 0);
3818 f2f46662 2020-01-23 tracey if (error == NULL) {
3819 f2f46662 2020-01-23 tracey int obj_type;
3820 deac617c 2020-02-14 tracey error = got_ref_resolve(&id, gw_trans->repo, ref);
3821 f2f46662 2020-01-23 tracey got_ref_close(ref);
3822 f2f46662 2020-01-23 tracey if (error)
3823 f2f46662 2020-01-23 tracey return error;
3824 deac617c 2020-02-14 tracey error = got_object_get_type(&obj_type, gw_trans->repo,
3825 3c245a0e 2020-02-14 tracey id);
3826 f2f46662 2020-01-23 tracey if (error)
3827 4e8d6e3e 2020-02-14 tracey goto done;
3828 f2f46662 2020-01-23 tracey if (obj_type == GOT_OBJ_TYPE_TAG) {
3829 f2f46662 2020-01-23 tracey struct got_tag_object *tag;
3830 f2f46662 2020-01-23 tracey error = got_object_open_as_tag(&tag,
3831 deac617c 2020-02-14 tracey gw_trans->repo, id);
3832 f2f46662 2020-01-23 tracey if (error)
3833 4e8d6e3e 2020-02-14 tracey goto done;
3834 f2f46662 2020-01-23 tracey if (got_object_tag_get_object_type(tag) !=
3835 f2f46662 2020-01-23 tracey GOT_OBJ_TYPE_COMMIT) {
3836 f2f46662 2020-01-23 tracey got_object_tag_close(tag);
3837 f2f46662 2020-01-23 tracey error = got_error(GOT_ERR_OBJ_TYPE);
3838 4e8d6e3e 2020-02-14 tracey goto done;
3839 f2f46662 2020-01-23 tracey }
3840 3c245a0e 2020-02-14 tracey free(id);
3841 3c245a0e 2020-02-14 tracey id = got_object_id_dup(
3842 f2f46662 2020-01-23 tracey got_object_tag_get_object_id(tag));
3843 3c245a0e 2020-02-14 tracey if (id == NULL)
3844 f2f46662 2020-01-23 tracey error = got_error_from_errno(
3845 f2f46662 2020-01-23 tracey "got_object_id_dup");
3846 f2f46662 2020-01-23 tracey got_object_tag_close(tag);
3847 f2f46662 2020-01-23 tracey if (error)
3848 4e8d6e3e 2020-02-14 tracey goto done;
3849 f2f46662 2020-01-23 tracey } else if (obj_type != GOT_OBJ_TYPE_COMMIT) {
3850 f2f46662 2020-01-23 tracey error = got_error(GOT_ERR_OBJ_TYPE);
3851 4e8d6e3e 2020-02-14 tracey goto done;
3852 f2f46662 2020-01-23 tracey }
3853 f2f46662 2020-01-23 tracey }
3854 3c245a0e 2020-02-14 tracey error = got_repo_match_object_id_prefix(&id,
3855 56997cd3 2020-02-14 tracey gw_trans->commit_id, GOT_OBJ_TYPE_COMMIT,
3856 deac617c 2020-02-14 tracey gw_trans->repo);
3857 122f3af5 2020-02-14 stsp if (error)
3858 4e8d6e3e 2020-02-14 tracey goto done;
3859 f2f46662 2020-01-23 tracey }
3860 f2f46662 2020-01-23 tracey
3861 deac617c 2020-02-14 tracey error = got_repo_map_path(&in_repo_path, gw_trans->repo,
3862 8b4e047e 2020-11-15 stsp gw_trans->repo_path);
3863 f2f46662 2020-01-23 tracey if (error)
3864 4e8d6e3e 2020-02-14 tracey goto done;
3865 f2f46662 2020-01-23 tracey
3866 f2f46662 2020-01-23 tracey if (in_repo_path) {
3867 d1635ae4 2020-02-13 tracey header->path = strdup(in_repo_path);
3868 d1635ae4 2020-02-13 tracey if (header->path == NULL) {
3869 d1635ae4 2020-02-13 tracey error = got_error_from_errno("strdup");
3870 4e8d6e3e 2020-02-14 tracey goto done;
3871 a942aa37 2020-02-10 tracey }
3872 f2f46662 2020-01-23 tracey }
3873 f2f46662 2020-01-23 tracey
3874 deac617c 2020-02-14 tracey error = got_ref_list(&header->refs, gw_trans->repo, NULL,
3875 f2f46662 2020-01-23 tracey got_ref_cmp_by_name, NULL);
3876 f2f46662 2020-01-23 tracey if (error)
3877 4e8d6e3e 2020-02-14 tracey goto done;
3878 f2f46662 2020-01-23 tracey
3879 3c245a0e 2020-02-14 tracey error = gw_get_commits(gw_trans, header, limit, id);
3880 4e8d6e3e 2020-02-14 tracey done:
3881 3c245a0e 2020-02-14 tracey free(id);
3882 4e8d6e3e 2020-02-14 tracey free(in_repo_path);
3883 f2f46662 2020-01-23 tracey return error;
3884 ec46ccd7 2020-01-15 tracey }
3885 ec46ccd7 2020-01-15 tracey
3886 ec46ccd7 2020-01-15 tracey struct blame_line {
3887 ec46ccd7 2020-01-15 tracey int annotated;
3888 ec46ccd7 2020-01-15 tracey char *id_str;
3889 ec46ccd7 2020-01-15 tracey char *committer;
3890 ec46ccd7 2020-01-15 tracey char datebuf[11]; /* YYYY-MM-DD + NUL */
3891 ec46ccd7 2020-01-15 tracey };
3892 ec46ccd7 2020-01-15 tracey
3893 147269d5 2020-01-15 tracey struct gw_blame_cb_args {
3894 ec46ccd7 2020-01-15 tracey struct blame_line *lines;
3895 ec46ccd7 2020-01-15 tracey int nlines;
3896 ec46ccd7 2020-01-15 tracey int nlines_prec;
3897 ec46ccd7 2020-01-15 tracey int lineno_cur;
3898 ec46ccd7 2020-01-15 tracey off_t *line_offsets;
3899 ec46ccd7 2020-01-15 tracey FILE *f;
3900 ec46ccd7 2020-01-15 tracey struct got_repository *repo;
3901 54415d85 2020-01-15 tracey struct gw_trans *gw_trans;
3902 ec46ccd7 2020-01-15 tracey };
3903 ec46ccd7 2020-01-15 tracey
3904 ec46ccd7 2020-01-15 tracey static const struct got_error *
3905 10f173fe 2022-04-16 thomas gw_blame_cb(void *arg, int nlines, int lineno,
3906 10f173fe 2022-04-16 thomas struct got_commit_object *commit, struct got_object_id *id)
3907 ec46ccd7 2020-01-15 tracey {
3908 ec46ccd7 2020-01-15 tracey const struct got_error *err = NULL;
3909 147269d5 2020-01-15 tracey struct gw_blame_cb_args *a = arg;
3910 ec46ccd7 2020-01-15 tracey struct blame_line *bline;
3911 ec46ccd7 2020-01-15 tracey char *line = NULL;
3912 9a9d12ca 2020-02-06 tracey size_t linesize = 0;
3913 ec46ccd7 2020-01-15 tracey off_t offset;
3914 ec46ccd7 2020-01-15 tracey struct tm tm;
3915 ec46ccd7 2020-01-15 tracey time_t committer_time;
3916 9a9d12ca 2020-02-06 tracey enum kcgi_err kerr = KCGI_OK;
3917 ec46ccd7 2020-01-15 tracey
3918 ec46ccd7 2020-01-15 tracey if (nlines != a->nlines ||
3919 ec46ccd7 2020-01-15 tracey (lineno != -1 && lineno < 1) || lineno > a->nlines)
3920 ec46ccd7 2020-01-15 tracey return got_error(GOT_ERR_RANGE);
3921 ec46ccd7 2020-01-15 tracey
3922 ec46ccd7 2020-01-15 tracey if (lineno == -1)
3923 ec46ccd7 2020-01-15 tracey return NULL; /* no change in this commit */
3924 ec46ccd7 2020-01-15 tracey
3925 ec46ccd7 2020-01-15 tracey /* Annotate this line. */
3926 ec46ccd7 2020-01-15 tracey bline = &a->lines[lineno - 1];
3927 ec46ccd7 2020-01-15 tracey if (bline->annotated)
3928 ec46ccd7 2020-01-15 tracey return NULL;
3929 ec46ccd7 2020-01-15 tracey err = got_object_id_str(&bline->id_str, id);
3930 ec46ccd7 2020-01-15 tracey if (err)
3931 ec46ccd7 2020-01-15 tracey return err;
3932 ec46ccd7 2020-01-15 tracey
3933 d1635ae4 2020-02-13 tracey bline->committer = strdup(got_object_commit_get_committer(commit));
3934 d1635ae4 2020-02-13 tracey if (bline->committer == NULL) {
3935 d1635ae4 2020-02-13 tracey err = got_error_from_errno("strdup");
3936 ec46ccd7 2020-01-15 tracey goto done;
3937 d1635ae4 2020-02-13 tracey }
3938 ec46ccd7 2020-01-15 tracey
3939 ec46ccd7 2020-01-15 tracey committer_time = got_object_commit_get_committer_time(commit);
3940 e385fc42 2021-08-30 stsp if (gmtime_r(&committer_time, &tm) == NULL)
3941 e385fc42 2021-08-30 stsp return got_error_from_errno("gmtime_r");
3942 ec46ccd7 2020-01-15 tracey if (strftime(bline->datebuf, sizeof(bline->datebuf), "%G-%m-%d",
3943 ec6d1a36 2021-03-21 jrick &tm) == 0) {
3944 ec46ccd7 2020-01-15 tracey err = got_error(GOT_ERR_NO_SPACE);
3945 ec46ccd7 2020-01-15 tracey goto done;
3946 ec46ccd7 2020-01-15 tracey }
3947 ec46ccd7 2020-01-15 tracey bline->annotated = 1;
3948 ec46ccd7 2020-01-15 tracey
3949 ec46ccd7 2020-01-15 tracey /* Print lines annotated so far. */
3950 ec46ccd7 2020-01-15 tracey bline = &a->lines[a->lineno_cur - 1];
3951 ec46ccd7 2020-01-15 tracey if (!bline->annotated)
3952 ec46ccd7 2020-01-15 tracey goto done;
3953 ec46ccd7 2020-01-15 tracey
3954 ec46ccd7 2020-01-15 tracey offset = a->line_offsets[a->lineno_cur - 1];
3955 ec46ccd7 2020-01-15 tracey if (fseeko(a->f, offset, SEEK_SET) == -1) {
3956 ec46ccd7 2020-01-15 tracey err = got_error_from_errno("fseeko");
3957 ec46ccd7 2020-01-15 tracey goto done;
3958 ec46ccd7 2020-01-15 tracey }
3959 ec46ccd7 2020-01-15 tracey
3960 ec46ccd7 2020-01-15 tracey while (bline->annotated) {
3961 9a9d12ca 2020-02-06 tracey char *smallerthan, *at, *nl, *committer;
3962 32b9f7ed 2020-04-14 tracey char *href_diff = NULL;
3963 ec46ccd7 2020-01-15 tracey size_t len;
3964 ec46ccd7 2020-01-15 tracey
3965 ec46ccd7 2020-01-15 tracey if (getline(&line, &linesize, a->f) == -1) {
3966 ec46ccd7 2020-01-15 tracey if (ferror(a->f))
3967 ec46ccd7 2020-01-15 tracey err = got_error_from_errno("getline");
3968 ec46ccd7 2020-01-15 tracey break;
3969 ec46ccd7 2020-01-15 tracey }
3970 ec46ccd7 2020-01-15 tracey
3971 ec46ccd7 2020-01-15 tracey committer = bline->committer;
3972 ec46ccd7 2020-01-15 tracey smallerthan = strchr(committer, '<');
3973 ec46ccd7 2020-01-15 tracey if (smallerthan && smallerthan[1] != '\0')
3974 ec46ccd7 2020-01-15 tracey committer = smallerthan + 1;
3975 ec46ccd7 2020-01-15 tracey at = strchr(committer, '@');
3976 ec46ccd7 2020-01-15 tracey if (at)
3977 ec46ccd7 2020-01-15 tracey *at = '\0';
3978 ec46ccd7 2020-01-15 tracey len = strlen(committer);
3979 ec46ccd7 2020-01-15 tracey if (len >= 9)
3980 ec46ccd7 2020-01-15 tracey committer[8] = '\0';
3981 ec46ccd7 2020-01-15 tracey
3982 ec46ccd7 2020-01-15 tracey nl = strchr(line, '\n');
3983 ec46ccd7 2020-01-15 tracey if (nl)
3984 ec46ccd7 2020-01-15 tracey *nl = '\0';
3985 0311ce2d 2020-01-15 tracey
3986 9a9d12ca 2020-02-06 tracey kerr = khtml_attr(a->gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
3987 9a9d12ca 2020-02-06 tracey "blame_wrapper", KATTR__MAX);
3988 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
3989 9a9d12ca 2020-02-06 tracey goto err;
3990 9a9d12ca 2020-02-06 tracey kerr = khtml_attr(a->gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
3991 9a9d12ca 2020-02-06 tracey "blame_number", KATTR__MAX);
3992 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
3993 9a9d12ca 2020-02-06 tracey goto err;
3994 32b9f7ed 2020-04-14 tracey kerr = khtml_printf(a->gw_trans->gw_html_req, "%.*d",
3995 32b9f7ed 2020-04-14 tracey a->nlines_prec, a->lineno_cur);
3996 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
3997 9a9d12ca 2020-02-06 tracey goto err;
3998 9a9d12ca 2020-02-06 tracey kerr = khtml_closeelem(a->gw_trans->gw_html_req, 1);
3999 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
4000 9a9d12ca 2020-02-06 tracey goto err;
4001 9a9d12ca 2020-02-06 tracey
4002 9a9d12ca 2020-02-06 tracey kerr = khtml_attr(a->gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
4003 9a9d12ca 2020-02-06 tracey "blame_hash", KATTR__MAX);
4004 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
4005 9a9d12ca 2020-02-06 tracey goto err;
4006 1b33afc0 2020-02-14 tracey
4007 ebc6542a 2020-04-14 tracey href_diff = khttp_urlpart(NULL, NULL, "gotweb", "path",
4008 ebc6542a 2020-04-14 tracey a->gw_trans->repo_name, "action", "diff", "commit",
4009 ebc6542a 2020-04-14 tracey bline->id_str, NULL);
4010 19ff7638 2020-04-14 tracey if (href_diff == NULL) {
4011 19ff7638 2020-04-14 tracey err = got_error_from_errno("khttp_urlpart");
4012 19ff7638 2020-04-14 tracey goto done;
4013 19ff7638 2020-04-14 tracey }
4014 9a9d12ca 2020-02-06 tracey kerr = khtml_attr(a->gw_trans->gw_html_req, KELEM_A,
4015 9a9d12ca 2020-02-06 tracey KATTR_HREF, href_diff, KATTR__MAX);
4016 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
4017 9a9d12ca 2020-02-06 tracey goto done;
4018 32b9f7ed 2020-04-14 tracey kerr = khtml_printf(a->gw_trans->gw_html_req, "%.8s",
4019 32b9f7ed 2020-04-14 tracey bline->id_str);
4020 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
4021 9a9d12ca 2020-02-06 tracey goto err;
4022 9a9d12ca 2020-02-06 tracey kerr = khtml_closeelem(a->gw_trans->gw_html_req, 2);
4023 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
4024 9a9d12ca 2020-02-06 tracey goto err;
4025 2e676fc5 2020-01-15 tracey
4026 9a9d12ca 2020-02-06 tracey kerr = khtml_attr(a->gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
4027 9a9d12ca 2020-02-06 tracey "blame_date", KATTR__MAX);
4028 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
4029 9a9d12ca 2020-02-06 tracey goto err;
4030 9a9d12ca 2020-02-06 tracey kerr = khtml_puts(a->gw_trans->gw_html_req, bline->datebuf);
4031 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
4032 9a9d12ca 2020-02-06 tracey goto err;
4033 9a9d12ca 2020-02-06 tracey kerr = khtml_closeelem(a->gw_trans->gw_html_req, 1);
4034 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
4035 9a9d12ca 2020-02-06 tracey goto err;
4036 9a9d12ca 2020-02-06 tracey
4037 9a9d12ca 2020-02-06 tracey kerr = khtml_attr(a->gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
4038 9a9d12ca 2020-02-06 tracey "blame_author", KATTR__MAX);
4039 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
4040 9a9d12ca 2020-02-06 tracey goto err;
4041 9a9d12ca 2020-02-06 tracey kerr = khtml_puts(a->gw_trans->gw_html_req, committer);
4042 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
4043 9a9d12ca 2020-02-06 tracey goto err;
4044 9a9d12ca 2020-02-06 tracey kerr = khtml_closeelem(a->gw_trans->gw_html_req, 1);
4045 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
4046 9a9d12ca 2020-02-06 tracey goto err;
4047 9a9d12ca 2020-02-06 tracey
4048 9a9d12ca 2020-02-06 tracey kerr = khtml_attr(a->gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
4049 9a9d12ca 2020-02-06 tracey "blame_code", KATTR__MAX);
4050 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
4051 9a9d12ca 2020-02-06 tracey goto err;
4052 9a9d12ca 2020-02-06 tracey kerr = khtml_puts(a->gw_trans->gw_html_req, line);
4053 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
4054 9a9d12ca 2020-02-06 tracey goto err;
4055 9a9d12ca 2020-02-06 tracey kerr = khtml_closeelem(a->gw_trans->gw_html_req, 1);
4056 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
4057 9a9d12ca 2020-02-06 tracey goto err;
4058 9a9d12ca 2020-02-06 tracey
4059 9a9d12ca 2020-02-06 tracey kerr = khtml_closeelem(a->gw_trans->gw_html_req, 1);
4060 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
4061 9a9d12ca 2020-02-06 tracey goto err;
4062 9a9d12ca 2020-02-06 tracey
4063 9a9d12ca 2020-02-06 tracey a->lineno_cur++;
4064 ec46ccd7 2020-01-15 tracey bline = &a->lines[a->lineno_cur - 1];
4065 de6bdba4 2020-01-31 tracey err:
4066 9a9d12ca 2020-02-06 tracey free(href_diff);
4067 ec46ccd7 2020-01-15 tracey }
4068 ec46ccd7 2020-01-15 tracey done:
4069 ec46ccd7 2020-01-15 tracey free(line);
4070 9a9d12ca 2020-02-06 tracey if (err == NULL && kerr != KCGI_OK)
4071 9a9d12ca 2020-02-06 tracey err = gw_kcgi_error(kerr);
4072 ec46ccd7 2020-01-15 tracey return err;
4073 872742ce 2020-02-01 stsp }
4074 872742ce 2020-02-01 stsp
4075 a81f3554 2020-02-03 stsp static const struct got_error *
4076 84de9106 2020-12-26 stsp gw_output_file_blame(struct gw_trans *gw_trans, struct gw_header *header)
4077 bcbc97d8 2020-01-15 tracey {
4078 bcbc97d8 2020-01-15 tracey const struct got_error *error = NULL;
4079 ec46ccd7 2020-01-15 tracey struct got_object_id *obj_id = NULL;
4080 ec46ccd7 2020-01-15 tracey struct got_object_id *commit_id = NULL;
4081 945f9229 2022-04-16 thomas struct got_commit_object *commit = NULL;
4082 ec46ccd7 2020-01-15 tracey struct got_blob_object *blob = NULL;
4083 a81f3554 2020-02-03 stsp char *path = NULL, *in_repo_path = NULL;
4084 147269d5 2020-01-15 tracey struct gw_blame_cb_args bca;
4085 9117a7b7 2022-07-01 thomas int i, obj_type, fd1 = -1, fd2 = -1, fd3 = -1;
4086 be659d10 2020-11-18 stsp off_t filesize;
4087 9117a7b7 2022-07-01 thomas FILE *f1 = NULL, *f2 = NULL;
4088 f4ae6ddb 2022-07-01 thomas
4089 9117a7b7 2022-07-01 thomas fd1 = got_opentempfd();
4090 9117a7b7 2022-07-01 thomas if (fd1 == -1)
4091 f4ae6ddb 2022-07-01 thomas return got_error_from_errno("got_opentempfd");
4092 9117a7b7 2022-07-01 thomas fd2 = got_opentempfd();
4093 9117a7b7 2022-07-01 thomas if (fd2 == -1) {
4094 9117a7b7 2022-07-01 thomas error = got_error_from_errno("got_opentempfd");
4095 9117a7b7 2022-07-01 thomas goto done;
4096 9117a7b7 2022-07-01 thomas }
4097 9117a7b7 2022-07-01 thomas fd3 = got_opentempfd();
4098 9117a7b7 2022-07-01 thomas if (fd3 == -1) {
4099 9117a7b7 2022-07-01 thomas error = got_error_from_errno("got_opentempfd");
4100 9117a7b7 2022-07-01 thomas goto done;
4101 9117a7b7 2022-07-01 thomas }
4102 d7c94b2b 2022-03-22 thomas
4103 d7c94b2b 2022-03-22 thomas memset(&bca, 0, sizeof(bca));
4104 ec46ccd7 2020-01-15 tracey
4105 a81f3554 2020-02-03 stsp if (asprintf(&path, "%s%s%s",
4106 a81f3554 2020-02-03 stsp gw_trans->repo_folder ? gw_trans->repo_folder : "",
4107 4fd4726a 2020-02-03 stsp gw_trans->repo_folder ? "/" : "",
4108 a81f3554 2020-02-03 stsp gw_trans->repo_file) == -1) {
4109 2e676fc5 2020-01-15 tracey error = got_error_from_errno("asprintf");
4110 2e676fc5 2020-01-15 tracey goto done;
4111 2e676fc5 2020-01-15 tracey }
4112 2e676fc5 2020-01-15 tracey
4113 8b4e047e 2020-11-15 stsp error = got_repo_map_path(&in_repo_path, gw_trans->repo, path);
4114 ec46ccd7 2020-01-15 tracey if (error)
4115 ec46ccd7 2020-01-15 tracey goto done;
4116 ec46ccd7 2020-01-15 tracey
4117 56997cd3 2020-02-14 tracey error = got_repo_match_object_id(&commit_id, NULL, gw_trans->commit_id,
4118 84de9106 2020-12-26 stsp GOT_OBJ_TYPE_COMMIT, &header->refs, gw_trans->repo);
4119 ec46ccd7 2020-01-15 tracey if (error)
4120 ec46ccd7 2020-01-15 tracey goto done;
4121 ec46ccd7 2020-01-15 tracey
4122 945f9229 2022-04-16 thomas error = got_object_open_as_commit(&commit, gw_trans->repo, commit_id);
4123 945f9229 2022-04-16 thomas if (error)
4124 945f9229 2022-04-16 thomas goto done;
4125 945f9229 2022-04-16 thomas
4126 945f9229 2022-04-16 thomas error = got_object_id_by_path(&obj_id, gw_trans->repo, commit,
4127 deac617c 2020-02-14 tracey in_repo_path);
4128 ec46ccd7 2020-01-15 tracey if (error)
4129 ec46ccd7 2020-01-15 tracey goto done;
4130 2e676fc5 2020-01-15 tracey
4131 ec46ccd7 2020-01-15 tracey if (obj_id == NULL) {
4132 ec46ccd7 2020-01-15 tracey error = got_error(GOT_ERR_NO_OBJ);
4133 ec46ccd7 2020-01-15 tracey goto done;
4134 ec46ccd7 2020-01-15 tracey }
4135 ec46ccd7 2020-01-15 tracey
4136 deac617c 2020-02-14 tracey error = got_object_get_type(&obj_type, gw_trans->repo, obj_id);
4137 ec46ccd7 2020-01-15 tracey if (error)
4138 ec46ccd7 2020-01-15 tracey goto done;
4139 ec46ccd7 2020-01-15 tracey
4140 ec46ccd7 2020-01-15 tracey if (obj_type != GOT_OBJ_TYPE_BLOB) {
4141 ec46ccd7 2020-01-15 tracey error = got_error(GOT_ERR_OBJ_TYPE);
4142 ec46ccd7 2020-01-15 tracey goto done;
4143 ec46ccd7 2020-01-15 tracey }
4144 ec46ccd7 2020-01-15 tracey
4145 f4ae6ddb 2022-07-01 thomas error = got_object_open_as_blob(&blob, gw_trans->repo, obj_id, 8192,
4146 9117a7b7 2022-07-01 thomas fd1);
4147 ec46ccd7 2020-01-15 tracey if (error)
4148 ec46ccd7 2020-01-15 tracey goto done;
4149 ec46ccd7 2020-01-15 tracey
4150 ec46ccd7 2020-01-15 tracey bca.f = got_opentemp();
4151 ec46ccd7 2020-01-15 tracey if (bca.f == NULL) {
4152 ec46ccd7 2020-01-15 tracey error = got_error_from_errno("got_opentemp");
4153 ec46ccd7 2020-01-15 tracey goto done;
4154 ec46ccd7 2020-01-15 tracey }
4155 ec46ccd7 2020-01-15 tracey error = got_object_blob_dump_to_file(&filesize, &bca.nlines,
4156 ec46ccd7 2020-01-15 tracey &bca.line_offsets, bca.f, blob);
4157 ec46ccd7 2020-01-15 tracey if (error || bca.nlines == 0)
4158 ec46ccd7 2020-01-15 tracey goto done;
4159 a81f3554 2020-02-03 stsp
4160 ec46ccd7 2020-01-15 tracey /* Don't include \n at EOF in the blame line count. */
4161 ec46ccd7 2020-01-15 tracey if (bca.line_offsets[bca.nlines - 1] == filesize)
4162 ec46ccd7 2020-01-15 tracey bca.nlines--;
4163 ec46ccd7 2020-01-15 tracey
4164 ec46ccd7 2020-01-15 tracey bca.lines = calloc(bca.nlines, sizeof(*bca.lines));
4165 ec46ccd7 2020-01-15 tracey if (bca.lines == NULL) {
4166 ec46ccd7 2020-01-15 tracey error = got_error_from_errno("calloc");
4167 ec46ccd7 2020-01-15 tracey goto done;
4168 ec46ccd7 2020-01-15 tracey }
4169 ec46ccd7 2020-01-15 tracey bca.lineno_cur = 1;
4170 ec46ccd7 2020-01-15 tracey bca.nlines_prec = 0;
4171 ec46ccd7 2020-01-15 tracey i = bca.nlines;
4172 ec46ccd7 2020-01-15 tracey while (i > 0) {
4173 ec46ccd7 2020-01-15 tracey i /= 10;
4174 ec46ccd7 2020-01-15 tracey bca.nlines_prec++;
4175 ec46ccd7 2020-01-15 tracey }
4176 deac617c 2020-02-14 tracey bca.repo = gw_trans->repo;
4177 2e676fc5 2020-01-15 tracey bca.gw_trans = gw_trans;
4178 ec46ccd7 2020-01-15 tracey
4179 00a8878e 2022-07-01 thomas fd1 = got_opentempfd();
4180 00a8878e 2022-07-01 thomas if (fd1 == -1) {
4181 9117a7b7 2022-07-01 thomas error = got_error_from_errno("got_opentempfd");
4182 9117a7b7 2022-07-01 thomas goto done;
4183 9117a7b7 2022-07-01 thomas }
4184 9117a7b7 2022-07-01 thomas
4185 9117a7b7 2022-07-01 thomas f1 = got_opentemp();
4186 9117a7b7 2022-07-01 thomas if (f1 == NULL) {
4187 00a8878e 2022-07-01 thomas error = got_error_from_errno("got_opentempfd");
4188 00a8878e 2022-07-01 thomas goto done;
4189 00a8878e 2022-07-01 thomas }
4190 9117a7b7 2022-07-01 thomas f2 = got_opentemp();
4191 9117a7b7 2022-07-01 thomas if (f2 == NULL) {
4192 9117a7b7 2022-07-01 thomas error = got_error_from_errno("got_opentempfd");
4193 9117a7b7 2022-07-01 thomas goto done;
4194 9117a7b7 2022-07-01 thomas }
4195 00a8878e 2022-07-01 thomas
4196 deac617c 2020-02-14 tracey error = got_blame(in_repo_path, commit_id, gw_trans->repo, gw_blame_cb,
4197 9117a7b7 2022-07-01 thomas &bca, NULL, NULL, fd2, fd3, f1, f2);
4198 ec46ccd7 2020-01-15 tracey done:
4199 2e676fc5 2020-01-15 tracey free(in_repo_path);
4200 2e676fc5 2020-01-15 tracey free(commit_id);
4201 2e676fc5 2020-01-15 tracey free(obj_id);
4202 2e676fc5 2020-01-15 tracey free(path);
4203 2e676fc5 2020-01-15 tracey
4204 00a8878e 2022-07-01 thomas if (fd1 != -1 && close(fd1) == -1 && error == NULL)
4205 9117a7b7 2022-07-01 thomas error = got_error_from_errno("close");
4206 9117a7b7 2022-07-01 thomas if (fd2 != -1 && close(fd2) == -1 && error == NULL)
4207 9117a7b7 2022-07-01 thomas error = got_error_from_errno("close");
4208 9117a7b7 2022-07-01 thomas if (fd3 != -1 && close(fd3) == -1 && error == NULL)
4209 00a8878e 2022-07-01 thomas error = got_error_from_errno("close");
4210 9117a7b7 2022-07-01 thomas if (f1 && fclose(f1) == EOF && error == NULL)
4211 9117a7b7 2022-07-01 thomas error = got_error_from_errno("fclose");
4212 9117a7b7 2022-07-01 thomas if (f2 && fclose(f2) == EOF && error == NULL)
4213 9117a7b7 2022-07-01 thomas error = got_error_from_errno("fclose");
4214 00a8878e 2022-07-01 thomas
4215 1b33afc0 2020-02-14 tracey if (blob) {
4216 1b33afc0 2020-02-14 tracey free(bca.line_offsets);
4217 1b33afc0 2020-02-14 tracey for (i = 0; i < bca.nlines; i++) {
4218 1b33afc0 2020-02-14 tracey struct blame_line *bline = &bca.lines[i];
4219 1b33afc0 2020-02-14 tracey free(bline->id_str);
4220 1b33afc0 2020-02-14 tracey free(bline->committer);
4221 1b33afc0 2020-02-14 tracey }
4222 1b33afc0 2020-02-14 tracey free(bca.lines);
4223 1b33afc0 2020-02-14 tracey if (bca.f && fclose(bca.f) == EOF && error == NULL)
4224 1b33afc0 2020-02-14 tracey error = got_error_from_errno("fclose");
4225 2e676fc5 2020-01-15 tracey }
4226 4fd4726a 2020-02-03 stsp if (blob)
4227 4fd4726a 2020-02-03 stsp got_object_blob_close(blob);
4228 945f9229 2022-04-16 thomas if (commit)
4229 945f9229 2022-04-16 thomas got_object_commit_close(commit);
4230 4fd4726a 2020-02-03 stsp return error;
4231 4fd4726a 2020-02-03 stsp }
4232 4fd4726a 2020-02-03 stsp
4233 4fd4726a 2020-02-03 stsp static const struct got_error *
4234 84de9106 2020-12-26 stsp gw_output_blob_buf(struct gw_trans *gw_trans, struct gw_header *header)
4235 4fd4726a 2020-02-03 stsp {
4236 4fd4726a 2020-02-03 stsp const struct got_error *error = NULL;
4237 4fd4726a 2020-02-03 stsp struct got_object_id *obj_id = NULL;
4238 4fd4726a 2020-02-03 stsp struct got_object_id *commit_id = NULL;
4239 945f9229 2022-04-16 thomas struct got_commit_object *commit = NULL;
4240 4fd4726a 2020-02-03 stsp struct got_blob_object *blob = NULL;
4241 4fd4726a 2020-02-03 stsp char *path = NULL, *in_repo_path = NULL;
4242 f4ae6ddb 2022-07-01 thomas int obj_type, set_mime = 0, fd = -1;
4243 e0857cfe 2020-02-06 tracey size_t len, hdrlen;
4244 e0857cfe 2020-02-06 tracey const uint8_t *buf;
4245 e0857cfe 2020-02-06 tracey enum kcgi_err kerr = KCGI_OK;
4246 4fd4726a 2020-02-03 stsp
4247 f4ae6ddb 2022-07-01 thomas fd = got_opentempfd();
4248 f4ae6ddb 2022-07-01 thomas if (fd == -1)
4249 f4ae6ddb 2022-07-01 thomas return got_error_from_errno("got_opentempfd");
4250 f4ae6ddb 2022-07-01 thomas
4251 4fd4726a 2020-02-03 stsp if (asprintf(&path, "%s%s%s",
4252 4fd4726a 2020-02-03 stsp gw_trans->repo_folder ? gw_trans->repo_folder : "",
4253 4fd4726a 2020-02-03 stsp gw_trans->repo_folder ? "/" : "",
4254 4fd4726a 2020-02-03 stsp gw_trans->repo_file) == -1) {
4255 4fd4726a 2020-02-03 stsp error = got_error_from_errno("asprintf");
4256 4fd4726a 2020-02-03 stsp goto done;
4257 4fd4726a 2020-02-03 stsp }
4258 4fd4726a 2020-02-03 stsp
4259 8b4e047e 2020-11-15 stsp error = got_repo_map_path(&in_repo_path, gw_trans->repo, path);
4260 4fd4726a 2020-02-03 stsp if (error)
4261 4fd4726a 2020-02-03 stsp goto done;
4262 4fd4726a 2020-02-03 stsp
4263 56997cd3 2020-02-14 tracey error = got_repo_match_object_id(&commit_id, NULL, gw_trans->commit_id,
4264 84de9106 2020-12-26 stsp GOT_OBJ_TYPE_COMMIT, &header->refs, gw_trans->repo);
4265 4fd4726a 2020-02-03 stsp if (error)
4266 4fd4726a 2020-02-03 stsp goto done;
4267 4fd4726a 2020-02-03 stsp
4268 945f9229 2022-04-16 thomas error = got_object_open_as_commit(&commit, gw_trans->repo, commit_id);
4269 945f9229 2022-04-16 thomas if (error)
4270 945f9229 2022-04-16 thomas goto done;
4271 945f9229 2022-04-16 thomas
4272 945f9229 2022-04-16 thomas error = got_object_id_by_path(&obj_id, gw_trans->repo, commit,
4273 deac617c 2020-02-14 tracey in_repo_path);
4274 4fd4726a 2020-02-03 stsp if (error)
4275 4fd4726a 2020-02-03 stsp goto done;
4276 4fd4726a 2020-02-03 stsp
4277 4fd4726a 2020-02-03 stsp if (obj_id == NULL) {
4278 4fd4726a 2020-02-03 stsp error = got_error(GOT_ERR_NO_OBJ);
4279 4fd4726a 2020-02-03 stsp goto done;
4280 4fd4726a 2020-02-03 stsp }
4281 4fd4726a 2020-02-03 stsp
4282 deac617c 2020-02-14 tracey error = got_object_get_type(&obj_type, gw_trans->repo, obj_id);
4283 4fd4726a 2020-02-03 stsp if (error)
4284 4fd4726a 2020-02-03 stsp goto done;
4285 4fd4726a 2020-02-03 stsp
4286 4fd4726a 2020-02-03 stsp if (obj_type != GOT_OBJ_TYPE_BLOB) {
4287 4fd4726a 2020-02-03 stsp error = got_error(GOT_ERR_OBJ_TYPE);
4288 4fd4726a 2020-02-03 stsp goto done;
4289 4fd4726a 2020-02-03 stsp }
4290 4fd4726a 2020-02-03 stsp
4291 f4ae6ddb 2022-07-01 thomas error = got_object_open_as_blob(&blob, gw_trans->repo, obj_id, 8192,
4292 f4ae6ddb 2022-07-01 thomas fd);
4293 4fd4726a 2020-02-03 stsp if (error)
4294 4fd4726a 2020-02-03 stsp goto done;
4295 4fd4726a 2020-02-03 stsp
4296 e0857cfe 2020-02-06 tracey hdrlen = got_object_blob_get_hdrlen(blob);
4297 e0857cfe 2020-02-06 tracey do {
4298 e0857cfe 2020-02-06 tracey error = got_object_blob_read_block(&len, blob);
4299 e0857cfe 2020-02-06 tracey if (error)
4300 e0857cfe 2020-02-06 tracey goto done;
4301 e0857cfe 2020-02-06 tracey buf = got_object_blob_get_read_buf(blob);
4302 4fd4726a 2020-02-03 stsp
4303 e0857cfe 2020-02-06 tracey /*
4304 e0857cfe 2020-02-06 tracey * Skip blob object header first time around,
4305 e0857cfe 2020-02-06 tracey * which also contains a zero byte.
4306 e0857cfe 2020-02-06 tracey */
4307 e0857cfe 2020-02-06 tracey buf += hdrlen;
4308 e0857cfe 2020-02-06 tracey if (set_mime == 0) {
4309 e0857cfe 2020-02-06 tracey if (isbinary(buf, len - hdrlen))
4310 e0857cfe 2020-02-06 tracey gw_trans->mime = KMIME_APP_OCTET_STREAM;
4311 e0857cfe 2020-02-06 tracey else
4312 e0857cfe 2020-02-06 tracey gw_trans->mime = KMIME_TEXT_PLAIN;
4313 e0857cfe 2020-02-06 tracey set_mime = 1;
4314 e0857cfe 2020-02-06 tracey error = gw_display_index(gw_trans);
4315 e0857cfe 2020-02-06 tracey if (error)
4316 e0857cfe 2020-02-06 tracey goto done;
4317 e0857cfe 2020-02-06 tracey }
4318 3b7fdcf4 2020-02-14 tracey kerr = khttp_write(gw_trans->gw_req, buf, len - hdrlen);
4319 c56af3fd 2020-02-17 stsp if (kerr != KCGI_OK)
4320 c56af3fd 2020-02-17 stsp goto done;
4321 e0857cfe 2020-02-06 tracey hdrlen = 0;
4322 e0857cfe 2020-02-06 tracey } while (len != 0);
4323 4fd4726a 2020-02-03 stsp done:
4324 4fd4726a 2020-02-03 stsp free(in_repo_path);
4325 4fd4726a 2020-02-03 stsp free(commit_id);
4326 4fd4726a 2020-02-03 stsp free(obj_id);
4327 4fd4726a 2020-02-03 stsp free(path);
4328 f4ae6ddb 2022-07-01 thomas if (fd != -1 && close(fd) == -1 && error == NULL)
4329 f4ae6ddb 2022-07-01 thomas error = got_error_from_errno("close");
4330 e46f587c 2020-01-29 tracey if (blob)
4331 a81f3554 2020-02-03 stsp got_object_blob_close(blob);
4332 945f9229 2022-04-16 thomas if (commit)
4333 945f9229 2022-04-16 thomas got_object_commit_close(commit);
4334 e0857cfe 2020-02-06 tracey if (error == NULL && kerr != KCGI_OK)
4335 e0857cfe 2020-02-06 tracey error = gw_kcgi_error(kerr);
4336 a81f3554 2020-02-03 stsp return error;
4337 ec46ccd7 2020-01-15 tracey }
4338 ec46ccd7 2020-01-15 tracey
4339 84bf4df2 2020-02-03 stsp static const struct got_error *
4340 84de9106 2020-12-26 stsp gw_output_repo_tree(struct gw_trans *gw_trans, struct gw_header *header)
4341 ec46ccd7 2020-01-15 tracey {
4342 ec46ccd7 2020-01-15 tracey const struct got_error *error = NULL;
4343 bcbc97d8 2020-01-15 tracey struct got_object_id *tree_id = NULL, *commit_id = NULL;
4344 bcbc97d8 2020-01-15 tracey struct got_tree_object *tree = NULL;
4345 945f9229 2022-04-16 thomas struct got_commit_object *commit = NULL;
4346 626b25b6 2020-02-06 tracey char *path = NULL, *in_repo_path = NULL;
4347 84bf4df2 2020-02-03 stsp char *id_str = NULL;
4348 84bf4df2 2020-02-03 stsp char *build_folder = NULL;
4349 626b25b6 2020-02-06 tracey char *href_blob = NULL, *href_blame = NULL;
4350 84bf4df2 2020-02-03 stsp const char *class = NULL;
4351 c3bcdfd5 2020-01-29 tracey int nentries, i, class_flip = 0;
4352 626b25b6 2020-02-06 tracey enum kcgi_err kerr = KCGI_OK;
4353 8d4d2453 2020-01-15 tracey
4354 a942aa37 2020-02-10 tracey if (gw_trans->repo_folder != NULL) {
4355 d1635ae4 2020-02-13 tracey path = strdup(gw_trans->repo_folder);
4356 d1635ae4 2020-02-13 tracey if (path == NULL) {
4357 d1635ae4 2020-02-13 tracey error = got_error_from_errno("strdup");
4358 a942aa37 2020-02-10 tracey goto done;
4359 d1635ae4 2020-02-13 tracey }
4360 a942aa37 2020-02-10 tracey } else {
4361 deac617c 2020-02-14 tracey error = got_repo_map_path(&in_repo_path, gw_trans->repo,
4362 8b4e047e 2020-11-15 stsp gw_trans->repo_path);
4363 84bf4df2 2020-02-03 stsp if (error)
4364 84bf4df2 2020-02-03 stsp goto done;
4365 bcbc97d8 2020-01-15 tracey free(path);
4366 bcbc97d8 2020-01-15 tracey path = in_repo_path;
4367 bcbc97d8 2020-01-15 tracey }
4368 bcbc97d8 2020-01-15 tracey
4369 56997cd3 2020-02-14 tracey if (gw_trans->commit_id == NULL) {
4370 ec46ccd7 2020-01-15 tracey struct got_reference *head_ref;
4371 deac617c 2020-02-14 tracey error = got_ref_open(&head_ref, gw_trans->repo,
4372 deac617c 2020-02-14 tracey gw_trans->headref, 0);
4373 ec46ccd7 2020-01-15 tracey if (error)
4374 ec46ccd7 2020-01-15 tracey goto done;
4375 deac617c 2020-02-14 tracey error = got_ref_resolve(&commit_id, gw_trans->repo, head_ref);
4376 84bf4df2 2020-02-03 stsp if (error)
4377 84bf4df2 2020-02-03 stsp goto done;
4378 ec46ccd7 2020-01-15 tracey got_ref_close(head_ref);
4379 56997cd3 2020-02-14 tracey /*
4380 56997cd3 2020-02-14 tracey * gw_trans->commit_id was not parsed from the querystring
4381 56997cd3 2020-02-14 tracey * we hit this code path from gw_index, where we don't know the
4382 56997cd3 2020-02-14 tracey * commit values for the tree link yet, so set
4383 56997cd3 2020-02-14 tracey * gw_trans->commit_id here to continue further into the tree
4384 56997cd3 2020-02-14 tracey */
4385 56997cd3 2020-02-14 tracey error = got_object_id_str(&gw_trans->commit_id, commit_id);
4386 56997cd3 2020-02-14 tracey if (error)
4387 56997cd3 2020-02-14 tracey goto done;
4388 ec46ccd7 2020-01-15 tracey
4389 84bf4df2 2020-02-03 stsp } else {
4390 f2f46662 2020-01-23 tracey error = got_repo_match_object_id(&commit_id, NULL,
4391 84de9106 2020-12-26 stsp gw_trans->commit_id, GOT_OBJ_TYPE_COMMIT, &header->refs,
4392 56997cd3 2020-02-14 tracey gw_trans->repo);
4393 84bf4df2 2020-02-03 stsp if (error)
4394 84bf4df2 2020-02-03 stsp goto done;
4395 84bf4df2 2020-02-03 stsp }
4396 f2f46662 2020-01-23 tracey
4397 945f9229 2022-04-16 thomas error = got_object_open_as_commit(&commit, gw_trans->repo, commit_id);
4398 945f9229 2022-04-16 thomas if (error)
4399 945f9229 2022-04-16 thomas goto done;
4400 945f9229 2022-04-16 thomas
4401 945f9229 2022-04-16 thomas error = got_object_id_by_path(&tree_id, gw_trans->repo, commit,
4402 56997cd3 2020-02-14 tracey path);
4403 bcbc97d8 2020-01-15 tracey if (error)
4404 bcbc97d8 2020-01-15 tracey goto done;
4405 bcbc97d8 2020-01-15 tracey
4406 deac617c 2020-02-14 tracey error = got_object_open_as_tree(&tree, gw_trans->repo, tree_id);
4407 bcbc97d8 2020-01-15 tracey if (error)
4408 bcbc97d8 2020-01-15 tracey goto done;
4409 bcbc97d8 2020-01-15 tracey
4410 bcbc97d8 2020-01-15 tracey nentries = got_object_tree_get_nentries(tree);
4411 bcbc97d8 2020-01-15 tracey for (i = 0; i < nentries; i++) {
4412 bcbc97d8 2020-01-15 tracey struct got_tree_entry *te;
4413 ec46ccd7 2020-01-15 tracey const char *modestr = "";
4414 84bf4df2 2020-02-03 stsp mode_t mode;
4415 bcbc97d8 2020-01-15 tracey
4416 bcbc97d8 2020-01-15 tracey te = got_object_tree_get_entry(tree, i);
4417 bcbc97d8 2020-01-15 tracey
4418 bcbc97d8 2020-01-15 tracey error = got_object_id_str(&id_str, got_tree_entry_get_id(te));
4419 bcbc97d8 2020-01-15 tracey if (error)
4420 bcbc97d8 2020-01-15 tracey goto done;
4421 bcbc97d8 2020-01-15 tracey
4422 84bf4df2 2020-02-03 stsp mode = got_tree_entry_get_mode(te);
4423 bcbc97d8 2020-01-15 tracey if (got_object_tree_entry_is_submodule(te))
4424 bcbc97d8 2020-01-15 tracey modestr = "$";
4425 bcbc97d8 2020-01-15 tracey else if (S_ISLNK(mode))
4426 bcbc97d8 2020-01-15 tracey modestr = "@";
4427 bcbc97d8 2020-01-15 tracey else if (S_ISDIR(mode))
4428 bcbc97d8 2020-01-15 tracey modestr = "/";
4429 bcbc97d8 2020-01-15 tracey else if (mode & S_IXUSR)
4430 bcbc97d8 2020-01-15 tracey modestr = "*";
4431 c3bcdfd5 2020-01-29 tracey
4432 c3bcdfd5 2020-01-29 tracey if (class_flip == 0) {
4433 84bf4df2 2020-02-03 stsp class = "back_lightgray";
4434 c3bcdfd5 2020-01-29 tracey class_flip = 1;
4435 c3bcdfd5 2020-01-29 tracey } else {
4436 84bf4df2 2020-02-03 stsp class = "back_white";
4437 c3bcdfd5 2020-01-29 tracey class_flip = 0;
4438 c3bcdfd5 2020-01-29 tracey }
4439 bcbc97d8 2020-01-15 tracey
4440 84bf4df2 2020-02-03 stsp if (S_ISDIR(mode)) {
4441 a5594e37 2020-02-05 tracey if (asprintf(&build_folder, "%s/%s",
4442 84bf4df2 2020-02-03 stsp gw_trans->repo_folder ? gw_trans->repo_folder : "",
4443 84bf4df2 2020-02-03 stsp got_tree_entry_get_name(te)) == -1) {
4444 53e81e48 2020-02-13 tracey error = got_error_from_errno("asprintf");
4445 84bf4df2 2020-02-03 stsp goto done;
4446 ec46ccd7 2020-01-15 tracey }
4447 626b25b6 2020-02-06 tracey
4448 c6eb96ac 2020-04-14 tracey href_blob = khttp_urlpart(NULL, NULL, "gotweb", "path",
4449 c6eb96ac 2020-04-14 tracey gw_trans->repo_name, "action",
4450 c6eb96ac 2020-04-14 tracey gw_get_action_name(gw_trans), "commit",
4451 c6eb96ac 2020-04-14 tracey gw_trans->commit_id, "folder", build_folder, NULL);
4452 19ff7638 2020-04-14 tracey if (href_blob == NULL) {
4453 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
4454 19ff7638 2020-04-14 tracey goto done;
4455 19ff7638 2020-04-14 tracey }
4456 626b25b6 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
4457 626b25b6 2020-02-06 tracey KATTR_ID, "tree_wrapper", KATTR__MAX);
4458 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4459 626b25b6 2020-02-06 tracey goto done;
4460 626b25b6 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
4461 626b25b6 2020-02-06 tracey KATTR_ID, "tree_line", KATTR_CLASS, class,
4462 626b25b6 2020-02-06 tracey KATTR__MAX);
4463 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4464 626b25b6 2020-02-06 tracey goto done;
4465 626b25b6 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
4466 626b25b6 2020-02-06 tracey KATTR_HREF, href_blob, KATTR_CLASS,
4467 626b25b6 2020-02-06 tracey "diff_directory", KATTR__MAX);
4468 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4469 626b25b6 2020-02-06 tracey goto done;
4470 32b9f7ed 2020-04-14 tracey kerr = khtml_printf(gw_trans->gw_html_req, "%s%s",
4471 32b9f7ed 2020-04-14 tracey got_tree_entry_get_name(te), modestr);
4472 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4473 626b25b6 2020-02-06 tracey goto done;
4474 626b25b6 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
4475 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4476 626b25b6 2020-02-06 tracey goto done;
4477 626b25b6 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
4478 626b25b6 2020-02-06 tracey KATTR_ID, "tree_line_blank", KATTR_CLASS, class,
4479 626b25b6 2020-02-06 tracey KATTR__MAX);
4480 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4481 84bf4df2 2020-02-03 stsp goto done;
4482 626b25b6 2020-02-06 tracey kerr = khtml_entity(gw_trans->gw_html_req,
4483 626b25b6 2020-02-06 tracey KENTITY_nbsp);
4484 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4485 626b25b6 2020-02-06 tracey goto done;
4486 626b25b6 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
4487 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4488 626b25b6 2020-02-06 tracey goto done;
4489 ec46ccd7 2020-01-15 tracey } else {
4490 c6eb96ac 2020-04-14 tracey href_blob = khttp_urlpart(NULL, NULL, "gotweb", "path",
4491 c6eb96ac 2020-04-14 tracey gw_trans->repo_name, "action", "blob", "commit",
4492 c6eb96ac 2020-04-14 tracey gw_trans->commit_id, "file",
4493 c6eb96ac 2020-04-14 tracey got_tree_entry_get_name(te), "folder",
4494 c6eb96ac 2020-04-14 tracey gw_trans->repo_folder ? gw_trans->repo_folder : "",
4495 c6eb96ac 2020-04-14 tracey NULL);
4496 19ff7638 2020-04-14 tracey if (href_blob == NULL) {
4497 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
4498 19ff7638 2020-04-14 tracey goto done;
4499 19ff7638 2020-04-14 tracey }
4500 c6eb96ac 2020-04-14 tracey href_blame = khttp_urlpart(NULL, NULL, "gotweb", "path",
4501 c6eb96ac 2020-04-14 tracey gw_trans->repo_name, "action", "blame", "commit",
4502 c6eb96ac 2020-04-14 tracey gw_trans->commit_id, "file",
4503 c6eb96ac 2020-04-14 tracey got_tree_entry_get_name(te), "folder",
4504 c6eb96ac 2020-04-14 tracey gw_trans->repo_folder ? gw_trans->repo_folder : "",
4505 c6eb96ac 2020-04-14 tracey NULL);
4506 19ff7638 2020-04-14 tracey if (href_blame == NULL) {
4507 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
4508 19ff7638 2020-04-14 tracey goto done;
4509 19ff7638 2020-04-14 tracey }
4510 626b25b6 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
4511 626b25b6 2020-02-06 tracey KATTR_ID, "tree_wrapper", KATTR__MAX);
4512 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4513 626b25b6 2020-02-06 tracey goto done;
4514 626b25b6 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
4515 626b25b6 2020-02-06 tracey KATTR_ID, "tree_line", KATTR_CLASS, class,
4516 626b25b6 2020-02-06 tracey KATTR__MAX);
4517 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4518 626b25b6 2020-02-06 tracey goto done;
4519 626b25b6 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
4520 626b25b6 2020-02-06 tracey KATTR_HREF, href_blob, KATTR__MAX);
4521 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4522 626b25b6 2020-02-06 tracey goto done;
4523 32b9f7ed 2020-04-14 tracey kerr = khtml_printf(gw_trans->gw_html_req, "%s%s",
4524 32b9f7ed 2020-04-14 tracey got_tree_entry_get_name(te), modestr);
4525 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4526 626b25b6 2020-02-06 tracey goto done;
4527 626b25b6 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
4528 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4529 626b25b6 2020-02-06 tracey goto done;
4530 626b25b6 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
4531 626b25b6 2020-02-06 tracey KATTR_ID, "tree_line_navs", KATTR_CLASS, class,
4532 626b25b6 2020-02-06 tracey KATTR__MAX);
4533 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4534 626b25b6 2020-02-06 tracey goto done;
4535 ec46ccd7 2020-01-15 tracey
4536 626b25b6 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
4537 626b25b6 2020-02-06 tracey KATTR_HREF, href_blob, KATTR__MAX);
4538 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4539 626b25b6 2020-02-06 tracey goto done;
4540 626b25b6 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req, "blob");
4541 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4542 626b25b6 2020-02-06 tracey goto done;
4543 626b25b6 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
4544 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4545 626b25b6 2020-02-06 tracey goto done;
4546 626b25b6 2020-02-06 tracey
4547 626b25b6 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req, " | ");
4548 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4549 626b25b6 2020-02-06 tracey goto done;
4550 626b25b6 2020-02-06 tracey
4551 626b25b6 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
4552 626b25b6 2020-02-06 tracey KATTR_HREF, href_blame, KATTR__MAX);
4553 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4554 626b25b6 2020-02-06 tracey goto done;
4555 626b25b6 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req, "blame");
4556 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4557 626b25b6 2020-02-06 tracey goto done;
4558 626b25b6 2020-02-06 tracey
4559 626b25b6 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 3);
4560 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4561 626b25b6 2020-02-06 tracey goto done;
4562 626b25b6 2020-02-06 tracey }
4563 bcbc97d8 2020-01-15 tracey free(id_str);
4564 84bf4df2 2020-02-03 stsp id_str = NULL;
4565 626b25b6 2020-02-06 tracey free(href_blob);
4566 626b25b6 2020-02-06 tracey href_blob = NULL;
4567 84bf4df2 2020-02-03 stsp free(build_folder);
4568 84bf4df2 2020-02-03 stsp build_folder = NULL;
4569 bcbc97d8 2020-01-15 tracey }
4570 bcbc97d8 2020-01-15 tracey done:
4571 bcbc97d8 2020-01-15 tracey if (tree)
4572 bcbc97d8 2020-01-15 tracey got_object_tree_close(tree);
4573 945f9229 2022-04-16 thomas if (commit)
4574 945f9229 2022-04-16 thomas got_object_commit_close(commit);
4575 84bf4df2 2020-02-03 stsp free(id_str);
4576 626b25b6 2020-02-06 tracey free(href_blob);
4577 626b25b6 2020-02-06 tracey free(href_blame);
4578 2e676fc5 2020-01-15 tracey free(in_repo_path);
4579 bcbc97d8 2020-01-15 tracey free(tree_id);
4580 84bf4df2 2020-02-03 stsp free(build_folder);
4581 626b25b6 2020-02-06 tracey if (error == NULL && kerr != KCGI_OK)
4582 626b25b6 2020-02-06 tracey error = gw_kcgi_error(kerr);
4583 84bf4df2 2020-02-03 stsp return error;
4584 bcbc97d8 2020-01-15 tracey }
4585 bcbc97d8 2020-01-15 tracey
4586 51d4a92d 2020-02-03 tracey static const struct got_error *
4587 9eed6f10 2020-02-08 tracey gw_output_repo_heads(struct gw_trans *gw_trans)
4588 8d4d2453 2020-01-15 tracey {
4589 87f9ebf5 2020-01-15 tracey const struct got_error *error = NULL;
4590 87f9ebf5 2020-01-15 tracey struct got_reflist_head refs;
4591 87f9ebf5 2020-01-15 tracey struct got_reflist_entry *re;
4592 9eed6f10 2020-02-08 tracey char *age = NULL, *href_summary = NULL, *href_briefs = NULL;
4593 9eed6f10 2020-02-08 tracey char *href_commits = NULL;
4594 9eed6f10 2020-02-08 tracey enum kcgi_err kerr = KCGI_OK;
4595 51d4a92d 2020-02-03 tracey
4596 d9dff0e5 2020-12-26 stsp TAILQ_INIT(&refs);
4597 87f9ebf5 2020-01-15 tracey
4598 deac617c 2020-02-14 tracey error = got_ref_list(&refs, gw_trans->repo, "refs/heads",
4599 deac617c 2020-02-14 tracey got_ref_cmp_by_name, NULL);
4600 87f9ebf5 2020-01-15 tracey if (error)
4601 87f9ebf5 2020-01-15 tracey goto done;
4602 87f9ebf5 2020-01-15 tracey
4603 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
4604 9eed6f10 2020-02-08 tracey KATTR_ID, "summary_heads_title_wrapper", KATTR__MAX);
4605 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4606 9eed6f10 2020-02-08 tracey goto done;
4607 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
4608 9eed6f10 2020-02-08 tracey KATTR_ID, "summary_heads_title", KATTR__MAX);
4609 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4610 9eed6f10 2020-02-08 tracey goto done;
4611 9eed6f10 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Heads");
4612 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4613 9eed6f10 2020-02-08 tracey goto done;
4614 9eed6f10 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
4615 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4616 9eed6f10 2020-02-08 tracey goto done;
4617 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
4618 9eed6f10 2020-02-08 tracey KATTR_ID, "summary_heads_content", KATTR__MAX);
4619 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4620 9eed6f10 2020-02-08 tracey goto done;
4621 9eed6f10 2020-02-08 tracey
4622 d9dff0e5 2020-12-26 stsp TAILQ_FOREACH(re, &refs, entry) {
4623 7eb2c8df 2020-02-14 stsp const char *refname;
4624 87f9ebf5 2020-01-15 tracey
4625 eb4f3ad3 2020-02-14 stsp if (got_ref_is_symbolic(re->ref))
4626 eb4f3ad3 2020-02-14 stsp continue;
4627 eb4f3ad3 2020-02-14 stsp
4628 7eb2c8df 2020-02-14 stsp refname = got_ref_get_name(re->ref);
4629 7eb2c8df 2020-02-14 stsp if (strncmp(refname, "refs/heads/", 11) != 0)
4630 87f9ebf5 2020-01-15 tracey continue;
4631 87f9ebf5 2020-01-15 tracey
4632 017d6da3 2020-01-29 tracey error = gw_get_repo_age(&age, gw_trans, gw_trans->gw_dir->path,
4633 017d6da3 2020-01-29 tracey refname, TM_DIFF);
4634 d126c1b7 2020-01-29 stsp if (error)
4635 d126c1b7 2020-01-29 stsp goto done;
4636 87f9ebf5 2020-01-15 tracey
4637 9eed6f10 2020-02-08 tracey if (strncmp(refname, "refs/heads/", 11) == 0)
4638 9eed6f10 2020-02-08 tracey refname += 11;
4639 9eed6f10 2020-02-08 tracey
4640 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
4641 9eed6f10 2020-02-08 tracey KATTR_ID, "heads_wrapper", KATTR__MAX);
4642 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4643 9eed6f10 2020-02-08 tracey goto done;
4644 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
4645 9eed6f10 2020-02-08 tracey KATTR_ID, "heads_age", KATTR__MAX);
4646 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4647 9eed6f10 2020-02-08 tracey goto done;
4648 9eed6f10 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req, age ? age : "");
4649 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4650 9eed6f10 2020-02-08 tracey goto done;
4651 9eed6f10 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
4652 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4653 9eed6f10 2020-02-08 tracey goto done;
4654 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
4655 9eed6f10 2020-02-08 tracey KATTR_ID, "heads_space", KATTR__MAX);
4656 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4657 9eed6f10 2020-02-08 tracey goto done;
4658 9eed6f10 2020-02-08 tracey kerr = khtml_entity(gw_trans->gw_html_req, KENTITY_nbsp);
4659 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4660 9eed6f10 2020-02-08 tracey goto done;
4661 9eed6f10 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
4662 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4663 9eed6f10 2020-02-08 tracey goto done;
4664 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
4665 9eed6f10 2020-02-08 tracey KATTR_ID, "head", KATTR__MAX);
4666 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4667 9eed6f10 2020-02-08 tracey goto done;
4668 e6789209 2020-04-14 tracey
4669 e6789209 2020-04-14 tracey href_summary = khttp_urlpart(NULL, NULL, "gotweb", "path",
4670 e6789209 2020-04-14 tracey gw_trans->repo_name, "action", "summary", "headref",
4671 19ff7638 2020-04-14 tracey refname, NULL);
4672 19ff7638 2020-04-14 tracey if (href_summary == NULL) {
4673 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
4674 19ff7638 2020-04-14 tracey goto done;
4675 19ff7638 2020-04-14 tracey }
4676 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A, KATTR_HREF,
4677 9eed6f10 2020-02-08 tracey href_summary, KATTR__MAX);
4678 9eed6f10 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req, refname);
4679 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4680 9eed6f10 2020-02-08 tracey goto done;
4681 9eed6f10 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 3);
4682 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4683 9eed6f10 2020-02-08 tracey goto done;
4684 87f9ebf5 2020-01-15 tracey
4685 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
4686 9eed6f10 2020-02-08 tracey "navs_wrapper", KATTR__MAX);
4687 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4688 9eed6f10 2020-02-08 tracey goto done;
4689 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
4690 9eed6f10 2020-02-08 tracey "navs", KATTR__MAX);
4691 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4692 9eed6f10 2020-02-08 tracey goto done;
4693 87f9ebf5 2020-01-15 tracey
4694 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A, KATTR_HREF,
4695 9eed6f10 2020-02-08 tracey href_summary, KATTR__MAX);
4696 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4697 9eed6f10 2020-02-08 tracey goto done;
4698 9eed6f10 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req, "summary");
4699 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4700 9eed6f10 2020-02-08 tracey goto done;
4701 9eed6f10 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
4702 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4703 9eed6f10 2020-02-08 tracey goto done;
4704 9eed6f10 2020-02-08 tracey
4705 9eed6f10 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req, " | ");
4706 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4707 87f9ebf5 2020-01-15 tracey goto done;
4708 e6789209 2020-04-14 tracey
4709 e6789209 2020-04-14 tracey href_briefs = khttp_urlpart(NULL, NULL, "gotweb", "path",
4710 e6789209 2020-04-14 tracey gw_trans->repo_name, "action", "briefs", "headref",
4711 e6789209 2020-04-14 tracey refname, NULL);
4712 19ff7638 2020-04-14 tracey if (href_briefs == NULL) {
4713 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
4714 19ff7638 2020-04-14 tracey goto done;
4715 19ff7638 2020-04-14 tracey }
4716 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A, KATTR_HREF,
4717 9eed6f10 2020-02-08 tracey href_briefs, KATTR__MAX);
4718 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4719 9eed6f10 2020-02-08 tracey goto done;
4720 9eed6f10 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req, "commit briefs");
4721 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4722 9eed6f10 2020-02-08 tracey goto done;
4723 9eed6f10 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
4724 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4725 9eed6f10 2020-02-08 tracey goto done;
4726 87f9ebf5 2020-01-15 tracey
4727 9eed6f10 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req, " | ");
4728 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4729 9eed6f10 2020-02-08 tracey goto done;
4730 87f9ebf5 2020-01-15 tracey
4731 e6789209 2020-04-14 tracey href_commits = khttp_urlpart(NULL, NULL, "gotweb", "path",
4732 e6789209 2020-04-14 tracey gw_trans->repo_name, "action", "commits", "headref",
4733 19ff7638 2020-04-14 tracey refname, NULL);
4734 19ff7638 2020-04-14 tracey if (href_commits == NULL) {
4735 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
4736 19ff7638 2020-04-14 tracey goto done;
4737 19ff7638 2020-04-14 tracey }
4738 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A, KATTR_HREF,
4739 9eed6f10 2020-02-08 tracey href_commits, KATTR__MAX);
4740 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4741 9eed6f10 2020-02-08 tracey goto done;
4742 9eed6f10 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req, "commits");
4743 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4744 9eed6f10 2020-02-08 tracey goto done;
4745 9eed6f10 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 3);
4746 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4747 9eed6f10 2020-02-08 tracey goto done;
4748 87f9ebf5 2020-01-15 tracey
4749 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
4750 9eed6f10 2020-02-08 tracey "dotted_line", KATTR__MAX);
4751 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4752 9eed6f10 2020-02-08 tracey goto done;
4753 9eed6f10 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
4754 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4755 9eed6f10 2020-02-08 tracey goto done;
4756 9eed6f10 2020-02-08 tracey free(href_summary);
4757 9eed6f10 2020-02-08 tracey href_summary = NULL;
4758 9eed6f10 2020-02-08 tracey free(href_briefs);
4759 9eed6f10 2020-02-08 tracey href_briefs = NULL;
4760 9eed6f10 2020-02-08 tracey free(href_commits);
4761 9eed6f10 2020-02-08 tracey href_commits = NULL;
4762 6c6c85af 2020-01-15 tracey }
4763 87f9ebf5 2020-01-15 tracey done:
4764 87f9ebf5 2020-01-15 tracey got_ref_list_free(&refs);
4765 9eed6f10 2020-02-08 tracey free(href_summary);
4766 9eed6f10 2020-02-08 tracey free(href_briefs);
4767 9eed6f10 2020-02-08 tracey free(href_commits);
4768 51d4a92d 2020-02-03 tracey return error;
4769 8d4d2453 2020-01-15 tracey }
4770 8d4d2453 2020-01-15 tracey
4771 4ae179a2 2020-02-08 tracey static const struct got_error *
4772 4ae179a2 2020-02-08 tracey gw_output_site_link(struct gw_trans *gw_trans)
4773 2c251c14 2020-01-15 tracey {
4774 4ae179a2 2020-02-08 tracey const struct got_error *error = NULL;
4775 4ae179a2 2020-02-08 tracey char *href_summary = NULL;
4776 4ae179a2 2020-02-08 tracey enum kcgi_err kerr = KCGI_OK;
4777 2c251c14 2020-01-15 tracey
4778 4ae179a2 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
4779 4ae179a2 2020-02-08 tracey "site_link", KATTR__MAX);
4780 4ae179a2 2020-02-08 tracey if (kerr != KCGI_OK)
4781 4ae179a2 2020-02-08 tracey goto done;
4782 4ae179a2 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A, KATTR_HREF, GOTWEB,
4783 4ae179a2 2020-02-08 tracey KATTR__MAX);
4784 4ae179a2 2020-02-08 tracey if (kerr != KCGI_OK)
4785 4ae179a2 2020-02-08 tracey goto done;
4786 4ae179a2 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req,
4787 62d463ca 2020-10-20 naddy gw_trans->gw_conf->got_site_link);
4788 4ae179a2 2020-02-08 tracey if (kerr != KCGI_OK)
4789 4ae179a2 2020-02-08 tracey goto done;
4790 4ae179a2 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
4791 4ae179a2 2020-02-08 tracey if (kerr != KCGI_OK)
4792 4ae179a2 2020-02-08 tracey goto done;
4793 2c251c14 2020-01-15 tracey
4794 4ae179a2 2020-02-08 tracey if (gw_trans->repo_name != NULL) {
4795 4ae179a2 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req, " / ");
4796 4ae179a2 2020-02-08 tracey if (kerr != KCGI_OK)
4797 4ae179a2 2020-02-08 tracey goto done;
4798 6918c609 2020-04-14 tracey
4799 6918c609 2020-04-14 tracey href_summary = khttp_urlpart(NULL, NULL, "gotweb", "path",
4800 19ff7638 2020-04-14 tracey gw_trans->repo_name, "action", "summary", NULL);
4801 19ff7638 2020-04-14 tracey if (href_summary == NULL) {
4802 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
4803 19ff7638 2020-04-14 tracey goto done;
4804 19ff7638 2020-04-14 tracey }
4805 4ae179a2 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A, KATTR_HREF,
4806 4ae179a2 2020-02-08 tracey href_summary, KATTR__MAX);
4807 4ae179a2 2020-02-08 tracey if (kerr != KCGI_OK)
4808 4ae179a2 2020-02-08 tracey goto done;
4809 4ae179a2 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req, gw_trans->repo_name);
4810 4ae179a2 2020-02-08 tracey if (kerr != KCGI_OK)
4811 4ae179a2 2020-02-08 tracey goto done;
4812 4ae179a2 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
4813 4ae179a2 2020-02-08 tracey if (kerr != KCGI_OK)
4814 4ae179a2 2020-02-08 tracey goto done;
4815 32b9f7ed 2020-04-14 tracey kerr = khtml_printf(gw_trans->gw_html_req, " / %s",
4816 5d1296de 2020-02-13 stsp gw_get_action_name(gw_trans));
4817 4ae179a2 2020-02-08 tracey if (kerr != KCGI_OK)
4818 4ae179a2 2020-02-08 tracey goto done;
4819 eb89db64 2020-02-03 stsp }
4820 2c251c14 2020-01-15 tracey
4821 4ae179a2 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
4822 4ae179a2 2020-02-08 tracey if (kerr != KCGI_OK)
4823 4ae179a2 2020-02-08 tracey goto done;
4824 4ae179a2 2020-02-08 tracey done:
4825 4ae179a2 2020-02-08 tracey free(href_summary);
4826 6918c609 2020-04-14 tracey if (error == NULL && kerr != KCGI_OK)
4827 6918c609 2020-04-14 tracey error = gw_kcgi_error(kerr);
4828 4ae179a2 2020-02-08 tracey return error;
4829 2c251c14 2020-01-15 tracey }
4830 2c251c14 2020-01-15 tracey
4831 83eb9a68 2020-02-03 stsp static const struct got_error *
4832 f7cc9480 2020-02-05 tracey gw_colordiff_line(struct gw_trans *gw_trans, char *buf)
4833 ec46ccd7 2020-01-15 tracey {
4834 ec46ccd7 2020-01-15 tracey const struct got_error *error = NULL;
4835 0c6f49ba 2022-07-01 thomas const char *color = NULL;
4836 f7cc9480 2020-02-05 tracey enum kcgi_err kerr = KCGI_OK;
4837 83eb9a68 2020-02-03 stsp
4838 ec46ccd7 2020-01-15 tracey if (strncmp(buf, "-", 1) == 0)
4839 ec46ccd7 2020-01-15 tracey color = "diff_minus";
4840 83eb9a68 2020-02-03 stsp else if (strncmp(buf, "+", 1) == 0)
4841 ec46ccd7 2020-01-15 tracey color = "diff_plus";
4842 83eb9a68 2020-02-03 stsp else if (strncmp(buf, "@@", 2) == 0)
4843 ec46ccd7 2020-01-15 tracey color = "diff_chunk_header";
4844 83eb9a68 2020-02-03 stsp else if (strncmp(buf, "@@", 2) == 0)
4845 ec46ccd7 2020-01-15 tracey color = "diff_chunk_header";
4846 83eb9a68 2020-02-03 stsp else if (strncmp(buf, "commit +", 8) == 0)
4847 ec46ccd7 2020-01-15 tracey color = "diff_meta";
4848 83eb9a68 2020-02-03 stsp else if (strncmp(buf, "commit -", 8) == 0)
4849 ec46ccd7 2020-01-15 tracey color = "diff_meta";
4850 83eb9a68 2020-02-03 stsp else if (strncmp(buf, "blob +", 6) == 0)
4851 ec46ccd7 2020-01-15 tracey color = "diff_meta";
4852 83eb9a68 2020-02-03 stsp else if (strncmp(buf, "blob -", 6) == 0)
4853 ec46ccd7 2020-01-15 tracey color = "diff_meta";
4854 83eb9a68 2020-02-03 stsp else if (strncmp(buf, "file +", 6) == 0)
4855 ec46ccd7 2020-01-15 tracey color = "diff_meta";
4856 83eb9a68 2020-02-03 stsp else if (strncmp(buf, "file -", 6) == 0)
4857 ec46ccd7 2020-01-15 tracey color = "diff_meta";
4858 83eb9a68 2020-02-03 stsp else if (strncmp(buf, "from:", 5) == 0)
4859 ec46ccd7 2020-01-15 tracey color = "diff_author";
4860 83eb9a68 2020-02-03 stsp else if (strncmp(buf, "via:", 4) == 0)
4861 ec46ccd7 2020-01-15 tracey color = "diff_author";
4862 83eb9a68 2020-02-03 stsp else if (strncmp(buf, "date:", 5) == 0)
4863 ec46ccd7 2020-01-15 tracey color = "diff_date";
4864 f7cc9480 2020-02-05 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
4865 f7cc9480 2020-02-05 tracey "diff_line", KATTR_CLASS, color ? color : "", KATTR__MAX);
4866 f7cc9480 2020-02-05 tracey if (error == NULL && kerr != KCGI_OK)
4867 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
4868 070fee27 2020-02-03 stsp return error;
4869 2c251c14 2020-01-15 tracey }
4870 2c251c14 2020-01-15 tracey
4871 2c251c14 2020-01-15 tracey int
4872 c08369d7 2020-01-15 tracey main(int argc, char *argv[])
4873 2c251c14 2020-01-15 tracey {
4874 6648f956 2021-04-26 tracey const struct got_error *error = NULL, *error2 = NULL;
4875 54415d85 2020-01-15 tracey struct gw_trans *gw_trans;
4876 2c251c14 2020-01-15 tracey struct gw_dir *dir = NULL, *tdir;
4877 2c251c14 2020-01-15 tracey const char *page = "index";
4878 795c10a4 2020-02-20 tracey enum kcgi_err kerr = KCGI_OK;
4879 2c251c14 2020-01-15 tracey
4880 54415d85 2020-01-15 tracey if ((gw_trans = malloc(sizeof(struct gw_trans))) == NULL)
4881 2c251c14 2020-01-15 tracey errx(1, "malloc");
4882 2c251c14 2020-01-15 tracey
4883 2c251c14 2020-01-15 tracey if ((gw_trans->gw_req = malloc(sizeof(struct kreq))) == NULL)
4884 2c251c14 2020-01-15 tracey errx(1, "malloc");
4885 2c251c14 2020-01-15 tracey
4886 2c251c14 2020-01-15 tracey if ((gw_trans->gw_html_req = malloc(sizeof(struct khtmlreq))) == NULL)
4887 2c251c14 2020-01-15 tracey errx(1, "malloc");
4888 2c251c14 2020-01-15 tracey
4889 2c251c14 2020-01-15 tracey if ((gw_trans->gw_tmpl = malloc(sizeof(struct ktemplate))) == NULL)
4890 2c251c14 2020-01-15 tracey errx(1, "malloc");
4891 2c251c14 2020-01-15 tracey
4892 c25c2314 2020-01-28 stsp kerr = khttp_parse(gw_trans->gw_req, gw_keys, KEY__ZMAX, &page, 1, 0);
4893 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK) {
4894 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
4895 c119608e 2020-01-28 stsp goto done;
4896 46b9c89b 2020-01-15 tracey }
4897 46b9c89b 2020-01-15 tracey
4898 2c251c14 2020-01-15 tracey TAILQ_INIT(&gw_trans->gw_dirs);
4899 f2f46662 2020-01-23 tracey TAILQ_INIT(&gw_trans->gw_headers);
4900 2c251c14 2020-01-15 tracey
4901 f1200fe3 2020-02-13 tracey gw_trans->action = -1;
4902 2c251c14 2020-01-15 tracey gw_trans->page = 0;
4903 2c251c14 2020-01-15 tracey gw_trans->repos_total = 0;
4904 2c251c14 2020-01-15 tracey gw_trans->repo_path = NULL;
4905 56997cd3 2020-02-14 tracey gw_trans->commit_id = NULL;
4906 55e46400 2020-02-18 tracey gw_trans->next_id = NULL;
4907 55e46400 2020-02-18 tracey gw_trans->prev_id = NULL;
4908 742ba378 2020-02-14 stsp gw_trans->headref = GOT_REF_HEAD;
4909 2c251c14 2020-01-15 tracey gw_trans->mime = KMIME_TEXT_HTML;
4910 54415d85 2020-01-15 tracey gw_trans->gw_tmpl->key = gw_templs;
4911 2c251c14 2020-01-15 tracey gw_trans->gw_tmpl->keysz = TEMPL__MAX;
4912 2c251c14 2020-01-15 tracey gw_trans->gw_tmpl->arg = gw_trans;
4913 2c251c14 2020-01-15 tracey gw_trans->gw_tmpl->cb = gw_template;
4914 c34ec417 2020-06-22 tracey
4915 e0fb2ce2 2022-06-23 thomas error = got_repo_pack_fds_open(&gw_trans->pack_fds);
4916 e0fb2ce2 2022-06-23 thomas if (error != NULL)
4917 e0fb2ce2 2022-06-23 thomas goto done;
4918 e0fb2ce2 2022-06-23 thomas
4919 c34ec417 2020-06-22 tracey error = parse_gotweb_config(&gw_trans->gw_conf, GOTWEB_CONF);
4920 c119608e 2020-01-28 stsp if (error)
4921 2c251c14 2020-01-15 tracey goto done;
4922 2c251c14 2020-01-15 tracey
4923 2c251c14 2020-01-15 tracey error = gw_parse_querystring(gw_trans);
4924 2c251c14 2020-01-15 tracey if (error)
4925 c119608e 2020-01-28 stsp goto done;
4926 2c251c14 2020-01-15 tracey
4927 1d0f4054 2021-06-17 stsp if (gw_trans->repo) {
4928 1d0f4054 2021-06-17 stsp const struct got_error *close_err;
4929 1d0f4054 2021-06-17 stsp close_err = got_repo_close(gw_trans->repo);
4930 1d0f4054 2021-06-17 stsp if (error == NULL)
4931 1d0f4054 2021-06-17 stsp error = close_err;
4932 1d0f4054 2021-06-17 stsp }
4933 7cd52833 2022-06-23 thomas if (gw_trans->action == GW_BLOB)
4934 7cd52833 2022-06-23 thomas error = gw_blob(gw_trans);
4935 7cd52833 2022-06-23 thomas else
4936 7cd52833 2022-06-23 thomas error = gw_display_index(gw_trans);
4937 7cd52833 2022-06-23 thomas done:
4938 6648f956 2021-04-26 tracey if (error) {
4939 6648f956 2021-04-26 tracey gw_trans->error = error;
4940 6648f956 2021-04-26 tracey gw_trans->action = GW_ERR;
4941 6648f956 2021-04-26 tracey error2 = gw_display_open(gw_trans, KHTTP_200, gw_trans->mime);
4942 6648f956 2021-04-26 tracey if (error2)
4943 6648f956 2021-04-26 tracey goto cleanup; /* we can't display an error page */
4944 6648f956 2021-04-26 tracey kerr = khtml_open(gw_trans->gw_html_req, gw_trans->gw_req, 0);
4945 6648f956 2021-04-26 tracey if (kerr != KCGI_OK)
4946 6648f956 2021-04-26 tracey goto cleanup; /* we can't display an error page */
4947 6648f956 2021-04-26 tracey kerr = khttp_template(gw_trans->gw_req, gw_trans->gw_tmpl,
4948 6648f956 2021-04-26 tracey gw_query_funcs[gw_trans->action].template);
4949 6648f956 2021-04-26 tracey if (kerr != KCGI_OK) {
4950 6648f956 2021-04-26 tracey khtml_close(gw_trans->gw_html_req);
4951 6648f956 2021-04-26 tracey goto cleanup; /* we can't display an error page */
4952 6648f956 2021-04-26 tracey }
4953 6648f956 2021-04-26 tracey }
4954 6648f956 2021-04-26 tracey
4955 6648f956 2021-04-26 tracey cleanup:
4956 e0fb2ce2 2022-06-23 thomas if (gw_trans->pack_fds) {
4957 e0fb2ce2 2022-06-23 thomas const struct got_error *pack_err =
4958 e0fb2ce2 2022-06-23 thomas got_repo_pack_fds_close(gw_trans->pack_fds);
4959 e0fb2ce2 2022-06-23 thomas if (error == NULL)
4960 e0fb2ce2 2022-06-23 thomas error = pack_err;
4961 1b4d350c 2022-06-23 thomas gw_trans->pack_fds = NULL;
4962 e0fb2ce2 2022-06-23 thomas }
4963 a5a8a332 2020-11-09 tracey free(gw_trans->gw_conf->got_repos_path);
4964 a5a8a332 2020-11-09 tracey free(gw_trans->gw_conf->got_www_path);
4965 a5a8a332 2020-11-09 tracey free(gw_trans->gw_conf->got_site_name);
4966 a5a8a332 2020-11-09 tracey free(gw_trans->gw_conf->got_site_owner);
4967 a5a8a332 2020-11-09 tracey free(gw_trans->gw_conf->got_site_link);
4968 a5a8a332 2020-11-09 tracey free(gw_trans->gw_conf->got_logo);
4969 a5a8a332 2020-11-09 tracey free(gw_trans->gw_conf->got_logo_url);
4970 a5a8a332 2020-11-09 tracey free(gw_trans->gw_conf);
4971 a5a8a332 2020-11-09 tracey free(gw_trans->commit_id);
4972 a5a8a332 2020-11-09 tracey free(gw_trans->next_id);
4973 a5a8a332 2020-11-09 tracey free(gw_trans->prev_id);
4974 a5a8a332 2020-11-09 tracey free(gw_trans->repo_path);
4975 a5a8a332 2020-11-09 tracey TAILQ_FOREACH_SAFE(dir, &gw_trans->gw_dirs, entry, tdir) {
4976 a5a8a332 2020-11-09 tracey free(dir->name);
4977 a5a8a332 2020-11-09 tracey free(dir->description);
4978 a5a8a332 2020-11-09 tracey free(dir->age);
4979 a5a8a332 2020-11-09 tracey free(dir->url);
4980 a5a8a332 2020-11-09 tracey free(dir->path);
4981 a5a8a332 2020-11-09 tracey free(dir);
4982 2c251c14 2020-01-15 tracey }
4983 2c251c14 2020-01-15 tracey
4984 2c251c14 2020-01-15 tracey khttp_free(gw_trans->gw_req);
4985 d56b34ca 2020-01-29 stsp return 0;
4986 2c251c14 2020-01-15 tracey }