diff options
Diffstat (limited to 'src/experimental')
26 files changed, 2679 insertions, 2679 deletions
diff --git a/src/experimental/blowfish.h b/src/experimental/blowfish.h index 0308026..b287bd4 100644 --- a/src/experimental/blowfish.h +++ b/src/experimental/blowfish.h | |||
@@ -23,454 +23,454 @@ | |||
23 | #define MAX_STRING 256 | 23 | #define MAX_STRING 256 |
24 | #define MAX_PASSWD 56 // 448bits | 24 | #define MAX_PASSWD 56 // 448bits |
25 | #define F(x) \ | 25 | #define F(x) \ |
26 | (((SB[0][x.byte.zero] + SB[1][x.byte.one]) ^ SB[2][x.byte.two]) + \ | 26 | (((SB[0][x.byte.zero] + SB[1][x.byte.one]) ^ SB[2][x.byte.two]) + \ |
27 | SB[3][x.byte.three]) | 27 | SB[3][x.byte.three]) |
28 | #define revBytes( x ) x = (((x&0xff)<<24)|((x&0xff00)<<8)|((x&0xff0000)>>8)|((x&0xff000000)>>24)) | 28 | #define revBytes( x ) x = (((x&0xff)<<24)|((x&0xff00)<<8)|((x&0xff0000)>>8)|((x&0xff000000)>>24)) |
29 | 29 | ||
30 | namespace Bu | 30 | namespace Bu |
31 | { | 31 | { |
32 | template<int Mode> | 32 | template<int Mode> |
33 | class Blowfish : public Bu::Cipher<8> | 33 | class Blowfish : public Bu::Cipher<8> |
34 | { | 34 | { |
35 | public: | 35 | public: |
36 | Blowfish( Bu::Stream &rNext ) : | 36 | Blowfish( Bu::Stream &rNext ) : |
37 | Bu::Cipher<8>( rNext ) | 37 | Bu::Cipher<8>( rNext ) |
38 | { | 38 | { |
39 | } | 39 | } |
40 | 40 | ||
41 | virtual ~Blowfish() | 41 | virtual ~Blowfish() |
42 | { | 42 | { |
43 | stop(); | 43 | stop(); |
44 | reset(); | 44 | reset(); |
45 | } | 45 | } |
46 | 46 | ||
47 | void setPassword( const Bu::String &sPass ) | 47 | void setPassword( const Bu::String &sPass ) |
48 | { | 48 | { |
49 | reset(); | 49 | reset(); |
50 | 50 | ||
51 | uint32_t i,j,len=sPass.getSize(); | 51 | uint32_t i,j,len=sPass.getSize(); |
52 | Word Work,null0,null1; | 52 | Word Work,null0,null1; |
53 | 53 | ||
54 | if (len > 0) | 54 | if (len > 0) |
55 | { | 55 | { |
56 | j = 0; | 56 | j = 0; |
57 | for (i=0;i<NUM_SUBKEYS;i++) | 57 | for (i=0;i<NUM_SUBKEYS;i++) |
58 | { | 58 | { |
59 | Work.byte.zero = sPass[(j++)%len]; | 59 | Work.byte.zero = sPass[(j++)%len]; |
60 | Work.byte.one = sPass[(j++)%len]; | 60 | Work.byte.one = sPass[(j++)%len]; |
61 | Work.byte.two = sPass[(j++)%len]; | 61 | Work.byte.two = sPass[(j++)%len]; |
62 | Work.byte.three = sPass[(j++)%len]; | 62 | Work.byte.three = sPass[(j++)%len]; |
63 | PA[i] ^= Work.word; | 63 | PA[i] ^= Work.word; |
64 | } | 64 | } |
65 | 65 | ||
66 | null0.word = null1.word = 0; | 66 | null0.word = null1.word = 0; |
67 | 67 | ||
68 | for (i=0;i<NUM_SUBKEYS;i+=2) | 68 | for (i=0;i<NUM_SUBKEYS;i+=2) |
69 | { | 69 | { |
70 | keyEncipher( null0, null1 ); | 70 | keyEncipher( null0, null1 ); |
71 | PA[i] = null0.word; | 71 | PA[i] = null0.word; |
72 | PA[i+1] = null1.word; | 72 | PA[i+1] = null1.word; |
73 | } | 73 | } |
74 | 74 | ||
75 | for (j=0;j<NUM_S_BOXES;j++) | 75 | for (j=0;j<NUM_S_BOXES;j++) |
76 | for (i=0;i<NUM_ENTRIES;i+=2) | 76 | for (i=0;i<NUM_ENTRIES;i+=2) |
77 | { | 77 | { |
78 | keyEncipher( null0, null1 ); | 78 | keyEncipher( null0, null1 ); |
79 | SB[j][i] = null0.word; | 79 | SB[j][i] = null0.word; |
80 | SB[j][i+1] = null1.word; | 80 | SB[j][i+1] = null1.word; |
81 | } | 81 | } |
82 | } | 82 | } |
83 | 83 | ||
84 | Work.word = null0.word = null1.word = 0; | 84 | Work.word = null0.word = null1.word = 0; |
85 | len = 0; | 85 | len = 0; |
86 | } | 86 | } |
87 | 87 | ||
88 | private: | 88 | private: |
89 | uint32_t PA[NUM_SUBKEYS]; | 89 | uint32_t PA[NUM_SUBKEYS]; |
90 | uint32_t SB[NUM_S_BOXES][NUM_ENTRIES]; | 90 | uint32_t SB[NUM_S_BOXES][NUM_ENTRIES]; |
91 | 91 | ||
92 | #if __BYTE_ORDER == __BIG_ENDIAN | 92 | #if __BYTE_ORDER == __BIG_ENDIAN |
93 | struct WordByte | 93 | struct WordByte |
94 | { | 94 | { |
95 | uint32_t zero:8; | 95 | uint32_t zero:8; |
96 | uint32_t one:8; | 96 | uint32_t one:8; |
97 | uint32_t two:8; | 97 | uint32_t two:8; |
98 | uint32_t three:8; | 98 | uint32_t three:8; |
99 | }; | 99 | }; |
100 | #elif __BYTE_ORDER == __LITTLE_ENDIAN | 100 | #elif __BYTE_ORDER == __LITTLE_ENDIAN |
101 | struct WordByte | 101 | struct WordByte |
102 | { | 102 | { |
103 | uint32_t three:8; | 103 | uint32_t three:8; |
104 | uint32_t two:8; | 104 | uint32_t two:8; |
105 | uint32_t one:8; | 105 | uint32_t one:8; |
106 | uint32_t zero:8; | 106 | uint32_t zero:8; |
107 | }; | 107 | }; |
108 | #else | 108 | #else |
109 | #error No endianness defined | 109 | #error No endianness defined |
110 | #endif | 110 | #endif |
111 | 111 | ||
112 | union Word | 112 | union Word |
113 | { | 113 | { |
114 | uint32_t word; | 114 | uint32_t word; |
115 | WordByte byte; | 115 | WordByte byte; |
116 | }; | 116 | }; |
117 | 117 | ||
118 | struct DWord | 118 | struct DWord |
119 | { | 119 | { |
120 | Word word0; | 120 | Word word0; |
121 | Word word1; | 121 | Word word1; |
122 | }; | 122 | }; |
123 | 123 | ||
124 | void reset() | 124 | void reset() |
125 | { | 125 | { |
126 | uint32_t i,j; | 126 | uint32_t i,j; |
127 | 127 | ||
128 | static uint32_t PA_Init[NUM_SUBKEYS] = | 128 | static uint32_t PA_Init[NUM_SUBKEYS] = |
129 | { | 129 | { |
130 | 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, | 130 | 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, |
131 | 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, | 131 | 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, |
132 | 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, | 132 | 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, |
133 | 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, | 133 | 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, |
134 | 0x9216d5d9, 0x8979fb1b | 134 | 0x9216d5d9, 0x8979fb1b |
135 | }; | 135 | }; |
136 | 136 | ||
137 | static uint32_t SB_Init[NUM_S_BOXES][NUM_ENTRIES] = { | 137 | static uint32_t SB_Init[NUM_S_BOXES][NUM_ENTRIES] = { |
138 | { | 138 | { |
139 | 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, | 139 | 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, |
140 | 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99, | 140 | 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99, |
141 | 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, | 141 | 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, |
142 | 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e, | 142 | 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e, |
143 | 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, | 143 | 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, |
144 | 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013, | 144 | 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013, |
145 | 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, | 145 | 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, |
146 | 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e, | 146 | 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e, |
147 | 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60, | 147 | 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60, |
148 | 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440, | 148 | 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440, |
149 | 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce, | 149 | 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce, |
150 | 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a, | 150 | 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a, |
151 | 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, | 151 | 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, |
152 | 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677, | 152 | 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677, |
153 | 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193, | 153 | 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193, |
154 | 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032, | 154 | 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032, |
155 | 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88, | 155 | 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88, |
156 | 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239, | 156 | 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239, |
157 | 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, | 157 | 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, |
158 | 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0, | 158 | 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0, |
159 | 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3, | 159 | 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3, |
160 | 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98, | 160 | 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98, |
161 | 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88, | 161 | 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88, |
162 | 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe, | 162 | 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe, |
163 | 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, | 163 | 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, |
164 | 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d, | 164 | 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d, |
165 | 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b, | 165 | 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b, |
166 | 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7, | 166 | 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7, |
167 | 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba, | 167 | 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba, |
168 | 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463, | 168 | 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463, |
169 | 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, | 169 | 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, |
170 | 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09, | 170 | 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09, |
171 | 171 | ||
172 | 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3, | 172 | 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3, |
173 | 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb, | 173 | 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb, |
174 | 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279, | 174 | 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279, |
175 | 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8, | 175 | 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8, |
176 | 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, | 176 | 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, |
177 | 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82, | 177 | 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82, |
178 | 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db, | 178 | 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db, |
179 | 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573, | 179 | 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573, |
180 | 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0, | 180 | 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0, |
181 | 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b, | 181 | 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b, |
182 | 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, | 182 | 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, |
183 | 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8, | 183 | 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8, |
184 | 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4, | 184 | 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4, |
185 | 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0, | 185 | 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0, |
186 | 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7, | 186 | 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7, |
187 | 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c, | 187 | 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c, |
188 | 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, | 188 | 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, |
189 | 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1, | 189 | 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1, |
190 | 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299, | 190 | 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299, |
191 | 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9, | 191 | 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9, |
192 | 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477, | 192 | 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477, |
193 | 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf, | 193 | 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf, |
194 | 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, | 194 | 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, |
195 | 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af, | 195 | 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af, |
196 | 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa, | 196 | 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa, |
197 | 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5, | 197 | 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5, |
198 | 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41, | 198 | 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41, |
199 | 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915, | 199 | 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915, |
200 | 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, | 200 | 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, |
201 | 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915, | 201 | 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915, |
202 | 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, | 202 | 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, |
203 | 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a | 203 | 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a |
204 | }, { | 204 | }, { |
205 | 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, | 205 | 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, |
206 | 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266, | 206 | 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266, |
207 | 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, | 207 | 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, |
208 | 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e, | 208 | 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e, |
209 | 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6, | 209 | 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6, |
210 | 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1, | 210 | 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1, |
211 | 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, | 211 | 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, |
212 | 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1, | 212 | 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1, |
213 | 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737, | 213 | 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737, |
214 | 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8, | 214 | 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8, |
215 | 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff, | 215 | 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff, |
216 | 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd, | 216 | 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd, |
217 | 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701, | 217 | 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701, |
218 | 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7, | 218 | 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7, |
219 | 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41, | 219 | 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41, |
220 | 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331, | 220 | 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331, |
221 | 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf, | 221 | 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf, |
222 | 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af, | 222 | 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af, |
223 | 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e, | 223 | 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e, |
224 | 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87, | 224 | 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87, |
225 | 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c, | 225 | 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c, |
226 | 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2, | 226 | 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2, |
227 | 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16, | 227 | 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16, |
228 | 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd, | 228 | 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd, |
229 | 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b, | 229 | 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b, |
230 | 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509, | 230 | 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509, |
231 | 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e, | 231 | 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e, |
232 | 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3, | 232 | 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3, |
233 | 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f, | 233 | 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f, |
234 | 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a, | 234 | 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a, |
235 | 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, | 235 | 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, |
236 | 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960, | 236 | 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960, |
237 | 237 | ||
238 | 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66, | 238 | 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66, |
239 | 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28, | 239 | 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28, |
240 | 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802, | 240 | 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802, |
241 | 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84, | 241 | 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84, |
242 | 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, | 242 | 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, |
243 | 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf, | 243 | 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf, |
244 | 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14, | 244 | 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14, |
245 | 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e, | 245 | 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e, |
246 | 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50, | 246 | 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50, |
247 | 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7, | 247 | 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7, |
248 | 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8, | 248 | 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8, |
249 | 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281, | 249 | 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281, |
250 | 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99, | 250 | 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99, |
251 | 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696, | 251 | 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696, |
252 | 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128, | 252 | 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128, |
253 | 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73, | 253 | 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73, |
254 | 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0, | 254 | 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0, |
255 | 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0, | 255 | 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0, |
256 | 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105, | 256 | 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105, |
257 | 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250, | 257 | 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250, |
258 | 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3, | 258 | 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3, |
259 | 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285, | 259 | 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285, |
260 | 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00, | 260 | 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00, |
261 | 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061, | 261 | 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061, |
262 | 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb, | 262 | 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb, |
263 | 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e, | 263 | 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e, |
264 | 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735, | 264 | 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735, |
265 | 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc, | 265 | 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc, |
266 | 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, | 266 | 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, |
267 | 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340, | 267 | 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340, |
268 | 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, | 268 | 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, |
269 | 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7 | 269 | 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7 |
270 | }, { | 270 | }, { |
271 | 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, | 271 | 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, |
272 | 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068, | 272 | 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068, |
273 | 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, | 273 | 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, |
274 | 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840, | 274 | 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840, |
275 | 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45, | 275 | 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45, |
276 | 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504, | 276 | 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504, |
277 | 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, | 277 | 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, |
278 | 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb, | 278 | 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb, |
279 | 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee, | 279 | 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee, |
280 | 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6, | 280 | 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6, |
281 | 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42, | 281 | 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42, |
282 | 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b, | 282 | 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b, |
283 | 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, | 283 | 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, |
284 | 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb, | 284 | 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb, |
285 | 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527, | 285 | 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527, |
286 | 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b, | 286 | 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b, |
287 | 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33, | 287 | 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33, |
288 | 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c, | 288 | 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c, |
289 | 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3, | 289 | 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3, |
290 | 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc, | 290 | 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc, |
291 | 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17, | 291 | 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17, |
292 | 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564, | 292 | 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564, |
293 | 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b, | 293 | 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b, |
294 | 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115, | 294 | 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115, |
295 | 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922, | 295 | 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922, |
296 | 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728, | 296 | 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728, |
297 | 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0, | 297 | 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0, |
298 | 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e, | 298 | 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e, |
299 | 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37, | 299 | 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37, |
300 | 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d, | 300 | 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d, |
301 | 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804, | 301 | 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804, |
302 | 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b, | 302 | 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b, |
303 | 303 | ||
304 | 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3, | 304 | 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3, |
305 | 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb, | 305 | 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb, |
306 | 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d, | 306 | 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d, |
307 | 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c, | 307 | 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c, |
308 | 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, | 308 | 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, |
309 | 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9, | 309 | 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9, |
310 | 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a, | 310 | 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a, |
311 | 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe, | 311 | 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe, |
312 | 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d, | 312 | 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d, |
313 | 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc, | 313 | 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc, |
314 | 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, | 314 | 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, |
315 | 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61, | 315 | 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61, |
316 | 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2, | 316 | 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2, |
317 | 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9, | 317 | 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9, |
318 | 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2, | 318 | 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2, |
319 | 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c, | 319 | 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c, |
320 | 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e, | 320 | 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e, |
321 | 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633, | 321 | 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633, |
322 | 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10, | 322 | 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10, |
323 | 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169, | 323 | 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169, |
324 | 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52, | 324 | 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52, |
325 | 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027, | 325 | 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027, |
326 | 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5, | 326 | 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5, |
327 | 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62, | 327 | 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62, |
328 | 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634, | 328 | 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634, |
329 | 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76, | 329 | 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76, |
330 | 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24, | 330 | 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24, |
331 | 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc, | 331 | 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc, |
332 | 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, | 332 | 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, |
333 | 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c, | 333 | 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c, |
334 | 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, | 334 | 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, |
335 | 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0 | 335 | 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0 |
336 | }, { | 336 | }, { |
337 | 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, | 337 | 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, |
338 | 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe, | 338 | 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe, |
339 | 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, | 339 | 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, |
340 | 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4, | 340 | 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4, |
341 | 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8, | 341 | 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8, |
342 | 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6, | 342 | 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6, |
343 | 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, | 343 | 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, |
344 | 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22, | 344 | 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22, |
345 | 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4, | 345 | 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4, |
346 | 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6, | 346 | 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6, |
347 | 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9, | 347 | 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9, |
348 | 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59, | 348 | 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59, |
349 | 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, | 349 | 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, |
350 | 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51, | 350 | 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51, |
351 | 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28, | 351 | 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28, |
352 | 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c, | 352 | 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c, |
353 | 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b, | 353 | 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b, |
354 | 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28, | 354 | 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28, |
355 | 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, | 355 | 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, |
356 | 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd, | 356 | 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd, |
357 | 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a, | 357 | 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a, |
358 | 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319, | 358 | 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319, |
359 | 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb, | 359 | 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb, |
360 | 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f, | 360 | 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f, |
361 | 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, | 361 | 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, |
362 | 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32, | 362 | 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32, |
363 | 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680, | 363 | 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680, |
364 | 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166, | 364 | 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166, |
365 | 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae, | 365 | 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae, |
366 | 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb, | 366 | 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb, |
367 | 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, | 367 | 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, |
368 | 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47, | 368 | 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47, |
369 | 369 | ||
370 | 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370, | 370 | 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370, |
371 | 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d, | 371 | 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d, |
372 | 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84, | 372 | 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84, |
373 | 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048, | 373 | 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048, |
374 | 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, | 374 | 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, |
375 | 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd, | 375 | 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd, |
376 | 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9, | 376 | 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9, |
377 | 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7, | 377 | 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7, |
378 | 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38, | 378 | 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38, |
379 | 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f, | 379 | 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f, |
380 | 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, | 380 | 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, |
381 | 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525, | 381 | 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525, |
382 | 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1, | 382 | 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1, |
383 | 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442, | 383 | 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442, |
384 | 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964, | 384 | 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964, |
385 | 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e, | 385 | 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e, |
386 | 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, | 386 | 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, |
387 | 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d, | 387 | 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d, |
388 | 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f, | 388 | 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f, |
389 | 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299, | 389 | 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299, |
390 | 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02, | 390 | 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02, |
391 | 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc, | 391 | 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc, |
392 | 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, | 392 | 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, |
393 | 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a, | 393 | 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a, |
394 | 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6, | 394 | 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6, |
395 | 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b, | 395 | 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b, |
396 | 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, | 396 | 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, |
397 | 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060, | 397 | 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060, |
398 | 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, | 398 | 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, |
399 | 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9, | 399 | 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9, |
400 | 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, | 400 | 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, |
401 | 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6 | 401 | 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6 |
402 | } | 402 | } |
403 | }; | 403 | }; |
404 | 404 | ||
405 | for (i=0;i<NUM_SUBKEYS;i++) | 405 | for (i=0;i<NUM_SUBKEYS;i++) |
406 | PA[i] = PA_Init[i]; | 406 | PA[i] = PA_Init[i]; |
407 | 407 | ||
408 | for (j=0;j<NUM_S_BOXES;j++) | 408 | for (j=0;j<NUM_S_BOXES;j++) |
409 | for (i=0;i<NUM_ENTRIES;i++) | 409 | for (i=0;i<NUM_ENTRIES;i++) |
410 | SB[j][i] = SB_Init[j][i]; | 410 | SB[j][i] = SB_Init[j][i]; |
411 | } | 411 | } |
412 | 412 | ||
413 | protected: | 413 | protected: |
414 | virtual void encipher( void *pData ) | 414 | virtual void encipher( void *pData ) |
415 | { | 415 | { |
416 | DWord *dwWork = (DWord *)pData; | 416 | DWord *dwWork = (DWord *)pData; |
417 | Word &w1 = dwWork->word0, &w2 = dwWork->word1; | 417 | Word &w1 = dwWork->word0, &w2 = dwWork->word1; |
418 | 418 | ||
419 | w1.word = be32toh( w1.word ); | 419 | w1.word = be32toh( w1.word ); |
420 | w2.word = be32toh( w2.word ); | 420 | w2.word = be32toh( w2.word ); |
421 | 421 | ||
422 | keyEncipher( w1, w2 ); | 422 | keyEncipher( w1, w2 ); |
423 | 423 | ||
424 | revBytes( w1.word ); | 424 | revBytes( w1.word ); |
425 | revBytes( w2.word ); | 425 | revBytes( w2.word ); |
426 | } | 426 | } |
427 | 427 | ||
428 | virtual void decipher( void *pData ) | 428 | virtual void decipher( void *pData ) |
429 | { | 429 | { |
430 | DWord *dwWork = (DWord *)pData; | 430 | DWord *dwWork = (DWord *)pData; |
431 | Word &w1 = dwWork->word0, &w2 = dwWork->word1; | 431 | Word &w1 = dwWork->word0, &w2 = dwWork->word1; |
432 | 432 | ||
433 | revBytes( w1.word ); | 433 | revBytes( w1.word ); |
434 | revBytes( w2.word ); | 434 | revBytes( w2.word ); |
435 | 435 | ||
436 | w1.word ^= PA[17]; | 436 | w1.word ^= PA[17]; |
437 | w2.word ^= F(w1)^PA[16]; w1.word ^= F(w2)^PA[15]; | 437 | w2.word ^= F(w1)^PA[16]; w1.word ^= F(w2)^PA[15]; |
438 | w2.word ^= F(w1)^PA[14]; w1.word ^= F(w2)^PA[13]; | 438 | w2.word ^= F(w1)^PA[14]; w1.word ^= F(w2)^PA[13]; |
439 | w2.word ^= F(w1)^PA[12]; w1.word ^= F(w2)^PA[11]; | 439 | w2.word ^= F(w1)^PA[12]; w1.word ^= F(w2)^PA[11]; |
440 | w2.word ^= F(w1)^PA[10]; w1.word ^= F(w2)^PA[9]; | 440 | w2.word ^= F(w1)^PA[10]; w1.word ^= F(w2)^PA[9]; |
441 | w2.word ^= F(w1)^PA[8]; w1.word ^= F(w2)^PA[7]; | 441 | w2.word ^= F(w1)^PA[8]; w1.word ^= F(w2)^PA[7]; |
442 | w2.word ^= F(w1)^PA[6]; w1.word ^= F(w2)^PA[5]; | 442 | w2.word ^= F(w1)^PA[6]; w1.word ^= F(w2)^PA[5]; |
443 | w2.word ^= F(w1)^PA[4]; w1.word ^= F(w2)^PA[3]; | 443 | w2.word ^= F(w1)^PA[4]; w1.word ^= F(w2)^PA[3]; |
444 | w2.word ^= F(w1)^PA[2]; w1.word ^= F(w2)^PA[1]; | 444 | w2.word ^= F(w1)^PA[2]; w1.word ^= F(w2)^PA[1]; |
445 | w2.word ^= PA[0]; | 445 | w2.word ^= PA[0]; |
446 | 446 | ||
447 | Bu::swap( w1, w2 ); | 447 | Bu::swap( w1, w2 ); |
448 | 448 | ||
449 | w1.word = htobe32( w1.word ); | 449 | w1.word = htobe32( w1.word ); |
450 | w2.word = htobe32( w2.word ); | 450 | w2.word = htobe32( w2.word ); |
451 | } | 451 | } |
452 | 452 | ||
453 | inline void keyEncipher( Word &w1, Word &w2 ) | 453 | inline void keyEncipher( Word &w1, Word &w2 ) |
454 | { | 454 | { |
455 | w1.word ^= PA[0]; | 455 | w1.word ^= PA[0]; |
456 | w2.word ^= F(w1)^PA[1]; w1.word ^= F(w2)^PA[2]; | 456 | w2.word ^= F(w1)^PA[1]; w1.word ^= F(w2)^PA[2]; |
457 | w2.word ^= F(w1)^PA[3]; w1.word ^= F(w2)^PA[4]; | 457 | w2.word ^= F(w1)^PA[3]; w1.word ^= F(w2)^PA[4]; |
458 | w2.word ^= F(w1)^PA[5]; w1.word ^= F(w2)^PA[6]; | 458 | w2.word ^= F(w1)^PA[5]; w1.word ^= F(w2)^PA[6]; |
459 | w2.word ^= F(w1)^PA[7]; w1.word ^= F(w2)^PA[8]; | 459 | w2.word ^= F(w1)^PA[7]; w1.word ^= F(w2)^PA[8]; |
460 | w2.word ^= F(w1)^PA[9]; w1.word ^= F(w2)^PA[10]; | 460 | w2.word ^= F(w1)^PA[9]; w1.word ^= F(w2)^PA[10]; |
461 | w2.word ^= F(w1)^PA[11]; w1.word ^= F(w2)^PA[12]; | 461 | w2.word ^= F(w1)^PA[11]; w1.word ^= F(w2)^PA[12]; |
462 | w2.word ^= F(w1)^PA[13]; w1.word ^= F(w2)^PA[14]; | 462 | w2.word ^= F(w1)^PA[13]; w1.word ^= F(w2)^PA[14]; |
463 | w2.word ^= F(w1)^PA[15]; w1.word ^= F(w2)^PA[16]; | 463 | w2.word ^= F(w1)^PA[15]; w1.word ^= F(w2)^PA[16]; |
464 | w2.word ^= PA[17]; | 464 | w2.word ^= PA[17]; |
465 | 465 | ||
466 | Bu::swap( w1, w2 ); | 466 | Bu::swap( w1, w2 ); |
467 | } | 467 | } |
468 | }; | 468 | }; |
469 | 469 | ||
470 | typedef CipherModeEcb<8, Blowfish<1> > BlowfishEcb; | 470 | typedef CipherModeEcb<8, Blowfish<1> > BlowfishEcb; |
471 | typedef CipherModeCfb<8, Blowfish<1> > BlowfishCfb; | 471 | typedef CipherModeCfb<8, Blowfish<1> > BlowfishCfb; |
472 | typedef CipherModeCbc<8, Blowfish<1> > BlowfishCbc; | 472 | typedef CipherModeCbc<8, Blowfish<1> > BlowfishCbc; |
473 | typedef CipherModeOfb<8, Blowfish<1> > BlowfishOfb; | 473 | typedef CipherModeOfb<8, Blowfish<1> > BlowfishOfb; |
474 | }; | 474 | }; |
475 | 475 | ||
476 | #endif | 476 | #endif |
diff --git a/src/experimental/cache.h b/src/experimental/cache.h index e3c8483..795d180 100644 --- a/src/experimental/cache.h +++ b/src/experimental/cache.h | |||
@@ -18,420 +18,420 @@ | |||
18 | 18 | ||
19 | namespace Bu | 19 | namespace Bu |
20 | { | 20 | { |
21 | // template<class keytype, class obtype> | 21 | // template<class keytype, class obtype> |
22 | // keytype __cacheGetKey( obtype *&pObj ); | 22 | // keytype __cacheGetKey( obtype *&pObj ); |
23 | template<class keytype, class obtype> | 23 | template<class keytype, class obtype> |
24 | keytype __cacheGetKey( const obtype *pObj ) | 24 | keytype __cacheGetKey( const obtype *pObj ) |
25 | { | 25 | { |
26 | return pObj->getKey(); | 26 | return pObj->getKey(); |
27 | } | 27 | } |
28 | 28 | ||
29 | template<class keytype, class obtype> | 29 | template<class keytype, class obtype> |
30 | class Cache | 30 | class Cache |
31 | { | 31 | { |
32 | public: | 32 | public: |
33 | /** | 33 | /** |
34 | * Cache Pointer - Provides access to data that is held within the | 34 | * Cache Pointer - Provides access to data that is held within the |
35 | * cache. This provides safe, refcounting access to data stored in | 35 | * cache. This provides safe, refcounting access to data stored in |
36 | * the cache, with support for lazy loading. | 36 | * the cache, with support for lazy loading. |
37 | */ | 37 | */ |
38 | class Ptr | 38 | class Ptr |
39 | { | 39 | { |
40 | friend class Bu::Cache<keytype, obtype>; | 40 | friend class Bu::Cache<keytype, obtype>; |
41 | private: | 41 | private: |
42 | Ptr( Cache<keytype, obtype> *pCache, obtype *pData, | 42 | Ptr( Cache<keytype, obtype> *pCache, obtype *pData, |
43 | const keytype &kId ) : | 43 | const keytype &kId ) : |
44 | pCache( pCache ), | 44 | pCache( pCache ), |
45 | pData( pData ), | 45 | pData( pData ), |
46 | kId( kId ) | 46 | kId( kId ) |
47 | { | 47 | { |
48 | if( pCache ) | 48 | if( pCache ) |
49 | pCache->incRef( kId ); | 49 | pCache->incRef( kId ); |
50 | } | 50 | } |
51 | 51 | ||
52 | Ptr( Cache<keytype, obtype> *pCache, const keytype &kId ) : | 52 | Ptr( Cache<keytype, obtype> *pCache, const keytype &kId ) : |
53 | pCache( pCache ), | 53 | pCache( pCache ), |
54 | pData( NULL ), | 54 | pData( NULL ), |
55 | kId( kId ) | 55 | kId( kId ) |
56 | { | 56 | { |
57 | } | 57 | } |
58 | 58 | ||
59 | public: | 59 | public: |
60 | Ptr( const Ptr &rSrc ) : | 60 | Ptr( const Ptr &rSrc ) : |
61 | pCache( rSrc.pCache ), | 61 | pCache( rSrc.pCache ), |
62 | pData( rSrc.pData ), | 62 | pData( rSrc.pData ), |
63 | kId( rSrc.kId ) | 63 | kId( rSrc.kId ) |
64 | { | 64 | { |
65 | if( pCache && pData ) | 65 | if( pCache && pData ) |
66 | pCache->incRef( kId ); | 66 | pCache->incRef( kId ); |
67 | } | 67 | } |
68 | 68 | ||
69 | Ptr() : | 69 | Ptr() : |
70 | pCache( 0 ), | 70 | pCache( 0 ), |
71 | pData( 0 ) | 71 | pData( 0 ) |
72 | { | 72 | { |
73 | } | 73 | } |
74 | 74 | ||
75 | virtual ~Ptr() | 75 | virtual ~Ptr() |
76 | { | 76 | { |
77 | if( pCache && pData ) | 77 | if( pCache && pData ) |
78 | pCache->decRef( kId ); | 78 | pCache->decRef( kId ); |
79 | } | 79 | } |
80 | 80 | ||
81 | obtype &operator*() | 81 | obtype &operator*() |
82 | { | 82 | { |
83 | checkPtr(); | 83 | checkPtr(); |
84 | return *pData; | 84 | return *pData; |
85 | } | 85 | } |
86 | 86 | ||
87 | const obtype &operator*() const | 87 | const obtype &operator*() const |
88 | { | 88 | { |
89 | checkPtr(); | 89 | checkPtr(); |
90 | return *pData; | 90 | return *pData; |
91 | } | 91 | } |
92 | 92 | ||
93 | obtype *operator->() | 93 | obtype *operator->() |
94 | { | 94 | { |
95 | checkPtr(); | 95 | checkPtr(); |
96 | return pData; | 96 | return pData; |
97 | } | 97 | } |
98 | 98 | ||
99 | const obtype *operator->() const | 99 | const obtype *operator->() const |
100 | { | 100 | { |
101 | checkPtr(); | 101 | checkPtr(); |
102 | return pData; | 102 | return pData; |
103 | } | 103 | } |
104 | 104 | ||
105 | bool isValid() const | 105 | bool isValid() const |
106 | { | 106 | { |
107 | return pCache != NULL; | 107 | return pCache != NULL; |
108 | } | 108 | } |
109 | 109 | ||
110 | bool isBound() const | 110 | bool isBound() const |
111 | { | 111 | { |
112 | return pData != NULL; | 112 | return pData != NULL; |
113 | } | 113 | } |
114 | 114 | ||
115 | bool isSet() const | 115 | bool isSet() const |
116 | { | 116 | { |
117 | return pCache != NULL; | 117 | return pCache != NULL; |
118 | } | 118 | } |
119 | 119 | ||
120 | const keytype &getKey() const | 120 | const keytype &getKey() const |
121 | { | 121 | { |
122 | return kId; | 122 | return kId; |
123 | } | 123 | } |
124 | 124 | ||
125 | void unbind() | 125 | void unbind() |
126 | { | 126 | { |
127 | if( pCache && pData ) | 127 | if( pCache && pData ) |
128 | pCache->decRef( kId ); | 128 | pCache->decRef( kId ); |
129 | pData = NULL; | 129 | pData = NULL; |
130 | } | 130 | } |
131 | 131 | ||
132 | void clear() | 132 | void clear() |
133 | { | 133 | { |
134 | unbind(); | 134 | unbind(); |
135 | pCache = NULL; | 135 | pCache = NULL; |
136 | } | 136 | } |
137 | 137 | ||
138 | void unset() | 138 | void unset() |
139 | { | 139 | { |
140 | clear(); | 140 | clear(); |
141 | } | 141 | } |
142 | 142 | ||
143 | Ptr &operator=( const Ptr &rRhs ) | 143 | Ptr &operator=( const Ptr &rRhs ) |
144 | { | 144 | { |
145 | if( pCache && pData ) | 145 | if( pCache && pData ) |
146 | pCache->decRef( kId ); | 146 | pCache->decRef( kId ); |
147 | pCache = rRhs.pCache; | 147 | pCache = rRhs.pCache; |
148 | pData = rRhs.pData; | 148 | pData = rRhs.pData; |
149 | kId = rRhs.kId; | 149 | kId = rRhs.kId; |
150 | if( pCache && pData ) | 150 | if( pCache && pData ) |
151 | pCache->incRef( kId ); | 151 | pCache->incRef( kId ); |
152 | return *this; | 152 | return *this; |
153 | } | 153 | } |
154 | 154 | ||
155 | bool operator==( const Ptr &rRhs ) const | 155 | bool operator==( const Ptr &rRhs ) const |
156 | { | 156 | { |
157 | return pCache == rRhs.pCache && kId == rRhs.kId; | 157 | return pCache == rRhs.pCache && kId == rRhs.kId; |
158 | } | 158 | } |
159 | 159 | ||
160 | bool operator!=( const Ptr &rRhs ) const | 160 | bool operator!=( const Ptr &rRhs ) const |
161 | { | 161 | { |
162 | return pCache != rRhs.pCache || kId != rRhs.kId; | 162 | return pCache != rRhs.pCache || kId != rRhs.kId; |
163 | } | 163 | } |
164 | 164 | ||
165 | private: | 165 | private: |
166 | void checkPtr() const | 166 | void checkPtr() const |
167 | { | 167 | { |
168 | if( pCache && !pData ) | 168 | if( pCache && !pData ) |
169 | { | 169 | { |
170 | pData = pCache->getRaw( kId ); | 170 | pData = pCache->getRaw( kId ); |
171 | pCache->incRef( kId ); | 171 | pCache->incRef( kId ); |
172 | } | 172 | } |
173 | } | 173 | } |
174 | 174 | ||
175 | private: | 175 | private: |
176 | Bu::Cache<keytype, obtype> *pCache; | 176 | Bu::Cache<keytype, obtype> *pCache; |
177 | mutable obtype *pData; | 177 | mutable obtype *pData; |
178 | mutable keytype kId; | 178 | mutable keytype kId; |
179 | }; | 179 | }; |
180 | 180 | ||
181 | private: | 181 | private: |
182 | typedef Bu::CacheStore<keytype, obtype> Store; | 182 | typedef Bu::CacheStore<keytype, obtype> Store; |
183 | typedef Bu::List<Store *> StoreList; | 183 | typedef Bu::List<Store *> StoreList; |
184 | typedef Bu::CacheCalc<keytype, obtype> Calc; | 184 | typedef Bu::CacheCalc<keytype, obtype> Calc; |
185 | 185 | ||
186 | typedef struct CacheEntry | 186 | typedef struct CacheEntry |
187 | { | 187 | { |
188 | obtype *pData; | 188 | obtype *pData; |
189 | int iRefs; | 189 | int iRefs; |
190 | time_t tLastSync; | 190 | time_t tLastSync; |
191 | } CacheEntry; | 191 | } CacheEntry; |
192 | 192 | ||
193 | typedef Bu::Hash<keytype, CacheEntry> CidHash; | 193 | typedef Bu::Hash<keytype, CacheEntry> CidHash; |
194 | 194 | ||
195 | public: | 195 | public: |
196 | typedef keytype Key; | 196 | typedef keytype Key; |
197 | Cache( Calc *pCalc, Store *pStore ) : | 197 | Cache( Calc *pCalc, Store *pStore ) : |
198 | pCalc( pCalc ), | 198 | pCalc( pCalc ), |
199 | pStore( pStore ) | 199 | pStore( pStore ) |
200 | { | 200 | { |
201 | TRACE(); | 201 | TRACE(); |
202 | pCalc->setCache( this ); | 202 | pCalc->setCache( this ); |
203 | } | 203 | } |
204 | 204 | ||
205 | virtual ~Cache() | 205 | virtual ~Cache() |
206 | { | 206 | { |
207 | TRACE(); | 207 | TRACE(); |
208 | 208 | ||
209 | // Better safe than sorry, better try a sync before anything | 209 | // Better safe than sorry, better try a sync before anything |
210 | // else happens. | 210 | // else happens. |
211 | sync(); | 211 | sync(); |
212 | 212 | ||
213 | // Cycle through and unload all objects from the system. | 213 | // Cycle through and unload all objects from the system. |
214 | for( typename CidHash::iterator i = hEnt.begin(); | 214 | for( typename CidHash::iterator i = hEnt.begin(); |
215 | i != hEnt.end(); i++ ) | 215 | i != hEnt.end(); i++ ) |
216 | { | 216 | { |
217 | if( i.getValue().iRefs > 0 ) | 217 | if( i.getValue().iRefs > 0 ) |
218 | { | 218 | { |
219 | // TODO: Throw an error in this case? iRefs != 0 for an | 219 | // TODO: Throw an error in this case? iRefs != 0 for an |
220 | // object when the Cache is destroyed. | 220 | // object when the Cache is destroyed. |
221 | throw Bu::ExceptionBase("iRefs not zero."); | 221 | throw Bu::ExceptionBase("iRefs not zero."); |
222 | } | 222 | } |
223 | pStore->unload( | 223 | pStore->unload( |
224 | i.getValue().pData, | 224 | i.getValue().pData, |
225 | i.getKey() | 225 | i.getKey() |
226 | ); | 226 | ); |
227 | } | 227 | } |
228 | delete pCalc; | 228 | delete pCalc; |
229 | delete pStore; | 229 | delete pStore; |
230 | } | 230 | } |
231 | 231 | ||
232 | Ptr insert( obtype *pData ) | 232 | Ptr insert( obtype *pData ) |
233 | { | 233 | { |
234 | TRACE( pData ); | 234 | TRACE( pData ); |
235 | if( pStore->has( __cacheGetKey<keytype, obtype>( pData ) ) ) | 235 | if( pStore->has( __cacheGetKey<keytype, obtype>( pData ) ) ) |
236 | throw Bu::ExceptionBase("Key already exists in cache."); | 236 | throw Bu::ExceptionBase("Key already exists in cache."); |
237 | CacheEntry e = {pData, 0, 0}; | 237 | CacheEntry e = {pData, 0, 0}; |
238 | keytype k = pStore->create( pData ); | 238 | keytype k = pStore->create( pData ); |
239 | hEnt.insert( k, e ); | 239 | hEnt.insert( k, e ); |
240 | 240 | ||
241 | pCalc->onLoad( pData, k ); | 241 | pCalc->onLoad( pData, k ); |
242 | 242 | ||
243 | pStore->sync(); | 243 | pStore->sync(); |
244 | 244 | ||
245 | return Ptr( this, pData, k ); | 245 | return Ptr( this, pData, k ); |
246 | } | 246 | } |
247 | 247 | ||
248 | bool has( const keytype &cId ) | 248 | bool has( const keytype &cId ) |
249 | { | 249 | { |
250 | return hEnt.has( cId ) || pStore->has( cId ); | 250 | return hEnt.has( cId ) || pStore->has( cId ); |
251 | } | 251 | } |
252 | 252 | ||
253 | /** | 253 | /** |
254 | * Retrieve an object from the cache and return a pointer to it. | 254 | * Retrieve an object from the cache and return a pointer to it. |
255 | * The object returned may be loaded from backend storage if needed, | 255 | * The object returned may be loaded from backend storage if needed, |
256 | * or the currently live object will be returned. | 256 | * or the currently live object will be returned. |
257 | *@param cId The id of the object to load. | 257 | *@param cId The id of the object to load. |
258 | *@returns A pointer to the object. | 258 | *@returns A pointer to the object. |
259 | */ | 259 | */ |
260 | Ptr get( const keytype &cId ) | 260 | Ptr get( const keytype &cId ) |
261 | { | 261 | { |
262 | TRACE( cId ); | 262 | TRACE( cId ); |
263 | try { | 263 | try { |
264 | return Ptr( this, hEnt.get( cId ).pData, cId ); | 264 | return Ptr( this, hEnt.get( cId ).pData, cId ); |
265 | } | 265 | } |
266 | catch( Bu::HashException &e ) { | 266 | catch( Bu::HashException &e ) { |
267 | CacheEntry e = {pStore->load( cId ), 0, time( NULL )}; | 267 | CacheEntry e = {pStore->load( cId ), 0, time( NULL )}; |
268 | pCalc->onLoad( e.pData, cId ); | 268 | pCalc->onLoad( e.pData, cId ); |
269 | hEnt.insert( cId, e ); | 269 | hEnt.insert( cId, e ); |
270 | return Ptr( this, e.pData, cId ); | 270 | return Ptr( this, e.pData, cId ); |
271 | } | 271 | } |
272 | } | 272 | } |
273 | 273 | ||
274 | /** | 274 | /** |
275 | * Retrieve a handle to an object without loading it now. This function | 275 | * Retrieve a handle to an object without loading it now. This function |
276 | * will return a pointer that has not yet been "realized" but can be | 276 | * will return a pointer that has not yet been "realized" but can be |
277 | * used normally. Upon initial use in any way the object will be | 277 | * used normally. Upon initial use in any way the object will be |
278 | * loaded from the cache, either linking against the already loaded | 278 | * loaded from the cache, either linking against the already loaded |
279 | * object or loading it fresh from the backend storage. The advantage | 279 | * object or loading it fresh from the backend storage. The advantage |
280 | * of this is that you recieve a usable handle to the data, but it | 280 | * of this is that you recieve a usable handle to the data, but it |
281 | * does not count as a reference yet, meaning that the data is loaded | 281 | * does not count as a reference yet, meaning that the data is loaded |
282 | * when you need it, not before. | 282 | * when you need it, not before. |
283 | */ | 283 | */ |
284 | Ptr getLazy( const keytype &cId ) | 284 | Ptr getLazy( const keytype &cId ) |
285 | { | 285 | { |
286 | TRACE( cId ); | 286 | TRACE( cId ); |
287 | return Ptr( this, cId ); | 287 | return Ptr( this, cId ); |
288 | } | 288 | } |
289 | 289 | ||
290 | int getRefCount( const keytype &cId ) | 290 | int getRefCount( const keytype &cId ) |
291 | { | 291 | { |
292 | TRACE( cId ); | 292 | TRACE( cId ); |
293 | return hEnt.get( cId ).iRefs; | 293 | return hEnt.get( cId ).iRefs; |
294 | } | 294 | } |
295 | 295 | ||
296 | void unload( const keytype &cId ) | 296 | void unload( const keytype &cId ) |
297 | { | 297 | { |
298 | TRACE( cId ); | 298 | TRACE( cId ); |
299 | try { | 299 | try { |
300 | if( hEnt.get( cId ).iRefs > 0 ) | 300 | if( hEnt.get( cId ).iRefs > 0 ) |
301 | { | 301 | { |
302 | printf("Shouldn't unload, references still exist!\n"); | 302 | printf("Shouldn't unload, references still exist!\n"); |
303 | return; | 303 | return; |
304 | } | 304 | } |
305 | } | 305 | } |
306 | catch( Bu::HashException &e ) { | 306 | catch( Bu::HashException &e ) { |
307 | // It's not here? Eh, return. | 307 | // It's not here? Eh, return. |
308 | return; | 308 | return; |
309 | } | 309 | } |
310 | obtype *pObj = hEnt.get( cId ).pData; | 310 | obtype *pObj = hEnt.get( cId ).pData; |
311 | pCalc->onUnload( pObj, cId ); | 311 | pCalc->onUnload( pObj, cId ); |
312 | hEnt.erase( cId ); | 312 | hEnt.erase( cId ); |
313 | 313 | ||
314 | // The unload has to happen last just in case cId is a reference | 314 | // The unload has to happen last just in case cId is a reference |
315 | // to data that is about to be deleted from memory by the unload. | 315 | // to data that is about to be deleted from memory by the unload. |
316 | pStore->unload( pObj, cId ); | 316 | pStore->unload( pObj, cId ); |
317 | } | 317 | } |
318 | 318 | ||
319 | void erase( const keytype &cId ) | 319 | void erase( const keytype &cId ) |
320 | { | 320 | { |
321 | TRACE( cId ); | 321 | TRACE( cId ); |
322 | try { | 322 | try { |
323 | if( hEnt.get( cId ).iRefs > 0 ) | 323 | if( hEnt.get( cId ).iRefs > 0 ) |
324 | { | 324 | { |
325 | printf("Shouldn't erase, references still exist!\n"); | 325 | printf("Shouldn't erase, references still exist!\n"); |
326 | return; | 326 | return; |
327 | } | 327 | } |
328 | 328 | ||
329 | obtype *pObj = hEnt.get( cId ).pData; | 329 | obtype *pObj = hEnt.get( cId ).pData; |
330 | pCalc->onDestroy( pObj, cId ); | 330 | pCalc->onDestroy( pObj, cId ); |
331 | hEnt.erase( cId ); | 331 | hEnt.erase( cId ); |
332 | 332 | ||
333 | pStore->destroy( pObj, cId ); | 333 | pStore->destroy( pObj, cId ); |
334 | pStore->sync(); | 334 | pStore->sync(); |
335 | } | 335 | } |
336 | catch( Bu::HashException &e ) { | 336 | catch( Bu::HashException &e ) { |
337 | pCalc->onDestroy( cId ); | 337 | pCalc->onDestroy( cId ); |
338 | 338 | ||
339 | if( hEnt.has( cId ) ) | 339 | if( hEnt.has( cId ) ) |
340 | { | 340 | { |
341 | // The object was loaded by onDestroy | 341 | // The object was loaded by onDestroy |
342 | erase( cId ); | 342 | erase( cId ); |
343 | } | 343 | } |
344 | else | 344 | else |
345 | { | 345 | { |
346 | pStore->destroy( cId ); | 346 | pStore->destroy( cId ); |
347 | pStore->sync(); | 347 | pStore->sync(); |
348 | } | 348 | } |
349 | } | 349 | } |
350 | } | 350 | } |
351 | 351 | ||
352 | typedef Bu::List<keytype> KeyList; | 352 | typedef Bu::List<keytype> KeyList; |
353 | KeyList getKeys() | 353 | KeyList getKeys() |
354 | { | 354 | { |
355 | return pStore->getKeys(); | 355 | return pStore->getKeys(); |
356 | } | 356 | } |
357 | 357 | ||
358 | KeyList getActiveKeys() | 358 | KeyList getActiveKeys() |
359 | { | 359 | { |
360 | return hEnt.getKeys(); | 360 | return hEnt.getKeys(); |
361 | } | 361 | } |
362 | 362 | ||
363 | int getSize() | 363 | int getSize() |
364 | { | 364 | { |
365 | return pStore->getSize(); | 365 | return pStore->getSize(); |
366 | } | 366 | } |
367 | 367 | ||
368 | /** | 368 | /** |
369 | * Make sure all currently loaded but not-in-use objects are synced to | 369 | * Make sure all currently loaded but not-in-use objects are synced to |
370 | * the store. | 370 | * the store. |
371 | */ | 371 | */ |
372 | void sync() | 372 | void sync() |
373 | { | 373 | { |
374 | TRACE(); | 374 | TRACE(); |
375 | int iSynced = 0; | 375 | int iSynced = 0; |
376 | for( typename CidHash::iterator i = hEnt.begin(); | 376 | for( typename CidHash::iterator i = hEnt.begin(); |
377 | i != hEnt.end(); i++ ) | 377 | i != hEnt.end(); i++ ) |
378 | { | 378 | { |
379 | if( i.getValue().iRefs == 0 ) | 379 | if( i.getValue().iRefs == 0 ) |
380 | { | 380 | { |
381 | if( pCalc->shouldSync( | 381 | if( pCalc->shouldSync( |
382 | i.getValue().pData, | 382 | i.getValue().pData, |
383 | i.getKey(), | 383 | i.getKey(), |
384 | i.getValue().tLastSync | 384 | i.getValue().tLastSync |
385 | ) ) | 385 | ) ) |
386 | { | 386 | { |
387 | pStore->sync( | 387 | pStore->sync( |
388 | i.getValue().pData, | 388 | i.getValue().pData, |
389 | i.getKey() | 389 | i.getKey() |
390 | ); | 390 | ); |
391 | iSynced++; | 391 | iSynced++; |
392 | i.getValue().tLastSync = time( NULL ); | 392 | i.getValue().tLastSync = time( NULL ); |
393 | } | 393 | } |
394 | } | 394 | } |
395 | } | 395 | } |
396 | if( iSynced > 0 ) | 396 | if( iSynced > 0 ) |
397 | { | 397 | { |
398 | pStore->sync(); | 398 | pStore->sync(); |
399 | } | 399 | } |
400 | } | 400 | } |
401 | 401 | ||
402 | private: | 402 | private: |
403 | void incRef( const keytype &cId ) | 403 | void incRef( const keytype &cId ) |
404 | { | 404 | { |
405 | TRACE( cId ); | 405 | TRACE( cId ); |
406 | hEnt.get( cId ).iRefs++; | 406 | hEnt.get( cId ).iRefs++; |
407 | } | 407 | } |
408 | 408 | ||
409 | void decRef( const keytype &cId ) | 409 | void decRef( const keytype &cId ) |
410 | { | 410 | { |
411 | TRACE( cId ); | 411 | TRACE( cId ); |
412 | CacheEntry &e = hEnt.get( cId ); | 412 | CacheEntry &e = hEnt.get( cId ); |
413 | e.iRefs--; | 413 | e.iRefs--; |
414 | } | 414 | } |
415 | 415 | ||
416 | obtype *getRaw( const keytype &cId ) | 416 | obtype *getRaw( const keytype &cId ) |
417 | { | 417 | { |
418 | TRACE( cId ); | 418 | TRACE( cId ); |
419 | try { | 419 | try { |
420 | return hEnt.get( cId ).pData; | 420 | return hEnt.get( cId ).pData; |
421 | } | 421 | } |
422 | catch( Bu::HashException &e ) { | 422 | catch( Bu::HashException &e ) { |
423 | CacheEntry e = {pStore->load( cId ), 0, time( NULL )}; | 423 | CacheEntry e = {pStore->load( cId ), 0, time( NULL )}; |
424 | pCalc->onLoad( e.pData, cId ); | 424 | pCalc->onLoad( e.pData, cId ); |
425 | hEnt.insert( cId, e ); | 425 | hEnt.insert( cId, e ); |
426 | return e.pData; | 426 | return e.pData; |
427 | } | 427 | } |
428 | } | 428 | } |
429 | 429 | ||
430 | private: | 430 | private: |
431 | CidHash hEnt; | 431 | CidHash hEnt; |
432 | Calc *pCalc; | 432 | Calc *pCalc; |
433 | Store *pStore; | 433 | Store *pStore; |
434 | }; | 434 | }; |
435 | }; | 435 | }; |
436 | 436 | ||
437 | #endif | 437 | #endif |
diff --git a/src/experimental/cachecalc.h b/src/experimental/cachecalc.h index ecfa3f4..cb5c755 100644 --- a/src/experimental/cachecalc.h +++ b/src/experimental/cachecalc.h | |||
@@ -14,50 +14,50 @@ | |||
14 | 14 | ||
15 | namespace Bu | 15 | namespace Bu |
16 | { | 16 | { |
17 | template<class keytype, class obtype> class Cache; | 17 | template<class keytype, class obtype> class Cache; |
18 | 18 | ||
19 | template<class keytype, class obtype> | 19 | template<class keytype, class obtype> |
20 | class CacheCalc | 20 | class CacheCalc |
21 | { | 21 | { |
22 | friend class Cache<keytype, obtype>; | 22 | friend class Cache<keytype, obtype>; |
23 | private: | 23 | private: |
24 | typedef Cache<keytype, obtype> MyCache; | 24 | typedef Cache<keytype, obtype> MyCache; |
25 | public: | 25 | public: |
26 | CacheCalc() : | 26 | CacheCalc() : |
27 | pCache( (MyCache *)0 ) | 27 | pCache( (MyCache *)0 ) |
28 | { | 28 | { |
29 | TRACE(); | 29 | TRACE(); |
30 | } | 30 | } |
31 | 31 | ||
32 | virtual ~CacheCalc() | 32 | virtual ~CacheCalc() |
33 | { | 33 | { |
34 | TRACE(); | 34 | TRACE(); |
35 | } | 35 | } |
36 | 36 | ||
37 | virtual void onLoad( obtype *pSrc, const keytype &key )=0; | 37 | virtual void onLoad( obtype *pSrc, const keytype &key )=0; |
38 | virtual void onUnload( obtype *pSrc, const keytype &key )=0; | 38 | virtual void onUnload( obtype *pSrc, const keytype &key )=0; |
39 | virtual void onDestroy( obtype *pSrc, const keytype &key )=0; | 39 | virtual void onDestroy( obtype *pSrc, const keytype &key )=0; |
40 | virtual void onDestroy( const keytype &key )=0; | 40 | virtual void onDestroy( const keytype &key )=0; |
41 | virtual bool shouldSync( obtype *pSrc, const keytype &key, | 41 | virtual bool shouldSync( obtype *pSrc, const keytype &key, |
42 | time_t tLastSync )=0; | 42 | time_t tLastSync )=0; |
43 | virtual void onTick() { }; | 43 | virtual void onTick() { }; |
44 | 44 | ||
45 | protected: | 45 | protected: |
46 | MyCache *getCache() | 46 | MyCache *getCache() |
47 | { | 47 | { |
48 | TRACE(); | 48 | TRACE(); |
49 | return pCache; | 49 | return pCache; |
50 | } | 50 | } |
51 | 51 | ||
52 | private: | 52 | private: |
53 | void setCache( MyCache *pCache ) | 53 | void setCache( MyCache *pCache ) |
54 | { | 54 | { |
55 | TRACE(); | 55 | TRACE(); |
56 | this->pCache = pCache; | 56 | this->pCache = pCache; |
57 | } | 57 | } |
58 | 58 | ||
59 | MyCache *pCache; | 59 | MyCache *pCache; |
60 | }; | 60 | }; |
61 | }; | 61 | }; |
62 | 62 | ||
63 | #endif | 63 | #endif |
diff --git a/src/experimental/cachestore.h b/src/experimental/cachestore.h index a332e49..5052670 100644 --- a/src/experimental/cachestore.h +++ b/src/experimental/cachestore.h | |||
@@ -12,35 +12,35 @@ | |||
12 | 12 | ||
13 | namespace Bu | 13 | namespace Bu |
14 | { | 14 | { |
15 | /** | 15 | /** |
16 | * Handles I/O for data in the cache. This also assigns ID's to the newly | 16 | * Handles I/O for data in the cache. This also assigns ID's to the newly |
17 | * created objects that are requested through this system. | 17 | * created objects that are requested through this system. |
18 | */ | 18 | */ |
19 | template<class keytype, class obtype> | 19 | template<class keytype, class obtype> |
20 | class CacheStore | 20 | class CacheStore |
21 | { | 21 | { |
22 | public: | 22 | public: |
23 | CacheStore() | 23 | CacheStore() |
24 | { | 24 | { |
25 | } | 25 | } |
26 | 26 | ||
27 | virtual ~CacheStore() | 27 | virtual ~CacheStore() |
28 | { | 28 | { |
29 | } | 29 | } |
30 | 30 | ||
31 | virtual obtype *load( const keytype &key )=0; | 31 | virtual obtype *load( const keytype &key )=0; |
32 | virtual void unload( obtype *pObj, const keytype &key )=0; | 32 | virtual void unload( obtype *pObj, const keytype &key )=0; |
33 | virtual keytype create( obtype *pSrc )=0; | 33 | virtual keytype create( obtype *pSrc )=0; |
34 | virtual void sync()=0; | 34 | virtual void sync()=0; |
35 | virtual void sync( obtype *pObj, const keytype &key )=0; | 35 | virtual void sync( obtype *pObj, const keytype &key )=0; |
36 | virtual void destroy( obtype *pObj, const keytype &key )=0; | 36 | virtual void destroy( obtype *pObj, const keytype &key )=0; |
37 | virtual void destroy( const keytype &key )=0; | 37 | virtual void destroy( const keytype &key )=0; |
38 | virtual bool has( const keytype &key )=0; | 38 | virtual bool has( const keytype &key )=0; |
39 | virtual Bu::List<keytype> getKeys() { return Bu::List<keytype>(); } | 39 | virtual Bu::List<keytype> getKeys() { return Bu::List<keytype>(); } |
40 | virtual int getSize() { return -1; } | 40 | virtual int getSize() { return -1; } |
41 | 41 | ||
42 | private: | 42 | private: |
43 | }; | 43 | }; |
44 | }; | 44 | }; |
45 | 45 | ||
46 | #endif | 46 | #endif |
diff --git a/src/experimental/cachestorefiles.h b/src/experimental/cachestorefiles.h index d3a6894..0805e7b 100644 --- a/src/experimental/cachestorefiles.h +++ b/src/experimental/cachestorefiles.h | |||
@@ -23,188 +23,188 @@ | |||
23 | 23 | ||
24 | namespace Bu | 24 | namespace Bu |
25 | { | 25 | { |
26 | template<class keytype, class obtype> | 26 | template<class keytype, class obtype> |
27 | keytype __cacheGetKey( const obtype *pObj ); | 27 | keytype __cacheGetKey( const obtype *pObj ); |
28 | 28 | ||
29 | template<class keytype, class obtype> | 29 | template<class keytype, class obtype> |
30 | obtype *__cacheStoreFilesAlloc( const keytype &key ) | 30 | obtype *__cacheStoreFilesAlloc( const keytype &key ) |
31 | { | 31 | { |
32 | return new obtype(); | 32 | return new obtype(); |
33 | } | 33 | } |
34 | 34 | ||
35 | template<class keytype, class obtype> | 35 | template<class keytype, class obtype> |
36 | void __cacheStoreFilesStore( Bu::Stream &s, obtype &rObj, | 36 | void __cacheStoreFilesStore( Bu::Stream &s, obtype &rObj, |
37 | const keytype & ) | 37 | const keytype & ) |
38 | { | 38 | { |
39 | Bu::Archive ar( s, Bu::Archive::save ); | 39 | Bu::Archive ar( s, Bu::Archive::save ); |
40 | ar << rObj; | 40 | ar << rObj; |
41 | } | 41 | } |
42 | 42 | ||
43 | template<class keytype, class obtype> | 43 | template<class keytype, class obtype> |
44 | obtype *__cacheStoreFilesLoad( Bu::Stream &s, const keytype &key ) | 44 | obtype *__cacheStoreFilesLoad( Bu::Stream &s, const keytype &key ) |
45 | { | 45 | { |
46 | obtype *pObj = __cacheStoreFilesAlloc<keytype, obtype>( key ); | 46 | obtype *pObj = __cacheStoreFilesAlloc<keytype, obtype>( key ); |
47 | Bu::Archive ar( s, Bu::Archive::load ); | 47 | Bu::Archive ar( s, Bu::Archive::load ); |
48 | ar >> (*pObj); | 48 | ar >> (*pObj); |
49 | return pObj; | 49 | return pObj; |
50 | } | 50 | } |
51 | 51 | ||
52 | template<class keytype, class obtype> | 52 | template<class keytype, class obtype> |
53 | class CacheStoreFiles : public CacheStore<keytype, obtype> | 53 | class CacheStoreFiles : public CacheStore<keytype, obtype> |
54 | { | 54 | { |
55 | public: | 55 | public: |
56 | CacheStoreFiles( const Bu::String &sPrefix ) : | 56 | CacheStoreFiles( const Bu::String &sPrefix ) : |
57 | sPrefix( sPrefix ) | 57 | sPrefix( sPrefix ) |
58 | { | 58 | { |
59 | if( access( sPrefix.getStr(), W_OK|R_OK|X_OK ) ) | 59 | if( access( sPrefix.getStr(), W_OK|R_OK|X_OK ) ) |
60 | { | 60 | { |
61 | #ifdef WIN32 | 61 | #ifdef WIN32 |
62 | mkdir( sPrefix.getStr() ); | 62 | mkdir( sPrefix.getStr() ); |
63 | #else | 63 | #else |
64 | mkdir( sPrefix.getStr(), 0755 ); | 64 | mkdir( sPrefix.getStr(), 0755 ); |
65 | #endif | 65 | #endif |
66 | } | 66 | } |
67 | } | 67 | } |
68 | 68 | ||
69 | virtual ~CacheStoreFiles() | 69 | virtual ~CacheStoreFiles() |
70 | { | 70 | { |
71 | } | 71 | } |
72 | 72 | ||
73 | virtual obtype *load( const keytype &key ) | 73 | virtual obtype *load( const keytype &key ) |
74 | { | 74 | { |
75 | // try | 75 | // try |
76 | // { | 76 | // { |
77 | Bu::MemBuf mb; | 77 | Bu::MemBuf mb; |
78 | Bu::Formatter f( mb ); | 78 | Bu::Formatter f( mb ); |
79 | f << sPrefix << "/" << key; | 79 | f << sPrefix << "/" << key; |
80 | Bu::File fIn( mb.getString(), Bu::File::Read ); | 80 | Bu::File fIn( mb.getString(), Bu::File::Read ); |
81 | obtype *pOb = __cacheStoreFilesLoad<keytype, obtype>( fIn, key ); | 81 | obtype *pOb = __cacheStoreFilesLoad<keytype, obtype>( fIn, key ); |
82 | return pOb; | 82 | return pOb; |
83 | // } | 83 | // } |
84 | // catch( std::exception &e ) | 84 | // catch( std::exception &e ) |
85 | // { | 85 | // { |
86 | // throw Bu::HashException( e.what() ); | 86 | // throw Bu::HashException( e.what() ); |
87 | // } | 87 | // } |
88 | } | 88 | } |
89 | 89 | ||
90 | virtual void unload( obtype *pObj, const keytype & ) | 90 | virtual void unload( obtype *pObj, const keytype & ) |
91 | { | 91 | { |
92 | delete pObj; | 92 | delete pObj; |
93 | } | 93 | } |
94 | 94 | ||
95 | virtual keytype create( obtype *pSrc ) | 95 | virtual keytype create( obtype *pSrc ) |
96 | { | 96 | { |
97 | keytype key = __cacheGetKey<keytype, obtype>( pSrc ); | 97 | keytype key = __cacheGetKey<keytype, obtype>( pSrc ); |
98 | Bu::MemBuf mb; | 98 | Bu::MemBuf mb; |
99 | Bu::Formatter f( mb ); | 99 | Bu::Formatter f( mb ); |
100 | f << sPrefix << "/" << key; | 100 | f << sPrefix << "/" << key; |
101 | 101 | ||
102 | Bu::File fTouch( mb.getString(), Bu::File::WriteNew ); | 102 | Bu::File fTouch( mb.getString(), Bu::File::WriteNew ); |
103 | 103 | ||
104 | return key; | 104 | return key; |
105 | } | 105 | } |
106 | 106 | ||
107 | virtual void sync() | 107 | virtual void sync() |
108 | { | 108 | { |
109 | } | 109 | } |
110 | 110 | ||
111 | virtual void sync( obtype *pSrc, const keytype &key ) | 111 | virtual void sync( obtype *pSrc, const keytype &key ) |
112 | { | 112 | { |
113 | Bu::MemBuf mb; | 113 | Bu::MemBuf mb; |
114 | Bu::Formatter f( mb ); | 114 | Bu::Formatter f( mb ); |
115 | f << sPrefix << "/" << key; | 115 | f << sPrefix << "/" << key; |
116 | 116 | ||
117 | Bu::File fOut( mb.getString(), Bu::File::WriteNew ); | 117 | Bu::File fOut( mb.getString(), Bu::File::WriteNew ); |
118 | __cacheStoreFilesStore<keytype, obtype>( fOut, *pSrc, key ); | 118 | __cacheStoreFilesStore<keytype, obtype>( fOut, *pSrc, key ); |
119 | } | 119 | } |
120 | 120 | ||
121 | virtual void destroy( obtype *pObj, const keytype &key ) | 121 | virtual void destroy( obtype *pObj, const keytype &key ) |
122 | { | 122 | { |
123 | Bu::MemBuf mb; | 123 | Bu::MemBuf mb; |
124 | Bu::Formatter f( mb ); | 124 | Bu::Formatter f( mb ); |
125 | f << sPrefix << "/" << key; | 125 | f << sPrefix << "/" << key; |
126 | 126 | ||
127 | unlink( mb.getString().getStr() ); | 127 | unlink( mb.getString().getStr() ); |
128 | delete pObj; | 128 | delete pObj; |
129 | } | 129 | } |
130 | 130 | ||
131 | virtual void destroy( const keytype &key ) | 131 | virtual void destroy( const keytype &key ) |
132 | { | 132 | { |
133 | Bu::MemBuf mb; | 133 | Bu::MemBuf mb; |
134 | Bu::Formatter f( mb ); | 134 | Bu::Formatter f( mb ); |
135 | f << sPrefix << "/" << key; | 135 | f << sPrefix << "/" << key; |
136 | 136 | ||
137 | unlink( mb.getString().getStr() ); | 137 | unlink( mb.getString().getStr() ); |
138 | } | 138 | } |
139 | 139 | ||
140 | virtual bool has( const keytype &key ) | 140 | virtual bool has( const keytype &key ) |
141 | { | 141 | { |
142 | Bu::MemBuf mb; | 142 | Bu::MemBuf mb; |
143 | Bu::Formatter f( mb ); | 143 | Bu::Formatter f( mb ); |
144 | f << sPrefix << "/"; | 144 | f << sPrefix << "/"; |
145 | Bu::String sBase = mb.getString(); | 145 | Bu::String sBase = mb.getString(); |
146 | f << key; | 146 | f << key; |
147 | 147 | ||
148 | if( sBase == mb.getString() ) | 148 | if( sBase == mb.getString() ) |
149 | return false; | 149 | return false; |
150 | 150 | ||
151 | return access( mb.getString().getStr(), F_OK ) == 0; | 151 | return access( mb.getString().getStr(), F_OK ) == 0; |
152 | } | 152 | } |
153 | 153 | ||
154 | virtual Bu::List<keytype> getKeys() | 154 | virtual Bu::List<keytype> getKeys() |
155 | { | 155 | { |
156 | DIR *dir = opendir( sPrefix.getStr() ); | 156 | DIR *dir = opendir( sPrefix.getStr() ); |
157 | struct dirent *de; | 157 | struct dirent *de; |
158 | Bu::List<keytype> lKeys; | 158 | Bu::List<keytype> lKeys; |
159 | 159 | ||
160 | while( (de = readdir( dir ) ) ) | 160 | while( (de = readdir( dir ) ) ) |
161 | { | 161 | { |
162 | if( de->d_type != DT_REG ) | 162 | if( de->d_type != DT_REG ) |
163 | continue; | 163 | continue; |
164 | 164 | ||
165 | keytype tmp; | 165 | keytype tmp; |
166 | Bu::MemBuf mb( de->d_name ); | 166 | Bu::MemBuf mb( de->d_name ); |
167 | Bu::Formatter f( mb ); | 167 | Bu::Formatter f( mb ); |
168 | try | 168 | try |
169 | { | 169 | { |
170 | Fmt fm; | 170 | Fmt fm; |
171 | fm.tokenize( false ); | 171 | fm.tokenize( false ); |
172 | f << fm; | 172 | f << fm; |
173 | f >> tmp; | 173 | f >> tmp; |
174 | } | 174 | } |
175 | catch( Bu::ExceptionBase &e ) | 175 | catch( Bu::ExceptionBase &e ) |
176 | { | 176 | { |
177 | Bu::sio << "Parse error in dir-scan: " << e.what() | 177 | Bu::sio << "Parse error in dir-scan: " << e.what() |
178 | << Bu::sio.nl; | 178 | << Bu::sio.nl; |
179 | } | 179 | } |
180 | lKeys.append( tmp ); | 180 | lKeys.append( tmp ); |
181 | } | 181 | } |
182 | closedir( dir ); | 182 | closedir( dir ); |
183 | 183 | ||
184 | return lKeys; | 184 | return lKeys; |
185 | } | 185 | } |
186 | 186 | ||
187 | virtual int getSize() | 187 | virtual int getSize() |
188 | { | 188 | { |
189 | DIR *dir = opendir( sPrefix.getStr() ); | 189 | DIR *dir = opendir( sPrefix.getStr() ); |
190 | struct dirent *de; | 190 | struct dirent *de; |
191 | int iCount = 0; | 191 | int iCount = 0; |
192 | 192 | ||
193 | while( (de = readdir( dir ) ) ) | 193 | while( (de = readdir( dir ) ) ) |
194 | { | 194 | { |
195 | if( de->d_type != DT_REG ) | 195 | if( de->d_type != DT_REG ) |
196 | continue; | 196 | continue; |
197 | 197 | ||
198 | iCount++; | 198 | iCount++; |
199 | } | 199 | } |
200 | closedir( dir ); | 200 | closedir( dir ); |
201 | 201 | ||
202 | return iCount; | 202 | return iCount; |
203 | } | 203 | } |
204 | 204 | ||
205 | private: | 205 | private: |
206 | Bu::String sPrefix; | 206 | Bu::String sPrefix; |
207 | }; | 207 | }; |
208 | 208 | ||
209 | }; | 209 | }; |
210 | 210 | ||
diff --git a/src/experimental/cachestoremyriad.h b/src/experimental/cachestoremyriad.h index 1953b61..01fe307 100644 --- a/src/experimental/cachestoremyriad.h +++ b/src/experimental/cachestoremyriad.h | |||
@@ -18,141 +18,141 @@ | |||
18 | 18 | ||
19 | namespace Bu | 19 | namespace Bu |
20 | { | 20 | { |
21 | template<class keytype, class obtype> | 21 | template<class keytype, class obtype> |
22 | keytype __cacheGetKey( const obtype *pObj ); | 22 | keytype __cacheGetKey( const obtype *pObj ); |
23 | 23 | ||
24 | template<class keytype, class obtype> | 24 | template<class keytype, class obtype> |
25 | obtype *__cacheStoreMyriadAlloc( const keytype &key ) | 25 | obtype *__cacheStoreMyriadAlloc( const keytype &key ) |
26 | { | 26 | { |
27 | return new obtype(); | 27 | return new obtype(); |
28 | } | 28 | } |
29 | 29 | ||
30 | template<class keytype, class obtype> | 30 | template<class keytype, class obtype> |
31 | void __cacheStoreMyriadStore( Bu::Stream &s, obtype &rObj, | 31 | void __cacheStoreMyriadStore( Bu::Stream &s, obtype &rObj, |
32 | const keytype & ) | 32 | const keytype & ) |
33 | { | 33 | { |
34 | Bu::Archive ar( s, Bu::Archive::save ); | 34 | Bu::Archive ar( s, Bu::Archive::save ); |
35 | ar << rObj; | 35 | ar << rObj; |
36 | } | 36 | } |
37 | 37 | ||
38 | template<class keytype, class obtype> | 38 | template<class keytype, class obtype> |
39 | obtype *__cacheStoreMyriadLoad( Bu::Stream &s, const keytype &key ) | 39 | obtype *__cacheStoreMyriadLoad( Bu::Stream &s, const keytype &key ) |
40 | { | 40 | { |
41 | obtype *pObj = __cacheStoreMyriadAlloc<keytype, obtype>( key ); | 41 | obtype *pObj = __cacheStoreMyriadAlloc<keytype, obtype>( key ); |
42 | Bu::Archive ar( s, Bu::Archive::load ); | 42 | Bu::Archive ar( s, Bu::Archive::load ); |
43 | ar >> (*pObj); | 43 | ar >> (*pObj); |
44 | return pObj; | 44 | return pObj; |
45 | } | 45 | } |
46 | 46 | ||
47 | template<class keytype, class obtype> | 47 | template<class keytype, class obtype> |
48 | class CacheStoreMyriad : public CacheStore<keytype, obtype> | 48 | class CacheStoreMyriad : public CacheStore<keytype, obtype> |
49 | { | 49 | { |
50 | public: | 50 | public: |
51 | CacheStoreMyriad( Bu::Stream &sArch, | 51 | CacheStoreMyriad( Bu::Stream &sArch, |
52 | int iBlockSize=512, int iPreAllocate=8 ) : | 52 | int iBlockSize=512, int iPreAllocate=8 ) : |
53 | mStore( sArch, iBlockSize, iPreAllocate ) | 53 | mStore( sArch, iBlockSize, iPreAllocate ) |
54 | { | 54 | { |
55 | try | 55 | try |
56 | { | 56 | { |
57 | MyriadStream ns = mStore.openStream( 1 ); | 57 | MyriadStream ns = mStore.openStream( 1 ); |
58 | Bu::Archive ar( ns, Bu::Archive::load ); | 58 | Bu::Archive ar( ns, Bu::Archive::load ); |
59 | ar >> hId; | 59 | ar >> hId; |
60 | } | 60 | } |
61 | catch( Bu::MyriadException &e ) | 61 | catch( Bu::MyriadException &e ) |
62 | { | 62 | { |
63 | int iStream = mStore.createStream(); | 63 | int iStream = mStore.createStream(); |
64 | if( iStream != 1 ) | 64 | if( iStream != 1 ) |
65 | throw Bu::ExceptionBase("That's...horrible...id = %d.\n\n", | 65 | throw Bu::ExceptionBase("That's...horrible...id = %d.\n\n", |
66 | iStream ); | 66 | iStream ); |
67 | MyriadStream ns = mStore.openStream( 1 ); | 67 | MyriadStream ns = mStore.openStream( 1 ); |
68 | Bu::Archive ar( ns, Bu::Archive::save ); | 68 | Bu::Archive ar( ns, Bu::Archive::save ); |
69 | ar << hId; | 69 | ar << hId; |
70 | } | 70 | } |
71 | } | 71 | } |
72 | 72 | ||
73 | virtual ~CacheStoreMyriad() | 73 | virtual ~CacheStoreMyriad() |
74 | { | 74 | { |
75 | MyriadStream ns = mStore.openStream( 1 ); | 75 | MyriadStream ns = mStore.openStream( 1 ); |
76 | Bu::Archive ar( ns, Bu::Archive::save ); | 76 | Bu::Archive ar( ns, Bu::Archive::save ); |
77 | ar << hId; | 77 | ar << hId; |
78 | } | 78 | } |
79 | 79 | ||
80 | virtual obtype *load( const keytype &key ) | 80 | virtual obtype *load( const keytype &key ) |
81 | { | 81 | { |
82 | int iStream = hId.get( key ); | 82 | int iStream = hId.get( key ); |
83 | MyriadStream ns = mStore.openStream( iStream ); | 83 | MyriadStream ns = mStore.openStream( iStream ); |
84 | obtype *pOb = __cacheStoreMyriadLoad<keytype, obtype>( ns, key ); | 84 | obtype *pOb = __cacheStoreMyriadLoad<keytype, obtype>( ns, key ); |
85 | return pOb; | 85 | return pOb; |
86 | } | 86 | } |
87 | 87 | ||
88 | virtual void unload( obtype *pObj, const keytype & ) | 88 | virtual void unload( obtype *pObj, const keytype & ) |
89 | { | 89 | { |
90 | delete pObj; | 90 | delete pObj; |
91 | } | 91 | } |
92 | 92 | ||
93 | virtual keytype create( obtype *pSrc ) | 93 | virtual keytype create( obtype *pSrc ) |
94 | { | 94 | { |
95 | keytype key = __cacheGetKey<keytype, obtype>( pSrc ); | 95 | keytype key = __cacheGetKey<keytype, obtype>( pSrc ); |
96 | int iStream = mStore.createStream(); | 96 | int iStream = mStore.createStream(); |
97 | hId.insert( key, iStream ); | 97 | hId.insert( key, iStream ); |
98 | MyriadStream ns = mStore.openStream( iStream ); | 98 | MyriadStream ns = mStore.openStream( iStream ); |
99 | __cacheStoreMyriadStore<keytype, obtype>( ns, *pSrc, key ); | 99 | __cacheStoreMyriadStore<keytype, obtype>( ns, *pSrc, key ); |
100 | ns.setSize( ns.tell() ); | 100 | ns.setSize( ns.tell() ); |
101 | return key; | 101 | return key; |
102 | } | 102 | } |
103 | 103 | ||
104 | virtual void sync() | 104 | virtual void sync() |
105 | { | 105 | { |
106 | MyriadStream ns = mStore.openStream( 1 ); | 106 | MyriadStream ns = mStore.openStream( 1 ); |
107 | Bu::Archive ar( ns, Bu::Archive::save ); | 107 | Bu::Archive ar( ns, Bu::Archive::save ); |
108 | ar << hId; | 108 | ar << hId; |
109 | ns.setSize( ns.tell() ); | 109 | ns.setSize( ns.tell() ); |
110 | mStore.sync(); | 110 | mStore.sync(); |
111 | } | 111 | } |
112 | 112 | ||
113 | virtual void sync( obtype *pSrc, const keytype &key ) | 113 | virtual void sync( obtype *pSrc, const keytype &key ) |
114 | { | 114 | { |
115 | int iStream = hId.get( key ); | 115 | int iStream = hId.get( key ); |
116 | MyriadStream ns = mStore.openStream( iStream ); | 116 | MyriadStream ns = mStore.openStream( iStream ); |
117 | __cacheStoreMyriadStore<keytype, obtype>( ns, *pSrc, key ); | 117 | __cacheStoreMyriadStore<keytype, obtype>( ns, *pSrc, key ); |
118 | ns.setSize( ns.tell() ); | 118 | ns.setSize( ns.tell() ); |
119 | } | 119 | } |
120 | 120 | ||
121 | virtual void destroy( obtype *pObj, const keytype &key ) | 121 | virtual void destroy( obtype *pObj, const keytype &key ) |
122 | { | 122 | { |
123 | int iStream = hId.get( key ); | 123 | int iStream = hId.get( key ); |
124 | mStore.deleteStream( iStream ); | 124 | mStore.deleteStream( iStream ); |
125 | hId.erase( key ); | 125 | hId.erase( key ); |
126 | delete pObj; | 126 | delete pObj; |
127 | } | 127 | } |
128 | 128 | ||
129 | virtual void destroy( const keytype &key ) | 129 | virtual void destroy( const keytype &key ) |
130 | { | 130 | { |
131 | int iStream = hId.get( key ); | 131 | int iStream = hId.get( key ); |
132 | mStore.deleteStream( iStream ); | 132 | mStore.deleteStream( iStream ); |
133 | hId.erase( key ); | 133 | hId.erase( key ); |
134 | } | 134 | } |
135 | 135 | ||
136 | virtual bool has( const keytype &key ) | 136 | virtual bool has( const keytype &key ) |
137 | { | 137 | { |
138 | return hId.has( key ); | 138 | return hId.has( key ); |
139 | } | 139 | } |
140 | 140 | ||
141 | virtual Bu::List<keytype> getKeys() | 141 | virtual Bu::List<keytype> getKeys() |
142 | { | 142 | { |
143 | return hId.getKeys(); | 143 | return hId.getKeys(); |
144 | } | 144 | } |
145 | 145 | ||
146 | virtual int getSize() | 146 | virtual int getSize() |
147 | { | 147 | { |
148 | return hId.getSize(); | 148 | return hId.getSize(); |
149 | } | 149 | } |
150 | 150 | ||
151 | private: | 151 | private: |
152 | Myriad mStore; | 152 | Myriad mStore; |
153 | typedef Bu::Hash<keytype, long> StreamHash; | 153 | typedef Bu::Hash<keytype, long> StreamHash; |
154 | StreamHash hId; | 154 | StreamHash hId; |
155 | }; | 155 | }; |
156 | }; | 156 | }; |
157 | 157 | ||
158 | #endif | 158 | #endif |
diff --git a/src/experimental/cipher.h b/src/experimental/cipher.h index 5d5cb07..6e58613 100644 --- a/src/experimental/cipher.h +++ b/src/experimental/cipher.h | |||
@@ -13,115 +13,115 @@ | |||
13 | 13 | ||
14 | namespace Bu | 14 | namespace Bu |
15 | { | 15 | { |
16 | template<int iBlockSize> | 16 | template<int iBlockSize> |
17 | class Cipher : public Bu::Filter | 17 | class Cipher : public Bu::Filter |
18 | { | 18 | { |
19 | public: | 19 | public: |
20 | Cipher( Bu::Stream &rNext ) : | 20 | Cipher( Bu::Stream &rNext ) : |
21 | Bu::Filter( rNext ), | 21 | Bu::Filter( rNext ), |
22 | iReadBufFill( 0 ), | 22 | iReadBufFill( 0 ), |
23 | iReadBufPos( 0 ), | 23 | iReadBufPos( 0 ), |
24 | iWriteBufFill( 0 ) | 24 | iWriteBufFill( 0 ) |
25 | { | 25 | { |
26 | } | 26 | } |
27 | 27 | ||
28 | virtual ~Cipher() | 28 | virtual ~Cipher() |
29 | { | 29 | { |
30 | } | 30 | } |
31 | 31 | ||
32 | virtual void start() | 32 | virtual void start() |
33 | { | 33 | { |
34 | } | 34 | } |
35 | 35 | ||
36 | virtual Bu::size stop() | 36 | virtual Bu::size stop() |
37 | { | 37 | { |
38 | flush(); | 38 | flush(); |
39 | return 0; | 39 | return 0; |
40 | } | 40 | } |
41 | 41 | ||
42 | virtual Bu::size read( void *pBuf, Bu::size iBytes ) | 42 | virtual Bu::size read( void *pBuf, Bu::size iBytes ) |
43 | { | 43 | { |
44 | Bu::size iRead = 0; | 44 | Bu::size iRead = 0; |
45 | while( iRead < iBytes ) | 45 | while( iRead < iBytes ) |
46 | { | 46 | { |
47 | if( iReadBufFill < iBlockSize ) | 47 | if( iReadBufFill < iBlockSize ) |
48 | { | 48 | { |
49 | int iR = rNext.read( | 49 | int iR = rNext.read( |
50 | aReadBuf+iReadBufFill, | 50 | aReadBuf+iReadBufFill, |
51 | iBlockSize-iReadBufFill | 51 | iBlockSize-iReadBufFill |
52 | ); | 52 | ); |
53 | if( iR == 0 ) | 53 | if( iR == 0 ) |
54 | return iRead; | 54 | return iRead; |
55 | 55 | ||
56 | iReadBufFill += iR; | 56 | iReadBufFill += iR; |
57 | 57 | ||
58 | if( iReadBufFill == iBlockSize ) | 58 | if( iReadBufFill == iBlockSize ) |
59 | decipher( aReadBuf ); | 59 | decipher( aReadBuf ); |
60 | } | 60 | } |
61 | 61 | ||
62 | if( iReadBufFill == iBlockSize ) | 62 | if( iReadBufFill == iBlockSize ) |
63 | { | 63 | { |
64 | int iCpy = Bu::buMin( (int)(iBytes-iRead), iBlockSize-iReadBufPos ); | 64 | int iCpy = Bu::buMin( (int)(iBytes-iRead), iBlockSize-iReadBufPos ); |
65 | memcpy( ((char *)pBuf)+iRead, aReadBuf+iReadBufPos, iCpy ); | 65 | memcpy( ((char *)pBuf)+iRead, aReadBuf+iReadBufPos, iCpy ); |
66 | iRead += iCpy; | 66 | iRead += iCpy; |
67 | iReadBufPos += iCpy; | 67 | iReadBufPos += iCpy; |
68 | if( iReadBufPos == iBlockSize ) | 68 | if( iReadBufPos == iBlockSize ) |
69 | { | 69 | { |
70 | iReadBufPos = iReadBufFill = 0; | 70 | iReadBufPos = iReadBufFill = 0; |
71 | } | 71 | } |
72 | } | 72 | } |
73 | } | 73 | } |
74 | 74 | ||
75 | return iRead; | 75 | return iRead; |
76 | } | 76 | } |
77 | 77 | ||
78 | virtual Bu::size write( const void *pBuf, Bu::size iBytes ) | 78 | virtual Bu::size write( const void *pBuf, Bu::size iBytes ) |
79 | { | 79 | { |
80 | Bu::size iPos = 0; | 80 | Bu::size iPos = 0; |
81 | 81 | ||
82 | while( iPos < iBytes ) | 82 | while( iPos < iBytes ) |
83 | { | 83 | { |
84 | int iLeft = Bu::buMin((int)(iBytes-iPos),iBlockSize-iWriteBufFill); | 84 | int iLeft = Bu::buMin((int)(iBytes-iPos),iBlockSize-iWriteBufFill); |
85 | memcpy( aWriteBuf+iWriteBufFill, (char *)pBuf+iPos, iLeft ); | 85 | memcpy( aWriteBuf+iWriteBufFill, (char *)pBuf+iPos, iLeft ); |
86 | iPos += iLeft; | 86 | iPos += iLeft; |
87 | iWriteBufFill += iLeft; | 87 | iWriteBufFill += iLeft; |
88 | if( iWriteBufFill == iBlockSize ) | 88 | if( iWriteBufFill == iBlockSize ) |
89 | { | 89 | { |
90 | encipher( aWriteBuf ); | 90 | encipher( aWriteBuf ); |
91 | rNext.write( aWriteBuf, iBlockSize ); | 91 | rNext.write( aWriteBuf, iBlockSize ); |
92 | iWriteBufFill = 0; | 92 | iWriteBufFill = 0; |
93 | } | 93 | } |
94 | } | 94 | } |
95 | 95 | ||
96 | return iPos; | 96 | return iPos; |
97 | } | 97 | } |
98 | 98 | ||
99 | virtual void flush() | 99 | virtual void flush() |
100 | { | 100 | { |
101 | if( iWriteBufFill > 0 && iWriteBufFill < iBlockSize ) | 101 | if( iWriteBufFill > 0 && iWriteBufFill < iBlockSize ) |
102 | { | 102 | { |
103 | memset( aWriteBuf+iWriteBufFill, 0, iBlockSize-iWriteBufFill ); | 103 | memset( aWriteBuf+iWriteBufFill, 0, iBlockSize-iWriteBufFill ); |
104 | encipher( aWriteBuf ); | 104 | encipher( aWriteBuf ); |
105 | rNext.write( aWriteBuf, iBlockSize ); | 105 | rNext.write( aWriteBuf, iBlockSize ); |
106 | iWriteBufFill = 0; | 106 | iWriteBufFill = 0; |
107 | } | 107 | } |
108 | rNext.flush(); | 108 | rNext.flush(); |
109 | } | 109 | } |
110 | 110 | ||
111 | using Bu::Stream::read; | 111 | using Bu::Stream::read; |
112 | using Bu::Stream::write; | 112 | using Bu::Stream::write; |
113 | 113 | ||
114 | protected: | 114 | protected: |
115 | virtual void encipher( void *pData )=0; | 115 | virtual void encipher( void *pData )=0; |
116 | virtual void decipher( void *pData )=0; | 116 | virtual void decipher( void *pData )=0; |
117 | 117 | ||
118 | private: | 118 | private: |
119 | char aReadBuf[iBlockSize]; | 119 | char aReadBuf[iBlockSize]; |
120 | char aWriteBuf[iBlockSize]; | 120 | char aWriteBuf[iBlockSize]; |
121 | int iReadBufFill; | 121 | int iReadBufFill; |
122 | int iReadBufPos; | 122 | int iReadBufPos; |
123 | int iWriteBufFill; | 123 | int iWriteBufFill; |
124 | }; | 124 | }; |
125 | }; | 125 | }; |
126 | 126 | ||
127 | #endif | 127 | #endif |
diff --git a/src/experimental/ciphermodecbc.h b/src/experimental/ciphermodecbc.h index 8fbf9f6..b06a972 100644 --- a/src/experimental/ciphermodecbc.h +++ b/src/experimental/ciphermodecbc.h | |||
@@ -6,49 +6,49 @@ | |||
6 | 6 | ||
7 | namespace Bu | 7 | namespace Bu |
8 | { | 8 | { |
9 | template<int iBlockSize, typename CipherType> | 9 | template<int iBlockSize, typename CipherType> |
10 | class CipherModeCbc : public CipherType | 10 | class CipherModeCbc : public CipherType |
11 | { | 11 | { |
12 | public: | 12 | public: |
13 | CipherModeCbc(class Stream &rNext ) : | 13 | CipherModeCbc(class Stream &rNext ) : |
14 | CipherType( rNext ), | 14 | CipherType( rNext ), |
15 | bStart( true ) | 15 | bStart( true ) |
16 | { | 16 | { |
17 | memset( aVector, 0, iBlockSize ); | 17 | memset( aVector, 0, iBlockSize ); |
18 | } | 18 | } |
19 | 19 | ||
20 | virtual ~CipherModeCbc() | 20 | virtual ~CipherModeCbc() |
21 | { | 21 | { |
22 | } | 22 | } |
23 | 23 | ||
24 | void setIv( const Bu::String &sIv ) | 24 | void setIv( const Bu::String &sIv ) |
25 | { | 25 | { |
26 | memcpy( aVector, sIv.getStr(), iBlockSize ); | 26 | memcpy( aVector, sIv.getStr(), iBlockSize ); |
27 | } | 27 | } |
28 | 28 | ||
29 | protected: | 29 | protected: |
30 | void decipher( void *pBuf ) | 30 | void decipher( void *pBuf ) |
31 | { | 31 | { |
32 | uint8_t aTmp[iBlockSize]; | 32 | uint8_t aTmp[iBlockSize]; |
33 | memcpy( aTmp, pBuf, iBlockSize ); | 33 | memcpy( aTmp, pBuf, iBlockSize ); |
34 | CipherType::decipher( pBuf ); | 34 | CipherType::decipher( pBuf ); |
35 | for( int j = 0; j < iBlockSize; j++ ) | 35 | for( int j = 0; j < iBlockSize; j++ ) |
36 | ((uint8_t *)pBuf)[j] ^= aVector[j]; | 36 | ((uint8_t *)pBuf)[j] ^= aVector[j]; |
37 | memcpy( aVector, aTmp, iBlockSize ); | 37 | memcpy( aVector, aTmp, iBlockSize ); |
38 | } | 38 | } |
39 | 39 | ||
40 | void encipher( void *pBuf ) | 40 | void encipher( void *pBuf ) |
41 | { | 41 | { |
42 | for( int j = 0; j < iBlockSize; j++ ) | 42 | for( int j = 0; j < iBlockSize; j++ ) |
43 | ((uint8_t *)pBuf)[j] ^= aVector[j]; | 43 | ((uint8_t *)pBuf)[j] ^= aVector[j]; |
44 | CipherType::encipher( pBuf ); | 44 | CipherType::encipher( pBuf ); |
45 | memcpy( aVector, pBuf, iBlockSize ); | 45 | memcpy( aVector, pBuf, iBlockSize ); |
46 | } | 46 | } |
47 | 47 | ||
48 | private: | 48 | private: |
49 | bool bStart; | 49 | bool bStart; |
50 | uint8_t aVector[iBlockSize]; | 50 | uint8_t aVector[iBlockSize]; |
51 | }; | 51 | }; |
52 | }; | 52 | }; |
53 | 53 | ||
54 | #endif | 54 | #endif |
diff --git a/src/experimental/ciphermodecfb.h b/src/experimental/ciphermodecfb.h index dab6c2e..34c682f 100644 --- a/src/experimental/ciphermodecfb.h +++ b/src/experimental/ciphermodecfb.h | |||
@@ -6,48 +6,48 @@ | |||
6 | 6 | ||
7 | namespace Bu | 7 | namespace Bu |
8 | { | 8 | { |
9 | template<int iBlockSize, typename CipherType> | 9 | template<int iBlockSize, typename CipherType> |
10 | class CipherModeCfb : public CipherType | 10 | class CipherModeCfb : public CipherType |
11 | { | 11 | { |
12 | public: | 12 | public: |
13 | CipherModeCfb(class Stream &rNext ) : | 13 | CipherModeCfb(class Stream &rNext ) : |
14 | CipherType( rNext ), | 14 | CipherType( rNext ), |
15 | bStart( true ) | 15 | bStart( true ) |
16 | { | 16 | { |
17 | memset( aVector, 0, iBlockSize ); | 17 | memset( aVector, 0, iBlockSize ); |
18 | } | 18 | } |
19 | 19 | ||
20 | virtual ~CipherModeCfb() | 20 | virtual ~CipherModeCfb() |
21 | { | 21 | { |
22 | } | 22 | } |
23 | 23 | ||
24 | void setIv( const Bu::String &sIv ) | 24 | void setIv( const Bu::String &sIv ) |
25 | { | 25 | { |
26 | memcpy( aVector, sIv.getStr(), iBlockSize ); | 26 | memcpy( aVector, sIv.getStr(), iBlockSize ); |
27 | } | 27 | } |
28 | 28 | ||
29 | protected: | 29 | protected: |
30 | void decipher( void *pBuf ) | 30 | void decipher( void *pBuf ) |
31 | { | 31 | { |
32 | uint8_t aTmp[iBlockSize]; | 32 | uint8_t aTmp[iBlockSize]; |
33 | memcpy( aTmp, pBuf, iBlockSize ); | 33 | memcpy( aTmp, pBuf, iBlockSize ); |
34 | CipherType::encipher( aVector ); | 34 | CipherType::encipher( aVector ); |
35 | for( int j = 0; j < iBlockSize; j++ ) | 35 | for( int j = 0; j < iBlockSize; j++ ) |
36 | ((uint8_t *)pBuf)[j] ^= aVector[j]; | 36 | ((uint8_t *)pBuf)[j] ^= aVector[j]; |
37 | memcpy( aVector, aTmp, iBlockSize ); | 37 | memcpy( aVector, aTmp, iBlockSize ); |
38 | } | 38 | } |
39 | 39 | ||
40 | void encipher( void *pBuf ) | 40 | void encipher( void *pBuf ) |
41 | { | 41 | { |
42 | CipherType::encipher( aVector ); | 42 | CipherType::encipher( aVector ); |
43 | for( int j = 0; j < iBlockSize; j++ ) | 43 | for( int j = 0; j < iBlockSize; j++ ) |
44 | aVector[j] = ((uint8_t *)pBuf)[j] ^= aVector[j]; | 44 | aVector[j] = ((uint8_t *)pBuf)[j] ^= aVector[j]; |
45 | } | 45 | } |
46 | 46 | ||
47 | private: | 47 | private: |
48 | bool bStart; | 48 | bool bStart; |
49 | uint8_t aVector[iBlockSize]; | 49 | uint8_t aVector[iBlockSize]; |
50 | }; | 50 | }; |
51 | }; | 51 | }; |
52 | 52 | ||
53 | #endif | 53 | #endif |
diff --git a/src/experimental/ciphermodeecb.h b/src/experimental/ciphermodeecb.h index 006741a..cac2beb 100644 --- a/src/experimental/ciphermodeecb.h +++ b/src/experimental/ciphermodeecb.h | |||
@@ -3,30 +3,30 @@ | |||
3 | 3 | ||
4 | namespace Bu | 4 | namespace Bu |
5 | { | 5 | { |
6 | template<int iBlockSize, typename CipherType> | 6 | template<int iBlockSize, typename CipherType> |
7 | class CipherModeEcb : public CipherType | 7 | class CipherModeEcb : public CipherType |
8 | { | 8 | { |
9 | public: | 9 | public: |
10 | CipherModeEcb( class Stream &rNext ) : | 10 | CipherModeEcb( class Stream &rNext ) : |
11 | CipherType( rNext ) | 11 | CipherType( rNext ) |
12 | { | 12 | { |
13 | } | 13 | } |
14 | 14 | ||
15 | virtual ~CipherModeEcb() | 15 | virtual ~CipherModeEcb() |
16 | { | 16 | { |
17 | } | 17 | } |
18 | 18 | ||
19 | protected: | 19 | protected: |
20 | virtual void decipher( void *pBuf ) | 20 | virtual void decipher( void *pBuf ) |
21 | { | 21 | { |
22 | CipherType::decipher( pBuf ); | 22 | CipherType::decipher( pBuf ); |
23 | } | 23 | } |
24 | 24 | ||
25 | virtual void encipher( void *pBuf ) | 25 | virtual void encipher( void *pBuf ) |
26 | { | 26 | { |
27 | CipherType::encipher( pBuf ); | 27 | CipherType::encipher( pBuf ); |
28 | } | 28 | } |
29 | }; | 29 | }; |
30 | }; | 30 | }; |
31 | 31 | ||
32 | #endif | 32 | #endif |
diff --git a/src/experimental/ciphermodeofb.h b/src/experimental/ciphermodeofb.h index 8c2aa20..e1b5108 100644 --- a/src/experimental/ciphermodeofb.h +++ b/src/experimental/ciphermodeofb.h | |||
@@ -6,51 +6,51 @@ | |||
6 | 6 | ||
7 | namespace Bu | 7 | namespace Bu |
8 | { | 8 | { |
9 | template<int iBlockSize, typename CipherType> | 9 | template<int iBlockSize, typename CipherType> |
10 | class CipherModeOfb : public CipherType | 10 | class CipherModeOfb : public CipherType |
11 | { | 11 | { |
12 | public: | 12 | public: |
13 | CipherModeOfb(class Stream &rNext ) : | 13 | CipherModeOfb(class Stream &rNext ) : |
14 | CipherType( rNext ), | 14 | CipherType( rNext ), |
15 | bStart( true ) | 15 | bStart( true ) |
16 | { | 16 | { |
17 | memset( aVector, 0, iBlockSize ); | 17 | memset( aVector, 0, iBlockSize ); |
18 | } | 18 | } |
19 | 19 | ||
20 | virtual ~CipherModeOfb() | 20 | virtual ~CipherModeOfb() |
21 | { | 21 | { |
22 | } | 22 | } |
23 | 23 | ||
24 | void setIv( const Bu::String &sIv ) | 24 | void setIv( const Bu::String &sIv ) |
25 | { | 25 | { |
26 | memcpy( aVector, sIv.getStr(), iBlockSize ); | 26 | memcpy( aVector, sIv.getStr(), iBlockSize ); |
27 | } | 27 | } |
28 | 28 | ||
29 | protected: | 29 | protected: |
30 | void decipher( void *pBuf ) | 30 | void decipher( void *pBuf ) |
31 | { | 31 | { |
32 | CipherType::encipher( aVector ); | 32 | CipherType::encipher( aVector ); |
33 | uint8_t aTmp[iBlockSize]; | 33 | uint8_t aTmp[iBlockSize]; |
34 | memcpy( aTmp, aVector, iBlockSize ); | 34 | memcpy( aTmp, aVector, iBlockSize ); |
35 | for( int j = 0; j < iBlockSize; j++ ) | 35 | for( int j = 0; j < iBlockSize; j++ ) |
36 | ((uint8_t *)pBuf)[j] ^= aVector[j]; | 36 | ((uint8_t *)pBuf)[j] ^= aVector[j]; |
37 | memcpy( aVector, aTmp, iBlockSize ); | 37 | memcpy( aVector, aTmp, iBlockSize ); |
38 | } | 38 | } |
39 | 39 | ||
40 | void encipher( void *pBuf ) | 40 | void encipher( void *pBuf ) |
41 | { | 41 | { |
42 | CipherType::encipher( aVector ); | 42 | CipherType::encipher( aVector ); |
43 | uint8_t aTmp[iBlockSize]; | 43 | uint8_t aTmp[iBlockSize]; |
44 | memcpy( aTmp, aVector, iBlockSize ); | 44 | memcpy( aTmp, aVector, iBlockSize ); |
45 | for( int j = 0; j < iBlockSize; j++ ) | 45 | for( int j = 0; j < iBlockSize; j++ ) |
46 | ((uint8_t *)pBuf)[j] ^= aVector[j]; | 46 | ((uint8_t *)pBuf)[j] ^= aVector[j]; |
47 | memcpy( aVector, aTmp, iBlockSize ); | 47 | memcpy( aVector, aTmp, iBlockSize ); |
48 | } | 48 | } |
49 | 49 | ||
50 | private: | 50 | private: |
51 | bool bStart; | 51 | bool bStart; |
52 | uint8_t aVector[iBlockSize]; | 52 | uint8_t aVector[iBlockSize]; |
53 | }; | 53 | }; |
54 | }; | 54 | }; |
55 | 55 | ||
56 | #endif | 56 | #endif |
diff --git a/src/experimental/dir.h b/src/experimental/dir.h index 8e885d1..9e518eb 100644 --- a/src/experimental/dir.h +++ b/src/experimental/dir.h | |||
@@ -6,15 +6,15 @@ | |||
6 | 6 | ||
7 | namespace Bu | 7 | namespace Bu |
8 | { | 8 | { |
9 | class Dir : public FileSystem | 9 | class Dir : public FileSystem |
10 | { | 10 | { |
11 | public: | 11 | public: |
12 | Dir(); | 12 | Dir(); |
13 | Dir( const Bu::String &sPath ); | 13 | Dir( const Bu::String &sPath ); |
14 | virtual ~Dir(); | 14 | virtual ~Dir(); |
15 | 15 | ||
16 | private: | 16 | private: |
17 | }; | 17 | }; |
18 | }; | 18 | }; |
19 | 19 | ||
20 | #endif | 20 | #endif |
diff --git a/src/experimental/fastcgi.cpp b/src/experimental/fastcgi.cpp index 7068fa8..71426b9 100644 --- a/src/experimental/fastcgi.cpp +++ b/src/experimental/fastcgi.cpp | |||
@@ -8,7 +8,7 @@ | |||
8 | #include "bu/fastcgi.h" | 8 | #include "bu/fastcgi.h" |
9 | 9 | ||
10 | #ifndef WIN32 | 10 | #ifndef WIN32 |
11 | #include <arpa/inet.h> | 11 | #include <arpa/inet.h> |
12 | #endif | 12 | #endif |
13 | 13 | ||
14 | #include <errno.h> | 14 | #include <errno.h> |
@@ -21,17 +21,17 @@ using Bu::sio; | |||
21 | using Bu::Fmt; | 21 | using Bu::Fmt; |
22 | 22 | ||
23 | Bu::FastCgi::FastCgi() : | 23 | Bu::FastCgi::FastCgi() : |
24 | pSrv( NULL ), | 24 | pSrv( NULL ), |
25 | bRunning( true ) | 25 | bRunning( true ) |
26 | { | 26 | { |
27 | pSrv = new Bu::TcpServerSocket( (Bu::TcpServerSocket::socket_t)STDIN_FILENO, false ); | 27 | pSrv = new Bu::TcpServerSocket( (Bu::TcpServerSocket::socket_t)STDIN_FILENO, false ); |
28 | } | 28 | } |
29 | 29 | ||
30 | Bu::FastCgi::FastCgi( int iPort ) : | 30 | Bu::FastCgi::FastCgi( int iPort ) : |
31 | pSrv( NULL ), | 31 | pSrv( NULL ), |
32 | bRunning( true ) | 32 | bRunning( true ) |
33 | { | 33 | { |
34 | pSrv = new Bu::TcpServerSocket( iPort ); | 34 | pSrv = new Bu::TcpServerSocket( iPort ); |
35 | } | 35 | } |
36 | 36 | ||
37 | Bu::FastCgi::~FastCgi() | 37 | Bu::FastCgi::~FastCgi() |
@@ -41,332 +41,332 @@ Bu::FastCgi::~FastCgi() | |||
41 | bool Bu::FastCgi::isEmbedded() | 41 | bool Bu::FastCgi::isEmbedded() |
42 | { | 42 | { |
43 | #ifndef WIN32 | 43 | #ifndef WIN32 |
44 | struct sockaddr name; | 44 | struct sockaddr name; |
45 | socklen_t namelen = sizeof(name); | 45 | socklen_t namelen = sizeof(name); |
46 | if( getpeername( STDIN_FILENO, &name, &namelen ) != 0 && | 46 | if( getpeername( STDIN_FILENO, &name, &namelen ) != 0 && |
47 | errno == ENOTCONN ) | 47 | errno == ENOTCONN ) |
48 | { | 48 | { |
49 | sio << "errno = " << errno << " (" << strerror( errno ) << ")" << | 49 | sio << "errno = " << errno << " (" << strerror( errno ) << ")" << |
50 | sio.nl; | 50 | sio.nl; |
51 | sio << "Socket found" << sio.nl; | 51 | sio << "Socket found" << sio.nl; |
52 | return true; | 52 | return true; |
53 | } | 53 | } |
54 | else | 54 | else |
55 | { | 55 | { |
56 | sio << "errno = " << errno << " (" << strerror( errno ) << ")" << | 56 | sio << "errno = " << errno << " (" << strerror( errno ) << ")" << |
57 | sio.nl; | 57 | sio.nl; |
58 | sio << "No socket detected, running in standalone mode" << sio.nl; | 58 | sio << "No socket detected, running in standalone mode" << sio.nl; |
59 | return false; | 59 | return false; |
60 | } | 60 | } |
61 | #else | 61 | #else |
62 | #warning Bu::FastCgi::isEmbedded IS A STUB for WIN32!!!! | 62 | #warning Bu::FastCgi::isEmbedded IS A STUB for WIN32!!!! |
63 | return false; | 63 | return false; |
64 | #endif | 64 | #endif |
65 | } | 65 | } |
66 | 66 | ||
67 | void Bu::FastCgi::read( Bu::TcpSocket &s, Bu::FastCgi::Record &r ) | 67 | void Bu::FastCgi::read( Bu::TcpSocket &s, Bu::FastCgi::Record &r ) |
68 | { | 68 | { |
69 | int iRead = s.read( &r, sizeof(Record) ); | 69 | int iRead = s.read( &r, sizeof(Record) ); |
70 | if( iRead != sizeof(Record) ) | 70 | if( iRead != sizeof(Record) ) |
71 | throw Bu::TcpSocketException("Hey, the size %d is wrong for Record. (%s)", | 71 | throw Bu::TcpSocketException("Hey, the size %d is wrong for Record. (%s)", |
72 | iRead, strerror( errno ) ); | 72 | iRead, strerror( errno ) ); |
73 | r.uRequestId = ntohs( r.uRequestId ); | 73 | r.uRequestId = ntohs( r.uRequestId ); |
74 | r.uContentLength = ntohs( r.uContentLength ); | 74 | r.uContentLength = ntohs( r.uContentLength ); |
75 | } | 75 | } |
76 | 76 | ||
77 | void Bu::FastCgi::write( Bu::TcpSocket &s, Bu::FastCgi::Record r ) | 77 | void Bu::FastCgi::write( Bu::TcpSocket &s, Bu::FastCgi::Record r ) |
78 | { | 78 | { |
79 | // sio << "Out -> " << r << sio.nl; | 79 | // sio << "Out -> " << r << sio.nl; |
80 | r.uRequestId = htons( r.uRequestId ); | 80 | r.uRequestId = htons( r.uRequestId ); |
81 | r.uContentLength = htons( r.uContentLength ); | 81 | r.uContentLength = htons( r.uContentLength ); |
82 | s.write( &r, sizeof(Record) ); | 82 | s.write( &r, sizeof(Record) ); |
83 | } | 83 | } |
84 | 84 | ||
85 | void Bu::FastCgi::read( Bu::TcpSocket &s, Bu::FastCgi::BeginRequestBody &b ) | 85 | void Bu::FastCgi::read( Bu::TcpSocket &s, Bu::FastCgi::BeginRequestBody &b ) |
86 | { | 86 | { |
87 | s.read( &b, sizeof(BeginRequestBody) ); | 87 | s.read( &b, sizeof(BeginRequestBody) ); |
88 | b.uRole = ntohs( b.uRole ); | 88 | b.uRole = ntohs( b.uRole ); |
89 | } | 89 | } |
90 | 90 | ||
91 | void Bu::FastCgi::write( Bu::TcpSocket &s, Bu::FastCgi::EndRequestBody b ) | 91 | void Bu::FastCgi::write( Bu::TcpSocket &s, Bu::FastCgi::EndRequestBody b ) |
92 | { | 92 | { |
93 | b.uStatus = htonl( b.uStatus ); | 93 | b.uStatus = htonl( b.uStatus ); |
94 | s.write( &b, sizeof(b) ); | 94 | s.write( &b, sizeof(b) ); |
95 | } | 95 | } |
96 | 96 | ||
97 | uint32_t Bu::FastCgi::readLen( Bu::TcpSocket &s, uint16_t &uRead ) | 97 | uint32_t Bu::FastCgi::readLen( Bu::TcpSocket &s, uint16_t &uRead ) |
98 | { | 98 | { |
99 | uint8_t uByte[4]; | 99 | uint8_t uByte[4]; |
100 | s.read( uByte, 1 ); | 100 | s.read( uByte, 1 ); |
101 | uRead++; | 101 | uRead++; |
102 | if( uByte[0] >> 7 == 0 ) | 102 | if( uByte[0] >> 7 == 0 ) |
103 | return uByte[0]; | 103 | return uByte[0]; |
104 | 104 | ||
105 | s.read( uByte+1, 3 ); | 105 | s.read( uByte+1, 3 ); |
106 | uRead += 3; | 106 | uRead += 3; |
107 | return ((uByte[0]&0x7f)<<24)|(uByte[1]<<16)|(uByte[2]<<8)|(uByte[3]); | 107 | return ((uByte[0]&0x7f)<<24)|(uByte[1]<<16)|(uByte[2]<<8)|(uByte[3]); |
108 | } | 108 | } |
109 | 109 | ||
110 | void Bu::FastCgi::readPair( Bu::TcpSocket &s, StrHash &hParams, uint16_t &uRead ) | 110 | void Bu::FastCgi::readPair( Bu::TcpSocket &s, StrHash &hParams, uint16_t &uRead ) |
111 | { | 111 | { |
112 | uint32_t uName = readLen( s, uRead ); | 112 | uint32_t uName = readLen( s, uRead ); |
113 | uint32_t uValue = readLen( s, uRead ); | 113 | uint32_t uValue = readLen( s, uRead ); |
114 | uRead += uName + uValue; | 114 | uRead += uName + uValue; |
115 | unsigned char *sName = new unsigned char[uName]; | 115 | unsigned char *sName = new unsigned char[uName]; |
116 | s.read( sName, uName ); | 116 | s.read( sName, uName ); |
117 | Bu::String fsName( (char *)sName, uName ); | 117 | Bu::String fsName( (char *)sName, uName ); |
118 | delete[] sName; | 118 | delete[] sName; |
119 | 119 | ||
120 | if( uValue > 0 ) | 120 | if( uValue > 0 ) |
121 | { | 121 | { |
122 | unsigned char *sValue = new unsigned char[uValue]; | 122 | unsigned char *sValue = new unsigned char[uValue]; |
123 | s.read( sValue, uValue ); | 123 | s.read( sValue, uValue ); |
124 | Bu::String fsValue( (char *)sValue, uValue ); | 124 | Bu::String fsValue( (char *)sValue, uValue ); |
125 | hParams.insert( fsName, fsValue ); | 125 | hParams.insert( fsName, fsValue ); |
126 | delete[] sValue; | 126 | delete[] sValue; |
127 | } | 127 | } |
128 | else | 128 | else |
129 | { | 129 | { |
130 | hParams.insert( fsName, "" ); | 130 | hParams.insert( fsName, "" ); |
131 | } | 131 | } |
132 | } | 132 | } |
133 | 133 | ||
134 | bool Bu::FastCgi::hasChannel( int iChan ) | 134 | bool Bu::FastCgi::hasChannel( int iChan ) |
135 | { | 135 | { |
136 | if( aChannel.getSize() < iChan ) | 136 | if( aChannel.getSize() < iChan ) |
137 | return false; | 137 | return false; |
138 | if( aChannel[iChan-1] == NULL ) | 138 | if( aChannel[iChan-1] == NULL ) |
139 | return false; | 139 | return false; |
140 | return true; | 140 | return true; |
141 | } | 141 | } |
142 | 142 | ||
143 | Bu::Formatter &Bu::operator<<( Bu::Formatter &f, const Bu::FastCgi::Record &r ) | 143 | Bu::Formatter &Bu::operator<<( Bu::Formatter &f, const Bu::FastCgi::Record &r ) |
144 | { | 144 | { |
145 | f << "[Ver=" << (uint32_t)r.uVersion << | 145 | f << "[Ver=" << (uint32_t)r.uVersion << |
146 | ", Type=" << (uint32_t)r.uType << | 146 | ", Type=" << (uint32_t)r.uType << |
147 | ", Req=" << (uint32_t)r.uRequestId << | 147 | ", Req=" << (uint32_t)r.uRequestId << |
148 | ", clen=" << (uint32_t)r.uContentLength << | 148 | ", clen=" << (uint32_t)r.uContentLength << |
149 | ", plen=" << (uint32_t)r.uPaddingLength << | 149 | ", plen=" << (uint32_t)r.uPaddingLength << |
150 | ", resv=" << (uint32_t)r.uReserved << | 150 | ", resv=" << (uint32_t)r.uReserved << |
151 | "]"; | 151 | "]"; |
152 | return f; | 152 | return f; |
153 | } | 153 | } |
154 | 154 | ||
155 | void Bu::FastCgi::run() | 155 | void Bu::FastCgi::run() |
156 | { | 156 | { |
157 | // sio << "sizeof(Bu::FastCgi::Record) = " << sizeof(Record) << sio.nl; | 157 | // sio << "sizeof(Bu::FastCgi::Record) = " << sizeof(Record) << sio.nl; |
158 | bRunning = true; | 158 | bRunning = true; |
159 | while( bRunning ) | 159 | while( bRunning ) |
160 | { | 160 | { |
161 | int iSock = pSrv->accept( 5 ); | 161 | int iSock = pSrv->accept( 5 ); |
162 | if( iSock < 0 ) | 162 | if( iSock < 0 ) |
163 | continue; | 163 | continue; |
164 | 164 | ||
165 | Bu::TcpSocket s( iSock ); | 165 | Bu::TcpSocket s( iSock ); |
166 | s.setBlocking( true ); | 166 | s.setBlocking( true ); |
167 | // sio << "Got connection, blocking? " << s.isBlocking() << sio.nl; | 167 | // sio << "Got connection, blocking? " << s.isBlocking() << sio.nl; |
168 | try | 168 | try |
169 | { | 169 | { |
170 | for(;;) | 170 | for(;;) |
171 | { | 171 | { |
172 | Record r; | 172 | Record r; |
173 | memset( &r, 0, sizeof(r) ); | 173 | memset( &r, 0, sizeof(r) ); |
174 | // try | 174 | // try |
175 | // { | 175 | // { |
176 | read( s, r ); | 176 | read( s, r ); |
177 | // } | 177 | // } |
178 | // catch( Bu::ExceptionBase &e ) | 178 | // catch( Bu::ExceptionBase &e ) |
179 | // { | 179 | // { |
180 | // sio << "Error: " << e.what() << ", " << s.isOpen() << | 180 | // sio << "Error: " << e.what() << ", " << s.isOpen() << |
181 | // sio.nl; | 181 | // sio.nl; |
182 | // continue; | 182 | // continue; |
183 | // } | 183 | // } |
184 | Channel *pChan = NULL; | 184 | Channel *pChan = NULL; |
185 | if( r.uRequestId > 0 ) | 185 | if( r.uRequestId > 0 ) |
186 | { | 186 | { |
187 | if( !hasChannel( r.uRequestId ) && | 187 | if( !hasChannel( r.uRequestId ) && |
188 | r.uType != typeBeginRequest ) | 188 | r.uType != typeBeginRequest ) |
189 | { | 189 | { |
190 | sio << "Error, stream data without stream." << sio.nl; | 190 | sio << "Error, stream data without stream." << sio.nl; |
191 | sio << r << sio.nl; | 191 | sio << r << sio.nl; |
192 | if( r.uContentLength > 0 ) | 192 | if( r.uContentLength > 0 ) |
193 | { | 193 | { |
194 | char *buf = new char[r.uContentLength]; | 194 | char *buf = new char[r.uContentLength]; |
195 | sio << " (read " << s.read( buf, r.uContentLength ) | 195 | sio << " (read " << s.read( buf, r.uContentLength ) |
196 | << "/" << r.uContentLength << "):" << sio.nl; | 196 | << "/" << r.uContentLength << "):" << sio.nl; |
197 | sio.write( buf, r.uContentLength ); | 197 | sio.write( buf, r.uContentLength ); |
198 | sio << sio.nl << sio.nl; | 198 | sio << sio.nl << sio.nl; |
199 | } | 199 | } |
200 | } | 200 | } |
201 | while( aChannel.getSize() < r.uRequestId ) | 201 | while( aChannel.getSize() < r.uRequestId ) |
202 | aChannel.append( NULL ); | 202 | aChannel.append( NULL ); |
203 | if( r.uRequestId > 0 ) | 203 | if( r.uRequestId > 0 ) |
204 | pChan = aChannel[r.uRequestId-1]; | 204 | pChan = aChannel[r.uRequestId-1]; |
205 | } | 205 | } |
206 | 206 | ||
207 | // sio << "Record (id=" << r.uRequestId << ", len=" << | 207 | // sio << "Record (id=" << r.uRequestId << ", len=" << |
208 | // r.uContentLength << ", pad=" << | 208 | // r.uContentLength << ", pad=" << |
209 | // (unsigned int)r.uPaddingLength << "): "; | 209 | // (unsigned int)r.uPaddingLength << "): "; |
210 | // fflush( stdout ); | 210 | // fflush( stdout ); |
211 | 211 | ||
212 | switch( (RequestType)r.uType ) | 212 | switch( (RequestType)r.uType ) |
213 | { | 213 | { |
214 | case typeBeginRequest: | 214 | case typeBeginRequest: |
215 | // sio << "Begin Request."; | 215 | // sio << "Begin Request."; |
216 | { | 216 | { |
217 | BeginRequestBody b; | 217 | BeginRequestBody b; |
218 | read( s, b ); | 218 | read( s, b ); |
219 | if( pChan != NULL ) | 219 | if( pChan != NULL ) |
220 | { | 220 | { |
221 | sio << "Error!!!" << sio.nl; | 221 | sio << "Error!!!" << sio.nl; |
222 | return; | 222 | return; |
223 | } | 223 | } |
224 | pChan = aChannel[r.uRequestId-1] = new Channel(); | 224 | pChan = aChannel[r.uRequestId-1] = new Channel(); |
225 | } | 225 | } |
226 | break; | 226 | break; |
227 | 227 | ||
228 | case typeParams: | 228 | case typeParams: |
229 | // sio << "Params."; | 229 | // sio << "Params."; |
230 | if( r.uContentLength == 0 ) | 230 | if( r.uContentLength == 0 ) |
231 | { | 231 | { |
232 | pChan->uFlags |= chflgParamsDone; | 232 | pChan->uFlags |= chflgParamsDone; |
233 | } | 233 | } |
234 | else | 234 | else |
235 | { | 235 | { |
236 | uint16_t uUsed = 0; | 236 | uint16_t uUsed = 0; |
237 | while( uUsed < r.uContentLength ) | 237 | while( uUsed < r.uContentLength ) |
238 | { | 238 | { |
239 | readPair( s, pChan->hParams, uUsed ); | 239 | readPair( s, pChan->hParams, uUsed ); |
240 | } | 240 | } |
241 | } | 241 | } |
242 | break; | 242 | break; |
243 | 243 | ||
244 | case typeStdIn: | 244 | case typeStdIn: |
245 | // sio << "StdIn."; | 245 | // sio << "StdIn."; |
246 | if( r.uContentLength == 0 ) | 246 | if( r.uContentLength == 0 ) |
247 | { | 247 | { |
248 | pChan->uFlags |= chflgStdInDone; | 248 | pChan->uFlags |= chflgStdInDone; |
249 | } | 249 | } |
250 | else | 250 | else |
251 | { | 251 | { |
252 | char *buf = new char[r.uContentLength]; | 252 | char *buf = new char[r.uContentLength]; |
253 | int iTotal = 0; | 253 | int iTotal = 0; |
254 | do | 254 | do |
255 | { | 255 | { |
256 | size_t iRead = s.read( | 256 | size_t iRead = s.read( |
257 | buf, r.uContentLength-iTotal ); | 257 | buf, r.uContentLength-iTotal ); |
258 | iTotal += iRead; | 258 | iTotal += iRead; |
259 | // sio << " (read " << iRead << " " << iTotal | 259 | // sio << " (read " << iRead << " " << iTotal |
260 | // << "/" << r.uContentLength << ")"; | 260 | // << "/" << r.uContentLength << ")"; |
261 | pChan->sStdIn.append( buf, iRead ); | 261 | pChan->sStdIn.append( buf, iRead ); |
262 | } while( iTotal < r.uContentLength ); | 262 | } while( iTotal < r.uContentLength ); |
263 | delete[] buf; | 263 | delete[] buf; |
264 | } | 264 | } |
265 | break; | 265 | break; |
266 | 266 | ||
267 | case typeData: | 267 | case typeData: |
268 | // sio << "Data."; | 268 | // sio << "Data."; |
269 | if( r.uContentLength == 0 ) | 269 | if( r.uContentLength == 0 ) |
270 | { | 270 | { |
271 | pChan->uFlags |= chflgDataDone; | 271 | pChan->uFlags |= chflgDataDone; |
272 | } | 272 | } |
273 | else | 273 | else |
274 | { | 274 | { |
275 | char *buf = new char[r.uContentLength]; | 275 | char *buf = new char[r.uContentLength]; |
276 | s.read( buf, r.uContentLength ); | 276 | s.read( buf, r.uContentLength ); |
277 | pChan->sData.append( buf, r.uContentLength ); | 277 | pChan->sData.append( buf, r.uContentLength ); |
278 | delete[] buf; | 278 | delete[] buf; |
279 | } | 279 | } |
280 | break; | 280 | break; |
281 | 281 | ||
282 | case typeStdOut: | 282 | case typeStdOut: |
283 | case typeStdErr: | 283 | case typeStdErr: |
284 | case typeEndRequest: | 284 | case typeEndRequest: |
285 | case typeAbortRequest: | 285 | case typeAbortRequest: |
286 | case typeGetValuesResult: | 286 | case typeGetValuesResult: |
287 | // sio << "Scary."; | 287 | // sio << "Scary."; |
288 | // ??? we shouldn't get these. | 288 | // ??? we shouldn't get these. |
289 | break; | 289 | break; |
290 | 290 | ||
291 | case typeGetValues: | 291 | case typeGetValues: |
292 | break; | 292 | break; |
293 | } | 293 | } |
294 | 294 | ||
295 | // sio << sio.nl; | 295 | // sio << sio.nl; |
296 | 296 | ||
297 | if( pChan ) | 297 | if( pChan ) |
298 | { | 298 | { |
299 | if( pChan->uFlags == chflgAllDone ) | 299 | if( pChan->uFlags == chflgAllDone ) |
300 | { | 300 | { |
301 | // sio << "All done, generating output." << sio.nl; | 301 | // sio << "All done, generating output." << sio.nl; |
302 | Bu::MemBuf mStdOut, mStdErr; | 302 | Bu::MemBuf mStdOut, mStdErr; |
303 | int iRet = onRequest( | 303 | int iRet = onRequest( |
304 | pChan->hParams, pChan->sStdIn, | 304 | pChan->hParams, pChan->sStdIn, |
305 | mStdOut, mStdErr | 305 | mStdOut, mStdErr |
306 | ); | 306 | ); |
307 | 307 | ||
308 | Bu::String &sStdOut = mStdOut.getString(); | 308 | Bu::String &sStdOut = mStdOut.getString(); |
309 | Bu::String &sStdErr = mStdErr.getString(); | 309 | Bu::String &sStdErr = mStdErr.getString(); |
310 | 310 | ||
311 | Record rOut; | 311 | Record rOut; |
312 | memset( &rOut, 0, sizeof(rOut) ); | 312 | memset( &rOut, 0, sizeof(rOut) ); |
313 | rOut.uVersion = 1; | 313 | rOut.uVersion = 1; |
314 | rOut.uRequestId = r.uRequestId; | 314 | rOut.uRequestId = r.uRequestId; |
315 | rOut.uPaddingLength = 0; | 315 | rOut.uPaddingLength = 0; |
316 | rOut.uType = typeStdOut; | 316 | rOut.uType = typeStdOut; |
317 | if( sStdOut.getSize() > 0 ) | 317 | if( sStdOut.getSize() > 0 ) |
318 | { | 318 | { |
319 | for( int iPos = 0; iPos < sStdOut.getSize(); | 319 | for( int iPos = 0; iPos < sStdOut.getSize(); |
320 | iPos += 65528 ) | 320 | iPos += 65528 ) |
321 | { | 321 | { |
322 | int iSize = sStdOut.getSize()-iPos; | 322 | int iSize = sStdOut.getSize()-iPos; |
323 | if( iSize > 65528 ) | 323 | if( iSize > 65528 ) |
324 | iSize = 65528; | 324 | iSize = 65528; |
325 | rOut.uContentLength = iSize; | 325 | rOut.uContentLength = iSize; |
326 | write( s, rOut ); | 326 | write( s, rOut ); |
327 | s.write( sStdOut.getStr()+iPos, iSize ); | 327 | s.write( sStdOut.getStr()+iPos, iSize ); |
328 | } | 328 | } |
329 | } | 329 | } |
330 | rOut.uContentLength = 0; | 330 | rOut.uContentLength = 0; |
331 | write( s, rOut ); | 331 | write( s, rOut ); |
332 | 332 | ||
333 | rOut.uType = typeStdErr; | 333 | rOut.uType = typeStdErr; |
334 | if( sStdErr.getSize() > 0 ) | 334 | if( sStdErr.getSize() > 0 ) |
335 | { | 335 | { |
336 | for( int iPos = 0; iPos < sStdErr.getSize(); | 336 | for( int iPos = 0; iPos < sStdErr.getSize(); |
337 | iPos += 65528 ) | 337 | iPos += 65528 ) |
338 | { | 338 | { |
339 | int iSize = sStdErr.getSize()-iPos; | 339 | int iSize = sStdErr.getSize()-iPos; |
340 | if( iSize > 65528 ) | 340 | if( iSize > 65528 ) |
341 | iSize = 65528; | 341 | iSize = 65528; |
342 | rOut.uContentLength = iSize; | 342 | rOut.uContentLength = iSize; |
343 | write( s, rOut ); | 343 | write( s, rOut ); |
344 | s.write( sStdErr.getStr()+iPos, iSize ); | 344 | s.write( sStdErr.getStr()+iPos, iSize ); |
345 | } | 345 | } |
346 | } | 346 | } |
347 | rOut.uContentLength = 0; | 347 | rOut.uContentLength = 0; |
348 | write( s, rOut ); | 348 | write( s, rOut ); |
349 | 349 | ||
350 | rOut.uType = typeEndRequest; | 350 | rOut.uType = typeEndRequest; |
351 | rOut.uContentLength = 8; | 351 | rOut.uContentLength = 8; |
352 | write( s, rOut ); | 352 | write( s, rOut ); |
353 | 353 | ||
354 | EndRequestBody b; | 354 | EndRequestBody b; |
355 | memset( &b, 0, sizeof(b) ); | 355 | memset( &b, 0, sizeof(b) ); |
356 | b.uStatus = iRet; | 356 | b.uStatus = iRet; |
357 | write( s, b ); | 357 | write( s, b ); |
358 | 358 | ||
359 | delete pChan; | 359 | delete pChan; |
360 | aChannel[r.uRequestId-1] = NULL; | 360 | aChannel[r.uRequestId-1] = NULL; |
361 | } | 361 | } |
362 | } | 362 | } |
363 | } | 363 | } |
364 | } | 364 | } |
365 | catch( Bu::TcpSocketException &e ) | 365 | catch( Bu::TcpSocketException &e ) |
366 | { | 366 | { |
367 | // sio << "Bu::SocketException: " << e.what() << sio.nl << | 367 | // sio << "Bu::SocketException: " << e.what() << sio.nl << |
368 | // "\tSocket open: " << s.isOpen() << sio.nl; | 368 | // "\tSocket open: " << s.isOpen() << sio.nl; |
369 | } | 369 | } |
370 | } | 370 | } |
371 | } | 371 | } |
372 | 372 | ||
diff --git a/src/experimental/fastcgi.h b/src/experimental/fastcgi.h index 63d975f..50b10f5 100644 --- a/src/experimental/fastcgi.h +++ b/src/experimental/fastcgi.h | |||
@@ -16,118 +16,118 @@ | |||
16 | 16 | ||
17 | namespace Bu | 17 | namespace Bu |
18 | { | 18 | { |
19 | class Stream; | 19 | class Stream; |
20 | 20 | ||
21 | class FastCgi | 21 | class FastCgi |
22 | { | 22 | { |
23 | public: | 23 | public: |
24 | FastCgi( int iPort ); | 24 | FastCgi( int iPort ); |
25 | FastCgi(); | 25 | FastCgi(); |
26 | virtual ~FastCgi(); | 26 | virtual ~FastCgi(); |
27 | 27 | ||
28 | static bool isEmbedded(); | 28 | static bool isEmbedded(); |
29 | 29 | ||
30 | typedef Bu::Hash<Bu::String, Bu::String> StrHash; | 30 | typedef Bu::Hash<Bu::String, Bu::String> StrHash; |
31 | enum RequestType | 31 | enum RequestType |
32 | { | 32 | { |
33 | typeBeginRequest = 1, | 33 | typeBeginRequest = 1, |
34 | typeAbortRequest = 2, | 34 | typeAbortRequest = 2, |
35 | typeEndRequest = 3, | 35 | typeEndRequest = 3, |
36 | typeParams = 4, | 36 | typeParams = 4, |
37 | typeStdIn = 5, | 37 | typeStdIn = 5, |
38 | typeStdOut = 6, | 38 | typeStdOut = 6, |
39 | typeStdErr = 7, | 39 | typeStdErr = 7, |
40 | typeData = 8, | 40 | typeData = 8, |
41 | typeGetValues = 9, | 41 | typeGetValues = 9, |
42 | typeGetValuesResult = 10 | 42 | typeGetValuesResult = 10 |
43 | }; | 43 | }; |
44 | 44 | ||
45 | enum Role | 45 | enum Role |
46 | { | 46 | { |
47 | roleResponder = 1, | 47 | roleResponder = 1, |
48 | roleAuthorizer = 2, | 48 | roleAuthorizer = 2, |
49 | roleFilter = 3 | 49 | roleFilter = 3 |
50 | }; | 50 | }; |
51 | 51 | ||
52 | enum Flags | 52 | enum Flags |
53 | { | 53 | { |
54 | flagsKeepConn = 1 | 54 | flagsKeepConn = 1 |
55 | }; | 55 | }; |
56 | 56 | ||
57 | enum Status | 57 | enum Status |
58 | { | 58 | { |
59 | statusRequestComplete = 0, | 59 | statusRequestComplete = 0, |
60 | statusCantMpxConn = 1, | 60 | statusCantMpxConn = 1, |
61 | statusOverloaded = 2, | 61 | statusOverloaded = 2, |
62 | statusUnknownRole = 3 | 62 | statusUnknownRole = 3 |
63 | }; | 63 | }; |
64 | 64 | ||
65 | typedef struct { | 65 | typedef struct { |
66 | uint8_t uVersion; | 66 | uint8_t uVersion; |
67 | uint8_t uType; | 67 | uint8_t uType; |
68 | uint16_t uRequestId; | 68 | uint16_t uRequestId; |
69 | uint16_t uContentLength; | 69 | uint16_t uContentLength; |
70 | uint8_t uPaddingLength; | 70 | uint8_t uPaddingLength; |
71 | uint8_t uReserved; | 71 | uint8_t uReserved; |
72 | } Record; | 72 | } Record; |
73 | 73 | ||
74 | typedef struct { | 74 | typedef struct { |
75 | uint16_t uRole; | 75 | uint16_t uRole; |
76 | uint8_t uFlags; | 76 | uint8_t uFlags; |
77 | uint8_t reserved[5]; | 77 | uint8_t reserved[5]; |
78 | } BeginRequestBody; | 78 | } BeginRequestBody; |
79 | 79 | ||
80 | typedef struct { | 80 | typedef struct { |
81 | uint32_t uStatus; | 81 | uint32_t uStatus; |
82 | uint8_t uProtocolStatus; | 82 | uint8_t uProtocolStatus; |
83 | uint8_t reserved[3]; | 83 | uint8_t reserved[3]; |
84 | } EndRequestBody; | 84 | } EndRequestBody; |
85 | 85 | ||
86 | typedef struct Channel { | 86 | typedef struct Channel { |
87 | Channel() : uFlags( 0 ) { } | 87 | Channel() : uFlags( 0 ) { } |
88 | StrHash hParams; | 88 | StrHash hParams; |
89 | Bu::String sStdIn; | 89 | Bu::String sStdIn; |
90 | Bu::String sData; | 90 | Bu::String sData; |
91 | uint8_t uFlags; | 91 | uint8_t uFlags; |
92 | } Channel; | 92 | } Channel; |
93 | 93 | ||
94 | enum ChannelFlags | 94 | enum ChannelFlags |
95 | { | 95 | { |
96 | chflgParamsDone = 0x01, | 96 | chflgParamsDone = 0x01, |
97 | chflgStdInDone = 0x02, | 97 | chflgStdInDone = 0x02, |
98 | chflgDataDone = 0x04, | 98 | chflgDataDone = 0x04, |
99 | 99 | ||
100 | chflgAllDone = 0x03 | 100 | chflgAllDone = 0x03 |
101 | }; | 101 | }; |
102 | 102 | ||
103 | virtual void run(); | 103 | virtual void run(); |
104 | 104 | ||
105 | void stopRunning() { bRunning = false; } | 105 | void stopRunning() { bRunning = false; } |
106 | 106 | ||
107 | virtual void onInit() { }; | 107 | virtual void onInit() { }; |
108 | virtual int onRequest( const StrHash &hParams, | 108 | virtual int onRequest( const StrHash &hParams, |
109 | const Bu::String &sStdIn, Bu::Stream &sStdOut, | 109 | const Bu::String &sStdIn, Bu::Stream &sStdOut, |
110 | Bu::Stream &sStdErr )=0; | 110 | Bu::Stream &sStdErr )=0; |
111 | virtual void onUninit() { }; | 111 | virtual void onUninit() { }; |
112 | 112 | ||
113 | private: | 113 | private: |
114 | void read( Bu::TcpSocket &s, Record &r ); | 114 | void read( Bu::TcpSocket &s, Record &r ); |
115 | void read( Bu::TcpSocket &s, BeginRequestBody &b ); | 115 | void read( Bu::TcpSocket &s, BeginRequestBody &b ); |
116 | uint32_t readLen( Bu::TcpSocket &s, uint16_t &uUsed ); | 116 | uint32_t readLen( Bu::TcpSocket &s, uint16_t &uUsed ); |
117 | void readPair( Bu::TcpSocket &s, StrHash &hParams, uint16_t &uUsed ); | 117 | void readPair( Bu::TcpSocket &s, StrHash &hParams, uint16_t &uUsed ); |
118 | 118 | ||
119 | void write( Bu::TcpSocket &s, Record r ); | 119 | void write( Bu::TcpSocket &s, Record r ); |
120 | void write( Bu::TcpSocket &s, EndRequestBody b ); | 120 | void write( Bu::TcpSocket &s, EndRequestBody b ); |
121 | 121 | ||
122 | bool hasChannel( int iChan ); | 122 | bool hasChannel( int iChan ); |
123 | 123 | ||
124 | private: | 124 | private: |
125 | Bu::TcpServerSocket *pSrv; | 125 | Bu::TcpServerSocket *pSrv; |
126 | bool bRunning; | 126 | bool bRunning; |
127 | Bu::Array<Channel *> aChannel; | 127 | Bu::Array<Channel *> aChannel; |
128 | }; | 128 | }; |
129 | 129 | ||
130 | Bu::Formatter &operator<<( Bu::Formatter &f, const Bu::FastCgi::Record &r ); | 130 | Bu::Formatter &operator<<( Bu::Formatter &f, const Bu::FastCgi::Record &r ); |
131 | }; | 131 | }; |
132 | 132 | ||
133 | #endif | 133 | #endif |
diff --git a/src/experimental/filesystem.h b/src/experimental/filesystem.h index 0c992a5..d25cb67 100644 --- a/src/experimental/filesystem.h +++ b/src/experimental/filesystem.h | |||
@@ -3,22 +3,22 @@ | |||
3 | 3 | ||
4 | namespace Bu | 4 | namespace Bu |
5 | { | 5 | { |
6 | /** | 6 | /** |
7 | * Represents an abstract baseclass for any file organization structure. | 7 | * Represents an abstract baseclass for any file organization structure. |
8 | * If you're looking for acessing a local filesystem, try Bu::Dir. This | 8 | * If you're looking for acessing a local filesystem, try Bu::Dir. This |
9 | * is used to make switching between different types of filesystems | 9 | * is used to make switching between different types of filesystems |
10 | * seamless. FileSystems could be anything that organizes and grants | 10 | * seamless. FileSystems could be anything that organizes and grants |
11 | * access to file data, local filesystems, FTP servers, zip or myriadfs | 11 | * access to file data, local filesystems, FTP servers, zip or myriadfs |
12 | * files, etc. | 12 | * files, etc. |
13 | */ | 13 | */ |
14 | class FileSystem | 14 | class FileSystem |
15 | { | 15 | { |
16 | public: | 16 | public: |
17 | FileSystem(); | 17 | FileSystem(); |
18 | virtual ~FileSystem(); | 18 | virtual ~FileSystem(); |
19 | 19 | ||
20 | 20 | ||
21 | }; | 21 | }; |
22 | }; | 22 | }; |
23 | 23 | ||
24 | #endif | 24 | #endif |
diff --git a/src/experimental/httpget.cpp b/src/experimental/httpget.cpp index 7a8a89a..70c722c 100644 --- a/src/experimental/httpget.cpp +++ b/src/experimental/httpget.cpp | |||
@@ -8,11 +8,11 @@ | |||
8 | #include "bu/httpget.h" | 8 | #include "bu/httpget.h" |
9 | 9 | ||
10 | Bu::HttpGet::HttpGet( const Bu::Url &uSrc, const Bu::String &sMethod ) : | 10 | Bu::HttpGet::HttpGet( const Bu::Url &uSrc, const Bu::String &sMethod ) : |
11 | uSrc( uSrc ), | 11 | uSrc( uSrc ), |
12 | sMethod( sMethod ), | 12 | sMethod( sMethod ), |
13 | sSrv( uSrc.getHost(), uSrc.getPort() ) | 13 | sSrv( uSrc.getHost(), uSrc.getPort() ) |
14 | { | 14 | { |
15 | sSrv.write( sMethod + " " + uSrc.getFullPath() + " HTTP/1.1\r\n" ); | 15 | sSrv.write( sMethod + " " + uSrc.getFullPath() + " HTTP/1.1\r\n" ); |
16 | } | 16 | } |
17 | 17 | ||
18 | Bu::HttpGet::~HttpGet() | 18 | Bu::HttpGet::~HttpGet() |
@@ -25,28 +25,28 @@ void Bu::HttpGet::close() | |||
25 | 25 | ||
26 | void Bu::HttpGet::get() | 26 | void Bu::HttpGet::get() |
27 | { | 27 | { |
28 | for( MimeHash::iterator i = hMimeOut.begin(); i; i++ ) | 28 | for( MimeHash::iterator i = hMimeOut.begin(); i; i++ ) |
29 | { | 29 | { |
30 | sSrv.write( i.getKey() + ": " + i.getValue() + "\r\n" ); | 30 | sSrv.write( i.getKey() + ": " + i.getValue() + "\r\n" ); |
31 | } | 31 | } |
32 | sSrv.write("\r\n", 2 ); | 32 | sSrv.write("\r\n", 2 ); |
33 | 33 | ||
34 | // sSrv.read( | 34 | // sSrv.read( |
35 | } | 35 | } |
36 | 36 | ||
37 | Bu::size Bu::HttpGet::read( void * /*pBuf*/, Bu::size /*nBytes*/ ) | 37 | Bu::size Bu::HttpGet::read( void * /*pBuf*/, Bu::size /*nBytes*/ ) |
38 | { | 38 | { |
39 | return 0; | 39 | return 0; |
40 | } | 40 | } |
41 | 41 | ||
42 | Bu::size Bu::HttpGet::write( const void * /*pBuf*/, Bu::size /*nBytes*/ ) | 42 | Bu::size Bu::HttpGet::write( const void * /*pBuf*/, Bu::size /*nBytes*/ ) |
43 | { | 43 | { |
44 | return 0; | 44 | return 0; |
45 | } | 45 | } |
46 | 46 | ||
47 | Bu::size Bu::HttpGet::tell() | 47 | Bu::size Bu::HttpGet::tell() |
48 | { | 48 | { |
49 | return 0; | 49 | return 0; |
50 | } | 50 | } |
51 | 51 | ||
52 | void Bu::HttpGet::seek( Bu::size ) | 52 | void Bu::HttpGet::seek( Bu::size ) |
@@ -63,12 +63,12 @@ void Bu::HttpGet::setPosEnd( Bu::size ) | |||
63 | 63 | ||
64 | bool Bu::HttpGet::isEos() | 64 | bool Bu::HttpGet::isEos() |
65 | { | 65 | { |
66 | return false; | 66 | return false; |
67 | } | 67 | } |
68 | 68 | ||
69 | bool Bu::HttpGet::isOpen() | 69 | bool Bu::HttpGet::isOpen() |
70 | { | 70 | { |
71 | return true; | 71 | return true; |
72 | } | 72 | } |
73 | 73 | ||
74 | void Bu::HttpGet::flush() | 74 | void Bu::HttpGet::flush() |
@@ -77,32 +77,32 @@ void Bu::HttpGet::flush() | |||
77 | 77 | ||
78 | bool Bu::HttpGet::canRead() | 78 | bool Bu::HttpGet::canRead() |
79 | { | 79 | { |
80 | return true; | 80 | return true; |
81 | } | 81 | } |
82 | 82 | ||
83 | bool Bu::HttpGet::canWrite() | 83 | bool Bu::HttpGet::canWrite() |
84 | { | 84 | { |
85 | return false; | 85 | return false; |
86 | } | 86 | } |
87 | 87 | ||
88 | bool Bu::HttpGet::isReadable() | 88 | bool Bu::HttpGet::isReadable() |
89 | { | 89 | { |
90 | return true; | 90 | return true; |
91 | } | 91 | } |
92 | 92 | ||
93 | bool Bu::HttpGet::isWritable() | 93 | bool Bu::HttpGet::isWritable() |
94 | { | 94 | { |
95 | return false; | 95 | return false; |
96 | } | 96 | } |
97 | 97 | ||
98 | bool Bu::HttpGet::isSeekable() | 98 | bool Bu::HttpGet::isSeekable() |
99 | { | 99 | { |
100 | return false; | 100 | return false; |
101 | } | 101 | } |
102 | 102 | ||
103 | bool Bu::HttpGet::isBlocking() | 103 | bool Bu::HttpGet::isBlocking() |
104 | { | 104 | { |
105 | return true; | 105 | return true; |
106 | } | 106 | } |
107 | 107 | ||
108 | void Bu::HttpGet::setBlocking( bool /*bBlocking*/ ) | 108 | void Bu::HttpGet::setBlocking( bool /*bBlocking*/ ) |
@@ -111,16 +111,16 @@ void Bu::HttpGet::setBlocking( bool /*bBlocking*/ ) | |||
111 | 111 | ||
112 | Bu::size Bu::HttpGet::getSize() const | 112 | Bu::size Bu::HttpGet::getSize() const |
113 | { | 113 | { |
114 | return 0; | 114 | return 0; |
115 | } | 115 | } |
116 | 116 | ||
117 | Bu::size Bu::HttpGet::getBlockSize() const | 117 | Bu::size Bu::HttpGet::getBlockSize() const |
118 | { | 118 | { |
119 | return 0; | 119 | return 0; |
120 | } | 120 | } |
121 | 121 | ||
122 | Bu::String Bu::HttpGet::getLocation() const | 122 | Bu::String Bu::HttpGet::getLocation() const |
123 | { | 123 | { |
124 | return uSrc.getUrl(); | 124 | return uSrc.getUrl(); |
125 | } | 125 | } |
126 | 126 | ||
diff --git a/src/experimental/httpget.h b/src/experimental/httpget.h index e8092e5..21e69d6 100644 --- a/src/experimental/httpget.h +++ b/src/experimental/httpget.h | |||
@@ -16,51 +16,51 @@ | |||
16 | 16 | ||
17 | namespace Bu | 17 | namespace Bu |
18 | { | 18 | { |
19 | class HttpGet : public Bu::Stream | 19 | class HttpGet : public Bu::Stream |
20 | { | 20 | { |
21 | public: | 21 | public: |
22 | HttpGet( const Bu::Url &uSrc, const Bu::String &sMethod="GET" ); | 22 | HttpGet( const Bu::Url &uSrc, const Bu::String &sMethod="GET" ); |
23 | virtual ~HttpGet(); | 23 | virtual ~HttpGet(); |
24 | 24 | ||
25 | void get(); | 25 | void get(); |
26 | 26 | ||
27 | // From Bu::Stream | 27 | // From Bu::Stream |
28 | virtual void close(); | 28 | virtual void close(); |
29 | virtual Bu::size read( void *pBuf, Bu::size nBytes ); | 29 | virtual Bu::size read( void *pBuf, Bu::size nBytes ); |
30 | virtual Bu::size write( const void *pBuf, Bu::size nBytes ); | 30 | virtual Bu::size write( const void *pBuf, Bu::size nBytes ); |
31 | using Stream::write; | 31 | using Stream::write; |
32 | 32 | ||
33 | virtual Bu::size tell(); | 33 | virtual Bu::size tell(); |
34 | virtual void seek( Bu::size offset ); | 34 | virtual void seek( Bu::size offset ); |
35 | virtual void setPos( Bu::size pos ); | 35 | virtual void setPos( Bu::size pos ); |
36 | virtual void setPosEnd( Bu::size pos ); | 36 | virtual void setPosEnd( Bu::size pos ); |
37 | virtual bool isEos(); | 37 | virtual bool isEos(); |
38 | virtual bool isOpen(); | 38 | virtual bool isOpen(); |
39 | 39 | ||
40 | virtual void flush(); | 40 | virtual void flush(); |
41 | 41 | ||
42 | virtual bool canRead(); | 42 | virtual bool canRead(); |
43 | virtual bool canWrite(); | 43 | virtual bool canWrite(); |
44 | 44 | ||
45 | virtual bool isReadable(); | 45 | virtual bool isReadable(); |
46 | virtual bool isWritable(); | 46 | virtual bool isWritable(); |
47 | virtual bool isSeekable(); | 47 | virtual bool isSeekable(); |
48 | 48 | ||
49 | virtual bool isBlocking(); | 49 | virtual bool isBlocking(); |
50 | virtual void setBlocking( bool bBlocking=true ); | 50 | virtual void setBlocking( bool bBlocking=true ); |
51 | 51 | ||
52 | virtual size getSize() const; | 52 | virtual size getSize() const; |
53 | virtual size getBlockSize() const; | 53 | virtual size getBlockSize() const; |
54 | virtual Bu::String getLocation() const; | 54 | virtual Bu::String getLocation() const; |
55 | 55 | ||
56 | private: | 56 | private: |
57 | Bu::Url uSrc; | 57 | Bu::Url uSrc; |
58 | Bu::String sMethod; | 58 | Bu::String sMethod; |
59 | Bu::TcpSocket sSrv; | 59 | Bu::TcpSocket sSrv; |
60 | typedef Bu::Hash<Bu::String,Bu::String> MimeHash; | 60 | typedef Bu::Hash<Bu::String,Bu::String> MimeHash; |
61 | MimeHash hMimeIn; | 61 | MimeHash hMimeIn; |
62 | MimeHash hMimeOut; | 62 | MimeHash hMimeOut; |
63 | }; | 63 | }; |
64 | }; | 64 | }; |
65 | 65 | ||
66 | #endif | 66 | #endif |
diff --git a/src/experimental/lexer.cpp b/src/experimental/lexer.cpp index 48ee017..ae95d09 100644 --- a/src/experimental/lexer.cpp +++ b/src/experimental/lexer.cpp | |||
@@ -18,23 +18,23 @@ Bu::Lexer::~Lexer() | |||
18 | } | 18 | } |
19 | 19 | ||
20 | Bu::Lexer::Token::Token() : | 20 | Bu::Lexer::Token::Token() : |
21 | iToken( -1 ) | 21 | iToken( -1 ) |
22 | { | 22 | { |
23 | } | 23 | } |
24 | 24 | ||
25 | Bu::Lexer::Token::Token( Bu::Lexer::TokenType iToken ) : | 25 | Bu::Lexer::Token::Token( Bu::Lexer::TokenType iToken ) : |
26 | iToken( iToken ) | 26 | iToken( iToken ) |
27 | { | 27 | { |
28 | } | 28 | } |
29 | 29 | ||
30 | Bu::String Bu::Lexer::tokenToString( const Bu::Lexer::Token &t ) | 30 | Bu::String Bu::Lexer::tokenToString( const Bu::Lexer::Token &t ) |
31 | { | 31 | { |
32 | Bu::MemBuf mb; | 32 | Bu::MemBuf mb; |
33 | Bu::Formatter f( mb ); | 33 | Bu::Formatter f( mb ); |
34 | f << "<" << t.iToken << ">"; | 34 | f << "<" << t.iToken << ">"; |
35 | if( t.vExtra.isSet() ) | 35 | if( t.vExtra.isSet() ) |
36 | f << " (" << t.vExtra << ")"; | 36 | f << " (" << t.vExtra << ")"; |
37 | 37 | ||
38 | return mb.getString(); | 38 | return mb.getString(); |
39 | } | 39 | } |
40 | 40 | ||
diff --git a/src/experimental/lexer.h b/src/experimental/lexer.h index 69f4106..273f3cf 100644 --- a/src/experimental/lexer.h +++ b/src/experimental/lexer.h | |||
@@ -12,47 +12,47 @@ | |||
12 | 12 | ||
13 | namespace Bu | 13 | namespace Bu |
14 | { | 14 | { |
15 | class Stream; | 15 | class Stream; |
16 | 16 | ||
17 | /** | 17 | /** |
18 | * The base class for creating a lexical analyzer. This is designed to work | 18 | * The base class for creating a lexical analyzer. This is designed to work |
19 | * in tandem with the Bu::Parser class, which uses this to tokenize textual | 19 | * in tandem with the Bu::Parser class, which uses this to tokenize textual |
20 | * input. It can be used by just about anything that cares about tokens | 20 | * input. It can be used by just about anything that cares about tokens |
21 | * more than raw input, though. | 21 | * more than raw input, though. |
22 | */ | 22 | */ |
23 | class Lexer | 23 | class Lexer |
24 | { | 24 | { |
25 | public: | 25 | public: |
26 | Lexer(); | 26 | Lexer(); |
27 | virtual ~Lexer(); | 27 | virtual ~Lexer(); |
28 | 28 | ||
29 | typedef int TokenType; | 29 | typedef int TokenType; |
30 | 30 | ||
31 | class Token | 31 | class Token |
32 | { | 32 | { |
33 | public: | 33 | public: |
34 | Token(); | 34 | Token(); |
35 | Token( TokenType iToken ); | 35 | Token( TokenType iToken ); |
36 | 36 | ||
37 | template<class t> | 37 | template<class t> |
38 | Token( TokenType iToken, const t &v ) : | 38 | Token( TokenType iToken, const t &v ) : |
39 | iToken( iToken )//, | 39 | iToken( iToken )//, |
40 | // vExtra( v ) | 40 | // vExtra( v ) |
41 | { | 41 | { |
42 | vExtra = v; | 42 | vExtra = v; |
43 | } | 43 | } |
44 | TokenType iToken; | 44 | TokenType iToken; |
45 | Bu::Variant vExtra; | 45 | Bu::Variant vExtra; |
46 | int iStartCol; | 46 | int iStartCol; |
47 | int iStartRow; | 47 | int iStartRow; |
48 | int iEndCol; | 48 | int iEndCol; |
49 | int iEndRow; | 49 | int iEndRow; |
50 | }; | 50 | }; |
51 | 51 | ||
52 | virtual Token *nextToken()=0; | 52 | virtual Token *nextToken()=0; |
53 | 53 | ||
54 | virtual Bu::String tokenToString( const Token &t ); | 54 | virtual Bu::String tokenToString( const Token &t ); |
55 | }; | 55 | }; |
56 | }; | 56 | }; |
57 | 57 | ||
58 | #endif | 58 | #endif |
diff --git a/src/experimental/parser.cpp b/src/experimental/parser.cpp index 9f10256..5d0d7eb 100644 --- a/src/experimental/parser.cpp +++ b/src/experimental/parser.cpp | |||
@@ -21,231 +21,231 @@ Bu::Parser::~Parser() | |||
21 | 21 | ||
22 | void Bu::Parser::pushLexer( Lexer *pLex ) | 22 | void Bu::Parser::pushLexer( Lexer *pLex ) |
23 | { | 23 | { |
24 | sLexer.push( pLex ); | 24 | sLexer.push( pLex ); |
25 | } | 25 | } |
26 | 26 | ||
27 | void Bu::Parser::popLexer() | 27 | void Bu::Parser::popLexer() |
28 | { | 28 | { |
29 | delete sLexer.peekPop(); | 29 | delete sLexer.peekPop(); |
30 | } | 30 | } |
31 | 31 | ||
32 | Lexer::Token *Bu::Parser::popToken() | 32 | Lexer::Token *Bu::Parser::popToken() |
33 | { | 33 | { |
34 | return sToken.peekPop(); | 34 | return sToken.peekPop(); |
35 | } | 35 | } |
36 | 36 | ||
37 | void Bu::Parser::pushToken( Lexer::Token *pTok ) | 37 | void Bu::Parser::pushToken( Lexer::Token *pTok ) |
38 | { | 38 | { |
39 | sToken.push( pTok ); | 39 | sToken.push( pTok ); |
40 | } | 40 | } |
41 | 41 | ||
42 | void Bu::Parser::parse() | 42 | void Bu::Parser::parse() |
43 | { | 43 | { |
44 | int iCurNt = iRootNonTerminal; | 44 | int iCurNt = iRootNonTerminal; |
45 | Lexer::Token *ptCur = sLexer.peek()->nextToken(); | 45 | Lexer::Token *ptCur = sLexer.peek()->nextToken(); |
46 | sio << "Token(a): " << sLexer.peek()->tokenToString( *ptCur ) << sio.nl; | 46 | sio << "Token(a): " << sLexer.peek()->tokenToString( *ptCur ) << sio.nl; |
47 | selectProduction( iCurNt, ptCur ); | 47 | selectProduction( iCurNt, ptCur ); |
48 | 48 | ||
49 | while( !sState.isEmpty() ) | 49 | while( !sState.isEmpty() ) |
50 | { | 50 | { |
51 | switch( (*sState.peek()).eType ) | 51 | switch( (*sState.peek()).eType ) |
52 | { | 52 | { |
53 | case State::typeTerminal: | 53 | case State::typeTerminal: |
54 | sio << "terminal: " << ptCur->iToken << " == " | 54 | sio << "terminal: " << ptCur->iToken << " == " |
55 | << (*sState.peek()).iIndex << sio.nl; | 55 | << (*sState.peek()).iIndex << sio.nl; |
56 | if( ptCur->iToken == (*sState.peek()).iIndex ) | 56 | if( ptCur->iToken == (*sState.peek()).iIndex ) |
57 | { | 57 | { |
58 | advanceState(); | 58 | advanceState(); |
59 | delete ptCur; | 59 | delete ptCur; |
60 | ptCur = sLexer.peek()->nextToken(); | 60 | ptCur = sLexer.peek()->nextToken(); |
61 | sio << "Token(b): " << sLexer.peek()->tokenToString( *ptCur ) << sio.nl; | 61 | sio << "Token(b): " << sLexer.peek()->tokenToString( *ptCur ) << sio.nl; |
62 | } | 62 | } |
63 | else | 63 | else |
64 | { | 64 | { |
65 | throw Bu::ExceptionBase("Error parsing code."); | 65 | throw Bu::ExceptionBase("Error parsing code."); |
66 | } | 66 | } |
67 | break; | 67 | break; |
68 | 68 | ||
69 | case State::typeTerminalPush: | 69 | case State::typeTerminalPush: |
70 | sio << "terminalpush: " << ptCur->iToken << " == " | 70 | sio << "terminalpush: " << ptCur->iToken << " == " |
71 | << (*sState.peek()).iIndex << sio.nl; | 71 | << (*sState.peek()).iIndex << sio.nl; |
72 | if( ptCur->iToken == (*sState.peek()).iIndex ) | 72 | if( ptCur->iToken == (*sState.peek()).iIndex ) |
73 | { | 73 | { |
74 | advanceState(); | 74 | advanceState(); |
75 | sToken.push( ptCur ); | 75 | sToken.push( ptCur ); |
76 | 76 | ||
77 | ptCur = sLexer.peek()->nextToken(); | 77 | ptCur = sLexer.peek()->nextToken(); |
78 | sio << "Token(c): " << sLexer.peek()->tokenToString( *ptCur ) << sio.nl; | 78 | sio << "Token(c): " << sLexer.peek()->tokenToString( *ptCur ) << sio.nl; |
79 | } | 79 | } |
80 | else | 80 | else |
81 | { | 81 | { |
82 | throw Bu::ExceptionBase("Error parsing code."); | 82 | throw Bu::ExceptionBase("Error parsing code."); |
83 | } | 83 | } |
84 | break; | 84 | break; |
85 | 85 | ||
86 | case State::typeNonTerminal: | 86 | case State::typeNonTerminal: |
87 | sio << "nonterminal: " << ptCur->iToken << " --> " | 87 | sio << "nonterminal: " << ptCur->iToken << " --> " |
88 | << (*sState.peek()).iIndex << sio.nl; | 88 | << (*sState.peek()).iIndex << sio.nl; |
89 | { | 89 | { |
90 | int iNt = (*sState.peek()).iIndex; | 90 | int iNt = (*sState.peek()).iIndex; |
91 | sio << "Current state: " << *sState.peek() << sio.nl; | 91 | sio << "Current state: " << *sState.peek() << sio.nl; |
92 | if( !selectProduction( iNt, ptCur ) ) | 92 | if( !selectProduction( iNt, ptCur ) ) |
93 | { | 93 | { |
94 | throw Bu::ExceptionBase("Error parsing code."); | 94 | throw Bu::ExceptionBase("Error parsing code."); |
95 | } | 95 | } |
96 | } | 96 | } |
97 | break; | 97 | break; |
98 | 98 | ||
99 | case State::typeReduction: | 99 | case State::typeReduction: |
100 | sio << "reduction" << sio.nl; | 100 | sio << "reduction" << sio.nl; |
101 | aReduction[(*sState.peek()).iIndex]( *this ); | 101 | aReduction[(*sState.peek()).iIndex]( *this ); |
102 | advanceState(); | 102 | advanceState(); |
103 | break; | 103 | break; |
104 | } | 104 | } |
105 | } | 105 | } |
106 | } | 106 | } |
107 | 107 | ||
108 | bool Bu::Parser::selectProduction( int iNt, Lexer::Token *ptCur ) | 108 | bool Bu::Parser::selectProduction( int iNt, Lexer::Token *ptCur ) |
109 | { | 109 | { |
110 | NonTerminal &nt = aNonTerminal[iNt]; | 110 | NonTerminal &nt = aNonTerminal[iNt]; |
111 | int j = 0; | 111 | int j = 0; |
112 | for( NonTerminal::ProductionList::iterator i = nt.lProduction.begin(); | 112 | for( NonTerminal::ProductionList::iterator i = nt.lProduction.begin(); |
113 | i; i++,j++ ) | 113 | i; i++,j++ ) |
114 | { | 114 | { |
115 | if( (*i).isEmpty() ) | 115 | if( (*i).isEmpty() ) |
116 | continue; | 116 | continue; |
117 | sio << "-->(Attempting production " << iNt << ":" << j << ": " | 117 | sio << "-->(Attempting production " << iNt << ":" << j << ": " |
118 | << (*i).first() << ")" << sio.nl; | 118 | << (*i).first() << ")" << sio.nl; |
119 | if( (*i).first().eType == State::typeTerminal || | 119 | if( (*i).first().eType == State::typeTerminal || |
120 | (*i).first().eType == State::typeTerminalPush ) | 120 | (*i).first().eType == State::typeTerminalPush ) |
121 | { | 121 | { |
122 | if( (*i).first().iIndex == ptCur->iToken ) | 122 | if( (*i).first().iIndex == ptCur->iToken ) |
123 | { | 123 | { |
124 | sState.push( (*i).begin() ); | 124 | sState.push( (*i).begin() ); |
125 | sio.incIndent(); | 125 | sio.incIndent(); |
126 | sio << "Pushing production " << j << " from nt " << iNt | 126 | sio << "Pushing production " << j << " from nt " << iNt |
127 | << sio.nl; | 127 | << sio.nl; |
128 | return true; | 128 | return true; |
129 | } | 129 | } |
130 | } | 130 | } |
131 | else if( (*i).first().eType == State::typeNonTerminal ) | 131 | else if( (*i).first().eType == State::typeNonTerminal ) |
132 | { | 132 | { |
133 | sState.push( (*i).begin() ); | 133 | sState.push( (*i).begin() ); |
134 | sio.incIndent(); | 134 | sio.incIndent(); |
135 | sio << "Pushing production " << j << " from nt " << iNt | 135 | sio << "Pushing production " << j << " from nt " << iNt |
136 | << " as test." << sio.nl; | 136 | << " as test." << sio.nl; |
137 | if( !selectProduction( (*i).first().iIndex, ptCur ) ) | 137 | if( !selectProduction( (*i).first().iIndex, ptCur ) ) |
138 | { | 138 | { |
139 | sio.decIndent(); | 139 | sio.decIndent(); |
140 | sState.pop(); | 140 | sState.pop(); |
141 | sio << "Production " << j << " from nt " << iNt | 141 | sio << "Production " << j << " from nt " << iNt |
142 | << " didn't work out." << sio.nl; | 142 | << " didn't work out." << sio.nl; |
143 | } | 143 | } |
144 | else | 144 | else |
145 | { | 145 | { |
146 | return true; | 146 | return true; |
147 | } | 147 | } |
148 | } | 148 | } |
149 | } | 149 | } |
150 | if( nt.bCanSkip ) | 150 | if( nt.bCanSkip ) |
151 | { | 151 | { |
152 | sio << "Nothing matches, skipping non-terminal." << sio.nl; | 152 | sio << "Nothing matches, skipping non-terminal." << sio.nl; |
153 | advanceState(); | 153 | advanceState(); |
154 | return true; | 154 | return true; |
155 | } | 155 | } |
156 | sio << "-->(Found nothing)" << sio.nl; | 156 | sio << "-->(Found nothing)" << sio.nl; |
157 | return false; | 157 | return false; |
158 | } | 158 | } |
159 | 159 | ||
160 | void Bu::Parser::advanceState() | 160 | void Bu::Parser::advanceState() |
161 | { | 161 | { |
162 | if( sState.isEmpty() ) | 162 | if( sState.isEmpty() ) |
163 | return; | 163 | return; |
164 | 164 | ||
165 | sState.peek()++; | 165 | sState.peek()++; |
166 | if( !sState.peek() ) | 166 | if( !sState.peek() ) |
167 | { | 167 | { |
168 | sio.decIndent(); | 168 | sio.decIndent(); |
169 | sState.pop(); | 169 | sState.pop(); |
170 | sio << "State advanced, End of production." << sio.nl; | 170 | sio << "State advanced, End of production." << sio.nl; |
171 | advanceState(); | 171 | advanceState(); |
172 | return; | 172 | return; |
173 | } | 173 | } |
174 | sio << "State advanced, now: " << *(sState.peek()) << sio.nl; | 174 | sio << "State advanced, now: " << *(sState.peek()) << sio.nl; |
175 | } | 175 | } |
176 | 176 | ||
177 | void Bu::Parser::setRootNonTerminal( int iRoot ) | 177 | void Bu::Parser::setRootNonTerminal( int iRoot ) |
178 | { | 178 | { |
179 | iRootNonTerminal = iRoot; | 179 | iRootNonTerminal = iRoot; |
180 | } | 180 | } |
181 | 181 | ||
182 | void Bu::Parser::setRootNonTerminal( const Bu::String &sRoot ) | 182 | void Bu::Parser::setRootNonTerminal( const Bu::String &sRoot ) |
183 | { | 183 | { |
184 | setRootNonTerminal( hNonTerminalName.get( sRoot ) ); | 184 | setRootNonTerminal( hNonTerminalName.get( sRoot ) ); |
185 | } | 185 | } |
186 | 186 | ||
187 | int Bu::Parser::addNonTerminal( const Bu::String &sName, NonTerminal &nt ) | 187 | int Bu::Parser::addNonTerminal( const Bu::String &sName, NonTerminal &nt ) |
188 | { | 188 | { |
189 | int iId = aNonTerminal.getSize(); | 189 | int iId = aNonTerminal.getSize(); |
190 | aNonTerminal.append( nt ); | 190 | aNonTerminal.append( nt ); |
191 | hNonTerminalName.insert( sName, iId ); | 191 | hNonTerminalName.insert( sName, iId ); |
192 | sio << "nt '" << sName << "' = " << iId << sio.nl; | 192 | sio << "nt '" << sName << "' = " << iId << sio.nl; |
193 | return iId; | 193 | return iId; |
194 | } | 194 | } |
195 | 195 | ||
196 | int Bu::Parser::addNonTerminal( const Bu::String &sName ) | 196 | int Bu::Parser::addNonTerminal( const Bu::String &sName ) |
197 | { | 197 | { |
198 | int iId = aNonTerminal.getSize(); | 198 | int iId = aNonTerminal.getSize(); |
199 | aNonTerminal.append( NonTerminal() ); | 199 | aNonTerminal.append( NonTerminal() ); |
200 | hNonTerminalName.insert( sName, iId ); | 200 | hNonTerminalName.insert( sName, iId ); |
201 | sio << "nt '" << sName << "' = " << iId << sio.nl; | 201 | sio << "nt '" << sName << "' = " << iId << sio.nl; |
202 | return iId; | 202 | return iId; |
203 | } | 203 | } |
204 | 204 | ||
205 | void Bu::Parser::setNonTerminal( const Bu::String &sName, NonTerminal &nt ) | 205 | void Bu::Parser::setNonTerminal( const Bu::String &sName, NonTerminal &nt ) |
206 | { | 206 | { |
207 | aNonTerminal[hNonTerminalName.get(sName)] = nt; | 207 | aNonTerminal[hNonTerminalName.get(sName)] = nt; |
208 | } | 208 | } |
209 | 209 | ||
210 | int Bu::Parser::getNonTerminalId( const Bu::String &sName ) | 210 | int Bu::Parser::getNonTerminalId( const Bu::String &sName ) |
211 | { | 211 | { |
212 | return hNonTerminalName.get( sName ); | 212 | return hNonTerminalName.get( sName ); |
213 | } | 213 | } |
214 | 214 | ||
215 | bool Bu::Parser::hasNonTerminal( const Bu::String &sName ) | 215 | bool Bu::Parser::hasNonTerminal( const Bu::String &sName ) |
216 | { | 216 | { |
217 | return hNonTerminalName.has( sName ); | 217 | return hNonTerminalName.has( sName ); |
218 | } | 218 | } |
219 | 219 | ||
220 | int Bu::Parser::addReduction( const Bu::String &sName, const Reduction &r ) | 220 | int Bu::Parser::addReduction( const Bu::String &sName, const Reduction &r ) |
221 | { | 221 | { |
222 | int iId = aReduction.getSize(); | 222 | int iId = aReduction.getSize(); |
223 | aReduction.append( r ); | 223 | aReduction.append( r ); |
224 | hReductionName.insert( sName, iId ); | 224 | hReductionName.insert( sName, iId ); |
225 | return iId; | 225 | return iId; |
226 | } | 226 | } |
227 | 227 | ||
228 | int Bu::Parser::addReduction( const Bu::String &sName ) | 228 | int Bu::Parser::addReduction( const Bu::String &sName ) |
229 | { | 229 | { |
230 | int iId = aReduction.getSize(); | 230 | int iId = aReduction.getSize(); |
231 | aReduction.append( Reduction() ); | 231 | aReduction.append( Reduction() ); |
232 | hReductionName.insert( sName, iId ); | 232 | hReductionName.insert( sName, iId ); |
233 | return iId; | 233 | return iId; |
234 | } | 234 | } |
235 | 235 | ||
236 | void Bu::Parser::setReduction( const Bu::String &sName, const Reduction &r ) | 236 | void Bu::Parser::setReduction( const Bu::String &sName, const Reduction &r ) |
237 | { | 237 | { |
238 | aReduction[hReductionName.get(sName)] = r; | 238 | aReduction[hReductionName.get(sName)] = r; |
239 | } | 239 | } |
240 | 240 | ||
241 | int Bu::Parser::getReductionId( const Bu::String &sName ) | 241 | int Bu::Parser::getReductionId( const Bu::String &sName ) |
242 | { | 242 | { |
243 | return hReductionName.get( sName ); | 243 | return hReductionName.get( sName ); |
244 | } | 244 | } |
245 | 245 | ||
246 | bool Bu::Parser::hasReduction( const Bu::String &sName ) | 246 | bool Bu::Parser::hasReduction( const Bu::String &sName ) |
247 | { | 247 | { |
248 | return hReductionName.has( sName ); | 248 | return hReductionName.has( sName ); |
249 | } | 249 | } |
250 | 250 | ||
251 | // | 251 | // |
@@ -253,8 +253,8 @@ bool Bu::Parser::hasReduction( const Bu::String &sName ) | |||
253 | // | 253 | // |
254 | 254 | ||
255 | Bu::Parser::State::State( Bu::Parser::State::Type eType, int iIndex ) : | 255 | Bu::Parser::State::State( Bu::Parser::State::Type eType, int iIndex ) : |
256 | eType( eType ), | 256 | eType( eType ), |
257 | iIndex( iIndex ) | 257 | iIndex( iIndex ) |
258 | { | 258 | { |
259 | } | 259 | } |
260 | 260 | ||
@@ -267,7 +267,7 @@ Bu::Parser::State::~State() | |||
267 | // | 267 | // |
268 | 268 | ||
269 | Bu::Parser::NonTerminal::NonTerminal() : | 269 | Bu::Parser::NonTerminal::NonTerminal() : |
270 | bCanSkip( false ) | 270 | bCanSkip( false ) |
271 | { | 271 | { |
272 | } | 272 | } |
273 | 273 | ||
@@ -277,35 +277,35 @@ Bu::Parser::NonTerminal::~NonTerminal() | |||
277 | 277 | ||
278 | void Bu::Parser::NonTerminal::addProduction( Production p ) | 278 | void Bu::Parser::NonTerminal::addProduction( Production p ) |
279 | { | 279 | { |
280 | lProduction.append( p ); | 280 | lProduction.append( p ); |
281 | } | 281 | } |
282 | 282 | ||
283 | void Bu::Parser::NonTerminal::setCanSkip() | 283 | void Bu::Parser::NonTerminal::setCanSkip() |
284 | { | 284 | { |
285 | bCanSkip = true; | 285 | bCanSkip = true; |
286 | } | 286 | } |
287 | 287 | ||
288 | Bu::Formatter &Bu::operator<<( Bu::Formatter &f, Bu::Parser::State::Type t ) | 288 | Bu::Formatter &Bu::operator<<( Bu::Formatter &f, Bu::Parser::State::Type t ) |
289 | { | 289 | { |
290 | switch( t ) | 290 | switch( t ) |
291 | { | 291 | { |
292 | case Bu::Parser::State::typeTerminal: | 292 | case Bu::Parser::State::typeTerminal: |
293 | return f << "typeTerminal"; | 293 | return f << "typeTerminal"; |
294 | 294 | ||
295 | case Bu::Parser::State::typeTerminalPush: | 295 | case Bu::Parser::State::typeTerminalPush: |
296 | return f << "typeTerminalPush"; | 296 | return f << "typeTerminalPush"; |
297 | 297 | ||
298 | case Bu::Parser::State::typeNonTerminal: | 298 | case Bu::Parser::State::typeNonTerminal: |
299 | return f << "typeNonTerminal"; | 299 | return f << "typeNonTerminal"; |
300 | 300 | ||
301 | case Bu::Parser::State::typeReduction: | 301 | case Bu::Parser::State::typeReduction: |
302 | return f << "typeReduction"; | 302 | return f << "typeReduction"; |
303 | } | 303 | } |
304 | return f << "***error***"; | 304 | return f << "***error***"; |
305 | } | 305 | } |
306 | 306 | ||
307 | Bu::Formatter &Bu::operator<<( Bu::Formatter &f, const Bu::Parser::State &s ) | 307 | Bu::Formatter &Bu::operator<<( Bu::Formatter &f, const Bu::Parser::State &s ) |
308 | { | 308 | { |
309 | return f << "{" << s.eType << ": " << s.iIndex << "}"; | 309 | return f << "{" << s.eType << ": " << s.iIndex << "}"; |
310 | } | 310 | } |
311 | 311 | ||
diff --git a/src/experimental/parser.h b/src/experimental/parser.h index 953202d..50b6afb 100644 --- a/src/experimental/parser.h +++ b/src/experimental/parser.h | |||
@@ -18,115 +18,115 @@ | |||
18 | 18 | ||
19 | namespace Bu | 19 | namespace Bu |
20 | { | 20 | { |
21 | /** | 21 | /** |
22 | * The base framework for a LR(1) grammar parser. Provided a proper set of | 22 | * The base framework for a LR(1) grammar parser. Provided a proper set of |
23 | * ParserStates this will prase any input the lexer can provide. | 23 | * ParserStates this will prase any input the lexer can provide. |
24 | */ | 24 | */ |
25 | class Parser | 25 | class Parser |
26 | { | 26 | { |
27 | public: | 27 | public: |
28 | Parser(); | 28 | Parser(); |
29 | virtual ~Parser(); | 29 | virtual ~Parser(); |
30 | 30 | ||
31 | /** | 31 | /** |
32 | * When a Lexer is pushed onto the stack it becomes the source for | 32 | * When a Lexer is pushed onto the stack it becomes the source for |
33 | * future tokens read by the parser until it is popped off the stack. | 33 | * future tokens read by the parser until it is popped off the stack. |
34 | * The Parser takes ownership of every Lexer pushed onto the stack, | 34 | * The Parser takes ownership of every Lexer pushed onto the stack, |
35 | * and will delete it when it is popped off the stack. | 35 | * and will delete it when it is popped off the stack. |
36 | */ | 36 | */ |
37 | void pushLexer( Lexer *pLex ); | 37 | void pushLexer( Lexer *pLex ); |
38 | 38 | ||
39 | /** | 39 | /** |
40 | * Pop a lexer off the stack, and delete it. | 40 | * Pop a lexer off the stack, and delete it. |
41 | */ | 41 | */ |
42 | void popLexer(); | 42 | void popLexer(); |
43 | 43 | ||
44 | Lexer::Token *popToken(); | 44 | Lexer::Token *popToken(); |
45 | void pushToken( Lexer::Token *pTok ); | 45 | void pushToken( Lexer::Token *pTok ); |
46 | 46 | ||
47 | /** | 47 | /** |
48 | * Execute a parse. | 48 | * Execute a parse. |
49 | */ | 49 | */ |
50 | void parse(); | 50 | void parse(); |
51 | 51 | ||
52 | void setRootNonTerminal( int iRoot ); | 52 | void setRootNonTerminal( int iRoot ); |
53 | void setRootNonTerminal( const Bu::String &sRoot ); | 53 | void setRootNonTerminal( const Bu::String &sRoot ); |
54 | 54 | ||
55 | typedef Bu::Signal1<void, Parser &> Reduction; | 55 | typedef Bu::Signal1<void, Parser &> Reduction; |
56 | 56 | ||
57 | /** | 57 | /** |
58 | * Represents a possible state, either a terminal or non-terminal symbol | 58 | * Represents a possible state, either a terminal or non-terminal symbol |
59 | * in a Production. | 59 | * in a Production. |
60 | */ | 60 | */ |
61 | class State | 61 | class State |
62 | { | 62 | { |
63 | public: | 63 | public: |
64 | enum Type | 64 | enum Type |
65 | { | 65 | { |
66 | typeTerminal, | 66 | typeTerminal, |
67 | typeTerminalPush, | 67 | typeTerminalPush, |
68 | typeNonTerminal, | 68 | typeNonTerminal, |
69 | typeReduction | 69 | typeReduction |
70 | }; | 70 | }; |
71 | 71 | ||
72 | State( Type eType, int iIndex ); | 72 | State( Type eType, int iIndex ); |
73 | virtual ~State(); | 73 | virtual ~State(); |
74 | 74 | ||
75 | //private: | 75 | //private: |
76 | Type eType; | 76 | Type eType; |
77 | int iIndex; | 77 | int iIndex; |
78 | }; | 78 | }; |
79 | 79 | ||
80 | typedef Bu::List<State> Production; | 80 | typedef Bu::List<State> Production; |
81 | 81 | ||
82 | class NonTerminal | 82 | class NonTerminal |
83 | { | 83 | { |
84 | public: | 84 | public: |
85 | NonTerminal(); | 85 | NonTerminal(); |
86 | virtual ~NonTerminal(); | 86 | virtual ~NonTerminal(); |
87 | 87 | ||
88 | void addProduction( Production p ); | 88 | void addProduction( Production p ); |
89 | void setCanSkip(); | 89 | void setCanSkip(); |
90 | 90 | ||
91 | // private: | 91 | // private: |
92 | typedef Bu::List<Production> ProductionList; | 92 | typedef Bu::List<Production> ProductionList; |
93 | ProductionList lProduction; | 93 | ProductionList lProduction; |
94 | bool bCanSkip; | 94 | bool bCanSkip; |
95 | }; | 95 | }; |
96 | 96 | ||
97 | int addNonTerminal( const Bu::String &sName, NonTerminal &nt ); | 97 | int addNonTerminal( const Bu::String &sName, NonTerminal &nt ); |
98 | int addNonTerminal( const Bu::String &sName ); | 98 | int addNonTerminal( const Bu::String &sName ); |
99 | void setNonTerminal( const Bu::String &sName, NonTerminal &nt ); | 99 | void setNonTerminal( const Bu::String &sName, NonTerminal &nt ); |
100 | int getNonTerminalId( const Bu::String &sName ); | 100 | int getNonTerminalId( const Bu::String &sName ); |
101 | bool hasNonTerminal( const Bu::String &sName ); | 101 | bool hasNonTerminal( const Bu::String &sName ); |
102 | 102 | ||
103 | int addReduction( const Bu::String &sName, const Reduction &r ); | 103 | int addReduction( const Bu::String &sName, const Reduction &r ); |
104 | int addReduction( const Bu::String &sName ); | 104 | int addReduction( const Bu::String &sName ); |
105 | void setReduction( const Bu::String &sName, const Reduction &r ); | 105 | void setReduction( const Bu::String &sName, const Reduction &r ); |
106 | int getReductionId( const Bu::String &sName ); | 106 | int getReductionId( const Bu::String &sName ); |
107 | bool hasReduction( const Bu::String &sName ); | 107 | bool hasReduction( const Bu::String &sName ); |
108 | 108 | ||
109 | private: | 109 | private: |
110 | bool selectProduction( int iNt, Lexer::Token *ptCur ); | 110 | bool selectProduction( int iNt, Lexer::Token *ptCur ); |
111 | void advanceState(); | 111 | void advanceState(); |
112 | 112 | ||
113 | private: | 113 | private: |
114 | typedef Bu::List<Lexer *> LexerStack; | 114 | typedef Bu::List<Lexer *> LexerStack; |
115 | typedef Bu::List<Lexer::Token *> TokenStack; | 115 | typedef Bu::List<Lexer::Token *> TokenStack; |
116 | typedef Bu::List<Production::const_iterator> StateStack; | 116 | typedef Bu::List<Production::const_iterator> StateStack; |
117 | typedef Bu::Array<Reduction> ReductionArray; | 117 | typedef Bu::Array<Reduction> ReductionArray; |
118 | typedef Bu::Hash<Bu::String,int> NameIndexHash; | 118 | typedef Bu::Hash<Bu::String,int> NameIndexHash; |
119 | typedef Bu::Array<NonTerminal> NonTerminalArray; | 119 | typedef Bu::Array<NonTerminal> NonTerminalArray; |
120 | 120 | ||
121 | LexerStack sLexer; | 121 | LexerStack sLexer; |
122 | TokenStack sToken; | 122 | TokenStack sToken; |
123 | StateStack sState; | 123 | StateStack sState; |
124 | ReductionArray aReduction; | 124 | ReductionArray aReduction; |
125 | NameIndexHash hReductionName; | 125 | NameIndexHash hReductionName; |
126 | NonTerminalArray aNonTerminal; | 126 | NonTerminalArray aNonTerminal; |
127 | NameIndexHash hNonTerminalName; | 127 | NameIndexHash hNonTerminalName; |
128 | int iRootNonTerminal; | 128 | int iRootNonTerminal; |
129 | }; | 129 | }; |
130 | Bu::Formatter &operator<<( Bu::Formatter &f, Bu::Parser::State::Type t ); | 130 | Bu::Formatter &operator<<( Bu::Formatter &f, Bu::Parser::State::Type t ); |
131 | Bu::Formatter &operator<<( Bu::Formatter &f, const Bu::Parser::State &s ); | 131 | Bu::Formatter &operator<<( Bu::Formatter &f, const Bu::Parser::State &s ); |
132 | }; | 132 | }; |
diff --git a/src/experimental/regex.cpp b/src/experimental/regex.cpp index de24935..dbe0e85 100644 --- a/src/experimental/regex.cpp +++ b/src/experimental/regex.cpp | |||
@@ -13,83 +13,83 @@ | |||
13 | #define aSubStr ((regmatch_t *)paSubStr) | 13 | #define aSubStr ((regmatch_t *)paSubStr) |
14 | 14 | ||
15 | Bu::RegEx::RegEx() : | 15 | Bu::RegEx::RegEx() : |
16 | pRegEx( NULL ), | 16 | pRegEx( NULL ), |
17 | bCompiled( false ), | 17 | bCompiled( false ), |
18 | paSubStr( NULL ) | 18 | paSubStr( NULL ) |
19 | { | 19 | { |
20 | } | 20 | } |
21 | 21 | ||
22 | Bu::RegEx::RegEx( const Bu::String &sSrc ) : | 22 | Bu::RegEx::RegEx( const Bu::String &sSrc ) : |
23 | pRegEx( NULL ), | 23 | pRegEx( NULL ), |
24 | bCompiled( false ), | 24 | bCompiled( false ), |
25 | paSubStr( NULL ) | 25 | paSubStr( NULL ) |
26 | { | 26 | { |
27 | compile( sSrc ); | 27 | compile( sSrc ); |
28 | } | 28 | } |
29 | 29 | ||
30 | Bu::RegEx::~RegEx() | 30 | Bu::RegEx::~RegEx() |
31 | { | 31 | { |
32 | if( bCompiled ) | 32 | if( bCompiled ) |
33 | { | 33 | { |
34 | regfree( re ); | 34 | regfree( re ); |
35 | delete re; | 35 | delete re; |
36 | delete[] aSubStr; | 36 | delete[] aSubStr; |
37 | } | 37 | } |
38 | } | 38 | } |
39 | 39 | ||
40 | void Bu::RegEx::compile( const Bu::String &sSrc ) | 40 | void Bu::RegEx::compile( const Bu::String &sSrc ) |
41 | { | 41 | { |
42 | if( bCompiled ) | 42 | if( bCompiled ) |
43 | { | 43 | { |
44 | regfree( re ); | 44 | regfree( re ); |
45 | delete re; | 45 | delete re; |
46 | delete[] aSubStr; | 46 | delete[] aSubStr; |
47 | bCompiled = false; | 47 | bCompiled = false; |
48 | } | 48 | } |
49 | pRegEx = (void *)(new regex_t); | 49 | pRegEx = (void *)(new regex_t); |
50 | 50 | ||
51 | int nErr = regcomp( re, sSrc.getStr(), REG_EXTENDED|REG_NEWLINE ); | 51 | int nErr = regcomp( re, sSrc.getStr(), REG_EXTENDED|REG_NEWLINE ); |
52 | if( nErr ) | 52 | if( nErr ) |
53 | { | 53 | { |
54 | size_t length = regerror( nErr, re, NULL, 0 ); | 54 | size_t length = regerror( nErr, re, NULL, 0 ); |
55 | char *buffer = new char[length]; | 55 | char *buffer = new char[length]; |
56 | (void) regerror( nErr, re, buffer, length ); | 56 | (void) regerror( nErr, re, buffer, length ); |
57 | Bu::String s( buffer ); | 57 | Bu::String s( buffer ); |
58 | delete[] buffer; | 58 | delete[] buffer; |
59 | throw "???"; // BuildException( s.getStr() ); | 59 | throw "???"; // BuildException( s.getStr() ); |
60 | } | 60 | } |
61 | bCompiled = true; | 61 | bCompiled = true; |
62 | this->sSrc = sSrc; | 62 | this->sSrc = sSrc; |
63 | 63 | ||
64 | nSubStr = re->re_nsub+1; | 64 | nSubStr = re->re_nsub+1; |
65 | paSubStr = (void *)(new regmatch_t[nSubStr]); | 65 | paSubStr = (void *)(new regmatch_t[nSubStr]); |
66 | } | 66 | } |
67 | 67 | ||
68 | int Bu::RegEx::getNumSubStrings() | 68 | int Bu::RegEx::getNumSubStrings() |
69 | { | 69 | { |
70 | return nSubStr; | 70 | return nSubStr; |
71 | } | 71 | } |
72 | 72 | ||
73 | bool Bu::RegEx::execute( const Bu::String &sSrc ) | 73 | bool Bu::RegEx::execute( const Bu::String &sSrc ) |
74 | { | 74 | { |
75 | sTest = sSrc; | 75 | sTest = sSrc; |
76 | if( regexec( re, sSrc.getStr(), nSubStr, aSubStr, 0 ) ) | 76 | if( regexec( re, sSrc.getStr(), nSubStr, aSubStr, 0 ) ) |
77 | return false; | 77 | return false; |
78 | return true; | 78 | return true; |
79 | } | 79 | } |
80 | 80 | ||
81 | void Bu::RegEx::getSubStringRange( int nIndex, int &iStart, int &iEnd ) | 81 | void Bu::RegEx::getSubStringRange( int nIndex, int &iStart, int &iEnd ) |
82 | { | 82 | { |
83 | iStart = aSubStr[nIndex].rm_so; | 83 | iStart = aSubStr[nIndex].rm_so; |
84 | iEnd = aSubStr[nIndex].rm_eo; | 84 | iEnd = aSubStr[nIndex].rm_eo; |
85 | } | 85 | } |
86 | 86 | ||
87 | Bu::String Bu::RegEx::getSubString( int nIndex ) | 87 | Bu::String Bu::RegEx::getSubString( int nIndex ) |
88 | { | 88 | { |
89 | // regmatch_t *Subs = aSubStr; | 89 | // regmatch_t *Subs = aSubStr; |
90 | return Bu::String( | 90 | return Bu::String( |
91 | sTest.getStr()+aSubStr[nIndex].rm_so, | 91 | sTest.getStr()+aSubStr[nIndex].rm_so, |
92 | aSubStr[nIndex].rm_eo - aSubStr[nIndex].rm_so | 92 | aSubStr[nIndex].rm_eo - aSubStr[nIndex].rm_so |
93 | ); | 93 | ); |
94 | } | 94 | } |
95 | 95 | ||
diff --git a/src/experimental/regex.h b/src/experimental/regex.h index c83ebe8..e723450 100644 --- a/src/experimental/regex.h +++ b/src/experimental/regex.h | |||
@@ -14,31 +14,31 @@ | |||
14 | 14 | ||
15 | namespace Bu | 15 | namespace Bu |
16 | { | 16 | { |
17 | class RegEx | 17 | class RegEx |
18 | { | 18 | { |
19 | public: | 19 | public: |
20 | RegEx(); | 20 | RegEx(); |
21 | RegEx( const Bu::String &sSrc ); | 21 | RegEx( const Bu::String &sSrc ); |
22 | virtual ~RegEx(); | 22 | virtual ~RegEx(); |
23 | 23 | ||
24 | void compile( const Bu::String &sSrc ); | 24 | void compile( const Bu::String &sSrc ); |
25 | int getNumSubStrings(); | 25 | int getNumSubStrings(); |
26 | bool execute( const Bu::String &sSrc ); | 26 | bool execute( const Bu::String &sSrc ); |
27 | void getSubStringRange( int nIndex, int &iStart, int &iEnd ); | 27 | void getSubStringRange( int nIndex, int &iStart, int &iEnd ); |
28 | Bu::String getSubString( int nIndex ); | 28 | Bu::String getSubString( int nIndex ); |
29 | const Bu::String &getSource() | 29 | const Bu::String &getSource() |
30 | { | 30 | { |
31 | return sSrc; | 31 | return sSrc; |
32 | } | 32 | } |
33 | 33 | ||
34 | private: | 34 | private: |
35 | Bu::String sSrc; | 35 | Bu::String sSrc; |
36 | Bu::String sTest; | 36 | Bu::String sTest; |
37 | void *pRegEx; | 37 | void *pRegEx; |
38 | bool bCompiled; | 38 | bool bCompiled; |
39 | int nSubStr; | 39 | int nSubStr; |
40 | void *paSubStr; | 40 | void *paSubStr; |
41 | }; | 41 | }; |
42 | }; | 42 | }; |
43 | 43 | ||
44 | #endif | 44 | #endif |
diff --git a/src/experimental/regexengine.h b/src/experimental/regexengine.h index ec181c1..133d418 100644 --- a/src/experimental/regexengine.h +++ b/src/experimental/regexengine.h | |||
@@ -7,136 +7,136 @@ | |||
7 | 7 | ||
8 | namespace Bu | 8 | namespace Bu |
9 | { | 9 | { |
10 | template<typename chr> class RegExEngine; | 10 | template<typename chr> class RegExEngine; |
11 | 11 | ||
12 | template<typename chr> | 12 | template<typename chr> |
13 | class RegExEngineCore | 13 | class RegExEngineCore |
14 | { | 14 | { |
15 | friend class RegExEngine<chr>; | 15 | friend class RegExEngine<chr>; |
16 | friend class SharedCore<RegExEngine<chr>, RegExEngineCore<chr> >; | 16 | friend class SharedCore<RegExEngine<chr>, RegExEngineCore<chr> >; |
17 | private: | 17 | private: |
18 | RegExEngineCore() | 18 | RegExEngineCore() |
19 | { | 19 | { |
20 | } | 20 | } |
21 | 21 | ||
22 | virtual ~RegExEngineCore() | 22 | virtual ~RegExEngineCore() |
23 | { | 23 | { |
24 | } | 24 | } |
25 | 25 | ||
26 | class Range | 26 | class Range |
27 | { | 27 | { |
28 | public: | 28 | public: |
29 | Range( chr cLower, chr cUpper, int iTrgState ) : | 29 | Range( chr cLower, chr cUpper, int iTrgState ) : |
30 | cLower( cLower ), cUpper( cUpper ), iTrgState( iTrgState ) | 30 | cLower( cLower ), cUpper( cUpper ), iTrgState( iTrgState ) |
31 | { | 31 | { |
32 | } | 32 | } |
33 | 33 | ||
34 | chr cLower; | 34 | chr cLower; |
35 | chr cUpper; | 35 | chr cUpper; |
36 | int iTrgState; | 36 | int iTrgState; |
37 | }; | 37 | }; |
38 | 38 | ||
39 | class State | 39 | class State |
40 | { | 40 | { |
41 | public: | 41 | public: |
42 | Bu::Array<Range> aRange; | 42 | Bu::Array<Range> aRange; |
43 | }; | 43 | }; |
44 | 44 | ||
45 | int addState() | 45 | int addState() |
46 | { | 46 | { |
47 | aState.append( State() ); | 47 | aState.append( State() ); |
48 | return aState.getSize()-1; | 48 | return aState.getSize()-1; |
49 | } | 49 | } |
50 | 50 | ||
51 | void addCompletion( int iState, chr cLower, chr cUpper, int iTrgState ) | 51 | void addCompletion( int iState, chr cLower, chr cUpper, int iTrgState ) |
52 | { | 52 | { |
53 | aState[iState].aRange.append( Range( cLower, cUpper, iTrgState ) ); | 53 | aState[iState].aRange.append( Range( cLower, cUpper, iTrgState ) ); |
54 | } | 54 | } |
55 | 55 | ||
56 | template<typename str> | 56 | template<typename str> |
57 | bool match( const str &sIn, int &iSize, int &iCompletion ) | 57 | bool match( const str &sIn, int &iSize, int &iCompletion ) |
58 | { | 58 | { |
59 | bool bMatch; | 59 | bool bMatch; |
60 | int iState = 0; | 60 | int iState = 0; |
61 | iSize = 0; | 61 | iSize = 0; |
62 | for( typename str::const_iterator i = sIn.begin(); i; i++ ) | 62 | for( typename str::const_iterator i = sIn.begin(); i; i++ ) |
63 | { | 63 | { |
64 | Bu::sio << "Finding char " << *i << " in state " << iState | 64 | Bu::sio << "Finding char " << *i << " in state " << iState |
65 | << ":" << Bu::sio.nl; | 65 | << ":" << Bu::sio.nl; |
66 | bMatch = false; | 66 | bMatch = false; |
67 | for( typename Bu::Array<Range>::iterator j = | 67 | for( typename Bu::Array<Range>::iterator j = |
68 | aState[iState].aRange.begin(); j; j++ ) | 68 | aState[iState].aRange.begin(); j; j++ ) |
69 | { | 69 | { |
70 | Bu::sio << " Testing range " << (*j).cLower << " - " << (*j).cUpper << Bu::sio.nl; | 70 | Bu::sio << " Testing range " << (*j).cLower << " - " << (*j).cUpper << Bu::sio.nl; |
71 | if( *i >= (*j).cLower && *i <= (*j).cUpper ) | 71 | if( *i >= (*j).cLower && *i <= (*j).cUpper ) |
72 | { | 72 | { |
73 | iState = (*j).iTrgState; | 73 | iState = (*j).iTrgState; |
74 | bMatch = true; | 74 | bMatch = true; |
75 | iSize++; | 75 | iSize++; |
76 | if( iState < 0 ) | 76 | if( iState < 0 ) |
77 | { | 77 | { |
78 | iCompletion = iState; | 78 | iCompletion = iState; |
79 | return true; | 79 | return true; |
80 | } | 80 | } |
81 | } | 81 | } |
82 | } | 82 | } |
83 | if( bMatch == false ) | 83 | if( bMatch == false ) |
84 | { | 84 | { |
85 | return false; | 85 | return false; |
86 | } | 86 | } |
87 | } | 87 | } |
88 | 88 | ||
89 | iCompletion = 0; | 89 | iCompletion = 0; |
90 | return true; | 90 | return true; |
91 | } | 91 | } |
92 | 92 | ||
93 | typedef Bu::Array<State> StateArray; | 93 | typedef Bu::Array<State> StateArray; |
94 | StateArray aState; | 94 | StateArray aState; |
95 | }; | 95 | }; |
96 | 96 | ||
97 | template<typename chr> | 97 | template<typename chr> |
98 | class RegExEngine : public SharedCore<RegExEngine<chr>, | 98 | class RegExEngine : public SharedCore<RegExEngine<chr>, |
99 | RegExEngineCore<chr> > | 99 | RegExEngineCore<chr> > |
100 | { | 100 | { |
101 | private: | 101 | private: |
102 | typedef class RegExEngine<chr> MyType; | 102 | typedef class RegExEngine<chr> MyType; |
103 | typedef class RegExEngineCore<chr> Core; | 103 | typedef class RegExEngineCore<chr> Core; |
104 | typedef class Core::Range Range; | 104 | typedef class Core::Range Range; |
105 | typedef class Core::State State; | 105 | typedef class Core::State State; |
106 | 106 | ||
107 | protected: | 107 | protected: |
108 | using SharedCore<MyType, Core>::core; | 108 | using SharedCore<MyType, Core>::core; |
109 | using SharedCore<MyType, Core>::_hardCopy; | 109 | using SharedCore<MyType, Core>::_hardCopy; |
110 | using SharedCore<MyType, Core>::_resetCore; | 110 | using SharedCore<MyType, Core>::_resetCore; |
111 | using SharedCore<MyType, Core>::_allocateCore; | 111 | using SharedCore<MyType, Core>::_allocateCore; |
112 | 112 | ||
113 | public: | 113 | public: |
114 | RegExEngine() | 114 | RegExEngine() |
115 | { | 115 | { |
116 | } | 116 | } |
117 | 117 | ||
118 | virtual ~RegExEngine() | 118 | virtual ~RegExEngine() |
119 | { | 119 | { |
120 | } | 120 | } |
121 | 121 | ||
122 | int addState() | 122 | int addState() |
123 | { | 123 | { |
124 | return core->addState(); | 124 | return core->addState(); |
125 | } | 125 | } |
126 | 126 | ||
127 | void addCompletion( int iState, chr cLower, chr cUpper, int iTrgState ) | 127 | void addCompletion( int iState, chr cLower, chr cUpper, int iTrgState ) |
128 | { | 128 | { |
129 | core->addCompletion( iState, cLower, cUpper, iTrgState ); | 129 | core->addCompletion( iState, cLower, cUpper, iTrgState ); |
130 | } | 130 | } |
131 | 131 | ||
132 | template<typename str> | 132 | template<typename str> |
133 | bool match( const str &sIn, int &iSize, int &iCompletion ) | 133 | bool match( const str &sIn, int &iSize, int &iCompletion ) |
134 | { | 134 | { |
135 | return core->match( sIn, iSize, iCompletion ); | 135 | return core->match( sIn, iSize, iCompletion ); |
136 | } | 136 | } |
137 | 137 | ||
138 | private: | 138 | private: |
139 | }; | 139 | }; |
140 | }; | 140 | }; |
141 | 141 | ||
142 | #endif | 142 | #endif |
diff --git a/src/experimental/xmlreader.cpp b/src/experimental/xmlreader.cpp index f11ac04..82f4684 100644 --- a/src/experimental/xmlreader.cpp +++ b/src/experimental/xmlreader.cpp | |||
@@ -11,13 +11,13 @@ | |||
11 | namespace Bu { subExceptionDef( XmlException ) } | 11 | namespace Bu { subExceptionDef( XmlException ) } |
12 | 12 | ||
13 | Bu::XmlReader::XmlReader( Stream &rInput ) : | 13 | Bu::XmlReader::XmlReader( Stream &rInput ) : |
14 | rInput( rInput ), | 14 | rInput( rInput ), |
15 | iCurToken( 0 ), | 15 | iCurToken( 0 ), |
16 | iNextToken( 0 ), | 16 | iNextToken( 0 ), |
17 | bIgnoreWS( true ) | 17 | bIgnoreWS( true ) |
18 | { | 18 | { |
19 | nextToken(); | 19 | nextToken(); |
20 | stDocument(); | 20 | stDocument(); |
21 | } | 21 | } |
22 | 22 | ||
23 | Bu::XmlReader::~XmlReader() | 23 | Bu::XmlReader::~XmlReader() |
@@ -26,148 +26,148 @@ Bu::XmlReader::~XmlReader() | |||
26 | 26 | ||
27 | void Bu::XmlReader::fillBuffer() | 27 | void Bu::XmlReader::fillBuffer() |
28 | { | 28 | { |
29 | if( rInput.isEos() ) | 29 | if( rInput.isEos() ) |
30 | return; | 30 | return; |
31 | char buf[1024]; | 31 | char buf[1024]; |
32 | int iSize = rInput.read( buf, 1024 ); | 32 | int iSize = rInput.read( buf, 1024 ); |
33 | sBuf.append( buf, iSize ); | 33 | sBuf.append( buf, iSize ); |
34 | } | 34 | } |
35 | 35 | ||
36 | void Bu::XmlReader::cleanupBuffer( int iUsed ) | 36 | void Bu::XmlReader::cleanupBuffer( int iUsed ) |
37 | { | 37 | { |
38 | for( int j = 0; j < iUsed; j++ ) | 38 | for( int j = 0; j < iUsed; j++ ) |
39 | { | 39 | { |
40 | if( sBuf[j] == '\n' ) | 40 | if( sBuf[j] == '\n' ) |
41 | { | 41 | { |
42 | spNextToken.iLine++; | 42 | spNextToken.iLine++; |
43 | spNextToken.iChar = 1; | 43 | spNextToken.iChar = 1; |
44 | } | 44 | } |
45 | else | 45 | else |
46 | { | 46 | { |
47 | spNextToken.iChar++; | 47 | spNextToken.iChar++; |
48 | } | 48 | } |
49 | } | 49 | } |
50 | 50 | ||
51 | printf("--Deleting %d bytes from front of buffer.\n", iUsed ); | 51 | printf("--Deleting %d bytes from front of buffer.\n", iUsed ); |
52 | sBuf.trimFront( iUsed ); | 52 | sBuf.trimFront( iUsed ); |
53 | } | 53 | } |
54 | 54 | ||
55 | int Bu::XmlReader::nextToken() | 55 | int Bu::XmlReader::nextToken() |
56 | { | 56 | { |
57 | fillBuffer(); | 57 | fillBuffer(); |
58 | 58 | ||
59 | int iUsed = 1; | 59 | int iUsed = 1; |
60 | 60 | ||
61 | iCurToken = iNextToken; | 61 | iCurToken = iNextToken; |
62 | spCurToken = spNextToken; | 62 | spCurToken = spNextToken; |
63 | 63 | ||
64 | switch( sBuf[0] ) | 64 | switch( sBuf[0] ) |
65 | { | 65 | { |
66 | case '<': | 66 | case '<': |
67 | if( !strncmp( sBuf.getStr(), "<?xml", 5 ) ) | 67 | if( !strncmp( sBuf.getStr(), "<?xml", 5 ) ) |
68 | { | 68 | { |
69 | iNextToken = tokXmlDeclHead; | 69 | iNextToken = tokXmlDeclHead; |
70 | iUsed = 5; | 70 | iUsed = 5; |
71 | } | 71 | } |
72 | else | 72 | else |
73 | { | 73 | { |
74 | iNextToken = '<'; | 74 | iNextToken = '<'; |
75 | } | 75 | } |
76 | break; | 76 | break; |
77 | 77 | ||
78 | case '?': | 78 | case '?': |
79 | if( sBuf[1] == '>' ) | 79 | if( sBuf[1] == '>' ) |
80 | { | 80 | { |
81 | iNextToken = tokXmlDeclEnd; | 81 | iNextToken = tokXmlDeclEnd; |
82 | iUsed = 2; | 82 | iUsed = 2; |
83 | } | 83 | } |
84 | else | 84 | else |
85 | { | 85 | { |
86 | iNextToken = '?'; | 86 | iNextToken = '?'; |
87 | } | 87 | } |
88 | break; | 88 | break; |
89 | 89 | ||
90 | case ' ': | 90 | case ' ': |
91 | case '\t': | 91 | case '\t': |
92 | case '\n': | 92 | case '\n': |
93 | case '\r': | 93 | case '\r': |
94 | for( int j = 1;; j++ ) | 94 | for( int j = 1;; j++ ) |
95 | { | 95 | { |
96 | if( j == sBuf.getSize() ) | 96 | if( j == sBuf.getSize() ) |
97 | { | 97 | { |
98 | if( rInput.isEos() ) | 98 | if( rInput.isEos() ) |
99 | error("Reached end of input while waiting for whitespace to end."); | 99 | error("Reached end of input while waiting for whitespace to end."); |
100 | 100 | ||
101 | fillBuffer(); | 101 | fillBuffer(); |
102 | } | 102 | } |
103 | if( sBuf[j] == ' ' || sBuf[j] == '\t' || | 103 | if( sBuf[j] == ' ' || sBuf[j] == '\t' || |
104 | sBuf[j] == '\n' || sBuf[j] == '\r' ) | 104 | sBuf[j] == '\n' || sBuf[j] == '\r' ) |
105 | iUsed++; | 105 | iUsed++; |
106 | else | 106 | else |
107 | break; | 107 | break; |
108 | } | 108 | } |
109 | sStr.clear(); | 109 | sStr.clear(); |
110 | sStr.append( sBuf, iUsed ); | 110 | sStr.append( sBuf, iUsed ); |
111 | iNextToken = tokWS; | 111 | iNextToken = tokWS; |
112 | break; | 112 | break; |
113 | 113 | ||
114 | case '=': | 114 | case '=': |
115 | iNextToken = sBuf[0]; | 115 | iNextToken = sBuf[0]; |
116 | break; | 116 | break; |
117 | 117 | ||
118 | default: | 118 | default: |
119 | if( (sBuf[0] >= 'a' && sBuf[0] <= 'z') || | 119 | if( (sBuf[0] >= 'a' && sBuf[0] <= 'z') || |
120 | (sBuf[0] >= 'A' && sBuf[0] <= 'Z') ) | 120 | (sBuf[0] >= 'A' && sBuf[0] <= 'Z') ) |
121 | { | 121 | { |
122 | for( int j = 1;; j++ ) | 122 | for( int j = 1;; j++ ) |
123 | { | 123 | { |
124 | if( j == sBuf.getSize() ) | 124 | if( j == sBuf.getSize() ) |
125 | { | 125 | { |
126 | if( rInput.isEos() ) | 126 | if( rInput.isEos() ) |
127 | error("Reached end of input while waiting for a string to end."); | 127 | error("Reached end of input while waiting for a string to end."); |
128 | 128 | ||
129 | fillBuffer(); | 129 | fillBuffer(); |
130 | } | 130 | } |
131 | if( (sBuf[j] >= 'a' && sBuf[j] <= 'z') || | 131 | if( (sBuf[j] >= 'a' && sBuf[j] <= 'z') || |
132 | (sBuf[j] >= 'A' && sBuf[j] <= 'Z') ) | 132 | (sBuf[j] >= 'A' && sBuf[j] <= 'Z') ) |
133 | iUsed++; | 133 | iUsed++; |
134 | else | 134 | else |
135 | break; | 135 | break; |
136 | } | 136 | } |
137 | sStr.clear(); | 137 | sStr.clear(); |
138 | sStr.append( sBuf, iUsed ); | 138 | sStr.append( sBuf, iUsed ); |
139 | iNextToken = tokIdent; | 139 | iNextToken = tokIdent; |
140 | } | 140 | } |
141 | } | 141 | } |
142 | 142 | ||
143 | cleanupBuffer( iUsed ); | 143 | cleanupBuffer( iUsed ); |
144 | 144 | ||
145 | return iCurToken; | 145 | return iCurToken; |
146 | } | 146 | } |
147 | 147 | ||
148 | void Bu::XmlReader::error( const char *sMessage ) | 148 | void Bu::XmlReader::error( const char *sMessage ) |
149 | { | 149 | { |
150 | throw Bu::XmlException("%d:%d: %s", | 150 | throw Bu::XmlException("%d:%d: %s", |
151 | spCurToken.iLine, spCurToken.iChar, sMessage ); | 151 | spCurToken.iLine, spCurToken.iChar, sMessage ); |
152 | } | 152 | } |
153 | 153 | ||
154 | void Bu::XmlReader::stDocument() | 154 | void Bu::XmlReader::stDocument() |
155 | { | 155 | { |
156 | stProlog(); | 156 | stProlog(); |
157 | } | 157 | } |
158 | 158 | ||
159 | void Bu::XmlReader::stProlog() | 159 | void Bu::XmlReader::stProlog() |
160 | { | 160 | { |
161 | stXmlDecl(); | 161 | stXmlDecl(); |
162 | } | 162 | } |
163 | 163 | ||
164 | void Bu::XmlReader::stXmlDecl() | 164 | void Bu::XmlReader::stXmlDecl() |
165 | { | 165 | { |
166 | if( nextToken() != tokXmlDeclHead ) | 166 | if( nextToken() != tokXmlDeclHead ) |
167 | error("You must begin your xml file with a declaration: <?xml ... ?>"); | 167 | error("You must begin your xml file with a declaration: <?xml ... ?>"); |
168 | if( nextToken() != tokIdent ) | 168 | if( nextToken() != tokIdent ) |
169 | error("A version comes first!"); | 169 | error("A version comes first!"); |
170 | if( sStr != "version" ) | 170 | if( sStr != "version" ) |
171 | error("No, a version!"); | 171 | error("No, a version!"); |
172 | } | 172 | } |
173 | 173 | ||
diff --git a/src/experimental/xmlreader.h b/src/experimental/xmlreader.h index d4bad1e..9615cfb 100644 --- a/src/experimental/xmlreader.h +++ b/src/experimental/xmlreader.h | |||
@@ -13,52 +13,52 @@ | |||
13 | 13 | ||
14 | namespace Bu | 14 | namespace Bu |
15 | { | 15 | { |
16 | class Stream; | 16 | class Stream; |
17 | 17 | ||
18 | subExceptionDecl( XmlException ); | 18 | subExceptionDecl( XmlException ); |
19 | 19 | ||
20 | class XmlReader | 20 | class XmlReader |
21 | { | 21 | { |
22 | public: | 22 | public: |
23 | XmlReader( Stream &rInput ); | 23 | XmlReader( Stream &rInput ); |
24 | virtual ~XmlReader(); | 24 | virtual ~XmlReader(); |
25 | 25 | ||
26 | private: | 26 | private: |
27 | Stream &rInput; | 27 | Stream &rInput; |
28 | int iCurToken; | 28 | int iCurToken; |
29 | int iNextToken; | 29 | int iNextToken; |
30 | Bu::String sBuf; | 30 | Bu::String sBuf; |
31 | Bu::String sStr; | 31 | Bu::String sStr; |
32 | bool bIgnoreWS; | 32 | bool bIgnoreWS; |
33 | typedef struct StreamPos | 33 | typedef struct StreamPos |
34 | { | 34 | { |
35 | StreamPos() : iLine( 1 ), iChar( 1 ) { } | 35 | StreamPos() : iLine( 1 ), iChar( 1 ) { } |
36 | int iLine; | 36 | int iLine; |
37 | int iChar; | 37 | int iChar; |
38 | } StreamPos; | 38 | } StreamPos; |
39 | StreamPos spCurToken; | 39 | StreamPos spCurToken; |
40 | StreamPos spNextToken; | 40 | StreamPos spNextToken; |
41 | 41 | ||
42 | 42 | ||
43 | enum | 43 | enum |
44 | { | 44 | { |
45 | tokXmlDeclHead = 0x100, | 45 | tokXmlDeclHead = 0x100, |
46 | tokXmlDeclEnd, | 46 | tokXmlDeclEnd, |
47 | tokWS, | 47 | tokWS, |
48 | tokIdent, | 48 | tokIdent, |
49 | tokString | 49 | tokString |
50 | }; | 50 | }; |
51 | 51 | ||
52 | void fillBuffer(); | 52 | void fillBuffer(); |
53 | void cleanupBuffer( int iUsed ); | 53 | void cleanupBuffer( int iUsed ); |
54 | int nextToken(); | 54 | int nextToken(); |
55 | 55 | ||
56 | void stDocument(); | 56 | void stDocument(); |
57 | void stProlog(); | 57 | void stProlog(); |
58 | void stXmlDecl(); | 58 | void stXmlDecl(); |
59 | 59 | ||
60 | void error( const char *sMessage ); | 60 | void error( const char *sMessage ); |
61 | }; | 61 | }; |
62 | }; | 62 | }; |
63 | 63 | ||
64 | #endif | 64 | #endif |