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"
41 // CalDAVConnectionData: used for
42 // connecting to the server.
44 enum CalDAVQueryResult {
45 CALDAVQUERYRESULT_UNITTESTFAIL = -1,
47 CALDAVQUERYRESULT_NOTRUN,
48 CALDAVQUERYRESULT_SERVERERROR,
49 CALDAVQUERYRESULT_SSLFAILURE,
52 struct CalDAVCalendarList {
57 map<int,string> description;
58 map<int,Colour> calColour;
60 map<int,string> tagURL;
64 struct CalDAVEntryList {
72 struct CalDAVConnectionData{
85 // CalDAVStatusData: used for
86 // getting the current server
87 // settings for the CalDAV
101 // CalDAVServerSupport: used for
102 // getting what the server supports
103 // from the CalDAV specification.
105 struct CalDAVServerSupport{
107 // Variable name. Name in CalDAV header.
109 bool basicSupport = false; // calendar-access
113 // CalDAVServerResult: used for
114 // getting the result of the
115 // request made via the CalDAV
118 struct CalDAVServerResult{
120 CalDAVQueryResult result = CALDAVQUERYRESULT_NOTRUN;
121 CURLcode code = CURLE_OK;
126 // CalDAVSendData: used for
127 // sending data to the CaLDAV
130 struct CalDAVSendData{
136 // Objects to move to a ConnectionObject-like interface in the future.
139 COSSL_UNITTESTFAIL = -1,
142 COSSL_UNABLETOVERIFY,
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,
164 string BuildServerAddress(CalDAVConnectionData *connData, string uriAddress);
165 void SetupDefaultParametersNonSSL(bool doAuthentication);
166 void SetupDefaultParametersSSL(bool doAuthentication);
169 CalDAVConnectionData connectionData;
170 CalDAVServerResult connectionServerResult;
171 CURL *connectionHandle = nullptr;
172 char sessionErrorBuffer[CURL_ERROR_SIZE];
173 string serverData = "";
174 string serverHeader = "";
176 COSSLVerified sslVerified;
177 bool enableSSLBypass = false;
178 bool sslSelfSigned = false;
179 bool sslStatus = false;
181 bool validResponse = false;
182 bool authPassed = false;
183 string errorMessage = "";
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);
196 CalDAVServerResult AddCalendar(string calendarName);
197 CalDAVServerResult AddCalendar(string *calendarName, string *calendarShortName);
199 CalDAVServerResult EditCalendar(string *calendarHREF,
200 string *calendarName,
201 Colour *calendarColour,
202 string *calendarDescription,
204 CalDAVServerResult EditCalendar(string *calendarHREF,
205 Colour *calendarColour);
206 CalDAVServerResult EditCalendar(string *calendarHREF,
207 string *calendarName);
208 CalDAVServerResult EditCalendar(string *calendarHREF,
210 CalDAVServerResult EditCalendarDescription(string *calendarHREF,
211 string *calendarDescription);
213 CalDAVServerResult DeleteCalendar(string *calendarHREF);
215 CalDAVServerResult AddEntry(string *calendarEntryHREF, string *entryData);
216 CalDAVServerResult EditEntry(string *calendarEntryHREF, string *entryData, string *entryETag);
217 CalDAVServerResult DeleteEntry(string *calendarEntryHREF);
219 string GetUserPrincipal();
220 string GetCalendarHome(string userPrincipalURI);
222 CalDAVServerResult GetEntryETag(string *calendarEntryHREF, string *eTagValue);
225 bool HasValidResponse();
228 std::string GetErrorMessage();
230 COSSLVerified SSLVerify();
231 void BypassSSLVerification(bool EnableBypass);
233 #if defined(__APPLE__)
235 SecTrustRef BuildSSLCollection();
237 #elif defined(__WIN32__)
239 PCCERT_CONTEXT BuildSSLCollection();
242 SSLCertCollectionString BuildSSLCollection();
247 // Subroutines that are used with the
248 // CalDAVConnectionData struct.
250 //bool CalDAVObjectValidSettings(CalDAVConnectionData *connData);