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