Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Implemented EditContact and GetContact in CardDAV2
[xestiaab/.git] / source / actmgr / frmActivityMgr.cpp
index 27960b7..606b9f1 100644 (file)
@@ -45,6 +45,7 @@ DEFINE_EVENT_TYPE(ACTMGR_STOPTIMER);
 DEFINE_EVENT_TYPE(ACTMGR_STARTPROCESSTIMER);
 DEFINE_EVENT_TYPE(ACTMGR_STOPPROCESSTIMER);
 DEFINE_EVENT_TYPE(ACTMGR_UPDATESTATUSLABEL);
+DEFINE_EVENT_TYPE(ACTMGR_STARTANIMATIONTIMER);
 
 BEGIN_EVENT_TABLE(frmActivityMgr, wxWindow)
   EVT_COMMAND(wxID_ANY, ACTMGR_RESUMEPROC, frmActivityMgr::ResumeProcessing)
@@ -54,6 +55,7 @@ BEGIN_EVENT_TABLE(frmActivityMgr, wxWindow)
   EVT_COMMAND(wxID_ANY, ACTMGR_STARTPROCESSTIMER, frmActivityMgr::StartProcessTimer)
   EVT_COMMAND(wxID_ANY, ACTMGR_STOPPROCESSTIMER, frmActivityMgr::StopProcessTimer)
   EVT_COMMAND(wxID_ANY, ACTMGR_UPDATESTATUSLABEL, frmActivityMgr::UpdateStatusLabel)
+  EVT_COMMAND(wxID_ANY, ACTMGR_STARTANIMATIONTIMER, frmActivityMgr::StartAnimationTimer)
 END_EVENT_TABLE()
 
 frmActivityMgr::frmActivityMgr( wxWindow* parent )
@@ -194,6 +196,12 @@ void frmActivityMgr::ProcessTasksThread()
        
        }
        
+       if (ApplicationSleepMode == TRUE){
+               
+               return;
+               
+       }
+       
        std::map<int,int>::iterator TypeIter;
        std::map<int,wxString>::iterator StringIter;
        std::map<int,wxString>::iterator StringDataIter;
@@ -206,6 +214,7 @@ void frmActivityMgr::ProcessTasksThread()
        std::map<int,wxString>::iterator StringETagIter;
        std::map<int,wxString>::iterator StringETagOrigIter;
        std::map<int,CardDAV*>::iterator CardDAVIter;
+       std::map<int,ConnectionObject*>::iterator ConnObjectIter;
        std::map<int,ActivityMgrAccountSettings>::iterator AccountSettingsIter;
        std::map<int,long>::iterator LongIter;
        bool TasksFoundProc = FALSE;
@@ -220,7 +229,14 @@ void frmActivityMgr::ProcessTasksThread()
                        continue;
                }
                
+               wxCommandEvent StartAnimationEvent(ACTMGR_STARTANIMATIONTIMER);
+               
+               wxPostEvent(this, StartAnimationEvent);
+               
+               // Start the animation timer if it hasn't started.
+               
                CardDAVIter = ActivityListConn.find(iter->first);
+               ConnObjectIter = ActivityListConnObject.find(iter->first);
                TypeIter = ActivityListType.find(iter->first);
                StringETagIter = ActivityListETag.find(iter->first);
                StringETagOrigIter = ActivityListETagOriginal.find(iter->first);
@@ -315,24 +331,158 @@ void frmActivityMgr::ProcessTasksThread()
                                FullFilename = StringFullFilenameIter->second;
                                EditMode = ActivityListEditMode.find(iter->first)->second;
                                
-                               bool KeepUpdating = TRUE;
+                               bool KeepUpdating = true;
                                
-                               while(KeepUpdating == TRUE){
+                               while(KeepUpdating == true){
                                        
-                                       bool ExitLoop = FALSE;
+                                       COConnectResult ConnectResponse = ConnObjectIter->second->Connect(false);
                                        
-                                       while (ExitLoop == FALSE){
+                                       bool ExitLoop = false;
+                                       
+                                       while (ExitLoop == false){
                                                
-                                               ConnHandle.SetUploadMode(TRUE);
-                                               ConnHandle.SetupData(wxT("PUT"), StringURLIter->second, StringDataIter->second);
-                                               ConnHandle.SetEditMode(EditMode);
-                                               ConnHandle.ProcessData();
+                                               if (ConnObjectIter->second->SSLVerify() == COSSL_UNABLETOVERIFY){
+                                                       
+                                                       frmMainPtrGet->PauseAllTimers();
+                                                       
+#if defined(__APPLE__)
+#elif defined(__WIN32__)
+#else
+       
+                                                       bool UsingSSLBypass = false;
+                                                       int SSLResult = 0;
+                                                       
+                                                       // Connect again and fetch SSL certificate information.
+               
+                                                       ConnObjectIter->second->BypassSSLVerification(true);
+               
+                                                       COConnectResult ConnectionSSLResult = ConnObjectIter->second->Connect(false);
+
+                                                       ConnObjectIter->second->BypassSSLVerification(false);
+
+                                                       SSLInvalidCertNotifObjString SSLICNProcData;
+                                                       
+                                                       SSLCertCollectionString certcol = ConnObjectIter->second->BuildSSLCollection();
+                                                               
+                                                       bool *PauseMode = new bool;
+                                                       QRNotif qrn;
+                                                               
+                                                       *PauseMode = TRUE;
+                                                       qrn.QResponse = &SSLResult;
+                                                       qrn.PausePtr = PauseMode;
+                                                               
+                                                       SSLICNProcData.CertCollection = certcol;
+                                                       SSLICNProcData.QRNotifData = &qrn;
+                                                       SSLICNProcData.AccountName = AccountNameFriendly;
+                                                               
+                                                       wxCommandEvent event(INVALIDSSLCERTSTRING);
+                                                       event.SetClientData(&SSLICNProcData);
+                                                       wxPostEvent(frmMainPtrGet, event);
+                                                               
+                                                       while (*PauseMode == TRUE){
+                                                               //nanosleep(&n1, &n2);
+                                                               SleepFor(250000000);
+                                                       }
+                                                       
+                                                       // Process the response from the user.
+                                                       
+                                                       if (SSLResult == 1){
+                                                               
+                                                               // Accept the Certificate.
+
+                                                               UsingSSLBypass = true;
+                                                               ConnObjectIter->second->BypassSSLVerification(true);
+               
+                                                               COConnectResult TestConnectionResult = ConnObjectIter->second->Connect(true);
+                                                               WriteServerCertificate(AccountDir, certcol);
+                                                               
+                                                               ConnObjectIter->second->BypassSSLVerification(false);
+                                                               
+                                                       } else if (SSLResult == 2){
+                                               
+                                                               // Reject the certificate, abort the task and mark as failed.
+
+                                                               iter->second = 2;
+                                                               break;
+                                                               
+                                                       }
+               
+#endif
+                                                       
+                                                       frmMainPtrGet->ResumeAllTimers();
+                                                       ExitLoop = true;
+                                                       
+                                               } else if (ConnectResponse == COCONNECT_AUTHFAIL){
+                                                       
+                                                       ConnectResponse = ConnObjectIter->second->Connect(true);
+                                                       
+                                                       if (ConnectResponse == COCONNECT_OK){
+                                                               
+                                                               ExitLoop = true;
+                                                               break;
+                                                               
+                                                       } else {
+                                                               
+                                                               ExitLoop = true;                                                        
+                                                               iter->second = 2;
+                                                               break;
+                                                               
+                                                       }
+                                                       
+                                               } else if (ConnectResponse == COCONNECT_OK){
+                                                       
+                                                       ConnectResponse = ConnObjectIter->second->Connect(true);
+                                                       
+                                                       ExitLoop = true;
+                                                       break;
+                                                       
+                                               } else {
+                                                       
+                                                       ExitLoop = true;                                                        
+                                                       iter->second = 2;
+                                                       break;
+                                                       
+                                               }
+                                               
+                                       }
+                                       
+                                       if (iter->second == 2 || iter->second == 3 || iter->second == 4){
+                                               break;
+                                       }
+                                       
+#if defined(__APPLE__)
+                                       
+                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
+
+#elif defined(__WIN32__)
+
+                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer());
+
+#else
+                                       
+                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData());
+                                       
+#endif
+                                       
+                                       COServerResponse AddContactResponse = ConnObjectIter->second->AddContact(StringURLIter->second.ToStdString(), 
+                                                       StringDataIter->second.ToStdString());
+                                       
+                                       if (AddContactResponse.RequestResult != COREQUEST_OK){
+                                               iter->second = 2;
+                                               break;
+                                       }
+                                       
+                                       /*while (ExitLoop == FALSE){
                                                
-                                               int ErrorCode = ConnHandle.GetResultCode();
+                                               // Verify that we have a trusted SSL connection first.
                                                
-                                               if (ErrorCode != 0){
+                                               int ErrorCode = ConnHandle.SSLVerifyTest();
+
+                                               if (ErrorCode != CURLE_OK){
                                                        
-                                                       if (ErrorCode == 60 || ErrorCode == 51){
+                                                       if (ErrorCode == CURLE_SSL_CACERT ||
+                                                               ErrorCode == CURLE_PEER_FAILED_VERIFICATION ||
+                                                               ErrorCode == CURLE_SSL_CONNECT_ERROR){
                                                                
                                                                // Invalid SSL certificate so bring up a dialog to the user
                                                                // explaining what has happened and the options available.
@@ -361,14 +511,37 @@ void frmActivityMgr::ProcessTasksThread()
                                                                        
                                                                        frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
                                                                        
+
+                                                               }
+
+#elif defined(__WIN32__)
+
+                                                               BOOL ModifiedCertificateData;
+                                                               CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(&ConnHandle, (HWND)frmMainPtrGet->GetHandle());
+
+                                                               if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)){
+                                                                       wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog"));
+                                                               }
+
+                                                               if (ModifiedCertificateData == FALSE){
+
+                                                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetCertificateContextPointer());
+                                                                       iter->second = 2;
+                                                                       break;
+
+                                                               } else {
+
+                                                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer());
+
                                                                }
+
 #else
                                                                
                                                                // Setup the data to be sent in the wxPostEvent command.
                                                                
                                                                SSLInvalidCertNotifObj SSLICNProcData;
                                                                
-                                                               SSLCertCollection certcol = ConnHandle.GetCertificateData();
+                                                               SSLCertCollection certcol = ConnHandle.GetSSLVerifyResults();
                                                                
                                                                bool *PauseMode = new bool;
                                                                QRNotif qrn;
@@ -385,13 +558,6 @@ void frmActivityMgr::ProcessTasksThread()
                                                                event.SetClientData(&SSLICNProcData);
                                                                wxPostEvent(frmMainPtrGet, event);
                                                                
-                                                               /*timespec n1, n2;
-                                                                
-                                                                       // Fall asleep until we get an response.
-                                                                
-                                                                       n1.tv_sec = 0;
-                                                                       n1.tv_nsec = 250000000L;*/
-                                                               
                                                                while (*PauseMode == TRUE){
                                                                        //nanosleep(&n1, &n2);
                                                                        SleepFor(250000000);
@@ -446,21 +612,48 @@ void frmActivityMgr::ProcessTasksThread()
 #if defined(__APPLE__)
                                        
                                        frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
-                                       
+
+#elif defined(__WIN32__)
+
+                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer());
+
 #else
                                        
                                        frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData());
                                        
 #endif
                                        
+                                       ConnHandle.SetUploadMode(TRUE);
+                                       ConnHandle.SetupData(wxT("PUT"), StringURLIter->second, StringDataIter->second);
+                                       ConnHandle.SetEditMode(EditMode);
+                                       ConnHandle.ProcessData();
+
+                                       int ErrorCode = ConnHandle.GetResultCode();
+
+                                       if (ErrorCode != CURLE_OK){
+
+                                               iter->second = 4;
+                                               break;
+
+                                       }
+
                                        // Add contact to the ETag DB.
                                        
                                        ConnHandle.GetServerETagValueThread();
-                                       ETagServer = ConnHandle.ETagValueResult();
-                                       ETagDBPtr->AddETag(ContactFilename, ETagServer, ETagServer);
+                                       ETagServer = ConnHandle.ETagValueResult();*/                                    
+                                       
+                                       // TODO: Get the entity tag for the new contact.
+                                       
+                                       COServerResponse ETagGetResponse = ConnObjectIter->second->GetServerEntityTagValue(StringURLIter->second.ToStdString());
+                                       
+                                       if (ETagGetResponse.RequestResult != COREQUEST_OK){
+                                               iter->second = 2;
+                                               break;
+                                       }
+                                       
+                                       ETagDBPtr->AddETag(ContactFilename, ETagGetResponse.EntityTag, ETagGetResponse.EntityTag);
                                        
                                        iter->second = 4;
-                                       CardDAVIter->second = NULL;
                                        break;
                                        
                                }
@@ -503,25 +696,248 @@ void frmActivityMgr::ProcessTasksThread()
                                FullFilename = StringFullFilenameIter->second;
                                EditMode = ActivityListEditMode.find(iter->first)->second;
                                
-                               bool KeepUpdating = TRUE;
+                               bool KeepUpdating = true;
                                
-                               while(KeepUpdating == TRUE){
+                               while(KeepUpdating == true){
                                        
-                                       bool ExitLoop = FALSE;
+                                       COConnectResult ConnectResponse = ConnObjectIter->second->Connect(false);
                                        
-                                       while (ExitLoop == FALSE){
+                                       bool ExitLoop = false;
+                                       
+                                       while(ExitLoop == false){
+                                               
+                                               if (ConnObjectIter->second->SSLVerify() == COSSL_UNABLETOVERIFY){
+                                                       
+                                                       frmMainPtrGet->PauseAllTimers();
+                                                       
+#if defined(__APPLE__)
+#elif defined(__WIN32__)
+#else
+       
+                                                       bool UsingSSLBypass = false;
+                                                       int SSLResult = 0;
+                                                       
+                                                       // Connect again and fetch SSL certificate information.
+               
+                                                       ConnObjectIter->second->BypassSSLVerification(true);
+               
+                                                       COConnectResult ConnectionSSLResult = ConnObjectIter->second->Connect(false);
+
+                                                       ConnObjectIter->second->BypassSSLVerification(false);
+
+                                                       SSLInvalidCertNotifObjString SSLICNProcData;
+                                                       
+                                                       SSLCertCollectionString certcol = ConnObjectIter->second->BuildSSLCollection();
+                                                               
+                                                       bool *PauseMode = new bool;
+                                                       QRNotif qrn;
+                                                               
+                                                       *PauseMode = TRUE;
+                                                       qrn.QResponse = &SSLResult;
+                                                       qrn.PausePtr = PauseMode;
+                                                               
+                                                       SSLICNProcData.CertCollection = certcol;
+                                                       SSLICNProcData.QRNotifData = &qrn;
+                                                       SSLICNProcData.AccountName = AccountNameFriendly;
+                                                               
+                                                       wxCommandEvent event(INVALIDSSLCERTSTRING);
+                                                       event.SetClientData(&SSLICNProcData);
+                                                       wxPostEvent(frmMainPtrGet, event);
+                                                               
+                                                       while (*PauseMode == TRUE){
+                                                               //nanosleep(&n1, &n2);
+                                                               SleepFor(250000000);
+                                                       }
+                                                       
+                                                       // Process the response from the user.
+                                                       
+                                                       if (SSLResult == 1){
+                                                               
+                                                               // Accept the Certificate.
+
+                                                               UsingSSLBypass = true;
+                                                               ConnObjectIter->second->BypassSSLVerification(true);
+               
+                                                               COConnectResult TestConnectionResult = ConnObjectIter->second->Connect(true);
+                                                               WriteServerCertificate(AccountDir, certcol);
+                                                               
+                                                               ConnObjectIter->second->BypassSSLVerification(false);
+                                                               
+                                                       } else if (SSLResult == 2){
+                                               
+                                                               // Reject the certificate, abort the task and mark as failed.
+
+                                                               iter->second = 2;
+                                                               break;
+                                                               
+                                                       }
+               
+#endif
+                                                       
+                                                       frmMainPtrGet->ResumeAllTimers();
+                                                       ExitLoop = true;
+                                                       
+                                               } else if (ConnectResponse == COCONNECT_AUTHFAIL){
+                                                       
+                                                       ConnectResponse = ConnObjectIter->second->Connect(true);
+                                                       
+                                                       if (ConnectResponse == COCONNECT_OK){
+                                                               
+                                                               ExitLoop = true;
+                                                               break;
+                                                               
+                                                       } else {
+                                                               
+                                                               ExitLoop = true;                                                        
+                                                               iter->second = 2;
+                                                               break;
+                                                               
+                                                       }
+                                                       
+                                               } else if (ConnectResponse == COCONNECT_OK){
+                                                       
+                                                       ConnectResponse = ConnObjectIter->second->Connect(true);
+                                                       
+                                                       ExitLoop = true;
+                                                       break;
+                                                       
+                                               } else {
+                                                       
+                                                       ExitLoop = true;                                                        
+                                                       iter->second = 2;
+                                                       break;
+                                                       
+                                               }
+                                               
+                                       }
+                                       
+                                       if (iter->second == 2 || iter->second == 3 || iter->second == 4){
+                                               break;
+                                       }
+                                       
+                                       COServerResponse ETagGetResponse = ConnObjectIter->second->GetServerEntityTagValue(StringURLIter->second.ToStdString());
+                                       
+                                       if (ETagGetResponse.RequestResult != COREQUEST_OK){
+                                               iter->second = 2;
+                                               break;
+                                       }
+                                       
+                                       ETagServer = ETagGetResponse.EntityTag;
+                                       
+                                       // Compare the ETag with the Server ETag.
+                                       
+                                       std::cout << ETagOriginal << std::endl;
+                                       std::cout << ETagServer << std::endl;
+                                       
+                                       if (ETagOriginal != ETagServer){
+                                               
+                                               // Server ETag is different from original ETag.
+                                               // This is a conflict which the user will now
+                                               // need to resolve.
+                                               
+                                               frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
+                                               
+                                               vCard34Conv vCard34Obj;
+                                               
+                                               std::string ServerContactData;
+                                               wxString wxStringServerContactData;
+                                               vCard ClientData;
+                                               vCard ConvertedV4Data;
+                                               
+                                               // Load the client data from the filename given.
+                                               
+                                               //ConnHandle.GetServerContactData();
+                                               //ServerContactData = ConnHandle.GetPageData();
+                                               
+                                               COServerResponse GetContactResponse = ConnObjectIter->second->GetContact(StringURLIter->second.ToStdString(),
+                                                       &ServerContactData);
+                                               
+                                               if (GetContactResponse.RequestResult != COREQUEST_OK){
+                                                       iter->second = 2;
+                                                       break;
+                                               }
+                                               
+                                               wxStringServerContactData = wxString::FromUTF8((const char*)ServerContactData.c_str());
+                                               
+                                               // Process v3 version into v4 version.
+                                               
+                                               vCard34Obj.ConvertToV4(&wxStringServerContactData, &ConvertedV4Data);
+                                               
+                                               vCardConflictObj vCardProcData;
+                                               
+                                               vCardProcData.vCardLocalData = &ClientData;
+                                               vCardProcData.vCardServerData = &ConvertedV4Data;
+                                               ClientData.LoadFile(FullFilename);
+                                               
+                                               // Setup Conflict Resolution Dialog.
+                                               
+                                               // Fetch Data from Server and convert.
+                                               
+                                               bool *PauseMode = new bool;
+                                               int ConflictResult;
+                                               QRNotif qrn;
+                                               
+                                               *PauseMode = TRUE;
+                                               qrn.QResponse = &ConflictResult;
+                                               qrn.PausePtr = PauseMode;
+                                               
+                                               vCardProcData.QRNotifData = &qrn;
+                                               
+                                               wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
+                                               event.SetClientData(&vCardProcData);
+                                               wxPostEvent(frmMainPtrGet, event);
+                                               
+                                               while (*PauseMode == TRUE){
+                                                       SleepFor(250000000);
+                                               }
+                                               
+                                               delete PauseMode;
+                                               PauseMode = NULL;
+                                               
+                                               if (ConflictResult == 0){
+                                                       
+                                                       // Decide Later.
+                                                       
+                                                       iter->second = 4;
+                                                       break;
+                                                       
+                                               } else if (ConflictResult == 1){
+                                                       
+                                                       // Decided to use client version.
+                                                       
+                                               } else if (ConflictResult == 2){
+                                                       
+                                                       // Decided to use server version.
+                                                       
+                                                       // Download server version.
+                                                       
+                                                       ConvertedV4Data.WriteFile(FullFilename);
+                                                       
+                                               }
                                                
-                                               ConnHandle.SetUploadMode(TRUE);
-                                               ConnHandle.SetupData(wxT("PUT"), StringURLIter->second, StringDataIter->second);
-                                               ConnHandle.SetEditMode(EditMode);
-                                               ConnHandle.GetServerETagValueThread();
-                                               ETagServer = ConnHandle.ETagValueResult();
+                                       } else {
                                                
-                                               int ErrorCode = ConnHandle.GetResultCode();
+                                               // Upload the data to the server.
                                                
-                                               if (ErrorCode != 0){
+                                               COServerResponse EditContactResponse = ConnObjectIter->second->EditContact(StringURLIter->second.ToStdString(), 
+                                                       StringDataIter->second.ToStdString());
+                                       
+                                               if (EditContactResponse.RequestResult != COREQUEST_OK){
+                                                       iter->second = 2;
+                                                       break;
+                                               }
+                                               
+                                       }
+                                       
+                                       /*while (ExitLoop == FALSE){
+                                                
+                                               int ErrorCode = ConnHandle.SSLVerifyTest();
+                                               
+                                               if (ErrorCode != CURLE_OK){
                                                        
-                                                       if (ErrorCode == 60 || ErrorCode == 51){
+                                                       if (ErrorCode == CURLE_SSL_CACERT ||
+                                                               ErrorCode == CURLE_PEER_FAILED_VERIFICATION ||
+                                                               ErrorCode == CURLE_SSL_CONNECT_ERROR){
                                                                
                                                                // Invalid SSL certificate so bring up a dialog to the user
                                                                // explaining what has happened and the options available.
@@ -551,13 +967,35 @@ void frmActivityMgr::ProcessTasksThread()
                                                                        frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
                                                                        
                                                                }
+
+#elif defined(__WIN32__)
+
+                                                               BOOL ModifiedCertificateData;
+                                                               CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(&ConnHandle, (HWND)frmMainPtrGet->GetHandle());
+
+                                                               if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)){
+                                                                       wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog"));
+                                                               }
+
+                                                               if (ModifiedCertificateData == FALSE){
+
+                                                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetCertificateContextPointer());
+                                                                       iter->second = 2;
+                                                                       break;
+
+                                                               } else {
+
+                                                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer());
+
+                                                               }
+
 #else
                                                                
                                                                // Setup the data to be sent in the wxPostEvent command.
                                                                
                                                                SSLInvalidCertNotifObj SSLICNProcData;
                                                                
-                                                               SSLCertCollection certcol = ConnHandle.GetCertificateData();
+                                                               SSLCertCollection certcol = ConnHandle.GetSSLVerifyResults();
                                                                
                                                                bool *PauseMode = new bool;
                                                                QRNotif qrn;
@@ -586,14 +1024,14 @@ void frmActivityMgr::ProcessTasksThread()
                                                                        // Accept the certificate. Write the certificate into the account
                                                                        // directory (as server.crt) - will overwrite old certificate.
                                                                        
-                                                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData());
-                                                                       WriteServerCertificate(AccountDir, ConnHandle.GetCertificateData());
+                                                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetSSLVerifyResults());
+                                                                       WriteServerCertificate(AccountDir, ConnHandle.GetSSLVerifyResults());
                                                                        
                                                                } else if (SSLResult == 2){
                                                                        
                                                                        // Reject the certificate, abort the task and mark as failed.
                                                                        
-                                                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetCertificateData());
+                                                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetSSLVerifyResults());
                                                                        iter->second = 2;
                                                                        break;
                                                                        
@@ -628,13 +1066,30 @@ void frmActivityMgr::ProcessTasksThread()
 #if defined(__APPLE__)
                                        
                                        frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
-                                       
+
+#elif defined(__WIN32__)
+
+                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer());
+
 #else
                                        
-                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData());
+                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetSSLVerifyResults());
                                        
 #endif
                                        
+                                       ConnHandle.SetUploadMode(TRUE);
+                                       ConnHandle.SetupData(wxT("PUT"), StringURLIter->second, StringDataIter->second);
+                                       ConnHandle.SetEditMode(EditMode);
+                                       ConnHandle.GetServerETagValueThread();
+                                       ETagServer = ConnHandle.ETagValueResult();
+
+                                       int ErrorCode = ConnHandle.GetResultCode();
+
+                                       if (ErrorCode != CURLE_OK){
+                                               iter->second = 2;
+                                               break;
+                                       }
+
                                        // Compare the ETag with the Server ETag.
                                        
                                        if (ETagOriginal != ETagServer){
@@ -713,7 +1168,7 @@ void frmActivityMgr::ProcessTasksThread()
                                                        
                                                        // Decided to use client version.
                                                        
-                                                       ConnHandle.ProcessData();
+                                                       //ConnHandle.ProcessData();
                                                        
                                                } else if (ConflictResult == 2){
                                                        
@@ -731,13 +1186,24 @@ void frmActivityMgr::ProcessTasksThread()
                                                
                                                ConnHandle.ProcessData();
                                                
-                                       }
+                                       }*/
                                        
                                        // Update the ETag DB.
                                        
-                                       ConnHandle.GetServerETagValueThread();
-                                       ETagServer = ConnHandle.ETagValueResult();
-                                       ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
+                                       //ConnHandle.GetServerETagValueThread();
+                                       //ETagServer = ConnHandle.ETagValueResult();
+                                       
+                                       ETagGetResponse = ConnObjectIter->second->GetServerEntityTagValue(StringURLIter->second.ToStdString());
+                                       
+                                       if (ETagGetResponse.RequestResult != COREQUEST_OK){
+                                               iter->second = 2;
+                                               break;
+                                       }
+                                       
+                                       std::cout << "Etag Update!" << std::endl;
+                                       std::cout << ETagGetResponse.EntityTag << std::endl;
+                                       
+                                       ETagDBPtr->UpdateETag(ContactFilename, ETagGetResponse.EntityTag, ETagGetResponse.EntityTag);
                                        
                                        iter->second = 4;
                                        break;
@@ -780,18 +1246,13 @@ void frmActivityMgr::ProcessTasksThread()
                                        
                                        while (ExitLoop == FALSE){
                                                
-                                               ConnHandle.SetUploadMode(FALSE);
-                                               ConnHandle.SetupData(wxT("DELETE"), ContactFilename, wxT(""));
-                                               ConnHandle.ProcessData();
-                                               SSLCertCollection certcol = ConnHandle.GetCertificateData();
-                                               
-                                               // Check if any errors have occured whilst getting the data.
-                                               
-                                               int ErrorCode = ConnHandle.GetResultCode();
-                                               
-                                               if (ErrorCode != 0){
+                                               int ErrorCode = ConnHandle.SSLVerifyTest();
+
+                                               if (ErrorCode != CURLE_OK){
                                                        
-                                                       if (ErrorCode == 60 || ErrorCode == 51){
+                                                       if (ErrorCode == CURLE_SSL_CACERT ||
+                                                               ErrorCode == CURLE_PEER_FAILED_VERIFICATION ||
+                                                               ErrorCode == CURLE_SSL_CONNECT_ERROR){
                                                                
                                                                // Invalid SSL certificate so bring up a dialog to the user
                                                                // explaining what has happened and the options available.
@@ -821,12 +1282,36 @@ void frmActivityMgr::ProcessTasksThread()
                                                                        frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
                                                                        
                                                                }
+
+#elif defined(__WIN32__)
+
+                                                               BOOL ModifiedCertificateData;
+                                                               CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(&ConnHandle, (HWND)frmMainPtrGet->GetHandle());
+
+                                                               if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)){
+                                                                       wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog"));
+                                                               }
+
+                                                               if (ModifiedCertificateData == FALSE){
+
+                                                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetCertificateContextPointer());
+                                                                       iter->second = 2;
+                                                                       break;
+
+                                                               } else {
+
+                                                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer());
+
+                                                               }
+
 #else
                                                                
                                                                // Setup the data to be sent in the wxPostEvent command.
                                                                
                                                                SSLInvalidCertNotifObj SSLICNProcData;
                                                                
+                                                               SSLCertCollection certcol = ConnHandle.GetSSLVerifyResults();
+                                                               
                                                                bool *PauseMode = new bool;
                                                                QRNotif qrn;
                                                                
@@ -861,14 +1346,14 @@ void frmActivityMgr::ProcessTasksThread()
                                                                        // Accept the certificate. Write the certificate into the account
                                                                        // directory (as server.crt) - will overwrite old certificate.
                                                                
-                                                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData());
-                                                                       WriteServerCertificate(AccountDir, ConnHandle.GetCertificateData());
+                                                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetSSLVerifyResults());
+                                                                       WriteServerCertificate(AccountDir, ConnHandle.GetSSLVerifyResults());
                                                                
                                                                } else if (SSLResult == 2){
                                                                
                                                                // Reject the certificate, abort the task and mark as failed.
                                                                
-                                                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetCertificateData());
+                                                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetSSLVerifyResults());
                                                                        iter->second = 2;
                                                                        break;
                                                                
@@ -903,13 +1388,31 @@ void frmActivityMgr::ProcessTasksThread()
 #if defined(__APPLE__)
                                
                                        frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
-                               
+
+#elif defined(__WIN32__)
+
+                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer());
+
 #else
                                
-                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData());
+                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetSSLVerifyResults());
                                
 #endif
 
+                                       ConnHandle.SetUploadMode(FALSE);
+                                       ConnHandle.SetupData(wxT("DELETE"), ContactFilename, wxT(""));
+                                       ConnHandle.ProcessData();
+                                       
+                                       SSLCertCollection certcol = ConnHandle.GetCertificateData();
+
+                                       // Check if any errors have occured whilst getting the data.
+
+                                       int ErrorCode = ConnHandle.GetResultCode();
+
+                                       if (ErrorCode != CURLE_OK){
+                                               iter->second = 2;
+                                               break;
+                                       }
                                
                                        ETagDBPtr->RemoveETag(ContactFilename);
                                
@@ -1062,12 +1565,25 @@ void frmActivityMgr::ProcessTasksThread()
                                                                        wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog"));
                                                                }
 
+                                                               if (ModifiedCertificateData == FALSE){
+
+                                                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetCertificateContextPointer());
+                                                                       iter->second = 2;
+                                                                       break;
+
+                                                               } else {
+
+                                                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer());
+
+                                                               }
 #else
                                 
                                                                // Setup the data to be sent in the wxPostEvent command.
 
                                                                SSLInvalidCertNotifObj SSLICNProcData;
 
+                                                               SSLCertCollection certcol = ConnHandle.GetSSLVerifyResults();
+
                                                                bool *PauseMode = new bool;
                                                                QRNotif qrn;
 
@@ -1102,14 +1618,14 @@ void frmActivityMgr::ProcessTasksThread()
                                                                        // Accept the certificate. Write the certificate into the account
                                                                        // directory (as server.crt) - will overwrite old certificate.
 
-                                                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData());
-                                                                       WriteServerCertificate(AccountDir, ConnHandle.GetCertificateData());
+                                                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetSSLVerifyResults());
+                                                                       WriteServerCertificate(AccountDir, ConnHandle.GetSSLVerifyResults());
                                                                
                                                                } else if (SSLResult == 2){
                                                                
                                                                        // Reject the certificate, abort the task and mark as failed.
 
-                                                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetCertificateData());
+                                                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetSSLVerifyResults());
                                                                        iter->second = 2;
                                                                        break;
                                                                
@@ -1144,10 +1660,14 @@ void frmActivityMgr::ProcessTasksThread()
 #if defined(__APPLE__)
                                         
                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
-                                        
+
+#elif defined(__WIN32__)
+
+                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer());
+
 #else
                                         
-                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData());
+                                       frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetSSLVerifyResults());
                        
 #endif
                                         
@@ -1165,6 +1685,16 @@ void frmActivityMgr::ProcessTasksThread()
                                        bool ContinueProcess = AccDir.GetFirst(&AccDirFilename, wxEmptyString, wxDIR_DEFAULT);
                                
                                        ServerContactList = ConnHandle.GetContactList(SyncTokenLoad.ToUTF8());
+
+                                       int ErrorCode = ConnHandle.GetResultCode();
+
+                                       if (ErrorCode != CURLE_OK){
+
+                                               iter->second = 4;
+                                               break;
+
+                                       }
+
                                        SSLCertCollection certcol = ConnHandle.GetCertificateData();
 
                                        // Create a pointer for the std::map<wxString,FileSyncData>.
@@ -1922,12 +2452,12 @@ void frmActivityMgr::ProcessTasksThread()
 
                        while (iter->second == 1){
 
-                               SleepFor(250000000);
+                               SleepFor(125000000);
                                //nanosleep(&n1, &n2);
        
                        }
                        
-                       if ((iter->second == 4 && TypeIter->second == 0) || 
+                       /*if ((iter->second == 4 && TypeIter->second == 0) || 
                        (iter->second == 8 && TypeIter->second == 0)){
 
                                AccountDir = StringAccountIter->second;
@@ -1949,7 +2479,7 @@ void frmActivityMgr::ProcessTasksThread()
                                ETagServer = ConnHandle.ETagValueResult();
                                ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
                        
-                       }
+                       }*/
                        
                        break;
                        
@@ -1971,7 +2501,7 @@ void frmActivityMgr::ProcessTasksThread()
                //ActListProcTimer.Start();
        
        }
-
+       
        wxCommandEvent event(ACTMGR_STARTPROCESSTIMER);
        wxPostEvent(this, event);
 
@@ -1981,7 +2511,7 @@ void frmActivityMgr::ProcessTasksThread()
 
 void frmActivityMgr::ProcessTasks()
 {
-
+       
        std::thread ProcessThread(&frmActivityMgr::ProcessTasksThread, this);
        ProcessThread.detach();
 
@@ -2012,15 +2542,23 @@ void frmActivityMgr::ToggleConnectionStatus( wxCommandEvent &event ){
 
        wxCommandEvent connevent(CONNSTAT_UPDATE);
        
-       if (SleepMode == FALSE){
+       if (ApplicationSleepMode == FALSE){
        
                connevent.SetInt(1);
-               SleepMode = TRUE;
+               ApplicationSleepMode = TRUE;
+               mnuSleepMode->Check(true);
        
        } else {
        
                connevent.SetInt(0);
-               SleepMode = FALSE;
+               ApplicationSleepMode = FALSE;
+               mnuSleepMode->Check(false);
+               
+               wxCommandEvent event(ACTMGR_STARTTIMER);
+               wxPostEvent(this, event);
+
+               wxCommandEvent eventp(ACTMGR_STARTPROCESSTIMER);
+               wxPostEvent(this, eventp);
        
        }
 
@@ -2028,6 +2566,14 @@ void frmActivityMgr::ToggleConnectionStatus( wxCommandEvent &event ){
 
 }
 
+void frmActivityMgr::SleepMode( wxCommandEvent &event ){
+       
+       wxCommandEvent connevent(ACTMGR_TOGGLECONN);
+       
+       wxPostEvent(this, connevent);
+       
+}
+
 void frmActivityMgr::WriteServerCertificate(wxString AccountName, SSLCertCollection SSLCertInc){
 
        wxString ServerCertFinal;
@@ -2048,6 +2594,26 @@ void frmActivityMgr::WriteServerCertificate(wxString AccountName, SSLCertCollect
 
 }
 
+void frmActivityMgr::WriteServerCertificate(wxString AccountName, SSLCertCollectionString SSLCertInc){
+
+       wxString ServerCertFinal;
+
+       // Get the Cert section of the certificate and write it to the file.
+
+       ServerCertFinal = GetAccountDir(AccountName, TRUE);
+
+       wxFile CertFile;
+       
+       std::map<int, SSLCertDataString>::iterator SSLCDIter = SSLCertInc.SSLCollection.find(0);
+       std::multimap<string,string>::iterator SSLDataIter = SSLCDIter->second.CertData.find("Cert");
+       
+       CertFile.Open(ServerCertFinal, wxFile::write);  
+       
+       CertFile.Write(SSLDataIter->second, wxConvUTF8);
+       CertFile.Close();
+
+}
+
 void frmActivityMgr::StartTimer(wxCommandEvent& event){
 
        ActListProcTimer.Start(1000, FALSE);
@@ -2072,6 +2638,12 @@ void frmActivityMgr::StopProcessTimer(wxCommandEvent& event){
 
 }
 
+void frmActivityMgr::StartAnimationTimer(wxCommandEvent& event){
+       
+       AnimationTimer.StartAnimation();
+       
+}
+
 void frmActivityMgr::UpdateStatusLabel(wxCommandEvent& event){
 
        ActivityMgrLabelUpdate *actmgrudata = (ActivityMgrLabelUpdate*)event.GetClientData();
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