From 1411d5536479b07ea92afee754c871a12c5679c6 Mon Sep 17 00:00:00 2001 From: Kalila L Date: Tue, 15 Jun 2021 00:31:28 -0400 Subject: [PATCH] Add ability for 'handleLookupString' to have spaces. --- libraries/networking/src/AddressManager.cpp | 49 ++++++++++++++++----- libraries/networking/src/AddressManager.h | 33 +++++++------- 2 files changed, 55 insertions(+), 27 deletions(-) diff --git a/libraries/networking/src/AddressManager.cpp b/libraries/networking/src/AddressManager.cpp index c246cc00de..db9f35fa94 100644 --- a/libraries/networking/src/AddressManager.cpp +++ b/libraries/networking/src/AddressManager.cpp @@ -242,7 +242,7 @@ const JSONCallbackParameters& AddressManager::apiCallbackParameters() { return callbackParams; } -bool AddressManager::handleUrl(const QUrl& lookupUrlIn, LookupTrigger trigger) { +bool AddressManager::handleUrl(const QUrl& lookupUrlIn, LookupTrigger trigger, const QString& lookupUrlInString) { static QString URL_TYPE_USER = "user"; static QString URL_TYPE_DOMAIN_ID = "domain_id"; static QString URL_TYPE_PLACE = "place"; @@ -271,7 +271,15 @@ bool AddressManager::handleUrl(const QUrl& lookupUrlIn, LookupTrigger trigger) { // would indicate that the scheme is 'somewhere' // use hifi://somewhere: instead - if (lookupUrl.scheme() == URL_SCHEME_VIRCADIA) { + if (lookupUrl.scheme() == URL_SCHEME_VIRCADIA || lookupUrlInString.startsWith(URL_SCHEME_VIRCADIA + "://")) { + QString lookupUrlString; + + if (lookupUrlInString.startsWith(URL_SCHEME_VIRCADIA + "://")) { + lookupUrlString = lookupUrlInString; + } else { + lookupUrlString = lookupUrl.toString(QUrl::FullyEncoded); + } + if (lookupUrl.host().isEmpty()) { // this was in the form hifi:/somewhere or hifi:somewhere. Fix it by making it hifi://somewhere static const QRegExp HIFI_SCHEME_REGEX = QRegExp(URL_SCHEME_VIRCADIA + ":\\/{0,2}", Qt::CaseInsensitive); @@ -340,6 +348,8 @@ bool AddressManager::handleUrl(const QUrl& lookupUrlIn, LookupTrigger trigger) { // try to look up the domain ID on the metaverse API attemptDomainIDLookup(lookupUrl.host(), lookupUrl.path(), trigger); } else { + // wasn't an address - lookup the place name + // we may have a path that defines a relative viewpoint - pass that through the lookup so we can go to it after UserActivityLogger::getInstance().wentTo(trigger, URL_TYPE_PLACE, lookupUrl.toString()); // save the last visited domain URL. @@ -348,10 +358,27 @@ bool AddressManager::handleUrl(const QUrl& lookupUrlIn, LookupTrigger trigger) { // store this place name as the previous lookup in case we fail to connect and want to refresh API info _previousAPILookup = lookupUrl; - // wasn't an address - lookup the place name - // we may have a path that defines a relative viewpoint - pass that through the lookup so we can go to it after - if (!lookupUrl.host().isNull() && !lookupUrl.host().isEmpty()) { - attemptPlaceNameLookup(lookupUrl.host(), lookupUrl.path(), trigger); + // Let's convert this to a QString for processing in case there are spaces in it. + + if (lookupUrlString.contains(URL_SCHEME_VIRCADIA + "://", Qt::CaseInsensitive)) { + lookupUrlString = lookupUrlString.replace((URL_SCHEME_VIRCADIA + "://"), ""); + } else if (lookupUrlString.contains(URL_SCHEME_VIRCADIA + ":/", Qt::CaseInsensitive)) { + lookupUrlString = lookupUrlString.replace((URL_SCHEME_VIRCADIA + ":/"), ""); + } else if (lookupUrlString.contains(URL_SCHEME_VIRCADIA + ":", Qt::CaseInsensitive)) { + lookupUrlString = lookupUrlString.replace((URL_SCHEME_VIRCADIA + ":"), ""); + } + + // Get the path and then strip it out. + QString lookupUrlStringPath; + + int index = lookupUrlString.indexOf('/'); + if (index != -1) { + lookupUrlStringPath = lookupUrlString.mid(index); + lookupUrlString.replace(lookupUrlStringPath, ""); + } + + if (!lookupUrlString.isNull() && !lookupUrlString.isEmpty()) { + attemptPlaceNameLookup(lookupUrlString, lookupUrlStringPath, trigger); } } } @@ -412,13 +439,13 @@ bool isPossiblePlaceName(QString possiblePlaceName) { } void AddressManager::handleLookupString(const QString& lookupString, bool fromSuggestions) { + QString trimmedString = lookupString.trimmed(); - QString sanitizedString = lookupString.trimmed(); - if (!sanitizedString.isEmpty()) { + if (!trimmedString.isEmpty()) { resetConfirmConnectWithoutAvatarEntities(); // make this a valid hifi URL and handle it off to handleUrl - handleUrl(sanitizedString, fromSuggestions ? Suggestions : UserInput); + handleUrl(trimmedString, fromSuggestions ? Suggestions : UserInput, trimmedString); } } @@ -606,7 +633,7 @@ void AddressManager::handleAPIError(QNetworkReply* errorReply) { void AddressManager::attemptPlaceNameLookup(const QString& lookupString, const QString& overridePath, LookupTrigger trigger) { // assume this is a place name and see if we can get any info on it - QString placeName = QUrl::toPercentEncoding(lookupString); + //QString placeName = QUrl::toPercentEncoding(lookupString); QVariantMap requestParams; @@ -618,7 +645,7 @@ void AddressManager::attemptPlaceNameLookup(const QString& lookupString, const Q // remember how this lookup was triggered for history storage handling later requestParams.insert(LOOKUP_TRIGGER_KEY, static_cast(trigger)); - DependencyManager::get()->sendRequest(GET_PLACE.arg(placeName), + DependencyManager::get()->sendRequest(GET_PLACE.arg(lookupString), AccountManagerAuth::None, QNetworkAccessManager::GetOperation, apiCallbackParameters(), diff --git a/libraries/networking/src/AddressManager.h b/libraries/networking/src/AddressManager.h index e8793edc1d..3632b7f938 100644 --- a/libraries/networking/src/AddressManager.h +++ b/libraries/networking/src/AddressManager.h @@ -4,6 +4,7 @@ // // Created by Stephen Birarda on 2014-09-10. // Copyright 2014 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -35,7 +36,7 @@ const QString GET_PLACE = "/api/v1/places/%1"; * The location API provides facilities related to your current location in the metaverse. * *

Getter/Setter

- *

You can get and set your current metaverse address by directly reading a string value from and writing a string value to + *

You can get and set your current metaverse address by directly reading a string value from and writing a string value to * the location object. This is an alternative to using the location.href property or other object * functions.

* @@ -53,12 +54,12 @@ const QString GET_PLACE = "/api/v1/places/%1"; * localhost, or an IP address). Is blank if you're in a serverless domain. * Read-only. * @property {string} href - Your current metaverse address (e.g., "hifi://domainname/15,-10,26/0,0,0,1") - * regardless of whether or not you're connected to the domain. Starts with "file:///" if you're in a + * regardless of whether or not you're connected to the domain. Starts with "file:///" if you're in a * serverless domain. * Read-only. * @property {boolean} isConnected - true if you're connected to the domain in your current href * metaverse address, otherwise false. - * @property {string} pathname - The location and orientation in your current href metaverse address + * @property {string} pathname - The location and orientation in your current href metaverse address * (e.g., "/15,-10,26/0,0,0,1"). * Read-only. * @property {string} placename - The place name in your current href metaverse address @@ -77,7 +78,7 @@ const QString GET_PLACE = "/api/v1/places/%1"; * @hifi-client-entity * @hifi-avatar * - * @deprecated This API is deprecated and will be removed. Use the {@link location} or {@link Window|Window.location} APIs + * @deprecated This API is deprecated and will be removed. Use the {@link location} or {@link Window|Window.location} APIs * instead. * * @property {Uuid} domainID - A UUID uniquely identifying the domain you're visiting. Is {@link Uuid(0)|Uuid.NULL} if you're not @@ -248,9 +249,9 @@ public slots: /*@jsdoc * Takes you to a specified metaverse address. * @function location.handleLookupString - * @param {string} address - The address to go to: a "hifi://" address, an IP address (e.g., - * "127.0.0.1" or "localhost"), a file:/// address, a domain name, a named path - * on a domain (starts with "/"), a position or position and orientation, or a user (starts with + * @param {string} address - The address to go to: a "hifi://" address, an IP address (e.g., + * "127.0.0.1" or "localhost"), a file:/// address, a domain name, a named path + * on a domain (starts with "/"), a position or position and orientation, or a user (starts with * "@"). * @param {boolean} [fromSuggestions=false] - Set to true if the address is obtained from the "Goto" dialog. * Helps ensure that user's location history is correctly maintained. @@ -258,7 +259,7 @@ public slots: void handleLookupString(const QString& lookupString, bool fromSuggestions = false); /*@jsdoc - * Takes you to a position and orientation resulting from a lookup for a named path in the domain (set in the domain + * Takes you to a position and orientation resulting from a lookup for a named path in the domain (set in the domain * server's settings). * @function location.goToViewpointForPath * @param {string} path - The position and orientation corresponding to the named path. @@ -292,7 +293,7 @@ public slots: * location history is correctly maintained. */ void goToLocalSandbox(QString path = "", LookupTrigger trigger = LookupTrigger::StartupFromSettings) { - handleUrl(SANDBOX_HIFI_ADDRESS + path, trigger); + handleUrl(SANDBOX_HIFI_ADDRESS + path, trigger); } /*@jsdoc @@ -307,7 +308,7 @@ public slots: * Takes you to the specified user's location. * @function location.goToUser * @param {string} username - The user's username. - * @param {boolean} [matchOrientation=true] - If true then go to a location just in front of the user and turn + * @param {boolean} [matchOrientation=true] - If true then go to a location just in front of the user and turn * to face them, otherwise go to the user's exact location and orientation. */ void goToUser(const QString& username, bool shouldMatchOrientation = true); @@ -348,7 +349,7 @@ public slots: void copyAddress(); /*@jsdoc - * Copies your current metaverse location and orientation (i.e., location.pathname property value) to the OS + * Copies your current metaverse location and orientation (i.e., location.pathname property value) to the OS * clipboard. * @function location.copyPath */ @@ -374,7 +375,7 @@ signals: void lookupResultsFinished(); /*@jsdoc - * Triggered when looking up the details of a metaverse user or location to go to has completed and the domain or user is + * Triggered when looking up the details of a metaverse user or location to go to has completed and the domain or user is * offline. * @function location.lookupResultIsOffline * @returns {Signal} @@ -415,9 +416,9 @@ signals: * @function location.locationChangeRequired * @param {Vec3} position - The position to go to. * @param {boolean} hasOrientationChange - If true then a new orientation has been requested. - * @param {Quat} orientation - The orientation to change to. Is {@link Quat(0)|Quat.IDENTITY} if + * @param {Quat} orientation - The orientation to change to. Is {@link Quat(0)|Quat.IDENTITY} if * hasOrientationChange is false. - * @param {boolean} shouldFaceLocation - If true then the request is to go to a position near that specified + * @param {boolean} shouldFaceLocation - If true then the request is to go to a position near that specified * and orient your avatar to face it. For example when you visit someone from the "People" dialog. * @returns {Signal} * @example Report location change requests. @@ -468,7 +469,7 @@ signals: * Triggered when there's a change in whether or not there's a previous location that can be navigated to using * {@link location.goBack|goBack}. (Reflects changes in the state of the "Goto" dialog's back arrow.) * @function location.goBackPossible - * @param {boolean} isPossible - true if there's a previous location to navigate to, otherwise + * @param {boolean} isPossible - true if there's a previous location to navigate to, otherwise * false. * @returns {Signal} * @example Report when ability to navigate back changes. @@ -511,7 +512,7 @@ private: const JSONCallbackParameters& apiCallbackParameters(); - bool handleUrl(const QUrl& lookupUrl, LookupTrigger trigger = UserInput); + bool handleUrl(const QUrl& lookupUrl, LookupTrigger trigger = UserInput, const QString& lookupUrlInString = ""); bool handleNetworkAddress(const QString& lookupString, LookupTrigger trigger, bool& hostChanged); void handlePath(const QString& path, LookupTrigger trigger, bool wasPathOnly = false);