1 |
dev-zero 08/05/22 13:50:11 |
2 |
|
3 |
Added: xqilla-xercesc_regex.patch |
4 |
xqilla-xercesc_content_type.patch |
5 |
Log: |
6 |
Added xqilla USE-flag to apply patches and install additional header-files conditionally |
7 |
(Portage version: 2.1.5_rc7) |
8 |
|
9 |
Revision Changes Path |
10 |
1.1 dev-libs/xerces-c/files/xqilla-xercesc_regex.patch |
11 |
|
12 |
file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/dev-libs/xerces-c/files/xqilla-xercesc_regex.patch?rev=1.1&view=markup |
13 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/dev-libs/xerces-c/files/xqilla-xercesc_regex.patch?rev=1.1&content-type=text/plain |
14 |
|
15 |
Index: xqilla-xercesc_regex.patch |
16 |
=================================================================== |
17 |
diff -ru xerces-c-src_2_8_0-release/src/xercesc/util/regx/BMPattern.cpp xerces-c-src_2_8_0/src/xercesc/util/regx/BMPattern.cpp |
18 |
--- xerces-c-src_2_8_0-release/src/xercesc/util/regx/BMPattern.cpp 2007-08-28 19:44:32.000000000 +0100 |
19 |
+++ xerces-c-src_2_8_0/src/xercesc/util/regx/BMPattern.cpp 2008-01-29 17:28:41.000000000 +0000 |
20 |
@@ -99,7 +99,7 @@ |
21 |
// --------------------------------------------------------------------------- |
22 |
// BMPattern: matches methods |
23 |
// --------------------------------------------------------------------------- |
24 |
-int BMPattern::matches(const XMLCh* const content, int start, int limit) { |
25 |
+int BMPattern::matches(const XMLCh* const content, int start, int limit) const { |
26 |
|
27 |
const unsigned int patternLen = XMLString::stringLen(fPattern); |
28 |
// Uppercase Content |
29 |
diff -ru xerces-c-src_2_8_0-release/src/xercesc/util/regx/BMPattern.hpp xerces-c-src_2_8_0/src/xercesc/util/regx/BMPattern.hpp |
30 |
--- xerces-c-src_2_8_0-release/src/xercesc/util/regx/BMPattern.hpp 2007-08-28 19:44:32.000000000 +0100 |
31 |
+++ xerces-c-src_2_8_0/src/xercesc/util/regx/BMPattern.hpp 2008-01-29 17:28:34.000000000 +0000 |
32 |
@@ -99,7 +99,7 @@ |
33 |
* This method will perform a match of the given content against a |
34 |
* predefined pattern. |
35 |
*/ |
36 |
- int matches(const XMLCh* const content, int start, int limit); |
37 |
+ int matches(const XMLCh* const content, int start, int limit) const; |
38 |
|
39 |
//@} |
40 |
|
41 |
diff -ru xerces-c-src_2_8_0-release/src/xercesc/util/regx/RegularExpression.cpp xerces-c-src_2_8_0/src/xercesc/util/regx/RegularExpression.cpp |
42 |
--- xerces-c-src_2_8_0-release/src/xercesc/util/regx/RegularExpression.cpp 2007-08-28 19:44:32.000000000 +0100 |
43 |
+++ xerces-c-src_2_8_0/src/xercesc/util/regx/RegularExpression.cpp 2008-01-29 17:27:46.000000000 +0000 |
44 |
@@ -71,7 +71,7 @@ |
45 |
|
46 |
|
47 |
bool RegularExpression::matchIgnoreCase(const XMLInt32 ch1, |
48 |
- const XMLInt32 ch2) |
49 |
+ const XMLInt32 ch2) const |
50 |
{ |
51 |
if (ch1 >= 0x10000) |
52 |
{ |
53 |
@@ -132,6 +132,7 @@ |
54 |
, fOffsets(0) |
55 |
, fMatch(0) |
56 |
, fString(0) |
57 |
+ , fOptions(0) |
58 |
, fMemoryManager(manager) |
59 |
{ |
60 |
} |
61 |
@@ -146,6 +147,7 @@ |
62 |
, fOffsets(0) |
63 |
, fMatch(0) |
64 |
, fString(src->fString) |
65 |
+ , fOptions(src->fOptions) |
66 |
, fMemoryManager(src->fMemoryManager) |
67 |
{ |
68 |
if(src->fOffsets) |
69 |
@@ -169,6 +171,7 @@ |
70 |
fSize=other.fSize; |
71 |
fStringMaxLen=other.fStringMaxLen; |
72 |
fString=other.fString; |
73 |
+ fOptions=other.fOptions; |
74 |
if (fOffsets) |
75 |
fMemoryManager->deallocate(fOffsets);//delete [] fOffsets; |
76 |
fOffsets=0; |
77 |
@@ -208,7 +211,8 @@ |
78 |
, const int stringLen |
79 |
, const int start |
80 |
, const int limit |
81 |
- , const int noClosures) |
82 |
+ , const int noClosures |
83 |
+ , const unsigned int options) |
84 |
{ |
85 |
fString = string; |
86 |
fStringMaxLen = stringLen; |
87 |
@@ -227,6 +231,7 @@ |
88 |
} |
89 |
|
90 |
fSize = noClosures; |
91 |
+ fOptions = options; |
92 |
|
93 |
for (int i = 0; i< fSize; i++) |
94 |
fOffsets[i] = -1; |
95 |
@@ -456,7 +461,7 @@ |
96 |
// RegularExpression: Matching methods |
97 |
// --------------------------------------------------------------------------- |
98 |
bool RegularExpression::matches(const char* const expression |
99 |
- , MemoryManager* const manager) { |
100 |
+ , MemoryManager* const manager) const { |
101 |
|
102 |
XMLCh* tmpBuf = XMLString::transcode(expression, manager); |
103 |
ArrayJanitor<XMLCh> janBuf(tmpBuf, manager); |
104 |
@@ -465,7 +470,7 @@ |
105 |
|
106 |
bool RegularExpression::matches(const char* const expression, |
107 |
const int start, const int end |
108 |
- , MemoryManager* const manager) { |
109 |
+ , MemoryManager* const manager) const { |
110 |
|
111 |
XMLCh* tmpBuf = XMLString::transcode(expression, manager); |
112 |
ArrayJanitor<XMLCh> janBuf(tmpBuf, manager); |
113 |
@@ -474,7 +479,7 @@ |
114 |
|
115 |
bool RegularExpression::matches(const char* const expression, |
116 |
Match* const match |
117 |
- , MemoryManager* const manager) { |
118 |
+ , MemoryManager* const manager) const { |
119 |
|
120 |
XMLCh* tmpBuf = XMLString::transcode(expression, manager); |
121 |
ArrayJanitor<XMLCh> janBuf(tmpBuf, manager); |
122 |
@@ -483,7 +488,7 @@ |
123 |
|
124 |
bool RegularExpression::matches(const char* const expression, const int start, |
125 |
const int end, Match* const pMatch |
126 |
- , MemoryManager* const manager) { |
127 |
+ , MemoryManager* const manager) const { |
128 |
|
129 |
XMLCh* tmpBuf = XMLString::transcode(expression, manager); |
130 |
ArrayJanitor<XMLCh> janBuf(tmpBuf, manager); |
131 |
@@ -494,33 +499,34 @@ |
132 |
// --------------------------------------------------------------------------- |
133 |
// RegularExpression: Matching methods - Wide char version |
134 |
// --------------------------------------------------------------------------- |
135 |
-bool RegularExpression::matches(const XMLCh* const expression, MemoryManager* const manager) { |
136 |
+bool RegularExpression::matches(const XMLCh* const expression, MemoryManager* const manager) const { |
137 |
|
138 |
return matches(expression, 0, XMLString::stringLen(expression), 0, manager); |
139 |
} |
140 |
|
141 |
bool RegularExpression::matches(const XMLCh* const expression, |
142 |
const int start, const int end |
143 |
- , MemoryManager* const manager) { |
144 |
+ , MemoryManager* const manager) const { |
145 |
|
146 |
return matches(expression, start, end, 0, manager); |
147 |
} |
148 |
|
149 |
bool RegularExpression::matches(const XMLCh* const expression, |
150 |
Match* const match |
151 |
- , MemoryManager* const manager) { |
152 |
+ , MemoryManager* const manager) const { |
153 |
|
154 |
return matches(expression, 0, XMLString::stringLen(expression), match, manager); |
155 |
} |
156 |
|
157 |
bool RegularExpression::matches(const XMLCh* const expression, const int start, |
158 |
const int end, Match* const pMatch |
159 |
- , MemoryManager* const manager) { |
160 |
+ , MemoryManager* const manager) const |
161 |
+{ |
162 |
|
163 |
Context context(manager); |
164 |
int strLength = XMLString::stringLen(expression); |
165 |
|
166 |
- context.reset(expression, strLength, start, end, fNoClosures); |
167 |
+ context.reset(expression, strLength, start, end, fNoClosures, fOptions); |
168 |
|
169 |
bool adoptMatch = false; |
170 |
Match* lMatch = pMatch; |
171 |
@@ -530,7 +536,7 @@ |
172 |
} |
173 |
else if (fHasBackReferences) { |
174 |
|
175 |
- lMatch = new (fMemoryManager) Match(fMemoryManager); |
176 |
+ lMatch = new (manager) Match(manager); |
177 |
lMatch->setNoGroups(fNoGroups); |
178 |
adoptMatch = true; |
179 |
} |
180 |
@@ -681,19 +687,21 @@ |
181 |
// --------------------------------------------------------------------------- |
182 |
// RegularExpression: Tokenize methods |
183 |
// --------------------------------------------------------------------------- |
184 |
-RefArrayVectorOf<XMLCh>* RegularExpression::tokenize(const char* const expression) { |
185 |
+RefArrayVectorOf<XMLCh>* RegularExpression::tokenize(const char* const expression, |
186 |
+ MemoryManager* const manager) const { |
187 |
|
188 |
- XMLCh* tmpBuf = XMLString::transcode(expression, fMemoryManager); |
189 |
- ArrayJanitor<XMLCh> janBuf(tmpBuf, fMemoryManager); |
190 |
- return tokenize(tmpBuf, 0, XMLString::stringLen(tmpBuf)); |
191 |
+ XMLCh* tmpBuf = XMLString::transcode(expression, manager); |
192 |
+ ArrayJanitor<XMLCh> janBuf(tmpBuf, manager); |
193 |
+ return tokenize(tmpBuf, 0, XMLString::stringLen(tmpBuf), manager); |
194 |
} |
195 |
|
196 |
RefArrayVectorOf<XMLCh>* RegularExpression::tokenize(const char* const expression, |
197 |
- const int start, const int end) { |
198 |
+ const int start, const int end, |
199 |
+ MemoryManager* const manager) const { |
200 |
|
201 |
- XMLCh* tmpBuf = XMLString::transcode(expression, fMemoryManager); |
202 |
- ArrayJanitor<XMLCh> janBuf(tmpBuf, fMemoryManager); |
203 |
- return tokenize(tmpBuf, start, end); |
204 |
+ XMLCh* tmpBuf = XMLString::transcode(expression, manager); |
205 |
+ ArrayJanitor<XMLCh> janBuf(tmpBuf, manager); |
206 |
+ return tokenize(tmpBuf, start, end, manager); |
207 |
} |
208 |
|
209 |
|
210 |
@@ -701,125 +709,74 @@ |
211 |
// --------------------------------------------------------------------------- |
212 |
// RegularExpression: Tokenize methods - Wide char version |
213 |
// --------------------------------------------------------------------------- |
214 |
-RefArrayVectorOf<XMLCh>* RegularExpression::tokenize(const XMLCh* const expression) { |
215 |
- return tokenize(expression, 0, XMLString::stringLen(expression), 0); |
216 |
-} |
217 |
- |
218 |
RefArrayVectorOf<XMLCh>* RegularExpression::tokenize(const XMLCh* const expression, |
219 |
- const int start, const int end) |
220 |
-{ |
221 |
- return tokenize(expression, start, end, 0); |
222 |
+ MemoryManager* const manager) const { |
223 |
+ return tokenize(expression, 0, XMLString::stringLen(expression), manager); |
224 |
} |
225 |
|
226 |
-RefArrayVectorOf<XMLCh>* RegularExpression::tokenize(const XMLCh* const expression, |
227 |
+RefArrayVectorOf<XMLCh>* RegularExpression::tokenize(const XMLCh* const matchString, |
228 |
const int start, const int end, |
229 |
- RefVectorOf<Match> *subEx){ |
230 |
- |
231 |
- RefArrayVectorOf<XMLCh>* tokenStack = new (fMemoryManager) RefArrayVectorOf<XMLCh>(16, true, fMemoryManager); |
232 |
+ MemoryManager* const manager) const |
233 |
+{ |
234 |
+ // check if matches zero length string - throw error if so |
235 |
+ if(matches(XMLUni::fgZeroLenString, manager)){ |
236 |
+ ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_RepPatMatchesZeroString, manager); |
237 |
+ } |
238 |
+ |
239 |
+ RefVectorOf<Match> *subEx = new (manager) RefVectorOf<Match>(10, true, manager); |
240 |
+ Janitor<RefVectorOf<Match> > janSubEx(subEx); |
241 |
|
242 |
- Context context(fMemoryManager); |
243 |
+ allMatches(matchString, start, end, subEx, manager); |
244 |
|
245 |
- int strLength = XMLString::stringLen(expression); |
246 |
- |
247 |
- context.reset(expression, strLength, start, end, fNoClosures); |
248 |
- |
249 |
- |
250 |
- Match* lMatch = 0; |
251 |
- bool adoptMatch = false; |
252 |
- |
253 |
- if (subEx || fHasBackReferences) { |
254 |
- lMatch = new (fMemoryManager) Match(fMemoryManager); |
255 |
- adoptMatch = true; |
256 |
- lMatch->setNoGroups(fNoGroups); |
257 |
- } |
258 |
+ RefArrayVectorOf<XMLCh> *tokens = new (manager) RefArrayVectorOf<XMLCh>(16, true, manager); |
259 |
+ int tokStart = start; |
260 |
|
261 |
- if (context.fAdoptMatch) |
262 |
- delete context.fMatch; |
263 |
- |
264 |
- context.fMatch = lMatch; |
265 |
- context.fAdoptMatch = adoptMatch; |
266 |
+ unsigned int i = 0; |
267 |
+ for(; i < subEx->size(); ++i) { |
268 |
+ Match *match = subEx->elementAt(i); |
269 |
+ int matchStart = match->getStartPos(0); |
270 |
|
271 |
- int tokStart = start; |
272 |
- int matchStart = start; |
273 |
+ XMLCh *token = (XMLCh*)manager->allocate((matchStart + 1 - tokStart) * sizeof(XMLCh)); |
274 |
+ XMLString::subString(token, matchString, tokStart, matchStart, manager); |
275 |
+ tokens->addElement(token); |
276 |
|
277 |
- for (; matchStart <= end; matchStart++) { |
278 |
- |
279 |
- int matchEnd = match(&context, fOperations, matchStart, 1); |
280 |
- |
281 |
- if (matchEnd != -1) { |
282 |
+ tokStart = match->getEndPos(0); |
283 |
+ } |
284 |
|
285 |
- if (context.fMatch != 0) { |
286 |
- context.fMatch->setStartPos(0, context.fStart); |
287 |
- context.fMatch->setEndPos(0, matchEnd); |
288 |
- } |
289 |
- |
290 |
- if (subEx){ |
291 |
- subEx->addElement(context.fMatch); |
292 |
- lMatch = new (fMemoryManager) Match(*(context.fMatch)); |
293 |
- adoptMatch = true; |
294 |
- |
295 |
- context.fAdoptMatch = adoptMatch; |
296 |
- context.fMatch = lMatch; |
297 |
- } |
298 |
+ XMLCh *token = (XMLCh*)manager->allocate((end + 1 - tokStart) * sizeof(XMLCh)); |
299 |
+ XMLString::subString(token, matchString, tokStart, end, manager); |
300 |
+ tokens->addElement(token); |
301 |
|
302 |
- XMLCh* token; |
303 |
- if (tokStart == matchStart){ |
304 |
- |
305 |
- if (tokStart == strLength){ |
306 |
- tokStart--; |
307 |
- break; |
308 |
- } |
309 |
+ return tokens; |
310 |
+} |
311 |
|
312 |
- token = (XMLCh*) fMemoryManager->allocate(sizeof(XMLCh));//new XMLCh[1]; |
313 |
- token[0] = chNull; |
314 |
+void RegularExpression::allMatches(const XMLCh* const matchString, const int start, const int end, |
315 |
+ RefVectorOf<Match> *subEx, MemoryManager* const manager) const |
316 |
+{ |
317 |
+ Context context(manager); |
318 |
+ context.reset(matchString, XMLString::stringLen(matchString), start, end, fNoClosures, fOptions); |
319 |
|
320 |
- // When you tokenize using zero string, will return each |
321 |
- // token in the string. Since the zero string will also |
322 |
- // match the start/end characters, resulting in empty |
323 |
- // tokens, we ignore them and do not add them to the stack. |
324 |
- if (!XMLString::equals(fPattern, &chNull)) |
325 |
- tokenStack->addElement(token); |
326 |
- else |
327 |
- fMemoryManager->deallocate(token);//delete[] token; |
328 |
+ context.fMatch = new (manager) Match(manager); |
329 |
+ context.fMatch->setNoGroups(fNoGroups); |
330 |
+ context.fAdoptMatch = true; |
331 |
|
332 |
- } else { |
333 |
- token = (XMLCh*) fMemoryManager->allocate |
334 |
- ( |
335 |
- (matchStart + 1 - tokStart) * sizeof(XMLCh) |
336 |
- );//new XMLCh[matchStart + 1 - tokStart]; |
337 |
- XMLString::subString(token, expression, tokStart, matchStart, fMemoryManager); |
338 |
- tokenStack->addElement(token); |
339 |
- } |
340 |
- |
341 |
- tokStart = matchEnd; |
342 |
- |
343 |
- //decrement matchStart as will increment it at the top of the loop |
344 |
- if (matchStart < matchEnd - 1) |
345 |
- matchStart = matchEnd - 1; |
346 |
- } |
347 |
- } |
348 |
- |
349 |
- XMLCh* token; |
350 |
- |
351 |
- if (matchStart == tokStart + 1){ |
352 |
- token = (XMLCh*) fMemoryManager->allocate(sizeof(XMLCh));//new XMLCh[1]; |
353 |
- token[0] = chNull; |
354 |
- |
355 |
- } else { |
356 |
- token = (XMLCh*) fMemoryManager->allocate |
357 |
- ( |
358 |
- (strLength + 1 - tokStart) * sizeof(XMLCh) |
359 |
- );//new XMLCh[strLength + 1 - tokStart]; |
360 |
- XMLString::subString(token, expression, tokStart, strLength, fMemoryManager); |
361 |
- } |
362 |
- |
363 |
- if (!XMLString::equals(fPattern, &chNull)) |
364 |
- tokenStack->addElement(token); |
365 |
- else |
366 |
- fMemoryManager->deallocate(token);//delete[] token; |
367 |
+ int matchStart = start; |
368 |
+ while(matchStart <= end) { |
369 |
+ int matchEnd = match(&context, fOperations, matchStart, 1); |
370 |
+ if(matchEnd != -1) { |
371 |
+ context.fMatch->setStartPos(0, matchStart); |
372 |
+ context.fMatch->setEndPos(0, matchEnd); |
373 |
|
374 |
- return tokenStack; |
375 |
+ subEx->addElement(context.fMatch); |
376 |
+ |
377 |
+ context.fMatch = new (manager) Match(*(context.fMatch)); |
378 |
+ context.fAdoptMatch = true; |
379 |
|
380 |
+ matchStart = matchEnd; |
381 |
+ } else { |
382 |
+ ++matchStart; |
383 |
+ } |
384 |
+ } |
385 |
} |
386 |
|
387 |
|
388 |
@@ -827,26 +784,28 @@ |
389 |
// RegularExpression: Replace methods |
390 |
// ----------------------------------------------------------------------- |
391 |
XMLCh* RegularExpression::replace(const char* const matchString, |
392 |
- const char* const replaceString){ |
393 |
+ const char* const replaceString, |
394 |
+ MemoryManager* const manager) const { |
395 |
|
396 |
- XMLCh* tmpBuf = XMLString::transcode(matchString, fMemoryManager); |
397 |
- ArrayJanitor<XMLCh> janBuf(tmpBuf, fMemoryManager); |
398 |
- XMLCh* tmpBuf2 = XMLString::transcode(replaceString, fMemoryManager); |
399 |
- ArrayJanitor<XMLCh> janBuf2(tmpBuf2, fMemoryManager); |
400 |
+ XMLCh* tmpBuf = XMLString::transcode(matchString, manager); |
401 |
+ ArrayJanitor<XMLCh> janBuf(tmpBuf, manager); |
402 |
+ XMLCh* tmpBuf2 = XMLString::transcode(replaceString, manager); |
403 |
+ ArrayJanitor<XMLCh> janBuf2(tmpBuf2, manager); |
404 |
|
405 |
- return replace(tmpBuf, tmpBuf2, 0, XMLString::stringLen(tmpBuf)); |
406 |
+ return replace(tmpBuf, tmpBuf2, 0, XMLString::stringLen(tmpBuf), manager); |
407 |
} |
408 |
|
409 |
XMLCh* RegularExpression::replace(const char* const matchString, |
410 |
const char* const replaceString, |
411 |
- const int start, const int end){ |
412 |
+ const int start, const int end, |
413 |
+ MemoryManager* const manager) const { |
414 |
|
415 |
- XMLCh* tmpBuf = XMLString::transcode(matchString, fMemoryManager); |
416 |
- ArrayJanitor<XMLCh> janBuf(tmpBuf, fMemoryManager); |
417 |
- XMLCh* tmpBuf2 = XMLString::transcode(replaceString, fMemoryManager); |
418 |
- ArrayJanitor<XMLCh> janBuf2(tmpBuf2, fMemoryManager); |
419 |
+ XMLCh* tmpBuf = XMLString::transcode(matchString, manager); |
420 |
+ ArrayJanitor<XMLCh> janBuf(tmpBuf, manager); |
421 |
+ XMLCh* tmpBuf2 = XMLString::transcode(replaceString, manager); |
422 |
+ ArrayJanitor<XMLCh> janBuf2(tmpBuf2, manager); |
423 |
|
424 |
- return replace(tmpBuf, tmpBuf2, start, end); |
425 |
+ return replace(tmpBuf, tmpBuf2, start, end, manager); |
426 |
} |
427 |
|
428 |
|
429 |
@@ -854,59 +813,113 @@ |
430 |
// RegularExpression: Replace methods - Wide char version |
431 |
// --------------------------------------------------------------------------- |
432 |
XMLCh* RegularExpression::replace(const XMLCh* const matchString, |
433 |
- const XMLCh* const replaceString){ |
434 |
+ const XMLCh* const replaceString, |
435 |
+ MemoryManager* const manager) const { |
436 |
|
437 |
return replace(matchString, replaceString, 0, |
438 |
- XMLString::stringLen(matchString)); |
439 |
+ XMLString::stringLen(matchString), manager); |
440 |
} |
441 |
|
442 |
XMLCh* RegularExpression::replace(const XMLCh* const matchString, |
443 |
const XMLCh* const replaceString, |
444 |
- const int start, const int end) |
445 |
+ const int start, const int end, |
446 |
+ MemoryManager* const manager) const |
447 |
{ |
448 |
- |
449 |
- //check if matches zero length string - throw error if so |
450 |
- if (matches(XMLUni::fgZeroLenString, fMemoryManager)){ |
451 |
- ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_RepPatMatchesZeroString, fMemoryManager); |
452 |
- } |
453 |
+ // check if matches zero length string - throw error if so |
454 |
+ if(matches(XMLUni::fgZeroLenString, manager)){ |
455 |
+ ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_RepPatMatchesZeroString, manager); |
456 |
+ } |
457 |
|
458 |
- RefVectorOf<Match> *subEx = new (fMemoryManager) RefVectorOf<Match>(10, true, fMemoryManager); |
459 |
- Janitor<RefVectorOf<Match> > janSubEx(subEx); |
460 |
+ RefVectorOf<Match> *subEx = new (manager) RefVectorOf<Match>(10, true, manager); |
461 |
+ Janitor<RefVectorOf<Match> > janSubEx(subEx); |
462 |
|
463 |
- //Call to tokenize with Match vector so that we keep track of the locations |
464 |
- //of the subExpression within each of the matches |
465 |
- RefArrayVectorOf<XMLCh>* tokenStack = tokenize(matchString, start, end, subEx); |
466 |
- Janitor<RefArrayVectorOf<XMLCh> > janTokStack(tokenStack); |
467 |
- |
468 |
- XMLBuffer result(1023, fMemoryManager); |
469 |
- |
470 |
- int numSubEx = 0; |
471 |
- |
472 |
- if (subEx && subEx->size() > 0) |
473 |
- numSubEx = subEx->elementAt(0)->getNoGroups() - 1; |
474 |
- |
475 |
- int tokStackSize = tokenStack->size(); |
476 |
- const XMLCh* curRepString = XMLString::replicate(replaceString, fMemoryManager); |
477 |
- |
478 |
- for (int i = 0; i < tokStackSize; i++){ |
479 |
+ allMatches(matchString, start, end, subEx, manager); |
480 |
+ |
481 |
+ XMLBuffer result(1023, manager); |
482 |
+ int tokStart = start; |
483 |
+ |
484 |
+ unsigned int i = 0; |
485 |
+ for(; i < subEx->size(); ++i) { |
486 |
+ Match *match = subEx->elementAt(i); |
487 |
+ int matchStart = match->getStartPos(0); |
488 |
+ |
489 |
+ if(matchStart > tokStart) |
490 |
+ result.append(matchString + tokStart, matchStart - tokStart); |
491 |
+ subInExp(replaceString, matchString, match, result, manager); |
492 |
+ |
493 |
+ tokStart = match->getEndPos(0); |
494 |
+ } |
495 |
+ |
496 |
+ if(end > tokStart) |
497 |
+ result.append(matchString + tokStart, end - tokStart); |
498 |
+ |
499 |
+ return XMLString::replicate(result.getRawBuffer(), manager); |
500 |
+} |
501 |
+ |
502 |
+/* |
503 |
+ * Helper for Replace. This method prepares the replacement string by substituting |
504 |
+ * in actual values for parenthesized sub expressions. |
505 |
+ * |
506 |
+ * An error will be thrown if: |
507 |
+ * 1) there is chBackSlash not followed by a chDollarSign or chBackSlash |
508 |
+ * 2) there is an unescaped chDollarSign which is not followed by a digit |
509 |
+ * |
510 |
+ */ |
511 |
+void RegularExpression::subInExp(const XMLCh* const repString, |
512 |
+ const XMLCh* const origString, |
513 |
+ const Match* subEx, |
514 |
+ XMLBuffer &result, |
515 |
+ MemoryManager* const manager) const |
516 |
+{ |
517 |
+ int numSubExp = subEx->getNoGroups() - 1; |
518 |
+ |
519 |
+ for(const XMLCh *ptr = repString; *ptr != chNull; ++ptr) { |
520 |
+ if(*ptr == chDollarSign) { |
521 |
+ ++ptr; |
522 |
|
523 |
- result.append(tokenStack->elementAt(i)); |
524 |
- |
525 |
- if (i != tokStackSize - 1) { |
526 |
- |
527 |
- //if there are subExpressions, then determine the string we want to |
528 |
- //substitute in. |
529 |
- if (numSubEx != 0) { |
530 |
- fMemoryManager->deallocate((XMLCh*)curRepString); |
531 |
- curRepString = subInExp(replaceString, matchString, subEx->elementAt(i)); |
532 |
+ // check that after the $ is a digit |
533 |
+ if(!XMLString::isDigit(*ptr)) { |
534 |
+ // invalid replace string - $ must be followed by a digit |
535 |
+ ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_InvalidRepPattern, manager); |
536 |
+ } |
537 |
+ |
538 |
+ int index = *ptr - chDigit_0; |
539 |
+ |
540 |
+ const XMLCh *dig = ptr + 1; |
541 |
+ while(XMLString::isDigit(*dig)) { |
542 |
+ int newIndex = index * 10 + (*dig - chDigit_0); |
543 |
+ if(newIndex > numSubExp) break; |
544 |
+ |
545 |
+ index = newIndex; |
546 |
+ ptr = dig; |
547 |
+ ++dig; |
548 |
+ } |
549 |
+ |
550 |
+ // now check that the index is legal |
551 |
+ if(index <= numSubExp) { |
552 |
+ int start = subEx->getStartPos(index); |
553 |
+ int end = subEx->getEndPos(index); |
554 |
+ |
555 |
+ // now copy the substring into the new string |
556 |
+ if(start < end) { |
557 |
+ result.append(origString + start, end - start); |
558 |
+ } |
559 |
+ } |
560 |
+ |
561 |
+ } else { |
562 |
+ if(*ptr == chBackSlash) { |
563 |
+ ++ptr; |
564 |
+ |
565 |
+ // if you have a slash and then a character that's not a $ or /, |
566 |
+ // then it's an invalid replace string |
567 |
+ if(*ptr != chDollarSign && *ptr != chBackSlash) { |
568 |
+ ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_InvalidRepPattern, manager); |
569 |
+ } |
570 |
+ } |
571 |
+ |
572 |
+ result.append(*ptr); |
573 |
} |
574 |
- result.append(curRepString); |
575 |
} |
576 |
- } |
577 |
- |
578 |
- fMemoryManager->deallocate((XMLCh*)curRepString); |
579 |
- return XMLString::replicate(result.getRawBuffer(), fMemoryManager); |
580 |
- |
581 |
} |
582 |
|
583 |
|
584 |
@@ -982,10 +995,10 @@ |
585 |
|
586 |
|
587 |
int RegularExpression::match(Context* const context, const Op* const operations |
588 |
- , int offset, const short direction) |
589 |
+ , int offset, const short direction) const |
590 |
{ |
591 |
const Op* tmpOp = operations; |
592 |
- bool ignoreCase = isSet(fOptions, IGNORE_CASE); |
593 |
+ bool ignoreCase = isSet(context->fOptions, IGNORE_CASE); |
594 |
|
595 |
while (true) { |
596 |
|
597 |
@@ -1133,7 +1146,7 @@ |
598 |
} |
599 |
bool RegularExpression::matchChar(Context* const context, |
600 |
const XMLInt32 ch, int& offset, |
601 |
- const short direction, const bool ignoreCase) |
602 |
+ const short direction, const bool ignoreCase) const |
603 |
{ |
604 |
int tmpOffset = direction > 0 ? offset : offset - 1; |
605 |
|
606 |
@@ -1156,7 +1169,7 @@ |
607 |
} |
608 |
|
609 |
bool RegularExpression::matchDot(Context* const context, int& offset, |
610 |
- const short direction) |
611 |
+ const short direction) const |
612 |
{ |
613 |
int tmpOffset = direction > 0 ? offset : offset - 1; |
614 |
|
615 |
@@ -1168,7 +1181,7 @@ |
616 |
if (!context->nextCh(strCh, tmpOffset, direction)) |
617 |
return false; |
618 |
|
619 |
- if (!isSet(fOptions, SINGLE_LINE)) { |
620 |
+ if (!isSet(context->fOptions, SINGLE_LINE)) { |
621 |
|
622 |
if (direction > 0 && RegxUtil::isEOLChar(strCh)) |
623 |
return false; |
624 |
@@ -1183,7 +1196,7 @@ |
625 |
|
626 |
bool RegularExpression::matchRange(Context* const context, const Op* const op, |
627 |
int& offset, const short direction, |
628 |
- const bool ignoreCase) |
629 |
+ const bool ignoreCase) const |
630 |
{ |
631 |
int tmpOffset = direction > 0 ? offset : offset - 1; |
632 |
|
633 |
@@ -1213,7 +1226,7 @@ |
634 |
} |
635 |
|
636 |
bool RegularExpression::matchAnchor(Context* const context, const XMLInt32 ch, |
637 |
- const int offset) |
638 |
+ const int offset) const |
639 |
{ |
640 |
switch ((XMLCh) ch) { |
641 |
case chLatin_A: |
642 |
@@ -1224,10 +1237,10 @@ |
643 |
if (context->fLength == 0) |
644 |
break; |
645 |
{ |
646 |
- int after = getWordType(context->fString, context->fStart, |
647 |
+ int after = getWordType(context, context->fString, context->fStart, |
648 |
context->fLimit, offset); |
649 |
if (after == WT_IGNORE |
650 |
- || after == getPreviousWordType(context->fString, |
651 |
+ || after == getPreviousWordType(context, context->fString, |
652 |
context->fStart, |
653 |
context->fLimit, offset)) |
654 |
break; |
655 |
@@ -1237,10 +1250,10 @@ |
656 |
if (context->fLength == 0) |
657 |
return false; |
658 |
{ |
659 |
- int after = getWordType(context->fString, context->fStart, |
660 |
+ int after = getWordType(context, context->fString, context->fStart, |
661 |
context->fLimit, offset); |
662 |
if (after == WT_IGNORE |
663 |
- || after == getPreviousWordType(context->fString, |
664 |
+ || after == getPreviousWordType(context, context->fString, |
665 |
context->fStart |
666 |
, context->fLimit, offset)) |
667 |
return false; |
668 |
@@ -1248,7 +1261,7 @@ |
669 |
break; |
670 |
case chLatin_Z: |
671 |
case chDollarSign: |
672 |
- if ( (XMLCh) ch == chDollarSign && isSet(fOptions, MULTIPLE_LINE)) { |
673 |
+ if ( (XMLCh) ch == chDollarSign && isSet(context->fOptions, MULTIPLE_LINE)) { |
674 |
if (!(offset == context->fLimit || (offset < context->fLimit |
675 |
&& RegxUtil::isEOLChar(context->fString[offset])))) |
676 |
return false; |
677 |
@@ -1270,7 +1283,7 @@ |
678 |
break; |
679 |
case chAt: |
680 |
case chCaret: |
681 |
- if ( (XMLCh) ch == chCaret && !isSet(fOptions, MULTIPLE_LINE)) { |
682 |
+ if ( (XMLCh) ch == chCaret && !isSet(context->fOptions, MULTIPLE_LINE)) { |
683 |
|
684 |
if (offset != context->fStart) |
685 |
return false; |
686 |
@@ -1286,9 +1299,9 @@ |
687 |
if (context->fLength == 0 || offset == context->fLimit) |
688 |
return false; |
689 |
|
690 |
- if (getWordType(context->fString, context->fStart, context->fLimit, |
691 |
+ if (getWordType(context, context->fString, context->fStart, context->fLimit, |
692 |
offset) != WT_LETTER |
693 |
- || getPreviousWordType(context->fString, context->fStart, |
694 |
+ || getPreviousWordType(context, context->fString, context->fStart, |
695 |
context->fLimit, offset) != WT_OTHER) |
696 |
return false; |
697 |
break; |
698 |
@@ -1296,9 +1309,9 @@ |
699 |
if (context->fLength == 0 || offset == context->fStart) |
700 |
return false; |
701 |
|
702 |
- if (getWordType(context->fString, context->fStart, context->fLimit, |
703 |
+ if (getWordType(context, context->fString, context->fStart, context->fLimit, |
704 |
offset) != WT_OTHER |
705 |
- || getPreviousWordType(context->fString, context->fStart, |
706 |
+ || getPreviousWordType(context, context->fString, context->fStart, |
707 |
context->fLimit, offset) != WT_LETTER) |
708 |
return false; |
709 |
break; |
710 |
@@ -1310,10 +1323,10 @@ |
711 |
bool RegularExpression::matchBackReference(Context* const context, |
712 |
const XMLInt32 refNo, int& offset, |
713 |
const short direction, |
714 |
- const bool ignoreCase) |
715 |
+ const bool ignoreCase) const |
716 |
{ |
717 |
if (refNo <=0 || refNo >= fNoGroups) |
718 |
- ThrowXMLwithMemMgr(IllegalArgumentException, XMLExcepts::Regex_BadRefNo, fMemoryManager); |
719 |
+ ThrowXMLwithMemMgr(IllegalArgumentException, XMLExcepts::Regex_BadRefNo, context->fMemoryManager); |
720 |
|
721 |
if (context->fMatch->getStartPos(refNo) < 0 |
722 |
|| context->fMatch->getEndPos(refNo) < 0) |
723 |
@@ -1341,7 +1354,7 @@ |
724 |
|
725 |
bool RegularExpression::matchString(Context* const context, |
726 |
const XMLCh* const literal, int& offset, |
727 |
- const short direction, const bool ignoreCase) |
728 |
+ const short direction, const bool ignoreCase) const |
729 |
{ |
730 |
int length = XMLString::stringLen(literal); |
731 |
int tmpOffset = (direction > 0) ? offset : offset - length; |
732 |
@@ -1363,7 +1376,7 @@ |
733 |
} |
734 |
|
735 |
int RegularExpression::matchCapture(Context* const context, const Op* const op, |
736 |
- int offset, const short direction) |
737 |
+ int offset, const short direction) const |
738 |
{ |
739 |
// No check is made for nullness of fMatch as the function is only called if |
740 |
// fMatch is not null. |
741 |
@@ -1389,7 +1402,7 @@ |
742 |
|
743 |
int RegularExpression::matchUnion(Context* const context, |
744 |
const Op* const op, int offset, |
745 |
- const short direction) |
746 |
+ const short direction) const |
747 |
{ |
748 |
unsigned int opSize = op->getSize(); |
749 |
|
750 |
@@ -1415,7 +1428,7 @@ |
751 |
|
752 |
bool RegularExpression::matchCondition(Context* const context, |
753 |
const Op* const op, int offset, |
754 |
- const short direction) |
755 |
+ const short direction) const |
756 |
{ |
757 |
|
758 |
int refNo = op->getRefNo(); |
759 |
@@ -1512,86 +1525,6 @@ |
760 |
} |
761 |
|
762 |
/* |
763 |
- * Helper for Replace. This method prepares the replacement string by substituting |
764 |
- * in actual values for parenthesized sub expressions. |
765 |
- * |
766 |
- * An error will be thrown if: |
767 |
- * 1) repString references an undefined subExpression |
768 |
- * 2) there is an unescaped chDollar which is not followed by a digit |
769 |
- * |
770 |
- */ |
771 |
-const XMLCh* RegularExpression::subInExp(const XMLCh* const repString, |
772 |
- const XMLCh* const origString, |
773 |
- const Match* subEx){ |
774 |
- |
775 |
- int numSubExp = subEx->getNoGroups() - 1; |
776 |
- |
777 |
- if (numSubExp == 0) |
778 |
- return XMLString::replicate(repString, fMemoryManager); |
779 |
- |
780 |
- bool notEscaped = true; |
781 |
- |
782 |
- XMLBuffer newString(1023, fMemoryManager); |
783 |
- |
784 |
- XMLCh indexStr[2]; //holds the string rep of a |
785 |
- |
786 |
- indexStr[1] = chNull; |
787 |
- int index = -1; |
788 |
- |
789 |
- for (const XMLCh* ptr = repString; *ptr != chNull; ptr++){ |
790 |
- |
791 |
- if ((*ptr == chDollarSign) && notEscaped) { |
792 |
- |
793 |
- ptr++; |
794 |
- |
795 |
- //check that after the $ is a digit |
796 |
- if (!XMLString::isDigit(*ptr)){ |
797 |
- |
798 |
- //invalid replace string - $ must be followed by a digit |
799 |
- ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_InvalidRepPattern, fMemoryManager); |
800 |
- } |
801 |
- |
802 |
- indexStr[0] = *ptr; //get the digit |
803 |
- index = XMLString::parseInt(indexStr, fMemoryManager); //convert it to an int |
804 |
- |
805 |
- //now check that the index is legal |
806 |
- if (index > numSubExp){ |
807 |
- ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_InvalidRepPattern, fMemoryManager); |
808 |
- } |
809 |
- |
810 |
- int start = subEx->getStartPos(index); |
811 |
- int end = subEx->getEndPos(index); |
812 |
- |
813 |
- //now copy the substring into the new string |
814 |
- for (int i=start; i<end; i++){ |
815 |
- newString.append(origString[i]); |
816 |
- } |
817 |
- |
818 |
- } else { |
819 |
- |
820 |
- //if you have a slash and then a character that's not a $ or /, |
821 |
- //then it's an invalid replace string |
822 |
- if (!notEscaped && (*ptr != chDollarSign && *ptr != chBackSlash)){ |
823 |
- ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_InvalidRepPattern, fMemoryManager); |
824 |
- } |
825 |
- |
826 |
- if (*ptr == chBackSlash){ |
827 |
- notEscaped = false; |
828 |
- continue; |
829 |
- |
830 |
- }else |
831 |
- notEscaped = true; |
832 |
- |
833 |
- newString.append(*ptr); |
834 |
- } |
835 |
- } |
836 |
- |
837 |
- return XMLString::replicate(newString.getRawBuffer(), fMemoryManager); |
838 |
- |
839 |
-} |
840 |
- |
841 |
- |
842 |
-/* |
843 |
* Prepares for matching. This method is called during construction. |
844 |
*/ |
845 |
void RegularExpression::prepare() { |
846 |
@@ -1679,17 +1612,17 @@ |
847 |
} |
848 |
} |
849 |
|
850 |
-unsigned short RegularExpression::getCharType(const XMLCh ch) { |
851 |
- |
852 |
- if (!isSet(fOptions, UNICODE_WORD_BOUNDARY)) { |
853 |
+unsigned short RegularExpression::getCharType(Context* const context, const XMLCh ch) const |
854 |
+{ |
855 |
+ if (!isSet(context->fOptions, UNICODE_WORD_BOUNDARY)) { |
856 |
|
857 |
- if (isSet(fOptions, USE_UNICODE_CATEGORY)) { |
858 |
+ if (isSet(context->fOptions, USE_UNICODE_CATEGORY)) { |
859 |
|
860 |
if (fWordRange == 0) { |
861 |
|
862 |
fWordRange = fTokenFactory->getRange(fgUniIsWord); |
863 |
if (fWordRange == 0) |
864 |
- ThrowXMLwithMemMgr1(RuntimeException, XMLExcepts::Regex_RangeTokenGetError, fgUniIsWord, fMemoryManager); |
865 |
+ ThrowXMLwithMemMgr1(RuntimeException, XMLExcepts::Regex_RangeTokenGetError, fgUniIsWord, context->fMemoryManager); |
866 |
} |
867 |
|
868 |
return fWordRange->match(ch) ? WT_LETTER : WT_OTHER; |
869 |
diff -ru xerces-c-src_2_8_0-release/src/xercesc/util/regx/RegularExpression.hpp xerces-c-src_2_8_0/src/xercesc/util/regx/RegularExpression.hpp |
870 |
--- xerces-c-src_2_8_0-release/src/xercesc/util/regx/RegularExpression.hpp 2007-08-28 19:44:32.000000000 +0100 |
871 |
+++ xerces-c-src_2_8_0/src/xercesc/util/regx/RegularExpression.hpp 2008-01-29 17:28:11.000000000 +0000 |
872 |
@@ -100,45 +100,53 @@ |
873 |
// ----------------------------------------------------------------------- |
874 |
// Matching methods |
875 |
// ----------------------------------------------------------------------- |
876 |
- bool matches(const char* const matchString, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
877 |
+ bool matches(const char* const matchString, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) const; |
878 |
bool matches(const char* const matchString, const int start, |
879 |
- const int end, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
880 |
- bool matches(const char* const matchString, Match* const pMatch, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
881 |
+ const int end, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) const; |
882 |
+ bool matches(const char* const matchString, Match* const pMatch, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) const; |
883 |
bool matches(const char* const matchString, const int start, |
884 |
- const int end, Match* const pMatch, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
885 |
+ const int end, Match* const pMatch, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) const; |
886 |
|
887 |
- bool matches(const XMLCh* const matchString, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
888 |
+ bool matches(const XMLCh* const matchString, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) const; |
889 |
bool matches(const XMLCh* const matchString, const int start, |
890 |
- const int end, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
891 |
- bool matches(const XMLCh* const matchString, Match* const pMatch, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
892 |
+ const int end, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) const; |
893 |
+ bool matches(const XMLCh* const matchString, Match* const pMatch, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) const; |
894 |
bool matches(const XMLCh* const matchString, const int start, |
895 |
- const int end, Match* const pMatch, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
896 |
+ const int end, Match* const pMatch, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) const; |
897 |
+ void allMatches(const XMLCh* const matchString, const int start, const int end, |
898 |
+ RefVectorOf<Match> *subEx, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) const; |
899 |
|
900 |
// ----------------------------------------------------------------------- |
901 |
// Tokenize methods |
902 |
// ----------------------------------------------------------------------- |
903 |
// Note: The caller owns the string vector that is returned, and is responsible |
904 |
// for deleting it. |
905 |
- RefArrayVectorOf<XMLCh> *tokenize(const char* const matchString); |
906 |
- RefArrayVectorOf<XMLCh> *tokenize(const char* const matchString, const int start, |
907 |
- const int end); |
908 |
+ RefArrayVectorOf<XMLCh> *tokenize(const char* const matchString, |
909 |
+ MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) const; |
910 |
+ RefArrayVectorOf<XMLCh> *tokenize(const char* const matchString, const int start, const int end, |
911 |
+ MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) const; |
912 |
|
913 |
- RefArrayVectorOf<XMLCh> *tokenize(const XMLCh* const matchString); |
914 |
RefArrayVectorOf<XMLCh> *tokenize(const XMLCh* const matchString, |
915 |
- const int start, const int end); |
916 |
+ MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) const; |
917 |
+ RefArrayVectorOf<XMLCh> *tokenize(const XMLCh* const matchString, const int start, const int end, |
918 |
+ MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) const; |
919 |
|
920 |
// ----------------------------------------------------------------------- |
921 |
// Replace methods |
922 |
// ----------------------------------------------------------------------- |
923 |
// Note: The caller owns the XMLCh* that is returned, and is responsible for |
924 |
// deleting it. |
925 |
- XMLCh *replace(const char* const matchString, const char* const replaceString); |
926 |
XMLCh *replace(const char* const matchString, const char* const replaceString, |
927 |
- const int start, const int end); |
928 |
+ MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) const; |
929 |
+ XMLCh *replace(const char* const matchString, const char* const replaceString, |
930 |
+ const int start, const int end, |
931 |
+ MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) const; |
932 |
|
933 |
- XMLCh *replace(const XMLCh* const matchString, const XMLCh* const replaceString); |
934 |
XMLCh *replace(const XMLCh* const matchString, const XMLCh* const replaceString, |
935 |
- const int start, const int end); |
936 |
+ MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) const; |
937 |
+ XMLCh *replace(const XMLCh* const matchString, const XMLCh* const replaceString, |
938 |
+ const int start, const int end, |
939 |
+ MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) const; |
940 |
|
941 |
// ----------------------------------------------------------------------- |
942 |
// Static initialize and cleanup methods |
943 |
@@ -165,7 +173,8 @@ |
944 |
Context& operator= (const Context& other); |
945 |
inline const XMLCh* getString() const { return fString; } |
946 |
void reset(const XMLCh* const string, const int stringLen, |
947 |
- const int start, const int limit, const int noClosures); |
948 |
+ const int start, const int limit, const int noClosures, |
949 |
+ const unsigned int options); |
950 |
bool nextCh(XMLInt32& ch, int& offset, const short direction); |
951 |
|
952 |
bool fAdoptMatch; |
953 |
@@ -177,6 +186,7 @@ |
954 |
int* fOffsets; |
955 |
Match* fMatch; |
956 |
const XMLCh* fString; |
957 |
+ unsigned int fOptions; |
958 |
MemoryManager* fMemoryManager; |
959 |
}; |
960 |
|
961 |
@@ -201,65 +211,54 @@ |
962 |
// ----------------------------------------------------------------------- |
963 |
void prepare(); |
964 |
int parseOptions(const XMLCh* const options); |
965 |
- unsigned short getWordType(const XMLCh* const target, const int begin, |
966 |
- const int end, const int offset); |
967 |
- unsigned short getCharType(const XMLCh ch); |
968 |
- unsigned short getPreviousWordType(const XMLCh* const target, |
969 |
+ unsigned short getWordType(Context* const context, const XMLCh* const target, |
970 |
+ const int begin, const int end, const int offset) const; |
971 |
+ unsigned short getCharType(Context* const context, const XMLCh ch) const; |
972 |
+ unsigned short getPreviousWordType(Context* const context, const XMLCh* const target, |
973 |
const int start, const int end, |
974 |
- int offset); |
975 |
+ int offset) const; |
976 |
|
977 |
/** |
978 |
* Matching helpers |
979 |
*/ |
980 |
int match(Context* const context, const Op* const operations, int offset, |
981 |
- const short direction); |
982 |
- bool matchIgnoreCase(const XMLInt32 ch1, const XMLInt32 ch2); |
983 |
+ const short direction) const; |
984 |
+ bool matchIgnoreCase(const XMLInt32 ch1, const XMLInt32 ch2) const; |
985 |
|
986 |
/** |
987 |
* Helper methods used by match(Context* ...) |
988 |
*/ |
989 |
bool matchChar(Context* const context, const XMLInt32 ch, int& offset, |
990 |
- const short direction, const bool ignoreCase); |
991 |
- bool matchDot(Context* const context, int& offset, const short direction); |
992 |
+ const short direction, const bool ignoreCase) const; |
993 |
+ bool matchDot(Context* const context, int& offset, const short direction) const; |
994 |
bool matchRange(Context* const context, const Op* const op, |
995 |
- int& offset, const short direction, const bool ignoreCase); |
996 |
+ int& offset, const short direction, const bool ignoreCase) const; |
997 |
bool matchAnchor(Context* const context, const XMLInt32 ch, |
998 |
- const int offset); |
999 |
+ const int offset) const; |
1000 |
bool matchBackReference(Context* const context, const XMLInt32 ch, |
1001 |
int& offset, const short direction, |
1002 |
- const bool ignoreCase); |
1003 |
+ const bool ignoreCase) const; |
1004 |
bool matchString(Context* const context, const XMLCh* const literal, |
1005 |
- int& offset, const short direction, const bool ignoreCase); |
1006 |
+ int& offset, const short direction, const bool ignoreCase) const; |
1007 |
int matchUnion(Context* const context, const Op* const op, int offset, |
1008 |
- const short direction); |
1009 |
+ const short direction) const; |
1010 |
int matchCapture(Context* const context, const Op* const op, int offset, |
1011 |
- const short direction); |
1012 |
+ const short direction) const; |
1013 |
bool matchCondition(Context* const context, const Op* const op, int offset, |
1014 |
- const short direction); |
1015 |
+ const short direction) const; |
1016 |
int matchModifier(Context* const context, const Op* const op, int offset, |
1017 |
- const short direction); |
1018 |
+ const short direction) const; |
1019 |
|
1020 |
/** |
1021 |
- * Tokenize helper |
1022 |
- * |
1023 |
- * This overloaded tokenize is for internal use only. It provides a way to |
1024 |
- * keep track of the sub-expressions in each match of the pattern. |
1025 |
- * |
1026 |
- * It is called by the other tokenize methods, and by the replace method. |
1027 |
- * The caller is responsible for the deletion of the returned |
1028 |
- * RefArrayVectorOf<XMLCh*> |
1029 |
- */ |
1030 |
- RefArrayVectorOf<XMLCh> *tokenize(const XMLCh* const matchString, |
1031 |
- const int start, const int end, |
1032 |
- RefVectorOf<Match> *subEx); |
1033 |
- /** |
1034 |
* Replace helpers |
1035 |
* |
1036 |
* Note: the caller owns the XMLCh* that is returned |
1037 |
*/ |
1038 |
- const XMLCh *subInExp(const XMLCh* const repString, |
1039 |
- const XMLCh* const origString, |
1040 |
- const Match* subEx); |
1041 |
+ void subInExp(const XMLCh* const repString, |
1042 |
+ const XMLCh* const origString, |
1043 |
+ const Match* subEx, |
1044 |
+ XMLBuffer &result, |
1045 |
+ MemoryManager* const manager) const; |
1046 |
/** |
1047 |
* Converts a token tree into an operation tree |
1048 |
*/ |
1049 |
@@ -293,10 +292,10 @@ |
1050 |
int fMinLength; |
1051 |
int fNoClosures; |
1052 |
unsigned int fOptions; |
1053 |
- BMPattern* fBMPattern; |
1054 |
+ const BMPattern* fBMPattern; |
1055 |
XMLCh* fPattern; |
1056 |
XMLCh* fFixedString; |
1057 |
- Op* fOperations; |
1058 |
+ const Op* fOperations; |
1059 |
Token* fTokenTree; |
1060 |
RangeToken* fFirstChar; |
1061 |
static RangeToken* fWordRange; |
1062 |
@@ -553,40 +552,42 @@ |
1063 |
|
1064 |
inline int RegularExpression::matchModifier(Context* const context, |
1065 |
const Op* const op, int offset, |
1066 |
- const short direction) |
1067 |
+ const short direction) const |
1068 |
{ |
1069 |
int saveOptions = fOptions; |
1070 |
- fOptions |= (int) op->getData(); |
1071 |
- fOptions &= (int) ~op->getData2(); |
1072 |
+ context->fOptions |= (int) op->getData(); |
1073 |
+ context->fOptions &= (int) ~op->getData2(); |
1074 |
|
1075 |
int ret = match(context, op->getChild(), offset, direction); |
1076 |
|
1077 |
- fOptions = saveOptions; |
1078 |
+ context->fOptions = saveOptions; |
1079 |
|
1080 |
return ret; |
1081 |
} |
1082 |
|
1083 |
- inline unsigned short RegularExpression::getWordType(const XMLCh* const target |
1084 |
+ inline unsigned short RegularExpression::getWordType(Context* const context |
1085 |
+ , const XMLCh* const target |
1086 |
, const int begin |
1087 |
, const int end |
1088 |
- , const int offset) |
1089 |
+ , const int offset) const |
1090 |
{ |
1091 |
if (offset < begin || offset >= end) |
1092 |
return WT_OTHER; |
1093 |
|
1094 |
- return getCharType(target[offset]); |
1095 |
+ return getCharType(context, target[offset]); |
1096 |
} |
1097 |
|
1098 |
inline |
1099 |
- unsigned short RegularExpression::getPreviousWordType(const XMLCh* const target |
1100 |
+ unsigned short RegularExpression::getPreviousWordType(Context* const context |
1101 |
+ , const XMLCh* const target |
1102 |
, const int start |
1103 |
, const int end |
1104 |
- , int offset) |
1105 |
+ , int offset) const |
1106 |
{ |
1107 |
- unsigned short ret = getWordType(target, start, end, --offset); |
1108 |
+ unsigned short ret = getWordType(context, target, start, end, --offset); |
1109 |
|
1110 |
while (ret == WT_IGNORE) { |
1111 |
- ret = getWordType(target, start, end, --offset); |
1112 |
+ ret = getWordType(context, target, start, end, --offset); |
1113 |
} |
1114 |
|
1115 |
return ret; |
1116 |
|
1117 |
|
1118 |
|
1119 |
1.1 dev-libs/xerces-c/files/xqilla-xercesc_content_type.patch |
1120 |
|
1121 |
file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/dev-libs/xerces-c/files/xqilla-xercesc_content_type.patch?rev=1.1&view=markup |
1122 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/dev-libs/xerces-c/files/xqilla-xercesc_content_type.patch?rev=1.1&content-type=text/plain |
1123 |
|
1124 |
Index: xqilla-xercesc_content_type.patch |
1125 |
=================================================================== |
1126 |
diff -ru xerces-c-src_2_8_0-release/src/xercesc/util/BinInputStream.cpp xerces-c-src_2_8_0/src/xercesc/util/BinInputStream.cpp |
1127 |
--- xerces-c-src_2_8_0-release/src/xercesc/util/BinInputStream.cpp 2008-02-08 15:30:17.000000000 +0000 |
1128 |
+++ xerces-c-src_2_8_0/src/xercesc/util/BinInputStream.cpp 2008-01-28 02:24:47.000000000 +0000 |
1129 |
@@ -42,4 +42,10 @@ |
1130 |
{ |
1131 |
} |
1132 |
|
1133 |
+const XMLCh *BinInputStream::getContentType() const |
1134 |
+{ |
1135 |
+ // The default implementation never returns a content type |
1136 |
+ return 0; |
1137 |
+} |
1138 |
+ |
1139 |
XERCES_CPP_NAMESPACE_END |
1140 |
diff -ru xerces-c-src_2_8_0-release/src/xercesc/util/BinInputStream.hpp xerces-c-src_2_8_0/src/xercesc/util/BinInputStream.hpp |
1141 |
--- xerces-c-src_2_8_0-release/src/xercesc/util/BinInputStream.hpp 2008-02-08 15:30:17.000000000 +0000 |
1142 |
+++ xerces-c-src_2_8_0/src/xercesc/util/BinInputStream.hpp 2008-01-28 02:23:51.000000000 +0000 |
1143 |
@@ -46,6 +46,7 @@ |
1144 |
, const unsigned int maxToRead |
1145 |
) = 0; |
1146 |
|
1147 |
+ virtual const XMLCh *getContentType() const; |
1148 |
|
1149 |
protected : |
1150 |
// ----------------------------------------------------------------------- |
1151 |
diff -ru xerces-c-src_2_8_0-release/src/xercesc/util/NetAccessors/Socket/UnixHTTPURLInputStream.cpp xerces-c-src_2_8_0/src/xercesc/util/NetAccessors/Socket/UnixHTTPURLInputStream.cpp |
1152 |
--- xerces-c-src_2_8_0-release/src/xercesc/util/NetAccessors/Socket/UnixHTTPURLInputStream.cpp 2008-02-08 15:30:17.000000000 +0000 |
1153 |
+++ xerces-c-src_2_8_0/src/xercesc/util/NetAccessors/Socket/UnixHTTPURLInputStream.cpp 2008-01-29 00:08:59.000000000 +0000 |
1154 |
@@ -58,7 +58,14 @@ |
1155 |
int* get() const { return fData; } |
1156 |
int* release() { int* p = fData; fData = 0; return p; } |
1157 |
|
1158 |
- void reset(int* p = 0) { if(fData) close(*fData); fData=p; } |
1159 |
+ void reset(int* p = 0) |
1160 |
+ { |
1161 |
+ if(fData) { |
1162 |
+ shutdown(*fData, 2); |
1163 |
+ close(*fData); |
1164 |
+ } |
1165 |
+ fData = p; |
1166 |
+ } |
1167 |
bool isDataNull() { return (fData == 0); } |
1168 |
|
1169 |
private : |
1170 |
@@ -79,370 +86,372 @@ |
1171 |
int* fData; |
1172 |
}; |
1173 |
|
1174 |
-UnixHTTPURLInputStream::UnixHTTPURLInputStream(const XMLURL& urlSource, const XMLNetHTTPInfo* httpInfo/*=0*/) |
1175 |
- : fSocket(0) |
1176 |
- , fBytesProcessed(0) |
1177 |
- , fMemoryManager(urlSource.getMemoryManager()) |
1178 |
+class TranscodeStr |
1179 |
{ |
1180 |
+public: |
1181 |
+ TranscodeStr(const XMLCh *in, XMLTranscoder* trans, |
1182 |
+ MemoryManager *manager = XMLPlatformUtils::fgMemoryManager) |
1183 |
+ : fString(0), |
1184 |
+ fBytesWritten(0), |
1185 |
+ fMemoryManager(manager) |
1186 |
+ { |
1187 |
+ if(in) { |
1188 |
+ unsigned int len = XMLString::stringLen(in) + 1; |
1189 |
+ |
1190 |
+ unsigned int allocSize = len * sizeof(XMLCh); |
1191 |
+ fString = (unsigned char*)fMemoryManager->allocate(allocSize); |
1192 |
+ |
1193 |
+ unsigned int charsRead; |
1194 |
+ |
1195 |
+ unsigned int charsDone = 0; |
1196 |
+ |
1197 |
+ while(true) { |
1198 |
+ fBytesWritten += trans->transcodeTo(in + charsDone, len - charsDone, |
1199 |
+ fString + fBytesWritten, allocSize - fBytesWritten, |
1200 |
+ charsRead, XMLTranscoder::UnRep_Throw); |
1201 |
+ charsDone += charsRead; |
1202 |
+ |
1203 |
+ if(charsDone == len) break; |
1204 |
+ |
1205 |
+ allocSize *= 2; |
1206 |
+ unsigned char *newBuf = (unsigned char*)fMemoryManager->allocate(allocSize); |
1207 |
+ memcpy(newBuf, fString, fBytesWritten); |
1208 |
+ fMemoryManager->deallocate(fString); |
1209 |
+ fString = newBuf; |
1210 |
+ } |
1211 |
+ } |
1212 |
+ } |
1213 |
|
1214 |
- // |
1215 |
- // Constants in ASCII to send/check in the HTTP request/response |
1216 |
- // |
1217 |
- |
1218 |
- const char GET[] = |
1219 |
- { |
1220 |
- chLatin_G, chLatin_E, chLatin_T, chSpace, chNull |
1221 |
- }; |
1222 |
- |
1223 |
- const char PUT[] = |
1224 |
- { |
1225 |
- chLatin_P, chLatin_U, chLatin_T, chSpace, chNull |
1226 |
- }; |
1227 |
- |
1228 |
- const char POST[] = |
1229 |
- { |
1230 |
- chLatin_P, chLatin_O, chLatin_S, chLatin_T, chSpace, chNull |
1231 |
- }; |
1232 |
- |
1233 |
- const char HTTP[] = |
1234 |
- { |
1235 |
- chLatin_H, chLatin_T, chLatin_T, chLatin_P, chNull |
1236 |
- }; |
1237 |
- |
1238 |
- const char HTTP10[] = |
1239 |
- { |
1240 |
- chSpace, chLatin_H, chLatin_T, chLatin_T, chLatin_P, chForwardSlash, chDigit_1, chPeriod, chDigit_0, chCR, chLF, chNull |
1241 |
- }; |
1242 |
- |
1243 |
- const char CRLF[] = |
1244 |
- { |
1245 |
- chCR, chLF, chNull |
1246 |
- }; |
1247 |
- |
1248 |
- const char CRLF2X[] = |
1249 |
+ ~TranscodeStr() |
1250 |
{ |
1251 |
- chCR, chLF, chCR, chLF, chNull |
1252 |
- }; |
1253 |
+ if(fString) |
1254 |
+ fMemoryManager->deallocate(fString); |
1255 |
+ } |
1256 |
|
1257 |
- const char LF2X[] = |
1258 |
+ const unsigned char *str() const |
1259 |
{ |
1260 |
- chLF, chLF, chNull |
1261 |
- }; |
1262 |
+ return fString; |
1263 |
+ } |
1264 |
|
1265 |
- const char HOST[] = |
1266 |
+ unsigned int len() const |
1267 |
{ |
1268 |
- chLatin_H, chLatin_o, chLatin_s, chLatin_t, chColon, chSpace, chNull |
1269 |
- }; |
1270 |
+ return fBytesWritten; |
1271 |
+ } |
1272 |
|
1273 |
- const char COLON[] = |
1274 |
- { |
1275 |
- chColon, chNull |
1276 |
- }; |
1277 |
+private: |
1278 |
+ unsigned char *fString; |
1279 |
+ unsigned int fBytesWritten; |
1280 |
+ MemoryManager *fMemoryManager; |
1281 |
+}; |
1282 |
|
1283 |
- const char AUTHORIZATION[] = |
1284 |
- { |
1285 |
- chLatin_A, chLatin_u, chLatin_t, chLatin_h, chLatin_o, chLatin_r, chLatin_i, chLatin_z, chLatin_a, chLatin_t, |
1286 |
- chLatin_i, chLatin_o, chLatin_n, chColon, chSpace, chLatin_B, chLatin_a, chLatin_s, chLatin_i, chLatin_c, chSpace, chNull |
1287 |
- }; |
1288 |
+static const char *CRLF = "\r\n"; |
1289 |
|
1290 |
- const char resp200 [] = |
1291 |
- { |
1292 |
- chSpace, chDigit_2, chDigit_0, chDigit_0, chSpace, chNull |
1293 |
- }; |
1294 |
+void UnixHTTPURLInputStream::createHTTPRequest(const XMLURL &urlSource, const XMLNetHTTPInfo *httpInfo, CharBuffer &buffer) |
1295 |
+{ |
1296 |
+ static const char *GET = "GET "; |
1297 |
+ static const char *PUT = "PUT "; |
1298 |
+ static const char *POST = "POST "; |
1299 |
+ static const char *HTTP10 = " HTTP/1.0\r\n"; |
1300 |
+ static const char *HOST = "Host: "; |
1301 |
+ static const char *AUTHORIZATION = "Authorization: Basic "; |
1302 |
+ static const char *COLON = ":"; |
1303 |
|
1304 |
- unsigned int charsEaten; |
1305 |
- unsigned int transSize; |
1306 |
XMLTransService::Codes failReason; |
1307 |
const unsigned int blockSize = 2048; |
1308 |
- const unsigned int bufSize = 5; |
1309 |
- static XMLCh portBuffer[bufSize+1]; |
1310 |
- |
1311 |
- // |
1312 |
- // Pull all of the parts of the URL out of the urlSource object |
1313 |
- // |
1314 |
- |
1315 |
- const XMLCh* hostName = urlSource.getHost(); |
1316 |
- const XMLCh* path = urlSource.getPath(); |
1317 |
- const XMLCh* fragment = urlSource.getFragment(); |
1318 |
- const XMLCh* query = urlSource.getQuery(); |
1319 |
|
1320 |
- // |
1321 |
- // Convert the hostName to the platform's code page for gethostbyname and |
1322 |
- // inet_addr functions. |
1323 |
- // |
1324 |
+ XMLTranscoder* trans = XMLPlatformUtils::fgTransService->makeNewTranscoderFor("ISO8859-1", failReason, blockSize, fMemoryManager); |
1325 |
+ Janitor<XMLTranscoder> janTrans(trans); |
1326 |
|
1327 |
- char* hostNameAsCharStar = XMLString::transcode(hostName, fMemoryManager); |
1328 |
- ArrayJanitor<char> janBuf1(hostNameAsCharStar, fMemoryManager); |
1329 |
+ TranscodeStr hostName(urlSource.getHost(), trans, fMemoryManager); |
1330 |
+ TranscodeStr path(urlSource.getPath(), trans, fMemoryManager); |
1331 |
+ TranscodeStr fragment(urlSource.getFragment(), trans, fMemoryManager); |
1332 |
+ TranscodeStr query(urlSource.getQuery(), trans, fMemoryManager); |
1333 |
|
1334 |
- // |
1335 |
- // Convert all the parts of the urlSource object to ASCII so they can be |
1336 |
- // sent to the remote host in that format |
1337 |
- // |
1338 |
+ // Build up the http GET command to send to the server. |
1339 |
+ // To do: We should really support http 1.1. This implementation |
1340 |
+ // is weak. |
1341 |
+ if(httpInfo) { |
1342 |
+ switch(httpInfo->fHTTPMethod) { |
1343 |
+ case XMLNetHTTPInfo::GET: buffer.append(GET); break; |
1344 |
+ case XMLNetHTTPInfo::PUT: buffer.append(PUT); break; |
1345 |
+ case XMLNetHTTPInfo::POST: buffer.append(POST); break; |
1346 |
+ } |
1347 |
+ } |
1348 |
+ else { |
1349 |
+ buffer.append(GET); |
1350 |
+ } |
1351 |
|
1352 |
- transSize = XMLString::stringLen(hostName)+1; |
1353 |
- char* hostNameAsASCII = (char*) fMemoryManager->allocate |
1354 |
- ( |
1355 |
- (transSize+1) * sizeof(char) |
1356 |
- );//new char[transSize+1]; |
1357 |
- ArrayJanitor<char> janBuf2(hostNameAsASCII, fMemoryManager); |
1358 |
+ if(path.str() != 0) { |
1359 |
+ buffer.append((char*)path.str()); |
1360 |
+ } |
1361 |
+ else { |
1362 |
+ buffer.append("/"); |
1363 |
+ } |
1364 |
|
1365 |
- XMLTranscoder* trans = XMLPlatformUtils::fgTransService->makeNewTranscoderFor("ISO8859-1", failReason, blockSize, fMemoryManager); |
1366 |
- trans->transcodeTo(hostName, transSize, (unsigned char *) hostNameAsASCII, transSize, charsEaten, XMLTranscoder::UnRep_Throw); |
1367 |
+ if(query.str() != 0) { |
1368 |
+ buffer.append("?"); |
1369 |
+ buffer.append((char*)query.str()); |
1370 |
+ } |
1371 |
|
1372 |
- char* pathAsASCII = 0; |
1373 |
- ArrayJanitor<char> janBuf3(pathAsASCII, fMemoryManager); |
1374 |
- if (path) |
1375 |
- { |
1376 |
- transSize = XMLString::stringLen(path)+1; |
1377 |
- pathAsASCII = (char*) fMemoryManager->allocate |
1378 |
- ( |
1379 |
- (transSize+1) * sizeof(char) |
1380 |
- );//new char[transSize+1]; |
1381 |
- janBuf3.reset(pathAsASCII, fMemoryManager); |
1382 |
- trans->transcodeTo(path, transSize, (unsigned char *) pathAsASCII, transSize, charsEaten, XMLTranscoder::UnRep_Throw); |
1383 |
+ if(fragment.str() != 0) { |
1384 |
+ buffer.append((char*)fragment.str()); |
1385 |
} |
1386 |
+ buffer.append(HTTP10); |
1387 |
|
1388 |
- char* fragmentAsASCII = 0; |
1389 |
- ArrayJanitor<char> janBuf4(fragmentAsASCII, fMemoryManager); |
1390 |
- if (fragment) |
1391 |
+ buffer.append(HOST); |
1392 |
+ buffer.append((char*)hostName.str()); |
1393 |
+ if(urlSource.getPortNum() != 80) |
1394 |
{ |
1395 |
- transSize = XMLString::stringLen(fragment)+1; |
1396 |
- fragmentAsASCII = (char*) fMemoryManager->allocate |
1397 |
- ( |
1398 |
- (transSize+1) * sizeof(char) |
1399 |
- );//new char[transSize+1]; |
1400 |
- janBuf4.reset(fragmentAsASCII, fMemoryManager); |
1401 |
- trans->transcodeTo(fragment, transSize, (unsigned char *) fragmentAsASCII, transSize, charsEaten, XMLTranscoder::UnRep_Throw); |
1402 |
+ buffer.append(COLON); |
1403 |
+ buffer.appendDecimalNumber(urlSource.getPortNum()); |
1404 |
} |
1405 |
+ buffer.append(CRLF); |
1406 |
|
1407 |
- char* queryAsASCII = 0; |
1408 |
- ArrayJanitor<char> janBuf5(queryAsASCII, fMemoryManager); |
1409 |
- if (query) |
1410 |
- { |
1411 |
- transSize = XMLString::stringLen(query)+1; |
1412 |
- queryAsASCII = (char*) fMemoryManager->allocate |
1413 |
- ( |
1414 |
- (transSize+1) * sizeof(char) |
1415 |
- );//new char[transSize+1]; |
1416 |
- janBuf5.reset(queryAsASCII, fMemoryManager); |
1417 |
- trans->transcodeTo(query, transSize, (unsigned char *) queryAsASCII, transSize, charsEaten, XMLTranscoder::UnRep_Throw); |
1418 |
+ const XMLCh *username = urlSource.getUser(); |
1419 |
+ const XMLCh *password = urlSource.getPassword(); |
1420 |
+ if(username && password) { |
1421 |
+ XMLBuffer userPassBuf(256, fMemoryManager); |
1422 |
+ userPassBuf.append(username); |
1423 |
+ userPassBuf.append(chColon); |
1424 |
+ userPassBuf.append(password); |
1425 |
+ |
1426 |
+ TranscodeStr userPass(userPassBuf.getRawBuffer(), trans, fMemoryManager); |
1427 |
+ |
1428 |
+ unsigned int len; |
1429 |
+ XMLByte* encodedData = Base64::encode((XMLByte*)userPass.str(), userPass.len() - 1, &len, fMemoryManager); |
1430 |
+ ArrayJanitor<XMLByte> janBuf2(encodedData, fMemoryManager); |
1431 |
+ |
1432 |
+ if(encodedData) { |
1433 |
+ // HTTP doesn't want the 0x0A separating the data in chunks of 76 chars per line |
1434 |
+ XMLByte* authData = (XMLByte*)fMemoryManager->allocate((len+1)*sizeof(XMLByte)); |
1435 |
+ ArrayJanitor<XMLByte> janBuf(authData, fMemoryManager); |
1436 |
+ XMLByte *cursor = authData; |
1437 |
+ for(unsigned int i = 0; i < len; ++i) |
1438 |
+ if(encodedData[i] != chLF) |
1439 |
+ *cursor++ = encodedData[i]; |
1440 |
+ *cursor++ = 0; |
1441 |
+ buffer.append(AUTHORIZATION); |
1442 |
+ buffer.append((char*)authData); |
1443 |
+ buffer.append(CRLF); |
1444 |
+ } |
1445 |
} |
1446 |
|
1447 |
- unsigned short portNumber = (unsigned short) urlSource.getPortNum(); |
1448 |
+ if(httpInfo && httpInfo->fHeaders) |
1449 |
+ buffer.append(httpInfo->fHeaders, httpInfo->fHeadersLen); |
1450 |
|
1451 |
- // |
1452 |
- // Convert port number integer to unicode so we can transcode it to ASCII |
1453 |
- // |
1454 |
+ buffer.append(CRLF); |
1455 |
+} |
1456 |
|
1457 |
- XMLString::binToText((unsigned int) portNumber, portBuffer, bufSize, 10, fMemoryManager); |
1458 |
- transSize = XMLString::stringLen(portBuffer)+1; |
1459 |
- char* portAsASCII = (char*) fMemoryManager->allocate |
1460 |
- ( |
1461 |
- (transSize+1) * sizeof(char) |
1462 |
- );//new char[transSize+1]; |
1463 |
- ArrayJanitor<char> janBuf6(portAsASCII, fMemoryManager); |
1464 |
- trans->transcodeTo(portBuffer, transSize, (unsigned char *) portAsASCII, transSize, charsEaten, XMLTranscoder::UnRep_Throw); |
1465 |
+int UnixHTTPURLInputStream::parseResponseStatus() const |
1466 |
+{ |
1467 |
+ char *p = const_cast<char*>(strstr(fBuffer.getRawBuffer(), "HTTP")); |
1468 |
+ if(p == 0) return -1; |
1469 |
|
1470 |
- delete trans; |
1471 |
+ p = strchr(p, chSpace); |
1472 |
+ if(p == 0) return -1; |
1473 |
+ |
1474 |
+ return atoi(p); |
1475 |
+} |
1476 |
|
1477 |
- // |
1478 |
- // Set up a socket. |
1479 |
- // |
1480 |
- struct hostent* hostEntPtr = 0; |
1481 |
- struct sockaddr_in sa; |
1482 |
+XMLCh *UnixHTTPURLInputStream::findHeader(const char *name) const |
1483 |
+{ |
1484 |
+ int len = strlen(name); |
1485 |
|
1486 |
- // Use the hostName in the local code page .... |
1487 |
- if ((hostEntPtr = gethostbyname(hostNameAsCharStar)) == NULL) |
1488 |
- { |
1489 |
- unsigned long numAddress = inet_addr(hostNameAsCharStar); |
1490 |
- if (numAddress < 0) |
1491 |
- { |
1492 |
- ThrowXMLwithMemMgr1(NetAccessorException, |
1493 |
- XMLExcepts::NetAcc_TargetResolution, hostName, fMemoryManager); |
1494 |
+ char *p = const_cast<char*>(strstr(fBuffer.getRawBuffer(), name)); |
1495 |
+ while(p != 0) { |
1496 |
+ if(*(p - 1) == '\n' && |
1497 |
+ *(p + len) == ':' && |
1498 |
+ *(p + len + 1) == ' ') { |
1499 |
+ |
1500 |
+ p += len + 2; |
1501 |
+ |
1502 |
+ char *endP = strstr(p, CRLF); |
1503 |
+ if(endP == 0) { |
1504 |
+ for(endP = p; *endP != 0; ++endP); |
1505 |
+ } |
1506 |
+ |
1507 |
+ char tmp = *endP; |
1508 |
+ *endP = 0; |
1509 |
+ |
1510 |
+ XMLCh *value = XMLString::transcode(p, fMemoryManager); |
1511 |
+ *endP = tmp; |
1512 |
+ return value; |
1513 |
} |
1514 |
- if ((hostEntPtr = |
1515 |
- gethostbyaddr((char *) &numAddress, |
1516 |
- sizeof(unsigned long), AF_INET)) == NULL) |
1517 |
- { |
1518 |
- ThrowXMLwithMemMgr1(NetAccessorException, |
1519 |
- XMLExcepts::NetAcc_TargetResolution, hostName, fMemoryManager); |
1520 |
- } |
1521 |
- } |
1522 |
- |
1523 |
- memset(&sa, '\0', sizeof(sockaddr_in)); // iSeries fix ?? |
1524 |
- memcpy((void *) &sa.sin_addr, |
1525 |
- (const void *) hostEntPtr->h_addr, hostEntPtr->h_length); |
1526 |
- sa.sin_family = hostEntPtr->h_addrtype; |
1527 |
- sa.sin_port = htons(portNumber); |
1528 |
|
1529 |
- int s = socket(hostEntPtr->h_addrtype, SOCK_STREAM, 0); |
1530 |
- if (s < 0) |
1531 |
- { |
1532 |
- ThrowXMLwithMemMgr1(NetAccessorException, |
1533 |
- XMLExcepts::NetAcc_CreateSocket, urlSource.getURLText(), fMemoryManager); |
1534 |
+ p = strstr(p + 1, name); |
1535 |
} |
1536 |
- SocketJanitor janSock(&s); |
1537 |
|
1538 |
- if (connect(s, (struct sockaddr *) &sa, sizeof(sa)) < 0) |
1539 |
- { |
1540 |
- ThrowXMLwithMemMgr1(NetAccessorException, |
1541 |
- XMLExcepts::NetAcc_ConnSocket, urlSource.getURLText(), fMemoryManager); |
1542 |
- } |
1543 |
+ return 0; |
1544 |
+} |
1545 |
|
1546 |
- // The port is open and ready to go. |
1547 |
- // Build up the http GET command to send to the server. |
1548 |
- // To do: We should really support http 1.1. This implementation |
1549 |
- // is weak. |
1550 |
- if(httpInfo==0) |
1551 |
- strcpy(fBuffer, GET); |
1552 |
- else |
1553 |
- switch(httpInfo->fHTTPMethod) |
1554 |
- { |
1555 |
- case XMLNetHTTPInfo::GET: strcpy(fBuffer, GET); break; |
1556 |
- case XMLNetHTTPInfo::PUT: strcpy(fBuffer, PUT); break; |
1557 |
- case XMLNetHTTPInfo::POST: strcpy(fBuffer, POST); break; |
1558 |
- } |
1559 |
- if (pathAsASCII != 0) |
1560 |
- { |
1561 |
- strcat(fBuffer, pathAsASCII); |
1562 |
- } |
1563 |
+bool UnixHTTPURLInputStream::send(const char *buf, unsigned int len) |
1564 |
+{ |
1565 |
+ unsigned int done = 0; |
1566 |
+ int ret; |
1567 |
|
1568 |
- if (queryAsASCII != 0) |
1569 |
- { |
1570 |
- size_t n = strlen(fBuffer); |
1571 |
- fBuffer[n] = chQuestion; |
1572 |
- fBuffer[n+1] = chNull; |
1573 |
- strcat(fBuffer, queryAsASCII); |
1574 |
+ while(done < len) { |
1575 |
+ ret = ::send(fSocket, buf + done, len - done, 0); |
1576 |
+ if(ret == -1) return false; |
1577 |
+ done += ret; |
1578 |
} |
1579 |
|
1580 |
- if (fragmentAsASCII != 0) |
1581 |
- { |
1582 |
- strcat(fBuffer, fragmentAsASCII); |
1583 |
- } |
1584 |
- strcat(fBuffer, HTTP10); |
1585 |
+ return true; |
1586 |
+} |
1587 |
|
1588 |
- strcat(fBuffer, HOST); |
1589 |
- strcat(fBuffer, hostNameAsASCII); |
1590 |
- if (portNumber != 80) |
1591 |
- { |
1592 |
- strcat(fBuffer,COLON); |
1593 |
- strcat(fBuffer,portAsASCII); |
1594 |
- } |
1595 |
- strcat(fBuffer, CRLF); |
1596 |
+UnixHTTPURLInputStream::UnixHTTPURLInputStream(const XMLURL& urlSource, const XMLNetHTTPInfo* httpInfo/*=0*/) |
1597 |
+ : fSocket(0) |
1598 |
+ , fBytesProcessed(0) |
1599 |
+ , fBuffer(1023, urlSource.getMemoryManager()) |
1600 |
+ , fContentType(0) |
1601 |
+ , fMemoryManager(urlSource.getMemoryManager()) |
1602 |
+{ |
1603 |
+ // |
1604 |
+ // Constants in ASCII to send/check in the HTTP request/response |
1605 |
+ // |
1606 |
|
1607 |
- const XMLCh* username = urlSource.getUser(); |
1608 |
- const XMLCh* password = urlSource.getPassword(); |
1609 |
- if (username && password) |
1610 |
- { |
1611 |
- XMLBuffer userPass(256, fMemoryManager); |
1612 |
- userPass.append(username); |
1613 |
- userPass.append(chColon); |
1614 |
- userPass.append(password); |
1615 |
- char* userPassAsCharStar = XMLString::transcode(userPass.getRawBuffer(), fMemoryManager); |
1616 |
- ArrayJanitor<char> janBuf(userPassAsCharStar, fMemoryManager); |
1617 |
+ static const char *CRLF2X = "\r\n\r\n"; |
1618 |
+ static const char *LF2X = "\n\n"; |
1619 |
|
1620 |
- unsigned int len; |
1621 |
- XMLByte* encodedData = Base64::encode((XMLByte *)userPassAsCharStar, strlen(userPassAsCharStar), &len, fMemoryManager); |
1622 |
- ArrayJanitor<XMLByte> janBuf2(encodedData, fMemoryManager); |
1623 |
+ // |
1624 |
+ // Convert the hostName to the platform's code page for gethostbyname and |
1625 |
+ // inet_addr functions. |
1626 |
+ // |
1627 |
|
1628 |
- if (encodedData) |
1629 |
- { |
1630 |
- // HTTP doesn't want the 0x0A separating the data in chunks of 76 chars per line |
1631 |
- XMLByte* authData = (XMLByte*)fMemoryManager->allocate((len+1)*sizeof(XMLByte)); |
1632 |
- ArrayJanitor<XMLByte> janBuf(authData, fMemoryManager); |
1633 |
- XMLByte* cursor=authData; |
1634 |
- for(unsigned int i=0;i<len;i++) |
1635 |
- if(encodedData[i]!=chLF) |
1636 |
- *cursor++=encodedData[i]; |
1637 |
- *cursor++=0; |
1638 |
- strcat(fBuffer, AUTHORIZATION); |
1639 |
- strcat(fBuffer, (char*)authData); |
1640 |
- strcat(fBuffer, CRLF); |
1641 |
- } |
1642 |
- } |
1643 |
+ const XMLCh* hostName = urlSource.getHost(); |
1644 |
+ char* hostNameAsCharStar = XMLString::transcode(hostName, fMemoryManager); |
1645 |
+ ArrayJanitor<char> janHostNameAsCharStar(hostNameAsCharStar, fMemoryManager); |
1646 |
|
1647 |
- if(httpInfo!=0 && httpInfo->fHeaders!=0) |
1648 |
- strncat(fBuffer,httpInfo->fHeaders,httpInfo->fHeadersLen); |
1649 |
+ XMLURL url(urlSource); |
1650 |
+ int redirectCount = 0; |
1651 |
+ SocketJanitor janSock(0); |
1652 |
+ |
1653 |
+ do { |
1654 |
+ // |
1655 |
+ // Set up a socket. |
1656 |
+ // |
1657 |
|
1658 |
- strcat(fBuffer, CRLF); |
1659 |
+ struct hostent *hostEntPtr = 0; |
1660 |
+ struct sockaddr_in sa; |
1661 |
|
1662 |
- // Send the http request |
1663 |
- int lent = strlen(fBuffer); |
1664 |
- int aLent = 0; |
1665 |
+ // Use the hostName in the local code page .... |
1666 |
+ if((hostEntPtr = gethostbyname(hostNameAsCharStar)) == NULL) |
1667 |
+ { |
1668 |
+ unsigned long numAddress = inet_addr(hostNameAsCharStar); |
1669 |
+ if ((hostEntPtr = |
1670 |
+ gethostbyaddr((char *) &numAddress, |
1671 |
+ sizeof(unsigned long), AF_INET)) == NULL) |
1672 |
+ { |
1673 |
+ ThrowXMLwithMemMgr1(NetAccessorException, |
1674 |
+ XMLExcepts::NetAcc_TargetResolution, hostName, fMemoryManager); |
1675 |
+ } |
1676 |
+ } |
1677 |
|
1678 |
- if ((aLent = write(s, (void *) fBuffer, lent)) != lent) |
1679 |
- { |
1680 |
- ThrowXMLwithMemMgr1(NetAccessorException, |
1681 |
- XMLExcepts::NetAcc_WriteSocket, urlSource.getURLText(), fMemoryManager); |
1682 |
- } |
1683 |
+ memset(&sa, '\0', sizeof(sockaddr_in)); // iSeries fix ?? |
1684 |
+ memcpy((void *) &sa.sin_addr, |
1685 |
+ (const void *) hostEntPtr->h_addr, hostEntPtr->h_length); |
1686 |
+ sa.sin_family = hostEntPtr->h_addrtype; |
1687 |
+ sa.sin_port = htons((unsigned short)url.getPortNum()); |
1688 |
+ |
1689 |
+ janSock.reset(); |
1690 |
+ fSocket = socket(hostEntPtr->h_addrtype, SOCK_STREAM, 0); |
1691 |
+ if(fSocket < 0) |
1692 |
+ { |
1693 |
+ ThrowXMLwithMemMgr1(NetAccessorException, |
1694 |
+ XMLExcepts::NetAcc_CreateSocket, url.getURLText(), fMemoryManager); |
1695 |
+ } |
1696 |
+ janSock.reset(&fSocket); |
1697 |
|
1698 |
- if(httpInfo!=0 && httpInfo->fPayload!=0) { |
1699 |
- int aLent = 0; |
1700 |
- if ((aLent = write(s, (void *) httpInfo->fPayload, httpInfo->fPayloadLen)) != httpInfo->fPayloadLen) |
1701 |
+ if(connect(fSocket, (struct sockaddr *) &sa, sizeof(sa)) < 0) |
1702 |
{ |
1703 |
ThrowXMLwithMemMgr1(NetAccessorException, |
1704 |
- XMLExcepts::NetAcc_WriteSocket, urlSource.getURLText(), fMemoryManager); |
1705 |
+ XMLExcepts::NetAcc_ConnSocket, url.getURLText(), fMemoryManager); |
1706 |
} |
1707 |
- } |
1708 |
|
1709 |
- // |
1710 |
- // get the response, check the http header for errors from the server. |
1711 |
- // |
1712 |
- aLent = read(s, (void *)fBuffer, sizeof(fBuffer)-1); |
1713 |
- if (aLent <= 0) |
1714 |
- { |
1715 |
- ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_ReadSocket, urlSource.getURLText(), fMemoryManager); |
1716 |
- } |
1717 |
|
1718 |
- fBufferEnd = fBuffer+aLent; |
1719 |
- *fBufferEnd = 0; |
1720 |
+ // The port is open and ready to go. |
1721 |
+ // Build up the http GET command to send to the server. |
1722 |
+ CharBuffer requestBuffer(1023, fMemoryManager); |
1723 |
+ createHTTPRequest(url, httpInfo, requestBuffer); |
1724 |
|
1725 |
- // Find the break between the returned http header and any data. |
1726 |
- // (Delimited by a blank line) |
1727 |
- // Hang on to any data for use by the first read from this BinHTTPURLInputStream. |
1728 |
- // |
1729 |
- fBufferPos = strstr(fBuffer, CRLF2X); |
1730 |
- if (fBufferPos != 0) |
1731 |
- { |
1732 |
- fBufferPos += 4; |
1733 |
- *(fBufferPos-2) = 0; |
1734 |
- } |
1735 |
- else |
1736 |
- { |
1737 |
- fBufferPos = strstr(fBuffer, LF2X); |
1738 |
- if (fBufferPos != 0) |
1739 |
- { |
1740 |
- fBufferPos += 2; |
1741 |
- *(fBufferPos-1) = 0; |
1742 |
+ // Send the http request |
1743 |
+ if(!send(requestBuffer.getRawBuffer(), requestBuffer.getLen())) { |
1744 |
+ ThrowXMLwithMemMgr1(NetAccessorException, |
1745 |
+ XMLExcepts::NetAcc_WriteSocket, url.getURLText(), fMemoryManager); |
1746 |
} |
1747 |
- else |
1748 |
- fBufferPos = fBufferEnd; |
1749 |
- } |
1750 |
|
1751 |
- // Make sure the header includes an HTTP 200 OK response. |
1752 |
- // |
1753 |
- char *p = strstr(fBuffer, HTTP); |
1754 |
- if (p == 0) |
1755 |
- { |
1756 |
- ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_ReadSocket, urlSource.getURLText(), fMemoryManager); |
1757 |
- } |
1758 |
+ if(httpInfo && httpInfo->fPayload) { |
1759 |
+ if(!send(httpInfo->fPayload, httpInfo->fPayloadLen)) { |
1760 |
+ ThrowXMLwithMemMgr1(NetAccessorException, |
1761 |
+ XMLExcepts::NetAcc_WriteSocket, url.getURLText(), fMemoryManager); |
1762 |
+ } |
1763 |
+ } |
1764 |
|
1765 |
- p = strchr(p, chSpace); |
1766 |
- if (p == 0) |
1767 |
- { |
1768 |
- ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_ReadSocket, urlSource.getURLText(), fMemoryManager); |
1769 |
- } |
1770 |
- |
1771 |
- if (memcmp(p, resp200, strlen(resp200))) |
1772 |
- { |
1773 |
- // Most likely a 404 Not Found error. |
1774 |
- // Should recognize and handle the forwarding responses. |
1775 |
// |
1776 |
- ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::File_CouldNotOpenFile, urlSource.getURLText(), fMemoryManager); |
1777 |
- } |
1778 |
+ // get the response, check the http header for errors from the server. |
1779 |
+ // |
1780 |
+ char tmpBuf[1024]; |
1781 |
+ int ret; |
1782 |
+ |
1783 |
+ fBuffer.reset(); |
1784 |
+ while(true) { |
1785 |
+ ret = ::recv(fSocket, tmpBuf, sizeof(tmpBuf), 0); |
1786 |
+ if(ret == -1) { |
1787 |
+ ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_ReadSocket, url.getURLText(), fMemoryManager); |
1788 |
+ } |
1789 |
+ |
1790 |
+ fBuffer.append(tmpBuf, ret); |
1791 |
+ |
1792 |
+ fBufferPos = strstr(fBuffer.getRawBuffer(), CRLF2X); |
1793 |
+ if(fBufferPos != 0) { |
1794 |
+ fBufferPos += 4; |
1795 |
+ *(fBufferPos - 2) = 0; |
1796 |
+ break; |
1797 |
+ } |
1798 |
+ |
1799 |
+ fBufferPos = strstr(fBuffer.getRawBuffer(), LF2X); |
1800 |
+ if(fBufferPos != 0) { |
1801 |
+ fBufferPos += 2; |
1802 |
+ *(fBufferPos - 1) = 0; |
1803 |
+ break; |
1804 |
+ } |
1805 |
+ } |
1806 |
+ |
1807 |
+ int status = parseResponseStatus(); |
1808 |
+ if(status < 0) { |
1809 |
+ ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_ReadSocket, url.getURLText(), fMemoryManager); |
1810 |
+ } |
1811 |
|
1812 |
- fSocket = *janSock.release(); |
1813 |
+ if(status == 200) { |
1814 |
+ // HTTP 200 OK response means we're done. |
1815 |
+ // We're done |
1816 |
+ break; |
1817 |
+ } |
1818 |
+ // a 3xx response means there was an HTTP redirect |
1819 |
+ else if(status >= 300 && status <= 307) { |
1820 |
+ redirectCount++; |
1821 |
+ |
1822 |
+ XMLCh *newURLString = findHeader("Location"); |
1823 |
+ ArrayJanitor<XMLCh> janNewURLString(newURLString, fMemoryManager); |
1824 |
+ |
1825 |
+ XMLURL newURL(fMemoryManager); |
1826 |
+ newURL.setURL(url, newURLString); |
1827 |
+ if(newURL.getProtocol() != XMLURL::HTTP) { |
1828 |
+ ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::File_CouldNotOpenFile, newURL.getURLText(), fMemoryManager); |
1829 |
+ } |
1830 |
+ |
1831 |
+ url = newURL; |
1832 |
+ |
1833 |
+ janHostNameAsCharStar.release(); |
1834 |
+ hostNameAsCharStar = XMLString::transcode(newURL.getHost(), fMemoryManager); |
1835 |
+ janHostNameAsCharStar.reset(hostNameAsCharStar, fMemoryManager); |
1836 |
+ } |
1837 |
+ else { |
1838 |
+ // Most likely a 404 Not Found error. |
1839 |
+ ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::File_CouldNotOpenFile, url.getURLText(), fMemoryManager); |
1840 |
+ } |
1841 |
+ } while(redirectCount < 6); |
1842 |
|
1843 |
+ janSock.release(); |
1844 |
} |
1845 |
|
1846 |
|
1847 |
@@ -450,14 +459,24 @@ |
1848 |
{ |
1849 |
shutdown(fSocket, 2); |
1850 |
close(fSocket); |
1851 |
+ |
1852 |
+ if(fContentType) fMemoryManager->deallocate(fContentType); |
1853 |
} |
1854 |
|
1855 |
+const XMLCh *UnixHTTPURLInputStream::getContentType() const |
1856 |
+{ |
1857 |
+ if(fContentType == 0) { |
1858 |
+ // mutable |
1859 |
+ const_cast<XMLCh*&>(fContentType) = findHeader("Content-Type"); |
1860 |
+ } |
1861 |
+ return fContentType; |
1862 |
+} |
1863 |
|
1864 |
unsigned int UnixHTTPURLInputStream::readBytes(XMLByte* const toFill |
1865 |
, const unsigned int maxToRead) |
1866 |
{ |
1867 |
- unsigned int len = fBufferEnd - fBufferPos; |
1868 |
- if (len > 0) |
1869 |
+ unsigned int len = fBuffer.getRawBuffer() + fBuffer.getLen() - fBufferPos; |
1870 |
+ if(len > 0) |
1871 |
{ |
1872 |
// If there's any data left over in the buffer into which we first |
1873 |
// read from the server (to get the http header), return that. |
1874 |
@@ -472,7 +491,7 @@ |
1875 |
// Read some from the socket, straight into our caller's buffer. |
1876 |
// |
1877 |
len = read(fSocket, (void *) toFill, maxToRead); |
1878 |
- if (len == -1) |
1879 |
+ if (len == (unsigned int)-1) |
1880 |
{ |
1881 |
ThrowXMLwithMemMgr(NetAccessorException, XMLExcepts::NetAcc_ReadSocket, fMemoryManager); |
1882 |
} |
1883 |
diff -ru xerces-c-src_2_8_0-release/src/xercesc/util/NetAccessors/Socket/UnixHTTPURLInputStream.hpp xerces-c-src_2_8_0/src/xercesc/util/NetAccessors/Socket/UnixHTTPURLInputStream.hpp |
1884 |
--- xerces-c-src_2_8_0-release/src/xercesc/util/NetAccessors/Socket/UnixHTTPURLInputStream.hpp 2008-02-08 15:30:17.000000000 +0000 |
1885 |
+++ xerces-c-src_2_8_0/src/xercesc/util/NetAccessors/Socket/UnixHTTPURLInputStream.hpp 2008-01-28 23:49:33.000000000 +0000 |
1886 |
@@ -27,10 +27,132 @@ |
1887 |
#include <xercesc/util/XMLExceptMsgs.hpp> |
1888 |
#include <xercesc/util/BinInputStream.hpp> |
1889 |
#include <xercesc/util/XMLNetAccessor.hpp> |
1890 |
+#include <xercesc/framework/MemoryManager.hpp> |
1891 |
|
1892 |
XERCES_CPP_NAMESPACE_BEGIN |
1893 |
|
1894 |
// |
1895 |
+// This class implements a simple expanding character buffer |
1896 |
+// |
1897 |
+class XMLUTIL_EXPORT CharBuffer |
1898 |
+{ |
1899 |
+public: |
1900 |
+ CharBuffer(unsigned int capacity = 1023, |
1901 |
+ MemoryManager *manager = XMLPlatformUtils::fgMemoryManager) |
1902 |
+ : fCapacity(capacity), |
1903 |
+ fIndex(0), |
1904 |
+ fMemoryManager(manager) |
1905 |
+ { |
1906 |
+ fBuffer = (char*)fMemoryManager->allocate((fCapacity + 1) * sizeof(char)); |
1907 |
+ } |
1908 |
+ |
1909 |
+ ~CharBuffer() |
1910 |
+ { |
1911 |
+ fMemoryManager->deallocate(fBuffer); |
1912 |
+ } |
1913 |
+ |
1914 |
+ const char* getRawBuffer() const |
1915 |
+ { |
1916 |
+ fBuffer[fIndex] = 0; |
1917 |
+ return fBuffer; |
1918 |
+ } |
1919 |
+ |
1920 |
+ char* getRawBuffer() |
1921 |
+ { |
1922 |
+ fBuffer[fIndex] = 0; |
1923 |
+ return fBuffer; |
1924 |
+ } |
1925 |
+ |
1926 |
+ unsigned int getLen() const |
1927 |
+ { |
1928 |
+ return fIndex; |
1929 |
+ } |
1930 |
+ |
1931 |
+ void reset() |
1932 |
+ { |
1933 |
+ fIndex = 0; |
1934 |
+ } |
1935 |
+ |
1936 |
+ void append(const char *chars) |
1937 |
+ { |
1938 |
+ if(chars != 0 && *chars != 0) { |
1939 |
+ // get length of chars |
1940 |
+ unsigned int count = 0; |
1941 |
+ for(; *(chars+count); ++count); |
1942 |
+ |
1943 |
+ if(fIndex + count >= fCapacity) { |
1944 |
+ insureCapacity(count); |
1945 |
+ } |
1946 |
+ memcpy(&fBuffer[fIndex], chars, count * sizeof(char)); |
1947 |
+ fIndex += count; |
1948 |
+ } |
1949 |
+ } |
1950 |
+ |
1951 |
+ void append(const char *chars, unsigned int len) |
1952 |
+ { |
1953 |
+ if(chars != 0 && len != 0) { |
1954 |
+ if(fIndex + len >= fCapacity) { |
1955 |
+ insureCapacity(len); |
1956 |
+ } |
1957 |
+ memcpy(&fBuffer[fIndex], chars, len * sizeof(char)); |
1958 |
+ fIndex += len; |
1959 |
+ } |
1960 |
+ } |
1961 |
+ |
1962 |
+ void appendDecimalNumber(unsigned int n) |
1963 |
+ { |
1964 |
+ if(n >= 10) appendDecimalNumber(n / 10); |
1965 |
+ |
1966 |
+ if(fIndex + 1 >= fCapacity) |
1967 |
+ insureCapacity(1); |
1968 |
+ |
1969 |
+ fBuffer[fIndex] = '0' + n; |
1970 |
+ ++fIndex; |
1971 |
+ } |
1972 |
+ |
1973 |
+ void set(const char *chars) |
1974 |
+ { |
1975 |
+ reset(); |
1976 |
+ append(chars); |
1977 |
+ } |
1978 |
+ |
1979 |
+private: |
1980 |
+ // ----------------------------------------------------------------------- |
1981 |
+ // Unimplemented constructors and operators |
1982 |
+ // ----------------------------------------------------------------------- |
1983 |
+ CharBuffer(const CharBuffer &); |
1984 |
+ CharBuffer &operator=(const CharBuffer &); |
1985 |
+ |
1986 |
+ void insureCapacity(unsigned int extraNeeded) |
1987 |
+ { |
1988 |
+ // If we can't handle it, try doubling the buffer size. |
1989 |
+ unsigned int newCap = (fIndex + extraNeeded) * 2; |
1990 |
+ |
1991 |
+ if(newCap > fCapacity) |
1992 |
+ { |
1993 |
+ // Allocate new buffer |
1994 |
+ char* newBuf = (char*)fMemoryManager->allocate((newCap + 1) * sizeof(char)); |
1995 |
+ |
1996 |
+ // Copy over the old stuff |
1997 |
+ memcpy(newBuf, fBuffer, fIndex * sizeof(char)); |
1998 |
+ |
1999 |
+ // Clean up old buffer and store new stuff |
2000 |
+ fMemoryManager->deallocate(fBuffer); |
2001 |
+ fBuffer = newBuf; |
2002 |
+ fCapacity = newCap; |
2003 |
+ } |
2004 |
+ } |
2005 |
+ |
2006 |
+ // ----------------------------------------------------------------------- |
2007 |
+ // Private data members |
2008 |
+ // ----------------------------------------------------------------------- |
2009 |
+ char *fBuffer; |
2010 |
+ unsigned int fCapacity; |
2011 |
+ unsigned int fIndex; |
2012 |
+ MemoryManager *fMemoryManager; |
2013 |
+}; |
2014 |
+ |
2015 |
+// |
2016 |
// This class implements the BinInputStream interface specified by the XML |
2017 |
// parser. |
2018 |
// |
2019 |
@@ -48,6 +170,7 @@ |
2020 |
, const unsigned int maxToRead |
2021 |
); |
2022 |
|
2023 |
+ const XMLCh *getContentType() const; |
2024 |
|
2025 |
private : |
2026 |
// ----------------------------------------------------------------------- |
2027 |
@@ -56,6 +179,11 @@ |
2028 |
UnixHTTPURLInputStream(const UnixHTTPURLInputStream&); |
2029 |
UnixHTTPURLInputStream& operator=(const UnixHTTPURLInputStream&); |
2030 |
|
2031 |
+ void createHTTPRequest(const XMLURL &urlSource, const XMLNetHTTPInfo *httpInfo, CharBuffer &buffer); |
2032 |
+ int parseResponseStatus() const; |
2033 |
+ XMLCh *findHeader(const char *name) const; |
2034 |
+ bool send(const char *buf, unsigned int len); |
2035 |
+ |
2036 |
// ----------------------------------------------------------------------- |
2037 |
// Private data members |
2038 |
// |
2039 |
@@ -68,16 +196,16 @@ |
2040 |
// Holds the http header, plus the first part of the actual |
2041 |
// data. Filled at the time the stream is opened, data goes |
2042 |
// out to user in response to readBytes(). |
2043 |
- // fBufferPos, fBufferEnd |
2044 |
+ // fBufferPos |
2045 |
// Pointers into fBuffer, showing start and end+1 of content |
2046 |
// that readBytes must return. |
2047 |
// ----------------------------------------------------------------------- |
2048 |
|
2049 |
int fSocket; |
2050 |
unsigned int fBytesProcessed; |
2051 |
- char fBuffer[4000]; |
2052 |
- char * fBufferEnd; |
2053 |
+ CharBuffer fBuffer; |
2054 |
char * fBufferPos; |
2055 |
+ XMLCh * fContentType; |
2056 |
MemoryManager* fMemoryManager; |
2057 |
}; // UnixHTTPURLInputStream |
2058 |
|
2059 |
--- xerces-c-src_2_8_0-release/src/xercesc/util/NetAccessors/WinSock/BinHTTPURLInputStream.cpp 2007-08-28 14:44:16.000000000 -0400 |
2060 |
+++ xerces-c-src_2_8_0/src/xercesc/util/NetAccessors/WinSock/BinHTTPURLInputStream.cpp 2008-02-11 15:03:57.000000000 -0500 |
2061 |
@@ -20,9 +20,6 @@ |
2062 |
*/ |
2063 |
|
2064 |
|
2065 |
-#define INCL_WINSOCK_API_TYPEDEFS 1 |
2066 |
-#include <winsock2.h> |
2067 |
-#include <windows.h> |
2068 |
#include <tchar.h> |
2069 |
|
2070 |
#include <stdio.h> |
2071 |
@@ -37,6 +34,7 @@ |
2072 |
#include <xercesc/util/Janitor.hpp> |
2073 |
#include <xercesc/util/XMLUniDefs.hpp> |
2074 |
#include <xercesc/util/Base64.hpp> |
2075 |
+#include <xercesc/util/TransService.hpp> |
2076 |
|
2077 |
XERCES_CPP_NAMESPACE_BEGIN |
2078 |
|
2079 |
@@ -52,7 +50,14 @@ |
2080 |
SOCKET* get() const { return fData; } |
2081 |
SOCKET* release() { SOCKET* p = fData; fData = 0; return p; } |
2082 |
|
2083 |
- void reset(SOCKET* p = 0) { if(fData) BinHTTPURLInputStream::closesocket(*fData); fData=p; } |
2084 |
+ void reset(SOCKET* p = 0) |
2085 |
+ { |
2086 |
+ if(fData) { |
2087 |
+ BinHTTPURLInputStream::shutdown(*fData, SD_BOTH); |
2088 |
+ BinHTTPURLInputStream::closesocket(*fData); |
2089 |
+ } |
2090 |
+ fData = p; |
2091 |
+ } |
2092 |
bool isDataNull() { return (fData == 0); } |
2093 |
|
2094 |
private : |
2095 |
@@ -73,6 +78,218 @@ |
2096 |
SOCKET* fData; |
2097 |
}; |
2098 |
|
2099 |
+class TranscodeStr |
2100 |
+{ |
2101 |
+public: |
2102 |
+ TranscodeStr(const XMLCh *in, XMLTranscoder* trans, |
2103 |
+ MemoryManager *manager = XMLPlatformUtils::fgMemoryManager) |
2104 |
+ : fString(0), |
2105 |
+ fBytesWritten(0), |
2106 |
+ fMemoryManager(manager) |
2107 |
+ { |
2108 |
+ if(in) { |
2109 |
+ unsigned int len = XMLString::stringLen(in) + 1; |
2110 |
+ |
2111 |
+ unsigned int allocSize = len * sizeof(XMLCh); |
2112 |
+ fString = (unsigned char*)fMemoryManager->allocate(allocSize); |
2113 |
+ |
2114 |
+ unsigned int charsRead; |
2115 |
+ |
2116 |
+ unsigned int charsDone = 0; |
2117 |
+ |
2118 |
+ while(true) { |
2119 |
+ fBytesWritten += trans->transcodeTo(in + charsDone, len - charsDone, |
2120 |
+ fString + fBytesWritten, allocSize - fBytesWritten, |
2121 |
+ charsRead, XMLTranscoder::UnRep_Throw); |
2122 |
+ charsDone += charsRead; |
2123 |
+ |
2124 |
+ if(charsDone == len) break; |
2125 |
+ |
2126 |
+ allocSize *= 2; |
2127 |
+ unsigned char *newBuf = (unsigned char*)fMemoryManager->allocate(allocSize); |
2128 |
+ memcpy(newBuf, fString, fBytesWritten); |
2129 |
+ fMemoryManager->deallocate(fString); |
2130 |
+ fString = newBuf; |
2131 |
+ } |
2132 |
+ } |
2133 |
+ } |
2134 |
+ |
2135 |
+ ~TranscodeStr() |
2136 |
+ { |
2137 |
+ if(fString) |
2138 |
+ fMemoryManager->deallocate(fString); |
2139 |
+ } |
2140 |
+ |
2141 |
+ const unsigned char *str() const |
2142 |
+ { |
2143 |
+ return fString; |
2144 |
+ } |
2145 |
+ |
2146 |
+ unsigned int len() const |
2147 |
+ { |
2148 |
+ return fBytesWritten; |
2149 |
+ } |
2150 |
+ |
2151 |
+private: |
2152 |
+ unsigned char *fString; |
2153 |
+ unsigned int fBytesWritten; |
2154 |
+ MemoryManager *fMemoryManager; |
2155 |
+}; |
2156 |
+ |
2157 |
+static const char *CRLF = "\r\n"; |
2158 |
+ |
2159 |
+void BinHTTPURLInputStream::createHTTPRequest(const XMLURL &urlSource, const XMLNetHTTPInfo *httpInfo, CharBuffer &buffer) |
2160 |
+{ |
2161 |
+ static const char *GET = "GET "; |
2162 |
+ static const char *PUT = "PUT "; |
2163 |
+ static const char *POST = "POST "; |
2164 |
+ static const char *HTTP10 = " HTTP/1.0\r\n"; |
2165 |
+ static const char *HOST = "Host: "; |
2166 |
+ static const char *AUTHORIZATION = "Authorization: Basic "; |
2167 |
+ static const char *COLON = ":"; |
2168 |
+ |
2169 |
+ XMLTransService::Codes failReason; |
2170 |
+ const unsigned int blockSize = 2048; |
2171 |
+ |
2172 |
+ XMLTranscoder* trans = XMLPlatformUtils::fgTransService->makeNewTranscoderFor("ISO8859-1", failReason, blockSize, fMemoryManager); |
2173 |
+ Janitor<XMLTranscoder> janTrans(trans); |
2174 |
+ |
2175 |
+ TranscodeStr hostName(urlSource.getHost(), trans, fMemoryManager); |
2176 |
+ TranscodeStr path(urlSource.getPath(), trans, fMemoryManager); |
2177 |
+ TranscodeStr fragment(urlSource.getFragment(), trans, fMemoryManager); |
2178 |
+ TranscodeStr query(urlSource.getQuery(), trans, fMemoryManager); |
2179 |
+ |
2180 |
+ // Build up the http GET command to send to the server. |
2181 |
+ // To do: We should really support http 1.1. This implementation |
2182 |
+ // is weak. |
2183 |
+ if(httpInfo) { |
2184 |
+ switch(httpInfo->fHTTPMethod) { |
2185 |
+ case XMLNetHTTPInfo::GET: buffer.append(GET); break; |
2186 |
+ case XMLNetHTTPInfo::PUT: buffer.append(PUT); break; |
2187 |
+ case XMLNetHTTPInfo::POST: buffer.append(POST); break; |
2188 |
+ } |
2189 |
+ } |
2190 |
+ else { |
2191 |
+ buffer.append(GET); |
2192 |
+ } |
2193 |
+ |
2194 |
+ if(path.str() != 0) { |
2195 |
+ buffer.append((char*)path.str()); |
2196 |
+ } |
2197 |
+ else { |
2198 |
+ buffer.append("/"); |
2199 |
+ } |
2200 |
+ |
2201 |
+ if(query.str() != 0) { |
2202 |
+ buffer.append("?"); |
2203 |
+ buffer.append((char*)query.str()); |
2204 |
+ } |
2205 |
+ |
2206 |
+ if(fragment.str() != 0) { |
2207 |
+ buffer.append((char*)fragment.str()); |
2208 |
+ } |
2209 |
+ buffer.append(HTTP10); |
2210 |
+ |
2211 |
+ buffer.append(HOST); |
2212 |
+ buffer.append((char*)hostName.str()); |
2213 |
+ if(urlSource.getPortNum() != 80) |
2214 |
+ { |
2215 |
+ buffer.append(COLON); |
2216 |
+ buffer.appendDecimalNumber(urlSource.getPortNum()); |
2217 |
+ } |
2218 |
+ buffer.append(CRLF); |
2219 |
+ |
2220 |
+ const XMLCh *username = urlSource.getUser(); |
2221 |
+ const XMLCh *password = urlSource.getPassword(); |
2222 |
+ if(username && password) { |
2223 |
+ XMLBuffer userPassBuf(256, fMemoryManager); |
2224 |
+ userPassBuf.append(username); |
2225 |
+ userPassBuf.append(chColon); |
2226 |
+ userPassBuf.append(password); |
2227 |
+ |
2228 |
+ TranscodeStr userPass(userPassBuf.getRawBuffer(), trans, fMemoryManager); |
2229 |
+ |
2230 |
+ unsigned int len; |
2231 |
+ XMLByte* encodedData = Base64::encode((XMLByte*)userPass.str(), userPass.len() - 1, &len, fMemoryManager); |
2232 |
+ ArrayJanitor<XMLByte> janBuf2(encodedData, fMemoryManager); |
2233 |
+ |
2234 |
+ if(encodedData) { |
2235 |
+ // HTTP doesn't want the 0x0A separating the data in chunks of 76 chars per line |
2236 |
+ XMLByte* authData = (XMLByte*)fMemoryManager->allocate((len+1)*sizeof(XMLByte)); |
2237 |
+ ArrayJanitor<XMLByte> janBuf(authData, fMemoryManager); |
2238 |
+ XMLByte *cursor = authData; |
2239 |
+ for(unsigned int i = 0; i < len; ++i) |
2240 |
+ if(encodedData[i] != chLF) |
2241 |
+ *cursor++ = encodedData[i]; |
2242 |
+ *cursor++ = 0; |
2243 |
+ buffer.append(AUTHORIZATION); |
2244 |
+ buffer.append((char*)authData); |
2245 |
+ buffer.append(CRLF); |
2246 |
+ } |
2247 |
+ } |
2248 |
+ |
2249 |
+ if(httpInfo && httpInfo->fHeaders) |
2250 |
+ buffer.append(httpInfo->fHeaders, httpInfo->fHeadersLen); |
2251 |
+ |
2252 |
+ buffer.append(CRLF); |
2253 |
+} |
2254 |
+ |
2255 |
+int BinHTTPURLInputStream::parseResponseStatus() const |
2256 |
+{ |
2257 |
+ char *p = strstr(const_cast<char*>(fBuffer.getRawBuffer()), "HTTP"); |
2258 |
+ if(p == 0) return -1; |
2259 |
+ |
2260 |
+ p = strchr(p, chSpace); |
2261 |
+ if(p == 0) return -1; |
2262 |
+ |
2263 |
+ return atoi(p); |
2264 |
+} |
2265 |
+ |
2266 |
+XMLCh *BinHTTPURLInputStream::findHeader(const char *name) const |
2267 |
+{ |
2268 |
+ int len = strlen(name); |
2269 |
+ |
2270 |
+ char *p = strstr(const_cast<char*>(fBuffer.getRawBuffer()), name); |
2271 |
+ while(p != 0) { |
2272 |
+ if(*(p - 1) == '\n' && |
2273 |
+ *(p + len) == ':' && |
2274 |
+ *(p + len + 1) == ' ') { |
2275 |
+ |
2276 |
+ p += len + 2; |
2277 |
+ |
2278 |
+ char *endP = strstr(p, CRLF); |
2279 |
+ if(endP == 0) { |
2280 |
+ for(endP = p; *endP != 0; ++endP); |
2281 |
+ } |
2282 |
+ |
2283 |
+ char tmp = *endP; |
2284 |
+ *endP = 0; |
2285 |
+ |
2286 |
+ XMLCh *value = XMLString::transcode(p, fMemoryManager); |
2287 |
+ *endP = tmp; |
2288 |
+ return value; |
2289 |
+ } |
2290 |
+ |
2291 |
+ p = strstr(p + 1, name); |
2292 |
+ } |
2293 |
+ |
2294 |
+ return 0; |
2295 |
+} |
2296 |
+ |
2297 |
+bool BinHTTPURLInputStream::send(const char *buf, unsigned int len) |
2298 |
+{ |
2299 |
+ unsigned int done = 0; |
2300 |
+ int ret; |
2301 |
+ |
2302 |
+ while(done < len) { |
2303 |
+ ret = send(fSocketHandle, buf + done, len - done, 0); |
2304 |
+ if(ret == SOCKET_ERROR) return false; |
2305 |
+ done += ret; |
2306 |
+ } |
2307 |
+ |
2308 |
+ return true; |
2309 |
+} |
2310 |
+ |
2311 |
static HMODULE gWinsockLib = NULL; |
2312 |
static LPFN_GETHOSTBYNAME gWSgethostbyname = NULL; |
2313 |
static LPFN_INET_ADDR gWSinet_addr = NULL; |
2314 |
@@ -190,40 +407,43 @@ |
2315 |
return (*gWShtons)(hostshort); |
2316 |
} |
2317 |
|
2318 |
-unsigned int BinHTTPURLInputStream::socket(int af,int type,int protocol) |
2319 |
+SOCKET BinHTTPURLInputStream::socket(int af,int type,int protocol) |
2320 |
{ |
2321 |
return (*gWSsocket)(af,type,protocol); |
2322 |
} |
2323 |
|
2324 |
-int BinHTTPURLInputStream::connect(unsigned int s,const sockaddr* name,int namelen) |
2325 |
+int BinHTTPURLInputStream::connect(SOCKET s,const sockaddr* name,int namelen) |
2326 |
{ |
2327 |
return (*gWSconnect)(s,name,namelen); |
2328 |
} |
2329 |
|
2330 |
-int BinHTTPURLInputStream::send(unsigned int s,const char* buf,int len,int flags) |
2331 |
+int BinHTTPURLInputStream::send(SOCKET s,const char* buf,int len,int flags) |
2332 |
{ |
2333 |
return (*gWSsend)(s,buf,len,flags); |
2334 |
} |
2335 |
|
2336 |
-int BinHTTPURLInputStream::recv(unsigned int s,char* buf,int len,int flags) |
2337 |
+int BinHTTPURLInputStream::recv(SOCKET s,char* buf,int len,int flags) |
2338 |
{ |
2339 |
return (*gWSrecv)(s,buf,len,flags); |
2340 |
} |
2341 |
|
2342 |
-int BinHTTPURLInputStream::shutdown(unsigned int s,int how) |
2343 |
+int BinHTTPURLInputStream::shutdown(SOCKET s,int how) |
2344 |
{ |
2345 |
return (*gWSshutdown)(s,how); |
2346 |
} |
2347 |
|
2348 |
-int BinHTTPURLInputStream::closesocket(unsigned int socket) |
2349 |
+int BinHTTPURLInputStream::closesocket(SOCKET socket) |
2350 |
{ |
2351 |
return (*gWSclosesocket)(socket); |
2352 |
} |
2353 |
|
2354 |
|
2355 |
BinHTTPURLInputStream::BinHTTPURLInputStream(const XMLURL& urlSource, const XMLNetHTTPInfo* httpInfo /*=0*/) |
2356 |
- : fSocketHandle(0) |
2357 |
+ : fMemoryManager(urlSource.getMemoryManager()) |
2358 |
+ , fSocketHandle(0) |
2359 |
, fBytesProcessed(0) |
2360 |
+ , fBuffer(1023, urlSource.getMemoryManager()) |
2361 |
+ , fContentType(0) |
2362 |
{ |
2363 |
if(!fInitialized) |
2364 |
{ |
2365 |
@@ -243,257 +463,160 @@ |
2366 |
} |
2367 |
} |
2368 |
|
2369 |
- fMemoryManager = urlSource.getMemoryManager(); |
2370 |
+ // |
2371 |
+ // Constants in ASCII to send/check in the HTTP request/response |
2372 |
+ // |
2373 |
+ |
2374 |
+ static const char *CRLF2X = "\r\n\r\n"; |
2375 |
+ static const char *LF2X = "\n\n"; |
2376 |
+ |
2377 |
// |
2378 |
// Pull all of the parts of the URL out of th urlSource object, and transcode them |
2379 |
// and transcode them back to ASCII. |
2380 |
// |
2381 |
const XMLCh* hostName = urlSource.getHost(); |
2382 |
- char* hostNameAsCharStar = XMLString::transcode(hostName, urlSource.getMemoryManager()); |
2383 |
- ArrayJanitor<char> janBuf1(hostNameAsCharStar, urlSource.getMemoryManager()); |
2384 |
+ char* hostNameAsCharStar = XMLString::transcode(hostName, fMemoryManager); |
2385 |
+ ArrayJanitor<char> janHostNameAsCharStar(hostNameAsCharStar, fMemoryManager); |
2386 |
|
2387 |
- const XMLCh* path = urlSource.getPath(); |
2388 |
- char* pathAsCharStar = XMLString::transcode(path, urlSource.getMemoryManager()); |
2389 |
- ArrayJanitor<char> janBuf2(pathAsCharStar, urlSource.getMemoryManager()); |
2390 |
- |
2391 |
- const XMLCh* fragment = urlSource.getFragment(); |
2392 |
- char* fragmentAsCharStar = 0; |
2393 |
- if (fragment) |
2394 |
- fragmentAsCharStar = XMLString::transcode(fragment, urlSource.getMemoryManager()); |
2395 |
- ArrayJanitor<char> janBuf3(fragmentAsCharStar, urlSource.getMemoryManager()); |
2396 |
- |
2397 |
- const XMLCh* query = urlSource.getQuery(); |
2398 |
- char* queryAsCharStar = 0; |
2399 |
- if (query) |
2400 |
- queryAsCharStar = XMLString::transcode(query, urlSource.getMemoryManager()); |
2401 |
- ArrayJanitor<char> janBuf4(queryAsCharStar, urlSource.getMemoryManager()); |
2402 |
+ XMLURL url(urlSource); |
2403 |
+ int redirectCount = 0; |
2404 |
+ SocketJanitor janSock(0); |
2405 |
+ |
2406 |
+ do { |
2407 |
+ // |
2408 |
+ // Set up a socket. |
2409 |
+ // |
2410 |
+ struct hostent* hostEntPtr = 0; |
2411 |
+ struct sockaddr_in sa; |
2412 |
|
2413 |
- unsigned short portNumber = (unsigned short) urlSource.getPortNum(); |
2414 |
- |
2415 |
- // |
2416 |
- // Set up a socket. |
2417 |
- // |
2418 |
- struct hostent* hostEntPtr = 0; |
2419 |
- struct sockaddr_in sa; |
2420 |
|
2421 |
+ if ((hostEntPtr = gethostbyname(hostNameAsCharStar)) == NULL) |
2422 |
+ { |
2423 |
+ unsigned long numAddress = inet_addr(hostNameAsCharStar); |
2424 |
+ if (numAddress == INADDR_NONE) |
2425 |
+ { |
2426 |
+ // Call WSAGetLastError() to get the error number. |
2427 |
+ ThrowXMLwithMemMgr1(NetAccessorException, |
2428 |
+ XMLExcepts::NetAcc_TargetResolution, hostName, fMemoryManager); |
2429 |
+ } |
2430 |
+ if ((hostEntPtr = |
2431 |
+ gethostbyaddr((const char *) &numAddress, |
2432 |
+ sizeof(unsigned long), AF_INET)) == NULL) |
2433 |
+ { |
2434 |
+ // Call WSAGetLastError() to get the error number. |
2435 |
+ ThrowXMLwithMemMgr1(NetAccessorException, |
2436 |
+ XMLExcepts::NetAcc_TargetResolution, hostName, fMemoryManager); |
2437 |
+ } |
2438 |
+ } |
2439 |
|
2440 |
- if ((hostEntPtr = gethostbyname(hostNameAsCharStar)) == NULL) |
2441 |
- { |
2442 |
- unsigned long numAddress = inet_addr(hostNameAsCharStar); |
2443 |
- if (numAddress == INADDR_NONE) |
2444 |
+ memcpy((void *) &sa.sin_addr, |
2445 |
+ (const void *) hostEntPtr->h_addr, hostEntPtr->h_length); |
2446 |
+ sa.sin_family = hostEntPtr->h_addrtype; |
2447 |
+ sa.sin_port = htons((unsigned short)url.getPortNum()); |
2448 |
+ |
2449 |
+ janSock.reset(); |
2450 |
+ fSocketHandle = socket(hostEntPtr->h_addrtype, SOCK_STREAM, 0); |
2451 |
+ if (fSocketHandle == INVALID_SOCKET) |
2452 |
{ |
2453 |
// Call WSAGetLastError() to get the error number. |
2454 |
ThrowXMLwithMemMgr1(NetAccessorException, |
2455 |
- XMLExcepts::NetAcc_TargetResolution, hostName, fMemoryManager); |
2456 |
+ XMLExcepts::NetAcc_CreateSocket, url.getURLText(), fMemoryManager); |
2457 |
} |
2458 |
- if ((hostEntPtr = |
2459 |
- gethostbyaddr((const char *) &numAddress, |
2460 |
- sizeof(unsigned long), AF_INET)) == NULL) |
2461 |
+ janSock.reset(&fSocketHandle); |
2462 |
+ |
2463 |
+ if (connect(fSocketHandle, (struct sockaddr *) &sa, sizeof(sa)) == SOCKET_ERROR) |
2464 |
{ |
2465 |
// Call WSAGetLastError() to get the error number. |
2466 |
ThrowXMLwithMemMgr1(NetAccessorException, |
2467 |
- XMLExcepts::NetAcc_TargetResolution, hostName, fMemoryManager); |
2468 |
+ XMLExcepts::NetAcc_ConnSocket, url.getURLText(), fMemoryManager); |
2469 |
} |
2470 |
- } |
2471 |
|
2472 |
- memcpy((void *) &sa.sin_addr, |
2473 |
- (const void *) hostEntPtr->h_addr, hostEntPtr->h_length); |
2474 |
- sa.sin_family = hostEntPtr->h_addrtype; |
2475 |
- sa.sin_port = htons(portNumber); |
2476 |
|
2477 |
- SOCKET s = socket(hostEntPtr->h_addrtype, SOCK_STREAM, 0); |
2478 |
- if (s == INVALID_SOCKET) |
2479 |
- { |
2480 |
- // Call WSAGetLastError() to get the error number. |
2481 |
- ThrowXMLwithMemMgr1(NetAccessorException, |
2482 |
- XMLExcepts::NetAcc_CreateSocket, urlSource.getURLText(), fMemoryManager); |
2483 |
- } |
2484 |
- SocketJanitor janSock(&s); |
2485 |
- |
2486 |
- if (connect(s, (struct sockaddr *) &sa, sizeof(sa)) == SOCKET_ERROR) |
2487 |
- { |
2488 |
- // Call WSAGetLastError() to get the error number. |
2489 |
- ThrowXMLwithMemMgr1(NetAccessorException, |
2490 |
- XMLExcepts::NetAcc_ConnSocket, urlSource.getURLText(), fMemoryManager); |
2491 |
- } |
2492 |
- |
2493 |
- |
2494 |
- // Set a flag so we know that the headers have not been read yet. |
2495 |
- bool fHeaderRead = false; |
2496 |
- |
2497 |
- // The port is open and ready to go. |
2498 |
- // Build up the http GET command to send to the server. |
2499 |
- // To do: We should really support http 1.1. This implementation |
2500 |
- // is weak. |
2501 |
+ // The port is open and ready to go. |
2502 |
+ // Build up the http GET command to send to the server. |
2503 |
+ CharBuffer requestBuffer(1023, fMemoryManager); |
2504 |
+ createHTTPRequest(url, httpInfo, requestBuffer); |
2505 |
|
2506 |
- memset(fBuffer, 0, sizeof(fBuffer)); |
2507 |
+ // Send the http request |
2508 |
+ if(!send(requestBuffer.getRawBuffer(), requestBuffer.getLen())) { |
2509 |
+ // Call WSAGetLastError() to get the error number. |
2510 |
+ ThrowXMLwithMemMgr1(NetAccessorException, |
2511 |
+ XMLExcepts::NetAcc_WriteSocket, url.getURLText(), fMemoryManager); |
2512 |
+ } |
2513 |
|
2514 |
- if(httpInfo==0) |
2515 |
- strcpy(fBuffer, "GET "); |
2516 |
- else { |
2517 |
- switch(httpInfo->fHTTPMethod) { |
2518 |
- case XMLNetHTTPInfo::GET: strcpy(fBuffer, "GET "); break; |
2519 |
- case XMLNetHTTPInfo::PUT: strcpy(fBuffer, "PUT "); break; |
2520 |
- case XMLNetHTTPInfo::POST: strcpy(fBuffer, "POST "); break; |
2521 |
+ if(httpInfo && httpInfo->fPayload) { |
2522 |
+ if(!send(httpInfo->fPayload, httpInfo->fPayloadLen)) { |
2523 |
+ ThrowXMLwithMemMgr1(NetAccessorException, |
2524 |
+ XMLExcepts::NetAcc_WriteSocket, url.getURLText(), fMemoryManager); |
2525 |
+ } |
2526 |
} |
2527 |
- } |
2528 |
- strcat(fBuffer, pathAsCharStar); |
2529 |
|
2530 |
- if (queryAsCharStar != 0) |
2531 |
- { |
2532 |
- // Tack on a ? before the fragment |
2533 |
- strcat(fBuffer,"?"); |
2534 |
- strcat(fBuffer, queryAsCharStar); |
2535 |
- } |
2536 |
+ // |
2537 |
+ // get the response, check the http header for errors from the server. |
2538 |
+ // |
2539 |
+ char tmpBuf[1024]; |
2540 |
+ int ret; |
2541 |
|
2542 |
- if (fragmentAsCharStar != 0) |
2543 |
- { |
2544 |
- strcat(fBuffer, fragmentAsCharStar); |
2545 |
- } |
2546 |
- strcat(fBuffer, " HTTP/1.0\r\n"); |
2547 |
+ fBuffer.reset(); |
2548 |
+ while(true) { |
2549 |
+ ret = recv(fSocketHandle, tmpBuf, sizeof(tmpBuf), 0); |
2550 |
+ if(ret == SOCKET_ERROR) { |
2551 |
+ ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_ReadSocket, url.getURLText(), fMemoryManager); |
2552 |
+ } |
2553 |
|
2554 |
+ fBuffer.append(tmpBuf, ret); |
2555 |
|
2556 |
- strcat(fBuffer, "Host: "); |
2557 |
- strcat(fBuffer, hostNameAsCharStar); |
2558 |
- if (portNumber != 80) |
2559 |
- { |
2560 |
- strcat(fBuffer, ":"); |
2561 |
- int i = strlen(fBuffer); |
2562 |
- _itoa(portNumber, fBuffer+i, 10); |
2563 |
- } |
2564 |
- strcat(fBuffer, "\r\n"); |
2565 |
- |
2566 |
- const XMLCh* username = urlSource.getUser(); |
2567 |
- const XMLCh* password = urlSource.getPassword(); |
2568 |
- if (username && password) |
2569 |
- { |
2570 |
- XMLBuffer userPass(256, fMemoryManager); |
2571 |
- userPass.append(username); |
2572 |
- userPass.append(chColon); |
2573 |
- userPass.append(password); |
2574 |
- char* userPassAsCharStar = XMLString::transcode(userPass.getRawBuffer(), fMemoryManager); |
2575 |
- ArrayJanitor<char> janBuf(userPassAsCharStar, fMemoryManager); |
2576 |
+ fBufferPos = strstr(fBuffer.getRawBuffer(), CRLF2X); |
2577 |
+ if(fBufferPos != 0) { |
2578 |
+ fBufferPos += 4; |
2579 |
+ *(fBufferPos - 2) = 0; |
2580 |
+ break; |
2581 |
+ } |
2582 |
|
2583 |
- unsigned int len; |
2584 |
- XMLByte* encodedData = Base64::encode((XMLByte *)userPassAsCharStar, strlen(userPassAsCharStar), &len, fMemoryManager); |
2585 |
- ArrayJanitor<XMLByte> janBuf2(encodedData, fMemoryManager); |
2586 |
- |
2587 |
- if (encodedData) |
2588 |
- { |
2589 |
- // HTTP doesn't want the 0x0A separating the data in chunks of 76 chars per line |
2590 |
- XMLByte* authData = (XMLByte*)fMemoryManager->allocate((len+1)*sizeof(XMLByte)); |
2591 |
- ArrayJanitor<XMLByte> janBuf(authData, fMemoryManager); |
2592 |
- XMLByte* cursor=authData; |
2593 |
- for(unsigned int i=0;i<len;i++) |
2594 |
- if(encodedData[i]!=chLF) |
2595 |
- *cursor++=encodedData[i]; |
2596 |
- *cursor++=0; |
2597 |
- strcat(fBuffer, "Authorization: Basic "); |
2598 |
- strcat(fBuffer, (char*)authData); |
2599 |
- strcat(fBuffer, "\r\n"); |
2600 |
+ fBufferPos = strstr(fBuffer.getRawBuffer(), LF2X); |
2601 |
+ if(fBufferPos != 0) { |
2602 |
+ fBufferPos += 2; |
2603 |
+ *(fBufferPos - 1) = 0; |
2604 |
+ break; |
2605 |
+ } |
2606 |
} |
2607 |
- } |
2608 |
|
2609 |
- if(httpInfo!=0 && httpInfo->fHeaders!=0) |
2610 |
- strncat(fBuffer,httpInfo->fHeaders,httpInfo->fHeadersLen); |
2611 |
- |
2612 |
- strcat(fBuffer, "\r\n"); |
2613 |
- |
2614 |
- // Send the http request |
2615 |
- int lent = strlen(fBuffer); |
2616 |
- int aLent = 0; |
2617 |
- if ((aLent = send(s, fBuffer, lent, 0)) != lent) |
2618 |
- { |
2619 |
- // Call WSAGetLastError() to get the error number. |
2620 |
- ThrowXMLwithMemMgr1(NetAccessorException, |
2621 |
- XMLExcepts::NetAcc_WriteSocket, urlSource.getURLText(), fMemoryManager); |
2622 |
- } |
2623 |
- |
2624 |
- if(httpInfo!=0 && httpInfo->fPayload!=0) { |
2625 |
- int aLent = 0; |
2626 |
- if ((aLent = send(s, httpInfo->fPayload, httpInfo->fPayloadLen, 0)) != httpInfo->fPayloadLen) |
2627 |
- { |
2628 |
- // Call WSAGetLastError() to get the error number. |
2629 |
- ThrowXMLwithMemMgr1(NetAccessorException, |
2630 |
- XMLExcepts::NetAcc_WriteSocket, urlSource.getURLText(), fMemoryManager); |
2631 |
+ int status = parseResponseStatus(); |
2632 |
+ if(status < 0) { |
2633 |
+ ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_ReadSocket, url.getURLText(), fMemoryManager); |
2634 |
} |
2635 |
- } |
2636 |
|
2637 |
- // |
2638 |
- // get the response, check the http header for errors from the server. |
2639 |
- // |
2640 |
- memset(fBuffer, 0, sizeof(fBuffer)); |
2641 |
- aLent = recv(s, fBuffer, sizeof(fBuffer)-1, 0); |
2642 |
- if (aLent == SOCKET_ERROR || aLent == 0) |
2643 |
- { |
2644 |
- // Call WSAGetLastError() to get the error number. |
2645 |
- ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_ReadSocket, urlSource.getURLText(), fMemoryManager); |
2646 |
- } |
2647 |
- |
2648 |
- fBufferEnd = fBuffer+aLent; |
2649 |
- *fBufferEnd = 0; |
2650 |
- |
2651 |
- do { |
2652 |
- // Find the break between the returned http header and any data. |
2653 |
- // (Delimited by a blank line) |
2654 |
- // Hang on to any data for use by the first read from this BinHTTPURLInputStream. |
2655 |
- // |
2656 |
- fBufferPos = strstr(fBuffer, "\r\n\r\n"); |
2657 |
- if (fBufferPos != 0) |
2658 |
- { |
2659 |
- fBufferPos += 4; |
2660 |
- *(fBufferPos-2) = 0; |
2661 |
- fHeaderRead = true; |
2662 |
+ if(status == 200) { |
2663 |
+ // HTTP 200 OK response means we're done. |
2664 |
+ // We're done |
2665 |
+ break; |
2666 |
} |
2667 |
- else |
2668 |
- { |
2669 |
- fBufferPos = strstr(fBuffer, "\n\n"); |
2670 |
- if (fBufferPos != 0) |
2671 |
- { |
2672 |
- fBufferPos += 2; |
2673 |
- *(fBufferPos-1) = 0; |
2674 |
- fHeaderRead = true; |
2675 |
- } |
2676 |
- else |
2677 |
- { |
2678 |
- // |
2679 |
- // Header is not yet read, do another recv() to get more data... |
2680 |
- aLent = recv(s, fBufferEnd, (sizeof(fBuffer) - 1) - (fBufferEnd - fBuffer), 0); |
2681 |
- if (aLent == SOCKET_ERROR || aLent == 0) |
2682 |
- { |
2683 |
- // Call WSAGetLastError() to get the error number. |
2684 |
- ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_ReadSocket, urlSource.getURLText(), fMemoryManager); |
2685 |
- } |
2686 |
- fBufferEnd = fBufferEnd + aLent; |
2687 |
- *fBufferEnd = 0; |
2688 |
+ // a 3xx response means there was an HTTP redirect |
2689 |
+ else if(status >= 300 && status <= 307) { |
2690 |
+ redirectCount++; |
2691 |
+ |
2692 |
+ XMLCh *newURLString = findHeader("Location"); |
2693 |
+ ArrayJanitor<XMLCh> janNewURLString(newURLString, fMemoryManager); |
2694 |
+ |
2695 |
+ XMLURL newURL(fMemoryManager); |
2696 |
+ newURL.setURL(url, newURLString); |
2697 |
+ if(newURL.getProtocol() != XMLURL::HTTP) { |
2698 |
+ ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::File_CouldNotOpenFile, newURL.getURLText(), fMemoryManager); |
2699 |
} |
2700 |
- } |
2701 |
- } while(fHeaderRead == false); |
2702 |
|
2703 |
- // Make sure the header includes an HTTP 200 OK response. |
2704 |
- // |
2705 |
- char *p = strstr(fBuffer, "HTTP"); |
2706 |
- if (p == 0) |
2707 |
- { |
2708 |
- ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_ReadSocket, urlSource.getURLText(), fMemoryManager); |
2709 |
- } |
2710 |
- |
2711 |
- p = strchr(p, ' '); |
2712 |
- if (p == 0) |
2713 |
- { |
2714 |
- ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_ReadSocket, urlSource.getURLText(), fMemoryManager); |
2715 |
- } |
2716 |
+ url = newURL; |
2717 |
|
2718 |
- int httpResponse = atoi(p); |
2719 |
- if (httpResponse != 200) |
2720 |
- { |
2721 |
- // Most likely a 404 Not Found error. |
2722 |
- // Should recognize and handle the forwarding responses. |
2723 |
- // |
2724 |
- ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::File_CouldNotOpenFile, urlSource.getURLText(), fMemoryManager); |
2725 |
- } |
2726 |
+ janHostNameAsCharStar.release(); |
2727 |
+ hostNameAsCharStar = XMLString::transcode(newURL.getHost(), fMemoryManager); |
2728 |
+ janHostNameAsCharStar.reset(hostNameAsCharStar, fMemoryManager); |
2729 |
+ } |
2730 |
+ else { |
2731 |
+ // Most likely a 404 Not Found error. |
2732 |
+ ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::File_CouldNotOpenFile, url.getURLText(), fMemoryManager); |
2733 |
+ } |
2734 |
+ } while(redirectCount < 6); |
2735 |
|
2736 |
- fSocketHandle = (unsigned int) *janSock.release(); |
2737 |
+ janSock.release(); |
2738 |
} |
2739 |
|
2740 |
|
2741 |
@@ -502,17 +625,28 @@ |
2742 |
{ |
2743 |
shutdown(fSocketHandle, SD_BOTH); |
2744 |
closesocket(fSocketHandle); |
2745 |
+ |
2746 |
+ if(fContentType) fMemoryManager->deallocate(fContentType); |
2747 |
} |
2748 |
|
2749 |
|
2750 |
+const XMLCh *BinHTTPURLInputStream::getContentType() const |
2751 |
+{ |
2752 |
+ if(fContentType == 0) { |
2753 |
+ // mutable |
2754 |
+ const_cast<XMLCh*&>(fContentType) = findHeader("Content-Type"); |
2755 |
+ } |
2756 |
+ return fContentType; |
2757 |
+} |
2758 |
+ |
2759 |
// |
2760 |
// readBytes |
2761 |
// |
2762 |
unsigned int BinHTTPURLInputStream::readBytes(XMLByte* const toFill |
2763 |
, const unsigned int maxToRead) |
2764 |
{ |
2765 |
- unsigned int len = fBufferEnd - fBufferPos; |
2766 |
- if (len > 0) |
2767 |
+ unsigned int len = fBuffer.getRawBuffer() + fBuffer.getLen() - fBufferPos; |
2768 |
+ if(len > 0) |
2769 |
{ |
2770 |
// If there's any data left over in the buffer into which we first |
2771 |
// read from the server (to get the http header), return that. |
2772 |
@@ -526,7 +660,7 @@ |
2773 |
// There was no data in the local buffer. |
2774 |
// Read some from the socket, straight into our caller's buffer. |
2775 |
// |
2776 |
- len = recv((SOCKET) fSocketHandle, (char *) toFill, maxToRead, 0); |
2777 |
+ len = recv(fSocketHandle, (char *) toFill, maxToRead, 0); |
2778 |
if (len == SOCKET_ERROR) |
2779 |
{ |
2780 |
// Call WSAGetLastError() to get the error number. |
2781 |
diff -ru xerces-c-src_2_8_0-release/src/xercesc/util/NetAccessors/WinSock/BinHTTPURLInputStream.hpp xerces-c-src_2_8_0/src/xercesc/util/NetAccessors/WinSock/BinHTTPURLInputStream.hpp |
2782 |
--- xerces-c-src_2_8_0-release/src/xercesc/util/NetAccessors/WinSock/BinHTTPURLInputStream.hpp 2008-02-08 15:30:17.000000000 +0000 |
2783 |
+++ xerces-c-src_2_8_0/src/xercesc/util/NetAccessors/WinSock/BinHTTPURLInputStream.hpp 2008-02-08 15:22:45.000000000 +0000 |
2784 |
@@ -28,16 +28,138 @@ |
2785 |
#include <xercesc/util/BinInputStream.hpp> |
2786 |
#include <xercesc/util/Mutexes.hpp> |
2787 |
#include <xercesc/util/XMLNetAccessor.hpp> |
2788 |
+#include <xercesc/framework/MemoryManager.hpp> |
2789 |
+ |
2790 |
+#define INCL_WINSOCK_API_TYPEDEFS 1 |
2791 |
+#include <winsock2.h> |
2792 |
+ |
2793 |
+XERCES_CPP_NAMESPACE_BEGIN |
2794 |
|
2795 |
// |
2796 |
-// This class implements the BinInputStream interface specified by the XML |
2797 |
-// parser. |
2798 |
+// This class implements a simple expanding character buffer |
2799 |
// |
2800 |
-struct hostent; |
2801 |
-struct sockaddr; |
2802 |
+class XMLUTIL_EXPORT CharBuffer |
2803 |
+{ |
2804 |
+public: |
2805 |
+ CharBuffer(unsigned int capacity = 1023, |
2806 |
+ MemoryManager *manager = XMLPlatformUtils::fgMemoryManager) |
2807 |
+ : fCapacity(capacity), |
2808 |
+ fIndex(0), |
2809 |
+ fMemoryManager(manager) |
2810 |
+ { |
2811 |
+ fBuffer = (char*)fMemoryManager->allocate((fCapacity + 1) * sizeof(char)); |
2812 |
+ } |
2813 |
+ |
2814 |
+ ~CharBuffer() |
2815 |
+ { |
2816 |
+ fMemoryManager->deallocate(fBuffer); |
2817 |
+ } |
2818 |
+ |
2819 |
+ const char* getRawBuffer() const |
2820 |
+ { |
2821 |
+ fBuffer[fIndex] = 0; |
2822 |
+ return fBuffer; |
2823 |
+ } |
2824 |
+ |
2825 |
+ char* getRawBuffer() |
2826 |
+ { |
2827 |
+ fBuffer[fIndex] = 0; |
2828 |
+ return fBuffer; |
2829 |
+ } |
2830 |
+ |
2831 |
+ unsigned int getLen() const |
2832 |
+ { |
2833 |
+ return fIndex; |
2834 |
+ } |
2835 |
+ |
2836 |
+ void reset() |
2837 |
+ { |
2838 |
+ fIndex = 0; |
2839 |
+ } |
2840 |
+ |
2841 |
+ void append(const char *chars) |
2842 |
+ { |
2843 |
+ if(chars != 0 && *chars != 0) { |
2844 |
+ // get length of chars |
2845 |
+ unsigned int count = 0; |
2846 |
+ for(; *(chars+count); ++count); |
2847 |
+ |
2848 |
+ if(fIndex + count >= fCapacity) { |
2849 |
+ insureCapacity(count); |
2850 |
+ } |
2851 |
+ memcpy(&fBuffer[fIndex], chars, count * sizeof(char)); |
2852 |
+ fIndex += count; |
2853 |
+ } |
2854 |
+ } |
2855 |
+ |
2856 |
+ void append(const char *chars, unsigned int len) |
2857 |
+ { |
2858 |
+ if(chars != 0 && len != 0) { |
2859 |
+ if(fIndex + len >= fCapacity) { |
2860 |
+ insureCapacity(len); |
2861 |
+ } |
2862 |
+ memcpy(&fBuffer[fIndex], chars, len * sizeof(char)); |
2863 |
+ fIndex += len; |
2864 |
+ } |
2865 |
+ } |
2866 |
+ |
2867 |
+ void appendDecimalNumber(unsigned int n) |
2868 |
+ { |
2869 |
+ if(n >= 10) appendDecimalNumber(n / 10); |
2870 |
+ |
2871 |
+ if(fIndex + 1 >= fCapacity) |
2872 |
+ insureCapacity(1); |
2873 |
+ |
2874 |
+ fBuffer[fIndex] = '0' + n; |
2875 |
+ ++fIndex; |
2876 |
+ } |
2877 |
+ |
2878 |
+ void set(const char *chars) |
2879 |
+ { |
2880 |
+ reset(); |
2881 |
+ append(chars); |
2882 |
+ } |
2883 |
|
2884 |
-XERCES_CPP_NAMESPACE_BEGIN |
2885 |
+private: |
2886 |
+ // ----------------------------------------------------------------------- |
2887 |
+ // Unimplemented constructors and operators |
2888 |
+ // ----------------------------------------------------------------------- |
2889 |
+ CharBuffer(const CharBuffer &); |
2890 |
+ CharBuffer &operator=(const CharBuffer &); |
2891 |
+ |
2892 |
+ void insureCapacity(unsigned int extraNeeded) |
2893 |
+ { |
2894 |
+ // If we can't handle it, try doubling the buffer size. |
2895 |
+ unsigned int newCap = (fIndex + extraNeeded) * 2; |
2896 |
+ |
2897 |
+ if(newCap > fCapacity) |
2898 |
+ { |
2899 |
+ // Allocate new buffer |
2900 |
+ char* newBuf = (char*)fMemoryManager->allocate((newCap + 1) * sizeof(char)); |
2901 |
+ |
2902 |
+ // Copy over the old stuff |
2903 |
+ memcpy(newBuf, fBuffer, fIndex * sizeof(char)); |
2904 |
+ |
2905 |
+ // Clean up old buffer and store new stuff |
2906 |
+ fMemoryManager->deallocate(fBuffer); |
2907 |
+ fBuffer = newBuf; |
2908 |
+ fCapacity = newCap; |
2909 |
+ } |
2910 |
+ } |
2911 |
+ |
2912 |
+ // ----------------------------------------------------------------------- |
2913 |
+ // Private data members |
2914 |
+ // ----------------------------------------------------------------------- |
2915 |
+ char *fBuffer; |
2916 |
+ unsigned int fCapacity; |
2917 |
+ unsigned int fIndex; |
2918 |
+ MemoryManager *fMemoryManager; |
2919 |
+}; |
2920 |
|
2921 |
+// |
2922 |
+// This class implements the BinInputStream interface specified by the XML |
2923 |
+// parser. |
2924 |
+// |
2925 |
class XMLUTIL_EXPORT BinHTTPURLInputStream : public BinInputStream |
2926 |
{ |
2927 |
public : |
2928 |
@@ -51,6 +173,8 @@ |
2929 |
, const unsigned int maxToRead |
2930 |
); |
2931 |
|
2932 |
+ const XMLCh *getContentType() const; |
2933 |
+ |
2934 |
static void Cleanup(); |
2935 |
|
2936 |
|
2937 |
@@ -60,6 +184,12 @@ |
2938 |
// ----------------------------------------------------------------------- |
2939 |
BinHTTPURLInputStream(const BinHTTPURLInputStream&); |
2940 |
BinHTTPURLInputStream& operator=(const BinHTTPURLInputStream&); |
2941 |
+ |
2942 |
+ void createHTTPRequest(const XMLURL &urlSource, const XMLNetHTTPInfo *httpInfo, CharBuffer &buffer); |
2943 |
+ int parseResponseStatus() const; |
2944 |
+ XMLCh *findHeader(const char *name) const; |
2945 |
+ bool send(const char *buf, unsigned int len); |
2946 |
+ |
2947 |
// ----------------------------------------------------------------------- |
2948 |
// Private data members |
2949 |
// |
2950 |
@@ -79,11 +209,12 @@ |
2951 |
// that readBytes must return. |
2952 |
// ----------------------------------------------------------------------- |
2953 |
MemoryManager* fMemoryManager; |
2954 |
- unsigned int fSocketHandle; |
2955 |
+ SOCKET fSocketHandle; |
2956 |
unsigned int fBytesProcessed; |
2957 |
- char fBuffer[4000]; |
2958 |
- char * fBufferEnd; |
2959 |
+ CharBuffer fBuffer; |
2960 |
char * fBufferPos; |
2961 |
+ XMLCh * fContentType; |
2962 |
+ |
2963 |
static bool fInitialized; |
2964 |
static XMLMutex* fInitMutex; |
2965 |
|
2966 |
@@ -93,12 +224,12 @@ |
2967 |
inline static unsigned long inet_addr(const char* cp); |
2968 |
inline static hostent* gethostbyaddr(const char* addr,int len,int type); |
2969 |
inline static unsigned short htons(unsigned short hostshort); |
2970 |
- inline static unsigned int socket(int af,int type,int protocol); |
2971 |
- inline static int connect(unsigned int s,const sockaddr* name,int namelen); |
2972 |
- inline static int send(unsigned int s,const char* buf,int len,int flags); |
2973 |
- inline static int recv(unsigned int s,char* buf,int len,int flags); |
2974 |
- inline static int shutdown(unsigned int s,int how); |
2975 |
- inline static int closesocket(unsigned int socket); |
2976 |
+ inline static SOCKET socket(int af,int type,int protocol); |
2977 |
+ inline static int connect(SOCKET s,const sockaddr* name,int namelen); |
2978 |
+ inline static int send(SOCKET s,const char* buf,int len,int flags); |
2979 |
+ inline static int recv(SOCKET s,char* buf,int len,int flags); |
2980 |
+ inline static int shutdown(SOCKET s,int how); |
2981 |
+ inline static int closesocket(SOCKET socket); |
2982 |
|
2983 |
friend class SocketJanitor; |
2984 |
}; |
2985 |
diff -ru xerces-c-src_2_8_0-release/src/xercesc/util/XMLURL.cpp xerces-c-src_2_8_0/src/xercesc/util/XMLURL.cpp |
2986 |
--- xerces-c-src_2_8_0-release/src/xercesc/util/XMLURL.cpp 2008-02-08 15:30:17.000000000 +0000 |
2987 |
+++ xerces-c-src_2_8_0/src/xercesc/util/XMLURL.cpp 2008-01-28 01:21:23.000000000 +0000 |
2988 |
@@ -1132,6 +1132,10 @@ |
2989 |
// If we are at the end, then we are done now |
2990 |
if (!*srcPtr) |
2991 |
{ |
2992 |
+ if(fHost) { |
2993 |
+ static const XMLCh slash[] = { chForwardSlash, chNull }; |
2994 |
+ fPath = XMLString::replicate(slash, fMemoryManager); |
2995 |
+ } |
2996 |
return; |
2997 |
} |
2998 |
|
2999 |
diff -ru xerces-c-src_2_8_0-release/src/xercesc/validators/schema/SchemaElementDecl.hpp xerces-c-src_2_8_0/src/xercesc/validators/schema/SchemaElementDecl.hpp |
3000 |
--- xerces-c-src_2_8_0-release/src/xercesc/validators/schema/SchemaElementDecl.hpp 2008-02-08 15:30:17.000000000 +0000 |
3001 |
+++ xerces-c-src_2_8_0/src/xercesc/validators/schema/SchemaElementDecl.hpp 2007-11-13 01:31:25.000000000 +0000 |
3002 |
@@ -506,7 +506,7 @@ |
3003 |
|
3004 |
inline bool SchemaElementDecl::isGlobalDecl() const { |
3005 |
|
3006 |
- return (fEnclosingScope == Grammar::TOP_LEVEL_SCOPE); |
3007 |
+ return ((unsigned int)fEnclosingScope == Grammar::TOP_LEVEL_SCOPE); |
3008 |
} |
3009 |
|
3010 |
inline SchemaElementDecl* |
3011 |
|
3012 |
|
3013 |
|
3014 |
-- |
3015 |
gentoo-commits@l.g.o mailing list |