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 8a35f56c 2022-07-16 thomas
27 8a35f56c 2022-07-16 thomas #ifdef DEBUG
28 8a35f56c 2022-07-16 thomas #define dprintf(x...) do { log_debug(x); } while(0)
29 8a35f56c 2022-07-16 thomas #else
30 8a35f56c 2022-07-16 thomas #define dprintf(x...)
31 8a35f56c 2022-07-16 thomas #endif /* DEBUG */
32 8a35f56c 2022-07-16 thomas
33 8a35f56c 2022-07-16 thomas #ifndef nitems
34 8a35f56c 2022-07-16 thomas #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
35 8a35f56c 2022-07-16 thomas #endif
36 8a35f56c 2022-07-16 thomas
37 8a35f56c 2022-07-16 thomas /* GOTWEBD DEFAULTS */
38 8a35f56c 2022-07-16 thomas #define GOTWEBD_CONF "/etc/gotwebd.conf"
39 8a35f56c 2022-07-16 thomas
40 8a35f56c 2022-07-16 thomas #define GOTWEBD_USER "www"
41 8a35f56c 2022-07-16 thomas
42 3e9a56b5 2022-12-01 thomas #define GOTWEBD_MAXDESCRSZ 1024
43 3e9a56b5 2022-12-01 thomas #define GOTWEBD_MAXCLONEURLSZ 1024
44 e5539f76 2022-08-10 thomas #define GOTWEBD_CACHESIZE 1024
45 8a35f56c 2022-07-16 thomas #define GOTWEBD_MAXCLIENTS 1024
46 8a35f56c 2022-07-16 thomas #define GOTWEBD_MAXTEXT 511
47 8a35f56c 2022-07-16 thomas #define GOTWEBD_MAXNAME 64
48 8a35f56c 2022-07-16 thomas #define GOTWEBD_MAXPORT 6
49 8a35f56c 2022-07-16 thomas #define GOTWEBD_NUMPROC 3
50 8a35f56c 2022-07-16 thomas #define GOTWEBD_MAXIFACE 16
51 55e6cffd 2022-09-01 thomas #define GOTWEBD_REPO_CACHESIZE 4
52 8a35f56c 2022-07-16 thomas
53 8a35f56c 2022-07-16 thomas /* GOTWEB DEFAULTS */
54 8a35f56c 2022-07-16 thomas #define MAX_QUERYSTRING 2048
55 3191e256 2022-12-30 thomas #define MAX_DOCUMENT_URI 255
56 8a35f56c 2022-07-16 thomas #define MAX_SERVER_NAME 255
57 8a35f56c 2022-07-16 thomas
58 8a35f56c 2022-07-16 thomas #define GOTWEB_GIT_DIR ".git"
59 8a35f56c 2022-07-16 thomas
60 8a35f56c 2022-07-16 thomas #define D_HTTPD_CHROOT "/var/www"
61 8a35f56c 2022-07-16 thomas #define D_UNIX_SOCKET "/run/gotweb.sock"
62 8a35f56c 2022-07-16 thomas #define D_FCGI_PORT "9000"
63 8a35f56c 2022-07-16 thomas #define D_GOTPATH "/got/public"
64 8a35f56c 2022-07-16 thomas #define D_SITENAME "Gotweb"
65 8a35f56c 2022-07-16 thomas #define D_SITEOWNER "Got Owner"
66 8a35f56c 2022-07-16 thomas #define D_SITELINK "Repos"
67 8a35f56c 2022-07-16 thomas #define D_GOTLOGO "got.png"
68 8a35f56c 2022-07-16 thomas #define D_GOTURL "https://gameoftrees.org"
69 8a35f56c 2022-07-16 thomas #define D_GOTWEBCSS "gotweb.css"
70 8a35f56c 2022-07-16 thomas
71 8a35f56c 2022-07-16 thomas #define D_SHOWROWNER 1
72 8a35f56c 2022-07-16 thomas #define D_SHOWSOWNER 1
73 8a35f56c 2022-07-16 thomas #define D_SHOWAGE 1
74 8a35f56c 2022-07-16 thomas #define D_SHOWDESC 1
75 8a35f56c 2022-07-16 thomas #define D_SHOWURL 1
76 3991b2a5 2022-10-31 thomas #define D_RESPECTEXPORTOK 0
77 8a35f56c 2022-07-16 thomas #define D_MAXREPO 0
78 8a35f56c 2022-07-16 thomas #define D_MAXREPODISP 25
79 8a35f56c 2022-07-16 thomas #define D_MAXSLCOMMDISP 10
80 8a35f56c 2022-07-16 thomas #define D_MAXCOMMITDISP 25
81 8a35f56c 2022-07-16 thomas
82 8a35f56c 2022-07-16 thomas #define BUF 8192
83 8a35f56c 2022-07-16 thomas
84 8a35f56c 2022-07-16 thomas #define TIMEOUT_DEFAULT 120
85 8a35f56c 2022-07-16 thomas
86 8a35f56c 2022-07-16 thomas #define FCGI_CONTENT_SIZE 65535
87 8a35f56c 2022-07-16 thomas #define FCGI_PADDING_SIZE 255
88 8a35f56c 2022-07-16 thomas #define FCGI_RECORD_SIZE \
89 8a35f56c 2022-07-16 thomas (sizeof(struct fcgi_record_header) + FCGI_CONTENT_SIZE + FCGI_PADDING_SIZE)
90 8a35f56c 2022-07-16 thomas
91 8a35f56c 2022-07-16 thomas #define FCGI_ALIGNMENT 8
92 8a35f56c 2022-07-16 thomas #define FCGI_ALIGN(n) \
93 8a35f56c 2022-07-16 thomas (((n) + (FCGI_ALIGNMENT - 1)) & ~(FCGI_ALIGNMENT - 1))
94 8a35f56c 2022-07-16 thomas
95 8a35f56c 2022-07-16 thomas #define FD_RESERVE 5
96 8a35f56c 2022-07-16 thomas #define FD_NEEDED 6
97 8a35f56c 2022-07-16 thomas
98 8a35f56c 2022-07-16 thomas #define FCGI_BEGIN_REQUEST 1
99 8a35f56c 2022-07-16 thomas #define FCGI_ABORT_REQUEST 2
100 8a35f56c 2022-07-16 thomas #define FCGI_END_REQUEST 3
101 8a35f56c 2022-07-16 thomas #define FCGI_PARAMS 4
102 8a35f56c 2022-07-16 thomas #define FCGI_STDIN 5
103 8a35f56c 2022-07-16 thomas #define FCGI_STDOUT 6
104 8a35f56c 2022-07-16 thomas #define FCGI_STDERR 7
105 8a35f56c 2022-07-16 thomas #define FCGI_DATA 8
106 8a35f56c 2022-07-16 thomas #define FCGI_GET_VALUES 9
107 8a35f56c 2022-07-16 thomas #define FCGI_GET_VALUES_RESULT 10
108 8a35f56c 2022-07-16 thomas #define FCGI_UNKNOWN_TYPE 11
109 8a35f56c 2022-07-16 thomas #define FCGI_MAXTYPE (FCGI_UNKNOWN_TYPE)
110 8a35f56c 2022-07-16 thomas
111 8a35f56c 2022-07-16 thomas #define FCGI_REQUEST_COMPLETE 0
112 8a35f56c 2022-07-16 thomas #define FCGI_CANT_MPX_CONN 1
113 8a35f56c 2022-07-16 thomas #define FCGI_OVERLOADED 2
114 8a35f56c 2022-07-16 thomas #define FCGI_UNKNOWN_ROLE 3
115 8a35f56c 2022-07-16 thomas
116 e80b37ed 2022-07-22 thomas #define GOTWEB_PACK_NUM_TEMPFILES 32
117 8a35f56c 2022-07-16 thomas
118 8a35f56c 2022-07-16 thomas enum imsg_type {
119 8a35f56c 2022-07-16 thomas IMSG_CFG_SRV = IMSG_PROC_MAX,
120 8a35f56c 2022-07-16 thomas IMSG_CFG_SOCK,
121 8a35f56c 2022-07-16 thomas IMSG_CFG_FD,
122 8a35f56c 2022-07-16 thomas IMSG_CFG_DONE,
123 8a35f56c 2022-07-16 thomas IMSG_CTL_START,
124 8a35f56c 2022-07-16 thomas };
125 8a35f56c 2022-07-16 thomas
126 8a35f56c 2022-07-16 thomas struct env_val {
127 8a35f56c 2022-07-16 thomas SLIST_ENTRY(env_val) entry;
128 8a35f56c 2022-07-16 thomas char *val;
129 8a35f56c 2022-07-16 thomas };
130 8a35f56c 2022-07-16 thomas SLIST_HEAD(env_head, env_val);
131 8a35f56c 2022-07-16 thomas
132 8a35f56c 2022-07-16 thomas struct fcgi_record_header {
133 8a35f56c 2022-07-16 thomas uint8_t version;
134 8a35f56c 2022-07-16 thomas uint8_t type;
135 8a35f56c 2022-07-16 thomas uint16_t id;
136 8a35f56c 2022-07-16 thomas uint16_t content_len;
137 8a35f56c 2022-07-16 thomas uint8_t padding_len;
138 8a35f56c 2022-07-16 thomas uint8_t reserved;
139 0740b40a 2022-07-16 thomas }__attribute__((__packed__));
140 8a35f56c 2022-07-16 thomas
141 8a35f56c 2022-07-16 thomas struct repo_dir {
142 8a35f56c 2022-07-16 thomas char *name;
143 8a35f56c 2022-07-16 thomas char *owner;
144 8a35f56c 2022-07-16 thomas char *description;
145 8a35f56c 2022-07-16 thomas char *url;
146 8a35f56c 2022-07-16 thomas char *age;
147 8a35f56c 2022-07-16 thomas char *path;
148 8a35f56c 2022-07-16 thomas };
149 8a35f56c 2022-07-16 thomas
150 8a35f56c 2022-07-16 thomas struct repo_tag {
151 8a35f56c 2022-07-16 thomas TAILQ_ENTRY(repo_tag) entry;
152 8a35f56c 2022-07-16 thomas char *commit_id;
153 8a35f56c 2022-07-16 thomas char *tag_name;
154 8a35f56c 2022-07-16 thomas char *tag_commit;
155 8a35f56c 2022-07-16 thomas char *commit_msg;
156 8a35f56c 2022-07-16 thomas char *tagger;
157 8a35f56c 2022-07-16 thomas time_t tagger_time;
158 8a35f56c 2022-07-16 thomas };
159 8a35f56c 2022-07-16 thomas
160 8a35f56c 2022-07-16 thomas struct repo_commit {
161 8a35f56c 2022-07-16 thomas TAILQ_ENTRY(repo_commit) entry;
162 8a35f56c 2022-07-16 thomas char *path;
163 8a35f56c 2022-07-16 thomas char *refs_str;
164 8a35f56c 2022-07-16 thomas char *commit_id; /* id_str1 */
165 8a35f56c 2022-07-16 thomas char *parent_id; /* id_str2 */
166 8a35f56c 2022-07-16 thomas char *tree_id;
167 8a35f56c 2022-07-16 thomas char *author;
168 8a35f56c 2022-07-16 thomas char *committer;
169 8a35f56c 2022-07-16 thomas char *commit_msg;
170 8a35f56c 2022-07-16 thomas time_t committer_time;
171 8a35f56c 2022-07-16 thomas };
172 8a35f56c 2022-07-16 thomas
173 8a35f56c 2022-07-16 thomas struct got_repository;
174 8a35f56c 2022-07-16 thomas struct transport {
175 8a35f56c 2022-07-16 thomas TAILQ_HEAD(repo_commits_head, repo_commit) repo_commits;
176 8a35f56c 2022-07-16 thomas TAILQ_HEAD(repo_tags_head, repo_tag) repo_tags;
177 8a35f56c 2022-07-16 thomas struct got_repository *repo;
178 8a35f56c 2022-07-16 thomas struct repo_dir *repo_dir;
179 8a35f56c 2022-07-16 thomas struct querystring *qs;
180 8a35f56c 2022-07-16 thomas char *next_id;
181 8a35f56c 2022-07-16 thomas char *prev_id;
182 8a35f56c 2022-07-16 thomas unsigned int repos_total;
183 8a35f56c 2022-07-16 thomas unsigned int next_disp;
184 8a35f56c 2022-07-16 thomas unsigned int prev_disp;
185 8a35f56c 2022-07-16 thomas unsigned int tag_count;
186 8a35f56c 2022-07-16 thomas };
187 8a35f56c 2022-07-16 thomas
188 8a35f56c 2022-07-16 thomas enum socket_priv_fds {
189 8a35f56c 2022-07-16 thomas DIFF_FD_1,
190 8a35f56c 2022-07-16 thomas DIFF_FD_2,
191 8a35f56c 2022-07-16 thomas DIFF_FD_3,
192 8a35f56c 2022-07-16 thomas DIFF_FD_4,
193 8a35f56c 2022-07-16 thomas DIFF_FD_5,
194 8a35f56c 2022-07-16 thomas BLAME_FD_1,
195 8a35f56c 2022-07-16 thomas BLAME_FD_2,
196 8a35f56c 2022-07-16 thomas BLAME_FD_3,
197 8a35f56c 2022-07-16 thomas BLAME_FD_4,
198 8a35f56c 2022-07-16 thomas BLAME_FD_5,
199 8a35f56c 2022-07-16 thomas BLAME_FD_6,
200 8a35f56c 2022-07-16 thomas BLOB_FD_1,
201 8a35f56c 2022-07-16 thomas BLOB_FD_2,
202 8a35f56c 2022-07-16 thomas PRIV_FDS__MAX,
203 8a35f56c 2022-07-16 thomas };
204 8a35f56c 2022-07-16 thomas
205 e7e5fa49 2022-12-30 thomas struct template;
206 8a35f56c 2022-07-16 thomas struct request {
207 8a35f56c 2022-07-16 thomas struct socket *sock;
208 8a35f56c 2022-07-16 thomas struct server *srv;
209 8a35f56c 2022-07-16 thomas struct transport *t;
210 e7e5fa49 2022-12-30 thomas struct template *tp;
211 8a35f56c 2022-07-16 thomas struct event ev;
212 8a35f56c 2022-07-16 thomas struct event tmo;
213 8a35f56c 2022-07-16 thomas
214 8a35f56c 2022-07-16 thomas uint16_t id;
215 8a35f56c 2022-07-16 thomas int fd;
216 8a35f56c 2022-07-16 thomas int priv_fd[PRIV_FDS__MAX];
217 8a35f56c 2022-07-16 thomas
218 8a35f56c 2022-07-16 thomas uint8_t buf[FCGI_RECORD_SIZE];
219 8a35f56c 2022-07-16 thomas size_t buf_pos;
220 8a35f56c 2022-07-16 thomas size_t buf_len;
221 e5539f76 2022-08-10 thomas
222 e5539f76 2022-08-10 thomas uint8_t outbuf[GOTWEBD_CACHESIZE];
223 e5539f76 2022-08-10 thomas size_t outbuf_len;
224 8a35f56c 2022-07-16 thomas
225 8a35f56c 2022-07-16 thomas char querystring[MAX_QUERYSTRING];
226 8a35f56c 2022-07-16 thomas char http_host[GOTWEBD_MAXTEXT];
227 3191e256 2022-12-30 thomas char document_uri[MAX_DOCUMENT_URI];
228 8a35f56c 2022-07-16 thomas char server_name[MAX_SERVER_NAME];
229 8a35f56c 2022-07-16 thomas
230 8a35f56c 2022-07-16 thomas uint8_t request_started;
231 8a35f56c 2022-07-16 thomas };
232 8a35f56c 2022-07-16 thomas
233 8a35f56c 2022-07-16 thomas struct fcgi_begin_request_body {
234 8a35f56c 2022-07-16 thomas uint16_t role;
235 8a35f56c 2022-07-16 thomas uint8_t flags;
236 8a35f56c 2022-07-16 thomas uint8_t reserved[5];
237 0740b40a 2022-07-16 thomas }__attribute__((__packed__));
238 8a35f56c 2022-07-16 thomas
239 8a35f56c 2022-07-16 thomas struct fcgi_end_request_body {
240 8a35f56c 2022-07-16 thomas uint32_t app_status;
241 8a35f56c 2022-07-16 thomas uint8_t protocol_status;
242 8a35f56c 2022-07-16 thomas uint8_t reserved[3];
243 755d897e 2022-08-06 thomas }__attribute__((__packed__));
244 8a35f56c 2022-07-16 thomas
245 8a35f56c 2022-07-16 thomas struct address {
246 8a35f56c 2022-07-16 thomas TAILQ_ENTRY(address) entry;
247 8a35f56c 2022-07-16 thomas struct sockaddr_storage ss;
248 8a35f56c 2022-07-16 thomas int ipproto;
249 8a35f56c 2022-07-16 thomas int prefixlen;
250 8a35f56c 2022-07-16 thomas in_port_t port;
251 8a35f56c 2022-07-16 thomas char ifname[IFNAMSIZ];
252 8a35f56c 2022-07-16 thomas };
253 8a35f56c 2022-07-16 thomas TAILQ_HEAD(addresslist, address);
254 8a35f56c 2022-07-16 thomas
255 55e6cffd 2022-09-01 thomas struct cached_repo {
256 55e6cffd 2022-09-01 thomas char path[PATH_MAX];
257 55e6cffd 2022-09-01 thomas struct got_repository *repo;
258 55e6cffd 2022-09-01 thomas };
259 55e6cffd 2022-09-01 thomas
260 8a35f56c 2022-07-16 thomas struct server {
261 8a35f56c 2022-07-16 thomas TAILQ_ENTRY(server) entry;
262 62f85214 2022-08-16 thomas struct addresslist al;
263 8a35f56c 2022-07-16 thomas
264 a004b24a 2022-09-06 thomas struct cached_repo *cached_repos;
265 55e6cffd 2022-09-01 thomas int ncached_repos;
266 55e6cffd 2022-09-01 thomas
267 8a35f56c 2022-07-16 thomas char name[GOTWEBD_MAXTEXT];
268 8a35f56c 2022-07-16 thomas
269 8a35f56c 2022-07-16 thomas char repos_path[PATH_MAX];
270 8a35f56c 2022-07-16 thomas char site_name[GOTWEBD_MAXNAME];
271 8a35f56c 2022-07-16 thomas char site_owner[GOTWEBD_MAXNAME];
272 8a35f56c 2022-07-16 thomas char site_link[GOTWEBD_MAXTEXT];
273 8a35f56c 2022-07-16 thomas char logo[GOTWEBD_MAXTEXT];
274 8a35f56c 2022-07-16 thomas char logo_url[GOTWEBD_MAXTEXT];
275 8a35f56c 2022-07-16 thomas char custom_css[PATH_MAX];
276 8a35f56c 2022-07-16 thomas
277 8a35f56c 2022-07-16 thomas size_t max_repos;
278 8a35f56c 2022-07-16 thomas size_t max_repos_display;
279 8a35f56c 2022-07-16 thomas size_t max_commits_display;
280 8a35f56c 2022-07-16 thomas
281 8a35f56c 2022-07-16 thomas int show_site_owner;
282 8a35f56c 2022-07-16 thomas int show_repo_owner;
283 8a35f56c 2022-07-16 thomas int show_repo_age;
284 8a35f56c 2022-07-16 thomas int show_repo_description;
285 8a35f56c 2022-07-16 thomas int show_repo_cloneurl;
286 3991b2a5 2022-10-31 thomas int respect_exportok;
287 8a35f56c 2022-07-16 thomas
288 8a35f56c 2022-07-16 thomas int unix_socket;
289 8a35f56c 2022-07-16 thomas char unix_socket_name[PATH_MAX];
290 8a35f56c 2022-07-16 thomas
291 8a35f56c 2022-07-16 thomas int fcgi_socket;
292 8a35f56c 2022-07-16 thomas };
293 8a35f56c 2022-07-16 thomas TAILQ_HEAD(serverlist, server);
294 8a35f56c 2022-07-16 thomas
295 8a35f56c 2022-07-16 thomas enum client_action {
296 8a35f56c 2022-07-16 thomas CLIENT_CONNECT,
297 8a35f56c 2022-07-16 thomas CLIENT_DISCONNECT,
298 8a35f56c 2022-07-16 thomas };
299 8a35f56c 2022-07-16 thomas
300 8a35f56c 2022-07-16 thomas struct socket_conf {
301 9d7714e3 2022-08-27 thomas struct address addr;
302 8a35f56c 2022-07-16 thomas
303 8a35f56c 2022-07-16 thomas char name[GOTWEBD_MAXTEXT];
304 8a35f56c 2022-07-16 thomas char srv_name[GOTWEBD_MAXTEXT];
305 8a35f56c 2022-07-16 thomas
306 8a35f56c 2022-07-16 thomas int id;
307 720c2b05 2022-08-16 thomas int af_type;
308 8a35f56c 2022-07-16 thomas char unix_socket_name[PATH_MAX];
309 8a35f56c 2022-07-16 thomas in_port_t fcgi_socket_port;
310 8a35f56c 2022-07-16 thomas };
311 8a35f56c 2022-07-16 thomas
312 8a35f56c 2022-07-16 thomas struct socket {
313 8a35f56c 2022-07-16 thomas TAILQ_ENTRY(socket) entry;
314 8a35f56c 2022-07-16 thomas struct socket_conf conf;
315 8a35f56c 2022-07-16 thomas
316 8a35f56c 2022-07-16 thomas int fd;
317 e80b37ed 2022-07-22 thomas int pack_fds[GOTWEB_PACK_NUM_TEMPFILES];
318 8a35f56c 2022-07-16 thomas int priv_fd[PRIV_FDS__MAX];
319 8a35f56c 2022-07-16 thomas
320 8a35f56c 2022-07-16 thomas struct event evt;
321 8a35f56c 2022-07-16 thomas struct event ev;
322 8a35f56c 2022-07-16 thomas struct event pause;
323 8a35f56c 2022-07-16 thomas
324 8a35f56c 2022-07-16 thomas int client_status;
325 8a35f56c 2022-07-16 thomas };
326 8a35f56c 2022-07-16 thomas TAILQ_HEAD(socketlist, socket);
327 8a35f56c 2022-07-16 thomas
328 8a35f56c 2022-07-16 thomas struct gotwebd {
329 90d63d47 2022-08-16 thomas struct serverlist servers;
330 90d63d47 2022-08-16 thomas struct socketlist sockets;
331 8a35f56c 2022-07-16 thomas
332 8a35f56c 2022-07-16 thomas struct privsep *gotwebd_ps;
333 8a35f56c 2022-07-16 thomas const char *gotwebd_conffile;
334 8a35f56c 2022-07-16 thomas
335 8a35f56c 2022-07-16 thomas int gotwebd_debug;
336 8a35f56c 2022-07-16 thomas int gotwebd_verbose;
337 8a35f56c 2022-07-16 thomas int gotwebd_noaction;
338 8a35f56c 2022-07-16 thomas
339 8a35f56c 2022-07-16 thomas uint16_t prefork_gotwebd;
340 8a35f56c 2022-07-16 thomas int gotwebd_reload;
341 8a35f56c 2022-07-16 thomas
342 8a35f56c 2022-07-16 thomas int server_cnt;
343 8a35f56c 2022-07-16 thomas
344 8a35f56c 2022-07-16 thomas char httpd_chroot[PATH_MAX];
345 8a35f56c 2022-07-16 thomas
346 8a35f56c 2022-07-16 thomas int unix_socket;
347 8a35f56c 2022-07-16 thomas char unix_socket_name[PATH_MAX];
348 8a35f56c 2022-07-16 thomas };
349 8a35f56c 2022-07-16 thomas
350 55144267 2022-09-07 thomas /*
351 55144267 2022-09-07 thomas * URL parameter for gotweb_link. NULL values and int set to -1 are
352 55144267 2022-09-07 thomas * implicitly ignored, and string are properly escaped.
353 55144267 2022-09-07 thomas */
354 55144267 2022-09-07 thomas struct gotweb_url {
355 55144267 2022-09-07 thomas int action;
356 55144267 2022-09-07 thomas int index_page;
357 55144267 2022-09-07 thomas int page;
358 55144267 2022-09-07 thomas const char *commit;
359 55144267 2022-09-07 thomas const char *previd;
360 55144267 2022-09-07 thomas const char *prevset;
361 55144267 2022-09-07 thomas const char *file;
362 55144267 2022-09-07 thomas const char *folder;
363 55144267 2022-09-07 thomas const char *headref;
364 55144267 2022-09-07 thomas const char *path;
365 55144267 2022-09-07 thomas };
366 55144267 2022-09-07 thomas
367 8a35f56c 2022-07-16 thomas struct querystring {
368 8a35f56c 2022-07-16 thomas uint8_t action;
369 8a35f56c 2022-07-16 thomas char *commit;
370 8a35f56c 2022-07-16 thomas char *previd;
371 8a35f56c 2022-07-16 thomas char *prevset;
372 8a35f56c 2022-07-16 thomas char *file;
373 8a35f56c 2022-07-16 thomas char *folder;
374 8a35f56c 2022-07-16 thomas char *headref;
375 8a35f56c 2022-07-16 thomas int index_page;
376 8a35f56c 2022-07-16 thomas char *path;
377 8a35f56c 2022-07-16 thomas int page;
378 8a35f56c 2022-07-16 thomas };
379 8a35f56c 2022-07-16 thomas
380 8a35f56c 2022-07-16 thomas struct querystring_keys {
381 8a35f56c 2022-07-16 thomas const char *name;
382 8a35f56c 2022-07-16 thomas int element;
383 8a35f56c 2022-07-16 thomas };
384 8a35f56c 2022-07-16 thomas
385 8a35f56c 2022-07-16 thomas struct action_keys {
386 8a35f56c 2022-07-16 thomas const char *name;
387 8a35f56c 2022-07-16 thomas int action;
388 8a35f56c 2022-07-16 thomas };
389 8a35f56c 2022-07-16 thomas
390 8a35f56c 2022-07-16 thomas enum querystring_elements {
391 8a35f56c 2022-07-16 thomas ACTION,
392 8a35f56c 2022-07-16 thomas COMMIT,
393 8a35f56c 2022-07-16 thomas RFILE,
394 8a35f56c 2022-07-16 thomas FOLDER,
395 8a35f56c 2022-07-16 thomas HEADREF,
396 8a35f56c 2022-07-16 thomas INDEX_PAGE,
397 8a35f56c 2022-07-16 thomas PATH,
398 8a35f56c 2022-07-16 thomas PAGE,
399 8a35f56c 2022-07-16 thomas PREVID,
400 8a35f56c 2022-07-16 thomas QSELEM__MAX,
401 8a35f56c 2022-07-16 thomas };
402 8a35f56c 2022-07-16 thomas
403 8a35f56c 2022-07-16 thomas enum query_actions {
404 8a35f56c 2022-07-16 thomas BLAME,
405 8a35f56c 2022-07-16 thomas BLOB,
406 8a35f56c 2022-07-16 thomas BRIEFS,
407 8a35f56c 2022-07-16 thomas COMMITS,
408 8a35f56c 2022-07-16 thomas DIFF,
409 8a35f56c 2022-07-16 thomas ERR,
410 8a35f56c 2022-07-16 thomas INDEX,
411 8a35f56c 2022-07-16 thomas SUMMARY,
412 8a35f56c 2022-07-16 thomas TAG,
413 8a35f56c 2022-07-16 thomas TAGS,
414 8a35f56c 2022-07-16 thomas TREE,
415 8a35f56c 2022-07-16 thomas ACTIONS__MAX,
416 8a35f56c 2022-07-16 thomas };
417 8a35f56c 2022-07-16 thomas
418 e7e5fa49 2022-12-30 thomas enum gotweb_ref_tm {
419 e7e5fa49 2022-12-30 thomas TM_DIFF,
420 e7e5fa49 2022-12-30 thomas TM_LONG,
421 e7e5fa49 2022-12-30 thomas };
422 e7e5fa49 2022-12-30 thomas
423 8a35f56c 2022-07-16 thomas extern struct gotwebd *gotwebd_env;
424 8a35f56c 2022-07-16 thomas
425 8a35f56c 2022-07-16 thomas /* sockets.c */
426 8a35f56c 2022-07-16 thomas void sockets(struct privsep *, struct privsep_proc *);
427 8a35f56c 2022-07-16 thomas void sockets_shutdown(void);
428 8a35f56c 2022-07-16 thomas void sockets_parse_sockets(struct gotwebd *);
429 8a35f56c 2022-07-16 thomas void sockets_socket_accept(int, short, void *);
430 8a35f56c 2022-07-16 thomas int sockets_privinit(struct gotwebd *, struct socket *);
431 8a35f56c 2022-07-16 thomas
432 8a35f56c 2022-07-16 thomas /* gotweb.c */
433 8a35f56c 2022-07-16 thomas const struct got_error *gotweb_render_content_type(struct request *,
434 8a35f56c 2022-07-16 thomas const uint8_t *);
435 8a35f56c 2022-07-16 thomas const struct got_error
436 8a35f56c 2022-07-16 thomas *gotweb_render_content_type_file(struct request *, const uint8_t *, char *);
437 2f4f0731 2022-12-30 thomas void gotweb_get_navs(struct request *, struct gotweb_url *, int *,
438 2f4f0731 2022-12-30 thomas struct gotweb_url *, int *);
439 8a35f56c 2022-07-16 thomas const struct got_error *gotweb_get_time_str(char **, time_t, int);
440 8a35f56c 2022-07-16 thomas const struct got_error *gotweb_init_transport(struct transport **);
441 8a35f56c 2022-07-16 thomas const struct got_error *gotweb_escape_html(char **, const char *);
442 e7e5fa49 2022-12-30 thomas const char *gotweb_action_name(int);
443 e7e5fa49 2022-12-30 thomas int gotweb_render_url(struct request *, struct gotweb_url *);
444 55144267 2022-09-07 thomas int gotweb_link(struct request *, struct gotweb_url *, const char *, ...)
445 55144267 2022-09-07 thomas __attribute__((__format__(printf, 3, 4)))
446 55144267 2022-09-07 thomas __attribute__((__nonnull__(3)));
447 8a35f56c 2022-07-16 thomas void gotweb_free_repo_commit(struct repo_commit *);
448 8a35f56c 2022-07-16 thomas void gotweb_free_repo_tag(struct repo_tag *);
449 8a35f56c 2022-07-16 thomas void gotweb_process_request(struct request *);
450 8a35f56c 2022-07-16 thomas void gotweb_free_transport(struct transport *);
451 8a35f56c 2022-07-16 thomas
452 e7e5fa49 2022-12-30 thomas /* pages.tmpl */
453 e7e5fa49 2022-12-30 thomas int gotweb_render_header(struct template *);
454 e7e5fa49 2022-12-30 thomas int gotweb_render_footer(struct template *);
455 e7e5fa49 2022-12-30 thomas int gotweb_render_repo_table_hdr(struct template *);
456 e7e5fa49 2022-12-30 thomas int gotweb_render_repo_fragment(struct template *, struct repo_dir *);
457 e7e5fa49 2022-12-30 thomas int gotweb_render_briefs(struct template *);
458 2f4f0731 2022-12-30 thomas int gotweb_render_navs(struct template *);
459 7ade8b27 2022-12-30 thomas int gotweb_render_commits(struct template *);
460 e7e5fa49 2022-12-30 thomas
461 8a35f56c 2022-07-16 thomas /* parse.y */
462 8a35f56c 2022-07-16 thomas int parse_config(const char *, struct gotwebd *);
463 8a35f56c 2022-07-16 thomas int cmdline_symset(char *);
464 8a35f56c 2022-07-16 thomas
465 8a35f56c 2022-07-16 thomas /* fcgi.c */
466 8a35f56c 2022-07-16 thomas void fcgi_request(int, short, void *);
467 8a35f56c 2022-07-16 thomas void fcgi_timeout(int, short, void *);
468 8a35f56c 2022-07-16 thomas void fcgi_cleanup_request(struct request *);
469 8a35f56c 2022-07-16 thomas void fcgi_create_end_record(struct request *);
470 8a35f56c 2022-07-16 thomas void dump_fcgi_record(const char *, struct fcgi_record_header *);
471 e7e5fa49 2022-12-30 thomas int fcgi_puts(struct template *, const char *);
472 e7e5fa49 2022-12-30 thomas int fcgi_putc(struct template *, int);
473 55144267 2022-09-07 thomas int fcgi_vprintf(struct request *, const char *, va_list);
474 79393471 2022-08-27 thomas int fcgi_printf(struct request *, const char *, ...)
475 79393471 2022-08-27 thomas __attribute__((__format__(printf, 2, 3)))
476 79393471 2022-08-27 thomas __attribute__((__nonnull__(2)));
477 8a35f56c 2022-07-16 thomas int fcgi_gen_binary_response(struct request *, const uint8_t *, int);
478 8a35f56c 2022-07-16 thomas
479 8a35f56c 2022-07-16 thomas /* got_operations.c */
480 6c7f10f7 2022-11-23 thomas const struct got_error *got_get_repo_owner(char **, struct request *);
481 6c7f10f7 2022-11-23 thomas const struct got_error *got_get_repo_age(char **, struct request *,
482 8a35f56c 2022-07-16 thomas const char *, int);
483 8a35f56c 2022-07-16 thomas const struct got_error *got_get_repo_commits(struct request *, int);
484 8a35f56c 2022-07-16 thomas const struct got_error *got_get_repo_tags(struct request *, int);
485 8a35f56c 2022-07-16 thomas const struct got_error *got_get_repo_heads(struct request *);
486 8a35f56c 2022-07-16 thomas const struct got_error *got_output_repo_diff(struct request *);
487 8a35f56c 2022-07-16 thomas const struct got_error *got_output_repo_tree(struct request *);
488 8a35f56c 2022-07-16 thomas const struct got_error *got_output_file_blob(struct request *);
489 8a35f56c 2022-07-16 thomas const struct got_error *got_output_file_blame(struct request *);
490 8a35f56c 2022-07-16 thomas
491 8a35f56c 2022-07-16 thomas /* config.c */
492 8a35f56c 2022-07-16 thomas int config_setserver(struct gotwebd *, struct server *);
493 8a35f56c 2022-07-16 thomas int config_getserver(struct gotwebd *, struct imsg *);
494 8a35f56c 2022-07-16 thomas int config_setsock(struct gotwebd *, struct socket *);
495 8a35f56c 2022-07-16 thomas int config_getsock(struct gotwebd *, struct imsg *);
496 8a35f56c 2022-07-16 thomas int config_setfd(struct gotwebd *, struct socket *);
497 8a35f56c 2022-07-16 thomas int config_getfd(struct gotwebd *, struct imsg *);
498 8a35f56c 2022-07-16 thomas int config_getcfg(struct gotwebd *, struct imsg *);
499 8a35f56c 2022-07-16 thomas int config_init(struct gotwebd *);