Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added code and unit tests to list calendars from the server.
[xestiacalendar/.git] / source / objects / CalDAV / CalDAV.h
1 // CalDAV.h - CalDAV Connection Object header.
2 //
3 // (c) 2016 Xestia Software Development.
4 //
5 // This file is part of Xestia Calendar.
6 //
7 // Xestia Address Book 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 Address Book 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"
33 using namespace std;
35 // CalDAVConnectionData: used for
36 // connecting to the server.
38 enum CalDAVQueryResult {
39         CALDAVQUERYRESULT_UNITTESTFAIL = -1,
40         CALDAVQUERYRESULT_OK,
41         CALDAVQUERYRESULT_NOTRUN,
42         CALDAVQUERYRESULT_SERVERERROR
43 };
45 struct CalDAVCalendarList {
47         map<int,string> Name;
48         map<int,string> HREF;
49         map<int,int> Order;
50         map<int,string> Description;
51         map<int,Colour> CalColour;
52         map<int,string> Tag;
53         
54 };
56 struct CalDAVConnectionData{
57         
58         string Hostname = "";
59         int Port = 8008;
60         string Username = "";
61         string Password = "";
62         string Prefix = "";
63         bool UseSSL = true;
64         int Timeout = 60;
65         
66 };
68 // CalDAVStatusData: used for
69 // getting the current server
70 // settings for the CalDAV
71 // object.
73 struct CalDAVStatus{
75         string Hostname;
76         int Port;
77         string Username;
78         string Prefix;
79         bool UseSSL;    
80         int Timeout;
82 };
84 // CalDAVServerSupport: used for
85 // getting what the server supports
86 // from the CalDAV specification.
88 struct CalDAVServerSupport{
89         
90         // Variable name.                          Name in CalDAV header.
91         
92         bool BasicSupport = false;              // calendar-access
93         
94 };
96 // CalDAVServerResult: used for
97 // getting the result of the
98 // request made via the CalDAV
99 // object.
101 struct CalDAVServerResult{
103         CalDAVQueryResult Result = CALDAVQUERYRESULT_NOTRUN;
104         CURLcode Code = CURLE_OK;
105         long HTTPCode = 0;
106         
107 };
109 // CalDAVSendData: used for
110 // sending data to the CaLDAV
111 // server.
113 struct CalDAVSendData{
114         string *readptr;
115         long sizeleft;
116         int seek = 0;
117 };
119 class CalDAV{
121         private:
122                 string ProcessXMLUserPrincipal();
123                 string ProcessXMLCalendarHome();
124                 CalDAVCalendarList ProcessXMLCalendarList();
125                 bool MatchXMLNameTransverse(xmlNodePtr *NodePtr, string NodeName);
126                 bool MatchXMLName(xmlNodePtr *NodePtrOriginal, string NodeName);
127                 string FetchXMLData(xmlNodePtr *NodePtr);
128         
129                 CalDAVConnectionData ConnectionData;
130                 CalDAVServerResult ConnectionServerResult;
131                 CURL *ConnectionHandle = nullptr;
132                 string ServerData = "";
133                 string ServerHeader = "";
134         
135         public:
136                 CalDAV();
137                 ~CalDAV();
138                 void SetupConnectionData(CalDAVConnectionData *ConnData);
139                 CalDAVStatus GetConnectionData();
140                 CalDAVServerResult Connect();
141                 CalDAVServerResult GetServerResult();
142                 CalDAVServerSupport GetServerSupport();
143                 CalDAVCalendarList GetCalendars();
144         
145                 string GetUserPrincipal();
146                 string GetCalendarHome(string UserPrincipalURI);
147         
148 };
150 // Subroutines that are used with the 
151 // CalDAVConnectionData struct.
153 bool CalDAVObjectValidSettings(CalDAVConnectionData *ConnData);
154 string BuildServerAddress(CalDAVConnectionData *ConnData, string URIAddress);
156 #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