mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-10 06:12:53 +02:00
DEV-1836 - handle urls in the form 'hifi://<domain>:<port>
This commit is contained in:
parent
95b219475d
commit
d0cb489247
1 changed files with 26 additions and 21 deletions
|
@ -234,14 +234,33 @@ const JSONCallbackParameters& AddressManager::apiCallbackParameters() {
|
|||
return callbackParams;
|
||||
}
|
||||
|
||||
bool AddressManager::handleUrl(const QUrl& lookupUrl, LookupTrigger trigger) {
|
||||
bool AddressManager::handleUrl(const QUrl& lookupUrlIn, LookupTrigger trigger) {
|
||||
static QString URL_TYPE_USER = "user";
|
||||
static QString URL_TYPE_DOMAIN_ID = "domain_id";
|
||||
static QString URL_TYPE_PLACE = "place";
|
||||
static QString URL_TYPE_NETWORK_ADDRESS = "network_address";
|
||||
if (lookupUrl.scheme() == URL_SCHEME_HIFI) {
|
||||
|
||||
qCDebug(networking) << "Trying to go to URL" << lookupUrl.toString();
|
||||
QUrl lookupUrl = lookupUrlIn;
|
||||
|
||||
qCDebug(networking) << "Trying to go to URL" << lookupUrl.toString();
|
||||
|
||||
if (lookupUrl.scheme().isEmpty() && !lookupUrl.path().startsWith("/")) {
|
||||
// 'urls' without schemes are taken as domain names, as opposed to
|
||||
// simply a path portion of a url, so we need to set the scheme
|
||||
lookupUrl.setScheme(URL_SCHEME_HIFI);
|
||||
}
|
||||
|
||||
// it should be noted that url's in the form
|
||||
// somewhere:<port> are not valid, as that
|
||||
// would indicate that the scheme is 'somewhere'
|
||||
// use hifi://somewhere:<port> instead
|
||||
|
||||
if (lookupUrl.scheme() == URL_SCHEME_HIFI) {
|
||||
if (lookupUrl.host().isEmpty()) {
|
||||
// this was in the form hifi:/somewhere or hifi:somewhere. Fix it by making it hifi://somewhere
|
||||
const QRegExp HIFI_SCHEME_REGEX = QRegExp(URL_SCHEME_HIFI + ":\\/?", Qt::CaseInsensitive);
|
||||
lookupUrl = QUrl(lookupUrl.toString().replace(HIFI_SCHEME_REGEX, URL_SCHEME_HIFI + "://"));
|
||||
}
|
||||
|
||||
DependencyManager::get<NodeList>()->flagTimeForConnectionStep(LimitedNodeList::ConnectionStep::LookupAddress);
|
||||
|
||||
|
@ -379,25 +398,11 @@ bool isPossiblePlaceName(QString possiblePlaceName) {
|
|||
}
|
||||
|
||||
void AddressManager::handleLookupString(const QString& lookupString, bool fromSuggestions) {
|
||||
if (!lookupString.isEmpty()) {
|
||||
|
||||
QString sanitizedString = lookupString.trimmed();
|
||||
if (!sanitizedString.isEmpty()) {
|
||||
// make this a valid hifi URL and handle it off to handleUrl
|
||||
QString sanitizedString = lookupString.trimmed();
|
||||
QUrl lookupURL;
|
||||
|
||||
if (!lookupString.startsWith('/')) {
|
||||
// sometimes we need to handle lookupStrings like hifi:/somewhere
|
||||
const QRegExp HIFI_SCHEME_REGEX = QRegExp(URL_SCHEME_HIFI + ":\\/{1,2}", Qt::CaseInsensitive);
|
||||
sanitizedString = sanitizedString.remove(HIFI_SCHEME_REGEX);
|
||||
|
||||
lookupURL = QUrl(sanitizedString);
|
||||
if (lookupURL.scheme().isEmpty() || lookupURL.scheme().toLower() == LOCALHOST) {
|
||||
lookupURL = QUrl("hifi://" + sanitizedString);
|
||||
}
|
||||
} else {
|
||||
lookupURL = QUrl(sanitizedString);
|
||||
}
|
||||
|
||||
handleUrl(lookupURL, fromSuggestions ? Suggestions : UserInput);
|
||||
handleUrl(sanitizedString, fromSuggestions ? Suggestions : UserInput);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue