OpenAB  1.0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
CalDAVStorage.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 "CalDAVHelper.hpp"
17 
19 
55 {
56  public:
66  CalDAVStorage(const std::string& url,
67  const std::string& login,
68  const OpenAB::SecureString& password,
69  const std::string& calendarURL,
70  const std::string& calendarName,
71  OpenAB::PIMItemType type);
72 
83  CalDAVStorage(const std::string& url,
84  const std::string& clientId,
85  const OpenAB::SecureString& clientSecret,
86  const OpenAB::SecureString& refreshToken,
87  const std::string& calendarURL,
88  const std::string& calendarName,
89  OpenAB::PIMItemType type);
90 
91  virtual ~CalDAVStorage();
92 
94 
96 
98 
100 
102 
103  int getTotalCount() const;
104 
105  enum eAddItem addObject( const std::string& iCal,
106  OpenAB::PIMItem::ID& newId,
107  OpenAB::PIMItem::Revision& revision);
108 
109  enum eAddItem addObjects( const std::vector<std::string> &iCals,
110  OpenAB::PIMItem::IDs& newIds,
111  OpenAB::PIMItem::Revisions& revisions);
112 
113  enum eModifyItem modifyObject( const std::string& iCal,
114  const OpenAB::PIMItem::ID& id,
115  OpenAB::PIMItem::Revision& revision);
116 
117  enum eModifyItem modifyObjects( const std::vector<std::string> &iCals,
118  const OpenAB::PIMItem::IDs& ids,
119  OpenAB::PIMItem::Revisions& revisions);
120 
122 
124 
125  enum eGetItem getEvent (const OpenAB::PIMItem::ID & id,
127 
128  enum eGetItem getEvents(const OpenAB::PIMItem::IDs & ids,
129  std::vector<OpenAB::SmartPtr<OpenAB::PIMCalendarEventItem> > & items);
130 
131  enum eGetItem getTask (const OpenAB::PIMItem::ID & id,
133 
134  enum eGetItem getTasks(const OpenAB::PIMItem::IDs & ids,
135  std::vector<OpenAB::SmartPtr<OpenAB::PIMCalendarTaskItem> > & items);
136 
137 
138  enum OpenAB_Storage::Storage::eGetRevisions getRevisions(std::map<std::string, std::string>& revisions);
139 
140  enum OpenAB_Storage::Storage::eGetRevisions getChangedRevisions(const std::string& token,
141  std::map<std::string, std::string>& revisions,
142  std::vector<OpenAB::PIMItem::ID>& removed);
143 
145 
147 
148  private:
152  CalDAVStorage(CalDAVStorage const &other);
153 
157  CalDAVStorage& operator=(CalDAVStorage const &other);
158 
159  void construct();
160 
161  void cleanup();
162 
163  bool selectFirstCalendar(const CalDAVHelper::Calendars cals,
164  CalDAVHelper::CalendarInfo& selectedCalendar);
165 
166  std::string serverUrl;
167  std::string calendarUrl;
168  std::string calendarName;
169 
170  std::string userLogin;
171  OpenAB::SecureString userPassword;
172 
173  std::string clientId;
174  OpenAB::SecureString clientSecret;
175  OpenAB::SecureString refreshToken;
176 
177  std::string syncToken;
178 
179  CalDAVHelper::CalendarInfo calendarInfo;
180 
181  OpenAB::HttpSession curlSession;
182  OpenAB::HttpAuthorizer* authorizer;
183  CalDAVHelper* calDavHelper;
184  CalDAVStorageItemIterator* sourceIterator;
185 };
186 
188 {
189  public:
194 
198  virtual ~CalDAVStorageItemIterator();
199 
203  };
204  enum eCursorInit cursorInit(CalDAVHelper* calDAVHelper,
205  const std::string& calendarURL,
206  OpenAB::PIMItemType type);
207 
209 
212 
213  unsigned int getSize() const;
214 
215  /*OpenAB_Source::Source::eSuspendRet suspend();
216  OpenAB_Source::Source::eResumeRet resume();
217  OpenAB_Source::Source::eCancelRet cancel();*/
218 
219  private:
224 
228  CalDAVStorageItemIterator& operator=(CalDAVStorageItemIterator const &other);
229 
230  enum eFetchEvents {
231  eFetchEventsOK,
232  eFetchEventsEND,
233  eFetchEventsFail
234  };
235  enum eFetchEvents fetchEvents(int fetchsize);
236 
237  static void* downloadThreadFunc(void* ptr);
238  bool downloadICals(unsigned int offset, unsigned int size);
239 
241  CalDAVHelper* calDavHelper;
242  std::string calendarURL;
243 
244  unsigned total;
245  unsigned int offset;
246  unsigned int offsetOfCachedICals;
247 
248  std::list<OpenAB::SmartPtr<OpenAB::PIMCalendarItem> > cachedEvents;
249  std::vector<CalDAVHelper::EventMetadata> eventsMetadata;
250 
251  bool paused;
252  bool cancelled;
253  bool threadCreated;
254  pthread_t downloadThread;
255  pthread_mutex_t mutex;
256  pthread_cond_t bufferReadyCond;
257  OpenAB_Source::Source::eGetItemRet transferStatus;
258  OpenAB::PIMItemType itemsType;
259 };
260 
261 #endif // CARDDAV_H_
CalDAVStorage(const std::string &url, const std::string &login, const OpenAB::SecureString &password, const std::string &calendarURL, const std::string &calendarName, OpenAB::PIMItemType type)
Constructor.
Definition: CalDAVStorage.cpp:26
enum eGetItem getTasks(const OpenAB::PIMItem::IDs &ids, std::vector< OpenAB::SmartPtr< OpenAB::PIMCalendarTaskItem > > &items)
Get the contacts from the Storage.
Definition: CalDAVStorage.cpp:461
std::string Revision
Definition: PIMItem.hpp:89
OpenAB_Storage::StorageItemIterator * newStorageItemIterator()
Retrieve an new Iterator to quickly parse the list of items.
Definition: CalDAVStorage.cpp:558
Definition: CalDAVStorage.hpp:202
Definition: CalDAVStorage.hpp:187
HttpSession class. Allows to send Http requests.
Definition: Http.hpp:26
enum eRemoveItem removeObjects(const OpenAB::PIMItem::IDs &ids)
Removes contacts from the ContactsStorage.
Definition: CalDAVStorage.cpp:320
enum eGetItem getTask(const OpenAB::PIMItem::ID &id, OpenAB::SmartPtr< OpenAB::PIMCalendarTaskItem > &item)
Get the contact from the Storage.
Definition: CalDAVStorage.cpp:418
enum eCursorInit cursorInit(CalDAVHelper *calDAVHelper, const std::string &calendarURL, OpenAB::PIMItemType type)
Definition: CalDAVStorage.cpp:648
enum eModifyItem modifyObjects(const std::vector< std::string > &iCals, const OpenAB::PIMItem::IDs &ids, OpenAB::PIMItem::Revisions &revisions)
Modifies contacts in the ContactsStorage.
Definition: CalDAVStorage.cpp:293
HttpAuthorizer interface. This should be used by classes implementing different Http authorization me...
Definition: Http.hpp:334
OpenAB_Storage::StorageItem * operator->()
Retrieve the current StorageItem.
Definition: CalDAVStorage.cpp:814
enum eRemoveItem removeObject(const OpenAB::PIMItem::ID &id)
Removes contact from the ContactsStorage.
Definition: CalDAVStorage.cpp:311
eCancelRet
Definition: Source.hpp:138
eResumeRet
Definition: Source.hpp:123
CalDAVStorageItemIterator()
Constructor.
Definition: CalDAVStorage.cpp:622
enum OpenAB_Source::Source::eSuspendRet suspend()
Suspends Source, if such operation is supported.
Definition: CalDAVStorage.cpp:598
std::vector< CalendarInfo > Calendars
Definition: CalDAVHelper.hpp:265
eModifyItem
Definition: Storage.hpp:164
OpenAB_Storage::StorageItem operator*()
Retrieve the current StorageItem.
Definition: CalDAVStorage.cpp:809
std::vector< OpenAB::PIMItem::Revision > Revisions
Definition: PIMItem.hpp:111
enum eModifyItem modifyObject(const std::string &iCal, const OpenAB::PIMItem::ID &id, OpenAB::PIMItem::Revision &revision)
Modifies contact in the ContactsStorage.
Definition: CalDAVStorage.cpp:282
eAddItem
Definition: Storage.hpp:126
Documentation for ContactsStorage interface. Provides functionalities specific to Storage of OpenAB::...
Definition: CalendarStorage.hpp:28
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
SecureString class, used to store strings like passwords etc. Current implementation encodes string i...
Definition: SecureString.hpp:26
eCursorInit
Definition: CalDAVStorage.hpp:200
enum OpenAB_Storage::Storage::eGetRevisions getRevisions(std::map< std::string, std::string > &revisions)
Gets revision of the items from the Storage.
Definition: CalDAVStorage.cpp:504
enum OpenAB_Source::Source::eCancelRet cancel()
Cancels Source, if such operation is supported. After canceling Source next call to getVCard() should...
Definition: CalDAVStorage.cpp:608
eSuspendRet
Definition: Source.hpp:108
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: CalDAVStorage.cpp:576
The StorageItemIterator is mainly used to quickly browse the Storage contents.
Definition: StorageItem.hpp:97
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: CalDAVStorage.cpp:546
std::vector< OpenAB::PIMItem::ID > IDs
Definition: PIMItem.hpp:110
virtual ~CalDAVStorage()
Definition: CalDAVStorage.cpp:80
Class describing calendar.
Definition: CalDAVHelper.hpp:225
eGetItemRet
Definition: Source.hpp:155
PIMItemType
Definition: PIMItemIndex.hpp:24
eGetItem
Definition: Storage.hpp:226
eGetRevisions
Definition: Storage.hpp:265
OpenAB_Storage::StorageItem * next()
Retrieve the next StorageItem.
Definition: CalDAVStorage.cpp:759
virtual ~CalDAVStorageItemIterator()
Destructor, virtual by default.
Definition: CalDAVStorage.cpp:637
Definition: CalDAVStorage.hpp:54
Definition: CalDAVStorage.hpp:201
int getTotalCount() const
Returns total count of items available from Source, if such information is available.
Definition: CalDAVStorage.cpp:613
enum eGetItem getEvents(const OpenAB::PIMItem::IDs &ids, std::vector< OpenAB::SmartPtr< OpenAB::PIMCalendarEventItem > > &items)
Get the contacts from the Storage.
Definition: CalDAVStorage.cpp:376
eGetSyncToken
Definition: Storage.hpp:251
eInit
Definition: Source.hpp:94
std::string ID
Definition: PIMItem.hpp:64
Documentation for class CalDAVHelper. This class implements CalDAV client using libcurl.
Definition: CalDAVHelper.hpp:21
enum OpenAB_Source::Source::eInit init()
Initializes Source.
Definition: CalDAVStorage.cpp:122
unsigned int getSize() const
Retrieve number of items in interator.
Definition: CalDAVStorage.cpp:819
enum OpenAB_Source::Source::eResumeRet resume()
Resumes Source, if such operation is supported.
Definition: CalDAVStorage.cpp:603
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: CalDAVStorage.cpp:521
eRemoveItem
Definition: Storage.hpp:201
enum eAddItem addObjects(const std::vector< std::string > &iCals, OpenAB::PIMItem::IDs &newIds, OpenAB::PIMItem::Revisions &revisions)
Adds new contacts to the ContactsStorage.
Definition: CalDAVStorage.cpp:261
enum eGetItem getEvent(const OpenAB::PIMItem::ID &id, OpenAB::SmartPtr< OpenAB::PIMCalendarEventItem > &item)
Get the contact from the Storage.
Definition: CalDAVStorage.cpp:333
enum eAddItem addObject(const std::string &iCal, OpenAB::PIMItem::ID &newId, OpenAB::PIMItem::Revision &revision)
Adds a new contact to the ContactsStorage.
Definition: CalDAVStorage.cpp:250