Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
CardDAV2/CDO: Cleaned up headers and included stdexcept
[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>
35 #include <stdexcept>
37 class CardDAV2 : public ConnectionObject {
38         
39         public:
40         
41                 CardDAV2(std::string ServerAddress, int ServerPort, std::string ServerUser, std::string ServerPass, bool ServerSSL);
42                 CardDAV2(std::string ServerAddress, int ServerPort, std::string ServerUser, std::string ServerPass, bool ServerSSL, std::string ServerPrefix, std::string ServerAccount);
44                 // Destructor.
45         
46                 ~CardDAV2();
47         
48                 // Functions from the ConnectionObject interface.
49         
50                 void SetupConnectionObject();
51                 
52                 bool IsTaskCompleted();
53                 
54                 COConnectResult Connect(bool DoAuthentication);
55                 
56                 COServerResponse GetDefaultPrefix(std::string *ServerPrefix);
57                 COServerResponse AddContact(std::string Location, std::string Data);
58                 COServerResponse EditContact(std::string Location, std::string Data);
59                 COServerResponse DeleteContact(std::string Location);
60                 COServerResponse GetServerEntityTagValue(std::string Location);
61                 COServerResponse GetContact(std::string Location, std::string *ContactData);
62                 COContactList GetContactList(std::string SyncToken);
63         
64                 bool CanDoProcessing();
65                 bool CanDoSSL();
66                 COSSLVerified SSLVerify();
67                 bool AbleToLogin();
68                 bool HasValidResponse();
69                 bool IsSelfSigned();
70                 std::string GetErrorMessage();
72 #if defined(__APPLE__)
73     
74                 SecTrustRef BuildSSLCollection();
75     
76 #elif defined(__WIN32__)
78                 PCCERT_CONTEXT BuildSSLCollection();
80 #else
81                 SSLCertCollectionString BuildSSLCollection();
83 #endif
85                 void BypassSSLVerification(bool EnableBypass);
86         
87                 struct CardDAV2PassObject {
88                         CardDAV2 *CardDAV2Object = nullptr;
89                         std::string *DataSetting = nullptr;
90                         bool ServerUsingSSL = false;
91                         CURL *ConnectionSessionObject = nullptr;
92 #if defined(__APPLE__)
93                         SecTrustRef SSLContext = nullptr;
94 #elif defined(__WIN32__)
95                         PCCERT_CONTEXT SSLContext = nullptr;
96 #endif
97                 };
99         protected:
100         private:
101                 
102                 // Variables to set for the CardDAV2 class.
103                 
104                 CURL *ConnectionSession = nullptr;
105                 CURLcode SessionResult = CURLE_OK;
106                 struct curl_slist *HeaderList = nullptr;
107         
108                 void SetupDefaultParametersNonSSL(bool DoAuthentication);
109                 void SetupDefaultParametersSSL(bool DoAuthentication);
110         
111                 std::string PageData;
112                 std::string PageHeader;
113                 char SessionErrorBuffer[CURL_ERROR_SIZE];
114         
115                 CardDAV2PassObject PageDataObject;
116                 CardDAV2PassObject PageHeaderObject;
118                 static size_t WritebackFunc(char *ptr, size_t size, size_t nmemb, void *stream);
119                 size_t WritebackFuncImplementation(char *ptr, size_t size, size_t nmemb, void *stream);
120         
121                 std::string BuildURL(std::string URI);
122                 void ResetResults();
123                 std::vector<std::string> GetDAVHeader();
124                 std::string GetETagHeader();
125                 std::string GetETagValue();
126         
127                 std::string GetUserPrincipalURI();
128                 std::string GetAddressBookHomeURI();
129                 std::string GetDefaultAddressBookURI();
130                 void ProcessContactData(COContactList *ContactList);
132 #if defined(__APPLE__)
134                 SecTrustRef CertificateData = nullptr;
135         
136 #elif defined(__WIN32__)
138                 PCCERT_CONTEXT CertificateData = nullptr;
140 #else
141 #endif
142         
143                 void SetCertificateData();
145                 bool EnableSSLBypass = false;
147 };
149 #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