Example #1
0
void CWaveSession::PostRequests()
{
	// This method is responsible for deleting the requests because requests
	// may later be stored. Responses can be linked to a request and when this
	// becomes necessary, this function will take the requests for later retrieval.
	// Now, we just delete them.

	wstringstream szPostData;

	ASSERT(m_vRequestQueue.size() > 0);

	szPostData << L"count=" << m_vRequestQueue.size();

	INT nOffset = 0;

	for (TWaveRequestVectorConstIter iter = m_vRequestQueue.begin(); iter != m_vRequestQueue.end(); iter++)
	{
		szPostData << L"&req" << nOffset << L"_key=" << UrlEncode(SerializeRequest(*iter));

		nOffset++;
	}

	// Post the JSON to the channel.

	wstring szUrl = Format(WAVE_URL_CHANNEL_POST, m_szStickySessionID.c_str(), m_szSID.c_str(), m_nRID++, BuildHash().c_str());

	if (m_lpPostRequest != NULL)
	{
		m_vOwnedRequests.push_back(m_lpPostRequest);
	}

	m_lpPostRequest = new CCurl(szUrl, m_lpTargetWindow);

	m_lpPostRequest->SetUserAgent(GetUserAgent());
	m_lpPostRequest->SetTimeout(WEB_TIMEOUT_SHORT);
	m_lpPostRequest->SetIgnoreSSLErrors(TRUE);
	m_lpPostRequest->SetCookies(GetCookies());

	m_lpPostRequest->SetUrlEncodedPostData(szPostData.str());

	CNotifierApp::Instance()->QueueRequest(m_lpPostRequest);

	for (TWaveRequestVectorIter iter1 = m_vRequestQueue.begin(); iter1 != m_vRequestQueue.end(); iter1++)
	{
		ASSERT(*iter1 != NULL);

		(*iter1)->RequestCompleted();

		delete *iter1;
	}

	m_vRequestQueue.clear();
}
Example #2
0
void TWebPgFetchEvent::OnConnect(const uint64& SockId){
  TChA RqChA;
  if (CurUrl->IsHttpRqStr()){
    RqChA=CurUrl->GetHttpRqStr();
  } else {
    // get http components
    TStr HostNm=CurUrl->GetHostNm();
    TStr AbsPath=CurUrl->GetPathStr()+CurUrl->GetSearchStr();
    // compose http request
    RqChA+="GET "; RqChA+=AbsPath; RqChA+=" HTTP/1.0\r\n";
    RqChA+="Host: "; RqChA+=HostNm; RqChA+="\r\n";
    if (!UserAgentStr.Empty()){ 
      RqChA+="User-Agent: "; RqChA+=UserAgentStr; RqChA+="\r\n";}
    // add cookies
    if (GetCookies()>0){
      RqChA+="Cookie: ";
      for (int CookieN=0; CookieN<GetCookies(); CookieN++){
        TStr KeyNm; TStr ValStr; TStr DmNm; TStr PathStr;
        GetCookie(CookieN, KeyNm, ValStr, DmNm, PathStr);
        if (HostNm.EndsWith(DmNm)){
          if (CookieN>0){RqChA+="; ";}
          RqChA+=KeyNm; RqChA+='='; RqChA+=ValStr; 
        }
      }
      RqChA+="\r\n";
    }
    // finish request
    RqChA+="\r\n";
  }
  // send http request
  PSIn RqSIn=TMIn::New(RqChA);
  bool Ok; TStr ErrMsg; Sock->Send(RqSIn, Ok, ErrMsg);
  if (Ok){
    Sock->PutTimeOut(TimeOutMSecs);
  } else {
    OnFetchError("Unable to send the data: " + ErrMsg);
  }
}
Example #3
0
void CWaveSession::PostChannelRequest()
{
	if (m_lpRequest != NULL)
	{
		m_vOwnedRequests.push_back(m_lpChannelRequest);
	}

	m_lpChannelRequest = new CCurl(
		Format(WAVE_URL_CHANNEL, m_szStickySessionID.c_str(), m_szSID.c_str(), m_nAID, BuildHash().c_str()),
		m_lpTargetWindow
	);

	m_lpChannelRequest->SetUserAgent(GetUserAgent());
	m_lpChannelRequest->SetTimeout(WEB_TIMEOUT_CHANNEL);
	m_lpChannelRequest->SetIgnoreSSLErrors(TRUE);
	m_lpChannelRequest->SetCookies(GetCookies());
	m_lpChannelRequest->SetReader(new CWaveReader(this));

	CNotifierApp::Instance()->QueueRequest(m_lpChannelRequest);
}
Example #4
0
void CWaveSession::PostSIDRequest()
{
	if (m_lpRequest != NULL)
	{
		m_vOwnedRequests.push_back(m_lpRequest);
	}

	m_lpRequest = new CCurl(
		Format(WAVE_URL_SESSIONID, m_szStickySessionID.c_str(), m_nRID++, BuildHash().c_str()),
		m_lpTargetWindow
	);

	m_lpRequest->SetUserAgent(GetUserAgent());
	m_lpRequest->SetTimeout(WEB_TIMEOUT_SHORT);
	m_lpRequest->SetIgnoreSSLErrors(TRUE);
	m_lpRequest->SetCookies(GetCookies());
	m_lpRequest->SetReader(new CCurlUTF8StringReader());

	m_lpRequest->SetUrlEncodedPostData(L"count=0");

	m_nRequesting = WSR_SID;

	CNotifierApp::Instance()->QueueRequest(m_lpRequest);
}
// Performs contact list retrieval
// Input:	csLogin=String with user's telephone number
//			csPwd=String with user's password
// Output:	Contact list
CMapStringToOb* CCopiagenda::RetrieveContacts(CString csLogin, CString csPwd)
{
	CMapStringToOb* pmsoList=NULL;

	CString csData;

	CString csCookie;

    CString csHeaders;
	CString csRetHeaders;
	CString csRetData;

	csData.Format("TM_ACTION=LOGIN&TM_LOGIN=%s&TM_PASSWORD=%s",csLogin,csPwd);
    csHeaders = "Content-type: application/x-www-form-urlencoded\r\n"
				"Accept-Encoding: gzip, deflate\r\n"
				"Host: copiagenda.movistar.es\r\n"
				"Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*\r\n"
				"Connection: Keep-Alive\r\n";

	UINT nCode=PostHTTPS("https://copiagenda.movistar.es/cp/ps/Main/login/Agenda",(BYTE*)csData.GetBuffer(0),csData.GetLength(),csHeaders,csRetHeaders,csRetData);
	if(nCode == 302)
	{
		csCookie=GetCookies(csRetHeaders);
		CString csURL=GetLocation(csRetHeaders);
		csHeaders = "Accept-Encoding: gzip, deflate\r\n"
					"Host: copiagenda.movistar.es\r\n"
					"Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*\r\n"
					"Connection: Keep-Alive\r\n";
		csHeaders += "Cookie: "+csCookie+"\r\n";

		nCode=GetHTTPS(csURL,csHeaders,csRetHeaders,csRetData);

		// We are asked to re-authenticate with user data + cookie and we receive a session token
		int nPosPwd=csRetData.Find("password\" value=");
		if(nPosPwd!=-1)
		{
			CString csPwdAux=csRetData.Mid(nPosPwd+16);
			int nPosPwd2=csPwdAux.Find(">");
			if(nPosPwd2!=-1)
			{
				CString csPwd2=csPwdAux.Left(nPosPwd2);

				csData.Format("password=%s&u=%s&d=movistar.es",csPwd2,csLogin);
				csHeaders = "Content-type: application/x-www-form-urlencoded\r\n"
							"Accept-Encoding: gzip, deflate\r\n"
							"Host: copiagenda.movistar.es\r\n"
							"Referer: https://copiagenda.movistar.es/cp/ps/Main/login/Verificacion?d=movistar.es\r\n"
							"Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*\r\n"
							"Connection: Keep-Alive\r\n";
				csHeaders += "Cookie: "+csCookie+"\r\n";

				UINT nCode=PostHTTPS("https://copiagenda.movistar.es/cp/ps/Main/login/Authenticate",(BYTE*)csData.GetBuffer(0),csData.GetLength(),csHeaders,csRetHeaders,csRetData);

				int nPosTok=csRetData.Find("&t=");
				if(nPosTok!=-1)
				{
					CString csTokAux=csRetData.Mid(nPosTok+3);
					int nPosTok2=csTokAux.Find("\"");
					if(nPosTok2!=-1)
					{
						// We ask for the data in text format delimited with TABs
						CString csToken=csTokAux.Left(nPosTok2);
						CString csURL = "https://copiagenda.movistar.es/cp/ps/PSPab/preferences/ExportContacts?d=movistar.es&c=yes&u="+csLogin+"&t="+csToken;
						csData = "fileFormat=TEXT&charset=8859_1&delimiter=TAB";
						csHeaders = "Content-type: application/x-www-form-urlencoded\r\n"
									"Accept-Encoding: gzip, deflate\r\n"
									"Host: copiagenda.movistar.es\r\n"
									"Referer: https://copiagenda.movistar.es/cp/ps/Main/login/Verificacion?d=movistar.es\r\n"
									"Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*\r\n"
									"Connection: Keep-Alive\r\n";
						csHeaders += "Cookie: "+csCookie+"\r\n";

						UINT nCode=PostHTTPS(csURL,(BYTE*)csData.GetBuffer(0),csData.GetLength(),csHeaders,csRetHeaders,csRetData);
						pmsoList = ParseResponse(csRetData);
					}
				}
			}
		}
	}

	return pmsoList;
}
Example #6
0
// Performs login to MMS service
// Input:	csLogin=String with user's telephone number
//			csPwd=String with user's password
// Returns:	UserId
CString CMMSSender::Login(CString csLogin, CString csPwd)
{
	if(m_pSession)
	{
		m_pSession->Close();
		delete m_pSession;
		m_pSession = NULL;

		DWORD SessionFlags = INTERNET_FLAG_NO_AUTH | INTERNET_FLAG_IGNORE_CERT_CN_INVALID;
		m_pSession = new CInternetSession(NULL,1,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,SessionFlags);

		CString csUserAgent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
		char strUserAgent[255];
		strcpy(strUserAgent,csUserAgent);
		m_pSession->SetOption(INTERNET_OPTION_USER_AGENT,(void*)strUserAgent,strlen(strUserAgent),0);
	}

	CString csData;
	CString csURL;

	CString csCookie;

    CString csHeaders;
	CString csRetHeaders;
	CString csRetData;

    // We try to access http://multimedia.movistar.es/
    csHeaders = "Connection: Keep-Alive\r\n";

	csURL.Format("http://%s/",m_csServer);
	UINT nCode=GetHTTP(csURL,csHeaders,csRetHeaders,csRetData);
	if(nCode == 302)
	{
        //We are redirected
		csCookie = GetCookies(csRetHeaders);
		CString csCookieSession=csCookie;

		// Login data posting
		csData.Format("TM_ACTION=LOGIN&variant=mensajeria&locale=sp-SP&client=html-msie-7-winxp&directMessageView=&uid=&uidl=&folder=&remoteAccountUID=&login=1&TM_LOGIN=%s&TM_PASSWORD=%s",csLogin,csPwd);
		csHeaders = "Content-type: application/x-www-form-urlencoded\r\n"
					"Accept-Encoding: identity\r\n"
					"Connection: Keep-Alive\r\n";

		CString csCookieSessionValue;
		int nPosValue=csCookieSession.Find("=");
		if(nPosValue!=-1)
		{
			csCookieSessionValue=csCookieSession.Mid(nPosValue+1);
			m_csUser = csCookieSessionValue;
		}
		csURL.Format("http://%s/do/dologin;jsessionid=%s",m_csServer,csCookieSessionValue);
		nCode=PostHTTP(csURL,(BYTE*)csData.GetBuffer(0),csData.GetLength(),csHeaders,csRetHeaders,csRetData);

		CString csMoreCookies=GetCookies(csRetHeaders);
		m_csCookie=csCookieSession + "; " + csMoreCookies;

		csHeaders = "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*\r\n"
					"Accept-Encoding: identity\r\n"
					"Connection: Keep-Alive\r\n";
		csHeaders += "Cookie: "+m_csCookie+"\r\n";
		csURL.Format("http://%s/do/multimedia/create?l=sp-SP&v=mensajeria",m_csServer);
		nCode=GetHTTP(csURL,csHeaders,csRetHeaders,csRetData);
	}

	m_csLogin = csLogin;

	return m_csUser;
}