Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mpc-hc/mpc-hc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXhmikosR <xhmikosr@users.sourceforge.net>2011-04-13 16:09:49 +0400
committerXhmikosR <xhmikosr@users.sourceforge.net>2011-04-13 16:09:49 +0400
commita460a864ba3553936cc6a201018d8b5427b73b3c (patch)
tree325d2ca02769095ed9ce9b96c6820ab4b29c1801 /include/atl
parentdedc42b6075d41d128552d56fbc7e2740b535630 (diff)
remove unneeded atl include files
git-svn-id: https://mpc-hc.svn.sourceforge.net/svnroot/mpc-hc/trunk@3028 10f7b99b-c216-0410-bff0-8a66a9350fd8
Diffstat (limited to 'include/atl')
-rw-r--r--include/atl/atlcrypt.h376
-rw-r--r--include/atl/atlcrypt.inl1062
-rw-r--r--include/atl/atlextmgmt.h1279
-rw-r--r--include/atl/atlhtml.h1682
-rw-r--r--include/atl/atlhttp.h725
-rw-r--r--include/atl/atlhttp.inl3144
-rw-r--r--include/atl/atlmime.h2406
-rw-r--r--include/atl/atlsession.h2490
-rw-r--r--include/atl/atlsharedsvc.h202
-rw-r--r--include/atl/atlsmtpconnection.h926
-rw-r--r--include/atl/atlsmtputil.h220
-rw-r--r--include/atl/atlsoap.h8174
-rw-r--r--include/atl/atlsrv.rc146
-rw-r--r--include/atl/l.chs/atlsrv.rc146
-rw-r--r--include/atl/l.cht/atlsrv.rc146
-rw-r--r--include/atl/l.deu/atlsrv.rc146
-rw-r--r--include/atl/l.esp/atlsrv.rc146
-rw-r--r--include/atl/l.fra/atlsrv.rc146
-rw-r--r--include/atl/l.ita/atlsrv.rc146
-rw-r--r--include/atl/l.jpn/atlsrv.rc146
-rw-r--r--include/atl/l.kor/atlsrv.rc146
-rw-r--r--include/atl/res/dllmgr.srf29
-rw-r--r--include/atl/res/stencilmgr.srf69
-rw-r--r--include/atl/res/threadmgr.srf24
24 files changed, 0 insertions, 24122 deletions
diff --git a/include/atl/atlcrypt.h b/include/atl/atlcrypt.h
deleted file mode 100644
index 8e8ac7d4e..000000000
--- a/include/atl/atlcrypt.h
+++ /dev/null
@@ -1,376 +0,0 @@
-// This is a part of the Active Template Library.
-// Copyright (C) Microsoft Corporation
-// All rights reserved.
-//
-// This source code is only intended as a supplement to the
-// Active Template Library Reference and related
-// electronic documentation provided with the library.
-// See these sources for detailed information regarding the
-// Active Template Library product.
-
-#ifndef __ATLCRYPT_H__
-#define __ATLCRYPT_H__
-
-#pragma once
-
-#include <atlchecked.h>
-#include <wincrypt.h>
-
-
-#pragma pack(push,_ATL_PACKING)
-namespace ATL
-{
-
-class CCryptKey;
-
-class CCryptProv
-{
-protected:
- HCRYPTPROV m_hProv;
-
-public:
- CCryptProv() throw();
- CCryptProv( const CCryptProv& prov ) throw();
- explicit CCryptProv( HCRYPTPROV hProv, BOOL bTakeOwnership = FALSE ) throw();
- ~CCryptProv() throw();
-
- CCryptProv& operator=( const CCryptProv& prov ) throw();
-
- HRESULT AddRef() throw();
- void Attach( HCRYPTPROV hProv, BOOL bTakeOwnership = FALSE ) throw();
- HCRYPTPROV Detach() throw();
- HRESULT Release() throw();
-
-
- HRESULT Initialize(DWORD dwProviderType = PROV_RSA_FULL,
- LPCTSTR szContainer = NULL, LPCTSTR szProvider = MS_DEF_PROV,
- DWORD dwFlags = 0) throw();
- HRESULT InitVerifyContext(DWORD dwProviderType = PROV_RSA_FULL,
- LPCTSTR szProvider = MS_DEF_PROV, DWORD dwFlags = 0) throw();
- HRESULT InitCreateKeySet(DWORD dwProviderType = PROV_RSA_FULL,
- LPCTSTR szContainer = NULL, LPCTSTR szProvider = MS_DEF_PROV,
- DWORD dwFlags = 0) throw();
-
- HRESULT DeleteKeySet(DWORD dwProviderType = PROV_RSA_FULL,
- LPCTSTR szContainer = NULL, LPCTSTR szProvider = MS_DEF_PROV,
- DWORD dwFlags = 0) throw();
-
- HRESULT Uninitialize();
-
- HRESULT GetParam(DWORD dwParam, BYTE * pbData, DWORD * pdwDataLen, DWORD dwFlags = 0) throw();
- HRESULT SetParam( DWORD dwParam, BYTE* pbData, DWORD dwFlags = 0) throw();
- HRESULT GetName(__out_ecount_part_z(*pdwLength, *pdwLength) LPSTR szBuf, __inout DWORD * pdwLength) throw();
- HRESULT GetContainer(__out_ecount_part_z(*pdwLength, *pdwLength) LPSTR szBuf, __inout DWORD * pdwLength) throw();
- HRESULT GetImpType(DWORD * pdwImpType) throw();
- HRESULT GetVersion(DWORD * pdwVersion) throw();
- HRESULT GetProvType(DWORD * pdwType) throw();
- HRESULT GetSecurityDesc(SECURITY_INFORMATION * pSecInfo) throw();
- HRESULT SetSecurityDesc(SECURITY_INFORMATION SecInfo) throw();
-
- HRESULT GenRandom(ULONG nLength, BYTE* pbBuffer ) throw();
-
- inline HCRYPTPROV GetHandle() throw()
- {
- return m_hProv;
- }
-}; // class CCryptProv
-
-
-// class CCryptHash
-// Provides base functionality of hashes.
-class CCryptHash
-{
-protected:
- HCRYPTHASH m_hHash;
-
-public:
- CCryptHash() throw();
- CCryptHash( const CCryptHash& hash ) throw();
- explicit CCryptHash( HCRYPTHASH hHash, BOOL bTakeOwnership = FALSE ) throw();
- ~CCryptHash() throw();
-
- void Attach( HCRYPTHASH hHash, BOOL bTakeOwnership = FALSE ) throw();
- void Destroy() throw();
- HCRYPTHASH Detach() throw();
- HCRYPTHASH Duplicate() const throw();
-
- HRESULT Uninitialize() throw();
- HRESULT Detach(HCRYPTHASH * phHash) throw();
- HRESULT AddData(const BYTE * pbData, DWORD dwDataLen, DWORD dwFlags = 0) throw();
- HRESULT AddString(LPCTSTR szData, DWORD dwFlags = 0) throw();
- HRESULT GetParam(DWORD dwParam, BYTE * pbData, DWORD * pdwDataLen, DWORD dwFlags = 0) throw();
- HRESULT SetParam(DWORD dwParam, BYTE * pbData, DWORD dwFlags = 0) throw();
- HRESULT GetAlgId(ALG_ID * pAlgId) throw();
- HRESULT GetSize(DWORD * pdwSize) throw();
- HRESULT GetValue(BYTE * pBuf, DWORD * pdwSize) throw();
- HRESULT SetValue(BYTE * pBuf) throw();
- HRESULT Sign(
- BYTE * pbSignature,
- DWORD * pdwSigLen,
- DWORD dwFlags = 0,
- DWORD dwKeySpec = AT_SIGNATURE) throw();
- HRESULT VerifySignature(
- const BYTE * pbSignature,
- DWORD pdwSignLen,
- CCryptKey &PubKey,
- DWORD dwFlags = 0) throw();
-
- inline HCRYPTHASH GetHandle()
- {
- return m_hHash;
- }
- static CCryptHash EmptyHash;
-
-}; // class CCryptHash
-
-// class CCryptKey
-// Provides the functionality for cryptographic keys, i.e. encrypting, decrypting.
-class CCryptKey
-{
-protected:
- HCRYPTKEY m_hKey;
-
-public:
- CCryptKey() throw();
- CCryptKey( const CCryptKey& key ) throw();
- explicit CCryptKey( HCRYPTKEY hKey, BOOL bTakeOwnership = FALSE ) throw();
- ~CCryptKey() throw();
-
- void Attach( HCRYPTKEY hKey, BOOL bTakeOwnership = FALSE ) throw();
- void Destroy() throw();
- HCRYPTKEY Detach() throw();
- HCRYPTKEY Duplicate() const throw();
-
- HRESULT Uninitialize() throw();
- HRESULT Encrypt(
- BOOL final,
- BYTE * pbData,
- DWORD * pdwDataLen,
- DWORD dwBufLen,
- CCryptHash &Hash = CCryptHash::EmptyHash) throw();
-
- HRESULT Encrypt(
- const BYTE * pbPlainText,
- DWORD dwPlainTextLen,
- BYTE * pbCipherText,
- DWORD * pdwCipherTextLen,
- CCryptHash &Hash = CCryptHash::EmptyHash) throw();
-
- HRESULT Decrypt(
- BOOL final,
- BYTE * pbData,
- DWORD * pdwDataLen,
- CCryptHash &Hash = CCryptHash::EmptyHash) throw();
- HRESULT Decrypt(
- const BYTE * pbCipherText,
- DWORD dwCipherTextLen,
- BYTE * pbPlainText,
- DWORD * pdwPlainTextLen,
- CCryptHash &Hash = CCryptHash::EmptyHash) throw();
- HRESULT EncryptString(
- LPCTSTR szPlainText,
- BYTE * pbCipherText,
- DWORD * pdwCipherTextLen,
- CCryptHash &Hash = CCryptHash::EmptyHash) throw();
- HRESULT ExportSimpleBlob(
- CCryptKey &ExpKey,
- DWORD dwFlags,
- BYTE * pbData,
- DWORD * pdwDataLen) throw();
- HRESULT ExportPublicKeyBlob(
- CCryptKey &ExpKey,
- DWORD dwFlags,
- BYTE * pbData,
- DWORD * pdwDataLen) throw();
- HRESULT ExportPrivateKeyBlob(
- CCryptKey &ExpKey,
- DWORD dwFlags,
- BYTE * pbData,
- DWORD * pdwDataLen) throw();
- HRESULT GetParam(DWORD dwParam, BYTE * pbData, DWORD * pdwDataLen, DWORD dwFlags = 0) throw();
- HRESULT SetParam(DWORD dwParam, BYTE * pbData, DWORD dwFlags = 0) throw();
- HRESULT GetAlgId(ALG_ID * pAlgId) throw();
- HRESULT SetAlgId(ALG_ID AlgId, DWORD dwFlags) throw();
- HRESULT GetBlockLength(DWORD * pdwBlockLen) throw();
- HRESULT GetKeyLength(DWORD * pdwKeyLen) throw();
- HRESULT GetSalt(BYTE * pbSalt, DWORD * pdwLength) throw();
- HRESULT SetSalt(BYTE * pbSalt) throw();
- HRESULT SetSaltEx(_CRYPTOAPI_BLOB * pBlobSalt) throw();
- HRESULT GetPermissions(DWORD * pdwPerms) throw();
- HRESULT SetPermissions(DWORD dwPerms) throw();
- HRESULT GetP(BYTE * pbP, DWORD * pdwLength) throw();
- HRESULT SetP(_CRYPTOAPI_BLOB * pBlobP) throw();
- HRESULT SetP(BYTE * pbP, DWORD dwLength) throw();
- HRESULT GetQ(BYTE * pbQ, DWORD * pdwLength) throw();
- HRESULT SetQ(_CRYPTOAPI_BLOB * pBlobQ) throw();
- HRESULT SetQ(BYTE * pbQ, DWORD dwLength) throw();
- HRESULT GetG(BYTE * pbG, DWORD * pdwLength) throw();
- HRESULT SetG(_CRYPTOAPI_BLOB * pBlobG) throw();
- HRESULT SetG(BYTE * pbG, DWORD dwLength) throw();
- HRESULT SetX() throw();
- HRESULT GetEffKeyLen(DWORD * pdwEffKeyLen) throw();
- HRESULT SetEffKeyLen(DWORD dwEffKeyLen) throw();
- HRESULT GetPadding(DWORD * pdwPadding) throw();
- HRESULT SetPadding(DWORD dwPadding) throw();
- HRESULT GetIV(BYTE * pbIV, DWORD * pdwLength) throw();
- HRESULT SetIV(BYTE * pbIV) throw();
- HRESULT GetMode(DWORD * pdwMode) throw();
- HRESULT SetMode(DWORD dwMode) throw();
- HRESULT GetModeBits(DWORD * pdwModeBits) throw();
- HRESULT SetModeBits(DWORD dwModeBits) throw();
-
- inline HCRYPTKEY GetHandle() throw()
- {
- return m_hKey;
- }
-
- static CCryptKey EmptyKey;
-}; // class CCryptKey
-
-
-
-// Specific instances of Keys and Hashes
-
-// class CCryptDerivedKey
-// A key that is derived from a hashed password. Two keys derived
-// from the same password will be identical.
-class CCryptDerivedKey : public CCryptKey
-{
-public:
- HRESULT Initialize(
- CCryptProv &Prov,
- CCryptHash &Hash,
- ALG_ID algid = CALG_RC4,
- DWORD dwFlags = CRYPT_EXPORTABLE) throw();
-}; // class CCryptDerivedKey
-
-// class CCryptRandomKey
-// A randomly generated key. Can be used internally by a program
-// to protect data during execution, or can be exported with Crypt.Export
-//
-// Currently it is possible to pass in AT_KEYEXCHANGE or AT_SIGNATURE
-// for algid, but these two will generate keys for the current key set, and
-// the resulting handle can only be used for exporting and importing keys or
-// signing hashes.
-class CCryptRandomKey : public CCryptKey
-{
-public:
- HRESULT Initialize(
- CCryptProv &Prov,
- ALG_ID algid = CALG_RC4,
- DWORD dwFlags = CRYPT_EXPORTABLE) throw();
-}; // class CCryptRandomKey
-
-// class CCryptUserExKey
-// Obtains the user's key exchange key pair.
-class CCryptUserExKey : public CCryptKey
-{
-public:
- HRESULT Initialize(CCryptProv &Prov) throw();
- HRESULT Create(CCryptProv &Prov) throw();
-}; // class CCryptUserExKey
-
-// class CCryptUserSigKey
-// Obtains the user's signature key pair
-class CCryptUserSigKey : public CCryptKey
-{
-public:
- HRESULT Initialize(CCryptProv &Prov) throw();
- HRESULT Create(CCryptProv &Prov) throw();
-}; // class CCryptUserSigKey
-
-// class CCryptImportKey
-// Forms a key from an imported key blob
-class CCryptImportKey : public CCryptKey
-{
-public:
- HRESULT Initialize(
- CCryptProv &Prov,
- BYTE * pbData,
- DWORD dwDataLen,
- CCryptKey &PubKey,
- DWORD dwFlags) throw();
-}; // class CCryptImportKey
-
-
-// class CCryptHash
-// A generic hash that may or may not take a key.
-class CCryptKeyedHash : public CCryptHash
-{
-public:
-
- HRESULT Initialize(CCryptProv &Prov, ALG_ID Algid, CCryptKey &Key, DWORD dwFlags) throw();
-}; // class CCryptKeyedHash
-
-// class CCryptMD5Hash
-// RSA's MD5 hash (RSA's most recent hash as of 9/7/99);
-class CCryptMD5Hash : public CCryptHash
-{
-public:
-
- HRESULT Initialize(CCryptProv &Prov, LPCTSTR szText = NULL) throw();
-}; // class CCryptMD5Hash
-
-// class CCryptMD4Hash
-// RSA's MD4 hash
-class CCryptMD4Hash : public CCryptHash
-{
-public:
-
- HRESULT Initialize(CCryptProv &Prov, LPCTSTR szText = NULL) throw();
-}; // class CCryptMD4Hash
-
-
-// class CCryptMD2Hash
-// RSA's MD2 hash
-class CCryptMD2Hash : public CCryptHash
-{
-public:
-
- HRESULT Initialize(CCryptProv &Prov, LPCTSTR szText = NULL) throw();
-}; // class CCryptMD2Hash
-
-
-// class CCryptSHAHash
-// The Secure Hash Algorithm hash, from NIST and NSA. Technically, SHA-1.
-class CCryptSHAHash : public CCryptHash
-{
-public:
-
- HRESULT Initialize(CCryptProv &Prov, LPCTSTR szText = NULL) throw();
-}; // class CCryptSHAHash
-
-// The Secure Hash Algorithm, from NIST and NSA. Identical to CCryptSHA
-typedef CCryptSHAHash CCryptSHA1Hash;
-
-
-// class CCryptHMACHash
-// Hash-base Message Authentication Code keyed hash
-class CCryptHMACHash : public CCryptHash
-{
-public:
- HRESULT Initialize(CCryptProv &Prov, CCryptKey &Key, LPCTSTR szText = NULL) throw();
-}; // class CCryptHMACHash
-
-// class CCryptMACHash
-// Message Authentication Code keyed hash. Believed to be less secure than HMAC
-class CCryptMACHash : public CCryptHash
-{
-public:
- HRESULT Initialize(CCryptProv &Prov, CCryptKey &Key, LPCTSTR szText = NULL) throw();
-}; // class CCryptMACHash
-
-// class CCryptSSL3SHAMD5Hash
-// Hash algorithm used by Secure Socket Layer
-class CCryptSSL3SHAMD5Hash : public CCryptHash
-{
-public:
- HRESULT Initialize(CCryptProv &Prov, CCryptKey &Key, LPCTSTR szText = NULL) throw();
-}; // class CCryptSSl3SHAMD5Hash
-
-}; // namespace ATL
-
-
-#include <atlcrypt.inl>
-#pragma pack(pop)
-#endif // __ATLCRYPT_H__
diff --git a/include/atl/atlcrypt.inl b/include/atl/atlcrypt.inl
deleted file mode 100644
index bfd119f87..000000000
--- a/include/atl/atlcrypt.inl
+++ /dev/null
@@ -1,1062 +0,0 @@
-// This is a part of the Active Template Library.
-// Copyright (C) Microsoft Corporation
-// All rights reserved.
-//
-// This source code is only intended as a supplement to the
-// Active Template Library Reference and related
-// electronic documentation provided with the library.
-// See these sources for detailed information regarding the
-// Active Template Library product.
-
-
-#ifndef __ATLCRYPT_INL__
-#define __ATLCRYPT_INL__
-
-#pragma once
-
-#ifndef __ATLCRYPT_H__
- #error atlcrypt.inl requires atlcrypt.h to be included first
-#endif
-
-
-namespace ATL
-{
-
-inline CCryptProv::CCryptProv( const CCryptProv& prov ) throw()
-{
- m_hProv = prov.m_hProv;
- if (m_hProv)
- AddRef();
-}
-
-inline CCryptProv::CCryptProv( HCRYPTPROV hProv, BOOL bTakeOwnership ) throw()
-{
- m_hProv = hProv;
- if (m_hProv && !bTakeOwnership)
- AddRef();
-}
-
-inline CCryptProv::~CCryptProv() throw()
-{
- Release();
-}
-
-inline CCryptProv& CCryptProv::operator=( const CCryptProv& prov ) throw()
-{
- if(this!=&prov)
- {
- Release();
-
- m_hProv = prov.m_hProv;
- if( m_hProv != NULL )
- {
- AddRef();
- }
- }
- return( *this );
-}
-
-inline HRESULT CCryptProv::AddRef() throw()
-{
- ATLASSUME( m_hProv != NULL );
-
- if (!CryptContextAddRef( m_hProv, NULL, 0))
- {
- return AtlHresultFromLastError();
- }
- return S_OK;
-}
-
-inline void CCryptProv::Attach( HCRYPTPROV hProv, BOOL bTakeOwnership ) throw()
-{
- ATLASSUME( m_hProv == NULL );
-
- m_hProv = hProv;
- if (m_hProv && !bTakeOwnership)
- AddRef();
-}
-
-inline HCRYPTPROV CCryptProv::Detach() throw()
-{
- HCRYPTPROV hProv;
-
- hProv = m_hProv;
- m_hProv = NULL;
-
- return( hProv );
-}
-
-
-inline CCryptProv::CCryptProv() throw() :
- m_hProv( NULL )
-{
-}
-
-inline HRESULT CCryptProv::Release() throw()
-{
- if( m_hProv != NULL )
- {
- if (!CryptReleaseContext( m_hProv, 0 ))
- {
- return AtlHresultFromLastError();
- }
- m_hProv = NULL;
- }
- return S_OK;
-}
-
-inline HRESULT CCryptProv::Initialize(
- DWORD dwProviderType,
- LPCTSTR szContainer,
- LPCTSTR szProvider,
- DWORD dwFlags) throw()
-{
- ATLASSUME(m_hProv == NULL);
-
- if (!CryptAcquireContext(&m_hProv, szContainer, szProvider, dwProviderType, dwFlags))
- {
- return AtlHresultFromLastError();
- }
- else return S_OK;
-}
-
-inline HRESULT CCryptProv::InitVerifyContext(
- DWORD dwProviderType,
- LPCTSTR szProvider,
- DWORD dwFlags) throw()
-{
- ATLASSUME(m_hProv == NULL);
-
- if (!CryptAcquireContext(&m_hProv, NULL, szProvider, dwProviderType, CRYPT_VERIFYCONTEXT | dwFlags))
- {
- return AtlHresultFromLastError();
- }
- else return S_OK;
-}
-
-inline HRESULT CCryptProv::InitCreateKeySet(
- DWORD dwProviderType,
- LPCTSTR szContainer,
- LPCTSTR szProvider,
- DWORD dwFlags) throw()
-{
- ATLASSUME(m_hProv == NULL);
-
- if (!CryptAcquireContext(&m_hProv, szContainer, szProvider, dwProviderType, CRYPT_NEWKEYSET | dwFlags))
- {
- return AtlHresultFromLastError();
- }
- else return S_OK;
-}
-
-inline HRESULT CCryptProv::DeleteKeySet(
- DWORD dwProviderType,
- LPCTSTR szContainer,
- LPCTSTR szProvider,
- DWORD dwFlags) throw()
-{
- HCRYPTPROV hProv = NULL;
- if (!CryptAcquireContext(&hProv, szContainer, szProvider, dwProviderType, CRYPT_DELETEKEYSET | dwFlags))
- {
- return AtlHresultFromLastError();
- }
- else return S_OK;
-}
-
-
-inline HRESULT CCryptProv::Uninitialize() throw()
-{
- ATLASSUME(m_hProv != NULL);
-
- if (!CryptReleaseContext(m_hProv, 0))
- {
- return AtlHresultFromLastError();
- }
- else
- {
- m_hProv = NULL;
- return S_OK;
- }
-}
-
-inline HRESULT CCryptProv::GetParam(DWORD dwParam, BYTE * pbData, DWORD * pdwDataLen, DWORD dwFlags) throw()
-{
- ATLASSUME(m_hProv != NULL);
-
- if (!CryptGetProvParam(m_hProv, dwParam, pbData, pdwDataLen, dwFlags))
- {
- return AtlHresultFromLastError();
- }
- else return S_OK;
-}
-
-inline HRESULT CCryptProv::SetParam( DWORD dwParam, BYTE* pbData, DWORD dwFlags) throw()
-{
- ATLASSUME(m_hProv != NULL);
-
- if (!CryptSetProvParam(m_hProv, dwParam, pbData, dwFlags ))
- {
- return AtlHresultFromLastError();
- }
- else return S_OK;
-}
-
-inline HRESULT CCryptProv::GetName(__out_bcount_part(*pdwLength, *pdwLength) LPSTR szBuf, __inout DWORD * pdwLength) throw()
-{
- return GetParam(PP_NAME, (BYTE *)szBuf, pdwLength);
-}
-
-inline HRESULT CCryptProv::GetContainer(__out_bcount_part(*pdwLength, *pdwLength) LPSTR szBuf, __inout DWORD * pdwLength) throw()
-{
- return GetParam(PP_CONTAINER, (BYTE *)szBuf, pdwLength);
-}
-
-inline HRESULT CCryptProv::GetImpType(DWORD * pdwImpType) throw()
-{
- DWORD dwLength = sizeof(DWORD);
- return GetParam(PP_IMPTYPE, (BYTE *)pdwImpType, &dwLength);
-}
-
-inline HRESULT CCryptProv::GetVersion(DWORD * pdwVersion) throw()
-{
- DWORD dwLength = sizeof(DWORD);
- return GetParam(PP_VERSION, (BYTE *)pdwVersion, &dwLength);
-}
-
-inline HRESULT CCryptProv::GetProvType(DWORD * pdwType) throw()
-{
- DWORD dwLength = sizeof(DWORD);
- return GetParam(PP_PROVTYPE, (BYTE * )pdwType, &dwLength);
-}
-
-inline HRESULT CCryptProv::GetSecurityDesc(SECURITY_INFORMATION * pSecInfo) throw()
-{
- DWORD dwSize = sizeof(SECURITY_INFORMATION);
- return GetParam(PP_KEYSET_SEC_DESCR, (BYTE *)pSecInfo, &dwSize);
-}
-
-inline HRESULT CCryptProv::SetSecurityDesc(SECURITY_INFORMATION SecInfo) throw()
-{
- return SetParam(PP_KEYSET_SEC_DESCR, (BYTE *)&SecInfo);
-}
-
-inline HRESULT CCryptProv::GenRandom(ULONG nLength, BYTE* pbBuffer ) throw()
-{
- ATLASSUME(m_hProv != NULL);
-
- if (!CryptGenRandom( m_hProv, nLength, pbBuffer ))
- {
- return AtlHresultFromLastError();
- }
-
- return S_OK;
-}
-
-inline CCryptHash::CCryptHash() throw() :
- m_hHash( NULL )
-{
-}
-
-inline CCryptHash::CCryptHash( const CCryptHash& hash ) throw()
-{
- m_hHash = hash.Duplicate();
-}
-
-inline CCryptHash::CCryptHash( HCRYPTHASH hHash, BOOL bTakeOwnership ) throw()
-{
- if (bTakeOwnership)
- m_hHash = hHash;
- else
- {
- m_hHash = NULL;
- BOOL bRet = ::CryptDuplicateHash( hHash, NULL, 0, &m_hHash );
- if (!bRet)
- m_hHash = NULL;
- }
-}
-
-inline CCryptHash::~CCryptHash() throw()
-{
- Destroy();
-}
-
-inline void CCryptHash::Attach( HCRYPTHASH hHash, BOOL bTakeOwnership ) throw()
-{
- ATLASSUME( m_hHash == NULL );
-
- if (bTakeOwnership)
- m_hHash = hHash;
- else
- {
- m_hHash = NULL;
- BOOL bRet = ::CryptDuplicateHash( hHash, NULL, 0, &m_hHash );
- if (!bRet)
- m_hHash = NULL;
- }
-}
-
-inline void CCryptHash::Destroy() throw()
-{
- if( m_hHash != NULL )
- {
- BOOL bSuccess;
-
- bSuccess = ::CryptDestroyHash( m_hHash );
-
- // can fail if the cryptographic service provider
- // (managed by CCryptProv) has already been destroyed
- ATLASSERT( bSuccess );
- m_hHash = NULL;
- }
-}
-
-inline HCRYPTHASH CCryptHash::Detach() throw()
-{
- HCRYPTHASH hHash;
-
- hHash = m_hHash;
- m_hHash = NULL;
-
- return hHash;
-}
-
-inline HCRYPTHASH CCryptHash::Duplicate() const throw()
-{
- BOOL bSuccess;
- HCRYPTHASH hHash;
-
- ATLASSUME( m_hHash != NULL );
-
- hHash = NULL;
- bSuccess = ::CryptDuplicateHash( m_hHash, NULL, 0, &hHash );
- if( !bSuccess )
- {
- return NULL;
- }
-
- return hHash;
-}
-
-inline HRESULT CCryptHash::Uninitialize() throw()
-{
- ATLASSUME(m_hHash != NULL);
-
- if (!CryptDestroyHash(m_hHash))
- {
- return AtlHresultFromLastError();
- }
- else
- {
- m_hHash = NULL;
- return S_OK;
- }
-}
-
-inline HRESULT CCryptHash::Detach(HCRYPTHASH * phHash) throw()
-{
- ATLASSERT(phHash);
- if (!phHash)
- return E_INVALIDARG;
-
- *phHash = m_hHash;
- m_hHash = NULL;
-
- return S_OK;
-}
-
-inline HRESULT CCryptHash::AddData(const BYTE * pbData, DWORD dwDataLen, DWORD dwFlags) throw()
-{
- ATLASSUME(m_hHash != NULL);
-
- if (!CryptHashData(m_hHash, pbData, dwDataLen, dwFlags))
- {
- return AtlHresultFromLastError();
- }
- else return S_OK;
-
-}
-
-inline HRESULT CCryptHash::AddString(LPCTSTR szData, DWORD dwFlags) throw()
-{
- return AddData((BYTE *)szData, (DWORD)_tcslen(szData) * sizeof(TCHAR), dwFlags);
-}
-
-inline HRESULT CCryptHash::GetParam(DWORD dwParam, BYTE * pbData, DWORD * pdwDataLen, DWORD dwFlags) throw()
-{
- ATLASSUME(m_hHash != NULL);
-
- if (!CryptGetHashParam(m_hHash, dwParam, pbData, pdwDataLen, dwFlags))
- {
- return AtlHresultFromLastError();
- }
- else return S_OK;
-}
-
-inline HRESULT CCryptHash::SetParam(DWORD dwParam, BYTE * pbData, DWORD dwFlags) throw()
-{
- ATLASSUME(m_hHash != NULL);
-
- if (!CryptSetHashParam(m_hHash, dwParam, pbData, dwFlags))
- {
- return AtlHresultFromLastError();
- }
- else return S_OK;
-}
-
-inline HRESULT CCryptHash::GetAlgId(ALG_ID * pAlgId) throw()
-{
- DWORD dwSize = sizeof(ALG_ID);
- return GetParam(HP_ALGID, (BYTE *)pAlgId, &dwSize);
-}
-
-inline HRESULT CCryptHash::GetSize(DWORD * pdwSize) throw()
-{
- DWORD dwLength = sizeof(DWORD);
- return GetParam(HP_HASHSIZE, (BYTE *)pdwSize, &dwLength);
-}
-
-inline HRESULT CCryptHash::GetValue(BYTE * pBuf, DWORD * pdwSize) throw()
-{
- return GetParam(HP_HASHVAL, pBuf, pdwSize);
-}
-
-inline HRESULT CCryptHash::SetValue(BYTE * pBuf) throw()
-{
- return SetParam(HP_HASHVAL, pBuf);
-}
-
-inline HRESULT CCryptHash::Sign(
- BYTE * pbSignature,
- DWORD * pdwSigLen,
- DWORD dwFlags,
- DWORD dwKeySpec) throw()
-{
- ATLASSUME(m_hHash != NULL);
-
- if (!CryptSignHash(m_hHash, dwKeySpec, NULL, dwFlags, pbSignature, pdwSigLen))
- {
- return AtlHresultFromLastError();
- }
- else return S_OK;
-}
-
-inline HRESULT CCryptHash::VerifySignature(
- const BYTE * pbSignature,
- DWORD dwSigLen,
- CCryptKey &PubKey,
- DWORD dwFlags) throw()
-{
- ATLASSUME(m_hHash != NULL);
-
- if (!CryptVerifySignature(m_hHash, pbSignature, dwSigLen, PubKey.GetHandle(), NULL, dwFlags))
- {
- return AtlHresultFromLastError();
- }
- else return S_OK;
-}
-
-__declspec(selectany) CCryptHash CCryptHash::EmptyHash = CCryptHash();
-__declspec(selectany) CCryptKey CCryptKey::EmptyKey = CCryptKey();
-inline CCryptKey::CCryptKey() throw() :
- m_hKey( NULL )
-{
-}
-
-inline CCryptKey::CCryptKey( const CCryptKey& key ) throw()
-{
- m_hKey = key.Duplicate();
-}
-
-inline CCryptKey::CCryptKey( HCRYPTKEY hKey, BOOL bTakeOwnership ) throw()
-{
- if (bTakeOwnership)
- m_hKey = hKey;
- else
- {
- BOOL bSuccess = ::CryptDuplicateKey( hKey, NULL, 0, &m_hKey );
- if( !bSuccess )
- m_hKey = NULL;
- }
-}
-
-inline CCryptKey::~CCryptKey() throw()
-{
- Destroy();
-}
-
-inline void CCryptKey::Attach( HCRYPTKEY hKey, BOOL bTakeOwnership ) throw()
-{
- ATLASSUME( m_hKey == NULL );
- if (bTakeOwnership)
- m_hKey = hKey;
- else
- {
- BOOL bSuccess = ::CryptDuplicateKey( hKey, NULL, 0, &m_hKey );
- if( !bSuccess )
- m_hKey = NULL;
- }
-}
-
-inline void CCryptKey::Destroy() throw()
-{
- if( m_hKey != NULL )
- {
- BOOL bSuccess;
-
- bSuccess = ::CryptDestroyKey( m_hKey );
-
- // can fail if the cryptographic service provider
- // (managed by CCryptProv) has already been destroyed
- ATLASSERT( bSuccess );
- m_hKey = NULL;
- }
-}
-
-inline HCRYPTKEY CCryptKey::Detach() throw()
-{
- HCRYPTKEY hKey;
-
- hKey = m_hKey;
- m_hKey = NULL;
-
- return( hKey );
-}
-
-inline HCRYPTKEY CCryptKey::Duplicate() const throw()
-{
- BOOL bSuccess;
-
- ATLASSUME( m_hKey != NULL );
-
- HCRYPTKEY hKey = NULL;
- bSuccess = ::CryptDuplicateKey( m_hKey, NULL, 0, &hKey );
- if( !bSuccess )
- return NULL;
-
- return hKey;
-}
-
-inline HRESULT CCryptKey::Uninitialize() throw()
-{
- ATLASSUME(m_hKey != NULL);
-
- if (!CryptDestroyKey(m_hKey))
- {
- return AtlHresultFromLastError();
- }
- else
- {
- m_hKey = NULL;
- return S_OK;
- }
-}
-
-inline HRESULT CCryptKey::Encrypt(
- BOOL final,
- BYTE * pbData,
- DWORD * pdwDataLen,
- DWORD dwBufLen,
- CCryptHash &Hash) throw()
-{
- ATLASSUME(m_hKey != NULL);
-
- if (!::CryptEncrypt(m_hKey, Hash.GetHandle(), final, 0, pbData, pdwDataLen, dwBufLen))
- {
- return AtlHresultFromLastError();
- }
- else return S_OK;
-
-}
-
-inline HRESULT CCryptKey::Decrypt(BOOL final, BYTE * pbData, DWORD * pdwDataLen, CCryptHash &Hash) throw()
-{
- ATLASSUME(m_hKey != NULL);
-
- if (!::CryptDecrypt(m_hKey, Hash.GetHandle(), final, 0, pbData, pdwDataLen))
- {
- return AtlHresultFromLastError();
- }
- else return S_OK;
-}
-
-
-inline HRESULT CCryptKey::Encrypt(
- const BYTE * pbPlainText,
- DWORD dwPlainTextLen,
- BYTE * pbCipherText,
- DWORD * pdwCipherTextLen,
- CCryptHash &Hash) throw()
-{
- ATLASSUME(m_hKey != NULL);
-
- if (*pdwCipherTextLen < dwPlainTextLen)
- return ERROR_MORE_DATA;
-
- Checked::memcpy_s(pbCipherText, dwPlainTextLen, pbPlainText, dwPlainTextLen);
- DWORD dwSize = dwPlainTextLen;
- if (!::CryptEncrypt(m_hKey, Hash.GetHandle(), TRUE, 0, pbCipherText, &dwSize, *pdwCipherTextLen))
- {
- return AtlHresultFromLastError();
- }
-
- *pdwCipherTextLen = dwSize;
- return S_OK;
-
-}
-
-inline HRESULT CCryptKey::Decrypt(
- const BYTE * pbCipherText,
- DWORD dwCipherTextLen,
- BYTE * pbPlainText,
- DWORD * pdwPlainTextLen,
- CCryptHash &Hash) throw()
-{
- ATLASSUME(m_hKey != NULL);
-
- if (*pdwPlainTextLen < dwCipherTextLen)
- return ERROR_MORE_DATA;
-
- Checked::memcpy_s(pbPlainText, dwCipherTextLen, pbCipherText, dwCipherTextLen);
- DWORD dwSize = dwCipherTextLen;
- if (!::CryptDecrypt(m_hKey, Hash.GetHandle(), TRUE, 0, pbPlainText, &dwSize))
- {
- return AtlHresultFromLastError();
- }
-
- *pdwPlainTextLen = dwSize;
- return S_OK;
-}
-
-inline HRESULT CCryptKey::EncryptString(
- LPCTSTR szPlainText,
- BYTE * pbCipherText,
- DWORD * pdwCipherTextLen,
- CCryptHash &Hash) throw()
-{
- DWORD dwSize = ((DWORD)_tcslen(szPlainText) + 1) * sizeof(TCHAR);
- return Encrypt((BYTE *)szPlainText, dwSize, pbCipherText, pdwCipherTextLen, Hash);
-}
-
-inline HRESULT CCryptKey::ExportSimpleBlob(
- CCryptKey &ExpKey,
- DWORD dwFlags,
- BYTE * pbData,
- DWORD * pdwDataLen) throw()
-{
- ATLASSUME(m_hKey != NULL);
-
- if (!CryptExportKey(m_hKey, ExpKey.GetHandle(), SIMPLEBLOB, dwFlags, pbData, pdwDataLen))
- {
- return AtlHresultFromLastError();
- }
- else return S_OK;
-}
-
-inline HRESULT CCryptKey::ExportPublicKeyBlob(
- CCryptKey &ExpKey,
- DWORD dwFlags,
- BYTE * pbData,
- DWORD * pdwDataLen) throw()
-{
- ATLASSUME(m_hKey != NULL);
-
- if (!CryptExportKey(m_hKey, ExpKey.GetHandle(), PUBLICKEYBLOB, dwFlags, pbData, pdwDataLen))
- {
- return AtlHresultFromLastError();
- }
- else return S_OK;
-}
-
-inline HRESULT CCryptKey::ExportPrivateKeyBlob(
- CCryptKey &ExpKey,
- DWORD dwFlags,
- BYTE * pbData,
- DWORD * pdwDataLen) throw()
-{
- ATLASSUME(m_hKey != NULL);
-
- if (!CryptExportKey(m_hKey, ExpKey.GetHandle(), PRIVATEKEYBLOB, dwFlags, pbData, pdwDataLen))
- {
- return AtlHresultFromLastError();
- }
- else return S_OK;
-}
-
-inline HRESULT CCryptKey::GetParam(DWORD dwParam, BYTE * pbData, DWORD * pdwDataLen, DWORD dwFlags) throw()
-{
- ATLASSUME(m_hKey != NULL);
-
- if (!CryptGetKeyParam(m_hKey, dwParam, pbData, pdwDataLen, dwFlags))
- {
- return AtlHresultFromLastError();
- }
- else return S_OK;
-}
-
-inline HRESULT CCryptKey::SetParam(DWORD dwParam, BYTE * pbData, DWORD dwFlags) throw()
-{
- ATLASSUME(m_hKey != NULL);
-
- if (!CryptSetKeyParam(m_hKey, dwParam, pbData, dwFlags))
- {
- return AtlHresultFromLastError();
- }
- else return S_OK;
-}
-
-inline HRESULT CCryptKey::GetAlgId(ALG_ID * pAlgId) throw()
-{
- DWORD dwSize = sizeof(DWORD);
- return GetParam(KP_ALGID, (BYTE *)pAlgId, &dwSize);
-}
-
-inline HRESULT CCryptKey::SetAlgId(ALG_ID AlgId, DWORD dwFlags) throw()
-{
- return SetParam(KP_ALGID, (BYTE *)&AlgId, dwFlags);
-}
-
-inline HRESULT CCryptKey::GetBlockLength(DWORD * pdwBlockLen) throw()
-{
- DWORD dwSize = sizeof(DWORD);
- return GetParam(KP_BLOCKLEN, (BYTE *)pdwBlockLen, &dwSize);
-}
-
-inline HRESULT CCryptKey::GetKeyLength(DWORD * pdwKeyLen) throw()
-{
- DWORD dwSize = sizeof(DWORD);
- return GetParam(KP_KEYLEN, (BYTE *)pdwKeyLen, &dwSize);
-}
-
-inline HRESULT CCryptKey::GetSalt(BYTE * pbSalt, DWORD * pdwLength) throw()
-{
- return GetParam(KP_SALT, pbSalt, pdwLength);
-}
-
-inline HRESULT CCryptKey::SetSalt(BYTE * pbSalt) throw()
-{
- return SetParam(KP_SALT, pbSalt);
-}
-
-inline HRESULT CCryptKey::SetSaltEx(_CRYPTOAPI_BLOB * pBlobSalt) throw()
-{
- return SetParam(KP_SALT_EX, (BYTE *)pBlobSalt);
-}
-
-inline HRESULT CCryptKey::GetPermissions(DWORD * pdwPerms) throw()
-{
- DWORD dwSize = sizeof(DWORD);
- return GetParam(KP_PERMISSIONS, (BYTE *)pdwPerms, &dwSize);
-}
-
-inline HRESULT CCryptKey::SetPermissions(DWORD dwPerms) throw()
-{
- return SetParam(KP_PERMISSIONS, (BYTE *)&dwPerms);
-}
-
-inline HRESULT CCryptKey::GetP(BYTE * pbP, DWORD * pdwLength) throw()
-{
- return GetParam(KP_P, (BYTE *)pbP, pdwLength);
-}
-
-inline HRESULT CCryptKey::SetP(_CRYPTOAPI_BLOB * pBlobP) throw()
-{
- return SetParam(KP_P, (BYTE *)pBlobP);
-}
-
-inline HRESULT CCryptKey::SetP(BYTE * pbP, DWORD dwLength) throw()
-{
- _CRYPTOAPI_BLOB blob = { dwLength, pbP };
- return SetParam(KP_P, (BYTE *)&blob);
-}
-
-inline HRESULT CCryptKey::GetQ(BYTE * pbQ, DWORD * pdwLength) throw()
-{
- return GetParam(KP_Q, (BYTE *)pbQ, pdwLength);
-}
-
-inline HRESULT CCryptKey::SetQ(_CRYPTOAPI_BLOB * pBlobQ) throw()
-{
- return SetParam(KP_Q, (BYTE *)pBlobQ);
-}
-
-inline HRESULT CCryptKey::SetQ(BYTE * pbQ, DWORD dwLength) throw()
-{
- _CRYPTOAPI_BLOB blob = { dwLength, pbQ };
- return SetParam(KP_Q, (BYTE *)&blob);
-}
-
-inline HRESULT CCryptKey::GetG(BYTE * pbG, DWORD * pdwLength) throw()
-{
- return GetParam(KP_G, (BYTE *)pbG, pdwLength);
-}
-
-inline HRESULT CCryptKey::SetG(_CRYPTOAPI_BLOB * pBlobG) throw()
-{
- return SetParam(KP_G, (BYTE *)pBlobG);
-}
-
-inline HRESULT CCryptKey::SetG(BYTE * pbG, DWORD dwLength) throw()
-{
- _CRYPTOAPI_BLOB blob = { dwLength, pbG };
- return SetParam(KP_G, (BYTE *)&blob);
-}
-
-inline HRESULT CCryptKey::SetX() throw()
-{
- return SetParam(KP_X, NULL);
-}
-
-inline HRESULT CCryptKey::GetEffKeyLen(DWORD * pdwEffKeyLen) throw()
-{
- DWORD dwSize = sizeof(DWORD);
- return GetParam(KP_EFFECTIVE_KEYLEN, (BYTE *)pdwEffKeyLen, &dwSize);
-}
-
-inline HRESULT CCryptKey::SetEffKeyLen(DWORD dwEffKeyLen) throw()
-{
- return SetParam(KP_EFFECTIVE_KEYLEN, (BYTE *)&dwEffKeyLen);
-}
-
-inline HRESULT CCryptKey::GetPadding(DWORD * pdwPadding) throw()
-{
- DWORD dwSize = sizeof(DWORD);
- return GetParam(KP_PADDING, (BYTE *)pdwPadding, &dwSize);
-}
-
-inline HRESULT CCryptKey::SetPadding(DWORD dwPadding) throw()
-{
- return SetParam(KP_PADDING, (BYTE *)&dwPadding);
-}
-
-inline HRESULT CCryptKey::GetIV(BYTE * pbIV, DWORD * pdwLength) throw()
-{
- return GetParam(KP_IV, pbIV, pdwLength);
-}
-
-inline HRESULT CCryptKey::SetIV(BYTE * pbIV) throw()
-{
- return SetParam(KP_IV, pbIV);
-}
-
-inline HRESULT CCryptKey::GetMode(DWORD * pdwMode) throw()
-{
- DWORD dwSize = sizeof(DWORD);
- return GetParam(KP_MODE, (BYTE *)pdwMode, &dwSize);
-}
-
-inline HRESULT CCryptKey::SetMode(DWORD dwMode) throw()
-{
- return SetParam(KP_MODE, (BYTE *)&dwMode);
-}
-
-inline HRESULT CCryptKey::GetModeBits(DWORD * pdwModeBits) throw()
-{
- DWORD dwSize = sizeof(DWORD);
- return GetParam(KP_MODE_BITS, (BYTE *)pdwModeBits, &dwSize);
-}
-
-inline HRESULT CCryptKey::SetModeBits(DWORD dwModeBits) throw()
-{
- return SetParam(KP_MODE_BITS, (BYTE *)&dwModeBits);
-}
-
-inline HRESULT CCryptDerivedKey::Initialize(
- CCryptProv &Prov,
- CCryptHash &Hash,
- ALG_ID algid,
- DWORD dwFlags) throw()
-{
- ATLASSUME(m_hKey == NULL);
-
- if (!CryptDeriveKey(Prov.GetHandle(), algid, Hash.GetHandle(), dwFlags, &m_hKey))
- {
- return AtlHresultFromLastError();
- }
- else return S_OK;
-}
-
-inline HRESULT CCryptRandomKey::Initialize(CCryptProv &Prov, ALG_ID algid, DWORD dwFlags) throw()
-{
- ATLASSUME(m_hKey == NULL);
-
- if (!CryptGenKey(Prov.GetHandle(), algid, dwFlags, &m_hKey))
- {
- return AtlHresultFromLastError();
- }
- else return S_OK;
-
-}
-
-inline HRESULT CCryptUserExKey::Initialize(CCryptProv &Prov) throw()
-{
- ATLASSUME(m_hKey == NULL);
-
- if (!CryptGetUserKey(Prov.GetHandle(), AT_KEYEXCHANGE, &m_hKey))
- {
- return AtlHresultFromLastError();
- }
- else return S_OK;
-}
-
-inline HRESULT CCryptUserExKey::Create(CCryptProv &Prov) throw()
-{
- ATLASSUME(m_hKey == NULL);
-
- if (!CryptGenKey(Prov.GetHandle(), AT_KEYEXCHANGE, 0, &m_hKey))
- {
- return AtlHresultFromLastError();
- }
- else return S_OK;
-}
-
-inline HRESULT CCryptUserSigKey::Initialize(CCryptProv &Prov) throw()
-{
- ATLASSUME(m_hKey == NULL);
-
- if (!CryptGetUserKey(Prov.GetHandle(), AT_SIGNATURE, &m_hKey))
- {
- return AtlHresultFromLastError();
- }
- else return S_OK;
-}
-
-inline HRESULT CCryptUserSigKey::Create(CCryptProv &Prov) throw()
-{
- ATLASSUME(m_hKey == NULL);
-
- if (!CryptGenKey(Prov.GetHandle(), AT_SIGNATURE, 0, &m_hKey))
- {
- return AtlHresultFromLastError();
- }
- else return S_OK;
-}
-
-inline HRESULT CCryptImportKey::Initialize(
- CCryptProv &Prov,
- BYTE * pbData,
- DWORD dwDataLen,
- CCryptKey &PubKey,
- DWORD dwFlags) throw()
-{
- ATLASSUME(m_hKey == NULL);
-
- if (!CryptImportKey(Prov.GetHandle(), pbData, dwDataLen, PubKey.GetHandle(), dwFlags, &m_hKey))
- {
- return AtlHresultFromLastError();
- }
- else return S_OK;
-}
-
-inline HRESULT CCryptKeyedHash::Initialize(
- CCryptProv &Prov,
- ALG_ID Algid,
- CCryptKey &Key,
- DWORD dwFlags) throw()
-{
- ATLASSUME(m_hHash == NULL);
-
- if (!CryptCreateHash(Prov.GetHandle(), Algid, Key.GetHandle(), dwFlags, &m_hHash))
- {
- return AtlHresultFromLastError();
- }
- else return S_OK;
-}
-
-inline HRESULT CCryptMD5Hash::Initialize(CCryptProv &Prov, LPCTSTR szText) throw()
-{
- ATLASSUME(m_hHash == NULL);
-
- if (!CryptCreateHash(Prov.GetHandle(), CALG_MD5, 0, 0, &m_hHash))
- {
- return AtlHresultFromLastError();
- }
-
- if (szText!=NULL)
- return AddString(szText);
- else return S_OK;
-}
-
-inline HRESULT CCryptMD4Hash::Initialize(CCryptProv &Prov, LPCTSTR szText) throw()
-{
- ATLASSUME(m_hHash == NULL);
-
- if (!CryptCreateHash(Prov.GetHandle(), CALG_MD4, 0, 0, &m_hHash))
- {
- return AtlHresultFromLastError();
- }
- if (szText!=NULL)
- return AddString(szText);
- else return S_OK;
-}
-
-inline HRESULT CCryptMD2Hash::Initialize(CCryptProv &Prov, LPCTSTR szText) throw()
-{
- ATLASSUME(m_hHash == NULL);
-
- if (!CryptCreateHash(Prov.GetHandle(), CALG_MD2, 0, 0, &m_hHash))
- {
- return AtlHresultFromLastError();
- }
- if (szText!=NULL)
- return AddString(szText);
- else return S_OK;
-}
-
-inline HRESULT CCryptSHAHash::Initialize(CCryptProv &Prov, LPCTSTR szText) throw()
-{
- ATLASSUME(m_hHash == NULL);
-
- if (!CryptCreateHash(Prov.GetHandle(), CALG_SHA, 0, 0, &m_hHash))
- {
- return AtlHresultFromLastError();
- }
- if (szText!=NULL)
- return AddString(szText);
- else return S_OK;
-}
-
-inline HRESULT CCryptHMACHash::Initialize(CCryptProv &Prov, CCryptKey &Key, LPCTSTR szText) throw()
-{
- ATLASSUME(m_hHash == NULL);
-
- if (!CryptCreateHash(Prov.GetHandle(), CALG_HMAC, Key.GetHandle(), 0, &m_hHash))
- {
- return AtlHresultFromLastError();
- }
- if (szText!=NULL)
- return AddString(szText);
- else return S_OK;
-
-}
-
-inline HRESULT CCryptMACHash::Initialize(CCryptProv &Prov, CCryptKey &Key, LPCTSTR szText) throw()
-{
- ATLASSUME(m_hHash == NULL);
-
- if (!CryptCreateHash(Prov.GetHandle(), CALG_MAC, Key.GetHandle(), 0, &m_hHash))
- {
- return AtlHresultFromLastError();
- }
- if (szText!=NULL)
- return AddString(szText);
- else return S_OK;
-
-}
-
-inline HRESULT CCryptSSL3SHAMD5Hash::Initialize(CCryptProv &Prov, CCryptKey &Key, LPCTSTR szText) throw()
-{
- ATLASSUME(m_hHash == NULL);
-
- if (!CryptCreateHash(Prov.GetHandle(), CALG_SSL3_SHAMD5, Key.GetHandle(), 0, &m_hHash))
- {
- return AtlHresultFromLastError();
- }
- if (szText!=NULL)
- return AddString(szText);
- else return S_OK;
-
-}
-
-}; // namespace ATL
-
-#endif //__ATLCRYPT_INL__
diff --git a/include/atl/atlextmgmt.h b/include/atl/atlextmgmt.h
deleted file mode 100644
index 59f8d4353..000000000
--- a/include/atl/atlextmgmt.h
+++ /dev/null
@@ -1,1279 +0,0 @@
-// This is a part of the Active Template Library.
-// Copyright (C) Microsoft Corporation
-// All rights reserved.
-//
-// This source code is only intended as a supplement to the
-// Active Template Library Reference and related
-// electronic documentation provided with the library.
-// See these sources for detailed information regarding the
-// Active Template Library product.
-
-#ifndef __ATLEXTMGMT_H__
-#define __ATLEXTMGMT_H__
-
-#pragma once
-#pragma warning(push)
-#pragma warning(disable: 4702)
-#include <atlsoap.h>
-#include <atlutil.h>
-#include <atlsrvres.h>
-#include <atlsecurity.h>
-
-//
-// You can change the local group that is used for authorizing
-// site administrators by #define'ing ATL_DEFAULT_AUTH group
-// to something else before including this header file. For
-// example:
-// #define ATL_DEFAULT_AUTHGRP CSid(_T("My Heros"))
-// Verify that the logged on user is a member of
-// the local group 'My Heros' before allowing them to
-// administrate this site.
-//
-// #define ATL_DEFAULT_AUTHGRP Sids::World
-// Allow everyone access
-//
-// #define ATL_DEFAULT_AUTHGRP Sids::Null
-// Allow no one access
-//
-#ifndef ATL_DEFAULT_AUTHGRP
- #define ATL_DEFAULT_AUTHGRP Sids::Admins()
-#endif
-
-// If you #define ATL_NO_DEFAULT_AUTHORITY then there will be no authorization
-// check before allowing access to management functions. You can also #define
-// ATL_NO_DEFAULT_AUTHORITY and then declare you own instance of _Authority
-// before #include-ing atlextmgmt.h to use a different authorization scheme.
-#ifndef ATL_NO_DEFAULT_AUTHORITY
- __declspec(selectany) CDefaultAuth _Authority;
-#endif
-
-// You can choose which of the management handlers actually get used by
-// #defining the following constants before including this header
-// _ATL_THREADPOOL_MANAGEMENT (The thread pool manager web service and web based UI)
-// _ATL_STENCILCACHE_MANAGEMENT (The stencil cache manager web service and web based UI)
-// _ATL_DLLCACHE_MANAGEMENT (The DLL cache manager service and web based UI)
-
-// You can use the following constants to remove the web based UI if you don't
-// want to use it.
-// _ATL_THREADPOOL_NOUI (removes the thread pool mgr's stencil handler)
-// _ATL_STENCILCACHE_NOUI (removes the stencil cache mgr's stencil handler)
-// _ATL_DLLCACHE_NOUI (removes the dll cache mgr's stencil handler)
-
-// You can use the following constants to remove the web service management
-// components individually
-// _ATL_THREADPOOL_NOWEBSERVICE (removes the thread pool mgr's stencil handler)
-// _ATL_STENCILCACHE_NOWEBSERVICE (removes the stencil cache mgr's stencil handler)
-// _ATL_DLLCACHE_NOWEBSERVICE (removes the dll cache mgr's stencil handler)
-
-
-// The following constants declare resource names of stencils included
-// as resources in the module that uses this header. These stencils are
-// used for the web based UI for the management objects. You can provide
-// stencils of your own by including them as resources and redefining these
-// constants before including this header.
-#ifndef IDR_THREADMGR_SRF
- #define IDR_THREADMGR_SRF "THREADMGR.SRF"
-#endif
-
-#ifndef IDR_STENCILMGR_SRF
- #define IDR_STENCILMGR_SRF "STENCILMGR.SRF"
-#endif
-
-#ifndef IDR_DLLMGR_SRF
- #define IDR_DLLMGR_SRF "DLLMGR.SRF"
-#endif
-
-// A warning so users using the web based UI to manage their extension
-// will remember to include the stencil resources in their projects
-#if (defined(_ATL_THREADPOOL_MANAGEMENT) && !defined(_ATL_THREADPOOL_NOUI)) || (defined(_ATL_STENCILCACHE_MANAGEMENT) && !defined(_ATL_STENCILCACHE_NOUI)) || (defined(_ATL_DLLCACHE_MANAGEMENT) && !defined(_ATL_DLLCACHE_NOUI))
-#ifndef NO_ATL_MGMT_STENCIL_WARNING
- #pragma message("*************** Please Note ***************")
- #pragma message("Your usage of atlextmgmt.h requires you to include management")
- #pragma message("stencil resources in your module's resource file.")
- #pragma message("Please make sure you include atlsrv.rc in your resource file.\r\n")
-#endif
-#endif
-
-// These constants define the names used for the handler objects for the
-// various services. You can change the names by redefining these constants
-// before including this header
-
-#ifndef ID_THREADMGR_WEBSERVICE_NAME
- #define ID_THREADMGR_WEBSERVICE_NAME "ThreadPoolManager"
-#endif
-
-#ifndef ID_THREADMGR_WEBSERVICE_URL
- #define ID_THREADMGR_WEBSERVICE_URL "http://www.microsoft.com/vc/atlserver/soap/ThreadPoolManager"
-#endif
-
-#ifndef ID_THREADMGR_WEBSERVICE_WSDL
- #define ID_THREADMGR_WEBSERVICE_WSDL "GenThreadPoolManagerWSDL"
-#endif
-
-#ifndef ID_THREADMGR_SRFHANDLER_NAME
- #define ID_THREADMGR_SRFHANDLER_NAME "ThreadMgrSrf"
-#endif
-
-#ifndef ID_STENCILCACHEMGR_WEBSERVICE_NAME
- #define ID_STENCILCACHEMGR_WEBSERVICE_NAME "StencilCacheManager"
-#endif
-
-#ifndef ID_STENCILCACHEMGR_WEBSERVICE_URL
- #define ID_STENCILCACHEMGR_WEBSERVICE_URL "http://www.microsoft.com/vc/atlserver/soap/StencilCacheManager"
-#endif
-
-#ifndef ID_STENCILCACHEMGR_WEBSERVICE_WSDL
- #define ID_STENCILCACHEMGR_WEBSERVICE_WSDL "GenStencilCacheManagerWSDL"
-#endif
-
-#ifndef ID_STENCILCACHEMGR_SRFHANDLER_NAME
- #define ID_STENCILCACHEMGR_SRFHANDLER_NAME "StencilMgrSrf"
-#endif
-
-#ifndef ID_DLLCACHEMGR_WEBSERVICE_NAME
- #define ID_DLLCACHEMGR_WEBSERVICE_NAME "DllCacheManager"
-#endif
-
-#ifndef ID_DLLCACHEMGR_WEBSERVICE_URL
- #define ID_DLLCACHEMGR_WEBSERVICE_URL "http://www.microsoft.com/vc/atlserver/soap/DllCacheManager"
-#endif
-
-#ifndef ID_DLLCACHEMGR_WEBSERVICE_WSDL
- #define ID_DLLCACHEMGR_WEBSERVICE_WSDL "GenDllCacheManagerWSDL"
-#endif
-
-
-#ifndef ID_DLLCACHEMGR_SRFHANDLER_NAME
- #define ID_DLLCACHEMGR_SRFHANDLER_NAME "DllMgrSrf"
-#endif
-
-#pragma pack(push,_ATL_PACKING)
-namespace ATL {
-
-[emitidl(restricted)];
-
-#define ATL_COLOR_TR1 RGB(0xd2, 0xff, 0xff)
-#define ATL_COLOR_TR2 RGB(0xd2, 0xff, 0xd2)
-#define ATL_COLOR_BODYBG RGB(0xec, 0xf9, 0xec)
-
-// _AtlRedirectToPage builds up a redirect URL from the
-// current request plus a Handler= specification and
-// redirects the user's browser to that page.
-inline HTTP_CODE _AtlRedirectToPage(
- IHttpServerContext *pContext,
- CHttpRequest& request,
- CHttpResponse& response,
- const char *szHandler)
-{
- ATLENSURE(pContext);
- CStringA strRedirect("http://");
-
- char buff[ATL_URL_MAX_URL_LENGTH];
- DWORD dwLen = static_cast<DWORD>(_countof(buff));
- if (!pContext->GetServerVariable("SERVER_NAME", buff, &dwLen))
- {
- return HTTP_FAIL;
- }
- buff[_countof(buff)-1]='\0';
- strRedirect+=buff;
-
- dwLen = static_cast<DWORD>(_countof(buff));
- if (!request.GetUrl(buff, &dwLen))
- {
- return HTTP_FAIL;
- }
- buff[_countof(buff)-1]='\0';
- strRedirect+=buff;
- strRedirect+=szHandler;
-
- if (strRedirect.GetLength() >= ATL_URL_MAX_URL_LENGTH)
- {
- return HTTP_FAIL;
- }
-
- BOOL bOK=response.Redirect(strRedirect.GetString());
-
- return bOK ? HTTP_SUCCESS_NO_PROCESS : HTTP_FAIL;
-}
-
-#ifdef _ATL_THREADPOOL_MANAGEMENT
-///////////////////////////////////////////////////////////////////////
-// Thread pool management
-
-[ uuid("44e9962a-5207-4d2a-a466-5f08a76e0e5d"), object ]
-__interface IThreadPoolMgr
-{
- [id(0)] STDMETHOD(SetSize)([in] int nNumThreads);
- [id(1)] STDMETHOD(GetSize)([out,retval] int *pnNumThreads);
-
-};
-
-
-class CThreadPoolMgrObject
-{
-public:
- CThreadPoolMgrObject() throw()
- {
- }
-
- HRESULT SetSize(int nNumThreads) throw()
- {
- if (!m_spThreadPoolConfig)
- return E_UNEXPECTED;
-
- CRevertThreadToken revert;
- if (!revert.Initialize())
- return E_FAIL;
-
- HRESULT hr = m_spThreadPoolConfig->SetSize(nNumThreads);
-
- DWORD dwErr = revert.Restore();
- if (dwErr)
- return AtlHresultFromWin32(dwErr);
-
- return hr;
- }
-
-
- HRESULT GetSize(int *pnNumThreads) throw()
- {
- if (!m_spThreadPoolConfig)
- return E_UNEXPECTED;
-
- return m_spThreadPoolConfig->GetSize(pnNumThreads);
-
- }
-
- HTTP_CODE Initialize(IServiceProvider *pProvider) throw()
- {
- ATLASSERT(pProvider); // should never be NULL
- if (!pProvider)
- return HTTP_ERROR(500, ISE_SUBERR_UNEXPECTED);
-
- if (m_spThreadPoolConfig)
- return HTTP_SUCCESS; // already initialized
-
- pProvider->QueryService(__uuidof(IThreadPoolConfig), &m_spThreadPoolConfig);
- return m_spThreadPoolConfig ? HTTP_SUCCESS : HTTP_ERROR(500, ISE_SUBERR_UNEXPECTED);
- }
-
-private:
- CComPtr<IThreadPoolConfig> m_spThreadPoolConfig;
-};
-
-#ifndef _ATL_THREADPOOL_NOWEBSERVICE
-#pragma warning(push)
-#pragma warning(disable:4199)
-[
- soap_handler(
- name= ID_THREADMGR_WEBSERVICE_NAME,
- namespace= ID_THREADMGR_WEBSERVICE_URL,
- protocol= "soap"
- ),
- request_handler(
- name= ID_THREADMGR_WEBSERVICE_NAME,
- sdl= ID_THREADMGR_WEBSERVICE_WSDL
- )
-]
-class CThreadPoolManager :
- public IThreadPoolMgr
-{
-#pragma warning(pop)
-public:
- [soap_method]
- STDMETHOD(SetSize)(int nNumThreads)
- {
- return m_PoolMgr.SetSize(nNumThreads);
- }
-
- [soap_method]
- STDMETHOD(GetSize)(int *pnNumThreads)
- {
- return m_PoolMgr.GetSize(pnNumThreads);
- }
-
- // override HandleRequest to Initialize our m_spServiceProvider
- // and to handle authorizing the client.
- HTTP_CODE HandleRequest(AtlServerRequest *pRequestInfo, IServiceProvider *pProvider)
- {
- HTTP_CODE hcErr = m_PoolMgr.Initialize(pProvider);
- if (hcErr != HTTP_SUCCESS)
- return hcErr;
-
- // Make sure caller is authorized on this system
-__if_exists(_Authority)
-{
- hcErr = HTTP_FAIL;
- ATLTRY(hcErr = _Authority.IsAuthorized(pRequestInfo, ATL_DEFAULT_AUTHGRP))
-}
- if (hcErr == HTTP_SUCCESS)
- {
- hcErr = __super::HandleRequest(pRequestInfo, pProvider);
- }
- return hcErr;
- }
-private:
- CThreadPoolMgrObject m_PoolMgr;
-};
-#endif //_ATL_THREADPOOL_NOWEBSERVICE
-
-#ifndef _ATL_THREADPOOL_NOUI
-#define INVALID_COMMAND_ID -1
-#define MAX_COMMAND_ID 64
-
-[request_handler(name=ID_THREADMGR_SRFHANDLER_NAME)]
-class CThreadMgrStencil
-{
-public:
- CThreadMgrStencil() :
- m_nColor(ATL_COLOR_TR1)
- {
-
- }
-
- [tag_name("GetSize")]
- HTTP_CODE GetSize()
- {
- int nSize = 0;
- HRESULT hr = m_PoolMgr.GetSize(&nSize);
- if (SUCCEEDED(hr))
- {
- m_HttpResponse << nSize;
- }
- else
- m_HttpResponse << "size not found";
-
- return HTTP_SUCCESS;
- }
-
- [tag_name("GetTRColor")]
- HTTP_CODE GetTRColor()
- {
- m_nColor = (m_nColor == ATL_COLOR_TR1) ? ATL_COLOR_TR2 : ATL_COLOR_TR1;
- TCHAR cr[8];
- if (RGBToHtml(m_nColor, cr, sizeof(cr)))
- m_HttpResponse << cr;
-
- return HTTP_SUCCESS;
- }
-
- [tag_name("GetBodyColor")]
- HTTP_CODE GetBodyColor()
- {
- TCHAR cr[8];
- if (RGBToHtml(ATL_COLOR_BODYBG, cr, sizeof(cr)))
- m_HttpResponse << cr;
- return HTTP_SUCCESS;
- }
-
-
- HTTP_CODE ValidateAndExchange() throw()
- {
- _ATLTRY
- {
- // Initialize the thread pool manager instance. Internally
- // the initialize function will only intialize it's data structures
- // once.
- HTTP_CODE hcErr = m_PoolMgr.Initialize(m_spServiceProvider);
- if (hcErr != HTTP_SUCCESS)
- return hcErr;
-
-__if_exists(_Authority)
-{
- // Make sure caller is authorized on this system
- hcErr = HTTP_FAIL;
- ATLTRY(hcErr = _Authority.IsAuthorized(m_pRequestInfo, ATL_DEFAULT_AUTHGRP))
- if (hcErr != HTTP_SUCCESS)
- return hcErr;
-}
-
-
- m_HttpResponse.SetContentType("text/html");
-
- CString strHandler, strOptParam;
- int nCmdToExec = INVALID_COMMAND_ID;
-
- if (m_HttpRequest.GetMethod() == CHttpRequest::HTTP_METHOD_POST)
- {
- // check to see if we have a "Method" form variable and can execute a command
- DWORD dwErr = m_HttpRequest.FormVars.Exchange("Method", &strHandler);
- if (dwErr == VALIDATION_S_OK)
- {
- if (strHandler == _T("ExecuteCommand"))
- {
- // get the value of the command parameter so we can execute it
- dwErr = m_HttpRequest.FormVars.Validate("command", &nCmdToExec, 0, MAX_COMMAND_ID);
- if (dwErr == VALIDATION_S_OK)
- {
- // get the optional parameter if it's there.
- m_HttpRequest.FormVars.Validate("DynValue", &strOptParam, 0, MAX_COMMAND_ID);
-
- hcErr = ExecCommand(nCmdToExec, strOptParam);
- return hcErr;
- }
- }
- }
- }
-
- // If we had a proper command to execute, we would have done it by now.
- // Just handle like it's a normal request to view the thread count.
- hcErr = LoadStencilResource(m_hInstHandler, IDR_THREADMGR_SRF);
- return hcErr;
-
- }
- _ATLCATCHALL()
- {
- return HTTP_FAIL;
- }
- }
-
- HTTP_CODE ExecCommand(int nCmdToExec, CString& strOptParam)
- {
- switch (nCmdToExec)
- {
- case 0:
- TCHAR *pStop = NULL;
- int nValue = _tcstoul(strOptParam, &pStop, 10);
- m_PoolMgr.SetSize(nValue);
- break;
- };
-
- return _AtlRedirectToPage(
- m_spServerContext,
- m_HttpRequest,
- m_HttpResponse,
- "?Handler=" ID_THREADMGR_SRFHANDLER_NAME
- );
- }
-private:
- CThreadPoolMgrObject m_PoolMgr;
- long m_nColor;
- CString m_strUrl;
-
-};
-
-
-#endif // _ATL_THREADPOOL_NOUI
-#endif // _ATL_THREADPOOL_MANAGEMENT
-
-#ifdef _ATL_STENCILCACHE_MANAGEMENT
-//////////////////////////////////////////////////////////////////////
-// Stencil cache management
-class CStencilCacheMgrObject
-{
-public:
- CStencilCacheMgrObject()
- {
-
- }
-
- HRESULT GetCurrentEntryCount(__int64 *pdwSize)
- {
- ATLASSUME(m_spMemCacheStats);
- if (!pdwSize)
- return E_INVALIDARG;
-
- DWORD dwValue;
- HRESULT hr = m_spMemCacheStats->GetCurrentEntryCount(&dwValue);
- if (hr == S_OK)
- {
- *pdwSize = dwValue;
- }
- return hr;
- }
-
- HRESULT ClearStats()
- {
- ATLENSURE(m_spMemCacheStats);
- return m_spMemCacheStats->ClearStats();
- }
-
- HRESULT GetHitCount(__int64 *pdwSize)
- {
- ATLENSURE(m_spMemCacheStats);
- if (!pdwSize)
- return E_INVALIDARG;
-
- DWORD dwValue;
- HRESULT hr = m_spMemCacheStats->GetHitCount(&dwValue);
- if (hr == S_OK)
- {
- *pdwSize = dwValue;
- }
- return hr;
- }
-
- HRESULT GetMissCount(__int64 *pdwSize)
- {
- ATLENSURE(m_spMemCacheStats);
- if (!pdwSize)
- return E_INVALIDARG;
-
- DWORD dwValue;
-
- HRESULT hr = m_spMemCacheStats->GetMissCount(&dwValue);
- if (hr == S_OK)
- {
- *pdwSize = dwValue;
- }
- return hr;
- }
-
- HRESULT GetCurrentAllocSize(__int64 *pdwSize)
- {
- ATLENSURE(m_spMemCacheStats);
- if (!pdwSize)
- return E_INVALIDARG;
-
- DWORD dwValue;
-
- HRESULT hr = m_spMemCacheStats->GetCurrentAllocSize(&dwValue);
- if (hr == S_OK)
- {
- *pdwSize = dwValue;
- }
- return hr;
- }
-
- HRESULT GetMaxAllocSize(__int64 *pdwSize)
- {
- ATLENSURE(m_spMemCacheStats);
- if (!pdwSize)
- return E_INVALIDARG;
-
- DWORD dwValue;
-
- HRESULT hr = m_spMemCacheStats->GetMaxAllocSize(&dwValue);
- if (hr == S_OK)
- {
- *pdwSize = dwValue;
- }
- return hr;
- }
-
-
- HRESULT GetMaxEntryCount(__int64 *pdwSize)
- {
- ATLENSURE(m_spMemCacheStats);
- if (!pdwSize)
- return E_INVALIDARG;
-
- DWORD dwValue;
-
- HRESULT hr = m_spMemCacheStats->GetMaxEntryCount(&dwValue);
- if (hr == S_OK)
- {
- *pdwSize = dwValue;
- }
- return hr;
- }
-
-
- HRESULT RemoveStencil(__int64 hStencil)
- {
- ATLENSURE(m_spStencilCacheControl);
- return m_spStencilCacheControl->RemoveStencil((const HCACHEITEM)hStencil);
- }
-
- HRESULT RemoveStencilByName(BSTR szStencil) throw()
- {
- ATLENSURE_RETURN(m_spStencilCacheControl);
- return m_spStencilCacheControl->RemoveStencilByName(CW2A(szStencil));
- }
-
-
- HRESULT RemoveAllStencils()
- {
- ATLENSURE(m_spStencilCacheControl);
- return m_spStencilCacheControl->RemoveAllStencils();
- }
-
- // we show lifespan in milliseconds in the UI so we have to
- // do the conversion to 100ns intervals here.
- HRESULT SetDefaultLifespan(unsigned __int64 dwdwLifespan)
- {
- ATLENSURE(m_spStencilCacheControl);
- // convert to 100ns intervals
- return m_spStencilCacheControl->SetDefaultLifespan(dwdwLifespan * CFileTime::Millisecond);
- }
-
- HRESULT GetDefaultLifespan(unsigned __int64 *pdwdwLifespan)
- {
- ATLENSURE(m_spStencilCacheControl);
- ATLENSURE(pdwdwLifespan!=NULL);
- *pdwdwLifespan = 0;
- unsigned __int64 dwls = 0;
- HRESULT hr = m_spStencilCacheControl->GetDefaultLifespan(&dwls);
-
- // convert to milliseconds
- if (SUCCEEDED(hr))
- {
- dwls /= CFileTime::Millisecond;
- *pdwdwLifespan = dwls;
- }
-
- return hr;
- }
-
- HTTP_CODE Initialize(IServiceProvider *pProvider) throw()
- {
-
- ATLASSERT(pProvider); // should never be NULL
- if (!pProvider)
- return HTTP_ERROR(500, ISE_SUBERR_UNEXPECTED);
-
-
- if (m_spMemCacheStats && m_spStencilCacheControl)
- return HTTP_SUCCESS; // already initialized
-
- CComPtr<IStencilCache> spStencilCache;
- pProvider->QueryService(__uuidof(IStencilCache), &spStencilCache);
- if (spStencilCache)
- {
- if (!m_spMemCacheStats)
- {
- spStencilCache->QueryInterface(__uuidof(IMemoryCacheStats),
- (void**)&m_spMemCacheStats);
- }
- if (!m_spStencilCacheControl)
- {
- spStencilCache->QueryInterface(__uuidof(IStencilCacheControl),
- (void**)&m_spStencilCacheControl);
- }
- }
-
- return (m_spMemCacheStats && m_spStencilCacheControl)
- ? HTTP_SUCCESS : HTTP_ERROR(500, ISE_SUBERR_UNEXPECTED);
- }
-
-private:
- CComPtr<IMemoryCacheStats> m_spMemCacheStats;
- CComPtr<IStencilCacheControl> m_spStencilCacheControl;
-};
-
-
-#ifndef _ATL_STENCILCACHE_NOWEBSERVICE
-
-[ uuid("3813895C-4C4C-41df-95F4-12220140B164"), object ]
-__interface IStencilCacheMgr
-{
- // data access
- [id(0)] STDMETHOD(GetCurrentEntryCount)([out,retval] __int64 *pdwSize);
- [id(1)] STDMETHOD(GetHitCount)([out,retval] __int64 *pdwSize);
- [id(2)] STDMETHOD(GetMissCount)([out,retval] __int64 *pdwSize);
- [id(3)] STDMETHOD(GetCurrentAllocSize)([out,retval] __int64 *pdwSize);
- [id(4)] STDMETHOD(GetMaxAllocSize)([out,retval] __int64 *pdwSize);
- [id(5)] STDMETHOD(GetMaxEntryCount)([out,retval] __int64 *pdwSize);
- [id(6)] STDMETHOD(GetDefaultLifespan)([out,retval] unsigned __int64 *pdwdwLifespan);
-
- // commands
- [id(7)] STDMETHOD(ClearStats)();
- [id(8)] STDMETHOD(RemoveStencil)([in] __int64 hStencil);
- [id(9)] STDMETHOD(RemoveStencilByName)([in] BSTR szStencil);
- [id(10)] STDMETHOD(RemoveAllStencils)();
- [id(11)] STDMETHOD(SetDefaultLifespan)([in] unsigned __int64 dwdwLifespan);
-};
-
-#pragma warning(push)
-#pragma warning(disable:4199)
-[
- soap_handler( name= ID_STENCILCACHEMGR_WEBSERVICE_NAME,
- namespace= ID_STENCILCACHEMGR_WEBSERVICE_URL,
- protocol= "soap"
- ),
- request_handler(
- name= ID_STENCILCACHEMGR_WEBSERVICE_NAME,
- sdl= ID_STENCILCACHEMGR_WEBSERVICE_WSDL )
-]
-class CStencilCacheManager :
- public IStencilCacheMgr
-{
-#pragma warning(pop)
-public:
- [ soap_method ]
- STDMETHOD(GetCurrentEntryCount)(__int64 *pdwSize)
- {
- return m_MgrObj.GetCurrentEntryCount(pdwSize);
- }
-
- [ soap_method ]
- STDMETHOD(ClearStats)()
- {
- return m_MgrObj.ClearStats();
- }
-
- [ soap_method ]
- STDMETHOD(GetHitCount)(__int64 *pdwSize)
- {
- return m_MgrObj.GetHitCount(pdwSize);
- }
-
- [ soap_method ]
- STDMETHOD(GetMissCount)(__int64 *pdwSize)
- {
- return m_MgrObj.GetMissCount(pdwSize);
- }
-
- [ soap_method ]
- STDMETHOD(GetCurrentAllocSize)(__int64 *pdwSize)
- {
- return m_MgrObj.GetCurrentAllocSize(pdwSize);
- }
-
- [ soap_method ]
- STDMETHOD(GetMaxAllocSize)(__int64 *pdwSize)
- {
- return m_MgrObj.GetMaxAllocSize(pdwSize);
- }
-
- [ soap_method ]
- STDMETHOD(GetMaxEntryCount)(__int64 *pdwSize)
- {
- return m_MgrObj.GetMaxEntryCount(pdwSize);
- }
-
- [ soap_method ]
- STDMETHOD(RemoveStencil)(__int64 hStencil)
- {
- return m_MgrObj.RemoveStencil(hStencil);
- }
-
- [ soap_method ]
- STDMETHOD(RemoveStencilByName)(BSTR bstrStencil)
- {
- return m_MgrObj.RemoveStencilByName(bstrStencil);
- }
-
- [ soap_method ]
- STDMETHOD(RemoveAllStencils)()
- {
- return m_MgrObj.RemoveAllStencils();
- }
-
- // we show lifespan in milliseconds in the UI.
- // m_MgrObj handles the conversion to 100ns intervals.
- [ soap_method ]
- STDMETHOD(SetDefaultLifespan)(unsigned __int64 dwdwLifespan)
- {
- return m_MgrObj.SetDefaultLifespan(dwdwLifespan);
- }
-
- [ soap_method ]
- STDMETHOD(GetDefaultLifespan)(unsigned __int64 *pdwdwLifespan)
- {
- return m_MgrObj.GetDefaultLifespan(pdwdwLifespan);
- }
-
- HTTP_CODE HandleRequest(AtlServerRequest *pRequestInfo, IServiceProvider *pProvider)
- {
- HTTP_CODE hcErr = m_MgrObj.Initialize(pProvider);
- if (hcErr != HTTP_SUCCESS)
- return hcErr;
-
-__if_exists(_Authority)
-{
- // Make sure caller is authorized on this system
- hcErr = HTTP_FAIL;
- ATLTRY(hcErr = _Authority.IsAuthorized(pRequestInfo, ATL_DEFAULT_AUTHGRP))
-}
- if (hcErr == HTTP_SUCCESS)
- {
- hcErr = __super::HandleRequest(pRequestInfo, pProvider);
- }
- return hcErr;
- }
-private:
- CStencilCacheMgrObject m_MgrObj;
-};
-#endif //_ATL_STENCILCACHE_NOWEBSERVICE
-#ifndef _ATL_STENCILCACHE_NOUI
-typedef HRESULT (CStencilCacheMgrObject::*PFNGETDATA)(__int64 *pdwSize);
-
-struct CCache_data
-{
- PFNGETDATA m_pfn;
- char m_sz[128];
-};
-
-#define INVALID_DATA_PTR ((DWORD_PTR) -1)
-#define INVALID_COMMAND_ID -1
-#define MAX_COMMAND_ID 64
-#define ATL_STENCILCACHECMD_CLEARALLSTATS 0
-#define ATL_STENCILCACHECMD_REMOVESTENCIL 1
-#define ATL_STENCILCACHECMD_REMOVEALLSTENCILS 2
-#define ATL_STENCILCACHECMD_SETDEFLIFESPAN 3
-
-[request_handler(name=ID_STENCILCACHEMGR_SRFHANDLER_NAME)]
-class CStencilMgr
-{
-public:
- CStencilMgr()
- {
- m_pData = (CCache_data*)INVALID_DATA_PTR;
- m_nColor = ATL_COLOR_TR1;
- }
-
- HTTP_CODE ValidateAndExchange() throw()
- {
- _ATLTRY
- {
- HTTP_CODE hcErr = m_MgrObj.Initialize(m_spServiceProvider);
- if (hcErr != HTTP_SUCCESS)
- return hcErr;
-
-__if_exists(_Authority)
-{
- // Make sure caller is authorized on this system
- hcErr = HTTP_FAIL;
- ATLTRY(hcErr = _Authority.IsAuthorized(m_pRequestInfo, ATL_DEFAULT_AUTHGRP))
- if (hcErr != HTTP_SUCCESS)
- return hcErr;
-}
- m_HttpResponse.SetContentType("text/html");
-
- // check to see if we have a "Handler" form variable
- CString strHandler, strOptParam;
- int nCmdToExec;
-
- if (m_HttpRequest.GetMethod() == CHttpRequest::HTTP_METHOD_POST)
- {
- DWORD dwErr = m_HttpRequest.FormVars.Exchange("Method", &strHandler);
- if (dwErr == VALIDATION_S_OK)
- {
- if (strHandler == _T("ExecuteCommand"))
- {
- // get the value of the command parameter so we can execute it
- dwErr = m_HttpRequest.FormVars.Validate("command", &nCmdToExec, 0, MAX_COMMAND_ID);
- if (dwErr == VALIDATION_S_OK)
- {
- // get the optional parameter if it's there.
- m_HttpRequest.FormVars.Validate("DynValue", &strOptParam, 0, MAX_COMMAND_ID);
- hcErr = ExecCommand(nCmdToExec, strOptParam);
- return hcErr;
- }
- }
- }
- }
- hcErr = LoadStencilResource(m_hInstHandler, IDR_STENCILMGR_SRF);
- return hcErr;
- }
- _ATLCATCHALL()
- {
- return HTTP_FAIL;
- }
- }
-
- HTTP_CODE ExecCommand(int nCmdToExec, CString& strOptParam)
- {
- switch (nCmdToExec)
- {
- case ATL_STENCILCACHECMD_CLEARALLSTATS:
- m_MgrObj.ClearStats();
- break;
-
- case ATL_STENCILCACHECMD_REMOVESTENCIL:
- m_MgrObj.RemoveStencilByName(strOptParam.AllocSysString());
- break;
-
- case ATL_STENCILCACHECMD_REMOVEALLSTENCILS:
- m_MgrObj.RemoveAllStencils();
- break;
-
- case ATL_STENCILCACHECMD_SETDEFLIFESPAN:
- TCHAR *pStop = NULL;
- m_MgrObj.SetDefaultLifespan(_tcstoul(strOptParam, &pStop, 10));
- break;
- };
-
- return _AtlRedirectToPage(
- m_spServerContext,
- m_HttpRequest,
- m_HttpResponse,
- "?Handler=" ID_STENCILCACHEMGR_SRFHANDLER_NAME
- );
-
- }
-
- [tag_name("GetNextStencilCacheStats")]
- HTTP_CODE GetNextStencilCacheStats()
- {
- if (m_pData == (CCache_data*)INVALID_DATA_PTR)
- {
- m_pData = GetCacheData();
- return HTTP_SUCCESS;
- }
- m_pData++;
-
- if (m_pData->m_pfn != NULL)
- return HTTP_SUCCESS;
-
- m_pData = (CCache_data*)INVALID_DATA_PTR;
- return HTTP_S_FALSE;
-
- }
-
- [tag_name("GetCacheValue")]
- HTTP_CODE GetCacheValue()
- {
- ATLENSURE(m_pData);
- ATLENSURE(m_pData != (CCache_data*)INVALID_DATA_PTR);
- m_HttpResponse << m_pData->m_sz;
- return HTTP_SUCCESS;
- }
-
- [tag_name("GetCacheQuantity")]
- HTTP_CODE GetCacheQuantity()
- {
- ATLENSURE(m_pData);
- ATLENSURE(m_pData != (CCache_data*)INVALID_DATA_PTR);
- __int64 dwValue = 0;
- PFNGETDATA pfn = m_pData->m_pfn;
- ATLENSURE(pfn);
- CStencilCacheMgrObject *pMgr = &m_MgrObj;
- (pMgr->*pfn)(&dwValue);
-
- m_HttpResponse << dwValue;
- return HTTP_SUCCESS;
- }
-
- [tag_name("GetTRColor")]
- HTTP_CODE GetTRColor()
- {
- m_nColor = (m_nColor == ATL_COLOR_TR1) ? ATL_COLOR_TR2 : ATL_COLOR_TR1;
- TCHAR cr[8];
- if (RGBToHtml(m_nColor, cr, sizeof(cr)))
- m_HttpResponse << cr;
-
- return HTTP_SUCCESS;
- }
-
- [tag_name("GetBodyColor")]
- HTTP_CODE GetBodyColor()
- {
- TCHAR cr[8];
- if (RGBToHtml(ATL_COLOR_BODYBG, cr, sizeof(cr)))
- m_HttpResponse << cr;
- return HTTP_SUCCESS;
- }
-private:
- static CCache_data* GetCacheData()
- {
- static CCache_data cache_data[] =
- {
- {(PFNGETDATA)&CStencilCacheMgrObject::GetCurrentEntryCount, "Current Cache Entry Count(stencils)"},
- {(PFNGETDATA)&CStencilCacheMgrObject::GetHitCount, "Cache Hit Count(stencils)"},
- {(PFNGETDATA)&CStencilCacheMgrObject::GetMissCount, "Cache Miss Count(stencils)"},
- {(PFNGETDATA)&CStencilCacheMgrObject::GetCurrentAllocSize, "Cache memory allocation(bytes)"},
- {(PFNGETDATA)&CStencilCacheMgrObject::GetMaxAllocSize, "Cache maximum allocation size(bytes)"},
- {(PFNGETDATA)&CStencilCacheMgrObject::GetMaxEntryCount, "Cache maximum entry count(stencils)"},
- {(PFNGETDATA)&CStencilCacheMgrObject::GetDefaultLifespan, "Default stencil lifespan(ms)"},
- {NULL, NULL}
- };
- return cache_data;
- }
-
- CStencilCacheMgrObject m_MgrObj;
- CCache_data *m_pData;
- long m_nColor;
-};
-//__declspec(selectany) CComObjectGlobal<CStencilCacheManager> CStencilMgr::m_cachemgr;
-#endif // _ATL_STENCILCACHE_NOUI
-#endif // _ATL_STENCILCACHE_MANAGEMENT
-
-//////////////////////////////////////////////////////////////////////
-// DLL cache management
-#ifdef _ATL_DLLCACHE_MANAGEMENT
-
-
-#ifndef _ATL_DLLCACHE_NOWEBSERVICE
-[export]
-#endif
-struct _DLL_CACHE_ENTRY
-{
- DWORD hInstDll;
- DWORD dwRefs;
- BSTR szDllName;
-};
-
-
-class CDllMgrObject
-{
-public:
- HRESULT GetEntries(DWORD dwCount, _DLL_CACHE_ENTRY *pEntries, DWORD *pdwCopied)
- {
- ATLASSUME(m_spDllCache);
- HRESULT hr = E_FAIL;
- DLL_CACHE_ENTRY *pe = NULL;
-
- if (!m_spDllCache)
- return E_UNEXPECTED;
-
- if (dwCount != 0 && pEntries == NULL)
- return E_UNEXPECTED; // asking for entries but no place to put them
-
- if (!pdwCopied)
- return E_POINTER;
- *pdwCopied = 0;
-
- if (dwCount)
- {
- pe = new DLL_CACHE_ENTRY[dwCount];
- if (!pe)
- return E_OUTOFMEMORY;
- }
-
- hr = m_spDllCache->GetEntries(dwCount, pe, pdwCopied);
- if (hr == S_OK && dwCount != 0 && pEntries != NULL)
- {
- // SysAllocString our path strings
- for (DWORD i = 0; i<*pdwCopied; i++)
- {
- pEntries[i].hInstDll = (DWORD)(DWORD_PTR)pe[i].hInstDll;
- pEntries[i].dwRefs = pe[i].dwRefs;
- pEntries[i].szDllName = ::SysAllocString(CA2W(pe[i].szDllName));
- }
- }
-
- delete [] pe;
- return hr;
- }
-
-
- HRESULT GetEntryCount(DWORD *pdwCount)
- {
- ATLASSUME(m_spDllCache);
- if (!m_spDllCache)
- return E_UNEXPECTED;
-
- return m_spDllCache->GetEntries(0, NULL, pdwCount);
- }
-
- HTTP_CODE Initialize(IServiceProvider *pProvider)
- {
- ATLASSERT(pProvider); // should never be NULL
- if (!pProvider)
- return HTTP_ERROR(500, ISE_SUBERR_UNEXPECTED);
-
- if (m_spDllCache)
- return HTTP_SUCCESS; // already initialized
-
- pProvider->QueryService(__uuidof(IDllCache), &m_spDllCache);
- return m_spDllCache ? HTTP_SUCCESS : HTTP_ERROR(500, ISE_SUBERR_UNEXPECTED);
- }
-
-private:
- CComPtr<IDllCache> m_spDllCache;
-
-}; // CDllMgrObject
-
-
-#ifndef _ATL_DLLCACHE_NOWEBSERVICE
-// _DLL_CACHE_ENTRY is our own version of DLL_CACHE_ENTRY(atlcache.h) that
-// uses a BSTR instead of a fixed length string for the szDllName for compatiblility
-// with our SOAP implementation.
-[ uuid("A0C00AF8-CEA5-46b9-97ED-FDEE55B583EF"), object ]
-__interface IDllCacheMgr
-{
- [id(0)] STDMETHOD(GetEntries)([in] DWORD dwCount, [out] _DLL_CACHE_ENTRY *pEntries, [out, retval] DWORD *pdwCopied);
- [id(1)] STDMETHOD(GetEntryCount)([out, retval] DWORD *pdwCount);
-
-};
-
-
-#pragma warning(push)
-#pragma warning(disable:4199)
-[
- soap_handler(
- name= ID_DLLCACHEMGR_WEBSERVICE_NAME,
- namespace= ID_DLLCACHEMGR_WEBSERVICE_URL,
- protocol= "soap"
- ),
- request_handler(
- name= ID_DLLCACHEMGR_WEBSERVICE_NAME,
- sdl= ID_DLLCACHEMGR_WEBSERVICE_WSDL
- )
-]
-class CDllCacheManager :
- public IDllCacheMgr
-{
-#pragma warning(pop)
-public:
- [soap_method]
- HRESULT GetEntries(DWORD dwCount, _DLL_CACHE_ENTRY *pEntries, DWORD *pdwCopied)
- {
- return m_MgrObj.GetEntries(dwCount, pEntries, pdwCopied);
- }
-
- [soap_method]
- STDMETHOD(GetEntryCount)(DWORD *pdwCount)
- {
- return m_MgrObj.GetEntries(0, NULL, pdwCount);
- }
-
- HTTP_CODE HandleRequest(AtlServerRequest *pRequestInfo, IServiceProvider *pProvider)
- {
- HTTP_CODE hcErr = m_MgrObj.Initialize(pProvider);
- if (hcErr != HTTP_SUCCESS)
- return hcErr;
-
-__if_exists(_Authority)
-{
- // Make sure caller is authorized on this system
- hcErr = HTTP_FAIL;
- ATLTRY(hcErr = _Authority.IsAuthorized(pRequestInfo, ATL_DEFAULT_AUTHGRP))
-}
- if (hcErr == HTTP_SUCCESS)
- {
- hcErr = __super::HandleRequest(pRequestInfo, pProvider);
- }
- return hcErr;
- }
-
-protected:
- CDllMgrObject m_MgrObj;
-};
-#endif _ATL_DLLCACHE_NOWEBSERVICE
-
-#ifndef _ATL_DLLCACHE_NOUI
-#define INVALID_INDEX -1
-
-[
- request_handler(name=ID_DLLCACHEMGR_SRFHANDLER_NAME)
-]
-class CDllCacheMgr
-{
-public:
- CDllCacheMgr() : m_nColor(ATL_COLOR_TR1),
- m_nEnumCount(INVALID_INDEX),
- m_nEnumIndex(INVALID_INDEX),
- m_pEntries(NULL)
- {
-
- }
-
- [tag_name("GetTRColor")]
- HTTP_CODE GetTRColor()
- {
- m_nColor = (m_nColor == ATL_COLOR_TR1) ? ATL_COLOR_TR2 : ATL_COLOR_TR1;
- TCHAR cr[8];
- if (RGBToHtml(m_nColor, cr, sizeof(cr)))
- m_HttpResponse << cr;
-
- return HTTP_SUCCESS;
- }
-
- [tag_name("GetBodyColor")]
- HTTP_CODE GetBodyColor()
- {
- TCHAR cr[8];
- if (RGBToHtml(ATL_COLOR_BODYBG, cr, sizeof(cr)))
- m_HttpResponse << cr;
- return HTTP_SUCCESS;
- }
-
-
- [tag_name("GetNumEntries")]
- HTTP_CODE GetNumEntries()
- {
- DWORD dwEntries = 0;
- m_MgrObj.GetEntryCount(&dwEntries);
- m_HttpResponse << dwEntries;
- return HTTP_SUCCESS;
- }
-
-
- [tag_name("EnumEntries")]
- HTTP_CODE EnumEntries()
- {
- // we lock the cache while we enum entries so no entries
- // will be removed during the enumeration request.
- if (m_nEnumIndex == INVALID_INDEX)
- {
- // set up for the iteration
- m_MgrObj.GetEntryCount((DWORD*)&m_nEnumCount);
- if (!m_nEnumCount)
- return HTTP_S_FALSE; // nothing to enum
-
- m_pEntries = new _DLL_CACHE_ENTRY[m_nEnumCount];
- if (!m_pEntries)
- return HTTP_ERROR(500, ISE_SUBERR_OUTOFMEM);
-
- DWORD dwFetched = INVALID_INDEX;
-
- if (S_OK != m_MgrObj.GetEntries(m_nEnumCount, m_pEntries, &dwFetched))
- return HTTP_ERROR(500, ISE_SUBERR_UNEXPECTED);
-
- m_nEnumIndex = 0;
- return HTTP_SUCCESS;
- }
-
- m_nEnumIndex++;
- if (m_nEnumIndex < m_nEnumCount)
- return HTTP_SUCCESS; // continue iterating
-
- else
- {
- // done, clean up
- for (int i = 0; i< m_nEnumCount; i++)
- {
- ::SysFreeString(m_pEntries[i].szDllName);
- }
- delete [] m_pEntries;
- m_pEntries = NULL;
- m_nEnumCount = INVALID_INDEX;
- m_nEnumIndex = INVALID_INDEX;
- return HTTP_S_FALSE; // terminate iterations.
- }
- }
-
- [tag_name("GetDllName")]
- HTTP_CODE GetDllName()
- {
- m_HttpResponse << m_pEntries[m_nEnumIndex].szDllName;
- return HTTP_SUCCESS;
- }
-
- [tag_name("GetDllReferences")]
- HTTP_CODE GetDllReferences()
- {
- m_HttpResponse << m_pEntries[m_nEnumIndex].dwRefs;
- return HTTP_SUCCESS;
- }
-
- HTTP_CODE ValidateAndExchange()
- {
-
- HTTP_CODE hcErr = m_MgrObj.Initialize(m_spServiceProvider);
- if (hcErr != HTTP_SUCCESS)
- return hcErr;
-
-__if_exists(_Authority)
-{
- // Make sure caller is authorized on this system
- hcErr = HTTP_FAIL;
- ATLTRY(hcErr = _Authority.IsAuthorized(m_pRequestInfo, ATL_DEFAULT_AUTHGRP))
- if (hcErr != HTTP_SUCCESS)
- return hcErr;
-}
- hcErr = LoadStencilResource(m_hInstHandler, IDR_DLLMGR_SRF);
- m_HttpResponse.SetContentType("text/html");
- return hcErr;
-
- }
-
- CDllMgrObject m_MgrObj;
- long m_nColor;
- int m_nEnumCount;
- int m_nEnumIndex;
- _DLL_CACHE_ENTRY *m_pEntries;
-
-};
-
-#endif // _ATL_DLLCACHE_NOUI
-#endif // _ATL_DLLCACHE_MANAGEMENT
-
-}; // ATL
-
-#pragma pack(pop)
-#pragma warning(pop)
-#endif // __ATLEXTMGMT_H__
diff --git a/include/atl/atlhtml.h b/include/atl/atlhtml.h
deleted file mode 100644
index 4922e580d..000000000
--- a/include/atl/atlhtml.h
+++ /dev/null
@@ -1,1682 +0,0 @@
-// This is a part of the Active Template Library.
-// Copyright (C) Microsoft Corporation
-// All rights reserved.
-//
-// This source code is only intended as a supplement to the
-// Active Template Library Reference and related
-// electronic documentation provided with the library.
-// See these sources for detailed information regarding the
-// Active Template Library product.
-
-#ifndef __ATLHTML_H__
-#define __ATLHTML_H__
-
-#pragma once
-
-#include <atlstr.h>
-#include <atlsiface.h>
-#include <atlconv.h>
-
-
-
-#pragma pack(push,_ATL_PACKING)
-namespace ATL {
-
-#define TAGF_NONE 0
-#define TAGF_HASEND 1
-#define TAGF_BLOCK 2
-
-
-struct ATL_HTML_TAG
-{
- LPCTSTR szTagName;
- UINT uFlags;
-};
-
-enum ATL_HTML_TAGS {
- ATL_HTML_TAG_BODY,
- ATL_HTML_TAG_A,
- ATL_HTML_TAG_B,
- ATL_HTML_TAG_I,
- ATL_HTML_TAG_U,
- ATL_HTML_TAG_FONT,
- ATL_HTML_TAG_IMG,
- ATL_HTML_TAG_HR,
- ATL_HTML_TAG_BR,
- ATL_HTML_TAG_DIV,
- ATL_HTML_TAG_BLOCKQUOTE,
- ATL_HTML_TAG_ADDRESS,
- ATL_HTML_TAG_P,
- ATL_HTML_TAG_H1,
- ATL_HTML_TAG_H2,
- ATL_HTML_TAG_H3,
- ATL_HTML_TAG_H4,
- ATL_HTML_TAG_H5,
- ATL_HTML_TAG_H6,
- ATL_HTML_TAG_PRE,
- ATL_HTML_TAG_Q,
- ATL_HTML_TAG_SUB,
- ATL_HTML_TAG_SUP,
- ATL_HTML_TAG_INS,
- ATL_HTML_TAG_DEL,
- ATL_HTML_TAG_EM,
- ATL_HTML_TAG_STRONG,
- ATL_HTML_TAG_DFN,
- ATL_HTML_TAG_CODE,
- ATL_HTML_TAG_SAMP,
- ATL_HTML_TAG_KBD,
- ATL_HTML_TAG_VAR,
- ATL_HTML_TAG_CITE,
- ATL_HTML_TAG_ABBR,
- ATL_HTML_TAG_ACRONYM,
- ATL_HTML_TAG_OL,
- ATL_HTML_TAG_UL,
- ATL_HTML_TAG_LI,
- ATL_HTML_TAG_DL,
- ATL_HTML_TAG_DT,
- ATL_HTML_TAG_DD,
- ATL_HTML_TAG_TABLE,
- ATL_HTML_TAG_TR,
- ATL_HTML_TAG_TD,
- ATL_HTML_TAG_FORM,
- ATL_HTML_TAG_INPUT,
- ATL_HTML_TAG_SELECT,
- ATL_HTML_TAG_OPTION,
- ATL_HTML_TAG_HEAD,
- ATL_HTML_TAG_HTML,
- ATL_HTML_TAG_MAP,
- ATL_HTML_TAG_AREA,
- ATL_HTML_TAG_BASE,
- ATL_HTML_TAG_BDO,
- ATL_HTML_TAG_BIG,
- ATL_HTML_TAG_BUTTON,
- ATL_HTML_TAG_IFRAME,
- ATL_HTML_TAG_LABEL,
- ATL_HTML_TAG_LINK,
- ATL_HTML_TAG_META,
- ATL_HTML_TAG_NOFRAMES,
- ATL_HTML_TAG_NOSCRIPT,
- ATL_HTML_TAG_COL,
- ATL_HTML_TAG_COLGROUP,
- ATL_HTML_TAG_FIELDSET,
- ATL_HTML_TAG_LEGEND,
- ATL_HTML_TAG_TBODY,
- ATL_HTML_TAG_TEXTAREA,
- ATL_HTML_TAG_TFOOT,
- ATL_HTML_TAG_TH,
- ATL_HTML_TAG_TITLE,
- ATL_HTML_TAG_TT,
- ATL_HTML_TAG_SMALL,
- ATL_HTML_TAG_SPAN,
- ATL_HTML_TAG_OBJECT,
- ATL_HTML_TAG_PARAM,
- ATL_HTML_TAG_LAST };
-
-extern __declspec(selectany) const ATL_HTML_TAG s_tags[] =
-{
- { _T("body"), TAGF_HASEND | TAGF_BLOCK },
- { _T("a"), TAGF_HASEND },
- { _T("b"), TAGF_HASEND },
- { _T("i"), TAGF_HASEND },
- { _T("u"), TAGF_HASEND },
- { _T("font"), TAGF_HASEND },
- { _T("img"), TAGF_NONE },
- { _T("hr"), TAGF_NONE },
- { _T("br"), TAGF_NONE },
- { _T("div"), TAGF_HASEND | TAGF_BLOCK },
- { _T("blockquote"), TAGF_HASEND | TAGF_BLOCK },
- { _T("adress"), TAGF_HASEND },
- { _T("p"), TAGF_HASEND | TAGF_BLOCK },
- { _T("h1"), TAGF_HASEND | TAGF_BLOCK},
- { _T("h2"), TAGF_HASEND | TAGF_BLOCK},
- { _T("h3"), TAGF_HASEND | TAGF_BLOCK },
- { _T("h4"), TAGF_HASEND | TAGF_BLOCK },
- { _T("h5"), TAGF_HASEND | TAGF_BLOCK },
- { _T("h6"), TAGF_HASEND | TAGF_BLOCK },
- { _T("pre"), TAGF_HASEND | TAGF_BLOCK },
- { _T("q"), TAGF_HASEND },
- { _T("sub"), TAGF_HASEND },
- { _T("sup"), TAGF_HASEND },
- { _T("ins"), TAGF_HASEND },
- { _T("del"), TAGF_HASEND },
- { _T("em"), TAGF_HASEND },
- { _T("strong"), TAGF_HASEND },
- { _T("dfn"), TAGF_HASEND },
- { _T("code"), TAGF_HASEND },
- { _T("samp"), TAGF_HASEND },
- { _T("kbd"), TAGF_HASEND },
- { _T("var"), TAGF_HASEND },
- { _T("cite"), TAGF_HASEND },
- { _T("abbr"), TAGF_HASEND },
- { _T("acronym"), TAGF_HASEND },
- { _T("ol"), TAGF_HASEND | TAGF_BLOCK },
- { _T("ul"), TAGF_HASEND | TAGF_BLOCK },
- { _T("li"), TAGF_HASEND },
- { _T("dl"), TAGF_HASEND | TAGF_BLOCK },
- { _T("dt"), TAGF_HASEND },
- { _T("dd"), TAGF_HASEND },
- { _T("table"), TAGF_HASEND },
- { _T("tr"), TAGF_HASEND },
- { _T("td"), TAGF_HASEND },
- { _T("form"), TAGF_HASEND },
- { _T("input"), TAGF_HASEND },
- { _T("select"), TAGF_HASEND },
- { _T("option"), TAGF_HASEND },
- { _T("head"), TAGF_HASEND | TAGF_BLOCK },
- { _T("html"), TAGF_HASEND | TAGF_BLOCK },
- { _T("map"), TAGF_HASEND | TAGF_BLOCK },
- { _T("area"), TAGF_BLOCK },
- { _T("base"), TAGF_BLOCK },
- { _T("bdo"), TAGF_HASEND },
- { _T("big"), TAGF_HASEND },
- { _T("button"), TAGF_HASEND },
- { _T("iframe"), TAGF_HASEND },
- { _T("label"), TAGF_HASEND },
- { _T("link"), TAGF_NONE },
- { _T("meta"), TAGF_BLOCK },
- { _T("noframes"), TAGF_BLOCK },
- { _T("noscript"), TAGF_BLOCK },
- { _T("col"), TAGF_BLOCK },
- { _T("colgroup"), TAGF_HASEND | TAGF_BLOCK },
- { _T("fieldset"), TAGF_HASEND | TAGF_BLOCK },
- { _T("legend"), TAGF_HASEND | TAGF_BLOCK },
- { _T("tbody"), TAGF_HASEND | TAGF_BLOCK },
- { _T("textarea"), TAGF_HASEND | TAGF_BLOCK },
- { _T("tfoot"), TAGF_HASEND | TAGF_BLOCK },
- { _T("th"), TAGF_HASEND | TAGF_BLOCK },
- { _T("title"), TAGF_HASEND | TAGF_BLOCK },
- { _T("tt"), TAGF_HASEND },
- { _T("small"), TAGF_HASEND },
- { _T("span"), TAGF_HASEND },
- { _T("object"), TAGF_HASEND | TAGF_BLOCK },
- { _T("param"), TAGF_NONE },
-};
-
-class AtlHtmlAttrs
-{
-public:
- CString m_strAttrs;
-
- AtlHtmlAttrs()
- {
-
- }
-
-#pragma warning(push)
-#pragma warning(disable : 4793)
- AtlHtmlAttrs(int nCount, ...)
- {
- va_list args;
-
- va_start(args, nCount);
- for (int i=0; i<nCount; i++)
- {
- LPCTSTR szName = va_arg(args, LPCTSTR);
- LPCTSTR szVal = va_arg(args, LPCTSTR);
- Add(szName, szVal);
- }
- va_end(args);
- }
-#pragma warning(pop)
-
-#pragma warning(push)
-#pragma warning(disable : 4793)
- AtlHtmlAttrs(LPCTSTR szFormat, ...)
- {
- if (!szFormat || !*szFormat)
- return;
-
- va_list args;
-
- va_start(args, szFormat);
-
- CString strTmp;
- strTmp.FormatV(szFormat, args);
- va_end(args);
-
- m_strAttrs += _T(" ");
- m_strAttrs += strTmp;
- }
-#pragma warning(pop)
-
- BOOL Add(LPCTSTR szName, LPCTSTR szValue)
- {
- if (szValue)
- m_strAttrs.AppendFormat(_T(" %s=\"%s\""), szName, szValue);
- else
- m_strAttrs.AppendFormat(_T(" %s"), szName);
- return TRUE;
- }
-
-#pragma warning(push)
-#pragma warning(disable : 4793)
- void AddFormat(LPCTSTR szFormat, ...)
- {
- va_list args;
-
- va_start(args, szFormat);
-
- CString strTmp;
- strTmp.FormatV(szFormat, args);
- va_end(args);
-
- m_strAttrs += _T(" ");
- m_strAttrs += strTmp;
- }
-#pragma warning(pop)
-
- void Set(LPCTSTR szAttrs)
- {
- if (szAttrs)
- {
- m_strAttrs.Empty();
-#ifndef UNICODE
- if (!isspace(static_cast<unsigned char>(szAttrs[0])))
-#else
- if (!iswspace(szAttrs[0]))
-#endif
- m_strAttrs = _T(" ");
- m_strAttrs += szAttrs;
- }
- }
-
- operator LPCTSTR()
- {
- return m_strAttrs;
- }
-
-};
-
-class CStreamOnWriteStream : public IStream
-{
-public:
- IWriteStream *m_pWriteStream;
-
- CStreamOnWriteStream()
- {
- m_pWriteStream = NULL;
- }
-
- void Init(IWriteStream *pWriteStream)
- {
- m_pWriteStream = pWriteStream;
- }
-
- // IUnknown methods
- STDMETHOD(QueryInterface)(REFIID riid, void **ppv)
- {
- if (!ppv)
- return E_POINTER;
-
- *ppv = NULL;
-
- if (IsEqualGUID(riid, IID_IUnknown) ||
- IsEqualGUID(riid, IID_IStream) ||
- IsEqualGUID(riid, IID_ISequentialStream))
- {
- *ppv = (IStream *) this;
- }
- if (!*ppv)
- return E_NOINTERFACE;
- return S_OK;
- }
-
- ULONG __stdcall AddRef()
- {
- return 1;
- }
-
- ULONG __stdcall Release()
- {
- return 1;
- }
-
- // ISequentialStream methods
- HRESULT STDMETHODCALLTYPE Read(void * /*pDest*/, ULONG /*dwMaxLen*/, ULONG * /*pdwRead*/)
- {
- return E_NOTIMPL;
- }
-
- HRESULT STDMETHODCALLTYPE Write(const void *pv, ULONG cb, ULONG *pcbWritten)
- {
- ATLASSUME(m_pWriteStream);
- HRESULT hr = m_pWriteStream->WriteStream((const char *) pv, cb, pcbWritten);
- return (hr==S_OK) ? S_OK : STG_E_WRITEFAULT;
- }
-
- // IStream methods
- HRESULT STDMETHODCALLTYPE Seek(LARGE_INTEGER /*dlibMove*/, DWORD /*dwOrigin*/, ULARGE_INTEGER * /*plibNewPosition*/)
- {
- return E_NOTIMPL;
- }
-
- HRESULT STDMETHODCALLTYPE SetSize(ULARGE_INTEGER /*libNewSize*/)
- {
- return E_NOTIMPL;
- }
-
- HRESULT STDMETHODCALLTYPE CopyTo(IStream * /*pstm*/, ULARGE_INTEGER /*cb*/, ULARGE_INTEGER * /*pcbRead*/, ULARGE_INTEGER * /*pcbWritten*/)
- {
- return E_NOTIMPL;
- }
-
- HRESULT STDMETHODCALLTYPE Commit(DWORD /*grfCommitFlags*/)
- {
- return E_NOTIMPL;
- }
-
- HRESULT STDMETHODCALLTYPE Revert(void)
- {
- return E_NOTIMPL;
- }
-
- HRESULT STDMETHODCALLTYPE LockRegion(ULARGE_INTEGER /*libOffset*/, ULARGE_INTEGER /*cb*/, DWORD /*dwLockType*/)
- {
- return E_NOTIMPL;
- }
-
- HRESULT STDMETHODCALLTYPE UnlockRegion(ULARGE_INTEGER /*libOffset*/, ULARGE_INTEGER /*cb*/, DWORD /*dwLockType*/)
- {
- return E_NOTIMPL;
- }
-
- HRESULT STDMETHODCALLTYPE Stat(STATSTG * /*pstatstg*/, DWORD /*grfStatFlag*/)
- {
- return E_NOTIMPL;
- }
-
-
- HRESULT STDMETHODCALLTYPE Clone(IStream ** /*ppstm*/)
- {
- return E_NOTIMPL;
- }
-};
-
-class CStreamFormatter
-{
-protected:
- CStreamOnWriteStream m_sows;
- IStream *m_pStream;
- BOOL m_bAddCRLF;
- BOOL m_bEmitUnicode;
- UINT m_nConversionCodepage;
-
-public:
- CStreamFormatter()
- {
- m_pStream = NULL;
- m_bAddCRLF = TRUE;
- m_bEmitUnicode = FALSE;
- m_nConversionCodepage = _AtlGetConversionACP();
- }
-
- void Initialize(IStream *pStream, BOOL bAddCRLF=TRUE)
- {
- m_pStream = pStream;
- m_bAddCRLF = bAddCRLF;
- }
-
- void Initialize(IWriteStream *pWriteStream, BOOL bAddCRLF=TRUE)
- {
- m_bAddCRLF = bAddCRLF;
- m_sows.Init(pWriteStream);
- m_pStream = &m_sows;
- }
-
- void EmitUnicode(BOOL bEmitUnicode)
- {
- m_bEmitUnicode = bEmitUnicode;
- }
-
- void SetConversionCodepage(UINT nConversionCodepage)
- {
- m_nConversionCodepage = nConversionCodepage;
- }
-
- void AddCRLF(bool bNewVal)
- {
- m_bAddCRLF = bNewVal;
- }
-
- HRESULT WriteRaw(LPCTSTR szString, int nCount=-1)
- {
- ATLENSURE_RETURN(szString != NULL);
- if (!m_pStream)
- return E_FAIL;
-
- if (m_bEmitUnicode)
- {
-#ifdef _UNICODE
- LPCWSTR sz = szString;
- if (nCount == -1)
- nCount = (int) wcslen(szString);
-#else
- CA2W sz(szString, m_nConversionCodepage);
- nCount = (int) wcslen(sz);
-#endif
- DWORD dwWritten;
- return m_pStream->Write(sz, (DWORD) nCount*sizeof(WCHAR), &dwWritten);
- }
- else
- {
-#ifdef _UNICODE
- CW2A sz(szString, m_nConversionCodepage);
- nCount = (int) strlen(sz);
-#else
- LPCSTR sz = szString;
- if (nCount == -1)
- nCount = (int) strlen(szString);
-#endif
- DWORD dwWritten;
- return m_pStream->Write(sz, (DWORD) nCount, &dwWritten);
- }
- }
-
- HRESULT StartTag(int nTagIndex, LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- if (nTagIndex < 0 || nTagIndex >= ATL_HTML_TAG_LAST)
- return E_INVALIDARG;
- if (m_bAddCRLF && (s_tags[nTagIndex].uFlags & TAGF_BLOCK))
- WriteRaw(_T("\r\n"));
- HRESULT hr = StartTag(s_tags[nTagIndex].szTagName, szContent, szAttrs);
- if (FAILED(hr))
- return hr;
- if (m_bAddCRLF && (s_tags[nTagIndex].uFlags & TAGF_BLOCK))
- WriteRaw(_T("\r\n"));
- return S_OK;
- }
-
- HRESULT StartTag(LPCTSTR szTag, LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- HRESULT hr;
- hr = WriteRaw(_T("<"));
- if (FAILED(hr))
- return hr;
- hr = WriteRaw(szTag);
- if (FAILED(hr))
- return hr;
- hr = WriteAttributes(szAttrs);
- if (FAILED(hr))
- return hr;
- hr = WriteRaw(_T(">"));
- if (FAILED(hr))
- return hr;
- if (szContent && *szContent)
- {
- WriteRaw(szContent);
- EndTag(szTag);
- }
- return S_OK;
- }
-
- HRESULT EndTag(int nTagIndex)
- {
- if (nTagIndex < 0 || nTagIndex >= ATL_HTML_TAG_LAST)
- return E_INVALIDARG;
- if (m_bAddCRLF && (s_tags[nTagIndex].uFlags & TAGF_BLOCK))
- WriteRaw(_T("\r\n"));
- HRESULT hr = EndTag(s_tags[nTagIndex].szTagName);
- if (FAILED(hr))
- return hr;
- if (m_bAddCRLF && (s_tags[nTagIndex].uFlags & TAGF_BLOCK))
- WriteRaw(_T("\r\n"));
- return S_OK;
- }
-
- HRESULT EndTag(LPCTSTR szTag)
- {
- HRESULT hr = WriteRaw(_T("</"));
- if (FAILED(hr))
- return hr;
- hr = WriteRaw(szTag);
- if (FAILED(hr))
- return hr;
- return WriteRaw(_T(">"));
- }
-
- HRESULT WriteAttributes(LPCTSTR szAttrs)
- {
- if (szAttrs && szAttrs[0])
- {
-#ifndef UNICODE
- if (!isspace(static_cast<unsigned char>(szAttrs[0])))
-#else
- if (!iswspace(szAttrs[0]))
-#endif
- WriteRaw(_T(" "));
- return WriteRaw(szAttrs);
- }
-
- return S_OK;
- }
-
-#pragma warning(push)
-#pragma warning(disable : 4793)
- HRESULT WriteFormatted(LPCTSTR szFormat, ...)
- {
- ATLASSERT(szFormat != NULL);
- if (!m_pStream)
- return E_FAIL;
-
- va_list args;
- va_start(args, szFormat);
-
-
- TCHAR buffFixed[1024];
- CTempBuffer<TCHAR> buffHeap;
- TCHAR *szTemp = buffFixed;
- int nCount = _vstprintf_s((LPTSTR)szTemp, _countof(buffFixed), szFormat, args);
- if (nCount < 0)
- {
- // we'll have to dynamically allocate the buffer
- nCount = _vsctprintf(szFormat, args);
- szTemp = NULL;
- ATLTRY(szTemp = buffHeap.Allocate(nCount + 1));
- if (!szTemp)
- return E_OUTOFMEMORY;
- nCount = _vstprintf_s(szTemp, nCount+1, szFormat, args);
- }
-
- va_end(args);
-
- if (nCount > 0)
- return WriteRaw(szTemp, (DWORD) nCount);
- return E_UNEXPECTED;
- }
-#pragma warning(pop)
-};
-
-template <typename TData, int nMax=64>
-class CSimpleStack
-{
-public:
- int m_nTop;
- TData m_Data[nMax];
-
- CSimpleStack()
- {
- m_nTop = -1;
- }
-
- bool IsEmpty()
- {
- return (m_nTop == -1);
- }
-
- bool Push(const TData *pData)
- {
- if (m_nTop + 1 >= nMax)
- return false;
-
- m_nTop++;
-
- m_Data[m_nTop] = *pData;
- return true;
- }
-
- bool Pop(TData *pData)
- {
- if (m_nTop < 0)
- return false;
-
- *pData = m_Data[m_nTop];
- m_nTop--;
- return true;
- }
-};
-
-
-struct HTML_SCHEME
-{
- CString strBgColor;
- CString strLinkColor;
- CString strVLinkColor;
- CString strALinkColor;
- CString strBackground;
- int nTopMargin;
- int nLeftMargin;
-
- CString strTdBgColor;
- CString strTableBgColor;
- CString strTrBgColor;
-
- HTML_SCHEME()
- {
- nTopMargin = -1;
- nLeftMargin = -1;
- }
-};
-
-template <class T>
-class CHtmlGenBase : public CStreamFormatter
-{
-public:
- T* GetOuter()
- {
- return static_cast<T*>(this);
- }
-
- enum ATL_HTML_FORM_METHOD { ATL_HTML_FORM_METHOD_NONE=0, ATL_HTML_FORM_METHOD_GET, ATL_HTML_FORM_METHOD_POST, ATL_HTML_FORM_METHOD_MULTIPART };
-
- CHtmlGenBase()
- {
- m_nWidthPercent = -1;
- m_nHeightPercent = -1;
- m_nFormMethod = ATL_HTML_FORM_METHOD_NONE;
- m_pScheme = NULL;
- }
-
- void SetScheme(HTML_SCHEME *pScheme)
- {
- m_pScheme = pScheme;
- }
-
- HRESULT body(LPCTSTR szBgColor=NULL, LPCTSTR szBackground=NULL, LPCTSTR szTopMargin=NULL, LPCTSTR szLeftMargin=NULL,
- LPCTSTR szAttrs=NULL)
- {
- AtlHtmlAttrs Attrs;
- Attrs.Set(szAttrs);
-
- if (szBgColor && *szBgColor)
- Attrs.Add(_T("bgColor"), szBgColor);
- else if (m_pScheme && m_pScheme->strBgColor.GetLength())
- Attrs.Add(_T("bgColor"), m_pScheme->strBgColor);
-
- if (szBackground && *szBackground)
- Attrs.Add(_T("background"), szBackground);
- else if (m_pScheme && m_pScheme->strBackground.GetLength())
- Attrs.Add(_T("background"), m_pScheme->strBackground);
-
- if (m_pScheme && m_pScheme->strLinkColor.GetLength())
- Attrs.Add(_T("link"), m_pScheme->strLinkColor);
-
- if (m_pScheme && m_pScheme->strALinkColor.GetLength())
- Attrs.Add(_T("alink"), m_pScheme->strALinkColor);
-
- if (m_pScheme && m_pScheme->strVLinkColor.GetLength())
- Attrs.Add(_T("vlink"), m_pScheme->strVLinkColor);
-
- if (szTopMargin && *szTopMargin)
- Attrs.Add(_T("topmargin"), szTopMargin);
- else if (m_pScheme && m_pScheme->nTopMargin != -1)
- Attrs.AddFormat(_T("topmargin=\"%d\""), m_pScheme->nTopMargin);
-
- if (szLeftMargin && *szLeftMargin)
- Attrs.Add(_T("leftmargin"), szLeftMargin);
- else if (m_pScheme && m_pScheme->nLeftMargin != -1)
- Attrs.AddFormat(_T("leftmargin=\"%d\""), m_pScheme->nLeftMargin);
-
- return GetOuter()->StartTag(ATL_HTML_TAG_BODY, NULL, Attrs);
- }
-
- HRESULT bodyEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_BODY);
- }
-
- HRESULT a(LPCTSTR szHref, LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- AtlHtmlAttrs Attrs;
- Attrs.Set(szAttrs);
-
- if (m_strState.GetLength()==0)
- {
- if (szHref && *szHref)
- Attrs.Add(_T("href"), szHref);
- return GetOuter()->StartTag(ATL_HTML_TAG_A, szContent, Attrs);
- }
-
- const TCHAR *szQuestion = NULL;
- if(szHref)
- szQuestion = _tcschr(szHref, '?');
-
- CString strHref = szHref;
- if (!szQuestion)
- strHref.Append("?");
- else
- strHref.Append("&");
-
- strHref += m_strState;
-
- if (szHref && *szHref)
- Attrs.Add(_T("href"), strHref);
-
- return GetOuter()->StartTag(ATL_HTML_TAG_A, szContent, Attrs);
- }
-
- HRESULT aEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_A);
- }
-
- HRESULT b(LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_B, szContent, szAttrs);
- }
-
- HRESULT bEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_B);
- }
-
- HRESULT i(LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_I, szContent, szAttrs);
- }
-
- HRESULT iEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_I);
- }
-
- HRESULT u(LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_U, szContent, szAttrs);
- }
-
- HRESULT uEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_U);
- }
-
- HRESULT font(LPCTSTR szFace, LPCTSTR szSize=NULL, LPCTSTR szColor=NULL, LPCTSTR szAttrs=NULL)
- {
- AtlHtmlAttrs Attrs;
- Attrs.Set(szAttrs);
- if (szFace && *szFace)
- Attrs.Add(_T("face"), szFace);
- if (szSize && *szSize)
- Attrs.Add(_T("size"), szSize);
- if (szColor && *szColor)
- Attrs.Add(_T("color"), szColor);
- return GetOuter()->StartTag(ATL_HTML_TAG_FONT, NULL, Attrs);
- }
-
- HRESULT font(COLORREF clrColor, LPCTSTR szAttrs=NULL)
- {
- TCHAR szColor[8];
- _stprintf_s(szColor, _countof(szColor), _T("#%02x%02x%02x"), GetRValue(clrColor),
- GetGValue(clrColor), GetBValue(clrColor));
- return GetOuter()->font(NULL, NULL, szColor, szAttrs);
- }
-
- HRESULT fontEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_FONT);
- }
-
- HRESULT img(LPCTSTR szSrc, LPCTSTR szAttrs=NULL)
- {
- ATLASSERT(szSrc && *szSrc);
-
- AtlHtmlAttrs Attrs;
- Attrs.Set(szAttrs);
-
- Attrs.Add(_T("src"), szSrc);
-
- return GetOuter()->StartTag(ATL_HTML_TAG_IMG, NULL, Attrs);
- }
-
- HRESULT br(LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_BR, NULL, szAttrs);
- }
-
- HRESULT hr(LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_HR, NULL, szAttrs);
- }
-
- HRESULT div(LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_DIV, szContent, szAttrs);
- }
-
- HRESULT divEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_DIV);
- }
-
- HRESULT blockquote(LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_BLOCKQUOTE, szContent, szAttrs);
- }
-
- HRESULT blockquoteEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_BLOCKQUOTE);
- }
-
- HRESULT address(LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_ADDRESS, szContent, szAttrs);
- }
-
- HRESULT addressEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_ADDRESS);
- }
-
- HRESULT p(LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_P, szContent, szAttrs);
- }
-
- HRESULT pEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_P);
- }
-
- HRESULT h(int nLevel=1, LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- if (nLevel < 1 || nLevel > 6)
- return E_INVALIDARG;
- return GetOuter()->StartTag(ATL_HTML_TAG_H1+nLevel-1, szContent, szAttrs);
- }
-
- HRESULT hEnd(int nLevel=1)
- {
- if (nLevel < 1 || nLevel > 6)
- return E_INVALIDARG;
- return GetOuter()->EndTag(ATL_HTML_TAG_H1+nLevel-1);
- }
-
- HRESULT pre(LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_PRE, szContent, szAttrs);
- }
-
- HRESULT preEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_PRE);
- }
-
- HRESULT q(LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_Q, szContent, szAttrs);
- }
-
- HRESULT qEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_Q);
- }
-
- HRESULT sub(LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_SUB, szContent, szAttrs);
- }
-
- HRESULT subEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_SUB);
- }
-
- HRESULT sup(LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_SUP, szContent, szAttrs);
- }
-
- HRESULT supEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_SUP);
- }
-
- HRESULT ins(LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_INS, szContent, szAttrs);
- }
-
- HRESULT insEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_INS);
- }
-
- HRESULT del(LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_DEL, szContent, szAttrs);
- }
-
- HRESULT delEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_DEL);
- }
-
-
- HRESULT em(LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_EM, szContent, szAttrs);
- }
-
- HRESULT emEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_EM);
- }
-
- HRESULT strong(LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_STRONG, szContent, szAttrs);
- }
-
- HRESULT strongEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_STRONG);
- }
-
- HRESULT dfn(LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_DFN, szContent, szAttrs);
- }
-
- HRESULT dfnEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_DFN);
- }
-
- HRESULT code(LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_CODE, szContent, szAttrs);
- }
-
- HRESULT codeEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_CODE);
- }
-
- HRESULT samp(LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_SAMP, szContent, szAttrs);
- }
-
- HRESULT sampEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_SAMP);
- }
-
- HRESULT kbd(LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_KBD, szContent, szAttrs);
- }
-
- HRESULT kbdEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_KBD);
- }
-
- HRESULT var(LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_VAR, szContent, szAttrs);
- }
-
- HRESULT varEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_VAR);
- }
-
- HRESULT cite(LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_CITE, szContent, szAttrs);
- }
-
- HRESULT citeEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_CITE);
- }
-
- HRESULT abbr(LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_ABBR, szContent, szAttrs);
- }
-
- HRESULT abbrEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_ABBR);
- }
-
- HRESULT acronym(LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_ACRONYM, szContent, szAttrs);
- }
-
- HRESULT acronymEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_ACRONYM);
- }
-
-
- HRESULT ol(LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_OL, NULL, szAttrs);
- }
-
- HRESULT ul(LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_UL, NULL, szAttrs);
- }
-
- HRESULT olEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_OL);
- }
-
- HRESULT ulEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_UL);
- }
-
- HRESULT li(LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_LI, szContent, szAttrs);
- }
-
- HRESULT liEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_LI);
- }
-
- HRESULT dl(LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_DL, szContent, szAttrs);
- }
-
- HRESULT dlEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_DL);
- }
-
- HRESULT dt(LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_DT, szContent, szAttrs);
- }
-
- HRESULT dtEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_DT);
- }
-
- HRESULT dd(LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_DD, szContent, szAttrs);
- }
-
- HRESULT ddEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_DD);
- }
-
- void SetSizePercent(int nWidth, int nHeight)
- {
- m_nWidthPercent = nWidth;
- m_nHeightPercent = nHeight;
- }
-
- HRESULT table(int nBorderWidth=0, LPCTSTR szAttrs=NULL)
- {
- AtlHtmlAttrs Attrs;
- Attrs.Set(szAttrs);
-
- m_RowStack.Push(&m_tableState);
- m_tableState.Clear();
-
- Attrs.AddFormat(_T("border=\"%d\""), nBorderWidth);
-
- if (m_nWidthPercent != -1)
- Attrs.AddFormat(_T("width=\"%d%%\""), m_nWidthPercent);
- if (m_nHeightPercent != -1)
- Attrs.AddFormat(_T("height=\"%d%%\""), m_nHeightPercent);
-
- if (m_pScheme && m_pScheme->strTableBgColor.GetLength())
- Attrs.Add(_T("bgcolor"), m_pScheme->strTableBgColor);
-
- m_nWidthPercent = -1;
- m_nHeightPercent = -1;
- return GetOuter()->StartTag(ATL_HTML_TAG_TABLE, NULL, Attrs);
- }
-
- HRESULT tableEnd()
- {
- if (m_tableState.m_bRowOpen)
- GetOuter()->trEnd();
- m_RowStack.Pop(&m_tableState);
- return GetOuter()->EndTag(ATL_HTML_TAG_TABLE);
- }
-
- HRESULT tr(LPCTSTR szAttrs=NULL)
- {
- AtlHtmlAttrs Attrs;
- Attrs.Set(szAttrs);
-
- if (m_RowStack.IsEmpty())
- GetOuter()->table();
- if (m_tableState.m_bRowOpen)
- GetOuter()->trEnd();
- m_tableState.m_bRowOpen = true;
-
- if (m_pScheme && m_pScheme->strTrBgColor.GetLength())
- Attrs.Add(_T("bgcolor"), m_pScheme->strTrBgColor);
- return GetOuter()->StartTag(ATL_HTML_TAG_TR, NULL, Attrs);
- }
-
- HRESULT td(LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- AtlHtmlAttrs Attrs;
- Attrs.Set(szAttrs);
-
- if (!m_tableState.m_bRowOpen)
- GetOuter()->tr();
- m_tableState.m_bDataOpen = true;
- if (m_pScheme && m_pScheme->strTdBgColor.GetLength())
- Attrs.Add(_T("bgColor"), m_pScheme->strTdBgColor);
-
- HRESULT hr = GetOuter()->StartTag(ATL_HTML_TAG_TD, szContent, Attrs);
- if (FAILED(hr))
- return hr;
- if (szContent)
- m_tableState.m_bDataOpen = false;
- return S_OK;
- }
-
- HRESULT tdEnd()
- {
- if (!m_tableState.m_bDataOpen)
- return S_OK;
- m_tableState.m_bDataOpen = false;
- return GetOuter()->EndTag(ATL_HTML_TAG_TD);
- }
-
- HRESULT trEnd()
- {
- if (!m_tableState.m_bRowOpen)
- return S_OK;
- if (m_tableState.m_bDataOpen)
- GetOuter()->tdEnd();
- m_tableState.m_bRowOpen = false;
- return GetOuter()->EndTag(ATL_HTML_TAG_TR);
- }
-
- HRESULT form(LPCTSTR szAction, ATL_HTML_FORM_METHOD nMethod=ATL_HTML_FORM_METHOD_GET, LPCTSTR szAttrs=NULL)
- {
- static const LPCTSTR s_szFormMethods[] = { NULL, _T("get"), _T("post"), _T("multipart-www-url-encoded") };
- return GetOuter()->form(szAction, s_szFormMethods[nMethod], szAttrs);
- }
-
- HRESULT form(LPCTSTR szAction, LPCTSTR szMethod, LPCTSTR szAttrs=NULL)
- {
- AtlHtmlAttrs Attrs;
- Attrs.Set(szAttrs);
-
- if (szAction && *szAction)
- Attrs.Add(_T("action"), szAction);
- if (szMethod && *szMethod)
- Attrs.Add(_T("method"), szMethod);
-
- return GetOuter()->StartTag(ATL_HTML_TAG_FORM, NULL, Attrs);
- }
-
- HRESULT input(LPCTSTR szType, LPCTSTR szName, LPCTSTR szValue, LPCTSTR szAttrs=NULL)
- {
- AtlHtmlAttrs Attrs;
- Attrs.Set(szAttrs);
-
- if (szType && *szType)
- Attrs.Add(_T("type"), szType);
- if (szName && *szName)
- Attrs.Add(_T("name"), szName);
- if (szValue && *szValue)
- Attrs.Add(_T("value"), szValue);
- return GetOuter()->StartTag(ATL_HTML_TAG_INPUT, NULL, Attrs);
- }
-
- HRESULT submit(LPCTSTR szValue=NULL, LPCTSTR szName=NULL, LPCTSTR szAttrs=NULL)
- {
- return input(_T("submit"), szName, szValue, szAttrs);
- }
-
- HRESULT textarea(LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_TEXTAREA, szContent, szAttrs);
- }
-
- HRESULT textareaEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_TEXTAREA);
- }
-
- HRESULT formEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_FORM);
- }
-
-
- HRESULT select(LPCTSTR szName, BOOL bMultiple=FALSE, LPCTSTR szAttrs=NULL)
- {
- ATLASSERT(szName && *szName);
-
- AtlHtmlAttrs Attrs;
- Attrs.Set(szAttrs);
-
- Attrs.Add(_T("name"), szName);
- if (bMultiple)
- Attrs.Add(_T("multiple"), NULL);
- return GetOuter()->StartTag(ATL_HTML_TAG_SELECT, NULL, Attrs);
- }
-
- HRESULT option(LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_OPTION, szContent, szAttrs);
- }
-
- HRESULT optionEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_OPTION);
- }
-
- HRESULT selectEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_SELECT);
- }
-
-
- HRESULT head(LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_HEAD, NULL, szAttrs);
- }
-
- HRESULT headEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_HEAD);
- }
-
- HRESULT html(LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_HTML, NULL, szAttrs);
- }
-
- HRESULT htmlEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_HTML);
- }
-
- HRESULT map(LPCTSTR szName, LPCTSTR szAttrs=NULL)
- {
- ATLASSERT(szName && *szName);
-
- AtlHtmlAttrs Attrs;
- Attrs.Set(szAttrs);
-
- Attrs.Add(_T("name"), szName);
- return GetOuter()->StartTag(ATL_HTML_TAG_MAP, NULL, Attrs);
- }
-
- HRESULT mapEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_MAP);
- }
-
- HRESULT area(LPCTSTR szAlt, LPCTSTR szHref=NULL, LPCTSTR szAttrs=NULL)
- {
- AtlHtmlAttrs Attrs;
- Attrs.Set(szAttrs);
-
- if (szAlt && *szAlt)
- Attrs.Add(_T("alt"), szAlt);
- if (szHref && *szHref)
- Attrs.Add(_T("href"), szHref);
- return GetOuter()->StartTag(ATL_HTML_TAG_AREA, NULL, Attrs);
- }
-
- HRESULT base(LPCTSTR szHref, LPCTSTR szAttrs=NULL)
- {
- ATLASSERT(szHref && *szHref);
-
- AtlHtmlAttrs Attrs;
- Attrs.Set(szAttrs);
-
- Attrs.Add(_T("href"), szHref);
- return GetOuter()->StartTag(ATL_HTML_TAG_BASE, NULL, Attrs);
- }
-
- HRESULT bdo(LPCTSTR szDir, LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- ATLASSERT(szDir&& *szDir);
-
- AtlHtmlAttrs Attrs;
- Attrs.Set(szAttrs);
-
- Attrs.Add(_T("dir"), szDir);
- return GetOuter()->StartTag(ATL_HTML_TAG_BDO, szContent, Attrs);
- }
-
- HRESULT bdoEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_BDO);
- }
-
- HRESULT big(LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_BIG, szContent, szAttrs);
- }
-
- HRESULT bigEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_BIG);
- }
-
- HRESULT button(LPCTSTR szName=NULL, LPCTSTR szValue=NULL, LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- AtlHtmlAttrs Attrs;
- Attrs.Set(szAttrs);
-
- if (szName && *szName)
- Attrs.Add(_T("name"), szName);
- if (szValue && *szValue)
- Attrs.Add(_T("value"), szValue);
- return GetOuter()->StartTag(ATL_HTML_TAG_BUTTON, szContent, Attrs);
- }
-
- HRESULT buttonEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_BUTTON);
- }
-
- HRESULT iframe(LPCTSTR szSrc=NULL, LPCTSTR szWidth=NULL, LPCTSTR szHeight=NULL, LPCTSTR szAttrs=NULL)
- {
- AtlHtmlAttrs Attrs;
- Attrs.Set(szAttrs);
-
- if (szSrc && *szSrc)
- Attrs.Add(_T("src"), szSrc);
- if (szWidth && *szWidth)
- Attrs.Add(_T("width"), szWidth);
- if (szHeight && *szHeight)
- Attrs.Add(_T("height"), szHeight);
- return GetOuter()->StartTag(ATL_HTML_TAG_IFRAME, NULL, Attrs);
- }
-
- HRESULT iframeEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_IFRAME);
- }
-
- HRESULT label(LPCTSTR szFor=NULL, LPCTSTR szAccessKey=NULL, LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- AtlHtmlAttrs Attrs;
- Attrs.Set(szAttrs);
-
- if (szFor && *szFor)
- Attrs.Add(_T("for"), szFor);
- if (szAccessKey && *szAccessKey)
- Attrs.Add(_T("accesskey"), szAccessKey);
- return GetOuter()->StartTag(ATL_HTML_TAG_LABEL, szContent, Attrs);
- }
-
- HRESULT labelEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_LABEL);
- }
-
- HRESULT link(LPCTSTR szRel=NULL, LPCTSTR szHref=NULL, LPCTSTR szAttrs=NULL)
- {
- AtlHtmlAttrs Attrs;
- Attrs.Set(szAttrs);
-
- if (szRel && *szRel)
- Attrs.Add(_T("rel"), szRel);
- if (szHref && *szHref)
- Attrs.Add(_T("href"), szHref);
- return GetOuter()->StartTag(ATL_HTML_TAG_LINK, NULL, Attrs);
- }
-
- HRESULT meta(LPCTSTR szName=NULL, LPCTSTR szContent=NULL, LPCTSTR szHttpEquiv=NULL, LPCTSTR szAttrs=NULL)
- {
- AtlHtmlAttrs Attrs;
- Attrs.Set(szAttrs);
-
- if (szName && *szName)
- Attrs.Add(_T("name"), szName);
- if (szContent && *szContent)
- Attrs.Add(_T("content"), szContent);
- if (szHttpEquiv && *szHttpEquiv)
- Attrs.Add(_T("http-equiv"), szHttpEquiv);
- return GetOuter()->StartTag(ATL_HTML_TAG_META, NULL, Attrs);
- }
-
- HRESULT noframes(LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_NOFRAMES, szContent, szAttrs);
- }
-
- HRESULT noframesEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_NOFRAMES);
- }
-
- HRESULT noscript(LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_NOSCRIPT, szContent, szAttrs);
- }
-
- HRESULT noscriptEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_NOSCRIPT);
- }
-
- HRESULT col(int nSpan=1, LPCTSTR szWidth=NULL, LPCTSTR szHeight=NULL, LPCTSTR szVAlign=NULL,
- LPCTSTR szHAlign=NULL, LPCTSTR szAttrs=NULL)
- {
- AtlHtmlAttrs Attrs;
- Attrs.Set(szAttrs);
-
-
- if (nSpan != 1)
- Attrs.AddFormat(_T("span"), _T("\"%d\""), nSpan);
- if (szWidth && *szWidth)
- Attrs.Add(_T("width"), szWidth);
- if (szHeight && *szHeight)
- Attrs.Add(_T("height"), szHeight);
- if (szVAlign && *szVAlign)
- Attrs.Add(_T("valign"), szVAlign);
- if (szHAlign && *szHAlign)
- Attrs.Add(_T("align"), szHAlign);
- return GetOuter()->StartTag(ATL_HTML_TAG_COL, NULL, Attrs);
- }
-
- HRESULT colgroup(int nSpan=1, LPCTSTR szWidth=NULL, LPCTSTR szHeight=NULL, LPCTSTR szVAlign=NULL,
- LPCTSTR szHAlign=NULL, LPCTSTR szAttrs=NULL)
- {
- AtlHtmlAttrs Attrs;
- Attrs.Set(szAttrs);
-
- if (nSpan != 1)
- Attrs.AddFormat(_T("span"), _T("\"%d\""), nSpan);
- if (szWidth && *szWidth)
- Attrs.Add(_T("width"), szWidth);
- if (szHeight && *szHeight)
- Attrs.Add(_T("height"), szHeight);
- if (szVAlign && *szVAlign)
- Attrs.Add(_T("valign"), szVAlign);
- if (szHAlign && *szHAlign)
- Attrs.Add(_T("align"), szHAlign);
- return GetOuter()->StartTag(ATL_HTML_TAG_COL, NULL, Attrs);
- }
-
- HRESULT colgroupEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_COLGROUP);
- }
-
- HRESULT fieldset(LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_FIELDSET, NULL, szAttrs);
- }
-
- HRESULT fieldsetEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_FIELDSET);
- }
-
- HRESULT legend(LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_LEGEND, szContent, szAttrs);
- }
-
- HRESULT legendEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_LEGEND);
- }
-
- HRESULT tbody(LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_TBODY, NULL, szAttrs);
- }
-
- HRESULT tbodyEnd()
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_TBODY);
- }
-
- HRESULT tfoot(LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_TFOOT, NULL, szAttrs);
- }
-
- HRESULT tfootEnd()
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_TFOOT);
- }
-
- HRESULT th(LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- if (!m_tableState.m_bRowOpen)
- GetOuter()->tr();
- m_tableState.m_bDataOpen = true;
- return GetOuter()->StartTag(ATL_HTML_TAG_TH, szContent, szAttrs);
- }
-
- HRESULT thEnd()
- {
- ATLASSUME(m_tableState.m_bDataOpen);
- m_tableState.m_bDataOpen = false;
- return GetOuter()->EndTag(ATL_HTML_TAG_TH);
- }
-
- HRESULT title(LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_TITLE, szContent, szAttrs);
- }
-
- HRESULT titleEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_TITLE);
- }
-
- HRESULT tt(LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_TT, szContent, szAttrs);
- }
-
- HRESULT ttEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_TT);
- }
-
- // unfortunately, we can't use small since it is defined as char
- // in rpcndr.h!
- HRESULT _small(LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_SMALL, szContent, szAttrs);
- }
-
- HRESULT _smallEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_SMALL);
- }
-
- HRESULT span(LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- return GetOuter()->StartTag(ATL_HTML_TAG_SPAN, szContent, szAttrs);
- }
-
- HRESULT spanEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_SPAN);
- }
-
- HRESULT object(LPCTSTR szClassId, LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- AtlHtmlAttrs Attrs;
- Attrs.Set(szAttrs);
- if (szClassId && *szClassId)
- Attrs.Add(_T("classid"), szClassId);
- return GetOuter()->StartTag(ATL_HTML_TAG_OBJECT, szContent, Attrs);
- }
-
- HRESULT object(REFCLSID rclsid, LPCTSTR szContent=NULL, LPCTSTR szAttrs=NULL)
- {
- USES_CONVERSION_EX;
- OLECHAR szClsid[64];
- CString strClassId;
- int i = StringFromGUID2(rclsid, szClsid, 64);
- if (!i)
- return E_FAIL;
- szClsid[i-2] = 0; // don't want curly braces
- strClassId.Format(_T("clsid:%s"), OLE2T_EX_DEF(szClsid+1));
- return object(strClassId, szContent, szAttrs);
- }
-
- HRESULT objectEnd()
- {
- return GetOuter()->EndTag(ATL_HTML_TAG_OBJECT);
- }
-
- HRESULT param(LPCTSTR szName, LPCTSTR szValue, LPCTSTR szAttrs=NULL)
- {
- ATLASSERT(szName && *szName);
-
- AtlHtmlAttrs Attrs;
- Attrs.Set(szAttrs);
-
- Attrs.Add(_T("name"), szName);
- if (szValue && *szValue)
- Attrs.Add(_T("value"), szValue);
- return GetOuter()->StartTag(ATL_HTML_TAG_PARAM, NULL, Attrs);
- }
-
-private:
- CString m_strState;
- HTML_SCHEME *m_pScheme;
-
- struct TableState
- {
- TableState() : m_bRowOpen(false), m_bDataOpen(false)
- {
-
- }
-
- void Clear()
- {
- m_bRowOpen = false;
- m_bDataOpen = false;
- }
-
- bool m_bRowOpen;
- bool m_bDataOpen;
- };
-
- ATL_HTML_FORM_METHOD m_nFormMethod;
-
- TableState m_tableState;
- CSimpleStack<TableState> m_RowStack;
-
- int m_nWidthPercent;
- int m_nHeightPercent;
-};
-
-class CHtmlGen : public CHtmlGenBase<CHtmlGen>
-{
-public:
-};
-
-} // namespace ATL
-#pragma pack(pop)
-
-#endif // __ATLHTML_H__
diff --git a/include/atl/atlhttp.h b/include/atl/atlhttp.h
deleted file mode 100644
index e8a4321e6..000000000
--- a/include/atl/atlhttp.h
+++ /dev/null
@@ -1,725 +0,0 @@
-// This is a part of the Active Template Library.
-// Copyright (C) Microsoft Corporation
-// All rights reserved.
-//
-// This source code is only intended as a supplement to the
-// Active Template Library Reference and related
-// electronic documentation provided with the library.
-// See these sources for detailed information regarding the
-// Active Template Library product.
-
-#ifndef __ATLHTTP_H__
-#define __ATLHTTP_H__
-
-#pragma once
-#ifndef __CPPUNWIND
-#pragma warning(push)
-#pragma warning(disable: 4702)
-#endif
-#ifndef _WINSOCKAPI_
- #include <winsock2.h>
-#endif
-#include <atlutil.h>
-#include <atlisapi.h>
-#include <atlcoll.h>
-#include <atlfile.h>
-#define SECURITY_WIN32
-#include <security.h>
-#include <atlenc.h>
-#ifndef _ATL_NO_DEFAULT_LIBS
-#pragma comment(lib, "ws2_32.lib")
-#pragma comment(lib, "SECUR32.LIB")
-#endif // !_ATL_NO_DEFAULT_LIBS
-
-#include <atlspriv.h>
-
-#pragma warning(push)
-#pragma warning(disable: 4625) // copy constructor could not be generated because a base class copy constructor is inaccessible
-#pragma warning(disable: 4626) // assignment operator could not be generated because a base class assignment operator is inaccessible
-
-#pragma pack(push,_ATL_PACKING)
-namespace ATL {
-
-template <class TSocketClass>
-class CAtlHttpClientT;
-class CAtlBaseAuthObject;
-
-enum status_headerparse{
- ATL_HEADER_PARSE_COMPLETE=0,
- ATL_HEADER_PARSE_HEADERNOTCOMPLETE,
- ATL_HEADER_PARSE_HEADERERROR
-};
-
-enum readstate{rs_init=0, rs_readheader, rs_scanheader, rs_readbody, rs_complete};
-
-#define ATL_HEADER_END "\r\n\r\n"
-#define ATL_HEADER_END_LEN 4
-#define ATL_DW_HEADER_END 0x0a0d0a0d
-#define ATL_FIELDNAME_DELIMITER _T(':')
-#define ATL_MAX_FIELDNAME_LEN 1024
-#define ATL_MAX_VALUE_LEN 1024
-#define ATL_AUTH_HDR_SIZE 1024
-#define ATL_READ_BUFF_SIZE 2048
-#define ATL_INVALID_STATUS -1
-#define ATL_HTTP_HEADER _T(" HTTP/1.1\r\n")
-#define ATL_HTTP_HEADER_PROXY _T(" HTTP/1.1\r\n")
-#ifndef ATL_HTTP_USERAGENT
- #define ATL_HTTP_USERAGENT _T("User-Agent: Microsoft-ATL-Native/") _T(_ATL_VER_RBLD) _T("\r\n")
-#endif
-
-#define ATL_IS_INVALIDCREDHANDLE(x) ((x.dwLower==0xFFFFFFFF) && (x.dwUpper==0xFFFFFFFF))
-#define ATL_HTTP_AUTHTYPE_NTLM _T("NTLM")
-#define ATL_HTTP_AUTHTYPE_BASIC _T("BASIC")
-#define ATL_HTTP_METHOD_GET _T("GET")
-#define ATL_HTTP_METHOD_POST _T("POST")
-
-#ifndef MAX_REALM_LEN
- #define MAX_REALM_LEN 1024
-#endif
-
-#ifndef _ATL_MAX_AUTH_BUFF
- #define _ATL_MAX_AUTH_BUFF 512
-#endif
-
-__interface IAuthInfo;
-typedef bool (WINAPI *PFNATLCHUNKEDCB)(BYTE** ppData, DWORD *pdwSize, DWORD_PTR dwParam);
-typedef bool (WINAPI *PFNATLSTATUSCALLBACK)(DWORD dwBytesSent, DWORD_PTR dwParam);
-
-#define ATL_HTTP_FLAG_AUTO_REDIRECT 0x1
-#define ATL_HTTP_FLAG_PROCESS_RESULT 0x2
-#define ATL_HTTP_FLAG_SEND_CALLBACK 0x4
-#define ATL_HTTP_FLAG_SEND_BLOCKS 0x8
-#define ATL_HTTP_FLAG_INVALID_FLAGS 0xFFFFFFFF
-
-#ifndef ATL_HTTP_DEFAULT_BLOCK_SIZE
- #define ATL_HTTP_DEFAULT_BLOCK_SIZE 4096
-#endif
-
-#define ATL_HTTP_CLIENT_EMPTY_READ_RETRIES 5
-
-struct ATL_NAVIGATE_DATA
-{
- LPCTSTR szExtraHeaders;
- LPCTSTR szMethod;
- LPCTSTR szDataType;
- DWORD dwDataLen;
- DWORD dwFlags;
- DWORD dwTimeout;
- DWORD dwSendBlockSize;
- DWORD dwReadBlockSize;
- DWORD_PTR m_lParamSend;
- DWORD_PTR m_lParamRead;
- DWORD_PTR m_lParamChunkCB;
- short nPort;
- BYTE *pData;
- PFNATLCHUNKEDCB pfnChunkCallback;
- PFNATLSTATUSCALLBACK pfnSendStatusCallback;
- PFNATLSTATUSCALLBACK pfnReadStatusCallback;
-};
-
-class CAtlNavigateData : public ATL_NAVIGATE_DATA
-{
-public:
- CAtlNavigateData() throw(); // public construction
- CAtlNavigateData(const CAtlNavigateData &rhs);
- CAtlNavigateData(const ATL_NAVIGATE_DATA &rhs);
- CAtlNavigateData& operator=(const CAtlNavigateData &rhs);
- CAtlNavigateData& operator=(const ATL_NAVIGATE_DATA &rhs);
- DWORD SetFlags(DWORD dwNewFlags) throw(); // set all flags
- DWORD GetFlags() throw(); // get value of flags
- DWORD AddFlags(DWORD dwFlagsToAdd) throw(); // add one or more flags to existing flags
- DWORD RemoveFlags(DWORD dwFlagsToRemove) throw(); // remove one or more flags from existing flags
- LPCTSTR SetExtraHeaders(LPCTSTR szNewHeaders) throw(); // set the extra request headers
- LPCTSTR GetExtraHeaders() throw(); // get the extra request headers
- LPCTSTR SetMethod(LPCTSTR szNewMethod) throw(); // set the HTTP request method
- LPCTSTR GetMethod() throw(); // get the HTTP request method
- short SetPort(short newPort) throw(); // set the TCP port for this request
- short GetPort() throw(); // get the TCP port for this request
- void SetPostData(BYTE *pData, DWORD dwDataLen, LPCTSTR szDataType) throw(); // Set data to be sent as the reqeust entity body
- DWORD SetSocketTimeout(DWORD dwNewTimeout) throw(); // Set the timeout for this socket
- DWORD GetSocketTimeout() throw(); // Get the timeout for this socket
- DWORD SetSendBlockSize(DWORD dwBlockSize) throw(); // Set the size of the blocks used to send data
- DWORD GetSendBlockSize() throw(); // get the size of the blocks used to send data
- DWORD SetReadBlockSize(DWORD dwBlockSize) throw(); // Set the size of the blocks used to send data
- DWORD GetReadBlockSize() throw(); // get the size of the blocks used to send data
- PFNATLCHUNKEDCB SetChunkCallback(PFNATLCHUNKEDCB pfn, DWORD_PTR dwParam) throw(); // set the callback function used for sending chunked data
- PFNATLCHUNKEDCB GetChunkCallback() throw(); // get the chunked callback function
- PFNATLSTATUSCALLBACK SetSendStatusCallback(PFNATLSTATUSCALLBACK pfn, DWORD_PTR dwData) throw(); // sets a function pointer to be called after bytes are sent over the socket
- PFNATLSTATUSCALLBACK GetSendStatusCallback() throw(); // returns current status callback function
- PFNATLSTATUSCALLBACK SetReadStatusCallback(PFNATLSTATUSCALLBACK pfn, DWORD_PTR dwData) throw();
- PFNATLSTATUSCALLBACK GetReadStatusCallback() throw();
-};
-
-template <class TSocketClass>
-class CAtlHttpClientT :
- private TSocketClass
-{
-public:
- CAtlHttpClientT() throw();
- virtual ~CAtlHttpClientT()
- {
- }
-
- // Use these functions to send an HTTP request and retrieve
- // the response.
- bool Navigate(
- const CUrl* pUrl,
- ATL_NAVIGATE_DATA *pNavData = NULL
- ) throw(...);
-
- bool Navigate(
- LPCTSTR szServer,
- LPCTSTR szPath,
- ATL_NAVIGATE_DATA *pNavData = NULL
- ) throw(...);
-
- bool Navigate(
- LPCTSTR szURL,
- ATL_NAVIGATE_DATA *pNavData = NULL
- ) throw(...);
-
-
- // Performs navigation, sending data with Transfer-Coding: chunked
- bool NavigateChunked(
- const CUrl *pUrl,
- ATL_NAVIGATE_DATA *pData
- ) throw();
-
- bool NavigateChunked(
- LPCTSTR szServer,
- LPCTSTR szPath,
- ATL_NAVIGATE_DATA *pNavData
- ) throw();
-
- bool NavigateChunked(
- LPCTSTR szURL,
- ATL_NAVIGATE_DATA *pNavData
- ) throw();
-
- // Use to set/retrieve information about the proxy server used
- // when making this request via a proxy server.
- bool SetProxy(LPCTSTR szProxy = NULL, short nProxyPort = 0) throw();
- void RemoveProxy() throw();
- LPCTSTR GetProxy() const throw();
- short GetProxyPort() const throw();
-
- // Use these functions to add/remove/find objects that will
- // be used to authorize request when a 401 Not Authorized response
- // is received. This class maps these objects by scheme name in map.
- // Override NegotiateAuth to change the way authorization negotiation occurs.
- bool AddAuthObj(LPCTSTR szScheme, CAtlBaseAuthObject *pObject, IAuthInfo *pInfo=NULL) throw();
- const CAtlBaseAuthObject* FindAuthObject(LPCTSTR szScheme) throw();
- bool RemoveAuthObject(LPCTSTR szScheme) throw();
- virtual bool NegotiateAuth(bool bProxy) throw();
-
-
- // Retrieve the value of a response header
- bool GetHeaderValue(LPCTSTR szName, CString& strValue) const throw();
- bool GetHeaderValue(__in_z LPCTSTR szName, __out_ecount_part_z_opt(*pdwLen, *pdwLen) LPTSTR szBuffer, __inout DWORD *pdwLen) const throw();
-
- DWORD GetResponseLength() throw(); // Get the number of bytes in the response
- const BYTE* GetResponse() throw(); // Get the entire response
- DWORD GetBodyLength() const throw(); // Get the length of the body of the response (everything after the \r\n\r\n)
- const BYTE* GetBody() throw(); // Get the body of the response (length is determined by GetBodyLength())
- DWORD GetRawResponseHeaderLength() throw(); // Get the length of the raw request headers
- bool GetRawResponseHeader(LPBYTE szBuffer, DWORD *pdwLen) throw(); // Get the raw request headers
- LPCURL GetCurrentUrl() const throw(); // Get a pointer to the current URL for this request
- DWORD GetFlags() const throw(); // Retrieve flags used for processing this request
- int GetStatus() throw(); // Get the HTTP status code that resulted from making this request
- LPCTSTR GetMethod() throw(); // Get the HTTP method used for making this request
- BYTE* GetPostData() throw(); // Get a pointer to raw data being sent with this request
- DWORD GetPostDataLen() throw(); // Get the length of the raw data sent with this request
- LPCTSTR GetPostDataType() throw(); // Get the data type (sent as Content-Type header) for this request
- DWORD GetLastError() throw(); // Retrieves errors from the underlying socket
- const SOCKET& GetSocket() throw(); // Retrieves the underlying socket. Be careful!
- void Close() throw(); // Close the connection
- DWORD SetSocketTimeout(DWORD dwNewTimeout) throw(); // Sets a new socket timeout, returns the old timeout.
- DWORD GetSocketTimeout() throw(); // retrieves the current socket timeout
- void AuthProtocolFailed(LPCTSTR szProto) throw(); // notifies us of failure to connect with the named protocol
- const ATL_NAVIGATE_DATA* GetCurrentNavdata();
- enum HTTP_RESPONSE_READ_STATUS
- {
- RR_OK = 0, // response was successfully processed
- RR_FAIL, // an unknown error occurred reading the HTTP response
- RR_STATUS_INVALID, // could not parse the status line
- RR_PARSEHEADERS_FAILED, // failed to parse HTTP response headers
- RR_READSOCKET_FAILED, // failed to read response data from socket
- RR_READBODY_FAILED, // failed to successfully read the entity body of the HTTP response
- RR_READCHUNKEDBODY_FAILED, // failed to read a 'Transfer-Encoding: chunked' response body
- RR_NOT_READ // we haven't started reading the response.
- };
- HTTP_RESPONSE_READ_STATUS GetResponseStatus();
-
-
-// Implementation
- HTTP_RESPONSE_READ_STATUS ReadHttpResponse() throw();
- void ResetConnection() throw();
- bool ProcessStatus(DWORD dwFlags) throw();
- bool BuildRequest(/*out*/CString *pstrRequest,
- LPCTSTR szDataType=NULL,
- LPCTSTR szExtraHeaders=NULL) throw();
-
- void SetSilentLogonOk(bool bSet)
- {
- m_bSilentLogonOk = bSet;
- }
-protected:
- DWORD WriteWithNoData(LPCSTR pRequest, DWORD dwRequestLen);
- DWORD WriteWithCallback(LPCSTR pRequest, DWORD dwRequestLen);
- DWORD WriteWithChunks(LPCSTR pRequest, DWORD dwRequestLen);
- DWORD WriteWithData(LPCSTR pRequest, DWORD dwRequestLen);
- bool SetDefaultUrl(LPCTSTR szUrl, short nPortNumber=ATL_URL_DEFAULT_HTTP_PORT) throw();
- bool SetDefaultUrl(LPCURL pUrl, short nPortNumber=ATL_URL_DEFAULT_HTTP_PORT) throw();
- bool SetDefaultMethod(LPCTSTR szMethod) throw();
- void InitializeObject() throw();
- void ResetRequest() throw();
- bool ReadSocket() throw();
- unsigned char* FindHeaderEnd(unsigned char** ppBegin) throw();
- bool LookupRegProxy() throw();
- bool DisconnectIfRequired() throw();
- bool ConnectSocket() throw();
-
- long GetContentLength() throw();
- LPCSTR NextLine(BYTE* pCurr) throw();
- bool IsMsgBodyChunked() throw();
- LPCSTR FindEndOfHeader(LPCSTR pszStart) throw();
- bool DecodeHeader(LPCSTR pHeaderStart, LPCSTR pHeaderEnd) throw();
- virtual void OnSetCookie(LPCTSTR /*szCookie*/) throw();
- LPCSTR ParseStatusLine(BYTE* pBuffer) throw();
- int CrackResponseHeader(LPCSTR pBuffer, /*out*/ LPCSTR *pEnd) throw();
- bool ReadBody(int nContentLen, int nCurrentBodyLen) throw();
- bool ReadChunkedBody() throw();
- bool ReconnectIfRequired() throw();
- bool CompleteURL(CString& strURL) throw();
- bool ProcessObjectMoved() throw();
- bool _SetDefaultUrl(LPCTSTR szURL, short nPort) throw();
-
- enum CHUNK_STATE{
- READ_CHUNK_SIZE, // need to read the size of a chunk.
- READ_CHUNK_SIZE_FOOTER,
- READ_CHUNK_DATA, // need to read the actual data
- READ_CHUNK_DATA_FOOTER, // need to read the chunk footer.
- READ_CHUNK_TRAILER, // Read the trailer headers at the end of the chunk data
- READ_CHUNK_TRAILER_FOOTER, // read the final crlf
- CHUNK_READ_DATA_COMPLETE, // done reading chunk data.
- };
-
- enum CHUNK_LEX_RESULT{
- LEX_OK,
- LEX_OUTOFDATA,
- LEX_ERROR,
- LEX_TRAILER_COMPLETE
- };
-
- CHUNK_LEX_RESULT get_chunked_size(__deref_inout char *&pBuffStart, __deref_inout char *&pBuffEnd, __inout long* pnChunkSize) throw();
- bool move_leftover_bytes(__in_ecount(nLen) char *pBufferStart, __in int nLen, __deref_inout char *&pBuffStart, __deref_inout char *&pBuffEnd) throw();
- CHUNK_LEX_RESULT get_chunked_data(__deref_inout char *&pBufferStart, __deref_inout char *&pBufferEnd, long nChunkSize,
- __deref_out_ecount_part(*pnDataLen, *pnDataLen) char **ppDataStart, __inout long *pnDataLen) throw();
- CHUNK_LEX_RESULT consume_chunk_trailer(__deref_inout char *&pBufferStart, __deref_inout char *pBufferEnd) throw();
- CHUNK_LEX_RESULT consume_chunk_footer(__deref_inout char *&pBufferStart, __deref_inout char *&pBufferEnd) throw();
-
- typedef CAtlMap<
- CString,
- CString,
- CStringElementTraitsI<CString>,
- CStringElementTraitsI<CString>
- > HeaderMapType;
-
- typedef CAtlMap <
- CString,
- CAtlBaseAuthObject*,
- CStringElementTraitsI<CString>
- > AuthMapType;
-
- typedef CAtlArray<
- CString,
- CStringElementTraitsI<CString>
- > AuthListType;
-
- HeaderMapType m_HeaderMap; // Map of response headers
- AuthMapType m_AuthMap; // Map of pointers to authorization objects.
- AuthListType m_AuthTypes; // list of authorization types the server is willing to use.
- BOOL m_bSilentLogonOk;
- CAtlIsapiBuffer<> m_current; // The entire response
- CUrl m_urlCurrent; // URL of current request
-
- CString m_strMethod; // Current request method.
- CString m_strProxy; // Path to current proxy server.
-
- long m_nStatus; // Current response status (from status line)
- short m_nProxyPort; // Port used on current proxy server
- DWORD m_dwBodyLen; // Length of body
- DWORD m_dwHeaderLen; // Length of current raw headers
- DWORD m_dwHeaderStart;
- BYTE *m_pCurrent;
- BYTE *m_pEnd; // the end of the data we've read fromt he socket;
- ATL_NAVIGATE_DATA *m_pNavData;
- HTTP_RESPONSE_READ_STATUS m_LastResponseParseError;
-}; //CAtlHttpClientT
-typedef CAtlHttpClientT<ZEvtSyncSocket> CAtlHttpClient;
-
-
-// Interface used to acquire authentication information from clients
-__interface IAuthInfo
-{
- HRESULT GetPassword(__out_ecount_part_z_opt(*pdwBuffSize, *pdwBuffSize) LPTSTR szPwd, __inout DWORD *pdwBuffSize);
- HRESULT GetUsername(__out_ecount_part_z_opt(*pdwBuffSize, *pdwBuffSize) LPTSTR szUid, __inout DWORD *pdwBuffSize);
- HRESULT GetDomain(__out_ecount_part_z_opt(*pdwBuffSize, *pdwBuffSize) LPTSTR szDomain, __inout DWORD *pdwBuffSize);
-};
-typedef HRESULT (IAuthInfo::*PFNAUTHFUNC)(LPTSTR szPwd, DWORD *pdwSize);
-
-// pure virtual class that describes required functions for authoriztion
-// objects
-class CAtlBaseAuthObject
-{
-public:
- CAtlBaseAuthObject();
- virtual bool Authenticate(LPCTSTR szAuthTypes, bool bProxy) = 0;
- virtual void Init(CAtlHttpClient *pSocket, IAuthInfo *pAuthInfo) = 0;
- bool m_bFailed;
-};
-
-// strings used for authentication.
-extern __declspec(selectany)const TCHAR * const g_pszWWWAuthenticate = _T("www-authenticate");
-extern __declspec(selectany)const TCHAR * const g_pszProxyAuthenticate = _T("proxy-authenticate");
-
-// Performs NTLM authentication
-class CNTLMAuthObject :
- public CAtlBaseAuthObject
-{
-public:
- virtual ~CNTLMAuthObject() throw();
- CNTLMAuthObject() throw();
- CNTLMAuthObject(IAuthInfo *pAuthInfo) throw();
- void SetAuthInfo(IAuthInfo *pAuthInfo) throw();
- bool GetCredentialNames(CString& theName);
-
-// Implementation
- // Called by the CAtlHttpClient class to authenticate a user.
- virtual void Init(CAtlHttpClient *pSocket, IAuthInfo *pAuthInfo=NULL) throw();
-
- // Called by the CAtlHttpClient class to initialize this authentication object.
- virtual bool Authenticate(LPCTSTR szAuthTypes, bool bProxy) throw();
-protected:
- bool AcquireCredHandle() throw();
- // This function creates an NTML Authorization header
- // and sends it to the HTTP server.
- bool SendSecurityInfo(SecBuffer *pSecBuffer, LPSTR *pszBuffer) throw();
- bool DoNTLMAuthenticate() throw();
-
- IAuthInfo *m_pAuthInfo;
- CAtlHttpClient *m_pSocket;
- CredHandle m_hCredentials;
- int m_nMaxTokenSize;
- TimeStamp m_ts;
- bool m_bProxy;
- static const char * const m_pszFmtWWW;
- static const char * const m_pszFmtProxy;
- CAtlNavigateData m_CurrentRequestData;
-
-}; // CNTLMAuthObject
-
-// Performs BASIC authentication for an CAtlHttpClient
-// object. Caller must implement an IAuthInfo interface
-// and pass it to this object before this object attempts
-// to authenticate or authentication will fail.
-class CBasicAuthObject :
- public CAtlBaseAuthObject
-{
-public:
- CBasicAuthObject() throw();
- CBasicAuthObject(IAuthInfo *pAuthInfo) throw();
- void SetAuthInfo(IAuthInfo *pAuthInfo) throw();
- LPCTSTR GetRealm() throw(); // Retrieve's the realm being used.
-
-// Implementation
- // Called by the CAtlHttpClient class to authenticate a user.
- virtual bool Authenticate(LPCTSTR szAuthTypes, bool bProxy) throw();
-
- // Called by the CAtlHttpClient class to initialize this authentication object.
- virtual void Init(CAtlHttpClient *pSocket, IAuthInfo *pAuthInfo=NULL) throw();
-protected:
- bool DoBasicAuthenticate() throw();
- bool CrackRealm(LPCTSTR szHeader) throw();
-
- IAuthInfo *m_pAuthInfo;
- CAtlHttpClient *m_pClient;
- TCHAR m_szRealm[MAX_REALM_LEN];
- bool m_bProxy;
- static const char * const m_pszFmtWWW;
- static const char * const m_pszFmtProxy;
-}; // CBasicAuthObject
-
-__declspec(selectany)const char * const CBasicAuthObject::m_pszFmtWWW = "Authorization: Basic ";
-__declspec(selectany)const char * const CBasicAuthObject::m_pszFmtProxy = "Proxy-Authorization: Basic ";
-__declspec(selectany)const char * const CNTLMAuthObject::m_pszFmtWWW = "Authorization: NTLM %s\r\n";
-__declspec(selectany)const char * const CNTLMAuthObject::m_pszFmtProxy = "Proxy-Authorization: NTLM %s\r\n";
-
-typedef CTempBuffer<TCHAR, _ATL_MAX_AUTH_BUFF> CAuthInfoBuffType;
-inline bool _AtlGetAuthInfoHelper(IAuthInfo *pObj, PFNAUTHFUNC pFunc, CAuthInfoBuffType& buff, DWORD *dwLen) throw()
-{
- ATLENSURE_RETURN_VAL(pObj, false);
- ATLENSURE_RETURN_VAL(pFunc, false);
- DWORD dwSize = _ATL_MAX_AUTH_BUFF;
- bool bRet = true;
- TCHAR *szValue = NULL;
- _ATLTRY
- {
- szValue = buff.Allocate(_ATL_MAX_AUTH_BUFF);
- HRESULT hr = E_FAIL;
- if (szValue)
- {
- hr = (pObj->*pFunc)(szValue, &dwSize);
- if (hr != S_OK)
- {
- if (hr == E_OUTOFMEMORY)
- {
- // buffer not big enough, try to allocate
- szValue = buff.Reallocate(dwSize);
- if (szValue)
- {
- // retry the call
- if (S_OK != (pObj->*pFunc)(szValue, &dwSize))
- bRet = false;
- }
- else
- bRet = false;
- }
- else
- bRet = false;
- }
- }
- else
- bRet = false;
-
- }
- _ATLCATCHALL()
- {
- bRet = false;
- }
- if (bRet)
- *dwLen = (DWORD)_tcslen(szValue);
- else
- *dwLen = 0;
- return bRet;
-}
-
-//
-// Security Service Provider Interface (sspi) Helper classes
-// These classes are used as helpers for structures used in
-// SSPI functions.
-//
-class CSecAuthIdentity : public SEC_WINNT_AUTH_IDENTITY_EX
-{
-public:
- CSecAuthIdentity() throw()
- {
- Version = SEC_WINNT_AUTH_IDENTITY_VERSION;
- Length = sizeof(SEC_WINNT_AUTH_IDENTITY_EX);
-#ifdef _UNICODE
- Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
-#else
- Flags = SEC_WINNT_AUTH_IDENTITY_ANSI;
-#endif
- }
-
-
- bool Init(IAuthInfo *pAuthInfo) throw()
- {
- if (!pAuthInfo)
- return false;
-
- if (!_AtlGetAuthInfoHelper(pAuthInfo, &IAuthInfo::GetUsername, buffUserName, &UserLength))
- return false;
-
- if (!_AtlGetAuthInfoHelper(pAuthInfo, &IAuthInfo::GetPassword, buffPassword, &PasswordLength))
- return false;
-
- if (!_AtlGetAuthInfoHelper(pAuthInfo, &IAuthInfo::GetDomain, buffDomain, &DomainLength))
- return false;
-
-#ifndef _UNICODE
- User = (unsigned char*)(char*)buffUserName;
- Domain = DomainLength > 0 ? (unsigned char*)(char*)buffDomain : 0;
- Password = PasswordLength > 0 ? (unsigned char*)(char*)buffPassword : 0;
-#else
- // have to cast to unsigned short *, because SEC_WINNT_AUTH_IDENTITY_EXW
- // uses unsigned short instead of wchar_t
- User = (unsigned short *)(wchar_t*)buffUserName;
- Domain = DomainLength > 0 ? (unsigned short *)(wchar_t*)buffDomain : 0;
- Password = PasswordLength > 0 ? (unsigned short *)(wchar_t*)buffPassword : 0;
-#endif
- return true;
- }
-
-protected:
- CAuthInfoBuffType buffUserName;
- CAuthInfoBuffType buffPassword;
- CAuthInfoBuffType buffDomain;
-}; // CSecAuthIdentity
-
-class CSecBuffer : public SecBuffer
-{
-public:
- CSecBuffer() throw()
- {
- cbBuffer = 0;
- BufferType = 0;
- pvBuffer = NULL;
- m_cbAlloc = 0;
- }
-
- ~CSecBuffer() throw()
- {
- delete [] static_cast<unsigned char*>(pvBuffer);
- }
-
- bool SetSize(unsigned long nSize) throw()
- {
- if (!nSize)
- return false;
-
- if (pvBuffer)
- {
- delete [] static_cast<unsigned char*>(pvBuffer);
- pvBuffer = NULL;
- cbBuffer = 0;
- m_cbAlloc = 0;
- }
-
- ATLTRY(pvBuffer = static_cast<void*>(new unsigned char[nSize]));
- if (pvBuffer)
- {
- cbBuffer = nSize;
- BufferType = SECBUFFER_TOKEN;
- m_cbAlloc = cbBuffer;
- return true;
- }
- return false;
- }
-
- bool ClearBuffer(unsigned long nSize) throw()
- {
- if(nSize > m_cbAlloc)
- return false;
-
- ZeroMemory(pvBuffer, nSize);
- cbBuffer = nSize;
- return true;
- }
-
- unsigned long Size()
- {
- return cbBuffer;
- }
-
- unsigned char *Buffer() throw()
- {
- return static_cast<unsigned char*>(pvBuffer);
- }
-
- operator SecBuffer*() throw()
- {
- return (SecBuffer*)this;
- }
-
-protected:
- unsigned long m_cbAlloc;
-
-}; // CSecBuffer
-
-class CSecBufferDesc : public SecBufferDesc
-{
-public:
- CSecBufferDesc() throw()
- {
- ulVersion = SECBUFFER_VERSION;
- cBuffers = 0;
- pBuffers = NULL;
- }
-
- ~CSecBufferDesc() throw()
- {
- cBuffers = 0;
-
- if (pBuffers)
- {
- CSecBuffer *psb = (CSecBuffer*)pBuffers;
- delete [] psb;
- }
- }
-
- // index is 0 based
- CSecBuffer* Buffers(unsigned int i) throw()
- {
- if (i < cBuffers)
- {
- return (CSecBuffer*)(&pBuffers[i]);
- }
-
- return NULL;
- }
-
- bool AddBuffers(unsigned int nCount, unsigned int nBufferSize) throw()
- {
- if (!nCount)
- return true;
-
- if (cBuffers == 0)
- {
- CSecBuffer *pSecBuffer = NULL;
- ATLTRY(pSecBuffer = new CSecBuffer[nCount]);
- if (!pSecBuffer)
- return false;
- CAutoVectorPtr<CSecBuffer> spSecBuffer(pSecBuffer);
-
- for (unsigned int i=0; i<nCount; i++)
- {
- if (!pSecBuffer[i].SetSize(nBufferSize))
- return false;
- }
- cBuffers = nCount;
- pBuffers = (SecBuffer*)spSecBuffer.Detach();
- }
- else // realloc
- {
- CSecBuffer *pSecBuffer = NULL;
- ATLTRY(pSecBuffer = new CSecBuffer[nCount + cBuffers]);
- if (!pSecBuffer)
- return false;
- CAutoVectorPtr<CSecBuffer> spSecBuffer(pSecBuffer);
- Checked::memcpy_s(pSecBuffer, (nCount + cBuffers)*sizeof(CSecBuffer), pBuffers, cBuffers*sizeof(CSecBuffer));
- delete [] pBuffers;
- pBuffers=NULL;
-
- // initialize new buffers
- for (unsigned int i=0; i<nCount; i++)
- {
- if (!pSecBuffer[cBuffers+i].SetSize(nBufferSize))
- return false;
- }
- pBuffers = spSecBuffer.Detach();
- cBuffers += nCount;
- }
- return true;
- }
-
- operator PSecBufferDesc() throw()
- {
- return static_cast<PSecBufferDesc>(this);
- }
-}; // CSecBufferDesc
-
-} // namespace ATL
-
-
-#include <atlhttp.inl>
-
-#pragma pack(pop)
-#pragma warning(pop)
-
-#ifndef __CPPUNWIND
-#pragma warning(pop)
-#endif
-
-#endif // __ATLHTTP_H__
diff --git a/include/atl/atlhttp.inl b/include/atl/atlhttp.inl
deleted file mode 100644
index 71294b49b..000000000
--- a/include/atl/atlhttp.inl
+++ /dev/null
@@ -1,3144 +0,0 @@
-// This is a part of the Active Template Library.
-// Copyright (C) Microsoft Corporation
-// All rights reserved.
-//
-// This source code is only intended as a supplement to the
-// Active Template Library Reference and related
-// electronic documentation provided with the library.
-// See these sources for detailed information regarding the
-// Active Template Library product.
-
-#ifndef __ATLHTTP_INL__
-#define __ATLHTTP_INL__
-
-#include <errno.h>
-
-#pragma warning(push)
-#pragma warning(disable: 4061) // enumerate 'enum value' in switch of enum 'enum type' is not explicitly handled by a case label
-#pragma warning(disable: 4062) // enumerate 'enum value' in switch of enum 'enum type' is not handled
-
-namespace ATL
-{
-
-/////////////////////////////////////////////////////////////////////////////////
-//
-// CAtlHttpClient
-// Implementation of CAtlHttpClient member functions
-//
-/////////////////////////////////////////////////////////////////////////////////
-template <class TSocketClass>
-inline CAtlHttpClientT<TSocketClass>::CAtlHttpClientT() throw()
-{
- InitializeObject();
-}
-
-// Sets this object to a known state.
-template <class TSocketClass>
-inline void CAtlHttpClientT<TSocketClass>::InitializeObject() throw()
-{
- Close(); // will close the socket if it's already open
- ResetRequest();
- SetSilentLogonOk(FALSE);
-}
-
-template <class TSocketClass>
-inline void CAtlHttpClientT<TSocketClass>::ResetRequest() throw()
-{
- // reset all data that has to do with the current request
- m_HeaderMap.RemoveAll();
- m_current.Empty();
- m_urlCurrent.Clear();
- m_strMethod.Empty();
- m_nStatus = ATL_INVALID_STATUS;
- m_dwBodyLen = 0;
- m_dwHeaderLen = 0;
- m_dwHeaderStart = 0;
- m_pCurrent = NULL;
- m_pNavData = NULL;
- m_LastResponseParseError = RR_NOT_READ;
- m_pEnd = NULL;
-
-}
-
-
-// Use this function to retrieve an entity from a server via an HTTP
-// request. This function will either request a connection from the
-// server specified in the szURL parameter or request a connection from
-// the proxy server. If a proxy server is to be used, you must call
-// SetProxy prior to calling this function to specify the proxy server
-// being used. Once the connection is established, an HTTP request
-// is built and sent to the HTTP server. An attempt to read the HTTP
-// response is then made. If the response is successfully read, the
-// response will be parsed and stored in this class instance. The
-// headers can be parsed via the LookupHeader function and the body
-// of the response can be retrieved using the GetBody function. You
-// can also retrieve the contents of the entire response by calling
-// GetResponse.
-template <class TSocketClass>
-inline bool CAtlHttpClientT<TSocketClass>::Navigate(
-
- LPCTSTR szUrl,
- ATL_NAVIGATE_DATA *pNavData
- ) throw(...)
-{
- if (!szUrl || *szUrl == _T('\0'))
- return false;
-
- CUrl url;
- TCHAR szTmp[ATL_URL_MAX_URL_LENGTH];
- if(!AtlEscapeUrl(szUrl,szTmp,0,ATL_URL_MAX_URL_LENGTH-1,ATL_URL_BROWSER_MODE))
- return false;
-
- if(!url.CrackUrl(szTmp))
- return false;
-
- // Navigate
- return Navigate(&url, pNavData);
-}
-
-template <class TSocketClass>
-inline bool CAtlHttpClientT<TSocketClass>::Navigate(
- LPCTSTR szServer,
- LPCTSTR szPath,
- ATL_NAVIGATE_DATA *pNavData
- ) throw(...)
-{
- // Create a URL
- if (!szServer || *szServer == _T('\0'))
- return false;
- if (!szPath || *szPath == _T('\0'))
- return false;
- CUrl url;
- url.SetScheme(ATL_URL_SCHEME_HTTP);
- url.SetHostName(szServer);
- url.SetUrlPath(szPath);
- if (pNavData)
- url.SetPortNumber(pNavData->nPort);
- else
- url.SetPortNumber(ATL_URL_DEFAULT_HTTP_PORT);
-
- TCHAR szUrl[ATL_URL_MAX_URL_LENGTH];
- DWORD dwMaxLen = ATL_URL_MAX_URL_LENGTH;
- if (!url.CreateUrl(szUrl, &dwMaxLen))
- return false;
-
- // Navigate
- return Navigate(szUrl, pNavData);
-}
-
-template <class TSocketClass>
-inline bool CAtlHttpClientT<TSocketClass>::Navigate(
- const CUrl *pUrl,
- ATL_NAVIGATE_DATA *pData
- ) throw(...)
-{
- bool bRet = false;
- if (!pUrl)
- return false;
-
- ResetRequest();
-
- CAtlNavigateData default_nav_data;
- if (!pData)
- m_pNavData = &default_nav_data;
- else
- m_pNavData = pData;
-
- ATLASSUME(m_pNavData);
-
- _ATLTRY
- {
- m_strMethod = m_pNavData->szMethod;
- }
- _ATLCATCHALL()
- {
- return false;
- }
-
- SetSocketTimeout(m_pNavData->dwTimeout);
-
- // set m_urlCurrent
- if (!SetDefaultUrl(pUrl, m_pNavData->nPort))
- return false;
- DWORD dwSent = 0;
- CString strRequest;
- CString strExtraInfo;
-
- if (!BuildRequest(&strRequest,
- m_pNavData->szMethod,
- m_pNavData->szExtraHeaders))
- {
- return false;
- }
-
-
- if (!ConnectSocket())
- return false;
-
- LPCTSTR szTRequest = strRequest;
- CT2CA strARequest(szTRequest);
- DWORD dwRequestLen = (DWORD)strlen(strARequest);
- DWORD dwAvailable = dwRequestLen + m_pNavData->dwDataLen;
-
- if (m_pNavData->dwFlags & ATL_HTTP_FLAG_SEND_CALLBACK)
- {
- dwSent = WriteWithCallback(strARequest, dwRequestLen);
- }
- else if (!m_pNavData->pData)
- dwSent = WriteWithNoData(strARequest, dwRequestLen);
- else if (m_pNavData->pData && (m_pNavData->dwFlags & ATL_HTTP_FLAG_SEND_BLOCKS))
- {
- dwSent = WriteWithChunks(strARequest, dwRequestLen);
- }
- else if(m_pNavData->pData)
- {
- dwSent = WriteWithData(strARequest, dwRequestLen);
- }
-
-
- // make sure everything was sent
- if (dwSent == dwAvailable)
- {
- // Read the response
- if (RR_OK == ReadHttpResponse())
- {
- // if navigation isn't complete, try to complete
- // it based on the status code and flags
- if ((m_pNavData->dwFlags & ATL_HTTP_FLAG_PROCESS_RESULT)&&
- !ProcessStatus(m_pNavData->dwFlags))
- {
- bRet = false;
- }
- else
- bRet = true;
- }
- else
- bRet = false;
- }
-
- if (!bRet)
- Close(); // some kind of failure happened, close the socket.
-
- m_pNavData = NULL;
- return bRet;
-}
-
-template <class TSocketClass>
-inline DWORD CAtlHttpClientT<TSocketClass>::WriteWithNoData(LPCSTR pRequest, DWORD dwRequestLen)
-{
- ATLASSUME(m_pNavData);
- WSABUF Buffer;
- Buffer.buf = (char*)pRequest;
- Buffer.len = (int)dwRequestLen;
- DWORD dwWritten = 0;
- Write(&Buffer, 1, &dwWritten);
- if (m_pNavData->pfnSendStatusCallback)
- m_pNavData->pfnSendStatusCallback(dwWritten, m_pNavData->m_lParamSend);
- return dwWritten;
-}
-
-// The entity body will be retrieved from the client by calling their
-// callback function.
-template <class TSocketClass>
-inline DWORD CAtlHttpClientT<TSocketClass>::WriteWithCallback(LPCSTR pRequest, DWORD dwRequestLen)
-{
- ATLASSUME(m_pNavData);
- if (!(m_pNavData->pfnChunkCallback &&
- (m_pNavData->dwFlags & ATL_HTTP_FLAG_SEND_CALLBACK)))
- return 0; // error, must have flag set and callback function
-
- // write the request
- DWORD dwTotalWritten = 0;
- WSABUF Buffer;
- Buffer.buf = (char*)pRequest;
- Buffer.len = (int)dwRequestLen;
- DWORD dwWritten = 0;
- Write(&Buffer, 1, &dwWritten);
- if (m_pNavData->pfnSendStatusCallback)
- if (!m_pNavData->pfnSendStatusCallback(dwWritten, m_pNavData->m_lParamSend))
- return 0;
- if (!dwWritten)
- return 0; // failure
- dwTotalWritten += dwWritten;
-
- // start writing data;
- while (m_pNavData->pfnChunkCallback((BYTE**)&Buffer.buf, (DWORD*)&Buffer.len, m_pNavData->m_lParamChunkCB) &&
- Buffer.len > 0 &&
- Buffer.buf != NULL)
- {
- Write(&Buffer, 1, &dwWritten);
- if (dwWritten != Buffer.len)
- return 0;
- if (m_pNavData->pfnSendStatusCallback)
- if (!m_pNavData->pfnSendStatusCallback(dwWritten, m_pNavData->m_lParamSend))
- return 0;
- dwTotalWritten += dwWritten;
- }
- return dwTotalWritten;
-}
-
-template <class TSocketClass>
-inline DWORD CAtlHttpClientT<TSocketClass>::WriteWithChunks(LPCSTR pRequest, DWORD dwRequestLen)
-{
- ATLASSUME(m_pNavData);
- if (!(m_pNavData->dwSendBlockSize > 0 && (m_pNavData->dwFlags & ATL_HTTP_FLAG_SEND_BLOCKS)))
- return 0; // error, must have flag set and callback function
-
- // write the request
- DWORD dwTotalWritten = 0;
- WSABUF Buffer;
- Buffer.buf = (char*)pRequest;
- Buffer.len = (int)dwRequestLen;
- DWORD dwWritten = 0;
- Write(&Buffer, 1, &dwWritten);
- if (m_pNavData->pfnSendStatusCallback)
- if (!m_pNavData->pfnSendStatusCallback(dwWritten, m_pNavData->m_lParamSend))
- return 0;
- if (!dwWritten)
- return 0; // failure
- dwTotalWritten += dwWritten;
-
- // start writing data;
- DWORD dwDataWritten = 0;
- DWORD dwDataLeft = m_pNavData->dwDataLen;
- while (dwDataLeft)
- {
- Buffer.buf = (char*)(m_pNavData->pData + dwDataWritten);
- Buffer.len = __min(dwDataLeft, m_pNavData->dwSendBlockSize);
- Write(&Buffer, 1, &dwWritten);
- if (dwWritten != Buffer.len)
- return 0;
- if (m_pNavData->pfnSendStatusCallback)
- if (!m_pNavData->pfnSendStatusCallback(dwWritten, m_pNavData->m_lParamSend))
- return false;
- dwTotalWritten += dwWritten;
- dwDataWritten += dwWritten;
- dwDataLeft -= dwWritten;
- }
- return dwTotalWritten;
-}
-
-template <class TSocketClass>
-inline DWORD CAtlHttpClientT<TSocketClass>::WriteWithData(LPCSTR pRequest, DWORD dwRequestLen)
-{
- WSABUF Buffers[2];
- Buffers[0].buf = (char*)pRequest;
- Buffers[0].len = dwRequestLen;
- Buffers[1].buf = (char*)m_pNavData->pData;
- Buffers[1].len = m_pNavData->dwDataLen;
-
- DWORD dwWritten = 0;
- Write(Buffers, 2, &dwWritten);
- if (m_pNavData->pfnSendStatusCallback)
- m_pNavData->pfnSendStatusCallback(dwWritten, m_pNavData->m_lParamSend);
-
- return dwWritten;
-}
-
-template <class TSocketClass>
-bool CAtlHttpClientT<TSocketClass>::NavigateChunked(
- LPCTSTR szServer,
- LPCTSTR szPath,
- ATL_NAVIGATE_DATA *pNavData
- ) throw()
-{
- // Create a URL
- if (!szServer || *szServer == _T('\0'))
- return false;
- if (!szPath || *szPath == _T('\0'))
- return false;
-
- if (!pNavData)
- {
- // To do chunked navigation you must specify an
- // ATL_NAVIGATE_DATA structure that has the pfnChunkCallback
- // member filled out.
- ATLASSERT(FALSE);
- return false;
- }
- CUrl url;
- url.SetScheme(ATL_URL_SCHEME_HTTP);
- url.SetHostName(szServer);
- url.SetUrlPath(szPath);
- if (pNavData)
- url.SetPortNumber(pNavData->nPort);
- else
- url.SetPortNumber(ATL_URL_DEFAULT_HTTP_PORT);
-
- TCHAR szUrl[ATL_URL_MAX_URL_LENGTH];
- DWORD dwMaxLen = ATL_URL_MAX_URL_LENGTH;
- if (!url.CreateUrl(szUrl, &dwMaxLen))
- return false;
-
- // Navigate
- return NavigateChunked(szUrl, pNavData);
-}
-
-template <class TSocketClass>
-bool CAtlHttpClientT<TSocketClass>::NavigateChunked(
- LPCTSTR szURL,
- ATL_NAVIGATE_DATA *pNavData
- ) throw()
-{
- if (!szURL || *szURL == _T('\0'))
- return false;
-
- ResetRequest();
-
- ATLASSERT(pNavData);
-
- CUrl url;
- if (!url.CrackUrl(szURL))
- return false;
-
- // Navigate
- return NavigateChunked(&url, pNavData);
-}
-
-template <class TSocketClass>
-inline bool CAtlHttpClientT<TSocketClass>::NavigateChunked(
- const CUrl *pUrl,
- ATL_NAVIGATE_DATA *pNavData
- ) throw()
-{
- if (!pUrl)
- return false;
-
- if (!pNavData)
- {
- // To do chunked navigation you must specify an
- // ATL_NAVIGATE_DATA structure that has the pfnChunkCallback
- // member filled out.
- ATLASSERT(FALSE);
- return false;
- }
-
- m_pNavData = pNavData;
- if (!pNavData->pfnChunkCallback)
- return false;
-
- bool bRet = true;
-
- _ATLTRY
- {
- m_strMethod = m_pNavData->szMethod;
- }
- _ATLCATCHALL()
- {
- return false;
- }
-
- SetSocketTimeout(m_pNavData->dwTimeout);
-
- // set m_urlCurrent
- if (!SetDefaultUrl(pUrl, m_pNavData->nPort))
- return false;
-
-
- DWORD dwSent = 0;
- CString strRequest;
- CString strExtraInfo;
-
- if (!BuildRequest(&strRequest,
- m_pNavData->szMethod,
- m_pNavData->szExtraHeaders // extra headers
- ))
- {
- return false;
- }
-
- if (!ConnectSocket())
- return false;
-
- WSABUF Buffers[3];
-
- _ATLTRY
- {
- CT2A pRequest(strRequest);
-
- Buffers[0].buf = (char*)pRequest;
- Buffers[0].len = strRequest.GetLength();
-
- // send the first buffer which is the request
- if (!Write(Buffers, 1, &dwSent))
- {
- Close();
- return false;
- }
- }
- _ATLCATCHALL()
- {
- Close();
- return false;
- }
- Buffers[0].buf = NULL;
- Buffers[0].len = 0;
-
- CStringA strChunkSize;
-
- Buffers[2].buf = "\r\n";
- Buffers[2].len = 2;
- int z = 0;
-
- // start sending the chunks
- do
- {
- z++;
- Buffers[1].buf = NULL;
- Buffers[1].len = 0;
- if (m_pNavData->pfnChunkCallback((BYTE**)&Buffers[1].buf, &Buffers[1].len,
- m_pNavData->m_lParamChunkCB))
- {
- _ATLTRY
- {
- if (Buffers[1].len > 0)
- {
- // send the chunk
- strChunkSize.Format("%x\r\n", Buffers[1].len);
- Buffers[0].buf = (char*)(LPCSTR)strChunkSize;
- Buffers[0].len = strChunkSize.GetLength();
- if (!Write(Buffers, 3, &dwSent))
- {
- bRet = false;
- break;
- }
- }
- else if (Buffers[1].len == 0)
- {
- strChunkSize = "0\r\n\r\n\r\n";
- Buffers[0].buf = (char*)(LPCSTR)strChunkSize;
- Buffers[0].len = strChunkSize.GetLength();
- if (!Write(Buffers, 1, &dwSent))
- {
- bRet = false;
- break;
- }
- break;
- }
- }
- _ATLCATCHALL()
- {
- bRet = false;
- break;
- }
- }
- else
- {
- bRet = false;
- break; // something went wrong in callback
- }
- }while (Buffers[1].len > 0);
-
- strRequest.ReleaseBuffer();
-
- if (bRet)
- {
- // Read the response
- if (RR_OK == ReadHttpResponse())
- {
- // if navigation isn't complete, try to complete
- // it based on the status code and flags
- if ((m_pNavData->dwFlags & ATL_HTTP_FLAG_PROCESS_RESULT)
- && !ProcessStatus(m_pNavData->dwFlags))
- {
- bRet = false;
- }
- bRet = true;
- }
- else
- bRet = false;
- }
-
- if (!bRet)
- Close();
-
- return bRet;
-}
-
-template <class TSocketClass>
-inline bool CAtlHttpClientT<TSocketClass>::ConnectSocket() throw()
-{
- bool bRet=false;
- // connect to the correct server
- if (GetProxy())
- {
- //if we're using a proxy connect to the proxy
- bRet=Connect(m_strProxy, m_nProxyPort);
- }
- else
- {
- bRet=Connect(m_urlCurrent.GetHostName(),m_urlCurrent.GetPortNumber()); // connect to the server
- }
- return bRet;
-}
-
-
-template <class TSocketClass>
-inline bool CAtlHttpClientT<TSocketClass>::BuildRequest(/*out*/CString *pstrRequest,
- LPCTSTR szMethod,
- LPCTSTR szExtraHeaders) throw()
-{
- if (!m_pNavData)
- return false;
- _ATLTRY
- {
- // build up the request
- CString strRequest = szMethod;
- strRequest += _T(" ");
- if (GetProxy())
- {
- TCHAR buffURL[ATL_URL_MAX_URL_LENGTH];
- DWORD dwSize = ATL_URL_MAX_URL_LENGTH;
- m_urlCurrent.CreateUrl(buffURL, &dwSize);
- strRequest += buffURL;
-
- strRequest += ATL_HTTP_HEADER_PROXY;
- CString strHost;
- if (m_urlCurrent.GetPortNumber() != ATL_URL_DEFAULT_HTTP_PORT)
- strHost.Format(_T("Host: %s:%d\r\n"), m_urlCurrent.GetHostName(), m_urlCurrent.GetPortNumber());
- else
- strHost.Format(_T("Host: %s\r\n"), m_urlCurrent.GetHostName());
- strRequest += strHost;
-
- if (m_pNavData->dwDataLen>0)
- {
- CString strCL;
- strCL.Format(_T("Content-Length: %d\r\n"), m_pNavData->dwDataLen);
- strRequest += strCL;
- }
-
- if (m_pNavData->szDataType)
- {
- strRequest += _T("Content-Type: ");
- strRequest += m_pNavData->szDataType;
- strRequest += _T("\r\n");
- }
-
- if (m_pNavData->szExtraHeaders)
- strRequest += szExtraHeaders;
- strRequest += ATL_HTTP_USERAGENT;
- }
- else
- {
- strRequest += m_urlCurrent.GetUrlPath();
- strRequest += m_urlCurrent.GetExtraInfo();
- strRequest += ATL_HTTP_HEADER;
-
- if (m_pNavData->dwDataLen > 0)
- {
- CString strCL;
- strCL.Format(_T("Content-Length: %d\r\n"), m_pNavData->dwDataLen);
- strRequest += strCL;
- }
-
- if (m_pNavData->szDataType &&
- *m_pNavData->szDataType)
- {
- strRequest += _T("Content-Type: ");
- strRequest += m_pNavData->szDataType;
- strRequest += _T("\r\n");
- }
-
- if (szExtraHeaders)
- strRequest += szExtraHeaders;
-
-
- CString strHost;
- strHost.Format(_T("Host: %s\r\n"), m_urlCurrent.GetHostName());
- strRequest += strHost;
- strRequest += ATL_HTTP_USERAGENT;
- }
- strRequest += _T("\r\n");
-
-
- *pstrRequest = strRequest;
- return true;
- }
- _ATLCATCHALL()
- {
- return false;
- }
-}
-
-template <class TSocketClass>
-inline bool CAtlHttpClientT<TSocketClass>::ReadSocket() throw()
-{
- bool bRet = false;
- unsigned char read_buff[ATL_READ_BUFF_SIZE];
- int dwSize = ATL_READ_BUFF_SIZE;
-
- // read some data
- for (int i = 0; i < ATL_HTTP_CLIENT_EMPTY_READ_RETRIES; ++i)
- {
- bRet = Read(read_buff, (DWORD*)&dwSize);
- if (!bRet)
- return bRet;
-
- // notify user
- if (m_pNavData)
- {
- if (m_pNavData->pfnReadStatusCallback)
- bRet = m_pNavData->pfnReadStatusCallback(dwSize, m_pNavData->m_lParamRead);
- if (!bRet)
- return bRet;
- }
-
- if (dwSize > 0)
- {
- // append the data to our internal buffer
- // m_current holds bytes (not UNICODE!)
-
- if (!m_current.Append((LPCSTR)read_buff, dwSize))
- return FALSE;
-
- m_pEnd = ((BYTE*)(LPCSTR)m_current) + m_current.GetLength();
- m_pCurrent = (BYTE*)(LPCSTR)m_current;
- break;
- }
- bRet = false; // nothing was read
- }
-
- return bRet;
-}
-
-// Starts searching for a complete header set at
-// m_pCurrent. This function will only move m_pCurrent
-// if a complete set is found. Returns the header beginning
-// optionally.
-template <class TSocketClass>
-inline unsigned char* CAtlHttpClientT<TSocketClass>::FindHeaderEnd(unsigned char** ppBegin) throw()
-{
- if (!m_pCurrent)
- return NULL;
-
- BYTE *pCurr = m_pCurrent;
- BYTE *pBegin = m_pCurrent;
- int nLen = m_current.GetLength();
-
- if (pCurr >= (BYTE*)(LPCSTR)m_current + m_current.GetLength())
- return NULL; // no more chars in buffer
- // look for the end of the header (the \r\n\r\n)
- while (pCurr <= (pBegin + nLen - ATL_HEADER_END_LEN))
- {
-
- if (* ((UNALIGNED DWORD*)pCurr)==ATL_DW_HEADER_END)
- {
- // set m_pCurrent pointer to the end of the header
- m_pCurrent = pCurr + ATL_HEADER_END_LEN;
- if (ppBegin)
- *ppBegin = pBegin;
- return m_pCurrent;
- }
- pCurr++;
- }
- return NULL;
-}
-
-// Call this function after sending an HTTP request over the socket. The complete
-// HTTP response will be read. This function will also parse
-// response headers into the response header map.
-template <class TSocketClass>
-inline typename CAtlHttpClientT<TSocketClass>::HTTP_RESPONSE_READ_STATUS CAtlHttpClientT<TSocketClass>::ReadHttpResponse()
-{
- // Read until we at least have the response headers
- HTTP_RESPONSE_READ_STATUS result = RR_OK;
- readstate state = rs_init;
- unsigned char *pBodyBegin = NULL;
- unsigned char *pHeaderBegin = NULL;
- m_current.Empty();
- m_pCurrent = NULL;
- m_LastResponseParseError = RR_OK;
-
- while (state != rs_complete)
- {
- switch(state)
- {
- case rs_init:
- m_HeaderMap.RemoveAll();
- m_nStatus = ATL_INVALID_STATUS;
- m_dwHeaderLen = 0;
- m_dwBodyLen = 0;
- state = rs_readheader;
- // fall through
-
- case rs_readheader:
-
- // read from the socket until we have a complete set of headers.
- pBodyBegin = FindHeaderEnd(&pHeaderBegin);
- if (!pBodyBegin)
- {
- if (!ReadSocket())
- {
- // Either reading from the socket failed, or there
- // was not data to read. Set the nav status to error
- // and change the state to complete.
- state = rs_complete;
- result = RR_READSOCKET_FAILED;
- break;
- }
- else
- break; // loop back and FindHeaderEnd again.
- }
- // we have a complete set of headers
- m_dwHeaderLen = (DWORD)(pBodyBegin-pHeaderBegin);
- m_dwHeaderStart = (DWORD)(pHeaderBegin - (BYTE*)(LPCSTR)m_current);
- // fall through
- state = rs_scanheader;
-
- case rs_scanheader:
- // set m_nStatus and check for valid status
- ParseStatusLine(pHeaderBegin);
- // failed to set m_nStatus;
- if (m_nStatus == ATL_INVALID_STATUS)
- {
- state = rs_complete;
- result = RR_STATUS_INVALID;
- break;
- }
-
- else if (m_nStatus == 100) // continue
- {
- state = rs_init;
- break;
- }
-
- // crack all the headers and put them into a header map. We've already
- // done the check to make sure we have a complete set of headers in
- // rs_readheader above
- if (ATL_HEADER_PARSE_COMPLETE != CrackResponseHeader((LPCSTR)pHeaderBegin,
- (LPCSTR*)&pBodyBegin))
- {
- // something bad happened while parsing the headers!
- state = rs_complete;
- result = RR_PARSEHEADERS_FAILED;
- break;
- }
- state = rs_readbody;
- // fall through
-
- case rs_readbody:
- // headers are parsed and cracked, we're ready to read the rest
- // of the response.
- if (IsMsgBodyChunked())
- {
- if (!ReadChunkedBody())
- {
- result = RR_READCHUNKEDBODY_FAILED;
- state = rs_complete;
- break;
- }
- }
- else
- if (!ReadBody(GetContentLength(), m_current.GetLength()-(m_dwHeaderStart+m_dwHeaderLen)))
- result = RR_READBODY_FAILED;
- state = rs_complete;
- //fall through
-
- case rs_complete:
- // clean up the connection if the server requested a close;
- DisconnectIfRequired();
- break;
- }
- }
- m_LastResponseParseError = result;
- return result;
-}
-
-template <class TSocketClass>
-inline typename CAtlHttpClientT<TSocketClass>::HTTP_RESPONSE_READ_STATUS CAtlHttpClientT<TSocketClass>::GetResponseStatus()
-{
- return m_LastResponseParseError;
-}
-
-// Checks to see if the server has closed the connection.
-// If it has, we create a new socket and reconnect it to
-// the current server. This also clears the contents of the
-// current response buffer.
-template <class TSocketClass>
-inline void CAtlHttpClientT<TSocketClass>::ResetConnection() throw()
-{
- ReconnectIfRequired();
- m_HeaderMap.RemoveAll();
- m_current.Empty();
- m_nStatus = ATL_INVALID_STATUS;
- m_AuthTypes.RemoveAll(); // the server will keep sending back www-authenticate
- // headers until the connection is authorized
-}
-
-// Takes action based on the flags passed and the current
-// status for this object.
-template <class TSocketClass>
-inline bool CAtlHttpClientT<TSocketClass>::ProcessStatus(DWORD dwFlags) throw()
-{
- switch(m_nStatus)
- {
- case 200: // In all these cases there is no further action
- case 201: // to take. Any additional informaion is returned
- case 202: // in the entity body.
- case 203:
- case 204:
- case 205:
- case 206:
- case 304:
- case 305:
- return true;
- break;
- case 301:
- case 302:
- case 303:
- if (dwFlags & ATL_HTTP_FLAG_AUTO_REDIRECT)
- return ProcessObjectMoved();
- break;
- case 401: // auth required
- return NegotiateAuth(false);
- break;
- case 407: // proxy auth required
- return NegotiateAuth(true);
- break;
-
- }
- return false;
-}
-
-// Looks up the value of a response header in the header map. Call with
-// NULL szBuffer to have length of the required buffer placed in
-// pdwLen on output.
-
-// szName is the name of the header to look up.
-// szBuffer is the buffer that will contain the looked up string.
-// pdwLen contains the length of szBuffer in characters on input and the length
-// of the string including NULL terminator in characters on output.
-template<class TSocketClass>
-inline bool CAtlHttpClientT<TSocketClass>::GetHeaderValue(LPCTSTR szName, CString& strValue) const throw()
-{
- _ATLTRY
- {
- return m_HeaderMap.Lookup(szName, strValue);
- }
- _ATLCATCHALL()
- {
- return false;
- }
-}
-
-template<class TSocketClass>
-inline bool CAtlHttpClientT<TSocketClass>::GetHeaderValue(__in_z LPCTSTR szName, __out_ecount_part_z_opt(*pdwLen, *pdwLen) LPTSTR szBuffer, __inout DWORD *pdwLen) const throw()
-{
- CString strValue;
- bool bRet = GetHeaderValue(szName, strValue);
- DWORD nLen = strValue.GetLength();
- if (!bRet)
- return false;
-
- if ((pdwLen && *pdwLen < nLen+1) ||
- (!szBuffer && pdwLen) )
- {
- *pdwLen = nLen+1;
- return true;
- }
-
- if (!szBuffer)
- return false;
-
- Checked::tcsncpy_s(szBuffer, nLen+1, (LPCTSTR)strValue, _TRUNCATE);
- if (pdwLen)
- *pdwLen = nLen+1;
- return true;
-}
-
-// Adds an authorization object to use for a particular scheme.
-// This will overwrite an existing entry if an object for the
-// same scheme has already been set.
-template<class TSocketClass>
-inline bool CAtlHttpClientT<TSocketClass>::AddAuthObj(LPCTSTR szScheme,
- CAtlBaseAuthObject *pObject, IAuthInfo *pInfo/*=NULL*/) throw()
-{
- if (!pObject)
- return false;
-
- pObject->Init(this, pInfo);
-
- _ATLTRY
- {
- POSITION pos = m_AuthMap.SetAt(szScheme, pObject);
- if (!pos)
- return false;
- }
- _ATLCATCHALL()
- {
- return false;
- }
-
- return true;
-}
-
-// Tries to find an authorization object to use for a particular
-// scheme
-template<class TSocketClass>
-inline const CAtlBaseAuthObject* CAtlHttpClientT<TSocketClass>::FindAuthObject(LPCTSTR szScheme) throw()
-{
- CAtlBaseAuthObject *pObject = NULL;
- if (m_AuthMap.Lookup(szScheme, pObject))
- {
- return const_cast<const CAtlBaseAuthObject*>(pObject);
- }
- return NULL;
-}
-
-// Removes an existing authorization object from the map.
-template<class TSocketClass>
-inline bool CAtlHttpClientT<TSocketClass>::RemoveAuthObject(LPCTSTR szScheme) throw()
-{
- return m_AuthMap.RemoveKey(szScheme);
-}
-
-// Sets the current proxy server and port
-template<class TSocketClass>
-inline bool CAtlHttpClientT<TSocketClass>::SetProxy(LPCTSTR szProxy, short nProxyPort) throw()
-{
- if (!szProxy)
- {
- if (!LookupRegProxy())
- return false;
- }
- else
- {
- _ATLTRY
- {
- m_strProxy = szProxy;
- m_nProxyPort = nProxyPort;
- }
- _ATLCATCHALL()
- {
- return false;
- }
- }
- return true;
-}
-
-// Removes the current proxy settings.
-template<class TSocketClass>
-inline void CAtlHttpClientT<TSocketClass>::RemoveProxy() throw()
-{
- m_strProxy.Empty();
- m_nProxyPort = ATL_URL_INVALID_PORT_NUMBER;
-}
-
-// retrieves the current proxy
-template<class TSocketClass>
-inline LPCTSTR CAtlHttpClientT<TSocketClass>::GetProxy() const throw()
-{
- if (m_strProxy.GetLength())
- return (LPCTSTR)m_strProxy;
- return NULL;
-}
-
-template<class TSocketClass>
-inline short CAtlHttpClientT<TSocketClass>::GetProxyPort() const throw()
-{
- return m_nProxyPort;
-}
-
-// Gets the contents of the entire response buffer.
-template<class TSocketClass>
-inline const BYTE* CAtlHttpClientT<TSocketClass>::GetResponse() throw()
-{
- return (const BYTE*)(LPCSTR)m_current;
-}
-
-template<class TSocketClass>
-inline DWORD CAtlHttpClientT<TSocketClass>::GetResponseLength() throw()
-{
- return m_current.GetLength();
-}
-
-// Gets the length in bytes of the body of the
-// current response
-template<class TSocketClass>
-inline DWORD CAtlHttpClientT<TSocketClass>::GetBodyLength() const throw()
-{
- return m_dwBodyLen;
-}
-
-// Gets the contents of the body of the current response. This
-// is the response without the headers.
-template<class TSocketClass>
-inline const BYTE* CAtlHttpClientT<TSocketClass>::GetBody() throw()
-{
- return (BYTE*)((LPCSTR)m_current + m_dwHeaderLen + m_dwHeaderStart);
-}
-
-// Get the length of the header part of the response in bytes.
-template<class TSocketClass>
-inline DWORD CAtlHttpClientT<TSocketClass>::GetRawResponseHeaderLength() throw()
-{
- return m_dwHeaderLen >= 2 ? m_dwHeaderLen-2 : 0; // m_dwHeaderLen includes the final \r\n
-}
-
-// buffer must include space for null terminator.
-// on input, pdwLen specifies the size of szBuffer,
-// on output, pdwLen holds the number of bytes copied
-// to szBuffer, or the required size of szBuffer if
-// szBuffer wasn't big enough
-template<class TSocketClass>
-inline bool CAtlHttpClientT<TSocketClass>::GetRawResponseHeader(LPBYTE szBuffer, DWORD *pdwLen) throw()
-{
- if (!pdwLen)
- return false;
-
- DWORD header_len = GetRawResponseHeaderLength();
- if (header_len == 0)
- return false;
-
- if (!szBuffer || *pdwLen < header_len+1)
- {
- *pdwLen = header_len+1;
- return false;
- }
-
- Checked::memcpy_s(szBuffer, *pdwLen, (BYTE*)(LPCSTR)m_current, header_len);
- szBuffer[header_len]='\0';
-
- *pdwLen = header_len+1;
- return true;
-}
-
-// Gets the current URL object.
-template<class TSocketClass>
-inline LPCURL CAtlHttpClientT<TSocketClass>::GetCurrentUrl() const throw()
-{
- return (LPCURL)&m_urlCurrent;
-}
-
-template<class TSocketClass>
-inline bool CAtlHttpClientT<TSocketClass>::SetDefaultUrl( LPCTSTR szUrl,
- short nPortNumber) throw()
-{
- return _SetDefaultUrl(szUrl,nPortNumber);
-}
-
-template<class TSocketClass>
-inline bool CAtlHttpClientT<TSocketClass>::SetDefaultUrl( LPCURL pUrl,
- short nPortNumber) throw()
-{
- m_urlCurrent = *pUrl;
- return _SetDefaultUrl(NULL, nPortNumber);
-}
-
-template<class TSocketClass>
-inline bool CAtlHttpClientT<TSocketClass>::SetDefaultMethod(LPCTSTR szMethod) throw()
-
-{
- _ATLTRY
- {
- m_strMethod = szMethod;
- return true;
- }
- _ATLCATCHALL()
- {
- return false;
- }
-}
-
-template<class TSocketClass>
-inline DWORD CAtlHttpClientT<TSocketClass>::GetFlags() const throw()
-{
- if (m_pNavData)
- return m_pNavData->dwFlags;
- else
- return ATL_HTTP_FLAG_INVALID_FLAGS;
-}
-
-template<class TSocketClass>
-inline bool CAtlHttpClientT<TSocketClass>::LookupRegProxy() throw()
-{
- // attempt to look it up from the registry
- CRegKey rkProxy;
- ULONG nChars = ATL_URL_MAX_URL_LENGTH+1;
- TCHAR szUrl[ATL_URL_MAX_URL_LENGTH+1] = { 0 };
-
- DWORD dwErr = rkProxy.Open(HKEY_CURRENT_USER,
- _T("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"), KEY_READ);
- if (dwErr == ERROR_SUCCESS)
- {
- dwErr = rkProxy.QueryStringValue(_T("ProxyServer"), szUrl, &nChars);
- }
- if (dwErr == ERROR_SUCCESS)
- {
- CUrl url;
- if (url.CrackUrl(szUrl))
- {
- if (url.GetScheme()==ATL_URL_SCHEME_UNKNOWN)
- {
- // without the scheme name (e.g. proxy:80)
- m_strProxy = url.GetSchemeName();
- m_nProxyPort = (short)_ttoi(url.GetHostName());
- return true;
- }
- else if (url.GetHostName())
- {
- // with the scheme (e.g. http://proxy:80)
- m_strProxy = url.GetHostName();
- m_nProxyPort = url.GetPortNumber();
- return true;
- }
- }
- }
- return false;
-}
-
-template<class TSocketClass>
-inline bool CAtlHttpClientT<TSocketClass>::DisconnectIfRequired() throw()
-{
- CString strValue;
- if (GetHeaderValue(_T("Connection"), strValue) && !strValue.CompareNoCase(_T("close")))
- {
- Close();
- }
-
- return true;
-}
-
-class CInitializeCOMThread
-{
-public:
- CInitializeCOMThread()
- : m_bCoInit(FALSE),m_bShouldUninit(FALSE)
- {
- //At this point the Thread can be uninit, init to STA or init to MTA.
- //CoInitialize can always fail unexpectedly.
- HRESULT hr = ::CoInitialize(NULL);
- if (SUCCEEDED(hr))
- {
- m_bCoInit=TRUE;
- m_bShouldUninit=TRUE;
- } else if (hr == RPC_E_CHANGED_MODE)
- {
- m_bCoInit=TRUE;
- }
- }
- ~CInitializeCOMThread()
- {
- if (m_bShouldUninit)
- {
- ::CoUninitialize();
- }
- }
- BOOL IsInitialized() { return m_bCoInit; }
-protected:
- BOOL m_bCoInit;
- BOOL m_bShouldUninit;
-};
-// Tries to find an authorization object that meets
-template<class TSocketClass>
-inline bool CAtlHttpClientT<TSocketClass>::NegotiateAuth(bool bProxy) throw()
-{
- //Test if can silently pass user credentials to server.
- if (!m_bSilentLogonOk)
- {
- //Call CoInit, because ATL Http code cannot assume it has already been called by the user.
- CInitializeCOMThread initThread;
- if (initThread.IsInitialized())
- {
- HRESULT hr = S_OK;
- CComPtr<IInternetSecurityManager> spSecurityMgr;
-
- hr = CoCreateInstance(CLSID_InternetSecurityManager, NULL, CLSCTX_INPROC_SERVER,
- IID_IInternetSecurityManager, (void**)&spSecurityMgr);
- if (SUCCEEDED(hr))
- {
- TCHAR szUrl[ATL_URL_MAX_URL_LENGTH];
- DWORD dwMaxLen = ATL_URL_MAX_URL_LENGTH;
- if (!m_urlCurrent.CreateUrl(szUrl, &dwMaxLen))
- {
- return false;
- }
-
- CStringW strUrlW(szUrl);
- DWORD dwPolicy=0xFFFF;
- hr=spSecurityMgr->ProcessUrlAction(strUrlW.GetString(),
- URLACTION_CREDENTIALS_USE,
- reinterpret_cast<BYTE*>(&dwPolicy),
- sizeof(dwPolicy),
- NULL,
- 0,
- PUAF_NOUI,
- NULL);
-
- if (FAILED(hr) || dwPolicy != URLPOLICY_CREDENTIALS_SILENT_LOGON_OK)
- {
- return false;
- }
- }
- else
- {
- // CoCreateInstance failed, return false
- return false;
- }
- }
- else
- {
- // CoInit failed, return false
- return false;
- }
- }
-
- // szAuthHeaderValue should contain a comma separated list
- // of authentication types
- CAtlBaseAuthObject *pAuthObj = NULL;
- bool bRet = false;
- for (size_t i = 0; i<m_AuthTypes.GetCount(); i++)
- {
- _ATLTRY
- {
- CString strName = m_AuthTypes[i];
- int nSpace = strName.Find(_T(' '));
- if (nSpace!=-1)
- strName.SetAt(nSpace,0);
-
- if (m_AuthMap.Lookup(strName, pAuthObj) &&
- !pAuthObj->m_bFailed)
- bRet = pAuthObj->Authenticate(m_AuthTypes[i], bProxy);
-
- if (bRet)
- return bRet;
- }
- _ATLCATCHALL()
- {
- bRet = false;
- }
- }
- return bRet;
-}
-
-template<class TSocketClass>
-inline long CAtlHttpClientT<TSocketClass>::GetContentLength() throw()
-{
- CString strValue;
- if (GetHeaderValue(_T("Content-Length"), strValue))
- {
- TCHAR *pStop = NULL;
- return _tcstol(strValue, &pStop, 10);
- }
- else
- return -1;
-}
-
-template<class TSocketClass>
-inline LPCSTR CAtlHttpClientT<TSocketClass>::NextLine(BYTE* pCurr) throw()
-{
- if (!pCurr)
- return NULL;
-
- while ( pCurr < m_pEnd && *pCurr && !(*pCurr == '\r' && *(pCurr+1) == '\n'))
- pCurr++;
-
- if (pCurr >= m_pEnd)
- return NULL;
-
-// if (pCurr < m_pEnd-4)
-// if (!memcmp(pCurr, ATL_HEADER_END, 4))
- //return NULL;
-
- return (LPCSTR)(pCurr+2);
-}
-
-template<class TSocketClass>
-inline bool CAtlHttpClientT<TSocketClass>::IsMsgBodyChunked() throw()
-{
- CString strValue;
- return (
- GetHeaderValue(_T("Transfer-Encoding"), strValue) &&
- !strValue.CompareNoCase(_T("chunked"))
- );
-
-}
-
-// finds the end of an individual header field pointed to by
-// pszStart. Header fields can be multi-line with multi-line
-// header fields being a line that starts with some kind of
-// white space.
-template<class TSocketClass>
-inline LPCSTR CAtlHttpClientT<TSocketClass>::FindEndOfHeader(LPCSTR pszStart) throw()
-{
- // move through all the lines until we come to one
- // that doesn't start with white space
- LPCSTR pLineStart = pszStart;
- LPCSTR pHeaderEnd = NULL;
-
- do
- {
- pLineStart = NextLine((BYTE*)pLineStart);
- }while (pLineStart && isspace(static_cast<unsigned char>(*pLineStart)) && strncmp(pLineStart-2, ATL_HEADER_END, ATL_HEADER_END_LEN));
-
- if (pLineStart > (LPCSTR)m_pEnd)
- return NULL; // ran out of data in the buffer without finding the end of a line
- // or the end of the headers.
-
- if (pLineStart)
- pHeaderEnd = pLineStart-2;
- else
- pHeaderEnd = NULL;
-
- return pHeaderEnd;
-}
-
-template<class TSocketClass>
-inline bool CAtlHttpClientT<TSocketClass>::DecodeHeader(LPCSTR pHeaderStart, LPCSTR pHeaderEnd) throw()
-{
- _ATLTRY
- {
- if (!pHeaderStart || !pHeaderEnd)
- return false;
- LPCSTR pTemp = pHeaderStart;
- while (*pTemp != ATL_FIELDNAME_DELIMITER && pTemp < pHeaderEnd)
- pTemp++;
- if (*pTemp == ATL_FIELDNAME_DELIMITER)
- {
- char szName[ATL_MAX_FIELDNAME_LEN];
- char szValue[ATL_MAX_VALUE_LEN];
- int nLen = (int)(pTemp-pHeaderStart) ;
- ATLASSERT(nLen < ATL_MAX_FIELDNAME_LEN);
- if (nLen >= ATL_MAX_FIELDNAME_LEN)
- return false; // won't fit in the buffer.
- Checked::memcpy_s(szName, ATL_MAX_FIELDNAME_LEN, pHeaderStart, nLen);
- szName[nLen]=0;
-
- pTemp++; // move past delimiter;
- while (isspace(static_cast<unsigned char>(*pTemp)) && pTemp < pHeaderEnd)
- pTemp++;
-
- nLen = (int)(pHeaderEnd-pTemp);
- ATLASSERT(nLen < ATL_MAX_VALUE_LEN);
- if (nLen >= ATL_MAX_VALUE_LEN)
- return false; // won't fit in the buffer
- Checked::memcpy_s(szValue, ATL_MAX_VALUE_LEN, pTemp, nLen);
- szValue[nLen]=0;
-
- CString strExist;
- CA2T pszName(szName);
- CA2T pszValue(szValue);
-
- if (!_tcsicmp(pszName, _T("www-authenticate")) ||
- !_tcsicmp(pszName, _T("proxy-authenticate")))
- {
- m_AuthTypes.Add(pszValue);
- }
-
- if (!m_HeaderMap.Lookup(pszName, strExist))
- m_HeaderMap.SetAt(pszName, pszValue);
- else
- {
- // field-values for headers with the same name can be appended
- // per rfc2068 4.2, we do the appending so we don't have to
- // store/lookup duplicate keys.
- strExist += ',';
- strExist += pszValue;
- m_HeaderMap.SetAt(pszName, (LPCTSTR)strExist);
- }
-
- // if it's a set-cookie header notify users so they can do
- // somthing with it.
- if (!_tcsicmp(pszName, _T("set-cookie")))
- OnSetCookie(pszValue);
- }
-
- return true;
- }
- _ATLCATCHALL()
- {
- return false;
- }
-}
-
-template<class TSocketClass>
-inline void CAtlHttpClientT<TSocketClass>::OnSetCookie(LPCTSTR) throw()
-{
- return;
-}
-
-template<class TSocketClass>
-inline LPCSTR CAtlHttpClientT<TSocketClass>::ParseStatusLine(BYTE* pBuffer) throw()
-{
- if (!pBuffer)
- return NULL;
- if (m_pEnd <= pBuffer)
- return NULL;
-
- // find the first space'
- while (pBuffer < m_pEnd && !isspace(static_cast<unsigned char>(*pBuffer)))
- pBuffer++;
-
- if (pBuffer >= m_pEnd)
- return NULL;
-
- // move past the space
- while (pBuffer < m_pEnd && isspace(static_cast<unsigned char>(*pBuffer)))
- pBuffer++;
-
- if (pBuffer >= m_pEnd)
- return NULL;
-
- // pBuffer better be pointing at the status code now
- LPCSTR pEnd = NULL;
- if (*pBuffer >= '0' && *pBuffer <= '9')
- {
- // probably a good status code
- errno_t errnoValue = AtlStrToNum(&m_nStatus, (LPSTR)pBuffer, (LPSTR*)&pEnd, 10);
- if (errnoValue == ERANGE)
- return NULL; // bad status code
- }
- else
- return FALSE; // bad status code;
-
- if (!pEnd)
- return FALSE; // bad status code;
-
- pBuffer = (BYTE*)pEnd;
- // move to end of line
- while (pBuffer < m_pEnd && *pBuffer != '\n')
- pBuffer++;
-
- if (pBuffer >= m_pEnd)
- return NULL;
-
- // set the return pointing to the first
- // character after our status line.
- return (LPCSTR)++pBuffer;
-}
-
-
-// pBuffer should start at the first character
-// after the status line.
-template<class TSocketClass>
-inline int CAtlHttpClientT<TSocketClass>::CrackResponseHeader(LPCSTR pBuffer, /*out*/ LPCSTR *pEnd) throw()
-{
- // read up to the double /r/n
- LPCSTR pszStartSearch = pBuffer;
- if (!pEnd)
- return ATL_HEADER_PARSE_HEADERERROR;
-
- *pEnd = NULL;
- if (pszStartSearch == NULL)
- return ATL_HEADER_PARSE_HEADERERROR;
-
- // start parsing headers
- LPCSTR pHeaderStart = ParseStatusLine((BYTE*)pBuffer);
- if (!pHeaderStart)
- return ATL_HEADER_PARSE_HEADERERROR;
- LPCSTR pHeaderEnd = NULL;
-
- while (pHeaderStart && *pHeaderStart && pHeaderStart < (LPCSTR)m_pEnd)
- {
- pHeaderEnd = FindEndOfHeader(pHeaderStart);
- if (!pHeaderEnd)
- break; // error
-
- DecodeHeader(pHeaderStart, pHeaderEnd);
-
- if (!strncmp(pHeaderEnd, ATL_HEADER_END, strlen(ATL_HEADER_END)))
- {
- *pEnd = pHeaderEnd + strlen(ATL_HEADER_END);
- break; // we're done
- }
- else
- pHeaderStart = pHeaderEnd+2;
- }
-
- return ATL_HEADER_PARSE_COMPLETE;
-}
-
-// Reads the body if the encoding is not chunked.
-template<class TSocketClass>
-inline bool CAtlHttpClientT<TSocketClass>::ReadBody(int nContentLen, int nCurrentBodyLen) throw()
-{
- // nCurrentBodyLen is the length of the body that has already been read
- // nContentLen is the value of Content-Length
- // current is the buffer that will contain the entire response
- bool bRet = true;
- ATLASSUME(m_pNavData);
- if (!m_pNavData)
- return false;
-
- CTempBuffer<BYTE, 512> readbuff;
- DWORD dwReadBuffSize = 0;
- DWORD dwRead = 0;
- if (m_pNavData->dwReadBlockSize)
- {
- ATLTRY(readbuff.Allocate(m_pNavData->dwReadBlockSize));
- dwReadBuffSize = m_pNavData->dwReadBlockSize;
- }
- else
- {
- ATLTRY(readbuff.Allocate(ATL_READ_BUFF_SIZE));
- dwReadBuffSize = ATL_READ_BUFF_SIZE;
- }
-
- if (readbuff.operator BYTE*() == NULL)
- return false;
-
- if (nContentLen != -1) // We know the content length.
- {
- // read the rest of the body.
- while (nCurrentBodyLen < nContentLen)
- {
- dwRead = dwReadBuffSize;
- // loop while dwRead == 0
- for (int nRetry = 0; nRetry < ATL_HTTP_CLIENT_EMPTY_READ_RETRIES; ++nRetry)
- {
- if (!Read(readbuff, &dwRead))
- return false;
-
- // notify user
- if (m_pNavData)
- {
- if (m_pNavData->pfnReadStatusCallback)
- if (!m_pNavData->pfnReadStatusCallback(dwRead, m_pNavData->m_lParamRead))
- return false;
- }
-
- if (dwRead == 0)
- continue;
- nCurrentBodyLen += dwRead;
- if (!m_current.Append((LPCSTR)(BYTE*)readbuff, dwRead))
- {
- ATLASSERT(0);
- return false; // error!
- }
- m_pEnd = ((BYTE*)(LPCSTR)m_current) + m_current.GetLength();
- break;
- }
- if (dwRead == 0)
- return false;
- }
- m_dwBodyLen = nCurrentBodyLen;
- }
- else // We don't know content length. All we can do is
- { // read until there is nothing else to read.
- int nRetries = 0;
- while (1)
- {
- dwRead = dwReadBuffSize;
- if (Read((BYTE*)readbuff, (DWORD*)&dwRead))
- {
- // notify user
- if (m_pNavData)
- {
- if (m_pNavData->pfnReadStatusCallback)
- bRet = m_pNavData->pfnReadStatusCallback(dwRead, m_pNavData->m_lParamRead);
- if (!bRet)
- return bRet;
- }
-
- if (dwRead == 0)
- {
- if (nRetries++ < ATL_HTTP_CLIENT_EMPTY_READ_RETRIES)
- continue;
- break;
- }
-
- nRetries = 0;
- nCurrentBodyLen += dwRead;
- if (!m_current.Append((LPCSTR)(BYTE*)readbuff, dwRead))
- return false;
- m_pEnd = ((BYTE*)(LPCSTR)m_current) + m_current.GetLength();
- }
- else
- {
- // notify user
- if (m_pNavData)
- {
- if (m_pNavData->pfnReadStatusCallback)
- bRet = m_pNavData->pfnReadStatusCallback(dwRead, m_pNavData->m_lParamRead);
- if (!bRet)
- return bRet;
- }
-
- bRet = true;
- break;
- }
- }
- m_dwBodyLen = nCurrentBodyLen;
- }
- return bRet;
-}
-
-
-// This function moves pBuffStart only on success. On success, pBuffStart is moved
-// to the element past the last element we consumed.
-template<class TSocketClass>
-inline typename CAtlHttpClientT<TSocketClass>::CHUNK_LEX_RESULT CAtlHttpClientT<TSocketClass>::get_chunked_size(char *&pBuffStart, char *&pBuffEnd, long* pnChunkSize) throw()
-{
- CHUNK_LEX_RESULT result = LEX_ERROR;
- char *pStop = NULL;
-
- if (pBuffStart >= pBuffEnd)
- result = LEX_OUTOFDATA;
- else
- {
- long nResult = 0;
- errno_t errnoValue = AtlStrToNum(&nResult, pBuffStart, &pStop, 16);
- if (errnoValue != ERANGE &&
- nResult >= 0 &&
- nResult < 0xFFFFFFFF &&
- pStop <= pBuffEnd &&
- *pStop == '\r')
- {
- // move pBuffStart
- // return chunk size
- *pnChunkSize = nResult;
- pBuffStart = pStop;
- result = LEX_OK;
- }
- if (*pStop != '\r')
- {
- result = LEX_OUTOFDATA; // not enough data in the buffer
- }
- }
- return result;
-}
-
-template<class TSocketClass>
-inline bool CAtlHttpClientT<TSocketClass>::move_leftover_bytes( __in_ecount(nLen) char *pBufferStart,
- __in int nLen,
- __deref_inout_ecount(nLen) char *&pBuffStart,
- __deref_inout char *& pBuffEnd) throw()
-{
- bool bRet = true;
- Checked::memcpy_s(pBufferStart, (pBuffEnd-pBuffStart), pBuffStart, nLen);
- return bRet;
-}
-
-template<class TSocketClass>
-inline typename CAtlHttpClientT<TSocketClass>::CHUNK_LEX_RESULT CAtlHttpClientT<TSocketClass>::get_chunked_data(char *&pBufferStart,
- char *&pBufferEnd,
- long nChunkSize,
- char **ppDataStart,
- long *pnDataLen) throw()
-{
- CHUNK_LEX_RESULT result = LEX_ERROR;
- if (pBufferStart + nChunkSize - 1 < pBufferEnd)
- {
- *ppDataStart = pBufferStart;
- *pnDataLen = nChunkSize;
- pBufferStart = pBufferStart + nChunkSize;
- result = LEX_OK;
- }
- else if (pBufferStart + nChunkSize - 1 >= pBufferEnd)
- result = LEX_OUTOFDATA;
-
- return result;
-}
-
-template<class TSocketClass>
-inline typename CAtlHttpClientT<TSocketClass>::CHUNK_LEX_RESULT CAtlHttpClientT<TSocketClass>::consume_chunk_trailer(char *&pBufferStart, char *pBufferEnd)
-{
- CHUNK_LEX_RESULT result = LEX_ERROR;
- if (pBufferStart >= pBufferEnd)
- return result;
-
- char *pHeaderEnd = NULL;
- char *pTemp = pBufferStart;
- // check for empty trailer, this means there are no more trailers
- if ( (pTemp < pBufferEnd && *pTemp == '\r') &&
- (pTemp+1 < pBufferEnd && *(pTemp+1) == '\n'))
- {
- pBufferStart += 2;
- return LEX_TRAILER_COMPLETE;
- }
-
- while (pTemp <= pBufferEnd)
- {
- if ( (pTemp < pBufferEnd && *pTemp == '\r') &&
- (pTemp+1 < pBufferEnd && *(pTemp+1) == '\n'))
- {
- pHeaderEnd = pTemp; // success case
- result = LEX_OK;
- break;
- }
- pTemp++;
- }
-
- if (result == LEX_OK)
- {
- DecodeHeader(pBufferStart, pHeaderEnd);
- pBufferStart = pHeaderEnd + 2;
- }
- else if (result != LEX_OK &&
- pTemp > pBufferEnd)
- result = LEX_OUTOFDATA;
- return result;
-}
-
-template<class TSocketClass>
-inline typename CAtlHttpClientT<TSocketClass>::CHUNK_LEX_RESULT CAtlHttpClientT<TSocketClass>::consume_chunk_footer(char *&pBufferStart, char *&pBufferEnd)
-{
- CHUNK_LEX_RESULT result = LEX_ERROR;
- if (pBufferStart < pBufferEnd &&
- (pBufferStart+1) <= pBufferEnd)
- {
- if ( *pBufferStart == '\r' &&
- *(pBufferStart+1) == '\n')
- {
- pBufferStart += 2;
- result = LEX_OK;
- }
- }
- else
- result = LEX_OUTOFDATA;
- return result;
-}
-
-#define CHUNK_BUFF_SIZE 2048
-
-template<class TSocketClass>
-inline bool CAtlHttpClientT<TSocketClass>::ReadChunkedBody() throw()
-{
- // At this point, m_current contains the headers, up to and including the \r\n\r\n,
- // plus any additional data that might have been read off the socket. So, we need
- // to copy off the additional data into our read buffer before we start parsing the
- // chunks.
-#ifdef _DEBUG
- // nReadCount, keeps track of how many socket reads we do.
- int nReadCount = 0;
-#endif
-
- // nChunkBuffCarryOver
- // When we run out of data in the input buffer, this is the
- // count of bytes that are left in the input that could not
- // be lexed into anything useful. We copy this many bytes to
- // the top of the input buffer before we fill the input buffer
- // with more bytes from the socket
- long nChunkBuffCarryOver = 0;
-
- // nChunkSize
- // The size of the next chunk to be read from the input buffer.
- long nChunkSize = 0;
-
- // t_chunk_buffer
- // The heap allocated buffer that we holds data
- // read from the socket. We will increase the size
- // of this buffer to 2 times the max chunk size we
- // need to read if we have to.
- CHeapPtr<char> t_chunk_buffer;
-
- // nTChunkBuffSize
- // Keeps track of the allocated size of t_chunk_buffer.
- // This size will change if we need to read chunks bigger
- // than the currently allocated size of t_chunk_buffer.
- long nTChunkBuffSize = CHUNK_BUFF_SIZE;
-
- // chunk_buffer & chunk_buffer_end
- // Keeps track of the current location
- // in t_chunk_buffer that we are lexing input from.
- // chunk_buffer_end is the end of the input buffer we
- // are lexing from. chunk_buffer_end is used as a marker
- // to make sure we don't read past the end of our input buffer
- char *chunk_buffer, *chunk_buffer_end;
-
- // cstate
- // The current state of the chunk parsing state machine. We
- // start out reading the size of the first chunk.
- CHUNK_STATE cstate = READ_CHUNK_SIZE;
-
- // cresult
- // Holds the value of the result of a lexing operation performed
- // on the input buffer.
- CHUNK_LEX_RESULT cresult = LEX_OK;
-
- CAtlIsapiBuffer<> result_buffer;
-
- // Initialize pointers and allocate the chunk buffer.
- chunk_buffer = chunk_buffer_end = NULL;
- if( !t_chunk_buffer.Allocate(nTChunkBuffSize) )
- return false;
-
- // copy the headers into a temporary buffer.
- result_buffer.Append(m_current + m_dwHeaderStart, m_dwHeaderLen);
-
- // calculate number of bytes left in m_current past the headers
- long leftover_in_m_current = m_current.GetLength() - (m_dwHeaderStart + m_dwHeaderLen);
-
- // copy the extra bytes that might have been read into m_current into the chunk buffer
- if (leftover_in_m_current > 0)
- {
- if (leftover_in_m_current > nTChunkBuffSize)
- {
- if( ! t_chunk_buffer.Reallocate(leftover_in_m_current) )
- return false;
- }
-
- chunk_buffer = (char*)t_chunk_buffer;
- Checked::memcpy_s(chunk_buffer, leftover_in_m_current, ((LPCSTR)m_current)+ m_dwHeaderStart + m_dwHeaderLen, leftover_in_m_current);
- chunk_buffer_end = chunk_buffer + leftover_in_m_current;
- }
-
- m_current.Empty();
- m_dwBodyLen = 0;
- m_dwHeaderStart = 0;
-
- // as we start the state machine, we should be either pointing at the first
- // byte of chunked response or nothing, in which case we will need to get
- // more data from the socket.
- nChunkSize = 0;
-
- bool bDone = false;
-
- while(!bDone)
- {
- // if we run out of data during processing, chunk_buffer
- // get set to null
- if (!chunk_buffer ||
- chunk_buffer >= chunk_buffer_end)
- {
- // we ran out of data in our input buffer, we need
- // to read more from the socket.
- DWORD dwReadBuffSize = nTChunkBuffSize - nChunkBuffCarryOver;
- chunk_buffer = t_chunk_buffer;
- if (!Read((const unsigned char*)(chunk_buffer+nChunkBuffCarryOver), &dwReadBuffSize))
- {
- ATLTRACE("ReadChunkedBody: Error reading from socket (%d)\n", GetLastError());
- return false;
- }
- else if(dwReadBuffSize == 0)
- {
- ATLTRACE("ReadChunkedBody: The socket read timed out and no bytes were read from the socket.\n");
- return false;
- }
-#ifdef _DEBUG
- ATLTRACE("ReadChunkedBody read %d bytes from socket. Reads %d \n", dwReadBuffSize, ++nReadCount);
-#endif
- chunk_buffer_end = chunk_buffer + nChunkBuffCarryOver + dwReadBuffSize;
- nChunkBuffCarryOver = 0;
- }
-
- switch(cstate)
- {
- case READ_CHUNK_SIZE:
- {
- cresult = get_chunked_size(chunk_buffer, chunk_buffer_end, &nChunkSize);
- switch(cresult)
- {
- case LEX_ERROR:
- ATLTRACE("ReadChunkedBody Failed retrieving chunk size\n");
- return false;
- break;
- case LEX_OUTOFDATA:
- nChunkBuffCarryOver = (long)(chunk_buffer_end - chunk_buffer);
- if (!move_leftover_bytes((char*)t_chunk_buffer, nChunkBuffCarryOver,
- chunk_buffer, chunk_buffer_end))
- {
- ATLTRACE("failed to move leftover chunk data to head of buffer\n");
- return false;
- }
- chunk_buffer = chunk_buffer_end = NULL;
- break;
- case LEX_OK:
- if (nChunkSize == 0)
- {
- cstate = CHUNK_READ_DATA_COMPLETE;
- }
- else if (nChunkSize + 2 > nTChunkBuffSize)
- {
- char *pBuffStart = (char*)t_chunk_buffer;
- int nReadSoFar = (int)(chunk_buffer - pBuffStart);
- int nTotal = (int)(chunk_buffer_end - pBuffStart);
- if( FAILED(::ATL::AtlMultiply(&nTChunkBuffSize, nChunkSize, 2L)))
- {
- return false;
- }
- t_chunk_buffer.Reallocate(nTChunkBuffSize);
- pBuffStart = (char*)t_chunk_buffer;
- chunk_buffer = pBuffStart + nReadSoFar;
- chunk_buffer_end = pBuffStart + nTotal;
- cstate = READ_CHUNK_SIZE_FOOTER;
- m_dwBodyLen += nChunkSize;
- }
- else
- {
- // everything is OK. move to next state
- cstate = READ_CHUNK_SIZE_FOOTER;
- m_dwBodyLen += nChunkSize;
- }
- break;
- default:
- ATLASSERT(0);
- return false;
- break;
- }
- }
- break;
- case READ_CHUNK_DATA:
- {
- char *pDataStart = NULL;
- long nDataLen = 0;
- cresult = LEX_OK;
- cresult = get_chunked_data(chunk_buffer, chunk_buffer_end,
- nChunkSize, &pDataStart, &nDataLen);
- switch(cresult)
- {
- case LEX_ERROR:
- ATLTRACE("ReadChunkedBody failed to retrieve chunk data\n");
- return false;
- break;
- case LEX_OUTOFDATA:
- nChunkBuffCarryOver = (long)(chunk_buffer_end - chunk_buffer);
- if (!move_leftover_bytes((char*)t_chunk_buffer, nChunkBuffCarryOver,
- chunk_buffer, chunk_buffer_end))
- {
- ATLTRACE("failed to move leftover chunk data to head of buffer\n");
- return false;
- }
- chunk_buffer = chunk_buffer_end = NULL;
- break;
- case LEX_OK:
- result_buffer.Append(pDataStart, nDataLen);
- cstate = READ_CHUNK_DATA_FOOTER;
- break;
- default:
- ATLASSERT(0);
- return false;
- }
- }
- break;
- case READ_CHUNK_SIZE_FOOTER:
- case READ_CHUNK_DATA_FOOTER:
- {
- cresult = consume_chunk_footer(chunk_buffer, chunk_buffer_end);
- switch(cresult)
- {
- case LEX_OK:
- cstate = (cstate == READ_CHUNK_SIZE_FOOTER) ? READ_CHUNK_DATA : READ_CHUNK_SIZE;
- break;
- case LEX_ERROR:
- ATLTRACE("Error consuming chunk footer!\n");
- return false;
- break;
- case LEX_OUTOFDATA:
- nChunkBuffCarryOver = (long)(chunk_buffer_end - chunk_buffer);
- if (!move_leftover_bytes((char*)t_chunk_buffer, nChunkBuffCarryOver,
- chunk_buffer, chunk_buffer_end))
- {
- ATLTRACE("failed to move leftover chunk data to head of buffer\n");
- return false;
- }
- chunk_buffer = chunk_buffer_end = NULL;
- break;
- default:
- ATLASSERT(0);
- return false;
-
- }
- }
- break;
- case CHUNK_READ_DATA_COMPLETE:
- {
- // We read the chunk of size 0
- // consume the chunk footer.
- DWORD dwLen = 0;
- cresult = consume_chunk_footer(chunk_buffer, chunk_buffer_end);
- if (GetHeaderValue((_T("Trailer")), NULL, &dwLen))
- {
- cstate = READ_CHUNK_TRAILER; // start reading trailer headers
- break;
- }
- else
- bDone = true;
- }
- break;
- case READ_CHUNK_TRAILER:
- cresult = consume_chunk_trailer(chunk_buffer, chunk_buffer_end);
- switch(cresult)
- {
- case LEX_OK:
- cstate = READ_CHUNK_TRAILER; // keep reading
- break;
- case LEX_ERROR:
- ATLTRACE("Error consuming chunk trailers!\n");
- return false;
- break;
- case LEX_OUTOFDATA:
- nChunkBuffCarryOver = (long)(chunk_buffer_end - chunk_buffer);
- if (!move_leftover_bytes((char*)t_chunk_buffer, nChunkBuffCarryOver,
- chunk_buffer, chunk_buffer_end))
- {
- ATLTRACE("failed to move leftover chunk data to head of buffer\n");
- return false;
- }
- chunk_buffer = chunk_buffer_end = NULL;
- break;
- case LEX_TRAILER_COMPLETE:
- return true;
- break;
- default:
- ATLASSERT(0);
- return false;
-
-
-
- }
- break;
-
- }
- }
- if (!m_current.Append((LPCSTR)result_buffer))
- return false;
-
- m_pEnd = ((BYTE*)(LPCSTR)m_current) + m_current.GetLength();
-
- return true;
-}
-
-template<class TSocketClass>
-inline bool CAtlHttpClientT<TSocketClass>::ReconnectIfRequired() throw()
-{
- CString strValue;
- // if we have a keep-alive header then return true
- // else we have to close and re-open the connection
- if (GetHeaderValue(_T("Connection"), strValue))
- {
- if (!strValue.CompareNoCase(_T("keep-alive")))
- return true; // server said keep connection open.
- }
- else
- {
- return true; // there was no 'Connection' header
- }
-
- if (!strValue.CompareNoCase(_T("close")))
- {
- Close();
- ConnectSocket();
- }
- return false;
-}
-
-// Complete relative URLs and URLs
-// that have a missing path. These are common with redirect headers.
-// http://www.microsoft.com becomes http://www.microsoft.com/
-// localstart.asp becomes whatever our current (m_urlCurrent)
-// path is plus localstart.asp
-template<class TSocketClass>
-inline bool CAtlHttpClientT<TSocketClass>::CompleteURL(CString& strURL) throw()
-{
- _ATLTRY
- {
- CString strUrlTemp = strURL;
- strUrlTemp.Trim();
- CUrl url;
- bool bErr = false;
- if (url.CrackUrl(strUrlTemp))
- {
- return true; // URL is already valid
- }
-
-
- // if we have a scheme and a host name but no
- // path, then add the path of '/'
- if (url.GetScheme() == ATL_URL_SCHEME_HTTP &&
- url.GetHostNameLength() > 0 &&
- !url.GetUrlPathLength() )
- {
- url.SetUrlPath(_T("/"));
- bErr = true;
- }
- // if we have leading / (absolute path) (ex: /Test/bbb.asp) we can concatinate it
- // to it to our current URL (m_urlCurrent) scheme and host
- else if (strUrlTemp[0] == _T('/'))
- {
- url = m_urlCurrent;
- url.SetUrlPath(strUrlTemp);
- bErr = true;
- }
- // relative path (ex: bbb.asp) - we don't have a valid url
- // and the first char is not /
- // Get the url from our current URL (m_urlCurrent) and add
- // our relative paths
- else
- {
- CString szPath;
- url = m_urlCurrent;
-
- if (!url.GetUrlPathLength())
- {
- szPath = _T('/'); // current URL has no path!
- }
- else
- {
- szPath = url.GetUrlPath();
- }
-
- // back up to the first / and insert our current url
- int pos = szPath.ReverseFind(_T('/'));
- if(pos == -1)
- {
- return false;
- }
-
- szPath.GetBufferSetLength(pos+1);
- szPath.ReleaseBuffer();
-
- szPath += strURL;
- url.SetUrlPath(szPath);
- bErr = true;
- }
- if (!bErr)
- {
- return bErr;
- }
- DWORD dwLen = ATL_URL_MAX_PATH_LENGTH;
-
- return url.CreateUrl(strURL.GetBuffer(ATL_URL_MAX_PATH_LENGTH),
- &dwLen) ? true : false;
- }
- _ATLCATCHALL()
- {
- return false;
- }
-}
-
-template<class TSocketClass>
-inline bool CAtlHttpClientT<TSocketClass>::ProcessObjectMoved() throw()
-{
- _ATLTRY
- {
- // look for a location header
- CString strValue;
- CString strURLNew;
- if (GetHeaderValue(_T("Location"), strValue))
- {
- CString strRedirectReqHeaders=m_pNavData->szExtraHeaders;
- ReconnectIfRequired();
- m_HeaderMap.RemoveAll();
- m_current.Empty();
-
-
- // create a new URL based on what is in the
- // Location header and set it as this object's
- // default Url
- strURLNew = strValue;
- CompleteURL(strURLNew);
- CString strCurrHostName = m_urlCurrent.GetHostName();
- ATL_URL_PORT nCurrPort=m_urlCurrent.GetPortNumber();
-
- SetDefaultUrl((LPCTSTR)strURLNew, m_urlCurrent.GetPortNumber());
- //If redirected (new url in strURLNew) to different host (server) or port, need a new socket.
- if (m_urlCurrent.GetHostName()!=strCurrHostName || m_urlCurrent.GetPortNumber()!=nCurrPort)
- {
- Close();
- ConnectSocket();
- }
- // build up a request.
- CString strRequest;
- BuildRequest(&strRequest,
- m_strMethod,
- strRedirectReqHeaders.GetString());
-
- // send the request
- DWORD dwSent = strRequest.GetLength();
- DWORD dwAvailable = dwSent;
- if (!Write((BYTE*)((LPCSTR)CT2A(strRequest.GetBuffer(dwAvailable))), &dwSent))
- return false;
- strRequest.ReleaseBuffer();
-
- if (dwSent != dwAvailable)
- return false;
-
- // read the response
- if (RR_OK == ReadHttpResponse())
- {
- if (m_pNavData)
- ProcessStatus(m_pNavData->dwFlags);
- }
- }
- return true;
- }
- _ATLCATCHALL()
- {
- return false;
- }
-}
-
-template<class TSocketClass>
-inline bool CAtlHttpClientT<TSocketClass>::_SetDefaultUrl(LPCTSTR szURL, short nPort) throw()
-{
-
- if (szURL)
- if (!m_urlCurrent.CrackUrl(szURL)) // re-inits the field of the CUrl first
- return false;
-
- ATL_URL_SCHEME currScheme = m_urlCurrent.GetScheme();
- if ( currScheme != ATL_URL_SCHEME_HTTP &&
- !TSocketClass::SupportsScheme(currScheme) )
- return false; // only support HTTP
-
- if (!m_urlCurrent.GetUrlPathLength())
- {
- // no path, default to /
- m_urlCurrent.SetUrlPath(_T("/"));
- }
-
- if (!m_urlCurrent.GetHostNameLength())
- {
- // no server name
- return false;
- }
-
- if (m_urlCurrent.GetPortNumber() == ATL_URL_INVALID_PORT_NUMBER)
- m_urlCurrent.SetPortNumber(nPort);
- return true;
-}
-
-template<class TSocketClass>
-inline int CAtlHttpClientT<TSocketClass>::GetStatus() throw()
-{
- return m_nStatus;
-}
-
-template<class TSocketClass>
-inline LPCTSTR CAtlHttpClientT<TSocketClass>::GetMethod() throw()
-{
- return m_strMethod;
-}
-
-template<class TSocketClass>
-inline BYTE* CAtlHttpClientT<TSocketClass>::GetPostData() throw()
-{
- if (m_pNavData)
- return m_pNavData->pData;
- return NULL;
-}
-
-template<class TSocketClass>
-inline DWORD CAtlHttpClientT<TSocketClass>::GetPostDataLen() throw()
-{
- if (m_pNavData)
- return m_pNavData->dwDataLen;
- return 0;
-}
-
-template<class TSocketClass>
-inline LPCTSTR CAtlHttpClientT<TSocketClass>::GetPostDataType() throw()
-{
- if (m_pNavData)
- return m_pNavData->szDataType;
- return NULL;
-}
-
-template<class TSocketClass>
-inline DWORD CAtlHttpClientT<TSocketClass>::GetLastError() throw()
-{
- return m_dwLastError;
-}
-
-template<class TSocketClass>
-inline const SOCKET& CAtlHttpClientT<TSocketClass>::GetSocket() throw()
-{
- return const_cast<const SOCKET&>(m_socket);
-}
-
-template<class TSocketClass>
-inline void CAtlHttpClientT<TSocketClass>::Close() throw()
-{
- TSocketClass::Close();
-}
-
-template<class TSocketClass>
-inline DWORD CAtlHttpClientT<TSocketClass>::SetSocketTimeout(DWORD dwNewTimeout) throw()
-{
- return TSocketClass::SetSocketTimeout(dwNewTimeout);
-}
-
-template<class TSocketClass>
-inline DWORD CAtlHttpClientT<TSocketClass>::GetSocketTimeout() throw()
-{
- return TSocketClass::GetSocketTimeout();
-}
-
-template<class TSocketClass>
-inline void CAtlHttpClientT<TSocketClass>::AuthProtocolFailed(LPCTSTR szProto) throw()
-{
- CAtlBaseAuthObject *pAuthObj = NULL;
- _ATLTRY
- {
- if (m_AuthMap.Lookup(szProto, pAuthObj) && pAuthObj)
- {
- pAuthObj->m_bFailed = true;
- }
- }
- _ATLCATCHALL()
- {
- }
-}
-
-template<class TSocketClass>
-inline const ATL_NAVIGATE_DATA* CAtlHttpClientT<TSocketClass>::GetCurrentNavdata()
-{
- return m_pNavData;
-}
-
-
-/////////////////////////////////////////////////////////////////////////////////
-//
-// CNTLMAuthObject
-// NTLM Security Authorization functions
-//
-/////////////////////////////////////////////////////////////////////////////////
-inline CNTLMAuthObject::CNTLMAuthObject() throw() :
- m_pSocket(NULL),
- m_nMaxTokenSize(0),
- m_pAuthInfo(NULL),
- m_bProxy(false)
-{
- SecInvalidateHandle(&m_hCredentials)
-}
-
-inline CNTLMAuthObject::CNTLMAuthObject(IAuthInfo *pAuthInfo) throw() :
- m_pSocket(NULL),
- m_nMaxTokenSize(0),
- m_pAuthInfo(pAuthInfo)
-{
- SecInvalidateHandle(&m_hCredentials)
-}
-
-inline CNTLMAuthObject::~CNTLMAuthObject() throw()
-{
- if (!ATL_IS_INVALIDCREDHANDLE(m_hCredentials))
- FreeCredentialsHandle(&m_hCredentials);
-}
-
-inline void CNTLMAuthObject::Init(CAtlHttpClient *pSocket, IAuthInfo *pAuthInfo) throw()
-{
- m_pSocket = pSocket;
- SetAuthInfo(pAuthInfo);
-}
-
-inline void CNTLMAuthObject::SetAuthInfo(IAuthInfo *pAuthInfo) throw()
-{
- m_pAuthInfo = pAuthInfo;
-}
-
-inline bool CNTLMAuthObject::Authenticate(LPCTSTR /*szAuthTypes*/, bool bProxy) throw()
-{
- m_bProxy = bProxy;
- if (AcquireCredHandle())
- return DoNTLMAuthenticate();
- return false;
-}
-
-inline bool CNTLMAuthObject::AcquireCredHandle() throw()
-{
- PSecPkgInfo pPackageInfo = NULL;
- SECURITY_STATUS SecurityStatus = SEC_E_OK;
-
- // Acquire a credentials handle on the NTLM security package
- SecurityStatus = QuerySecurityPackageInfo(ATL_HTTP_AUTHTYPE_NTLM,
- &pPackageInfo);
-
- if (SecurityStatus != SEC_E_OK)
- return false;
-
- void *pAuthData = NULL;
- CSecAuthIdentity CA;
- if (m_pAuthInfo)
- {
- // if m_pAuthInfo has been set then the caller wants us
- // to get credentials from them.
- if (CA.Init(m_pAuthInfo))
- pAuthData = static_cast<void*>(&CA);
- }
-
- SecurityStatus = AcquireCredentialsHandle(
- 0,
- pPackageInfo->Name,
- SECPKG_CRED_OUTBOUND,
- 0,
- pAuthData,
- 0,
- 0,
- &m_hCredentials,
- &m_ts
- );
-
- m_nMaxTokenSize = pPackageInfo->cbMaxToken;
- FreeContextBuffer(pPackageInfo);
- return SecurityStatus == SEC_E_OK ? true : false;
-}
-
-inline bool CNTLMAuthObject::DoNTLMAuthenticate() throw()
-{
- bool bRet = false;
-
- m_CurrentRequestData = (*(const_cast<const ATL_NAVIGATE_DATA*>(m_pSocket->GetCurrentNavdata())));
- // make sure we have a good credentials handle
- ATLASSERT(!ATL_IS_INVALIDCREDHANDLE(m_hCredentials));
- if (ATL_IS_INVALIDCREDHANDLE(m_hCredentials))
- return false;
-
- SECURITY_STATUS SecurityStatus = SEC_E_OK;
-
- unsigned long ContextAttributes = 0;
- CSecBufferDesc OutBufferDesc;
- CtxtHandle SecurityContext;
- SecInvalidateHandle(&SecurityContext);
-
- // Create a SecBufferDesc with one buffer of m_nMaxTokenSize
- if (!OutBufferDesc.AddBuffers(1, m_nMaxTokenSize))
- return false;
-
- SecurityStatus = InitializeSecurityContext(
- &m_hCredentials,
- 0,
- NULL,
- ISC_REQ_CONNECTION,
- 0,
- 0,
- 0,
- 0,
- &SecurityContext,
- OutBufferDesc,
- &ContextAttributes,
- &m_ts
- );
-
- if ( (SecurityStatus == SEC_I_COMPLETE_NEEDED) ||
- (SecurityStatus == SEC_I_COMPLETE_AND_CONTINUE) )
- {
- SecurityStatus = CompleteAuthToken( &SecurityContext, (PSecBufferDesc)OutBufferDesc);
- }
-
- if (IS_ERROR(SecurityStatus))
- return false;
-
- // create an Authentication header with the contents of the
- // security buffer and send it to the HTTP server. The output
- // buffer will be pointing to a buffer that contains the
- // response from the HTTP server on return.
- LPSTR pszbuff = NULL;
- if (!SendSecurityInfo(OutBufferDesc.Buffers(0), &pszbuff) || !pszbuff)
- return false;
-
- CString strVal;
- if (!m_pSocket->GetHeaderValue(m_bProxy ? g_pszProxyAuthenticate : g_pszWWWAuthenticate, strVal))
- return false; // wrong authentication type
-
- LPCTSTR szResponsecode = strVal;
- TCHAR pszcode[ATL_AUTH_HDR_SIZE];
- if (szResponsecode)
- {
- // first four characters better be 'NTLM'
- if (_tcsncicmp(szResponsecode, _T("NTLM"), 4) != 0)
- return false;
-
- // skip NTLM
- szResponsecode += 4;
-
- // skip space
- while (*szResponsecode && _AtlIsHttpSpace(*szResponsecode))
- szResponsecode++;
-
- // find end of header
- LPCTSTR pszend = szResponsecode;
- while (*pszend && *pszend != _T('\r'))
- pszend++;
- bRet = false;
- if (pszend)
- {
- // copy authentication data to our buffer
- // and base64decode it.
- int nlen = (int)(pszend-szResponsecode);
- Checked::memcpy_s(pszcode, ATL_AUTH_HDR_SIZE, szResponsecode, nlen*sizeof(TCHAR));
- pszcode[pszend-szResponsecode]=0;
-
- // re-use OutBufferDesc here since we'll need to need
- // a SecBufferDesc to pass to the next call to InitializeSecurityContext
- // anyways.
- if(!OutBufferDesc.Buffers(0)->ClearBuffer(m_nMaxTokenSize))
- return false;
-
- _ATLTRY
- {
- CT2A pszcode_a(pszcode);
- bRet = Base64Decode(pszcode_a,
- (int) strlen(pszcode_a),
- (BYTE*)OutBufferDesc.Buffers(0)->pvBuffer,
- (int*) &OutBufferDesc.Buffers(0)->cbBuffer) != FALSE;
- }
- _ATLCATCHALL()
- {
- bRet = false;
- }
- }
-
- if (!bRet)
- return false;
-
- // Create buffers for the challenge data
- CSecBufferDesc *InBufferDesc = &OutBufferDesc;
- CSecBufferDesc OutBufferDesc2;
- if (!OutBufferDesc2.AddBuffers(1, m_nMaxTokenSize))
- return false;
-
- // Process the challenge response from the server
- SecurityStatus = InitializeSecurityContext(
- 0,
- &SecurityContext,
- NULL,
- 0,
- 0,
- 0 ,
- InBufferDesc,
- 0,
- &SecurityContext,
- OutBufferDesc2,
- &ContextAttributes,
- &m_ts
- );
-
- if (IS_ERROR(SecurityStatus))
- return false;
-
- pszbuff = NULL;
- if (SendSecurityInfo(OutBufferDesc2.Buffers(0), &pszbuff))
- {
- // at this point we should be authenticated and either have the page
- // we requested or be getting re-directed to another page under our
- // authorization. Either way, we don't want to go through authorization
- // code again if we are not authorized to prevent recursive authorization
- // so we tell the client not to try this protocol again.
- if (m_pSocket->GetStatus() == 401 ||
- m_pSocket->GetStatus() == 407)
- {
- // Authorization with this protocol failed.
- // don't try it again.
- m_pSocket->AuthProtocolFailed(_T("NTLM"));
- }
- bRet = m_pSocket->ProcessStatus(m_pSocket->GetFlags());
- }
- }
-
- return bRet;
-}
-inline bool CNTLMAuthObject::GetCredentialNames(CString& theName)
-{
- if (ATL_IS_INVALIDCREDHANDLE(m_hCredentials))
- return false;
-
- SecPkgCredentials_Names spcn;
- if(!IS_ERROR(QueryCredentialsAttributes(&m_hCredentials,
- SECPKG_CRED_ATTR_NAMES, (void*)&spcn)))
- {
- theName = spcn.sUserName;
- return true;
- }
- return false;
-}
-
-inline bool CNTLMAuthObject::SendSecurityInfo(SecBuffer *pSecBuffer, LPSTR *pszBuffer) throw()
-{
- ATLASSERT(pSecBuffer);
- ATLASSUME(m_pSocket);
- ATLASSERT(pszBuffer);
-
- int nDest = ATL_AUTH_HDR_SIZE;
- char auth_b64encoded[ATL_AUTH_HDR_SIZE];
- char auth_header[ATL_AUTH_HDR_SIZE];
- const char *pszFmtStr = m_bProxy ? m_pszFmtProxy : m_pszFmtWWW;
-
- if (!pSecBuffer || !pSecBuffer->pvBuffer || !pszBuffer)
- return false;
- *pszBuffer = 0;
-
- // Base64Encode will fail gracefully if buffer not big enough
- if (Base64Encode((BYTE*)pSecBuffer->pvBuffer, pSecBuffer->cbBuffer,
- auth_b64encoded, &nDest, ATL_BASE64_FLAG_NOCRLF))
- {
- if (nDest < ATL_AUTH_HDR_SIZE)
- {
- auth_b64encoded[nDest]=0;
- // make sure we have enough room in our header buffer
- if ( (strlen(pszFmtStr)-2 + nDest) < ATL_AUTH_HDR_SIZE)
- sprintf_s(auth_header, ATL_AUTH_HDR_SIZE, pszFmtStr, auth_b64encoded);
- else
- return false;
- }
- else
- return false;
- }
- else
- return false;
-
- // reset the connection if required
- m_pSocket->ResetConnection();
-
- // Resend the request with the authorization information
- LPCURL pUrl = m_pSocket->GetCurrentUrl();
- bool bRet = false;
-
- TCHAR szUrl[ATL_URL_MAX_URL_LENGTH];
- DWORD dwMaxLen = ATL_URL_MAX_URL_LENGTH;
- if( ! pUrl->CreateUrl(szUrl, &dwMaxLen) )
- return false;
-
- _ATLTRY
- {
- CA2CT hdr(auth_header);
- CAtlNavigateData navigate_data(m_CurrentRequestData);
- // append authorization header to extra headers
- CString strHeaders = navigate_data.GetExtraHeaders();
- strHeaders += hdr;
- navigate_data.SetExtraHeaders(strHeaders);
- navigate_data.RemoveFlags(ATL_HTTP_FLAG_PROCESS_RESULT);
-
- bRet = m_pSocket->Navigate( szUrl, &navigate_data);
- }
- _ATLCATCHALL()
- {
- bRet = false;
- }
- if (bRet)
- *pszBuffer = (LPSTR)m_pSocket->GetResponse();
- return bRet;
-}
-
-/////////////////////////////////////////////////////////////////////////////////
-//
-// CBasicAuthObject
-// BASIC Security Authorization functions
-//
-/////////////////////////////////////////////////////////////////////////////////
-inline bool CBasicAuthObject::DoBasicAuthenticate() throw()
-{
- bool bRet = false;
- ATLASSUME(m_pClient);
- ATLASSUME(m_pAuthInfo);
- // Create an authentication string
- CTempBuffer<TCHAR, (_ATL_MAX_AUTH_BUFF*2)+2> auth_string;
- CAuthInfoBuffType buffUID;
- CAuthInfoBuffType buffPWD;
-
- DWORD dwUID=0,dwPWD=0;
- if (!_AtlGetAuthInfoHelper(m_pAuthInfo, &IAuthInfo::GetPassword, buffPWD, &dwPWD) ||
- !_AtlGetAuthInfoHelper(m_pAuthInfo, &IAuthInfo::GetUsername, buffUID, &dwUID))
- return false;
-
- _ATLTRY
- {
- if (!auth_string.Allocate((_ATL_MAX_AUTH_BUFF*2)+2))
- return false;
-
- Checked::tcscpy_s(auth_string, _ATL_MAX_AUTH_BUFF, buffUID);
- Checked::tcscat_s(auth_string, _ATL_MAX_AUTH_BUFF, _T(":"));
- Checked::tcscat_s(auth_string, _ATL_MAX_AUTH_BUFF, buffPWD);
-
- // Base64 encode the auth string
- char *auth_string_enc = NULL;
- CTempBuffer<char, 512> auth_string_buff;
- CT2A auth_string_a(auth_string);
-
- int nLen = Base64EncodeGetRequiredLength((int)strlen((LPSTR)auth_string_a));
- auth_string_buff.Allocate(nLen+1);
- if (!((char*)auth_string_buff))
- return false;
-
- auth_string_enc = (char*)auth_string_buff;
- if (!Base64Encode((const BYTE*)(LPSTR)auth_string_a, (int)strlen((LPSTR)auth_string_a),
- auth_string_enc, &nLen, ATL_BASE64_FLAG_NOCRLF))
- return false;
- auth_string_buff[nLen]=0;
-
- // Format the Authentication header
- int nLenFmt = (m_bProxy ? (int)strlen(m_pszFmtProxy) : (int)strlen(m_pszFmtWWW)) + 2;
- nLen += nLenFmt;
- ++nLen; // Space for '\0'
-
- CTempBuffer<char, 512> auth_header_buff;
- ATLTRY(auth_header_buff.Allocate(nLen));
- if (!((char*)auth_header_buff))
- return false;
-
- char *auth_header = (char*)auth_header_buff;
- Checked::strcpy_s(auth_header, nLen, m_bProxy ? m_pszFmtProxy : m_pszFmtWWW);
- Checked::strcat_s(auth_header, nLen, auth_string_enc);
- Checked::strcat_s(auth_header, nLen, "\r\n");
-
- // Resend the request with the authorization information
- LPCURL pUrl = m_pClient->GetCurrentUrl();
- TCHAR szUrl[ATL_URL_MAX_URL_LENGTH];
- DWORD dwMaxLen = ATL_URL_MAX_URL_LENGTH;
- pUrl->CreateUrl(szUrl, &dwMaxLen);
-
- // reset the connection if required
- m_pClient->ResetConnection();
-
- CA2T hdr(auth_header);
- CAtlNavigateData navigate_data(*(const_cast<const ATL_NAVIGATE_DATA*>(m_pClient->GetCurrentNavdata())));
- // append authorization header to extra headers
- CString strHeaders = navigate_data.GetExtraHeaders();
- strHeaders += hdr;
- navigate_data.SetExtraHeaders(strHeaders);
- navigate_data.RemoveFlags(ATL_HTTP_FLAG_PROCESS_RESULT);
- bRet = m_pClient->Navigate( szUrl,
- &navigate_data);
- }
- _ATLCATCHALL()
- {
- bRet = false;
- }
-
- if (bRet)
- {
- // Request was successfully sent. Process the result.
- if (m_pClient->GetStatus() == 401 ||
- m_pClient->GetStatus() == 407)
- {
- // Authorization with this protocol failed.
- // don't try it again.
- m_pClient->AuthProtocolFailed(_T("basic"));
- }
- bRet = m_pClient->ProcessStatus(m_pClient->GetFlags());
- }
- return bRet;
-}
-
-inline CBasicAuthObject::CBasicAuthObject() throw()
-{
- m_pClient = NULL;
- m_pAuthInfo = NULL;
- m_szRealm[0] = 0;
- m_bProxy = false;
-}
-
-inline CBasicAuthObject::CBasicAuthObject(IAuthInfo *pAuthInfo) throw()
-{
- m_pAuthInfo = pAuthInfo;
- m_pClient = NULL;
-}
-
-inline void CBasicAuthObject::SetAuthInfo(IAuthInfo *pAuthInfo) throw()
-{
- m_pAuthInfo = pAuthInfo;
-}
-
-// Called by the CAtlHttpClient class to
-// authenticate a user.
-inline bool CBasicAuthObject::Authenticate(LPCTSTR szAuthTypes, bool bProxy) throw()
-{
- if (lstrlen(szAuthTypes) > ATL_AUTH_HDR_SIZE)
- return false;
-
- m_bProxy = bProxy;
-
- if (!CrackRealm(szAuthTypes))
- return false;
- return DoBasicAuthenticate();
-}
-
-inline LPCTSTR CBasicAuthObject::GetRealm() throw()
-{
- return const_cast<LPCTSTR>(m_szRealm);
-}
-
-// Called by the CAtlHttpClient class to initialize
-// this authentication object.
-inline void CBasicAuthObject::Init(CAtlHttpClient *pSocket, IAuthInfo *pAuthInfo) throw()
-{
- ATLASSERT(pSocket);
- m_pClient = pSocket;
- if (pAuthInfo)
- SetAuthInfo(pAuthInfo);
-}
-
-inline bool CBasicAuthObject::CrackRealm(LPCTSTR szHeader) throw()
-{
- // szHeader is pointing at the
- // "basic" in the header
- // see if realm is available
- const TCHAR *pStart = szHeader;
-
- // skip "basic"
- pStart += 5;
-
- // skip space
- while (*pStart && _AtlIsHttpSpace(*pStart))
- pStart++;
-
- // are we pointing at 'realm'?
- if ((*pStart == 'r' || *pStart == 'R') &&
- (*(pStart+1) == 'e' || *(pStart+1) == 'E') &&
- (*(pStart+2) == 'a' || *(pStart+2) == 'A') &&
- (*(pStart+3) == 'l' || *(pStart+3) == 'L') &&
- (*(pStart+4) == 'm' || *(pStart+4) == 'M'))
- {
- // skip 'realm'
- pStart += 5;
-
- // skip space
- while (*pStart && _AtlIsHttpSpace(*pStart))
- pStart++;
-
- // skip '='
- if (*pStart && *pStart == _T('='))
- pStart++;
- else
- return false; // invalid realm
-
- // skip space
- while (*pStart && _AtlIsHttpSpace(*pStart))
- pStart++;
-
- // skip quotes if they are there
- if (*pStart == '\"')
- pStart++;
-
- const TCHAR *pEnd = pStart;
- while (*pEnd && *pEnd != '\"')
- {
- if (*pEnd == '\\' && *(pEnd + 1)) // escaped character, skip it
- pEnd += 2;
- else
- pEnd++;
- }
-
- if (*pEnd == '\"' && *(pEnd+1) != '\0')
- return false; //trailing junk after the quoted realm
-
- if (*pEnd=='\0' || *pEnd =='\"')
- {
- int nLen = (int)(pEnd-pStart);
- if (nLen < MAX_REALM_LEN)
- {
- Checked::tcsncpy_s(m_szRealm, _countof(m_szRealm), pStart, nLen);
- m_szRealm[nLen]=0;
- if (!AtlUnescapeUrl(m_szRealm, m_szRealm, NULL, MAX_REALM_LEN))
- return false; // error unescaping the string
- }
- else
- return false;
- }
- }
- return true;
-}
-
-inline CAtlBaseAuthObject::CAtlBaseAuthObject()
-{
- m_bFailed = false;
-}
-
-
-inline CAtlNavigateData::CAtlNavigateData() throw()
-{
- dwFlags = ATL_HTTP_FLAG_AUTO_REDIRECT|
- ATL_HTTP_FLAG_PROCESS_RESULT|
- ATL_HTTP_FLAG_SEND_BLOCKS;
- szExtraHeaders = NULL;
- szMethod = ATL_HTTP_METHOD_GET;
- nPort = ATL_URL_DEFAULT_HTTP_PORT;
- pData = NULL;
- dwDataLen = 0;
- szDataType = NULL;
- dwTimeout = ATL_SOCK_TIMEOUT;
- dwSendBlockSize = ATL_HTTP_DEFAULT_BLOCK_SIZE;
- dwReadBlockSize = ATL_HTTP_DEFAULT_BLOCK_SIZE;
- pfnChunkCallback = NULL;
- pfnSendStatusCallback = NULL;
- pfnReadStatusCallback = NULL;
- m_lParamSend = 0;
- m_lParamRead = 0;
-}
-
-inline CAtlNavigateData::CAtlNavigateData(const CAtlNavigateData &rhs)
-{
- this->operator=(rhs);
-}
-
-inline CAtlNavigateData::CAtlNavigateData(const ATL_NAVIGATE_DATA &rhs)
-{
- this->operator=(rhs);
-}
-
-inline CAtlNavigateData& CAtlNavigateData::operator=(const CAtlNavigateData &rhs)
-{
- return this->operator=(static_cast<const ATL_NAVIGATE_DATA&>(rhs));
-}
-
-inline CAtlNavigateData& CAtlNavigateData::operator=(const ATL_NAVIGATE_DATA &rhs)
-{
- dwFlags = rhs.dwFlags;
- szExtraHeaders = rhs.szExtraHeaders;
- szMethod = rhs.szMethod;
- nPort = rhs.nPort;
- pData = rhs.pData;
- dwDataLen = rhs.dwDataLen;
- szDataType = rhs.szDataType;
- dwTimeout = rhs.dwTimeout;
- dwSendBlockSize = rhs.dwSendBlockSize;
- dwReadBlockSize = rhs.dwReadBlockSize;
- pfnChunkCallback = rhs.pfnChunkCallback;
- pfnSendStatusCallback = rhs.pfnSendStatusCallback;
- pfnReadStatusCallback = rhs.pfnReadStatusCallback;
- m_lParamSend = rhs.m_lParamSend;
- m_lParamRead = rhs.m_lParamRead;
- return *this;
-}
-
-inline DWORD CAtlNavigateData::SetFlags(DWORD dwNewFlags) throw()
-{
- // check for mutually exclusive flags
- if ((dwNewFlags & ATL_HTTP_FLAG_SEND_CALLBACK) &&
- (dwNewFlags & ATL_HTTP_FLAG_SEND_BLOCKS))
- {
- ATLASSERT(0);
- return ATL_HTTP_FLAG_INVALID_FLAGS;
- }
-
- DWORD dwOldFlags = dwFlags;
- dwFlags = dwNewFlags;
- return dwOldFlags;
-}
-
-inline DWORD CAtlNavigateData::GetFlags() throw()
-{
- return dwFlags;
-}
-
-inline DWORD CAtlNavigateData::AddFlags(DWORD dwFlagsToAdd) throw()
-{
- // check for mutually exclusive flags
- if (
- ((dwFlagsToAdd & ATL_HTTP_FLAG_SEND_CALLBACK) &&
- (dwFlags & ATL_HTTP_FLAG_SEND_BLOCKS)) ||
- ((dwFlagsToAdd & ATL_HTTP_FLAG_SEND_BLOCKS) &&
- (dwFlags & ATL_HTTP_FLAG_SEND_CALLBACK))
- )
- {
- ATLASSERT(0);
- return ATL_HTTP_FLAG_INVALID_FLAGS;
- }
-
- DWORD dwOldFlags = dwFlags;
- dwFlags |= dwFlagsToAdd;
- return dwOldFlags;
-}
-
-inline DWORD CAtlNavigateData::RemoveFlags(DWORD dwFlagsToRemove) throw()
-{
- DWORD dwOldFlags = dwFlags;
- dwFlags &= ~dwFlagsToRemove;
- return dwOldFlags;
-}
-
-inline LPCTSTR CAtlNavigateData::SetExtraHeaders(LPCTSTR szNewHeaders) throw()
-{
- LPCTSTR szold = szExtraHeaders;
- szExtraHeaders = szNewHeaders;
- return szold;
-}
-
-inline LPCTSTR CAtlNavigateData::GetExtraHeaders() throw()
-{
- return szExtraHeaders;
-}
-inline LPCTSTR CAtlNavigateData::SetMethod(LPCTSTR szNewMethod) throw()
-{
- LPCTSTR szold = szMethod;
- szMethod = szNewMethod;
- return szold;
-}
-inline LPCTSTR CAtlNavigateData::GetMethod() throw()
-{
- return szMethod;
-}
-inline short CAtlNavigateData::SetPort(short newPort) throw()
-{
- short oldport = nPort;
- nPort = newPort;
- return oldport;
-}
-inline short CAtlNavigateData::GetPort() throw()
-{
- return nPort;
-}
-inline void CAtlNavigateData::SetPostData(BYTE *pd, DWORD len, LPCTSTR type) throw()
-{
- pData = pd;
- dwDataLen = len;
- szDataType = type;
-}
-
-inline DWORD CAtlNavigateData::SetSocketTimeout(DWORD dwNewTimeout) throw()
-{
- DWORD dwold = dwTimeout;
- dwTimeout = dwNewTimeout;
- return dwold;
-}
-inline DWORD CAtlNavigateData::GetSocketTimeout() throw()
-{
- return dwTimeout;
-}
-inline DWORD CAtlNavigateData::SetSendBlockSize(DWORD dwNewBlockSize) throw()
-{
- DWORD dwold = dwSendBlockSize;
- dwSendBlockSize = dwNewBlockSize;
- return dwold;
-}
-inline DWORD CAtlNavigateData::GetSendBlockSize() throw()
-{
- return dwSendBlockSize;
-}
-
-inline DWORD CAtlNavigateData::SetReadBlockSize(DWORD dwNewBlockSize) throw()
-{
- DWORD dwold = dwReadBlockSize;
- dwReadBlockSize = dwNewBlockSize;
- return dwold;
-}
-
-inline DWORD CAtlNavigateData::GetReadBlockSize() throw()
-{
- return dwReadBlockSize;
-}
-
-inline PFNATLCHUNKEDCB CAtlNavigateData::SetChunkCallback(PFNATLCHUNKEDCB pfn, DWORD_PTR dwParam) throw()
-{
- PFNATLCHUNKEDCB pold = pfnChunkCallback;
- pfnChunkCallback = pfn;
- m_lParamChunkCB = dwParam;
- return pold;
-}
-inline PFNATLCHUNKEDCB CAtlNavigateData::GetChunkCallback() throw()
-{
- return pfnChunkCallback;
-}
-
-inline PFNATLSTATUSCALLBACK CAtlNavigateData::SetSendStatusCallback(PFNATLSTATUSCALLBACK pfn, DWORD_PTR dwData) throw()
-{
- PFNATLSTATUSCALLBACK pold = pfnSendStatusCallback;
- pfnSendStatusCallback = pfn;
- m_lParamSend = dwData;
- return pold;
-}
-
-inline PFNATLSTATUSCALLBACK CAtlNavigateData::GetSendStatusCallback() throw()
-{
- return pfnSendStatusCallback;
-}
-
-inline PFNATLSTATUSCALLBACK CAtlNavigateData::SetReadStatusCallback(PFNATLSTATUSCALLBACK pfn, DWORD_PTR dwData) throw()
-{
- PFNATLSTATUSCALLBACK pOld = pfnReadStatusCallback;
- pfnReadStatusCallback = pfn;
- m_lParamRead = dwData;
- return pOld;
-}
-
-inline PFNATLSTATUSCALLBACK CAtlNavigateData::GetReadStatusCallback() throw()
-{
- return pfnReadStatusCallback;
-}
-
-} // namespace ATL
-
-#pragma warning(pop)
-
-#endif // __ATLHTTP_INL__
diff --git a/include/atl/atlmime.h b/include/atl/atlmime.h
deleted file mode 100644
index 06d4fd2f4..000000000
--- a/include/atl/atlmime.h
+++ /dev/null
@@ -1,2406 +0,0 @@
-// This is a part of the Active Template Library.
-// Copyright (C) Microsoft Corporation
-// All rights reserved.
-//
-// This source code is only intended as a supplement to the
-// Active Template Library Reference and related
-// electronic documentation provided with the library.
-// See these sources for detailed information regarding the
-// Active Template Library product.
-
-#ifndef __ATLMIME_H__
-#define __ATLMIME_H__
-
-#pragma once
-
-#include <tchar.h>
-#include <time.h>
-#include <atlbase.h>
-#include <mlang.h>
-#include <atlfile.h>
-#include <atlcoll.h>
-#include <atlstr.h>
-#include <atlsmtputil.h>
-#include <atlenc.h>
-#include <atlspriv.h>
-
-#pragma warning(push)
-#pragma warning(disable: 4625) // copy constructor could not be generated because a base class copy constructor is inaccessible
-#pragma warning(disable: 4626) // assignment operator could not be generated because a base class assignment operator is inaccessible
-
-#ifndef _CPPUNWIND
-#pragma warning (push)
-#pragma warning(disable: 4702) // unreachable code
-#endif // _CPPUNWIND
-
-#pragma pack(push,_ATL_PACKING)
-namespace ATL {
-
-#ifndef ATLMIME_SEPARATOR
-#define ATLMIME_SEPARATOR "\r\n\r\n--"
-#endif//ATLMIME_SEPARATOR
-
-#ifndef ATLMIME_VERSION
-#define ATLMIME_VERSION "MIME-Version: 1.0"
-#endif//ATLMIME_VERSION
-
-#ifndef ATLMIME_EMAIL
-#define ATLMIME_EMAIL "email"
-#endif//ATLMIME_EMAIL
-
-extern __declspec(selectany) const DWORD ATL_MIME_BOUNDARYLEN = 32;
-extern __declspec(selectany) const DWORD ATL_MIME_DATE_LEN = 64;
-
-// Called when message is sent - sets the "Date:" field
-inline size_t SetRfc822Time(__out_ecount_part_z_opt(dwLen, return) LPSTR szDate, __in size_t dwLen) throw()
-{
- // Max buffer size required(including NULL) - 38
- const size_t s_dwMaxBufferLen = 38;
- if (szDate == NULL)
- {
- return s_dwMaxBufferLen;
- }
-
- if (dwLen < 38)
- {
- return 0;
- }
- static const LPCSTR s_months[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
-
- static const LPCSTR s_days[7] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
-
- SYSTEMTIME st;
- DWORD dwTimeZoneId=TIME_ZONE_ID_UNKNOWN;
- CHAR cDiff;
- LONG ltzBias=0;
- LONG ltzHour;
- LONG ltzMinute;
- TIME_ZONE_INFORMATION tzi;
-
- GetLocalTime(&st);
-
- // Gets TIME_ZONE_INFORMATION
- memset(&tzi, 0, sizeof(tzi));
- dwTimeZoneId = GetTimeZoneInformation(&tzi);
- switch (dwTimeZoneId)
- {
- case TIME_ZONE_ID_STANDARD:
- ltzBias = tzi.Bias + tzi.StandardBias;
- break;
-
- case TIME_ZONE_ID_DAYLIGHT:
- ltzBias = tzi.Bias + tzi.DaylightBias;
- break;
-
- case TIME_ZONE_ID_UNKNOWN:
- default:
- ltzBias = tzi.Bias;
- break;
- }
-
- // Set Hour Minutes and time zone dif
- ltzHour = ltzBias / 60;
- ltzMinute = ltzBias % 60;
- cDiff = (ltzHour < 0) ? '+' : '-';
-
- int nDay = (st.wDayOfWeek > 6) ? 0 : st.wDayOfWeek;
- int nMonth = st.wMonth = (WORD)((st.wMonth < 1 || st.wMonth > 12) ? 0 : st.wMonth - 1);
-
-
- // Constructs RFC 822 format: "ddd, dd mmm yyyy hh:mm:ss +/- hhmm\0"
- sprintf_s(szDate, dwLen, "Date: %3s, %d %3s %4d %02d:%02d:%02d %c%02d%02d",
- s_days[nDay], // "ddd"
- st.wDay, // "dd"
- s_months[nMonth], // "mmm"
- st.wYear, // "yyyy"
- st.wHour, // "hh"
- st.wMinute, // "mm"
- st.wSecond, // "ss"
- cDiff, // "+" / "-"
- abs (ltzHour), // "hh"
- abs (ltzMinute)); // "mm"
- return s_dwMaxBufferLen;
-}
-
-inline DWORD GetContentTypeFromFileName(LPCTSTR szFileName, CSimpleString& strContentType) throw()
-{
- if (szFileName == NULL)
- {
- return ERROR_INVALID_DATA;
- }
-
- DWORD dwErr = ERROR_PATH_NOT_FOUND;
- _ATLTRY
- {
- // get the file extension
- TCHAR szExt[_MAX_EXT];
- Checked::tsplitpath_s(szFileName, NULL, 0, NULL, 0, NULL, 0, szExt, _countof(szExt));
- if (*szExt)
- {
- // Query the content type from the registry
- CRegKey rkContentType;
- dwErr = rkContentType.Open(HKEY_CLASSES_ROOT, szExt, KEY_READ);
- if (dwErr == ERROR_SUCCESS)
- {
- ULONG nChars=0;
- dwErr = rkContentType.QueryStringValue(_T("Content Type"), NULL, &nChars);
- if (dwErr == ERROR_SUCCESS)
- {
- LPTSTR szBuf = strContentType.GetBuffer(nChars);
- dwErr = rkContentType.QueryStringValue(_T("Content Type"), szBuf, &nChars);
- strContentType.ReleaseBuffer(nChars);
- }
- }
- }
-
- if (dwErr != ERROR_SUCCESS)
- {
- // default to application/octet-stream
- strContentType.SetString(_T("application/octet-stream"), sizeof("application/octet-stream")-1);
- }
- }
- _ATLCATCHALL()
- {
- dwErr = ERROR_OUTOFMEMORY;
- }
-
- return dwErr;
-}
-
-// CMimeBodyPart is an abstract base class for the body parts
-// CMimeAttachment, CMimeText, CMimeHeader.
-class CMimeBodyPart
-{
-public:
-
- virtual ~CMimeBodyPart() = 0 {}
-
- // WriteData - pure virtual method to dump the data for a body part.
- virtual BOOL WriteData(HANDLE hFile, LPOVERLAPPED pOverlapped, LPCSTR szBoundary, DWORD dwFlags = 0) = 0;
-
- // GetContentType - pure virtual method to get the content of a body part
- virtual LPCSTR GetContentType() = 0;
-
- // GetCharset - virtual method to get the character set of a body part
- // (defaults to ATLSMTP_DEFAULT_CSET).
- virtual LPCSTR GetCharset()
- {
- return ATLSMTP_DEFAULT_CSET;
- }
-
- virtual CMimeBodyPart* Copy() = 0;
-
-protected:
-
- // MakeMimeHeader - pure virutal method to create a MIME header for a
- // body part.
- virtual BOOL MakeMimeHeader(CStringA& header, LPCSTR szBoundary) = 0;
-}; // class CMimeBodyPart
-
-
-// This enum is used with the X-Priority part of the message header
-enum ATL_MIME_PRIORITY
-{
- ATL_MIME_HIGH_PRIORITY = 1,
- ATL_MIME_NORMAL_PRIORITY = 3,
- ATL_MIME_LOW_PRIORITY = 5,
- ATL_MIME_PRIORITY_ERROR = 0
-};
-
-
-// CMimeHeader describes the basic RFC 822 message header.
-// It also serves as the base class for the CMimeMessage object.
-class CMimeHeader : public CMimeBodyPart
-{
-protected:
-
- // Pointer to MLANG's IMultiLanguage interface.
- // This is used in doing conversion from code pages
- // to MIME-compatible character sets.
- CComPtr<IMultiLanguage> m_spMultiLanguage;
-
- //Basic Header Parts
- CStringA m_strFrom;
- CStringA m_strTo;
- CStringA m_strCc;
- CStringA m_strBcc;
- CStringA m_strSubject;
-
- //Extended Header Parts
- ATL_MIME_PRIORITY m_nPriority;
- CStringA m_XHeader;
-
- //Display Names
- CStringA m_strSenderName;
-
- //MIME Character Sets
- char m_szSubjectCharset[ATL_MAX_ENC_CHARSET_LENGTH];
- char m_szSenderCharset[ATL_MAX_ENC_CHARSET_LENGTH];
-
- //Recipient and CC charsets are encoded in the Add methods
-
-public:
-
- CMimeHeader() throw()
- :m_nPriority(ATL_MIME_NORMAL_PRIORITY)
- {
- m_szSubjectCharset[0] = '\0';
- m_szSenderCharset[0] = '\0';
- }
-
- ~CMimeHeader() throw()
- {
- }
-
- // Initialize MLang for multilanguage support
- inline BOOL Initialize(IMultiLanguage* pMultiLanguage = NULL) throw()
- {
- if (pMultiLanguage != NULL)
- {
- m_spMultiLanguage = pMultiLanguage;
- }
- else
- {
- HRESULT hr = m_spMultiLanguage.CoCreateInstance(__uuidof(CMultiLanguage), NULL, CLSCTX_INPROC_SERVER);
- if (hr != S_OK)
- return FALSE;
- }
- return TRUE;
- }
-
- // Get the content type
- virtual inline LPCSTR GetContentType() throw()
- {
- return "text/plain";
- }
-
- // Get the character set
- virtual inline LPCSTR GetCharset() throw()
- {
- return "iso-8859-1";
- }
-
- virtual ATL_NOINLINE CMimeBodyPart* Copy() throw( ... )
- {
- CAutoPtr<CMimeHeader> pNewHeader;
- ATLTRY(pNewHeader.Attach(new CMimeHeader));
- if (pNewHeader)
- *pNewHeader = *this;
-
- return pNewHeader.Detach();
- }
-
- const CMimeHeader& operator=(const CMimeHeader& that) throw( ... )
- {
- if (this != &that)
- {
- m_spMultiLanguage = that.m_spMultiLanguage;
- m_strFrom = that.m_strFrom;
- m_strTo = that.m_strTo;
- m_strCc = that.m_strCc;
- m_strSubject = that.m_strSubject;
-
- m_nPriority = that.m_nPriority;
- m_XHeader = that.m_XHeader;
-
- m_strSenderName = that.m_strSenderName;
-
- Checked::strcpy_s(m_szSubjectCharset, ATL_MAX_ENC_CHARSET_LENGTH, that.m_szSubjectCharset);
- Checked::strcpy_s(m_szSenderCharset, ATL_MAX_ENC_CHARSET_LENGTH, that.m_szSenderCharset);
- }
-
- return *this;
- }
-
- // Set the priority of the message
- inline BOOL SetPriority(ATL_MIME_PRIORITY nPriority) throw()
- {
- if (nPriority < 0)
- return FALSE;
- m_nPriority = nPriority;
- return TRUE;
- }
-
- // Get the priority of the message
- inline ATL_MIME_PRIORITY GetPriority() throw()
- {
- return m_nPriority;
- }
-
- // Set the display (friendly) name for the header
- inline BOOL SetSenderName(LPCTSTR szName, UINT uiCodePage = 0) throw()
- {
- if (szName == NULL)
- return FALSE;
-
- CHeapPtr<char> szNamePtr;
- UINT nLen(0);
-
- BOOL bRet = AtlMimeConvertString(m_spMultiLanguage, uiCodePage, szName, &szNamePtr, &nLen);
- if (bRet)
- {
- _ATLTRY
- {
- m_strSenderName.Empty();
- m_strSenderName.Append(szNamePtr, (int) nLen);
- }
- _ATLCATCHALL()
- {
- return FALSE;
- }
- bRet = AtlMimeCharsetFromCodePage(m_szSenderCharset, uiCodePage, m_spMultiLanguage, ATL_MAX_ENC_CHARSET_LENGTH);
- }
-
- return bRet;
- }
-
- // Get the display (friendly) name for the sender
- inline LPCSTR GetSenderName() throw()
- {
- return m_strSenderName;
- }
-
- // Append a user defined header (should not contain CRLF)
- inline BOOL AppendUserDefinedHeader(LPCTSTR szHeaderName, LPCTSTR szHeader, UINT uiCodePage = 0) throw()
- {
- if ((szHeader == NULL) || (szHeaderName == NULL))
- return FALSE;
-
- _ATLTRY
- {
- CHeapPtr<char> szName;
- UINT nLen(0);
-
- BOOL bRet = AtlMimeConvertString(m_spMultiLanguage, uiCodePage, szHeader, &szName, &nLen);
- if (bRet)
- {
- // get the charset
- char szCharset[ATL_MAX_ENC_CHARSET_LENGTH];
- bRet = AtlMimeCharsetFromCodePage(szCharset, uiCodePage, m_spMultiLanguage, ATL_MAX_ENC_CHARSET_LENGTH);
-
- if (bRet)
- {
- CStringA str;
- str.Append(szName, (int)nLen);
-
- // encode the string
- CHeapPtr<char> szBuf;
- DWORD dwReqLen = QEncodeGetRequiredLength(str.GetLength(),
- ATL_MAX_ENC_CHARSET_LENGTH);
-
- if (szBuf.Allocate(dwReqLen) == false)
- {
- return FALSE;
- }
-
- DWORD dwLength(0);
- BOOL bEncoded = FALSE;
- if (!GetEncodedString(str, szCharset, szBuf, dwReqLen, dwLength, bEncoded))
- {
- return FALSE;
- }
-
- // add to m_XHeader
- m_XHeader += CT2CA(szHeaderName);
- m_XHeader.Append(": ", 2);
- m_XHeader.Append(szBuf, dwLength);
- m_XHeader.Append("\r\n", 2);
- }
- }
-
- return bRet;
- }
- _ATLCATCHALL()
- {
- return FALSE;
- }
- }
-
- // Add a recipient ("To:" line)
- inline BOOL AddRecipient(LPCTSTR szAddress, LPCTSTR szName = NULL, UINT uiCodePage = 0) throw()
- {
- return AddRecipientHelper(m_strTo, szAddress, szName, uiCodePage);
- }
-
- // Get the recipients string ("To:" line)
- inline LPCSTR GetRecipients() throw()
- {
- return m_strTo;
- }
-
- // Clear all recipients ("To:" line)
- inline BOOL ClearRecipients() throw()
- {
- m_strTo.Empty();
- return TRUE;
- }
-
- // Add a recipient ("CC:" line)
- inline BOOL AddCc(LPCTSTR szAddress, LPCTSTR szName = NULL, UINT uiCodePage = 0) throw()
- {
- return AddRecipientHelper(m_strCc, szAddress, szName, uiCodePage);
- }
-
- // Get the recipients string ("CC:" line)
- inline LPCSTR GetCc() throw()
- {
- return m_strCc;
- }
-
- // Clear the recipients string ("CC:" line)
- inline BOOL ClearCc() throw()
- {
- m_strCc.Empty();
- return TRUE;
- }
-
- // Add a Bcc recipient (not output as part of message)
- inline BOOL AddBcc(LPCTSTR szAddress) throw()
- {
- if (szAddress == NULL)
- {
- return FALSE;
- }
-
- _ATLTRY
- {
- CStringA str = m_strBcc;
-
- if (m_strBcc.GetLength() > 0)
- str.Append(",", 1);
-
- str += CT2CA(szAddress);
-
- m_strBcc = str;
-
- return TRUE;
- }
- _ATLCATCHALL()
- {
- return FALSE;
- }
- }
-
- // Get the recipients string (Bcc part)
- inline LPCSTR GetBcc() throw()
- {
- return m_strBcc;
- }
-
- // Clear the recipients string (Bcc part)
- inline BOOL ClearBcc() throw()
- {
- m_strBcc.Empty();
- return TRUE;
- }
-
-
- inline DWORD GetRequiredRecipientsStringLength() throw()
- {
- DWORD dwRet = m_strTo.GetLength();
- if (m_strCc.GetLength())
- {
- dwRet += dwRet ? 1 : 0;
- dwRet += m_strCc.GetLength();
- }
- if (m_strBcc.GetLength())
- {
- dwRet += dwRet ? 1 : 0;
- dwRet += m_strBcc.GetLength();
- }
- dwRet++;
- return dwRet;
- }
-
- // returns the recipients string to be (addresses only, in comma separated format)
- ATL_NOINLINE BOOL GetRecipientsString(__out_ecount_part_z(*pdwLen, *pdwLen) LPSTR szRecip, __inout LPDWORD pdwLen) throw()
- {
- if ( (szRecip == NULL) || (pdwLen == NULL) )
- {
- return FALSE;
- }
-
- if ( *pdwLen < GetRequiredRecipientsStringLength())
- {
- *pdwLen = GetRequiredRecipientsStringLength();
- return FALSE;
- }
-
- DWORD dwMaxLen = *pdwLen;
- *pdwLen = 0;
-
- DWORD dwLen = 0;
- DWORD dwTotalLen = 0;
- if (m_strTo.GetLength() > 0)
- {
- dwLen = *pdwLen - dwTotalLen;
- if (AtlMimeMakeRecipientsString(m_strTo, szRecip, &dwLen) != TRUE)
- {
- return FALSE;
- }
- szRecip+= dwLen;
- dwTotalLen = dwLen;
- }
-
- if (m_strCc.GetLength() > 0)
- {
- if (dwTotalLen)
- {
- *szRecip++ = ',';
- dwTotalLen++;
- }
- dwLen = *pdwLen - dwTotalLen;
- if (AtlMimeMakeRecipientsString(m_strCc, szRecip, &dwLen) != TRUE)
- {
- return FALSE;
- }
- szRecip+= dwLen;
- dwTotalLen+= dwLen;
- }
-
- if (m_strBcc.GetLength() > 0)
- {
- dwLen = m_strBcc.GetLength();
- if (dwTotalLen)
- {
- *szRecip++ = ',';
- dwTotalLen++;
- }
- dwLen = *pdwLen - dwTotalLen;
- Checked::memcpy_s(szRecip, dwMaxLen-dwTotalLen, m_strBcc, dwLen);
- szRecip+= dwLen;
- dwTotalLen+= dwLen;
- }
-
- *szRecip = '\0';
- *pdwLen = dwTotalLen;
-
- return TRUE;
- }
-
-
- // Get the sender
- inline LPCSTR GetSender() throw()
- {
- return m_strFrom;
- }
-
- // Set the sender
- inline BOOL SetSender(LPCTSTR szSender) throw()
- {
- if (szSender == NULL)
- return FALSE;
-
- _ATLTRY
- {
- m_strFrom = CT2CA(szSender);
- return TRUE;
- }
- _ATLCATCHALL()
- {
- return FALSE;
- }
- }
-
- // Set the subject
- inline BOOL SetSubject(LPCTSTR szSubject, UINT uiCodePage = 0) throw()
- {
- if (szSubject == NULL)
- return FALSE;
-
- _ATLTRY
- {
- CHeapPtr<char> szName;
- UINT nLen(0);
-
- BOOL bRet = AtlMimeConvertString(m_spMultiLanguage, uiCodePage, szSubject, &szName, &nLen);
- if (bRet)
- {
- m_strSubject.Empty();
- m_strSubject.Append(szName, (int)nLen);
- bRet = AtlMimeCharsetFromCodePage(m_szSubjectCharset, uiCodePage, m_spMultiLanguage, ATL_MAX_ENC_CHARSET_LENGTH);
- }
-
- return bRet;
- }
- _ATLCATCHALL()
- {
- return FALSE;
- }
- }
-
- // Get the subject
- inline LPCSTR GetSubject() throw()
- {
- return (LPCSTR)m_strSubject;
- }
-
- // Dump the header to hFile
- virtual inline BOOL WriteData(HANDLE hFile, LPOVERLAPPED pOverlapped, LPCSTR /*szBoundary*/, DWORD dwFlags = 0) throw()
- {
- if (pOverlapped == NULL)
- {
- return FALSE;
- }
-
- int nMaxSendLen = GetRequiredBufferSize(ATLSMTP_MAX_LINE_LENGTH-4);
- CHeapPtr<char> spSendBuffer;
- if (!spSendBuffer.Allocate(nMaxSendLen))
- return FALSE;
-
- // choose QEncode here, because the max QEncodeGetRequiredLength will always
- // return a value greater than BEncodeGetRequiredLength
- int nBufLen = __max(QEncodeGetRequiredLength(m_strSubject.GetLength(),
- ATL_MAX_ENC_CHARSET_LENGTH),
- QEncodeGetRequiredLength(m_strSenderName.GetLength(),
- ATL_MAX_ENC_CHARSET_LENGTH)+m_strFrom.GetLength()+2);
-
- CHeapPtr<char> spBuf;
- if (!spBuf.Allocate(nBufLen))
- return FALSE;
-
- int nMaxLen = nBufLen;
- DWORD dwOffset = 0;
-
- char szDate[ATL_MIME_DATE_LEN];
-
- SetRfc822Time(szDate, ATL_MIME_DATE_LEN);
- char *pSendBuffer = spSendBuffer;
-
- DWORD dwLength = (DWORD) strlen(szDate);
-
- if(dwLength > ATLSMTP_MAX_LINE_LENGTH -2 -dwOffset )
- return FALSE;
-
- Checked::memcpy_s(pSendBuffer+dwOffset, nMaxSendLen-dwOffset, szDate, dwLength);
- dwOffset += dwLength;
- *(pSendBuffer+dwOffset++) = '\r';
- *(pSendBuffer+dwOffset++) = '\n';
-
- int dwHeaderPartLength = 0;
- *spBuf = '\0';
-
- // Get the sender name
- BOOL bRet = TRUE;
- BOOL bEncoded = FALSE;
- if (m_strSenderName.GetLength() > 0)
- {
- bRet = GetEncodedString(m_strSenderName, m_szSenderCharset, spBuf, nBufLen, dwLength, bEncoded);
- dwHeaderPartLength += dwLength;
- }
-
- // Get the sender email address
- if (bRet && m_strFrom.GetLength() > 0)
- {
-
- if (dwHeaderPartLength != 0)
- {
- if(dwHeaderPartLength + 1 > nBufLen)
- return FALSE;
-
- *(spBuf+dwHeaderPartLength++) = ' ';
- }
-
- if(dwHeaderPartLength + m_strFrom.GetLength() + 2 > nBufLen)
- return FALSE;
-
- *(spBuf+dwHeaderPartLength++) = '<';
- if (dwHeaderPartLength < 0 || dwHeaderPartLength > nMaxLen)
- {
- return FALSE;
- }
- Checked::memcpy_s(spBuf+dwHeaderPartLength, nMaxLen-dwHeaderPartLength, (LPCSTR)m_strFrom, m_strFrom.GetLength());
- dwHeaderPartLength+= m_strFrom.GetLength();
- *(spBuf+dwHeaderPartLength++) = '>';
- }
-
- // Output the "From: " line
- if (bRet && dwHeaderPartLength != 0)
- {
- const char szFrom[] = "From: ";
- if(sizeof(szFrom)/sizeof(szFrom[0])-1 > ATLSMTP_MAX_LINE_LENGTH -2 -dwOffset )
- return FALSE;
- if (dwOffset > static_cast<DWORD>(nMaxSendLen))
- {
- return FALSE;
- }
- Checked::memcpy_s(pSendBuffer+dwOffset, nMaxSendLen-dwOffset, szFrom, _countof(szFrom)-1);
- dwOffset+= (sizeof(szFrom)/sizeof(szFrom[0])-1) ;
- DWORD dwWritten = ATLSMTP_MAX_LINE_LENGTH - 2 - dwOffset;
- bRet = FormatField((LPBYTE)(char*)spBuf, dwHeaderPartLength, (LPBYTE)(pSendBuffer+dwOffset), &dwWritten, dwFlags);
- dwOffset += dwWritten;
- *(pSendBuffer+dwOffset++) = '\r';
- *(pSendBuffer+dwOffset++) = '\n';
- }
-
- // Output the subject
- if (bRet && m_strSubject.GetLength() > 0)
- {
- dwLength = 0;
- bRet = GetEncodedString(m_strSubject, m_szSubjectCharset, spBuf, nBufLen, dwLength, bEncoded);
- if (bRet && dwLength != 0)
- {
- const char szSubject[] = "Subject: ";
- if(sizeof(szSubject)/sizeof(szSubject[0])-1 > ATLSMTP_MAX_LINE_LENGTH -2 -dwOffset )
- return FALSE;
- if (dwOffset > static_cast<DWORD>(nMaxSendLen))
- {
- return FALSE;
- }
- Checked::memcpy_s(pSendBuffer+dwOffset, nMaxSendLen-dwOffset, szSubject, _countof(szSubject)-1);
- dwOffset+= (sizeof(szSubject)/sizeof(szSubject[0])-1);
- DWORD dwWritten = ATLSMTP_MAX_LINE_LENGTH - 2 - dwOffset;
- bRet = FormatField((LPBYTE)(char*)spBuf, dwLength, (LPBYTE)(pSendBuffer+dwOffset), &dwWritten, dwFlags);
- dwOffset += dwWritten;
- *(pSendBuffer+dwOffset++) = '\r';
- *(pSendBuffer+dwOffset++) = '\n';
- }
- }
-
- // Output the "To:" line
- if (bRet && m_strTo.GetLength() > 0)
- {
- const char szTo[] = "To: ";
- if(sizeof(szTo)/sizeof(szTo[0])-1 > ATLSMTP_MAX_LINE_LENGTH -2 -dwOffset )
- return FALSE;
- if (dwOffset > static_cast<DWORD>(nMaxSendLen))
- {
- return FALSE;
- }
- Checked::memcpy_s(pSendBuffer+dwOffset, nMaxSendLen-dwOffset, szTo, _countof(szTo)-1);
- dwOffset+= (sizeof(szTo)/sizeof(szTo[0]) -1);
- DWORD dwWritten = ATLSMTP_MAX_LINE_LENGTH - 2 - dwOffset;
- bRet = FormatRecipients((LPBYTE)((LPCSTR)m_strTo), m_strTo.GetLength(), (LPBYTE)(pSendBuffer+dwOffset), &dwWritten);
- dwOffset+= dwWritten;
- *(pSendBuffer+dwOffset++) = '\r';
- *(pSendBuffer+dwOffset++) = '\n';
- }
-
- // Output the "CC:" line
- if (bRet && m_strCc.GetLength() > 0)
- {
- const char szCC[] = "CC: ";
- if(sizeof(szCC)/sizeof(szCC[0])-1 > ATLSMTP_MAX_LINE_LENGTH -2 -dwOffset )
- return FALSE;
- if (dwOffset > static_cast<DWORD>(nMaxSendLen))
- {
- return FALSE;
- }
- Checked::memcpy_s(pSendBuffer+dwOffset, nMaxSendLen-dwOffset, szCC, _countof(szCC)-1);
- dwOffset+= (sizeof(szCC)/sizeof(szCC[0]) -1);
- DWORD dwWritten = ATLSMTP_MAX_LINE_LENGTH - 2 - dwOffset;
- bRet = FormatRecipients((LPBYTE)((LPCSTR)m_strCc), m_strCc.GetLength(), (LPBYTE)(pSendBuffer+dwOffset), &dwWritten);
- dwOffset+= dwWritten;
- *(pSendBuffer+dwOffset++) = '\r';
- *(pSendBuffer+dwOffset++) = '\n';
- }
-
- // Send the header
- if (bRet && dwOffset)
- bRet = AtlSmtpSendAndWait(hFile, pSendBuffer, dwOffset, pOverlapped);
-
- return bRet;
- }
-
-protected:
-
- // Make the mime header
- virtual inline BOOL MakeMimeHeader(CStringA& /*header*/, LPCSTR /*szBoundary*/) throw()
- {
- // The message header does not have its own MIME header
- ATLASSERT(FALSE);
- return TRUE;
- }
-
- // Get an encoded string for a header field
- inline BOOL GetEncodedString(__in CStringA& headerString, __in LPCSTR szCharset, __out_ecount_part_z(nBufLen, dwLength) LPSTR szBuf, __in int nBufLen, __out DWORD& dwLength, __out BOOL& bEncoded) throw()
- {
-// BOOL bEncoded = FALSE;
- bEncoded = FALSE;
- if (m_spMultiLanguage.p)
- {
- // only encode if there are 8bit characters
- int nExtendedChars = GetExtendedChars(headerString, headerString.GetLength());
- if (nExtendedChars)
- {
- // choose smallest encoding
- if (((nExtendedChars*100)/headerString.GetLength()) < 17)
- {
- int nEncCnt = 0;
- if (!QEncode((LPBYTE)((LPCSTR)headerString), headerString.GetLength(), szBuf, &nBufLen, szCharset, &nEncCnt))
- {
- return FALSE;
- }
-
- //if no unsafe characters were encountered, just output it
- if (nEncCnt != 0)
- {
- bEncoded = TRUE;
- }
- }
- else
- {
- if (!BEncode((LPBYTE)((LPCSTR)headerString), headerString.GetLength(), szBuf, &nBufLen, szCharset))
- {
- return FALSE;
- }
-
- bEncoded = TRUE;
- }
- }
- }
-
- if (!bEncoded)
- {
- // there was no encoding
- dwLength = (DWORD) headerString.GetLength();
- if(dwLength > DWORD(nBufLen))
- return FALSE;
- Checked::memcpy_s(szBuf, nBufLen, headerString, dwLength);
- }
- else
- {
- dwLength = nBufLen;
- }
- return TRUE;
- }
-
-
- // Helper function for adding recipients
- inline BOOL AddRecipientHelper(CStringA& str, LPCTSTR szAddress, LPCTSTR szName = NULL, UINT uiCodePage = 0) throw()
- {
- if ((szAddress == NULL) && (szName == NULL))
- {
- return FALSE;
- }
-
- _ATLTRY
- {
- if (szName)
- {
- CHeapPtr<char> szNamePtr;
- UINT nLen(0);
-
- BOOL bRet = AtlMimeConvertString(m_spMultiLanguage, uiCodePage, szName, &szNamePtr, &nLen);
- if (bRet)
- {
- CStringA Name(szNamePtr, (int)nLen);
-
- char szCharset[ATL_MAX_ENC_CHARSET_LENGTH];
-
- if (!AtlMimeCharsetFromCodePage(szCharset, uiCodePage, m_spMultiLanguage, ATL_MAX_ENC_CHARSET_LENGTH))
- {
- return FALSE;
- }
-
- CFixedStringT<CStringA, 256> strBuf;
-
- int nBufLen = QEncodeGetRequiredLength(Name.GetLength(),
- ATL_MAX_ENC_CHARSET_LENGTH)+1;
-
- char * szBuf = strBuf.GetBuffer(nBufLen);
- if (szBuf == NULL)
- {
- return FALSE;
- }
-
- DWORD dwLength = 0;
- BOOL bEncoded = FALSE;
- if (!GetEncodedString(Name, szCharset, szBuf, nBufLen, dwLength, bEncoded))
- {
- strBuf.ReleaseBuffer();
- return FALSE;
- }
-
- strBuf.ReleaseBuffer(dwLength);
-
- // append comma if there are existing recipients
- if (str.GetLength() != 0)
- {
- str.Append(", ", 2);
- }
-
- if (bEncoded == FALSE)
- {
- // need to escape the string if no encoding
- strBuf.Replace("\\", "\\\\");
- strBuf.Replace("\"", "\\\"");
-
- // wrap the unescaped name in quotes
- str.Append("\"", 1);
- }
- str += strBuf;
- if (bEncoded == FALSE)
- {
- // close quote
- str.Append("\"", 1);
- }
- }
- else
- {
- return bRet;
- }
- }
-
- if (szAddress)
- {
- if (szName)
- {
- str.Append(" ", 1);
- }
- else
- {
- // append comma if there are existing recipients
- if (str.GetLength() != 0)
- {
- str.Append(", ", 2);
- }
- }
- str.Append("<", 1);
- str += CT2CA(szAddress);
- str.Append(">", 1);
- }
- return TRUE;
- }
- _ATLCATCHALL()
- {
- return FALSE;
- }
- }
-
- // Get the formatted header information
- inline BOOL FormatField(LPBYTE pbSrcData, int nSrcLen, LPBYTE pbDest,
- DWORD* pnBufLen, DWORD dwFlags = 0) throw()
- {
- if(pnBufLen == NULL)
- return FALSE;
-
- int nRead = 0;
-
- // 9 is the length of the maximum field name : "Subject :"
- // we set that here for simplicity
- int nLineLen = 9;
- DWORD nWritten = 0;
-
- //subtract 2 from these because it's easier for when we have
- //to break lines with a CRLF (and tab if necessary)
- int nMaxLineLength = ATLSMTP_MAX_LINE_LENGTH-3;
- while (nRead < nSrcLen)
- {
- //if we're at the end of the line, break it
- if (nLineLen == nMaxLineLength)
- {
- if( nWritten + 2 > *pnBufLen)
- return FALSE;
-
- *pbDest++ = '\r';
- *pbDest++ = '\n';
- nWritten+= 2;
- nLineLen = -1;
-
- if ((dwFlags & ATLSMTP_FORMAT_SMTP))
- {
- if(nWritten + 1 > *pnBufLen)
- return FALSE;
-
- *pbDest++ = '\t';
- nWritten++;
- nLineLen++;
- }
- }
-
- //if we hit a CRLF, reset nLineLen
- if (*pbSrcData == '\n' && nRead > 0 && *(pbSrcData-1) == '\r')
- {
- nLineLen = -1;
- }
-
- if(nWritten + 1 > *pnBufLen)
- return FALSE;
-
- *pbDest++ = *pbSrcData++;
- nRead++;
- nWritten++;
- nLineLen++;
- }
-
- *pnBufLen = (DWORD)nWritten;
-
- return TRUE;
- }
-
-
- // Get the formatted recipient information
- inline BOOL FormatRecipients(LPBYTE pbSrcData, int nSrcLen, LPBYTE pbDest,
- DWORD* pnBufLen) throw()
- {
-
- if(pnBufLen == NULL)
- return FALSE;
-
- int nRead = 0;
- DWORD nWritten = 0;
-
- while (nRead < nSrcLen)
- {
- if (*pbSrcData == ',')
- {
- if(nWritten + 4 > *pnBufLen)
- return FALSE;
-
- *pbDest++ = *pbSrcData++;
- nRead++;
- if (nRead+1 <= nSrcLen && *pbSrcData == ' ')
- {
- pbSrcData++;
- nRead++;
- }
- *pbDest++ = '\r';
- *pbDest++ = '\n';
- *pbDest++ = '\t';
- nWritten+= 4;
-
- continue;
- }
-
- if(nWritten + 1 > *pnBufLen)
- return FALSE;
-
- *pbDest++ = *pbSrcData++;
- nRead++;
- nWritten++;
- }
-
- *pnBufLen = nWritten;
-
- return TRUE;
- }
-
- // Get the required buffer size for the header
- inline int GetRequiredBufferSize(int nMaxLineLength) throw()
- {
- const static DWORD DATELINE = 27;
- const static DWORD FROMLINE = 10;
- const static DWORD TOLINE = 6;
- const static DWORD CCLINE = 6;
- const static DWORD SUBJECTLINE = 11;
-
- //data lengths (QEncoding potentially takes up more space than BEncoding,
- //so default to it)
- int nRequiredLength = QEncodeGetRequiredLength(m_strSenderName.GetLength(), ATL_MAX_ENC_CHARSET_LENGTH)
- +QEncodeGetRequiredLength(m_strSubject.GetLength(), ATL_MAX_ENC_CHARSET_LENGTH);
- nRequiredLength += m_strFrom.GetLength()+m_strTo.GetLength()+m_strCc.GetLength();
-
- //Add space for date
- nRequiredLength += DATELINE;
-
- //Add space for From: line
- nRequiredLength += FROMLINE;
-
- //Add space for To: line
- nRequiredLength += TOLINE;
-
- //Add space for Cc: line
- nRequiredLength += CCLINE;
-
- //Add space for Subject: line
- nRequiredLength += SUBJECTLINE;
-
- //Add space for line breaks and tabs
- nRequiredLength += 3*(nRequiredLength/nMaxLineLength);
-
- //Trailing CRLF
- nRequiredLength += 2;
-
- return nRequiredLength;
- }
-
-}; // class CMimeHeader
-
-
-// CMimeAttachment is an abstract base class for MIME message attachments.
-// It serves as a base class for CMimeFileAttachment and CMimeRawAttachment
-class CMimeAttachment : public CMimeBodyPart
-{
-protected:
-
- // the encoding scheme (ATLSMTP_BASE64_ENCODE, ATLSMTP_UUENCODE, ATLSMTP_QP_ENCODE)
- int m_nEncodingScheme;
-
- // the content type of the attachment
- CStringA m_ContentType;
-
- // the character set
- char m_szCharset[ATL_MAX_ENC_CHARSET_LENGTH];
-
- // the encode string ("base64", "quoted-printable", "uuencode")
- char *m_pszEncodeString;
-
- // the display name of the attachment
- TCHAR m_szDisplayName[_MAX_FNAME];
-
-public:
- CMimeAttachment() throw()
- :m_nEncodingScheme(ATLSMTP_BASE64_ENCODE), m_pszEncodeString(NULL)
- {
- m_szCharset[0] = 0;
- m_szDisplayName[0] = 0;
- }
-
- virtual ~CMimeAttachment() throw()
- {
- }
-
- // CMimeFileAttachment and CMimeRawAttachment have to handle their own dumping
- virtual inline BOOL WriteData(HANDLE hFile, LPOVERLAPPED pOverlapped, LPCSTR szBoundary, DWORD dwFlags = 0) = 0;
-
- // Set the encoding scheme of the attachment
- inline BOOL SetEncodingScheme(int nScheme) throw()
- {
- if (nScheme != ATLSMTP_BASE64_ENCODE && nScheme != ATLSMTP_UUENCODE && nScheme != ATLSMTP_QP_ENCODE)
- {
- return FALSE;
- }
-
- m_nEncodingScheme = nScheme;
- return TRUE;
- }
-
- // Set the Content-Type of the attachment
- inline BOOL SetContentType(LPCTSTR szContent) throw()
- {
- _ATLTRY
- {
- m_ContentType = CT2CA(szContent);
- return TRUE;
- }
- _ATLCATCHALL()
- {
- return FALSE;
- }
- }
-
- // Get the content type of the attachment
- virtual inline LPCSTR GetContentType() throw()
- {
- return m_ContentType;
- }
-
- // Get the character set of the attachment
- virtual inline LPCSTR GetCharset() throw()
- {
- return m_szCharset;
- }
-
- virtual ATL_NOINLINE CMimeBodyPart* Copy() = 0;
-
- const CMimeAttachment& operator=(const CMimeAttachment& that) throw( ... )
- {
- if (this != &that)
- {
- m_nEncodingScheme = that.m_nEncodingScheme;
- m_ContentType = that.m_ContentType;
- Checked::strcpy_s(m_szCharset, ATL_MAX_ENC_CHARSET_LENGTH, that.m_szCharset);
- m_pszEncodeString = that.m_pszEncodeString;
- Checked::tcscpy_s(m_szDisplayName, _countof(m_szDisplayName), that.m_szDisplayName);
- }
-
- return *this;
- }
-
-protected:
-
- // Make the MIME header for the attachment
- virtual inline BOOL MakeMimeHeader(CStringA& header, LPCSTR szBoundary) throw()
- {
- // if no display name is specified, default to "rawdata"
- return MakeMimeHeader(header, szBoundary, _T("rawdata"));
- }
-
- // Make the MIME header with the specified filename
- virtual inline BOOL MakeMimeHeader(CStringA& header, LPCSTR szBoundary, LPCTSTR szFileName)
- {
- ATLENSURE(szBoundary != NULL);
- ATLASSERT(szFileName != NULL);
- ATLASSUME(m_pszEncodeString != NULL);
-
- char szBegin[256];
- if (*szBoundary)
- {
- // this is not the only body part
- Checked::memcpy_s(szBegin, 256, ATLMIME_SEPARATOR, sizeof(ATLMIME_SEPARATOR));
- Checked::memcpy_s(szBegin+6, 250, szBoundary, ATL_MIME_BOUNDARYLEN);
- *(szBegin+(ATL_MIME_BOUNDARYLEN+6)) = '\0';
- }
- else
- {
- // this is the only body part, so output the MIME header
- Checked::memcpy_s(szBegin, 256, ATLMIME_VERSION, sizeof(ATLMIME_VERSION));
- }
-
- // Get file name with the path stripped out
- TCHAR szFile[MAX_PATH+1];
- TCHAR szExt[_MAX_EXT+1];
- Checked::tsplitpath_s(szFileName, NULL, 0, NULL, 0, szFile, _countof(szFile), szExt, _countof(szExt));
- Checked::tcscat_s(szFile, _countof(szFile), szExt);
-
- _ATLTRY
- {
- CT2CAEX<MAX_PATH+1> szFileNameA(szFile);
-
- CStringA szDisplayName(szFile);
- if (m_szDisplayName[0] != '\0')
- {
- szDisplayName = CT2CAEX<_MAX_FNAME+1>(m_szDisplayName);
- }
-
- header.Format("%s\r\nContent-Type: %s;\r\n\tcharset=\"%s\"\r\n\tname=\"%s\"\r\n"
- "Content-Transfer-Encoding: %s\r\nContent-Disposition: attachment;\r\n\tfilename=\"%s\"\r\n\r\n",
- szBegin, (LPCSTR) m_ContentType, m_szCharset, (LPCSTR) szDisplayName, m_pszEncodeString, (LPCSTR) szFileNameA);
- return TRUE;
- }
- _ATLCATCHALL()
- {
- return FALSE;
- }
- }
-
- // Get encoding information
- inline BOOL GetEncodingInformation(int* pnRequiredLength, int* pnLineLength)
- {
- ATLENSURE(pnRequiredLength != NULL);
- ATLENSURE(pnLineLength != NULL);
-
- switch(m_nEncodingScheme)
- {
- case ATLSMTP_BASE64_ENCODE:
- m_pszEncodeString = "base64";
- *pnLineLength = ATLSMTP_MAX_BASE64_LINE_LENGTH;
- *pnRequiredLength = Base64EncodeGetRequiredLength(ATLSMTP_MAX_BASE64_LINE_LENGTH);
- break;
- case ATLSMTP_UUENCODE:
- m_pszEncodeString ="uuencode";
- *pnLineLength = ATLSMTP_MAX_UUENCODE_LINE_LENGTH;
- *pnRequiredLength = UUEncodeGetRequiredLength(ATLSMTP_MAX_UUENCODE_LINE_LENGTH);
- break;
- case ATLSMTP_QP_ENCODE:
- m_pszEncodeString = "quoted-printable";
- *pnLineLength = ATLSMTP_MAX_QP_LINE_LENGTH;
- *pnRequiredLength = QPEncodeGetRequiredLength(ATLSMTP_MAX_QP_LINE_LENGTH);
- break;
- default:
- return FALSE;
- }
- return TRUE;
- }
-
-}; // class CMimeAttachment
-
-
-// CMimeFileAttachment represents a MIME file attachment body part
-class CMimeFileAttachment : public CMimeAttachment
-{
-
-protected:
- // The filename
- TCHAR m_szFileName[MAX_PATH+1];
-
-public:
- CMimeFileAttachment() throw()
- {
- m_szFileName[0] = 0;
- }
-
- virtual ATL_NOINLINE CMimeBodyPart* Copy() throw( ... )
- {
- CAutoPtr<CMimeFileAttachment> pNewAttachment;
- ATLTRY(pNewAttachment.Attach(new CMimeFileAttachment));
- if (pNewAttachment)
- *pNewAttachment = *this;
-
- return pNewAttachment.Detach();
- }
-
- const CMimeFileAttachment& operator=(const CMimeFileAttachment& that) throw( ... )
- {
- if (this != &that)
- {
- CMimeAttachment::operator=(that);
- Checked::tcscpy_s(m_szFileName, _countof(m_szFileName), that.m_szFileName);
- }
-
- return *this;
- }
-
-
- // Initialize the file attachment
- // szFileName - the actual file name
- // szDisplayName - the display name for the file (optional)
- // pMultiLanguage - the IMulitLanguage pointer for codepage to charset conversion (optional)
- // uiCodePage - the code page (optional)
- inline BOOL Initialize(LPCTSTR szFileName, LPCTSTR szDisplayName = NULL, IMultiLanguage* pMultiLanguage = NULL, UINT uiCodePage = 0) throw()
- {
- if (!AtlMimeCharsetFromCodePage(m_szCharset, uiCodePage, pMultiLanguage, ATL_MAX_ENC_CHARSET_LENGTH))
- return FALSE;
-
- if( _tcslen(szFileName) > MAX_PATH )
- {
- return FALSE;
- }
- Checked::tcscpy_s(m_szFileName, _countof(m_szFileName), szFileName);
-
- if (szDisplayName)
- {
- // use the user-specified display name
- size_t nLen = _tcslen(szDisplayName)+1;
- if (nLen <= _countof(m_szDisplayName))
- {
- Checked::tcscpy_s(m_szDisplayName, _countof(m_szDisplayName), szDisplayName);
- }
- else
- {
- Checked::tcsncpy_s(m_szDisplayName, _countof(m_szDisplayName), szDisplayName, _countof(m_szDisplayName) - 4);
- Checked::tcscpy_s(m_szDisplayName + _countof(m_szDisplayName) - 4, 4, _T("..."));
- }
- }
- else
- {
- // otherwise there is no display name
- *m_szDisplayName = '\0';
- }
- return TRUE;
- }
-
- // Dump the data for the file attachment
- virtual inline BOOL WriteData(HANDLE hFile, LPOVERLAPPED pOverlapped, LPCSTR szBoundary, DWORD dwFlags = 0) throw()
- {
- if ((pOverlapped == NULL) || (szBoundary == NULL))
- {
- return FALSE;
- }
-
- int nLineLength = 0;
- int nRequiredLength = 0;
-
- if (!GetEncodingInformation(&nRequiredLength, &nLineLength))
- return FALSE;
-
- //Try to open the file that is being attached
- CAtlFile readFile;
- if (FAILED(readFile.Create(m_szFileName, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING)))
- return FALSE;
-
- //Make the mime header
- CStringA header;
- if (!MakeMimeHeader(header, szBoundary, m_szFileName))
- {
- return FALSE;
- }
-
- //Try to send the mime header
- if (!AtlSmtpSendAndWait(hFile, ((LPCSTR)header), header.GetLength(), pOverlapped))
- {
- return FALSE;
- }
-
- int nGetLines = ATLSMTP_GET_LINES;
-
- nRequiredLength *= nGetLines;
-
- //dwToGet is the total number of characters to attempt to get
- DWORD dwToGet = (DWORD)nGetLines*nLineLength;
-
- //allocate the data array
- CHeapPtr<BYTE> spData;
- if (!spData.Allocate(dwToGet+1))
- return FALSE;
-
-// if double buffering is defined, create two buffers
-#ifdef ATLSMTP_DOUBLE_BUFFERED
- CHeapPtr<char> buffer1;
- if (!buffer1.Allocate(nRequiredLength+3))
- return FALSE;
-
- CHeapPtr<char> buffer2;
- if (!buffer2.Allocate(nRequiredLength+3))
- return FALSE;
-
- char* currBuffer = buffer1;
- char* prevBuffer = NULL;
- int nCurrBuffer = 0;
- DWORD dwPrevLength = 0;
-#else
- CHeapPtr<char> currBuffer;
- if (!currBuffer.Allocate(nRequiredLength+3))
- return FALSE;
-
-#endif // ATLSMTP_DOUBLE_BUFFERED
-
- int nEncodedLength = nRequiredLength;
- BOOL bRet = FALSE;
- DWORD dwRead = 0;
- DWORD dwTotalRead = 0;
- DWORD dwCurrRead = 0;
-
- do
- {
- do
- {
- //Read a chunk of data from the file increment buffer offsets and amount to read
- //based on what's already been read in this iteration of the loop
- HRESULT hr = readFile.Read(((LPBYTE)spData)+dwCurrRead, dwToGet-dwCurrRead, dwRead);
- if (FAILED(hr))
- {
- if (hr != AtlHresultFromWin32(ERROR_MORE_DATA))
- {
- return FALSE;
- }
- }
- dwCurrRead += dwRead;
-
- } while (dwRead != 0 && dwCurrRead < dwToGet);
-
- //reset nEncodedLength
- nEncodedLength = nRequiredLength;
- switch (m_nEncodingScheme)
- {
- case ATLSMTP_BASE64_ENCODE:
- //if we are at the end of input (dwCurrRead < dwToGet), output the trailing padding if necessary
- //(ATL_FLAG_NONE)
- bRet = Base64Encode(spData, dwCurrRead, currBuffer, &nEncodedLength,
- (dwCurrRead < dwToGet ? ATL_BASE64_FLAG_NONE: ATL_BASE64_FLAG_NOPAD));
- //Base64Encoding needs explicit CRLF added
- if (dwCurrRead < dwToGet)
- {
- currBuffer[nEncodedLength++] = '\r';
- currBuffer[nEncodedLength++] = '\n';
- }
- break;
- case ATLSMTP_UUENCODE:
- //if we are at the beginning of the input, output the header (ATL_UUENCODE_HEADER)
- //if we are the end of input (dwCurrRead < dwToGet), output the 'end'
- //we are encoding for purposes of sending mail, so stuff dots (ATL_UUENCODE_DOT)
- bRet = UUEncode(spData, dwCurrRead, currBuffer, &nEncodedLength, m_szFileName,
- (dwTotalRead > 0 ? 0 : ATLSMTP_UUENCODE_HEADER) |
- (dwCurrRead < dwToGet ? ATLSMTP_UUENCODE_END : 0) |
- ((dwFlags & ATLSMTP_FORMAT_SMTP) ? ATLSMTP_UUENCODE_DOT : 0));
- break;
- case ATLSMTP_QP_ENCODE:
- //we are encoding for purposes of sending mail, so stuff dots
- bRet = QPEncode(spData, dwCurrRead, currBuffer, &nEncodedLength,
- ((dwFlags & ATLSMTP_FORMAT_SMTP) ? ATLSMTP_QPENCODE_DOT : 0) |
- (dwCurrRead < dwToGet ? 0 : ATLSMTP_QPENCODE_TRAILING_SOFT));
- break;
- }
- //try to send the encoded data
-#ifdef ATLSMTP_DOUBLE_BUFFERED
- if (bRet)
- {
- bRet = AtlSmtpSendOverlapped(hFile, currBuffer, nEncodedLength,
- prevBuffer, dwPrevLength, pOverlapped);
- }
-
- //swap the buffers
- dwPrevLength = nEncodedLength;
- prevBuffer = currBuffer;
- currBuffer = (nCurrBuffer == 0 ? buffer2 : buffer1);
- nCurrBuffer = (nCurrBuffer == 0 ? 1 : 0);
-#else
- if (bRet)
- {
- bRet = AtlSmtpSendAndWait(hFile, currBuffer, nEncodedLength, pOverlapped);
- }
-#endif // ATLSMTP_DOUBLE_BUFFERED
-
- dwTotalRead += dwCurrRead;
- if (dwRead != 0)
- dwCurrRead = 0;
-
- nEncodedLength = nRequiredLength;
-
- } while (dwRead != 0 && bRet);
-
- //ensure that the last Send sent all the data
-#ifdef ATLSMTP_DOUBLE_BUFFERED
- DWORD dwWritten = 0, dwErr = 0;
- if (!GetOverlappedResult(hFile, pOverlapped, &dwWritten, TRUE))
- {
- if ((dwErr = GetLastError()) != ERROR_IO_PENDING && dwErr != ERROR_IO_INCOMPLETE)
- {
- bRet = FALSE;
- }
- else if (dwWritten < dwPrevLength)
- {
- bRet = AtlSmtpSendAndWait(hFile, prevBuffer+dwWritten,
- dwPrevLength-dwWritten, pOverlapped);
- }
- }
-#endif // ATLSMTP_DOUBLE_BUFFERED
-
- //for uuencoding, if the last chunk read was of size dwToGet, but it was also the end of the file,
- //the "end" keyword will not get encoded, so a check is necessary
- if (m_nEncodingScheme == ATLSMTP_UUENCODE && dwCurrRead == dwToGet)
- {
- bRet = UUEncode(spData, 0, currBuffer, &nEncodedLength, m_szFileName,
- (dwFlags & ATLSMTP_FORMAT_SMTP ? ATLSMTP_UUENCODE_DOT : 0) |
- ATLSMTP_UUENCODE_END);
- if (bRet)
- {
- bRet = AtlSmtpSendAndWait(hFile, currBuffer, nEncodedLength, pOverlapped);
- }
- }
-
- return bRet;
- }
-}; // class CMimeFileAttachment
-
-// CMimeRawAttachment represents a file attachment MIME body part.
-// The data provided is not a file, but a blob of raw data.
-class CMimeRawAttachment : public CMimeAttachment
-{
-protected:
-
- //the raw data
- void* m_pvRaw;
-
- //the length
- DWORD m_dwLength;
-
- //whether or not we own it
- bool m_bShared;
-
-public:
- CMimeRawAttachment() throw()
- :m_dwLength(0), m_bShared(false), m_pvRaw(NULL)
- {
- }
-
- ~CMimeRawAttachment() throw()
- {
- //If we own the raw data, free it
- if (!m_bShared && m_pvRaw)
- free(m_pvRaw);
- }
-
- virtual ATL_NOINLINE CMimeBodyPart* Copy() throw( ... )
- {
- CAutoPtr<CMimeRawAttachment> pNewAttachment;
- ATLTRY(pNewAttachment.Attach(new CMimeRawAttachment));
- if (pNewAttachment)
- *pNewAttachment = *this;
-
- return pNewAttachment.Detach();
- }
-
- const CMimeRawAttachment& operator=(const CMimeRawAttachment& that) throw( ... )
- {
- if (this != &that)
- {
- CMimeAttachment::operator=(that);
- if (!m_bShared && m_pvRaw)
- free(m_pvRaw);
-
- m_bShared = that.m_bShared;
- m_dwLength = that.m_dwLength;
-
- if (m_bShared)
- {
- m_pvRaw = that.m_pvRaw;
- }
- else
- {
- m_pvRaw = malloc(m_dwLength);
- if (m_pvRaw)
- {
- Checked::memcpy_s(m_pvRaw, m_dwLength, that.m_pvRaw, m_dwLength);
- }
- }
- }
-
- return *this;
- }
-
- // Initialize the attachment
- // pData - the data
- // nDataLength - the size of pData in BYTEs
- // bCopyData - flag specifying whether CMimeRawAttachment should make a copy of the data (optional)
- // pMultiLanguage - the IMultiLanguage pointer for codepage to character set conversion (optional)
- // uiCodePage - the codepage (optional)
- inline BOOL Initialize(void* pData, DWORD nDataLength, BOOL bCopyData = TRUE, LPCTSTR szDisplayName = NULL,
- IMultiLanguage* pMultiLanguage = NULL, UINT uiCodePage = 0) throw()
- {
- // if we're already attached to some data, and it's not shared, free it
- if (m_pvRaw && !m_bShared)
- free(m_pvRaw);
- m_pvRaw = NULL;
-
- m_dwLength = nDataLength;
- if (bCopyData)
- {
- m_pvRaw = calloc(sizeof(BYTE),m_dwLength);
- if (!m_pvRaw)
- {
- return FALSE;
- }
- Checked::memcpy_s(m_pvRaw, m_dwLength, pData, m_dwLength);
- m_bShared = false;
- }
- else
- {
- m_pvRaw = pData;
- m_bShared = true;
- }
-
- if (!AtlMimeCharsetFromCodePage(m_szCharset, uiCodePage, pMultiLanguage, ATL_MAX_ENC_CHARSET_LENGTH))
- return FALSE;
-
- if (szDisplayName)
- {
- // use the user-specified display name
- Checked::tcscpy_s(m_szDisplayName, _countof(m_szDisplayName), szDisplayName);
- m_szDisplayName[_countof(m_szDisplayName)-1] = 0;
- }
- else
- {
- // no display name
- *m_szDisplayName = '\0';
- }
- return TRUE;
- }
-
- // Output the data--similar to CFileAttachment::WriteData
- // See CFileAttachment::WriteData for comments
- virtual inline BOOL WriteData(HANDLE hFile, LPOVERLAPPED pOverlapped, LPCSTR szBoundary, DWORD dwFlags = 0) throw()
- {
- if ((pOverlapped == NULL) || (szBoundary == NULL))
- {
- return FALSE;
- }
-
- if (!m_pvRaw)
- return FALSE;
-
- int nLineLength = 0, nRequiredLength = 0;
- if (!GetEncodingInformation(&nRequiredLength, &nLineLength))
- return FALSE;
-
- CStringA header;
-
- if (!MakeMimeHeader(header, szBoundary))
- {
- return FALSE;
- }
-
- if (!AtlSmtpSendAndWait(hFile, ((LPCSTR)header), header.GetLength(), pOverlapped))
- {
- return FALSE;
- }
-
- int nGetLines = ATLSMTP_GET_LINES;
- DWORD dwCurrChunk = 0;
- nRequiredLength *= nGetLines;
- DWORD dwToGet = (DWORD)nGetLines*nLineLength;
- int nDestLen = nRequiredLength;
- BOOL bRet = FALSE;
- DWORD dwRead = 0;
-#ifdef ATLSMTP_DOUBLE_BUFFERED
- CHeapPtr<char> buffer1;
- if (!buffer1.Allocate(nRequiredLength+3))
- return FALSE;
-
- CHeapPtr<char> buffer2;
- if (!buffer2.Allocate(nRequiredLength+3))
- return FALSE;
-
- char* currBuffer = buffer1;
- char* prevBuffer = NULL;
- int nCurrBuffer = 0;
- DWORD dwPrevLength = 0;
-#else
- CHeapPtr<char> currBuffer;
- if (!currBuffer.Allocate(nRequiredLength+3))
- return FALSE;
-#endif // ATLSMTP_DOUBLE_BUFFERED
-
- do
- {
- if ((m_dwLength-dwRead) <= dwToGet)
- dwCurrChunk = m_dwLength-dwRead;
- else
- dwCurrChunk = dwToGet;
- switch(m_nEncodingScheme)
- {
- case ATLSMTP_BASE64_ENCODE:
- bRet = Base64Encode(((LPBYTE)(m_pvRaw))+dwRead, dwCurrChunk, currBuffer, &nDestLen,
- (dwRead < m_dwLength) ? ATL_BASE64_FLAG_NONE : ATL_BASE64_FLAG_NOPAD);
- if (dwRead+dwCurrChunk == m_dwLength)
- {
- currBuffer[nDestLen++] = '\r';
- currBuffer[nDestLen++] = '\n';
- }
- break;
- case ATLSMTP_UUENCODE:
- bRet = UUEncode(((LPBYTE)(m_pvRaw))+dwRead, dwCurrChunk, currBuffer, &nDestLen, _T("rawdata"),
- (dwRead > 0 ? 0 : ATLSMTP_UUENCODE_HEADER) |
- (dwRead+dwCurrChunk == m_dwLength ? ATLSMTP_UUENCODE_END : 0) |
- ((dwFlags & ATLSMTP_FORMAT_SMTP) ? ATLSMTP_UUENCODE_DOT : 0));
- break;
- case ATLSMTP_QP_ENCODE:
- bRet = QPEncode(((LPBYTE)(m_pvRaw))+dwRead, dwCurrChunk, currBuffer, &nDestLen,
- ((dwFlags & ATLSMTP_FORMAT_SMTP) ? ATLSMTP_QPENCODE_DOT : 0) |
- (dwRead+dwCurrChunk == m_dwLength ? 0 : ATLSMTP_QPENCODE_TRAILING_SOFT));
- break;
- }
- if (!bRet)
- break;
-#ifdef ATLSMTP_DOUBLE_BUFFERED
- bRet = AtlSmtpSendOverlapped(hFile, currBuffer, nDestLen, prevBuffer, dwPrevLength, pOverlapped);
- dwPrevLength = (DWORD)nDestLen;
- prevBuffer = currBuffer;
- currBuffer = (nCurrBuffer == 0 ? buffer2 : buffer1);
- nCurrBuffer = (nCurrBuffer == 0 ? 1 : 0);
-#else
- bRet = AtlSmtpSendAndWait(hFile, currBuffer, nDestLen, pOverlapped);
-#endif // ATLSMTP_DOUBLE_BUFFERED
-
- nDestLen = nRequiredLength;
- dwRead += dwCurrChunk;
- } while (bRet && (dwRead < m_dwLength));
-
- //ensure all data is sent from prevBuffer
-#ifdef ATLSMTP_DOUBLE_BUFFERED
- DWORD dwWritten = 0, dwErr = 0;
- if (!GetOverlappedResult(hFile, pOverlapped, &dwWritten, TRUE))
- {
- if ((dwErr = GetLastError()) != ERROR_IO_PENDING && dwErr != ERROR_IO_INCOMPLETE)
- bRet = FALSE;
- else if (dwWritten < dwPrevLength)
- bRet = AtlSmtpSendAndWait(hFile, prevBuffer+dwWritten, dwPrevLength-dwWritten, pOverlapped);
- }
-#endif // ATLSMTP_DOUBLE_BUFFERED
-
- return bRet;
- }
-}; // class CMimeRawAttachment
-
-
-// CMimeText - represents a text body part in MIME body
-class CMimeText : public CMimeBodyPart
-{
-protected:
-
- // the text
- CHeapPtr<char> m_szText;
-
- // the character set
- char m_szCharset[ATL_MAX_ENC_CHARSET_LENGTH];
-
- // the text length
- int m_nTextLen;
-
-public:
- CMimeText() throw()
- :m_nTextLen(0)
- {
- Checked::strcpy_s(m_szCharset, ATL_MAX_ENC_CHARSET_LENGTH, ATLSMTP_DEFAULT_CSET);
- }
-
- virtual ~CMimeText() throw()
- {
- }
-
- // Get the content type
- virtual inline LPCSTR GetContentType() throw()
- {
- return "text/plain";
- }
-
- // Get the character set
- virtual inline LPCSTR GetCharset() throw()
- {
- return m_szCharset;
- }
-
- virtual ATL_NOINLINE CMimeBodyPart* Copy() throw( ... )
- {
- CAutoPtr<CMimeText> pNewText;
- ATLTRY(pNewText.Attach(new CMimeText));
- if (pNewText)
- *pNewText = *this;
-
- return pNewText.Detach();
- }
-
- const CMimeText& operator=(const CMimeText& that) throw( ... )
- {
- if (this != &that)
- {
- m_nTextLen = that.m_nTextLen;
- Checked::strcpy_s(m_szCharset, ATL_MAX_ENC_CHARSET_LENGTH, that.m_szCharset);
- m_szText.Free();
- if (m_szText.AllocateBytes(m_nTextLen) != false)
- {
- Checked::memcpy_s((char *)m_szText, m_nTextLen, (char *)that.m_szText, m_nTextLen);
- }
- }
-
- return *this;
- }
-
- // Initialize the body part
- // szText - the text (required)
- // nTextLen - the text length in bytes (optional--if not specified a _tcslen will be done)
- // pMultiLanguage - the IMultiLanguagte pointer for converting codepages to MIME character sets (optional)
- // uiCodePage - the codepage
- inline BOOL Initialize(LPCTSTR szText, int nTextLen = -1, IMultiLanguage* pMultiLanguage = NULL, UINT uiCodePage = 0) throw()
- {
- BOOL bRet = TRUE;
-
- // if IMultiLanguage is there, respect the codepage
- if (pMultiLanguage)
- {
- CHeapPtr<char> szTextPtr;
- UINT nLen(0);
-
- bRet = AtlMimeConvertString(pMultiLanguage, uiCodePage, szText, &szTextPtr, &nLen);
- if (bRet)
- {
- m_szText.Free();
- m_szText.Attach(szTextPtr.Detach());
- m_nTextLen = nLen;
- }
- }
- else // no multilanguage support
- {
- if (nTextLen < 0)
- {
- nTextLen = (int) _tcslen(szText);
- nTextLen*= sizeof(TCHAR);
- }
-
- m_szText.Free();
- if (m_szText.AllocateBytes(nTextLen) != false)
- {
- Checked::memcpy_s((char *)m_szText, nTextLen, szText, nTextLen);
- m_nTextLen = nTextLen;
- }
- }
-
- if (bRet)
- {
- bRet = AtlMimeCharsetFromCodePage(m_szCharset, uiCodePage, pMultiLanguage, ATL_MAX_ENC_CHARSET_LENGTH);
- }
-
- return bRet;
- }
-
- // Dump the data to hFile
- virtual inline BOOL WriteData(HANDLE hFile, LPOVERLAPPED pOverlapped, LPCSTR szBoundary, DWORD dwFlags = 0) throw()
- {
- if ((pOverlapped == NULL) || (szBoundary == NULL))
- {
- return FALSE;
- }
-
- CStringA strHeader;
- char sendBuffer[ATLSMTP_READBUFFER_SIZE];
- LPSTR pSendBuffer = sendBuffer;
- LPSTR szText = m_szText;
-
- if (!MakeMimeHeader(strHeader, szBoundary))
- {
- return FALSE;
- }
-
- //copy the header into the sendbuffer
- int nWritten = strHeader.GetLength();
- if(nWritten > ATLSMTP_READBUFFER_SIZE)
- return FALSE;
-
- Checked::memcpy_s(pSendBuffer, ATLSMTP_READBUFFER_SIZE, (LPCSTR)strHeader, nWritten);
- pSendBuffer+= nWritten;
- int nRead = 0;
- int nLineLen = 0;
-
- //subtract 2 from these because it's easier for when we have
- //to break lines with a CRLF
- int nMaxLineLength = ATLSMTP_MAX_LINE_LENGTH-2;
- int nMaxBufferSize = ATLSMTP_READBUFFER_SIZE-2;
- while (nRead <= m_nTextLen)
- {
- //if the buffer is full or we've reached the end of the text,
- //send it
- if (nWritten >= nMaxBufferSize || nRead == m_nTextLen)
- {
- if (!AtlSmtpSendAndWait(hFile, sendBuffer, nWritten, pOverlapped))
- return FALSE;
- nWritten = 0;
- pSendBuffer = sendBuffer;
- if (nRead == m_nTextLen)
- {
- break; // job done, no need to run the code below
- }
- }
-
- //if we're at the end of the line, break it
- if (nLineLen == nMaxLineLength)
- {
- if(nWritten + 2 > ATLSMTP_READBUFFER_SIZE)
- return FALSE;
- *pSendBuffer++ = '\r';
- *pSendBuffer++ = '\n';
- nWritten+= 2;
- nLineLen = -1;
- continue;
- }
-
- //stuff dots at the start of the line
- if (nLineLen == 0 && (dwFlags & ATLSMTP_FORMAT_SMTP) && *szText == '.')
- {
- if(nWritten + 1 > ATLSMTP_READBUFFER_SIZE)
- return FALSE;
- *pSendBuffer++ = '.';
- nWritten++;
- nLineLen++;
- continue;
- }
-
- //if we hit a CRLF, reset nLineLen
- if (*szText == '\n' && nRead > 0 && *(szText-1) == '\r')
- nLineLen = -1;
-
- if(nWritten + 1 > ATLSMTP_READBUFFER_SIZE)
- return FALSE;
- *pSendBuffer++ = (*szText++);
- nRead++;
- nWritten++;
- nLineLen++;
- }
-
- return TRUE;
- }
-
-protected:
-
- // Make the MIME header
- virtual inline BOOL MakeMimeHeader(CStringA& header, LPCSTR szBoundary) throw()
- {
- char szBegin[256];
- if (*szBoundary)
- {
- // this is not the only body part
- Checked::memcpy_s(szBegin, sizeof(szBegin), ATLMIME_SEPARATOR, sizeof(ATLMIME_SEPARATOR));
- Checked::memcpy_s(szBegin+6, sizeof(szBegin)-6, szBoundary, ATL_MIME_BOUNDARYLEN);
- *(szBegin+(ATL_MIME_BOUNDARYLEN+6)) = '\0';
- }
- else
- {
- // this is the only body part, so output the full MIME header
- Checked::memcpy_s(szBegin, sizeof(szBegin), ATLMIME_VERSION, sizeof(ATLMIME_VERSION));
- }
-
- _ATLTRY
- {
- header.Format("%s\r\nContent-Type: text/plain;\r\n\tcharset=\"%s\"\r\nContent-Transfer-Encoding: 8bit\r\n\r\n",
- szBegin, m_szCharset);
- return TRUE;
- }
- _ATLCATCHALL()
- {
- return FALSE;
- }
- }
-}; // class CMimeText
-
-
-// CMimeMessage - the MIME message class. Represents a full MIME message
-class CMimeMessage : public CMimeHeader
-{
-protected:
-
- // The list of the MIME body parts
- CAutoPtrList<CMimeBodyPart> m_BodyParts;
-
- // The display name of the message
- char m_szDisplayName[MAX_PATH+1];
-
-public:
- CMimeMessage(IMultiLanguage *pMultiLanguage = NULL) throw()
- {
- Initialize(pMultiLanguage);
- Checked::memcpy_s(m_szDisplayName, MAX_PATH+1, ATLMIME_EMAIL, sizeof(ATLMIME_EMAIL));
- }
-
- virtual ~CMimeMessage() throw()
- {
- RemoveParts();
- }
-
- void RemoveParts() throw()
- {
- m_BodyParts.RemoveAll();
- }
-
-
- virtual ATL_NOINLINE CMimeBodyPart* Copy() throw( ... )
- {
- CAutoPtr<CMimeMessage> pNewMessage;
- ATLTRY(pNewMessage.Attach(new CMimeMessage));
- if (pNewMessage)
- *pNewMessage = *this;
-
- return pNewMessage.Detach();
- }
-
-
- const CMimeMessage& operator=(const CMimeMessage& that) throw( ... )
- {
- if (this != &that)
- {
- CMimeHeader::operator=(that);
- Checked::strcpy_s(m_szDisplayName, MAX_PATH+1, that.m_szDisplayName);
-
- RemoveParts();
- POSITION pos = that.m_BodyParts.GetHeadPosition();
- while (pos != NULL)
- {
- CAutoPtr<CMimeBodyPart> pCopy(that.m_BodyParts.GetNext(pos)->Copy());
- if (pCopy)
- {
- m_BodyParts.AddTail(pCopy);
- }
- }
- }
-
- return *this;
- }
-
- // Set the display name of the message
- inline BOOL SetDisplayName(LPCTSTR szDisplayName) throw()
- {
- if (szDisplayName == NULL)
- {
- return FALSE;
- }
-
- _ATLTRY
- {
- CT2CA szDisplayNameA(szDisplayName);
- if (szDisplayNameA == NULL || strlen(szDisplayNameA) > MAX_PATH)
- return FALSE;
- Checked::strcpy_s(m_szDisplayName, MAX_PATH+1, szDisplayNameA);
- return TRUE;
- }
- _ATLCATCHALL()
- {
- return FALSE;
- }
- }
-
- // Add some text to the message at position nPos in the body parts list
- // szText - the text
- // nTextLen - the size of the text in bytes (optional - if not specified a _tcslen will be done)
- // nPos - the position in the message at which to insert the text (optional)
- // uiCodePage - the codepage (optional)
- inline BOOL AddText(LPCTSTR szText, int nTextLen = -1, int nPos = 1, UINT uiCodePage = 0) throw()
- {
- if (szText == NULL)
- return FALSE;
-
- if (nPos < 1)
- {
- nPos = 1;
- }
-
- CAutoPtr<CMimeBodyPart> spNewText;
- CMimeText *pNewText = NULL;
- ATLTRY(spNewText.Attach(pNewText = new CMimeText()));
- if (!spNewText || !pNewText)
- return FALSE;
-
- BOOL bRet = pNewText->Initialize(szText, nTextLen, m_spMultiLanguage, uiCodePage);
- if (bRet)
- {
- _ATLTRY
- {
- POSITION currPos = m_BodyParts.FindIndex(nPos-1);
-
- if (!currPos)
- {
- if (!m_BodyParts.AddTail(spNewText))
- bRet = FALSE;
- }
- else
- {
- if (!m_BodyParts.InsertBefore(currPos, spNewText))
- bRet = FALSE;
- }
-
- }
- _ATLCATCHALL()
- {
- bRet = FALSE;
- }
- }
-
- return bRet;
- }
-
- // Dump the data
- virtual BOOL WriteData(HANDLE hFile, LPOVERLAPPED pOverlapped, LPCSTR szBoundary=NULL, DWORD dwFlags = 0) throw()
- {
- if (pOverlapped == NULL)
- {
- return FALSE;
- }
-
- // Make the MIME boundary for this message
- char szBoundaryBuf[ATL_MIME_BOUNDARYLEN+1];
- if(MakeBoundary(szBoundaryBuf,ATL_MIME_BOUNDARYLEN+1) == FALSE)
- return FALSE;
-
- // if the passed boundary is valid, this is an attached message
- if (szBoundary && *szBoundary != '\0')
- {
- _ATLTRY
- {
- // output the MIME header for a message attachment
- CStringA strHeader;
- strHeader.Format("\r\n\r\n--%s\r\nContent-Type: message/rfc822\r\n\tname=\"%s\"\r\nContent-Transfer-Encoding: 8bit\r\n"
- "Content-Disposition: attachment;\r\n\tfilename=\"%s\"\r\n\r\n",
- szBoundary, m_szDisplayName, m_szDisplayName);
-
- if (!AtlSmtpSendAndWait(hFile, ((LPCSTR)strHeader), strHeader.GetLength(), pOverlapped))
- {
- return FALSE;
- }
- }
- _ATLCATCHALL()
- {
- return FALSE;
- }
- }
-
- if (!CMimeHeader::WriteData(hFile, pOverlapped, szBoundaryBuf, dwFlags))
- return FALSE;
-
- // Create and output the header
- CStringA strHeader;
-
- if (!MakeMimeHeader(strHeader, szBoundaryBuf))
- {
- return FALSE;
- }
-
- if (!AtlSmtpSendAndWait(hFile, ((LPCSTR)strHeader), strHeader.GetLength(), pOverlapped))
- {
- return FALSE;
- }
-
- CMimeBodyPart* pCurrPart;
- POSITION currPos = m_BodyParts.GetHeadPosition();
-
- //Dump the body parts
- while (currPos != NULL)
- {
- pCurrPart = m_BodyParts.GetAt(currPos);
- if (!pCurrPart->WriteData(hFile, pOverlapped, szBoundaryBuf, dwFlags))
- {
- return FALSE;
- }
- m_BodyParts.GetNext(currPos);
- }
-
- char szBuf[ATL_MIME_BOUNDARYLEN+(sizeof("\r\n\r\n--%s--\r\n"))];
- //output a trailing boundary
- if (*szBoundaryBuf)
- {
- int nBufLen = sprintf_s(szBuf, ATL_MIME_BOUNDARYLEN+(sizeof("\r\n\r\n--%s--\r\n")),
- "\r\n\r\n--%s--\r\n", szBoundaryBuf);
- if ((nBufLen < 0) || (!AtlSmtpSendAndWait(hFile, szBuf, nBufLen, pOverlapped)))
- {
- return FALSE;
- }
- }
-
- return TRUE;
- }
-
- // Attach a file.
- // szFileName - the filename
- // szDisplayName - the display name (optional)
- // szContentType - the content type (optional - defaults to NULL -- lookup will be attempted, otherwise default to application/octet-stream)
- // nEncodingScheme - the encoding scheme to use for the attachment (optional - defaults to base64
- // uiCodePage - the codepage (optional)
- inline BOOL AttachFile(LPCTSTR szFileName, LPCTSTR szDisplayName = NULL, LPCTSTR szContentType = NULL,
- int nEncodingScheme = ATLSMTP_BASE64_ENCODE, UINT uiCodepage = 0)
- {
- if (szFileName == NULL)
- return FALSE;
-
- CAutoPtr<CMimeBodyPart> spFileAttach;
- CMimeFileAttachment* pFileAttach = NULL;
- ATLTRY(spFileAttach.Attach(pFileAttach = new CMimeFileAttachment()));
- if (!spFileAttach || !pFileAttach)
- return FALSE;
-
- BOOL bRet = pFileAttach->Initialize(szFileName, szDisplayName, m_spMultiLanguage, uiCodepage);
-
- if (bRet)
- bRet = pFileAttach->SetEncodingScheme(nEncodingScheme);
-
- CString strContentType;
- if (bRet && (szContentType == NULL))
- {
- if (GetContentTypeFromFileName(szFileName, strContentType) != ERROR_OUTOFMEMORY)
- {
- szContentType = strContentType;
- }
- else
- {
- bRet = FALSE;
- }
- }
-
- _ATLTRY
- {
- if (bRet)
- {
- bRet = pFileAttach->SetContentType(szContentType);
- if (bRet)
- {
- if (!m_BodyParts.AddTail(spFileAttach))
- {
- bRet = FALSE;
- }
- }
- }
- }
- _ATLCATCHALL()
- {
- bRet = FALSE;
- }
-
- return bRet;
- }
-
- // Attach some raw data
- // pRawData - the data
- // nDataLength - the size of the data in bytes
- // nEncodingScheme - the encoding scheme to use for the attachment (optional - defaults to base64
- // uiCodePage - the codepage (optional)
- inline BOOL AttachRaw(void* pRawData, DWORD dwDataLength, int nEncodingScheme = ATLSMTP_BASE64_ENCODE, BOOL bCopyData = TRUE,
- LPCTSTR szDisplayName = NULL, LPCTSTR szContentType = _T("application/octet-stream"), UINT uiCodepage = 0)
- {
- if (!pRawData)
- return FALSE;
-
- CAutoPtr<CMimeBodyPart> spRawAttach;
- CMimeRawAttachment* pRawAttach;
- ATLTRY(spRawAttach.Attach(pRawAttach = new CMimeRawAttachment()));
- if (!spRawAttach)
- {
- return FALSE;
- }
-
- BOOL bRet = pRawAttach->Initialize(pRawData, dwDataLength, bCopyData, szDisplayName, m_spMultiLanguage, uiCodepage);
-
- if (bRet)
- bRet = pRawAttach->SetEncodingScheme(nEncodingScheme);
- if (bRet)
- bRet = pRawAttach->SetContentType(szContentType);
-
- _ATLTRY
- {
- if (bRet)
- if(!m_BodyParts.AddTail(spRawAttach))
- bRet = FALSE;
- }
- _ATLCATCHALL()
- {
- bRet = FALSE;
- }
-
- return bRet;
- }
-
- // Attach a CMimeMessage
- // pMsg - pointer to the Msg object
- inline BOOL AttachMessage(CMimeMessage* pMsg) throw( ... )
- {
- if (!pMsg)
- return FALSE;
-
- _ATLTRY
- {
- CAutoPtr<CMimeBodyPart> spMsg(pMsg->Copy());
- if (!m_BodyParts.AddTail(spMsg))
- return FALSE;
- }
- _ATLCATCHALL()
- {
- return FALSE;
- }
-
- return TRUE;
- }
-
-protected:
- // Make the MIME header
- virtual inline BOOL MakeMimeHeader(CStringA& header, LPCSTR szBoundary) throw()
- {
- _ATLTRY
- {
- if (!*szBoundary)
- {
- header.Format("X-Priority: %d\r\n%s", m_nPriority, (LPCSTR) m_XHeader);
- }
- else if (m_BodyParts.GetCount() > 1)
- {
- header.Format("X-Priority: %d\r\n%sMIME-Version: 1.0\r\nContent-Type: multipart/mixed;\r\n\tboundary=\"%s\"\r\n",
- m_nPriority, (LPCSTR) m_XHeader, szBoundary);
- }
- return TRUE;
- }
- _ATLCATCHALL()
- {
- return FALSE;
- }
- }
-
- // Make the MIME boundary
- inline BOOL MakeBoundary(__out_ecount_z(nBufLen) LPSTR szBoundary, __in int nBufLen)
- {
- ATLENSURE(szBoundary != NULL);
-
- if(nBufLen < 1)
- {
- return FALSE;
- }
-
- if (m_BodyParts.GetCount() < 2)
- {
- *szBoundary = '\0';
- }
- else
- {
- int ret = sprintf_s(szBoundary, nBufLen, "------=_Next_Part_%.10u.%.3u", GetTickCount(), rand()%1000);
- if (ret == -1 || ret >= nBufLen)
- return FALSE;
- }
- return TRUE;
- }
-
-}; // class CMimeMessage
-
-} // namespace ATL
-#pragma pack(pop)
-
-#ifndef _CPPUNWIND
-#pragma warning (pop)
-#endif //_CPPUNWIND
-
-#pragma warning(pop)
-
-#endif // __ATLMIME_H__
diff --git a/include/atl/atlsession.h b/include/atl/atlsession.h
deleted file mode 100644
index 808748b21..000000000
--- a/include/atl/atlsession.h
+++ /dev/null
@@ -1,2490 +0,0 @@
-// This is a part of the Active Template Library.
-// Copyright (C) Microsoft Corporation
-// All rights reserved.
-//
-// This source code is only intended as a supplement to the
-// Active Template Library Reference and related
-// electronic documentation provided with the library.
-// See these sources for detailed information regarding the
-// Active Template Library product.
-
-#ifndef __ATLSESSION_H__
-#define __ATLSESSION_H__
-
-#pragma once
-#pragma warning(push)
-#pragma warning(disable: 4702) // unreachable code
-
-#include <atldbcli.h>
-#include <atlcom.h>
-#include <atlstr.h>
-#include <stdio.h>
-#include <atlcoll.h>
-#include <atltime.h>
-#include <atlcrypt.h>
-#include <atlenc.h>
-#include <atlutil.h>
-#include <atlcache.h>
-#include <atlspriv.h>
-#include <atlsiface.h>
-
-#pragma warning(disable: 4625) // copy constructor could not be generated because a base class copy constructor is inaccessible
-#pragma warning(disable: 4626) // assignment operator could not be generated because a base class assignment operator is inaccessible
-
-#ifndef MAX_SESSION_KEY_LEN
- #define MAX_SESSION_KEY_LEN 128
-#endif
-
-#ifndef MAX_VARIABLE_NAME_LENGTH
- #define MAX_VARIABLE_NAME_LENGTH 50
-#endif
-
-#ifndef MAX_VARIABLE_VALUE_LENGTH
- #define MAX_VARIABLE_VALUE_LENGTH 1024
-#endif
-
-#ifndef MAX_CONNECTION_STRING_LEN
- #define MAX_CONNECTION_STRING_LEN 2048
-#endif
-
-#ifndef SESSION_COOKIE_NAME
- #define SESSION_COOKIE_NAME "SESSIONID"
-#endif
-
-#ifndef ATL_SESSION_TIMEOUT
- #define ATL_SESSION_TIMEOUT 600000 //10 min
-#endif
-
-#ifndef ATL_SESSION_SWEEPER_TIMEOUT
- #define ATL_SESSION_SWEEPER_TIMEOUT 1000 // 1sec
-#endif
-
-#define INVALID_DB_SESSION_POS 0x0
-#define ATL_DBSESSION_ID _T("__ATL_SESSION_DB_CONNECTION")
-
-#pragma pack(push,_ATL_PACKING)
-namespace ATL {
-
-// CSessionNameGenerator
-// This is a helper class that generates random data for session key
-// names. This class tries to use the CryptoApi to generate random
-// bytes for the session key name. If the CryptoApi isn't available
-// then the CRT rand() is used to generate the random bytes. This
-// class's GetNewSessionName member function is used to actually
-// generate the session name.
-class CSessionNameGenerator :
- public CCryptProv
-{
-public:
- bool m_bCryptNotAvailable;
- enum {MIN_SESSION_KEY_LEN=5};
-
- CSessionNameGenerator() throw() :
- m_bCryptNotAvailable(false)
- {
- // Note that the crypto api is being
- // initialized with no private key
- // information
- HRESULT hr = InitVerifyContext();
- m_bCryptNotAvailable = FAILED(hr) ? true : false;
- }
-
- // This function creates a new session name and base64 encodes it.
- // The base64 encoding algorithm used needs at least MIN_SESSION_KEY_LEN
- // bytes to work correctly. Since we stack allocate the temporary
- // buffer that holds the key name, the buffer must be less than or equal to
- // the MAX_SESSION_KEY_LEN in size.
- HRESULT GetNewSessionName(__out_ecount_part_z(*pdwSize, *pdwSize) LPSTR szNewID, __inout DWORD *pdwSize) throw()
- {
- HRESULT hr = E_FAIL;
-
- if (!pdwSize)
- return E_POINTER;
-
- if (*pdwSize < MIN_SESSION_KEY_LEN ||
- *pdwSize > MAX_SESSION_KEY_LEN)
- return E_INVALIDARG;
-
- if (!szNewID)
- return E_POINTER;
-
- BYTE key[MAX_SESSION_KEY_LEN] = {0x0};
-
-
- // calculate the number of bytes that will fit in the
- // buffer we've been passed
- DWORD dwDataSize = CalcMaxInputSize(*pdwSize);
-
- if (dwDataSize && *pdwSize >= (DWORD)(Base64EncodeGetRequiredLength(dwDataSize,
- ATL_BASE64_FLAG_NOCRLF)))
- {
- int dwKeySize = *pdwSize;
- hr = GenerateRandomName(key, dwDataSize);
- if (SUCCEEDED(hr))
- {
- if( Base64Encode(key,
- dwDataSize,
- szNewID,
- &dwKeySize,
- ATL_BASE64_FLAG_NOCRLF) )
- {
- //null terminate
- szNewID[dwKeySize]=0;
- *pdwSize = dwKeySize+1;
- }
- else
- hr = E_FAIL;
- }
- else
- {
- *pdwSize = (DWORD)(Base64EncodeGetRequiredLength(dwDataSize,
- ATL_BASE64_FLAG_NOCRLF));
- return E_OUTOFMEMORY;
- }
- }
- return hr;
- }
-
- DWORD CalcMaxInputSize(DWORD nOutputSize) throw()
- {
- if (nOutputSize < (DWORD)MIN_SESSION_KEY_LEN)
- return 0;
- // subtract one from the output size to make room
- // for the NULL terminator in the output then
- // calculate the biggest number of input bytes that
- // when base64 encoded will fit in a buffer of size
- // nOutputSize (including base64 padding)
- int nInputSize = ((nOutputSize-1)*3)/4;
- int factor = ((nInputSize*4)/3)%4;
- if (factor)
- nInputSize -= factor;
- return nInputSize;
- }
-
-
- HRESULT GenerateRandomName(BYTE *pBuff, DWORD dwBuffSize) throw()
- {
- if (!pBuff)
- return E_POINTER;
-
- if (!dwBuffSize)
- return E_UNEXPECTED;
-
- if (!m_bCryptNotAvailable && GetHandle())
- {
- // Use the crypto api to generate random data.
- return GenRandom(dwBuffSize, pBuff);
- }
-
- // CryptoApi isn't available so we generate
- // random data using rand. We seed the random
- // number generator with a seed that is a combination
- // of bytes from an arbitrary number and the system
- // time which changes every millisecond so it will
- // be different for every call to this function.
- FILETIME ft;
- GetSystemTimeAsFileTime(&ft);
- static DWORD dwVal = 0x21;
- DWORD dwSeed = (dwVal++ << 0x18) | (ft.dwLowDateTime & 0x00ffff00) | dwVal++ & 0x000000ff;
- srand(dwSeed);
- BYTE *pCurr = pBuff;
- // fill buffer with random bytes
- for (int i=0; i < (int)dwBuffSize; i++)
- {
- *pCurr = (BYTE) (rand() & 0x000000ff);
- pCurr++;
- }
- return S_OK;
- }
-};
-
-
-//
-// CDefaultQueryClass
-// returns Query strings for use in SQL queries used
-// by the database persisted session service.
-class CDefaultQueryClass
-{
-public:
- LPCTSTR GetSessionRefDelete() throw()
- {
- return _T("DELETE FROM SessionReferences ")
- _T("WHERE SessionID=? AND RefCount <= 0 ")
- _T("AND DATEDIFF(millisecond, LastAccess, getdate()) > TimeoutMs");
- }
-
- LPCTSTR GetSessionRefIsExpired() throw()
- {
- return _T("SELECT SessionID FROM SessionReferences ")
- _T("WHERE (SessionID=?) AND (DATEDIFF(millisecond, LastAccess, getdate()) > TimeoutMs)");
- }
-
- LPCTSTR GetSessionRefDeleteFinal() throw()
- {
- return _T("DELETE FROM SessionReferences ")
- _T("WHERE SessionID=?");
- }
-
- LPCTSTR GetSessionRefCreate() throw()
- {
- return _T("INSERT INTO SessionReferences ")
- _T("(SessionID, LastAccess, RefCount, TimeoutMs) ")
- _T("VALUES (?, getdate(), 1, ?)");
- }
-
- LPCTSTR GetSessionRefUpdateTimeout() throw()
- {
- return _T("UPDATE SessionReferences ")
- _T("SET TimeoutMs=? WHERE SessionID=?");
- }
-
- LPCTSTR GetSessionRefAddRef() throw()
- {
- return _T("UPDATE SessionReferences ")
- _T("SET RefCount=RefCount+1, ")
- _T("LastAccess=getdate() ")
- _T("WHERE SessionID=?");
- }
-
- LPCTSTR GetSessionRefRemoveRef() throw()
- {
- return _T("UPDATE SessionReferences ")
- _T("SET RefCount=RefCount-1, ")
- _T("LastAccess=getdate() ")
- _T("WHERE SessionID=?");
- }
-
- LPCTSTR GetSessionRefAccess() throw()
- {
- return _T("UPDATE SessionReferences ")
- _T("SET LastAccess=getdate() ")
- _T("WHERE SessionID=?");
- }
-
- LPCTSTR GetSessionRefSelect() throw()
- {
- return _T("SELECT * FROM SessionReferences ")
- _T("WHERE SessionID=?");
- }
-
- LPCTSTR GetSessionRefGetCount() throw()
- {
- return _T("SELECT COUNT(*) FROM SessionReferences");
- }
-
-
- LPCTSTR GetSessionVarCount() throw()
- {
- return _T("SELECT COUNT(*) FROM SessionVariables WHERE SessionID=?");
- }
-
- LPCTSTR GetSessionVarInsert() throw()
- {
- return _T("INSERT INTO SessionVariables ")
- _T("(VariableValue, SessionID, VariableName) ")
- _T("VALUES (?, ?, ?)");
- }
-
- LPCTSTR GetSessionVarUpdate() throw()
- {
- return _T("UPDATE SessionVariables ")
- _T("SET VariableValue=? ")
- _T("WHERE SessionID=? AND VariableName=?");
- }
-
- LPCTSTR GetSessionVarDeleteVar() throw()
- {
- return _T("DELETE FROM SessionVariables ")
- _T("WHERE SessionID=? AND VariableName=?");
- }
-
- LPCTSTR GetSessionVarDeleteAllVars() throw()
- {
- return _T("DELETE FROM SessionVariables WHERE (SessionID=?)");
- }
-
- LPCTSTR GetSessionVarSelectVar()throw()
- {
- return _T("SELECT SessionID, VariableName, VariableValue ")
- _T("FROM SessionVariables ")
- _T("WHERE SessionID=? AND VariableName=?");
- }
-
- LPCTSTR GetSessionVarSelectAllVars() throw()
- {
- return _T("SELECT SessionID, VariableName, VariableValue ")
- _T("FROM SessionVariables ")
- _T("WHERE SessionID=?");
- }
-
- LPCTSTR GetSessionReferencesSet() throw()
- {
- return _T("UPDATE SessionReferences SET TimeoutMs=?");
- }
-};
-
-
-// Contains the data for the session variable accessors
-class CSessionDataBase
-{
-public:
- TCHAR m_szSessionID[MAX_SESSION_KEY_LEN];
- TCHAR m_VariableName[MAX_VARIABLE_NAME_LENGTH];
- BYTE m_VariableValue[MAX_VARIABLE_VALUE_LENGTH];
- DBLENGTH m_VariableLen;
- CSessionDataBase() throw()
- {
- m_szSessionID[0] = '\0';
- m_VariableName[0] = '\0';
- m_VariableValue[0] = '\0';
- m_VariableLen = 0;
- }
- HRESULT Assign(LPCTSTR szSessionID, LPCTSTR szVarName, VARIANT *pVal) throw()
- {
- HRESULT hr = S_OK;
- CVariantStream stream;
- if ( szSessionID )
- {
- if (Checked::tcsnlen(szSessionID, MAX_SESSION_KEY_LEN)< MAX_SESSION_KEY_LEN)
- Checked::tcscpy_s(m_szSessionID, _countof(m_szSessionID), szSessionID);
- else
- hr = E_OUTOFMEMORY;
- }
- else
- return E_INVALIDARG;
-
- if (hr == S_OK && szVarName)
- if (Checked::tcsnlen(szVarName, MAX_VARIABLE_NAME_LENGTH) < MAX_VARIABLE_NAME_LENGTH)
- Checked::tcscpy_s(m_VariableName, _countof(m_VariableName), szVarName);
- else
- hr = E_OUTOFMEMORY;
-
- if (hr == S_OK && pVal)
- {
- hr = stream.InsertVariant(pVal);
- if (hr == S_OK)
- {
- BYTE *pBytes = stream.m_stream;
- size_t size = stream.GetVariantSize();
- if (pBytes && size && size < MAX_VARIABLE_VALUE_LENGTH)
- {
- Checked::memcpy_s(m_VariableValue, MAX_VARIABLE_VALUE_LENGTH, pBytes, size);
- m_VariableLen = static_cast<DBLENGTH>(size);
- }
- else
- hr = E_INVALIDARG;
- }
- }
-
- return hr;
- }
-};
-
-// Use to select a session variable given the name
-// of a session and the name of a variable.
-class CSessionDataSelector : public CSessionDataBase
-{
-public:
- BEGIN_COLUMN_MAP(CSessionDataSelector)
- COLUMN_ENTRY(1, m_szSessionID)
- COLUMN_ENTRY(2, m_VariableName)
- COLUMN_ENTRY_LENGTH(3, m_VariableValue, m_VariableLen)
- END_COLUMN_MAP()
- BEGIN_PARAM_MAP(CSessionDataSelector)
- SET_PARAM_TYPE(DBPARAMIO_INPUT)
- COLUMN_ENTRY(1, m_szSessionID)
- COLUMN_ENTRY(2, m_VariableName)
- END_PARAM_MAP()
-};
-
-// Use to select all session variables given the name of
-// of a session.
-class CAllSessionDataSelector : public CSessionDataBase
-{
-public:
- BEGIN_COLUMN_MAP(CAllSessionDataSelector)
- COLUMN_ENTRY(1, m_szSessionID)
- COLUMN_ENTRY(2, m_VariableName)
- COLUMN_ENTRY_LENGTH(3, m_VariableValue, m_VariableLen)
- END_COLUMN_MAP()
- BEGIN_PARAM_MAP(CAllSessionDataSelector)
- SET_PARAM_TYPE(DBPARAMIO_INPUT)
- COLUMN_ENTRY(1, m_szSessionID)
- END_PARAM_MAP()
-};
-
-// Use to update the value of a session variable
-class CSessionDataUpdator : public CSessionDataBase
-{
-public:
- BEGIN_PARAM_MAP(CSessionDataUpdator)
- SET_PARAM_TYPE(DBPARAMIO_INPUT)
- COLUMN_ENTRY_LENGTH(1, m_VariableValue, m_VariableLen)
- COLUMN_ENTRY(2, m_szSessionID)
- COLUMN_ENTRY(3, m_VariableName)
- END_PARAM_MAP()
-};
-
-// Use to delete a session variable given the
-// session name and the name of the variable
-class CSessionDataDeletor
-{
-public:
- CSessionDataDeletor()
- {
- m_szSessionID[0] = '\0';
- m_VariableName[0] = '\0';
- }
-
- TCHAR m_szSessionID[MAX_SESSION_KEY_LEN];
- TCHAR m_VariableName[MAX_VARIABLE_NAME_LENGTH];
- HRESULT Assign(LPCTSTR szSessionID, LPCTSTR szVarName) throw()
- {
- if (szSessionID)
- {
- if (Checked::tcsnlen(szSessionID, MAX_SESSION_KEY_LEN) < MAX_SESSION_KEY_LEN)
- Checked::tcscpy_s(m_szSessionID, _countof(m_szSessionID), szSessionID);
- else
- return E_OUTOFMEMORY;
- }
-
- if (szVarName)
- {
- if(Checked::tcsnlen(szVarName, MAX_VARIABLE_NAME_LENGTH) < MAX_VARIABLE_NAME_LENGTH)
- Checked::tcscpy_s(m_VariableName, _countof(m_VariableName), szVarName);
- else
- return E_OUTOFMEMORY;
- }
- return S_OK;
- }
-
- BEGIN_PARAM_MAP(CSessionDataDeletor)
- SET_PARAM_TYPE(DBPARAMIO_INPUT)
- COLUMN_ENTRY(1, m_szSessionID)
- COLUMN_ENTRY(2, m_VariableName)
- END_PARAM_MAP()
-};
-
-class CSessionDataDeleteAll
-{
-public:
- TCHAR m_szSessionID[MAX_SESSION_KEY_LEN];
- HRESULT Assign(LPCTSTR szSessionID) throw()
- {
- if (!szSessionID)
- return E_INVALIDARG;
-
- if (Checked::tcsnlen(szSessionID, MAX_SESSION_KEY_LEN) < MAX_SESSION_KEY_LEN)
- Checked::tcscpy_s(m_szSessionID, _countof(m_szSessionID), szSessionID);
- else
- return E_OUTOFMEMORY;
-
- return S_OK;
- }
-
- BEGIN_PARAM_MAP(CSessionDataDeleteAll)
- SET_PARAM_TYPE(DBPARAMIO_INPUT)
- COLUMN_ENTRY(1, m_szSessionID)
- END_PARAM_MAP()
-};
-
-// Used for retrieving the count of session variables for
-// a given session ID.
-class CCountAccessor
-{
-public:
- LONG m_nCount;
- TCHAR m_szSessionID[MAX_SESSION_KEY_LEN];
- CCountAccessor() throw()
- {
- m_szSessionID[0] = '\0';
- m_nCount = 0;
- }
-
- HRESULT Assign(LPCTSTR szSessionID) throw()
- {
- if (!szSessionID)
- return E_INVALIDARG;
-
- if (Checked::tcsnlen(szSessionID, MAX_SESSION_KEY_LEN) < MAX_SESSION_KEY_LEN)
- Checked::tcscpy_s(m_szSessionID, _countof(m_szSessionID), szSessionID);
- else
- return E_OUTOFMEMORY;
-
- return S_OK;
- }
-
- BEGIN_COLUMN_MAP(CCountAccessor)
- COLUMN_ENTRY(1, m_nCount)
- END_COLUMN_MAP()
- BEGIN_PARAM_MAP(CCountAccessor)
- SET_PARAM_TYPE(DBPARAMIO_INPUT)
- COLUMN_ENTRY(1, m_szSessionID)
- END_PARAM_MAP()
-};
-
-
-// Used for updating entries in the session
-// references table, given a session ID
-class CSessionRefUpdator
-{
-public:
- TCHAR m_SessionID[MAX_SESSION_KEY_LEN];
- HRESULT Assign(LPCTSTR szSessionID) throw()
- {
- if (!szSessionID)
- return E_INVALIDARG;
- if (Checked::tcsnlen(szSessionID, MAX_SESSION_KEY_LEN) < MAX_SESSION_KEY_LEN)
- Checked::tcscpy_s(m_SessionID, _countof(m_SessionID), szSessionID);
- else
- return E_OUTOFMEMORY;
- return S_OK;
- }
- BEGIN_PARAM_MAP(CSessionRefUpdator)
- SET_PARAM_TYPE(DBPARAMIO_INPUT)
- COLUMN_ENTRY(1, m_SessionID)
- END_PARAM_MAP()
-};
-
-class CSessionRefIsExpired
-{
-public:
- TCHAR m_SessionID[MAX_SESSION_KEY_LEN];
- TCHAR m_SessionIDOut[MAX_SESSION_KEY_LEN];
- HRESULT Assign(LPCTSTR szSessionID) throw()
- {
- m_SessionIDOut[0]=0;
- if (!szSessionID)
- return E_INVALIDARG;
- if (Checked::tcsnlen(szSessionID, MAX_SESSION_KEY_LEN) < MAX_SESSION_KEY_LEN)
- Checked::tcscpy_s(m_SessionID, _countof(m_SessionID), szSessionID);
- else
- return E_OUTOFMEMORY;
- return S_OK;
- }
- BEGIN_COLUMN_MAP(CSessionRefIsExpired)
- COLUMN_ENTRY(1, m_SessionIDOut)
- END_COLUMN_MAP()
- BEGIN_PARAM_MAP(CSessionRefIsExpired)
- SET_PARAM_TYPE(DBPARAMIO_INPUT)
- COLUMN_ENTRY(1, m_SessionID)
- END_PARAM_MAP()
-};
-
-class CSetAllTimeouts
-{
-public:
- unsigned __int64 m_dwNewTimeout;
- HRESULT Assign(unsigned __int64 dwNewValue)
- {
- m_dwNewTimeout = dwNewValue;
- return S_OK;
- }
- BEGIN_PARAM_MAP(CSetAllTimeouts)
- SET_PARAM_TYPE(DBPARAMIO_INPUT)
- COLUMN_ENTRY(1, m_dwNewTimeout)
- END_PARAM_MAP()
-};
-
-class CSessionRefUpdateTimeout
-{
-public:
- TCHAR m_SessionID[MAX_SESSION_KEY_LEN];
- unsigned __int64 m_nNewTimeout;
- HRESULT Assign(LPCTSTR szSessionID, unsigned __int64 nNewTimeout) throw()
- {
- if (!szSessionID)
- return E_INVALIDARG;
-
- if (Checked::tcsnlen(szSessionID, MAX_SESSION_KEY_LEN) < MAX_SESSION_KEY_LEN)
- Checked::tcscpy_s(m_SessionID, _countof(m_SessionID), szSessionID);
- else
- return E_OUTOFMEMORY;
-
- m_nNewTimeout = nNewTimeout;
-
- return S_OK;
- }
-
- BEGIN_PARAM_MAP(CSessionRefUpdateTimeout)
- SET_PARAM_TYPE(DBPARAMIO_INPUT)
- COLUMN_ENTRY(1, m_nNewTimeout)
- COLUMN_ENTRY(2, m_SessionID)
- END_PARAM_MAP()
-};
-
-class CSessionRefSelector
-{
-public:
- TCHAR m_SessionID[MAX_SESSION_KEY_LEN];
- int m_RefCount;
- HRESULT Assign(LPCTSTR szSessionID) throw()
- {
- if (!szSessionID)
- return E_INVALIDARG;
- if (Checked::tcsnlen(szSessionID, MAX_SESSION_KEY_LEN) < MAX_SESSION_KEY_LEN)
- Checked::tcscpy_s(m_SessionID, _countof(m_SessionID), szSessionID);
- else
- return E_OUTOFMEMORY;
- return S_OK;
- }
- BEGIN_COLUMN_MAP(CSessionRefSelector)
- COLUMN_ENTRY(1, m_SessionID)
- COLUMN_ENTRY(3, m_RefCount)
- END_COLUMN_MAP()
- BEGIN_PARAM_MAP(CSessionRefSelector)
- SET_PARAM_TYPE(DBPARAMIO_INPUT)
- COLUMN_ENTRY(1, m_SessionID)
- END_PARAM_MAP()
-};
-
-class CSessionRefCount
-{
-public:
- LONG m_nCount;
- BEGIN_COLUMN_MAP(CSessionRefCount)
- COLUMN_ENTRY(1, m_nCount)
- END_COLUMN_MAP()
-};
-
-// Used for creating new entries in the session
-// references table.
-class CSessionRefCreator
-{
-public:
- TCHAR m_SessionID[MAX_SESSION_KEY_LEN];
- unsigned __int64 m_TimeoutMs;
- HRESULT Assign(LPCTSTR szSessionID, unsigned __int64 timeout) throw()
- {
- if (!szSessionID)
- return E_INVALIDARG;
- if (Checked::tcsnlen(szSessionID, MAX_SESSION_KEY_LEN) < MAX_SESSION_KEY_LEN)
- {
- Checked::tcscpy_s(m_SessionID, _countof(m_SessionID), szSessionID);
- m_TimeoutMs = timeout;
- }
- else
- return E_OUTOFMEMORY;
- return S_OK;
- }
- BEGIN_PARAM_MAP(CSessionRefCreator)
- SET_PARAM_TYPE(DBPARAMIO_INPUT)
- COLUMN_ENTRY(1, m_SessionID)
- COLUMN_ENTRY(2, m_TimeoutMs)
- END_PARAM_MAP()
-};
-
-
-// CDBSession
-// This session persistance class persists session variables to
-// an OLEDB datasource. The following table gives a general description
-// of the table schema for the tables this class uses.
-//
-// TableName: SessionVariables
-// Column Name Type Description
-// 1 SessionID char[MAX_SESSION_KEY_LEN] Session Key name
-// 2 VariableName char[MAX_VARIABLE_NAME_LENGTH] Variable Name
-// 3 VariableValue varbinary[MAX_VARIABLE_VALUE_LENGTH] Variable Value
-
-//
-// TableName: SessionReferences
-// Column Name Type Description
-// 1 SessionID char[MAX_SESSION_KEY_LEN] Session Key Name.
-// 2 LastAccess datetime Date and time of last access to this session.
-// 3 RefCount int Current references on this session.
-// 4 TimeoutMS int Timeout value for the session in milli seconds
-
-typedef bool (*PFN_GETPROVIDERINFO)(DWORD_PTR, wchar_t **);
-
-template <class QueryClass=CDefaultQueryClass>
-class CDBSession:
- public ISession,
- public CComObjectRootEx<CComGlobalsThreadModel>
-
-{
- typedef CCommand<CAccessor<CAllSessionDataSelector> > iterator_accessor;
-public:
- typedef QueryClass DBQUERYCLASS_TYPE;
- BEGIN_COM_MAP(CDBSession)
- COM_INTERFACE_ENTRY(ISession)
- END_COM_MAP()
-
- CDBSession() throw():
- m_dwTimeout(ATL_SESSION_TIMEOUT)
- {
- m_szSessionName[0] = '\0';
- }
-
- ~CDBSession() throw()
- {
- }
-
- void FinalRelease()throw()
- {
- SessionUnlock();
- }
-
- STDMETHOD(SetVariable)(LPCSTR szName, VARIANT Val) throw()
- {
- HRESULT hr = E_FAIL;
- if (!szName)
- return E_INVALIDARG;
-
- // Get the data connection for this thread.
- CDataConnection dataconn;
- hr = GetSessionConnection(&dataconn, m_spServiceProvider);
- if (hr != S_OK)
- return hr;
-
- // Update the last access time for this session
- hr = Access();
- if (hr != S_OK)
- return hr;
-
- // Allocate an updator command and fill out it's input parameters.
- CCommand<CAccessor<CSessionDataUpdator> > command;
- _ATLTRY
- {
- CA2CT name(szName);
- hr = command.Assign(m_szSessionName, name, &Val);
- }
- _ATLCATCHALL()
- {
- hr = E_OUTOFMEMORY;
- }
- if (hr != S_OK)
- return hr;
-
- // Try an update. Update will fail if the variable is not already there.
- DBROWCOUNT nRows = 0;
-
- hr = command.Open(dataconn,
- m_QueryObj.GetSessionVarUpdate(),
- NULL, &nRows, DBGUID_DEFAULT, false);
- if (hr == S_OK && nRows <= 0)
- hr = E_UNEXPECTED;
- if (hr != S_OK)
- {
- // Try an insert
- hr = command.Open(dataconn, m_QueryObj.GetSessionVarInsert(), NULL, &nRows, DBGUID_DEFAULT, false);
- if (hr == S_OK && nRows <=0)
- hr = E_UNEXPECTED;
- }
-
- return hr;
- }
-
- // Warning: For string data types, depending on the configuration of
- // your database, strings might be returned with trailing white space.
- STDMETHOD(GetVariable)(LPCSTR szName, VARIANT *pVal) throw()
- {
- HRESULT hr = E_FAIL;
- if (!szName)
- return E_INVALIDARG;
- if (pVal)
- VariantInit(pVal);
- else
- return E_POINTER;
-
- // Get the data connection for this thread
- CDataConnection dataconn;
- hr = GetSessionConnection(&dataconn, m_spServiceProvider);
- if (hr != S_OK)
- return hr;
-
- // Update the last access time for this session
- hr = Access();
- if (hr != S_OK)
- return hr;
-
- // Allocate a command a fill out it's input parameters.
- CCommand<CAccessor<CSessionDataSelector> > command;
- _ATLTRY
- {
- CA2CT name(szName);
- hr = command.Assign(m_szSessionName, name, NULL);
- }
- _ATLCATCHALL()
- {
- hr = E_OUTOFMEMORY;
- }
-
- if (hr == S_OK)
- {
- hr = command.Open(dataconn, m_QueryObj.GetSessionVarSelectVar());
- if (SUCCEEDED(hr))
- {
- if ( S_OK == (hr = command.MoveFirst()))
- {
- CStreamOnByteArray stream(command.m_VariableValue);
- CComVariant vOut;
- hr = vOut.ReadFromStream(static_cast<IStream*>(&stream));
- if (hr == S_OK)
- hr = vOut.Detach(pVal);
- }
- }
- }
- return hr;
- }
-
- STDMETHOD(RemoveVariable)(LPCSTR szName) throw()
- {
- HRESULT hr = E_FAIL;
- if (!szName)
- return E_INVALIDARG;
-
- // Get the data connection for this thread.
- CDataConnection dataconn;
- hr = GetSessionConnection(&dataconn, m_spServiceProvider);
- if (hr != S_OK)
- return hr;
-
- // update the last access time for this session
- hr = Access();
- if (hr != S_OK)
- return hr;
-
- // allocate a command and set it's input parameters
- CCommand<CAccessor<CSessionDataDeletor> > command;
- _ATLTRY
- {
- CA2CT name(szName);
- hr = command.Assign(m_szSessionName, name);
- }
- _ATLCATCHALL()
- {
- return E_OUTOFMEMORY;
- }
-
- // execute the command
- DBROWCOUNT nRows = 0;
- if (hr == S_OK)
- hr = command.Open(dataconn, m_QueryObj.GetSessionVarDeleteVar(),
- NULL, &nRows, DBGUID_DEFAULT, false);
- if (hr == S_OK && nRows <= 0)
- hr = E_FAIL;
- return hr;
- }
-
- // Gives the count of rows in the table for this session ID.
- STDMETHOD(GetCount)(long *pnCount) throw()
- {
- HRESULT hr = S_OK;
- if (pnCount)
- *pnCount = 0;
- else
- return E_POINTER;
-
- // Get the database connection for this thread.
- CDataConnection dataconn;
- hr = GetSessionConnection(&dataconn, m_spServiceProvider);
- if (hr != S_OK)
- return hr;
- hr = Access();
- if (hr != S_OK)
- return hr;
- CCommand<CAccessor<CCountAccessor> > command;
-
- hr = command.Assign(m_szSessionName);
- if (hr == S_OK)
- {
- hr = command.Open(dataconn, m_QueryObj.GetSessionVarCount());
- if (hr == S_OK)
- {
- if (S_OK == (hr = command.MoveFirst()))
- {
- *pnCount = command.m_nCount;
- hr = S_OK;
- }
- }
- }
- return hr;
- }
-
- STDMETHOD(RemoveAllVariables)() throw()
- {
- HRESULT hr = E_UNEXPECTED;
-
- // Get the data connection for this thread.
- CDataConnection dataconn;
- hr = GetSessionConnection(&dataconn, m_spServiceProvider);
- if (hr != S_OK)
- return hr;
-
- CCommand<CAccessor<CSessionDataDeleteAll> > command;
- hr = command.Assign(m_szSessionName);
- if (hr != S_OK)
- return hr;
-
- // delete all session variables
- hr = command.Open(dataconn, m_QueryObj.GetSessionVarDeleteAllVars(), NULL, NULL, DBGUID_DEFAULT, false);
- return hr;
- }
-
- // Iteration of variables works by taking a snapshot
- // of the sessions at the point in time BeginVariableEnum
- // is called, and then keeping an index variable that you use to
- // move through the snapshot rowset. It is important to know
- // that the handle returned in phEnum is not thread safe. It
- // should only be used by the calling thread.
- STDMETHOD(BeginVariableEnum)(POSITION *pPOS, HSESSIONENUM *phEnum) throw()
- {
- HRESULT hr = E_FAIL;
- if (!pPOS)
- return E_POINTER;
-
- if (phEnum)
- *phEnum = NULL;
- else
- return E_POINTER;
-
- // Get the data connection for this thread.
- CDataConnection dataconn;
- hr = GetSessionConnection(&dataconn, m_spServiceProvider);
- if (hr != S_OK)
- return hr;
-
- // Update the last access time for this session.
- hr = Access();
- if (hr != S_OK)
- return hr;
-
- // Allocate a new iterator accessor and initialize it's input parameters.
- iterator_accessor *pIteratorAccessor = NULL;
- ATLTRYALLOC(pIteratorAccessor = new iterator_accessor);
- if (!pIteratorAccessor)
- return E_OUTOFMEMORY;
-
- hr = pIteratorAccessor->Assign(m_szSessionName, NULL, NULL);
- if (hr == S_OK)
- {
- // execute the command and move to the first row of the recordset.
- hr = pIteratorAccessor->Open(dataconn,
- m_QueryObj.GetSessionVarSelectAllVars());
- if (hr == S_OK)
- {
- hr = pIteratorAccessor->MoveFirst();
- if (hr == S_OK)
- {
- *pPOS = (POSITION) INVALID_DB_SESSION_POS + 1;
- *phEnum = reinterpret_cast<HSESSIONENUM>(pIteratorAccessor);
- }
- }
-
- if (hr != S_OK)
- {
- *pPOS = INVALID_DB_SESSION_POS;
- *phEnum = NULL;
- delete pIteratorAccessor;
- }
- }
- return hr;
- }
-
- // The values for hEnum and pPos must have been initialized in a previous
- // call to BeginVariableEnum. On success, the out variant will hold the next
- // variable
- STDMETHOD(GetNextVariable)(POSITION *pPOS, VARIANT *pVal, HSESSIONENUM hEnum, LPSTR szName=NULL, DWORD dwLen=0) throw()
- {
- if (!pPOS)
- return E_INVALIDARG;
-
- if (pVal)
- VariantInit(pVal);
- else
- return E_POINTER;
-
- if (!hEnum)
- return E_UNEXPECTED;
-
- if (*pPOS <= INVALID_DB_SESSION_POS)
- return E_UNEXPECTED;
-
- iterator_accessor *pIteratorAccessor = reinterpret_cast<iterator_accessor*>(hEnum);
-
- // update the last access time.
- HRESULT hr = Access();
-
- POSITION posCurrent = *pPOS;
-
- if (szName)
- {
- // caller wants entry name
- _ATLTRY
- {
- CT2CA szVarName(pIteratorAccessor->m_VariableName);
- if (szVarName != NULL && dwLen > Checked::strnlen(szVarName, dwLen))
- {
- Checked::strcpy_s(szName, dwLen, szVarName);
- }
- else
- hr = E_OUTOFMEMORY; // buffer not big enough
- }
- _ATLCATCHALL()
- {
- hr = E_OUTOFMEMORY;
- }
-
- }
-
- if (hr == S_OK)
- {
- CStreamOnByteArray stream(pIteratorAccessor->m_VariableValue);
- CComVariant vOut;
- hr = vOut.ReadFromStream(static_cast<IStream*>(&stream));
- if (hr == S_OK)
- vOut.Detach(pVal);
- else
- return hr;
- }
- else
- return hr;
-
- hr = pIteratorAccessor->MoveNext();
- *pPOS = ++posCurrent;
-
- if (hr == DB_S_ENDOFROWSET)
- {
- // We're done iterating, reset everything
- *pPOS = INVALID_DB_SESSION_POS;
- hr = S_OK;
- }
-
- if (hr != S_OK)
- {
- VariantClear(pVal);
- }
- return hr;
- }
-
- // CloseEnum frees up any resources allocated by the iterator
- STDMETHOD(CloseEnum)(HSESSIONENUM hEnum) throw()
- {
- iterator_accessor *pIteratorAccessor = reinterpret_cast<iterator_accessor*>(hEnum);
- if (!pIteratorAccessor)
- return E_INVALIDARG;
- pIteratorAccessor->Close();
- delete pIteratorAccessor;
- return S_OK;
- }
-
- //
- // Returns S_FALSE if it's not expired
- // S_OK if it is expired and an error HRESULT
- // if an error occurred.
- STDMETHOD(IsExpired)() throw()
- {
- HRESULT hrRet = S_FALSE;
- HRESULT hr = E_UNEXPECTED;
-
- // Get the data connection for this thread.
- CDataConnection dataconn;
- hr = GetSessionConnection(&dataconn, m_spServiceProvider);
- if (hr != S_OK)
- return hr;
-
- CCommand<CAccessor<CSessionRefIsExpired> > command;
- hr = command.Assign(m_szSessionName);
- if (hr != S_OK)
- return hr;
-
- hr = command.Open(dataconn, m_QueryObj.GetSessionRefIsExpired(),
- NULL, NULL, DBGUID_DEFAULT, true);
- if (hr == S_OK)
- {
- if (S_OK == command.MoveFirst())
- {
- if (!_tcscmp(command.m_SessionIDOut, m_szSessionName))
- hrRet = S_OK;
- }
- }
-
- if (hr == S_OK)
- return hrRet;
- return hr;
- }
-
- STDMETHOD(SetTimeout)(unsigned __int64 dwNewTimeout) throw()
- {
- HRESULT hr = E_UNEXPECTED;
-
- // Get the data connection for this thread.
- CDataConnection dataconn;
- hr = GetSessionConnection(&dataconn, m_spServiceProvider);
- if (hr != S_OK)
- return hr;
-
- // allocate a command and set it's input parameters
- CCommand<CAccessor<CSessionRefUpdateTimeout> > command;
- hr = command.Assign(m_szSessionName, dwNewTimeout);
- if (hr != S_OK)
- return hr;
-
- hr = command.Open(dataconn, m_QueryObj.GetSessionRefUpdateTimeout(),
- NULL, NULL, DBGUID_DEFAULT, false);
-
- return hr;
- }
-
- // SessionLock increments the session reference count for this session.
- // If there is not a session by this name in the session references table,
- // a new session entry is created in the the table.
- HRESULT SessionLock() throw()
- {
- HRESULT hr = E_UNEXPECTED;
- if (!m_szSessionName || m_szSessionName[0]==0)
- return hr; // no session to lock.
-
- // retrieve the data connection for this thread
- CDataConnection dataconn;
- hr = GetSessionConnection(&dataconn, m_spServiceProvider);
- if (hr != S_OK)
- return hr;
-
- // first try to update a session with this name
- DBROWCOUNT nRows = 0;
- CCommand<CAccessor<CSessionRefUpdator> > updator;
- if (S_OK == updator.Assign(m_szSessionName))
- {
- if (S_OK != (hr = updator.Open(dataconn, m_QueryObj.GetSessionRefAddRef(),
- NULL, &nRows, DBGUID_DEFAULT, false)) ||
- nRows == 0)
- {
- // No session to update. Use the creator accessor
- // to create a new session reference.
- CCommand<CAccessor<CSessionRefCreator> > creator;
- hr = creator.Assign(m_szSessionName, m_dwTimeout);
- if (hr == S_OK)
- hr = creator.Open(dataconn, m_QueryObj.GetSessionRefCreate(),
- NULL, &nRows, DBGUID_DEFAULT, false);
- }
- }
-
- // We should have been able to create or update a session.
- ATLASSERT(nRows > 0);
- if (hr == S_OK && nRows <= 0)
- hr = E_UNEXPECTED;
-
- return hr;
- }
-
- // SessionUnlock decrements the session RefCount for this session.
- // Sessions cannot be removed from the database unless the session
- // refcount is 0
- HRESULT SessionUnlock() throw()
- {
- HRESULT hr = E_UNEXPECTED;
- if (!m_szSessionName ||
- m_szSessionName[0]==0)
- return hr;
-
- // get the data connection for this thread
- CDataConnection dataconn;
- hr = GetSessionConnection(&dataconn, m_spServiceProvider);
- if (hr != S_OK)
- return hr;
-
- // The session must exist at this point in order to unlock it
- // so we can just use the session updator here.
- DBROWCOUNT nRows = 0;
- CCommand<CAccessor<CSessionRefUpdator> > updator;
- hr = updator.Assign(m_szSessionName);
- if (hr == S_OK)
- {
- hr = updator.Open( dataconn,
- m_QueryObj.GetSessionRefRemoveRef(),
- NULL,
- &nRows,
- DBGUID_DEFAULT,
- false);
- }
- if (hr != S_OK)
- return hr;
-
- // delete the session from the database if
- // nobody else is using it and it's expired.
- hr = FreeSession();
- return hr;
- }
-
- // Access updates the last access time for the session. The access
- // time for sessions is updated using the SQL GETDATE function on the
- // database server so that all clients will be using the same clock
- // to compare access times against.
- HRESULT Access() throw()
- {
- HRESULT hr = E_UNEXPECTED;
-
- if (!m_szSessionName ||
- m_szSessionName[0]==0)
- return hr; // no session to access
-
- // get the data connection for this thread
- CDataConnection dataconn;
- hr = GetSessionConnection(&dataconn, m_spServiceProvider);
- if (hr != S_OK)
- return hr;
-
- // The session reference entry in the references table must
- // be created prior to calling this function so we can just
- // use an updator to update the current entry.
- CCommand<CAccessor<CSessionRefUpdator> > updator;
-
- DBROWCOUNT nRows = 0;
- hr = updator.Assign(m_szSessionName);
- if (hr == S_OK)
- {
- hr = updator.Open( dataconn,
- m_QueryObj.GetSessionRefAccess(),
- NULL,
- &nRows,
- DBGUID_DEFAULT,
- false);
- }
-
- ATLASSERT(nRows > 0);
- if (hr == S_OK && nRows <= 0)
- hr = E_UNEXPECTED;
- return hr;
- }
-
- // If the session is expired and it's reference is 0,
- // it can be deleted. SessionUnlock calls this function to
- // unlock the session and delete it after we release a session
- // lock. Note that our SQL command will only delete the session
- // if it is expired and it's refcount is <= 0
- HRESULT FreeSession() throw()
- {
- HRESULT hr = E_UNEXPECTED;
- if (!m_szSessionName ||
- m_szSessionName[0]==0)
- return hr;
-
- // Get the data connection for this thread.
- CDataConnection dataconn;
- hr = GetSessionConnection(&dataconn, m_spServiceProvider);
- if (hr != S_OK)
- return hr;
-
- CCommand<CAccessor<CSessionRefUpdator> > updator;
-
- // The SQL for this command only deletes the
- // session reference from the references table if it's access
- // count is 0 and it has expired.
- return updator.Open(dataconn,
- m_QueryObj.GetSessionRefDelete(),
- NULL,
- NULL,
- DBGUID_DEFAULT,
- false);
- }
-
- // Initialize is called each time a new session is created.
- HRESULT Initialize( LPCSTR szSessionName,
- IServiceProvider *pServiceProvider,
- DWORD_PTR dwCookie,
- PFN_GETPROVIDERINFO pfnInfo) throw()
- {
- if (!szSessionName)
- return E_INVALIDARG;
-
- if (!pServiceProvider)
- return E_INVALIDARG;
-
- if (!pfnInfo)
- return E_INVALIDARG;
-
- m_pfnInfo = pfnInfo;
- m_dwProvCookie = dwCookie;
- m_spServiceProvider = pServiceProvider;
-
- _ATLTRY
- {
- CA2CT tcsSessionName(szSessionName);
- if (Checked::tcsnlen(tcsSessionName, MAX_SESSION_KEY_LEN) < MAX_SESSION_KEY_LEN)
- Checked::tcscpy_s(m_szSessionName, _countof(m_szSessionName), tcsSessionName);
- else
- return E_OUTOFMEMORY;
- }
- _ATLCATCHALL()
- {
- return E_OUTOFMEMORY;
- }
- return SessionLock();
- }
-
- HRESULT GetSessionConnection(CDataConnection *pConn,
- IServiceProvider *pProv) throw()
- {
- if (!pProv)
- return E_INVALIDARG;
-
- if (!m_pfnInfo ||
- !m_dwProvCookie)
- return E_UNEXPECTED;
-
- wchar_t *wszProv = NULL;
- if (m_pfnInfo(m_dwProvCookie, &wszProv) && wszProv!=NULL)
- {
- return GetDataSource(pProv,
- ATL_DBSESSION_ID,
- wszProv,
- pConn);
- }
- return E_FAIL;
- }
-
-
-protected:
- TCHAR m_szSessionName[MAX_SESSION_KEY_LEN];
- unsigned __int64 m_dwTimeout;
- CComPtr<IServiceProvider> m_spServiceProvider;
- DWORD_PTR m_dwProvCookie;
- PFN_GETPROVIDERINFO m_pfnInfo;
- DBQUERYCLASS_TYPE m_QueryObj;
-}; // CDBSession
-
-
-template <class TDBSession=CDBSession<> >
-class CDBSessionServiceImplT
-{
- wchar_t m_szConnectionString[MAX_CONNECTION_STRING_LEN];
- CComPtr<IServiceProvider> m_spServiceProvider;
- typename TDBSession::DBQUERYCLASS_TYPE m_QueryObj;
-public:
- typedef const wchar_t* SERVICEIMPL_INITPARAM_TYPE;
- CDBSessionServiceImplT() throw()
- {
- m_dwTimeout = ATL_SESSION_TIMEOUT;
- m_szConnectionString[0] = '\0';
- }
-
- static bool GetProviderInfo(DWORD_PTR dwProvCookie, wchar_t **ppszProvInfo) throw()
- {
- if (dwProvCookie &&
- ppszProvInfo)
- {
- CDBSessionServiceImplT<TDBSession> *pSvc =
- reinterpret_cast<CDBSessionServiceImplT<TDBSession>*>(dwProvCookie);
- *ppszProvInfo = pSvc->m_szConnectionString;
- return true;
- }
- return false;
- }
-
- HRESULT GetSessionConnection(CDataConnection *pConn,
- IServiceProvider *pProv) throw()
- {
- if (!pProv)
- return E_INVALIDARG;
-
- if(!m_szConnectionString[0])
- return E_UNEXPECTED;
-
- return GetDataSource(pProv,
- ATL_DBSESSION_ID,
- m_szConnectionString,
- pConn);
- }
-
- HRESULT Initialize(SERVICEIMPL_INITPARAM_TYPE pData,
- IServiceProvider *pProvider,
- unsigned __int64 dwInitialTimeout) throw()
- {
- if (!pData || !pProvider)
- return E_INVALIDARG;
-
- if (Checked::wcsnlen(pData, MAX_CONNECTION_STRING_LEN) < MAX_CONNECTION_STRING_LEN)
- {
- Checked::wcscpy_s(m_szConnectionString, _countof(m_szConnectionString), pData);
- }
- else
- return E_OUTOFMEMORY;
-
- m_dwTimeout = dwInitialTimeout;
- m_spServiceProvider = pProvider;
- return S_OK;
- }
-
- HRESULT CreateNewSession(__out_ecount_part_z(*pdwSize, *pdwSize) LPSTR szNewID, __inout DWORD *pdwSize, __deref_out ISession** ppSession) throw()
- {
- HRESULT hr = E_FAIL;
- CComObject<TDBSession> *pNewSession = NULL;
-
- if (!pdwSize)
- return E_POINTER;
-
- if (ppSession)
- *ppSession = NULL;
- else
- return E_POINTER;
-
- if (szNewID)
- *szNewID = NULL;
- else
- return E_INVALIDARG;
-
-
- // Create new session
- CComObject<TDBSession>::CreateInstance(&pNewSession);
- if (pNewSession == NULL)
- return E_OUTOFMEMORY;
-
- // Create a session name and initialize the object
- hr = m_SessionNameGenerator.GetNewSessionName(szNewID, pdwSize);
- if (hr == S_OK)
- {
- hr = pNewSession->Initialize(szNewID,
- m_spServiceProvider,
- reinterpret_cast<DWORD_PTR>(this),
- GetProviderInfo);
- if (hr == S_OK)
- {
- // we don't hold a reference to the object
- hr = pNewSession->QueryInterface(ppSession);
- }
- }
-
- if (hr != S_OK)
- delete pNewSession;
- return hr;
- }
-
- HRESULT CreateNewSessionByName(__in_z LPSTR szNewID, __deref_out ISession** ppSession) throw()
- {
- HRESULT hr = E_FAIL;
- CComObject<TDBSession> *pNewSession = NULL;
-
- if (!szNewID || *szNewID == 0)
- return E_INVALIDARG;
-
- if (ppSession)
- *ppSession = NULL;
- else
- return E_POINTER;
-
- // Create new session
- CComObject<TDBSession>::CreateInstance(&pNewSession);
- if (pNewSession == NULL)
- return E_OUTOFMEMORY;
-
- hr = pNewSession->Initialize(szNewID,
- m_spServiceProvider,
- reinterpret_cast<DWORD_PTR>(this),
- GetProviderInfo);
- if (hr == S_OK)
- {
- // we don't hold a reference to the object
- hr = pNewSession->QueryInterface(ppSession);
- }
-
-
- if (hr != S_OK)
- delete pNewSession;
- return hr;
- }
-
-
- HRESULT GetSession(LPCSTR szID, ISession **ppSession) throw()
- {
- HRESULT hr = E_FAIL;
- if (!szID)
- return E_INVALIDARG;
-
- if (ppSession)
- *ppSession = NULL;
- else
- return E_POINTER;
-
- CComObject<TDBSession> *pNewSession = NULL;
-
- // Check the DB to see if the session ID is a valid session
- _ATLTRY
- {
- CA2CT session(szID);
- hr = IsValidSession(session);
- }
- _ATLCATCHALL()
- {
- hr = E_OUTOFMEMORY;
- }
- if (hr == S_OK)
- {
- // Create new session object to represent this session
- CComObject<TDBSession>::CreateInstance(&pNewSession);
- if (pNewSession == NULL)
- return E_OUTOFMEMORY;
-
- hr = pNewSession->Initialize(szID,
- m_spServiceProvider,
- reinterpret_cast<DWORD_PTR>(this),
- GetProviderInfo);
- if (hr == S_OK)
- {
- // we don't hold a reference to the object
- hr = pNewSession->QueryInterface(ppSession);
- }
- }
-
- if (hr != S_OK && pNewSession)
- delete pNewSession;
- return hr;
- }
-
- HRESULT CloseSession(LPCSTR szID) throw()
- {
- if (!szID)
- return E_INVALIDARG;
-
- CDataConnection conn;
- HRESULT hr = GetSessionConnection(&conn,
- m_spServiceProvider);
- if (hr != S_OK)
- return hr;
-
- // set up accessors
- CCommand<CAccessor<CSessionRefUpdator> > updator;
- CCommand<CAccessor<CSessionDataDeleteAll> > command;
- _ATLTRY
- {
- CA2CT session(szID);
- hr = updator.Assign(session);
- if (hr == S_OK)
- hr = command.Assign(session);
- }
- _ATLCATCHALL()
- {
- hr = E_OUTOFMEMORY;
- }
-
- if (hr == S_OK)
- {
- // delete all session variables (may not be any!)
- hr = command.Open(conn,
- m_QueryObj.GetSessionVarDeleteAllVars(),
- NULL,
- NULL,
- DBGUID_DEFAULT,
- false);
- if (hr == S_OK)
- {
- DBROWCOUNT nRows = 0;
- nRows = 0;
- // delete references in the session references table
- hr = updator.Open(conn,
- m_QueryObj.GetSessionRefDeleteFinal(),
- NULL,
- &nRows,
- DBGUID_DEFAULT,
- false);
- if (nRows == 0)
- hr = E_UNEXPECTED;
- }
- }
- return hr;
- }
-
- HRESULT SetSessionTimeout(unsigned __int64 nTimeout) throw()
- {
- // Get the data connection for this thread
- CDataConnection conn;
-
- HRESULT hr = GetSessionConnection(&conn, m_spServiceProvider);
- if (hr != S_OK)
- return hr;
-
- // all sessions get the same timeout
- CCommand<CAccessor<CSetAllTimeouts> > command;
- hr = command.Assign(nTimeout);
- if (hr == S_OK)
- {
- hr = command.Open(conn, m_QueryObj.GetSessionReferencesSet(),
- NULL,
- NULL,
- DBGUID_DEFAULT,
- false);
- if (hr == S_OK)
- {
- m_dwTimeout = nTimeout;
- }
- }
- return hr;
- }
-
-
- HRESULT GetSessionTimeout(unsigned __int64* pnTimeout) throw()
- {
- if (pnTimeout)
- *pnTimeout = m_dwTimeout;
- else
- return E_INVALIDARG;
-
- return S_OK;
- }
-
- HRESULT GetSessionCount(DWORD *pnCount) throw()
- {
- if (pnCount)
- *pnCount = 0;
- else
- return E_POINTER;
-
- CCommand<CAccessor<CSessionRefCount> > command;
- CDataConnection conn;
- HRESULT hr = GetSessionConnection(&conn,
- m_spServiceProvider);
- if (hr != S_OK)
- return hr;
-
- hr = command.Open(conn,
- m_QueryObj.GetSessionRefGetCount());
- if (hr == S_OK)
- {
- hr = command.MoveFirst();
- if (hr == S_OK)
- {
- *pnCount = (DWORD)command.m_nCount;
- }
- }
-
- return hr;
- }
-
- void ReleaseAllSessions() throw()
- {
- // nothing to do
- }
-
- void SweepSessions() throw()
- {
- // nothing to do
- }
-
-
- // Helpers
- HRESULT IsValidSession(LPCTSTR szID) throw()
- {
- if (!szID)
- return E_INVALIDARG;
- // Look in the sessionreferences table to see if there is an entry
- // for this session.
- if (m_szConnectionString[0] == 0)
- return E_UNEXPECTED;
-
- CDataConnection conn;
- HRESULT hr = GetSessionConnection(&conn,
- m_spServiceProvider);
- if (hr != S_OK)
- return hr;
-
- // Check the session references table to see if
- // this is a valid session
- CCommand<CAccessor<CSessionRefSelector> > selector;
- hr = selector.Assign(szID);
- if (hr != S_OK)
- return hr;
-
- hr = selector.Open(conn,
- m_QueryObj.GetSessionRefSelect(),
- NULL,
- NULL,
- DBGUID_DEFAULT,
- true);
- if (hr == S_OK)
- return selector.MoveFirst();
- return hr;
- }
-
- CSessionNameGenerator m_SessionNameGenerator; // Object for generating session names
- unsigned __int64 m_dwTimeout;
-}; // CDBSessionServiceImplT
-
-typedef CDBSessionServiceImplT<> CDBSessionServiceImpl;
-
-
-
-
-
-//////////////////////////////////////////////////////////////////
-//
-// In-memory persisted session
-//
-//////////////////////////////////////////////////////////////////
-
-// In-memory persisted session service keeps a pointer
-// to the session obejct around in memory. The pointer is
-// contained in a CComPtr, which is stored in a CAtlMap, so
-// we have to have a CElementTraits class for that.
-typedef CComPtr<ISession> SESSIONPTRTYPE;
-
-template<>
-class CElementTraits<SESSIONPTRTYPE> :
- public CElementTraitsBase<SESSIONPTRTYPE>
-{
-public:
- static ULONG Hash( INARGTYPE obj ) throw()
- {
- return( (ULONG)(ULONG_PTR)obj.p);
- }
-
- static BOOL CompareElements( OUTARGTYPE element1, OUTARGTYPE element2 ) throw()
- {
- return element1.IsEqualObject(element2.p) ? TRUE : FALSE;
- }
-
- static int CompareElementsOrdered( INARGTYPE , INARGTYPE ) throw()
- {
- ATLASSERT(0); // NOT IMPLEMENTED
- return 0;
- }
-};
-
-
-// CMemSession
-// This session persistance class persists session variables in memory.
-// Note that this type of persistance should only be used on single server
-// web sites.
-class CMemSession :
- public ISession,
- public CComObjectRootEx<CComGlobalsThreadModel>
-{
-public:
- BEGIN_COM_MAP(CMemSession)
- COM_INTERFACE_ENTRY(ISession)
- END_COM_MAP()
-
- CMemSession() throw(...)
- {
- }
- virtual ~CMemSession()
- {
- }
-
- STDMETHOD(GetVariable)(LPCSTR szName, VARIANT *pVal) throw()
- {
- if (!szName)
- return E_INVALIDARG;
-
- if (pVal)
- VariantInit(pVal);
- else
- return E_POINTER;
-
- HRESULT hr = Access();
- if (hr == S_OK)
- {
- CSLockType lock(m_cs, false);
- hr = lock.Lock();
- if (FAILED(hr))
- return hr;
-
- hr = E_FAIL;
- _ATLTRY
- {
- CComVariant val;
- if (m_Variables.Lookup(szName, val))
- {
- hr = VariantCopy(pVal, &val);
- }
- }
- _ATLCATCHALL()
- {
- hr = E_UNEXPECTED;
- }
- }
- return hr;
- }
-
- STDMETHOD(SetVariable)(LPCSTR szName, VARIANT vNewVal) throw()
- {
- if (!szName)
- return E_INVALIDARG;
-
- HRESULT hr = Access();
- if (hr == S_OK)
- {
- CSLockType lock(m_cs, false);
- hr = lock.Lock();
- if (FAILED(hr))
- return hr;
- _ATLTRY
- {
- hr = m_Variables.SetAt(szName, vNewVal) ? S_OK : E_FAIL;
- }
- _ATLCATCHALL()
- {
- hr = E_UNEXPECTED;
- }
- }
- return hr;
- }
-
- STDMETHOD(RemoveVariable)(LPCSTR szName) throw()
- {
- if (!szName)
- return E_INVALIDARG;
-
- HRESULT hr = Access();
- if (hr == S_OK)
- {
- CSLockType lock(m_cs, false);
- hr = lock.Lock();
- if (FAILED(hr))
- return hr;
- _ATLTRY
- {
- hr = m_Variables.RemoveKey(szName) ? S_OK : E_FAIL;
- }
- _ATLCATCHALL()
- {
- hr = E_UNEXPECTED;
- }
- }
- return hr;
- }
-
- STDMETHOD(GetCount)(long *pnCount) throw()
- {
- if (pnCount)
- *pnCount = 0;
- else
- return E_POINTER;
-
- HRESULT hr = Access();
- if (hr == S_OK)
- {
- CSLockType lock(m_cs, false);
- hr = lock.Lock();
- if (FAILED(hr))
- return hr;
- *pnCount = (long) m_Variables.GetCount();
- }
- return hr;
- }
-
- STDMETHOD(RemoveAllVariables)() throw()
- {
- HRESULT hr = Access();
- if (hr == S_OK)
- {
- CSLockType lock(m_cs, false);
- hr = lock.Lock();
- if (FAILED(hr))
- return hr;
- m_Variables.RemoveAll();
- }
-
- return hr;
- }
-
- STDMETHOD(BeginVariableEnum)(POSITION *pPOS, HSESSIONENUM *phEnumHandle=NULL) throw()
- {
- if (phEnumHandle)
- *phEnumHandle = NULL;
-
- if (pPOS)
- *pPOS = NULL;
- else
- return E_POINTER;
-
- HRESULT hr = Access();
- if (hr == S_OK)
- {
- CSLockType lock(m_cs, false);
- hr = lock.Lock();
- if (FAILED(hr))
- return hr;
- *pPOS = m_Variables.GetStartPosition();
- }
- return hr;
- }
-
- STDMETHOD(GetNextVariable)(POSITION *pPOS, VARIANT *pVal,
- HSESSIONENUM hEnum=NULL,
- LPSTR szName=NULL,
- DWORD dwLen=0 ) throw()
- {
- (hEnum); // Unused!
- if (pVal)
- VariantInit(pVal);
- else
- return E_POINTER;
-
- if (!pPOS)
- return E_POINTER;
-
- CComVariant val;
- POSITION pos = *pPOS;
- HRESULT hr = Access();
- if (hr == S_OK)
- {
- CSLockType lock(m_cs, false);
- hr = lock.Lock();
- if (FAILED(hr))
- return hr;
-
- hr = E_FAIL;
- _ATLTRY
- {
- if (szName)
- {
- CStringA strName = m_Variables.GetKeyAt(pos);
- if (strName.GetLength())
- {
- if (dwLen > (DWORD)strName.GetLength())
- {
- Checked::strcpy_s(szName, dwLen, strName);
- hr = S_OK;
- }
- else
- hr = E_OUTOFMEMORY;
- }
- }
- else
- hr = S_OK;
-
- if (hr == S_OK)
- {
- val = m_Variables.GetNextValue(pos);
- hr = VariantCopy(pVal, &val);
- if (hr == S_OK)
- *pPOS = pos;
- }
- }
- _ATLCATCHALL()
- {
- hr = E_UNEXPECTED;
- }
- }
- return hr;
- }
-
- STDMETHOD(CloseEnum)(HSESSIONENUM /*hEnumHandle*/) throw()
- {
- return S_OK;
- }
-
- STDMETHOD(IsExpired)() throw()
- {
- CTime tmNow = CTime::GetCurrentTime();
- CTimeSpan span = tmNow-m_tLastAccess;
- if ((unsigned __int64)((span.GetTotalSeconds()*1000)) > m_dwTimeout)
- return S_OK;
- return S_FALSE;
- }
-
- HRESULT Access() throw()
- {
- // We lock here to protect against multiple threads
- // updating the same member concurrently.
- CSLockType lock(m_cs, false);
- HRESULT hr = lock.Lock();
- if (FAILED(hr))
- return hr;
- m_tLastAccess = CTime::GetCurrentTime();
- return S_OK;
- }
-
- STDMETHOD(SetTimeout)(unsigned __int64 dwNewTimeout) throw()
- {
- // We lock here to protect against multiple threads
- // updating the same member concurrently
- CSLockType lock(m_cs, false);
- HRESULT hr = lock.Lock();
- if (FAILED(hr))
- return hr;
- m_dwTimeout = dwNewTimeout;
- return S_OK;
- }
-
- HRESULT SessionLock() throw()
- {
- Access();
- return S_OK;
- }
-
- HRESULT SessionUnlock() throw()
- {
- return S_OK;
- }
-
-protected:
- typedef CAtlMap<CStringA,
- CComVariant,
- CStringElementTraits<CStringA> > VarMapType;
- unsigned __int64 m_dwTimeout;
- CTime m_tLastAccess;
- VarMapType m_Variables;
- CComAutoCriticalSection m_cs;
- typedef CComCritSecLock<CComAutoCriticalSection> CSLockType;
-}; // CMemSession
-
-
-//
-// CMemSessionServiceImpl
-// Implements the service part of in-memory persisted session services.
-//
-class CMemSessionServiceImpl
-{
-public:
- typedef void* SERVICEIMPL_INITPARAM_TYPE;
- CMemSessionServiceImpl() throw()
- {
- m_dwTimeout = ATL_SESSION_TIMEOUT;
- }
-
- ~CMemSessionServiceImpl() throw()
- {
- m_CritSec.Term();
- }
-
- HRESULT CreateNewSession(__out_ecount_part_z(*pdwSize, *pdwSize) LPSTR szNewID, __inout DWORD *pdwSize, __deref_out_opt ISession** ppSession) throw()
- {
- HRESULT hr = E_FAIL;
- CComObject<CMemSession> *pNewSession = NULL;
-
- if (!szNewID)
- return E_INVALIDARG;
-
- if (!pdwSize)
- return E_POINTER;
-
- if (ppSession)
- *ppSession = NULL;
- else
- return E_POINTER;
-
- _ATLTRY
- {
- // Create new session
- CComObject<CMemSession>::CreateInstance(&pNewSession);
- if (pNewSession == NULL)
- return E_OUTOFMEMORY;
-
- // Initialize and add to list of CSessionData
- hr = m_SessionNameGenerator.GetNewSessionName(szNewID, pdwSize);
-
- if (SUCCEEDED(hr))
- {
- CComPtr<ISession> spSession;
- hr = pNewSession->QueryInterface(&spSession);
- if (SUCCEEDED(hr))
- {
- pNewSession->SetTimeout(m_dwTimeout);
- pNewSession->Access();
- CSLockType lock(m_CritSec, false);
- hr = lock.Lock();
- if (FAILED(hr))
- return hr;
- hr = m_Sessions.SetAt(szNewID, spSession) != NULL ? S_OK : E_FAIL;
- if (hr == S_OK)
- *ppSession = spSession.Detach();
- }
- }
- }
- _ATLCATCHALL()
- {
- hr = E_UNEXPECTED;
- }
-
- return hr;
-
- }
-
- HRESULT CreateNewSessionByName(__in_z LPSTR szNewID, __deref_out_opt ISession** ppSession) throw()
- {
- HRESULT hr = E_FAIL;
- CComObject<CMemSession> *pNewSession = NULL;
-
- if (!szNewID || *szNewID == 0)
- return E_INVALIDARG;
-
- if (ppSession)
- *ppSession = NULL;
- else
- return E_POINTER;
-
- CComPtr<ISession> spSession;
- // If the session already exists, you get a pointer to the
- // existing session. You can't have multiple entries with the
- // same name in CAtlMap
- hr = GetSession(szNewID, &spSession);
- if (hr == S_OK)
- {
- *ppSession = spSession.Detach();
- return hr;
- }
-
- _ATLTRY
- {
- // Create new session
- CComObject<CMemSession>::CreateInstance(&pNewSession);
- if (pNewSession == NULL)
- return E_OUTOFMEMORY;
-
-
- hr = pNewSession->QueryInterface(&spSession);
- if (SUCCEEDED(hr))
- {
- pNewSession->SetTimeout(m_dwTimeout);
- pNewSession->Access();
- CSLockType lock(m_CritSec, false);
- hr = lock.Lock();
- if (FAILED(hr))
- return hr;
-
- hr = m_Sessions.SetAt(szNewID, spSession) != NULL ? S_OK : E_FAIL;
-
- if (hr == S_OK)
- *ppSession = spSession.Detach();
- }
- }
- _ATLCATCHALL()
- {
- hr = E_UNEXPECTED;
- }
-
- return hr;
-
- }
-
- HRESULT GetSession(LPCSTR szID, ISession **ppSession) throw()
- {
- HRESULT hr = E_FAIL;
- SessMapType::CPair *pPair = NULL;
-
- if (ppSession)
- *ppSession = NULL;
- else
- return E_POINTER;
-
- if (!szID)
- return E_INVALIDARG;
-
- CSLockType lock(m_CritSec, false);
- hr = lock.Lock();
- if (FAILED(hr))
- return hr;
-
- hr = E_FAIL;
- _ATLTRY
- {
- pPair = m_Sessions.Lookup(szID);
- if (pPair) // the session exists and is in our local map of sessions
- {
- hr = pPair->m_value.QueryInterface(ppSession);
- }
- }
- _ATLCATCHALL()
- {
- return E_UNEXPECTED;
- }
-
- return hr;
- }
-
- HRESULT CloseSession(LPCSTR szID) throw()
- {
- if (!szID)
- return E_INVALIDARG;
-
- HRESULT hr = E_FAIL;
- CSLockType lock(m_CritSec, false);
- hr = lock.Lock();
- if (FAILED(hr))
- return hr;
- _ATLTRY
- {
- hr = m_Sessions.RemoveKey(szID) ? S_OK : E_UNEXPECTED;
- }
- _ATLCATCHALL()
- {
- hr = E_UNEXPECTED;
- }
- return hr;
- }
-
- void SweepSessions() throw()
- {
- POSITION posRemove = NULL;
- const SessMapType::CPair *pPair = NULL;
- POSITION pos = NULL;
-
- CSLockType lock(m_CritSec, false);
- if (FAILED(lock.Lock()))
- return;
- pos = m_Sessions.GetStartPosition();
- while (pos)
- {
- posRemove = pos;
- pPair = m_Sessions.GetNext(pos);
- if (pPair)
- {
- if (pPair->m_value.p &&
- S_OK == pPair->m_value->IsExpired())
- {
- // remove our reference on the session
- m_Sessions.RemoveAtPos(posRemove);
- }
- }
- }
- }
-
- HRESULT SetSessionTimeout(unsigned __int64 nTimeout) throw()
- {
- HRESULT hr = S_OK;
- CComPtr<ISession> spSession;
- m_dwTimeout = nTimeout;
-
- CSLockType lock(m_CritSec, false);
- hr = lock.Lock();
- if (FAILED(hr))
- return hr;
-
- POSITION pos = m_Sessions.GetStartPosition();
- if (!pos)
- return S_OK; // no sessions to set the timeout on
-
-
- while (pos)
- {
- SessMapType::CPair *pPair = const_cast<SessMapType::CPair*>(m_Sessions.GetNext(pos));
- if (pPair)
- {
- spSession = pPair->m_value;
- if (spSession)
- {
- // if we fail on any of the sets we will return the
- // error code immediately
- hr = spSession->SetTimeout(nTimeout);
- spSession.Release();
- if (hr != S_OK)
- break;
- }
- else
- {
- hr = E_UNEXPECTED;
- break;
- }
- }
- else
- {
- hr = E_UNEXPECTED;
- break;
- }
- }
-
- return hr;
- }
-
- HRESULT GetSessionTimeout(unsigned __int64* pnTimeout) throw()
- {
- if (pnTimeout)
- *pnTimeout = m_dwTimeout;
- else
- return E_POINTER;
-
- return S_OK;
- }
-
- HRESULT GetSessionCount(DWORD *pnCount) throw()
- {
- if (pnCount)
- *pnCount = 0;
- else
- return E_POINTER;
-
- CSLockType lock(m_CritSec, false);
- HRESULT hr = lock.Lock();
- if (FAILED(hr))
- return hr;
- *pnCount = (DWORD)m_Sessions.GetCount();
-
- return S_OK;
- }
-
- void ReleaseAllSessions() throw()
- {
- CSLockType lock(m_CritSec, false);
- if (FAILED(lock.Lock()))
- return;
- m_Sessions.RemoveAll();
- }
-
- HRESULT Initialize(SERVICEIMPL_INITPARAM_TYPE,
- IServiceProvider*,
- unsigned __int64 dwNewTimeout) throw()
- {
- m_dwTimeout = dwNewTimeout;
- return m_CritSec.Init();
- }
-
- typedef CAtlMap<CStringA,
- SESSIONPTRTYPE,
- CStringElementTraits<CStringA>,
- CElementTraitsBase<SESSIONPTRTYPE> > SessMapType;
-
- SessMapType m_Sessions; // map for holding sessions in memory
- CComCriticalSection m_CritSec; // for synchronizing access to map
- typedef CComCritSecLock<CComCriticalSection> CSLockType;
- CSessionNameGenerator m_SessionNameGenerator; // Object for generating session names
- unsigned __int64 m_dwTimeout;
-}; // CMemSessionServiceImpl
-
-
-
-//
-// CSessionStateService
-// This class implements the session state service which can be
-// exposed to request handlers.
-//
-// Template Parameters:
-// MonitorClass: Provides periodic sweeping services for the session service class.
-// TServiceImplClass: The class that actually implements the methods of the
-// ISessionStateService and ISessionStateControl interfaces.
-template <class MonitorClass, class TServiceImplClass >
-class CSessionStateService :
- public ISessionStateService,
- public ISessionStateControl,
- public IWorkerThreadClient,
- public CComObjectRootEx<CComGlobalsThreadModel>
-{
-protected:
- MonitorClass m_Monitor;
- HANDLE m_hTimer;
- CComPtr<IServiceProvider> m_spServiceProvider;
- TServiceImplClass m_SessionServiceImpl;
-public:
- // Construction/Initialization
- CSessionStateService() throw() :
- m_hTimer(NULL)
- {
-
- }
- ~CSessionStateService() throw()
- {
- ATLASSUME(m_hTimer == NULL);
- }
- BEGIN_COM_MAP(CSessionStateService)
- COM_INTERFACE_ENTRY(ISessionStateService)
- COM_INTERFACE_ENTRY(ISessionStateControl)
- END_COM_MAP()
-
-// ISessionStateServie methods
- STDMETHOD(CreateNewSession)(LPSTR szNewID, DWORD *pdwSize, ISession** ppSession) throw()
- {
- return m_SessionServiceImpl.CreateNewSession(szNewID, pdwSize, ppSession);
- }
-
- STDMETHOD(CreateNewSessionByName)(LPSTR szNewID, ISession** ppSession) throw()
- {
- return m_SessionServiceImpl.CreateNewSessionByName(szNewID, ppSession);
- }
-
- STDMETHOD(GetSession)(LPCSTR szID, ISession **ppSession) throw()
- {
- return m_SessionServiceImpl.GetSession(szID, ppSession);
- }
-
- STDMETHOD(CloseSession)(LPCSTR szSessionID) throw()
- {
- return m_SessionServiceImpl.CloseSession(szSessionID);
- }
-
- STDMETHOD(SetSessionTimeout)(unsigned __int64 nTimeout) throw()
- {
- return m_SessionServiceImpl.SetSessionTimeout(nTimeout);
- }
-
- STDMETHOD(GetSessionTimeout)(unsigned __int64 *pnTimeout) throw()
- {
- return m_SessionServiceImpl.GetSessionTimeout(pnTimeout);
- }
-
- STDMETHOD(GetSessionCount)(DWORD *pnSessionCount) throw()
- {
- return m_SessionServiceImpl.GetSessionCount(pnSessionCount);
- }
-
- void SweepSessions() throw()
- {
- m_SessionServiceImpl.SweepSessions();
- }
-
- void ReleaseAllSessions() throw()
- {
- m_SessionServiceImpl.ReleaseAllSessions();
- }
-
- HRESULT Initialize(
- IServiceProvider *pServiceProvider = NULL,
- typename TServiceImplClass::SERVICEIMPL_INITPARAM_TYPE pInitData = NULL,
- unsigned __int64 dwTimeout = ATL_SESSION_TIMEOUT) throw()
- {
- HRESULT hr = S_OK;
- if (pServiceProvider)
- m_spServiceProvider = pServiceProvider;
-
- hr = m_SessionServiceImpl.Initialize(pInitData, pServiceProvider, dwTimeout);
-
- return hr;
- }
-
-
- template <class ThreadTraits>
- HRESULT Initialize(
- CWorkerThread<ThreadTraits> *pWorker,
- IServiceProvider *pServiceProvider = NULL,
- typename TServiceImplClass::SERVICEIMPL_INITPARAM_TYPE pInitData = NULL,
- unsigned __int64 dwTimeout = ATL_SESSION_TIMEOUT) throw()
- {
- if (!pWorker)
- return E_INVALIDARG;
-
- HRESULT hr = Initialize(pServiceProvider, pInitData, dwTimeout);
- if (hr == S_OK)
- {
- hr = m_Monitor.Initialize(pWorker);
- if (hr == S_OK)
- {
- //sweep every 500ms
- hr = m_Monitor.AddTimer(ATL_SESSION_SWEEPER_TIMEOUT, this, 0, &m_hTimer);
- }
- }
- return hr;
- }
-
- void Shutdown() throw()
- {
- if (m_hTimer)
- {
- if(FAILED(m_Monitor.RemoveHandle(m_hTimer)))
- {
- /* can't report from here */
- ATLASSERT(FALSE);
- }
- m_hTimer = NULL;
- }
- ReleaseAllSessions();
- }
-// Implementation
- HRESULT Execute(DWORD_PTR /*dwParam*/, HANDLE /*hObject*/) throw()
- {
- SweepSessions();
- return S_OK;
- }
-
- HRESULT CloseHandle(HANDLE hHandle) throw()
- {
- ::CloseHandle(hHandle);
- m_hTimer = NULL;
- return S_OK;
- }
-
-}; // CSessionStateService
-
-} // namespace ATL
-#pragma pack(pop)
-
-#pragma warning(pop)
-#endif // __ATLSESSION_H__
diff --git a/include/atl/atlsharedsvc.h b/include/atl/atlsharedsvc.h
deleted file mode 100644
index b309f12c6..000000000
--- a/include/atl/atlsharedsvc.h
+++ /dev/null
@@ -1,202 +0,0 @@
-// This is a part of the Active Template Library.
-// Copyright (C) Microsoft Corporation
-// All rights reserved.
-//
-// This source code is only intended as a supplement to the
-// Active Template Library Reference and related
-// electronic documentation provided with the library.
-// See these sources for detailed information regarding the
-// Active Template Library product.
-
-#ifndef __ATLSHAREDSVC_H__
-#define __ATLSHAREDSVC_H__
-
-#pragma once
-
-#include <atltime.h>
-#include <atlsoap.h>
-#pragma pack(push,_ATL_PACKING)
-namespace ATL{
-
-#ifndef ATL_SHAREDBLOBCACHE_TIMEOUT
- #define ATL_SHAREDBLOBCACHE_TIMEOUT 36000000000 // in 100 nano second intervals
- // each entry will be free'd if
- // no access in 1 hour.
-#endif
-
-// Interface used by to access the shared blob cache.
-[ uuid("AB4AF9CD-8DB1-4974-A617-CF0449578FB9"), object ]
-__interface ISharedBlobCache
-{
- [id(0)] STDMETHOD(AddItem)([in] BSTR szItemName, [in] BSTR szData);
- [id(1)] STDMETHOD(GetItem)([in] BSTR szItemName, [out,retval] BSTR *szData);
-};
-
-class CSharedCache:
- public CBlobCache<CWorkerThread<>, CStdStatClass >,
- public IMemoryCacheClient,
- public ISharedBlobCache
-{
- typedef CBlobCache<CWorkerThread<>, CStdStatClass > basecache;
-public:
-
- // IMemoryCacheClient method, frees data in the memory cache.
- STDMETHOD( Free )(const void *pvData)
- {
- if (pvData)
- {
- ::SysFreeString((BSTR)pvData);
- }
- return S_OK;
- }
-
-
- STDMETHODIMP AddItem(BSTR szItemName, BSTR szData)
- {
-
- HRESULT hr = E_UNEXPECTED;
-
- // We make a copy of the BSTR and stick it in the cache.
- // The BSTR will be freed in our IMemoryCacheClient::Free
- // implementation above.
- BSTR szEntry = SysAllocString(szData);
- if(szEntry)
- {
- USES_CONVERSION_EX;
- // create a time span and for the entry
- CFileTime tm = CFileTime::GetCurrentTime();
- CFileTimeSpan span;
- span.SetTimeSpan(ATL_SHAREDBLOBCACHE_TIMEOUT);
- tm += span;
- HCACHEITEM h;
- hr = basecache::Add(OLE2A_EX(szItemName, _ATL_SAFE_ALLOCA_DEF_THRESHOLD), szEntry, sizeof(BSTR),
- &tm, _AtlBaseModule.m_hInst, &h, static_cast<IMemoryCacheClient*>(this));
-
- if (hr == S_OK)
- {
- // On successful add, we have to release our
- // reference on the entry.
- basecache::ReleaseEntry(h);
- }
- }
- return hr;
- }
-
- STDMETHODIMP GetItem(BSTR szItemName, BSTR *szData)
- {
- USES_CONVERSION_EX;
- HRESULT hr = E_UNEXPECTED;
- HCACHEITEM hEntry = NULL;
-
- if (!szItemName || !szData)
- return hr;
-
- hr = basecache::LookupEntry(OLE2A_EX(szItemName, _ATL_SAFE_ALLOCA_DEF_THRESHOLD), &hEntry);
- if (hr == S_OK)
- {
- void *pData = NULL;
- DWORD dwSize = 0;
- hr = basecache::GetData(hEntry, &pData, &dwSize);
- if (hr == S_OK)
- {
- // make a copy of the string
- *szData = ::SysAllocString((BSTR)pData);
- }
- basecache::ReleaseEntry(hEntry);
- }
- return hr;
- }
-
-
- STDMETHODIMP QueryInterface(REFIID riid, void **ppv)
- {
- HRESULT hr = E_NOINTERFACE;
- if (InlineIsEqualGUID(__uuidof(IMemoryCacheClient), riid)||
- InlineIsEqualGUID(__uuidof(IUnknown), riid))
- {
- *ppv = static_cast<void*>(static_cast<IMemoryCacheClient*>(this));
- hr = S_OK;
- }
- else if( InlineIsEqualGUID(__uuidof(ISharedBlobCache), riid))
- {
- *ppv = static_cast<void*>(static_cast<ISharedBlobCache*>(this));
- hr = S_OK;
- }
- return hr;
- }
- ULONG STDMETHODCALLTYPE AddRef()
- {
- return 1;
- }
- ULONG STDMETHODCALLTYPE Release()
- {
- return 1;
- }
-};
-
-
-// This class implements the SOAP interface for the shared blob cache.
-[
- soap_handler(
- name="SharedBlobCache",
- namespace="http://www.microsoft.com/vc/atlserver/soap/SharedBlobCache",
- protocol="soap"
- ),
- request_handler(
- name="SharedBlobCache",
- sdl="GenSharedBlobCacheWSDL"
- )
-]
-class CSharedCacheHandler:
- public ISharedBlobCache
-{
-public:
- [soap_method]
- STDMETHOD(AddItem)(BSTR szItemName, BSTR szData)
- {
- if (!m_spMemCache)
- return E_UNEXPECTED;
- return m_spMemCache->AddItem(szItemName, szData);
- }
-
- [soap_method]
- STDMETHOD(GetItem)(BSTR szItemName, BSTR *szData)
- {
- if (!m_spMemCache)
- return E_UNEXPECTED;
- return m_spMemCache->GetItem(szItemName, szData);
- }
-
- HTTP_CODE Initialize(IServiceProvider *pProvider)
- {
- ATLASSERT(pProvider); // should never be NULL
- if (!pProvider)
- return HTTP_ERROR(500, ISE_SUBERR_UNEXPECTED);
-
- if (m_spMemCache)
- return HTTP_SUCCESS; // already initialized
-
- pProvider->QueryService(__uuidof(ISharedBlobCache), &m_spMemCache);
- return m_spMemCache ? HTTP_SUCCESS : HTTP_ERROR(500, ISE_SUBERR_UNEXPECTED);
- }
-
- // override HandleRequest to Initialize our m_spServiceProvider
- // and to handle authorizing the client.
- HTTP_CODE HandleRequest(AtlServerRequest *pRequestInfo, IServiceProvider *pProvider)
- {
- HTTP_CODE dwErr = Initialize(pProvider);
- if (dwErr != HTTP_SUCCESS)
- return dwErr;
-
- dwErr = CSoapHandler<CSharedCacheHandler>::HandleRequest(pRequestInfo,
- pProvider);
- return dwErr;
- }
- CComPtr<ISharedBlobCache> m_spMemCache;
-};
-
-} //ATL
-
-#pragma pack(pop)
-
-#endif // __ATLSHAREDSVC_H__
diff --git a/include/atl/atlsmtpconnection.h b/include/atl/atlsmtpconnection.h
deleted file mode 100644
index 5cda41d1d..000000000
--- a/include/atl/atlsmtpconnection.h
+++ /dev/null
@@ -1,926 +0,0 @@
-// This is a part of the Active Template Library.
-// Copyright (C) Microsoft Corporation
-// All rights reserved.
-//
-// This source code is only intended as a supplement to the
-// Active Template Library Reference and related
-// electronic documentation provided with the library.
-// See these sources for detailed information regarding the
-// Active Template Library product.
-
-#ifndef __ATLSMTPCONNECTION_H__
-#define __ATLSMTPCONNECTION_H__
-
-#pragma once
-
-#ifndef _ATL_NO_DEFAULT_LIBS
-#pragma comment(lib, "ws2_32.lib")
-#endif // !_ATL_NO_DEFAULT_LIBS
-
-#include <winsock2.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <tchar.h>
-#include <atlstr.h>
-#include <atlcoll.h>
-#include <atlfile.h>
-#include <atlmime.h>
-#include <atlspriv.h>
-#include <atlsmtputil.h>
-#include <atlsocket.h>
-
-// SMTP Return Codes
-#define ATLSMTP_MAIL_SUCCESS 250
-#define ATLSMTP_RCPT_SUCCESS 250
-#define ATLSMTP_RCPT_NOT_LOCAL 251
-#define ATLSMTP_DATA_INTERMEDIATE 354
-
-#define ATLSMTP_CONN_SUCC "220"
-#define ATLSMTP_HELO_SUCC "250"
-#define ATLSMTP_MAIL_SUCC "250"
-#define ATLSMTP_RCPT_SUCC "250"
-#define ATLSMTP_RCPT_NLOC "251"
-#define ATLSMTP_DATA_INTM "354"
-#define ATLSMTP_DATA_SUCC "250"
-#define ATLSMTP_RSET_SUCC "250"
-
-// SMTP flags
-#define ATLSMTP_DUMP_SENDER 1
-#define ATLSMTP_DUMP_RECIPS 2
-#define ATLSMTP_FOR_SEND 4
-
-
-struct CSMTPWSAStartup
-{
-private:
- bool m_bInit;
-
-public:
- CSMTPWSAStartup() throw()
- :m_bInit(false)
- {
- Init();
- }
-
- ~CSMTPWSAStartup() throw()
- {
- Uninit();
- }
-
- bool Init() throw()
- {
- if (m_bInit)
- return true;
-
- WSADATA wsadata;
- if (WSAStartup(ATLSMTP_WSA_VERSION, &wsadata))
- return false;
- m_bInit = true;
- ATLASSERT(wsadata.wHighVersion >= 2);
- return true;
- }
-
- bool Uninit() throw()
- {
- if (m_bInit)
- if (WSACleanup())
- return false;
- m_bInit = false;
- return true;
- }
-};
-
-__declspec(selectany) CSMTPWSAStartup _g_smtp_init;
-
-#pragma pack(push,_ATL_PACKING)
-namespace ATL {
-
-class CSMTPConnection
-{
-protected:
-
- // the socket
- SOCKET m_hSocket;
-
- // the OVERLAPPED struct
- OVERLAPPED m_Overlapped;
-
-public:
-
- CSMTPConnection() throw()
- :m_hSocket(INVALID_SOCKET)
- {
- // initialize the OVERLAPPED struct
- memset(&m_Overlapped, 0, sizeof(OVERLAPPED));
- }
-
- ~CSMTPConnection() throw()
- {
- Disconnect();
- }
-
- // Attempt to connect to the socket
- // lpszHostName - the host name to connect to
- BOOL Connect(LPCTSTR lpszHostName, DWORD dwTimeout = 10000) throw()
- {
- ATLASSERT(lpszHostName != NULL);
-
- // If we're already connected
- if (Connected())
- {
- return FALSE;
- }
-
- if (!_g_smtp_init.Init())
- {
- return FALSE;
- }
-
- CSocketAddr address;
- if (address.FindAddr(lpszHostName, IPPORT_SMTP, 0, PF_UNSPEC, SOCK_STREAM, 0))
- {
- return FALSE;
- }
-
- ADDRINFOT *pAI;
-
- BOOL bRet = FALSE;
- int nIndex = 0;
- while ((pAI = address.GetAddrInfo(nIndex++)) != NULL)
- {
- // create the socket
- m_hSocket = WSASocket(pAI->ai_family, pAI->ai_socktype, pAI->ai_protocol, NULL, 0, WSA_FLAG_OVERLAPPED);
-
- if (m_hSocket == INVALID_SOCKET)
- {
- return FALSE;
- }
-
- bRet = FALSE;
- WSAEVENT hEventConnect = WSACreateEvent();
- if (hEventConnect != NULL)
- {
- if (SOCKET_ERROR != WSAEventSelect(m_hSocket, hEventConnect, FD_CONNECT))
- {
- if (WSAConnect(m_hSocket, pAI->ai_addr, (int)pAI->ai_addrlen,
- NULL, NULL, NULL, NULL))
- {
- if (WSAGetLastError() == WSAEWOULDBLOCK)
- {
- DWORD dwWait = WaitForSingleObject((HANDLE) hEventConnect, dwTimeout);
- if (dwWait == WAIT_OBJECT_0)
- {
- // make sure there were no connection errors.
- WSANETWORKEVENTS wse;
- ZeroMemory(&wse, sizeof(wse));
- WSAEnumNetworkEvents(m_hSocket, NULL, &wse);
- if (wse.iErrorCode[FD_CONNECT_BIT]==0)
- {
- bRet = TRUE;
- }
- }
- }
- }
- }
-
- // we're done with the event
- WSACloseEvent(hEventConnect);
- }
- if (bRet)
- {
- break;
- }
-
- shutdown(m_hSocket, SD_BOTH);
- closesocket(m_hSocket);
- m_hSocket = INVALID_SOCKET;
- }
-
-
- // Create an event for asynchronous I/O
- if (bRet)
- {
- ATLASSUME(m_Overlapped.hEvent == NULL);
- m_Overlapped.hEvent = CreateEvent(NULL, TRUE, TRUE, NULL);
- if (m_Overlapped.hEvent == NULL)
- {
- bRet = FALSE;
- }
- }
-
- char szBuf[ATLSMTP_MAX_LINE_LENGTH+1];
- int nBufLen = ATLSMTP_MAX_LINE_LENGTH;
- if (bRet)
- {
- // See if the connect returns success
- bRet = AtlSmtpReadData((HANDLE)m_hSocket, szBuf, &nBufLen, &m_Overlapped);
- if (bRet)
- {
- if (strncmp(szBuf, ATLSMTP_CONN_SUCC, ATLSMTP_RETCODE_LEN))
- {
- bRet = FALSE;
- }
- }
- }
-
- char szLocalHost[ATLSMTP_MAX_SERVER_NAME_LENGTH+1];
-
- // gethostname should return 0 on success
- if (bRet && gethostname(szLocalHost, ATLSMTP_MAX_SERVER_NAME_LENGTH))
- {
- bRet = FALSE;
- }
-
- // Send HELO command and get reply
- if (bRet)
- {
- nBufLen = sprintf_s(szBuf, ATLSMTP_MAX_LINE_LENGTH+1, "HELO %s\r\n", szLocalHost);
- if (nBufLen > 0)
- {
- bRet = AtlSmtpSendAndCheck((HANDLE)m_hSocket, szBuf, nBufLen, szBuf, &nBufLen,
- ATLSMTP_MAX_LINE_LENGTH, ATLSMTP_HELO_SUCC, &m_Overlapped);
- }
- else
- {
- bRet = FALSE;
- }
- }
-
- if (!bRet)
- {
- if (m_Overlapped.hEvent != NULL)
- CloseHandle(m_Overlapped.hEvent);
- shutdown(m_hSocket, SD_BOTH);
- closesocket(m_hSocket);
- m_hSocket = INVALID_SOCKET;
- }
-
- return bRet;
- }
-
- // Disconnect the socket
- inline BOOL Disconnect() throw()
- {
- if (!Connected())
- {
- return FALSE;
- }
-
- // shutdown should return 0 on success
- if (shutdown(m_hSocket, SD_BOTH))
- {
- return FALSE;
- }
-
- // closesocket should return 0 on success
- if (closesocket(m_hSocket))
- {
- return FALSE;
- }
-
- // close the handle to the overlapped event
- CloseHandle(m_Overlapped.hEvent);
- m_hSocket = INVALID_SOCKET;
- memset((void*)&m_Overlapped, 0, sizeof(OVERLAPPED));
- return TRUE;
- }
-
- // Are we connected?
- inline BOOL Connected() throw()
- {
- return (m_hSocket != INVALID_SOCKET ? TRUE : FALSE);
- }
-
- // Send a message from a file
- // lpszFileName - the file containing the message
- // lpszRecipients - the recipients to send to (optional - if not specified, the recipients specified
- // in the file will be used
- // lpszSender - the sender (optional - if not specified, the recipients specified in the file
- // will be used
- BOOL SendMessage(LPCTSTR lpszFileName, LPCTSTR lpszRecipients = NULL, LPCTSTR lpszSender = NULL) throw()
- {
- if (!Connected())
- {
- return FALSE;
- }
-
- //Try to open the file
- CAtlFile readFile;
- if (FAILED(readFile.Create(lpszFileName, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL)))
- {
- return FALSE;
- }
-
- char szBuf[ATLSMTP_MAX_LINE_LENGTH+1];
- int nBufLen = ATLSMTP_MAX_LINE_LENGTH;
- BOOL bDumpedSender = FALSE;
-
- //If the caller specifies the sender, rather than having an existing one in the file...
- if (lpszSender)
- {
- nBufLen = sprintf_s(szBuf, ATLSMTP_MAX_LINE_LENGTH+1,
- "MAIL FROM:<%s>\r\n", (LPCSTR) CT2CA(lpszSender));
- if ((nBufLen < 0) ||
- (!AtlSmtpSendAndCheck((HANDLE)m_hSocket, szBuf, nBufLen, szBuf, &nBufLen, ATLSMTP_MAX_LINE_LENGTH,
- ATLSMTP_MAIL_SUCC, &m_Overlapped)))
- {
- return FALSE;
- }
- bDumpedSender = TRUE;
- }
- nBufLen = ATLSMTP_MAX_LINE_LENGTH;
-
-#ifdef ATLSMTP_DOUBLE_BUFFERED
- char buffer1[ATLSMTP_READBUFFER_SIZE];
- char buffer2[ATLSMTP_READBUFFER_SIZE];
- char* currBuffer = buffer1;
- char* prevBuffer = NULL;
-
- int nCurrBuffer = 0;
- DWORD dwPrevLength = 0;
- DWORD dwWritten = 0;
-#else
- char bakBuffer[ATLSMTP_READBUFFER_SIZE];
- char* currBuffer = bakBuffer;
-
-#endif // ATLSMTP_DOUBLE_BUFFERED
- DWORD dwRead = 0;
- DWORD dwBytesInBuffer = 0;
- DWORD dwBufPos = 0;
-
- //first handle the MAIL FROM and RCPT TO commands
- BOOL bDumpedRecipients = FALSE;
- BOOL bRet = TRUE;
- while (bRet)
- {
- int nRetCode = 0;
-
- //if we have dumped the sender, and we have extra recipients to send,
- //and we haven't alredy done so, do it
- if (lpszRecipients && !bDumpedRecipients && bDumpedSender)
- {
- bRet = DumpRecipients((HANDLE)m_hSocket, CT2A(lpszRecipients), &m_Overlapped, ATLSMTP_FOR_SEND);
- }
-
- if (bRet)
- {
- dwRead = 0;
- BOOL bFullLine = FALSE;
- bRet = ReadLine(readFile, currBuffer, szBuf, &dwBytesInBuffer, &dwBufPos,
- ATLSMTP_READBUFFER_SIZE, ATLSMTP_MAX_LINE_LENGTH, &dwRead, &bFullLine);
- if (dwRead == 0 || bFullLine == FALSE)
- bRet = FALSE;
- }
-
- if (bRet)
- {
- bRet = AtlSmtpSendAndWait((HANDLE)m_hSocket, szBuf, (int)(dwRead), &m_Overlapped);
- }
-
- if (bRet)
- {
- nBufLen = ATLSMTP_MAX_LINE_LENGTH;
- bRet = AtlSmtpReadData((HANDLE)m_hSocket, szBuf, &nBufLen, &m_Overlapped);
- }
-
- if (bRet)
- {
- nRetCode = atoi(szBuf);
- //if the command is equal to ATLSMTP_MAIL_SUCC (or RCPT_SUCC: they are equivalent)
- if (nRetCode == ATLSMTP_MAIL_SUCCESS || nRetCode == ATLSMTP_RCPT_NOT_LOCAL || nRetCode == ATLSMTP_RCPT_SUCCESS)
- {
- bDumpedSender = TRUE;
- continue;
- }
-
- //If the command is equal to the data intermediate success code,
- //break out of the loop
- if (nRetCode == ATLSMTP_DATA_INTERMEDIATE)
- break;
- }
-
- //otherwise, we got an error code
- CancelMessage();
- return FALSE;
- }
-
- dwRead = dwBytesInBuffer;
- currBuffer+= dwBufPos;
- DWORD dwErr = 0;
- do
- {
- dwErr = 0;
-
- //Try to send the data
-#ifdef ATLSMTP_DOUBLE_BUFFERED
- if (!AtlSmtpSendOverlapped((HANDLE)m_hSocket, currBuffer, dwRead, prevBuffer, dwPrevLength, &m_Overlapped))
- {
- bRet = FALSE;
- break;
- }
-#else
- if (!AtlSmtpSendAndWait((HANDLE)m_hSocket, currBuffer, dwRead, &m_Overlapped))
- {
- bRet = FALSE;
- break;
- }
-#endif // ATLSMTP_DOUBLE_BUFFERED
-
- //swap the current and previous buffer
-#ifdef ATLSMTP_DOUBLE_BUFFERED
- prevBuffer = currBuffer;
- currBuffer = (nCurrBuffer == 0 ? buffer2 : buffer1);
- nCurrBuffer = (nCurrBuffer == 0 ? 1 : 0);
- dwPrevLength = dwBytesInBuffer;
-#else
- currBuffer = bakBuffer;
-#endif // ATLSMTP_DOUBLE_BUFFERED
-
- if (FAILED(readFile.Read(currBuffer, ATLSMTP_READBUFFER_SIZE, dwRead)))
- {
- bRet = FALSE;
- break;
- }
- } while (dwRead != 0);
-
- //ensure that the last of the data is sent
-#ifdef ATLSMTP_DOUBLE_BUFFERED
- if (!GetOverlappedResult((HANDLE)m_hSocket, &m_Overlapped, &dwWritten, TRUE))
- {
- if ((dwErr = GetLastError()) != ERROR_IO_PENDING && dwErr != ERROR_IO_INCOMPLETE)
- bRet = FALSE;
- else if (dwWritten < dwPrevLength)
- bRet = AtlSmtpSendAndWait((HANDLE)m_hSocket, prevBuffer+dwWritten, dwPrevLength-dwWritten, &m_Overlapped);
- }
-#endif // ATLSMTP_DOUBLE_BUFFERED
-
-
- if (bRet)
- {
- // End the message with a CRLF.CRLF
- nBufLen = sprintf_s(szBuf, _countof(szBuf), "\r\n.\r\n");
- if (!AtlSmtpSendAndCheck((HANDLE)m_hSocket, szBuf, nBufLen,
- szBuf, &nBufLen, ATLSMTP_MAX_LINE_LENGTH, ATLSMTP_DATA_SUCC, &m_Overlapped))
- {
- bRet = FALSE;
- }
- }
-
- return bRet;
- }
-
- // Send the message
- // msg - the CMimeMessage to send
- // lpszSender - the sender
- inline BOOL SendMessage(CMimeMessage& msg, LPCTSTR lpszRecipients = NULL, LPCTSTR lpszSender = NULL) throw()
- {
- if (!Connected())
- {
- return FALSE;
- }
-
- char szBuf[ATLSMTP_MAX_LINE_LENGTH+1];
-
- //Send MAIL FROM command and get reply
- int nBufLen = sprintf_s(szBuf, ATLSMTP_MAX_LINE_LENGTH+1, "MAIL FROM:<%s>\r\n",
- (lpszSender ? (LPCSTR) CT2CA(lpszSender) : msg.GetSender()));
- if ((nBufLen < 0) ||
- (!AtlSmtpSendAndCheck((HANDLE)m_hSocket, szBuf, nBufLen,
- szBuf, &nBufLen, ATLSMTP_MAX_LINE_LENGTH, ATLSMTP_MAIL_SUCC, &m_Overlapped)))
- {
- return FALSE;
- }
-
- BOOL bRet = TRUE;
- if (!lpszRecipients)
- {
- LPSTR lpszRecipientsA = NULL;
- DWORD dwLen = msg.GetRequiredRecipientsStringLength();
- lpszRecipientsA = static_cast<LPSTR>(calloc(sizeof(char),dwLen));
- if (!lpszRecipientsA || msg.GetRecipientsString(lpszRecipientsA, &dwLen) == FALSE)
- {
- bRet = FALSE;
- }
- if (bRet)
- bRet = DumpRecipients((HANDLE)m_hSocket, lpszRecipientsA, &m_Overlapped, ATLSMTP_FOR_SEND);
- free(lpszRecipientsA);
- }
- else
- {
- bRet = DumpRecipients((HANDLE)m_hSocket, CT2CA(lpszRecipients),
- &m_Overlapped, ATLSMTP_FOR_SEND);
- }
-
- //Begin the data output
- if (bRet)
- {
- nBufLen = sprintf_s(szBuf, _countof(szBuf), "DATA\r\n");
- bRet = AtlSmtpSendAndCheck((HANDLE)m_hSocket, szBuf, nBufLen,
- szBuf, &nBufLen, ATLSMTP_MAX_LINE_LENGTH, ATLSMTP_DATA_INTM, &m_Overlapped);
- }
-
- if (!bRet)
- CancelMessage();
-
- //Attempt to write the data to the socket
- if (bRet)
- {
- bRet = msg.WriteData((HANDLE)m_hSocket, &m_Overlapped, NULL, ATLSMTP_FORMAT_SMTP);
- }
-
- if (bRet)
- {
- //End the message with a <CRLF>.<CRLF>
- nBufLen = sprintf_s(szBuf, _countof(szBuf), "\r\n.\r\n");
- if (!AtlSmtpSendAndCheck((HANDLE)m_hSocket, szBuf, nBufLen,
- szBuf, &nBufLen, ATLSMTP_MAX_LINE_LENGTH, ATLSMTP_DATA_SUCC, &m_Overlapped))
- {
- return FALSE;
- }
- }
-
- return bRet;
- }
-
- // Send a chunk of raw data
- inline BOOL SendRaw(LPCTSTR lpszRawData, DWORD dwLen, LPCTSTR lpszRecipients, LPCTSTR lpszSender) throw()
- {
- ATLASSERT(lpszRawData != NULL);
- ATLASSERT(lpszRecipients != NULL);
- ATLASSERT(lpszSender != NULL);
-
- if (!Connected())
- return FALSE;
-
- char szBuf[ATLSMTP_MAX_LINE_LENGTH+1];
-
- //Send MAIL FROM command and get reply
- int nBufLen = sprintf_s(szBuf, ATLSMTP_MAX_LINE_LENGTH+1,
- "MAIL FROM:<%s>\r\n", (LPCSTR) CT2CA(lpszSender));
- if ((nBufLen < 0) ||
- (!AtlSmtpSendAndCheck((HANDLE)m_hSocket, szBuf, nBufLen,
- szBuf, &nBufLen, ATLSMTP_MAX_LINE_LENGTH, ATLSMTP_MAIL_SUCC, &m_Overlapped)))
- {
- return FALSE;
- }
-
- BOOL bRet = DumpRecipients((HANDLE)m_hSocket, CT2CA(lpszRecipients),
- &m_Overlapped, ATLSMTP_FOR_SEND);
-
- // Begin the data output
- if (bRet)
- {
- nBufLen = sprintf_s(szBuf, _countof(szBuf), "DATA\r\n");
- bRet = AtlSmtpSendAndCheck((HANDLE)m_hSocket, szBuf, nBufLen,
- szBuf, &nBufLen, ATLSMTP_MAX_LINE_LENGTH, ATLSMTP_DATA_INTM, &m_Overlapped);
- }
-
- if (!bRet)
- CancelMessage();
-
- if (bRet)
- {
- bRet = AtlSmtpSendAndWait((HANDLE)m_hSocket, (LPSTR)(lpszRawData), dwLen, &m_Overlapped);
- }
-
- if (bRet)
- {
- //End the message with a <CRLF>.<CRLF>
- nBufLen = sprintf_s(szBuf, _countof(szBuf), "\r\n.\r\n");
- if (!AtlSmtpSendAndCheck((HANDLE)m_hSocket, szBuf, nBufLen,
- szBuf, &nBufLen, ATLSMTP_MAX_LINE_LENGTH, ATLSMTP_DATA_SUCC, &m_Overlapped))
- {
- return FALSE;
- }
- }
-
- return bRet;
- }
-
- inline BOOL SendSimple(LPCTSTR lpszRecipients, LPCTSTR lpszSender, LPCTSTR lpszSubject, LPCTSTR lpszBody, int nTextLen = -1) throw()
- {
- CMimeMessage msg;
- BOOL bRet = msg.SetSubject(lpszSubject);
- if (bRet)
- bRet = msg.AddText(lpszBody, nTextLen);
-
- CFixedStringT<CString, MAX_PATH> strRecip;
- LPCTSTR szTmp = lpszRecipients;
- LPCTSTR szTmp2 = lpszRecipients;
- while (*szTmp && bRet)
- {
- if (AtlSmtpIsRecipientDelimiter((char) *szTmp2))
- {
- _ATLTRY
- {
- strRecip.SetString(szTmp, (int)(szTmp2-szTmp));
- bRet = msg.AddRecipient((LPCTSTR) strRecip);
-
- if (*szTmp2)
- {
- while (*szTmp2 && AtlSmtpIsRecipientDelimiter((char) *szTmp2))
- {
- szTmp2++;
- }
- }
- szTmp = szTmp2;
- }
- _ATLCATCHALL()
- {
- bRet = FALSE;
- }
- }
- else
- {
- szTmp2++;
- }
- }
-
- if (bRet)
- bRet = SendMessage(msg, lpszRecipients, lpszSender);
-
- return bRet;
- }
-
- // Save a MIME message to a file
- // lpszFileName - the file name
- // lpszRecipients - the recipients string (optional)
- // lpszSender - the sender (optional)
- // dwFlags - the flags (optional)
- inline BOOL WriteToFile(LPCTSTR lpszFileName, CMimeMessage& msg, LPCTSTR lpszRecipients = NULL,
- LPCTSTR lpszSender = NULL, DWORD dwFlags = 0) throw()
- {
- //Try to create/open the file
- HANDLE hFile = CreateFile(lpszFileName, GENERIC_WRITE, 0, NULL,
- CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
-
- if (hFile == INVALID_HANDLE_VALUE)
- {
- return FALSE;
- }
-
- // Use CHandle to close the file handle
- // (CAtlFile does not allow for overlapped I/O)
- CHandle hdlFile(hFile);
-
- //Create and initialize the OVERLAPPED struct
- OVERLAPPED writeOverlapped;
- memset((void*)&writeOverlapped, 0, sizeof(OVERLAPPED));
- writeOverlapped.hEvent = CreateEvent(NULL, TRUE, TRUE, NULL);
- if (writeOverlapped.hEvent == NULL)
- {
- return FALSE;
- }
-
- // Use CHandle to close the event handle
- CHandle hdlEvent(writeOverlapped.hEvent);
-
- char szBuf[ATLSMTP_MAX_LINE_LENGTH+1];
- BOOL bRet = TRUE;
-
- int nBufLen = 0;
-
- //if writing to file for purposes of sending, write out the
- //commands as well
- if (lpszSender || (dwFlags & ATLSMTP_DUMP_SENDER))
- {
- nBufLen = sprintf_s(szBuf, ATLSMTP_MAX_LINE_LENGTH+1, "MAIL FROM:<%s>\r\n",
- (lpszSender ? (LPCSTR) CT2CA(lpszSender) : msg.GetSender()));
- if (nBufLen > 0)
- {
- bRet = AtlSmtpSendAndWait(hFile, szBuf, nBufLen, &writeOverlapped);
- }
- else
- {
- bRet = FALSE;
- }
- }
-
- if (bRet && (lpszRecipients || (dwFlags & ATLSMTP_DUMP_RECIPS)))
- {
- if (!lpszRecipients)
- {
- LPSTR lpszRecipientsA = NULL;
- DWORD dwLen = msg.GetRequiredRecipientsStringLength();
- lpszRecipientsA = static_cast<LPSTR>(calloc(sizeof(char),dwLen));
- if (!lpszRecipientsA || msg.GetRecipientsString(lpszRecipientsA, &dwLen) == FALSE)
- {
- bRet = FALSE;
- }
- if (bRet)
- bRet = DumpRecipients(hFile, lpszRecipientsA, &writeOverlapped);
- free(lpszRecipientsA);
- }
- else
- {
- bRet = DumpRecipients(hFile, CT2CA(lpszRecipients), &writeOverlapped);
- }
- }
-
- if (bRet)
- {
- nBufLen = sprintf_s(szBuf, _countof(szBuf), "DATA\r\n");
- bRet = AtlSmtpSendAndWait(hFile, szBuf, nBufLen, &writeOverlapped);
- }
-
- if (bRet)
- {
- bRet = msg.WriteData(hFile, &writeOverlapped, NULL, ATLSMTP_FORMAT_SMTP);
- }
-
- return bRet;
- }
-
-protected:
-
- // disallow copy construction
- CSMTPConnection(const CSMTPConnection&) throw()
- {
- ATLASSERT(FALSE);
- }
-
- // disallow assignment
- const CSMTPConnection& operator=(const CSMTPConnection&) throw()
- {
- ATLASSERT(FALSE);
- return *this;
- }
-
- // Tell the server we are aborting the message
- inline BOOL CancelMessage() throw()
- {
- char szBuf[ATLSMTP_MAX_LINE_LENGTH+1];
- int nBufLen = 0;
- nBufLen = sprintf_s(szBuf, _countof(szBuf), "RSET\r\n");
- if (!AtlSmtpSendAndCheck((HANDLE)m_hSocket, szBuf, nBufLen, szBuf, &nBufLen, ATLSMTP_MAX_LINE_LENGTH,
- ATLSMTP_RSET_SUCC, &m_Overlapped))
- {
- Disconnect();
- return FALSE;
- }
- return TRUE;
- }
-
- // Dump the recipients to hFile
- // lpszRecipients - the recipients string
- // pOverlapped - the OVERALAPPED struct
- // dwFlags - the flags
- inline BOOL DumpRecipients(HANDLE hFile, LPCSTR lpszRecipients, LPOVERLAPPED pOverlapped, DWORD dwFlags = 0)
- {
- ATLENSURE(lpszRecipients != NULL);
- ATLASSERT(pOverlapped != NULL);
-
- char rcptBuf[ATLSMTP_MAX_LINE_LENGTH-12+1];
- char szBuf[ATLSMTP_MAX_LINE_LENGTH+1];
- LPSTR tmpBuf = rcptBuf;
- char ch;
- BOOL bRet = TRUE;
- int nMaxLength = ATLSMTP_MAX_LINE_LENGTH;
- int nRetCode = 0;
- size_t nCnt = 0;
- do
- {
- ch = *lpszRecipients;
- if (ch)
- lpszRecipients++;
- if (AtlSmtpIsRecipientDelimiter(ch))
- {
- *tmpBuf = 0;
- int nBufLen = sprintf_s(szBuf, ATLSMTP_MAX_LINE_LENGTH,
- "RCPT TO:<%s>\r\n", rcptBuf);
- if (nBufLen > 0)
- {
- bRet = AtlSmtpSendAndWait(hFile, szBuf, nBufLen, pOverlapped);
- }
- else
- {
- bRet = FALSE;
- }
-
- if (bRet && (dwFlags & ATLSMTP_FOR_SEND))
- {
- bRet = AtlSmtpReadData(hFile, szBuf, &nMaxLength, pOverlapped);
- nRetCode = atoi(szBuf);
- if (!bRet || (nRetCode != ATLSMTP_RCPT_SUCCESS && nRetCode != ATLSMTP_RCPT_NOT_LOCAL))
- {
- bRet = FALSE;
- break;
- }
- }
- tmpBuf = rcptBuf;
- nCnt = 0;
- nMaxLength = ATLSMTP_MAX_LINE_LENGTH;
- while (isspace(static_cast<unsigned char>(*lpszRecipients)))
- lpszRecipients++;
- continue;
- }
-
- if (nCnt >= sizeof(rcptBuf)-1)
- {
- // recipient string too long
- bRet = FALSE;
- break;
- }
-
- *tmpBuf++ = ch;
- nCnt++;
- } while (ch != '\0');
-
- return bRet;
- }
-
- // Implementation - used from ReadLine
- // fills pBuf with up to dwMaxLen bytes
- BOOL FillBuffer(__in HANDLE hFile, __out_ecount_part(dwMaxLen, *pdwLen) LPSTR pBuf, __in DWORD dwMaxLen, __out LPDWORD pdwLen) throw()
- {
- ATLASSERT(hFile != INVALID_HANDLE_VALUE);
- ATLASSERT(pdwLen != NULL);
-
- DWORD dwRead = 0;
- DWORD dwTotalRead = 0;
- int nRet = 0;
-
- do
- {
- nRet = ReadFile(hFile, pBuf, dwMaxLen-dwTotalRead, &dwRead, NULL);
- if (!nRet && GetLastError() != ERROR_HANDLE_EOF)
- {
- return FALSE;
- }
-
- if (dwRead == 0)
- break;
-
- dwTotalRead+= dwRead;
- } while (dwTotalRead < dwMaxLen);
-
- *pdwLen = dwTotalRead;
-
- return TRUE;
- }
-
- // Implementation
- // Read a line (terminated by LF) from hFile
- BOOL ReadLine(__in HANDLE hFile, __out_ecount_part_z(dwMaxSrcLen, *pdwSrcLen) LPSTR pSrc, __out_ecount_part_z(dwMaxDestLen, *pdwRead) LPSTR pDest, __inout LPDWORD pdwSrcLen, __inout LPDWORD pdwBufPos, __in DWORD dwMaxSrcLen,
- __in DWORD dwMaxDestLen, __out_opt LPDWORD pdwRead=NULL, __out_opt LPBOOL pbFullLine=NULL)
- {
- ATLENSURE(hFile != INVALID_HANDLE_VALUE);
- ATLENSURE(pSrc != NULL);
- ATLENSURE(pDest != NULL);
- ATLENSURE(pdwSrcLen != NULL);
- ATLENSURE(pdwBufPos != NULL);
-
- BOOL bRet = TRUE;
- DWORD dwLen = 0;
- DWORD dwBufPos = 0;
- DWORD dwSrcLen = *pdwSrcLen;
- LPSTR pSrcCurrent = pSrc + *pdwBufPos;
-
- while (bRet && dwLen < dwMaxDestLen)
- {
- if (dwSrcLen == 0)
- {
- if (!FillBuffer(hFile, pSrc, dwMaxSrcLen, pdwSrcLen) || *pdwSrcLen == 0)
- break;
-
- dwBufPos = 0;
- *pdwBufPos = 0;
- dwSrcLen = *pdwSrcLen;
- pSrcCurrent = pSrc;
- }
-
- --dwSrcLen;
- *pDest = *pSrcCurrent++;
- dwLen++;
- dwBufPos++;
- if (*pDest == '\n')
- {
- break;
- }
- pDest++;
- }
-
- *pdwSrcLen = dwSrcLen;
-
- if (pbFullLine)
- {
- if (*pDest != '\n')
- *pbFullLine = FALSE;
- else
- *pbFullLine = TRUE;
- }
-
- if (pdwRead)
- *pdwRead = dwLen;
-
- *pdwBufPos += dwBufPos;
-
- return bRet;
- }
-
-}; // class CSMTPConnection
-
-} // namespace ATL
-#pragma pack(pop)
-
-#endif // __ATLSMTPCONNECTION_H__
diff --git a/include/atl/atlsmtputil.h b/include/atl/atlsmtputil.h
deleted file mode 100644
index 6ce443861..000000000
--- a/include/atl/atlsmtputil.h
+++ /dev/null
@@ -1,220 +0,0 @@
-// This is a part of the Active Template Library.
-// Copyright (C) Microsoft Corporation
-// All rights reserved.
-//
-// This source code is only intended as a supplement to the
-// Active Template Library Reference and related
-// electronic documentation provided with the library.
-// See these sources for detailed information regarding the
-// Active Template Library product.
-
-#ifndef __ATLSMTPUTIL_H__
-#define __ATLSMTPUTIL_H__
-
-#pragma once
-
-#if (defined(_WINSOCKAPI_) && !defined(_WINSOCK2API_))
-#error <atlsmtputil.h> requires <winsock2.h> -- include <winsock2.h> before you include <windows.h> or <winsock.h>
-#endif
-#include <winsock2.h>
-#include <windows.h>
-#include <string.h>
-#include <stdlib.h>
-#include <tchar.h>
-#include <atlstr.h>
-#include <winnls.h>
-#include <atlspriv.h>
-
-//=======================================================================
-//defines for SMTPMail module
-//=======================================================================
-
-//If overlapped I/O is desired, need 2.0 or greater
-#define ATLSMTP_WSA_VERSION ATL_WINSOCK_VER
-
-//The maximum number of characters on a SMTP line
-#define ATLSMTP_MAX_LINE_LENGTH 1000
-
-#define ATLSMTP_MAX_SERVER_NAME_LENGTH 256
-
-//Encoding schemes
-#define ATLSMTP_BASE64_ENCODE 0
-#define ATLSMTP_UUENCODE 1
-#define ATLSMTP_QP_ENCODE 2
-
-//I/O Defines
-#define ATLSMTP_READBUFFER_SIZE 4096
-#define ATLSMTP_GET_LINES 100
-
-
-//Miscellaneous defines
-#define ATLSMTP_SEND_FILE 1
-#define ATLSMTP_FORMAT_SMTP 8
-
-#define ATLSMTP_RETCODE_LEN 3
-
-
-#pragma pack(push,_ATL_PACKING)
-namespace ATL
-{
-
-//=======================================================================
-// Miscellaneous Utility Functions
-//=======================================================================
-//A list of recipients in a string must by separated by one
-//of the following characters
-inline BOOL AtlSmtpIsRecipientDelimiter(char ch) throw()
-{
- return (ch == ',' || ch == ';' || ch == ' ' || ch == '\0');
-}
-
-//Send data to hFile and wait for it to finish sending
-inline BOOL AtlSmtpSendAndWait(HANDLE hFile, LPCSTR lpData, int nDataLength, LPOVERLAPPED pOverlapped) throw()
-{
- ATLASSERT(lpData != NULL);
- ATLENSURE_RETURN_VAL(pOverlapped != NULL, FALSE);
-
- DWORD dwWritten = 0, dwErr = 0;
- int nRet = 0, nBufPos = 0;
-
- //write all the data
- do
- {
- //Write a chunk of data, offsetting the buffer and amount to write by what's already
- //been written
- nRet = WriteFile(hFile, (void*)(lpData+nBufPos), nDataLength-nBufPos, &dwWritten, pOverlapped);
- if (!nRet && (dwErr = GetLastError()) != ERROR_IO_INCOMPLETE && dwErr != ERROR_IO_PENDING)
- return FALSE;
-
- //Get the result of the write operation (wait for it)
- nRet = GetOverlappedResult(hFile, pOverlapped, &dwWritten, TRUE);
- if (!nRet)
- return FALSE;
-
- //Need to update offsets when writing to a file
- pOverlapped->Offset += dwWritten;
- nBufPos += dwWritten;
-
- } while (nBufPos < nDataLength);
- return TRUE;
-}
-
-
-//Read up to nDestLen bytes from hFile, keep reading while there's more data and there's
-//room in the buffer
-inline BOOL AtlSmtpReadData(__in HANDLE hFile, __out_ecount_part_z(*pnDestLen, *pnDestLen) LPSTR lpData, __inout int* pnDestLen, __in LPOVERLAPPED pOverlapped)
-{
- ATLASSERT(lpData != NULL);
- ATLASSERT(pnDestLen != NULL);
- ATLENSURE(pOverlapped != NULL);
-
- DWORD dwRead = 0, dwErr = 0;
- int nBufPos = 0;
- do
- {
- //REad a chunk of data, offsetting the buffer and amount to read by what's already been read
- int nRet = ReadFile(hFile, (void*)(lpData+nBufPos), (*pnDestLen)-nBufPos, &dwRead, pOverlapped);
- if (!nRet && (dwErr = GetLastError()) != ERROR_MORE_DATA && dwErr != ERROR_IO_PENDING && dwErr != ERROR_IO_INCOMPLETE)
- return FALSE;
-
- //Get the result of the read operation (wait for it)
- nRet = GetOverlappedResult(hFile, pOverlapped, &dwRead, TRUE);
- if (!nRet)
- return FALSE;
-
- //Handle offsets when reading from a file
- pOverlapped->Offset += dwRead;
- nBufPos += dwRead;
- } while (nBufPos < *pnDestLen && dwErr == ERROR_MORE_DATA);
- *pnDestLen = nBufPos;
- return TRUE;
-}
-
-
-//Used in sending encoded data
-//lpData is the data to be sent now
-//lpPrev is a pointer to the buffer that the previous call was made on
-//This allows the new buffer (lpData) to be filled while lpPrev is being sent
-//If all the data in lpPrev had not finished sending, we complete the send and wait
-inline BOOL AtlSmtpSendOverlapped(HANDLE hFile, LPCSTR lpData, int nDataLength, LPCSTR lpPrev, DWORD dwPrevLength, LPOVERLAPPED pOverlapped)
-{
- ATLASSERT(lpData != NULL);
- ATLENSURE(pOverlapped != NULL);
-
- DWORD dwWritten = 0, dwErr = 0, dwBufPos = 0;
- int nRet = 0;
-
- //Get the results of the previous call (if any)
- if (lpPrev && (!GetOverlappedResult(hFile, pOverlapped, &dwWritten, FALSE) || dwWritten < dwPrevLength))
- {
- //If any error but IO_INCOMPLETE, return failure
- if ((dwErr = GetLastError()) != ERROR_SUCCESS && dwErr != ERROR_IO_INCOMPLETE && dwErr != ERROR_IO_PENDING)
- {
- return FALSE;
- }
- //Finish writing lpPrev if we need to
- while (dwBufPos < dwPrevLength)
- {
- //Get the result of the previous write (wait for it)
- nRet = GetOverlappedResult(hFile, pOverlapped, &dwWritten, TRUE);
- if (!nRet || (dwBufPos += dwWritten) == dwPrevLength)
- {
- if ((dwErr = GetLastError()) != ERROR_IO_INCOMPLETE && dwErr != ERROR_IO_PENDING)
- break;
- }
-
- //If we are writing to a file, we need to update the offsets
- pOverlapped->Offset += dwWritten;
- if(dwBufPos>dwPrevLength)
- {
- /* shouldn't happen */
- ATLASSERT(false);
- break;
- }
- nRet = WriteFile(hFile, (void*)(lpPrev+dwBufPos), dwPrevLength-dwBufPos, &dwWritten, pOverlapped);
-
- //If any error but IO_PENDING and IO_INCOMPLETE, break
- if (!nRet && (dwErr = GetLastError()) != ERROR_IO_PENDING && dwErr != ERROR_IO_INCOMPLETE)
- break;
- }
- if (dwBufPos < dwPrevLength)
- return FALSE;
- }
-
- //Now that all the previous data has been sent, start sending the current data
- nRet = WriteFile(hFile, (void*)lpData, nDataLength, &dwWritten, pOverlapped);
- GetOverlappedResult(hFile, pOverlapped, &dwWritten, FALSE);
-
- pOverlapped->Offset += dwWritten;
-
- //If any error but IO_PENDING
- if (!nRet && (dwErr = GetLastError()) != ERROR_IO_PENDING && dwErr != ERROR_IO_INCOMPLETE)
- return FALSE;
- return TRUE;
-}
-
-
-//Send a SMTP command and read the response
-//return TRUE if it matches szResponse, FALSE otherwise
-inline BOOL AtlSmtpSendAndCheck(__in HANDLE hFile, __in LPCSTR lpData, __in int nDataLength, __out_ecount_part(nMaxResponseLength, *pnResponseLength) LPSTR lpResponse, __out int* pnResponseLength, __in int nMaxResponseLength,
- __in_z LPCSTR szResponse, __in LPOVERLAPPED pOverlapped) throw()
-{
- ATLASSERT(lpData != NULL);
- ATLASSERT(lpResponse != NULL);
- ATLASSERT(pnResponseLength != NULL);
-
- BOOL bRet = AtlSmtpSendAndWait(hFile, lpData, nDataLength, pOverlapped);
- if (bRet)
- {
- *pnResponseLength = nMaxResponseLength;
- bRet = AtlSmtpReadData(hFile, lpResponse, pnResponseLength, pOverlapped);
- }
- if (!bRet || strncmp((char*)lpResponse, szResponse, ATLSMTP_RETCODE_LEN))
- return FALSE;
- return TRUE;
-}
-
-} // namespace ATL
-#pragma pack(pop)
-
-#endif // __ATLSMTPUTIL_H__
diff --git a/include/atl/atlsoap.h b/include/atl/atlsoap.h
deleted file mode 100644
index b286e7c61..000000000
--- a/include/atl/atlsoap.h
+++ /dev/null
@@ -1,8174 +0,0 @@
-// This is a part of the Active Template Library.
-// Copyright (C) Microsoft Corporation
-// All rights reserved.
-//
-// This source code is only intended as a supplement to the
-// Active Template Library Reference and related
-// electronic documentation provided with the library.
-// See these sources for detailed information regarding the
-// Active Template Library product.
-
-#ifndef __ATLSOAP_H__
-#define __ATLSOAP_H__
-
-#pragma once
-
-#if (defined(_WINSOCKAPI_) && !defined(_WINSOCK2API_))
- #error require winsock2.h -- include <winsock2.h> before you include <windows.h>
-#endif
-
-#if ((_WIN32_WINNT < 0x0400) && (_WIN32_WINDOWS <= 0x0400))
- #error require _WIN32_WINNT >= 0x0400 or _WIN32_WINDOWS > 0x0400
-#endif
-
-#ifndef ATLSOAP_TRACE
- #ifdef _ATLSOAP_TRACE_XML
- #define ATLSOAP_TRACE(__data, __len) AtlSoapTraceXML(__data, __len)
- #else
- #define ATLSOAP_TRACE(__data, __len) __noop
- #endif
-#endif // ATLSOAP_TRACE
-
-// override this macro to ATL_BASE64_FLAG_NOCRLF if you do
-// not want Base64-encoded binary data to contain CRLFs
-#ifndef ATLSOAP_BASE64_FLAGS
- #define ATLSOAP_BASE64_FLAGS ATL_BASE64_FLAG_NONE
-#endif // ATLSOAP_BASE64_FLAGS
-
-[ emitidl(restricted) ];
-#include <winsock2.h>
-#include <atlstr.h>
-#include <atlcoll.h>
-#include <atlbase.h>
-#include <msxml2.h>
-#include <atlenc.h>
-#include <fcntl.h>
-#include <float.h>
-#include <math.h>
-#include <limits>
-#include <atlisapi.h>
-#include <atlstencil.h>
-#include <atlhttp.h>
-#include <atlhttp.inl>
-
-#pragma warning(push)
-#pragma warning(disable: 4625) // copy constructor could not be generated because a base class copy constructor is inaccessible
-#pragma warning(disable: 4626) // assignment operator could not be generated because a base class assignment operator is inaccessible
-#pragma warning(disable: 4061) // enumerate 'enum value' in switch of enum 'enum type' is not explicitly handled by a case label
-
-#ifndef _CPPUNWIND
-#pragma warning(disable: 4702) // unreachable code
-#endif // _CPPUNWIND
-
-#ifndef ATLSOAP_NOWININET
- #include <wininet.h>
- #ifndef ATLSOAPINET_CLIENT
- #define ATLSOAPINET_CLIENT _T("VCSoapClient")
- #endif
-#endif
-
-#ifndef _ATL_NO_DEFAULT_LIBS
-#pragma comment(lib, "msxml2.lib")
- #ifndef ATLSOAP_NOWININET
- #pragma comment(lib, "wininet.lib")
- #endif
-#endif
-
-#define _ATLSOAP_MAKEWIDESTR( str ) L ## str
-#define ATLSOAP_MAKEWIDESTR( str ) _ATLSOAP_MAKEWIDESTR( str )
-
-
-#pragma pack(push,_ATL_PACKING)
-namespace ATL
-{
-
-ATL_NOINLINE inline void AtlSoapTraceXML(LPBYTE pdwData, DWORD dwLen)
-{
- HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
- if (hStdOut != INVALID_HANDLE_VALUE)
- {
- DWORD dwWritten;
- WriteFile(hStdOut,
- "\n-----------------------------------------------------------------\n",
- sizeof("\n-----------------------------------------------------------------\n")-1,
- &dwWritten, NULL);
-
- WriteFile(hStdOut, pdwData, dwLen, &dwWritten, NULL);
-
- WriteFile(hStdOut,
- "\n-----------------------------------------------------------------\n",
- sizeof("\n-----------------------------------------------------------------\n")-1,
- &dwWritten, NULL);
- }
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// IStreamImpl - stub IStream implementation class
-//
-////////////////////////////////////////////////////////////////////////////////
-
-class IStreamImpl : public IStream
-{
-public:
-
- HRESULT __stdcall Read(void * /*pDest*/, ULONG /*nMaxLen*/, ULONG * /*pnRead*/)
- {
- return E_NOTIMPL;
- }
-
- HRESULT __stdcall Write(const void * /*pv*/, ULONG /*cb*/, ULONG * /*pcbWritten*/)
- {
- return E_NOTIMPL;
- }
-
- HRESULT __stdcall Seek(LARGE_INTEGER /*dlibMove*/, DWORD /*dwOrigin*/,
- ULARGE_INTEGER * /*pLibNewPosition*/)
- {
- return E_NOTIMPL;
- }
-
- HRESULT __stdcall SetSize(ULARGE_INTEGER /*libNewSize*/)
- {
- return E_NOTIMPL;
- }
-
- HRESULT __stdcall CopyTo(IStream * /*pStream*/, ULARGE_INTEGER /*cb*/,
- ULARGE_INTEGER * /*pcbRead*/, ULARGE_INTEGER * /*pcbWritten*/)
- {
- return E_NOTIMPL;
- }
-
- HRESULT __stdcall Commit(DWORD /*grfCommitFlags*/)
- {
- return E_NOTIMPL;
- }
-
- HRESULT __stdcall Revert()
- {
- return E_NOTIMPL;
- }
-
- HRESULT __stdcall LockRegion(ULARGE_INTEGER /*libOffset*/, ULARGE_INTEGER /*cb*/, DWORD /*dwLockType*/)
- {
- return E_NOTIMPL;
- }
-
- HRESULT __stdcall UnlockRegion(ULARGE_INTEGER /*libOffset*/, ULARGE_INTEGER /*cb*/, DWORD /*dwLockType*/)
- {
- return E_NOTIMPL;
- }
-
- HRESULT __stdcall Stat(STATSTG * /*pstatstg*/, DWORD /*grfStatFlag*/)
- {
- return E_NOTIMPL;
- }
-
- HRESULT __stdcall Clone(IStream ** /*ppstm*/)
- {
- return E_NOTIMPL;
- }
-}; // class IStreamImpl
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// CStreamOnServerContext
-//
-////////////////////////////////////////////////////////////////////////////////
-
-class CStreamOnServerContext : public IStreamImpl
-{
-public:
-
- HRESULT __stdcall QueryInterface(REFIID riid, void **ppv)
- {
- if (ppv == NULL)
- {
- return E_POINTER;
- }
-
- *ppv = NULL;
-
- if (InlineIsEqualGUID(riid, IID_IUnknown) ||
- InlineIsEqualGUID(riid, IID_IStream) ||
- InlineIsEqualGUID(riid, IID_ISequentialStream))
- {
- *ppv = static_cast<IStream *>(this);
- return S_OK;
- }
-
- return E_NOINTERFACE;
- }
-
- ULONG __stdcall AddRef()
- {
- return 1;
- }
-
- ULONG __stdcall Release()
- {
- return 1;
- }
-
-private:
-
- IHttpServerContext * m_pServerContext;
- DWORD m_dwBytesRead;
-
-public:
-
- CStreamOnServerContext(IHttpServerContext *pServerContext = NULL)
- : m_pServerContext(pServerContext), m_dwBytesRead(0)
- {
- }
-
- void SetServerContext(IHttpServerContext *pServerContext)
- {
- ATLASSUME( m_pServerContext == NULL );
-
- m_pServerContext = pServerContext;
- }
-
- HRESULT __stdcall Read(void *pDest, ULONG nMaxLen, ULONG *pnRead)
- {
- ATLENSURE( pDest != NULL );
- ATLASSUME( m_pServerContext != NULL );
-
- DWORD dwToRead = __min(m_pServerContext->GetTotalBytes()-m_dwBytesRead, nMaxLen);
- if (ReadClientData(m_pServerContext, (LPSTR) pDest, &dwToRead, m_dwBytesRead) != FALSE)
- {
- m_dwBytesRead+= dwToRead;
-
- if (pnRead != NULL)
- {
- *pnRead = dwToRead;
- }
-
- return S_OK;
- }
-
- ATLTRACE( _T("ATLSOAP: CStreamOnServerContext::Read -- ReadClientData failed.\r\n") );
-
- return E_FAIL;
- }
-}; // class CStreamOnServerContext
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// CReadStreamOnSocket
-//
-////////////////////////////////////////////////////////////////////////////////
-
-template <typename TSocketClass>
-class CReadStreamOnSocket : public IStreamImpl
-{
-public:
-
- HRESULT __stdcall QueryInterface(REFIID riid, void **ppv)
- {
- if (ppv == NULL)
- {
- return E_POINTER;
- }
-
- *ppv = NULL;
-
- if (InlineIsEqualGUID(riid, IID_IUnknown) ||
- InlineIsEqualGUID(riid, IID_IStream) ||
- InlineIsEqualGUID(riid, IID_ISequentialStream))
- {
- *ppv = static_cast<IStream *>(this);
- return S_OK;
- }
-
- return E_NOINTERFACE;
- }
-
- ULONG __stdcall AddRef()
- {
- return 1;
- }
-
- ULONG __stdcall Release()
- {
- return 1;
- }
-
-private:
-
- CAtlHttpClientT<TSocketClass> * m_pSocket;
- LPCSTR m_szBuffer;
- LPCSTR m_szCurr;
- long m_nBodyLen;
-
-public:
-
- CReadStreamOnSocket()
- : m_pSocket(NULL), m_szBuffer(NULL), m_szCurr(NULL), m_nBodyLen(0)
- {
- }
-
- BOOL Init(CAtlHttpClientT<TSocketClass> *pSocket)
- {
- ATLENSURE( pSocket != NULL );
-
- m_pSocket = pSocket;
- m_szBuffer = (LPCSTR) pSocket->GetBody();
-
- ATLSOAP_TRACE( (LPBYTE) pSocket->GetBody(), pSocket->GetBodyLength() );
-
- if (m_szBuffer != NULL)
- {
- m_szCurr = m_szBuffer;
- m_nBodyLen = pSocket->GetBodyLength();
- if (m_nBodyLen != 0)
- {
- return TRUE;
- }
- }
-
- ATLTRACE( _T("ATLSOAP: CReadStreamOnSocket::Init failed.\r\n") );
-
- return FALSE;
- }
-
- HRESULT __stdcall Read(void *pDest, ULONG nMaxLen, ULONG *pnRead)
- {
- ATLASSERT( pDest != NULL );
- ATLASSUME( m_pSocket != NULL );
- ATLASSUME( m_szBuffer != NULL );
-
- if (pnRead != NULL)
- {
- *pnRead = 0;
- }
-
- long nRead = (int) (m_szCurr-m_szBuffer);
- if (nRead < m_nBodyLen)
- {
- long nLength = __min((int)(m_nBodyLen-nRead), (LONG) nMaxLen);
- Checked::memcpy_s(pDest, nMaxLen, m_szCurr, nLength);
- m_szCurr+= nLength;
-
- if (pnRead != NULL)
- {
- *pnRead = (ULONG) nLength;
- }
- }
-
- return S_OK;
- }
-}; // class CReadStreamOnSocket
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// CWriteStreamOnCString
-//
-////////////////////////////////////////////////////////////////////////////////
-
-class CWriteStreamOnCString : public IWriteStream
-{
-
-public:
- CStringA m_str;
-
- virtual ~CWriteStreamOnCString()
- {
- }
-
- HRESULT WriteStream(LPCSTR szOut, int nLen, LPDWORD pdwWritten)
- {
- ATLENSURE_RETURN( szOut != NULL );
-
- if (nLen < 0)
- {
- nLen = (int) strlen(szOut);
- }
-
- _ATLTRY
- {
- m_str.Append(szOut, nLen);
- }
- _ATLCATCHALL()
- {
- return E_OUTOFMEMORY;
- }
-
- if (pdwWritten != NULL)
- {
- *pdwWritten = (DWORD) nLen;
- }
-
- return S_OK;
- }
-
- HRESULT FlushStream()
- {
- return S_OK;
- }
-
- void Cleanup()
- {
- m_str.Empty();
- }
-}; // class CWriteStreamOnCString
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// Namespaces
-//
-////////////////////////////////////////////////////////////////////////////////
-
-#define SOAPENV_NAMESPACEA "http://schemas.xmlsoap.org/soap/envelope/"
-#define SOAPENV_NAMESPACEW ATLSOAP_MAKEWIDESTR( SOAPENV_NAMESPACEA )
-
-#define SOAPENC_NAMESPACEA "http://schemas.xmlsoap.org/soap/encoding/"
-#define SOAPENC_NAMESPACEW ATLSOAP_MAKEWIDESTR( SOAPENC_NAMESPACEA )
-
-#define XSI_NAMESPACEA "http://www.w3.org/2001/XMLSchema-instance"
-#define XSI_NAMESPACEW ATLSOAP_MAKEWIDESTR( XSI_NAMESPACEA )
-
-#define XSD_NAMESPACEA "http://www.w3.org/2001/XMLSchema"
-#define XSD_NAMESPACEW ATLSOAP_MAKEWIDESTR( XSD_NAMESPACEA )
-
-#ifndef ATLSOAP_GENERIC_NAMESPACE
-#define ATLSOAP_GENERIC_NAMESPACE L"http://www.tempuri.org"
-#endif
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// Helpers
-//
-////////////////////////////////////////////////////////////////////////////////
-
-inline HRESULT GetAttribute(
- __in ISAXAttributes *pAttributes,
- __in_ecount(cchName) const wchar_t *wszAttrName, __in int cchName,
- __out_ecount_part(*pcchValue, *pcchValue) const wchar_t **pwszValue, __inout int *pcchValue,
- __in_ecount_opt(cchNamespace) wchar_t *wszNamespace = NULL, __in int cchNamespace = 0)
-{
- if (!pAttributes || !wszAttrName || !pwszValue || !pcchValue)
- {
- return E_INVALIDARG;
- }
-
- *pwszValue = NULL;
- *pcchValue = 0;
- if (!wszNamespace)
- {
- return (pAttributes->getValueFromQName(wszAttrName, cchName, pwszValue, pcchValue) == S_OK ? S_OK : E_FAIL);
- }
- return (pAttributes->getValueFromName(wszNamespace, cchNamespace,
- wszAttrName, cchName, pwszValue, pcchValue) == S_OK ? S_OK : E_FAIL);
-}
-
-inline HRESULT GetAttribute(
- __in ISAXAttributes *pAttributes,
- __in_ecount(cchName) const wchar_t *wszAttrName, __in int cchName,
- __inout CStringW &strValue,
- __in_ecount_opt(cchNamespace) wchar_t *wszNamespace = NULL, __in int cchNamespace = 0)
-{
- const wchar_t *wszValue = NULL;
- int cchValue = 0;
-
- if (!pAttributes || !wszAttrName)
- {
- return E_INVALIDARG;
- }
-
- HRESULT hr;
- if (!wszNamespace)
- {
- hr = (pAttributes->getValueFromQName(wszAttrName, cchName, &wszValue, &cchValue) == S_OK ? S_OK : E_FAIL);
- }
- else
- {
- hr = (pAttributes->getValueFromName(wszNamespace, cchNamespace,
- wszAttrName, cchName, &wszValue, &cchValue) == S_OK ? S_OK : E_FAIL);
- }
-
- if (hr == S_OK)
- {
- _ATLTRY
- {
- strValue.SetString(wszValue, cchValue);
- }
- _ATLCATCHALL()
- {
- ATLTRACE( _T("ATLSOAP: GetAttribute -- out of memory.\r\n") );
-
- hr = E_OUTOFMEMORY;
- }
- }
-
- return hr;
-}
-
-inline const wchar_t *SkipWhitespace(const wchar_t *wsz)
-{
- while (*wsz && iswspace(*wsz))
- ++wsz;
- return wsz;
-}
-
-} // namespace ATL
-#pragma pack(pop)
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// BLOB data type - use this struct when you want to send BLOB data
-// the attribute provider and proxy generator will only properly special
-// case blob data when using this struct.
-//
-////////////////////////////////////////////////////////////////////////////////
-
-[ export ]
-typedef struct _tagATLSOAP_BLOB
-{
- unsigned long size;
- unsigned char *data;
-} ATLSOAP_BLOB;
-
-#ifndef _ATL_SOAP_NO_PARAMETER_VALIDATIONS
-#define _ATL_VALIDATE_PARAMETER_END(p)\
- do \
- { \
- if(*(p) !='\0') \
- return E_FAIL; \
- } while(0)
-#else
-#define _ATL_VALIDATE_PARAMETER_END(p)
-#endif
-
-// All non-integral types have specializations which
-// will be called. The following function will be called
-// only for integral types
-
-#pragma push_macro("max")
-#pragma push_macro("min")
-#undef max
-#undef min
-template <typename T>
-inline HRESULT AtlGetSAXValue(T * pVal , const wchar_t * wsz , int cch )
-{
- __int64 nVal = *pVal;
- if (FAILED(AtlGetSAXValue(&nVal, wsz, cch)))
- return E_FAIL;
-
-#ifndef _ATL_SOAP_NO_PARAMETER_VALIDATIONS
- if(nVal < std::numeric_limits<T>::min() || nVal > std::numeric_limits<T>::max())
- return E_FAIL;
-#endif
-
- *pVal = T(nVal);
- return S_OK;
-
-
-}
-#pragma pop_macro("max")
-#pragma pop_macro("min")
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// AtlGetXMLValue (for IXMLDOMDocument) - get the real type from the XML data
-//
-///////////////////////////////////////////////////////////////////////////////
-
-//
-// generic IXMLDOMNode template function
-// delegates to AtlGetSAXValue
-//
-template <typename T>
-inline HRESULT AtlGetXMLValue(IXMLDOMNode *pParam, T *pVal)
-{
- CComBSTR bstrVal;
- HRESULT hr = AtlGetXMLValue(pParam, &bstrVal);
- if (SUCCEEDED(hr))
- {
- hr = AtlGetSAXValue(pVal, bstrVal, bstrVal.Length());
- }
-
- return hr;
-}
-
-// specialization for BSTR
-template <>
-inline HRESULT AtlGetXMLValue<BSTR>(IXMLDOMNode *pParam, BSTR *pbstrVal)
-{
- if (pParam == NULL)
- {
- return E_INVALIDARG;
- }
- if (pbstrVal == NULL)
- {
- return E_POINTER;
- }
-
- CComPtr<IXMLDOMNode> spChild;
- if (pParam->get_firstChild(&spChild) == S_OK)
- {
- CComPtr<IXMLDOMNode> spXmlChild;
- if (spChild->get_firstChild(&spXmlChild) == S_OK)
- {
- return (pParam->get_xml(pbstrVal) == S_OK ? S_OK : E_FAIL);
- }
- }
-
- return (pParam->get_text(pbstrVal) == S_OK) ? S_OK : E_FAIL;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// AtlGetSAXValue - (for SAX or generic) get the real type from the XML data
-//
-////////////////////////////////////////////////////////////////////////////////
-
-template <>
-inline HRESULT AtlGetSAXValue<bool>(bool *pVal, __in_z const wchar_t *wsz, int cch)
-{
- ATLENSURE( wsz != NULL );
-
- if (!pVal)
- {
- return E_POINTER;
- }
-
- *pVal = false;
-
- HRESULT hr = E_FAIL;
- switch (wsz[0])
- {
- case L'1':
- {
- if (cch==1)
- {
- *pVal = true;
- hr = S_OK;
- }
- break;
- }
- case L'0':
- {
- if (cch==1)
- {
- *pVal = false;
- hr = S_OK;
- }
- break;
- }
- case L't':
- {
- if (cch==sizeof("true")-1 && !wcsncmp(wsz, L"true", cch))
- {
- *pVal = true;
- hr = S_OK;
- }
- break;
- }
- case L'f':
- {
- if (cch==sizeof("false")-1 && !wcsncmp(wsz, L"false", cch))
- {
- *pVal = false;
- hr = S_OK;
- }
- break;
- }
- }
-
- return hr;
-}
-
-template <>
-inline HRESULT AtlGetSAXValue<__int64>(__int64 *pVal, __in_z const wchar_t *wsz, int cch)
-{
- ATLENSURE_RETURN( wsz != NULL );
-
- if (!pVal)
- {
- return E_POINTER;
- }
-
- _ATLTRY
- {
- CFixedStringT<CStringW, 1024> wstr(wsz, cch);
- const wchar_t *pStart = ATL::SkipWhitespace(static_cast<LPCWSTR>(wstr));
- const wchar_t *pEnd;
-
- __int64 i = 0;
- errno_t errnoValue = AtlStrToNum(&i, pStart, const_cast<wchar_t **>(&pEnd), 10);
- if (errnoValue == ERANGE)
- {
- return E_FAIL;//overflow or underflow case
- }
- pEnd = ATL::SkipWhitespace(pEnd);
- _ATL_VALIDATE_PARAMETER_END(pEnd);
- *pVal = i;
- }
- _ATLCATCHALL()
- {
- return E_OUTOFMEMORY;
- }
-
- return S_OK;
-}
-
-template <>
-inline HRESULT AtlGetSAXValue<unsigned __int64>(unsigned __int64 *pVal, __in_z const wchar_t *wsz, int cch)
-{
- ATLENSURE_RETURN( wsz != NULL );
-
- if (!pVal)
- {
- return E_POINTER;
- }
-
- _ATLTRY
- {
- CFixedStringT<CStringW, 1024> wstr(wsz, cch);
- const wchar_t *pStart = ATL::SkipWhitespace(static_cast<LPCWSTR>(wstr));
- const wchar_t *pEnd;
-
- unsigned __int64 i = 0;
- errno_t errnoValue = AtlStrToNum(&i, pStart, const_cast<wchar_t **>(&pEnd), 10);
- if (errnoValue == ERANGE)
- {
- return E_FAIL;//overflow or underflow case
- }
- pEnd = ATL::SkipWhitespace(pEnd);
- _ATL_VALIDATE_PARAMETER_END(pEnd);
- *pVal = i;
- }
- _ATLCATCHALL()
- {
- return E_OUTOFMEMORY;
- }
-
- return S_OK;
-}
-template <>
-inline HRESULT AtlGetSAXValue<double>(double *pVal, __in_z const wchar_t *wsz, int cch)
-{
- ATLENSURE_RETURN( wsz != NULL );
-
- if (!pVal)
- {
- return E_POINTER;
- }
-
- if ((cch == 3) && (wsz[0]==L'I') && (!wcsncmp(wsz, L"INF", cch)))
- {
- *(((int *) pVal)+0) = 0x0000000;
- *(((int *) pVal)+1) = 0x7FF00000;
- }
- else if ((cch == 3) && (wsz[0]==L'N') && (!wcsncmp(wsz, L"NaN", cch)))
- {
- *(((int *) pVal)+0) = 0x0000000;
- *(((int *) pVal)+1) = 0xFFF80000;
- }
- else if ((cch == 4) && (wsz[1]==L'I') && (!wcsncmp(wsz, L"-INF", cch)))
- {
- *(((int *) pVal)+0) = 0x0000000;
- *(((int *) pVal)+1) = 0xFFF00000;
- }
- else
- {
- errno_t errnoValue = 0;
-
- _ATLTRY
- {
- CFixedStringT<CStringW, 1024> wstr(wsz, cch);
- const wchar_t *pStart = ATL::SkipWhitespace(static_cast<LPCWSTR>(wstr));
- const wchar_t *pEnd;
- double d = 0.0;
- errnoValue = AtlStrToNum(&d, pStart, const_cast<wchar_t **>(&pEnd));
- pEnd = ATL::SkipWhitespace(pEnd);
- _ATL_VALIDATE_PARAMETER_END(pEnd);
- *pVal = d;
- }
- _ATLCATCHALL()
- {
- return E_OUTOFMEMORY;
- }
-
- if ((*pVal == -HUGE_VAL) || (*pVal == HUGE_VAL) || (errnoValue == ERANGE))
- {
- return E_FAIL;
- }
- }
-
- return S_OK;
-}
-
-template <>
-inline HRESULT AtlGetSAXValue<float>(float *pVal, __in_z const wchar_t *wsz, int cch)
-{
- ATLASSERT( wsz != NULL );
-
- if (!pVal)
- {
- return E_POINTER;
- }
-
- double d = *pVal;
- if (SUCCEEDED(AtlGetSAXValue(&d, wsz, cch)))
- {
-#ifdef _ATL_SOAP_PARAMETER_VALIDATIONS
- if(d > FLT_MAX || d < -FLT_MAX)
- return E_FAIL;
-#endif
- *pVal = (float) d;
- return S_OK;
- }
-
- return E_FAIL;
-}
-
-template <>
-inline HRESULT AtlGetSAXValue<BSTR>(BSTR *pVal, __in_z const wchar_t *wsz, int cch)
-{
- ATLASSERT( wsz != NULL );
-
- if (pVal == NULL)
- {
- return E_POINTER;
- }
-
- *pVal = SysAllocStringLen(wsz, cch);
-
- return ((*pVal != NULL) ? S_OK : E_OUTOFMEMORY);
-}
-
-inline HRESULT AtlGetSAXBlobValue(
- ATLSOAP_BLOB *pVal,
- const wchar_t *wsz,
- int cch,
- IAtlMemMgr *pMemMgr,
- bool bHex = false)
-{
- ATLENSURE_RETURN( wsz != NULL );
- ATLENSURE_RETURN( pMemMgr != NULL );
-
- if (pVal == NULL)
- {
- return E_POINTER;
- }
-
- if (pVal->data != NULL)
- {
- return E_INVALIDARG;
- }
-
- pVal->data = NULL;
- pVal->size = 0;
-
- int nLength = AtlUnicodeToUTF8(wsz, cch, NULL, 0);
-
- if (nLength != 0)
- {
- char * pSrc = (char *) pMemMgr->Allocate(nLength);
- if (pSrc != NULL)
- {
- nLength = AtlUnicodeToUTF8(wsz, cch, pSrc, nLength);
- if (nLength != 0)
- {
- pVal->data = (unsigned char *) pMemMgr->Allocate(nLength);
- if (pVal->data != NULL)
- {
- BOOL bRet;
- int nDataLength = nLength;
- if (!bHex)
- {
- bRet = Base64Decode(pSrc, nLength, pVal->data, &nDataLength);
- }
- else
- {
- bRet = AtlHexDecode(pSrc, nLength, pVal->data, &nDataLength);
- }
- if (bRet)
- {
- pVal->size = nDataLength;
- }
- }
- }
-
- pMemMgr->Free(pSrc);
- }
- }
-
- if (pVal->size == 0)
- {
- if (pVal->data != NULL)
- {
- pMemMgr->Free(pVal->data);
- pVal->data = NULL;
- }
- }
-
- return S_OK;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// AtlGenXMLValue template and specializations
-//
-////////////////////////////////////////////////////////////////////////////////
-
-template <typename T>
-inline HRESULT AtlGenXMLValue(__in IWriteStream *pStream, __in T *pVal)
-{
- if ((pStream == NULL) || (pVal == NULL))
- {
- return E_INVALIDARG;
- }
-
- //
- // delegate to CWriteStreamHelper
- //
- CWriteStreamHelper s(pStream);
-
- return (s.Write(*pVal) == TRUE ? S_OK : E_FAIL);
-}
-
-#ifdef _NATIVE_WCHAR_T_DEFINED
-template <>
-inline HRESULT AtlGenXMLValue<wchar_t>(__in IWriteStream *pStream, __in wchar_t *pVal)
-{
- return AtlGenXMLValue(pStream, (unsigned short *)pVal);
-}
-#endif
-
-template <>
-inline HRESULT AtlGenXMLValue<wchar_t *>(__in IWriteStream *pStream, __deref_inout_z wchar_t **pVal)
-{
- if ((pStream == NULL) || (*pVal == NULL))
- {
- return E_INVALIDARG;
- }
-
- wchar_t *wszWrite = *pVal;
- int nSrcLen = (int)wcslen(*pVal);
- int nCnt = EscapeXML(*pVal, nSrcLen, NULL, 0);
- if (nCnt > nSrcLen)
- {
- nCnt++;
- wszWrite = (wchar_t *)calloc((nCnt),sizeof(wchar_t));
- if (wszWrite == NULL)
- {
- return E_OUTOFMEMORY;
- }
-
- nCnt = EscapeXML(*pVal, nSrcLen, wszWrite, nCnt);
- if (nCnt == 0)
- {
- free(wszWrite);
- return E_FAIL;
- }
- wszWrite[nCnt] = L'\0';
- nSrcLen = nCnt;
- }
-
- nCnt = AtlUnicodeToUTF8(wszWrite, nSrcLen, NULL, 0);
- HRESULT hr = E_FAIL;
- if ((nCnt == 0) || (nCnt == nSrcLen))
- {
- CWriteStreamHelper s(pStream);
-
- hr = (s.Write(wszWrite) == TRUE ? S_OK : E_FAIL);
- }
- else
- {
- nCnt++;
- CHeapPtr<char> szWrite;
- szWrite.AllocateBytes((size_t)(nCnt));
- if (szWrite != NULL)
- {
- nCnt = AtlUnicodeToUTF8(wszWrite, nSrcLen, szWrite, nCnt);
- if (nCnt != 0)
- {
- hr = pStream->WriteStream(szWrite, nCnt, NULL);
- }
- }
- else
- {
- ATLTRACE( _T("ATLSOAP: AtlGenXMLValue<wchar_t *> -- out of memory.\r\n") );
-
- hr = E_OUTOFMEMORY;
- }
- }
-
- if (wszWrite != *pVal)
- {
- free(wszWrite);
- }
-
- return hr;
-}
-
-template <>
-inline HRESULT AtlGenXMLValue<double>(IWriteStream *pStream, double *pVal)
-{
- if ((pStream == NULL) || (pVal == NULL))
- {
- return E_INVALIDARG;
- }
-
- HRESULT hr;
- switch (_fpclass(*pVal))
- {
- case _FPCLASS_SNAN:
- case _FPCLASS_QNAN:
- {
- hr = pStream->WriteStream("NaN", 3, NULL);
- break;
- }
- case _FPCLASS_NINF:
- {
- hr = pStream->WriteStream("-INF", 4, NULL);
- break;
- }
- case _FPCLASS_PINF:
- {
- hr = pStream->WriteStream("INF", 3, NULL);
- break;
- }
- case _FPCLASS_NZ:
- {
- hr = pStream->WriteStream("-0", 2, NULL);
- break;
- }
- default:
- {
- /***
- * 2 = sign + decimal point
- * ndec = decimal digits
- * 5 = exponent letter (e or E), exponent sign, three digits exponent
- * 1 = extra space for rounding
- * 1 = string terminator '\0'
- ***/
- const int ndec = 512;
- CHAR szBuf[ndec+9];
- szBuf[0] = '\0';
- Checked::gcvt_s(szBuf, _countof(szBuf), *pVal, ndec);
- size_t nLen = strlen(szBuf);
- if (nLen && szBuf[nLen-1] == '.')
- {
- szBuf[--nLen] = '\0';
- }
-
- hr = pStream->WriteStream(szBuf, (int)nLen, NULL);
- break;
- }
- }
-
- return hr;
-}
-
-template <>
-inline HRESULT AtlGenXMLValue<float>(IWriteStream *pStream, float *pVal)
-{
- if ((pStream == NULL) || (pVal == NULL))
- {
- return E_INVALIDARG;
- }
-
- double d = *pVal;
-
- return AtlGenXMLValue(pStream, &d);
-}
-
-template <>
-inline HRESULT AtlGenXMLValue<bool>(IWriteStream *pStream, bool *pVal)
-{
- if ((pStream == NULL) || (pVal == NULL))
- {
- return E_INVALIDARG;
- }
-
- if (*pVal == true)
- {
- return pStream->WriteStream("true", sizeof("true")-1, NULL);
- }
-
- return pStream->WriteStream("false", sizeof("false")-1, NULL);
-}
-
-inline HRESULT AtlGenXMLBlobValue(
- IWriteStream *pStream,
- ATLSOAP_BLOB *pVal,
- IAtlMemMgr *pMemMgr,
- bool bHex = false)
-{
- if ((pStream == NULL) || (pVal == NULL) || (pMemMgr == NULL))
- {
- return E_INVALIDARG;
- }
-
- HRESULT hr = E_FAIL;
- int nLength;
- if (!bHex)
- {
- nLength = Base64EncodeGetRequiredLength(pVal->size, ATLSOAP_BASE64_FLAGS);
- }
- else
- {
- nLength = AtlHexEncodeGetRequiredLength(pVal->size);
- }
-
- char *pEnc = (char *) pMemMgr->Allocate(nLength);
- if (pEnc != NULL)
- {
- BOOL bRet;
- if (!bHex)
- {
- bRet = Base64Encode(pVal->data, pVal->size, pEnc, &nLength, ATLSOAP_BASE64_FLAGS);
- }
- else
- {
- bRet = AtlHexEncode(pVal->data, pVal->size, pEnc, &nLength);
- }
- if (bRet)
- {
- hr = pStream->WriteStream(pEnc, nLength, NULL);
- }
-
- pMemMgr->Free(pEnc);
- }
-
- return hr;
-}
-
-template <typename T>
-inline HRESULT AtlCleanupValue(T * /*pVal*/)
-{
- return S_OK;
-}
-
-inline HRESULT AtlCleanupBlobValue(ATLSOAP_BLOB *pVal, IAtlMemMgr *pMemMgr)
-{
- if ((pVal == NULL) || (pMemMgr == NULL))
- {
- return E_INVALIDARG;
- }
-
- if (pVal->data != NULL)
- {
- pMemMgr->Free(pVal->data);
- pVal->data = NULL;
- pVal->size = 0;
- }
-
- return S_OK;
-}
-
-template <>
-inline HRESULT AtlCleanupValue<ATLSOAP_BLOB>(ATLSOAP_BLOB *pVal)
-{
- ATLTRACE( _T("Warning: AtlCleanupValue<ATLSOAP_BLOB> was called -- assuming CRT allocator.\r\n") );
-
- if (pVal == NULL)
- {
- return E_INVALIDARG;
- }
-
- if (pVal->data != NULL)
- {
- free(pVal->data);
- pVal->data = NULL;
- pVal->size = 0;
- }
-
- return S_OK;
-}
-
-template <>
-inline HRESULT AtlCleanupValue<BSTR>(BSTR *pVal)
-{
- if (pVal == NULL)
- {
- // should never happen
- ATLASSERT( FALSE );
- return E_INVALIDARG;
- }
-
- if ((*pVal) != NULL)
- {
- // null strings are okay
- SysFreeString(*pVal);
- *pVal = NULL;
- }
-
- return S_OK;
-}
-
-template <typename T>
-inline HRESULT AtlCleanupValueEx(T *pVal, IAtlMemMgr *pMemMgr)
-{
- pMemMgr;
-
- return AtlCleanupValue(pVal);
-}
-
-template <>
-inline HRESULT AtlCleanupValueEx<ATLSOAP_BLOB>(ATLSOAP_BLOB *pVal, IAtlMemMgr *pMemMgr)
-{
- return AtlCleanupBlobValue(pVal, pMemMgr);
-}
-
-// single dimensional arrays
-template <typename T>
-inline HRESULT AtlCleanupArray(T *pArray, int nCnt)
-{
- if (pArray == NULL)
- {
- return E_INVALIDARG;
- }
-
- for (int i=0; i<nCnt; i++)
- {
- AtlCleanupValue(&pArray[i]);
- }
-
- return S_OK;
-}
-
-
-template <typename T>
-inline HRESULT AtlCleanupArrayEx(T *pArray, int nCnt, IAtlMemMgr *pMemMgr)
-{
- if (pArray == NULL)
- {
- return E_INVALIDARG;
- }
-
- for (int i=0; i<nCnt; i++)
- {
- AtlCleanupValueEx(&pArray[i], pMemMgr);
- }
-
- return S_OK;
-}
-
-
-// multi-dimensional arrays
-template <typename T>
-inline HRESULT AtlCleanupArrayMD(T *pArray, const int *pDims)
-{
- if ((pArray == NULL) || (pDims == NULL))
- {
- return E_INVALIDARG;
- }
-
- // calculate size
- int nCnt = 1;
- for (int i=1; i<=pDims[0]; i++)
- {
- nCnt*= pDims[i];
- }
-
- return AtlCleanupArray(pArray, nCnt);
-}
-
-template <typename T>
-inline HRESULT AtlCleanupArrayMDEx(T *pArray, const int *pDims, IAtlMemMgr *pMemMgr)
-{
- if ((pArray == NULL) || (pDims == NULL))
- {
- return E_INVALIDARG;
- }
-
- // calculate size
- int nCnt = 1;
- for (int i=1; i<=pDims[0]; i++)
- {
- nCnt*= pDims[i];
- }
-
- return AtlCleanupArrayEx(pArray, nCnt, pMemMgr);
-}
-
-
-#pragma pack(push,_ATL_PACKING)
-namespace ATL
-{
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// CSAXSoapErrorHandler
-//
-////////////////////////////////////////////////////////////////////////////////
-
-class CSAXSoapErrorHandler : public ISAXErrorHandler
-{
-private:
-
- CFixedStringT<CStringW, 256> m_strParseError;
-
-public:
- virtual ~CSAXSoapErrorHandler()
- {
- }
-
- HRESULT __stdcall QueryInterface(REFIID riid, void **ppv)
- {
- if (!ppv)
- {
- return E_POINTER;
- }
-
- if (InlineIsEqualGUID(riid, __uuidof(ISAXErrorHandler)) ||
- InlineIsEqualGUID(riid, __uuidof(IUnknown)))
- {
- *ppv = static_cast<ISAXErrorHandler*>(this);
- return S_OK;
- }
- return E_NOINTERFACE;
- }
-
- ULONG __stdcall AddRef()
- {
- return 1;
- }
-
- ULONG __stdcall Release()
- {
- return 1;
- }
-
- const CStringW& GetParseError()
- {
- return m_strParseError;
- }
-
- HRESULT __stdcall error(
- ISAXLocator *pLocator,
- const wchar_t *wszErrorMessage,
- HRESULT hrErrorCode)
- {
- (pLocator);
- (wszErrorMessage);
- (hrErrorCode);
-
- ATLTRACE( _T("ATLSOAP: parse error: %ws\r\n"), wszErrorMessage );
-
- _ATLTRY
- {
- m_strParseError = wszErrorMessage;
- }
- _ATLCATCHALL()
- {
- return E_FAIL;
- }
-
- return hrErrorCode;
- }
-
- HRESULT __stdcall fatalError(
- ISAXLocator *pLocator,
- const wchar_t *wszErrorMessage,
- HRESULT hrErrorCode)
- {
- (pLocator);
- (wszErrorMessage);
- (hrErrorCode);
-
- ATLTRACE( _T("ATLSOAP: fatal parse error: %ws\r\n"), wszErrorMessage );
-
- _ATLTRY
- {
- m_strParseError = wszErrorMessage;
- }
- _ATLCATCHALL()
- {
- return E_FAIL;
- }
-
- return hrErrorCode;
- }
-
- HRESULT __stdcall ignorableWarning(
- ISAXLocator *pLocator,
- const wchar_t *wszErrorMessage,
- HRESULT hrErrorCode)
- {
- (pLocator);
- (wszErrorMessage);
- (hrErrorCode);
-
- ATLTRACE( _T("ATLSOAP: ignorable warning: %ws\r\n"), wszErrorMessage );
-
- return hrErrorCode;
- }
-};
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// ISAXContentHandlerImpl
-//
-////////////////////////////////////////////////////////////////////////////////
-
-class ISAXContentHandlerImpl :
- public ISAXContentHandler
-{
-public:
-
- //
- // ISAXContentHandler interface
- //
-
- HRESULT __stdcall putDocumentLocator(ISAXLocator * /*pLocator*/)
- {
- return S_OK;
- }
-
- HRESULT __stdcall startDocument()
- {
- return S_OK;
- }
-
- HRESULT __stdcall endDocument()
- {
- return S_OK;
- }
-
- HRESULT __stdcall startPrefixMapping(
- const wchar_t * /*wszPrefix*/,
- int /*cchPrefix*/,
- const wchar_t * /*wszUri*/,
- int /*cchUri*/)
- {
- return S_OK;
- }
-
- HRESULT __stdcall endPrefixMapping(
- const wchar_t * /*wszPrefix*/,
- int /*cchPrefix*/)
- {
- return S_OK;
- }
-
- HRESULT __stdcall startElement(
- const wchar_t * /*wszNamespaceUri*/,
- int /*cchNamespaceUri*/,
- const wchar_t * /*wszLocalName*/,
- int /*cchLocalName*/,
- const wchar_t * /*wszQName*/,
- int /*cchQName*/,
- ISAXAttributes * /*pAttributes*/)
- {
- return S_OK;
- }
-
- HRESULT __stdcall endElement(
- const wchar_t * /*wszNamespaceUri*/,
- int /*cchNamespaceUri*/,
- const wchar_t * /*wszLocalName*/,
- int /*cchLocalName*/,
- const wchar_t * /*wszQName*/,
- int /*cchQName*/)
- {
- return S_OK;
- }
-
- HRESULT __stdcall characters(
- const wchar_t * /*wszChars*/,
- int /*cchChars*/)
- {
- return S_OK;
- }
-
- HRESULT __stdcall ignorableWhitespace(
- const wchar_t * /*wszChars*/,
- int /*cchChars*/)
- {
- return S_OK;
- }
-
- HRESULT __stdcall processingInstruction(
- const wchar_t * /*wszTarget*/,
- int /*cchTarget*/,
- const wchar_t * /*wszData*/,
- int /*cchData*/)
- {
- return S_OK;
- }
-
- HRESULT __stdcall skippedEntity(
- const wchar_t * /*wszName*/,
- int /*cchName*/)
- {
- return S_OK;
- }
-}; // class ISAXContentHandlerImpl
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// SAX skip element handler utility class
-// (skip an element and all its child elements)
-//
-////////////////////////////////////////////////////////////////////////////////
-
-class CSkipHandler : public ISAXContentHandlerImpl
-{
-public:
- virtual ~CSkipHandler()
- {
- }
-
- HRESULT __stdcall QueryInterface(REFIID riid, void **ppv)
- {
- if (ppv == NULL)
- {
- return E_POINTER;
- }
-
- *ppv = NULL;
-
- if (InlineIsEqualGUID(riid, IID_IUnknown) ||
- InlineIsEqualGUID(riid, IID_ISAXContentHandler))
- {
- *ppv = static_cast<ISAXContentHandler *>(this);
- return S_OK;
- }
-
- return E_NOINTERFACE;
- }
-
- ULONG __stdcall AddRef()
- {
- return 1;
- }
-
- ULONG __stdcall Release()
- {
- return 1;
- }
-
-private:
-
- DWORD m_dwReset;
- CComPtr<ISAXXMLReader> m_spReader;
- CComPtr<ISAXContentHandler> m_spParent;
-
- DWORD DisableReset(DWORD dwCnt = 1)
- {
- m_dwReset += dwCnt;
-
- return m_dwReset;
- }
-
- DWORD EnableReset()
- {
- if (m_dwReset > 0)
- {
- --m_dwReset;
- }
-
- return m_dwReset;
- }
-
-public:
-
- CSkipHandler(ISAXContentHandler *pParent = NULL, ISAXXMLReader *pReader = NULL)
- : m_spParent(pParent), m_spReader(pReader), m_dwReset(1)
- {
- }
-
- void SetParent(ISAXContentHandler *pParent)
- {
- m_spParent = pParent;
- }
- void DetachParent()
- {
- m_spParent.Detach();
- }
-
- void SetReader(ISAXXMLReader *pReader)
- {
- m_spReader = pReader;
- }
-
- HRESULT __stdcall startElement(
- const wchar_t * /*wszNamespaceUri*/,
- int /*cchNamespaceUri*/,
- const wchar_t * /*wszLocalName*/,
- int /*cchLocalName*/,
- const wchar_t * /*wszQName*/,
- int /*cchQName*/,
- ISAXAttributes * /*pAttributes*/)
- {
- DisableReset();
- return S_OK;
- }
-
- HRESULT __stdcall endElement(
- const wchar_t * /*wszNamespaceUri*/,
- int /*cchNamespaceUri*/,
- const wchar_t * /*wszLocalName*/,
- int /*cchLocalName*/,
- const wchar_t * /*wszQName*/,
- int /*cchQName*/)
- {
- if (EnableReset() == 0)
- {
- m_spReader->putContentHandler(m_spParent);
- }
-
- return S_OK;
- }
-}; // class CSkipHandler
-
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// SAX string builder class
-//
-////////////////////////////////////////////////////////////////////////////////
-
-class CSAXStringBuilder : public ISAXContentHandlerImpl
-{
-public:
-
- HRESULT __stdcall QueryInterface(REFIID riid, void **ppv)
- {
- if (ppv == NULL)
- {
- return E_POINTER;
- }
-
- *ppv = NULL;
-
- if (InlineIsEqualGUID(riid, IID_IUnknown) ||
- InlineIsEqualGUID(riid, IID_ISAXContentHandler))
- {
- *ppv = static_cast<ISAXContentHandler *>(this);
- return S_OK;
- }
-
- return E_NOINTERFACE;
- }
-
- ULONG __stdcall AddRef()
- {
- return 1;
- }
-
- ULONG __stdcall Release()
- {
- return 1;
- }
-
-private:
-
- ISAXContentHandler * m_pParent;
- ISAXXMLReader * m_pReader;
- DWORD m_dwReset;
- CFixedStringT<CStringW, 64> m_str;
-
- DWORD DisableReset(DWORD dwReset = 1)
- {
- m_dwReset+= dwReset;
-
- return m_dwReset;
- }
-
- DWORD EnableReset()
- {
- if (m_dwReset > 0)
- {
- --m_dwReset;
- }
-
- return m_dwReset;
- }
-
-public:
-
- CSAXStringBuilder(ISAXXMLReader *pReader = NULL, ISAXContentHandler *pParent = NULL)
- :m_pReader(pReader), m_pParent(pParent), m_dwReset(0)
- {
- }
-
- virtual ~CSAXStringBuilder()
- {
- }
-
- void SetReader(ISAXXMLReader *pReader)
- {
- m_pReader = pReader;
- }
-
- void SetParent(ISAXContentHandler *pParent)
- {
- m_pParent = pParent;
- }
-
- const CStringW& GetString()
- {
- return m_str;
- }
-
- void Clear()
- {
- m_str.Empty();
- m_dwReset = 0;
- }
-
- HRESULT __stdcall startElement(
- const wchar_t * /*wszNamespaceUri*/,
- int /*cchNamespaceUri*/,
- const wchar_t * /*wszLocalName*/,
- int /*cchLocalName*/,
- const wchar_t *wszQName,
- int cchQName,
- ISAXAttributes *pAttributes)
- {
- if (m_dwReset == 0)
- {
- // if there is unescaped, nested XML, must disable
- // an additional time for the first element
- DisableReset();
- }
- DisableReset();
-
- int nAttrs = 0;
- HRESULT hr = pAttributes->getLength(&nAttrs);
-
- _ATLTRY
- {
- if (SUCCEEDED(hr))
- {
- m_str.Append(L"<", 1);
- m_str.Append(wszQName, cchQName);
-
- const wchar_t *wszAttrNamespaceUri = NULL;
- const wchar_t *wszAttrLocalName = NULL;
- const wchar_t *wszAttrQName = NULL;
- const wchar_t *wszAttrValue = NULL;
- int cchAttrUri = 0;
- int cchAttrLocalName = 0;
- int cchAttrQName = 0;
- int cchAttrValue = 0;
-
- for (int i=0; i<nAttrs; i++)
- {
- hr = pAttributes->getName(i, &wszAttrNamespaceUri, &cchAttrUri,
- &wszAttrLocalName, &cchAttrLocalName, &wszAttrQName, &cchAttrQName);
-
- if (FAILED(hr))
- {
- ATLTRACE( _T("ATLSOAP: CSAXStringBuilder::startElement -- MSXML error.\r\n") );
-
- break;
- }
-
- m_str.Append(L" ", 1);
- m_str.Append(wszAttrQName, cchAttrQName);
-
- hr = pAttributes->getValue(i, &wszAttrValue, &cchAttrValue);
-
- if (FAILED(hr))
- {
- ATLTRACE( _T("ATLSOAP: CSAXStringBuilder::startElement -- MSXML error.\r\n") );
-
- break;
- }
-
- m_str.Append(L"=\"", sizeof("=\"")-1);
- if (cchAttrValue != 0)
- {
- m_str.Append(wszAttrValue, cchAttrValue);
- }
- m_str.Append(L"\"", 1);
- }
-
- if (SUCCEEDED(hr))
- {
- m_str.Append(L">", 1);
- }
- }
- }
- _ATLCATCHALL()
- {
- ATLTRACE( _T("ATLSOAP: CSAXStringBuilder::startElement -- out of memory.\r\n") );
-
- hr = E_OUTOFMEMORY;
- }
-
- return hr;
- }
-
- HRESULT __stdcall endElement(
- const wchar_t * wszNamespaceUri,
- int cchNamespaceUri,
- const wchar_t * wszLocalName,
- int cchLocalName,
- const wchar_t *wszQName,
- int cchQName)
- {
- HRESULT hr = S_OK;
- _ATLTRY
- {
- if (EnableReset() == 0)
- {
- hr = m_pParent->characters((LPCWSTR) m_str, m_str.GetLength());
- if (SUCCEEDED(hr))
- {
- hr = m_pParent->endElement(wszNamespaceUri, cchNamespaceUri,
- wszLocalName, cchLocalName, wszQName, cchQName);
- }
-
- m_pReader->putContentHandler(m_pParent);
- }
-
- if (m_dwReset > 0)
- {
- m_str.Append(L"</", 2);
- m_str.Append(wszQName, cchQName);
- m_str.Append(L">", 1);
- }
- }
- _ATLCATCHALL()
- {
- ATLTRACE( _T("ATLSOAP: CSAXStringBuilder::endElement -- out of memory.\r\n") );
-
- hr = E_OUTOFMEMORY;
- }
-
- return hr;
- }
-
- HRESULT __stdcall characters(
- const wchar_t *wszChars,
- int cchChars)
- {
- _ATLTRY
- {
- m_str.Append(wszChars, cchChars);
- }
- _ATLCATCHALL()
- {
- ATLTRACE( _T("ATLSOAP: CSAXStringBuilder::characters -- out of memory.\r\n") );
-
- return E_OUTOFMEMORY;
- }
-
- return S_OK;
- }
-
- HRESULT __stdcall ignorableWhitespace(
- const wchar_t *wszChars,
- int cchChars)
- {
- _ATLTRY
- {
- m_str.Append(wszChars, cchChars);
- }
- _ATLCATCHALL()
- {
- ATLTRACE( _T("ATLSOAP: CSAXStringBuilder::ignorableWhitespace -- out of memory.\r\n") );
-
- return E_OUTOFMEMORY;
- }
-
- return S_OK;
- }
-}; // class CSAXStringBuilder
-
-} // namespace ATL
-#pragma pack(pop)
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// SOAP data structure definitions
-//
-////////////////////////////////////////////////////////////////////////////////
-
-//
-// ***************************** WARNING *****************************
-// THESE STRUCTURES ARE INTERNAL ONLY, FOR USE WITH THE ATL SERVER SOAP
-// ATTRIBUTES. USERS SHOULD NOT USE THESE TYPES DIRECTLY. ABSOLUTELY NO
-// GUARANTEES ARE MADE ABOUT BACKWARD COMPATIBILITY FOR DIRECT USE OF
-// THESE TYPES.
-//
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// BEGIN PRIVATE DEFINITIONS
-//
-////////////////////////////////////////////////////////////////////////////////
-
-inline HRESULT AtlSoapGetArraySize(ISAXAttributes *pAttributes, size_t *pnSize,
- const wchar_t **pwszTypeStart = NULL, const wchar_t **pwszTypeEnd = NULL)
-{
- if (pnSize == NULL)
- {
- return E_POINTER;
- }
-
- if (pAttributes == NULL)
- {
- return E_INVALIDARG;
- }
-
- *pnSize = 0;
-
- HRESULT hr = S_OK;
-
- _ATLTRY
- {
- const wchar_t *wszTmp;
- int cch;
-
- hr = GetAttribute(pAttributes, L"arrayType", sizeof("arrayType")-1,
- &wszTmp, &cch, SOAPENC_NAMESPACEW, sizeof(SOAPENC_NAMESPACEA)-1);
-
- if ((SUCCEEDED(hr)) && (wszTmp != NULL))
- {
- hr = E_FAIL;
-
- CFixedStringT<CStringW, 1024> wstrArrayType(wszTmp, cch);
- const wchar_t *wsz = static_cast<LPCWSTR>(wstrArrayType);
-
- const wchar_t *wszTypeStart = NULL;
- const wchar_t *wszTypeEnd = NULL;
-
- // skip spaces
- while (iswspace(*wsz) != 0)
- {
- wsz++;
- }
-
- // no need to walk the string if the caller is not interested
- if ((pwszTypeStart != NULL) && (pwszTypeEnd != NULL))
- {
- wszTypeStart = wsz;
- wszTypeEnd = wcschr(wszTypeStart, L':');
- if (wszTypeEnd != NULL)
- {
- wszTypeStart = wszTypeEnd+1;
- }
- }
-
- // SOAP Section 5 encodings are of the form:
- // <soap_enc namespace>:arrayType="<type_qname>[dim1(,dim_i)*]
- // for example: SOAP-ENC:arrayType="xsd:string[2,4]"
-
- wsz = wcschr(wsz, L'[');
- if (wsz != NULL)
- {
- wszTypeEnd = wsz-1;
- if (wsz[1] == ']')
- {
- return S_FALSE;
- }
-
- *pnSize = 1;
-
- // get the size of each dimension
- while (wsz != NULL)
- {
- wsz++;
- int nDim = _wtoi(wsz);
- if (nDim < 0)
- {
- hr = E_FAIL;
- break;
- }
- *pnSize *= (size_t) nDim;
- if (!nDim)
- {
- break;
- }
-
- wsz = wcschr(wsz, L',');
- }
-
- if ((pwszTypeStart != NULL) && (pwszTypeEnd != NULL))
- {
- *pwszTypeStart = wszTypeStart;
- *pwszTypeEnd = wszTypeEnd;
- }
-
- hr = S_OK;
- }
- }
- else
- {
- // not a section-5 encoding
- hr = S_FALSE;
- }
- }
- _ATLCATCHALL()
- {
- hr = E_OUTOFMEMORY;
- }
-
- return hr;
-}
-
-inline size_t AtlSoapGetArrayDims(const int *pDims)
-{
- if (pDims == NULL)
- {
- return 0;
- }
-
- size_t nRet = 1;
- for (int i=1; i<=pDims[0]; i++)
- {
- nRet *= pDims[i];
- }
-
- return nRet;
-}
-
-enum SOAPFLAGS
-{
- SOAPFLAG_NONE = 0x00000000,
- SOAPFLAG_IN = 0x00000001,
- SOAPFLAG_OUT = 0x00000002,
- SOAPFLAG_RETVAL = 0x00000004,
- SOAPFLAG_DYNARR = 0x00000008,
- SOAPFLAG_FIXEDARR = 0x00000010,
- SOAPFLAG_MUSTUNDERSTAND = 0x00000020,
- SOAPFLAG_UNKSIZE = 0x00000040,
- SOAPFLAG_READYSTATE = 0x00000080,
- SOAPFLAG_FIELD = 0x00000100,
- SOAPFLAG_NOMARSHAL = 0x00000200,
- SOAPFLAG_NULLABLE = 0x00000400,
- SOAPFLAG_DOCUMENT = 0x00000800,
- SOAPFLAG_RPC = 0x00001000,
- SOAPFLAG_LITERAL = 0x00002000,
- SOAPFLAG_ENCODED = 0x00004000,
- SOAPFLAG_PID = 0x00008000,
- SOAPFLAG_PAD = 0x00010000,
- SOAPFLAG_CHAIN = 0x00020000,
- SOAPFLAG_SIZEIS = 0x00040000,
- SOAPFLAG_DYNARRWRAPPER = 0x00080000
-};
-
-enum SOAPMAPTYPE
-{
- SOAPMAP_ERR = 0,
- SOAPMAP_ENUM,
- SOAPMAP_FUNC,
- SOAPMAP_STRUCT,
- SOAPMAP_UNION,
- SOAPMAP_HEADER,
- SOAPMAP_PARAM
-};
-
-struct _soapmap;
-
-struct _soapmapentry
-{
- ULONG nHash;
- const char * szField;
- const WCHAR * wszField;
- int cchField;
- int nVal;
- DWORD dwFlags;
-
- size_t nOffset;
- const int * pDims;
-
- const _soapmap * pChain;
-
- int nSizeIs;
-
- ULONG nNamespaceHash;
- const char *szNamespace;
- const wchar_t *wszNamespace;
- int cchNamespace;
-};
-
-struct _soapmap
-{
- ULONG nHash;
- const char * szName;
- const wchar_t * wszName;
- int cchName;
- int cchWName;
- SOAPMAPTYPE mapType;
- const _soapmapentry * pEntries;
- size_t nElementSize;
- size_t nElements;
- int nRetvalIndex;
-
- DWORD dwCallFlags;
-
- ULONG nNamespaceHash;
- const char *szNamespace;
- const wchar_t *wszNamespace;
- int cchNamespace;
-};
-
-enum SOAPTYPES
-{
- SOAPTYPE_ERR = -2,
- SOAPTYPE_UNK = -1,
- SOAPTYPE_STRING = 0,
- SOAPTYPE_BOOLEAN,
- SOAPTYPE_FLOAT,
- SOAPTYPE_DOUBLE,
- SOAPTYPE_DECIMAL,
- SOAPTYPE_DURATION,
- SOAPTYPE_HEXBINARY,
- SOAPTYPE_BASE64BINARY,
- SOAPTYPE_ANYURI,
- SOAPTYPE_ID,
- SOAPTYPE_IDREF,
- SOAPTYPE_ENTITY,
- SOAPTYPE_NOTATION,
- SOAPTYPE_QNAME,
- SOAPTYPE_NORMALIZEDSTRING,
- SOAPTYPE_TOKEN,
- SOAPTYPE_LANGUAGE,
- SOAPTYPE_IDREFS,
- SOAPTYPE_ENTITIES,
- SOAPTYPE_NMTOKEN,
- SOAPTYPE_NMTOKENS,
- SOAPTYPE_NAME,
- SOAPTYPE_NCNAME,
- SOAPTYPE_INTEGER,
- SOAPTYPE_NONPOSITIVEINTEGER,
- SOAPTYPE_NEGATIVEINTEGER,
- SOAPTYPE_LONG,
- SOAPTYPE_INT,
- SOAPTYPE_SHORT,
- SOAPTYPE_BYTE,
- SOAPTYPE_NONNEGATIVEINTEGER,
- SOAPTYPE_UNSIGNEDLONG,
- SOAPTYPE_UNSIGNEDINT,
- SOAPTYPE_UNSIGNEDSHORT,
- SOAPTYPE_UNSIGNEDBYTE,
- SOAPTYPE_POSITIVEINTEGER,
- SOAPTYPE_DATETIME,
- SOAPTYPE_TIME,
- SOAPTYPE_DATE,
- SOAPTYPE_GMONTH,
- SOAPTYPE_GYEARMONTH,
- SOAPTYPE_GYEAR,
- SOAPTYPE_GMONTHDAY,
- SOAPTYPE_GDAY,
-
- SOAPTYPE_USERBASE = 0x00001000
-};
-
-inline ULONG AtlSoapHashStr(const char * sz)
-{
- ULONG nHash = 0;
- while (*sz != 0)
- {
- nHash = (nHash<<5)+nHash+(*sz);
- sz++;
- }
-
- return nHash;
-}
-
-inline ULONG AtlSoapHashStr(const wchar_t * sz)
-{
- ULONG nHash = 0;
- while (*sz != 0)
- {
- nHash = (nHash<<5)+nHash+(*sz);
- sz++;
- }
-
- return nHash;
-}
-
-inline ULONG AtlSoapHashStr(const char * sz, int cch)
-{
- ULONG nHash = 0;
- for (int i=0; i<cch; i++)
- {
- nHash = (nHash<<5)+nHash+(*sz);
- sz++;
- }
-
- return nHash;
-}
-
-inline ULONG AtlSoapHashStr(const wchar_t * sz, int cch)
-{
- ULONG nHash = 0;
- for (int i=0; i<cch; i++)
- {
- nHash = (nHash<<5)+nHash+(*sz);
- sz++;
- }
-
- return nHash;
-}
-
-inline size_t AtlSoapGetElementSize(SOAPTYPES type)
-{
- size_t nRet;
- switch (type)
- {
- case SOAPTYPE_BOOLEAN:
- nRet = sizeof(bool);
- break;
- case SOAPTYPE_FLOAT:
- nRet = sizeof(float);
- break;
- case SOAPTYPE_DOUBLE:
- case SOAPTYPE_DECIMAL:
- nRet = sizeof(double);
- break;
- case SOAPTYPE_HEXBINARY:
- case SOAPTYPE_BASE64BINARY:
- nRet = sizeof(ATLSOAP_BLOB);
- break;
- case SOAPTYPE_INTEGER:
- case SOAPTYPE_NONPOSITIVEINTEGER:
- case SOAPTYPE_NEGATIVEINTEGER:
- case SOAPTYPE_LONG:
- nRet = sizeof(__int64);
- break;
- case SOAPTYPE_INT:
- nRet = sizeof(int);
- break;
- case SOAPTYPE_SHORT:
- nRet = sizeof(short);
- break;
- case SOAPTYPE_BYTE:
- nRet = sizeof(char);
- break;
- case SOAPTYPE_POSITIVEINTEGER:
- case SOAPTYPE_NONNEGATIVEINTEGER:
- case SOAPTYPE_UNSIGNEDLONG:
- nRet = sizeof(unsigned __int64);
- break;
- case SOAPTYPE_UNSIGNEDINT:
- nRet = sizeof(unsigned int);
- break;
- case SOAPTYPE_UNSIGNEDSHORT:
- nRet = sizeof(unsigned short);
- break;
- case SOAPTYPE_UNSIGNEDBYTE:
- nRet = sizeof(unsigned char);
- break;
- default:
- if ((type != SOAPTYPE_ERR) && (type != SOAPTYPE_UNK) && (type != SOAPTYPE_USERBASE))
- {
- // treat as string
- nRet = sizeof(BSTR);
- }
- else
- {
- ATLTRACE( _T("ATLSOAP: AtlSoapGetElementSize -- internal error.\r\n") );
- // should never get here
- ATLASSERT( FALSE );
- nRet = 0;
- }
- break;
- }
-
- return nRet;
-}
-
-inline HRESULT AtlSoapGetElementValue(const wchar_t *wsz, int cch,
- void *pVal, SOAPTYPES type, IAtlMemMgr *pMemMgr)
-{
- HRESULT hr = E_FAIL;
-
- switch (type)
- {
- case SOAPTYPE_BOOLEAN:
- hr = AtlGetSAXValue((bool *)pVal, wsz, cch);
- break;
- case SOAPTYPE_FLOAT:
- hr = AtlGetSAXValue((float *)pVal, wsz, cch);
- break;
- case SOAPTYPE_DOUBLE:
- case SOAPTYPE_DECIMAL:
- hr = AtlGetSAXValue((double *)pVal, wsz, cch);
- break;
- case SOAPTYPE_HEXBINARY:
- hr = AtlGetSAXBlobValue((ATLSOAP_BLOB *)pVal, wsz, cch, pMemMgr, true);
- break;
- case SOAPTYPE_BASE64BINARY:
- hr = AtlGetSAXBlobValue((ATLSOAP_BLOB *)pVal, wsz, cch, pMemMgr, false);
- break;
-
- case SOAPTYPE_INTEGER:
- case SOAPTYPE_NONPOSITIVEINTEGER:
- case SOAPTYPE_NEGATIVEINTEGER:
- case SOAPTYPE_LONG:
- hr = AtlGetSAXValue((__int64 *)pVal, wsz, cch);
- break;
- case SOAPTYPE_INT:
- hr = AtlGetSAXValue((int *)pVal, wsz, cch);
- break;
- case SOAPTYPE_SHORT:
- hr = AtlGetSAXValue((short *)pVal, wsz, cch);
- break;
- case SOAPTYPE_BYTE:
- hr = AtlGetSAXValue((char *)pVal, wsz, cch);
- break;
- case SOAPTYPE_POSITIVEINTEGER:
- case SOAPTYPE_NONNEGATIVEINTEGER:
- case SOAPTYPE_UNSIGNEDLONG:
- hr = AtlGetSAXValue((unsigned __int64 *)pVal, wsz, cch);
- break;
- case SOAPTYPE_UNSIGNEDINT:
- hr = AtlGetSAXValue((unsigned int *)pVal, wsz, cch);
- break;
- case SOAPTYPE_UNSIGNEDSHORT:
- hr = AtlGetSAXValue((unsigned short *)pVal, wsz, cch);
- break;
- case SOAPTYPE_UNSIGNEDBYTE:
- hr = AtlGetSAXValue((unsigned char *)pVal, wsz, cch);
- break;
- default:
- if ((type != SOAPTYPE_ERR) && (type != SOAPTYPE_UNK) && (type != SOAPTYPE_USERBASE))
- {
- hr = AtlGetSAXValue((BSTR *)pVal, wsz, cch);
- }
-#ifdef _DEBUG
- else
- {
- ATLTRACE( _T("ATLSOAP: AtlSoapGetElementValue -- internal error.\r\n") );
-
- // should never get here
- ATLASSERT( FALSE );
- }
-#endif
- break;
- }
-
- return hr;
-}
-
-inline HRESULT AtlSoapGenElementValue(void *pVal, IWriteStream *pStream, SOAPTYPES type, IAtlMemMgr *pMemMgr)
-{
- HRESULT hr = E_FAIL;
-
- switch (type)
- {
- case SOAPTYPE_BOOLEAN:
- hr = AtlGenXMLValue(pStream, (bool *)pVal);
- break;
- case SOAPTYPE_FLOAT:
- hr = AtlGenXMLValue(pStream, (float *)pVal);
- break;
- case SOAPTYPE_DOUBLE:
- case SOAPTYPE_DECIMAL:
- hr = AtlGenXMLValue(pStream, (double *)pVal);
- break;
- case SOAPTYPE_HEXBINARY:
- hr = AtlGenXMLBlobValue(pStream, (ATLSOAP_BLOB *)pVal, pMemMgr, true);
- break;
- case SOAPTYPE_BASE64BINARY:
- hr = AtlGenXMLBlobValue(pStream, (ATLSOAP_BLOB *)pVal, pMemMgr, false);
- break;
-
- case SOAPTYPE_INTEGER:
- case SOAPTYPE_NONPOSITIVEINTEGER:
- case SOAPTYPE_NEGATIVEINTEGER:
- case SOAPTYPE_LONG:
- hr = AtlGenXMLValue(pStream, (__int64 *)pVal);
- break;
- case SOAPTYPE_INT:
- hr = AtlGenXMLValue(pStream, (int *)pVal);
- break;
- case SOAPTYPE_SHORT:
- hr = AtlGenXMLValue(pStream, (short *)pVal);
- break;
- case SOAPTYPE_BYTE:
- hr = AtlGenXMLValue(pStream, (char *)pVal);
- break;
- case SOAPTYPE_POSITIVEINTEGER:
- case SOAPTYPE_NONNEGATIVEINTEGER:
- case SOAPTYPE_UNSIGNEDLONG:
- hr = AtlGenXMLValue(pStream, (unsigned __int64 *)pVal);
- break;
- case SOAPTYPE_UNSIGNEDINT:
- hr = AtlGenXMLValue(pStream, (unsigned int *)pVal);
- break;
- case SOAPTYPE_UNSIGNEDSHORT:
- hr = AtlGenXMLValue(pStream, (unsigned short *)pVal);
- break;
- case SOAPTYPE_UNSIGNEDBYTE:
- hr = AtlGenXMLValue(pStream, (unsigned char *)pVal);
- break;
- default:
- if ((type != SOAPTYPE_ERR) && (type != SOAPTYPE_UNK) && (type != SOAPTYPE_USERBASE))
- {
- hr = AtlGenXMLValue(pStream, (BSTR *)pVal);
- }
-#ifdef _DEBUG
- else
- {
- ATLTRACE( _T("ATLSOAP: AtlSoapGenElementValue -- internal error.\r\n" ) );
-
- // should never get here
- ATLASSERT( FALSE );
- }
-#endif
- break;
- }
- return hr;
-}
-
-inline HRESULT AtlSoapCleanupElement(void *pVal, SOAPTYPES type, IAtlMemMgr *pMemMgr)
-{
- HRESULT hr = S_OK;
-
- switch (type)
- {
- case SOAPTYPE_BOOLEAN:
- case SOAPTYPE_FLOAT:
- case SOAPTYPE_DOUBLE:
- case SOAPTYPE_DECIMAL:
- case SOAPTYPE_INT:
- case SOAPTYPE_INTEGER:
- case SOAPTYPE_NONPOSITIVEINTEGER:
- case SOAPTYPE_NEGATIVEINTEGER:
- case SOAPTYPE_LONG:
- case SOAPTYPE_SHORT:
- case SOAPTYPE_BYTE:
- case SOAPTYPE_POSITIVEINTEGER:
- case SOAPTYPE_NONNEGATIVEINTEGER:
- case SOAPTYPE_UNSIGNEDLONG:
- case SOAPTYPE_UNSIGNEDINT:
- case SOAPTYPE_UNSIGNEDSHORT:
- case SOAPTYPE_UNSIGNEDBYTE:
- break;
-
- case SOAPTYPE_HEXBINARY:
- case SOAPTYPE_BASE64BINARY:
- hr = AtlCleanupBlobValue((ATLSOAP_BLOB *)pVal, pMemMgr);
- break;
-
- default:
- if ((type != SOAPTYPE_ERR) && (type != SOAPTYPE_UNK) && (type != SOAPTYPE_USERBASE))
- {
- // treat as string
- hr = AtlCleanupValue((BSTR *)pVal);
- }
-#ifdef _DEBUG
- else
- {
- ATLTRACE( _T("ATLSOAP: AtlSoapCleanupElement -- internal error.\r\n" ) );
-
- // should never get here
- ATLASSERT( FALSE );
- }
-#endif
- break;
- }
-
- return hr;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// END PRIVATE DEFINITIONS
-//
-////////////////////////////////////////////////////////////////////////////////
-
-#define SOAP_ENVELOPEA "Envelope"
-#define SOAP_ENVELOPEW ATLSOAP_MAKEWIDESTR( SOAP_ENVELOPEA )
-
-#define SOAP_HEADERA "Header"
-#define SOAP_HEADERW ATLSOAP_MAKEWIDESTR( SOAP_HEADERA )
-
-#define SOAP_BODYA "Body"
-#define SOAP_BODYW ATLSOAP_MAKEWIDESTR( SOAP_BODYA )
-
-
-#pragma pack(push,_ATL_PACKING)
-namespace ATL
-{
-
-//
-// SOAP fault helpers
-//
-
-enum SOAP_ERROR_CODE
-{
- SOAP_E_UNK=0,
- SOAP_E_VERSION_MISMATCH=100,
- SOAP_E_MUST_UNDERSTAND=200,
- SOAP_E_CLIENT=300,
- SOAP_E_SERVER=400
-};
-
-// forward declaration of CSoapFault
-class CSoapFault;
-
-class CSoapFaultParser : public ISAXContentHandlerImpl
-{
-private:
-
- CSoapFault *m_pFault;
-
- DWORD m_dwState;
-
- const static DWORD STATE_ERROR = 0;
- const static DWORD STATE_ENVELOPE = 1;
- const static DWORD STATE_BODY = 2;
- const static DWORD STATE_START = 4;
- const static DWORD STATE_FAULTCODE = 8;
- const static DWORD STATE_FAULTSTRING = 16;
- const static DWORD STATE_FAULTACTOR = 32;
- const static DWORD STATE_DETAIL = 64;
- const static DWORD STATE_RESET = 128;
- const static DWORD STATE_SKIP = 256;
-
-
- CComPtr<ISAXXMLReader> m_spReader;
- CSAXStringBuilder m_stringBuilder;
- CSkipHandler m_skipHandler;
-
- const wchar_t *m_wszSoapPrefix;
- int m_cchSoapPrefix;
-
-public:
- virtual ~CSoapFaultParser()
- {
- m_skipHandler.DetachParent();
- }
-
- // IUnknown interface
- HRESULT __stdcall QueryInterface(REFIID riid, void **ppv)
- {
- if (ppv == NULL)
- {
- return E_POINTER;
- }
-
- *ppv = NULL;
-
- if (InlineIsEqualGUID(riid, IID_IUnknown) ||
- InlineIsEqualGUID(riid, IID_ISAXContentHandler))
- {
- *ppv = static_cast<ISAXContentHandler *>(this);
- return S_OK;
- }
-
- return E_NOINTERFACE;
- }
-
- ULONG __stdcall AddRef()
- {
- return 1;
- }
-
- ULONG __stdcall Release()
- {
- return 1;
- }
-
- // constructor
-
- CSoapFaultParser(CSoapFault *pFault, ISAXXMLReader *pReader)
- :m_pFault(pFault), m_dwState(STATE_ERROR), m_spReader(pReader)
- {
- ATLASSERT( pFault != NULL );
- ATLASSERT( pReader != NULL );
- }
-
- // ISAXContentHandler interface
- HRESULT __stdcall startElement(
- const wchar_t * wszNamespaceUri,
- int cchNamespaceUri,
- const wchar_t * wszLocalName,
- int cchLocalName,
- const wchar_t * /*wszQName*/,
- int /*cchQName*/,
- ISAXAttributes * /*pAttributes*/)
- {
- struct _faultmap
- {
- const wchar_t *wszTag;
- int cchTag;
- DWORD dwState;
- };
-
- const static _faultmap s_faultParseMap[] =
- {
- { L"Envelope", sizeof("Envelope")-1, CSoapFaultParser::STATE_ENVELOPE },
- { L"Body", sizeof("Body")-1, CSoapFaultParser::STATE_BODY },
- { L"Header", sizeof("Header")-1, CSoapFaultParser::STATE_BODY },
- { L"Fault", sizeof("Fault")-1, CSoapFaultParser::STATE_START },
- { L"faultcode", sizeof("faultcode")-1, CSoapFaultParser::STATE_FAULTCODE },
- { L"faultstring", sizeof("faultstring")-1, CSoapFaultParser::STATE_FAULTSTRING },
- { L"faultactor", sizeof("faultactor")-1, CSoapFaultParser::STATE_FAULTACTOR },
- { L"detail", sizeof("detail")-1, CSoapFaultParser::STATE_DETAIL }
- };
-
- if (m_spReader.p == NULL)
- {
- ATLTRACE( _T("ATLSOAP: CSoapFaultParser::startElement -- ISAXXMLReader is NULL.\r\n" ) );
-
- return E_INVALIDARG;
- }
-
- m_dwState &= ~STATE_RESET;
- for (int i=0; i<(sizeof(s_faultParseMap)/sizeof(s_faultParseMap[0])); i++)
- {
- if ((cchLocalName == s_faultParseMap[i].cchTag) &&
- (!wcsncmp(wszLocalName, s_faultParseMap[i].wszTag, cchLocalName)))
- {
- DWORD dwState = s_faultParseMap[i].dwState;
- if ((dwState & (STATE_START | STATE_ENVELOPE | STATE_BODY)) == 0)
- {
- m_stringBuilder.SetReader(m_spReader);
- m_stringBuilder.SetParent(this);
-
- m_stringBuilder.Clear();
- m_spReader->putContentHandler( &m_stringBuilder );
- }
- else
- {
- if ((dwState <= m_dwState) ||
- (cchNamespaceUri != sizeof(SOAPENV_NAMESPACEA)-1) ||
- (wcsncmp(wszNamespaceUri, SOAPENV_NAMESPACEW, cchNamespaceUri)))
- {
- ATLTRACE( _T("ATLSOAP: CSoapFaultParser::startElement -- malformed SOAP fault.\r\n" ) );
-
- return E_FAIL;
- }
- }
-
- m_dwState = dwState;
- return S_OK;
- }
- }
- if (m_dwState > STATE_START)
- {
- m_dwState = STATE_SKIP;
- m_skipHandler.SetReader(m_spReader);
- m_skipHandler.SetParent(this);
-
- m_spReader->putContentHandler( &m_skipHandler );
- return S_OK;
- }
-
- ATLTRACE( _T("ATLSOAP: CSoapFaultParser::startElement -- malformed SOAP fault.\r\n" ) );
-
- return E_FAIL;
- }
-
- HRESULT __stdcall startPrefixMapping(
- const wchar_t * wszPrefix,
- int cchPrefix,
- const wchar_t * wszUri,
- int cchUri)
- {
- if ((cchUri == sizeof(SOAPENV_NAMESPACEA)-1) &&
- (!wcsncmp(wszUri, SOAPENV_NAMESPACEW, cchUri)))
- {
- m_wszSoapPrefix = wszPrefix;
- m_cchSoapPrefix = cchPrefix;
- }
-
- return S_OK;
- }
-
- HRESULT __stdcall characters(
- const wchar_t * wszChars,
- int cchChars);
-};
-
-extern __declspec(selectany) const int ATLS_SOAPFAULT_CNT = 4;
-
-class CSoapFault
-{
-private:
-
- struct _faultcode
- {
- const wchar_t *wsz;
- int cch;
- const wchar_t *wszFaultString;
- int cchFaultString;
- SOAP_ERROR_CODE errCode;
- };
-
- static const _faultcode s_faultCodes[];
-
-public:
-
- // members
- SOAP_ERROR_CODE m_soapErrCode;
- CStringW m_strFaultCode;
- CStringW m_strFaultString;
- CStringW m_strFaultActor;
- CStringW m_strDetail;
-
- CSoapFault()
- : m_soapErrCode(SOAP_E_UNK)
- {
- }
-
- HRESULT SetErrorCode(
- const wchar_t *wsz,
- const wchar_t *wszSoapPrefix,
- int cch = -1,
- int cchSoapPrefix = -1,
- bool bSetFaultString = true)
- {
- if ((wsz == NULL) || (wszSoapPrefix == NULL))
- {
- return E_INVALIDARG;
- }
-
- if (cch == -1)
- {
- cch = (int) wcslen(wsz);
- }
-
- while (*wsz && iswspace(*wsz))
- {
- ++wsz;
- --cch;
- }
-
- if (cchSoapPrefix == -1)
- {
- cchSoapPrefix = (int) wcslen(wszSoapPrefix);
- }
-
- const wchar_t *wszLocalName = wcschr(wsz, L':');
- if (wszLocalName == NULL)
- {
- // faultCode must be QName
-
- ATLTRACE( _T("ATLSOAP: CSoapFault::SetErrorCode -- faultCode is not a QName.\r\n" ) );
-
- return E_FAIL;
- }
-
- // make sure the namespace of the fault is the
- // SOAPENV namespace
- if ((cchSoapPrefix != (int)(wszLocalName-wsz)) ||
- (wcsncmp(wsz, wszSoapPrefix, cchSoapPrefix)))
- {
- ATLTRACE( _T("ATLSOAP: CSoapFault::SetErrorCode -- fault namespace is incorrect.\r\n" ) );
-
- return E_FAIL;
- }
-
- wszLocalName++;
- cch -= (int) (wszLocalName-wsz);
-
- _ATLTRY
- {
- for (int i=0; i<ATLS_SOAPFAULT_CNT; i++)
- {
- if ((cch == s_faultCodes[i].cch) &&
- (!wcsncmp(wszLocalName, s_faultCodes[i].wsz, cch)))
- {
- m_soapErrCode = s_faultCodes[i].errCode;
- if (bSetFaultString != false)
- {
- m_strFaultString.SetString(s_faultCodes[i].wszFaultString, s_faultCodes[i].cchFaultString);
- break;
- }
- }
- }
- if (m_strFaultString.GetLength() == 0)
- {
- m_strFaultCode.SetString(wszLocalName, cch);
- }
- }
- _ATLCATCHALL()
- {
- ATLTRACE( _T("ATLSOAP: CSoapFault::SetErrorCode -- out of memory.\r\n" ) );
-
- return E_OUTOFMEMORY;
- }
-
- return S_OK;
- }
-
- HRESULT ParseFault(IStream *pStream, ISAXXMLReader *pReader = NULL)
- {
- if (pStream == NULL)
- {
- ATLTRACE( _T("ATLSOAP: CSoapFault::ParseFault -- NULL IStream was passed.\r\n" ) );
-
- return E_INVALIDARG;
- }
-
- CComPtr<ISAXXMLReader> spReader;
- if (pReader != NULL)
- {
- spReader = pReader;
- }
- else
- {
- if (FAILED(spReader.CoCreateInstance(ATLS_SAXXMLREADER_CLSID, NULL, CLSCTX_INPROC_SERVER)))
- {
- ATLTRACE( _T("ATLSOAP: CSoapFault::ParseFault -- CoCreateInstance of SAXXMLReader failed.\r\n" ) );
-
- return E_FAIL;
- }
- }
-
- Clear();
- CSoapFaultParser parser(const_cast<CSoapFault *>(this), spReader);
- spReader->putContentHandler(&parser);
-
- CComVariant varStream;
- varStream = static_cast<IUnknown*>(pStream);
-
- HRESULT hr = spReader->parse(varStream);
- spReader->putContentHandler(NULL);
- return hr;
- }
-
- HRESULT GenerateFault(IWriteStream *pWriteStream)
- {
- if ((pWriteStream == NULL) || (m_soapErrCode == SOAP_E_UNK))
- {
- return E_INVALIDARG;
- }
-
- ATLASSERT( (m_soapErrCode == SOAP_E_UNK) ||
- (m_soapErrCode == SOAP_E_VERSION_MISMATCH) ||
- (m_soapErrCode == SOAP_E_MUST_UNDERSTAND) ||
- (m_soapErrCode == SOAP_E_CLIENT) ||
- (m_soapErrCode == SOAP_E_SERVER) );
-
- HRESULT hr = S_OK;
- _ATLTRY
- {
- const wchar_t *wszFaultCode = NULL;
- if (m_strFaultCode.GetLength() == 0)
- {
- for (int i=0; i<4; i++)
- {
- if (s_faultCodes[i].errCode == m_soapErrCode)
- {
- if (m_strFaultString.GetLength() == 0)
- {
- m_strFaultString.SetString(s_faultCodes[i].wszFaultString,
- s_faultCodes[i].cchFaultString);
- }
-
- wszFaultCode = s_faultCodes[i].wsz;
- break;
- }
- }
- }
-
- if (wszFaultCode == NULL)
- {
- if (m_strFaultCode.GetLength() != 0)
- {
- wszFaultCode = m_strFaultCode;
- }
- else
- {
- ATLTRACE( _T("CSoapFault::GenerateFault -- missing/invalid fault code.\r\n") );
- return E_FAIL;
- }
- }
-
- const LPCSTR s_szErrorFormat =
- "<SOAP:Envelope xmlns:SOAP=\"" SOAPENV_NAMESPACEA "\">"
- "<SOAP:Body>"
- "<SOAP:Fault>"
- "<faultcode>SOAP:%ws</faultcode>"
- "<faultstring>%ws</faultstring>"
- "%s%ws%s"
- "<detail>%ws</detail>"
- "</SOAP:Fault>"
- "</SOAP:Body>"
- "</SOAP:Envelope>";
-
- CStringA strFault;
- strFault.Format(s_szErrorFormat, wszFaultCode, m_strFaultString,
- m_strFaultActor.GetLength() ? "<faultactor>" : "", m_strFaultActor,
- m_strFaultActor.GetLength() ? "</faultactor>" : "",
- m_strDetail);
-
- hr = pWriteStream->WriteStream(strFault, strFault.GetLength(), NULL);
- }
- _ATLCATCHALL()
- {
- ATLTRACE( _T("ATLSOAP: CSoapFault::GenerateFault -- out of memory.\r\n" ) );
- hr = E_OUTOFMEMORY;
- }
-
- return hr;
- }
-
- void Clear()
- {
- m_soapErrCode = SOAP_E_UNK;
- m_strFaultCode.Empty();
- m_strFaultString.Empty();
- m_strFaultActor.Empty();
- m_strDetail.Empty();
- }
-}; // class CSoapFault
-
-#define DECLARE_SOAP_FAULT(__name, __faultstring, __errcode) \
- { L ## __name, sizeof(__name)-1, L ## __faultstring, sizeof(__faultstring), __errcode },
-
-__declspec(selectany) const CSoapFault::_faultcode CSoapFault::s_faultCodes[] =
-{
- DECLARE_SOAP_FAULT("VersionMismatch", "SOAP Version Mismatch Error", SOAP_E_VERSION_MISMATCH)
- DECLARE_SOAP_FAULT("MustUnderstand", "SOAP Must Understand Error", SOAP_E_MUST_UNDERSTAND)
- DECLARE_SOAP_FAULT("Client", "SOAP Invalid Request", SOAP_E_CLIENT)
- DECLARE_SOAP_FAULT("Server", "SOAP Server Application Faulted", SOAP_E_SERVER)
-};
-
-ATL_NOINLINE inline HRESULT __stdcall CSoapFaultParser::characters(
- const wchar_t * wszChars,
- int cchChars)
-{
- if (m_pFault == NULL)
- {
- return E_INVALIDARG;
- }
-
- if (m_dwState & STATE_RESET)
- {
- return S_OK;
- }
-
- HRESULT hr = E_FAIL;
- _ATLTRY
- {
- switch (m_dwState)
- {
- case STATE_FAULTCODE:
- if (m_pFault->m_soapErrCode == SOAP_E_UNK)
- {
- hr = m_pFault->SetErrorCode(wszChars, m_wszSoapPrefix,
- cchChars, m_cchSoapPrefix, false);
- }
- break;
- case STATE_FAULTSTRING:
- if (m_pFault->m_strFaultString.GetLength() == 0)
- {
- m_pFault->m_strFaultString.SetString(wszChars, cchChars);
- hr = S_OK;
- }
- break;
- case STATE_FAULTACTOR:
- if (m_pFault->m_strFaultActor.GetLength() == 0)
- {
- m_pFault->m_strFaultActor.SetString(wszChars, cchChars);
- hr = S_OK;
- }
- break;
- case STATE_DETAIL:
- if (m_pFault->m_strDetail.GetLength() == 0)
- {
- m_pFault->m_strDetail.SetString(wszChars, cchChars);
- hr = S_OK;
- }
- break;
- case STATE_START: case STATE_ENVELOPE : case STATE_BODY : case STATE_SKIP:
- hr = S_OK;
- break;
- default:
- // should never get here
- ATLASSERT( FALSE );
- break;
- }
- }
- _ATLCATCHALL()
- {
- ATLTRACE( _T("ATLSOAP: CSoapFaultParser::characters -- out of memory.\r\n" ) );
-
- hr = E_OUTOFMEMORY;
- }
-
- m_dwState |= STATE_RESET;
-
- return hr;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// CSoapRootHandler - the class that does most of the work
-//
-////////////////////////////////////////////////////////////////////////////////
-
-#ifndef ATLSOAP_STACKSIZE
- // 16 will be plenty for the 99% case
- #define ATLSOAP_STACKSIZE 16
-#endif
-
-#ifndef ATLSOAP_GROWARRAY
- #define ATLSOAP_GROWARRAY 10
-#endif
-
-class CSoapRootHandler : public ISAXContentHandlerImpl
-{
-private:
-
- friend class _CSDLGenerator;
-
- //
- // state constants
- //
- const static DWORD SOAP_START = 0;
- const static DWORD SOAP_ENVELOPE = 1;
- const static DWORD SOAP_HEADERS = 2;
- const static DWORD SOAP_BODY = 3;
- const static DWORD SOAP_PARAMS = 4;
- const static DWORD SOAP_CALLED = 5;
- const static DWORD SOAP_RESPONSE = 6;
- const static DWORD SOAP_HEADERS_DONE = 7;
-
- //
- // hash values for SOAP namespaces and elements
- //
- const static ULONG SOAP_ENV = 0x5D3574E2;
- const static ULONG SOAP_ENC = 0xBD62724B;
- const static ULONG ENVELOPE = 0xDBE6009E;
- const static ULONG HEADER = 0xAF4DFFC9;
- const static ULONG BODY = 0x0026168E;
-
- //
- // XSD Names
- //
- struct XSDEntry
- {
- wchar_t * wszName;
- char * szName;
- int cchName;
- };
-
- const static XSDEntry s_xsdNames[];
-
- //
- // CBitVector - a dynamically sized bit vector class
- //
- class CBitVector
- {
- private:
-
- // 64 bits will handle the 99% case
- unsigned __int64 m_nBits;
-
- // when we need to grow
- unsigned __int64 * m_pBits;
-
- size_t m_nSize;
-
- bool Grow(size_t nIndex)
- {
- // Think carefully
- // In our current implementation, CHAR_BIT==8, and sizeof(m_nBits)==8. Easy to confuse the two.
-
- // We do math in bits, so this is our max size
- ATLENSURE(nIndex<SIZE_MAX/((sizeof(m_nBits)*CHAR_BIT)));
-
- // round up to nearest 64 bits
- size_t nAllocSizeBits = nIndex+((sizeof(m_nBits)*CHAR_BIT)-(nIndex%(sizeof(m_nBits)*CHAR_BIT)));
- size_t nAllocSizeBytes = nAllocSizeBits/CHAR_BIT;
-
- if (m_pBits != &m_nBits)
- {
- unsigned __int64 * pNewBits=NULL;
- pNewBits = (unsigned __int64 *) realloc(m_pBits, nAllocSizeBytes );
- if(!pNewBits)
- {
- return false;
- }
- m_pBits=pNewBits;
- }
- else
- {
- m_pBits = (unsigned __int64 *) malloc(nAllocSizeBytes );
- if (m_pBits != NULL)
- {
- Checked::memcpy_s(m_pBits, nAllocSizeBytes, &m_nBits, sizeof(m_nBits));
- }
- }
-
- if (m_pBits != NULL)
- {
- // set new bits to 0
- memset(m_pBits+(m_nSize/(CHAR_BIT*sizeof(m_nBits))), 0x00, (nAllocSizeBits-m_nSize)/CHAR_BIT);
- m_nSize = nAllocSizeBits;
- return true;
- }
-
- ATLTRACE( _T("ATLSOAP: CBitVector::Grow -- out of memory.\r\n" ) );
-
- return false;
- }
-
- public:
-
- CBitVector()
- : m_nBits(0), m_nSize(sizeof(m_nBits)*CHAR_BIT)
- {
- m_pBits = &m_nBits;
- }
-
- CBitVector(const CBitVector&)
- {
- m_pBits = &m_nBits;
- }
-
- const CBitVector& operator=(const CBitVector& that)
- {
- if (this != &that)
- {
- m_pBits = &m_nBits;
- }
-
- return *this;
- }
-
- bool GetBit(size_t nIndex) const
- {
- if (nIndex >= m_nSize)
- {
- return false;
- }
-
- size_t i = nIndex/(sizeof(m_nBits)*CHAR_BIT);
- size_t nBits = nIndex-i*(sizeof(m_nBits)*CHAR_BIT);
- return ((m_pBits[i] >> nBits) & 0x01);
- }
-
- bool SetBit(size_t nIndex)
- {
- if (nIndex >= m_nSize)
- {
- if (!Grow(nIndex))
- {
- return false;
- }
- }
-
- size_t i = nIndex/(sizeof(m_nBits)*CHAR_BIT);
- size_t nBits = nIndex-i*(sizeof(m_nBits)*CHAR_BIT);
- m_pBits[i] |= (((unsigned __int64) 1) << nBits);
-
- return true;
- }
-
- void Clear()
- {
- if (m_pBits == &m_nBits)
- {
- m_nBits = 0;
- }
- else
- {
- memset(m_pBits, 0x00, (m_nSize/CHAR_BIT));
- }
- }
-
- ~CBitVector()
- {
- if (m_pBits != &m_nBits)
- {
- free(m_pBits);
- }
-
- m_pBits = &m_nBits;
- m_nSize = sizeof(m_nBits)*CHAR_BIT;
- }
-
- void RelocateFixup()
- {
- if (m_nSize <= sizeof(m_nBits)*CHAR_BIT)
- {
- m_pBits = &m_nBits;
- }
- }
- }; // class CBitVector
-
- //
- // Parsing State
- //
- struct ParseState
- {
- void *pvElement;
- DWORD dwFlags;
- size_t nAllocSize;
- size_t nExpectedElements;
- size_t nElement;
- const _soapmap *pMap;
- const _soapmapentry *pEntry;
-
- // mark when we get an item
- CBitVector vec;
-
- size_t nDepth;
-
- ParseState(void *pvElement_ = NULL, DWORD dwFlags_ = 0,
- size_t nAllocSize_ = 0, size_t nExpectedElements_ = 0,
- size_t nElement_ = 0, const _soapmap *pMap_ = NULL,
- const _soapmapentry *pEntry_ = NULL)
- : pvElement(pvElement_), dwFlags(dwFlags_), nAllocSize(nAllocSize_),
- nExpectedElements(nExpectedElements_), nElement(nElement_), pMap(pMap_),
- pEntry(pEntry_), nDepth(0)
- {
- vec.Clear();
- }
-
- ParseState(const ParseState& that)
- {
- pvElement = that.pvElement;
- dwFlags = that.dwFlags;
- nAllocSize = that.nAllocSize;
- nExpectedElements = that.nExpectedElements;
- nElement = that.nElement;
- pMap = that.pMap;
- pEntry = that.pEntry;
- nDepth = that.nDepth;
- vec.Clear();
- }
-
- ~ParseState()
- {
- pvElement = NULL;
- dwFlags = 0;
- nAllocSize = 0;
- nExpectedElements = 0;
- nElement = 0;
- pMap = NULL;
- pEntry = NULL;
- nDepth = 0;
- vec.Clear();
- }
-
- void RelocateFixup()
- {
- vec.RelocateFixup();
- }
- }; // struct ParseState
-
- class CParseStateElementTraits : public CDefaultElementTraits<ParseState>
- {
- public:
- // CBitVector relocate fixup
- static void RelocateElements( ParseState* pDest, ParseState* pSrc, size_t nElements )
- {
- CDefaultElementTraits<ParseState>::RelocateElements(pDest, pSrc, nElements);
-
- // fixup CBitVector
- for (size_t i=0; i<nElements; i++)
- {
- pDest[i].RelocateFixup();
- }
- }
- };
-
- class CResponseGenerator
- {
- public:
- HRESULT StartEnvelope(IWriteStream *pStream)
- {
- ATLENSURE_RETURN( pStream != NULL );
-
- return pStream->WriteStream("<soap:Envelope "
- "xmlns:soap=\"" SOAPENV_NAMESPACEA "\" "
- "xmlns:xsi=\"" XSI_NAMESPACEA "\" "
- "xmlns:xsd=\"" XSD_NAMESPACEA "\" "
- "xmlns:soapenc=\"" SOAPENC_NAMESPACEA "\">",
-
- sizeof("<soap:Envelope "
- "xmlns:soap=\"" SOAPENV_NAMESPACEA "\" "
- "xmlns:xsi=\"" XSI_NAMESPACEA "\" "
- "xmlns:xsd=\"" XSD_NAMESPACEA "\" "
- "xmlns:soapenc=\"" SOAPENC_NAMESPACEA "\">")-1,
-
- NULL);
- }
-
- HRESULT StartHeaders(IWriteStream *pStream, const _soapmap *pMap)
- {
- ATLENSURE_RETURN( pStream != NULL );
- ATLENSURE_RETURN( pMap != NULL );
-
- HRESULT hr = pStream->WriteStream("<soap:Header", sizeof("<soap:Header")-1, NULL);
- if (SUCCEEDED(hr))
- {
- if ((pMap->dwCallFlags & (SOAPFLAG_RPC | SOAPFLAG_ENCODED)) !=
- (SOAPFLAG_RPC | SOAPFLAG_ENCODED))
- {
- // qualify document/literal by default
- // For this version, ATL Server will not respect
- // the elementForm* attributes in an XSD schema
-
- hr = pStream->WriteStream(" xmlns=\"", sizeof(" xmlns=\"")-1, NULL);
- if (SUCCEEDED(hr))
- {
- hr = pStream->WriteStream(pMap->szNamespace, pMap->cchNamespace, NULL);
- if (SUCCEEDED(hr))
- {
- hr = pStream->WriteStream("\">", sizeof("\">")-1, NULL);
- }
- }
- }
- else
- {
- // rpc/encoded
- hr = pStream->WriteStream(">", sizeof(">")-1, NULL);
- }
- }
- return hr;
- }
-
- HRESULT EndHeaders(IWriteStream *pStream)
- {
- ATLENSURE_RETURN( pStream != NULL );
-
- return pStream->WriteStream("</soap:Header>", sizeof("</soap:Header>")-1, NULL);
- }
-
- virtual HRESULT StartBody(IWriteStream *pStream)
- {
- ATLENSURE_RETURN( pStream != NULL );
-
- return pStream->WriteStream(
- "<soap:Body>", sizeof("<soap:Body>")-1, NULL);
- }
-
- HRESULT EndBody(IWriteStream *pStream)
- {
- ATLENSURE_RETURN( pStream != NULL );
-
- return pStream->WriteStream("</soap:Body>", sizeof("</soap:Body>")-1, NULL);
- }
-
- HRESULT EndEnvelope(IWriteStream *pStream)
- {
- ATLENSURE_RETURN( pStream != NULL );
-
- return pStream->WriteStream("</soap:Envelope>", sizeof("</soap:Envelope>")-1, NULL);
- }
-
- virtual HRESULT StartMap(IWriteStream *pStream, const _soapmap *pMap, bool bClient) = 0;
- virtual HRESULT EndMap(IWriteStream *pStream, const _soapmap *pMap, bool bClient) = 0;
-
- virtual HRESULT StartEntry(IWriteStream *pStream, const _soapmap *pMap, const _soapmapentry *pEntry)
- {
- ATLENSURE_RETURN( pStream != NULL );
- ATLENSURE_RETURN( pEntry != NULL );
-
- // output name
- HRESULT hr = pStream->WriteStream("<", 1, NULL);
- if (SUCCEEDED(hr))
- {
- const char *szHeaderNamespace = NULL;
- int cchHeaderNamespace = 0;
-
- if ((pMap != NULL) && (pMap->mapType == SOAPMAP_HEADER) &&
- ((pEntry->pChain != NULL) &&
- (pEntry->pChain->szNamespace !=NULL)) ||
- (pEntry->szNamespace != NULL))
- {
- hr = pStream->WriteStream("snp:", sizeof("snp:")-1, NULL);
- if (SUCCEEDED(hr))
- {
- szHeaderNamespace = pEntry->pChain ?
- pEntry->pChain->szNamespace : pEntry->szNamespace;
-
- cchHeaderNamespace = pEntry->pChain ?
- pEntry->pChain->cchNamespace : pEntry->cchNamespace;
- }
- }
-
- if (SUCCEEDED(hr))
- {
- if ((pEntry->dwFlags & SOAPFLAG_RETVAL)==0)
- {
- hr = pStream->WriteStream(pEntry->szField, pEntry->cchField, NULL);
- }
- else
- {
- hr = pStream->WriteStream("return", sizeof("return")-1, NULL);
- }
- if (SUCCEEDED(hr))
- {
- if (szHeaderNamespace != NULL)
- {
- ATLASSERT( cchHeaderNamespace != 0 );
-
- hr = pStream->WriteStream(" xmlns:snp=\"", sizeof(" xmlns:snp=\"")-1, NULL);
- if (SUCCEEDED(hr))
- {
- hr = pStream->WriteStream(szHeaderNamespace, cchHeaderNamespace, NULL);
- if (SUCCEEDED(hr))
- {
- hr = pStream->WriteStream("\"", sizeof("\"")-1, NULL);
- }
- }
- }
- }
- }
- }
- if (SUCCEEDED(hr))
- {
- if (pEntry->dwFlags & SOAPFLAG_MUSTUNDERSTAND)
- {
- // output mustUnderstand
- hr = pStream->WriteStream(" soap:mustUnderstand=\"1\"", sizeof(" soap:mustUnderstand=\"1\"")-1, NULL);
- }
- }
- return hr;
- }
-
- HRESULT EndEntry(IWriteStream *pStream, const _soapmap *pMap, const _soapmapentry *pEntry)
- {
- ATLENSURE_RETURN( pStream != NULL );
- ATLENSURE_RETURN( pEntry != NULL );
-
- HRESULT hr = pStream->WriteStream("</", 2, NULL);
- if (SUCCEEDED(hr))
- {
- if ((pMap != NULL) &&
- (pMap->mapType == SOAPMAP_HEADER) &&
- ((pEntry->pChain != NULL) &&
- (pEntry->pChain->szNamespace !=NULL)) ||
- (pEntry->szNamespace != NULL))
- {
- hr = pStream->WriteStream("snp:", sizeof("snp:")-1, NULL);
- }
- if ((pEntry->dwFlags & SOAPFLAG_RETVAL)==0)
- {
- hr = pStream->WriteStream(pEntry->szField, pEntry->cchField, NULL);
- }
- else
- {
- hr = pStream->WriteStream("return", sizeof("return")-1, NULL);
- }
- if (SUCCEEDED(hr))
- {
- hr = pStream->WriteStream(">", 1, NULL);
- }
- }
- return hr;
- }
- }; // class CResponseGenerator
-
- class CDocLiteralGenerator : public CResponseGenerator
- {
- public:
-
- HRESULT StartMap(IWriteStream *pStream, const _soapmap *pMap, bool bClient)
- {
- ATLENSURE_RETURN( pStream != NULL );
- ATLENSURE_RETURN( pMap != NULL );
-
- HRESULT hr = S_OK;
- // output type name
- hr = pStream->WriteStream("<", 1, NULL);
- if (SUCCEEDED(hr))
- {
- hr = pStream->WriteStream(pMap->szName, pMap->cchName, NULL);
- if (SUCCEEDED(hr))
- {
- if ((pMap->mapType == SOAPMAP_FUNC) &&
- (bClient == false) &&
- (pMap->dwCallFlags & SOAPFLAG_PID))
- {
- hr = pStream->WriteStream("Response", sizeof("Response")-1, NULL);
- if (FAILED(hr))
- {
- return hr;
- }
- }
-
- if (pMap->mapType == SOAPMAP_FUNC)
- {
- hr = pStream->WriteStream(" xmlns=\"", sizeof(" xmlns=\"")-1, NULL);
- if (SUCCEEDED(hr))
- {
- hr = pStream->WriteStream(pMap->szNamespace, pMap->cchNamespace, NULL);
- if (SUCCEEDED(hr))
- {
- hr = pStream->WriteStream("\">", sizeof("\">")-1, NULL);
- }
- }
- }
- else
- {
- hr = pStream->WriteStream(">", 1, NULL);
- }
- }
- }
- return hr;
- }
-
- HRESULT EndMap(IWriteStream *pStream, const _soapmap *pMap, bool bClient)
- {
- ATLENSURE_RETURN( pStream != NULL );
- ATLENSURE_RETURN( pMap != NULL );
-
- HRESULT hr = pStream->WriteStream("</", sizeof("</")-1, NULL);
- if (SUCCEEDED(hr))
- {
- hr = pStream->WriteStream(pMap->szName, pMap->cchName, NULL);
- if (SUCCEEDED(hr))
- {
- if ((pMap->mapType == SOAPMAP_FUNC) &&
- (bClient == false) &&
- (pMap->dwCallFlags & SOAPFLAG_PID))
- {
- hr = pStream->WriteStream("Response", sizeof("Response")-1, NULL);
- if (FAILED(hr))
- {
- return hr;
- }
- }
- hr = pStream->WriteStream(">", 1, NULL);
- }
- }
-
- return hr;
- }
-
- }; // class CDocLiteralGenerator
-
- class CPIDGenerator : public CDocLiteralGenerator
- {
- };
-
- class CPADGenerator : public CDocLiteralGenerator
- {
- public:
-
- virtual HRESULT StartEntry(IWriteStream *pStream, const _soapmap *pMap, const _soapmapentry *pEntry)
- {
- ATLENSURE_RETURN( pStream != NULL );
- ATLENSURE_RETURN( pEntry != NULL );
-
- HRESULT hr = __super::StartEntry(pStream, pMap, pEntry);
- if (SUCCEEDED(hr) && (pMap->dwCallFlags & SOAPFLAG_PAD))
- {
- hr = pStream->WriteStream(" xmlns=\"", sizeof(" xmlns=\"")-1, NULL);
- if (SUCCEEDED(hr))
- {
- hr = pStream->WriteStream(pMap->szNamespace, pMap->cchNamespace, NULL);
- if (SUCCEEDED(hr))
- {
- hr = pStream->WriteStream("\"", sizeof("\"")-1, NULL);
- }
- }
- }
-
- return hr;
- }
- }; // class CPADGenerator
-
- class CRpcEncodedGenerator : public CResponseGenerator
- {
- public:
-
- HRESULT StartBody(IWriteStream *pStream)
- {
- ATLENSURE_RETURN( pStream != NULL );
-
- return pStream->WriteStream(
- "<soap:Body soap:encodingStyle=\"" SOAPENC_NAMESPACEA "\">",
- sizeof("<soap:Body soap:encodingStyle=\"" SOAPENC_NAMESPACEA "\">")-1, NULL);
- }
-
- HRESULT StartMap(IWriteStream *pStream, const _soapmap *pMap, bool bClient)
- {
- ATLENSURE_RETURN( pStream != NULL );
- ATLENSURE_RETURN( pMap != NULL );
-
- (bClient); // unused for rpc/encoded
-
- HRESULT hr = pStream->WriteStream("<snp:", sizeof("<snp:")-1, NULL);
- if (SUCCEEDED(hr))
- {
- hr = pStream->WriteStream(pMap->szName, pMap->cchName, NULL);
- if (SUCCEEDED(hr))
- {
- if (pMap->mapType == SOAPMAP_FUNC)
- {
- hr = pStream->WriteStream(" xmlns:snp=\"", sizeof(" xmlns:snp=\"")-1, NULL);
- if (SUCCEEDED(hr))
- {
- ATLASSERT( pMap->szNamespace != NULL );
- hr = pStream->WriteStream(pMap->szNamespace, pMap->cchNamespace, NULL);
- if (SUCCEEDED(hr))
- {
- hr = pStream->WriteStream("\">", sizeof("\">")-1, NULL);
- }
- }
- }
- else
- {
- hr = pStream->WriteStream(">", 1, NULL);
- }
- }
- }
- return hr;
- }
-
- HRESULT EndMap(IWriteStream *pStream, const _soapmap *pMap, bool bClient)
- {
- ATLENSURE_RETURN( pStream != NULL );
- ATLENSURE_RETURN( pMap != NULL );
-
- (bClient); // unused for rpc/encoded
-
- HRESULT hr = pStream->WriteStream("</snp:", sizeof("</snp:")-1, NULL);
- if (SUCCEEDED(hr))
- {
- hr = pStream->WriteStream(pMap->szName, pMap->cchName, NULL);
- if (SUCCEEDED(hr))
- {
- hr = pStream->WriteStream(">", 1, NULL);
- }
- }
-
- return hr;
- }
- }; // class CRpcEncodedGenerator
-
- //
- // members
- //
- CAtlArray<ParseState, CParseStateElementTraits> m_stateStack;
- size_t m_nState;
-
- DWORD m_dwState;
-
- CComPtr<ISAXXMLReader> m_spReader;
-
- CSAXStringBuilder m_stringBuilder;
- CSkipHandler m_skipHandler;
-
- IAtlMemMgr * m_pMemMgr;
-
- static CCRTHeap m_crtHeap;
-
- bool m_bClient;
-
- void *m_pvParam;
-
- bool m_bNullCheck;
- bool m_bChildCheck;
- bool m_bCharacters;
- size_t m_nDepth;
-
- typedef CFixedStringT<CStringW, 16> REFSTRING;
-
- // used for rpc/encoded messages with href's
- typedef CAtlMap<REFSTRING, ParseState, CStringRefElementTraits<REFSTRING> > REFMAP;
- REFMAP m_refMap;
-
- //
- // Implementation helpers
- //
-
- HRESULT PushState(void *pvElement = NULL, const _soapmap *pMap = NULL,
- const _soapmapentry *pEntry = NULL, DWORD dwFlags = 0, size_t nAllocSize = 0,
- size_t nExpectedElements = 0, size_t nElement = 0)
- {
- if (m_stateStack.IsEmpty())
- {
- // 16 will be plenty for the 99% case
- if (!m_stateStack.SetCount(0, 16))
- {
- ATLTRACE( _T("ATLSOAP: CSoapRootHandler::PushState -- out of memory.\r\n" ) );
-
- return E_OUTOFMEMORY;
- }
- }
-
- size_t nCnt = m_stateStack.GetCount();
- m_nState = m_stateStack.Add();
- if (m_stateStack.GetCount() <= nCnt)
- {
- ATLTRACE( _T("ATLSOAP: CSoapRootHandler::PushState -- out of memory.\r\n" ) );
-
- return E_OUTOFMEMORY;
- }
-
- ParseState &state = m_stateStack[m_nState];
-
- state.pvElement = pvElement;
- state.dwFlags = dwFlags;
- state.nAllocSize = nAllocSize;
- state.nExpectedElements = nExpectedElements;
- state.nElement = nElement;
- state.pMap = pMap;
- state.pEntry = pEntry;
- state.nDepth = m_nDepth;
-
- return S_OK;
- }
-
- ParseState& GetState()
- {
- return m_stateStack[m_nState];
- }
-
- void PopState(bool bForce = false)
- {
- if ((m_nState != 0) || (bForce != false))
- {
- m_stateStack.RemoveAt(m_nState);
- --m_nState;
- }
- }
-
- BOOL IsEqualElement(int cchLocalNameCheck, const wchar_t *wszLocalNameCheck,
- int cchNamespaceUriCheck, const wchar_t *wszNamespaceUriCheck,
- int cchLocalName, const wchar_t *wszLocalName,
- int cchNamespaceUri, const wchar_t *wszNamespaceUri)
- {
- ATLENSURE(wszLocalName);
- ATLENSURE(wszLocalNameCheck);
- ATLENSURE(wszNamespaceUri);
- ATLENSURE(wszNamespaceUriCheck);
-
- if (cchLocalName == cchLocalNameCheck &&
- cchNamespaceUri == cchNamespaceUriCheck &&
- !wcsncmp(wszLocalName, wszLocalNameCheck, cchLocalName) &&
- !wcsncmp(wszNamespaceUri, wszNamespaceUriCheck, cchNamespaceUri))
- {
- return TRUE;
- }
-
- return FALSE;
- }
-
- ATL_FORCEINLINE BOOL IsEqualString(const wchar_t *wszStr1, int cchStr1, const wchar_t *wszStr2, int cchStr2)
- {
- ATLENSURE( wszStr1 != NULL );
- ATLENSURE( wszStr2 != NULL );
- ATLENSURE( cchStr1 >= 0 );
- ATLENSURE( cchStr2 >= 0 );
-
- if (cchStr1 == cchStr2)
- {
- return !wcsncmp(wszStr1, wszStr2, cchStr2);
- }
- return FALSE;
- }
-
- ATL_FORCEINLINE BOOL IsEqualStringHash(const wchar_t *wszStr1, int cchStr1, ULONG nHash1,
- const wchar_t *wszStr2, int cchStr2, ULONG nHash2)
- {
- ATLENSURE( wszStr1 != NULL );
- ATLENSURE( wszStr2 != NULL );
- ATLENSURE( cchStr1 >= 0 );
- ATLENSURE( cchStr2 >= 0 );
-
- if (nHash1 == nHash2)
- {
- return IsEqualString(wszStr1, cchStr1, wszStr2, cchStr2);
- }
-
- return FALSE;
- }
-
- BOOL IsEqualElement(int cchLocalNameCheck, const wchar_t *wszLocalNameCheck,
- int cchLocalName, const wchar_t *wszLocalName)
- {
- if (cchLocalName == cchLocalNameCheck &&
- !wcsncmp(wszLocalName, wszLocalNameCheck, cchLocalName))
- {
- return TRUE;
- }
-
- return FALSE;
- }
-
- void SetOffsetValue(void *pBase, void *pSrc, size_t nOffset)
- {
- void **ppDest = (void **)(((unsigned char *)pBase)+nOffset);
- *ppDest = pSrc;
- }
-
- bool IsRpcEncoded()
- {
- if ((m_stateStack[0].pMap->dwCallFlags & (SOAPFLAG_RPC | SOAPFLAG_ENCODED)) ==
- (SOAPFLAG_RPC | SOAPFLAG_ENCODED))
- {
- return true;
- }
- return false;
- }
-
-
- HRESULT ValidateArrayEntry(
- ParseState& state,
- const wchar_t *wszLocalName,
- int cchLocalName)
- {
- (cchLocalName);
- (wszLocalName);
-
- ATLASSERT( state.pEntry != NULL );
-
- // SOAP Section 5.4.2
-
- // check number of elements
- if (state.nElement == state.nExpectedElements)
- {
- // too many elements
- if ((state.dwFlags & SOAPFLAG_UNKSIZE)==0)
- {
- ATLTRACE( _T("ATLSOAP: CSoapRootHandler::ValidateArrayEntry -- too many elements.\r\n" ) );
- return E_FAIL;
- }
-
- ATLASSERT( IsRpcEncoded() == false );
-
- // see if we need to allocate more
- if (state.nElement == state.nAllocSize)
- {
- unsigned char **ppArr = (unsigned char **)state.pvElement;
- size_t nNewElement=0;
- HRESULT hr=E_FAIL;
- if(FAILED(hr=::ATL::AtlMultiply(&nNewElement, state.nElement, static_cast<size_t>(2))))
- {
- return hr;
- }
- hr = AllocateArray(state.pEntry, (void **)ppArr, __max(nNewElement, ATLSOAP_GROWARRAY), state.nElement);
-
- if (SUCCEEDED(hr))
- {
- state.nAllocSize = __max((state.nElement)*2, ATLSOAP_GROWARRAY);
- }
-
- return hr;
- }
- }
-
- return S_OK;
- }
-
- HRESULT CheckID(
- const wchar_t *wszNamespaceUri,
- const wchar_t *wszLocalName,
- int cchLocalName,
- ISAXAttributes *pAttributes)
- {
- (cchLocalName);
- (wszLocalName);
- (wszNamespaceUri);
- ATLASSERT( pAttributes != NULL );
-
- const wchar_t *wsz = NULL;
- int cch = 0;
-
- HRESULT hr = GetAttribute(pAttributes, L"id", sizeof("id")-1, &wsz, &cch);
- if ((hr == S_OK) && (wsz != NULL))
- {
- const REFMAP::CPair *p = NULL;
- _ATLTRY
- {
- REFSTRING strRef(wsz, cch);
- p = m_refMap.Lookup(strRef);
- if (p == NULL)
- {
- return S_FALSE;
- }
- }
- _ATLCATCHALL()
- {
- ATLTRACE( _T("ATLSOAP: CSoapRootHandler::CheckID -- out of memory.\r\n" ) );
-
- return E_OUTOFMEMORY;
- }
-
- ATLASSERT( IsRpcEncoded() == true );
-
- const ParseState& state = p->m_value;
-
- // disallow href-chaining
- hr = CheckHref(state.pEntry, state.pvElement, pAttributes);
- if (hr != S_FALSE)
- {
- return E_FAIL;
- }
-
- hr = S_OK;
-
- // do array stuff
- if (state.dwFlags & (SOAPFLAG_FIXEDARR | SOAPFLAG_DYNARR))
- {
- hr = GetSection5Info(state, state.pEntry, pAttributes);
- }
- else
- {
- // only structs and arrays are allowed for hrefs
- ATLASSERT( state.pEntry->pChain != NULL );
- ATLASSERT( state.pEntry->pChain->mapType == SOAPMAP_STRUCT );
-
- // structs must have child entries
- m_bChildCheck = state.pEntry->pChain->nElements != 0;
-
- if (S_OK != PushState(state.pvElement, state.pEntry->pChain, state.pEntry,
- state.dwFlags, 0, state.pEntry->pChain->nElements))
- {
- ATLTRACE( _T("ATLSOAP: CSoapRootHandler::CheckID -- out of memory.\n" ) );
- hr = E_OUTOFMEMORY;
- }
- }
-
- m_refMap.DisableAutoRehash();
- m_refMap.RemoveAtPos(const_cast<REFMAP::CPair*>(p));
- m_refMap.EnableAutoRehash();
-
- return hr;
- }
-
- return S_FALSE;
- }
-
- HRESULT GetElementEntry(
- ParseState& state,
- const wchar_t *wszNamespaceUri,
- const wchar_t *wszLocalName,
- int cchLocalName,
- ISAXAttributes *pAttributes,
- const _soapmapentry **ppEntry)
- {
- ATLENSURE_RETURN( state.pMap != NULL );
- ATLENSURE_RETURN( ppEntry != NULL );
-
- *ppEntry = NULL;
- const _soapmapentry *pEntries = state.pMap->pEntries;
- DWORD dwIncludeFlags;
- DWORD dwExcludeFlags;
-
- HRESULT hr = CheckID(wszNamespaceUri, wszLocalName, cchLocalName, pAttributes);
- if (hr != S_FALSE)
- {
- if (hr == S_OK)
- {
- hr = S_FALSE;
- }
- return hr;
- }
-
- if (m_bClient != false)
- {
- dwIncludeFlags = SOAPFLAG_OUT;
- dwExcludeFlags = SOAPFLAG_IN;
- }
- else
- {
- dwIncludeFlags = SOAPFLAG_IN;
- dwExcludeFlags = SOAPFLAG_OUT;
- }
-
- ULONG nHash = AtlSoapHashStr(wszLocalName, cchLocalName);
-
- for (size_t i=0; pEntries[i].nHash != 0; i++)
- {
- if (nHash == pEntries[i].nHash &&
- ((pEntries[i].dwFlags & dwIncludeFlags) ||
- ((pEntries[i].dwFlags & dwExcludeFlags) == 0)) &&
- IsEqualElement(pEntries[i].cchField, pEntries[i].wszField,
- cchLocalName, wszLocalName)/* &&
- !wcscmp(wszNamespaceUri, wszNamespace)*/)
- {
- // check bit vector
-
- if (state.vec.GetBit(i) == false)
- {
- if (state.vec.SetBit(i) == false)
- {
- return E_OUTOFMEMORY;
- }
- }
- else
- {
- // already received this element
- ATLTRACE( _T("ATLSOAP: CSoapRootHandler::GetElementEntry -- duplicate element was sent.\r\n" ) );
-
- return E_FAIL;
- }
-
- state.nElement++;
- *ppEntry = &pEntries[i];
-
- return S_OK;
- }
- }
-
- ATLTRACE( _T("ATLSOAP: CSoapRootHandler::GetElementEntry -- element not found: %.*ws.\r\n" ), cchLocalName, wszLocalName );
-
- return E_FAIL;
- }
-
- HRESULT CheckMustUnderstandHeader(ISAXAttributes *pAttributes)
- {
- ATLASSERT( pAttributes != NULL );
-
- const wchar_t* wszMustUnderstand;
- int cchMustUnderstand;
- bool bMustUnderstand= false;
-
- if (SUCCEEDED(GetAttribute(pAttributes, L"mustUnderstand", sizeof("mustUnderstand")-1,
- &wszMustUnderstand, &cchMustUnderstand,
- SOAPENV_NAMESPACEW, sizeof(SOAPENV_NAMESPACEA)-1)) &&
- (wszMustUnderstand != NULL))
- {
- if (FAILED(AtlGetSAXValue(&bMustUnderstand, wszMustUnderstand, cchMustUnderstand)))
- {
- bMustUnderstand = true;
- }
- }
-
- if (bMustUnderstand == false)
- {
- ATLASSERT( GetReader() != NULL );
-
- m_skipHandler.SetReader(GetReader());
- m_skipHandler.SetParent(this);
-
- return GetReader()->putContentHandler( &m_skipHandler );
- }
- else
- {
- SoapFault(SOAP_E_MUST_UNDERSTAND, NULL, 0);
- }
-
- ATLTRACE( _T("ATLSOAP: CSoapRootHandler::CheckMustUnderstandHeader -- unknown \"mustUnderstand\" SOAP Header was received.\r\n" ) );
-
- return E_FAIL;
- }
-
- HRESULT AllocateArray(
- const _soapmapentry *pEntry,
- void **ppArr, size_t nElements,
- size_t nCurrElements = 0)
- {
- ATLENSURE_RETURN( ppArr != NULL );
- ATLENSURE_RETURN( pEntry != NULL );
-
- size_t nElementSize;
- if (pEntry->nVal != SOAPTYPE_UNK)
- {
- nElementSize = AtlSoapGetElementSize((SOAPTYPES) pEntry->nVal);
- }
- else // UDT
- {
- ATLENSURE_RETURN( pEntry->pChain != NULL );
- nElementSize = pEntry->pChain->nElementSize;
- }
- if (nElementSize != 0)
- {
- if (*ppArr == NULL)
- {
- ATLASSERT( nCurrElements == 0 );
- size_t nBytes=0;
- HRESULT hr=S_OK;
- if( FAILED(hr=::ATL::AtlMultiply(&nBytes, nElementSize, nElements)))
- {
- return hr;
- }
- *ppArr = m_pMemMgr->Allocate(nBytes);
- }
- else // *ppArr != NULL
- {
- ATLASSERT( nCurrElements != 0 );
- size_t nBytes=0;
- HRESULT hr=S_OK;
- if( FAILED(hr=::ATL::AtlAdd(&nBytes, nElements, nCurrElements)) ||
- FAILED(hr=::ATL::AtlMultiply(&nBytes, nElementSize, nBytes)))
- {
- return hr;
- }
- *ppArr = m_pMemMgr->Reallocate(*ppArr, nBytes);
- }
- }
- else
- {
- // internal error
- ATLASSERT( FALSE );
- return E_FAIL;
- }
-
- if (*ppArr == NULL)
- {
- return E_OUTOFMEMORY;
- }
-
- memset(((unsigned char *)(*ppArr))+(nCurrElements*nElementSize), 0x00, nElements*nElementSize);
-
- return S_OK;
- }
-
- HRESULT GetSection5Info(
- const ParseState& state,
- const _soapmapentry *pEntry,
- ISAXAttributes *pAttributes)
- {
- ATLENSURE_RETURN( pEntry != NULL );
- ATLENSURE_RETURN( pAttributes != NULL );
-
- HRESULT hr;
- if (IsRpcEncoded() != false)
- {
- // check for href
- // we ONLY do this for rpc/encoded (required for interop)
- // NOTE: ATL Server does not support object graphs, so
- // only single-reference elements are allowed
- hr = CheckHref(pEntry, state.pvElement, pAttributes,
- pEntry->dwFlags, SOAPFLAG_READYSTATE);
- if (hr != S_FALSE)
- {
- return hr;
- }
- }
-
- size_t nElements;
- DWORD dwFlags = 0;
- hr = AtlSoapGetArraySize(pAttributes, &nElements);
- if (FAILED(hr))
- {
- return hr;
- }
-
- size_t nAllocSize = 0;
- size_t nElementsPush = 0;
-
- if (pEntry->dwFlags & SOAPFLAG_DYNARR)
- {
- // set size_is value
- ATLENSURE_RETURN( state.pMap != NULL );
- int *pnSizeIs = (int *)(((unsigned char *)state.pvElement)+
- (state.pMap->pEntries[pEntry->nSizeIs].nOffset));
-
- if (hr != S_OK)
- {
- if (IsRpcEncoded())
- {
- // rpc/encoded requires soapenc:arrayType attribute
- return E_FAIL;
- }
-
- nElements = ATLSOAP_GROWARRAY;
- nAllocSize = ATLSOAP_GROWARRAY;
- dwFlags |= SOAPFLAG_UNKSIZE;
- *pnSizeIs = 0;
- }
- else
- {
- *pnSizeIs = (int)nElements;
- if (nElements == 0)
- {
- // soapenc:arrayType="type[0]"
- // treat as null array
-
- m_bNullCheck = true;
-
- // push an emtpy state
- return PushState();
- }
-
- nElementsPush = nElements;
- }
- void *p = NULL;
- hr = AllocateArray(pEntry, &p, nElements);
- if (hr != S_OK)
- {
- return hr;
- }
-
- SetOffsetValue(state.pvElement, p, pEntry->nOffset);
- }
- else
- {
- // for fixed-size arrays, we know the number of elements
- ATLASSERT( pEntry->dwFlags & SOAPFLAG_FIXEDARR );
- if (hr == S_OK)
- {
- if (nElements != AtlSoapGetArrayDims(pEntry->pDims))
- {
- return E_FAIL;
- }
- }
- else
- {
- hr = S_OK;
- nElements = AtlSoapGetArrayDims(pEntry->pDims);
- }
- nElementsPush = nElements;
- }
-
- dwFlags |= pEntry->dwFlags;
-
- // push element with array flag
-
- if (S_OK != PushState(((unsigned char *)state.pvElement)+pEntry->nOffset,
- state.pMap, pEntry, dwFlags & ~SOAPFLAG_READYSTATE, nAllocSize, nElementsPush))
- {
- return E_OUTOFMEMORY;
- }
-
- m_bChildCheck = true;
-
- return S_OK;
- }
-
- void * UpdateArray(ParseState& state, const _soapmapentry *pEntry)
- {
- ATLENSURE(pEntry);
-
- size_t nSize;
- void *pVal = NULL;
-
- if (pEntry->nVal != SOAPTYPE_UNK)
- {
- nSize = AtlSoapGetElementSize((SOAPTYPES) pEntry->nVal);
- }
- else
- {
- ATLENSURE( pEntry->pChain != NULL );
-
- nSize = pEntry->pChain->nElementSize;
- }
-
- if (state.dwFlags & SOAPFLAG_FIXEDARR)
- {
- unsigned char *ppArr = (unsigned char *)state.pvElement;
- pVal = ppArr+(state.nElement*nSize);
- }
- else
- {
- ATLASSERT( state.dwFlags & SOAPFLAG_DYNARR );
-
- unsigned char **ppArr = (unsigned char **)state.pvElement;
- pVal = (*ppArr)+(state.nElement*nSize);
- if (state.dwFlags & SOAPFLAG_UNKSIZE)
- {
- ATLASSERT( IsRpcEncoded() == false );
-
- // need to use the previous state's pvElement to update the size_is value
- ATLASSUME( m_nState > 0 );
- int *pnSizeIs = (int *)(((unsigned char *)m_stateStack[m_nState-1].pvElement)+
- (state.pMap->pEntries[pEntry->nSizeIs].nOffset));
-
- // update size_is parameter
- *pnSizeIs = (int)(state.nElement+1);
- state.nExpectedElements++;
- }
- }
- state.nElement++;
-
- return pVal;
- }
-
- HRESULT ProcessString(const _soapmapentry *pEntry, void *pVal)
- {
- ATLENSURE_RETURN( pEntry != NULL );
-
- // set to the string builder class
-
- ATLASSERT( GetReader() != NULL );
-
- m_stringBuilder.SetReader(GetReader());
- m_stringBuilder.SetParent(this);
-
- m_stringBuilder.Clear();
- GetReader()->putContentHandler( &m_stringBuilder );
-
- if (S_OK != PushState(pVal, NULL, pEntry, SOAPFLAG_READYSTATE | pEntry->dwFlags))
- {
- return E_OUTOFMEMORY;
- }
-
- return S_OK;
- }
-
-
- HRESULT CheckHref(
- const _soapmapentry *pEntry,
- void *pVal,
- ISAXAttributes *pAttributes,
- DWORD dwIncludeFlags = 0,
- DWORD dwExcludeFlags = 0)
- {
- ATLASSERT( pEntry != NULL );
- ATLASSERT( pVal != NULL );
- ATLASSERT( pAttributes != NULL );
-
- const wchar_t *wsz = NULL;
- int cch = 0;
-
- HRESULT hr = GetAttribute(pAttributes, L"href", sizeof("href")-1, &wsz, &cch);
- if ((hr == S_OK) && (wsz != NULL))
- {
- // only allow hrefs on structs and arrays
- if (((pEntry->dwFlags & (SOAPFLAG_FIXEDARR | SOAPFLAG_DYNARR))==0) &&
- (pEntry->pChain == NULL || pEntry->pChain->mapType != SOAPMAP_STRUCT))
- {
- ATLTRACE( _T("ATL Server only allows href's on arrays and structs.\r\n") );
-
- return E_FAIL;
- }
-
- ATLASSERT( IsRpcEncoded() == true );
-
- _ATLTRY
- {
- if (*wsz == L'#')
- {
- wsz++;
- cch--;
- }
-
- REFSTRING strRef(wsz, cch);
- if (m_refMap.Lookup(strRef) != NULL)
- {
- // ATL Server does not support multi-reference objects
- ATLASSERT( FALSE );
- return E_FAIL;
- }
-
- ParseState& currState = GetState();
- if ((currState.pEntry != NULL) && (currState.pEntry->dwFlags & (SOAPFLAG_FIXEDARR | SOAPFLAG_DYNARR)))
- {
- // it is an array item
- ATLASSERT( currState.nElement != 0 );
-
- // exclude array flags for href'd array elements
- dwExcludeFlags |= SOAPFLAG_FIXEDARR | SOAPFLAG_DYNARR;
- }
-
- ParseState state;
- state.pvElement = pVal;
- state.dwFlags = (pEntry->dwFlags | dwIncludeFlags) & ~dwExcludeFlags;
- state.nExpectedElements = 0;
-
- state.nElement = 0;
- state.pMap = GetState().pMap;
- state.pEntry = pEntry;
-
- if (!m_refMap.SetAt(strRef, state))
- {
- ATLTRACE( _T("ATLSOAP: CSoapRootHandler::CheckHref -- out of memory.\r\n" ) );
-
- return E_OUTOFMEMORY;
- }
-
- // make sure there are no child elements
- m_bNullCheck = true;
-
- // push an emtpy state
- return PushState();
- }
- _ATLCATCHALL()
- {
- ATLTRACE( _T("ATLSOAP: CSoapRootHandler::CheckHref -- out of memory.\r\n" ) );
-
- return E_OUTOFMEMORY;
- }
- }
-
- return S_FALSE;
- }
-
- HRESULT ProcessUDT(
- const _soapmapentry *pEntry,
- void *pVal)
- {
- ATLENSURE_RETURN( pEntry != NULL );
- ATLENSURE_RETURN( pVal != NULL );
- ATLENSURE_RETURN( pEntry->nVal != SOAPTYPE_ERR );
- ATLENSURE_RETURN( pEntry->nVal != SOAPTYPE_USERBASE );
-
- // if it is a complex type, get the chain entry
- // and push the new state on the stack
-
- DWORD dwFlags = pEntry->dwFlags;
- if (pEntry->pChain->mapType != SOAPMAP_ENUM)
- {
- // struct
- dwFlags &= ~(SOAPFLAG_FIXEDARR | SOAPFLAG_DYNARR);
- m_bChildCheck = pEntry->pChain->nElements != 0;
- }
- else
- {
- // enum
- dwFlags |= SOAPFLAG_READYSTATE;
-
- // enums must not have child elements
- m_bNullCheck = true;
-
- // enums must be specified
- m_bCharacters = true;
- }
-
- if (S_OK != PushState(pVal, pEntry->pChain, pEntry, dwFlags, 0, pEntry->pChain->nElements))
- {
- return E_OUTOFMEMORY;
- }
-
- return S_OK;
- }
-
- HRESULT ChainEntry(
- const ParseState& state,
- const wchar_t *wszNamespaceUri,
- int cchNamespaceUri,
- const wchar_t *wszLocalName,
- int cchLocalName,
- ISAXAttributes *pAttributes)
- {
- ATLENSURE_RETURN( state.pMap != NULL );
-
- // PAD is only supported on the client
- const _soapmap *pMap = state.pMap;
- if ((pMap->dwCallFlags & SOAPFLAG_CHAIN)==0)
- {
- return S_FALSE;
- }
-
- ATLENSURE_RETURN( pMap->dwCallFlags & SOAPFLAG_PAD );
- ATLASSUME( m_bClient == true );
- ATLENSURE_RETURN( pMap->nElements == 1 );
- const _soapmapentry *pEntries = pMap->pEntries;
- ATLENSURE_RETURN( pEntries != NULL );
-
- int nIndex;
- if (pEntries[0].dwFlags & SOAPFLAG_OUT)
- {
- nIndex = 0;
- }
- else
- {
- nIndex = 1;
- }
-
- const _soapmapentry *pEntry = &pEntries[nIndex];
- ATLENSURE_RETURN( pEntry->nHash != 0 );
- ATLENSURE_RETURN( pEntry->pChain != NULL );
-
- if (S_OK != PushState(state.pvElement, pEntry->pChain, pEntry, pEntry->dwFlags, 0, pEntry->pChain->nElements))
- {
- return E_OUTOFMEMORY;
- }
-
- return ProcessParams(wszNamespaceUri, cchNamespaceUri, wszLocalName, cchLocalName, pAttributes);
- }
-
- HRESULT IsNullEntry(const _soapmapentry *pEntry, ISAXAttributes *pAttributes)
- {
- ATLASSERT( pEntry != NULL );
- ATLASSERT( pAttributes != NULL );
-
- HRESULT hr = E_FAIL;
- bool bNull = false;
- const wchar_t *wszNull = NULL;
- int cchNull = 0;
- hr = GetAttribute(pAttributes, L"nil", sizeof("nil")-1, &wszNull, &cchNull,
- XSI_NAMESPACEW, sizeof(XSI_NAMESPACEA)-1);
- if ((hr == S_OK) && (wszNull != NULL))
- {
- hr = AtlGetSAXValue(&bNull, wszNull, cchNull);
- if (hr == S_OK)
- {
- if (bNull != false)
- {
- if (pEntry->dwFlags & SOAPFLAG_NULLABLE)
- {
- m_bNullCheck = true;
-
- // push an emtpy state
- return PushState();
- }
-
- // non-nullable element
- return E_FAIL;
- }
- }
- }
-
- return S_FALSE;
- }
-
- HRESULT ProcessParams(
- const wchar_t *wszNamespaceUri,
- int cchNamespaceUri,
- const wchar_t *wszLocalName,
- int cchLocalName,
- ISAXAttributes *pAttributes)
- {
- (wszNamespaceUri);
- (cchNamespaceUri);
-
- if (m_stateStack.IsEmpty())
- {
- if (m_dwState == SOAP_HEADERS)
- {
- return CheckMustUnderstandHeader(pAttributes);
- }
-
- return E_FAIL;
- }
-
- ParseState &state = GetState();
-
- ATLASSERT( state.pvElement != NULL );
- HRESULT hr = E_FAIL;
- const _soapmapentry *pEntry = NULL;
-
- // if array element
- if (state.dwFlags & (SOAPFLAG_FIXEDARR | SOAPFLAG_DYNARR))
- {
- hr = ValidateArrayEntry(state, wszLocalName, cchLocalName);
-
- if (SUCCEEDED(hr))
- {
- pEntry = state.pEntry;
- }
- else
- {
- return hr;
- }
- }
- else // not an array element
- {
- // special-case for PAD with type=
- hr = ChainEntry(state, wszNamespaceUri, cchNamespaceUri,
- wszLocalName, cchLocalName, pAttributes);
-
- if (hr == S_FALSE)
- {
- hr = GetElementEntry(state, wszNamespaceUri, wszLocalName, cchLocalName, pAttributes, &pEntry);
- if (hr != S_OK)
- {
- if (hr == S_FALSE)
- {
- hr = S_OK;
- }
- else if (m_dwState == SOAP_HEADERS)
- {
- hr = CheckMustUnderstandHeader(pAttributes);
- }
- return hr;
- }
-
- ATLASSERT( pEntry != NULL );
- }
- else
- {
- return hr;
- }
- }
-
- hr = IsNullEntry(pEntry, pAttributes);
- if (hr != S_FALSE)
- {
- return hr;
- }
- hr = S_OK;
- ATLENSURE_RETURN(pEntry);
- // if is array
- if (((pEntry->pDims != NULL) || (pEntry->dwFlags & (SOAPFLAG_FIXEDARR | SOAPFLAG_DYNARR))) &&
- ((state.dwFlags & (SOAPFLAG_FIXEDARR | SOAPFLAG_DYNARR)) == 0))
- {
- // get SOAP section-5 info (if it is there)
- return GetSection5Info(state, pEntry, pAttributes);
- }
- else
- {
- // if it is a simple type, push a new (ready) state on the stack
- void *pVal;
- if (state.dwFlags & (SOAPFLAG_FIXEDARR | SOAPFLAG_DYNARR))
- {
- pVal = UpdateArray(state, pEntry);
- ATLASSERT( pVal != NULL );
- }
- else
- {
- pVal = (((unsigned char *)state.pvElement)+pEntry->nOffset);
- }
-
- if (IsRpcEncoded() != false)
- {
- // check for href
- // we ONLY do this for rpc/encoded (required for interop)
- // NOTE: ATL Server does not support object graphs, so
- // only single-reference elements are allowed
- hr = CheckHref(pEntry, pVal, pAttributes);
- if (hr != S_FALSE)
- {
- return hr;
- }
- hr = S_OK;
- }
-
- if (pEntry->nVal != SOAPTYPE_UNK)
- {
- // simple types should not have child elements
- m_bNullCheck = true;
-
- // if it is a string
- if ((pEntry->nVal == SOAPTYPE_STRING) || (pEntry->nVal == SOAPTYPE_BASE64BINARY))
- {
- hr = ProcessString(pEntry, pVal);
- }
- else
- {
- // expect characters for all non-string simple types
- m_bCharacters = true;
-
- // basic simple type
- if (S_OK != PushState(pVal, NULL, pEntry, SOAPFLAG_READYSTATE | pEntry->dwFlags))
- {
- hr = E_OUTOFMEMORY;
- }
- }
- }
- else
- {
- hr = ProcessUDT(pEntry, pVal);
- if (pEntry->dwFlags & (SOAPFLAG_DYNARRWRAPPER))
- {
- // We're moving to the **first** entry in the dynamic array wrapper.
- // We know it is the first entry because the dynamic array wrapper is created
- // by sproxy and it guarantees this layouts.
- ++m_nDepth;
- ProcessParams (wszNamespaceUri, cchNamespaceUri, pEntry->pChain->pEntries[0].wszField,
- pEntry->pChain->pEntries[0].cchField, pAttributes);
- }
- }
- }
-
- return hr;
- }
-
- size_t GetSizeIsValue(void *pvParam, const _soapmap *pMap, const _soapmapentry *pEntry)
- {
- ATLENSURE( pvParam != NULL );
- ATLENSURE( pMap != NULL );
- ATLENSURE( pEntry != NULL );
-
- int nSizeIs = pEntry->nSizeIs;
- size_t nOffset = pMap->pEntries[nSizeIs].nOffset;
- void *pVal = ((unsigned char *)pvParam)+nOffset;
-
- __int64 nVal = 0;
- switch(pMap->pEntries[nSizeIs].nVal)
- {
- case SOAPTYPE_INTEGER:
- case SOAPTYPE_NONPOSITIVEINTEGER:
- case SOAPTYPE_NEGATIVEINTEGER:
- case SOAPTYPE_LONG:
- nVal = *((__int64 *)pVal);
- break;
- case SOAPTYPE_INT:
- nVal = *((int *)pVal);
- break;
- case SOAPTYPE_SHORT:
- nVal = *((short *)pVal);
- break;
- case SOAPTYPE_BYTE:
- nVal = *((char *)pVal);
- break;
- case SOAPTYPE_POSITIVEINTEGER:
- case SOAPTYPE_NONNEGATIVEINTEGER:
- case SOAPTYPE_UNSIGNEDLONG:
- unsigned __int64 n;
- n = *((unsigned __int64 *)pVal);
- if (n > _I64_MAX)
- {
- // come on ...
- nVal = 0;
- }
- else
- {
- nVal = (__int64)n;
- }
- break;
- case SOAPTYPE_UNSIGNEDINT:
- nVal = *((unsigned int *)pVal);
- break;
- case SOAPTYPE_UNSIGNEDSHORT:
- nVal = *((unsigned short *)pVal);
- break;
- case SOAPTYPE_UNSIGNEDBYTE:
- nVal = *((unsigned char *)pVal);
- break;
- default:
- nVal = 0;
- }
-
- if (nVal < 0)
- {
- nVal = 0;
- }
-
- return (size_t) nVal;
- }
-
- HRESULT GenerateArrayInfo(const _soapmapentry *pEntry, const int *pDims, IWriteStream *pStream)
- {
- ATLENSURE_RETURN( pEntry != NULL );
- ATLENSURE_RETURN( pStream != NULL );
-
- HRESULT hr = S_OK;
- if (pEntry->nVal != SOAPTYPE_UNK)
- {
- // xsd type
- hr = pStream->WriteStream(" soapenc:arrayType=\"xsd:",
- sizeof(" soapenc:arrayType=\"xsd:")-1, NULL);
- }
- else
- {
- ATLENSURE_RETURN( pEntry->pChain != NULL );
-
- hr = pStream->WriteStream(" xmlns:q1=\"", sizeof(" xmlns:q1=\"")-1, NULL);
- if (SUCCEEDED(hr))
- {
- if (pEntry->pChain->szNamespace != NULL)
- {
- hr = pStream->WriteStream(pEntry->pChain->szNamespace, pEntry->pChain->cchNamespace, NULL);
- }
- else
- {
- hr = pStream->WriteStream(GetNamespaceUriA(), -1, NULL);
- }
- if (SUCCEEDED(hr))
- {
- hr = pStream->WriteStream("\"", 1, NULL);
- if (SUCCEEDED(hr))
- {
- hr = pStream->WriteStream(" soapenc:arrayType=\"q1:",
- sizeof(" soapenc:arrayType=\"q1:")-1, NULL);
- }
- }
- }
- }
-
- if (FAILED(hr))
- {
- return hr;
- }
-
- if (pEntry->nVal != SOAPTYPE_UNK)
- {
- hr = pStream->WriteStream(s_xsdNames[pEntry->nVal].szName ,
- s_xsdNames[pEntry->nVal].cchName, NULL);
- }
- else
- {
- ATLASSERT( pEntry->pChain != NULL );
-
- hr = pStream->WriteStream(pEntry->pChain->szName, pEntry->pChain->cchName, NULL);
- }
-
- if (FAILED(hr))
- {
- return hr;
- }
-
- hr = pStream->WriteStream("[", 1, NULL);
- if (FAILED(hr))
- {
- return hr;
- }
-
- CWriteStreamHelper s( pStream );
- for (int i=1; i<=pDims[0]; i++)
- {
- if (!s.Write(pDims[i]) ||
- ((i < pDims[0]) && (S_OK != pStream->WriteStream(", ", 2, NULL))))
- {
- return E_FAIL;
- }
- }
-
- hr = pStream->WriteStream("]\"", 2, NULL);
- if (FAILED(hr))
- {
- return hr;
- }
-
- return S_OK;
- }
-
- HRESULT GenerateXSDWrapper(bool bStart, int nVal, bool bNull, IWriteStream *pStream)
- {
- ATLENSURE_RETURN( pStream != NULL );
-
- HRESULT hr = pStream->WriteStream((bStart != false) ? "<" : "</",
- (bStart != false) ? 1 : 2, NULL);
- if (SUCCEEDED(hr))
- {
- hr = pStream->WriteStream(s_xsdNames[nVal].szName,
- s_xsdNames[nVal].cchName, NULL);
- if ((bNull != false) && (SUCCEEDED(hr)))
- {
- hr = pStream->WriteStream(" xsi:nil=\"1\"", sizeof(" xsi:nil=\"1\"")-1, NULL);
- }
- if (SUCCEEDED(hr))
- {
- hr = pStream->WriteStream(">", 1, NULL);
- }
- }
-
- return hr;
- }
-
- HRESULT GenerateGenericWrapper(bool bStart, const _soapmap *pMap, IWriteStream *pStream)
- {
- ATLENSURE_RETURN( pStream != NULL );
- ATLENSURE_RETURN( pMap != NULL );
-
- HRESULT hr = pStream->WriteStream((bStart != false) ? "<" : "</",
- (bStart != false) ? 1 : 2, NULL);
- if (SUCCEEDED(hr))
- {
- hr = pStream->WriteStream(pMap->szName, pMap->cchName, NULL);
- if (SUCCEEDED(hr))
- {
- hr = pStream->WriteStream(">", 1, NULL);
- }
- }
-
- return hr;
- }
-
- HRESULT GetArrayInformation(
- IWriteStream *pStream,
- const _soapmap *pMap,
- const _soapmapentry *pEntry,
- void *pvParam,
- size_t &nCnt,
- size_t &nElementSize)
- {
- ATLENSURE_RETURN( pStream != NULL );
- ATLENSURE_RETURN( pMap != NULL );
- ATLENSURE_RETURN( pEntry != NULL );
- ATLENSURE_RETURN( pvParam != NULL );
-
- const int *pDims = NULL;
- int arrDims[2] = { 0 };
-
- if (pEntry->dwFlags & SOAPFLAG_FIXEDARR)
- {
- pDims = pEntry->pDims;
- }
- else
- {
- ATLASSERT( pEntry->dwFlags & SOAPFLAG_DYNARR );
- nCnt = GetSizeIsValue(pvParam, pMap, pEntry);
-
- if (nCnt == 0)
- {
- // array size should only be zero if array is NULL
- // did you forget to set the array size?
- ATLASSERT( FALSE );
- return E_FAIL;
- }
-
- arrDims[0] = 1;
- arrDims[1] = (int) nCnt;
-
- pDims = arrDims;
- }
-
- // output array information
- HRESULT hr = GenerateArrayInfo(pEntry, pDims, pStream);
- if (FAILED(hr))
- {
- return hr;
- }
- if (SUCCEEDED(hr))
- {
- nCnt = AtlSoapGetArrayDims(pDims);
-
- // did you forget to set the size_is value?
- ATLASSERT( nCnt != 0 );
-
- if (pEntry->nVal != SOAPTYPE_UNK)
- {
- nElementSize = AtlSoapGetElementSize((SOAPTYPES) pEntry->nVal);
- }
- else
- {
- ATLENSURE_RETURN( pEntry->pChain != NULL );
-
- nElementSize = pEntry->pChain->nElementSize;
- }
- }
-
- return hr;
- }
-
- HRESULT GenerateEnum(IWriteStream *pStream, void *pVal, const _soapmapentry *pEntry, bool bArray)
- {
- ATLENSURE_RETURN( pStream != NULL );
- ATLENSURE_RETURN( pVal != NULL );
- ATLENSURE_RETURN( pEntry != NULL );
-
- int nVal = *((int *)pVal);
- const _soapmapentry *pEnumEntries = pEntry->pChain->pEntries;
-
- ATLENSURE_RETURN( pEnumEntries != NULL );
- size_t j;
- HRESULT hr = E_FAIL;
- for (j=0; pEnumEntries[j].nHash != 0; j++)
- {
- if (nVal == pEnumEntries[j].nVal)
- {
- hr = pStream->WriteStream(pEnumEntries[j].szField, pEnumEntries[j].cchField, NULL);
- if ((bArray != false) && (SUCCEEDED(hr)))
- {
- hr = GenerateGenericWrapper(false, pEntry->pChain, pStream);
- }
- break;
- }
- }
-
- return hr;
- }
-
- HRESULT GenerateHeaders(CResponseGenerator *pGenerator, const _soapmap *pMap, IWriteStream *pStream)
- {
- ATLENSURE_RETURN( pStream != NULL );
- ATLENSURE_RETURN( pMap != NULL );
-
- ATLENSURE_RETURN( pGenerator != NULL );
-
- DWORD dwIncludeFlags = SOAPFLAG_OUT;
- if (m_bClient != false)
- {
- dwIncludeFlags = SOAPFLAG_IN;
- }
-
- size_t nCnt = 0;
- for (size_t i=0; pMap->pEntries[i].nHash != 0; i++)
- {
- if (pMap->pEntries[i].dwFlags & dwIncludeFlags)
- {
- nCnt++;
- }
- }
-
- // no headers to be sent
- if (nCnt == 0)
- {
- return S_OK;
- }
-
- HRESULT hr = pGenerator->StartHeaders(pStream, pMap);
- if (SUCCEEDED(hr))
- {
- hr = GenerateResponseHelper(pGenerator, pMap, GetHeaderValue(), pStream);
- if (SUCCEEDED(hr))
- {
- hr = pGenerator->EndHeaders(pStream);
- }
- }
-
- return hr;
- }
-
- bool IsNullElement(const _soapmapentry *pEntry, void *pVal, DWORD dwExcludeFlags=0)
- {
- ATLENSURE( pEntry != NULL );
- ATLENSURE( pVal != NULL );
-
- bool bNull = false;
-
- DWORD dwFlags = pEntry->dwFlags & ~dwExcludeFlags;
-
- if (dwFlags & SOAPFLAG_DYNARR)
- {
- unsigned char **ppArr = (unsigned char **)pVal;
- if (*ppArr == NULL)
- {
- bNull = true;
- }
- }
- else if (pEntry->nVal == SOAPTYPE_STRING)
- {
- BSTR *pBSTR = (BSTR *)pVal;
- if (*pBSTR == NULL)
- {
- bNull = true;
- }
- }
- else if ((pEntry->nVal == SOAPTYPE_BASE64BINARY) || (pEntry->nVal == SOAPTYPE_HEXBINARY))
- {
- if (((ATLSOAP_BLOB *)pVal)->data == NULL)
- {
- bNull = true;
- }
- }
-
- return bNull;
- }
-
- HRESULT GenerateNull(IWriteStream *pStream)
- {
- ATLENSURE_RETURN( pStream != NULL );
- return pStream->WriteStream(" xsi:nil=\"1\"/>", sizeof(" xsi:nil=\"1\"/>")-1, NULL);
- }
-
- HRESULT GenerateResponseHelper(CResponseGenerator *pGenerator, const _soapmap *pMap, void *pvParam, IWriteStream *pStream,
- bool bArrayElement = false)
- {
- ATLENSURE_RETURN( pGenerator != NULL );
- ATLENSURE_RETURN( pMap != NULL );
- ATLENSURE_RETURN( pStream != NULL );
-
- HRESULT hr = S_OK;
-
- if ((bArrayElement != false) &&
- ((pMap->dwCallFlags & SOAPFLAG_PAD)==0))
- {
- hr = pGenerator->StartMap(pStream, pMap, m_bClient);
- if (FAILED(hr))
- {
- return hr;
- }
- }
-
- ATLENSURE_RETURN( pMap->pEntries != NULL );
-
- const _soapmapentry *pEntries = pMap->pEntries;
- size_t i;
-
- DWORD dwIncludeFlags;
- DWORD dwExcludeFlags;
- if (m_bClient != false)
- {
- dwIncludeFlags = SOAPFLAG_IN;
- dwExcludeFlags = SOAPFLAG_OUT;
- }
- else
- {
- dwIncludeFlags = SOAPFLAG_OUT;
- dwExcludeFlags = SOAPFLAG_IN;
- }
-
- for (i=0; pEntries[i].nHash != 0; i++)
- {
- if (((pEntries[i].dwFlags & dwIncludeFlags) ||
- ((pEntries[i].dwFlags & dwExcludeFlags)==0)) &&
- ((pEntries[i].dwFlags & SOAPFLAG_NOMARSHAL)==0))
- {
- hr = pGenerator->StartEntry(pStream, pMap, &pEntries[i]);
- if (FAILED(hr))
- {
- return hr;
- }
-
- size_t nElementSize = 0;
- size_t nCnt = 1;
-
- ATLASSERT( pvParam != NULL );
-
- void *pvCurrent = ((unsigned char *)pvParam)+pEntries[i].nOffset;
-
- if (IsNullElement(&pEntries[i], pvCurrent))
- {
- hr = GenerateNull(pStream);
- if (SUCCEEDED(hr))
- {
- continue;
- }
- return hr;
- }
-
- bool bArray = (pEntries[i].dwFlags & (SOAPFLAG_FIXEDARR | SOAPFLAG_DYNARR)) != 0;
- if (bArray != false)
- {
- hr = GetArrayInformation(pStream, pMap, &pEntries[i], pvParam, nCnt, nElementSize);
- }
-
- hr = pStream->WriteStream(">", 1, NULL);
- if (FAILED(hr))
- {
- return hr;
- }
-
- for (size_t nElement=0; nElement<nCnt; nElement++)
- {
- void *pVal;
-
- // get updated value
- if (bArray != false)
- {
- if (pEntries[i].dwFlags & SOAPFLAG_FIXEDARR)
- {
- unsigned char *ppArr = (unsigned char *)pvCurrent;
- pVal = ppArr+(nElement*nElementSize);
- }
- else
- {
- ATLASSERT( pEntries[i].dwFlags & SOAPFLAG_DYNARR );
-
- unsigned char **ppArr = (unsigned char **)pvCurrent;
- pVal = (*ppArr)+(nElement*nElementSize);
- }
- }
- else
- {
- pVal = pvCurrent;
- }
-
- if (pEntries[i].nVal != SOAPTYPE_UNK)
- {
- bool bNull = false;
- if (bArray != false)
- {
- bNull = IsNullElement(&pEntries[i], pVal, SOAPFLAG_DYNARR | SOAPFLAG_FIXEDARR);
- hr = GenerateXSDWrapper(true, pEntries[i].nVal, bNull, pStream);
- if (FAILED(hr))
- {
- return hr;
- }
- }
- if (bNull == false)
- {
- hr = AtlSoapGenElementValue(pVal, pStream, (SOAPTYPES) pEntries[i].nVal, GetMemMgr());
- }
- if ((SUCCEEDED(hr)) && (bArray != false))
- {
- hr = GenerateXSDWrapper(false, pEntries[i].nVal, false, pStream);
- }
-
- if (FAILED(hr))
- {
- return hr;
- }
- }
- else
- {
- ATLASSERT( pEntries[i].pChain != NULL );
-
- if (pEntries[i].pChain->mapType != SOAPMAP_ENUM)
- {
- // struct
- hr = GenerateResponseHelper(pGenerator, pEntries[i].pChain, pVal, pStream, bArray);
- }
- else
- {
- if (bArray != false)
- {
- hr = GenerateGenericWrapper(true, pEntries[i].pChain, pStream);
- if (FAILED(hr))
- {
- return hr;
- }
- }
-
- hr = GenerateEnum(pStream, pVal, &pEntries[i], bArray);
- }
- }
- }
-
- // output element close
- if (SUCCEEDED(hr))
- {
- hr = pGenerator->EndEntry(pStream, pMap, &pEntries[i]);
- }
- }
-
- if (FAILED(hr))
- {
- return hr;
- }
- }
-
- if ((bArrayElement != false) &&
- ((pMap->dwCallFlags & SOAPFLAG_PAD)==0))
- {
- // output type name
- hr = pGenerator->EndMap(pStream, pMap, m_bClient);
- }
-
- return hr;
- }
-
- void CleanupHelper(const _soapmap *pMap, void *pvParam)
- {
- ATLENSURE( pMap != NULL );
- ATLENSURE( pMap->pEntries != NULL );
-
- if (pvParam == NULL)
- {
- return;
- }
-
- const _soapmapentry *pEntries = pMap->pEntries;
- size_t i;
-
- for (i=0; pEntries[i].nHash != 0; i++)
- {
- if ((m_bClient != false) && ((pEntries[i].dwFlags & SOAPFLAG_OUT)==0))
- {
- // skip in-only headers on the client
- continue;
- }
-
- void *pvCheck = ((unsigned char *)pvParam)+pEntries[i].nOffset;
- if (IsNullElement(&pEntries[i], pvCheck))
- {
- continue;
- }
-
- size_t nElementSize = 0;
- size_t nCnt = 1;
-
- const int *pDims = NULL;
- int arrDims[2] = { 0 };
-
- bool bArray = (pEntries[i].dwFlags & (SOAPFLAG_FIXEDARR | SOAPFLAG_DYNARR)) != 0;
-
- if (bArray != false)
- {
- if (pEntries[i].dwFlags & SOAPFLAG_FIXEDARR)
- {
- pDims = pEntries[i].pDims;
- }
- else
- {
- ATLASSERT( pEntries[i].dwFlags & SOAPFLAG_DYNARR );
- nCnt = GetSizeIsValue(pvParam, pMap, &pEntries[i]);
-
- arrDims[0] = 1;
- arrDims[1] = (int) nCnt;
-
- pDims = arrDims;
- }
-
- nCnt = AtlSoapGetArrayDims(pDims);
-
- if (pEntries[i].nVal != SOAPTYPE_UNK)
- {
- nElementSize = AtlSoapGetElementSize((SOAPTYPES) pEntries[i].nVal);
- }
- else
- {
- ATLENSURE( pEntries[i].pChain != NULL );
-
- nElementSize = pEntries[i].pChain->nElementSize;
- }
- }
-
- void *pvCurrent = ((unsigned char *)pvParam)+pEntries[i].nOffset;
-
- for (size_t nElement=0; nElement<nCnt; nElement++)
- {
- void *pVal;
-
- // get updated value
- if (bArray != false)
- {
- if (pEntries[i].dwFlags & SOAPFLAG_FIXEDARR)
- {
- unsigned char *ppArr = (unsigned char *)pvCurrent;
- pVal = ppArr+(nElement*nElementSize);
- }
- else
- {
- ATLASSERT( pEntries[i].dwFlags & SOAPFLAG_DYNARR );
-
- unsigned char **ppArr = (unsigned char **)pvCurrent;
- if (*ppArr == NULL)
- {
- break;
- }
- pVal = (*ppArr)+(nElement*nElementSize);
- }
- }
- else
- {
- pVal = pvCurrent;
- }
-
- if (pEntries[i].nVal != SOAPTYPE_UNK)
- {
- AtlSoapCleanupElement(pVal, (SOAPTYPES) pEntries[i].nVal, GetMemMgr());
- }
- else
- {
- ATLENSURE( pEntries[i].pChain != NULL );
-
- if (pEntries[i].pChain->mapType != SOAPMAP_ENUM)
- {
- CleanupHelper(pEntries[i].pChain, pVal);
- }
- }
- }
-
- if (pEntries[i].dwFlags & SOAPFLAG_DYNARR)
- {
- // free it
- unsigned char **ppArr = (unsigned char **)pvCurrent;
-
- ATLENSURE( ppArr != NULL );
-
- if (*ppArr != NULL)
- {
- m_pMemMgr->Free(*ppArr);
- *ppArr = NULL;
- }
- }
- }
- }
-
- const _soapmap * GetSoapMapFromName(
- const wchar_t * wszName,
- int cchName = -1,
- const wchar_t * wszNamespaceUri = NULL,
- int cchNamespaceUri = -1,
- int *pnVal = NULL,
- bool bHeader = false)
- {
- (cchNamespaceUri);
-
- const _soapmap ** pEntry = NULL;
-
- if (bHeader == false)
- {
- pEntry = GetFunctionMap();
- }
- else
- {
- pEntry = GetHeaderMap();
- }
-
- if (pEntry == NULL)
- {
- return NULL;
- }
-
- if (cchName < 0)
- {
- cchName = (int)wcslen(wszName);
- }
- if ((cchNamespaceUri < 0) && (wszNamespaceUri != NULL))
- {
- cchNamespaceUri = (int)wcslen(wszNamespaceUri);
- }
-
- ULONG nFunctionHash = AtlSoapHashStr(wszName, cchName);
- ULONG nNamespaceHash = wszNamespaceUri ? AtlSoapHashStr(wszNamespaceUri, cchNamespaceUri) : 0;
-
- int i;
- for (i=0; pEntry[i] != NULL; i++)
- {
- if ((IsEqualStringHash(wszName, cchName, nFunctionHash,
- pEntry[i]->wszName, pEntry[i]->cchWName, pEntry[i]->nHash) != FALSE) &&
- (!wszNamespaceUri ||
- IsEqualStringHash(wszNamespaceUri, cchNamespaceUri, nNamespaceHash,
- pEntry[i]->wszNamespace, pEntry[i]->cchNamespace, pEntry[i]->nNamespaceHash) != FALSE))
- {
- break;
- }
- }
-
- if (pnVal != NULL)
- {
- *pnVal = i;
- }
- return pEntry[i];
- }
-
- HRESULT CheckEndElement(const ParseState& state)
- {
- // check for all elements
- if (state.nElement == state.nExpectedElements)
- {
- return S_OK;
- }
-
- // error check for fixed arrays
- if (state.dwFlags & SOAPFLAG_FIXEDARR)
- {
- return E_FAIL;
- }
-
- // check for dynamic arrays
- if (state.dwFlags & SOAPFLAG_DYNARR)
- {
- // check for dynamic arrays with known size
- // (from soap:arrayType attribute)
- if ((state.dwFlags & SOAPFLAG_UNKSIZE)==0)
- {
- return E_FAIL;
- }
- }
-
- DWORD dwIncludeFlags;
- DWORD dwExcludeFlags;
-
- if (m_bClient != false)
- {
- dwIncludeFlags = SOAPFLAG_OUT;
- dwExcludeFlags = SOAPFLAG_IN;
- }
- else
- {
- dwIncludeFlags = SOAPFLAG_IN;
- dwExcludeFlags = SOAPFLAG_OUT;
- }
-
- if (state.pMap != NULL)
- {
- // ensure all omitted elements were nullable elements or nomarshal elements
- const _soapmapentry *pEntries = state.pMap->pEntries;
- for (size_t i=0; pEntries[i].nHash != 0; i++)
- {
- if ((pEntries[i].dwFlags & dwIncludeFlags) ||
- ((pEntries[i].dwFlags & dwExcludeFlags)==0))
- {
- if (state.vec.GetBit(i) == false)
- {
- if (((pEntries[i].dwFlags & (SOAPFLAG_NULLABLE | SOAPFLAG_NOMARSHAL))==0) && (pEntries[i].nVal != SOAPTYPE_UNK))
- {
- ATLTRACE( _T("ATLSOAP: CSoapRootHandler::CheckEndElement -- invalid number of elements for parameter/field\r\n") );
- return E_FAIL;
- }
- }
- }
- }
- }
-
- return S_OK;
- }
-
- HRESULT CheckSoapHeaders(const ParseState &state)
- {
- DWORD dwIncludeFlags;
- DWORD dwExcludeFlags;
-
- if (m_bClient != false)
- {
- dwIncludeFlags = SOAPFLAG_OUT;
- dwExcludeFlags = SOAPFLAG_IN;
- }
- else
- {
- dwIncludeFlags = SOAPFLAG_IN;
- dwExcludeFlags = SOAPFLAG_OUT;
- }
-
- if (state.pMap != NULL)
- {
- ATLASSERT( state.pMap->mapType == SOAPMAP_HEADER );
-
- // ensure all omitted elements were nullable elements, nomarshal elements, or non-required elements
- const _soapmapentry *pEntries = state.pMap->pEntries;
- for (size_t i=0; pEntries[i].nHash != 0; i++)
- {
- if ((pEntries[i].dwFlags & dwIncludeFlags) ||
- ((pEntries[i].dwFlags & dwExcludeFlags)==0))
- {
- if (state.vec.GetBit(i) == false)
- {
- bool bNoOmit = (pEntries[i].dwFlags & (SOAPFLAG_NULLABLE | SOAPFLAG_NOMARSHAL))==0;
-
- if ((bNoOmit != false) ||
- ((bNoOmit != false) && (pEntries[i].dwFlags & SOAPFLAG_MUSTUNDERSTAND)))
- {
- ATLTRACE( _T("ATLSOAP: CSoapRootHandler::CheckSoapHeaders -- missing header\r\n") );
- return E_FAIL;
- }
- }
- }
- }
- }
-
- return S_OK;
- }
-
- HRESULT CheckEndHeaders(
- const wchar_t * wszNamespaceUri,
- int cchNamespaceUri,
- const wchar_t * wszLocalName,
- int cchLocalName)
- {
- if (IsEqualElement(sizeof(SOAP_HEADERA)-1, SOAP_HEADERW,
- sizeof(SOAPENV_NAMESPACEA)-1, SOAPENV_NAMESPACEW,
- cchLocalName, wszLocalName,
- cchNamespaceUri, wszNamespaceUri))
- {
- m_dwState = SOAP_HEADERS_DONE;
- return S_OK;
- }
-
- // some sort of error
- ATLTRACE( _T("ATLSOAP: CSoapRootHandler::endElement -- invalid SOAP message format while processing headers.\r\n" ) );
-
- return E_FAIL;
- }
-
-protected:
-
- ISAXXMLReader * SetReader(ISAXXMLReader *pReader)
- {
- ISAXXMLReader *pPrevRdr = m_spReader;
- m_spReader = pReader;
-
- return pPrevRdr;
- }
-
- ISAXXMLReader * GetReader()
- {
- return m_spReader;
- }
-
- HRESULT SetSoapMapFromName(
- const wchar_t * wszName,
- int cchName = -1,
- const wchar_t * wszNamespaceUri = NULL,
- int cchNamespaceUri = -1,
- bool bHeader = false)
- {
- ATLENSURE_RETURN( wszName != NULL );
-
- int nVal;
- const _soapmap *pMap = NULL;
- if (m_stateStack.GetCount() != 0)
- {
- ATLASSUME( m_stateStack[0].pMap != NULL );
- nVal = (int) m_stateStack[0].nAllocSize;
- ATLASSERT( GetFunctionMap() != NULL );
- pMap = GetFunctionMap()[nVal];
- }
- else
- {
- pMap = GetSoapMapFromName(wszName, cchName,
- wszNamespaceUri, cchNamespaceUri, &nVal, bHeader);
- }
-
- if (pMap == NULL)
- {
- ATLTRACE( _T("ATLSOAP: CSoapRootHandler::SetSoapMapFromName -- _soapmap not found for: %.*ws, with namespace %.*ws\r\n"),
- (int)wcslen(wszName), wszName, wszNamespaceUri ? (int)wcslen(wszNamespaceUri) : 0, wszNamespaceUri ? wszNamespaceUri : L"");
-
- return E_FAIL;
- }
-
- HRESULT hr = E_OUTOFMEMORY;
-
- // allocate the parameter struct
-
- void *pvParam = NULL;
- if (bHeader != false)
- {
- pvParam = GetHeaderValue();
- }
- else
- {
- if (m_bClient == false)
- {
- m_pvParam = m_pMemMgr->Allocate(pMap->nElementSize);
- }
- pvParam = m_pvParam;
- }
-
- if (pvParam != NULL)
- {
- if (bHeader == false)
- {
- memset(pvParam, 0x00, pMap->nElementSize);
- }
-
- // push initial state
-
- if (m_stateStack.GetCount() != 0)
- {
- m_stateStack.RemoveAll();
- }
-
- hr = PushState(pvParam, pMap, NULL, 0, nVal, pMap->nElements);
-
- if (FAILED(hr))
- {
- if ((m_bClient == false) && (bHeader == false))
- {
- m_pMemMgr->Free(pvParam);
- }
- }
- }
-
-#ifdef _DEBUG
- if (hr == E_OUTOFMEMORY)
- {
- ATLTRACE( _T("ATLSOAP: CSoapRootHandler::SetSoapMapFromName -- out of memory.\r\n" ) );
- }
-#endif // _DEBUG
-
- return hr;
- }
-
- // implementation
- virtual const _soapmap ** GetFunctionMap() = 0;
- virtual const _soapmap ** GetHeaderMap() = 0;
- virtual const wchar_t * GetNamespaceUri() = 0;
- virtual const char * GetServiceName() = 0;
- virtual const char * GetNamespaceUriA() = 0;
- virtual HRESULT CallFunction(
- void *pvParam,
- const wchar_t *wszLocalName, int cchLocalName,
- size_t nItem) = 0;
- virtual void * GetHeaderValue() = 0;
-
-public:
-
- CSoapRootHandler(ISAXXMLReader *pReader = NULL)
- : m_pMemMgr(&m_crtHeap), m_spReader(pReader), m_bClient(false),
- m_nState(0), m_pvParam(NULL), m_nDepth(0)
- {
- InitHandlerState();
- }
- virtual ~CSoapRootHandler()
- {
- m_skipHandler.DetachParent();
- }
-
- IAtlMemMgr * SetMemMgr(IAtlMemMgr *pMemMgr)
- {
- IAtlMemMgr *pPrevMgr = m_pMemMgr;
- m_pMemMgr = pMemMgr;
-
- return pPrevMgr;
- }
-
- IAtlMemMgr * GetMemMgr()
- {
- return m_pMemMgr;
- }
-
- // override this function to do SOAP Fault handling
- virtual HRESULT SoapFault(
- SOAP_ERROR_CODE /*errCode*/,
- const wchar_t * /*wszDetail*/,
- int /*cchDetail*/)
- {
- if (m_bClient != false)
- {
- return S_OK;
- }
-
- // SOAP servers must implement this function
- ATLASSERT( FALSE );
- return E_FAIL;
- }
-
- //
- // implementation
- //
-
- void InitHandlerState()
- {
- m_bNullCheck = false;
- m_bCharacters = false;
- m_bChildCheck = false;
- m_dwState = SOAP_START;
- }
- HRESULT __stdcall startDocument()
- {
- InitHandlerState();
- return S_OK;
- }
-
- HRESULT __stdcall startElement(
- const wchar_t *wszNamespaceUri,
- int cchNamespaceUri,
- const wchar_t *wszLocalName,
- int cchLocalName,
- const wchar_t * wszQName,
- int cchQName,
- ISAXAttributes *pAttributes)
- {
- if (m_bNullCheck || m_bCharacters)
- {
- // make sure elements that aren't supposed to have child elements
- // do not have child elements, and where we were expecting
- // characters, we got them
- return E_FAIL;
- }
-
- m_bChildCheck = false;
- ++m_nDepth;
-
- HRESULT hr = S_OK;
- switch (m_dwState)
- {
- case SOAP_PARAMS: case SOAP_HEADERS:
- {
- hr = ProcessParams(wszNamespaceUri, cchNamespaceUri, wszLocalName,
- cchLocalName, pAttributes);
-
- break;
- }
- case SOAP_START: case SOAP_ENVELOPE: case SOAP_HEADERS_DONE:
- {
- ULONG nNamespaceHash = AtlSoapHashStr(wszNamespaceUri,
- cchNamespaceUri);
- if (nNamespaceHash != SOAP_ENV)
- {
- ATLTRACE( _T("ATLSOAP: CSoapRootHandler::startElement -- incorrect SOAP-ENV namespace.\r\n" ) );
-
- return E_FAIL;
- }
-
- ULONG nElementHash = AtlSoapHashStr(wszLocalName, cchLocalName);
-
- if (nElementHash == ENVELOPE &&
- IsEqualElement(
- sizeof(SOAP_ENVELOPEA)-1, SOAP_ENVELOPEW,
- sizeof(SOAPENV_NAMESPACEA)-1, SOAPENV_NAMESPACEW,
- cchLocalName, wszLocalName,
- cchNamespaceUri, wszNamespaceUri))
- {
- // Envelope must be first element in package
-
- if (m_dwState != SOAP_START)
- {
- ATLTRACE( _T("ATLSOAP: CSoapRootHandler::startElement -- invalid SOAP message format: \"Envelope\" in unexpected location.\r\n" ) );
-
- hr = E_FAIL;
- }
- m_dwState = SOAP_ENVELOPE;
- }
- else if (nElementHash == HEADER &&
- IsEqualElement(sizeof(SOAP_HEADERA)-1, SOAP_HEADERW,
- sizeof(SOAPENV_NAMESPACEA)-1, SOAPENV_NAMESPACEW,
- cchLocalName, wszLocalName,
- cchNamespaceUri, wszNamespaceUri))
- {
- if (m_dwState != SOAP_ENVELOPE)
- {
- ATLTRACE( _T("ATLSOAP: CSoapRootHandler::startElement -- invalid SOAP message format: \"Headers\" in unexpected location.\r\n" ) );
-
- hr = E_FAIL;
- }
-
- m_dwState = SOAP_HEADERS;
- }
- else if (nElementHash == BODY &&
- IsEqualElement(sizeof(SOAP_BODYA)-1, SOAP_BODYW,
- sizeof(SOAPENV_NAMESPACEA)-1, SOAPENV_NAMESPACEW,
- cchLocalName, wszLocalName,
- cchNamespaceUri, wszNamespaceUri))
- {
- if (m_dwState == SOAP_START)
- {
- ATLTRACE( _T("ATLSOAP: CSoapRootHandler::startElement -- invalid SOAP message format: \"Body\" in unexpected location.\r\n" ) );
-
- hr = E_FAIL;
- }
- m_dwState = SOAP_BODY;
- }
-
- break;
- }
- case SOAP_BODY:
- {
- hr = DispatchSoapCall(wszNamespaceUri, cchNamespaceUri,
- wszLocalName, cchLocalName);
-
- m_dwState = SOAP_PARAMS;
-
- if (SUCCEEDED(hr))
- {
- if (GetState().pMap->dwCallFlags & SOAPFLAG_PAD)
- {
- hr = startElement(wszNamespaceUri, cchNamespaceUri,
- wszLocalName, cchLocalName, wszQName, cchQName,
- pAttributes);
- }
- }
-
- break;
- }
-
-#ifdef _DEBUG
-
- default:
- {
- // should never get here -- internal error
- ATLASSERT( FALSE );
- }
-
-#endif // _DEBUG
- }
-
- return hr;
- }
-
- HRESULT __stdcall characters(
- const wchar_t *wszChars,
- int cchChars)
- {
- m_bCharacters = false;
-
- // if it is a ready state, get the value
- if (m_stateStack.IsEmpty() == false)
- {
- ParseState& state = GetState();
- if ((state.dwFlags & SOAPFLAG_READYSTATE) &&
- ((state.dwFlags & SOAPFLAG_SIZEIS)==0)) // don't marshal struct size_is elements -- should be filled in by array marshaling code
- {
- if ((state.pMap == NULL) || (state.pMap->mapType != SOAPMAP_ENUM))
- {
- return AtlSoapGetElementValue(wszChars, cchChars,
- state.pvElement, (SOAPTYPES)state.pEntry->nVal, GetMemMgr());
- }
- else
- {
- // enum
-
- ATLASSERT( state.pMap != NULL );
- ATLASSERT( state.pMap->pEntries != NULL );
-
- ULONG nHash = AtlSoapHashStr(wszChars, cchChars);
- const _soapmapentry *pEntries = state.pMap->pEntries;
-
- size_t i;
- for (i=0; pEntries[i].nHash != 0; i++)
- {
- if ((nHash == pEntries[i].nHash) &&
- (cchChars == pEntries[i].cchField) &&
- (!wcsncmp(wszChars, pEntries[i].wszField, cchChars)))
- {
- break;
- }
- }
-
- if (pEntries[i].nHash != 0)
- {
- *((int *)state.pvElement) = pEntries[i].nVal;
- state.nElement++;
- return S_OK;
- }
-
- // no matching enum entry found
- ATLTRACE( _T("ATLSOAP: CSoapRootHandler::characters -- no matching enum entry found for: %.*ws.\r\n" ), cchChars, wszChars );
-
- return E_FAIL;
- }
- }
- }
-
- // otherwise, ignore
-
- return S_OK;
- }
-
- HRESULT __stdcall endElement(
- const wchar_t * wszNamespaceUri,
- int cchNamespaceUri,
- const wchar_t * wszLocalName,
- int cchLocalName,
- const wchar_t * /*wszQName*/,
- int /*cchQName*/)
- {
- static bool bDynArrWrapper = false;
- if (m_bCharacters)
- {
- return E_FAIL;
- }
-
- m_bNullCheck = false;
-
- if (m_stateStack.IsEmpty() != false)
- {
- return S_OK;
- }
-
- if (!bDynArrWrapper && (m_nState > 1))
- {
- ParseState prevState = m_stateStack.GetAt(m_nState - 1);
- ParseState curState = m_stateStack.GetAt(m_nState);
- if (prevState.dwFlags & SOAPFLAG_DYNARRWRAPPER)
- {
- bDynArrWrapper = true;
- endElement (wszNamespaceUri, cchNamespaceUri, curState.pEntry->wszField,
- curState.pEntry->cchField, NULL, 0);
- }
- }
- else
- {
- bDynArrWrapper = false;
- }
-
- --m_nDepth;
-
- const ParseState& state = GetState();
-
- if ((m_dwState == SOAP_HEADERS) && (m_stateStack.GetCount() == 1))
- {
- return CheckEndHeaders(wszNamespaceUri, cchNamespaceUri, wszLocalName, cchLocalName);
- }
-
- if (state.dwFlags & (SOAPFLAG_FIXEDARR | SOAPFLAG_DYNARR))
- {
- if (state.dwFlags & SOAPFLAG_READYSTATE)
- {
- PopState();
- }
-
- const ParseState& currstate = GetState();
- ATLENSURE_RETURN( currstate.pEntry != NULL );
-
- if (m_nDepth == (currstate.nDepth-1))
- {
- if (S_OK != CheckEndElement(currstate))
- {
- // invalid number of elements
- ATLTRACE( _T("ATLSOAP: CSoapRootHandler::endElement -- invalid number of array elements for array parameter %.*ws.\r\n"),
- currstate.pEntry->cchField, currstate.pEntry->wszField );
-
- return E_FAIL;
- }
-
- PopState();
- }
- }
- else
- {
- if (S_OK != CheckEndElement(state))
- {
- return E_FAIL;
- }
-
- PopState();
- }
-
- return S_OK;
- }
-
- HRESULT SetClientStruct(void *pvParam, int nMapIndex)
- {
- ATLENSURE_RETURN( pvParam != NULL );
- ATLENSURE_RETURN( nMapIndex >= 0 );
-
- // this is the params struct
- // store for later use
- m_pvParam = pvParam;
-
- const _soapmap ** pEntries = GetHeaderMap();
- ATLENSURE_RETURN( pEntries != NULL );
-
- // push header value
- return PushState(GetHeaderValue(), pEntries[nMapIndex], NULL, 0, nMapIndex, pEntries[nMapIndex]->nElements);
- }
-
- void ResetClientState(bool bFull = false)
- {
- m_stateStack.RemoveAll();
- m_nState = 0;
- if (bFull != false)
- {
- m_dwState = SOAP_START;
- m_pvParam = NULL;
- }
- }
-
- HRESULT CreateReader()
- {
- return m_spReader.CoCreateInstance(ATLS_SAXXMLREADER_CLSID, NULL, CLSCTX_INPROC_SERVER);
- }
-
- HRESULT InitializeSOAP(IServiceProvider *pProvider)
- {
- HRESULT hr = S_OK;
-
- if (m_spReader.p == NULL)
- {
- hr = E_FAIL;
- if (pProvider != NULL)
- {
- IAtlMemMgr *pMemMgr = NULL;
- hr = pProvider->QueryService(__uuidof(IAtlMemMgr),
- __uuidof(IAtlMemMgr), (void **)&pMemMgr);
- if ((SUCCEEDED(hr)) && (pMemMgr != NULL))
- {
- SetMemMgr(pMemMgr);
- }
-
- hr = pProvider->QueryService(__uuidof(ISAXXMLReader),
- __uuidof(ISAXXMLReader), (void **)&m_spReader);
- }
-
- if (FAILED(hr))
- {
- hr = CreateReader();
- }
- }
-
- if (SUCCEEDED(hr))
- {
- hr = m_spReader->putContentHandler(this);
- }
-
-#ifdef _DEBUG
- else
- {
- ATLTRACE( _T("ATLSOAP: CSoapRootHandler::InitializeSOAP -- failed to get SAXXMLReader.\r\n" ) );
- }
-#endif // _DEBUG
-
- return hr;
- }
-
- void UninitializeSOAP()
- {
- if (m_spReader.p != NULL)
- {
- m_spReader->putContentHandler(NULL);
- m_spReader.Release();
- }
- }
-
- virtual HRESULT DispatchSoapCall(const wchar_t *wszNamespaceUri,
- int cchNamespaceUri, const wchar_t *wszLocalName,
- int cchLocalName)
- {
- HRESULT hr = S_OK;
-
- if (m_stateStack.IsEmpty() == false)
- {
- ATLASSUME( m_stateStack[0].pMap != NULL );
-
- // check to see if all required and non-nullable SOAP headers were sent
- if (m_stateStack[0].pMap->mapType == SOAPMAP_HEADER)
- {
- hr = CheckSoapHeaders(m_stateStack[0]);
- }
- if (SUCCEEDED(hr))
- {
- hr = SetSoapMapFromName(wszLocalName, cchLocalName,
- wszNamespaceUri, cchNamespaceUri);
- }
- }
- else
- {
- // get the appropriate function map
- hr = SetSoapMapFromName(wszLocalName, cchLocalName,
- wszNamespaceUri, cchNamespaceUri);
-
- if (SUCCEEDED(hr))
- {
- // set the SOAP Header map for the function
- ATLASSUME( m_stateStack.IsEmpty() == false );
-
- const _soapmap **ppHeaderMap = GetHeaderMap();
- ATLENSURE_RETURN( ppHeaderMap != NULL );
-
- // create a temporary parse state for checking headers
- ParseState state;
- state.pMap = ppHeaderMap[m_stateStack[0].nAllocSize];
- ATLENSURE_RETURN( state.pMap != NULL );
-
- // check to see if all required and non-nullable SOAP headers were sent
- hr = CheckSoapHeaders(state);
- }
- }
-
- return hr;
- }
-
- virtual HRESULT BeginParse(IStream *pStream)
- {
- ATLASSERT( pStream != NULL );
-
- CComVariant varStream;
- varStream = static_cast<IUnknown*>(pStream);
-
- HRESULT hr = m_spReader->parse(varStream);
- if (SUCCEEDED(hr))
- {
- if (m_refMap.GetCount() != 0)
- {
- hr = E_FAIL;
- }
- }
- return hr;
- }
-
- HRESULT CallFunctionInternal()
- {
- HRESULT hr = E_FAIL;
- const ParseState& state = m_stateStack[0];
- hr = CallFunction(
- state.pvElement,
- state.pMap->wszName,
- state.pMap->cchWName,
- state.nAllocSize);
-
- return hr;
- }
-
- virtual HRESULT GenerateResponse(IWriteStream *pStream)
- {
- ATLASSUME( m_stateStack.IsEmpty() == false );
- ATLASSUME( m_stateStack[0].pMap != NULL );
- ATLASSUME( m_stateStack[0].pvElement != NULL );
-
- const ParseState& state = m_stateStack[0];
-
- const _soapmap *pHeaderMap = NULL;
- if (m_bClient == false)
- {
- const _soapmap **ppHeaderMap = GetHeaderMap();
- if (ppHeaderMap != NULL)
- {
- pHeaderMap = ppHeaderMap[state.nAllocSize];
- }
- }
- else
- {
- pHeaderMap = state.pMap;
- }
-
- const _soapmap *pFuncMap = NULL;
- if (m_bClient == false)
- {
- pFuncMap = state.pMap;
- }
- else
- {
- const _soapmap **ppFuncMap = GetFunctionMap();
- ATLENSURE_RETURN( ppFuncMap != NULL );
- pFuncMap = ppFuncMap[state.nAllocSize];
- }
-
- ATLENSURE_RETURN( pFuncMap != NULL );
-
- CRpcEncodedGenerator rpcGen;
- CPADGenerator padGen;
- CPIDGenerator pidGen;
-
- CResponseGenerator *pGenerator = NULL;
-
- if ((pFuncMap->dwCallFlags & (SOAPFLAG_RPC | SOAPFLAG_ENCODED)) == (SOAPFLAG_RPC | SOAPFLAG_ENCODED))
- {
- pGenerator = &rpcGen;
- }
- else if (pFuncMap->dwCallFlags & SOAPFLAG_PID)
- {
- ATLASSERT( (pFuncMap->dwCallFlags & (SOAPFLAG_DOCUMENT | SOAPFLAG_LITERAL)) == (SOAPFLAG_DOCUMENT | SOAPFLAG_LITERAL) );
- pGenerator = &pidGen;
- }
- else
- {
- ATLASSERT( (pFuncMap->dwCallFlags & (SOAPFLAG_DOCUMENT | SOAPFLAG_LITERAL)) == (SOAPFLAG_DOCUMENT | SOAPFLAG_LITERAL) );
- ATLASSERT( pFuncMap->dwCallFlags & SOAPFLAG_PAD );
- pGenerator = &padGen;
- }
-
- HRESULT hr = pGenerator->StartEnvelope(pStream);
- if (SUCCEEDED(hr))
- {
- // generate headers if necessary
- hr = GenerateHeaders(pGenerator, pHeaderMap, pStream);
- if (SUCCEEDED(hr))
- {
- hr = pGenerator->StartBody(pStream);
- if (SUCCEEDED(hr))
- {
- hr = GenerateResponseHelper(pGenerator, pFuncMap, m_pvParam, pStream, true);
- if (SUCCEEDED(hr))
- {
- hr = pGenerator->EndBody(pStream);
- if (SUCCEEDED(hr))
- {
- hr = pGenerator->EndEnvelope(pStream);
- }
- }
- }
- }
- }
-
- return hr;
- }
-
- virtual void Cleanup()
- {
- // cleanup headers
- CleanupHeaders();
-
- if ((m_stateStack.IsEmpty() == false) && (m_pvParam != NULL))
- {
- const _soapmap **ppFuncMap = GetFunctionMap();
- ATLENSURE( ppFuncMap != NULL );
-
- const _soapmap *pFuncMap = ppFuncMap[m_stateStack[0].nAllocSize];
- ATLENSURE( pFuncMap != NULL );
-
- CleanupHelper(pFuncMap, m_pvParam);
- if (m_bClient == false)
- {
- m_pMemMgr->Free(m_pvParam);
- m_stateStack.RemoveAll();
- }
- }
- }
-
- virtual void CleanupHeaders()
- {
- if (m_stateStack.IsEmpty() == false)
- {
- const _soapmap **ppHeaderMap = GetHeaderMap();
- ATLENSURE( ppHeaderMap != NULL );
-
- const _soapmap *pHeaderMap = ppHeaderMap[m_stateStack[0].nAllocSize];
- ATLENSURE( pHeaderMap != NULL );
-
- CleanupHelper(pHeaderMap, GetHeaderValue());
- }
- }
-
- void SetClient(bool bClient)
- {
- m_bClient = bClient;
- }
-
-}; // class CSoapRootHandler
-
-#define DECLARE_XSD_ENTRY( __name ) \
- { L ## __name, __name, sizeof(__name)-1 },
-
-__declspec(selectany) const CSoapRootHandler::XSDEntry CSoapRootHandler::s_xsdNames[] =
-{
- DECLARE_XSD_ENTRY("string")
- DECLARE_XSD_ENTRY("boolean")
- DECLARE_XSD_ENTRY("float")
- DECLARE_XSD_ENTRY("double")
- DECLARE_XSD_ENTRY("decimal")
- DECLARE_XSD_ENTRY("duration")
- DECLARE_XSD_ENTRY("hexBinary")
- DECLARE_XSD_ENTRY("base64Binary")
- DECLARE_XSD_ENTRY("anyURI")
- DECLARE_XSD_ENTRY("ID")
- DECLARE_XSD_ENTRY("IDREF")
- DECLARE_XSD_ENTRY("ENTITY")
- DECLARE_XSD_ENTRY("NOTATION")
- DECLARE_XSD_ENTRY("QName")
- DECLARE_XSD_ENTRY("normalizedString")
- DECLARE_XSD_ENTRY("token")
- DECLARE_XSD_ENTRY("language")
- DECLARE_XSD_ENTRY("IDREFS")
- DECLARE_XSD_ENTRY("ENTITIES")
- DECLARE_XSD_ENTRY("NMTOKEN")
- DECLARE_XSD_ENTRY("NMTOKENS")
- DECLARE_XSD_ENTRY("Name")
- DECLARE_XSD_ENTRY("NCName")
- DECLARE_XSD_ENTRY("integer")
- DECLARE_XSD_ENTRY("nonPositiveInteger")
- DECLARE_XSD_ENTRY("negativeInteger")
- DECLARE_XSD_ENTRY("long")
- DECLARE_XSD_ENTRY("int")
- DECLARE_XSD_ENTRY("short")
- DECLARE_XSD_ENTRY("byte")
- DECLARE_XSD_ENTRY("nonNegativeInteger")
- DECLARE_XSD_ENTRY("unsignedLong")
- DECLARE_XSD_ENTRY("unsignedInt")
- DECLARE_XSD_ENTRY("unsignedShort")
- DECLARE_XSD_ENTRY("unsignedByte")
- DECLARE_XSD_ENTRY("positiveInteger")
- DECLARE_XSD_ENTRY("dateTime")
- DECLARE_XSD_ENTRY("time")
- DECLARE_XSD_ENTRY("date")
- DECLARE_XSD_ENTRY("gMonth")
- DECLARE_XSD_ENTRY("gYearMonth")
- DECLARE_XSD_ENTRY("gYear")
- DECLARE_XSD_ENTRY("gMonthDay")
- DECLARE_XSD_ENTRY("gDay")
-};
-
-__declspec(selectany) CCRTHeap CSoapRootHandler::m_crtHeap;
-
-template <typename THandler>
-class CSoapHandler :
- public CSoapRootHandler,
- public CComObjectRootEx<CComMultiThreadModel>,
- public IRequestHandlerImpl<THandler>
-{
-protected:
-
- HTTP_CODE m_hcErr;
- CHttpResponse *m_pHttpResponse;
-
- // heap for SOAP requests
- CWin32Heap m_heap;
-
- // default heap is COM heap (SOAP Servers can double as COM objects)
- CComHeap m_comHeap;
-
-public:
-
- BEGIN_COM_MAP(CSoapHandler<THandler>)
- COM_INTERFACE_ENTRY(ISAXContentHandler)
- COM_INTERFACE_ENTRY(IRequestHandler)
- END_COM_MAP()
-
- CSoapHandler()
- :m_pHttpResponse(NULL), m_hcErr(HTTP_SUCCESS)
- {
- SetMemMgr(&m_comHeap);
- }
-
- void SetHttpError(HTTP_CODE hcErr)
- {
- m_hcErr = hcErr;
- }
-
- HRESULT SoapFault(
- SOAP_ERROR_CODE errCode,
- const wchar_t *wszDetail,
- int cchDetail)
- {
- ATLASSUME( m_pHttpResponse != NULL );
-
- SetHttpError(AtlsHttpError(500, SUBERR_NO_PROCESS));
-
- m_pHttpResponse->ClearHeaders();
- m_pHttpResponse->ClearContent();
- m_pHttpResponse->SetContentType("text/xml");
- m_pHttpResponse->SetStatusCode(500);
-
- CSoapFault fault;
- if (wszDetail != NULL)
- {
- if (cchDetail < 0)
- {
- cchDetail = (int) wcslen(wszDetail);
- }
-
- _ATLTRY
- {
- fault.m_strDetail.SetString(wszDetail, cchDetail);
- }
- _ATLCATCHALL()
- {
- ATLTRACE( _T("CSoapHandler::SoapFault -- out of memory.\r\n" ) );
-
- return E_OUTOFMEMORY;
- }
- }
-
- fault.m_soapErrCode = errCode;
- fault.GenerateFault(m_pHttpResponse);
- return S_OK;
- }
-
- HTTP_CODE InitializeHandler(AtlServerRequest *pRequestInfo, IServiceProvider *pProvider)
- {
- m_hcErr = IRequestHandlerImpl<THandler>::InitializeHandler(pRequestInfo, pProvider);
- if (m_hcErr == HTTP_SUCCESS)
- {
- HRESULT hr = InitializeSOAP(m_spServiceProvider);
- if (SUCCEEDED(hr))
- {
- // try to use the per-thread heap
- CIsapiWorker *pWorker = pRequestInfo->pExtension->GetThreadWorker();
- if (pWorker != NULL)
- {
- m_heap.Attach(pWorker->m_hHeap, false);
- SetMemMgr(&m_heap);
- }
-
- return m_hcErr;
- }
- }
-
- // some initialization failure
- CHttpResponse HttpResponse(pRequestInfo->pServerContext);
- m_pHttpResponse = &HttpResponse;
-
- SoapFault(SOAP_E_SERVER, NULL, 0);
-
- m_pHttpResponse = NULL;
-
- return m_hcErr;
- }
-
- HTTP_CODE HandleRequest(AtlServerRequest *pRequestInfo, IServiceProvider * /*pProvider*/)
- {
- // SOAPACTION header is required per the SOAP 1.1
- // mainly so firewalls can filter on it.
- char szBuf[ATL_URL_MAX_URL_LENGTH+1];
- szBuf[0] = '\0';
- DWORD dwLen = ATL_URL_MAX_URL_LENGTH;
- if ( m_spServerContext->GetServerVariable("HTTP_SOAPACTION", szBuf, &dwLen) != FALSE )
- {
- if ( dwLen >= 2 )
- {
- // drop the last "
- szBuf[dwLen-2] = '\0';
- char *szMethod = strrchr(szBuf, '#');
- if (szMethod != NULL)
- {
- _ATLTRY
- {
- // ignore return code here
- SetSoapMapFromName(CA2W( szMethod+1 ), -1, GetNamespaceUri(), -1, true);
- }
- _ATLCATCHALL()
- {
- return AtlsHttpError(500, ISE_SUBERR_OUTOFMEM);
- }
- }
- }
- }
- else
- {
- // SOAP requestion that use the HTTP transport
- // must have a SOAPACTION header.
- return HTTP_ERROR(500, ISE_SUBERR_SOAPNOSOAPACTION);
- }
-
- // set the header map
- CHttpResponse HttpResponse(pRequestInfo->pServerContext);
- m_pHttpResponse = &HttpResponse;
-
- CStreamOnServerContext s(pRequestInfo->pServerContext);
-
-#ifdef _DEBUG
-
- CSAXSoapErrorHandler err;
- GetReader()->putErrorHandler(&err);
-
-#endif // _DEBUG
-
- HRESULT hr = BeginParse(&s);
-
-#ifdef _DEBUG
- // release the error handler
- GetReader()->putErrorHandler(NULL);
-#endif // _DEBUG
-
- if (FAILED(hr))
- {
- Cleanup();
- if (m_hcErr == HTTP_SUCCESS)
- {
- SoapFault(SOAP_E_CLIENT, NULL, NULL);
- }
-
- return m_hcErr;
- }
-
- _ATLTRY
- {
- hr = CallFunctionInternal();
- }
- _ATLCATCHALL()
- {
- // cleanup before propagating user exception
- Cleanup();
- HttpResponse.Detach();
- _ATLRETHROW;
- }
-
- if (FAILED(hr))
- {
- Cleanup();
- HttpResponse.ClearHeaders();
- HttpResponse.ClearContent();
- if (m_hcErr != HTTP_SUCCESS)
- {
- HttpResponse.SetStatusCode(HTTP_ERROR_CODE(m_hcErr));
- return HTTP_SUCCESS_NO_PROCESS;
- }
- HttpResponse.SetStatusCode(500);
- GenerateAppError(&HttpResponse, hr);
- return AtlsHttpError(500, SUBERR_NO_PROCESS);
- }
-
- HttpResponse.SetContentType("text/xml");
- hr = GenerateResponse(&HttpResponse);
- Cleanup();
- if (FAILED(hr))
- {
- SoapFault(SOAP_E_SERVER, NULL, 0);
- return m_hcErr;
- }
-
- return HTTP_SUCCESS;
- }
-
- virtual ATL_NOINLINE HRESULT GenerateAppError(IWriteStream *pStream, HRESULT hr)
- {
- if (pStream == NULL)
- {
- return E_INVALIDARG;
- }
-
- LPWSTR pwszMessage = NULL;
- DWORD dwLen = ::FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
- NULL, hr, 0, (LPWSTR) &pwszMessage, 0, NULL);
-
- if (dwLen == 0)
- {
- pwszMessage = L"Application Error";
- }
-
- hr = SoapFault(SOAP_E_SERVER, pwszMessage, dwLen ? dwLen : -1);
- if (dwLen != 0)
- {
- ::LocalFree(pwszMessage);
- }
-
- return hr;
- }
-
- void UninitializeHandler()
- {
- UninitializeSOAP();
- }
-};
-
-
-// client error states
-enum SOAPCLIENT_ERROR
-{
- SOAPCLIENT_SUCCESS=0, // everything succeeded
- SOAPCLIENT_INITIALIZE_ERROR, // initialization failed -- most likely an MSXML installation problem
- SOAPCLIENT_OUTOFMEMORY, // out of memory
- SOAPCLIENT_GENERATE_ERROR, // failed in generating the response
- SOAPCLIENT_CONNECT_ERROR, // failed connecting to server
- SOAPCLIENT_SEND_ERROR, // failed in sending message
- SOAPCLIENT_SERVER_ERROR, // server error
- SOAPCLIENT_SOAPFAULT, // a SOAP Fault was returned by the server
- SOAPCLIENT_PARSEFAULT_ERROR, // failed in parsing SOAP fault
- SOAPCLIENT_READ_ERROR, // failed in reading response
- SOAPCLIENT_PARSE_ERROR // failed in parsing response
-};
-
-template <typename TSocketClass = ZEvtSyncSocket>
-class CSoapSocketClientT
-{
-private:
-
- CUrl m_url;
- CWriteStreamOnCString m_writeStream;
- CReadStreamOnSocket<TSocketClass> m_readStream;
- DWORD m_dwTimeout;
-
- SOAPCLIENT_ERROR m_errorState;
-
-protected:
-
- virtual HRESULT GetClientReader(ISAXXMLReader **pReader)
- {
- if (pReader == NULL)
- {
- return E_POINTER;
- }
- *pReader = NULL;
-
- CComPtr<ISAXXMLReader> spReader;
- HRESULT hr = spReader.CoCreateInstance(ATLS_SAXXMLREADER_CLSID, NULL, CLSCTX_INPROC_SERVER);
- if (SUCCEEDED(hr))
- {
- *pReader = spReader.Detach();
- }
- return hr;
- }
-
-public:
-
- // note : not shared across stock client implementations
- CAtlHttpClientT<TSocketClass> m_socket;
-
- CSoapFault m_fault;
-
- // constructor
- CSoapSocketClientT(LPCTSTR szUrl)
- : m_dwTimeout(0), m_errorState(SOAPCLIENT_SUCCESS)
- {
- TCHAR szTmp[ATL_URL_MAX_URL_LENGTH];
- if(AtlEscapeUrl(szUrl,szTmp,0,ATL_URL_MAX_URL_LENGTH-1,ATL_URL_BROWSER_MODE))
- m_url.CrackUrl(szTmp);
- }
-
- CSoapSocketClientT(LPCTSTR szServer, LPCTSTR szUri, ATL_URL_PORT nPort=80)
- : m_dwTimeout(0), m_errorState(SOAPCLIENT_SUCCESS)
- {
- ATLASSERT( szServer != NULL );
- ATLASSERT( szUri != NULL );
-
- m_url.SetUrlPath(szUri);
- m_url.SetHostName(szServer);
- m_url.SetPortNumber(nPort);
- }
-
- ~CSoapSocketClientT()
- {
- CleanupClient();
- }
-
- SOAPCLIENT_ERROR GetClientError()
- {
- return m_errorState;
- }
-
- void SetClientError(SOAPCLIENT_ERROR errorState)
- {
- m_errorState = errorState;
- }
-
- IWriteStream * GetWriteStream()
- {
- return &m_writeStream;
- }
-
- HRESULT GetReadStream(IStream **ppStream)
- {
- if (ppStream == NULL)
- {
- return E_POINTER;
- }
-
- *ppStream = &m_readStream;
- return S_OK;
- }
-
- void CleanupClient()
- {
- m_writeStream.Cleanup();
- m_fault.Clear();
- SetClientError(SOAPCLIENT_SUCCESS);
- }
-
- HRESULT SendRequest(LPCTSTR szAction)
- {
- HRESULT hr = E_FAIL;
- _ATLTRY
- {
- // create extra headers to send with request
- CFixedStringT<CString, 256> strExtraHeaders(szAction);
- strExtraHeaders.Append(_T("Accept: text/xml\r\n"), sizeof("Accept: text/xml\r\n")-1);
- CAtlNavigateData navData;
- navData.SetMethod(ATL_HTTP_METHOD_POST);
- navData.SetPort(m_url.GetPortNumber());
- navData.SetExtraHeaders(strExtraHeaders);
- navData.SetPostData((LPBYTE)(LPCSTR) m_writeStream.m_str, m_writeStream.m_str.GetLength(), _T("text/xml; charset=utf-8"));
-
- ATLSOAP_TRACE( (LPBYTE)(LPCSTR)m_writeStream.m_str, m_writeStream.m_str.GetLength() );
-
- if (m_dwTimeout != 0)
- {
- navData.SetSocketTimeout(m_dwTimeout);
- }
-
- if (m_socket.Navigate(&m_url, &navData) != false)
- {
- if (GetStatusCode() == 200)
- {
- hr = (m_readStream.Init(&m_socket) != FALSE ? S_OK : E_FAIL);
- if (hr != S_OK)
- {
- SetClientError(SOAPCLIENT_READ_ERROR);
- }
- }
- else if (GetStatusCode() == 202)
- {
- // for one-way methods
- hr = S_OK;
- }
- else
- {
- SetClientError(SOAPCLIENT_SERVER_ERROR);
- }
- }
- else if (GetStatusCode() == 500)
- {
- SetClientError(SOAPCLIENT_SOAPFAULT);
-
- // if returned 500, get the SOAP fault
- if (m_readStream.Init(&m_socket) != FALSE)
- {
- CComPtr<ISAXXMLReader> spReader;
- if (SUCCEEDED(GetClientReader(&spReader)))
- {
- CComPtr<IStream> spReadStream;
- if (SUCCEEDED(GetReadStream(&spReadStream)))
- {
- if (FAILED(m_fault.ParseFault(spReadStream, spReader)))
- {
- SetClientError(SOAPCLIENT_PARSEFAULT_ERROR);
- }
- }
- }
- }
- }
- else
- {
- SetClientError(SOAPCLIENT_SEND_ERROR);
- }
- }
- _ATLCATCHALL()
- {
- hr = E_FAIL;
- }
-
- return hr;
- }
-
- HRESULT SetUrl(LPCTSTR szUrl)
- {
- TCHAR szTmp[ATL_URL_MAX_URL_LENGTH];
- if(!AtlEscapeUrl(szUrl,szTmp,0,ATL_URL_MAX_URL_LENGTH-1,ATL_URL_BROWSER_MODE))
- {
- return E_FAIL;
- }
-
- return (m_url.CrackUrl(szTmp) != FALSE) ? S_OK : E_FAIL;
- }
-
- HRESULT GetUrl(__out_ecount_part_z(*pdwLen, *pdwLen) LPTSTR szUrl, __inout LPDWORD pdwLen)
- {
- if ((szUrl == NULL) || (pdwLen == NULL))
- {
- return E_INVALIDARG;
- }
-
- return (m_url.CreateUrl(szUrl, pdwLen) != FALSE) ? S_OK : E_FAIL;
- }
-
- HRESULT SetProxy(LPCTSTR szProxy = NULL, short nProxyPort = 80)
- {
- BOOL bRet = m_socket.SetProxy(szProxy, nProxyPort);
- return (bRet != FALSE) ? S_OK : E_FAIL;
- }
-
- void SetTimeout(DWORD dwTimeout)
- {
- m_dwTimeout = dwTimeout;
- }
-
- int GetStatusCode()
- {
- return m_socket.GetStatus();
- }
-
-}; // CSoapSocketClientT
-
-#ifndef ATLSOAP_NOWININET
-
-class CReadStreamOnInet : public IStreamImpl
-{
-public:
-
- HRESULT __stdcall QueryInterface(REFIID riid, void **ppv)
- {
- if (ppv == NULL)
- {
- return E_POINTER;
- }
-
- *ppv = NULL;
-
- if (InlineIsEqualGUID(riid, IID_IUnknown) ||
- InlineIsEqualGUID(riid, IID_IStream) ||
- InlineIsEqualGUID(riid, IID_ISequentialStream))
- {
- *ppv = static_cast<IStream *>(this);
- return S_OK;
- }
-
- return E_NOINTERFACE;
- }
-
- ULONG __stdcall AddRef()
- {
- return 1;
- }
-
- ULONG __stdcall Release()
- {
- return 1;
- }
-
-private:
-
- HINTERNET m_hFile;
-
-public:
-
- CReadStreamOnInet()
- :m_hFile(NULL)
- {
- }
-
- void Init(HINTERNET hFile)
- {
- m_hFile = hFile;
- }
-
- HRESULT STDMETHODCALLTYPE Read(void *pDest, ULONG dwMaxLen, ULONG *pdwRead)
- {
- BOOL bRet = InternetReadFile(m_hFile, pDest, dwMaxLen, pdwRead);
- return (bRet != FALSE) ? S_OK : E_FAIL;
- }
-
-}; // CStreamOnInet
-
-class CSoapWininetClient
-{
-private:
-
- CUrl m_url;
- CWriteStreamOnCString m_writeStream;
- CReadStreamOnInet m_readStream;
- CString m_strProxy;
- DWORD m_dwTimeout;
- CFixedStringT<CString, ATL_URL_MAX_URL_LENGTH+1> m_strUrl;
- SOAPCLIENT_ERROR m_errorState;
-
- void CloseAll()
- {
- if (m_hRequest != NULL)
- {
- InternetCloseHandle(m_hRequest);
- m_hRequest = NULL;
- }
- if (m_hConnection != NULL)
- {
- InternetCloseHandle(m_hConnection);
- m_hConnection = NULL;
- }
- if (m_hInternet != NULL)
- {
- InternetCloseHandle(m_hInternet);
- m_hInternet = NULL;
- }
- }
-
- HRESULT ConnectToServer()
- {
- if (m_hConnection != NULL)
- {
- return S_OK;
- }
-
- m_hInternet = InternetOpen(
- ATLSOAPINET_CLIENT,
- m_strProxy.GetLength() ? (INTERNET_OPEN_TYPE_PRECONFIG | INTERNET_OPEN_TYPE_PROXY) : INTERNET_OPEN_TYPE_PRECONFIG,
- m_strProxy.GetLength() ? (LPCTSTR) m_strProxy : NULL,
- NULL, 0);
-
- if (m_hInternet != NULL)
- {
- if (m_dwTimeout != 0)
- {
- InternetSetOption(m_hInternet, INTERNET_OPTION_CONNECT_TIMEOUT,
- &m_dwTimeout, sizeof(m_dwTimeout));
- InternetSetOption(m_hInternet, INTERNET_OPTION_RECEIVE_TIMEOUT,
- &m_dwTimeout, sizeof(m_dwTimeout));
- InternetSetOption(m_hInternet, INTERNET_OPTION_SEND_TIMEOUT,
- &m_dwTimeout, sizeof(m_dwTimeout));
- }
- m_hConnection = InternetConnect(m_hInternet, m_url.GetHostName(),
- (INTERNET_PORT) m_url.GetPortNumber(), NULL, NULL,
- INTERNET_SERVICE_HTTP, 0, NULL);
-
- if (m_hConnection != NULL)
- {
- return S_OK;
- }
- }
- CloseAll();
- return E_FAIL;
- }
-
-protected:
-
- virtual HRESULT GetClientReader(ISAXXMLReader **pReader)
- {
- if (pReader == NULL)
- {
- return E_POINTER;
- }
- *pReader = NULL;
-
- CComPtr<ISAXXMLReader> spReader;
- HRESULT hr = spReader.CoCreateInstance(ATLS_SAXXMLREADER_CLSID, NULL, CLSCTX_INPROC_SERVER);
- if (SUCCEEDED(hr))
- {
- *pReader = spReader.Detach();
- }
- return hr;
- }
-
-public:
-
- // note : not shared across stock client implementations
- HINTERNET m_hInternet;
- HINTERNET m_hConnection;
- HINTERNET m_hRequest;
-
- CSoapFault m_fault;
-
- CSoapWininetClient(LPCTSTR szUrl)
- :m_hInternet(NULL), m_hConnection(NULL), m_hRequest(NULL), m_dwTimeout(0), m_errorState(SOAPCLIENT_SUCCESS)
- {
- TCHAR szTmp[ATL_URL_MAX_URL_LENGTH];
- if(AtlEscapeUrl(szUrl,szTmp,0,ATL_URL_MAX_URL_LENGTH-1,ATL_URL_BROWSER_MODE))
- {
- if (m_url.CrackUrl(szTmp) != FALSE)
- {
- SetProxy();
- _ATLTRY
- {
- m_strUrl.SetString(m_url.GetUrlPath(), m_url.GetUrlPathLength());
- m_strUrl.Append(m_url.GetExtraInfo(), m_url.GetExtraInfoLength());
- }
- _ATLCATCHALL()
- {
- }
- }
- }
- }
-
- CSoapWininetClient(LPCTSTR szServer, LPCTSTR szUri, short nPort=80)
- :m_hInternet(NULL), m_hConnection(NULL), m_hRequest(NULL), m_dwTimeout(0), m_errorState(SOAPCLIENT_SUCCESS)
- {
- if (m_url.SetHostName(szServer) != FALSE)
- {
- if (m_url.SetUrlPath(szUri) != FALSE)
- {
- if (m_url.SetPortNumber((ATL_URL_PORT) nPort) != FALSE)
- {
- _ATLTRY
- {
- m_strUrl.SetString(m_url.GetUrlPath(), m_url.GetUrlPathLength());
- m_strUrl.Append(m_url.GetExtraInfo(), m_url.GetExtraInfoLength());
- }
- _ATLCATCHALL()
- {
- }
- }
- }
- }
- }
-
- virtual ~CSoapWininetClient()
- {
- CleanupClient();
- CloseAll();
- }
-
- SOAPCLIENT_ERROR GetClientError()
- {
- return m_errorState;
- }
-
- void SetClientError(SOAPCLIENT_ERROR errorState)
- {
- m_errorState = errorState;
- }
-
- IWriteStream * GetWriteStream()
- {
- return &m_writeStream;
- }
-
- HRESULT GetReadStream(IStream **ppStream)
- {
- if (ppStream == NULL)
- {
- return E_POINTER;
- }
-
- *ppStream = &m_readStream;
- return S_OK;
- }
-
- void CleanupClient()
- {
- m_writeStream.Cleanup();
- if (m_hRequest != NULL)
- {
- InternetCloseHandle(m_hRequest);
- m_hRequest = NULL;
- }
- m_fault.Clear();
- SetClientError(SOAPCLIENT_SUCCESS);
- }
-
- HRESULT SendRequest(LPCTSTR szAction)
- {
- if (ConnectToServer() != S_OK)
- {
- SetClientError(SOAPCLIENT_CONNECT_ERROR);
- return E_FAIL;
- }
-
- CString strHeaders;
- _ATLTRY
- {
- strHeaders.Append(szAction);
- strHeaders.Append(_T("Content-Type: text/xml; charset=utf-8\r\n"));
- }
- _ATLCATCHALL()
- {
- return E_OUTOFMEMORY;
- }
-
- static LPCTSTR s_szAcceptTypes[] = { _T("text/*"), NULL };
- m_hRequest = HttpOpenRequest(m_hConnection, _T("POST"),
- m_strUrl, _T("HTTP/1.0"), NULL,
- s_szAcceptTypes,
- INTERNET_FLAG_NO_UI | INTERNET_FLAG_KEEP_CONNECTION | ((m_url.GetScheme() == ATL_URL_SCHEME_HTTPS) ? INTERNET_FLAG_SECURE : 0)
- , NULL);
-
- if (m_hRequest != NULL)
- {
- if (FALSE != HttpSendRequest(m_hRequest, strHeaders, (DWORD) strHeaders.GetLength(),
- (void *)(LPCSTR)m_writeStream.m_str, m_writeStream.m_str.GetLength()))
- {
- m_readStream.Init(m_hRequest);
- if (GetStatusCode() != HTTP_STATUS_SERVER_ERROR)
- {
- return S_OK;
- }
- else
- {
- SetClientError(SOAPCLIENT_SOAPFAULT);
-
- CComPtr<ISAXXMLReader> spReader;
- if (SUCCEEDED(GetClientReader(&spReader)))
- {
- CComPtr<IStream> spReadStream;
- if (SUCCEEDED(GetReadStream(&spReadStream)))
- {
- if (FAILED(m_fault.ParseFault(spReadStream, spReader)))
- {
- SetClientError(SOAPCLIENT_PARSEFAULT_ERROR);
- }
- }
- }
- }
- }
- }
- else
- {
- SetClientError(SOAPCLIENT_SEND_ERROR);
- }
-
- return E_FAIL;
- }
-
- HRESULT SetUrl(LPCTSTR szUrl)
- {
- CloseAll();
- TCHAR szTmp[ATL_URL_MAX_URL_LENGTH];
- if(!AtlEscapeUrl(szUrl,szTmp,0,ATL_URL_MAX_URL_LENGTH-1,ATL_URL_BROWSER_MODE))
- {
- return E_FAIL;
- }
-
- if (m_url.CrackUrl(szTmp) != FALSE)
- {
- _ATLTRY
- {
- m_strUrl.SetString(m_url.GetUrlPath(), m_url.GetUrlPathLength());
- m_strUrl.Append(m_url.GetExtraInfo(), m_url.GetExtraInfoLength());
- }
- _ATLCATCHALL()
- {
- return E_OUTOFMEMORY;
- }
- return S_OK;
- }
- return E_FAIL;
- }
-
- HRESULT GetUrl(LPTSTR szUrl, LPDWORD pdwLen)
- {
- if ((szUrl == NULL) || (pdwLen == NULL))
- {
- return E_INVALIDARG;
- }
-
- return (m_url.CreateUrl(szUrl, pdwLen) != FALSE) ? S_OK : E_FAIL;
- }
-
- HRESULT SetProxy(LPCTSTR szProxy = NULL, short nProxyPort = 80)
- {
- _ATLTRY
- {
- if (szProxy && szProxy[0])
- {
- m_strProxy.Format(_T("http=http://%s:%d https=http://%s:%d"), szProxy, nProxyPort, szProxy, nProxyPort);
- }
- else
- {
- m_strProxy.Empty();
- }
- }
- _ATLCATCHALL()
- {
- return E_OUTOFMEMORY;
- }
-
- return S_OK;
- }
-
- void SetTimeout(DWORD dwTimeout)
- {
- m_dwTimeout = dwTimeout;
- }
-
- int GetStatusCode()
- {
- DWORD dwLen = 255;
- TCHAR szBuf[256];
- if (HttpQueryInfo(m_hRequest, HTTP_QUERY_STATUS_CODE, szBuf, &dwLen, NULL))
- {
- szBuf[dwLen] = '\0';
- return _ttoi(szBuf);
- }
- return 0;
- }
-}; // CSoapWininetClient
-#endif
-
-#ifndef ATLSOAP_NOMSXML_INET
-class CSoapMSXMLInetClient
-{
-private:
-
- CUrl m_url;
- CWriteStreamOnCString m_writeStream;
- DWORD m_dwTimeout;
- SOAPCLIENT_ERROR m_errorState;
-
- HRESULT ConnectToServer()
- {
- TCHAR szURL[ATL_URL_MAX_URL_LENGTH];
- DWORD dwLen = ATL_URL_MAX_URL_LENGTH;
- HRESULT hr = E_FAIL;
-
- if (m_spHttpRequest)
- return S_OK;
-
- if (!m_url.CreateUrl(szURL, &dwLen))
- return E_FAIL;
-
-
- hr = m_spHttpRequest.CoCreateInstance(__uuidof(ServerXMLHTTP30));
- if (hr != S_OK)
- return hr;
-
- CComVariant vEmpty;
- hr = m_spHttpRequest->open( CComBSTR(L"POST"),
- CComBSTR(szURL),
- CComVariant(VARIANT_BOOL(VARIANT_FALSE)),
- vEmpty,
- vEmpty );
- if (hr != S_OK)
- {
- m_spHttpRequest.Release();
- return hr;
- }
-
- return S_OK;
- }
-
-protected:
-
- virtual HRESULT GetClientReader(ISAXXMLReader **pReader)
- {
- if (pReader == NULL)
- {
- return E_POINTER;
- }
- *pReader = NULL;
-
- CComPtr<ISAXXMLReader> spReader;
- HRESULT hr = spReader.CoCreateInstance(ATLS_SAXXMLREADER_CLSID, NULL, CLSCTX_INPROC_SERVER);
- if (SUCCEEDED(hr))
- {
- *pReader = spReader.Detach();
- }
- return hr;
- }
-
-public:
-
- // note : not shared across stock client implementations
- CComPtr<IServerXMLHTTPRequest> m_spHttpRequest;
-
- CSoapFault m_fault;
-
- CSoapMSXMLInetClient(LPCTSTR szUrl)
- :m_dwTimeout(0), m_errorState(SOAPCLIENT_SUCCESS)
- {
- m_url.CrackUrl(szUrl);
- }
-
- CSoapMSXMLInetClient(LPCTSTR szServer, LPCTSTR szUri, short nPort=80)
- : m_dwTimeout(0), m_errorState(SOAPCLIENT_SUCCESS)
- {
- m_url.SetHostName(szServer);
- m_url.SetUrlPath(szUri);
- m_url.SetPortNumber((ATL_URL_PORT) nPort);
- }
-
- virtual ~CSoapMSXMLInetClient()
- {
- CleanupClient();
- }
-
- SOAPCLIENT_ERROR GetClientError()
- {
- return m_errorState;
- }
-
- void SetClientError(SOAPCLIENT_ERROR errorState)
- {
- m_errorState = errorState;
- }
-
- IWriteStream * GetWriteStream()
- {
- return &m_writeStream;
- }
-
- HRESULT GetReadStream(IStream **ppStream)
- {
- if (ppStream == NULL)
- {
- return E_POINTER;
- }
-
- *ppStream = NULL;
- HRESULT hr = E_FAIL;
-
- if (m_spHttpRequest)
- {
- VARIANT vResponseStream;
- VariantInit(&vResponseStream);
- hr = m_spHttpRequest->get_responseStream(&vResponseStream);
- if (S_OK == hr)
- {
- hr = E_FAIL;
- if ((vResponseStream.vt == VT_UNKNOWN) && (vResponseStream.punkVal != NULL))
- {
- // we return the refcount with the pointer!
- hr = vResponseStream.punkVal->QueryInterface(__uuidof(IStream), (void **)ppStream);
- }
- else
- {
- SetClientError(SOAPCLIENT_READ_ERROR);
- }
- }
- VariantClear(&vResponseStream);
- }
- return hr;
- }
-
- void CleanupClient()
- {
- m_writeStream.Cleanup();
- m_spHttpRequest.Release();
- m_fault.Clear();
- SetClientError(SOAPCLIENT_SUCCESS);
- }
-
- HRESULT SendRequest(LPCTSTR szAction)
- {
- if (ConnectToServer() != S_OK)
- {
- SetClientError(SOAPCLIENT_CONNECT_ERROR);
- return E_FAIL;
- }
-
- // set the action header
- LPCTSTR szColon = _tcschr(szAction, _T(':'));
- if (szColon != NULL)
- {
- do
- {
- szColon++;
- } while (_istspace(static_cast<unsigned char>(*szColon)));
-
- if (FAILED(m_spHttpRequest->setRequestHeader(
- CComBSTR( L"SOAPAction" ), CComBSTR( szColon ))))
- {
- SetClientError(SOAPCLIENT_SEND_ERROR);
- return E_FAIL;
- }
- } // if SOAPAction header not properly formed, attempt to send anyway
-
- if (FAILED(m_spHttpRequest->setRequestHeader(CComBSTR( L"Content-Type" ), CComBSTR(L"text/xml; charset=utf-8"))))
- {
- SetClientError(SOAPCLIENT_SEND_ERROR);
- return E_FAIL;
- }
-
- // set timeout
- if (m_dwTimeout != 0)
- {
- long nTimeout = (long) m_dwTimeout;
- m_spHttpRequest->setTimeouts(nTimeout, nTimeout, nTimeout, nTimeout);
- // reset timeout
- m_dwTimeout = 0;
- }
-
- CComVariant vBody(m_writeStream.m_str);
- HRESULT hr = m_spHttpRequest->send(vBody);
- if ((SUCCEEDED(hr)) && (GetStatusCode() == 500))
- {
- hr = E_FAIL;
- CComPtr<ISAXXMLReader> spReader;
- if (SUCCEEDED(GetClientReader(&spReader)))
- {
- SetClientError(SOAPCLIENT_SOAPFAULT);
-
- CComPtr<IStream> spReadStream;
- if (SUCCEEDED(GetReadStream(&spReadStream)))
- {
- if (FAILED(m_fault.ParseFault(spReadStream, spReader)))
- {
- SetClientError(SOAPCLIENT_PARSEFAULT_ERROR);
- }
- }
- }
- }
- else if (FAILED(hr))
- {
- SetClientError(SOAPCLIENT_SEND_ERROR);
- }
-
- return hr;
- }
-
- HRESULT SetUrl(LPCTSTR szUrl)
- {
- CleanupClient();
- return (m_url.CrackUrl(szUrl) != FALSE ? S_OK : E_FAIL);
- }
-
- HRESULT GetUrl(LPTSTR szUrl, LPDWORD pdwLen)
- {
- if ((szUrl == NULL) || (pdwLen == NULL))
- {
- return E_INVALIDARG;
- }
-
- return (m_url.CreateUrl(szUrl, pdwLen) != FALSE) ? S_OK : E_FAIL;
- }
-
- void SetTimeout(DWORD dwTimeout)
- {
- m_dwTimeout = dwTimeout;
- }
-
- int GetStatusCode()
- {
- long lStatus;
- if (m_spHttpRequest->get_status(&lStatus) == S_OK)
- {
- return (int) lStatus;
- }
- return 0;
- }
-
- HRESULT SetProxy(LPCTSTR szProxy = NULL, short nProxyPort = 80)
- {
- (szProxy);
- (nProxyPort);
-
- ATLTRACE( _T("CSoapMSXMLInetClient does not support SetProxy") );
-
- return S_OK;
- }
-}; // CSoapMSXMLInetClient
-#endif
-
-
-class _CSDLGenerator : public ITagReplacerImpl<_CSDLGenerator>
-{
-private:
-
- typedef CAtlMap<CStringA, const _soapmap *, CStringElementTraits<CStringA> > WSDLMAP;
- typedef CAtlMap<CStringA, const _soapmapentry *, CStringElementTraits<CStringA> > HEADERMAP;
-
- HRESULT GenerateWSDLHelper(const _soapmap *pMap, WSDLMAP& structMap, WSDLMAP& enumMap)
- {
- ATLENSURE_RETURN( pMap != NULL );
-
- const _soapmapentry *pEntries = pMap->pEntries;
- ATLENSURE_RETURN( pEntries != NULL );
-
- HRESULT hr = S_OK;
-
- for (int i=0; pEntries[i].nHash != 0; i++)
- {
- if (pEntries[i].nVal == SOAPTYPE_UNK)
- {
- ATLENSURE_RETURN( pEntries[i].pChain != NULL );
-
- _ATLTRY
- {
- POSITION pos = NULL;
- CStringA strName(pEntries[i].pChain->szName, pEntries[i].pChain->cchName);
- if (pEntries[i].pChain->mapType == SOAPMAP_STRUCT)
- {
- pos = structMap.SetAt(strName, pEntries[i].pChain);
- }
- else if (pEntries[i].pChain->mapType == SOAPMAP_ENUM)
- {
- pos = enumMap.SetAt(strName, pEntries[i].pChain);
- }
- if (pos == NULL)
- {
- hr = E_OUTOFMEMORY;
- break;
- }
- }
- _ATLCATCHALL()
- {
- hr = E_OUTOFMEMORY;
- break;
- }
-
- hr = GenerateWSDLHelper(pEntries[i].pChain, structMap, enumMap);
- if (FAILED(hr))
- {
- break;
- }
- }
- }
-
- return hr;
- }
-
- HTTP_CODE IsUDT(const _soapmapentry *pEntry)
- {
- ATLENSURE( pEntry != NULL );
- return (pEntry->nVal != SOAPTYPE_UNK) ? HTTP_S_FALSE : HTTP_SUCCESS;
- }
-
- HTTP_CODE GetSoapDims(const _soapmapentry *pEntry)
- {
- ATLENSURE( pEntry != NULL );
- if (pEntry->pDims[0] != 0)
- {
- if (SUCCEEDED(m_pWriteStream->WriteStream("[", 1, NULL)))
- {
- for (int i=1; i<=pEntry->pDims[0]; i++)
- {
- if (m_writeHelper.Write(pEntry->pDims[i]) != FALSE)
- {
- if (i < pEntry->pDims[0])
- {
- if (FAILED(m_pWriteStream->WriteStream(", ", 2, NULL)))
- {
- return HTTP_FAIL;
- }
- }
- }
- }
- if (SUCCEEDED(m_pWriteStream->WriteStream("]", 1, NULL)))
- {
- return HTTP_SUCCESS;
- }
- }
- }
- return HTTP_FAIL;
- }
-
- const _soapmap **m_pFuncs;
- const _soapmap **m_pHeaders;
- int m_nFunc;
- int m_nParam;
- int m_nHeader;
- WSDLMAP m_structMap;
- WSDLMAP m_enumMap;
- POSITION m_currUDTPos;
- int m_nCurrUDTField;
-
- HEADERMAP m_headerMap;
- POSITION m_currHeaderPos;
-
- CWriteStreamHelper m_writeHelper;
-
- CStringA m_strServiceName;
- CStringA m_strNamespaceUri;
-
- IWriteStream *m_pWriteStream;
-
- CComPtr<IHttpServerContext> m_spHttpServerContext;
-
- DWORD m_dwCallFlags;
-
-protected:
-
- void SetWriteStream(IWriteStream *pStream)
- {
- m_pWriteStream = pStream;
- m_writeHelper.Attach(m_pWriteStream);
- }
-
- void SetHttpServerContext(IHttpServerContext *pServerContext)
- {
- m_spHttpServerContext = pServerContext;
- }
-
- static HTTP_CODE GetSoapType(int nVal, IWriteStream *pStream)
- {
- return (pStream->WriteStream(CSoapRootHandler::s_xsdNames[nVal].szName,
- CSoapRootHandler::s_xsdNames[nVal].cchName, NULL) == S_OK) ? HTTP_SUCCESS : HTTP_FAIL;
- }
-
-
- HRESULT InitializeSDL(CSoapRootHandler *pHdlr)
- {
- m_pFuncs = pHdlr->GetFunctionMap();
-
- if (m_pFuncs == NULL)
- {
- return E_FAIL;
- }
-
- ATLASSUME( m_pFuncs[0] != NULL );
-
- m_dwCallFlags = m_pFuncs[0]->dwCallFlags;
-
- size_t i;
- for (i=0; m_pFuncs[i] != NULL; i++)
- {
- const _soapmap *pMap = m_pFuncs[i];
- HRESULT hr = GenerateWSDLHelper(pMap, m_structMap, m_enumMap);
- if (FAILED(hr))
- {
- return hr;
- }
- }
-
- m_pHeaders = pHdlr->GetHeaderMap();
- if (m_pHeaders != NULL)
- {
- for (i=0; m_pHeaders[i] != NULL; i++)
- {
- const _soapmap *pMap = m_pHeaders[i];
- HRESULT hr = GenerateWSDLHelper(pMap, m_structMap, m_enumMap);
- if (FAILED(hr))
- {
- return hr;
- }
- }
-
- for (i=0; m_pHeaders[i] != NULL; i++)
- {
- const _soapmap *pMap = m_pHeaders[i];
- for (size_t j=0; pMap->pEntries[j].nHash != 0; j++)
- {
- HRESULT hr = S_OK;
- _ATLTRY
- {
- if (m_headerMap.SetAt(pMap->pEntries[j].szField, &pMap->pEntries[j]) == NULL)
- {
- hr = E_OUTOFMEMORY;
- }
- }
- _ATLCATCHALL()
- {
- hr = E_OUTOFMEMORY;
- }
- if (FAILED(hr))
- {
- return hr;
- }
- }
- }
- }
-
- _ATLTRY
- {
- m_strServiceName = pHdlr->GetServiceName();
- m_strNamespaceUri = pHdlr->GetNamespaceUriA();
- }
- _ATLCATCHALL()
- {
- return E_OUTOFMEMORY;
- }
- return S_OK;
- }
-
- virtual const char * GetHandlerName() = 0;
-
-public:
-
- _CSDLGenerator()
- :m_pFuncs(NULL), m_nFunc(-1), m_nParam(-1),
- m_currUDTPos(NULL), m_nCurrUDTField(-1),
- m_pWriteStream(NULL), m_nHeader(-1), m_currHeaderPos(NULL)
- {
- }
- virtual ~_CSDLGenerator()
- {
- }
-
- HTTP_CODE OnGetURL()
- {
- char szURL[ATL_URL_MAX_URL_LENGTH];
- DWORD dwUrlSize = sizeof(szURL);
- char szServer[ATL_URL_MAX_HOST_NAME_LENGTH];
- DWORD dwServerSize = sizeof(szServer);
- char szHttps[16];
- DWORD dwHttpsLen = sizeof(szHttps);
- char szPort[ATL_URL_MAX_PORT_NUMBER_LENGTH+1];
- DWORD dwPortLen = sizeof(szPort);
-
- if (m_spHttpServerContext->GetServerVariable("URL", szURL, &dwUrlSize) != FALSE)
- {
- if (m_spHttpServerContext->GetServerVariable("SERVER_NAME", szServer, &dwServerSize) != FALSE)
- {
- bool bHttps = false;
- if ((m_spHttpServerContext->GetServerVariable("HTTPS", szHttps, &dwHttpsLen) != FALSE) &&
- (!_stricmp(szHttps, "ON")))
- {
- bHttps = true;
- }
-
- if (m_spHttpServerContext->GetServerVariable("SERVER_PORT", szPort, &dwPortLen) != FALSE)
- {
- _ATLTRY
- {
- CStringA strUrl;
- strUrl.Format("http%s://%s:%s%s?Handler=%s", bHttps ? "s" : "", szServer, szPort, szURL, GetHandlerName());
-
- CA2W wszUrl(strUrl);
- wchar_t *pwszUrl = wszUrl;
- HRESULT hr = AtlGenXMLValue(m_pWriteStream, &pwszUrl);
- return SUCCEEDED(hr) ? HTTP_SUCCESS : HTTP_FAIL;
- }
- _ATLCATCHALL()
- {
- return HTTP_FAIL;
- }
- }
- }
- }
- return HTTP_FAIL;
- }
-
- HTTP_CODE OnGetNamespace()
- {
- return (m_pWriteStream->WriteStream(m_strNamespaceUri,
- m_strNamespaceUri.GetLength(), NULL) == S_OK) ? HTTP_SUCCESS : HTTP_FAIL;
- }
-
- HTTP_CODE OnGetNextFunction()
- {
- m_nFunc++;
- if (m_pFuncs[m_nFunc] == NULL)
- {
- m_nFunc = -1;
- return HTTP_S_FALSE;
- }
- return HTTP_SUCCESS;
- }
-
- HTTP_CODE OnGetFunctionName()
- {
- return (m_pWriteStream->WriteStream(m_pFuncs[m_nFunc]->szName,
- m_pFuncs[m_nFunc]->cchName, NULL) == S_OK) ? HTTP_SUCCESS : HTTP_S_FALSE;
- }
-
- HTTP_CODE OnGetNextParameter()
- {
- ++m_nParam;
- if (m_pFuncs[m_nFunc]->pEntries[m_nParam].nHash != 0)
- {
- if (m_pFuncs[m_nFunc]->pEntries[m_nParam].dwFlags & SOAPFLAG_NOMARSHAL)
- {
- return OnGetNextParameter();
- }
- return HTTP_SUCCESS;
- }
- m_nParam = -1;
- return HTTP_S_FALSE;
- }
-
- HTTP_CODE OnIsInParameter()
- {
- return (m_pFuncs[m_nFunc]->pEntries[m_nParam].dwFlags & SOAPFLAG_IN) ? HTTP_SUCCESS : HTTP_S_FALSE;
- }
-
- HTTP_CODE OnGetParameterName()
- {
- HRESULT hr = S_OK;
- if (m_pFuncs[m_nFunc]->pEntries[m_nParam].dwFlags & SOAPFLAG_RETVAL)
- {
- hr = m_pWriteStream->WriteStream("return", sizeof("return")-1, NULL);
- }
- else
- {
- hr = m_pWriteStream->WriteStream(m_pFuncs[m_nFunc]->pEntries[m_nParam].szField,
- m_pFuncs[m_nFunc]->pEntries[m_nParam].cchField, NULL);
- }
-
- return (hr == S_OK) ? HTTP_SUCCESS : HTTP_FAIL;
- }
-
- HTTP_CODE OnNotIsArrayParameter()
- {
- return (m_pFuncs[m_nFunc]->pEntries[m_nParam].dwFlags & (SOAPFLAG_FIXEDARR | SOAPFLAG_DYNARR))
- ? HTTP_S_FALSE: HTTP_SUCCESS;
- }
-
- HTTP_CODE OnIsParameterUDT()
- {
- return IsUDT(&m_pFuncs[m_nFunc]->pEntries[m_nParam]);
- }
-
- HTTP_CODE OnGetParameterSoapType()
- {
- if (m_pFuncs[m_nFunc]->pEntries[m_nParam].nVal != SOAPTYPE_UNK)
- {
- return GetSoapType(m_pFuncs[m_nFunc]->pEntries[m_nParam].nVal, m_pWriteStream);
- }
- ATLASSUME( m_pFuncs[m_nFunc]->pEntries[m_nParam].pChain != NULL );
- return (m_pWriteStream->WriteStream(m_pFuncs[m_nFunc]->pEntries[m_nParam].pChain->szName,
- m_pFuncs[m_nFunc]->pEntries[m_nParam].pChain->cchName, NULL) == S_OK) ? HTTP_SUCCESS : HTTP_S_FALSE;
- }
-
- HTTP_CODE OnIsParameterDynamicArray()
- {
- return (m_pFuncs[m_nFunc]->pEntries[m_nParam].dwFlags & SOAPFLAG_DYNARR) ? HTTP_SUCCESS: HTTP_S_FALSE;
- }
-
- HTTP_CODE OnIsArrayParameter()
- {
- return (OnNotIsArrayParameter() != HTTP_SUCCESS) ? HTTP_SUCCESS : HTTP_S_FALSE;
- }
-
- HTTP_CODE OnIsParameterOneDimensional()
- {
- return (m_pFuncs[m_nFunc]->pEntries[m_nParam].pDims[0] == 1) ? HTTP_SUCCESS : HTTP_S_FALSE;
- }
-
- HTTP_CODE OnGetParameterArraySize()
- {
- return (m_writeHelper.Write(m_pFuncs[m_nFunc]->pEntries[m_nParam].pDims[1]) != FALSE)
- ? HTTP_SUCCESS : HTTP_FAIL;
- }
-
- HTTP_CODE OnGetParameterArraySoapDims()
- {
- return GetSoapDims(&m_pFuncs[m_nFunc]->pEntries[m_nParam]);
- }
-
- HTTP_CODE OnIsOutParameter()
- {
- return (m_pFuncs[m_nFunc]->pEntries[m_nParam].dwFlags & SOAPFLAG_OUT) ? HTTP_SUCCESS : HTTP_S_FALSE;
- }
-
- HTTP_CODE OnGetNextEnum()
- {
- if (m_currUDTPos == NULL)
- {
- m_currUDTPos = m_enumMap.GetStartPosition();
- }
- else
- {
- m_enumMap.GetNext(m_currUDTPos);
- }
-
- return (m_currUDTPos != NULL) ? HTTP_SUCCESS : HTTP_S_FALSE;
- }
-
- HTTP_CODE OnGetEnumName()
- {
- const _soapmap *pMap = m_enumMap.GetValueAt(m_currUDTPos);
- return (m_pWriteStream->WriteStream(pMap->szName, pMap->cchName, NULL) == S_OK) ? HTTP_SUCCESS : HTTP_S_FALSE;
- }
-
- HTTP_CODE OnGetNextEnumElement()
- {
- const _soapmap *pMap = m_enumMap.GetValueAt(m_currUDTPos);
- ++m_nCurrUDTField;
- if (pMap->pEntries[m_nCurrUDTField].nHash != 0)
- {
- return HTTP_SUCCESS;
- }
- m_nCurrUDTField = -1;
- return HTTP_S_FALSE;
- }
-
- HTTP_CODE OnGetEnumElementName()
- {
- const _soapmap *pMap = m_enumMap.GetValueAt(m_currUDTPos);
- return (m_pWriteStream->WriteStream(pMap->pEntries[m_nCurrUDTField].szField,
- pMap->pEntries[m_nCurrUDTField].cchField, NULL) == S_OK) ? HTTP_SUCCESS : HTTP_S_FALSE;
- }
-
- HTTP_CODE OnGetNextStruct()
- {
- if (m_currUDTPos == NULL)
- {
- m_currUDTPos = m_structMap.GetStartPosition();
- }
- else
- {
- m_structMap.GetNext(m_currUDTPos);
- }
-
- return (m_currUDTPos != NULL) ? HTTP_SUCCESS : HTTP_S_FALSE;
- }
-
- HTTP_CODE OnGetStructName()
- {
- const _soapmap *pMap = m_enumMap.GetValueAt(m_currUDTPos);
- return (m_pWriteStream->WriteStream(pMap->szName, pMap->cchName, NULL) == S_OK) ? HTTP_SUCCESS : HTTP_S_FALSE;
- }
-
- HTTP_CODE OnGetNextStructField()
- {
- const _soapmap *pMap = m_structMap.GetValueAt(m_currUDTPos);
- ++m_nCurrUDTField;
- if (pMap->pEntries[m_nCurrUDTField].nHash != 0)
- {
- return HTTP_SUCCESS;
- }
- m_nCurrUDTField = -1;
- return HTTP_S_FALSE;
- }
-
- HTTP_CODE OnGetStructFieldName()
- {
- const _soapmap *pMap = m_structMap.GetValueAt(m_currUDTPos);
- return (m_pWriteStream->WriteStream(pMap->pEntries[m_nCurrUDTField].szField,
- pMap->pEntries[m_nCurrUDTField].cchField, NULL) == S_OK) ? HTTP_SUCCESS : HTTP_S_FALSE;
- }
-
- HTTP_CODE OnNotIsArrayField()
- {
- const _soapmap *pMap = m_structMap.GetValueAt(m_currUDTPos);
- return (pMap->pEntries[m_nCurrUDTField].dwFlags & (SOAPFLAG_FIXEDARR | SOAPFLAG_DYNARR)) ? HTTP_S_FALSE : HTTP_SUCCESS;
- }
-
- HTTP_CODE OnIsFieldUDT()
- {
- const _soapmap *pMap = m_structMap.GetValueAt(m_currUDTPos);
- return IsUDT(&pMap->pEntries[m_nCurrUDTField]);
- }
-
- HTTP_CODE OnGetStructFieldSoapType()
- {
- const _soapmap *pMap = m_structMap.GetValueAt(m_currUDTPos);
- if (pMap->pEntries[m_nCurrUDTField].nVal != SOAPTYPE_UNK)
- {
- return GetSoapType(pMap->pEntries[m_nCurrUDTField].nVal, m_pWriteStream);
- }
- ATLASSERT( pMap->pEntries[m_nCurrUDTField].pChain != NULL );
- return (m_pWriteStream->WriteStream(pMap->pEntries[m_nCurrUDTField].pChain->szName,
- pMap->pEntries[m_nCurrUDTField].pChain->cchName, NULL) == S_OK) ? HTTP_SUCCESS : HTTP_S_FALSE;
- }
-
- HTTP_CODE OnIsArrayField()
- {
- return (OnNotIsArrayField() != HTTP_SUCCESS) ? HTTP_SUCCESS : HTTP_S_FALSE;
- }
-
- HTTP_CODE OnIsFieldDynamicArray()
- {
- const _soapmap *pMap = m_structMap.GetValueAt(m_currUDTPos);
- return (pMap->pEntries[m_nCurrUDTField].dwFlags & SOAPFLAG_DYNARR) ? HTTP_SUCCESS : HTTP_S_FALSE;
- }
-
- HTTP_CODE OnGetFieldSizeIsName()
- {
- const _soapmap *pMap = m_structMap.GetValueAt(m_currUDTPos);
- int nIndex = pMap->pEntries[m_nCurrUDTField].nSizeIs;
- ATLASSERT( nIndex >= 0 );
- return (m_pStream->WriteStream(pMap->pEntries[nIndex].szField,
- pMap->pEntries[nIndex].cchField, NULL) == S_OK) ? HTTP_SUCCESS : HTTP_S_FALSE;
- }
-
- HTTP_CODE OnIsFieldOneDimensional()
- {
- const _soapmap *pMap = m_structMap.GetValueAt(m_currUDTPos);
- return (pMap->pEntries[m_nCurrUDTField].pDims[0] == 1) ? HTTP_SUCCESS : HTTP_S_FALSE;
- }
-
- HTTP_CODE OnGetFieldArraySize()
- {
- const _soapmap *pMap = m_structMap.GetValueAt(m_currUDTPos);
- return (m_writeHelper.Write(pMap->pEntries[m_nCurrUDTField].pDims[1]) != FALSE) ?
- HTTP_SUCCESS : HTTP_S_FALSE;
- }
-
- HTTP_CODE OnGetFieldArraySoapDims()
- {
- const _soapmap *pMap = m_structMap.GetValueAt(m_currUDTPos);
- return GetSoapDims(&pMap->pEntries[m_nCurrUDTField]);
- }
-
- HTTP_CODE OnGetServiceName()
- {
- return (m_pWriteStream->WriteStream(m_strServiceName,
- m_strServiceName.GetLength(), NULL) == S_OK) ? HTTP_SUCCESS : HTTP_FAIL;
- }
-
- HTTP_CODE OnGetNextHeader()
- {
- if (m_currHeaderPos == NULL)
- {
- m_currHeaderPos = m_headerMap.GetStartPosition();
- }
- else
- {
- m_headerMap.GetNext(m_currHeaderPos);
- }
-
- return (m_currHeaderPos != NULL) ? HTTP_SUCCESS : HTTP_S_FALSE;
- }
-
- HTTP_CODE OnIsInHeader()
- {
- return (m_pHeaders[m_nFunc]->pEntries[m_nHeader].dwFlags & SOAPFLAG_IN)
- ? HTTP_SUCCESS : HTTP_S_FALSE;
- }
-
- HTTP_CODE OnIsOutHeader()
- {
- return (m_pHeaders[m_nFunc]->pEntries[m_nHeader].dwFlags & SOAPFLAG_OUT)
- ? HTTP_SUCCESS : HTTP_S_FALSE;
- }
-
- HTTP_CODE OnIsRequiredHeader()
- {
- return (m_pHeaders[m_nFunc]->pEntries[m_nHeader].dwFlags & SOAPFLAG_MUSTUNDERSTAND)
- ? HTTP_SUCCESS : HTTP_S_FALSE;
- }
-
- HTTP_CODE OnGetHeaderName()
- {
- const _soapmapentry *pEntry = m_headerMap.GetValueAt(m_currHeaderPos);
- return (m_pWriteStream->WriteStream(pEntry->szField,
- pEntry->cchField, NULL) == S_OK) ? HTTP_SUCCESS : HTTP_FAIL;
- }
-
- HTTP_CODE OnNotIsArrayHeader()
- {
- const _soapmapentry *pEntry = m_headerMap.GetValueAt(m_currHeaderPos);
- return (pEntry->dwFlags & SOAPFLAG_FIXEDARR) ? HTTP_S_FALSE : HTTP_SUCCESS;
- }
-
- HTTP_CODE OnIsHeaderUDT()
- {
- return IsUDT(m_headerMap.GetValueAt(m_currHeaderPos));
- }
-
- HTTP_CODE OnGetHeaderSoapType()
- {
- const _soapmapentry *pEntry = m_headerMap.GetValueAt(m_currHeaderPos);
- if (pEntry->nVal != SOAPTYPE_UNK)
- {
- return GetSoapType(pEntry->nVal, m_pWriteStream);
- }
- ATLENSURE( pEntry->pChain != NULL );
- return (m_pWriteStream->WriteStream(pEntry->pChain->szName,
- pEntry->pChain->cchName, NULL) == S_OK) ? HTTP_SUCCESS : HTTP_S_FALSE;
- }
-
- HTTP_CODE OnIsHeaderOneDimensional()
- {
- const _soapmapentry *pEntry = m_headerMap.GetValueAt(m_currHeaderPos);
- return (pEntry->pDims[0] == 1) ? HTTP_SUCCESS : HTTP_S_FALSE;
- }
-
- HTTP_CODE OnGetHeaderArraySize()
- {
- const _soapmapentry *pEntry = m_headerMap.GetValueAt(m_currHeaderPos);
- return (m_writeHelper.Write(pEntry->pDims[1]) != FALSE) ?
- HTTP_SUCCESS : HTTP_S_FALSE;
- }
-
- HTTP_CODE OnGetHeaderArraySoapDims()
- {
- return GetSoapDims(m_headerMap.GetValueAt(m_currHeaderPos));
- }
-
- HTTP_CODE OnGetNextFunctionHeader()
- {
- ++m_nHeader;
- if (m_pHeaders[m_nFunc]->pEntries[m_nHeader].nHash != 0)
- {
- if (m_pHeaders[m_nFunc]->pEntries[m_nHeader].dwFlags & SOAPFLAG_NOMARSHAL)
- {
- return OnGetNextHeader();
- }
- return HTTP_SUCCESS;
- }
- m_nHeader = -1;
- return HTTP_S_FALSE;
- }
-
- HTTP_CODE OnGetFunctionHeaderName()
- {
- return (m_pWriteStream->WriteStream(
- m_pHeaders[m_nFunc]->pEntries[m_nHeader].szField,
- m_pHeaders[m_nFunc]->pEntries[m_nHeader].cchField,
- NULL) == S_OK) ? HTTP_SUCCESS : HTTP_FAIL;
- }
-
- HTTP_CODE OnIsArrayHeader()
- {
- return (OnNotIsArrayHeader() == HTTP_SUCCESS) ? HTTP_S_FALSE : HTTP_SUCCESS;
- }
-
- HTTP_CODE OnIsDocumentLiteral()
- {
- if ((m_dwCallFlags & (SOAPFLAG_DOCUMENT | SOAPFLAG_LITERAL)) ==
- (SOAPFLAG_DOCUMENT | SOAPFLAG_LITERAL))
- {
- return HTTP_SUCCESS;
- }
- return HTTP_S_FALSE;
- }
-
- HTTP_CODE OnIsRpcEncoded()
- {
- if ((m_dwCallFlags & (SOAPFLAG_RPC | SOAPFLAG_ENCODED)) ==
- (SOAPFLAG_RPC | SOAPFLAG_ENCODED))
- {
- return HTTP_SUCCESS;
- }
- return HTTP_S_FALSE;
- }
-
-#pragma warning (push)
-#pragma warning (disable : 4640) // construction of local static object is not thread-safe
-
- BEGIN_REPLACEMENT_METHOD_MAP(_CSDLGenerator)
- REPLACEMENT_METHOD_ENTRY("GetNamespace", OnGetNamespace)
- REPLACEMENT_METHOD_ENTRY("GetNextFunction", OnGetNextFunction)
- REPLACEMENT_METHOD_ENTRY("GetFunctionName", OnGetFunctionName)
- REPLACEMENT_METHOD_ENTRY("GetNextParameter", OnGetNextParameter)
- REPLACEMENT_METHOD_ENTRY("IsInParameter", OnIsInParameter)
- REPLACEMENT_METHOD_ENTRY("GetParameterName", OnGetParameterName)
- REPLACEMENT_METHOD_ENTRY("NotIsArrayParameter", OnNotIsArrayParameter)
- REPLACEMENT_METHOD_ENTRY("IsParameterUDT", OnIsParameterUDT)
- REPLACEMENT_METHOD_ENTRY("GetParameterSoapType", OnGetParameterSoapType)
- REPLACEMENT_METHOD_ENTRY("IsParameterDynamicArray", OnIsParameterDynamicArray)
- REPLACEMENT_METHOD_ENTRY("IsArrayParameter", OnIsArrayParameter)
- REPLACEMENT_METHOD_ENTRY("IsParameterOneDimensional", OnIsParameterOneDimensional)
- REPLACEMENT_METHOD_ENTRY("GetParameterArraySize", OnGetParameterArraySize)
- REPLACEMENT_METHOD_ENTRY("GetParameterArraySoapDims", OnGetParameterArraySoapDims)
- REPLACEMENT_METHOD_ENTRY("IsOutParameter", OnIsOutParameter)
- REPLACEMENT_METHOD_ENTRY("GetNextEnum", OnGetNextEnum)
- REPLACEMENT_METHOD_ENTRY("GetEnumName", OnGetEnumName)
- REPLACEMENT_METHOD_ENTRY("GetNextEnumElement", OnGetNextEnumElement)
- REPLACEMENT_METHOD_ENTRY("GetEnumElementName", OnGetEnumElementName)
- REPLACEMENT_METHOD_ENTRY("GetNextStruct", OnGetNextStruct)
- REPLACEMENT_METHOD_ENTRY("GetStructName", OnGetStructName)
- REPLACEMENT_METHOD_ENTRY("GetNextStructField", OnGetNextStructField)
- REPLACEMENT_METHOD_ENTRY("GetStructFieldName", OnGetStructFieldName)
- REPLACEMENT_METHOD_ENTRY("NotIsArrayField", OnNotIsArrayField)
- REPLACEMENT_METHOD_ENTRY("IsFieldUDT", OnIsFieldUDT)
- REPLACEMENT_METHOD_ENTRY("GetStructFieldSoapType", OnGetStructFieldSoapType)
- REPLACEMENT_METHOD_ENTRY("IsArrayField", OnIsArrayField)
- REPLACEMENT_METHOD_ENTRY("IsFieldOneDimensional", OnIsFieldOneDimensional)
- REPLACEMENT_METHOD_ENTRY("GetFieldArraySize", OnGetFieldArraySize)
- REPLACEMENT_METHOD_ENTRY("GetFieldArraySoapDims", OnGetFieldArraySoapDims)
- REPLACEMENT_METHOD_ENTRY("GetServiceName", OnGetServiceName)
- REPLACEMENT_METHOD_ENTRY("GetURL", OnGetURL)
-
- REPLACEMENT_METHOD_ENTRY("GetNextHeader", OnGetNextHeader)
- REPLACEMENT_METHOD_ENTRY("GetHeaderName", OnGetHeaderName)
- REPLACEMENT_METHOD_ENTRY("NotIsArrayHeader", OnNotIsArrayHeader)
- REPLACEMENT_METHOD_ENTRY("IsArrayHeader", OnIsArrayHeader)
- REPLACEMENT_METHOD_ENTRY("IsHeaderUDT", OnIsHeaderUDT)
- REPLACEMENT_METHOD_ENTRY("GetHeaderSoapType", OnGetHeaderSoapType)
- REPLACEMENT_METHOD_ENTRY("IsHeaderOneDimensional", OnIsHeaderOneDimensional)
- REPLACEMENT_METHOD_ENTRY("GetHeaderArraySize", OnGetHeaderArraySize)
- REPLACEMENT_METHOD_ENTRY("GetHeaderArraySoapDims", OnGetHeaderArraySoapDims)
- REPLACEMENT_METHOD_ENTRY("GetNextFunctionHeader", OnGetNextFunctionHeader)
- REPLACEMENT_METHOD_ENTRY("GetFunctionHeaderName", OnGetFunctionHeaderName)
- REPLACEMENT_METHOD_ENTRY("IsInHeader", OnIsInHeader)
- REPLACEMENT_METHOD_ENTRY("IsOutHeader", OnIsOutHeader)
- REPLACEMENT_METHOD_ENTRY("IsRequiredHeader", OnIsRequiredHeader)
-
- REPLACEMENT_METHOD_ENTRY("IsDocumentLiteral", OnIsDocumentLiteral)
- REPLACEMENT_METHOD_ENTRY("IsRpcEncoded", OnIsRpcEncoded)
- REPLACEMENT_METHOD_ENTRY("IsFieldDynamicArray", OnIsFieldDynamicArray)
- REPLACEMENT_METHOD_ENTRY("GetFieldSizeIsName", OnGetFieldSizeIsName)
- END_REPLACEMENT_METHOD_MAP()
-
-#pragma warning (pop)
-
-}; // class _CSDLGenerator
-
-template <class THandler, const char *szHandlerName>
-class CSDLGenerator :
- public _CSDLGenerator,
- public IRequestHandlerImpl< CSDLGenerator<THandler,szHandlerName> >,
- public CComObjectRootEx<CComSingleThreadModel>
-{
-private:
-
-public:
- typedef CSDLGenerator<THandler, szHandlerName> _sdlGenerator;
-
- BEGIN_COM_MAP(_sdlGenerator)
- COM_INTERFACE_ENTRY(IRequestHandler)
- COM_INTERFACE_ENTRY(ITagReplacer)
- END_COM_MAP()
-
- HTTP_CODE InitializeHandler(AtlServerRequest *pRequestInfo, IServiceProvider *pServiceProvider)
- {
- IRequestHandlerImpl<CSDLGenerator>::InitializeHandler(pRequestInfo, pServiceProvider);
-
- CComObjectStack<THandler> handler;
- if (FAILED(InitializeSDL(&handler)))
- {
- return HTTP_FAIL;
- }
-
- CStencil s;
- HTTP_CODE hcErr = s.LoadFromString(s_szAtlsWSDLSrf, (DWORD) strlen(s_szAtlsWSDLSrf));
- if (hcErr == HTTP_SUCCESS)
- {
- hcErr = HTTP_FAIL;
- CHttpResponse HttpResponse(pRequestInfo->pServerContext);
- HttpResponse.SetContentType("text/xml");
- if (s.ParseReplacements(this) != false)
- {
- s.FinishParseReplacements();
-
- SetStream(&HttpResponse);
- SetWriteStream(&HttpResponse);
- SetHttpServerContext(m_spServerContext);
-
- ATLASSERT( s.ParseSuccessful() != false );
-
- hcErr = s.Render(this, &HttpResponse);
- }
- }
-
- return hcErr;
- }
-
- const char * GetHandlerName()
- {
- return szHandlerName;
- }
-}; // class CSDLGenerator
-
-} // namespace ATL
-#pragma pack(pop)
-
-#pragma warning(pop)
-
-#endif // __ATLSOAP_H__
diff --git a/include/atl/atlsrv.rc b/include/atl/atlsrv.rc
deleted file mode 100644
index a9d6b93a0..000000000
--- a/include/atl/atlsrv.rc
+++ /dev/null
@@ -1,146 +0,0 @@
-// This is a part of the Active Template Library.
-// Copyright (C) Microsoft Corporation
-// All rights reserved.
-//
-// This source code is only intended as a supplement to the
-// Active Template Library Reference and related
-// electronic documentation provided with the library.
-// See these sources for detailed information regarding the
-// Active Template Library product.
-
-#include <winresrc.h>
-#include "atlsrvres.h"
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// String Table
-//
-
-STRINGTABLE DISCARDABLE
-BEGIN
- IDS_ATLSRV_BAD_REQUEST "<html><head><title>Bad Request</title></head><body>Bad Request</body></html>"
- IDS_ATLSRV_AUTH_REQUIRED
- "<html><head><title>Authorization Required</title></head><body>Authorization is required</body></html>"
- IDS_ATLSRV_FORBIDDEN "<html><head><title>Forbidden</title></head><body>Forbidden</body></html>"
- IDS_ATLSRV_NOT_FOUND "<html><head><title>Not Found</title></head><body>Not Found</body></html>"
- IDS_ATLSRV_SERVER_ERROR "<html><head><title>Server Error</title></head><body>Server Error</body></html>"
- IDS_ATLSRV_NOT_IMPLEMENTED
- "<html><head><title>Not Implemented</title></head><body>Not Implemented</body></html>"
- IDS_ATLSRV_BAD_GATEWAY "<html><head><title>Bad Gateway</title></head><body>Bad Gateway</body></html>"
- IDS_ATLSRV_SERVICE_NOT_AVAILABLE
- "<html><head><title>Service Not Available</title></head><body>Service Not Available</body></html>"
- IDS_ATLSRV_SERVER_ERROR_BADSRF "<html><head><title>Server Error</title></head><body><H1>Server Error</H1><P>SRF file could not be loaded.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_HNDLFAIL "<html><head><title>Server Error</title></head><body><H1>Server Error</H1><P>The requested SRF file was loaded but could not be successfully processed.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_SYSOBJFAIL "<html><head><title>Server Error</title></head><body><H1>Server Error</H1><P>A Windows system object could not be created.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_READFILEFAIL "<html><head><title>Server Error</title></head><body><H1>Server Error</H1><P>A File read operation failed.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_LOADFILEFAIL "<html><head><title>Server Error</title></head><body><H1>Server Error</H1><P>The specified file could not be opened.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_LOADLIB "<html><head><title>Server Error</title></head><body><H1>Server Error</H1><P>LoadLibrary failed.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_HANDLERIF "<html><head><title>Server Error</title></head><body><H1>Server Error</H1><P>Failed to retrieve the request handler interface.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_OUTOFMEM "<html><head><title>Server Error</title></head><body><H1>Server Error</H1><P>Server is out of memory.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_UNEXPECTED "<html><head><title>Server Error</title></head><body><H1>Server Error</H1><P>The server encountered an unexpected error.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_STENCILPARSEFAIL "<html><head><title>Server Error</title></head><body><H1>Server Error</H1><P>The server encountered an unexpected error while trying to parse the requested stencil.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_STENCILLOADFAIL "<html><head><title>Server Error</title></head><body><H1>Server Error</H1><P>The server failed to load the requested stencil. The stencil file may be damaged or missing on this web server.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_HANDLERNOTFOUND "<html><head><title>Server Error</title></head><body><H1>Server Error</H1><P>One of the handlers named in a handler tag for the requested stencil could not be found in the specified handler .dll.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_BADHANDLERTAG "<html><head><title>Server Error</title></head><body><H1>Server Error</H1><P>This stencil contains a handler tag that could not be properly parsed by the stencil processor or does not contain a handler tag at all. Check the requested stencil for proper stencil syntax.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_NOHANDLERTAG "<html><head><title>Server Error</title></head><body><H1>Server Error</H1><P>The requested stencil does not contain a handler tag.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_LONGMETHODNAME "<html><head><title>Server Error</title></head><body><H1>Server Error</H1><P>A replacement tag was encountered in the requested stencil that had a replacement name that was too long. The maximum length of the replacment name must be less than or equal to the ATL_MAX_METHOD_NAME constant defined in atlstencil.h</body></html>"
- IDS_ATLSRV_SERVER_ERROR_LONGHANDLERNAME "<html><head><title>Server Error</title></head><body><H1>Server Error</H1><P>A replacement tag that uses the id.tagname syntax was encountered in the requested stencil that had a handler name that was too long. The maximum length of the handler name must be less than or equal to the ATL_MAX_METHOD_NAME constant defined in atlstencil.h</body></html>"
- IDS_ATLSRV_SERVER_ERROR_IMPERSONATIONFAILED "<html><head><title>Server Error</title></head><body><H1>Server Error</H1><P>An attempt to impersonate the client making the request failed.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_ISAPISTARTUPFAILED "<html><head><title>Server Error</title></head><body><H1>Server Error</H1><P>The ISAPI extension used to service this request failed to load correctly due to an unknown error.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_SOAPNOSOAPACTION "<html><head><title>Server Error</title></head><body><H1>Server Error</H1><P>SOAP request did not provide SOAPACTION header.</body></html>"
-
- IDS_ATLSRV_CRITICAL_HEAPCREATEFAILED "Request heap creation failed"
- IDS_ATLSRV_CRITICAL_WORKERINITFAILED "Worker Thread initialization failed"
- IDS_ATLSRV_CRITICAL_CRITSECINITFAILED "Critical section initialization failed"
- IDS_ATLSRV_CRITICAL_THREADPOOLFAILED "Thread pool initialization failed"
- IDS_ATLSRV_CRITICAL_DLLCACHEFAILED "DLL cache initialization failed"
- IDS_ATLSRV_CRITICAL_PAGECACHEFAILED "Page cache initialization failed"
- IDS_ATLSRV_CRITICAL_STENCILCACHEFAILED "Stencil cache initialization failed"
- IDS_ATLSRV_CRITICAL_SESSIONSTATEFAILED "Session state service initialization failed"
- IDS_ATLSRV_CRITICAL_BLOBCACHEFAILED "Blob cache initialization failed"
- IDS_ATLSRV_CRITICAL_FILECACHEFAILED "File cache initialization failed"
-
- IDS_PERFMON_CACHE "ATL Server:Cache"
- IDS_PERFMON_CACHE_HELP "Information about the ATL Server cache"
- IDS_PERFMON_HITCOUNT "Cache Hit Count"
- IDS_PERFMON_HITCOUNT_HELP "Number of cache hits"
- IDS_PERFMON_MISSCOUNT "Cache Miss Count"
- IDS_PERFMON_MISSCOUNT_HELP "Number of cache misses"
- IDS_PERFMON_CURRENTALLOCATIONS "Cache Current Allocations"
- IDS_PERFMON_CURRENTALLOCATIONS_HELP "Current Memory allocated for cache"
- IDS_PERFMON_MAXALLOCATIONS "Cache Max Allocations"
- IDS_PERFMON_MAXALLOCATIONS_HELP "Maximum memory allocated for cache"
- IDS_PERFMON_CURRENTENTRIES "Cache Current Entries"
- IDS_PERFMON_CURRENTENTRIES_HELP "Current number of cache entries"
- IDS_PERFMON_MAXENTRIES "Cache Max Entries"
- IDS_PERFMON_MAXENTRIES_HELP "Maximum number of cache entries"
- IDS_PERFMON_HITCOUNTRATE "Cache Hit Count Rate"
- IDS_PERFMON_HITCOUNTRATE_HELP "Number of hit counts per second"
- IDS_PERFMON_REQUEST "ATL Server:Request"
- IDS_PERFMON_REQUEST_HELP "Statistics about the requests coming into the server"
- IDS_PERFMON_REQUEST_TOTAL "Server Total Requests"
- IDS_PERFMON_REQUEST_TOTAL_HELP "The total number of requests"
- IDS_PERFMON_REQUEST_FAILED "Server Failed Requests"
- IDS_PERFMON_REQUEST_FAILED_HELP "The number of failed requests"
- IDS_PERFMON_REQUEST_RATE "Server Requests /sec"
- IDS_PERFMON_REQUEST_RATE_HELP "Number of requests per second"
- IDS_PERFMON_REQUEST_AVG_RESPONSE_TIME "Average Response Time"
- IDS_PERFMON_REQUEST_AVG_RESPONSE_TIME_HELP "Average time spent handling a request"
- IDS_PERFMON_REQUEST_CURR_WAITING "Current Queued Requests"
- IDS_PERFMON_REQUEST_CURR_WAITING_HELP "Current number of requests waiting to be handled"
- IDS_PERFMON_REQUEST_MAX_WAITING "Maximum Queued Requests"
- IDS_PERFMON_REQUEST_MAX_WAITING_HELP "Maximum number of requests waiting to be handled"
- IDS_PERFMON_REQUEST_ACTIVE_THREADS "Active Threads"
- IDS_PERFMON_REQUEST_ACTIVE_THREADS_HELP "The number of threads actively handling requests"
-END
-
-
-#ifndef ATL_NO_DEFAULT_STENCIL_RESOURCE
-dllmgr.srf HTML "res\\dllmgr.srf"
-stencilmgr.srf HTML "res\\stencilmgr.srf"
-threadmgr.srf HTML "res\\threadmgr.srf"
-#endif
-
-
-//
-// Stencil parse error support
-//
-#ifdef ATL_DEBUG_STENCILS
-
-STRINGTABLE DISCARDABLE
-BEGIN
- IDS_STENCIL_ERROR_STENCIL
-"{{codepage 0}}<h1><font color=#ff0000> While trying to parse a stencil file, the following errors occurred:</font></h1>\r\n{{while GetNextError}}<table border=1 width=50%>\r\n<tr><td width=25%>Error type</td><td>{{GetErrorText}}</td></tr>\r\n<tr><td>Line number</td><td>{{GetErrorLineNumber}}</td></tr>\r\n<tr><td>Error text</td><td><pre>{{GetErrorLine}}</pre></td></tr>\r\n</table>\r\n{{endwhile}}<br>Stencil output follows:\r\n<hr>"
-
- IDS_STENCIL_UNCLOSEDBLOCK_IF "{{if}} without {{endif}}"
- IDS_STENCIL_UNCLOSEDBLOCK_ELSE "{{else}} without {{endif}}"
- IDS_STENCIL_UNCLOSEDBLOCK_WHILE "{{while}} without {{endwhile}}"
- IDS_STENCIL_UNOPENEDBLOCK_ENDWHILE "{{endwhile}} without {{while}}"
- IDS_STENCIL_UNOPENEDBLOCK_ELSE "{{else}} without {{if}}"
- IDS_STENCIL_UNOPENEDBLOCK_ENDIF "{{endif}} without {{if}} or {{else}}"
-
- IDS_STENCIL_INVALID_HANDLER "Invalid handler tag"
- IDS_STENCIL_NULLPARAM "NULL parameter to ParseReplacements"
- IDS_STENCIL_INVALIDSTRING "Empty or negative string passed to ParseReplacements"
- IDS_STENCIL_EMBEDDED_NULL "Embedded null character in stencil"
- IDS_STENCIL_UNMATCHED_TAG_START "Unmatched {{"
- IDS_STENCIL_MISMATCHED_TAG_START "Mismatched {{"
- IDS_STENCIL_BAD_PARAMETER "Bad parameter"
- IDS_STENCIL_METHODNAME_TOO_LONG "Method name too long"
- IDS_STENCIL_HANDLERNAME_TOO_LONG "Handler name too long"
- IDS_STENCIL_INVALID_SUBHANDLER "Invalid subhandler tag"
- IDS_STENCIL_UNRESOLVED_REPLACEMENT "Unresolved replacement : '%s'"
-
- IDS_STENCIL_INCLUDE_ERROR "Could not open included file"
- IDS_STENCIL_INCLUDE_INVALID "Included file is not a disk file"
-
- IDS_STENCIL_MLANG_COCREATE "Couldn't create CMultiLanguage"
- IDS_STENCIL_MLANG_LCID "Error getting lcid"
- IDS_STENCIL_MLANG_GETLOCALE "GetLocaleInfo failed"
- IDS_STENCIL_MLANG_GETCHARSET "GetCharsetInfo failed"
-
- IDS_STENCIL_OUTOFMEMORY "Out of memory"
- IDS_STENCIL_UNEXPECTED "Unexpected error"
-END
-
-#endif
diff --git a/include/atl/l.chs/atlsrv.rc b/include/atl/l.chs/atlsrv.rc
deleted file mode 100644
index 281ab2371..000000000
--- a/include/atl/l.chs/atlsrv.rc
+++ /dev/null
@@ -1,146 +0,0 @@
-// This is a part of the Active Template Library.
-// Copyright (C) Microsoft Corporation
-// All rights reserved.
-//
-// This source code is only intended as a supplement to the
-// Active Template Library Reference and related
-// electronic documentation provided with the library.
-// See these sources for detailed information regarding the
-// Active Template Library product.
-
-#include <winresrc.h>
-#include "atlsrvres.h"
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// String Table
-//
-
-STRINGTABLE DISCARDABLE
-BEGIN
- IDS_ATLSRV_BAD_REQUEST "<html><head><title></title></head><body></body></html>"
- IDS_ATLSRV_AUTH_REQUIRED
- "<html><head><title>Ҫ֤</title></head><body>Ҫ֤</body></html>"
- IDS_ATLSRV_FORBIDDEN "<html><head><title>ֹ</title></head><body>ֹ</body></html>"
- IDS_ATLSRV_NOT_FOUND "<html><head><title>δҵ</title></head><body>δҵ</body></html>"
- IDS_ATLSRV_SERVER_ERROR "<html><head><title></title></head><body></body></html>"
- IDS_ATLSRV_NOT_IMPLEMENTED
- "<html><head><title>δʵ</title></head><body>δʵ</body></html>"
- IDS_ATLSRV_BAD_GATEWAY "<html><head><title></title></head><body></body></html>"
- IDS_ATLSRV_SERVICE_NOT_AVAILABLE
- "<html><head><title>񲻿</title></head><body>񲻿</body></html>"
- IDS_ATLSRV_SERVER_ERROR_BADSRF "<html><head><title>Server Error</title></head><body><H1></H1><P>޷ SRF ļ</body></html>"
- IDS_ATLSRV_SERVER_ERROR_HNDLFAIL "<html><head><title></title></head><body><H1></H1><P> SRF Ѽأ޷ȷ</body></html>"
- IDS_ATLSRV_SERVER_ERROR_SYSOBJFAIL "<html><head><title></title></head><body><H1></H1><P>޷ Windows ϵͳ</body></html>"
- IDS_ATLSRV_SERVER_ERROR_READFILEFAIL "<html><head><title></title></head><body><H1></H1><P>ļʧܡ</body></html>"
- IDS_ATLSRV_SERVER_ERROR_LOADFILEFAIL "<html><head><title></title></head><body><H1></H1><P>ָļ޷򿪡</body></html>"
- IDS_ATLSRV_SERVER_ERROR_LOADLIB "<html><head><title></title></head><body><H1></H1><P>LoadLibrary ʧܡ</body></html>"
- IDS_ATLSRV_SERVER_ERROR_HANDLERIF "<html><head><title></title></head><body><H1></H1><P>ӿʧܡ</body></html>"
- IDS_ATLSRV_SERVER_ERROR_OUTOFMEM "<html><head><title></title></head><body><H1></H1><P>ڴ治㡣</body></html>"
- IDS_ATLSRV_SERVER_ERROR_UNEXPECTED "<html><head><title></title></head><body><H1></H1><P></body></html>"
- IDS_ATLSRV_SERVER_ERROR_STENCILPARSEFAIL "<html><head><title></title></head><body><H1></H1><P>ͼģʱ</body></html>"
- IDS_ATLSRV_SERVER_ERROR_STENCILLOADFAIL "<html><head><title></title></head><body><H1></H1><P>δܼģ塣ģļ𻵻ڸ Web ϡ</body></html>"
- IDS_ATLSRV_SERVER_ERROR_HANDLERNOTFOUND "<html><head><title></title></head><body><H1></H1><P>ָ .dll δҵģĴij</body></html>"
- IDS_ATLSRV_SERVER_ERROR_BADHANDLERTAG "<html><head><title></title></head><body><H1></H1><P>ģһ޷ģ崦ȷĴǣ߸ģûаǡ鿴ģ壬˽ȷģ﷨</body></html>"
- IDS_ATLSRV_SERVER_ERROR_NOHANDLERTAG "<html><head><title></title></head><body><H1></H1><P>ģûадǡ</body></html>"
- IDS_ATLSRV_SERVER_ERROR_LONGMETHODNAME "<html><head><title></title></head><body><H1></H1><P>ģзһ滻ǣ滻ǵ滻ƹ滻Ƶ󳤶ȱСڻ atlstencil.h жij ATL_MAX_METHOD_NAME</body></html>"
- IDS_ATLSRV_SERVER_ERROR_LONGHANDLERNAME "<html><head><title></title></head><body><H1></H1><P>ģзһʹ id.tagname ﷨滻ǡƵ󳤶ȱСڻ atlstencil.h жij ATL_MAX_METHOD_NAME</body></html>"
- IDS_ATLSRV_SERVER_ERROR_IMPERSONATIONFAILED "<html><head><title></title></head><body><H1></H1><P>ģͻijʧܡ</body></html>"
- IDS_ATLSRV_SERVER_ERROR_ISAPISTARTUPFAILED "<html><head><title></title></head><body><H1></H1><P>ڷδ֪ڴ ISAPI չ޷ȷء</body></html>"
- IDS_ATLSRV_SERVER_ERROR_SOAPNOSOAPACTION "<html><head><title>Server Error</title></head><body><H1>Server Error</H1><P>SOAP request did not provide SOAPACTION header.</body></html>"
-
- IDS_ATLSRV_CRITICAL_HEAPCREATEFAILED "Ѵʧ"
- IDS_ATLSRV_CRITICAL_WORKERINITFAILED "̳߳ʼʧ"
- IDS_ATLSRV_CRITICAL_CRITSECINITFAILED "ٽʼʧ"
- IDS_ATLSRV_CRITICAL_THREADPOOLFAILED "̳߳سʼʧ"
- IDS_ATLSRV_CRITICAL_DLLCACHEFAILED "DLL ʼʧ"
- IDS_ATLSRV_CRITICAL_PAGECACHEFAILED "Page ʼʧ"
- IDS_ATLSRV_CRITICAL_STENCILCACHEFAILED "ģ建ʼʧ"
- IDS_ATLSRV_CRITICAL_SESSIONSTATEFAILED "Ự״̬ʼʧ"
- IDS_ATLSRV_CRITICAL_BLOBCACHEFAILED "Blob ʼʧ"
- IDS_ATLSRV_CRITICAL_FILECACHEFAILED "ļʼʧ"
-
- IDS_PERFMON_CACHE "ATL Server:"
- IDS_PERFMON_CACHE_HELP "ATL Server Ϣ"
- IDS_PERFMON_HITCOUNT ""
- IDS_PERFMON_HITCOUNT_HELP "лĿ"
- IDS_PERFMON_MISSCOUNT "δ"
- IDS_PERFMON_MISSCOUNT_HELP "δлĿ"
- IDS_PERFMON_CURRENTALLOCATIONS "浱ǰ"
- IDS_PERFMON_CURRENTALLOCATIONS_HELP "ĵǰڴС"
- IDS_PERFMON_MAXALLOCATIONS ""
- IDS_PERFMON_MAXALLOCATIONS_HELP "ڴС"
- IDS_PERFMON_CURRENTENTRIES "ǰ"
- IDS_PERFMON_CURRENTENTRIES_HELP "ǰĿ"
- IDS_PERFMON_MAXENTRIES ""
- IDS_PERFMON_MAXENTRIES_HELP "Ŀ"
- IDS_PERFMON_HITCOUNTRATE ""
- IDS_PERFMON_HITCOUNTRATE_HELP "ÿлĴ"
- IDS_PERFMON_REQUEST "ATL Server:"
- IDS_PERFMON_REQUEST_HELP "ڽ÷ͳϢ"
- IDS_PERFMON_REQUEST_TOTAL ""
- IDS_PERFMON_REQUEST_TOTAL_HELP ""
- IDS_PERFMON_REQUEST_FAILED "ʧ"
- IDS_PERFMON_REQUEST_FAILED_HELP "ʧܵĿ"
- IDS_PERFMON_REQUEST_RATE "/"
- IDS_PERFMON_REQUEST_RATE_HELP "ÿĿ"
- IDS_PERFMON_REQUEST_AVG_RESPONSE_TIME "ƽӦʱ"
- IDS_PERFMON_REQUEST_AVG_RESPONSE_TIME_HELP "ƽʱ"
- IDS_PERFMON_REQUEST_CURR_WAITING "ǰе"
- IDS_PERFMON_REQUEST_CURR_WAITING_HELP "ǰȴĿ"
- IDS_PERFMON_REQUEST_MAX_WAITING "Ŀ"
- IDS_PERFMON_REQUEST_MAX_WAITING_HELP "ȴĿ"
- IDS_PERFMON_REQUEST_ACTIVE_THREADS "߳"
- IDS_PERFMON_REQUEST_ACTIVE_THREADS_HELP "ڴĻ߳"
-END
-
-
-#ifndef ATL_NO_DEFAULT_STENCIL_RESOURCE
-dllmgr.srf HTML "res\\dllmgr.srf"
-stencilmgr.srf HTML "res\\stencilmgr.srf"
-threadmgr.srf HTML "res\\threadmgr.srf"
-#endif
-
-
-//
-// Stencil parse error support
-//
-#ifdef ATL_DEBUG_STENCILS
-
-STRINGTABLE DISCARDABLE
-BEGIN
- IDS_STENCIL_ERROR_STENCIL
-"{{codepage 0}}<h1><font color=#ff0000>ͼģļʱ´</font></h1>\r\n{{while GetNextError}}<table border=1 width=50%>\r\n<tr><td width=25%></td><td>{{GetErrorText}}</td></tr>\r\n<tr><td>к</td><td>{{GetErrorLineNumber}}</td></tr>\r\n<tr><td>ı</td><td><pre>{{GetErrorLine}}</pre></td></tr>\r\n</table>\r\n{{endwhile}}<br>ģΪ\r\n<hr>"
-
- IDS_STENCIL_UNCLOSEDBLOCK_IF "{{if}} ȱ {{endif}}"
- IDS_STENCIL_UNCLOSEDBLOCK_ELSE "{{else}} ȱ {{endif}}"
- IDS_STENCIL_UNCLOSEDBLOCK_WHILE "{{while}} ȱ {{endwhile}}"
- IDS_STENCIL_UNOPENEDBLOCK_ENDWHILE "{{endwhile}} ȱ {{while}}"
- IDS_STENCIL_UNOPENEDBLOCK_ELSE "{{else}} ȱ {{if}}"
- IDS_STENCIL_UNOPENEDBLOCK_ENDIF "{{endif}} ȱ {{if}} or {{else}}"
-
- IDS_STENCIL_INVALID_HANDLER "ЧĴ"
- IDS_STENCIL_NULLPARAM "ParseReplacements Ϊ Null "
- IDS_STENCIL_INVALIDSTRING "ݸ ParseReplacements ַΪջΪ"
- IDS_STENCIL_EMBEDDED_NULL "ǶģеĿַ"
- IDS_STENCIL_UNMATCHED_TAG_START "ƥ {{"
- IDS_STENCIL_MISMATCHED_TAG_START "ƥ {{"
- IDS_STENCIL_BAD_PARAMETER "IJ"
- IDS_STENCIL_METHODNAME_TOO_LONG "ƹ"
- IDS_STENCIL_HANDLERNAME_TOO_LONG "ƹ"
- IDS_STENCIL_INVALID_SUBHANDLER "ЧӴ"
- IDS_STENCIL_UNRESOLVED_REPLACEMENT "޷滻 : '%s'"
-
- IDS_STENCIL_INCLUDE_ERROR "޷򿪱ļ"
- IDS_STENCIL_INCLUDE_INVALID "ļǴļ"
-
- IDS_STENCIL_MLANG_COCREATE "޷ CMultiLanguage"
- IDS_STENCIL_MLANG_LCID "ȡ lcid "
- IDS_STENCIL_MLANG_GETLOCALE "GetLocaleInfo ʧ"
- IDS_STENCIL_MLANG_GETCHARSET "GetCharsetInfo ʧ"
-
- IDS_STENCIL_OUTOFMEMORY "ڴ治"
- IDS_STENCIL_UNEXPECTED "쳣"
-END
-
-#endif
diff --git a/include/atl/l.cht/atlsrv.rc b/include/atl/l.cht/atlsrv.rc
deleted file mode 100644
index 2d9f7340d..000000000
--- a/include/atl/l.cht/atlsrv.rc
+++ /dev/null
@@ -1,146 +0,0 @@
-// This is a part of the Active Template Library.
-// Copyright (C) Microsoft Corporation
-// All rights reserved.
-//
-// This source code is only intended as a supplement to the
-// Active Template Library Reference and related
-// electronic documentation provided with the library.
-// See these sources for detailed information regarding the
-// Active Template Library product.
-
-#include <winresrc.h>
-#include "atlsrvres.h"
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// String Table
-//
-
-STRINGTABLE DISCARDABLE
-BEGIN
- IDS_ATLSRV_BAD_REQUEST "<html><head><title>TnD</title></head><body>TnD</body></html>"
- IDS_ATLSRV_AUTH_REQUIRED
- "<html><head><title>ݭnv</title></head><body>ݭnv</body></html>"
- IDS_ATLSRV_FORBIDDEN "<html><head><title>Tϥ</title></head><body>Tϥ</body></html>"
- IDS_ATLSRV_NOT_FOUND "<html><head><title>䤣</title></head><body>䤣</body></html>"
- IDS_ATLSRV_SERVER_ERROR "<html><head><title>A~</title></head><body>A~</body></html>"
- IDS_ATLSRV_NOT_IMPLEMENTED
- "<html><head><title>@</title></head><body>@</body></html>"
- IDS_ATLSRV_BAD_GATEWAY "<html><head><title>ThD</title></head><body>ThD</body></html>"
- IDS_ATLSRV_SERVICE_NOT_AVAILABLE
- "<html><head><title>LkoA</title></head><body>LkoA</body></html>"
- IDS_ATLSRV_SERVER_ERROR_BADSRF "<html><head><title>A~</title></head><body><H1>A~</H1><P>LkJ SRF ɡC</body></html>"
- IDS_ATLSRV_SERVER_ERROR_HNDLFAIL "<html><head><title>A~</title></head><body><H1>A~</H1><P>wgJnD SRF ɡALk\BzC</body></html>"
- IDS_ATLSRV_SERVER_ERROR_SYSOBJFAIL "<html><head><title>A~</title></head><body><H1>A~</H1><P>Lkإ Windows tΪC</body></html>"
- IDS_ATLSRV_SERVER_ERROR_READFILEFAIL "<html><head><title>A~</title></head><body><H1>A~</H1><P>ɮŪ@~wѡC</body></html>"
- IDS_ATLSRV_SERVER_ERROR_LOADFILEFAIL "<html><head><title>A~</title></head><body><H1>A~</H1><P>Lk}ҫwɮסC</body></html>"
- IDS_ATLSRV_SERVER_ERROR_LOADLIB "<html><head><title>A~</title></head><body><H1>A~</H1><P>LoadLibrary wѡC</body></html>"
- IDS_ATLSRV_SERVER_ERROR_HANDLERIF "<html><head><title>A~</title></head><body><H1>A~</H1><P>Lk^nDBz`C</body></html>"
- IDS_ATLSRV_SERVER_ERROR_OUTOFMEM "<html><head><title>A~</title></head><body><H1>A~</H1><P>AO餣C</body></html>"
- IDS_ATLSRV_SERVER_ERROR_UNEXPECTED "<html><head><title>A~</title></head><body><H1>A~</H1><P>Aoͥw~C</body></html>"
- IDS_ATLSRV_SERVER_ERROR_STENCILPARSEFAIL "<html><head><title>A~</title></head><body><H1>A~</H1><P>խRnDҪOɡAAoͥw~C</body></html>"
- IDS_ATLSRV_SERVER_ERROR_STENCILLOADFAIL "<html><head><title>A~</title></head><body><H1>A~</H1><P>ALkJnDҪOCҪOɥiwlΤb Web AWC</body></html>"
- IDS_ATLSRV_SERVER_ERROR_HANDLERNOTFOUND "<html><head><title>A~</title></head><body><H1>A~</H1><P>bw handler .dll A䤣bnDҪOBz`аORWYӳBz`C</body></html>"
- IDS_ATLSRV_SERVER_ERROR_BADHANDLERTAG "<html><head><title>A~</title></head><body><H1>A~</H1><P>ҪO]tҪOBzLkARBz`аOAΥ]tBz`аOCˬdnDҪOO_ϥξAXҪOykC</body></html>"
- IDS_ATLSRV_SERVER_ERROR_NOHANDLERTAG "<html><head><title>A~</title></head><body><H1>A~</H1><P>nDҪO]tBz`аOC</body></html>"
- IDS_ATLSRV_SERVER_ERROR_LONGMETHODNAME "<html><head><title>A~</title></head><body><H1>A~</H1><P>bnDҪOo{NаONW٤ӪCNWٳ̪ץpεb atlstencil.h ҩwq ATL_MAX_METHOD_NAME `ơC</body></html>"
- IDS_ATLSRV_SERVER_ERROR_LONGHANDLERNAME "<html><head><title>A~</title></head><body><H1>A~</H1><P>bnDҪOϥ id.tagname ykNаOBz`W٤ӪCBz`Wٳ̪ץpεb atlstencil.h ҩwq ATL_MAX_METHOD_NAME `ơC</body></html>"
- IDS_ATLSRV_SERVER_ERROR_IMPERSONATIONFAILED "<html><head><title>A~</title></head><body><H1>A~</H1><P>ռΤݳynDѡC</body></html>"
- IDS_ATLSRV_SERVER_ERROR_ISAPISTARTUPFAILED "<html><head><title>A~</title></head><body><H1>A~</H1><P>]oͥ~ALkTJΨӪAȦnD ISAPI XR{C</body></html>"
- IDS_ATLSRV_SERVER_ERROR_SOAPNOSOAPACTION "<html><head><title>Server Error</title></head><body><H1>Server Error</H1><P>SOAP request did not provide SOAPACTION header.</body></html>"
-
- IDS_ATLSRV_CRITICAL_HEAPCREATEFAILED "nDnإߥ"
- IDS_ATLSRV_CRITICAL_WORKERINITFAILED "Iu@lƥ"
- IDS_ATLSRV_CRITICAL_CRITSECINITFAILED "Ϭqlƥ"
- IDS_ATLSRV_CRITICAL_THREADPOOLFAILED "Ϫlƥ"
- IDS_ATLSRV_CRITICAL_DLLCACHEFAILED "DLL ֨lƥ"
- IDS_ATLSRV_CRITICAL_PAGECACHEFAILED "֨lƥ"
- IDS_ATLSRV_CRITICAL_STENCILCACHEFAILED "ҪO֨lƥ"
- IDS_ATLSRV_CRITICAL_SESSIONSTATEFAILED "u@qAAȪlƥ"
- IDS_ATLSRV_CRITICAL_BLOBCACHEFAILED "Blob ֨lƥ"
- IDS_ATLSRV_CRITICAL_FILECACHEFAILED "ɮק֨lƥ"
-
- IDS_PERFMON_CACHE "ATL Server:֨"
- IDS_PERFMON_CACHE_HELP " ATL Server ֨T"
- IDS_PERFMON_HITCOUNT "֨sΦ"
- IDS_PERFMON_HITCOUNT_HELP "֨sΪ"
- IDS_PERFMON_MISSCOUNT "֨|"
- IDS_PERFMON_MISSCOUNT_HELP "֨|"
- IDS_PERFMON_CURRENTALLOCATIONS "֨ثetm"
- IDS_PERFMON_CURRENTALLOCATIONS_HELP "֨ثeOtm"
- IDS_PERFMON_MAXALLOCATIONS "֨tmW"
- IDS_PERFMON_MAXALLOCATIONS_HELP "̤֨jOtm"
- IDS_PERFMON_CURRENTENTRIES "֨ثe"
- IDS_PERFMON_CURRENTENTRIES_HELP "ثe֨ؼ"
- IDS_PERFMON_MAXENTRIES "֨ؤW"
- IDS_PERFMON_MAXENTRIES_HELP "֨ت̤j"
- IDS_PERFMON_HITCOUNTRATE "֨sβv"
- IDS_PERFMON_HITCOUNTRATE_HELP "C֨sΪƥ"
- IDS_PERFMON_REQUEST "ATL Server:nD"
- IDS_PERFMON_REQUEST_HELP "iJAnDέp"
- IDS_PERFMON_REQUEST_TOTAL "AnD`"
- IDS_PERFMON_REQUEST_TOTAL_HELP "nD`"
- IDS_PERFMON_REQUEST_FAILED "AѭnD"
- IDS_PERFMON_REQUEST_FAILED_HELP "ѭnDƥ"
- IDS_PERFMON_REQUEST_RATE "AnD /"
- IDS_PERFMON_REQUEST_RATE_HELP "CnDƥ"
- IDS_PERFMON_REQUEST_AVG_RESPONSE_TIME "^ɶ"
- IDS_PERFMON_REQUEST_AVG_RESPONSE_TIME_HELP "BznDҪOɶ"
- IDS_PERFMON_REQUEST_CURR_WAITING "ثewƤJCnD"
- IDS_PERFMON_REQUEST_CURR_WAITING_HELP "ثeԳBznDƥ"
- IDS_PERFMON_REQUEST_MAX_WAITING "CnDW"
- IDS_PERFMON_REQUEST_MAX_WAITING_HELP "ԳBznD̤j"
- IDS_PERFMON_REQUEST_ACTIVE_THREADS "@Τ"
- IDS_PERFMON_REQUEST_ACTIVE_THREADS_HELP "bBznDƥ"
-END
-
-
-#ifndef ATL_NO_DEFAULT_STENCIL_RESOURCE
-dllmgr.srf HTML "res\\dllmgr.srf"
-stencilmgr.srf HTML "res\\stencilmgr.srf"
-threadmgr.srf HTML "res\\threadmgr.srf"
-#endif
-
-
-//
-// Stencil parse error support
-//
-#ifdef ATL_DEBUG_STENCILS
-
-STRINGTABLE DISCARDABLE
-BEGIN
- IDS_STENCIL_ERROR_STENCIL
-"{{codepage 0}}<h1><font color=#ff0000> խRҪOɮɡAoͤUC~:</font></h1>\r\n{{while GetNextError}}<table border=1 width=50%>\r\n<tr><td width=25%>~</td><td>{{GetErrorText}}</td></tr>\r\n<tr><td>渹</td><td>{{GetErrorLineNumber}}</td></tr>\r\n<tr><td>~r</td><td><pre>{{GetErrorLine}}</pre></td></tr>\r\n</table>\r\n{{endwhile}}<br>᪺ҪOX:\r\n<hr>"
-
- IDS_STENCIL_UNCLOSEDBLOCK_IF " {{if}} S {{endif}}"
- IDS_STENCIL_UNCLOSEDBLOCK_ELSE " {{else}} S {{endif}}"
- IDS_STENCIL_UNCLOSEDBLOCK_WHILE " {{while}} S {{endwhile}}"
- IDS_STENCIL_UNOPENEDBLOCK_ENDWHILE " {{endwhile}} S {{while}}"
- IDS_STENCIL_UNOPENEDBLOCK_ELSE " {{else}} S {{if}}"
- IDS_STENCIL_UNOPENEDBLOCK_ENDIF " {{endif}} S {{if}} {{else}}"
-
- IDS_STENCIL_INVALID_HANDLER "LĪBz`аO"
- IDS_STENCIL_NULLPARAM "ParseReplacements NULL Ѽ"
- IDS_STENCIL_INVALIDSTRING "ǻ ParseReplacements ŪέtȦr"
- IDS_STENCIL_EMBEDDED_NULL "ҪOOJ Null r"
- IDS_STENCIL_UNMATCHED_TAG_START "۲Ū {{"
- IDS_STENCIL_MISMATCHED_TAG_START "۲Ū {{"
- IDS_STENCIL_BAD_PARAMETER "TѼ"
- IDS_STENCIL_METHODNAME_TOO_LONG "kW٤Ӫ"
- IDS_STENCIL_HANDLERNAME_TOO_LONG "Bz`W٤Ӫ"
- IDS_STENCIL_INVALID_SUBHANDLER "LĪlBz`аO"
- IDS_STENCIL_UNRESOLVED_REPLACEMENT "LkѪRN : '%s'"
-
- IDS_STENCIL_INCLUDE_ERROR "Lk}ҥ]tɮ"
- IDS_STENCIL_INCLUDE_INVALID "]tɮפOϺɮ"
-
- IDS_STENCIL_MLANG_COCREATE "Lkإ CMultiLanguage"
- IDS_STENCIL_MLANG_LCID "o lcid oͿ~"
- IDS_STENCIL_MLANG_GETLOCALE "GetLocaleInfo "
- IDS_STENCIL_MLANG_GETCHARSET "GetCharsetInfo "
-
- IDS_STENCIL_OUTOFMEMORY "O餣"
- IDS_STENCIL_UNEXPECTED "w~"
-END
-
-#endif
diff --git a/include/atl/l.deu/atlsrv.rc b/include/atl/l.deu/atlsrv.rc
deleted file mode 100644
index 2ffca35c6..000000000
--- a/include/atl/l.deu/atlsrv.rc
+++ /dev/null
@@ -1,146 +0,0 @@
-// This is a part of the Active Template Library.
-// Copyright (C) Microsoft Corporation
-// All rights reserved.
-//
-// This source code is only intended as a supplement to the
-// Active Template Library Reference and related
-// electronic documentation provided with the library.
-// See these sources for detailed information regarding the
-// Active Template Library product.
-
-#include <winresrc.h>
-#include "atlsrvres.h"
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// String Table
-//
-
-STRINGTABLE DISCARDABLE
-BEGIN
- IDS_ATLSRV_BAD_REQUEST "<html><head><title>Ungltige Anforderung</title></head><body>Ungltige Anforderung</body></html>"
- IDS_ATLSRV_AUTH_REQUIRED
- "<html><head><title>Authorisierung erforderlich</title></head><body>Authorisierung erforderlich</body></html>"
- IDS_ATLSRV_FORBIDDEN "<html><head><title>Unzulssig</title></head><body>Unzulssig</body></html>"
- IDS_ATLSRV_NOT_FOUND "<html><head><title>Nicht gefunden</title></head><body>Nicht gefunden</body></html>"
- IDS_ATLSRV_SERVER_ERROR "<html><head><title>Serverfehler</title></head><body>Serverfehler</body></html>"
- IDS_ATLSRV_NOT_IMPLEMENTED
- "<html><head><title>Nicht implementiert</title></head><body>Nicht implementiert</body></html>"
- IDS_ATLSRV_BAD_GATEWAY "<html><head><title>Ungltiger Gateway</title></head><body>Ungltiger Gateway</body></html>"
- IDS_ATLSRV_SERVICE_NOT_AVAILABLE
- "<html><head><title>Dienst nicht verfgbar</title></head><body>Dienst nicht verfgbar</body></html>"
- IDS_ATLSRV_SERVER_ERROR_BADSRF "<html><head><title>Serverfehler</title></head><body><H1>Serverfehler</H1><P>SRF-Datei konnte nicht geladen werden.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_HNDLFAIL "<html><head><title>Serverfehler</title></head><body><H1>Serverfehler</H1><P>Die angeforderte SRF-Datei wurde geladen, aber konnte nicht verarbeitet werden.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_SYSOBJFAIL "<html><head><title>Serverfehler</title></head><body><H1>Serverfehler</H1><P>Ein Windows-Systemobjekt konnte nicht erstellt werden.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_READFILEFAIL "<html><head><title>Serverfehler</title></head><body><H1>Serverfehler</H1><P>Ein Dateilesevorgang ist fehlgeschlagen.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_LOADFILEFAIL "<html><head><title>Serverfehler</title></head><body><H1>Serverfehler</H1><P>Die angegebene Datei konnte nicht geffnet werden.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_LOADLIB "<html><head><title>Serverfehler</title></head><body><H1>Serverfehler</H1><P>LoadLibrary fehlgeschlagen.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_HANDLERIF "<html><head><title>Serverfehler</title></head><body><H1>Serverfehler</H1><P>Die Anforderungshandlerschnittstelle konnte nicht abgerufen werden.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_OUTOFMEM "<html><head><title>Serverfehler</title></head><body><H1>Serverfehler</H1><P>Auf dem Server ist nicht gengend Arbeitsspeicher verfgbar.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_UNEXPECTED "<html><head><title>Serverfehler</title></head><body><H1>Serverfehler</H1><P>Auf dem Server ist ein unerwarteter Fehler aufgetreten.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_STENCILPARSEFAIL "<html><head><title>Serverfehler</title></head><body><H1>Serverfehler</H1><P>Beim Bearbeiten des angeforderten Stencils ist ein unerwarteter Fehler auf dem Server aufgetreten.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_STENCILLOADFAIL "<html><head><title>Serverfehler</title></head><body><H1>Serverfehler</H1><P>Der Server konnte den angeforderten Stencil nicht laden. Die Stencildatei ist mglicherweise beschdigt oder nicht auf dem Webserver vorhanden.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_HANDLERNOTFOUND "<html><head><title>Serverfehler</title></head><body><H1>Serverfehler</H1><P>Ein in einem Handlertag benannter Handler fr den angeforderten Stencil konnte nicht im angegebenen Handler gefunden werden .dll.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_BADHANDLERTAG "<html><head><title>Serverfehler</title></head><body><H1>Serverfehler</H1><P>Der Stencil enthlt ein Handlertag, das vom Stencilprozessor nicht richtig bearbeitet werden konnte und kein Handlertag enthlt. berprfen Sie die Stencilsyntax fr den angeforderten Stencil.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_NOHANDLERTAG "<html><head><title>Serverfehler</title></head><body><H1>Serverfehler</H1><P>Der angeforderte Stencil enthlt kein Handlertag.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_LONGMETHODNAME "<html><head><title>Serverfehler</title></head><body><H1>Serverfehler</H1><P>Im angeforderten Stencil wurde ein Ersetzungstag mit einem zu langen Namen gefunden. Die maximale Lnge des Ersetzungsnamen muss kleiner oder gleich der ATL_MAX_METHOD_NAME-Konstante sein, die in atlstencil.h definiert ist.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_LONGHANDLERNAME "<html><head><title>Serverfehler</title></head><body><H1>Serverfehler</H1><P>Im angeforderten Stencil wurde ein Ersetzungstag mit einem zu langen Handlernamen gefunden, der die id.tagname-Syntax verwendet. Die maximale Lnge des Handlernamens muss kleiner oder gleich der ATL_MAX_METHOD_NAME-Konstante sein, die in atlstencil.h definiert ist.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_IMPERSONATIONFAILED "<html><head><title>Serverfehler</title></head><body><H1>Serverfehler</H1><P>Die Anforderung ist fehlgeschlagen, da versucht wurde, den Client zu imitieren.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_ISAPISTARTUPFAILED "<html><head><title>Serverfehler</title></head><body><H1>Serverfehler</H1><P>Die ISAPI-Erweiterung fr die Anforderung konnte nicht geladen werden, da ein unbekannter Fehler aufgetreten ist.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_SOAPNOSOAPACTION "<html><head><title>Server Error</title></head><body><H1>Server Error</H1><P>SOAP request did not provide SOAPACTION header.</body></html>"
-
- IDS_ATLSRV_CRITICAL_HEAPCREATEFAILED "Anforderungsheap konnte nicht erstellt werden"
- IDS_ATLSRV_CRITICAL_WORKERINITFAILED "Workerthread konnte nicht initialisiert werden"
- IDS_ATLSRV_CRITICAL_CRITSECINITFAILED "Kritischer Abschnitt konnte nicht initialisiert werden"
- IDS_ATLSRV_CRITICAL_THREADPOOLFAILED "Threadpool konnte nicht initialisiert werden"
- IDS_ATLSRV_CRITICAL_DLLCACHEFAILED "DLL-Cache konnte nicht initialisiert werden"
- IDS_ATLSRV_CRITICAL_PAGECACHEFAILED "Seitencache konnte nicht initialisiert werden"
- IDS_ATLSRV_CRITICAL_STENCILCACHEFAILED "Stencilcache konnte nicht initialisiert werden"
- IDS_ATLSRV_CRITICAL_SESSIONSTATEFAILED "Sitzungsstatusdienst konnte nicht initialisiert werden"
- IDS_ATLSRV_CRITICAL_BLOBCACHEFAILED "Blobcache konnte nicht initialisiert werden"
- IDS_ATLSRV_CRITICAL_FILECACHEFAILED "Dateicache konnte nicht initialisiert werden"
-
- IDS_PERFMON_CACHE "ATL-Server:Cache"
- IDS_PERFMON_CACHE_HELP "Informationen ber den ATL-Servercache"
- IDS_PERFMON_HITCOUNT "Cachetrefferanzahl"
- IDS_PERFMON_HITCOUNT_HELP "Anzahl der Cachetreffer"
- IDS_PERFMON_MISSCOUNT "Fehlgeschlagene Cachezugriffe"
- IDS_PERFMON_MISSCOUNT_HELP "Anzahl der fehlgeschlagenen Cachezugriffe"
- IDS_PERFMON_CURRENTALLOCATIONS "Aktuelle Cachezuordnungen"
- IDS_PERFMON_CURRENTALLOCATIONS_HELP "Aktuelle Speicherzuordnung fr den Cache"
- IDS_PERFMON_MAXALLOCATIONS "Max. Cachezuordnungen"
- IDS_PERFMON_MAXALLOCATIONS_HELP "Maximale Speicherzuordnung fr den Cache"
- IDS_PERFMON_CURRENTENTRIES "Aktuelle Cacheeintrge"
- IDS_PERFMON_CURRENTENTRIES_HELP "Aktuelle Anzahl der Cacheeintrge"
- IDS_PERFMON_MAXENTRIES "Max. Cacheeintrge"
- IDS_PERFMON_MAXENTRIES_HELP "Maximale Anzahl der Cacheeintrge"
- IDS_PERFMON_HITCOUNTRATE "Cachetrefferanzahl"
- IDS_PERFMON_HITCOUNTRATE_HELP "Anzahl der Treffer pro Sekunde"
- IDS_PERFMON_REQUEST "ATL-Server:Request"
- IDS_PERFMON_REQUEST_HELP "Statistik ber die eingehenden Serveranforderungen"
- IDS_PERFMON_REQUEST_TOTAL "Serveranforderungen insgesamt"
- IDS_PERFMON_REQUEST_TOTAL_HELP "Gesamtanzahl der Anforderungen"
- IDS_PERFMON_REQUEST_FAILED "Fehlgeschlagene Serveranforderungen"
- IDS_PERFMON_REQUEST_FAILED_HELP "Anzahl der fehlgeschlagenen Anforderungen"
- IDS_PERFMON_REQUEST_RATE "Serveranforderungen /Sek."
- IDS_PERFMON_REQUEST_RATE_HELP "Anzahl der Anforderungen pro Sekunde"
- IDS_PERFMON_REQUEST_AVG_RESPONSE_TIME "Durchschnittliche Antwortzeit"
- IDS_PERFMON_REQUEST_AVG_RESPONSE_TIME_HELP "Durchschnittliche Bearbeitungszeit"
- IDS_PERFMON_REQUEST_CURR_WAITING "Aktuelle Anforderungen in der Warteschlange"
- IDS_PERFMON_REQUEST_CURR_WAITING_HELP "Die aktuvelle Anzahl der Anforderungen, die auf die Bearbeitung warten"
- IDS_PERFMON_REQUEST_MAX_WAITING "Maximale Anforderungen in der Warteschlange"
- IDS_PERFMON_REQUEST_MAX_WAITING_HELP "Die maximale Anzahl der Anforderungen, die auf die Bearbeitung warten"
- IDS_PERFMON_REQUEST_ACTIVE_THREADS "AKtive Threads"
- IDS_PERFMON_REQUEST_ACTIVE_THREADS_HELP "Die Anzahl der Threads, die Anforderungen bearbeiten"
-END
-
-
-#ifndef ATL_NO_DEFAULT_STENCIL_RESOURCE
-dllmgr.srf HTML "res\\dllmgr.srf"
-stencilmgr.srf HTML "res\\stencilmgr.srf"
-threadmgr.srf HTML "res\\threadmgr.srf"
-#endif
-
-
-//
-// Stencil parse error support
-//
-#ifdef ATL_DEBUG_STENCILS
-
-STRINGTABLE DISCARDABLE
-BEGIN
- IDS_STENCIL_ERROR_STENCIL
-"{{codepage 0}}<h1><font color=#ff0000>Beim Bearbeiten einer Stencildatei sind folgende Fehler aufgetreten:</font></h1>\r\n{{while GetNextError}}<table border=1 width=50%>\r\n<tr><td width=25%>Fehlertyp</td><td>{{GetErrorText}}</td></tr>\r\n<tr><td>Zeilennummer</td><td>{{GetErrorLineNumber}}</td></tr>\r\n<tr><td>Fehlertext</td><td><pre>{{GetErrorLine}}</pre></td></tr>\r\n</table>\r\n{{endwhile}}<br>Stencilausgabe:\r\n<hr>"
-
- IDS_STENCIL_UNCLOSEDBLOCK_IF "{{if}} ohne {{endif}}"
- IDS_STENCIL_UNCLOSEDBLOCK_ELSE "{{else}} ohne {{endif}}"
- IDS_STENCIL_UNCLOSEDBLOCK_WHILE "{{while}} ohne {{endwhile}}"
- IDS_STENCIL_UNOPENEDBLOCK_ENDWHILE "{{endwhile}} ohne {{while}}"
- IDS_STENCIL_UNOPENEDBLOCK_ELSE "{{else}} ohne {{if}}"
- IDS_STENCIL_UNOPENEDBLOCK_ENDIF "{{endif}} ohne {{if}} oder {{else}}"
-
- IDS_STENCIL_INVALID_HANDLER "Ungltiges Handlertag"
- IDS_STENCIL_NULLPARAM "NULL-Parameter fr ParseReplacements"
- IDS_STENCIL_INVALIDSTRING "An ParseReplacements wurde eine leere oder negative Zeichenfolge bergeben"
- IDS_STENCIL_EMBEDDED_NULL "Eingebettetes Nullzeichen in Stencil"
- IDS_STENCIL_UNMATCHED_TAG_START "Unterschiedlich {{"
- IDS_STENCIL_MISMATCHED_TAG_START "Nicht bereinstimmend {{"
- IDS_STENCIL_BAD_PARAMETER "Ungltiger Parameter"
- IDS_STENCIL_METHODNAME_TOO_LONG "Methodenname zu lang"
- IDS_STENCIL_HANDLERNAME_TOO_LONG "Handlername zu lang"
- IDS_STENCIL_INVALID_SUBHANDLER "Ungltiges Unterhandlertag"
- IDS_STENCIL_UNRESOLVED_REPLACEMENT "Nicht aufgelste Ersetzung : '%s'"
-
- IDS_STENCIL_INCLUDE_ERROR "Die einbezogene Datei konnte nicht geffnet werden"
- IDS_STENCIL_INCLUDE_INVALID "Die einbezogene Datei ist keine Datentrgerdatei"
-
- IDS_STENCIL_MLANG_COCREATE "CMultiLanguage konnte nicht erstellt werden"
- IDS_STENCIL_MLANG_LCID "Beim Abfragen der lcid ist ein Fehler aufgetreten"
- IDS_STENCIL_MLANG_GETLOCALE "GetLocaleInfo fehlgeschlagen"
- IDS_STENCIL_MLANG_GETCHARSET "GetCharsetInfo fehlgeschlagen"
-
- IDS_STENCIL_OUTOFMEMORY "Nicht gengend Speicher verfgbar"
- IDS_STENCIL_UNEXPECTED "Unerwarteter Fehler"
-END
-
-#endif
diff --git a/include/atl/l.esp/atlsrv.rc b/include/atl/l.esp/atlsrv.rc
deleted file mode 100644
index 15bf88daa..000000000
--- a/include/atl/l.esp/atlsrv.rc
+++ /dev/null
@@ -1,146 +0,0 @@
-// This is a part of the Active Template Library.
-// Copyright (C) Microsoft Corporation
-// All rights reserved.
-//
-// This source code is only intended as a supplement to the
-// Active Template Library Reference and related
-// electronic documentation provided with the library.
-// See these sources for detailed information regarding the
-// Active Template Library product.
-
-#include <winresrc.h>
-#include "atlsrvres.h"
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// String Table
-//
-
-STRINGTABLE DISCARDABLE
-BEGIN
- IDS_ATLSRV_BAD_REQUEST "<html><head><title>Solicitud incorrecta</title></head><body>Solicitud incorrecta</body></html>"
- IDS_ATLSRV_AUTH_REQUIRED
- "<html><head><title>Autorizacin requerida</title></head><body>Se necesita autorizacin</body></html>"
- IDS_ATLSRV_FORBIDDEN "<html><head><title>Prohibido</title></head><body>Prohibido</body></html>"
- IDS_ATLSRV_NOT_FOUND "<html><head><title>No se encontr</title></head><body>No se encontr</body></html>"
- IDS_ATLSRV_SERVER_ERROR "<html><head><title>Error del servidor</title></head><body>Error del servidor</body></html>"
- IDS_ATLSRV_NOT_IMPLEMENTED
- "<html><head><title>No implementado</title></head><body>No implementado</body></html>"
- IDS_ATLSRV_BAD_GATEWAY "<html><head><title>Puerta de enlace no vlida</title></head><body>Puerta de enlace no vlida</body></html>"
- IDS_ATLSRV_SERVICE_NOT_AVAILABLE
- "<html><head><title>Servicio no disponible</title></head><body>Servicio no disponible</body></html>"
- IDS_ATLSRV_SERVER_ERROR_BADSRF "<html><head><title>Error del servidor</title></head><body><H1>Error del servidor</H1><P>No se puede cargar el archivo SRF.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_HNDLFAIL "<html><head><title>Error del servidor</title></head><body><H1>Error del servidor</H1><P>El archivo SRF solicitado se carg pero no se pudo procesar correctamente.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_SYSOBJFAIL "<html><head><title>Error del servidor</title></head><body><H1>Error del servidor</H1><P>No se puede crear un objeto del sistema Windows.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_READFILEFAIL "<html><head><title>Error del servidor</title></head><body><H1>Error del servidor</H1><P>Error en la operacin de lectura de archivo.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_LOADFILEFAIL "<html><head><title>Error en el servidor</title></head><body><H1>Error en el servidor</H1><P>No se puede abrir el archivo especificado.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_LOADLIB "<html><head><title>Error del servidor</title></head><body><H1>Error del servidor</H1><P>Error de LoadLibrary.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_HANDLERIF "<html><head><title>Error del servidor</title></head><body><H1>Error del servidor</H1><P>Error al recuperar la interfaz del controlador de solicitudes.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_OUTOFMEM "<html><head><title>Error del servidor</title></head><body><H1>Error del servidor</H1><P>El servidor no tiene suficiente memoria.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_UNEXPECTED "<html><head><title>Error del servidor</title></head><body><H1>Error del servidor</H1><P>El servidor detect un error inesperado.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_STENCILPARSEFAIL "<html><head><title>Error del servidor</title></head><body><H1>Error del servidor</H1><P>El servidor detect un error inesperado al intentar analizar el clich solicitado.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_STENCILLOADFAIL "<html><head><title>Error del servidor</title></head><body><H1>Error del servidor</H1><P>Error del servidor al cargar el clich solicitado. Es posible que el archivo de clich est daado o no se encuentre en este servidor Web.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_HANDLERNOTFOUND "<html><head><title>Error del servidor</title></head><body><H1>Error del servidor</H1><P>No se encontr uno de los controladores nombrado en una etiqueta de controlador para el clich solicitado en el archivo DLL del controlador especificado.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_BADHANDLERTAG "<html><head><title>Error del servidor</title></head><body><H1>Error del servidor</H1><P>Este clich contiene una etiqueta de controlador que el procesador de clich no puede analizar correctamente o bien no contiene ninguna etiqueta de controlador. Compruebe que la sintaxis del clich solicitado sea correcta.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_NOHANDLERTAG "<html><head><title>Error del servidor</title></head><body><H1>Error del servidor</H1><P>El clich solicitado no contiene una etiqueta de controlador.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_LONGMETHODNAME "<html><head><title>Error del servidor</title></head><body><H1>Error del servidor</H1><P>Se encontr una etiqueta de reemplazo en el clich solicitado con un nombre de reemplazo demasiado largo. La longitud mxima del nombre de reemplazo debe ser inferior o igual a la constante ATL_MAX_METHOD_NAME definida en atlstencil.h</body></html>"
- IDS_ATLSRV_SERVER_ERROR_LONGHANDLERNAME "<html><head><title>Error del servidor</title></head><body><H1>Error del servidor</H1><P>Se encontr una etiqueta de reemplazo que utiliza la sintaxis id.tagname en el clich seleccionado con un nombre de controlador demasiado largo. La longitud mxima del nombre del controlador debe ser inferior o igual a la constante ATL_MAX_METHOD_NAME definida en atlstencil.h</body></html>"
- IDS_ATLSRV_SERVER_ERROR_IMPERSONATIONFAILED "<html><head><title>Error del servidor</title></head><body><H1>Error del servidor</H1><P>Error al intentar identificar al cliente que realiza la solicitud.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_ISAPISTARTUPFAILED "<html><head><title>Error del servidor</title></head><body><H1>Error del servidor</H1><P>Error desconocido de la extensin ISAPI utilizada para dar servicio a esta solicitud al realizar la carga.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_SOAPNOSOAPACTION "<html><head><title>Server Error</title></head><body><H1>Server Error</H1><P>SOAP request did not provide SOAPACTION header.</body></html>"
-
- IDS_ATLSRV_CRITICAL_HEAPCREATEFAILED "Error al crear el montn de solicitudes"
- IDS_ATLSRV_CRITICAL_WORKERINITFAILED "Error al inicializar el subproceso de trabajo"
- IDS_ATLSRV_CRITICAL_CRITSECINITFAILED "Error al inicializar la seccin crtica"
- IDS_ATLSRV_CRITICAL_THREADPOOLFAILED "Error al inicializar el grupo de subprocesos"
- IDS_ATLSRV_CRITICAL_DLLCACHEFAILED "Error al inicializar la cach de archivos DLL"
- IDS_ATLSRV_CRITICAL_PAGECACHEFAILED "Error al inicializar la cach de pginas"
- IDS_ATLSRV_CRITICAL_STENCILCACHEFAILED "Error al inicializar la cach de clichs"
- IDS_ATLSRV_CRITICAL_SESSIONSTATEFAILED "Error al inicializar el servicio de estado de sesin"
- IDS_ATLSRV_CRITICAL_BLOBCACHEFAILED "Error al inicializar la cach de objetos binarios"
- IDS_ATLSRV_CRITICAL_FILECACHEFAILED "Error al inicializar la cach de archivos"
-
- IDS_PERFMON_CACHE "Servidor ATL:cach"
- IDS_PERFMON_CACHE_HELP "Informacin sobre la cach del servidor ATL"
- IDS_PERFMON_HITCOUNT "Recuento de visitas de cach"
- IDS_PERFMON_HITCOUNT_HELP "Nmero de visitas de cach"
- IDS_PERFMON_MISSCOUNT "Recuento de errores de cach"
- IDS_PERFMON_MISSCOUNT_HELP "Nmero de errores de cach"
- IDS_PERFMON_CURRENTALLOCATIONS "Asignaciones actuales de cach"
- IDS_PERFMON_CURRENTALLOCATIONS_HELP "Memoria actual asignada a cach"
- IDS_PERFMON_MAXALLOCATIONS "Asignaciones mximas de cach"
- IDS_PERFMON_MAXALLOCATIONS_HELP "Memoria mxima asignada a cach"
- IDS_PERFMON_CURRENTENTRIES "Entradas actuales de cach"
- IDS_PERFMON_CURRENTENTRIES_HELP "Nmero actual de entradas de cach"
- IDS_PERFMON_MAXENTRIES "Entradas mximas de cach"
- IDS_PERFMON_MAXENTRIES_HELP "Nmero mximo de entradas de cach"
- IDS_PERFMON_HITCOUNTRATE "Velocidad de recuento de visitas de cach"
- IDS_PERFMON_HITCOUNTRATE_HELP "Nmero de recuentos de visitas por segundo"
- IDS_PERFMON_REQUEST "Servidor ATL:solicitud"
- IDS_PERFMON_REQUEST_HELP "Estadsticas de las solicitudes que entran en el servidor"
- IDS_PERFMON_REQUEST_TOTAL "Solicitudes totales del servidor"
- IDS_PERFMON_REQUEST_TOTAL_HELP "Nmero total de solicitudes"
- IDS_PERFMON_REQUEST_FAILED "Solicitudes no procesadas del servidor"
- IDS_PERFMON_REQUEST_FAILED_HELP "Nmero de solitudes no procesadas"
- IDS_PERFMON_REQUEST_RATE "Solicitudes del servidor /seg"
- IDS_PERFMON_REQUEST_RATE_HELP "Nmero de solicitudes por segundo"
- IDS_PERFMON_REQUEST_AVG_RESPONSE_TIME "Tiempo medio de respuesta"
- IDS_PERFMON_REQUEST_AVG_RESPONSE_TIME_HELP "Tiempo medio empleado en administrar una solicitud"
- IDS_PERFMON_REQUEST_CURR_WAITING "Solicitudes en cola actuales"
- IDS_PERFMON_REQUEST_CURR_WAITING_HELP "Nmero actual de solicitudes en espera de administracin"
- IDS_PERFMON_REQUEST_MAX_WAITING "Solicitudes mximas en cola"
- IDS_PERFMON_REQUEST_MAX_WAITING_HELP "Nmero mximo de solicitudes en espera de administracin"
- IDS_PERFMON_REQUEST_ACTIVE_THREADS "Subprocesos activos"
- IDS_PERFMON_REQUEST_ACTIVE_THREADS_HELP "Nmero de subprocesos que administran solicitudes activamente"
-END
-
-
-#ifndef ATL_NO_DEFAULT_STENCIL_RESOURCE
-dllmgr.srf HTML "res\\dllmgr.srf"
-stencilmgr.srf HTML "res\\stencilmgr.srf"
-threadmgr.srf HTML "res\\threadmgr.srf"
-#endif
-
-
-//
-// Stencil parse error support
-//
-#ifdef ATL_DEBUG_STENCILS
-
-STRINGTABLE DISCARDABLE
-BEGIN
- IDS_STENCIL_ERROR_STENCIL
-"{{codepage 0}}<h1><font color=#ff0000> Errores al analizar un archivo de clichs:</font></h1>\r\n{{while GetNextError}}<table border=1 width=50%>\r\n<tr><td width=25%>Tipo de error</td><td>{{GetErrorText}}</td></tr>\r\n<tr><td>Nmero de lnea</td><td>{{GetErrorLineNumber}}</td></tr>\r\n<tr><td>Texto del error</td><td><pre>{{GetErrorLine}}</pre></td></tr>\r\n</table>\r\n{{endwhile}}<br>Resultados de clich:\r\n<hr>"
-
- IDS_STENCIL_UNCLOSEDBLOCK_IF "{{if}} sin {{endif}}"
- IDS_STENCIL_UNCLOSEDBLOCK_ELSE "{{else}} sin {{endif}}"
- IDS_STENCIL_UNCLOSEDBLOCK_WHILE "{{while}} sin {{endwhile}}"
- IDS_STENCIL_UNOPENEDBLOCK_ENDWHILE "{{endwhile}} sin {{while}}"
- IDS_STENCIL_UNOPENEDBLOCK_ELSE "{{else}} sin {{if}}"
- IDS_STENCIL_UNOPENEDBLOCK_ENDIF "{{endif}} sin {{if}} o {{else}}"
-
- IDS_STENCIL_INVALID_HANDLER "Etiqueta de controlador no vlida"
- IDS_STENCIL_NULLPARAM "Parmetro NULL para ParseReplacements"
- IDS_STENCIL_INVALIDSTRING "Se pas una cadena vaca o negativa a ParseReplacements"
- IDS_STENCIL_EMBEDDED_NULL "Carcter null incrustado en el clich"
- IDS_STENCIL_UNMATCHED_TAG_START "Las llaves {{ no coinciden"
- IDS_STENCIL_MISMATCHED_TAG_START "Diferente nmero de llaves {{"
- IDS_STENCIL_BAD_PARAMETER "Parmetro errneo"
- IDS_STENCIL_METHODNAME_TOO_LONG "Nombre de mtodo demasiado largo"
- IDS_STENCIL_HANDLERNAME_TOO_LONG "Nombre de controlador demasiado largo"
- IDS_STENCIL_INVALID_SUBHANDLER "Etiqueta de controlador secundario no vlida"
- IDS_STENCIL_UNRESOLVED_REPLACEMENT "Reemplazo no resuelto: '%s'"
-
- IDS_STENCIL_INCLUDE_ERROR "No se puede abrir el archivo incluido"
- IDS_STENCIL_INCLUDE_INVALID "El archivo incluido no es un archivo de disco"
-
- IDS_STENCIL_MLANG_COCREATE "No se puede crear CMultiLanguage"
- IDS_STENCIL_MLANG_LCID "Error al obtener el identificador LCID"
- IDS_STENCIL_MLANG_GETLOCALE "Error en GetLocaleInfo"
- IDS_STENCIL_MLANG_GETCHARSET "Error en GetCharsetInfo"
-
- IDS_STENCIL_OUTOFMEMORY "Memoria insuficiente"
- IDS_STENCIL_UNEXPECTED "Error inesperado"
-END
-
-#endif
diff --git a/include/atl/l.fra/atlsrv.rc b/include/atl/l.fra/atlsrv.rc
deleted file mode 100644
index dc26cb83a..000000000
--- a/include/atl/l.fra/atlsrv.rc
+++ /dev/null
@@ -1,146 +0,0 @@
-// This is a part of the Active Template Library.
-// Copyright (C) Microsoft Corporation
-// All rights reserved.
-//
-// This source code is only intended as a supplement to the
-// Active Template Library Reference and related
-// electronic documentation provided with the library.
-// See these sources for detailed information regarding the
-// Active Template Library product.
-
-#include <winresrc.h>
-#include "atlsrvres.h"
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// String Table
-//
-
-STRINGTABLE DISCARDABLE
-BEGIN
- IDS_ATLSRV_BAD_REQUEST "<html><head><title>Demande incorrecte</title></head><body>Demande incorrecte</body></html>"
- IDS_ATLSRV_AUTH_REQUIRED
- "<html><head><title>Autorisation requise</title></head><body>Une autorisation est requise</body></html>"
- IDS_ATLSRV_FORBIDDEN "<html><head><title>Interdit</title></head><body>Interdit</body></html>"
- IDS_ATLSRV_NOT_FOUND "<html><head><title>Introuvable</title></head><body>Introuvable</body></html>"
- IDS_ATLSRV_SERVER_ERROR "<html><head><title>Erreur serveur</title></head><body>Erreur serveur</body></html>"
- IDS_ATLSRV_NOT_IMPLEMENTED
- "<html><head><title>Non implment</title></head><body>Non implment</body></html>"
- IDS_ATLSRV_BAD_GATEWAY "<html><head><title>Passerelle incorrecte</title></head><body>Passerelle incorrecte</body></html>"
- IDS_ATLSRV_SERVICE_NOT_AVAILABLE
- "<html><head><title>Service non disponible</title></head><body>Service non disponible</body></html>"
- IDS_ATLSRV_SERVER_ERROR_BADSRF "<html><head><title>Erreur serveur</title></head><body><H1>Erreur serveur</H1><P>Impossible de charger le fichier SRF.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_HNDLFAIL "<html><head><title>Erreur serveur</title></head><body><H1>Erreur serveur</H1><P>Le fichier SRF requis a t charg mais n'a pas pu tre trait correctement.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_SYSOBJFAIL "<html><head><title>Erreur serveur</title></head><body><H1>Erreur serveur</H1><P>Un objet systme Windows n'a pas pu tre cr.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_READFILEFAIL "<html><head><title>Erreur serveur</title></head><body><H1>Erreur serveur</H1><P>Une opration de lecture de fichier a chou.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_LOADFILEFAIL "<html><head><title>Erreur serveur</title></head><body><H1>Erreur serveur</H1><P>Le fichier spcifi n'a pas pu tre ouvert.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_LOADLIB "<html><head><title>Erreur serveur</title></head><body><H1>Erreur serveur</H1><P>chec de LoadLibrary.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_HANDLERIF "<html><head><title>Erreur serveur</title></head><body><H1>Erreur serveur</H1><P>chec de la rcupration de l'interface du gestionnaire des demandes.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_OUTOFMEM "<html><head><title>Erreur serveur</title></head><body><H1>Erreur serveur</H1><P>La mmoire du serveur est sature.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_UNEXPECTED "<html><head><title>Erreur serveur</title></head><body><H1>Erreur serveur</H1><P>Le serveur a rencontr une erreur inattendue.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_STENCILPARSEFAIL "<html><head><title>Erreur serveur</title></head><body><H1>Erreur serveur</H1><P>Le serveur a rencontr une erreur inattendue lors de l'analyse du stencil requis.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_STENCILLOADFAIL "<html><head><title>Erreur serveur</title></head><body><H1>Erreur serveur</H1><P>Le serveur n'a pas pu charger le stencil requis. Le fichier stencil est peut-tre endommag ou manquant sur ce serveur Web.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_HANDLERNOTFOUND "<html><head><title>Erreur serveur</title></head><body><H1>Erreur serveur</H1><P>Un gestionnaire spcifi dans une balise de gestionnaire pour le stencil requis n'a pas pu tre trouv dans le fichier .dll de gestionnaire spcifi.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_BADHANDLERTAG "<html><head><title>Erreur serveur</title></head><body><H1>Erreur serveur</H1><P>Soit ce stencil contient une balise de gestionnaire qui n'a pas pu tre analyse correctement par le processeur de stencil, soit il ne contient aucune balise de gestionnaire. Vrifiez la syntaxe correcte utiliser pour le stencil requis.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_NOHANDLERTAG "<html><head><title>Erreur serveur</title></head><body><H1>Erreur serveur</H1><P>Le stencil requis ne contient aucune balise de gestionnaire.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_LONGMETHODNAME "<html><head><title>Erreur serveur</title></head><body><H1>Erreur serveur</H1><P>Le stencil requis contient une balise de remplacement dans laquelle un nom de remplacement est trop long. La longueur maximale du nom de remplacement doit tre infrieure ou gale la valeur de la constante ATL_MAX_METHOD_NAME dfinie dans atlstencil.h</body></html>"
- IDS_ATLSRV_SERVER_ERROR_LONGHANDLERNAME "<html><head><title>Erreur serveur</title></head><body><H1>Erreur serveur</H1><P>Le stencil requis contient une balise de remplacement, utilisant la syntaxe id.nombalise, dans laquelle un nom de gestionnaire est trop long. La longueur maximale du nom d'un gestionnaire doit tre infrieure ou gale la valeur de la constante ATL_MAX_METHOD_NAME dfinie dans atlstencil.h</body></html>"
- IDS_ATLSRV_SERVER_ERROR_IMPERSONATIONFAILED "<html><head><title>Erreur serveur</title></head><body><H1>Erreur serveur</H1><P>Impossible d'emprunter l'identit du client qui a mis la demande.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_ISAPISTARTUPFAILED "<html><head><title>Erreur serveur</title></head><body><H1>Erreur serveur</H1><P>L'extension ISAPI utilise pour traiter cette demande n'a pas pu tre charge en raison d'une erreur inconnue.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_SOAPNOSOAPACTION "<html><head><title>Server Error</title></head><body><H1>Server Error</H1><P>SOAP request did not provide SOAPACTION header.</body></html>"
-
- IDS_ATLSRV_CRITICAL_HEAPCREATEFAILED "chec de la cration du segment de mmoire demande"
- IDS_ATLSRV_CRITICAL_WORKERINITFAILED "chec de l'initialisation de la thread de traitement"
- IDS_ATLSRV_CRITICAL_CRITSECINITFAILED "chec de l'initialisation de la section critique"
- IDS_ATLSRV_CRITICAL_THREADPOOLFAILED "chec de l'initialisation du pool de threads"
- IDS_ATLSRV_CRITICAL_DLLCACHEFAILED "chec de l'initialisation du cache de DLL"
- IDS_ATLSRV_CRITICAL_PAGECACHEFAILED "chec de l'initialisation du cache de page"
- IDS_ATLSRV_CRITICAL_STENCILCACHEFAILED "chec de l'initialisation du cache du stencil"
- IDS_ATLSRV_CRITICAL_SESSIONSTATEFAILED "chec de l'initialisation du service d'tat de session"
- IDS_ATLSRV_CRITICAL_BLOBCACHEFAILED "chec de l'initialisation du cache BLOB"
- IDS_ATLSRV_CRITICAL_FILECACHEFAILED "chec de l'initialisation du cache du fichier"
-
- IDS_PERFMON_CACHE "Serveur ATL : Cache"
- IDS_PERFMON_CACHE_HELP "Information sur le cache du serveur ATL"
- IDS_PERFMON_HITCOUNT "Accs cache avec rsultat"
- IDS_PERFMON_HITCOUNT_HELP "Nombre des accs cache avec rsultat"
- IDS_PERFMON_MISSCOUNT "Accs cache sans rsultat"
- IDS_PERFMON_MISSCOUNT_HELP "Nombre des accs cache sans rsultat"
- IDS_PERFMON_CURRENTALLOCATIONS "Allocations cache actuelles"
- IDS_PERFMON_CURRENTALLOCATIONS_HELP "Mmoire actuellement alloue au cache"
- IDS_PERFMON_MAXALLOCATIONS "Allocations cache maximales"
- IDS_PERFMON_MAXALLOCATIONS_HELP "Mmoire maximale alloue au cache"
- IDS_PERFMON_CURRENTENTRIES "Entres cache actuelles"
- IDS_PERFMON_CURRENTENTRIES_HELP "Nombre actuel d'entres du cache"
- IDS_PERFMON_MAXENTRIES "Entres cache maximales"
- IDS_PERFMON_MAXENTRIES_HELP "Nombre maximal d'entres du cache"
- IDS_PERFMON_HITCOUNTRATE "Taux d'accs au cache"
- IDS_PERFMON_HITCOUNTRATE_HELP "Nombre d'accs par seconde"
- IDS_PERFMON_REQUEST "Serveur ATL : Demande"
- IDS_PERFMON_REQUEST_HELP "Statistiques sur les demandes serveur entrantes"
- IDS_PERFMON_REQUEST_TOTAL "Total des demandes serveur"
- IDS_PERFMON_REQUEST_TOTAL_HELP "Nombre total des demandes"
- IDS_PERFMON_REQUEST_FAILED "Demandes serveur choues"
- IDS_PERFMON_REQUEST_FAILED_HELP "Nombre de demandes ayant chou"
- IDS_PERFMON_REQUEST_RATE "Demandes serveur/s"
- IDS_PERFMON_REQUEST_RATE_HELP "Nombre de demandes par seconde"
- IDS_PERFMON_REQUEST_AVG_RESPONSE_TIME "Temps de rponse moyen"
- IDS_PERFMON_REQUEST_AVG_RESPONSE_TIME_HELP "Dure moyenne du traitement d'une demande"
- IDS_PERFMON_REQUEST_CURR_WAITING "Demandes actuelles en attente"
- IDS_PERFMON_REQUEST_CURR_WAITING_HELP "Nombre de demandes actuellement en attente d'tre traites"
- IDS_PERFMON_REQUEST_MAX_WAITING "Demandes maximales en attente"
- IDS_PERFMON_REQUEST_MAX_WAITING_HELP "Nombre maximal de demandes en attente d'tre traites"
- IDS_PERFMON_REQUEST_ACTIVE_THREADS "Threads actives"
- IDS_PERFMON_REQUEST_ACTIVE_THREADS_HELP "Nombre de threads qui traitent activement des demandes"
-END
-
-
-#ifndef ATL_NO_DEFAULT_STENCIL_RESOURCE
-dllmgr.srf HTML "res\\dllmgr.srf"
-stencilmgr.srf HTML "res\\stencilmgr.srf"
-threadmgr.srf HTML "res\\threadmgr.srf"
-#endif
-
-
-//
-// Stencil parse error support
-//
-#ifdef ATL_DEBUG_STENCILS
-
-STRINGTABLE DISCARDABLE
-BEGIN
- IDS_STENCIL_ERROR_STENCIL
-"{{codepage 0}}<h1><font color=#ff0000> Lors de la tentative d'analyse d'un fichier stencil, les erreurs suivantes se sont produites :</font></h1>\r\n{{while GetNextError}}<table border=1 width=50%>\r\n<tr><td width=25%>Type d'erreur</td><td>{{GetErrorText}}</td></tr>\r\n<tr><td>Numro de ligne</td><td>{{GetErrorLineNumber}}</td></tr>\r\n<tr><td>Texte de l'erreur</td><td><pre>{{GetErrorLine}}</pre></td></tr>\r\n</table>\r\n{{endwhile}}<br>La sortie du stencil est la suivante :\r\n<hr>"
-
- IDS_STENCIL_UNCLOSEDBLOCK_IF "{{if}} sans {{endif}}"
- IDS_STENCIL_UNCLOSEDBLOCK_ELSE "{{else}} sans {{endif}}"
- IDS_STENCIL_UNCLOSEDBLOCK_WHILE "{{while}} sans {{endwhile}}"
- IDS_STENCIL_UNOPENEDBLOCK_ENDWHILE "{{endwhile}} sans {{while}}"
- IDS_STENCIL_UNOPENEDBLOCK_ELSE "{{else}} sans {{if}}"
- IDS_STENCIL_UNOPENEDBLOCK_ENDIF "{{endif}} sans {{if}} ou {{else}}"
-
- IDS_STENCIL_INVALID_HANDLER "Balise de gestionnaire non valide"
- IDS_STENCIL_NULLPARAM "Paramtre NULL ParseReplacements"
- IDS_STENCIL_INVALIDSTRING "Chane vide ou ngative passe ParseReplacements"
- IDS_STENCIL_EMBEDDED_NULL "Caractre null incorpor dans le stencil"
- IDS_STENCIL_UNMATCHED_TAG_START "{{ non appari"
- IDS_STENCIL_MISMATCHED_TAG_START "{{ incompatible"
- IDS_STENCIL_BAD_PARAMETER "Paramtre incorrect"
- IDS_STENCIL_METHODNAME_TOO_LONG "Nom de mthode trop long"
- IDS_STENCIL_HANDLERNAME_TOO_LONG "Nom de gestionnaire trop long"
- IDS_STENCIL_INVALID_SUBHANDLER "Balise de sous-gestionnaire non valide"
- IDS_STENCIL_UNRESOLVED_REPLACEMENT "Remplacement non rsolu : '%s'"
-
- IDS_STENCIL_INCLUDE_ERROR "Impossible d'ouvrir le fichier inclus"
- IDS_STENCIL_INCLUDE_INVALID "Le fichier inclus n'est pas un fichier disque"
-
- IDS_STENCIL_MLANG_COCREATE "Impossible de crer CMultiLanguage"
- IDS_STENCIL_MLANG_LCID "Erreur lors de l'obtention du lcid"
- IDS_STENCIL_MLANG_GETLOCALE "chec de GetLocaleInfo"
- IDS_STENCIL_MLANG_GETCHARSET "chec de GetCharsetInfo"
-
- IDS_STENCIL_OUTOFMEMORY "Mmoire insuffisante"
- IDS_STENCIL_UNEXPECTED "Erreur inattendue"
-END
-
-#endif
diff --git a/include/atl/l.ita/atlsrv.rc b/include/atl/l.ita/atlsrv.rc
deleted file mode 100644
index 009e0b2db..000000000
--- a/include/atl/l.ita/atlsrv.rc
+++ /dev/null
@@ -1,146 +0,0 @@
-// This is a part of the Active Template Library.
-// Copyright (C) Microsoft Corporation
-// All rights reserved.
-//
-// This source code is only intended as a supplement to the
-// Active Template Library Reference and related
-// electronic documentation provided with the library.
-// See these sources for detailed information regarding the
-// Active Template Library product.
-
-#include <winresrc.h>
-#include "atlsrvres.h"
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// String Table
-//
-
-STRINGTABLE DISCARDABLE
-BEGIN
- IDS_ATLSRV_BAD_REQUEST "<html><head><title>Richiesta non valida</title></head><body>Richiesta non valida</body></html>"
- IDS_ATLSRV_AUTH_REQUIRED
- "<html><head><title>Autorizzazione richiesta</title></head><body>Autorizzazione richiesta</body></html>"
- IDS_ATLSRV_FORBIDDEN "<html><head><title>Non consentito</title></head><body>Non consentito</body></html>"
- IDS_ATLSRV_NOT_FOUND "<html><head><title>Non trovato</title></head><body>Non trovato</body></html>"
- IDS_ATLSRV_SERVER_ERROR "<html><head><title>Errore del server</title></head><body>Errore del server</body></html>"
- IDS_ATLSRV_NOT_IMPLEMENTED
- "<html><head><title>Non implementato</title></head><body>Non implementato</body></html>"
- IDS_ATLSRV_BAD_GATEWAY "<html><head><title>Gateway non valido</title></head><body>Gateway non valido</body></html>"
- IDS_ATLSRV_SERVICE_NOT_AVAILABLE
- "<html><head><title>Servizio non disponibile</title></head><body>Servizio non disponibile</body></html>"
- IDS_ATLSRV_SERVER_ERROR_BADSRF "<html><head><title>Errore del server</title></head><body><H1>Errore del server</H1><P>Impossibile caricare il file SRF.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_HNDLFAIL "<html><head><title>Errore del server</title></head><body><H1>Errore del server</H1><P>Il file SRF richiesto stato caricato ma non elaborato correttamente.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_SYSOBJFAIL "<html><head><title>Errore del server</title></head><body><H1>Errore del server</H1><P>Impossibile creare un oggetto di sistema Windows.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_READFILEFAIL "<html><head><title>Errore del server</title></head><body><H1>Errore del server</H1><P>Operazione di lettura file non riuscita.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_LOADFILEFAIL "<html><head><title>Errore del server</title></head><body><H1>Errore del server</H1><P>Impossibile aprire il file specificato.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_LOADLIB "<html><head><title>Errore del server</title></head><body><H1>Errore del server</H1><P>LoadLibrary non riuscito.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_HANDLERIF "<html><head><title>Errore del server</title></head><body><H1>Errore del server</H1><P>Impossibile recuperare l'interfaccia del gestore delle richieste.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_OUTOFMEM "<html><head><title>Errore del server</title></head><body><H1>Errore del server</H1><P>Memoria del server esaurita.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_UNEXPECTED "<html><head><title>Errore del server</title></head><body><H1>Errore del server</H1><P>Errore imprevisto del server.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_STENCILPARSEFAIL "<html><head><title>Errore del server</title></head><body><H1>Errore del server</H1><P>Errore imprevisto del server durante il tentativo di analizzare il file SRF richiesto.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_STENCILLOADFAIL "<html><head><title>Errore del server</title></head><body><H1>Errore del server</H1><P>Impossibile caricare il file SRF richiesto. Il file potrebbe essere danneggiato o mancante sul server Web.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_HANDLERNOTFOUND "<html><head><title>Errore del server</title></head><body><H1>Errore del server</H1><P>Impossibile trovare nella DLL del gestore specificata uno dei gestori denominati in un tag di gestione per il file SRF richiesto.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_BADHANDLERTAG "<html><head><title>Errore del server</title></head><body><H1>Errore del server</H1><P>Questo file SRF contiene un tag di gestione che non pu essere analizzato correttamente dal processore dei file SRF o non contiene affatto un tag di gestione. Cercare nel file SRF richiesto la sintassi appropriata.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_NOHANDLERTAG "<html><head><title>Errore del server</title></head><body><H1>Errore del server</H1><P>Il file SRF richiesto non contiene un tag di gestione.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_LONGMETHODNAME "<html><head><title>Errore del server</title></head><body><H1>Errore del server</H1><P>Rilevato un tag di sostituzione nel file SRF richiesto con un nome di sostituzione troppo lungo. Il nome di sostituzione deve contenere un numero di caratteri inferiore o uguale alla costante ATL_MAX_METHOD_NAME definita in atlstencil.h</body></html>"
- IDS_ATLSRV_SERVER_ERROR_LONGHANDLERNAME "<html><head><title>Errore del server</title></head><body><H1>Errore del server</H1><P>Rilevato nel file SRF richiesto un tag di sostituzione che utilizza la sintassi id.tagname con un nome di gestore troppo lungo. Un nome di gestore deve contenere un numero di caratteri inferiore o uguale alla costante ATL_MAX_METHOD_NAME definita in atlstencil.h</body></html>"
- IDS_ATLSRV_SERVER_ERROR_IMPERSONATIONFAILED "<html><head><title>Errore del server</title></head><body><H1>Errore del server</H1><P>Tentativo di rappresentare il client eseguendo la richiesta non riuscito.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_ISAPISTARTUPFAILED "<html><head><title>Errore del server</title></head><body><H1>Errore del server</H1><P>L'estensione ISAPI utilizzata per soddisfare questa richiesta non riuscita a eseguire il caricamento correttamente. Errore sconosciuto.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_SOAPNOSOAPACTION "<html><head><title>Server Error</title></head><body><H1>Server Error</H1><P>SOAP request did not provide SOAPACTION header.</body></html>"
-
- IDS_ATLSRV_CRITICAL_HEAPCREATEFAILED "Creazione heap richiesta non riuscita"
- IDS_ATLSRV_CRITICAL_WORKERINITFAILED "Inizializzazione thread di lavoro non riuscita"
- IDS_ATLSRV_CRITICAL_CRITSECINITFAILED "Inizializzazione sezione critica non riuscita"
- IDS_ATLSRV_CRITICAL_THREADPOOLFAILED "Inizializzazione pool di thread non riuscita"
- IDS_ATLSRV_CRITICAL_DLLCACHEFAILED "Inizializzazione cache DLL non riuscita"
- IDS_ATLSRV_CRITICAL_PAGECACHEFAILED "Inizializzazione cache pagina non riuscita"
- IDS_ATLSRV_CRITICAL_STENCILCACHEFAILED "Inizializzazione cache file SRF non riuscita"
- IDS_ATLSRV_CRITICAL_SESSIONSTATEFAILED "Inizializzazione servizio di stato sessione non riuscita"
- IDS_ATLSRV_CRITICAL_BLOBCACHEFAILED "Inizializzazione cache dati BLOB non riuscita"
- IDS_ATLSRV_CRITICAL_FILECACHEFAILED "Inizializzazione cache file non riuscita"
-
- IDS_PERFMON_CACHE "Server ATL:Cache"
- IDS_PERFMON_CACHE_HELP "Informazioni sulla cache del server ATL"
- IDS_PERFMON_HITCOUNT "Passaggi cache"
- IDS_PERFMON_HITCOUNT_HELP "Numero di riscontri cache"
- IDS_PERFMON_MISSCOUNT "Conteggio mancati riscontri cache"
- IDS_PERFMON_MISSCOUNT_HELP "Numero di mancati riscontri cache"
- IDS_PERFMON_CURRENTALLOCATIONS "Allocazioni correnti cache"
- IDS_PERFMON_CURRENTALLOCATIONS_HELP "Memoria corrente allocata per la cache"
- IDS_PERFMON_MAXALLOCATIONS "Numero massimo allocazioni cache"
- IDS_PERFMON_MAXALLOCATIONS_HELP "Quantit massima di memoria allocata per la cache"
- IDS_PERFMON_CURRENTENTRIES "Voci correnti cache"
- IDS_PERFMON_CURRENTENTRIES_HELP "Numero corrente di voci della cache"
- IDS_PERFMON_MAXENTRIES "Numero massimo voci cache"
- IDS_PERFMON_MAXENTRIES_HELP "Numero massimo di voci della cache"
- IDS_PERFMON_HITCOUNTRATE "Frequenza passaggi cache"
- IDS_PERFMON_HITCOUNTRATE_HELP "Numero di passaggi al secondo"
- IDS_PERFMON_REQUEST "Server ATL:Richiesta"
- IDS_PERFMON_REQUEST_HELP "Statistica sulle richieste pervenute al server"
- IDS_PERFMON_REQUEST_TOTAL "Richieste totali al server"
- IDS_PERFMON_REQUEST_TOTAL_HELP "Numero totale di richieste"
- IDS_PERFMON_REQUEST_FAILED "Richieste al server non riuscite"
- IDS_PERFMON_REQUEST_FAILED_HELP "Numero di richieste non riuscite"
- IDS_PERFMON_REQUEST_RATE "Richieste al server /sec"
- IDS_PERFMON_REQUEST_RATE_HELP "Numero di richieste al secondo"
- IDS_PERFMON_REQUEST_AVG_RESPONSE_TIME "Tempo medio di risposta"
- IDS_PERFMON_REQUEST_AVG_RESPONSE_TIME_HELP "Tempo medio impiegato per la gestione di una richiesta"
- IDS_PERFMON_REQUEST_CURR_WAITING "Richieste correnti in coda"
- IDS_PERFMON_REQUEST_CURR_WAITING_HELP "Numero corrente di richieste in attesa di essere gestite"
- IDS_PERFMON_REQUEST_MAX_WAITING "Numero massimo di richieste in coda"
- IDS_PERFMON_REQUEST_MAX_WAITING_HELP "Numero massimo di richieste in attesa di essere gestite"
- IDS_PERFMON_REQUEST_ACTIVE_THREADS "Thread attivi"
- IDS_PERFMON_REQUEST_ACTIVE_THREADS_HELP "Numero di thread che gestiscono attivamente le richieste"
-END
-
-
-#ifndef ATL_NO_DEFAULT_STENCIL_RESOURCE
-dllmgr.srf HTML "res\\dllmgr.srf"
-stencilmgr.srf HTML "res\\stencilmgr.srf"
-threadmgr.srf HTML "res\\threadmgr.srf"
-#endif
-
-
-//
-// Stencil parse error support
-//
-#ifdef ATL_DEBUG_STENCILS
-
-STRINGTABLE DISCARDABLE
-BEGIN
- IDS_STENCIL_ERROR_STENCIL
-"{{codepage 0}}<h1><font color=#ff0000> Durante l'analisi di un file SRF, si verificato il seguente errore:</font></h1>\r\n{{while GetNextError}}<table border=1 width=50%>\r\n<tr><td width=25%>Tipo di errore</td><td>{{GetErrorText}}</td></tr>\r\n<tr><td>Numero della riga</td><td>{{GetErrorLineNumber}}</td></tr>\r\n<tr><td>Testo dell'errore</td><td><pre>{{GetErrorLine}}</pre></td></tr>\r\n</table>\r\n{{endwhile}}<br>Output file SRF:\r\n<hr>"
-
- IDS_STENCIL_UNCLOSEDBLOCK_IF "{{if}} senza {{endif}}"
- IDS_STENCIL_UNCLOSEDBLOCK_ELSE "{{else}} senza {{endif}}"
- IDS_STENCIL_UNCLOSEDBLOCK_WHILE "{{while}} senza {{endwhile}}"
- IDS_STENCIL_UNOPENEDBLOCK_ENDWHILE "{{endwhile}} senza {{while}}"
- IDS_STENCIL_UNOPENEDBLOCK_ELSE "{{else}} senza {{if}}"
- IDS_STENCIL_UNOPENEDBLOCK_ENDIF "{{endif}} senza {{if}} o {{else}}"
-
- IDS_STENCIL_INVALID_HANDLER "Tag di gestione non valido"
- IDS_STENCIL_NULLPARAM "Parametro NULL in ParseReplacements"
- IDS_STENCIL_INVALIDSTRING "Stringa vuota o negativa passata a ParseReplacements"
- IDS_STENCIL_EMBEDDED_NULL "Carattere null incorporato in file SRF"
- IDS_STENCIL_UNMATCHED_TAG_START "{{ non corrispondenti"
- IDS_STENCIL_MISMATCHED_TAG_START "{{ non corrispondenti"
- IDS_STENCIL_BAD_PARAMETER "Parametro non valido"
- IDS_STENCIL_METHODNAME_TOO_LONG "Nome metodo troppo lungo"
- IDS_STENCIL_HANDLERNAME_TOO_LONG "Nome gestore troppo lungo"
- IDS_STENCIL_INVALID_SUBHANDLER "Tag di gestione secondaria non valida"
- IDS_STENCIL_UNRESOLVED_REPLACEMENT "Sostituzione non risolta: '%s'"
-
- IDS_STENCIL_INCLUDE_ERROR "Impossibile aprire il file incluso"
- IDS_STENCIL_INCLUDE_INVALID "Il file incluso non un file su disco"
-
- IDS_STENCIL_MLANG_COCREATE "Impossibile creare CMultiLanguage"
- IDS_STENCIL_MLANG_LCID "Errore durante la ricerca di lcid"
- IDS_STENCIL_MLANG_GETLOCALE "GetLocaleInfo non riuscito"
- IDS_STENCIL_MLANG_GETCHARSET "GetCharsetInfo non riuscito"
-
- IDS_STENCIL_OUTOFMEMORY "Memoria insufficiente"
- IDS_STENCIL_UNEXPECTED "Errore imprevisto"
-END
-
-#endif
diff --git a/include/atl/l.jpn/atlsrv.rc b/include/atl/l.jpn/atlsrv.rc
deleted file mode 100644
index d908accdc..000000000
--- a/include/atl/l.jpn/atlsrv.rc
+++ /dev/null
@@ -1,146 +0,0 @@
-// This is a part of the Active Template Library.
-// Copyright (C) Microsoft Corporation
-// All rights reserved.
-//
-// This source code is only intended as a supplement to the
-// Active Template Library Reference and related
-// electronic documentation provided with the library.
-// See these sources for detailed information regarding the
-// Active Template Library product.
-
-#include <winresrc.h>
-#include "atlsrvres.h"
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// String Table
-//
-
-STRINGTABLE DISCARDABLE
-BEGIN
- IDS_ATLSRV_BAD_REQUEST "<html><head><title>sK؂ȗv</title></head><body>sK؂ȗv</body></html>"
- IDS_ATLSRV_AUTH_REQUIRED
- "<html><head><title>F؂Kvł</title></head><body>F؂Kvł</body></html>"
- IDS_ATLSRV_FORBIDDEN "<html><head><title>Ȃ/title></head><body>Ȃ</body></html>"
- IDS_ATLSRV_NOT_FOUND "<html><head><title>‚܂</title></head><body>‚܂</body></html>"
- IDS_ATLSRV_SERVER_ERROR "<html><head><title>T[o[ G[</title></head><body>T[o[ G[</body></html>"
- IDS_ATLSRV_NOT_IMPLEMENTED
- "<html><head><title>Ă܂</title></head><body>Ă܂</body></html>"
- IDS_ATLSRV_BAD_GATEWAY "<html><head><title>sK؂ȃQ[gEFC</title></head><body>sK؂ȃQ[gEFC</body></html>"
- IDS_ATLSRV_SERVICE_NOT_AVAILABLE
- "<html><head><title>T[rXgpł܂</title></head><body>T[rXgpł܂</body></html>"
- IDS_ATLSRV_SERVER_ERROR_BADSRF "<html><head><title>T[o[ G[</title></head><body><H1>Server Error</H1><P>SRF t@Cǂݍ߂܂łB</body></html>"
- IDS_ATLSRV_SERVER_ERROR_HNDLFAIL "<html><head><title>T[o[ G[</title></head><body><H1>T[o[ G[</H1><P>vꂽ SRF t@C͓ǂݍ߂܂AɃvZXł܂łB</body></html>"
- IDS_ATLSRV_SERVER_ERROR_SYSOBJFAIL "<html><head><title>T[o[ G[</title></head><body><H1>T[o[ G[</H1><P>Windows VXe IuWFNg쐬ł܂łB</body></html>"
- IDS_ATLSRV_SERVER_ERROR_READFILEFAIL "<html><head><title>T[o[ G[</title></head><body><H1>T[o[ G[</H1><P>t@C̓ǂݎ葀삪ł܂łB</body></html>"
- IDS_ATLSRV_SERVER_ERROR_LOADFILEFAIL "<html><head><title>T[o[ G[</title></head><body><H1>T[o[ G[</H1><P>w肳ꂽt@CJƂł܂łB</body></html>"
- IDS_ATLSRV_SERVER_ERROR_LOADLIB "<html><head><title>T[o[ G[</title></head><body><H1>T[o[ G[</H1><P>LoadLibrary s܂B</body></html>"
- IDS_ATLSRV_SERVER_ERROR_HANDLERIF "<html><head><title>T[o[ G[</title></head><body><H1>T[o[ G[</H1><P>nhv C^[tFCX擾ł܂łB</body></html>"
- IDS_ATLSRV_SERVER_ERROR_OUTOFMEM "<html><head><title>T[o[ G[</title></head><body><H1>T[o[ G[</H1><P>T[o[̃sĂ܂B</body></html>"
- IDS_ATLSRV_SERVER_ERROR_UNEXPECTED "<html><head><title>T[o[ G[</title></head><body><H1>T[o[ G[</H1><P>T[o[ɗ\ȂG[܂B</body></html>"
- IDS_ATLSRV_SERVER_ERROR_STENCILPARSEFAIL "<html><head><title>T[o[ G[</title></head><body><H1>T[o[ G[</H1><P>vꂽXeV͒ɁAT[o[ɗ\ȂG[܂B</body></html>"
- IDS_ATLSRV_SERVER_ERROR_STENCILLOADFAIL "<html><head><title>T[o[ G[</title></head><body><H1>T[o[ G[</H1><P>T[o[ ͗vꂽXeVǂݍ߂܂łBXeV t@CĂ邩A Web T[o[ɂȂ”\܂B</body></html>"
- IDS_ATLSRV_SERVER_ERROR_HANDLERNOTFOUND "<html><head><title>T[o[ G[</title></head><body><H1>T[o[ G[</H1><P>vꂽXeṼnh ^OŖOw肳ꂽnh 1 ‚w肳ꂽnh .dll Ɍ‚܂łB</body></html>"
- IDS_ATLSRV_SERVER_ERROR_BADHANDLERTAG "<html><head><title>T[o[ G[</title></head><body><H1>T[o[ G[</H1><P>̃XeV́AXeV vZbTɂēK؂ɉ͂łȂnh ^O܂ł邩A܂̓nh ^OĂ܂BvXeṼXeV\K؂ł邩ǂmׂĂB</body></html>"
- IDS_ATLSRV_SERVER_ERROR_NOHANDLERTAG "<html><head><title>T[o[ G[</title></head><body><H1>T[o[ G[</H1><P>vꂽXeV̓nh ^OĂ܂B</body></html>"
- IDS_ATLSRV_SERVER_ERROR_LONGMETHODNAME "<html><head><title>T[o[ G[</title></head><body><H1>T[o[ G[</H1><P>vꂽXeVŒu^O‚܂Au܂Bu̍ő̒́Aatlstencil.h Œ`ꂽ ATL_MAX_METHOD_NAME 萔 ƓZȂĂ͂Ȃ܂B</body></html>"
- IDS_ATLSRV_SERVER_ERROR_LONGHANDLERNAME "<html><head><title>T[o[ G[</title></head><body><H1>T[o[ G[</H1><P>ID.tagname \gpu^OAvꂽXeVŌ‚܂Ã^Õnh͒܂Bnh̍ő̒́Aatlstencil.h Œ`ꂽ ATL_MAX_METHOD_NAME 萔ƓZȂĂ͂Ȃ܂B</body></html>"
- IDS_ATLSRV_SERVER_ERROR_IMPERSONATIONFAILED "<html><head><title>Server Error</title></head><body><H1>Server Error</H1><P>An attempt to impersonate the client making the request failed.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_ISAPISTARTUPFAILED "<html><head><title>T[o[ G[</title></head><body><H1>T[o[ G[</H1><P>̗vɓ邽߂Ɏgp ISAPI gq́A\ȂG[̂ߐɓǂݍ݂ł܂łB</body></html>"
- IDS_ATLSRV_SERVER_ERROR_SOAPNOSOAPACTION "<html><head><title>Server Error</title></head><body><H1>Server Error</H1><P>SOAP request did not provide SOAPACTION header.</body></html>"
-
- IDS_ATLSRV_CRITICAL_HEAPCREATEFAILED "q[v̍쐬vł܂łB"
- IDS_ATLSRV_CRITICAL_WORKERINITFAILED "[J[ Xbh̏ł܂łB"
- IDS_ATLSRV_CRITICAL_CRITSECINITFAILED "NeBJȃZNV̏ł܂łB"
- IDS_ATLSRV_CRITICAL_THREADPOOLFAILED "Xbh v[̏ł܂łB"
- IDS_ATLSRV_CRITICAL_DLLCACHEFAILED "DLL LbV̏ł܂łB"
- IDS_ATLSRV_CRITICAL_PAGECACHEFAILED "y[W LbV̏ł܂łB"
- IDS_ATLSRV_CRITICAL_STENCILCACHEFAILED "XeV LbV̏ł܂łB"
- IDS_ATLSRV_CRITICAL_SESSIONSTATEFAILED "ZbVԃT[rX̏ł܂łB"
- IDS_ATLSRV_CRITICAL_BLOBCACHEFAILED "Blob LbV̏ł܂łB"
- IDS_ATLSRV_CRITICAL_FILECACHEFAILED "t@C LbV̏ł܂łB"
-
- IDS_PERFMON_CACHE "ATL T[o[ : LbV"
- IDS_PERFMON_CACHE_HELP "ATL T[o[ LbV̏"
- IDS_PERFMON_HITCOUNT "LbṼqbg JEg"
- IDS_PERFMON_HITCOUNT_HELP "LbV qbg̉"
- IDS_PERFMON_MISSCOUNT "LbṼ~X JEg"
- IDS_PERFMON_MISSCOUNT_HELP "LbṼ~X JEg̉"
- IDS_PERFMON_CURRENTALLOCATIONS "LbV݂̌̊蓖"
- IDS_PERFMON_CURRENTALLOCATIONS_HELP "LbVɌ݊蓖ĂĂ郁"
- IDS_PERFMON_MAXALLOCATIONS "LbV̍ő̊蓖"
- IDS_PERFMON_MAXALLOCATIONS_HELP "LbVɊ蓖Ăꂽő僁"
- IDS_PERFMON_CURRENTENTRIES "݂̃LbV Gg"
- IDS_PERFMON_CURRENTENTRIES_HELP "݂̃LbV Gg̐"
- IDS_PERFMON_MAXENTRIES "ő̃LbV Gg"
- IDS_PERFMON_MAXENTRIES_HELP "LbV Gg̍ő吔"
- IDS_PERFMON_HITCOUNTRATE "LbṼqbg JEg"
- IDS_PERFMON_HITCOUNTRATE_HELP "b̃qbg JEg"
- IDS_PERFMON_REQUEST "ATL T[o[ : v"
- IDS_PERFMON_REQUEST_HELP "T[o[ɓĂv̓v"
- IDS_PERFMON_REQUEST_TOTAL "T[o[v̑"
- IDS_PERFMON_REQUEST_TOTAL_HELP "v̑"
- IDS_PERFMON_REQUEST_FAILED "T[o[Ȃv "
- IDS_PERFMON_REQUEST_FAILED_HELP "Ȃv"
- IDS_PERFMON_REQUEST_RATE "T[o[v /sec"
- IDS_PERFMON_REQUEST_RATE_HELP "b̗v"
- IDS_PERFMON_REQUEST_AVG_RESPONSE_TIME "ς̉Ύ"
- IDS_PERFMON_REQUEST_AVG_RESPONSE_TIME_HELP "v̏ɂώ"
- IDS_PERFMON_REQUEST_CURR_WAITING "݃L[ɂv"
- IDS_PERFMON_REQUEST_CURR_WAITING_HELP "݉΂҂Ăv"
- IDS_PERFMON_REQUEST_MAX_WAITING "L[ɂv̍ő吔"
- IDS_PERFMON_REQUEST_MAX_WAITING_HELP "΂҂Ăv̍ő吔"
- IDS_PERFMON_REQUEST_ACTIVE_THREADS "ANeBu Xbh"
- IDS_PERFMON_REQUEST_ACTIVE_THREADS_HELP "vݏ̃Xbh"
-END
-
-
-#ifndef ATL_NO_DEFAULT_STENCIL_RESOURCE
-dllmgr.srf HTML "res\\dllmgr.srf"
-stencilmgr.srf HTML "res\\stencilmgr.srf"
-threadmgr.srf HTML "res\\threadmgr.srf"
-#endif
-
-
-//
-// Stencil parse error support
-//
-#ifdef ATL_DEBUG_STENCILS
-
-STRINGTABLE DISCARDABLE
-BEGIN
- IDS_STENCIL_ERROR_STENCIL
-"{{codepage 0}}<h1><font color=#ff0000> XeV t@C͒Ɏ̃G[܂ :</font></h1>\r\n{{while GetNextError}}<table border=1 width=50%>\r\n<tr><td width=25%>G[̎</td><td>{{GetErrorText}}</td></tr>\r\n<tr><td>sio</td><td>{{GetErrorLineNumber}}</td></tr>\r\n<tr><td>G[ eLXg</td><td><pre>{{GetErrorLine}}</pre></td></tr>\r\n</table>\r\n{{endwhile}}<br>XeVo͎͂̂悤ɂȂĂ܂ :\r\n<hr>"
-
- IDS_STENCIL_UNCLOSEDBLOCK_IF "{{if}} {{endif}} Ă܂"
- IDS_STENCIL_UNCLOSEDBLOCK_ELSE "{{else}} {{endif}} Ă܂"
- IDS_STENCIL_UNCLOSEDBLOCK_WHILE "{{while}} {{endwhile}} Ă܂"
- IDS_STENCIL_UNOPENEDBLOCK_ENDWHILE "{{endwhile}} {{while}} Ă܂"
- IDS_STENCIL_UNOPENEDBLOCK_ELSE "{{else}} {{if}} Ă܂"
- IDS_STENCIL_UNOPENEDBLOCK_ENDIF "{{endif}} {{if}} or {{else}} Ă܂"
-
- IDS_STENCIL_INVALID_HANDLER "ȃnh ^O"
- IDS_STENCIL_NULLPARAM "ParseReplacements ւ NULL p[^"
- IDS_STENCIL_INVALIDSTRING "ParseReplacements ɋA܂͕̕񂪓n܂"
- IDS_STENCIL_EMBEDDED_NULL "XeV ߍ݂ null ܂"
- IDS_STENCIL_UNMATCHED_TAG_START "v܂ {{"
- IDS_STENCIL_MISMATCHED_TAG_START "v܂ {{"
- IDS_STENCIL_BAD_PARAMETER "sK؂ȃp[^ł"
- IDS_STENCIL_METHODNAME_TOO_LONG "\bh܂"
- IDS_STENCIL_HANDLERNAME_TOO_LONG "nh܂"
- IDS_STENCIL_INVALID_SUBHANDLER "Tunh ^Oł"
- IDS_STENCIL_UNRESOLVED_REPLACEMENT "uł܂ : '%s'"
-
- IDS_STENCIL_INCLUDE_ERROR "Ytt@CJ܂"
- IDS_STENCIL_INCLUDE_INVALID "Ytt@C̓fBXN t@Cł͂܂"
-
- IDS_STENCIL_MLANG_COCREATE "CMultiLanguage 쐬ł܂ł"
- IDS_STENCIL_MLANG_LCID "lcid 擾̃G[ł"
- IDS_STENCIL_MLANG_GETLOCALE "GetLocaleInfo ł܂ł"
- IDS_STENCIL_MLANG_GETCHARSET "GetCharsetInfo ł܂ł"
-
- IDS_STENCIL_OUTOFMEMORY "܂"
- IDS_STENCIL_UNEXPECTED "\ȂG[ł"
-END
-
-#endif
diff --git a/include/atl/l.kor/atlsrv.rc b/include/atl/l.kor/atlsrv.rc
deleted file mode 100644
index 54208d9ca..000000000
--- a/include/atl/l.kor/atlsrv.rc
+++ /dev/null
@@ -1,146 +0,0 @@
-// This is a part of the Active Template Library.
-// Copyright (C) Microsoft Corporation
-// All rights reserved.
-//
-// This source code is only intended as a supplement to the
-// Active Template Library Reference and related
-// electronic documentation provided with the library.
-// See these sources for detailed information regarding the
-// Active Template Library product.
-
-#include <winresrc.h>
-#include "atlsrvres.h"
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// String Table
-//
-
-STRINGTABLE DISCARDABLE
-BEGIN
- IDS_ATLSRV_BAD_REQUEST "<html><head><title>߸ û</title></head><body>߸ ûԴϴ.</body></html>"
- IDS_ATLSRV_AUTH_REQUIRED
- "<html><head><title> ʿ</title></head><body> ʿմϴ.</body></html>"
- IDS_ATLSRV_FORBIDDEN "<html><head><title></title></head><body>Ǿϴ.</body></html>"
- IDS_ATLSRV_NOT_FOUND "<html><head><title>ã </title></head><body>ã ϴ.</body></html>"
- IDS_ATLSRV_SERVER_ERROR "<html><head><title> </title></head><body> </body></html>"
- IDS_ATLSRV_NOT_IMPLEMENTED
- "<html><head><title> ȵ</title></head><body> ʾҽϴ.</body></html>"
- IDS_ATLSRV_BAD_GATEWAY "<html><head><title>߸ Ʈ</title></head><body>߸ ƮԴϴ.</body></html>"
- IDS_ATLSRV_SERVICE_NOT_AVAILABLE
- "<html><head><title>񽺸 </title></head><body>񽺸 ϴ.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_BADSRF "<html><head><title> </title></head><body><H1> </H1><P>SRF ε ϴ.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_HNDLFAIL "<html><head><title> </title></head><body><H1> </H1><P>û SRF ε ó ϴ.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_SYSOBJFAIL "<html><head><title> </title></head><body><H1> </H1><P>Windows ý ü ϴ.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_READFILEFAIL "<html><head><title> </title></head><body><H1> </H1><P> б ۾ ߽ϴ.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_LOADFILEFAIL "<html><head><title>Server Error</title></head><body><H1>Server Error</H1><P> ϴ.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_LOADLIB "<html><head><title> </title></head><body><H1> </H1><P>LoadLibrary ȣ ߽ϴ.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_HANDLERIF "<html><head><title> </title></head><body><H1> </H1><P>û ó ̽ ߽ϴ.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_OUTOFMEM "<html><head><title> </title></head><body><H1> </H1><P> ޸𸮰 մϴ.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_UNEXPECTED "<html><head><title> </title></head><body><H1> </H1><P> ġ ߻߽ϴ.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_STENCILPARSEFAIL "<html><head><title> </title></head><body><H1> </H1><P>û ٽ мϴ ġ ߻߽ϴ.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_STENCILLOADFAIL "<html><head><title> </title></head><body><H1> </H1><P>û ٽ ε ߽ϴ. ٽ ջǾų ϴ.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_HANDLERNOTFOUND "<html><head><title> </title></head><body><H1> </H1><P> ó .dll û ٽ ó ±׿ ó ϳ ϴ.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_BADHANDLERTAG "<html><head><title> </title></head><body><H1> </H1><P> ٽǿ ó ±װ ų ٽ μ ó ִ ó ±װ ϴ. û ٽ ȮϿ ٽ ùٸ ʽÿ.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_NOHANDLERTAG "<html><head><title> </title></head><body><H1> Server Error</H1><P>û ٽǿ ó ±װ ϴ.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_LONGMETHODNAME "<html><head><title> </title></head><body><H1> </H1><P>û ٽ ü ± ̸ ʹ ϴ. ٲ ̸ ִ ̴ atlstencil.h ǵ ATL_MAX_METHOD_NAME ۰ų ƾ մϴ.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_LONGHANDLERNAME "<html><head><title> </title></head><body><H1> </H1><P>û ٽ id.tagname ϴ ü ± ó ̸ ʹ ϴ. ó ̸ ִ ̴ atlstencil.h ǵ ATL_MAX_METHOD_NAME ۰ų ƾ մϴ.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_IMPERSONATIONFAILED "<html><head><title> </title></head><body><H1> </H1><P>Ŭ̾Ʈ ߱ û ߽ϴ.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_ISAPISTARTUPFAILED "<html><head><title> </title></head><body><H1> </H1><P> û óϴ ISAPI ͽټ ε ߽ϴ.</body></html>"
- IDS_ATLSRV_SERVER_ERROR_SOAPNOSOAPACTION "<html><head><title>Server Error</title></head><body><H1>Server Error</H1><P>SOAP request did not provide SOAPACTION header.</body></html>"
-
- IDS_ATLSRV_CRITICAL_HEAPCREATEFAILED "û ۼ ߽ϴ."
- IDS_ATLSRV_CRITICAL_WORKERINITFAILED "۾ 带 ʱȭ ߽ϴ."
- IDS_ATLSRV_CRITICAL_CRITSECINITFAILED "Ӱ ʱȭ ߽ϴ."
- IDS_ATLSRV_CRITICAL_THREADPOOLFAILED " Ǯ ʱȭ ߽ϴ."
- IDS_ATLSRV_CRITICAL_DLLCACHEFAILED "DLL ijø ʱȭ ߽ϴ."
- IDS_ATLSRV_CRITICAL_PAGECACHEFAILED " ijø ʱȭ ߽ϴ."
- IDS_ATLSRV_CRITICAL_STENCILCACHEFAILED "ٽ ijø ʱȭ ߽ϴ."
- IDS_ATLSRV_CRITICAL_SESSIONSTATEFAILED " 񽺸 ʱȭ ߽ϴ."
- IDS_ATLSRV_CRITICAL_BLOBCACHEFAILED "Blob ijø ʱȭ ߽ϴ."
- IDS_ATLSRV_CRITICAL_FILECACHEFAILED " ijø ʱȭ ߽ϴ."
-
- IDS_PERFMON_CACHE "ATL :ij"
- IDS_PERFMON_CACHE_HELP "ATL ijÿ "
- IDS_PERFMON_HITCOUNT "ij Ƚ"
- IDS_PERFMON_HITCOUNT_HELP "ij Ƚ"
- IDS_PERFMON_MISSCOUNT "ij Ƚ"
- IDS_PERFMON_MISSCOUNT_HELP "ij Ƚ"
- IDS_PERFMON_CURRENTALLOCATIONS " ij Ҵ緮"
- IDS_PERFMON_CURRENTALLOCATIONS_HELP "ij÷ Ҵ ޸ "
- IDS_PERFMON_MAXALLOCATIONS "ִ ij Ҵ緮"
- IDS_PERFMON_MAXALLOCATIONS_HELP "ij÷ Ҵ ִ ޸ "
- IDS_PERFMON_CURRENTENTRIES " ij Ʈ"
- IDS_PERFMON_CURRENTENTRIES_HELP " ij Ʈ "
- IDS_PERFMON_MAXENTRIES "ִ ij Ʈ"
- IDS_PERFMON_MAXENTRIES_HELP "ִ ij Ʈ "
- IDS_PERFMON_HITCOUNTRATE "ij ߷"
- IDS_PERFMON_HITCOUNTRATE_HELP " Ƚ"
- IDS_PERFMON_REQUEST "ATL :û"
- IDS_PERFMON_REQUEST_HELP " ޵Ǵ û "
- IDS_PERFMON_REQUEST_TOTAL " û "
- IDS_PERFMON_REQUEST_TOTAL_HELP " û "
- IDS_PERFMON_REQUEST_FAILED " û "
- IDS_PERFMON_REQUEST_FAILED_HELP " û "
- IDS_PERFMON_REQUEST_RATE " û /"
- IDS_PERFMON_REQUEST_RATE_HELP " û "
- IDS_PERFMON_REQUEST_AVG_RESPONSE_TIME " ð"
- IDS_PERFMON_REQUEST_AVG_RESPONSE_TIME_HELP "û ó ҿ ð"
- IDS_PERFMON_REQUEST_CURR_WAITING "⿭ ִ û"
- IDS_PERFMON_REQUEST_CURR_WAITING_HELP "ó û "
- IDS_PERFMON_REQUEST_MAX_WAITING "ִ û "
- IDS_PERFMON_REQUEST_MAX_WAITING_HELP "ó ִ û "
- IDS_PERFMON_REQUEST_ACTIVE_THREADS "Ȱ "
- IDS_PERFMON_REQUEST_ACTIVE_THREADS_HELP "û ȭ óϴ "
-END
-
-
-#ifndef ATL_NO_DEFAULT_STENCIL_RESOURCE
-dllmgr.srf HTML "res\\dllmgr.srf"
-stencilmgr.srf HTML "res\\stencilmgr.srf"
-threadmgr.srf HTML "res\\threadmgr.srf"
-#endif
-
-
-//
-// Stencil parse error support
-//
-#ifdef ATL_DEBUG_STENCILS
-
-STRINGTABLE DISCARDABLE
-BEGIN
- IDS_STENCIL_ERROR_STENCIL
-"{{ڵ 0}}<h1><font color=#ff0000> ٽ мϴ ߻߽ϴ.</font></h1>\r\n{{while GetNextError}}<table border=1 width=50%>\r\n<tr><td width=25%> </td><td>{{GetErrorText}}</td></tr>\r\n<tr><td> ȣ</td><td>{{GetErrorLineNumber}}</td></tr>\r\n<tr><td> ؽƮ</td><td><pre>{{GetErrorLine}}</pre></td></tr>\r\n</table>\r\n{{endwhile}}<br>ٽ ϴ.\r\n<hr>"
-
- IDS_STENCIL_UNCLOSEDBLOCK_IF "{{if}} {{endif}} ϴ."
- IDS_STENCIL_UNCLOSEDBLOCK_ELSE "{{else}} {{endif}} ϴ."
- IDS_STENCIL_UNCLOSEDBLOCK_WHILE "{{while}} {{endwhile}} ϴ."
- IDS_STENCIL_UNOPENEDBLOCK_ENDWHILE "{{endwhile}} {{while}} ϴ"
- IDS_STENCIL_UNOPENEDBLOCK_ELSE "{{else}} {{if}} ϴ."
- IDS_STENCIL_UNOPENEDBLOCK_ENDIF "{{endif}} {{if}} Ǵ {{else}} ϴ."
-
- IDS_STENCIL_INVALID_HANDLER "ó ±װ ߸Ǿϴ."
- IDS_STENCIL_NULLPARAM "ParseReplacements Ű NULLԴϴ."
- IDS_STENCIL_INVALIDSTRING " ְų ڿ ParseReplacements ޵Ǿϴ."
- IDS_STENCIL_EMBEDDED_NULL "ٽǿ Ե null ڰ ֽϴ."
- IDS_STENCIL_UNMATCHED_TAG_START "{{ ġ ʽϴ."
- IDS_STENCIL_MISMATCHED_TAG_START "{{ ġ ʽϴ."
- IDS_STENCIL_BAD_PARAMETER "Ű ߸Ǿϴ."
- IDS_STENCIL_METHODNAME_TOO_LONG "޼ ̸ ʹ ϴ."
- IDS_STENCIL_HANDLERNAME_TOO_LONG "ó ̸ ʹ ϴ."
- IDS_STENCIL_INVALID_SUBHANDLER " ó ±װ ߸Ǿϴ."
- IDS_STENCIL_UNRESOLVED_REPLACEMENT "ü Ȯ ϴ: '%s'"
-
- IDS_STENCIL_INCLUDE_ERROR "Ե ϴ."
- IDS_STENCIL_INCLUDE_INVALID "Ե ũ ƴմϴ."
-
- IDS_STENCIL_MLANG_COCREATE "CMultiLanguage ϴ."
- IDS_STENCIL_MLANG_LCID "lcid ߻߽ϴ."
- IDS_STENCIL_MLANG_GETLOCALE "GetLocaleInfo ߽ϴ."
- IDS_STENCIL_MLANG_GETCHARSET "GetCharsetInfo ߽ϴ."
-
- IDS_STENCIL_OUTOFMEMORY "޸𸮰 մϴ."
- IDS_STENCIL_UNEXPECTED "ġ Դϴ."
-END
-
-#endif
diff --git a/include/atl/res/dllmgr.srf b/include/atl/res/dllmgr.srf
deleted file mode 100644
index 45f9c7049..000000000
--- a/include/atl/res/dllmgr.srf
+++ /dev/null
@@ -1,29 +0,0 @@
-<!--
- This is a part of the Active Template Library.
- Copyright (C) Microsoft Corporation
- All rights reserved.
-
- This source code is only intended as a supplement to the
- Active Template Library Reference and related
- electronic documentation provided with the library.
- See these sources for detailed information regarding the
- Active Template Library product.
--->
-
-<html>
-<body bgcolor={{GetBodyColor}}>
-<H1 align=left> ATL Server DLL Cache Manager </H1>
-
-Current DLL Cache Entries: {{GetNumEntries}}<p>
-
-<table border=1>
-<tr bgcolor={{GetTRColor}}><th>DLL Path</th><th>Ref Count</th></tr>
-
-{{while EnumEntries}}
-<tr bgcolor={{GetTRColor}}><td align=center>{{GetDllName}}</td><td align=center>{{GetDllReferences}}</tr>
-{{endwhile}}
-
-</table>
-
-</body>
-</html> \ No newline at end of file
diff --git a/include/atl/res/stencilmgr.srf b/include/atl/res/stencilmgr.srf
deleted file mode 100644
index f0ca82fa3..000000000
--- a/include/atl/res/stencilmgr.srf
+++ /dev/null
@@ -1,69 +0,0 @@
-<!--
- This is a part of the Active Template Library.
- Copyright (C) Microsoft Corporation
- All rights reserved.
-
- This source code is only intended as a supplement to the
- Active Template Library Reference and related
- electronic documentation provided with the library.
- See these sources for detailed information regarding the
- Active Template Library product.
--->
-<html>
- <body bgcolor="{{GetBodyColor}}">
- <H1 align="left">
- ATL Server Stencil Cache Management
- </H1>
- <table border="1" width="50%">
- <tr bgcolor="{{GetTRColor}}">
- <th align="center">
- Value</th><th align="center">Quantity</th></tr>
- {{while GetNextStencilCacheStats}}
- <tr bgcolor="{{GetTRColor}}">
- <td>{{GetCacheValue}}</td>
- <td>{{GetCacheQuantity}}</td>
- </tr>
- {{endwhile}}
- </table>
- <form method="post">
- <input type="hidden" name="Handler" value="StencilMgrSrf"> <input type="hidden" name="Method" value="ExecuteCommand">
- <select name="command" onchange="HandleFormOnChange(this);">
- <option value="0">Clear All Statistics</option>
- <option value="1">Remove Stencil</option>
- <option value="2">Remove All Stencils</option>
- <option value="3">Set default Lifespan</option>
- </select>
- <br>
- <span id="DynValueCap"></span><input type="text" name="DynValue" style="visibility=hidden">
- <br>
- <input type="submit" value="Execute Command">
- </form>
- <script language="JavaScript">
-function HandleFormOnChange(select_object)
-{
-
- //alert(select_object.form.elements["StencilName"].type);
-
- if (select_object.value==1)
- {
- select_object.form.elements["DynValue"].style.visibility="visible";
- window.document.all["DynValueCap"].innerHTML = "Stencil Name:&nbsp;";
-
- }
- else if (select_object.value==3)
- {
- select_object.form.elements["DynValue"].style.visibility="visible";
- window.document.all["DynValueCap"].innerHTML = "New Lifetime:&nbsp;";
- }
- else
- {
- select_object.form.elements["DynValue"].style.visibility="hidden";
- window.document.all["DynValueCap"].innerHTML="";
- }
-}
-
-
-
- </script>
- </body>
-</html>
diff --git a/include/atl/res/threadmgr.srf b/include/atl/res/threadmgr.srf
deleted file mode 100644
index fd322be77..000000000
--- a/include/atl/res/threadmgr.srf
+++ /dev/null
@@ -1,24 +0,0 @@
-<!--
- This is a part of the Active Template Library.
- Copyright (C) Microsoft Corporation
- All rights reserved.
-
- This source code is only intended as a supplement to the
- Active Template Library Reference and related
- electronic documentation provided with the library.
- See these sources for detailed information regarding the
- Active Template Library product.
--->
-<html>
- <body bgcolor="{{GetBodyColor}}">
- <H1 align="left">
- ATL Server Thread Pool Management
- </H1>
- This server's thread pool is currently using {{GetSize}} threads.<p>
- <form method="post">
- <input type="hidden" name="Handler" value="ThreadMgrSrf"> <input type="hidden" name="Method" value="ExecuteCommand">
- <input type="hidden" name="command" value="0"> Enter a new thread pool size: <input type="text" name="DynValue">
- <input type="submit" value="Change Thread Pool">
- </form>
- </body>
-</html>