|
Lines 5-10
Link Here
|
| 5 |
#include <stddef.h> |
5 |
#include <stddef.h> |
| 6 |
#include <string.h> /* memset(), memcpy() */ |
6 |
#include <string.h> /* memset(), memcpy() */ |
| 7 |
#include <assert.h> |
7 |
#include <assert.h> |
|
|
8 |
#include <limits.h> /* UINT_MAX */ |
| 9 |
#include <time.h> /* time() */ |
| 8 |
|
10 |
|
| 9 |
#define XML_BUILDING_EXPAT 1 |
11 |
#define XML_BUILDING_EXPAT 1 |
| 10 |
|
12 |
|
|
Lines 391-402
static void dtdReset(DTD *p, const XML_M
Link Here
|
| 391 |
static void |
393 |
static void |
| 392 |
dtdDestroy(DTD *p, XML_Bool isDocEntity, const XML_Memory_Handling_Suite *ms); |
394 |
dtdDestroy(DTD *p, XML_Bool isDocEntity, const XML_Memory_Handling_Suite *ms); |
| 393 |
static int |
395 |
static int |
| 394 |
dtdCopy(DTD *newDtd, const DTD *oldDtd, const XML_Memory_Handling_Suite *ms); |
396 |
dtdCopy(XML_Parser oldParser, |
|
|
397 |
DTD *newDtd, const DTD *oldDtd, const XML_Memory_Handling_Suite *ms); |
| 395 |
static int |
398 |
static int |
| 396 |
copyEntityTable(HASH_TABLE *, STRING_POOL *, const HASH_TABLE *); |
399 |
copyEntityTable(XML_Parser oldParser, |
| 397 |
|
400 |
HASH_TABLE *, STRING_POOL *, const HASH_TABLE *); |
| 398 |
static NAMED * |
401 |
static NAMED * |
| 399 |
lookup(HASH_TABLE *table, KEY name, size_t createSize); |
402 |
lookup(XML_Parser parser, HASH_TABLE *table, KEY name, size_t createSize); |
| 400 |
static void FASTCALL |
403 |
static void FASTCALL |
| 401 |
hashTableInit(HASH_TABLE *, const XML_Memory_Handling_Suite *ms); |
404 |
hashTableInit(HASH_TABLE *, const XML_Memory_Handling_Suite *ms); |
| 402 |
static void FASTCALL hashTableClear(HASH_TABLE *); |
405 |
static void FASTCALL hashTableClear(HASH_TABLE *); |
|
Lines 546-551
struct XML_ParserStruct {
Link Here
|
| 546 |
XML_Bool m_useForeignDTD; |
553 |
XML_Bool m_useForeignDTD; |
| 547 |
enum XML_ParamEntityParsing m_paramEntityParsing; |
554 |
enum XML_ParamEntityParsing m_paramEntityParsing; |
| 548 |
#endif |
555 |
#endif |
|
|
556 |
unsigned long m_hash_secret_salt; |
| 549 |
}; |
557 |
}; |
| 550 |
|
558 |
|
| 551 |
#define MALLOC(s) (parser->m_mem.malloc_fcn((s))) |
559 |
#define MALLOC(s) (parser->m_mem.malloc_fcn((s))) |
|
Lines 653-658
struct XML_ParserStruct {
Link Here
|
| 653 |
#define useForeignDTD (parser->m_useForeignDTD) |
662 |
#define useForeignDTD (parser->m_useForeignDTD) |
| 654 |
#define paramEntityParsing (parser->m_paramEntityParsing) |
663 |
#define paramEntityParsing (parser->m_paramEntityParsing) |
| 655 |
#endif /* XML_DTD */ |
664 |
#endif /* XML_DTD */ |
|
|
665 |
#define hash_secret_salt (parser->m_hash_secret_salt) |
| 656 |
|
666 |
|
| 657 |
XML_Parser XMLCALL |
667 |
XML_Parser XMLCALL |
| 658 |
XML_ParserCreate(const XML_Char *encodingName) |
668 |
XML_ParserCreate(const XML_Char *encodingName) |
|
Lines 677-682
static const XML_Char implicitContext[]
Link Here
|
| 677 |
ASCII_s, ASCII_p, ASCII_a, ASCII_c, ASCII_e, '\0' |
687 |
ASCII_s, ASCII_p, ASCII_a, ASCII_c, ASCII_e, '\0' |
| 678 |
}; |
688 |
}; |
| 679 |
|
689 |
|
|
|
690 |
static unsigned long |
| 691 |
generate_hash_secret_salt(void) |
| 692 |
{ |
| 693 |
unsigned int seed = time(NULL) % UINT_MAX; |
| 694 |
srand(seed); |
| 695 |
return rand(); |
| 696 |
} |
| 697 |
|
| 680 |
XML_Parser XMLCALL |
698 |
XML_Parser XMLCALL |
| 681 |
XML_ParserCreate_MM(const XML_Char *encodingName, |
699 |
XML_ParserCreate_MM(const XML_Char *encodingName, |
| 682 |
const XML_Memory_Handling_Suite *memsuite, |
700 |
const XML_Memory_Handling_Suite *memsuite, |
|
Lines 866-871
parserInit(XML_Parser parser, const XML_
Link Here
|
| 866 |
useForeignDTD = XML_FALSE; |
898 |
useForeignDTD = XML_FALSE; |
| 867 |
paramEntityParsing = XML_PARAM_ENTITY_PARSING_NEVER; |
899 |
paramEntityParsing = XML_PARAM_ENTITY_PARSING_NEVER; |
| 868 |
#endif |
900 |
#endif |
|
|
901 |
hash_secret_salt = 0; |
| 869 |
} |
902 |
} |
| 870 |
|
903 |
|
| 871 |
/* moves list of bindings to freeBindingList */ |
904 |
/* moves list of bindings to freeBindingList */ |
|
Lines 982-987
XML_ExternalEntityParserCreate(XML_Parse
Link Here
|
| 982 |
int oldInEntityValue = prologState.inEntityValue; |
1015 |
int oldInEntityValue = prologState.inEntityValue; |
| 983 |
#endif |
1016 |
#endif |
| 984 |
XML_Bool oldns_triplets = ns_triplets; |
1017 |
XML_Bool oldns_triplets = ns_triplets; |
|
|
1018 |
/* Note that the new parser shares the same hash secret as the old |
| 1019 |
parser, so that dtdCopy and copyEntityTable can lookup values |
| 1020 |
from hash tables associated with either parser without us having |
| 1021 |
to worry which hash secrets each table has. |
| 1022 |
*/ |
| 1023 |
unsigned long oldhash_secret_salt = hash_secret_salt; |
| 985 |
|
1024 |
|
| 986 |
#ifdef XML_DTD |
1025 |
#ifdef XML_DTD |
| 987 |
if (!context) |
1026 |
if (!context) |
|
Lines 1035-1047
XML_ExternalEntityParserCreate(XML_Parse
Link Here
|
| 1035 |
externalEntityRefHandlerArg = oldExternalEntityRefHandlerArg; |
1074 |
externalEntityRefHandlerArg = oldExternalEntityRefHandlerArg; |
| 1036 |
defaultExpandInternalEntities = oldDefaultExpandInternalEntities; |
1075 |
defaultExpandInternalEntities = oldDefaultExpandInternalEntities; |
| 1037 |
ns_triplets = oldns_triplets; |
1076 |
ns_triplets = oldns_triplets; |
|
|
1077 |
hash_secret_salt = oldhash_secret_salt; |
| 1038 |
parentParser = oldParser; |
1078 |
parentParser = oldParser; |
| 1039 |
#ifdef XML_DTD |
1079 |
#ifdef XML_DTD |
| 1040 |
paramEntityParsing = oldParamEntityParsing; |
1080 |
paramEntityParsing = oldParamEntityParsing; |
| 1041 |
prologState.inEntityValue = oldInEntityValue; |
1081 |
prologState.inEntityValue = oldInEntityValue; |
| 1042 |
if (context) { |
1082 |
if (context) { |
| 1043 |
#endif /* XML_DTD */ |
1083 |
#endif /* XML_DTD */ |
| 1044 |
if (!dtdCopy(_dtd, oldDtd, &parser->m_mem) |
1084 |
if (!dtdCopy(oldParser, _dtd, oldDtd, &parser->m_mem) |
| 1045 |
|| !setContext(parser, context)) { |
1085 |
|| !setContext(parser, context)) { |
| 1046 |
XML_ParserFree(parser); |
1086 |
XML_ParserFree(parser); |
| 1047 |
return NULL; |
1087 |
return NULL; |
|
Lines 1426-1431
XML_SetParamEntityParsing(XML_Parser par
Link Here
|
| 1426 |
#endif |
1477 |
#endif |
| 1427 |
} |
1478 |
} |
| 1428 |
|
1479 |
|
|
|
1480 |
int XMLCALL |
| 1481 |
XML_SetHashSalt(XML_Parser parser, |
| 1482 |
unsigned long hash_salt) |
| 1483 |
{ |
| 1484 |
/* block after XML_Parse()/XML_ParseBuffer() has been called */ |
| 1485 |
if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED) |
| 1486 |
return 0; |
| 1487 |
hash_secret_salt = hash_salt; |
| 1488 |
return 1; |
| 1489 |
} |
| 1490 |
|
| 1429 |
enum XML_Status XMLCALL |
1491 |
enum XML_Status XMLCALL |
| 1430 |
XML_Parse(XML_Parser parser, const char *s, int len, int isFinal) |
1492 |
XML_Parse(XML_Parser parser, const char *s, int len, int isFinal) |
| 1431 |
{ |
1493 |
{ |
|
Lines 1436-1441
XML_Parse(XML_Parser parser, const char
Link Here
|
| 1436 |
case XML_FINISHED: |
1498 |
case XML_FINISHED: |
| 1437 |
errorCode = XML_ERROR_FINISHED; |
1499 |
errorCode = XML_ERROR_FINISHED; |
| 1438 |
return XML_STATUS_ERROR; |
1500 |
return XML_STATUS_ERROR; |
|
|
1501 |
case XML_INITIALIZED: |
| 1502 |
if (hash_secret_salt == 0) |
| 1503 |
hash_secret_salt = generate_hash_secret_salt(); |
| 1439 |
default: |
1504 |
default: |
| 1440 |
ps_parsing = XML_PARSING; |
1505 |
ps_parsing = XML_PARSING; |
| 1441 |
} |
1506 |
} |
|
Lines 1494-1504
XML_Parse(XML_Parser parser, const char
Link Here
|
| 1494 |
break; |
1559 |
break; |
| 1495 |
case XML_INITIALIZED: |
1560 |
case XML_INITIALIZED: |
| 1496 |
case XML_PARSING: |
1561 |
case XML_PARSING: |
| 1497 |
result = XML_STATUS_OK; |
|
|
| 1498 |
if (isFinal) { |
1562 |
if (isFinal) { |
| 1499 |
ps_parsing = XML_FINISHED; |
1563 |
ps_parsing = XML_FINISHED; |
| 1500 |
return result; |
1564 |
return XML_STATUS_OK; |
| 1501 |
} |
1565 |
} |
|
|
1566 |
/* fall through */ |
| 1567 |
default: |
| 1568 |
result = XML_STATUS_OK; |
| 1502 |
} |
1569 |
} |
| 1503 |
} |
1570 |
} |
| 1504 |
|
1571 |
|
|
Lines 1559-1564
XML_ParseBuffer(XML_Parser parser, int l
Link Here
|
| 1559 |
case XML_FINISHED: |
1626 |
case XML_FINISHED: |
| 1560 |
errorCode = XML_ERROR_FINISHED; |
1627 |
errorCode = XML_ERROR_FINISHED; |
| 1561 |
return XML_STATUS_ERROR; |
1628 |
return XML_STATUS_ERROR; |
|
|
1629 |
case XML_INITIALIZED: |
| 1630 |
if (hash_secret_salt == 0) |
| 1631 |
hash_secret_salt = generate_hash_secret_salt(); |
| 1562 |
default: |
1632 |
default: |
| 1563 |
ps_parsing = XML_PARSING; |
1633 |
ps_parsing = XML_PARSING; |
| 1564 |
} |
1634 |
} |
|
Lines 2240-2246
doContent(XML_Parser parser,
Link Here
|
| 2240 |
next - enc->minBytesPerChar); |
2313 |
next - enc->minBytesPerChar); |
| 2241 |
if (!name) |
2314 |
if (!name) |
| 2242 |
return XML_ERROR_NO_MEMORY; |
2315 |
return XML_ERROR_NO_MEMORY; |
| 2243 |
entity = (ENTITY *)lookup(&dtd->generalEntities, name, 0); |
2316 |
entity = (ENTITY *)lookup(parser, &dtd->generalEntities, name, 0); |
| 2244 |
poolDiscard(&dtd->pool); |
2317 |
poolDiscard(&dtd->pool); |
| 2245 |
/* First, determine if a check for an existing declaration is needed; |
2318 |
/* First, determine if a check for an existing declaration is needed; |
| 2246 |
if yes, check that the entity exists, and that it is internal, |
2319 |
if yes, check that the entity exists, and that it is internal, |
|
Lines 2630-2641
storeAtts(XML_Parser parser, const ENCOD
Link Here
|
| 2630 |
const XML_Char *localPart; |
2703 |
const XML_Char *localPart; |
| 2631 |
|
2704 |
|
| 2632 |
/* lookup the element type name */ |
2705 |
/* lookup the element type name */ |
| 2633 |
elementType = (ELEMENT_TYPE *)lookup(&dtd->elementTypes, tagNamePtr->str,0); |
2706 |
elementType = (ELEMENT_TYPE *)lookup(parser, &dtd->elementTypes, tagNamePtr->str,0); |
| 2634 |
if (!elementType) { |
2707 |
if (!elementType) { |
| 2635 |
const XML_Char *name = poolCopyString(&dtd->pool, tagNamePtr->str); |
2708 |
const XML_Char *name = poolCopyString(&dtd->pool, tagNamePtr->str); |
| 2636 |
if (!name) |
2709 |
if (!name) |
| 2637 |
return XML_ERROR_NO_MEMORY; |
2710 |
return XML_ERROR_NO_MEMORY; |
| 2638 |
elementType = (ELEMENT_TYPE *)lookup(&dtd->elementTypes, name, |
2711 |
elementType = (ELEMENT_TYPE *)lookup(parser, &dtd->elementTypes, name, |
| 2639 |
sizeof(ELEMENT_TYPE)); |
2712 |
sizeof(ELEMENT_TYPE)); |
| 2640 |
if (!elementType) |
2713 |
if (!elementType) |
| 2641 |
return XML_ERROR_NO_MEMORY; |
2714 |
return XML_ERROR_NO_MEMORY; |
|
Lines 2804-2812
storeAtts(XML_Parser parser, const ENCOD
Link Here
|
| 2804 |
if (s[-1] == 2) { /* prefixed */ |
2898 |
if (s[-1] == 2) { /* prefixed */ |
| 2805 |
ATTRIBUTE_ID *id; |
2899 |
ATTRIBUTE_ID *id; |
| 2806 |
const BINDING *b; |
2900 |
const BINDING *b; |
| 2807 |
unsigned long uriHash = 0; |
2901 |
unsigned long uriHash = hash_secret_salt; |
| 2808 |
((XML_Char *)s)[-1] = 0; /* clear flag */ |
2902 |
((XML_Char *)s)[-1] = 0; /* clear flag */ |
| 2809 |
id = (ATTRIBUTE_ID *)lookup(&dtd->attributeIds, s, 0); |
2903 |
id = (ATTRIBUTE_ID *)lookup(parser, &dtd->attributeIds, s, 0); |
| 2810 |
b = id->prefix->binding; |
2904 |
b = id->prefix->binding; |
| 2811 |
if (!b) |
2905 |
if (!b) |
| 2812 |
return XML_ERROR_UNBOUND_PREFIX; |
2906 |
return XML_ERROR_UNBOUND_PREFIX; |
|
Lines 2828-2834
storeAtts(XML_Parser parser, const ENCOD
Link Here
|
| 2828 |
} while (*s++); |
2922 |
} while (*s++); |
| 2829 |
|
2923 |
|
| 2830 |
{ /* Check hash table for duplicate of expanded name (uriName). |
2924 |
{ /* Check hash table for duplicate of expanded name (uriName). |
| 2831 |
Derived from code in lookup(HASH_TABLE *table, ...). |
2925 |
Derived from code in lookup(parser, HASH_TABLE *table, ...). |
| 2832 |
*/ |
2926 |
*/ |
| 2833 |
unsigned char step = 0; |
2927 |
unsigned char step = 0; |
| 2834 |
unsigned long mask = nsAttsSize - 1; |
2928 |
unsigned long mask = nsAttsSize - 1; |
|
Lines 3777-3783
doProlog(XML_Parser parser,
Link Here
|
| 3777 |
case XML_ROLE_DOCTYPE_PUBLIC_ID: |
3871 |
case XML_ROLE_DOCTYPE_PUBLIC_ID: |
| 3778 |
#ifdef XML_DTD |
3872 |
#ifdef XML_DTD |
| 3779 |
useForeignDTD = XML_FALSE; |
3873 |
useForeignDTD = XML_FALSE; |
| 3780 |
declEntity = (ENTITY *)lookup(&dtd->paramEntities, |
3874 |
declEntity = (ENTITY *)lookup(parser, |
|
|
3875 |
&dtd->paramEntities, |
| 3781 |
externalSubsetName, |
3876 |
externalSubsetName, |
| 3782 |
sizeof(ENTITY)); |
3877 |
sizeof(ENTITY)); |
| 3783 |
if (!declEntity) |
3878 |
if (!declEntity) |
|
Lines 3832-3838
doProlog(XML_Parser parser,
Link Here
|
| 3832 |
XML_Bool hadParamEntityRefs = dtd->hasParamEntityRefs; |
3927 |
XML_Bool hadParamEntityRefs = dtd->hasParamEntityRefs; |
| 3833 |
dtd->hasParamEntityRefs = XML_TRUE; |
3928 |
dtd->hasParamEntityRefs = XML_TRUE; |
| 3834 |
if (paramEntityParsing && externalEntityRefHandler) { |
3929 |
if (paramEntityParsing && externalEntityRefHandler) { |
| 3835 |
ENTITY *entity = (ENTITY *)lookup(&dtd->paramEntities, |
3930 |
ENTITY *entity = (ENTITY *)lookup(parser, |
|
|
3931 |
&dtd->paramEntities, |
| 3836 |
externalSubsetName, |
3932 |
externalSubsetName, |
| 3837 |
sizeof(ENTITY)); |
3933 |
sizeof(ENTITY)); |
| 3838 |
if (!entity) |
3934 |
if (!entity) |
|
Lines 3876-3882
doProlog(XML_Parser parser,
Link Here
|
| 3876 |
XML_Bool hadParamEntityRefs = dtd->hasParamEntityRefs; |
3972 |
XML_Bool hadParamEntityRefs = dtd->hasParamEntityRefs; |
| 3877 |
dtd->hasParamEntityRefs = XML_TRUE; |
3973 |
dtd->hasParamEntityRefs = XML_TRUE; |
| 3878 |
if (paramEntityParsing && externalEntityRefHandler) { |
3974 |
if (paramEntityParsing && externalEntityRefHandler) { |
| 3879 |
ENTITY *entity = (ENTITY *)lookup(&dtd->paramEntities, |
3975 |
ENTITY *entity = (ENTITY *)lookup(parser, &dtd->paramEntities, |
| 3880 |
externalSubsetName, |
3976 |
externalSubsetName, |
| 3881 |
sizeof(ENTITY)); |
3977 |
sizeof(ENTITY)); |
| 3882 |
if (!entity) |
3978 |
if (!entity) |
|
Lines 4090-4096
doProlog(XML_Parser parser,
Link Here
|
| 4090 |
break; |
4186 |
break; |
| 4091 |
#else /* XML_DTD */ |
4187 |
#else /* XML_DTD */ |
| 4092 |
if (!declEntity) { |
4188 |
if (!declEntity) { |
| 4093 |
declEntity = (ENTITY *)lookup(&dtd->paramEntities, |
4189 |
declEntity = (ENTITY *)lookup(parser, |
|
|
4190 |
&dtd->paramEntities, |
| 4094 |
externalSubsetName, |
4191 |
externalSubsetName, |
| 4095 |
sizeof(ENTITY)); |
4192 |
sizeof(ENTITY)); |
| 4096 |
if (!declEntity) |
4193 |
if (!declEntity) |
|
Lines 4165-4171
doProlog(XML_Parser parser,
Link Here
|
| 4165 |
const XML_Char *name = poolStoreString(&dtd->pool, enc, s, next); |
4262 |
const XML_Char *name = poolStoreString(&dtd->pool, enc, s, next); |
| 4166 |
if (!name) |
4263 |
if (!name) |
| 4167 |
return XML_ERROR_NO_MEMORY; |
4264 |
return XML_ERROR_NO_MEMORY; |
| 4168 |
declEntity = (ENTITY *)lookup(&dtd->generalEntities, name, |
4265 |
declEntity = (ENTITY *)lookup(parser, &dtd->generalEntities, name, |
| 4169 |
sizeof(ENTITY)); |
4266 |
sizeof(ENTITY)); |
| 4170 |
if (!declEntity) |
4267 |
if (!declEntity) |
| 4171 |
return XML_ERROR_NO_MEMORY; |
4268 |
return XML_ERROR_NO_MEMORY; |
|
Lines 4197-4203
doProlog(XML_Parser parser,
Link Here
|
| 4197 |
const XML_Char *name = poolStoreString(&dtd->pool, enc, s, next); |
4294 |
const XML_Char *name = poolStoreString(&dtd->pool, enc, s, next); |
| 4198 |
if (!name) |
4295 |
if (!name) |
| 4199 |
return XML_ERROR_NO_MEMORY; |
4296 |
return XML_ERROR_NO_MEMORY; |
| 4200 |
declEntity = (ENTITY *)lookup(&dtd->paramEntities, |
4297 |
declEntity = (ENTITY *)lookup(parser, &dtd->paramEntities, |
| 4201 |
name, sizeof(ENTITY)); |
4298 |
name, sizeof(ENTITY)); |
| 4202 |
if (!declEntity) |
4299 |
if (!declEntity) |
| 4203 |
return XML_ERROR_NO_MEMORY; |
4300 |
return XML_ERROR_NO_MEMORY; |
|
Lines 4379-4385
doProlog(XML_Parser parser,
Link Here
|
| 4379 |
next - enc->minBytesPerChar); |
4476 |
next - enc->minBytesPerChar); |
| 4380 |
if (!name) |
4477 |
if (!name) |
| 4381 |
return XML_ERROR_NO_MEMORY; |
4478 |
return XML_ERROR_NO_MEMORY; |
| 4382 |
entity = (ENTITY *)lookup(&dtd->paramEntities, name, 0); |
4479 |
entity = (ENTITY *)lookup(parser, &dtd->paramEntities, name, 0); |
| 4383 |
poolDiscard(&dtd->pool); |
4480 |
poolDiscard(&dtd->pool); |
| 4384 |
/* first, determine if a check for an existing declaration is needed; |
4481 |
/* first, determine if a check for an existing declaration is needed; |
| 4385 |
if yes, check that the entity exists, and that it is internal, |
4482 |
if yes, check that the entity exists, and that it is internal, |
|
Lines 4903-4909
appendAttributeValue(XML_Parser parser,
Link Here
|
| 4903 |
next - enc->minBytesPerChar); |
5000 |
next - enc->minBytesPerChar); |
| 4904 |
if (!name) |
5001 |
if (!name) |
| 4905 |
return XML_ERROR_NO_MEMORY; |
5002 |
return XML_ERROR_NO_MEMORY; |
| 4906 |
entity = (ENTITY *)lookup(&dtd->generalEntities, name, 0); |
5003 |
entity = (ENTITY *)lookup(parser, &dtd->generalEntities, name, 0); |
| 4907 |
poolDiscard(&temp2Pool); |
5004 |
poolDiscard(&temp2Pool); |
| 4908 |
/* First, determine if a check for an existing declaration is needed; |
5005 |
/* First, determine if a check for an existing declaration is needed; |
| 4909 |
if yes, check that the entity exists, and that it is internal. |
5006 |
if yes, check that the entity exists, and that it is internal. |
|
Lines 5012-5018
storeEntityValue(XML_Parser parser,
Link Here
|
| 5012 |
result = XML_ERROR_NO_MEMORY; |
5109 |
result = XML_ERROR_NO_MEMORY; |
| 5013 |
goto endEntityValue; |
5110 |
goto endEntityValue; |
| 5014 |
} |
5111 |
} |
| 5015 |
entity = (ENTITY *)lookup(&dtd->paramEntities, name, 0); |
5112 |
entity = (ENTITY *)lookup(parser, &dtd->paramEntities, name, 0); |
| 5016 |
poolDiscard(&tempPool); |
5113 |
poolDiscard(&tempPool); |
| 5017 |
if (!entity) { |
5114 |
if (!entity) { |
| 5018 |
/* not a well-formedness error - see XML 1.0: WFC Entity Declared */ |
5115 |
/* not a well-formedness error - see XML 1.0: WFC Entity Declared */ |
|
Lines 5302-5308
setElementTypePrefix(XML_Parser parser,
Link Here
|
| 5302 |
} |
5399 |
} |
| 5303 |
if (!poolAppendChar(&dtd->pool, XML_T('\0'))) |
5400 |
if (!poolAppendChar(&dtd->pool, XML_T('\0'))) |
| 5304 |
return 0; |
5401 |
return 0; |
| 5305 |
prefix = (PREFIX *)lookup(&dtd->prefixes, poolStart(&dtd->pool), |
5402 |
prefix = (PREFIX *)lookup(parser, &dtd->prefixes, poolStart(&dtd->pool), |
| 5306 |
sizeof(PREFIX)); |
5403 |
sizeof(PREFIX)); |
| 5307 |
if (!prefix) |
5404 |
if (!prefix) |
| 5308 |
return 0; |
5405 |
return 0; |
|
Lines 5331-5337
getAttributeId(XML_Parser parser, const
Link Here
|
| 5331 |
return NULL; |
5428 |
return NULL; |
| 5332 |
/* skip quotation mark - its storage will be re-used (like in name[-1]) */ |
5429 |
/* skip quotation mark - its storage will be re-used (like in name[-1]) */ |
| 5333 |
++name; |
5430 |
++name; |
| 5334 |
id = (ATTRIBUTE_ID *)lookup(&dtd->attributeIds, name, sizeof(ATTRIBUTE_ID)); |
5431 |
id = (ATTRIBUTE_ID *)lookup(parser, &dtd->attributeIds, name, sizeof(ATTRIBUTE_ID)); |
| 5335 |
if (!id) |
5432 |
if (!id) |
| 5336 |
return NULL; |
5433 |
return NULL; |
| 5337 |
if (id->name != name) |
5434 |
if (id->name != name) |
|
Lines 5349-5355
getAttributeId(XML_Parser parser, const
Link Here
|
| 5349 |
if (name[5] == XML_T('\0')) |
5446 |
if (name[5] == XML_T('\0')) |
| 5350 |
id->prefix = &dtd->defaultPrefix; |
5447 |
id->prefix = &dtd->defaultPrefix; |
| 5351 |
else |
5448 |
else |
| 5352 |
id->prefix = (PREFIX *)lookup(&dtd->prefixes, name + 6, sizeof(PREFIX)); |
5449 |
id->prefix = (PREFIX *)lookup(parser, &dtd->prefixes, name + 6, sizeof(PREFIX)); |
| 5353 |
id->xmlns = XML_TRUE; |
5450 |
id->xmlns = XML_TRUE; |
| 5354 |
} |
5451 |
} |
| 5355 |
else { |
5452 |
else { |
|
Lines 5364-5370
getAttributeId(XML_Parser parser, const
Link Here
|
| 5364 |
} |
5461 |
} |
| 5365 |
if (!poolAppendChar(&dtd->pool, XML_T('\0'))) |
5462 |
if (!poolAppendChar(&dtd->pool, XML_T('\0'))) |
| 5366 |
return NULL; |
5463 |
return NULL; |
| 5367 |
id->prefix = (PREFIX *)lookup(&dtd->prefixes, poolStart(&dtd->pool), |
5464 |
id->prefix = (PREFIX *)lookup(parser, &dtd->prefixes, poolStart(&dtd->pool), |
| 5368 |
sizeof(PREFIX)); |
5465 |
sizeof(PREFIX)); |
| 5369 |
if (id->prefix->name == poolStart(&dtd->pool)) |
5466 |
if (id->prefix->name == poolStart(&dtd->pool)) |
| 5370 |
poolFinish(&dtd->pool); |
5467 |
poolFinish(&dtd->pool); |
|
Lines 5460-5466
setContext(XML_Parser parser, const XML_
Link Here
|
| 5460 |
ENTITY *e; |
5557 |
ENTITY *e; |
| 5461 |
if (!poolAppendChar(&tempPool, XML_T('\0'))) |
5558 |
if (!poolAppendChar(&tempPool, XML_T('\0'))) |
| 5462 |
return XML_FALSE; |
5559 |
return XML_FALSE; |
| 5463 |
e = (ENTITY *)lookup(&dtd->generalEntities, poolStart(&tempPool), 0); |
5560 |
e = (ENTITY *)lookup(parser, &dtd->generalEntities, poolStart(&tempPool), 0); |
| 5464 |
if (e) |
5561 |
if (e) |
| 5465 |
e->open = XML_TRUE; |
5562 |
e->open = XML_TRUE; |
| 5466 |
if (*s != XML_T('\0')) |
5563 |
if (*s != XML_T('\0')) |
|
Lines 5475-5481
setContext(XML_Parser parser, const XML_
Link Here
|
| 5475 |
else { |
5572 |
else { |
| 5476 |
if (!poolAppendChar(&tempPool, XML_T('\0'))) |
5573 |
if (!poolAppendChar(&tempPool, XML_T('\0'))) |
| 5477 |
return XML_FALSE; |
5574 |
return XML_FALSE; |
| 5478 |
prefix = (PREFIX *)lookup(&dtd->prefixes, poolStart(&tempPool), |
5575 |
prefix = (PREFIX *)lookup(parser, &dtd->prefixes, poolStart(&tempPool), |
| 5479 |
sizeof(PREFIX)); |
5576 |
sizeof(PREFIX)); |
| 5480 |
if (!prefix) |
5577 |
if (!prefix) |
| 5481 |
return XML_FALSE; |
5578 |
return XML_FALSE; |
|
Lines 5639-5645
dtdDestroy(DTD *p, XML_Bool isDocEntity,
Link Here
|
| 5639 |
The new DTD has already been initialized. |
5736 |
The new DTD has already been initialized. |
| 5640 |
*/ |
5737 |
*/ |
| 5641 |
static int |
5738 |
static int |
| 5642 |
dtdCopy(DTD *newDtd, const DTD *oldDtd, const XML_Memory_Handling_Suite *ms) |
5739 |
dtdCopy(XML_Parser oldParser, DTD *newDtd, const DTD *oldDtd, const XML_Memory_Handling_Suite *ms) |
| 5643 |
{ |
5740 |
{ |
| 5644 |
HASH_TABLE_ITER iter; |
5741 |
HASH_TABLE_ITER iter; |
| 5645 |
|
5742 |
|
|
Lines 5654-5660
dtdCopy(DTD *newDtd, const DTD *oldDtd,
Link Here
|
| 5654 |
name = poolCopyString(&(newDtd->pool), oldP->name); |
5751 |
name = poolCopyString(&(newDtd->pool), oldP->name); |
| 5655 |
if (!name) |
5752 |
if (!name) |
| 5656 |
return 0; |
5753 |
return 0; |
| 5657 |
if (!lookup(&(newDtd->prefixes), name, sizeof(PREFIX))) |
5754 |
if (!lookup(oldParser, &(newDtd->prefixes), name, sizeof(PREFIX))) |
| 5658 |
return 0; |
5755 |
return 0; |
| 5659 |
} |
5756 |
} |
| 5660 |
|
5757 |
|
|
Lines 5676-5682
dtdCopy(DTD *newDtd, const DTD *oldDtd,
Link Here
|
| 5676 |
if (!name) |
5773 |
if (!name) |
| 5677 |
return 0; |
5774 |
return 0; |
| 5678 |
++name; |
5775 |
++name; |
| 5679 |
newA = (ATTRIBUTE_ID *)lookup(&(newDtd->attributeIds), name, |
5776 |
newA = (ATTRIBUTE_ID *)lookup(oldParser, &(newDtd->attributeIds), name, |
| 5680 |
sizeof(ATTRIBUTE_ID)); |
5777 |
sizeof(ATTRIBUTE_ID)); |
| 5681 |
if (!newA) |
5778 |
if (!newA) |
| 5682 |
return 0; |
5779 |
return 0; |
|
Lines 5686-5692
dtdCopy(DTD *newDtd, const DTD *oldDtd,
Link Here
|
| 5686 |
if (oldA->prefix == &oldDtd->defaultPrefix) |
5783 |
if (oldA->prefix == &oldDtd->defaultPrefix) |
| 5687 |
newA->prefix = &newDtd->defaultPrefix; |
5784 |
newA->prefix = &newDtd->defaultPrefix; |
| 5688 |
else |
5785 |
else |
| 5689 |
newA->prefix = (PREFIX *)lookup(&(newDtd->prefixes), |
5786 |
newA->prefix = (PREFIX *)lookup(oldParser, &(newDtd->prefixes), |
| 5690 |
oldA->prefix->name, 0); |
5787 |
oldA->prefix->name, 0); |
| 5691 |
} |
5788 |
} |
| 5692 |
} |
5789 |
} |
|
Lines 5705-5711
dtdCopy(DTD *newDtd, const DTD *oldDtd,
Link Here
|
| 5705 |
name = poolCopyString(&(newDtd->pool), oldE->name); |
5802 |
name = poolCopyString(&(newDtd->pool), oldE->name); |
| 5706 |
if (!name) |
5803 |
if (!name) |
| 5707 |
return 0; |
5804 |
return 0; |
| 5708 |
newE = (ELEMENT_TYPE *)lookup(&(newDtd->elementTypes), name, |
5805 |
newE = (ELEMENT_TYPE *)lookup(oldParser, &(newDtd->elementTypes), name, |
| 5709 |
sizeof(ELEMENT_TYPE)); |
5806 |
sizeof(ELEMENT_TYPE)); |
| 5710 |
if (!newE) |
5807 |
if (!newE) |
| 5711 |
return 0; |
5808 |
return 0; |
|
Lines 5719-5732
dtdCopy(DTD *newDtd, const DTD *oldDtd,
Link Here
|
| 5719 |
} |
5816 |
} |
| 5720 |
if (oldE->idAtt) |
5817 |
if (oldE->idAtt) |
| 5721 |
newE->idAtt = (ATTRIBUTE_ID *) |
5818 |
newE->idAtt = (ATTRIBUTE_ID *) |
| 5722 |
lookup(&(newDtd->attributeIds), oldE->idAtt->name, 0); |
5819 |
lookup(oldParser, &(newDtd->attributeIds), oldE->idAtt->name, 0); |
| 5723 |
newE->allocDefaultAtts = newE->nDefaultAtts = oldE->nDefaultAtts; |
5820 |
newE->allocDefaultAtts = newE->nDefaultAtts = oldE->nDefaultAtts; |
| 5724 |
if (oldE->prefix) |
5821 |
if (oldE->prefix) |
| 5725 |
newE->prefix = (PREFIX *)lookup(&(newDtd->prefixes), |
5822 |
newE->prefix = (PREFIX *)lookup(oldParser, &(newDtd->prefixes), |
| 5726 |
oldE->prefix->name, 0); |
5823 |
oldE->prefix->name, 0); |
| 5727 |
for (i = 0; i < newE->nDefaultAtts; i++) { |
5824 |
for (i = 0; i < newE->nDefaultAtts; i++) { |
| 5728 |
newE->defaultAtts[i].id = (ATTRIBUTE_ID *) |
5825 |
newE->defaultAtts[i].id = (ATTRIBUTE_ID *) |
| 5729 |
lookup(&(newDtd->attributeIds), oldE->defaultAtts[i].id->name, 0); |
5826 |
lookup(oldParser, &(newDtd->attributeIds), oldE->defaultAtts[i].id->name, 0); |
| 5730 |
newE->defaultAtts[i].isCdata = oldE->defaultAtts[i].isCdata; |
5827 |
newE->defaultAtts[i].isCdata = oldE->defaultAtts[i].isCdata; |
| 5731 |
if (oldE->defaultAtts[i].value) { |
5828 |
if (oldE->defaultAtts[i].value) { |
| 5732 |
newE->defaultAtts[i].value |
5829 |
newE->defaultAtts[i].value |
|
Lines 5740-5752
dtdCopy(DTD *newDtd, const DTD *oldDtd,
Link Here
|
| 5740 |
} |
5837 |
} |
| 5741 |
|
5838 |
|
| 5742 |
/* Copy the entity tables. */ |
5839 |
/* Copy the entity tables. */ |
| 5743 |
if (!copyEntityTable(&(newDtd->generalEntities), |
5840 |
if (!copyEntityTable(oldParser, |
|
|
5841 |
&(newDtd->generalEntities), |
| 5744 |
&(newDtd->pool), |
5842 |
&(newDtd->pool), |
| 5745 |
&(oldDtd->generalEntities))) |
5843 |
&(oldDtd->generalEntities))) |
| 5746 |
return 0; |
5844 |
return 0; |
| 5747 |
|
5845 |
|
| 5748 |
#ifdef XML_DTD |
5846 |
#ifdef XML_DTD |
| 5749 |
if (!copyEntityTable(&(newDtd->paramEntities), |
5847 |
if (!copyEntityTable(oldParser, |
|
|
5848 |
&(newDtd->paramEntities), |
| 5750 |
&(newDtd->pool), |
5849 |
&(newDtd->pool), |
| 5751 |
&(oldDtd->paramEntities))) |
5850 |
&(oldDtd->paramEntities))) |
| 5752 |
return 0; |
5851 |
return 0; |
|
Lines 5769-5775
dtdCopy(DTD *newDtd, const DTD *oldDtd,
Link Here
|
| 5769 |
} /* End dtdCopy */ |
5868 |
} /* End dtdCopy */ |
| 5770 |
|
5869 |
|
| 5771 |
static int |
5870 |
static int |
| 5772 |
copyEntityTable(HASH_TABLE *newTable, |
5871 |
copyEntityTable(XML_Parser oldParser, |
|
|
5872 |
HASH_TABLE *newTable, |
| 5773 |
STRING_POOL *newPool, |
5873 |
STRING_POOL *newPool, |
| 5774 |
const HASH_TABLE *oldTable) |
5874 |
const HASH_TABLE *oldTable) |
| 5775 |
{ |
5875 |
{ |
|
Lines 5788-5794
copyEntityTable(HASH_TABLE *newTable,
Link Here
|
| 5788 |
name = poolCopyString(newPool, oldE->name); |
5888 |
name = poolCopyString(newPool, oldE->name); |
| 5789 |
if (!name) |
5889 |
if (!name) |
| 5790 |
return 0; |
5890 |
return 0; |
| 5791 |
newE = (ENTITY *)lookup(newTable, name, sizeof(ENTITY)); |
5891 |
newE = (ENTITY *)lookup(oldParser, newTable, name, sizeof(ENTITY)); |
| 5792 |
if (!newE) |
5892 |
if (!newE) |
| 5793 |
return 0; |
5893 |
return 0; |
| 5794 |
if (oldE->systemId) { |
5894 |
if (oldE->systemId) { |
|
Lines 5846-5861
keyeq(KEY s1, KEY s2)
Link Here
|
| 5846 |
} |
5946 |
} |
| 5847 |
|
5947 |
|
| 5848 |
static unsigned long FASTCALL |
5948 |
static unsigned long FASTCALL |
| 5849 |
hash(KEY s) |
5949 |
hash(XML_Parser parser, KEY s) |
| 5850 |
{ |
5950 |
{ |
| 5851 |
unsigned long h = 0; |
5951 |
unsigned long h = hash_secret_salt; |
| 5852 |
while (*s) |
5952 |
while (*s) |
| 5853 |
h = CHAR_HASH(h, *s++); |
5953 |
h = CHAR_HASH(h, *s++); |
| 5854 |
return h; |
5954 |
return h; |
| 5855 |
} |
5955 |
} |
| 5856 |
|
5956 |
|
| 5857 |
static NAMED * |
5957 |
static NAMED * |
| 5858 |
lookup(HASH_TABLE *table, KEY name, size_t createSize) |
5958 |
lookup(XML_Parser parser, HASH_TABLE *table, KEY name, size_t createSize) |
| 5859 |
{ |
5959 |
{ |
| 5860 |
size_t i; |
5960 |
size_t i; |
| 5861 |
if (table->size == 0) { |
5961 |
if (table->size == 0) { |
|
Lines 5872-5881
lookup(HASH_TABLE *table, KEY name, size
Link Here
|
| 5872 |
return NULL; |
5972 |
return NULL; |
| 5873 |
} |
5973 |
} |
| 5874 |
memset(table->v, 0, tsize); |
5974 |
memset(table->v, 0, tsize); |
| 5875 |
i = hash(name) & ((unsigned long)table->size - 1); |
5975 |
i = hash(parser, name) & ((unsigned long)table->size - 1); |
| 5876 |
} |
5976 |
} |
| 5877 |
else { |
5977 |
else { |
| 5878 |
unsigned long h = hash(name); |
5978 |
unsigned long h = hash(parser, name); |
| 5879 |
unsigned long mask = (unsigned long)table->size - 1; |
5979 |
unsigned long mask = (unsigned long)table->size - 1; |
| 5880 |
unsigned char step = 0; |
5980 |
unsigned char step = 0; |
| 5881 |
i = h & mask; |
5981 |
i = h & mask; |
|
Lines 5901-5907
lookup(HASH_TABLE *table, KEY name, size
Link Here
|
| 5901 |
memset(newV, 0, tsize); |
6001 |
memset(newV, 0, tsize); |
| 5902 |
for (i = 0; i < table->size; i++) |
6002 |
for (i = 0; i < table->size; i++) |
| 5903 |
if (table->v[i]) { |
6003 |
if (table->v[i]) { |
| 5904 |
unsigned long newHash = hash(table->v[i]->name); |
6004 |
unsigned long newHash = hash(parser, table->v[i]->name); |
| 5905 |
size_t j = newHash & newMask; |
6005 |
size_t j = newHash & newMask; |
| 5906 |
step = 0; |
6006 |
step = 0; |
| 5907 |
while (newV[j]) { |
6007 |
while (newV[j]) { |
|
Lines 6276-6282
getElementType(XML_Parser parser,
Link Here
|
| 6276 |
|
6376 |
|
| 6277 |
if (!name) |
6377 |
if (!name) |
| 6278 |
return NULL; |
6378 |
return NULL; |
| 6279 |
ret = (ELEMENT_TYPE *) lookup(&dtd->elementTypes, name, sizeof(ELEMENT_TYPE)); |
6379 |
ret = (ELEMENT_TYPE *) lookup(parser, &dtd->elementTypes, name, sizeof(ELEMENT_TYPE)); |
| 6280 |
if (!ret) |
6380 |
if (!ret) |
| 6281 |
return NULL; |
6381 |
return NULL; |
| 6282 |
if (ret->name != name) |
6382 |
if (ret->name != name) |