1 // CardDAV2.h - CardDAV v2 class header
3 // (c) 2012-2016 Xestia Software Development.
5 // This file is part of Xestia Address Book.
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
19 #ifndef __CARDDAV2_CARDDAV2_H__
20 #define __CARDDAV2_CARDDAV2_H__
22 #include "../connobject/ConnectionObject.h"
23 #include "../version.h"
24 #include "../common/sslcertstructs.h"
25 #include "../common/dirs.h"
27 #include <curl/curl.h>
28 #include <wx/tokenzr.h>
30 #include <libxml/parser.h>
31 #include <libxml/tree.h>
36 class CardDAV2 : public ConnectionObject {
40 CardDAV2(std::string ServerAddress, int ServerPort, std::string ServerUser, std::string ServerPass, bool ServerSSL);
41 CardDAV2(std::string ServerAddress, int ServerPort, std::string ServerUser, std::string ServerPass, bool ServerSSL, std::string ServerPrefix, std::string ServerAccount);
47 // Functions from the ConnectionObject interface.
49 void SetupConnectionObject();
51 bool IsTaskCompleted();
53 COConnectResult Connect(bool DoAuthentication);
55 COServerResponse GetDefaultPrefix(std::string *ServerPrefix);
56 COServerResponse AddContact(std::string Location, std::string Data);
57 COServerResponse EditContact(std::string Location, std::string Data);
58 COServerResponse DeleteContact(std::string Location);
59 COServerResponse GetServerEntityTagValue(std::string Location);
60 COServerResponse GetContact(std::string Location, std::string *ContactData);
61 COContactList GetContactList(std::string SyncToken);
63 bool CanDoProcessing();
65 COSSLVerified SSLVerify();
67 bool HasValidResponse();
69 std::string GetErrorMessage();
71 #if defined(__APPLE__)
72 #elif defined(__WIN32__)
74 PCCERT_CONTEXT BuildSSLCollection();
77 SSLCertCollectionString BuildSSLCollection();
81 void BypassSSLVerification(bool EnableBypass);
83 struct CardDAV2PassObject {
84 CardDAV2 *CardDAV2Object = nullptr;
85 std::string *DataSetting = nullptr;
86 bool ServerUsingSSL = false;
87 CURL *ConnectionSessionObject = nullptr;
88 #if defined(__APPLE__)
89 #elif defined(__WIN32__)
90 PCCERT_CONTEXT SSLContext = nullptr;
97 // Variables to set for the CardDAV2 class.
99 CURL *ConnectionSession = nullptr;
100 CURLcode SessionResult = CURLE_OK;
101 struct curl_slist *HeaderList = nullptr;
103 void SetupDefaultParametersNonSSL(bool DoAuthentication);
104 void SetupDefaultParametersSSL(bool DoAuthentication);
106 std::string PageData;
107 std::string PageHeader;
108 char SessionErrorBuffer[CURL_ERROR_SIZE];
110 CardDAV2PassObject PageDataObject;
111 CardDAV2PassObject PageHeaderObject;
113 static size_t WritebackFunc(char *ptr, size_t size, size_t nmemb, void *stream);
114 size_t WritebackFuncImplementation(char *ptr, size_t size, size_t nmemb, void *stream);
116 std::string BuildURL(std::string URI);
118 std::vector<std::string> GetDAVHeader();
119 std::string GetETagHeader();
120 std::string GetETagValue();
122 std::string GetUserPrincipalURI();
123 std::string GetAddressBookHomeURI();
124 std::string GetDefaultAddressBookURI();
125 void ProcessContactData(COContactList *ContactList);
127 #if defined(__APPLE__)
128 #elif defined(__WIN32__)
130 PCCERT_CONTEXT CertificateData = nullptr;
135 void SetCertificateData();
137 bool EnableSSLBypass = false;