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"
36 // CalDAVConnectionData: used for
37 // connecting to the server.
39 enum CalDAVQueryResult {
40 CALDAVQUERYRESULT_UNITTESTFAIL = -1,
42 CALDAVQUERYRESULT_NOTRUN,
43 CALDAVQUERYRESULT_SERVERERROR
46 struct CalDAVCalendarList {
51 map<int,string> description;
52 map<int,Colour> calColour;
54 map<int,string> tagURL;
58 struct CalDAVEntryList {
66 struct CalDAVConnectionData{
78 // CalDAVStatusData: used for
79 // getting the current server
80 // settings for the CalDAV
94 // CalDAVServerSupport: used for
95 // getting what the server supports
96 // from the CalDAV specification.
98 struct CalDAVServerSupport{
100 // Variable name. Name in CalDAV header.
102 bool basicSupport = false; // calendar-access
106 // CalDAVServerResult: used for
107 // getting the result of the
108 // request made via the CalDAV
111 struct CalDAVServerResult{
113 CalDAVQueryResult result = CALDAVQUERYRESULT_NOTRUN;
114 CURLcode code = CURLE_OK;
119 // CalDAVSendData: used for
120 // sending data to the CaLDAV
123 struct CalDAVSendData{
132 string ProcessXMLUserPrincipal();
133 string ProcessXMLCalendarHome();
134 CalDAVCalendarList ProcessXMLCalendarList();
135 CalDAVEntryList ProcessXMLEntryList();
136 CalDAVEntryList ProcessXMLSyncTokenList();
137 string ProcessXMLEntryETag();
138 bool MatchXMLNameTransverse(xmlNodePtr *nodePtr, string nodeName);
139 bool MatchXMLName(xmlNodePtr *nodePtrOriginal, string nodeName);
140 string FetchXMLData(xmlNodePtr *nodePtr);
141 CalDAVServerResult EditCalendarProcess(string *calendarHREF,
142 string *calendarName,
143 Colour *calendarColour,
144 string *calendarDescription,
147 CalDAVConnectionData connectionData;
148 CalDAVServerResult connectionServerResult;
149 CURL *connectionHandle = nullptr;
150 string serverData = "";
151 string serverHeader = "";
156 void SetupConnectionData(CalDAVConnectionData *connData);
157 CalDAVStatus GetConnectionData();
158 CalDAVServerResult Connect();
159 CalDAVServerResult GetServerResult();
160 CalDAVServerSupport GetServerSupport();
161 CalDAVCalendarList GetCalendars();
162 CalDAVEntryList GetEntryList(string *calendarHREF);
163 CalDAVEntryList GetEntryList(string *calendarHREF, string *calendarTag);
165 CalDAVServerResult AddCalendar(string calendarName);
166 CalDAVServerResult AddCalendar(string *calendarName, string *calendarShortName);
168 CalDAVServerResult EditCalendar(string *calendarHREF,
169 string *calendarName,
170 Colour *calendarColour,
171 string *calendarDescription,
173 CalDAVServerResult EditCalendar(string *calendarHREF,
174 Colour *calendarColour);
175 CalDAVServerResult EditCalendar(string *calendarHREF,
176 string *calendarName);
177 CalDAVServerResult EditCalendar(string *calendarHREF,
179 CalDAVServerResult EditCalendarDescription(string *calendarHREF,
180 string *calendarDescription);
182 CalDAVServerResult DeleteCalendar(string *calendarHREF);
184 CalDAVServerResult AddEntry(string *calendarEntryHREF, string *entryData);
185 CalDAVServerResult EditEntry(string *calendarEntryHREF, string *entryData, string *entryETag);
186 CalDAVServerResult DeleteEntry(string *calendarEntryHREF);
188 string GetUserPrincipal();
189 string GetCalendarHome(string userPrincipalURI);
191 CalDAVServerResult GetEntryETag(string *calendarEntryHREF, string *eTagValue);
195 // Subroutines that are used with the
196 // CalDAVConnectionData struct.
198 bool CalDAVObjectValidSettings(CalDAVConnectionData *connData);
199 string BuildServerAddress(CalDAVConnectionData *connData, string uriAddress);