Exemplo n.º 1
0
void HttpSprite::onHttpResponseGetSprite(network::HttpClient* client, network::HttpResponse* response)
{
	if (response && response->isSucceed())
	{
		network::HttpRequest *pRequest = response->getHttpRequest();
		if (pRequest)
		{
			std::string strUrl(pRequest->getUrl());


			if (strUrl == m_strSourceUrl_requst)
			//if (strUrl == m_strSourceUrl)
			{
				std::vector<char> *pVecResponseData = response->getResponseData();
				if (pVecResponseData && !pVecResponseData->empty())
				{
					FILE *file = fopen(m_strLocalFullPath.c_str(), "wb");
					if (file)
					{
						std::vector<char>& vecResponseData = *pVecResponseData;
						fwrite(&vecResponseData[0], sizeof(char), vecResponseData.size(), file);
						fclose(file);
						NotifyScheduleCheckDownload();
					}
				}
			}
		}		
	}
	//response->release();
}
Exemplo n.º 2
0
CString Utils::ReadWebPage(const std::vector<CString>& webPages)
{
	CString        strAllPages;
	CAmHttpSocket  httpSocket;
	CStdioFile     file;
	CFileException e;

	for (int i=0; i<webPages.size(); i++)
	{
		CString strUrl(webPages[i]);

		CString strProtocol(strUrl.Left(4));
		strProtocol.MakeLower();

		if (strProtocol == "http")
		{
			CString strPage(httpSocket.GetPage(strUrl));
			strAllPages += strPage;
		}
		else if (file.Open(strUrl, CFile::modeRead, &e))
		{
			CString strLine;
			while (file.ReadString(strLine))
			{
				strAllPages += strLine;
			}
		}
	}

	return strAllPages;
}
Exemplo n.º 3
0
void CTransChatWebWnd::ExecuteJavascript(const std::wstring& strCode)
{
	if (m_cWebClient.get())
	{
		CefRefPtr<CefFrame> frame = m_cWebClient->GetBrowser()->GetMainFrame();
		if (frame.get())
		{
			CefString strCode(strCode.c_str()), strUrl(L"");
			frame->ExecuteJavaScript(strCode, strUrl, 0);
		}
	}
}
Exemplo n.º 4
0
void sendHttpReq(HttpRequest* request, Params params /*= nullptr*/, size_t size /*=0*/, bool checkNetwork /*= false*/)
{
    if (!request) {
        return;
    }
    HttpCallback* httpCallback = _httpMap[request->getTag()];
    if (!httpCallback) {
        return;         //because the req has been sent before and httpCallback was released
    }
    if (checkNetwork && !networkReachable()) {
        TempVar* strings = VARIABLES_LOCAL("strings.json");
        showAlert(strings->getString("dialog_title_tip").c_str(), strings->getString("network_unreachable").c_str(), NULL, strings->getString("dialog_btn_ok").c_str(), nullptr);
        return;
    }
    if(params!=NULL&&size != 0){
        std::string data = formatParams(params, size);
        switch (request->getRequestType()) {
            case HttpRequest::Type::PUT:
            case HttpRequest::Type::POST:
            {
                request->setRequestData(data.c_str(), (unsigned int)data.length());
                break;
            }
            case HttpRequest::Type::DELETE:
            case HttpRequest::Type::GET:
            {
                const char* url = request->getUrl();
                std::string strUrl(url);
                strUrl.append("?");
                strUrl.append(data);
                request->setUrl(strUrl.c_str());
                break;
            }
            default:
                log("unknown request type.");
                break;
        }
    }
    HttpClient::getInstance()->send(request);
    request->release();
    httpCallback->state = Sending;
    /*show dialog*/
    if(httpCallback->dlg)
        httpCallback->dlg->retain();
}
Exemplo n.º 5
0
STDMETHODIMP CMyIENSHandle::Start(
        LPCWSTR szUrl,
        IInternetProtocolSink *pIProtSink,
        IInternetBindInfo *pIBindInfo,
        DWORD grfSTI,
        DWORD dwReserved)
{
	// Should we do the following or always fail? How can we continue if parsing failed?
	try{

	if(pMainFrame->m_bUseUrlFilter && !pMainFrame->m_bUrlFilterDirty)
	{
		CString strUrl(szUrl); void* tmp;
		strUrl.MakeLower();
		BOOL bFilter = FALSE;
		if(mapUrlFilter.Lookup(strUrl, tmp))
			bFilter = TRUE;
		else if(PatternFilter(strUrl))
			bFilter = TRUE;
		if(bFilter)
		{
			if(pIProtSink!=NULL)
			{
				m_pProtSink = pIProtSink;
				m_pProtSink->AddRef();
				m_pProtSink->ReportData(BSCF_FIRSTDATANOTIFICATION || BSCF_LASTDATANOTIFICATION || BSCF_DATAFULLYAVAILABLE, 42, 42);
				m_pProtSink->ReportResult(S_OK, 0, 0);
				m_pProtSink->Release();
				m_pProtSink = NULL;
			}
			return S_OK;
		}
	}

	}catch(...)
	{
	}

	return INET_E_USE_DEFAULT_PROTOCOLHANDLER;
}
Exemplo n.º 6
0
 void onRelationStart(const QXmlAttributes& attrs)
 {
     if (m_bTargetIsUrl)
     {
         QString qstrType (attrs.value("type"));
         if ("AmazonAsin" == qstrType)
         {
             m_albumInfo.m_strAmazonLink = convStr(attrs.value("target"));
         }
         else if ("CoverArtLink" == qstrType)
         {
             string strUrl (convStr(attrs.value("target")));
             if (beginsWith(strUrl, "http://"))
             {
                 m_albumInfo.m_vstrImageNames.push_back(strUrl);
             }
             else
             { //ttt2 perhaps tell the user
                 qDebug("Unsupported image link");
             }
         }
     }
 }
//-----------------------------------------------------------------------------
bool MakeResponse(CommunicationID requestID, Response** ppResponse)
{
    // protect the maps from being changed by other threads using the mutex
    ScopeLock lock(s_mutex);

    PsAssert(ppResponse != NULL);

    // first see if we already have this ID as a streaming response
    ResponseMap::iterator iterResponse = g_streamingResponseMap.find(requestID);

    if (iterResponse != g_streamingResponseMap.end())
    {
        *ppResponse = iterResponse->second;
        return true;
    }

    // otherwise we need to create a new response based on the original request
    // so get the request
    RequestMap::iterator iterRequest = g_requestMap.find(requestID);

    if (iterRequest == g_requestMap.end())
    {
        // the original request couldn't be found, so return failure
        return false;
    }

    // need to create a new response
    if (PsNew(*ppResponse) == false)
    {
        return false;
    }

    HTTPRequestHeader* pRequest = iterRequest->second;
    PsAssert(pRequest != NULL);

    if (pRequest->GetReceivedOverSocket() == true)
    {
        (*ppResponse)->client_socket = pRequest->GetClientSocket();
    }
    else
    {
#if defined (_WIN32)
        (*ppResponse)->client_socket = NetSocket::CreateFromDuplicate(pRequest->GetProtoInfo());
#else
        // create a new socket and connect to the streamSocket on the server
        (*ppResponse)->client_socket = NetSocket::Create();

        if ((*ppResponse)->client_socket != NULL)
        {
            osPortAddress portAddress((unsigned short)pRequest->GetPort());
            (*ppResponse)->client_socket->Connect(portAddress);
        }

#endif
    }

    if ((*ppResponse)->client_socket == NULL)
    {
        int Err = NetSocket::LastError();
        Log(logERROR, "Could not create socket: NetSocket failed with error: %ld\n", Err);
        return false;
    }

    // see if this should be added as a streaming response
    gtASCIIString strUrl(pRequest->GetUrl());
    int32 iStream = strUrl.find(STR_STREAM_TOKEN);

    if (iStream >= 0)
    {
        const char* pBuf = strUrl.asCharArray();
        const char* pRate = &pBuf[ iStream + strlen(STR_STREAM_TOKEN)];
        unsigned int uRate = 0;

        // try to get the rate from the command;
        if (sscanf_s(pRate, "%u", &uRate) < 1)
        {
            // default to max rate
            uRate = COMM_MAX_STREAM_RATE;
        }

        // set the response as streaming with the specified rate
        (*ppResponse)->m_bStreamingEnabled = true;
        (*ppResponse)->m_dwMaxStreamsPerSecond = uRate;
        g_streamingResponseMap[ requestID ] = *ppResponse;
    }
    else
    {
        // streaming requests need to be kept around so that
        // additional responses can be directed to the right place,
        // HOWEVER, non-streaming requests only get a single response
        // and we just created the response for it, so it is safe
        // to remove the request from the requestMap. This will
        // help keep communication quick as the number of incoming
        // requests grows.
        RemoveRequest(requestID);
    }

    return true;
}
Exemplo n.º 8
0
QUrl ArestShopPlugin::createSearchURL(const QString &  strName)
{
	QString strUrl(QString(cstrSearchPrefix).arg(strName.isEmpty()?m_strComponentName:strName));
	return strUrl;
}