X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Futils.c;h=4a822814609ee26811bb6eb15c0ad4dc036d468a;hb=HEAD;hp=7d6b02bdcc97541c1a68c7fce546f0711f56d0e2;hpb=8e165dd308679f195af8614d62dbdb4e43238495;p=citadel.git diff --git a/webcit/utils.c b/webcit/utils.c index 7d6b02bdc..e08dcb7d5 100644 --- a/webcit/utils.c +++ b/webcit/utils.c @@ -1,8 +1,4 @@ -/* - * $Id: utils.c 6808 2008-12-11 00:00:36Z dothebart $ - * - * de/encoding stuff. hopefully mostly to be depricated in favour of subst.c + strbuf - */ +// de/encoding stuff. hopefully mostly to be depricated in favour of subst.c + strbuf #define SHOW_ME_VAPPEND_PRINTF #include @@ -10,11 +6,8 @@ #include "webcit.h" -/* - * remove escaped strings from i.e. the url string (like %20 for blanks) - */ -long unescape_input(char *buf) -{ +// remove escaped strings from i.e. the url string (like %20 for blanks) +long unescape_input(char *buf) { unsigned int a, b; char hex[3]; long buflen; @@ -32,7 +25,7 @@ long unescape_input(char *buf) if (buf[a] == '+') buf[a] = ' '; if (buf[a] == '%') { - /* don't let % chars through, rather truncate the input. */ + // don't let % chars through, rather truncate the input. if (a + 2 > buflen) { buf[a] = '\0'; buflen = a; @@ -56,22 +49,19 @@ long unescape_input(char *buf) return a; } -/* - * 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) -{ +// 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... */ + eptr = target + tSize - 6; // our biggest unit to put in... while ((bptr < eptr) && !IsEmptyStr(aptr) ){ @@ -129,151 +119,39 @@ long stresc(char *target, long tSize, char *strbuf, int nbsp, int nolinebreaks) return (bptr - target); } - -void escputs1(const char *strbuf, int nbsp, int nolinebreaks) -{ - StrEscAppend(WC->WBuf, NULL, strbuf, nbsp, nolinebreaks); -} - -void StrEscputs1(const StrBuf *strbuf, int nbsp, int nolinebreaks) -{ - StrEscAppend(WC->WBuf, strbuf, NULL, nbsp, nolinebreaks); +// static wrapper for escputs1 +void escputs(const char *strbuf) { + StrEscAppend(WC->WBuf, NULL, strbuf, 0, 0); } -/* - * static wrapper for ecsputs1 - */ -void escputs(const char *strbuf) -{ - escputs1(strbuf, 0, 0); -} - - -/* - * static wrapper for ecsputs1 - */ -void StrEscPuts(const StrBuf *strbuf) -{ - StrEscputs1(strbuf, 0, 0); -} - - -/* - * urlescape buffer and print it to the client - */ -void urlescputs(const char *strbuf) -{ +// urlescape buffer and print it to the client +void urlescputs(const char *strbuf) { 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(const char *strbuf) -{ +// urlescape buffer and print it as header +void hurlescputs(const char *strbuf) { StrBufUrlescAppend(WC->HBuf, NULL, strbuf); } -/* - * Copy a string, escaping characters for JavaScript strings. - */ -void jsesc(char *target, size_t tlen, char *strbuf) -{ - int len; - char *tend; - char *send; - char *tptr; - char *sptr; +// Output a string to the client as a CDATA block +void cdataout(char *rawdata) { + char *ptr = rawdata; + wc_printf("') - *tptr = ']'; - else if (*sptr == '\'') { - if (tend - tptr < 3) - return; - *(tptr++) = '\\'; - *tptr = '\''; - } - else if (*sptr == '"') { - if (tend - tptr < 8) - return; - *(tptr++) = '&'; - *(tptr++) = 'q'; - *(tptr++) = 'u'; - *(tptr++) = 'o'; - *(tptr++) = 't'; - *tptr = ';'; + while ((ptr != NULL) && (ptr[0] != 0)) + { + if (!strncmp(ptr, "]]>", 3)) { + wc_printf("]]]]>"); + ++ptr; ++ptr; ++ptr; } - else if (*sptr == '&') { - if (tend - tptr < 7) - return; - *(tptr++) = '&'; - *(tptr++) = 'a'; - *(tptr++) = 'm'; - *(tptr++) = 'p'; - *tptr = ';'; - } else { - *tptr = *sptr; + else { + wc_printf("%c", ptr[0]); + ++ptr; } - tptr++; sptr++; } - *tptr = '\0'; -} - -/* - * escape and print javascript - */ -void jsescputs(char *strbuf) -{ - char outbuf[SIZ]; - - jsesc(outbuf, SIZ, strbuf); - wc_printf("%s", outbuf); -} - -/* - * print a string to the client after cleaning it with msgesc() and stresc() - */ -void msgescputs1( char *strbuf) -{ - StrBuf *OutBuf; - - if ((strbuf == NULL) || IsEmptyStr(strbuf)) - return; - OutBuf = NewStrBuf(); - StrMsgEscAppend(OutBuf, NULL, strbuf); - StrEscAppend(WC->WBuf, OutBuf, NULL, 0, 0); - FreeStrBuf(&OutBuf); -} - -/* - * print a string to the client after cleaning it with msgesc() - */ -void msgescputs(char *strbuf) { - if ((strbuf != NULL) && !IsEmptyStr(strbuf)) - StrMsgEscAppend(WC->WBuf, NULL, strbuf); -} - - + wc_printf("]]>"); +} \ No newline at end of file