mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-11 10:26:00 +08:00
Compare commits
25 Commits
core/devel
...
core/devel
| Author | SHA1 | Date | |
|---|---|---|---|
| 02238f7eea | |||
| 907e00a3ac | |||
| 2470bfd335 | |||
| 3ae52bd221 | |||
| 227d4f18d6 | |||
| 36bdbad685 | |||
| 525b828540 | |||
| f64ee80a1a | |||
| f6402813c4 | |||
| 224ac7d6e2 | |||
| 2e2bd8989d | |||
| 8f434efb95 | |||
| 244dafb02b | |||
| 149a1bdbd5 | |||
| a79d9041bc | |||
| 3954c42602 | |||
| 29dc0aee32 | |||
| d805972d6d | |||
| 549d5a46a6 | |||
| 771bf2d55c | |||
| 3c58cd96fc | |||
| e50864fa98 | |||
| ec4f4fe476 | |||
| 634509ae28 | |||
| 8197fb8900 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -20,6 +20,7 @@ Common/3dParty/v8/win_32
|
||||
Common/3dParty/v8/linux_64
|
||||
Common/3dParty/v8/linux_32
|
||||
Common/3dParty/v8/mac_64
|
||||
Common/3dParty/openssl/openssl
|
||||
**/core_build
|
||||
**/Release
|
||||
**/Debug
|
||||
|
||||
15
.travis.yml
15
.travis.yml
@ -1 +1,14 @@
|
||||
language: cpp
|
||||
language: cpp
|
||||
compiler: gcc
|
||||
dist: trusty
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- p7zip-full
|
||||
script:
|
||||
- exit 0
|
||||
# Build fails anyway. See explanation in
|
||||
# https://github.com/ONLYOFFICE/core/pull/29#issuecomment-306773327
|
||||
- cd Common/3dParty && ./make.sh
|
||||
- cd ../../
|
||||
- make
|
||||
@ -137,7 +137,7 @@ namespace PPTX
|
||||
pWriter->WriteLimit2(4, m_oDrawAspect);
|
||||
pWriter->WriteLimit2(5, m_oType);
|
||||
pWriter->WriteLimit2(6, m_oUpdateMode);
|
||||
if (ole_file.IsInit() == false || ole_file->isMsPackage() == false)
|
||||
if (ole_file.IsInit() && ole_file->isMsPackage() == false)
|
||||
{
|
||||
std::wstring sExt = ole_file->filename().GetExtention(false);
|
||||
if (!sExt.empty())
|
||||
|
||||
@ -189,8 +189,8 @@ namespace PPTX
|
||||
WritingElement_ReadAttributes_Read_else_if( oReader, _T("lvl"), lvl)
|
||||
WritingElement_ReadAttributes_Read_else_if( oReader, _T("algn"), algn)
|
||||
WritingElement_ReadAttributes_Read_else_if( oReader, _T("fontAlgn"),fontAlgn)
|
||||
WritingElement_ReadAttributes_Read_else_if( oReader, _T("marL"), marR)
|
||||
WritingElement_ReadAttributes_Read_else_if( oReader, _T("marR"), marL)
|
||||
WritingElement_ReadAttributes_Read_else_if( oReader, _T("marL"), marL)
|
||||
WritingElement_ReadAttributes_Read_else_if( oReader, _T("marR"), marR)
|
||||
WritingElement_ReadAttributes_Read_else_if( oReader, _T("indent"), indent)
|
||||
WritingElement_ReadAttributes_Read_else_if( oReader, _T("defTabSz"),defTabSz)
|
||||
WritingElement_ReadAttributes_End ( oReader )
|
||||
@ -541,4 +541,4 @@ namespace PPTX
|
||||
} // namespace Logic
|
||||
} // namespace PPTX
|
||||
|
||||
#endif // PPTX_LOGIC_TEXTPARAGRAPHPR_INCLUDE_H_
|
||||
#endif // PPTX_LOGIC_TEXTPARAGRAPHPR_INCLUDE_H_
|
||||
|
||||
@ -1,19 +1,21 @@
|
||||
SET SCRIPTPATH=%~dp0
|
||||
CD /D %~dp0
|
||||
SET PLATFORM=win
|
||||
SET ARCH=_32
|
||||
|
||||
SET PLATFORM=win_32
|
||||
if defined ProgramFiles(x86) (
|
||||
SET ARCH=_64
|
||||
SET PLATFORM=win_64
|
||||
)
|
||||
|
||||
mkdir "%SCRIPTPATH%%PLATFORM%%ARCH%"
|
||||
cd "%SCRIPTPATH%%PLATFORM%%ARCH%"
|
||||
if defined TARGET (
|
||||
SET PLATFORM=%TARGET%
|
||||
)
|
||||
|
||||
mkdir "%SCRIPTPATH%%PLATFORM%"
|
||||
cd "%SCRIPTPATH%%PLATFORM%"
|
||||
|
||||
if exist "cef_binary.7z" (
|
||||
echo "cef_binary.7z already downloaded"
|
||||
) else (
|
||||
Powershell.exe Invoke-WebRequest -OutFile cef_binary.7z http://d2ettrnqo7v976.cloudfront.net/cef/2454/%PLATFORM%%ARCH%/cef_binary.7z
|
||||
Powershell.exe Invoke-WebRequest -OutFile cef_binary.7z http://d2ettrnqo7v976.cloudfront.net/cef/2454/%PLATFORM%/cef_binary.7z
|
||||
)
|
||||
|
||||
SET UNSIP_PROGRAMM="%ProgramFiles%\7-Zip\7z.exe"
|
||||
|
||||
@ -6,6 +6,10 @@ if defined ProgramFiles(x86) (
|
||||
SET platform=win_64
|
||||
)
|
||||
|
||||
if defined TARGET (
|
||||
SET platform=%TARGET%
|
||||
)
|
||||
|
||||
if not exist "%platform%" (
|
||||
md "%platform%"
|
||||
)
|
||||
|
||||
12
Common/3dParty/openssl/build.sh
Normal file
12
Common/3dParty/openssl/build.sh
Normal file
@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
|
||||
export PATH=`pwd`/depot_tools:"$PATH"
|
||||
|
||||
SCRIPT=$(readlink -f "$0")
|
||||
SCRIPTPATH=$(dirname "$SCRIPT")
|
||||
|
||||
cd "$SCRIPTPATH"/openssl
|
||||
|
||||
perl ./Configure linux-64
|
||||
./config
|
||||
make
|
||||
8
Common/3dParty/openssl/fetch.sh
Normal file
8
Common/3dParty/openssl/fetch.sh
Normal file
@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
SCRIPT=$(readlink -f "$0")
|
||||
SCRIPTPATH=$(dirname "$SCRIPT")
|
||||
|
||||
cd "$SCRIPTPATH"
|
||||
|
||||
git clone https://github.com/openssl/openssl.git
|
||||
@ -158,7 +158,16 @@ namespace OOX
|
||||
else if ( pRelation->Type() == FileTypes::Document)
|
||||
return smart_ptr<OOX::File>(new CDocument( oRootPath, oFileName ));
|
||||
else if ( pRelation->Type() == FileTypes::Theme)
|
||||
return smart_ptr<OOX::File>(new PPTX::Theme( oFileName ));
|
||||
{
|
||||
if(NSFile::CFileBinary::Exists(oFileName.GetPath()))
|
||||
{
|
||||
return smart_ptr<OOX::File>(new PPTX::Theme( oFileName ));
|
||||
}
|
||||
else
|
||||
{
|
||||
return smart_ptr<OOX::File>( new UnknowTypeFile() );
|
||||
}
|
||||
}
|
||||
else if ( pRelation->Type() == FileTypes::ThemeOverride)
|
||||
return smart_ptr<OOX::File>(new PPTX::Theme( oFileName ));
|
||||
else if ( pRelation->Type() == FileTypes::Setting)
|
||||
|
||||
@ -1092,6 +1092,21 @@ namespace OOX
|
||||
et_x_SheetPr,
|
||||
et_x_Pane,
|
||||
et_x_ExternalBook,
|
||||
et_x_ExternalSheetNames,
|
||||
et_x_ExternalDefinedNames,
|
||||
et_x_ExternalDefinedName,
|
||||
et_x_ExternalSheetDataSet,
|
||||
et_x_ExternalSheetData,
|
||||
et_x_ExternalRow,
|
||||
et_x_ExternalCell,
|
||||
et_x_OleLink,
|
||||
et_x_OleItems,
|
||||
et_x_OleItem,
|
||||
et_x_DdeLink,
|
||||
et_x_DdeItems,
|
||||
et_x_DdeItem,
|
||||
et_x_DdeValues,
|
||||
et_x_DdeValue,
|
||||
et_x_Selection,
|
||||
et_x_LegacyDrawingWorksheet,
|
||||
et_x_LegacyDrawingHFWorksheet,
|
||||
|
||||
@ -68,7 +68,35 @@ namespace OOX
|
||||
return type().DefaultFileName();
|
||||
}
|
||||
};
|
||||
class ExternalOleObject : public External
|
||||
{
|
||||
public:
|
||||
ExternalOleObject()
|
||||
{
|
||||
}
|
||||
ExternalOleObject(const CPath& uri)
|
||||
{
|
||||
read(uri);
|
||||
}
|
||||
~ExternalOleObject()
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
virtual const FileType type() const
|
||||
{
|
||||
return OOX::FileTypes::OleObject;
|
||||
}
|
||||
virtual const CPath DefaultDirectory() const
|
||||
{
|
||||
return type().DefaultDirectory();
|
||||
}
|
||||
virtual const CPath DefaultFileName() const
|
||||
{
|
||||
return type().DefaultFileName();
|
||||
}
|
||||
};
|
||||
}// namespace Spreadsheet
|
||||
} // namespace OOX
|
||||
|
||||
#endif // OOX_EXTERNALLINKPATH_INCLUDE_H_
|
||||
#endif // OOX_EXTERNALLINKPATH_INCLUDE_H_
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -128,7 +128,16 @@ namespace OOX
|
||||
else if ( pRelation->Type() == FileTypes::Worksheet )
|
||||
return smart_ptr<OOX::File>(new CWorksheet( oRootPath, oFileName ));
|
||||
else if ( pRelation->Type() == OOX::FileTypes::Theme )
|
||||
return smart_ptr<OOX::File>(new PPTX::Theme( oFileName ));
|
||||
{
|
||||
if(NSFile::CFileBinary::Exists(oFileName.GetPath()))
|
||||
{
|
||||
return smart_ptr<OOX::File>(new PPTX::Theme( oFileName ));
|
||||
}
|
||||
else
|
||||
{
|
||||
return smart_ptr<OOX::File>( new UnknowTypeFile() );
|
||||
}
|
||||
}
|
||||
else if ( pRelation->Type() == OOX::FileTypes::ThemeOverride )
|
||||
return smart_ptr<OOX::File>(new PPTX::Theme( oFileName ));
|
||||
else if ( pRelation->Type() == FileTypes::Drawings )
|
||||
@ -152,7 +161,16 @@ namespace OOX
|
||||
else if ( pRelation->Type() == OOX::FileTypes::ExternalLinkPath)
|
||||
return smart_ptr<OOX::File>(new ExternalLinkPath( oRelationFilename ));
|
||||
else if ( pRelation->Type() == OOX::FileTypes::OleObject)
|
||||
return smart_ptr<OOX::File>(new OOX::OleObject( oFileName ));
|
||||
{
|
||||
if (pRelation->IsExternal())
|
||||
{
|
||||
return smart_ptr<OOX::File>(new OOX::OleObject( oRelationFilename ));
|
||||
}
|
||||
else
|
||||
{
|
||||
return smart_ptr<OOX::File>(new OOX::OleObject( oFileName ));
|
||||
}
|
||||
}
|
||||
else if ( pRelation->Type() == OOX::FileTypes::Data)
|
||||
return smart_ptr<OOX::File>(new OOX::CDiagramData( oRootPath, oFileName ));
|
||||
else if ( pRelation->Type() == OOX::FileTypes::DiagDrawing)
|
||||
|
||||
@ -2608,5 +2608,48 @@ namespace SimpleTypes
|
||||
SimpleType_FromString (EPaneState)
|
||||
SimpleType_Operator_Equal (CPaneState)
|
||||
};
|
||||
|
||||
enum EDdeValueType
|
||||
{
|
||||
ddevaluetypeNil = 0,
|
||||
ddevaluetypeB = 1,
|
||||
ddevaluetypeN = 2,
|
||||
ddevaluetypeE = 3,
|
||||
ddevaluetypeStr = 4
|
||||
};
|
||||
|
||||
template<EDdeValueType eDefValue = ddevaluetypeNil>
|
||||
class CDdeValueType : public CSimpleType<EDdeValueType, eDefValue>
|
||||
{
|
||||
public:
|
||||
CDdeValueType() {}
|
||||
|
||||
virtual EDdeValueType FromString(std::wstring &sValue)
|
||||
{
|
||||
if ( _T("nil") == sValue ) this->m_eValue = ddevaluetypeNil;
|
||||
else if ( _T("b") == sValue ) this->m_eValue = ddevaluetypeB;
|
||||
else if ( _T("n") == sValue ) this->m_eValue = ddevaluetypeN;
|
||||
else if ( _T("e") == sValue ) this->m_eValue = ddevaluetypeE;
|
||||
else if ( _T("str") == sValue ) this->m_eValue = ddevaluetypeStr;
|
||||
else this->m_eValue = eDefValue;
|
||||
return this->m_eValue;
|
||||
}
|
||||
|
||||
virtual std::wstring ToString () const
|
||||
{
|
||||
switch(this->m_eValue)
|
||||
{
|
||||
case ddevaluetypeNil : return _T("nil");
|
||||
case ddevaluetypeB : return _T("b");
|
||||
case ddevaluetypeN : return _T("n");
|
||||
case ddevaluetypeE : return _T("e");
|
||||
case ddevaluetypeStr : return _T("str");
|
||||
default : return _T("nil");
|
||||
}
|
||||
}
|
||||
|
||||
SimpleType_FromString (EDdeValueType)
|
||||
SimpleType_Operator_Equal (CDdeValueType)
|
||||
};
|
||||
};// Spreadsheet
|
||||
} // SimpleTypes
|
||||
|
||||
@ -745,6 +745,7 @@
|
||||
#define ASC_MENU_EVENT_TYPE_USER_ZOOM 301
|
||||
|
||||
#define ASC_MENU_EVENT_TYPE_INSERT_CHART 400
|
||||
#define ASC_MENU_EVENT_TYPE_GET_CHART_DATA 450
|
||||
|
||||
#define ASC_MENU_EVENT_TYPE_ERROR 500
|
||||
|
||||
|
||||
@ -452,6 +452,14 @@ namespace NSStringExt
|
||||
|
||||
return arrElements;
|
||||
}
|
||||
static inline void ToLower(std::string& wsString)
|
||||
{
|
||||
std::transform(wsString.begin(), wsString.end(), wsString.begin(), ::towlower);
|
||||
}
|
||||
static inline void ToUpper(std::string& wsString)
|
||||
{
|
||||
std::transform(wsString.begin(), wsString.end(), wsString.begin(), ::towupper);
|
||||
}
|
||||
static inline void ToLower(std::wstring& wsString)
|
||||
{
|
||||
std::transform(wsString.begin(), wsString.end(), wsString.begin(), ::towlower);
|
||||
|
||||
@ -8,9 +8,36 @@
|
||||
#define OOXML_HASH_ALG_SHA1 0
|
||||
#define OOXML_HASH_ALG_INVALID 1
|
||||
|
||||
class Q_DECL_EXPORT CCertificateInfo
|
||||
#define OPEN_SSL_WARNING_OK 0
|
||||
#define OPEN_SSL_WARNING_ERR 1
|
||||
#define OPEN_SSL_WARNING_ALL_OK 2
|
||||
#define OPEN_SSL_WARNING_PASS 4
|
||||
|
||||
class ICertificate;
|
||||
class Q_DECL_EXPORT ICertificateSelectDialogOpenSsl
|
||||
{
|
||||
public:
|
||||
ICertificateSelectDialogOpenSsl()
|
||||
{
|
||||
}
|
||||
virtual ~ICertificateSelectDialogOpenSsl()
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
virtual std::wstring GetCertificatePath() = 0;
|
||||
virtual std::wstring GetCertificatePassword() = 0;
|
||||
|
||||
virtual std::wstring GetKeyPath() = 0;
|
||||
virtual std::wstring GetKeyPassword() = 0;
|
||||
|
||||
virtual bool ShowSelectDialog() = 0;
|
||||
virtual int ShowCertificate(ICertificate* pCert) = 0;
|
||||
};
|
||||
|
||||
class Q_DECL_EXPORT CCertificateInfo
|
||||
{
|
||||
private:
|
||||
std::wstring m_name;
|
||||
std::string m_date;
|
||||
std::string m_id;
|
||||
@ -22,6 +49,33 @@ public:
|
||||
~CCertificateInfo()
|
||||
{
|
||||
}
|
||||
|
||||
std::wstring GetName()
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
void SetName(const std::wstring& name)
|
||||
{
|
||||
m_name = name;
|
||||
}
|
||||
|
||||
std::string GetDate()
|
||||
{
|
||||
return m_date;
|
||||
}
|
||||
void SetDate(const std::string& date)
|
||||
{
|
||||
m_date = date;
|
||||
}
|
||||
|
||||
std::string GetId()
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
void SetId(const std::string& id)
|
||||
{
|
||||
m_id = id;
|
||||
}
|
||||
};
|
||||
|
||||
class Q_DECL_EXPORT ICertificate
|
||||
@ -58,15 +112,17 @@ public:
|
||||
virtual bool ShowSelectDialog() = 0;
|
||||
virtual int ShowCertificate() = 0;
|
||||
|
||||
virtual void SetOpenSslDialog(ICertificateSelectDialogOpenSsl* pDialog) {}
|
||||
|
||||
static CCertificateInfo GetDefault();
|
||||
static ICertificate* GetById(const std::string& id);
|
||||
|
||||
virtual CCertificateInfo GetInfo()
|
||||
{
|
||||
CCertificateInfo info;
|
||||
info.m_name = GetSignerName();
|
||||
info.m_date = GetDate();
|
||||
info.m_id = GetId();
|
||||
info.SetName(GetSignerName());
|
||||
info.SetDate(GetDate());
|
||||
info.SetId(GetId());
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
@ -21,6 +21,13 @@ include($$CORE_ROOT_DIR/DesktopEditor/xml/build/qt/libxml2.pri)
|
||||
|
||||
DEFINES -= UNICODE
|
||||
|
||||
core_linux {
|
||||
CONFIG += signature_openssl
|
||||
}
|
||||
core_mac {
|
||||
CONFIG += signature_openssl
|
||||
}
|
||||
|
||||
HEADERS += \
|
||||
include/XmlCertificate.h \
|
||||
include/OOXMLSigner.h \
|
||||
@ -29,9 +36,7 @@ HEADERS += \
|
||||
HEADERS += \
|
||||
src/XmlCanonicalizator.h \
|
||||
src/XmlRels.h \
|
||||
src/XmlTransform.h \
|
||||
src/XmlSigner_mscrypto.h \
|
||||
src/XmlSigner_openssl.h
|
||||
src/XmlTransform.h
|
||||
|
||||
SOURCES += \
|
||||
src/XmlTransform.cpp \
|
||||
@ -41,8 +46,31 @@ SOURCES += \
|
||||
|
||||
core_windows {
|
||||
|
||||
HEADERS += \
|
||||
src/XmlSigner_mscrypto.h
|
||||
|
||||
LIBS += -lcrypt32
|
||||
LIBS += -lcryptui
|
||||
LIBS += -lAdvapi32
|
||||
|
||||
}
|
||||
|
||||
signature_openssl {
|
||||
|
||||
HEADERS += \
|
||||
src/XmlSigner_openssl.h
|
||||
|
||||
SOURCES += \
|
||||
src/XmlSigner_openssl.cpp
|
||||
|
||||
}
|
||||
|
||||
signature_openssl {
|
||||
|
||||
DEFINES += XMLSEC_OPENSSL_110
|
||||
INCLUDEPATH += $$CORE_ROOT_DIR/Common/3dParty/openssl/openssl/include
|
||||
|
||||
LIBS += -L$$CORE_ROOT_DIR/Common/3dParty/openssl/openssl -lssl
|
||||
LIBS += -L$$CORE_ROOT_DIR/Common/3dParty/openssl/openssl -lcrypto
|
||||
|
||||
}
|
||||
|
||||
663
DesktopEditor/xmlsec/src/src/XmlSigner_openssl.cpp
Normal file
663
DesktopEditor/xmlsec/src/src/XmlSigner_openssl.cpp
Normal file
@ -0,0 +1,663 @@
|
||||
#include "./XmlSigner_openssl.h"
|
||||
|
||||
#include "../../../common/File.h"
|
||||
#include "../../../common/String.h"
|
||||
#include "../../../common/BigInteger.h"
|
||||
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/pkcs12.h>
|
||||
|
||||
#include <openssl/sha.h>
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/engine.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/conf.h>
|
||||
|
||||
class CCertificate_openssl_private
|
||||
{
|
||||
protected:
|
||||
ICertificateSelectDialogOpenSsl* m_pDialog;
|
||||
|
||||
X509* m_cert;
|
||||
EVP_PKEY* m_key;
|
||||
|
||||
public:
|
||||
ICertificate* m_pBase;
|
||||
|
||||
public:
|
||||
CCertificate_openssl_private()
|
||||
{
|
||||
m_pDialog = NULL;
|
||||
|
||||
m_cert = NULL;
|
||||
m_key = NULL;
|
||||
|
||||
m_pBase = NULL;
|
||||
}
|
||||
virtual ~CCertificate_openssl_private()
|
||||
{
|
||||
if (NULL != m_cert)
|
||||
X509_free(m_cert);
|
||||
if (NULL != m_key)
|
||||
EVP_PKEY_free(m_key);
|
||||
}
|
||||
|
||||
public:
|
||||
std::string GetNumber()
|
||||
{
|
||||
if (NULL == m_cert)
|
||||
return "";
|
||||
|
||||
ASN1_INTEGER* asn1_serial = X509_get_serialNumber(m_cert);
|
||||
if (asn1_serial == NULL)
|
||||
return "";
|
||||
|
||||
BIGNUM* bn = ASN1_INTEGER_to_BN(asn1_serial, NULL);
|
||||
if (!bn)
|
||||
{
|
||||
ASN1_INTEGER_free(asn1_serial);
|
||||
return "";
|
||||
}
|
||||
|
||||
char *tmp = BN_bn2dec(bn);
|
||||
std::string sReturn(tmp);
|
||||
|
||||
BN_free(bn);
|
||||
ASN1_INTEGER_free(asn1_serial);
|
||||
|
||||
return sReturn;
|
||||
}
|
||||
|
||||
std::wstring GetSignerName()
|
||||
{
|
||||
if (NULL == m_cert)
|
||||
return L"";
|
||||
|
||||
X509_NAME* name = X509_get_issuer_name(m_cert);
|
||||
char* utf_8_name = X509_NAME_oneline(name, NULL, 0);
|
||||
|
||||
std::string sName(utf_8_name);
|
||||
std::wstring sNameW = UTF8_TO_U(sName);
|
||||
|
||||
OPENSSL_free(utf_8_name);
|
||||
|
||||
return sNameW;
|
||||
}
|
||||
|
||||
std::string GetCertificateBase64()
|
||||
{
|
||||
if (NULL == m_cert)
|
||||
return "";
|
||||
|
||||
BIO* bio = BIO_new(BIO_s_mem());
|
||||
PEM_write_bio_X509_AUX(bio, m_cert);
|
||||
|
||||
unsigned char *data;
|
||||
unsigned int len = 0;
|
||||
len = BIO_get_mem_data(bio, &data);
|
||||
|
||||
std::string sReturn((char*)data, (size_t)len);
|
||||
|
||||
BIO_free(bio);
|
||||
return sReturn;
|
||||
}
|
||||
|
||||
std::string GetCertificateHash()
|
||||
{
|
||||
std::string sBase64 = GetCertificateBase64();
|
||||
BYTE* pData = NULL;
|
||||
int nLen = 0;
|
||||
if (NSFile::CBase64Converter::Decode(sBase64.c_str(), (int)sBase64.length(), pData, nLen))
|
||||
{
|
||||
std::string sHash = GetHash(pData, (unsigned int)nLen, OOXML_HASH_ALG_SHA1);
|
||||
RELEASEARRAYOBJECTS(pData);
|
||||
return sHash;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string GetDate()
|
||||
{
|
||||
if (NULL == m_cert)
|
||||
return "";
|
||||
|
||||
ASN1_TIME* _time1 = X509_get_notBefore(m_cert);
|
||||
struct tm t1 = this->ASN1_GetTimeT(_time1);
|
||||
ASN1_TIME_free(_time1);
|
||||
|
||||
ASN1_TIME* _time2 = X509_get_notAfter(m_cert);
|
||||
struct tm t2 = this->ASN1_GetTimeT(_time2);
|
||||
ASN1_TIME_free(_time2);
|
||||
|
||||
std::string sRet = std::to_string(t1.tm_mday) +
|
||||
"/" +
|
||||
std::to_string(t1.tm_mon + 1) +
|
||||
"/" +
|
||||
std::to_string(t1.tm_year + 1900) +
|
||||
" - " +
|
||||
std::to_string(t1.tm_mday) +
|
||||
"/" +
|
||||
std::to_string(t2.tm_mon + 1) +
|
||||
"/" +
|
||||
std::to_string(t2.tm_year + 1900);
|
||||
return sRet;
|
||||
}
|
||||
|
||||
std::string GetId()
|
||||
{
|
||||
// TODO: + public key?
|
||||
return GetNumber();
|
||||
}
|
||||
|
||||
public:
|
||||
std::string Sign(const std::string& sXml)
|
||||
{
|
||||
EVP_MD_CTX* pCtx = EVP_MD_CTX_create();
|
||||
const EVP_MD* pDigest = EVP_sha1();
|
||||
|
||||
int n1 = EVP_SignInit(pCtx, pDigest);
|
||||
n1 = n1;
|
||||
|
||||
int n2 = EVP_SignUpdate(pCtx, sXml.c_str(), sXml.length());
|
||||
n2 = n2;
|
||||
|
||||
BYTE pSignature[4096];
|
||||
unsigned int nSignatureLen = 0;
|
||||
|
||||
int n3 = EVP_SignFinal(pCtx, pSignature, &nSignatureLen, m_key);
|
||||
n3 = n3;
|
||||
|
||||
EVP_MD_CTX_destroy(pCtx);
|
||||
|
||||
return std::string((char*)pSignature, (size_t)nSignatureLen);
|
||||
}
|
||||
|
||||
std::string GetHash(unsigned char* pData, unsigned int nSize, int nAlg)
|
||||
{
|
||||
if (nAlg == OOXML_HASH_ALG_SHA1)
|
||||
{
|
||||
unsigned char obuf[20];
|
||||
SHA1(pData, (size_t)nSize, obuf);
|
||||
|
||||
char* pBase64_hash = NULL;
|
||||
int nBase64Len_hash = 0;
|
||||
NSFile::CBase64Converter::Encode(obuf, 20, pBase64_hash, nBase64Len_hash, NSBase64::B64_BASE64_FLAG_NOCRLF);
|
||||
|
||||
std::string sReturn(pBase64_hash, nBase64Len_hash);
|
||||
delete [] pBase64_hash;
|
||||
|
||||
return sReturn;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string GetHash(const std::string& sXml, int nAlg)
|
||||
{
|
||||
return GetHash((BYTE*)sXml.c_str(), (DWORD)sXml.length(), nAlg);
|
||||
}
|
||||
|
||||
std::string GetHash(const std::wstring& sXmlFile, int nAlg)
|
||||
{
|
||||
BYTE* pFileData = NULL;
|
||||
DWORD dwFileDataLen = 0;
|
||||
NSFile::CFileBinary::ReadAllBytes(sXmlFile, &pFileData, dwFileDataLen);
|
||||
|
||||
if (0 == dwFileDataLen)
|
||||
return "";
|
||||
|
||||
std::string sReturn = GetHash(pFileData, dwFileDataLen, nAlg);
|
||||
|
||||
RELEASEARRAYOBJECTS(pFileData);
|
||||
return sReturn;
|
||||
}
|
||||
|
||||
bool Verify(const std::string& sXml, std::string& sXmlSignature, int nAlg)
|
||||
{
|
||||
EVP_MD_CTX* pCtx = EVP_MD_CTX_create();
|
||||
const EVP_MD* pDigest = EVP_sha1();
|
||||
|
||||
int n1 = EVP_VerifyInit(pCtx, pDigest);
|
||||
n1 = n1;
|
||||
|
||||
BYTE* pDigestValue = NULL;
|
||||
int nDigestLen = 0;
|
||||
NSFile::CBase64Converter::Decode(sXmlSignature.c_str(), (int)sXmlSignature.length(), pDigestValue, nDigestLen);
|
||||
|
||||
int n2 = EVP_VerifyUpdate(pCtx, pDigestValue, (size_t)nDigestLen);
|
||||
n2 = n2;
|
||||
|
||||
EVP_PKEY* pubkey = X509_get_pubkey(m_cert);
|
||||
|
||||
int n3 = EVP_VerifyFinal(pCtx, (BYTE*)sXml.c_str(), (unsigned int)sXml.length(), pubkey);
|
||||
n3 = n3;
|
||||
|
||||
EVP_MD_CTX_destroy(pCtx);
|
||||
EVP_PKEY_free(pubkey);
|
||||
|
||||
RELEASEARRAYOBJECTS(pDigestValue);
|
||||
|
||||
return (1 == n3) ? true : false;
|
||||
}
|
||||
|
||||
bool LoadFromBase64Data(const std::string& data)
|
||||
{
|
||||
BYTE* pData = NULL;
|
||||
int nLen = 0;
|
||||
if (NSFile::CBase64Converter::Decode(data.c_str(), (int)data.length(), pData, nLen))
|
||||
{
|
||||
X509* pCert = NULL;
|
||||
int nErr = LoadCert(pData, (DWORD)nLen, "", &pCert);
|
||||
|
||||
if (nErr == OPEN_SSL_WARNING_OK || nErr == OPEN_SSL_WARNING_ALL_OK)
|
||||
{
|
||||
m_cert = pCert;
|
||||
}
|
||||
else
|
||||
{
|
||||
X509_free(pCert);
|
||||
m_cert = NULL;
|
||||
}
|
||||
|
||||
RELEASEARRAYOBJECTS(pData);
|
||||
return (NULL == m_cert) ? false : true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public:
|
||||
bool ShowSelectDialog()
|
||||
{
|
||||
if (!m_pDialog)
|
||||
return false;
|
||||
|
||||
bool bResult = m_pDialog->ShowSelectDialog();
|
||||
|
||||
std::wstring sKeyPath = m_pDialog->GetKeyPath();
|
||||
std::wstring sKeyPasswordW = m_pDialog->GetKeyPassword();
|
||||
std::string sKeyPassword = U_TO_UTF8(sKeyPasswordW);
|
||||
|
||||
std::wstring sCertPath = m_pDialog->GetCertificatePath();
|
||||
std::wstring sCertPasswordW = m_pDialog->GetCertificatePassword();
|
||||
std::string sCertPassword = U_TO_UTF8(sCertPasswordW);
|
||||
|
||||
if (sCertPath.empty())
|
||||
{
|
||||
sCertPath = sKeyPath;
|
||||
sCertPassword = sKeyPassword;
|
||||
}
|
||||
|
||||
int nErr = LoadKey(sKeyPath, sKeyPassword, &m_key);
|
||||
|
||||
if (nErr != OPEN_SSL_WARNING_OK && nErr != OPEN_SSL_WARNING_ALL_OK)
|
||||
return false;
|
||||
|
||||
nErr = LoadCert(sCertPath, sCertPassword, &m_cert);
|
||||
|
||||
if (nErr != OPEN_SSL_WARNING_OK && nErr != OPEN_SSL_WARNING_ALL_OK)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
int ShowCertificate()
|
||||
{
|
||||
if (m_pDialog)
|
||||
return m_pDialog->ShowCertificate(m_pBase);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void SetOpenSslDialog(ICertificateSelectDialogOpenSsl* pDialog)
|
||||
{
|
||||
m_pDialog = pDialog;
|
||||
}
|
||||
|
||||
protected:
|
||||
tm ASN1_GetTimeT(ASN1_TIME* time)
|
||||
{
|
||||
struct tm t;
|
||||
const char* str = (const char*) time->data;
|
||||
size_t i = 0;
|
||||
|
||||
memset(&t, 0, sizeof(t));
|
||||
|
||||
if (time->type == V_ASN1_UTCTIME)
|
||||
{
|
||||
/* two digit year */
|
||||
t.tm_year = (str[i++] - '0') * 10;
|
||||
t.tm_year += (str[i++] - '0');
|
||||
if (t.tm_year < 70)
|
||||
t.tm_year += 100;
|
||||
}
|
||||
else if (time->type == V_ASN1_GENERALIZEDTIME)
|
||||
{
|
||||
/* four digit year */
|
||||
t.tm_year = (str[i++] - '0') * 1000;
|
||||
t.tm_year+= (str[i++] - '0') * 100;
|
||||
t.tm_year+= (str[i++] - '0') * 10;
|
||||
t.tm_year+= (str[i++] - '0');
|
||||
t.tm_year -= 1900;
|
||||
}
|
||||
t.tm_mon = (str[i++] - '0') * 10;
|
||||
t.tm_mon += (str[i++] - '0') - 1; // -1 since January is 0 not 1.
|
||||
t.tm_mday = (str[i++] - '0') * 10;
|
||||
t.tm_mday+= (str[i++] - '0');
|
||||
t.tm_hour = (str[i++] - '0') * 10;
|
||||
t.tm_hour+= (str[i++] - '0');
|
||||
t.tm_min = (str[i++] - '0') * 10;
|
||||
t.tm_min += (str[i++] - '0');
|
||||
t.tm_sec = (str[i++] - '0') * 10;
|
||||
t.tm_sec += (str[i++] - '0');
|
||||
|
||||
/* Note: we did not adjust the time based on time zone information */
|
||||
return t;
|
||||
}
|
||||
|
||||
public:
|
||||
static std::string GetOpenSslErrors()
|
||||
{
|
||||
BIO* bio = BIO_new(BIO_s_mem());
|
||||
ERR_print_errors(bio);
|
||||
char *buf = NULL;
|
||||
size_t len = BIO_get_mem_data(bio, &buf);
|
||||
std::string sRet((char*)buf, len);
|
||||
NSStringExt::ToLower(sRet);
|
||||
BIO_free (bio);
|
||||
return sRet;
|
||||
}
|
||||
static bool IsOpenSslPasswordError(const std::string& str)
|
||||
{
|
||||
if (std::string::npos != str.find("mac verify error"))
|
||||
return true;
|
||||
if (std::string::npos != str.find("mac verify failure"))
|
||||
return true;
|
||||
if (std::string::npos != str.find("password"))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
static int LoadKey(BYTE* pData, DWORD dwDataLen, std::string password, EVP_PKEY** ppKey)
|
||||
{
|
||||
int nErr = OPEN_SSL_WARNING_ERR;
|
||||
std::string sError = "";
|
||||
|
||||
PKCS12* p12 = NULL;
|
||||
EVP_PKEY* pKey = NULL;
|
||||
char* pPassword = (password.empty()) ? NULL : (char*)password.c_str();
|
||||
|
||||
BIO* bio = BIO_new_mem_buf((void*)pData, (int)dwDataLen);
|
||||
if (PEM_read_bio_PrivateKey(bio, &pKey, NULL, (void*)pPassword))
|
||||
{
|
||||
nErr = OPEN_SSL_WARNING_OK;
|
||||
goto end;
|
||||
}
|
||||
sError = GetOpenSslErrors();
|
||||
if (IsOpenSslPasswordError(sError))
|
||||
{
|
||||
nErr = OPEN_SSL_WARNING_PASS;
|
||||
goto end;
|
||||
}
|
||||
|
||||
BIO_free(bio);
|
||||
bio = BIO_new_mem_buf((void*)pData, (int)dwDataLen);
|
||||
if (d2i_PrivateKey_bio(bio, &pKey))
|
||||
{
|
||||
nErr = OPEN_SSL_WARNING_OK;
|
||||
goto end;
|
||||
}
|
||||
sError = GetOpenSslErrors();
|
||||
if (IsOpenSslPasswordError(sError))
|
||||
{
|
||||
nErr = OPEN_SSL_WARNING_PASS;
|
||||
goto end;
|
||||
}
|
||||
|
||||
BIO_free(bio);
|
||||
bio = BIO_new_mem_buf((void*)pData, (int)dwDataLen);
|
||||
if (d2i_PKCS8PrivateKey_bio(bio, &pKey, NULL, (void*)pPassword))
|
||||
{
|
||||
nErr = OPEN_SSL_WARNING_OK;
|
||||
goto end;
|
||||
}
|
||||
sError = GetOpenSslErrors();
|
||||
if (IsOpenSslPasswordError(sError))
|
||||
{
|
||||
nErr = OPEN_SSL_WARNING_PASS;
|
||||
goto end;
|
||||
}
|
||||
|
||||
BIO_free(bio);
|
||||
bio = BIO_new_mem_buf((void*)pData, (int)dwDataLen);
|
||||
|
||||
p12 = d2i_PKCS12_bio(bio, NULL);
|
||||
if (p12)
|
||||
{
|
||||
X509* pCert = NULL;
|
||||
STACK_OF(X509)* pCa = NULL;
|
||||
|
||||
if (PKCS12_parse(p12, pPassword, &pKey, &pCert, &pCa))
|
||||
{
|
||||
sk_X509_pop_free(pCa, X509_free);
|
||||
X509_free(pCert);
|
||||
PKCS12_free(p12);
|
||||
nErr = OPEN_SSL_WARNING_ALL_OK;
|
||||
goto end;
|
||||
}
|
||||
PKCS12_free(p12);
|
||||
|
||||
sError = GetOpenSslErrors();
|
||||
if (IsOpenSslPasswordError(sError))
|
||||
{
|
||||
nErr = OPEN_SSL_WARNING_PASS;
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
end:
|
||||
if (NULL == ppKey)
|
||||
EVP_PKEY_free(pKey);
|
||||
else
|
||||
*ppKey = pKey;
|
||||
|
||||
BIO_free(bio);
|
||||
return nErr;
|
||||
}
|
||||
|
||||
static int LoadKey(std::wstring file, std::string password, EVP_PKEY** ppKey)
|
||||
{
|
||||
BYTE* pData = NULL;
|
||||
DWORD dwDataLen;
|
||||
if (!NSFile::CFileBinary::ReadAllBytes(file, &pData, dwDataLen))
|
||||
return OPEN_SSL_WARNING_ERR;
|
||||
|
||||
int nErr = LoadKey(pData, dwDataLen, password, ppKey);
|
||||
RELEASEARRAYOBJECTS(pData);
|
||||
return nErr;
|
||||
}
|
||||
|
||||
static int LoadCert(BYTE* pData, DWORD dwDataLen, std::string password, X509** ppCert)
|
||||
{
|
||||
int nErr = OPEN_SSL_WARNING_ERR;
|
||||
std::string sError = "";
|
||||
|
||||
PKCS12* p12 = NULL;
|
||||
X509* pCert = NULL;
|
||||
char* pPassword = (password.empty()) ? NULL : (char*)password.c_str();
|
||||
|
||||
BIO* bio = BIO_new_mem_buf((void*)pData, (int)dwDataLen);
|
||||
if (PEM_read_bio_X509(bio, &pCert, NULL, (void*)pPassword))
|
||||
{
|
||||
nErr = OPEN_SSL_WARNING_OK;
|
||||
goto end;
|
||||
}
|
||||
sError = GetOpenSslErrors();
|
||||
if (IsOpenSslPasswordError(sError))
|
||||
{
|
||||
nErr = OPEN_SSL_WARNING_PASS;
|
||||
goto end;
|
||||
}
|
||||
|
||||
BIO_free(bio);
|
||||
bio = BIO_new_mem_buf((void*)pData, (int)dwDataLen);
|
||||
if (d2i_X509_bio(bio, &pCert))
|
||||
{
|
||||
nErr = OPEN_SSL_WARNING_OK;
|
||||
goto end;
|
||||
}
|
||||
sError = GetOpenSslErrors();
|
||||
if (IsOpenSslPasswordError(sError))
|
||||
{
|
||||
nErr = OPEN_SSL_WARNING_PASS;
|
||||
goto end;
|
||||
}
|
||||
|
||||
BIO_free(bio);
|
||||
bio = BIO_new_mem_buf((void*)pData, (int)dwDataLen);
|
||||
|
||||
p12 = d2i_PKCS12_bio(bio, NULL);
|
||||
if (p12)
|
||||
{
|
||||
EVP_PKEY* pKey = NULL;
|
||||
STACK_OF(X509)* pCa = NULL;
|
||||
|
||||
if (PKCS12_parse(p12, pPassword, &pKey, &pCert, &pCa))
|
||||
{
|
||||
sk_X509_pop_free(pCa, X509_free);
|
||||
EVP_PKEY_free(pKey);
|
||||
PKCS12_free(p12);
|
||||
BIO_free(bio);
|
||||
nErr = OPEN_SSL_WARNING_ALL_OK;
|
||||
goto end;
|
||||
}
|
||||
|
||||
PKCS12_free(p12);
|
||||
sError = GetOpenSslErrors();
|
||||
if (IsOpenSslPasswordError(sError))
|
||||
{
|
||||
nErr = OPEN_SSL_WARNING_PASS;
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
end:
|
||||
if (NULL == ppCert)
|
||||
X509_free(pCert);
|
||||
else
|
||||
*ppCert = pCert;
|
||||
|
||||
BIO_free(bio);
|
||||
return nErr;
|
||||
}
|
||||
|
||||
static int LoadCert(std::wstring file, std::string password, X509** ppCert)
|
||||
{
|
||||
BYTE* pData = NULL;
|
||||
DWORD dwDataLen;
|
||||
if (!NSFile::CFileBinary::ReadAllBytes(file, &pData, dwDataLen))
|
||||
return OPEN_SSL_WARNING_ERR;
|
||||
|
||||
int nErr = LoadCert(pData, dwDataLen, password, ppCert);
|
||||
RELEASEARRAYOBJECTS(pData);
|
||||
return nErr;
|
||||
}
|
||||
};
|
||||
|
||||
// REALIZE
|
||||
CCertificate_openssl::CCertificate_openssl() : ICertificate()
|
||||
{
|
||||
m_internal = new CCertificate_openssl_private();
|
||||
m_internal->m_pBase = this;
|
||||
}
|
||||
|
||||
CCertificate_openssl::~CCertificate_openssl()
|
||||
{
|
||||
RELEASEOBJECT(m_internal);
|
||||
}
|
||||
|
||||
std::string CCertificate_openssl::GetNumber()
|
||||
{
|
||||
return m_internal->GetNumber();
|
||||
}
|
||||
|
||||
std::wstring CCertificate_openssl::GetSignerName()
|
||||
{
|
||||
return m_internal->GetSignerName();
|
||||
}
|
||||
|
||||
std::string CCertificate_openssl::GetCertificateBase64()
|
||||
{
|
||||
return m_internal->GetCertificateBase64();
|
||||
}
|
||||
|
||||
std::string CCertificate_openssl::GetCertificateHash()
|
||||
{
|
||||
return m_internal->GetCertificateHash();
|
||||
}
|
||||
|
||||
std::string CCertificate_openssl::GetDate()
|
||||
{
|
||||
return m_internal->GetDate();
|
||||
}
|
||||
|
||||
std::string CCertificate_openssl::GetId()
|
||||
{
|
||||
return m_internal->GetId();
|
||||
}
|
||||
|
||||
std::string CCertificate_openssl::Sign(const std::string& sXml)
|
||||
{
|
||||
return m_internal->Sign(sXml);
|
||||
}
|
||||
|
||||
std::string CCertificate_openssl::GetHash(unsigned char* pData, unsigned int nSize, int nAlg)
|
||||
{
|
||||
return m_internal->GetHash(pData, nSize, nAlg);
|
||||
}
|
||||
|
||||
std::string CCertificate_openssl::GetHash(const std::string& sXml, int nAlg)
|
||||
{
|
||||
return m_internal->GetHash(sXml, nAlg);
|
||||
}
|
||||
|
||||
std::string CCertificate_openssl::GetHash(const std::wstring& sXmlFile, int nAlg)
|
||||
{
|
||||
return m_internal->GetHash(sXmlFile, nAlg);
|
||||
}
|
||||
|
||||
bool CCertificate_openssl::Verify(const std::string& sXml, std::string& sXmlSignature, int nAlg)
|
||||
{
|
||||
return m_internal->Verify(sXml, sXmlSignature, nAlg);
|
||||
}
|
||||
|
||||
bool CCertificate_openssl::LoadFromBase64Data(const std::string& data)
|
||||
{
|
||||
return m_internal->LoadFromBase64Data(data);
|
||||
}
|
||||
|
||||
bool CCertificate_openssl::ShowSelectDialog()
|
||||
{
|
||||
return m_internal->ShowSelectDialog();
|
||||
}
|
||||
|
||||
int CCertificate_openssl::ShowCertificate()
|
||||
{
|
||||
return m_internal->ShowCertificate();
|
||||
}
|
||||
|
||||
void CCertificate_openssl::SetOpenSslDialog(ICertificateSelectDialogOpenSsl* pDialog)
|
||||
{
|
||||
return m_internal->SetOpenSslDialog(pDialog);
|
||||
}
|
||||
|
||||
int LoadKey(std::wstring file, std::string password)
|
||||
{
|
||||
return CCertificate_openssl_private::LoadKey(file, password, NULL);
|
||||
}
|
||||
|
||||
int LoadCert(std::wstring file, std::string password)
|
||||
{
|
||||
return CCertificate_openssl_private::LoadCert(file, password, NULL);
|
||||
}
|
||||
@ -1,111 +1,53 @@
|
||||
#ifndef _XMLSIGNER_OPENSSL_H_
|
||||
#define _XMLSIGNER_OPENSSL_H_
|
||||
|
||||
#include "./include/XmlCertificate.h"
|
||||
|
||||
#include "../../../common/File.h"
|
||||
#include "../../../common/BigInteger.h"
|
||||
#include "./../include/XmlCertificate.h"
|
||||
|
||||
class CCertificate_openssl_private;
|
||||
class CCertificate_openssl : public ICertificate
|
||||
{
|
||||
public:
|
||||
|
||||
protected:
|
||||
BYTE* m_rawData;
|
||||
int m_rawDataLen;
|
||||
CCertificate_openssl_private* m_internal;
|
||||
|
||||
public:
|
||||
CCertificate_openssl() : ICertificate()
|
||||
{
|
||||
m_rawData = NULL;
|
||||
m_rawDataLen = 0;
|
||||
}
|
||||
virtual ~CCertificate_openssl()
|
||||
{
|
||||
}
|
||||
CCertificate_openssl();
|
||||
virtual ~CCertificate_openssl();
|
||||
|
||||
public:
|
||||
virtual std::string GetNumber()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
virtual std::string GetNumber();
|
||||
|
||||
virtual std::wstring GetSignerName()
|
||||
{
|
||||
return L"";
|
||||
}
|
||||
virtual std::wstring GetSignerName();
|
||||
|
||||
virtual std::string GetCertificateBase64()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
virtual std::string GetCertificateBase64();
|
||||
|
||||
virtual std::string GetCertificateHash()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
virtual std::string GetCertificateHash();
|
||||
|
||||
virtual std::string GetDate()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
virtual std::string GetDate();
|
||||
|
||||
virtual std::string GetId()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
virtual std::string GetId();
|
||||
|
||||
public:
|
||||
virtual std::string Sign(const std::string& sXml)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
virtual std::string Sign(const std::string& sXml);
|
||||
|
||||
virtual std::string GetHash(unsigned char* pData, unsigned int nSize, int nAlg)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
virtual std::string GetHash(unsigned char* pData, unsigned int nSize, int nAlg);
|
||||
|
||||
virtual std::string GetHash(const std::string& sXml, int nAlg)
|
||||
{
|
||||
return GetHash((BYTE*)sXml.c_str(), (DWORD)sXml.length(), nAlg);
|
||||
}
|
||||
virtual std::string GetHash(const std::string& sXml, int nAlg);
|
||||
|
||||
virtual std::string GetHash(const std::wstring& sXmlFile, int nAlg)
|
||||
{
|
||||
BYTE* pFileData = NULL;
|
||||
DWORD dwFileDataLen = 0;
|
||||
NSFile::CFileBinary::ReadAllBytes(sXmlFile, &pFileData, dwFileDataLen);
|
||||
virtual std::string GetHash(const std::wstring& sXmlFile, int nAlg);
|
||||
|
||||
if (0 == dwFileDataLen)
|
||||
return "";
|
||||
virtual bool Verify(const std::string& sXml, std::string& sXmlSignature, int nAlg);
|
||||
|
||||
std::string sReturn = GetHash(pFileData, dwFileDataLen, nAlg);
|
||||
|
||||
RELEASEARRAYOBJECTS(pFileData);
|
||||
return sReturn;
|
||||
}
|
||||
|
||||
virtual bool Verify(const std::string& sXml, std::string& sXmlSignature, int nAlg)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool LoadFromBase64Data(const std::string& data)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual int ShowCertificate()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
virtual bool LoadFromBase64Data(const std::string& data);
|
||||
|
||||
public:
|
||||
virtual bool ShowSelectDialog()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
virtual bool ShowSelectDialog();
|
||||
virtual int ShowCertificate();
|
||||
|
||||
virtual void SetOpenSslDialog(ICertificateSelectDialogOpenSsl* pDialog);
|
||||
|
||||
public:
|
||||
static int LoadKey(std::wstring file, std::string password);
|
||||
static int LoadCert(std::wstring file, std::string password);
|
||||
};
|
||||
|
||||
#endif // _XMLSIGNER_OPENSSL_H_
|
||||
|
||||
@ -0,0 +1,43 @@
|
||||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2017-06-05T12:59:43
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core gui
|
||||
|
||||
QT += widgets
|
||||
|
||||
TARGET = OpenSSL_gui_test
|
||||
TEMPLATE = app
|
||||
|
||||
DEFINES -= \
|
||||
UNICODE \
|
||||
_UNICODE
|
||||
|
||||
CORE_ROOT_DIR = $$PWD/../../../..
|
||||
PWD_ROOT_DIR = $$PWD
|
||||
include($$CORE_ROOT_DIR/Common/base.pri)
|
||||
|
||||
core_linux {
|
||||
QMAKE_LFLAGS += -Wl,--rpath=./
|
||||
QMAKE_LFLAGS += -static-libstdc++ -static-libgcc
|
||||
}
|
||||
|
||||
DEFINES += XMLSEC_OPENSSL_110
|
||||
#DEFINES += "OPENSSL_API_COMPAT=\"0x10100000\""
|
||||
|
||||
INCLUDEPATH += $$CORE_ROOT_DIR/Common/3dParty/openssl/openssl/include
|
||||
|
||||
LIBS += -L$$CORE_ROOT_DIR/Common/3dParty/openssl/openssl -lssl
|
||||
LIBS += -L$$CORE_ROOT_DIR/Common/3dParty/openssl/openssl -lcrypto
|
||||
|
||||
LIBS += -ldl
|
||||
|
||||
SOURCES += main.cpp\
|
||||
mainwindow.cpp
|
||||
|
||||
HEADERS += mainwindow.h
|
||||
|
||||
HEADERS += opensslwrapper.h
|
||||
SOURCES += opensslwrapper.cpp
|
||||
11
DesktopEditor/xmlsec/test/OpenSSL_gui_test/main.cpp
Normal file
11
DesktopEditor/xmlsec/test/OpenSSL_gui_test/main.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
#include "mainwindow.h"
|
||||
#include <QApplication>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
MainWindow w;
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
110
DesktopEditor/xmlsec/test/OpenSSL_gui_test/mainwindow.cpp
Normal file
110
DesktopEditor/xmlsec/test/OpenSSL_gui_test/mainwindow.cpp
Normal file
@ -0,0 +1,110 @@
|
||||
#include "mainwindow.h"
|
||||
#include <QGridLayout>
|
||||
#include <QFileDialog>
|
||||
#include <QtNetwork/QSslSocket>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent)
|
||||
{
|
||||
QRect rect = this->geometry();
|
||||
this->setGeometry(rect.x(), rect.y(), 600, 170);
|
||||
|
||||
QGridLayout *mainGridLayout = new QGridLayout();
|
||||
mainGridLayout->setSpacing( 0 );
|
||||
mainGridLayout->setMargin( 0 );
|
||||
setLayout( mainGridLayout );
|
||||
|
||||
QWidget *centralWidget = new QWidget( this );
|
||||
centralWidget->setObjectName( "centralWidget" );
|
||||
centralWidget->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
|
||||
|
||||
this->setCentralWidget(centralWidget);
|
||||
|
||||
m_pKeyFile = new QPlainTextEdit(centralWidget);
|
||||
m_pKeyPassword = new QPlainTextEdit(centralWidget);
|
||||
|
||||
m_pCertFile = new QPlainTextEdit(centralWidget);
|
||||
m_pCertPassword = new QPlainTextEdit(centralWidget);
|
||||
|
||||
m_pKeyDialog = new QPushButton(centralWidget);
|
||||
m_pCertDialog = new QPushButton(centralWidget);
|
||||
m_pOK = new QPushButton(centralWidget);
|
||||
|
||||
m_pKeyDialog->setText("...");
|
||||
m_pCertDialog->setText("...");
|
||||
m_pOK->setText("OK");
|
||||
|
||||
m_pKeyFile->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
m_pKeyPassword->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
m_pCertFile->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
m_pCertPassword->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
|
||||
QObject::connect( m_pKeyDialog, SIGNAL( clicked() ), this, SLOT( pushButtonKeyClicked()) );
|
||||
QObject::connect( m_pCertDialog, SIGNAL( clicked() ), this, SLOT( pushButtonCertClicked()) );
|
||||
QObject::connect( m_pOK, SIGNAL( clicked() ), this, SLOT( pushButtonOKClicked()) );
|
||||
|
||||
CalculatePlaces();
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
}
|
||||
|
||||
void MainWindow::resizeEvent(QResizeEvent* e)
|
||||
{
|
||||
CalculatePlaces();
|
||||
}
|
||||
|
||||
void MainWindow::CalculatePlaces()
|
||||
{
|
||||
int nWidth = this->width();
|
||||
int nHeight = this->height();
|
||||
|
||||
int nWidthBetween = 30;
|
||||
int nWidthButton = 40;
|
||||
int nWidthPassword = 40;
|
||||
int nHeightLine = 30;
|
||||
int nWidthPath = nWidth - 40 - 2 * nWidthBetween - nWidthButton - nWidthPassword;
|
||||
if (nWidthPath < 20)
|
||||
nWidthPath = 20;
|
||||
|
||||
int nTop1 = 20;
|
||||
m_pKeyFile->setGeometry(20, nTop1, nWidthPath, nHeightLine);
|
||||
m_pKeyPassword->setGeometry(20 + nWidthPath + nWidthBetween, nTop1, nWidthPassword, nHeightLine);
|
||||
m_pKeyDialog->setGeometry(nWidth - 20 - nWidthButton, nTop1, nWidthButton, nHeightLine);
|
||||
|
||||
nTop1 = 20 + nHeightLine + 20;
|
||||
m_pCertFile->setGeometry(20, nTop1, nWidthPath, nHeightLine);
|
||||
m_pCertPassword->setGeometry(20 + nWidthPath + nWidthBetween, nTop1, nWidthPassword, nHeightLine);
|
||||
m_pCertDialog->setGeometry(nWidth - 20 - nWidthButton, nTop1, nWidthButton, nHeightLine);
|
||||
|
||||
m_pOK->setGeometry((nWidth - 40) >> 1, nTop1 + nHeightLine + 20, 40, nHeightLine);
|
||||
}
|
||||
|
||||
void MainWindow::pushButtonKeyClicked()
|
||||
{
|
||||
std::wstring sFile = QFileDialog::getOpenFileName(NULL, QString(), QString()).toStdWString();
|
||||
if (sFile.empty())
|
||||
return;
|
||||
|
||||
m_pKeyFile->setPlainText(QString::fromStdWString(sFile));
|
||||
}
|
||||
|
||||
void MainWindow::pushButtonCertClicked()
|
||||
{
|
||||
std::wstring sFile = QFileDialog::getOpenFileName(NULL, QString(), QString()).toStdWString();
|
||||
if (sFile.empty())
|
||||
return;
|
||||
|
||||
m_pCertFile->setPlainText(QString::fromStdWString(sFile));
|
||||
}
|
||||
|
||||
void MainWindow::pushButtonOKClicked()
|
||||
{
|
||||
COpenssl_library library;
|
||||
int nKeyValue = library.LoadKey(m_pKeyFile->toPlainText().toStdWString(), m_pKeyPassword->toPlainText().toStdString());
|
||||
int nCertValue = library.LoadCert(m_pCertFile->toPlainText().toStdWString(), m_pCertPassword->toPlainText().toStdString());
|
||||
|
||||
int y = 0;
|
||||
y++;
|
||||
}
|
||||
44
DesktopEditor/xmlsec/test/OpenSSL_gui_test/mainwindow.h
Normal file
44
DesktopEditor/xmlsec/test/OpenSSL_gui_test/mainwindow.h
Normal file
@ -0,0 +1,44 @@
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QTextEdit>
|
||||
#include <QPushButton>
|
||||
#include <QResizeEvent>
|
||||
#include <QPlainTextEdit>
|
||||
#include "opensslwrapper.h"
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = 0);
|
||||
~MainWindow();
|
||||
|
||||
virtual void resizeEvent(QResizeEvent*);
|
||||
void CalculatePlaces();
|
||||
|
||||
public:
|
||||
|
||||
QPlainTextEdit* m_pKeyFile;
|
||||
QPlainTextEdit* m_pKeyPassword;
|
||||
QPushButton* m_pKeyDialog;
|
||||
|
||||
QPlainTextEdit* m_pCertFile;
|
||||
QPlainTextEdit* m_pCertPassword;
|
||||
QPushButton* m_pCertDialog;
|
||||
|
||||
QPushButton* m_pOK;
|
||||
|
||||
public slots:
|
||||
void pushButtonKeyClicked();
|
||||
void pushButtonCertClicked();
|
||||
void pushButtonOKClicked();
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
247
DesktopEditor/xmlsec/test/OpenSSL_gui_test/opensslwrapper.cpp
Normal file
247
DesktopEditor/xmlsec/test/OpenSSL_gui_test/opensslwrapper.cpp
Normal file
@ -0,0 +1,247 @@
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/pkcs12.h>
|
||||
|
||||
#include <openssl/sha.h>
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/engine.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/conf.h>
|
||||
|
||||
#include "../../../common/File.h"
|
||||
#include "../../../common/String.h"
|
||||
#include "opensslwrapper.h"
|
||||
|
||||
class COpenssl_library_private
|
||||
{
|
||||
private:
|
||||
static bool m_bInit;
|
||||
|
||||
public:
|
||||
EVP_PKEY* m_key;
|
||||
|
||||
public:
|
||||
COpenssl_library_private()
|
||||
{
|
||||
if (!m_bInit)
|
||||
{
|
||||
SSL_library_init();
|
||||
OpenSSL_add_all_algorithms();
|
||||
ERR_load_BIO_strings();
|
||||
ERR_load_crypto_strings();
|
||||
m_bInit = true;
|
||||
}
|
||||
}
|
||||
~COpenssl_library_private()
|
||||
{
|
||||
ENGINE_cleanup();
|
||||
CONF_modules_unload(1);
|
||||
ERR_free_strings();
|
||||
EVP_cleanup();
|
||||
CRYPTO_cleanup_all_ex_data();
|
||||
}
|
||||
};
|
||||
|
||||
bool COpenssl_library_private::m_bInit = false;
|
||||
|
||||
std::string GetOpenSslErrors()
|
||||
{
|
||||
BIO* bio = BIO_new(BIO_s_mem());
|
||||
ERR_print_errors(bio);
|
||||
char *buf = NULL;
|
||||
size_t len = BIO_get_mem_data(bio, &buf);
|
||||
std::string sRet((char*)buf, len);
|
||||
NSStringExt::ToLower(sRet);
|
||||
BIO_free (bio);
|
||||
return sRet;
|
||||
}
|
||||
bool IsOpenSslPasswordError(const std::string& str)
|
||||
{
|
||||
if (std::string::npos != str.find("mac verify error"))
|
||||
return true;
|
||||
if (std::string::npos != str.find("mac verify failure"))
|
||||
return true;
|
||||
if (std::string::npos != str.find("password"))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
COpenssl_library::COpenssl_library()
|
||||
{
|
||||
m_internal = new COpenssl_library_private();
|
||||
}
|
||||
|
||||
COpenssl_library::~COpenssl_library()
|
||||
{
|
||||
RELEASEOBJECT(m_internal);
|
||||
}
|
||||
|
||||
int COpenssl_library::LoadKey(std::wstring file, std::string password)
|
||||
{
|
||||
BYTE* pData = NULL;
|
||||
DWORD dwDataLen;
|
||||
if (!NSFile::CFileBinary::ReadAllBytes(file, &pData, dwDataLen))
|
||||
return OPEN_SSL_WARNING_ERR;
|
||||
|
||||
EVP_PKEY* pKey = NULL;
|
||||
char* pPassword = (password.empty()) ? NULL : (char*)password.c_str();
|
||||
|
||||
BIO* bio = BIO_new_mem_buf((void*)pData, (int)dwDataLen);
|
||||
if (PEM_read_bio_PrivateKey(bio, &pKey, NULL, (void*)pPassword))
|
||||
{
|
||||
EVP_PKEY_free(pKey);
|
||||
BIO_free(bio);
|
||||
return OPEN_SSL_WARNING_OK;
|
||||
}
|
||||
std::string sError = GetOpenSslErrors();
|
||||
if (IsOpenSslPasswordError(sError))
|
||||
{
|
||||
EVP_PKEY_free(pKey);
|
||||
BIO_free(bio);
|
||||
return OPEN_SSL_WARNING_PASS;
|
||||
}
|
||||
|
||||
BIO_free(bio);
|
||||
bio = BIO_new_mem_buf((void*)pData, (int)dwDataLen);
|
||||
if (d2i_PrivateKey_bio(bio, &pKey))
|
||||
{
|
||||
EVP_PKEY_free(pKey);
|
||||
BIO_free(bio);
|
||||
return OPEN_SSL_WARNING_OK;
|
||||
}
|
||||
sError = GetOpenSslErrors();
|
||||
if (IsOpenSslPasswordError(sError))
|
||||
{
|
||||
EVP_PKEY_free(pKey);
|
||||
BIO_free(bio);
|
||||
return OPEN_SSL_WARNING_PASS;
|
||||
}
|
||||
|
||||
BIO_free(bio);
|
||||
bio = BIO_new_mem_buf((void*)pData, (int)dwDataLen);
|
||||
if (d2i_PKCS8PrivateKey_bio(bio, &pKey, NULL, (void*)pPassword))
|
||||
{
|
||||
EVP_PKEY_free(pKey);
|
||||
BIO_free(bio);
|
||||
return OPEN_SSL_WARNING_OK;
|
||||
}
|
||||
sError = GetOpenSslErrors();
|
||||
if (IsOpenSslPasswordError(sError))
|
||||
{
|
||||
EVP_PKEY_free(pKey);
|
||||
BIO_free(bio);
|
||||
return OPEN_SSL_WARNING_PASS;
|
||||
}
|
||||
|
||||
BIO_free(bio);
|
||||
bio = BIO_new_mem_buf((void*)pData, (int)dwDataLen);
|
||||
|
||||
PKCS12* p12 = d2i_PKCS12_bio(bio, NULL);
|
||||
if (p12)
|
||||
{
|
||||
X509* pCert = NULL;
|
||||
STACK_OF(X509)* pCa = NULL;
|
||||
|
||||
if (PKCS12_parse(p12, pPassword, &pKey, &pCert, &pCa))
|
||||
{
|
||||
sk_X509_pop_free(pCa, X509_free);
|
||||
X509_free(pCert);
|
||||
EVP_PKEY_free(pKey);
|
||||
PKCS12_free(p12);
|
||||
BIO_free(bio);
|
||||
return OPEN_SSL_WARNING_ALL_OK;
|
||||
}
|
||||
|
||||
sError = GetOpenSslErrors();
|
||||
if (IsOpenSslPasswordError(sError))
|
||||
{
|
||||
PKCS12_free(p12);
|
||||
BIO_free(bio);
|
||||
return OPEN_SSL_WARNING_PASS;
|
||||
}
|
||||
|
||||
PKCS12_free(p12);
|
||||
}
|
||||
|
||||
BIO_free(bio);
|
||||
|
||||
return OPEN_SSL_WARNING_ERR;
|
||||
}
|
||||
|
||||
int COpenssl_library::LoadCert(std::wstring file, std::string password)
|
||||
{
|
||||
BYTE* pData = NULL;
|
||||
DWORD dwDataLen;
|
||||
if (!NSFile::CFileBinary::ReadAllBytes(file, &pData, dwDataLen))
|
||||
return OPEN_SSL_WARNING_ERR;
|
||||
|
||||
X509* pCert = NULL;
|
||||
char* pPassword = (password.empty()) ? NULL : (char*)password.c_str();
|
||||
|
||||
BIO* bio = BIO_new_mem_buf((void*)pData, (int)dwDataLen);
|
||||
if (PEM_read_bio_X509(bio, &pCert, NULL, (void*)pPassword))
|
||||
{
|
||||
X509_free(pCert);
|
||||
BIO_free(bio);
|
||||
return OPEN_SSL_WARNING_OK;
|
||||
}
|
||||
std::string sError = GetOpenSslErrors();
|
||||
if (IsOpenSslPasswordError(sError))
|
||||
{
|
||||
X509_free(pCert);
|
||||
BIO_free(bio);
|
||||
return OPEN_SSL_WARNING_PASS;
|
||||
}
|
||||
|
||||
BIO_free(bio);
|
||||
bio = BIO_new_mem_buf((void*)pData, (int)dwDataLen);
|
||||
if (d2i_X509_bio(bio, &pCert))
|
||||
{
|
||||
X509_free(pCert);
|
||||
BIO_free(bio);
|
||||
return OPEN_SSL_WARNING_OK;
|
||||
}
|
||||
sError = GetOpenSslErrors();
|
||||
if (IsOpenSslPasswordError(sError))
|
||||
{
|
||||
X509_free(pCert);
|
||||
BIO_free(bio);
|
||||
return OPEN_SSL_WARNING_PASS;
|
||||
}
|
||||
|
||||
BIO_free(bio);
|
||||
bio = BIO_new_mem_buf((void*)pData, (int)dwDataLen);
|
||||
|
||||
PKCS12* p12 = d2i_PKCS12_bio(bio, NULL);
|
||||
if (p12)
|
||||
{
|
||||
EVP_PKEY* pKey = NULL;
|
||||
STACK_OF(X509)* pCa = NULL;
|
||||
|
||||
if (PKCS12_parse(p12, pPassword, &pKey, &pCert, &pCa))
|
||||
{
|
||||
sk_X509_pop_free(pCa, X509_free);
|
||||
X509_free(pCert);
|
||||
EVP_PKEY_free(pKey);
|
||||
PKCS12_free(p12);
|
||||
BIO_free(bio);
|
||||
return OPEN_SSL_WARNING_ALL_OK;
|
||||
}
|
||||
|
||||
sError = GetOpenSslErrors();
|
||||
if (IsOpenSslPasswordError(sError))
|
||||
{
|
||||
PKCS12_free(p12);
|
||||
BIO_free(bio);
|
||||
return OPEN_SSL_WARNING_PASS;
|
||||
}
|
||||
|
||||
PKCS12_free(p12);
|
||||
}
|
||||
|
||||
BIO_free(bio);
|
||||
return OPEN_SSL_WARNING_ERR;
|
||||
}
|
||||
23
DesktopEditor/xmlsec/test/OpenSSL_gui_test/opensslwrapper.h
Normal file
23
DesktopEditor/xmlsec/test/OpenSSL_gui_test/opensslwrapper.h
Normal file
@ -0,0 +1,23 @@
|
||||
#ifndef OPENSSL_WRAPPER
|
||||
#define OPENSSL_WRAPPER
|
||||
|
||||
#define OPEN_SSL_WARNING_OK 0
|
||||
#define OPEN_SSL_WARNING_ERR 1
|
||||
#define OPEN_SSL_WARNING_ALL_OK 2
|
||||
#define OPEN_SSL_WARNING_PASS 4
|
||||
|
||||
class COpenssl_library_private;
|
||||
class COpenssl_library
|
||||
{
|
||||
private:
|
||||
COpenssl_library_private* m_internal;
|
||||
|
||||
public:
|
||||
COpenssl_library();
|
||||
~COpenssl_library();
|
||||
|
||||
int LoadKey(std::wstring file, std::string password);
|
||||
int LoadCert(std::wstring file, std::string password);
|
||||
};
|
||||
|
||||
#endif // OPENSSL_WRAPPER
|
||||
@ -5,10 +5,46 @@
|
||||
#include <openssl/pkcs12.h>
|
||||
|
||||
#include <openssl/sha.h>
|
||||
#include <openssl/ssl.h>
|
||||
|
||||
#include "../../../common/File.h"
|
||||
|
||||
#if 0
|
||||
static time_t ASN1_GetTimeT(ASN1_TIME* time)
|
||||
{
|
||||
struct tm t;
|
||||
const char* str = (const char*) time->data;
|
||||
size_t i = 0;
|
||||
|
||||
memset(&t, 0, sizeof(t));
|
||||
|
||||
if (time->type == V_ASN1_UTCTIME) {/* two digit year */
|
||||
t.tm_year = (str[i++] - '0') * 10;
|
||||
t.tm_year += (str[i++] - '0');
|
||||
if (t.tm_year < 70)
|
||||
t.tm_year += 100;
|
||||
} else if (time->type == V_ASN1_GENERALIZEDTIME) {/* four digit year */
|
||||
t.tm_year = (str[i++] - '0') * 1000;
|
||||
t.tm_year+= (str[i++] - '0') * 100;
|
||||
t.tm_year+= (str[i++] - '0') * 10;
|
||||
t.tm_year+= (str[i++] - '0');
|
||||
t.tm_year -= 1900;
|
||||
}
|
||||
t.tm_mon = (str[i++] - '0') * 10;
|
||||
t.tm_mon += (str[i++] - '0') - 1; // -1 since January is 0 not 1.
|
||||
t.tm_mday = (str[i++] - '0') * 10;
|
||||
t.tm_mday+= (str[i++] - '0');
|
||||
t.tm_hour = (str[i++] - '0') * 10;
|
||||
t.tm_hour+= (str[i++] - '0');
|
||||
t.tm_min = (str[i++] - '0') * 10;
|
||||
t.tm_min += (str[i++] - '0');
|
||||
t.tm_sec = (str[i++] - '0') * 10;
|
||||
t.tm_sec += (str[i++] - '0');
|
||||
|
||||
/* Note: we did not adjust the time based on time zone information */
|
||||
return mktime(&t);
|
||||
}
|
||||
|
||||
#if 1
|
||||
int main()
|
||||
{
|
||||
std::wstring sFolderW = NSFile::GetProcessDirectory();
|
||||
@ -55,6 +91,10 @@ int main()
|
||||
if (asn1_serial == NULL)
|
||||
BIO_printf(outbio, "Error getting serial number from certificate");
|
||||
|
||||
ASN1_TIME* _time = X509_get_notBefore(cert);
|
||||
const char* s = (const char*)_time->data;
|
||||
time_t time1 = ASN1_GetTimeT(_time);
|
||||
|
||||
/* ---------------------------------------------------------- *
|
||||
* Print the serial number value, openssl x509 -serial style *
|
||||
* ---------------------------------------------------------- */
|
||||
@ -118,6 +158,7 @@ int main(int argc, char **argv)
|
||||
STACK_OF(X509) *ca = NULL;
|
||||
PKCS12 *p12;
|
||||
|
||||
SSL_library_init();
|
||||
OpenSSL_add_all_algorithms();
|
||||
ERR_load_crypto_strings();
|
||||
|
||||
@ -194,7 +235,7 @@ int main()
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
#if 0
|
||||
int main()
|
||||
{
|
||||
std::wstring sFolderW = NSFile::GetProcessDirectory();
|
||||
|
||||
@ -18,7 +18,7 @@ DEFINES += XMLSEC_OPENSSL_110
|
||||
|
||||
INCLUDEPATH += $$PWD/../../openssl/include
|
||||
|
||||
LIBS += -L$$PWD/../../openssl -lcrypto -lssl
|
||||
LIBS += -L$$PWD/../../openssl -lssl -lcrypto
|
||||
LIBS += -ldl
|
||||
|
||||
SOURCES += main.cpp
|
||||
|
||||
6
Makefile
6
Makefile
@ -21,11 +21,11 @@ else
|
||||
LIB_PREFIX := lib
|
||||
MAKE := make -j $(shell grep -c ^processor /proc/cpuinfo)
|
||||
endif
|
||||
UNAME_P := $(shell uname -p)
|
||||
ifeq ($(UNAME_P),x86_64)
|
||||
UNAME_M := $(shell uname -m)
|
||||
ifeq ($(UNAME_M),x86_64)
|
||||
ARCHITECTURE := 64
|
||||
endif
|
||||
ifneq ($(filter %86,$(UNAME_P)),)
|
||||
ifneq ($(filter %86,$(UNAME_M)),)
|
||||
ARCHITECTURE := 32
|
||||
endif
|
||||
endif
|
||||
|
||||
@ -262,9 +262,9 @@ namespace PdfReader
|
||||
}
|
||||
void CPdfReader::ConvertToRaster(int nPageIndex, const std::wstring& wsDstPath, int nImageType, const int nRasterW, const int nRasterH)
|
||||
{
|
||||
CFontManager *pFontManager = m_pInternal->m_pAppFonts->GenerateFontManager();
|
||||
CFontManager *pFontManager = m_pInternal->m_pAppFonts->GenerateFontManager();
|
||||
CFontsCache* pFontCache = new CFontsCache();
|
||||
pFontCache->SetStreams(m_pInternal->m_pAppFonts->GetStreams());
|
||||
pFontCache->SetStreams(m_pInternal->m_pAppFonts->GetStreams());
|
||||
pFontManager->SetOwnerCache(pFontCache);
|
||||
|
||||
CGraphicsRenderer oRenderer;
|
||||
|
||||
@ -47,6 +47,7 @@
|
||||
#include "GFont.h"
|
||||
#include "File.h"
|
||||
#include "Stream.h"
|
||||
#include "XRef.h"
|
||||
|
||||
namespace PdfReader
|
||||
{
|
||||
@ -1945,12 +1946,10 @@ namespace PdfReader
|
||||
}
|
||||
else
|
||||
{
|
||||
// Нет ссылки на данный шрифт, но ссылка нам нужна как идентефикатор, поэтому выбираем некотый уникальный номер
|
||||
// (поскольку корректное версионное число состоит из 5 цифр, поэтому любое 6-циферное число будет безопасным решением)
|
||||
oRef.nNum = nIndex;
|
||||
if (pFontDictRef)
|
||||
if (pXref)
|
||||
{
|
||||
oRef.nGen = 100000 + pFontDictRef->nNum;
|
||||
oRef.nGen = pXref->GenerateUniqueRefGen();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1998,4 +1997,4 @@ namespace PdfReader
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,25 +69,35 @@ namespace PdfReader
|
||||
}
|
||||
bool operator <(const Ref& oRight)const
|
||||
{
|
||||
return nNum < oRight.nNum;
|
||||
if (nNum < oRight.nNum)
|
||||
return true;
|
||||
else if (nNum == oRight.nNum)
|
||||
return nGen < oRight.nGen;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
bool operator >(const Ref& oRight)const
|
||||
{
|
||||
return nNum > oRight.nNum;
|
||||
if (nNum > oRight.nNum)
|
||||
return true;
|
||||
else if (nNum == oRight.nNum)
|
||||
return nGen > oRight.nGen;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
bool operator <=(const Ref& oRight)const
|
||||
{
|
||||
if (*this == oRight)
|
||||
return true;
|
||||
|
||||
return nNum < oRight.nNum;
|
||||
return (*this < oRight);
|
||||
}
|
||||
bool operator >=(const Ref& oRight)const
|
||||
{
|
||||
if (*this == oRight)
|
||||
return true;
|
||||
|
||||
return nNum > oRight.nNum;
|
||||
return (*this > oRight);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -345,7 +345,7 @@ namespace PdfReader
|
||||
m_bTransparentGroupSoftMask = false;
|
||||
m_pTransparentGroupSoftMask = NULL;
|
||||
|
||||
m_bDrawOnlyText = false;
|
||||
m_bDrawOnlyText = false;
|
||||
|
||||
//m_oFontList.LoadFromFile( m_pGlobalParams->GetTempFolder() );
|
||||
//// Тестовый пример
|
||||
@ -461,7 +461,7 @@ namespace PdfReader
|
||||
if (c_nHtmlRendrerer2 == m_lRendererType)
|
||||
m_bDrawOnlyText = ((NSHtmlRenderer::CASCHTMLRenderer3*)m_pRenderer)->GetOnlyTextMode();
|
||||
else
|
||||
m_bDrawOnlyText = false;
|
||||
m_bDrawOnlyText = false;
|
||||
}
|
||||
void RendererOutputDev::EndPage()
|
||||
{
|
||||
@ -2982,39 +2982,36 @@ namespace PdfReader
|
||||
double *pCTM = pGState->GetCTM();
|
||||
double *pTm = pGState->GetTextMatrix();
|
||||
GrFont *pFont = pGState->GetFont();
|
||||
//double dTfs = pGState->GetFontSize();
|
||||
//double dTh = pGState->GetHorizScaling();
|
||||
//double dTrise = pGState->GetRise();
|
||||
//double *pFontBBox = pGState->GetFont()->GetFontBBox();
|
||||
|
||||
//double dAcsentFactor = ( ( fabs(pFontBBox[1]) + fabs(pFontBBox[3]) ) - ( pFont->GetAscent() + fabs( pFont->GetDescent() ) ) ) / 2 + pFont->GetAscent();
|
||||
double pNewTm[6], arrMatrix[6];
|
||||
//double dKoef = 0;//( pFont->GetAscent() - fabs( pFont->GetDescent() ) ) * dTfs;
|
||||
|
||||
double dTextScale = min(sqrt(pTm[2] * pTm[2] + pTm[3] * pTm[3]), sqrt(pTm[0] * pTm[0] + pTm[1] * pTm[1]));
|
||||
double dITextScale = 1 / dTextScale;
|
||||
|
||||
//pTm[0] *= dITextScale;
|
||||
//pTm[1] *= dITextScale;
|
||||
//pTm[2] *= dITextScale;
|
||||
//pTm[3] *= dITextScale;
|
||||
|
||||
//double dOldSize = m_oFont.Size;
|
||||
//m_oFont.Size *= dTextScale;
|
||||
double dOldSize = 10.0;
|
||||
m_pRenderer->get_FontSize(&dOldSize);
|
||||
m_pRenderer->put_FontSize(dOldSize * dTextScale);
|
||||
if (dOldSize * dTextScale > 0)
|
||||
{
|
||||
m_pRenderer->put_FontSize(dOldSize * dTextScale);
|
||||
|
||||
pNewTm[0] = pTm[0] * dITextScale;
|
||||
pNewTm[1] = pTm[1] * dITextScale;
|
||||
pNewTm[2] = -pTm[2] * dITextScale;
|
||||
pNewTm[3] = -pTm[3] * dITextScale;
|
||||
pNewTm[4] = dX;
|
||||
pNewTm[5] = dY;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pRenderer->put_FontSize(-dOldSize * dTextScale);
|
||||
|
||||
pNewTm[0] = pTm[0] * dITextScale;
|
||||
pNewTm[1] = pTm[1] * dITextScale;
|
||||
pNewTm[2] = pTm[2] * dITextScale;
|
||||
pNewTm[3] = pTm[3] * dITextScale;
|
||||
pNewTm[4] = dX;
|
||||
pNewTm[5] = dY;
|
||||
}
|
||||
|
||||
pNewTm[0] = pTm[0] * dITextScale;
|
||||
pNewTm[1] = pTm[1] * dITextScale;
|
||||
pNewTm[2] = -pTm[2] * dITextScale;
|
||||
pNewTm[3] = -pTm[3] * dITextScale;
|
||||
//pNewTm[0] = pTm[0];
|
||||
//pNewTm[1] = pTm[1];
|
||||
//pNewTm[2] = -pTm[2];
|
||||
//pNewTm[3] = -pTm[3];
|
||||
pNewTm[4] = dX;//+ pTm[2] * dKoef;
|
||||
pNewTm[5] = dY;//+ pTm[3] * dKoef;
|
||||
|
||||
arrMatrix[0] = pNewTm[0] * pCTM[0] + pNewTm[1] * pCTM[2];
|
||||
arrMatrix[1] = -(pNewTm[0] * pCTM[1] + pNewTm[1] * pCTM[3]);
|
||||
@ -3023,31 +3020,26 @@ namespace PdfReader
|
||||
arrMatrix[4] = pNewTm[4] * pCTM[0] + pNewTm[5] * pCTM[2] + pCTM[4];
|
||||
arrMatrix[5] = -(pNewTm[4] * pCTM[1] + pNewTm[5] * pCTM[3] + pCTM[5]) + pGState->GetPageHeight();
|
||||
|
||||
//double dAscentShiftX = arrMatrix[2] * pFont->GetDescent();
|
||||
//double dAscentShiftY = arrMatrix[3] * pFont->GetDescent();
|
||||
|
||||
//arrMatrix[4] += dAscentShiftX;
|
||||
//arrMatrix[5] += dAscentShiftY;
|
||||
|
||||
|
||||
if (true)
|
||||
{
|
||||
double dDet = sqrt(arrMatrix[0] * arrMatrix[3] - arrMatrix[1] * arrMatrix[2]);
|
||||
arrMatrix[0] /= dDet;
|
||||
arrMatrix[1] /= dDet;
|
||||
arrMatrix[2] /= dDet;
|
||||
arrMatrix[3] /= dDet;
|
||||
double dNorma = min(sqrt(arrMatrix[0] * arrMatrix[0] + arrMatrix[1] * arrMatrix[1]), sqrt(arrMatrix[2] * arrMatrix[2] + arrMatrix[3] * arrMatrix[3]));
|
||||
if (dNorma > 0.001)
|
||||
{
|
||||
arrMatrix[0] /= dNorma;
|
||||
arrMatrix[1] /= dNorma;
|
||||
arrMatrix[2] /= dNorma;
|
||||
arrMatrix[3] /= dNorma;
|
||||
|
||||
double dSize = 1;
|
||||
m_pRenderer->get_FontSize(&dSize);
|
||||
m_pRenderer->put_FontSize(dSize * dDet);
|
||||
double dSize = 1;
|
||||
m_pRenderer->get_FontSize(&dSize);
|
||||
m_pRenderer->put_FontSize(dSize * dNorma);
|
||||
}
|
||||
}
|
||||
|
||||
double dShiftX = 0, dShiftY = 0;
|
||||
DoTransform(arrMatrix, &dShiftX, &dShiftY, true);
|
||||
|
||||
// Здесь мы посылаем координаты текста в пунктах
|
||||
|
||||
double dPageHeight = pGState->GetPageHeight();
|
||||
|
||||
std::wstring wsUnicodeText;
|
||||
|
||||
@ -241,6 +241,10 @@ namespace PdfReader
|
||||
m_nPermissionFlags = DefaultPermissionFlags;
|
||||
m_bOwnerPassword = false;
|
||||
|
||||
// Если нет ссылки на данный объект, а ссылка нам нужна как идентефикатор, то выбираем некотый уникальный номер
|
||||
// (поскольку корректное версионное число состоит из 5 цифр, поэтому любое 6-циферное число будет безопасным решением)
|
||||
m_unRefGenCounter = 100000;
|
||||
|
||||
// Читаем Trailer
|
||||
m_pStream = pStream;
|
||||
m_nStart = m_pStream->GetStartPos();
|
||||
@ -1066,4 +1070,4 @@ namespace PdfReader
|
||||
}
|
||||
return unRes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -142,6 +142,10 @@ namespace PdfReader
|
||||
{
|
||||
return &m_oTrailerDict;
|
||||
}
|
||||
unsigned int GenerateUniqueRefGen()
|
||||
{
|
||||
return m_unRefGenCounter++;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@ -181,6 +185,8 @@ namespace PdfReader
|
||||
int m_nEncryptVersion; // Версия шифровки
|
||||
CryptAlgorithm m_eEncryptAlgorithm; // Алгоритм шифрования
|
||||
|
||||
unsigned int m_unRefGenCounter; // Специальный счетчик для генерации уникальных ссылок для встроенных объектов
|
||||
|
||||
NSCriticalSection::CRITICAL_SECTION m_oCS;
|
||||
};
|
||||
}
|
||||
|
||||
@ -187,7 +187,10 @@ namespace BinXlsxRW
|
||||
ExternalReferences = 5,
|
||||
ExternalReference = 6,
|
||||
PivotCaches = 7,
|
||||
PivotCache = 8
|
||||
PivotCache = 8,
|
||||
ExternalBook = 9,
|
||||
OleLink = 10,
|
||||
DdeLink = 11
|
||||
};}
|
||||
namespace c_oSerWorkbookPrTypes{enum c_oSerWorkbookPrTypes
|
||||
{
|
||||
@ -819,6 +822,53 @@ namespace BinXlsxRW
|
||||
cacheId = 3,
|
||||
table = 4
|
||||
};}
|
||||
namespace c_oSer_ExternalLinkTypes{enum c_oSer_ExternalLinkTypes
|
||||
{
|
||||
Id = 0,
|
||||
SheetNames = 1,
|
||||
SheetName = 2,
|
||||
DefinedNames = 3,
|
||||
DefinedName = 4,
|
||||
DefinedNameName = 5,
|
||||
DefinedNameRefersTo = 6,
|
||||
DefinedNameSheetId = 7,
|
||||
SheetDataSet = 8,
|
||||
SheetData = 9,
|
||||
SheetDataSheetId = 10,
|
||||
SheetDataRefreshError = 11,
|
||||
SheetDataRow = 12,
|
||||
SheetDataRowR = 13,
|
||||
SheetDataRowCell = 14,
|
||||
SheetDataRowCellRef = 15,
|
||||
SheetDataRowCellType = 16,
|
||||
SheetDataRowCellValue = 17
|
||||
};}
|
||||
namespace c_oSer_OleLinkTypes{enum c_oSer_OleLinkTypes
|
||||
{
|
||||
Id = 0,
|
||||
ProgId = 1,
|
||||
OleItem = 2,
|
||||
Name = 3,
|
||||
Icon = 4,
|
||||
Advise = 5,
|
||||
PreferPic = 6
|
||||
};}
|
||||
namespace c_oSer_DdeLinkTypes{enum c_oSer_DdeLinkTypes
|
||||
{
|
||||
DdeService = 0,
|
||||
DdeTopic = 1,
|
||||
DdeItem = 2,
|
||||
Name = 3,
|
||||
Ole = 4,
|
||||
Advise = 5,
|
||||
PreferPic = 6,
|
||||
DdeValues = 7,
|
||||
DdeValuesRows = 8,
|
||||
DdeValuesCols = 9,
|
||||
DdeValue = 10,
|
||||
DdeValueType = 11,
|
||||
DdeValueVal = 12
|
||||
};}
|
||||
}
|
||||
|
||||
#endif //
|
||||
|
||||
@ -1583,26 +1583,54 @@ namespace BinXlsxRW
|
||||
if(pExternalReference->m_oRid.IsInit())
|
||||
{
|
||||
smart_ptr<OOX::File> pFile = workbook.Find( OOX::RId(pExternalReference->m_oRid->GetValue()));
|
||||
|
||||
|
||||
if (pFile.IsInit() && OOX::Spreadsheet::FileTypes::ExternalLinks == pFile->type())
|
||||
{
|
||||
OOX::Spreadsheet::CExternalLink* pExternalLink = static_cast<OOX::Spreadsheet::CExternalLink*>(pFile.operator ->());
|
||||
if ((pExternalLink) && (pExternalLink->m_oExternalBook.IsInit()))
|
||||
if (pExternalLink)
|
||||
{
|
||||
std::wstring sLink;
|
||||
if (pExternalLink->m_oExternalBook->m_oRid.IsInit())
|
||||
if(pExternalLink->m_oExternalBook.IsInit())
|
||||
{
|
||||
smart_ptr<OOX::File> pFile = pExternalLink->Find( OOX::RId(pExternalLink->m_oExternalBook->m_oRid.get().GetValue()));
|
||||
if (pFile.IsInit() && OOX::FileTypes::ExternalLinkPath == pFile->type())
|
||||
std::wstring sLink;
|
||||
if (pExternalLink->m_oExternalBook->m_oRid.IsInit())
|
||||
{
|
||||
OOX::Spreadsheet::ExternalLinkPath* pLinkFile = static_cast<OOX::Spreadsheet::ExternalLinkPath*>(pFile.operator ->());
|
||||
sLink = pLinkFile->Uri().GetPath();
|
||||
}
|
||||
smart_ptr<OOX::File> pFile = pExternalLink->Find( OOX::RId(pExternalLink->m_oExternalBook->m_oRid.get().GetValue()));
|
||||
if (pFile.IsInit() && OOX::FileTypes::ExternalLinkPath == pFile->type())
|
||||
{
|
||||
OOX::Spreadsheet::ExternalLinkPath* pLinkFile = static_cast<OOX::Spreadsheet::ExternalLinkPath*>(pFile.operator ->());
|
||||
sLink = pLinkFile->Uri().GetPath();
|
||||
}
|
||||
}
|
||||
if(!sLink.empty())
|
||||
{
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSerWorkbookTypes::ExternalBook);
|
||||
WriteExternalBook(pExternalLink->m_oExternalBook.get(), sLink);
|
||||
m_oBcw.WriteItemWithLengthEnd(nCurPos);
|
||||
}
|
||||
}
|
||||
if(!sLink.empty())
|
||||
else if(pExternalLink->m_oOleLink.IsInit())
|
||||
{
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSerWorkbookTypes::ExternalReference);
|
||||
m_oBcw.m_oStream.WriteStringW3(sLink);
|
||||
std::wstring sLink;
|
||||
if (pExternalLink->m_oOleLink->m_oRid.IsInit())
|
||||
{
|
||||
smart_ptr<OOX::File> pFile = pExternalLink->Find( OOX::RId(pExternalLink->m_oOleLink->m_oRid.get().GetValue()));
|
||||
if (pFile.IsInit() && OOX::FileTypes::OleObject == pFile->type())
|
||||
{
|
||||
OOX::OleObject* pLinkFile = static_cast<OOX::OleObject*>(pFile.operator ->());
|
||||
sLink = pLinkFile->filename().GetPath();
|
||||
}
|
||||
}
|
||||
if(!sLink.empty())
|
||||
{
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSerWorkbookTypes::OleLink);
|
||||
WriteOleLink(pExternalLink->m_oOleLink.get(), sLink);
|
||||
m_oBcw.WriteItemWithLengthEnd(nCurPos);
|
||||
}
|
||||
}
|
||||
else if(pExternalLink->m_oDdeLink.IsInit())
|
||||
{
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSerWorkbookTypes::DdeLink);
|
||||
WriteDdeLink(pExternalLink->m_oDdeLink.get());
|
||||
m_oBcw.WriteItemWithLengthEnd(nCurPos);
|
||||
}
|
||||
}
|
||||
@ -1610,6 +1638,292 @@ namespace BinXlsxRW
|
||||
}
|
||||
}
|
||||
};
|
||||
void WriteExternalBook(const OOX::Spreadsheet::CExternalBook& externalBook, const std::wstring& sLink)
|
||||
{
|
||||
int nCurPos = 0;
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSer_ExternalLinkTypes::Id);
|
||||
m_oBcw.m_oStream.WriteStringW3(sLink);
|
||||
m_oBcw.WriteItemWithLengthEnd(nCurPos);
|
||||
|
||||
if (externalBook.m_oSheetNames.IsInit())
|
||||
{
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSer_ExternalLinkTypes::SheetNames);
|
||||
WriteExternalSheetNames(externalBook.m_oSheetNames.get());
|
||||
m_oBcw.WriteItemWithLengthEnd(nCurPos);
|
||||
}
|
||||
if (externalBook.m_oDefinedNames.IsInit())
|
||||
{
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSer_ExternalLinkTypes::DefinedNames);
|
||||
WriteExternalDefinedNames(externalBook.m_oDefinedNames.get());
|
||||
m_oBcw.WriteItemWithLengthEnd(nCurPos);
|
||||
}
|
||||
if (externalBook.m_oSheetDataSet.IsInit())
|
||||
{
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSer_ExternalLinkTypes::SheetDataSet);
|
||||
WriteExternalSheetDataSet(externalBook.m_oSheetDataSet.get());
|
||||
m_oBcw.WriteItemWithLengthEnd(nCurPos);
|
||||
}
|
||||
}
|
||||
void WriteExternalSheetNames(const OOX::Spreadsheet::CExternalSheetNames& sheetNames)
|
||||
{
|
||||
int nCurPos = 0;
|
||||
for (size_t i = 0, length = sheetNames.m_arrItems.size(); i < length; ++i)
|
||||
{
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSer_ExternalLinkTypes::SheetName);
|
||||
m_oBcw.m_oStream.WriteStringW3(sheetNames.m_arrItems[i]->ToString2());
|
||||
m_oBcw.WriteItemWithLengthEnd(nCurPos);
|
||||
}
|
||||
}
|
||||
void WriteExternalDefinedNames(const OOX::Spreadsheet::CExternalDefinedNames& definedNames)
|
||||
{
|
||||
int nCurPos = 0;
|
||||
for (size_t i = 0, length = definedNames.m_arrItems.size(); i < length; ++i)
|
||||
{
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSer_ExternalLinkTypes::DefinedName);
|
||||
WriteExternalDefinedName(*definedNames.m_arrItems[i]);
|
||||
m_oBcw.WriteItemWithLengthEnd(nCurPos);
|
||||
}
|
||||
}
|
||||
void WriteExternalDefinedName(const OOX::Spreadsheet::CExternalDefinedName& definedName)
|
||||
{
|
||||
int nCurPos = 0;
|
||||
if (definedName.m_oName.IsInit())
|
||||
{
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSer_ExternalLinkTypes::DefinedNameName);
|
||||
m_oBcw.m_oStream.WriteStringW3(definedName.m_oName.get());
|
||||
m_oBcw.WriteItemWithLengthEnd(nCurPos);
|
||||
}
|
||||
if (definedName.m_oRefersTo.IsInit())
|
||||
{
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSer_ExternalLinkTypes::DefinedNameRefersTo);
|
||||
m_oBcw.m_oStream.WriteStringW3(definedName.m_oRefersTo.get());
|
||||
m_oBcw.WriteItemWithLengthEnd(nCurPos);
|
||||
}
|
||||
if (definedName.m_oSheetId.IsInit())
|
||||
{
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSer_ExternalLinkTypes::DefinedNameSheetId);
|
||||
m_oBcw.m_oStream.WriteULONG(definedName.m_oSheetId->GetValue());
|
||||
m_oBcw.WriteItemWithLengthEnd(nCurPos);
|
||||
}
|
||||
}
|
||||
void WriteExternalSheetDataSet(const OOX::Spreadsheet::CExternalSheetDataSet& sheetDataSet)
|
||||
{
|
||||
int nCurPos = 0;
|
||||
for (size_t i = 0, length = sheetDataSet.m_arrItems.size(); i < length; ++i)
|
||||
{
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSer_ExternalLinkTypes::SheetData);
|
||||
WriteExternalSheetData(*sheetDataSet.m_arrItems[i]);
|
||||
m_oBcw.WriteItemWithLengthEnd(nCurPos);
|
||||
}
|
||||
}
|
||||
void WriteExternalSheetData(const OOX::Spreadsheet::CExternalSheetData& sheetData)
|
||||
{
|
||||
int nCurPos = 0;
|
||||
if(sheetData.m_oSheetId.IsInit())
|
||||
{
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSer_ExternalLinkTypes::SheetDataSheetId);
|
||||
m_oBcw.m_oStream.WriteULONG(sheetData.m_oSheetId->GetValue());
|
||||
m_oBcw.WriteItemWithLengthEnd(nCurPos);
|
||||
}
|
||||
if(sheetData.m_oRefreshError.IsInit())
|
||||
{
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSer_ExternalLinkTypes::SheetDataRefreshError);
|
||||
m_oBcw.m_oStream.WriteBOOL(sheetData.m_oRefreshError->ToBool());
|
||||
m_oBcw.WriteItemWithLengthEnd(nCurPos);
|
||||
}
|
||||
for (size_t i = 0, length = sheetData.m_arrItems.size(); i < length; ++i)
|
||||
{
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSer_ExternalLinkTypes::SheetDataRow);
|
||||
WriteExternalRow(*sheetData.m_arrItems[i]);
|
||||
m_oBcw.WriteItemEnd(nCurPos);
|
||||
}
|
||||
}
|
||||
void WriteExternalRow(const OOX::Spreadsheet::CExternalRow& row)
|
||||
{
|
||||
int nCurPos = 0;
|
||||
if(row.m_oR.IsInit())
|
||||
{
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSer_ExternalLinkTypes::SheetDataRowR);
|
||||
m_oBcw.m_oStream.WriteULONG(row.m_oR->GetValue());
|
||||
m_oBcw.WriteItemWithLengthEnd(nCurPos);
|
||||
}
|
||||
for (size_t i = 0, length = row.m_arrItems.size(); i < length; ++i)
|
||||
{
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSer_ExternalLinkTypes::SheetDataRowCell);
|
||||
WriteExternalCell(*row.m_arrItems[i]);
|
||||
m_oBcw.WriteItemEnd(nCurPos);
|
||||
}
|
||||
}
|
||||
void WriteExternalCell(const OOX::Spreadsheet::CExternalCell& cell)
|
||||
{
|
||||
int nCurPos = 0;
|
||||
if(cell.m_oRef.IsInit())
|
||||
{
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSer_ExternalLinkTypes::SheetDataRowCellRef);
|
||||
m_oBcw.m_oStream.WriteStringW3(cell.m_oRef.get());
|
||||
m_oBcw.WriteItemWithLengthEnd(nCurPos);
|
||||
}
|
||||
if(cell.m_oType.IsInit())
|
||||
{
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSer_ExternalLinkTypes::SheetDataRowCellType);
|
||||
m_oBcw.m_oStream.WriteBYTE(cell.m_oType->GetValue());
|
||||
m_oBcw.WriteItemWithLengthEnd(nCurPos);
|
||||
}
|
||||
if(cell.m_oValue.IsInit())
|
||||
{
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSer_ExternalLinkTypes::SheetDataRowCellValue);
|
||||
m_oBcw.m_oStream.WriteStringW3(cell.m_oValue->ToString());
|
||||
m_oBcw.WriteItemWithLengthEnd(nCurPos);
|
||||
}
|
||||
}
|
||||
void WriteOleLink(const OOX::Spreadsheet::COleLink& oleLink, const std::wstring& sLink)
|
||||
{
|
||||
int nCurPos = 0;
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSer_OleLinkTypes::Id);
|
||||
m_oBcw.m_oStream.WriteStringW3(sLink);
|
||||
m_oBcw.WriteItemWithLengthEnd(nCurPos);
|
||||
|
||||
if (oleLink.m_oProgId.IsInit())
|
||||
{
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSer_OleLinkTypes::ProgId);
|
||||
m_oBcw.m_oStream.WriteStringW3(oleLink.m_oProgId.get());
|
||||
m_oBcw.WriteItemWithLengthEnd(nCurPos);
|
||||
}
|
||||
if (oleLink.m_oOleItems.IsInit())
|
||||
{
|
||||
for(size_t i = 0; i < oleLink.m_oOleItems->m_arrItems.size(); ++i)
|
||||
{
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSer_OleLinkTypes::OleItem);
|
||||
WriteOleItem(*oleLink.m_oOleItems->m_arrItems[i]);
|
||||
m_oBcw.WriteItemWithLengthEnd(nCurPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
void WriteOleItem(const OOX::Spreadsheet::COleItem& oleItem)
|
||||
{
|
||||
int nCurPos = 0;
|
||||
if (oleItem.m_oName.IsInit())
|
||||
{
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSer_OleLinkTypes::Name);
|
||||
m_oBcw.m_oStream.WriteStringW3(oleItem.m_oName.get());
|
||||
m_oBcw.WriteItemWithLengthEnd(nCurPos);
|
||||
}
|
||||
if (oleItem.m_oIcon.IsInit())
|
||||
{
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSer_OleLinkTypes::Icon);
|
||||
m_oBcw.m_oStream.WriteBOOL(oleItem.m_oIcon->ToBool());
|
||||
m_oBcw.WriteItemWithLengthEnd(nCurPos);
|
||||
}
|
||||
if (oleItem.m_oAdvise.IsInit())
|
||||
{
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSer_OleLinkTypes::Advise);
|
||||
m_oBcw.m_oStream.WriteBOOL(oleItem.m_oAdvise->ToBool());
|
||||
m_oBcw.WriteItemWithLengthEnd(nCurPos);
|
||||
}
|
||||
if (oleItem.m_oPreferPic.IsInit())
|
||||
{
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSer_OleLinkTypes::PreferPic);
|
||||
m_oBcw.m_oStream.WriteBOOL(oleItem.m_oPreferPic->ToBool());
|
||||
m_oBcw.WriteItemWithLengthEnd(nCurPos);
|
||||
}
|
||||
}
|
||||
void WriteDdeLink(const OOX::Spreadsheet::CDdeLink& ddeLink)
|
||||
{
|
||||
int nCurPos = 0;
|
||||
if (ddeLink.m_oDdeService.IsInit())
|
||||
{
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSer_DdeLinkTypes::DdeService);
|
||||
m_oBcw.m_oStream.WriteStringW3(ddeLink.m_oDdeService.get());
|
||||
m_oBcw.WriteItemWithLengthEnd(nCurPos);
|
||||
}
|
||||
if (ddeLink.m_oDdeTopic.IsInit())
|
||||
{
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSer_DdeLinkTypes::DdeTopic);
|
||||
m_oBcw.m_oStream.WriteStringW3(ddeLink.m_oDdeTopic.get());
|
||||
m_oBcw.WriteItemWithLengthEnd(nCurPos);
|
||||
}
|
||||
if (ddeLink.m_oDdeItems.IsInit())
|
||||
{
|
||||
for(size_t i = 0; i < ddeLink.m_oDdeItems->m_arrItems.size(); ++i)
|
||||
{
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSer_DdeLinkTypes::DdeItem);
|
||||
WriteDdeItem(*ddeLink.m_oDdeItems->m_arrItems[i]);
|
||||
m_oBcw.WriteItemWithLengthEnd(nCurPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
void WriteDdeItem(const OOX::Spreadsheet::CDdeItem& ddeItem)
|
||||
{
|
||||
int nCurPos = 0;
|
||||
if (ddeItem.m_oName.IsInit())
|
||||
{
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSer_DdeLinkTypes::Name);
|
||||
m_oBcw.m_oStream.WriteStringW3(ddeItem.m_oName.get());
|
||||
m_oBcw.WriteItemWithLengthEnd(nCurPos);
|
||||
}
|
||||
if (ddeItem.m_oOle.IsInit())
|
||||
{
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSer_DdeLinkTypes::Ole);
|
||||
m_oBcw.m_oStream.WriteBOOL(ddeItem.m_oOle->ToBool());
|
||||
m_oBcw.WriteItemWithLengthEnd(nCurPos);
|
||||
}
|
||||
if (ddeItem.m_oAdvise.IsInit())
|
||||
{
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSer_DdeLinkTypes::Advise);
|
||||
m_oBcw.m_oStream.WriteBOOL(ddeItem.m_oAdvise->ToBool());
|
||||
m_oBcw.WriteItemWithLengthEnd(nCurPos);
|
||||
}
|
||||
if (ddeItem.m_oPreferPic.IsInit())
|
||||
{
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSer_DdeLinkTypes::PreferPic);
|
||||
m_oBcw.m_oStream.WriteBOOL(ddeItem.m_oPreferPic->ToBool());
|
||||
m_oBcw.WriteItemWithLengthEnd(nCurPos);
|
||||
}
|
||||
if (ddeItem.m_oDdeValues.IsInit())
|
||||
{
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSer_DdeLinkTypes::DdeValues);
|
||||
WriteDdeValues(ddeItem.m_oDdeValues.get());
|
||||
m_oBcw.WriteItemWithLengthEnd(nCurPos);
|
||||
}
|
||||
}
|
||||
void WriteDdeValues(const OOX::Spreadsheet::CDdeValues& ddeValues)
|
||||
{
|
||||
int nCurPos = 0;
|
||||
if (ddeValues.m_oRows.IsInit())
|
||||
{
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSer_DdeLinkTypes::DdeValuesRows);
|
||||
m_oBcw.m_oStream.WriteULONG(ddeValues.m_oRows->GetValue());
|
||||
m_oBcw.WriteItemWithLengthEnd(nCurPos);
|
||||
}
|
||||
if (ddeValues.m_oCols.IsInit())
|
||||
{
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSer_DdeLinkTypes::DdeValuesCols);
|
||||
m_oBcw.m_oStream.WriteULONG(ddeValues.m_oCols->GetValue());
|
||||
m_oBcw.WriteItemWithLengthEnd(nCurPos);
|
||||
}
|
||||
for(size_t i = 0; i < ddeValues.m_arrItems.size(); ++i)
|
||||
{
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSer_DdeLinkTypes::DdeValue);
|
||||
WriteDdeValue(*ddeValues.m_arrItems[i]);
|
||||
m_oBcw.WriteItemWithLengthEnd(nCurPos);
|
||||
}
|
||||
}
|
||||
void WriteDdeValue(const OOX::Spreadsheet::CDdeValue& ddeValue)
|
||||
{
|
||||
int nCurPos = 0;
|
||||
if (ddeValue.m_oType.IsInit())
|
||||
{
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSer_DdeLinkTypes::DdeValueType);
|
||||
m_oBcw.m_oStream.WriteBYTE(ddeValue.m_oType->GetValue());
|
||||
m_oBcw.WriteItemWithLengthEnd(nCurPos);
|
||||
}
|
||||
for (size_t i = 0; i < ddeValue.m_arrItems.size(); ++i)
|
||||
{
|
||||
nCurPos = m_oBcw.WriteItemStart(c_oSer_DdeLinkTypes::DdeValueVal);
|
||||
m_oBcw.m_oStream.WriteStringW3(ddeValue.m_arrItems[i]->ToString());
|
||||
m_oBcw.WriteItemWithLengthEnd(nCurPos);
|
||||
}
|
||||
}
|
||||
|
||||
void WriteDefinedName(const OOX::Spreadsheet::CDefinedName& definedName)
|
||||
{
|
||||
@ -2737,7 +3051,10 @@ namespace BinXlsxRW
|
||||
{
|
||||
OOX::CPath pathImage = pImageFileCache->filename();
|
||||
|
||||
olePic->oleObject->m_OleObjectFile->set_filename_cache(pathImage);
|
||||
if (olePic->oleObject->m_OleObjectFile.IsInit())
|
||||
{
|
||||
olePic->oleObject->m_OleObjectFile->set_filename_cache(pathImage);
|
||||
}
|
||||
|
||||
olePic->blipFill.blip->embed = new OOX::RId(sIdImageFileCache); //ваще то тут не важно что - приоритет у того что ниже..
|
||||
olePic->blipFill.blip->oleFilepathImage = pathImage.GetPath();
|
||||
|
||||
@ -1592,35 +1592,62 @@ namespace BinXlsxRW {
|
||||
int ReadExternalReferences(BYTE type, long length, void* poResult)
|
||||
{
|
||||
int res = c_oSerConstants::ReadOk;
|
||||
if(c_oSerWorkbookTypes::ExternalReference == type)
|
||||
if(c_oSerWorkbookTypes::ExternalBook == type)
|
||||
{
|
||||
std::wstring sName(m_oBufferedStream.GetString3(length));
|
||||
|
||||
if (sName.empty() == false)
|
||||
OOX::Spreadsheet::CExternalLink *extLink = new OOX::Spreadsheet::CExternalLink();
|
||||
extLink->m_oExternalBook.Init();
|
||||
res = Read1(length, &BinaryWorkbookTableReader::ReadExternalBook, this, extLink);
|
||||
if (extLink->m_oExternalBook->m_oRid.IsInit())
|
||||
{
|
||||
OOX::Spreadsheet::CExternalReference* pExternalReference = new OOX::Spreadsheet::CExternalReference();
|
||||
|
||||
OOX::Spreadsheet::CExternalLink *extLink= new OOX::Spreadsheet::CExternalLink();
|
||||
smart_ptr<OOX::File> oCurFile(extLink);
|
||||
|
||||
const OOX::RId oRId = m_oWorkbook.Add(oCurFile);
|
||||
|
||||
pExternalReference->m_oRid.Init();
|
||||
pExternalReference->m_oRid->SetValue(oRId.get());
|
||||
|
||||
extLink->m_oExternalBook.Init();
|
||||
smart_ptr<OOX::File> oCurFile(extLink);
|
||||
const OOX::RId oRId = m_oWorkbook.Add(oCurFile);
|
||||
|
||||
OOX::Spreadsheet::ExternalLinkPath *link = new OOX::Spreadsheet::ExternalLinkPath(sName);
|
||||
smart_ptr<OOX::File> oLinkFile(link);
|
||||
const OOX::RId oRIdLink = extLink->Add(oLinkFile);
|
||||
|
||||
extLink->m_oExternalBook->m_oRid.Init();
|
||||
extLink->m_oExternalBook->m_oRid->SetValue(oRIdLink.get());
|
||||
pExternalReference->m_oRid.Init();
|
||||
pExternalReference->m_oRid->SetValue(oRId.get());
|
||||
|
||||
|
||||
m_oWorkbook.m_oExternalReferences->m_arrItems.push_back(pExternalReference);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
RELEASEOBJECT(extLink)
|
||||
}
|
||||
}
|
||||
else if(c_oSerWorkbookTypes::OleLink == type)
|
||||
{
|
||||
OOX::Spreadsheet::CExternalLink *extLink = new OOX::Spreadsheet::CExternalLink();
|
||||
extLink->m_oOleLink.Init();
|
||||
res = Read1(length, &BinaryWorkbookTableReader::ReadOleLink, this, extLink);
|
||||
if (extLink->m_oOleLink->m_oRid.IsInit())
|
||||
{
|
||||
smart_ptr<OOX::File> oCurFile(extLink);
|
||||
const OOX::RId oRId = m_oWorkbook.Add(oCurFile);
|
||||
|
||||
OOX::Spreadsheet::CExternalReference* pExternalReference = new OOX::Spreadsheet::CExternalReference();
|
||||
pExternalReference->m_oRid.Init();
|
||||
pExternalReference->m_oRid->SetValue(oRId.get());
|
||||
m_oWorkbook.m_oExternalReferences->m_arrItems.push_back(pExternalReference);
|
||||
}
|
||||
else
|
||||
{
|
||||
RELEASEOBJECT(extLink)
|
||||
}
|
||||
}
|
||||
else if(c_oSerWorkbookTypes::DdeLink == type)
|
||||
{
|
||||
OOX::Spreadsheet::CExternalLink *extLink = new OOX::Spreadsheet::CExternalLink();
|
||||
extLink->m_oDdeLink.Init();
|
||||
res = Read1(length, &BinaryWorkbookTableReader::ReadDdeLink, this, extLink->m_oDdeLink.GetPointer());
|
||||
|
||||
smart_ptr<OOX::File> oCurFile(extLink);
|
||||
const OOX::RId oRId = m_oWorkbook.Add(oCurFile);
|
||||
|
||||
OOX::Spreadsheet::CExternalReference* pExternalReference = new OOX::Spreadsheet::CExternalReference();
|
||||
pExternalReference->m_oRid.Init();
|
||||
pExternalReference->m_oRid->SetValue(oRId.get());
|
||||
m_oWorkbook.m_oExternalReferences->m_arrItems.push_back(pExternalReference);
|
||||
}
|
||||
else
|
||||
res = c_oSerConstants::ReadUnknown;
|
||||
@ -1672,6 +1699,340 @@ namespace BinXlsxRW {
|
||||
res = c_oSerConstants::ReadUnknown;
|
||||
return res;
|
||||
};
|
||||
int ReadExternalBook(BYTE type, long length, void* poResult)
|
||||
{
|
||||
OOX::Spreadsheet::CExternalLink* extLink = static_cast<OOX::Spreadsheet::CExternalLink*>(poResult);
|
||||
OOX::Spreadsheet::CExternalBook* pExternalBook = extLink->m_oExternalBook.GetPointer();
|
||||
int res = c_oSerConstants::ReadOk;
|
||||
if(c_oSer_ExternalLinkTypes::Id == type)
|
||||
{
|
||||
std::wstring sName(m_oBufferedStream.GetString3(length));
|
||||
|
||||
OOX::Spreadsheet::ExternalLinkPath *link = new OOX::Spreadsheet::ExternalLinkPath(sName);
|
||||
smart_ptr<OOX::File> oLinkFile(link);
|
||||
const OOX::RId oRIdLink = extLink->Add(oLinkFile);
|
||||
|
||||
pExternalBook->m_oRid.Init();
|
||||
pExternalBook->m_oRid->SetValue(oRIdLink.get());
|
||||
}
|
||||
else if(c_oSer_ExternalLinkTypes::SheetNames == type)
|
||||
{
|
||||
pExternalBook->m_oSheetNames.Init();
|
||||
res = Read1(length, &BinaryWorkbookTableReader::ReadExternalSheetNames, this, pExternalBook->m_oSheetNames.GetPointer());
|
||||
}
|
||||
else if(c_oSer_ExternalLinkTypes::DefinedNames == type)
|
||||
{
|
||||
pExternalBook->m_oDefinedNames.Init();
|
||||
res = Read1(length, &BinaryWorkbookTableReader::ReadExternalDefinedNames, this, pExternalBook->m_oDefinedNames.GetPointer());
|
||||
}
|
||||
else if(c_oSer_ExternalLinkTypes::SheetDataSet == type)
|
||||
{
|
||||
pExternalBook->m_oSheetDataSet.Init();
|
||||
res = Read1(length, &BinaryWorkbookTableReader::ReadExternalSheetDataSet, this, pExternalBook->m_oSheetDataSet.GetPointer());
|
||||
}
|
||||
else
|
||||
res = c_oSerConstants::ReadUnknown;
|
||||
return res;
|
||||
};
|
||||
int ReadExternalSheetNames(BYTE type, long length, void* poResult)
|
||||
{
|
||||
OOX::Spreadsheet::CExternalSheetNames* pSheetNames = static_cast<OOX::Spreadsheet::CExternalSheetNames*>(poResult);
|
||||
int res = c_oSerConstants::ReadOk;
|
||||
if(c_oSer_ExternalLinkTypes::SheetName == type)
|
||||
{
|
||||
ComplexTypes::Spreadsheet::String* pSheetName = new ComplexTypes::Spreadsheet::String();
|
||||
pSheetName->m_sVal.Init();
|
||||
pSheetName->m_sVal->append(m_oBufferedStream.GetString4(length));
|
||||
pSheetNames->m_arrItems.push_back(pSheetName);
|
||||
}
|
||||
else
|
||||
res = c_oSerConstants::ReadUnknown;
|
||||
return res;
|
||||
};
|
||||
int ReadExternalDefinedNames(BYTE type, long length, void* poResult)
|
||||
{
|
||||
OOX::Spreadsheet::CExternalDefinedNames* pDefinedNames = static_cast<OOX::Spreadsheet::CExternalDefinedNames*>(poResult);
|
||||
int res = c_oSerConstants::ReadOk;
|
||||
if(c_oSer_ExternalLinkTypes::DefinedName == type)
|
||||
{
|
||||
OOX::Spreadsheet::CExternalDefinedName* pDefinedName = new OOX::Spreadsheet::CExternalDefinedName();
|
||||
res = Read1(length, &BinaryWorkbookTableReader::ReadExternalDefinedName, this, pDefinedName);
|
||||
pDefinedNames->m_arrItems.push_back(pDefinedName);
|
||||
}
|
||||
else
|
||||
res = c_oSerConstants::ReadUnknown;
|
||||
return res;
|
||||
};
|
||||
int ReadExternalDefinedName(BYTE type, long length, void* poResult)
|
||||
{
|
||||
OOX::Spreadsheet::CExternalDefinedName* pDefinedName = static_cast<OOX::Spreadsheet::CExternalDefinedName*>(poResult);
|
||||
int res = c_oSerConstants::ReadOk;
|
||||
if(c_oSer_ExternalLinkTypes::DefinedNameName == type)
|
||||
{
|
||||
pDefinedName->m_oName.Init();
|
||||
pDefinedName->m_oName->append(m_oBufferedStream.GetString3(length));
|
||||
}
|
||||
else if(c_oSer_ExternalLinkTypes::DefinedNameRefersTo == type)
|
||||
{
|
||||
pDefinedName->m_oRefersTo.Init();
|
||||
pDefinedName->m_oRefersTo->append(m_oBufferedStream.GetString3(length));
|
||||
}
|
||||
else if(c_oSer_ExternalLinkTypes::DefinedNameSheetId == type)
|
||||
{
|
||||
pDefinedName->m_oSheetId.Init();
|
||||
pDefinedName->m_oSheetId->SetValue(m_oBufferedStream.GetULong());
|
||||
}
|
||||
else
|
||||
res = c_oSerConstants::ReadUnknown;
|
||||
return res;
|
||||
};
|
||||
int ReadExternalSheetDataSet(BYTE type, long length, void* poResult)
|
||||
{
|
||||
OOX::Spreadsheet::CExternalSheetDataSet* pSheetDataSet = static_cast<OOX::Spreadsheet::CExternalSheetDataSet*>(poResult);
|
||||
int res = c_oSerConstants::ReadOk;
|
||||
if(c_oSer_ExternalLinkTypes::SheetData == type)
|
||||
{
|
||||
OOX::Spreadsheet::CExternalSheetData* pSheetData = new OOX::Spreadsheet::CExternalSheetData();
|
||||
res = Read1(length, &BinaryWorkbookTableReader::ReadExternalSheetData, this, pSheetData);
|
||||
pSheetDataSet->m_arrItems.push_back(pSheetData);
|
||||
}
|
||||
else
|
||||
res = c_oSerConstants::ReadUnknown;
|
||||
return res;
|
||||
};
|
||||
int ReadExternalSheetData(BYTE type, long length, void* poResult)
|
||||
{
|
||||
OOX::Spreadsheet::CExternalSheetData* pSheetData = static_cast<OOX::Spreadsheet::CExternalSheetData*>(poResult);
|
||||
int res = c_oSerConstants::ReadOk;
|
||||
if(c_oSer_ExternalLinkTypes::SheetDataSheetId == type)
|
||||
{
|
||||
pSheetData->m_oSheetId.Init();
|
||||
pSheetData->m_oSheetId->SetValue(m_oBufferedStream.GetULong());
|
||||
}
|
||||
else if(c_oSer_ExternalLinkTypes::SheetDataRefreshError == type)
|
||||
{
|
||||
pSheetData->m_oRefreshError.Init();
|
||||
pSheetData->m_oRefreshError->FromBool(m_oBufferedStream.GetBool());
|
||||
}
|
||||
else if(c_oSer_ExternalLinkTypes::SheetDataRow == type)
|
||||
{
|
||||
OOX::Spreadsheet::CExternalRow* pRow = new OOX::Spreadsheet::CExternalRow();
|
||||
res = Read1(length, &BinaryWorkbookTableReader::ReadExternalRow, this, pRow);
|
||||
pSheetData->m_arrItems.push_back(pRow);
|
||||
}
|
||||
else
|
||||
res = c_oSerConstants::ReadUnknown;
|
||||
return res;
|
||||
};
|
||||
int ReadExternalRow(BYTE type, long length, void* poResult)
|
||||
{
|
||||
OOX::Spreadsheet::CExternalRow* pRow = static_cast<OOX::Spreadsheet::CExternalRow*>(poResult);
|
||||
int res = c_oSerConstants::ReadOk;
|
||||
if(c_oSer_ExternalLinkTypes::SheetDataRowR == type)
|
||||
{
|
||||
pRow->m_oR.Init();
|
||||
pRow->m_oR->SetValue(m_oBufferedStream.GetULong());
|
||||
}
|
||||
else if(c_oSer_ExternalLinkTypes::SheetDataRowCell == type)
|
||||
{
|
||||
OOX::Spreadsheet::CExternalCell* pCell = new OOX::Spreadsheet::CExternalCell();
|
||||
res = Read1(length, &BinaryWorkbookTableReader::ReadExternalCell, this, pCell);
|
||||
pRow->m_arrItems.push_back(pCell);
|
||||
}
|
||||
else
|
||||
res = c_oSerConstants::ReadUnknown;
|
||||
return res;
|
||||
};
|
||||
int ReadExternalCell(BYTE type, long length, void* poResult)
|
||||
{
|
||||
OOX::Spreadsheet::CExternalCell* pCell = static_cast<OOX::Spreadsheet::CExternalCell*>(poResult);
|
||||
int res = c_oSerConstants::ReadOk;
|
||||
if(c_oSer_ExternalLinkTypes::SheetDataRowCellRef == type)
|
||||
{
|
||||
pCell->m_oRef.Init();
|
||||
pCell->m_oRef->append(m_oBufferedStream.GetString3(length));
|
||||
}
|
||||
else if(c_oSer_ExternalLinkTypes::SheetDataRowCellType == type)
|
||||
{
|
||||
pCell->m_oType.Init();
|
||||
pCell->m_oType->SetValue((SimpleTypes::Spreadsheet::ECellTypeType)m_oBufferedStream.GetUChar());
|
||||
}
|
||||
else if(c_oSer_ExternalLinkTypes::SheetDataRowCellValue == type)
|
||||
{
|
||||
pCell->m_oValue.Init();
|
||||
pCell->m_oValue->m_sText.append(m_oBufferedStream.GetString3(length));
|
||||
}
|
||||
else
|
||||
res = c_oSerConstants::ReadUnknown;
|
||||
return res;
|
||||
};
|
||||
int ReadOleLink(BYTE type, long length, void* poResult)
|
||||
{
|
||||
OOX::Spreadsheet::CExternalLink* extLink = static_cast<OOX::Spreadsheet::CExternalLink*>(poResult);
|
||||
OOX::Spreadsheet::COleLink* oleLink = extLink->m_oOleLink.GetPointer();
|
||||
int res = c_oSerConstants::ReadOk;
|
||||
if(c_oSer_OleLinkTypes::Id == type)
|
||||
{
|
||||
std::wstring sName(m_oBufferedStream.GetString3(length));
|
||||
|
||||
OOX::Spreadsheet::ExternalOleObject *link = new OOX::Spreadsheet::ExternalOleObject(sName);
|
||||
smart_ptr<OOX::File> oLinkFile(link);
|
||||
const OOX::RId oRIdLink = extLink->Add(oLinkFile);
|
||||
|
||||
oleLink->m_oRid.Init();
|
||||
oleLink->m_oRid->SetValue(oRIdLink.get());
|
||||
}
|
||||
else if(c_oSer_OleLinkTypes::ProgId == type)
|
||||
{
|
||||
oleLink->m_oProgId.Init();
|
||||
oleLink->m_oProgId->append(m_oBufferedStream.GetString3(length));
|
||||
}
|
||||
else if(c_oSer_OleLinkTypes::OleItem == type)
|
||||
{
|
||||
if (!oleLink->m_oOleItems.IsInit())
|
||||
{
|
||||
oleLink->m_oOleItems.Init();
|
||||
}
|
||||
OOX::Spreadsheet::COleItem* pOleItem = new OOX::Spreadsheet::COleItem();
|
||||
res = Read1(length, &BinaryWorkbookTableReader::ReadOleItem, this, pOleItem);
|
||||
oleLink->m_oOleItems->m_arrItems.push_back(pOleItem);
|
||||
}
|
||||
else
|
||||
res = c_oSerConstants::ReadUnknown;
|
||||
return res;
|
||||
};
|
||||
int ReadOleItem(BYTE type, long length, void* poResult)
|
||||
{
|
||||
OOX::Spreadsheet::COleItem* pOleItem = static_cast<OOX::Spreadsheet::COleItem*>(poResult);
|
||||
int res = c_oSerConstants::ReadOk;
|
||||
if(c_oSer_OleLinkTypes::Name == type)
|
||||
{
|
||||
pOleItem->m_oName.Init();
|
||||
pOleItem->m_oName->append(m_oBufferedStream.GetString3(length));
|
||||
}
|
||||
else if(c_oSer_OleLinkTypes::Icon == type)
|
||||
{
|
||||
pOleItem->m_oIcon.Init();
|
||||
pOleItem->m_oIcon->FromBool(m_oBufferedStream.GetBool());
|
||||
}
|
||||
else if(c_oSer_OleLinkTypes::Advise == type)
|
||||
{
|
||||
pOleItem->m_oAdvise.Init();
|
||||
pOleItem->m_oAdvise->FromBool(m_oBufferedStream.GetBool());
|
||||
}
|
||||
else if(c_oSer_OleLinkTypes::PreferPic == type)
|
||||
{
|
||||
pOleItem->m_oPreferPic.Init();
|
||||
pOleItem->m_oPreferPic->FromBool(m_oBufferedStream.GetBool());
|
||||
}
|
||||
else
|
||||
res = c_oSerConstants::ReadUnknown;
|
||||
return res;
|
||||
};
|
||||
int ReadDdeLink(BYTE type, long length, void* poResult)
|
||||
{
|
||||
OOX::Spreadsheet::CDdeLink* ddeLink = static_cast<OOX::Spreadsheet::CDdeLink*>(poResult);
|
||||
int res = c_oSerConstants::ReadOk;
|
||||
if(c_oSer_DdeLinkTypes::DdeService == type)
|
||||
{
|
||||
ddeLink->m_oDdeService.Init();
|
||||
ddeLink->m_oDdeService->append(m_oBufferedStream.GetString3(length));
|
||||
}
|
||||
else if(c_oSer_DdeLinkTypes::DdeTopic == type)
|
||||
{
|
||||
ddeLink->m_oDdeTopic.Init();
|
||||
ddeLink->m_oDdeTopic->append(m_oBufferedStream.GetString3(length));
|
||||
}
|
||||
else if(c_oSer_DdeLinkTypes::DdeItem == type)
|
||||
{
|
||||
if (!ddeLink->m_oDdeItems.IsInit())
|
||||
{
|
||||
ddeLink->m_oDdeItems.Init();
|
||||
}
|
||||
OOX::Spreadsheet::CDdeItem* pDdeItem = new OOX::Spreadsheet::CDdeItem();
|
||||
res = Read1(length, &BinaryWorkbookTableReader::ReadDdeItem, this, pDdeItem);
|
||||
ddeLink->m_oDdeItems->m_arrItems.push_back(pDdeItem);
|
||||
}
|
||||
else
|
||||
res = c_oSerConstants::ReadUnknown;
|
||||
return res;
|
||||
};
|
||||
int ReadDdeItem(BYTE type, long length, void* poResult)
|
||||
{
|
||||
OOX::Spreadsheet::CDdeItem* pDdeItem = static_cast<OOX::Spreadsheet::CDdeItem*>(poResult);
|
||||
int res = c_oSerConstants::ReadOk;
|
||||
if(c_oSer_DdeLinkTypes::Name == type)
|
||||
{
|
||||
pDdeItem->m_oName.Init();
|
||||
pDdeItem->m_oName->append(m_oBufferedStream.GetString3(length));
|
||||
}
|
||||
else if(c_oSer_DdeLinkTypes::Ole == type)
|
||||
{
|
||||
pDdeItem->m_oOle.Init();
|
||||
pDdeItem->m_oOle->FromBool(m_oBufferedStream.GetBool());
|
||||
}
|
||||
else if(c_oSer_DdeLinkTypes::Advise == type)
|
||||
{
|
||||
pDdeItem->m_oAdvise.Init();
|
||||
pDdeItem->m_oAdvise->FromBool(m_oBufferedStream.GetBool());
|
||||
}
|
||||
else if(c_oSer_DdeLinkTypes::PreferPic == type)
|
||||
{
|
||||
pDdeItem->m_oPreferPic.Init();
|
||||
pDdeItem->m_oPreferPic->FromBool(m_oBufferedStream.GetBool());
|
||||
}
|
||||
else if(c_oSer_DdeLinkTypes::DdeValues == type)
|
||||
{
|
||||
pDdeItem->m_oDdeValues.Init();
|
||||
res = Read1(length, &BinaryWorkbookTableReader::ReadDdeValues, this, pDdeItem->m_oDdeValues.GetPointer());
|
||||
}
|
||||
else
|
||||
res = c_oSerConstants::ReadUnknown;
|
||||
return res;
|
||||
};
|
||||
int ReadDdeValues(BYTE type, long length, void* poResult)
|
||||
{
|
||||
OOX::Spreadsheet::CDdeValues* pDdeValues = static_cast<OOX::Spreadsheet::CDdeValues*>(poResult);
|
||||
int res = c_oSerConstants::ReadOk;
|
||||
if(c_oSer_DdeLinkTypes::DdeValuesRows == type)
|
||||
{
|
||||
pDdeValues->m_oRows.Init();
|
||||
pDdeValues->m_oRows->SetValue(m_oBufferedStream.GetULong());
|
||||
}
|
||||
else if(c_oSer_DdeLinkTypes::DdeValuesCols == type)
|
||||
{
|
||||
pDdeValues->m_oCols.Init();
|
||||
pDdeValues->m_oCols->SetValue(m_oBufferedStream.GetULong());
|
||||
}
|
||||
else if(c_oSer_DdeLinkTypes::DdeValue == type)
|
||||
{
|
||||
OOX::Spreadsheet::CDdeValue* pDdeValue = new OOX::Spreadsheet::CDdeValue();
|
||||
res = Read1(length, &BinaryWorkbookTableReader::ReadDdeValue, this, pDdeValue);
|
||||
pDdeValues->m_arrItems.push_back(pDdeValue);
|
||||
}
|
||||
else
|
||||
res = c_oSerConstants::ReadUnknown;
|
||||
return res;
|
||||
};
|
||||
int ReadDdeValue(BYTE type, long length, void* poResult)
|
||||
{
|
||||
OOX::Spreadsheet::CDdeValue* pDdeValue = static_cast<OOX::Spreadsheet::CDdeValue*>(poResult);
|
||||
int res = c_oSerConstants::ReadOk;
|
||||
if(c_oSer_DdeLinkTypes::DdeValueType == type)
|
||||
{
|
||||
pDdeValue->m_oType.Init();
|
||||
pDdeValue->m_oType->SetValue((SimpleTypes::Spreadsheet::EDdeValueType)m_oBufferedStream.GetUChar());
|
||||
}
|
||||
else if(c_oSer_DdeLinkTypes::DdeValueVal == type)
|
||||
{
|
||||
OOX::Spreadsheet::CText* pText = new OOX::Spreadsheet::CText();
|
||||
pText->m_sText.append(m_oBufferedStream.GetString3(length));
|
||||
pDdeValue->m_arrItems.push_back(pText);
|
||||
}
|
||||
else
|
||||
res = c_oSerConstants::ReadUnknown;
|
||||
return res;
|
||||
};
|
||||
int ReadPivotCaches(BYTE type, long length, void* poResult)
|
||||
{
|
||||
int res = c_oSerConstants::ReadOk;
|
||||
|
||||
Reference in New Issue
Block a user