Changeset - c83fd4c4b188
[Not reviewed]
0 5 0
Jan Kaluza - 10 years ago 2015-11-11 08:01:19
jkaluza@redhat.com
Support only libcommuni >= 3.0.0
5 files changed with 23 insertions and 38 deletions:
0 comments (0 inline, 0 general)
CMakeLists.txt
Show inline comments
 
@@ -337,25 +337,25 @@ if (PROTOBUF_FOUND)
 

	
 
	if (HAVE_EVENT)
 
		ADD_DEFINITIONS(-DWITH_LIBEVENT)
 
		include_directories(${EVENT_INCLUDE_DIRS})
 
		message("  libev eventloop : yes")
 
	else()
 
		if(ENABLE_PURPLE)
 
			message("  libev eventloop : no (install libev-devel)")
 
		endif()
 
	endif()
 

	
 
	if(IRC_FOUND)
 
		ADD_DEFINITIONS(-DCOMMUNI_SHARED)
 
		ADD_DEFINITIONS(-DIRC_SHARED)
 
		message("IRC plugin        : yes")
 
		include_directories(${QT_QTNETWORK_INCLUDE_DIR})
 
		include_directories(${IRC_INCLUDE_DIR})
 
		include(${QT_USE_FILE})
 
	else()
 
		if(ENABLE_IRC)
 
			message("IRC plugin        : no (install libCommuni and libprotobuf-dev)")
 
		else(ENABLE_IRC)
 
			message("IRC plugin        : no (user disabled)")
 
		endif()
 
	endif()
 
	if(ENABLE_TWITTER)
backends/libcommuni/session.cpp
Show inline comments
 
@@ -14,41 +14,38 @@
 
 * 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
 
 */
 

	
 
#include "session.h"
 
#include <QtCore>
 
#include <iostream>
 
#include <IrcCommand>
 
#include <IrcMessage>
 
#if COMMUNI_VERSION < 0x020000
 
#include <IrcUtil>
 
#endif
 
#include "backports.h"
 

	
 
#include "ircnetworkplugin.h"
 

	
 
#define FROM_UTF8(WHAT) QString::fromUtf8((WHAT).c_str(), (WHAT).size())
 
#define TO_UTF8(WHAT) std::string((WHAT).toUtf8().data(), (WHAT).toUtf8().size())
 

	
 
#include "transport/logging.h"
 

	
 
DEFINE_LOGGER(logger, "IRCSession");
 
DEFINE_LOGGER(logger, "IRCConnection");
 

	
 
static bool sentList;
 

	
 
MyIrcSession::MyIrcSession(const std::string &user, IRCNetworkPlugin *np, const std::string &suffix, QObject* parent) : IrcSession(parent)
 
MyIrcSession::MyIrcSession(const std::string &user, IRCNetworkPlugin *np, const std::string &suffix, QObject* parent) : IrcConnection(parent)
 
{
 
	this->np = np;
 
	this->user = user;
 
	this->suffix = suffix;
 
	m_connected = false;
 
	rooms = 0;
 
	connect(this, SIGNAL(disconnected()), SLOT(on_disconnected()));
 
	connect(this, SIGNAL(socketError(QAbstractSocket::SocketError)), SLOT(on_socketError(QAbstractSocket::SocketError)));
 
	connect(this, SIGNAL(connected()), SLOT(on_connected()));
 
	connect(this, SIGNAL(messageReceived(IrcMessage*)), this, SLOT(onMessageReceived(IrcMessage*)));
 

	
 
	m_awayTimer = new QTimer(this);
 
@@ -128,59 +125,59 @@ bool MyIrcSession::correctNickname(std::string &nickname) {
 
			case '+': nickname = nickname.substr(1); break;
 
			case '~': nickname = nickname.substr(1); break;
 
			case '&': nickname = nickname.substr(1); break;
 
			case '%': nickname = nickname.substr(1); break;
 
			default: break;
 
		}
 
	}
 
	return flags;
 
}
 

	
 
void MyIrcSession::on_joined(IrcMessage *message) {
 
	IrcJoinMessage *m = (IrcJoinMessage *) message;
 
	std::string nickname = TO_UTF8(m->sender().name());
 
	std::string nickname = TO_UTF8(m->nick());
 
	bool op = correctNickname(nickname);
 
	getIRCBuddy(TO_UTF8(m->channel().toLower()), nickname).setOp(op);
 
	np->handleParticipantChanged(user, nickname, TO_UTF8(m->channel().toLower()) + suffix, op, pbnetwork::STATUS_ONLINE);
 
	LOG4CXX_INFO(logger, user << ": " << nickname << " joined " << TO_UTF8(m->channel().toLower()) + suffix);
 
}
 

	
 

	
 
void MyIrcSession::on_parted(IrcMessage *message) {
 
	IrcPartMessage *m = (IrcPartMessage *) message;
 
	std::string nickname = TO_UTF8(m->sender().name());
 
	std::string nickname = TO_UTF8(m->nick());
 
	bool op = correctNickname(nickname);
 
	removeIRCBuddy(TO_UTF8(m->channel().toLower()), nickname);
 
	LOG4CXX_INFO(logger, user << ": " << nickname << " parted " << TO_UTF8(m->channel().toLower()) + suffix);
 
	np->handleParticipantChanged(user, nickname, TO_UTF8(m->channel().toLower()) + suffix, op, pbnetwork::STATUS_NONE, TO_UTF8(m->reason()));
 
}
 

	
 
void MyIrcSession::on_quit(IrcMessage *message) {
 
	IrcQuitMessage *m = (IrcQuitMessage *) message;
 
	std::string nickname = TO_UTF8(m->sender().name());
 
	std::string nickname = TO_UTF8(m->nick());
 
	bool op = correctNickname(nickname);
 

	
 
	for(AutoJoinMap::iterator it = m_autoJoin.begin(); it != m_autoJoin.end(); it++) {
 
		if (!hasIRCBuddy(it->second->getChannel(), nickname)) {
 
			continue;
 
		}
 
		removeIRCBuddy(it->second->getChannel(), nickname);
 
		LOG4CXX_INFO(logger, user << ": " << nickname << " quit " << it->second->getChannel() + suffix);
 
		np->handleParticipantChanged(user, nickname, it->second->getChannel() + suffix, op, pbnetwork::STATUS_NONE, TO_UTF8(m->reason()));
 
	}
 
}
 

	
 
void MyIrcSession::on_nickChanged(IrcMessage *message) {
 
	IrcNickMessage *m = (IrcNickMessage *) message;
 
	std::string nickname = TO_UTF8(m->sender().name());
 
	std::string nickname = TO_UTF8(m->nick());
 
	correctNickname(nickname);
 

	
 
	for(AutoJoinMap::iterator it = m_autoJoin.begin(); it != m_autoJoin.end(); it++) {
 
		if (!hasIRCBuddy(it->second->getChannel(), nickname)) {
 
			continue;
 
		}
 
		IRCBuddy &buddy = getIRCBuddy(it->second->getChannel(), nickname);
 
		LOG4CXX_INFO(logger, user << ": " << nickname << " changed nickname to " << TO_UTF8(m->nick()));
 
		np->handleParticipantChanged(user, nickname, it->second->getChannel() + suffix,(int) buddy.isOp(), pbnetwork::STATUS_ONLINE, "", TO_UTF8(m->nick()));
 
	}
 
}
 

	
 
@@ -205,65 +202,65 @@ void MyIrcSession::on_modeChanged(IrcMessage *message) {
 
	else {
 
		buddy.setOp(false);
 
	}
 
	
 
	np->handleParticipantChanged(user, nickname, TO_UTF8(m->target().toLower()) + suffix,(int) buddy.isOp(), pbnetwork::STATUS_ONLINE, "");
 

	
 
	LOG4CXX_INFO(logger, user << ": " << nickname << " changed mode to " << mode << " in " << TO_UTF8(m->target().toLower()));
 
}
 

	
 
void MyIrcSession::on_topicChanged(IrcMessage *message) {
 
	IrcTopicMessage *m = (IrcTopicMessage *) message;
 

	
 
	std::string nickname = TO_UTF8(m->sender().name());
 
	std::string nickname = TO_UTF8(m->nick());
 
	correctNickname(nickname);
 

	
 
	LOG4CXX_INFO(logger, user << ": " << nickname << " topic changed to " << TO_UTF8(m->topic()));
 
	np->handleSubject(user, TO_UTF8(m->channel().toLower()) + suffix, TO_UTF8(m->topic()), nickname);
 
}
 

	
 
void MyIrcSession::on_messageReceived(IrcMessage *message) {
 
	IrcPrivateMessage *m = (IrcPrivateMessage *) message;
 
	if (m->isRequest()) {
 
		QString request = m->message().split(" ", QString::SkipEmptyParts).value(0).toUpper();
 
		QString request = m->content().split(" ", QString::SkipEmptyParts).value(0).toUpper();
 
		if (request == "PING" || request == "TIME" || request == "VERSION") {
 
			LOG4CXX_INFO(logger, user << ": " << TO_UTF8(request) << " received and has been answered");
 
			return;
 
		}
 
	}
 

	
 
	QString msg = m->message();
 
	QString msg = m->content();
 
	if (m->isAction()) {
 
		msg = QString("/me ") + msg;
 
	}
 
	QString html = "";//msg;
 
	CommuniBackport::toPlainText(msg);
 

	
 
	// TODO: Communi produces invalid html now...
 
// 	if (html == msg) {
 
// 		html = "";
 
// 	}
 
// 	else {
 
// 		html = IrcUtil::messageToHtml(html);
 
// 	}
 

	
 
	std::string target = TO_UTF8(m->target().toLower());
 
	LOG4CXX_INFO(logger, user << ": Message from " << target);
 
	if (target.find("#") == 0) {
 
		std::string nickname = TO_UTF8(m->sender().name());
 
		std::string nickname = TO_UTF8(m->nick());
 
		correctNickname(nickname);
 
		np->handleMessage(user, target + suffix, TO_UTF8(msg), nickname, TO_UTF8(html));
 
	}
 
	else {
 
		std::string nickname = TO_UTF8(m->sender().name());
 
		std::string nickname = TO_UTF8(m->nick());
 
		correctNickname(nickname);
 
		if (m_pms.find(nickname) != m_pms.end()) {
 
			if (hasIRCBuddy(m_pms[nickname], nickname)) {
 
				LOG4CXX_INFO(logger, nickname);
 
				np->handleMessage(user, m_pms[nickname] + suffix, TO_UTF8(msg), nickname, TO_UTF8(html), "", false, true);
 
				return;
 
			}
 
			else {
 
				nickname = nickname + suffix;
 
			}
 
		}
 
		else {
 
@@ -384,37 +381,37 @@ void MyIrcSession::on_numericMessageReceived(IrcMessage *message) {
 

	
 
void MyIrcSession::awayTimeout() {
 
	for(AutoJoinMap::iterator it = m_autoJoin.begin(); it != m_autoJoin.end(); it++) {
 
		if (it->second->shouldAskWho()) {
 
			LOG4CXX_INFO(logger, "The time has come. Asking /who " << it->second->getChannel() << " again to get current away states.");
 
			sendCommand(IrcCommand::createWho(FROM_UTF8(it->second->getChannel())));
 
		}
 
	}
 
}
 

	
 
void MyIrcSession::on_noticeMessageReceived(IrcMessage *message) {
 
	IrcNoticeMessage *m = (IrcNoticeMessage *) message;
 
	LOG4CXX_INFO(logger, user << ": NOTICE " << TO_UTF8(m->message()));
 
	LOG4CXX_INFO(logger, user << ": NOTICE " << TO_UTF8(m->content()));
 

	
 
	QString msg = m->message();
 
	QString msg = m->content();
 
	CommuniBackport::toPlainText(msg);
 

	
 
	std::string target = TO_UTF8(m->target().toLower());
 
	if (target.find("#") == 0) {
 
		std::string nickname = TO_UTF8(m->sender().name());
 
		std::string nickname = TO_UTF8(m->nick());
 
		correctNickname(nickname);
 
		np->handleMessage(user, target + suffix, TO_UTF8(msg), nickname);
 
	}
 
	else {
 
		std::string nickname = TO_UTF8(m->sender().name());
 
		std::string nickname = TO_UTF8(m->nick());
 
		correctNickname(nickname);
 
		if (nickname.find(".") != std::string::npos) {
 
			return;
 
		}
 
		if (m_pms.find(nickname) != m_pms.end()) {
 
			if (hasIRCBuddy(m_pms[nickname], nickname)) {
 
				LOG4CXX_INFO(logger, nickname);
 
				np->handleMessage(user, m_pms[nickname] + suffix, TO_UTF8(msg), nickname, "", "", false, true);
 
				return;
 
			}
 
			else {
 
				nickname = nickname + suffix;
backends/libcommuni/session.h
Show inline comments
 
@@ -13,36 +13,36 @@
 
 * 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
 
 */
 

	
 
#ifndef SESSION_H
 
#define SESSION_H
 

	
 
#ifndef Q_MOC_RUN
 
#include <IrcSession>
 
#include <IrcConnection>
 
#include <transport/networkplugin.h>
 
#include "Swiften/Swiften.h"
 
#include <boost/smart_ptr/make_shared.hpp>
 
#include <QTimer>
 
#endif
 

	
 
using namespace Transport;
 

	
 
class IRCNetworkPlugin;
 

	
 
class MyIrcSession : public IrcSession
 
class MyIrcSession : public IrcConnection
 
{
 
    Q_OBJECT
 

	
 
public:
 
	class AutoJoinChannel {
 
		public:
 
			AutoJoinChannel(const std::string &channel = "", const std::string &password = "", int awayCycle = 12) : m_channel(channel), m_password(password),
 
				m_awayCycle(awayCycle), m_currentAwayTick(0) {}
 
			virtual ~AutoJoinChannel() {}
 

	
 
			const std::string &getChannel() { return m_channel; }
 
			const std::string &getPassword() { return m_password; }
cmake_modules/CommuniConfig.cmake
Show inline comments
 
find_package(Qt4)
 
include( ${QT_USE_FILE} )
 

	
 
FIND_LIBRARY(IRC_LIBRARY NAMES Communi PATHS ${QT_LIBRARY_DIR})
 
FIND_PATH(IRC_INCLUDE_DIR NAMES "ircglobal.h" PATHS ${QT_INCLUDE_DIR} PATH_SUFFIXES Communi)
 
FIND_LIBRARY(IRC_LIBRARY NAMES IrcCore PATHS ${QT_LIBRARY_DIR})
 
FIND_PATH(IRC_INCLUDE_DIR NAMES "IrcCore/ircglobal.h" PATHS ${QT_INCLUDE_DIR} PATH_SUFFIXES Communi)
 

	
 
# message( STATUS ${IRC_LIBRARY})
 
if( IRC_LIBRARY AND IRC_INCLUDE_DIR )
 
	set(IRC_INCLUDE_DIR ${IRC_INCLUDE_DIR}/IrcCore ${IRC_INCLUDE_DIR}/IrcUtil ${IRC_INCLUDE_DIR}/IrcModel)
 
	message( STATUS "Found libCommuni ${IRC_LIBRARY}, ${IRC_INCLUDE_DIR}")
 
	set( IRC_FOUND 1 )
 
else()
 
	message( STATUS "Could NOT find libCommuni" )
 
endif()
packaging/fedora/spectrum2.spec
Show inline comments
 
@@ -16,25 +16,25 @@ BuildRequires: cppunit-devel
 
%if 0%{?rhel} > 0 && 0%{?rhel} <= 6
 
BuildRequires: sqlite-devel
 
%else
 
BuildRequires: libsqlite3x-devel
 
%endif
 
BuildRequires: protobuf-devel
 
BuildRequires: protobuf-compiler
 
BuildRequires: popt-devel
 
BuildRequires: libidn-devel
 
BuildRequires: expat-devel
 
BuildRequires: avahi-devel
 
BuildRequires: log4cxx-devel
 
#BuildRequires: swiften-devel
 
BuildRequires: swiften-devel
 
BuildRequires: libcommuni-devel
 
Requires:      libtransport%{?_isa} = %{version}-%{release}
 

	
 
%description
 
Spectrum 2 is an XMPP transport/gateway and also simple XMPP server.
 

	
 
%prep
 
%setup -q -n spectrum2
 

	
 
%build
 
%cmake . -DCMAKE_BUILD_TYPE=Debug
 
make VERBOSE=1 %{?_smp_mflags}
 
@@ -49,25 +49,25 @@ install -p -D -m 755 packaging/fedora/spectrum2.init \
 
ln -s /usr/bin/spectrum2_libpurple_backend %{buildroot}/usr/bin/spectrum_libpurple_backend
 

	
 
%pre
 
getent group %{groupname} >/dev/null || groupadd -r %{groupname}
 
getent passwd %{username} >/dev/null || \
 
    useradd -r -g %{groupname} -d %{_localstatedir}/lib/spectrum \
 
        -s /sbin/nologin \
 
        -c "spectrum XMPP transport" %{username}
 
exit 0
 

	
 
%files
 
%defattr(-, root, root,-)
 
%doc README
 
%doc README.md
 
%{_bindir}/spectrum2
 
%{_bindir}/spectrum2_manager
 
/etc/spectrum2/*
 
%{_initddir}/spectrum2
 
%attr(700, %{username}, %{groupname}) %{_localstatedir}/lib/spectrum2/
 
%attr(700, %{username}, %{groupname}) %{_localstatedir}/run/spectrum2/
 
%attr(700, %{username}, %{groupname}) %{_localstatedir}/log/spectrum2/
 

	
 
%package libpurple-backend
 
Summary:    Libtransport
 
Group:      Development/Libraries
 
Requires:   boost
 
@@ -126,37 +126,24 @@ Spectrum2 Skype backend
 
Summary:    Libtransport
 
Group:      Development/Libraries
 
Requires:   boost
 
Requires:   libtransport%{?_isa} = %{version}-%{release}
 

	
 
%description swiften-backend
 
Spectrum2 Swiften backend
 

	
 
%files swiften-backend
 
%defattr(-, root, root,-)
 
/usr/bin/spectrum2_swiften_backend
 

	
 
%package libyahoo2-backend
 
Summary:    Libtransport
 
Group:      Development/Libraries
 
Requires:   boost
 
Requires:   libtransport%{?_isa} = %{version}-%{release}
 

	
 
%description libyahoo2-backend
 
Spectrum2 libyahoo2 backend
 

	
 
%files libyahoo2-backend
 
%defattr(-, root, root,-)
 
/usr/bin/spectrum2_libyahoo2_backend
 

	
 
%package twitter-backend
 
Summary:    Libtransport
 
Group:      Development/Libraries
 
Requires:   boost
 
Requires:   libtransport%{?_isa} = %{version}-%{release}
 

	
 
%description twitter-backend
 
Spectrum2 libyahoo2 backend
 

	
 
%files twitter-backend
 
%defattr(-, root, root,-)
 
/usr/bin/spectrum2_twitter_backend
0 comments (0 inline, 0 general)