UWVA#14391 Encrypted/zip/ SLNKDWF 2.20

svn path=/Slnkdwf/trunk/; revision=12492
This commit is contained in:
Jos Groot Lipman
2008-09-02 13:48:16 +00:00
parent 21d0ab72e6
commit 6ddcc6bf77
8 changed files with 310 additions and 2 deletions

View File

@@ -263,6 +263,24 @@ interface ISLNKSymbol : IDispatch{
interface IOptions : IDispatch{
[id(1), helpstring("method SetOption")] HRESULT SetOption([in] BSTR optionName, VARIANT OptionValue);
};
[
object,
uuid(01C19AF8-073E-40E2-843F-25A2C6C4E274),
dual,
nonextensible,
helpstring("IZip Interface"),
pointer_default(unique)
]
interface IZip : IDispatch{
[id(1), helpstring("method Open")] HRESULT Open([in] BSTR ZIPPath);
[id(2), helpstring("method New")] HRESULT New(BSTR ZipPath);
[id(3), helpstring("method UnzipToStream")] HRESULT UnzipToStream([in] VARIANT pVal, [in]BSTR filepath, [in, defaultvalue(L"")] BSTR Password);
[id(4), helpstring("method DecryptToStream")] HRESULT DecryptToStream([in] VARIANT pVal, [in]BSTR filepath);
[id(5), helpstring("method ZipFromString")] HRESULT ZipFromString([in] BSTR filepath, [in] BSTR data, [in, defaultvalue(L"")] BSTR Password);
[id(6), helpstring("method ZipFromStream")] HRESULT ZipFromStream([in] BSTR filepath, [in] VARIANT pVal, [in, defaultvalue(L"")] BSTR Password);
[id(7), helpstring("method EncryptFromString")] HRESULT EncryptFromString([in] BSTR filepath, [in] BSTR data);
[id(8), helpstring("method Close")] HRESULT Close(void);
};
[
uuid(B6FCDE6E-141C-4601-B3AC-4DF4D5F25DF8),
version(1.0),
@@ -374,4 +392,12 @@ library SLNKDWFLib
{
[default] interface IOptions;
};
[
uuid(C5805A7A-67CF-452B-94F1-E7A50023D695),
helpstring("Zip Class")
]
coclass Zip
{
[default] interface IZip;
};
};

View File

@@ -355,6 +355,10 @@
RelativePath="WhipFile.cpp"
>
</File>
<File
RelativePath=".\Zip.cpp"
>
</File>
</Filter>
<Filter
Name="Header Files"
@@ -476,6 +480,10 @@
RelativePath="WriterTest.h"
>
</File>
<File
RelativePath=".\Zip.h"
>
</File>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
@@ -512,6 +520,10 @@
RelativePath="WhipFile.rgs"
>
</File>
<File
RelativePath=".\Zip.rgs"
>
</File>
</Filter>
</Filter>
<Filter

View File

@@ -1,6 +1,6 @@
// Zorg dat versies alfabetisch altijd op elkaar volgen!
#define SLNK_MAJOR_VERSION 2
#define SLNK_MINOR_VERSION 14
#define SLNK_MINOR_VERSION 20
#define SLNK_BUILD_VERSION 0
// Define resource strings

View File

@@ -135,6 +135,7 @@ IDR_DWGPOINT REGISTRY "DWGPoint.rgs"
IDR_SLNKCONTOUR REGISTRY "SLNKContour.rgs"
IDR_SLNKSYMBOL REGISTRY "SLNKSymbol.rgs"
IDR_OPTIONS REGISTRY "Options.rgs"
IDR_ZIP REGISTRY "Zip.rgs"
/////////////////////////////////////////////////////////////////////////////
//

241
SlnkDWFCom/Zip.cpp Normal file
View File

@@ -0,0 +1,241 @@
// Zip.cpp : Implementation of CZip
#include "stdafx.h"
#include "Zip.h"
#define DATA_BUFFER_BYTES 4096
#define VERYSECRET ("H&4!0jKd")
// CZip
STDMETHODIMP CZip::InterfaceSupportsErrorInfo(REFIID riid)
{
static const IID* arr[] =
{
&IID_IZip
};
for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
{
if (InlineIsEqualGUID(*arr[i],riid))
return S_OK;
}
return S_FALSE;
}
STDMETHODIMP CZip::Open(BSTR ZipPath)
{
if (m_pZipFile)
return myAtlReportError (GetObjectCLSID(), "\nCZip::Open zipfile is already open.");
try
{
DWFCore::DWFFile oZipFilename( ZipPath );
m_pZipFile = new DWFCore::DWFZipFileDescriptor(oZipFilename, DWFZipFileDescriptor::eUnzip);
m_pZipFile->open();
}
catch (DWFException& ex)
{
CString err;
err.Format("%ls\n%ls\n%s\n%ls(%d)",ex.type(),ex.message(),ex.function(),ex.file(),ex.line());
return myAtlReportError (GetObjectCLSID(), "\nCZip::Open('%ls')\n%s", ZipPath, err);
}
return S_OK;
}
STDMETHODIMP CZip::New(BSTR ZipPath)
{
if (m_pZipFile)
return myAtlReportError (GetObjectCLSID(), "\nCZip::New zipfile is already open.");
try
{
DWFCore::DWFFile oZipFilename( ZipPath );
m_pZipFile = new DWFCore::DWFZipFileDescriptor(oZipFilename, DWFZipFileDescriptor::eZip);
m_pZipFile->open();
}
catch (DWFException& ex)
{
CString err;
err.Format("%ls\n%ls\n%s\n%ls(%d)",ex.type(),ex.message(),ex.function(),ex.file(),ex.line());
return myAtlReportError (GetObjectCLSID(), "\nCZip::New('%ls')\n%s", ZipPath, err);
}
return S_OK;
}
STDMETHODIMP CZip::DecryptToStream(VARIANT pStream, BSTR filepath)
{
return UnzipToStream(pStream, filepath, CComBSTR ( VERYSECRET ));
}
// Gebruik vanuit ASP: oZIP.UnzipToStream(Response, "Geheim");
// want het Response Object implementeerd mooi de IStream interface
STDMETHODIMP CZip::UnzipToStream(VARIANT pStream, BSTR filepath, BSTR Password/*=L""*/)
{
if (!m_pZipFile)
return myAtlReportError (GetObjectCLSID(), "\nCZip::UnzipToStream zipfile not open.");
myTRACE("\nEntering CZip::UnzipToStream");
CComQIPtr<IStream> pIStream;
if (pStream.vt!=VT_ERROR)
{
VARIANT *var2 = &pStream;
if (var2->vt==(VT_VARIANT|VT_BYREF)) // ByRef vanuit VBScript
var2 = (VARIANT *)var2->pvarVal;
if (var2->vt==VT_DISPATCH)
pIStream = var2->pdispVal;
else if (var2->vt==(VT_DISPATCH|VT_BYREF)) // ByRef vanuit VB
pIStream = *(var2->ppdispVal);
if (!pIStream)
return E_INVALIDARG;
try
{
unsigned char* pDataBuffer = DWFCORE_ALLOC_MEMORY( unsigned char, DATA_BUFFER_BYTES );
if (pDataBuffer == NULL)
{
_DWFCORE_THROW( DWFMemoryException, L"No memory for data buffer" );
}
DWFCore::DWFInputStream* pUnzipStream =
m_pZipFile->unzip((LPCSTR)CString(filepath),(LPCSTR)CString(Password));
while (pUnzipStream->available() > 0)
{
size_t nBytes;
nBytes = pUnzipStream->read( pDataBuffer, DATA_BUFFER_BYTES );
ULONG cb;
pIStream->Write((void*)pDataBuffer, (ULONG)nBytes, &cb);
}
DWFCORE_FREE_OBJECT (pUnzipStream);
DWFCORE_FREE_MEMORY( pDataBuffer )
}
catch (DWFException& ex)
{
CString err;
err.Format("%ls\n%ls\n%s\n%ls(%d)",ex.type(),ex.message(),ex.function(),ex.file(),ex.line());
return myAtlReportError (GetObjectCLSID(), "\nCZip::UnzipToStream()\n%s", err);
}
}
return S_OK;
}
STDMETHODIMP CZip::EncryptFromString(BSTR filepath, BSTR data)
{
return ZipFromString( filepath, data, CComBSTR ( VERYSECRET ));
}
// filepath naam waaronder opgeslagen binnen de ZIP
// data Visual Basic string
// Password Optioneel
STDMETHODIMP CZip::ZipFromStream(BSTR filepath, VARIANT pStream, BSTR Password)
{
if (!m_pZipFile)
return myAtlReportError (GetObjectCLSID(), "\nCZip::ZipFromStream zipfile not open.");
myTRACE("\nEntering CZip::ZipFromStream");
CComQIPtr<IStream> pIStream;
if (pStream.vt!=VT_ERROR)
{
VARIANT *var2 = &pStream;
if (var2->vt==(VT_VARIANT|VT_BYREF)) // ByRef vanuit VBScript
var2 = (VARIANT *)var2->pvarVal;
if (var2->vt==VT_DISPATCH)
pIStream = var2->pdispVal;
else if (var2->vt==(VT_DISPATCH|VT_BYREF)) // ByRef vanuit VB
pIStream = *(var2->ppdispVal);
if (!pIStream)
return E_INVALIDARG;
try
{
// Naam waaronder binnen de zip is opgeslagen
DWFCore::DWFString file((LPCSTR)CString(filepath));
DWFCore::DWFOutputStream* pZipStream;
pZipStream = m_pZipFile->zip(file,(LPCSTR)CString(Password));
unsigned char* pDataBuffer = DWFCORE_ALLOC_MEMORY( unsigned char, DATA_BUFFER_BYTES );
if (pDataBuffer == NULL)
{
_DWFCORE_THROW( DWFMemoryException, L"No memory for data buffer" );
}
ULONG cbRead;
do
{
pIStream->Read((void*)pDataBuffer, DATA_BUFFER_BYTES, &cbRead);
if (cbRead>0)
pZipStream->write( pDataBuffer, cbRead);
}
while (cbRead == DATA_BUFFER_BYTES);
pZipStream->flush();
DWFCORE_FREE_MEMORY( pDataBuffer )
DWFCORE_FREE_OBJECT (pZipStream);
}
catch (DWFException& ex)
{
CString err;
err.Format("%ls\n%ls\n%s\n%ls(%d)",ex.type(),ex.message(),ex.function(),ex.file(),ex.line());
return myAtlReportError (GetObjectCLSID(), "\nCZip::ZipFromString('%ls')\n%s", filepath, err);
}
}
return S_OK;
}
// filepath naam waaronder opgeslagen binnen de ZIP
// data Visual Basic string
// Password Optioneel
STDMETHODIMP CZip::ZipFromString(BSTR filepath, BSTR data, BSTR Password)
{
if (!m_pZipFile)
return myAtlReportError (GetObjectCLSID(), "\nCZip::ZipFromString zipfile not open.");
myTRACE("\nEntering CZip::ZipFromString met data lengte: %d\n", SysStringByteLen(data));
try
{
// Naam waaronder binnen de zip is opgeslagen
DWFCore::DWFString file((LPCSTR)CString(filepath));
DWFCore::DWFOutputStream* pZipStream;
pZipStream = m_pZipFile->zip(file,(LPCSTR)CString(Password));
size_t nBytes=pZipStream->write( data, SysStringByteLen(data));
pZipStream->flush();
DWFCORE_FREE_OBJECT (pZipStream);
}
catch (DWFException& ex)
{
CString err;
err.Format("%ls\n%ls\n%s\n%ls(%d)",ex.type(),ex.message(),ex.function(),ex.file(),ex.line());
return myAtlReportError (GetObjectCLSID(), "\nCZip::ZipFromString('%ls')\n%s", filepath, err);
}
return S_OK;
}
STDMETHODIMP CZip::Close(void)
{
if (!m_pZipFile)
return myAtlReportError (GetObjectCLSID(), "\nCZip::Close zipfile not open.");
m_pZipFile->close();
delete m_pZipFile;
m_pZipFile = NULL;
return S_OK;
}

26
SlnkDWFCom/Zip.rgs Normal file
View File

@@ -0,0 +1,26 @@
HKCR
{
SLNKDWF.Zip.1 = s 'Zip Class'
{
CLSID = s '{C5805A7A-67CF-452B-94F1-E7A50023D695}'
}
SLNKDWF.Zip = s 'Zip Class'
{
CLSID = s '{C5805A7A-67CF-452B-94F1-E7A50023D695}'
CurVer = s 'SLNKDWF.Zip.1'
}
NoRemove CLSID
{
ForceRemove {C5805A7A-67CF-452B-94F1-E7A50023D695} = s 'Zip Class'
{
ProgID = s 'SLNKDWF.Zip.1'
VersionIndependentProgID = s 'SLNKDWF.Zip'
ForceRemove 'Programmable'
InprocServer32 = s '%MODULE%'
{
val ThreadingModel = s 'Apartment'
}
'TypeLib' = s '{B6FCDE6E-141C-4601-B3AC-4DF4D5F25DF8}'
}
}
}

View File

@@ -25,6 +25,7 @@
#define IDR_SLNKCONTOUR 120
#define IDR_SLNKSYMBOL 126
#define IDR_OPTIONS 127
#define IDR_ZIP 128
// Next default values for new objects
//
@@ -33,6 +34,6 @@
#define _APS_NEXT_RESOURCE_VALUE 201
#define _APS_NEXT_COMMAND_VALUE 32768
#define _APS_NEXT_CONTROL_VALUE 201
#define _APS_NEXT_SYMED_VALUE 128
#define _APS_NEXT_SYMED_VALUE 129
#endif
#endif

View File

@@ -23,6 +23,7 @@ HRESULT myAtlReportError(const CLSID & clsid, LPCTSTR lpszFormat, ...)
va_end(args);
myTRACE(szBuffer);
return AtlReportError(clsid, szBuffer);
}