OpenAB  1.0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
CardDAVStorage.hpp
Go to the documentation of this file.
1 /*
2  * This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5  */
10 #ifndef CARDDAV_H_
11 #define CARDDAV_H_
12 
14 #include <list>
15 #include "helpers/Http.hpp"
16 #include "CardDAVHelper.hpp"
17 
19 
45 {
46  public:
50  CardDAVStorage(const std::string& url,
51  const std::string& login,
52  const OpenAB::SecureString& password);
53 
54  CardDAVStorage(const std::string& url,
55  const std::string& clientId,
56  const OpenAB::SecureString& clientSecret,
57  const OpenAB::SecureString& refreshToken);
58 
59  virtual ~CardDAVStorage();
60 
62 
64 
66 
68 
70 
71  int getTotalCount() const;
72 
73  enum eAddItem addContact( const std::string& vCard,
74  OpenAB::PIMItem::ID& newId,
75  OpenAB::PIMItem::Revision& revision);
76 
77  enum eAddItem addContacts( const std::vector<std::string> &vCards,
78  OpenAB::PIMItem::IDs& newIds,
79  OpenAB::PIMItem::Revisions& revisions);
80 
81  enum eModifyItem modifyContact( const std::string& vCard,
82  const OpenAB::PIMItem::ID& id,
83  OpenAB::PIMItem::Revision& revision);
84 
85  enum eModifyItem modifyContacts( const std::vector<std::string> &vCard,
86  const OpenAB::PIMItem::IDs& ids,
87  OpenAB::PIMItem::Revisions& revisions);
88 
90 
92 
93  enum eGetItem getContact (const OpenAB::PIMItem::ID & id,
95 
96  enum eGetItem getContacts(const OpenAB::PIMItem::IDs & ids,
97  std::vector<OpenAB::SmartPtr<OpenAB::PIMContactItem> > & items);
98 
99  enum OpenAB_Storage::Storage::eGetRevisions getRevisions(std::map<std::string, std::string>& revisions);
100 
101  enum OpenAB_Storage::Storage::eGetRevisions getChangedRevisions(const std::string& token,
102  std::map<std::string, std::string>& revisions,
103  std::vector<OpenAB::PIMItem::ID>& removed);
104 
106 
108 
109  private:
113  CardDAVStorage(CardDAVStorage const &other);
114 
118  CardDAVStorage& operator=(CardDAVStorage const &other);
119 
120  void construct();
121 
122  void cleanup();
123 
124  bool downloadVCards(unsigned int offset, unsigned int size);
125 
126  std::string serverUrl;
127 
128  std::string userLogin;
129  OpenAB::SecureString userPassword;
130 
131  std::string clientId;
132  OpenAB::SecureString clientSecret;
133  OpenAB::SecureString refreshToken;
134 
135  std::string syncToken;
136 
137  OpenAB::HttpSession curlSession;
138  OpenAB::HttpAuthorizer* authorizer;
139  CardDAVHelper* cardDAVHelper;
140  CardDAVStorageItemIterator* sourceIterator;
141 };
142 
144 {
145  public:
150 
154  virtual ~CardDAVStorageItemIterator();
155 
159  };
160  enum eCursorInit cursorInit(CardDAVHelper* cardDavHelper);
161 
163 
166 
167  unsigned int getSize() const;
168 
169  /*OpenAB_Source::Source::eSuspendRet suspend();
170  OpenAB_Source::Source::eResumeRet resume();
171  OpenAB_Source::Source::eCancelRet cancel();*/
172 
173  private:
178 
183 
184  enum eFetchContacts {
185  eFetchContactsOK,
186  eFetchContactsEND,
187  eFetchContactsFail
188  };
189  enum eFetchContacts fetchContacts(int fetchsize);
190 
191  static void* downloadThreadFunc(void* ptr);
192  bool downloadVCards(unsigned int offset, unsigned int size);
194  CardDAVHelper* cardDavHelper;
195  unsigned total;
196  unsigned int offset;
197  unsigned int offsetOfCachedVCards;
198  std::list<OpenAB::SmartPtr<OpenAB::PIMContactItem> > cachedContacts;
199  std::vector<CardDAVHelper::ContactMetadata> contactsMetadata;
200  bool paused;
201  bool cancelled;
202  pthread_t downloadThread;
203  bool threadCreated;
204  pthread_mutex_t mutex;
205  pthread_cond_t bufferReadyCond;
206  OpenAB_Source::Source::eGetItemRet transferStatus;
207 };
208 
209 #endif // CARDDAV_H_
CardDAVStorageItemIterator()
Constructor.
Definition: CardDAVStorage.cpp:437
Documentation for class CardDAVHelper.
Definition: CardDAVHelper.hpp:19
enum OpenAB_Source::Source::eCancelRet cancel()
Cancels Source, if such operation is supported. After canceling Source next call to getVCard() should...
Definition: CardDAVStorage.cpp:419
virtual ~CardDAVStorage()
Definition: CardDAVStorage.cpp:71
std::string Revision
Definition: PIMItem.hpp:89
enum eGetItem getContact(const OpenAB::PIMItem::ID &id, OpenAB::SmartPtr< OpenAB::PIMContactItem > &item)
Get the contact from the Storage.
Definition: CardDAVStorage.cpp:231
enum eRemoveItem removeContacts(const OpenAB::PIMItem::IDs &ids)
Removes contacts from the ContactsStorage.
Definition: CardDAVStorage.cpp:218
Documentation for ContactsStorage interface. Provides functionalities specific to Storage of OpenAB::...
Definition: ContactsStorage.hpp:27
HttpSession class. Allows to send Http requests.
Definition: Http.hpp:26
enum eModifyItem modifyContacts(const std::vector< std::string > &vCard, const OpenAB::PIMItem::IDs &ids, OpenAB::PIMItem::Revisions &revisions)
Modifies contacts in the ContactsStorage.
Definition: CardDAVStorage.cpp:191
HttpAuthorizer interface. This should be used by classes implementing different Http authorization me...
Definition: Http.hpp:334
eCancelRet
Definition: Source.hpp:138
eResumeRet
Definition: Source.hpp:123
Definition: CardDAVStorage.hpp:44
eModifyItem
Definition: Storage.hpp:164
enum eModifyItem modifyContact(const std::string &vCard, const OpenAB::PIMItem::ID &id, OpenAB::PIMItem::Revision &revision)
Modifies contact in the ContactsStorage.
Definition: CardDAVStorage.cpp:180
enum eAddItem addContact(const std::string &vCard, OpenAB::PIMItem::ID &newId, OpenAB::PIMItem::Revision &revision)
Adds a new contact to the ContactsStorage.
Definition: CardDAVStorage.cpp:148
std::vector< OpenAB::PIMItem::Revision > Revisions
Definition: PIMItem.hpp:111
enum OpenAB_Storage::Storage::eGetRevisions getChangedRevisions(const std::string &token, std::map< std::string, std::string > &revisions, std::vector< OpenAB::PIMItem::ID > &removed)
Gets revisions of items changed since Storage was in state identified by token.
Definition: CardDAVStorage.cpp:326
eAddItem
Definition: Storage.hpp:126
This object associates OpenAB::PIMItem with its unique ID from OpenAB_Storage::Storage. Additionally it stores status flag used in synchronization process.
Definition: StorageItem.hpp:22
unsigned int getSize() const
Retrieve number of items in interator.
Definition: CardDAVStorage.cpp:612
SecureString class, used to store strings like passwords etc. Current implementation encodes string i...
Definition: SecureString.hpp:26
enum OpenAB_Source::Source::eGetItemRet getItem(OpenAB::SmartPtr< OpenAB::PIMItem > &item)
Gets PIM Item from Source. If Source is suspended getItem() should block until Source will be resumed...
Definition: CardDAVStorage.cpp:380
Definition: CardDAVStorage.hpp:157
int getTotalCount() const
Returns total count of items available from Source, if such information is available.
Definition: CardDAVStorage.cpp:428
OpenAB_Storage::StorageItem * operator->()
Retrieve the current StorageItem.
Definition: CardDAVStorage.cpp:606
eSuspendRet
Definition: Source.hpp:108
The StorageItemIterator is mainly used to quickly browse the Storage contents.
Definition: StorageItem.hpp:97
eCursorInit
Definition: CardDAVStorage.hpp:156
std::vector< OpenAB::PIMItem::ID > IDs
Definition: PIMItem.hpp:110
Definition: CardDAVStorage.hpp:158
OpenAB_Storage::StorageItem * next()
Retrieve the next StorageItem.
Definition: CardDAVStorage.cpp:561
eGetItemRet
Definition: Source.hpp:155
enum eRemoveItem removeContact(const OpenAB::PIMItem::ID &id)
Removes contact from the ContactsStorage.
Definition: CardDAVStorage.cpp:209
OpenAB_Storage::StorageItemIterator * newStorageItemIterator()
Retrieve an new Iterator to quickly parse the list of items.
Definition: CardDAVStorage.cpp:363
eGetItem
Definition: Storage.hpp:226
enum OpenAB_Storage::Storage::eGetSyncToken getLatestSyncToken(std::string &token)
If storage supports tracking of items changes, it returns latest status identifier of the storage...
Definition: CardDAVStorage.cpp:351
eGetRevisions
Definition: Storage.hpp:265
enum OpenAB_Source::Source::eInit init()
Initializes Source.
Definition: CardDAVStorage.cpp:99
OpenAB_Storage::StorageItem operator*()
Retrieve the current StorageItem.
Definition: CardDAVStorage.cpp:600
CardDAVStorage(const std::string &url, const std::string &login, const OpenAB::SecureString &password)
Constructor.
Definition: CardDAVStorage.cpp:26
enum eCursorInit cursorInit(CardDAVHelper *cardDavHelper)
Definition: CardDAVStorage.cpp:462
eGetSyncToken
Definition: Storage.hpp:251
eInit
Definition: Source.hpp:94
enum OpenAB_Storage::Storage::eGetRevisions getRevisions(std::map< std::string, std::string > &revisions)
Gets revision of the items from the Storage.
Definition: CardDAVStorage.cpp:309
std::string ID
Definition: PIMItem.hpp:64
enum OpenAB_Source::Source::eSuspendRet suspend()
Suspends Source, if such operation is supported.
Definition: CardDAVStorage.cpp:401
enum OpenAB_Source::Source::eResumeRet resume()
Resumes Source, if such operation is supported.
Definition: CardDAVStorage.cpp:410
virtual ~CardDAVStorageItemIterator()
Destructor, virtual by default.
Definition: CardDAVStorage.cpp:451
enum eGetItem getContacts(const OpenAB::PIMItem::IDs &ids, std::vector< OpenAB::SmartPtr< OpenAB::PIMContactItem > > &items)
Get the contacts from the Storage.
Definition: CardDAVStorage.cpp:268
enum eAddItem addContacts(const std::vector< std::string > &vCards, OpenAB::PIMItem::IDs &newIds, OpenAB::PIMItem::Revisions &revisions)
Adds new contacts to the ContactsStorage.
Definition: CardDAVStorage.cpp:159
Definition: CardDAVStorage.hpp:143
eRemoveItem
Definition: Storage.hpp:201