2 * Copyright (c) 2022 Omar Polo <op@omarpolo.com>
3 * Copyright (c) 2006 - 2015 Reyk Floeter <reyk@openbsd.org>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #include <sys/types.h>
19 #include <sys/queue.h>
21 #include <sys/socket.h>
24 #include <netinet/in.h>
25 #include <arpa/inet.h>
49 #define MINIMUM(a, b) ((a) < (b) ? (a) : (b))
52 # define G_TOUT(t) ((t).tv_sec)
54 # define G_TOUT(t) (t)
57 /* provided by OpenBSD' base libevent but not in any header? */
58 extern void bufferevent_read_pressure_cb(struct evbuffer *, size_t,
61 void proxy_init(struct privsep *, struct privsep_proc *, void *);
62 int proxy_launch(struct galileo *);
63 void proxy_inflight_dec(const char *);
64 int proxy_dispatch_parent(int, struct privsep_proc *, struct imsg *);
65 int proxy_resurl(struct client *, const char *, char *, size_t);
66 void proxy_translate_gemtext(struct client *);
67 void proxy_resolved(struct asr_result *, void *);
68 void proxy_connect(int, short, void *);
69 int proxy_start_reply(struct client *, int, const char *);
70 void proxy_read(struct bufferevent *, void *);
71 void proxy_write(struct bufferevent *, void *);
72 void proxy_error(struct bufferevent *, short, void *);
73 int proxy_bufferevent_add(struct event *, int);
74 void proxy_tls_writecb(int, short, void *);
75 void proxy_tls_readcb(int, short, void *);
77 static struct privsep_proc procs[] = {
78 { "parent", PROC_PARENT, proxy_dispatch_parent },
81 volatile int proxy_clients;
82 volatile int proxy_inflight;
83 uint32_t proxy_fcg_id;
86 proxy(struct privsep *ps, struct privsep_proc *p)
88 proc_run(ps, p, procs, nitems(procs), proxy_init, NULL);
92 proxy_init(struct privsep *ps, struct privsep_proc *p, void *arg)
94 if (config_init(ps->ps_env) == -1)
95 fatal("failed to initialize configuration");
97 /* We use a custom shutdown callback */
98 /* p->p_shutdown = proxy_shutdown */
100 if (pledge("stdio recvfd unix inet dns", NULL) == -1)
105 proxy_launch(struct galileo *env)
107 event_add(&env->sc_evsock, NULL);
112 proxy_purge(struct proxy *pr)
118 proxy_inflight_dec(const char *why)
121 log_debug("%s: inflight decremented, now %d, %s",
122 __func__, proxy_inflight, why);
126 proxy_dispatch_parent(int fd, struct privsep_proc *p, struct imsg *imsg)
128 struct privsep *ps = p->p_ps;
129 struct galileo *env = ps->ps_env;
131 switch (imsg->hdr.type) {
133 if (config_getproxy(env, imsg) == -1)
134 fatal("config_getproxy");
139 env->sc_sock_fd = config_getsock(env, imsg);
140 if (env->sc_sock_fd == -1)
141 fatal("config_getsock");
143 event_set(&env->sc_evsock, env->sc_sock_fd,
144 EV_READ | EV_PERSIST, fcgi_accept, env);
145 evtimer_set(&env->sc_evpause, fcgi_accept, env);
148 config_getcfg(env, imsg);
154 config_getreset(env, imsg);
164 portok(const char **url, struct client *clt)
166 const char *u = *url;
167 const char *port = clt->clt_pc->proxy_port;
172 if (*u == '\0' || *u == '/' || *u == '?' || *u == '#')
177 if (strncmp(u, port, len) != 0)
180 if (*u != '\0' && *u != '/' && *u != '?' && *u != '#')
187 proxy_resurl(struct client *clt, const char *url, char *buf, size_t len)
192 if (clt->clt_server_name == NULL)
195 l = strlen(clt->clt_server_name);
198 log_warn("%s: zero-sized buffer!", __func__);
202 /* look if it's an absolute URI */
203 if (strncmp(url, "//", 2) == 0) {
205 if (strncmp(tmp, clt->clt_server_name, l) != 0)
209 if (!portok(&tmp, clt))
212 } else if (strncmp(url, "gemini://", 9) == 0) {
214 if (strncmp(tmp, clt->clt_server_name, l) != 0)
218 if (!portok(&tmp, clt))
223 while (isalpha((unsigned char)*tmp) || *tmp == '+')
225 if (strncmp(tmp, "://", 3) == 0)
229 /* maybe it's an absolute path? */
230 if (*url == '\0' || *url == '/') {
231 if (strlcpy(buf, clt->clt_script_name, len) >= len)
233 if (strlcat(buf, url + 1, len) >= len)
238 /* otherwise, leave it as it is */
240 if (strlcpy(buf, url, len) >= len)
246 match_image_heur(const char *url)
248 return (fnmatch("*.jpg", url, 0) == 0 ||
249 fnmatch("*.jpeg", url, 0) == 0 ||
250 fnmatch("*.gif", url, 0) == 0 ||
251 fnmatch("*.png", url, 0) == 0 ||
252 fnmatch("*.svg", url, 0) == 0 ||
253 fnmatch("*.webp", url, 0) == 0);
257 gemtext_translate_line(struct client *clt, char *line)
259 struct template *tp = clt->clt_tp;
263 /* preformatted line / closing */
264 if (clt->clt_translate & TR_PRE) {
265 if (!strncmp(line, "```", 3)) {
266 clt->clt_translate &= ~TR_PRE;
267 return (tp_pre_close(clt->clt_tp));
270 if (tp_htmlescape(clt->clt_tp, line) == -1)
272 return (tp_write(tp, "\n", 1));
276 if (!strncmp(line, "* ", 2)) {
277 if (clt->clt_translate & TR_NAV) {
278 if (tp_writes(tp, "</ul></nav>") == -1)
280 clt->clt_translate &= ~TR_NAV;
283 if (!(clt->clt_translate & TR_LIST)) {
284 if (tp_writes(tp, "<ul>") == -1)
286 clt->clt_translate |= TR_LIST;
289 if (tp_writes(tp, "<li>") == -1 ||
290 tp_htmlescape(clt->clt_tp, line + 2) == -1 ||
291 tp_writes(tp, "</li>") == -1)
296 if (clt->clt_translate & TR_LIST) {
297 if (tp_writes(tp, "</ul>") == -1)
299 clt->clt_translate &= ~TR_LIST;
303 if (!strncmp(line, "=>", 2)) {
307 line += strspn(line, " \t");
309 label = line + strcspn(line, " \t");
314 label += strspn(label, " \t");
319 if (proxy_resurl(clt, line, buf, sizeof(buf)) == 0)
322 url = line; /* leave the URL as it is */
324 if (!(clt->clt_pc->flags & PROXY_NO_IMGPRV) &&
325 match_image_heur(url)) {
326 if (clt->clt_translate & TR_NAV) {
327 if (tp_writes(tp, "</ul></nav>") == -1)
329 clt->clt_translate &= ~TR_NAV;
332 if (tp_figure(tp, url, label) == -1)
338 if (!(clt->clt_translate & TR_NAV)) {
339 if (tp_writes(tp, "<nav><ul>") == -1)
341 clt->clt_translate |= TR_NAV;
344 if (tp_writes(tp, "<li><a href='") == -1)
347 if (tp_urlescape(clt->clt_tp, url) == -1 ||
348 tp_writes(tp, "'>") == -1 ||
349 tp_htmlescape(clt->clt_tp, label) == -1 ||
350 tp_writes(tp, "</a></li>") == -1)
356 if (clt->clt_translate & TR_NAV) {
357 if (tp_writes(tp, "</ul></nav>") == -1)
359 clt->clt_translate &= ~TR_NAV;
363 if (!strncmp(line, "```", 3)) {
365 line += strspn(line, " \t");
367 clt->clt_translate |= TR_PRE;
368 return (tp_pre_open(tp, line));
373 if (tp_writes(tp, "<blockquote>") == -1 ||
374 tp_htmlescape(clt->clt_tp, line + 1) == -1 ||
375 tp_writes(tp, "</blockquote>") == -1)
381 if (!strncmp(line, "###", 3)) {
382 if (tp_writes(tp, "<h3>") == -1 ||
383 tp_htmlescape(clt->clt_tp, line + 3) == -1 ||
384 tp_writes(tp, "</h3>") == -1)
388 if (!strncmp(line, "##", 2)) {
389 if (tp_writes(tp, "<h2>") == -1 ||
390 tp_htmlescape(clt->clt_tp, line + 2) == -1 ||
391 tp_writes(tp, "</h2>") == -1)
395 if (!strncmp(line, "#", 1)) {
396 if (tp_writes(tp, "<h1>") == -1 ||
397 tp_htmlescape(clt->clt_tp, line + 1) == -1 ||
398 tp_writes(tp, "</h1>") == -1)
403 /* Not following strictly the gemini specification... */
408 if (tp_writes(tp, "<p>") == -1 ||
409 tp_htmlescape(clt->clt_tp, line) == -1 ||
410 tp_writes(tp, "</p>") == -1)
417 proxy_translate_gemtext(struct client *clt)
419 struct bufferevent *bev = clt->clt_bev;
420 struct evbuffer *src = EVBUFFER_INPUT(bev);
426 line = evbuffer_readln(src, &len, EVBUFFER_EOL_CRLF);
430 r = gemtext_translate_line(clt, line);
437 struct proxy_config *
438 proxy_match(struct galileo *env, const char *name)
445 TAILQ_FOREACH(pr, &env->sc_proxies, pr_entry) {
446 if (!strcmp(name, pr->pr_conf.host))
447 return (&pr->pr_conf);
454 proxy_start_request(struct galileo *env, struct client *clt)
456 struct addrinfo hints;
457 struct asr_query *query;
461 if (clt->clt_path_info == NULL) {
462 log_warnx("PATH_INFO not defined!");
463 if (proxy_start_reply(clt, 501, "text/html") == -1)
465 if (tp_error(clt->clt_tp, -1, "internal server error") == -1)
467 return (fcgi_end_request(clt, 1));
470 if ((clt->clt_pc = proxy_match(env, clt->clt_server_name)) == NULL) {
471 if (proxy_start_reply(clt, 501, "text/html") == -1)
473 if (tp_error(clt->clt_tp, -1, "unknown server") == -1)
475 return (fcgi_end_request(clt, 1));
478 if (clt->clt_bodylen != 0 && clt->clt_body == NULL) {
479 if (proxy_start_reply(clt, 400, "text/html") == -1)
481 if (tp_error(clt->clt_tp, -1, "bad request") == -1)
483 return (fcgi_end_request(clt, 1));
487 r = asprintf(&url, "%s%s?%s", clt->clt_script_name,
488 clt->clt_path_info + 1, clt->clt_body);
490 return (fcgi_end_request(clt, 1));
492 if (proxy_start_reply(clt, 302, url) == -1 ||
493 fcgi_end_request(clt, 1) == -1) {
501 memset(&hints, 0, sizeof(hints));
502 hints.ai_family = AF_UNSPEC;
503 hints.ai_socktype = SOCK_STREAM;
505 query = getaddrinfo_async(clt->clt_pc->proxy_addr,
506 clt->clt_pc->proxy_port, &hints, NULL);
508 log_warn("getaddrinfo_async");
509 return (fcgi_abort_request(clt));
512 clt->clt_evasr = event_asr_run(query, proxy_resolved, clt);
513 if (clt->clt_evasr == NULL) {
514 log_warn("event_asr_run");
516 return (fcgi_abort_request(clt));
523 proxy_resolved(struct asr_result *res, void *d)
525 struct client *clt = d;
526 struct proxy_config *pc = clt->clt_pc;
528 clt->clt_evasr = NULL;
530 if (res->ar_gai_errno != 0) {
531 log_warnx("failed to resolve %s:%s: %s",
532 pc->proxy_addr, pc->proxy_port,
533 gai_strerror(res->ar_gai_errno));
534 if (proxy_start_reply(clt, 501, "text/html") == -1)
536 if (tp_error(clt->clt_tp, -1, "Can't resolve host") == -1)
538 fcgi_end_request(clt, 1);
542 clt->clt_addrinfo = res->ar_addrinfo;
543 clt->clt_p = clt->clt_addrinfo;
544 proxy_connect(-1, 0, clt);
548 proxy_connect(int fd, short ev, void *d)
550 struct client *clt = d;
551 struct evbuffer *out;
553 struct tls_config *conf;
554 struct timeval conntv = {5, 0};
556 socklen_t len = sizeof(err);
559 if (clt->clt_p == NULL)
562 if (clt->clt_fd != -1) {
563 if (getsockopt(clt->clt_fd, SOL_SOCKET, SO_ERROR, &err, &len)
574 clt->clt_fd = socket(p->ai_family, p->ai_socktype | SOCK_NONBLOCK,
576 if (clt->clt_fd == -1) {
577 clt->clt_p = clt->clt_p->ai_next;
581 if (connect(clt->clt_fd, p->ai_addr, p->ai_addrlen) == 0)
584 clt->clt_evconn_live = 1;
585 event_set(&clt->clt_evconn, clt->clt_fd, EV_WRITE, proxy_connect, clt);
586 event_add(&clt->clt_evconn, &conntv);
590 clt->clt_evconn_live = 0;
591 freeaddrinfo(clt->clt_addrinfo);
592 clt->clt_addrinfo = clt->clt_p = NULL;
594 clt->clt_bev = bufferevent_new(clt->clt_fd, proxy_read, proxy_write,
596 if (clt->clt_bev == NULL) {
597 log_warn("bufferevent_new");
601 if (!(clt->clt_pc->flags & PROXY_NO_TLS)) {
602 /* initialize TLS for Gemini */
603 if ((conf = tls_config_new()) == NULL) {
604 log_warn("tls_config_new failed");
608 tls_config_insecure_noverifycert(conf);
610 if ((clt->clt_ctx = tls_client()) == NULL) {
611 log_warnx("tls_client failed");
612 tls_config_free(conf);
616 if (tls_configure(clt->clt_ctx, conf) == -1) {
617 log_warnx("tls_configure failed");
618 tls_config_free(conf);
622 tls_config_free(conf);
624 if (tls_connect_socket(clt->clt_ctx, clt->clt_fd,
625 clt->clt_pc->proxy_name) == -1) {
626 log_warnx("tls_connect_socket failed");
630 event_set(&clt->clt_bev->ev_read, clt->clt_fd, EV_READ,
631 proxy_tls_readcb, clt->clt_bev);
632 event_set(&clt->clt_bev->ev_write, clt->clt_fd, EV_WRITE,
633 proxy_tls_writecb, clt->clt_bev);
636 evbuffer_unfreeze(clt->clt_bev->input, 0);
637 evbuffer_unfreeze(clt->clt_bev->output, 1);
641 /* bufferevent_settimeout(); */
642 bufferevent_enable(clt->clt_bev, EV_READ|EV_WRITE);
644 /* TODO: compute the URL */
645 out = EVBUFFER_OUTPUT(clt->clt_bev);
646 if (evbuffer_add_printf(out, "gemini://%s/%s",
647 clt->clt_pc->proxy_name, clt->clt_path_info) == -1) {
648 log_warn("bufferevent_printf failed");
652 if (clt->clt_query &&
653 evbuffer_add_printf(out, "?%s", clt->clt_query) == -1) {
654 log_warn("bufferevent_printf failed");
658 if (evbuffer_add(out, "\r\n", 2) == -1) {
659 log_warn("bufferevent_add failed");
666 log_warn("failed to connect to %s:%s",
667 clt->clt_pc->proxy_addr, clt->clt_pc->proxy_port);
668 if (proxy_start_reply(clt, 501, "text/html") == -1)
670 if (tp_error(clt->clt_tp, -1, "Can't connect") == -1)
672 fcgi_end_request(clt, 1);
676 parse_mime(struct client *clt, char *mime, char *lang, size_t len)
680 memset(lang, 0, len);
682 if (strncmp(mime, "text/gemini", 11) != 0)
685 clt->clt_translate = TR_ENABLED;
687 if ((mime = strchr(mime, ';')) == NULL)
691 while ((t = strsep(&mime, ";")) != NULL) {
692 if (!strncmp(t, "charset=", 8)) {
694 if (!strncasecmp(t, "utf8", 4) ||
695 !strncasecmp(t, "utf-8", 5) ||
696 !strncasecmp(t, "ascii", 5)) {
697 log_debug("unknown charset %s", t);
703 if (!strncmp(t, "lang=", 5)) {
705 if ((semi = strchr(t, ';')) != NULL)
708 if (strlcpy(lang, t, len) >= len) {
709 log_debug("lang too long: %s", t);
723 proxy_start_reply(struct client *clt, int status, const char *ctype)
725 struct template *tp = clt->clt_tp;
728 csp = "Content-Security-Policy: default-src 'self'; "
729 "script-src 'none'; object-src 'none';\r\n";
732 tp_writef(tp, "Status: %d\r\n", status) == -1)
735 if (tp_writes(tp, csp) == -1)
739 /* use "ctype" as redirect target */
740 if (tp_writef(tp, "Location: %s\r\n", ctype) == -1)
742 if (tp_writes(tp, "\r\n") == -1)
748 if (!strcmp(ctype, "text/html"))
749 ctype = "text/html;charset=utf-8";
750 if (tp_writef(tp, "Content-Type: %s\r\n", ctype)
755 if (tp_writes(tp, "\r\n") == -1)
762 proxy_read(struct bufferevent *bev, void *d)
764 struct client *clt = d;
765 struct evbuffer *src = EVBUFFER_INPUT(bev);
773 if (clt->clt_headersdone) {
774 if (clt->clt_translate)
775 proxy_translate_gemtext(clt);
777 clt_write_bufferevent(clt, bev);
781 hdr = evbuffer_readln(src, &len, EVBUFFER_EOL_CRLF_STRICT);
783 if (EVBUFFER_LENGTH(src) >= 1026)
784 proxy_error(bev, EV_READ, clt);
789 !isdigit((unsigned char)hdr[0]) ||
790 !isdigit((unsigned char)hdr[1]) ||
792 log_warnx("invalid ");
793 proxy_error(bev, EV_READ, clt);
797 code = (hdr[0] - '0') * 10 + (hdr[1] - '0');
801 if (proxy_start_reply(clt, 200, "text/html") == -1)
803 if (tp_inputpage(clt->clt_tp, &hdr[3]) == -1)
805 fcgi_end_request(clt, 0);
811 if (proxy_resurl(clt, &hdr[3], buf, sizeof(buf)) == 0) {
812 if (proxy_start_reply(clt, 302, buf) == -1)
814 fcgi_end_request(clt, 0);
819 if (proxy_start_reply(clt, 501, "text/html") == -1)
821 if (tp_error(clt->clt_tp, code, &hdr[3]) == -1)
823 fcgi_end_request(clt, 1);
827 mime = hdr + 2 + strspn(hdr + 2, " \t");
828 if (parse_mime(clt, mime, lang, sizeof(lang)) == -1) {
829 if (proxy_start_reply(clt, 501, "text/html") == -1)
831 if (tp_error(clt->clt_tp, -1, "Bad response") == -1)
833 fcgi_end_request(clt, 1);
837 if (clt->clt_translate)
838 ctype = "text/html;charset=utf-8";
842 if (tp_writef(clt->clt_tp, "Content-Type: %s\r\n\r\n", ctype) == -1)
845 clt->clt_headersdone = 1;
847 if (clt->clt_translate &&
848 tp_head(clt->clt_tp, lang, NULL) == -1)
852 * Trigger the read again so we proceed with the response
864 proxy_write(struct bufferevent *bev, void *d)
870 proxy_error(struct bufferevent *bev, short err, void *d)
872 struct client *clt = d;
873 struct template *tp = clt->clt_tp;
874 int status = !(err & EVBUFFER_EOF);
876 log_debug("proxy error, shutting down the connection (err: %x)",
879 if (!clt->clt_headersdone) {
880 if (proxy_start_reply(clt, 501, "text/html") == -1)
882 if (tp_error(clt->clt_tp, -1, "Proxy error") == -1)
884 } else if (status == 0) {
885 if (clt->clt_translate & TR_PRE) {
886 if (tp_pre_close(clt->clt_tp))
888 clt->clt_translate &= ~TR_PRE;
891 if (clt->clt_translate & TR_LIST) {
892 if (tp_writes(tp, "</ul>") == -1)
894 clt->clt_translate &= ~TR_LIST;
897 if (clt->clt_translate & TR_NAV) {
898 if (tp_writes(tp, "</ul></nav>") == -1)
900 clt->clt_translate &= ~TR_NAV;
903 if (clt->clt_translate &&
904 tp_foot(clt->clt_tp) == -1)
908 fcgi_end_request(clt, status);
912 proxy_tls_readcb(int fd, short event, void *arg)
914 struct bufferevent *bufev = arg;
915 struct client *clt = bufev->cbarg;
916 char rbuf[IBUF_READ_SIZE];
917 int what = EVBUFFER_READ;
918 int howmuch = IBUF_READ_SIZE;
922 if (event == EV_TIMEOUT) {
923 what |= EVBUFFER_TIMEOUT;
927 if (bufev->wm_read.high != 0)
928 howmuch = MINIMUM(sizeof(rbuf), bufev->wm_read.high);
930 ret = tls_read(clt->clt_ctx, rbuf, howmuch);
931 if (ret == TLS_WANT_POLLIN || ret == TLS_WANT_POLLOUT) {
933 } else if (ret == -1) {
934 what |= EVBUFFER_ERROR;
940 what |= EVBUFFER_EOF;
944 if (evbuffer_add(bufev->input, rbuf, len) == -1) {
945 what |= EVBUFFER_ERROR;
949 proxy_bufferevent_add(&bufev->ev_read, G_TOUT(bufev->timeout_read));
951 len = EVBUFFER_LENGTH(bufev->input);
952 if (bufev->wm_read.low != 0 && len < bufev->wm_read.low)
954 if (bufev->wm_read.high != 0 && len > bufev->wm_read.high) {
955 struct evbuffer *buf = bufev->input;
956 event_del(&bufev->ev_read);
957 evbuffer_setcb(buf, bufferevent_read_pressure_cb, bufev);
961 if (bufev->readcb != NULL)
962 (*bufev->readcb)(bufev, bufev->cbarg);
966 proxy_bufferevent_add(&bufev->ev_read, G_TOUT(bufev->timeout_read));
970 (*bufev->errorcb)(bufev, what, bufev->cbarg);
974 proxy_bufferevent_add(struct event *ev, int timeout)
976 struct timeval tv, *ptv = NULL;
984 return (event_add(ev, ptv));
988 proxy_tls_writecb(int fd, short event, void *arg)
990 struct bufferevent *bufev = arg;
991 struct client *clt = bufev->cbarg;
993 short what = EVBUFFER_WRITE;
996 if (event == EV_TIMEOUT) {
997 what |= EVBUFFER_TIMEOUT;
1001 if (EVBUFFER_LENGTH(bufev->output)) {
1002 ret = tls_write(clt->clt_ctx,
1003 EVBUFFER_DATA(bufev->output),
1004 EVBUFFER_LENGTH(bufev->output));
1005 if (ret == TLS_WANT_POLLIN || ret == TLS_WANT_POLLOUT) {
1007 } else if (ret == -1) {
1008 what |= EVBUFFER_ERROR;
1012 evbuffer_drain(bufev->output, len);
1015 if (EVBUFFER_LENGTH(bufev->output) != 0)
1016 proxy_bufferevent_add(&bufev->ev_write,
1017 G_TOUT(bufev->timeout_write));
1019 if (bufev->writecb != NULL &&
1020 EVBUFFER_LENGTH(bufev->output) <= bufev->wm_write.low)
1021 (*bufev->writecb)(bufev, bufev->cbarg);
1025 proxy_bufferevent_add(&bufev->ev_write, G_TOUT(bufev->timeout_write));
1029 (*bufev->errorcb)(bufev, what, bufev->cbarg);
1033 proxy_client_free(struct client *clt)
1036 event_asr_abort(clt->clt_evasr);
1038 if (clt->clt_addrinfo)
1039 freeaddrinfo(clt->clt_addrinfo);
1041 if (clt->clt_evconn_live)
1042 event_del(&clt->clt_evconn);
1044 if (clt->clt_fd != -1)
1048 tls_free(clt->clt_ctx);
1051 bufferevent_free(clt->clt_bev);
1053 template_free(clt->clt_tp);
1055 free(clt->clt_body);
1056 free(clt->clt_server_name);
1057 free(clt->clt_script_name);
1058 free(clt->clt_path_info);
1059 free(clt->clt_query);