Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
CalDAV: Implemented SSL support (taken from XAB)
[xestiacalendar/.git] / source / objects / CalDAV / CalDAV.h
1 // CalDAV.h - CalDAV Connection Object header.
2 //
3 // (c) 2016-2017 Xestia Software Development.
4 //
5 // This file is part of Xestia Calendar.
6 //
7 // Xestia Calendar 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 Calendar 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 Calendar. If not, see <http://www.gnu.org/licenses/>
19 #ifndef __OBJECTS_CALDAV_CALDAV_H__
20 #define __OBJECTS_CALDAV_CALDAV_H__
22 #include <curl/curl.h>
23 #include <libxml/parser.h>
24 #include <libxml/tree.h>
25 #include <wx/tokenzr.h>
26 #include <wx/file.h>
27 #include <string>
28 #include <iostream>
29 #include <vector>
30 #include <stdexcept>
31 #include <map>
32 #include "../../common/colour.h"
33 #include "../../common/text.h"
34 #include "../../common/uuid.h"
35 #include "../../common/dirs.h"
36 #include "../../common/sslcertstructs.h"
37 #include "../../version.h"
39 using namespace std;
41 // CalDAVConnectionData: used for
42 // connecting to the server.
44 enum CalDAVQueryResult {
45         CALDAVQUERYRESULT_UNITTESTFAIL = -1,
46         CALDAVQUERYRESULT_OK,
47         CALDAVQUERYRESULT_NOTRUN,
48         CALDAVQUERYRESULT_SERVERERROR,
49         CALDAVQUERYRESULT_SSLFAILURE,
50 };
52 struct CalDAVCalendarList {
54         map<int,string> name;
55         map<int,string> href;
56         map<int,int> order;
57         map<int,string> description;
58         map<int,Colour> calColour;
59         map<int,string> tag;
60         map<int,string> tagURL;
61         
62 };
64 struct CalDAVEntryList {
65         
66         map<int,string> href;
67         map<int,string> data;
68         map<int,string> tag;
69         
70 };
72 struct CalDAVConnectionData{
73         
74         string hostname = "";
75         int port = 8008;
76         string username = "";
77         string password = "";
78         string prefix = "";
79         bool useSSL = true;
80         int timeout = 60;
81         string account = "";
82         
83 };
85 // CalDAVStatusData: used for
86 // getting the current server
87 // settings for the CalDAV
88 // object.
90 struct CalDAVStatus{
92         string hostname;
93         int port;
94         string username;
95         string prefix;
96         bool useSSL;    
97         int timeout;
99 };
101 // CalDAVServerSupport: used for
102 // getting what the server supports
103 // from the CalDAV specification.
105 struct CalDAVServerSupport{
106         
107         // Variable name.                          Name in CalDAV header.
108         
109         bool basicSupport = false;              // calendar-access
110         
111 };
113 // CalDAVServerResult: used for
114 // getting the result of the
115 // request made via the CalDAV
116 // object.
118 struct CalDAVServerResult{
120         CalDAVQueryResult result = CALDAVQUERYRESULT_NOTRUN;
121         CURLcode code = CURLE_OK;
122         long httpCode = 0;
123         
124 };
126 // CalDAVSendData: used for
127 // sending data to the CaLDAV
128 // server.
130 struct CalDAVSendData{
131         string *readptr;
132         long sizeleft;
133         int seek = 0;
134 };
136 // Objects to move to a ConnectionObject-like interface in the future.
138 enum COSSLVerified {
139         COSSL_UNITTESTFAIL = -1,
140         COSSL_VERIFIED,
141         COSSL_VERIFIED_USER,
142         COSSL_UNABLETOVERIFY,
143         COSSL_NOTAPPLICABLE,
144         COSSL_NORESULT
145 };
147 class CalDAV{
149         private:
150                 string ProcessXMLUserPrincipal();
151                 string ProcessXMLCalendarHome();
152                 CalDAVCalendarList ProcessXMLCalendarList();
153                 CalDAVEntryList ProcessXMLEntryList();
154                 CalDAVEntryList ProcessXMLSyncTokenList();
155                 string ProcessXMLEntryETag();
156                 bool MatchXMLNameTransverse(xmlNodePtr *nodePtr, string nodeName);
157                 bool MatchXMLName(xmlNodePtr *nodePtrOriginal, string nodeName);
158                 string FetchXMLData(xmlNodePtr *nodePtr);
159                 CalDAVServerResult EditCalendarProcess(string *calendarHREF,
160                         string *calendarName,
161                         Colour *calendarColour,
162                         string *calendarDescription,
163                         int *calendarOrder);
164                 string BuildServerAddress(CalDAVConnectionData *connData, string uriAddress);
165                 void SetupDefaultParametersNonSSL(bool doAuthentication);
166                 void SetupDefaultParametersSSL(bool doAuthentication);
167                 void ResetResults();
168         
169                 CalDAVConnectionData connectionData;
170                 CalDAVServerResult connectionServerResult;
171                 CURL *connectionHandle = nullptr;
172                 char sessionErrorBuffer[CURL_ERROR_SIZE];
173                 string serverData = "";
174                 string serverHeader = "";
175         
176                 COSSLVerified sslVerified;
177                 bool enableSSLBypass = false;
178                 bool sslSelfSigned = false;
179                 bool sslStatus = false;
180                 
181                 bool validResponse = false;
182                 bool authPassed = false;
183                 string errorMessage = "";
184         public:
185                 CalDAV();
186                 ~CalDAV();
187                 void SetupConnectionData(CalDAVConnectionData *connData);
188                 CalDAVStatus GetConnectionData();
189                 CalDAVServerResult Connect(bool doAuthentication);
190                 CalDAVServerResult GetServerResult();
191                 CalDAVServerSupport GetServerSupport();
192                 CalDAVCalendarList GetCalendars();
193                 CalDAVEntryList GetEntryList(string *calendarHREF);
194                 CalDAVEntryList GetEntryList(string *calendarHREF, string *calendarTag);
195         
196                 CalDAVServerResult AddCalendar(string calendarName);
197                 CalDAVServerResult AddCalendar(string *calendarName, string *calendarShortName);
198         
199                 CalDAVServerResult EditCalendar(string *calendarHREF,
200                         string *calendarName,
201                         Colour *calendarColour,
202                         string *calendarDescription,
203                         int *calendarOrder);
204                 CalDAVServerResult EditCalendar(string *calendarHREF,
205                         Colour *calendarColour);
206                 CalDAVServerResult EditCalendar(string *calendarHREF,
207                         string *calendarName);
208                 CalDAVServerResult EditCalendar(string *calendarHREF,
209                         int *calendarOrder);
210                 CalDAVServerResult EditCalendarDescription(string *calendarHREF,
211                         string *calendarDescription);
212                 
213                 CalDAVServerResult DeleteCalendar(string *calendarHREF);
214                 
215                 CalDAVServerResult AddEntry(string *calendarEntryHREF, string *entryData);
216                 CalDAVServerResult EditEntry(string *calendarEntryHREF, string *entryData, string *entryETag);
217                 CalDAVServerResult DeleteEntry(string *calendarEntryHREF);
218         
219                 string GetUserPrincipal();
220                 string GetCalendarHome(string userPrincipalURI);
221                 
222                 CalDAVServerResult GetEntryETag(string *calendarEntryHREF, string *eTagValue);
224                 bool CanDoSSL();
225                 bool HasValidResponse();
226                 bool AbleToLogin();
227                 bool IsSelfSigned();
228                 std::string GetErrorMessage();
230                 COSSLVerified SSLVerify();
231                 void BypassSSLVerification(bool EnableBypass);
232                 
233 #if defined(__APPLE__)
234     
235                 SecTrustRef BuildSSLCollection();
236     
237 #elif defined(__WIN32__)
239                 PCCERT_CONTEXT BuildSSLCollection();
241 #else
242                 SSLCertCollectionString BuildSSLCollection();
244 #endif
245 };
247 // Subroutines that are used with the 
248 // CalDAVConnectionData struct.
250 //bool CalDAVObjectValidSettings(CalDAVConnectionData *connData);
252 #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