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/cfx_saxreader.h" | 7 #include "xfa/fde/xml/cfx_saxreader.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <utility> | 10 #include <utility> |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 } // namespace | 63 } // namespace |
64 | 64 |
65 CFX_SAXFile::CFX_SAXFile() | 65 CFX_SAXFile::CFX_SAXFile() |
66 : m_pFile(nullptr), | 66 : m_pFile(nullptr), |
67 m_dwStart(0), | 67 m_dwStart(0), |
68 m_dwEnd(0), | 68 m_dwEnd(0), |
69 m_dwCur(0), | 69 m_dwCur(0), |
70 m_pBuf(nullptr), | 70 m_pBuf(nullptr), |
71 m_dwBufSize(0), | 71 m_dwBufSize(0), |
72 m_dwBufIndex(0) {} | 72 m_dwBufIndex(0) {} |
73 FX_BOOL CFX_SAXFile::StartFile(IFX_SeekableReadStream* pFile, | 73 bool CFX_SAXFile::StartFile(IFX_SeekableReadStream* pFile, |
74 uint32_t dwStart, | 74 uint32_t dwStart, |
75 uint32_t dwLen) { | 75 uint32_t dwLen) { |
76 ASSERT(!m_pFile && pFile); | 76 ASSERT(!m_pFile && pFile); |
77 uint32_t dwSize = pFile->GetSize(); | 77 uint32_t dwSize = pFile->GetSize(); |
78 if (dwStart >= dwSize) { | 78 if (dwStart >= dwSize) { |
79 return FALSE; | 79 return false; |
80 } | 80 } |
81 if (dwLen == static_cast<uint32_t>(-1) || dwStart + dwLen > dwSize) { | 81 if (dwLen == static_cast<uint32_t>(-1) || dwStart + dwLen > dwSize) { |
82 dwLen = dwSize - dwStart; | 82 dwLen = dwSize - dwStart; |
83 } | 83 } |
84 if (dwLen == 0) { | 84 if (dwLen == 0) { |
85 return FALSE; | 85 return false; |
86 } | 86 } |
87 m_dwBufSize = std::min(dwLen, kSaxFileBufSize); | 87 m_dwBufSize = std::min(dwLen, kSaxFileBufSize); |
88 m_pBuf = FX_Alloc(uint8_t, m_dwBufSize); | 88 m_pBuf = FX_Alloc(uint8_t, m_dwBufSize); |
89 if (!pFile->ReadBlock(m_pBuf, dwStart, m_dwBufSize)) { | 89 if (!pFile->ReadBlock(m_pBuf, dwStart, m_dwBufSize)) { |
90 return FALSE; | 90 return false; |
91 } | 91 } |
92 m_dwStart = dwStart; | 92 m_dwStart = dwStart; |
93 m_dwEnd = dwStart + dwLen; | 93 m_dwEnd = dwStart + dwLen; |
94 m_dwCur = dwStart; | 94 m_dwCur = dwStart; |
95 m_pFile = pFile; | 95 m_pFile = pFile; |
96 m_dwBufIndex = 0; | 96 m_dwBufIndex = 0; |
97 return TRUE; | 97 return true; |
98 } | 98 } |
99 | 99 |
100 FX_BOOL CFX_SAXFile::ReadNextBlock() { | 100 bool CFX_SAXFile::ReadNextBlock() { |
101 ASSERT(m_pFile); | 101 ASSERT(m_pFile); |
102 uint32_t dwSize = m_dwEnd - m_dwCur; | 102 uint32_t dwSize = m_dwEnd - m_dwCur; |
103 if (dwSize == 0) { | 103 if (dwSize == 0) { |
104 return FALSE; | 104 return false; |
105 } | 105 } |
106 m_dwBufSize = std::min(dwSize, kSaxFileBufSize); | 106 m_dwBufSize = std::min(dwSize, kSaxFileBufSize); |
107 if (!m_pFile->ReadBlock(m_pBuf, m_dwCur, m_dwBufSize)) { | 107 if (!m_pFile->ReadBlock(m_pBuf, m_dwCur, m_dwBufSize)) { |
108 return FALSE; | 108 return false; |
109 } | 109 } |
110 m_dwBufIndex = 0; | 110 m_dwBufIndex = 0; |
111 return TRUE; | 111 return true; |
112 } | 112 } |
113 | 113 |
114 void CFX_SAXFile::Reset() { | 114 void CFX_SAXFile::Reset() { |
115 if (m_pBuf) { | 115 if (m_pBuf) { |
116 FX_Free(m_pBuf); | 116 FX_Free(m_pBuf); |
117 m_pBuf = nullptr; | 117 m_pBuf = nullptr; |
118 } | 118 } |
119 m_pFile = nullptr; | 119 m_pFile = nullptr; |
120 } | 120 } |
121 | 121 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 return; | 203 return; |
204 } | 204 } |
205 if (m_iNameSize <= 1024 * 1024) { | 205 if (m_iNameSize <= 1024 * 1024) { |
206 m_iNameSize *= 2; | 206 m_iNameSize *= 2; |
207 } else { | 207 } else { |
208 m_iNameSize += 1024 * 1024; | 208 m_iNameSize += 1024 * 1024; |
209 } | 209 } |
210 m_pszName = (uint8_t*)FX_Realloc(uint8_t, m_pszName, m_iNameSize); | 210 m_pszName = (uint8_t*)FX_Realloc(uint8_t, m_pszName, m_iNameSize); |
211 } | 211 } |
212 | 212 |
213 FX_BOOL CFX_SAXReader::SkipSpace(uint8_t ch) { | 213 bool CFX_SAXReader::SkipSpace(uint8_t ch) { |
214 return (m_dwParseMode & CFX_SaxParseMode_NotSkipSpace) == 0 && ch < 0x21; | 214 return (m_dwParseMode & CFX_SaxParseMode_NotSkipSpace) == 0 && ch < 0x21; |
215 } | 215 } |
216 | 216 |
217 int32_t CFX_SAXReader::StartParse(IFX_SeekableReadStream* pFile, | 217 int32_t CFX_SAXReader::StartParse(IFX_SeekableReadStream* pFile, |
218 uint32_t dwStart, | 218 uint32_t dwStart, |
219 uint32_t dwLen, | 219 uint32_t dwLen, |
220 uint32_t dwParseMode) { | 220 uint32_t dwParseMode) { |
221 m_iState = -1; | 221 m_iState = -1; |
222 Reset(); | 222 Reset(); |
223 if (!m_File.StartFile(pFile, dwStart, dwLen)) { | 223 if (!m_File.StartFile(pFile, dwStart, dwLen)) { |
224 return -1; | 224 return -1; |
225 } | 225 } |
226 m_iState = 0; | 226 m_iState = 0; |
227 m_eMode = CFX_SaxMode::Text; | 227 m_eMode = CFX_SaxMode::Text; |
228 m_ePrevMode = CFX_SaxMode::Text; | 228 m_ePrevMode = CFX_SaxMode::Text; |
229 m_bCharData = FALSE; | 229 m_bCharData = false; |
230 m_dwDataOffset = 0; | 230 m_dwDataOffset = 0; |
231 m_dwParseMode = dwParseMode; | 231 m_dwParseMode = dwParseMode; |
232 m_Stack.emplace(new CFX_SAXItem(++m_dwItemID)); | 232 m_Stack.emplace(new CFX_SAXItem(++m_dwItemID)); |
233 return 0; | 233 return 0; |
234 } | 234 } |
235 | 235 |
236 int32_t CFX_SAXReader::ContinueParse(IFX_Pause* pPause) { | 236 int32_t CFX_SAXReader::ContinueParse(IFX_Pause* pPause) { |
237 if (m_iState < 0 || m_iState > 99) { | 237 if (m_iState < 0 || m_iState > 99) { |
238 return m_iState; | 238 return m_iState; |
239 } | 239 } |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 m_iDataPos = 0; | 630 m_iDataPos = 0; |
631 if (m_iDataLength >= 9 && | 631 if (m_iDataLength >= 9 && |
632 FXSYS_memcmp(m_pszData, "[CDATA[", 7 * sizeof(uint8_t)) == 0 && | 632 FXSYS_memcmp(m_pszData, "[CDATA[", 7 * sizeof(uint8_t)) == 0 && |
633 FXSYS_memcmp(m_pszData + m_iDataLength - 2, "]]", | 633 FXSYS_memcmp(m_pszData + m_iDataLength - 2, "]]", |
634 2 * sizeof(uint8_t)) == 0) { | 634 2 * sizeof(uint8_t)) == 0) { |
635 Pop(); | 635 Pop(); |
636 m_iDataLength -= 9; | 636 m_iDataLength -= 9; |
637 m_dwDataOffset += 7; | 637 m_dwDataOffset += 7; |
638 FXSYS_memmove(m_pszData, m_pszData + 7, | 638 FXSYS_memmove(m_pszData, m_pszData + 7, |
639 m_iDataLength * sizeof(uint8_t)); | 639 m_iDataLength * sizeof(uint8_t)); |
640 m_bCharData = TRUE; | 640 m_bCharData = true; |
641 if (m_pHandler) { | 641 if (m_pHandler) { |
642 NotifyData(); | 642 NotifyData(); |
643 } | 643 } |
644 m_bCharData = FALSE; | 644 m_bCharData = false; |
645 } else { | 645 } else { |
646 Pop(); | 646 Pop(); |
647 } | 647 } |
648 m_eMode = CFX_SaxMode::Text; | 648 m_eMode = CFX_SaxMode::Text; |
649 } | 649 } |
650 } | 650 } |
651 break; | 651 break; |
652 } | 652 } |
653 if (iLen > 0) { | 653 if (iLen > 0) { |
654 ParseChar(m_CurByte); | 654 ParseChar(m_CurByte); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 CFX_ByteStringC(m_pszData, m_iDataLength), | 721 CFX_ByteStringC(m_pszData, m_iDataLength), |
722 m_dwNodePos); | 722 m_dwNodePos); |
723 } | 723 } |
724 } | 724 } |
725 | 725 |
726 void CFX_SAXReader::SkipCurrentNode() { | 726 void CFX_SAXReader::SkipCurrentNode() { |
727 CFX_SAXItem* pItem = GetCurrentItem(); | 727 CFX_SAXItem* pItem = GetCurrentItem(); |
728 if (!pItem) | 728 if (!pItem) |
729 return; | 729 return; |
730 | 730 |
731 pItem->m_bSkip = TRUE; | 731 pItem->m_bSkip = true; |
732 } | 732 } |
733 | 733 |
734 void CFX_SAXReader::SetHandler(CXFA_SAXReaderHandler* pHandler) { | 734 void CFX_SAXReader::SetHandler(CXFA_SAXReaderHandler* pHandler) { |
735 m_pHandler = pHandler; | 735 m_pHandler = pHandler; |
736 } | 736 } |
OLD | NEW |