Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added the AddCalendar function.
[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"
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         
55 };
57 struct CalDAVConnectionData{
58         
59         string Hostname = "";
60         int Port = 8008;
61         string Username = "";
62         string Password = "";
63         string Prefix = "";
64         bool UseSSL = true;
65         int Timeout = 60;
66         
67 };
69 // CalDAVStatusData: used for
70 // getting the current server
71 // settings for the CalDAV
72 // object.
74 struct CalDAVStatus{
76         string Hostname;
77         int Port;
78         string Username;
79         string Prefix;
80         bool UseSSL;    
81         int Timeout;
83 };
85 // CalDAVServerSupport: used for
86 // getting what the server supports
87 // from the CalDAV specification.
89 struct CalDAVServerSupport{
90         
91         // Variable name.                          Name in CalDAV header.
92         
93         bool BasicSupport = false;              // calendar-access
94         
95 };
97 // CalDAVServerResult: used for
98 // getting the result of the
99 // request made via the CalDAV
100 // object.
102 struct CalDAVServerResult{
104         CalDAVQueryResult Result = CALDAVQUERYRESULT_NOTRUN;
105         CURLcode Code = CURLE_OK;
106         long HTTPCode = 0;
107         
108 };
110 // CalDAVSendData: used for
111 // sending data to the CaLDAV
112 // server.
114 struct CalDAVSendData{
115         string *readptr;
116         long sizeleft;
117         int seek = 0;
118 };
120 class CalDAV{
122         private:
123                 string ProcessXMLUserPrincipal();
124                 string ProcessXMLCalendarHome();
125                 CalDAVCalendarList ProcessXMLCalendarList();
126                 bool MatchXMLNameTransverse(xmlNodePtr *NodePtr, string NodeName);
127                 bool MatchXMLName(xmlNodePtr *NodePtrOriginal, string NodeName);
128                 string FetchXMLData(xmlNodePtr *NodePtr);
129         
130                 CalDAVConnectionData ConnectionData;
131                 CalDAVServerResult ConnectionServerResult;
132                 CURL *ConnectionHandle = nullptr;
133                 string ServerData = "";
134                 string ServerHeader = "";
135         
136         public:
137                 CalDAV();
138                 ~CalDAV();
139                 void SetupConnectionData(CalDAVConnectionData *ConnData);
140                 CalDAVStatus GetConnectionData();
141                 CalDAVServerResult Connect();
142                 CalDAVServerResult GetServerResult();
143                 CalDAVServerSupport GetServerSupport();
144                 CalDAVCalendarList GetCalendars();
145                 CalDAVServerResult AddCalendar(string CalendarName);
146         
147                 string GetUserPrincipal();
148                 string GetCalendarHome(string UserPrincipalURI);
149         
150 };
152 // Subroutines that are used with the 
153 // CalDAVConnectionData struct.
155 bool CalDAVObjectValidSettings(CalDAVConnectionData *ConnData);
156 string BuildServerAddress(CalDAVConnectionData *ConnData, string URIAddress);
158 #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