--- parser3/src/include/pa_string.h 2009/06/23 10:05:09 1.188 +++ parser3/src/include/pa_string.h 2009/07/14 23:32:07 1.193 @@ -8,7 +8,7 @@ #ifndef PA_STRING_H #define PA_STRING_H -static const char * const IDENT_STRING_H="$Date: 2009/06/23 10:05:09 $"; +static const char * const IDENT_STRING_H="$Date: 2009/07/14 23:32:07 $"; // 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 }; @@ -409,7 +410,14 @@ public: } char fetch(size_t index) const { return CORD_fetch(body, index); } - Body mid(size_t index, size_t length) const { return CORD_substr(body, index, length); } + Body mid(size_t aindex, size_t alength) const { + if(alength==0) return 0; + size_t self_length=length(); + if(aindex>self_length) return 0; + if(aindex+alength>self_length) alength=self_length-aindex; + + return CORD_substr_checked(body, aindex, alength); + } size_t pos(const char* substr, size_t offset=0) const { return CORD_str(body, offset, substr); } size_t pos(const Body substr, size_t offset=0) const { if(substr.is_empty()) @@ -513,22 +521,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 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(); } - /// 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(); + 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;