Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Updated CardDAV2/ConnectionObject implementation
[xestiaab/.git] / source / carddav2 / carddav2.h
1 // CardDAV2.h - CardDAV v2 class header
2 //
3 // (c) 2012-2016 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
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.
10 //
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.
15 //
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>
29 #include <wx/file.h>
30 #include <libxml/parser.h>
31 #include <libxml/tree.h>
33 #include <string>
34 #include <vector>
36 class CardDAV2 : public ConnectionObject {
37         
38         public:
39         
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);
43                 // Destructor.
44         
45                 ~CardDAV2();
46         
47                 // Functions from the ConnectionObject interface.
48         
49                 void SetupConnectionObject();
50                 
51                 bool IsTaskCompleted();
52                 
53                 COConnectResult Connect(bool DoAuthentication);
54                 
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);
62         
63                 bool CanDoProcessing();
64                 bool CanDoSSL();
65                 COSSLVerified SSLVerify();
66                 bool AbleToLogin();
67                 bool HasValidResponse();
68                 bool IsSelfSigned();
69                 std::string GetErrorMessage();
71 #if defined(__APPLE__)
72     
73                 SecTrustRef BuildSSLCollection();
74     
75 #elif defined(__WIN32__)
77                 PCCERT_CONTEXT BuildSSLCollection();
79 #else
80                 SSLCertCollectionString BuildSSLCollection();
82 #endif
84                 void BypassSSLVerification(bool EnableBypass);
85         
86                 struct CardDAV2PassObject {
87                         CardDAV2 *CardDAV2Object = nullptr;
88                         std::string *DataSetting = nullptr;
89                         bool ServerUsingSSL = false;
90                         CURL *ConnectionSessionObject = nullptr;
91 #if defined(__APPLE__)
92                         SecTrustRef SSLContext = nullptr;
93 #elif defined(__WIN32__)
94                         PCCERT_CONTEXT SSLContext = nullptr;
95 #endif
96                 };
98         protected:
99         private:
100                 
101                 // Variables to set for the CardDAV2 class.
102                 
103                 CURL *ConnectionSession = nullptr;
104                 CURLcode SessionResult = CURLE_OK;
105                 struct curl_slist *HeaderList = nullptr;
106         
107                 void SetupDefaultParametersNonSSL(bool DoAuthentication);
108                 void SetupDefaultParametersSSL(bool DoAuthentication);
109         
110                 std::string PageData;
111                 std::string PageHeader;
112                 char SessionErrorBuffer[CURL_ERROR_SIZE];
113         
114                 CardDAV2PassObject PageDataObject;
115                 CardDAV2PassObject PageHeaderObject;
117                 static size_t WritebackFunc(char *ptr, size_t size, size_t nmemb, void *stream);
118                 size_t WritebackFuncImplementation(char *ptr, size_t size, size_t nmemb, void *stream);
119         
120                 std::string BuildURL(std::string URI);
121                 void ResetResults();
122                 std::vector<std::string> GetDAVHeader();
123                 std::string GetETagHeader();
124                 std::string GetETagValue();
125         
126                 std::string GetUserPrincipalURI();
127                 std::string GetAddressBookHomeURI();
128                 std::string GetDefaultAddressBookURI();
129                 void ProcessContactData(COContactList *ContactList);
131 #if defined(__APPLE__)
133                 SecTrustRef CertificateData = nullptr;
134         
135 #elif defined(__WIN32__)
137                 PCCERT_CONTEXT CertificateData = nullptr;
139 #else
140 #endif
141         
142                 void SetCertificateData();
144                 bool EnableSSLBypass = false;
146 };
148 #endif
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy