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