1 // de/encoding stuff. hopefully mostly to be depricated in favour of subst.c + strbuf
3 #define SHOW_ME_VAPPEND_PRINTF
9 // remove escaped strings from i.e. the url string (like %20 for blanks)
10 long unescape_input(char *buf) {
18 while ((buflen > 0) && (isspace(buf[buflen - 1]))){
28 // don't let % chars through, rather truncate the input.
42 memmove(&buf[a + 1], &buf[a + 3], len);
52 // Copy a string, escaping characters which have meaning in HTML.
54 // target target buffer
55 // strbuf source buffer
56 // nbsp If nonzero, spaces are converted to non-breaking spaces.
57 // nolinebreaks if set, linebreaks are removed from the string.
58 long stresc(char *target, long tSize, char *strbuf, int nbsp, int nolinebreaks) {
59 char *aptr, *bptr, *eptr;
64 eptr = target + tSize - 6; // our biggest unit to put in...
67 while ((bptr < eptr) && !IsEmptyStr(aptr) ){
69 memcpy(bptr, "<", 4);
72 else if (*aptr == '>') {
73 memcpy(bptr, ">", 4);
76 else if (*aptr == '&') {
77 memcpy(bptr, "&", 5);
80 else if (*aptr == '\"') {
81 memcpy(bptr, """, 6);
84 else if (*aptr == '\'') {
85 memcpy(bptr, "'", 5);
88 else if (*aptr == LB) {
92 else if (*aptr == RB) {
96 else if (*aptr == QU) {
100 else if ((*aptr == 32) && (nbsp == 1)) {
101 memcpy(bptr, " ", 6);
104 else if ((*aptr == '\n') && (nolinebreaks)) {
105 *bptr='\0'; /* nothing */
107 else if ((*aptr == '\r') && (nolinebreaks)) {
108 *bptr='\0'; /* nothing */
117 if ((bptr = eptr - 1 ) && !IsEmptyStr(aptr) )
119 return (bptr - target);
122 // static wrapper for escputs1
123 void escputs(const char *strbuf) {
124 StrEscAppend(WC->WBuf, NULL, strbuf, 0, 0);
127 // urlescape buffer and print it to the client
128 void urlescputs(const char *strbuf) {
129 StrBufUrlescAppend(WC->WBuf, NULL, strbuf);
133 // urlescape buffer and print it as header
134 void hurlescputs(const char *strbuf) {
135 StrBufUrlescAppend(WC->HBuf, NULL, strbuf);
139 // Output a string to the client as a CDATA block
140 void cdataout(char *rawdata) {
142 wc_printf("<![CDATA[");
144 while ((ptr != NULL) && (ptr[0] != 0))
146 if (!strncmp(ptr, "]]>", 3)) {
147 wc_printf("]]]]><![CDATA[>");
151 wc_printf("%c", ptr[0]);