コード例 #1
0
ファイル: CCommunity.cpp プロジェクト: Anubhav652/mtasa-blue
void CCommunity::Login ( VERIFICATIONCALLBACK pCallBack, void* pObject )
{
    m_bLoggedIn = false;

    if ( pCallBack && pObject )
    {
        m_pCallback = pCallBack;
        m_pVerificationObject = pObject;
    }

    // Get our serial number
    char szSerial [ 64 ];
    g_pCore->GetNetwork ()->GetSerial ( szSerial, sizeof ( szSerial ) );

    // Create the URL
    SString strURL ( VERIFICATION_URL "?username=%s&password=%s&serial=%s",
                     m_strUsername.c_str(),
                     m_strPassword.c_str(),
                     szSerial );

    // Perform the HTTP request
    GetHTTP()->Reset();
    GetHTTP()->QueueFile( strURL, NULL, 0, NULL, 0, false, this, StaticDownloadFinished, false, 1/*uiConnectionAttempts*/ );

    // Store the start time
    m_ulStartTime = CClientTime::GetTime ();
}
コード例 #2
0
ファイル: CCommunity.cpp プロジェクト: Anubhav652/mtasa-blue
void CCommunity::DoPulse ( void )
{
    if ( m_ulStartTime )
    {
        GetHTTP()->ProcessQueuedFiles();
    }
}
コード例 #3
0
///////////////////////////////////////////////////////////////
//
// CRemoteMasterServer::Refresh
//
//
//
///////////////////////////////////////////////////////////////
void CRemoteMasterServer::Refresh ( void )
{
    // If it's been less than a minute and we has data, don't send a new request
    if ( GetTickCount64_ () - m_llLastRefreshTime < 60000 && m_strStage == "hasdata" )
        return;

    // Send new request
    m_strStage = "waitingreply";
    m_llLastRefreshTime = GetTickCount64_ ();
    AddRef();   // Keep alive
    GetHTTP()->QueueFile( m_strURL, NULL, 0, NULL, 0, false, this, &CRemoteMasterServer::StaticDownloadFinished, false, 1 );
}
コード例 #4
0
///////////////////////////////////////////////////////////////
//
// CRemoteMasterServer::Init
//
//
//
///////////////////////////////////////////////////////////////
void CRemoteMasterServer::Init ( const SString& strURL )
{
    m_strURL = strURL;
    GetHTTP()->SetMaxConnections( 5 );
}
コード例 #5
0
///////////////////////////////////////////////////////////////
//
// CRemoteMasterServer::HasData
//
//
//
///////////////////////////////////////////////////////////////
bool CRemoteMasterServer::HasData ( void )
{
    GetHTTP()->ProcessQueuedFiles();
    return m_strStage == "hasdata";
}
コード例 #6
0
ファイル: cl_serverlist.c プロジェクト: jitspoe/starviewer
// unused function
static void M_ServerlistUpdate (char *sServerSource)
{
	char *buffer = NULL;
	int numread = -1;
	qboolean file = false;
	char *current;
	char *found = NULL;
	int bytes_read = 0;

	if (!*sServerSource)
		return;

	Com_Printf("Retrieving serverlist from %s.\n", sServerSource);

	if (strstr(sServerSource, "://"))
	{
		buffer = Z_Malloc(BUFFER_SIZE);
		numread = GetHTTP(sServerSource, buffer, BUFFER_SIZE);
		current = buffer;

		if (numread < 0)
			return;

		current = buffer;

		// find \n\n, thats the end of header/beginning of the data
		while (*current != '\n' || *(current + 2) != '\n')
		{
			if (current > buffer + numread)
			{
				FILE *fp;

				Com_Printf("WARNING: Invalid serverlist %s (no header).\n", sServerSource);

				if (fp = fopen("invalid_serverlist.txt", "ab"))
				{
					fwrite(buffer, numread, 1, fp);
					fclose(fp);
				}

				free(buffer);
				return; 
			}

			current++;
		};

		current = current + 3; // skip the trailing \n.  We're at the beginning of the data now

		if (strchr(current, '<'))
		{
			// If it has any HTML codes in it, we know it's not valid (probably a 404 page).
			if (strstr(current, "Not Found") || strstr(current, "not found"))
			{
				Com_Printf("WARNING: %s returned 404 Not Found.\n", sServerSource);
			}
			else
			{
				FILE *fp;

				Com_Printf("WARNING: Invalid serverlist: %s\n", sServerSource);

				if (fp = fopen("invalid_serverlist.txt", "ab"))
				{
					fwrite(buffer, numread, 1, fp);
					fclose(fp);
				}
			}

			Z_Free(buffer);
			return;
		}
	}
	else // Local file?
	{
		numread = FS_LoadFileZ(sServerSource, (void **)&buffer);
		file = true;
		current = buffer;

		if (numread < 0)
		{
			Com_Printf("WARNING: Bad serverlist address: %s\n", sServerSource);
			Com_Printf("Serverlist must be a file in the pball directory or http site.\n");
			return;
		}
	}

	// Ping all of the servers on the list
	while (current < buffer + numread)
	{
		found = current;						// Mark the beginning of the line

		while (*current && *current != '\r' && *current != '\n')
		{										// Find the end of the line
			current++; 
			
			if (current > buffer + numread)
			{
				if (file)
					FS_FreeFile(buffer);
				else
					Z_Free(buffer);

				return;	// Exit if we run out of room
			}
		}

		*current = 0; // NULL terminate the string

		if (!*found || Q_streq(found, "X"))
			goto done;

		CL_PingServerlistServer(found);
		Sleep(16); // jitodo -- make a cvar for the time between pings
		// Start at the next line:
		current++;

		while ((*current == '\r' || *current == '\n') && (current < buffer + numread))
			current++;
	};

done:
	if (current + 1 < buffer + numread)
	{
		// Check to make sure they're updated with the latest version.
		if (found = strstr(current + 1, "LatestClientBuild:"))
		{
			int latest_build;

			found += sizeof("LatestClientBuild:")-1;
			latest_build = atoi(found);

			if (latest_build > BUILD)
			{
				if (!g_notified_of_new_version) // only pop it up once.
				{
					Cbuf_AddTextThreadsafe("menu newversion\n");
					g_notified_of_new_version = true;
				}
			}
		}
	}

	if (file)
		FS_FreeFile(buffer);
	else
		Z_Free(buffer);

	return;
}
コード例 #7
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;
}
コード例 #8
0
ファイル: HttpRequest.cpp プロジェクト: dblock/baseclasses
int CHttpRequest::ExecuteGet(bool Recurse) {

    bool bContinueExecuteGet = false;
    bool bKeepAlive = false;

    Trace(tagHttp, levInfo, ("CHttpRequest - ExecuteGet"));

    unsigned int nCredentialsIndex = 0;

    bool Result;

    do {

        if (! bKeepAlive) {
            Result = CreateSocket();
            
            if (! Result) {
                return -1;
            }
        }

        bContinueExecuteGet = false;

        // process authentication

        CString AuthHeader;
        
        switch(m_ServerAuthState.GetLeg()) {
        case AUTHENTICATION_STATE_NONE:            
            break;
        case AUTHENTICATION_STATE_PRECHALENGE:            
        case AUTHENTICATION_STATE_CHALENGE:
            if (! m_ServerAuthState.GetNextHeader(& AuthHeader, nCredentialsIndex))
                return m_RStatusValue;
            break;
        }

        ClearResults(false);

        // add the auth header
        if (AuthHeader.GetLength())
            SetHttpField(g_strHttpAuthorization, AuthHeader);

        /* create socket and get results */
                
        CStringTable Connection;
        if (!m_HttpFields.FindAndCopy(g_strHttpConnection, Connection) || 
            ! Connection.GetValue(g_strHttpConnection).GetLength()) {            
            SetHttpField(g_strHttpConnection, "Keep-Alive");
        }       
        
        
        Result = GetHTTP((float) 1.0);

        // 406: no acceptable objects found (NT4/ISM)
        // if (!Result || (m_RStatusValue == 406)) {            
        //    ClearResults(false);
        //    Result = CreateSocket() && GetHTTP((float) 0.9);
        //    if (! Result) {
        //        return -1;
        //    }
        // }

        Trace(tagHttp, levInfo, ("CHttpRequest - ExecuteGet {%d/%d}", Result, m_RStatusValue));        
        
        if (! Result) {
            return -1;
        }
        
        CString l_RedirectLoc;
        CUrl ResolvedUrl;

        switch(m_RStatusValue) {
        case 407:
            // $(TODO)
            break;
            
        case 401:        

            // any valid authentication stage
            if (m_ServerAuthState.GetLeg() == AUTHENTICATION_STATE_NONE) {         
                // we need to send credentials
                m_ServerAuthState.SetLeg(AUTHENTICATION_STATE_PRECHALENGE);
                bContinueExecuteGet = true;                
            } else if (m_ServerAuthState.GetLeg() == AUTHENTICATION_STATE_CHALENGE) {
                nCredentialsIndex ++;
                // equal, because we do want to run once without username/password credentials
                if (nCredentialsIndex <= m_ServerAuthState.GetSize()) {
                    bContinueExecuteGet = true;
                }
                m_ServerAuthState.SetLeg(AUTHENTICATION_STATE_PRECHALENGE);
                bKeepAlive = false;
            } else if (m_ServerAuthState.GetLeg() == AUTHENTICATION_STATE_PRECHALENGE) {
                m_ServerAuthState.SetLeg(AUTHENTICATION_STATE_CHALENGE);
                bContinueExecuteGet = true;
                bKeepAlive = true;
            }
            
            break;
            
        case 301: /* redirections */
        case 302:
        case 303:
        case 307:

            l_RedirectLoc = m_RFields.FindElement(g_strHttpLocation).GetValue(g_strHttpLocation);
            
            if (! l_RedirectLoc.GetLength()) {
                Trace(tagHttp, levInfo, ("CHttpRequest - GetHTTP - %d redirection without a Location: header.", m_RStatusValue));		      
                break;
	    }
                
            // HTTP 1.1 - Temporary Redirect is 302 and 307
            // m_RRedirections is relevant for final URL address
            // that could be retrieved
            
            ResolvedUrl = m_Url.Resolve(l_RedirectLoc);        
            l_RedirectLoc = ResolvedUrl.GetHttpAll();        
            
            if (m_FollowRedirections && m_RRedirections.Contains(l_RedirectLoc)) {
                // avoid circular redirections
                Trace(tagHttp, levInfo, ("CHttpRequest - GetHTTP - circular redirection %s", l_RedirectLoc.GetBuffer()));		      
                return m_RStatusValue;
            } else m_RRedirections.Add(l_RedirectLoc);
            
            if (!m_FollowRedirections)
                return m_RStatusValue;                
            
            if (m_ClientSocket.GetVerbose()) 
                cout << "\n\t[" << l_RedirectLoc << "]";
            
            ClearResults(false);
            m_Url.SetUrl(l_RedirectLoc);
            bContinueExecuteGet = true;
            
            break;
            
        case 305: /* use proxy */
            
            l_RedirectLoc = m_RFields.FindElement(g_strHttpLocation).GetValue(g_strHttpLocation);
            
            if (! l_RedirectLoc.GetLength())
                break;

            // HTTP 1.1 - Temporary Redirect is 302 and 307
            // m_RRedirections is relevant for final URL address
            // that could be retrieved
            
            ClearResults(false);
            m_Proxy.SetUrl(l_RedirectLoc);

            bContinueExecuteGet = true;

            break;
        };

        Trace(tagHttp, levInfo, ("CHttpRequest - GetHTTP - %d", m_RStatusValue));        

    } while (bContinueExecuteGet);

    return m_RStatusValue;
}