Blame


1 8a35f56c 2022-07-16 thomas /*
2 8a35f56c 2022-07-16 thomas * Copyright (c) 2016, 2019, 2020-2022 Tracey Emery <tracey@traceyemery.net>
3 8a35f56c 2022-07-16 thomas * Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org>
4 8a35f56c 2022-07-16 thomas * Copyright (c) 2013 David Gwynne <dlg@openbsd.org>
5 8a35f56c 2022-07-16 thomas * Copyright (c) 2013 Florian Obser <florian@openbsd.org>
6 8a35f56c 2022-07-16 thomas *
7 8a35f56c 2022-07-16 thomas * Permission to use, copy, modify, and distribute this software for any
8 8a35f56c 2022-07-16 thomas * purpose with or without fee is hereby granted, provided that the above
9 8a35f56c 2022-07-16 thomas * copyright notice and this permission notice appear in all copies.
10 8a35f56c 2022-07-16 thomas *
11 8a35f56c 2022-07-16 thomas * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 8a35f56c 2022-07-16 thomas * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 8a35f56c 2022-07-16 thomas * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 8a35f56c 2022-07-16 thomas * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 8a35f56c 2022-07-16 thomas * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 8a35f56c 2022-07-16 thomas * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 8a35f56c 2022-07-16 thomas * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 8a35f56c 2022-07-16 thomas */
19 8a35f56c 2022-07-16 thomas
20 8a35f56c 2022-07-16 thomas #include <netinet/in.h>
21 8a35f56c 2022-07-16 thomas #include <net/if.h>
22 8a35f56c 2022-07-16 thomas #include <sys/queue.h>
23 8a35f56c 2022-07-16 thomas
24 8a35f56c 2022-07-16 thomas #include <limits.h>
25 8a35f56c 2022-07-16 thomas #include <stdio.h>
26 cb11302c 2022-12-30 thomas
27 cb11302c 2022-12-30 thomas #include "tmpl.h"
28 8a35f56c 2022-07-16 thomas
29 8a35f56c 2022-07-16 thomas #ifdef DEBUG
30 8a35f56c 2022-07-16 thomas #define dprintf(x...) do { log_debug(x); } while(0)
31 8a35f56c 2022-07-16 thomas #else
32 8a35f56c 2022-07-16 thomas #define dprintf(x...)
33 8a35f56c 2022-07-16 thomas #endif /* DEBUG */
34 8a35f56c 2022-07-16 thomas
35 8a35f56c 2022-07-16 thomas #ifndef nitems
36 8a35f56c 2022-07-16 thomas #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
37 8a35f56c 2022-07-16 thomas #endif
38 8a35f56c 2022-07-16 thomas
39 8a35f56c 2022-07-16 thomas /* GOTWEBD DEFAULTS */
40 8a35f56c 2022-07-16 thomas #define GOTWEBD_CONF "/etc/gotwebd.conf"
41 8a35f56c 2022-07-16 thomas
42 8a35f56c 2022-07-16 thomas #define GOTWEBD_USER "www"
43 8a35f56c 2022-07-16 thomas
44 3e9a56b5 2022-12-01 thomas #define GOTWEBD_MAXDESCRSZ 1024
45 3e9a56b5 2022-12-01 thomas #define GOTWEBD_MAXCLONEURLSZ 1024
46 e5539f76 2022-08-10 thomas #define GOTWEBD_CACHESIZE 1024
47 8a35f56c 2022-07-16 thomas #define GOTWEBD_MAXCLIENTS 1024
48 8a35f56c 2022-07-16 thomas #define GOTWEBD_MAXTEXT 511
49 8a35f56c 2022-07-16 thomas #define GOTWEBD_MAXNAME 64
50 8a35f56c 2022-07-16 thomas #define GOTWEBD_MAXPORT 6
51 8a35f56c 2022-07-16 thomas #define GOTWEBD_NUMPROC 3
52 55e6cffd 2022-09-01 thomas #define GOTWEBD_REPO_CACHESIZE 4
53 f1e20d01 2023-11-22 thomas #define GOTWEBD_SOCK_FILENO 3
54 8a35f56c 2022-07-16 thomas
55 f85c939f 2023-11-22 thomas #define PROC_MAX_INSTANCES 32
56 f85c939f 2023-11-22 thomas
57 8a35f56c 2022-07-16 thomas /* GOTWEB DEFAULTS */
58 8a35f56c 2022-07-16 thomas #define MAX_QUERYSTRING 2048
59 3191e256 2022-12-30 thomas #define MAX_DOCUMENT_URI 255
60 8a35f56c 2022-07-16 thomas #define MAX_SERVER_NAME 255
61 8a35f56c 2022-07-16 thomas
62 8a35f56c 2022-07-16 thomas #define GOTWEB_GIT_DIR ".git"
63 8a35f56c 2022-07-16 thomas
64 8a35f56c 2022-07-16 thomas #define D_HTTPD_CHROOT "/var/www"
65 8a35f56c 2022-07-16 thomas #define D_UNIX_SOCKET "/run/gotweb.sock"
66 8a35f56c 2022-07-16 thomas #define D_FCGI_PORT "9000"
67 8a35f56c 2022-07-16 thomas #define D_GOTPATH "/got/public"
68 8a35f56c 2022-07-16 thomas #define D_SITENAME "Gotweb"
69 8a35f56c 2022-07-16 thomas #define D_SITEOWNER "Got Owner"
70 8a35f56c 2022-07-16 thomas #define D_SITELINK "Repos"
71 8a35f56c 2022-07-16 thomas #define D_GOTLOGO "got.png"
72 8a35f56c 2022-07-16 thomas #define D_GOTURL "https://gameoftrees.org"
73 8a35f56c 2022-07-16 thomas #define D_GOTWEBCSS "gotweb.css"
74 8a35f56c 2022-07-16 thomas
75 8a35f56c 2022-07-16 thomas #define D_SHOWROWNER 1
76 8a35f56c 2022-07-16 thomas #define D_SHOWSOWNER 1
77 8a35f56c 2022-07-16 thomas #define D_SHOWAGE 1
78 8a35f56c 2022-07-16 thomas #define D_SHOWDESC 1
79 8a35f56c 2022-07-16 thomas #define D_SHOWURL 1
80 3991b2a5 2022-10-31 thomas #define D_RESPECTEXPORTOK 0
81 8a35f56c 2022-07-16 thomas #define D_MAXREPO 0
82 8a35f56c 2022-07-16 thomas #define D_MAXREPODISP 25
83 8a35f56c 2022-07-16 thomas #define D_MAXSLCOMMDISP 10
84 8a35f56c 2022-07-16 thomas #define D_MAXCOMMITDISP 25
85 8a35f56c 2022-07-16 thomas
86 8a35f56c 2022-07-16 thomas #define BUF 8192
87 8a35f56c 2022-07-16 thomas
88 8a35f56c 2022-07-16 thomas #define TIMEOUT_DEFAULT 120
89 8a35f56c 2022-07-16 thomas
90 8a35f56c 2022-07-16 thomas #define FCGI_CONTENT_SIZE 65535
91 8a35f56c 2022-07-16 thomas #define FCGI_PADDING_SIZE 255
92 8a35f56c 2022-07-16 thomas #define FCGI_RECORD_SIZE \
93 8a35f56c 2022-07-16 thomas (sizeof(struct fcgi_record_header) + FCGI_CONTENT_SIZE + FCGI_PADDING_SIZE)
94 8a35f56c 2022-07-16 thomas
95 8a35f56c 2022-07-16 thomas #define FCGI_ALIGNMENT 8
96 8a35f56c 2022-07-16 thomas #define FCGI_ALIGN(n) \
97 8a35f56c 2022-07-16 thomas (((n) + (FCGI_ALIGNMENT - 1)) & ~(FCGI_ALIGNMENT - 1))
98 8a35f56c 2022-07-16 thomas
99 8a35f56c 2022-07-16 thomas #define FD_RESERVE 5
100 8a35f56c 2022-07-16 thomas #define FD_NEEDED 6
101 8a35f56c 2022-07-16 thomas
102 8a35f56c 2022-07-16 thomas #define FCGI_BEGIN_REQUEST 1
103 8a35f56c 2022-07-16 thomas #define FCGI_ABORT_REQUEST 2
104 8a35f56c 2022-07-16 thomas #define FCGI_END_REQUEST 3
105 8a35f56c 2022-07-16 thomas #define FCGI_PARAMS 4
106 8a35f56c 2022-07-16 thomas #define FCGI_STDIN 5
107 8a35f56c 2022-07-16 thomas #define FCGI_STDOUT 6
108 8a35f56c 2022-07-16 thomas #define FCGI_STDERR 7
109 8a35f56c 2022-07-16 thomas #define FCGI_DATA 8
110 8a35f56c 2022-07-16 thomas #define FCGI_GET_VALUES 9
111 8a35f56c 2022-07-16 thomas #define FCGI_GET_VALUES_RESULT 10
112 8a35f56c 2022-07-16 thomas #define FCGI_UNKNOWN_TYPE 11
113 8a35f56c 2022-07-16 thomas #define FCGI_MAXTYPE (FCGI_UNKNOWN_TYPE)
114 8a35f56c 2022-07-16 thomas
115 8a35f56c 2022-07-16 thomas #define FCGI_REQUEST_COMPLETE 0
116 8a35f56c 2022-07-16 thomas #define FCGI_CANT_MPX_CONN 1
117 8a35f56c 2022-07-16 thomas #define FCGI_OVERLOADED 2
118 8a35f56c 2022-07-16 thomas #define FCGI_UNKNOWN_ROLE 3
119 8a35f56c 2022-07-16 thomas
120 61f9965e 2023-05-25 thomas #define GOTWEB_PACK_NUM_TEMPFILES (32 * 2)
121 8a35f56c 2022-07-16 thomas
122 b82440e1 2023-01-06 thomas /* Forward declaration */
123 b82440e1 2023-01-06 thomas struct got_blob_object;
124 3c14c1f2 2023-01-06 thomas struct got_tree_entry;
125 00abe30b 2023-01-14 thomas struct got_reflist_head;
126 b82440e1 2023-01-06 thomas
127 8a35f56c 2022-07-16 thomas enum imsg_type {
128 f85c939f 2023-11-22 thomas IMSG_CFG_SRV,
129 8a35f56c 2022-07-16 thomas IMSG_CFG_SOCK,
130 8a35f56c 2022-07-16 thomas IMSG_CFG_FD,
131 8a35f56c 2022-07-16 thomas IMSG_CFG_DONE,
132 8a35f56c 2022-07-16 thomas IMSG_CTL_START,
133 8a35f56c 2022-07-16 thomas };
134 8a35f56c 2022-07-16 thomas
135 f85c939f 2023-11-22 thomas struct imsgev {
136 f85c939f 2023-11-22 thomas struct imsgbuf ibuf;
137 f85c939f 2023-11-22 thomas void (*handler)(int, short, void *);
138 f85c939f 2023-11-22 thomas struct event ev;
139 f85c939f 2023-11-22 thomas void *data;
140 f85c939f 2023-11-22 thomas short events;
141 f85c939f 2023-11-22 thomas };
142 f85c939f 2023-11-22 thomas
143 f85c939f 2023-11-22 thomas #define IMSG_SIZE_CHECK(imsg, p) do { \
144 f85c939f 2023-11-22 thomas if (IMSG_DATA_SIZE(imsg) < sizeof(*p)) \
145 f85c939f 2023-11-22 thomas fatalx("bad length imsg received (%s)", #p); \
146 f85c939f 2023-11-22 thomas } while (0)
147 f85c939f 2023-11-22 thomas
148 f85c939f 2023-11-22 thomas #define IMSG_DATA_SIZE(imsg) ((imsg)->hdr.len - IMSG_HEADER_SIZE)
149 f85c939f 2023-11-22 thomas
150 8a35f56c 2022-07-16 thomas struct env_val {
151 8a35f56c 2022-07-16 thomas SLIST_ENTRY(env_val) entry;
152 8a35f56c 2022-07-16 thomas char *val;
153 8a35f56c 2022-07-16 thomas };
154 8a35f56c 2022-07-16 thomas SLIST_HEAD(env_head, env_val);
155 8a35f56c 2022-07-16 thomas
156 8a35f56c 2022-07-16 thomas struct fcgi_record_header {
157 8a35f56c 2022-07-16 thomas uint8_t version;
158 8a35f56c 2022-07-16 thomas uint8_t type;
159 8a35f56c 2022-07-16 thomas uint16_t id;
160 8a35f56c 2022-07-16 thomas uint16_t content_len;
161 8a35f56c 2022-07-16 thomas uint8_t padding_len;
162 8a35f56c 2022-07-16 thomas uint8_t reserved;
163 0740b40a 2022-07-16 thomas }__attribute__((__packed__));
164 1cd5d437 2023-01-15 thomas
165 1cd5d437 2023-01-15 thomas struct blame_line {
166 1cd5d437 2023-01-15 thomas int annotated;
167 1cd5d437 2023-01-15 thomas char *id_str;
168 1cd5d437 2023-01-15 thomas char *committer;
169 1cd5d437 2023-01-15 thomas char datebuf[11]; /* YYYY-MM-DD + NUL */
170 1cd5d437 2023-01-15 thomas };
171 8a35f56c 2022-07-16 thomas
172 8a35f56c 2022-07-16 thomas struct repo_dir {
173 8a35f56c 2022-07-16 thomas char *name;
174 8a35f56c 2022-07-16 thomas char *owner;
175 8a35f56c 2022-07-16 thomas char *description;
176 8a35f56c 2022-07-16 thomas char *url;
177 53bf32b8 2023-01-23 thomas time_t age;
178 8a35f56c 2022-07-16 thomas char *path;
179 8a35f56c 2022-07-16 thomas };
180 8a35f56c 2022-07-16 thomas
181 8a35f56c 2022-07-16 thomas struct repo_tag {
182 8a35f56c 2022-07-16 thomas TAILQ_ENTRY(repo_tag) entry;
183 8a35f56c 2022-07-16 thomas char *commit_id;
184 8a35f56c 2022-07-16 thomas char *tag_name;
185 8a35f56c 2022-07-16 thomas char *tag_commit;
186 8a35f56c 2022-07-16 thomas char *commit_msg;
187 8a35f56c 2022-07-16 thomas char *tagger;
188 8a35f56c 2022-07-16 thomas time_t tagger_time;
189 8a35f56c 2022-07-16 thomas };
190 8a35f56c 2022-07-16 thomas
191 8a35f56c 2022-07-16 thomas struct repo_commit {
192 8a35f56c 2022-07-16 thomas TAILQ_ENTRY(repo_commit) entry;
193 8a35f56c 2022-07-16 thomas char *path;
194 8a35f56c 2022-07-16 thomas char *refs_str;
195 8a35f56c 2022-07-16 thomas char *commit_id; /* id_str1 */
196 8a35f56c 2022-07-16 thomas char *parent_id; /* id_str2 */
197 8a35f56c 2022-07-16 thomas char *tree_id;
198 8a35f56c 2022-07-16 thomas char *author;
199 8a35f56c 2022-07-16 thomas char *committer;
200 8a35f56c 2022-07-16 thomas char *commit_msg;
201 8a35f56c 2022-07-16 thomas time_t committer_time;
202 8a35f56c 2022-07-16 thomas };
203 8a35f56c 2022-07-16 thomas
204 8a35f56c 2022-07-16 thomas struct got_repository;
205 8a35f56c 2022-07-16 thomas struct transport {
206 8a35f56c 2022-07-16 thomas TAILQ_HEAD(repo_commits_head, repo_commit) repo_commits;
207 8a35f56c 2022-07-16 thomas TAILQ_HEAD(repo_tags_head, repo_tag) repo_tags;
208 161663e7 2023-03-11 thomas struct got_reflist_head refs;
209 8a35f56c 2022-07-16 thomas struct got_repository *repo;
210 8a35f56c 2022-07-16 thomas struct repo_dir *repo_dir;
211 8a35f56c 2022-07-16 thomas struct querystring *qs;
212 20bab626 2023-02-03 thomas char *more_id;
213 8a35f56c 2022-07-16 thomas char *next_id;
214 8a35f56c 2022-07-16 thomas char *prev_id;
215 8a35f56c 2022-07-16 thomas unsigned int repos_total;
216 8a35f56c 2022-07-16 thomas unsigned int next_disp;
217 8a35f56c 2022-07-16 thomas unsigned int prev_disp;
218 8a35f56c 2022-07-16 thomas unsigned int tag_count;
219 164b5ddc 2023-03-11 thomas const struct got_error *error;
220 161663e7 2023-03-11 thomas struct got_blob_object *blob;
221 161663e7 2023-03-11 thomas int fd;
222 161663e7 2023-03-11 thomas FILE *fp;
223 161663e7 2023-03-11 thomas struct dirent **repos;
224 161663e7 2023-03-11 thomas int nrepos;
225 8a35f56c 2022-07-16 thomas };
226 8a35f56c 2022-07-16 thomas
227 8a35f56c 2022-07-16 thomas enum socket_priv_fds {
228 8a35f56c 2022-07-16 thomas DIFF_FD_1,
229 8a35f56c 2022-07-16 thomas DIFF_FD_2,
230 8a35f56c 2022-07-16 thomas DIFF_FD_3,
231 8a35f56c 2022-07-16 thomas DIFF_FD_4,
232 8a35f56c 2022-07-16 thomas DIFF_FD_5,
233 8a35f56c 2022-07-16 thomas BLAME_FD_1,
234 8a35f56c 2022-07-16 thomas BLAME_FD_2,
235 8a35f56c 2022-07-16 thomas BLAME_FD_3,
236 8a35f56c 2022-07-16 thomas BLAME_FD_4,
237 8a35f56c 2022-07-16 thomas BLAME_FD_5,
238 8a35f56c 2022-07-16 thomas BLAME_FD_6,
239 8a35f56c 2022-07-16 thomas BLOB_FD_1,
240 8a35f56c 2022-07-16 thomas BLOB_FD_2,
241 8a35f56c 2022-07-16 thomas PRIV_FDS__MAX,
242 8a35f56c 2022-07-16 thomas };
243 8a35f56c 2022-07-16 thomas
244 e7e5fa49 2022-12-30 thomas struct template;
245 8a35f56c 2022-07-16 thomas struct request {
246 8a35f56c 2022-07-16 thomas struct socket *sock;
247 8a35f56c 2022-07-16 thomas struct server *srv;
248 8a35f56c 2022-07-16 thomas struct transport *t;
249 e7e5fa49 2022-12-30 thomas struct template *tp;
250 8a35f56c 2022-07-16 thomas struct event ev;
251 8a35f56c 2022-07-16 thomas struct event tmo;
252 8a35f56c 2022-07-16 thomas
253 8a35f56c 2022-07-16 thomas uint16_t id;
254 8a35f56c 2022-07-16 thomas int fd;
255 8a35f56c 2022-07-16 thomas int priv_fd[PRIV_FDS__MAX];
256 8a35f56c 2022-07-16 thomas
257 8a35f56c 2022-07-16 thomas uint8_t buf[FCGI_RECORD_SIZE];
258 8a35f56c 2022-07-16 thomas size_t buf_pos;
259 8a35f56c 2022-07-16 thomas size_t buf_len;
260 e5539f76 2022-08-10 thomas
261 e5539f76 2022-08-10 thomas uint8_t outbuf[GOTWEBD_CACHESIZE];
262 8a35f56c 2022-07-16 thomas
263 8a35f56c 2022-07-16 thomas char querystring[MAX_QUERYSTRING];
264 3191e256 2022-12-30 thomas char document_uri[MAX_DOCUMENT_URI];
265 8a35f56c 2022-07-16 thomas char server_name[MAX_SERVER_NAME];
266 d6795e9f 2022-12-30 thomas int https;
267 8a35f56c 2022-07-16 thomas
268 8a35f56c 2022-07-16 thomas uint8_t request_started;
269 8a35f56c 2022-07-16 thomas };
270 8a35f56c 2022-07-16 thomas
271 8a35f56c 2022-07-16 thomas struct fcgi_begin_request_body {
272 8a35f56c 2022-07-16 thomas uint16_t role;
273 8a35f56c 2022-07-16 thomas uint8_t flags;
274 8a35f56c 2022-07-16 thomas uint8_t reserved[5];
275 0740b40a 2022-07-16 thomas }__attribute__((__packed__));
276 8a35f56c 2022-07-16 thomas
277 8a35f56c 2022-07-16 thomas struct fcgi_end_request_body {
278 8a35f56c 2022-07-16 thomas uint32_t app_status;
279 8a35f56c 2022-07-16 thomas uint8_t protocol_status;
280 8a35f56c 2022-07-16 thomas uint8_t reserved[3];
281 755d897e 2022-08-06 thomas }__attribute__((__packed__));
282 8a35f56c 2022-07-16 thomas
283 8a35f56c 2022-07-16 thomas struct address {
284 8a35f56c 2022-07-16 thomas TAILQ_ENTRY(address) entry;
285 8a35f56c 2022-07-16 thomas struct sockaddr_storage ss;
286 2edd250d 2023-11-16 thomas socklen_t slen;
287 7d1d4b6f 2023-11-16 thomas int ai_family;
288 7d1d4b6f 2023-11-16 thomas int ai_socktype;
289 7d1d4b6f 2023-11-16 thomas int ai_protocol;
290 8a35f56c 2022-07-16 thomas in_port_t port;
291 8a35f56c 2022-07-16 thomas char ifname[IFNAMSIZ];
292 8a35f56c 2022-07-16 thomas };
293 8a35f56c 2022-07-16 thomas TAILQ_HEAD(addresslist, address);
294 8a35f56c 2022-07-16 thomas
295 55e6cffd 2022-09-01 thomas struct cached_repo {
296 55e6cffd 2022-09-01 thomas char path[PATH_MAX];
297 55e6cffd 2022-09-01 thomas struct got_repository *repo;
298 55e6cffd 2022-09-01 thomas };
299 55e6cffd 2022-09-01 thomas
300 8a35f56c 2022-07-16 thomas struct server {
301 8a35f56c 2022-07-16 thomas TAILQ_ENTRY(server) entry;
302 62f85214 2022-08-16 thomas struct addresslist al;
303 8a35f56c 2022-07-16 thomas
304 a004b24a 2022-09-06 thomas struct cached_repo *cached_repos;
305 55e6cffd 2022-09-01 thomas int ncached_repos;
306 55e6cffd 2022-09-01 thomas
307 8a35f56c 2022-07-16 thomas char name[GOTWEBD_MAXTEXT];
308 8a35f56c 2022-07-16 thomas
309 8a35f56c 2022-07-16 thomas char repos_path[PATH_MAX];
310 8a35f56c 2022-07-16 thomas char site_name[GOTWEBD_MAXNAME];
311 8a35f56c 2022-07-16 thomas char site_owner[GOTWEBD_MAXNAME];
312 8a35f56c 2022-07-16 thomas char site_link[GOTWEBD_MAXTEXT];
313 8a35f56c 2022-07-16 thomas char logo[GOTWEBD_MAXTEXT];
314 8a35f56c 2022-07-16 thomas char logo_url[GOTWEBD_MAXTEXT];
315 8a35f56c 2022-07-16 thomas char custom_css[PATH_MAX];
316 8a35f56c 2022-07-16 thomas
317 8a35f56c 2022-07-16 thomas size_t max_repos;
318 8a35f56c 2022-07-16 thomas size_t max_repos_display;
319 8a35f56c 2022-07-16 thomas size_t max_commits_display;
320 8a35f56c 2022-07-16 thomas
321 8a35f56c 2022-07-16 thomas int show_site_owner;
322 8a35f56c 2022-07-16 thomas int show_repo_owner;
323 8a35f56c 2022-07-16 thomas int show_repo_age;
324 8a35f56c 2022-07-16 thomas int show_repo_description;
325 8a35f56c 2022-07-16 thomas int show_repo_cloneurl;
326 3991b2a5 2022-10-31 thomas int respect_exportok;
327 8a35f56c 2022-07-16 thomas
328 8a35f56c 2022-07-16 thomas int unix_socket;
329 8a35f56c 2022-07-16 thomas char unix_socket_name[PATH_MAX];
330 8a35f56c 2022-07-16 thomas
331 8a35f56c 2022-07-16 thomas int fcgi_socket;
332 8a35f56c 2022-07-16 thomas };
333 8a35f56c 2022-07-16 thomas TAILQ_HEAD(serverlist, server);
334 8a35f56c 2022-07-16 thomas
335 8a35f56c 2022-07-16 thomas enum client_action {
336 8a35f56c 2022-07-16 thomas CLIENT_CONNECT,
337 8a35f56c 2022-07-16 thomas CLIENT_DISCONNECT,
338 8a35f56c 2022-07-16 thomas };
339 8a35f56c 2022-07-16 thomas
340 8a35f56c 2022-07-16 thomas struct socket_conf {
341 9d7714e3 2022-08-27 thomas struct address addr;
342 8a35f56c 2022-07-16 thomas
343 8a35f56c 2022-07-16 thomas char name[GOTWEBD_MAXTEXT];
344 8a35f56c 2022-07-16 thomas char srv_name[GOTWEBD_MAXTEXT];
345 8a35f56c 2022-07-16 thomas
346 8a35f56c 2022-07-16 thomas int id;
347 720c2b05 2022-08-16 thomas int af_type;
348 8a35f56c 2022-07-16 thomas char unix_socket_name[PATH_MAX];
349 8a35f56c 2022-07-16 thomas in_port_t fcgi_socket_port;
350 8a35f56c 2022-07-16 thomas };
351 8a35f56c 2022-07-16 thomas
352 8a35f56c 2022-07-16 thomas struct socket {
353 8a35f56c 2022-07-16 thomas TAILQ_ENTRY(socket) entry;
354 8a35f56c 2022-07-16 thomas struct socket_conf conf;
355 8a35f56c 2022-07-16 thomas
356 8a35f56c 2022-07-16 thomas int fd;
357 e80b37ed 2022-07-22 thomas int pack_fds[GOTWEB_PACK_NUM_TEMPFILES];
358 8a35f56c 2022-07-16 thomas int priv_fd[PRIV_FDS__MAX];
359 8a35f56c 2022-07-16 thomas
360 8a35f56c 2022-07-16 thomas struct event evt;
361 8a35f56c 2022-07-16 thomas struct event ev;
362 8a35f56c 2022-07-16 thomas struct event pause;
363 8a35f56c 2022-07-16 thomas
364 8a35f56c 2022-07-16 thomas int client_status;
365 8a35f56c 2022-07-16 thomas };
366 8a35f56c 2022-07-16 thomas TAILQ_HEAD(socketlist, socket);
367 8a35f56c 2022-07-16 thomas
368 f85c939f 2023-11-22 thomas struct passwd;
369 8a35f56c 2022-07-16 thomas struct gotwebd {
370 90d63d47 2022-08-16 thomas struct serverlist servers;
371 90d63d47 2022-08-16 thomas struct socketlist sockets;
372 8a35f56c 2022-07-16 thomas
373 8a35f56c 2022-07-16 thomas const char *gotwebd_conffile;
374 8a35f56c 2022-07-16 thomas
375 8a35f56c 2022-07-16 thomas int gotwebd_debug;
376 8a35f56c 2022-07-16 thomas int gotwebd_verbose;
377 8a35f56c 2022-07-16 thomas
378 f85c939f 2023-11-22 thomas struct imsgev *iev_parent;
379 f85c939f 2023-11-22 thomas struct imsgev *iev_server;
380 f85c939f 2023-11-22 thomas size_t nserver;
381 f85c939f 2023-11-22 thomas
382 f85c939f 2023-11-22 thomas struct passwd *pw;
383 f85c939f 2023-11-22 thomas
384 8a35f56c 2022-07-16 thomas uint16_t prefork_gotwebd;
385 8a35f56c 2022-07-16 thomas int gotwebd_reload;
386 8a35f56c 2022-07-16 thomas
387 8a35f56c 2022-07-16 thomas int server_cnt;
388 8a35f56c 2022-07-16 thomas
389 8a35f56c 2022-07-16 thomas char httpd_chroot[PATH_MAX];
390 8a35f56c 2022-07-16 thomas
391 8a35f56c 2022-07-16 thomas int unix_socket;
392 8a35f56c 2022-07-16 thomas char unix_socket_name[PATH_MAX];
393 8a35f56c 2022-07-16 thomas };
394 8a35f56c 2022-07-16 thomas
395 55144267 2022-09-07 thomas /*
396 11490987 2023-01-15 thomas * URL parameter for gotweb_render_url. NULL values and int set to -1
397 11490987 2023-01-15 thomas * are implicitly ignored, and string are properly escaped.
398 55144267 2022-09-07 thomas */
399 55144267 2022-09-07 thomas struct gotweb_url {
400 55144267 2022-09-07 thomas int action;
401 55144267 2022-09-07 thomas int index_page;
402 55144267 2022-09-07 thomas int page;
403 55144267 2022-09-07 thomas const char *commit;
404 55144267 2022-09-07 thomas const char *previd;
405 55144267 2022-09-07 thomas const char *prevset;
406 55144267 2022-09-07 thomas const char *file;
407 55144267 2022-09-07 thomas const char *folder;
408 55144267 2022-09-07 thomas const char *headref;
409 55144267 2022-09-07 thomas const char *path;
410 55144267 2022-09-07 thomas };
411 55144267 2022-09-07 thomas
412 8a35f56c 2022-07-16 thomas struct querystring {
413 8a35f56c 2022-07-16 thomas uint8_t action;
414 8a35f56c 2022-07-16 thomas char *commit;
415 8a35f56c 2022-07-16 thomas char *previd;
416 8a35f56c 2022-07-16 thomas char *prevset;
417 8a35f56c 2022-07-16 thomas char *file;
418 8a35f56c 2022-07-16 thomas char *folder;
419 8a35f56c 2022-07-16 thomas char *headref;
420 8a35f56c 2022-07-16 thomas int index_page;
421 8a35f56c 2022-07-16 thomas char *path;
422 8a35f56c 2022-07-16 thomas int page;
423 8a35f56c 2022-07-16 thomas };
424 8a35f56c 2022-07-16 thomas
425 8a35f56c 2022-07-16 thomas struct querystring_keys {
426 8a35f56c 2022-07-16 thomas const char *name;
427 8a35f56c 2022-07-16 thomas int element;
428 8a35f56c 2022-07-16 thomas };
429 8a35f56c 2022-07-16 thomas
430 8a35f56c 2022-07-16 thomas struct action_keys {
431 8a35f56c 2022-07-16 thomas const char *name;
432 8a35f56c 2022-07-16 thomas int action;
433 8a35f56c 2022-07-16 thomas };
434 8a35f56c 2022-07-16 thomas
435 8a35f56c 2022-07-16 thomas enum querystring_elements {
436 8a35f56c 2022-07-16 thomas ACTION,
437 8a35f56c 2022-07-16 thomas COMMIT,
438 8a35f56c 2022-07-16 thomas RFILE,
439 8a35f56c 2022-07-16 thomas FOLDER,
440 8a35f56c 2022-07-16 thomas HEADREF,
441 8a35f56c 2022-07-16 thomas INDEX_PAGE,
442 8a35f56c 2022-07-16 thomas PATH,
443 8a35f56c 2022-07-16 thomas PAGE,
444 8a35f56c 2022-07-16 thomas };
445 8a35f56c 2022-07-16 thomas
446 8a35f56c 2022-07-16 thomas enum query_actions {
447 8a35f56c 2022-07-16 thomas BLAME,
448 8a35f56c 2022-07-16 thomas BLOB,
449 b82440e1 2023-01-06 thomas BLOBRAW,
450 8a35f56c 2022-07-16 thomas BRIEFS,
451 8a35f56c 2022-07-16 thomas COMMITS,
452 8a35f56c 2022-07-16 thomas DIFF,
453 8a35f56c 2022-07-16 thomas ERR,
454 8a35f56c 2022-07-16 thomas INDEX,
455 8a35f56c 2022-07-16 thomas SUMMARY,
456 8a35f56c 2022-07-16 thomas TAG,
457 8a35f56c 2022-07-16 thomas TAGS,
458 8a35f56c 2022-07-16 thomas TREE,
459 d6795e9f 2022-12-30 thomas RSS,
460 8a35f56c 2022-07-16 thomas ACTIONS__MAX,
461 8a35f56c 2022-07-16 thomas };
462 8a35f56c 2022-07-16 thomas
463 8a35f56c 2022-07-16 thomas extern struct gotwebd *gotwebd_env;
464 8a35f56c 2022-07-16 thomas
465 1cd5d437 2023-01-15 thomas typedef int (*got_render_blame_line_cb)(struct template *, const char *,
466 1cd5d437 2023-01-15 thomas struct blame_line *, int, int);
467 f85c939f 2023-11-22 thomas
468 f85c939f 2023-11-22 thomas /* gotwebd.c */
469 f85c939f 2023-11-22 thomas void imsg_event_add(struct imsgev *);
470 f85c939f 2023-11-22 thomas int imsg_compose_event(struct imsgev *, uint16_t, uint32_t,
471 f85c939f 2023-11-22 thomas pid_t, int, const void *, uint16_t);
472 f85c939f 2023-11-22 thomas int main_compose_sockets(struct gotwebd *, uint32_t, int,
473 f85c939f 2023-11-22 thomas const void *, uint16_t);
474 f85c939f 2023-11-22 thomas int sockets_compose_main(struct gotwebd *, uint32_t,
475 f85c939f 2023-11-22 thomas const void *, uint16_t);
476 1cd5d437 2023-01-15 thomas
477 8a35f56c 2022-07-16 thomas /* sockets.c */
478 f85c939f 2023-11-22 thomas void sockets(struct gotwebd *, int);
479 8a35f56c 2022-07-16 thomas void sockets_parse_sockets(struct gotwebd *);
480 8a35f56c 2022-07-16 thomas void sockets_socket_accept(int, short, void *);
481 8a35f56c 2022-07-16 thomas int sockets_privinit(struct gotwebd *, struct socket *);
482 8a35f56c 2022-07-16 thomas
483 8a35f56c 2022-07-16 thomas /* gotweb.c */
484 2f4f0731 2022-12-30 thomas void gotweb_get_navs(struct request *, struct gotweb_url *, int *,
485 2f4f0731 2022-12-30 thomas struct gotweb_url *, int *);
486 4cc0851e 2023-10-08 thomas int gotweb_render_age(struct template *, time_t);
487 8a35f56c 2022-07-16 thomas const struct got_error *gotweb_init_transport(struct transport **);
488 e7e5fa49 2022-12-30 thomas const char *gotweb_action_name(int);
489 e7e5fa49 2022-12-30 thomas int gotweb_render_url(struct request *, struct gotweb_url *);
490 d6795e9f 2022-12-30 thomas int gotweb_render_absolute_url(struct request *, struct gotweb_url *);
491 8a35f56c 2022-07-16 thomas void gotweb_free_repo_commit(struct repo_commit *);
492 8a35f56c 2022-07-16 thomas void gotweb_free_repo_tag(struct repo_tag *);
493 8a35f56c 2022-07-16 thomas void gotweb_process_request(struct request *);
494 8a35f56c 2022-07-16 thomas void gotweb_free_transport(struct transport *);
495 8a35f56c 2022-07-16 thomas
496 e7e5fa49 2022-12-30 thomas /* pages.tmpl */
497 161663e7 2023-03-11 thomas int gotweb_render_page(struct template *, int (*)(struct template *));
498 164b5ddc 2023-03-11 thomas int gotweb_render_error(struct template *);
499 e7e5fa49 2022-12-30 thomas int gotweb_render_repo_table_hdr(struct template *);
500 e7e5fa49 2022-12-30 thomas int gotweb_render_repo_fragment(struct template *, struct repo_dir *);
501 e7e5fa49 2022-12-30 thomas int gotweb_render_briefs(struct template *);
502 2f4f0731 2022-12-30 thomas int gotweb_render_navs(struct template *);
503 7ade8b27 2022-12-30 thomas int gotweb_render_commits(struct template *);
504 161663e7 2023-03-11 thomas int gotweb_render_blob(struct template *);
505 3c14c1f2 2023-01-06 thomas int gotweb_render_tree(struct template *);
506 b3ba36c3 2023-01-14 thomas int gotweb_render_tags(struct template *);
507 145ca42a 2023-01-09 thomas int gotweb_render_tag(struct template *);
508 161663e7 2023-03-11 thomas int gotweb_render_diff(struct template *);
509 00abe30b 2023-01-14 thomas int gotweb_render_branches(struct template *, struct got_reflist_head *);
510 161663e7 2023-03-11 thomas int gotweb_render_summary(struct template *);
511 1cd5d437 2023-01-15 thomas int gotweb_render_blame(struct template *);
512 d6795e9f 2022-12-30 thomas int gotweb_render_rss(struct template *);
513 e7e5fa49 2022-12-30 thomas
514 8a35f56c 2022-07-16 thomas /* parse.y */
515 8a35f56c 2022-07-16 thomas int parse_config(const char *, struct gotwebd *);
516 8a35f56c 2022-07-16 thomas int cmdline_symset(char *);
517 8a35f56c 2022-07-16 thomas
518 8a35f56c 2022-07-16 thomas /* fcgi.c */
519 8a35f56c 2022-07-16 thomas void fcgi_request(int, short, void *);
520 8a35f56c 2022-07-16 thomas void fcgi_timeout(int, short, void *);
521 8a35f56c 2022-07-16 thomas void fcgi_cleanup_request(struct request *);
522 8a35f56c 2022-07-16 thomas void fcgi_create_end_record(struct request *);
523 8a35f56c 2022-07-16 thomas void dump_fcgi_record(const char *, struct fcgi_record_header *);
524 d8bf4f25 2023-09-14 thomas int fcgi_write(void *, const void *, size_t);
525 8a35f56c 2022-07-16 thomas
526 8a35f56c 2022-07-16 thomas /* got_operations.c */
527 d00235d8 2023-05-17 thomas const struct got_error *got_gotweb_closefile(FILE *);
528 6c7f10f7 2022-11-23 thomas const struct got_error *got_get_repo_owner(char **, struct request *);
529 53bf32b8 2023-01-23 thomas const struct got_error *got_get_repo_age(time_t *, struct request *,
530 53bf32b8 2023-01-23 thomas const char *);
531 087cc2fc 2023-06-15 thomas const struct got_error *got_get_repo_commits(struct request *, size_t);
532 6c24d194 2023-06-15 thomas const struct got_error *got_get_repo_tags(struct request *, size_t);
533 8a35f56c 2022-07-16 thomas const struct got_error *got_get_repo_heads(struct request *);
534 04b2c111 2023-05-16 thomas const struct got_error *got_open_diff_for_output(FILE **, struct request *);
535 3c14c1f2 2023-01-06 thomas int got_output_repo_tree(struct request *,
536 3c14c1f2 2023-01-06 thomas int (*)(struct template *, struct got_tree_entry *));
537 b82440e1 2023-01-06 thomas const struct got_error *got_open_blob_for_output(struct got_blob_object **,
538 b82440e1 2023-01-06 thomas int *, int *, struct request *);
539 b82440e1 2023-01-06 thomas int got_output_blob_by_lines(struct template *, struct got_blob_object *,
540 b82440e1 2023-01-06 thomas int (*)(struct template *, const char *, size_t));
541 1cd5d437 2023-01-15 thomas const struct got_error *got_output_file_blame(struct request *,
542 1cd5d437 2023-01-15 thomas got_render_blame_line_cb);
543 8a35f56c 2022-07-16 thomas
544 8a35f56c 2022-07-16 thomas /* config.c */
545 8a35f56c 2022-07-16 thomas int config_setserver(struct gotwebd *, struct server *);
546 8a35f56c 2022-07-16 thomas int config_getserver(struct gotwebd *, struct imsg *);
547 8a35f56c 2022-07-16 thomas int config_setsock(struct gotwebd *, struct socket *);
548 8a35f56c 2022-07-16 thomas int config_getsock(struct gotwebd *, struct imsg *);
549 8a35f56c 2022-07-16 thomas int config_setfd(struct gotwebd *, struct socket *);
550 8a35f56c 2022-07-16 thomas int config_getfd(struct gotwebd *, struct imsg *);
551 8a35f56c 2022-07-16 thomas int config_getcfg(struct gotwebd *, struct imsg *);
552 8a35f56c 2022-07-16 thomas int config_init(struct gotwebd *);
553 f85c939f 2023-11-22 thomas
554 f85c939f 2023-11-22 thomas /* log.c */
555 f85c939f 2023-11-22 thomas void log_init(int, int);
556 f85c939f 2023-11-22 thomas void log_procinit(const char *);
557 f85c939f 2023-11-22 thomas void log_setverbose(int);
558 f85c939f 2023-11-22 thomas int log_getverbose(void);
559 f85c939f 2023-11-22 thomas void log_warn(const char *, ...)
560 f85c939f 2023-11-22 thomas __attribute__((__format__ (printf, 1, 2)));
561 f85c939f 2023-11-22 thomas void log_warnx(const char *, ...)
562 f85c939f 2023-11-22 thomas __attribute__((__format__ (printf, 1, 2)));
563 f85c939f 2023-11-22 thomas void log_info(const char *, ...)
564 f85c939f 2023-11-22 thomas __attribute__((__format__ (printf, 1, 2)));
565 f85c939f 2023-11-22 thomas void log_debug(const char *, ...)
566 f85c939f 2023-11-22 thomas __attribute__((__format__ (printf, 1, 2)));
567 f85c939f 2023-11-22 thomas void logit(int, const char *, ...)
568 f85c939f 2023-11-22 thomas __attribute__((__format__ (printf, 2, 3)));
569 f85c939f 2023-11-22 thomas void vlog(int, const char *, va_list)
570 f85c939f 2023-11-22 thomas __attribute__((__format__ (printf, 2, 0)));
571 f85c939f 2023-11-22 thomas __dead void fatal(const char *, ...)
572 f85c939f 2023-11-22 thomas __attribute__((__format__ (printf, 1, 2)));
573 f85c939f 2023-11-22 thomas __dead void fatalx(const char *, ...)
574 f85c939f 2023-11-22 thomas __attribute__((__format__ (printf, 1, 2)));