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/include/xfa_checksum.h" | 7 #include "xfa/fxfa/include/xfa_checksum.h" |
8 | 8 |
9 #include "core/fdrm/crypto/include/fx_crypt.h" | 9 #include "core/fdrm/crypto/include/fx_crypt.h" |
10 #include "xfa/fgas/crt/fgas_algorithm.h" | 10 #include "xfa/fgas/crt/fgas_algorithm.h" |
11 | 11 |
12 CXFA_SAXReaderHandler::CXFA_SAXReaderHandler(CXFA_ChecksumContext* pContext) | 12 CXFA_SAXReaderHandler::CXFA_SAXReaderHandler(CXFA_ChecksumContext* pContext) |
13 : m_pContext(pContext) { | 13 : m_pContext(pContext) { |
14 ASSERT(m_pContext); | 14 ASSERT(m_pContext); |
15 } | 15 } |
16 CXFA_SAXReaderHandler::~CXFA_SAXReaderHandler() {} | 16 CXFA_SAXReaderHandler::~CXFA_SAXReaderHandler() {} |
17 void* CXFA_SAXReaderHandler::OnTagEnter(const CFX_ByteStringC& bsTagName, | 17 void* CXFA_SAXReaderHandler::OnTagEnter(const CFX_ByteStringC& bsTagName, |
18 FX_SAXNODE eType, | 18 CFX_SaxNode eType, |
19 uint32_t dwStartPos) { | 19 uint32_t dwStartPos) { |
20 UpdateChecksum(TRUE); | 20 UpdateChecksum(TRUE); |
21 if (eType != FX_SAXNODE_Tag && eType != FX_SAXNODE_Instruction) { | 21 if (eType != CFX_SaxNode::Tag && eType != CFX_SaxNode::Instruction) { |
22 return NULL; | 22 return NULL; |
23 } | 23 } |
24 m_SAXContext.m_eNode = eType; | 24 m_SAXContext.m_eNode = eType; |
25 CFX_ByteTextBuf& textBuf = m_SAXContext.m_TextBuf; | 25 CFX_ByteTextBuf& textBuf = m_SAXContext.m_TextBuf; |
26 textBuf << "<"; | 26 textBuf << "<"; |
27 if (eType == FX_SAXNODE_Instruction) { | 27 if (eType == CFX_SaxNode::Instruction) { |
28 textBuf << "?"; | 28 textBuf << "?"; |
29 } | 29 } |
30 textBuf << bsTagName; | 30 textBuf << bsTagName; |
31 m_SAXContext.m_bsTagName = bsTagName; | 31 m_SAXContext.m_bsTagName = bsTagName; |
32 return &m_SAXContext; | 32 return &m_SAXContext; |
33 } | 33 } |
34 void CXFA_SAXReaderHandler::OnTagAttribute(void* pTag, | 34 void CXFA_SAXReaderHandler::OnTagAttribute(void* pTag, |
35 const CFX_ByteStringC& bsAttri, | 35 const CFX_ByteStringC& bsAttri, |
36 const CFX_ByteStringC& bsValue) { | 36 const CFX_ByteStringC& bsValue) { |
37 if (pTag == NULL) { | 37 if (pTag == NULL) { |
38 return; | 38 return; |
39 } | 39 } |
40 CFX_ByteTextBuf& textBuf = ((CXFA_SAXContext*)pTag)->m_TextBuf; | 40 CFX_ByteTextBuf& textBuf = ((CXFA_SAXContext*)pTag)->m_TextBuf; |
41 textBuf << " " << bsAttri << "=\"" << bsValue << "\""; | 41 textBuf << " " << bsAttri << "=\"" << bsValue << "\""; |
42 } | 42 } |
43 void CXFA_SAXReaderHandler::OnTagBreak(void* pTag) { | 43 void CXFA_SAXReaderHandler::OnTagBreak(void* pTag) { |
44 if (pTag == NULL) { | 44 if (pTag == NULL) { |
45 return; | 45 return; |
46 } | 46 } |
47 CFX_ByteTextBuf& textBuf = ((CXFA_SAXContext*)pTag)->m_TextBuf; | 47 CFX_ByteTextBuf& textBuf = ((CXFA_SAXContext*)pTag)->m_TextBuf; |
48 textBuf << ">"; | 48 textBuf << ">"; |
49 UpdateChecksum(FALSE); | 49 UpdateChecksum(FALSE); |
50 } | 50 } |
51 void CXFA_SAXReaderHandler::OnTagData(void* pTag, | 51 void CXFA_SAXReaderHandler::OnTagData(void* pTag, |
52 FX_SAXNODE eType, | 52 CFX_SaxNode eType, |
53 const CFX_ByteStringC& bsData, | 53 const CFX_ByteStringC& bsData, |
54 uint32_t dwStartPos) { | 54 uint32_t dwStartPos) { |
55 if (pTag == NULL) { | 55 if (pTag == NULL) { |
56 return; | 56 return; |
57 } | 57 } |
58 CFX_ByteTextBuf& textBuf = ((CXFA_SAXContext*)pTag)->m_TextBuf; | 58 CFX_ByteTextBuf& textBuf = ((CXFA_SAXContext*)pTag)->m_TextBuf; |
59 if (eType == FX_SAXNODE_CharData) { | 59 if (eType == CFX_SaxNode::CharData) { |
60 textBuf << "<![CDATA["; | 60 textBuf << "<![CDATA["; |
61 } | 61 } |
62 textBuf << bsData; | 62 textBuf << bsData; |
63 if (eType == FX_SAXNODE_CharData) { | 63 if (eType == CFX_SaxNode::CharData) { |
64 textBuf << "]]>"; | 64 textBuf << "]]>"; |
65 } | 65 } |
66 } | 66 } |
67 void CXFA_SAXReaderHandler::OnTagClose(void* pTag, uint32_t dwEndPos) { | 67 void CXFA_SAXReaderHandler::OnTagClose(void* pTag, uint32_t dwEndPos) { |
68 if (pTag == NULL) { | 68 if (pTag == NULL) { |
69 return; | 69 return; |
70 } | 70 } |
71 CXFA_SAXContext* pSAXContext = (CXFA_SAXContext*)pTag; | 71 CXFA_SAXContext* pSAXContext = (CXFA_SAXContext*)pTag; |
72 CFX_ByteTextBuf& textBuf = pSAXContext->m_TextBuf; | 72 CFX_ByteTextBuf& textBuf = pSAXContext->m_TextBuf; |
73 if (pSAXContext->m_eNode == FX_SAXNODE_Instruction) { | 73 if (pSAXContext->m_eNode == CFX_SaxNode::Instruction) { |
74 textBuf << "?>"; | 74 textBuf << "?>"; |
75 } else if (pSAXContext->m_eNode == FX_SAXNODE_Tag) { | 75 } else if (pSAXContext->m_eNode == CFX_SaxNode::Tag) { |
76 textBuf << "></" << pSAXContext->m_bsTagName.AsStringC() << ">"; | 76 textBuf << "></" << pSAXContext->m_bsTagName.AsStringC() << ">"; |
77 } | 77 } |
78 UpdateChecksum(FALSE); | 78 UpdateChecksum(FALSE); |
79 } | 79 } |
80 void CXFA_SAXReaderHandler::OnTagEnd(void* pTag, | 80 void CXFA_SAXReaderHandler::OnTagEnd(void* pTag, |
81 const CFX_ByteStringC& bsTagName, | 81 const CFX_ByteStringC& bsTagName, |
82 uint32_t dwEndPos) { | 82 uint32_t dwEndPos) { |
83 if (pTag == NULL) { | 83 if (pTag == NULL) { |
84 return; | 84 return; |
85 } | 85 } |
86 CFX_ByteTextBuf& textBuf = ((CXFA_SAXContext*)pTag)->m_TextBuf; | 86 CFX_ByteTextBuf& textBuf = ((CXFA_SAXContext*)pTag)->m_TextBuf; |
87 textBuf << "</" << bsTagName << ">"; | 87 textBuf << "</" << bsTagName << ">"; |
88 UpdateChecksum(FALSE); | 88 UpdateChecksum(FALSE); |
89 } | 89 } |
90 void CXFA_SAXReaderHandler::OnTargetData(void* pTag, | 90 void CXFA_SAXReaderHandler::OnTargetData(void* pTag, |
91 FX_SAXNODE eType, | 91 CFX_SaxNode eType, |
92 const CFX_ByteStringC& bsData, | 92 const CFX_ByteStringC& bsData, |
93 uint32_t dwStartPos) { | 93 uint32_t dwStartPos) { |
94 if (pTag == NULL && eType != FX_SAXNODE_Comment) { | 94 if (pTag == NULL && eType != CFX_SaxNode::Comment) { |
95 return; | 95 return; |
96 } | 96 } |
97 if (eType == FX_SAXNODE_Comment) { | 97 if (eType == CFX_SaxNode::Comment) { |
98 CFX_ByteTextBuf& textBuf = m_SAXContext.m_TextBuf; | 98 CFX_ByteTextBuf& textBuf = m_SAXContext.m_TextBuf; |
99 textBuf << "<!--" << bsData << "-->"; | 99 textBuf << "<!--" << bsData << "-->"; |
100 UpdateChecksum(FALSE); | 100 UpdateChecksum(FALSE); |
101 } else { | 101 } else { |
102 CFX_ByteTextBuf& textBuf = ((CXFA_SAXContext*)pTag)->m_TextBuf; | 102 CFX_ByteTextBuf& textBuf = ((CXFA_SAXContext*)pTag)->m_TextBuf; |
103 textBuf << " " << bsData; | 103 textBuf << " " << bsData; |
104 } | 104 } |
105 } | 105 } |
106 void CXFA_SAXReaderHandler::UpdateChecksum(FX_BOOL bCheckSpace) { | 106 void CXFA_SAXReaderHandler::UpdateChecksum(FX_BOOL bCheckSpace) { |
107 int32_t iLength = m_SAXContext.m_TextBuf.GetLength(); | 107 int32_t iLength = m_SAXContext.m_TextBuf.GetLength(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 size_t size) { | 145 size_t size) { |
146 if (!m_pSAXReader || !pSrcFile) | 146 if (!m_pSAXReader || !pSrcFile) |
147 return FALSE; | 147 return FALSE; |
148 if (size < 1) | 148 if (size < 1) |
149 size = pSrcFile->GetSize(); | 149 size = pSrcFile->GetSize(); |
150 | 150 |
151 CXFA_SAXReaderHandler handler(this); | 151 CXFA_SAXReaderHandler handler(this); |
152 m_pSAXReader->SetHandler(&handler); | 152 m_pSAXReader->SetHandler(&handler); |
153 if (m_pSAXReader->StartParse( | 153 if (m_pSAXReader->StartParse( |
154 pSrcFile, (uint32_t)offset, (uint32_t)size, | 154 pSrcFile, (uint32_t)offset, (uint32_t)size, |
155 FX_SAXPARSEMODE_NotSkipSpace | FX_SAXPARSEMODE_NotConvert_amp | | 155 CFX_SaxParseMode_NotSkipSpace | CFX_SaxParseMode_NotConvert_amp | |
156 FX_SAXPARSEMODE_NotConvert_lt | FX_SAXPARSEMODE_NotConvert_gt | | 156 CFX_SaxParseMode_NotConvert_lt | CFX_SaxParseMode_NotConvert_gt | |
157 FX_SAXPARSEMODE_NotConvert_sharp) < 0) { | 157 CFX_SaxParseMode_NotConvert_sharp) < 0) { |
158 return FALSE; | 158 return FALSE; |
159 } | 159 } |
160 return m_pSAXReader->ContinueParse(NULL) > 99; | 160 return m_pSAXReader->ContinueParse(NULL) > 99; |
161 } | 161 } |
162 | 162 |
163 void CXFA_ChecksumContext::FinishChecksum() { | 163 void CXFA_ChecksumContext::FinishChecksum() { |
164 if (m_pSAXReader) { | 164 if (m_pSAXReader) { |
165 m_pSAXReader->Release(); | 165 m_pSAXReader->Release(); |
166 m_pSAXReader = NULL; | 166 m_pSAXReader = NULL; |
167 } | 167 } |
(...skipping 10 matching lines...) Expand all Loading... |
178 } | 178 } |
179 } | 179 } |
180 void CXFA_ChecksumContext::GetChecksum(CFX_ByteString& bsChecksum) { | 180 void CXFA_ChecksumContext::GetChecksum(CFX_ByteString& bsChecksum) { |
181 bsChecksum = m_bsChecksum; | 181 bsChecksum = m_bsChecksum; |
182 } | 182 } |
183 void CXFA_ChecksumContext::Update(const CFX_ByteStringC& bsText) { | 183 void CXFA_ChecksumContext::Update(const CFX_ByteStringC& bsText) { |
184 if (m_pByteContext) { | 184 if (m_pByteContext) { |
185 CRYPT_SHA1Update(m_pByteContext, bsText.raw_str(), bsText.GetLength()); | 185 CRYPT_SHA1Update(m_pByteContext, bsText.raw_str(), bsText.GetLength()); |
186 } | 186 } |
187 } | 187 } |
OLD | NEW |