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/app/xfa_checksum.h" | 7 #include "xfa/fxfa/app/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 FXSYS_assert(m_pContext); | 14 FXSYS_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 FX_SAXNODE eType, |
19 FX_DWORD dwStartPos) { | 19 uint32_t dwStartPos) { |
20 UpdateChecksum(TRUE); | 20 UpdateChecksum(TRUE); |
21 if (eType != FX_SAXNODE_Tag && eType != FX_SAXNODE_Instruction) { | 21 if (eType != FX_SAXNODE_Tag && eType != FX_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 == FX_SAXNODE_Instruction) { |
28 textBuf << "?"; | 28 textBuf << "?"; |
29 } | 29 } |
(...skipping 14 matching lines...) Expand all Loading... |
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 FX_SAXNODE eType, |
53 const CFX_ByteStringC& bsData, | 53 const CFX_ByteStringC& bsData, |
54 FX_DWORD 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 == FX_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 == FX_SAXNODE_CharData) { |
64 textBuf << "]]>"; | 64 textBuf << "]]>"; |
65 } | 65 } |
66 } | 66 } |
67 void CXFA_SAXReaderHandler::OnTagClose(void* pTag, FX_DWORD 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 == FX_SAXNODE_Instruction) { |
74 textBuf << "?>"; | 74 textBuf << "?>"; |
75 } else if (pSAXContext->m_eNode == FX_SAXNODE_Tag) { | 75 } else if (pSAXContext->m_eNode == FX_SAXNODE_Tag) { |
76 textBuf << "></" << pSAXContext->m_bsTagName << ">"; | 76 textBuf << "></" << pSAXContext->m_bsTagName << ">"; |
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 FX_DWORD 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 FX_SAXNODE eType, |
92 const CFX_ByteStringC& bsData, | 92 const CFX_ByteStringC& bsData, |
93 FX_DWORD dwStartPos) { | 93 uint32_t dwStartPos) { |
94 if (pTag == NULL && eType != FX_SAXNODE_Comment) { | 94 if (pTag == NULL && eType != FX_SAXNODE_Comment) { |
95 return; | 95 return; |
96 } | 96 } |
97 if (eType == FX_SAXNODE_Comment) { | 97 if (eType == FX_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; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 } | 148 } |
149 if (pSrcFile == NULL) { | 149 if (pSrcFile == NULL) { |
150 return FALSE; | 150 return FALSE; |
151 } | 151 } |
152 if (size < 1) { | 152 if (size < 1) { |
153 size = pSrcFile->GetSize(); | 153 size = pSrcFile->GetSize(); |
154 } | 154 } |
155 CXFA_SAXReaderHandler handler(this); | 155 CXFA_SAXReaderHandler handler(this); |
156 m_pSAXReader->SetHandler(&handler); | 156 m_pSAXReader->SetHandler(&handler); |
157 if (m_pSAXReader->StartParse( | 157 if (m_pSAXReader->StartParse( |
158 pSrcFile, (FX_DWORD)offset, (FX_DWORD)size, | 158 pSrcFile, (uint32_t)offset, (uint32_t)size, |
159 FX_SAXPARSEMODE_NotSkipSpace | FX_SAXPARSEMODE_NotConvert_amp | | 159 FX_SAXPARSEMODE_NotSkipSpace | FX_SAXPARSEMODE_NotConvert_amp | |
160 FX_SAXPARSEMODE_NotConvert_lt | FX_SAXPARSEMODE_NotConvert_gt | | 160 FX_SAXPARSEMODE_NotConvert_lt | FX_SAXPARSEMODE_NotConvert_gt | |
161 FX_SAXPARSEMODE_NotConvert_sharp) < 0) { | 161 FX_SAXPARSEMODE_NotConvert_sharp) < 0) { |
162 return FALSE; | 162 return FALSE; |
163 } | 163 } |
164 return m_pSAXReader->ContinueParse(NULL) > 99; | 164 return m_pSAXReader->ContinueParse(NULL) > 99; |
165 } | 165 } |
166 void CXFA_ChecksumContext::FinishChecksum() { | 166 void CXFA_ChecksumContext::FinishChecksum() { |
167 if (m_pSAXReader) { | 167 if (m_pSAXReader) { |
168 m_pSAXReader->Release(); | 168 m_pSAXReader->Release(); |
(...skipping 12 matching lines...) Expand all Loading... |
181 } | 181 } |
182 } | 182 } |
183 void CXFA_ChecksumContext::GetChecksum(CFX_ByteString& bsChecksum) { | 183 void CXFA_ChecksumContext::GetChecksum(CFX_ByteString& bsChecksum) { |
184 bsChecksum = m_bsChecksum; | 184 bsChecksum = m_bsChecksum; |
185 } | 185 } |
186 void CXFA_ChecksumContext::Update(const CFX_ByteStringC& bsText) { | 186 void CXFA_ChecksumContext::Update(const CFX_ByteStringC& bsText) { |
187 if (m_pByteContext) { | 187 if (m_pByteContext) { |
188 CRYPT_SHA1Update(m_pByteContext, bsText.GetPtr(), bsText.GetLength()); | 188 CRYPT_SHA1Update(m_pByteContext, bsText.GetPtr(), bsText.GetLength()); |
189 } | 189 } |
190 } | 190 } |
OLD | NEW |