--- parser3/src/include/pa_string.h 2001/07/07 17:59:02 1.97 +++ parser3/src/include/pa_string.h 2001/11/05 11:46:25 1.115 @@ -2,10 +2,9 @@ Parser: string class decl. Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) + Author: Alexander Petrosyan (http://paf.design.ru) - Author: Alexander Petrosyan (http://design.ru/paf) - - $Id: pa_string.h,v 1.97 2001/07/07 17:59:02 parser Exp $ + $Id: pa_string.h,v 1.115 2001/11/05 11:46:25 paf Exp $ */ #ifndef PA_STRING_H @@ -57,6 +56,7 @@ class Table; class Array; class SQL_Connection; +class Dictionary; /** Pooled string. @@ -78,6 +78,7 @@ class SQL_Connection; - whether they are tainted or not, and the language which should be used to detaint them */ +#include "pa_pragma_pack_begin.h" class String : public Pooled { public: @@ -86,7 +87,9 @@ public: CR_GROW_COUNT=2 ///< each time the String chunk_is_full() string expanded() }; - /// piece is tainted or not. the language to use when detaint + /** piece is tainted or not. the language to use when detaint + remember to change String_Untaint_lang_name @ untaint.C along + */ enum Untaint_lang { UL_UNSPECIFIED=0, ///< zero value handy for hash lookup @see untaint_lang_name2enum UL_CLEAN, ///< clean @@ -98,13 +101,14 @@ public: just a flag, that value not stored */ UL_AS_IS, ///< leave all characters intact - UL_FILE_NAME, ///< filename + UL_FILE_SPEC, ///< file specification UL_HTTP_HEADER, ///< text in HTTP response header UL_MAIL_HEADER, ///< text in mail header UL_URI, ///< text in uri UL_TABLE, ///< ^table:set body UL_SQL, ///< ^table:sql body UL_JS, ///< JavaScript code + UL_XML, ///< ^dom:set xml UL_HTML, ///< HTML code (for editing) UL_USER_HTML ///< HTML code with USER chars }; @@ -114,8 +118,10 @@ public: String(Pool& apool, const char *src=0, size_t src_size=0, bool tainted=false); String(const String& src); size_t size() const { return fsize; } + /// makes store_to produce origin:text\n output + void set_origins_mode(bool aorigins_mode) const { forigins_mode=aorigins_mode; } /// convert to C string. if 'lang' known, forcing 'lang' to it - char *cstr(Untaint_lang lang=UL_UNSPECIFIED, + char *cstr(Untaint_lang lang=UL_AS_IS, SQL_Connection *connection=0, const char *charset=0) const { @@ -124,6 +130,10 @@ public: *eol=0; return result; } + /// puts pieces to buf + void serialize(size_t prolog_size, void *& buf, size_t& buf_size) const; + /// appends pieces from buf to self + void deserialize(size_t prolog_size, void *buf, size_t buf_size, const char *file); /** append fragment @see APPEND_AS_IS, APPEND_CLEAN, APPEND_TAINTED, APPEND_CONST */ @@ -164,7 +174,6 @@ public: return cmp(partial, src_ptr, 0)!=0; } - /** appends other String. @@ -178,15 +187,18 @@ public: /// simple hash code of string. used by Hash uint hash_code() const; + /// extracts first char of a string + char first_char() const; + /// extracts [start, finish) piece of string String& mid(size_t start, size_t finish) const; /// @return position of substr in string, -1 means "not found" [String version] int pos(const String& substr, - size_t this_offset=0, Untaint_lang lang=UL_UNSPECIFIED) const; + int this_offset=0, Untaint_lang lang=UL_UNSPECIFIED) const; /// @return position of substr in string, -1 means "not found" [const char* version] int pos(const char *substr, size_t substr_size=0, - size_t this_offset=0, Untaint_lang lang=UL_UNSPECIFIED) const; + int this_offset=0, Untaint_lang lang=UL_UNSPECIFIED) const; void split(Array& result, size_t *pos_after_ref, @@ -211,13 +223,15 @@ public: const String& regexp, const String *options, Table **table, - Row_action row_action, void *info) const; + Row_action row_action, void *info, + bool *was_global=0) const; enum Change_case_kind { CC_UPPER, CC_LOWER }; String& change_case(Pool& pool, const unsigned char *pcre_tables, Change_case_kind kind) const; + String& replace(Pool& pool, Dictionary& dict) const; double as_double() const; int as_int() const; @@ -230,14 +244,14 @@ private: /// several String fragments struct Chunk { - size_t count; ///< the number of rows in chunk + uint count; ///< the number of rows in chunk /// string fragment or a link to next chunk union union Row { /// fragment struct { const char *ptr; ///< pointer to the start size_t size; ///< length - Untaint_lang lang; ///< untaint flag, later untaint language + unsigned char/*Untaint_lang*/ lang; ///< untaint flag, later untaint language #ifndef NO_STRING_ORIGIN Origin origin; ///< origin #endif @@ -257,20 +271,21 @@ private: Chunk::Row *link_row; private: - // last chunk + /// last chunk Chunk *last_chunk; - // string size + /// string size size_t fsize; - // used rows in all chunks - int fused_rows; + /// origins_mode changes behaviour of store_to[cstr()] + mutable bool forigins_mode; private: bool chunk_is_full() { return append_here == link_row; } + uint used_rows() const; void expand(); size_t cstr_bufsize(Untaint_lang lang) const; @@ -279,10 +294,17 @@ private: SQL_Connection *connection=0, const char *charset=0) const; + String& reconstruct(Pool& pool) const; + void join_chain(Pool& pool, + uint& ai, const Chunk*& achunk, const Chunk::Row*& arow, + Untaint_lang& joined_lang, const char *& joined_ptr, size_t& joined_size) const; + String& replace_in_reconstructed(Pool& pool, Dictionary& dict) const; + private: //disabled String& operator = (const String&) { return *this; } }; +#include "pa_pragma_pack_end.h" #endif