perl-libxml-sax.c

filter: Statementstmt 71.1% 551 / 774 Branchbran 42.6% 192 / 450 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 60.7% 743 / 1224 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« xpath.c ↑ Summary dom.c »
1 /**
2 * perl-libxml-sax.c
3 * $Id$
4 *
5 * This is free software, you may use it and distribute it under the same terms as
6 * Perl itself.
7 *
8 * Copyright 2001-2003 AxKit.com Ltd., 2002-2006 Christian Glahn, 2006-2009 Petr Pajas
9 */
10  
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 /* Disable this and use a threaded perl to test MSVC compilation errors */
15 #define PERL_NO_GET_CONTEXT /* we want efficiency */
16  
17 #include "EXTERN.h"
18 #include "perl.h"
19 #include "XSUB.h"
20 #include "ppport.h"
21  
22 #include <stdlib.h>
23 #include <stdint.h>
24 #include <libxml/xmlmemory.h>
25 #include <libxml/parser.h>
26 #include <libxml/parserInternals.h>
27 #include <libxml/tree.h>
28 #include <libxml/entities.h>
29 #include <libxml/xmlerror.h>
30  
31 #include "perl-libxml-sax.h"
32  
33 #ifdef __cplusplus
34 }
35 #endif
36  
37  
38 /*
39 we must call CLEAR_SERROR_HANDLER upon each excurse from
40 perl
41 */
42 #define WITH_SERRORS
43  
44 #ifdef WITH_SERRORS
45 #define CLEAR_SERROR_HANDLER /*xmlSetStructuredErrorFunc(NULL,NULL);*/
46 #else
47 #define CLEAR_SERROR_HANDLER
48 #endif
49  
50 #define NSDELIM ':'
51 /* #define NSDEFAULTURI "http://www.w3.org/XML/1998/namespace" */
52 #define NSDEFAULTURI "http://www.w3.org/2000/xmlns/"
53 typedef struct {
54 SV * parser;
55 xmlNodePtr ns_stack;
56 HV * locator;
57 xmlDocPtr ns_stack_root;
58 SV * handler;
59 SV * saved_error;
60 struct CBuffer *charbuf;
61 int joinchars;
62 } PmmSAXVector;
63  
64 typedef PmmSAXVector* PmmSAXVectorPtr;
65  
66 struct CBufferChunk {
67 struct CBufferChunk *next;
68 xmlChar *data;
69 size_t len;
70 };
71  
72 struct CBuffer {
73 struct CBufferChunk *head;
74 struct CBufferChunk *tail;
75 };
76  
77 static U32 PrefixHash; /* pre-computed */
78 static U32 NsURIHash;
79 static U32 NameHash;
80 static U32 LocalNameHash;
81 static U32 AttributesHash;
82 static U32 ValueHash;
83 static U32 DataHash;
84 static U32 TargetHash;
85 static U32 VersionHash;
86 static U32 EncodingHash;
87 static U32 PublicIdHash;
88 static U32 SystemIdHash;
89  
90 /* helper function C2Sv is ment to work faster than the perl-libxml-mm
91 version. this shortcut is useful, because SAX handles only UTF8
92 strings, so there is no conversion logic required.
93 */
94 SV*
95 1760 _C2Sv( const xmlChar *string, const xmlChar *dummy )
96 {
97  
98 dTHX;
99 1760 SV *retval = &PL_sv_undef;
100 STRLEN len;
101  
102 1760 ▶ if ( string != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( string != NULL ) { 1760 0 1760
103 1760 len = xmlStrlen( string );
104 1760 retval = NEWSV(0, len+1);
105 1760 sv_setpvn(retval, (const char *)string, len );
106 #ifdef HAVE_UTF8
107 1760 SvUTF8_on( retval );
108 #endif
109 }
110  
111 1760 return retval;
112 }
113  
114 SV*
115 113 _C2Sv_len( const xmlChar *string, int len )
116 {
117  
118 dTHX;
119 113 SV *retval = &PL_sv_undef;
120  
121 113 ▶ if ( string != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( string != NULL ) { 113 0 113
122 113 retval = NEWSV(0, len+1);
123 113 sv_setpvn(retval, (const char *)string, (STRLEN) len );
124 #ifdef HAVE_UTF8
125 113 SvUTF8_on( retval );
126 #endif
127 }
128  
129 113 return retval;
130 }
131  
132 void
133 77 PmmSAXInitialize(pTHX)
134 {
135 77 PERL_HASH(PrefixHash, "Prefix", 6);
136 77 PERL_HASH(NsURIHash, "NamespaceURI", 12);
137 77 PERL_HASH(NameHash, "Name", 4);
138 77 PERL_HASH(LocalNameHash, "LocalName", 9);
139 77 PERL_HASH(AttributesHash, "Attributes", 10);
140 77 PERL_HASH(ValueHash, "Value", 5);
141 77 PERL_HASH(DataHash, "Data", 4);
142 77 PERL_HASH(TargetHash, "Target", 6);
143 77 PERL_HASH(VersionHash, "Version", 7);
144 77 PERL_HASH(EncodingHash, "Encoding", 8);
145 77 PERL_HASH(PublicIdHash, "PublicId", 8);
146 77 PERL_HASH(SystemIdHash, "SystemId", 8);
147 77 }
148  
149 xmlSAXHandlerPtr PSaxGetHandler();
150 int PSaxCharactersFlush(void *, struct CBuffer *);
151  
152  
153 /* Character buffering functions */
154  
155 0 struct CBufferChunk * CBufferChunkNew(void) {
156 0 struct CBufferChunk *newchunk = xmlMalloc(sizeof(struct CBufferChunk));
157 dTHX;
158  
159 0 ▶ if (newchunk == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (newchunk == NULL) { 0 0 0
160 0 croak("Out of memory in SAX character buffering");
161 }
162  
163 0 memset(newchunk, 0, sizeof(struct CBufferChunk));
164 0 return newchunk;
165 }
166  
167 0 struct CBuffer * CBufferNew(void) {
168 0 struct CBuffer *new = xmlMalloc(sizeof(struct CBuffer));
169 struct CBufferChunk *newchunk;
170 dTHX;
171  
172 0 ▶ if (new == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (new == NULL) { 0 0 0
173 0 croak("Out of memory in SAX character buffering");
174 }
175  
176 0 newchunk = CBufferChunkNew();
177 0 memset(new, 0, sizeof(struct CBuffer));
178  
179 0 new->head = newchunk;
180 0 new->tail = newchunk;
181  
182 0 return new;
183 }
184  
185 0 void CBufferPurge(struct CBuffer *buffer) {
186 struct CBufferChunk *p1;
187 struct CBufferChunk *p2;
188  
189 0 ▶ if (buffer == NULL || buffer->head->data == NULL) {
Branch: 2 branches
BranchTrueFalseTotal
if (buffer == NULL || buffer->head->data == NULL) { 0 0 0
if (buffer == NULL || buffer->head->data == NULL) { 0 0 0
190 0 return;
191 }
192  
193 0 ▶ if ((p1 = buffer->head)) {
Branch: 1 branch
BranchTrueFalseTotal
if ((p1 = buffer->head)) { 0 0 0
194  
195 0 ▶ while(p1) {
Branch: 1 branch
BranchTrueFalseTotal
while(p1) { 0 0 0
196 0 p2 = p1->next;
197  
198 0 ▶ if (p1->data) {
Branch: 1 branch
BranchTrueFalseTotal
if (p1->data) { 0 0 0
199 0 xmlFree(p1->data);
200 }
201  
202 0 xmlFree(p1);
203  
204 0 p1 = p2;
205 }
206 }
207  
208 0 buffer->head = CBufferChunkNew();
209 0 buffer->tail = buffer->head;
210 }
211  
212 102 void CBufferFree(struct CBuffer *buffer) {
213 struct CBufferChunk *p1;
214 struct CBufferChunk *p2;
215  
216 102 ▶ if (buffer == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (buffer == NULL) { 102 0 102
217 102 return;
218 }
219  
220 0 ▶ if ((p1 = buffer->head)) {
Branch: 1 branch
BranchTrueFalseTotal
if ((p1 = buffer->head)) { 0 0 0
221  
222 0 ▶ while(p1) {
Branch: 1 branch
BranchTrueFalseTotal
while(p1) { 0 0 0
223 0 p2 = p1->next;
224  
225 0 ▶ if (p1->data) {
Branch: 1 branch
BranchTrueFalseTotal
if (p1->data) { 0 0 0
226 0 xmlFree(p1->data);
227 }
228  
229 0 xmlFree(p1);
230  
231 0 p1 = p2;
232 }
233 }
234  
235 0 xmlFree(buffer);
236  
237 0 return;
238 }
239  
240 0 size_t CBufferLength(struct CBuffer *buffer) {
241 0 size_t length = 0;
242 struct CBufferChunk *cur;
243  
244 0 ▶ for(cur = buffer->head; cur; cur = cur->next) {
Branch: 1 branch
BranchTrueFalseTotal
for(cur = buffer->head; cur; cur = cur->next) { 0 0 0
245 0 ▶ if (length > SIZE_MAX - cur->len) {
Branch: 1 branch
BranchTrueFalseTotal
if (length > SIZE_MAX - cur->len) { 0 0 0
246 0 croak("XML::LibXML: SAX character buffer overflow");
247 }
248 0 length += cur->len;
249 }
250  
251 0 return length;
252 }
253  
254 0 void CBufferAppend(struct CBuffer *buffer, const xmlChar *newstring, size_t len) {
255 0 xmlChar *copy = xmlMalloc(len);
256 dTHX;
257  
258 0 ▶ if (copy == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (copy == NULL) { 0 0 0
259 0 croak("Out of memory in SAX character buffering");
260 }
261  
262 0 memcpy(copy, newstring, len);
263  
264 0 buffer->tail->data = copy;
265 0 buffer->tail->len = len;
266 0 buffer->tail->next = CBufferChunkNew();
267 0 buffer->tail = buffer->tail->next;
268 0 }
269  
270 0 xmlChar * CBufferCharacters(struct CBuffer *buffer) {
271 0 size_t length = CBufferLength(buffer);
272 0 xmlChar *new = xmlMalloc(length + 1);
273 0 xmlChar *p = new;
274 0 size_t copied = 0;
275 struct CBufferChunk *cur;
276  
277 /* We need this because stderr on some perls requires
278 * my_perl. See:
279 *
280 * https://rt.cpan.org/Public/Bug/Display.html?id=69082
281 *
282 * */
283 dTHX;
284  
285 0 ▶ if (new == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (new == NULL) { 0 0 0
286 0 croak("Out of memory in SAX character buffering");
287 }
288  
289 0 ▶ if (buffer->head->data == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (buffer->head->data == NULL) { 0 0 0
290 0 return NULL;
291 }
292  
293 0 ▶ for(cur = buffer->head;cur;cur = cur->next) {
Branch: 1 branch
BranchTrueFalseTotal
for(cur = buffer->head;cur;cur = cur->next) { 0 0 0
294 0 ▶ if (! cur->data) {
Branch: 1 branch
BranchTrueFalseTotal
if (! cur->data) { 0 0 0
295 0 continue;
296 }
297  
298 0 ▶ if ((copied = copied + cur->len) > length) {
Branch: 1 branch
BranchTrueFalseTotal
if ((copied = copied + cur->len) > length) { 0 0 0
299 0 fprintf(stderr, "string overflow\n");
300 0 abort();
301 }
302  
303 0 memcpy(p, cur->data, cur->len);
304 0 p += cur->len;
305 }
306  
307 0 new[length] = '\0';
308  
309 0 return new;
310 }
311  
312 /* end character buffering functions */
313  
314  
315 void
316 103 PmmSAXInitContext( xmlParserCtxtPtr ctxt, SV * parser, SV * saved_error )
317 {
318 103 PmmSAXVectorPtr vec = NULL;
319 SV ** th;
320 SV ** joinchars;
321  
322 dTHX;
323  
324 CLEAR_SERROR_HANDLER
325 103 vec = (PmmSAXVector*) xmlMalloc( sizeof(PmmSAXVector) );
326  
327 103 vec->ns_stack_root = xmlNewDoc(NULL);
328 103 vec->ns_stack = xmlNewDocNode(vec->ns_stack_root,
329 NULL,
330 (const xmlChar*)"stack",
331 NULL );
332  
333 103 xmlAddChild((xmlNodePtr)vec->ns_stack_root, vec->ns_stack);
334  
335 103 vec->locator = NULL;
336  
337 103 vec->saved_error = saved_error;
338  
339 103 vec->parser = SvREFCNT_inc( parser );
340 103 th = hv_fetch( (HV*)SvRV(parser), "HANDLER", 7, 0 );
341 103 ▶ if ( th != NULL && SvTRUE(*th) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( th != NULL && SvTRUE(*th) ) { 103 0 103
if ( th != NULL && SvTRUE(*th) ) { 103 0 103
342 103 vec->handler = SvREFCNT_inc(*th) ;
343 }
344 else {
345 0 vec->handler = NULL;
346 }
347  
348 103 joinchars = hv_fetch((HV*)SvRV(parser), "JOIN_CHARACTERS", 15, 0);
349  
350 103 ▶ if (joinchars != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (joinchars != NULL) { 40 63 103
351 40 vec->joinchars = (SvIV(*joinchars));
352 } else {
353 63 vec->joinchars = 0;
354 }
355  
356 103 ▶ if (vec->joinchars) {
Branch: 1 branch
BranchTrueFalseTotal
if (vec->joinchars) { 0 103 103
357 0 vec->charbuf = CBufferNew();
358 } else {
359 103 vec->charbuf = NULL;
360 }
361  
362 103 ▶ if ( ctxt->sax ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ctxt->sax ) { 103 0 103
363 103 xmlFree( ctxt->sax );
364 }
365 103 ctxt->sax = PSaxGetHandler();
366  
367 103 ctxt->_private = (void*)vec;
368 103 }
369  
370 void
371 102 PmmSAXCloseContext( xmlParserCtxtPtr ctxt )
372 {
373 102 PmmSAXVector * vec = (PmmSAXVectorPtr) ctxt->_private;
374 dTHX;
375  
376 102 ▶ if ( vec->handler != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( vec->handler != NULL ) { 102 0 102
377 102 SvREFCNT_dec( vec->handler );
378 102 vec->handler = NULL;
379 }
380  
381 102 CBufferFree(vec->charbuf);
382 102 vec->charbuf = NULL;
383  
384 102 xmlFree( ctxt->sax );
385 102 ctxt->sax = NULL;
386  
387 102 SvREFCNT_dec( vec->parser );
388 102 vec->parser = NULL;
389  
390 102 xmlFreeDoc( vec->ns_stack_root );
391 102 vec->ns_stack_root = NULL;
392  
393 102 ▶ if ( vec->locator != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( vec->locator != NULL ) { 73 29 102
394 73 SvREFCNT_dec( vec->locator );
395 73 vec->locator = NULL;
396 }
397  
398 102 xmlFree( vec );
399 102 ctxt->_private = NULL;
400 102 }
401  
402  
403 xmlNsPtr
404 310 PmmGetNsMapping( xmlNodePtr ns_stack, const xmlChar * prefix )
405 {
406 310 ▶ if ( ns_stack != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ns_stack != NULL ) { 310 0 310
407 310 return xmlSearchNs( ns_stack->doc, ns_stack, prefix );
408 }
409  
410 0 return NULL;
411 }
412  
413  
414 void
415 35 PSaxStartPrefix( PmmSAXVectorPtr sax, const xmlChar * prefix,
416 const xmlChar * uri, SV * handler )
417 {
418 dTHX;
419 HV * param;
420 SV * rv;
421  
422 35 dSP;
423  
424 35 ENTER;
425 35 SAVETMPS;
426  
427 35 param = newHV();
428  
429 35 (void) hv_store(param, "NamespaceURI", 12,
430 _C2Sv(uri, NULL), NsURIHash);
431  
432 35 ▶ if ( prefix != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( prefix != NULL ) { 31 4 35
433 31 (void) hv_store(param, "Prefix", 6,
434 _C2Sv(prefix, NULL), PrefixHash);
435 }
436 else {
437 4 (void) hv_store(param, "Prefix", 6,
438 _C2Sv((const xmlChar*)"", NULL), PrefixHash);
439 }
440  
441 35 ▶ PUSHMARK(SP) ;
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP) ; 0 35 35
442 35 ▶ XPUSHs(handler);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(handler); 0 35 35
443  
444 35 rv = newRV_noinc((SV*)param);
445  
446 35 ▶ XPUSHs(rv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(rv); 0 35 35
447 35 PUTBACK;
448  
449 35 call_method( "start_prefix_mapping", G_SCALAR | G_EVAL | G_DISCARD );
450 35 sv_2mortal(rv);
451 35 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 35 0 35
if (SvTRUE(ERRSV)) { 0 35 35
452 0 croak_obj;
453 }
454 35 ▶ FREETMPS ;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS ; 35 0 35
455 35 LEAVE ;
456 CLEAR_SERROR_HANDLER
457 35 }
458  
459 void
460 35 PSaxEndPrefix( PmmSAXVectorPtr sax, const xmlChar * prefix,
461 const xmlChar * uri, SV * handler )
462 {
463 dTHX;
464 HV * param;
465 SV * rv;
466  
467 35 dSP;
468  
469 35 ENTER;
470 35 SAVETMPS;
471 35 param = newHV();
472 35 (void) hv_store(param, "NamespaceURI", 12,
473 _C2Sv(uri, NULL), NsURIHash);
474  
475 35 ▶ if ( prefix != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( prefix != NULL ) { 31 4 35
476 31 (void) hv_store(param, "Prefix", 6,
477 _C2Sv(prefix, NULL), PrefixHash);
478 }
479 else {
480 4 (void) hv_store(param, "Prefix", 6,
481 _C2Sv((const xmlChar *)"", NULL), PrefixHash);
482 }
483  
484 35 ▶ PUSHMARK(SP) ;
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP) ; 0 35 35
485 35 ▶ XPUSHs(handler);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(handler); 0 35 35
486  
487  
488 35 rv = newRV_noinc((SV*)param);
489  
490 35 ▶ XPUSHs(rv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(rv); 0 35 35
491 35 PUTBACK;
492  
493 35 call_method( "end_prefix_mapping", G_SCALAR | G_EVAL | G_DISCARD );
494 35 sv_2mortal(rv);
495 35 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 35 0 35
if (SvTRUE(ERRSV)) { 0 35 35
496 0 croak_obj;
497 }
498  
499 35 ▶ FREETMPS ;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS ; 35 0 35
500 35 LEAVE ;
501 CLEAR_SERROR_HANDLER
502 35 }
503  
504 void
505 151 PmmExtendNsStack( PmmSAXVectorPtr sax , const xmlChar * name) {
506 151 xmlNodePtr newNS = NULL;
507 151 xmlChar * localname = NULL;
508 151 xmlChar * prefix = NULL;
509  
510 151 localname = xmlSplitQName( NULL, name, &prefix );
511 151 ▶ if ( prefix != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( prefix != NULL ) { 26 125 151
512 /* check if we can find a namespace with that prefix... */
513 26 xmlNsPtr ns = xmlSearchNs( sax->ns_stack->doc, sax->ns_stack, prefix );
514  
515 26 ▶ if ( ns != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ns != NULL ) { 16 10 26
516 16 newNS = xmlNewDocNode( sax->ns_stack_root, ns, localname, NULL );
517 }
518 else {
519 10 newNS = xmlNewDocNode( sax->ns_stack_root, NULL, name, NULL );
520 }
521 }
522 else {
523 125 newNS = xmlNewDocNode( sax->ns_stack_root, NULL, name, NULL );
524 }
525  
526 151 ▶ if ( newNS != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( newNS != NULL ) { 151 0 151
527 151 xmlAddChild(sax->ns_stack, newNS);
528 151 sax->ns_stack = newNS;
529 }
530  
531 151 ▶ if ( localname != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( localname != NULL ) { 151 0 151
532 151 xmlFree( localname ) ;
533 }
534 151 ▶ if ( prefix != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( prefix != NULL ) { 26 125 151
535 26 xmlFree( prefix );
536 }
537 151 }
538  
539 void
540 146 PmmNarrowNsStack( PmmSAXVectorPtr sax, SV *handler )
541 {
542 146 xmlNodePtr parent = sax->ns_stack->parent;
543 146 xmlNsPtr list = sax->ns_stack->nsDef;
544  
545 181 ▶ while ( list ) {
Branch: 1 branch
BranchTrueFalseTotal
while ( list ) { 35 146 181
546 35 ▶ if ( !xmlStrEqual(list->prefix, (const xmlChar*)"xml") ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( !xmlStrEqual(list->prefix, (const xmlChar*)"xml") ) { 35 0 35
547 35 PSaxEndPrefix( sax, list->prefix, list->href, handler );
548 }
549 35 list = list->next;
550 }
551 146 xmlUnlinkNode(sax->ns_stack);
552 146 xmlFreeNode(sax->ns_stack);
553 146 sax->ns_stack = parent;
554 146 }
555  
556 void
557 35 PmmAddNamespace( PmmSAXVectorPtr sax, const xmlChar * name,
558 const xmlChar * href, SV *handler)
559 {
560 35 xmlNsPtr ns = NULL;
561 35 xmlChar * prefix = NULL;
562 35 xmlChar * localname = NULL;
563  
564  
565 35 ▶ if ( sax->ns_stack == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( sax->ns_stack == NULL ) { 0 35 35
566 0 return;
567 }
568  
569 35 ns = xmlNewNs( sax->ns_stack, href, name );
570  
571 35 ▶ if ( sax->ns_stack->ns == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( sax->ns_stack->ns == NULL ) { 33 2 35
572 33 localname = xmlSplitQName( NULL, sax->ns_stack->name, &prefix );
573  
574 33 ▶ if ( name != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( name != NULL ) { 29 4 33
575 29 ▶ if ( xmlStrEqual( prefix , name ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( xmlStrEqual( prefix , name ) ) { 10 19 29
576 10 xmlChar * oname = (xmlChar*)(sax->ns_stack->name);
577 10 sax->ns_stack->ns = ns;
578 10 xmlFree( oname );
579 10 sax->ns_stack->name = (const xmlChar*) xmlStrdup( localname );
580 }
581 }
582 4 ▶ else if ( prefix == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
else if ( prefix == NULL ) { 4 0 4
583 4 sax->ns_stack->ns = ns;
584 }
585 }
586  
587 35 ▶ if ( prefix ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( prefix ) { 22 13 35
588 22 xmlFree( prefix );
589 }
590 35 ▶ if ( localname ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( localname ) { 33 2 35
591 33 xmlFree( localname );
592 }
593  
594 35 PSaxStartPrefix( sax, name, href, handler );
595 }
596  
597 #define XML_STR_NOT_EMPTY(s) ((s)[0] != 0)
598  
599 HV *
600 297 PmmGenElementSV( pTHX_ PmmSAXVectorPtr sax, const xmlChar * name )
601 {
602 297 HV * retval = newHV();
603 297 xmlChar * localname = NULL;
604 297 xmlChar * prefix = NULL;
605  
606 297 xmlNsPtr ns = NULL;
607  
608 297 ▶ if ( name != NULL && XML_STR_NOT_EMPTY( name ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( name != NULL && XML_STR_NOT_EMPTY( name ) ) { 297 0 297
if ( name != NULL && XML_STR_NOT_EMPTY( name ) ) { 297 0 297
609 297 (void) hv_store(retval, "Name", 4,
610 _C2Sv(name, NULL), NameHash);
611  
612 297 localname = xmlSplitQName(NULL, name, &prefix);
613 297 ▶ if (localname != NULL) xmlFree(localname);
Branch: 1 branch
BranchTrueFalseTotal
if (localname != NULL) xmlFree(localname); 297 0 297
614 297 ns = PmmGetNsMapping( sax->ns_stack, prefix );
615 297 ▶ if (prefix != NULL) xmlFree(prefix);
Branch: 1 branch
BranchTrueFalseTotal
if (prefix != NULL) xmlFree(prefix); 52 245 297
616  
617 297 ▶ if ( ns != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ns != NULL ) { 82 215 297
618 82 (void) hv_store(retval, "NamespaceURI", 12,
619 _C2Sv(ns->href, NULL), NsURIHash);
620 82 ▶ if ( ns->prefix ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ns->prefix ) { 52 30 82
621 52 (void) hv_store(retval, "Prefix", 6,
622 _C2Sv(ns->prefix, NULL), PrefixHash);
623 }
624 else {
625 30 (void) hv_store(retval, "Prefix", 6,
626 _C2Sv((const xmlChar *)"",NULL), PrefixHash);
627 }
628  
629 82 (void) hv_store(retval, "LocalName", 9,
630 _C2Sv(sax->ns_stack->name, NULL), LocalNameHash);
631 }
632 else {
633 215 (void) hv_store(retval, "NamespaceURI", 12,
634 _C2Sv((const xmlChar *)"",NULL), NsURIHash);
635 215 (void) hv_store(retval, "Prefix", 6,
636 _C2Sv((const xmlChar *)"",NULL), PrefixHash);
637 215 (void) hv_store(retval, "LocalName", 9,
638 _C2Sv(name, NULL), LocalNameHash);
639 }
640 }
641  
642 297 return retval;
643 }
644  
645 xmlChar *
646 69 PmmGenNsName( const xmlChar * name, const xmlChar * nsURI )
647 {
648 69 int namelen = 0;
649 69 int urilen = 0;
650 69 xmlChar * retval = NULL;
651  
652 69 ▶ if ( name == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( name == NULL ) { 0 69 69
653 0 return NULL;
654 }
655 69 namelen = xmlStrlen( name );
656  
657 69 retval = xmlStrncat( retval, (const xmlChar *)"{", 1 );
658 69 ▶ if ( nsURI != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( nsURI != NULL ) { 43 26 69
659 43 urilen = xmlStrlen( nsURI );
660 43 retval = xmlStrncat( retval, nsURI, urilen );
661 }
662 69 retval = xmlStrncat( retval, (const xmlChar *)"}", 1 );
663 69 retval = xmlStrncat( retval, name, namelen );
664 69 return retval;
665 }
666  
667 HV *
668 151 PmmGenAttributeHashSV( pTHX_ PmmSAXVectorPtr sax,
669 const xmlChar **attr, SV * handler )
670 {
671 151 HV * retval = NULL;
672 151 HV * atV = NULL;
673 151 xmlNsPtr ns = NULL;
674  
675 151 U32 atnameHash = 0;
676 151 int len = 0;
677  
678 151 const xmlChar * nsURI = NULL;
679 151 const xmlChar **ta = attr;
680 151 const xmlChar * name = NULL;
681 151 const xmlChar * value = NULL;
682  
683 151 xmlChar * keyname = NULL;
684 151 xmlChar * localname = NULL;
685 151 xmlChar * prefix = NULL;
686  
687 151 retval = newHV();
688  
689 151 ▶ if ( ta != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ta != NULL ) { 43 108 151
690 112 ▶ while ( *ta != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
while ( *ta != NULL ) { 69 43 112
691 69 atV = newHV();
692 69 name = *ta; ta++;
693 69 value = *ta; ta++;
694  
695 69 ▶ if ( name != NULL && XML_STR_NOT_EMPTY( name ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( name != NULL && XML_STR_NOT_EMPTY( name ) ) { 69 0 69
if ( name != NULL && XML_STR_NOT_EMPTY( name ) ) { 69 0 69
696 69 localname = xmlSplitQName(NULL, name, &prefix);
697  
698 69 (void) hv_store(atV, "Name", 4,
699 _C2Sv(name, NULL), NameHash);
700 69 ▶ if ( value != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( value != NULL ) { 69 0 69
701 69 (void) hv_store(atV, "Value", 5,
702 _C2Sv(value, NULL), ValueHash);
703 }
704  
705 69 ▶ if ( xmlStrEqual( (const xmlChar *)"xmlns", name ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( xmlStrEqual( (const xmlChar *)"xmlns", name ) ) { 4 65 69
706 /* a default namespace */
707 4 PmmAddNamespace( sax, NULL, value, handler);
708 /* nsURI = (const xmlChar*)NSDEFAULTURI; */
709 4 nsURI = NULL;
710 4 (void) hv_store(atV, "Name", 4,
711 _C2Sv(name, NULL), NameHash);
712  
713 4 (void) hv_store(atV, "Prefix", 6,
714 _C2Sv((const xmlChar *)"", NULL), PrefixHash);
715 4 (void) hv_store(atV, "LocalName", 9,
716 _C2Sv(name,NULL), LocalNameHash);
717 4 (void) hv_store(atV, "NamespaceURI", 12,
718 _C2Sv((const xmlChar *)"", NULL), NsURIHash);
719  
720 }
721 65 ▶ else if (xmlStrncmp((const xmlChar *)"xmlns:", name, 6 ) == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
else if (xmlStrncmp((const xmlChar *)"xmlns:", name, 6 ) == 0 ) { 31 34 65
722 31 PmmAddNamespace( sax,
723 localname,
724 value,
725 handler);
726  
727 31 nsURI = (const xmlChar*)NSDEFAULTURI;
728  
729 31 (void) hv_store(atV, "Prefix", 6,
730 _C2Sv(prefix, NULL), PrefixHash);
731 31 (void) hv_store(atV, "LocalName", 9,
732 _C2Sv(localname, NULL), LocalNameHash);
733 31 (void) hv_store(atV, "NamespaceURI", 12,
734 _C2Sv((const xmlChar *)NSDEFAULTURI,NULL),
735 NsURIHash);
736 }
737 34 ▶ else if ( prefix != NULL
Branch: 1 branch
BranchTrueFalseTotal
else if ( prefix != NULL 13 21 34
738 13 ▶ && (ns = PmmGetNsMapping( sax->ns_stack, prefix ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
&& (ns = PmmGetNsMapping( sax->ns_stack, prefix ) ) ) { 12 1 13
739 12 nsURI = ns->href;
740  
741 12 (void) hv_store(atV, "NamespaceURI", 12,
742 _C2Sv(ns->href, NULL), NsURIHash);
743 12 (void) hv_store(atV, "Prefix", 6,
744 _C2Sv(ns->prefix, NULL), PrefixHash);
745 12 (void) hv_store(atV, "LocalName", 9,
746 _C2Sv(localname, NULL), LocalNameHash);
747 }
748 else {
749 22 nsURI = NULL;
750 22 (void) hv_store(atV, "NamespaceURI", 12,
751 _C2Sv((const xmlChar *)"", NULL), NsURIHash);
752 22 (void) hv_store(atV, "Prefix", 6,
753 _C2Sv((const xmlChar *)"", NULL), PrefixHash);
754 22 (void) hv_store(atV, "LocalName", 9,
755 _C2Sv(name, NULL), LocalNameHash);
756 }
757  
758 69 ▶ keyname = PmmGenNsName( localname != NULL ? localname : name,
Branch: 1 branch
BranchTrueFalseTotal
keyname = PmmGenNsName( localname != NULL ? localname : name, 69 0 69
759 nsURI );
760  
761 69 len = xmlStrlen( keyname );
762 69 ▶ PERL_HASH( atnameHash, (const char *)keyname, len );
Branch: 1 branch
BranchTrueFalseTotal
PERL_HASH( atnameHash, (const char *)keyname, len ); 31 38 69
763 69 (void) hv_store(retval,
764 (const char *)keyname,
765 len,
766 newRV_noinc((SV*)atV),
767 atnameHash );
768  
769 69 ▶ if ( keyname != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( keyname != NULL ) { 69 0 69
770 69 xmlFree( keyname );
771 }
772 69 ▶ if ( localname != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( localname != NULL ) { 69 0 69
773 69 xmlFree(localname);
774 }
775 69 localname = NULL;
776 69 ▶ if ( prefix != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( prefix != NULL ) { 44 25 69
777 44 xmlFree( prefix );
778 }
779 69 prefix = NULL;
780  
781 }
782 }
783 }
784  
785 151 return retval;
786 }
787  
788 HV *
789 116 PmmGenCharDataSV( pTHX_ PmmSAXVectorPtr sax, const xmlChar * data, int len )
790 {
791 116 HV * retval = newHV();
792  
793 116 ▶ if ( data != NULL && XML_STR_NOT_EMPTY( data ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( data != NULL && XML_STR_NOT_EMPTY( data ) ) { 116 0 116
if ( data != NULL && XML_STR_NOT_EMPTY( data ) ) { 113 3 116
794 113 (void) hv_store(retval, "Data", 4,
795 _C2Sv_len(data, len), DataHash);
796 }
797  
798 116 return retval;
799 }
800  
801 HV *
802 0 PmmGenPISV( pTHX_ PmmSAXVectorPtr sax,
803 const xmlChar * target,
804 const xmlChar * data )
805 {
806 0 HV * retval = newHV();
807  
808 0 ▶ if ( target != NULL && XML_STR_NOT_EMPTY( target ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( target != NULL && XML_STR_NOT_EMPTY( target ) ) { 0 0 0
if ( target != NULL && XML_STR_NOT_EMPTY( target ) ) { 0 0 0
809 0 (void) hv_store(retval, "Target", 6,
810 _C2Sv(target, NULL), TargetHash);
811  
812 0 ▶ if ( data != NULL && XML_STR_NOT_EMPTY( data ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( data != NULL && XML_STR_NOT_EMPTY( data ) ) { 0 0 0
if ( data != NULL && XML_STR_NOT_EMPTY( data ) ) { 0 0 0
813 0 (void) hv_store(retval, "Data", 4,
814 _C2Sv(data, NULL), DataHash);
815 }
816 else {
817 0 (void) hv_store(retval, "Data", 4,
818 _C2Sv((const xmlChar *)"", NULL), DataHash);
819 }
820 }
821  
822 0 return retval;
823 }
824  
825 HV *
826 9 PmmGenDTDSV( pTHX_ PmmSAXVectorPtr sax,
827 const xmlChar * name,
828 const xmlChar * publicId,
829 const xmlChar * systemId )
830 {
831 9 HV * retval = newHV();
832 9 ▶ if ( name != NULL && XML_STR_NOT_EMPTY( name ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( name != NULL && XML_STR_NOT_EMPTY( name ) ) { 9 0 9
if ( name != NULL && XML_STR_NOT_EMPTY( name ) ) { 9 0 9
833 9 (void) hv_store(retval, "Name", 4,
834 _C2Sv(name, NULL), NameHash);
835 }
836 9 ▶ if ( publicId != NULL && XML_STR_NOT_EMPTY( publicId ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( publicId != NULL && XML_STR_NOT_EMPTY( publicId ) ) { 0 9 9
if ( publicId != NULL && XML_STR_NOT_EMPTY( publicId ) ) { 0 0 0
837 0 (void) hv_store(retval, "PublicId", 8,
838 _C2Sv(publicId, NULL), PublicIdHash);
839 }
840 9 ▶ if ( systemId != NULL && XML_STR_NOT_EMPTY( systemId ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( systemId != NULL && XML_STR_NOT_EMPTY( systemId ) ) { 0 9 9
if ( systemId != NULL && XML_STR_NOT_EMPTY( systemId ) ) { 0 0 0
841 0 (void) hv_store(retval, "SystemId", 8,
842 _C2Sv(systemId, NULL), SystemIdHash);
843 }
844 9 return retval;
845 }
846  
847 HV *
848 74 PmmGenLocator( xmlSAXLocatorPtr loc)
849 {
850 dTHX;
851 74 HV * locator = newHV();
852  
853 74 const xmlChar * PublicId = loc->getPublicId(NULL);
854 74 const xmlChar * SystemId = loc->getSystemId(NULL);
855  
856 74 ▶ if ( PublicId != NULL && XML_STR_NOT_EMPTY( PublicId ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( PublicId != NULL && XML_STR_NOT_EMPTY( PublicId ) ) { 0 74 74
if ( PublicId != NULL && XML_STR_NOT_EMPTY( PublicId ) ) { 0 0 0
857 0 (void) hv_store(locator, "PublicId", 8,
858 newSVpv((char *)PublicId, 0), 0);
859 }
860  
861 74 ▶ if ( SystemId != NULL && XML_STR_NOT_EMPTY( SystemId ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( SystemId != NULL && XML_STR_NOT_EMPTY( SystemId ) ) { 0 74 74
if ( SystemId != NULL && XML_STR_NOT_EMPTY( SystemId ) ) { 0 0 0
862 0 (void) hv_store(locator, "SystemId", 8,
863 newSVpv((char *)SystemId, 0), 0);
864 }
865  
866 74 return locator;
867 }
868  
869  
870 void
871 496 PmmUpdateLocator( xmlParserCtxtPtr ctxt )
872 {
873 dTHX;
874 const xmlChar * encoding;
875 const xmlChar * version;
876 496 PmmSAXVectorPtr sax = (PmmSAXVectorPtr)ctxt->_private;
877  
878 496 ▶ if (sax->locator == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (sax->locator == NULL) { 105 391 496
879 105 return;
880 }
881  
882 391 (void) hv_store(sax->locator, "LineNumber", 10,
883 newSViv(ctxt->input->line), 0);
884  
885 391 (void) hv_store(sax->locator, "ColumnNumber", 12,
886 newSViv(ctxt->input->col), 0);
887  
888 391 encoding = ctxt->input->encoding;
889 391 version = ctxt->input->version;
890  
891 391 ▶ if ( encoding != NULL && XML_STR_NOT_EMPTY( encoding ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( encoding != NULL && XML_STR_NOT_EMPTY( encoding ) ) { 0 391 391
if ( encoding != NULL && XML_STR_NOT_EMPTY( encoding ) ) { 0 0 0
892 0 (void) hv_store(sax->locator, "Encoding", 8,
893 newSVpv((char *)encoding, 0), 0);
894 }
895  
896 391 ▶ if ( version != NULL && XML_STR_NOT_EMPTY( version ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( version != NULL && XML_STR_NOT_EMPTY( version ) ) { 0 391 391
if ( version != NULL && XML_STR_NOT_EMPTY( version ) ) { 0 0 0
897 0 (void) hv_store(sax->locator, "XMLVersion", 10,
898 newSVpv((char *)version, 0), 0);
899 }
900 }
901  
902 int
903 74 PSaxSetDocumentLocator(void *ctx, xmlSAXLocatorPtr loc)
904 {
905 74 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr)ctx;
906 74 PmmSAXVectorPtr sax = (PmmSAXVectorPtr)ctxt->_private;
907 dTHX;
908 HV* empty;
909 74 SV * handler = sax->handler;
910 SV * rv;
911  
912 74 dSP;
913  
914 74 ▶ if (sax->joinchars)
Branch: 1 branch
BranchTrueFalseTotal
if (sax->joinchars) 0 74 74
915 {
916 0 PSaxCharactersFlush(ctxt, sax->charbuf);
917 }
918  
919 74 ENTER;
920 74 SAVETMPS;
921  
922 74 ▶ PUSHMARK(SP) ;
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP) ; 0 74 74
923  
924 74 ▶ XPUSHs(handler);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(handler); 0 74 74
925  
926 74 sax->locator = PmmGenLocator(loc);
927  
928 74 rv = newRV_inc((SV*)sax->locator);
929 74 ▶ XPUSHs( rv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs( rv); 0 74 74
930  
931 74 PUTBACK;
932  
933 74 call_method( "set_document_locator", G_SCALAR | G_EVAL | G_DISCARD );
934 74 sv_2mortal(rv) ;
935  
936 74 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 74 0 74
if (SvTRUE(ERRSV)) { 0 74 74
937 0 croak_obj;
938 }
939  
940 74 ▶ FREETMPS ;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS ; 74 0 74
941 74 LEAVE ;
942 CLEAR_SERROR_HANDLER
943 74 return 1;
944 }
945  
946 int
947 74 PSaxStartDocument(void * ctx)
948 {
949 74 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr)ctx;
950 74 PmmSAXVectorPtr sax = (PmmSAXVectorPtr)ctxt->_private;
951 dTHX;
952 HV* empty;
953 74 SV * handler = sax->handler;
954  
955 SV * rv;
956 74 ▶ if ( handler != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( handler != NULL ) { 74 0 74
957  
958 74 dSP;
959 74 PmmUpdateLocator(ctx);
960  
961 74 ENTER;
962 74 SAVETMPS;
963  
964 74 empty = newHV();
965 74 ▶ PUSHMARK(SP) ;
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP) ; 0 74 74
966 74 ▶ XPUSHs(handler);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(handler); 0 74 74
967 74 ▶ XPUSHs(sv_2mortal(newRV_noinc((SV*)empty)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newRV_noinc((SV*)empty))); 0 74 74
968 74 PUTBACK;
969  
970 74 call_method( "start_document", G_SCALAR | G_EVAL | G_DISCARD );
971 74 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 74 0 74
if (SvTRUE(ERRSV)) { 0 74 74
972 0 croak_obj;
973 }
974  
975 74 SPAGAIN;
976  
977 74 ▶ PUSHMARK(SP) ;
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP) ; 0 74 74
978  
979  
980 74 ▶ XPUSHs(handler);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(handler); 0 74 74
981  
982 74 empty = newHV();
983 74 ▶ if ( ctxt->version != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ctxt->version != NULL ) { 74 0 74
984 74 (void) hv_store(empty, "Version", 7,
985 _C2Sv(ctxt->version, NULL), VersionHash);
986 }
987 else {
988 0 (void) hv_store(empty, "Version", 7,
989 _C2Sv((const xmlChar *)"1.0", NULL), VersionHash);
990 }
991  
992 74 ▶ if ( ctxt->input->encoding != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ctxt->input->encoding != NULL ) { 0 74 74
993 0 (void) hv_store(empty, "Encoding", 8,
994 _C2Sv(ctxt->input->encoding, NULL), EncodingHash);
995 }
996  
997 74 rv = newRV_noinc((SV*)empty);
998 74 ▶ XPUSHs( rv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs( rv); 0 74 74
999  
1000 74 PUTBACK;
1001  
1002 74 call_method( "xml_decl", G_SCALAR | G_EVAL | G_DISCARD );
1003 CLEAR_SERROR_HANDLER
1004 74 sv_2mortal(rv);
1005 74 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 74 0 74
if (SvTRUE(ERRSV)) { 0 74 74
1006 0 croak_obj;
1007 }
1008  
1009 74 ▶ FREETMPS ;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS ; 74 0 74
1010 74 LEAVE ;
1011 }
1012 CLEAR_SERROR_HANDLER
1013 74 return 1;
1014 }
1015  
1016 int
1017 0 PSaxEndDocument(void * ctx)
1018 {
1019 0 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr)ctx;
1020 0 PmmSAXVectorPtr sax = (PmmSAXVectorPtr)ctxt->_private;
1021  
1022 dTHX;
1023 0 dSP;
1024  
1025 0 PmmUpdateLocator(ctx);
1026  
1027 0 ▶ if (sax->joinchars)
Branch: 1 branch
BranchTrueFalseTotal
if (sax->joinchars) 0 0 0
1028 {
1029 0 PSaxCharactersFlush(ctxt, sax->charbuf);
1030 }
1031  
1032  
1033 0 ENTER;
1034 0 SAVETMPS;
1035  
1036 0 ▶ PUSHMARK(SP) ;
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP) ; 0 0 0
1037 0 ▶ XPUSHs(sax->parser);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sax->parser); 0 0 0
1038 0 PUTBACK;
1039  
1040 0 call_pv( "XML::LibXML::_SAXParser::end_document", G_SCALAR | G_EVAL | G_DISCARD );
1041 0 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 0 0 0
if (SvTRUE(ERRSV)) { 0 0 0
1042 0 croak_obj;
1043 }
1044  
1045 0 ▶ FREETMPS ;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS ; 0 0 0
1046 0 LEAVE ;
1047 CLEAR_SERROR_HANDLER
1048 0 return 1;
1049 }
1050  
1051 int
1052 151 PSaxStartElement(void *ctx, const xmlChar * name, const xmlChar** attr)
1053 {
1054 151 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr)ctx;
1055 151 PmmSAXVectorPtr sax = (PmmSAXVectorPtr)ctxt->_private;
1056 dTHX;
1057 151 HV * attrhash = NULL;
1058 151 HV * element = NULL;
1059 151 SV * handler = sax->handler;
1060 SV * rv;
1061 SV * arv;
1062  
1063 151 dSP;
1064  
1065 151 PmmUpdateLocator(ctx);
1066  
1067 151 ▶ if (sax->joinchars)
Branch: 1 branch
BranchTrueFalseTotal
if (sax->joinchars) 0 151 151
1068 {
1069 0 PSaxCharactersFlush(ctxt, sax->charbuf);
1070 }
1071  
1072 151 ENTER;
1073 151 SAVETMPS;
1074  
1075 151 PmmExtendNsStack(sax, name);
1076  
1077 151 attrhash = PmmGenAttributeHashSV(aTHX_ sax, attr, handler );
1078 151 element = PmmGenElementSV(aTHX_ sax, name);
1079  
1080 151 arv = newRV_noinc((SV*)attrhash);
1081 151 (void) hv_store( element,
1082 "Attributes",
1083 10,
1084 arv,
1085 AttributesHash );
1086  
1087 151 ▶ PUSHMARK(SP) ;
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP) ; 0 151 151
1088  
1089 151 ▶ XPUSHs(handler);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(handler); 0 151 151
1090 151 rv = newRV_noinc((SV*)element);
1091 151 ▶ XPUSHs(rv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(rv); 0 151 151
1092 151 PUTBACK;
1093  
1094 151 call_method( "start_element", G_SCALAR | G_EVAL | G_DISCARD );
1095 151 sv_2mortal(rv) ;
1096  
1097 151 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 151 0 151
if (SvTRUE(ERRSV)) { 1 150 151
1098 1 croak_obj;
1099 }
1100  
1101 150 ▶ FREETMPS ;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS ; 150 0 150
1102 150 LEAVE ;
1103 CLEAR_SERROR_HANDLER
1104 150 return 1;
1105 }
1106  
1107 int
1108 146 PSaxEndElement(void *ctx, const xmlChar * name) {
1109 146 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr)ctx;
1110 146 PmmSAXVectorPtr sax = (PmmSAXVectorPtr)ctxt->_private;
1111 dTHX;
1112 146 SV * handler = sax->handler;
1113 SV * rv;
1114 HV * element;
1115  
1116 146 dSP;
1117  
1118 146 PmmUpdateLocator(ctx);
1119  
1120 146 ▶ if (sax->joinchars)
Branch: 1 branch
BranchTrueFalseTotal
if (sax->joinchars) 0 146 146
1121 {
1122 0 PSaxCharactersFlush(ctxt, sax->charbuf);
1123 }
1124  
1125 146 ENTER;
1126 146 SAVETMPS;
1127  
1128 146 ▶ PUSHMARK(SP) ;
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP) ; 0 146 146
1129 146 ▶ XPUSHs(handler);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(handler); 0 146 146
1130  
1131 146 element = PmmGenElementSV(aTHX_ sax, name);
1132 146 rv = newRV_noinc((SV*)element);
1133  
1134 146 ▶ XPUSHs(rv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(rv); 0 146 146
1135 146 PUTBACK;
1136  
1137 146 call_method( "end_element", G_SCALAR | G_EVAL | G_DISCARD );
1138 146 sv_2mortal(rv);
1139  
1140 146 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 146 0 146
if (SvTRUE(ERRSV)) { 0 146 146
1141 0 croak_obj;
1142 }
1143  
1144 146 ▶ FREETMPS ;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS ; 146 0 146
1145 146 LEAVE ;
1146  
1147 146 PmmNarrowNsStack(sax, handler);
1148 CLEAR_SERROR_HANDLER
1149 146 return 1;
1150 }
1151  
1152 int
1153 89 PSaxCharactersDispatch(void *ctx, const xmlChar * ch, int len) {
1154 89 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr)ctx;
1155 89 PmmSAXVectorPtr sax = (PmmSAXVectorPtr)ctxt->_private;
1156 dTHX;
1157 HV* element;
1158 SV * handler;
1159 89 SV * rv = NULL;
1160  
1161 89 ▶ if ( sax == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( sax == NULL ) { 0 89 89
1162 /* warn( "lost my sax context!? ( %s, %d )\n", ch, len ); */
1163 0 return 0;
1164 }
1165  
1166 89 handler = sax->handler;
1167  
1168 89 ▶ if ( ch != NULL && handler != NULL ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( ch != NULL && handler != NULL ) { 89 0 89
if ( ch != NULL && handler != NULL ) { 89 0 89
1169  
1170 89 dSP;
1171  
1172 89 ENTER;
1173 89 SAVETMPS;
1174  
1175 89 ▶ PUSHMARK(SP) ;
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP) ; 0 89 89
1176  
1177 89 ▶ XPUSHs(handler);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(handler); 0 89 89
1178 89 element = PmmGenCharDataSV(aTHX_ sax, ch, len );
1179  
1180 89 rv = newRV_noinc((SV*)element);
1181 89 ▶ XPUSHs(rv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(rv); 0 89 89
1182 89 sv_2mortal(rv);
1183  
1184 89 PUTBACK;
1185  
1186 89 call_method( "characters", G_SCALAR | G_EVAL | G_DISCARD );
1187  
1188 89 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 89 0 89
if (SvTRUE(ERRSV)) { 0 89 89
1189 0 croak_obj;
1190 }
1191 89 ▶ FREETMPS ;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS ; 89 0 89
1192 89 LEAVE ;
1193  
1194 }
1195 CLEAR_SERROR_HANDLER;
1196 89 return 1;
1197 }
1198  
1199 0 int PSaxCharactersFlush (void *ctx, struct CBuffer *buffer) {
1200 0 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr)ctx;
1201 0 PmmSAXVectorPtr sax = (PmmSAXVectorPtr)ctxt->_private;
1202 xmlChar *ch;
1203 size_t buflen;
1204 int len;
1205 int ret;
1206  
1207 0 ▶ if (buffer->head->data == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (buffer->head->data == NULL) { 0 0 0
1208 0 return 1;
1209 }
1210  
1211 0 ch = CBufferCharacters(sax->charbuf);
1212 0 buflen = CBufferLength(sax->charbuf);
1213 0 ▶ if (buflen > (size_t)INT_MAX) {
Branch: 1 branch
BranchTrueFalseTotal
if (buflen > (size_t)INT_MAX) { 0 0 0
1214 0 xmlFree(ch);
1215 0 CBufferPurge(buffer);
1216 0 croak("XML::LibXML: SAX character data exceeds maximum length");
1217 }
1218 0 len = (int)buflen;
1219  
1220 0 CBufferPurge(buffer);
1221  
1222 0 ret = PSaxCharactersDispatch(ctx, ch, len);
1223 0 xmlFree(ch);
1224 0 return ret;
1225 }
1226  
1227 89 int PSaxCharacters (void *ctx, const xmlChar * ch, int len) {
1228 89 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr)ctx;
1229 89 PmmSAXVectorPtr sax = (PmmSAXVectorPtr)ctxt->_private;
1230  
1231 89 PmmUpdateLocator(ctx);
1232  
1233 89 ▶ if (sax->joinchars) {
Branch: 1 branch
BranchTrueFalseTotal
if (sax->joinchars) { 0 89 89
1234 0 struct CBuffer *buffer = sax->charbuf;
1235 0 CBufferAppend(buffer, ch, len);
1236 0 return 1;
1237 }
1238  
1239 89 return PSaxCharactersDispatch(ctx, ch, len);
1240 }
1241  
1242 int
1243 15 PSaxComment(void *ctx, const xmlChar * ch) {
1244 15 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr)ctx;
1245 15 PmmSAXVectorPtr sax = (PmmSAXVectorPtr)ctxt->_private;
1246 dTHX;
1247 HV* element;
1248 15 SV * handler = sax->handler;
1249 15 SV * rv = NULL;
1250  
1251 15 PmmUpdateLocator(ctx);
1252  
1253 15 ▶ if ( ch != NULL && handler != NULL ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( ch != NULL && handler != NULL ) { 15 0 15
if ( ch != NULL && handler != NULL ) { 15 0 15
1254 15 dSP;
1255  
1256 15 int len = xmlStrlen( ch );
1257  
1258 15 ▶ if (sax->joinchars)
Branch: 1 branch
BranchTrueFalseTotal
if (sax->joinchars) 0 15 15
1259 {
1260 0 PSaxCharactersFlush(ctxt, sax->charbuf);
1261 }
1262  
1263 15 ENTER;
1264 15 SAVETMPS;
1265  
1266 15 ▶ PUSHMARK(SP) ;
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP) ; 0 15 15
1267 15 ▶ XPUSHs(handler);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(handler); 0 15 15
1268 15 element = PmmGenCharDataSV(aTHX_ sax, ch, len);
1269  
1270 15 rv = newRV_noinc((SV*)element);
1271 15 ▶ XPUSHs(rv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(rv); 0 15 15
1272 15 PUTBACK;
1273  
1274 15 call_method( "comment", G_SCALAR | G_EVAL | G_DISCARD );
1275 15 sv_2mortal(rv);
1276  
1277 15 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 15 0 15
if (SvTRUE(ERRSV)) { 0 15 15
1278 0 croak_obj;
1279 }
1280  
1281 15 ▶ FREETMPS ;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS ; 15 0 15
1282 15 LEAVE ;
1283 }
1284 CLEAR_SERROR_HANDLER
1285 15 return 1;
1286 }
1287  
1288 int
1289 12 PSaxCDATABlock(void *ctx, const xmlChar * ch, int len) {
1290 12 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr)ctx;
1291 12 PmmSAXVectorPtr sax = (PmmSAXVectorPtr)ctxt->_private;
1292 dTHX;
1293 HV* element;
1294 12 SV * handler = sax->handler;
1295 12 SV * rv = NULL;
1296  
1297 12 PmmUpdateLocator(ctx);
1298  
1299 12 ▶ if ( ch != NULL && handler != NULL ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( ch != NULL && handler != NULL ) { 12 0 12
if ( ch != NULL && handler != NULL ) { 12 0 12
1300 12 dSP;
1301  
1302 12 ▶ if (sax->joinchars)
Branch: 1 branch
BranchTrueFalseTotal
if (sax->joinchars) 0 12 12
1303 {
1304 0 PSaxCharactersFlush(ctxt, sax->charbuf);
1305 }
1306  
1307  
1308 12 ENTER;
1309 12 SAVETMPS;
1310  
1311 12 ▶ PUSHMARK(SP) ;
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP) ; 0 12 12
1312 12 ▶ XPUSHs(handler);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(handler); 0 12 12
1313 12 PUTBACK;
1314 12 call_method( "start_cdata", G_SCALAR | G_EVAL | G_DISCARD );
1315 12 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 12 0 12
if (SvTRUE(ERRSV)) { 0 12 12
1316 0 croak_obj;
1317 }
1318  
1319 12 SPAGAIN;
1320 12 ▶ PUSHMARK(SP) ;
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP) ; 0 12 12
1321  
1322 12 ▶ XPUSHs(handler);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(handler); 0 12 12
1323 12 element = PmmGenCharDataSV(aTHX_ sax, ch, len);
1324  
1325 12 rv = newRV_noinc((SV*)element);
1326 12 ▶ XPUSHs(rv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(rv); 0 12 12
1327 12 PUTBACK;
1328  
1329 12 call_method( "characters", G_SCALAR | G_EVAL | G_DISCARD);
1330 12 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 12 0 12
if (SvTRUE(ERRSV)) { 0 12 12
1331 0 croak_obj;
1332 }
1333  
1334 12 SPAGAIN;
1335 12 ▶ PUSHMARK(SP) ;
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP) ; 0 12 12
1336  
1337 12 ▶ XPUSHs(handler);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(handler); 0 12 12
1338 12 PUTBACK;
1339  
1340 12 call_method( "end_cdata", G_SCALAR | G_EVAL | G_DISCARD );
1341 12 sv_2mortal(rv);
1342  
1343 12 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 12 0 12
if (SvTRUE(ERRSV)) { 0 12 12
1344 0 croak_obj;
1345 }
1346  
1347 12 ▶ FREETMPS ;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS ; 12 0 12
1348 12 LEAVE ;
1349  
1350 }
1351 CLEAR_SERROR_HANDLER
1352 12 return 1;
1353  
1354 }
1355  
1356 int
1357 0 PSaxProcessingInstruction( void * ctx, const xmlChar * target, const xmlChar * data )
1358 {
1359 0 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr)ctx;
1360 0 PmmSAXVectorPtr sax = (PmmSAXVectorPtr)ctxt->_private;
1361 dTHX;
1362 0 SV * handler = sax->handler;
1363 SV * element;
1364 0 SV * rv = NULL;
1365  
1366 0 PmmUpdateLocator(ctx);
1367  
1368 0 ▶ if ( handler != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( handler != NULL ) { 0 0 0
1369 0 dSP;
1370  
1371 0 ▶ if (sax->joinchars)
Branch: 1 branch
BranchTrueFalseTotal
if (sax->joinchars) 0 0 0
1372 {
1373 0 PSaxCharactersFlush(ctxt, sax->charbuf);
1374 }
1375  
1376 0 ENTER;
1377 0 SAVETMPS;
1378  
1379 0 ▶ PUSHMARK(SP) ;
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP) ; 0 0 0
1380 0 ▶ XPUSHs(handler);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(handler); 0 0 0
1381 0 element = (SV*)PmmGenPISV(aTHX_ sax, (const xmlChar *)target, data);
1382 0 rv = newRV_noinc((SV*)element);
1383 0 ▶ XPUSHs(rv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(rv); 0 0 0
1384  
1385 0 PUTBACK;
1386  
1387 0 call_method( "processing_instruction", G_SCALAR | G_EVAL | G_DISCARD );
1388  
1389 0 sv_2mortal(rv);
1390  
1391 0 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 0 0 0
if (SvTRUE(ERRSV)) { 0 0 0
1392 0 croak_obj;
1393 }
1394  
1395 0 ▶ FREETMPS ;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS ; 0 0 0
1396 0 LEAVE ;
1397 }
1398 CLEAR_SERROR_HANDLER
1399 0 return 1;
1400 }
1401  
1402 9 void PSaxExternalSubset (void * ctx,
1403 const xmlChar * name,
1404 const xmlChar * ExternalID,
1405 const xmlChar * SystemID)
1406 {
1407 9 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr)ctx;
1408 9 PmmSAXVectorPtr sax = (PmmSAXVectorPtr)ctxt->_private;
1409  
1410 dTHX;
1411 9 SV * handler = sax->handler;
1412 SV * element;
1413 9 SV * rv = NULL;
1414  
1415 9 PmmUpdateLocator(ctx);
1416  
1417 9 ▶ if ( handler != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( handler != NULL ) { 9 0 9
1418 9 dSP;
1419  
1420 9 ENTER;
1421 9 SAVETMPS;
1422  
1423 9 ▶ PUSHMARK(SP) ;
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP) ; 0 9 9
1424 9 ▶ XPUSHs(handler);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(handler); 0 9 9
1425 9 element = (SV*)PmmGenDTDSV(aTHX_ sax,
1426 name,
1427 ExternalID,
1428 SystemID);
1429 9 rv = newRV_noinc((SV*)element);
1430 9 ▶ XPUSHs(rv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(rv); 0 9 9
1431  
1432 9 PUTBACK;
1433  
1434 9 call_method( "start_dtd", G_SCALAR | G_EVAL | G_DISCARD );
1435 9 sv_2mortal(rv);
1436  
1437 9 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 9 0 9
if (SvTRUE(ERRSV)) { 0 9 9
1438 0 croak_obj;
1439 }
1440  
1441 9 ▶ PUSHMARK(SP) ;
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP) ; 0 9 9
1442 9 ▶ XPUSHs(handler);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(handler); 0 9 9
1443 9 rv = newRV_noinc((SV*)newHV()); /* empty */
1444 9 ▶ XPUSHs(rv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(rv); 0 9 9
1445  
1446 9 PUTBACK;
1447  
1448 9 call_method( "end_dtd", G_SCALAR | G_EVAL | G_DISCARD );
1449  
1450 9 ▶ FREETMPS ;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS ; 9 0 9
1451 9 LEAVE ;
1452 }
1453 CLEAR_SERROR_HANDLER
1454 9 return;
1455 }
1456  
1457  
1458 /*
1459  
1460 void PSaxInternalSubset (void * ctx,
1461 const xmlChar * name,
1462 const xmlChar * ExternalID,
1463 const xmlChar * SystemID)
1464 {
1465 // called before ExternalSubset
1466 // if used, how do we generate the correct start_dtd ?
1467 }
1468  
1469 void PSaxElementDecl (void *ctx, const xmlChar *name,
1470 int type,
1471 xmlElementContentPtr content) {
1472 // this one is not easy to implement
1473 // since libxml2 has no (reliable) public method
1474 // for dumping xmlElementContent :-(
1475 }
1476  
1477 void
1478 PSaxAttributeDecl (void * ctx,
1479 const xmlChar * elem,
1480 const xmlChar * fullname,
1481 int type,
1482 int def,
1483 const xmlChar * defaultValue,
1484 xmlEnumerationPtr tree)
1485 {
1486 }
1487  
1488 void
1489 PSaxEntityDecl (void * ctx,
1490 const xmlChar * name,
1491 int type,
1492 const xmlChar * publicId,
1493 const xmlChar * systemId,
1494 xmlChar * content)
1495 {
1496 }
1497  
1498 void
1499 PSaxNotationDecl (void * ctx,
1500 const xmlChar * name,
1501 const xmlChar * publicId,
1502 const xmlChar * systemId)
1503 {
1504 }
1505  
1506 void
1507 PSaxUnparsedEntityDecl (void * ctx,
1508 const xmlChar * name,
1509 const xmlChar * publicId,
1510 const xmlChar * systemId,
1511 const xmlChar * notationName)
1512 {
1513 }
1514 */
1515  
1516 int
1517 0 PmmSaxWarning(void * ctx, const char * msg, ...)
1518 {
1519 0 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr)ctx;
1520 0 PmmSAXVectorPtr sax = (PmmSAXVectorPtr)ctxt->_private;
1521  
1522 va_list args;
1523 SV * svMessage;
1524  
1525 dTHX;
1526 0 dSP;
1527 0 svMessage = NEWSV(0,512);
1528  
1529 0 va_start(args, msg);
1530 0 sv_vsetpvfn(svMessage,
1531 msg,
1532 xmlStrlen((const xmlChar *)msg),
1533 &args,
1534 NULL,
1535 0,
1536 NULL);
1537 0 va_end(args);
1538  
1539 0 ENTER;
1540 0 SAVETMPS;
1541  
1542 0 ▶ PUSHMARK(SP) ;
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP) ; 0 0 0
1543 0 ▶ XPUSHs(sax->parser);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sax->parser); 0 0 0
1544  
1545 0 ▶ XPUSHs(sv_2mortal(svMessage));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(svMessage)); 0 0 0
1546 0 ▶ XPUSHs(sv_2mortal(newSViv(ctxt->input->line)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(ctxt->input->line))); 0 0 0
1547 0 ▶ XPUSHs(sv_2mortal(newSViv(ctxt->input->col)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(ctxt->input->col))); 0 0 0
1548  
1549 0 PUTBACK;
1550  
1551 0 call_pv( "XML::LibXML::_SAXParser::warning", G_SCALAR | G_EVAL | G_DISCARD );
1552  
1553 0 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 0 0 0
if (SvTRUE(ERRSV)) { 0 0 0
1554 0 croak_obj;
1555 }
1556  
1557 0 ▶ FREETMPS ;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS ; 0 0 0
1558 0 LEAVE ;
1559 CLEAR_SERROR_HANDLER
1560 0 return 1;
1561 }
1562  
1563  
1564 int
1565 1 PmmSaxError(void * ctx, const char * msg, ...)
1566 {
1567 1 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr)ctx;
1568 1 PmmSAXVectorPtr sax = (PmmSAXVectorPtr)ctxt->_private;
1569  
1570 va_list args;
1571 SV * svMessage;
1572  
1573 #if LIBXML_VERSION > 20600
1574 1 const xmlError *last_err = xmlCtxtGetLastError( ctxt );
1575 #endif
1576 dTHX;
1577 1 dSP;
1578  
1579 1 ENTER;
1580 1 SAVETMPS;
1581  
1582 1 ▶ PUSHMARK(SP) ;
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP) ; 0 1 1
1583  
1584 1 ▶ XPUSHs(sax->parser);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sax->parser); 0 1 1
1585  
1586 1 svMessage = NEWSV(0,512);
1587  
1588 1 va_start(args, msg);
1589 1 sv_vsetpvfn(svMessage, msg, xmlStrlen((const xmlChar *)msg), &args, NULL, 0, NULL);
1590 1 va_end(args);
1591 1 ▶ if (SvOK(sax->saved_error)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(sax->saved_error)) { 0 1 1
1592 0 sv_catsv( sax->saved_error, svMessage );
1593 } else {
1594 1 sv_setsv( sax->saved_error, svMessage );
1595 }
1596 1 ▶ XPUSHs(sv_2mortal(svMessage));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(svMessage)); 0 1 1
1597 1 ▶ XPUSHs(sv_2mortal(newSViv(ctxt->input->line)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(ctxt->input->line))); 0 1 1
1598 1 ▶ XPUSHs(sv_2mortal(newSViv(ctxt->input->col)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(ctxt->input->col))); 0 1 1
1599  
1600 1 PUTBACK;
1601 #if LIBXML_VERSION > 20600
1602 /*
1603 this is a workaround: at least some versions of libxml2 didn't not call
1604 the fatalError callback at all
1605 */
1606 1 ▶ if (last_err && last_err->level == XML_ERR_FATAL) {
Branch: 2 branches
BranchTrueFalseTotal
if (last_err && last_err->level == XML_ERR_FATAL) { 1 0 1
if (last_err && last_err->level == XML_ERR_FATAL) { 1 0 1
1607 1 call_pv( "XML::LibXML::_SAXParser::fatal_error", G_SCALAR | G_EVAL | G_DISCARD );
1608 } else {
1609 0 call_pv( "XML::LibXML::_SAXParser::error", G_SCALAR | G_EVAL | G_DISCARD );
1610 }
1611 #else
1612 /* actually, we do not know if it is a fatal error or not */
1613 call_pv( "XML::LibXML::_SAXParser::fatal_error", G_SCALAR | G_EVAL | G_DISCARD );
1614 #endif
1615 1 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 1 0 1
if (SvTRUE(ERRSV)) { 0 1 1
1616 0 croak_obj;
1617 }
1618  
1619 1 ▶ FREETMPS ;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS ; 1 0 1
1620 1 LEAVE ;
1621 CLEAR_SERROR_HANDLER
1622 1 return 1;
1623 }
1624  
1625  
1626 int
1627 0 PmmSaxFatalError(void * ctx, const char * msg, ...)
1628 {
1629 0 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr)ctx;
1630 0 PmmSAXVectorPtr sax = (PmmSAXVectorPtr)ctxt->_private;
1631  
1632 va_list args;
1633 SV * svMessage;
1634  
1635 dTHX;
1636 0 dSP;
1637  
1638 0 svMessage = NEWSV(0,512);
1639  
1640 0 va_start(args, msg);
1641 0 sv_vsetpvfn(svMessage, msg, xmlStrlen((const xmlChar *)msg), &args, NULL, 0, NULL);
1642 0 va_end(args);
1643  
1644 0 ENTER;
1645 0 SAVETMPS;
1646  
1647 0 ▶ PUSHMARK(SP) ;
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP) ; 0 0 0
1648 0 ▶ XPUSHs(sax->parser);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sax->parser); 0 0 0
1649  
1650 0 ▶ if (SvOK(sax->saved_error)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(sax->saved_error)) { 0 0 0
1651 0 sv_catsv( sax->saved_error, svMessage );
1652 } else {
1653 0 sv_setsv( sax->saved_error, svMessage );
1654 }
1655  
1656 0 ▶ XPUSHs(sv_2mortal(svMessage));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(svMessage)); 0 0 0
1657 0 ▶ XPUSHs(sv_2mortal(newSViv(ctxt->input->line)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(ctxt->input->line))); 0 0 0
1658 0 ▶ XPUSHs(sv_2mortal(newSViv(ctxt->input->col)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(ctxt->input->col))); 0 0 0
1659  
1660 0 PUTBACK;
1661 0 call_pv( "XML::LibXML::_SAXParser::fatal_error", G_SCALAR | G_EVAL | G_DISCARD );
1662 0 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 0 0 0
if (SvTRUE(ERRSV)) { 0 0 0
1663 0 croak_obj;
1664 }
1665  
1666 0 ▶ FREETMPS ;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS ; 0 0 0
1667 0 LEAVE ;
1668 CLEAR_SERROR_HANDLER
1669 0 return 1;
1670 }
1671  
1672 /* NOTE:
1673 * end document is not handled by the parser itself! use
1674 * XML::LibXML::SAX instead!
1675 */
1676 xmlSAXHandlerPtr
1677 133 PSaxGetHandler()
1678 {
1679 133 xmlSAXHandlerPtr retval = (xmlSAXHandlerPtr)xmlMalloc(sizeof(xmlSAXHandler));
1680 133 memset(retval, 0, sizeof(xmlSAXHandler));
1681  
1682 133 retval->setDocumentLocator = (setDocumentLocatorSAXFunc)&PSaxSetDocumentLocator;
1683  
1684 133 retval->startDocument = (startDocumentSAXFunc)&PSaxStartDocument;
1685  
1686 /* libxml2 will not handle perls returnvalue correctly, so we have
1687 * to end the document ourselfes
1688 */
1689 133 retval->endDocument = NULL; /* (endDocumentSAXFunc)&PSaxEndDocument; */
1690  
1691 133 retval->startElement = (startElementSAXFunc)&PSaxStartElement;
1692 133 retval->endElement = (endElementSAXFunc)&PSaxEndElement;
1693  
1694 133 retval->characters = (charactersSAXFunc)&PSaxCharacters;
1695 133 retval->ignorableWhitespace = (ignorableWhitespaceSAXFunc)&PSaxCharacters;
1696  
1697 133 retval->comment = (commentSAXFunc)&PSaxComment;
1698 133 retval->cdataBlock = (cdataBlockSAXFunc)&PSaxCDATABlock;
1699  
1700 133 retval->processingInstruction = (processingInstructionSAXFunc)&PSaxProcessingInstruction;
1701  
1702 /* warning functions should be internal */
1703 133 retval->warning = (warningSAXFunc)&PmmSaxWarning;
1704 133 retval->error = (errorSAXFunc)&PmmSaxError;
1705 133 retval->fatalError = (fatalErrorSAXFunc)&PmmSaxFatalError;
1706  
1707 133 retval->externalSubset = (externalSubsetSAXFunc)&PSaxExternalSubset;
1708  
1709 /*
1710 retval->internalSubset = (internalSubsetSAXFunc)&PSaxInternalSubset;
1711 retval->elementDecl = (elementDeclSAXFunc)&PSaxElementDecl;
1712 retval->entityDecl = (entityDeclSAXFunc)&PSaxEntityDecl;
1713 retval->notationDecl = (notationDeclSAXFunc)&PSaxNotationDecl;
1714 retval->attributeDecl = (attributeDeclSAXFunc)&PSaxAttributeDecl;
1715 retval->unparsedEntityDecl = (unparsedEntityDeclSAXFunc)&PSaxUnparsedEntityDecl;
1716 */
1717  
1718 133 return retval;
1719 }
1720  
« xpath.c ↑ Summary dom.c »