X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fwebcit.c;h=a63d9f383f6623cb23f272352edd8febfc7327d3;hb=0c7439d969d42ea85ecd26202d709f2550ff1c58;hp=3034419c8fed3628886f72f0bbec74ec68e2bd06;hpb=8d6fb6f9425da9daf22b9570f3a31d3f630c6eb6;p=citadel.git diff --git a/webcit/webcit.c b/webcit/webcit.c index 3034419c8..a63d9f383 100644 --- a/webcit/webcit.c +++ b/webcit/webcit.c @@ -409,89 +409,15 @@ void wDumpContent(int print_standard_html_footer) } -/* - * Copy a string, escaping characters which have meaning in HTML. - * - * target target buffer - * strbuf source buffer - * nbsp If nonzero, spaces are converted to non-breaking spaces. - * nolinebreaks if set, linebreaks are removed from the string. - */ -long stresc(char *target, long tSize, char *strbuf, int nbsp, int nolinebreaks) -{ - char *aptr, *bptr, *eptr; - - *target = '\0'; - aptr = strbuf; - bptr = target; - eptr = target + tSize - 6; // our biggest unit to put in... - - while ((bptr < eptr) && !IsEmptyStr(aptr) ){ - if (*aptr == '<') { - memcpy(bptr, "<", 4); - bptr += 4; - } - else if (*aptr == '>') { - memcpy(bptr, ">", 4); - bptr += 4; - } - else if (*aptr == '&') { - memcpy(bptr, "&", 5); - bptr += 5; - } - else if (*aptr == '\"') { - memcpy(bptr, """, 6); - bptr += 6; - } - else if (*aptr == '\'') { - memcpy(bptr, "'", 5); - bptr += 5; - } - else if (*aptr == LB) { - *bptr = '<'; - bptr ++; - } - else if (*aptr == RB) { - *bptr = '>'; - bptr ++; - } - else if (*aptr == QU) { - *bptr ='"'; - bptr ++; - } - else if ((*aptr == 32) && (nbsp == 1)) { - memcpy(bptr, " ", 6); - bptr += 6; - } - else if ((*aptr == '\n') && (nolinebreaks)) { - *bptr='\0'; /* nothing */ - } - else if ((*aptr == '\r') && (nolinebreaks)) { - *bptr='\0'; /* nothing */ - } - else{ - *bptr = *aptr; - bptr++; - } - aptr ++; - } - *bptr = '\0'; - if ((bptr = eptr - 1 ) && !IsEmptyStr(aptr) ) - return -1; - return (bptr - target); -} void escputs1(char *strbuf, int nbsp, int nolinebreaks) { - char *buf; - long Siz; + StrEscAppend(WC->WBuf, NULL, strbuf, nbsp, nolinebreaks); +} - if (strbuf == NULL) return; - Siz = (3 * strlen(strbuf)) + SIZ ; - buf = malloc(Siz); - stresc(buf, Siz, strbuf, nbsp, nolinebreaks); - wprintf("%s", buf); - free(buf); +void StrEscputs1(const StrBuf *strbuf, int nbsp, int nolinebreaks) +{ + StrEscAppend(WC->WBuf, strbuf, NULL, nbsp, nolinebreaks); } /* @@ -503,24 +429,37 @@ void escputs(char *strbuf) } +/* + * static wrapper for ecsputs1 + */ +void StrEscPuts(const StrBuf *strbuf) +{ + StrEscputs1(strbuf, 0, 0); +} + + /* * urlescape buffer and print it to the client */ -void urlescputs(char *strbuf) +void urlescputs(const char *strbuf) { - char outbuf[SIZ]; - - urlesc(outbuf, SIZ, strbuf); - wprintf("%s", outbuf); + StrBufUrlescAppend(WC->WBuf, NULL, strbuf); } + +/* + * urlescape buffer and print it to the client + */ +void UrlescPutStrBuf(const StrBuf *strbuf) +{ + StrBufUrlescAppend(WC->WBuf, strbuf, NULL); +} + /** * urlescape buffer and print it as header */ -void hurlescputs(char *strbuf) { - char outbuf[SIZ]; - - urlesc(outbuf, SIZ, strbuf); - hprintf("%s", outbuf); +void hurlescputs(const char *strbuf) +{ + StrBufUrlescAppend(WC->HBuf, NULL, strbuf); }