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

ServiceAccountHandler.h

Go to the documentation of this file.
00001 /* Copyright (C) 2006,2007 Marc Maurer <uwog@uwog.net>
00002  * Copyright (C) 2008,2009 AbiSource Corporation B.V.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301 USA.
00018  */
00019 
00020 #ifndef __SERVICEACCOUNTHANDLER__
00021 #define __SERVICEACCOUNTHANDLER__
00022 
00023 #include <string>
00024 #include <vector>
00025 #include <boost/bind.hpp>
00026 #include <boost/shared_ptr.hpp>
00027 
00028 #include "xap_Types.h"
00029 #include "ut_string_class.h"
00030 
00031 #include "soa.h"
00032 #include <core/account/xp/AccountHandler.h>
00033 #include "AbiCollabSaveInterceptor.h"
00034 #include "AsioRealmProtocol.h"
00035 #include "pl_Listener.h"
00036 #include "RealmConnection.h"
00037 #include "RealmBuddy.h"
00038 #include "RealmProtocol.h"
00039 #include "ServiceBuddy.h"
00040 #include "ServiceErrorCodes.h"
00041 
00042 namespace acs = abicollab::service;
00043 namespace rpv1 = realm::protocolv1;
00044 
00045 class PD_Document;
00046 class GetSessionsResponseEvent;
00047 class JoinSessionRequestResponseEvent;
00048 class ServiceBuddy;
00049 class AbiCollabService_Export;
00050 class RealmBuddy;
00051 
00052 struct DocumentPermissions
00053 {
00054     std::vector<UT_uint64> read_write;
00055     std::vector<UT_uint64> read_only;
00056     std::vector<UT_uint64> group_read_write;
00057     std::vector<UT_uint64> group_read_only;
00058     std::vector<UT_uint64> group_read_owner;
00059 };
00060 
00061 extern AccountHandlerConstructor ServiceAccountHandlerConstructor;
00062 
00063 #define SERVICE_ACCOUNT_HANDLER_TYPE "com.abisource.abiword.abicollab.backend.service"
00064 #define SERVICE_REGISTRATION_URL "https://abicollab.net/user/register"
00065 
00066 class ServiceAccountHandler : public AccountHandler
00067 {
00068 public:
00069     ServiceAccountHandler();
00070     virtual ~ServiceAccountHandler();
00071 
00072     static bool                             askPassword(const std::string& email, std::string& password);
00073     static bool                             askFilename(std::string& filename, bool firsttime);
00074     static void                             ensureExt(std::string& filename, const std::string& extension);
00075 
00076     // housekeeping
00077     static UT_UTF8String                    getStaticStorageType();
00078     virtual UT_UTF8String                   getStorageType()
00079         { return getStaticStorageType(); }
00080     virtual UT_UTF8String                   getDescription();
00081     virtual UT_UTF8String                   getDisplayType();
00082 
00083     // dialog management
00084     virtual UT_UTF8String                   getShareHint(PD_Document* pDoc);
00085     static XAP_Dialog_Id                    getDialogGenericInputId();
00086     static XAP_Dialog_Id                    getDialogGenericProgressId();
00087 
00088     // connection management
00089     virtual ConnectResult                   connect();
00090     virtual bool                            disconnect();
00091     virtual bool                            isOnline();
00092     ConnectionPtr                           getConnection(PD_Document* pDoc);
00093 
00094     // user management
00095     virtual void                            getBuddiesAsync();
00096     virtual BuddyPtr                        constructBuddy(const PropertyMap& props);
00097     virtual BuddyPtr                        constructBuddy(const std::string& descriptor, BuddyPtr pBuddy);
00098     virtual bool                            allowsManualBuddies()
00099         { return false; }
00100     virtual bool                            recognizeBuddyIdentifier(const std::string& identifier);
00101     virtual void                            forceDisconnectBuddy(BuddyPtr pBuddy);
00102     virtual bool                            hasAccess(const std::vector<std::string>& vAcl, BuddyPtr pBuddy);
00103     virtual bool                            hasPersistentAccessControl()
00104         { return true; }
00105     virtual bool                            canShare(BuddyPtr pBuddy);
00106 
00107     // packet management
00108     virtual bool                            send(const Packet* packet);
00109     virtual bool                            send(const Packet* packet, BuddyPtr pBuddy);
00110 
00111     // session management
00112     virtual void                            getSessionsAsync();
00113     virtual void                            getSessionsAsync(const Buddy& buddy);
00114     virtual bool                            startSession(PD_Document* pDoc, const std::vector<std::string>& vAcl, AbiCollab** pSession);
00115     virtual bool                            getAcl(AbiCollab* pSession, std::vector<std::string>& vAcl);
00116     virtual bool                            setAcl(AbiCollab* pSession, const std::vector<std::string>& vAcl);
00117     virtual void                            joinSessionAsync(BuddyPtr pBuddy, DocHandle& docHandle);
00118     virtual bool                            hasSession(const std::string& sSessionId);
00119     acs::SOAP_ERROR                         openDocument(UT_uint64 doc_id, UT_uint64 revision, const std::string& session_id, PD_Document** pDoc, XAP_Frame* pFrame);
00120     soa::function_call_ptr                  constructListDocumentsCall();
00121     soa::function_call_ptr                  constructSaveDocumentCall(PD_Document* pDoc, ConnectionPtr connection_ptr);
00122     void                                    removeExporter(void);
00123     virtual bool                            allowsSessionTakeover()
00124         { return true; }
00125 
00126     // signal management
00127     virtual void                            signal(const Event& event, BuddyPtr pSource);
00128 
00129     // misc functions
00130     const std::string&                      getCA() const
00131         { return m_ssl_ca_file; }
00132     static bool                         parseUserInfo(const std::string& userinfo, uint64_t& user_id);
00133 
00134     static XAP_Dialog_Id                    m_iDialogGenericInput;
00135     static XAP_Dialog_Id                    m_iDialogGenericProgress;
00136     static AbiCollabSaveInterceptor         m_saveInterceptor;
00137 
00138 private:
00139     ConnectionPtr                           _realmConnect(soa::CollectionPtr rcp,
00140                                                     UT_uint64 doc_id, const std::string& session_id, bool master);
00141 
00142     ServiceBuddyPtr                         _getBuddy(const UT_UTF8String& descriptor);
00143     ServiceBuddyPtr                         _getBuddy(ServiceBuddyPtr pBuddy);
00144     ServiceBuddyPtr                         _getBuddy(ServiceBuddyType type, uint64_t user_id);
00145 
00146 
00147     template <class T>
00148     void _send(boost::shared_ptr<T> packet, RealmBuddyPtr recipient)
00149     {
00150         realm::protocolv1::send(*packet, recipient->connection()->socket(),
00151             boost::bind(&ServiceAccountHandler::_write_handler, this,
00152                             asio::placeholders::error, asio::placeholders::bytes_transferred, recipient,
00153                             boost::static_pointer_cast<rpv1::Packet>(packet)));
00154     }
00155 
00156     void                                    _write_handler(const asio::error_code& e, std::size_t bytes_transferred,
00157                                                     boost::shared_ptr<const RealmBuddy> recipient, boost::shared_ptr<rpv1::Packet> packet);
00158 
00159     void                                    _write_result(const asio::error_code& e, std::size_t bytes_transferred,
00160                                                     ConnectionPtr connection, boost::shared_ptr<rpv1::Packet> packet);
00161 
00162     bool                                    _listDocuments(soa::function_call_ptr fc_ptr,
00163                                                     const std::string uri, bool verify_webapp_host,
00164                                                     boost::shared_ptr<std::string> result_ptr);
00165     void                                    _listDocuments_cb(bool success, soa::function_call_ptr fc_ptr, boost::shared_ptr<std::string> result_ptr);
00166 
00167     acs::SOAP_ERROR                         _openDocumentMaster(ConnectionPtr connection, soa::CollectionPtr rcp, PD_Document** pDoc, XAP_Frame* pFrame,
00168                                                     const std::string& session_id, const std::string& filename, bool bLocallyOwned);
00169     acs::SOAP_ERROR                         _openDocumentSlave(ConnectionPtr connection, PD_Document** pDoc, XAP_Frame* pFrame,
00170                                                     const std::string& filename, bool bLocallyOwned);
00171     bool                                    _getConnections();
00172     bool                                    _getPermissions(uint64_t doc_id, DocumentPermissions& perms);
00173     bool                                    _setPermissions(UT_uint64 doc_id, DocumentPermissions& perms);
00174 
00175     void                                    _handleJoinSessionRequestResponse(
00176                                                     JoinSessionRequestResponseEvent* jsre, BuddyPtr pBuddy,
00177                                                     XAP_Frame* pFrame, PD_Document** pDoc, const std::string& filename,
00178                                                     bool bLocallyOwned);
00179     void                                    _handleRealmPacket(ConnectionPtr connection);
00180     ConnectionPtr                           _getConnection(const std::string& session_id);
00181     void                                    _removeConnection(const std::string& session_id);
00182     void                                    _handleMessages(ConnectionPtr connection);
00183     void                                    _parseSessionFiles(soa::ArrayPtr files_array, GetSessionsResponseEvent& gsre);
00184     bool                                    _splitDescriptor(const std::string& descriptor, uint64_t& user_id, uint8_t& conn_id, std::string& domain);
00185     std::string                             _getDomain(const std::string& protocol);
00186     std::string                             _getDomain();
00187     bool                                    _parseUserInfo(const std::string& userinfo, uint64_t& user_id);
00188 
00189     bool                                    m_bOnline;  // only used to determine if we are allowed to
00190                                                         // communicate with abicollab.net or not
00191     std::vector<ConnectionPtr>              m_connections;
00192     std::map<uint64_t, DocumentPermissions> m_permissions;
00193     std::string                             m_ssl_ca_file;
00194     PL_ListenerId             m_iListenerID;
00195     AbiCollabService_Export * m_pExport;
00196 
00197 };
00198 
00199 #endif /* __SERVICEACCOUNTHANDLER__ */

Generated on Sun Feb 14 2021 for AbiWord by  doxygen 1.7.1