]>
Commit | Line | Data |
---|---|---|
45516216 | 1 | extern "C++" { |
2 | namespace std { | |
3 | class exception { public: exception() throw() { } virtual ~exception() throw(); virtual const char* what() const throw(); }; | |
4 | } | |
5 | } | |
6 | typedef unsigned int size_t; | |
7 | extern "C" { | |
8 | extern void *memcpy (void *__restrict __dest, __const void *__restrict __src, size_t __n) throw () __attribute__ ((__nonnull__ (1, 2))); | |
9 | } | |
10 | typedef unsigned char UCHAR; | |
11 | typedef unsigned short USHORT; | |
12 | typedef char TEXT; | |
13 | namespace Firebird { | |
14 | class status_exception : public std::exception { | |
15 | }; | |
16 | class fatal_exception : public status_exception { | |
17 | public: explicit fatal_exception(const char* message); | |
18 | static void raiseFmt(const char* format, ...); | |
19 | }; | |
20 | typedef struct _IO_FILE FILE; | |
21 | typedef unsigned int wint_t; | |
22 | typedef struct { | |
23 | union { wint_t __wch; char __wchb[4]; } | |
24 | __value; | |
25 | } | |
26 | __mbstate_t; | |
27 | typedef struct { | |
28 | } | |
29 | _IO_cookie_io_functions_t; | |
30 | extern struct _IO_FILE *stderr; | |
31 | extern int fprintf (FILE *__restrict __stream, __const char *__restrict __format, ...); | |
32 | extern void abort (void) throw () __attribute__ ((__noreturn__)); | |
33 | void gds__log(const TEXT*, ...); | |
34 | struct FreeMemoryBlock { | |
35 | }; | |
36 | struct MemoryBlock { | |
37 | union { class MemoryPool* mbk_pool; FreeMemoryBlock* mbk_prev_fragment; }; | |
38 | }; | |
39 | } | |
40 | namespace Firebird { | |
41 | class PermanentStorage { | |
42 | private: MemoryPool& pool; | |
43 | protected: explicit PermanentStorage(MemoryPool& p) : pool(p) { } | |
44 | }; | |
45 | class AutoStorage : public PermanentStorage { | |
46 | private: void ProbeStack() const; | |
47 | public: static MemoryPool& getAutoMemoryPool(); | |
48 | protected: AutoStorage() : PermanentStorage(getAutoMemoryPool()) { ProbeStack(); } | |
49 | }; | |
50 | class AbstractString : private AutoStorage { | |
51 | public: typedef char char_type; | |
52 | typedef size_t size_type; | |
53 | typedef char* pointer; | |
54 | typedef const char* const_pointer; | |
55 | enum {INLINE_BUFFER_SIZE = 32, INIT_RESERVE = 16 }; | |
56 | protected: typedef USHORT internal_size_type; | |
57 | char_type inlineBuffer[INLINE_BUFFER_SIZE]; | |
58 | char_type* stringBuffer; | |
59 | internal_size_type stringLength, bufferSize; | |
60 | inline AbstractString() : stringBuffer(inlineBuffer), stringLength(0), bufferSize(INLINE_BUFFER_SIZE) { stringBuffer[0] = 0; } | |
61 | AbstractString(size_type sizeL, char_type c); | |
62 | pointer baseAppend(size_type n); | |
63 | public: inline const_pointer c_str() const { return stringBuffer; } | |
64 | inline size_type length() const { return stringLength; } | |
65 | void printf(const char* Format, ...); | |
66 | }; | |
67 | class StringComparator { | |
68 | }; | |
69 | template<typename Comparator> class StringBase : public AbstractString { | |
70 | typedef StringBase<Comparator> StringType; | |
71 | public: inline StringBase<Comparator>() : AbstractString() {} | |
72 | inline StringBase<Comparator>(char_type c) : AbstractString(1, c) {} | |
73 | 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()); } | |
74 | inline StringType& append(const_pointer s, size_type n) { memcpy(baseAppend(n), s, n); return *this; } | |
75 | 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); } | |
76 | }; | |
77 | typedef StringBase<StringComparator> string; | |
78 | class ClumpletReader : protected AutoStorage { | |
79 | public: enum Kind {Tagged, UnTagged, SpbAttach, SpbStart, Tpb }; | |
80 | ClumpletReader(Kind k, const UCHAR* buffer, size_t buffLen); | |
81 | bool isEof() const { return cur_offset >= getBufferLength(); } | |
82 | void moveNext(); | |
83 | void rewind(); | |
84 | UCHAR getClumpTag() const; | |
85 | size_t getClumpLength() const; | |
86 | const UCHAR* getBytes() const; | |
87 | UCHAR getBufferTag() const; | |
88 | size_t getBufferLength() const { size_t rc = getBufferEnd() - getBuffer(); if (rc == 1 && kind != UnTagged && kind != SpbStart) { rc = 0; } return rc; } | |
89 | size_t getCurOffset() const { return cur_offset; } | |
90 | void dump() const; | |
91 | size_t cur_offset; | |
92 | const Kind kind; | |
93 | virtual const UCHAR* getBuffer() const { return static_buffer; } | |
94 | virtual const UCHAR* getBufferEnd() const { return static_buffer_end; } | |
95 | const UCHAR* static_buffer; | |
96 | const UCHAR* static_buffer_end; | |
97 | }; | |
98 | extern int isprint (int) throw (); | |
99 | void ClumpletReader::dump() const { | |
100 | 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); } }; | |
101 | 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()); } } | |
102 | 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()); } | |
103 | } | |
104 | } |