Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
CalDAV: WIP CalDAV support
[xestiacalendar/.git] / source / objects / CalDAV / CalDAV.h
1 // CalDAV.h - CalDAV Connection Object header.
2 //
3 // (c) 2016-2017 Xestia Software Development.
4 //
5 // This file is part of Xestia Calendar.
6 //
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.
10 //
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.
15 //
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 <string>
26 #include <iostream>
27 #include <vector>
28 #include <stdexcept>
29 #include <map>
30 #include "../../common/colour.h"
31 #include "../../common/text.h"
32 #include "../../common/uuid.h"
33 #include "../../common/sslcertstructs.h"
35 using namespace std;
37 // CalDAVConnectionData: used for
38 // connecting to the server.
40 enum CalDAVQueryResult {
41         CALDAVQUERYRESULT_UNITTESTFAIL = -1,
42         CALDAVQUERYRESULT_OK,
43         CALDAVQUERYRESULT_NOTRUN,
44         CALDAVQUERYRESULT_SERVERERROR
45 };
47 struct CalDAVCalendarList {
49         map<int,string> name;
50         map<int,string> href;
51         map<int,int> order;
52         map<int,string> description;
53         map<int,Colour> calColour;
54         map<int,string> tag;
55         map<int,string> tagURL;
56         
57 };
59 struct CalDAVEntryList {
60         
61         map<int,string> href;
62         map<int,string> data;
63         map<int,string> tag;
64         
65 };
67 struct CalDAVConnectionData{
68         
69         string hostname = "";
70         int port = 8008;
71         string username = "";
72         string password = "";
73         string prefix = "";
74         bool useSSL = true;
75         int timeout = 60;
76         
77 };
79 // CalDAVStatusData: used for
80 // getting the current server
81 // settings for the CalDAV
82 // object.
84 struct CalDAVStatus{
86         string hostname;
87         int port;
88         string username;
89         string prefix;
90         bool useSSL;    
91         int timeout;
93 };
95 // CalDAVServerSupport: used for
96 // getting what the server supports
97 // from the CalDAV specification.
99 struct CalDAVServerSupport{
100         
101         // Variable name.                          Name in CalDAV header.
102         
103         bool basicSupport = false;              // calendar-access
104         
105 };
107 // CalDAVServerResult: used for
108 // getting the result of the
109 // request made via the CalDAV
110 // object.
112 struct CalDAVServerResult{
114         CalDAVQueryResult result = CALDAVQUERYRESULT_NOTRUN;
115         CURLcode code = CURLE_OK;
116         long httpCode = 0;
117         
118 };
120 // CalDAVSendData: used for
121 // sending data to the CaLDAV
122 // server.
124 struct CalDAVSendData{
125         string *readptr;
126         long sizeleft;
127         int seek = 0;
128 };
130 // Objects to move to a ConnectionObject-like interface in the future.
132 enum COSSLVerified {
133         COSSL_UNITTESTFAIL = -1,
134         COSSL_VERIFIED,
135         COSSL_VERIFIED_USER,
136         COSSL_UNABLETOVERIFY,
137         COSSL_NOTAPPLICABLE,
138         COSSL_NORESULT
139 };
141 class CalDAV{
143         private:
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,
157                         int *calendarOrder);
158         
159                 CalDAVConnectionData connectionData;
160                 CalDAVServerResult connectionServerResult;
161                 CURL *connectionHandle = nullptr;
162                 string serverData = "";
163                 string serverHeader = "";
164         
165                 COSSLVerified SSLVerified;
166                 bool EnableSSLBypass = false;
167                 bool SSLSelfSigned = false;
168         public:
169                 CalDAV();
170                 ~CalDAV();
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);
179         
180                 CalDAVServerResult AddCalendar(string calendarName);
181                 CalDAVServerResult AddCalendar(string *calendarName, string *calendarShortName);
182         
183                 CalDAVServerResult EditCalendar(string *calendarHREF,
184                         string *calendarName,
185                         Colour *calendarColour,
186                         string *calendarDescription,
187                         int *calendarOrder);
188                 CalDAVServerResult EditCalendar(string *calendarHREF,
189                         Colour *calendarColour);
190                 CalDAVServerResult EditCalendar(string *calendarHREF,
191                         string *calendarName);
192                 CalDAVServerResult EditCalendar(string *calendarHREF,
193                         int *calendarOrder);
194                 CalDAVServerResult EditCalendarDescription(string *calendarHREF,
195                         string *calendarDescription);
196                 
197                 CalDAVServerResult DeleteCalendar(string *calendarHREF);
198                 
199                 CalDAVServerResult AddEntry(string *calendarEntryHREF, string *entryData);
200                 CalDAVServerResult EditEntry(string *calendarEntryHREF, string *entryData, string *entryETag);
201                 CalDAVServerResult DeleteEntry(string *calendarEntryHREF);
202         
203                 string GetUserPrincipal();
204                 string GetCalendarHome(string userPrincipalURI);
205                 
206                 CalDAVServerResult GetEntryETag(string *calendarEntryHREF, string *eTagValue);
208                 COSSLVerified SSLVerify();
209                 void BypassSSLVerification(bool EnableBypass);
210                 
211 #if defined(__APPLE__)
212     
213                 SecTrustRef BuildSSLCollection();
214     
215 #elif defined(__WIN32__)
217                 PCCERT_CONTEXT BuildSSLCollection();
219 #else
220                 SSLCertCollectionString BuildSSLCollection();
222 #endif
223 };
225 // Subroutines that are used with the 
226 // CalDAVConnectionData struct.
228 //bool CalDAVObjectValidSettings(CalDAVConnectionData *connData);
229 //string BuildServerAddress(CalDAVConnectionData *connData, string uriAddress);
231 #endif
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy