// CalDAV.h - CalDAV Connection Object header. // // (c) 2016-2017 Xestia Software Development. // // This file is part of Xestia Calendar. // // 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 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. // // You should have received a copy of the GNU General Public License along // with Xestia Calendar. If not, see #ifndef __OBJECTS_CALDAV_CALDAV_H__ #define __OBJECTS_CALDAV_CALDAV_H__ #include #include #include #include #include #include #include #include #include #include #include "../../common/colour.h" #include "../../common/text.h" #include "../../common/uuid.h" #include "../../common/dirs.h" #include "../../common/sslcertstructs.h" #include "../../version.h" using namespace std; // CalDAVConnectionData: used for // connecting to the server. enum CalDAVQueryResult { CALDAVQUERYRESULT_UNITTESTFAIL = -1, CALDAVQUERYRESULT_OK, CALDAVQUERYRESULT_NOTRUN, CALDAVQUERYRESULT_SERVERERROR, CALDAVQUERYRESULT_SSLFAILURE, }; struct CalDAVCalendarList { map name; map href; map order; map description; map calColour; map tag; map tagURL; }; struct CalDAVEntryList { map href; map data; map tag; }; struct CalDAVConnectionData{ string hostname = ""; int port = 8008; string username = ""; string password = ""; string prefix = ""; bool useSSL = true; int timeout = 60; string account = ""; }; // CalDAVStatusData: used for // getting the current server // settings for the CalDAV // object. struct CalDAVStatus{ 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 // getting the result of the // request made via the CalDAV // object. struct CalDAVServerResult{ 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: 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(); 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 = ""; public: 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 }; // Subroutines that are used with the // CalDAVConnectionData struct. //bool CalDAVObjectValidSettings(CalDAVConnectionData *connData); #endif