Esempio n. 1
0
STDMETHODIMP
CCertEncodeAltName::Reset(
    /* [in] */ LONG NameCount)
{
    HRESULT hr = S_OK;

    _Cleanup();
    m_fConstructing = TRUE;
    if (CENCODEMAX < NameCount || 0 > NameCount)
    {
	hr = E_INVALIDARG;
	ceERRORPRINTLINE("bad count parameter", hr);
	goto error;
    }

    m_aValue = (CERT_ALT_NAME_ENTRY *) LocalAlloc(
				LMEM_FIXED | LMEM_ZEROINIT,
				NameCount * sizeof(m_aValue[0]));
    if (NULL == m_aValue)
    {
	hr = E_OUTOFMEMORY;
	ceERRORPRINTLINE("LocalAlloc", hr);
	goto error;
    }
    m_cValue = NameCount;

error:
    if (S_OK != hr)
    {
	_Cleanup();
    }
    return(_SetErrorInfo(hr, L"CCertEncodeAltName::Reset"));
}
Esempio n. 2
0
CFileDownloader::~CFileDownloader()
{
	_CloseFileHandler();
	_Cleanup();
	if(m_pBuffer)
		SAFE_DELETE_ARRAY(m_pBuffer);
}
Esempio n. 3
0
// destructor
IFSSaver::~IFSSaver()
{
	if (Looper()) {
		Looper()->RemoveHandler(this);
	}
	_Cleanup();
}
Esempio n. 4
0
STDMETHODIMP
CCertEncodeAltName::Decode(
    /* [in] */ BSTR const strBinary)
{
    HRESULT hr = S_OK;

    _Cleanup();

    if (NULL == strBinary)
    {
	hr = E_POINTER;
	ceERRORPRINTLINE("NULL parm", hr);
	goto error;
    }

    // Decode CERT_ALT_NAME_INFO:

    if (!ceDecodeObject(
		    X509_ASN_ENCODING,
		    X509_ALTERNATE_NAME,
		    (BYTE *) strBinary,
		    SysStringByteLen(strBinary),
		    FALSE,
		    (VOID **) &m_DecodeInfo,
		    &m_DecodeLength))
    {
	hr = ceHLastError();
	ceERRORPRINTLINE("ceDecodeObject", hr);
	goto error;
    }

    m_aValue = m_DecodeInfo->rgAltEntry;
    m_cValue = m_DecodeInfo->cAltEntry;

error:
    if (S_OK != hr)
    {
	_Cleanup();
    }
    return(_SetErrorInfo(hr, L"CCertEncodeAltName::Decode"));
}
Esempio n. 5
0
bool CILSLadderInfo::Load()
{
  ConfigDir *pDir = mainApp::GetConfig();
  wxString sFile = pDir->GetILSLadderFileName();
  _Cleanup();
  m_bIsOK = LoadFile(sFile);
  if(!m_bIsOK)
  {
    m_vKits.Clear();
  }
  return m_bIsOK;
}
Esempio n. 6
0
StackFrameValues::StackFrameValues(const StackFrameValues& other)
	:
	fValues(NULL)
{
	try {
		// init
		if (Init() != B_OK)
			throw std::bad_alloc();

		// clone all values
		for (ValueTable::Iterator it = other.fValues->GetIterator();
				ValueEntry* entry = it.Next();) {
			if (SetValue(entry->variable, entry->path, entry->value) != B_OK)
				throw std::bad_alloc();
		}
	} catch (...) {
		_Cleanup();
		throw;
	}
}
Esempio n. 7
0
BOOL CDownload::Start(INT nCorrurent)
{
	_Cleanup();
	_Reset();
	
	if(nCorrurent>0)
	{
		m_nCocurrent = nCorrurent;
		//m_locationPool.SetMainSiteLimit(m_nCocurrent-1);
		m_locationPool.SetMainSiteLimit(m_nCocurrent);
	}
	
	m_hStopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
	if (m_hStopEvent)
	{
		unsigned int nThreadID = 0;
		m_hThread = (HANDLE) _beginthreadex(NULL, 0, _RunThreadFun, this, 0, &nThreadID);
	}
	return TRUE;
}
Esempio n. 8
0
ExpressionValues::ExpressionValues(const ExpressionValues& other)
	:
	fValues(NULL)
{
	try {
		// init
		if (Init() != B_OK)
			throw std::bad_alloc();

		// clone all values
		for (ValueTable::Iterator it = other.fValues->GetIterator();
				ValueEntry* entry = it.Next();) {
			if (SetValue(entry->function, entry->thread, entry->expression,
				entry->value) != B_OK) {
				throw std::bad_alloc();
			}
		}
	} catch (...) {
		_Cleanup();
		throw;
	}
}
Esempio n. 9
0
COARartifact &COARartifact::operator =(const COARartifact &x)
{
  _Cleanup();
  COARcopy(m_sLabel);
  COARcopy(m_sUserDisplay);
  COARcopy(m_dtUpdate);
  COARcopy(m_vnMessageNumber);

  COARcopyVP(COARartifactAllele,m_vpAllele);
  _CopyCurrentAllele(x); // after COARcopyVP

  COARcopy(m_dRFU);
  COARcopy(m_dPullupHeightCorrection);
  COARcopy(m_dMeanBPS);
  COARcopy(m_dPeakArea);
  COARcopy(m_dWidth);
  COARcopy(m_dTime);
  COARcopy(m_dFit);
  COARcopy(m_nID);
  COARcopy(m_nLevel);
  COARcopy(m_bDisabled);
  COARcopy(m_bIsEditable);
  return *this;
}
Esempio n. 10
0
CKitLadderInfo::~CKitLadderInfo()
{
  _Cleanup();
}
Esempio n. 11
0
StackFrameValueInfos::~StackFrameValueInfos()
{
	_Cleanup();
}
Esempio n. 12
0
CNamedHKey::CNamedHKey(
    BSTR          bstrRegFullKeyValueName,
    SPLITKEYVALUE skv /* =KEYANDVALUE */)
    : m_skv(skv)
{
    m_hk = m_hkNonRemote = NULL;
    m_bstrRegFullKeyValueName = bstrRegFullKeyValueName;
    m_ptszComputername = m_ptszKeyname = m_ptszValuename = NULL;
    m_lErr = ERROR_SUCCESS;

    if (bstrRegFullKeyValueName == NULL)
    {
        _Cleanup(ERROR_INVALID_DATA);
        return;
    }

    // check for leading "\\computername\"
    if (bstrRegFullKeyValueName[0] == L'\\'
        &&  bstrRegFullKeyValueName[1] == L'\\')
    {
        BSTR bstrHKey = wcschr(bstrRegFullKeyValueName + 2, L'\\');

        // no '\' terminating computername or zero-length computername?
        if (bstrHKey == NULL  ||  bstrHKey == bstrRegFullKeyValueName + 2)
        {
            _Cleanup(ERROR_INVALID_DATA);
            return;
        }

        m_ptszComputername = TcsNDup(bstrRegFullKeyValueName,
                                     bstrHKey - bstrRegFullKeyValueName);
        if (m_ptszComputername == NULL)
        {
            _Cleanup(ERROR_OUTOFMEMORY);
            return;
        }
        bstrRegFullKeyValueName = bstrHKey + 1;
    }

    // Parse out the leading HKEY_xxx
    if ((m_hkNonRemote = _ParseHKeyRoot(bstrRegFullKeyValueName)) == NULL)
    {
        _Cleanup(ERROR_INVALID_HANDLE);
        return;
    }

    if (m_skv == KEYONLY)
    {
        // do not split into Key\Value pair
        m_ptszKeyname = TcsNDup(bstrRegFullKeyValueName);
        m_ptszValuename = NULL;
    }
    else if (m_skv == KEYANDVALUE)
    {
        // Look for last '\' to split off Valuename
        BSTR bstrValue = wcsrchr(bstrRegFullKeyValueName, L'\\');
        
        // Have name of form "HKLM\foo"; i.e., only one component?
        if (bstrValue == NULL)
        {
            m_ptszKeyname = TcsNDup(OLESTR(""));
            m_ptszValuename = TcsNDup(bstrRegFullKeyValueName);
        }
        else
        {
            m_ptszKeyname = TcsNDup(bstrRegFullKeyValueName,
                                    bstrValue - bstrRegFullKeyValueName);
            m_ptszValuename = TcsNDup(bstrValue + 1);
        }

        if (m_ptszValuename == NULL)
        {
            _Cleanup(ERROR_OUTOFMEMORY);
            return;
        }
    }
    else
    {
        _Cleanup(ERROR_INVALID_DATA);
        return;
    }
    
    if (m_ptszKeyname == NULL)
    {
        _Cleanup(ERROR_OUTOFMEMORY);
        return;
    }

    // Open the key on a remote registry?
    if (m_ptszComputername == NULL)
    {
        m_hk = m_hkNonRemote;
        m_hkNonRemote = NULL;
    }
    else
    {
        m_lErr = ::RegConnectRegistry(m_ptszComputername,
                                      m_hkNonRemote, &m_hk);
        
        if (m_lErr != ERROR_SUCCESS)
            _Cleanup(m_lErr);
    }
    
    // At this point, if m_hk == NULL, there's been an error.
    // Otherwise, m_hk is the key we'll use.
    //   If m_hkNonRemote != NULL, it's one of the predefined
    //     constants, HKEY_CLASSES_ROOT ... HKEY_DYN_DATA
    //     and m_hk refers to a key on a remote registry.
    //   else HKEY_CLASSES_ROOT <= m_hk <= HKEY_DYN_DATA.

    TRACE(_T("computer = `%s', keyname = `%s'\n")
          _T("\tvaluename = `%s', hk = %x, hkNonRemote = %x, ")
          _T("split = %d, err = %x\n"),
          m_ptszComputername, m_ptszKeyname,
          m_ptszValuename, (UINT) m_hk, (UINT) m_hkNonRemote,
          (int) m_skv, m_lErr);
}
Esempio n. 13
0
CNamedHKey::~CNamedHKey()
{
    _Cleanup(ERROR_SUCCESS);
}
Esempio n. 14
0
StackFrameValues::~StackFrameValues()
{
	_Cleanup();
}
Esempio n. 15
0
// StopSaver
void
IFSSaver::StopSaver()
{
	_Cleanup();
}
Esempio n. 16
0
CRegex::~CRegex()
{
	_Cleanup();
}
Esempio n. 17
0
CDownload::~CDownload()
{
	_Cleanup();
}
Esempio n. 18
0
void CDownload::Wait()
{
	if(m_hThread)
		WaitForSingleObject(m_hThread, INFINITE);
	_Cleanup();
}
Esempio n. 19
0
CCertEncodeAltName::~CCertEncodeAltName()
{
    _Cleanup();
}
Esempio n. 20
0
void CKitLadderInfo::Init()
{
  _Cleanup();
  m_sName.Empty();
  m_setLS->clear();
}
Esempio n. 21
0
CPlotData::~CPlotData()
{
  _Cleanup();
}
Esempio n. 22
0
VariablesViewState::~VariablesViewState()
{
	_Cleanup();
}
Esempio n. 23
0
status_t CRegex::SetTo(const char* pattern, bool ignoreCase, bool fullWord,
					   bool backward)
{
	_Cleanup();
	return _Init(pattern, ignoreCase, fullWord, backward);
}
Esempio n. 24
0
ExpressionValues::~ExpressionValues()
{
	_Cleanup();
}
Esempio n. 25
0
COARartifact::~COARartifact() 
{
  _Cleanup();
}
Esempio n. 26
0
CRequestInstance::~CRequestInstance()
{
    _Cleanup();
}
Esempio n. 27
0
BOOL CFileDownloader::_IssueRequest( CString strHostname, CString strPath, LPCTSTR szHeader, BOOL bUseProxyConfig )
{
	for(int nRetry=0; nRetry<3 && !_IfInterruptted(); ++nRetry)
	{
		_Cleanup();
		DEBUG_TRACE(_T("_IssueRequest Try %d \n"), nRetry );
		do 
		{
			DWORD dwAccessType = INTERNET_OPEN_TYPE_PRECONFIG;
			CString strProxyServer;			

			if(m_currentProxySetting.nProxyMode==PROXY_MODE_NONE)
			{
				dwAccessType = INTERNET_OPEN_TYPE_DIRECT;
			}
			else if(m_currentProxySetting.nProxyMode==PROXY_MODE_USER)
			{
				dwAccessType = INTERNET_OPEN_TYPE_PROXY;
				strProxyServer = m_currentProxySetting.strHost;
				if(m_currentProxySetting.nPort>0)
					strProxyServer.AppendFormat(_T(":%d"), m_currentProxySetting.nPort);
			}
			m_hSession = ::InternetOpen(BK_USER_AGENT, dwAccessType, strProxyServer, NULL, 0);
			if(m_hSession==NULL)
				break;
			
			::InternetSetOption(m_hSession, INTERNET_OPTION_CONNECT_TIMEOUT, &m_dwTimeout, sizeof(DWORD)/sizeof(BYTE));
			::InternetSetOption(m_hSession, INTERNET_OPTION_SEND_TIMEOUT, &m_dwTimeout, sizeof(DWORD)/sizeof(BYTE));
			::InternetSetOption(m_hSession, INTERNET_OPTION_RECEIVE_TIMEOUT, &m_dwTimeout, sizeof(DWORD)/sizeof(BYTE));
			m_hConnection = InternetConnect(m_hSession, strHostname, INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
			if(m_hConnection==NULL)
				break; 
			
			DWORD dwFlags = INTERNET_FLAG_RELOAD | INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_NO_UI | INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP | INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS;
			//DEBUG_TRACE(_T("InternetConnect DONE \n"));
			static LPCTSTR ppszAcceptTypes[2] =
			{
				_T("*/*"),
				NULL
			};
			m_hRequest = HttpOpenRequest(m_hConnection, _T("GET"), strPath, _T("HTTP/1.1"), NULL, ppszAcceptTypes, dwFlags, 0);
			if(m_hRequest==NULL)
				break; 
			if(szHeader)
				HttpAddRequestHeaders(m_hRequest, szHeader, (DWORD)_tcslen(szHeader), HTTP_ADDREQ_FLAG_ADD|HTTP_ADDREQ_FLAG_REPLACE);

			if(m_currentProxySetting.nProxyMode!=PROXY_MODE_NONE && m_currentProxySetting.bNeedAuthorization)
			{
				// 不管是否autodetect 都设置密码 
				if ( InternetSetOption(m_hRequest, INTERNET_OPTION_PROXY_USERNAME, (LPVOID) m_currentProxySetting.strLogin.operator LPCTSTR(), (m_currentProxySetting.strLogin.GetLength()+1) * sizeof(TCHAR))
					&& InternetSetOption(m_hRequest, INTERNET_OPTION_PROXY_PASSWORD, (LPVOID) m_currentProxySetting.strPassword.operator LPCTSTR(), (m_currentProxySetting.strPassword.GetLength()+1) * sizeof(TCHAR))
					)
				{
					;
				}
			}

			//DEBUG_TRACE(_T("HttpOpenRequest DONE \n"));
			BOOL bRet = HttpSendRequest(m_hRequest, NULL, 0, NULL, 0);
			DEBUG_TRACE(_T("HttpSendRequest DONE \n"));
			if(bRet)
				return TRUE;
		} while (FALSE);
		Sleep( 1*1000 );
	}	
	return FALSE;
}
Esempio n. 28
0
	~ArgVector()
	{
		_Cleanup();
	}
Esempio n. 29
0
DWORD CFileDownloader::Download( LPCTSTR lpszURL, LPCTSTR lpszFilename, LPCTSTR lpszRefererUrl, LPVOID pUserData, BOOL bUseCache, BOOL bUseProxyConfig )
{
	m_Stopped = FALSE;
	if(!SplitDownloadUrl( lpszURL, m_strHostname, m_strHostPath, m_strHostFilename ))
		return FALSE;
	
	m_pUserData = pUserData;
	m_strDownloadURL = lpszURL;
	m_strDownloadFile = lpszFilename;

	// Check the tmp file 
	m_strDownloadFileTemp = m_strDownloadFile + _T(".tmp");
	m_strDownloadFileInfo = m_strDownloadFile + _T(".nfo");		
	
	// Check if file exists 
	if( bUseCache && IsFileExist(m_strDownloadFile) )
	{
		return TRUE;
	}
	else if(!bUseCache)
	{
		DeleteFile(m_strDownloadFileTemp);
		DeleteFile(m_strDownloadFileInfo);
		DeleteFile(m_strDownloadFile);
	}
	
	CPubConfig::T_ProxySetting proxyconfig;
	CPubConfig pubconfig;
	pubconfig.LoadProxyConfig(proxyconfig);	
	SetProxySetting(proxyconfig);


	INT64 lContentSize = 0;
	INT64 lFileSize = 0;
	if( IsFileExist(m_strDownloadFileTemp) && IsFileExist(m_strDownloadFileInfo) )
	{
		CString strLastModified;
		BOOL notModified = FALSE;
		if( file_get_contents(m_strDownloadFileInfo, strLastModified) )		
		{
			LPCTSTR lpszLengthTag = _T("; length=");
			LPCTSTR pszLen = _tcsstr(strLastModified, lpszLengthTag);
			if(pszLen)
			{
				pszLen+= _tcslen(lpszLengthTag);
				lContentSize = _ttoi64(pszLen);
			}

			// 检查文件是否完全下载完成了 
			lFileSize = file_get_size( m_strDownloadFileTemp );
			if(lFileSize>0 && lFileSize==lContentSize)
			{
				MoveFile(m_strDownloadFileTemp, m_strDownloadFile);
				DeleteFile(m_strDownloadFileInfo);
				return TRUE;
			}

			if( _CheckIfModifiedSince(lpszURL, strLastModified, bUseProxyConfig, notModified) && notModified )
			{
			}
			else
			{
				lFileSize = 0;
			}
		}
	}
	// 如果文件已经过期, 或者文件的信息文件不存在, 都删除旧下载临时文件 
	if(lFileSize==0)
	{
		DeleteFile(m_strDownloadFileTemp);
		DeleteFile(m_strDownloadFileInfo);
	}
	
	// Prepare file 
	_CloseFileHandler();
	m_hFile = CreateFile(m_strDownloadFileTemp, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
	if( m_hFile==INVALID_HANDLE_VALUE )
		return FALSE;
	SetFilePointer( m_hFile, lFileSize, 0, FILE_BEGIN );
	
	if(m_pBuffer==NULL)
		m_pBuffer = new BYTE[HTTP_BUFFER_SIZE];	
	INT nRetry = HTTP_DEFAULT_RETYR;
	INT nRetried = 0;
	do 
	{
		INT iRet = _DownloadFileFrom(lFileSize, lContentSize, bUseProxyConfig);
		DEBUG_TRACE(_T("FD:_DownloadFileFrom %I64d/%I64d LastError:%d Ret:%d"), lFileSize, lContentSize, GetLastError(), iRet);
		_Cleanup();

		if(iRet>0)
		{
			// 考虑socket 被主动关闭 
			if(lFileSize>=lContentSize)
				break;
			nRetry = HTTP_DEFAULT_RETYR;
		}
		else if(iRet==0)
		{
			--nRetry;
		}
		else if(iRet==-1)
		{
			// 文件长度不匹配! 需要删了文件, 然后重新下载 
			_CloseFileHandler();
			DeleteFile(m_strDownloadFileTemp);
			DeleteFile(m_strDownloadFileInfo);
			lFileSize = lContentSize = 0;
			
			m_hFile = CreateFile(m_strDownloadFileTemp, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
			if( m_hFile==INVALID_HANDLE_VALUE )
				break;
			--nRetry;
		}
		else if(iRet==-2)
		{
			// 写入文件失败, 直接返回
			break;
		}
		else
		{
			ATLASSERT(FALSE);
			break;
		}
		++ nRetried;
	} while (!m_Stopped && nRetry>0 && nRetried<HTTP_DEFAULT_MAXRETYR);
	
	_CloseFileHandler();
	BOOL bFileDone = FALSE;
	if(lContentSize==0)
	{
		// 163.com 等页面
		if(lFileSize==0)
		{
			DeleteFile(m_strDownloadFileTemp);
		}
		else if(!m_Stopped)
		{
			bFileDone = TRUE;
		}
	}
	else
	{
		bFileDone = lFileSize>=lContentSize;
	}
	if(bFileDone)
	{
		MoveFile(m_strDownloadFileTemp, m_strDownloadFile);
		DeleteFile(m_strDownloadFileInfo);
	}
	BOOL bRet = PathFileExists(m_strDownloadFile);
	_FireFileDownloaderEvent(bRet ? IFileDownloaderObserver::DOWNLOAD_COMPLETE : IFileDownloaderObserver::DOWNLOAD_ERROR);
	return bRet;
}
Esempio n. 30
0
	bool Parse(const char* commandLine)
	{
		_Cleanup();

		// init temporary arg/argv storage
		std::string currentArg;
		std::vector<std::string> argVector;

		fCurrentArg = &currentArg;
		fCurrentArgStarted = false;
		fArgVector = &argVector;

		for (; *commandLine; commandLine++) {
			char c = *commandLine;

			// whitespace delimits args and is otherwise ignored
			if (isspace(c)) {
				_PushCurrentArg();
				continue;
			}

			switch (c) {
				case '\'':
					// quoted string -- no quoting
					while (*++commandLine != '\'') {
						c = *commandLine;
						if (c == '\0') {
							fprintf(stderr, "Error: Unterminated quoted "
								"string.\n");
							return false;
						}
						_PushCharacter(c);
					}
					break;

				case '"':
					// quoted string -- some quoting
					while (*++commandLine != '"') {
						c = *commandLine;
						if (c == '\0') {
							fprintf(stderr, "Error: Unterminated quoted "
								"string.\n");
							return false;
						}

						if (c == '\\') {
							c = *++commandLine;
							if (c == '\0') {
								fprintf(stderr, "Error: Unterminated quoted "
									"string.\n");
								return false;
							}

							// only '\' and '"' can be quoted, otherwise the
							// the '\' is treated as a normal char
							if (c != '\\' && c != '"')
								_PushCharacter('\\');
						}

						_PushCharacter(c);
					}
					break;

				case '\\':
					// quoted char
					c = *++commandLine;
					if (c == '\0') {
						fprintf(stderr, "Error: Command line ends with "
							"'\\'.\n");
						return false;
					}
					_PushCharacter(c);
					break;

				default:
					// normal char
					_PushCharacter(c);
					break;
			}
		}

		// commit last arg
		_PushCurrentArg();

		// build arg vector
		fArgc = argVector.size();
		fArgv = new char*[fArgc + 1];
		for (int i = 0; i < fArgc; i++) {
			int len = argVector[i].length();
			fArgv[i] = new char[len + 1];
			memcpy(fArgv[i], argVector[i].c_str(), len + 1);
		}
		fArgv[fArgc] = NULL;

		return true;
	}