X-Git-Url: http://Server1/repobrowser/?p=xestiaab%2F.git;a=blobdiff_plain;f=source%2Factmgr%2FfrmActivityMgr.cpp;h=be5f40aa2eddd38fe7152c8d3c2100694364ddac;hp=63755f848029ea1bd4a13f74b17198219c93718c;hb=ccc379ac30775d5b73698b83875a35fc1bfa56d0;hpb=57b0514feb18c2ed89f5c6f4b49d6c6513cac9f1 diff --git a/source/actmgr/frmActivityMgr.cpp b/source/actmgr/frmActivityMgr.cpp index 63755f8..be5f40a 100644 --- a/source/actmgr/frmActivityMgr.cpp +++ b/source/actmgr/frmActivityMgr.cpp @@ -80,7 +80,7 @@ frmActivityMgrADT( parent ) ActListProcTimer.SetupPointers(&ActivityList, &ActivityListIndex, &ActivityListTaskDetail, &TasksActive, lstActivity, lblDetails, GauProgress, this, &AnimationTimer, - &ActProcessTimer, &ActivityListFinDate, &ActivityListConn); + &ActProcessTimer, &ActivityListFinDate, &ActivityListConnObject); AnimationTimer.SetBitmap(bmpActivity); AnimationTimer.SetSleepBitmap(&SleepBitmap); @@ -213,7 +213,7 @@ void frmActivityMgr::ProcessTasksThread() std::map::iterator StringTaskDetailIter; std::map::iterator StringETagIter; std::map::iterator StringETagOrigIter; - std::map::iterator CardDAVIter; + std::map::iterator ConnObjectIter; std::map::iterator AccountSettingsIter; std::map::iterator LongIter; bool TasksFoundProc = FALSE; @@ -234,7 +234,7 @@ void frmActivityMgr::ProcessTasksThread() // 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); @@ -245,18 +245,6 @@ void frmActivityMgr::ProcessTasksThread() // Setup the CardDAV object. - CardDAV ConnHandle; - - ConnHandle.SetupConnection(AccountSettingsIter->second.Address, - AccountSettingsIter->second.Port, - AccountSettingsIter->second.Username, - AccountSettingsIter->second.Password, - AccountSettingsIter->second.SSL, - AccountSettingsIter->second.Prefix, - AccountSettingsIter->second.Dir); - ConnHandle.SetupVariables(&ActivityList, iter->first); - ConnHandle.SetupResultBools(&BlankBool, &BlankBool); - // 0 = Queued. // 1 = Processing. // 2 = Failed. @@ -271,8 +259,6 @@ void frmActivityMgr::ProcessTasksThread() XABPreferences PrefData(GetUserPrefDir()); if (iter->second == 0){ - - //CardDAVIter->second. // Wait for process to finish. @@ -329,147 +315,163 @@ 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){ - - // Verify that we have a trusted SSL connection first. + bool ExitLoop = false; + + while (ExitLoop == false){ - int ErrorCode = ConnHandle.SSLVerifyTest(); - - if (ErrorCode != CURLE_OK){ + if (ConnObjectIter->second->SSLVerify() == COSSL_UNABLETOVERIFY){ + + frmMainPtrGet->PauseAllTimers(); - 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. - - // Stop all the timers. - - frmMainPtrGet->PauseAllTimers(); - - int SSLResult; - #if defined(__APPLE__) + + ConnObjectIter->second->BypassSSLVerification(true); + + COConnectResult ConnectionSSLResult = ConnObjectIter->second->Connect(false); + + ConnObjectIter->second->BypassSSLVerification(false); + + int SSLResult = DisplayTrustPanel(ConnObjectIter->second->BuildSSLCollection(), AccountNameFriendly); + + if (SSLResult != NSOKButton){ - // Bring up the trust panel and display the SSL certificate dialog. + frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnObjectIter->second->BuildSSLCollection()); + iter->second = 2; + break; - SSLResult = DisplayTrustPanel(ConnHandle.GetTrustObject(), AccountNameFriendly); + } else { - // Update the SSL account with the trust object. + frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection()); - if (SSLResult != NSOKButton){ - - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetTrustObject()); - iter->second = 2; - break; - - } else { - - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject()); - + } + +#elif defined(__WIN32__) - } + ConnObjectIter->second->BypassSSLVerification(true); -#elif defined(__WIN32__) + COConnectResult ConnectionSSLResult = ConnObjectIter->second->Connect(false); - BOOL ModifiedCertificateData; - CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(&ConnHandle, (HWND)frmMainPtrGet->GetHandle()); + ConnObjectIter->second->BypassSSLVerification(false); - if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)){ - wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog")); - } + BOOL ModifiedCertificateData = false; + CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(ConnObjectIter->second, (HWND)frmMainPtrGet->GetHandle()); - if (ModifiedCertificateData == FALSE){ + if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)) { + wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog")); + } - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetCertificateContextPointer()); - iter->second = 2; - break; + if (ModifiedCertificateData == false) { - } else { + frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnObjectIter->second->BuildSSLCollection()); + iter->second = 2; + break; - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer()); + } else { - } + frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection()); + + } #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(); - // Setup the data to be sent in the wxPostEvent command. - - SSLInvalidCertNotifObj SSLICNProcData; - - SSLCertCollection certcol = ConnHandle.GetSSLVerifyResults(); + bool *PauseMode = new bool; + QRNotif qrn; - bool *PauseMode = new bool; - QRNotif qrn; + *PauseMode = TRUE; + qrn.QResponse = &SSLResult; + qrn.PausePtr = PauseMode; - *PauseMode = TRUE; - qrn.QResponse = &SSLResult; - qrn.PausePtr = PauseMode; + SSLICNProcData.CertCollection = certcol; + SSLICNProcData.QRNotifData = &qrn; + SSLICNProcData.AccountName = AccountNameFriendly; - SSLICNProcData.CertCollection = certcol; - SSLICNProcData.QRNotifData = &qrn; - SSLICNProcData.AccountName = AccountNameFriendly; + wxCommandEvent event(INVALIDSSLCERTSTRING); + event.SetClientData(&SSLICNProcData); + wxPostEvent(frmMainPtrGet, event); - wxCommandEvent event(INVALIDSSLCERT); - 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); + } + + // Process the response from the user. + + if (SSLResult == 1){ - while (*PauseMode == TRUE){ - //nanosleep(&n1, &n2); - SleepFor(250000000); - } + // Accept the Certificate. + + UsingSSLBypass = true; + ConnObjectIter->second->BypassSSLVerification(true); + + COConnectResult TestConnectionResult = ConnObjectIter->second->Connect(true); + WriteServerCertificate(AccountDir, certcol); - // Process the response from the user. + ConnObjectIter->second->BypassSSLVerification(false); - if (SSLResult == 1){ - - // 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()); - - } else if (SSLResult == 2){ - - // Reject the certificate, abort the task and mark as failed. - - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetCertificateData()); - iter->second = 2; - break; - - } + } 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){ - // Resume all the timers. - - frmMainPtrGet->ResumeAllTimers(); - ExitLoop = TRUE; + 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; + ExitLoop = true; + iter->second = 2; + break; } @@ -481,37 +483,36 @@ void frmActivityMgr::ProcessTasksThread() #if defined(__APPLE__) - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject()); + frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection()); #elif defined(__WIN32__) - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer()); + frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection()); #else - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData()); + frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection()); #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; + COServerResponse AddContactResponse = ConnObjectIter->second->AddContact(StringURLIter->second.ToStdString(), + std::string(StringDataIter->second.ToUTF8())); + + if (AddContactResponse.RequestResult != COREQUEST_OK){ + iter->second = 2; break; - } - - // Add contact to the ETag DB. - ConnHandle.GetServerETagValueThread(); - ETagServer = ConnHandle.ETagValueResult(); - ETagDBPtr->AddETag(ContactFilename, ETagServer, ETagServer); + // 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->UpdateETag(ContactFilename, ETagGetResponse.EntityTag, ETagGetResponse.EntityTag); iter->second = 4; break; @@ -556,137 +557,162 @@ 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){ - - int ErrorCode = ConnHandle.SSLVerifyTest(); + bool ExitLoop = false; + + while(ExitLoop == false){ - if (ErrorCode != CURLE_OK){ + if (ConnObjectIter->second->SSLVerify() == COSSL_UNABLETOVERIFY){ + + frmMainPtrGet->PauseAllTimers(); - 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. - - // Stop all the timers. - - frmMainPtrGet->PauseAllTimers(); - - int SSLResult; - #if defined(__APPLE__) + + ConnObjectIter->second->BypassSSLVerification(true); + + COConnectResult ConnectionSSLResult = ConnObjectIter->second->Connect(false); + + ConnObjectIter->second->BypassSSLVerification(false); + + int SSLResult = DisplayTrustPanel(ConnObjectIter->second->BuildSSLCollection(), AccountNameFriendly); + + if (SSLResult != NSOKButton){ - // Bring up the trust panel and display the SSL certificate dialog. + frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnObjectIter->second->BuildSSLCollection()); + iter->second = 2; + break; - SSLResult = DisplayTrustPanel(ConnHandle.GetTrustObject(), AccountNameFriendly); + } else { - // Update the SSL account with the trust object. + frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection()); - if (SSLResult != NSOKButton){ - - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetTrustObject()); - iter->second = 2; - break; - - } else { - - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject()); - - } - + } + #elif defined(__WIN32__) - BOOL ModifiedCertificateData; - CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(&ConnHandle, (HWND)frmMainPtrGet->GetHandle()); + ConnObjectIter->second->BypassSSLVerification(true); - if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)){ - wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog")); - } + COConnectResult ConnectionSSLResult = ConnObjectIter->second->Connect(false); - if (ModifiedCertificateData == FALSE){ + ConnObjectIter->second->BypassSSLVerification(false); - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetCertificateContextPointer()); - iter->second = 2; - break; + BOOL ModifiedCertificateData = false; + CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(ConnObjectIter->second, (HWND)frmMainPtrGet->GetHandle()); - } else { + if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)) { + wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog")); + } - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer()); + if (ModifiedCertificateData == FALSE) { - } + frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnObjectIter->second->BuildSSLCollection()); + iter->second = 2; + break; + + } else { + + frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection()); + + } #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(); - // Setup the data to be sent in the wxPostEvent command. + bool *PauseMode = new bool; + QRNotif qrn; - SSLInvalidCertNotifObj SSLICNProcData; + *PauseMode = TRUE; + qrn.QResponse = &SSLResult; + qrn.PausePtr = PauseMode; - SSLCertCollection certcol = ConnHandle.GetSSLVerifyResults(); + SSLICNProcData.CertCollection = certcol; + SSLICNProcData.QRNotifData = &qrn; + SSLICNProcData.AccountName = AccountNameFriendly; - bool *PauseMode = new bool; - QRNotif qrn; + wxCommandEvent event(INVALIDSSLCERTSTRING); + event.SetClientData(&SSLICNProcData); + wxPostEvent(frmMainPtrGet, event); - *PauseMode = TRUE; - qrn.QResponse = &SSLResult; - qrn.PausePtr = PauseMode; - - SSLICNProcData.CertCollection = certcol; - SSLICNProcData.QRNotifData = &qrn; - SSLICNProcData.AccountName = AccountNameFriendly; - - wxCommandEvent event(INVALIDSSLCERT); - event.SetClientData(&SSLICNProcData); - wxPostEvent(frmMainPtrGet, event); + while (*PauseMode == TRUE){ + SleepFor(250000000); + } + + // Process the response from the user. + + if (SSLResult == 1){ - while (*PauseMode == TRUE){ - //nanosleep(&n1, &n2); - SleepFor(250000000); - } + // Accept the Certificate. + + UsingSSLBypass = true; + ConnObjectIter->second->BypassSSLVerification(true); + + COConnectResult TestConnectionResult = ConnObjectIter->second->Connect(true); + WriteServerCertificate(AccountDir, certcol); - // Process the response from the user. + ConnObjectIter->second->BypassSSLVerification(false); - if (SSLResult == 1){ - - // Accept the certificate. Write the certificate into the account - // directory (as server.crt) - will overwrite old certificate. - - 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.GetSSLVerifyResults()); - iter->second = 2; - break; - - } + } 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){ - // Resume all the timers. - - frmMainPtrGet->ResumeAllTimers(); - ExitLoop = TRUE; + 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; + ExitLoop = true; + iter->second = 2; + break; } @@ -696,33 +722,15 @@ void frmActivityMgr::ProcessTasksThread() 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.GetSSLVerifyResults()); + COServerResponse ETagGetResponse = ConnObjectIter->second->GetServerEntityTagValue(StringURLIter->second.ToStdString()); -#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){ + if (ETagGetResponse.RequestResult != COREQUEST_OK){ iter->second = 2; break; } - + + ETagServer = ETagGetResponse.EntityTag; + // Compare the ETag with the Server ETag. if (ETagOriginal != ETagServer){ @@ -731,25 +739,30 @@ void frmActivityMgr::ProcessTasksThread() // This is a conflict which the user will now // need to resolve. - vCard Moo1; - vCard Moo2; - frmMain *frmMainPtrGet = static_cast(frmMainPtr); vCard34Conv vCard34Obj; - wxString ServerContactData; + 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(&ServerContactData, &ConvertedV4Data); + vCard34Obj.ConvertToV4(&wxStringServerContactData, &ConvertedV4Data); vCardConflictObj vCardProcData; @@ -757,11 +770,6 @@ void frmActivityMgr::ProcessTasksThread() vCardProcData.vCardServerData = &ConvertedV4Data; ClientData.LoadFile(FullFilename); - //ContactConflictEvent event(ContactConflictCmdEnv); - //event.SetData(ContactFilename, Moo1, Moo2); - - //wxPostEvent(frmMainPtrGet, event); - // Setup Conflict Resolution Dialog. // Fetch Data from Server and convert. @@ -781,15 +789,12 @@ void frmActivityMgr::ProcessTasksThread() wxPostEvent(frmMainPtrGet, event); while (*PauseMode == TRUE){ - //nanosleep(&n1, &n2); SleepFor(250000000); } delete PauseMode; PauseMode = NULL; - //intResult = frmMainPtrGet->ShowConflictDialog(&Moo1, &Moo2); - if (ConflictResult == 0){ // Decide Later. @@ -801,8 +806,6 @@ void frmActivityMgr::ProcessTasksThread() // Decided to use client version. - ConnHandle.ProcessData(); - } else if (ConflictResult == 2){ // Decided to use server version. @@ -815,17 +818,26 @@ void frmActivityMgr::ProcessTasksThread() } else { - // Update the data to the server. + // Upload the data to the server. - ConnHandle.ProcessData(); + COServerResponse EditContactResponse = ConnObjectIter->second->EditContact(StringURLIter->second.ToStdString(), + std::string(StringDataIter->second.ToUTF8())); + + if (EditContactResponse.RequestResult != COREQUEST_OK){ + iter->second = 2; + break; + } } - // Update the ETag DB. + ETagGetResponse = ConnObjectIter->second->GetServerEntityTagValue(StringURLIter->second.ToStdString()); - ConnHandle.GetServerETagValueThread(); - ETagServer = ConnHandle.ETagValueResult(); - ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer); + if (ETagGetResponse.RequestResult != COREQUEST_OK){ + iter->second = 2; + break; + } + + ETagDBPtr->UpdateETag(ContactFilename, ETagGetResponse.EntityTag, ETagGetResponse.EntityTag); iter->second = 4; break; @@ -864,141 +876,160 @@ void frmActivityMgr::ProcessTasksThread() while(KeepUpdating == TRUE){ + COConnectResult ConnectResponse = ConnObjectIter->second->Connect(false); + bool ExitLoop = FALSE; while (ExitLoop == FALSE){ - int ErrorCode = ConnHandle.SSLVerifyTest(); - - if (ErrorCode != CURLE_OK){ + if (ConnObjectIter->second->SSLVerify() == COSSL_UNABLETOVERIFY){ + + frmMainPtrGet->PauseAllTimers(); - 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. - - // Stop all the timers. - - frmMainPtrGet->PauseAllTimers(); - - int SSLResult; - #if defined(__APPLE__) + + ConnObjectIter->second->BypassSSLVerification(true); + + COConnectResult ConnectionSSLResult = ConnObjectIter->second->Connect(false); + + ConnObjectIter->second->BypassSSLVerification(false); + + int SSLResult = DisplayTrustPanel(ConnObjectIter->second->BuildSSLCollection(), AccountNameFriendly); + + if (SSLResult != NSOKButton){ - // Bring up the trust panel and display the SSL certificate dialog. + frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnObjectIter->second->BuildSSLCollection()); + iter->second = 2; + break; - SSLResult = DisplayTrustPanel(ConnHandle.GetTrustObject(), AccountNameFriendly); + } else { - // Update the SSL account with the trust object. + frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection()); - if (SSLResult != NSOKButton){ - - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetTrustObject()); - iter->second = 2; - break; - - } else { - - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject()); - - } - + } + #elif defined(__WIN32__) - BOOL ModifiedCertificateData; - CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(&ConnHandle, (HWND)frmMainPtrGet->GetHandle()); + ConnObjectIter->second->BypassSSLVerification(true); - if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)){ - wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog")); - } + COConnectResult ConnectionSSLResult = ConnObjectIter->second->Connect(false); - if (ModifiedCertificateData == FALSE){ + ConnObjectIter->second->BypassSSLVerification(false); - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetCertificateContextPointer()); - iter->second = 2; - break; + BOOL ModifiedCertificateData = false; + CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(ConnObjectIter->second, (HWND)frmMainPtrGet->GetHandle()); - } else { + if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)) { + wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog")); + } - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer()); + if (ModifiedCertificateData == false) { - } + frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnObjectIter->second->BuildSSLCollection()); + iter->second = 2; + break; + + } else { + + frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection()); + + } #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(); - // Setup the data to be sent in the wxPostEvent command. + bool *PauseMode = new bool; + QRNotif qrn; - SSLInvalidCertNotifObj SSLICNProcData; + *PauseMode = TRUE; + qrn.QResponse = &SSLResult; + qrn.PausePtr = PauseMode; - SSLCertCollection certcol = ConnHandle.GetSSLVerifyResults(); + SSLICNProcData.CertCollection = certcol; + SSLICNProcData.QRNotifData = &qrn; + SSLICNProcData.AccountName = AccountNameFriendly; - bool *PauseMode = new bool; - QRNotif qrn; + wxCommandEvent event(INVALIDSSLCERTSTRING); + event.SetClientData(&SSLICNProcData); + wxPostEvent(frmMainPtrGet, event); - *PauseMode = TRUE; - qrn.QResponse = &SSLResult; - qrn.PausePtr = PauseMode; + while (*PauseMode == TRUE){ + //nanosleep(&n1, &n2); + SleepFor(250000000); + } + + // Process the response from the user. + + if (SSLResult == 1){ - SSLICNProcData.CertCollection = certcol; - SSLICNProcData.QRNotifData = &qrn; - SSLICNProcData.AccountName = AccountNameFriendly; + // Accept the Certificate. + + UsingSSLBypass = true; + ConnObjectIter->second->BypassSSLVerification(true); + + COConnectResult TestConnectionResult = ConnObjectIter->second->Connect(true); + WriteServerCertificate(AccountDir, certcol); - wxCommandEvent event(INVALIDSSLCERT); - event.SetClientData(&SSLICNProcData); - wxPostEvent(frmMainPtrGet, event); + ConnObjectIter->second->BypassSSLVerification(false); - /*timespec n1, n2; - - // Fall asleep until we get an response. - - n1.tv_sec = 0; - n1.tv_nsec = 250000000L;*/ + } else if (SSLResult == 2){ + + // Reject the certificate, abort the task and mark as failed. + + iter->second = 2; + break; - while (*PauseMode == TRUE){ - //nanosleep(&n1, &n2); - SleepFor(250000000); - } + } + +#endif - // Process the response from the user. + frmMainPtrGet->ResumeAllTimers(); + ExitLoop = true; - if (SSLResult == 1){ - - // Accept the certificate. Write the certificate into the account - // directory (as server.crt) - will overwrite old certificate. - - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetSSLVerifyResults()); - WriteServerCertificate(AccountDir, ConnHandle.GetSSLVerifyResults()); + } else if (ConnectResponse == COCONNECT_AUTHFAIL){ + + ConnectResponse = ConnObjectIter->second->Connect(true); + + if (ConnectResponse == COCONNECT_OK){ - } else if (SSLResult == 2){ + ExitLoop = true; + break; - // Reject the certificate, abort the task and mark as failed. + } else { - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetSSLVerifyResults()); - iter->second = 2; - break; + ExitLoop = true; + iter->second = 2; + break; - } + } -#endif + } else if (ConnectResponse == COCONNECT_OK){ - // Resume all the timers. + ConnectResponse = ConnObjectIter->second->Connect(true); - frmMainPtrGet->ResumeAllTimers(); - ExitLoop = TRUE; + ExitLoop = true; + break; - } else { + } else { - iter->second = 4; - break; + ExitLoop = true; + iter->second = 2; + break; - } - - } else { - - ExitLoop = TRUE; - } } @@ -1009,29 +1040,21 @@ void frmActivityMgr::ProcessTasksThread() #if defined(__APPLE__) - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject()); + frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection()); #elif defined(__WIN32__) - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer()); + frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection()); #else - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetSSLVerifyResults()); + frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection()); #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){ + COServerResponse DeleteContactResponse = ConnObjectIter->second->DeleteContact(ContactFilename.ToStdString()); + + if (DeleteContactResponse.RequestResult != COREQUEST_OK){ iter->second = 2; break; } @@ -1039,7 +1062,6 @@ void frmActivityMgr::ProcessTasksThread() ETagDBPtr->RemoveETag(ContactFilename); iter->second = 4; - CardDAVIter->second = NULL; break; } @@ -1083,11 +1105,8 @@ void frmActivityMgr::ProcessTasksThread() wxArrayString vCardUpdateRemote; wxArrayString vCardUpdateLog; std::map vCardETag; - ContactListData ServerContactList; std::map vCardDownloadData; - //wxArrayString vCardDownload; - //std::map vCardDownloadData; // Get the list of vCard files locally. @@ -1133,165 +1152,194 @@ void frmActivityMgr::ProcessTasksThread() std::map ETagDBData = ETagDBPtr->GetETagData(); - bool ExitLoop = FALSE; - - std::map *SCListData = NULL; + COConnectResult ConnectResponse = ConnObjectIter->second->Connect(false); - while (ExitLoop == FALSE){ - - // Check if any errors have occured whilst getting the data. - - int ErrorCode = ConnHandle.SSLVerifyTest(); - - if (ErrorCode != CURLE_OK){ + bool ExitLoop = FALSE; - if (ErrorCode == CURLE_SSL_CACERT || - ErrorCode == CURLE_PEER_FAILED_VERIFICATION || - ErrorCode == CURLE_SSL_CONNECT_ERROR){ + while (ExitLoop == FALSE){ - // Invalid SSL certificate so bring up a dialog to the user - // explaining what has happened and the options available. + if (ConnObjectIter->second->SSLVerify() == COSSL_UNABLETOVERIFY){ + + frmMainPtrGet->PauseAllTimers(); + +#if defined(__APPLE__) + + ConnObjectIter->second->BypassSSLVerification(true); + + COConnectResult ConnectionSSLResult = ConnObjectIter->second->Connect(false); + + ConnObjectIter->second->BypassSSLVerification(false); + + int SSLResult = DisplayTrustPanel(ConnObjectIter->second->BuildSSLCollection(), AccountNameFriendly); - // Stop all the timers. + if (SSLResult != NSOKButton){ - frmMainPtrGet->PauseAllTimers(); + frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnObjectIter->second->BuildSSLCollection()); + iter->second = 2; + break; + + } else { + + frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection()); + + } - int SSLResult; +#elif defined(__WIN32__) -#if defined(__APPLE__) - - // Bring up the trust panel and display the SSL certificate dialog. - - SSLResult = DisplayTrustPanel(ConnHandle.GetTrustObject(), AccountNameFriendly); - - // Update the SSL account with the trust object. - - if (SSLResult != NSOKButton){ - - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetTrustObject()); - iter->second = 2; - break; - - } else { - - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject()); - - } + ConnObjectIter->second->BypassSSLVerification(true); -#elif defined(__WIN32__) + COConnectResult ConnectionSSLResult = ConnObjectIter->second->Connect(false); - BOOL ModifiedCertificateData; - CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(&ConnHandle, (HWND)frmMainPtrGet->GetHandle()); + ConnObjectIter->second->BypassSSLVerification(false); - if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)){ - wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog")); - } + BOOL ModifiedCertificateData = false; + CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(ConnObjectIter->second, (HWND)frmMainPtrGet->GetHandle()); - if (ModifiedCertificateData == FALSE){ + if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)) { + wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog")); + } - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetCertificateContextPointer()); - iter->second = 2; - break; + if (ModifiedCertificateData == false) { - } else { + frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnObjectIter->second->BuildSSLCollection()); + iter->second = 2; + break; - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer()); + } else { - } -#else - - // Setup the data to be sent in the wxPostEvent command. + frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection()); - SSLInvalidCertNotifObj SSLICNProcData; + } - SSLCertCollection certcol = ConnHandle.GetSSLVerifyResults(); +#else + + bool UsingSSLBypass = false; + int SSLResult = 0; + + // Connect again and fetch SSL certificate information. + + ConnObjectIter->second->BypassSSLVerification(true); + + COConnectResult ConnectionSSLResult = ConnObjectIter->second->Connect(false); - bool *PauseMode = new bool; - QRNotif qrn; + ConnObjectIter->second->BypassSSLVerification(false); - *PauseMode = TRUE; - qrn.QResponse = &SSLResult; - qrn.PausePtr = PauseMode; - - SSLICNProcData.CertCollection = certcol; - SSLICNProcData.QRNotifData = &qrn; - SSLICNProcData.AccountName = AccountNameFriendly; + SSLInvalidCertNotifObjString SSLICNProcData; - wxCommandEvent event(INVALIDSSLCERT); - 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); - } + 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. + // Process the response from the user. - if (SSLResult == 1){ + if (SSLResult == 1){ - // Accept the certificate. Write the certificate into the account - // directory (as server.crt) - will overwrite old certificate. + // Accept the Certificate. - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetSSLVerifyResults()); - WriteServerCertificate(AccountDir, ConnHandle.GetSSLVerifyResults()); + UsingSSLBypass = true; + ConnObjectIter->second->BypassSSLVerification(true); + + COConnectResult TestConnectionResult = ConnObjectIter->second->Connect(true); + WriteServerCertificate(AccountDir, certcol); - } else if (SSLResult == 2){ + ConnObjectIter->second->BypassSSLVerification(false); - // Reject the certificate, abort the task and mark as failed. + } else if (SSLResult == 2){ + + // Reject the certificate, abort the task and mark as failed. - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetSSLVerifyResults()); - iter->second = 2; - break; + iter->second = 2; + break; - } - + } + #endif - // Resume all the timers. + frmMainPtrGet->ResumeAllTimers(); + ExitLoop = true; + + } else if (ConnectResponse == COCONNECT_AUTHFAIL){ + + ConnectResponse = ConnObjectIter->second->Connect(true); + + if (ConnectResponse == COCONNECT_OK){ + + ExitLoop = true; + break; - frmMainPtrGet->ResumeAllTimers(); - ExitLoop = TRUE; - } else { - - iter->second = 4; + + ExitLoop = true; + iter->second = 2; break; + + } + } else if (ConnectResponse == COCONNECT_OK){ + + ConnectResponse = ConnObjectIter->second->Connect(true); + + if (ConnectResponse == COCONNECT_OK){ + + ExitLoop = true; + break; + + } else { + + ExitLoop = true; + iter->second = 2; + break; + } - + + ExitLoop = true; + break; + } else { - - ExitLoop = TRUE; - + + 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()); + frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection()); #elif defined(__WIN32__) - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer()); + frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection()); #else - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetSSLVerifyResults()); + frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection()); #endif + + if (iter->second == 2 || iter->second == 3 || iter->second == 4){ + break; + } // Look in directory and see which vCards to add and delete @@ -1306,63 +1354,25 @@ 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. - - SCListData = &ServerContactList.ListData; + COContactList ServerContactList2 = ConnObjectIter->second->GetContactList(SyncTokenLoad.ToStdString()); // Process the server data. - if (SCListData != NULL){ - - for (std::map::iterator fsiter = SCListData->begin(); - fsiter != SCListData->end(); fsiter++){ - - // Check the mode of the file before adding. - - // Get the HTTP status of the file from the list. - - FileSyncData fsd = fsiter->second; - - if (fsd.DataFlag == 1){ - - // Added or modified contact. - - //vCardAdd.Add(fsiter->first, 1); - - vCardDownloadDataFileClass vCardNewData; - vCardNewData.DataType = 0; - vCardDownloadData.insert(std::make_pair(fsiter->first, vCardNewData)); - - //} else if (fsd.DataFlag == 1){ - - // Contact has been modified on the server. - - // vCardUpdateLocal.Add(fsiter->first, 1); - - } - else if (fsd.DataFlag == 2){ - - // Contact has been deleted. - - vCardDelete.Add(fsiter->first, 1); - - } - + for (std::vector::iterator ContactInfo = ServerContactList2.ListData.begin(); + ContactInfo != ServerContactList2.ListData.end(); ContactInfo++){ + + if (ContactInfo->Status == COCS_UPDATED){ + + vCardDownloadDataFileClass vCardNewData; + vCardNewData.DataType = 0; + vCardDownloadData.insert(std::make_pair(ContactInfo->Location, vCardNewData)); + + } else if (ContactInfo->Status == COCS_DELETED){ + + vCardDelete.Add(ContactInfo->Location, 1); + } - + } // Look for vCards that are missing but in the ETagDB. @@ -1386,19 +1396,18 @@ void frmActivityMgr::ProcessTasksThread() // needs to updated remotely and which needs to be // updated locally. - for (std::map::iterator srviter = SCListData->begin(); - srviter != SCListData->end(); srviter++){ - - if (ETagDBData.find(srviter->first) == ETagDBData.end()){ + for (std::vector::iterator ContactInfo = ServerContactList2.ListData.begin(); + ContactInfo != ServerContactList2.ListData.end(); ContactInfo++){ + + if (ETagDBData.find(ContactInfo->Location) == ETagDBData.end()){ continue; } - - std::map::iterator lociter = ETagDBData.find(srviter->first); - + + std::map::iterator lociter = ETagDBData.find(ContactInfo->Location); + ETagData etd = lociter->second; - FileSyncData fsd = srviter->second; - - wxString ETagSrv = fsd.ETagData; + + wxString ETagSrv = ContactInfo->Data; // Check if the local ETag value has 'DELETED' set and skip // checking this file if it does. @@ -1421,20 +1430,21 @@ void frmActivityMgr::ProcessTasksThread() vCard34Conv vCard34Obj; - wxString ServerContactData; wxString FullFilename; vCard ClientData; vCard ConvertedV4Data; + std::string ServerContactDataString; + wxString ServerContactData; + // Conflict. Bring up conflict resolution dialog. // Get the server contact data for comparison. - ConnHandle.SetServerFilename(srviter->first); - ConnHandle.GetServerContactData(); - ServerContactData = ConnHandle.GetPageData(); + ConnObjectIter->second->GetContact(ContactInfo->Location, &ServerContactDataString); + ServerContactData = wxString::FromUTF8(ServerContactDataString.c_str()); - FullFilename = CreateFilenamePath(AccountDirFinal, srviter->first); + FullFilename = CreateFilenamePath(AccountDirFinal, ContactInfo->Location); // Convert it to v4. @@ -1466,11 +1476,6 @@ void frmActivityMgr::ProcessTasksThread() event.SetClientData(&vCardProcData); wxPostEvent(frmMainPtrGet, event); - /*timespec n1, n2; - - n1.tv_sec = 0; - n1.tv_nsec = 250000000L;*/ - while (*PauseMode == TRUE){ //nanosleep(&n1, &n2); SleepFor(250000000); @@ -1492,8 +1497,8 @@ void frmActivityMgr::ProcessTasksThread() // Decided to use client version. - vCardUpdateLocal.Remove(srviter->first); - vCardUpdateRemote.Add(srviter->first, 1); + vCardUpdateLocal.Remove(ContactInfo->Location); + vCardUpdateRemote.Add(ContactInfo->Location, 1); } else if (ConflictResult == 2){ @@ -1509,7 +1514,7 @@ void frmActivityMgr::ProcessTasksThread() ConvertedV4Data.WriteFile(FullFilename); - vCardDownloadData.insert(std::make_pair(srviter->first, vCardNewData)); + vCardDownloadData.insert(std::make_pair(ContactInfo->Location, vCardNewData)); @@ -1519,7 +1524,7 @@ void frmActivityMgr::ProcessTasksThread() // Send vCard to the server. - vCardUpdateRemote.Add(srviter->first, 1); + vCardUpdateRemote.Add(ContactInfo->Location, 1); } @@ -1530,12 +1535,12 @@ void frmActivityMgr::ProcessTasksThread() if (etd.ETagOrigValue != ETagSrv){ - vCardUpdateLocal.Add(srviter->first, 1); + vCardUpdateLocal.Add(ContactInfo->Location, 1); } } - + } // Process the vCards that need to be downloaded and added/overwritten. @@ -1565,32 +1570,34 @@ void frmActivityMgr::ProcessTasksThread() // Grab the file from the server and write the contact out. vCard34Conv vCard34Obj; - - ConnHandle.SetServerFilename(additer->first); - ConnHandle.GetServerContactData(); - vCardInputData = ConnHandle.GetPageData(); + + wxString ServerContactData; + std::string ServerContactDataString; + + // Conflict. Bring up conflict resolution dialog. + + // Get the server contact data for comparison. + + ConnObjectIter->second->GetContact(additer->first.ToStdString(), &ServerContactDataString); + vCardInputData = wxString::FromUTF8(ServerContactDataString.c_str()); vCard34Obj.ConvertToV4(&vCardInputData, &ConvertedV4Data); ConvertedV4Data.WriteFile(vCardFilenameFinal); - // Update the ETagDB. - - //vCardFile.Open(vCardFilenameFinal, wxT("w")); - - //if (vCardFile.IsOpened()){ - - // vCardFile.Write(vCardOutputData, wxConvAuto()); - // vCardFile.Close(); - - //} - // Get the server ETag. wxString ServerETag; - ConnHandle.GetServerETagValueThread(); - ServerETag = ConnHandle.ETagValueResult(); - + + COServerResponse ServerEntityTag = ConnObjectIter->second->GetServerEntityTagValue(additer->first.ToStdString()); + + if (ServerEntityTag.RequestResult != COREQUEST_OK){ + iter->second = 2; + break; + } + + ServerETag = wxString::FromUTF8(ServerEntityTag.EntityTag.c_str()); + // Add to the ETag Database. ETagDBPtr->AddETag(additer->first, ServerETag, ServerETag); @@ -1614,8 +1621,15 @@ void frmActivityMgr::ProcessTasksThread() // Update the ETagDB. wxString ServerETag; - ConnHandle.GetServerETagValueThread(); - ServerETag = ConnHandle.ETagValueResult(); + + COServerResponse ServerEntityTag = ConnObjectIter->second->GetServerEntityTagValue(additer->first.ToStdString()); + + if (ServerEntityTag.RequestResult != COREQUEST_OK){ + iter->second = 2; + break; + } + + ServerETag = wxString::FromUTF8(ServerEntityTag.EntityTag.c_str()); // Add to the ETag Database. @@ -1623,6 +1637,12 @@ void frmActivityMgr::ProcessTasksThread() } } + + // Check if any errors occured before continuing. + + if (iter->second != 1){ + break; + } // Look for vCard files which aren't in the ETagDB. @@ -1678,10 +1698,15 @@ void frmActivityMgr::ProcessTasksThread() if (ETag == ETagOriginal && ETagDBPtr->ETagExists(vCardAdd[vi])){ // Compare the ETag with the Server ETag. - - ConnHandle.SetServerFilename(vCardAdd[vi]); - ConnHandle.GetServerETagValueThread(); - ETagServer = ConnHandle.ETagValueResult(); + + COServerResponse ServerEntityTag = ConnObjectIter->second->GetServerEntityTagValue(vCardAdd[vi].ToStdString()); + + if (ServerEntityTag.RequestResult != COREQUEST_OK){ + iter->second = 2; + break; + } + + ETagServer = wxString::FromUTF8(ServerEntityTag.EntityTag.c_str()); if (ETagOriginal != ETagServer){ @@ -1694,13 +1719,20 @@ void frmActivityMgr::ProcessTasksThread() vCard34Conv vCard34Obj; wxString ServerContactData; + std::string ServerContactDataString; vCard ClientData; vCard ConvertedV4Data; // Load the client data from the filename given. - - ConnHandle.GetServerContactData(); - ServerContactData = ConnHandle.GetPageData(); + + COServerResponse GetContactResponse = ConnObjectIter->second->GetContact(vCardAdd[vi].ToStdString(), &ServerContactDataString); + + if (GetContactResponse.RequestResult != COREQUEST_OK){ + iter->second = 2; + break; + } + + ServerContactData = wxString::FromUTF8(ServerContactDataString.c_str()); // Process v3 version into v4 version. @@ -1712,11 +1744,6 @@ void frmActivityMgr::ProcessTasksThread() vCardProcData.vCardServerData = &ConvertedV4Data; ClientData.LoadFile(FullFilename); - //ContactConflictEvent event(ContactConflictCmdEnv); - //event.SetData(ContactFilename, Moo1, Moo2); - - //wxPostEvent(frmMainPtrGet, event); - // Setup Conflict Resolution Dialog. // Fetch Data from Server and convert. @@ -1735,11 +1762,6 @@ void frmActivityMgr::ProcessTasksThread() event.SetClientData(&vCardProcData); wxPostEvent(frmMainPtrGet, event); - /*timespec n1, n2; - - n1.tv_sec = 0; - n1.tv_nsec = 250000000L;*/ - while (*PauseMode == TRUE){ //nanosleep(&n1, &n2); SleepFor(250000000); @@ -1748,8 +1770,6 @@ void frmActivityMgr::ProcessTasksThread() delete PauseMode; PauseMode = NULL; - //intResult = frmMainPtrGet->ShowConflictDialog(&Moo1, &Moo2); - if (ConflictResult == 0){ // Decide Later. @@ -1761,8 +1781,13 @@ void frmActivityMgr::ProcessTasksThread() // Decided to use client version. - ConnHandle.ProcessData(); + COServerResponse EditContactResponse = ConnObjectIter->second->EditContact(vCardAdd[vi].ToStdString(), std::string(ClientData.WriteString().ToUTF8())); + if (EditContactResponse.RequestResult != COREQUEST_OK){ + iter->second = 2; + break; + } + iter->second = 4; } else if (ConflictResult == 2){ @@ -1784,7 +1809,6 @@ void frmActivityMgr::ProcessTasksThread() wxString wxSFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]); wxString wxSCardData; wxString TaskData; - //wxString TaskURL; // Load the data from the file. @@ -1803,22 +1827,26 @@ void frmActivityMgr::ProcessTasksThread() vCard34Conv vCard34Obj; vCard34Obj.ConvertToV3(wxSFilename, &TaskData); - - // Setup the URL address. - - //TaskURL = StringTaskDetailIter->second + wxT("/") + vCardAdd[vi]; // Upload the data to the server. - - ConnHandle.SetUploadMode(TRUE); - ConnHandle.SetupData(wxT("PUT"), vCardAdd[vi], TaskData); - ConnHandle.ProcessData(); + + COServerResponse AddContactResponse = ConnObjectIter->second->AddContact(vCardAdd[vi].ToStdString(), std::string(TaskData.ToUTF8())); + if (AddContactResponse.RequestResult != COREQUEST_OK){ + iter->second = 2; + break; + } + // Get the Server ETag and put it in the ETag database. - - ConnHandle.SetServerFilename(vCardAdd[vi]); - ConnHandle.GetServerETagValueThread(); - ETagServer = ConnHandle.ETagValueResult(); + + COServerResponse EntityTagResponse = ConnObjectIter->second->GetServerEntityTagValue(vCardAdd[vi].ToStdString()); + + if (EntityTagResponse.RequestResult != COREQUEST_OK){ + iter->second = 2; + break; + } + + ETagServer = wxString::FromUTF8(EntityTagResponse.EntityTag.c_str()); ETagDBPtr->AddETag(vCardAdd[vi], ETagServer, ETagServer); @@ -1834,19 +1862,24 @@ void frmActivityMgr::ProcessTasksThread() frmMain *frmMainPtrGet = (frmMain *)frmMainPtr; - //ContactConflictEvent event(ContactConflictCmdEnv); - //event.SetData(ContactFilename, Moo1, Moo2); - vCard34Conv vCard34Obj; + std::string ServerContactDataString; wxString ServerContactData; vCard ClientData; vCard ConvertedV4Data; // Load the client data from the filename given. - ConnHandle.GetServerContactData(); - ServerContactData = ConnHandle.GetPageData(); + COServerResponse GetContactResponse = ConnObjectIter->second->GetContact(vCardAdd[vi].ToStdString(), &ServerContactDataString); + + if (GetContactResponse.RequestResult != COREQUEST_OK){ + iter->second = 2; + break; + } + + ServerContactData = wxString::FromUTF8(ServerContactDataString.c_str()); + ClientData.LoadFile(FullFilename); // Process v3 version into v4 version. @@ -1871,22 +1904,14 @@ void frmActivityMgr::ProcessTasksThread() wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED); event.SetClientData(&vCardProcData); wxPostEvent(frmMainPtrGet, event); - - /*timespec n1, n2; - - n1.tv_sec = 0; - n1.tv_nsec = 250000000L;*/ - + while (*PauseMode == TRUE){ - //nanosleep(&n1, &n2); SleepFor(250000000); } delete PauseMode; PauseMode = NULL; - //intResult = frmMainPtrGet->ShowConflictDialog(&Moo1, &Moo2); - if (ConflictResult == 0){ // Decide Later. @@ -1898,10 +1923,13 @@ void frmActivityMgr::ProcessTasksThread() // Decided to use client version. - ConnHandle.ProcessData(); - //ETagServer = CardDAVIter->second.GetServerETagValueThread(); - //ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer); - + COServerResponse EditContactResponse = ConnObjectIter->second->EditContact(vCardAdd[vi].ToStdString(), std::string(ClientData.WriteString().ToUTF8())); + + if (EditContactResponse.RequestResult != COREQUEST_OK){ + iter->second = 2; + break; + } + iter->second = 4; } else if (ConflictResult == 2){ @@ -1923,7 +1951,6 @@ void frmActivityMgr::ProcessTasksThread() wxString wxSFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]); wxString wxSCardData; wxString TaskData; - //wxString TaskURL; // Load the data from the file. @@ -1942,24 +1969,25 @@ void frmActivityMgr::ProcessTasksThread() vCard34Conv vCard34Obj; vCard34Obj.ConvertToV3(wxSFilename, &TaskData); - - // Setup the URL address. - - //TaskURL = StringTaskDetailIter->second + wxT("/") + vCardAdd[vi]; // Upload the data to the server. - - ConnHandle.SetUploadMode(TRUE); - ConnHandle.SetupData(wxT("PUT"), vCardAdd[vi], TaskData); - ConnHandle.ProcessData(); - + + COServerResponse AddContactResponse = ConnObjectIter->second->AddContact(vCardAdd[vi].ToStdString(), std::string(TaskData.ToUTF8())); + + if (AddContactResponse.RequestResult != COREQUEST_OK){ + iter->second = 2; + break; + } + // Get the Server ETag and put it in the ETag database. - ConnHandle.SetServerFilename(vCardAdd[vi]); - ConnHandle.GetServerETagValueThread(); - ETagServer = ConnHandle.ETagValueResult(); - + COServerResponse EntityTagResponse = ConnObjectIter->second->GetServerEntityTagValue(vCardAdd[vi].ToStdString()); + if (EntityTagResponse.RequestResult != COREQUEST_OK){ + iter->second = 2; + break; + } + ETagDBPtr->AddETag(vCardAdd[vi], ETagServer, ETagServer); } @@ -1968,6 +1996,10 @@ void frmActivityMgr::ProcessTasksThread() } + if (iter->second != 1){ + break; + } + // Process the vCards to delete locally. for (int vi = 0; vi < vCardDelete.GetCount(); vi++){ @@ -1994,9 +2026,7 @@ void frmActivityMgr::ProcessTasksThread() if (deliter->second == wxT("DELETED")){ - ConnHandle.SetUploadMode(FALSE); - ConnHandle.SetupData(wxT("DELETE"), deliter->first, wxT("")); - ConnHandle.ProcessDataThread(); + ConnObjectIter->second->DeleteContact(deliter->first.ToStdString()); // Delete the ETag as the file has now been deleted. @@ -2007,7 +2037,7 @@ void frmActivityMgr::ProcessTasksThread() } for (std::list::iterator removeetagiter = DeleteList.begin(); - removeetagiter != DeleteList.end(); removeetagiter++){ + removeetagiter != DeleteList.end(); removeetagiter++){ ETagDBPtr->RemoveETag(*removeetagiter); @@ -2015,7 +2045,7 @@ void frmActivityMgr::ProcessTasksThread() // Write out the update server sync token. - wxString ServerSyncToken = ServerContactList.SyncToken; + wxString ServerSyncToken = wxString::FromUTF8(ServerContactList2.SyncToken.c_str()); ServerSyncToken.Trim(); @@ -2060,49 +2090,18 @@ void frmActivityMgr::ProcessTasksThread() } else { // Update the data to the server. - - ConnHandle.ProcessData(); + iter->second = 4; continue; } - /*timespec n1, n2; - - n1.tv_sec = 0; - n1.tv_nsec = 250000000L;*/ - while (iter->second == 1){ - SleepFor(250000000); - //nanosleep(&n1, &n2); + SleepFor(125000000); } - if ((iter->second == 4 && TypeIter->second == 0) || - (iter->second == 8 && TypeIter->second == 0)){ - - AccountDir = StringAccountIter->second; - ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir); - - ConnHandle.GetServerETagValueThread(); - ETagServer = ConnHandle.ETagValueResult(); - ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer); - - } - - if ((iter->second == 4 && TypeIter->second == 1) || - (iter->second == 8 && TypeIter->second == 1)){ - - AccountDir = StringAccountIter->second; - ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir); - - ConnHandle.GetServerETagValueThread(); - ETagServer = ConnHandle.ETagValueResult(); - ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer); - - } - break; } @@ -2118,17 +2117,12 @@ void frmActivityMgr::ProcessTasksThread() wxCommandEvent eventp(ACTMGR_STARTTIMER); wxPostEvent(this, eventp); - - //AnimationTimer.StartAnimation(); - //ActListProcTimer.Start(); } wxCommandEvent event(ACTMGR_STARTPROCESSTIMER); wxPostEvent(this, event); - //ActProcessTimer.Start(); - } void frmActivityMgr::ProcessTasks() @@ -2216,6 +2210,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::iterator SSLCDIter = SSLCertInc.SSLCollection.find(0); + std::multimap::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); @@ -2254,13 +2268,9 @@ void frmActivityMgr::UpdateStatusLabel(wxCommandEvent& event){ lstActivity->SetItem(actmgrudata->ItemIndex, 2, actmgrudata->ItemLabel); - /*if (!actmgrudata->ItemDes.IsEmpty()){ - lstActivity->SetItem(actmgrudata->ItemIndex, 0, actmgrudata->ItemDes); - }*/ - delete actmgrudata; actmgrudata = NULL; } -} \ No newline at end of file +}