Files @ 07ee87c60d2d
Branch filter:

Location: libtransport.git/include/transport/Conversation.h

Andrey Utkin
Define 'foreach' in backends/libcommuni/session.cpp

Fixes compilation issue

[ 64%] Building CXX object backends/libcommuni/CMakeFiles/spectrum2_libcommuni_backend.dir/session.cpp.o
cd /var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni && /usr/bin/x86_64-pc-linux-gnu-g++ -DBOOST_FILESYSTEM_VERSION=3 -DDEBUG -DIRC_SHARED -DPURPLE_RUNTIME=0 -DQT_CORE_LIB -DQT_NETWORK_LIB -DQT_NO_KEYWORDS -DSPECTRUM_VERSION=\"2.0.5-git-b15fcedf\" -DSUPPORT_LEGACY_CAPS -DWITH_LIBEVENT -DWITH_LOG4CXX -DWITH_PQXX -DWITH_PROTOBUF -isystem /usr/include/qt4 -isystem /usr/include/qt4/QtCore -I/usr/include/libpurple -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -isystem /usr/include/qt4/QtNetwork -I/usr/include/qt4/Communi/IrcCore -I/usr/include/qt4/Communi/IrcUtil -I/usr/include/qt4/Communi/IrcModel -I/var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/include -isystem /usr/share/qt4/mkspecs/default -DBOOST_SIGNALS_NO_DEPRECATION_WARNING -O2 -pipe -O0 -ggdb -o CMakeFiles/spectrum2_libcommuni_backend.dir/session.cpp.o -c /var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.cpp
/var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.cpp: In member function ‘void MyIrcSession::on_socketError(QAbstractSocket::SocketError)’:
/var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.cpp:208:22: error: expected primary-expression before ‘*’ token
foreach (IrcBuffer *buffer, m_bufferModel->buffers()) {
^
/var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.cpp:208:23: error: ‘buffer’ was not declared in this scope
foreach (IrcBuffer *buffer, m_bufferModel->buffers()) {
^~~~~~
/var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.cpp:208:23: note: suggested alternative:
In file included from /usr/include/boost/asio/detail/reactive_socket_service.hpp:22:0,
from /usr/include/boost/asio/socket_acceptor_service.hpp:29,
from /usr/include/boost/asio/basic_socket_acceptor.hpp:25,
from /usr/include/boost/asio/ip/tcp.hpp:19,
from /usr/include/Swiften/Network/HostAddressPort.h:9,
from /usr/include/Swiften/Elements/S5BProxyRequest.h:22,
from /usr/include/Swiften/Parser/PayloadParsers/S5BProxyRequestParser.h:18,
from /usr/include/Swiften/Swiften.h:112,
from /var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.h:30,
from /var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.cpp:21:
/usr/include/boost/asio/buffer.hpp:1231:24: note: ‘boost::asio::buffer’
inline const_buffers_1 buffer(
^~~~~~
/var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.cpp:208:55: error: ‘foreach’ was not declared in this scope
ch (IrcBuffer *buffer, m_bufferModel->buffers()) {
^
/var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.cpp:208:55: note: suggested alternative:
In file included from /usr/include/boost/foreach.hpp:86:0,
from /var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/include/transport/Config.h:24,
from /var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/ircnetworkplugin.h:27,
from /var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.cpp:30:
/usr/include/boost/foreach_fwd.hpp:26:11: note: ‘boost::foreach’
namespace foreach
^~~~~~~
/var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.cpp: In member function ‘void MyIrcSession::on_namesMessageReceived(IrcMessage*)’:
/var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.cpp:348:19: error: expected primary-expression before ‘*’ token
foreach (IrcUser *user, userModel->users()) {
^
/var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.cpp:348:20: error: ‘user’ was not declared in this scope
foreach (IrcUser *user, userModel->users()) {
^~~~
/var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.cpp:348:44: error: ‘foreach’ was not declared in this scope
foreach (IrcUser *user, userModel->users()) {
^
/var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.cpp:348:44: note: suggested alternative:
In file included from /usr/include/boost/foreach.hpp:86:0,
from /var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/include/transport/Config.h:24,
from /var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/ircnetworkplugin.h:27,
from /var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.cpp:30:
/usr/include/boost/foreach_fwd.hpp:26:11: note: ‘boost::foreach’
namespace foreach
^~~~~~~
/var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.cpp: In member function ‘void MyIrcSession::sendMessageToFrontend(const string&, const string&, const string&)’:
/var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.cpp:387:23: error: expected primary-expression before ‘*’ token
foreach (IrcBuffer *buffer, m_bufferModel->buffers()) {
^
/var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.cpp:387:24: error: ‘buffer’ was not declared in this scope
foreach (IrcBuffer *buffer, m_bufferModel->buffers()) {
^~~~~~
/var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.cpp:387:24: note: suggested alternative:
In file included from /usr/include/boost/asio/detail/reactive_socket_service.hpp:22:0,
from /usr/include/boost/asio/socket_acceptor_service.hpp:29,
from /usr/include/boost/asio/basic_socket_acceptor.hpp:25,
from /usr/include/boost/asio/ip/tcp.hpp:19,
from /usr/include/Swiften/Network/HostAddressPort.h:9,
from /usr/include/Swiften/Elements/S5BProxyRequest.h:22,
from /usr/include/Swiften/Parser/PayloadParsers/S5BProxyRequestParser.h:18,
from /usr/include/Swiften/Swiften.h:112,
from /var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.h:30,
from /var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.cpp:21:
/usr/include/boost/asio/buffer.hpp:1231:24: note: ‘boost::asio::buffer’
inline const_buffers_1 buffer(
^~~~~~
/var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.cpp:387:56: error: ‘foreach’ was not declared in this scope
ch (IrcBuffer *buffer, m_bufferModel->buffers()) {
^
/var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.cpp:387:56: note: suggested alternative:
In file included from /usr/include/boost/foreach.hpp:86:0,
from /var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/include/transport/Config.h:24,
from /var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/ircnetworkplugin.h:27,
from /var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.cpp:30:
/usr/include/boost/foreach_fwd.hpp:26:11: note: ‘boost::foreach’
namespace foreach
^~~~~~~
/var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.cpp: In member function ‘void MyIrcSession::on_numericMessageReceived(IrcMessage*)’:
/var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.cpp:465:23: error: expected primary-expression before ‘*’ token
foreach (IrcBuffer *buffer, m_bufferModel->buffers()) {
^
/var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.cpp:465:24: error: ‘buffer’ was not declared in this scope
foreach (IrcBuffer *buffer, m_bufferModel->buffers()) {
^~~~~~
/var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.cpp:465:24: note: suggested alternative:
In file included from /usr/include/boost/asio/detail/reactive_socket_service.hpp:22:0,
from /usr/include/boost/asio/socket_acceptor_service.hpp:29,
from /usr/include/boost/asio/basic_socket_acceptor.hpp:25,
from /usr/include/boost/asio/ip/tcp.hpp:19,
from /usr/include/Swiften/Network/HostAddressPort.h:9,
from /usr/include/Swiften/Elements/S5BProxyRequest.h:22,
from /usr/include/Swiften/Parser/PayloadParsers/S5BProxyRequestParser.h:18,
from /usr/include/Swiften/Swiften.h:112,
from /var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.h:30,
from /var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.cpp:21:
/usr/include/boost/asio/buffer.hpp:1231:24: note: ‘boost::asio::buffer’
inline const_buffers_1 buffer(
^~~~~~
/var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.cpp:465:56: error: ‘foreach’ was not declared in this scope
ch (IrcBuffer *buffer, m_bufferModel->buffers()) {
^
/var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.cpp:465:56: note: suggested alternative:
In file included from /usr/include/boost/foreach.hpp:86:0,
from /var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/include/transport/Config.h:24,
from /var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/ircnetworkplugin.h:27,
from /var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.cpp:30:
/usr/include/boost/foreach_fwd.hpp:26:11: note: ‘boost::foreach’
namespace foreach
^~~~~~~
/var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.cpp:490:23: error: expected primary-expression before ‘*’ token
foreach (IrcBuffer *buffer, m_bufferModel->buffers()) {
^
/var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.cpp: In member function ‘void MyIrcSession::awayTimeout()’:
/var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.cpp:523:21: error: expected primary-expression before ‘*’ token
foreach (IrcBuffer *buffer, m_bufferModel->buffers()) {
^
/var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.cpp:523:22: error: ‘buffer’ was not declared in this scope
foreach (IrcBuffer *buffer, m_bufferModel->buffers()) {
^~~~~~
/var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.cpp:523:22: note: suggested alternative:
In file included from /usr/include/boost/asio/detail/reactive_socket_service.hpp:22:0,
from /usr/include/boost/asio/socket_acceptor_service.hpp:29,
from /usr/include/boost/asio/basic_socket_acceptor.hpp:25,
from /usr/include/boost/asio/ip/tcp.hpp:19,
from /usr/include/Swiften/Network/HostAddressPort.h:9,
from /usr/include/Swiften/Elements/S5BProxyRequest.h:22,
from /usr/include/Swiften/Parser/PayloadParsers/S5BProxyRequestParser.h:18,
from /usr/include/Swiften/Swiften.h:112,
from /var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.h:30,
from /var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.cpp:21:
/usr/include/boost/asio/buffer.hpp:1231:24: note: ‘boost::asio::buffer’
inline const_buffers_1 buffer(
^~~~~~
/var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.cpp:523:54: error: ‘foreach’ was not declared in this scope
ch (IrcBuffer *buffer, m_bufferModel->buffers()) {
^
/var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.cpp:523:54: note: suggested alternative:
In file included from /usr/include/boost/foreach.hpp:86:0,
from /var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/include/transport/Config.h:24,
from /var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/ircnetworkplugin.h:27,
from /var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999/backends/libcommuni/session.cpp:30:
/usr/include/boost/foreach_fwd.hpp:26:11: note: ‘boost::foreach’
namespace foreach
^~~~~~~
make[2]: *** [backends/libcommuni/CMakeFiles/spectrum2_libcommuni_backend.dir/build.make:126: backends/libcommuni/CMakeFiles/spectrum2_libcommuni_backend.dir/session.cpp.o] Error 1
make[2]: Leaving directory '/var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999'
make[1]: *** [CMakeFiles/Makefile2:646: backends/libcommuni/CMakeFiles/spectrum2_libcommuni_backend.dir/all] Error 2
make[1]: Leaving directory '/var/tmp/portage/net-im/spectrum-9999/work/spectrum-9999'
make: *** [Makefile:152: all] Error 2
/**
 * XMPP - libpurple transport
 *
 * 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 <list>
#include "Swiften/Elements/Message.h"
#include "Swiften/Elements/Presence.h"
#include "Swiften/SwiftenCompat.h"

namespace Transport {

class ConversationManager;

/// Represents one XMPP-Legacy network conversation.
class Conversation {
	public:
		typedef enum {
			PARTICIPANT_FLAG_NONE = 0,
			PARTICIPANT_FLAG_MODERATOR = 1,
			PARTICIPANT_FLAG_CONFLICT = 2,
			PARTICIPANT_FLAG_BANNED = 4,
			PARTICIPANT_FLAG_NOT_AUTHORIZED = 8,
			PARTICIPANT_FLAG_ME = 16,
			PARTICIPANT_FLAG_KICKED = 32,
			PARTICIPANT_FLAG_ROOM_NOT_FOUD = 64
		} ParticipantFlag;

		/// Creates new conversation.

		/// \param conversationManager ConversationManager associated with this Conversation.
		/// \param legacyName Legacy network name of recipient.
		/// \param muc True if this conversation is Multi-user chat.
		Conversation(ConversationManager *conversationManager, const std::string &legacyName, bool muc = false);

		/// Destructor.
		virtual ~Conversation();

		/// Returns legacy network name of this conversation.

		/// \return legacy network name of this conversation.
		const std::string &getLegacyName() { return m_legacyName; }

		/// Handles new message from Legacy network and forwards it to XMPP.

		/// \param message Message received from legacy network.
		/// \param nickname For MUC conversation this is nickname of room participant who sent this message.
		void handleMessage(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Message> &message, const std::string &nickname = "");

		void handleRawMessage(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Message> &message);
		void handleRawPresence(Swift::Presence::ref presence);

		/// Handles participant change in MUC.

		/// \param nickname Nickname of participant which changed.
		/// \param flag ParticipantFlag.
		/// \param status Current status of this participant.
		/// \param statusMessage Current status message of this participant.
		/// \param newname If participant was renamed, this variable contains his new name.
		void handleParticipantChanged(const std::string &nickname, ParticipantFlag flag, int status = Swift::StatusShow::None, const std::string &statusMessage = "", const std::string &newname = "", const std::string &iconhash = "", const std::string &alias = "");

		/// Sets XMPP user nickname in MUC rooms.

		/// \param nickname XMPP user nickname in MUC rooms.
		void setNickname(const std::string &nickname);

		const std::string &getNickname() {
			return m_nickname;
		}

		void setJID(const Swift::JID &jid) {
			m_jid = jid;
		}

		void addJID(const Swift::JID &jid) {
			m_jids.push_back(jid);
		}

		void clearJIDs() {
			m_jids.clear();
		}

		void removeJID(const Swift::JID &jid);

		const std::list<Swift::JID> &getJIDs() {
			return m_jids;
		}

		/// Sends message to Legacy network.

		/// \param message Message.
		virtual void sendMessage(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Message> &message) = 0;

		/// Returns ConversationManager associated with this Conversation.

		/// \return  ConversationManager associated with this Conversation.
		ConversationManager *getConversationManager() {
			return m_conversationManager;
		}

		/// Returns True if this conversation is MUC room.

		/// \return  True if this conversation is MUC room.
		bool isMUC() {
			return m_muc;
		}

		/// Sets room name associated with this Conversation.

		/// This is used to detect Private messages associated with particular room.
		/// \param room room name associated with this Conversation.
		void setRoom(const std::string &room);

		/// Returns room name associated with this Conversation.

		/// \return room name associated with this Conversation.
		const std::string &getRoom() {
			return m_room;
		}

		void destroyRoom();

		std::string getParticipants();
		void sendParticipants(const Swift::JID &to, const std::string &nickname);

		void sendCachedMessages(const Swift::JID &to = Swift::JID());

		void setMUCEscaping(bool mucEscaping);

	private:
		Swift::Presence::ref generatePresence(const std::string &nick, int flag, int status, const std::string &statusMessage, const std::string &newname = "", const std::string &iconhash = "");
		void cacheMessage(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Message> &message);

	private:
		ConversationManager *m_conversationManager;
		std::string m_legacyName;
		std::string m_nickname;
		std::string m_room;
		bool m_muc;
		Swift::JID m_jid;
		std::list<Swift::JID> m_jids;
		bool m_sentInitialPresence;
		bool m_nicknameChanged;
		bool m_mucEscaping;
		bool m_sentInitialSubject;

		// TODO: Move this to some extra class to cache the most used
		// rooms across different accounts. Just now if we have 10 users
		// connected to single room, we store all those things 10 times.
		// It would be also great to store last 100 messages per room
		// every time, so we can get history messages for IRC for example.
		SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Message> m_subject;
		std::list<SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Message> > m_cachedMessages;

		typedef struct {
			Swift::Presence::ref presence;
			std::string alias;
		} Participant;
		std::map<std::string, Participant> m_participants;
};

}