X-Git-Url: http://Server1/repobrowser/?a=blobdiff_plain;f=source%2FfrmEditAccount.cpp;h=18e5591d144d6f92b630d6fb8bb552934642ee0c;hb=d4087a12e1dccd74c089f2583500578fa5e59212;hp=b7c8fef333ab26e712ab4aca059ba48af971e283;hpb=45729fca56479bd9158486e0cda0c4a94b4dd1dc;p=xestiaab%2F.git diff --git a/source/frmEditAccount.cpp b/source/frmEditAccount.cpp index b7c8fef..18e5591 100644 --- a/source/frmEditAccount.cpp +++ b/source/frmEditAccount.cpp @@ -1,4 +1,23 @@ +// frmEditAccount.cpp - Edit Account form. +// +// (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 + #include "frmEditAccount.h" +#include "frmInvalidSSLCertificate.h" #include "carddav/carddav.h" frmEditAccount::frmEditAccount( wxWindow* parent ) @@ -63,7 +82,69 @@ void frmEditAccount::DetectAddressBook( wxCommandEvent& event ) CardDAV CDavObj; - CDavObj.SetupConnection(txtAddress->GetValue(), PortNum, txtUsername->GetValue(), txtPassword->GetValue(), UseSSL); + CDavObj.SetupConnection(txtAddress->GetValue(), (int)PortNum, txtUsername->GetValue(), txtPassword->GetValue(), UseSSL); + + // Verify SSL trust first before doing anything. + + if (UseSSL == TRUE){ + + CURLcode sslcode = CDavObj.SSLVerifyTest(); + + if (sslcode == CURLE_OK){ + + // Certificate is okay. Do nothing. + + } else if (sslcode == CURLE_SSL_CACERT || sslcode == CURLE_SSL_CONNECT_ERROR){ + + // Certificate is more than likely a self-signed or + // expired certificate so display the invalid + // SSL certificate message. + + // Setup the data to be sent in the wxPostEvent command. + + int SSLResult; + + frmInvalidSSLCertificate *frmICPtr = new frmInvalidSSLCertificate(this); + + frmICPtr->LoadDataNew(CDavObj.GetSSLVerifyResults(), txtAddress->GetValue()); + frmICPtr->ShowModal(); + + SSLResult = frmICPtr->GetResult(); + + // Clean up before processing response. + + delete frmICPtr; + frmICPtr = NULL; + + // Process the response from the user. + + if (SSLResult == 1){ + + // Accept the Certificate. + + CDavObj.AllowSelfSignTest(TRUE); + + } else if (SSLResult == 2){ + + // Reject the certificate, abort the task and mark as failed. + + wxMessageBox(_("An error occured whilst connnecting: ") + CDavObj.GetErrorMessage() + wxString::Format(wxT(" (%i)\n%s"), sslcode, CDavObj.GetErrorBuffer().mb_str()), _("Failed"), wxOK+wxICON_ERROR); + return; + + } + + + } else { + + // Something else happened. Stop the process and + // display an error message instead. + + wxMessageBox(_("An error occured whilst connnecting: ") + CDavObj.GetErrorMessage() + wxString::Format(wxT(" (%i)\n%s"), sslcode, CDavObj.GetErrorBuffer().mb_str()), _("Failed"), wxOK+wxICON_ERROR); + return; + + } + + } // Attempt to extract the CardDAV address. @@ -75,13 +156,16 @@ void frmEditAccount::DetectAddressBook( wxCommandEvent& event ) void frmEditAccount::LoadPointers( wxFileConfig* cfgin ){ + // Setup the account configuration file pointer. + cfgfile = cfgin; } void frmEditAccount::LoadSettings( wxString AccNameIn ){ - // Get the data from the accounts settings file. + // Get the data from the accounts settings file and + // fill in the account fields. AccName = AccNameIn; long itemindex = 0; @@ -186,32 +270,6 @@ void frmEditAccount::UpdateSettings( wxCommandEvent& event ) cfgfile->DeleteEntry(wxT("refresh"), FALSE); cfgfile->Write(wxT("refresh"), txtRefresh->GetValue()); - /*cfgfile->Read("address", &AccountData); - //txtAddress->SetValue(AccountData); - - cfgfile->Read("port", &AccountData); - //txtPort->SetValue(AccountData); - - cfgfile->Read("username", &AccountData); - //txtUsername->SetValue(AccountData); - - cfgfile->Read("password", &AccountData); - //txtPassword->SetValue(AccountData); - - cfgfile->Read("prefix", &AccountData); - //txtPrefix->SetValue(AccountData); - - cfgfile->Read("ssl", &AccountData); - if (AccountData == wxT("true")){ - - chkSSL->SetValue(TRUE); - - } - - cfgfile->Read("refresh", &AccountData); - //txtRefresh->SetValue(AccountData);*/ - - break; } @@ -220,12 +278,28 @@ void frmEditAccount::UpdateSettings( wxCommandEvent& event ) ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex); } + + // Set the dialog result to true and close the window. + DialogResult = true; this->Close(); } void frmEditAccount::CloseWindow( wxCommandEvent& event ) { + + // Set the dialog result to false and close the window. + + DialogResult = false; this->Close(); + } + +bool frmEditAccount::GetDialogResult(){ + + // Get the result of the dialog. + + return DialogResult; + +} \ No newline at end of file