Support for joining MUCs; Stanza error-handling

Adds basic support for joining MUCs― so basic that Caya won't even tell
the user they've joined, and messages can't be received.

The scaffolding for further MUC development was added, and some
much-needed error-handling for stanzas has been created.
This commit is contained in:
Jaidyn Ann 2021-06-01 21:53:50 -05:00
parent 75de08a18b
commit 770f7eaee3
2 changed files with 239 additions and 12 deletions

View File

@ -18,6 +18,7 @@
#include <gloox/chatstatefilter.h>
#include <gloox/messageeventfilter.h>
#include <gloox/mucroom.h>
#include "JabberHandler.h"
@ -38,7 +39,7 @@ connect_thread(void* data)
while ((e = client->recv(10000000)) == gloox::ConnNoError);
if (e != gloox::ConnUserDisconnected)
handler->HandleError(e);
handler->HandleConnectionError(e);
return B_OK;
}
@ -133,6 +134,15 @@ JabberHandler::Process(BMessage* msg)
break;
}
case IM_JOIN_ROOM: {
BString chat_id = msg->FindString("chat_id");
chat_id << "/" << fUsername;
gloox::MUCRoom room(fClient, gloox::JID(chat_id.String()), this, this);
room.join();
break;
}
default:
return B_ERROR;
}
@ -157,19 +167,33 @@ JabberHandler::Shutdown()
void
JabberHandler::SetPath(BPath path)
JabberHandler::SetAddOnPath(BPath path)
{
fPath = path;
}
BPath
JabberHandler::Path()
JabberHandler::AddOnPath()
{
return fPath;
}
void
JabberHandler::SetName(const char* name)
{
fName = name;
}
const char*
JabberHandler::GetName()
{
return fName.String();
}
status_t
JabberHandler::UpdateSettings(BMessage* msg)
{
@ -246,7 +270,7 @@ JabberHandler::Client() const
void
JabberHandler::HandleError(gloox::ConnectionError& e)
JabberHandler::HandleConnectionError(gloox::ConnectionError& e)
{
// Handle error
BMessage errMsg(IM_ERROR);
@ -499,6 +523,96 @@ JabberHandler::HandleError(gloox::ConnectionError& e)
}
void
JabberHandler::HandleStanzaError(gloox::StanzaError error)
{
BMessage errMsg(IM_ERROR);
errMsg.AddString("error", "Stanza-related error");
BString detail;
switch (error)
{
case gloox::StanzaErrorBadRequest:
detail = "The sender has sent XML that is malformed or that cannot "
"be processed.";
break;
case gloox::StanzaErrorConflict:
detail = "Access cannot be granted because an existing resource or "
"session exists with the same name or address.";
break;
case gloox::StanzaErrorFeatureNotImplemented:
detail = "This feature hasn't been implemented by the recipient or "
"by the server.";
break;
case gloox::StanzaErrorForbidden:
detail = "You don't have permssion to do this.";
break;
case gloox::StanzaErrorGone:
detail = "The recipient or server can no longer be contacted at "
"this address. Try again later, or with a different address.";
break;
case gloox::StanzaErrorInternalServerError:
detail = "The server could not process the stanza because of a "
"misconfiguration or an otherwise-undefined internal server error.";
break;
case gloox::StanzaErrorItemNotFound:
detail = "The addressed JID or item requested cannot be found.";
break;
case gloox::StanzaErrorJidMalformed:
detail = "An invalid XMPP address or identifier was given. If you "
"can, please try a different one.";
break;
case gloox::StanzaErrorNotAcceptable:
detail = "The server or user refuses to accept this, because some "
"criteria hasn't been met (e.g., a local policy regarding "
"acceptable words in messages).";
break;
case gloox::StanzaErrorNotAllowed:
detail = "You aren't allowed to do this by the server or recepient.";
break;
case gloox::StanzaErrorNotAuthorized:
detail = "You need to be properily authenticated before doing this.";
case gloox::StanzaErrorNotModified:
detail = "The item requested has not changed since it was last "
"requested.";
case gloox::StanzaErrorPaymentRequired:
detail = "The server refuses to offer service, because payment is "
"required.";
break;
case gloox::StanzaErrorRecipientUnavailable:
detail = "The recipient is temporarily unavailable.";
break;
case gloox::StanzaErrorRedirect:
detail = "The recipient or server is redirecting requests for this "
"information to another entity, usually temporarily.";
break;
case gloox::StanzaErrorRegistrationRequired:
detail = "You can't do this before registration! Be sure your "
"finished registering for your account.";
break;
case gloox::StanzaErrorRemoteServerNotFound:
detail = "That user's server doesn't exist.";
break;
case gloox::StanzaErrorRemoteServerTimeout:
detail = "Connection to that user's server has timed out.";
break;
case gloox::StanzaErrorResourceConstraint:
detail = "The server or recipient are too busy right now; try "
"again later.";
break;
case gloox::StanzaErrorServiceUnavailable:
detail = "The server or recipient don't provide this service.";
break;
case gloox::StanzaErrorSubscribtionRequired:
detail = "You can't access this unless you are subscribed.";
break;
}
errMsg.AddString("detail", detail);
_SendMessage(&errMsg);
}
void
JabberHandler::_SendMessage(BMessage* msg)
{
@ -797,7 +911,7 @@ JabberHandler::onDisconnect(gloox::ConnectionError e)
}
// Handle error
HandleError(e);
HandleConnectionError(e);
}
@ -951,6 +1065,90 @@ printf("------ %d\n", state);
}
void
JabberHandler::handleMUCParticipantPresence(gloox::MUCRoom *room,
const gloox::MUCRoomParticipant participant,
const gloox::Presence &presence)
{
}
void
JabberHandler::handleMUCMessage(gloox::MUCRoom *room, const gloox::Message &msg,
bool priv)
{
}
bool
JabberHandler::handleMUCRoomCreation(gloox::MUCRoom *room)
{
return true;
}
void
JabberHandler::handleMUCSubject(gloox::MUCRoom *room, const std::string &nick,
const std::string &subject)
{
}
void
JabberHandler::handleMUCInviteDecline(gloox::MUCRoom *room, const gloox::JID &invitee,
const std::string &reason)
{
}
void
JabberHandler::handleMUCError(gloox::MUCRoom *room, gloox::StanzaError error)
{
HandleStanzaError(error);
}
void
JabberHandler::handleMUCInfo(gloox::MUCRoom *room, int features,
const std::string &name, const gloox::DataForm *infoForm)
{
}
void
JabberHandler::handleMUCItems(gloox::MUCRoom *room, const gloox::Disco::ItemList &items)
{
}
void
JabberHandler::handleMUCConfigList(gloox::MUCRoom* room, const gloox::MUCListItemList &items,
gloox::MUCOperation operation)
{
}
void
JabberHandler::handleMUCConfigForm(gloox::MUCRoom* room, const gloox::DataForm &form)
{
}
void
JabberHandler::handleMUCConfigResult(gloox::MUCRoom* room, bool success,
gloox::MUCOperation operation)
{
}
void
JabberHandler::handleMUCRequest(gloox::MUCRoom* room, const gloox::DataForm &form)
{
}
void
JabberHandler::handleItemAdded(const gloox::JID&)
{

View File

@ -18,11 +18,13 @@
#include <gloox/rostermanager.h>
#include <gloox/loghandler.h>
#include <gloox/logsink.h>
#include <gloox/message.h>
#include <gloox/messagehandler.h>
#include <gloox/messagesession.h>
#include <gloox/messagesessionhandler.h>
#include <gloox/messageeventhandler.h>
#include <gloox/message.h>
#include <gloox/mucroomhandler.h>
#include <gloox/mucroomconfighandler.h>
#include <gloox/presence.h>
#include <gloox/vcardhandler.h>
#include <gloox/vcardmanager.h>
@ -35,7 +37,8 @@ class BList;
class JabberHandler : public CayaProtocol, gloox::RosterListener, gloox::ConnectionListener,
gloox::LogHandler, gloox::MessageSessionHandler,
gloox::MessageHandler, gloox::MessageEventHandler,
gloox::ChatStateHandler, gloox::VCardHandler {
gloox::ChatStateHandler, gloox::VCardHandler,
gloox::MUCRoomHandler, gloox::MUCRoomConfigHandler {
public:
JabberHandler();
virtual ~JabberHandler();
@ -50,8 +53,11 @@ public:
virtual const char* Signature() const = 0;
virtual const char* FriendlySignature() const = 0;
virtual void SetPath(BPath path);
virtual BPath Path();
virtual void SetAddOnPath(BPath path);
virtual BPath AddOnPath();
virtual void SetName(const char* name);
virtual const char* GetName();
virtual status_t UpdateSettings(BMessage* msg);
@ -64,7 +70,8 @@ public:
// Functions for gloox
gloox::Client* Client() const;
void HandleError(gloox::ConnectionError& e);
void HandleConnectionError(gloox::ConnectionError& e);
void HandleStanzaError(gloox::StanzaError error);
// Callbacks for protocols
virtual void OverrideSettings() = 0;
@ -78,6 +85,7 @@ protected:
uint16 fPort;
BPath fPath;
BString fName;
BMessage _SettingsTemplate(const char* username, bool serverOption);
private:
@ -125,6 +133,28 @@ private:
virtual void handleMessageEvent(const gloox::JID& from, gloox::MessageEventType event);
virtual void handleChatState(const gloox::JID& from, gloox::ChatStateType state);
virtual void handleMUCParticipantPresence(gloox::MUCRoom* room,
const gloox::MUCRoomParticipant participant,
const gloox::Presence &presence);
virtual void handleMUCMessage(gloox::MUCRoom* room, const gloox::Message &msg, bool priv);
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);
virtual void handleItemAdded(const gloox::JID&);
virtual void handleItemSubscribed(const gloox::JID&);
virtual void handleItemUnsubscribed(const gloox::JID&);
@ -142,8 +172,7 @@ private:
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,
const gloox::JID&,
gloox::StanzaError);
const gloox::JID&, gloox::StanzaError);
};
#endif // _JABBER_HANDLER_H