--- parser3/src/include/pa_string.h 2009/06/20 00:45:46 1.187 +++ parser3/src/include/pa_string.h 2009/07/07 12:13:28 1.192 @@ -8,7 +8,7 @@ #ifndef PA_STRING_H #define PA_STRING_H -static const char * const IDENT_STRING_H="$Date: 2009/06/20 00:45:46 $"; +static const char * const IDENT_STRING_H="$Date: 2009/07/07 12:13:28 $"; // includes #include "pa_types.h" @@ -100,14 +100,15 @@ public: L_FILE_SPEC='F', ///< file specification L_HTTP_HEADER='h', ///< text in HTTP response header L_MAIL_HEADER='m', ///< text in mail header - L_URI='U', ///< text in uri - L_SQL='Q', ///< ^table:sql body - L_JS='J', ///< JavaScript code - L_XML='X', ///< ^dom:set xml - L_HTML='H', ///< HTML code - L_REGEX='R', ///< RegEx expression + L_URI='U', ///< text in uri + L_SQL='Q', ///< ^table:sql body + L_JS='J', ///< JavaScript code + L_XML='X', ///< ^dom:set xml + L_HTML='H', ///< HTML code + L_REGEX='R', ///< RegEx expression L_HTTP_COOKIE='C', ///< cookies encoded as %uXXXX for compartibility with js functions encode/decode - L_FILE_POST='f', ///temporary escaping zero-char + L_FILE_POST='f', ///< temporary escaping zero-char + L_PARSER_CODE='p', ///< ^process body // READ WARNING ABOVE BEFORE ADDING ANYTHING L_OPTIMIZE_BIT = 0x80 ///< flag, requiring cstr whitespace optimization }; @@ -444,7 +445,7 @@ public: /// @returns this or 0 or mid. if returns this or 0 out_* are not filled Body trim(Trim_kind kind=TRIM_BOTH, const char* chars=0, - size_t* out_start=0, size_t* out_length=0) const; + size_t* out_start=0, size_t* out_length=0, Charset* source_charset=0) const; }; struct C { @@ -513,22 +514,34 @@ public: size_t length() const { return body.length(); } size_t length(Charset& charset) const; - /// convert to CORD. if 'lang' known, forcing 'lang' to it - Body cstr_to_string_body(Language lang=L_AS_IS, - SQL_Connection* connection=0, - const Request_charsets *charsets=0) const; - - /// convert to constant C string. if 'lang' known, forcing 'lang' to it - const char* cstr(Language lang=L_AS_IS, - SQL_Connection* connection=0, - const Request_charsets *charsets=0) const { - return cstr_to_string_body(lang, connection, charsets).cstr(); - } - /// convert to Modifiable C string. if 'lang' known, forcing 'lang' to it - char *cstrm(Language lang=L_AS_IS, - SQL_Connection* connection=0, - const Request_charsets *charsets=0) const { - return cstr_to_string_body(lang, connection, charsets).cstrm(); + /// convert to CORD forcing lang tainting + Body cstr_to_string_body_taint(Language lang, SQL_Connection* connection=0, const Request_charsets *charsets=0) const; + /// convert to CORD with tainting dirty to lang + Body cstr_to_string_body_untaint(Language lang, SQL_Connection* connection=0, const Request_charsets *charsets=0) const; + + /// + const char* cstr() const { + return body.cstr(); + } + /// + char* cstrm() const { + return body.cstrm(); + } + + /// convert to constant C string forcing lang tainting + const char* taint_cstr(Language lang, SQL_Connection* connection=0, const Request_charsets *charsets=0) const { + return cstr_to_string_body_taint(lang, connection, charsets).cstr(); + } + char *taint_cstrm(Language lang, SQL_Connection* connection=0, const Request_charsets *charsets=0) const { + return cstr_to_string_body_taint(lang, connection, charsets).cstrm(); + } + + /// convert to constant C string with tainting dirty to lang + const char* untaint_cstr(Language lang, SQL_Connection* connection=0, const Request_charsets *charsets=0) const { + return cstr_to_string_body_untaint(lang, connection, charsets).cstr(); + } + char *untaint_cstrm(Language lang, SQL_Connection* connection=0, const Request_charsets *charsets=0) const { + return cstr_to_string_body_untaint(lang, connection, charsets).cstrm(); } /// puts pieces to buf Cm serialize(size_t prolog_size) const; @@ -628,7 +641,7 @@ public: String& change_case(Charset& source_charset, Change_case_kind kind) const; const String& replace(const Dictionary& dict) const; - const String& trim(Trim_kind kind=TRIM_BOTH, const char* chars=0) const; + const String& trim(Trim_kind kind=TRIM_BOTH, const char* chars=0, Charset* source_charset=0) const; double as_double() const { return pa_atod(cstr(), this); } int as_int() const { return pa_atoi(cstr(), this); } bool as_bool() const { return as_int()!=0; }