Blob


1 #include <sys/socket.h>
3 #include <errno.h>
4 #include <limits.h>
5 #include <signal.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <unistd.h>
11 #include "pages.h"
12 #include "parser.h"
13 #include "telescope.h"
14 #include "ui.h"
16 static struct imsgev *iev_fs, *iev_net;
18 struct tabshead tabshead = TAILQ_HEAD_INITIALIZER(tabshead);
19 struct proxylist proxies = TAILQ_HEAD_INITIALIZER(proxies);
21 enum telescope_process {
22 PROC_UI,
23 PROC_FS,
24 PROC_NET,
25 };
27 /* the first is also the fallback one */
28 static struct proto protos[] = {
29 { "gemini", load_gemini_url },
30 { "about", load_about_url },
31 { NULL, NULL },
32 };
34 static void die(void) __attribute__((__noreturn__));
35 static struct tab *tab_by_id(uint32_t);
36 static void handle_imsg_err(struct imsg*, size_t);
37 static void handle_imsg_check_cert(struct imsg*, size_t);
38 static void handle_check_cert_user_choice(int, struct tab *);
39 static void handle_maybe_save_new_cert(int, struct tab *);
40 static void handle_imsg_got_code(struct imsg*, size_t);
41 static void handle_imsg_got_meta(struct imsg*, size_t);
42 static void handle_maybe_save_page(int, struct tab *);
43 static void handle_save_page_path(const char *, unsigned int);
44 static void handle_imsg_file_opened(struct imsg*, size_t);
45 static void handle_imsg_buf(struct imsg*, size_t);
46 static void handle_imsg_eof(struct imsg*, size_t);
47 static void handle_imsg_bookmark_ok(struct imsg*, size_t);
48 static void handle_imsg_save_cert_ok(struct imsg*, size_t);
49 static void handle_imsg_update_cert_ok(struct imsg *, size_t);
50 static void handle_dispatch_imsg(int, short, void*);
51 static void load_page_from_str(struct tab*, const char*);
52 static void do_load_url(struct tab*, const char*);
53 static pid_t start_child(enum telescope_process, const char *, int);
54 static int ui_send_net(int, uint32_t, const void *, uint16_t);
55 static int ui_send_fs(int, uint32_t, const void *, uint16_t);
57 static imsg_handlerfn *handlers[] = {
58 [IMSG_ERR] = handle_imsg_err,
59 [IMSG_CHECK_CERT] = handle_imsg_check_cert,
60 [IMSG_GOT_CODE] = handle_imsg_got_code,
61 [IMSG_GOT_META] = handle_imsg_got_meta,
62 [IMSG_BUF] = handle_imsg_buf,
63 [IMSG_EOF] = handle_imsg_eof,
64 [IMSG_BOOKMARK_OK] = handle_imsg_bookmark_ok,
65 [IMSG_SAVE_CERT_OK] = handle_imsg_save_cert_ok,
66 [IMSG_UPDATE_CERT_OK] = handle_imsg_update_cert_ok,
67 [IMSG_FILE_OPENED] = handle_imsg_file_opened,
68 };
70 static struct ohash certs;
72 static void __attribute__((__noreturn__))
73 die(void)
74 {
75 abort(); /* TODO */
76 }
78 static struct tab *
79 tab_by_id(uint32_t id)
80 {
81 struct tab *t;
83 TAILQ_FOREACH(t, &tabshead, tabs) {
84 if (t->id == id)
85 return t;
86 }
88 die();
89 }
91 static void
92 handle_imsg_err(struct imsg *imsg, size_t datalen)
93 {
94 struct tab *tab;
95 char *page;
97 tab = tab_by_id(imsg->hdr.peerid);
99 page = imsg->data;
100 page[datalen-1] = '\0';
102 if (asprintf(&page, "# Error loading %s\n\n> %s\n",
103 tab->hist_cur->h, page) == -1)
104 die();
105 load_page_from_str(tab, page);
106 free(page);
109 static void
110 handle_imsg_check_cert(struct imsg *imsg, size_t datalen)
112 const char *hash, *host, *port;
113 int tofu_res;
114 struct tofu_entry *e;
115 struct tab *tab;
117 hash = imsg->data;
118 if (hash[datalen-1] != '\0')
119 abort();
121 tab = tab_by_id(imsg->hdr.peerid);
123 if (tab->proxy != NULL) {
124 host = tab->proxy->host;
125 port = tab->proxy->port;
126 } else {
127 host = tab->uri.host;
128 port = tab->uri.port;
131 if ((e = tofu_lookup(&certs, host, port)) == NULL) {
132 /* TODO: an update in libressl/libretls changed
133 * significantly. Find a better approach at storing
134 * the certs! */
135 if (datalen > sizeof(e->hash))
136 abort();
138 tofu_res = 1; /* trust on first use */
139 if ((e = calloc(1, sizeof(*e))) == NULL)
140 abort();
141 strlcpy(e->domain, host, sizeof(e->domain));
142 if (*port != '\0' && strcmp(port, "1965")) {
143 strlcat(e->domain, ":", sizeof(e->domain));
144 strlcat(e->domain, port, sizeof(e->domain));
146 strlcpy(e->hash, hash, sizeof(e->hash));
147 tofu_add(&certs, e);
148 ui_send_fs(IMSG_SAVE_CERT, tab->id, e, sizeof(*e));
149 } else
150 tofu_res = !strcmp(hash, e->hash);
152 if (tofu_res) {
153 if (e->verified == -1)
154 tab->trust = TS_TEMP_TRUSTED;
155 else if (e->verified == 1)
156 tab->trust = TS_VERIFIED;
157 else
158 tab->trust = TS_TRUSTED;
160 ui_send_net(IMSG_CERT_STATUS, imsg->hdr.peerid,
161 &tofu_res, sizeof(tofu_res));
162 } else {
163 tab->trust = TS_UNTRUSTED;
164 load_page_from_str(tab, "# Certificate mismatch\n");
165 if ((tab->cert = strdup(hash)) == NULL)
166 die();
167 ui_yornp("Certificate mismatch. Proceed?",
168 handle_check_cert_user_choice, tab);
172 static void
173 handle_check_cert_user_choice(int accept, struct tab *tab)
175 ui_send_net(IMSG_CERT_STATUS, tab->id, &accept,
176 sizeof(accept));
178 if (accept) {
179 /*
180 * trust the certificate for this session only. If
181 * the page results in a redirect while we're asking
182 * the user to save, we'll end up with an invalid
183 * tabid (one request == one tab id) and crash. It
184 * also makes sense to save it for the current session
185 * if the user accepted it.
186 */
187 tofu_temp_trust(&certs, tab->uri.host, tab->uri.port, tab->cert);
189 ui_yornp("Save the new certificate?",
190 handle_maybe_save_new_cert, tab);
191 } else {
192 free(tab->cert);
193 tab->cert = NULL;
197 static void
198 handle_maybe_save_new_cert(int accept, struct tab *tab)
200 struct tofu_entry *e;
201 const char *host, *port;
203 if (tab->proxy != NULL) {
204 host = tab->proxy->host;
205 port = tab->proxy->port;
206 } else {
207 host = tab->uri.host;
208 port = tab->uri.port;
211 if (!accept)
212 goto end;
214 if ((e = calloc(1, sizeof(*e))) == NULL)
215 die();
217 strlcpy(e->domain, host, sizeof(e->domain));
218 if (*port != '\0' && strcmp(port, "1965")) {
219 strlcat(e->domain, ":", sizeof(e->domain));
220 strlcat(e->domain, port, sizeof(e->domain));
222 strlcpy(e->hash, tab->cert, sizeof(e->hash));
223 ui_send_fs(IMSG_UPDATE_CERT, 0, e, sizeof(*e));
225 tofu_update(&certs, e);
227 tab->trust = TS_TRUSTED;
229 end:
230 free(tab->cert);
231 tab->cert = NULL;
234 static inline int
235 normalize_code(int n)
237 if (n < 20) {
238 if (n == 10 || n == 11)
239 return n;
240 return 10;
241 } else if (n < 30) {
242 return 20;
243 } else if (n < 40) {
244 if (n == 30 || n == 31)
245 return n;
246 return 30;
247 } else if (n < 50) {
248 if (n <= 44)
249 return n;
250 return 40;
251 } else if (n < 60) {
252 if (n <= 53 || n == 59)
253 return n;
254 return 50;
255 } else if (n < 70) {
256 if (n <= 62)
257 return n;
258 return 60;
259 } else
260 return MALFORMED_RESPONSE;
263 static void
264 handle_imsg_got_code(struct imsg *imsg, size_t datalen)
266 struct tab *tab;
268 tab = tab_by_id(imsg->hdr.peerid);
270 if (sizeof(tab->code) != datalen)
271 die();
273 memcpy(&tab->code, imsg->data, sizeof(tab->code));
274 tab->code = normalize_code(tab->code);
275 if (tab->code != 30 && tab->code != 31)
276 tab->redirect_count = 0;
279 static void
280 handle_imsg_got_meta(struct imsg *imsg, size_t datalen)
282 struct tab *tab;
284 tab = tab_by_id(imsg->hdr.peerid);
286 if (sizeof(tab->meta) <= datalen)
287 die();
289 memcpy(tab->meta, imsg->data, datalen);
291 if (tab->code < 10) { /* internal errors */
292 load_page_from_str(tab, err_pages[tab->code]);
293 } else if (tab->code < 20) { /* 1x */
294 load_page_from_str(tab, err_pages[tab->code]);
295 ui_require_input(tab, tab->code == 11);
296 } else if (tab->code == 20) {
297 if (setup_parser_for(tab)) {
298 ui_send_net(IMSG_PROCEED, tab->id, NULL, 0);
299 } else {
300 load_page_from_str(tab, err_pages[UNKNOWN_TYPE_OR_CSET]);
301 ui_yornp("Can't display page, wanna save?",
302 handle_maybe_save_page, tab);
304 } else if (tab->code < 40) { /* 3x */
305 tab->redirect_count++;
307 /* TODO: make customizable? */
308 if (tab->redirect_count > 5) {
309 load_page_from_str(tab,
310 err_pages[TOO_MUCH_REDIRECTS]);
311 } else
312 do_load_url(tab, tab->meta);
313 } else { /* 4x, 5x & 6x */
314 load_page_from_str(tab, err_pages[tab->code]);
318 static void
319 handle_maybe_save_page(int dosave, struct tab *tab)
321 if (dosave)
322 ui_read("Save to path", handle_save_page_path, tab->id);
323 else
324 stop_tab(tab);
327 static void
328 handle_save_page_path(const char *path, unsigned int tabid)
330 struct tab *tab;
332 if (path == NULL) {
333 stop_tab(tab_by_id(tabid));
334 return;
337 tab = tab_by_id(tabid);
338 tab->path = strdup(path);
340 ui_send_fs(IMSG_FILE_OPEN, tabid, path, strlen(path)+1);
343 static void
344 handle_imsg_file_opened(struct imsg *imsg, size_t datalen)
346 struct tab *tab;
347 char *page;
348 const char *e;
349 int l;
351 tab = tab_by_id(imsg->hdr.peerid);
353 if (imsg->fd == -1) {
354 stop_tab(tab);
356 e = imsg->data;
357 if (e[datalen-1] != '\0')
358 die();
359 l = asprintf(&page, "# Can't open file\n\n> %s: %s\n",
360 tab->path, e);
361 if (l == -1)
362 die();
363 load_page_from_str(tab, page);
364 free(page);
365 } else {
366 tab->fd = imsg->fd;
367 ui_send_net(IMSG_PROCEED, tab->id, NULL, 0);
371 static void
372 handle_imsg_buf(struct imsg *imsg, size_t datalen)
374 struct tab *tab;
375 int l;
376 char *page, buf[FMT_SCALED_STRSIZE] = {0};
378 tab = tab_by_id(imsg->hdr.peerid);
380 tab->bytes += datalen;
381 if (tab->fd == -1) {
382 if (!tab->buffer.page.parse(&tab->buffer.page,
383 imsg->data, datalen))
384 die();
385 } else {
386 write(tab->fd, imsg->data, datalen);
387 fmt_scaled(tab->bytes, buf);
388 l = asprintf(&page, "Saving to \"%s\"... (%s)\n",
389 tab->path,
390 buf);
391 if (l == -1)
392 die();
393 load_page_from_str(tab, page);
394 free(page);
397 ui_on_tab_refresh(tab);
400 static void
401 handle_imsg_eof(struct imsg *imsg, size_t datalen)
403 struct tab *tab;
404 int l;
405 char *page, buf[FMT_SCALED_STRSIZE] = {0};
407 tab = tab_by_id(imsg->hdr.peerid);
409 if (tab->fd == -1) {
410 if (!tab->buffer.page.free(&tab->buffer.page))
411 die();
412 } else {
413 fmt_scaled(tab->bytes, buf);
414 l = asprintf(&page, "Saved to \"%s\" (%s)\n",
415 tab->path,
416 buf);
417 if (l == -1)
418 die();
419 load_page_from_str(tab, page);
420 free(page);
422 close(tab->fd);
423 tab->fd = -1;
424 free(tab->path);
425 tab->path = NULL;
428 ui_on_tab_refresh(tab);
429 ui_on_tab_loaded(tab);
432 static void
433 handle_imsg_bookmark_ok(struct imsg *imsg, size_t datalen)
435 int res;
437 if (datalen != sizeof(res))
438 die();
440 memcpy(&res, imsg->data, sizeof(res));
441 if (res == 0)
442 message("Added to bookmarks!");
443 else
444 message("Failed to add to bookmarks: %s",
445 strerror(res));
448 static void
449 handle_imsg_save_cert_ok(struct imsg *imsg, size_t datalen)
451 int res;
453 if (datalen != sizeof(res))
454 die();
455 memcpy(&res, imsg->data, datalen);
456 if (res != 0)
457 message("Failed to save the cert for: %s",
458 strerror(res));
461 static void
462 handle_imsg_update_cert_ok(struct imsg *imsg, size_t datalen)
464 int res;
466 if (datalen != sizeof(res))
467 die();
468 memcpy(&res, imsg->data, datalen);
469 if (!res)
470 message("Failed to update the certificate");
473 static void
474 handle_dispatch_imsg(int fd, short ev, void *d)
476 struct imsgev *iev = d;
477 dispatch_imsg(iev, ev, handlers, sizeof(handlers));
480 static void
481 load_page_from_str(struct tab *tab, const char *page)
483 erase_buffer(&tab->buffer);
484 gemtext_initparser(&tab->buffer.page);
485 if (!tab->buffer.page.parse(&tab->buffer.page, page, strlen(page)))
486 die();
487 if (!tab->buffer.page.free(&tab->buffer.page))
488 die();
489 ui_on_tab_refresh(tab);
490 ui_on_tab_loaded(tab);
493 void
494 load_about_url(struct tab *tab, const char *url)
496 tab->trust = TS_VERIFIED;
498 gemtext_initparser(&tab->buffer.page);
500 ui_send_fs(IMSG_GET, tab->id,
501 tab->hist_cur->h, strlen(tab->hist_cur->h)+1);
504 void
505 load_gemini_url(struct tab *tab, const char *url)
507 struct get_req req;
509 stop_tab(tab);
510 tab->id = tab_new_id();
512 memset(&req, 0, sizeof(req));
513 strlcpy(req.host, tab->uri.host, sizeof(req.host));
514 strlcpy(req.port, tab->uri.port, sizeof(req.host));
516 strlcpy(req.req, tab->hist_cur->h, sizeof(req.req));
517 strlcat(req.req, "\r\n", sizeof(req.req));
519 req.proto = PROTO_GEMINI;
521 ui_send_net(IMSG_GET_RAW, tab->id,
522 &req, sizeof(req));
525 void
526 load_via_proxy(struct tab *tab, const char *url, struct proxy *p)
528 struct get_req req;
530 stop_tab(tab);
531 tab->id = tab_new_id();
532 tab->proxy = p;
534 memset(&req, 0, sizeof(req));
535 strlcpy(req.host, p->host, sizeof(req.host));
536 strlcpy(req.port, p->port, sizeof(req.host));
538 strlcpy(req.req, tab->hist_cur->h, sizeof(req.req));
539 strlcat(req.req, "\r\n", sizeof(req.req));
541 req.proto = p->proto;
543 ui_send_net(IMSG_GET_RAW, tab->id,
544 &req, sizeof(req));
547 static void
548 do_load_url(struct tab *tab, const char *url)
550 struct phos_uri uri;
551 struct proto *p;
552 struct proxy *proxy;
553 char *t;
555 tab->proxy = NULL;
557 if (tab->fd != -1) {
558 close(tab->fd);
559 tab->fd = -1;
560 free(tab->path);
561 tab->path = NULL;
564 tab->trust = TS_UNKNOWN;
566 memcpy(&uri, &tab->uri, sizeof(tab->uri));
567 if (!phos_resolve_uri_from_str(&uri, url, &tab->uri)) {
568 if (asprintf(&t, "#error loading %s\n>%s\n",
569 url, "Can't parse the URI") == -1)
570 die();
571 strlcpy(tab->hist_cur->h, url, sizeof(tab->hist_cur->h));
572 load_page_from_str(tab, t);
573 free(t);
574 return;
577 phos_serialize_uri(&tab->uri, tab->hist_cur->h,
578 sizeof(tab->hist_cur->h));
580 for (p = protos; p->schema != NULL; ++p) {
581 if (!strcmp(tab->uri.scheme, p->schema)) {
582 p->loadfn(tab, url);
583 return;
587 TAILQ_FOREACH(proxy, &proxies, proxies) {
588 if (!strcmp(tab->uri.scheme, proxy->match_proto)) {
589 load_via_proxy(tab, url, proxy);
590 return;
594 protos[0].loadfn(tab, url);
597 void
598 load_url(struct tab *tab, const char *url)
600 if (tab->hist_cur != NULL)
601 hist_clear_forward(&tab->hist, TAILQ_NEXT(tab->hist_cur, entries));
603 if ((tab->hist_cur = calloc(1, sizeof(*tab->hist_cur))) == NULL) {
604 event_loopbreak();
605 return;
608 hist_push(&tab->hist, tab->hist_cur);
609 do_load_url(tab, url);
610 erase_buffer(&tab->buffer);
613 int
614 load_previous_page(struct tab *tab)
616 struct hist *h;
618 if ((h = TAILQ_PREV(tab->hist_cur, mhisthead, entries)) == NULL)
619 return 0;
620 tab->hist_cur = h;
621 do_load_url(tab, h->h);
622 return 1;
625 int
626 load_next_page(struct tab *tab)
628 struct hist *h;
630 if ((h = TAILQ_NEXT(tab->hist_cur, entries)) == NULL)
631 return 0;
632 tab->hist_cur = h;
633 do_load_url(tab, h->h);
634 return 1;
637 void
638 stop_tab(struct tab *tab)
640 ui_send_net(IMSG_STOP, tab->id, NULL, 0);
642 if (tab->fd != -1) {
643 close(tab->fd);
644 tab->fd = -1;
645 free(tab->path);
646 tab->path = NULL;
647 load_page_from_str(tab, "Stopped.\n");
651 void
652 add_to_bookmarks(const char *str)
654 ui_send_fs(IMSG_BOOKMARK_PAGE, 0,
655 str, strlen(str)+1);
658 void
659 save_session(void)
661 struct tab *tab;
663 ui_send_fs(IMSG_SESSION_START, 0, NULL, 0);
665 TAILQ_FOREACH(tab, &tabshead, tabs) {
666 ui_send_fs(IMSG_SESSION_TAB, 0,
667 tab->hist_cur->h, strlen(tab->hist_cur->h)+1);
670 ui_send_fs(IMSG_SESSION_END, 0, NULL, 0);
673 static void
674 session_new_tab_cb(const char *url)
676 new_tab(url);
679 static pid_t
680 start_child(enum telescope_process p, const char *argv0, int fd)
682 const char *argv[4];
683 int argc = 0;
684 pid_t pid;
686 switch (pid = fork()) {
687 case -1:
688 die();
689 case 0:
690 break;
691 default:
692 close(fd);
693 return pid;
696 if (dup2(fd, 3) == -1)
697 err(1, "cannot setup imsg fd");
699 argv[argc++] = argv0;
700 switch (p) {
701 case PROC_UI:
702 errx(1, "Can't start ui process");
703 case PROC_FS:
704 argv[argc++] = "-Tf";
705 break;
706 case PROC_NET:
707 argv[argc++] = "-Tn";
708 break;
711 argv[argc++] = NULL;
712 execvp(argv0, (char *const *)argv);
713 err(1, "execvp(%s)", argv0);
716 static int
717 ui_send_net(int type, uint32_t peerid, const void *data,
718 uint16_t datalen)
720 return imsg_compose_event(iev_net, type, peerid, 0, -1, data,
721 datalen);
724 static int
725 ui_send_fs(int type, uint32_t peerid, const void *data, uint16_t datalen)
727 return imsg_compose_event(iev_fs, type, peerid, 0, -1, data,
728 datalen);
731 static void __attribute__((noreturn))
732 usage(int r)
734 fprintf(stderr, "USAGE: %s [-hn] [-c config] [url]\n", getprogname());
735 fprintf(stderr, "version: " PACKAGE " " VERSION "\n");
736 exit(r);
739 int
740 main(int argc, char * const *argv)
742 struct imsgev net_ibuf, fs_ibuf;
743 int pipe2net[2], pipe2fs[2];
744 int ch, configtest = 0, fail = 0;
745 int has_url = 0;
746 int proc = -1;
747 char path[PATH_MAX];
748 const char *url = NEW_TAB_URL;
749 const char *argv0;
751 argv0 = argv[0];
753 signal(SIGCHLD, SIG_IGN);
754 signal(SIGPIPE, SIG_IGN);
756 if (getenv("NO_COLOR") != NULL)
757 enable_colors = 0;
759 strlcpy(path, getenv("HOME"), sizeof(path));
760 strlcat(path, "/.telescope/config", sizeof(path));
762 while ((ch = getopt(argc, argv, "c:hnT:")) != -1) {
763 switch (ch) {
764 case 'c':
765 fail = 1;
766 strlcpy(path, optarg, sizeof(path));
767 break;
768 case 'n':
769 configtest = 1;
770 break;
771 case 'h':
772 usage(0);
773 case 'T':
774 switch (*optarg) {
775 case 'f':
776 proc = PROC_FS;
777 break;
778 case 'n':
779 proc = PROC_NET;
780 break;
781 default:
782 errx(1, "invalid process spec %c",
783 *optarg);
785 break;
786 default:
787 usage(1);
791 argc -= optind;
792 argv += optind;
794 if (proc != -1) {
795 if (argc > 0)
796 usage(1);
797 else if (proc == PROC_FS)
798 return fs_main();
799 else if (proc == PROC_NET)
800 return client_main();
801 else
802 usage(1);
805 if (argc != 0) {
806 has_url = 1;
807 url = argv[0];
810 /* setup keys before reading the config */
811 TAILQ_INIT(&global_map.m);
812 global_map.unhandled_input = global_key_unbound;
813 TAILQ_INIT(&minibuffer_map.m);
815 config_init();
816 parseconfig(path, fail);
817 if (configtest){
818 puts("config OK");
819 exit(0);
822 /* Start children. */
823 if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe2fs) == -1)
824 err(1, "socketpair");
825 start_child(PROC_FS, argv0, pipe2fs[1]);
826 imsg_init(&fs_ibuf.ibuf, pipe2fs[0]);
827 iev_fs = &fs_ibuf;
828 iev_fs->handler = handle_dispatch_imsg;
830 if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe2net) == -1)
831 err(1, "socketpair");
832 start_child(PROC_NET, argv0, pipe2net[1]);
833 imsg_init(&net_ibuf.ibuf, pipe2net[0]);
834 iev_net = &net_ibuf;
835 iev_net->handler = handle_dispatch_imsg;
837 setproctitle("ui");
839 /* initialize tofu & load certificates */
840 fs_init();
841 tofu_init(&certs, 5, offsetof(struct tofu_entry, domain));
842 load_certs(&certs);
844 event_init();
846 /* Setup event handlers for pipes to fs/net */
847 iev_fs->events = EV_READ;
848 event_set(&iev_fs->ev, iev_fs->ibuf.fd, iev_fs->events,
849 iev_fs->handler, iev_fs);
850 event_add(&iev_fs->ev, NULL);
852 iev_net->events = EV_READ;
853 event_set(&iev_net->ev, iev_net->ibuf.fd, iev_net->events,
854 iev_net->handler, iev_net);
855 event_add(&iev_net->ev, NULL);
857 if (ui_init()) {
858 load_last_session(session_new_tab_cb);
859 if (has_url || TAILQ_EMPTY(&tabshead))
860 new_tab(url);
862 sandbox_ui_process();
863 event_dispatch();
864 ui_end();
867 ui_send_fs(IMSG_QUIT, 0, NULL, 0);
868 ui_send_net(IMSG_QUIT, 0, NULL, 0);
869 imsg_flush(&iev_fs->ibuf);
871 return 0;