Blob


1 #include "telescope.h"
3 #include <sys/socket.h>
5 #include <errno.h>
6 #include <limits.h>
7 #include <signal.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <unistd.h>
13 struct event netev, fsev;
14 struct tabshead tabshead;
15 struct proxylist proxies;
17 enum telescope_process {
18 PROC_UI,
19 PROC_FS,
20 PROC_NET,
21 };
23 /* the first is also the fallback one */
24 static struct proto protos[] = {
25 { "gemini", load_gemini_url },
26 { "about", load_about_url },
27 { NULL, NULL },
28 };
30 static struct imsgbuf *netibuf, *fsibuf;
32 static void die(void) __attribute__((__noreturn__));
33 static struct tab *tab_by_id(uint32_t);
34 static void handle_imsg_err(struct imsg*, size_t);
35 static void handle_imsg_check_cert(struct imsg*, size_t);
36 static void handle_check_cert_user_choice(int, struct tab *);
37 static void handle_maybe_save_new_cert(int, struct tab *);
38 static void handle_imsg_got_code(struct imsg*, size_t);
39 static void handle_imsg_got_meta(struct imsg*, size_t);
40 static void handle_maybe_save_page(int, struct tab *);
41 static void handle_save_page_path(const char *, unsigned int);
42 static void handle_imsg_file_opened(struct imsg*, size_t);
43 static void handle_imsg_buf(struct imsg*, size_t);
44 static void handle_imsg_eof(struct imsg*, size_t);
45 static void handle_imsg_bookmark_ok(struct imsg*, size_t);
46 static void handle_imsg_save_cert_ok(struct imsg*, size_t);
47 static void handle_imsg_update_cert_ok(struct imsg *, size_t);
48 static void handle_dispatch_imsg(int, short, void*);
49 static void load_page_from_str(struct tab*, const char*);
50 static void do_load_url(struct tab*, const char*);
51 static pid_t start_child(enum telescope_process, const char *, int);
53 static imsg_handlerfn *handlers[] = {
54 [IMSG_ERR] = handle_imsg_err,
55 [IMSG_CHECK_CERT] = handle_imsg_check_cert,
56 [IMSG_GOT_CODE] = handle_imsg_got_code,
57 [IMSG_GOT_META] = handle_imsg_got_meta,
58 [IMSG_BUF] = handle_imsg_buf,
59 [IMSG_EOF] = handle_imsg_eof,
60 [IMSG_BOOKMARK_OK] = handle_imsg_bookmark_ok,
61 [IMSG_SAVE_CERT_OK] = handle_imsg_save_cert_ok,
62 [IMSG_UPDATE_CERT_OK] = handle_imsg_update_cert_ok,
63 [IMSG_FILE_OPENED] = handle_imsg_file_opened,
64 };
66 static struct ohash certs;
68 static void __attribute__((__noreturn__))
69 die(void)
70 {
71 abort(); /* TODO */
72 }
74 static struct tab *
75 tab_by_id(uint32_t id)
76 {
77 struct tab *t;
79 TAILQ_FOREACH(t, &tabshead, tabs) {
80 if (t->id == id)
81 return t;
82 }
84 die();
85 }
87 static void
88 handle_imsg_err(struct imsg *imsg, size_t datalen)
89 {
90 struct tab *tab;
91 char *page;
93 tab = tab_by_id(imsg->hdr.peerid);
95 page = imsg->data;
96 page[datalen-1] = '\0';
98 if (asprintf(&page, "# Error loading %s\n\n> %s\n",
99 tab->hist_cur->h, page) == -1)
100 die();
101 load_page_from_str(tab, page);
102 free(page);
105 static void
106 handle_imsg_check_cert(struct imsg *imsg, size_t datalen)
108 const char *hash, *host, *port;
109 int tofu_res;
110 struct tofu_entry *e;
111 struct tab *tab;
113 hash = imsg->data;
114 if (hash[datalen-1] != '\0')
115 abort();
117 tab = tab_by_id(imsg->hdr.peerid);
119 if (tab->proxy != NULL) {
120 host = tab->proxy->host;
121 port = tab->proxy->port;
122 } else {
123 host = tab->uri.host;
124 port = tab->uri.port;
127 if ((e = tofu_lookup(&certs, host, port)) == NULL) {
128 /* TODO: an update in libressl/libretls changed
129 * significantly. Find a better approach at storing
130 * the certs! */
131 if (datalen > sizeof(e->hash))
132 abort();
134 tofu_res = 1; /* trust on first use */
135 if ((e = calloc(1, sizeof(*e))) == NULL)
136 abort();
137 strlcpy(e->domain, host, sizeof(e->domain));
138 if (*port != '\0' && strcmp(port, "1965")) {
139 strlcat(e->domain, ":", sizeof(e->domain));
140 strlcat(e->domain, port, sizeof(e->domain));
142 strlcpy(e->hash, hash, sizeof(e->hash));
143 tofu_add(&certs, e);
144 imsg_compose(fsibuf, IMSG_SAVE_CERT, tab->id, 0, -1,
145 e, sizeof(*e));
146 imsg_flush(fsibuf);
147 } else
148 tofu_res = !strcmp(hash, e->hash);
150 if (tofu_res) {
151 if (e->verified == -1)
152 tab->trust = TS_TEMP_TRUSTED;
153 else if (e->verified == 1)
154 tab->trust = TS_VERIFIED;
155 else
156 tab->trust = TS_TRUSTED;
158 imsg_compose(netibuf, IMSG_CERT_STATUS, imsg->hdr.peerid, 0, -1,
159 &tofu_res, sizeof(tofu_res));
160 imsg_flush(netibuf);
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 imsg_compose(netibuf, IMSG_CERT_STATUS, tab->id, 0, -1,
175 &accept, sizeof(accept));
176 imsg_flush(netibuf);
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 imsg_compose(fsibuf, IMSG_UPDATE_CERT, 0, 0, -1, e, sizeof(*e));
224 imsg_flush(fsibuf);
226 tofu_update(&certs, e);
228 tab->trust = TS_TRUSTED;
230 end:
231 free(tab->cert);
232 tab->cert = NULL;
235 static inline int
236 normalize_code(int n)
238 if (n < 20) {
239 if (n == 10 || n == 11)
240 return n;
241 return 10;
242 } else if (n < 30) {
243 return 20;
244 } else if (n < 40) {
245 if (n == 30 || n == 31)
246 return n;
247 return 30;
248 } else if (n < 50) {
249 if (n <= 44)
250 return n;
251 return 40;
252 } else if (n < 60) {
253 if (n <= 53 || n == 59)
254 return n;
255 return 50;
256 } else if (n < 70) {
257 if (n <= 62)
258 return n;
259 return 60;
260 } else
261 return MALFORMED_RESPONSE;
264 static void
265 handle_imsg_got_code(struct imsg *imsg, size_t datalen)
267 struct tab *tab;
269 tab = tab_by_id(imsg->hdr.peerid);
271 if (sizeof(tab->code) != datalen)
272 die();
274 memcpy(&tab->code, imsg->data, sizeof(tab->code));
275 tab->code = normalize_code(tab->code);
276 if (tab->code != 30 && tab->code != 31)
277 tab->redirect_count = 0;
280 static void
281 handle_imsg_got_meta(struct imsg *imsg, size_t datalen)
283 struct tab *tab;
285 tab = tab_by_id(imsg->hdr.peerid);
287 if (sizeof(tab->meta) <= datalen)
288 die();
290 memcpy(tab->meta, imsg->data, datalen);
292 if (tab->code < 10) { /* internal errors */
293 load_page_from_str(tab, err_pages[tab->code]);
294 } else if (tab->code < 20) { /* 1x */
295 load_page_from_str(tab, err_pages[tab->code]);
296 ui_require_input(tab, tab->code == 11);
297 } else if (tab->code == 20) {
298 if (setup_parser_for(tab)) {
299 imsg_compose(netibuf, IMSG_PROCEED, tab->id, 0, -1, NULL, 0);
300 imsg_flush(netibuf);
301 } else {
302 load_page_from_str(tab, err_pages[UNKNOWN_TYPE_OR_CSET]);
303 ui_yornp("Can't display page, wanna save?",
304 handle_maybe_save_page, tab);
306 } else if (tab->code < 40) { /* 3x */
307 tab->redirect_count++;
309 /* TODO: make customizable? */
310 if (tab->redirect_count > 5) {
311 load_page_from_str(tab,
312 err_pages[TOO_MUCH_REDIRECTS]);
313 } else
314 do_load_url(tab, tab->meta);
315 } else { /* 4x, 5x & 6x */
316 load_page_from_str(tab, err_pages[tab->code]);
320 static void
321 handle_maybe_save_page(int dosave, struct tab *tab)
323 if (dosave)
324 ui_read("Save to path", handle_save_page_path, tab->id);
325 else
326 stop_tab(tab);
329 static void
330 handle_save_page_path(const char *path, unsigned int tabid)
332 struct tab *tab;
334 if (path == NULL) {
335 stop_tab(tab_by_id(tabid));
336 return;
339 tab = tab_by_id(tabid);
340 tab->path = strdup(path);
342 imsg_compose(fsibuf, IMSG_FILE_OPEN, tabid, 0, -1, path, strlen(path)+1);
343 imsg_flush(fsibuf);
346 static void
347 handle_imsg_file_opened(struct imsg *imsg, size_t datalen)
349 struct tab *tab;
350 char *page;
351 const char *e;
352 int l;
354 tab = tab_by_id(imsg->hdr.peerid);
356 if (imsg->fd == -1) {
357 stop_tab(tab);
359 e = imsg->data;
360 if (e[datalen-1] != '\0')
361 die();
362 l = asprintf(&page, "# Can't open file\n\n> %s: %s\n",
363 tab->path, e);
364 if (l == -1)
365 die();
366 load_page_from_str(tab, page);
367 free(page);
368 } else {
369 tab->fd = imsg->fd;
370 imsg_compose(netibuf, IMSG_PROCEED, tab->id, 0, -1, NULL, 0);
371 imsg_flush(netibuf);
375 static void
376 handle_imsg_buf(struct imsg *imsg, size_t datalen)
378 struct tab *tab;
379 int l;
380 char *page, buf[FMT_SCALED_STRSIZE] = {0};
382 tab = tab_by_id(imsg->hdr.peerid);
384 tab->bytes += datalen;
385 if (tab->fd == -1) {
386 if (!tab->buffer.page.parse(&tab->buffer.page,
387 imsg->data, datalen))
388 die();
389 } else {
390 write(tab->fd, imsg->data, datalen);
391 fmt_scaled(tab->bytes, buf);
392 l = asprintf(&page, "Saving to \"%s\"... (%s)\n",
393 tab->path,
394 buf);
395 if (l == -1)
396 die();
397 load_page_from_str(tab, page);
398 free(page);
401 ui_on_tab_refresh(tab);
404 static void
405 handle_imsg_eof(struct imsg *imsg, size_t datalen)
407 struct tab *tab;
408 int l;
409 char *page, buf[FMT_SCALED_STRSIZE] = {0};
411 tab = tab_by_id(imsg->hdr.peerid);
413 if (tab->fd == -1) {
414 if (!tab->buffer.page.free(&tab->buffer.page))
415 die();
416 } else {
417 fmt_scaled(tab->bytes, buf);
418 l = asprintf(&page, "Saved to \"%s\" (%s)\n",
419 tab->path,
420 buf);
421 if (l == -1)
422 die();
423 load_page_from_str(tab, page);
424 free(page);
426 close(tab->fd);
427 tab->fd = -1;
428 free(tab->path);
429 tab->path = NULL;
432 ui_on_tab_refresh(tab);
433 ui_on_tab_loaded(tab);
436 static void
437 handle_imsg_bookmark_ok(struct imsg *imsg, size_t datalen)
439 int res;
441 if (datalen != sizeof(res))
442 die();
444 memcpy(&res, imsg->data, sizeof(res));
445 if (res == 0)
446 message("Added to bookmarks!");
447 else
448 message("Failed to add to bookmarks: %s",
449 strerror(res));
452 static void
453 handle_imsg_save_cert_ok(struct imsg *imsg, size_t datalen)
455 int res;
457 if (datalen != sizeof(res))
458 die();
459 memcpy(&res, imsg->data, datalen);
460 if (res != 0)
461 message("Failed to save the cert for: %s",
462 strerror(res));
465 static void
466 handle_imsg_update_cert_ok(struct imsg *imsg, size_t datalen)
468 int res;
470 if (datalen != sizeof(res))
471 die();
472 memcpy(&res, imsg->data, datalen);
473 if (!res)
474 message("Failed to update the certificate");
477 static void
478 handle_dispatch_imsg(int fd, short ev, void *d)
480 struct imsgbuf *ibuf = d;
481 dispatch_imsg(ibuf, handlers, sizeof(handlers));
484 static void
485 load_page_from_str(struct tab *tab, const char *page)
487 erase_buffer(&tab->buffer);
488 gemtext_initparser(&tab->buffer.page);
489 if (!tab->buffer.page.parse(&tab->buffer.page, page, strlen(page)))
490 die();
491 if (!tab->buffer.page.free(&tab->buffer.page))
492 die();
493 ui_on_tab_refresh(tab);
494 ui_on_tab_loaded(tab);
497 void
498 load_about_url(struct tab *tab, const char *url)
500 tab->trust = TS_VERIFIED;
502 gemtext_initparser(&tab->buffer.page);
504 imsg_compose(fsibuf, IMSG_GET, tab->id, 0, -1,
505 tab->hist_cur->h, strlen(tab->hist_cur->h)+1);
506 imsg_flush(fsibuf);
509 void
510 load_gemini_url(struct tab *tab, const char *url)
512 struct get_req req;
514 stop_tab(tab);
515 tab->id = tab_new_id();
517 memset(&req, 0, sizeof(req));
518 strlcpy(req.host, tab->uri.host, sizeof(req.host));
519 strlcpy(req.port, tab->uri.port, sizeof(req.host));
521 strlcpy(req.req, tab->hist_cur->h, sizeof(req.req));
522 strlcat(req.req, "\r\n", sizeof(req.req));
524 req.proto = PROTO_GEMINI;
526 imsg_compose(netibuf, IMSG_GET_RAW, tab->id, 0, -1,
527 &req, sizeof(req));
528 imsg_flush(netibuf);
531 void
532 load_via_proxy(struct tab *tab, const char *url, struct proxy *p)
534 struct get_req req;
536 stop_tab(tab);
537 tab->id = tab_new_id();
538 tab->proxy = p;
540 memset(&req, 0, sizeof(req));
541 strlcpy(req.host, p->host, sizeof(req.host));
542 strlcpy(req.port, p->port, sizeof(req.host));
544 strlcpy(req.req, tab->hist_cur->h, sizeof(req.req));
545 strlcat(req.req, "\r\n", sizeof(req.req));
547 req.proto = p->proto;
549 imsg_compose(netibuf, IMSG_GET_RAW, tab->id, 0, -1,
550 &req, sizeof(req));
551 imsg_flush(netibuf);
554 static void
555 do_load_url(struct tab *tab, const char *url)
557 struct phos_uri uri;
558 struct proto *p;
559 struct proxy *proxy;
560 char *t;
562 if (tab->fd != -1) {
563 close(tab->fd);
564 tab->fd = -1;
565 free(tab->path);
566 tab->path = NULL;
569 tab->trust = TS_UNKNOWN;
571 memcpy(&uri, &tab->uri, sizeof(tab->uri));
572 if (!phos_resolve_uri_from_str(&uri, url, &tab->uri)) {
573 if (asprintf(&t, "#error loading %s\n>%s\n",
574 url, "Can't parse the URI") == -1)
575 die();
576 strlcpy(tab->hist_cur->h, url, sizeof(tab->hist_cur->h));
577 load_page_from_str(tab, t);
578 free(t);
579 return;
582 phos_serialize_uri(&tab->uri, tab->hist_cur->h,
583 sizeof(tab->hist_cur->h));
585 for (p = protos; p->schema != NULL; ++p) {
586 if (!strcmp(tab->uri.scheme, p->schema)) {
587 p->loadfn(tab, url);
588 return;
592 TAILQ_FOREACH(proxy, &proxies, proxies) {
593 if (!strcmp(tab->uri.scheme, proxy->match_proto)) {
594 load_via_proxy(tab, url, proxy);
595 return;
599 protos[0].loadfn(tab, url);
602 void
603 load_url(struct tab *tab, const char *url)
605 if (tab->hist_cur != NULL)
606 hist_clear_forward(&tab->hist, TAILQ_NEXT(tab->hist_cur, entries));
608 if ((tab->hist_cur = calloc(1, sizeof(*tab->hist_cur))) == NULL) {
609 event_loopbreak();
610 return;
613 tab->proxy = NULL;
615 hist_push(&tab->hist, tab->hist_cur);
616 do_load_url(tab, url);
617 erase_buffer(&tab->buffer);
620 int
621 load_previous_page(struct tab *tab)
623 struct hist *h;
625 if ((h = TAILQ_PREV(tab->hist_cur, mhisthead, entries)) == NULL)
626 return 0;
627 tab->hist_cur = h;
628 do_load_url(tab, h->h);
629 return 1;
632 int
633 load_next_page(struct tab *tab)
635 struct hist *h;
637 if ((h = TAILQ_NEXT(tab->hist_cur, entries)) == NULL)
638 return 0;
639 tab->hist_cur = h;
640 do_load_url(tab, h->h);
641 return 1;
644 void
645 stop_tab(struct tab *tab)
647 imsg_compose(netibuf, IMSG_STOP, tab->id, 0, -1, NULL, 0);
648 imsg_flush(netibuf);
650 if (tab->fd != -1) {
651 close(tab->fd);
652 tab->fd = -1;
653 free(tab->path);
654 tab->path = NULL;
655 load_page_from_str(tab, "Stopped.\n");
659 void
660 add_to_bookmarks(const char *str)
662 imsg_compose(fsibuf, IMSG_BOOKMARK_PAGE, 0, 0, -1, str, strlen(str)+1);
663 imsg_flush(fsibuf);
666 void
667 save_session(void)
669 struct tab *tab;
671 imsg_compose(fsibuf, IMSG_SESSION_START, 0, 0, -1, NULL, 0);
672 imsg_flush(fsibuf);
674 TAILQ_FOREACH(tab, &tabshead, tabs) {
675 imsg_compose(fsibuf, IMSG_SESSION_TAB, 0, 0, -1,
676 tab->hist_cur->h, strlen(tab->hist_cur->h)+1);
677 imsg_flush(fsibuf);
680 imsg_compose(fsibuf, IMSG_SESSION_END, 0, 0, -1, NULL, 0);
681 imsg_flush(fsibuf);
684 static void
685 session_new_tab_cb(const char *url)
687 new_tab(url);
690 static pid_t
691 start_child(enum telescope_process p, const char *argv0, int fd)
693 const char *argv[4];
694 int argc = 0;
695 pid_t pid;
697 switch (pid = fork()) {
698 case -1:
699 die();
700 case 0:
701 break;
702 default:
703 close(fd);
704 return pid;
707 if (dup2(fd, 3) == -1)
708 err(1, "cannot setup imsg fd");
710 argv[argc++] = argv0;
711 switch (p) {
712 case PROC_UI:
713 errx(1, "Can't start ui process");
714 case PROC_FS:
715 argv[argc++] = "-Tf";
716 break;
717 case PROC_NET:
718 argv[argc++] = "-Tn";
719 break;
722 argv[argc++] = NULL;
723 execvp(argv0, (char *const *)argv);
724 err(1, "execvp(%s)", argv0);
727 static void __attribute__((noreturn))
728 usage(int r)
730 fprintf(stderr, "USAGE: %s [-hn] [-c config] [url]\n", getprogname());
731 fprintf(stderr, "version: " PACKAGE " " VERSION "\n");
732 exit(r);
735 int
736 main(int argc, char * const *argv)
738 struct imsgbuf network_ibuf, fs_ibuf;
739 int net_fds[2], fs_fds[2];
740 int ch, configtest = 0, fail = 0;
741 int has_url = 0;
742 int proc = -1;
743 char path[PATH_MAX];
744 const char *url = NEW_TAB_URL;
745 const char *argv0;
747 argv0 = argv[0];
749 signal(SIGCHLD, SIG_IGN);
750 signal(SIGPIPE, SIG_IGN);
752 if (getenv("NO_COLOR") != NULL)
753 enable_colors = 0;
755 strlcpy(path, getenv("HOME"), sizeof(path));
756 strlcat(path, "/.telescope/config", sizeof(path));
758 while ((ch = getopt(argc, argv, "c:hnT:")) != -1) {
759 switch (ch) {
760 case 'c':
761 fail = 1;
762 strlcpy(path, optarg, sizeof(path));
763 break;
764 case 'n':
765 configtest = 1;
766 break;
767 case 'h':
768 usage(0);
769 case 'T':
770 switch (*optarg) {
771 case 'f':
772 proc = PROC_FS;
773 break;
774 case 'n':
775 proc = PROC_NET;
776 break;
777 default:
778 errx(1, "invalid process spec %c",
779 *optarg);
781 break;
782 default:
783 usage(1);
787 argc -= optind;
788 argv += optind;
790 if (proc != -1) {
791 if (argc > 0)
792 usage(1);
793 else if (proc == PROC_FS)
794 return fs_main();
795 else if (proc == PROC_NET)
796 return client_main();
797 else
798 usage(1);
801 if (argc != 0) {
802 has_url = 1;
803 url = argv[0];
806 /* setup keys before reading the config */
807 TAILQ_INIT(&global_map.m);
808 global_map.unhandled_input = global_key_unbound;
809 TAILQ_INIT(&minibuffer_map.m);
811 config_init();
812 parseconfig(path, fail);
813 if (configtest){
814 puts("config OK");
815 exit(0);
818 /* Start children. */
819 if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, fs_fds) == -1)
820 err(1, "socketpair");
821 start_child(PROC_FS, argv0, fs_fds[1]);
822 imsg_init(&fs_ibuf, fs_fds[0]);
823 fsibuf = &fs_ibuf;
825 if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, net_fds) == -1)
826 err(1, "socketpair");
827 start_child(PROC_NET, argv0, net_fds[1]);
828 imsg_init(&network_ibuf, net_fds[0]);
829 netibuf = &network_ibuf;
831 setproctitle("ui");
833 /* initialize tofu & load certificates */
834 fs_init();
835 tofu_init(&certs, 5, offsetof(struct tofu_entry, domain));
836 load_certs(&certs);
838 TAILQ_INIT(&tabshead);
839 TAILQ_INIT(&proxies);
841 event_init();
843 event_set(&netev, netibuf->fd, EV_READ | EV_PERSIST,
844 handle_dispatch_imsg, netibuf);
845 event_add(&netev, NULL);
847 event_set(&fsev, fsibuf->fd, EV_READ | EV_PERSIST,
848 handle_dispatch_imsg, fsibuf);
849 event_add(&fsev, NULL);
851 if (ui_init()) {
852 load_last_session(session_new_tab_cb);
853 if (has_url || TAILQ_EMPTY(&tabshead))
854 new_tab(url);
856 sandbox_ui_process();
857 event_dispatch();
858 ui_end();
861 imsg_compose(netibuf, IMSG_QUIT, 0, 0, -1, NULL, 0);
862 imsg_flush(netibuf);
864 imsg_compose(fsibuf, IMSG_QUIT, 0, 0, -1, NULL, 0);
865 imsg_flush(fsibuf);
867 return 0;