Implement glooxwrapper::MUCRoom argument for muc event handlers.
I.e. don't dereference NULL if the user of the glooxwrapper library reads from the provided room argument. A step towards being able to use XmppClient with multiple rooms. Differential Revision: https://code.wildfiregames.com/D2287 Tested on: clang 8.0.1, Jenkins This was SVN commit r22898.
This commit is contained in:
parent
a84e2e57df
commit
cab920696c
@ -316,8 +316,9 @@ bool XmppClient::onTLSConnect(const glooxwrapper::CertInfo& info)
|
||||
/**
|
||||
* Handle MUC room errors
|
||||
*/
|
||||
void XmppClient::handleMUCError(glooxwrapper::MUCRoom*, gloox::StanzaError err)
|
||||
void XmppClient::handleMUCError(glooxwrapper::MUCRoom& UNUSED(room), gloox::StanzaError err)
|
||||
{
|
||||
DbgXMPP("MUC Error " << ": " << StanzaErrorToString(err));
|
||||
CreateGUIMessage("system", "error", std::time(nullptr), "text", err);
|
||||
}
|
||||
|
||||
@ -742,7 +743,7 @@ void XmppClient::SendMUCMessage(const std::string& message)
|
||||
/**
|
||||
* Handle a room message.
|
||||
*/
|
||||
void XmppClient::handleMUCMessage(glooxwrapper::MUCRoom*, const glooxwrapper::Message& msg, bool priv)
|
||||
void XmppClient::handleMUCMessage(glooxwrapper::MUCRoom& UNUSED(room), const glooxwrapper::Message& msg, bool priv)
|
||||
{
|
||||
DbgXMPP(msg.from().resource() << " said " << msg.body());
|
||||
|
||||
@ -862,7 +863,7 @@ bool XmppClient::handleIq(const glooxwrapper::IQ& iq)
|
||||
/**
|
||||
* Update local data when a user changes presence.
|
||||
*/
|
||||
void XmppClient::handleMUCParticipantPresence(glooxwrapper::MUCRoom*, const glooxwrapper::MUCRoomParticipant participant, const glooxwrapper::Presence& presence)
|
||||
void XmppClient::handleMUCParticipantPresence(glooxwrapper::MUCRoom& UNUSED(room), const glooxwrapper::MUCRoomParticipant participant, const glooxwrapper::Presence& presence)
|
||||
{
|
||||
const glooxwrapper::string& nick = participant.nick->resource();
|
||||
|
||||
@ -981,7 +982,7 @@ void XmppClient::handleMUCParticipantPresence(glooxwrapper::MUCRoom*, const gloo
|
||||
/**
|
||||
* Update local cache when subject changes.
|
||||
*/
|
||||
void XmppClient::handleMUCSubject(glooxwrapper::MUCRoom*, const glooxwrapper::string& nick, const glooxwrapper::string& subject)
|
||||
void XmppClient::handleMUCSubject(glooxwrapper::MUCRoom& UNUSED(room), const glooxwrapper::string& nick, const glooxwrapper::string& subject)
|
||||
{
|
||||
m_Subject = wstring_from_utf8(subject.to_string());
|
||||
|
||||
|
@ -113,10 +113,10 @@ public:
|
||||
protected:
|
||||
/* Xmpp handlers */
|
||||
/* MUC handlers */
|
||||
virtual void handleMUCParticipantPresence(glooxwrapper::MUCRoom*, const glooxwrapper::MUCRoomParticipant, const glooxwrapper::Presence&);
|
||||
virtual void handleMUCError(glooxwrapper::MUCRoom*, gloox::StanzaError);
|
||||
virtual void handleMUCMessage(glooxwrapper::MUCRoom* room, const glooxwrapper::Message& msg, bool priv);
|
||||
virtual void handleMUCSubject(glooxwrapper::MUCRoom*, const glooxwrapper::string& nick, const glooxwrapper::string& subject);
|
||||
virtual void handleMUCParticipantPresence(glooxwrapper::MUCRoom& room, const glooxwrapper::MUCRoomParticipant, const glooxwrapper::Presence&);
|
||||
virtual void handleMUCError(glooxwrapper::MUCRoom& room, gloox::StanzaError);
|
||||
virtual void handleMUCMessage(glooxwrapper::MUCRoom& room, const glooxwrapper::Message& msg, bool priv);
|
||||
virtual void handleMUCSubject(glooxwrapper::MUCRoom& room, const glooxwrapper::string& nick, const glooxwrapper::string& subject);
|
||||
/* MUC handlers not supported by glooxwrapper */
|
||||
// virtual bool handleMUCRoomCreation(glooxwrapper::MUCRoom*) {return false;}
|
||||
// virtual void handleMUCInviteDecline(glooxwrapper::MUCRoom*, const glooxwrapper::JID&, const std::string&) {}
|
||||
|
@ -121,8 +121,9 @@ public:
|
||||
|
||||
virtual ~MUCRoomHandlerWrapper() {}
|
||||
|
||||
virtual void handleMUCParticipantPresence(gloox::MUCRoom* UNUSED(room), const gloox::MUCRoomParticipant participant, const gloox::Presence& presence)
|
||||
virtual void handleMUCParticipantPresence(gloox::MUCRoom* room, const gloox::MUCRoomParticipant participant, const gloox::Presence& presence)
|
||||
{
|
||||
glooxwrapper::MUCRoom roomWrapper(room, false);
|
||||
glooxwrapper::MUCRoomParticipant part;
|
||||
glooxwrapper::JID nick(*participant.nick);
|
||||
glooxwrapper::JID jid(*participant.jid);
|
||||
@ -139,8 +140,7 @@ public:
|
||||
part.status = participant.status;
|
||||
part.alternate = participant.alternate ? &alternate : NULL;
|
||||
|
||||
/* MUCRoom not supported */
|
||||
m_Wrapped->handleMUCParticipantPresence(NULL, part, glooxwrapper::Presence(presence.presence()));
|
||||
m_Wrapped->handleMUCParticipantPresence(roomWrapper, part, glooxwrapper::Presence(presence.presence()));
|
||||
|
||||
/* gloox 1.0 leaks some JIDs (fixed in 1.0.1), so clean them up */
|
||||
#if GLOOXVERSION == 0x10000
|
||||
@ -150,12 +150,11 @@ public:
|
||||
#endif
|
||||
}
|
||||
|
||||
virtual void handleMUCMessage(gloox::MUCRoom* UNUSED(room), const gloox::Message& msg, bool priv)
|
||||
virtual void handleMUCMessage(gloox::MUCRoom* room, const gloox::Message& msg, bool priv)
|
||||
{
|
||||
glooxwrapper::MUCRoom roomWrapper(room, false);
|
||||
glooxwrapper::Message msgWrapper(const_cast<gloox::Message*>(&msg), false);
|
||||
|
||||
/* MUCRoom not supported */
|
||||
m_Wrapped->handleMUCMessage(NULL, msgWrapper, priv);
|
||||
m_Wrapped->handleMUCMessage(roomWrapper, msgWrapper, priv);
|
||||
}
|
||||
|
||||
virtual bool handleMUCRoomCreation(gloox::MUCRoom* UNUSED(room))
|
||||
@ -164,10 +163,10 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual void handleMUCSubject(gloox::MUCRoom* UNUSED(room), const std::string& nick, const std::string& subject)
|
||||
virtual void handleMUCSubject(gloox::MUCRoom* room, const std::string& nick, const std::string& subject)
|
||||
{
|
||||
/* MUCRoom not supported */
|
||||
m_Wrapped->handleMUCSubject(NULL, nick, subject);
|
||||
glooxwrapper::MUCRoom roomWrapper(room, false);
|
||||
m_Wrapped->handleMUCSubject(roomWrapper, nick, subject);
|
||||
}
|
||||
|
||||
virtual void handleMUCInviteDecline(gloox::MUCRoom* UNUSED(room), const gloox::JID& UNUSED(invitee), const std::string& UNUSED(reason))
|
||||
@ -175,10 +174,10 @@ public:
|
||||
/* Not supported */
|
||||
}
|
||||
|
||||
virtual void handleMUCError(gloox::MUCRoom* UNUSED(room), gloox::StanzaError error)
|
||||
virtual void handleMUCError(gloox::MUCRoom* room, gloox::StanzaError error)
|
||||
{
|
||||
/* MUCRoom not supported */
|
||||
m_Wrapped->handleMUCError(NULL, error);
|
||||
glooxwrapper::MUCRoom roomWrapper(room, false);
|
||||
m_Wrapped->handleMUCError(roomWrapper, error);
|
||||
}
|
||||
|
||||
virtual void handleMUCInfo(gloox::MUCRoom* UNUSED(room), int UNUSED(features), const std::string& UNUSED(name), const gloox::DataForm* UNUSED(infoForm))
|
||||
@ -579,16 +578,23 @@ const glooxwrapper::DelayedDelivery* glooxwrapper::Message::when() const
|
||||
return new glooxwrapper::DelayedDelivery(wrapped);
|
||||
}
|
||||
|
||||
glooxwrapper::MUCRoom::MUCRoom(gloox::MUCRoom* room, bool owned)
|
||||
: m_Wrapped(room), m_Owned(owned), m_HandlerWrapper(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
glooxwrapper::MUCRoom::MUCRoom(Client* parent, const JID& nick, MUCRoomHandler* mrh, MUCRoomConfigHandler* UNUSED(mrch))
|
||||
{
|
||||
m_HandlerWrapper = new MUCRoomHandlerWrapper(mrh);
|
||||
m_Wrapped = new gloox::MUCRoom(parent ? parent->getWrapped() : NULL, nick.getWrapped(), m_HandlerWrapper);
|
||||
m_Owned = true;
|
||||
}
|
||||
|
||||
glooxwrapper::MUCRoom::~MUCRoom()
|
||||
{
|
||||
delete m_Wrapped;
|
||||
if (m_Owned)
|
||||
delete m_Wrapped;
|
||||
|
||||
delete m_HandlerWrapper;
|
||||
}
|
||||
|
||||
@ -597,6 +603,16 @@ const glooxwrapper::string glooxwrapper::MUCRoom::nick() const
|
||||
return m_Wrapped->nick();
|
||||
}
|
||||
|
||||
const glooxwrapper::string glooxwrapper::MUCRoom::name() const
|
||||
{
|
||||
return m_Wrapped->name();
|
||||
}
|
||||
|
||||
const glooxwrapper::string glooxwrapper::MUCRoom::service() const
|
||||
{
|
||||
return m_Wrapped->service();
|
||||
}
|
||||
|
||||
void glooxwrapper::MUCRoom::join(gloox::Presence::PresenceType type, const string& status, int priority)
|
||||
{
|
||||
m_Wrapped->join(type, status.to_string(), priority);
|
||||
|
@ -361,10 +361,10 @@ namespace glooxwrapper
|
||||
{
|
||||
public:
|
||||
virtual ~MUCRoomHandler() {}
|
||||
virtual void handleMUCParticipantPresence(MUCRoom* room, const MUCRoomParticipant participant, const Presence& presence) = 0; // MUCRoom not supported
|
||||
virtual void handleMUCMessage(MUCRoom* room, const Message& msg, bool priv) = 0; // MUCRoom not supported
|
||||
virtual void handleMUCError(MUCRoom* room, gloox::StanzaError error) = 0; // MUCRoom not supported
|
||||
virtual void handleMUCSubject(MUCRoom* room, const string& nick, const string& subject) = 0; // MUCRoom not supported
|
||||
virtual void handleMUCParticipantPresence(MUCRoom& room, const MUCRoomParticipant participant, const Presence& presence) = 0;
|
||||
virtual void handleMUCMessage(MUCRoom& room, const Message& msg, bool priv) = 0;
|
||||
virtual void handleMUCError(MUCRoom& room, gloox::StanzaError error) = 0;
|
||||
virtual void handleMUCSubject(MUCRoom& room, const string& nick, const string& subject) = 0;
|
||||
};
|
||||
|
||||
class GLOOXWRAPPER_API RegistrationHandler
|
||||
@ -526,10 +526,14 @@ namespace glooxwrapper
|
||||
private:
|
||||
gloox::MUCRoom* m_Wrapped;
|
||||
MUCRoomHandlerWrapper* m_HandlerWrapper;
|
||||
bool m_Owned;
|
||||
public:
|
||||
MUCRoom(gloox::MUCRoom* room, bool owned);
|
||||
MUCRoom(Client* parent, const JID& nick, MUCRoomHandler* mrh, MUCRoomConfigHandler* mrch = 0);
|
||||
~MUCRoom();
|
||||
const string nick() const;
|
||||
const string name() const;
|
||||
const string service() const;
|
||||
void join(gloox::Presence::PresenceType type = gloox::Presence::Available, const string& status = "", int priority = 0);
|
||||
void leave(const string& msg = "");
|
||||
void send(const string& message);
|
||||
|
Loading…
Reference in New Issue
Block a user