- Notifications
You must be signed in to change notification settings - Fork 7.8k
/
Copy pathcompat.c
726 lines (627 loc) · 21.8 KB
/
compat.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Sterling Hughes <sterling@php.net> |
+----------------------------------------------------------------------+
*/
#include"php.h"
#if defined(HAVE_LIBXML) && (defined(HAVE_XML) || defined(HAVE_XMLRPC)) && !defined(HAVE_LIBEXPAT)
#include"expat_compat.h"
#include"ext/libxml/php_libxml.h"
#ifdefLIBXML_EXPAT_COMPAT
staticvoid
qualify_namespace(XML_Parserparser, constxmlChar*name, constxmlChar*URI, xmlChar**qualified)
{
if (URI) {
/* Use libxml functions otherwise its memory deallocation is screwed up */
*qualified=xmlStrdup(URI);
*qualified=xmlStrncat(*qualified, parser->_ns_separator, 1);
*qualified=xmlStrncat(*qualified, name, xmlStrlen(name));
} else {
*qualified=xmlStrdup(name);
}
}
staticvoid
start_element_handler(void*user, constxmlChar*name, constxmlChar**attributes)
{
XML_Parserparser= (XML_Parser) user;
xmlChar*qualified_name=NULL;
if (parser->h_start_element==NULL) {
if (parser->h_default) {
intattno=0;
qualified_name=xmlStrncatNew((xmlChar*)"<", name, xmlStrlen(name));
if (attributes) {
while (attributes[attno] !=NULL) {
intatt_len;
char*att_string, *att_name, *att_value;
att_name= (char*)attributes[attno++];
att_value= (char*)attributes[attno++];
att_len=spprintf(&att_string, 0, " %s=\"%s\"", att_name, att_value);
qualified_name=xmlStrncat(qualified_name, (xmlChar*)att_string, att_len);
efree(att_string);
}
}
qualified_name=xmlStrncat(qualified_name, (xmlChar*)">", 1);
parser->h_default(parser->user, (constXML_Char*) qualified_name, xmlStrlen(qualified_name));
xmlFree(qualified_name);
}
return;
}
parser->h_start_element(parser->user, name, (constXML_Char**) attributes);
}
staticvoid
start_element_handler_ns(void*user, constxmlChar*name, constxmlChar*prefix, constxmlChar*URI, intnb_namespaces, constxmlChar**namespaces, intnb_attributes, intnb_defaulted, constxmlChar**attributes)
{
XML_Parserparser= (XML_Parser) user;
xmlChar*qualified_name=NULL;
xmlChar**attrs=NULL;
inti;
intz=0;
inty=0;
if (nb_namespaces>0&&parser->h_start_ns!=NULL) {
for (i=0; i<nb_namespaces; i+=1) {
parser->h_start_ns(parser->user, (constXML_Char*) namespaces[y], (constXML_Char*) namespaces[y+1]);
y+=2;
}
y=0;
}
if (parser->h_start_element==NULL) {
if (parser->h_default) {
if (prefix) {
qualified_name=xmlStrncatNew((xmlChar*)"<", prefix, xmlStrlen(prefix));
qualified_name=xmlStrncat(qualified_name, (xmlChar*)":", 1);
qualified_name=xmlStrncat(qualified_name, name, xmlStrlen(name));
} else {
qualified_name=xmlStrncatNew((xmlChar*)"<", name, xmlStrlen(name));
}
if (namespaces) {
inti, j;
for (i=0,j=0;j<nb_namespaces;j++) {
intns_len;
char*ns_string, *ns_prefix, *ns_url;
ns_prefix= (char*) namespaces[i++];
ns_url= (char*) namespaces[i++];
if (ns_prefix) {
ns_len=spprintf(&ns_string, 0, " xmlns:%s=\"%s\"", ns_prefix, ns_url);
} else {
ns_len=spprintf(&ns_string, 0, " xmlns=\"%s\"", ns_url);
}
qualified_name=xmlStrncat(qualified_name, (xmlChar*)ns_string, ns_len);
efree(ns_string);
}
}
if (attributes) {
for (i=0; i<nb_attributes; i+=1) {
intatt_len;
char*att_string, *att_name, *att_value, *att_prefix, *att_valueend;
att_name= (char*) attributes[y++];
att_prefix= (char*)attributes[y++];
y++;
att_value= (char*)attributes[y++];
att_valueend= (char*)attributes[y++];
if (att_prefix) {
att_len=spprintf(&att_string, 0, " %s:%s=\"", att_prefix, att_name);
} else {
att_len=spprintf(&att_string, 0, " %s=\"", att_name);
}
qualified_name=xmlStrncat(qualified_name, (xmlChar*)att_string, att_len);
qualified_name=xmlStrncat(qualified_name, (xmlChar*)att_value, att_valueend-att_value);
qualified_name=xmlStrncat(qualified_name, (xmlChar*)"\"", 1);
efree(att_string);
}
}
qualified_name=xmlStrncat(qualified_name, (xmlChar*)">", 1);
parser->h_default(parser->user, (constXML_Char*) qualified_name, xmlStrlen(qualified_name));
xmlFree(qualified_name);
}
return;
}
qualify_namespace(parser, name, URI, &qualified_name);
if (attributes!=NULL) {
xmlChar*qualified_name_attr=NULL;
attrs=safe_emalloc((nb_attributes*2) +1, sizeof(int*), 0);
for (i=0; i<nb_attributes; i+=1) {
if (attributes[y+1] !=NULL) {
qualify_namespace(parser, attributes[y] , attributes[y+2], &qualified_name_attr);
} else {
qualified_name_attr=xmlStrdup(attributes[y]);
}
attrs[z] =qualified_name_attr;
attrs[z+1] =xmlStrndup(attributes[y+3] , (int) (attributes[y+4] -attributes[y+3]));
z+=2;
y+=5;
}
attrs[z] =NULL;
}
parser->h_start_element(parser->user, (constXML_Char*) qualified_name, (constXML_Char**) attrs);
if (attrs) {
for (i=0; i<z; i++) {
xmlFree(attrs[i]);
}
efree(attrs);
}
xmlFree(qualified_name);
}
staticvoid
end_element_handler(void*user, constxmlChar*name)
{
XML_Parserparser= (XML_Parser) user;
if (parser->h_end_element==NULL) {
if (parser->h_default) {
char*end_element;
spprintf(&end_element, 0, "</%s>", (char*)name);
parser->h_default(parser->user, (constXML_Char*) end_element, strlen(end_element));
efree(end_element);
}
return;
}
parser->h_end_element(parser->user, (constXML_Char*) name);
}
staticvoid
end_element_handler_ns(void*user, constxmlChar*name, constxmlChar*prefix, constxmlChar*URI)
{
xmlChar*qualified_name;
XML_Parserparser= (XML_Parser) user;
if (parser->h_end_element==NULL) {
if (parser->h_default) {
char*end_element;
intend_element_len;
if (prefix) {
end_element_len=spprintf(&end_element, 0, "</%s:%s>", (char*) prefix, (char*)name);
} else {
end_element_len=spprintf(&end_element, 0, "</%s>", (char*)name);
}
parser->h_default(parser->user, (constXML_Char*) end_element, end_element_len);
efree(end_element);
}
return;
}
qualify_namespace(parser, name, URI, &qualified_name);
parser->h_end_element(parser->user, (constXML_Char*) qualified_name);
xmlFree(qualified_name);
}
staticvoid
cdata_handler(void*user, constxmlChar*cdata, intcdata_len)
{
XML_Parserparser= (XML_Parser) user;
if (parser->h_cdata==NULL) {
if (parser->h_default) {
parser->h_default(parser->user, (constXML_Char*) cdata, cdata_len);
}
return;
}
parser->h_cdata(parser->user, (constXML_Char*) cdata, cdata_len);
}
staticvoid
pi_handler(void*user, constxmlChar*target, constxmlChar*data)
{
XML_Parserparser= (XML_Parser) user;
if (parser->h_pi==NULL) {
if (parser->h_default) {
char*full_pi;
spprintf(&full_pi, 0, "<?%s %s?>", (char*)target, (char*)data);
parser->h_default(parser->user, (constXML_Char*) full_pi, strlen(full_pi));
efree(full_pi);
}
return;
}
parser->h_pi(parser->user, (constXML_Char*) target, (constXML_Char*) data);
}
staticvoid
unparsed_entity_decl_handler(void*user,
constxmlChar*name,
constxmlChar*pub_id,
constxmlChar*sys_id,
constxmlChar*notation)
{
XML_Parserparser= (XML_Parser) user;
if (parser->h_unparsed_entity_decl==NULL) {
return;
}
parser->h_unparsed_entity_decl(parser->user, name, NULL, sys_id, pub_id, notation);
}
staticvoid
notation_decl_handler(void*user, constxmlChar*notation, constxmlChar*pub_id, constxmlChar*sys_id)
{
XML_Parserparser= (XML_Parser) user;
if (parser->h_notation_decl==NULL) {
return;
}
parser->h_notation_decl(parser->user, notation, NULL, sys_id, pub_id);
}
staticvoid
build_comment(constxmlChar*data, size_tdata_len, xmlChar**comment, size_t*comment_len)
{
*comment_len=data_len+7;
*comment=xmlMalloc(*comment_len+1);
memcpy(*comment, "<!--", 4);
memcpy(*comment+4, data, data_len);
memcpy(*comment+4+data_len, "-->", 3);
(*comment)[*comment_len] ='\0';
}
staticvoid
comment_handler(void*user, constxmlChar*comment)
{
XML_Parserparser= (XML_Parser) user;
if (parser->h_default) {
xmlChar*d_comment;
size_td_comment_len;
build_comment(comment, (size_t) xmlStrlen(comment), &d_comment, &d_comment_len);
parser->h_default(parser->user, d_comment, d_comment_len);
xmlFree(d_comment);
}
}
staticvoid
build_entity(constxmlChar*name, size_tlen, xmlChar**entity, size_t*entity_len)
{
*entity_len=len+2;
*entity=xmlMalloc(*entity_len+1);
(*entity)[0] ='&';
memcpy(*entity+1, name, len);
(*entity)[len+1] =';';
(*entity)[*entity_len] ='\0';
}
staticvoid
external_entity_ref_handler(void*user, constxmlChar*names, constxmlChar*sys_id, constxmlChar*pub_id)
{
XML_Parserparser= (XML_Parser) user;
if (parser->h_external_entity_ref==NULL) {
return;
}
if (!parser->h_external_entity_ref(parser, names, (XML_Char*) "", sys_id, pub_id)) {
xmlStopParser(parser->parser);
parser->parser->errNo=XML_ERROR_EXTERNAL_ENTITY_HANDLING;
};
}
staticxmlEntityPtr
get_entity(void*user, constxmlChar*name)
{
XML_Parserparser= (XML_Parser) user;
xmlEntityPtrret=NULL;
if (parser->parser->inSubset==0) {
ret=xmlGetPredefinedEntity(name);
if (ret==NULL)
ret=xmlGetDocEntity(parser->parser->myDoc, name);
if (ret==NULL||parser->parser->instate==XML_PARSER_CONTENT) {
if (ret==NULL||ret->etype==XML_INTERNAL_GENERAL_ENTITY||ret->etype==XML_INTERNAL_PARAMETER_ENTITY||ret->etype==XML_INTERNAL_PREDEFINED_ENTITY) {
/* Predefined entities will expand unless no cdata handler is present */
if (parser->h_default&& ! (ret&&ret->etype==XML_INTERNAL_PREDEFINED_ENTITY&&parser->h_cdata)) {
xmlChar*entity;
size_tlen;
build_entity(name, (size_t) xmlStrlen(name), &entity, &len);
parser->h_default(parser->user, (constxmlChar*) entity, len);
xmlFree(entity);
} else {
/* expat will not expand internal entities if default handler is present otherwise
it will expand and pass them to cdata handler */
if (parser->h_cdata&&ret) {
parser->h_cdata(parser->user, ret->content, xmlStrlen(ret->content));
}
}
} else {
if (ret->etype==XML_EXTERNAL_GENERAL_PARSED_ENTITY) {
external_entity_ref_handler(user, ret->name, ret->SystemID, ret->ExternalID);
}
}
}
}
returnret;
}
staticconstxmlSAXHandler
php_xml_compat_handlers= {
NULL, /* internalSubset */
NULL, /* isStandalone */
NULL, /* hasInternalSubset */
NULL, /* hasExternalSubset */
NULL, /* resolveEntity */
get_entity, /* getEntity */
NULL, /* entityDecl */
notation_decl_handler,
NULL, /* attributeDecl */
NULL, /* elementDecl */
unparsed_entity_decl_handler, /* unparsedEntity */
NULL, /* setDocumentLocator */
NULL, /* startDocument */
NULL, /* endDocument */
start_element_handler, /* startElement */
end_element_handler, /* endElement */
NULL, /* reference */
cdata_handler,
NULL, /* ignorableWhitespace */
pi_handler,
comment_handler, /* comment */
NULL, /* warning */
NULL, /* error */
NULL, /* fatalError */
NULL, /* getParameterEntity */
cdata_handler, /* cdataBlock */
NULL, /* externalSubset */
XML_SAX2_MAGIC,
NULL,
start_element_handler_ns,
end_element_handler_ns,
NULL
};
PHP_XML_APIXML_Parser
XML_ParserCreate(constXML_Char*encoding)
{
returnXML_ParserCreate_MM(encoding, NULL, NULL);
}
PHP_XML_APIXML_Parser
XML_ParserCreateNS(constXML_Char*encoding, constXML_Charsep)
{
XML_Chartmp[2];
tmp[0] =sep;
tmp[1] ='\0';
returnXML_ParserCreate_MM(encoding, NULL, tmp);
}
PHP_XML_APIXML_Parser
XML_ParserCreate_MM(constXML_Char*encoding, constXML_Memory_Handling_Suite*memsuite, constXML_Char*sep)
{
XML_Parserparser;
parser=emalloc(sizeof(structXML_Parser_Struct));
memset(parser, 0, sizeof(structXML_Parser_Struct));
parser->use_namespace=0;
parser->_ns_separator=NULL;
parser->parser=xmlCreatePushParserCtxt((xmlSAXHandlerPtr) &php_xml_compat_handlers, (void*) parser, NULL, 0, NULL);
if (parser->parser==NULL) {
efree(parser);
returnNULL;
}
php_libxml_sanitize_parse_ctxt_options(parser->parser);
xmlCtxtUseOptions(parser->parser, XML_PARSE_OLDSAX | XML_PARSE_NOENT);
parser->parser->wellFormed=0;
if (sep!=NULL) {
/* Note: sax2 flag will be set due to the magic number in `initialized` in php_xml_compat_handlers */
ZEND_ASSERT(parser->parser->sax->initialized==XML_SAX2_MAGIC);
parser->use_namespace=1;
parser->_ns_separator=xmlStrdup(sep);
} else {
/* Reset flag as XML_SAX2_MAGIC is needed for xmlCreatePushParserCtxt
so must be set in the handlers */
parser->parser->sax->initialized=1;
}
returnparser;
}
PHP_XML_APIvoid
XML_SetUserData(XML_Parserparser, void*user)
{
parser->user=user;
}
PHP_XML_APIvoid*
XML_GetUserData(XML_Parserparser)
{
returnparser->user;
}
PHP_XML_APIvoid
XML_SetElementHandler(XML_Parserparser, XML_StartElementHandlerstart, XML_EndElementHandlerend)
{
parser->h_start_element=start;
parser->h_end_element=end;
}
PHP_XML_APIvoid
XML_SetCharacterDataHandler(XML_Parserparser, XML_CharacterDataHandlercdata)
{
parser->h_cdata=cdata;
}
PHP_XML_APIvoid
XML_SetProcessingInstructionHandler(XML_Parserparser, XML_ProcessingInstructionHandlerpi)
{
parser->h_pi=pi;
}
PHP_XML_APIvoid
XML_SetCommentHandler(XML_Parserparser, XML_CommentHandlercomment)
{
parser->h_comment=comment;
}
PHP_XML_APIvoid
XML_SetDefaultHandler(XML_Parserparser, XML_DefaultHandlerd)
{
parser->h_default=d;
}
PHP_XML_APIvoid
XML_SetUnparsedEntityDeclHandler(XML_Parserparser, XML_UnparsedEntityDeclHandlerunparsed_decl)
{
parser->h_unparsed_entity_decl=unparsed_decl;
}
PHP_XML_APIvoid
XML_SetNotationDeclHandler(XML_Parserparser, XML_NotationDeclHandlernotation_decl)
{
parser->h_notation_decl=notation_decl;
}
PHP_XML_APIvoid
XML_SetExternalEntityRefHandler(XML_Parserparser, XML_ExternalEntityRefHandlerext_entity)
{
parser->h_external_entity_ref=ext_entity;
}
PHP_XML_APIvoid
XML_SetStartNamespaceDeclHandler(XML_Parserparser, XML_StartNamespaceDeclHandlerstart_ns)
{
parser->h_start_ns=start_ns;
}
PHP_XML_APIvoid
XML_SetEndNamespaceDeclHandler(XML_Parserparser, XML_EndNamespaceDeclHandlerend_ns)
{
parser->h_end_ns=end_ns;
}
PHP_XML_APIint
XML_Parse(XML_Parserparser, constXML_Char*data, intdata_len, intis_final)
{
interror=xmlParseChunk(parser->parser, (char*) data, data_len, is_final);
if (!error) {
constxmlError*error_data=xmlCtxtGetLastError(parser->parser);
return !error_data||error_data->level <= XML_ERR_WARNING;
}
return0;
}
PHP_XML_APIint
XML_GetErrorCode(XML_Parserparser)
{
returnparser->parser->errNo;
}
staticconstXML_Char*consterror_mapping[] = {
(constXML_Char*)"No error",
(constXML_Char*)"No memory",
(constXML_Char*)"Invalid document start",
(constXML_Char*)"Empty document",
(constXML_Char*)"Not well-formed (invalid token)",
(constXML_Char*)"Invalid document end",
(constXML_Char*)"Invalid hexadecimal character reference",
(constXML_Char*)"Invalid decimal character reference",
(constXML_Char*)"Invalid character reference",
(constXML_Char*)"Invalid character",
(constXML_Char*)"XML_ERR_CHARREF_AT_EOF",
(constXML_Char*)"XML_ERR_CHARREF_IN_PROLOG",
(constXML_Char*)"XML_ERR_CHARREF_IN_EPILOG",
(constXML_Char*)"XML_ERR_CHARREF_IN_DTD",
(constXML_Char*)"XML_ERR_ENTITYREF_AT_EOF",
(constXML_Char*)"XML_ERR_ENTITYREF_IN_PROLOG",
(constXML_Char*)"XML_ERR_ENTITYREF_IN_EPILOG",
(constXML_Char*)"XML_ERR_ENTITYREF_IN_DTD",
(constXML_Char*)"PEReference at end of document",
(constXML_Char*)"PEReference in prolog",
(constXML_Char*)"PEReference in epilog",
(constXML_Char*)"PEReference: forbidden within markup decl in internal subset",
(constXML_Char*)"XML_ERR_ENTITYREF_NO_NAME",
(constXML_Char*)"EntityRef: expecting ';'",
(constXML_Char*)"PEReference: no name",
(constXML_Char*)"PEReference: expecting ';'",
(constXML_Char*)"Undeclared entity error",
(constXML_Char*)"Undeclared entity warning",
(constXML_Char*)"Unparsed Entity",
(constXML_Char*)"XML_ERR_ENTITY_IS_EXTERNAL",
(constXML_Char*)"XML_ERR_ENTITY_IS_PARAMETER",
(constXML_Char*)"Unknown encoding",
(constXML_Char*)"Unsupported encoding",
(constXML_Char*)"String not started expecting ' or \"",
(constXML_Char*)"String not closed expecting \" or '",
(constXML_Char*)"Namespace declaration error",
(constXML_Char*)"EntityValue: \" or ' expected",
(constXML_Char*)"EntityValue: \" or ' expected",
(constXML_Char*)"< in attribute",
(constXML_Char*)"Attribute not started",
(constXML_Char*)"Attribute not finished",
(constXML_Char*)"Attribute without value",
(constXML_Char*)"Attribute redefined",
(constXML_Char*)"SystemLiteral \" or ' expected",
(constXML_Char*)"SystemLiteral \" or ' expected",
/* (const XML_Char *)"XML_ERR_COMMENT_NOT_STARTED", <= eliminated on purpose */
(constXML_Char*)"Comment not finished",
(constXML_Char*)"Processing Instruction not started",
(constXML_Char*)"Processing Instruction not finished",
(constXML_Char*)"NOTATION: Name expected here",
(constXML_Char*)"'>' required to close NOTATION declaration",
(constXML_Char*)"'(' required to start ATTLIST enumeration",
(constXML_Char*)"'(' required to start ATTLIST enumeration",
(constXML_Char*)"MixedContentDecl : '|' or ')*' expected",
(constXML_Char*)"XML_ERR_MIXED_NOT_FINISHED",
(constXML_Char*)"ELEMENT in DTD not started",
(constXML_Char*)"ELEMENT in DTD not finished",
(constXML_Char*)"XML declaration not started",
(constXML_Char*)"XML declaration not finished",
(constXML_Char*)"XML_ERR_CONDSEC_NOT_STARTED",
(constXML_Char*)"XML conditional section not closed",
(constXML_Char*)"Content error in the external subset",
(constXML_Char*)"DOCTYPE not finished",
(constXML_Char*)"Sequence ']]>' not allowed in content",
(constXML_Char*)"CDATA not finished",
(constXML_Char*)"Reserved XML Name",
(constXML_Char*)"Space required",
(constXML_Char*)"XML_ERR_SEPARATOR_REQUIRED",
(constXML_Char*)"NmToken expected in ATTLIST enumeration",
(constXML_Char*)"XML_ERR_NAME_REQUIRED",
(constXML_Char*)"MixedContentDecl : '#PCDATA' expected",
(constXML_Char*)"SYSTEM or PUBLIC, the URI is missing",
(constXML_Char*)"PUBLIC, the Public Identifier is missing",
(constXML_Char*)"< required",
(constXML_Char*)"> required",
(constXML_Char*)"</ required",
(constXML_Char*)"= required",
(constXML_Char*)"Mismatched tag",
(constXML_Char*)"Tag not finished",
(constXML_Char*)"standalone accepts only 'yes' or 'no'",
(constXML_Char*)"Invalid XML encoding name",
(constXML_Char*)"Comment must not contain '--' (double-hyphen)",
(constXML_Char*)"Invalid encoding",
(constXML_Char*)"external parsed entities cannot be standalone",
(constXML_Char*)"XML conditional section '[' expected",
(constXML_Char*)"Entity value required",
(constXML_Char*)"chunk is not well balanced",
(constXML_Char*)"extra content at the end of well balanced chunk",
(constXML_Char*)"XML_ERR_ENTITY_CHAR_ERROR",
(constXML_Char*)"PEReferences forbidden in internal subset",
(constXML_Char*)"Detected an entity reference loop",
(constXML_Char*)"XML_ERR_ENTITY_BOUNDARY",
(constXML_Char*)"Invalid URI",
(constXML_Char*)"Fragment not allowed",
(constXML_Char*)"XML_WAR_CATALOG_PI",
(constXML_Char*)"XML_ERR_NO_DTD",
(constXML_Char*)"conditional section INCLUDE or IGNORE keyword expected", /* 95 */
(constXML_Char*)"Version in XML Declaration missing", /* 96 */
(constXML_Char*)"XML_WAR_UNKNOWN_VERSION", /* 97 */
(constXML_Char*)"XML_WAR_LANG_VALUE", /* 98 */
(constXML_Char*)"XML_WAR_NS_URI", /* 99 */
(constXML_Char*)"XML_WAR_NS_URI_RELATIVE", /* 100 */
(constXML_Char*)"Missing encoding in text declaration"/* 101 */
};
PHP_XML_APIconstXML_Char*
XML_ErrorString(intcode)
{
if (code<0||code >= (int)(sizeof(error_mapping) / sizeof(error_mapping[0]))) {
return (constXML_Char*) "Unknown";
}
returnerror_mapping[code];
}
PHP_XML_APIint
XML_GetCurrentLineNumber(XML_Parserparser)
{
returnparser->parser->input->line;
}
PHP_XML_APIint
XML_GetCurrentColumnNumber(XML_Parserparser)
{
returnparser->parser->input->col;
}
PHP_XML_API long
XML_GetCurrentByteIndex(XML_Parserparser)
{
returnparser->parser->input->consumed+
(parser->parser->input->cur-parser->parser->input->base);
}
PHP_XML_APIint
XML_GetCurrentByteCount(XML_Parserparser)
{
/* TODO: this is identical to ByteIndex; it should probably
* be different */
return (int) XML_GetCurrentByteIndex(parser);
}
PHP_XML_APIconstXML_Char*XML_ExpatVersion(void)
{
return (constXML_Char*) "1.0";
}
PHP_XML_APIvoid
XML_ParserFree(XML_Parserparser)
{
if (parser->use_namespace) {
if (parser->_ns_separator) {
xmlFree(parser->_ns_separator);
}
}
if (parser->parser->myDoc) {
xmlFreeDoc(parser->parser->myDoc);
parser->parser->myDoc=NULL;
}
xmlFreeParserCtxt(parser->parser);
efree(parser);
}
#endif/* LIBXML_EXPAT_COMPAT */
#endif