Annotation of parser3/src/main/untaint.C, revision 1.161
1.7 paf 1: /** @file
1.8 paf 2: Parser: String class part: untaint mechanizm.
3:
1.135 paf 4: Copyright(c) 2001-2005 ArtLebedev Group (http://www.artlebedev.com)
1.89 paf 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.103 paf 6: */
1.8 paf 7:
1.161 ! moko 8: static const char * const IDENT_UNTAINT_C="$Date: 2010-11-15 23:47:56 $";
1.117 paf 9:
1.1 paf 10:
11: #include "pa_string.h"
12: #include "pa_hash.h"
13: #include "pa_exception.h"
1.13 paf 14: #include "pa_table.h"
1.32 paf 15: #include "pa_globals.h"
1.58 parser 16: #include "pa_dictionary.h"
1.66 parser 17: #include "pa_common.h"
1.85 paf 18: #include "pa_charset.h"
1.117 paf 19: #include "pa_request_charsets.h"
20: #include "pa_sapi.h"
1.1 paf 21:
1.117 paf 22: extern "C" { // author forgot to do that
23: #include "ec.h"
24: }
1.91 paf 25:
1.117 paf 26: #include "pa_sql_connection.h"
1.91 paf 27:
1.117 paf 28: // defines
29:
30: #undef CORD_ec_append
31: // redefining to intercept flushes and implement whitespace optimization
32: // of all consequent white space chars leaving only first one
33: #define CORD_ec_append(x, c) \
34: { \
35: bool skip=false; \
36: if(optimize) switch(c) { \
1.131 paf 37: case ' ': case '\n': case '\t': \
1.117 paf 38: if(whitespace) \
39: skip=true; /*skipping subsequent*/ \
40: else \
41: whitespace=true; \
42: break; \
43: default: \
44: whitespace=false; \
45: break; \
46: } \
47: if(!skip) { \
48: if ((x)[0].ec_bufptr == (x)[0].ec_buf + CORD_BUFSZ) { \
49: CORD_ec_flush_buf(x); \
50: } \
51: *((x)[0].ec_bufptr)++ = (c); \
52: } \
53: }
54:
55:
1.140 misha 56: #define escape_fragment(action) \
1.119 paf 57: for(; fragment_length--; CORD_next(info->pos)) { \
58: char c=CORD_pos_fetch(info->pos); \
1.117 paf 59: action \
1.1 paf 60: }
1.133 paf 61: #define _default CORD_ec_append(info->result, c)
1.117 paf 62: #define encode(need_encode_func, prefix, otherwise) \
63: if(need_encode_func(c)) { \
64: static const char* hex="0123456789ABCDEF"; \
1.119 paf 65: CORD_ec_append(info->result, prefix); \
66: CORD_ec_append(info->result, hex[((unsigned char)c)/0x10]); \
67: CORD_ec_append(info->result, hex[((unsigned char)c)%0x10]); \
1.117 paf 68: } else \
1.119 paf 69: CORD_ec_append(info->result, otherwise);
1.126 paf 70: #define to_char(c) { CORD_ec_append(info->result, c); whitespace=false; }
71: #define to_string(s) { CORD_ec_append_cord(info->result, s); whitespace=false; }
1.4 paf 72:
1.9 paf 73: inline bool need_file_encode(unsigned char c){
1.108 paf 74: // russian letters and space ENABLED
75: // encoding only these...
76: return strchr(
1.143 misha 77: "*?'\"<>|"
1.108 paf 78: #ifndef WIN32
1.143 misha 79: ":\\"
1.31 paf 80: #endif
1.143 misha 81: , c)!=0;
1.9 paf 82: }
1.143 misha 83:
1.5 paf 84: inline bool need_uri_encode(unsigned char c){
1.152 misha 85: if((c>='0') && (c<='9') || (c>='A') && (c<='Z') || (c>='a') && (c<='z'))
1.4 paf 86: return false;
87:
1.158 moko 88: return !strchr("_-./*", c);
1.4 paf 89: }
1.143 misha 90:
1.136 paf 91: inline bool need_regex_escape(unsigned char c){
1.142 misha 92: return strchr("\\^$.[]|()?*+{}-", c)!=0;
1.136 paf 93: }
1.1 paf 94:
1.150 misha 95: inline bool need_parser_code_escape(unsigned char c){
96: return strchr("^$;@()[]{}:#\"", c)!=0;
97: }
98:
1.1 paf 99: // String
100:
1.41 paf 101: /*
102: HTTP-header = field-name ":" [ field-value ] CRLF
103:
1.152 misha 104: field-name = token
105: field-value = *( field-content | LWS )
1.41 paf 106:
1.152 misha 107: field-content = <the OCTETs making up the field-value
1.41 paf 108: and consisting of either *TEXT or combinations
109: of token, tspecials, and quoted-string>
110:
111:
1.152 misha 112: token = 1*<any CHAR except CTLs or tspecials>
1.41 paf 113: word = token | quoted-string
1.152 misha 114: quoted-string = ( <"> *(qdtext | quoted-pair ) <"> )
115: qdtext = <any TEXT except <">>
116: quoted-pair = "\" CHAR
1.41 paf 117:
1.152 misha 118: OCTET = <any 8-bit sequence of data>
119: CHAR = <any US-ASCII character (octets 0 - 127)>
1.41 paf 120:
121: tspecials = "(" | ")" | "<" | ">" | "@"
1.152 misha 122: | "," | ";" | ":" | "\" | <">
123: | "/" | "[" | "]" | "?" | "="
124: | "{" | "}" | SP | HT
1.41 paf 125:
126: SP = <US-ASCII SP, space (32)>
127: HT = <US-ASCII HT, horizontal-tab (9)>
128:
129: LWS = [CRLF] 1*( SP | HT )
1.152 misha 130: TEXT = <any OCTET except CTLs, but including LWS>
131: CTL = <any US-ASCII control character (octets 0 - 31) and DEL (127)>
1.41 paf 132:
133:
134: if(strchr("()<>@,;:\\\"/[]?={} \t", *ptr))
135: */
1.117 paf 136: inline bool need_quote_http_header(const char* ptr, size_t size) {
1.41 paf 137: for(; size--; ptr++)
1.42 paf 138: if(strchr(";\\\"= \t" /* excluded ()<>@, :/ ? []{} */, *ptr))
1.41 paf 139: return true;
140: return false;
141: }
142:
1.119 paf 143: #ifndef DOXYGEN
144: struct Append_fragment_info {
145: String::Language lang;
146: String::Languages* dest_languages;
147: size_t dest_body_plan_length;
148: };
149: #endif
150: int append_fragment_optimizing(char alang, size_t asize, Append_fragment_info* info) {
151: const String::Language lang=(String::Language)(unsigned char)alang;
152: // main idea here:
153: // tainted piece would get OPTIMIZED bit from 'lang'
154: // clean piece would be marked OPTIMIZED manually
155: // pieces with determined languages [not tainted|clean] would retain theirs langs
156: info->dest_languages->append(info->dest_body_plan_length,
1.120 paf 157: lang==String::L_TAINTED?
1.119 paf 158: info->lang
1.120 paf 159: :lang==String::L_CLEAN?
160: (String::Language)(String::L_CLEAN|String::L_OPTIMIZE_BIT) // ORing with OPTIMIZED flag
1.119 paf 161: :lang,
162: asize);
163: info->dest_body_plan_length+=asize;
164:
165: return 0; // 0=continue
166: }
167: int append_fragment_nonoptimizing(char alang, size_t asize, Append_fragment_info* info) {
168: const String::Language lang=(String::Language)(unsigned char)alang;
169: // The core idea: tainted pieces got marked with context's lang
170: info->dest_languages->append(info->dest_body_plan_length,
1.120 paf 171: lang==String::L_TAINTED?
1.119 paf 172: info->lang
173: :lang,
174: asize);
175: info->dest_body_plan_length+=asize;
176:
177: return 0; // 0=continue
178: }
1.117 paf 179:
1.91 paf 180: /**
1.117 paf 181: appends to other String,
1.91 paf 182: marking all tainted pieces of it with @a lang.
1.92 paf 183: or marking ALL pieces of it with a @a lang when @a forced to,
184: and propagating OPTIMIZE language bit.
1.117 paf 185: */
1.147 misha 186: String& String::append_to(String& dest, Language ilang, bool forced) const {
1.117 paf 187: if(is_empty())
188: return dest;
1.91 paf 189:
1.119 paf 190: // first: fragment infos
1.117 paf 191:
1.147 misha 192: if(ilang==L_PASS_APPENDED) // without language-change?
193: dest.langs.appendHelper(dest.body, langs, body);
1.117 paf 194: else if(forced) //forcing passed lang?
1.147 misha 195: dest.langs.appendHelper(dest.body, ilang, body);
196: else {
197: if(langs.opt.is_not_just_lang){
198: Append_fragment_info info={ilang, &dest.langs, dest.body.length()};
199: langs.for_each(body, ilang&L_OPTIMIZE_BIT?
200: append_fragment_optimizing
201: :append_fragment_nonoptimizing, &info);
202: } else {
203: Language lang=langs.opt.lang;
204: // see append_fragment_* for explanation
205: if(ilang&L_OPTIMIZE_BIT){
206: dest.langs.appendHelper(dest.body,
207: lang==String::L_TAINTED?
208: ilang
209: :lang==String::L_CLEAN?
210: (String::Language)(String::L_CLEAN|String::L_OPTIMIZE_BIT)
211: :lang,
212: body);
213: } else {
214: dest.langs.appendHelper(dest.body, lang==String::L_TAINTED ? ilang:lang, body);
215: }
216: }
1.91 paf 217: }
218:
1.119 paf 219: // next: letters
220: dest.body<<body;
221:
1.117 paf 222: ASSERT_STRING_INVARIANT(dest);
1.75 paf 223: return dest;
1.51 parser 224: }
225:
1.109 paf 226: /** http://www.ietf.org/rfc/rfc2047.txt
227: RFC
228: (3) As a replacement for a 'word' entity within a 'phrase', for example,
229: one that precedes an address in a From, To, or Cc header. The ABNF
230: definition for 'phrase' from RFC 822 thus becomes:
231:
232: phrase = 1*( encoded-word / word )
233:
234: In this case the set of characters that may be used in a "Q"-encoded
235: 'encoded-word' is restricted to: <upper and lower case ASCII
236: letters, decimal digits, "!", "*", "+", "-", "/", "=", and "_"
237: (underscore, ASCII 95.)>. An 'encoded-word' that appears within a
238: 'phrase' MUST be separated from any adjacent 'word', 'text' or
239: 'special' by 'linear-white-space'.
240: ...
241: (2) The 8-bit hexadecimal value 20 (e.g., ISO-8859-1 SPACE) may be
242: represented as "_" (underscore, ASCII 95.). (This character may
243: not pass through some internetwork mail gateways, but its use
244: will greatly enhance readability of "Q" encoded data with mail
245: readers that do not support this encoding.) Note that the "_"
246: always represents hexadecimal 20, even if the SPACE character
247: occupies a different code position in the character set in use.
248:
249: paf: obviously,
250: without "=", or one could not differ "=E0" and "russian letter a"
251: and without "_", or in would mean 0x20
252: */
1.117 paf 253: inline bool mail_header_char_valid_within_Qencoded(char c) {
1.109 paf 254: return c>='A' && c<='Z'
255: || c>='a' && c<='Z'
256: || c>='0' && c<='9'
257: || strchr("!*+-/", c);
258: }
1.118 paf 259: inline bool addr_spec_soon(const char *src) {
1.124 paf 260: for(char c; (c=*src); src++)
1.118 paf 261: if(c=='<')
262: return true;
263: else if(!(c==' ' || c=='\t'))
264: return false;
265: return false;
266: }
1.117 paf 267: /**
268: RFC
269: Upper case should be used for hexadecimal digits "A" through "F"
270: The 8-bit hexadecimal value 20 (e.g., ISO-8859-1 SPACE)
271: may be represented as "_"
272: */
273: inline bool mail_header_nonspace_char(char c) {
274: return c != 0x20;
275: }
1.125 paf 276:
1.117 paf 277: inline void ec_append(CORD_ec& result, bool& optimize, bool& whitespace, CORD_pos pos, size_t size) {
278: while(size--) {
279: CORD_ec_append(result, CORD_pos_fetch(pos));
280: CORD_next(pos);
281: }
282: }
283: inline void pa_CORD_pos_advance(CORD_pos pos, size_t n) {
284: while(true) {
1.125 paf 285: long avail=CORD_pos_chars_left(pos);
286: if(avail<=0) {
1.117 paf 287: CORD_next(pos);
288: if(!--n)
289: break;
1.125 paf 290: } else if((size_t)avail<n) {
1.117 paf 291: CORD_pos_advance(pos, avail);
292: n-=avail;
293: } else { // avail>=n
294: CORD_pos_advance(pos, n);
295: break;
296: }
297: }
298: }
299:
1.119 paf 300: #ifndef DOXYGEN
301: struct Cstr_to_string_body_block_info {
302: // input
303: String::Language lang;
304: SQL_Connection* connection;
305: const Request_charsets* charsets;
306: const String::Body* body;
307:
308: // output
309: CORD_ec result;
310:
311: // private
312: CORD_pos pos;
313: size_t fragment_begin;
314: bool whitespace;
1.138 misha 315: const char* exception;
1.119 paf 316: };
317: #endif
1.151 misha 318:
319: // @todo: replace info->body->mid with something that uses info->pos
1.148 misha 320: int cstr_to_string_body_block(String::Language to_lang, size_t fragment_length, Cstr_to_string_body_block_info* info) {
1.119 paf 321: bool& whitespace=info->whitespace;
322: size_t fragment_end=info->fragment_begin+fragment_length;
1.148 misha 323: //fprintf(stderr, "%d, %d =%s=\n", to_lang, fragment_length, info->body->cstr());
1.119 paf 324:
1.120 paf 325: bool optimize=(to_lang & String::L_OPTIMIZE_BIT)!=0;
1.119 paf 326: if(!optimize)
327: whitespace=false;
328:
1.120 paf 329: switch(to_lang & ~String::L_OPTIMIZE_BIT) {
330: case String::L_CLEAN:
331: case String::L_TAINTED:
332: case String::L_AS_IS:
1.119 paf 333: // clean piece
334:
335: // tainted piece, but undefined untaint language
336: // for VString.as_double of tainted values
337: // for ^process{body} evaluation
338:
339: // tainted, untaint language: as-is
340: ec_append(info->result, optimize, whitespace, info->pos, fragment_length);
341: break;
1.120 paf 342: case String::L_FILE_SPEC:
1.119 paf 343: // tainted, untaint language: file [name]
1.140 misha 344: {
345: escape_fragment(
1.154 misha 346: encode(need_file_encode, '_', c);
1.140 misha 347: );
348: }
1.119 paf 349: break;
1.120 paf 350: case String::L_URI:
1.155 misha 351: // tainted, untaint language: uri
352: {
353: const char *fragment_str=info->body->mid(info->fragment_begin, fragment_length).cstr();
354: // skip source [we use recoded version]
355: pa_CORD_pos_advance(info->pos, fragment_length);
356: String::C output(fragment_str, fragment_length);
357: if(info->charsets)
358: output=Charset::transcode(output,
359: info->charsets->source(),
360: info->charsets->client());
361:
362: char c;
363: for(const char* src=output.str; (c=*src++); )
364: encode(need_uri_encode, '%', c);
365: }
366: break;
1.120 paf 367: case String::L_HTTP_HEADER:
1.119 paf 368: // tainted, untaint language: http-field-content-text
1.161 ! moko 369: escape_fragment(switch(c) {
! 370: case '\n':
! 371: case '\r': to_string(" "); break;
! 372: default: _default; break;
! 373: });
1.119 paf 374: break;
1.120 paf 375: case String::L_MAIL_HEADER:
1.119 paf 376: // tainted, untaint language: mail-header
377: // http://www.ietf.org/rfc/rfc2047.txt
378: if(info->charsets) {
379: size_t mail_size;
380: const char *mail_ptr=
381: info->body->mid(info->fragment_begin, mail_size=fragment_length).cstr();
382: // skip source [we use recoded version]
383: pa_CORD_pos_advance(info->pos, mail_size);
384:
385: const char* charset_name=info->charsets->mail().NAME().cstr();
386:
387: // Subject: Re: parser3: =?koi8-r?Q?=D3=C5=CD=C9=CE=C1=D2?=
388: bool to_quoted_printable=false;
389:
390: bool email=false;
391: uchar c;
1.124 paf 392: for(const char* src=mail_ptr; (c=(uchar)*src++); ) {
1.137 paf 393: if(c=='\r' || c=='\n')
394: c=' ';
1.130 paf 395: if(to_quoted_printable && (c==',' || c == '"' || addr_spec_soon(src-1/*position to 'c'*/))) {
1.119 paf 396: email=c=='<';
397: to_string("?=");
398: to_quoted_printable=false;
399: }
1.130 paf 400: //RFC + An 'encoded-word' MUST NOT appear in any portion of an 'addr-spec'.
1.119 paf 401: if(!email && (
402: !to_quoted_printable && (c & 0x80) // starting quote-printable-encoding on first 8bit char
403: || to_quoted_printable && !mail_header_char_valid_within_Qencoded(c)
404: )) {
405: if(!to_quoted_printable) {
406: to_string("=?");
407: to_string(charset_name);
408: to_string("?Q?");
409: to_quoted_printable=true;
1.105 paf 410: }
1.119 paf 411: encode(mail_header_nonspace_char, '=', '_');
412: } else
413: to_char(c);
414: if(c=='>')
415: email=false;
416: }
417: if(to_quoted_printable) // close
418: to_string("?=");
419:
420: } else
421: ec_append(info->result, optimize, whitespace, info->pos, fragment_length);
422: break;
1.120 paf 423: case String::L_SQL:
1.119 paf 424: // tainted, untaint language: sql
425: if(info->connection) {
426: const char *fragment_str=info->body->mid(info->fragment_begin, fragment_length).cstr();
427: // skip source [we use recoded version]
428: pa_CORD_pos_advance(info->pos, fragment_length);
429:
430: to_string(info->connection->quote(fragment_str, fragment_length));
1.138 misha 431: } else {
432: info->exception="untaint in SQL language failed - no connection specified";
433: info->fragment_begin=fragment_end;
434: return 1; // stop processing. can't throw exception here
435: }
1.119 paf 436: break;
1.120 paf 437: case String::L_JS:
1.140 misha 438: escape_fragment(switch(c) {
439: case '\n': to_string("\\n"); break;
1.119 paf 440: case '"': to_string("\\\""); break;
441: case '\'': to_string("\\'"); break;
442: case '\\': to_string("\\\\"); break;
443: case '\xFF': to_string("\\\xFF"); break;
1.146 misha 444: case '\r': to_string("\\r"); break;
1.133 paf 445: default: _default; break;
1.119 paf 446: });
447: break;
1.120 paf 448: case String::L_XML:
1.133 paf 449: // [2] Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
1.140 misha 450: escape_fragment(switch(c) {
451: case '\x20':
452: case '\x9':
453: case '\xA':
1.133 paf 454: case '\xD': // this is usually removed on input
455: _default;
456: break;
1.119 paf 457: case '&': to_string("&"); break;
458: case '>': to_string(">"); break;
459: case '<': to_string("<"); break;
460: case '"': to_string("""); break;
461: case '\'': to_string("'"); break;
1.133 paf 462: default:
463: if(((unsigned char)c)<0x20) {
464: // fixing it, so that libxml would not result
465: // in fatal error parsing text
466: // though it really violates standard.
467: // to indicate there were an error
468: // replace bad char not to it's code,
469: // which we can do,
470: // but rather to '!' to show that input were actually
471: // invalid.
472: // life: shows that MSIE can somehow garble form values
473: // so that they contain these chars.
474: to_char('!');
475: } else {
476: _default;
477: }
478: break;
1.119 paf 479: });
480: break;
1.120 paf 481: case String::L_HTML:
1.140 misha 482: escape_fragment(switch(c) {
1.119 paf 483: case '&': to_string("&"); break;
484: case '>': to_string(">"); break;
485: case '<': to_string("<"); break;
486: case '"': to_string("""); break;
1.133 paf 487: default: _default; break;
1.119 paf 488: });
489: break;
1.136 paf 490: case String::L_REGEX:
491: // tainted, untaint language: regex
1.140 misha 492: escape_fragment(
1.136 paf 493: if(need_regex_escape(c))
494: to_char('\\')
495: _default;
496: );
497: break;
1.156 misha 498: case String::L_JSON:
499: // tainted, untaint language: json <http://json.org/>
500: // escape '"' '\' '/' '\n' '\t' '\r' '\b' '\f' chars and escape chars as \uXXXX if output charset != UTF-8
501: {
1.159 moko 502: if(info->charsets==NULL || info->charsets->client().isUTF8()){
1.156 misha 503: // escaping to \uXXXX is not needed
504: escape_fragment(switch(c) {
505: case '\n': to_string("\\n"); break;
506: case '"' : to_string("\\\""); break;
507: case '\\': to_string("\\\\"); break;
508: case '/' : to_string("\\/"); break;
509: case '\t': to_string("\\t"); break;
510: case '\r': to_string("\\r"); break;
511: case '\b': to_string("\\b"); break;
512: case '\f': to_string("\\f"); break;
513: default : _default; break;
514: });
515: } else {
516: const char *fragment_str=info->body->mid(info->fragment_begin, fragment_length).cstr();
517: // skip source [we use recoded version]
518: pa_CORD_pos_advance(info->pos, fragment_length);
519: String::C output(fragment_str, fragment_length);
520:
521: output=Charset::escape_JSON(output, info->charsets->source());
522: to_string(output);
523: }
524: }
525: break;
1.140 misha 526: case String::L_HTTP_COOKIE:
527: // tainted, untaint language: cookie (3.3.0 and higher: %uXXXX in UTF-8)
1.159 moko 528: if(info->charsets) {
1.140 misha 529: const char *fragment_str=info->body->mid(info->fragment_begin, fragment_length).cstr();
530: // skip source [we use recoded version]
531: pa_CORD_pos_advance(info->pos, fragment_length);
532: String::C output(fragment_str, fragment_length);
533:
1.155 misha 534: output=Charset::escape(output, info->charsets->source());
1.140 misha 535: to_string(output);
1.159 moko 536: } else
537: ec_append(info->result, optimize, whitespace, info->pos, fragment_length);
1.140 misha 538: break;
1.150 misha 539: case String::L_PARSER_CODE:
540: // for auto-untaint in process
541: escape_fragment(
542: if(need_parser_code_escape(c))
543: to_char('^');
544: _default;
545: );
546: break;
1.119 paf 547: default:
1.127 paf 548: SAPI::abort("unknown untaint language #%d",
1.119 paf 549: static_cast<int>(to_lang)); // should never
550: break; // never
1.117 paf 551: }
1.55 parser 552:
1.119 paf 553: info->fragment_begin=fragment_end;
554:
555: return 0; // 0=continue
556: }
557:
558:
1.148 misha 559: String::Body String::cstr_to_string_body_taint(Language lang, SQL_Connection* connection, const Request_charsets *charsets) const {
1.134 paf 560: if(is_empty())
561: return String::Body();
1.119 paf 562:
563: Cstr_to_string_body_block_info info;
564: // input
565: info.lang=lang;
566: info.connection=connection;
567: info.charsets=charsets;
568: info.body=&body;
569: // output
570: CORD_ec_init(info.result);
571: // private
572: body.set_pos(info.pos, 0);
573: info.fragment_begin=0;
1.138 misha 574: info.exception=0;
1.119 paf 575: info.whitespace=true;
576:
1.148 misha 577: cstr_to_string_body_block(lang, length(), &info);
578:
579: if(info.exception)
580: throw Exception(0,
581: 0,
582: info.exception);
583:
1.160 moko 584: return String::Body(CORD_ec_to_cord(info.result));
1.148 misha 585: }
586:
587: int cstr_to_string_body_block_untaint(char alang, size_t fragment_length, Cstr_to_string_body_block_info* info){
588: const String::Language lang=(String::Language)(unsigned char)alang;
589: // see append_fragment_* for explanation
590: if(info->lang&String::L_OPTIMIZE_BIT)
591: return cstr_to_string_body_block(
592: lang==String::L_TAINTED?
593: info->lang
594: :lang==String::L_CLEAN?
595: (String::Language)(String::L_CLEAN|String::L_OPTIMIZE_BIT)
596: :lang,
597: fragment_length, info);
598: else
599: return cstr_to_string_body_block(lang==String::L_TAINTED ? info->lang:lang, fragment_length, info);
600: }
601:
602: String::Body String::cstr_to_string_body_untaint(Language lang, SQL_Connection* connection, const Request_charsets *charsets) const {
603: if(is_empty())
604: return String::Body();
605:
606: Cstr_to_string_body_block_info info;
607: // input
608: info.lang=lang;
609: info.connection=connection;
610: info.charsets=charsets;
611: info.body=&body;
612: // output
613: CORD_ec_init(info.result);
614: // private
615: body.set_pos(info.pos, 0);
616: info.fragment_begin=0;
617: info.exception=0;
618: info.whitespace=true;
619:
620: langs.for_each(body, cstr_to_string_body_block_untaint, &info);
1.151 misha 621:
622: if(info.exception)
623: throw Exception(0,
624: 0,
625: info.exception);
626:
1.160 moko 627: return String::Body(CORD_ec_to_cord(info.result));
1.151 misha 628: }
629:
1.155 misha 630: const char* String::untaint_and_transcode_cstr(Language lang, const Request_charsets *charsets) const {
1.151 misha 631: if(charsets && &charsets->source() != &charsets->client()){
1.155 misha 632: // Note: L_URI is allready transcoded during untaint, but transcode does not affect %XX
633: return Charset::transcode(cstr_to_string_body_untaint(lang, 0, charsets), charsets->source(), charsets->client()).cstr();
634: } else
1.151 misha 635: return cstr_to_string_body_untaint(lang, 0, charsets).cstr();
1.1 paf 636: }
E-mail: