Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
CalDAV: Implemented Win32 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 <wx/tokenzr.h>
26 #include <wx/file.h>
27 #include <string>
28 #include <iostream>
29 #include <vector>
30 #include <stdexcept>
31 #include <map>
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"
41 #endif
43 using namespace std;
45 // CalDAVConnectionData: used for
46 // connecting to the server.
48 enum CalDAVQueryResult {
49         CALDAVQUERYRESULT_UNITTESTFAIL = -1,
50         CALDAVQUERYRESULT_OK,
51         CALDAVQUERYRESULT_NOTRUN,
52         CALDAVQUERYRESULT_SERVERERROR,
53         CALDAVQUERYRESULT_SSLFAILURE,
54 };
56 struct CalDAVCalendarList {
58         map<int,string> name;
59         map<int,string> href;
60         map<int,int> order;
61         map<int,string> description;
62         map<int,Colour> calColour;
63         map<int,string> tag;
64         map<int,string> tagURL;
65         
66 };
68 struct CalDAVEntryList {
69         
70         map<int,string> href;
71         map<int,string> data;
72         map<int,string> tag;
73         
74 };
76 struct CalDAVConnectionData{
77         
78         string hostname = "";
79         int port = 8008;
80         string username = "";
81         string password = "";
82         string prefix = "";
83         bool useSSL = true;
84         int timeout = 60;
85         string account = "";
86         
87 };
89 // CalDAVStatusData: used for
90 // getting the current server
91 // settings for the CalDAV
92 // object.
94 struct CalDAVStatus{
96         string hostname;
97         int port;
98         string username;
99         string prefix;
100         bool useSSL;    
101         int timeout;
103 };
105 // CalDAVServerSupport: used for
106 // getting what the server supports
107 // from the CalDAV specification.
109 struct CalDAVServerSupport{
110         
111         // Variable name.                          Name in CalDAV header.
112         
113         bool basicSupport = false;              // calendar-access
114         
115 };
117 // CalDAVServerResult: used for
118 // getting the result of the
119 // request made via the CalDAV
120 // object.
122 struct CalDAVServerResult{
124         CalDAVQueryResult result = CALDAVQUERYRESULT_NOTRUN;
125         CURLcode code = CURLE_OK;
126         long httpCode = 0;
127         
128 };
130 // CalDAVSendData: used for
131 // sending data to the CaLDAV
132 // server.
134 struct CalDAVSendData{
135         string *readptr;
136         long sizeleft;
137         int seek = 0;
138 };
140 // Objects to move to a ConnectionObject-like interface in the future.
142 enum COSSLVerified {
143         COSSL_UNITTESTFAIL = -1,
144         COSSL_VERIFIED,
145         COSSL_VERIFIED_USER,
146         COSSL_UNABLETOVERIFY,
147         COSSL_NOTAPPLICABLE,
148         COSSL_NORESULT
149 };
151 class CalDAV{
153         private:
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,
167                         int *calendarOrder);
168                 string BuildServerAddress(CalDAVConnectionData *connData, string uriAddress);
169                 void SetupDefaultParametersNonSSL(bool doAuthentication);
170                 void SetupDefaultParametersSSL(bool doAuthentication);
171                 void ResetResults();
173                 static size_t CalDAVReceive(char *receivedBuffer, size_t size, size_t newMemoryBytes, void *stream);
174         
175                 CalDAVConnectionData connectionData;
176                 CalDAVServerResult connectionServerResult;
177                 CURL *connectionHandle = nullptr;
178                 char sessionErrorBuffer[CURL_ERROR_SIZE];
179                 string serverData = "";
180                 string serverHeader = "";
181         
182                 COSSLVerified sslVerified;
183                 bool enableSSLBypass = false;
184                 bool sslSelfSigned = false;
185                 bool sslStatus = false;
186                 
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;
195 #endif
196         public:
197                 CalDAV();
198                 ~CalDAV();
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);
207         
208                 CalDAVServerResult AddCalendar(string calendarName);
209                 CalDAVServerResult AddCalendar(string *calendarName, string *calendarShortName);
210         
211                 CalDAVServerResult EditCalendar(string *calendarHREF,
212                         string *calendarName,
213                         Colour *calendarColour,
214                         string *calendarDescription,
215                         int *calendarOrder);
216                 CalDAVServerResult EditCalendar(string *calendarHREF,
217                         Colour *calendarColour);
218                 CalDAVServerResult EditCalendar(string *calendarHREF,
219                         string *calendarName);
220                 CalDAVServerResult EditCalendar(string *calendarHREF,
221                         int *calendarOrder);
222                 CalDAVServerResult EditCalendarDescription(string *calendarHREF,
223                         string *calendarDescription);
224                 
225                 CalDAVServerResult DeleteCalendar(string *calendarHREF);
226                 
227                 CalDAVServerResult AddEntry(string *calendarEntryHREF, string *entryData);
228                 CalDAVServerResult EditEntry(string *calendarEntryHREF, string *entryData, string *entryETag);
229                 CalDAVServerResult DeleteEntry(string *calendarEntryHREF);
230         
231                 string GetUserPrincipal();
232                 string GetCalendarHome(string userPrincipalURI);
233                 
234                 CalDAVServerResult GetEntryETag(string *calendarEntryHREF, string *eTagValue);
236                 bool CanDoSSL();
237                 bool HasValidResponse();
238                 bool AbleToLogin();
239                 bool IsSelfSigned();
240                 std::string GetErrorMessage();
242                 COSSLVerified SSLVerify();
243                 void BypassSSLVerification(bool EnableBypass);
244                 
245 #if defined(__APPLE__)
246     
247                 SecTrustRef BuildSSLCollection();
248     
249 #elif defined(__WIN32__)
251                 PCCERT_CONTEXT BuildSSLCollection();
253 #else
254                 SSLCertCollectionString BuildSSLCollection();
256 #endif
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;
267 #endif
268                 };
270                 private:
271                         CalDAVPassObject PageDataObject;
272                         CalDAVPassObject PageHeaderObject;
273 };
275 // Subroutines that are used with the 
276 // CalDAVConnectionData struct.
278 //bool CalDAVObjectValidSettings(CalDAVConnectionData *connData);
280 #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