Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Updated/Added copyright header and licensing to all source files
[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"
34 using namespace std;
36 // CalDAVConnectionData: used for
37 // connecting to the server.
39 enum CalDAVQueryResult {
40         CALDAVQUERYRESULT_UNITTESTFAIL = -1,
41         CALDAVQUERYRESULT_OK,
42         CALDAVQUERYRESULT_NOTRUN,
43         CALDAVQUERYRESULT_SERVERERROR
44 };
46 struct CalDAVCalendarList {
48         map<int,string> Name;
49         map<int,string> HREF;
50         map<int,int> Order;
51         map<int,string> Description;
52         map<int,Colour> CalColour;
53         map<int,string> Tag;
54         map<int,string> TagURL;
55         
56 };
58 struct CalDAVEntryList {
59         
60         map<int,string> HREF;
61         map<int,string> Data;
62         map<int,string> Tag;
63         
64 };
66 struct CalDAVConnectionData{
67         
68         string Hostname = "";
69         int Port = 8008;
70         string Username = "";
71         string Password = "";
72         string Prefix = "";
73         bool UseSSL = true;
74         int Timeout = 60;
75         
76 };
78 // CalDAVStatusData: used for
79 // getting the current server
80 // settings for the CalDAV
81 // object.
83 struct CalDAVStatus{
85         string Hostname;
86         int Port;
87         string Username;
88         string Prefix;
89         bool UseSSL;    
90         int Timeout;
92 };
94 // CalDAVServerSupport: used for
95 // getting what the server supports
96 // from the CalDAV specification.
98 struct CalDAVServerSupport{
99         
100         // Variable name.                          Name in CalDAV header.
101         
102         bool BasicSupport = false;              // calendar-access
103         
104 };
106 // CalDAVServerResult: used for
107 // getting the result of the
108 // request made via the CalDAV
109 // object.
111 struct CalDAVServerResult{
113         CalDAVQueryResult Result = CALDAVQUERYRESULT_NOTRUN;
114         CURLcode Code = CURLE_OK;
115         long HTTPCode = 0;
116         
117 };
119 // CalDAVSendData: used for
120 // sending data to the CaLDAV
121 // server.
123 struct CalDAVSendData{
124         string *readptr;
125         long sizeleft;
126         int seek = 0;
127 };
129 class CalDAV{
131         private:
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,
145                         int *CalendarOrder);
146         
147                 CalDAVConnectionData ConnectionData;
148                 CalDAVServerResult ConnectionServerResult;
149                 CURL *ConnectionHandle = nullptr;
150                 string ServerData = "";
151                 string ServerHeader = "";
152         
153         public:
154                 CalDAV();
155                 ~CalDAV();
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);
164         
165                 CalDAVServerResult AddCalendar(string CalendarName);
166                 CalDAVServerResult AddCalendar(string *CalendarName, string *CalendarShortName);
167         
168                 CalDAVServerResult EditCalendar(string *CalendarHREF,
169                         string *CalendarName,
170                         Colour *CalendarColour,
171                         string *CalendarDescription,
172                         int *CalendarOrder);
173                 CalDAVServerResult EditCalendar(string *CalendarHREF,
174                         Colour *CalendarColour);
175                 CalDAVServerResult EditCalendar(string *CalendarHREF,
176                         string *CalendarName);
177                 CalDAVServerResult EditCalendar(string *CalendarHREF,
178                         int *CalendarOrder);
179                 CalDAVServerResult EditCalendarDescription(string *CalendarHREF,
180                         string *CalendarDescription);
181                 
182                 CalDAVServerResult DeleteCalendar(string *CalendarHREF);
183                 
184                 CalDAVServerResult AddEntry(string *CalendarEntryHREF, string *EntryData);
185                 CalDAVServerResult EditEntry(string *CalendarEntryHREF, string *EntryData, string *EntryETag);
186                 CalDAVServerResult DeleteEntry(string *CalendarEntryHREF);
187         
188                 string GetUserPrincipal();
189                 string GetCalendarHome(string UserPrincipalURI);
190                 
191                 CalDAVServerResult GetEntryETag(string *CalendarEntryHREF, string *ETagValue);
192         
193 };
195 // Subroutines that are used with the 
196 // CalDAVConnectionData struct.
198 bool CalDAVObjectValidSettings(CalDAVConnectionData *ConnData);
199 string BuildServerAddress(CalDAVConnectionData *ConnData, string URIAddress);
201 #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