3 * de/encoding stuff. hopefully mostly to be depricated in favour of subst.c + strbuf
6 #define SHOW_ME_VAPPEND_PRINTF
13 * remove escaped strings from i.e. the url string (like %20 for blanks)
15 long unescape_input(char *buf) {
23 while ((buflen > 0) && (isspace(buf[buflen - 1]))) {
33 /* don't let % chars through, rather truncate the input. */
47 memmove(&buf[a + 1], &buf[a + 3], len);
58 * Copy a string, escaping characters which have meaning in HTML.
60 * target target buffer
61 * strbuf source buffer
62 * nbsp If nonzero, spaces are converted to non-breaking spaces.
63 * nolinebreaks if set, linebreaks are removed from the string.
65 long stresc(char *target, long tSize, char *strbuf, int nbsp, int nolinebreaks) {
66 char *aptr, *bptr, *eptr;
71 eptr = target + tSize - 6; /* our biggest unit to put in... */
74 while ((bptr < eptr) && !IsEmptyStr(aptr)) {
76 memcpy(bptr, "<", 4);
79 else if (*aptr == '>') {
80 memcpy(bptr, ">", 4);
83 else if (*aptr == '&') {
84 memcpy(bptr, "&", 5);
87 else if (*aptr == '\"') {
88 memcpy(bptr, """, 6);
91 else if (*aptr == '\'') {
92 memcpy(bptr, "'", 5);
95 else if (*aptr == LB) {
99 else if (*aptr == RB) {
103 else if (*aptr == QU) {
107 else if ((*aptr == 32) && (nbsp == 1)) {
108 memcpy(bptr, " ", 6);
111 else if ((*aptr == '\n') && (nolinebreaks)) {
112 *bptr = '\0'; /* nothing */
114 else if ((*aptr == '\r') && (nolinebreaks)) {
115 *bptr = '\0'; /* nothing */
124 if ((bptr = eptr - 1) && !IsEmptyStr(aptr))
126 return (bptr - target);
130 * static wrapper for ecsputs1
132 void escputs(const char *strbuf) {
133 StrEscAppend(WC->WBuf, NULL, strbuf, 0, 0);
137 * urlescape buffer and print it to the client
139 void urlescputs(const char *strbuf) {
140 StrBufUrlescAppend(WC->WBuf, NULL, strbuf);
145 * urlescape buffer and print it as header
147 void hurlescputs(const char *strbuf) {
148 StrBufUrlescAppend(WC->HBuf, NULL, strbuf);
153 * Output a string to the client as a CDATA block
155 void cdataout(char *rawdata) {
157 wc_printf("<![CDATA[");
159 while ((ptr != NULL) && (ptr[0] != 0)) {
160 if (!strncmp(ptr, "]]>", 3)) {
161 wc_printf("]]]]><![CDATA[>");
167 wc_printf("%c", ptr[0]);