4 * de/encoding stuff. hopefully mostly to be depricated in favour of subst.c + strbuf
7 #define SHOW_ME_VAPPEND_PRINTF
14 * remove escaped strings from i.e. the url string (like %20 for blanks)
16 long unescape_input(char *buf)
25 while ((buflen > 0) && (isspace(buf[buflen - 1]))){
35 /* don't let % chars through, rather truncate the input. */
49 memmove(&buf[a + 1], &buf[a + 3], len);
60 * Copy a string, escaping characters which have meaning in HTML.
62 * target target buffer
63 * strbuf source buffer
64 * nbsp If nonzero, spaces are converted to non-breaking spaces.
65 * nolinebreaks if set, linebreaks are removed from the string.
67 long stresc(char *target, long tSize, char *strbuf, int nbsp, int nolinebreaks)
69 char *aptr, *bptr, *eptr;
74 eptr = target + tSize - 6; /* our biggest unit to put in... */
77 while ((bptr < eptr) && !IsEmptyStr(aptr) ){
79 memcpy(bptr, "<", 4);
82 else if (*aptr == '>') {
83 memcpy(bptr, ">", 4);
86 else if (*aptr == '&') {
87 memcpy(bptr, "&", 5);
90 else if (*aptr == '\"') {
91 memcpy(bptr, """, 6);
94 else if (*aptr == '\'') {
95 memcpy(bptr, "'", 5);
98 else if (*aptr == LB) {
102 else if (*aptr == RB) {
106 else if (*aptr == QU) {
110 else if ((*aptr == 32) && (nbsp == 1)) {
111 memcpy(bptr, " ", 6);
114 else if ((*aptr == '\n') && (nolinebreaks)) {
115 *bptr='\0'; /* nothing */
117 else if ((*aptr == '\r') && (nolinebreaks)) {
118 *bptr='\0'; /* nothing */
127 if ((bptr = eptr - 1 ) && !IsEmptyStr(aptr) )
129 return (bptr - target);
133 void escputs1(const char *strbuf, int nbsp, int nolinebreaks)
135 StrEscAppend(WC->WBuf, NULL, strbuf, nbsp, nolinebreaks);
138 void StrEscputs1(const StrBuf *strbuf, int nbsp, int nolinebreaks)
140 StrEscAppend(WC->WBuf, strbuf, NULL, nbsp, nolinebreaks);
144 * static wrapper for ecsputs1
146 void escputs(const char *strbuf)
148 escputs1(strbuf, 0, 0);
153 * static wrapper for ecsputs1
155 void StrEscPuts(const StrBuf *strbuf)
157 StrEscputs1(strbuf, 0, 0);
162 * urlescape buffer and print it to the client
164 void urlescputs(const char *strbuf)
166 StrBufUrlescAppend(WC->WBuf, NULL, strbuf);
170 * urlescape buffer and print it to the client
172 void UrlescPutStrBuf(const StrBuf *strbuf)
174 StrBufUrlescAppend(WC->WBuf, strbuf, NULL);
178 * urlescape buffer and print it as header
180 void hurlescputs(const char *strbuf)
182 StrBufUrlescAppend(WC->HBuf, NULL, strbuf);
187 * Copy a string, escaping characters for JavaScript strings.
189 void jsesc(char *target, size_t tlen, char *strbuf)
198 len = strlen (strbuf);
200 tend = target + tlen;
204 while (!IsEmptyStr(sptr) &&
210 else if (*sptr == '>')
212 else if (*sptr == '\'') {
218 else if (*sptr == '"') {
228 else if (*sptr == '&') {
245 * escape and print javascript
247 void jsescputs(char *strbuf)
251 jsesc(outbuf, SIZ, strbuf);
252 wc_printf("%s", outbuf);
256 * print a string to the client after cleaning it with msgesc() and stresc()
258 void msgescputs1( char *strbuf)
262 if ((strbuf == NULL) || IsEmptyStr(strbuf))
264 OutBuf = NewStrBuf();
265 StrMsgEscAppend(OutBuf, NULL, strbuf);
266 StrEscAppend(WC->WBuf, OutBuf, NULL, 0, 0);
271 * print a string to the client after cleaning it with msgesc()
273 void msgescputs(char *strbuf) {
274 if ((strbuf != NULL) && !IsEmptyStr(strbuf))
275 StrMsgEscAppend(WC->WBuf, NULL, strbuf);