コード例 #1
0
void vmsHttpFlvTrafficAnalyzer::ExtractTitleFromHtml(const vmsHttpTrafficCollector::HttpDialog *pHtmlDlg, wstring &wstrTitle)
{
	wstrTitle = L"";
	UINT codePage = 0;
	ExtractCodePageFromHtml (pHtmlDlg, codePage);
	if (!codePage)
		codePage = pHtmlDlg->codePage;

	assert (pHtmlDlg != NULL);
	if (!pHtmlDlg)
		return;

	if (pHtmlDlg->vbResponseBody.empty ())
		return;
	
	LPCSTR psz = strstrni ((LPCSTR)&pHtmlDlg->vbResponseBody [0], "<title>", pHtmlDlg->vbResponseBody.size ());
	if (psz)
	{
		psz += 7;
		LPCSTR pszEnd = (LPCSTR)&pHtmlDlg->vbResponseBody [0] + pHtmlDlg->vbResponseBody.size ();
		string strTitle;
		while (psz < pszEnd)
		{
			if (*psz != '<')
				strTitle += *psz++;
			else 
				break;
		}
		if (*psz == '<' && !strTitle.empty ())
		{
			vmsCharsets::DecodeString (strTitle.c_str (), 
				codePage ? codePage : CP_UTF8, wstrTitle);
				
			while (wstrTitle.empty () == false && wstrTitle [0] <= ' ')
				wstrTitle.erase (wstrTitle.begin ());
			while (wstrTitle.empty () == false && wstrTitle [wstrTitle.length ()-1] <= ' ')
				wstrTitle.erase (wstrTitle.end ()-1);
			for (int i = 0; i < wstrTitle.length (); i++)
			{
				if (wstrTitle [i] < ' ')
					wstrTitle [i] = ' ';
				if (i && wstrTitle [i] == ' ' && wstrTitle [i-1] == ' ')
					wstrTitle.erase (wstrTitle.begin () + i--);
			}
		}
	}
}
コード例 #2
0
void vmsHttpFlvTrafficAnalyzer::ExtractTitleFromXWwwFormUrlEncoded(const vmsHttpTrafficCollector::HttpDialog *pDlg, wstring &wstrTitle)
{
	wstrTitle = L"";

	assert (pDlg != NULL);
	if (!pDlg)
		return;
	assert (pDlg->enCT == vmsHttpTrafficCollector::HttpDialog::X_WWW_FORM_URL_ENCODED);

	if (pDlg->vbResponseBody.empty ())
		return;
	
	extern LPCSTR strstrni (LPCSTR pszSrc, LPCSTR pszSrch, int lenSrc);
	LPCSTR psz = strstrni ((LPCSTR)&pDlg->vbResponseBody [0], "&title=", pDlg->vbResponseBody.size ());
	if (!psz)
		return;

	psz += 7; 
	int iLenAvail = (int)pDlg->vbResponseBody.size () - (psz - (LPCSTR)&pDlg->vbResponseBody [0]);

	string strTitle;
	while (iLenAvail > 0 && *psz != '&')
	{
		strTitle += *psz++;
		iLenAvail--;
	}

	if (strTitle.empty ())
		return;

	for (int i = 0; i < strTitle.length (); i++)
	{
		if (strTitle [i] == '+')
			strTitle [i] = ' ';
	}

	string strDecodedTitle;
	vmsHttpHelper::DecodeUrl (strTitle.c_str (), strDecodedTitle);

	int n = MultiByteToWideChar (CP_UTF8, 0, strDecodedTitle.c_str (), -1, NULL, 0);
	assert (n != 0);
	LPWSTR pwsz = new WCHAR [n+1]; *pwsz = 0;
	MultiByteToWideChar (CP_UTF8, 0, strDecodedTitle.c_str (), -1, pwsz, n);
	wstrTitle = pwsz;
	delete [] pwsz;
}
コード例 #3
0
void vmsHttpFlvTrafficAnalyzer::ExtractTitleFromHtml(const vmsHttpTrafficCollector::HttpDialog *pHtmlDlg, wstring &wstrTitle)
{
	wstrTitle = L"";

	assert (pHtmlDlg != NULL);
	if (!pHtmlDlg)
		return;

	if (pHtmlDlg->vbResponseBody.empty ())
		return;
	
	extern LPCSTR strstrni (LPCSTR pszSrc, LPCSTR pszSrch, int lenSrc);
	LPCSTR psz = strstrni ((LPCSTR)&pHtmlDlg->vbResponseBody [0], "<title>", pHtmlDlg->vbResponseBody.size ());
	if (psz)
	{
		psz += 7;
		LPCSTR pszEnd = (LPCSTR)&pHtmlDlg->vbResponseBody [0] + pHtmlDlg->vbResponseBody.size ();
		string strTitle;
		while (psz < pszEnd)
		{
			if (*psz != '<')
				strTitle += *psz++;
			else 
				break;
		}
		if (*psz == '<')
		{
			const vmsHttpParser::HdrField *pFld = pHtmlDlg->pHttpResponse->FieldByName ("Content-Type");
			LPCSTR pszCharset = pFld ? strstr (pFld->strValue.c_str (), "charset") : NULL;
			if (pszCharset)
			{
				pszCharset += 7;
				while (*pszCharset == ' ')
					pszCharset++;
				if (*pszCharset == '=')
				{
					pszCharset++;
					while (*pszCharset == ' ')
						pszCharset++;
					string strCharset;
					while (*pszCharset != ' ' && *pszCharset != 0)
						strCharset += *pszCharset++;
					UINT nCP = vmsCharsets::GetCpIdFromName (strCharset.c_str ());
					if (nCP)
					{
						int n = MultiByteToWideChar (nCP, 0, strTitle.c_str (), -1, NULL, 0);
						assert (n != 0);
						LPWSTR pwsz = new WCHAR [n+1];
						MultiByteToWideChar (nCP, 0, strTitle.c_str (), -1, pwsz, n);
						wstrTitle = pwsz;
						delete [] pwsz;
					}
				}
			}
			
			if (wstrTitle.empty ())
			{
				USES_CONVERSION;
				wstrTitle = A2W (strTitle.c_str ());
			}
				
			while (wstrTitle.empty () == false && wstrTitle [0] <= ' ')
				wstrTitle.erase (wstrTitle.begin ());
			while (wstrTitle.empty () == false && wstrTitle [wstrTitle.length ()-1] <= ' ')
				wstrTitle.erase (wstrTitle.end ()-1);
			for (int i = 0; i < wstrTitle.length (); i++)
			{
				if (wstrTitle [i] < ' ')
					wstrTitle [i] = ' ';
				if (i && wstrTitle [i] == ' ' && wstrTitle [i-1] == ' ')
					wstrTitle.erase (wstrTitle.begin () + i--);
			}
		}
	}
}
コード例 #4
0
void vmsHttpFlvTrafficAnalyzer::ExtractTitleFromXml(const vmsHttpTrafficCollector::HttpDialog *pDlg, wstring &wstrTitle, const vmsHttpTrafficCollector::HttpDialog* pFlvDlg)
{
	extern LPCSTR strstrni (LPCSTR pszSrc, LPCSTR pszSrch, int lenSrc);
	extern LPCSTR strstrn (LPCSTR pszSrc, LPCSTR pszSrch, int lenSrc);

	wstrTitle = L"";
	
	assert (pDlg != NULL);
	if (!pDlg)
		return;
	assert (pDlg->enCT == vmsHttpTrafficCollector::HttpDialog::XML);
	
	if (pDlg->vbResponseBody.empty ())
		return;

	LPCSTR pszXml = (LPCSTR)&pDlg->vbResponseBody [0];
	int iXmlLen = pDlg->vbResponseBody.size ();

	

	LPCSTR pszXml2 = strstrni (pszXml, "encoding=\"", iXmlLen);
	if (!pszXml2)
		return;
	
	pszXml2 += 10;
	iXmlLen -= pszXml2 - pszXml;
	pszXml = pszXml2;
	if (iXmlLen < 5)
		return;

	if (strnicmp (pszXml, "utf-8", 5))
		return;

	

	USES_CONVERSION;
	tstring tstrRequestUrl = A2CT (pFlvDlg->strRequestUrl.c_str ());
	
	
	string strUrl = vmsXmlHelper::toUtf8noEncode (tstrRequestUrl);
	pszXml2 = strstrn (pszXml, strUrl.c_str (), iXmlLen);

	if (!pszXml2)
	{
		
		strUrl = vmsXmlHelper::toUtf8 (tstrRequestUrl);
		pszXml2 = strstrn (pszXml, strUrl.c_str (), iXmlLen);
		if (!pszXml2)
		{
			
			strUrl = pFlvDlg->strRequestUrl;
			pszXml2 = strstrn (pszXml, strUrl.c_str (), iXmlLen);
		}
	}

	

	LPCSTR pszVideoSectionTag = pszXml;

	if (pszXml2)
	{
		

		bool bAsAttr = pszXml2 [-1] != '>'; 

		if (bAsAttr)
		{
			
			
			while (pszXml2 > pszXml && *pszXml2 != '"')
				pszXml2--;
			pszXml2--;
			if (pszXml2 > pszXml)
			{
				bool bInQ = false;
				while (pszXml2 > pszXml)
				{
					if (*pszXml2 == '"')
						bInQ = !bInQ;
					else if (*pszXml2 == '<' && bInQ == false)
						break;
					pszXml2--;
				}
				if (pszXml2 > pszXml)
					pszVideoSectionTag = pszXml2;
			}
		}
		else
		{
			
			

			
			while (pszXml2 > pszXml && *pszXml2 != '<')
				pszXml2--;
			pszXml2--;
			if (pszXml2 > pszXml)
			{
				
				bool bInT = false; 
				while (pszXml2 > pszXml)
				{
					if (*pszXml2 == '<')
					{
						if (bInT)
						{
							
							bInT = false;
						}
						else
						{
							if (pszXml2 [1] == '/')
							{
								bInT = true; 
							}
							else
							{
								
								
								break;
							}
						}
					}
					pszXml2--;
				}
				if (pszXml2 > pszXml)
					pszVideoSectionTag = pszXml2;
			}
		}
	}

	

	int iXmlLen2 = iXmlLen - (pszVideoSectionTag - pszXml);

	LPCSTR apszTags [] = {"title=\"", "<title>", "name=\"", "<name>"};
	int iTag;
	LPCSTR pszTitle = NULL;
	
	do
	{	
		for (iTag = 0; iTag < sizeof (apszTags)/sizeof (LPCSTR) && pszTitle == NULL; iTag++)
			pszTitle = strstrni (pszVideoSectionTag, apszTags [iTag], iXmlLen2);
		if (!pszTitle)
		{
			if (pszVideoSectionTag != pszXml)
			{
				
				pszVideoSectionTag = pszXml;
				iXmlLen2 = iXmlLen;
			}
			else
			{
				return; 
			}			
		}
	}
	while (pszTitle == NULL);

	pszTitle += strlen (apszTags [iTag]);

	LPCSTR pszTitleE = pszTitle;
	int iXmlLen3 = iXmlLen - (pszTitle - pszXml);
	char chEnd = pszTitle [-1] == '>' ? '<' : '"';
	while (*pszTitleE != chEnd && iXmlLen3)
	{
		pszTitleE++;
		iXmlLen3--;
	}
	if (!iXmlLen3)
		return; 
	string strTitle; strTitle.assign (pszTitle, pszTitleE-pszTitle);

	int n = MultiByteToWideChar (CP_UTF8, 0, strTitle.c_str (), -1, NULL, 0);
	assert (n != 0);
	LPWSTR pwsz = new WCHAR [n+1]; *pwsz = 0;
	MultiByteToWideChar (CP_UTF8, 0, strTitle.c_str (), -1, pwsz, n);
	wstrTitle = pwsz;
	delete [] pwsz;
}