Debian Codegraph @

plugins/collab/core/account/xp/AccountHandler.h

raw
1 /* Copyright (C) 2006 by Marc Maurer <[email protected]>
2 *
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License
5 * as published by the Free Software Foundation; either version 2
6 * of the License, or (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 * 02110-1301 USA.
17 */
18
19 #ifndef __ACCOUNTHANDLER_H__
20 #define __ACCOUNTHANDLER_H__
21
22 #include <map>
23 #include <string>
24 #include <list>
25 #include <vector>
26 #include "ut_types.h"
27 #include "ut_string_class.h"
28 #include "ut_vector.h"
29 #include "DocHandle.h"
30 #include <packet/xp/AbiCollab_Packet.h>
31 #include <account/xp/Buddy.h>
32 #include <account/xp/EventListener.h>
33 #ifdef WIN32
34 #define WIN32_LEAN_AND_MEAN
35 #include <windows.h>
36 #endif
37
38 class AbiCollab;
39
40 typedef enum _ConnectResult
41 {
42 CONNECT_SUCCESS = 0,
43 CONNECT_FAILED,
44 CONNECT_IN_PROGRESS,
45 CONNECT_AUTHENTICATION_FAILED,
46 CONNECT_ALREADY_CONNECTED,
47 CONNECT_INTERNAL_ERROR
48 } ConnectResult;
49
50 typedef AccountHandler* (*AccountHandlerConstructor)();
51
52 typedef std::map<std::string, std::string> PropertyMap;
53
54 class ProtocolErrorPacket : public Packet
55 {
56 public:
57 ProtocolErrorPacket();
58 ProtocolErrorPacket( UT_sint32 errorEnum );
59 DECLARE_PACKET(ProtocolErrorPacket);
60
61 virtual UT_sint32 getProtocolVersion() const
62 { return 0; } // not ABICOLLAB_PROTOCOL_VERSION!!
63 UT_sint32 getErrorEnum() const
64 { return m_errorEnum; }
65 UT_sint32 getRemoteVersion() const
66 { return m_remoteVersion; }
67 protected:
68 UT_sint32 m_errorEnum;
69 UT_sint32 m_remoteVersion;
70 };
71
72 class AccountHandler : public EventListener
73 {
74 public:
75 AccountHandler() {}
76 virtual ~AccountHandler() {}
77
78 // housekeeping
79 static UT_UTF8String getStaticStorageType()
80 { /* every backend should re-implement this static function */ return "null"; };
81 virtual UT_UTF8String getStorageType() = 0;
82 virtual UT_UTF8String getDescription() = 0;
83 virtual UT_UTF8String getDisplayType() = 0;
84
85 void addProperty(const std::string& key, const std::string& value)
86 { m_properties[key] = value; }
87 bool hasProperty(const std::string& key);
88 const std::string getProperty(const std::string& key);
89 PropertyMap& getProperties()
90 { return m_properties; }
91
92 // dialog management
93 virtual UT_UTF8String getShareHint(PD_Document* /*pDoc*/) { return ""; }
94 virtual void embedDialogWidgets(void* pEmbeddingParent) = 0;
95 virtual void removeDialogWidgets(void* pEmbeddingParent) = 0;
96 virtual bool canDelete()
97 { return true; }
98 virtual bool canEditProperties()
99 { return true; }
100 virtual void loadProperties() = 0;
101 virtual void storeProperties() = 0;
102
103 #ifdef WIN32
104 virtual BOOL _onCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) = 0;
105 virtual bool shouldProcessFocus() = 0;
106 #endif
107
108 // connection management
109 virtual ConnectResult connect() = 0;
110 virtual bool disconnect() = 0;
111 virtual bool isOnline() = 0;
112 virtual bool autoConnect();
113
114 // for duplicate prevention
115 virtual bool operator==(AccountHandler & rhHandler);
116
117 // packet management
118 virtual bool send(const Packet* packet) = 0;
119 virtual bool send(const Packet* packet, BuddyPtr buddy) = 0;
120
121 // user management
122 void addBuddy(BuddyPtr pBuddy);
123 std::vector<BuddyPtr>& getBuddies()
124 { return m_vBuddies; }
125 virtual void getBuddiesAsync() {}
126 void deleteBuddy(BuddyPtr pBuddy);
127 void deleteBuddies();
128 virtual BuddyPtr constructBuddy(const PropertyMap& vProps) = 0;
129 // Constructs a buddy given a buddy descriptor
130 // NOTE: some backends require additional *backend specific* session information
131 // to construct a particular buddy. Information that is not available in the buddy
132 // descriptor (the service and sugar backends need this for example)
133 // This additional information can then be retrieved via the 'pBuddy'
134 // argument. That means that the pBuddy should already be in a session and
135 // thus have access to all backend specific session information
136 virtual BuddyPtr constructBuddy(const std::string& descriptor, BuddyPtr pBuddy) = 0;
137 virtual bool recognizeBuddyIdentifier(const std::string& identifier) = 0;
138 virtual bool allowsManualBuddies() = 0;
139 virtual void forceDisconnectBuddy(BuddyPtr /*buddy*/) = 0;
140 virtual bool hasAccess(const std::vector<std::string>& vAcl, BuddyPtr pBuddy);
141 virtual bool hasPersistentAccessControl() = 0;
142 // Return true if you can to share a file with this buddy, false otherwise
143 virtual bool canShare(BuddyPtr /*pBuddy*/)
144 { return true; }
145 virtual bool defaultShareState(BuddyPtr /*pBuddy*/)
146 { return false; }
147
148 // session management
149 virtual void getSessionsAsync();
150 virtual void getSessionsAsync(BuddyPtr pBuddy);
151 virtual bool startSession(PD_Document* /*pDoc*/, const std::vector<std::string>& /*vAcl*/, AbiCollab** /*pSession*/)
152 { return true; }
153 virtual bool getAcl(AbiCollab* /*pSession*/, std::vector<std::string>& /*vAcl*/)
154 { return true; }
155 virtual bool setAcl(AbiCollab* /*pSession*/, const std::vector<std::string>& /*vAcl*/)
156 { return true; }
157 virtual void joinSessionAsync(BuddyPtr pBuddy, DocHandle& docHandle);
158 virtual bool hasSession(const UT_UTF8String& sSessionId);
159 virtual bool allowsSessionTakeover() = 0;
160 bool getCanOffer()
161 { return m_bCanOffer; }
162 void setOffering(bool bCanOffer)
163 { m_bCanOffer = bCanOffer; }
164 virtual bool canManuallyStartSession()
165 { return true; }
166
167 // generic session management packet implementation
168 virtual void handleMessage(Packet* pPacket, BuddyPtr pBuddy);
169
170 // signal management
171 virtual void signal(const Event& event, BuddyPtr pSource);
172
173 // protocol error management
174 enum
175 {
176 PE_Invalid_Version = 1, // only possible error atm ^_^
177 };
178
179 protected:
180 // packet management
181 Packet* _createPacket(const std::string& packet, BuddyPtr pBuddy);
182 void _createPacketStream(std::string& sString, const Packet* pPacket); // creates binary string!
183 virtual bool _handleProtocolError(Packet* packet, BuddyPtr buddy);
184 virtual void _handlePacket(Packet* packet, BuddyPtr buddy);
185
186 // protocol error management
187 void _sendProtocolError(BuddyPtr, UT_sint32 errorEnum);
188
189 // bad bad, protected variables are bad
190 PropertyMap m_properties;
191
192 private:
193 static void _reportProtocolError(UT_sint32 remoteVersion, UT_sint32 errorEnum, BuddyPtr buddy);
194
195 bool m_bCanOffer;
196 std::vector<BuddyPtr> m_vBuddies;
197 };
198
199
200 #endif /* ACCOUNTHANDLER_H */