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 l = strlen(clt->clt_server_name);
195 log_warn("%s: zero-sized buffer!", __func__);
199 /* look if it's an absolute URI */
200 if (strncmp(url, "//", 2) == 0) {
202 if (strncmp(tmp, clt->clt_server_name, l) != 0)
206 if (!portok(&tmp, clt))
209 } else if (strncmp(url, "gemini://", 9) == 0) {
211 if (strncmp(tmp, clt->clt_server_name, l) != 0)
215 if (!portok(&tmp, clt))
220 while (isalpha((unsigned char)*tmp) || *tmp == '+')
222 if (strncmp(tmp, "://", 3) == 0)
226 /* maybe it's an absolute path? */
227 if (*url == '\0' || *url == '/') {
228 if (strlcpy(buf, clt->clt_script_name, len) >= len)
230 if (strlcat(buf, url + 1, len) >= len)
235 /* otherwise, leave it as it is */
237 if (strlcpy(buf, url, len) >= len)
243 gemtext_translate_line(struct client *clt, char *line)
248 /* preformatted line / closing */
249 if (clt->clt_translate & TR_PRE) {
250 if (!strncmp(line, "```", 3)) {
251 clt->clt_translate &= ~TR_PRE;
252 return (tp_pre_close(clt->clt_tp));
255 if (tp_htmlescape(clt->clt_tp, line) == -1)
257 return (clt_putc(clt, '\n'));
261 if (!strncmp(line, "* ", 2)) {
262 if (clt->clt_translate & TR_NAV) {
263 if (clt_puts(clt, "</ul></nav>") == -1)
265 clt->clt_translate &= ~TR_NAV;
268 if (!(clt->clt_translate & TR_LIST)) {
269 if (clt_puts(clt, "<ul>") == -1)
271 clt->clt_translate |= TR_LIST;
274 if (clt_puts(clt, "<li>") == -1 ||
275 tp_htmlescape(clt->clt_tp, line + 2) == -1 ||
276 clt_puts(clt, "</li>") == -1)
281 if (clt->clt_translate & TR_LIST) {
282 if (clt_puts(clt, "</ul>") == -1)
284 clt->clt_translate &= ~TR_LIST;
288 if (!strncmp(line, "=>", 2)) {
292 line += strspn(line, " \t");
294 label = line + strcspn(line, " \t");
299 label += strspn(label, " \t");
304 if (proxy_resurl(clt, line, buf, sizeof(buf)) == 0)
307 url = line; /* leave the URL as it is */
309 if (fnmatch("*.jpg", url, 0) == 0 ||
310 fnmatch("*.jpeg", url, 0) == 0 ||
311 fnmatch("*.gif", url, 0) == 0 ||
312 fnmatch("*.png", url, 0) == 0 ||
313 fnmatch("*.svg", url, 0) == 0 ||
314 fnmatch("*.webp", url, 0) == 0) {
315 if (clt->clt_translate & TR_NAV) {
316 if (clt_puts(clt, "</ul></nav>") == -1)
318 clt->clt_translate &= ~TR_NAV;
321 if (tp_figure(clt->clt_tp, url, label) == -1)
327 if (!(clt->clt_translate & TR_NAV)) {
328 if (clt_puts(clt, "<nav><ul>") == -1)
330 clt->clt_translate |= TR_NAV;
333 if (clt_puts(clt, "<li><a href='") == -1)
336 if (tp_urlescape(clt->clt_tp, url) == -1 ||
337 clt_puts(clt, "'>") == -1 ||
338 tp_htmlescape(clt->clt_tp, label) == -1 ||
339 clt_puts(clt, "</a></li>") == -1)
345 if (clt->clt_translate & TR_NAV) {
346 if (clt_puts(clt, "</ul></nav>") == -1)
348 clt->clt_translate &= ~TR_NAV;
352 if (!strncmp(line, "```", 3)) {
354 line += strspn(line, " \t");
356 clt->clt_translate |= TR_PRE;
357 return (tp_pre_open(clt->clt_tp, line));
362 if (clt_puts(clt, "<blockquote>") == -1 ||
363 tp_htmlescape(clt->clt_tp, line + 1) == -1 ||
364 clt_puts(clt, "</blockquote>") == -1)
370 if (!strncmp(line, "###", 3)) {
371 if (clt_puts(clt, "<h3>") == -1 ||
372 tp_htmlescape(clt->clt_tp, line + 3) == -1 ||
373 clt_puts(clt, "</h3>") == -1)
377 if (!strncmp(line, "##", 2)) {
378 if (clt_puts(clt, "<h2>") == -1 ||
379 tp_htmlescape(clt->clt_tp, line + 2) == -1 ||
380 clt_puts(clt, "</h2>") == -1)
384 if (!strncmp(line, "#", 1)) {
385 if (clt_puts(clt, "<h1>") == -1 ||
386 tp_htmlescape(clt->clt_tp, line + 1) == -1 ||
387 clt_puts(clt, "</h1>") == -1)
392 /* Not following strictly the gemini specification... */
397 if (clt_puts(clt, "<p>") == -1 ||
398 tp_htmlescape(clt->clt_tp, line) == -1 ||
399 clt_puts(clt, "</p>") == -1)
406 proxy_translate_gemtext(struct client *clt)
408 struct bufferevent *bev = clt->clt_bev;
409 struct evbuffer *src = EVBUFFER_INPUT(bev);
415 line = evbuffer_readln(src, &len, EVBUFFER_EOL_CRLF);
419 r = gemtext_translate_line(clt, line);
426 struct proxy_config *
427 proxy_match(struct galileo *env, const char *name)
434 TAILQ_FOREACH(pr, &env->sc_proxies, pr_entry) {
435 if (!strcmp(name, pr->pr_conf.host))
436 return (&pr->pr_conf);
443 proxy_start_request(struct galileo *env, struct client *clt)
445 struct addrinfo hints;
446 struct asr_query *query;
450 if (clt->clt_path_info == NULL) {
451 log_warnx("PATH_INFO not defined!");
452 if (proxy_start_reply(clt, 501, "text/html") == -1)
454 if (tp_error(clt->clt_tp, -1, "internal server error") == -1)
456 return (fcgi_end_request(clt, 1));
459 if ((clt->clt_pc = proxy_match(env, clt->clt_server_name)) == NULL) {
460 if (proxy_start_reply(clt, 501, "text/html") == -1)
462 if (tp_error(clt->clt_tp, -1, "unknown server") == -1)
464 return (fcgi_end_request(clt, 1));
467 if (clt->clt_bodylen != 0 && clt->clt_body == NULL) {
468 if (proxy_start_reply(clt, 400, "text/html") == -1)
470 if (tp_error(clt->clt_tp, -1, "bad request") == -1)
472 return (fcgi_end_request(clt, 1));
476 r = asprintf(&url, "%s%s?%s", clt->clt_script_name,
477 clt->clt_path_info + 1, clt->clt_body);
479 return (fcgi_end_request(clt, 1));
481 if (proxy_start_reply(clt, 302, url) == -1 ||
482 fcgi_end_request(clt, 1) == -1) {
490 memset(&hints, 0, sizeof(hints));
491 hints.ai_family = AF_UNSPEC;
492 hints.ai_socktype = SOCK_STREAM;
494 query = getaddrinfo_async(clt->clt_pc->proxy_addr,
495 clt->clt_pc->proxy_port, &hints, NULL);
497 log_warn("getaddrinfo_async");
498 return (fcgi_abort_request(clt));
501 clt->clt_evasr = event_asr_run(query, proxy_resolved, clt);
502 if (clt->clt_evasr == NULL) {
503 log_warn("event_asr_run");
505 return (fcgi_abort_request(clt));
512 proxy_resolved(struct asr_result *res, void *d)
514 struct client *clt = d;
515 struct proxy_config *pc = clt->clt_pc;
517 clt->clt_evasr = NULL;
519 if (res->ar_gai_errno != 0) {
520 log_warnx("failed to resolve %s:%s: %s",
521 pc->proxy_addr, pc->proxy_port,
522 gai_strerror(res->ar_gai_errno));
523 if (proxy_start_reply(clt, 501, "text/html") == -1)
525 if (tp_error(clt->clt_tp, -1, "Can't resolve host") == -1)
527 fcgi_end_request(clt, 1);
531 clt->clt_addrinfo = res->ar_addrinfo;
532 clt->clt_p = clt->clt_addrinfo;
533 proxy_connect(-1, 0, clt);
537 proxy_connect(int fd, short ev, void *d)
539 struct client *clt = d;
540 struct evbuffer *out;
542 struct tls_config *conf;
543 struct timeval conntv = {5, 0};
545 socklen_t len = sizeof(err);
548 if (clt->clt_p == NULL)
551 if (clt->clt_fd != -1) {
552 if (getsockopt(clt->clt_fd, SOL_SOCKET, SO_ERROR, &err, &len)
563 clt->clt_fd = socket(p->ai_family, p->ai_socktype | SOCK_NONBLOCK,
565 if (clt->clt_fd == -1) {
566 clt->clt_p = clt->clt_p->ai_next;
570 if (connect(clt->clt_fd, p->ai_addr, p->ai_addrlen) == 0)
573 clt->clt_evconn_live = 1;
574 event_set(&clt->clt_evconn, clt->clt_fd, EV_WRITE, proxy_connect, clt);
575 event_add(&clt->clt_evconn, &conntv);
579 clt->clt_evconn_live = 0;
580 freeaddrinfo(clt->clt_addrinfo);
581 clt->clt_addrinfo = clt->clt_p = NULL;
583 clt->clt_bev = bufferevent_new(clt->clt_fd, proxy_read, proxy_write,
585 if (clt->clt_bev == NULL) {
586 log_warn("bufferevent_new");
590 if (!clt->clt_pc->no_tls) {
591 /* initialize TLS for Gemini */
592 if ((conf = tls_config_new()) == NULL) {
593 log_warn("tls_config_new failed");
597 tls_config_insecure_noverifycert(conf);
599 if ((clt->clt_ctx = tls_client()) == NULL) {
600 log_warnx("tls_client failed");
601 tls_config_free(conf);
605 if (tls_configure(clt->clt_ctx, conf) == -1) {
606 log_warnx("tls_configure failed");
607 tls_config_free(conf);
611 tls_config_free(conf);
613 if (tls_connect_socket(clt->clt_ctx, clt->clt_fd,
614 clt->clt_pc->proxy_name) == -1) {
615 log_warnx("tls_connect_socket failed");
619 event_set(&clt->clt_bev->ev_read, clt->clt_fd, EV_READ,
620 proxy_tls_readcb, clt->clt_bev);
621 event_set(&clt->clt_bev->ev_write, clt->clt_fd, EV_WRITE,
622 proxy_tls_writecb, clt->clt_bev);
625 evbuffer_unfreeze(clt->clt_bev->input, 0);
626 evbuffer_unfreeze(clt->clt_bev->output, 1);
630 /* bufferevent_settimeout(); */
631 bufferevent_enable(clt->clt_bev, EV_READ|EV_WRITE);
633 /* TODO: compute the URL */
634 out = EVBUFFER_OUTPUT(clt->clt_bev);
635 if (evbuffer_add_printf(out, "gemini://%s/%s",
636 clt->clt_pc->proxy_name, clt->clt_path_info) == -1) {
637 log_warn("bufferevent_printf failed");
641 if (clt->clt_query &&
642 evbuffer_add_printf(out, "?%s", clt->clt_query) == -1) {
643 log_warn("bufferevent_printf failed");
647 if (evbuffer_add(out, "\r\n", 2) == -1) {
648 log_warn("bufferevent_add failed");
655 log_warn("failed to connect to %s:%s",
656 clt->clt_pc->proxy_addr, clt->clt_pc->proxy_port);
657 if (proxy_start_reply(clt, 501, "text/html") == -1)
659 if (tp_error(clt->clt_tp, -1, "Can't connect") == -1)
661 fcgi_end_request(clt, 1);
665 parse_mime(struct client *clt, char *mime, char *lang, size_t len)
669 if (strncmp(mime, "text/gemini", 11) != 0)
672 clt->clt_translate = TR_ENABLED;
674 if ((mime = strchr(mime, ';')) == NULL)
678 while ((t = strsep(&mime, ";")) != NULL) {
679 if (!strncmp(t, "charset=", 8)) {
681 if (!strncasecmp(t, "utf8", 4) ||
682 !strncasecmp(t, "utf-8", 5) ||
683 !strncasecmp(t, "ascii", 5)) {
684 log_debug("unknown charset %s", t);
690 if (!strncmp(t, "lang=", 5)) {
692 if ((semi = strchr(t, ';')) != NULL)
695 if (strlcpy(lang, t, len) >= len) {
696 log_debug("lang too long: %s", t);
710 proxy_start_reply(struct client *clt, int status, const char *ctype)
714 csp = "Content-Security-Policy: default-src 'self'; "
715 "script-src 'none'; object-src 'none';\r\n";
718 clt_printf(clt, "Status: %d\r\n", status) == -1)
721 if (clt_puts(clt, csp) == -1)
725 /* use "ctype" as redirect target */
726 if (clt_printf(clt, "Location: %s\r\n", ctype) == -1)
728 if (clt_puts(clt, "\r\n") == -1)
734 if (!strcmp(ctype, "text/html"))
735 ctype = "text/html;charset=utf-8";
736 if (clt_printf(clt, "Content-Type: %s\r\n", ctype)
741 if (clt_puts(clt, "\r\n") == -1)
748 proxy_read(struct bufferevent *bev, void *d)
750 struct client *clt = d;
751 struct evbuffer *src = EVBUFFER_INPUT(bev);
759 if (clt->clt_headersdone) {
760 if (clt->clt_translate)
761 proxy_translate_gemtext(clt);
763 clt_write_bufferevent(clt, bev);
767 hdr = evbuffer_readln(src, &len, EVBUFFER_EOL_CRLF_STRICT);
769 if (EVBUFFER_LENGTH(src) >= 1026)
770 proxy_error(bev, EV_READ, clt);
775 !isdigit((unsigned char)hdr[0]) ||
776 !isdigit((unsigned char)hdr[1]) ||
778 log_warnx("invalid ");
779 proxy_error(bev, EV_READ, clt);
783 code = (hdr[0] - '0') * 10 + (hdr[1] - '0');
787 if (proxy_start_reply(clt, 200, "text/html") == -1)
789 if (tp_inputpage(clt->clt_tp, &hdr[3]) == -1)
791 fcgi_end_request(clt, 0);
797 if (proxy_resurl(clt, &hdr[3], buf, sizeof(buf)) == 0) {
798 if (proxy_start_reply(clt, 302, buf) == -1)
800 fcgi_end_request(clt, 0);
805 if (proxy_start_reply(clt, 501, "text/html") == -1)
807 if (tp_error(clt->clt_tp, code, &hdr[3]) == -1)
809 fcgi_end_request(clt, 1);
813 mime = hdr + 2 + strspn(hdr + 2, " \t");
814 if (parse_mime(clt, mime, lang, sizeof(lang)) == -1) {
815 if (proxy_start_reply(clt, 501, "text/html") == -1)
817 if (tp_error(clt->clt_tp, -1, "Bad response") == -1)
819 fcgi_end_request(clt, 1);
823 if (clt->clt_translate)
824 ctype = "text/html;charset=utf-8";
828 if (clt_printf(clt, "Content-Type: %s\r\n\r\n", ctype) == -1)
831 clt->clt_headersdone = 1;
833 if (clt->clt_translate &&
834 tp_head(clt->clt_tp, lang, NULL) == -1)
838 * Trigger the read again so we proceed with the response
850 proxy_write(struct bufferevent *bev, void *d)
856 proxy_error(struct bufferevent *bev, short err, void *d)
858 struct client *clt = d;
859 int status = !(err & EVBUFFER_EOF);
861 log_debug("proxy error, shutting down the connection (err: %x)",
864 if (!clt->clt_headersdone) {
865 if (proxy_start_reply(clt, 501, "text/html") == -1)
867 if (tp_error(clt->clt_tp, -1, "Proxy error") == -1)
869 } else if (status == 0) {
870 if (clt->clt_translate & TR_PRE) {
871 if (tp_pre_close(clt->clt_tp))
873 clt->clt_translate &= ~TR_PRE;
876 if (clt->clt_translate & TR_LIST) {
877 if (clt_puts(clt, "</ul>") == -1)
879 clt->clt_translate &= ~TR_LIST;
882 if (clt->clt_translate & TR_NAV) {
883 if (clt_puts(clt, "</ul></nav>") == -1)
885 clt->clt_translate &= ~TR_NAV;
888 if (clt->clt_translate &&
889 tp_foot(clt->clt_tp) == -1)
893 fcgi_end_request(clt, status);
897 proxy_tls_readcb(int fd, short event, void *arg)
899 struct bufferevent *bufev = arg;
900 struct client *clt = bufev->cbarg;
901 char rbuf[IBUF_READ_SIZE];
902 int what = EVBUFFER_READ;
903 int howmuch = IBUF_READ_SIZE;
907 if (event == EV_TIMEOUT) {
908 what |= EVBUFFER_TIMEOUT;
912 if (bufev->wm_read.high != 0)
913 howmuch = MINIMUM(sizeof(rbuf), bufev->wm_read.high);
915 ret = tls_read(clt->clt_ctx, rbuf, howmuch);
916 if (ret == TLS_WANT_POLLIN || ret == TLS_WANT_POLLOUT) {
918 } else if (ret == -1) {
919 what |= EVBUFFER_ERROR;
925 what |= EVBUFFER_EOF;
929 if (evbuffer_add(bufev->input, rbuf, len) == -1) {
930 what |= EVBUFFER_ERROR;
934 proxy_bufferevent_add(&bufev->ev_read, G_TOUT(bufev->timeout_read));
936 len = EVBUFFER_LENGTH(bufev->input);
937 if (bufev->wm_read.low != 0 && len < bufev->wm_read.low)
939 if (bufev->wm_read.high != 0 && len > bufev->wm_read.high) {
940 struct evbuffer *buf = bufev->input;
941 event_del(&bufev->ev_read);
942 evbuffer_setcb(buf, bufferevent_read_pressure_cb, bufev);
946 if (bufev->readcb != NULL)
947 (*bufev->readcb)(bufev, bufev->cbarg);
951 proxy_bufferevent_add(&bufev->ev_read, G_TOUT(bufev->timeout_read));
955 (*bufev->errorcb)(bufev, what, bufev->cbarg);
959 proxy_bufferevent_add(struct event *ev, int timeout)
961 struct timeval tv, *ptv = NULL;
969 return (event_add(ev, ptv));
973 proxy_tls_writecb(int fd, short event, void *arg)
975 struct bufferevent *bufev = arg;
976 struct client *clt = bufev->cbarg;
978 short what = EVBUFFER_WRITE;
981 if (event == EV_TIMEOUT) {
982 what |= EVBUFFER_TIMEOUT;
986 if (EVBUFFER_LENGTH(bufev->output)) {
987 ret = tls_write(clt->clt_ctx,
988 EVBUFFER_DATA(bufev->output),
989 EVBUFFER_LENGTH(bufev->output));
990 if (ret == TLS_WANT_POLLIN || ret == TLS_WANT_POLLOUT) {
992 } else if (ret == -1) {
993 what |= EVBUFFER_ERROR;
997 evbuffer_drain(bufev->output, len);
1000 if (EVBUFFER_LENGTH(bufev->output) != 0)
1001 proxy_bufferevent_add(&bufev->ev_write,
1002 G_TOUT(bufev->timeout_write));
1004 if (bufev->writecb != NULL &&
1005 EVBUFFER_LENGTH(bufev->output) <= bufev->wm_write.low)
1006 (*bufev->writecb)(bufev, bufev->cbarg);
1010 proxy_bufferevent_add(&bufev->ev_write, G_TOUT(bufev->timeout_write));
1014 (*bufev->errorcb)(bufev, what, bufev->cbarg);
1018 proxy_client_free(struct client *clt)
1021 event_asr_abort(clt->clt_evasr);
1023 if (clt->clt_addrinfo)
1024 freeaddrinfo(clt->clt_addrinfo);
1026 if (clt->clt_evconn_live)
1027 event_del(&clt->clt_evconn);
1029 if (clt->clt_fd != -1)
1033 tls_free(clt->clt_ctx);
1036 bufferevent_free(clt->clt_bev);
1038 template_free(clt->clt_tp);
1040 free(clt->clt_body);
1041 free(clt->clt_server_name);
1042 free(clt->clt_script_name);
1043 free(clt->clt_path_info);
1044 free(clt->clt_query);