| 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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 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( | 228   if (!XFA_FDEExtension_ResolveNamespaceQualifier( | 
| 229           pElement, wsNodeStr.AsWideStringC(), wsNamespaceURI)) { | 229           pElement, wsNodeStr.AsStringC(), 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 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( | 286   if (!XFA_FDEExtension_ResolveNamespaceQualifier( | 
| 287           pElement, wsNSPrefix.AsWideStringC(), wsNamespaceURI)) { | 287           pElement, wsNSPrefix.AsStringC(), 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 14 matching lines...) Expand all  Loading... | 
| 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( | 321     if (!XFA_FDEExtension_ResolveNamespaceQualifier( | 
| 322             pElement, wsNSPrefix.AsWideStringC(), wsAttrNS)) { | 322             pElement, wsNSPrefix.AsStringC(), 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 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 = | 436       const XFA_PACKETINFO* pPacketInfo = | 
| 437           XFA_GetPacketByName(wsPacketName.AsWideStringC()); | 437           XFA_GetPacketByName(wsPacketName.AsStringC()); | 
| 438       if (pPacketInfo && pPacketInfo->pURI) { | 438       if (pPacketInfo && pPacketInfo->pURI) { | 
| 439         if (!XFA_FDEExtension_MatchNodeName(pElement, pPacketInfo->pName, | 439         if (!XFA_FDEExtension_MatchNodeName(pElement, pPacketInfo->pName, | 
| 440                                             pPacketInfo->pURI, | 440                                             pPacketInfo->pURI, | 
| 441                                             pPacketInfo->eFlags)) { | 441                                             pPacketInfo->eFlags)) { | 
| 442           pPacketInfo = nullptr; | 442           pPacketInfo = nullptr; | 
| 443         } | 443         } | 
| 444       } | 444       } | 
| 445       XFA_XDPPACKET ePacket = | 445       XFA_XDPPACKET ePacket = | 
| 446           pPacketInfo ? pPacketInfo->eName : XFA_XDPPACKET_USER; | 446           pPacketInfo ? pPacketInfo->eName : XFA_XDPPACKET_USER; | 
| 447       if (ePacket == XFA_XDPPACKET_XDP) { | 447       if (ePacket == XFA_XDPPACKET_XDP) { | 
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 579       if (bsCheck != wsChecksum.UTF8Encode()) { | 579       if (bsCheck != wsChecksum.UTF8Encode()) { | 
| 580         return NULL; | 580         return NULL; | 
| 581       } | 581       } | 
| 582 | 582 | 
| 583       pNode = m_pFactory->CreateNode(XFA_XDPPACKET_Form, XFA_ELEMENT_Form); | 583       pNode = m_pFactory->CreateNode(XFA_XDPPACKET_Form, XFA_ELEMENT_Form); | 
| 584       if (!pNode) { | 584       if (!pNode) { | 
| 585         return NULL; | 585         return NULL; | 
| 586       } | 586       } | 
| 587       pNode->SetCData(XFA_ATTRIBUTE_Name, | 587       pNode->SetCData(XFA_ATTRIBUTE_Name, | 
| 588                       XFA_GetPacketByIndex(XFA_PACKET_Form)->pName); | 588                       XFA_GetPacketByIndex(XFA_PACKET_Form)->pName); | 
| 589       pNode->SetAttribute(XFA_ATTRIBUTE_Checksum, wsChecksum.AsWideStringC()); | 589       pNode->SetAttribute(XFA_ATTRIBUTE_Checksum, wsChecksum.AsStringC()); | 
| 590       CXFA_Node* pTemplateRoot = | 590       CXFA_Node* pTemplateRoot = | 
| 591           m_pRootNode->GetFirstChildByClass(XFA_ELEMENT_Template); | 591           m_pRootNode->GetFirstChildByClass(XFA_ELEMENT_Template); | 
| 592       CXFA_Node* pTemplateChosen = | 592       CXFA_Node* pTemplateChosen = | 
| 593           pTemplateRoot | 593           pTemplateRoot | 
| 594               ? pTemplateRoot->GetFirstChildByClass(XFA_ELEMENT_Subform) | 594               ? pTemplateRoot->GetFirstChildByClass(XFA_ELEMENT_Subform) | 
| 595               : NULL; | 595               : NULL; | 
| 596       FX_BOOL bUseAttribute = TRUE; | 596       FX_BOOL bUseAttribute = TRUE; | 
| 597       if (pTemplateChosen && | 597       if (pTemplateChosen && | 
| 598           pTemplateChosen->GetEnum(XFA_ATTRIBUTE_RestoreState) != | 598           pTemplateChosen->GetEnum(XFA_ATTRIBUTE_RestoreState) != | 
| 599               XFA_ATTRIBUTEENUM_Auto) { | 599               XFA_ATTRIBUTEENUM_Auto) { | 
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 816   FX_BOOL bOneOfPropertyFound = FALSE; | 816   FX_BOOL bOneOfPropertyFound = FALSE; | 
| 817   for (CFDE_XMLNode* pXMLChild = pXMLDoc->GetNodeItem(CFDE_XMLNode::FirstChild); | 817   for (CFDE_XMLNode* pXMLChild = pXMLDoc->GetNodeItem(CFDE_XMLNode::FirstChild); | 
| 818        pXMLChild; | 818        pXMLChild; | 
| 819        pXMLChild = pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling)) { | 819        pXMLChild = pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling)) { | 
| 820     switch (pXMLChild->GetType()) { | 820     switch (pXMLChild->GetType()) { | 
| 821       case FDE_XMLNODE_Element: { | 821       case FDE_XMLNODE_Element: { | 
| 822         CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLChild); | 822         CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLChild); | 
| 823         CFX_WideString wsTagName; | 823         CFX_WideString wsTagName; | 
| 824         pXMLElement->GetLocalTagName(wsTagName); | 824         pXMLElement->GetLocalTagName(wsTagName); | 
| 825         const XFA_ELEMENTINFO* pElemInfo = | 825         const XFA_ELEMENTINFO* pElemInfo = | 
| 826             XFA_GetElementByName(wsTagName.AsWideStringC()); | 826             XFA_GetElementByName(wsTagName.AsStringC()); | 
| 827         if (!pElemInfo) { | 827         if (!pElemInfo) { | 
| 828           continue; | 828           continue; | 
| 829         } | 829         } | 
| 830         const XFA_PROPERTY* pPropertyInfo = XFA_GetPropertyOfElement( | 830         const XFA_PROPERTY* pPropertyInfo = XFA_GetPropertyOfElement( | 
| 831             pXFANode->GetClassID(), pElemInfo->eName, ePacketID); | 831             pXFANode->GetClassID(), pElemInfo->eName, ePacketID); | 
| 832         if (pPropertyInfo && | 832         if (pPropertyInfo && | 
| 833             ((pPropertyInfo->uFlags & | 833             ((pPropertyInfo->uFlags & | 
| 834               (XFA_PROPERTYFLAG_OneOf | XFA_PROPERTYFLAG_DefaultOneOf)) != 0)) { | 834               (XFA_PROPERTYFLAG_OneOf | XFA_PROPERTYFLAG_DefaultOneOf)) != 0)) { | 
| 835           if (bOneOfPropertyFound) { | 835           if (bOneOfPropertyFound) { | 
| 836             break; | 836             break; | 
| 837           } | 837           } | 
| 838           bOneOfPropertyFound = TRUE; | 838           bOneOfPropertyFound = TRUE; | 
| 839         } | 839         } | 
| 840         CXFA_Node* pXFAChild = | 840         CXFA_Node* pXFAChild = | 
| 841             m_pFactory->CreateNode(ePacketID, pElemInfo->eName); | 841             m_pFactory->CreateNode(ePacketID, pElemInfo->eName); | 
| 842         if (pXFAChild == NULL) { | 842         if (pXFAChild == NULL) { | 
| 843           return NULL; | 843           return NULL; | 
| 844         } | 844         } | 
| 845         if (ePacketID == XFA_XDPPACKET_Config) { | 845         if (ePacketID == XFA_XDPPACKET_Config) { | 
| 846           pXFAChild->SetAttribute(XFA_ATTRIBUTE_Name, | 846           pXFAChild->SetAttribute(XFA_ATTRIBUTE_Name, wsTagName.AsStringC()); | 
| 847                                   wsTagName.AsWideStringC()); |  | 
| 848         } | 847         } | 
| 849         FX_BOOL IsNeedValue = TRUE; | 848         FX_BOOL IsNeedValue = TRUE; | 
| 850         for (int32_t i = 0, count = pXMLElement->CountAttributes(); i < count; | 849         for (int32_t i = 0, count = pXMLElement->CountAttributes(); i < count; | 
| 851              i++) { | 850              i++) { | 
| 852           CFX_WideString wsAttrQualifiedName; | 851           CFX_WideString wsAttrQualifiedName; | 
| 853           CFX_WideString wsAttrName; | 852           CFX_WideString wsAttrName; | 
| 854           CFX_WideString wsAttrValue; | 853           CFX_WideString wsAttrValue; | 
| 855           pXMLElement->GetAttribute(i, wsAttrQualifiedName, wsAttrValue); | 854           pXMLElement->GetAttribute(i, wsAttrQualifiedName, wsAttrValue); | 
| 856           XFA_FDEExtension_GetAttributeLocalName( | 855           XFA_FDEExtension_GetAttributeLocalName( | 
| 857               wsAttrQualifiedName.AsWideStringC(), wsAttrName); | 856               wsAttrQualifiedName.AsStringC(), wsAttrName); | 
| 858           if (wsAttrName == FX_WSTRC(L"nil") && | 857           if (wsAttrName == FX_WSTRC(L"nil") && | 
| 859               wsAttrValue == FX_WSTRC(L"true")) { | 858               wsAttrValue == FX_WSTRC(L"true")) { | 
| 860             IsNeedValue = FALSE; | 859             IsNeedValue = FALSE; | 
| 861           } | 860           } | 
| 862           const XFA_ATTRIBUTEINFO* lpAttrInfo = | 861           const XFA_ATTRIBUTEINFO* lpAttrInfo = | 
| 863               XFA_GetAttributeByName(wsAttrName.AsWideStringC()); | 862               XFA_GetAttributeByName(wsAttrName.AsStringC()); | 
| 864           if (!lpAttrInfo) { | 863           if (!lpAttrInfo) { | 
| 865             continue; | 864             continue; | 
| 866           } | 865           } | 
| 867           if (!bUseAttribute && lpAttrInfo->eName != XFA_ATTRIBUTE_Name && | 866           if (!bUseAttribute && lpAttrInfo->eName != XFA_ATTRIBUTE_Name && | 
| 868               lpAttrInfo->eName != XFA_ATTRIBUTE_Save) { | 867               lpAttrInfo->eName != XFA_ATTRIBUTE_Save) { | 
| 869             continue; | 868             continue; | 
| 870           } | 869           } | 
| 871           pXFAChild->SetAttribute(lpAttrInfo->eName, | 870           pXFAChild->SetAttribute(lpAttrInfo->eName, wsAttrValue.AsStringC()); | 
| 872                                   wsAttrValue.AsWideStringC()); |  | 
| 873         } | 871         } | 
| 874         pXFANode->InsertChild(pXFAChild); | 872         pXFANode->InsertChild(pXFAChild); | 
| 875         if (pElemInfo->eName == XFA_ELEMENT_Validate || | 873         if (pElemInfo->eName == XFA_ELEMENT_Validate || | 
| 876             pElemInfo->eName == XFA_ELEMENT_Locale) { | 874             pElemInfo->eName == XFA_ELEMENT_Locale) { | 
| 877           if (ePacketID == XFA_XDPPACKET_Config) { | 875           if (ePacketID == XFA_XDPPACKET_Config) { | 
| 878             ParseContentNode(pXFAChild, pXMLElement, ePacketID); | 876             ParseContentNode(pXFAChild, pXMLElement, ePacketID); | 
| 879           } else { | 877           } else { | 
| 880             NormalLoader(pXFAChild, pXMLElement, ePacketID, bUseAttribute); | 878             NormalLoader(pXFAChild, pXMLElement, ePacketID, bUseAttribute); | 
| 881           } | 879           } | 
| 882           break; | 880           break; | 
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1105         FX_BOOL bNeedValue = TRUE; | 1103         FX_BOOL bNeedValue = TRUE; | 
| 1106         if (1) { | 1104         if (1) { | 
| 1107           for (int32_t i = 0, count = pXMLElement->CountAttributes(); i < count; | 1105           for (int32_t i = 0, count = pXMLElement->CountAttributes(); i < count; | 
| 1108                i++) { | 1106                i++) { | 
| 1109             CFX_WideString wsAttrQualifiedName; | 1107             CFX_WideString wsAttrQualifiedName; | 
| 1110             CFX_WideString wsAttrValue; | 1108             CFX_WideString wsAttrValue; | 
| 1111             CFX_WideString wsAttrName; | 1109             CFX_WideString wsAttrName; | 
| 1112             CFX_WideString wsAttrNamespaceURI; | 1110             CFX_WideString wsAttrNamespaceURI; | 
| 1113             pXMLElement->GetAttribute(i, wsAttrQualifiedName, wsAttrValue); | 1111             pXMLElement->GetAttribute(i, wsAttrQualifiedName, wsAttrValue); | 
| 1114             if (!XFA_FDEExtension_ResolveAttribute( | 1112             if (!XFA_FDEExtension_ResolveAttribute( | 
| 1115                     pXMLElement, wsAttrQualifiedName.AsWideStringC(), | 1113                     pXMLElement, wsAttrQualifiedName.AsStringC(), wsAttrName, | 
| 1116                     wsAttrName, wsAttrNamespaceURI)) { | 1114                     wsAttrNamespaceURI)) { | 
| 1117               continue; | 1115               continue; | 
| 1118             } | 1116             } | 
| 1119             if (wsAttrName == FX_WSTRC(L"nil") && | 1117             if (wsAttrName == FX_WSTRC(L"nil") && | 
| 1120                 wsAttrValue == FX_WSTRC(L"true")) { | 1118                 wsAttrValue == FX_WSTRC(L"true")) { | 
| 1121               bNeedValue = FALSE; | 1119               bNeedValue = FALSE; | 
| 1122               continue; | 1120               continue; | 
| 1123             } | 1121             } | 
| 1124             if (wsAttrNamespaceURI == | 1122             if (wsAttrNamespaceURI == | 
| 1125                     FX_WSTRC(L"http://www.xfa.com/schema/xfa-package/") || | 1123                     FX_WSTRC(L"http://www.xfa.com/schema/xfa-package/") || | 
| 1126                 wsAttrNamespaceURI == | 1124                 wsAttrNamespaceURI == | 
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1559     } | 1557     } | 
| 1560     if (pPause && iCount > 500 && pPause->NeedToPauseNow()) { | 1558     if (pPause && iCount > 500 && pPause->NeedToPauseNow()) { | 
| 1561       break; | 1559       break; | 
| 1562     } | 1560     } | 
| 1563   } | 1561   } | 
| 1564   return (m_syntaxParserResult == FDE_XmlSyntaxResult::Error || | 1562   return (m_syntaxParserResult == FDE_XmlSyntaxResult::Error || | 
| 1565           m_NodeStack.GetSize() != 1) | 1563           m_NodeStack.GetSize() != 1) | 
| 1566              ? -1 | 1564              ? -1 | 
| 1567              : m_pParser->GetStatus(); | 1565              : m_pParser->GetStatus(); | 
| 1568 } | 1566 } | 
| OLD | NEW | 
|---|