Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
CalDAV: Implemented SSL support (taken from XAB)
authorSteve Brokenshire <sbrokenshire@xestia.co.uk>
Wed, 6 Dec 2017 23:28:11 +0000 (23:28 +0000)
committerSteve Brokenshire <sbrokenshire@xestia.co.uk>
Wed, 6 Dec 2017 23:28:11 +0000 (23:28 +0000)
source/objects/CalDAV/CalDAV.cpp
source/objects/CalDAV/CalDAV.h

index 25c322e..5914817 100644 (file)
@@ -103,7 +103,10 @@ CalDAVStatus CalDAV::GetConnectionData(){
        
 }
 
-CalDAVServerResult CalDAV::Connect(){
+CalDAVServerResult CalDAV::Connect(bool doAuthentication){
+
+       connectionData.useSSL ? SetupDefaultParametersSSL(doAuthentication) : SetupDefaultParametersNonSSL(doAuthentication);
+       ResetResults();
 
        CalDAVServerResult serverResult;
 
@@ -123,6 +126,7 @@ CalDAVServerResult CalDAV::Connect(){
        curl_easy_setopt(connectionHandle, CURLOPT_URL, serverAddress.c_str());
        curl_easy_setopt(connectionHandle, CURLOPT_USERPWD, serverUserPass.c_str());
        curl_easy_setopt(connectionHandle, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
+       curl_easy_setopt(connectionHandle, CURLOPT_ERRORBUFFER, sessionErrorBuffer);
        curl_easy_setopt(connectionHandle, CURLOPT_FAILONERROR, 1L);
        curl_easy_setopt(connectionHandle, CURLOPT_TIMEOUT, connectionData.timeout);
        curl_easy_setopt(connectionHandle, CURLOPT_WRITEFUNCTION, CalDAVReceive);
@@ -134,20 +138,46 @@ CalDAVServerResult CalDAV::Connect(){
        serverResult.code = curl_easy_perform(connectionHandle);
 
        // Process the result received from the server.
-       
-       if (serverResult.code != CURLE_OK){
-               
-               serverResult.result = CALDAVQUERYRESULT_SERVERERROR;
-               
-       } else {
-               
-               serverResult.result = CALDAVQUERYRESULT_OK;
-               
-       }
-       
+
        // Get the HTTP code.
        
        curl_easy_getinfo(connectionHandle, CURLINFO_RESPONSE_CODE, &serverResult.httpCode);
+
+       switch(serverResult.code){
+               case CURLE_OK:
+                       authPassed = true;
+               case CURLE_HTTP_RETURNED_ERROR:
+                       if (connectionData.useSSL)
+                       {
+                               sslStatus = connectionData.useSSL;
+                               sslVerified = COSSL_VERIFIED;
+                       }
+                       serverResult.result = CALDAVQUERYRESULT_OK;
+                       if (serverResult.httpCode == 401)
+                       {
+                               authPassed = false;
+                       }
+                       break;
+               case CURLE_SSL_CACERT:
+               case CURLE_SSL_CONNECT_ERROR:
+                       if (connectionData.useSSL)
+                       {
+                               sslStatus = connectionData.useSSL;
+                               sslVerified = COSSL_UNABLETOVERIFY;
+                       }
+                       serverResult.result = CALDAVQUERYRESULT_SSLFAILURE;
+                       authPassed = false;
+                       break;
+               default:
+                       serverResult.result = CALDAVQUERYRESULT_SERVERERROR;
+                       authPassed = false;
+                       break;
+       };
+
+       if (serverResult.httpCode >= 200 && serverResult.httpCode <= 299)
+       {
+               validResponse = true;
+       }
        
        return serverResult;
        
@@ -328,6 +358,7 @@ string CalDAV::GetUserPrincipal(){
 
        curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, "PROPFIND");
        curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 1L);
+       curl_easy_setopt(connectionHandle, CURLOPT_ERRORBUFFER, sessionErrorBuffer);
        curl_easy_setopt(connectionHandle, CURLOPT_READDATA, &userPrincipalSendData);
        curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, CalDAVSend);
        
@@ -361,6 +392,7 @@ string CalDAV::GetUserPrincipal(){
        // Reset the changed settings.
        
        curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 0L);
+       curl_easy_setopt(connectionHandle, CURLOPT_ERRORBUFFER, sessionErrorBuffer);
        curl_easy_setopt(connectionHandle, CURLOPT_READDATA, NULL);
        curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, NULL);
 
@@ -402,6 +434,7 @@ string CalDAV::GetCalendarHome(string userPrincipalURI){
        curl_easy_setopt(connectionHandle, CURLOPT_URL, calendarHomeURL.c_str());
        curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, "PROPFIND");
        curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 1L);
+       curl_easy_setopt(connectionHandle, CURLOPT_ERRORBUFFER, sessionErrorBuffer);
        curl_easy_setopt(connectionHandle, CURLOPT_READDATA, &calendarHomeSendData);
        curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, CalDAVSend);
        
@@ -438,6 +471,7 @@ string CalDAV::GetCalendarHome(string userPrincipalURI){
        curl_easy_setopt(connectionHandle, CURLOPT_URL, originalServerAddress.c_str());
        
        curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 0L);
+       curl_easy_setopt(connectionHandle, CURLOPT_ERRORBUFFER, sessionErrorBuffer);
        curl_easy_setopt(connectionHandle, CURLOPT_READDATA, NULL);
        curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, NULL);
        curl_easy_setopt(connectionHandle, CURLOPT_HTTPHEADER, NULL);
@@ -497,6 +531,7 @@ CalDAVCalendarList CalDAV::GetCalendars(){
        curl_easy_setopt(connectionHandle, CURLOPT_URL, calendarListURLAddress.c_str());
        curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, "PROPFIND");
        curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 1L);
+       curl_easy_setopt(connectionHandle, CURLOPT_ERRORBUFFER, sessionErrorBuffer);
        curl_easy_setopt(connectionHandle, CURLOPT_READDATA, &calendarListSendData);
        curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, CalDAVSend);
        
@@ -535,6 +570,7 @@ CalDAVCalendarList CalDAV::GetCalendars(){
        curl_easy_setopt(connectionHandle, CURLOPT_URL, originalServerAddress.c_str());
        curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, NULL);        
        curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 0L);
+       curl_easy_setopt(connectionHandle, CURLOPT_ERRORBUFFER, sessionErrorBuffer);
        curl_easy_setopt(connectionHandle, CURLOPT_READDATA, NULL);
        curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, NULL);
        
@@ -604,6 +640,7 @@ CalDAVEntryList CalDAV::GetEntryList(string *calendarHREF){
        curl_easy_setopt(connectionHandle, CURLOPT_URL, entryListURLAddress.c_str());
        curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, "REPORT");
        curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 1L);
+       curl_easy_setopt(connectionHandle, CURLOPT_ERRORBUFFER, sessionErrorBuffer);
        curl_easy_setopt(connectionHandle, CURLOPT_READDATA, &entryListSendData);
        curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, CalDAVSend);
        
@@ -642,6 +679,7 @@ CalDAVEntryList CalDAV::GetEntryList(string *calendarHREF){
        curl_easy_setopt(connectionHandle, CURLOPT_URL, originalServerAddress.c_str());
        curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, NULL);        
        curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 0L);
+       curl_easy_setopt(connectionHandle, CURLOPT_ERRORBUFFER, sessionErrorBuffer);
        curl_easy_setopt(connectionHandle, CURLOPT_READDATA, NULL);
        curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, NULL);
        
@@ -698,6 +736,7 @@ CalDAVEntryList CalDAV::GetEntryList(string *calendarHREF, string *calendarTag){
        curl_easy_setopt(connectionHandle, CURLOPT_URL, entryListURLAddress.c_str());
        curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, "REPORT");
        curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 1L);
+       curl_easy_setopt(connectionHandle, CURLOPT_ERRORBUFFER, sessionErrorBuffer);
        curl_easy_setopt(connectionHandle, CURLOPT_READDATA, &entryListSendData);
        curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, CalDAVSend);
        
@@ -775,6 +814,7 @@ CalDAVEntryList CalDAV::GetEntryList(string *calendarHREF, string *calendarTag){
        curl_easy_setopt(connectionHandle, CURLOPT_URL, entryListURLAddress.c_str());
        curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, "REPORT");
        curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 1L);
+       curl_easy_setopt(connectionHandle, CURLOPT_ERRORBUFFER, sessionErrorBuffer);
        curl_easy_setopt(connectionHandle, CURLOPT_READDATA, &updatedEntryListSendData);
        curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, CalDAVSend);
        
@@ -817,6 +857,7 @@ CalDAVEntryList CalDAV::GetEntryList(string *calendarHREF, string *calendarTag){
        curl_easy_setopt(connectionHandle, CURLOPT_URL, originalServerAddress.c_str());
        curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, NULL);        
        curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 0L);
+       curl_easy_setopt(connectionHandle, CURLOPT_ERRORBUFFER, sessionErrorBuffer);
        curl_easy_setopt(connectionHandle, CURLOPT_READDATA, NULL);
        curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, NULL);
        
@@ -898,10 +939,11 @@ CalDAVServerResult CalDAV::AddCalendar(string *calendarName, string *calendarSho
        
        struct curl_slist *calendarRequestHeader = NULL;
        
-       //curl_easy_setopt(ConnectionHandle, CURLOPT_HTTPHEADER, CalendarRequestHeader);
+       //curl_easy_setopt(connectionHandle, CURLOPT_HTTPHEADER, CalendarRequestHeader);
        curl_easy_setopt(connectionHandle, CURLOPT_URL, calendarListURLAddress.c_str());
        curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, "MKCALENDAR");
        curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 1L);
+       curl_easy_setopt(connectionHandle, CURLOPT_ERRORBUFFER, sessionErrorBuffer);
        curl_easy_setopt(connectionHandle, CURLOPT_READDATA, &calendarAddSendData);
        curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, CalDAVSend);
        
@@ -926,6 +968,7 @@ CalDAVServerResult CalDAV::AddCalendar(string *calendarName, string *calendarSho
        curl_easy_setopt(connectionHandle, CURLOPT_URL, originalServerAddress.c_str());
        curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, NULL);        
        curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 0L);
+       curl_easy_setopt(connectionHandle, CURLOPT_ERRORBUFFER, sessionErrorBuffer);
        curl_easy_setopt(connectionHandle, CURLOPT_READDATA, NULL);
        curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, NULL);
        
@@ -1026,10 +1069,11 @@ CalDAVServerResult CalDAV::EditCalendarProcess(string *calendarHREF,
        
        struct curl_slist *calendarRequestHeader = NULL;
        
-       //curl_easy_setopt(ConnectionHandle, CURLOPT_HTTPHEADER, CalendarRequestHeader);
+       //curl_easy_setopt(connectionHandle, CURLOPT_HTTPHEADER, CalendarRequestHeader);
        curl_easy_setopt(connectionHandle, CURLOPT_URL, calendarEditURLAddress.c_str());
        curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, "PROPPATCH");
        curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 1L);
+       curl_easy_setopt(connectionHandle, CURLOPT_ERRORBUFFER, sessionErrorBuffer);
        curl_easy_setopt(connectionHandle, CURLOPT_READDATA, &calendarEditSendData);
        curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, CalDAVSend);
        
@@ -1054,6 +1098,7 @@ CalDAVServerResult CalDAV::EditCalendarProcess(string *calendarHREF,
        curl_easy_setopt(connectionHandle, CURLOPT_URL, originalServerAddress.c_str());
        curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, NULL);        
        curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 0L);
+       curl_easy_setopt(connectionHandle, CURLOPT_ERRORBUFFER, sessionErrorBuffer);
        curl_easy_setopt(connectionHandle, CURLOPT_READDATA, NULL);
        curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, NULL);
        
@@ -1199,6 +1244,7 @@ CalDAVServerResult CalDAV::DeleteCalendar(string *calendarHREF){
        curl_easy_setopt(connectionHandle, CURLOPT_URL, originalServerAddress.c_str());
        curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, NULL);        
        curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 0L);
+       curl_easy_setopt(connectionHandle, CURLOPT_ERRORBUFFER, sessionErrorBuffer);
        curl_easy_setopt(connectionHandle, CURLOPT_READDATA, NULL);
        curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, NULL);
        curl_easy_setopt(connectionHandle, CURLOPT_HTTPHEADER, NULL);
@@ -1262,6 +1308,7 @@ CalDAVServerResult CalDAV::GetEntryETag(string *calendarEntryHREF, string *eTagV
        curl_easy_setopt(connectionHandle, CURLOPT_URL, getETagURLAddress.c_str());
        curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, "REPORT");
        curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 1L);
+       curl_easy_setopt(connectionHandle, CURLOPT_ERRORBUFFER, sessionErrorBuffer);
        curl_easy_setopt(connectionHandle, CURLOPT_READDATA, &entryETagGetData);
        curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, CalDAVSend);
        
@@ -1294,6 +1341,7 @@ CalDAVServerResult CalDAV::GetEntryETag(string *calendarEntryHREF, string *eTagV
        curl_easy_setopt(connectionHandle, CURLOPT_URL, originalServerAddress.c_str());
        curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, NULL);        
        curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 0L);
+       curl_easy_setopt(connectionHandle, CURLOPT_ERRORBUFFER, sessionErrorBuffer);
        curl_easy_setopt(connectionHandle, CURLOPT_READDATA, NULL);
        curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, NULL);
        curl_easy_setopt(connectionHandle, CURLOPT_HTTPHEADER, NULL);
@@ -1324,6 +1372,7 @@ CalDAVServerResult CalDAV::AddEntry(string *calendarEntryHREF, string *entryData
        curl_easy_setopt(connectionHandle, CURLOPT_URL, entryAddURLAddress.c_str());
        curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, "PUT");
        curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 1L);
+       curl_easy_setopt(connectionHandle, CURLOPT_ERRORBUFFER, sessionErrorBuffer);
        curl_easy_setopt(connectionHandle, CURLOPT_READDATA, &entryAddSendData);
        curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, CalDAVSend);
        
@@ -1348,6 +1397,7 @@ CalDAVServerResult CalDAV::AddEntry(string *calendarEntryHREF, string *entryData
        curl_easy_setopt(connectionHandle, CURLOPT_URL, originalServerAddress.c_str());
        curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, NULL);        
        curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 0L);
+       curl_easy_setopt(connectionHandle, CURLOPT_ERRORBUFFER, sessionErrorBuffer);
        curl_easy_setopt(connectionHandle, CURLOPT_READDATA, NULL);
        curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, NULL);
        curl_easy_setopt(connectionHandle, CURLOPT_HTTPHEADER, NULL);
@@ -1385,6 +1435,7 @@ CalDAVServerResult CalDAV::EditEntry(string *calendarEntryHREF, string *entryDat
        curl_easy_setopt(connectionHandle, CURLOPT_URL, entryAddURLAddress.c_str());
        curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, "PUT");
        curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 1L);
+       curl_easy_setopt(connectionHandle, CURLOPT_ERRORBUFFER, sessionErrorBuffer);
        curl_easy_setopt(connectionHandle, CURLOPT_READDATA, &entryAddSendData);
        curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, CalDAVSend);
        
@@ -1409,6 +1460,7 @@ CalDAVServerResult CalDAV::EditEntry(string *calendarEntryHREF, string *entryDat
        curl_easy_setopt(connectionHandle, CURLOPT_URL, originalServerAddress.c_str());
        curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, NULL);        
        curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 0L);
+       curl_easy_setopt(connectionHandle, CURLOPT_ERRORBUFFER, sessionErrorBuffer);
        curl_easy_setopt(connectionHandle, CURLOPT_READDATA, NULL);
        curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, NULL);
        curl_easy_setopt(connectionHandle, CURLOPT_HTTPHEADER, NULL);
@@ -1452,6 +1504,7 @@ CalDAVServerResult CalDAV::DeleteEntry(string *calendarEntryHREF){
        curl_easy_setopt(connectionHandle, CURLOPT_URL, originalServerAddress.c_str());
        curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, NULL);        
        curl_easy_setopt(connectionHandle, CURLOPT_UPLOAD, 0L);
+       curl_easy_setopt(connectionHandle, CURLOPT_ERRORBUFFER, sessionErrorBuffer);
        curl_easy_setopt(connectionHandle, CURLOPT_READDATA, NULL);
        curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, NULL);
        curl_easy_setopt(connectionHandle, CURLOPT_HTTPHEADER, NULL);
@@ -1462,19 +1515,19 @@ CalDAVServerResult CalDAV::DeleteEntry(string *calendarEntryHREF){
 
 COSSLVerified CalDAV::SSLVerify()
 {
-       return SSLVerified;
+       return sslVerified;
 }
 
-void CalDAV::BypassSSLVerification(bool EnableBypass){
-       EnableSSLBypass = EnableBypass;
-       SSLSelfSigned = EnableBypass;
+void CalDAV::BypassSSLVerification(bool enableBypass){
+       enableSSLBypass = enableBypass;
+       sslSelfSigned = enableBypass;
 }
 
 #if defined(__APPLE__)
 
 SecTrustRef CalDAV::BuildSSLCollection(){
        
-       return CertificateData;
+       return certificateData;
        
 }
 
@@ -1482,7 +1535,7 @@ SecTrustRef CalDAV::BuildSSLCollection(){
 
 PCCERT_CONTEXT CalDAV::BuildSSLCollection(){
 
-       return CertificateData;
+       return certificateData;
 
 }
 
@@ -1492,7 +1545,7 @@ SSLCertCollectionString CalDAV::BuildSSLCollection(){
 
        // Build and return the SSL collection.
        
-       SSLCertCollectionString SSLCertInfo;
+       SSLCertCollectionString sslCertInfo;
 
        // Grab the certificate data.
 
@@ -1503,50 +1556,73 @@ SSLCertCollectionString CalDAV::BuildSSLCollection(){
 
        certptr.certdata = NULL;
        
-       CURLcode result = curl_easy_getinfo(ConnectionSession, CURLINFO_CERTINFO, &certptr.certinfo);
+       CURLcode result = curl_easy_getinfo(connectionHandle, CURLINFO_CERTINFO, &certptr.certinfo);
        
-       std::string CertPropName;
-       std::string CertPropValue;
+       std::string certPropName;
+       std::string certPropValue;
        
        for (int i = 0; i < certptr.certinfo->num_of_certs; i++){
                
                struct curl_slist *slist;
-               SSLCertDataString SSLCertDataInc;
+               SSLCertDataString sslCertDataInc;
                
                for (slist = certptr.certinfo->certinfo[i]; slist; slist = slist->next){
                        
                        // Using wxStringTokenizer from wxWidgets.
                        
-                       wxStringTokenizer CertDataInc(wxString::FromUTF8(slist->data), ":");
+                       wxStringTokenizer certDataInc(wxString::FromUTF8(slist->data), ":");
                        
                        // Get first token as the property name.
                        
-                       CertPropName = CertDataInc.GetNextToken().ToStdString();
+                       certPropName = certDataInc.GetNextToken().ToStdString();
                        
                        // Get remaining tokens as the property value.
                        
-                       while(CertDataInc.HasMoreTokens()){
+                       while(certDataInc.HasMoreTokens()){
                        
-                               CertPropValue.append(CertDataInc.GetNextToken());
+                               certPropValue.append(certDataInc.GetNextToken());
                        
                        }
                        
-                       SSLCertDataInc.CertData.insert(std::make_pair(CertPropName, CertPropValue));
-                       CertPropName.clear();
-                       CertPropValue.clear();
+                       sslCertDataInc.CertData.insert(std::make_pair(certPropName, certPropValue));
+                       certPropName.clear();
+                       certPropValue.clear();
                        
                }
        
-               SSLCertInfo.SSLCollection.insert(std::make_pair(i, SSLCertDataInc));
+               sslCertInfo.SSLCollection.insert(std::make_pair(i, sslCertDataInc));
        
        }
        
-       return SSLCertInfo;
+       return sslCertInfo;
 
 }
 
 #endif
 
+bool CalDAV::CanDoSSL(){
+       return sslStatus;
+}
+
+bool CalDAV::HasValidResponse(){
+       return validResponse;
+}
+
+bool CalDAV::AbleToLogin(){
+       return authPassed;
+}
+
+bool CalDAV::IsSelfSigned(){
+       return sslSelfSigned;
+}
+
+string CalDAV::GetErrorMessage(){
+       
+       errorMessage = sessionErrorBuffer;      
+       return errorMessage;
+       
+}
+
 static bool CalDAVObjectValidSettings(CalDAVConnectionData *connData){
 
        // Check if the passed CalDAV Connection Data is has
@@ -1608,7 +1684,7 @@ static bool CalDAVObjectValidSettings(CalDAVConnectionData *connData){
 
 }
 
-static string BuildServerAddress(CalDAVConnectionData *connData, string uriAddress){
+string CalDAV::BuildServerAddress(CalDAVConnectionData *connData, string uriAddress){
        
        string serverAddress;
        
@@ -1635,3 +1711,106 @@ static string BuildServerAddress(CalDAVConnectionData *connData, string uriAddre
        return serverAddress;
        
 }
+
+void CalDAV::SetupDefaultParametersNonSSL(bool doAuthentication){
+       
+       std::string serverAddress = "";
+
+       string serverAddressURL = "http://" + connectionData.hostname + ":" + to_string(connectionData.port) + "/";
+       string usernamePassword = connectionData.username + ":" + connectionData.password;
+       
+       curl_easy_setopt(connectionHandle, CURLOPT_URL, serverAddressURL.c_str());
+       curl_easy_setopt(connectionHandle, CURLOPT_NOPROGRESS, 1L);
+       curl_easy_setopt(connectionHandle, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST|CURLAUTH_BASIC);
+       curl_easy_setopt(connectionHandle, CURLOPT_TIMEOUT, 60);
+       curl_easy_setopt(connectionHandle, CURLOPT_FAILONERROR, true);
+       curl_easy_setopt(connectionHandle, CURLOPT_USERAGENT, XSDCAL_USERAGENT);
+       curl_easy_setopt(connectionHandle, CURLOPT_NOSIGNAL, 1L);
+       curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, "GET");
+       curl_easy_setopt(connectionHandle, CURLOPT_HTTPHEADER, nullptr);
+       curl_easy_setopt(connectionHandle, CURLOPT_POSTFIELDS, nullptr);
+       curl_easy_setopt(connectionHandle, CURLOPT_POSTFIELDSIZE, 0L);
+
+       if (doAuthentication == true){
+               curl_easy_setopt(connectionHandle, CURLOPT_USERPWD, usernamePassword.c_str());
+       } else {
+               curl_easy_setopt(connectionHandle, CURLOPT_USERPWD, NULL);              
+       }
+       
+}
+
+void CalDAV::SetupDefaultParametersSSL(bool doAuthentication){
+       
+       // Setup the default parameters.
+       
+       string ServerAddressURL = "https://" + connectionData.hostname + ":" + to_string(connectionData.port) + "/";
+       string UsernamePassword = connectionData.username + ":" + connectionData.password;
+       
+       curl_easy_setopt(connectionHandle, CURLOPT_URL, ServerAddressURL.c_str());
+       curl_easy_setopt(connectionHandle, CURLOPT_NOPROGRESS, 1L);
+       curl_easy_setopt(connectionHandle, CURLOPT_CERTINFO, 1L);
+       curl_easy_setopt(connectionHandle, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST|CURLAUTH_BASIC);
+       curl_easy_setopt(connectionHandle, CURLOPT_TIMEOUT, 60);
+       curl_easy_setopt(connectionHandle, CURLOPT_FAILONERROR, 0L);
+       curl_easy_setopt(connectionHandle, CURLOPT_USERAGENT, XSDCAL_USERAGENT);
+       curl_easy_setopt(connectionHandle, CURLOPT_ERRORBUFFER, sessionErrorBuffer);
+       curl_easy_setopt(connectionHandle, CURLOPT_CUSTOMREQUEST, "GET");
+       curl_easy_setopt(connectionHandle, CURLOPT_HTTPHEADER, nullptr);
+       curl_easy_setopt(connectionHandle, CURLOPT_POSTFIELDS, nullptr);
+       curl_easy_setopt(connectionHandle, CURLOPT_POSTFIELDSIZE, 0L);
+
+       if (doAuthentication == true){
+               curl_easy_setopt(connectionHandle, CURLOPT_USERPWD, UsernamePassword.c_str());
+       } else {
+               curl_easy_setopt(connectionHandle, CURLOPT_USERPWD, NULL);              
+       }
+       
+       if (enableSSLBypass == true){
+               curl_easy_setopt(connectionHandle, CURLOPT_SSL_VERIFYHOST, 0L);
+               curl_easy_setopt(connectionHandle, CURLOPT_SSL_VERIFYPEER, 0L);
+               curl_easy_setopt(connectionHandle, CURLOPT_SSL_VERIFYSTATUS, 0L);
+       } else {
+               curl_easy_setopt(connectionHandle, CURLOPT_SSL_VERIFYHOST, 2L);
+               curl_easy_setopt(connectionHandle, CURLOPT_SSL_VERIFYPEER, 1L);
+               curl_easy_setopt(connectionHandle, CURLOPT_SSL_VERIFYSTATUS, 1L);
+       }
+       
+#if !defined(__APPLE__) || defined(__WIN32__)
+       
+       if (connectionData.account.size() > 0){
+               
+               // Check if the server certificate file exists.
+               
+               string certificateFilename = GetAccountDir(connectionData.account, true);
+               
+               if (wxFile::Exists(certificateFilename)){
+                       
+                       curl_easy_setopt(connectionHandle, CURLOPT_CAINFO, certificateFilename.c_str());
+                       
+               }
+               
+       }
+
+#endif
+       
+}
+
+void CalDAV::ResetResults(){
+       
+       sslStatus = false;
+       COSSLVerified SSLVerified = COSSL_NORESULT;
+       validResponse = false;
+       authPassed = false;
+       sslSelfSigned = false;
+       //taskCompleted = false;
+       errorMessage = "";
+       sessionErrorBuffer[0] = '\0';
+       //sessionResult = CURLE_OK;
+       serverData = "";
+       serverHeader = "";
+       /*if (headerList != nullptr){
+               curl_slist_free_all(headerList);
+               headerList = nullptr;
+       }*/
+       
+}
\ No newline at end of file
index 7ca237a..cd873d8 100644 (file)
@@ -22,6 +22,8 @@
 #include <curl/curl.h>
 #include <libxml/parser.h>
 #include <libxml/tree.h>
+#include <wx/tokenzr.h>
+#include <wx/file.h>
 #include <string>
 #include <iostream>
 #include <vector>
@@ -30,7 +32,9 @@
 #include "../../common/colour.h"
 #include "../../common/text.h"
 #include "../../common/uuid.h"
+#include "../../common/dirs.h"
 #include "../../common/sslcertstructs.h"
+#include "../../version.h"
 
 using namespace std;
 
@@ -41,7 +45,8 @@ enum CalDAVQueryResult {
        CALDAVQUERYRESULT_UNITTESTFAIL = -1,
        CALDAVQUERYRESULT_OK,
        CALDAVQUERYRESULT_NOTRUN,
-       CALDAVQUERYRESULT_SERVERERROR
+       CALDAVQUERYRESULT_SERVERERROR,
+       CALDAVQUERYRESULT_SSLFAILURE,
 };
 
 struct CalDAVCalendarList {
@@ -73,6 +78,7 @@ struct CalDAVConnectionData{
        string prefix = "";
        bool useSSL = true;
        int timeout = 60;
+       string account = "";
        
 };
 
@@ -155,22 +161,32 @@ class CalDAV{
                        Colour *calendarColour,
                        string *calendarDescription,
                        int *calendarOrder);
+               string BuildServerAddress(CalDAVConnectionData *connData, string uriAddress);
+               void SetupDefaultParametersNonSSL(bool doAuthentication);
+               void SetupDefaultParametersSSL(bool doAuthentication);
+               void ResetResults();
        
                CalDAVConnectionData connectionData;
                CalDAVServerResult connectionServerResult;
                CURL *connectionHandle = nullptr;
+               char sessionErrorBuffer[CURL_ERROR_SIZE];
                string serverData = "";
                string serverHeader = "";
        
-               COSSLVerified SSLVerified;
-               bool EnableSSLBypass = false;
-               bool SSLSelfSigned = false;
+               COSSLVerified sslVerified;
+               bool enableSSLBypass = false;
+               bool sslSelfSigned = false;
+               bool sslStatus = false;
+               
+               bool validResponse = false;
+               bool authPassed = false;
+               string errorMessage = "";
        public:
                CalDAV();
                ~CalDAV();
                void SetupConnectionData(CalDAVConnectionData *connData);
                CalDAVStatus GetConnectionData();
-               CalDAVServerResult Connect();
+               CalDAVServerResult Connect(bool doAuthentication);
                CalDAVServerResult GetServerResult();
                CalDAVServerSupport GetServerSupport();
                CalDAVCalendarList GetCalendars();
@@ -205,6 +221,12 @@ class CalDAV{
                
                CalDAVServerResult GetEntryETag(string *calendarEntryHREF, string *eTagValue);
 
+               bool CanDoSSL();
+               bool HasValidResponse();
+               bool AbleToLogin();
+               bool IsSelfSigned();
+               std::string GetErrorMessage();
+
                COSSLVerified SSLVerify();
                void BypassSSLVerification(bool EnableBypass);
                
@@ -226,6 +248,5 @@ class CalDAV{
 // CalDAVConnectionData struct.
 
 //bool CalDAVObjectValidSettings(CalDAVConnectionData *connData);
-//string BuildServerAddress(CalDAVConnectionData *connData, string uriAddress);
 
 #endif
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