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