OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "xfa/fxfa/parser/xfa_parser_imp.h" | 7 #include "xfa/fxfa/parser/xfa_parser_imp.h" |
8 | 8 |
9 #include "xfa/fde/xml/fde_xml_imp.h" | 9 #include "xfa/fde/xml/fde_xml_imp.h" |
10 #include "xfa/fgas/crt/fgas_codepage.h" | 10 #include "xfa/fgas/crt/fgas_codepage.h" |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 } | 218 } |
219 } | 219 } |
220 wsNamespaceURI.Empty(); | 220 wsNamespaceURI.Empty(); |
221 return bRet; | 221 return bRet; |
222 } | 222 } |
223 static inline void XFA_FDEExtension_GetElementTagNamespaceURI( | 223 static inline void XFA_FDEExtension_GetElementTagNamespaceURI( |
224 CFDE_XMLElement* pElement, | 224 CFDE_XMLElement* pElement, |
225 CFX_WideString& wsNamespaceURI) { | 225 CFX_WideString& wsNamespaceURI) { |
226 CFX_WideString wsNodeStr; | 226 CFX_WideString wsNodeStr; |
227 pElement->GetNamespacePrefix(wsNodeStr); | 227 pElement->GetNamespacePrefix(wsNodeStr); |
228 if (!XFA_FDEExtension_ResolveNamespaceQualifier(pElement, wsNodeStr, | 228 if (!XFA_FDEExtension_ResolveNamespaceQualifier( |
229 wsNamespaceURI)) { | 229 pElement, wsNodeStr.AsWideStringC(), wsNamespaceURI)) { |
230 wsNamespaceURI.Empty(); | 230 wsNamespaceURI.Empty(); |
231 } | 231 } |
232 } | 232 } |
233 static FX_BOOL XFA_FDEExtension_MatchNodeName( | 233 static FX_BOOL XFA_FDEExtension_MatchNodeName( |
234 CFDE_XMLNode* pNode, | 234 CFDE_XMLNode* pNode, |
235 const CFX_WideStringC& wsLocalTagName, | 235 const CFX_WideStringC& wsLocalTagName, |
236 const CFX_WideStringC& wsNamespaceURIPrefix, | 236 const CFX_WideStringC& wsNamespaceURIPrefix, |
237 uint32_t eMatchFlags = XFA_XDPPACKET_FLAGS_NOMATCH) { | 237 uint32_t eMatchFlags = XFA_XDPPACKET_FLAGS_NOMATCH) { |
238 if (!pNode || pNode->GetType() != FDE_XMLNODE_Element) { | 238 if (!pNode || pNode->GetType() != FDE_XMLNODE_Element) { |
239 return FALSE; | 239 return FALSE; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 CFX_WideString wsNSPrefix; | 276 CFX_WideString wsNSPrefix; |
277 if (XFA_FDEExtension_GetAttributeLocalName(wsAttributeName, | 277 if (XFA_FDEExtension_GetAttributeLocalName(wsAttributeName, |
278 wsLocalAttrName)) { | 278 wsLocalAttrName)) { |
279 wsNSPrefix = wsAttrName.Left(wsAttributeName.GetLength() - | 279 wsNSPrefix = wsAttrName.Left(wsAttributeName.GetLength() - |
280 wsLocalAttrName.GetLength() - 1); | 280 wsLocalAttrName.GetLength() - 1); |
281 } | 281 } |
282 if (wsLocalAttrName == FX_WSTRC(L"xmlns") || | 282 if (wsLocalAttrName == FX_WSTRC(L"xmlns") || |
283 wsNSPrefix == FX_WSTRC(L"xmlns") || wsNSPrefix == FX_WSTRC(L"xml")) { | 283 wsNSPrefix == FX_WSTRC(L"xmlns") || wsNSPrefix == FX_WSTRC(L"xml")) { |
284 return FALSE; | 284 return FALSE; |
285 } | 285 } |
286 if (!XFA_FDEExtension_ResolveNamespaceQualifier(pElement, wsNSPrefix, | 286 if (!XFA_FDEExtension_ResolveNamespaceQualifier( |
287 wsNamespaceURI)) { | 287 pElement, wsNSPrefix.AsWideStringC(), wsNamespaceURI)) { |
288 wsNamespaceURI.Empty(); | 288 wsNamespaceURI.Empty(); |
289 return FALSE; | 289 return FALSE; |
290 } | 290 } |
291 return TRUE; | 291 return TRUE; |
292 } | 292 } |
293 static FX_BOOL XFA_FDEExtension_FindAttributeWithNS( | 293 static FX_BOOL XFA_FDEExtension_FindAttributeWithNS( |
294 CFDE_XMLElement* pElement, | 294 CFDE_XMLElement* pElement, |
295 const CFX_WideStringC& wsLocalAttributeName, | 295 const CFX_WideStringC& wsLocalAttributeName, |
296 const CFX_WideStringC& wsNamespaceURIPrefix, | 296 const CFX_WideStringC& wsNamespaceURIPrefix, |
297 CFX_WideString& wsValue, | 297 CFX_WideString& wsValue, |
(...skipping 13 matching lines...) Expand all Loading... |
311 if (wsLocalAttributeName != wsAttrName) { | 311 if (wsLocalAttributeName != wsAttrName) { |
312 continue; | 312 continue; |
313 } | 313 } |
314 } else { | 314 } else { |
315 if (wsLocalAttributeName != | 315 if (wsLocalAttributeName != |
316 wsAttrName.Right(wsAttrName.GetLength() - iFind - 1)) { | 316 wsAttrName.Right(wsAttrName.GetLength() - iFind - 1)) { |
317 continue; | 317 continue; |
318 } | 318 } |
319 wsNSPrefix = wsAttrName.Left(iFind); | 319 wsNSPrefix = wsAttrName.Left(iFind); |
320 } | 320 } |
321 if (!XFA_FDEExtension_ResolveNamespaceQualifier(pElement, wsNSPrefix, | 321 if (!XFA_FDEExtension_ResolveNamespaceQualifier( |
322 wsAttrNS)) { | 322 pElement, wsNSPrefix.AsWideStringC(), wsAttrNS)) { |
323 continue; | 323 continue; |
324 } | 324 } |
325 if (bMatchNSAsPrefix) { | 325 if (bMatchNSAsPrefix) { |
326 if (wsAttrNS.Left(wsNamespaceURIPrefix.GetLength()) != | 326 if (wsAttrNS.Left(wsNamespaceURIPrefix.GetLength()) != |
327 wsNamespaceURIPrefix) { | 327 wsNamespaceURIPrefix) { |
328 continue; | 328 continue; |
329 } | 329 } |
330 } else { | 330 } else { |
331 if (wsAttrNS != wsNamespaceURIPrefix) { | 331 if (wsAttrNS != wsNamespaceURIPrefix) { |
332 continue; | 332 continue; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 if (!pChildItem || pChildItem->GetType() != FDE_XMLNODE_Element) { | 426 if (!pChildItem || pChildItem->GetType() != FDE_XMLNODE_Element) { |
427 continue; | 427 continue; |
428 } | 428 } |
429 if (pChildItem == pXMLConfigDOMRoot) { | 429 if (pChildItem == pXMLConfigDOMRoot) { |
430 continue; | 430 continue; |
431 } | 431 } |
432 CFDE_XMLElement* pElement = | 432 CFDE_XMLElement* pElement = |
433 reinterpret_cast<CFDE_XMLElement*>(pChildItem); | 433 reinterpret_cast<CFDE_XMLElement*>(pChildItem); |
434 CFX_WideString wsPacketName; | 434 CFX_WideString wsPacketName; |
435 pElement->GetLocalTagName(wsPacketName); | 435 pElement->GetLocalTagName(wsPacketName); |
436 const XFA_PACKETINFO* pPacketInfo = XFA_GetPacketByName(wsPacketName); | 436 const XFA_PACKETINFO* pPacketInfo = |
| 437 XFA_GetPacketByName(wsPacketName.AsWideStringC()); |
437 if (pPacketInfo && pPacketInfo->pURI) { | 438 if (pPacketInfo && pPacketInfo->pURI) { |
438 if (!XFA_FDEExtension_MatchNodeName(pElement, pPacketInfo->pName, | 439 if (!XFA_FDEExtension_MatchNodeName(pElement, pPacketInfo->pName, |
439 pPacketInfo->pURI, | 440 pPacketInfo->pURI, |
440 pPacketInfo->eFlags)) { | 441 pPacketInfo->eFlags)) { |
441 pPacketInfo = nullptr; | 442 pPacketInfo = nullptr; |
442 } | 443 } |
443 } | 444 } |
444 XFA_XDPPACKET ePacket = | 445 XFA_XDPPACKET ePacket = |
445 pPacketInfo ? pPacketInfo->eName : XFA_XDPPACKET_USER; | 446 pPacketInfo ? pPacketInfo->eName : XFA_XDPPACKET_USER; |
446 if (ePacket == XFA_XDPPACKET_XDP) { | 447 if (ePacket == XFA_XDPPACKET_XDP) { |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 if (bsCheck != wsChecksum.UTF8Encode()) { | 579 if (bsCheck != wsChecksum.UTF8Encode()) { |
579 return NULL; | 580 return NULL; |
580 } | 581 } |
581 | 582 |
582 pNode = m_pFactory->CreateNode(XFA_XDPPACKET_Form, XFA_ELEMENT_Form); | 583 pNode = m_pFactory->CreateNode(XFA_XDPPACKET_Form, XFA_ELEMENT_Form); |
583 if (!pNode) { | 584 if (!pNode) { |
584 return NULL; | 585 return NULL; |
585 } | 586 } |
586 pNode->SetCData(XFA_ATTRIBUTE_Name, | 587 pNode->SetCData(XFA_ATTRIBUTE_Name, |
587 XFA_GetPacketByIndex(XFA_PACKET_Form)->pName); | 588 XFA_GetPacketByIndex(XFA_PACKET_Form)->pName); |
588 pNode->SetAttribute(XFA_ATTRIBUTE_Checksum, wsChecksum); | 589 pNode->SetAttribute(XFA_ATTRIBUTE_Checksum, wsChecksum.AsWideStringC()); |
589 CXFA_Node* pTemplateRoot = | 590 CXFA_Node* pTemplateRoot = |
590 m_pRootNode->GetFirstChildByClass(XFA_ELEMENT_Template); | 591 m_pRootNode->GetFirstChildByClass(XFA_ELEMENT_Template); |
591 CXFA_Node* pTemplateChosen = | 592 CXFA_Node* pTemplateChosen = |
592 pTemplateRoot | 593 pTemplateRoot |
593 ? pTemplateRoot->GetFirstChildByClass(XFA_ELEMENT_Subform) | 594 ? pTemplateRoot->GetFirstChildByClass(XFA_ELEMENT_Subform) |
594 : NULL; | 595 : NULL; |
595 FX_BOOL bUseAttribute = TRUE; | 596 FX_BOOL bUseAttribute = TRUE; |
596 if (pTemplateChosen && | 597 if (pTemplateChosen && |
597 pTemplateChosen->GetEnum(XFA_ATTRIBUTE_RestoreState) != | 598 pTemplateChosen->GetEnum(XFA_ATTRIBUTE_RestoreState) != |
598 XFA_ATTRIBUTEENUM_Auto) { | 599 XFA_ATTRIBUTEENUM_Auto) { |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
814 FX_BOOL bUseAttribute) { | 815 FX_BOOL bUseAttribute) { |
815 FX_BOOL bOneOfPropertyFound = FALSE; | 816 FX_BOOL bOneOfPropertyFound = FALSE; |
816 for (CFDE_XMLNode* pXMLChild = pXMLDoc->GetNodeItem(CFDE_XMLNode::FirstChild); | 817 for (CFDE_XMLNode* pXMLChild = pXMLDoc->GetNodeItem(CFDE_XMLNode::FirstChild); |
817 pXMLChild; | 818 pXMLChild; |
818 pXMLChild = pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling)) { | 819 pXMLChild = pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling)) { |
819 switch (pXMLChild->GetType()) { | 820 switch (pXMLChild->GetType()) { |
820 case FDE_XMLNODE_Element: { | 821 case FDE_XMLNODE_Element: { |
821 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLChild); | 822 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLChild); |
822 CFX_WideString wsTagName; | 823 CFX_WideString wsTagName; |
823 pXMLElement->GetLocalTagName(wsTagName); | 824 pXMLElement->GetLocalTagName(wsTagName); |
824 const XFA_ELEMENTINFO* pElemInfo = XFA_GetElementByName(wsTagName); | 825 const XFA_ELEMENTINFO* pElemInfo = |
| 826 XFA_GetElementByName(wsTagName.AsWideStringC()); |
825 if (!pElemInfo) { | 827 if (!pElemInfo) { |
826 continue; | 828 continue; |
827 } | 829 } |
828 const XFA_PROPERTY* pPropertyInfo = XFA_GetPropertyOfElement( | 830 const XFA_PROPERTY* pPropertyInfo = XFA_GetPropertyOfElement( |
829 pXFANode->GetClassID(), pElemInfo->eName, ePacketID); | 831 pXFANode->GetClassID(), pElemInfo->eName, ePacketID); |
830 if (pPropertyInfo && | 832 if (pPropertyInfo && |
831 ((pPropertyInfo->uFlags & | 833 ((pPropertyInfo->uFlags & |
832 (XFA_PROPERTYFLAG_OneOf | XFA_PROPERTYFLAG_DefaultOneOf)) != 0)) { | 834 (XFA_PROPERTYFLAG_OneOf | XFA_PROPERTYFLAG_DefaultOneOf)) != 0)) { |
833 if (bOneOfPropertyFound) { | 835 if (bOneOfPropertyFound) { |
834 break; | 836 break; |
835 } | 837 } |
836 bOneOfPropertyFound = TRUE; | 838 bOneOfPropertyFound = TRUE; |
837 } | 839 } |
838 CXFA_Node* pXFAChild = | 840 CXFA_Node* pXFAChild = |
839 m_pFactory->CreateNode(ePacketID, pElemInfo->eName); | 841 m_pFactory->CreateNode(ePacketID, pElemInfo->eName); |
840 if (pXFAChild == NULL) { | 842 if (pXFAChild == NULL) { |
841 return NULL; | 843 return NULL; |
842 } | 844 } |
843 if (ePacketID == XFA_XDPPACKET_Config) { | 845 if (ePacketID == XFA_XDPPACKET_Config) { |
844 pXFAChild->SetAttribute(XFA_ATTRIBUTE_Name, wsTagName); | 846 pXFAChild->SetAttribute(XFA_ATTRIBUTE_Name, |
| 847 wsTagName.AsWideStringC()); |
845 } | 848 } |
846 FX_BOOL IsNeedValue = TRUE; | 849 FX_BOOL IsNeedValue = TRUE; |
847 for (int32_t i = 0, count = pXMLElement->CountAttributes(); i < count; | 850 for (int32_t i = 0, count = pXMLElement->CountAttributes(); i < count; |
848 i++) { | 851 i++) { |
849 CFX_WideString wsAttrQualifiedName; | 852 CFX_WideString wsAttrQualifiedName; |
850 CFX_WideString wsAttrName; | 853 CFX_WideString wsAttrName; |
851 CFX_WideString wsAttrValue; | 854 CFX_WideString wsAttrValue; |
852 pXMLElement->GetAttribute(i, wsAttrQualifiedName, wsAttrValue); | 855 pXMLElement->GetAttribute(i, wsAttrQualifiedName, wsAttrValue); |
853 XFA_FDEExtension_GetAttributeLocalName(wsAttrQualifiedName, | 856 XFA_FDEExtension_GetAttributeLocalName( |
854 wsAttrName); | 857 wsAttrQualifiedName.AsWideStringC(), wsAttrName); |
855 if (wsAttrName == FX_WSTRC(L"nil") && | 858 if (wsAttrName == FX_WSTRC(L"nil") && |
856 wsAttrValue == FX_WSTRC(L"true")) { | 859 wsAttrValue == FX_WSTRC(L"true")) { |
857 IsNeedValue = FALSE; | 860 IsNeedValue = FALSE; |
858 } | 861 } |
859 const XFA_ATTRIBUTEINFO* lpAttrInfo = | 862 const XFA_ATTRIBUTEINFO* lpAttrInfo = |
860 XFA_GetAttributeByName(wsAttrName); | 863 XFA_GetAttributeByName(wsAttrName.AsWideStringC()); |
861 if (!lpAttrInfo) { | 864 if (!lpAttrInfo) { |
862 continue; | 865 continue; |
863 } | 866 } |
864 if (!bUseAttribute && lpAttrInfo->eName != XFA_ATTRIBUTE_Name && | 867 if (!bUseAttribute && lpAttrInfo->eName != XFA_ATTRIBUTE_Name && |
865 lpAttrInfo->eName != XFA_ATTRIBUTE_Save) { | 868 lpAttrInfo->eName != XFA_ATTRIBUTE_Save) { |
866 continue; | 869 continue; |
867 } | 870 } |
868 pXFAChild->SetAttribute(lpAttrInfo->eName, wsAttrValue); | 871 pXFAChild->SetAttribute(lpAttrInfo->eName, |
| 872 wsAttrValue.AsWideStringC()); |
869 } | 873 } |
870 pXFANode->InsertChild(pXFAChild); | 874 pXFANode->InsertChild(pXFAChild); |
871 if (pElemInfo->eName == XFA_ELEMENT_Validate || | 875 if (pElemInfo->eName == XFA_ELEMENT_Validate || |
872 pElemInfo->eName == XFA_ELEMENT_Locale) { | 876 pElemInfo->eName == XFA_ELEMENT_Locale) { |
873 if (ePacketID == XFA_XDPPACKET_Config) { | 877 if (ePacketID == XFA_XDPPACKET_Config) { |
874 ParseContentNode(pXFAChild, pXMLElement, ePacketID); | 878 ParseContentNode(pXFAChild, pXMLElement, ePacketID); |
875 } else { | 879 } else { |
876 NormalLoader(pXFAChild, pXMLElement, ePacketID, bUseAttribute); | 880 NormalLoader(pXFAChild, pXMLElement, ePacketID, bUseAttribute); |
877 } | 881 } |
878 break; | 882 break; |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1101 FX_BOOL bNeedValue = TRUE; | 1105 FX_BOOL bNeedValue = TRUE; |
1102 if (1) { | 1106 if (1) { |
1103 for (int32_t i = 0, count = pXMLElement->CountAttributes(); i < count; | 1107 for (int32_t i = 0, count = pXMLElement->CountAttributes(); i < count; |
1104 i++) { | 1108 i++) { |
1105 CFX_WideString wsAttrQualifiedName; | 1109 CFX_WideString wsAttrQualifiedName; |
1106 CFX_WideString wsAttrValue; | 1110 CFX_WideString wsAttrValue; |
1107 CFX_WideString wsAttrName; | 1111 CFX_WideString wsAttrName; |
1108 CFX_WideString wsAttrNamespaceURI; | 1112 CFX_WideString wsAttrNamespaceURI; |
1109 pXMLElement->GetAttribute(i, wsAttrQualifiedName, wsAttrValue); | 1113 pXMLElement->GetAttribute(i, wsAttrQualifiedName, wsAttrValue); |
1110 if (!XFA_FDEExtension_ResolveAttribute( | 1114 if (!XFA_FDEExtension_ResolveAttribute( |
1111 pXMLElement, wsAttrQualifiedName, wsAttrName, | 1115 pXMLElement, wsAttrQualifiedName.AsWideStringC(), |
1112 wsAttrNamespaceURI)) { | 1116 wsAttrName, wsAttrNamespaceURI)) { |
1113 continue; | 1117 continue; |
1114 } | 1118 } |
1115 if (wsAttrName == FX_WSTRC(L"nil") && | 1119 if (wsAttrName == FX_WSTRC(L"nil") && |
1116 wsAttrValue == FX_WSTRC(L"true")) { | 1120 wsAttrValue == FX_WSTRC(L"true")) { |
1117 bNeedValue = FALSE; | 1121 bNeedValue = FALSE; |
1118 continue; | 1122 continue; |
1119 } | 1123 } |
1120 if (wsAttrNamespaceURI == | 1124 if (wsAttrNamespaceURI == |
1121 FX_WSTRC(L"http://www.xfa.com/schema/xfa-package/") || | 1125 FX_WSTRC(L"http://www.xfa.com/schema/xfa-package/") || |
1122 wsAttrNamespaceURI == | 1126 wsAttrNamespaceURI == |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1555 } | 1559 } |
1556 if (pPause && iCount > 500 && pPause->NeedToPauseNow()) { | 1560 if (pPause && iCount > 500 && pPause->NeedToPauseNow()) { |
1557 break; | 1561 break; |
1558 } | 1562 } |
1559 } | 1563 } |
1560 return (m_syntaxParserResult == FDE_XmlSyntaxResult::Error || | 1564 return (m_syntaxParserResult == FDE_XmlSyntaxResult::Error || |
1561 m_NodeStack.GetSize() != 1) | 1565 m_NodeStack.GetSize() != 1) |
1562 ? -1 | 1566 ? -1 |
1563 : m_pParser->GetStatus(); | 1567 : m_pParser->GetStatus(); |
1564 } | 1568 } |
OLD | NEW |