Blame


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