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>
30 #include "../../common/colour.h"
31 #include "../../common/text.h"
32 #include "../../common/uuid.h"
33 #include "../../common/sslcertstructs.h"
37 // CalDAVConnectionData: used for
38 // connecting to the server.
40 enum CalDAVQueryResult {
41 CALDAVQUERYRESULT_UNITTESTFAIL = -1,
43 CALDAVQUERYRESULT_NOTRUN,
44 CALDAVQUERYRESULT_SERVERERROR
47 struct CalDAVCalendarList {
52 map<int,string> description;
53 map<int,Colour> calColour;
55 map<int,string> tagURL;
59 struct CalDAVEntryList {
67 struct CalDAVConnectionData{
79 // CalDAVStatusData: used for
80 // getting the current server
81 // settings for the CalDAV
95 // CalDAVServerSupport: used for
96 // getting what the server supports
97 // from the CalDAV specification.
99 struct CalDAVServerSupport{
101 // Variable name. Name in CalDAV header.
103 bool basicSupport = false; // calendar-access
107 // CalDAVServerResult: used for
108 // getting the result of the
109 // request made via the CalDAV
112 struct CalDAVServerResult{
114 CalDAVQueryResult result = CALDAVQUERYRESULT_NOTRUN;
115 CURLcode code = CURLE_OK;
120 // CalDAVSendData: used for
121 // sending data to the CaLDAV
124 struct CalDAVSendData{
130 // Objects to move to a ConnectionObject-like interface in the future.
133 COSSL_UNITTESTFAIL = -1,
136 COSSL_UNABLETOVERIFY,
144 string ProcessXMLUserPrincipal();
145 string ProcessXMLCalendarHome();
146 CalDAVCalendarList ProcessXMLCalendarList();
147 CalDAVEntryList ProcessXMLEntryList();
148 CalDAVEntryList ProcessXMLSyncTokenList();
149 string ProcessXMLEntryETag();
150 bool MatchXMLNameTransverse(xmlNodePtr *nodePtr, string nodeName);
151 bool MatchXMLName(xmlNodePtr *nodePtrOriginal, string nodeName);
152 string FetchXMLData(xmlNodePtr *nodePtr);
153 CalDAVServerResult EditCalendarProcess(string *calendarHREF,
154 string *calendarName,
155 Colour *calendarColour,
156 string *calendarDescription,
159 CalDAVConnectionData connectionData;
160 CalDAVServerResult connectionServerResult;
161 CURL *connectionHandle = nullptr;
162 string serverData = "";
163 string serverHeader = "";
165 COSSLVerified SSLVerified;
166 bool EnableSSLBypass = false;
167 bool SSLSelfSigned = false;
171 void SetupConnectionData(CalDAVConnectionData *connData);
172 CalDAVStatus GetConnectionData();
173 CalDAVServerResult Connect();
174 CalDAVServerResult GetServerResult();
175 CalDAVServerSupport GetServerSupport();
176 CalDAVCalendarList GetCalendars();
177 CalDAVEntryList GetEntryList(string *calendarHREF);
178 CalDAVEntryList GetEntryList(string *calendarHREF, string *calendarTag);
180 CalDAVServerResult AddCalendar(string calendarName);
181 CalDAVServerResult AddCalendar(string *calendarName, string *calendarShortName);
183 CalDAVServerResult EditCalendar(string *calendarHREF,
184 string *calendarName,
185 Colour *calendarColour,
186 string *calendarDescription,
188 CalDAVServerResult EditCalendar(string *calendarHREF,
189 Colour *calendarColour);
190 CalDAVServerResult EditCalendar(string *calendarHREF,
191 string *calendarName);
192 CalDAVServerResult EditCalendar(string *calendarHREF,
194 CalDAVServerResult EditCalendarDescription(string *calendarHREF,
195 string *calendarDescription);
197 CalDAVServerResult DeleteCalendar(string *calendarHREF);
199 CalDAVServerResult AddEntry(string *calendarEntryHREF, string *entryData);
200 CalDAVServerResult EditEntry(string *calendarEntryHREF, string *entryData, string *entryETag);
201 CalDAVServerResult DeleteEntry(string *calendarEntryHREF);
203 string GetUserPrincipal();
204 string GetCalendarHome(string userPrincipalURI);
206 CalDAVServerResult GetEntryETag(string *calendarEntryHREF, string *eTagValue);
208 COSSLVerified SSLVerify();
209 void BypassSSLVerification(bool EnableBypass);
211 #if defined(__APPLE__)
213 SecTrustRef BuildSSLCollection();
215 #elif defined(__WIN32__)
217 PCCERT_CONTEXT BuildSSLCollection();
220 SSLCertCollectionString BuildSSLCollection();
225 // Subroutines that are used with the
226 // CalDAVConnectionData struct.
228 //bool CalDAVObjectValidSettings(CalDAVConnectionData *connData);
229 //string BuildServerAddress(CalDAVConnectionData *connData, string uriAddress);