Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
macOS: Implemented support for adding, editing and deleting a CalDAV account
[xestiacalendar/.git] / source / objects / CalDAV / CalDAV.h
index 5e8622d..eeb84e7 100644 (file)
@@ -1,14 +1,14 @@
 // CalDAV.h - CalDAV Connection Object header.
 //
-// (c) 2016 Xestia Software Development.
+// (c) 2016-2017 Xestia Software Development.
 //
 // This file is part of Xestia Calendar.
 //
-// Xestia Address Book is free software: you can redistribute it and/or modify
+// Xestia Calendar is free software: you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by the
 // Free Software Foundation, version 3 of the license.
 //
-// Xestia Address Book is distributed in the hope that it will be useful,
+// Xestia Calendar is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 // GNU General Public License for more details.
 #define __OBJECTS_CALDAV_CALDAV_H__
 
 #include <curl/curl.h>
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+#include <wx/tokenzr.h>
+#include <wx/file.h>
 #include <string>
+#include <iostream>
+#include <vector>
+#include <stdexcept>
+#include <map>
+#include "../../common/colour.h"
+#include "../../common/text.h"
+#include "../../common/uuid.h"
+#include "../../common/dirs.h"
+#include "../../common/sslcertstructs.h"
+#include "../../version.h"
+
+#if defined (__APPLE__)
+#import <Foundation/Foundation.h>
+#import <SecurityInterface/SFCertificateTrustPanel.h>
+#endif
+
+#if defined(__WIN32__)
+#include "../common/win32ssl.h"
+#endif
 
 using namespace std;
 
@@ -31,17 +54,40 @@ enum CalDAVQueryResult {
        CALDAVQUERYRESULT_UNITTESTFAIL = -1,
        CALDAVQUERYRESULT_OK,
        CALDAVQUERYRESULT_NOTRUN,
-       CALDAVQUERYRESULT_SERVERERROR
+       CALDAVQUERYRESULT_SERVERERROR,
+       CALDAVQUERYRESULT_SSLFAILURE,
+};
+
+struct CalDAVCalendarList {
+
+       map<int,string> name;
+       map<int,string> href;
+       map<int,int> order;
+       map<int,string> description;
+       map<int,Colour> calColour;
+       map<int,string> tag;
+       map<int,string> tagURL;
+       
+};
+
+struct CalDAVEntryList {
+       
+       map<int,string> href;
+       map<int,string> data;
+       map<int,string> tag;
+       
 };
 
 struct CalDAVConnectionData{
        
-       string Hostname = "";
-       int Port = 8008;
-       string Username = "";
-       string Password = "";
-       string Prefix = "";
-       bool UseSSL = true;
+       string hostname = "";
+       int port = 8008;
+       string username = "";
+       string password = "";
+       string prefix = "";
+       bool useSSL = true;
+       int timeout = 60;
+       string account = "";
        
 };
 
@@ -52,12 +98,25 @@ struct CalDAVConnectionData{
 
 struct CalDAVStatus{
 
-       string Hostname;
-       int Port;
-       string Username;
-       string Prefix;
-       bool UseSSL;    
+       string hostname;
+       int port;
+       string username;
+       string prefix;
+       bool useSSL;    
+       int timeout;
+
+};
 
+// CalDAVServerSupport: used for
+// getting what the server supports
+// from the CalDAV specification.
+
+struct CalDAVServerSupport{
+       
+       // Variable name.                          Name in CalDAV header.
+       
+       bool basicSupport = false;              // calendar-access
+       
 };
 
 // CalDAVServerResult: used for
@@ -67,30 +126,160 @@ struct CalDAVStatus{
 
 struct CalDAVServerResult{
 
-       CalDAVQueryResult Result = CALDAVQUERYRESULT_NOTRUN;
-       CURLcode Code = CURLE_OK;
-       long HTTPCode = 0;
+       CalDAVQueryResult result = CALDAVQUERYRESULT_NOTRUN;
+       CURLcode code = CURLE_OK;
+       long httpCode = 0;
        
 };
 
+// CalDAVSendData: used for
+// sending data to the CaLDAV
+// server.
+
+struct CalDAVSendData{
+       string *readptr;
+       long sizeleft;
+       int seek = 0;
+};
+
+// Objects to move to a ConnectionObject-like interface in the future.
+
+enum COSSLVerified {
+       COSSL_UNITTESTFAIL = -1,
+       COSSL_VERIFIED,
+       COSSL_VERIFIED_USER,
+       COSSL_UNABLETOVERIFY,
+       COSSL_NOTAPPLICABLE,
+       COSSL_NORESULT
+};
+
 class CalDAV{
 
        private:
-               CalDAVConnectionData ConnectionData;
-               CURL *ConnectionHandle = nullptr;
+               string ProcessXMLUserPrincipal();
+               string ProcessXMLCalendarHome();
+               CalDAVCalendarList ProcessXMLCalendarList();
+               CalDAVEntryList ProcessXMLEntryList();
+               CalDAVEntryList ProcessXMLSyncTokenList();
+               string ProcessXMLEntryETag();
+               bool MatchXMLNameTransverse(xmlNodePtr *nodePtr, string nodeName);
+               bool MatchXMLName(xmlNodePtr *nodePtrOriginal, string nodeName);
+               string FetchXMLData(xmlNodePtr *nodePtr);
+               CalDAVServerResult EditCalendarProcess(string *calendarHREF,
+                       string *calendarName,
+                       Colour *calendarColour,
+                       string *calendarDescription,
+                       int *calendarOrder);
+               string BuildServerAddress(CalDAVConnectionData *connData, string uriAddress);
+               void SetupDefaultParametersNonSSL(bool doAuthentication);
+               void SetupDefaultParametersSSL(bool doAuthentication);
+               void ResetResults();
+
+               static size_t CalDAVReceive(char *receivedBuffer, size_t size, size_t newMemoryBytes, void *stream);
+       
+               CalDAVConnectionData connectionData;
+               CalDAVServerResult connectionServerResult;
+               CURL *connectionHandle = nullptr;
+               char sessionErrorBuffer[CURL_ERROR_SIZE];
+               string serverData = "";
+               string serverHeader = "";
        
+               COSSLVerified sslVerified;
+               bool enableSSLBypass = false;
+               bool sslSelfSigned = false;
+               bool sslStatus = false;
+               
+               bool validResponse = false;
+               bool authPassed = false;
+               string errorMessage = "";
+
+#if defined(__APPLE__)
+               SecTrustRef certificateData = nullptr;
+#elif defined(__WIN32__)
+               PCCERT_CONTEXT certificateData = nullptr;
+#endif
        public:
-               void SetupConnectionData(CalDAVConnectionData *ConnData);
-               CalDAVStatus GetConnectionData();
-               CalDAVServerResult Connect();
                CalDAV();
                ~CalDAV();
+               void SetupConnectionData(CalDAVConnectionData *connData);
+               CalDAVStatus GetConnectionData();
+               CalDAVServerResult Connect(bool doAuthentication);
+               CalDAVServerResult GetServerResult();
+               CalDAVServerSupport GetServerSupport();
+               CalDAVCalendarList GetCalendars();
+               CalDAVEntryList GetEntryList(string *calendarHREF);
+               CalDAVEntryList GetEntryList(string *calendarHREF, string *calendarTag);
+       
+               CalDAVServerResult AddCalendar(string calendarName);
+               CalDAVServerResult AddCalendar(string *calendarName, string *calendarShortName);
        
+               CalDAVServerResult EditCalendar(string *calendarHREF,
+                       string *calendarName,
+                       Colour *calendarColour,
+                       string *calendarDescription,
+                       int *calendarOrder);
+               CalDAVServerResult EditCalendar(string *calendarHREF,
+                       Colour *calendarColour);
+               CalDAVServerResult EditCalendar(string *calendarHREF,
+                       string *calendarName);
+               CalDAVServerResult EditCalendar(string *calendarHREF,
+                       int *calendarOrder);
+               CalDAVServerResult EditCalendarDescription(string *calendarHREF,
+                       string *calendarDescription);
+               
+               CalDAVServerResult DeleteCalendar(string *calendarHREF);
+               
+               CalDAVServerResult AddEntry(string *calendarEntryHREF, string *entryData);
+               CalDAVServerResult EditEntry(string *calendarEntryHREF, string *entryData, string *entryETag);
+               CalDAVServerResult DeleteEntry(string *calendarEntryHREF);
+       
+               string GetUserPrincipal();
+               string GetCalendarHome(string userPrincipalURI);
+               
+               CalDAVServerResult GetEntryETag(string *calendarEntryHREF, string *eTagValue);
+
+               bool CanDoSSL();
+               bool HasValidResponse();
+               bool AbleToLogin();
+               bool IsSelfSigned();
+               std::string GetErrorMessage();
+
+               COSSLVerified SSLVerify();
+               void BypassSSLVerification(bool EnableBypass);
+               
+#if defined(__APPLE__)
+    
+               SecTrustRef BuildSSLCollection();
+    
+#elif defined(__WIN32__)
+
+               PCCERT_CONTEXT BuildSSLCollection();
+
+#else
+               SSLCertCollectionString BuildSSLCollection();
+
+#endif
+
+               struct CalDAVPassObject {
+                       CalDAV *CalDAVObject = nullptr;
+                       std::string *DataSetting = nullptr;
+                       bool ServerUsingSSL = false;
+                       CURL *ConnectionSessionObject = nullptr;
+#if defined(__APPLE__)
+                       SecTrustRef SSLContext = nullptr;
+#elif defined (__WIN32__)
+                       PCCERT_CONTEXT SSLContext = nullptr;
+#endif
+               };
+
+               private:
+                       CalDAVPassObject PageDataObject;
+                       CalDAVPassObject PageHeaderObject;
 };
 
 // Subroutines that are used with the 
 // CalDAVConnectionData struct.
 
-bool CalDAVObjectValidSettings(CalDAVConnectionData *ConnData);
+//bool CalDAVObjectValidSettings(CalDAVConnectionData *connData);
 
 #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