2 * de/encoding stuff. hopefully mostly to be depricated in favour of subst.c + strbuf
5 #define SHOW_ME_VAPPEND_PRINTF
12 * remove escaped strings from i.e. the url string (like %20 for blanks)
14 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)
67 char *aptr, *bptr, *eptr;
72 eptr = target + tSize - 6; /* our biggest unit to put in... */
75 while ((bptr < eptr) && !IsEmptyStr(aptr) ){
77 memcpy(bptr, "<", 4);
80 else if (*aptr == '>') {
81 memcpy(bptr, ">", 4);
84 else if (*aptr == '&') {
85 memcpy(bptr, "&", 5);
88 else if (*aptr == '\"') {
89 memcpy(bptr, """, 6);
92 else if (*aptr == '\'') {
93 memcpy(bptr, "'", 5);
96 else if (*aptr == LB) {
100 else if (*aptr == RB) {
104 else if (*aptr == QU) {
108 else if ((*aptr == 32) && (nbsp == 1)) {
109 memcpy(bptr, " ", 6);
112 else if ((*aptr == '\n') && (nolinebreaks)) {
113 *bptr='\0'; /* nothing */
115 else if ((*aptr == '\r') && (nolinebreaks)) {
116 *bptr='\0'; /* nothing */
125 if ((bptr = eptr - 1 ) && !IsEmptyStr(aptr) )
127 return (bptr - target);
131 * static wrapper for ecsputs1
133 void escputs(const char *strbuf)
135 StrEscAppend(WC->WBuf, NULL, strbuf, 0, 0);
139 * urlescape buffer and print it to the client
141 void urlescputs(const char *strbuf)
143 StrBufUrlescAppend(WC->WBuf, NULL, strbuf);
148 * urlescape buffer and print it as header
150 void hurlescputs(const char *strbuf)
152 StrBufUrlescAppend(WC->HBuf, NULL, strbuf);
157 * Output a string to the client as a CDATA block
159 void cdataout(char *rawdata)
162 wc_printf("<![CDATA[");
164 while ((ptr != NULL) && (ptr[0] != 0))
166 if (!strncmp(ptr, "]]>", 3)) {
167 wc_printf("]]]]><![CDATA[>");
171 wc_printf("%c", ptr[0]);