OpenAB  1.0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
CardDAVHelper.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 CARDDAVHELPER_HPP_
11 #define CARDDAVHELPER_HPP_
12 
13 #include "helpers/Http.hpp"
14 #include "DAVHelper.hpp"
15 #include "PIMItem/PIMItem.hpp"
20 {
21  public:
25  CardDAVHelper(const std::string& serverUrl,
26  OpenAB::HttpSession* httpSession,
27  OpenAB::HttpAuthorizer* httpAuthorizer);
28 
32  virtual ~CardDAVHelper();
33 
39  bool findPrincipalUrl();
40 
46  bool findAddressbookSet();
47 
53  bool findAddressbooks();
54 
61 
67  bool queryContactsMetadata();
68 
74  bool queryChangedContactsMetadata(const std::string& syncToken,
75  std::vector<OpenAB::PIMItem::ID>& removed);
76 
86  bool downloadVCards(unsigned int offset, unsigned int size,
87  std::vector<std::string>& vcards);
88 
95  bool downloadVCards(std::vector<std::string>& uris,
96  std::vector<std::string>& vcards);
97 
105  bool addContact(const std::string& vcard,
106  std::string& uri,
107  std::string& etag);
108 
115  bool removeContact(const std::string& uri,
116  const std::string& etag="");
117 
125  bool modifyContact(const std::string& uri,
126  const std::string& vcard,
127  std::string& etag);
128 
133  unsigned int getTotalCount() const
134  {
135  return contactsMetadata.size();
136  }
137 
142  std::string getSyncToken() const
143  {
144  return addressbookSyncToken;
145  }
146 
147  typedef struct
148  {
149  std::string etag;
150  std::string uri;
151  } ContactMetadata;
152 
153  typedef std::vector<ContactMetadata> ContactsMetadata;
154 
161  {
162  return contactsMetadata;
163  }
164 
165  private:
169  CardDAVHelper(CardDAVHelper const &other);
170 
174  CardDAVHelper& operator=(CardDAVHelper const &other);
175 
176  std::string serverUrl;
177  std::string serverHostUrl;
178  std::string principalUrl;
179  std::string principalAddressbookSetUrl;
180  std::string principalAddressbookSetHostUrl;
181  std::string principalAddressbookUrl;
182 
183  DAVHelper davHelper;
184  OpenAB::HttpSession* httpSession;
185  OpenAB::HttpAuthorizer* httpAuthorizer;
186 
187  ContactsMetadata contactsMetadata;
188  std::string addressbookCTag;
189  std::string addressbookSyncToken;
190 };
191 
192 #endif // CARDDAVHELPER_HPP_
Documentation for class CardDAVHelper.
Definition: CardDAVHelper.hpp:19
HttpSession class. Allows to send Http requests.
Definition: Http.hpp:26
bool findAddressbookSet()
Query address book set.
Definition: CardDAVHelper.cpp:88
bool modifyContact(const std::string &uri, const std::string &vcard, std::string &etag)
Modifies contact.
Definition: CardDAVHelper.cpp:673
unsigned int getTotalCount() const
Returns total count of contacts metadata downlaoded by queryContactsMetadata or queryChangedContactsM...
Definition: CardDAVHelper.hpp:133
HttpAuthorizer interface. This should be used by classes implementing different Http authorization me...
Definition: Http.hpp:334
bool downloadVCards(unsigned int offset, unsigned int size, std::vector< std::string > &vcards)
Download vCards of contacts from metadata.
Definition: CardDAVHelper.cpp:466
bool removeContact(const std::string &uri, const std::string &etag="")
Removes contact.
Definition: CardDAVHelper.cpp:635
bool findAddressbooks()
Query address books.
Definition: CardDAVHelper.cpp:150
bool queryContactsMetadata()
Query contacts metadata (list of IDs and revisions). After calling this function metadata can be obta...
Definition: CardDAVHelper.cpp:259
bool addContact(const std::string &vcard, std::string &uri, std::string &etag)
Uploads contact.
Definition: CardDAVHelper.cpp:557
std::string getSyncToken() const
Returns sync token queried by queryAddressbookMetadata().
Definition: CardDAVHelper.hpp:142
ContactsMetadata getContactsMetadata() const
Returns contacts metadata downlaoded by queryContactsMetadata or queryChangedContactsMetadata.
Definition: CardDAVHelper.hpp:160
bool findPrincipalUrl()
Query principal url.
Definition: CardDAVHelper.cpp:29
CardDAVHelper(const std::string &serverUrl, OpenAB::HttpSession *httpSession, OpenAB::HttpAuthorizer *httpAuthorizer)
Constructor.
Definition: CardDAVHelper.cpp:15
Definition: CardDAVHelper.hpp:147
std::string uri
Definition: CardDAVHelper.hpp:150
bool queryAddressbookMetadata()
Query address book metadata (current revision and sync token). After calling this function sync token...
Definition: CardDAVHelper.cpp:210
std::vector< ContactMetadata > ContactsMetadata
Definition: CardDAVHelper.hpp:153
Helper class handling DAV responses parsing.
Definition: DAVHelper.hpp:22
bool queryChangedContactsMetadata(const std::string &syncToken, std::vector< OpenAB::PIMItem::ID > &removed)
Query contacts metadta only of contact that were modified since sync token. After calling this functi...
Definition: CardDAVHelper.cpp:310
virtual ~CardDAVHelper()
Destructor, virtual by default.
Definition: CardDAVHelper.cpp:25
std::string etag
Definition: CardDAVHelper.hpp:149