session-manager.cpp revision 535b1596de71acb960a629b0f34f0d2171a34348
/**
* Whiteboard session manager
*
* Authors:
* David Yip <yipdw@rose-hulman.edu>
* Bob Jamison (Pedro port)
*
* Copyright (c) 2005 Authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include <functional>
#include <algorithm>
#include <iostream>
#include <gtkmm.h>
#include "xml/node-observer.h"
#include "document.h"
#include "desktop.h"
#include "desktop-handles.h"
#include "jabber_whiteboard/message-verifier.h"
#include "jabber_whiteboard/session-manager.h"
#include "jabber_whiteboard/inkboard-document.h"
#include "jabber_whiteboard/new-inkboard-document.h"
#define INKBOARD_XMLNS "http://inkscape.org/inkboard"
namespace Inkscape {
namespace Whiteboard {
//#########################################################################
//# S E S S I O N M A N A G E R
//#########################################################################
void SessionManager::showClient()
{
}
{
if (!sessionManagerInstance)
sessionManagerInstance = new SessionManager();
return *sessionManagerInstance;
}
{
sequenceNumber = 0L;
getClient().addXmppEventListener(*this);
this->_check_pending_invitations = Glib::signal_timeout().connect(sigc::mem_fun(*this, &SessionManager::_checkInvitationQueue), 50);
this->_check_invitation_responses = Glib::signal_timeout().connect(sigc::mem_fun(*this, &SessionManager::_checkInvitationResponseQueue), 50);
}
{
getClient().removeXmppEventListener(*this);
getClient().disconnect();
}
unsigned long SessionManager::getSequenceNumber()
{
return sequenceNumber++;
}
bool
const MessageType type,
{
char *fmt=
"<message type='chat' from='%s' to='%s' id='ink_%d'>"
"<inkboard xmlns='%s' "
"protocol='%d' type='%d' seq='%d'><x:inkboard-data>%s</x:inkboard-data></inkboard>"
"<body></body>"
"</message>";
2,
))
{
return false;
}
return true;
}
bool
const MessageType type,
{
char *fmt=
"<message type='groupchat' from='%s' to='%s' id='ink_%d'>"
"<inkboard xmlns='%s' "
"protocol='%d' type='%d' seq='%d'><x:inkboard-data>%s</x:inkboard-data></inkboard>"
"<body></body>"
"</message>";
2,
type,
))
{
return false;
}
return true;
}
void
{
switch (type) {
{
break;
}
{
break;
}
{
break;
}
{
break;
}
{
if (root)
{
{
}
}
break;
}
{
break;
}
{
if (root)
{
{
}
}
break;
}
{
break;
}
{
break;
}
{
break;
}
default:
{
break;
}
}
}
/**
* Initiates a shared session with a user or conference room.
*
* \param to The recipient to which this desktop will be linked, specified as a JID.
* \param type Type of the session; i.e. private message or group chat.
*/
void
{
}
}
}
/**
* Clone of sp_file_new and all related subroutines and functions,
* with appropriate modifications to use the Inkboard document class.
*
* \param to The JID to which this Inkboard document will be connected.
* \return A pointer to the created desktop, or NULL if a new desktop could not be created.
*/
{
// Create document (sp_repr_document_new clone)
return NULL;
}
// Create desktop and attach document
return dt;
}
void
{
for(; i != _inkboards.end(); ++i) {
break;
}
}
if (i != _inkboards.end()) {
(*i).second->terminateSession();
_inkboards.erase(i);
}
}
{
for(; i != _inkboards.end(); ++i) {
return (*i).second;
}
}
return NULL;
}
void
{
g_warning("Received null DOM; ignoring message.");
return;
}
g_warning("Received incomplete Inkboard message (missing type, protocol, or sequence number); ignoring message.");
return;
}
// Messages that deal with the creation and destruction of sessions should be handled
// here in the SessionManager.
//
// These events are listed below, along with rationale.
//
// - CONNECT_REQUEST_USER: when we begin to process this message, we will not have an
// Inkboard session available to send the message to. Therefore, this message needs
// to be handled by the SessionManager.
//
// - CONNECT_REQUEST_REFUSED_BY_PEER: this message means that the recipient of a
// private invitation refused the invitation. In this case, we need to destroy the
// Inkboard desktop, document, and session associated with that invitation.
// Destruction of these components seems to be more naturally done in the SessionManager
// than in the Inkboard document itself (especially since the document may be associated
// with multiple desktops).
//
// - UNSUPPORTED_PROTOCOL_VERSION: this message means that the recipient of an invitation
// does not support the version of the Inkboard protocol we are using. In this case,
// we have to destroy the Inkboard desktop, document, and session associated with that
// invitation. The rationale for doing it in the SessionManager is the same as that
// given above.
//
// - ALREADY_IN_SESSION: similar rationale to above.
//
// - DISCONNECTED_FROM_USER_SIGNAL: similar rationale to above.
//
//
// All other events can be handled inside an Inkboard session.
// The message we are handling will have come from some Jabber ID. We need to verify
// that the Inkboard session associated with that JID is in the correct state for the
// incoming message (or, in some cases, that the session correctly exists / does not
// exist).
// NOTE: This line refers to a class that hasn't been written yet
// MessageValidityTestResult res = MessageVerifier::verifyMessageValidity(event, mtype, doc);
switch (res) {
case RESULT_VALID:
{
switch (mtype) {
case CONNECT_REQUEST_USER:
case ALREADY_IN_SESSION:
break;
break;
default:
}
break;
}
break;
}
case RESULT_INVALID:
default:
// FIXME: better warning message
g_warning("Received message in invalid context.");
break;
}
}
void
{
switch (mtype) {
case CONNECT_REQUEST_USER:
break;
break;
case ALREADY_IN_SESSION:
break;
break;
default:
break;
}
}
void
{
// don't insert duplicate invitations
if (std::find(_pending_invitations.begin(), _pending_invitations.end(), from) != _pending_invitations.end()) {
return;
}
// when this method is called, we're still executing in Pedro's context,
// which causes issues when we run a dialog main loop.
//
// The invitation handling is done in a poller timeout that executes approximately
// every 50ms. It calls _checkInvitationQueue.
}
void
{
// only handle one response per invitation sender
//
// TODO: this could have one huge bug: say that Alice sends an invite to Bob, but
// Bob is doing something else at the moment and doesn't want to get in an Inkboard
// session. Eve intercepts Bob's "reject invitation" message and passes a
// "accept invitation" message to Alice that comes before Bob's "reject invitation"
// message.
//
// Does XMPP prevent this sort of attack? Need to investigate that.
if (std::find_if(_invitation_responses.begin(), _invitation_responses.end(), CheckInvitationSender(from)) != _invitation_responses.end()) {
return;
}
// when this method is called, we're still executing in Pedro's context,
// which causes issues when we run a dialog main loop.
//
// The invitation handling is done in a poller timeout that executes approximately
// every 50ms. It calls _checkInvitationResponseQueue.
}
} // namespace Whiteboard
} // namespace Inkscape
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :