phroxy

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.z3bra.org/phroxy.git
Log | Files | Refs | LICENSE

commit e159168461c30eb37813b1c43afa98d27bc3d6d5
parent c3904deacd7faa41c91e97ae247e0791c945138f
Author: Willy Goiffon <dev@z3bra.org>
Date:   Fri, 11 Sep 2020 22:37:01 +0200

Wrap types 0 and 1 in HTML

Diffstat:
Mphroxy.c | 41+++++++++++++++++++++++++++++++++++++----
1 file changed, 37 insertions(+), 4 deletions(-)

diff --git a/phroxy.c b/phroxy.c @@ -205,16 +205,49 @@ printheaders(char *ctype) printf("Connection: close\r\n"); } +char * +htmlize(char *data, size_t len, size_t *newsize) +{ + size_t hlen; + char *html = NULL; + + char *foot = "</pre></body></html>"; + char *head = + "<!DOCTYPE HTML>" + "<html><head>" + "<meta charset=\"utf-8\">" + "<meta name=\"viewport\" content=\"width=device-width\">" + "<link rel=\"stylesheet\" type=\"text/css\" href=\"https://z3bra.org/z3bra.css\">" + "<title>phroxy(8)</title>" + "</head><body><pre>\n"; + + hlen = len + strlen(head) + strlen(foot); + html = malloc(hlen); + if (!html) + return NULL; + + snprintf(html, hlen, "%s%s%s", head, data, foot); + + if (newsize) + *newsize = hlen; + + return html; +} int serveitem(char item, char *data, size_t len) { - char *sendi; + char *send, *html; int sent; switch(item) { case '0': case '1': + html = htmlize(data, len, &len); + free(data); + data = html; + break; + case '6': case '9': case 'g': @@ -243,12 +276,12 @@ serveitem(char item, char *data, size_t len) printf("\r\n"); fflush(stdout); - sendi = data; + send = data; while (len > 0) { - if ((sent = write(1, sendi, len)) < 0) + if ((sent = write(1, send, len)) < 0) return 1; len -= sent; - sendi += sent; + send += sent; } return 0;