commit df2db2149a21ac230e2961435f2b3011bae12d41 from: Omar Polo date: Mon Sep 19 14:33:48 2022 UTC switch to the escaping function from tmpl.h it also fixes some issue / limitations of the old htmlescape / printurl. commit - bff58270a8ffa0e66ce97234e440b545ba9290d3 commit + df2db2149a21ac230e2961435f2b3011bae12d41 blob - 6096ef855d97f397cf4a1cb0c4521cdf43eca476 blob + 174d291acae8533ddd33ce821c32214b578043a4 --- proxy.c +++ proxy.c @@ -149,56 +149,6 @@ proxy_dispatch_parent(int fd, struct privsep_proc *p, default: log_warnx("unknown message %d", imsg->hdr.type); return (-1); - } - - return (0); -} - -static inline int -printurl(struct client *clt, const char *str) -{ - for (; *str; ++str) { - switch (*str) { - case ' ': - case '\t': - case '\'': - case '\\': - if (clt_printf(clt, "%2X", (unsigned char)*str) == -1) - return (-1); - break; - default: - if (clt_putc(clt, *str) == -1) - return (-1); - break; - } - } - - return (0); -} - -static inline int -htmlescape(struct client *clt, const char *str) -{ - int r; - - for (; *str; ++str) { - switch (*str) { - case '<': - r = clt_puts(clt, "<"); - break; - case '>': - r = clt_puts(clt, ">"); - break; - case '&': - r = clt_puts(clt, "&"); - break; - default: - r = clt_putc(clt, *str); - break; - } - - if (r == -1) - return (-1); } return (0); @@ -214,7 +164,7 @@ gemtext_translate_line(struct client *clt, char *line) return (clt_puts(clt, "")); } - if (htmlescape(clt, line) == -1) + if (tp_htmlescape(clt->clt_tp, line) == -1) return (-1); return (clt_putc(clt, '\n')); } @@ -234,7 +184,7 @@ gemtext_translate_line(struct client *clt, char *line) } if (clt_puts(clt, "
  • ") == -1 || - htmlescape(clt, line + 2) == -1 || + tp_htmlescape(clt->clt_tp, line + 2) == -1 || clt_puts(clt, "
  • ") == -1) return (-1); return (0); @@ -284,9 +234,9 @@ gemtext_translate_line(struct client *clt, char *line) } if (clt_puts(clt, "
  • ") == -1 || - htmlescape(clt, label) == -1 || + tp_htmlescape(clt->clt_tp, label) == -1 || clt_puts(clt, "
  • ") == -1) return (-1); @@ -308,7 +258,7 @@ gemtext_translate_line(struct client *clt, char *line) /* citation block */ if (*line == '>') { if (clt_puts(clt, "
    ") == -1 || - htmlescape(clt, line + 1) == -1 || + tp_htmlescape(clt->clt_tp, line + 1) == -1 || clt_puts(clt, "
    ") == -1) return (-1); return (0); @@ -317,21 +267,21 @@ gemtext_translate_line(struct client *clt, char *line) /* headings */ if (!strncmp(line, "###", 3)) { if (clt_puts(clt, "

    ") == -1 || - htmlescape(clt, line + 3) == -1 || + tp_htmlescape(clt->clt_tp, line + 3) == -1 || clt_puts(clt, "

    ") == -1) return (-1); return (0); } if (!strncmp(line, "##", 2)) { if (clt_puts(clt, "

    ") == -1 || - htmlescape(clt, line + 2) == -1 || + tp_htmlescape(clt->clt_tp, line + 2) == -1 || clt_puts(clt, "

    ") == -1) return (-1); return (0); } if (!strncmp(line, "#", 1)) { if (clt_puts(clt, "

    ") == -1 || - htmlescape(clt, line + 1) == -1 || + tp_htmlescape(clt->clt_tp, line + 1) == -1 || clt_puts(clt, "

    ") == -1) return (-1); return (0); @@ -343,7 +293,7 @@ gemtext_translate_line(struct client *clt, char *line) /* paragraph */ if (clt_puts(clt, "

    ") == -1 || - htmlescape(clt, line) == -1 || + tp_htmlescape(clt->clt_tp, line) == -1 || clt_puts(clt, "

    ") == -1) return (-1);