Exemple #1
0
bool AddressManager::handleNetworkAddress(const QString& lookupString, LookupTrigger trigger) {
    const QString IP_ADDRESS_REGEX_STRING = "^((?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}"
        "(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))(?::(\\d{1,5}))?$";

    const QString HOSTNAME_REGEX_STRING = "^((?:[A-Z0-9]|[A-Z0-9][A-Z0-9\\-]{0,61}[A-Z0-9])"
        "(?:\\.(?:[A-Z0-9]|[A-Z0-9][A-Z0-9\\-]{0,61}[A-Z0-9]))+|localhost)(?::(\\d{1,5}))?$";

    QRegExp ipAddressRegex(IP_ADDRESS_REGEX_STRING);

    if (ipAddressRegex.indexIn(lookupString) != -1) {
        QString domainIPString = ipAddressRegex.cap(1);

        qint16 domainPort = DEFAULT_DOMAIN_SERVER_PORT;
        if (!ipAddressRegex.cap(2).isEmpty()) {
            domainPort = (qint16) ipAddressRegex.cap(2).toInt();
        }

        emit lookupResultsFinished();
        setDomainInfo(domainIPString, domainPort, trigger);

        return true;
    }

    QRegExp hostnameRegex(HOSTNAME_REGEX_STRING, Qt::CaseInsensitive);

    if (hostnameRegex.indexIn(lookupString) != -1) {
        QString domainHostname = hostnameRegex.cap(1);

        quint16 domainPort = DEFAULT_DOMAIN_SERVER_PORT;

        if (!hostnameRegex.cap(2).isEmpty()) {
            domainPort = (qint16)hostnameRegex.cap(2).toInt();
        }

        emit lookupResultsFinished();
        setDomainInfo(domainHostname, domainPort, trigger);

        return true;
    }

    return false;
}
Exemple #2
0
void AddressManager::handleAPIResponse(QNetworkReply& requestReply) {
    QJsonObject responseObject = QJsonDocument::fromJson(requestReply.readAll()).object();
    QJsonObject dataObject = responseObject["data"].toObject();

    if (!dataObject.isEmpty()) {
        goToAddressFromObject(dataObject.toVariantMap(), requestReply);
    } else if (responseObject.contains(DATA_OBJECT_DOMAIN_KEY)) {
        goToAddressFromObject(responseObject.toVariantMap(), requestReply);
    }

    emit lookupResultsFinished();
}
Exemple #3
0
void AddressManager::handleAPIResponse(const QJsonObject &jsonObject) {
    QJsonObject dataObject = jsonObject["data"].toObject();
    
    const QString ADDRESS_API_DOMAIN_KEY = "domain";
    const QString ADDRESS_API_ONLINE_KEY = "online";
    
    if (!dataObject.contains(ADDRESS_API_ONLINE_KEY)
        || dataObject[ADDRESS_API_ONLINE_KEY].toBool()) {
        
        if (dataObject.contains(ADDRESS_API_DOMAIN_KEY)) {
            QJsonObject domainObject = dataObject[ADDRESS_API_DOMAIN_KEY].toObject();
            
            const QString DOMAIN_NETWORK_ADDRESS_KEY = "network_address";
            QString domainHostname = domainObject[DOMAIN_NETWORK_ADDRESS_KEY].toString();
            
            emit possibleDomainChangeRequired(domainHostname);
            
            // take the path that came back
            const QString LOCATION_KEY = "location";
            const QString LOCATION_PATH_KEY = "path";
            QString returnedPath;
            
            if (domainObject.contains(LOCATION_PATH_KEY)) {
                returnedPath = domainObject[LOCATION_PATH_KEY].toString();
            } else if (domainObject.contains(LOCATION_KEY)) {
                returnedPath = domainObject[LOCATION_KEY].toObject()[LOCATION_PATH_KEY].toString();
            }
            
            bool shouldFaceViewpoint = dataObject.contains(ADDRESS_API_ONLINE_KEY);
            
            if (!returnedPath.isEmpty()) {
                // try to parse this returned path as a viewpoint, that's the only thing it could be for now
                if (!handleRelativeViewpoint(returnedPath, shouldFaceViewpoint)) {
                    qDebug() << "Received a location path that was could not be handled as a viewpoint -" << returnedPath;
                }
            }
            
        } else {
            qDebug() << "Received an address manager API response with no domain key. Cannot parse.";
            qDebug() << jsonObject;
        }
    } else {
        // we've been told that this result exists but is offline, emit our signal so the application can handle
        emit lookupResultIsOffline();
    }
    emit lookupResultsFinished();
}
Exemple #4
0
bool AddressManager::handleUrl(const QUrl& lookupUrl, LookupTrigger trigger) {
    if (lookupUrl.scheme() == HIFI_URL_SCHEME) {

        qCDebug(networking) << "Trying to go to URL" << lookupUrl.toString();

        DependencyManager::get<NodeList>()->flagTimeForConnectionStep(LimitedNodeList::ConnectionStep::LookupAddress);

        // there are 4 possible lookup strings

        // 1. global place name (name of domain or place) - example: sanfrancisco
        // 2. user name (prepended with @) - example: @philip
        // 3. location string (posX,posY,posZ/eulerX,eulerY,eulerZ)
        // 4. domain network address (IP or dns resolvable hostname)

        // use our regex'ed helpers to figure out what we're supposed to do with this
        if (!handleUsername(lookupUrl.authority())) {
            // we're assuming this is either a network address or global place name
            // check if it is a network address first
            if (handleNetworkAddress(lookupUrl.host()
                                      + (lookupUrl.port() == -1 ? "" : ":" + QString::number(lookupUrl.port())), trigger)) {
                // we may have a path that defines a relative viewpoint - if so we should jump to that now
                handlePath(lookupUrl.path(), trigger);
            } else if (handleDomainID(lookupUrl.host())){
                // no place name - this is probably a domain ID
                // 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
                attemptPlaceNameLookup(lookupUrl.host(), lookupUrl.path(), trigger);
            }
        }

        return true;
    } else if (lookupUrl.toString().startsWith('/')) {
        qCDebug(networking) << "Going to relative path" << lookupUrl.path();

        // if this is a relative path then handle it as a relative viewpoint
        handlePath(lookupUrl.path(), trigger, true);
        emit lookupResultsFinished();

        return true;
    }

    return false;
}
Exemple #5
0
bool AddressManager::handleUrl(const QUrl& lookupUrl) {
    if (lookupUrl.scheme() == HIFI_URL_SCHEME) {
        
        qDebug() << "Trying to go to URL" << lookupUrl.toString();
        
        // there are 4 possible lookup strings
        
        // 1. global place name (name of domain or place) - example: sanfrancisco
        // 2. user name (prepended with @) - example: @philip
        // 3. location string (posX,posY,posZ/eulerX,eulerY,eulerZ)
        // 4. domain network address (IP or dns resolvable hostname)
        
        // use our regex'ed helpers to figure out what we're supposed to do with this
        if (!handleUsername(lookupUrl.authority())) {
            // we're assuming this is either a network address or global place name
            // check if it is a network address first
            if (handleNetworkAddress(lookupUrl.host()
                                      + (lookupUrl.port() == -1 ? "" : ":" + QString::number(lookupUrl.port())))) {
                // we may have a path that defines a relative viewpoint - if so we should jump to that now
                handleRelativeViewpoint(lookupUrl.path());
            } 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
                attemptPlaceNameLookup(lookupUrl.host(), lookupUrl.path());
                
            }
        }
        
        return true;
    } else if (lookupUrl.toString().startsWith('/')) {
        qDebug() << "Going to relative path" << lookupUrl.path();
        
        // if this is a relative path then handle it as a relative viewpoint
        handleRelativeViewpoint(lookupUrl.path());
        emit lookupResultsFinished();
    }
    
    return false;
}