OpenAB  1.0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
CalDAVHelper.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 CALDAVHELPER_HPP_
11 #define CALDAVHELPER_HPP_
12 
13 #include "helpers/Http.hpp"
14 #include "DAVHelper.hpp"
15 #include "PIMItem/PIMItem.hpp"
16 
22 {
23  public:
31  CalDAVHelper(const std::string& serverUrl,
32  bool isCalendarUrl,
33  OpenAB::HttpSession* httpSession,
34  OpenAB::HttpAuthorizer* httpAuthorizer);
35 
39  virtual ~CalDAVHelper();
40 
46  bool findPrincipalUrl();
47 
53  bool findCalendarHomeSet();
54 
61  bool findCalendars();
62 
63  struct CalendarInfo;
72  bool queryCalendarInfo(const std::string& calendarURL,
73  CalendarInfo& info);
74 
81  bool queryCalendarMetadata(const std::string& calendarURL);
82 
89  bool queryEventsMetadata(const std::string& calendarURL);
90 
99  bool queryChangedEventsMetadata(const std::string& calendarURL,
100  const std::string& syncToken,
101  std::vector<OpenAB::PIMItem::ID>& removed);
102 
114  bool downloadEvents(const std::string& calendarURL,
115  unsigned int offset, unsigned int size,
116  std::vector<std::string>& icals);
117 
125  bool downloadEvents(const std::string& calendarURL,
126  std::vector<std::string>& uris,
127  std::vector<std::string>& icals);
128 
142  bool addEvent(const std::string& calendarURL,
143  const std::string& ical,
144  std::string& uri,
145  std::string& etag);
146 
156  bool removeEvent(const std::string& uri,
157  const std::string& etag="");
158 
167  bool modifyEvent(const std::string& uri,
168  const std::string& ical,
169  std::string& etag);
170 
175  unsigned int getTotalCount() const
176  {
177  return eventsMetadata.size();
178  }
179 
184  std::string getSyncToken() const
185  {
186  return calendarSyncToken;
187  }
188 
192  typedef struct
193  {
194  /*Current ETAG (revision) of item*/
195  std::string etag;
196  /*Item Uri that uniquely identifies item on server*/
197  std::string uri;
198  } EventMetadata;
199 
200  typedef std::vector<EventMetadata> EventsMetadata;
201 
208  {
209  return eventsMetadata;
210  }
211 
216  {
217  EVENT = 0, //< Event
218  TODO, //< Task
219  JOURNAL //< Journal/Memo
220  };
221 
226  {
227  public:
228  CalendarInfo();
229  CalendarInfo(const std::string& url,
230  const std::string& name,
231  const std::vector<CalendarItemTypes>& types);
232  ~CalendarInfo();
233 
238  std::string getUrl() const;
239 
244  std::string getDisplayName() const;
245 
250  bool supportsType(CalendarItemTypes type) const;
251 
256  std::vector<CalendarItemTypes> getSupportedCalendarTypes() const;
257 
258  private:
259  std::string url;
260  std::string displayName;
261 
262  std::vector<CalendarItemTypes> supportedTypes;
263  };
264 
265  typedef std::vector<CalendarInfo> Calendars;
266 
272  {
273  return calendars;
274  }
275 
276  private:
280  CalDAVHelper(CalDAVHelper const &other);
281 
285  CalDAVHelper& operator=(CalDAVHelper const &other);
286 
287  //CalDAV server url
288  std::string serverUrl;
289 
290  //Parsed part of server url containing only host address
291  std::string serverHostUrl;
292 
293  std::string principalUrl;
294  std::string principalCalendarHomeSetUrl;
295  std::string principalCalendarSetHostUrl;
296  std::string principalCalendarUrl;
297 
298  //list of available calendars
299  Calendars calendars;
300 
307  int getIndexFromUris(const std::vector<std::string>& uris, const std::string& uri);
308 
317  bool processCalendarsInfo(const std::string& davResponse,
318  Calendars& cals);
319 
320  DAVHelper davHelper;
321  OpenAB::HttpSession* httpSession;
322  OpenAB::HttpAuthorizer* httpAuthorizer;
323 
324  EventsMetadata eventsMetadata;
325  std::string calendarCTag;
326  std::string calendarSyncToken;
327 
328  std::string userAgent;
329 };
330 
331 #endif // CALDAVHELPER_HPP_
bool queryCalendarMetadata(const std::string &calendarURL)
Queries calendar metadata (current revision and sync token). After calling this function sync token c...
Definition: CalDAVHelper.cpp:319
Definition: CalDAVHelper.hpp:219
EventsMetadata getEventsMetadata() const
Returns contacts metadata downlaoded by queryContactsMetadata or queryChangedEventsMetadata.
Definition: CalDAVHelper.hpp:207
std::vector< EventMetadata > EventsMetadata
Definition: CalDAVHelper.hpp:200
HttpSession class. Allows to send Http requests.
Definition: Http.hpp:26
bool queryCalendarInfo(const std::string &calendarURL, CalendarInfo &info)
Queries calendar infromation. In opposite to findCalendars, this function queries detailed informatio...
Definition: CalDAVHelper.cpp:275
std::string getSyncToken() const
Returns sync token queried by queryCalendarMetadata().
Definition: CalDAVHelper.hpp:184
bool queryChangedEventsMetadata(const std::string &calendarURL, const std::string &syncToken, std::vector< OpenAB::PIMItem::ID > &removed)
Queries only metadata of events/tasks that were modified since provided sync token was created...
Definition: CalDAVHelper.cpp:420
HttpAuthorizer interface. This should be used by classes implementing different Http authorization me...
Definition: Http.hpp:334
std::vector< CalendarInfo > Calendars
Definition: CalDAVHelper.hpp:265
Definition: CalDAVHelper.hpp:217
bool findCalendars()
Queries calendars information. Queried information about calendars can be obtained by getCalendars...
Definition: CalDAVHelper.cpp:206
bool findPrincipalUrl()
Queries principal url - url used by given user to send CalDAV requests.
Definition: CalDAVHelper.cpp:41
std::string etag
Definition: CalDAVHelper.hpp:195
bool modifyEvent(const std::string &uri, const std::string &ical, std::string &etag)
Modifies event/task.
Definition: CalDAVHelper.cpp:792
Definition: CalDAVHelper.hpp:218
bool removeEvent(const std::string &uri, const std::string &etag="")
Removes event/task.
Definition: CalDAVHelper.cpp:755
bool downloadEvents(const std::string &calendarURL, unsigned int offset, unsigned int size, std::vector< std::string > &icals)
Downloads iCalendar objects from metadata.
Definition: CalDAVHelper.cpp:573
Class describing calendar.
Definition: CalDAVHelper.hpp:225
CalendarItemTypes
Definition: CalDAVHelper.hpp:215
std::string uri
Definition: CalDAVHelper.hpp:197
bool addEvent(const std::string &calendarURL, const std::string &ical, std::string &uri, std::string &etag)
Creates new event/task.
Definition: CalDAVHelper.cpp:643
std::string getDisplayName() const
Returns display name of calendar.
Definition: CalDAVHelper.cpp:893
Calendars getCalendars() const
Returns list of available calendars.
Definition: CalDAVHelper.hpp:271
CalendarInfo()
Definition: CalDAVHelper.cpp:870
std::string getUrl() const
Returns URL of calendar.
Definition: CalDAVHelper.cpp:888
bool findCalendarHomeSet()
Queries address book set - url that can be further queried about user calendars details..
Definition: CalDAVHelper.cpp:102
bool supportsType(CalendarItemTypes type) const
Checks if calendar support given type of items.
Definition: CalDAVHelper.cpp:903
std::vector< CalendarItemTypes > getSupportedCalendarTypes() const
Returns list of all supported types.
Definition: CalDAVHelper.cpp:898
~CalendarInfo()
Definition: CalDAVHelper.cpp:875
Documentation for class CalDAVHelper. This class implements CalDAV client using libcurl.
Definition: CalDAVHelper.hpp:21
bool queryEventsMetadata(const std::string &calendarURL)
Queries events/tasks metadata (list of IDs and revisions). After calling this function metadata can b...
Definition: CalDAVHelper.cpp:369
virtual ~CalDAVHelper()
Destructor, virtual by default.
Definition: CalDAVHelper.cpp:37
Helper class handling DAV responses parsing.
Definition: DAVHelper.hpp:22
unsigned int getTotalCount() const
Returns total count of items in metadata downlaoded by queryEventsMetadata or queryChangedEventsMetad...
Definition: CalDAVHelper.hpp:175
Simple struct describing items in metadata.
Definition: CalDAVHelper.hpp:192
CalDAVHelper(const std::string &serverUrl, bool isCalendarUrl, OpenAB::HttpSession *httpSession, OpenAB::HttpAuthorizer *httpAuthorizer)
Constructor.
Definition: CalDAVHelper.cpp:15