X-Git-Url: http://Server1/repobrowser/?a=blobdiff_plain;f=source%2Fobjects%2FCalDAV%2FCalDAV.h;h=eeb84e7c342dbfa9f22711bb8119b86caa3fb778;hb=512577f3a85cf85feab3f09e9389581bb379413a;hp=e95c03bfd7c1a12596415f5bbdd3fdea70fe6b42;hpb=feee46cd739cb77e2adac508832f13b7b6d1b75f;p=xestiacalendar%2F.git diff --git a/source/objects/CalDAV/CalDAV.h b/source/objects/CalDAV/CalDAV.h index e95c03b..eeb84e7 100644 --- a/source/objects/CalDAV/CalDAV.h +++ b/source/objects/CalDAV/CalDAV.h @@ -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. @@ -22,6 +22,8 @@ #include #include #include +#include +#include #include #include #include @@ -30,6 +32,18 @@ #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 +#import +#endif + +#if defined(__WIN32__) +#include "../common/win32ssl.h" +#endif using namespace std; @@ -40,38 +54,40 @@ enum CalDAVQueryResult { CALDAVQUERYRESULT_UNITTESTFAIL = -1, CALDAVQUERYRESULT_OK, CALDAVQUERYRESULT_NOTRUN, - CALDAVQUERYRESULT_SERVERERROR + CALDAVQUERYRESULT_SERVERERROR, + CALDAVQUERYRESULT_SSLFAILURE, }; struct CalDAVCalendarList { - map Name; - map HREF; - map Order; - map Description; - map CalColour; - map Tag; - map TagURL; + map name; + map href; + map order; + map description; + map calColour; + map tag; + map tagURL; }; struct CalDAVEntryList { - map HREF; - map Data; - map Tag; + 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 hostname = ""; + int port = 8008; + string username = ""; + string password = ""; + string prefix = ""; + bool useSSL = true; + int timeout = 60; + string account = ""; }; @@ -82,12 +98,12 @@ struct CalDAVConnectionData{ struct CalDAVStatus{ - string Hostname; - int Port; - string Username; - string Prefix; - bool UseSSL; - int Timeout; + string hostname; + int port; + string username; + string prefix; + bool useSSL; + int timeout; }; @@ -99,7 +115,7 @@ struct CalDAVServerSupport{ // Variable name. Name in CalDAV header. - bool BasicSupport = false; // calendar-access + bool basicSupport = false; // calendar-access }; @@ -110,9 +126,9 @@ struct CalDAVServerSupport{ struct CalDAVServerResult{ - CalDAVQueryResult Result = CALDAVQUERYRESULT_NOTRUN; - CURLcode Code = CURLE_OK; - long HTTPCode = 0; + CalDAVQueryResult result = CALDAVQUERYRESULT_NOTRUN; + CURLcode code = CURLE_OK; + long httpCode = 0; }; @@ -126,6 +142,17 @@ struct CalDAVSendData{ 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: @@ -135,67 +162,124 @@ class CalDAV{ 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); + 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; - string ServerData = ""; - string ServerHeader = ""; + 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: CalDAV(); ~CalDAV(); - void SetupConnectionData(CalDAVConnectionData *ConnData); + void SetupConnectionData(CalDAVConnectionData *connData); CalDAVStatus GetConnectionData(); - CalDAVServerResult Connect(); + CalDAVServerResult Connect(bool doAuthentication); CalDAVServerResult GetServerResult(); CalDAVServerSupport GetServerSupport(); CalDAVCalendarList GetCalendars(); - CalDAVEntryList GetEntryList(string *CalendarHREF); - CalDAVEntryList GetEntryList(string *CalendarHREF, string *CalendarTag); + CalDAVEntryList GetEntryList(string *calendarHREF); + CalDAVEntryList GetEntryList(string *calendarHREF, string *calendarTag); - CalDAVServerResult AddCalendar(string CalendarName); - CalDAVServerResult AddCalendar(string *CalendarName, string *CalendarShortName); + 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 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 DeleteCalendar(string *calendarHREF); - CalDAVServerResult AddEntry(string *CalendarEntryHREF, string *EntryData); - CalDAVServerResult EditEntry(string *CalendarEntryHREF, string *EntryData, string *EntryETag); - CalDAVServerResult DeleteEntry(string *CalendarEntryHREF); + CalDAVServerResult AddEntry(string *calendarEntryHREF, string *entryData); + CalDAVServerResult EditEntry(string *calendarEntryHREF, string *entryData, string *entryETag); + CalDAVServerResult DeleteEntry(string *calendarEntryHREF); string GetUserPrincipal(); - string GetCalendarHome(string UserPrincipalURI); + string GetCalendarHome(string userPrincipalURI); - CalDAVServerResult GetEntryETag(string *CalendarEntryHREF, string *ETagValue); - + 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); -string BuildServerAddress(CalDAVConnectionData *ConnData, string URIAddress); +//bool CalDAVObjectValidSettings(CalDAVConnectionData *connData); #endif