Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(820)

Unified Diff: xfa/src/fxfa/src/app/xfa_checksum.cpp

Issue 1636873004: XFA: Fix DOS newlines (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: All of them Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « xfa/src/fxfa/src/app/xfa_checksum.h ('k') | xfa/src/fxfa/src/app/xfa_ffConfigAcc.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: xfa/src/fxfa/src/app/xfa_checksum.cpp
diff --git a/xfa/src/fxfa/src/app/xfa_checksum.cpp b/xfa/src/fxfa/src/app/xfa_checksum.cpp
index 87c3cdbe250336927fe0e15afbf1ba16b822a967..a62f8a4b40ecac978d76001312ed11ca4b4ba615 100644
--- a/xfa/src/fxfa/src/app/xfa_checksum.cpp
+++ b/xfa/src/fxfa/src/app/xfa_checksum.cpp
@@ -1,188 +1,188 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "xfa/src/foxitlib.h"
-#include "xfa/src/fxfa/src/common/xfa_common.h"
-#include "xfa_checksum.h"
-CXFA_SAXReaderHandler::CXFA_SAXReaderHandler(CXFA_ChecksumContext* pContext)
- : m_pContext(pContext) {
- FXSYS_assert(m_pContext);
-}
-CXFA_SAXReaderHandler::~CXFA_SAXReaderHandler() {}
-void* CXFA_SAXReaderHandler::OnTagEnter(const CFX_ByteStringC& bsTagName,
- FX_SAXNODE eType,
- FX_DWORD dwStartPos) {
- UpdateChecksum(TRUE);
- if (eType != FX_SAXNODE_Tag && eType != FX_SAXNODE_Instruction) {
- return NULL;
- }
- m_SAXContext.m_eNode = eType;
- CFX_ByteTextBuf& textBuf = m_SAXContext.m_TextBuf;
- textBuf << "<";
- if (eType == FX_SAXNODE_Instruction) {
- textBuf << "?";
- }
- textBuf << bsTagName;
- m_SAXContext.m_bsTagName = bsTagName;
- return &m_SAXContext;
-}
-void CXFA_SAXReaderHandler::OnTagAttribute(void* pTag,
- const CFX_ByteStringC& bsAttri,
- const CFX_ByteStringC& bsValue) {
- if (pTag == NULL) {
- return;
- }
- CFX_ByteTextBuf& textBuf = ((CXFA_SAXContext*)pTag)->m_TextBuf;
- textBuf << " " << bsAttri << "=\"" << bsValue << "\"";
-}
-void CXFA_SAXReaderHandler::OnTagBreak(void* pTag) {
- if (pTag == NULL) {
- return;
- }
- CFX_ByteTextBuf& textBuf = ((CXFA_SAXContext*)pTag)->m_TextBuf;
- textBuf << ">";
- UpdateChecksum(FALSE);
-}
-void CXFA_SAXReaderHandler::OnTagData(void* pTag,
- FX_SAXNODE eType,
- const CFX_ByteStringC& bsData,
- FX_DWORD dwStartPos) {
- if (pTag == NULL) {
- return;
- }
- CFX_ByteTextBuf& textBuf = ((CXFA_SAXContext*)pTag)->m_TextBuf;
- if (eType == FX_SAXNODE_CharData) {
- textBuf << "<![CDATA[";
- }
- textBuf << bsData;
- if (eType == FX_SAXNODE_CharData) {
- textBuf << "]]>";
- }
-}
-void CXFA_SAXReaderHandler::OnTagClose(void* pTag, FX_DWORD dwEndPos) {
- if (pTag == NULL) {
- return;
- }
- CXFA_SAXContext* pSAXContext = (CXFA_SAXContext*)pTag;
- CFX_ByteTextBuf& textBuf = pSAXContext->m_TextBuf;
- if (pSAXContext->m_eNode == FX_SAXNODE_Instruction) {
- textBuf << "?>";
- } else if (pSAXContext->m_eNode == FX_SAXNODE_Tag) {
- textBuf << "></" << pSAXContext->m_bsTagName << ">";
- }
- UpdateChecksum(FALSE);
-}
-void CXFA_SAXReaderHandler::OnTagEnd(void* pTag,
- const CFX_ByteStringC& bsTagName,
- FX_DWORD dwEndPos) {
- if (pTag == NULL) {
- return;
- }
- CFX_ByteTextBuf& textBuf = ((CXFA_SAXContext*)pTag)->m_TextBuf;
- textBuf << "</" << bsTagName << ">";
- UpdateChecksum(FALSE);
-}
-void CXFA_SAXReaderHandler::OnTargetData(void* pTag,
- FX_SAXNODE eType,
- const CFX_ByteStringC& bsData,
- FX_DWORD dwStartPos) {
- if (pTag == NULL && eType != FX_SAXNODE_Comment) {
- return;
- }
- if (eType == FX_SAXNODE_Comment) {
- CFX_ByteTextBuf& textBuf = m_SAXContext.m_TextBuf;
- textBuf << "<!--" << bsData << "-->";
- UpdateChecksum(FALSE);
- } else {
- CFX_ByteTextBuf& textBuf = ((CXFA_SAXContext*)pTag)->m_TextBuf;
- textBuf << " " << bsData;
- }
-}
-void CXFA_SAXReaderHandler::UpdateChecksum(FX_BOOL bCheckSpace) {
- int32_t iLength = m_SAXContext.m_TextBuf.GetLength();
- if (iLength < 1) {
- return;
- }
- uint8_t* pBuffer = m_SAXContext.m_TextBuf.GetBuffer();
- FX_BOOL bUpdata = TRUE;
- if (bCheckSpace) {
- bUpdata = FALSE;
- for (int32_t i = 0; i < iLength; i++) {
- bUpdata = (pBuffer[i] > 0x20);
- if (bUpdata) {
- break;
- }
- }
- }
- if (bUpdata) {
- m_pContext->Update(CFX_ByteStringC(pBuffer, iLength));
- }
- m_SAXContext.m_TextBuf.Clear();
-}
-IXFA_ChecksumContext* XFA_Checksum_Create() {
- return new CXFA_ChecksumContext;
-}
-CXFA_ChecksumContext::CXFA_ChecksumContext()
- : m_pSAXReader(NULL), m_pByteContext(NULL) {}
-CXFA_ChecksumContext::~CXFA_ChecksumContext() {
- FinishChecksum();
-}
-FX_BOOL CXFA_ChecksumContext::StartChecksum() {
- FinishChecksum();
- m_pByteContext = FX_Alloc(uint8_t, 128);
- CRYPT_SHA1Start(m_pByteContext);
- m_bsChecksum.Empty();
- m_pSAXReader = FX_SAXReader_Create();
- return m_pSAXReader != NULL;
-}
-FX_BOOL CXFA_ChecksumContext::UpdateChecksum(IFX_FileRead* pSrcFile,
- FX_FILESIZE offset,
- size_t size) {
- if (m_pSAXReader == NULL) {
- return FALSE;
- }
- if (pSrcFile == NULL) {
- return FALSE;
- }
- if (size < 1) {
- size = pSrcFile->GetSize();
- }
- CXFA_SAXReaderHandler handler(this);
- m_pSAXReader->SetHandler(&handler);
- if (m_pSAXReader->StartParse(
- pSrcFile, (FX_DWORD)offset, (FX_DWORD)size,
- FX_SAXPARSEMODE_NotSkipSpace | FX_SAXPARSEMODE_NotConvert_amp |
- FX_SAXPARSEMODE_NotConvert_lt | FX_SAXPARSEMODE_NotConvert_gt |
- FX_SAXPARSEMODE_NotConvert_sharp) < 0) {
- return FALSE;
- }
- return m_pSAXReader->ContinueParse(NULL) > 99;
-}
-void CXFA_ChecksumContext::FinishChecksum() {
- if (m_pSAXReader != NULL) {
- m_pSAXReader->Release();
- m_pSAXReader = NULL;
- }
- if (m_pByteContext) {
- uint8_t digest[20];
- FXSYS_memset(digest, 0, 20);
- CRYPT_SHA1Finish(m_pByteContext, digest);
- int32_t nLen = FX_Base64EncodeA(digest, 20, NULL);
- FX_CHAR* pBuffer = m_bsChecksum.GetBuffer(nLen);
- FX_Base64EncodeA(digest, 20, pBuffer);
- m_bsChecksum.ReleaseBuffer(nLen);
- FX_Free(m_pByteContext);
- m_pByteContext = NULL;
- }
-}
-void CXFA_ChecksumContext::GetChecksum(CFX_ByteString& bsChecksum) {
- bsChecksum = m_bsChecksum;
-}
-void CXFA_ChecksumContext::Update(const CFX_ByteStringC& bsText) {
- if (m_pByteContext != NULL) {
- CRYPT_SHA1Update(m_pByteContext, bsText.GetPtr(), bsText.GetLength());
- }
-}
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "xfa/src/foxitlib.h"
+#include "xfa/src/fxfa/src/common/xfa_common.h"
+#include "xfa_checksum.h"
+CXFA_SAXReaderHandler::CXFA_SAXReaderHandler(CXFA_ChecksumContext* pContext)
+ : m_pContext(pContext) {
+ FXSYS_assert(m_pContext);
+}
+CXFA_SAXReaderHandler::~CXFA_SAXReaderHandler() {}
+void* CXFA_SAXReaderHandler::OnTagEnter(const CFX_ByteStringC& bsTagName,
+ FX_SAXNODE eType,
+ FX_DWORD dwStartPos) {
+ UpdateChecksum(TRUE);
+ if (eType != FX_SAXNODE_Tag && eType != FX_SAXNODE_Instruction) {
+ return NULL;
+ }
+ m_SAXContext.m_eNode = eType;
+ CFX_ByteTextBuf& textBuf = m_SAXContext.m_TextBuf;
+ textBuf << "<";
+ if (eType == FX_SAXNODE_Instruction) {
+ textBuf << "?";
+ }
+ textBuf << bsTagName;
+ m_SAXContext.m_bsTagName = bsTagName;
+ return &m_SAXContext;
+}
+void CXFA_SAXReaderHandler::OnTagAttribute(void* pTag,
+ const CFX_ByteStringC& bsAttri,
+ const CFX_ByteStringC& bsValue) {
+ if (pTag == NULL) {
+ return;
+ }
+ CFX_ByteTextBuf& textBuf = ((CXFA_SAXContext*)pTag)->m_TextBuf;
+ textBuf << " " << bsAttri << "=\"" << bsValue << "\"";
+}
+void CXFA_SAXReaderHandler::OnTagBreak(void* pTag) {
+ if (pTag == NULL) {
+ return;
+ }
+ CFX_ByteTextBuf& textBuf = ((CXFA_SAXContext*)pTag)->m_TextBuf;
+ textBuf << ">";
+ UpdateChecksum(FALSE);
+}
+void CXFA_SAXReaderHandler::OnTagData(void* pTag,
+ FX_SAXNODE eType,
+ const CFX_ByteStringC& bsData,
+ FX_DWORD dwStartPos) {
+ if (pTag == NULL) {
+ return;
+ }
+ CFX_ByteTextBuf& textBuf = ((CXFA_SAXContext*)pTag)->m_TextBuf;
+ if (eType == FX_SAXNODE_CharData) {
+ textBuf << "<![CDATA[";
+ }
+ textBuf << bsData;
+ if (eType == FX_SAXNODE_CharData) {
+ textBuf << "]]>";
+ }
+}
+void CXFA_SAXReaderHandler::OnTagClose(void* pTag, FX_DWORD dwEndPos) {
+ if (pTag == NULL) {
+ return;
+ }
+ CXFA_SAXContext* pSAXContext = (CXFA_SAXContext*)pTag;
+ CFX_ByteTextBuf& textBuf = pSAXContext->m_TextBuf;
+ if (pSAXContext->m_eNode == FX_SAXNODE_Instruction) {
+ textBuf << "?>";
+ } else if (pSAXContext->m_eNode == FX_SAXNODE_Tag) {
+ textBuf << "></" << pSAXContext->m_bsTagName << ">";
+ }
+ UpdateChecksum(FALSE);
+}
+void CXFA_SAXReaderHandler::OnTagEnd(void* pTag,
+ const CFX_ByteStringC& bsTagName,
+ FX_DWORD dwEndPos) {
+ if (pTag == NULL) {
+ return;
+ }
+ CFX_ByteTextBuf& textBuf = ((CXFA_SAXContext*)pTag)->m_TextBuf;
+ textBuf << "</" << bsTagName << ">";
+ UpdateChecksum(FALSE);
+}
+void CXFA_SAXReaderHandler::OnTargetData(void* pTag,
+ FX_SAXNODE eType,
+ const CFX_ByteStringC& bsData,
+ FX_DWORD dwStartPos) {
+ if (pTag == NULL && eType != FX_SAXNODE_Comment) {
+ return;
+ }
+ if (eType == FX_SAXNODE_Comment) {
+ CFX_ByteTextBuf& textBuf = m_SAXContext.m_TextBuf;
+ textBuf << "<!--" << bsData << "-->";
+ UpdateChecksum(FALSE);
+ } else {
+ CFX_ByteTextBuf& textBuf = ((CXFA_SAXContext*)pTag)->m_TextBuf;
+ textBuf << " " << bsData;
+ }
+}
+void CXFA_SAXReaderHandler::UpdateChecksum(FX_BOOL bCheckSpace) {
+ int32_t iLength = m_SAXContext.m_TextBuf.GetLength();
+ if (iLength < 1) {
+ return;
+ }
+ uint8_t* pBuffer = m_SAXContext.m_TextBuf.GetBuffer();
+ FX_BOOL bUpdata = TRUE;
+ if (bCheckSpace) {
+ bUpdata = FALSE;
+ for (int32_t i = 0; i < iLength; i++) {
+ bUpdata = (pBuffer[i] > 0x20);
+ if (bUpdata) {
+ break;
+ }
+ }
+ }
+ if (bUpdata) {
+ m_pContext->Update(CFX_ByteStringC(pBuffer, iLength));
+ }
+ m_SAXContext.m_TextBuf.Clear();
+}
+IXFA_ChecksumContext* XFA_Checksum_Create() {
+ return new CXFA_ChecksumContext;
+}
+CXFA_ChecksumContext::CXFA_ChecksumContext()
+ : m_pSAXReader(NULL), m_pByteContext(NULL) {}
+CXFA_ChecksumContext::~CXFA_ChecksumContext() {
+ FinishChecksum();
+}
+FX_BOOL CXFA_ChecksumContext::StartChecksum() {
+ FinishChecksum();
+ m_pByteContext = FX_Alloc(uint8_t, 128);
+ CRYPT_SHA1Start(m_pByteContext);
+ m_bsChecksum.Empty();
+ m_pSAXReader = FX_SAXReader_Create();
+ return m_pSAXReader != NULL;
+}
+FX_BOOL CXFA_ChecksumContext::UpdateChecksum(IFX_FileRead* pSrcFile,
+ FX_FILESIZE offset,
+ size_t size) {
+ if (m_pSAXReader == NULL) {
+ return FALSE;
+ }
+ if (pSrcFile == NULL) {
+ return FALSE;
+ }
+ if (size < 1) {
+ size = pSrcFile->GetSize();
+ }
+ CXFA_SAXReaderHandler handler(this);
+ m_pSAXReader->SetHandler(&handler);
+ if (m_pSAXReader->StartParse(
+ pSrcFile, (FX_DWORD)offset, (FX_DWORD)size,
+ FX_SAXPARSEMODE_NotSkipSpace | FX_SAXPARSEMODE_NotConvert_amp |
+ FX_SAXPARSEMODE_NotConvert_lt | FX_SAXPARSEMODE_NotConvert_gt |
+ FX_SAXPARSEMODE_NotConvert_sharp) < 0) {
+ return FALSE;
+ }
+ return m_pSAXReader->ContinueParse(NULL) > 99;
+}
+void CXFA_ChecksumContext::FinishChecksum() {
+ if (m_pSAXReader != NULL) {
+ m_pSAXReader->Release();
+ m_pSAXReader = NULL;
+ }
+ if (m_pByteContext) {
+ uint8_t digest[20];
+ FXSYS_memset(digest, 0, 20);
+ CRYPT_SHA1Finish(m_pByteContext, digest);
+ int32_t nLen = FX_Base64EncodeA(digest, 20, NULL);
+ FX_CHAR* pBuffer = m_bsChecksum.GetBuffer(nLen);
+ FX_Base64EncodeA(digest, 20, pBuffer);
+ m_bsChecksum.ReleaseBuffer(nLen);
+ FX_Free(m_pByteContext);
+ m_pByteContext = NULL;
+ }
+}
+void CXFA_ChecksumContext::GetChecksum(CFX_ByteString& bsChecksum) {
+ bsChecksum = m_bsChecksum;
+}
+void CXFA_ChecksumContext::Update(const CFX_ByteStringC& bsText) {
+ if (m_pByteContext != NULL) {
+ CRYPT_SHA1Update(m_pByteContext, bsText.GetPtr(), bsText.GetLength());
+ }
+}
« no previous file with comments | « xfa/src/fxfa/src/app/xfa_checksum.h ('k') | xfa/src/fxfa/src/app/xfa_ffConfigAcc.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698