Esempio n. 1
0
void ServerStanzaChannel::handleDataRead(const SafeByteArray &data, const SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<ServerFromClientSession> &session) {
	if (safeByteArrayToString(data).find("</stream:stream>") != std::string::npos) {
		Swift::Presence::ref presence = Swift::Presence::create();
		presence->setFrom(session->getRemoteJID());
		presence->setType(Swift::Presence::Unavailable);
		onPresenceReceived(presence);
	}
}
Esempio n. 2
0
void HTTPRequest::handleDisconnected(const boost::optional<Swift::Connection::Error>& error) {
	//std::cerr << "HTTP Disconnected" << std::endl;
	cancelConnector();
	if (receivedHeaders_) {
		onComplete(Swift::createByteArray(safeByteArrayToString(buffer_))); // Yes, this is getting a little silly with the conversions.
	}
	else {
		onError();
	}
	connection_.reset(); // Delete the connection, the signals that keep the HTTPRequest alive get cleared, this gets cleaned up.
}
Esempio n. 3
0
void BOSHConnection::write(const SafeByteArray& data, bool streamRestart, bool terminate) {
    assert(connectionReady_);
    assert(!sid_.empty());

    SafeByteArray safeHeader = createHTTPRequest(data, streamRestart, terminate, rid_, sid_, boshURL_).first;

    onBOSHDataWritten(safeHeader);
    writeData(safeHeader);
    pending_ = true;

    SWIFT_LOG(debug) << "write data: " << safeByteArrayToString(safeHeader) << std::endl;
}
Esempio n. 4
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);
    }

}
Esempio n. 5
0
void HTTPRequest::handleDataRead(boost::shared_ptr<Swift::SafeByteArray> data) {
	//std::cerr << "<<< " << Swift::safeByteArrayToString(*data) << std::endl;
	buffer_ = Swift::concat(buffer_, *data);
	if (!receivedHeaders_) {
		std::string response = safeByteArrayToString(buffer_);
		if (response.find("\r\n\r\n") == std::string::npos) {
			return;
		}
		receivedHeaders_ = true;
		std::string httpCode = response.substr(response.find(" ") + 1, 3);
		if (httpCode != "200") {
			//onHTTPError(httpCode);
			onError();
			return;
		}
		std::string rest = Swift::safeByteArrayToString(buffer_);
		buffer_ = Swift::createSafeByteArray(response.substr(response.find("\r\n\r\n") + 4));
	}
	//Now see if we've had the headers (now, or previously)
	if (receivedHeaders_) {
	
	}
}
Esempio n. 6
0
void BOSHConnection::startStream(const std::string& to, unsigned long long rid) {
    assert(connectionReady_);
    // Session Creation Request
    std::stringstream content;
    std::stringstream header;

    content << "<body content='text/xml; charset=utf-8'"
            << " hold='1'"
            << " to='" << to << "'"
            << " rid='" << rid << "'"
            << " ver='1.6'"
            << " wait='60'" /* FIXME: we probably want this configurable*/
            // << " ack='0'" FIXME: support acks
            << " xml:lang='en'"
            << " xmlns:xmpp='urn:xmpp:bosh'"
            << " xmpp:version='1.0'"
            << " xmlns='http://jabber.org/protocol/httpbind' />";

    std::string contentString = content.str();

    header    << "POST " << boshURL_.getPath() << " HTTP/1.1\r\n"
            << "Host: " << boshURL_.getHost();
    if (boshURL_.getPort()) {
        header << ":" << *boshURL_.getPort();
    }
    header << "\r\n"
         // << "Accept-Encoding: deflate\r\n"
            << "Content-Type: text/xml; charset=utf-8\r\n"
            << "Content-Length: " << contentString.size() << "\r\n\r\n"
            << contentString;

    waitingForStartResponse_ = true;
    SafeByteArray safeHeader = createSafeByteArray(header.str());
    onBOSHDataWritten(safeHeader);
    writeData(safeHeader);
    SWIFT_LOG(debug) << "write stream header: " << safeByteArrayToString(safeHeader) << std::endl;
}
void Component::handleDataWritten(const Swift::SafeByteArray &data) {
	LOG4CXX_INFO(logger_xml, "XML OUT " << safeByteArrayToString(data));
}
void Component::handleDataRead(const Swift::SafeByteArray &data) {
	std::string d = safeByteArrayToString(data);
	if (!boost::starts_with(d, "<auth")) {
		LOG4CXX_INFO(logger_xml, "XML IN " << d);
	}
}
Esempio n. 9
0
void XMPPFrontend::handleDataWritten(const Swift::SafeByteArray &data) {
	std::string d = safeByteArrayToString(data);
	m_transport->handleDataWritten(d);
}