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 void escputs1(const char *strbuf, int nbsp, int nolinebreaks)
133 StrEscAppend(WC->WBuf, NULL, strbuf, nbsp, nolinebreaks);
136 void StrEscputs1(const StrBuf *strbuf, int nbsp, int nolinebreaks)
138 StrEscAppend(WC->WBuf, strbuf, NULL, nbsp, nolinebreaks);
142 * static wrapper for ecsputs1
144 void escputs(const char *strbuf)
146 escputs1(strbuf, 0, 0);
151 * static wrapper for ecsputs1
153 void StrEscPuts(const StrBuf *strbuf)
155 StrEscputs1(strbuf, 0, 0);
160 * urlescape buffer and print it to the client
162 void urlescputs(const char *strbuf)
164 StrBufUrlescAppend(WC->WBuf, NULL, strbuf);
168 * urlescape buffer and print it to the client
170 void UrlescPutStrBuf(const StrBuf *strbuf)
172 StrBufUrlescAppend(WC->WBuf, strbuf, NULL);
176 * urlescape buffer and print it as header
178 void hurlescputs(const char *strbuf)
180 StrBufUrlescAppend(WC->HBuf, NULL, strbuf);
185 * Copy a string, escaping characters for JavaScript strings.
187 void jsesc(char *target, size_t tlen, char *strbuf)
196 len = strlen (strbuf);
198 tend = target + tlen;
202 while (!IsEmptyStr(sptr) &&
208 else if (*sptr == '>')
210 else if (*sptr == '\'') {
216 else if (*sptr == '"') {
226 else if (*sptr == '&') {
243 * escape and print javascript
245 void jsescputs(char *strbuf)
249 jsesc(outbuf, SIZ, strbuf);
250 wc_printf("%s", outbuf);
254 * print a string to the client after cleaning it with msgesc() and stresc()
256 void msgescputs1( char *strbuf)
260 if ((strbuf == NULL) || IsEmptyStr(strbuf))
262 OutBuf = NewStrBuf();
263 StrMsgEscAppend(OutBuf, NULL, strbuf);
264 StrEscAppend(WC->WBuf, OutBuf, NULL, 0, 0);
269 * print a string to the client after cleaning it with msgesc()
271 void msgescputs(char *strbuf) {
272 if ((strbuf != NULL) && !IsEmptyStr(strbuf))
273 StrMsgEscAppend(WC->WBuf, NULL, strbuf);
281 * Output a string to the client as a CDATA block
283 void cdataout(char *rawdata)
286 wc_printf("<![CDATA[");
288 while ((ptr != NULL) && (ptr[0] != 0))
290 if (!strncmp(ptr, "]]>", 3)) {
291 wc_printf("]]]]><![CDATA[>");
295 wc_printf("%c", ptr[0]);