hide default port from addresses, fix localhost scheme

This commit is contained in:
Stephen Birarda 2018-04-26 11:38:50 -07:00 committed by Dante Ruiz
parent 8b9d2cdcc8
commit c8d7dc9b91
2 changed files with 15 additions and 10 deletions

View file

@ -329,12 +329,14 @@ bool AddressManager::handleUrl(const QUrl& lookupUrl, LookupTrigger trigger) {
return false;
}
static const QString LOCALHOST = "localhost";
bool isPossiblePlaceName(QString possiblePlaceName) {
bool result { false };
int length = possiblePlaceName.length();
static const int MINIMUM_PLACENAME_LENGTH = 1;
static const int MAXIMUM_PLACENAME_LENGTH = 64;
if (possiblePlaceName.toLower() != "localhost" &&
if (possiblePlaceName.toLower() != LOCALHOST &&
length >= MINIMUM_PLACENAME_LENGTH && length <= MAXIMUM_PLACENAME_LENGTH) {
const QRegExp PLACE_NAME_REGEX = QRegExp("^[0-9A-Za-z](([0-9A-Za-z]|-(?!-))*[^\\W_]$|$)");
result = PLACE_NAME_REGEX.indexIn(possiblePlaceName) == 0;
@ -354,7 +356,7 @@ void AddressManager::handleLookupString(const QString& lookupString, bool fromSu
sanitizedString = sanitizedString.remove(HIFI_SCHEME_REGEX);
lookupURL = QUrl(sanitizedString);
if (lookupURL.scheme().isEmpty()) {
if (lookupURL.scheme().isEmpty() || lookupURL.scheme().toLower() == LOCALHOST) {
lookupURL = QUrl("hifi://" + sanitizedString);
}
} else {
@ -603,7 +605,7 @@ bool AddressManager::handleNetworkAddress(const QString& lookupString, LookupTri
if (ipAddressRegex.indexIn(lookupString) != -1) {
QString domainIPString = ipAddressRegex.cap(1);
quint16 domainPort = DEFAULT_DOMAIN_SERVER_PORT;
quint16 domainPort = 0;
if (!ipAddressRegex.cap(2).isEmpty()) {
domainPort = (quint16) ipAddressRegex.cap(2).toInt();
}
@ -625,7 +627,7 @@ bool AddressManager::handleNetworkAddress(const QString& lookupString, LookupTri
if (hostnameRegex.indexIn(lookupString) != -1) {
QString domainHostname = hostnameRegex.cap(1);
quint16 domainPort = DEFAULT_DOMAIN_SERVER_PORT;
quint16 domainPort = 0;
if (!hostnameRegex.cap(2).isEmpty()) {
domainPort = (quint16)hostnameRegex.cap(2).toInt();

View file

@ -166,7 +166,12 @@ void DomainHandler::setURLAndID(QUrl domainURL, QUuid domainID) {
}
}
if (_domainURL != domainURL || _sockAddr.getPort() != domainURL.port()) {
auto domainPort = domainURL.port();
if (domainPort == -1) {
domainPort = DEFAULT_DOMAIN_SERVER_PORT;
}
if (_domainURL != domainURL || _sockAddr.getPort() != domainPort) {
// re-set the domain info so that auth information is reloaded
hardReset();
@ -192,12 +197,10 @@ void DomainHandler::setURLAndID(QUrl domainURL, QUuid domainID) {
emit domainURLChanged(_domainURL);
if (_sockAddr.getPort() != domainURL.port()) {
qCDebug(networking) << "Updated domain port to" << domainURL.port();
if (_sockAddr.getPort() != domainPort) {
qCDebug(networking) << "Updated domain port to" << domainPort;
_sockAddr.setPort(domainPort);
}
// grab the port by reading the string after the colon
_sockAddr.setPort(domainURL.port());
}
}