#include "target.h"
#include "protocol.h"
namespace Security {
namespace Network {
HostTarget HostTarget::defaultPort(IPPort defPort) const
{
return HostTarget(scheme(), host(), port(defPort), username(), password());
}
string HostTarget::urlForm() const
{
char portPart[10];
if (mPort)
sprintf(portPart, ":%d", mPort);
else
portPart[0] = '\0';
char buffer[1024];
if (haveUserPass()) {
snprintf(buffer, sizeof(buffer), "%s://%s:%s@%s%s",
scheme(), mUser.c_str(), mPassword.c_str(),
mHost.name().c_str(), portPart);
} else {
snprintf(buffer, sizeof(buffer), "%s://%s%s",
scheme(), mHost.name().c_str(), portPart);
}
return buffer;
}
string Target::urlForm() const
{
return host.urlForm() + path;
}
bool HostTarget::operator == (const HostTarget &other) const
{
return mScheme == other.mScheme
&& mHost == other.mHost
&& mPort == other.mPort
&& mUser == other.mUser
&& mPassword == other.mPassword;
}
bool HostTarget::operator < (const HostTarget &other) const
{
if (mScheme != other.mScheme)
return mScheme < other.mScheme;
if (mHost != other.mHost)
return mHost < other.mHost;
if (mPort != other.mPort)
return mPort < other.mPort;
if (mUser != other.mUser)
return mUser < other.mUser;
return mPassword < other.mPassword;
}
bool HostTarget::operator <= (const HostTarget &other) const
{
return mHost <= other.mHost
&& mScheme == other.mScheme
&& mPort == other.mPort
&& mUser == other.mUser
&& mPassword == other.mPassword;
}
bool Target::operator == (const Target &other) const
{
return host == other.host && path == other.path;
}
bool Target::operator <= (const Target &other) const
{
return host <= other.host && path == other.path;
}
} }