예제 #1
0
파일: url.cpp 프로젝트: arthuraa/quadra
void Url::getFull(char* buf) const {
	buf[0]=0;
	if(strlen(getScheme())) {
		strcat(buf, getScheme());
		strcat(buf, "://");
	}
	strcat(buf, getHost());
	if(getPort()) {
		char n[16];
		sprintf(n, ":%i", getPort());
		strcat(buf, n);
	}
	strcat(buf, getPath());
}
예제 #2
0
void SBWorkspace::getSchemes(const StringSet& schemeNames, SchemeVec& ret) const {
    for (auto schemeName : schemeNames) {
        const XCScheme* scheme = getScheme(schemeName);
        if (scheme)
            ret.push_back(scheme);
    }
}
예제 #3
0
void URL_Resolver::parseBase(string base){
	getScheme(base);
	if(schemeIsWeb){
		getNET_LOC(base);
	}
	parsePath(base);
    StringUtil::ToLower(SCHEME);
    StringUtil::ToLower(NET_LOC);

}
void TrackerFiltersList::addItem(const QString &tracker, const QString &hash)
{
    QStringList tmp;
    QListWidgetItem *trackerItem = nullptr;
    QString host = getHost(tracker);
    bool exists = m_trackers.contains(host);

    if (exists) {
        tmp = m_trackers.value(host);
        if (tmp.contains(hash))
            return;

        if (host != "") {
            trackerItem = item(rowFromTracker(host));
        }
        else {
            trackerItem = item(1);
        }
    }
    else {
        trackerItem = new QListWidgetItem();
        trackerItem->setData(Qt::DecorationRole, GuiIconProvider::instance()->getIcon("network-server"));

        const QString scheme = getScheme(tracker);
        downloadFavicon(QString("%1://%2/favicon.ico").arg((scheme.startsWith("http") ? scheme : "http"), host));
    }
    if (!trackerItem) return;

    tmp.append(hash);
    m_trackers.insert(host, tmp);
    if (host == "") {
        trackerItem->setText(tr("Trackerless (%1)").arg(tmp.size()));
        if (currentRow() == 1)
            applyFilter(1);
        return;
    }

    trackerItem->setText(QString("%1 (%2)").arg(host).arg(tmp.size()));
    if (exists) {
        if (currentRow() == rowFromTracker(host))
            applyFilter(currentRow());
        return;
    }

    Q_ASSERT(count() >= 4);
    int insPos = count();
    for (int i = 4; i < count(); ++i) {
        if (Utils::String::naturalLessThan<Qt::CaseSensitive>(host, item(i)->text())) {
            insPos = i;
            break;
        }
    }
    QListWidget::insertItem(insPos, trackerItem);
    updateGeometry();
}
void TrackerFiltersList::setDownloadTrackerFavicon(bool value)
{
    if (value == m_downloadTrackerFavicon) return;
    m_downloadTrackerFavicon = value;

    if (m_downloadTrackerFavicon) {
        for (auto i = m_trackers.cbegin(); i != m_trackers.cend(); ++i) {
            const QString &tracker = i.key();
            if (!tracker.isEmpty()) {
                const QString scheme = getScheme(tracker);
                downloadFavicon(QString("%1://%2/favicon.ico")
                                .arg((scheme.startsWith("http") ? scheme : "http"), getHost(tracker)));
             }
        }
    }
}
예제 #6
0
std::string AuthScope::toString() const
{
    std::stringstream ss;

    ss << "Scheme: " << (_hasScheme ? getScheme() : "Any");
    ss << " Host: " << (_hasHost ? getHost() : "Any");
    ss << " Port: ";
    if (_hasPort)
    {
        ss << getPort();
    }
    else
    {
        ss << "Any";
    }

    ss << " Realm: " << (_hasRealm ? getRealm() : "Any");
    ss << " AuthType: ";

    if (_hasAuthType)
    {
        switch (getAuthType())
        {
            case BASIC:
                ss << "BASIC";
                break;
            case DIGEST:
                ss << "DIGEST";
                break;
            case NONE:
                ss << "NONE";
                break;
            default:
                ss << "UNKNOWN";
        }
    }
    else
    {
        ss << "Any";
    }
    
    return ss.str();
}
예제 #7
0
/***********************************************************************
 * Factory routine -- connect to server and create remote device
 **********************************************************************/
static SoapySDR::Device *makeRemote(const SoapySDR::Kwargs &args)
{
    if (args.count(SOAPY_REMOTE_KWARG_STOP) != 0) //probably wont happen
    {
        throw std::runtime_error("SoapyRemoteDevice() -- factory loop");
    }

    if (args.count("remote") == 0)
    {
        throw std::runtime_error("SoapyRemoteDevice() -- missing URL");
    }

    auto url = SoapyURL(args.at("remote"));

    //default url parameters when not specified
    if (url.getScheme().empty()) url.setScheme("tcp");
    if (url.getService().empty()) url.setService(SOAPY_REMOTE_DEFAULT_SERVICE);

    return new SoapyRemoteDevice(url.toString(), translateArgs(args));
}
예제 #8
0
Configuration* Configuration::getScheme(const std::string& iTag, const Data& iData) {
   Options opt = getOptions(iTag);
   return getScheme(opt, iData);
}
예제 #9
0
bool URL::isLocalFile() const
{
    return (getScheme() == "file");
}
예제 #10
0
/***********************************************************************
 * Discovery routine -- connect to server when key specified
 **********************************************************************/
static std::vector<SoapySDR::Kwargs> findRemote(const SoapySDR::Kwargs &args)
{
    std::vector<SoapySDR::Kwargs> result;

    if (args.count(SOAPY_REMOTE_KWARG_STOP) != 0) return result;

    //no remote specified, use the discovery protocol
    if (args.count("remote") == 0)
    {
        //On non-windows platforms the endpoint instance can last the
        //duration of the process because it can be cleaned up safely.
        //Windows has issues cleaning up threads and sockets on exit.
        #ifndef _MSC_VER
        static
        #endif //_MSC_VER
        auto ssdpEndpoint = SoapySSDPEndpoint::getInstance();

        //enable forces new search queries
        ssdpEndpoint->enablePeriodicSearch(true);

        //wait maximum timeout for replies
        std::this_thread::sleep_for(std::chrono::microseconds(SOAPY_REMOTE_SOCKET_TIMEOUT_US));

        for (const auto &url : SoapySSDPEndpoint::getInstance()->getServerURLs())
        {
            auto argsWithURL = args;
            argsWithURL["remote"] = url;
            const auto subResult = findRemote(argsWithURL);
            result.insert(result.end(), subResult.begin(), subResult.end());
        }

        return result;
    }

    //otherwise connect to a specific url and enumerate
    auto url = SoapyURL(args.at("remote"));

    //default url parameters when not specified
    if (url.getScheme().empty()) url.setScheme("tcp");
    if (url.getService().empty()) url.setService(SOAPY_REMOTE_DEFAULT_SERVICE);

    //try to connect to the remote server
    SoapySocketSession sess;
    SoapyRPCSocket s;
    int ret = s.connect(url.toString());
    if (ret != 0)
    {
        SoapySDR::logf(SOAPY_SDR_ERROR, "SoapyRemote::find() -- connect(%s) FAIL: %s", url.toString().c_str(), s.lastErrorMsg());
        return result;
    }

    //find transaction
    try
    {
        SoapyLogAcceptor logAcceptor(url.toString(), s);

        SoapyRPCPacker packer(s);
        packer & SOAPY_REMOTE_FIND;
        packer & translateArgs(args);
        packer();
        SoapyRPCUnpacker unpacker(s);
        unpacker & result;

        //graceful disconnect
        SoapyRPCPacker packerHangup(s);
        packerHangup & SOAPY_REMOTE_HANGUP;
        packerHangup();
        SoapyRPCUnpacker unpackerHangup(s);
    }
    catch (const std::exception &ex)
    {
        SoapySDR::logf(SOAPY_SDR_ERROR, "SoapyRemote::find() -- transact FAIL: %s", ex.what());
    }

    //remove instances of the stop key from the result
    for (auto &resultArgs : result)
    {
        resultArgs.erase(SOAPY_REMOTE_KWARG_STOP);
        if (resultArgs.count("driver") != 0)
        {
            resultArgs["remote:driver"] = resultArgs.at("driver");
            resultArgs.erase("driver");
        }
        if (resultArgs.count("type") != 0)
        {
            resultArgs["remote:type"] = resultArgs.at("type");
            resultArgs.erase("type");
        }
        resultArgs["remote"] = url.toString();
    }

    return result;
}
예제 #11
0
    static
    std::shared_ptr<Document> create(const std::string& url,
                                     const std::string& jailRoot,
                                     const std::string& childId)
    {
        // TODO: Sanitize the url and limit access!
        auto uriPublic = Poco::URI(url);
        uriPublic.normalize();

        const auto publicFilePath = uriPublic.getPath();

        if (publicFilePath.empty())
            throw std::runtime_error("Invalid URL.");

        // This lock could become a bottleneck.
        // In that case, we can use a pool and index by publicPath.
        std::unique_lock<std::mutex> lock(DocumentsMutex);

        // Find the document if already open.
        auto it = UriToDocumentMap.lower_bound(publicFilePath);
        if (it != UriToDocumentMap.end() && it->first == publicFilePath)
        {
            Log::info("Document [" + it->first + "] found.");
            return it->second;
        }

        // The URL is the publicly visible one, not visible in the chroot jail.
        // We need to map it to a jailed path and copy the file there.
        auto uriJailed = uriPublic;
        if (uriPublic.isRelative() || uriPublic.getScheme() == "file")
        {
            // chroot/jailId/user/doc
            const auto jailedDocRoot = Poco::Path(jailRoot, JailedDocumentRoot);

            // chroot/jailId/user/doc/childId
            const auto docPath = Poco::Path(jailedDocRoot, childId);
            Poco::File(docPath).createDirectories();

            const auto filename = Poco::Path(uriPublic.getPath()).getFileName();

            // chroot/jailId/user/doc/childId/file.ext
            const auto jailedFilePath = Poco::Path(docPath, filename).toString();

            const auto localPath = Poco::Path(JailedDocumentRoot, childId);
            uriJailed = Poco::URI(Poco::URI("file://"), Poco::Path(localPath, filename).toString());

            Log::info("Public URI [" + uriPublic.toString() +
                      "] jailed to [" + uriJailed.toString() + "].");

#ifdef __linux
            Log::info("Linking " + publicFilePath + " to " + jailedFilePath);
            if (!Poco::File(jailedFilePath).exists() && link(publicFilePath.c_str(), jailedFilePath.c_str()) == -1)
            {
                // Failed
                Log::error("link(\"" + publicFilePath + "\", \"" + jailedFilePath + "\") failed.");
            }
#endif

            try
            {
                // Fallback to copying.
                if (!Poco::File(jailedFilePath).exists())
                {
                    Log::info("Copying " + publicFilePath + " to " + jailedFilePath);
                    Poco::File(publicFilePath).copyTo(jailedFilePath);
                }
            }
            catch (const Poco::Exception& exc)
            {
                Log::error("copyTo(\"" + publicFilePath + "\", \"" + jailedFilePath + "\") failed: " + exc.displayText());
                throw;
            }
        }
        else
        {
            Log::info("Public URI [" + uriPublic.toString() +
                      "] is not a file.");
        }

        auto document = std::shared_ptr<Document>(new Document(uriPublic, uriJailed, childId));

        Log::info("Document [" + publicFilePath + "] created.");
        it = UriToDocumentMap.emplace_hint(it, publicFilePath, document);
        return it->second;
    }