diff options
Diffstat (limited to 'src/tipideed')
| -rw-r--r-- | src/tipideed/deps-exe/tipideed | 1 | ||||
| -rw-r--r-- | src/tipideed/fastcgi.c | 66 | ||||
| -rw-r--r-- | src/tipideed/redirection.c | 4 | ||||
| -rw-r--r-- | src/tipideed/rproxy.c | 11 | ||||
| -rw-r--r-- | src/tipideed/tipideed-internal.h | 5 | ||||
| -rw-r--r-- | src/tipideed/tipideed.c | 14 |
6 files changed, 86 insertions, 15 deletions
diff --git a/src/tipideed/deps-exe/tipideed b/src/tipideed/deps-exe/tipideed index c099ab9..bc32b06 100644 --- a/src/tipideed/deps-exe/tipideed +++ b/src/tipideed/deps-exe/tipideed @@ -1,6 +1,7 @@ cgi.o errors.o harden.o +fastcgi.o options.o regular.o redirection.o diff --git a/src/tipideed/fastcgi.c b/src/tipideed/fastcgi.c new file mode 100644 index 0000000..5d5debf --- /dev/null +++ b/src/tipideed/fastcgi.c @@ -0,0 +1,66 @@ +/* ISC license. */ + +#include <stdint.h> +#include <unistd.h> +#include <strings.h> + +#include <skalibs/uint16.h> +#include <skalibs/fmtscan.h> +#include <skalibs/tai.h> +#include <skalibs/buffer.h> +#include <skalibs/djbunix.h> +#include <skalibs/socket.h> +#include <skalibs/ip46.h> +#include <skalibs/unix-timed.h> + +#include <tipidee/tipidee.h> +#include "tipideed-internal.h" + +#define putit(b, s, deadline) if (buffer_timed_puts_g(b, s, deadline) == -1) die500sys(rql, 111, docroot, "write to ", fn) + +static void do_fastcgi (tipidee_rql const *rql, int fd, char const *sub, char const *docroot, tipidee_headers const *hdr, char const *body, size_t bodylen, tain const *deadline, char const *fn) +{ + char buf[4096] ; + buffer b = BUFFER_INIT(&buffer_write, fd, buf, 4096) ; + _exit(0) ; +} + +static void fastcgi_unix (tipidee_rql const *rql, char const *socketpath, char const *sub, char const *docroot, tipidee_headers const *hdr, char const *body, size_t bodylen) +{ + tain deadline ; + int fd = ipc_stream_nbcoe() ; + if (fd == -1) die500sys(rql, 111, docroot, "create socket") ; + tain_add_g(&deadline, &g.readtto) ; + if (!ipc_timed_connect_g(fd, socketpath, &deadline)) die500sys(rql, 111, docroot, "connect to ", socketpath) ; + do_fastcgi(rql, fd, sub, docroot, hdr, body, bodylen, &deadline, socketpath) ; + fd_close(fd) ; +} + +static inline void fastcgi_tcp (tipidee_rql const *rql, char const *ip, uint16_t port, int is6, char const *sub, char const *docroot, tipidee_headers const *hdr, char const *body, size_t bodylen) +{ + tain deadline ; + size_t m = 0 ; + int fd = socket_tcp46_nbcoe(is6) ; + char fmt[IP6_FMT + UINT16_FMT + 2] ; + if (fd == -1) die500sys(rql, 111, docroot, "create socket") ; + tain_add_g(&deadline, &g.readtto) ; + if (is6) fmt[m++] = '[' ; + m += is6 ? ip6_fmt(fmt + m, ip) : ip4_fmt(fmt + m, ip) ; + if (is6) fmt[m++] = ']' ; + fmt[m++] = ':' ; + m += uint16_fmt(fmt + m, port) ; + fmt[m++] = 0 ; + + if (!(is6 ? socket_deadlineconnstamp6_g(fd, ip, port, &deadline) : socket_deadlineconnstamp4_g(fd, ip, port, &deadline))) + die500sys(rql, 111, docroot, "connect to ", fmt) ; + do_fastcgi(rql, fd, sub, docroot, hdr, body, bodylen, &deadline, fmt) ; + fd_close(fd) ; +} + +void fastcgi (tipidee_rql const *rql, tipidee_redirection const *rd, char const *docroot, tipidee_headers const *hdr, char const *body, size_t bodylen) +{ + if (rd->flags & TIPIDEE_REDIR_ISINET) + fastcgi_tcp(rql, rd->addr, rd->port, !!(rd->flags & TIPIDEE_REDIR_ISV6), rd->sub, docroot, hdr, body, bodylen) ; + else + fastcgi_unix(rql, rd->addr, rd->sub, docroot, hdr, body, bodylen) ; +} diff --git a/src/tipideed/redirection.c b/src/tipideed/redirection.c index ce32e44..f13eabb 100644 --- a/src/tipideed/redirection.c +++ b/src/tipideed/redirection.c @@ -15,12 +15,12 @@ void respond_30x (tipidee_rql const *rql, tipidee_redirection const *rd) static unsigned int const status[4] = { 307, 308, 302, 301 } ; tipidee_defaulttext dt ; tain deadline ; - unsigned int type = rd->type & 3 ; + unsigned int type = rd->flags & 3 ; tipidee_util_defaulttext(status[type], &dt) ; tipidee_response_status(buffer_1, rql, status[type], dt.reason) ; tipidee_response_header_writeall_G(buffer_1, g.rhdr, g.rhdrn, 0) ; buffer_putsnoflush(buffer_1, "Content-Length: 0\r\nLocation: ") ; - buffer_putsnoflush(buffer_1, rd->location) ; + buffer_putsnoflush(buffer_1, rd->addr) ; if (rd->sub) buffer_putsnoflush(buffer_1, rd->sub) ; buffer_putnoflush(buffer_1, "\r\n\r\n", 4) ; tipidee_log_answer(g.logv, rql, status[type], 0) ; diff --git a/src/tipideed/rproxy.c b/src/tipideed/rproxy.c index 5b0ec29..10e9692 100644 --- a/src/tipideed/rproxy.c +++ b/src/tipideed/rproxy.c @@ -64,7 +64,7 @@ static void rproxy_unix (tipidee_rql const *rql, char const *socketpath, char co fd_close(fd) ; } -static void rproxy_tcp (tipidee_rql const *rql, char const *ip, uint16_t port, int is6, char const *sub, char const *docroot, tipidee_headers const *hdr, char const *body, size_t bodylen) +static inline void rproxy_tcp (tipidee_rql const *rql, char const *ip, uint16_t port, int is6, char const *sub, char const *docroot, tipidee_headers const *hdr, char const *body, size_t bodylen) { tain deadline ; size_t m = 0 ; @@ -87,11 +87,8 @@ static void rproxy_tcp (tipidee_rql const *rql, char const *ip, uint16_t port, i void rproxy (tipidee_rql const *rql, tipidee_redirection const *rd, char const *docroot, tipidee_headers const *hdr, char const *body, size_t bodylen) { - if (rd->type & 16) rproxy_unix(rql, rd->location, rd->sub, docroot, hdr, body, bodylen) ; + if (rd->flags & TIPIDEE_REDIR_ISINET) + rproxy_tcp(rql, rd->addr, rd->port, !!(rd->flags & TIPIDEE_REDIR_ISV6), rd->sub, docroot, hdr, body, bodylen) ; else - { - uint16_t port ; - uint16_unpack_big(rd->location, &port) ; - rproxy_tcp(rql, rd->location + 2, port, !!(rd->type & 8), rd->sub, docroot, hdr, body, bodylen) ; - } + rproxy_unix(rql, rd->addr, rd->sub, docroot, hdr, body, bodylen) ; } diff --git a/src/tipideed/tipideed-internal.h b/src/tipideed/tipideed-internal.h index e3e014c..2cc8186 100644 --- a/src/tipideed/tipideed-internal.h +++ b/src/tipideed/tipideed-internal.h @@ -129,6 +129,11 @@ extern void respond_30x (tipidee_rql const *, tipidee_redirection const *) ; extern void rproxy (tipidee_rql const *, tipidee_redirection const *, char const *, tipidee_headers const *, char const *, size_t) ; + /* fastcgi */ + +extern void fastcgi (tipidee_rql const *, tipidee_redirection const *, char const *, tipidee_headers const *, char const *, size_t) ; + + /* trace */ extern int respond_trace (tipidee_rql const *, tipidee_headers const *) ; diff --git a/src/tipideed/tipideed.c b/src/tipideed/tipideed.c index b5098af..402c59c 100644 --- a/src/tipideed/tipideed.c +++ b/src/tipideed/tipideed.c @@ -211,12 +211,12 @@ static inline void get_resattr (tipidee_rql const *rql, char const *docroot, cha static inline void force_redirect (tipidee_rql const *rql, char const *fn) { - tipidee_redirection rd = { .sub = 0, .type = 1 } ; + tipidee_redirection rd = { .sub = 0, .type = TIPIDEE_REDIR_REDIRECT, .flags = TIPIDEE_REDIR_308, .port = 0 } ; size_t len = strlen(fn) ; char location[len + 8 + g.ssl] ; memcpy(location, g.ssl ? "https://" : "http://", 7 + g.ssl) ; memcpy(location + 7 + g.ssl, fn, len + 1) ; - rd.location = location ; + rd.addr = location ; respond_30x(rql, &rd) ; } @@ -241,11 +241,13 @@ static inline int serve (tipidee_rql *rql, char const *docroot, char *uribuf, ti tipidee_redirection rd = TIPIDEE_REDIRECTION_ZERO ; int e = tipidee_conf_get_redirection(&g.conf, docroot, docrootlen, rql->uri.path, &rd) ; if (e == -1) die500sys(rql, 111, docroot, "get redirection data for ", fn) ; - if (e) + if (e) switch (rd.type) { - if (rd.type & 32) rproxy(rql, &rd, docroot, hdr, body, bodylen) ; - else respond_30x(rql, &rd) ; - return 0 ; + case TIPIDEE_REDIR_NONE : break ; + case TIPIDEE_REDIR_REDIRECT : respond_30x(rql, &rd) ; return 0 ; + case TIPIDEE_REDIR_RPROXY : rproxy(rql, &rd, docroot, hdr, body, bodylen) ; return 0 ; + case TIPIDEE_REDIR_FASTCGI : fastcgi(rql, &rd, docroot, hdr, body, bodylen) ; return 0 ; + default : strerr_dief(101, "can't happen: ", "unknown redirection type") ; } } |
