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 4ae179a2 2020-02-08 tracey char *img_src = NULL;
2196 2c251c14 2020-01-15 tracey
2197 2c251c14 2020-01-15 tracey switch (key) {
2198 2c251c14 2020-01-15 tracey case (TEMPL_HEAD):
2199 aaed5792 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_META,
2200 1dcb8908 2020-02-12 tracey KATTR_NAME, "viewport",
2201 1dcb8908 2020-02-12 tracey KATTR_CONTENT, "initial-scale=.75, user-scalable=yes",
2202 aaed5792 2020-02-08 tracey KATTR__MAX);
2203 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
2204 bd275801 2020-02-03 tracey return 0;
2205 aaed5792 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2206 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2207 aaed5792 2020-02-08 tracey return 0;
2208 aaed5792 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_META,
2209 aaed5792 2020-02-08 tracey KATTR_CHARSET, "utf-8",
2210 aaed5792 2020-02-08 tracey KATTR__MAX);
2211 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2212 aaed5792 2020-02-08 tracey return 0;
2213 aaed5792 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2214 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2215 aaed5792 2020-02-08 tracey return 0;
2216 aaed5792 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_META,
2217 aaed5792 2020-02-08 tracey KATTR_NAME, "msapplication-TileColor",
2218 aaed5792 2020-02-08 tracey KATTR_CONTENT, "#da532c", KATTR__MAX);
2219 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2220 aaed5792 2020-02-08 tracey return 0;
2221 aaed5792 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2222 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2223 aaed5792 2020-02-08 tracey return 0;
2224 aaed5792 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_META,
2225 aaed5792 2020-02-08 tracey KATTR_NAME, "theme-color",
2226 aaed5792 2020-02-08 tracey KATTR_CONTENT, "#ffffff", KATTR__MAX);
2227 aaed5792 2020-02-08 tracey if (kerr != KCGI_OK)
2228 aaed5792 2020-02-08 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_LINK,
2233 aaed5792 2020-02-08 tracey KATTR_REL, "apple-touch-icon", KATTR_SIZES, "180x180",
2234 aaed5792 2020-02-08 tracey KATTR_HREF, "/apple-touch-icon.png", 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_LINK,
2241 aaed5792 2020-02-08 tracey KATTR_REL, "icon", KATTR_TYPE, "image/png", KATTR_SIZES,
2242 aaed5792 2020-02-08 tracey "32x32", KATTR_HREF, "/favicon-32x32.png", 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_LINK,
2249 aaed5792 2020-02-08 tracey KATTR_REL, "icon", KATTR_TYPE, "image/png", KATTR_SIZES,
2250 aaed5792 2020-02-08 tracey "16x16", KATTR_HREF, "/favicon-16x16.png", 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, "manifest", KATTR_HREF, "/site.webmanifest",
2258 aaed5792 2020-02-08 tracey 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, "mask-icon", KATTR_HREF,
2266 aaed5792 2020-02-08 tracey "/safari-pinned-tab.svg", 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, "stylesheet", KATTR_TYPE, "text/css",
2274 aaed5792 2020-02-08 tracey KATTR_HREF, "/gotweb.css", 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 2c251c14 2020-01-15 tracey break;
2281 2c251c14 2020-01-15 tracey case(TEMPL_HEADER):
2282 185ba3ba 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2283 185ba3ba 2020-02-04 tracey KATTR_ID, "got_link", KATTR__MAX);
2284 185ba3ba 2020-02-04 tracey if (kerr != KCGI_OK)
2285 185ba3ba 2020-02-04 tracey return 0;
2286 185ba3ba 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
2287 185ba3ba 2020-02-04 tracey KATTR_HREF, gw_trans->gw_conf->got_logo_url,
2288 185ba3ba 2020-02-04 tracey KATTR_TARGET, "_sotd", KATTR__MAX);
2289 185ba3ba 2020-02-04 tracey if (kerr != KCGI_OK)
2290 185ba3ba 2020-02-04 tracey return 0;
2291 185ba3ba 2020-02-04 tracey if (asprintf(&img_src, "/%s",
2292 185ba3ba 2020-02-04 tracey gw_trans->gw_conf->got_logo) == -1)
2293 185ba3ba 2020-02-04 tracey return 0;
2294 185ba3ba 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_IMG,
2295 185ba3ba 2020-02-04 tracey KATTR_SRC, img_src, KATTR__MAX);
2296 185ba3ba 2020-02-04 tracey if (kerr != KCGI_OK) {
2297 185ba3ba 2020-02-04 tracey free(img_src);
2298 185ba3ba 2020-02-04 tracey return 0;
2299 bd275801 2020-02-03 tracey }
2300 185ba3ba 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 3);
2301 185ba3ba 2020-02-04 tracey if (kerr != KCGI_OK) {
2302 185ba3ba 2020-02-04 tracey free(img_src);
2303 185ba3ba 2020-02-04 tracey return 0;
2304 185ba3ba 2020-02-04 tracey }
2305 2c251c14 2020-01-15 tracey break;
2306 2c251c14 2020-01-15 tracey case (TEMPL_SITEPATH):
2307 4ae179a2 2020-02-08 tracey error = gw_output_site_link(gw_trans);
2308 4ae179a2 2020-02-08 tracey if (error)
2309 4ae179a2 2020-02-08 tracey return 0;
2310 2c251c14 2020-01-15 tracey break;
2311 2c251c14 2020-01-15 tracey case(TEMPL_TITLE):
2312 bd275801 2020-02-03 tracey if (gw_trans->gw_conf->got_site_name != NULL) {
2313 bd275801 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req,
2314 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_site_name);
2315 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
2316 bd275801 2020-02-03 tracey return 0;
2317 bd275801 2020-02-03 tracey }
2318 2c251c14 2020-01-15 tracey break;
2319 2c251c14 2020-01-15 tracey case (TEMPL_SEARCH):
2320 63ee0dca 2020-02-08 tracey break;
2321 63ee0dca 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
2322 63ee0dca 2020-02-08 tracey "search", KATTR__MAX);
2323 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
2324 bd275801 2020-02-03 tracey return 0;
2325 63ee0dca 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_FORM,
2326 63ee0dca 2020-02-08 tracey KATTR_METHOD, "POST", KATTR__MAX);
2327 63ee0dca 2020-02-08 tracey if (kerr != KCGI_OK)
2328 63ee0dca 2020-02-08 tracey return 0;
2329 63ee0dca 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_INPUT, KATTR_ID,
2330 63ee0dca 2020-02-08 tracey "got-search", KATTR_NAME, "got-search", KATTR_SIZE, "15",
2331 63ee0dca 2020-02-08 tracey KATTR_MAXLENGTH, "50", KATTR__MAX);
2332 63ee0dca 2020-02-08 tracey if (kerr != KCGI_OK)
2333 63ee0dca 2020-02-08 tracey return 0;
2334 63ee0dca 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_BUTTON,
2335 63ee0dca 2020-02-08 tracey KATTR__MAX);
2336 63ee0dca 2020-02-08 tracey if (kerr != KCGI_OK)
2337 63ee0dca 2020-02-08 tracey return 0;
2338 63ee0dca 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Search");
2339 63ee0dca 2020-02-08 tracey if (kerr != KCGI_OK)
2340 63ee0dca 2020-02-08 tracey return 0;
2341 63ee0dca 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 4);
2342 63ee0dca 2020-02-08 tracey if (kerr != KCGI_OK)
2343 63ee0dca 2020-02-08 tracey return 0;
2344 2c251c14 2020-01-15 tracey break;
2345 2c251c14 2020-01-15 tracey case(TEMPL_SITEOWNER):
2346 2c251c14 2020-01-15 tracey if (gw_trans->gw_conf->got_site_owner != NULL &&
2347 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_show_site_owner) {
2348 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2349 bd275801 2020-02-03 tracey KATTR_ID, "site_owner_wrapper", KATTR__MAX);
2350 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
2351 070fee27 2020-02-03 stsp return 0;
2352 bd275801 2020-02-03 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2353 bd275801 2020-02-03 tracey KATTR_ID, "site_owner", KATTR__MAX);
2354 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
2355 2c251c14 2020-01-15 tracey return 0;
2356 bd275801 2020-02-03 tracey kerr = khtml_puts(gw_trans->gw_html_req,
2357 bd275801 2020-02-03 tracey gw_trans->gw_conf->got_site_owner);
2358 bd275801 2020-02-03 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
2359 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
2360 bd275801 2020-02-03 tracey return 0;
2361 2c251c14 2020-01-15 tracey }
2362 2c251c14 2020-01-15 tracey break;
2363 2c251c14 2020-01-15 tracey case(TEMPL_CONTENT):
2364 2c251c14 2020-01-15 tracey error = gw_query_funcs[gw_trans->action].func_main(gw_trans);
2365 bd275801 2020-02-03 tracey if (error) {
2366 0d100d0b 2020-02-07 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2367 0d100d0b 2020-02-07 tracey KATTR_ID, "tmpl_err", KATTR__MAX);
2368 0d100d0b 2020-02-07 tracey if (kerr != KCGI_OK)
2369 0d100d0b 2020-02-07 tracey return 0;
2370 f08447b0 2020-04-14 tracey kerr = khttp_printf(gw_trans->gw_req, "Error: %s",
2371 f08447b0 2020-04-14 tracey error->msg);
2372 0d100d0b 2020-02-07 tracey if (kerr != KCGI_OK)
2373 0d100d0b 2020-02-07 tracey return 0;
2374 0d100d0b 2020-02-07 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2375 bd275801 2020-02-03 tracey if (kerr != KCGI_OK)
2376 bd275801 2020-02-03 tracey return 0;
2377 bd275801 2020-02-03 tracey }
2378 2c251c14 2020-01-15 tracey break;
2379 2c251c14 2020-01-15 tracey default:
2380 2c251c14 2020-01-15 tracey return 0;
2381 2c251c14 2020-01-15 tracey }
2382 2c251c14 2020-01-15 tracey return 1;
2383 f2f46662 2020-01-23 tracey }
2384 21a55cc7 2020-02-04 tracey
2385 21a55cc7 2020-02-04 tracey static const struct got_error *
2386 21a55cc7 2020-02-04 tracey gw_gen_commit_header(struct gw_trans *gw_trans, char *str1, char *str2)
2387 21a55cc7 2020-02-04 tracey {
2388 21a55cc7 2020-02-04 tracey const struct got_error *error = NULL;
2389 21a55cc7 2020-02-04 tracey enum kcgi_err kerr = KCGI_OK;
2390 21a55cc7 2020-02-04 tracey
2391 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2392 21a55cc7 2020-02-04 tracey KATTR_ID, "header_commit_title", KATTR__MAX);
2393 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2394 21a55cc7 2020-02-04 tracey goto done;
2395 21a55cc7 2020-02-04 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Commit: ");
2396 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2397 21a55cc7 2020-02-04 tracey goto done;
2398 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2399 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2400 21a55cc7 2020-02-04 tracey goto done;
2401 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2402 21a55cc7 2020-02-04 tracey KATTR_ID, "header_commit", KATTR__MAX);
2403 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2404 21a55cc7 2020-02-04 tracey goto done;
2405 32b9f7ed 2020-04-14 tracey kerr = khtml_printf(gw_trans->gw_html_req, "%s ", str1);
2406 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2407 21a55cc7 2020-02-04 tracey goto done;
2408 5c65becf 2020-02-13 tracey if (str2 != NULL) {
2409 bf93a5c0 2020-02-15 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_SPAN,
2410 bf93a5c0 2020-02-15 tracey KATTR_ID, "refs_str", KATTR__MAX);
2411 5c65becf 2020-02-13 tracey if (kerr != KCGI_OK)
2412 5c65becf 2020-02-13 tracey goto done;
2413 32b9f7ed 2020-04-14 tracey kerr = khtml_printf(gw_trans->gw_html_req, "(%s)", str2);
2414 bf93a5c0 2020-02-15 tracey if (kerr != KCGI_OK)
2415 bf93a5c0 2020-02-15 tracey goto done;
2416 bf93a5c0 2020-02-15 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2417 5c65becf 2020-02-13 tracey if (kerr != KCGI_OK)
2418 5c65becf 2020-02-13 tracey goto done;
2419 5c65becf 2020-02-13 tracey }
2420 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2421 21a55cc7 2020-02-04 tracey done:
2422 21a55cc7 2020-02-04 tracey if (error == NULL && kerr != KCGI_OK)
2423 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
2424 21a55cc7 2020-02-04 tracey return error;
2425 21a55cc7 2020-02-04 tracey }
2426 21a55cc7 2020-02-04 tracey
2427 f7cc9480 2020-02-05 tracey static const struct got_error *
2428 f7cc9480 2020-02-05 tracey gw_gen_diff_header(struct gw_trans *gw_trans, char *str1, char *str2)
2429 f2f46662 2020-01-23 tracey {
2430 27192be7 2020-02-04 tracey const struct got_error *error = NULL;
2431 f7cc9480 2020-02-05 tracey enum kcgi_err kerr = KCGI_OK;
2432 f2f46662 2020-01-23 tracey
2433 f7cc9480 2020-02-05 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2434 f7cc9480 2020-02-05 tracey KATTR_ID, "header_diff_title", KATTR__MAX);
2435 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2436 f7cc9480 2020-02-05 tracey goto done;
2437 f7cc9480 2020-02-05 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Diff: ");
2438 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2439 f7cc9480 2020-02-05 tracey goto done;
2440 f7cc9480 2020-02-05 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2441 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2442 f7cc9480 2020-02-05 tracey goto done;
2443 f7cc9480 2020-02-05 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2444 f7cc9480 2020-02-05 tracey KATTR_ID, "header_diff", KATTR__MAX);
2445 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2446 f7cc9480 2020-02-05 tracey goto done;
2447 5c65becf 2020-02-13 tracey if (str1 != NULL) {
2448 5c65becf 2020-02-13 tracey kerr = khtml_puts(gw_trans->gw_html_req, str1);
2449 5c65becf 2020-02-13 tracey if (kerr != KCGI_OK)
2450 5c65becf 2020-02-13 tracey goto done;
2451 5c65becf 2020-02-13 tracey }
2452 f7cc9480 2020-02-05 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_BR, KATTR__MAX);
2453 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2454 f7cc9480 2020-02-05 tracey goto done;
2455 f7cc9480 2020-02-05 tracey kerr = khtml_puts(gw_trans->gw_html_req, str2);
2456 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2457 f7cc9480 2020-02-05 tracey goto done;
2458 f7cc9480 2020-02-05 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2459 f7cc9480 2020-02-05 tracey done:
2460 f7cc9480 2020-02-05 tracey if (error == NULL && kerr != KCGI_OK)
2461 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
2462 f7cc9480 2020-02-05 tracey return error;
2463 21a55cc7 2020-02-04 tracey }
2464 21a55cc7 2020-02-04 tracey
2465 21a55cc7 2020-02-04 tracey static const struct got_error *
2466 21a55cc7 2020-02-04 tracey gw_gen_age_header(struct gw_trans *gw_trans, const char *str)
2467 21a55cc7 2020-02-04 tracey {
2468 21a55cc7 2020-02-04 tracey const struct got_error *error = NULL;
2469 21a55cc7 2020-02-04 tracey enum kcgi_err kerr = KCGI_OK;
2470 21a55cc7 2020-02-04 tracey
2471 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2472 21a55cc7 2020-02-04 tracey KATTR_ID, "header_age_title", KATTR__MAX);
2473 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2474 21a55cc7 2020-02-04 tracey goto done;
2475 21a55cc7 2020-02-04 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Date: ");
2476 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2477 21a55cc7 2020-02-04 tracey goto done;
2478 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2479 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2480 21a55cc7 2020-02-04 tracey goto done;
2481 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2482 21a55cc7 2020-02-04 tracey KATTR_ID, "header_age", KATTR__MAX);
2483 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2484 21a55cc7 2020-02-04 tracey goto done;
2485 21a55cc7 2020-02-04 tracey kerr = khtml_puts(gw_trans->gw_html_req, str);
2486 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2487 21a55cc7 2020-02-04 tracey goto done;
2488 21a55cc7 2020-02-04 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2489 21a55cc7 2020-02-04 tracey done:
2490 21a55cc7 2020-02-04 tracey if (error == NULL && kerr != KCGI_OK)
2491 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
2492 21a55cc7 2020-02-04 tracey return error;
2493 21a55cc7 2020-02-04 tracey }
2494 21a55cc7 2020-02-04 tracey
2495 21a55cc7 2020-02-04 tracey static const struct got_error *
2496 21a55cc7 2020-02-04 tracey gw_gen_author_header(struct gw_trans *gw_trans, const char *str)
2497 21a55cc7 2020-02-04 tracey {
2498 21a55cc7 2020-02-04 tracey const struct got_error *error = NULL;
2499 795c10a4 2020-02-20 tracey enum kcgi_err kerr = KCGI_OK;
2500 21a55cc7 2020-02-04 tracey
2501 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2502 21a55cc7 2020-02-04 tracey KATTR_ID, "header_author_title", KATTR__MAX);
2503 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2504 21a55cc7 2020-02-04 tracey goto done;
2505 21a55cc7 2020-02-04 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Author: ");
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_closeelem(gw_trans->gw_html_req, 1);
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_attr(gw_trans->gw_html_req, KELEM_DIV,
2512 21a55cc7 2020-02-04 tracey KATTR_ID, "header_author", KATTR__MAX);
2513 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2514 21a55cc7 2020-02-04 tracey goto done;
2515 21a55cc7 2020-02-04 tracey kerr = khtml_puts(gw_trans->gw_html_req, str);
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_closeelem(gw_trans->gw_html_req, 1);
2519 21a55cc7 2020-02-04 tracey done:
2520 21a55cc7 2020-02-04 tracey if (error == NULL && kerr != KCGI_OK)
2521 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
2522 21a55cc7 2020-02-04 tracey return error;
2523 f2f46662 2020-01-23 tracey }
2524 f2f46662 2020-01-23 tracey
2525 21a55cc7 2020-02-04 tracey static const struct got_error *
2526 21a55cc7 2020-02-04 tracey gw_gen_committer_header(struct gw_trans *gw_trans, const char *str)
2527 21a55cc7 2020-02-04 tracey {
2528 21a55cc7 2020-02-04 tracey const struct got_error *error = NULL;
2529 795c10a4 2020-02-20 tracey enum kcgi_err kerr = KCGI_OK;
2530 21a55cc7 2020-02-04 tracey
2531 21a55cc7 2020-02-04 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2532 21a55cc7 2020-02-04 tracey KATTR_ID, "header_committer_title", KATTR__MAX);
2533 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2534 21a55cc7 2020-02-04 tracey goto done;
2535 87ca24ac 2020-02-04 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Committer: ");
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_closeelem(gw_trans->gw_html_req, 1);
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_attr(gw_trans->gw_html_req, KELEM_DIV,
2542 21a55cc7 2020-02-04 tracey KATTR_ID, "header_committer", KATTR__MAX);
2543 21a55cc7 2020-02-04 tracey if (kerr != KCGI_OK)
2544 21a55cc7 2020-02-04 tracey goto done;
2545 21a55cc7 2020-02-04 tracey kerr = khtml_puts(gw_trans->gw_html_req, str);
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_closeelem(gw_trans->gw_html_req, 1);
2549 21a55cc7 2020-02-04 tracey done:
2550 21a55cc7 2020-02-04 tracey if (error == NULL && kerr != KCGI_OK)
2551 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
2552 21a55cc7 2020-02-04 tracey return error;
2553 21a55cc7 2020-02-04 tracey }
2554 21a55cc7 2020-02-04 tracey
2555 f7cc9480 2020-02-05 tracey static const struct got_error *
2556 f7cc9480 2020-02-05 tracey gw_gen_commit_msg_header(struct gw_trans *gw_trans, char *str)
2557 f2f46662 2020-01-23 tracey {
2558 27192be7 2020-02-04 tracey const struct got_error *error = NULL;
2559 795c10a4 2020-02-20 tracey enum kcgi_err kerr = KCGI_OK;
2560 f2f46662 2020-01-23 tracey
2561 f7cc9480 2020-02-05 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2562 f7cc9480 2020-02-05 tracey KATTR_ID, "header_commit_msg_title", KATTR__MAX);
2563 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2564 f7cc9480 2020-02-05 tracey goto done;
2565 f7cc9480 2020-02-05 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Message: ");
2566 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2567 f7cc9480 2020-02-05 tracey goto done;
2568 f7cc9480 2020-02-05 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2569 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2570 f7cc9480 2020-02-05 tracey goto done;
2571 f7cc9480 2020-02-05 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2572 f7cc9480 2020-02-05 tracey KATTR_ID, "header_commit_msg", KATTR__MAX);
2573 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2574 f7cc9480 2020-02-05 tracey goto done;
2575 f7cc9480 2020-02-05 tracey kerr = khttp_puts(gw_trans->gw_req, str);
2576 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2577 f7cc9480 2020-02-05 tracey goto done;
2578 f7cc9480 2020-02-05 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2579 f7cc9480 2020-02-05 tracey done:
2580 f7cc9480 2020-02-05 tracey if (error == NULL && kerr != KCGI_OK)
2581 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
2582 f7cc9480 2020-02-05 tracey return error;
2583 f2f46662 2020-01-23 tracey }
2584 f2f46662 2020-01-23 tracey
2585 f7cc9480 2020-02-05 tracey static const struct got_error *
2586 f7cc9480 2020-02-05 tracey gw_gen_tree_header(struct gw_trans *gw_trans, char *str)
2587 f2f46662 2020-01-23 tracey {
2588 f7cc9480 2020-02-05 tracey const struct got_error *error = NULL;
2589 795c10a4 2020-02-20 tracey enum kcgi_err kerr = KCGI_OK;
2590 f2f46662 2020-01-23 tracey
2591 f7cc9480 2020-02-05 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
2592 f7cc9480 2020-02-05 tracey KATTR_ID, "header_tree_title", KATTR__MAX);
2593 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2594 f7cc9480 2020-02-05 tracey goto done;
2595 f7cc9480 2020-02-05 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Tree: ");
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_closeelem(gw_trans->gw_html_req, 1);
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_attr(gw_trans->gw_html_req, KELEM_DIV,
2602 f7cc9480 2020-02-05 tracey KATTR_ID, "header_tree", KATTR__MAX);
2603 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2604 f7cc9480 2020-02-05 tracey goto done;
2605 f7cc9480 2020-02-05 tracey kerr = khtml_puts(gw_trans->gw_html_req, str);
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 = khtml_closeelem(gw_trans->gw_html_req, 1);
2609 f7cc9480 2020-02-05 tracey done:
2610 f7cc9480 2020-02-05 tracey if (error == NULL && kerr != KCGI_OK)
2611 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
2612 f7cc9480 2020-02-05 tracey return error;
2613 f2f46662 2020-01-23 tracey }
2614 f2f46662 2020-01-23 tracey
2615 32cd4d18 2020-02-03 stsp static const struct got_error *
2616 32cd4d18 2020-02-03 stsp gw_get_repo_description(char **description, struct gw_trans *gw_trans,
2617 32cd4d18 2020-02-03 stsp char *dir)
2618 2c251c14 2020-01-15 tracey {
2619 32cd4d18 2020-02-03 stsp const struct got_error *error = NULL;
2620 b8b04565 2020-02-02 tracey FILE *f = NULL;
2621 32cd4d18 2020-02-03 stsp char *d_file = NULL;
2622 2c251c14 2020-01-15 tracey unsigned int len;
2623 1ab830c1 2020-02-03 stsp size_t n;
2624 2c251c14 2020-01-15 tracey
2625 32cd4d18 2020-02-03 stsp *description = NULL;
2626 0b20762b 2020-01-29 stsp if (gw_trans->gw_conf->got_show_repo_description == 0)
2627 a942aa37 2020-02-10 tracey return NULL;
2628 2c251c14 2020-01-15 tracey
2629 88d59c36 2020-01-29 stsp if (asprintf(&d_file, "%s/description", dir) == -1)
2630 32cd4d18 2020-02-03 stsp return got_error_from_errno("asprintf");
2631 2c251c14 2020-01-15 tracey
2632 32cd4d18 2020-02-03 stsp f = fopen(d_file, "r");
2633 32cd4d18 2020-02-03 stsp if (f == NULL) {
2634 32cd4d18 2020-02-03 stsp if (errno == ENOENT || errno == EACCES)
2635 a942aa37 2020-02-10 tracey return NULL;
2636 32cd4d18 2020-02-03 stsp error = got_error_from_errno2("fopen", d_file);
2637 32cd4d18 2020-02-03 stsp goto done;
2638 32cd4d18 2020-02-03 stsp }
2639 2c251c14 2020-01-15 tracey
2640 32cd4d18 2020-02-03 stsp if (fseek(f, 0, SEEK_END) == -1) {
2641 32cd4d18 2020-02-03 stsp error = got_ferror(f, GOT_ERR_IO);
2642 32cd4d18 2020-02-03 stsp goto done;
2643 32cd4d18 2020-02-03 stsp }
2644 32cd4d18 2020-02-03 stsp len = ftell(f);
2645 32cd4d18 2020-02-03 stsp if (len == -1) {
2646 32cd4d18 2020-02-03 stsp error = got_ferror(f, GOT_ERR_IO);
2647 32cd4d18 2020-02-03 stsp goto done;
2648 32cd4d18 2020-02-03 stsp }
2649 32cd4d18 2020-02-03 stsp if (fseek(f, 0, SEEK_SET) == -1) {
2650 32cd4d18 2020-02-03 stsp error = got_ferror(f, GOT_ERR_IO);
2651 32cd4d18 2020-02-03 stsp goto done;
2652 32cd4d18 2020-02-03 stsp }
2653 32cd4d18 2020-02-03 stsp *description = calloc(len + 1, sizeof(**description));
2654 32cd4d18 2020-02-03 stsp if (*description == NULL) {
2655 32cd4d18 2020-02-03 stsp error = got_error_from_errno("calloc");
2656 32cd4d18 2020-02-03 stsp goto done;
2657 32cd4d18 2020-02-03 stsp }
2658 32cd4d18 2020-02-03 stsp
2659 32cd4d18 2020-02-03 stsp n = fread(*description, 1, len, f);
2660 1ab830c1 2020-02-03 stsp if (n == 0 && ferror(f))
2661 32cd4d18 2020-02-03 stsp error = got_ferror(f, GOT_ERR_IO);
2662 32cd4d18 2020-02-03 stsp done:
2663 32cd4d18 2020-02-03 stsp if (f != NULL && fclose(f) == -1 && error == NULL)
2664 32cd4d18 2020-02-03 stsp error = got_error_from_errno("fclose");
2665 2c251c14 2020-01-15 tracey free(d_file);
2666 32cd4d18 2020-02-03 stsp return error;
2667 2c251c14 2020-01-15 tracey }
2668 2c251c14 2020-01-15 tracey
2669 55ccf528 2020-02-03 stsp static const struct got_error *
2670 55ccf528 2020-02-03 stsp gw_get_time_str(char **repo_age, time_t committer_time, int ref_tm)
2671 474370cb 2020-01-15 tracey {
2672 474370cb 2020-01-15 tracey struct tm tm;
2673 474370cb 2020-01-15 tracey time_t diff_time;
2674 474370cb 2020-01-15 tracey char *years = "years ago", *months = "months ago";
2675 474370cb 2020-01-15 tracey char *weeks = "weeks ago", *days = "days ago", *hours = "hours ago";
2676 474370cb 2020-01-15 tracey char *minutes = "minutes ago", *seconds = "seconds ago";
2677 474370cb 2020-01-15 tracey char *now = "right now";
2678 55ccf528 2020-02-03 stsp char *s;
2679 6c6c85af 2020-01-15 tracey char datebuf[29];
2680 474370cb 2020-01-15 tracey
2681 55ccf528 2020-02-03 stsp *repo_age = NULL;
2682 55ccf528 2020-02-03 stsp
2683 474370cb 2020-01-15 tracey switch (ref_tm) {
2684 474370cb 2020-01-15 tracey case TM_DIFF:
2685 474370cb 2020-01-15 tracey diff_time = time(NULL) - committer_time;
2686 474370cb 2020-01-15 tracey if (diff_time > 60 * 60 * 24 * 365 * 2) {
2687 55ccf528 2020-02-03 stsp if (asprintf(repo_age, "%lld %s",
2688 88d59c36 2020-01-29 stsp (diff_time / 60 / 60 / 24 / 365), years) == -1)
2689 55ccf528 2020-02-03 stsp return got_error_from_errno("asprintf");
2690 474370cb 2020-01-15 tracey } else if (diff_time > 60 * 60 * 24 * (365 / 12) * 2) {
2691 55ccf528 2020-02-03 stsp if (asprintf(repo_age, "%lld %s",
2692 474370cb 2020-01-15 tracey (diff_time / 60 / 60 / 24 / (365 / 12)),
2693 88d59c36 2020-01-29 stsp months) == -1)
2694 55ccf528 2020-02-03 stsp return got_error_from_errno("asprintf");
2695 474370cb 2020-01-15 tracey } else if (diff_time > 60 * 60 * 24 * 7 * 2) {
2696 55ccf528 2020-02-03 stsp if (asprintf(repo_age, "%lld %s",
2697 88d59c36 2020-01-29 stsp (diff_time / 60 / 60 / 24 / 7), weeks) == -1)
2698 55ccf528 2020-02-03 stsp return got_error_from_errno("asprintf");
2699 474370cb 2020-01-15 tracey } else if (diff_time > 60 * 60 * 24 * 2) {
2700 55ccf528 2020-02-03 stsp if (asprintf(repo_age, "%lld %s",
2701 88d59c36 2020-01-29 stsp (diff_time / 60 / 60 / 24), days) == -1)
2702 55ccf528 2020-02-03 stsp return got_error_from_errno("asprintf");
2703 474370cb 2020-01-15 tracey } else if (diff_time > 60 * 60 * 2) {
2704 55ccf528 2020-02-03 stsp if (asprintf(repo_age, "%lld %s",
2705 88d59c36 2020-01-29 stsp (diff_time / 60 / 60), hours) == -1)
2706 55ccf528 2020-02-03 stsp return got_error_from_errno("asprintf");
2707 474370cb 2020-01-15 tracey } else if (diff_time > 60 * 2) {
2708 55ccf528 2020-02-03 stsp if (asprintf(repo_age, "%lld %s", (diff_time / 60),
2709 88d59c36 2020-01-29 stsp minutes) == -1)
2710 55ccf528 2020-02-03 stsp return got_error_from_errno("asprintf");
2711 474370cb 2020-01-15 tracey } else if (diff_time > 2) {
2712 55ccf528 2020-02-03 stsp if (asprintf(repo_age, "%lld %s", diff_time,
2713 88d59c36 2020-01-29 stsp seconds) == -1)
2714 55ccf528 2020-02-03 stsp return got_error_from_errno("asprintf");
2715 474370cb 2020-01-15 tracey } else {
2716 55ccf528 2020-02-03 stsp if (asprintf(repo_age, "%s", now) == -1)
2717 55ccf528 2020-02-03 stsp return got_error_from_errno("asprintf");
2718 474370cb 2020-01-15 tracey }
2719 474370cb 2020-01-15 tracey break;
2720 474370cb 2020-01-15 tracey case TM_LONG:
2721 474370cb 2020-01-15 tracey if (gmtime_r(&committer_time, &tm) == NULL)
2722 55ccf528 2020-02-03 stsp return got_error_from_errno("gmtime_r");
2723 474370cb 2020-01-15 tracey
2724 474370cb 2020-01-15 tracey s = asctime_r(&tm, datebuf);
2725 474370cb 2020-01-15 tracey if (s == NULL)
2726 55ccf528 2020-02-03 stsp return got_error_from_errno("asctime_r");
2727 474370cb 2020-01-15 tracey
2728 55ccf528 2020-02-03 stsp if (asprintf(repo_age, "%s UTC", datebuf) == -1)
2729 55ccf528 2020-02-03 stsp return got_error_from_errno("asprintf");
2730 474370cb 2020-01-15 tracey break;
2731 474370cb 2020-01-15 tracey }
2732 55ccf528 2020-02-03 stsp return NULL;
2733 474370cb 2020-01-15 tracey }
2734 474370cb 2020-01-15 tracey
2735 d126c1b7 2020-01-29 stsp static const struct got_error *
2736 d126c1b7 2020-01-29 stsp gw_get_repo_age(char **repo_age, struct gw_trans *gw_trans, char *dir,
2737 2011c142 2020-02-14 stsp const char *refname, int ref_tm)
2738 2c251c14 2020-01-15 tracey {
2739 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
2740 2c251c14 2020-01-15 tracey struct got_repository *repo = NULL;
2741 2c251c14 2020-01-15 tracey struct got_commit_object *commit = NULL;
2742 2c251c14 2020-01-15 tracey struct got_reflist_head refs;
2743 2c251c14 2020-01-15 tracey struct got_reflist_entry *re;
2744 474370cb 2020-01-15 tracey time_t committer_time = 0, cmp_time = 0;
2745 a0f36e03 2020-01-28 stsp
2746 d126c1b7 2020-01-29 stsp *repo_age = NULL;
2747 a0f36e03 2020-01-28 stsp SIMPLEQ_INIT(&refs);
2748 387a29ba 2020-01-15 tracey
2749 55ccf528 2020-02-03 stsp if (gw_trans->gw_conf->got_show_repo_age == 0)
2750 d126c1b7 2020-01-29 stsp return NULL;
2751 87f9ebf5 2020-01-15 tracey
2752 deac617c 2020-02-14 tracey if (gw_trans->repo)
2753 deac617c 2020-02-14 tracey repo = gw_trans->repo;
2754 deac617c 2020-02-14 tracey else {
2755 deac617c 2020-02-14 tracey error = got_repo_open(&repo, dir, NULL);
2756 deac617c 2020-02-14 tracey if (error)
2757 deac617c 2020-02-14 tracey return error;
2758 deac617c 2020-02-14 tracey }
2759 2c251c14 2020-01-15 tracey
2760 2011c142 2020-02-14 stsp error = got_ref_list(&refs, repo, "refs/heads",
2761 2011c142 2020-02-14 stsp got_ref_cmp_by_name, NULL);
2762 ec46ccd7 2020-01-15 tracey if (error)
2763 d126c1b7 2020-01-29 stsp goto done;
2764 2c251c14 2020-01-15 tracey
2765 2011c142 2020-02-14 stsp /*
2766 2011c142 2020-02-14 stsp * Find the youngest branch tip in the repository, or the age of
2767 2011c142 2020-02-14 stsp * the a specific branch tip if a name was provided by the caller.
2768 2011c142 2020-02-14 stsp */
2769 2c251c14 2020-01-15 tracey SIMPLEQ_FOREACH(re, &refs, entry) {
2770 2011c142 2020-02-14 stsp struct got_object_id *id = NULL;
2771 17d4bf8d 2020-02-14 stsp
2772 2011c142 2020-02-14 stsp if (refname && strcmp(got_ref_get_name(re->ref), refname) != 0)
2773 2011c142 2020-02-14 stsp continue;
2774 4e8d6e3e 2020-02-14 tracey
2775 2011c142 2020-02-14 stsp error = got_ref_resolve(&id, repo, re->ref);
2776 ec46ccd7 2020-01-15 tracey if (error)
2777 d126c1b7 2020-01-29 stsp goto done;
2778 2c251c14 2020-01-15 tracey
2779 2c251c14 2020-01-15 tracey error = got_object_open_as_commit(&commit, repo, id);
2780 2011c142 2020-02-14 stsp free(id);
2781 ec46ccd7 2020-01-15 tracey if (error)
2782 d126c1b7 2020-01-29 stsp goto done;
2783 2c251c14 2020-01-15 tracey
2784 2c251c14 2020-01-15 tracey committer_time =
2785 2c251c14 2020-01-15 tracey got_object_commit_get_committer_time(commit);
2786 2011c142 2020-02-14 stsp got_object_commit_close(commit);
2787 387a29ba 2020-01-15 tracey if (cmp_time < committer_time)
2788 2c251c14 2020-01-15 tracey cmp_time = committer_time;
2789 2011c142 2020-02-14 stsp
2790 2011c142 2020-02-14 stsp if (refname)
2791 2011c142 2020-02-14 stsp break;
2792 2c251c14 2020-01-15 tracey }
2793 2c251c14 2020-01-15 tracey
2794 474370cb 2020-01-15 tracey if (cmp_time != 0) {
2795 2c251c14 2020-01-15 tracey committer_time = cmp_time;
2796 55ccf528 2020-02-03 stsp error = gw_get_time_str(repo_age, committer_time, ref_tm);
2797 d126c1b7 2020-01-29 stsp }
2798 d126c1b7 2020-01-29 stsp done:
2799 2c251c14 2020-01-15 tracey got_ref_list_free(&refs);
2800 deac617c 2020-02-14 tracey if (gw_trans->repo == NULL)
2801 deac617c 2020-02-14 tracey got_repo_close(repo);
2802 d126c1b7 2020-01-29 stsp return error;
2803 ec46ccd7 2020-01-15 tracey }
2804 ec46ccd7 2020-01-15 tracey
2805 83eb9a68 2020-02-03 stsp static const struct got_error *
2806 38b240fb 2020-02-06 tracey gw_output_diff(struct gw_trans *gw_trans, struct gw_header *header)
2807 ec46ccd7 2020-01-15 tracey {
2808 ec46ccd7 2020-01-15 tracey const struct got_error *error;
2809 ec46ccd7 2020-01-15 tracey FILE *f = NULL;
2810 ec46ccd7 2020-01-15 tracey struct got_object_id *id1 = NULL, *id2 = NULL;
2811 f7cc9480 2020-02-05 tracey char *label1 = NULL, *label2 = NULL, *line = NULL;
2812 05ce9a79 2020-01-24 tracey int obj_type;
2813 f7cc9480 2020-02-05 tracey size_t linesize = 0;
2814 83eb9a68 2020-02-03 stsp ssize_t linelen;
2815 f7cc9480 2020-02-05 tracey enum kcgi_err kerr = KCGI_OK;
2816 ec46ccd7 2020-01-15 tracey
2817 ec46ccd7 2020-01-15 tracey f = got_opentemp();
2818 ec46ccd7 2020-01-15 tracey if (f == NULL)
2819 ec46ccd7 2020-01-15 tracey return NULL;
2820 ec46ccd7 2020-01-15 tracey
2821 5c65becf 2020-02-13 tracey if (header->parent_id != NULL &&
2822 5c65becf 2020-02-13 tracey strncmp(header->parent_id, "/dev/null", 9) != 0) {
2823 05ce9a79 2020-01-24 tracey error = got_repo_match_object_id(&id1, &label1,
2824 deac617c 2020-02-14 tracey header->parent_id, GOT_OBJ_TYPE_ANY, 1, gw_trans->repo);
2825 05ce9a79 2020-01-24 tracey if (error)
2826 05ce9a79 2020-01-24 tracey goto done;
2827 05ce9a79 2020-01-24 tracey }
2828 ec46ccd7 2020-01-15 tracey
2829 90f16cb8 2020-01-24 tracey error = got_repo_match_object_id(&id2, &label2,
2830 deac617c 2020-02-14 tracey header->commit_id, GOT_OBJ_TYPE_ANY, 1, gw_trans->repo);
2831 90f16cb8 2020-01-24 tracey if (error)
2832 90f16cb8 2020-01-24 tracey goto done;
2833 ec46ccd7 2020-01-15 tracey
2834 deac617c 2020-02-14 tracey error = got_object_get_type(&obj_type, gw_trans->repo, id2);
2835 90f16cb8 2020-01-24 tracey if (error)
2836 90f16cb8 2020-01-24 tracey goto done;
2837 05ce9a79 2020-01-24 tracey switch (obj_type) {
2838 ec46ccd7 2020-01-15 tracey case GOT_OBJ_TYPE_BLOB:
2839 90f16cb8 2020-01-24 tracey error = got_diff_objects_as_blobs(id1, id2, NULL, NULL, 3, 0,
2840 deac617c 2020-02-14 tracey gw_trans->repo, f);
2841 ec46ccd7 2020-01-15 tracey break;
2842 ec46ccd7 2020-01-15 tracey case GOT_OBJ_TYPE_TREE:
2843 90f16cb8 2020-01-24 tracey error = got_diff_objects_as_trees(id1, id2, "", "", 3, 0,
2844 deac617c 2020-02-14 tracey gw_trans->repo, f);
2845 ec46ccd7 2020-01-15 tracey break;
2846 ec46ccd7 2020-01-15 tracey case GOT_OBJ_TYPE_COMMIT:
2847 90f16cb8 2020-01-24 tracey error = got_diff_objects_as_commits(id1, id2, 3, 0,
2848 deac617c 2020-02-14 tracey gw_trans->repo, f);
2849 ec46ccd7 2020-01-15 tracey break;
2850 ec46ccd7 2020-01-15 tracey default:
2851 ec46ccd7 2020-01-15 tracey error = got_error(GOT_ERR_OBJ_TYPE);
2852 ec46ccd7 2020-01-15 tracey }
2853 b8b04565 2020-02-02 tracey if (error)
2854 b8b04565 2020-02-02 tracey goto done;
2855 b8b04565 2020-02-02 tracey
2856 d4729381 2020-02-03 stsp if (fseek(f, 0, SEEK_SET) == -1) {
2857 d4729381 2020-02-03 stsp error = got_ferror(f, GOT_ERR_IO);
2858 ec46ccd7 2020-01-15 tracey goto done;
2859 d4729381 2020-02-03 stsp }
2860 ec46ccd7 2020-01-15 tracey
2861 83eb9a68 2020-02-03 stsp while ((linelen = getline(&line, &linesize, f)) != -1) {
2862 f7cc9480 2020-02-05 tracey error = gw_colordiff_line(gw_trans, line);
2863 ec46ccd7 2020-01-15 tracey if (error)
2864 b8b04565 2020-02-02 tracey goto done;
2865 f7cc9480 2020-02-05 tracey /* XXX: KHTML_PRETTY breaks this */
2866 f7cc9480 2020-02-05 tracey kerr = khtml_puts(gw_trans->gw_html_req, line);
2867 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2868 83eb9a68 2020-02-03 stsp goto done;
2869 f7cc9480 2020-02-05 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
2870 f7cc9480 2020-02-05 tracey if (kerr != KCGI_OK)
2871 b8b04565 2020-02-02 tracey goto done;
2872 ec46ccd7 2020-01-15 tracey }
2873 f7cc9480 2020-02-05 tracey if (linelen == -1 && ferror(f))
2874 83eb9a68 2020-02-03 stsp error = got_error_from_errno("getline");
2875 ec46ccd7 2020-01-15 tracey done:
2876 d4729381 2020-02-03 stsp if (f && fclose(f) == -1 && error == NULL)
2877 d4729381 2020-02-03 stsp error = got_error_from_errno("fclose");
2878 d4729381 2020-02-03 stsp free(line);
2879 ec46ccd7 2020-01-15 tracey free(label1);
2880 ec46ccd7 2020-01-15 tracey free(label2);
2881 ec46ccd7 2020-01-15 tracey free(id1);
2882 ec46ccd7 2020-01-15 tracey free(id2);
2883 ec46ccd7 2020-01-15 tracey
2884 f7cc9480 2020-02-05 tracey if (error == NULL && kerr != KCGI_OK)
2885 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
2886 83eb9a68 2020-02-03 stsp return error;
2887 2c251c14 2020-01-15 tracey }
2888 2c251c14 2020-01-15 tracey
2889 9a1cc63f 2020-02-03 stsp static const struct got_error *
2890 9a1cc63f 2020-02-03 stsp gw_get_repo_owner(char **owner, struct gw_trans *gw_trans, char *dir)
2891 9a1cc63f 2020-02-03 stsp {
2892 9a1cc63f 2020-02-03 stsp const struct got_error *error = NULL;
2893 9a1cc63f 2020-02-03 stsp struct got_repository *repo;
2894 9a1cc63f 2020-02-03 stsp const char *gitconfig_owner;
2895 2c251c14 2020-01-15 tracey
2896 9a1cc63f 2020-02-03 stsp *owner = NULL;
2897 2c251c14 2020-01-15 tracey
2898 9a1cc63f 2020-02-03 stsp if (gw_trans->gw_conf->got_show_repo_owner == 0)
2899 9a1cc63f 2020-02-03 stsp return NULL;
2900 2c251c14 2020-01-15 tracey
2901 9a1cc63f 2020-02-03 stsp error = got_repo_open(&repo, dir, NULL);
2902 9a1cc63f 2020-02-03 stsp if (error)
2903 9a1cc63f 2020-02-03 stsp return error;
2904 9a1cc63f 2020-02-03 stsp gitconfig_owner = got_repo_get_gitconfig_owner(repo);
2905 d1635ae4 2020-02-13 tracey if (gitconfig_owner) {
2906 d1635ae4 2020-02-13 tracey *owner = strdup(gitconfig_owner);
2907 d1635ae4 2020-02-13 tracey if (*owner == NULL)
2908 d1635ae4 2020-02-13 tracey error = got_error_from_errno("strdup");
2909 d1635ae4 2020-02-13 tracey }
2910 9a1cc63f 2020-02-03 stsp got_repo_close(repo);
2911 9a1cc63f 2020-02-03 stsp return error;
2912 2c251c14 2020-01-15 tracey }
2913 2c251c14 2020-01-15 tracey
2914 59d3c40e 2020-02-03 stsp static const struct got_error *
2915 59d3c40e 2020-02-03 stsp gw_get_clone_url(char **url, struct gw_trans *gw_trans, char *dir)
2916 2c251c14 2020-01-15 tracey {
2917 59d3c40e 2020-02-03 stsp const struct got_error *error = NULL;
2918 2c251c14 2020-01-15 tracey FILE *f;
2919 59d3c40e 2020-02-03 stsp char *d_file = NULL;
2920 2c251c14 2020-01-15 tracey unsigned int len;
2921 59d3c40e 2020-02-03 stsp size_t n;
2922 2c251c14 2020-01-15 tracey
2923 59d3c40e 2020-02-03 stsp *url = NULL;
2924 2c251c14 2020-01-15 tracey
2925 59d3c40e 2020-02-03 stsp if (asprintf(&d_file, "%s/cloneurl", dir) == -1)
2926 59d3c40e 2020-02-03 stsp return got_error_from_errno("asprintf");
2927 2c251c14 2020-01-15 tracey
2928 59d3c40e 2020-02-03 stsp f = fopen(d_file, "r");
2929 59d3c40e 2020-02-03 stsp if (f == NULL) {
2930 59d3c40e 2020-02-03 stsp if (errno != ENOENT && errno != EACCES)
2931 59d3c40e 2020-02-03 stsp error = got_error_from_errno2("fopen", d_file);
2932 59d3c40e 2020-02-03 stsp goto done;
2933 59d3c40e 2020-02-03 stsp }
2934 59d3c40e 2020-02-03 stsp
2935 59d3c40e 2020-02-03 stsp if (fseek(f, 0, SEEK_END) == -1) {
2936 59d3c40e 2020-02-03 stsp error = got_ferror(f, GOT_ERR_IO);
2937 59d3c40e 2020-02-03 stsp goto done;
2938 59d3c40e 2020-02-03 stsp }
2939 59d3c40e 2020-02-03 stsp len = ftell(f);
2940 59d3c40e 2020-02-03 stsp if (len == -1) {
2941 59d3c40e 2020-02-03 stsp error = got_ferror(f, GOT_ERR_IO);
2942 59d3c40e 2020-02-03 stsp goto done;
2943 59d3c40e 2020-02-03 stsp }
2944 59d3c40e 2020-02-03 stsp if (fseek(f, 0, SEEK_SET) == -1) {
2945 59d3c40e 2020-02-03 stsp error = got_ferror(f, GOT_ERR_IO);
2946 59d3c40e 2020-02-03 stsp goto done;
2947 59d3c40e 2020-02-03 stsp }
2948 2c251c14 2020-01-15 tracey
2949 59d3c40e 2020-02-03 stsp *url = calloc(len + 1, sizeof(**url));
2950 59d3c40e 2020-02-03 stsp if (*url == NULL) {
2951 59d3c40e 2020-02-03 stsp error = got_error_from_errno("calloc");
2952 59d3c40e 2020-02-03 stsp goto done;
2953 59d3c40e 2020-02-03 stsp }
2954 2c251c14 2020-01-15 tracey
2955 59d3c40e 2020-02-03 stsp n = fread(*url, 1, len, f);
2956 59d3c40e 2020-02-03 stsp if (n == 0 && ferror(f))
2957 59d3c40e 2020-02-03 stsp error = got_ferror(f, GOT_ERR_IO);
2958 59d3c40e 2020-02-03 stsp done:
2959 59d3c40e 2020-02-03 stsp if (f && fclose(f) == -1 && error == NULL)
2960 59d3c40e 2020-02-03 stsp error = got_error_from_errno("fclose");
2961 2c251c14 2020-01-15 tracey free(d_file);
2962 59d3c40e 2020-02-03 stsp return NULL;
2963 8d4d2453 2020-01-15 tracey }
2964 8d4d2453 2020-01-15 tracey
2965 6eccd105 2020-02-03 stsp static const struct got_error *
2966 38b240fb 2020-02-06 tracey gw_output_repo_tags(struct gw_trans *gw_trans, struct gw_header *header,
2967 38b240fb 2020-02-06 tracey int limit, int tag_type)
2968 8d4d2453 2020-01-15 tracey {
2969 87f9ebf5 2020-01-15 tracey const struct got_error *error = NULL;
2970 87f9ebf5 2020-01-15 tracey struct got_reflist_head refs;
2971 87f9ebf5 2020-01-15 tracey struct got_reflist_entry *re;
2972 38b240fb 2020-02-06 tracey char *age = NULL;
2973 ef2c200c 2020-02-07 tracey char *id_str = NULL, *newline, *href_commits = NULL;
2974 38b240fb 2020-02-06 tracey char *tag_commit0 = NULL, *href_tag = NULL, *href_briefs = NULL;
2975 6eccd105 2020-02-03 stsp struct got_tag_object *tag = NULL;
2976 38b240fb 2020-02-06 tracey enum kcgi_err kerr = KCGI_OK;
2977 ff4bb25f 2020-02-19 tracey int summary_header_displayed = 0, start_tag = 0, chk_next = 0;
2978 ff4bb25f 2020-02-19 tracey int prev_set = 0, tag_count = 0;
2979 8d4d2453 2020-01-15 tracey
2980 a0f36e03 2020-01-28 stsp SIMPLEQ_INIT(&refs);
2981 a0f36e03 2020-01-28 stsp
2982 deac617c 2020-02-14 tracey error = got_ref_list(&refs, gw_trans->repo, "refs/tags",
2983 deac617c 2020-02-14 tracey got_ref_cmp_tags, gw_trans->repo);
2984 ec46ccd7 2020-01-15 tracey if (error)
2985 87f9ebf5 2020-01-15 tracey goto done;
2986 87f9ebf5 2020-01-15 tracey
2987 87f9ebf5 2020-01-15 tracey SIMPLEQ_FOREACH(re, &refs, entry) {
2988 87f9ebf5 2020-01-15 tracey const char *refname;
2989 4ff7391f 2020-01-28 tracey const char *tagger;
2990 6eccd105 2020-02-03 stsp const char *tag_commit;
2991 87f9ebf5 2020-01-15 tracey time_t tagger_time;
2992 87f9ebf5 2020-01-15 tracey struct got_object_id *id;
2993 ef2c200c 2020-02-07 tracey struct got_commit_object *commit = NULL;
2994 87f9ebf5 2020-01-15 tracey
2995 87f9ebf5 2020-01-15 tracey refname = got_ref_get_name(re->ref);
2996 87f9ebf5 2020-01-15 tracey if (strncmp(refname, "refs/tags/", 10) != 0)
2997 87f9ebf5 2020-01-15 tracey continue;
2998 87f9ebf5 2020-01-15 tracey refname += 10;
2999 87f9ebf5 2020-01-15 tracey
3000 deac617c 2020-02-14 tracey error = got_ref_resolve(&id, gw_trans->repo, re->ref);
3001 87f9ebf5 2020-01-15 tracey if (error)
3002 87f9ebf5 2020-01-15 tracey goto done;
3003 38b240fb 2020-02-06 tracey
3004 deac617c 2020-02-14 tracey error = got_object_open_as_tag(&tag, gw_trans->repo, id);
3005 38b240fb 2020-02-06 tracey if (error) {
3006 ef2c200c 2020-02-07 tracey if (error->code != GOT_ERR_OBJ_TYPE) {
3007 ef2c200c 2020-02-07 tracey free(id);
3008 ef2c200c 2020-02-07 tracey goto done;
3009 ef2c200c 2020-02-07 tracey }
3010 ef2c200c 2020-02-07 tracey /* "lightweight" tag */
3011 deac617c 2020-02-14 tracey error = got_object_open_as_commit(&commit,
3012 deac617c 2020-02-14 tracey gw_trans->repo, id);
3013 ef2c200c 2020-02-07 tracey if (error) {
3014 ef2c200c 2020-02-07 tracey free(id);
3015 ef2c200c 2020-02-07 tracey goto done;
3016 ef2c200c 2020-02-07 tracey }
3017 ef2c200c 2020-02-07 tracey tagger = got_object_commit_get_committer(commit);
3018 ef2c200c 2020-02-07 tracey tagger_time =
3019 ef2c200c 2020-02-07 tracey got_object_commit_get_committer_time(commit);
3020 ef2c200c 2020-02-07 tracey error = got_object_id_str(&id_str, id);
3021 ef2c200c 2020-02-07 tracey free(id);
3022 ef2c200c 2020-02-07 tracey } else {
3023 ef2c200c 2020-02-07 tracey free(id);
3024 ef2c200c 2020-02-07 tracey tagger = got_object_tag_get_tagger(tag);
3025 ef2c200c 2020-02-07 tracey tagger_time = got_object_tag_get_tagger_time(tag);
3026 ef2c200c 2020-02-07 tracey error = got_object_id_str(&id_str,
3027 ef2c200c 2020-02-07 tracey got_object_tag_get_object_id(tag));
3028 38b240fb 2020-02-06 tracey }
3029 87f9ebf5 2020-01-15 tracey if (error)
3030 87f9ebf5 2020-01-15 tracey goto done;
3031 87f9ebf5 2020-01-15 tracey
3032 38b240fb 2020-02-06 tracey if (tag_type == TAGFULL && strncmp(id_str, header->commit_id,
3033 38b240fb 2020-02-06 tracey strlen(id_str)) != 0)
3034 38b240fb 2020-02-06 tracey continue;
3035 38b240fb 2020-02-06 tracey
3036 ff4bb25f 2020-02-19 tracey if (tag_type == TAGBRIEF && gw_trans->commit_id &&
3037 ff4bb25f 2020-02-19 tracey start_tag == 0 && strncmp(id_str, header->commit_id,
3038 ff4bb25f 2020-02-19 tracey strlen(id_str)) != 0) {
3039 ff4bb25f 2020-02-19 tracey continue;
3040 ff4bb25f 2020-02-19 tracey } else {
3041 ff4bb25f 2020-02-19 tracey start_tag = 1;
3042 ff4bb25f 2020-02-19 tracey }
3043 ff4bb25f 2020-02-19 tracey
3044 ff4bb25f 2020-02-19 tracey tag_count++;
3045 ff4bb25f 2020-02-19 tracey
3046 ff4bb25f 2020-02-19 tracey if (prev_set == 0 && start_tag == 1) {
3047 ff4bb25f 2020-02-19 tracey gw_trans->next_prev_id = strdup(id_str);
3048 ff4bb25f 2020-02-19 tracey if (gw_trans->next_prev_id == NULL) {
3049 ff4bb25f 2020-02-19 tracey error = got_error_from_errno("strdup");
3050 ff4bb25f 2020-02-19 tracey goto done;
3051 ff4bb25f 2020-02-19 tracey }
3052 ff4bb25f 2020-02-19 tracey prev_set = 1;
3053 ff4bb25f 2020-02-19 tracey }
3054 ff4bb25f 2020-02-19 tracey
3055 ff4bb25f 2020-02-19 tracey if (chk_next) {
3056 ff4bb25f 2020-02-19 tracey gw_trans->next_id = strdup(id_str);
3057 ff4bb25f 2020-02-19 tracey if (gw_trans->next_id == NULL)
3058 ff4bb25f 2020-02-19 tracey error = got_error_from_errno("strdup");
3059 ff4bb25f 2020-02-19 tracey goto done;
3060 ff4bb25f 2020-02-19 tracey }
3061 ff4bb25f 2020-02-19 tracey
3062 ef2c200c 2020-02-07 tracey if (commit) {
3063 ef2c200c 2020-02-07 tracey error = got_object_commit_get_logmsg(&tag_commit0,
3064 ef2c200c 2020-02-07 tracey commit);
3065 ef2c200c 2020-02-07 tracey if (error)
3066 ef2c200c 2020-02-07 tracey goto done;
3067 ef2c200c 2020-02-07 tracey got_object_commit_close(commit);
3068 ef2c200c 2020-02-07 tracey } else {
3069 ef2c200c 2020-02-07 tracey tag_commit0 = strdup(got_object_tag_get_message(tag));
3070 ef2c200c 2020-02-07 tracey if (tag_commit0 == NULL) {
3071 ef2c200c 2020-02-07 tracey error = got_error_from_errno("strdup");
3072 ef2c200c 2020-02-07 tracey goto done;
3073 ef2c200c 2020-02-07 tracey }
3074 87f9ebf5 2020-01-15 tracey }
3075 87f9ebf5 2020-01-15 tracey
3076 f2f46662 2020-01-23 tracey tag_commit = tag_commit0;
3077 f2f46662 2020-01-23 tracey while (*tag_commit == '\n')
3078 f2f46662 2020-01-23 tracey tag_commit++;
3079 87f9ebf5 2020-01-15 tracey
3080 87f9ebf5 2020-01-15 tracey switch (tag_type) {
3081 87f9ebf5 2020-01-15 tracey case TAGBRIEF:
3082 f2f46662 2020-01-23 tracey newline = strchr(tag_commit, '\n');
3083 87f9ebf5 2020-01-15 tracey if (newline)
3084 87f9ebf5 2020-01-15 tracey *newline = '\0';
3085 87f9ebf5 2020-01-15 tracey
3086 38b240fb 2020-02-06 tracey if (summary_header_displayed == 0) {
3087 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req,
3088 38b240fb 2020-02-06 tracey KELEM_DIV, KATTR_ID,
3089 38b240fb 2020-02-06 tracey "summary_tags_title_wrapper", KATTR__MAX);
3090 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3091 38b240fb 2020-02-06 tracey goto done;
3092 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req,
3093 38b240fb 2020-02-06 tracey KELEM_DIV, KATTR_ID,
3094 38b240fb 2020-02-06 tracey "summary_tags_title", KATTR__MAX);
3095 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3096 38b240fb 2020-02-06 tracey goto done;
3097 38b240fb 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req,
3098 38b240fb 2020-02-06 tracey "Tags");
3099 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3100 38b240fb 2020-02-06 tracey goto done;
3101 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req,
3102 38b240fb 2020-02-06 tracey 2);
3103 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3104 38b240fb 2020-02-06 tracey goto done;
3105 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req,
3106 38b240fb 2020-02-06 tracey KELEM_DIV, KATTR_ID,
3107 38b240fb 2020-02-06 tracey "summary_tags_content", KATTR__MAX);
3108 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3109 38b240fb 2020-02-06 tracey goto done;
3110 38b240fb 2020-02-06 tracey summary_header_displayed = 1;
3111 38b240fb 2020-02-06 tracey }
3112 38b240fb 2020-02-06 tracey
3113 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
3114 ff4bb25f 2020-02-19 tracey KATTR_ID, "tag_wrapper", KATTR__MAX);
3115 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3116 38b240fb 2020-02-06 tracey goto done;
3117 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
3118 ff4bb25f 2020-02-19 tracey KATTR_ID, "tag_age", KATTR__MAX);
3119 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3120 38b240fb 2020-02-06 tracey goto done;
3121 55ccf528 2020-02-03 stsp error = gw_get_time_str(&age, tagger_time, TM_DIFF);
3122 55ccf528 2020-02-03 stsp if (error)
3123 87f9ebf5 2020-01-15 tracey goto done;
3124 38b240fb 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req,
3125 38b240fb 2020-02-06 tracey age ? age : "");
3126 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3127 38b240fb 2020-02-06 tracey goto done;
3128 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
3129 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3130 38b240fb 2020-02-06 tracey goto done;
3131 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
3132 ff4bb25f 2020-02-19 tracey KATTR_ID, "tag", KATTR__MAX);
3133 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3134 38b240fb 2020-02-06 tracey goto done;
3135 38b240fb 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req, refname);
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_closeelem(gw_trans->gw_html_req, 1);
3139 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3140 38b240fb 2020-02-06 tracey goto done;
3141 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
3142 ff4bb25f 2020-02-19 tracey KATTR_ID, "tag_name", KATTR__MAX);
3143 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3144 dad0fde4 2020-02-06 tracey goto done;
3145 12003b6a 2020-04-14 tracey
3146 12003b6a 2020-04-14 tracey href_tag = khttp_urlpart(NULL, NULL, "gotweb", "path",
3147 12003b6a 2020-04-14 tracey gw_trans->repo_name, "action", "tag", "commit",
3148 12003b6a 2020-04-14 tracey id_str, NULL);
3149 19ff7638 2020-04-14 tracey if (href_tag == NULL) {
3150 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
3151 19ff7638 2020-04-14 tracey goto done;
3152 19ff7638 2020-04-14 tracey }
3153 056e30c8 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
3154 056e30c8 2020-02-06 tracey KATTR_HREF, href_tag, KATTR__MAX);
3155 056e30c8 2020-02-06 tracey if (kerr != KCGI_OK)
3156 056e30c8 2020-02-06 tracey goto done;
3157 38b240fb 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req, tag_commit);
3158 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3159 38b240fb 2020-02-06 tracey goto done;
3160 dad0fde4 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 3);
3161 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3162 38b240fb 2020-02-06 tracey goto done;
3163 87f9ebf5 2020-01-15 tracey
3164 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
3165 38b240fb 2020-02-06 tracey KATTR_ID, "navs_wrapper", 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_attr(gw_trans->gw_html_req, KELEM_DIV,
3169 38b240fb 2020-02-06 tracey KATTR_ID, "navs", KATTR__MAX);
3170 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3171 38b240fb 2020-02-06 tracey goto done;
3172 38b240fb 2020-02-06 tracey
3173 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
3174 38b240fb 2020-02-06 tracey KATTR_HREF, href_tag, KATTR__MAX);
3175 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3176 38b240fb 2020-02-06 tracey goto done;
3177 38b240fb 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req, "tag");
3178 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3179 38b240fb 2020-02-06 tracey goto done;
3180 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
3181 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3182 38b240fb 2020-02-06 tracey goto done;
3183 87f9ebf5 2020-01-15 tracey
3184 38b240fb 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req, " | ");
3185 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3186 87f9ebf5 2020-01-15 tracey goto done;
3187 12003b6a 2020-04-14 tracey
3188 12003b6a 2020-04-14 tracey href_briefs = khttp_urlpart(NULL, NULL, "gotweb",
3189 12003b6a 2020-04-14 tracey "path", gw_trans->repo_name, "action", "briefs",
3190 12003b6a 2020-04-14 tracey "commit", id_str, NULL);
3191 19ff7638 2020-04-14 tracey if (href_briefs == NULL) {
3192 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
3193 19ff7638 2020-04-14 tracey goto done;
3194 19ff7638 2020-04-14 tracey }
3195 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
3196 38b240fb 2020-02-06 tracey KATTR_HREF, href_briefs, KATTR__MAX);
3197 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3198 38b240fb 2020-02-06 tracey goto done;
3199 38b240fb 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req,
3200 38b240fb 2020-02-06 tracey "commit briefs");
3201 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3202 38b240fb 2020-02-06 tracey goto done;
3203 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
3204 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3205 38b240fb 2020-02-06 tracey goto done;
3206 87f9ebf5 2020-01-15 tracey
3207 38b240fb 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req, " | ");
3208 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3209 38b240fb 2020-02-06 tracey goto done;
3210 38b240fb 2020-02-06 tracey
3211 12003b6a 2020-04-14 tracey href_commits = khttp_urlpart(NULL, NULL, "gotweb",
3212 12003b6a 2020-04-14 tracey "path", gw_trans->repo_name, "action", "commits",
3213 12003b6a 2020-04-14 tracey "commit", id_str, NULL);
3214 19ff7638 2020-04-14 tracey if (href_commits == NULL) {
3215 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
3216 19ff7638 2020-04-14 tracey goto done;
3217 19ff7638 2020-04-14 tracey }
3218 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
3219 38b240fb 2020-02-06 tracey KATTR_HREF, href_commits, KATTR__MAX);
3220 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3221 38b240fb 2020-02-06 tracey goto done;
3222 32b9f7ed 2020-04-14 tracey kerr = khtml_puts(gw_trans->gw_html_req, "commits");
3223 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3224 38b240fb 2020-02-06 tracey goto done;
3225 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 3);
3226 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3227 38b240fb 2020-02-06 tracey goto done;
3228 38b240fb 2020-02-06 tracey
3229 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
3230 38b240fb 2020-02-06 tracey KATTR_ID, "dotted_line", KATTR__MAX);
3231 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3232 38b240fb 2020-02-06 tracey goto done;
3233 ef2c200c 2020-02-07 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
3234 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3235 38b240fb 2020-02-06 tracey goto done;
3236 87f9ebf5 2020-01-15 tracey break;
3237 87f9ebf5 2020-01-15 tracey case TAGFULL:
3238 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
3239 38b240fb 2020-02-06 tracey KATTR_ID, "tag_info_date_title", KATTR__MAX);
3240 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3241 38b240fb 2020-02-06 tracey goto done;
3242 38b240fb 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Tag Date:");
3243 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3244 38b240fb 2020-02-06 tracey goto done;
3245 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
3246 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3247 38b240fb 2020-02-06 tracey goto done;
3248 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
3249 38b240fb 2020-02-06 tracey KATTR_ID, "tag_info_date", KATTR__MAX);
3250 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3251 38b240fb 2020-02-06 tracey goto done;
3252 55ccf528 2020-02-03 stsp error = gw_get_time_str(&age, tagger_time, TM_LONG);
3253 55ccf528 2020-02-03 stsp if (error)
3254 4ff7391f 2020-01-28 tracey goto done;
3255 38b240fb 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req,
3256 38b240fb 2020-02-06 tracey age ? age : "");
3257 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3258 070fee27 2020-02-03 stsp goto done;
3259 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
3260 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3261 38b240fb 2020-02-06 tracey goto done;
3262 38b240fb 2020-02-06 tracey
3263 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
3264 38b240fb 2020-02-06 tracey KATTR_ID, "tag_info_tagger_title", KATTR__MAX);
3265 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3266 38b240fb 2020-02-06 tracey goto done;
3267 38b240fb 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Tagger:");
3268 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3269 38b240fb 2020-02-06 tracey goto done;
3270 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
3271 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3272 38b240fb 2020-02-06 tracey goto done;
3273 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
3274 38b240fb 2020-02-06 tracey KATTR_ID, "tag_info_date", KATTR__MAX);
3275 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3276 38b240fb 2020-02-06 tracey goto done;
3277 38b240fb 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req, tagger);
3278 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3279 38b240fb 2020-02-06 tracey goto done;
3280 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
3281 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3282 38b240fb 2020-02-06 tracey goto done;
3283 38b240fb 2020-02-06 tracey
3284 38b240fb 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
3285 38b240fb 2020-02-06 tracey KATTR_ID, "tag_info", KATTR__MAX);
3286 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3287 38b240fb 2020-02-06 tracey goto done;
3288 78a9dab5 2020-02-07 tracey kerr = khttp_puts(gw_trans->gw_req, tag_commit);
3289 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3290 4ff7391f 2020-01-28 tracey goto done;
3291 87f9ebf5 2020-01-15 tracey break;
3292 87f9ebf5 2020-01-15 tracey default:
3293 87f9ebf5 2020-01-15 tracey break;
3294 87f9ebf5 2020-01-15 tracey }
3295 38b240fb 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
3296 38b240fb 2020-02-06 tracey if (kerr != KCGI_OK)
3297 6eccd105 2020-02-03 stsp goto done;
3298 87ca24ac 2020-02-04 tracey
3299 6eccd105 2020-02-03 stsp if (limit && --limit == 0)
3300 ff4bb25f 2020-02-19 tracey chk_next = 1;
3301 87f9ebf5 2020-01-15 tracey
3302 ef2c200c 2020-02-07 tracey if (tag)
3303 ef2c200c 2020-02-07 tracey got_object_tag_close(tag);
3304 6eccd105 2020-02-03 stsp tag = NULL;
3305 6c6c85af 2020-01-15 tracey free(id_str);
3306 6eccd105 2020-02-03 stsp id_str = NULL;
3307 6c6c85af 2020-01-15 tracey free(age);
3308 55ccf528 2020-02-03 stsp age = NULL;
3309 f2f46662 2020-01-23 tracey free(tag_commit0);
3310 6eccd105 2020-02-03 stsp tag_commit0 = NULL;
3311 38b240fb 2020-02-06 tracey free(href_tag);
3312 38b240fb 2020-02-06 tracey href_tag = NULL;
3313 38b240fb 2020-02-06 tracey free(href_briefs);
3314 38b240fb 2020-02-06 tracey href_briefs = NULL;
3315 38b240fb 2020-02-06 tracey free(href_commits);
3316 38b240fb 2020-02-06 tracey href_commits = NULL;
3317 ff4bb25f 2020-02-19 tracey }
3318 ff4bb25f 2020-02-19 tracey if (tag_count == 0) {
3319 ff4bb25f 2020-02-19 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
3320 ff4bb25f 2020-02-19 tracey "summary_tags_title_wrapper", KATTR__MAX);
3321 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
3322 ff4bb25f 2020-02-19 tracey goto done;
3323 ff4bb25f 2020-02-19 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
3324 ff4bb25f 2020-02-19 tracey "summary_tags_title", KATTR__MAX);
3325 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
3326 ff4bb25f 2020-02-19 tracey goto done;
3327 ff4bb25f 2020-02-19 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Tags");
3328 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
3329 ff4bb25f 2020-02-19 tracey goto done;
3330 ff4bb25f 2020-02-19 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
3331 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
3332 ff4bb25f 2020-02-19 tracey goto done;
3333 ff4bb25f 2020-02-19 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
3334 ff4bb25f 2020-02-19 tracey "summary_tags_content", KATTR__MAX);
3335 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
3336 ff4bb25f 2020-02-19 tracey goto done;
3337 ff4bb25f 2020-02-19 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
3338 ff4bb25f 2020-02-19 tracey "tags_info", KATTR__MAX);
3339 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
3340 ff4bb25f 2020-02-19 tracey goto done;
3341 ff4bb25f 2020-02-19 tracey kerr = khttp_puts(gw_trans->gw_req,
3342 ff4bb25f 2020-02-19 tracey "There are no tags for this repo.");
3343 ff4bb25f 2020-02-19 tracey if (kerr != KCGI_OK)
3344 ff4bb25f 2020-02-19 tracey goto done;
3345 ff4bb25f 2020-02-19 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
3346 6c6c85af 2020-01-15 tracey }
3347 87f9ebf5 2020-01-15 tracey done:
3348 6eccd105 2020-02-03 stsp if (tag)
3349 6eccd105 2020-02-03 stsp got_object_tag_close(tag);
3350 6eccd105 2020-02-03 stsp free(id_str);
3351 55ccf528 2020-02-03 stsp free(age);
3352 6eccd105 2020-02-03 stsp free(tag_commit0);
3353 38b240fb 2020-02-06 tracey free(href_tag);
3354 38b240fb 2020-02-06 tracey free(href_briefs);
3355 38b240fb 2020-02-06 tracey free(href_commits);
3356 6eccd105 2020-02-03 stsp got_ref_list_free(&refs);
3357 38b240fb 2020-02-06 tracey if (error == NULL && kerr != KCGI_OK)
3358 38b240fb 2020-02-06 tracey error = gw_kcgi_error(kerr);
3359 6eccd105 2020-02-03 stsp return error;
3360 f2f46662 2020-01-23 tracey }
3361 f2f46662 2020-01-23 tracey
3362 f2f46662 2020-01-23 tracey static void
3363 b0a1bc86 2020-02-14 stsp gw_free_header(struct gw_header *header)
3364 f2f46662 2020-01-23 tracey {
3365 f2f46662 2020-01-23 tracey free(header->path);
3366 4e8d6e3e 2020-02-14 tracey free(header->author);
3367 4e8d6e3e 2020-02-14 tracey free(header->committer);
3368 f2f46662 2020-01-23 tracey free(header->refs_str);
3369 f2f46662 2020-01-23 tracey free(header->commit_id);
3370 f2f46662 2020-01-23 tracey free(header->parent_id);
3371 f2f46662 2020-01-23 tracey free(header->tree_id);
3372 f2f46662 2020-01-23 tracey free(header->commit_msg);
3373 f2f46662 2020-01-23 tracey }
3374 f2f46662 2020-01-23 tracey
3375 f2f46662 2020-01-23 tracey static struct gw_header *
3376 f2f46662 2020-01-23 tracey gw_init_header()
3377 f2f46662 2020-01-23 tracey {
3378 f2f46662 2020-01-23 tracey struct gw_header *header;
3379 f2f46662 2020-01-23 tracey
3380 ae36ed87 2020-01-28 stsp header = malloc(sizeof(*header));
3381 ae36ed87 2020-01-28 stsp if (header == NULL)
3382 f2f46662 2020-01-23 tracey return NULL;
3383 f2f46662 2020-01-23 tracey
3384 f2f46662 2020-01-23 tracey header->path = NULL;
3385 ae36ed87 2020-01-28 stsp SIMPLEQ_INIT(&header->refs);
3386 5c65becf 2020-02-13 tracey
3387 5c65becf 2020-02-13 tracey header->refs_str = NULL;
3388 5c65becf 2020-02-13 tracey header->commit_id = NULL;
3389 f9315db0 2020-02-14 tracey header->committer = NULL;
3390 f9315db0 2020-02-14 tracey header->author = NULL;
3391 5c65becf 2020-02-13 tracey header->parent_id = NULL;
3392 5c65becf 2020-02-13 tracey header->tree_id = NULL;
3393 5c65becf 2020-02-13 tracey header->commit_msg = NULL;
3394 f2f46662 2020-01-23 tracey
3395 f2f46662 2020-01-23 tracey return header;
3396 f2f46662 2020-01-23 tracey }
3397 f2f46662 2020-01-23 tracey
3398 f2f46662 2020-01-23 tracey static const struct got_error *
3399 f2f46662 2020-01-23 tracey gw_get_commits(struct gw_trans * gw_trans, struct gw_header *header,
3400 3c245a0e 2020-02-14 tracey int limit, struct got_object_id *id)
3401 f2f46662 2020-01-23 tracey {
3402 f2f46662 2020-01-23 tracey const struct got_error *error = NULL;
3403 f2f46662 2020-01-23 tracey struct got_commit_graph *graph = NULL;
3404 4e8d6e3e 2020-02-14 tracey struct got_commit_object *commit = NULL;
3405 55e46400 2020-02-18 tracey int chk_next = 0, chk_multi = 0, prev_set = 0;
3406 f2f46662 2020-01-23 tracey
3407 f2f46662 2020-01-23 tracey error = got_commit_graph_open(&graph, header->path, 0);
3408 f2f46662 2020-01-23 tracey if (error)
3409 00f13350 2020-02-10 tracey return error;
3410 f2f46662 2020-01-23 tracey
3411 deac617c 2020-02-14 tracey error = got_commit_graph_iter_start(graph, id, gw_trans->repo, NULL,
3412 3c245a0e 2020-02-14 tracey NULL);
3413 f2f46662 2020-01-23 tracey if (error)
3414 f2f46662 2020-01-23 tracey goto done;
3415 f2f46662 2020-01-23 tracey
3416 f2f46662 2020-01-23 tracey for (;;) {
3417 deac617c 2020-02-14 tracey error = got_commit_graph_iter_next(&id, graph, gw_trans->repo,
3418 3c245a0e 2020-02-14 tracey NULL, NULL);
3419 f2f46662 2020-01-23 tracey if (error) {
3420 f2f46662 2020-01-23 tracey if (error->code == GOT_ERR_ITER_COMPLETED)
3421 f2f46662 2020-01-23 tracey error = NULL;
3422 f2f46662 2020-01-23 tracey goto done;
3423 f2f46662 2020-01-23 tracey }
3424 3c245a0e 2020-02-14 tracey if (id == NULL)
3425 f2f46662 2020-01-23 tracey goto done;
3426 f2f46662 2020-01-23 tracey
3427 deac617c 2020-02-14 tracey error = got_object_open_as_commit(&commit, gw_trans->repo, id);
3428 4e8d6e3e 2020-02-14 tracey if (error)
3429 4e8d6e3e 2020-02-14 tracey goto done;
3430 bf4484a3 2020-02-18 tracey if (limit == 1 && chk_multi == 0 &&
3431 bf4484a3 2020-02-18 tracey gw_trans->gw_conf->got_max_commits_display != 1) {
3432 3c245a0e 2020-02-14 tracey error = gw_get_commit(gw_trans, header, commit, id);
3433 4e8d6e3e 2020-02-14 tracey if (error)
3434 4e8d6e3e 2020-02-14 tracey goto done;
3435 4e8d6e3e 2020-02-14 tracey } else {
3436 55e46400 2020-02-18 tracey chk_multi = 1;
3437 f2f46662 2020-01-23 tracey struct gw_header *n_header = NULL;
3438 5147ab56 2020-01-29 stsp if ((n_header = gw_init_header()) == NULL) {
3439 f2f46662 2020-01-23 tracey error = got_error_from_errno("malloc");
3440 a942aa37 2020-02-10 tracey goto done;
3441 d1635ae4 2020-02-13 tracey }
3442 bf93a5c0 2020-02-15 tracey error = got_ref_list(&n_header->refs, gw_trans->repo,
3443 bf93a5c0 2020-02-15 tracey NULL, got_ref_cmp_by_name, NULL);
3444 bf93a5c0 2020-02-15 tracey if (error)
3445 bf93a5c0 2020-02-15 tracey goto done;
3446 bf93a5c0 2020-02-15 tracey
3447 3c245a0e 2020-02-14 tracey error = gw_get_commit(gw_trans, n_header, commit, id);
3448 4e8d6e3e 2020-02-14 tracey if (error)
3449 d1635ae4 2020-02-13 tracey goto done;
3450 bc8c6114 2020-02-17 tracey got_ref_list_free(&n_header->refs);
3451 55e46400 2020-02-18 tracey
3452 55e46400 2020-02-18 tracey /*
3453 55e46400 2020-02-18 tracey * we have a commit_id now, so copy it to next_prev_id
3454 55e46400 2020-02-18 tracey * for navigation through gw_briefs and gw_commits
3455 55e46400 2020-02-18 tracey */
3456 55e46400 2020-02-18 tracey if (gw_trans->next_prev_id == NULL && prev_set == 0 &&
3457 55e46400 2020-02-18 tracey (gw_trans->action == GW_BRIEFS ||
3458 55e46400 2020-02-18 tracey gw_trans->action == GW_COMMITS ||
3459 55e46400 2020-02-18 tracey gw_trans->action == GW_SUMMARY)) {
3460 55e46400 2020-02-18 tracey prev_set = 1;
3461 55e46400 2020-02-18 tracey gw_trans->next_prev_id =
3462 55e46400 2020-02-18 tracey strdup(n_header->commit_id);
3463 55e46400 2020-02-18 tracey if (gw_trans->next_prev_id == NULL) {
3464 55e46400 2020-02-18 tracey error = got_error_from_errno("strdup");
3465 55e46400 2020-02-18 tracey goto done;
3466 55e46400 2020-02-18 tracey }
3467 55e46400 2020-02-18 tracey }
3468 55e46400 2020-02-18 tracey
3469 55e46400 2020-02-18 tracey /*
3470 55e46400 2020-02-18 tracey * check for one more commit before breaking,
3471 55e46400 2020-02-18 tracey * so we know whether to navicate through gw_briefs
3472 55e46400 2020-02-18 tracey * gw_commits and gw_summary
3473 55e46400 2020-02-18 tracey */
3474 55e46400 2020-02-18 tracey if (chk_next && (gw_trans->action == GW_BRIEFS||
3475 55e46400 2020-02-18 tracey gw_trans->action == GW_COMMITS ||
3476 55e46400 2020-02-18 tracey gw_trans->action == GW_SUMMARY)) {
3477 55e46400 2020-02-18 tracey gw_trans->next_id = strdup(n_header->commit_id);
3478 55e46400 2020-02-18 tracey if (gw_trans->next_id == NULL)
3479 55e46400 2020-02-18 tracey error = got_error_from_errno("strdup");
3480 55e46400 2020-02-18 tracey goto done;
3481 55e46400 2020-02-18 tracey }
3482 55e46400 2020-02-18 tracey
3483 f2f46662 2020-01-23 tracey TAILQ_INSERT_TAIL(&gw_trans->gw_headers, n_header,
3484 f2f46662 2020-01-23 tracey entry);
3485 f2f46662 2020-01-23 tracey }
3486 55e46400 2020-02-18 tracey if (error || (limit && --limit == 0)) {
3487 55e46400 2020-02-18 tracey if (chk_multi == 0)
3488 55e46400 2020-02-18 tracey break;
3489 55e46400 2020-02-18 tracey chk_next = 1;
3490 55e46400 2020-02-18 tracey }
3491 f2f46662 2020-01-23 tracey }
3492 f2f46662 2020-01-23 tracey done:
3493 4e8d6e3e 2020-02-14 tracey if (commit != NULL)
3494 4e8d6e3e 2020-02-14 tracey got_object_commit_close(commit);
3495 f2f46662 2020-01-23 tracey if (graph)
3496 f2f46662 2020-01-23 tracey got_commit_graph_close(graph);
3497 f2f46662 2020-01-23 tracey return error;
3498 f2f46662 2020-01-23 tracey }
3499 f2f46662 2020-01-23 tracey
3500 f2f46662 2020-01-23 tracey static const struct got_error *
3501 4e8d6e3e 2020-02-14 tracey gw_get_commit(struct gw_trans *gw_trans, struct gw_header *header,
3502 4e8d6e3e 2020-02-14 tracey struct got_commit_object *commit, struct got_object_id *id)
3503 f2f46662 2020-01-23 tracey {
3504 f2f46662 2020-01-23 tracey const struct got_error *error = NULL;
3505 f2f46662 2020-01-23 tracey struct got_reflist_entry *re;
3506 f2f46662 2020-01-23 tracey struct got_object_id *id2 = NULL;
3507 f2f46662 2020-01-23 tracey struct got_object_qid *parent_id;
3508 a81394a7 2020-02-13 stsp char *commit_msg = NULL, *commit_msg0;
3509 f2f46662 2020-01-23 tracey
3510 f2f46662 2020-01-23 tracey /*print commit*/
3511 f2f46662 2020-01-23 tracey SIMPLEQ_FOREACH(re, &header->refs, entry) {
3512 f2f46662 2020-01-23 tracey char *s;
3513 f2f46662 2020-01-23 tracey const char *name;
3514 f2f46662 2020-01-23 tracey struct got_tag_object *tag = NULL;
3515 3721d310 2020-09-23 stsp struct got_object_id *ref_id;
3516 f2f46662 2020-01-23 tracey int cmp;
3517 f2f46662 2020-01-23 tracey
3518 eb4f3ad3 2020-02-14 stsp if (got_ref_is_symbolic(re->ref))
3519 f2f46662 2020-01-23 tracey continue;
3520 eb4f3ad3 2020-02-14 stsp
3521 eb4f3ad3 2020-02-14 stsp name = got_ref_get_name(re->ref);
3522 f2f46662 2020-01-23 tracey if (strncmp(name, "refs/", 5) == 0)
3523 f2f46662 2020-01-23 tracey name += 5;
3524 f2f46662 2020-01-23 tracey if (strncmp(name, "got/", 4) == 0)
3525 f2f46662 2020-01-23 tracey continue;
3526 f2f46662 2020-01-23 tracey if (strncmp(name, "heads/", 6) == 0)
3527 f2f46662 2020-01-23 tracey name += 6;
3528 abdd569e 2020-09-23 stsp if (strncmp(name, "remotes/", 8) == 0) {
3529 f2f46662 2020-01-23 tracey name += 8;
3530 abdd569e 2020-09-23 stsp s = strstr(name, "/" GOT_REF_HEAD);
3531 abdd569e 2020-09-23 stsp if (s != NULL && s[strlen(s)] == '\0')
3532 abdd569e 2020-09-23 stsp continue;
3533 abdd569e 2020-09-23 stsp }
3534 3721d310 2020-09-23 stsp error = got_ref_resolve(&ref_id, gw_trans->repo, re->ref);
3535 3721d310 2020-09-23 stsp if (error)
3536 3721d310 2020-09-23 stsp return error;
3537 f2f46662 2020-01-23 tracey if (strncmp(name, "tags/", 5) == 0) {
3538 deac617c 2020-02-14 tracey error = got_object_open_as_tag(&tag, gw_trans->repo,
3539 3721d310 2020-09-23 stsp ref_id);
3540 f2f46662 2020-01-23 tracey if (error) {
3541 3721d310 2020-09-23 stsp if (error->code != GOT_ERR_OBJ_TYPE) {
3542 3721d310 2020-09-23 stsp free(ref_id);
3543 f2f46662 2020-01-23 tracey continue;
3544 3721d310 2020-09-23 stsp }
3545 f2f46662 2020-01-23 tracey /*
3546 f2f46662 2020-01-23 tracey * Ref points at something other
3547 f2f46662 2020-01-23 tracey * than a tag.
3548 f2f46662 2020-01-23 tracey */
3549 f2f46662 2020-01-23 tracey error = NULL;
3550 f2f46662 2020-01-23 tracey tag = NULL;
3551 f2f46662 2020-01-23 tracey }
3552 f2f46662 2020-01-23 tracey }
3553 f2f46662 2020-01-23 tracey cmp = got_object_id_cmp(tag ?
3554 3721d310 2020-09-23 stsp got_object_tag_get_object_id(tag) : ref_id, id);
3555 3721d310 2020-09-23 stsp free(ref_id);
3556 f2f46662 2020-01-23 tracey if (tag)
3557 f2f46662 2020-01-23 tracey got_object_tag_close(tag);
3558 f2f46662 2020-01-23 tracey if (cmp != 0)
3559 f2f46662 2020-01-23 tracey continue;
3560 a81394a7 2020-02-13 stsp s = header->refs_str;
3561 a81394a7 2020-02-13 stsp if (asprintf(&header->refs_str, "%s%s%s", s ? s : "",
3562 88d59c36 2020-01-29 stsp s ? ", " : "", name) == -1) {
3563 f2f46662 2020-01-23 tracey error = got_error_from_errno("asprintf");
3564 f2f46662 2020-01-23 tracey free(s);
3565 a81394a7 2020-02-13 stsp header->refs_str = NULL;
3566 f2f46662 2020-01-23 tracey return error;
3567 f2f46662 2020-01-23 tracey }
3568 f2f46662 2020-01-23 tracey free(s);
3569 f2f46662 2020-01-23 tracey }
3570 f1200fe3 2020-02-13 tracey
3571 4e8d6e3e 2020-02-14 tracey error = got_object_id_str(&header->commit_id, id);
3572 f2f46662 2020-01-23 tracey if (error)
3573 f2f46662 2020-01-23 tracey return error;
3574 f2f46662 2020-01-23 tracey
3575 f2f46662 2020-01-23 tracey error = got_object_id_str(&header->tree_id,
3576 4e8d6e3e 2020-02-14 tracey got_object_commit_get_tree_id(commit));
3577 f2f46662 2020-01-23 tracey if (error)
3578 f2f46662 2020-01-23 tracey return error;
3579 f2f46662 2020-01-23 tracey
3580 f2f46662 2020-01-23 tracey if (gw_trans->action == GW_DIFF) {
3581 f2f46662 2020-01-23 tracey parent_id = SIMPLEQ_FIRST(
3582 4e8d6e3e 2020-02-14 tracey got_object_commit_get_parent_ids(commit));
3583 f2f46662 2020-01-23 tracey if (parent_id != NULL) {
3584 f2f46662 2020-01-23 tracey id2 = got_object_id_dup(parent_id->id);
3585 f2f46662 2020-01-23 tracey free (parent_id);
3586 f2f46662 2020-01-23 tracey error = got_object_id_str(&header->parent_id, id2);
3587 f2f46662 2020-01-23 tracey if (error)
3588 f2f46662 2020-01-23 tracey return error;
3589 f2f46662 2020-01-23 tracey free(id2);
3590 a942aa37 2020-02-10 tracey } else {
3591 d1635ae4 2020-02-13 tracey header->parent_id = strdup("/dev/null");
3592 d1635ae4 2020-02-13 tracey if (header->parent_id == NULL) {
3593 d1635ae4 2020-02-13 tracey error = got_error_from_errno("strdup");
3594 a942aa37 2020-02-10 tracey return error;
3595 d1635ae4 2020-02-13 tracey }
3596 d1635ae4 2020-02-13 tracey }
3597 a942aa37 2020-02-10 tracey }
3598 f2f46662 2020-01-23 tracey
3599 f2f46662 2020-01-23 tracey header->committer_time =
3600 4e8d6e3e 2020-02-14 tracey got_object_commit_get_committer_time(commit);
3601 1177268c 2020-01-28 tracey
3602 d1635ae4 2020-02-13 tracey header->author =
3603 4e8d6e3e 2020-02-14 tracey strdup(got_object_commit_get_author(commit));
3604 4e8d6e3e 2020-02-14 tracey if (header->author == NULL) {
3605 4e8d6e3e 2020-02-14 tracey error = got_error_from_errno("strdup");
3606 4e8d6e3e 2020-02-14 tracey return error;
3607 4e8d6e3e 2020-02-14 tracey }
3608 d1635ae4 2020-02-13 tracey header->committer =
3609 4e8d6e3e 2020-02-14 tracey strdup(got_object_commit_get_committer(commit));
3610 4e8d6e3e 2020-02-14 tracey if (header->committer == NULL) {
3611 4e8d6e3e 2020-02-14 tracey error = got_error_from_errno("strdup");
3612 a942aa37 2020-02-10 tracey return error;
3613 4e8d6e3e 2020-02-14 tracey }
3614 4e8d6e3e 2020-02-14 tracey error = got_object_commit_get_logmsg(&commit_msg0, commit);
3615 f2f46662 2020-01-23 tracey if (error)
3616 f2f46662 2020-01-23 tracey return error;
3617 f2f46662 2020-01-23 tracey
3618 f2f46662 2020-01-23 tracey commit_msg = commit_msg0;
3619 f2f46662 2020-01-23 tracey while (*commit_msg == '\n')
3620 f2f46662 2020-01-23 tracey commit_msg++;
3621 f2f46662 2020-01-23 tracey
3622 d1635ae4 2020-02-13 tracey header->commit_msg = strdup(commit_msg);
3623 d1635ae4 2020-02-13 tracey if (header->commit_msg == NULL)
3624 d1635ae4 2020-02-13 tracey error = got_error_from_errno("strdup");
3625 f2f46662 2020-01-23 tracey free(commit_msg0);
3626 f2f46662 2020-01-23 tracey return error;
3627 f2f46662 2020-01-23 tracey }
3628 f2f46662 2020-01-23 tracey
3629 f2f46662 2020-01-23 tracey static const struct got_error *
3630 f2f46662 2020-01-23 tracey gw_get_header(struct gw_trans *gw_trans, struct gw_header *header, int limit)
3631 f2f46662 2020-01-23 tracey {
3632 f2f46662 2020-01-23 tracey const struct got_error *error = NULL;
3633 f2f46662 2020-01-23 tracey char *in_repo_path = NULL;
3634 3c245a0e 2020-02-14 tracey struct got_object_id *id = NULL;
3635 f2f46662 2020-01-23 tracey
3636 deac617c 2020-02-14 tracey error = got_repo_open(&gw_trans->repo, gw_trans->repo_path, NULL);
3637 f2f46662 2020-01-23 tracey if (error)
3638 f2f46662 2020-01-23 tracey return error;
3639 f2f46662 2020-01-23 tracey
3640 56997cd3 2020-02-14 tracey if (gw_trans->commit_id == NULL) {
3641 f2f46662 2020-01-23 tracey struct got_reference *head_ref;
3642 deac617c 2020-02-14 tracey error = got_ref_open(&head_ref, gw_trans->repo,
3643 f2f46662 2020-01-23 tracey gw_trans->headref, 0);
3644 f2f46662 2020-01-23 tracey if (error)
3645 f2f46662 2020-01-23 tracey return error;
3646 f2f46662 2020-01-23 tracey
3647 deac617c 2020-02-14 tracey error = got_ref_resolve(&id, gw_trans->repo, head_ref);
3648 f2f46662 2020-01-23 tracey got_ref_close(head_ref);
3649 f2f46662 2020-01-23 tracey if (error)
3650 f2f46662 2020-01-23 tracey return error;
3651 f2f46662 2020-01-23 tracey } else {
3652 f2f46662 2020-01-23 tracey struct got_reference *ref;
3653 55e46400 2020-02-18 tracey
3654 56997cd3 2020-02-14 tracey error = got_ref_open(&ref, gw_trans->repo,
3655 56997cd3 2020-02-14 tracey gw_trans->commit_id, 0);
3656 f2f46662 2020-01-23 tracey if (error == NULL) {
3657 f2f46662 2020-01-23 tracey int obj_type;
3658 deac617c 2020-02-14 tracey error = got_ref_resolve(&id, gw_trans->repo, ref);
3659 f2f46662 2020-01-23 tracey got_ref_close(ref);
3660 f2f46662 2020-01-23 tracey if (error)
3661 f2f46662 2020-01-23 tracey return error;
3662 deac617c 2020-02-14 tracey error = got_object_get_type(&obj_type, gw_trans->repo,
3663 3c245a0e 2020-02-14 tracey id);
3664 f2f46662 2020-01-23 tracey if (error)
3665 4e8d6e3e 2020-02-14 tracey goto done;
3666 f2f46662 2020-01-23 tracey if (obj_type == GOT_OBJ_TYPE_TAG) {
3667 f2f46662 2020-01-23 tracey struct got_tag_object *tag;
3668 f2f46662 2020-01-23 tracey error = got_object_open_as_tag(&tag,
3669 deac617c 2020-02-14 tracey gw_trans->repo, id);
3670 f2f46662 2020-01-23 tracey if (error)
3671 4e8d6e3e 2020-02-14 tracey goto done;
3672 f2f46662 2020-01-23 tracey if (got_object_tag_get_object_type(tag) !=
3673 f2f46662 2020-01-23 tracey GOT_OBJ_TYPE_COMMIT) {
3674 f2f46662 2020-01-23 tracey got_object_tag_close(tag);
3675 f2f46662 2020-01-23 tracey error = got_error(GOT_ERR_OBJ_TYPE);
3676 4e8d6e3e 2020-02-14 tracey goto done;
3677 f2f46662 2020-01-23 tracey }
3678 3c245a0e 2020-02-14 tracey free(id);
3679 3c245a0e 2020-02-14 tracey id = got_object_id_dup(
3680 f2f46662 2020-01-23 tracey got_object_tag_get_object_id(tag));
3681 3c245a0e 2020-02-14 tracey if (id == NULL)
3682 f2f46662 2020-01-23 tracey error = got_error_from_errno(
3683 f2f46662 2020-01-23 tracey "got_object_id_dup");
3684 f2f46662 2020-01-23 tracey got_object_tag_close(tag);
3685 f2f46662 2020-01-23 tracey if (error)
3686 4e8d6e3e 2020-02-14 tracey goto done;
3687 f2f46662 2020-01-23 tracey } else if (obj_type != GOT_OBJ_TYPE_COMMIT) {
3688 f2f46662 2020-01-23 tracey error = got_error(GOT_ERR_OBJ_TYPE);
3689 4e8d6e3e 2020-02-14 tracey goto done;
3690 f2f46662 2020-01-23 tracey }
3691 f2f46662 2020-01-23 tracey }
3692 3c245a0e 2020-02-14 tracey error = got_repo_match_object_id_prefix(&id,
3693 56997cd3 2020-02-14 tracey gw_trans->commit_id, GOT_OBJ_TYPE_COMMIT,
3694 deac617c 2020-02-14 tracey gw_trans->repo);
3695 122f3af5 2020-02-14 stsp if (error)
3696 4e8d6e3e 2020-02-14 tracey goto done;
3697 f2f46662 2020-01-23 tracey }
3698 f2f46662 2020-01-23 tracey
3699 deac617c 2020-02-14 tracey error = got_repo_map_path(&in_repo_path, gw_trans->repo,
3700 f2f46662 2020-01-23 tracey gw_trans->repo_path, 1);
3701 f2f46662 2020-01-23 tracey if (error)
3702 4e8d6e3e 2020-02-14 tracey goto done;
3703 f2f46662 2020-01-23 tracey
3704 f2f46662 2020-01-23 tracey if (in_repo_path) {
3705 d1635ae4 2020-02-13 tracey header->path = strdup(in_repo_path);
3706 d1635ae4 2020-02-13 tracey if (header->path == NULL) {
3707 d1635ae4 2020-02-13 tracey error = got_error_from_errno("strdup");
3708 4e8d6e3e 2020-02-14 tracey goto done;
3709 a942aa37 2020-02-10 tracey }
3710 f2f46662 2020-01-23 tracey }
3711 f2f46662 2020-01-23 tracey
3712 deac617c 2020-02-14 tracey error = got_ref_list(&header->refs, gw_trans->repo, NULL,
3713 f2f46662 2020-01-23 tracey got_ref_cmp_by_name, NULL);
3714 f2f46662 2020-01-23 tracey if (error)
3715 4e8d6e3e 2020-02-14 tracey goto done;
3716 f2f46662 2020-01-23 tracey
3717 3c245a0e 2020-02-14 tracey error = gw_get_commits(gw_trans, header, limit, id);
3718 4e8d6e3e 2020-02-14 tracey done:
3719 4e8d6e3e 2020-02-14 tracey got_ref_list_free(&header->refs);
3720 3c245a0e 2020-02-14 tracey free(id);
3721 4e8d6e3e 2020-02-14 tracey free(in_repo_path);
3722 f2f46662 2020-01-23 tracey return error;
3723 ec46ccd7 2020-01-15 tracey }
3724 ec46ccd7 2020-01-15 tracey
3725 ec46ccd7 2020-01-15 tracey struct blame_line {
3726 ec46ccd7 2020-01-15 tracey int annotated;
3727 ec46ccd7 2020-01-15 tracey char *id_str;
3728 ec46ccd7 2020-01-15 tracey char *committer;
3729 ec46ccd7 2020-01-15 tracey char datebuf[11]; /* YYYY-MM-DD + NUL */
3730 ec46ccd7 2020-01-15 tracey };
3731 ec46ccd7 2020-01-15 tracey
3732 147269d5 2020-01-15 tracey struct gw_blame_cb_args {
3733 ec46ccd7 2020-01-15 tracey struct blame_line *lines;
3734 ec46ccd7 2020-01-15 tracey int nlines;
3735 ec46ccd7 2020-01-15 tracey int nlines_prec;
3736 ec46ccd7 2020-01-15 tracey int lineno_cur;
3737 ec46ccd7 2020-01-15 tracey off_t *line_offsets;
3738 ec46ccd7 2020-01-15 tracey FILE *f;
3739 ec46ccd7 2020-01-15 tracey struct got_repository *repo;
3740 54415d85 2020-01-15 tracey struct gw_trans *gw_trans;
3741 ec46ccd7 2020-01-15 tracey };
3742 ec46ccd7 2020-01-15 tracey
3743 ec46ccd7 2020-01-15 tracey static const struct got_error *
3744 147269d5 2020-01-15 tracey gw_blame_cb(void *arg, int nlines, int lineno, struct got_object_id *id)
3745 ec46ccd7 2020-01-15 tracey {
3746 ec46ccd7 2020-01-15 tracey const struct got_error *err = NULL;
3747 147269d5 2020-01-15 tracey struct gw_blame_cb_args *a = arg;
3748 ec46ccd7 2020-01-15 tracey struct blame_line *bline;
3749 ec46ccd7 2020-01-15 tracey char *line = NULL;
3750 9a9d12ca 2020-02-06 tracey size_t linesize = 0;
3751 ec46ccd7 2020-01-15 tracey struct got_commit_object *commit = NULL;
3752 ec46ccd7 2020-01-15 tracey off_t offset;
3753 ec46ccd7 2020-01-15 tracey struct tm tm;
3754 ec46ccd7 2020-01-15 tracey time_t committer_time;
3755 9a9d12ca 2020-02-06 tracey enum kcgi_err kerr = KCGI_OK;
3756 ec46ccd7 2020-01-15 tracey
3757 ec46ccd7 2020-01-15 tracey if (nlines != a->nlines ||
3758 ec46ccd7 2020-01-15 tracey (lineno != -1 && lineno < 1) || lineno > a->nlines)
3759 ec46ccd7 2020-01-15 tracey return got_error(GOT_ERR_RANGE);
3760 ec46ccd7 2020-01-15 tracey
3761 ec46ccd7 2020-01-15 tracey if (lineno == -1)
3762 ec46ccd7 2020-01-15 tracey return NULL; /* no change in this commit */
3763 ec46ccd7 2020-01-15 tracey
3764 ec46ccd7 2020-01-15 tracey /* Annotate this line. */
3765 ec46ccd7 2020-01-15 tracey bline = &a->lines[lineno - 1];
3766 ec46ccd7 2020-01-15 tracey if (bline->annotated)
3767 ec46ccd7 2020-01-15 tracey return NULL;
3768 ec46ccd7 2020-01-15 tracey err = got_object_id_str(&bline->id_str, id);
3769 ec46ccd7 2020-01-15 tracey if (err)
3770 ec46ccd7 2020-01-15 tracey return err;
3771 ec46ccd7 2020-01-15 tracey
3772 ec46ccd7 2020-01-15 tracey err = got_object_open_as_commit(&commit, a->repo, id);
3773 ec46ccd7 2020-01-15 tracey if (err)
3774 ec46ccd7 2020-01-15 tracey goto done;
3775 ec46ccd7 2020-01-15 tracey
3776 d1635ae4 2020-02-13 tracey bline->committer = strdup(got_object_commit_get_committer(commit));
3777 d1635ae4 2020-02-13 tracey if (bline->committer == NULL) {
3778 d1635ae4 2020-02-13 tracey err = got_error_from_errno("strdup");
3779 ec46ccd7 2020-01-15 tracey goto done;
3780 d1635ae4 2020-02-13 tracey }
3781 ec46ccd7 2020-01-15 tracey
3782 ec46ccd7 2020-01-15 tracey committer_time = got_object_commit_get_committer_time(commit);
3783 ec46ccd7 2020-01-15 tracey if (localtime_r(&committer_time, &tm) == NULL)
3784 ec46ccd7 2020-01-15 tracey return got_error_from_errno("localtime_r");
3785 ec46ccd7 2020-01-15 tracey if (strftime(bline->datebuf, sizeof(bline->datebuf), "%G-%m-%d",
3786 ec46ccd7 2020-01-15 tracey &tm) >= sizeof(bline->datebuf)) {
3787 ec46ccd7 2020-01-15 tracey err = got_error(GOT_ERR_NO_SPACE);
3788 ec46ccd7 2020-01-15 tracey goto done;
3789 ec46ccd7 2020-01-15 tracey }
3790 ec46ccd7 2020-01-15 tracey bline->annotated = 1;
3791 ec46ccd7 2020-01-15 tracey
3792 ec46ccd7 2020-01-15 tracey /* Print lines annotated so far. */
3793 ec46ccd7 2020-01-15 tracey bline = &a->lines[a->lineno_cur - 1];
3794 ec46ccd7 2020-01-15 tracey if (!bline->annotated)
3795 ec46ccd7 2020-01-15 tracey goto done;
3796 ec46ccd7 2020-01-15 tracey
3797 ec46ccd7 2020-01-15 tracey offset = a->line_offsets[a->lineno_cur - 1];
3798 ec46ccd7 2020-01-15 tracey if (fseeko(a->f, offset, SEEK_SET) == -1) {
3799 ec46ccd7 2020-01-15 tracey err = got_error_from_errno("fseeko");
3800 ec46ccd7 2020-01-15 tracey goto done;
3801 ec46ccd7 2020-01-15 tracey }
3802 ec46ccd7 2020-01-15 tracey
3803 ec46ccd7 2020-01-15 tracey while (bline->annotated) {
3804 9a9d12ca 2020-02-06 tracey char *smallerthan, *at, *nl, *committer;
3805 32b9f7ed 2020-04-14 tracey char *href_diff = NULL;
3806 ec46ccd7 2020-01-15 tracey size_t len;
3807 ec46ccd7 2020-01-15 tracey
3808 ec46ccd7 2020-01-15 tracey if (getline(&line, &linesize, a->f) == -1) {
3809 ec46ccd7 2020-01-15 tracey if (ferror(a->f))
3810 ec46ccd7 2020-01-15 tracey err = got_error_from_errno("getline");
3811 ec46ccd7 2020-01-15 tracey break;
3812 ec46ccd7 2020-01-15 tracey }
3813 ec46ccd7 2020-01-15 tracey
3814 ec46ccd7 2020-01-15 tracey committer = bline->committer;
3815 ec46ccd7 2020-01-15 tracey smallerthan = strchr(committer, '<');
3816 ec46ccd7 2020-01-15 tracey if (smallerthan && smallerthan[1] != '\0')
3817 ec46ccd7 2020-01-15 tracey committer = smallerthan + 1;
3818 ec46ccd7 2020-01-15 tracey at = strchr(committer, '@');
3819 ec46ccd7 2020-01-15 tracey if (at)
3820 ec46ccd7 2020-01-15 tracey *at = '\0';
3821 ec46ccd7 2020-01-15 tracey len = strlen(committer);
3822 ec46ccd7 2020-01-15 tracey if (len >= 9)
3823 ec46ccd7 2020-01-15 tracey committer[8] = '\0';
3824 ec46ccd7 2020-01-15 tracey
3825 ec46ccd7 2020-01-15 tracey nl = strchr(line, '\n');
3826 ec46ccd7 2020-01-15 tracey if (nl)
3827 ec46ccd7 2020-01-15 tracey *nl = '\0';
3828 0311ce2d 2020-01-15 tracey
3829 9a9d12ca 2020-02-06 tracey kerr = khtml_attr(a->gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
3830 9a9d12ca 2020-02-06 tracey "blame_wrapper", KATTR__MAX);
3831 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
3832 9a9d12ca 2020-02-06 tracey goto err;
3833 9a9d12ca 2020-02-06 tracey kerr = khtml_attr(a->gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
3834 9a9d12ca 2020-02-06 tracey "blame_number", KATTR__MAX);
3835 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
3836 9a9d12ca 2020-02-06 tracey goto err;
3837 32b9f7ed 2020-04-14 tracey kerr = khtml_printf(a->gw_trans->gw_html_req, "%.*d",
3838 32b9f7ed 2020-04-14 tracey a->nlines_prec, a->lineno_cur);
3839 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
3840 9a9d12ca 2020-02-06 tracey goto err;
3841 9a9d12ca 2020-02-06 tracey kerr = khtml_closeelem(a->gw_trans->gw_html_req, 1);
3842 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
3843 9a9d12ca 2020-02-06 tracey goto err;
3844 9a9d12ca 2020-02-06 tracey
3845 9a9d12ca 2020-02-06 tracey kerr = khtml_attr(a->gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
3846 9a9d12ca 2020-02-06 tracey "blame_hash", KATTR__MAX);
3847 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
3848 9a9d12ca 2020-02-06 tracey goto err;
3849 1b33afc0 2020-02-14 tracey
3850 ebc6542a 2020-04-14 tracey href_diff = khttp_urlpart(NULL, NULL, "gotweb", "path",
3851 ebc6542a 2020-04-14 tracey a->gw_trans->repo_name, "action", "diff", "commit",
3852 ebc6542a 2020-04-14 tracey bline->id_str, NULL);
3853 19ff7638 2020-04-14 tracey if (href_diff == NULL) {
3854 19ff7638 2020-04-14 tracey err = got_error_from_errno("khttp_urlpart");
3855 19ff7638 2020-04-14 tracey goto done;
3856 19ff7638 2020-04-14 tracey }
3857 9a9d12ca 2020-02-06 tracey kerr = khtml_attr(a->gw_trans->gw_html_req, KELEM_A,
3858 9a9d12ca 2020-02-06 tracey KATTR_HREF, href_diff, KATTR__MAX);
3859 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
3860 9a9d12ca 2020-02-06 tracey goto done;
3861 32b9f7ed 2020-04-14 tracey kerr = khtml_printf(a->gw_trans->gw_html_req, "%.8s",
3862 32b9f7ed 2020-04-14 tracey bline->id_str);
3863 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
3864 9a9d12ca 2020-02-06 tracey goto err;
3865 9a9d12ca 2020-02-06 tracey kerr = khtml_closeelem(a->gw_trans->gw_html_req, 2);
3866 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
3867 9a9d12ca 2020-02-06 tracey goto err;
3868 2e676fc5 2020-01-15 tracey
3869 9a9d12ca 2020-02-06 tracey kerr = khtml_attr(a->gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
3870 9a9d12ca 2020-02-06 tracey "blame_date", KATTR__MAX);
3871 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
3872 9a9d12ca 2020-02-06 tracey goto err;
3873 9a9d12ca 2020-02-06 tracey kerr = khtml_puts(a->gw_trans->gw_html_req, bline->datebuf);
3874 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
3875 9a9d12ca 2020-02-06 tracey goto err;
3876 9a9d12ca 2020-02-06 tracey kerr = khtml_closeelem(a->gw_trans->gw_html_req, 1);
3877 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
3878 9a9d12ca 2020-02-06 tracey goto err;
3879 9a9d12ca 2020-02-06 tracey
3880 9a9d12ca 2020-02-06 tracey kerr = khtml_attr(a->gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
3881 9a9d12ca 2020-02-06 tracey "blame_author", KATTR__MAX);
3882 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
3883 9a9d12ca 2020-02-06 tracey goto err;
3884 9a9d12ca 2020-02-06 tracey kerr = khtml_puts(a->gw_trans->gw_html_req, committer);
3885 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
3886 9a9d12ca 2020-02-06 tracey goto err;
3887 9a9d12ca 2020-02-06 tracey kerr = khtml_closeelem(a->gw_trans->gw_html_req, 1);
3888 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
3889 9a9d12ca 2020-02-06 tracey goto err;
3890 9a9d12ca 2020-02-06 tracey
3891 9a9d12ca 2020-02-06 tracey kerr = khtml_attr(a->gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
3892 9a9d12ca 2020-02-06 tracey "blame_code", KATTR__MAX);
3893 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
3894 9a9d12ca 2020-02-06 tracey goto err;
3895 9a9d12ca 2020-02-06 tracey kerr = khtml_puts(a->gw_trans->gw_html_req, line);
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, 1);
3899 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
3900 9a9d12ca 2020-02-06 tracey goto err;
3901 9a9d12ca 2020-02-06 tracey
3902 9a9d12ca 2020-02-06 tracey kerr = khtml_closeelem(a->gw_trans->gw_html_req, 1);
3903 9a9d12ca 2020-02-06 tracey if (kerr != KCGI_OK)
3904 9a9d12ca 2020-02-06 tracey goto err;
3905 9a9d12ca 2020-02-06 tracey
3906 9a9d12ca 2020-02-06 tracey a->lineno_cur++;
3907 ec46ccd7 2020-01-15 tracey bline = &a->lines[a->lineno_cur - 1];
3908 de6bdba4 2020-01-31 tracey err:
3909 9a9d12ca 2020-02-06 tracey free(href_diff);
3910 ec46ccd7 2020-01-15 tracey }
3911 ec46ccd7 2020-01-15 tracey done:
3912 ec46ccd7 2020-01-15 tracey if (commit)
3913 ec46ccd7 2020-01-15 tracey got_object_commit_close(commit);
3914 ec46ccd7 2020-01-15 tracey free(line);
3915 9a9d12ca 2020-02-06 tracey if (err == NULL && kerr != KCGI_OK)
3916 9a9d12ca 2020-02-06 tracey err = gw_kcgi_error(kerr);
3917 ec46ccd7 2020-01-15 tracey return err;
3918 872742ce 2020-02-01 stsp }
3919 872742ce 2020-02-01 stsp
3920 a81f3554 2020-02-03 stsp static const struct got_error *
3921 9a9d12ca 2020-02-06 tracey gw_output_file_blame(struct gw_trans *gw_trans)
3922 bcbc97d8 2020-01-15 tracey {
3923 bcbc97d8 2020-01-15 tracey const struct got_error *error = NULL;
3924 ec46ccd7 2020-01-15 tracey struct got_object_id *obj_id = NULL;
3925 ec46ccd7 2020-01-15 tracey struct got_object_id *commit_id = NULL;
3926 ec46ccd7 2020-01-15 tracey struct got_blob_object *blob = NULL;
3927 a81f3554 2020-02-03 stsp char *path = NULL, *in_repo_path = NULL;
3928 147269d5 2020-01-15 tracey struct gw_blame_cb_args bca;
3929 119bf4ed 2020-01-15 tracey int i, obj_type;
3930 ec46ccd7 2020-01-15 tracey size_t filesize;
3931 ec46ccd7 2020-01-15 tracey
3932 a81f3554 2020-02-03 stsp if (asprintf(&path, "%s%s%s",
3933 a81f3554 2020-02-03 stsp gw_trans->repo_folder ? gw_trans->repo_folder : "",
3934 4fd4726a 2020-02-03 stsp gw_trans->repo_folder ? "/" : "",
3935 a81f3554 2020-02-03 stsp gw_trans->repo_file) == -1) {
3936 2e676fc5 2020-01-15 tracey error = got_error_from_errno("asprintf");
3937 2e676fc5 2020-01-15 tracey goto done;
3938 2e676fc5 2020-01-15 tracey }
3939 2e676fc5 2020-01-15 tracey
3940 deac617c 2020-02-14 tracey error = got_repo_map_path(&in_repo_path, gw_trans->repo, path, 1);
3941 ec46ccd7 2020-01-15 tracey if (error)
3942 ec46ccd7 2020-01-15 tracey goto done;
3943 ec46ccd7 2020-01-15 tracey
3944 56997cd3 2020-02-14 tracey error = got_repo_match_object_id(&commit_id, NULL, gw_trans->commit_id,
3945 deac617c 2020-02-14 tracey GOT_OBJ_TYPE_COMMIT, 1, gw_trans->repo);
3946 ec46ccd7 2020-01-15 tracey if (error)
3947 ec46ccd7 2020-01-15 tracey goto done;
3948 ec46ccd7 2020-01-15 tracey
3949 deac617c 2020-02-14 tracey error = got_object_id_by_path(&obj_id, gw_trans->repo, commit_id,
3950 deac617c 2020-02-14 tracey in_repo_path);
3951 ec46ccd7 2020-01-15 tracey if (error)
3952 ec46ccd7 2020-01-15 tracey goto done;
3953 2e676fc5 2020-01-15 tracey
3954 ec46ccd7 2020-01-15 tracey if (obj_id == NULL) {
3955 ec46ccd7 2020-01-15 tracey error = got_error(GOT_ERR_NO_OBJ);
3956 ec46ccd7 2020-01-15 tracey goto done;
3957 ec46ccd7 2020-01-15 tracey }
3958 ec46ccd7 2020-01-15 tracey
3959 deac617c 2020-02-14 tracey error = got_object_get_type(&obj_type, gw_trans->repo, obj_id);
3960 ec46ccd7 2020-01-15 tracey if (error)
3961 ec46ccd7 2020-01-15 tracey goto done;
3962 ec46ccd7 2020-01-15 tracey
3963 ec46ccd7 2020-01-15 tracey if (obj_type != GOT_OBJ_TYPE_BLOB) {
3964 ec46ccd7 2020-01-15 tracey error = got_error(GOT_ERR_OBJ_TYPE);
3965 ec46ccd7 2020-01-15 tracey goto done;
3966 ec46ccd7 2020-01-15 tracey }
3967 ec46ccd7 2020-01-15 tracey
3968 deac617c 2020-02-14 tracey error = got_object_open_as_blob(&blob, gw_trans->repo, obj_id, 8192);
3969 ec46ccd7 2020-01-15 tracey if (error)
3970 ec46ccd7 2020-01-15 tracey goto done;
3971 ec46ccd7 2020-01-15 tracey
3972 ec46ccd7 2020-01-15 tracey bca.f = got_opentemp();
3973 ec46ccd7 2020-01-15 tracey if (bca.f == NULL) {
3974 ec46ccd7 2020-01-15 tracey error = got_error_from_errno("got_opentemp");
3975 ec46ccd7 2020-01-15 tracey goto done;
3976 ec46ccd7 2020-01-15 tracey }
3977 ec46ccd7 2020-01-15 tracey error = got_object_blob_dump_to_file(&filesize, &bca.nlines,
3978 ec46ccd7 2020-01-15 tracey &bca.line_offsets, bca.f, blob);
3979 ec46ccd7 2020-01-15 tracey if (error || bca.nlines == 0)
3980 ec46ccd7 2020-01-15 tracey goto done;
3981 a81f3554 2020-02-03 stsp
3982 ec46ccd7 2020-01-15 tracey /* Don't include \n at EOF in the blame line count. */
3983 ec46ccd7 2020-01-15 tracey if (bca.line_offsets[bca.nlines - 1] == filesize)
3984 ec46ccd7 2020-01-15 tracey bca.nlines--;
3985 ec46ccd7 2020-01-15 tracey
3986 ec46ccd7 2020-01-15 tracey bca.lines = calloc(bca.nlines, sizeof(*bca.lines));
3987 ec46ccd7 2020-01-15 tracey if (bca.lines == NULL) {
3988 ec46ccd7 2020-01-15 tracey error = got_error_from_errno("calloc");
3989 ec46ccd7 2020-01-15 tracey goto done;
3990 ec46ccd7 2020-01-15 tracey }
3991 ec46ccd7 2020-01-15 tracey bca.lineno_cur = 1;
3992 ec46ccd7 2020-01-15 tracey bca.nlines_prec = 0;
3993 ec46ccd7 2020-01-15 tracey i = bca.nlines;
3994 ec46ccd7 2020-01-15 tracey while (i > 0) {
3995 ec46ccd7 2020-01-15 tracey i /= 10;
3996 ec46ccd7 2020-01-15 tracey bca.nlines_prec++;
3997 ec46ccd7 2020-01-15 tracey }
3998 deac617c 2020-02-14 tracey bca.repo = gw_trans->repo;
3999 2e676fc5 2020-01-15 tracey bca.gw_trans = gw_trans;
4000 ec46ccd7 2020-01-15 tracey
4001 deac617c 2020-02-14 tracey error = got_blame(in_repo_path, commit_id, gw_trans->repo, gw_blame_cb,
4002 deac617c 2020-02-14 tracey &bca, NULL, NULL);
4003 ec46ccd7 2020-01-15 tracey done:
4004 2e676fc5 2020-01-15 tracey free(in_repo_path);
4005 2e676fc5 2020-01-15 tracey free(commit_id);
4006 2e676fc5 2020-01-15 tracey free(obj_id);
4007 2e676fc5 2020-01-15 tracey free(path);
4008 2e676fc5 2020-01-15 tracey
4009 1b33afc0 2020-02-14 tracey if (blob) {
4010 1b33afc0 2020-02-14 tracey free(bca.line_offsets);
4011 1b33afc0 2020-02-14 tracey for (i = 0; i < bca.nlines; i++) {
4012 1b33afc0 2020-02-14 tracey struct blame_line *bline = &bca.lines[i];
4013 1b33afc0 2020-02-14 tracey free(bline->id_str);
4014 1b33afc0 2020-02-14 tracey free(bline->committer);
4015 1b33afc0 2020-02-14 tracey }
4016 1b33afc0 2020-02-14 tracey free(bca.lines);
4017 1b33afc0 2020-02-14 tracey if (bca.f && fclose(bca.f) == EOF && error == NULL)
4018 1b33afc0 2020-02-14 tracey error = got_error_from_errno("fclose");
4019 2e676fc5 2020-01-15 tracey }
4020 4fd4726a 2020-02-03 stsp if (blob)
4021 4fd4726a 2020-02-03 stsp got_object_blob_close(blob);
4022 4fd4726a 2020-02-03 stsp return error;
4023 4fd4726a 2020-02-03 stsp }
4024 4fd4726a 2020-02-03 stsp
4025 4fd4726a 2020-02-03 stsp static const struct got_error *
4026 e0857cfe 2020-02-06 tracey gw_output_blob_buf(struct gw_trans *gw_trans)
4027 4fd4726a 2020-02-03 stsp {
4028 4fd4726a 2020-02-03 stsp const struct got_error *error = NULL;
4029 4fd4726a 2020-02-03 stsp struct got_object_id *obj_id = NULL;
4030 4fd4726a 2020-02-03 stsp struct got_object_id *commit_id = NULL;
4031 4fd4726a 2020-02-03 stsp struct got_blob_object *blob = NULL;
4032 4fd4726a 2020-02-03 stsp char *path = NULL, *in_repo_path = NULL;
4033 e0857cfe 2020-02-06 tracey int obj_type, set_mime = 0;
4034 e0857cfe 2020-02-06 tracey size_t len, hdrlen;
4035 e0857cfe 2020-02-06 tracey const uint8_t *buf;
4036 e0857cfe 2020-02-06 tracey enum kcgi_err kerr = KCGI_OK;
4037 4fd4726a 2020-02-03 stsp
4038 4fd4726a 2020-02-03 stsp if (asprintf(&path, "%s%s%s",
4039 4fd4726a 2020-02-03 stsp gw_trans->repo_folder ? gw_trans->repo_folder : "",
4040 4fd4726a 2020-02-03 stsp gw_trans->repo_folder ? "/" : "",
4041 4fd4726a 2020-02-03 stsp gw_trans->repo_file) == -1) {
4042 4fd4726a 2020-02-03 stsp error = got_error_from_errno("asprintf");
4043 4fd4726a 2020-02-03 stsp goto done;
4044 4fd4726a 2020-02-03 stsp }
4045 4fd4726a 2020-02-03 stsp
4046 deac617c 2020-02-14 tracey error = got_repo_map_path(&in_repo_path, gw_trans->repo, path, 1);
4047 4fd4726a 2020-02-03 stsp if (error)
4048 4fd4726a 2020-02-03 stsp goto done;
4049 4fd4726a 2020-02-03 stsp
4050 56997cd3 2020-02-14 tracey error = got_repo_match_object_id(&commit_id, NULL, gw_trans->commit_id,
4051 deac617c 2020-02-14 tracey GOT_OBJ_TYPE_COMMIT, 1, gw_trans->repo);
4052 4fd4726a 2020-02-03 stsp if (error)
4053 4fd4726a 2020-02-03 stsp goto done;
4054 4fd4726a 2020-02-03 stsp
4055 deac617c 2020-02-14 tracey error = got_object_id_by_path(&obj_id, gw_trans->repo, commit_id,
4056 deac617c 2020-02-14 tracey in_repo_path);
4057 4fd4726a 2020-02-03 stsp if (error)
4058 4fd4726a 2020-02-03 stsp goto done;
4059 4fd4726a 2020-02-03 stsp
4060 4fd4726a 2020-02-03 stsp if (obj_id == NULL) {
4061 4fd4726a 2020-02-03 stsp error = got_error(GOT_ERR_NO_OBJ);
4062 4fd4726a 2020-02-03 stsp goto done;
4063 4fd4726a 2020-02-03 stsp }
4064 4fd4726a 2020-02-03 stsp
4065 deac617c 2020-02-14 tracey error = got_object_get_type(&obj_type, gw_trans->repo, obj_id);
4066 4fd4726a 2020-02-03 stsp if (error)
4067 4fd4726a 2020-02-03 stsp goto done;
4068 4fd4726a 2020-02-03 stsp
4069 4fd4726a 2020-02-03 stsp if (obj_type != GOT_OBJ_TYPE_BLOB) {
4070 4fd4726a 2020-02-03 stsp error = got_error(GOT_ERR_OBJ_TYPE);
4071 4fd4726a 2020-02-03 stsp goto done;
4072 4fd4726a 2020-02-03 stsp }
4073 4fd4726a 2020-02-03 stsp
4074 deac617c 2020-02-14 tracey error = got_object_open_as_blob(&blob, gw_trans->repo, obj_id, 8192);
4075 4fd4726a 2020-02-03 stsp if (error)
4076 4fd4726a 2020-02-03 stsp goto done;
4077 4fd4726a 2020-02-03 stsp
4078 e0857cfe 2020-02-06 tracey hdrlen = got_object_blob_get_hdrlen(blob);
4079 e0857cfe 2020-02-06 tracey do {
4080 e0857cfe 2020-02-06 tracey error = got_object_blob_read_block(&len, blob);
4081 e0857cfe 2020-02-06 tracey if (error)
4082 e0857cfe 2020-02-06 tracey goto done;
4083 e0857cfe 2020-02-06 tracey buf = got_object_blob_get_read_buf(blob);
4084 4fd4726a 2020-02-03 stsp
4085 e0857cfe 2020-02-06 tracey /*
4086 e0857cfe 2020-02-06 tracey * Skip blob object header first time around,
4087 e0857cfe 2020-02-06 tracey * which also contains a zero byte.
4088 e0857cfe 2020-02-06 tracey */
4089 e0857cfe 2020-02-06 tracey buf += hdrlen;
4090 e0857cfe 2020-02-06 tracey if (set_mime == 0) {
4091 e0857cfe 2020-02-06 tracey if (isbinary(buf, len - hdrlen))
4092 e0857cfe 2020-02-06 tracey gw_trans->mime = KMIME_APP_OCTET_STREAM;
4093 e0857cfe 2020-02-06 tracey else
4094 e0857cfe 2020-02-06 tracey gw_trans->mime = KMIME_TEXT_PLAIN;
4095 e0857cfe 2020-02-06 tracey set_mime = 1;
4096 e0857cfe 2020-02-06 tracey error = gw_display_index(gw_trans);
4097 e0857cfe 2020-02-06 tracey if (error)
4098 e0857cfe 2020-02-06 tracey goto done;
4099 e0857cfe 2020-02-06 tracey }
4100 3b7fdcf4 2020-02-14 tracey kerr = khttp_write(gw_trans->gw_req, buf, len - hdrlen);
4101 c56af3fd 2020-02-17 stsp if (kerr != KCGI_OK)
4102 c56af3fd 2020-02-17 stsp goto done;
4103 e0857cfe 2020-02-06 tracey hdrlen = 0;
4104 e0857cfe 2020-02-06 tracey } while (len != 0);
4105 4fd4726a 2020-02-03 stsp done:
4106 4fd4726a 2020-02-03 stsp free(in_repo_path);
4107 4fd4726a 2020-02-03 stsp free(commit_id);
4108 4fd4726a 2020-02-03 stsp free(obj_id);
4109 4fd4726a 2020-02-03 stsp free(path);
4110 e46f587c 2020-01-29 tracey if (blob)
4111 a81f3554 2020-02-03 stsp got_object_blob_close(blob);
4112 e0857cfe 2020-02-06 tracey if (error == NULL && kerr != KCGI_OK)
4113 e0857cfe 2020-02-06 tracey error = gw_kcgi_error(kerr);
4114 a81f3554 2020-02-03 stsp return error;
4115 ec46ccd7 2020-01-15 tracey }
4116 ec46ccd7 2020-01-15 tracey
4117 84bf4df2 2020-02-03 stsp static const struct got_error *
4118 626b25b6 2020-02-06 tracey gw_output_repo_tree(struct gw_trans *gw_trans)
4119 ec46ccd7 2020-01-15 tracey {
4120 ec46ccd7 2020-01-15 tracey const struct got_error *error = NULL;
4121 bcbc97d8 2020-01-15 tracey struct got_object_id *tree_id = NULL, *commit_id = NULL;
4122 bcbc97d8 2020-01-15 tracey struct got_tree_object *tree = NULL;
4123 626b25b6 2020-02-06 tracey char *path = NULL, *in_repo_path = NULL;
4124 84bf4df2 2020-02-03 stsp char *id_str = NULL;
4125 84bf4df2 2020-02-03 stsp char *build_folder = NULL;
4126 626b25b6 2020-02-06 tracey char *href_blob = NULL, *href_blame = NULL;
4127 84bf4df2 2020-02-03 stsp const char *class = NULL;
4128 c3bcdfd5 2020-01-29 tracey int nentries, i, class_flip = 0;
4129 626b25b6 2020-02-06 tracey enum kcgi_err kerr = KCGI_OK;
4130 8d4d2453 2020-01-15 tracey
4131 a942aa37 2020-02-10 tracey if (gw_trans->repo_folder != NULL) {
4132 d1635ae4 2020-02-13 tracey path = strdup(gw_trans->repo_folder);
4133 d1635ae4 2020-02-13 tracey if (path == NULL) {
4134 d1635ae4 2020-02-13 tracey error = got_error_from_errno("strdup");
4135 a942aa37 2020-02-10 tracey goto done;
4136 d1635ae4 2020-02-13 tracey }
4137 a942aa37 2020-02-10 tracey } else {
4138 deac617c 2020-02-14 tracey error = got_repo_map_path(&in_repo_path, gw_trans->repo,
4139 84bf4df2 2020-02-03 stsp gw_trans->repo_path, 1);
4140 84bf4df2 2020-02-03 stsp if (error)
4141 84bf4df2 2020-02-03 stsp goto done;
4142 bcbc97d8 2020-01-15 tracey free(path);
4143 bcbc97d8 2020-01-15 tracey path = in_repo_path;
4144 bcbc97d8 2020-01-15 tracey }
4145 bcbc97d8 2020-01-15 tracey
4146 56997cd3 2020-02-14 tracey if (gw_trans->commit_id == NULL) {
4147 ec46ccd7 2020-01-15 tracey struct got_reference *head_ref;
4148 deac617c 2020-02-14 tracey error = got_ref_open(&head_ref, gw_trans->repo,
4149 deac617c 2020-02-14 tracey gw_trans->headref, 0);
4150 ec46ccd7 2020-01-15 tracey if (error)
4151 ec46ccd7 2020-01-15 tracey goto done;
4152 deac617c 2020-02-14 tracey error = got_ref_resolve(&commit_id, gw_trans->repo, head_ref);
4153 84bf4df2 2020-02-03 stsp if (error)
4154 84bf4df2 2020-02-03 stsp goto done;
4155 ec46ccd7 2020-01-15 tracey got_ref_close(head_ref);
4156 56997cd3 2020-02-14 tracey /*
4157 56997cd3 2020-02-14 tracey * gw_trans->commit_id was not parsed from the querystring
4158 56997cd3 2020-02-14 tracey * we hit this code path from gw_index, where we don't know the
4159 56997cd3 2020-02-14 tracey * commit values for the tree link yet, so set
4160 56997cd3 2020-02-14 tracey * gw_trans->commit_id here to continue further into the tree
4161 56997cd3 2020-02-14 tracey */
4162 56997cd3 2020-02-14 tracey error = got_object_id_str(&gw_trans->commit_id, commit_id);
4163 56997cd3 2020-02-14 tracey if (error)
4164 56997cd3 2020-02-14 tracey goto done;
4165 ec46ccd7 2020-01-15 tracey
4166 84bf4df2 2020-02-03 stsp } else {
4167 f2f46662 2020-01-23 tracey error = got_repo_match_object_id(&commit_id, NULL,
4168 56997cd3 2020-02-14 tracey gw_trans->commit_id, GOT_OBJ_TYPE_COMMIT, 1,
4169 56997cd3 2020-02-14 tracey gw_trans->repo);
4170 84bf4df2 2020-02-03 stsp if (error)
4171 84bf4df2 2020-02-03 stsp goto done;
4172 84bf4df2 2020-02-03 stsp }
4173 f2f46662 2020-01-23 tracey
4174 56997cd3 2020-02-14 tracey error = got_object_id_by_path(&tree_id, gw_trans->repo, commit_id,
4175 56997cd3 2020-02-14 tracey path);
4176 bcbc97d8 2020-01-15 tracey if (error)
4177 bcbc97d8 2020-01-15 tracey goto done;
4178 bcbc97d8 2020-01-15 tracey
4179 deac617c 2020-02-14 tracey error = got_object_open_as_tree(&tree, gw_trans->repo, tree_id);
4180 bcbc97d8 2020-01-15 tracey if (error)
4181 bcbc97d8 2020-01-15 tracey goto done;
4182 bcbc97d8 2020-01-15 tracey
4183 bcbc97d8 2020-01-15 tracey nentries = got_object_tree_get_nentries(tree);
4184 bcbc97d8 2020-01-15 tracey for (i = 0; i < nentries; i++) {
4185 bcbc97d8 2020-01-15 tracey struct got_tree_entry *te;
4186 ec46ccd7 2020-01-15 tracey const char *modestr = "";
4187 84bf4df2 2020-02-03 stsp mode_t mode;
4188 bcbc97d8 2020-01-15 tracey
4189 bcbc97d8 2020-01-15 tracey te = got_object_tree_get_entry(tree, i);
4190 bcbc97d8 2020-01-15 tracey
4191 bcbc97d8 2020-01-15 tracey error = got_object_id_str(&id_str, got_tree_entry_get_id(te));
4192 bcbc97d8 2020-01-15 tracey if (error)
4193 bcbc97d8 2020-01-15 tracey goto done;
4194 bcbc97d8 2020-01-15 tracey
4195 84bf4df2 2020-02-03 stsp mode = got_tree_entry_get_mode(te);
4196 bcbc97d8 2020-01-15 tracey if (got_object_tree_entry_is_submodule(te))
4197 bcbc97d8 2020-01-15 tracey modestr = "$";
4198 bcbc97d8 2020-01-15 tracey else if (S_ISLNK(mode))
4199 bcbc97d8 2020-01-15 tracey modestr = "@";
4200 bcbc97d8 2020-01-15 tracey else if (S_ISDIR(mode))
4201 bcbc97d8 2020-01-15 tracey modestr = "/";
4202 bcbc97d8 2020-01-15 tracey else if (mode & S_IXUSR)
4203 bcbc97d8 2020-01-15 tracey modestr = "*";
4204 c3bcdfd5 2020-01-29 tracey
4205 c3bcdfd5 2020-01-29 tracey if (class_flip == 0) {
4206 84bf4df2 2020-02-03 stsp class = "back_lightgray";
4207 c3bcdfd5 2020-01-29 tracey class_flip = 1;
4208 c3bcdfd5 2020-01-29 tracey } else {
4209 84bf4df2 2020-02-03 stsp class = "back_white";
4210 c3bcdfd5 2020-01-29 tracey class_flip = 0;
4211 c3bcdfd5 2020-01-29 tracey }
4212 bcbc97d8 2020-01-15 tracey
4213 84bf4df2 2020-02-03 stsp if (S_ISDIR(mode)) {
4214 a5594e37 2020-02-05 tracey if (asprintf(&build_folder, "%s/%s",
4215 84bf4df2 2020-02-03 stsp gw_trans->repo_folder ? gw_trans->repo_folder : "",
4216 84bf4df2 2020-02-03 stsp got_tree_entry_get_name(te)) == -1) {
4217 53e81e48 2020-02-13 tracey error = got_error_from_errno("asprintf");
4218 84bf4df2 2020-02-03 stsp goto done;
4219 ec46ccd7 2020-01-15 tracey }
4220 626b25b6 2020-02-06 tracey
4221 c6eb96ac 2020-04-14 tracey href_blob = khttp_urlpart(NULL, NULL, "gotweb", "path",
4222 c6eb96ac 2020-04-14 tracey gw_trans->repo_name, "action",
4223 c6eb96ac 2020-04-14 tracey gw_get_action_name(gw_trans), "commit",
4224 c6eb96ac 2020-04-14 tracey gw_trans->commit_id, "folder", build_folder, NULL);
4225 19ff7638 2020-04-14 tracey if (href_blob == NULL) {
4226 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
4227 19ff7638 2020-04-14 tracey goto done;
4228 19ff7638 2020-04-14 tracey }
4229 626b25b6 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
4230 626b25b6 2020-02-06 tracey KATTR_ID, "tree_wrapper", KATTR__MAX);
4231 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4232 626b25b6 2020-02-06 tracey goto done;
4233 626b25b6 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
4234 626b25b6 2020-02-06 tracey KATTR_ID, "tree_line", KATTR_CLASS, class,
4235 626b25b6 2020-02-06 tracey KATTR__MAX);
4236 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4237 626b25b6 2020-02-06 tracey goto done;
4238 626b25b6 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
4239 626b25b6 2020-02-06 tracey KATTR_HREF, href_blob, KATTR_CLASS,
4240 626b25b6 2020-02-06 tracey "diff_directory", KATTR__MAX);
4241 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4242 626b25b6 2020-02-06 tracey goto done;
4243 32b9f7ed 2020-04-14 tracey kerr = khtml_printf(gw_trans->gw_html_req, "%s%s",
4244 32b9f7ed 2020-04-14 tracey got_tree_entry_get_name(te), modestr);
4245 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4246 626b25b6 2020-02-06 tracey goto done;
4247 626b25b6 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
4248 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4249 626b25b6 2020-02-06 tracey goto done;
4250 626b25b6 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
4251 626b25b6 2020-02-06 tracey KATTR_ID, "tree_line_blank", KATTR_CLASS, class,
4252 626b25b6 2020-02-06 tracey KATTR__MAX);
4253 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4254 84bf4df2 2020-02-03 stsp goto done;
4255 626b25b6 2020-02-06 tracey kerr = khtml_entity(gw_trans->gw_html_req,
4256 626b25b6 2020-02-06 tracey KENTITY_nbsp);
4257 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4258 626b25b6 2020-02-06 tracey goto done;
4259 626b25b6 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
4260 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4261 626b25b6 2020-02-06 tracey goto done;
4262 ec46ccd7 2020-01-15 tracey } else {
4263 c6eb96ac 2020-04-14 tracey href_blob = khttp_urlpart(NULL, NULL, "gotweb", "path",
4264 c6eb96ac 2020-04-14 tracey gw_trans->repo_name, "action", "blob", "commit",
4265 c6eb96ac 2020-04-14 tracey gw_trans->commit_id, "file",
4266 c6eb96ac 2020-04-14 tracey got_tree_entry_get_name(te), "folder",
4267 c6eb96ac 2020-04-14 tracey gw_trans->repo_folder ? gw_trans->repo_folder : "",
4268 c6eb96ac 2020-04-14 tracey NULL);
4269 19ff7638 2020-04-14 tracey if (href_blob == NULL) {
4270 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
4271 19ff7638 2020-04-14 tracey goto done;
4272 19ff7638 2020-04-14 tracey }
4273 c6eb96ac 2020-04-14 tracey href_blame = khttp_urlpart(NULL, NULL, "gotweb", "path",
4274 c6eb96ac 2020-04-14 tracey gw_trans->repo_name, "action", "blame", "commit",
4275 c6eb96ac 2020-04-14 tracey gw_trans->commit_id, "file",
4276 c6eb96ac 2020-04-14 tracey got_tree_entry_get_name(te), "folder",
4277 c6eb96ac 2020-04-14 tracey gw_trans->repo_folder ? gw_trans->repo_folder : "",
4278 c6eb96ac 2020-04-14 tracey NULL);
4279 19ff7638 2020-04-14 tracey if (href_blame == NULL) {
4280 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
4281 19ff7638 2020-04-14 tracey goto done;
4282 19ff7638 2020-04-14 tracey }
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_wrapper", KATTR__MAX);
4285 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4286 626b25b6 2020-02-06 tracey goto done;
4287 626b25b6 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
4288 626b25b6 2020-02-06 tracey KATTR_ID, "tree_line", KATTR_CLASS, class,
4289 626b25b6 2020-02-06 tracey KATTR__MAX);
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_attr(gw_trans->gw_html_req, KELEM_A,
4293 626b25b6 2020-02-06 tracey KATTR_HREF, href_blob, KATTR__MAX);
4294 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4295 626b25b6 2020-02-06 tracey goto done;
4296 32b9f7ed 2020-04-14 tracey kerr = khtml_printf(gw_trans->gw_html_req, "%s%s",
4297 32b9f7ed 2020-04-14 tracey got_tree_entry_get_name(te), modestr);
4298 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4299 626b25b6 2020-02-06 tracey goto done;
4300 626b25b6 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
4301 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4302 626b25b6 2020-02-06 tracey goto done;
4303 626b25b6 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
4304 626b25b6 2020-02-06 tracey KATTR_ID, "tree_line_navs", KATTR_CLASS, class,
4305 626b25b6 2020-02-06 tracey KATTR__MAX);
4306 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4307 626b25b6 2020-02-06 tracey goto done;
4308 ec46ccd7 2020-01-15 tracey
4309 626b25b6 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
4310 626b25b6 2020-02-06 tracey KATTR_HREF, href_blob, KATTR__MAX);
4311 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4312 626b25b6 2020-02-06 tracey goto done;
4313 626b25b6 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req, "blob");
4314 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4315 626b25b6 2020-02-06 tracey goto done;
4316 626b25b6 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
4317 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4318 626b25b6 2020-02-06 tracey goto done;
4319 626b25b6 2020-02-06 tracey
4320 626b25b6 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req, " | ");
4321 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4322 626b25b6 2020-02-06 tracey goto done;
4323 626b25b6 2020-02-06 tracey
4324 626b25b6 2020-02-06 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
4325 626b25b6 2020-02-06 tracey KATTR_HREF, href_blame, KATTR__MAX);
4326 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4327 626b25b6 2020-02-06 tracey goto done;
4328 626b25b6 2020-02-06 tracey kerr = khtml_puts(gw_trans->gw_html_req, "blame");
4329 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4330 626b25b6 2020-02-06 tracey goto done;
4331 626b25b6 2020-02-06 tracey
4332 626b25b6 2020-02-06 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 3);
4333 626b25b6 2020-02-06 tracey if (kerr != KCGI_OK)
4334 626b25b6 2020-02-06 tracey goto done;
4335 626b25b6 2020-02-06 tracey }
4336 bcbc97d8 2020-01-15 tracey free(id_str);
4337 84bf4df2 2020-02-03 stsp id_str = NULL;
4338 626b25b6 2020-02-06 tracey free(href_blob);
4339 626b25b6 2020-02-06 tracey href_blob = NULL;
4340 84bf4df2 2020-02-03 stsp free(build_folder);
4341 84bf4df2 2020-02-03 stsp build_folder = NULL;
4342 bcbc97d8 2020-01-15 tracey }
4343 bcbc97d8 2020-01-15 tracey done:
4344 bcbc97d8 2020-01-15 tracey if (tree)
4345 bcbc97d8 2020-01-15 tracey got_object_tree_close(tree);
4346 84bf4df2 2020-02-03 stsp free(id_str);
4347 626b25b6 2020-02-06 tracey free(href_blob);
4348 626b25b6 2020-02-06 tracey free(href_blame);
4349 2e676fc5 2020-01-15 tracey free(in_repo_path);
4350 bcbc97d8 2020-01-15 tracey free(tree_id);
4351 84bf4df2 2020-02-03 stsp free(build_folder);
4352 626b25b6 2020-02-06 tracey if (error == NULL && kerr != KCGI_OK)
4353 626b25b6 2020-02-06 tracey error = gw_kcgi_error(kerr);
4354 84bf4df2 2020-02-03 stsp return error;
4355 bcbc97d8 2020-01-15 tracey }
4356 bcbc97d8 2020-01-15 tracey
4357 51d4a92d 2020-02-03 tracey static const struct got_error *
4358 9eed6f10 2020-02-08 tracey gw_output_repo_heads(struct gw_trans *gw_trans)
4359 8d4d2453 2020-01-15 tracey {
4360 87f9ebf5 2020-01-15 tracey const struct got_error *error = NULL;
4361 87f9ebf5 2020-01-15 tracey struct got_reflist_head refs;
4362 87f9ebf5 2020-01-15 tracey struct got_reflist_entry *re;
4363 9eed6f10 2020-02-08 tracey char *age = NULL, *href_summary = NULL, *href_briefs = NULL;
4364 9eed6f10 2020-02-08 tracey char *href_commits = NULL;
4365 9eed6f10 2020-02-08 tracey enum kcgi_err kerr = KCGI_OK;
4366 51d4a92d 2020-02-03 tracey
4367 a0f36e03 2020-01-28 stsp SIMPLEQ_INIT(&refs);
4368 87f9ebf5 2020-01-15 tracey
4369 deac617c 2020-02-14 tracey error = got_ref_list(&refs, gw_trans->repo, "refs/heads",
4370 deac617c 2020-02-14 tracey got_ref_cmp_by_name, NULL);
4371 87f9ebf5 2020-01-15 tracey if (error)
4372 87f9ebf5 2020-01-15 tracey goto done;
4373 87f9ebf5 2020-01-15 tracey
4374 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
4375 9eed6f10 2020-02-08 tracey KATTR_ID, "summary_heads_title_wrapper", KATTR__MAX);
4376 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4377 9eed6f10 2020-02-08 tracey goto done;
4378 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
4379 9eed6f10 2020-02-08 tracey KATTR_ID, "summary_heads_title", KATTR__MAX);
4380 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4381 9eed6f10 2020-02-08 tracey goto done;
4382 9eed6f10 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req, "Heads");
4383 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4384 9eed6f10 2020-02-08 tracey goto done;
4385 9eed6f10 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
4386 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4387 9eed6f10 2020-02-08 tracey goto done;
4388 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
4389 9eed6f10 2020-02-08 tracey KATTR_ID, "summary_heads_content", KATTR__MAX);
4390 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4391 9eed6f10 2020-02-08 tracey goto done;
4392 9eed6f10 2020-02-08 tracey
4393 87f9ebf5 2020-01-15 tracey SIMPLEQ_FOREACH(re, &refs, entry) {
4394 7eb2c8df 2020-02-14 stsp const char *refname;
4395 87f9ebf5 2020-01-15 tracey
4396 eb4f3ad3 2020-02-14 stsp if (got_ref_is_symbolic(re->ref))
4397 eb4f3ad3 2020-02-14 stsp continue;
4398 eb4f3ad3 2020-02-14 stsp
4399 7eb2c8df 2020-02-14 stsp refname = got_ref_get_name(re->ref);
4400 7eb2c8df 2020-02-14 stsp if (strncmp(refname, "refs/heads/", 11) != 0)
4401 87f9ebf5 2020-01-15 tracey continue;
4402 87f9ebf5 2020-01-15 tracey
4403 017d6da3 2020-01-29 tracey error = gw_get_repo_age(&age, gw_trans, gw_trans->gw_dir->path,
4404 017d6da3 2020-01-29 tracey refname, TM_DIFF);
4405 d126c1b7 2020-01-29 stsp if (error)
4406 d126c1b7 2020-01-29 stsp goto done;
4407 87f9ebf5 2020-01-15 tracey
4408 9eed6f10 2020-02-08 tracey if (strncmp(refname, "refs/heads/", 11) == 0)
4409 9eed6f10 2020-02-08 tracey refname += 11;
4410 9eed6f10 2020-02-08 tracey
4411 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
4412 9eed6f10 2020-02-08 tracey KATTR_ID, "heads_wrapper", 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_attr(gw_trans->gw_html_req, KELEM_DIV,
4416 9eed6f10 2020-02-08 tracey KATTR_ID, "heads_age", KATTR__MAX);
4417 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4418 9eed6f10 2020-02-08 tracey goto done;
4419 9eed6f10 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req, age ? age : "");
4420 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4421 9eed6f10 2020-02-08 tracey goto done;
4422 9eed6f10 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
4423 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4424 9eed6f10 2020-02-08 tracey goto done;
4425 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
4426 9eed6f10 2020-02-08 tracey KATTR_ID, "heads_space", KATTR__MAX);
4427 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4428 9eed6f10 2020-02-08 tracey goto done;
4429 9eed6f10 2020-02-08 tracey kerr = khtml_entity(gw_trans->gw_html_req, KENTITY_nbsp);
4430 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4431 9eed6f10 2020-02-08 tracey goto done;
4432 9eed6f10 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
4433 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4434 9eed6f10 2020-02-08 tracey goto done;
4435 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
4436 9eed6f10 2020-02-08 tracey KATTR_ID, "head", KATTR__MAX);
4437 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4438 9eed6f10 2020-02-08 tracey goto done;
4439 e6789209 2020-04-14 tracey
4440 e6789209 2020-04-14 tracey href_summary = khttp_urlpart(NULL, NULL, "gotweb", "path",
4441 e6789209 2020-04-14 tracey gw_trans->repo_name, "action", "summary", "headref",
4442 19ff7638 2020-04-14 tracey refname, NULL);
4443 19ff7638 2020-04-14 tracey if (href_summary == NULL) {
4444 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
4445 19ff7638 2020-04-14 tracey goto done;
4446 19ff7638 2020-04-14 tracey }
4447 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A, KATTR_HREF,
4448 9eed6f10 2020-02-08 tracey href_summary, KATTR__MAX);
4449 9eed6f10 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req, refname);
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_closeelem(gw_trans->gw_html_req, 3);
4453 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4454 9eed6f10 2020-02-08 tracey goto done;
4455 87f9ebf5 2020-01-15 tracey
4456 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
4457 9eed6f10 2020-02-08 tracey "navs_wrapper", KATTR__MAX);
4458 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4459 9eed6f10 2020-02-08 tracey goto done;
4460 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
4461 9eed6f10 2020-02-08 tracey "navs", KATTR__MAX);
4462 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4463 9eed6f10 2020-02-08 tracey goto done;
4464 87f9ebf5 2020-01-15 tracey
4465 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A, KATTR_HREF,
4466 9eed6f10 2020-02-08 tracey href_summary, KATTR__MAX);
4467 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4468 9eed6f10 2020-02-08 tracey goto done;
4469 9eed6f10 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req, "summary");
4470 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4471 9eed6f10 2020-02-08 tracey goto done;
4472 9eed6f10 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
4473 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4474 9eed6f10 2020-02-08 tracey goto done;
4475 9eed6f10 2020-02-08 tracey
4476 9eed6f10 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req, " | ");
4477 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4478 87f9ebf5 2020-01-15 tracey goto done;
4479 e6789209 2020-04-14 tracey
4480 e6789209 2020-04-14 tracey href_briefs = khttp_urlpart(NULL, NULL, "gotweb", "path",
4481 e6789209 2020-04-14 tracey gw_trans->repo_name, "action", "briefs", "headref",
4482 e6789209 2020-04-14 tracey refname, NULL);
4483 19ff7638 2020-04-14 tracey if (href_briefs == NULL) {
4484 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
4485 19ff7638 2020-04-14 tracey goto done;
4486 19ff7638 2020-04-14 tracey }
4487 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A, KATTR_HREF,
4488 9eed6f10 2020-02-08 tracey href_briefs, KATTR__MAX);
4489 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4490 9eed6f10 2020-02-08 tracey goto done;
4491 9eed6f10 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req, "commit briefs");
4492 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4493 9eed6f10 2020-02-08 tracey goto done;
4494 9eed6f10 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
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_puts(gw_trans->gw_html_req, " | ");
4499 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4500 9eed6f10 2020-02-08 tracey goto done;
4501 87f9ebf5 2020-01-15 tracey
4502 e6789209 2020-04-14 tracey href_commits = khttp_urlpart(NULL, NULL, "gotweb", "path",
4503 e6789209 2020-04-14 tracey gw_trans->repo_name, "action", "commits", "headref",
4504 19ff7638 2020-04-14 tracey refname, NULL);
4505 19ff7638 2020-04-14 tracey if (href_commits == NULL) {
4506 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
4507 19ff7638 2020-04-14 tracey goto done;
4508 19ff7638 2020-04-14 tracey }
4509 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A, KATTR_HREF,
4510 9eed6f10 2020-02-08 tracey href_commits, KATTR__MAX);
4511 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4512 9eed6f10 2020-02-08 tracey goto done;
4513 9eed6f10 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req, "commits");
4514 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4515 9eed6f10 2020-02-08 tracey goto done;
4516 9eed6f10 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 3);
4517 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4518 9eed6f10 2020-02-08 tracey goto done;
4519 87f9ebf5 2020-01-15 tracey
4520 9eed6f10 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
4521 9eed6f10 2020-02-08 tracey "dotted_line", 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_closeelem(gw_trans->gw_html_req, 2);
4525 9eed6f10 2020-02-08 tracey if (kerr != KCGI_OK)
4526 9eed6f10 2020-02-08 tracey goto done;
4527 9eed6f10 2020-02-08 tracey free(href_summary);
4528 9eed6f10 2020-02-08 tracey href_summary = NULL;
4529 9eed6f10 2020-02-08 tracey free(href_briefs);
4530 9eed6f10 2020-02-08 tracey href_briefs = NULL;
4531 9eed6f10 2020-02-08 tracey free(href_commits);
4532 9eed6f10 2020-02-08 tracey href_commits = NULL;
4533 6c6c85af 2020-01-15 tracey }
4534 87f9ebf5 2020-01-15 tracey done:
4535 87f9ebf5 2020-01-15 tracey got_ref_list_free(&refs);
4536 9eed6f10 2020-02-08 tracey free(href_summary);
4537 9eed6f10 2020-02-08 tracey free(href_briefs);
4538 9eed6f10 2020-02-08 tracey free(href_commits);
4539 51d4a92d 2020-02-03 tracey return error;
4540 8d4d2453 2020-01-15 tracey }
4541 8d4d2453 2020-01-15 tracey
4542 4ae179a2 2020-02-08 tracey static const struct got_error *
4543 4ae179a2 2020-02-08 tracey gw_output_site_link(struct gw_trans *gw_trans)
4544 2c251c14 2020-01-15 tracey {
4545 4ae179a2 2020-02-08 tracey const struct got_error *error = NULL;
4546 4ae179a2 2020-02-08 tracey char *href_summary = NULL;
4547 4ae179a2 2020-02-08 tracey enum kcgi_err kerr = KCGI_OK;
4548 2c251c14 2020-01-15 tracey
4549 4ae179a2 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
4550 4ae179a2 2020-02-08 tracey "site_link", KATTR__MAX);
4551 4ae179a2 2020-02-08 tracey if (kerr != KCGI_OK)
4552 4ae179a2 2020-02-08 tracey goto done;
4553 4ae179a2 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A, KATTR_HREF, GOTWEB,
4554 4ae179a2 2020-02-08 tracey KATTR__MAX);
4555 4ae179a2 2020-02-08 tracey if (kerr != KCGI_OK)
4556 4ae179a2 2020-02-08 tracey goto done;
4557 4ae179a2 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req,
4558 4ae179a2 2020-02-08 tracey gw_trans->gw_conf->got_site_link);
4559 4ae179a2 2020-02-08 tracey if (kerr != KCGI_OK)
4560 4ae179a2 2020-02-08 tracey goto done;
4561 4ae179a2 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
4562 4ae179a2 2020-02-08 tracey if (kerr != KCGI_OK)
4563 4ae179a2 2020-02-08 tracey goto done;
4564 2c251c14 2020-01-15 tracey
4565 4ae179a2 2020-02-08 tracey if (gw_trans->repo_name != NULL) {
4566 4ae179a2 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req, " / ");
4567 4ae179a2 2020-02-08 tracey if (kerr != KCGI_OK)
4568 4ae179a2 2020-02-08 tracey goto done;
4569 6918c609 2020-04-14 tracey
4570 6918c609 2020-04-14 tracey href_summary = khttp_urlpart(NULL, NULL, "gotweb", "path",
4571 19ff7638 2020-04-14 tracey gw_trans->repo_name, "action", "summary", NULL);
4572 19ff7638 2020-04-14 tracey if (href_summary == NULL) {
4573 19ff7638 2020-04-14 tracey error = got_error_from_errno("khttp_urlpart");
4574 19ff7638 2020-04-14 tracey goto done;
4575 19ff7638 2020-04-14 tracey }
4576 4ae179a2 2020-02-08 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A, KATTR_HREF,
4577 4ae179a2 2020-02-08 tracey href_summary, KATTR__MAX);
4578 4ae179a2 2020-02-08 tracey if (kerr != KCGI_OK)
4579 4ae179a2 2020-02-08 tracey goto done;
4580 4ae179a2 2020-02-08 tracey kerr = khtml_puts(gw_trans->gw_html_req, gw_trans->repo_name);
4581 4ae179a2 2020-02-08 tracey if (kerr != KCGI_OK)
4582 4ae179a2 2020-02-08 tracey goto done;
4583 4ae179a2 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
4584 4ae179a2 2020-02-08 tracey if (kerr != KCGI_OK)
4585 4ae179a2 2020-02-08 tracey goto done;
4586 32b9f7ed 2020-04-14 tracey kerr = khtml_printf(gw_trans->gw_html_req, " / %s",
4587 5d1296de 2020-02-13 stsp gw_get_action_name(gw_trans));
4588 4ae179a2 2020-02-08 tracey if (kerr != KCGI_OK)
4589 4ae179a2 2020-02-08 tracey goto done;
4590 eb89db64 2020-02-03 stsp }
4591 2c251c14 2020-01-15 tracey
4592 4ae179a2 2020-02-08 tracey kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
4593 4ae179a2 2020-02-08 tracey if (kerr != KCGI_OK)
4594 4ae179a2 2020-02-08 tracey goto done;
4595 4ae179a2 2020-02-08 tracey done:
4596 4ae179a2 2020-02-08 tracey free(href_summary);
4597 6918c609 2020-04-14 tracey if (error == NULL && kerr != KCGI_OK)
4598 6918c609 2020-04-14 tracey error = gw_kcgi_error(kerr);
4599 4ae179a2 2020-02-08 tracey return error;
4600 2c251c14 2020-01-15 tracey }
4601 2c251c14 2020-01-15 tracey
4602 83eb9a68 2020-02-03 stsp static const struct got_error *
4603 f7cc9480 2020-02-05 tracey gw_colordiff_line(struct gw_trans *gw_trans, char *buf)
4604 ec46ccd7 2020-01-15 tracey {
4605 ec46ccd7 2020-01-15 tracey const struct got_error *error = NULL;
4606 f7cc9480 2020-02-05 tracey char *color = NULL;
4607 f7cc9480 2020-02-05 tracey enum kcgi_err kerr = KCGI_OK;
4608 83eb9a68 2020-02-03 stsp
4609 ec46ccd7 2020-01-15 tracey if (strncmp(buf, "-", 1) == 0)
4610 ec46ccd7 2020-01-15 tracey color = "diff_minus";
4611 83eb9a68 2020-02-03 stsp else if (strncmp(buf, "+", 1) == 0)
4612 ec46ccd7 2020-01-15 tracey color = "diff_plus";
4613 83eb9a68 2020-02-03 stsp else if (strncmp(buf, "@@", 2) == 0)
4614 ec46ccd7 2020-01-15 tracey color = "diff_chunk_header";
4615 83eb9a68 2020-02-03 stsp else if (strncmp(buf, "@@", 2) == 0)
4616 ec46ccd7 2020-01-15 tracey color = "diff_chunk_header";
4617 83eb9a68 2020-02-03 stsp else if (strncmp(buf, "commit +", 8) == 0)
4618 ec46ccd7 2020-01-15 tracey color = "diff_meta";
4619 83eb9a68 2020-02-03 stsp else if (strncmp(buf, "commit -", 8) == 0)
4620 ec46ccd7 2020-01-15 tracey color = "diff_meta";
4621 83eb9a68 2020-02-03 stsp else if (strncmp(buf, "blob +", 6) == 0)
4622 ec46ccd7 2020-01-15 tracey color = "diff_meta";
4623 83eb9a68 2020-02-03 stsp else if (strncmp(buf, "blob -", 6) == 0)
4624 ec46ccd7 2020-01-15 tracey color = "diff_meta";
4625 83eb9a68 2020-02-03 stsp else if (strncmp(buf, "file +", 6) == 0)
4626 ec46ccd7 2020-01-15 tracey color = "diff_meta";
4627 83eb9a68 2020-02-03 stsp else if (strncmp(buf, "file -", 6) == 0)
4628 ec46ccd7 2020-01-15 tracey color = "diff_meta";
4629 83eb9a68 2020-02-03 stsp else if (strncmp(buf, "from:", 5) == 0)
4630 ec46ccd7 2020-01-15 tracey color = "diff_author";
4631 83eb9a68 2020-02-03 stsp else if (strncmp(buf, "via:", 4) == 0)
4632 ec46ccd7 2020-01-15 tracey color = "diff_author";
4633 83eb9a68 2020-02-03 stsp else if (strncmp(buf, "date:", 5) == 0)
4634 ec46ccd7 2020-01-15 tracey color = "diff_date";
4635 f7cc9480 2020-02-05 tracey kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
4636 f7cc9480 2020-02-05 tracey "diff_line", KATTR_CLASS, color ? color : "", KATTR__MAX);
4637 f7cc9480 2020-02-05 tracey if (error == NULL && kerr != KCGI_OK)
4638 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
4639 070fee27 2020-02-03 stsp return error;
4640 2c251c14 2020-01-15 tracey }
4641 2c251c14 2020-01-15 tracey
4642 2c251c14 2020-01-15 tracey int
4643 c08369d7 2020-01-15 tracey main(int argc, char *argv[])
4644 2c251c14 2020-01-15 tracey {
4645 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
4646 54415d85 2020-01-15 tracey struct gw_trans *gw_trans;
4647 2c251c14 2020-01-15 tracey struct gw_dir *dir = NULL, *tdir;
4648 2c251c14 2020-01-15 tracey const char *page = "index";
4649 4ceb8155 2020-01-15 tracey int gw_malloc = 1;
4650 795c10a4 2020-02-20 tracey enum kcgi_err kerr = KCGI_OK;
4651 2c251c14 2020-01-15 tracey
4652 54415d85 2020-01-15 tracey if ((gw_trans = malloc(sizeof(struct gw_trans))) == NULL)
4653 2c251c14 2020-01-15 tracey errx(1, "malloc");
4654 2c251c14 2020-01-15 tracey
4655 2c251c14 2020-01-15 tracey if ((gw_trans->gw_req = malloc(sizeof(struct kreq))) == NULL)
4656 2c251c14 2020-01-15 tracey errx(1, "malloc");
4657 2c251c14 2020-01-15 tracey
4658 2c251c14 2020-01-15 tracey if ((gw_trans->gw_html_req = malloc(sizeof(struct khtmlreq))) == NULL)
4659 2c251c14 2020-01-15 tracey errx(1, "malloc");
4660 2c251c14 2020-01-15 tracey
4661 2c251c14 2020-01-15 tracey if ((gw_trans->gw_tmpl = malloc(sizeof(struct ktemplate))) == NULL)
4662 2c251c14 2020-01-15 tracey errx(1, "malloc");
4663 2c251c14 2020-01-15 tracey
4664 c25c2314 2020-01-28 stsp kerr = khttp_parse(gw_trans->gw_req, gw_keys, KEY__ZMAX, &page, 1, 0);
4665 c25c2314 2020-01-28 stsp if (kerr != KCGI_OK) {
4666 2447adad 2020-02-06 stsp error = gw_kcgi_error(kerr);
4667 c119608e 2020-01-28 stsp goto done;
4668 46b9c89b 2020-01-15 tracey }
4669 46b9c89b 2020-01-15 tracey
4670 2c251c14 2020-01-15 tracey TAILQ_INIT(&gw_trans->gw_dirs);
4671 f2f46662 2020-01-23 tracey TAILQ_INIT(&gw_trans->gw_headers);
4672 2c251c14 2020-01-15 tracey
4673 f1200fe3 2020-02-13 tracey gw_trans->action = -1;
4674 2c251c14 2020-01-15 tracey gw_trans->page = 0;
4675 2c251c14 2020-01-15 tracey gw_trans->repos_total = 0;
4676 2c251c14 2020-01-15 tracey gw_trans->repo_path = NULL;
4677 56997cd3 2020-02-14 tracey gw_trans->commit_id = NULL;
4678 55e46400 2020-02-18 tracey gw_trans->next_id = NULL;
4679 55e46400 2020-02-18 tracey gw_trans->next_prev_id = NULL;
4680 55e46400 2020-02-18 tracey gw_trans->prev_id = NULL;
4681 55e46400 2020-02-18 tracey gw_trans->prev_prev_id = NULL;
4682 742ba378 2020-02-14 stsp gw_trans->headref = GOT_REF_HEAD;
4683 2c251c14 2020-01-15 tracey gw_trans->mime = KMIME_TEXT_HTML;
4684 54415d85 2020-01-15 tracey gw_trans->gw_tmpl->key = gw_templs;
4685 2c251c14 2020-01-15 tracey gw_trans->gw_tmpl->keysz = TEMPL__MAX;
4686 2c251c14 2020-01-15 tracey gw_trans->gw_tmpl->arg = gw_trans;
4687 2c251c14 2020-01-15 tracey gw_trans->gw_tmpl->cb = gw_template;
4688 c34ec417 2020-06-22 tracey
4689 c34ec417 2020-06-22 tracey error = parse_gotweb_config(&gw_trans->gw_conf, GOTWEB_CONF);
4690 c119608e 2020-01-28 stsp if (error)
4691 2c251c14 2020-01-15 tracey goto done;
4692 2c251c14 2020-01-15 tracey
4693 2c251c14 2020-01-15 tracey error = gw_parse_querystring(gw_trans);
4694 2c251c14 2020-01-15 tracey if (error)
4695 c119608e 2020-01-28 stsp goto done;
4696 2c251c14 2020-01-15 tracey
4697 017d6da3 2020-01-29 tracey if (gw_trans->action == GW_BLOB)
4698 017d6da3 2020-01-29 tracey error = gw_blob(gw_trans);
4699 017d6da3 2020-01-29 tracey else
4700 017d6da3 2020-01-29 tracey error = gw_display_index(gw_trans);
4701 2c251c14 2020-01-15 tracey done:
4702 2c251c14 2020-01-15 tracey if (gw_malloc) {
4703 2c251c14 2020-01-15 tracey free(gw_trans->gw_conf->got_repos_path);
4704 2c251c14 2020-01-15 tracey free(gw_trans->gw_conf->got_site_name);
4705 2c251c14 2020-01-15 tracey free(gw_trans->gw_conf->got_site_owner);
4706 2c251c14 2020-01-15 tracey free(gw_trans->gw_conf->got_site_link);
4707 2c251c14 2020-01-15 tracey free(gw_trans->gw_conf->got_logo);
4708 2c251c14 2020-01-15 tracey free(gw_trans->gw_conf->got_logo_url);
4709 f71c0a3a 2020-06-23 tracey free(gw_trans->gw_conf);
4710 56997cd3 2020-02-14 tracey free(gw_trans->commit_id);
4711 55e46400 2020-02-18 tracey free(gw_trans->next_id);
4712 55e46400 2020-02-18 tracey free(gw_trans->next_prev_id);
4713 55e46400 2020-02-18 tracey free(gw_trans->prev_id);
4714 55e46400 2020-02-18 tracey free(gw_trans->prev_prev_id);
4715 2c251c14 2020-01-15 tracey free(gw_trans->repo_path);
4716 deac617c 2020-02-14 tracey if (gw_trans->repo)
4717 deac617c 2020-02-14 tracey got_repo_close(gw_trans->repo);
4718 2c251c14 2020-01-15 tracey
4719 2c251c14 2020-01-15 tracey TAILQ_FOREACH_SAFE(dir, &gw_trans->gw_dirs, entry, tdir) {
4720 2c251c14 2020-01-15 tracey free(dir->name);
4721 2c251c14 2020-01-15 tracey free(dir->description);
4722 2c251c14 2020-01-15 tracey free(dir->age);
4723 2c251c14 2020-01-15 tracey free(dir->url);
4724 2c251c14 2020-01-15 tracey free(dir->path);
4725 2c251c14 2020-01-15 tracey free(dir);
4726 2c251c14 2020-01-15 tracey }
4727 2c251c14 2020-01-15 tracey
4728 2c251c14 2020-01-15 tracey }
4729 2c251c14 2020-01-15 tracey
4730 2c251c14 2020-01-15 tracey khttp_free(gw_trans->gw_req);
4731 d56b34ca 2020-01-29 stsp return 0;
4732 2c251c14 2020-01-15 tracey }