1 // CalDAV.h - CalDAV Connection Object header.
3 // (c) 2016-2017 Xestia Software Development.
5 // This file is part of Xestia Calendar.
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.
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.
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>
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 #if defined (__APPLE__)
40 #import <Foundation/Foundation.h>
41 #import <SecurityInterface/SFCertificateTrustPanel.h>
44 #if defined(__WIN32__)
45 #include "../common/win32ssl.h"
50 // CalDAVConnectionData: used for
51 // connecting to the server.
53 enum CalDAVQueryResult {
54 CALDAVQUERYRESULT_UNITTESTFAIL = -1,
56 CALDAVQUERYRESULT_NOTRUN,
57 CALDAVQUERYRESULT_SERVERERROR,
58 CALDAVQUERYRESULT_SSLFAILURE,
61 struct CalDAVCalendarList {
66 map<int,string> description;
67 map<int,Colour> calColour;
69 map<int,string> tagURL;
73 struct CalDAVEntryList {
81 struct CalDAVConnectionData{
94 // CalDAVStatusData: used for
95 // getting the current server
96 // settings for the CalDAV
110 // CalDAVServerSupport: used for
111 // getting what the server supports
112 // from the CalDAV specification.
114 struct CalDAVServerSupport{
116 // Variable name. Name in CalDAV header.
118 bool basicSupport = false; // calendar-access
122 // CalDAVServerResult: used for
123 // getting the result of the
124 // request made via the CalDAV
127 struct CalDAVServerResult{
129 CalDAVQueryResult result = CALDAVQUERYRESULT_NOTRUN;
130 CURLcode code = CURLE_OK;
135 // CalDAVSendData: used for
136 // sending data to the CaLDAV
139 struct CalDAVSendData{
145 // Objects to move to a ConnectionObject-like interface in the future.
148 COSSL_UNITTESTFAIL = -1,
151 COSSL_UNABLETOVERIFY,
159 string ProcessXMLUserPrincipal();
160 string ProcessXMLCalendarHome();
161 CalDAVCalendarList ProcessXMLCalendarList();
162 CalDAVEntryList ProcessXMLEntryList();
163 CalDAVEntryList ProcessXMLSyncTokenList();
164 string ProcessXMLEntryETag();
165 bool MatchXMLNameTransverse(xmlNodePtr *nodePtr, string nodeName);
166 bool MatchXMLName(xmlNodePtr *nodePtrOriginal, string nodeName);
167 string FetchXMLData(xmlNodePtr *nodePtr);
168 CalDAVServerResult EditCalendarProcess(string *calendarHREF,
169 string *calendarName,
170 Colour *calendarColour,
171 string *calendarDescription,
173 string BuildServerAddress(CalDAVConnectionData *connData, string uriAddress);
174 void SetupDefaultParametersNonSSL(bool doAuthentication);
175 void SetupDefaultParametersSSL(bool doAuthentication);
178 static size_t CalDAVReceive(char *receivedBuffer, size_t size, size_t newMemoryBytes, void *stream);
180 CalDAVConnectionData connectionData;
181 CalDAVServerResult connectionServerResult;
182 CURL *connectionHandle = nullptr;
183 char sessionErrorBuffer[CURL_ERROR_SIZE];
184 string serverData = "";
185 string serverHeader = "";
187 COSSLVerified sslVerified;
188 bool enableSSLBypass = false;
189 bool sslSelfSigned = false;
190 bool sslStatus = false;
192 bool validResponse = false;
193 bool authPassed = false;
194 string errorMessage = "";
196 #if defined(__APPLE__)
197 SecTrustRef certificateData = nullptr;
198 #elif defined(__WIN32__)
199 PCCERT_CONTEXT certificateData = nullptr;
204 void SetupConnectionData(CalDAVConnectionData *connData);
205 CalDAVStatus GetConnectionData();
206 CalDAVServerResult Connect(bool doAuthentication);
207 CalDAVServerResult GetServerResult();
208 CalDAVServerSupport GetServerSupport();
209 CalDAVCalendarList GetCalendars();
210 CalDAVEntryList GetEntryList(string *calendarHREF);
211 CalDAVEntryList GetEntryList(string *calendarHREF, string *calendarTag);
213 CalDAVServerResult AddCalendar(string calendarName);
214 CalDAVServerResult AddCalendar(string *calendarName, string *calendarShortName);
216 CalDAVServerResult EditCalendar(string *calendarHREF,
217 string *calendarName,
218 Colour *calendarColour,
219 string *calendarDescription,
221 CalDAVServerResult EditCalendar(string *calendarHREF,
222 Colour *calendarColour);
223 CalDAVServerResult EditCalendar(string *calendarHREF,
224 string *calendarName);
225 CalDAVServerResult EditCalendar(string *calendarHREF,
227 CalDAVServerResult EditCalendarDescription(string *calendarHREF,
228 string *calendarDescription);
230 CalDAVServerResult DeleteCalendar(string *calendarHREF);
232 CalDAVServerResult AddEntry(string *calendarEntryHREF, string *entryData);
233 CalDAVServerResult EditEntry(string *calendarEntryHREF, string *entryData, string *entryETag);
234 CalDAVServerResult DeleteEntry(string *calendarEntryHREF);
236 string GetUserPrincipal();
237 string GetCalendarHome(string userPrincipalURI);
239 CalDAVServerResult GetEntryETag(string *calendarEntryHREF, string *eTagValue);
242 bool HasValidResponse();
245 std::string GetErrorMessage();
247 COSSLVerified SSLVerify();
248 void BypassSSLVerification(bool EnableBypass);
250 #if defined(__APPLE__)
252 SecTrustRef BuildSSLCollection();
254 #elif defined(__WIN32__)
256 PCCERT_CONTEXT BuildSSLCollection();
259 SSLCertCollectionString BuildSSLCollection();
263 struct CalDAVPassObject {
264 CalDAV *CalDAVObject = nullptr;
265 std::string *DataSetting = nullptr;
266 bool ServerUsingSSL = false;
267 CURL *ConnectionSessionObject = nullptr;
268 #if defined(__APPLE__)
269 SecTrustRef SSLContext = nullptr;
270 #elif defined (__WIN32__)
271 PCCERT_CONTEXT SSLContext = nullptr;
276 CalDAVPassObject PageDataObject;
277 CalDAVPassObject PageHeaderObject;
280 // Subroutines that are used with the
281 // CalDAVConnectionData struct.
283 //bool CalDAVObjectValidSettings(CalDAVConnectionData *connData);