Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmNewAccount now using the CardDAV2 class
[xestiaab/.git] / source / frmNewAccount-CardDAV2.cpp
1 // frmNewAccount.cpp - New Account form (CardDAV2 account section).
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
10 //
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/> 
19 #include "frmNewAccount.h"
20 #include <iostream>
22 void frmNewAccount::RunCardDAV2Test( wxCommandEvent& event ){
23         
24         NewAccountResult *ResultData = new NewAccountResult;
25         
26         lblServerConnResult->SetLabel(_("Testing..."));
27         lblCardDAVSupportResult->SetLabel(_(""));
28         lblServerResponse->SetLabel(_(""));
29         lblServerSSLResult->SetLabel(_(""));
30         lblServerSSLValid->SetLabel(_(""));
31         lblAbleToLoginResult->SetLabel(_(""));
32         bool UsingSSLBypass = false;
33         
34         // Setup a CardDAV2 connection object for testing.
36         CardDAV2 TestConnection(txtServerAddress->GetValue().ToStdString(),
37                 wxAtoi(txtServerPort->GetValue()),
38                 txtUsername->GetValue().ToStdString(),
39                 txtPassword->GetValue().ToStdString(),
40                 chkUseSSL->GetValue());
41         
42         // Test the connection.
43         
44         TestConnection.SetupConnectionObject();
45         COConnectResult TestConnectionResult = TestConnection.Connect(false);
46         
47         // If server is using SSL, verify that the SSL connection is valid.
48         
49         if (TestConnection.SSLVerify() == COSSL_UNABLETOVERIFY){
50 #if defined(__APPLE__)
51 #elif defined(__WIN32__)
52 #else
53         
54                 // Connect again and fetch SSL certificate information.
55                 
56                 TestConnection.BypassSSLVerification(true);
57                 
58                 COConnectResult TestConnectionResult = TestConnection.Connect(false);
59                 
60                 TestConnection.BypassSSLVerification(false);
62                 SSLCertCollectionString CertData = TestConnection.BuildSSLCollection();
63                 frmInvalidSSLCertificate *frmICPtr = new frmInvalidSSLCertificate(this);
64                 
65                 frmICPtr->LoadDataNew(CertData, txtServerAddress->GetValue().ToStdString());
66                 frmICPtr->ShowModal();
67                                                                 
68                 int SSLResult = frmICPtr->GetResult();
69                                                         
70                 // Clean up before processing response.
71                                 
72                 delete frmICPtr;
73                 frmICPtr = NULL;
74                                                         
75                 // Process the response from the user.
76                                                         
77                 if (SSLResult == 1){
78                                                                 
79                         // Accept the Certificate.
80                         
81                         UsingSSLBypass = true;
82                         TestConnection.BypassSSLVerification(true);
83                 
84                         COConnectResult TestConnectionResult = TestConnection.Connect(true);
85                 
86                         TestConnection.BypassSSLVerification(false);
87                                                                 
88                 } else if (SSLResult == 2){
89                                                                 
90                         // Reject the certificate, abort the task and mark as failed.
92                         // TODO: Integrate into the code.
93                         
94                         //lblConnectionResultText->SetLabel(_("An error occured whilst connnecting: ") + CardDAVConn.GetErrorMessage() + wxString::Format(wxT(" (%i)\n%s"), sslcode, CardDAVConn.GetErrorBuffer().mb_str()));
95                                                                 
96                 }               
97                 
98 #endif
99         }
100         
101         // Get the server prefix if the connection was successful.
102         
103         if (TestConnectionResult == COCONNECT_OK){
105                 if (UsingSSLBypass == true){
106                         TestConnection.BypassSSLVerification(true);                     
107                 }
108                 
109                 std::string ReceivedServerPrefix;
110                 
111                 COServerResponse PrefixRequestResult = TestConnection.GetDefaultPrefix(&ReceivedServerPrefix);
113                 if (UsingSSLBypass == true){
114                         TestConnection.BypassSSLVerification(true);                     
115                 }
116                 
117         }
118         
119         TestConnectionResult == COCONNECT_OK ? ResultData->Connected = true : ResultData->Connected = false;
120         
121         ResultData->SSLStatus = TestConnection.CanDoSSL();
122         ResultData->SSLVerified = TestConnection.SSLVerify();
123         ResultData->ValidResponse = TestConnection.HasValidResponse();
124         ResultData->AuthPassed = TestConnection.AbleToLogin();
125         ResultData->CanProcess = TestConnection.CanDoProcessing();
126         ResultData->ErrorMessage = TestConnection.GetErrorMessage();
127         
128         // Post event back confirming the tests.
129         
130         wxCommandEvent ResultsEvent(UPDATERESULTS);
131         ResultsEvent.SetClientData(ResultData);
132         wxPostEvent(this, ResultsEvent);
133         
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