Changeset - 161a7988902f
[Not reviewed]
0 3 0
me@boku.ru - 7 years ago 2018-02-01 18:30:52
me@boku.ru
Use the default JID resource for the sender when forming carbons
3 files changed with 11 insertions and 4 deletions:
0 comments (0 inline, 0 general)
include/transport/Buddy.h
Show inline comments
 
@@ -4,48 +4,51 @@
 
 * Copyright (C) 2009, Jan Kaluza <hanzz@soc.pidgin.im>
 
 *
 
 * This program is free software; you can redistribute it and/or modify
 
 * it under the terms of the GNU General Public License as published by
 
 * the Free Software Foundation; either version 2 of the License, or
 
 * (at your option) any later version.
 
 *
 
 * This program is distributed in the hope that it will be useful,
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 * GNU General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU General Public License
 
 * along with this program; if not, write to the Free Software
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
 
 */
 

	
 
#pragma once
 

	
 
#include <string>
 
#include <algorithm>
 
#include "Swiften/Elements/VCard.h"
 
#include "Swiften/Elements/Presence.h"
 

	
 
//Default resource name which contacts use
 
#define JID_DEFAULT_RESOURCE "bot"
 

	
 
namespace Transport {
 

	
 
class RosterManager;
 
class User;
 

	
 
typedef enum { 	BUDDY_NO_FLAG = 0,
 
				BUDDY_JID_ESCAPING = 2,
 
				BUDDY_IGNORE = 4,
 
				BUDDY_BLOCKED = 8,
 
			} BuddyFlag;
 

	
 
/// Represents one legacy network Buddy.
 
class Buddy {
 
	public:
 
		typedef enum { 	Ask,
 
						Both,
 
					} Subscription;
 
		/// Constructor.
 

	
 
		/// \param rosterManager RosterManager associated with this buddy.
 
		/// \param id ID which identifies the buddy in database or -1 if it's new buddy which is
 
		/// not in database yet.
 
		Buddy(RosterManager *rosterManager, long id = -1, BuddyFlag flags = BUDDY_NO_FLAG);
 

	
libtransport/Buddy.cpp
Show inline comments
 
@@ -28,49 +28,49 @@
 
#include "Swiften/Elements/VCardUpdate.h"
 
#include "Swiften/Elements/Presence.h"
 

	
 
#include <boost/foreach.hpp>
 
#include <boost/make_shared.hpp>
 

	
 
namespace Transport {
 

	
 
Buddy::Buddy(RosterManager *rosterManager, long id, BuddyFlag flags) : m_id(id), m_flags(flags), m_rosterManager(rosterManager),
 
	m_subscription(Ask) {
 
}
 

	
 
Buddy::~Buddy() {
 
}
 

	
 
void Buddy::sendPresence() {
 
	std::vector<Swift::Presence::ref> &presences = generatePresenceStanzas(255);
 
	BOOST_FOREACH(Swift::Presence::ref presence, presences) {
 
		m_rosterManager->getUser()->getComponent()->getFrontend()->sendPresence(presence);
 
	}
 
}
 

	
 
void Buddy::generateJID() {
 
	m_jid = Swift::JID();
 
	m_jid = Swift::JID(getSafeName(), m_rosterManager->getUser()->getComponent()->getJID().toString(), "bot");
 
	m_jid = Swift::JID(getSafeName(), m_rosterManager->getUser()->getComponent()->getJID().toString(), JID_DEFAULT_RESOURCE);
 
}
 

	
 
void Buddy::setID(long id) {
 
	m_id = id;
 
}
 

	
 
long Buddy::getID() {
 
	return m_id;
 
}
 

	
 
void Buddy::setFlags(BuddyFlag flags) {
 
	m_flags = flags;
 

	
 
	if (!getSafeName().empty()) {
 
		try {
 
			generateJID();
 
		} catch (...) {
 
		}
 
	}
 
}
 

	
 
BuddyFlag Buddy::getFlags() {
 
	return m_flags;
 
}
libtransport/Conversation.cpp
Show inline comments
 
@@ -220,51 +220,55 @@ void Conversation::handleMessage(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Mes
 
		if (!m_mucEscaping && legacyName.find_last_of("@") != std::string::npos) {
 
			legacyName.replace(legacyName.find_last_of("@"), 1, "%"); // OK
 
		}
 
		legacyName = Swift::JID::getEscapedNode(legacyName);
 

	
 
		std::string n = nickname;
 
		if (n.empty()) {
 
			n = " ";
 
		}
 

	
 
		std::map<std::string, Participant>::iterator it = m_participants.find(n);
 
		if (it != m_participants.end() && !it->second.alias.empty()) {
 
			n = it->second.alias;
 
		}
 

	
 
		message->setFrom(Swift::JID(legacyName, m_conversationManager->getComponent()->getJID().toBare(), n));
 
		LOG4CXX_INFO(logger, "MSG FROM " << message->getFrom().toString());
 
	}
 

	
 

	
 
	if (carbon) {
 
#ifdef SWIFTEN_SUPPORTS_CARBONS
 
		LOG4CXX_INFO(logger, "CARBON MSG");
 
		//Swap from and to
 
		Swift::JID from = message->getFrom();
 
		message->setFrom(message->getTo());
 
		message->setTo(from);
 
		Swift::JID from = message->getTo();
 
		if (from.getResource().empty()) {
 
		    //If no resource is specified, set the same that is used for legacy network contacts
 
		    from = Swift::JID(from.getNode(), from.getDomain(), JID_DEFAULT_RESOURCE);
 
		}
 
		message->setTo(message->getFrom());
 
		message->setFrom(from);
 

	
 
		//Carbons should be sent to every resource directly.
 
		//Even if we tried to send to bare jid, the server would at best route it
 
		//as it would normal message (usually to the highest priority resource),
 
		//but won't produce carbons to other resources as it does with normal messages.
 
		Component* transport = this->getConversationManager()->getComponent();
 
		std::vector<Swift::Presence::ref> presences = transport->getPresenceOracle()->getAllPresence(this->m_jid.toBare());
 
		if (presences.empty()) {
 
			LOG4CXX_INFO(logger, "No presences for JID " << this->m_jid.toString()
 
			    << ", will send to bare JID for archival.");
 
			this->forwardAsCarbonSent(message, this->m_jid.toBare());
 
		} else
 
		BOOST_FOREACH(const Swift::Presence::ref &it, presences) {
 
			this->forwardAsCarbonSent(message, it->getFrom());
 
		}
 
#else //!SWIFTEN_SUPPORTS_CARBONS
 
		//Ignore the message.
 
#endif
 
	} else {
 
		handleRawMessage(message);
 
	}
 
}
 

	
 
void Conversation::forwardAsCarbonSent(
0 comments (0 inline, 0 general)