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 "parser.h"
12 #include "telescope.h"
13 #include "ui.h"
15 static struct imsgev *iev_fs, *iev_net;
17 struct tabshead tabshead = TAILQ_HEAD_INITIALIZER(tabshead);
18 struct proxylist proxies = TAILQ_HEAD_INITIALIZER(proxies);
20 enum telescope_process {
21 PROC_UI,
22 PROC_FS,
23 PROC_NET,
24 };
26 /* the first is also the fallback one */
27 static struct proto protos[] = {
28 { "gemini", load_gemini_url },
29 { "about", load_about_url },
30 { NULL, NULL },
31 };
33 static void die(void) __attribute__((__noreturn__));
34 static struct tab *tab_by_id(uint32_t);
35 static void handle_imsg_err(struct imsg*, size_t);
36 static void handle_imsg_check_cert(struct imsg*, size_t);
37 static void handle_check_cert_user_choice(int, struct tab *);
38 static void handle_maybe_save_new_cert(int, struct tab *);
39 static void handle_imsg_got_code(struct imsg*, size_t);
40 static void handle_imsg_got_meta(struct imsg*, size_t);
41 static void handle_maybe_save_page(int, struct tab *);
42 static void handle_save_page_path(const char *, unsigned int);
43 static void handle_imsg_file_opened(struct imsg*, size_t);
44 static void handle_imsg_buf(struct imsg*, size_t);
45 static void handle_imsg_eof(struct imsg*, size_t);
46 static void handle_imsg_bookmark_ok(struct imsg*, size_t);
47 static void handle_imsg_save_cert_ok(struct imsg*, size_t);
48 static void handle_imsg_update_cert_ok(struct imsg *, size_t);
49 static void handle_dispatch_imsg(int, short, void*);
50 static void load_page_from_str(struct tab*, const char*);
51 static void do_load_url(struct tab*, const char*);
52 static pid_t start_child(enum telescope_process, const char *, int);
53 static int ui_send_net(int, uint32_t, const void *, uint16_t);
54 static int ui_send_fs(int, uint32_t, const void *, uint16_t);
56 static imsg_handlerfn *handlers[] = {
57 [IMSG_ERR] = handle_imsg_err,
58 [IMSG_CHECK_CERT] = handle_imsg_check_cert,
59 [IMSG_GOT_CODE] = handle_imsg_got_code,
60 [IMSG_GOT_META] = handle_imsg_got_meta,
61 [IMSG_BUF] = handle_imsg_buf,
62 [IMSG_EOF] = handle_imsg_eof,
63 [IMSG_BOOKMARK_OK] = handle_imsg_bookmark_ok,
64 [IMSG_SAVE_CERT_OK] = handle_imsg_save_cert_ok,
65 [IMSG_UPDATE_CERT_OK] = handle_imsg_update_cert_ok,
66 [IMSG_FILE_OPENED] = handle_imsg_file_opened,
67 };
69 static struct ohash certs;
71 static void __attribute__((__noreturn__))
72 die(void)
73 {
74 abort(); /* TODO */
75 }
77 static struct tab *
78 tab_by_id(uint32_t id)
79 {
80 struct tab *t;
82 TAILQ_FOREACH(t, &tabshead, tabs) {
83 if (t->id == id)
84 return t;
85 }
87 die();
88 }
90 static void
91 handle_imsg_err(struct imsg *imsg, size_t datalen)
92 {
93 struct tab *tab;
94 char *page;
96 tab = tab_by_id(imsg->hdr.peerid);
98 page = imsg->data;
99 page[datalen-1] = '\0';
101 if (asprintf(&page, "# Error loading %s\n\n> %s\n",
102 tab->hist_cur->h, page) == -1)
103 die();
104 load_page_from_str(tab, page);
105 free(page);
108 static void
109 handle_imsg_check_cert(struct imsg *imsg, size_t datalen)
111 const char *hash, *host, *port;
112 int tofu_res;
113 struct tofu_entry *e;
114 struct tab *tab;
116 hash = imsg->data;
117 if (hash[datalen-1] != '\0')
118 abort();
120 tab = tab_by_id(imsg->hdr.peerid);
122 if (tab->proxy != NULL) {
123 host = tab->proxy->host;
124 port = tab->proxy->port;
125 } else {
126 host = tab->uri.host;
127 port = tab->uri.port;
130 if ((e = tofu_lookup(&certs, host, port)) == NULL) {
131 /* TODO: an update in libressl/libretls changed
132 * significantly. Find a better approach at storing
133 * the certs! */
134 if (datalen > sizeof(e->hash))
135 abort();
137 tofu_res = 1; /* trust on first use */
138 if ((e = calloc(1, sizeof(*e))) == NULL)
139 abort();
140 strlcpy(e->domain, host, sizeof(e->domain));
141 if (*port != '\0' && strcmp(port, "1965")) {
142 strlcat(e->domain, ":", sizeof(e->domain));
143 strlcat(e->domain, port, sizeof(e->domain));
145 strlcpy(e->hash, hash, sizeof(e->hash));
146 tofu_add(&certs, e);
147 ui_send_fs(IMSG_SAVE_CERT, tab->id, e, sizeof(*e));
148 } else
149 tofu_res = !strcmp(hash, e->hash);
151 if (tofu_res) {
152 if (e->verified == -1)
153 tab->trust = TS_TEMP_TRUSTED;
154 else if (e->verified == 1)
155 tab->trust = TS_VERIFIED;
156 else
157 tab->trust = TS_TRUSTED;
159 ui_send_net(IMSG_CERT_STATUS, imsg->hdr.peerid,
160 &tofu_res, sizeof(tofu_res));
161 } else {
162 tab->trust = TS_UNTRUSTED;
163 load_page_from_str(tab, "# Certificate mismatch\n");
164 if ((tab->cert = strdup(hash)) == NULL)
165 die();
166 ui_yornp("Certificate mismatch. Proceed?",
167 handle_check_cert_user_choice, tab);
171 static void
172 handle_check_cert_user_choice(int accept, struct tab *tab)
174 ui_send_net(IMSG_CERT_STATUS, tab->id, &accept,
175 sizeof(accept));
177 if (accept) {
178 /*
179 * trust the certificate for this session only. If
180 * the page results in a redirect while we're asking
181 * the user to save, we'll end up with an invalid
182 * tabid (one request == one tab id) and crash. It
183 * also makes sense to save it for the current session
184 * if the user accepted it.
185 */
186 tofu_temp_trust(&certs, tab->uri.host, tab->uri.port, tab->cert);
188 ui_yornp("Save the new certificate?",
189 handle_maybe_save_new_cert, tab);
190 } else {
191 free(tab->cert);
192 tab->cert = NULL;
196 static void
197 handle_maybe_save_new_cert(int accept, struct tab *tab)
199 struct tofu_entry *e;
200 const char *host, *port;
202 if (tab->proxy != NULL) {
203 host = tab->proxy->host;
204 port = tab->proxy->port;
205 } else {
206 host = tab->uri.host;
207 port = tab->uri.port;
210 if (!accept)
211 goto end;
213 if ((e = calloc(1, sizeof(*e))) == NULL)
214 die();
216 strlcpy(e->domain, host, sizeof(e->domain));
217 if (*port != '\0' && strcmp(port, "1965")) {
218 strlcat(e->domain, ":", sizeof(e->domain));
219 strlcat(e->domain, port, sizeof(e->domain));
221 strlcpy(e->hash, tab->cert, sizeof(e->hash));
222 ui_send_fs(IMSG_UPDATE_CERT, 0, e, sizeof(*e));
224 tofu_update(&certs, e);
226 tab->trust = TS_TRUSTED;
228 end:
229 free(tab->cert);
230 tab->cert = NULL;
233 static inline int
234 normalize_code(int n)
236 if (n < 20) {
237 if (n == 10 || n == 11)
238 return n;
239 return 10;
240 } else if (n < 30) {
241 return 20;
242 } else if (n < 40) {
243 if (n == 30 || n == 31)
244 return n;
245 return 30;
246 } else if (n < 50) {
247 if (n <= 44)
248 return n;
249 return 40;
250 } else if (n < 60) {
251 if (n <= 53 || n == 59)
252 return n;
253 return 50;
254 } else if (n < 70) {
255 if (n <= 62)
256 return n;
257 return 60;
258 } else
259 return MALFORMED_RESPONSE;
262 static void
263 handle_imsg_got_code(struct imsg *imsg, size_t datalen)
265 struct tab *tab;
267 tab = tab_by_id(imsg->hdr.peerid);
269 if (sizeof(tab->code) != datalen)
270 die();
272 memcpy(&tab->code, imsg->data, sizeof(tab->code));
273 tab->code = normalize_code(tab->code);
274 if (tab->code != 30 && tab->code != 31)
275 tab->redirect_count = 0;
278 static void
279 handle_imsg_got_meta(struct imsg *imsg, size_t datalen)
281 struct tab *tab;
283 tab = tab_by_id(imsg->hdr.peerid);
285 if (sizeof(tab->meta) <= datalen)
286 die();
288 memcpy(tab->meta, imsg->data, datalen);
290 if (tab->code < 10) { /* internal errors */
291 load_page_from_str(tab, err_pages[tab->code]);
292 } else if (tab->code < 20) { /* 1x */
293 load_page_from_str(tab, err_pages[tab->code]);
294 ui_require_input(tab, tab->code == 11);
295 } else if (tab->code == 20) {
296 if (setup_parser_for(tab)) {
297 ui_send_net(IMSG_PROCEED, tab->id, NULL, 0);
298 } else {
299 load_page_from_str(tab, err_pages[UNKNOWN_TYPE_OR_CSET]);
300 ui_yornp("Can't display page, wanna save?",
301 handle_maybe_save_page, tab);
303 } else if (tab->code < 40) { /* 3x */
304 tab->redirect_count++;
306 /* TODO: make customizable? */
307 if (tab->redirect_count > 5) {
308 load_page_from_str(tab,
309 err_pages[TOO_MUCH_REDIRECTS]);
310 } else
311 do_load_url(tab, tab->meta);
312 } else { /* 4x, 5x & 6x */
313 load_page_from_str(tab, err_pages[tab->code]);
317 static void
318 handle_maybe_save_page(int dosave, struct tab *tab)
320 if (dosave)
321 ui_read("Save to path", handle_save_page_path, tab->id);
322 else
323 stop_tab(tab);
326 static void
327 handle_save_page_path(const char *path, unsigned int tabid)
329 struct tab *tab;
331 if (path == NULL) {
332 stop_tab(tab_by_id(tabid));
333 return;
336 tab = tab_by_id(tabid);
337 tab->path = strdup(path);
339 ui_send_fs(IMSG_FILE_OPEN, tabid, path, strlen(path)+1);
342 static void
343 handle_imsg_file_opened(struct imsg *imsg, size_t datalen)
345 struct tab *tab;
346 char *page;
347 const char *e;
348 int l;
350 tab = tab_by_id(imsg->hdr.peerid);
352 if (imsg->fd == -1) {
353 stop_tab(tab);
355 e = imsg->data;
356 if (e[datalen-1] != '\0')
357 die();
358 l = asprintf(&page, "# Can't open file\n\n> %s: %s\n",
359 tab->path, e);
360 if (l == -1)
361 die();
362 load_page_from_str(tab, page);
363 free(page);
364 } else {
365 tab->fd = imsg->fd;
366 ui_send_net(IMSG_PROCEED, tab->id, NULL, 0);
370 static void
371 handle_imsg_buf(struct imsg *imsg, size_t datalen)
373 struct tab *tab;
374 int l;
375 char *page, buf[FMT_SCALED_STRSIZE] = {0};
377 tab = tab_by_id(imsg->hdr.peerid);
379 tab->bytes += datalen;
380 if (tab->fd == -1) {
381 if (!tab->buffer.page.parse(&tab->buffer.page,
382 imsg->data, datalen))
383 die();
384 } else {
385 write(tab->fd, imsg->data, datalen);
386 fmt_scaled(tab->bytes, buf);
387 l = asprintf(&page, "Saving to \"%s\"... (%s)\n",
388 tab->path,
389 buf);
390 if (l == -1)
391 die();
392 load_page_from_str(tab, page);
393 free(page);
396 ui_on_tab_refresh(tab);
399 static void
400 handle_imsg_eof(struct imsg *imsg, size_t datalen)
402 struct tab *tab;
403 int l;
404 char *page, buf[FMT_SCALED_STRSIZE] = {0};
406 tab = tab_by_id(imsg->hdr.peerid);
408 if (tab->fd == -1) {
409 if (!tab->buffer.page.free(&tab->buffer.page))
410 die();
411 } else {
412 fmt_scaled(tab->bytes, buf);
413 l = asprintf(&page, "Saved to \"%s\" (%s)\n",
414 tab->path,
415 buf);
416 if (l == -1)
417 die();
418 load_page_from_str(tab, page);
419 free(page);
421 close(tab->fd);
422 tab->fd = -1;
423 free(tab->path);
424 tab->path = NULL;
427 ui_on_tab_refresh(tab);
428 ui_on_tab_loaded(tab);
431 static void
432 handle_imsg_bookmark_ok(struct imsg *imsg, size_t datalen)
434 int res;
436 if (datalen != sizeof(res))
437 die();
439 memcpy(&res, imsg->data, sizeof(res));
440 if (res == 0)
441 message("Added to bookmarks!");
442 else
443 message("Failed to add to bookmarks: %s",
444 strerror(res));
447 static void
448 handle_imsg_save_cert_ok(struct imsg *imsg, size_t datalen)
450 int res;
452 if (datalen != sizeof(res))
453 die();
454 memcpy(&res, imsg->data, datalen);
455 if (res != 0)
456 message("Failed to save the cert for: %s",
457 strerror(res));
460 static void
461 handle_imsg_update_cert_ok(struct imsg *imsg, size_t datalen)
463 int res;
465 if (datalen != sizeof(res))
466 die();
467 memcpy(&res, imsg->data, datalen);
468 if (!res)
469 message("Failed to update the certificate");
472 static void
473 handle_dispatch_imsg(int fd, short ev, void *d)
475 struct imsgev *iev = d;
476 dispatch_imsg(iev, ev, handlers, sizeof(handlers));
479 static void
480 load_page_from_str(struct tab *tab, const char *page)
482 erase_buffer(&tab->buffer);
483 gemtext_initparser(&tab->buffer.page);
484 if (!tab->buffer.page.parse(&tab->buffer.page, page, strlen(page)))
485 die();
486 if (!tab->buffer.page.free(&tab->buffer.page))
487 die();
488 ui_on_tab_refresh(tab);
489 ui_on_tab_loaded(tab);
492 void
493 load_about_url(struct tab *tab, const char *url)
495 tab->trust = TS_VERIFIED;
497 gemtext_initparser(&tab->buffer.page);
499 ui_send_fs(IMSG_GET, tab->id,
500 tab->hist_cur->h, strlen(tab->hist_cur->h)+1);
503 void
504 load_gemini_url(struct tab *tab, const char *url)
506 struct get_req req;
508 stop_tab(tab);
509 tab->id = tab_new_id();
511 memset(&req, 0, sizeof(req));
512 strlcpy(req.host, tab->uri.host, sizeof(req.host));
513 strlcpy(req.port, tab->uri.port, sizeof(req.host));
515 strlcpy(req.req, tab->hist_cur->h, sizeof(req.req));
516 strlcat(req.req, "\r\n", sizeof(req.req));
518 req.proto = PROTO_GEMINI;
520 ui_send_net(IMSG_GET_RAW, tab->id,
521 &req, sizeof(req));
524 void
525 load_via_proxy(struct tab *tab, const char *url, struct proxy *p)
527 struct get_req req;
529 stop_tab(tab);
530 tab->id = tab_new_id();
531 tab->proxy = p;
533 memset(&req, 0, sizeof(req));
534 strlcpy(req.host, p->host, sizeof(req.host));
535 strlcpy(req.port, p->port, sizeof(req.host));
537 strlcpy(req.req, tab->hist_cur->h, sizeof(req.req));
538 strlcat(req.req, "\r\n", sizeof(req.req));
540 req.proto = p->proto;
542 ui_send_net(IMSG_GET_RAW, tab->id,
543 &req, sizeof(req));
546 static void
547 do_load_url(struct tab *tab, const char *url)
549 struct phos_uri uri;
550 struct proto *p;
551 struct proxy *proxy;
552 char *t;
554 tab->proxy = NULL;
556 if (tab->fd != -1) {
557 close(tab->fd);
558 tab->fd = -1;
559 free(tab->path);
560 tab->path = NULL;
563 tab->trust = TS_UNKNOWN;
565 memcpy(&uri, &tab->uri, sizeof(tab->uri));
566 if (!phos_resolve_uri_from_str(&uri, url, &tab->uri)) {
567 if (asprintf(&t, "#error loading %s\n>%s\n",
568 url, "Can't parse the URI") == -1)
569 die();
570 strlcpy(tab->hist_cur->h, url, sizeof(tab->hist_cur->h));
571 load_page_from_str(tab, t);
572 free(t);
573 return;
576 phos_serialize_uri(&tab->uri, tab->hist_cur->h,
577 sizeof(tab->hist_cur->h));
579 for (p = protos; p->schema != NULL; ++p) {
580 if (!strcmp(tab->uri.scheme, p->schema)) {
581 p->loadfn(tab, url);
582 return;
586 TAILQ_FOREACH(proxy, &proxies, proxies) {
587 if (!strcmp(tab->uri.scheme, proxy->match_proto)) {
588 load_via_proxy(tab, url, proxy);
589 return;
593 protos[0].loadfn(tab, url);
596 void
597 load_url(struct tab *tab, const char *url)
599 if (tab->hist_cur != NULL)
600 hist_clear_forward(&tab->hist, TAILQ_NEXT(tab->hist_cur, entries));
602 if ((tab->hist_cur = calloc(1, sizeof(*tab->hist_cur))) == NULL) {
603 event_loopbreak();
604 return;
607 hist_push(&tab->hist, tab->hist_cur);
608 do_load_url(tab, url);
609 erase_buffer(&tab->buffer);
612 int
613 load_previous_page(struct tab *tab)
615 struct hist *h;
617 if ((h = TAILQ_PREV(tab->hist_cur, mhisthead, entries)) == NULL)
618 return 0;
619 tab->hist_cur = h;
620 do_load_url(tab, h->h);
621 return 1;
624 int
625 load_next_page(struct tab *tab)
627 struct hist *h;
629 if ((h = TAILQ_NEXT(tab->hist_cur, entries)) == NULL)
630 return 0;
631 tab->hist_cur = h;
632 do_load_url(tab, h->h);
633 return 1;
636 void
637 stop_tab(struct tab *tab)
639 ui_send_net(IMSG_STOP, tab->id, NULL, 0);
641 if (tab->fd != -1) {
642 close(tab->fd);
643 tab->fd = -1;
644 free(tab->path);
645 tab->path = NULL;
646 load_page_from_str(tab, "Stopped.\n");
650 void
651 add_to_bookmarks(const char *str)
653 ui_send_fs(IMSG_BOOKMARK_PAGE, 0,
654 str, strlen(str)+1);
657 void
658 save_session(void)
660 struct tab *tab;
662 ui_send_fs(IMSG_SESSION_START, 0, NULL, 0);
664 TAILQ_FOREACH(tab, &tabshead, tabs) {
665 ui_send_fs(IMSG_SESSION_TAB, 0,
666 tab->hist_cur->h, strlen(tab->hist_cur->h)+1);
669 ui_send_fs(IMSG_SESSION_END, 0, NULL, 0);
672 static void
673 session_new_tab_cb(const char *url)
675 new_tab(url);
678 static pid_t
679 start_child(enum telescope_process p, const char *argv0, int fd)
681 const char *argv[4];
682 int argc = 0;
683 pid_t pid;
685 switch (pid = fork()) {
686 case -1:
687 die();
688 case 0:
689 break;
690 default:
691 close(fd);
692 return pid;
695 if (dup2(fd, 3) == -1)
696 err(1, "cannot setup imsg fd");
698 argv[argc++] = argv0;
699 switch (p) {
700 case PROC_UI:
701 errx(1, "Can't start ui process");
702 case PROC_FS:
703 argv[argc++] = "-Tf";
704 break;
705 case PROC_NET:
706 argv[argc++] = "-Tn";
707 break;
710 argv[argc++] = NULL;
711 execvp(argv0, (char *const *)argv);
712 err(1, "execvp(%s)", argv0);
715 static int
716 ui_send_net(int type, uint32_t peerid, const void *data,
717 uint16_t datalen)
719 return imsg_compose_event(iev_net, type, peerid, 0, -1, data,
720 datalen);
723 static int
724 ui_send_fs(int type, uint32_t peerid, const void *data, uint16_t datalen)
726 return imsg_compose_event(iev_fs, type, peerid, 0, -1, data,
727 datalen);
730 static void __attribute__((noreturn))
731 usage(int r)
733 fprintf(stderr, "USAGE: %s [-hn] [-c config] [url]\n", getprogname());
734 fprintf(stderr, "version: " PACKAGE " " VERSION "\n");
735 exit(r);
738 int
739 main(int argc, char * const *argv)
741 struct imsgev net_ibuf, fs_ibuf;
742 int pipe2net[2], pipe2fs[2];
743 int ch, configtest = 0, fail = 0;
744 int has_url = 0;
745 int proc = -1;
746 char path[PATH_MAX];
747 const char *url = NEW_TAB_URL;
748 const char *argv0;
750 argv0 = argv[0];
752 signal(SIGCHLD, SIG_IGN);
753 signal(SIGPIPE, SIG_IGN);
755 if (getenv("NO_COLOR") != NULL)
756 enable_colors = 0;
758 strlcpy(path, getenv("HOME"), sizeof(path));
759 strlcat(path, "/.telescope/config", sizeof(path));
761 while ((ch = getopt(argc, argv, "c:hnT:")) != -1) {
762 switch (ch) {
763 case 'c':
764 fail = 1;
765 strlcpy(path, optarg, sizeof(path));
766 break;
767 case 'n':
768 configtest = 1;
769 break;
770 case 'h':
771 usage(0);
772 case 'T':
773 switch (*optarg) {
774 case 'f':
775 proc = PROC_FS;
776 break;
777 case 'n':
778 proc = PROC_NET;
779 break;
780 default:
781 errx(1, "invalid process spec %c",
782 *optarg);
784 break;
785 default:
786 usage(1);
790 argc -= optind;
791 argv += optind;
793 if (proc != -1) {
794 if (argc > 0)
795 usage(1);
796 else if (proc == PROC_FS)
797 return fs_main();
798 else if (proc == PROC_NET)
799 return client_main();
800 else
801 usage(1);
804 if (argc != 0) {
805 has_url = 1;
806 url = argv[0];
809 /* setup keys before reading the config */
810 TAILQ_INIT(&global_map.m);
811 global_map.unhandled_input = global_key_unbound;
812 TAILQ_INIT(&minibuffer_map.m);
814 config_init();
815 parseconfig(path, fail);
816 if (configtest){
817 puts("config OK");
818 exit(0);
821 /* Start children. */
822 if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe2fs) == -1)
823 err(1, "socketpair");
824 start_child(PROC_FS, argv0, pipe2fs[1]);
825 imsg_init(&fs_ibuf.ibuf, pipe2fs[0]);
826 iev_fs = &fs_ibuf;
827 iev_fs->handler = handle_dispatch_imsg;
829 if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe2net) == -1)
830 err(1, "socketpair");
831 start_child(PROC_NET, argv0, pipe2net[1]);
832 imsg_init(&net_ibuf.ibuf, pipe2net[0]);
833 iev_net = &net_ibuf;
834 iev_net->handler = handle_dispatch_imsg;
836 setproctitle("ui");
838 /* initialize tofu & load certificates */
839 fs_init();
840 tofu_init(&certs, 5, offsetof(struct tofu_entry, domain));
841 load_certs(&certs);
843 event_init();
845 /* Setup event handlers for pipes to fs/net */
846 iev_fs->events = EV_READ;
847 event_set(&iev_fs->ev, iev_fs->ibuf.fd, iev_fs->events,
848 iev_fs->handler, iev_fs);
849 event_add(&iev_fs->ev, NULL);
851 iev_net->events = EV_READ;
852 event_set(&iev_net->ev, iev_net->ibuf.fd, iev_net->events,
853 iev_net->handler, iev_net);
854 event_add(&iev_net->ev, NULL);
856 if (ui_init()) {
857 load_last_session(session_new_tab_cb);
858 if (has_url || TAILQ_EMPTY(&tabshead))
859 new_tab(url);
861 sandbox_ui_process();
862 event_dispatch();
863 ui_end();
866 ui_send_fs(IMSG_QUIT, 0, NULL, 0);
867 ui_send_net(IMSG_QUIT, 0, NULL, 0);
869 return 0;