2 * Copyright (c) 2022 Omar Polo <op@omarpolo.com>
3 * Copyright (c) 2006 - 2015 Reyk Floeter <reyk@openbsd.org>
4 * Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org>
5 * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
24 #define GALILEO_USER "www"
25 #define GALILEO_SOCK "/var/www/run/galileo.sock"
26 #define CONF_FILE "/etc/galileo.conf"
28 #define PROC_MAX_INSTANCES 32
29 #define PROXY_NUMPROC 3
30 #define PROC_PARENT_SOCK_FILENO 3
56 struct fcgi *clt_fcgi;
57 char *clt_server_name;
58 char *clt_script_name;
60 struct proxy_config *clt_pc;
61 struct event_asr *clt_evasr;
62 struct addrinfo *clt_addrinfo;
63 struct addrinfo *clt_p;
64 struct event clt_evconn;
67 struct bufferevent *clt_bev;
69 struct template *clt_tp;
71 #define TR_ENABLED 0x1
80 SPLAY_ENTRY(client) clt_nodes;
82 SPLAY_HEAD(client_tree, client);
87 struct client_tree fcg_clients;
88 struct bufferevent *fcg_bev;
97 struct galileo *fcg_env;
99 SPLAY_ENTRY(fcgi) fcg_nodes;
101 SPLAY_HEAD(fcgi_tree, fcgi);
103 struct proxy_config {
104 char host[HOST_NAME_MAX + 1];
105 char stylesheet[PATH_MAX];
106 char proxy_addr[HOST_NAME_MAX + 1];
107 char proxy_name[HOST_NAME_MAX + 1];
108 uint16_t proxy_port; /* TODO: turn into string */
112 TAILQ_ENTRY(server) srv_entry;
113 struct proxy_config srv_conf;
115 TAILQ_HEAD(serverlist, server);
118 char sc_conffile[PATH_MAX];
120 char sc_chroot[PATH_MAX];
121 struct serverlist sc_servers;
122 struct fcgi_tree sc_fcgi_socks;
124 struct privsep *sc_ps;
127 /* XXX: generalize */
129 struct event sc_evsock;
130 struct event sc_evpause;
133 extern int privsep_process;
136 int config_init(struct galileo *);
137 void config_purge(struct galileo *);
138 int config_setserver(struct galileo *, struct server *);
139 int config_getserver(struct galileo *, struct imsg *);
140 int config_setsock(struct galileo *);
141 int config_getsock(struct galileo *, struct imsg *);
142 int config_setreset(struct galileo *);
143 int config_getreset(struct galileo *, struct imsg *);
146 int fcgi_end_request(struct client *, int);
147 int fcgi_abort_request(struct client *);
148 void fcgi_accept(int, short, void *);
149 void fcgi_read(struct bufferevent *, void *);
150 void fcgi_write(struct bufferevent *, void *);
151 void fcgi_error(struct bufferevent *, short error, void *);
152 int clt_putc(struct client *, char);
153 int clt_puts(struct client *, const char *);
154 int clt_write_bufferevent(struct client *, struct bufferevent *);
155 int clt_flush(struct client *);
156 int clt_write(struct client *, const uint8_t *, size_t);
157 int clt_printf(struct client *, const char *, ...)
158 __attribute__((__format__(printf, 2, 3)))
159 __attribute__((__nonnull__(2)));
160 int fcgi_cmp(struct fcgi *, struct fcgi *);
161 int fcgi_client_cmp(struct client *, struct client *);
164 int tp_head(struct template *, const char *, const char *);
165 int tp_foot(struct template *);
166 int tp_figure(struct template *, const char *, const char *);
167 int tp_error(struct template *, const char *);
170 int accept_reserve(int, struct sockaddr *, socklen_t *, int,
173 int parse_config(const char *, struct galileo *);
174 int cmdline_symset(char *);
177 extern volatile int proxy_inflight;
178 extern uint32_t proxy_fcg_id;
180 void proxy(struct privsep *, struct privsep_proc *);
181 void proxy_purge(struct server *);
182 void proxy_start_request(struct galileo *, struct client *);
183 void proxy_client_free(struct client *);
185 SPLAY_PROTOTYPE(fcgi_tree, fcgi, fcg_nodes, fcgi_cmp);
186 SPLAY_PROTOTYPE(client_tree, client, clt_nodes, fcgi_client_cmp);