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/fde/xml/fde_xml_imp.h" | 7 #include "xfa/fde/xml/fde_xml_imp.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 1084 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1095 m_ws1(), | 1095 m_ws1(), |
1096 m_ws2() { | 1096 m_ws2() { |
1097 m_NodeStack.Push(m_pParent); | 1097 m_NodeStack.Push(m_pParent); |
1098 } | 1098 } |
1099 CFDE_XMLDOMParser::~CFDE_XMLDOMParser() { | 1099 CFDE_XMLDOMParser::~CFDE_XMLDOMParser() { |
1100 m_NodeStack.RemoveAll(); | 1100 m_NodeStack.RemoveAll(); |
1101 m_ws1.Empty(); | 1101 m_ws1.Empty(); |
1102 m_ws2.Empty(); | 1102 m_ws2.Empty(); |
1103 } | 1103 } |
1104 int32_t CFDE_XMLDOMParser::DoParser(IFX_Pause* pPause) { | 1104 int32_t CFDE_XMLDOMParser::DoParser(IFX_Pause* pPause) { |
1105 FX_DWORD dwRet; | 1105 uint32_t dwRet; |
1106 int32_t iCount = 0; | 1106 int32_t iCount = 0; |
1107 while (TRUE) { | 1107 while (TRUE) { |
1108 dwRet = m_pParser->DoSyntaxParse(); | 1108 dwRet = m_pParser->DoSyntaxParse(); |
1109 switch (dwRet) { | 1109 switch (dwRet) { |
1110 case FDE_XMLSYNTAXSTATUS_InstructionOpen: | 1110 case FDE_XMLSYNTAXSTATUS_InstructionOpen: |
1111 break; | 1111 break; |
1112 case FDE_XMLSYNTAXSTATUS_InstructionClose: | 1112 case FDE_XMLSYNTAXSTATUS_InstructionClose: |
1113 if (m_pChild->GetType() != FDE_XMLNODE_Instruction) { | 1113 if (m_pChild->GetType() != FDE_XMLNODE_Instruction) { |
1114 dwRet = FDE_XMLSYNTAXSTATUS_Error; | 1114 dwRet = FDE_XMLSYNTAXSTATUS_Error; |
1115 break; | 1115 break; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1213 m_TagStack(16), | 1213 m_TagStack(16), |
1214 m_pTagTop(NULL), | 1214 m_pTagTop(NULL), |
1215 m_ws1(), | 1215 m_ws1(), |
1216 m_ws2() {} | 1216 m_ws2() {} |
1217 CFDE_XMLSAXParser::~CFDE_XMLSAXParser() { | 1217 CFDE_XMLSAXParser::~CFDE_XMLSAXParser() { |
1218 m_TagStack.RemoveAll(); | 1218 m_TagStack.RemoveAll(); |
1219 m_ws1.Empty(); | 1219 m_ws1.Empty(); |
1220 m_ws2.Empty(); | 1220 m_ws2.Empty(); |
1221 } | 1221 } |
1222 int32_t CFDE_XMLSAXParser::DoParser(IFX_Pause* pPause) { | 1222 int32_t CFDE_XMLSAXParser::DoParser(IFX_Pause* pPause) { |
1223 FX_DWORD dwRet = 0; | 1223 uint32_t dwRet = 0; |
1224 int32_t iCount = 0; | 1224 int32_t iCount = 0; |
1225 while (TRUE) { | 1225 while (TRUE) { |
1226 dwRet = m_pParser->DoSyntaxParse(); | 1226 dwRet = m_pParser->DoSyntaxParse(); |
1227 switch (dwRet) { | 1227 switch (dwRet) { |
1228 case FDE_XMLSYNTAXSTATUS_ElementBreak: | 1228 case FDE_XMLSYNTAXSTATUS_ElementBreak: |
1229 if (m_pTagTop == NULL) { | 1229 if (m_pTagTop == NULL) { |
1230 dwRet = FDE_XMLSYNTAXSTATUS_Error; | 1230 dwRet = FDE_XMLSYNTAXSTATUS_Error; |
1231 break; | 1231 break; |
1232 } | 1232 } |
1233 if (m_pTagTop->eType == FDE_XMLNODE_Element) { | 1233 if (m_pTagTop->eType == FDE_XMLNODE_Element) { |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1492 m_iCurrentPos = m_pStream->GetBOM(bom); | 1492 m_iCurrentPos = m_pStream->GetBOM(bom); |
1493 FXSYS_assert(m_pBuffer == NULL); | 1493 FXSYS_assert(m_pBuffer == NULL); |
1494 m_pBuffer = FX_Alloc(FX_WCHAR, m_iXMLPlaneSize); | 1494 m_pBuffer = FX_Alloc(FX_WCHAR, m_iXMLPlaneSize); |
1495 m_pStart = m_pEnd = m_pBuffer; | 1495 m_pStart = m_pEnd = m_pBuffer; |
1496 FXSYS_assert(!m_BlockBuffer.IsInitialized()); | 1496 FXSYS_assert(!m_BlockBuffer.IsInitialized()); |
1497 m_BlockBuffer.InitBuffer(); | 1497 m_BlockBuffer.InitBuffer(); |
1498 m_pCurrentBlock = m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); | 1498 m_pCurrentBlock = m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); |
1499 m_iParsedBytes = m_iParsedChars = 0; | 1499 m_iParsedBytes = m_iParsedChars = 0; |
1500 m_iBufferChars = 0; | 1500 m_iBufferChars = 0; |
1501 } | 1501 } |
1502 FX_DWORD CFDE_XMLSyntaxParser::DoSyntaxParse() { | 1502 uint32_t CFDE_XMLSyntaxParser::DoSyntaxParse() { |
1503 if (m_dwStatus == FDE_XMLSYNTAXSTATUS_Error || | 1503 if (m_dwStatus == FDE_XMLSYNTAXSTATUS_Error || |
1504 m_dwStatus == FDE_XMLSYNTAXSTATUS_EOS) { | 1504 m_dwStatus == FDE_XMLSYNTAXSTATUS_EOS) { |
1505 return m_dwStatus; | 1505 return m_dwStatus; |
1506 } | 1506 } |
1507 FXSYS_assert(m_pStream && m_pBuffer && m_BlockBuffer.IsInitialized()); | 1507 FXSYS_assert(m_pStream && m_pBuffer && m_BlockBuffer.IsInitialized()); |
1508 int32_t iStreamLength = m_pStream->GetLength(); | 1508 int32_t iStreamLength = m_pStream->GetLength(); |
1509 int32_t iPos; | 1509 int32_t iPos; |
1510 FX_WCHAR ch; | 1510 FX_WCHAR ch; |
1511 FX_DWORD dwStatus = FDE_XMLSYNTAXSTATUS_None; | 1511 uint32_t dwStatus = FDE_XMLSYNTAXSTATUS_None; |
1512 while (TRUE) { | 1512 while (TRUE) { |
1513 if (m_pStart >= m_pEnd) { | 1513 if (m_pStart >= m_pEnd) { |
1514 if (m_bEOS || m_iCurrentPos >= iStreamLength) { | 1514 if (m_bEOS || m_iCurrentPos >= iStreamLength) { |
1515 m_dwStatus = FDE_XMLSYNTAXSTATUS_EOS; | 1515 m_dwStatus = FDE_XMLSYNTAXSTATUS_EOS; |
1516 return m_dwStatus; | 1516 return m_dwStatus; |
1517 } | 1517 } |
1518 m_iParsedChars += (m_pEnd - m_pBuffer); | 1518 m_iParsedChars += (m_pEnd - m_pBuffer); |
1519 m_iParsedBytes = m_iCurrentPos; | 1519 m_iParsedBytes = m_iCurrentPos; |
1520 if (m_pStream->GetPosition() != m_iCurrentPos) { | 1520 if (m_pStream->GetPosition() != m_iCurrentPos) { |
1521 m_pStream->Seek(FX_STREAMSEEK_Begin, m_iCurrentPos); | 1521 m_pStream->Seek(FX_STREAMSEEK_Begin, m_iCurrentPos); |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1807 m_SkipStack.Push(L'>'); | 1807 m_SkipStack.Push(L'>'); |
1808 } | 1808 } |
1809 break; | 1809 break; |
1810 case FDE_XMLSYNTAXMODE_SkipDeclNode: | 1810 case FDE_XMLSYNTAXMODE_SkipDeclNode: |
1811 if (m_SkipChar == L'\'' || m_SkipChar == L'\"') { | 1811 if (m_SkipChar == L'\'' || m_SkipChar == L'\"') { |
1812 m_pStart++; | 1812 m_pStart++; |
1813 if (ch != m_SkipChar) { | 1813 if (ch != m_SkipChar) { |
1814 break; | 1814 break; |
1815 } | 1815 } |
1816 m_SkipStack.Pop(); | 1816 m_SkipStack.Pop(); |
1817 FX_DWORD* pDWord = m_SkipStack.GetTopElement(); | 1817 uint32_t* pDWord = m_SkipStack.GetTopElement(); |
1818 if (pDWord == NULL) { | 1818 if (pDWord == NULL) { |
1819 m_dwMode = FDE_XMLSYNTAXMODE_Text; | 1819 m_dwMode = FDE_XMLSYNTAXMODE_Text; |
1820 } else { | 1820 } else { |
1821 m_SkipChar = (FX_WCHAR)*pDWord; | 1821 m_SkipChar = (FX_WCHAR)*pDWord; |
1822 } | 1822 } |
1823 } else { | 1823 } else { |
1824 switch (ch) { | 1824 switch (ch) { |
1825 case L'<': | 1825 case L'<': |
1826 m_SkipChar = L'>'; | 1826 m_SkipChar = L'>'; |
1827 m_SkipStack.Push(L'>'); | 1827 m_SkipStack.Push(L'>'); |
(...skipping 10 matching lines...) Expand all Loading... |
1838 m_SkipChar = L'\''; | 1838 m_SkipChar = L'\''; |
1839 m_SkipStack.Push(L'\''); | 1839 m_SkipStack.Push(L'\''); |
1840 break; | 1840 break; |
1841 case L'\"': | 1841 case L'\"': |
1842 m_SkipChar = L'\"'; | 1842 m_SkipChar = L'\"'; |
1843 m_SkipStack.Push(L'\"'); | 1843 m_SkipStack.Push(L'\"'); |
1844 break; | 1844 break; |
1845 default: | 1845 default: |
1846 if (ch == m_SkipChar) { | 1846 if (ch == m_SkipChar) { |
1847 m_SkipStack.Pop(); | 1847 m_SkipStack.Pop(); |
1848 FX_DWORD* pDWord = m_SkipStack.GetTopElement(); | 1848 uint32_t* pDWord = m_SkipStack.GetTopElement(); |
1849 if (pDWord == NULL) { | 1849 if (pDWord == NULL) { |
1850 if (m_iDataLength >= 9) { | 1850 if (m_iDataLength >= 9) { |
1851 CFX_WideString wsHeader; | 1851 CFX_WideString wsHeader; |
1852 m_BlockBuffer.GetTextData(wsHeader, 0, 7); | 1852 m_BlockBuffer.GetTextData(wsHeader, 0, 7); |
1853 if (wsHeader.Equal(FX_WSTRC(L"[CDATA["))) { | 1853 if (wsHeader.Equal(FX_WSTRC(L"[CDATA["))) { |
1854 CFX_WideString wsTailer; | 1854 CFX_WideString wsTailer; |
1855 m_BlockBuffer.GetTextData(wsTailer, m_iDataLength - 2, | 1855 m_BlockBuffer.GetTextData(wsTailer, m_iDataLength - 2, |
1856 2); | 1856 2); |
1857 if (wsTailer.Equal(FX_WSTRC(L"]]"))) { | 1857 if (wsTailer.Equal(FX_WSTRC(L"]]"))) { |
1858 m_BlockBuffer.DeleteTextChars(7, TRUE); | 1858 m_BlockBuffer.DeleteTextChars(7, TRUE); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1986 } | 1986 } |
1987 if (m_dwStatus == FDE_XMLSYNTAXSTATUS_Error) { | 1987 if (m_dwStatus == FDE_XMLSYNTAXSTATUS_Error) { |
1988 return -1; | 1988 return -1; |
1989 } | 1989 } |
1990 if (m_dwStatus == FDE_XMLSYNTAXSTATUS_EOS) { | 1990 if (m_dwStatus == FDE_XMLSYNTAXSTATUS_EOS) { |
1991 return 100; | 1991 return 100; |
1992 } | 1992 } |
1993 return m_iParsedBytes * 100 / iStreamLength; | 1993 return m_iParsedBytes * 100 / iStreamLength; |
1994 } | 1994 } |
1995 static int32_t FX_GetUTF8EncodeLength(const FX_WCHAR* pSrc, int32_t iSrcLen) { | 1995 static int32_t FX_GetUTF8EncodeLength(const FX_WCHAR* pSrc, int32_t iSrcLen) { |
1996 FX_DWORD unicode = 0; | 1996 uint32_t unicode = 0; |
1997 int32_t iDstNum = 0; | 1997 int32_t iDstNum = 0; |
1998 while (iSrcLen-- > 0) { | 1998 while (iSrcLen-- > 0) { |
1999 unicode = *pSrc++; | 1999 unicode = *pSrc++; |
2000 int nbytes = 0; | 2000 int nbytes = 0; |
2001 if ((FX_DWORD)unicode < 0x80) { | 2001 if ((uint32_t)unicode < 0x80) { |
2002 nbytes = 1; | 2002 nbytes = 1; |
2003 } else if ((FX_DWORD)unicode < 0x800) { | 2003 } else if ((uint32_t)unicode < 0x800) { |
2004 nbytes = 2; | 2004 nbytes = 2; |
2005 } else if ((FX_DWORD)unicode < 0x10000) { | 2005 } else if ((uint32_t)unicode < 0x10000) { |
2006 nbytes = 3; | 2006 nbytes = 3; |
2007 } else if ((FX_DWORD)unicode < 0x200000) { | 2007 } else if ((uint32_t)unicode < 0x200000) { |
2008 nbytes = 4; | 2008 nbytes = 4; |
2009 } else if ((FX_DWORD)unicode < 0x4000000) { | 2009 } else if ((uint32_t)unicode < 0x4000000) { |
2010 nbytes = 5; | 2010 nbytes = 5; |
2011 } else { | 2011 } else { |
2012 nbytes = 6; | 2012 nbytes = 6; |
2013 } | 2013 } |
2014 iDstNum += nbytes; | 2014 iDstNum += nbytes; |
2015 } | 2015 } |
2016 return iDstNum; | 2016 return iDstNum; |
2017 } | 2017 } |
2018 FX_FILESIZE CFDE_XMLSyntaxParser::GetCurrentBinaryPos() const { | 2018 FX_FILESIZE CFDE_XMLSyntaxParser::GetCurrentBinaryPos() const { |
2019 if (m_pStream == NULL) { | 2019 if (m_pStream == NULL) { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2090 m_BlockBuffer.DeleteTextChars(m_iDataLength - m_iEntityStart, FALSE); | 2090 m_BlockBuffer.DeleteTextChars(m_iDataLength - m_iEntityStart, FALSE); |
2091 m_pCurrentBlock = m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); | 2091 m_pCurrentBlock = m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); |
2092 m_iEntityStart = -1; | 2092 m_iEntityStart = -1; |
2093 } else { | 2093 } else { |
2094 if (m_iEntityStart < 0 && ch == L'&') { | 2094 if (m_iEntityStart < 0 && ch == L'&') { |
2095 m_iEntityStart = m_iDataLength - 1; | 2095 m_iEntityStart = m_iDataLength - 1; |
2096 } | 2096 } |
2097 } | 2097 } |
2098 m_pStart++; | 2098 m_pStart++; |
2099 } | 2099 } |
OLD | NEW |