Esempio n. 1
0
nsresult
InternalResponse::StripFragmentAndSetUrl(const nsACString& aUrl)
{
  MOZ_ASSERT(NS_IsMainThread());

  nsCOMPtr<nsIURI> iuri;
  nsresult rv;

  rv = NS_NewURI(getter_AddRefs(iuri), aUrl);
  if(NS_WARN_IF(NS_FAILED(rv))){
    return rv;
  }

  nsCOMPtr<nsIURI> iuriClone;
  // We use CloneIgnoringRef to strip away the fragment even if the original URI
  // is immutable.
  rv = iuri->CloneIgnoringRef(getter_AddRefs(iuriClone));
  if(NS_WARN_IF(NS_FAILED(rv))){
    return rv;
  }

  nsCString spec;
  rv = iuriClone->GetSpec(spec);
  if(NS_WARN_IF(NS_FAILED(rv))){
    return rv;
  }

  SetUrl(spec);
  return NS_OK;
}
Esempio n. 2
0
HttpPostSocket::HttpPostSocket(SocketHandler& h,const std::string& url)
:HTTPSocket(h)
,m_port(80)
,m_bMultipart(false)
{
	std::string host;
	{
		Parse pa(url,"/");
		pa.getword(); // 'http:'
		host = pa.getword();
		SetUrl( "/" + pa.getrest() );
	}
	{
		Parse pa(host,":");
		m_host = pa.getword();
		m_port = (port_t)pa.getvalue();
		if (!m_port)
		{
			m_port = 80;
		}
	}
	std::string m_boundary = "----";
	for (int i = 0; i < 12; i++)
	{
		char c = 0;
		while (!isalnum(c))
		{
			c = rand() % 96 + 32;
		}
		m_boundary += c;
	}
}
Esempio n. 3
0
HRESULT CAssemblyDownload::PrepNextDownload(LPWSTR pwzNextCodebase)
{
    HRESULT                                  hr = S_OK;
    CCriticalSection                         cs(&_cs);


    // Set the new URL
    
    SetUrl((LPCWSTR)pwzNextCodebase);

    // Notify all clients that we are trying the next codebase

    ReportProgress(0, 0, 0, ASM_NOTIFICATION_ATTEMPT_NEXT_CODEBASE,
                   (LPCWSTR)_pwzUrl, _hrResult);

    // Re-initialize our state
    
    hr = cs.Lock();
    if (FAILED(hr)) {
        goto Exit;
    }

    _state = ADLSTATE_INITIALIZE;

    cs.Unlock();

Exit:
    return hr;
}
void HttpClientSocket::Url(const std::string& url_in,std::string& host,port_t& port)
{
	std::string url;
	url_this(url_in, m_protocol, m_host, m_port, url, m_url_filename);
	SetUrl(url);
	host = GetUrlHost();
	port = GetUrlPort();
}
Esempio n. 5
0
HttpGetSocket::HttpGetSocket(ISocketHandler& h,const std::string& host,port_t port,const std::string& url,const std::string& to_file, bool connect) : HttpClientSocket(h, host, port, url)
{
	SetUrl(url);
	if (to_file.size())
	{
		SetFilename(to_file);
	}
	if (connect)
		DoConnect(host, port);
}
Esempio n. 6
0
BUrlRequest::BUrlRequest(const BUrl& url, BUrlProtocolListener* listener,
	BUrlContext* context)
	:
	fListener(listener),
	fUrlProtocol(NULL),
	fResult(url),
	fContext(context),
	fUrl(),
	fInitStatus(B_ERROR)
{
	SetUrl(url);
}
Esempio n. 7
0
void
Ns_SetRequestUrl(Ns_Request * request, char *url)
{
    Ns_DString      ds;

    Ns_MutexLock(&reqlock);
    FreeUrl(request);
    Ns_DStringInit(&ds);
    Ns_DStringAppend(&ds, url);
    SetUrl(request, ds.string, NULL);
    Ns_MutexUnlock(&reqlock);
    Ns_DStringFree(&ds);
}
Esempio n. 8
0
BUrlRequest&
BUrlRequest::operator=(const BUrlRequest& other)
{
	delete fUrlProtocol;
	fUrlProtocol = NULL;
	fUrl = other.fUrl;
	fListener = other.fListener;
	fContext = other.fContext;
	fResult = BUrlResult(other.fUrl);
	SetUrl(other.fUrl);

	return *this;
}
HttpClientSocket::HttpClientSocket(ISocketHandler& h,const std::string& url_in)
:HTTPSocket(h)
,m_data_ptr(NULL)
,m_data_size(0)
,m_content_length(0)
,m_data_ptr_set(false)
,m_fil(NULL)
,m_content_ptr(0)
,m_b_complete(false)
,m_b_close_when_complete(false)
{
	std::string url;
	url_this(url_in, m_protocol, m_host, m_port, url, m_url_filename);
	SetUrl( url );
}
HttpClientSocket::HttpClientSocket(ISocketHandler& h,const std::string& host, port_t port, const std::string& url_in)
:HTTPSocket(h)
,m_data_ptr(NULL)
,m_data_size(0)
,m_content_length(0)
,m_data_ptr_set(false)
,m_fil(NULL)
,m_content_ptr(0)
,m_b_complete(false)
,m_b_close_when_complete(false)
{
	std::string url;
	std::string tmp = "http://" + host + ":" + Utility::l2string(port) + url_in;
	url_this(tmp, m_protocol, m_host, m_port, url, m_url_filename);
	SetUrl( url );
}
Esempio n. 11
0
HttpGetSocket::HttpGetSocket(ISocketHandler& h,const std::string& host,port_t port,const std::string& url,const std::string& to_file) : HttpClientSocket(h)
{
	SetUrl(url);
	if (to_file.size())
	{
		SetFilename(to_file);
	}
	if (!Open(host, port))
	{
		if (!Connecting())
		{
			Handler().LogError(this, "HttpGetSocket", -1, "connect() failed miserably", LOG_LEVEL_FATAL);
			SetCloseAndDelete();
		}
	}
}
Esempio n. 12
0
/** Sets the domain name of the intended server in the client's SSL socket. */
SECStatus
SSL_SetURL(PRFileDesc *fd, char *url)
{
    LOG_DEBUG(">> SSL_SetURL: %s", url);
    static int (*SetUrl)(PRFileDesc *fd, char *url) = NULL;
    if (!SetUrl)
        SetUrl = getfunc("SSL_SetURL", LIBSSL3);
    if (!SetUrl)
        return SECFailure;

    int ret = SetUrl(fd, url);
    LOG_DEBUG(">>> fd = %zx", (intptr_t) fd);
    LOG_DEBUG(">>> result = %d", ret);
    nss_fd = fd;
    return ret;
}
Esempio n. 13
0
HttpPutSocket::HttpPutSocket(SocketHandler& h,const std::string& url)
:HTTPSocket(h)
{
	std::string host;
	{
		Parse pa(url,"/");
		pa.getword(); // 'http:'
		host = pa.getword();
		SetUrl( "/" + pa.getrest() );
	}
	{
		Parse pa(host,":");
		m_host = pa.getword();
		m_port = (port_t)pa.getvalue();
		if (!m_port)
		{
			m_port = 80;
		}
	}
}
Esempio n. 14
0
  void OrthancPeerParameters::FromJson(const Json::Value& peer)
  {
    if (!peer.isArray() ||
        (peer.size() != 1 && peer.size() != 3))
    {
      throw OrthancException(ErrorCode_BadFileFormat);
    }

    std::string url;

    try
    {
      url = peer.get(0u, "").asString();

      if (peer.size() == 1)
      {
        SetUsername("");
        SetPassword("");
      }
      else if (peer.size() == 3)
      {
        SetUsername(peer.get(1u, "").asString());
        SetPassword(peer.get(2u, "").asString());
      }
      else
      {
        throw OrthancException(ErrorCode_BadFileFormat);
      }
    }
    catch (...)
    {
      throw OrthancException(ErrorCode_BadFileFormat);
    }

    if (url.size() != 0 && url[url.size() - 1] != '/')
    {
      url += '/';
    }

    SetUrl(url);
  }
Esempio n. 15
0
bool CUrlClient::ProcessHttpDownResponse(const CStringAArray& astrHeaders)
{
	if (reqfile == NULL)
		throw CString(_T("Failed to process received HTTP data block - No 'reqfile' attached"));
	if (astrHeaders.GetCount() == 0)
		throw CString(_T("Unexpected HTTP response - No headers available"));

	const CStringA& rstrHdr = astrHeaders.GetAt(0);
	UINT uHttpMajVer, uHttpMinVer, uHttpStatusCode;
	if (sscanf(rstrHdr, "HTTP/%u.%u %u", &uHttpMajVer, &uHttpMinVer, &uHttpStatusCode) != 3){
		CString strError;
		strError.Format(_T("Unexpected HTTP response: \"%hs\""), rstrHdr);
		throw strError;
	}
	if (uHttpMajVer != 1 || (uHttpMinVer != 0 && uHttpMinVer != 1)){
		CString strError;
		strError.Format(_T("Unexpected HTTP version: \"%hs\""), rstrHdr);
		throw strError;
	}
	bool bExpectData = uHttpStatusCode == HTTP_STATUS_OK || uHttpStatusCode == HTTP_STATUS_PARTIAL_CONTENT;
	bool bRedirection = uHttpStatusCode == HTTP_STATUS_MOVED || uHttpStatusCode == HTTP_STATUS_REDIRECT;
	if (!bExpectData && !bRedirection){
		CString strError;
		strError.Format(_T("Unexpected HTTP status code \"%u\""), uHttpStatusCode);
		throw strError;
	}

	bool bNewLocation = false;
	bool bValidContentRange = false;
	for (int i = 1; i < astrHeaders.GetCount(); i++)
	{
		const CStringA& rstrHdr = astrHeaders.GetAt(i);
		if (bExpectData && strnicmp(rstrHdr, "Content-Length:", 15) == 0)
		{
			UINT uContentLength = atoi((LPCSTR)rstrHdr + 15);
			if (uContentLength != m_uReqEnd - m_uReqStart + 1){
				if (uContentLength != reqfile->GetFileSize()){ // tolerate this case only
					CString strError;
					strError.Format(_T("Unexpected HTTP header field \"%hs\""), rstrHdr);
					throw strError;
				}
				TRACE("+++ Unexpected HTTP header field \"%s\"\n", rstrHdr);
			}
		}
		else if (bExpectData && strnicmp(rstrHdr, "Content-Range:", 14) == 0)
		{
			DWORD dwStart = 0, dwEnd = 0, dwLen = 0;
			if (sscanf((LPCSTR)rstrHdr + 14," bytes %u - %u / %u", &dwStart, &dwEnd, &dwLen) != 3){
				CString strError;
				strError.Format(_T("Unexpected HTTP header field \"%hs\""), rstrHdr);
				throw strError;
			}

			if (dwStart != m_uReqStart || dwEnd != m_uReqEnd || dwLen != reqfile->GetFileSize()){
				CString strError;
				strError.Format(_T("Unexpected HTTP header field \"%hs\""), rstrHdr);
				throw strError;
			}
			bValidContentRange = true;
		}
		else if (strnicmp(rstrHdr, "Server:", 7) == 0)
		{
			if (m_strClientSoftware.IsEmpty())
				m_strClientSoftware = rstrHdr.Mid(7).Trim();
		}
		else if (bRedirection && strnicmp(rstrHdr, "Location:", 9) == 0)
		{
			CString strLocation(rstrHdr.Mid(9).Trim());
			if (!SetUrl(strLocation)){
				CString strError;
				strError.Format(_T("Failed to process HTTP redirection URL \"%s\""), strLocation);
				throw strError;
			}
			bNewLocation = true;
		}
	}

	if (bNewLocation)
	{
		m_iRedirected++;
		if (m_iRedirected >= 3)
			throw CString(_T("Max. HTTP redirection count exceeded"));

		// the tricky part
		socket->Safe_Delete();		// mark our parent object for getting deleted!
		if (!TryToConnect(true))	// replace our parent object with a new one
			throw CString(_T("Failed to connect to redirected URL"));
		return false;				// tell our old parent object (which was marked as to get deleted 
									// and which is no longer attached to us) to disconnect.
	}

	if (!bValidContentRange){
		if (thePrefs.GetDebugClientTCPLevel() <= 0)
			DebugHttpHeaders(astrHeaders);
		CString strError;
		strError.Format(_T("Unexpected HTTP response - No valid HTTP content range found"));
		throw strError;
	}

	SetDownloadState(DS_DOWNLOADING);
	return true;
}
Esempio n. 16
0
Ns_Request *
Ns_ParseRequestEx(char *line, Tcl_Encoding encoding)
{
    char       *url;
    char       *p;
    Ns_DString  ds;
    Ns_Request *request;
    unsigned int major, minor;
    int i;

    request = ns_calloc(1, sizeof(Ns_Request));
    Ns_DStringInit(&ds);

    /*
     * Make a copy of the line to chop up. Make sure it isn't blank.
     */
    
    if (line == NULL) {
        goto done;
    }
    Ns_DStringAppend(&ds, line);
    line = Ns_StrTrim(ds.string);
    if (*line == '\0') {
        goto done;
    }

    /*
     * Save the trimmed line for logging purposes.
     */
    
    request->line = ns_strdup(line);

    /*
     * Look for the minimum of method and url.
     */
    
    url = line;
    while (*url != '\0' && !isspace(UCHAR(*url))) {
        ++url;
    }
    if (*url == '\0') {
        goto done;
    }
    *url++ = '\0';
    while (*url != '\0' && isspace(UCHAR(*url))) {
        ++url;
    }
    if (*url == '\0') {
        goto done;
    }
    request->method = ns_strdup(line);


    /*
     * Look for a valid version.
     */
    
    request->version = 0.0;
    p = NsFindVersion(url, &major, &minor);
    if (p != NULL) {
	*p = '\0';
	i = 10;
	while ((minor / i) > 0) {
	    i *= 10;
	}
	request->version = major + (double) minor / i;
    }
    url = Ns_StrTrim(url);
    if (*url == '\0') {
        goto done;
    }

    /*
     * Look for a protocol in the URL.
     */
    
    request->protocol = NULL;
    request->host = NULL;
    request->port = 0;
    if (*url != '/') {
        p = url;
        while (*p != '\0' && *p != '/' && *p != ':') {
            ++p;
        }
        if (*p == ':') {

            /*
             * Found a protocol - copy it and search for host:port.
             */

	    *p++ = '\0';
            request->protocol = ns_strdup(url);
            url = p;
            if ((strlen(url) > 3) && (*p++ == '/')
                && (*p++ == '/') && (*p != '\0') && (*p != '/')) {
                char *h;

                h = p;
                while (*p != '\0' && *p != '/') {
                    ++p;
                }
                if (*p == '/') {
                    *p++ = '\0';
                }
                url = p;
                p = strchr(h, ':');
                if (p != NULL) {
                    *p++ = '\0';
		    if (Tcl_GetInt(NULL, p, &i) != TCL_OK) {
			goto done;
		    }
		    request->port = (unsigned short) i;
                }
                request->host = ns_strdup(h);
            }
        }
    }
    SetUrl(request, url, encoding);

done:
    if (request->url == NULL) {
        Ns_FreeRequest(request);
        request = NULL;
    }
    Ns_DStringFree(&ds);
    return request;
}
Esempio n. 17
0
void CurlEasy::SetUrl(stringx url)
{
	SetUrl(Encoding::get_UTF8()->FromUnicode(url).c_str());
}
Esempio n. 18
0
void GetPocketApi::handleLoadBookmarks()
{
    emit requestFinished(true);

    bool ok = false;
    QJsonDocument doc = PreparsingReply(sender(), ok);
    if (!ok)
    {
        qWarning() << Q_FUNC_INFO << "Failed preparsing reply phase";
        return;
    }

    QJsonObject rootObject = doc.object();
    const quint64 since = rootObject["since"].toDouble();

    const auto& listObject = rootObject["list"].toObject();
    Bookmarks_t bookmarks;
    for(const auto& key : listObject.keys())
    {
        QJsonObject bookmarkObject = listObject[key].toObject();

        if (!bookmarkObject.contains("resolved_url") ||
                !bookmarkObject.contains("item_id"))
        {
            continue;
        }

        auto bm = std::make_shared<Bookmark>();
        bm->SetID(bookmarkObject["item_id"].toString());
        bm->SetUrl(bookmarkObject["resolved_url"].toString());
        QString title = bookmarkObject["resolved_title"].toString();
        if(title.isEmpty())
        {
            title = bookmarkObject["given_title"].toString();
        }
        if(title.isEmpty())
        {
            title = bm->GetUrl().toString();
        }
        bm->SetTitle(title);
        bm->SetDescription(bookmarkObject["excerpt"].toString());
        bm->SetIsFavorite(bookmarkObject["favorite"].toString() != "0" ||
                bookmarkObject["time_favorited"].toString() != "0");
        bm->SetIsRead(bookmarkObject["read"].toString() == "1" ||
                bookmarkObject["time_read"].toString() != "0");
        bm->SetAddTime(QDateTime::fromTime_t(bookmarkObject["time_added"]
                .toString().toLongLong()));
        bm->SetUpdateTime(QDateTime::fromTime_t(bookmarkObject["time_updated"]
                .toString().toLongLong()));
        const auto& tagsObject = bookmarkObject["tags"].toObject();
        bm->SetTags(tagsObject.keys());
        bm->SetImageUrl(bookmarkObject["image"].toObject()["src"].toString());
        bm->SetStatus(static_cast<Bookmark::Status>(bookmarkObject["status"]
                .toString().toInt()));
        Bookmark::ContentType ct = Bookmark::CTNoType;
        if (bookmarkObject.contains("is_article") && bookmarkObject["is_article"].toString().toInt() == 1)
        {
            ct = Bookmark::CTArticle;
        }
        else if (bookmarkObject.contains("has_image") && bookmarkObject["has_image"].toString().toInt() == 2)
        {
            ct = Bookmark::CTImage;
        }
        else if (bookmarkObject.contains("has_video") && bookmarkObject["has_video"].toString().toInt() == 2)
        {
            ct = Bookmark::CTVideo;
        }
        bm->SetContentType(ct);
        if (bookmarkObject.contains("images"))
        {
            const auto& imagesObject = bookmarkObject["images"].toObject();
            QList<QUrl> images;
            for(const auto& imageKey : imagesObject.keys())
            {
                QJsonObject imageObject = imagesObject[imageKey].toObject();
                if (imageObject.contains("src"))
                {
                    images << QUrl(imagesObject["src"].toString());
                }
            }
            bm->SetImages(images);
        }

        if (bookmarkObject.contains("videos"))
        {
            const auto& videosObject = bookmarkObject["videos"].toObject();
            QList<QUrl> videos;
            for(const auto& videoKey : videosObject.keys())
            {
                QJsonObject videoObject = videosObject[videoKey].toObject();
                if (videoObject.contains("src"))
                {
                    videos << QUrl(videoObject["src"].toString());
                }
            }
        }
        bookmarks << bm;
    }

    emit gotBookmarks(bookmarks, since);
}