From 512577f3a85cf85feab3f09e9389581bb379413a Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Fri, 29 Dec 2017 12:31:25 +0000 Subject: [PATCH] macOS: Implemented support for adding, editing and deleting a CalDAV account --- .../XestiaCalendar.xcodeproj/project.pbxproj | 48 +++++++++++++++++ source/forms/newaccount/frmNewAccount.cpp | 19 ++++--- source/forms/newaccount/frmNewAccount.h | 4 +- source/forms/newaccount/frmNewAccount.mm | 52 +++++++++++++++++++ source/forms/preferences/frmPreferences.cpp | 8 ++- .../objects/CalDAV/CalDAV-XMLProcessing.cpp | 3 +- source/objects/CalDAV/CalDAV.cpp | 10 +++- source/objects/CalDAV/CalDAV.h | 5 ++ 8 files changed, 137 insertions(+), 12 deletions(-) create mode 100644 source/forms/newaccount/frmNewAccount.mm diff --git a/projects/osx/XestiaCalendar.xcodeproj/project.pbxproj b/projects/osx/XestiaCalendar.xcodeproj/project.pbxproj index f943484..50019b2 100644 --- a/projects/osx/XestiaCalendar.xcodeproj/project.pbxproj +++ b/projects/osx/XestiaCalendar.xcodeproj/project.pbxproj @@ -13,6 +13,11 @@ 4ABACC9D1B20E968001368B0 /* wxdebug.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 4ABACC981B20E968001368B0 /* wxdebug.xcconfig */; }; 4ABACC9E1B20E968001368B0 /* wxrelease.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 4ABACC991B20E968001368B0 /* wxrelease.xcconfig */; }; 4ABACC9F1B20E968001368B0 /* Info_cocoa.plist in Resources */ = {isa = PBXBuildFile; fileRef = 4ABACC9A1B20E968001368B0 /* Info_cocoa.plist */; }; + 4B03EDB11FE092D10041DE17 /* frmNewAccount.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4B03EDB01FE092D00041DE17 /* frmNewAccount.mm */; }; + 4B03EDB51FE094F50041DE17 /* frmActivityMgr.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B03EDB41FE094F40041DE17 /* frmActivityMgr.cpp */; }; + 4B03EDB61FE096690041DE17 /* CalDAV-XMLProcessing.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B03EDA91FDDF1130041DE17 /* CalDAV-XMLProcessing.cpp */; }; + 4B03EDB71FE0966C0041DE17 /* CalDAV.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B03EDAA1FDDF1130041DE17 /* CalDAV.cpp */; }; + 4B03EDB91FE096F40041DE17 /* frmMain-Setup.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B03EDB81FE096F30041DE17 /* frmMain-Setup.cpp */; }; 4B4A35271F6B2AD400919765 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4B4A35241F6B29EB00919765 /* Images.xcassets */; }; 4B4A352A1F6B2D7E00919765 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B4A35291F6B2D7E00919765 /* main.cpp */; }; 4B4A35311F6B342B00919765 /* bitmapcode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B4A352F1F6B342700919765 /* bitmapcode.cpp */; }; @@ -116,6 +121,13 @@ 4ABACC991B20E968001368B0 /* wxrelease.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = wxrelease.xcconfig; sourceTree = ""; }; 4ABACC9A1B20E968001368B0 /* Info_cocoa.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info_cocoa.plist; sourceTree = ""; }; 4ABACCA11B20ECA8001368B0 /* Xestia Calendar.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Xestia Calendar.app"; sourceTree = BUILT_PRODUCTS_DIR; }; + 4B03EDA81FDDF1130041DE17 /* CalDAV.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CalDAV.h; path = ../../source/objects/CalDAV/CalDAV.h; sourceTree = ""; }; + 4B03EDA91FDDF1130041DE17 /* CalDAV-XMLProcessing.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "CalDAV-XMLProcessing.cpp"; path = "../../source/objects/CalDAV/CalDAV-XMLProcessing.cpp"; sourceTree = ""; }; + 4B03EDAA1FDDF1130041DE17 /* CalDAV.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CalDAV.cpp; path = ../../source/objects/CalDAV/CalDAV.cpp; sourceTree = ""; }; + 4B03EDB01FE092D00041DE17 /* frmNewAccount.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = frmNewAccount.mm; path = ../../source/forms/newaccount/frmNewAccount.mm; sourceTree = ""; }; + 4B03EDB31FE094F40041DE17 /* frmActivityMgr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = frmActivityMgr.h; path = ../../source/forms/actmgr/frmActivityMgr.h; sourceTree = ""; }; + 4B03EDB41FE094F40041DE17 /* frmActivityMgr.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = frmActivityMgr.cpp; path = ../../source/forms/actmgr/frmActivityMgr.cpp; sourceTree = ""; }; + 4B03EDB81FE096F30041DE17 /* frmMain-Setup.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "frmMain-Setup.cpp"; path = "../../source/forms/main/frmMain-Setup.cpp"; sourceTree = ""; }; 4B4A35241F6B29EB00919765 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 4B4A35291F6B2D7E00919765 /* main.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = main.cpp; path = ../../source/main.cpp; sourceTree = ""; }; 4B4A352F1F6B342700919765 /* bitmapcode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = bitmapcode.cpp; path = ../../source/tools/bitmapcode.cpp; sourceTree = ""; }; @@ -258,9 +270,36 @@ 4B4A35281F6B2CB200919765 /* src */, 4ABACCA11B20ECA8001368B0 /* Xestia Calendar.app */, 4A6DA3E21CAC0B3E00A15B3D /* bitmaphelper */, + 4B03EDAD1FDDF56F0041DE17 /* Frameworks */, ); sourceTree = ""; }; + 4B03EDA71FDDEF790041DE17 /* caldav */ = { + isa = PBXGroup; + children = ( + 4B03EDA91FDDF1130041DE17 /* CalDAV-XMLProcessing.cpp */, + 4B03EDAA1FDDF1130041DE17 /* CalDAV.cpp */, + 4B03EDA81FDDF1130041DE17 /* CalDAV.h */, + ); + name = caldav; + sourceTree = ""; + }; + 4B03EDAD1FDDF56F0041DE17 /* Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = Frameworks; + sourceTree = ""; + }; + 4B03EDB21FE094DB0041DE17 /* actmgr */ = { + isa = PBXGroup; + children = ( + 4B03EDB41FE094F40041DE17 /* frmActivityMgr.cpp */, + 4B03EDB31FE094F40041DE17 /* frmActivityMgr.h */, + ); + name = actmgr; + sourceTree = ""; + }; 4B4A35281F6B2CB200919765 /* src */ = { isa = PBXGroup; children = ( @@ -319,6 +358,7 @@ 4B4A35581F6C67C900919765 /* forms */ = { isa = PBXGroup; children = ( + 4B03EDB21FE094DB0041DE17 /* actmgr */, 4B4A35BF1F6EFC2500919765 /* calendarselectmonth */, 4B4A35791F6C782D00919765 /* preferences */, 4B4A35751F6C76F000919765 /* eventeditor */, @@ -354,6 +394,7 @@ isa = PBXGroup; children = ( 4B4A35641F6C74D600919765 /* frmMain-Window.cpp */, + 4B03EDB81FE096F30041DE17 /* frmMain-Setup.cpp */, 4B4A35651F6C74D600919765 /* frmMain.cpp */, 4B4A35661F6C74D600919765 /* frmMain.h */, ); @@ -373,6 +414,7 @@ isa = PBXGroup; children = ( 4B4A356E1F6C75A500919765 /* frmNewAccount.cpp */, + 4B03EDB01FE092D00041DE17 /* frmNewAccount.mm */, 4B4A356F1F6C75A500919765 /* frmNewAccount.h */, ); name = newaccount; @@ -439,6 +481,7 @@ 4B4A35A21F6C904700919765 /* objects */ = { isa = PBXGroup; children = ( + 4B03EDA71FDDEF790041DE17 /* caldav */, 4B4A35AD1F6C94F600919765 /* calendarevent */, 4B4A35A71F6C94DF00919765 /* calendarobject */, 4B4A35A31F6C922700919765 /* calendarlist */, @@ -622,9 +665,13 @@ 4B4A35561F6C67C100919765 /* text.cpp in Sources */, 4B4A356C1F6C759100919765 /* frmEditAccount.cpp in Sources */, 4B4A35541F6C67C100919765 /* random.cpp in Sources */, + 4B03EDB11FE092D10041DE17 /* frmNewAccount.mm in Sources */, + 4B03EDB61FE096690041DE17 /* CalDAV-XMLProcessing.cpp in Sources */, 4B4A355C1F6C67DC00919765 /* frmAbout.cpp in Sources */, 4B4A35741F6C75CB00919765 /* frmCalendarEditor.cpp in Sources */, + 4B03EDB71FE0966C0041DE17 /* CalDAV.cpp in Sources */, 4B4A359A1F6C7C6500919765 /* XCCalendarListAccountCtrl.cpp in Sources */, + 4B03EDB51FE094F50041DE17 /* frmActivityMgr.cpp in Sources */, 4B4A357C1F6C78FF00919765 /* frmPreferences.cpp in Sources */, 4B4A35531F6C67C100919765 /* preferences.cpp in Sources */, 4B4A35971F6C7C6500919765 /* XCCalendarDay.cpp in Sources */, @@ -632,6 +679,7 @@ 4B4A35501F6C67C100919765 /* dirs.cpp in Sources */, 4B4A35551F6C67C100919765 /* svrblist.cpp in Sources */, 4B4A35681F6C74D600919765 /* frmMain.cpp in Sources */, + 4B03EDB91FE096F40041DE17 /* frmMain-Setup.cpp in Sources */, 4B4A35571F6C67C100919765 /* uuid.cpp in Sources */, 4B4A35B71F6D036300919765 /* CalendarDataStorage.cpp in Sources */, 4B4A35671F6C74D600919765 /* frmMain-Window.cpp in Sources */, diff --git a/source/forms/newaccount/frmNewAccount.cpp b/source/forms/newaccount/frmNewAccount.cpp index 57b14f9..c50cf84 100644 --- a/source/forms/newaccount/frmNewAccount.cpp +++ b/source/forms/newaccount/frmNewAccount.cpp @@ -504,14 +504,14 @@ void frmNewAccount::RunCalDAVTest( wxCommandEvent &event ) if (testConnection.SSLVerify() == COSSL_UNABLETOVERIFY){ #if defined(__APPLE__) - + testConnection.BypassSSLVerification(true); - CalDAVServerResult testConnection = testConnection.Connect(false); + CalDAVServerResult testConnectionResult = testConnection.Connect(false); testConnection.BypassSSLVerification(false); - int SSLResult = DisplayTrustPanel(&TestConnection); + int SSLResult = DisplayTrustPanel(&testConnection); if (SSLResult != NSOKButton){ @@ -519,7 +519,7 @@ void frmNewAccount::RunCalDAVTest( wxCommandEvent &event ) lblServerResponse->SetLabel(_("Not applicable")); lblServerSSLResult->SetLabel(_("Used")); lblServerSSLValid->SetLabel(_("No")); - lblConnectionResultText->SetLabel(_("An error occured whilst connnecting: ") + TestConnection.GetErrorMessage()); + lblConnectionResultText->SetLabel(_("An error occured whilst connnecting: ") + testConnection.GetErrorMessage()); btnPrevious->Enable(true); return; @@ -532,7 +532,8 @@ void frmNewAccount::RunCalDAVTest( wxCommandEvent &event ) switch(evalResult){ case kSecTrustResultProceed: lblServerSSLValid->SetLabel(_("Verified")); - break; + break; + case kSecTrustResultUnspecified: case kSecTrustResultConfirm: lblServerSSLValid->SetLabel(_("Verified (user)")); break; @@ -540,10 +541,14 @@ void frmNewAccount::RunCalDAVTest( wxCommandEvent &event ) lblServerSSLValid->SetLabel(_("Unable to verify")); } + lblServerConnResult->SetLabel(_("Connected")); lblServerResponse->SetLabel(_("Not applicable")); lblServerSSLResult->SetLabel(_("Used")); - if (evalResult != kSecTrustResultProceed){ + btnPrevious->Enable(true); + + if (evalResult != kSecTrustResultProceed && evalResult != kSecTrustResultUnspecified){ + lblConnectionResultText->SetLabel(_("An error occured whilst connnecting: ") + testConnection.GetErrorMessage()); return; } @@ -678,4 +683,4 @@ void frmNewAccount::RunCalDAVTest( wxCommandEvent &event ) wxCommandEvent resultsEvent(UPDATERESULTS); resultsEvent.SetClientData(resultData); wxPostEvent(this, resultsEvent); -} \ No newline at end of file +} diff --git a/source/forms/newaccount/frmNewAccount.h b/source/forms/newaccount/frmNewAccount.h index ae8c170..c1c75e3 100644 --- a/source/forms/newaccount/frmNewAccount.h +++ b/source/forms/newaccount/frmNewAccount.h @@ -76,8 +76,8 @@ class frmNewAccount : public frmNewAccountADT void CloseWindow( wxCommandEvent& event ); void WriteAccountDetails( wxFileConfig *cfgFileIn, wxString accountType, wxString directoryName ); #if defined(__APPLE__) - int DisplayTrustPanel(ConnectionObject *Connection); - SecTrustResultType ProcessResultType(ConnectionObject *Connection); + int DisplayTrustPanel(CalDAV *Connection); + SecTrustResultType ProcessResultType(CalDAV *Connection); #endif public: /** Constructor */ diff --git a/source/forms/newaccount/frmNewAccount.mm b/source/forms/newaccount/frmNewAccount.mm new file mode 100644 index 0000000..5b7d999 --- /dev/null +++ b/source/forms/newaccount/frmNewAccount.mm @@ -0,0 +1,52 @@ +// frmNewAccount.mm - OS X specific functions for frmNewAccount +// +// (c) 2012-2015 Xestia Software Development. +// +// This file is part of Xestia Address Book. +// +// Xestia Address Book 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, +// 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 Address Book. If not, see + +#import +#import + +#include "frmNewAccount.h" +#include "CalDAV.h" + +int frmNewAccount::DisplayTrustPanel(CalDAV *Connection){ + + NSInteger ResultValue; + + SFCertificateTrustPanel *secpanel = [SFCertificateTrustPanel sharedCertificateTrustPanel]; + + [secpanel setDefaultButtonTitle:@"Accept"]; + [secpanel setAlternateButtonTitle:@"Cancel"]; + [secpanel setInformativeText: @"This certificate is not trusted. Someone could be trying to eavesdrop on your connection. Do you want to accept this certificate anyway?\n\nAccept and trusting the certificate will fetch and process information as required.\nCancel will close the connection."]; + [secpanel setShowsHelp:YES]; + + [secpanel setParentWindow:(NSWindow*)this->GetHandle()]; + + ResultValue = [secpanel runModalForTrust:Connection->BuildSSLCollection() message:@"Certificate not trusted"]; + + return (int)ResultValue; + +} + +SecTrustResultType frmNewAccount::ProcessResultType(CalDAV *Connection){ + + SecTrustResultType EvalResult; + + SecTrustEvaluate(Connection->BuildSSLCollection(), &EvalResult); + + return EvalResult; + +} diff --git a/source/forms/preferences/frmPreferences.cpp b/source/forms/preferences/frmPreferences.cpp index 77abeae..fde8e03 100644 --- a/source/forms/preferences/frmPreferences.cpp +++ b/source/forms/preferences/frmPreferences.cpp @@ -335,6 +335,12 @@ void frmPreferences::DeleteAccount( wxCommandEvent& event ) accountDirDelFull.Append(wxT("\\accounts\\")); accountDirDelFull.Append(accountDirFull); +#elif defined(__APPLE__) + + accountDirDelFull.Append(wxString::FromUTF8(getenv("HOME"))); + accountDirDelFull.Append(wxT("/Library/Preferences/Xestia/Calendar/accounts/")); + accountDirDelFull.Append(accountDirFull); + #else accountDirDelFull.Append(wxString::FromUTF8(getenv("HOME"))); @@ -440,4 +446,4 @@ void frmPreferences::SetupPointers(bool *reloadAccountInc){ reloadAccountConfig = reloadAccountInc; -} \ No newline at end of file +} diff --git a/source/objects/CalDAV/CalDAV-XMLProcessing.cpp b/source/objects/CalDAV/CalDAV-XMLProcessing.cpp index ab0549b..935bf1c 100644 --- a/source/objects/CalDAV/CalDAV-XMLProcessing.cpp +++ b/source/objects/CalDAV/CalDAV-XMLProcessing.cpp @@ -736,4 +736,5 @@ string CalDAV::FetchXMLData(xmlNodePtr *nodePtr){ } -} \ No newline at end of file + return ""; +} diff --git a/source/objects/CalDAV/CalDAV.cpp b/source/objects/CalDAV/CalDAV.cpp index 48fdb74..3da1e6d 100644 --- a/source/objects/CalDAV/CalDAV.cpp +++ b/source/objects/CalDAV/CalDAV.cpp @@ -201,6 +201,13 @@ CalDAVServerResult CalDAV::Connect(bool doAuthentication){ switch(serverResult.code){ case CURLE_OK: authPassed = true; + if (connectionData.useSSL) + { + sslStatus = connectionData.useSSL; + sslVerified = COSSL_VERIFIED; + } + serverResult.result = CALDAVQUERYRESULT_OK; + break; case CURLE_HTTP_RETURNED_ERROR: if (connectionData.useSSL) { @@ -215,6 +222,7 @@ CalDAVServerResult CalDAV::Connect(bool doAuthentication){ break; case CURLE_SSL_CACERT: case CURLE_SSL_CONNECT_ERROR: + case CURLE_PEER_FAILED_VERIFICATION: if (connectionData.useSSL) { sslStatus = connectionData.useSSL; @@ -1890,4 +1898,4 @@ void CalDAV::ResetResults(){ headerList = nullptr; }*/ -} \ No newline at end of file +} diff --git a/source/objects/CalDAV/CalDAV.h b/source/objects/CalDAV/CalDAV.h index 377f6ea..eeb84e7 100644 --- a/source/objects/CalDAV/CalDAV.h +++ b/source/objects/CalDAV/CalDAV.h @@ -36,6 +36,11 @@ #include "../../common/sslcertstructs.h" #include "../../version.h" +#if defined (__APPLE__) +#import +#import +#endif + #if defined(__WIN32__) #include "../common/win32ssl.h" #endif -- 2.39.2