From 605b58c9379ab60f97b6e7edda40c59dd9f3cb4b Mon Sep 17 00:00:00 2001 From: daleharvey Date: Wed, 26 Jul 2006 16:30:34 +0000 Subject: [PATCH] Refactoring Session Establishment --- src/jabber_whiteboard/Makefile_insert | 1 + src/jabber_whiteboard/defines.cpp | 74 +++++++++++++++++++++ src/jabber_whiteboard/defines.h | 23 ++++--- src/jabber_whiteboard/inkboard-document.cpp | 2 +- src/jabber_whiteboard/session-manager.cpp | 23 +++---- src/jabber_whiteboard/session-manager.h | 3 +- 6 files changed, 102 insertions(+), 24 deletions(-) create mode 100644 src/jabber_whiteboard/defines.cpp diff --git a/src/jabber_whiteboard/Makefile_insert b/src/jabber_whiteboard/Makefile_insert index e3966086e..252ec4980 100644 --- a/src/jabber_whiteboard/Makefile_insert +++ b/src/jabber_whiteboard/Makefile_insert @@ -9,6 +9,7 @@ jabber_whiteboard/clean: rm -f jabber_whiteboard/libjabber_whiteboard.a $(jabber_whiteboard_libjabber_whiteboard_a_OBJECTS) jabber_whiteboard_SOURCES = \ + jabber_whiteboard/defines.cpp \ jabber_whiteboard/defines.h \ jabber_whiteboard/empty.cpp \ jabber_whiteboard/keynode.cpp \ diff --git a/src/jabber_whiteboard/defines.cpp b/src/jabber_whiteboard/defines.cpp new file mode 100644 index 000000000..7e06cd625 --- /dev/null +++ b/src/jabber_whiteboard/defines.cpp @@ -0,0 +1,74 @@ +/** + * Whiteboard session manager + * Definitions + * + * Authors: + * Dale Harvey + * + * Copyright (c) 2006 Authors + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifndef __INKSCAPE_WHITEBOARD_DEFINES_CPP__ +#define __INKSCAPE_WHITEBOARD_DEFINES_CPP__ + +#include "jabber_whiteboard/defines.h" + +namespace Inkscape { + +namespace Whiteboard { + +char const * const MessageString[] = { + // image and internal data + "CHANGE_NOT_REPEATABLE", + "CHANGE_REPEATABLE", + "DUMMY_CHANGE", + "CHANGE_COMMIT", + "DOCUMENT_BEGIN", + "DOCUMENT_END", + + // 1-1 connections + "connect-request", + "CONNECT_REQUEST_RESPONSE_USER", + // chat connections + "CONNECT_REQUEST_RESPONSE_CHAT", + + // chatroom document synchronization + "CHATROOM_SYNCHRONIZE_REQUEST", + "CHATROOM_SYNCHRONIZE_RESPONSE", + + // requests + "DOCUMENT_SENDER_REQUEST", + "DOCUMENT_SENDER_REQUEST_RESPONSE", + "DOCUMENT_REQUEST", + + // notifications + "CONNECTED_SIGNAL", + "DISCONNECTED_FROM_USER_SIGNAL", + + // error responses + "CONNECT_REQUEST_REFUSED_BY_PEER", + "UNSUPPORTED_PROTOCOL_VERSION", + "ALREADY_IN_SESSION", + + // error cases, i.e. garbled messages or bad clients. These should + // never actually be transmitted + "UNKNOWN" +}; + +} +} + +#endif + +/* + 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 : diff --git a/src/jabber_whiteboard/defines.h b/src/jabber_whiteboard/defines.h index afed3338f..587e29376 100644 --- a/src/jabber_whiteboard/defines.h +++ b/src/jabber_whiteboard/defines.h @@ -24,37 +24,44 @@ namespace Whiteboard { // explicitly numbered to aid protocol description later on enum MessageType { // image and internal data - CHANGE_NOT_REPEATABLE = 0, + CHANGE_NOT_REPEATABLE = 0, CHANGE_REPEATABLE = 1, DUMMY_CHANGE = 2, CHANGE_COMMIT = 3, DOCUMENT_BEGIN = 4, DOCUMENT_END = 5, + // 1-1 connections CONNECT_REQUEST_USER = 6, CONNECT_REQUEST_RESPONSE_USER = 7, // chat connections -CONNECT_REQUEST_RESPONSE_CHAT = 8, - // chatroom document synchronization + CONNECT_REQUEST_RESPONSE_CHAT = 8, + + // chatroom document synchronization CHATROOM_SYNCHRONIZE_REQUEST = 9, CHATROOM_SYNCHRONIZE_RESPONSE = 10, + // requests - DOCUMENT_SENDER_REQUEST = 11, + DOCUMENT_SENDER_REQUEST = 11, DOCUMENT_SENDER_REQUEST_RESPONSE = 12, DOCUMENT_REQUEST = 13, + // notifications - CONNECTED_SIGNAL = 14, + CONNECTED_SIGNAL = 14, DISCONNECTED_FROM_USER_SIGNAL = 15, - // error responses + + // error responses CONNECT_REQUEST_REFUSED_BY_PEER = 16, UNSUPPORTED_PROTOCOL_VERSION = 17, ALREADY_IN_SESSION = 18, - // error cases, i.e. garbled messages or bad clients. These should - // never actually be transmitted + // error cases, i.e. garbled messages or bad clients. These should + // never actually be transmitted UNKNOWN = 21 }; +extern char const * const MessageString[]; + // Responses to whiteboard invitations enum InvitationResponses { ACCEPT_INVITATION, diff --git a/src/jabber_whiteboard/inkboard-document.cpp b/src/jabber_whiteboard/inkboard-document.cpp index a3881af39..c7e86a527 100644 --- a/src/jabber_whiteboard/inkboard-document.cpp +++ b/src/jabber_whiteboard/inkboard-document.cpp @@ -58,7 +58,7 @@ InkboardDocument::startSessionNegotiation() break; case INKBOARD_PRIVATE: default: - sm.send(_recipient, CONNECT_REQUEST_USER, " "); + sm.sendProtocol(_recipient, CONNECT_REQUEST_USER); break; } } diff --git a/src/jabber_whiteboard/session-manager.cpp b/src/jabber_whiteboard/session-manager.cpp index 36bf3615b..3c982c4df 100644 --- a/src/jabber_whiteboard/session-manager.cpp +++ b/src/jabber_whiteboard/session-manager.cpp @@ -29,6 +29,7 @@ #include "jabber_whiteboard/session-manager.h" #include "jabber_whiteboard/inkboard-document.h" #include "jabber_whiteboard/new-inkboard-document.h" +#include "jabber_whiteboard/defines.h" #include "jabber_whiteboard/dialog/choose-desktop.h" @@ -108,30 +109,26 @@ SessionManager::send(const Glib::ustring &destJid, bool SessionManager::sendProtocol(const Glib::ustring &destJid, - const MessageType type, - const Glib::ustring &data) + const MessageType type) { - Pedro::DOMString xmlData = Pedro::Parser::encode(data); char *fmt= - "" - "%s" - "" + "" + "" + "" + "<%s />" + "" + "" ""; if (!getClient().write(fmt, getClient().getJid().c_str(), destJid.c_str(), - getClient().getMsgId(), INKBOARD_XMLNS, - 2, - (MessageType)type, - getSequenceNumber(), - xmlData.c_str() + MessageString[type] )) { return false; } - + return true; } diff --git a/src/jabber_whiteboard/session-manager.h b/src/jabber_whiteboard/session-manager.h index 0a2c22f55..b07b64906 100644 --- a/src/jabber_whiteboard/session-manager.h +++ b/src/jabber_whiteboard/session-manager.h @@ -79,8 +79,7 @@ public: * */ virtual bool sendProtocol(const Glib::ustring &destJid, - const MessageType type, - const Glib::ustring &data); + const MessageType type); /** * -- 2.30.2