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");
300 if (proxy_resurl(clt, line, buf, sizeof(buf)) == 0)
303 url = line; /* leave the URL as it is */
305 if (fnmatch("*.jpg", url, 0) == 0 ||
306 fnmatch("*.jpeg", url, 0) == 0 ||
307 fnmatch("*.gif", url, 0) == 0 ||
308 fnmatch("*.png", url, 0) == 0 ||
309 fnmatch("*.svg", url, 0) == 0 ||
310 fnmatch("*.webp", url, 0) == 0) {
311 if (clt->clt_translate & TR_NAV) {
312 if (clt_puts(clt, "</ul></nav>") == -1)
314 clt->clt_translate &= ~TR_NAV;
317 if (tp_figure(clt->clt_tp, url, label) == -1)
323 if (!(clt->clt_translate & TR_NAV)) {
324 if (clt_puts(clt, "<nav><ul>") == -1)
326 clt->clt_translate |= TR_NAV;
329 if (clt_puts(clt, "<li><a href='") == -1)
332 if (tp_urlescape(clt->clt_tp, url) == -1 ||
333 clt_puts(clt, "'>") == -1 ||
334 tp_htmlescape(clt->clt_tp, label) == -1 ||
335 clt_puts(clt, "</a></li>") == -1)
341 if (clt->clt_translate & TR_NAV) {
342 if (clt_puts(clt, "</ul></nav>") == -1)
344 clt->clt_translate &= ~TR_NAV;
348 if (!strncmp(line, "```", 3)) {
350 line += strspn(line, " \t");
352 clt->clt_translate |= TR_PRE;
353 return (tp_pre_open(clt->clt_tp, line));
358 if (clt_puts(clt, "<blockquote>") == -1 ||
359 tp_htmlescape(clt->clt_tp, line + 1) == -1 ||
360 clt_puts(clt, "</blockquote>") == -1)
366 if (!strncmp(line, "###", 3)) {
367 if (clt_puts(clt, "<h3>") == -1 ||
368 tp_htmlescape(clt->clt_tp, line + 3) == -1 ||
369 clt_puts(clt, "</h3>") == -1)
373 if (!strncmp(line, "##", 2)) {
374 if (clt_puts(clt, "<h2>") == -1 ||
375 tp_htmlescape(clt->clt_tp, line + 2) == -1 ||
376 clt_puts(clt, "</h2>") == -1)
380 if (!strncmp(line, "#", 1)) {
381 if (clt_puts(clt, "<h1>") == -1 ||
382 tp_htmlescape(clt->clt_tp, line + 1) == -1 ||
383 clt_puts(clt, "</h1>") == -1)
388 /* Not following strictly the gemini specification... */
393 if (clt_puts(clt, "<p>") == -1 ||
394 tp_htmlescape(clt->clt_tp, line) == -1 ||
395 clt_puts(clt, "</p>") == -1)
402 proxy_translate_gemtext(struct client *clt)
404 struct bufferevent *bev = clt->clt_bev;
405 struct evbuffer *src = EVBUFFER_INPUT(bev);
411 line = evbuffer_readln(src, &len, EVBUFFER_EOL_CRLF);
415 r = gemtext_translate_line(clt, line);
422 struct proxy_config *
423 proxy_match(struct galileo *env, const char *name)
430 TAILQ_FOREACH(pr, &env->sc_proxies, pr_entry) {
431 if (!strcmp(name, pr->pr_conf.host))
432 return (&pr->pr_conf);
439 proxy_start_request(struct galileo *env, struct client *clt)
441 struct addrinfo hints;
442 struct asr_query *query;
446 if (clt->clt_path_info == NULL) {
447 log_warnx("PATH_INFO not defined!");
448 if (proxy_start_reply(clt, 501, "text/html") == -1)
450 if (tp_error(clt->clt_tp, -1, "internal server error") == -1)
452 return (fcgi_end_request(clt, 1));
455 if ((clt->clt_pc = proxy_match(env, clt->clt_server_name)) == NULL) {
456 if (proxy_start_reply(clt, 501, "text/html") == -1)
458 if (tp_error(clt->clt_tp, -1, "unknown server") == -1)
460 return (fcgi_end_request(clt, 1));
463 if (clt->clt_bodylen != 0 && clt->clt_body == NULL) {
464 if (proxy_start_reply(clt, 400, "text/html") == -1)
466 if (tp_error(clt->clt_tp, -1, "bad request") == -1)
468 return (fcgi_end_request(clt, 1));
472 r = asprintf(&url, "%s%s?%s", clt->clt_script_name,
473 clt->clt_path_info + 1, clt->clt_body);
475 return (fcgi_end_request(clt, 1));
477 if (proxy_start_reply(clt, 302, url) == -1 ||
478 fcgi_end_request(clt, 1) == -1) {
486 memset(&hints, 0, sizeof(hints));
487 hints.ai_family = AF_UNSPEC;
488 hints.ai_socktype = SOCK_STREAM;
490 query = getaddrinfo_async(clt->clt_pc->proxy_addr,
491 clt->clt_pc->proxy_port, &hints, NULL);
493 log_warn("getaddrinfo_async");
494 return (fcgi_abort_request(clt));
497 clt->clt_evasr = event_asr_run(query, proxy_resolved, clt);
498 if (clt->clt_evasr == NULL) {
499 log_warn("event_asr_run");
501 return (fcgi_abort_request(clt));
508 proxy_resolved(struct asr_result *res, void *d)
510 struct client *clt = d;
511 struct proxy_config *pc = clt->clt_pc;
513 clt->clt_evasr = NULL;
515 if (res->ar_gai_errno != 0) {
516 log_warnx("failed to resolve %s:%s: %s",
517 pc->proxy_addr, pc->proxy_port,
518 gai_strerror(res->ar_gai_errno));
519 if (proxy_start_reply(clt, 501, "text/html") == -1)
521 if (tp_error(clt->clt_tp, -1, "Can't resolve host") == -1)
523 fcgi_end_request(clt, 1);
527 clt->clt_addrinfo = res->ar_addrinfo;
528 clt->clt_p = clt->clt_addrinfo;
529 proxy_connect(-1, 0, clt);
533 proxy_connect(int fd, short ev, void *d)
535 struct client *clt = d;
536 struct evbuffer *out;
538 struct tls_config *conf;
539 struct timeval conntv = {5, 0};
541 socklen_t len = sizeof(err);
544 if (clt->clt_p == NULL)
547 if (clt->clt_fd != -1) {
548 if (getsockopt(clt->clt_fd, SOL_SOCKET, SO_ERROR, &err, &len)
559 clt->clt_fd = socket(p->ai_family, p->ai_socktype | SOCK_NONBLOCK,
561 if (clt->clt_fd == -1) {
562 clt->clt_p = clt->clt_p->ai_next;
566 if (connect(clt->clt_fd, p->ai_addr, p->ai_addrlen) == 0)
569 clt->clt_evconn_live = 1;
570 event_set(&clt->clt_evconn, clt->clt_fd, EV_WRITE, proxy_connect, clt);
571 event_add(&clt->clt_evconn, &conntv);
575 clt->clt_evconn_live = 0;
576 freeaddrinfo(clt->clt_addrinfo);
577 clt->clt_addrinfo = clt->clt_p = NULL;
579 clt->clt_bev = bufferevent_new(clt->clt_fd, proxy_read, proxy_write,
581 if (clt->clt_bev == NULL) {
582 log_warn("bufferevent_new");
586 if (!clt->clt_pc->no_tls) {
587 /* initialize TLS for Gemini */
588 if ((conf = tls_config_new()) == NULL) {
589 log_warn("tls_config_new failed");
593 tls_config_insecure_noverifycert(conf);
595 if ((clt->clt_ctx = tls_client()) == NULL) {
596 log_warnx("tls_client failed");
597 tls_config_free(conf);
601 if (tls_configure(clt->clt_ctx, conf) == -1) {
602 log_warnx("tls_configure failed");
603 tls_config_free(conf);
607 tls_config_free(conf);
609 if (tls_connect_socket(clt->clt_ctx, clt->clt_fd,
610 clt->clt_pc->proxy_name) == -1) {
611 log_warnx("tls_connect_socket failed");
615 event_set(&clt->clt_bev->ev_read, clt->clt_fd, EV_READ,
616 proxy_tls_readcb, clt->clt_bev);
617 event_set(&clt->clt_bev->ev_write, clt->clt_fd, EV_WRITE,
618 proxy_tls_writecb, clt->clt_bev);
621 evbuffer_unfreeze(clt->clt_bev->input, 0);
622 evbuffer_unfreeze(clt->clt_bev->output, 1);
626 /* bufferevent_settimeout(); */
627 bufferevent_enable(clt->clt_bev, EV_READ|EV_WRITE);
629 /* TODO: compute the URL */
630 out = EVBUFFER_OUTPUT(clt->clt_bev);
631 if (evbuffer_add_printf(out, "gemini://%s/%s",
632 clt->clt_pc->proxy_name, clt->clt_path_info) == -1) {
633 log_warn("bufferevent_printf failed");
637 if (clt->clt_query &&
638 evbuffer_add_printf(out, "?%s", clt->clt_query) == -1) {
639 log_warn("bufferevent_printf failed");
643 if (evbuffer_add(out, "\r\n", 2) == -1) {
644 log_warn("bufferevent_add failed");
651 log_warn("failed to connect to %s:%s",
652 clt->clt_pc->proxy_addr, clt->clt_pc->proxy_port);
653 if (proxy_start_reply(clt, 501, "text/html") == -1)
655 if (tp_error(clt->clt_tp, -1, "Can't connect") == -1)
657 fcgi_end_request(clt, 1);
661 parse_mime(struct client *clt, char *mime, char *lang, size_t len)
665 if (strncmp(mime, "text/gemini", 11) != 0)
668 clt->clt_translate = TR_ENABLED;
670 if ((mime = strchr(mime, ';')) == NULL)
674 while ((t = strsep(&mime, ";")) != NULL) {
675 if (!strncmp(t, "charset=", 8)) {
677 if (!strncasecmp(t, "utf8", 4) ||
678 !strncasecmp(t, "utf-8", 5) ||
679 !strncasecmp(t, "ascii", 5)) {
680 log_debug("unknown charset %s", t);
686 if (!strncmp(t, "lang=", 5)) {
688 if ((semi = strchr(t, ';')) != NULL)
691 if (strlcpy(lang, t, len) >= len) {
692 log_debug("lang too long: %s", t);
706 proxy_start_reply(struct client *clt, int status, const char *ctype)
710 csp = "Content-Security-Policy: default-src 'self'; "
711 "script-src 'none'; object-src 'none';\r\n";
714 clt_printf(clt, "Status: %d\r\n", status) == -1)
717 if (clt_puts(clt, csp) == -1)
721 /* use "ctype" as redirect target */
722 if (clt_printf(clt, "Location: %s\r\n", ctype) == -1)
724 if (clt_puts(clt, "\r\n") == -1)
730 if (!strcmp(ctype, "text/html"))
731 ctype = "text/html;charset=utf-8";
732 if (clt_printf(clt, "Content-Type: %s\r\n", ctype)
737 if (clt_puts(clt, "\r\n") == -1)
744 proxy_read(struct bufferevent *bev, void *d)
746 struct client *clt = d;
747 struct evbuffer *src = EVBUFFER_INPUT(bev);
755 if (clt->clt_headersdone) {
756 if (clt->clt_translate)
757 proxy_translate_gemtext(clt);
759 clt_write_bufferevent(clt, bev);
763 hdr = evbuffer_readln(src, &len, EVBUFFER_EOL_CRLF_STRICT);
765 if (EVBUFFER_LENGTH(src) >= 1026)
766 proxy_error(bev, EV_READ, clt);
771 !isdigit((unsigned char)hdr[0]) ||
772 !isdigit((unsigned char)hdr[1]) ||
774 log_warnx("invalid ");
775 proxy_error(bev, EV_READ, clt);
779 code = (hdr[0] - '0') * 10 + (hdr[1] - '0');
783 if (proxy_start_reply(clt, 200, "text/html") == -1)
785 if (tp_inputpage(clt->clt_tp, &hdr[3]) == -1)
787 fcgi_end_request(clt, 0);
793 if (proxy_resurl(clt, &hdr[3], buf, sizeof(buf)) == 0) {
794 if (proxy_start_reply(clt, 302, buf) == -1)
796 fcgi_end_request(clt, 0);
801 if (proxy_start_reply(clt, 501, "text/html") == -1)
803 if (tp_error(clt->clt_tp, code, &hdr[3]) == -1)
805 fcgi_end_request(clt, 1);
809 mime = hdr + 2 + strspn(hdr + 2, " \t");
810 if (parse_mime(clt, mime, lang, sizeof(lang)) == -1) {
811 if (proxy_start_reply(clt, 501, "text/html") == -1)
813 if (tp_error(clt->clt_tp, -1, "Bad response") == -1)
815 fcgi_end_request(clt, 1);
819 if (clt->clt_translate)
820 ctype = "text/html;charset=utf-8";
824 if (clt_printf(clt, "Content-Type: %s\r\n\r\n", ctype) == -1)
827 clt->clt_headersdone = 1;
829 if (clt->clt_translate &&
830 tp_head(clt->clt_tp, lang, NULL) == -1)
834 * Trigger the read again so we proceed with the response
846 proxy_write(struct bufferevent *bev, void *d)
852 proxy_error(struct bufferevent *bev, short err, void *d)
854 struct client *clt = d;
855 int status = !(err & EVBUFFER_EOF);
857 log_debug("proxy error, shutting down the connection (err: %x)",
860 if (!clt->clt_headersdone) {
861 if (proxy_start_reply(clt, 501, "text/html") == -1)
863 if (tp_error(clt->clt_tp, -1, "Proxy error") == -1)
865 } else if (status == 0) {
866 if (clt->clt_translate & TR_PRE) {
867 if (tp_pre_close(clt->clt_tp))
869 clt->clt_translate &= ~TR_PRE;
872 if (clt->clt_translate & TR_LIST) {
873 if (clt_puts(clt, "</ul>") == -1)
875 clt->clt_translate &= ~TR_LIST;
878 if (clt->clt_translate & TR_NAV) {
879 if (clt_puts(clt, "</ul></nav>") == -1)
881 clt->clt_translate &= ~TR_NAV;
884 if (clt->clt_translate &&
885 tp_foot(clt->clt_tp) == -1)
889 fcgi_end_request(clt, status);
893 proxy_tls_readcb(int fd, short event, void *arg)
895 struct bufferevent *bufev = arg;
896 struct client *clt = bufev->cbarg;
897 char rbuf[IBUF_READ_SIZE];
898 int what = EVBUFFER_READ;
899 int howmuch = IBUF_READ_SIZE;
903 if (event == EV_TIMEOUT) {
904 what |= EVBUFFER_TIMEOUT;
908 if (bufev->wm_read.high != 0)
909 howmuch = MINIMUM(sizeof(rbuf), bufev->wm_read.high);
911 ret = tls_read(clt->clt_ctx, rbuf, howmuch);
912 if (ret == TLS_WANT_POLLIN || ret == TLS_WANT_POLLOUT) {
914 } else if (ret == -1) {
915 what |= EVBUFFER_ERROR;
921 what |= EVBUFFER_EOF;
925 if (evbuffer_add(bufev->input, rbuf, len) == -1) {
926 what |= EVBUFFER_ERROR;
930 proxy_bufferevent_add(&bufev->ev_read, G_TOUT(bufev->timeout_read));
932 len = EVBUFFER_LENGTH(bufev->input);
933 if (bufev->wm_read.low != 0 && len < bufev->wm_read.low)
935 if (bufev->wm_read.high != 0 && len > bufev->wm_read.high) {
936 struct evbuffer *buf = bufev->input;
937 event_del(&bufev->ev_read);
938 evbuffer_setcb(buf, bufferevent_read_pressure_cb, bufev);
942 if (bufev->readcb != NULL)
943 (*bufev->readcb)(bufev, bufev->cbarg);
947 proxy_bufferevent_add(&bufev->ev_read, G_TOUT(bufev->timeout_read));
951 (*bufev->errorcb)(bufev, what, bufev->cbarg);
955 proxy_bufferevent_add(struct event *ev, int timeout)
957 struct timeval tv, *ptv = NULL;
965 return (event_add(ev, ptv));
969 proxy_tls_writecb(int fd, short event, void *arg)
971 struct bufferevent *bufev = arg;
972 struct client *clt = bufev->cbarg;
974 short what = EVBUFFER_WRITE;
977 if (event == EV_TIMEOUT) {
978 what |= EVBUFFER_TIMEOUT;
982 if (EVBUFFER_LENGTH(bufev->output)) {
983 ret = tls_write(clt->clt_ctx,
984 EVBUFFER_DATA(bufev->output),
985 EVBUFFER_LENGTH(bufev->output));
986 if (ret == TLS_WANT_POLLIN || ret == TLS_WANT_POLLOUT) {
988 } else if (ret == -1) {
989 what |= EVBUFFER_ERROR;
993 evbuffer_drain(bufev->output, len);
996 if (EVBUFFER_LENGTH(bufev->output) != 0)
997 proxy_bufferevent_add(&bufev->ev_write,
998 G_TOUT(bufev->timeout_write));
1000 if (bufev->writecb != NULL &&
1001 EVBUFFER_LENGTH(bufev->output) <= bufev->wm_write.low)
1002 (*bufev->writecb)(bufev, bufev->cbarg);
1006 proxy_bufferevent_add(&bufev->ev_write, G_TOUT(bufev->timeout_write));
1010 (*bufev->errorcb)(bufev, what, bufev->cbarg);
1014 proxy_client_free(struct client *clt)
1017 event_asr_abort(clt->clt_evasr);
1019 if (clt->clt_addrinfo)
1020 freeaddrinfo(clt->clt_addrinfo);
1022 if (clt->clt_evconn_live)
1023 event_del(&clt->clt_evconn);
1025 if (clt->clt_fd != -1)
1029 tls_free(clt->clt_ctx);
1032 bufferevent_free(clt->clt_bev);
1034 template_free(clt->clt_tp);
1036 free(clt->clt_body);
1037 free(clt->clt_server_name);
1038 free(clt->clt_script_name);
1039 free(clt->clt_path_info);
1040 free(clt->clt_query);