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