Exemplo n.º 1
0
QString AddressManager::pathForPositionAndOrientation(const glm::vec3& position, bool hasOrientation,
                                                      const glm::quat& orientation) {
    
    QString pathString = "/" + createByteArray(position);
    
    if (hasOrientation) {
        QString orientationString = createByteArray(orientation);
        pathString += "/" + orientationString;
    }
    
    return pathString;
}
Exemplo n.º 2
0
CapsInfo CapsInfoGenerator::generateCapsInfo(const DiscoInfo& discoInfo) const {
    std::string serializedCaps;

    std::vector<DiscoInfo::Identity> identities(discoInfo.getIdentities());
    std::sort(identities.begin(), identities.end());
    for (const auto& identity : identities) {
        serializedCaps += identity.getCategory() + "/" + identity.getType() + "/" + identity.getLanguage() + "/" + identity.getName() + "<";
    }

    std::vector<std::string> features(discoInfo.getFeatures());
    std::sort(features.begin(), features.end());
    for (const auto& feature : features) {
        serializedCaps += feature + "<";
    }

    for (const auto& extension : discoInfo.getExtensions()) {
        serializedCaps += extension->getFormType() + "<";
        std::vector<FormField::ref> fields(extension->getFields());
        std::sort(fields.begin(), fields.end(), &compareFields);
        for (const auto& field : fields) {
            if (field->getName() == "FORM_TYPE") {
                continue;
            }
            serializedCaps += field->getName() + "<";
            std::vector<std::string> values(field->getValues());
            std::sort(values.begin(), values.end());
            for (const auto& value : values) {
                serializedCaps += value + "<";
            }
        }
    }

    std::string version(Base64::encode(crypto_->getSHA1Hash(createByteArray(serializedCaps))));
    return CapsInfo(node_, version, "sha-1");
}
Exemplo n.º 3
0
void Profile::updatePosition(const glm::vec3 position) {
    if (_lastPosition != position) {
        
        static timeval lastPositionSend = {};
        const quint64 DATA_SERVER_POSITION_UPDATE_INTERVAL_USECS = 5 * 1000 * 1000;
        const float DATA_SERVER_POSITION_CHANGE_THRESHOLD_METERS = 1;
        
        if (usecTimestampNow() - usecTimestamp(&lastPositionSend) >= DATA_SERVER_POSITION_UPDATE_INTERVAL_USECS &&
            (fabsf(_lastPosition.x - position.x) >= DATA_SERVER_POSITION_CHANGE_THRESHOLD_METERS ||
             fabsf(_lastPosition.y - position.y) >= DATA_SERVER_POSITION_CHANGE_THRESHOLD_METERS ||
             fabsf(_lastPosition.z - position.z) >= DATA_SERVER_POSITION_CHANGE_THRESHOLD_METERS))  {
                
                // if it has been 5 seconds since the last position change and the user has moved >= the threshold
                // in at least one of the axis then send the position update to the data-server
                
                _lastPosition = position;
                
                // update the lastPositionSend to now
                gettimeofday(&lastPositionSend, NULL);
                
                // send the changed position to the data-server
                DataServerClient::putValueForKeyAndUserString(DataServerKey::Position,
                                                              QString(createByteArray(position)), getUserString());
            }
    }
}
Exemplo n.º 4
0
ByteArray DIGESTMD5Properties::serialize() const {
	ByteArray result;
	for(DIGESTMD5PropertiesMap::const_iterator i = properties.begin(); i != properties.end(); ++i) {
		if (i != properties.begin()) {
			result.push_back(',');
		}
		append(result, createByteArray(i->first));
		result.push_back('=');
		if (isQuoted(i->first)) {
			append(result, createByteArray("\""));
			append(result, i->second);
			append(result, createByteArray("\""));
		}
		else {
			append(result, i->second);
		}
	}
	return result;
}
void SOCKS5BytestreamClientSession::handleDataRead(boost::shared_ptr<SafeByteArray> data) {
	SWIFT_LOG(debug) << "state: " << state << " data.size() = " << data->size() << std::endl;
	if (state != Reading) {
		append(unprocessedData, *data);
		process();
	}
	else {
		writeBytestream->write(createByteArray(vecptr(*data), data->size()));
		//onBytesReceived(data->size());
	}
}
void SOCKS5BytestreamClientSession::authenticate() {
	SWIFT_LOG(debug) << std::endl;
	SafeByteArray header = createSafeByteArray("\x05\x01\x00\x03", 4);
	SafeByteArray message = header;
	append(message, createSafeByteArray(boost::numeric_cast<char>(destination.size())));
	authenticateAddress = createByteArray(destination);
	append(message, authenticateAddress);
	append(message, createSafeByteArray("\x00\x00", 2)); // 2 byte for port
	connection->write(message);
	state = Authenticating;
}
Exemplo n.º 7
0
const QString AddressManager::currentPath(bool withOrientation) const {

    if (_positionGetter) {
        QString pathString = "/" + createByteArray(_positionGetter());

        if (withOrientation) {
            if (_orientationGetter) {
                QString orientationString = createByteArray(_orientationGetter());
                pathString += "/" + orientationString;
            } else {
                qCDebug(networking) << "Cannot add orientation to path without a getter for position."
                    << "Call AddressManager::setOrientationGetter to pass a function that will return a glm::quat";
            }

        }

        return pathString;
    } else {
        qCDebug(networking) << "Cannot create address path without a getter for position."
            << "Call AddressManager::setPositionGetter to pass a function that will return a const glm::vec3&";
        return QString();
    }
}
Exemplo n.º 8
0
RefPtr<TTObject> TTLiteral::createByteArray(const std::vector<uint8_t> &bytes)
{
    RefPtr<TTObject> obj = createByteArray(bytes.size());

    uint8_t *dataBytes = obj->getLiteral()->data;

    for(auto &byt : bytes)
    {
        *dataBytes = byt;
        dataBytes++;
    }

    return obj;
}
Exemplo n.º 9
0
static std::string getCertUri(PCCERT_CONTEXT cert, const char * cert_store_name) {
	DWORD cbHash = SHA1_HASH_LENGTH;
	BYTE aHash[SHA1_HASH_LENGTH];
	std::string result("certstore:");

	result += cert_store_name;
	result += ":sha1:";

	if (CertGetCertificateContextProperty(cert, CERT_HASH_PROP_ID, aHash, &cbHash) == FALSE ) {
		return "";
	}

	ByteArray byteArray = createByteArray((char *)(&aHash[0]), cbHash);
	result += Hexify::hexify(byteArray);

	return result;
}
Exemplo n.º 10
0
void BOSHConnection::handleDataRead(std::shared_ptr<SafeByteArray> data) {
    onBOSHDataRead(*data);
    buffer_ = concat(buffer_, *data);
    std::string response = safeByteArrayToString(buffer_);
    if (response.find("\r\n\r\n") == std::string::npos) {
        onBOSHDataRead(createSafeByteArray("[[Previous read incomplete, pending]]"));
        return;
    }

    std::string httpCode = response.substr(response.find(" ") + 1, 3);
    if (httpCode != "200") {
        onHTTPError(httpCode);
        return;
    }

    BOSHBodyExtractor parser(parserFactory_, createByteArray(response.substr(response.find("\r\n\r\n") + 4)));
    if (parser.getBody()) {
        if (parser.getBody()->attributes.getAttribute("type") == "terminate") {
            BOSHError::Type errorType = parseTerminationCondition(parser.getBody()->attributes.getAttribute("condition"));
            onSessionTerminated(errorType == BOSHError::NoError ? std::shared_ptr<BOSHError>() : std::make_shared<BOSHError>(errorType));
        }
        buffer_.clear();
        if (waitingForStartResponse_) {
            waitingForStartResponse_ = false;
            sid_ = parser.getBody()->attributes.getAttribute("sid");
            std::string requestsString = parser.getBody()->attributes.getAttribute("requests");
            size_t requests = 2;
            if (!requestsString.empty()) {
                try {
                    requests = boost::lexical_cast<size_t>(requestsString);
                }
                catch (const boost::bad_lexical_cast&) {
                }
            }
            onSessionStarted(sid_, requests);
        }
        SafeByteArray payload = createSafeByteArray(parser.getBody()->content);
        /* Say we're good to go again, so don't add anything after here in the method */
        pending_ = false;
        onXMPPDataRead(payload);
    }

}
void SOCKS5BytestreamClientSession::process() {
	SWIFT_LOG(debug) << "unprocessedData.size(): " << unprocessedData.size() << std::endl;
	ByteArray bndAddress;
	switch(state) {
		case Initial:
			hello();
			break;
		case Hello:
			if (unprocessedData.size() > 1) {
				unsigned char version = unprocessedData[0];
				unsigned char authMethod = unprocessedData[1];
				if (version != 5 || authMethod != 0) {
					// signal failure to upper level
					finish(true);
					return;
				}
				unprocessedData.clear();
				authenticate();
			}
			break;
		case Authenticating:
			if (unprocessedData.size() < 5) {
				// need more data to start progressing
				break;
			}
			if (unprocessedData[0] != '\x05') {
				// wrong version
				// disconnect & signal failure
				finish(true);
				break;
			}
			if (unprocessedData[1] != '\x00') {
				// no success
				// disconnect & signal failure
				finish(true);
				break;
			}
			if (unprocessedData[3] != '\x03') {
				// we expect x'03' = DOMAINNAME here
				// discconect & signal failure
				finish(true);
				break;
			}
			if (static_cast<size_t>(unprocessedData[4]) + 1 > unprocessedData.size() + 5) {
				// complete domainname and port not available yet
				break;
			}
			bndAddress = createByteArray(&vecptr(unprocessedData)[5], unprocessedData[4]);
			if (unprocessedData[unprocessedData[4] + 5] != 0 && bndAddress == createByteArray(destination)) {
				// we expect a 0 as port
				// disconnect and fail
				finish(true);
			}
			unprocessedData.clear();
			state = Ready;
			SWIFT_LOG(debug) << "session ready" << std::endl;
			// issue ready signal so the bytestream can be used for reading or writing
			weFailedTimeout->stop();
			onSessionReady(false);
			break;
		case Ready:
			SWIFT_LOG(debug) << "Received further data in Ready state." << std::endl;
			break;
		case Reading:
		case Writing:
		case Finished:
			SWIFT_LOG(debug) << "Unexpected receive of data. Current state: " << state << std::endl;
			SWIFT_LOG(debug) << "Data: " << Hexify::hexify(unprocessedData) << std::endl;
			unprocessedData.clear();
			//assert(false);
	}
}
Exemplo n.º 12
0
void DIGESTMD5Properties::setValue(const std::string& key, const std::string& value) {
	properties.insert(DIGESTMD5PropertiesMap::value_type(key, createByteArray(value)));
}
std::string SOCKS5BytestreamServer::getSOCKSDestinationAddress(const std::string& id, const JID& from, const JID& to) {
	return Hexify::hexify(SHA1::getHash(createByteArray(id + from.toString() + to.toString())));
}
Exemplo n.º 14
0
void Profile::updateOrientation(const glm::quat& orientation) {
    glm::vec3 eulerAngles = safeEulerAngles(orientation);
    if (_lastOrientation == eulerAngles) {
        return;
    }
    const quint64 DATA_SERVER_ORIENTATION_UPDATE_INTERVAL_USECS = 5 * 1000 * 1000;
    const float DATA_SERVER_ORIENTATION_CHANGE_THRESHOLD_DEGREES = 5.0f;
    
    quint64 now = usecTimestampNow();
    if (now - _lastOrientationSend >= DATA_SERVER_ORIENTATION_UPDATE_INTERVAL_USECS &&
            glm::distance(_lastOrientation, eulerAngles) >= DATA_SERVER_ORIENTATION_CHANGE_THRESHOLD_DEGREES) {
        DataServerClient::putValueForKeyAndUserString(DataServerKey::Orientation, QString(createByteArray(eulerAngles)),
                                                      getUserString());
        
        _lastOrientation = eulerAngles;
        _lastOrientationSend = now;
    }
}