Esempio n. 1
0
void SlimItem::InsertPath(const CString& strPath, const CStringA& strOsFlag)
{
    CString strRealPath;
    TCHAR* temp = new TCHAR[MAX_PATH * 2];
    WinVersion sysVersion = KGetWinVersion();

    if (!strOsFlag.CompareNoCase("xp") && sysVersion >= WINVERSION_VISTA)
        return;

    if (!strOsFlag.CompareNoCase("vista") && sysVersion != WINVERSION_VISTA)
        return;

    if (!strOsFlag.CompareNoCase("win7") && sysVersion <= WINVERSION_VISTA)
        return;

    if (!ExpandEnvironmentStrings(strPath, temp, MAX_PATH * 2))
        return;

    strRealPath = temp;

    if (strRealPath.Find(L"*") != -1)
    {
        _FindPath(strRealPath);
    } 
    else if (::GetFileAttributes(strRealPath) != INVALID_FILE_ATTRIBUTES)
    {    
        m_itemPaths.Add(strRealPath);
    }
}
Esempio n. 2
0
BOOL CCaHtmlParse::__IsTwoAirPort(const CStringA & straCode1, const CStringA & straCode2)
{
	BOOL bRet = FALSE;
	if (0 == straCode1.CompareNoCase("SHA") || 0 == straCode1.CompareNoCase("PVG") || 0 == straCode1.CompareNoCase("PEK") || 0 == straCode1.CompareNoCase("NAY")
		|| 0 == straCode2.CompareNoCase("SHA") || 0 == straCode2.CompareNoCase("PVG") || 0 == straCode2.CompareNoCase("PEK") || 0 == straCode2.CompareNoCase("NAY"))
	{
		bRet = TRUE;
	}
	return bRet;
}
Esempio n. 3
0
BOOL CCaHtmlParse::__findCaFlight(SCaLowPriceFlightDetail** pFind, const CStringA & straFlightStartDate, const CStringA & straDPortCode
	, const CStringA & straAPortCode, const CStringA & straFlightNo, const std::list<SCaLowPriceFlightDetail*> & listFlight)
{
	*pFind = NULL;
	BOOL bFind = FALSE;
	SCaLowPriceFlightDetail* pCur = NULL;
	for (std::list<SCaLowPriceFlightDetail*>::const_iterator it = listFlight.begin(); it != listFlight.end();  it++)
	{
		pCur = *it;
		if (0 == straFlightNo.CompareNoCase(pCur->straFlightNo) && 0 == straDPortCode.CompareNoCase(pCur->straFromCityCode)
			&& 0 == straAPortCode.CompareNoCase(pCur->straToCityCode) && 0 == straFlightStartDate.CompareNoCase(pCur->straFromDate))
		{
			bFind = TRUE;
			*pFind = pCur;
			break;
		}
	}
	return bFind;
}
Esempio n. 4
0
BOOL CCaHtmlParse::__IsFlightValid(const TidyNode & tdChild)
{
	BOOL bValid = TRUE;
	TidyNode tRadioNode;
	CStringA straValid;
	tRadioNode = tidyGetChild(tdChild);
	straValid.Format("%s", GetAttValue(tRadioNode, "disabled"));
	if (0 == straValid.CompareNoCase("disabled"))
		bValid = FALSE;

	return bValid;
}
Esempio n. 5
0
CCookie* CCookie::FromString(const CStringA& strCookie, LPCSTR lpszDefaultDomain, LPCSTR lpszDefaultPath)
{
	CStringA strName;
	CStringA strValue;
	CStringA strDomain;
	CStringA strPath;

	int iMaxAge			  = -1;
	BOOL bHttpOnly		  = FALSE;
	BOOL bSecure		  = FALSE;
	EnSameSite enSameSite = SS_NONE;

	int i		= 0;
	int iStart	= 0;

	while(TRUE)
	{
		CStringA strField = strCookie.Tokenize(COOKIE_FIELD_SEP, iStart);
		strField.Trim();

		if(strField.IsEmpty())
			break;

		if(i == 0)
		{
			ParseFieldKV(strField, strName, strValue, COOKIE_KV_SEP_CHAR);

			if(strName.IsEmpty())
				return nullptr;
		}
		else
		{
			CStringA strKey;
			CStringA strVal;

			ParseFieldKV(strField, strKey, strVal, COOKIE_KV_SEP_CHAR);

			if(strKey.CompareNoCase(COOKIE_DOMAIN) == 0)
				strDomain = strVal;
			else if(strKey.CompareNoCase(COOKIE_PATH) == 0)
				strPath = strVal;
			else if(strKey.CompareNoCase(COOKIE_MAX_AGE) == 0 && !strVal.IsEmpty())
				iMaxAge = atoi(strVal);
			else if(strKey.CompareNoCase(COOKIE_EXPIRES) == 0 && !strVal.IsEmpty() && iMaxAge == -1)
			{
				__time64_t tmExpires = -1;

				if(!ParseExpires(strVal, tmExpires))
					return nullptr;

				iMaxAge = ExpiresToMaxAge(tmExpires);
			}
			else if(strKey.CompareNoCase(COOKIE_HTTPONLY) == 0)
				bHttpOnly = TRUE;
			else if(strKey.CompareNoCase(COOKIE_SECURE) == 0)
				bSecure = TRUE;
			else if(strKey.CompareNoCase(COOKIE_SAMESITE) == 0)
			{
				if(strVal.IsEmpty() || strVal.CompareNoCase(COOKIE_SAMESITE_STRICT) == 0)
					enSameSite = SS_STRICT;
				else if(strVal.CompareNoCase(COOKIE_SAMESITE_LAX) == 0)
					enSameSite = SS_LAX;
			}
		}

		++i;
	}

	if(!AdjustDomain(strDomain, lpszDefaultDomain) || !AdjustPath(strPath, lpszDefaultPath))
		return nullptr;

	CCookie* pCookie = new CCookie(strName, strValue, strDomain, strPath, iMaxAge, bHttpOnly, bSecure, enSameSite);
	ASSERT(pCookie->IsValid());

	return pCookie;
}
Esempio n. 6
0
BOOL CHttpDataParser::ParseRecvData( PBYTE pRecvData,int nRecvDataLen,BOOL *pbFinalData)
{
	BOOL bAddRes = FALSE;
	do 
	{
		if ( NULL == pRecvData || nRecvDataLen == 0 )
		{
			break;
		}

		//如果还没有接受到头部,则缓存数据,等待头部
		if ( FALSE == m_bHeaderOk )
		{
			m_bufHead.AppendData(pRecvData,nRecvDataLen);
		}
		else
		{
			m_bufContent.AppendData(pRecvData,nRecvDataLen);
		}

		if ( FALSE == m_bHeaderOk )
		{
			BYTE *pHeadDataBuffer = m_bufHead.GetDataBuffer();
			LONGLONG llHeadDataLen = m_bufHead.GetTotalBufferLen();
			CHttpRecvParser recvparser;
			if (recvparser.ParseData((const char *)pHeadDataBuffer,llHeadDataLen) )
			{
				m_bHeaderOk = TRUE;

				m_nContentStart = recvparser.GetContentStart();

				int nRecvContentLen = llHeadDataLen - m_nContentStart;
				if ( nRecvContentLen > 0 )
				{
					m_bufContent.AppendData(pHeadDataBuffer+m_nContentStart,nRecvContentLen);
				}

				m_pCallback(m_pCallbackParam,pHeadDataBuffer,m_nContentStart,TRUE);

				CStringA strContentLen;
				CStringA strContentEncoding;
				CStringA strTransferEncoding;

				strContentLen = recvparser.GetValueByName("Content-Length");
				strContentEncoding = recvparser.GetValueByName("Content-Encoding");
				strTransferEncoding = recvparser.GetValueByName("Transfer-Encoding");

				if ( !strContentLen.IsEmpty() )
				{
					//没有传输编码
					m_teEncoding = TE_NO_ENCODING;
					m_llTotalContentLen = _ttoi64(CString(strContentLen));
				}
				else if( !strTransferEncoding.IsEmpty() )
				{
					//有传输编码
					if ( strTransferEncoding.CompareNoCase("chunked") == 0 )
					{
						m_teEncoding = TE_CHUNKED;
					}
					else
					{
						ASSERT(FALSE);
					}
				}
				else
				{
					m_teEncoding = TE_NO_ENCODING;
					m_llTotalContentLen = 0;
				}

				if( !strContentEncoding.IsEmpty() )
				{
					//内容有压缩编码
					if ( strContentEncoding.Find("gzip") >= 0 )
					{
						m_ceEncoding = CE_GZIP;
					}
					else
					{
						m_ceEncoding = CE_UNKNOWN;
					}
				}
				else
				{
					m_ceEncoding = CE_NO_ENCODING;
				}
			}
		}

		if ( m_bHeaderOk )
		{
			BYTE *pContentDataBuffer = m_bufContent.GetDataBuffer();
			LONGLONG llContentDataLen = m_bufContent.GetTotalBufferLen();

			if ( pContentDataBuffer && llContentDataLen )
			{
				HandleContentData( pContentDataBuffer , llContentDataLen,pbFinalData);
				m_bufContent.DestoryData();
			}
		}

		bAddRes = TRUE;

	} while (FALSE);

	return bAddRes;
}
Esempio n. 7
0
int CBoxScript::ParseScriptText(LPCSTR pstrText, int nCount, CStringA& strScriptText, int nIncludeFlagIndex)
{
	CStringA strTempText;
	if(nCount >= 2 && (BYTE)pstrText[0] == 0xff && (BYTE)pstrText[1] == 0xfe)
	{
/*		int _nTempCount = WideCharToMultiByte(_AtlGetConversionACP(), 0, LPWSTR(pstrText + 2), (nCount - 2) / 2, NULL, 0, NULL, NULL);
		LPSTR _pstr = strTempText.GetBuffer(_nTempCount);

		WideCharToMultiByte(_AtlGetConversionACP(), 0, LPWSTR(pstrText + 2), (nCount - 2) / 2, _pstr, _nTempCount, NULL, NULL);
		strTempText.ReleaseBuffer(_nTempCount);
*/

//发现是Unicode则检查是否已经存在CodePage,存在就转换到当前CodePage,否则转换成UTF8同时设定m_CodePage为65001
		if (m_uiCodePage == 0)
			m_uiCodePage = CP_UTF8;

		int _nTempCount = WideCharToMultiByte(m_uiCodePage, 0, LPWSTR(pstrText + 2), (nCount - 2) / 2, NULL, 0, NULL, NULL);
		LPSTR _pstr = strTempText.GetBuffer(_nTempCount);

		WideCharToMultiByte(m_uiCodePage, 0, LPWSTR(pstrText + 2), (nCount - 2) / 2, _pstr, _nTempCount, NULL, NULL);
		strTempText.ReleaseBuffer(_nTempCount);

		pstrText = strTempText;
		nCount = strTempText.GetLength();
	}
	else if(nCount >= 3 && (BYTE)pstrText[0] == 0xEF && (BYTE)pstrText[1] == 0xBB && (BYTE)pstrText[2] == 0xBF)
	{
		pstrText += 3;
		nCount -= 3;

		if (m_uiCodePage && m_uiCodePage != CP_UTF8)
		{
			CStringW strTempTextW;
			int _nTempCount = MultiByteToWideChar(CP_UTF8, 0, pstrText, nCount, NULL, 0);
			LPWSTR _pstrW = strTempTextW.GetBuffer(_nTempCount);

			MultiByteToWideChar(CP_UTF8, 0, pstrText, nCount, _pstrW, _nTempCount);
			strTempTextW.ReleaseBuffer(_nTempCount);
			
			_nTempCount = WideCharToMultiByte(m_uiCodePage, 0, strTempTextW, strTempTextW.GetLength(), NULL, 0, NULL, NULL);
			LPSTR _pstr = strTempText.GetBuffer(_nTempCount);

			WideCharToMultiByte(m_uiCodePage, 0, strTempTextW, strTempTextW.GetLength(), _pstr, _nTempCount, NULL, NULL);
			strTempText.ReleaseBuffer(_nTempCount);

			pstrText = strTempText;
			nCount = strTempText.GetLength();
		}
		else
			m_uiCodePage = CP_UTF8;
	}
	else
	{
		UINT uiCodePage = ParseScriptTextCodePage(pstrText, nCount);
		if (uiCodePage == 0)
			uiCodePage = GetACP();

		//if (m_uiCodePage == 0)
		//	m_uiCodePage = CP_UTF8;

		if (m_uiCodePage && m_uiCodePage != uiCodePage)
		{
			CStringW strTempTextW;
			int _nTempCount = MultiByteToWideChar(uiCodePage, 0, pstrText, nCount, NULL, 0);
			LPWSTR _pstrW = strTempTextW.GetBuffer(_nTempCount);

			MultiByteToWideChar(uiCodePage, 0, pstrText, nCount, _pstrW, _nTempCount);
			strTempTextW.ReleaseBuffer(_nTempCount);
			
			_nTempCount = WideCharToMultiByte(m_uiCodePage, 0, strTempTextW, strTempTextW.GetLength(), NULL, 0, NULL, NULL);
			LPSTR _pstr = strTempText.GetBuffer(_nTempCount);

			WideCharToMultiByte(m_uiCodePage, 0, strTempTextW, strTempTextW.GetLength(), _pstr, _nTempCount, NULL, NULL);
			strTempText.ReleaseBuffer(_nTempCount);

			pstrText = strTempText;
			nCount = strTempText.GetLength();
		}
		else
		{
			m_uiCodePage = uiCodePage;
		}
	}

	static struct
	{
		char *pstrName;
		int nSize;
	}CmdName[] =
	{
		{"#include", 8},
		{"#language", 9},
		{"#debug", 6},
		{"#timeout", 8},
		{"#transaction", 12},
		{"#codepage", 9}
	};
	#define CMD_COUNT (sizeof(CmdName) / sizeof(CmdName[0]))
	int i;
	LPCSTR pstrTemp, pstrTemp1;
	int nTempCount;
	int nLineCount = 1;

	while(nCount > 0 && IsBlank(pstrText[0]))
	{
		if(pstrText[0] == '\n')
			nLineCount ++;

		pstrText ++;
		nCount --;
	}

	while(nCount > 0 && pstrText[0] == '#')
	{
		for(i = 0; i < CMD_COUNT; i ++)
			if(nCount > CmdName[i].nSize &&
				!_strnicmp(pstrText, CmdName[i].pstrName, CmdName[i].nSize) &&
				IsBlankChar(pstrText[CmdName[i].nSize]))
				break;

		if(i == CMD_COUNT)
			break;

		pstrText += CmdName[i].nSize;
		nCount -= CmdName[i].nSize;

		while(nCount > 0 && IsBlankChar(pstrText[0]))
		{
			pstrText ++;
			nCount --;
		}

		if(nCount > 0 && pstrText[0] == '\"')
		{
			pstrText ++;
			nCount --;
		}

		pstrTemp = pstrText;
		nTempCount = nCount;
		while(nTempCount > 0 && !IsLineChar(pstrTemp[0]))
		{
			pstrTemp ++;
			nTempCount --;
		}

		pstrTemp1 = pstrTemp;
		while(pstrTemp1 > pstrText && IsBlankChar(pstrTemp1[0]))
			pstrTemp1 --;

		if(pstrTemp1 > pstrText && pstrTemp1[-1] == '\"')
			pstrTemp1 --;

		CStringA strValue;

		strValue.SetString(pstrText, (int)(pstrTemp1 - pstrText));

		pstrText = pstrTemp;
		nCount = nTempCount;

		switch(i)
		{
		case 0:
			strValue.MakeLower();
			if(LoadScriptFile(BOX_CA2CT(strValue), strScriptText, nLineCount))
				return 500;
			break;
		case 1:
			m_strLanguage = strValue;
			break;
		case 2:
			m_bEnableDebug = !strValue.CompareNoCase("on") || !strValue.CompareNoCase("true");
			if(!strValue.CompareNoCase("step"))
				m_bStepDebug = TRUE;
			break;
		case 3:
			m_pHost->m_nTimeout = atoi(strValue);
			break;
		case 4:
			if(!strValue.CompareNoCase("Required"))
                m_nTransaction = 3;
			else if(!strValue.CompareNoCase("Requires_New"))
				m_nTransaction = 2;
			else if(!strValue.CompareNoCase("Supported"))
				m_nTransaction = 1;
			else if(!strValue.CompareNoCase("Not_Supported"))
				m_nTransaction = 0;
			break;
		case 5:
			//(uiCodePage)
			break;
		}

		while(nCount > 0 && IsBlank(pstrText[0]))
		{
			if(pstrText[0] == '\n')
				nLineCount ++;

			pstrText ++;
			nCount --;
		}
	}

	AddLineMap(nIncludeFlagIndex, nLineCount);

	strScriptText.Append(pstrText, nCount);
	strScriptText += _T("\r\n");

	m_nScriptLine ++;

	pstrTemp = pstrText;
	nTempCount = nCount;
	while(nTempCount > 0)
	{
		if(pstrTemp[0] == '\n')
			m_nScriptLine ++;

		pstrTemp ++;
		nTempCount --;
	}

	return 0;
}
Esempio n. 8
0
void CClientDlg::SendWebSocket()
{
	static LPCSTR CLOSE_FLAG	 = "$close";
	static const BYTE MASK_KEY[] = {0x1, 0x2, 0x3, 0x4};

	USES_CONVERSION;

	if(!CheckStarted(FALSE))
		return;

	CString strBody;
	m_Body.GetWindowText(strBody);

	CStringA strBodyA	= T2A(strBody);
	BYTE* pData			= (BYTE*)(LPCSTR)strBodyA;
	int iLength			= strBodyA.GetLength();
	CONNID dwConnID		= m_pClient->GetConnectionID();

	if(strBodyA.CompareNoCase(CLOSE_FLAG) != 0)
	{
		if(m_pClient->SendWSMessage(TRUE, 0, 0x1, MASK_KEY, pData, iLength))
		{
			CString strContent;
			strContent.Format(_T("[WebSocket] (len: %d)"), iLength);

			::LogSend(dwConnID, strContent);

			BOOL bFinal;
			BYTE iReserved;
			BYTE iOperationCode;
			LPCBYTE lpszMask;
			ULONGLONG ullBodyLen;

			VERIFY(m_pClient->GetWSMessageState(&bFinal, &iReserved, &iOperationCode, &lpszMask, &ullBodyLen, nullptr));

			if(!m_bListener) ::PostOnWSMessageHeader(dwConnID, bFinal, iReserved, iOperationCode, lpszMask, ullBodyLen);

			if(ullBodyLen > 0)
			{
				m_pClient->GetResponseBody((LPCBYTE*)&pData, &iLength);

				if(!m_bListener) ::PostOnWSMessageBody(dwConnID, pData, iLength);
			}

			if(!m_bListener) ::PostOnWSMessageComplete(dwConnID);

			if(iOperationCode == 0x8)
				OnBnClickedStop();
		}
		else
		{
			::LogSendFail(dwConnID, ::GetLastError(), ::GetSocketErrorDesc(SE_DATA_SEND));
			SetAppState(ST_STOPPED);
		}
	}
	else
	{
		if(m_pClient->SendWSMessage(TRUE, 0, 0x8, MASK_KEY, nullptr, 0))
		{
			::LogSend(dwConnID, _T("[WebSocket] (OP: close)"));
		}

		m_Body.SetWindowText(_T(""));

		OnBnClickedStop();
	}

	m_pClient->CleanupRequestResult();
}
Esempio n. 9
0
BOOL CFCacheImpl::QueryTopExt(
    IFCacheQueryback* piQueryback,
    int nTop
    )
{
    BOOL retval = FALSE;
    int nRetCode;
    char* szError = NULL;
    CStringA strSql;
    sqlite3_stmt* pStmt = NULL;

    if (!m_pDbConnect)
        goto clean0;

    if (!piQueryback)
        goto clean0;

    strSql.Format("select ext, sum(size), sum(count) from exts group by ext order by sum(size) desc");
    nRetCode = sqlite3_prepare(m_pDbConnect, strSql, -1, &pStmt, 0);
    if (nRetCode)
        goto clean0;

    nRetCode = sqlite3_step(pStmt);
    if (nRetCode == SQLITE_ROW)
        goto get_data;

    sqlite3_finalize(pStmt);
    pStmt = NULL;

    strSql.Format("insert into exts(ext, size, count) select ext, sum(size), count(size) from files group by ext order by sum(size) desc limit %d",
                  nTop);

    nRetCode = sqlite3_exec(m_pDbConnect, strSql, NULL, NULL, &szError);
    if (nRetCode)
        goto clean0;

    strSql.Format("select ext, size, count from exts");

    nRetCode = sqlite3_prepare(m_pDbConnect, strSql, -1, &pStmt, 0);
    if (nRetCode)
        goto clean0;

    nRetCode = sqlite3_step(pStmt);
    if (nRetCode != SQLITE_ROW)
        goto clean0;

get_data:
    while (SQLITE_ROW == nRetCode)
    {
        CStringA strExt = (char*)sqlite3_column_text(pStmt, 0);
        ULONGLONG qwSize = sqlite3_column_int64(pStmt, 1);
        ULONGLONG qwCount = sqlite3_column_int64(pStmt, 2);

        if (strExt.CompareNoCase(".n/a") == 0)
        {
            strExt = "N/A";
        }

        piQueryback->OnExtData(KUTF8_To_UTF16(strExt), qwSize, qwCount);

        nRetCode = sqlite3_step(pStmt);
    }

    retval = TRUE;

clean0:
    if (pStmt)
    {
        sqlite3_finalize(pStmt);
        pStmt = NULL;
    }

    return retval;
}