• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

AccountHandler.h

Go to the documentation of this file.
00001 /* Copyright (C) 2006 by Marc Maurer <uwog@uwog.net>
00002  *
00003  * This program is free software; you can redistribute it and/or
00004  * modify it under the terms of the GNU General Public License
00005  * as published by the Free Software Foundation; either version 2
00006  * of the License, or (at your option) any later version.
00007  *
00008  * This program is distributed in the hope that it will be useful,
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  * GNU General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * along with this program; if not, write to the Free Software
00015  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00016  * 02110-1301 USA.
00017  */
00018 
00019 #ifndef __ACCOUNTHANDLER_H__
00020 #define __ACCOUNTHANDLER_H__
00021 
00022 #include <map>
00023 #include <string>
00024 #include <list>
00025 #include <vector>
00026 #include "ut_types.h"
00027 #include "ut_string_class.h"
00028 #include "ut_vector.h"
00029 #include "DocHandle.h"
00030 #include <packet/xp/AbiCollab_Packet.h>
00031 #include <account/xp/Buddy.h>
00032 #include <account/xp/EventListener.h>
00033 #ifdef _WIN32
00034 #define WIN32_LEAN_AND_MEAN
00035 #include <windows.h>
00036 #endif
00037 
00038 class AbiCollab;
00039 
00040 typedef enum _ConnectResult
00041 {
00042     CONNECT_SUCCESS = 0,
00043     CONNECT_FAILED,
00044     CONNECT_IN_PROGRESS,
00045     CONNECT_AUTHENTICATION_FAILED,
00046     CONNECT_ALREADY_CONNECTED,
00047     CONNECT_INTERNAL_ERROR
00048 } ConnectResult;
00049 
00050 typedef AccountHandler* (*AccountHandlerConstructor)();
00051 
00052 typedef std::map<std::string, std::string> PropertyMap;
00053 
00054 class ProtocolErrorPacket : public Packet
00055 {
00056 public:
00057     ProtocolErrorPacket();
00058     ProtocolErrorPacket( UT_sint32 errorEnum );
00059     DECLARE_PACKET(ProtocolErrorPacket);
00060 
00061     virtual UT_sint32                       getProtocolVersion() const
00062         { return 0; } // not ABICOLLAB_PROTOCOL_VERSION!!
00063     UT_sint32                               getErrorEnum() const
00064         { return m_errorEnum; }
00065     UT_sint32                               getRemoteVersion() const
00066         { return m_remoteVersion; }
00067 protected:
00068     UT_sint32       m_errorEnum;
00069     UT_sint32       m_remoteVersion;
00070 };
00071 
00072 class AccountHandler : public EventListener
00073 {
00074 public:
00075     AccountHandler() {}
00076     virtual ~AccountHandler() {}
00077 
00078     // housekeeping
00079     static UT_UTF8String                    getStaticStorageType()
00080         { /* every backend should re-implement this static function */ return "null"; };
00081     virtual UT_UTF8String                   getStorageType() = 0;
00082     virtual UT_UTF8String                   getDescription() = 0;
00083     virtual UT_UTF8String                   getDisplayType() = 0;
00084 
00085     void                                    addProperty(const std::string& key, const std::string& value)
00086         { m_properties[key] = value; }
00087     bool                                    hasProperty(const std::string& key);
00088     const std::string                           getProperty(const std::string& key);
00089     PropertyMap&                            getProperties()
00090         { return m_properties; }
00091 
00092     // dialog management
00093     virtual UT_UTF8String                   getShareHint(PD_Document* /*pDoc*/) { return ""; }
00094     virtual void                            embedDialogWidgets(void* pEmbeddingParent) = 0;
00095     virtual void                            removeDialogWidgets(void* pEmbeddingParent) = 0;
00096     virtual bool                            canDelete()
00097         { return true; }
00098     virtual bool                            canEditProperties()
00099         { return true; }
00100     virtual void                            loadProperties() = 0;
00101     virtual void                            storeProperties() = 0;
00102 
00103     #ifdef _WIN32
00104     virtual BOOL                            _onCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) = 0;
00105     virtual bool                            shouldProcessFocus() = 0;
00106     #endif
00107 
00108     // connection management
00109     virtual ConnectResult                   connect() = 0;
00110     virtual bool                            disconnect() = 0;
00111     virtual bool                            isOnline() = 0;
00112     virtual bool                            autoConnect();
00113 
00114     // for duplicate prevention
00115     virtual bool                            operator==(AccountHandler & rhHandler);
00116 
00117     // packet management
00118     virtual bool                            send(const Packet* packet) = 0;
00119     virtual bool                            send(const Packet* packet, BuddyPtr buddy) = 0;
00120 
00121     // user management
00122     void                                    addBuddy(BuddyPtr pBuddy);
00123     std::vector<BuddyPtr>&                  getBuddies()
00124         { return m_vBuddies; }
00125     virtual void                            getBuddiesAsync() {}
00126     void                                    deleteBuddy(BuddyPtr pBuddy);
00127     void                                    deleteBuddies();
00128     virtual BuddyPtr                        constructBuddy(const PropertyMap& vProps) = 0;
00129     // Constructs a buddy given a buddy descriptor
00130     // NOTE: some backends require additional *backend specific* session information
00131     // to construct a particular buddy. Information that is not available in the buddy
00132     // descriptor (the service and sugar backends need this for example)
00133     // This additional information can then be retrieved via the 'pBuddy'
00134     // argument. That means that the pBuddy should already be in a session and
00135     // thus have access to all backend specific session information
00136     virtual BuddyPtr                        constructBuddy(const std::string& descriptor, BuddyPtr pBuddy) = 0;
00137     virtual bool                            recognizeBuddyIdentifier(const std::string& identifier) = 0;
00138     virtual bool                            allowsManualBuddies() = 0;
00139     virtual void                            forceDisconnectBuddy(BuddyPtr /*buddy*/) = 0;
00140     virtual bool                            hasAccess(const std::vector<std::string>& vAcl, BuddyPtr pBuddy);
00141     virtual bool                            hasPersistentAccessControl() = 0;
00142     // Return true if you can to share a file with this buddy, false otherwise
00143     virtual bool                            canShare(BuddyPtr /*pBuddy*/)
00144         { return true; }
00145     virtual bool                            defaultShareState(BuddyPtr /*pBuddy*/)
00146         { return false; }
00147 
00148     // session management
00149     virtual void                            getSessionsAsync();
00150     virtual void                            getSessionsAsync(BuddyPtr pBuddy);
00151     virtual bool                            startSession(PD_Document* /*pDoc*/, const std::vector<std::string>& /*vAcl*/, AbiCollab** /*pSession*/)
00152         { return true; }
00153     virtual bool                            getAcl(AbiCollab* /*pSession*/, std::vector<std::string>& /*vAcl*/)
00154         { return true; }
00155     virtual bool                            setAcl(AbiCollab* /*pSession*/, const std::vector<std::string>& /*vAcl*/)
00156         { return true; }
00157     virtual void                            joinSessionAsync(BuddyPtr pBuddy, DocHandle& docHandle);
00158     virtual bool                            hasSession(const std::string& sSessionId);
00159     virtual bool                            allowsSessionTakeover() = 0;
00160     bool                                    getCanOffer()
00161         { return m_bCanOffer; }
00162     void                                    setOffering(bool bCanOffer)
00163         { m_bCanOffer = bCanOffer; }
00164     virtual bool                            canManuallyStartSession()
00165         { return true; }
00166 
00167     // generic session management packet implementation
00168     virtual void                            handleMessage(Packet* pPacket, BuddyPtr pBuddy);
00169 
00170     // signal management
00171     virtual void                            signal(const Event& event, BuddyPtr pSource);
00172 
00173     // protocol error management
00174     enum
00175     {
00176         PE_Invalid_Version      = 1,    // only possible error atm ^_^
00177     };
00178 
00179 protected:
00180     // packet management
00181     Packet*                                 _createPacket(const std::string& packet, BuddyPtr pBuddy);
00182     void                                    _createPacketStream(std::string& sString, const Packet* pPacket);   // creates binary string!
00183     virtual bool                            _handleProtocolError(Packet* packet, BuddyPtr buddy);
00184     virtual void                            _handlePacket(Packet* packet, BuddyPtr buddy);
00185 
00186     // protocol error management
00187     void                                    _sendProtocolError(BuddyPtr, UT_sint32 errorEnum);
00188 
00189     // bad bad, protected variables are bad
00190     PropertyMap                             m_properties;
00191 
00192 private:
00193     static void                             _reportProtocolError(UT_sint32 remoteVersion, UT_sint32 errorEnum, BuddyPtr buddy);
00194 
00195     bool                                    m_bCanOffer;
00196     std::vector<BuddyPtr>                   m_vBuddies;
00197 };
00198 
00199 
00200 #endif /* ACCOUNTHANDLER_H */

Generated on Sun Feb 14 2021 for AbiWord by  doxygen 1.7.1