Blame


1 2c251c14 2020-01-15 tracey /*
2 2c251c14 2020-01-15 tracey * Copyright (c) 2019 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 * Copyright (c) 2014, 2015, 2017 Kristaps Dzonsons <kristaps@bsd.lv>
5 2c251c14 2020-01-15 tracey *
6 2c251c14 2020-01-15 tracey * Permission to use, copy, modify, and distribute this software for any
7 2c251c14 2020-01-15 tracey * purpose with or without fee is hereby granted, provided that the above
8 2c251c14 2020-01-15 tracey * copyright notice and this permission notice appear in all copies.
9 2c251c14 2020-01-15 tracey *
10 2c251c14 2020-01-15 tracey * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 2c251c14 2020-01-15 tracey * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 2c251c14 2020-01-15 tracey * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 2c251c14 2020-01-15 tracey * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 2c251c14 2020-01-15 tracey * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 2c251c14 2020-01-15 tracey * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 2c251c14 2020-01-15 tracey * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 2c251c14 2020-01-15 tracey */
18 2c251c14 2020-01-15 tracey
19 2c251c14 2020-01-15 tracey #include <sys/queue.h>
20 2c251c14 2020-01-15 tracey #include <sys/stat.h>
21 2c251c14 2020-01-15 tracey #include <sys/types.h>
22 2c251c14 2020-01-15 tracey
23 2c251c14 2020-01-15 tracey #include <dirent.h>
24 2c251c14 2020-01-15 tracey #include <err.h>
25 2c251c14 2020-01-15 tracey #include <stdarg.h>
26 2c251c14 2020-01-15 tracey #include <stdbool.h>
27 2c251c14 2020-01-15 tracey #include <stdint.h>
28 2c251c14 2020-01-15 tracey #include <stdio.h>
29 2c251c14 2020-01-15 tracey #include <stdlib.h>
30 2c251c14 2020-01-15 tracey #include <string.h>
31 2c251c14 2020-01-15 tracey #include <unistd.h>
32 2c251c14 2020-01-15 tracey
33 2c251c14 2020-01-15 tracey #include <got_object.h>
34 2c251c14 2020-01-15 tracey #include <got_reference.h>
35 2c251c14 2020-01-15 tracey #include <got_repository.h>
36 2c251c14 2020-01-15 tracey #include <got_path.h>
37 2c251c14 2020-01-15 tracey #include <got_cancel.h>
38 2c251c14 2020-01-15 tracey #include <got_worktree.h>
39 2c251c14 2020-01-15 tracey #include <got_diff.h>
40 2c251c14 2020-01-15 tracey #include <got_commit_graph.h>
41 2c251c14 2020-01-15 tracey #include <got_blame.h>
42 2c251c14 2020-01-15 tracey #include <got_privsep.h>
43 2c251c14 2020-01-15 tracey #include <got_opentemp.h>
44 2c251c14 2020-01-15 tracey
45 2c251c14 2020-01-15 tracey #include <kcgi.h>
46 2c251c14 2020-01-15 tracey #include <kcgihtml.h>
47 2c251c14 2020-01-15 tracey
48 2c251c14 2020-01-15 tracey #include "gotweb.h"
49 2c251c14 2020-01-15 tracey #include "gotweb_ui.h"
50 2c251c14 2020-01-15 tracey
51 2c251c14 2020-01-15 tracey #ifndef nitems
52 2c251c14 2020-01-15 tracey #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
53 2c251c14 2020-01-15 tracey #endif
54 2c251c14 2020-01-15 tracey
55 2c251c14 2020-01-15 tracey struct trans {
56 2c251c14 2020-01-15 tracey TAILQ_HEAD(dirs, gw_dir) gw_dirs;
57 46b9c89b 2020-01-15 tracey struct gw_dir *gw_dir;
58 2c251c14 2020-01-15 tracey struct gotweb_conf *gw_conf;
59 2c251c14 2020-01-15 tracey struct ktemplate *gw_tmpl;
60 2c251c14 2020-01-15 tracey struct khtmlreq *gw_html_req;
61 2c251c14 2020-01-15 tracey struct kreq *gw_req;
62 2c251c14 2020-01-15 tracey char *repo_name;
63 2c251c14 2020-01-15 tracey char *repo_path;
64 2c251c14 2020-01-15 tracey char *commit;
65 2c251c14 2020-01-15 tracey char *repo_file;
66 2c251c14 2020-01-15 tracey char *action_name;
67 2c251c14 2020-01-15 tracey unsigned int action;
68 2c251c14 2020-01-15 tracey unsigned int page;
69 2c251c14 2020-01-15 tracey unsigned int repos_total;
70 387a29ba 2020-01-15 tracey enum kmime mime;
71 2c251c14 2020-01-15 tracey };
72 2c251c14 2020-01-15 tracey
73 2c251c14 2020-01-15 tracey enum gw_key {
74 2c251c14 2020-01-15 tracey KEY_PATH,
75 2c251c14 2020-01-15 tracey KEY_ACTION,
76 2c251c14 2020-01-15 tracey KEY_COMMIT_ID,
77 2c251c14 2020-01-15 tracey KEY_FILE,
78 2c251c14 2020-01-15 tracey KEY_PAGE,
79 2c251c14 2020-01-15 tracey KEY__MAX
80 2c251c14 2020-01-15 tracey };
81 2c251c14 2020-01-15 tracey
82 2c251c14 2020-01-15 tracey struct gw_dir {
83 2c251c14 2020-01-15 tracey TAILQ_ENTRY(gw_dir) entry;
84 2c251c14 2020-01-15 tracey char *name;
85 2c251c14 2020-01-15 tracey char *owner;
86 2c251c14 2020-01-15 tracey char *description;
87 2c251c14 2020-01-15 tracey char *url;
88 2c251c14 2020-01-15 tracey char *age;
89 2c251c14 2020-01-15 tracey char *path;
90 2c251c14 2020-01-15 tracey };
91 2c251c14 2020-01-15 tracey
92 2c251c14 2020-01-15 tracey enum tmpl {
93 2c251c14 2020-01-15 tracey TEMPL_HEAD,
94 2c251c14 2020-01-15 tracey TEMPL_HEADER,
95 2c251c14 2020-01-15 tracey TEMPL_SITEPATH,
96 2c251c14 2020-01-15 tracey TEMPL_SITEOWNER,
97 2c251c14 2020-01-15 tracey TEMPL_TITLE,
98 2c251c14 2020-01-15 tracey TEMPL_SEARCH,
99 2c251c14 2020-01-15 tracey TEMPL_CONTENT,
100 2c251c14 2020-01-15 tracey TEMPL__MAX
101 2c251c14 2020-01-15 tracey };
102 2c251c14 2020-01-15 tracey
103 387a29ba 2020-01-15 tracey enum ref_tm {
104 387a29ba 2020-01-15 tracey TM_DIFF,
105 387a29ba 2020-01-15 tracey TM_LONG,
106 387a29ba 2020-01-15 tracey };
107 387a29ba 2020-01-15 tracey
108 2c251c14 2020-01-15 tracey static const char *const templs[TEMPL__MAX] = {
109 2c251c14 2020-01-15 tracey "head",
110 2c251c14 2020-01-15 tracey "header",
111 2c251c14 2020-01-15 tracey "sitepath",
112 2c251c14 2020-01-15 tracey "siteowner",
113 2c251c14 2020-01-15 tracey "title",
114 2c251c14 2020-01-15 tracey "search",
115 2c251c14 2020-01-15 tracey "content",
116 2c251c14 2020-01-15 tracey };
117 2c251c14 2020-01-15 tracey
118 2c251c14 2020-01-15 tracey static const struct kvalid gw_keys[KEY__MAX] = {
119 2c251c14 2020-01-15 tracey { kvalid_stringne, "path" },
120 2c251c14 2020-01-15 tracey { kvalid_stringne, "action" },
121 2c251c14 2020-01-15 tracey { kvalid_stringne, "commit" },
122 2c251c14 2020-01-15 tracey { kvalid_stringne, "file" },
123 2c251c14 2020-01-15 tracey { kvalid_int, "page" },
124 2c251c14 2020-01-15 tracey };
125 2c251c14 2020-01-15 tracey
126 2c251c14 2020-01-15 tracey static struct gw_dir *gw_init_gw_dir(char *);
127 2c251c14 2020-01-15 tracey
128 2c251c14 2020-01-15 tracey static char *gw_get_repo_description(struct trans *,
129 2c251c14 2020-01-15 tracey char *);
130 2c251c14 2020-01-15 tracey static char *gw_get_repo_owner(struct trans *,
131 2c251c14 2020-01-15 tracey char *);
132 2c251c14 2020-01-15 tracey static char *gw_get_repo_age(struct trans *,
133 387a29ba 2020-01-15 tracey char *, char *, int);
134 8d4d2453 2020-01-15 tracey static char *gw_get_repo_shortlog(struct trans *);
135 8d4d2453 2020-01-15 tracey static char *gw_get_repo_tags(struct trans *);
136 8d4d2453 2020-01-15 tracey static char *gw_get_repo_heads(struct trans *);
137 2c251c14 2020-01-15 tracey static char *gw_get_clone_url(struct trans *, char *);
138 2c251c14 2020-01-15 tracey static char *gw_get_got_link(struct trans *);
139 2c251c14 2020-01-15 tracey static char *gw_get_site_link(struct trans *);
140 2c251c14 2020-01-15 tracey static char *gw_html_escape(const char *);
141 2c251c14 2020-01-15 tracey
142 2c251c14 2020-01-15 tracey static void gw_display_open(struct trans *, enum khttp,
143 2c251c14 2020-01-15 tracey enum kmime);
144 2c251c14 2020-01-15 tracey static void gw_display_index(struct trans *,
145 2c251c14 2020-01-15 tracey const struct got_error *);
146 2c251c14 2020-01-15 tracey
147 2c251c14 2020-01-15 tracey static int gw_template(size_t, void *);
148 2c251c14 2020-01-15 tracey
149 2c251c14 2020-01-15 tracey static const struct got_error* apply_unveil(const char *, const char *);
150 2c251c14 2020-01-15 tracey static const struct got_error* gw_load_got_paths(struct trans *);
151 2c251c14 2020-01-15 tracey static const struct got_error* gw_load_got_path(struct trans *,
152 2c251c14 2020-01-15 tracey struct gw_dir *);
153 2c251c14 2020-01-15 tracey static const struct got_error* gw_parse_querystring(struct trans *);
154 2c251c14 2020-01-15 tracey
155 2c251c14 2020-01-15 tracey static const struct got_error* gw_blame(struct trans *);
156 2c251c14 2020-01-15 tracey static const struct got_error* gw_blob(struct trans *);
157 2c251c14 2020-01-15 tracey static const struct got_error* gw_blob_diff(struct trans *);
158 2c251c14 2020-01-15 tracey static const struct got_error* gw_commit(struct trans *);
159 2c251c14 2020-01-15 tracey static const struct got_error* gw_commit_diff(struct trans *);
160 2c251c14 2020-01-15 tracey static const struct got_error* gw_history(struct trans *);
161 2c251c14 2020-01-15 tracey static const struct got_error* gw_index(struct trans *);
162 2c251c14 2020-01-15 tracey static const struct got_error* gw_log(struct trans *);
163 2c251c14 2020-01-15 tracey static const struct got_error* gw_raw(struct trans *);
164 2c251c14 2020-01-15 tracey static const struct got_error* gw_shortlog(struct trans *);
165 2c251c14 2020-01-15 tracey static const struct got_error* gw_snapshot(struct trans *);
166 387a29ba 2020-01-15 tracey static const struct got_error* gw_summary(struct trans *);
167 2c251c14 2020-01-15 tracey static const struct got_error* gw_tree(struct trans *);
168 2c251c14 2020-01-15 tracey
169 2c251c14 2020-01-15 tracey struct gw_query_action {
170 2c251c14 2020-01-15 tracey unsigned int func_id;
171 2c251c14 2020-01-15 tracey const char *func_name;
172 2c251c14 2020-01-15 tracey const struct got_error *(*func_main)(struct trans *);
173 2c251c14 2020-01-15 tracey char *template;
174 2c251c14 2020-01-15 tracey };
175 2c251c14 2020-01-15 tracey
176 2c251c14 2020-01-15 tracey enum gw_query_actions {
177 2c251c14 2020-01-15 tracey GW_BLAME,
178 2c251c14 2020-01-15 tracey GW_BLOB,
179 2c251c14 2020-01-15 tracey GW_BLOBDIFF,
180 2c251c14 2020-01-15 tracey GW_COMMIT,
181 2c251c14 2020-01-15 tracey GW_COMMITDIFF,
182 2c251c14 2020-01-15 tracey GW_ERR,
183 2c251c14 2020-01-15 tracey GW_HISTORY,
184 2c251c14 2020-01-15 tracey GW_INDEX,
185 2c251c14 2020-01-15 tracey GW_LOG,
186 2c251c14 2020-01-15 tracey GW_RAW,
187 2c251c14 2020-01-15 tracey GW_SHORTLOG,
188 2c251c14 2020-01-15 tracey GW_SNAPSHOT,
189 2c251c14 2020-01-15 tracey GW_SUMMARY,
190 2c251c14 2020-01-15 tracey GW_TREE
191 2c251c14 2020-01-15 tracey };
192 2c251c14 2020-01-15 tracey
193 2c251c14 2020-01-15 tracey static struct gw_query_action gw_query_funcs[] = {
194 2c251c14 2020-01-15 tracey { GW_BLAME, "blame", gw_blame, "gw_tmpl/index.tmpl" },
195 2c251c14 2020-01-15 tracey { GW_BLOB, "blob", gw_blob, "gw_tmpl/index.tmpl" },
196 2c251c14 2020-01-15 tracey { GW_BLOBDIFF, "blobdiff", gw_blob_diff, "gw_tmpl/index.tmpl" },
197 2c251c14 2020-01-15 tracey { GW_COMMIT, "commit", gw_commit, "gw_tmpl/index.tmpl" },
198 2c251c14 2020-01-15 tracey { GW_COMMITDIFF, "commit_diff", gw_commit_diff, "gw_tmpl/index.tmpl" },
199 387a29ba 2020-01-15 tracey { GW_ERR, NULL, NULL, "gw_tmpl/index.tmpl" },
200 2c251c14 2020-01-15 tracey { GW_HISTORY, "history", gw_history, "gw_tmpl/index.tmpl" },
201 2c251c14 2020-01-15 tracey { GW_INDEX, "index", gw_index, "gw_tmpl/index.tmpl" },
202 2c251c14 2020-01-15 tracey { GW_LOG, "log", gw_log, "gw_tmpl/index.tmpl" },
203 2c251c14 2020-01-15 tracey { GW_RAW, "raw", gw_raw, "gw_tmpl/index.tmpl" },
204 2c251c14 2020-01-15 tracey { GW_SHORTLOG, "shortlog", gw_shortlog, "gw_tmpl/index.tmpl" },
205 2c251c14 2020-01-15 tracey { GW_SNAPSHOT, "snapshot", gw_snapshot, "gw_tmpl/index.tmpl" },
206 46b9c89b 2020-01-15 tracey { GW_SUMMARY, "summary", gw_summary, "gw_tmpl/index.tmpl" },
207 2c251c14 2020-01-15 tracey { GW_TREE, "tree", gw_tree, "gw_tmpl/index.tmpl" },
208 2c251c14 2020-01-15 tracey };
209 2c251c14 2020-01-15 tracey
210 2c251c14 2020-01-15 tracey static const struct got_error *
211 2c251c14 2020-01-15 tracey apply_unveil(const char *repo_path, const char *repo_file)
212 2c251c14 2020-01-15 tracey {
213 2c251c14 2020-01-15 tracey const struct got_error *err;
214 2c251c14 2020-01-15 tracey
215 2c251c14 2020-01-15 tracey if (repo_path && repo_file) {
216 2c251c14 2020-01-15 tracey char *full_path;
217 2c251c14 2020-01-15 tracey if ((asprintf(&full_path, "%s/%s", repo_path, repo_file)) == -1)
218 2c251c14 2020-01-15 tracey return got_error_from_errno("asprintf unveil");
219 2c251c14 2020-01-15 tracey if (unveil(full_path, "r") != 0)
220 2c251c14 2020-01-15 tracey return got_error_from_errno2("unveil", full_path);
221 2c251c14 2020-01-15 tracey }
222 2c251c14 2020-01-15 tracey
223 2c251c14 2020-01-15 tracey if (repo_path && unveil(repo_path, "r") != 0)
224 2c251c14 2020-01-15 tracey return got_error_from_errno2("unveil", repo_path);
225 2c251c14 2020-01-15 tracey
226 2c251c14 2020-01-15 tracey if (unveil("/tmp", "rwc") != 0)
227 2c251c14 2020-01-15 tracey return got_error_from_errno2("unveil", "/tmp");
228 2c251c14 2020-01-15 tracey
229 2c251c14 2020-01-15 tracey err = got_privsep_unveil_exec_helpers();
230 2c251c14 2020-01-15 tracey if (err != NULL)
231 2c251c14 2020-01-15 tracey return err;
232 2c251c14 2020-01-15 tracey
233 2c251c14 2020-01-15 tracey if (unveil(NULL, NULL) != 0)
234 2c251c14 2020-01-15 tracey return got_error_from_errno("unveil");
235 2c251c14 2020-01-15 tracey
236 2c251c14 2020-01-15 tracey return NULL;
237 2c251c14 2020-01-15 tracey }
238 2c251c14 2020-01-15 tracey
239 2c251c14 2020-01-15 tracey static const struct got_error *
240 2c251c14 2020-01-15 tracey gw_blame(struct trans *gw_trans)
241 2c251c14 2020-01-15 tracey {
242 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
243 2c251c14 2020-01-15 tracey
244 2c251c14 2020-01-15 tracey return error;
245 2c251c14 2020-01-15 tracey }
246 2c251c14 2020-01-15 tracey
247 2c251c14 2020-01-15 tracey static const struct got_error *
248 2c251c14 2020-01-15 tracey gw_blob(struct trans *gw_trans)
249 2c251c14 2020-01-15 tracey {
250 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
251 2c251c14 2020-01-15 tracey
252 2c251c14 2020-01-15 tracey return error;
253 2c251c14 2020-01-15 tracey }
254 2c251c14 2020-01-15 tracey
255 2c251c14 2020-01-15 tracey static const struct got_error *
256 2c251c14 2020-01-15 tracey gw_blob_diff(struct trans *gw_trans)
257 2c251c14 2020-01-15 tracey {
258 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
259 2c251c14 2020-01-15 tracey
260 2c251c14 2020-01-15 tracey return error;
261 2c251c14 2020-01-15 tracey }
262 2c251c14 2020-01-15 tracey
263 2c251c14 2020-01-15 tracey static const struct got_error *
264 2c251c14 2020-01-15 tracey gw_commit(struct trans *gw_trans)
265 2c251c14 2020-01-15 tracey {
266 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
267 2c251c14 2020-01-15 tracey
268 2c251c14 2020-01-15 tracey return error;
269 2c251c14 2020-01-15 tracey }
270 2c251c14 2020-01-15 tracey
271 2c251c14 2020-01-15 tracey static const struct got_error *
272 2c251c14 2020-01-15 tracey gw_commit_diff(struct trans *gw_trans)
273 2204c934 2020-01-15 tracey {
274 2204c934 2020-01-15 tracey const struct got_error *error = NULL;
275 2204c934 2020-01-15 tracey
276 2204c934 2020-01-15 tracey return error;
277 2204c934 2020-01-15 tracey }
278 2204c934 2020-01-15 tracey
279 2204c934 2020-01-15 tracey static const struct got_error *
280 2c251c14 2020-01-15 tracey gw_history(struct trans *gw_trans)
281 2c251c14 2020-01-15 tracey {
282 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
283 2c251c14 2020-01-15 tracey
284 2c251c14 2020-01-15 tracey return error;
285 2c251c14 2020-01-15 tracey }
286 2c251c14 2020-01-15 tracey
287 2c251c14 2020-01-15 tracey static const struct got_error *
288 2c251c14 2020-01-15 tracey gw_index(struct trans *gw_trans)
289 2c251c14 2020-01-15 tracey {
290 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
291 46b9c89b 2020-01-15 tracey struct gw_dir *gw_dir = NULL;
292 2c251c14 2020-01-15 tracey char *html, *navs, *next, *prev;
293 387a29ba 2020-01-15 tracey unsigned int prev_disp = 0, next_disp = 1, dir_c = 0;
294 2c251c14 2020-01-15 tracey
295 46b9c89b 2020-01-15 tracey error = apply_unveil(gw_trans->gw_conf->got_repos_path, NULL);
296 46b9c89b 2020-01-15 tracey if (error)
297 46b9c89b 2020-01-15 tracey return error;
298 46b9c89b 2020-01-15 tracey
299 2c251c14 2020-01-15 tracey error = gw_load_got_paths(gw_trans);
300 46b9c89b 2020-01-15 tracey if (error)
301 2c251c14 2020-01-15 tracey return error;
302 2c251c14 2020-01-15 tracey
303 2c251c14 2020-01-15 tracey khttp_puts(gw_trans->gw_req, index_projects_header);
304 2c251c14 2020-01-15 tracey
305 46b9c89b 2020-01-15 tracey TAILQ_FOREACH(gw_dir, &gw_trans->gw_dirs, entry)
306 2c251c14 2020-01-15 tracey dir_c++;
307 2c251c14 2020-01-15 tracey
308 46b9c89b 2020-01-15 tracey TAILQ_FOREACH(gw_dir, &gw_trans->gw_dirs, entry) {
309 2c251c14 2020-01-15 tracey if (gw_trans->page > 0 && (gw_trans->page *
310 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_max_repos_display) > prev_disp) {
311 2c251c14 2020-01-15 tracey prev_disp++;
312 2c251c14 2020-01-15 tracey continue;
313 2c251c14 2020-01-15 tracey }
314 2c251c14 2020-01-15 tracey
315 2c251c14 2020-01-15 tracey prev_disp++;
316 46b9c89b 2020-01-15 tracey if((asprintf(&navs, index_navs, gw_dir->name, gw_dir->name,
317 46b9c89b 2020-01-15 tracey gw_dir->name, gw_dir->name)) == -1)
318 2c251c14 2020-01-15 tracey return got_error_from_errno("asprintf");
319 2c251c14 2020-01-15 tracey
320 46b9c89b 2020-01-15 tracey if ((asprintf(&html, index_projects, gw_dir->name, gw_dir->name,
321 46b9c89b 2020-01-15 tracey gw_dir->description, gw_dir->owner, gw_dir->age,
322 46b9c89b 2020-01-15 tracey navs)) == -1)
323 2c251c14 2020-01-15 tracey return got_error_from_errno("asprintf");
324 2c251c14 2020-01-15 tracey
325 2c251c14 2020-01-15 tracey khttp_puts(gw_trans->gw_req, html);
326 2c251c14 2020-01-15 tracey
327 2c251c14 2020-01-15 tracey free(navs);
328 2c251c14 2020-01-15 tracey free(html);
329 2c251c14 2020-01-15 tracey
330 2c251c14 2020-01-15 tracey if (gw_trans->gw_conf->got_max_repos_display == 0)
331 2c251c14 2020-01-15 tracey continue;
332 2c251c14 2020-01-15 tracey
333 2c251c14 2020-01-15 tracey if (next_disp == gw_trans->gw_conf->got_max_repos_display)
334 2c251c14 2020-01-15 tracey khttp_puts(gw_trans->gw_req, np_wrapper_start);
335 2c251c14 2020-01-15 tracey else if ((gw_trans->gw_conf->got_max_repos_display > 0) &&
336 2c251c14 2020-01-15 tracey (gw_trans->page > 0) &&
337 2c251c14 2020-01-15 tracey (next_disp == gw_trans->gw_conf->got_max_repos_display ||
338 2c251c14 2020-01-15 tracey prev_disp == gw_trans->repos_total))
339 2c251c14 2020-01-15 tracey khttp_puts(gw_trans->gw_req, np_wrapper_start);
340 2c251c14 2020-01-15 tracey
341 2c251c14 2020-01-15 tracey if ((gw_trans->gw_conf->got_max_repos_display > 0) &&
342 2c251c14 2020-01-15 tracey (gw_trans->page > 0) &&
343 2c251c14 2020-01-15 tracey (next_disp == gw_trans->gw_conf->got_max_repos_display ||
344 2c251c14 2020-01-15 tracey prev_disp == gw_trans->repos_total)) {
345 2c251c14 2020-01-15 tracey if ((asprintf(&prev, nav_prev,
346 2c251c14 2020-01-15 tracey gw_trans->page - 1)) == -1)
347 2c251c14 2020-01-15 tracey return got_error_from_errno("asprintf");
348 2c251c14 2020-01-15 tracey khttp_puts(gw_trans->gw_req, prev);
349 2c251c14 2020-01-15 tracey free(prev);
350 2c251c14 2020-01-15 tracey }
351 2c251c14 2020-01-15 tracey
352 2c251c14 2020-01-15 tracey khttp_puts(gw_trans->gw_req, div_end);
353 2c251c14 2020-01-15 tracey
354 2c251c14 2020-01-15 tracey if (gw_trans->gw_conf->got_max_repos_display > 0 &&
355 2c251c14 2020-01-15 tracey next_disp == gw_trans->gw_conf->got_max_repos_display &&
356 2c251c14 2020-01-15 tracey dir_c != (gw_trans->page + 1) *
357 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_max_repos_display) {
358 2c251c14 2020-01-15 tracey if ((asprintf(&next, nav_next,
359 2c251c14 2020-01-15 tracey gw_trans->page + 1)) == -1)
360 2c251c14 2020-01-15 tracey return got_error_from_errno("calloc");
361 2c251c14 2020-01-15 tracey khttp_puts(gw_trans->gw_req, next);
362 2c251c14 2020-01-15 tracey khttp_puts(gw_trans->gw_req, div_end);
363 2c251c14 2020-01-15 tracey free(next);
364 2c251c14 2020-01-15 tracey next_disp = 0;
365 2c251c14 2020-01-15 tracey break;
366 2c251c14 2020-01-15 tracey }
367 2c251c14 2020-01-15 tracey
368 2c251c14 2020-01-15 tracey if ((gw_trans->gw_conf->got_max_repos_display > 0) &&
369 2c251c14 2020-01-15 tracey (gw_trans->page > 0) &&
370 2c251c14 2020-01-15 tracey (next_disp == gw_trans->gw_conf->got_max_repos_display ||
371 2c251c14 2020-01-15 tracey prev_disp == gw_trans->repos_total))
372 2c251c14 2020-01-15 tracey khttp_puts(gw_trans->gw_req, div_end);
373 2c251c14 2020-01-15 tracey
374 2c251c14 2020-01-15 tracey next_disp++;
375 2c251c14 2020-01-15 tracey }
376 2c251c14 2020-01-15 tracey return error;
377 2c251c14 2020-01-15 tracey }
378 2c251c14 2020-01-15 tracey
379 2c251c14 2020-01-15 tracey static const struct got_error *
380 2c251c14 2020-01-15 tracey gw_log(struct trans *gw_trans)
381 2c251c14 2020-01-15 tracey {
382 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
383 2c251c14 2020-01-15 tracey
384 2c251c14 2020-01-15 tracey return error;
385 2c251c14 2020-01-15 tracey }
386 2c251c14 2020-01-15 tracey
387 2c251c14 2020-01-15 tracey static const struct got_error *
388 2c251c14 2020-01-15 tracey gw_raw(struct trans *gw_trans)
389 2c251c14 2020-01-15 tracey {
390 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
391 2c251c14 2020-01-15 tracey
392 2c251c14 2020-01-15 tracey return error;
393 2c251c14 2020-01-15 tracey }
394 2c251c14 2020-01-15 tracey
395 2c251c14 2020-01-15 tracey static const struct got_error *
396 2c251c14 2020-01-15 tracey gw_shortlog(struct trans *gw_trans)
397 2c251c14 2020-01-15 tracey {
398 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
399 17a96b9f 2020-01-15 tracey
400 2c251c14 2020-01-15 tracey return error;
401 2c251c14 2020-01-15 tracey }
402 2c251c14 2020-01-15 tracey
403 2c251c14 2020-01-15 tracey static const struct got_error *
404 2c251c14 2020-01-15 tracey gw_snapshot(struct trans *gw_trans)
405 2c251c14 2020-01-15 tracey {
406 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
407 2c251c14 2020-01-15 tracey
408 2c251c14 2020-01-15 tracey return error;
409 2c251c14 2020-01-15 tracey }
410 2c251c14 2020-01-15 tracey
411 2c251c14 2020-01-15 tracey static const struct got_error *
412 387a29ba 2020-01-15 tracey gw_summary(struct trans *gw_trans)
413 387a29ba 2020-01-15 tracey {
414 387a29ba 2020-01-15 tracey const struct got_error *error = NULL;
415 46b9c89b 2020-01-15 tracey char *description_html, *repo_owner_html, *repo_age_html,
416 8d4d2453 2020-01-15 tracey *cloneurl_html, *shortlog, *tags, *heads, *shortlog_html,
417 c6b62706 2020-01-15 tracey *tags_html, *heads_html, *age;
418 387a29ba 2020-01-15 tracey
419 46b9c89b 2020-01-15 tracey error = apply_unveil(gw_trans->gw_dir->path, NULL);
420 46b9c89b 2020-01-15 tracey if (error)
421 46b9c89b 2020-01-15 tracey return error;
422 46b9c89b 2020-01-15 tracey
423 46b9c89b 2020-01-15 tracey khttp_puts(gw_trans->gw_req, summary_wrapper);
424 46b9c89b 2020-01-15 tracey if (gw_trans->gw_conf->got_show_repo_description) {
425 46b9c89b 2020-01-15 tracey if (gw_trans->gw_dir->description != NULL &&
426 46b9c89b 2020-01-15 tracey (strcmp(gw_trans->gw_dir->description, "") != 0)) {
427 46b9c89b 2020-01-15 tracey if ((asprintf(&description_html, description,
428 46b9c89b 2020-01-15 tracey gw_trans->gw_dir->description)) == -1)
429 46b9c89b 2020-01-15 tracey return got_error_from_errno("asprintf");
430 46b9c89b 2020-01-15 tracey
431 46b9c89b 2020-01-15 tracey khttp_puts(gw_trans->gw_req, description_html);
432 46b9c89b 2020-01-15 tracey free(description_html);
433 46b9c89b 2020-01-15 tracey }
434 46b9c89b 2020-01-15 tracey }
435 46b9c89b 2020-01-15 tracey
436 46b9c89b 2020-01-15 tracey if (gw_trans->gw_conf->got_show_repo_owner) {
437 46b9c89b 2020-01-15 tracey if (gw_trans->gw_dir->owner != NULL &&
438 46b9c89b 2020-01-15 tracey (strcmp(gw_trans->gw_dir->owner, "") != 0)) {
439 46b9c89b 2020-01-15 tracey if ((asprintf(&repo_owner_html, repo_owner,
440 46b9c89b 2020-01-15 tracey gw_trans->gw_dir->owner)) == -1)
441 46b9c89b 2020-01-15 tracey return got_error_from_errno("asprintf");
442 46b9c89b 2020-01-15 tracey
443 46b9c89b 2020-01-15 tracey khttp_puts(gw_trans->gw_req, repo_owner_html);
444 46b9c89b 2020-01-15 tracey free(repo_owner_html);
445 46b9c89b 2020-01-15 tracey }
446 46b9c89b 2020-01-15 tracey }
447 46b9c89b 2020-01-15 tracey
448 46b9c89b 2020-01-15 tracey if (gw_trans->gw_conf->got_show_repo_age) {
449 c6b62706 2020-01-15 tracey age = gw_get_repo_age(gw_trans, gw_trans->gw_dir->path,
450 c6b62706 2020-01-15 tracey "refs/heads", TM_LONG);
451 c6b62706 2020-01-15 tracey if (age != NULL && (strcmp(age, "") != 0)) {
452 c6b62706 2020-01-15 tracey if ((asprintf(&repo_age_html, last_change, age)) == -1)
453 46b9c89b 2020-01-15 tracey return got_error_from_errno("asprintf");
454 46b9c89b 2020-01-15 tracey
455 46b9c89b 2020-01-15 tracey khttp_puts(gw_trans->gw_req, repo_age_html);
456 46b9c89b 2020-01-15 tracey free(repo_age_html);
457 c6b62706 2020-01-15 tracey free(age);
458 46b9c89b 2020-01-15 tracey }
459 46b9c89b 2020-01-15 tracey }
460 46b9c89b 2020-01-15 tracey
461 46b9c89b 2020-01-15 tracey if (gw_trans->gw_conf->got_show_repo_cloneurl) {
462 46b9c89b 2020-01-15 tracey if (gw_trans->gw_dir->url != NULL &&
463 46b9c89b 2020-01-15 tracey (strcmp(gw_trans->gw_dir->url, "") != 0)) {
464 46b9c89b 2020-01-15 tracey if ((asprintf(&cloneurl_html, cloneurl,
465 46b9c89b 2020-01-15 tracey gw_trans->gw_dir->url)) == -1)
466 46b9c89b 2020-01-15 tracey return got_error_from_errno("asprintf");
467 46b9c89b 2020-01-15 tracey
468 46b9c89b 2020-01-15 tracey khttp_puts(gw_trans->gw_req, cloneurl_html);
469 46b9c89b 2020-01-15 tracey free(cloneurl_html);
470 46b9c89b 2020-01-15 tracey }
471 46b9c89b 2020-01-15 tracey }
472 46b9c89b 2020-01-15 tracey khttp_puts(gw_trans->gw_req, div_end);
473 46b9c89b 2020-01-15 tracey
474 8d4d2453 2020-01-15 tracey shortlog = gw_get_repo_shortlog(gw_trans);
475 8d4d2453 2020-01-15 tracey tags = gw_get_repo_tags(gw_trans);
476 8d4d2453 2020-01-15 tracey heads = gw_get_repo_heads(gw_trans);
477 387a29ba 2020-01-15 tracey
478 8d4d2453 2020-01-15 tracey if (shortlog != NULL && strcmp(shortlog, "") != 0) {
479 8d4d2453 2020-01-15 tracey if ((asprintf(&shortlog_html, summary_shortlog,
480 8d4d2453 2020-01-15 tracey shortlog)) == -1)
481 8d4d2453 2020-01-15 tracey return got_error_from_errno("asprintf");
482 8d4d2453 2020-01-15 tracey khttp_puts(gw_trans->gw_req, shortlog_html);
483 8d4d2453 2020-01-15 tracey free(shortlog_html);
484 8d4d2453 2020-01-15 tracey free(shortlog);
485 8d4d2453 2020-01-15 tracey }
486 8d4d2453 2020-01-15 tracey
487 8d4d2453 2020-01-15 tracey if (tags != NULL && strcmp(tags, "") != 0) {
488 8d4d2453 2020-01-15 tracey if ((asprintf(&tags_html, summary_tags,
489 8d4d2453 2020-01-15 tracey tags)) == -1)
490 8d4d2453 2020-01-15 tracey return got_error_from_errno("asprintf");
491 8d4d2453 2020-01-15 tracey khttp_puts(gw_trans->gw_req, tags_html);
492 8d4d2453 2020-01-15 tracey free(tags_html);
493 8d4d2453 2020-01-15 tracey free(tags);
494 8d4d2453 2020-01-15 tracey }
495 8d4d2453 2020-01-15 tracey
496 8d4d2453 2020-01-15 tracey if (heads != NULL && strcmp(heads, "") != 0) {
497 8d4d2453 2020-01-15 tracey if ((asprintf(&heads_html, summary_heads,
498 8d4d2453 2020-01-15 tracey heads)) == -1)
499 8d4d2453 2020-01-15 tracey return got_error_from_errno("asprintf");
500 8d4d2453 2020-01-15 tracey khttp_puts(gw_trans->gw_req, heads_html);
501 8d4d2453 2020-01-15 tracey free(heads_html);
502 8d4d2453 2020-01-15 tracey free(heads);
503 8d4d2453 2020-01-15 tracey }
504 2204c934 2020-01-15 tracey
505 2204c934 2020-01-15 tracey return error;
506 2204c934 2020-01-15 tracey }
507 2204c934 2020-01-15 tracey
508 2204c934 2020-01-15 tracey static const struct got_error *
509 2c251c14 2020-01-15 tracey gw_tree(struct trans *gw_trans)
510 2c251c14 2020-01-15 tracey {
511 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
512 2c251c14 2020-01-15 tracey
513 2c251c14 2020-01-15 tracey return error;
514 2c251c14 2020-01-15 tracey }
515 2c251c14 2020-01-15 tracey
516 2c251c14 2020-01-15 tracey static const struct got_error *
517 2c251c14 2020-01-15 tracey gw_load_got_path(struct trans *gw_trans, struct gw_dir *gw_dir)
518 2c251c14 2020-01-15 tracey {
519 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
520 2c251c14 2020-01-15 tracey DIR *dt;
521 2c251c14 2020-01-15 tracey char *dir_test;
522 2c251c14 2020-01-15 tracey bool opened = false;
523 2c251c14 2020-01-15 tracey
524 2c251c14 2020-01-15 tracey if ((asprintf(&dir_test, "%s/%s/%s",
525 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_repos_path, gw_dir->name,
526 2c251c14 2020-01-15 tracey GOTWEB_GIT_DIR)) == -1)
527 2c251c14 2020-01-15 tracey return got_error_from_errno("asprintf");
528 2c251c14 2020-01-15 tracey
529 2c251c14 2020-01-15 tracey dt = opendir(dir_test);
530 2c251c14 2020-01-15 tracey if (dt == NULL) {
531 2c251c14 2020-01-15 tracey free(dir_test);
532 2c251c14 2020-01-15 tracey } else {
533 2c251c14 2020-01-15 tracey gw_dir->path = strdup(dir_test);
534 2c251c14 2020-01-15 tracey opened = true;
535 2c251c14 2020-01-15 tracey goto done;
536 2c251c14 2020-01-15 tracey }
537 2c251c14 2020-01-15 tracey
538 2c251c14 2020-01-15 tracey if ((asprintf(&dir_test, "%s/%s/%s",
539 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_repos_path, gw_dir->name,
540 2c251c14 2020-01-15 tracey GOTWEB_GOT_DIR)) == -1)
541 2c251c14 2020-01-15 tracey return got_error_from_errno("asprintf");
542 2c251c14 2020-01-15 tracey
543 2c251c14 2020-01-15 tracey dt = opendir(dir_test);
544 2c251c14 2020-01-15 tracey if (dt == NULL)
545 2c251c14 2020-01-15 tracey free(dir_test);
546 2c251c14 2020-01-15 tracey else {
547 2c251c14 2020-01-15 tracey opened = true;
548 2c251c14 2020-01-15 tracey error = got_error(GOT_ERR_NOT_GIT_REPO);
549 2c251c14 2020-01-15 tracey goto errored;
550 2c251c14 2020-01-15 tracey }
551 2c251c14 2020-01-15 tracey
552 2c251c14 2020-01-15 tracey if ((asprintf(&dir_test, "%s/%s",
553 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_repos_path, gw_dir->name)) == -1)
554 2c251c14 2020-01-15 tracey return got_error_from_errno("asprintf");
555 2c251c14 2020-01-15 tracey
556 2c251c14 2020-01-15 tracey gw_dir->path = strdup(dir_test);
557 2c251c14 2020-01-15 tracey
558 2c251c14 2020-01-15 tracey done:
559 2c251c14 2020-01-15 tracey gw_dir->description = gw_get_repo_description(gw_trans,
560 2c251c14 2020-01-15 tracey gw_dir->path);
561 2c251c14 2020-01-15 tracey gw_dir->owner = gw_get_repo_owner(gw_trans, gw_dir->path);
562 387a29ba 2020-01-15 tracey gw_dir->age = gw_get_repo_age(gw_trans, gw_dir->path, "refs/heads",
563 387a29ba 2020-01-15 tracey TM_DIFF);
564 2c251c14 2020-01-15 tracey gw_dir->url = gw_get_clone_url(gw_trans, gw_dir->path);
565 2c251c14 2020-01-15 tracey
566 2c251c14 2020-01-15 tracey errored:
567 2c251c14 2020-01-15 tracey free(dir_test);
568 2c251c14 2020-01-15 tracey if (opened)
569 2c251c14 2020-01-15 tracey closedir(dt);
570 2c251c14 2020-01-15 tracey return error;
571 2c251c14 2020-01-15 tracey }
572 2c251c14 2020-01-15 tracey
573 2c251c14 2020-01-15 tracey static const struct got_error *
574 2c251c14 2020-01-15 tracey gw_load_got_paths(struct trans *gw_trans)
575 2c251c14 2020-01-15 tracey {
576 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
577 2c251c14 2020-01-15 tracey DIR *d;
578 2c251c14 2020-01-15 tracey struct dirent **sd_dent;
579 2c251c14 2020-01-15 tracey struct gw_dir *gw_dir;
580 2c251c14 2020-01-15 tracey struct stat st;
581 2c251c14 2020-01-15 tracey unsigned int d_cnt, d_i;
582 2c251c14 2020-01-15 tracey
583 2c251c14 2020-01-15 tracey d = opendir(gw_trans->gw_conf->got_repos_path);
584 2c251c14 2020-01-15 tracey if (d == NULL) {
585 2c251c14 2020-01-15 tracey error = got_error_from_errno2("opendir",
586 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_repos_path);
587 2c251c14 2020-01-15 tracey return error;
588 2c251c14 2020-01-15 tracey }
589 2c251c14 2020-01-15 tracey
590 2c251c14 2020-01-15 tracey d_cnt = scandir(gw_trans->gw_conf->got_repos_path, &sd_dent, NULL,
591 2c251c14 2020-01-15 tracey alphasort);
592 2c251c14 2020-01-15 tracey if (d_cnt == -1) {
593 2c251c14 2020-01-15 tracey error = got_error_from_errno2("scandir",
594 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_repos_path);
595 2c251c14 2020-01-15 tracey return error;
596 2c251c14 2020-01-15 tracey }
597 2c251c14 2020-01-15 tracey
598 2c251c14 2020-01-15 tracey for (d_i = 0; d_i < d_cnt; d_i++) {
599 2c251c14 2020-01-15 tracey if (gw_trans->gw_conf->got_max_repos > 0 &&
600 2c251c14 2020-01-15 tracey (d_i - 2) == gw_trans->gw_conf->got_max_repos)
601 2c251c14 2020-01-15 tracey break; /* account for parent and self */
602 2c251c14 2020-01-15 tracey
603 2c251c14 2020-01-15 tracey if (strcmp(sd_dent[d_i]->d_name, ".") == 0 ||
604 2c251c14 2020-01-15 tracey strcmp(sd_dent[d_i]->d_name, "..") == 0)
605 2c251c14 2020-01-15 tracey continue;
606 2c251c14 2020-01-15 tracey
607 2c251c14 2020-01-15 tracey if ((gw_dir = gw_init_gw_dir(sd_dent[d_i]->d_name)) == NULL)
608 2c251c14 2020-01-15 tracey return got_error_from_errno("gw_dir malloc");
609 2c251c14 2020-01-15 tracey
610 2c251c14 2020-01-15 tracey error = gw_load_got_path(gw_trans, gw_dir);
611 2c251c14 2020-01-15 tracey if (error && error->code == GOT_ERR_NOT_GIT_REPO)
612 2c251c14 2020-01-15 tracey continue;
613 2c251c14 2020-01-15 tracey else if (error)
614 2c251c14 2020-01-15 tracey return error;
615 2c251c14 2020-01-15 tracey
616 2c251c14 2020-01-15 tracey if (lstat(gw_dir->path, &st) == 0 && S_ISDIR(st.st_mode) &&
617 2c251c14 2020-01-15 tracey !got_path_dir_is_empty(gw_dir->path)) {
618 2c251c14 2020-01-15 tracey TAILQ_INSERT_TAIL(&gw_trans->gw_dirs, gw_dir,
619 2c251c14 2020-01-15 tracey entry);
620 2c251c14 2020-01-15 tracey gw_trans->repos_total++;
621 2c251c14 2020-01-15 tracey }
622 2c251c14 2020-01-15 tracey }
623 2c251c14 2020-01-15 tracey
624 2c251c14 2020-01-15 tracey closedir(d);
625 2c251c14 2020-01-15 tracey return error;
626 2c251c14 2020-01-15 tracey }
627 2c251c14 2020-01-15 tracey
628 2c251c14 2020-01-15 tracey static const struct got_error *
629 2c251c14 2020-01-15 tracey gw_parse_querystring(struct trans *gw_trans)
630 2c251c14 2020-01-15 tracey {
631 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
632 2c251c14 2020-01-15 tracey struct kpair *p;
633 2c251c14 2020-01-15 tracey struct gw_query_action *action = NULL;
634 2c251c14 2020-01-15 tracey unsigned int i;
635 2c251c14 2020-01-15 tracey
636 2c251c14 2020-01-15 tracey if (gw_trans->gw_req->fieldnmap[0]) {
637 2c251c14 2020-01-15 tracey error = got_error_from_errno("bad parse");
638 2c251c14 2020-01-15 tracey return error;
639 2c251c14 2020-01-15 tracey } else if ((p = gw_trans->gw_req->fieldmap[KEY_PATH])) {
640 2c251c14 2020-01-15 tracey /* define gw_trans->repo_path */
641 2c251c14 2020-01-15 tracey if ((asprintf(&gw_trans->repo_name, "%s", p->parsed.s)) == -1)
642 2c251c14 2020-01-15 tracey return got_error_from_errno("asprintf");
643 2c251c14 2020-01-15 tracey
644 2c251c14 2020-01-15 tracey if ((asprintf(&gw_trans->repo_path, "%s/%s",
645 387a29ba 2020-01-15 tracey gw_trans->gw_conf->got_repos_path, p->parsed.s)) == -1)
646 2c251c14 2020-01-15 tracey return got_error_from_errno("asprintf");
647 2c251c14 2020-01-15 tracey
648 2c251c14 2020-01-15 tracey if ((p = gw_trans->gw_req->fieldmap[KEY_COMMIT_ID]))
649 2c251c14 2020-01-15 tracey if ((asprintf(&gw_trans->commit, "%s",
650 2c251c14 2020-01-15 tracey p->parsed.s)) == -1)
651 2c251c14 2020-01-15 tracey return got_error_from_errno("asprintf");
652 2c251c14 2020-01-15 tracey
653 2c251c14 2020-01-15 tracey /* get action and set function */
654 2c251c14 2020-01-15 tracey if ((p = gw_trans->gw_req->fieldmap[KEY_ACTION]))
655 2c251c14 2020-01-15 tracey for (i = 0; i < nitems(gw_query_funcs); i++) {
656 2c251c14 2020-01-15 tracey action = &gw_query_funcs[i];
657 2c251c14 2020-01-15 tracey if (action->func_name == NULL)
658 2c251c14 2020-01-15 tracey continue;
659 2c251c14 2020-01-15 tracey
660 2c251c14 2020-01-15 tracey if (strcmp(action->func_name,
661 2c251c14 2020-01-15 tracey p->parsed.s) == 0) {
662 2c251c14 2020-01-15 tracey gw_trans->action = i;
663 2c251c14 2020-01-15 tracey if ((asprintf(&gw_trans->action_name,
664 2c251c14 2020-01-15 tracey "%s", action->func_name)) == -1)
665 2c251c14 2020-01-15 tracey return
666 2c251c14 2020-01-15 tracey got_error_from_errno(
667 2c251c14 2020-01-15 tracey "asprintf");
668 2c251c14 2020-01-15 tracey
669 2c251c14 2020-01-15 tracey break;
670 2c251c14 2020-01-15 tracey }
671 2c251c14 2020-01-15 tracey
672 2c251c14 2020-01-15 tracey action = NULL;
673 2c251c14 2020-01-15 tracey }
674 2c251c14 2020-01-15 tracey
675 2c251c14 2020-01-15 tracey if ((p = gw_trans->gw_req->fieldmap[KEY_FILE]))
676 2c251c14 2020-01-15 tracey if ((asprintf(&gw_trans->repo_file, "%s",
677 2c251c14 2020-01-15 tracey p->parsed.s)) == -1)
678 2c251c14 2020-01-15 tracey return got_error_from_errno("asprintf");
679 2c251c14 2020-01-15 tracey
680 2c251c14 2020-01-15 tracey if (action == NULL) {
681 2c251c14 2020-01-15 tracey error = got_error_from_errno("invalid action");
682 2c251c14 2020-01-15 tracey return error;
683 2c251c14 2020-01-15 tracey }
684 46b9c89b 2020-01-15 tracey if ((gw_trans->gw_dir =
685 46b9c89b 2020-01-15 tracey gw_init_gw_dir(gw_trans->repo_name)) == NULL)
686 46b9c89b 2020-01-15 tracey return got_error_from_errno("gw_dir malloc");
687 46b9c89b 2020-01-15 tracey
688 46b9c89b 2020-01-15 tracey error = gw_load_got_path(gw_trans, gw_trans->gw_dir);
689 46b9c89b 2020-01-15 tracey if (error)
690 46b9c89b 2020-01-15 tracey return error;
691 2c251c14 2020-01-15 tracey } else
692 2c251c14 2020-01-15 tracey gw_trans->action = GW_INDEX;
693 2c251c14 2020-01-15 tracey
694 2c251c14 2020-01-15 tracey if ((p = gw_trans->gw_req->fieldmap[KEY_PAGE]))
695 2c251c14 2020-01-15 tracey gw_trans->page = p->parsed.i;
696 2c251c14 2020-01-15 tracey
697 2c251c14 2020-01-15 tracey if (gw_trans->action == GW_RAW)
698 387a29ba 2020-01-15 tracey gw_trans->mime = KMIME_TEXT_PLAIN;
699 2c251c14 2020-01-15 tracey
700 2c251c14 2020-01-15 tracey return error;
701 2c251c14 2020-01-15 tracey }
702 2c251c14 2020-01-15 tracey
703 2c251c14 2020-01-15 tracey static struct gw_dir *
704 2c251c14 2020-01-15 tracey gw_init_gw_dir(char *dir)
705 2c251c14 2020-01-15 tracey {
706 2c251c14 2020-01-15 tracey struct gw_dir *gw_dir;
707 2c251c14 2020-01-15 tracey
708 2c251c14 2020-01-15 tracey if ((gw_dir = malloc(sizeof(*gw_dir))) == NULL)
709 2c251c14 2020-01-15 tracey return NULL;
710 2c251c14 2020-01-15 tracey
711 2c251c14 2020-01-15 tracey if ((asprintf(&gw_dir->name, "%s", dir)) == -1)
712 2c251c14 2020-01-15 tracey return NULL;
713 2c251c14 2020-01-15 tracey
714 2c251c14 2020-01-15 tracey return gw_dir;
715 2c251c14 2020-01-15 tracey }
716 2c251c14 2020-01-15 tracey
717 2c251c14 2020-01-15 tracey static void
718 2c251c14 2020-01-15 tracey gw_display_open(struct trans *gw_trans, enum khttp code, enum kmime mime)
719 2c251c14 2020-01-15 tracey {
720 2c251c14 2020-01-15 tracey khttp_head(gw_trans->gw_req, kresps[KRESP_ALLOW], "GET");
721 2c251c14 2020-01-15 tracey khttp_head(gw_trans->gw_req, kresps[KRESP_STATUS], "%s",
722 2c251c14 2020-01-15 tracey khttps[code]);
723 387a29ba 2020-01-15 tracey khttp_head(gw_trans->gw_req, kresps[KRESP_CONTENT_TYPE], "%s",
724 2c251c14 2020-01-15 tracey kmimetypes[mime]);
725 2c251c14 2020-01-15 tracey khttp_head(gw_trans->gw_req, "X-Content-Type-Options", "nosniff");
726 2c251c14 2020-01-15 tracey khttp_head(gw_trans->gw_req, "X-Frame-Options", "DENY");
727 2c251c14 2020-01-15 tracey khttp_head(gw_trans->gw_req, "X-XSS-Protection", "1; mode=block");
728 2c251c14 2020-01-15 tracey khttp_body(gw_trans->gw_req);
729 2c251c14 2020-01-15 tracey }
730 2c251c14 2020-01-15 tracey
731 2c251c14 2020-01-15 tracey static void
732 2c251c14 2020-01-15 tracey gw_display_index(struct trans *gw_trans, const struct got_error *err)
733 2c251c14 2020-01-15 tracey {
734 2c251c14 2020-01-15 tracey gw_display_open(gw_trans, KHTTP_200, gw_trans->mime);
735 2c251c14 2020-01-15 tracey khtml_open(gw_trans->gw_html_req, gw_trans->gw_req, 0);
736 2c251c14 2020-01-15 tracey
737 2c251c14 2020-01-15 tracey if (err)
738 2c251c14 2020-01-15 tracey khttp_puts(gw_trans->gw_req, err->msg);
739 2c251c14 2020-01-15 tracey else
740 2c251c14 2020-01-15 tracey khttp_template(gw_trans->gw_req, gw_trans->gw_tmpl,
741 2c251c14 2020-01-15 tracey gw_query_funcs[gw_trans->action].template);
742 2c251c14 2020-01-15 tracey
743 2c251c14 2020-01-15 tracey khtml_close(gw_trans->gw_html_req);
744 2c251c14 2020-01-15 tracey }
745 2c251c14 2020-01-15 tracey
746 2c251c14 2020-01-15 tracey static int
747 2c251c14 2020-01-15 tracey gw_template(size_t key, void *arg)
748 2c251c14 2020-01-15 tracey {
749 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
750 2c251c14 2020-01-15 tracey struct trans *gw_trans = arg;
751 2c251c14 2020-01-15 tracey char *gw_got_link, *gw_site_link;
752 2c251c14 2020-01-15 tracey char *site_owner_name, *site_owner_name_h;
753 2c251c14 2020-01-15 tracey
754 2c251c14 2020-01-15 tracey switch (key) {
755 2c251c14 2020-01-15 tracey case (TEMPL_HEAD):
756 2c251c14 2020-01-15 tracey khttp_puts(gw_trans->gw_req, head);
757 2c251c14 2020-01-15 tracey break;
758 2c251c14 2020-01-15 tracey case(TEMPL_HEADER):
759 2c251c14 2020-01-15 tracey gw_got_link = gw_get_got_link(gw_trans);
760 2c251c14 2020-01-15 tracey if (gw_got_link != NULL)
761 2c251c14 2020-01-15 tracey khttp_puts(gw_trans->gw_req, gw_got_link);
762 2c251c14 2020-01-15 tracey
763 2c251c14 2020-01-15 tracey free(gw_got_link);
764 2c251c14 2020-01-15 tracey break;
765 2c251c14 2020-01-15 tracey case (TEMPL_SITEPATH):
766 2c251c14 2020-01-15 tracey gw_site_link = gw_get_site_link(gw_trans);
767 2c251c14 2020-01-15 tracey if (gw_site_link != NULL)
768 2c251c14 2020-01-15 tracey khttp_puts(gw_trans->gw_req, gw_site_link);
769 2c251c14 2020-01-15 tracey
770 2c251c14 2020-01-15 tracey free(gw_site_link);
771 2c251c14 2020-01-15 tracey break;
772 2c251c14 2020-01-15 tracey case(TEMPL_TITLE):
773 2c251c14 2020-01-15 tracey if (gw_trans->gw_conf->got_site_name != NULL)
774 2c251c14 2020-01-15 tracey khtml_puts(gw_trans->gw_html_req,
775 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_site_name);
776 2c251c14 2020-01-15 tracey
777 2c251c14 2020-01-15 tracey break;
778 2c251c14 2020-01-15 tracey case (TEMPL_SEARCH):
779 2c251c14 2020-01-15 tracey khttp_puts(gw_trans->gw_req, search);
780 2c251c14 2020-01-15 tracey break;
781 2c251c14 2020-01-15 tracey case(TEMPL_SITEOWNER):
782 2c251c14 2020-01-15 tracey if (gw_trans->gw_conf->got_site_owner != NULL &&
783 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_show_site_owner) {
784 2c251c14 2020-01-15 tracey site_owner_name =
785 2c251c14 2020-01-15 tracey gw_html_escape(gw_trans->gw_conf->got_site_owner);
786 2c251c14 2020-01-15 tracey if ((asprintf(&site_owner_name_h, site_owner,
787 2c251c14 2020-01-15 tracey site_owner_name))
788 2c251c14 2020-01-15 tracey == -1)
789 2c251c14 2020-01-15 tracey return 0;
790 2c251c14 2020-01-15 tracey
791 2c251c14 2020-01-15 tracey khttp_puts(gw_trans->gw_req, site_owner_name_h);
792 2c251c14 2020-01-15 tracey free(site_owner_name);
793 2c251c14 2020-01-15 tracey free(site_owner_name_h);
794 2c251c14 2020-01-15 tracey }
795 2c251c14 2020-01-15 tracey break;
796 2c251c14 2020-01-15 tracey case(TEMPL_CONTENT):
797 2c251c14 2020-01-15 tracey error = gw_query_funcs[gw_trans->action].func_main(gw_trans);
798 2c251c14 2020-01-15 tracey if (error)
799 2c251c14 2020-01-15 tracey khttp_puts(gw_trans->gw_req, error->msg);
800 2c251c14 2020-01-15 tracey
801 2c251c14 2020-01-15 tracey break;
802 2c251c14 2020-01-15 tracey default:
803 2c251c14 2020-01-15 tracey return 0;
804 2c251c14 2020-01-15 tracey break;
805 2c251c14 2020-01-15 tracey }
806 2c251c14 2020-01-15 tracey return 1;
807 2c251c14 2020-01-15 tracey }
808 2c251c14 2020-01-15 tracey
809 2c251c14 2020-01-15 tracey static char *
810 2c251c14 2020-01-15 tracey gw_get_repo_description(struct trans *gw_trans, char *dir)
811 2c251c14 2020-01-15 tracey {
812 2c251c14 2020-01-15 tracey FILE *f;
813 2c251c14 2020-01-15 tracey char *description = NULL, *d_file = NULL;
814 2c251c14 2020-01-15 tracey unsigned int len;
815 2c251c14 2020-01-15 tracey
816 2c251c14 2020-01-15 tracey if (gw_trans->gw_conf->got_show_repo_description == false)
817 2c251c14 2020-01-15 tracey goto err;
818 2c251c14 2020-01-15 tracey
819 2c251c14 2020-01-15 tracey if ((asprintf(&d_file, "%s/description", dir)) == -1)
820 2c251c14 2020-01-15 tracey goto err;
821 2c251c14 2020-01-15 tracey
822 2c251c14 2020-01-15 tracey if ((f = fopen(d_file, "r")) == NULL)
823 2c251c14 2020-01-15 tracey goto err;
824 2c251c14 2020-01-15 tracey
825 2c251c14 2020-01-15 tracey fseek(f, 0, SEEK_END);
826 2c251c14 2020-01-15 tracey len = ftell(f) + 1;
827 2c251c14 2020-01-15 tracey fseek(f, 0, SEEK_SET);
828 2c251c14 2020-01-15 tracey if ((description = calloc(len, sizeof(char *))) == NULL)
829 2c251c14 2020-01-15 tracey goto err;
830 2c251c14 2020-01-15 tracey
831 2c251c14 2020-01-15 tracey fread(description, 1, len, f);
832 2c251c14 2020-01-15 tracey fclose(f);
833 2c251c14 2020-01-15 tracey free(d_file);
834 2c251c14 2020-01-15 tracey return description;
835 2c251c14 2020-01-15 tracey err:
836 2c251c14 2020-01-15 tracey if ((asprintf(&description, "%s", "")) == -1)
837 2c251c14 2020-01-15 tracey return NULL;
838 2c251c14 2020-01-15 tracey
839 2c251c14 2020-01-15 tracey return description;
840 2c251c14 2020-01-15 tracey }
841 2c251c14 2020-01-15 tracey
842 2c251c14 2020-01-15 tracey static char *
843 387a29ba 2020-01-15 tracey gw_get_repo_age(struct trans *gw_trans, char *dir, char *repo_ref, int ref_tm)
844 2c251c14 2020-01-15 tracey {
845 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
846 2c251c14 2020-01-15 tracey struct got_object_id *id = NULL;
847 2c251c14 2020-01-15 tracey struct got_repository *repo = NULL;
848 2c251c14 2020-01-15 tracey struct got_commit_object *commit = NULL;
849 2c251c14 2020-01-15 tracey struct got_reflist_head refs;
850 2c251c14 2020-01-15 tracey struct got_reflist_entry *re;
851 2c251c14 2020-01-15 tracey struct got_reference *head_ref;
852 387a29ba 2020-01-15 tracey struct tm tm;
853 2c251c14 2020-01-15 tracey time_t committer_time = 0, cmp_time = 0, diff_time;
854 2c251c14 2020-01-15 tracey char *repo_age = NULL, *years = "years ago", *months = "months ago";
855 2c251c14 2020-01-15 tracey char *weeks = "weeks ago", *days = "days ago", *hours = "hours ago";
856 2c251c14 2020-01-15 tracey char *minutes = "minutes ago", *seconds = "seconds ago";
857 2c251c14 2020-01-15 tracey char *now = "right now";
858 2204c934 2020-01-15 tracey char *s;
859 387a29ba 2020-01-15 tracey char datebuf[BUFFER_SIZE];
860 387a29ba 2020-01-15 tracey
861 387a29ba 2020-01-15 tracey if (repo_ref == NULL)
862 387a29ba 2020-01-15 tracey return NULL;
863 2c251c14 2020-01-15 tracey
864 2c251c14 2020-01-15 tracey SIMPLEQ_INIT(&refs);
865 2c251c14 2020-01-15 tracey if (gw_trans->gw_conf->got_show_repo_age == false) {
866 2c251c14 2020-01-15 tracey asprintf(&repo_age, "");
867 2c251c14 2020-01-15 tracey return repo_age;
868 2c251c14 2020-01-15 tracey }
869 2c251c14 2020-01-15 tracey error = got_repo_open(&repo, dir, NULL);
870 2c251c14 2020-01-15 tracey if (error != NULL)
871 2c251c14 2020-01-15 tracey goto err;
872 2c251c14 2020-01-15 tracey
873 387a29ba 2020-01-15 tracey error = got_ref_list(&refs, repo, repo_ref, got_ref_cmp_by_name,
874 2c251c14 2020-01-15 tracey NULL);
875 2c251c14 2020-01-15 tracey if (error != NULL)
876 2c251c14 2020-01-15 tracey goto err;
877 2c251c14 2020-01-15 tracey
878 2c251c14 2020-01-15 tracey const char *refname;
879 2c251c14 2020-01-15 tracey SIMPLEQ_FOREACH(re, &refs, entry) {
880 2c251c14 2020-01-15 tracey refname = got_ref_get_name(re->ref);
881 2c251c14 2020-01-15 tracey error = got_ref_open(&head_ref, repo, refname, 0);
882 2c251c14 2020-01-15 tracey if (error != NULL)
883 2c251c14 2020-01-15 tracey goto err;
884 2c251c14 2020-01-15 tracey
885 2c251c14 2020-01-15 tracey error = got_ref_resolve(&id, repo, head_ref);
886 2c251c14 2020-01-15 tracey got_ref_close(head_ref);
887 2c251c14 2020-01-15 tracey if (error != NULL)
888 2c251c14 2020-01-15 tracey goto err;
889 2c251c14 2020-01-15 tracey
890 387a29ba 2020-01-15 tracey /* here is what breaks tags, so adjust */
891 2c251c14 2020-01-15 tracey error = got_object_open_as_commit(&commit, repo, id);
892 2c251c14 2020-01-15 tracey if (error != NULL)
893 2c251c14 2020-01-15 tracey goto err;
894 2c251c14 2020-01-15 tracey
895 2c251c14 2020-01-15 tracey committer_time =
896 2c251c14 2020-01-15 tracey got_object_commit_get_committer_time(commit);
897 2c251c14 2020-01-15 tracey
898 387a29ba 2020-01-15 tracey if (cmp_time < committer_time)
899 2c251c14 2020-01-15 tracey cmp_time = committer_time;
900 2c251c14 2020-01-15 tracey }
901 2c251c14 2020-01-15 tracey
902 2c251c14 2020-01-15 tracey if (cmp_time != 0)
903 2c251c14 2020-01-15 tracey committer_time = cmp_time;
904 2c251c14 2020-01-15 tracey
905 387a29ba 2020-01-15 tracey switch (ref_tm) {
906 387a29ba 2020-01-15 tracey case TM_DIFF:
907 387a29ba 2020-01-15 tracey diff_time = time(NULL) - committer_time;
908 387a29ba 2020-01-15 tracey if (diff_time > 60 * 60 * 24 * 365 * 2) {
909 387a29ba 2020-01-15 tracey if ((asprintf(&repo_age, "%lld %s",
910 387a29ba 2020-01-15 tracey (diff_time / 60 / 60 / 24 / 365), years)) == -1)
911 387a29ba 2020-01-15 tracey return NULL;
912 387a29ba 2020-01-15 tracey } else if (diff_time > 60 * 60 * 24 * (365 / 12) * 2) {
913 387a29ba 2020-01-15 tracey if ((asprintf(&repo_age, "%lld %s",
914 387a29ba 2020-01-15 tracey (diff_time / 60 / 60 / 24 / (365 / 12)),
915 387a29ba 2020-01-15 tracey months)) == -1)
916 387a29ba 2020-01-15 tracey return NULL;
917 387a29ba 2020-01-15 tracey } else if (diff_time > 60 * 60 * 24 * 7 * 2) {
918 387a29ba 2020-01-15 tracey if ((asprintf(&repo_age, "%lld %s",
919 387a29ba 2020-01-15 tracey (diff_time / 60 / 60 / 24 / 7), weeks)) == -1)
920 387a29ba 2020-01-15 tracey return NULL;
921 387a29ba 2020-01-15 tracey } else if (diff_time > 60 * 60 * 24 * 2) {
922 387a29ba 2020-01-15 tracey if ((asprintf(&repo_age, "%lld %s",
923 387a29ba 2020-01-15 tracey (diff_time / 60 / 60 / 24), days)) == -1)
924 387a29ba 2020-01-15 tracey return NULL;
925 387a29ba 2020-01-15 tracey } else if (diff_time > 60 * 60 * 2) {
926 387a29ba 2020-01-15 tracey if ((asprintf(&repo_age, "%lld %s",
927 387a29ba 2020-01-15 tracey (diff_time / 60 / 60), hours)) == -1)
928 387a29ba 2020-01-15 tracey return NULL;
929 387a29ba 2020-01-15 tracey } else if (diff_time > 60 * 2) {
930 387a29ba 2020-01-15 tracey if ((asprintf(&repo_age, "%lld %s", (diff_time / 60),
931 387a29ba 2020-01-15 tracey minutes)) == -1)
932 387a29ba 2020-01-15 tracey return NULL;
933 387a29ba 2020-01-15 tracey } else if (diff_time > 2) {
934 387a29ba 2020-01-15 tracey if ((asprintf(&repo_age, "%lld %s", diff_time,
935 387a29ba 2020-01-15 tracey seconds)) == -1)
936 387a29ba 2020-01-15 tracey return NULL;
937 387a29ba 2020-01-15 tracey } else {
938 387a29ba 2020-01-15 tracey if ((asprintf(&repo_age, "%s", now)) == -1)
939 387a29ba 2020-01-15 tracey return NULL;
940 387a29ba 2020-01-15 tracey }
941 387a29ba 2020-01-15 tracey break;
942 387a29ba 2020-01-15 tracey case TM_LONG:
943 387a29ba 2020-01-15 tracey if (cmp_time != 0) {
944 387a29ba 2020-01-15 tracey if (gmtime_r(&committer_time, &tm) == NULL)
945 387a29ba 2020-01-15 tracey return NULL;
946 2204c934 2020-01-15 tracey
947 2204c934 2020-01-15 tracey s = asctime_r(&tm, datebuf);
948 2204c934 2020-01-15 tracey if (s == NULL)
949 387a29ba 2020-01-15 tracey return NULL;
950 387a29ba 2020-01-15 tracey
951 2204c934 2020-01-15 tracey if ((asprintf(&repo_age, "%s UTC", datebuf)) == -1)
952 387a29ba 2020-01-15 tracey return NULL;
953 387a29ba 2020-01-15 tracey } else {
954 387a29ba 2020-01-15 tracey if ((asprintf(&repo_age, "")) == -1)
955 387a29ba 2020-01-15 tracey return NULL;
956 387a29ba 2020-01-15 tracey }
957 387a29ba 2020-01-15 tracey break;
958 387a29ba 2020-01-15 tracey }
959 2c251c14 2020-01-15 tracey
960 46b9c89b 2020-01-15 tracey /* noref: */
961 2c251c14 2020-01-15 tracey got_ref_list_free(&refs);
962 2c251c14 2020-01-15 tracey free(id);
963 2c251c14 2020-01-15 tracey return repo_age;
964 2c251c14 2020-01-15 tracey err:
965 2c251c14 2020-01-15 tracey if ((asprintf(&repo_age, "%s", error->msg)) == -1)
966 2c251c14 2020-01-15 tracey return NULL;
967 2c251c14 2020-01-15 tracey
968 2c251c14 2020-01-15 tracey return repo_age;
969 2c251c14 2020-01-15 tracey }
970 2c251c14 2020-01-15 tracey
971 2c251c14 2020-01-15 tracey static char *
972 2c251c14 2020-01-15 tracey gw_get_repo_owner(struct trans *gw_trans, char *dir)
973 2c251c14 2020-01-15 tracey {
974 2c251c14 2020-01-15 tracey FILE *f;
975 2c251c14 2020-01-15 tracey char *owner = NULL, *d_file = NULL;
976 2c251c14 2020-01-15 tracey char *gotweb = "[gotweb]", *gitweb = "[gitweb]", *gw_owner = "owner";
977 2c251c14 2020-01-15 tracey char *comp, *pos, *buf;
978 2c251c14 2020-01-15 tracey unsigned int i;
979 2c251c14 2020-01-15 tracey
980 2c251c14 2020-01-15 tracey if (gw_trans->gw_conf->got_show_repo_owner == false)
981 2c251c14 2020-01-15 tracey goto err;
982 2c251c14 2020-01-15 tracey
983 2c251c14 2020-01-15 tracey if ((asprintf(&d_file, "%s/config", dir)) == -1)
984 2c251c14 2020-01-15 tracey goto err;
985 2c251c14 2020-01-15 tracey
986 2c251c14 2020-01-15 tracey if ((f = fopen(d_file, "r")) == NULL)
987 2c251c14 2020-01-15 tracey goto err;
988 2c251c14 2020-01-15 tracey
989 2c251c14 2020-01-15 tracey if ((buf = calloc(BUFFER_SIZE, sizeof(char *))) == NULL)
990 2c251c14 2020-01-15 tracey goto err;
991 2c251c14 2020-01-15 tracey
992 2c251c14 2020-01-15 tracey while ((fgets(buf, BUFFER_SIZE, f)) != NULL) {
993 2c251c14 2020-01-15 tracey if ((pos = strstr(buf, gotweb)) != NULL)
994 2c251c14 2020-01-15 tracey break;
995 2c251c14 2020-01-15 tracey
996 2c251c14 2020-01-15 tracey if ((pos = strstr(buf, gitweb)) != NULL)
997 2c251c14 2020-01-15 tracey break;
998 2c251c14 2020-01-15 tracey }
999 2c251c14 2020-01-15 tracey
1000 2c251c14 2020-01-15 tracey if (pos == NULL)
1001 2c251c14 2020-01-15 tracey goto err;
1002 2c251c14 2020-01-15 tracey
1003 2c251c14 2020-01-15 tracey do {
1004 2c251c14 2020-01-15 tracey fgets(buf, BUFFER_SIZE, f);
1005 2c251c14 2020-01-15 tracey } while ((comp = strcasestr(buf, gw_owner)) == NULL);
1006 2c251c14 2020-01-15 tracey
1007 2c251c14 2020-01-15 tracey if (comp == NULL)
1008 2c251c14 2020-01-15 tracey goto err;
1009 2c251c14 2020-01-15 tracey
1010 2c251c14 2020-01-15 tracey if (strncmp(gw_owner, comp, strlen(gw_owner)) != 0)
1011 2c251c14 2020-01-15 tracey goto err;
1012 2c251c14 2020-01-15 tracey
1013 2c251c14 2020-01-15 tracey for (i = 0; i < 2; i++) {
1014 2c251c14 2020-01-15 tracey owner = strsep(&buf, "\"");
1015 2c251c14 2020-01-15 tracey }
1016 2c251c14 2020-01-15 tracey
1017 2c251c14 2020-01-15 tracey if (owner == NULL)
1018 2c251c14 2020-01-15 tracey goto err;
1019 2c251c14 2020-01-15 tracey
1020 2c251c14 2020-01-15 tracey fclose(f);
1021 2c251c14 2020-01-15 tracey free(d_file);
1022 2c251c14 2020-01-15 tracey return owner;
1023 2c251c14 2020-01-15 tracey err:
1024 2c251c14 2020-01-15 tracey if ((asprintf(&owner, "%s", "")) == -1)
1025 2c251c14 2020-01-15 tracey return NULL;
1026 2c251c14 2020-01-15 tracey
1027 2c251c14 2020-01-15 tracey return owner;
1028 2c251c14 2020-01-15 tracey }
1029 2c251c14 2020-01-15 tracey
1030 2c251c14 2020-01-15 tracey static char *
1031 2c251c14 2020-01-15 tracey gw_get_clone_url(struct trans *gw_trans, char *dir)
1032 2c251c14 2020-01-15 tracey {
1033 2c251c14 2020-01-15 tracey FILE *f;
1034 2c251c14 2020-01-15 tracey char *url = NULL, *d_file = NULL;
1035 2c251c14 2020-01-15 tracey unsigned int len;
1036 2c251c14 2020-01-15 tracey
1037 2c251c14 2020-01-15 tracey if ((asprintf(&d_file, "%s/cloneurl", dir)) == -1)
1038 2c251c14 2020-01-15 tracey return NULL;
1039 2c251c14 2020-01-15 tracey
1040 2c251c14 2020-01-15 tracey if ((f = fopen(d_file, "r")) == NULL)
1041 2c251c14 2020-01-15 tracey return NULL;
1042 2c251c14 2020-01-15 tracey
1043 2c251c14 2020-01-15 tracey fseek(f, 0, SEEK_END);
1044 2c251c14 2020-01-15 tracey len = ftell(f) + 1;
1045 2c251c14 2020-01-15 tracey fseek(f, 0, SEEK_SET);
1046 2c251c14 2020-01-15 tracey
1047 2c251c14 2020-01-15 tracey if ((url = calloc(len, sizeof(char *))) == NULL)
1048 2c251c14 2020-01-15 tracey return NULL;
1049 2c251c14 2020-01-15 tracey
1050 2c251c14 2020-01-15 tracey fread(url, 1, len, f);
1051 2c251c14 2020-01-15 tracey fclose(f);
1052 2c251c14 2020-01-15 tracey free(d_file);
1053 2c251c14 2020-01-15 tracey return url;
1054 8d4d2453 2020-01-15 tracey }
1055 8d4d2453 2020-01-15 tracey
1056 8d4d2453 2020-01-15 tracey static char *
1057 8d4d2453 2020-01-15 tracey gw_get_repo_shortlog(struct trans *gw_trans)
1058 8d4d2453 2020-01-15 tracey {
1059 c6b62706 2020-01-15 tracey const struct got_error *error;
1060 c6b62706 2020-01-15 tracey struct got_repository *repo = NULL;
1061 c6b62706 2020-01-15 tracey struct got_reflist_head refs;
1062 c6b62706 2020-01-15 tracey struct got_commit_object *commit = NULL;
1063 c6b62706 2020-01-15 tracey struct got_object_id *id = NULL;
1064 c6b62706 2020-01-15 tracey char *start_commit = NULL, *head_ref_name = NULL;
1065 8d4d2453 2020-01-15 tracey char *shortlog = NULL;
1066 8d4d2453 2020-01-15 tracey
1067 c6b62706 2020-01-15 tracey error = got_repo_open(&repo, gw_trans->repo_path, NULL);
1068 c6b62706 2020-01-15 tracey if (error != NULL)
1069 c6b62706 2020-01-15 tracey goto done;
1070 c6b62706 2020-01-15 tracey
1071 c6b62706 2020-01-15 tracey if (start_commit == NULL) {
1072 c6b62706 2020-01-15 tracey struct got_reference *head_ref;
1073 c6b62706 2020-01-15 tracey error = got_ref_open(&head_ref, repo, GOT_REF_HEAD, 0);
1074 c6b62706 2020-01-15 tracey if (error != NULL)
1075 c6b62706 2020-01-15 tracey return NULL;
1076 c6b62706 2020-01-15 tracey error = got_ref_resolve(&id, repo, head_ref);
1077 c6b62706 2020-01-15 tracey got_ref_close(head_ref);
1078 c6b62706 2020-01-15 tracey if (error != NULL)
1079 c6b62706 2020-01-15 tracey return NULL;
1080 c6b62706 2020-01-15 tracey error = got_object_open_as_commit(&commit, repo, id);
1081 c6b62706 2020-01-15 tracey } else {
1082 c6b62706 2020-01-15 tracey struct got_reference *ref;
1083 c6b62706 2020-01-15 tracey error = got_ref_open(&ref, repo, start_commit, 0);
1084 c6b62706 2020-01-15 tracey if (error == NULL) {
1085 c6b62706 2020-01-15 tracey int obj_type;
1086 c6b62706 2020-01-15 tracey error = got_ref_resolve(&id, repo, ref);
1087 c6b62706 2020-01-15 tracey got_ref_close(ref);
1088 c6b62706 2020-01-15 tracey if (error != NULL)
1089 c6b62706 2020-01-15 tracey goto done;
1090 c6b62706 2020-01-15 tracey error = got_object_get_type(&obj_type, repo, id);
1091 c6b62706 2020-01-15 tracey if (error != NULL)
1092 c6b62706 2020-01-15 tracey goto done;
1093 c6b62706 2020-01-15 tracey if (obj_type == GOT_OBJ_TYPE_TAG) {
1094 c6b62706 2020-01-15 tracey struct got_tag_object *tag;
1095 c6b62706 2020-01-15 tracey error = got_object_open_as_tag(&tag, repo, id);
1096 c6b62706 2020-01-15 tracey if (error != NULL)
1097 c6b62706 2020-01-15 tracey goto done;
1098 c6b62706 2020-01-15 tracey if (got_object_tag_get_object_type(tag) !=
1099 c6b62706 2020-01-15 tracey GOT_OBJ_TYPE_COMMIT) {
1100 c6b62706 2020-01-15 tracey got_object_tag_close(tag);
1101 c6b62706 2020-01-15 tracey error = got_error(GOT_ERR_OBJ_TYPE);
1102 c6b62706 2020-01-15 tracey goto done;
1103 c6b62706 2020-01-15 tracey }
1104 c6b62706 2020-01-15 tracey free(id);
1105 c6b62706 2020-01-15 tracey id = got_object_id_dup(
1106 c6b62706 2020-01-15 tracey got_object_tag_get_object_id(tag));
1107 c6b62706 2020-01-15 tracey if (id == NULL)
1108 c6b62706 2020-01-15 tracey error = got_error_from_errno(
1109 c6b62706 2020-01-15 tracey "got_object_id_dup");
1110 c6b62706 2020-01-15 tracey got_object_tag_close(tag);
1111 c6b62706 2020-01-15 tracey if (error)
1112 c6b62706 2020-01-15 tracey goto done;
1113 c6b62706 2020-01-15 tracey } else if (obj_type != GOT_OBJ_TYPE_COMMIT) {
1114 c6b62706 2020-01-15 tracey error = got_error(GOT_ERR_OBJ_TYPE);
1115 c6b62706 2020-01-15 tracey goto done;
1116 c6b62706 2020-01-15 tracey }
1117 c6b62706 2020-01-15 tracey error = got_object_open_as_commit(&commit, repo, id);
1118 c6b62706 2020-01-15 tracey if (error != NULL)
1119 c6b62706 2020-01-15 tracey goto done;
1120 c6b62706 2020-01-15 tracey }
1121 c6b62706 2020-01-15 tracey if (commit == NULL) {
1122 c6b62706 2020-01-15 tracey error = got_repo_match_object_id_prefix(&id,
1123 c6b62706 2020-01-15 tracey start_commit, GOT_OBJ_TYPE_COMMIT, repo);
1124 c6b62706 2020-01-15 tracey if (error != NULL)
1125 c6b62706 2020-01-15 tracey return NULL;
1126 c6b62706 2020-01-15 tracey }
1127 c6b62706 2020-01-15 tracey }
1128 c6b62706 2020-01-15 tracey
1129 c6b62706 2020-01-15 tracey if (error != NULL)
1130 c6b62706 2020-01-15 tracey goto done;
1131 c6b62706 2020-01-15 tracey
1132 c6b62706 2020-01-15 tracey error = got_ref_list(&refs, repo, NULL, got_ref_cmp_by_name, NULL);
1133 c6b62706 2020-01-15 tracey if (error)
1134 c6b62706 2020-01-15 tracey goto done;
1135 c6b62706 2020-01-15 tracey
1136 c6b62706 2020-01-15 tracey /* int diff_context = -1, show_patch = 0; */
1137 c6b62706 2020-01-15 tracey /* error = print_commits(id, repo, path, show_patch, search_pattern, */
1138 c6b62706 2020-01-15 tracey /* diff_context, limit, first_parent_traversal, &refs); */
1139 c6b62706 2020-01-15 tracey /* error = print_commit(commit, id, repo, path, 0, */
1140 c6b62706 2020-01-15 tracey /* -1, refs); */
1141 c6b62706 2020-01-15 tracey got_object_commit_close(commit);
1142 c6b62706 2020-01-15 tracey
1143 8d4d2453 2020-01-15 tracey asprintf(&shortlog, shortlog_row, "30 min ago", "Flan Author", "this is just a fake ass place holder", shortlog_navs);
1144 8d4d2453 2020-01-15 tracey return shortlog;
1145 c6b62706 2020-01-15 tracey done:
1146 c6b62706 2020-01-15 tracey free(head_ref_name);
1147 c6b62706 2020-01-15 tracey if (repo)
1148 c6b62706 2020-01-15 tracey got_repo_close(repo);
1149 c6b62706 2020-01-15 tracey got_ref_list_free(&refs);
1150 c6b62706 2020-01-15 tracey return NULL;
1151 2c251c14 2020-01-15 tracey }
1152 2c251c14 2020-01-15 tracey
1153 2c251c14 2020-01-15 tracey static char *
1154 8d4d2453 2020-01-15 tracey gw_get_repo_tags(struct trans *gw_trans)
1155 8d4d2453 2020-01-15 tracey {
1156 8d4d2453 2020-01-15 tracey char *tags = NULL;
1157 8d4d2453 2020-01-15 tracey
1158 8d4d2453 2020-01-15 tracey asprintf(&tags, tags_row, "30 min ago", "1.0.0", "tag 1.0.0", tags_navs);
1159 8d4d2453 2020-01-15 tracey return tags;
1160 8d4d2453 2020-01-15 tracey }
1161 8d4d2453 2020-01-15 tracey
1162 8d4d2453 2020-01-15 tracey static char *
1163 8d4d2453 2020-01-15 tracey gw_get_repo_heads(struct trans *gw_trans)
1164 8d4d2453 2020-01-15 tracey {
1165 8d4d2453 2020-01-15 tracey char *heads = NULL;
1166 8d4d2453 2020-01-15 tracey
1167 8d4d2453 2020-01-15 tracey asprintf(&heads, heads_row, "30 min ago", "master", heads_navs);
1168 8d4d2453 2020-01-15 tracey return heads;
1169 8d4d2453 2020-01-15 tracey }
1170 8d4d2453 2020-01-15 tracey
1171 8d4d2453 2020-01-15 tracey static char *
1172 2c251c14 2020-01-15 tracey gw_get_got_link(struct trans *gw_trans)
1173 2c251c14 2020-01-15 tracey {
1174 2c251c14 2020-01-15 tracey char *link;
1175 2c251c14 2020-01-15 tracey
1176 2c251c14 2020-01-15 tracey if ((asprintf(&link, got_link, gw_trans->gw_conf->got_logo_url,
1177 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_logo)) == -1)
1178 2c251c14 2020-01-15 tracey return NULL;
1179 2c251c14 2020-01-15 tracey
1180 2c251c14 2020-01-15 tracey return link;
1181 2c251c14 2020-01-15 tracey }
1182 2c251c14 2020-01-15 tracey
1183 2c251c14 2020-01-15 tracey static char *
1184 2c251c14 2020-01-15 tracey gw_get_site_link(struct trans *gw_trans)
1185 2c251c14 2020-01-15 tracey {
1186 2c251c14 2020-01-15 tracey char *link, *repo = "", *action = "";
1187 2c251c14 2020-01-15 tracey
1188 2c251c14 2020-01-15 tracey if (gw_trans->repo_name != NULL)
1189 2c251c14 2020-01-15 tracey if ((asprintf(&repo, " / <a href='?path=%s&action=summary'>%s" \
1190 2c251c14 2020-01-15 tracey "</a>", gw_trans->repo_name, gw_trans->repo_name)) == -1)
1191 2c251c14 2020-01-15 tracey return NULL;
1192 2c251c14 2020-01-15 tracey
1193 2c251c14 2020-01-15 tracey if (gw_trans->action_name != NULL)
1194 2c251c14 2020-01-15 tracey if ((asprintf(&action, " / %s", gw_trans->action_name)) == -1)
1195 2c251c14 2020-01-15 tracey return NULL;
1196 2c251c14 2020-01-15 tracey
1197 2c251c14 2020-01-15 tracey if ((asprintf(&link, site_link, GOTWEB,
1198 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_site_link, repo, action)) == -1)
1199 2c251c14 2020-01-15 tracey return NULL;
1200 2c251c14 2020-01-15 tracey
1201 2c251c14 2020-01-15 tracey return link;
1202 2c251c14 2020-01-15 tracey }
1203 2c251c14 2020-01-15 tracey
1204 2c251c14 2020-01-15 tracey static char *
1205 2c251c14 2020-01-15 tracey gw_html_escape(const char *html)
1206 2c251c14 2020-01-15 tracey {
1207 2c251c14 2020-01-15 tracey char *escaped_str = NULL, *buf;
1208 2c251c14 2020-01-15 tracey char c[1];
1209 2c251c14 2020-01-15 tracey size_t sz, i;
1210 2c251c14 2020-01-15 tracey
1211 2c251c14 2020-01-15 tracey if ((buf = calloc(BUFFER_SIZE, sizeof(char *))) == NULL)
1212 2c251c14 2020-01-15 tracey return NULL;
1213 2c251c14 2020-01-15 tracey
1214 2c251c14 2020-01-15 tracey if (html == NULL)
1215 2c251c14 2020-01-15 tracey return NULL;
1216 2c251c14 2020-01-15 tracey else
1217 2c251c14 2020-01-15 tracey if ((sz = strlen(html)) == 0)
1218 2c251c14 2020-01-15 tracey return NULL;
1219 2c251c14 2020-01-15 tracey
1220 2c251c14 2020-01-15 tracey /* only work with BUFFER_SIZE */
1221 2c251c14 2020-01-15 tracey if (BUFFER_SIZE < sz)
1222 2c251c14 2020-01-15 tracey sz = BUFFER_SIZE;
1223 2c251c14 2020-01-15 tracey
1224 2c251c14 2020-01-15 tracey for (i = 0; i < sz; i++) {
1225 2c251c14 2020-01-15 tracey c[0] = html[i];
1226 2c251c14 2020-01-15 tracey switch (c[0]) {
1227 2c251c14 2020-01-15 tracey case ('>'):
1228 2c251c14 2020-01-15 tracey strcat(buf, "&gt;");
1229 2c251c14 2020-01-15 tracey break;
1230 2c251c14 2020-01-15 tracey case ('&'):
1231 2c251c14 2020-01-15 tracey strcat(buf, "&amp;");
1232 2c251c14 2020-01-15 tracey break;
1233 2c251c14 2020-01-15 tracey case ('<'):
1234 2c251c14 2020-01-15 tracey strcat(buf, "&lt;");
1235 2c251c14 2020-01-15 tracey break;
1236 2c251c14 2020-01-15 tracey case ('"'):
1237 2c251c14 2020-01-15 tracey strcat(buf, "&quot;");
1238 2c251c14 2020-01-15 tracey break;
1239 2c251c14 2020-01-15 tracey case ('\''):
1240 2c251c14 2020-01-15 tracey strcat(buf, "&apos;");
1241 2c251c14 2020-01-15 tracey break;
1242 2c251c14 2020-01-15 tracey case ('\n'):
1243 2c251c14 2020-01-15 tracey strcat(buf, "<br />");
1244 2c251c14 2020-01-15 tracey default:
1245 2c251c14 2020-01-15 tracey strcat(buf, &c[0]);
1246 2c251c14 2020-01-15 tracey break;
1247 2c251c14 2020-01-15 tracey }
1248 2c251c14 2020-01-15 tracey }
1249 2c251c14 2020-01-15 tracey asprintf(&escaped_str, "%s", buf);
1250 2c251c14 2020-01-15 tracey free(buf);
1251 2c251c14 2020-01-15 tracey return escaped_str;
1252 2c251c14 2020-01-15 tracey }
1253 2c251c14 2020-01-15 tracey
1254 2c251c14 2020-01-15 tracey int
1255 2c251c14 2020-01-15 tracey main()
1256 2c251c14 2020-01-15 tracey {
1257 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
1258 2c251c14 2020-01-15 tracey struct trans *gw_trans;
1259 2c251c14 2020-01-15 tracey struct gw_dir *dir = NULL, *tdir;
1260 2c251c14 2020-01-15 tracey const char *page = "index";
1261 2c251c14 2020-01-15 tracey bool gw_malloc = true;
1262 2c251c14 2020-01-15 tracey
1263 2c251c14 2020-01-15 tracey if ((gw_trans = malloc(sizeof(struct trans))) == NULL)
1264 2c251c14 2020-01-15 tracey errx(1, "malloc");
1265 2c251c14 2020-01-15 tracey
1266 2c251c14 2020-01-15 tracey if ((gw_trans->gw_req = malloc(sizeof(struct kreq))) == NULL)
1267 2c251c14 2020-01-15 tracey errx(1, "malloc");
1268 2c251c14 2020-01-15 tracey
1269 2c251c14 2020-01-15 tracey if ((gw_trans->gw_html_req = malloc(sizeof(struct khtmlreq))) == NULL)
1270 2c251c14 2020-01-15 tracey errx(1, "malloc");
1271 2c251c14 2020-01-15 tracey
1272 2c251c14 2020-01-15 tracey if ((gw_trans->gw_tmpl = malloc(sizeof(struct ktemplate))) == NULL)
1273 2c251c14 2020-01-15 tracey errx(1, "malloc");
1274 2c251c14 2020-01-15 tracey
1275 2c251c14 2020-01-15 tracey if (KCGI_OK != khttp_parse(gw_trans->gw_req, gw_keys, KEY__MAX,
1276 2c251c14 2020-01-15 tracey &page, 1, 0))
1277 2c251c14 2020-01-15 tracey errx(1, "khttp_parse");
1278 2c251c14 2020-01-15 tracey
1279 2c251c14 2020-01-15 tracey if ((gw_trans->gw_conf =
1280 2c251c14 2020-01-15 tracey malloc(sizeof(struct gotweb_conf))) == NULL) {
1281 2c251c14 2020-01-15 tracey gw_malloc = false;
1282 387a29ba 2020-01-15 tracey error = got_error_from_errno("malloc");
1283 2c251c14 2020-01-15 tracey goto err;
1284 2c251c14 2020-01-15 tracey }
1285 2c251c14 2020-01-15 tracey
1286 46b9c89b 2020-01-15 tracey if (pledge("stdio rpath proc exec sendfd unveil", NULL) == -1) {
1287 46b9c89b 2020-01-15 tracey error = got_error_from_errno("pledge");
1288 46b9c89b 2020-01-15 tracey goto err;
1289 46b9c89b 2020-01-15 tracey }
1290 46b9c89b 2020-01-15 tracey
1291 2c251c14 2020-01-15 tracey TAILQ_INIT(&gw_trans->gw_dirs);
1292 2c251c14 2020-01-15 tracey
1293 2c251c14 2020-01-15 tracey gw_trans->page = 0;
1294 2c251c14 2020-01-15 tracey gw_trans->repos_total = 0;
1295 2c251c14 2020-01-15 tracey gw_trans->repo_path = NULL;
1296 2c251c14 2020-01-15 tracey gw_trans->commit = NULL;
1297 2c251c14 2020-01-15 tracey gw_trans->mime = KMIME_TEXT_HTML;
1298 2c251c14 2020-01-15 tracey gw_trans->gw_tmpl->key = templs;
1299 2c251c14 2020-01-15 tracey gw_trans->gw_tmpl->keysz = TEMPL__MAX;
1300 2c251c14 2020-01-15 tracey gw_trans->gw_tmpl->arg = gw_trans;
1301 2c251c14 2020-01-15 tracey gw_trans->gw_tmpl->cb = gw_template;
1302 2c251c14 2020-01-15 tracey error = parse_conf(GOTWEB_CONF, gw_trans->gw_conf);
1303 2c251c14 2020-01-15 tracey
1304 2c251c14 2020-01-15 tracey err:
1305 2c251c14 2020-01-15 tracey if (error) {
1306 2c251c14 2020-01-15 tracey gw_trans->mime = KMIME_TEXT_PLAIN;
1307 2c251c14 2020-01-15 tracey gw_trans->action = GW_ERR;
1308 2c251c14 2020-01-15 tracey gw_display_index(gw_trans, error);
1309 2c251c14 2020-01-15 tracey goto done;
1310 2c251c14 2020-01-15 tracey }
1311 2c251c14 2020-01-15 tracey
1312 2c251c14 2020-01-15 tracey error = gw_parse_querystring(gw_trans);
1313 2c251c14 2020-01-15 tracey if (error)
1314 2c251c14 2020-01-15 tracey goto err;
1315 2c251c14 2020-01-15 tracey
1316 2c251c14 2020-01-15 tracey gw_display_index(gw_trans, error);
1317 2c251c14 2020-01-15 tracey
1318 2c251c14 2020-01-15 tracey done:
1319 2c251c14 2020-01-15 tracey if (gw_malloc) {
1320 2c251c14 2020-01-15 tracey free(gw_trans->gw_conf->got_repos_path);
1321 2c251c14 2020-01-15 tracey free(gw_trans->gw_conf->got_www_path);
1322 2c251c14 2020-01-15 tracey free(gw_trans->gw_conf->got_site_name);
1323 2c251c14 2020-01-15 tracey free(gw_trans->gw_conf->got_site_owner);
1324 2c251c14 2020-01-15 tracey free(gw_trans->gw_conf->got_site_link);
1325 2c251c14 2020-01-15 tracey free(gw_trans->gw_conf->got_logo);
1326 2c251c14 2020-01-15 tracey free(gw_trans->gw_conf->got_logo_url);
1327 2c251c14 2020-01-15 tracey free(gw_trans->gw_conf);
1328 2c251c14 2020-01-15 tracey free(gw_trans->commit);
1329 2c251c14 2020-01-15 tracey free(gw_trans->repo_path);
1330 2c251c14 2020-01-15 tracey free(gw_trans->repo_name);
1331 2c251c14 2020-01-15 tracey free(gw_trans->repo_file);
1332 2c251c14 2020-01-15 tracey free(gw_trans->action_name);
1333 2c251c14 2020-01-15 tracey
1334 2c251c14 2020-01-15 tracey TAILQ_FOREACH_SAFE(dir, &gw_trans->gw_dirs, entry, tdir) {
1335 2c251c14 2020-01-15 tracey free(dir->name);
1336 2c251c14 2020-01-15 tracey free(dir->description);
1337 2c251c14 2020-01-15 tracey free(dir->age);
1338 2c251c14 2020-01-15 tracey free(dir->url);
1339 2c251c14 2020-01-15 tracey free(dir->path);
1340 2c251c14 2020-01-15 tracey free(dir);
1341 2c251c14 2020-01-15 tracey }
1342 2c251c14 2020-01-15 tracey
1343 2c251c14 2020-01-15 tracey }
1344 2c251c14 2020-01-15 tracey
1345 2c251c14 2020-01-15 tracey khttp_free(gw_trans->gw_req);
1346 2c251c14 2020-01-15 tracey return EXIT_SUCCESS;
1347 2c251c14 2020-01-15 tracey }