コード例 #1
0
ファイル: HttpUtility.cpp プロジェクト: cyendra/HTTP-Utility
bool HttpRequest::SetHost(const std::wstring& inputQuery) {
	server = L"";
	query = L"";
	port = 0;
	secure = false;
	
	if (server == L"") {
		if (inputQuery.length()>7) {
			std::wstring protocol = inputQuery.substr(0, 8);
			if (_wcsicmp(protocol.c_str(), L"https://") == 0) {
				const wchar_t* reading = inputQuery.c_str() + 8;
				const wchar_t* index1 = wcschr(reading, L':');
				const wchar_t* index2 = wcschr(reading, L'/');
				if (index2) {
					query = index2;
					server = std::wstring(reading, (index1 ? index1 : index2) - reading);
					port = INTERNET_DEFAULT_HTTPS_PORT;
					secure = true;
					if (index1) {
						std::wstring portString(index1 + 1, index2 - index1 - 1);
						port = _wtoi(portString.c_str());
					}
					return true;
				}
			}
		}
	}
	if (server == L"") {
		if (inputQuery.length()>6) {
			std::wstring protocol = inputQuery.substr(0, 7);
			if (_wcsicmp(protocol.c_str(), L"http://") == 0) {
				const wchar_t* reading = inputQuery.c_str() + 7;
				const wchar_t* index1 = wcschr(reading, L':');
				const wchar_t* index2 = wcschr(reading, L'/');
				if (index2) {
					query = index2;
					server = std::wstring(reading, (index1 ? index1 : index2) - reading);
					port = INTERNET_DEFAULT_HTTP_PORT;
					if (index1) {
						std::wstring portString(index1 + 1, index2 - index1 - 1);
						port = _wtoi(portString.c_str());
					}
					return true;
				}
			}
		}
	}
	
	return false;
}
コード例 #2
0
bool ARTPSession::validateMediaFormat(size_t index, unsigned *port) const {
    AString format;
    mDesc->getFormat(index, &format);

    ssize_t i = format.find(" ");
    if (i < 0) {
        return false;
    }

    ++i;
    size_t j = i;
    while (isdigit(format.c_str()[j])) {
        ++j;
    }
    if (format.c_str()[j] != ' ') {
        return false;
    }

    AString portString(format, i, j - i);

    char *end;
    unsigned long x = strtoul(portString.c_str(), &end, 10);
    if (end == portString.c_str() || *end != '\0') {
        return false;
    }

    if (x == 0 || x > 65535) {
        return false;
    }

    *port = x;

    return true;
}
コード例 #3
0
nsresult
nsCertOverrideService::Read()
{
    nsAutoMonitor lock(monitor);

    nsresult rv;
    nsCOMPtr<nsIInputStream> fileInputStream;
    rv = NS_NewLocalFileInputStream(getter_AddRefs(fileInputStream), mSettingsFile);
    if (NS_FAILED(rv)) {
        return rv;
    }

    nsCOMPtr<nsILineInputStream> lineInputStream = do_QueryInterface(fileInputStream, &rv);
    if (NS_FAILED(rv)) {
        return rv;
    }

    nsCAutoString buffer;
    PRBool isMore = PR_TRUE;
    PRInt32 hostIndex = 0, algoIndex, fingerprintIndex, overrideBitsIndex, dbKeyIndex;

    /* file format is:
     *
     * host:port \t fingerprint-algorithm \t fingerprint \t override-mask \t dbKey
     *
     *   where override-mask is a sequence of characters,
     *     M meaning hostname-Mismatch-override
     *     U meaning Untrusted-override
     *     T meaning Time-error-override (expired/not yet valid)
     *
     * if this format isn't respected we move onto the next line in the file.
     */

    while (isMore && NS_SUCCEEDED(lineInputStream->ReadLine(buffer, &isMore))) {
        if (buffer.IsEmpty() || buffer.First() == '#') {
            continue;
        }

        // this is a cheap, cheesy way of parsing a tab-delimited line into
        // string indexes, which can be lopped off into substrings. just for
        // purposes of obfuscation, it also checks that each token was found.
        // todo: use iterators?
        if ((algoIndex         = buffer.FindChar('\t', hostIndex)         + 1) == 0 ||
                (fingerprintIndex  = buffer.FindChar('\t', algoIndex)         + 1) == 0 ||
                (overrideBitsIndex = buffer.FindChar('\t', fingerprintIndex)  + 1) == 0 ||
                (dbKeyIndex        = buffer.FindChar('\t', overrideBitsIndex) + 1) == 0) {
            continue;
        }

        const nsASingleFragmentCString &tmp = Substring(buffer, hostIndex, algoIndex - hostIndex - 1);
        const nsASingleFragmentCString &algo_string = Substring(buffer, algoIndex, fingerprintIndex - algoIndex - 1);
        const nsASingleFragmentCString &fingerprint = Substring(buffer, fingerprintIndex, overrideBitsIndex - fingerprintIndex - 1);
        const nsASingleFragmentCString &bits_string = Substring(buffer, overrideBitsIndex, dbKeyIndex - overrideBitsIndex - 1);
        const nsASingleFragmentCString &db_key = Substring(buffer, dbKeyIndex, buffer.Length() - dbKeyIndex);

        nsCAutoString host(tmp);
        nsCertOverride::OverrideBits bits;
        nsCertOverride::convertStringToBits(bits_string, bits);

        PRInt32 port;
        PRInt32 portIndex = host.RFindChar(':');
        if (portIndex == kNotFound)
            continue; // Ignore broken entries

        PRInt32 portParseError;
        nsCAutoString portString(Substring(host, portIndex+1));
        port = portString.ToInteger(&portParseError);
        if (portParseError)
            continue; // Ignore broken entries

        host.Truncate(portIndex);

        AddEntryToList(host, port,
                       nsnull, // don't have the cert
                       PR_FALSE, // not temporary
                       algo_string, fingerprint, bits, db_key);
    }

    return NS_OK;
}
コード例 #4
0
ファイル: proxy_config.cpp プロジェクト: toisoftware/TideSDK
SharedProxy ParseProxyEntry(string entry, const string& urlScheme,
                            const string& entryScheme)
{
    // If the hostname came with a scheme:// speicifier, read this,
    // though it has lower precedence than the other two places the
    // scheme can be defined.
    entry = FileUtils::Trim(entry);
    size_t schemeEnd = entry.find("://");
    std::string hostScheme;
    if (schemeEnd != string::npos)
    {
        hostScheme = entry.substr(0, schemeEnd);
        entry = entry.substr(schemeEnd + 3);
    }

    // We need to pull out the credentials before the port, because
    // the port just searches for the first ':', which can be in the
    // credentials section.
    string username, password;
    size_t credentialsEnd = entry.find('@');
    if (credentialsEnd != string::npos && credentialsEnd > 0 && entry.size() > 1)
    {
        username = entry.substr(0, credentialsEnd);
        entry = entry.substr(credentialsEnd + 1);

        size_t usernameEnd = username.find(':');
        if (usernameEnd != string::npos)
        {
            password = username.substr(usernameEnd + 1);
            username = username.substr(0, usernameEnd);
        }
    }

    size_t portStart = entry.find(':');
    unsigned port = 0;
    if (portStart != string::npos && portStart != entry.size())
    {
        std::string portString(entry.substr(portStart + 1));
        entry = entry.substr(0, portStart);
        try
        {
            portString = FileUtils::Trim(portString);
            port = NumberParser::parseUnsigned(portString);
        }
        catch (Poco::SyntaxException& e)
        {
            port = 0;
        }
    }

    std::string scheme;
    if (!entryScheme.empty())
        scheme = entryScheme;
    else if (!hostScheme.empty())
        scheme = hostScheme;
    else
        scheme = urlScheme;

    if (scheme == "direct")
        return 0;

    SharedProxy proxy = new Proxy();
    proxy->type = Proxy::SchemeToProxyType(scheme);
    proxy->host = FileUtils::Trim(entry);
    proxy->port = port;

    if (!username.empty())
        proxy->username = username;
    if (!password.empty())
        proxy->password = password;

    return proxy;
}