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(__WIN32__)
40 #include "../common/win32ssl.h"
45 // CalDAVConnectionData: used for
46 // connecting to the server.
48 enum CalDAVQueryResult {
49 CALDAVQUERYRESULT_UNITTESTFAIL = -1,
51 CALDAVQUERYRESULT_NOTRUN,
52 CALDAVQUERYRESULT_SERVERERROR,
53 CALDAVQUERYRESULT_SSLFAILURE,
56 struct CalDAVCalendarList {
61 map<int,string> description;
62 map<int,Colour> calColour;
64 map<int,string> tagURL;
68 struct CalDAVEntryList {
76 struct CalDAVConnectionData{
89 // CalDAVStatusData: used for
90 // getting the current server
91 // settings for the CalDAV
105 // CalDAVServerSupport: used for
106 // getting what the server supports
107 // from the CalDAV specification.
109 struct CalDAVServerSupport{
111 // Variable name. Name in CalDAV header.
113 bool basicSupport = false; // calendar-access
117 // CalDAVServerResult: used for
118 // getting the result of the
119 // request made via the CalDAV
122 struct CalDAVServerResult{
124 CalDAVQueryResult result = CALDAVQUERYRESULT_NOTRUN;
125 CURLcode code = CURLE_OK;
130 // CalDAVSendData: used for
131 // sending data to the CaLDAV
134 struct CalDAVSendData{
140 // Objects to move to a ConnectionObject-like interface in the future.
143 COSSL_UNITTESTFAIL = -1,
146 COSSL_UNABLETOVERIFY,
154 string ProcessXMLUserPrincipal();
155 string ProcessXMLCalendarHome();
156 CalDAVCalendarList ProcessXMLCalendarList();
157 CalDAVEntryList ProcessXMLEntryList();
158 CalDAVEntryList ProcessXMLSyncTokenList();
159 string ProcessXMLEntryETag();
160 bool MatchXMLNameTransverse(xmlNodePtr *nodePtr, string nodeName);
161 bool MatchXMLName(xmlNodePtr *nodePtrOriginal, string nodeName);
162 string FetchXMLData(xmlNodePtr *nodePtr);
163 CalDAVServerResult EditCalendarProcess(string *calendarHREF,
164 string *calendarName,
165 Colour *calendarColour,
166 string *calendarDescription,
168 string BuildServerAddress(CalDAVConnectionData *connData, string uriAddress);
169 void SetupDefaultParametersNonSSL(bool doAuthentication);
170 void SetupDefaultParametersSSL(bool doAuthentication);
173 static size_t CalDAVReceive(char *receivedBuffer, size_t size, size_t newMemoryBytes, void *stream);
175 CalDAVConnectionData connectionData;
176 CalDAVServerResult connectionServerResult;
177 CURL *connectionHandle = nullptr;
178 char sessionErrorBuffer[CURL_ERROR_SIZE];
179 string serverData = "";
180 string serverHeader = "";
182 COSSLVerified sslVerified;
183 bool enableSSLBypass = false;
184 bool sslSelfSigned = false;
185 bool sslStatus = false;
187 bool validResponse = false;
188 bool authPassed = false;
189 string errorMessage = "";
191 #if defined(__APPLE__)
192 SecTrustRef certificateData = nullptr;
193 #elif defined(__WIN32__)
194 PCCERT_CONTEXT certificateData = nullptr;
199 void SetupConnectionData(CalDAVConnectionData *connData);
200 CalDAVStatus GetConnectionData();
201 CalDAVServerResult Connect(bool doAuthentication);
202 CalDAVServerResult GetServerResult();
203 CalDAVServerSupport GetServerSupport();
204 CalDAVCalendarList GetCalendars();
205 CalDAVEntryList GetEntryList(string *calendarHREF);
206 CalDAVEntryList GetEntryList(string *calendarHREF, string *calendarTag);
208 CalDAVServerResult AddCalendar(string calendarName);
209 CalDAVServerResult AddCalendar(string *calendarName, string *calendarShortName);
211 CalDAVServerResult EditCalendar(string *calendarHREF,
212 string *calendarName,
213 Colour *calendarColour,
214 string *calendarDescription,
216 CalDAVServerResult EditCalendar(string *calendarHREF,
217 Colour *calendarColour);
218 CalDAVServerResult EditCalendar(string *calendarHREF,
219 string *calendarName);
220 CalDAVServerResult EditCalendar(string *calendarHREF,
222 CalDAVServerResult EditCalendarDescription(string *calendarHREF,
223 string *calendarDescription);
225 CalDAVServerResult DeleteCalendar(string *calendarHREF);
227 CalDAVServerResult AddEntry(string *calendarEntryHREF, string *entryData);
228 CalDAVServerResult EditEntry(string *calendarEntryHREF, string *entryData, string *entryETag);
229 CalDAVServerResult DeleteEntry(string *calendarEntryHREF);
231 string GetUserPrincipal();
232 string GetCalendarHome(string userPrincipalURI);
234 CalDAVServerResult GetEntryETag(string *calendarEntryHREF, string *eTagValue);
237 bool HasValidResponse();
240 std::string GetErrorMessage();
242 COSSLVerified SSLVerify();
243 void BypassSSLVerification(bool EnableBypass);
245 #if defined(__APPLE__)
247 SecTrustRef BuildSSLCollection();
249 #elif defined(__WIN32__)
251 PCCERT_CONTEXT BuildSSLCollection();
254 SSLCertCollectionString BuildSSLCollection();
258 struct CalDAVPassObject {
259 CalDAV *CalDAVObject = nullptr;
260 std::string *DataSetting = nullptr;
261 bool ServerUsingSSL = false;
262 CURL *ConnectionSessionObject = nullptr;
263 #if defined(__APPLE__)
264 SecTrustRef SSLContext = nullptr;
265 #elif defined (__WIN32__)
266 PCCERT_CONTEXT SSLContext = nullptr;
271 CalDAVPassObject PageDataObject;
272 CalDAVPassObject PageHeaderObject;
275 // Subroutines that are used with the
276 // CalDAVConnectionData struct.
278 //bool CalDAVObjectValidSettings(CalDAVConnectionData *connData);