2010-05-27 20:04:31 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2010, Pier Luigi Fiorini. All rights reserved.
|
2021-06-13 01:16:30 -05:00
|
|
|
* Copyright 2021, Jaidyn Levesque. All rights reserved.
|
2010-05-27 20:04:31 -05:00
|
|
|
* Distributed under the terms of the GPL v2 License.
|
|
|
|
*/
|
2010-05-28 15:41:58 -05:00
|
|
|
#ifndef _JABBER_HANDLER_H
|
|
|
|
#define _JABBER_HANDLER_H
|
2010-05-27 20:04:31 -05:00
|
|
|
|
2010-05-30 13:57:19 -05:00
|
|
|
#include <Notification.h>
|
2010-05-29 23:26:36 -05:00
|
|
|
#include <Path.h>
|
2010-05-27 20:04:31 -05:00
|
|
|
#include <String.h>
|
2021-06-13 01:16:30 -05:00
|
|
|
#include <StringList.h>
|
2010-05-27 20:04:31 -05:00
|
|
|
|
2021-05-19 16:12:19 -05:00
|
|
|
#include <gloox/client.h>
|
|
|
|
#include <gloox/chatstatehandler.h>
|
|
|
|
#include <gloox/connectionlistener.h>
|
|
|
|
#include <gloox/connectiontcpclient.h>
|
|
|
|
#include <gloox/discohandler.h>
|
|
|
|
#include <gloox/disco.h>
|
|
|
|
#include <gloox/rostermanager.h>
|
|
|
|
#include <gloox/loghandler.h>
|
|
|
|
#include <gloox/logsink.h>
|
2021-06-01 21:53:50 -05:00
|
|
|
#include <gloox/message.h>
|
2021-06-08 19:59:22 -05:00
|
|
|
#include <gloox/messageeventhandler.h>
|
2021-05-19 16:12:19 -05:00
|
|
|
#include <gloox/messagehandler.h>
|
|
|
|
#include <gloox/messagesession.h>
|
|
|
|
#include <gloox/messagesessionhandler.h>
|
2021-06-08 19:59:22 -05:00
|
|
|
#include <gloox/mucinvitationhandler.h>
|
2021-06-01 21:53:50 -05:00
|
|
|
#include <gloox/mucroomconfighandler.h>
|
2021-06-08 19:59:22 -05:00
|
|
|
#include <gloox/mucroomhandler.h>
|
2021-05-19 16:12:19 -05:00
|
|
|
#include <gloox/presence.h>
|
|
|
|
#include <gloox/vcardhandler.h>
|
|
|
|
#include <gloox/vcardmanager.h>
|
2010-05-27 20:04:31 -05:00
|
|
|
|
2010-05-29 23:26:36 -05:00
|
|
|
#include <CayaProtocol.h>
|
|
|
|
#include <CayaConstants.h>
|
2021-06-15 14:40:28 -05:00
|
|
|
#include <ChatCommand.h>
|
2021-06-02 12:34:00 -05:00
|
|
|
#include <libsupport/KeyMap.h>
|
2010-05-29 23:26:36 -05:00
|
|
|
|
|
|
|
class BList;
|
2021-06-08 19:59:22 -05:00
|
|
|
class InviteHandler;
|
2010-05-27 20:04:31 -05:00
|
|
|
|
2021-06-02 12:34:00 -05:00
|
|
|
|
|
|
|
typedef KeyMap<BString, gloox::MUCRoom*> RoomMap;
|
|
|
|
|
|
|
|
|
2010-05-28 15:41:58 -05:00
|
|
|
class JabberHandler : public CayaProtocol, gloox::RosterListener, gloox::ConnectionListener,
|
2010-07-10 14:27:32 -05:00
|
|
|
gloox::LogHandler, gloox::MessageSessionHandler,
|
|
|
|
gloox::MessageHandler, gloox::MessageEventHandler,
|
2021-06-01 21:53:50 -05:00
|
|
|
gloox::ChatStateHandler, gloox::VCardHandler,
|
|
|
|
gloox::MUCRoomHandler, gloox::MUCRoomConfigHandler {
|
2010-05-27 20:04:31 -05:00
|
|
|
public:
|
2010-05-28 15:41:58 -05:00
|
|
|
JabberHandler();
|
|
|
|
virtual ~JabberHandler();
|
2010-05-27 20:04:31 -05:00
|
|
|
|
2010-05-30 15:50:04 -05:00
|
|
|
// CayaProtocol inheritance
|
2010-05-27 20:04:31 -05:00
|
|
|
virtual status_t Init(CayaProtocolMessengerInterface*);
|
|
|
|
|
|
|
|
virtual status_t Process(BMessage* msg);
|
|
|
|
|
|
|
|
virtual status_t Shutdown();
|
|
|
|
|
Allow multiple protocols per add-on
Now an add-on can contain multiple protocols, and the protocol API has
changed. An add-on must now export protocol_count() and protocol_at(),
with the latter replacing protocol(). protocol_count() returning the
amount of protocols in a given add-on, and protocol_at(i) giving a
new CayaProtocol* "at" the given index.
CayaProtocol has also been changed, adding Signature(),
FriendlySignature(), Icon(), Path(), and SetPath(). The reasoning is
that different protocols (even within a single add-on) will have
different signatures and icons, so this data should be accessible from
the protocol itself.
CayaProtocolAddOn now has CountProtocols() and ProtocolAt(i), allowing
the accessing of multiple protocols. A CayaProtocolAddOn can be given a
default protocol index in the constructor, whose protocol will be
returned with Protocol(). Version() was also moved from CayaProtocol to
CayaProtocolAddOn.
2021-05-21 13:33:43 -05:00
|
|
|
virtual const char* Signature() const = 0;
|
|
|
|
virtual const char* FriendlySignature() const = 0;
|
|
|
|
|
2021-06-01 21:53:50 -05:00
|
|
|
virtual void SetAddOnPath(BPath path);
|
|
|
|
virtual BPath AddOnPath();
|
|
|
|
|
|
|
|
virtual void SetName(const char* name);
|
|
|
|
virtual const char* GetName();
|
2010-05-27 20:04:31 -05:00
|
|
|
|
|
|
|
virtual status_t UpdateSettings(BMessage* msg);
|
|
|
|
|
2021-06-15 14:40:28 -05:00
|
|
|
virtual CommandMap Commands();
|
2010-05-27 20:04:31 -05:00
|
|
|
|
2021-06-15 14:40:28 -05:00
|
|
|
virtual uint32 GetEncoding();
|
2021-05-24 19:12:42 -05:00
|
|
|
|
2010-05-27 20:04:31 -05:00
|
|
|
virtual CayaProtocolMessengerInterface*
|
|
|
|
MessengerInterface() const;
|
|
|
|
|
2010-05-30 15:50:04 -05:00
|
|
|
// Functions for gloox
|
|
|
|
gloox::Client* Client() const;
|
2021-06-01 21:53:50 -05:00
|
|
|
void HandleConnectionError(gloox::ConnectionError& e);
|
|
|
|
void HandleStanzaError(gloox::StanzaError error);
|
2010-05-30 15:50:04 -05:00
|
|
|
|
|
|
|
// Callbacks for protocols
|
2010-05-28 15:41:58 -05:00
|
|
|
virtual void OverrideSettings() = 0;
|
|
|
|
virtual BString ComposeJID() const = 0;
|
|
|
|
|
|
|
|
protected:
|
2010-05-27 20:04:31 -05:00
|
|
|
BString fUsername;
|
2021-06-02 16:58:29 -05:00
|
|
|
BString fNick;
|
2010-05-27 20:04:31 -05:00
|
|
|
BString fPassword;
|
|
|
|
BString fServer;
|
|
|
|
BString fResource;
|
2010-05-30 07:17:59 -05:00
|
|
|
uint16 fPort;
|
2010-05-27 20:04:31 -05:00
|
|
|
|
Allow multiple protocols per add-on
Now an add-on can contain multiple protocols, and the protocol API has
changed. An add-on must now export protocol_count() and protocol_at(),
with the latter replacing protocol(). protocol_count() returning the
amount of protocols in a given add-on, and protocol_at(i) giving a
new CayaProtocol* "at" the given index.
CayaProtocol has also been changed, adding Signature(),
FriendlySignature(), Icon(), Path(), and SetPath(). The reasoning is
that different protocols (even within a single add-on) will have
different signatures and icons, so this data should be accessible from
the protocol itself.
CayaProtocolAddOn now has CountProtocols() and ProtocolAt(i), allowing
the accessing of multiple protocols. A CayaProtocolAddOn can be given a
default protocol index in the constructor, whose protocol will be
returned with Protocol(). Version() was also moved from CayaProtocol to
CayaProtocolAddOn.
2021-05-21 13:33:43 -05:00
|
|
|
BPath fPath;
|
2021-06-01 21:53:50 -05:00
|
|
|
BString fName;
|
Allow multiple protocols per add-on
Now an add-on can contain multiple protocols, and the protocol API has
changed. An add-on must now export protocol_count() and protocol_at(),
with the latter replacing protocol(). protocol_count() returning the
amount of protocols in a given add-on, and protocol_at(i) giving a
new CayaProtocol* "at" the given index.
CayaProtocol has also been changed, adding Signature(),
FriendlySignature(), Icon(), Path(), and SetPath(). The reasoning is
that different protocols (even within a single add-on) will have
different signatures and icons, so this data should be accessible from
the protocol itself.
CayaProtocolAddOn now has CountProtocols() and ProtocolAt(i), allowing
the accessing of multiple protocols. A CayaProtocolAddOn can be given a
default protocol index in the constructor, whose protocol will be
returned with Protocol(). Version() was also moved from CayaProtocol to
CayaProtocolAddOn.
2021-05-21 13:33:43 -05:00
|
|
|
|
2021-05-20 09:32:52 -05:00
|
|
|
BMessage _SettingsTemplate(const char* username, bool serverOption);
|
2010-05-28 15:41:58 -05:00
|
|
|
private:
|
2010-05-27 20:04:31 -05:00
|
|
|
CayaProtocolMessengerInterface*
|
|
|
|
fServerMessenger;
|
|
|
|
|
|
|
|
gloox::Client* fClient;
|
|
|
|
gloox::ConnectionTCPClient*
|
|
|
|
fConnection;
|
|
|
|
gloox::VCardManager* fVCardManager;
|
2010-07-10 14:27:32 -05:00
|
|
|
gloox::MessageSession* fSession;
|
2021-06-08 19:59:22 -05:00
|
|
|
InviteHandler* fInviteHandler;
|
2010-05-27 20:04:31 -05:00
|
|
|
|
2010-05-30 07:17:59 -05:00
|
|
|
gloox::JID fJid;
|
2010-05-28 15:41:58 -05:00
|
|
|
thread_id fRecvThread;
|
2021-06-13 01:16:30 -05:00
|
|
|
|
|
|
|
RoomMap fRooms; // Keylist of MUC rooms
|
|
|
|
BStringList fUserChats; // List of individual chats (non-gloox::MUCRooms)
|
2010-05-28 15:41:58 -05:00
|
|
|
|
2010-05-29 23:26:36 -05:00
|
|
|
BPath fCachePath;
|
|
|
|
BPath fAvatarCachePath;
|
|
|
|
BMessage fAvatarCache;
|
|
|
|
BList* fAvatars;
|
|
|
|
|
2010-05-30 07:30:47 -05:00
|
|
|
void _SendMessage(BMessage* msg);
|
2010-05-28 15:41:58 -05:00
|
|
|
void _MessageSent(const char* id, const char* subject,
|
2010-05-27 20:04:31 -05:00
|
|
|
const char* body);
|
2010-05-30 13:57:19 -05:00
|
|
|
|
2021-06-13 01:16:30 -05:00
|
|
|
void _JoinRoom(const char* chat_id);
|
2021-06-07 00:03:15 -05:00
|
|
|
void _ChatCreatedMsg(const char* id);
|
|
|
|
void _RoleChangedMsg(BString chat_id, BString user_id,
|
|
|
|
gloox::MUCRoomRole role, gloox::MUCRoomAffiliation aff);
|
|
|
|
void _UserLeftMsg(BString chat_id, gloox::MUCRoomParticipant participant);
|
|
|
|
void _StatusSetMsg(const char* user_id, gloox::Presence::PresenceType type,
|
|
|
|
const char* message, const char* resource);
|
2021-05-26 07:48:25 -05:00
|
|
|
|
2010-05-30 13:57:19 -05:00
|
|
|
void _Notify(notification_type type, const char* title, const char* message);
|
|
|
|
void _NotifyProgress(const char* title, const char* message, float progress);
|
2010-05-27 20:04:31 -05:00
|
|
|
|
2021-06-13 01:16:30 -05:00
|
|
|
void _EnsureUserChat(const char* chat_id);
|
|
|
|
|
2010-05-29 23:26:36 -05:00
|
|
|
status_t _SetupAvatarCache();
|
|
|
|
status_t _SaveAvatarCache();
|
|
|
|
void _CacheAvatar(const char* id, const char* binval, size_t length);
|
|
|
|
void _AvatarChanged(const char*id, const char* filename);
|
2010-05-30 07:30:47 -05:00
|
|
|
|
|
|
|
CayaStatus _GlooxStatusToCaya(gloox::Presence::PresenceType type);
|
2010-05-29 23:26:36 -05:00
|
|
|
|
2021-06-03 20:24:34 -05:00
|
|
|
BString _MUCChatId(gloox::MUCRoom* room);
|
|
|
|
bool _MUCUserId(BString chat_id, const char* nick, BString* id);
|
2021-06-06 16:31:25 -05:00
|
|
|
void _MUCModeration(BMessage* msg);
|
2021-06-03 14:25:51 -05:00
|
|
|
|
Support for "Roles" (user, moderator, admin, etc.)
Add scaffodling support for arbitrary roles and permission-based (and
varying!) UI.
A new class, Role, represents a user's role in a given room, with three
values:
* The role's title
* The role's permission-set
* The role's priority
The permission set is a bitmask value for various permissions (e.g.,
PERM_WRITE, PERM_BAN, etc), and priority is position in the hierarchy.
A user with higher priority (and PERM_BAN) can ban a user with lower
priority, but not vice-versa. Two users with the same priority can't
ban/kick/mute each other, etc.
These permissions should be used to determine what UI elements are
displayed― if the user doesn't have permission to ban users, then a
"Ban" button shouldn't exist. If the user is muted, they shouldn't be
able to type. So on and so forth.
For now, permissions are sent with a IM_ROLECHANGE message and stored
by the Conversation, but aren't really in use yet.
This system should be flexible groundwork to account for the varying
administrative hierarchies and norms of different protocols.
2021-06-06 00:41:45 -05:00
|
|
|
const char* _RoleTitle(gloox::MUCRoomRole role, gloox::MUCRoomAffiliation aff);
|
2021-06-06 01:49:11 -05:00
|
|
|
int32 _RolePerms(gloox::MUCRoomRole role, gloox::MUCRoomAffiliation aff);
|
|
|
|
int32 _RolePriority(gloox::MUCRoomRole role, gloox::MUCRoomAffiliation aff);
|
Support for "Roles" (user, moderator, admin, etc.)
Add scaffodling support for arbitrary roles and permission-based (and
varying!) UI.
A new class, Role, represents a user's role in a given room, with three
values:
* The role's title
* The role's permission-set
* The role's priority
The permission set is a bitmask value for various permissions (e.g.,
PERM_WRITE, PERM_BAN, etc), and priority is position in the hierarchy.
A user with higher priority (and PERM_BAN) can ban a user with lower
priority, but not vice-versa. Two users with the same priority can't
ban/kick/mute each other, etc.
These permissions should be used to determine what UI elements are
displayed― if the user doesn't have permission to ban users, then a
"Ban" button shouldn't exist. If the user is muted, they shouldn't be
able to type. So on and so forth.
For now, permissions are sent with a IM_ROLECHANGE message and stored
by the Conversation, but aren't really in use yet.
This system should be flexible groundwork to account for the varying
administrative hierarchies and norms of different protocols.
2021-06-06 00:41:45 -05:00
|
|
|
|
2010-05-27 20:04:31 -05:00
|
|
|
virtual void onConnect();
|
|
|
|
virtual void onDisconnect(gloox::ConnectionError);
|
|
|
|
virtual bool onTLSConnect(const gloox::CertInfo&);
|
|
|
|
virtual void onResourceBindError(const gloox::Error*);
|
|
|
|
virtual void handleRoster(const gloox::Roster&);
|
2010-07-10 14:27:32 -05:00
|
|
|
virtual void handleMessageSession(gloox::MessageSession* session);
|
|
|
|
virtual void handleMessage(const gloox::Message& m, gloox::MessageSession*);
|
|
|
|
virtual void handleMessageEvent(const gloox::JID& from, gloox::MessageEventType event);
|
|
|
|
virtual void handleChatState(const gloox::JID& from, gloox::ChatStateType state);
|
|
|
|
|
2021-06-01 21:53:50 -05:00
|
|
|
virtual void handleMUCParticipantPresence(gloox::MUCRoom* room,
|
|
|
|
const gloox::MUCRoomParticipant participant,
|
|
|
|
const gloox::Presence &presence);
|
2021-06-02 12:34:00 -05:00
|
|
|
virtual void handleMUCMessage(gloox::MUCRoom* room, const gloox::Message &m, bool priv);
|
2021-06-01 21:53:50 -05:00
|
|
|
virtual bool handleMUCRoomCreation(gloox::MUCRoom* room);
|
|
|
|
virtual void handleMUCSubject(gloox::MUCRoom* room, const std::string &nick,
|
|
|
|
const std::string &subject);
|
|
|
|
virtual void handleMUCInviteDecline(gloox::MUCRoom* room, const gloox::JID &invitee,
|
|
|
|
const std::string &reason);
|
|
|
|
virtual void handleMUCError(gloox::MUCRoom* room, gloox::StanzaError error);
|
|
|
|
virtual void handleMUCInfo(gloox::MUCRoom* room, int features, const std::string &name,
|
|
|
|
const gloox::DataForm* infoForm);
|
|
|
|
virtual void handleMUCItems(gloox::MUCRoom* room, const gloox::Disco::ItemList &items);
|
|
|
|
|
|
|
|
virtual void handleMUCConfigList(gloox::MUCRoom* room,
|
|
|
|
const gloox::MUCListItemList &items,
|
|
|
|
gloox::MUCOperation operation);
|
|
|
|
virtual void handleMUCConfigForm(gloox::MUCRoom* room, const gloox::DataForm &form);
|
|
|
|
virtual void handleMUCConfigResult(gloox::MUCRoom* room, bool success,
|
|
|
|
gloox::MUCOperation operation);
|
|
|
|
virtual void handleMUCRequest(gloox::MUCRoom* room, const gloox::DataForm &form);
|
|
|
|
|
2010-05-27 20:04:31 -05:00
|
|
|
virtual void handleItemAdded(const gloox::JID&);
|
|
|
|
virtual void handleItemSubscribed(const gloox::JID&);
|
|
|
|
virtual void handleItemUnsubscribed(const gloox::JID&);
|
|
|
|
virtual void handleItemRemoved(const gloox::JID&);
|
|
|
|
virtual void handleItemUpdated(const gloox::JID&);
|
|
|
|
virtual void handleRosterPresence(const gloox::RosterItem&,
|
|
|
|
const std::string&, gloox::Presence::PresenceType,
|
|
|
|
const std::string&);
|
|
|
|
virtual void handleSelfPresence(const gloox::RosterItem&, const std::string&,
|
|
|
|
gloox::Presence::PresenceType, const std::string&);
|
|
|
|
virtual bool handleSubscriptionRequest(const gloox::JID&, const std::string&);
|
|
|
|
virtual bool handleUnsubscriptionRequest(const gloox::JID&, const std::string&);
|
|
|
|
virtual void handleNonrosterPresence(const gloox::Presence&);
|
|
|
|
virtual void handleRosterError(const gloox::IQ&);
|
|
|
|
virtual void handleLog(gloox::LogLevel, gloox::LogArea, const std::string&);
|
|
|
|
virtual void handleVCard(const gloox::JID&, const gloox::VCard*);
|
|
|
|
virtual void handleVCardResult(gloox::VCardHandler::VCardContext,
|
2021-06-01 21:53:50 -05:00
|
|
|
const gloox::JID&, gloox::StanzaError);
|
2010-05-27 20:04:31 -05:00
|
|
|
};
|
|
|
|
|
2021-06-08 19:59:22 -05:00
|
|
|
|
|
|
|
class InviteHandler : public gloox::MUCInvitationHandler {
|
|
|
|
public:
|
|
|
|
InviteHandler(gloox::ClientBase* parent, JabberHandler* handler);
|
2021-06-13 01:16:30 -05:00
|
|
|
void handleMUCInvitation(const gloox::JID& room, const gloox::JID& from,
|
2021-06-08 19:59:22 -05:00
|
|
|
const std::string& reason, const std::string& body,
|
|
|
|
const std::string& password, bool cont,
|
|
|
|
const std::string& thread);
|
|
|
|
private:
|
|
|
|
JabberHandler* fHandler;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-05-28 15:41:58 -05:00
|
|
|
#endif // _JABBER_HANDLER_H
|
2021-06-08 19:59:22 -05:00
|
|
|
|