示例#1
0
// This function will take a resolved URI and create a version of it that is relative to
// another existing URI.  The new URI is stored in the "originalURI"
int daeURI::makeRelativeTo(daeURI* relativeToURI)
{
	// !!!GAC for some reason, relativeToURI is in pending and not success state, why??
	// Can't do this function unless both URIs have already been successfully resolved
	if(getState() != uri_success /*|| relativeToURI->getState() != uri_success*/ )
		return(DAE_ERR_INVALID_CALL);  // !!!GAC Need to assign a real error code to this

	// Can only do this function if both URIs have the same scheme and authority

	if((strcmp(getProtocol(), relativeToURI->getProtocol()) != 0) || (strcmp(getAuthority(), relativeToURI->getAuthority()) != 0))
		return(DAE_ERR_INVALID_CALL);  // !!!GAC Need to assign a real error code to this
	
	// advance till we find a segment that doesn't match

	const char *this_filepath		= getFilepath();
	const char *relativeTo_filepath = relativeToURI->getFilepath();
	const char *this_slash			= this_filepath;
	const char *relativeTo_slash	= relativeTo_filepath;

	while(*this_filepath == *relativeTo_filepath)
	{
		if(*this_filepath == '/')
		{
			this_slash = this_filepath;
			relativeTo_slash = relativeTo_filepath;
		}
		this_filepath++;
		relativeTo_filepath++;
	}

	// Decide how many ../ segments are needed (Filepath should always end in a /)
	int segment_count = 0;
	relativeTo_slash++;
	while(*relativeTo_slash != 0)
	{
		if(*relativeTo_slash == '/')
			segment_count ++;
		relativeTo_slash++;
	}
	this_slash++;
	// Delete old URI string
	safeDelete(originalURIString);
	// Allocate memory for a new "originalURI" and free the old one
	char *newRelativeURI = (char*) daeMemorySystem::malloc("uri",strlen(relativeTo_slash)+ strlen(file)+(segment_count*3)+strlen(getID())+2);
	char *temp = newRelativeURI;
	for(int i = 0; i < segment_count; i++)
	{
		strcpy(temp,"../");
		temp += 3;
	}
	strcpy(temp,this_slash);
	strcat(temp,file);
	if(id!=empty && strlen(getID()) != 0)
	{
		strcat(temp,"#");
		strcat(temp,getID());
	}
	originalURIString = newRelativeURI;
	return(DAE_OK);
}
示例#2
0
bool DnsLayer::removeAuthority(const std::string& authorityNameToRemove, bool exactMatch)
{
	DnsResource* authorityToRemove = getAuthority(authorityNameToRemove, exactMatch);
	if (authorityToRemove == NULL)
	{
		LOG_DEBUG("Authority not found");
		return false;
	}

	return removeAuthority(authorityToRemove);
}
示例#3
0
文件: URI.cpp 项目: 119/vdc
std::string URI::toString() const
{
	std::string uri;
	if (isRelative())
	{
		encode(_path, RESERVED_PATH, uri);
	}
	else
	{
		uri = _scheme;
		uri += ':';
		std::string auth = getAuthority();
		if (!auth.empty() || _scheme == "file")
		{
			uri.append("//");
			uri.append(auth);
		}
		if (!_path.empty())
		{
			if (!auth.empty() && _path[0] != '/')
				uri += '/';
			encode(_path, RESERVED_PATH, uri);
		}
		else if (!_query.empty() || !_fragment.empty())
		{
			uri += '/';
		}
	}
	if (!_query.empty())
	{
		uri += '?';
		uri.append(_query);
	}
	if (!_fragment.empty())
	{
		uri += '#';
		encode(_fragment, RESERVED_FRAGMENT, uri);
	}
	return uri;
}
示例#4
0
void GroupClient::connectionEncrypted()
{
    const auto secret = socket.getSecret();
    emit sendLog(QString("Host's secret: %1").arg(secret.constData()));

    const bool requireAuth = getConfig().groupManager.requireAuth;
    const bool validSecret = getAuthority()->validSecret(secret);
    const bool validCert = getAuthority()->validCertificate(&socket);
    if (requireAuth && !validSecret) {
        emit messageBox(
            QString("Host's secret is not in your contacts:\n%1").arg(secret.constData()));
        stop();
        return;
    }
    if (requireAuth && !validCert) {
        emit messageBox(
            "WARNING: Host's secret has been compromised making the connection insecure.");
        stop();
        return;
    }

    sendLoginInformation();

    if (validCert) {
        // Assume that anyone connecting to a host will trust them (if auth is not required)
        if (!validSecret)
            getAuthority()->add(secret);
        // Update metadata
        getAuthority()->setMetadata(secret,
                                    GroupMetadata::IP_ADDRESS,
                                    socket.getPeerAddress().toString());
        getAuthority()->setMetadata(secret,
                                    GroupMetadata::LAST_LOGIN,
                                    QDateTime::currentDateTime().toString());
        getAuthority()->setMetadata(secret,
                                    GroupMetadata::CERTIFICATE,
                                    socket.getPeerCertificate().toPem());
        getAuthority()->setMetadata(secret,
                                    GroupMetadata::PORT,
                                    QString("%1").arg(socket.getPeerPort()));
    }
}