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)
262 /* preformatted line / closing */
263 if (clt->clt_translate & TR_PRE) {
264 if (!strncmp(line, "```", 3)) {
265 clt->clt_translate &= ~TR_PRE;
266 return (tp_pre_close(clt->clt_tp));
269 if (tp_htmlescape(clt->clt_tp, line) == -1)
271 return (clt_putc(clt, '\n'));
275 if (!strncmp(line, "* ", 2)) {
276 if (clt->clt_translate & TR_NAV) {
277 if (clt_puts(clt, "</ul></nav>") == -1)
279 clt->clt_translate &= ~TR_NAV;
282 if (!(clt->clt_translate & TR_LIST)) {
283 if (clt_puts(clt, "<ul>") == -1)
285 clt->clt_translate |= TR_LIST;
288 if (clt_puts(clt, "<li>") == -1 ||
289 tp_htmlescape(clt->clt_tp, line + 2) == -1 ||
290 clt_puts(clt, "</li>") == -1)
295 if (clt->clt_translate & TR_LIST) {
296 if (clt_puts(clt, "</ul>") == -1)
298 clt->clt_translate &= ~TR_LIST;
302 if (!strncmp(line, "=>", 2)) {
306 line += strspn(line, " \t");
308 label = line + strcspn(line, " \t");
313 label += strspn(label, " \t");
318 if (proxy_resurl(clt, line, buf, sizeof(buf)) == 0)
321 url = line; /* leave the URL as it is */
323 if (!(clt->clt_pc->flags & PROXY_NO_IMGPRV) &&
324 match_image_heur(url)) {
325 if (clt->clt_translate & TR_NAV) {
326 if (clt_puts(clt, "</ul></nav>") == -1)
328 clt->clt_translate &= ~TR_NAV;
331 if (tp_figure(clt->clt_tp, url, label) == -1)
337 if (!(clt->clt_translate & TR_NAV)) {
338 if (clt_puts(clt, "<nav><ul>") == -1)
340 clt->clt_translate |= TR_NAV;
343 if (clt_puts(clt, "<li><a href='") == -1)
346 if (tp_urlescape(clt->clt_tp, url) == -1 ||
347 clt_puts(clt, "'>") == -1 ||
348 tp_htmlescape(clt->clt_tp, label) == -1 ||
349 clt_puts(clt, "</a></li>") == -1)
355 if (clt->clt_translate & TR_NAV) {
356 if (clt_puts(clt, "</ul></nav>") == -1)
358 clt->clt_translate &= ~TR_NAV;
362 if (!strncmp(line, "```", 3)) {
364 line += strspn(line, " \t");
366 clt->clt_translate |= TR_PRE;
367 return (tp_pre_open(clt->clt_tp, line));
372 if (clt_puts(clt, "<blockquote>") == -1 ||
373 tp_htmlescape(clt->clt_tp, line + 1) == -1 ||
374 clt_puts(clt, "</blockquote>") == -1)
380 if (!strncmp(line, "###", 3)) {
381 if (clt_puts(clt, "<h3>") == -1 ||
382 tp_htmlescape(clt->clt_tp, line + 3) == -1 ||
383 clt_puts(clt, "</h3>") == -1)
387 if (!strncmp(line, "##", 2)) {
388 if (clt_puts(clt, "<h2>") == -1 ||
389 tp_htmlescape(clt->clt_tp, line + 2) == -1 ||
390 clt_puts(clt, "</h2>") == -1)
394 if (!strncmp(line, "#", 1)) {
395 if (clt_puts(clt, "<h1>") == -1 ||
396 tp_htmlescape(clt->clt_tp, line + 1) == -1 ||
397 clt_puts(clt, "</h1>") == -1)
402 /* Not following strictly the gemini specification... */
407 if (clt_puts(clt, "<p>") == -1 ||
408 tp_htmlescape(clt->clt_tp, line) == -1 ||
409 clt_puts(clt, "</p>") == -1)
416 proxy_translate_gemtext(struct client *clt)
418 struct bufferevent *bev = clt->clt_bev;
419 struct evbuffer *src = EVBUFFER_INPUT(bev);
425 line = evbuffer_readln(src, &len, EVBUFFER_EOL_CRLF);
429 r = gemtext_translate_line(clt, line);
436 struct proxy_config *
437 proxy_match(struct galileo *env, const char *name)
444 TAILQ_FOREACH(pr, &env->sc_proxies, pr_entry) {
445 if (!strcmp(name, pr->pr_conf.host))
446 return (&pr->pr_conf);
453 proxy_start_request(struct galileo *env, struct client *clt)
455 struct addrinfo hints;
456 struct asr_query *query;
460 if (clt->clt_path_info == NULL) {
461 log_warnx("PATH_INFO not defined!");
462 if (proxy_start_reply(clt, 501, "text/html") == -1)
464 if (tp_error(clt->clt_tp, -1, "internal server error") == -1)
466 return (fcgi_end_request(clt, 1));
469 if ((clt->clt_pc = proxy_match(env, clt->clt_server_name)) == NULL) {
470 if (proxy_start_reply(clt, 501, "text/html") == -1)
472 if (tp_error(clt->clt_tp, -1, "unknown server") == -1)
474 return (fcgi_end_request(clt, 1));
477 if (clt->clt_bodylen != 0 && clt->clt_body == NULL) {
478 if (proxy_start_reply(clt, 400, "text/html") == -1)
480 if (tp_error(clt->clt_tp, -1, "bad request") == -1)
482 return (fcgi_end_request(clt, 1));
486 r = asprintf(&url, "%s%s?%s", clt->clt_script_name,
487 clt->clt_path_info + 1, clt->clt_body);
489 return (fcgi_end_request(clt, 1));
491 if (proxy_start_reply(clt, 302, url) == -1 ||
492 fcgi_end_request(clt, 1) == -1) {
500 memset(&hints, 0, sizeof(hints));
501 hints.ai_family = AF_UNSPEC;
502 hints.ai_socktype = SOCK_STREAM;
504 query = getaddrinfo_async(clt->clt_pc->proxy_addr,
505 clt->clt_pc->proxy_port, &hints, NULL);
507 log_warn("getaddrinfo_async");
508 return (fcgi_abort_request(clt));
511 clt->clt_evasr = event_asr_run(query, proxy_resolved, clt);
512 if (clt->clt_evasr == NULL) {
513 log_warn("event_asr_run");
515 return (fcgi_abort_request(clt));
522 proxy_resolved(struct asr_result *res, void *d)
524 struct client *clt = d;
525 struct proxy_config *pc = clt->clt_pc;
527 clt->clt_evasr = NULL;
529 if (res->ar_gai_errno != 0) {
530 log_warnx("failed to resolve %s:%s: %s",
531 pc->proxy_addr, pc->proxy_port,
532 gai_strerror(res->ar_gai_errno));
533 if (proxy_start_reply(clt, 501, "text/html") == -1)
535 if (tp_error(clt->clt_tp, -1, "Can't resolve host") == -1)
537 fcgi_end_request(clt, 1);
541 clt->clt_addrinfo = res->ar_addrinfo;
542 clt->clt_p = clt->clt_addrinfo;
543 proxy_connect(-1, 0, clt);
547 proxy_connect(int fd, short ev, void *d)
549 struct client *clt = d;
550 struct evbuffer *out;
552 struct tls_config *conf;
553 struct timeval conntv = {5, 0};
555 socklen_t len = sizeof(err);
558 if (clt->clt_p == NULL)
561 if (clt->clt_fd != -1) {
562 if (getsockopt(clt->clt_fd, SOL_SOCKET, SO_ERROR, &err, &len)
573 clt->clt_fd = socket(p->ai_family, p->ai_socktype | SOCK_NONBLOCK,
575 if (clt->clt_fd == -1) {
576 clt->clt_p = clt->clt_p->ai_next;
580 if (connect(clt->clt_fd, p->ai_addr, p->ai_addrlen) == 0)
583 clt->clt_evconn_live = 1;
584 event_set(&clt->clt_evconn, clt->clt_fd, EV_WRITE, proxy_connect, clt);
585 event_add(&clt->clt_evconn, &conntv);
589 clt->clt_evconn_live = 0;
590 freeaddrinfo(clt->clt_addrinfo);
591 clt->clt_addrinfo = clt->clt_p = NULL;
593 clt->clt_bev = bufferevent_new(clt->clt_fd, proxy_read, proxy_write,
595 if (clt->clt_bev == NULL) {
596 log_warn("bufferevent_new");
600 if (!(clt->clt_pc->flags & PROXY_NO_TLS)) {
601 /* initialize TLS for Gemini */
602 if ((conf = tls_config_new()) == NULL) {
603 log_warn("tls_config_new failed");
607 tls_config_insecure_noverifycert(conf);
609 if ((clt->clt_ctx = tls_client()) == NULL) {
610 log_warnx("tls_client failed");
611 tls_config_free(conf);
615 if (tls_configure(clt->clt_ctx, conf) == -1) {
616 log_warnx("tls_configure failed");
617 tls_config_free(conf);
621 tls_config_free(conf);
623 if (tls_connect_socket(clt->clt_ctx, clt->clt_fd,
624 clt->clt_pc->proxy_name) == -1) {
625 log_warnx("tls_connect_socket failed");
629 event_set(&clt->clt_bev->ev_read, clt->clt_fd, EV_READ,
630 proxy_tls_readcb, clt->clt_bev);
631 event_set(&clt->clt_bev->ev_write, clt->clt_fd, EV_WRITE,
632 proxy_tls_writecb, clt->clt_bev);
635 evbuffer_unfreeze(clt->clt_bev->input, 0);
636 evbuffer_unfreeze(clt->clt_bev->output, 1);
640 /* bufferevent_settimeout(); */
641 bufferevent_enable(clt->clt_bev, EV_READ|EV_WRITE);
643 /* TODO: compute the URL */
644 out = EVBUFFER_OUTPUT(clt->clt_bev);
645 if (evbuffer_add_printf(out, "gemini://%s/%s",
646 clt->clt_pc->proxy_name, clt->clt_path_info) == -1) {
647 log_warn("bufferevent_printf failed");
651 if (clt->clt_query &&
652 evbuffer_add_printf(out, "?%s", clt->clt_query) == -1) {
653 log_warn("bufferevent_printf failed");
657 if (evbuffer_add(out, "\r\n", 2) == -1) {
658 log_warn("bufferevent_add failed");
665 log_warn("failed to connect to %s:%s",
666 clt->clt_pc->proxy_addr, clt->clt_pc->proxy_port);
667 if (proxy_start_reply(clt, 501, "text/html") == -1)
669 if (tp_error(clt->clt_tp, -1, "Can't connect") == -1)
671 fcgi_end_request(clt, 1);
675 parse_mime(struct client *clt, char *mime, char *lang, size_t len)
679 memset(lang, 0, len);
681 if (strncmp(mime, "text/gemini", 11) != 0)
684 clt->clt_translate = TR_ENABLED;
686 if ((mime = strchr(mime, ';')) == NULL)
690 while ((t = strsep(&mime, ";")) != NULL) {
691 if (!strncmp(t, "charset=", 8)) {
693 if (!strncasecmp(t, "utf8", 4) ||
694 !strncasecmp(t, "utf-8", 5) ||
695 !strncasecmp(t, "ascii", 5)) {
696 log_debug("unknown charset %s", t);
702 if (!strncmp(t, "lang=", 5)) {
704 if ((semi = strchr(t, ';')) != NULL)
707 if (strlcpy(lang, t, len) >= len) {
708 log_debug("lang too long: %s", t);
722 proxy_start_reply(struct client *clt, int status, const char *ctype)
726 csp = "Content-Security-Policy: default-src 'self'; "
727 "script-src 'none'; object-src 'none';\r\n";
730 clt_printf(clt, "Status: %d\r\n", status) == -1)
733 if (clt_puts(clt, csp) == -1)
737 /* use "ctype" as redirect target */
738 if (clt_printf(clt, "Location: %s\r\n", ctype) == -1)
740 if (clt_puts(clt, "\r\n") == -1)
746 if (!strcmp(ctype, "text/html"))
747 ctype = "text/html;charset=utf-8";
748 if (clt_printf(clt, "Content-Type: %s\r\n", ctype)
753 if (clt_puts(clt, "\r\n") == -1)
760 proxy_read(struct bufferevent *bev, void *d)
762 struct client *clt = d;
763 struct evbuffer *src = EVBUFFER_INPUT(bev);
771 if (clt->clt_headersdone) {
772 if (clt->clt_translate)
773 proxy_translate_gemtext(clt);
775 clt_write_bufferevent(clt, bev);
779 hdr = evbuffer_readln(src, &len, EVBUFFER_EOL_CRLF_STRICT);
781 if (EVBUFFER_LENGTH(src) >= 1026)
782 proxy_error(bev, EV_READ, clt);
787 !isdigit((unsigned char)hdr[0]) ||
788 !isdigit((unsigned char)hdr[1]) ||
790 log_warnx("invalid ");
791 proxy_error(bev, EV_READ, clt);
795 code = (hdr[0] - '0') * 10 + (hdr[1] - '0');
799 if (proxy_start_reply(clt, 200, "text/html") == -1)
801 if (tp_inputpage(clt->clt_tp, &hdr[3]) == -1)
803 fcgi_end_request(clt, 0);
809 if (proxy_resurl(clt, &hdr[3], buf, sizeof(buf)) == 0) {
810 if (proxy_start_reply(clt, 302, buf) == -1)
812 fcgi_end_request(clt, 0);
817 if (proxy_start_reply(clt, 501, "text/html") == -1)
819 if (tp_error(clt->clt_tp, code, &hdr[3]) == -1)
821 fcgi_end_request(clt, 1);
825 mime = hdr + 2 + strspn(hdr + 2, " \t");
826 if (parse_mime(clt, mime, lang, sizeof(lang)) == -1) {
827 if (proxy_start_reply(clt, 501, "text/html") == -1)
829 if (tp_error(clt->clt_tp, -1, "Bad response") == -1)
831 fcgi_end_request(clt, 1);
835 if (clt->clt_translate)
836 ctype = "text/html;charset=utf-8";
840 if (clt_printf(clt, "Content-Type: %s\r\n\r\n", ctype) == -1)
843 clt->clt_headersdone = 1;
845 if (clt->clt_translate &&
846 tp_head(clt->clt_tp, lang, NULL) == -1)
850 * Trigger the read again so we proceed with the response
862 proxy_write(struct bufferevent *bev, void *d)
868 proxy_error(struct bufferevent *bev, short err, void *d)
870 struct client *clt = d;
871 int status = !(err & EVBUFFER_EOF);
873 log_debug("proxy error, shutting down the connection (err: %x)",
876 if (!clt->clt_headersdone) {
877 if (proxy_start_reply(clt, 501, "text/html") == -1)
879 if (tp_error(clt->clt_tp, -1, "Proxy error") == -1)
881 } else if (status == 0) {
882 if (clt->clt_translate & TR_PRE) {
883 if (tp_pre_close(clt->clt_tp))
885 clt->clt_translate &= ~TR_PRE;
888 if (clt->clt_translate & TR_LIST) {
889 if (clt_puts(clt, "</ul>") == -1)
891 clt->clt_translate &= ~TR_LIST;
894 if (clt->clt_translate & TR_NAV) {
895 if (clt_puts(clt, "</ul></nav>") == -1)
897 clt->clt_translate &= ~TR_NAV;
900 if (clt->clt_translate &&
901 tp_foot(clt->clt_tp) == -1)
905 fcgi_end_request(clt, status);
909 proxy_tls_readcb(int fd, short event, void *arg)
911 struct bufferevent *bufev = arg;
912 struct client *clt = bufev->cbarg;
913 char rbuf[IBUF_READ_SIZE];
914 int what = EVBUFFER_READ;
915 int howmuch = IBUF_READ_SIZE;
919 if (event == EV_TIMEOUT) {
920 what |= EVBUFFER_TIMEOUT;
924 if (bufev->wm_read.high != 0)
925 howmuch = MINIMUM(sizeof(rbuf), bufev->wm_read.high);
927 ret = tls_read(clt->clt_ctx, rbuf, howmuch);
928 if (ret == TLS_WANT_POLLIN || ret == TLS_WANT_POLLOUT) {
930 } else if (ret == -1) {
931 what |= EVBUFFER_ERROR;
937 what |= EVBUFFER_EOF;
941 if (evbuffer_add(bufev->input, rbuf, len) == -1) {
942 what |= EVBUFFER_ERROR;
946 proxy_bufferevent_add(&bufev->ev_read, G_TOUT(bufev->timeout_read));
948 len = EVBUFFER_LENGTH(bufev->input);
949 if (bufev->wm_read.low != 0 && len < bufev->wm_read.low)
951 if (bufev->wm_read.high != 0 && len > bufev->wm_read.high) {
952 struct evbuffer *buf = bufev->input;
953 event_del(&bufev->ev_read);
954 evbuffer_setcb(buf, bufferevent_read_pressure_cb, bufev);
958 if (bufev->readcb != NULL)
959 (*bufev->readcb)(bufev, bufev->cbarg);
963 proxy_bufferevent_add(&bufev->ev_read, G_TOUT(bufev->timeout_read));
967 (*bufev->errorcb)(bufev, what, bufev->cbarg);
971 proxy_bufferevent_add(struct event *ev, int timeout)
973 struct timeval tv, *ptv = NULL;
981 return (event_add(ev, ptv));
985 proxy_tls_writecb(int fd, short event, void *arg)
987 struct bufferevent *bufev = arg;
988 struct client *clt = bufev->cbarg;
990 short what = EVBUFFER_WRITE;
993 if (event == EV_TIMEOUT) {
994 what |= EVBUFFER_TIMEOUT;
998 if (EVBUFFER_LENGTH(bufev->output)) {
999 ret = tls_write(clt->clt_ctx,
1000 EVBUFFER_DATA(bufev->output),
1001 EVBUFFER_LENGTH(bufev->output));
1002 if (ret == TLS_WANT_POLLIN || ret == TLS_WANT_POLLOUT) {
1004 } else if (ret == -1) {
1005 what |= EVBUFFER_ERROR;
1009 evbuffer_drain(bufev->output, len);
1012 if (EVBUFFER_LENGTH(bufev->output) != 0)
1013 proxy_bufferevent_add(&bufev->ev_write,
1014 G_TOUT(bufev->timeout_write));
1016 if (bufev->writecb != NULL &&
1017 EVBUFFER_LENGTH(bufev->output) <= bufev->wm_write.low)
1018 (*bufev->writecb)(bufev, bufev->cbarg);
1022 proxy_bufferevent_add(&bufev->ev_write, G_TOUT(bufev->timeout_write));
1026 (*bufev->errorcb)(bufev, what, bufev->cbarg);
1030 proxy_client_free(struct client *clt)
1033 event_asr_abort(clt->clt_evasr);
1035 if (clt->clt_addrinfo)
1036 freeaddrinfo(clt->clt_addrinfo);
1038 if (clt->clt_evconn_live)
1039 event_del(&clt->clt_evconn);
1041 if (clt->clt_fd != -1)
1045 tls_free(clt->clt_ctx);
1048 bufferevent_free(clt->clt_bev);
1050 template_free(clt->clt_tp);
1052 free(clt->clt_body);
1053 free(clt->clt_server_name);
1054 free(clt->clt_script_name);
1055 free(clt->clt_path_info);
1056 free(clt->clt_query);