Blame


1 5e11c00c 2021-03-02 op #include "telescope.h"
2 5e11c00c 2021-03-02 op
3 5e11c00c 2021-03-02 op #include <sys/socket.h>
4 5e11c00c 2021-03-02 op
5 5e11c00c 2021-03-02 op #include <errno.h>
6 5e11c00c 2021-03-02 op #include <signal.h>
7 5e11c00c 2021-03-02 op #include <stdio.h>
8 5e11c00c 2021-03-02 op #include <stdlib.h>
9 5e11c00c 2021-03-02 op #include <string.h>
10 5e11c00c 2021-03-02 op #include <unistd.h>
11 5e11c00c 2021-03-02 op
12 35e1f40a 2021-03-14 op struct event netev, fsev;
13 5e11c00c 2021-03-02 op struct tabshead tabshead;
14 984245ce 2021-06-23 op struct proxylist proxies;
15 5e11c00c 2021-03-02 op
16 c07ac996 2021-03-12 op /* the first is also the fallback one */
17 c07ac996 2021-03-12 op static struct proto protos[] = {
18 31f1a758 2021-04-22 op { "gemini", load_gemini_url },
19 31f1a758 2021-04-22 op { "about", load_about_url },
20 4d3785b1 2021-03-09 op { NULL, NULL },
21 4d3785b1 2021-03-09 op };
22 4d3785b1 2021-03-09 op
23 35e1f40a 2021-03-14 op static struct imsgbuf *netibuf, *fsibuf;
24 5e11c00c 2021-03-02 op
25 2051e653 2021-03-13 op static void die(void) __attribute__((__noreturn__));
26 2051e653 2021-03-13 op static struct tab *tab_by_id(uint32_t);
27 2051e653 2021-03-13 op static void handle_imsg_err(struct imsg*, size_t);
28 2051e653 2021-03-13 op static void handle_imsg_check_cert(struct imsg*, size_t);
29 b3575139 2021-04-01 op static void handle_check_cert_user_choice(int, unsigned int);
30 288fd238 2021-04-25 op static void handle_maybe_save_new_cert(int, unsigned int);
31 2051e653 2021-03-13 op static void handle_imsg_got_code(struct imsg*, size_t);
32 2051e653 2021-03-13 op static void handle_imsg_got_meta(struct imsg*, size_t);
33 de2a69bb 2021-05-17 op static void handle_maybe_save_page(int, unsigned int);
34 de2a69bb 2021-05-17 op static void handle_save_page_path(const char *, unsigned int);
35 de2a69bb 2021-05-17 op static void handle_imsg_file_opened(struct imsg*, size_t);
36 2051e653 2021-03-13 op static void handle_imsg_buf(struct imsg*, size_t);
37 2051e653 2021-03-13 op static void handle_imsg_eof(struct imsg*, size_t);
38 740f578b 2021-03-15 op static void handle_imsg_bookmark_ok(struct imsg*, size_t);
39 3a227e9a 2021-03-18 op static void handle_imsg_save_cert_ok(struct imsg*, size_t);
40 288fd238 2021-04-25 op static void handle_imsg_update_cert_ok(struct imsg *, size_t);
41 1304bbdd 2021-03-15 op static void handle_dispatch_imsg(int, short, void*);
42 2051e653 2021-03-13 op static void load_page_from_str(struct tab*, const char*);
43 2051e653 2021-03-13 op static void do_load_url(struct tab*, const char*);
44 5e11c00c 2021-03-02 op
45 5e11c00c 2021-03-02 op static imsg_handlerfn *handlers[] = {
46 5e11c00c 2021-03-02 op [IMSG_ERR] = handle_imsg_err,
47 5e11c00c 2021-03-02 op [IMSG_CHECK_CERT] = handle_imsg_check_cert,
48 5e11c00c 2021-03-02 op [IMSG_GOT_CODE] = handle_imsg_got_code,
49 5e11c00c 2021-03-02 op [IMSG_GOT_META] = handle_imsg_got_meta,
50 5e11c00c 2021-03-02 op [IMSG_BUF] = handle_imsg_buf,
51 5e11c00c 2021-03-02 op [IMSG_EOF] = handle_imsg_eof,
52 740f578b 2021-03-15 op [IMSG_BOOKMARK_OK] = handle_imsg_bookmark_ok,
53 3a227e9a 2021-03-18 op [IMSG_SAVE_CERT_OK] = handle_imsg_save_cert_ok,
54 288fd238 2021-04-25 op [IMSG_UPDATE_CERT_OK] = handle_imsg_update_cert_ok,
55 de2a69bb 2021-05-17 op [IMSG_FILE_OPENED] = handle_imsg_file_opened,
56 5e11c00c 2021-03-02 op };
57 5e11c00c 2021-03-02 op
58 cbcc75fb 2021-03-17 op static struct ohash certs;
59 cbcc75fb 2021-03-17 op
60 5e11c00c 2021-03-02 op static void __attribute__((__noreturn__))
61 5e11c00c 2021-03-02 op die(void)
62 5e11c00c 2021-03-02 op {
63 5e11c00c 2021-03-02 op abort(); /* TODO */
64 5e11c00c 2021-03-02 op }
65 5e11c00c 2021-03-02 op
66 5e11c00c 2021-03-02 op static struct tab *
67 5e11c00c 2021-03-02 op tab_by_id(uint32_t id)
68 5e11c00c 2021-03-02 op {
69 5e11c00c 2021-03-02 op struct tab *t;
70 5e11c00c 2021-03-02 op
71 5e11c00c 2021-03-02 op TAILQ_FOREACH(t, &tabshead, tabs) {
72 5e11c00c 2021-03-02 op if (t->id == id)
73 5e11c00c 2021-03-02 op return t;
74 5e11c00c 2021-03-02 op }
75 5e11c00c 2021-03-02 op
76 5e11c00c 2021-03-02 op die();
77 5e11c00c 2021-03-02 op }
78 5e11c00c 2021-03-02 op
79 5e11c00c 2021-03-02 op static void
80 5e11c00c 2021-03-02 op handle_imsg_err(struct imsg *imsg, size_t datalen)
81 5e11c00c 2021-03-02 op {
82 3a9b9365 2021-03-09 op struct tab *tab;
83 3a9b9365 2021-03-09 op char *page;
84 3a9b9365 2021-03-09 op
85 3a9b9365 2021-03-09 op tab = tab_by_id(imsg->hdr.peerid);
86 3a9b9365 2021-03-09 op
87 3a9b9365 2021-03-09 op page = imsg->data;
88 3a9b9365 2021-03-09 op page[datalen-1] = '\0';
89 3a9b9365 2021-03-09 op
90 3a9b9365 2021-03-09 op if (asprintf(&page, "# Error loading %s\n\n> %s\n",
91 2051e653 2021-03-13 op tab->hist_cur->h, page) == -1)
92 3a9b9365 2021-03-09 op die();
93 3a9b9365 2021-03-09 op load_page_from_str(tab, page);
94 3a9b9365 2021-03-09 op free(page);
95 5e11c00c 2021-03-02 op }
96 5e11c00c 2021-03-02 op
97 5e11c00c 2021-03-02 op static void
98 5e11c00c 2021-03-02 op handle_imsg_check_cert(struct imsg *imsg, size_t datalen)
99 5e11c00c 2021-03-02 op {
100 984245ce 2021-06-23 op const char *hash, *host, *port;
101 cbcc75fb 2021-03-17 op int tofu_res;
102 cbcc75fb 2021-03-17 op struct tofu_entry *e;
103 cbcc75fb 2021-03-17 op struct tab *tab;
104 5e11c00c 2021-03-02 op
105 cbcc75fb 2021-03-17 op hash = imsg->data;
106 cbcc75fb 2021-03-17 op if (hash[datalen-1] != '\0')
107 cbcc75fb 2021-03-17 op abort();
108 cbcc75fb 2021-03-17 op
109 10346511 2021-03-17 op tab = tab_by_id(imsg->hdr.peerid);
110 cbcc75fb 2021-03-17 op
111 984245ce 2021-06-23 op if (tab->proxy != NULL) {
112 984245ce 2021-06-23 op host = tab->proxy->host;
113 984245ce 2021-06-23 op port = tab->proxy->port;
114 984245ce 2021-06-23 op } else {
115 984245ce 2021-06-23 op host = tab->uri.host;
116 984245ce 2021-06-23 op port = tab->uri.port;
117 984245ce 2021-06-23 op }
118 984245ce 2021-06-23 op
119 984245ce 2021-06-23 op if ((e = tofu_lookup(&certs, host, port)) == NULL) {
120 cbcc75fb 2021-03-17 op /* TODO: an update in libressl/libretls changed
121 cbcc75fb 2021-03-17 op * significantly. Find a better approach at storing
122 cbcc75fb 2021-03-17 op * the certs! */
123 cbcc75fb 2021-03-17 op if (datalen > sizeof(e->hash))
124 cbcc75fb 2021-03-17 op abort();
125 cbcc75fb 2021-03-17 op
126 cbcc75fb 2021-03-17 op tofu_res = 1; /* trust on first use */
127 cbcc75fb 2021-03-17 op if ((e = calloc(1, sizeof(*e))) == NULL)
128 cbcc75fb 2021-03-17 op abort();
129 984245ce 2021-06-23 op strlcpy(e->domain, host, sizeof(e->domain));
130 984245ce 2021-06-23 op if (*port != '\0' && strcmp(port, "1965")) {
131 eb4388ee 2021-04-25 op strlcat(e->domain, ":", sizeof(e->domain));
132 984245ce 2021-06-23 op strlcat(e->domain, port, sizeof(e->domain));
133 eb4388ee 2021-04-25 op }
134 cbcc75fb 2021-03-17 op strlcpy(e->hash, hash, sizeof(e->hash));
135 3768e50f 2021-04-25 op tofu_add(&certs, e);
136 3a227e9a 2021-03-18 op imsg_compose(fsibuf, IMSG_SAVE_CERT, tab->id, 0, -1,
137 3a227e9a 2021-03-18 op e, sizeof(*e));
138 3a227e9a 2021-03-18 op imsg_flush(fsibuf);
139 cbcc75fb 2021-03-17 op } else
140 cbcc75fb 2021-03-17 op tofu_res = !strcmp(hash, e->hash);
141 cbcc75fb 2021-03-17 op
142 5d1bac73 2021-03-25 op if (tofu_res) {
143 cbcc75fb 2021-03-17 op tab->trust = e->verified ? TS_VERIFIED : TS_TRUSTED;
144 5d1bac73 2021-03-25 op imsg_compose(netibuf, IMSG_CERT_STATUS, imsg->hdr.peerid, 0, -1,
145 5d1bac73 2021-03-25 op &tofu_res, sizeof(tofu_res));
146 5d1bac73 2021-03-25 op imsg_flush(netibuf);
147 5d1bac73 2021-03-25 op } else {
148 cbcc75fb 2021-03-17 op tab->trust = TS_UNTRUSTED;
149 cbcc75fb 2021-03-17 op load_page_from_str(tab, "# Certificate mismatch\n");
150 288fd238 2021-04-25 op if ((tab->cert = strdup(hash)) == NULL)
151 288fd238 2021-04-25 op die();
152 5d1bac73 2021-03-25 op ui_yornp("Certificate mismatch. Proceed?",
153 b3575139 2021-04-01 op handle_check_cert_user_choice, tab->id);
154 cbcc75fb 2021-03-17 op }
155 5d1bac73 2021-03-25 op }
156 5d1bac73 2021-03-25 op
157 5d1bac73 2021-03-25 op static void
158 b3575139 2021-04-01 op handle_check_cert_user_choice(int accept, unsigned int tabid)
159 5d1bac73 2021-03-25 op {
160 288fd238 2021-04-25 op struct tab *tab;
161 288fd238 2021-04-25 op
162 288fd238 2021-04-25 op tab = tab_by_id(tabid);
163 288fd238 2021-04-25 op
164 5d1bac73 2021-03-25 op imsg_compose(netibuf, IMSG_CERT_STATUS, tabid, 0, -1,
165 5d1bac73 2021-03-25 op &accept, sizeof(accept));
166 1b8a4bbf 2021-03-12 op imsg_flush(netibuf);
167 288fd238 2021-04-25 op
168 288fd238 2021-04-25 op if (accept)
169 288fd238 2021-04-25 op ui_yornp("Save the new certificate?",
170 288fd238 2021-04-25 op handle_maybe_save_new_cert, tabid);
171 288fd238 2021-04-25 op else {
172 288fd238 2021-04-25 op free(tab->cert);
173 288fd238 2021-04-25 op tab->cert = NULL;
174 288fd238 2021-04-25 op }
175 5e11c00c 2021-03-02 op }
176 5e11c00c 2021-03-02 op
177 288fd238 2021-04-25 op static void
178 288fd238 2021-04-25 op handle_maybe_save_new_cert(int accept, unsigned int tabid)
179 288fd238 2021-04-25 op {
180 288fd238 2021-04-25 op struct tab *tab;
181 288fd238 2021-04-25 op struct tofu_entry *e;
182 984245ce 2021-06-23 op const char *host, *port;
183 288fd238 2021-04-25 op
184 288fd238 2021-04-25 op tab = tab_by_id(tabid);
185 288fd238 2021-04-25 op
186 984245ce 2021-06-23 op if (tab->proxy != NULL) {
187 984245ce 2021-06-23 op host = tab->proxy->host;
188 984245ce 2021-06-23 op port = tab->proxy->port;
189 984245ce 2021-06-23 op } else {
190 984245ce 2021-06-23 op host = tab->uri.host;
191 984245ce 2021-06-23 op port = tab->uri.port;
192 984245ce 2021-06-23 op }
193 984245ce 2021-06-23 op
194 288fd238 2021-04-25 op if (!accept)
195 288fd238 2021-04-25 op goto end;
196 288fd238 2021-04-25 op
197 fe2262ad 2021-05-12 op if ((e = calloc(1, sizeof(*e))) == NULL)
198 288fd238 2021-04-25 op die();
199 288fd238 2021-04-25 op
200 984245ce 2021-06-23 op strlcpy(e->domain, host, sizeof(e->domain));
201 984245ce 2021-06-23 op if (*port != '\0' && strcmp(port, "1965")) {
202 288fd238 2021-04-25 op strlcat(e->domain, ":", sizeof(e->domain));
203 984245ce 2021-06-23 op strlcat(e->domain, port, sizeof(e->domain));
204 288fd238 2021-04-25 op }
205 288fd238 2021-04-25 op strlcpy(e->hash, tab->cert, sizeof(e->hash));
206 288fd238 2021-04-25 op imsg_compose(fsibuf, IMSG_UPDATE_CERT, 0, 0, -1, e, sizeof(*e));
207 288fd238 2021-04-25 op imsg_flush(fsibuf);
208 288fd238 2021-04-25 op
209 288fd238 2021-04-25 op tofu_update(&certs, e);
210 288fd238 2021-04-25 op
211 288fd238 2021-04-25 op tab->trust = TS_TRUSTED;
212 288fd238 2021-04-25 op
213 288fd238 2021-04-25 op end:
214 288fd238 2021-04-25 op free(tab->cert);
215 288fd238 2021-04-25 op tab->cert = NULL;
216 288fd238 2021-04-25 op }
217 288fd238 2021-04-25 op
218 5cd2ebb1 2021-03-11 op static inline int
219 5cd2ebb1 2021-03-11 op normalize_code(int n)
220 5cd2ebb1 2021-03-11 op {
221 5cd2ebb1 2021-03-11 op if (n < 20) {
222 5cd2ebb1 2021-03-11 op if (n == 10 || n == 11)
223 5cd2ebb1 2021-03-11 op return n;
224 5cd2ebb1 2021-03-11 op return 10;
225 5cd2ebb1 2021-03-11 op } else if (n < 30) {
226 5cd2ebb1 2021-03-11 op return 20;
227 5cd2ebb1 2021-03-11 op } else if (n < 40) {
228 5cd2ebb1 2021-03-11 op if (n == 30 || n == 31)
229 5cd2ebb1 2021-03-11 op return n;
230 5cd2ebb1 2021-03-11 op return 30;
231 5cd2ebb1 2021-03-11 op } else if (n < 50) {
232 5cd2ebb1 2021-03-11 op if (n <= 44)
233 5cd2ebb1 2021-03-11 op return n;
234 5cd2ebb1 2021-03-11 op return 40;
235 5cd2ebb1 2021-03-11 op } else if (n < 60) {
236 5cd2ebb1 2021-03-11 op if (n <= 53 || n == 59)
237 5cd2ebb1 2021-03-11 op return n;
238 5cd2ebb1 2021-03-11 op return 50;
239 5cd2ebb1 2021-03-11 op } else if (n < 70) {
240 5cd2ebb1 2021-03-11 op if (n <= 62)
241 5cd2ebb1 2021-03-11 op return n;
242 5cd2ebb1 2021-03-11 op return 60;
243 5cd2ebb1 2021-03-11 op } else
244 5cd2ebb1 2021-03-11 op return MALFORMED_RESPONSE;
245 5cd2ebb1 2021-03-11 op }
246 5cd2ebb1 2021-03-11 op
247 5e11c00c 2021-03-02 op static void
248 5e11c00c 2021-03-02 op handle_imsg_got_code(struct imsg *imsg, size_t datalen)
249 5e11c00c 2021-03-02 op {
250 0972d8b2 2021-03-02 op struct tab *tab;
251 5e11c00c 2021-03-02 op
252 0972d8b2 2021-03-02 op tab = tab_by_id(imsg->hdr.peerid);
253 0972d8b2 2021-03-02 op
254 0972d8b2 2021-03-02 op if (sizeof(tab->code) != datalen)
255 5e11c00c 2021-03-02 op die();
256 5e11c00c 2021-03-02 op
257 5cd2ebb1 2021-03-11 op memcpy(&tab->code, imsg->data, sizeof(tab->code));
258 5cd2ebb1 2021-03-11 op tab->code = normalize_code(tab->code);
259 5cd2ebb1 2021-03-11 op if (tab->code != 30 && tab->code != 31)
260 0972d8b2 2021-03-02 op tab->redirect_count = 0;
261 5e11c00c 2021-03-02 op }
262 5e11c00c 2021-03-02 op
263 5e11c00c 2021-03-02 op static void
264 5e11c00c 2021-03-02 op handle_imsg_got_meta(struct imsg *imsg, size_t datalen)
265 5e11c00c 2021-03-02 op {
266 0972d8b2 2021-03-02 op struct tab *tab;
267 0972d8b2 2021-03-02 op
268 0972d8b2 2021-03-02 op tab = tab_by_id(imsg->hdr.peerid);
269 0972d8b2 2021-03-02 op
270 0972d8b2 2021-03-02 op if (sizeof(tab->meta) <= datalen)
271 0972d8b2 2021-03-02 op die();
272 5cd2ebb1 2021-03-11 op
273 0972d8b2 2021-03-02 op memcpy(tab->meta, imsg->data, datalen);
274 0972d8b2 2021-03-02 op
275 5cd2ebb1 2021-03-11 op if (tab->code < 10) { /* internal errors */
276 5cd2ebb1 2021-03-11 op load_page_from_str(tab, err_pages[tab->code]);
277 5cd2ebb1 2021-03-11 op } else if (tab->code < 20) { /* 1x */
278 5cd2ebb1 2021-03-11 op load_page_from_str(tab, err_pages[tab->code]);
279 5cd2ebb1 2021-03-11 op ui_require_input(tab, tab->code == 11);
280 5cd2ebb1 2021-03-11 op } else if (tab->code == 20) {
281 c07ac996 2021-03-12 op if (setup_parser_for(tab)) {
282 1b8a4bbf 2021-03-12 op imsg_compose(netibuf, IMSG_PROCEED, tab->id, 0, -1, NULL, 0);
283 1b8a4bbf 2021-03-12 op imsg_flush(netibuf);
284 c07ac996 2021-03-12 op } else {
285 c07ac996 2021-03-12 op load_page_from_str(tab, err_pages[UNKNOWN_TYPE_OR_CSET]);
286 de2a69bb 2021-05-17 op ui_yornp("Can't display page, wanna save?",
287 de2a69bb 2021-05-17 op handle_maybe_save_page, tab->id);
288 c07ac996 2021-03-12 op }
289 5cd2ebb1 2021-03-11 op } else if (tab->code < 40) { /* 3x */
290 3a9b9365 2021-03-09 op tab->redirect_count++;
291 0972d8b2 2021-03-02 op
292 3a9b9365 2021-03-09 op /* TODO: make customizable? */
293 3a9b9365 2021-03-09 op if (tab->redirect_count > 5) {
294 3a9b9365 2021-03-09 op load_page_from_str(tab,
295 3a9b9365 2021-03-09 op err_pages[TOO_MUCH_REDIRECTS]);
296 5cd2ebb1 2021-03-11 op } else
297 2051e653 2021-03-13 op do_load_url(tab, tab->meta);
298 5cd2ebb1 2021-03-11 op } else { /* 4x, 5x & 6x */
299 5cd2ebb1 2021-03-11 op load_page_from_str(tab, err_pages[tab->code]);
300 3a9b9365 2021-03-09 op }
301 de2a69bb 2021-05-17 op }
302 de2a69bb 2021-05-17 op
303 de2a69bb 2021-05-17 op static void
304 de2a69bb 2021-05-17 op handle_maybe_save_page(int dosave, unsigned int tabid)
305 de2a69bb 2021-05-17 op {
306 de2a69bb 2021-05-17 op if (dosave)
307 de2a69bb 2021-05-17 op ui_read("Save to path", handle_save_page_path, tabid);
308 de2a69bb 2021-05-17 op else
309 de2a69bb 2021-05-17 op stop_tab(tab_by_id(tabid));
310 de2a69bb 2021-05-17 op }
311 de2a69bb 2021-05-17 op
312 de2a69bb 2021-05-17 op static void
313 de2a69bb 2021-05-17 op handle_save_page_path(const char *path, unsigned int tabid)
314 de2a69bb 2021-05-17 op {
315 de2a69bb 2021-05-17 op struct tab *tab;
316 de2a69bb 2021-05-17 op
317 de2a69bb 2021-05-17 op if (path == NULL) {
318 de2a69bb 2021-05-17 op stop_tab(tab_by_id(tabid));
319 de2a69bb 2021-05-17 op return;
320 de2a69bb 2021-05-17 op }
321 de2a69bb 2021-05-17 op
322 de2a69bb 2021-05-17 op tab = tab_by_id(tabid);
323 de2a69bb 2021-05-17 op tab->path = strdup(path);
324 de2a69bb 2021-05-17 op
325 de2a69bb 2021-05-17 op imsg_compose(fsibuf, IMSG_FILE_OPEN, tabid, 0, -1, path, strlen(path)+1);
326 de2a69bb 2021-05-17 op imsg_flush(fsibuf);
327 5e11c00c 2021-03-02 op }
328 5e11c00c 2021-03-02 op
329 5e11c00c 2021-03-02 op static void
330 de2a69bb 2021-05-17 op handle_imsg_file_opened(struct imsg *imsg, size_t datalen)
331 de2a69bb 2021-05-17 op {
332 de2a69bb 2021-05-17 op struct tab *tab;
333 de2a69bb 2021-05-17 op char *page;
334 de2a69bb 2021-05-17 op const char *e;
335 de2a69bb 2021-05-17 op int l;
336 de2a69bb 2021-05-17 op
337 de2a69bb 2021-05-17 op tab = tab_by_id(imsg->hdr.peerid);
338 de2a69bb 2021-05-17 op
339 de2a69bb 2021-05-17 op if (imsg->fd == -1) {
340 de2a69bb 2021-05-17 op stop_tab(tab);
341 de2a69bb 2021-05-17 op
342 de2a69bb 2021-05-17 op e = imsg->data;
343 de2a69bb 2021-05-17 op if (e[datalen-1] != '\0')
344 de2a69bb 2021-05-17 op die();
345 de2a69bb 2021-05-17 op l = asprintf(&page, "# Can't open file\n\n> %s: %s\n",
346 de2a69bb 2021-05-17 op tab->path, e);
347 de2a69bb 2021-05-17 op if (l == -1)
348 de2a69bb 2021-05-17 op die();
349 de2a69bb 2021-05-17 op load_page_from_str(tab, page);
350 de2a69bb 2021-05-17 op free(page);
351 de2a69bb 2021-05-17 op } else {
352 de2a69bb 2021-05-17 op tab->fd = imsg->fd;
353 de2a69bb 2021-05-17 op imsg_compose(netibuf, IMSG_PROCEED, tab->id, 0, -1, NULL, 0);
354 de2a69bb 2021-05-17 op imsg_flush(netibuf);
355 de2a69bb 2021-05-17 op }
356 de2a69bb 2021-05-17 op }
357 de2a69bb 2021-05-17 op
358 de2a69bb 2021-05-17 op static void
359 5e11c00c 2021-03-02 op handle_imsg_buf(struct imsg *imsg, size_t datalen)
360 5e11c00c 2021-03-02 op {
361 0972d8b2 2021-03-02 op struct tab *tab;
362 de2a69bb 2021-05-17 op int l;
363 0e1eff5b 2021-06-23 op char *page, buf[FMT_SCALED_STRSIZE] = {0};
364 5e11c00c 2021-03-02 op
365 0972d8b2 2021-03-02 op tab = tab_by_id(imsg->hdr.peerid);
366 5e11c00c 2021-03-02 op
367 de2a69bb 2021-05-17 op tab->bytes += datalen;
368 de2a69bb 2021-05-17 op if (tab->fd == -1) {
369 46f6e974 2021-05-17 op if (!tab->buffer.page.parse(&tab->buffer.page,
370 de2a69bb 2021-05-17 op imsg->data, datalen))
371 de2a69bb 2021-05-17 op die();
372 de2a69bb 2021-05-17 op } else {
373 de2a69bb 2021-05-17 op write(tab->fd, imsg->data, datalen);
374 0e1eff5b 2021-06-23 op fmt_scaled(tab->bytes, buf);
375 0e1eff5b 2021-06-23 op l = asprintf(&page, "Saving to \"%s\"... (%s)\n",
376 de2a69bb 2021-05-17 op tab->path,
377 0e1eff5b 2021-06-23 op buf);
378 de2a69bb 2021-05-17 op if (l == -1)
379 de2a69bb 2021-05-17 op die();
380 de2a69bb 2021-05-17 op load_page_from_str(tab, page);
381 de2a69bb 2021-05-17 op free(page);
382 de2a69bb 2021-05-17 op }
383 5e11c00c 2021-03-02 op
384 0972d8b2 2021-03-02 op ui_on_tab_refresh(tab);
385 5e11c00c 2021-03-02 op }
386 5e11c00c 2021-03-02 op
387 5e11c00c 2021-03-02 op static void
388 5e11c00c 2021-03-02 op handle_imsg_eof(struct imsg *imsg, size_t datalen)
389 5e11c00c 2021-03-02 op {
390 2ba66cea 2021-03-22 op struct tab *tab;
391 de2a69bb 2021-05-17 op int l;
392 0e1eff5b 2021-06-23 op char *page, buf[FMT_SCALED_STRSIZE] = {0};
393 a5c3e03d 2021-03-02 op
394 2ba66cea 2021-03-22 op tab = tab_by_id(imsg->hdr.peerid);
395 de2a69bb 2021-05-17 op
396 de2a69bb 2021-05-17 op if (tab->fd == -1) {
397 46f6e974 2021-05-17 op if (!tab->buffer.page.free(&tab->buffer.page))
398 de2a69bb 2021-05-17 op die();
399 de2a69bb 2021-05-17 op } else {
400 0e1eff5b 2021-06-23 op fmt_scaled(tab->bytes, buf);
401 0e1eff5b 2021-06-23 op l = asprintf(&page, "Saved to \"%s\" (%s)\n",
402 de2a69bb 2021-05-17 op tab->path,
403 0e1eff5b 2021-06-23 op buf);
404 de2a69bb 2021-05-17 op if (l == -1)
405 de2a69bb 2021-05-17 op die();
406 de2a69bb 2021-05-17 op load_page_from_str(tab, page);
407 de2a69bb 2021-05-17 op free(page);
408 a5c3e03d 2021-03-02 op
409 de2a69bb 2021-05-17 op close(tab->fd);
410 de2a69bb 2021-05-17 op tab->fd = -1;
411 de2a69bb 2021-05-17 op free(tab->path);
412 de2a69bb 2021-05-17 op tab->path = NULL;
413 de2a69bb 2021-05-17 op }
414 de2a69bb 2021-05-17 op
415 2ba66cea 2021-03-22 op ui_on_tab_refresh(tab);
416 2ba66cea 2021-03-22 op ui_on_tab_loaded(tab);
417 5e11c00c 2021-03-02 op }
418 5e11c00c 2021-03-02 op
419 5e11c00c 2021-03-02 op static void
420 740f578b 2021-03-15 op handle_imsg_bookmark_ok(struct imsg *imsg, size_t datalen)
421 740f578b 2021-03-15 op {
422 740f578b 2021-03-15 op int res;
423 740f578b 2021-03-15 op
424 740f578b 2021-03-15 op if (datalen != sizeof(res))
425 740f578b 2021-03-15 op die();
426 740f578b 2021-03-15 op
427 740f578b 2021-03-15 op memcpy(&res, imsg->data, sizeof(res));
428 740f578b 2021-03-15 op if (res == 0)
429 7f963c41 2021-06-20 op message("Added to bookmarks!");
430 740f578b 2021-03-15 op else
431 7f963c41 2021-06-20 op message("Failed to add to bookmarks: %s",
432 740f578b 2021-03-15 op strerror(res));
433 740f578b 2021-03-15 op }
434 740f578b 2021-03-15 op
435 740f578b 2021-03-15 op static void
436 3a227e9a 2021-03-18 op handle_imsg_save_cert_ok(struct imsg *imsg, size_t datalen)
437 3a227e9a 2021-03-18 op {
438 3a227e9a 2021-03-18 op int res;
439 3a227e9a 2021-03-18 op
440 3a227e9a 2021-03-18 op if (datalen != sizeof(res))
441 3a227e9a 2021-03-18 op die();
442 3a227e9a 2021-03-18 op memcpy(&res, imsg->data, datalen);
443 3a227e9a 2021-03-18 op if (res != 0)
444 7f963c41 2021-06-20 op message("Failed to save the cert for: %s",
445 3a227e9a 2021-03-18 op strerror(res));
446 288fd238 2021-04-25 op }
447 288fd238 2021-04-25 op
448 288fd238 2021-04-25 op static void
449 288fd238 2021-04-25 op handle_imsg_update_cert_ok(struct imsg *imsg, size_t datalen)
450 288fd238 2021-04-25 op {
451 288fd238 2021-04-25 op int res;
452 288fd238 2021-04-25 op
453 288fd238 2021-04-25 op if (datalen != sizeof(res))
454 288fd238 2021-04-25 op die();
455 288fd238 2021-04-25 op memcpy(&res, imsg->data, datalen);
456 288fd238 2021-04-25 op if (!res)
457 7f963c41 2021-06-20 op message("Failed to update the certificate");
458 3a227e9a 2021-03-18 op }
459 3a227e9a 2021-03-18 op
460 3a227e9a 2021-03-18 op static void
461 1304bbdd 2021-03-15 op handle_dispatch_imsg(int fd, short ev, void *d)
462 5e11c00c 2021-03-02 op {
463 35e1f40a 2021-03-14 op struct imsgbuf *ibuf = d;
464 1304bbdd 2021-03-15 op dispatch_imsg(ibuf, handlers, sizeof(handlers));
465 5e11c00c 2021-03-02 op }
466 5e11c00c 2021-03-02 op
467 0972d8b2 2021-03-02 op static void
468 0972d8b2 2021-03-02 op load_page_from_str(struct tab *tab, const char *page)
469 0972d8b2 2021-03-02 op {
470 46f6e974 2021-05-17 op gemtext_initparser(&tab->buffer.page);
471 46f6e974 2021-05-17 op if (!tab->buffer.page.parse(&tab->buffer.page, page, strlen(page)))
472 0972d8b2 2021-03-02 op die();
473 46f6e974 2021-05-17 op if (!tab->buffer.page.free(&tab->buffer.page))
474 0972d8b2 2021-03-02 op die();
475 0972d8b2 2021-03-02 op ui_on_tab_refresh(tab);
476 8af5e5ed 2021-03-08 op ui_on_tab_loaded(tab);
477 0972d8b2 2021-03-02 op }
478 0972d8b2 2021-03-02 op
479 bcb0b073 2021-03-07 op void
480 4d3785b1 2021-03-09 op load_about_url(struct tab *tab, const char *url)
481 0972d8b2 2021-03-02 op {
482 10346511 2021-03-17 op tab->trust = TS_VERIFIED;
483 2051e653 2021-03-13 op
484 46f6e974 2021-05-17 op gemtext_initparser(&tab->buffer.page);
485 35e1f40a 2021-03-14 op
486 35e1f40a 2021-03-14 op imsg_compose(fsibuf, IMSG_GET, tab->id, 0, -1,
487 31f1a758 2021-04-22 op tab->hist_cur->h, strlen(tab->hist_cur->h)+1);
488 35e1f40a 2021-03-14 op imsg_flush(fsibuf);
489 4d3785b1 2021-03-09 op }
490 0972d8b2 2021-03-02 op
491 4d3785b1 2021-03-09 op void
492 4d3785b1 2021-03-09 op load_gemini_url(struct tab *tab, const char *url)
493 4d3785b1 2021-03-09 op {
494 984245ce 2021-06-23 op struct get_req req;
495 754622a2 2021-03-15 op
496 2eef3403 2021-04-22 op stop_tab(tab);
497 2eef3403 2021-04-22 op tab->id = tab_new_id();
498 2eef3403 2021-04-22 op
499 984245ce 2021-06-23 op memset(&req, 0, sizeof(req));
500 984245ce 2021-06-23 op strlcpy(req.host, tab->uri.host, sizeof(req.host));
501 984245ce 2021-06-23 op strlcpy(req.port, tab->uri.port, sizeof(req.host));
502 984245ce 2021-06-23 op
503 984245ce 2021-06-23 op strlcpy(req.req, tab->hist_cur->h, sizeof(req.req));
504 984245ce 2021-06-23 op strlcat(req.req, "\r\n", sizeof(req.req));
505 984245ce 2021-06-23 op
506 984245ce 2021-06-23 op req.proto = PROTO_GEMINI;
507 984245ce 2021-06-23 op
508 984245ce 2021-06-23 op imsg_compose(netibuf, IMSG_GET_RAW, tab->id, 0, -1,
509 984245ce 2021-06-23 op &req, sizeof(req));
510 1b8a4bbf 2021-03-12 op imsg_flush(netibuf);
511 0972d8b2 2021-03-02 op }
512 0972d8b2 2021-03-02 op
513 984245ce 2021-06-23 op void
514 984245ce 2021-06-23 op load_via_proxy(struct tab *tab, const char *url, struct proxy *p)
515 984245ce 2021-06-23 op {
516 984245ce 2021-06-23 op struct get_req req;
517 984245ce 2021-06-23 op
518 984245ce 2021-06-23 op stop_tab(tab);
519 984245ce 2021-06-23 op tab->id = tab_new_id();
520 984245ce 2021-06-23 op tab->proxy = p;
521 984245ce 2021-06-23 op
522 984245ce 2021-06-23 op memset(&req, 0, sizeof(req));
523 984245ce 2021-06-23 op strlcpy(req.host, p->host, sizeof(req.host));
524 984245ce 2021-06-23 op strlcpy(req.port, p->port, sizeof(req.host));
525 984245ce 2021-06-23 op
526 984245ce 2021-06-23 op strlcpy(req.req, tab->hist_cur->h, sizeof(req.req));
527 984245ce 2021-06-23 op strlcat(req.req, "\r\n", sizeof(req.req));
528 984245ce 2021-06-23 op
529 984245ce 2021-06-23 op req.proto = p->proto;
530 984245ce 2021-06-23 op
531 984245ce 2021-06-23 op imsg_compose(netibuf, IMSG_GET_RAW, tab->id, 0, -1,
532 984245ce 2021-06-23 op &req, sizeof(req));
533 984245ce 2021-06-23 op imsg_flush(netibuf);
534 984245ce 2021-06-23 op }
535 984245ce 2021-06-23 op
536 2051e653 2021-03-13 op static void
537 2051e653 2021-03-13 op do_load_url(struct tab *tab, const char *url)
538 4d3785b1 2021-03-09 op {
539 31f1a758 2021-04-22 op struct phos_uri uri;
540 31f1a758 2021-04-22 op struct proto *p;
541 984245ce 2021-06-23 op struct proxy *proxy;
542 31f1a758 2021-04-22 op char *t;
543 de2a69bb 2021-05-17 op
544 de2a69bb 2021-05-17 op if (tab->fd != -1) {
545 de2a69bb 2021-05-17 op close(tab->fd);
546 de2a69bb 2021-05-17 op tab->fd = -1;
547 de2a69bb 2021-05-17 op free(tab->path);
548 de2a69bb 2021-05-17 op tab->path = NULL;
549 de2a69bb 2021-05-17 op }
550 4d3785b1 2021-03-09 op
551 10346511 2021-03-17 op tab->trust = TS_UNKNOWN;
552 10346511 2021-03-17 op
553 31f1a758 2021-04-22 op memcpy(&uri, &tab->uri, sizeof(tab->uri));
554 31f1a758 2021-04-22 op if (!phos_resolve_uri_from_str(&uri, url, &tab->uri)) {
555 31f1a758 2021-04-22 op if (asprintf(&t, "#error loading %s\n>%s\n",
556 31f1a758 2021-04-22 op url, "Can't parse the URI") == -1)
557 31f1a758 2021-04-22 op die();
558 31f1a758 2021-04-22 op strlcpy(tab->hist_cur->h, url, sizeof(tab->hist_cur->h));
559 31f1a758 2021-04-22 op load_page_from_str(tab, t);
560 31f1a758 2021-04-22 op free(t);
561 31f1a758 2021-04-22 op return;
562 31f1a758 2021-04-22 op }
563 31f1a758 2021-04-22 op
564 31f1a758 2021-04-22 op phos_serialize_uri(&tab->uri, tab->hist_cur->h,
565 31f1a758 2021-04-22 op sizeof(tab->hist_cur->h));
566 31f1a758 2021-04-22 op
567 4d3785b1 2021-03-09 op for (p = protos; p->schema != NULL; ++p) {
568 ed383cf4 2021-04-22 op if (!strcmp(tab->uri.scheme, p->schema)) {
569 4d3785b1 2021-03-09 op p->loadfn(tab, url);
570 31f1a758 2021-04-22 op return;
571 4d3785b1 2021-03-09 op }
572 4d3785b1 2021-03-09 op }
573 4d3785b1 2021-03-09 op
574 984245ce 2021-06-23 op TAILQ_FOREACH(proxy, &proxies, proxies) {
575 984245ce 2021-06-23 op if (!strcmp(tab->uri.scheme, proxy->match_proto)) {
576 984245ce 2021-06-23 op load_via_proxy(tab, url, proxy);
577 984245ce 2021-06-23 op return;
578 984245ce 2021-06-23 op }
579 984245ce 2021-06-23 op }
580 984245ce 2021-06-23 op
581 4d3785b1 2021-03-09 op protos[0].loadfn(tab, url);
582 4d3785b1 2021-03-09 op }
583 4d3785b1 2021-03-09 op
584 9ad4627d 2021-03-10 op void
585 2051e653 2021-03-13 op load_url(struct tab *tab, const char *url)
586 2051e653 2021-03-13 op {
587 2051e653 2021-03-13 op if (tab->hist_cur != NULL)
588 2051e653 2021-03-13 op hist_clear_forward(&tab->hist, TAILQ_NEXT(tab->hist_cur, entries));
589 2051e653 2021-03-13 op
590 2051e653 2021-03-13 op if ((tab->hist_cur = calloc(1, sizeof(*tab->hist_cur))) == NULL) {
591 2051e653 2021-03-13 op event_loopbreak();
592 2051e653 2021-03-13 op return;
593 2051e653 2021-03-13 op }
594 984245ce 2021-06-23 op
595 984245ce 2021-06-23 op tab->proxy = NULL;
596 984245ce 2021-06-23 op
597 2051e653 2021-03-13 op hist_push(&tab->hist, tab->hist_cur);
598 2051e653 2021-03-13 op do_load_url(tab, url);
599 46f6e974 2021-05-17 op empty_vlist(&tab->buffer);
600 46f6e974 2021-05-17 op empty_linelist(&tab->buffer);
601 2051e653 2021-03-13 op }
602 2051e653 2021-03-13 op
603 2051e653 2021-03-13 op int
604 2051e653 2021-03-13 op load_previous_page(struct tab *tab)
605 2051e653 2021-03-13 op {
606 2051e653 2021-03-13 op struct hist *h;
607 2051e653 2021-03-13 op
608 2051e653 2021-03-13 op if ((h = TAILQ_PREV(tab->hist_cur, mhisthead, entries)) == NULL)
609 2051e653 2021-03-13 op return 0;
610 2051e653 2021-03-13 op tab->hist_cur = h;
611 2051e653 2021-03-13 op do_load_url(tab, h->h);
612 2051e653 2021-03-13 op return 1;
613 2051e653 2021-03-13 op }
614 2051e653 2021-03-13 op
615 2051e653 2021-03-13 op int
616 2051e653 2021-03-13 op load_next_page(struct tab *tab)
617 2051e653 2021-03-13 op {
618 2051e653 2021-03-13 op struct hist *h;
619 2051e653 2021-03-13 op
620 2051e653 2021-03-13 op if ((h = TAILQ_NEXT(tab->hist_cur, entries)) == NULL)
621 2051e653 2021-03-13 op return 0;
622 2051e653 2021-03-13 op tab->hist_cur = h;
623 2051e653 2021-03-13 op do_load_url(tab, h->h);
624 2051e653 2021-03-13 op return 1;
625 2051e653 2021-03-13 op }
626 2051e653 2021-03-13 op
627 2051e653 2021-03-13 op void
628 9ad4627d 2021-03-10 op stop_tab(struct tab *tab)
629 9ad4627d 2021-03-10 op {
630 1b8a4bbf 2021-03-12 op imsg_compose(netibuf, IMSG_STOP, tab->id, 0, -1, NULL, 0);
631 1b8a4bbf 2021-03-12 op imsg_flush(netibuf);
632 de2a69bb 2021-05-17 op
633 de2a69bb 2021-05-17 op if (tab->fd != -1) {
634 de2a69bb 2021-05-17 op close(tab->fd);
635 de2a69bb 2021-05-17 op tab->fd = -1;
636 de2a69bb 2021-05-17 op free(tab->path);
637 de2a69bb 2021-05-17 op tab->path = NULL;
638 de2a69bb 2021-05-17 op load_page_from_str(tab, "Stopped.\n");
639 de2a69bb 2021-05-17 op }
640 9ad4627d 2021-03-10 op }
641 9ad4627d 2021-03-10 op
642 740f578b 2021-03-15 op void
643 740f578b 2021-03-15 op add_to_bookmarks(const char *str)
644 740f578b 2021-03-15 op {
645 740f578b 2021-03-15 op imsg_compose(fsibuf, IMSG_BOOKMARK_PAGE, 0, 0, -1, str, strlen(str)+1);
646 c7107cec 2021-04-01 op imsg_flush(fsibuf);
647 c7107cec 2021-04-01 op }
648 c7107cec 2021-04-01 op
649 c7107cec 2021-04-01 op void
650 c7107cec 2021-04-01 op save_session(void)
651 c7107cec 2021-04-01 op {
652 c7107cec 2021-04-01 op struct tab *tab;
653 c7107cec 2021-04-01 op
654 c7107cec 2021-04-01 op imsg_compose(fsibuf, IMSG_SESSION_START, 0, 0, -1, NULL, 0);
655 c7107cec 2021-04-01 op imsg_flush(fsibuf);
656 c7107cec 2021-04-01 op
657 c7107cec 2021-04-01 op TAILQ_FOREACH(tab, &tabshead, tabs) {
658 c7107cec 2021-04-01 op imsg_compose(fsibuf, IMSG_SESSION_TAB, 0, 0, -1,
659 c7107cec 2021-04-01 op tab->hist_cur->h, strlen(tab->hist_cur->h)+1);
660 c7107cec 2021-04-01 op imsg_flush(fsibuf);
661 c7107cec 2021-04-01 op }
662 c7107cec 2021-04-01 op
663 c7107cec 2021-04-01 op imsg_compose(fsibuf, IMSG_SESSION_END, 0, 0, -1, NULL, 0);
664 740f578b 2021-03-15 op imsg_flush(fsibuf);
665 740f578b 2021-03-15 op }
666 740f578b 2021-03-15 op
667 5e11c00c 2021-03-02 op int
668 6cd6a9e1 2021-03-20 op main(int argc, char * const *argv)
669 5e11c00c 2021-03-02 op {
670 35e1f40a 2021-03-14 op struct imsgbuf network_ibuf, fs_ibuf;
671 35e1f40a 2021-03-14 op int net_fds[2], fs_fds[2];
672 5e11c00c 2021-03-02 op
673 5e11c00c 2021-03-02 op signal(SIGCHLD, SIG_IGN);
674 a0e91173 2021-06-13 op signal(SIGPIPE, SIG_IGN);
675 5e11c00c 2021-03-02 op
676 3a227e9a 2021-03-18 op /* initialize part of the fs layer. Before starting the UI
677 3a227e9a 2021-03-18 op * and dropping the priviledges we need to read some stuff. */
678 3a227e9a 2021-03-18 op fs_init();
679 3a227e9a 2021-03-18 op
680 35e1f40a 2021-03-14 op if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, fs_fds) == -1)
681 5e11c00c 2021-03-02 op err(1, "socketpair");
682 5e11c00c 2021-03-02 op
683 5e11c00c 2021-03-02 op switch (fork()) {
684 5e11c00c 2021-03-02 op case -1:
685 5e11c00c 2021-03-02 op err(1, "fork");
686 5e11c00c 2021-03-02 op case 0:
687 5e11c00c 2021-03-02 op /* child */
688 37d429b0 2021-04-01 op setproctitle("fs");
689 35e1f40a 2021-03-14 op close(fs_fds[0]);
690 35e1f40a 2021-03-14 op imsg_init(&fs_ibuf, fs_fds[1]);
691 35e1f40a 2021-03-14 op exit(fs_main(&fs_ibuf));
692 35e1f40a 2021-03-14 op default:
693 35e1f40a 2021-03-14 op close(fs_fds[1]);
694 35e1f40a 2021-03-14 op imsg_init(&fs_ibuf, fs_fds[0]);
695 35e1f40a 2021-03-14 op fsibuf = &fs_ibuf;
696 5e11c00c 2021-03-02 op }
697 b1d4d01b 2021-03-14 op
698 35e1f40a 2021-03-14 op if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, net_fds) == -1)
699 35e1f40a 2021-03-14 op err(1, "socketpair");
700 5e11c00c 2021-03-02 op
701 35e1f40a 2021-03-14 op switch (fork()) {
702 35e1f40a 2021-03-14 op case -1:
703 35e1f40a 2021-03-14 op err(1, "fork");
704 35e1f40a 2021-03-14 op case 0:
705 35e1f40a 2021-03-14 op /* child */
706 37d429b0 2021-04-01 op setproctitle("client");
707 35e1f40a 2021-03-14 op close(net_fds[0]);
708 35e1f40a 2021-03-14 op close(fs_fds[0]);
709 35e1f40a 2021-03-14 op imsg_init(&network_ibuf, net_fds[1]);
710 35e1f40a 2021-03-14 op exit(client_main(&network_ibuf));
711 35e1f40a 2021-03-14 op default:
712 35e1f40a 2021-03-14 op close(net_fds[1]);
713 35e1f40a 2021-03-14 op imsg_init(&network_ibuf, net_fds[0]);
714 35e1f40a 2021-03-14 op netibuf = &network_ibuf;
715 35e1f40a 2021-03-14 op }
716 5e11c00c 2021-03-02 op
717 37d429b0 2021-04-01 op setproctitle("ui");
718 35e1f40a 2021-03-14 op
719 3768e50f 2021-04-25 op tofu_init(&certs, 5, offsetof(struct tofu_entry, domain));
720 3a227e9a 2021-03-18 op load_certs(&certs);
721 cbcc75fb 2021-03-17 op
722 5e11c00c 2021-03-02 op TAILQ_INIT(&tabshead);
723 984245ce 2021-06-23 op TAILQ_INIT(&proxies);
724 5e11c00c 2021-03-02 op
725 5e11c00c 2021-03-02 op event_init();
726 5e11c00c 2021-03-02 op
727 4ad01575 2021-06-13 op event_set(&netev, netibuf->fd, EV_READ | EV_PERSIST,
728 4ad01575 2021-06-13 op handle_dispatch_imsg, netibuf);
729 35e1f40a 2021-03-14 op event_add(&netev, NULL);
730 5e11c00c 2021-03-02 op
731 4ad01575 2021-06-13 op event_set(&fsev, fsibuf->fd, EV_READ | EV_PERSIST,
732 4ad01575 2021-06-13 op handle_dispatch_imsg, fsibuf);
733 35e1f40a 2021-03-14 op event_add(&fsev, NULL);
734 35e1f40a 2021-03-14 op
735 941b3761 2021-03-18 op if (ui_init(argc, argv)) {
736 941b3761 2021-03-18 op sandbox_ui_process();
737 941b3761 2021-03-18 op event_dispatch();
738 941b3761 2021-03-18 op ui_end();
739 941b3761 2021-03-18 op }
740 5e11c00c 2021-03-02 op
741 1b8a4bbf 2021-03-12 op imsg_compose(netibuf, IMSG_QUIT, 0, 0, -1, NULL, 0);
742 1b8a4bbf 2021-03-12 op imsg_flush(netibuf);
743 5e11c00c 2021-03-02 op
744 35e1f40a 2021-03-14 op imsg_compose(fsibuf, IMSG_QUIT, 0, 0, -1, NULL, 0);
745 35e1f40a 2021-03-14 op imsg_flush(fsibuf);
746 35e1f40a 2021-03-14 op
747 5e11c00c 2021-03-02 op return 0;
748 5e11c00c 2021-03-02 op }