Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Replaced use of CardDAV with CardDAV2 in frmEditAccount
authorSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sat, 20 Aug 2016 09:28:29 +0000 (10:28 +0100)
committerSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sat, 20 Aug 2016 09:28:29 +0000 (10:28 +0100)
source/frmEditAccount.cpp
source/frmEditAccount.h

index d850bf8..faea105 100644 (file)
@@ -30,15 +30,17 @@ void frmEditAccount::DetectAddressBook( wxCommandEvent& event )
 
        // Check data before connecting.
 
-       wxString ValueData;
+       wxString ValueData = "";
+       std::string ReceivedServerPrefix = "";
        
-       long PortNum;
+       long PortNum = 80;
        ValueData = txtPort->GetValue();
        ValueData.ToLong(&PortNum, 10);
-       long RefreshNum;
+       long RefreshNum = 1800;
        ValueData = txtRefresh->GetValue();
        ValueData.ToLong(&RefreshNum, 10);
-       bool UseSSL;
+       bool UseSSL = true;
+       bool UsingSSLBypass = false;
        
        if (txtAddress->IsEmpty()){
        
@@ -75,102 +77,93 @@ void frmEditAccount::DetectAddressBook( wxCommandEvent& event )
                RefreshNum = 1800;
                
        }
+
+       CardDAV2 TestConnection(txtAddress->GetValue().ToStdString(),
+               wxAtoi(txtPort->GetValue()),
+               txtUsername->GetValue().ToStdString(),
+               txtPassword->GetValue().ToStdString(),
+               chkSSL->GetValue());
        
-       // Setup a CardDAV object.
+       // Test the connection.
        
-       CardDAV CDavObj;
+       TestConnection.SetupConnectionObject();
+       COConnectResult TestConnectionResult = TestConnection.Connect(false);
        
-       CDavObj.SetupConnection(txtAddress->GetValue(), (int)PortNum, txtUsername->GetValue(), txtPassword->GetValue(), UseSSL);
+       // If server is using SSL, verify that the SSL connection is valid.
        
-       // 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;
-                       
+       if (TestConnection.SSLVerify() == COSSL_UNABLETOVERIFY){
 #if defined(__APPLE__)
-       
-                       SSLResult = DisplayTrustPanel(&CDavObj);
-
 #elif defined(__WIN32__)
-
-                       BOOL ModifiedCertificateData;
-                       CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(&CDavObj, (HWND)this->GetHandle());
-
-                       if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)){
-                               wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog"));
-                               return;
-                       }
-
-                       if (ModifiedCertificateData == FALSE){
-                               wxMessageBox(_("Unable to get server prefix without a valid SSL certificate."), _("Error getting server prefix"));
-                               return;
-                       }
-
 #else
-                       
-                       frmInvalidSSLCertificate *frmICPtr = new frmInvalidSSLCertificate(this);
+       
+               // Connect again and fetch SSL certificate information.
+               
+               TestConnection.BypassSSLVerification(true);
+               
+               COConnectResult TestConnectionResult = TestConnection.Connect(false);
+               
+               TestConnection.BypassSSLVerification(false);
 
-                       frmICPtr->LoadDataNew(CDavObj.GetSSLVerifyResults(), txtAddress->GetValue());
-                       frmICPtr->ShowModal();
-                                       
-                       SSLResult = frmICPtr->GetResult();
+               SSLCertCollectionString CertData = TestConnection.BuildSSLCollection();
+               frmInvalidSSLCertificate *frmICPtr = new frmInvalidSSLCertificate(this);
+               
+               frmICPtr->LoadDataNew(CertData, txtAddress->GetValue().ToStdString());
+               frmICPtr->ShowModal();
+                                                               
+               int SSLResult = frmICPtr->GetResult();
                                                        
-                       // Clean up before processing response.
+               // Clean up before processing response.
                                
-                       delete frmICPtr;
-                       frmICPtr = NULL;
-                       
-#endif
-                       
-                       // Process the response from the user.
+               delete frmICPtr;
+               frmICPtr = NULL;
+                                                       
+               // Process the response from the user.
                                                        
-                       if (SSLResult == 1){
+               if (SSLResult == 1){
                                                                
-                               // Accept the Certificate.
-
-                               CDavObj.AllowSelfSignTest(TRUE);
+                       // Accept the Certificate.
+                       
+                       UsingSSLBypass = true;
+                       TestConnection.BypassSSLVerification(true);
+               
+                       COConnectResult TestConnectionResult = TestConnection.Connect(true);
+               
+                       TestConnection.BypassSSLVerification(false);
                                                                
-                       } else if (SSLResult == 2){
+               } else if (SSLResult == 2){
                                                                
-                               // Reject the certificate, abort the task and mark as failed.
+                       // Reject the certificate, abort the task.
 
-                               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;
+                       wxMessageBox(_("Server certficiate rejected. Unable to detect the prefix."), _("Failed"), wxOK+wxICON_ERROR);
+                       
+                       return; 
+                       
+               }               
+               
+#endif
+       }
+       
+       // Get the server prefix if the connection was successful.
+       
+       if (TestConnectionResult == COCONNECT_OK){
 
+               if (UsingSSLBypass == true){
+                       TestConnection.BypassSSLVerification(true);                     
                }
+               
+               COServerResponse PrefixRequestResult = TestConnection.GetDefaultPrefix(&ReceivedServerPrefix);
 
+               if (UsingSSLBypass == true){
+                       TestConnection.BypassSSLVerification(true);                     
+               }
+               
+       } else {
+               
+               wxMessageBox(_("An error occured whilst detecting the prefix: ") + TestConnection.GetErrorMessage(), _("Failed"), wxOK+wxICON_ERROR);
+               
        }
        
-       // Attempt to extract the CardDAV address.
-       
-       wxString ABURL = CDavObj.GetDefaultAddressBookURL();
-       
-       txtPrefix->SetValue(ABURL);
+       txtPrefix->SetValue(ReceivedServerPrefix);
        
 }
 
index 754e2c7..2cc4bd8 100644 (file)
@@ -28,10 +28,12 @@ Subclass of frmEditAccountADT, which is generated by wxFormBuilder.
 #include <wx/fileconf.h>
 #include "frmInvalidSSLCertificate.h"
 #include "common/svrblist.h"
-#include "carddav/carddav.h"
+#include "carddav2/carddav2.h"
 
 #if defined(__WIN32__)
 #include "common/win32ssl.h"
+#else 
+#include "common/sslcertstructs.h"
 #endif
 
 //// end generated include
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