• 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., 59 Temple Place - Suite 330, Boston, MA
00016  * 02111-1307, 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 using std::string;
00041 using std::map;
00042 using std::vector;
00043 
00044 typedef enum _ConnectResult
00045 {
00046     CONNECT_SUCCESS = 0,
00047     CONNECT_FAILED,
00048     CONNECT_IN_PROGRESS,
00049     CONNECT_AUTHENTICATION_FAILED,
00050     CONNECT_ALREADY_CONNECTED,
00051     CONNECT_INTERNAL_ERROR
00052 } ConnectResult;
00053 
00054 typedef AccountHandler* (*AccountHandlerConstructor)();
00055 
00056 typedef map<string, string> PropertyMap;
00057 
00058 class ProtocolErrorPacket : public Packet
00059 {
00060 public:
00061     ProtocolErrorPacket();
00062     ProtocolErrorPacket( UT_sint32 errorEnum );
00063     DECLARE_PACKET(ProtocolErrorPacket);
00064 
00065     virtual UT_sint32                       getProtocolVersion() const
00066         { return 0; } // not ABICOLLAB_PROTOCOL_VERSION!!
00067     UT_sint32                               getErrorEnum() const
00068         { return m_errorEnum; }
00069     UT_sint32                               getRemoteVersion() const
00070         { return m_remoteVersion; }
00071 protected:
00072     UT_sint32       m_errorEnum;
00073     UT_sint32       m_remoteVersion;
00074 };
00075 
00076 class AccountHandler : public EventListener
00077 {
00078 public:
00079     AccountHandler() {}
00080     virtual ~AccountHandler() {}
00081 
00082     // housekeeping
00083     static UT_UTF8String                    getStaticStorageType()
00084         { /* every backend should re-implement this static function */ return "null"; };
00085     virtual UT_UTF8String                   getStorageType() = 0;
00086     virtual UT_UTF8String                   getDescription() = 0;
00087     virtual UT_UTF8String                   getDisplayType() = 0;
00088 
00089     void                                    addProperty(const string& key, const string& value)
00090         { m_properties[key] = value; }
00091     bool                                    hasProperty(const string& key);
00092     const string                            getProperty(const string& key);
00093     PropertyMap&                            getProperties()
00094         { return m_properties; }
00095 
00096     // dialog management
00097     virtual UT_UTF8String                   getShareHint(PD_Document* /*pDoc*/) { return ""; }
00098     virtual void                            embedDialogWidgets(void* pEmbeddingParent) = 0;
00099     virtual void                            removeDialogWidgets(void* pEmbeddingParent) = 0;
00100     virtual bool                            canDelete()
00101         { return true; }
00102     virtual bool                            canEditProperties()
00103         { return true; }
00104     virtual void                            loadProperties() = 0;
00105     virtual void                            storeProperties() = 0;
00106 
00107     #ifdef WIN32
00108     virtual BOOL                            _onCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) = 0;
00109     virtual bool                            shouldProcessFocus() = 0;
00110     #endif
00111 
00112     // connection management
00113     virtual ConnectResult                   connect() = 0;
00114     virtual bool                            disconnect() = 0;
00115     virtual bool                            isOnline() = 0;
00116     virtual bool                            autoConnect();
00117 
00118     // for duplicate prevention
00119     virtual bool                            operator==(AccountHandler & rhHandler);
00120 
00121     // packet management
00122     virtual bool                            send(const Packet* packet) = 0;
00123     virtual bool                            send(const Packet* packet, BuddyPtr buddy) = 0;
00124 
00125     // user management
00126     void                                    addBuddy(BuddyPtr pBuddy);
00127     std::vector<BuddyPtr>&                  getBuddies()
00128         { return m_vBuddies; }
00129     virtual void                            getBuddiesAsync() {}
00130     void                                    deleteBuddy(BuddyPtr pBuddy);
00131     void                                    deleteBuddies();
00132     virtual BuddyPtr                        constructBuddy(const PropertyMap& vProps) = 0;
00133     // Constructs a buddy given a buddy descriptor
00134     // NOTE: some backends require additional *backend specific* session information
00135     // to construct a particular buddy. Information that is not available in the buddy
00136     // descriptor (the service and sugar backends need this for example)
00137     // This additional information can then be retrieved via the 'pBuddy'
00138     // argument. That means that the pBuddy should already be in a session and
00139     // thus have access to all backend specific session information
00140     virtual BuddyPtr                        constructBuddy(const std::string& descriptor, BuddyPtr pBuddy) = 0;
00141     virtual bool                            recognizeBuddyIdentifier(const std::string& identifier) = 0;
00142     virtual bool                            allowsManualBuddies() = 0;
00143     virtual void                            forceDisconnectBuddy(BuddyPtr /*buddy*/) = 0;
00144     virtual bool                            hasAccess(const std::vector<std::string>& vAcl, BuddyPtr pBuddy);
00145     virtual bool                            hasPersistentAccessControl() = 0;
00146     // Return true if you can to share a file with this buddy, false otherwise
00147     virtual bool                            canShare(BuddyPtr /*pBuddy*/)
00148         { return true; }
00149     virtual bool                            defaultShareState(BuddyPtr /*pBuddy*/)
00150         { return false; }
00151 
00152     // session management
00153     virtual void                            getSessionsAsync();
00154     virtual void                            getSessionsAsync(BuddyPtr pBuddy);
00155     virtual bool                            startSession(PD_Document* /*pDoc*/, const std::vector<std::string>& /*vAcl*/, AbiCollab** /*pSession*/)
00156         { return true; }
00157     virtual bool                            getAcl(AbiCollab* /*pSession*/, std::vector<std::string>& /*vAcl*/)
00158         { return true; }
00159     virtual bool                            setAcl(AbiCollab* /*pSession*/, const std::vector<std::string>& /*vAcl*/)
00160         { return true; }
00161     virtual void                            joinSessionAsync(BuddyPtr pBuddy, DocHandle& docHandle);
00162     virtual bool                            hasSession(const UT_UTF8String& sSessionId);
00163     virtual bool                            allowsSessionTakeover() = 0;
00164     bool                                    getCanOffer()
00165         { return m_bCanOffer; }
00166     void                                    setOffering(bool bCanOffer)
00167         { m_bCanOffer = bCanOffer; }
00168     virtual bool                            canManuallyStartSession()
00169         { return true; }
00170 
00171     // generic session management packet implementation
00172     virtual void                            handleMessage(Packet* pPacket, BuddyPtr pBuddy);
00173 
00174     // signal management
00175     virtual void                            signal(const Event& event, BuddyPtr pSource);
00176 
00177     // protocol error management
00178     enum
00179     {
00180         PE_Invalid_Version      = 1,    // only possible error atm ^_^
00181     };
00182 
00183 protected:
00184     // packet management
00185     Packet*                                 _createPacket(const std::string& packet, BuddyPtr pBuddy);
00186     void                                    _createPacketStream(std::string& sString, const Packet* pPacket);   // creates binary string!
00187     virtual bool                            _handleProtocolError(Packet* packet, BuddyPtr buddy);
00188     virtual void                            _handlePacket(Packet* packet, BuddyPtr buddy);
00189 
00190     // protocol error management
00191     void                                    _sendProtocolError(BuddyPtr, UT_sint32 errorEnum);
00192 
00193     // bad bad, protected variables are bad
00194     PropertyMap                             m_properties;
00195 
00196 private:
00197     static void                             _reportProtocolError(UT_sint32 remoteVersion, UT_sint32 errorEnum, BuddyPtr buddy);
00198 
00199     bool                                    m_bCanOffer;
00200     std::vector<BuddyPtr>                   m_vBuddies;
00201 };
00202 
00203 
00204 #endif /* ACCOUNTHANDLER_H */

Generated on Sat May 26 2012 for AbiWord by  doxygen 1.7.1