Changeset - 6dd386320050
[Not reviewed]
0 2 0
Jan Kaluza - 9 years ago 2016-02-08 16:00:17
jkaluza@redhat.com
Do no create Swift::JID with an empty node
2 files changed with 6 insertions and 6 deletions:
0 comments (0 inline, 0 general)
include/Swiften/Server/ServerFromClientSession.cpp
Show inline comments
 
@@ -126,25 +126,25 @@ void ServerFromClientSession::handleElement(boost::shared_ptr<Element> element)
 
				resultResourceBind->setJID(getRemoteJID());
 
				getXMPPLayer()->writeElement(IQ::createResult(JID(), iq->getID(), resultResourceBind));
 
			}
 
			else if (iq->getPayload<StartSession>()) {
 
				getXMPPLayer()->writeElement(IQ::createResult(getRemoteJID(), iq->getID()));
 
				setInitialized();
 
			}
 
		}
 
	}
 
}
 

	
 
void ServerFromClientSession::handleStreamStart(const ProtocolHeader& incomingHeader) {
 
	setLocalJID(JID("", incomingHeader.getTo()));
 
	setLocalJID(JID(incomingHeader.getTo()));
 
	ProtocolHeader header;
 
	header.setFrom(incomingHeader.getTo());
 
	header.setID(id_);
 
	getXMPPLayer()->writeHeader(header);
 

	
 
	boost::shared_ptr<StreamFeatures> features(new StreamFeatures());
 

	
 
	if (!authenticated_) {
 
		if (tlsLayer && !tlsConnected) {
 
			features->setHasStartTLS();
 
		}
 
		features->addAuthenticationMechanism("PLAIN");
spectrum/src/frontends/slack/SlackSession.cpp
Show inline comments
 
@@ -174,79 +174,79 @@ void SlackSession::handleJoinRoomCreated(const std::string &channelId, std::vect
 
	std::string to = legacyRoom + "%" + legacyServer + "@" + m_component->getJID().toString();
 
// 	if (!CONFIG_BOOL_DEFAULTED(m_component->getConfig(), "registration.needRegistration", true)) {
 
// 		m_uinfo.uin = name;
 
// 		m_storageBackend->setUser(m_uinfo);
 
// 	}
 

	
 
	LOG4CXX_INFO(logger, m_uinfo.jid << ": Channel " << args[5] << " is created. Joining the room on legacy network.");
 

	
 
	m_jid2channel[to] = slackChannel;
 
	m_channel2jid[slackChannel] = to;
 

	
 
	Swift::Presence::ref presence = Swift::Presence::create();
 
	presence->setFrom(Swift::JID("", m_uinfo.jid, "default"));
 
	presence->setFrom(Swift::JID(m_uinfo.jid + "/default"));
 
	presence->setTo(Swift::JID(to + "/" + name));
 
	presence->setType(Swift::Presence::Available);
 
	presence->addPayload(boost::shared_ptr<Swift::Payload>(new Swift::MUCPayload()));
 
	m_component->getFrontend()->onPresenceReceived(presence);
 

	
 
	m_onlineBuddiesTimer->start();
 
}
 

	
 
void SlackSession::handleJoinMessage(const std::string &message, std::vector<std::string> &args, bool quiet) {
 
	LOG4CXX_INFO(logger, m_uinfo.jid << ": Going to join the room " << args[3] << "@" << args[4] << ", transporting it to channel " << args[5]);
 
	m_api->createChannel(args[5], m_idManager->getSelfId(), boost::bind(&SlackSession::handleJoinRoomCreated, this, _1, args));
 
}
 

	
 
void SlackSession::handleSlackChannelCreated(const std::string &channelId) {
 
	m_slackChannel = channelId;
 

	
 
	LOG4CXX_INFO(logger, m_uinfo.jid << ": Main Slack Channel created, connecting the legacy network");
 
	Swift::Presence::ref presence = Swift::Presence::create();
 
	presence->setFrom(Swift::JID("", m_uinfo.jid, "default"));
 
	presence->setFrom(Swift::JID(m_uinfo.jid + "/default"));
 
	presence->setTo(m_component->getJID());
 
	presence->setType(Swift::Presence::Available);
 
	presence->addPayload(boost::shared_ptr<Swift::Payload>(new Swift::MUCPayload()));
 
	m_component->getFrontend()->onPresenceReceived(presence);
 
}
 

	
 
void SlackSession::leaveRoom(const std::string &channel) {
 
	std::string channelId = m_idManager->getId(channel);
 
	std::string to = m_channel2jid[channelId];
 
	if (to.empty()) {
 
		LOG4CXX_ERROR(logger, "Spectrum 2 is not configured to transport this Slack channel.")
 
		return;
 
	}
 

	
 
	LOG4CXX_INFO(logger, m_uinfo.jid << ": Leaving the legacy network room " << to);
 

	
 
	Swift::Presence::ref presence = Swift::Presence::create();
 
	presence->setFrom(Swift::JID("", m_uinfo.jid, "default"));
 
	presence->setFrom(Swift::JID(m_uinfo.jid + "/default"));
 
	presence->setTo(Swift::JID(to + "/" + m_uinfo.uin));
 
	presence->setType(Swift::Presence::Unavailable);
 
	presence->addPayload(boost::shared_ptr<Swift::Payload>(new Swift::MUCPayload()));
 
	m_component->getFrontend()->onPresenceReceived(presence);
 
}
 

	
 
void SlackSession::handleMessageReceived(const std::string &channel, const std::string &user, const std::string &message, const std::string &ts, bool quiet) {
 
	std::string to = m_channel2jid[channel];
 
	if (m_idManager->getName(user) == m_idManager->getSelfName()) {
 
		return;
 
	}
 

	
 
	if (!to.empty()) {
 
		boost::shared_ptr<Swift::Message> msg(new Swift::Message());
 
		msg->setType(Swift::Message::Groupchat);
 
		msg->setTo(to);
 
		msg->setFrom(Swift::JID("", m_uinfo.jid, "default"));
 
		msg->setFrom(Swift::JID(m_uinfo.jid + "/default"));
 
		msg->setBody("<" + m_idManager->getName(user) + "> " + message);
 
		m_component->getFrontend()->onMessageReceived(msg);
 
	}
 
	else {
 
		// When changing the purpose, we do not want to spam to room with the info,
 
		// so remove the purpose message.
 
// 			if (message.find("set the channel purpose") != std::string::npos) {
 
// 				m_rtm->getAPI()->deleteMessage(channel, ts);
 
// 			}
 
		// TODO: MAP `user` to JID somehow and send the message to proper JID.
 
		// So far send to all online contacts
 

	
 
@@ -264,25 +264,25 @@ void SlackSession::handleMessageReceived(const std::string &channel, const std::
 
			}
 

	
 
			if (!(b->getStatus(s, statusMessage))) {
 
				continue;
 
			}
 

	
 
			if (s.getType() == Swift::StatusShow::None) {
 
				continue;
 
			}
 

	
 
			boost::shared_ptr<Swift::Message> msg(new Swift::Message());
 
			msg->setTo(b->getJID());
 
			msg->setFrom(Swift::JID("", m_uinfo.jid, "default"));
 
			msg->setFrom(Swift::JID(m_uinfo.jid + "/default"));
 
			msg->setBody("<" + m_idManager->getName(user) + "> " + message);
 
			m_component->getFrontend()->onMessageReceived(msg);
 
		}
 
	}
 
}
 

	
 
void SlackSession::handleDisconnected() {
 
	m_disconnected = true;
 
}
 

	
 
void SlackSession::setUser(User *user) {
 
	m_user = user;
0 comments (0 inline, 0 general)