2 5e11c00c 2021-03-02 op * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
4 5e11c00c 2021-03-02 op * Permission to use, copy, modify, and distribute this software for any
5 5e11c00c 2021-03-02 op * purpose with or without fee is hereby granted, provided that the above
6 5e11c00c 2021-03-02 op * copyright notice and this permission notice appear in all copies.
8 5e11c00c 2021-03-02 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 5e11c00c 2021-03-02 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 5e11c00c 2021-03-02 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 5e11c00c 2021-03-02 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 5e11c00c 2021-03-02 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 5e11c00c 2021-03-02 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 5e11c00c 2021-03-02 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 5e11c00c 2021-03-02 op * - move the various
20 5e11c00c 2021-03-02 op * imsg_compose(...);
21 5e11c00c 2021-03-02 op * imsg_flush(...);
22 5e11c00c 2021-03-02 op * to something more asynchronous
25 5e11c00c 2021-03-02 op #include <telescope.h>
27 5e11c00c 2021-03-02 op #include <sys/types.h>
28 5e11c00c 2021-03-02 op #include <sys/socket.h>
30 5e11c00c 2021-03-02 op #include <netinet/in.h>
32 5e11c00c 2021-03-02 op #include <assert.h>
33 5e11c00c 2021-03-02 op #include <ctype.h>
34 5e11c00c 2021-03-02 op #include <errno.h>
35 5e11c00c 2021-03-02 op #include <netdb.h>
36 5e11c00c 2021-03-02 op #include <stdarg.h>
37 5e11c00c 2021-03-02 op #include <stdio.h>
38 5e11c00c 2021-03-02 op #include <stdlib.h>
39 5e11c00c 2021-03-02 op #include <string.h>
40 5e11c00c 2021-03-02 op #include <tls.h>
41 5e11c00c 2021-03-02 op #include <unistd.h>
43 cc4953ef 2021-03-16 op #if HAVE_ASR_RUN
44 cc4953ef 2021-03-16 op # include <asr.h>
47 35e1f40a 2021-03-14 op static struct event imsgev;
48 5e11c00c 2021-03-02 op static struct tls_config *tlsconf;
49 5e11c00c 2021-03-02 op static struct imsgbuf *ibuf;
53 5e11c00c 2021-03-02 op static void die(void) __attribute__((__noreturn__));
55 cc4953ef 2021-03-16 op #if HAVE_ASR_RUN
56 cc4953ef 2021-03-16 op static void try_to_connect(int, short, void*);
57 cc4953ef 2021-03-16 op static void query_done(struct asr_result*, void*);
58 cc4953ef 2021-03-16 op static void async_conn_towards(struct req*);
60 4e600d30 2021-03-29 op static void blocking_conn_towards(struct req*);
63 a237223e 2021-03-16 op static void close_with_err(struct req*, const char*);
64 a237223e 2021-03-16 op static void close_with_errf(struct req*, const char*, ...) __attribute__((format(printf, 2, 3)));
65 5e11c00c 2021-03-02 op static struct req *req_by_id(uint32_t);
66 15354eed 2021-03-10 op static struct req *req_by_id_try(uint32_t);
68 cc4953ef 2021-03-16 op static void setup_tls(struct req*);
69 5e11c00c 2021-03-02 op static void do_handshake(int, short, void*);
70 5e11c00c 2021-03-02 op static void write_request(int, short, void*);
71 5e11c00c 2021-03-02 op static void read_reply(int, short, void*);
72 5e11c00c 2021-03-02 op static void parse_reply(struct req*);
73 5e11c00c 2021-03-02 op static void copy_body(int, short, void*);
75 5e11c00c 2021-03-02 op static void handle_get(struct imsg*, size_t);
76 5e11c00c 2021-03-02 op static void handle_cert_status(struct imsg*, size_t);
77 0972d8b2 2021-03-02 op static void handle_proceed(struct imsg*, size_t);
78 5e11c00c 2021-03-02 op static void handle_stop(struct imsg*, size_t);
79 5e11c00c 2021-03-02 op static void handle_quit(struct imsg*, size_t);
80 1304bbdd 2021-03-15 op static void handle_dispatch_imsg(int, short, void*);
82 723bee54 2021-03-09 op /* TODO: making this customizable */
83 723bee54 2021-03-09 op struct timeval timeout_for_handshake = { 5, 0 };
85 5e11c00c 2021-03-02 op static imsg_handlerfn *handlers[] = {
86 848779c2 2021-03-29 op [IMSG_GET] = handle_get,
87 848779c2 2021-03-29 op [IMSG_CERT_STATUS] = handle_cert_status,
88 848779c2 2021-03-29 op [IMSG_PROCEED] = handle_proceed,
89 848779c2 2021-03-29 op [IMSG_STOP] = handle_stop,
90 848779c2 2021-03-29 op [IMSG_QUIT] = handle_quit,
93 5e11c00c 2021-03-02 op typedef void (*statefn)(int, short, void*);
95 5e11c00c 2021-03-02 op TAILQ_HEAD(, req) reqhead;
96 5e11c00c 2021-03-02 op /* a pending request */
98 5e11c00c 2021-03-02 op struct event ev;
99 5e11c00c 2021-03-02 op struct url url;
102 5e11c00c 2021-03-02 op struct tls *ctx;
103 5e11c00c 2021-03-02 op char buf[1024];
106 cc4953ef 2021-03-16 op #if HAVE_ASR_RUN
107 cc4953ef 2021-03-16 op struct addrinfo hints, *servinfo, *p;
108 cc4953ef 2021-03-16 op struct event_asr *asrev;
111 5e11c00c 2021-03-02 op TAILQ_ENTRY(req) reqs;
114 5e11c00c 2021-03-02 op static inline void
115 5e11c00c 2021-03-02 op yield_r(struct req *req, statefn fn, struct timeval *tv)
117 5e11c00c 2021-03-02 op event_once(req->fd, EV_READ, fn, req, tv);
120 5e11c00c 2021-03-02 op static inline void
121 5e11c00c 2021-03-02 op yield_w(struct req *req, statefn fn, struct timeval *tv)
123 5e11c00c 2021-03-02 op event_once(req->fd, EV_WRITE, fn, req, tv);
126 5e11c00c 2021-03-02 op static inline void
127 5e11c00c 2021-03-02 op advance_buf(struct req *req, size_t len)
129 5e11c00c 2021-03-02 op assert(len <= req->off);
131 5e11c00c 2021-03-02 op req->off -= len;
132 5e11c00c 2021-03-02 op memmove(req->buf, req->buf + len, req->off);
135 5e11c00c 2021-03-02 op static void __attribute__((__noreturn__))
138 5e11c00c 2021-03-02 op abort(); /* TODO */
141 cc4953ef 2021-03-16 op #if HAVE_ASR_RUN
143 cc4953ef 2021-03-16 op try_to_connect(int fd, short ev, void *d)
145 cc4953ef 2021-03-16 op struct req *req = d;
146 cc4953ef 2021-03-16 op int error = 0;
147 cc4953ef 2021-03-16 op socklen_t len = sizeof(error);
150 cc4953ef 2021-03-16 op if (req->p == NULL)
153 cc4953ef 2021-03-16 op if (req->fd != -1) {
154 cc4953ef 2021-03-16 op if (getsockopt(req->fd, SOL_SOCKET, SO_ERROR, &error, &len) == -1)
156 cc4953ef 2021-03-16 op if (error != 0) {
157 cc4953ef 2021-03-16 op errno = error;
163 cc4953ef 2021-03-16 op req->fd = socket(req->p->ai_family, req->p->ai_socktype, req->p->ai_protocol);
164 20d2d786 2021-03-16 op if (req->fd == -1) {
165 cc4953ef 2021-03-16 op req->p = req->p->ai_next;
168 cc4953ef 2021-03-16 op mark_nonblock(req->fd);
169 cc4953ef 2021-03-16 op if (connect(req->fd, req->p->ai_addr, req->p->ai_addrlen) == 0)
171 20d2d786 2021-03-16 op yield_w(req, try_to_connect, NULL);
176 cc4953ef 2021-03-16 op freeaddrinfo(req->servinfo);
177 cc4953ef 2021-03-16 op close_with_errf(req, "failed to connect to %s",
178 cc4953ef 2021-03-16 op req->url.host);
182 cc4953ef 2021-03-16 op freeaddrinfo(req->servinfo);
183 cc4953ef 2021-03-16 op setup_tls(req);
187 cc4953ef 2021-03-16 op query_done(struct asr_result *res, void *d)
189 cc4953ef 2021-03-16 op struct req *req = d;
191 cc4953ef 2021-03-16 op req->asrev = NULL;
192 cc4953ef 2021-03-16 op if (res->ar_gai_errno != 0) {
193 cc4953ef 2021-03-16 op close_with_errf(req, "failed to resolve %s: %s",
194 cc4953ef 2021-03-16 op req->url.host, gai_strerror(res->ar_gai_errno));
198 cc4953ef 2021-03-16 op req->fd = -1;
199 cc4953ef 2021-03-16 op req->servinfo = res->ar_addrinfo;
200 cc4953ef 2021-03-16 op req->p = res->ar_addrinfo;
201 cc4953ef 2021-03-16 op try_to_connect(0, 0, req);
205 cc4953ef 2021-03-16 op async_conn_towards(struct req *req)
207 cc4953ef 2021-03-16 op struct asr_query *q;
208 cc4953ef 2021-03-16 op const char *proto = "1965";
210 cc4953ef 2021-03-16 op if (*req->url.port != '\0')
211 cc4953ef 2021-03-16 op proto = req->url.port;
213 cc4953ef 2021-03-16 op req->hints.ai_family = AF_UNSPEC;
214 cc4953ef 2021-03-16 op req->hints.ai_socktype = SOCK_STREAM;
215 cc4953ef 2021-03-16 op q = getaddrinfo_async(req->url.host, proto, &req->hints, NULL);
216 cc4953ef 2021-03-16 op req->asrev = event_asr_run(q, query_done, req);
220 4e600d30 2021-03-29 op blocking_conn_towards(struct req *req)
222 5e11c00c 2021-03-02 op struct addrinfo hints, *servinfo, *p;
223 4e600d30 2021-03-29 op struct url *url = &req->url;
224 5e11c00c 2021-03-02 op int status, sock;
225 5e11c00c 2021-03-02 op const char *proto = "1965";
227 5e11c00c 2021-03-02 op if (*url->port != '\0')
228 5e11c00c 2021-03-02 op proto = url->port;
230 5e11c00c 2021-03-02 op memset(&hints, 0, sizeof(hints));
231 5e11c00c 2021-03-02 op hints.ai_family = AF_UNSPEC;
232 5e11c00c 2021-03-02 op hints.ai_socktype = SOCK_STREAM;
234 5e11c00c 2021-03-02 op if ((status = getaddrinfo(url->host, proto, &hints, &servinfo))) {
235 4e600d30 2021-03-29 op close_with_errf(req, "failed to resolve %s: %s",
236 5e11c00c 2021-03-02 op url->host, gai_strerror(status));
241 5e11c00c 2021-03-02 op for (p = servinfo; p != NULL; p = p->ai_next) {
242 5e11c00c 2021-03-02 op if ((sock = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1)
244 5e11c00c 2021-03-02 op if (connect(sock, p->ai_addr, p->ai_addrlen) != -1)
248 4e600d30 2021-03-29 op freeaddrinfo(servinfo);
250 4e600d30 2021-03-29 op if (sock == -1) {
251 4e600d30 2021-03-29 op close_with_errf(req, "couldn't connect to %s", url->host);
255 4e600d30 2021-03-29 op req->fd = sock;
256 4e600d30 2021-03-29 op mark_nonblock(req->fd);
257 4e600d30 2021-03-29 op setup_tls(req);
261 5e11c00c 2021-03-02 op static struct req *
262 5e11c00c 2021-03-02 op req_by_id(uint32_t id)
264 15354eed 2021-03-10 op struct req *r;
266 15354eed 2021-03-10 op if ((r = req_by_id_try(id)) == NULL)
271 15354eed 2021-03-10 op static struct req *
272 15354eed 2021-03-10 op req_by_id_try(uint32_t id)
274 5e11c00c 2021-03-02 op struct req *r;
276 5e11c00c 2021-03-02 op TAILQ_FOREACH(r, &reqhead, reqs) {
277 5e11c00c 2021-03-02 op if (r->id == id)
285 5e11c00c 2021-03-02 op close_conn(int fd, short ev, void *d)
287 5e11c00c 2021-03-02 op struct req *req = d;
289 cc4953ef 2021-03-16 op #if HAVE_ASR_RUN
290 cc4953ef 2021-03-16 op if (req->asrev != NULL)
291 cc4953ef 2021-03-16 op event_asr_abort(req->asrev);
294 5e11c00c 2021-03-02 op if (req->ctx != NULL) {
295 5e11c00c 2021-03-02 op switch (tls_close(req->ctx)) {
296 5e11c00c 2021-03-02 op case TLS_WANT_POLLIN:
297 5e11c00c 2021-03-02 op yield_r(req, close_conn, NULL);
299 5e11c00c 2021-03-02 op case TLS_WANT_POLLOUT:
300 5e11c00c 2021-03-02 op yield_w(req, close_conn, NULL);
304 5e11c00c 2021-03-02 op tls_free(req->ctx);
307 5e11c00c 2021-03-02 op TAILQ_REMOVE(&reqhead, req, reqs);
308 5e11c00c 2021-03-02 op if (req->fd != -1)
309 5e11c00c 2021-03-02 op close(req->fd);
314 5e11c00c 2021-03-02 op close_with_err(struct req *req, const char *err)
316 5e11c00c 2021-03-02 op imsg_compose(ibuf, IMSG_ERR, req->id, 0, -1, err, strlen(err)+1);
317 5e11c00c 2021-03-02 op imsg_flush(ibuf);
318 5e11c00c 2021-03-02 op close_conn(0, 0, req);
322 a237223e 2021-03-16 op close_with_errf(struct req *req, const char *fmt, ...)
327 a237223e 2021-03-16 op va_start(ap, fmt);
328 a237223e 2021-03-16 op if (vasprintf(&s, fmt, ap) == -1)
332 a237223e 2021-03-16 op close_with_err(req, s);
337 cc4953ef 2021-03-16 op setup_tls(struct req *req)
339 cc4953ef 2021-03-16 op if ((req->ctx = tls_client()) == NULL) {
340 cc4953ef 2021-03-16 op close_with_errf(req, "tls_client: %s", strerror(errno));
343 cc4953ef 2021-03-16 op if (tls_configure(req->ctx, tlsconf) == -1) {
344 cc4953ef 2021-03-16 op close_with_errf(req, "tls_configure: %s", tls_error(req->ctx));
347 cc4953ef 2021-03-16 op if (tls_connect_socket(req->ctx, req->fd, req->url.host) == -1) {
348 cc4953ef 2021-03-16 op close_with_errf(req, "tls_connect_socket: %s", tls_error(req->ctx));
351 cc4953ef 2021-03-16 op yield_w(req, do_handshake, &timeout_for_handshake);
355 5e11c00c 2021-03-02 op do_handshake(int fd, short ev, void *d)
357 5e11c00c 2021-03-02 op struct req *req = d;
358 5e11c00c 2021-03-02 op const char *hash;
360 723bee54 2021-03-09 op if (ev == EV_TIMEOUT) {
361 723bee54 2021-03-09 op close_with_err(req, "Timeout loading page");
365 5e11c00c 2021-03-02 op switch (tls_handshake(req->ctx)) {
366 5e11c00c 2021-03-02 op case TLS_WANT_POLLIN:
367 5e11c00c 2021-03-02 op yield_r(req, do_handshake, NULL);
369 5e11c00c 2021-03-02 op case TLS_WANT_POLLOUT:
370 5e11c00c 2021-03-02 op yield_w(req, do_handshake, NULL);
374 5e11c00c 2021-03-02 op hash = tls_peer_cert_hash(req->ctx);
375 282a1d0a 2021-03-16 op if (hash == NULL) {
376 a237223e 2021-03-16 op close_with_errf(req, "handshake failed: %s", tls_error(req->ctx));
379 5e11c00c 2021-03-02 op imsg_compose(ibuf, IMSG_CHECK_CERT, req->id, 0, -1, hash, strlen(hash)+1);
380 5e11c00c 2021-03-02 op imsg_flush(ibuf);
384 5e11c00c 2021-03-02 op write_request(int fd, short ev, void *d)
386 5e11c00c 2021-03-02 op struct req *req = d;
389 ff6cf34b 2021-03-29 op char buf[1027]; /* URL + \r\n\0 */
391 5e11c00c 2021-03-02 op strlcpy(buf, "gemini://", sizeof(buf));
392 5e11c00c 2021-03-02 op strlcat(buf, req->url.host, sizeof(buf));
393 5e11c00c 2021-03-02 op strlcat(buf, "/", sizeof(buf));
394 5e11c00c 2021-03-02 op strlcat(buf, req->url.path, sizeof(buf));
396 5e11c00c 2021-03-02 op if (req->url.query[0] != '\0') {
397 5e11c00c 2021-03-02 op strlcat(buf, "?", sizeof(buf));
398 5e11c00c 2021-03-02 op strlcat(buf, req->url.query, sizeof(buf));
401 5e11c00c 2021-03-02 op len = strlcat(buf, "\r\n", sizeof(buf));
403 5e11c00c 2021-03-02 op assert(len <= sizeof(buf));
405 5e11c00c 2021-03-02 op switch (r = tls_write(req->ctx, buf, len)) {
407 a237223e 2021-03-16 op close_with_errf(req, "tls_write: %s", tls_error(req->ctx));
409 5e11c00c 2021-03-02 op case TLS_WANT_POLLIN:
410 5e11c00c 2021-03-02 op yield_r(req, write_request, NULL);
412 5e11c00c 2021-03-02 op case TLS_WANT_POLLOUT:
413 5e11c00c 2021-03-02 op yield_w(req, write_request, NULL);
416 5e11c00c 2021-03-02 op /* assume r == len */
418 5e11c00c 2021-03-02 op yield_r(req, read_reply, NULL);
424 5e11c00c 2021-03-02 op read_reply(int fd, short ev, void *d)
426 5e11c00c 2021-03-02 op struct req *req = d;
431 5e11c00c 2021-03-02 op buf = req->buf + req->off;
432 5e11c00c 2021-03-02 op len = sizeof(req->buf) - req->off;
434 5e11c00c 2021-03-02 op switch (r = tls_read(req->ctx, buf, len)) {
436 a237223e 2021-03-16 op close_with_errf(req, "tls_read: %s", tls_error(req->ctx));
438 5e11c00c 2021-03-02 op case TLS_WANT_POLLIN:
439 5e11c00c 2021-03-02 op yield_r(req, read_reply, NULL);
441 5e11c00c 2021-03-02 op case TLS_WANT_POLLOUT:
442 5e11c00c 2021-03-02 op yield_w(req, read_reply, NULL);
445 5e11c00c 2021-03-02 op req->off += r;
447 e62289e7 2021-03-16 op if (memmem(req->buf, req->off, "\r\n", 2) != NULL)
448 5e11c00c 2021-03-02 op parse_reply(req);
449 5e11c00c 2021-03-02 op else if (req->off == sizeof(req->buf))
450 5e11c00c 2021-03-02 op close_with_err(req, "invalid response");
452 5e11c00c 2021-03-02 op yield_r(req, read_reply, NULL);
458 5e11c00c 2021-03-02 op parse_reply(struct req *req)
464 5e11c00c 2021-03-02 op if (req->off < 4)
467 5e11c00c 2021-03-02 op if (!isdigit(req->buf[0]) || !isdigit(req->buf[1]))
470 5e11c00c 2021-03-02 op code = (req->buf[0] - '0')*10 + (req->buf[1] - '0');
472 5e11c00c 2021-03-02 op if (!isspace(req->buf[2]))
475 5e11c00c 2021-03-02 op advance_buf(req, 3);
476 e62289e7 2021-03-16 op if ((e = memmem(req->buf, req->off, "\r\n", 2)) == NULL)
481 5e11c00c 2021-03-02 op len = e - req->buf;
482 5e11c00c 2021-03-02 op imsg_compose(ibuf, IMSG_GOT_CODE, req->id, 0, -1, &code, sizeof(code));
483 155dac7f 2021-03-29 op imsg_compose(ibuf, IMSG_GOT_META, req->id, 0, -1, req->buf, len);
484 5e11c00c 2021-03-02 op imsg_flush(ibuf);
486 723bee54 2021-03-09 op if (code != 20)
487 723bee54 2021-03-09 op close_conn(0, 0, req);
489 58ba20cd 2021-03-18 op advance_buf(req, len+1); /* skip \n too */
494 5e11c00c 2021-03-02 op close_with_err(req, "malformed request");
498 5e11c00c 2021-03-02 op copy_body(int fd, short ev, void *d)
500 5e11c00c 2021-03-02 op struct req *req = d;
504 72a79cfb 2021-03-13 op if (req->off != 0) {
505 72a79cfb 2021-03-13 op imsg_compose(ibuf, IMSG_BUF, req->id, 0, -1,
506 72a79cfb 2021-03-13 op req->buf, req->off);
507 72a79cfb 2021-03-13 op imsg_flush(ibuf);
508 1deaf397 2021-03-14 op req->off = 0;
511 72a79cfb 2021-03-13 op switch (r = tls_read(req->ctx, req->buf, sizeof(req->buf))) {
512 5e11c00c 2021-03-02 op case TLS_WANT_POLLIN:
513 5e11c00c 2021-03-02 op yield_r(req, copy_body, NULL);
515 5e11c00c 2021-03-02 op case TLS_WANT_POLLOUT:
516 5e11c00c 2021-03-02 op yield_w(req, copy_body, NULL);
519 5e11c00c 2021-03-02 op imsg_compose(ibuf, IMSG_EOF, req->id, 0, -1, NULL, 0);
520 5e11c00c 2021-03-02 op imsg_flush(ibuf);
521 5e11c00c 2021-03-02 op close_conn(0, 0, req);
524 72a79cfb 2021-03-13 op req->off = r;
530 5e11c00c 2021-03-02 op handle_get(struct imsg *imsg, size_t datalen)
532 5e11c00c 2021-03-02 op struct req *req;
533 5e11c00c 2021-03-02 op const char *e;
536 5e11c00c 2021-03-02 op data = imsg->data;
538 5e11c00c 2021-03-02 op if (data[datalen-1] != '\0')
541 5e11c00c 2021-03-02 op if ((req = calloc(1, sizeof(*req))) == NULL)
544 5e11c00c 2021-03-02 op req->id = imsg->hdr.peerid;
545 71a2feab 2021-03-10 op TAILQ_INSERT_HEAD(&reqhead, req, reqs);
547 5e11c00c 2021-03-02 op if (!url_parse(imsg->data, &req->url, &e)) {
548 5e11c00c 2021-03-02 op close_with_err(req, e);
552 cc4953ef 2021-03-16 op #if HAVE_ASR_RUN
553 cc4953ef 2021-03-16 op async_conn_towards(req);
555 4e600d30 2021-03-29 op blocking_conn_towards(req);
560 5e11c00c 2021-03-02 op handle_cert_status(struct imsg *imsg, size_t datalen)
562 5e11c00c 2021-03-02 op struct req *req;
565 5e11c00c 2021-03-02 op req = req_by_id(imsg->hdr.peerid);
567 5e11c00c 2021-03-02 op if (datalen < sizeof(is_ok))
569 5e11c00c 2021-03-02 op memcpy(&is_ok, imsg->data, sizeof(is_ok));
572 5e11c00c 2021-03-02 op yield_w(req, write_request, NULL);
574 5e11c00c 2021-03-02 op close_conn(0, 0, req);
578 0972d8b2 2021-03-02 op handle_proceed(struct imsg *imsg, size_t datalen)
580 e4304954 2021-03-14 op yield_r(req_by_id(imsg->hdr.peerid),
581 e4304954 2021-03-14 op copy_body, NULL);
585 5e11c00c 2021-03-02 op handle_stop(struct imsg *imsg, size_t datalen)
587 5e11c00c 2021-03-02 op struct req *req;
589 15354eed 2021-03-10 op if ((req = req_by_id_try(imsg->hdr.peerid)) == NULL)
591 5e11c00c 2021-03-02 op close_conn(0, 0, req);
595 5e11c00c 2021-03-02 op handle_quit(struct imsg *imsg, size_t datalen)
597 5e11c00c 2021-03-02 op event_loopbreak();
601 1304bbdd 2021-03-15 op handle_dispatch_imsg(int fd, short ev, void *d)
603 5e11c00c 2021-03-02 op struct imsgbuf *ibuf = d;
604 1304bbdd 2021-03-15 op dispatch_imsg(ibuf, handlers, sizeof(handlers));
608 5e11c00c 2021-03-02 op client_main(struct imsgbuf *b)
612 5e11c00c 2021-03-02 op TAILQ_INIT(&reqhead);
614 5e11c00c 2021-03-02 op if ((tlsconf = tls_config_new()) == NULL)
616 5e11c00c 2021-03-02 op tls_config_insecure_noverifycert(tlsconf);
617 d6cd2fc1 2021-03-25 op tls_config_insecure_noverifyname(tlsconf);
619 5e11c00c 2021-03-02 op event_init();
621 1304bbdd 2021-03-15 op event_set(&imsgev, ibuf->fd, EV_READ | EV_PERSIST, handle_dispatch_imsg, ibuf);
622 5e11c00c 2021-03-02 op event_add(&imsgev, NULL);
624 ebdcadbf 2021-03-12 op sandbox_network_process();
626 5e11c00c 2021-03-02 op event_dispatch();