extern "C++" { namespace std { class exception { public: exception() throw() { } virtual ~exception() throw(); virtual const char* what() const throw(); }; } } typedef unsigned int size_t; extern "C" { extern void *memcpy (void *__restrict __dest, __const void *__restrict __src, size_t __n) throw () __attribute__ ((__nonnull__ (1, 2))); } typedef unsigned char UCHAR; typedef unsigned short USHORT; typedef char TEXT; namespace Firebird { class status_exception : public std::exception { }; class fatal_exception : public status_exception { public: explicit fatal_exception(const char* message); static void raiseFmt(const char* format, ...); }; typedef struct _IO_FILE FILE; typedef unsigned int wint_t; typedef struct { union { wint_t __wch; char __wchb[4]; } __value; } __mbstate_t; typedef struct { } _IO_cookie_io_functions_t; extern struct _IO_FILE *stderr; extern int fprintf (FILE *__restrict __stream, __const char *__restrict __format, ...); extern void abort (void) throw () __attribute__ ((__noreturn__)); void gds__log(const TEXT*, ...); struct FreeMemoryBlock { }; struct MemoryBlock { union { class MemoryPool* mbk_pool; FreeMemoryBlock* mbk_prev_fragment; }; }; } namespace Firebird { class PermanentStorage { private: MemoryPool& pool; protected: explicit PermanentStorage(MemoryPool& p) : pool(p) { } }; class AutoStorage : public PermanentStorage { private: void ProbeStack() const; public: static MemoryPool& getAutoMemoryPool(); protected: AutoStorage() : PermanentStorage(getAutoMemoryPool()) { ProbeStack(); } }; class AbstractString : private AutoStorage { public: typedef char char_type; typedef size_t size_type; typedef char* pointer; typedef const char* const_pointer; enum {INLINE_BUFFER_SIZE = 32, INIT_RESERVE = 16 }; protected: typedef USHORT internal_size_type; char_type inlineBuffer[INLINE_BUFFER_SIZE]; char_type* stringBuffer; internal_size_type stringLength, bufferSize; inline AbstractString() : stringBuffer(inlineBuffer), stringLength(0), bufferSize(INLINE_BUFFER_SIZE) { stringBuffer[0] = 0; } AbstractString(size_type sizeL, char_type c); pointer baseAppend(size_type n); public: inline const_pointer c_str() const { return stringBuffer; } inline size_type length() const { return stringLength; } void printf(const char* Format, ...); }; class StringComparator { }; template class StringBase : public AbstractString { typedef StringBase StringType; public: inline StringBase() : AbstractString() {} inline StringBase(char_type c) : AbstractString(1, c) {} inline StringType& append(const StringType& str) { {if (!(&str != this)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/fb_string.h", 416); abort();}}; return append(str.c_str(), str.length()); } inline StringType& append(const_pointer s, size_type n) { memcpy(baseAppend(n), s, n); return *this; } inline StringType& operator+=(const StringType& v) { {if (!(&v != this)) {fprintf (stderr, "GDS Assertion failure: %s %""d""\n", "../src/include/../common/classes/fb_string.h", 474); abort();}}; return append(v); } }; typedef StringBase string; class ClumpletReader : protected AutoStorage { public: enum Kind {Tagged, UnTagged, SpbAttach, SpbStart, Tpb }; ClumpletReader(Kind k, const UCHAR* buffer, size_t buffLen); bool isEof() const { return cur_offset >= getBufferLength(); } void moveNext(); void rewind(); UCHAR getClumpTag() const; size_t getClumpLength() const; const UCHAR* getBytes() const; UCHAR getBufferTag() const; size_t getBufferLength() const { size_t rc = getBufferEnd() - getBuffer(); if (rc == 1 && kind != UnTagged && kind != SpbStart) { rc = 0; } return rc; } size_t getCurOffset() const { return cur_offset; } void dump() const; size_t cur_offset; const Kind kind; virtual const UCHAR* getBuffer() const { return static_buffer; } virtual const UCHAR* getBufferEnd() const { return static_buffer_end; } const UCHAR* static_buffer; const UCHAR* static_buffer_end; }; extern int isprint (int) throw (); void ClumpletReader::dump() const { class ClumpletDump : public ClumpletReader { public: ClumpletDump(Kind k, const UCHAR* buffer, size_t buffLen) : ClumpletReader(k, buffer, buffLen) { } static string hexString(const UCHAR* b, size_t len) { string t1, t2; for (; len > 0; --len, ++b) { if (isprint(*b)) t2 += *b; else { t1.printf("<%02x>", *b); t2 += t1; } } return t2; } protected: virtual void usage_mistake(const char* what) const { fatal_exception::raiseFmt( "Internal error when using clumplet API: %s", what); } virtual void invalid_structure(const char* what) const { fatal_exception::raiseFmt( "Invalid clumplet buffer structure: %s", what); } }; try { ClumpletDump d(kind, getBuffer(), getBufferLength()); int t = (kind == SpbStart || kind == UnTagged) ? -1 : d.getBufferTag(); gds__log("Tag=%d Offset=%d Length=%d Eof=%d\n", t, getCurOffset(), getBufferLength(), isEof()); for (d.rewind(); !(d.isEof()); d.moveNext()) { gds__log("Clump %d at offset %d: %s", d.getClumpTag(), d.getCurOffset(), ClumpletDump::hexString(d.getBytes(), d.getClumpLength()).c_str()); } } catch(const fatal_exception& x) { gds__log("Fatal exception during clumplet dump: %s", x.what()); size_t l = getBufferLength() - getCurOffset(); const UCHAR *p = getBuffer() + getCurOffset(); gds__log("Plain dump starting with offset %d: %s", getCurOffset(), ClumpletDump::hexString(p, l).c_str()); } } }