X-Git-Url: http://Server1/repobrowser/?a=blobdiff_plain;f=source%2Factmgr%2FfrmActivityMgr.cpp;h=e60ce73d37a8932a6d51c91332bb2bcfdc91e98a;hb=c58983d98dc0bcaceef7bfd3421a7710f3bd8fc0;hp=63755f848029ea1bd4a13f74b17198219c93718c;hpb=57b0514feb18c2ed89f5c6f4b49d6c6513cac9f1;p=xestiaab%2F.git diff --git a/source/actmgr/frmActivityMgr.cpp b/source/actmgr/frmActivityMgr.cpp index 63755f8..e60ce73 100644 --- a/source/actmgr/frmActivityMgr.cpp +++ b/source/actmgr/frmActivityMgr.cpp @@ -214,6 +214,7 @@ void frmActivityMgr::ProcessTasksThread() 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; @@ -235,6 +236,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); @@ -329,13 +331,148 @@ 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; + } + +#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){ // Verify that we have a trusted SSL connection first. @@ -421,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); @@ -510,8 +640,20 @@ void frmActivityMgr::ProcessTasksThread() // 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; + } + + std::cout << ETagGetResponse.EntityTag << std::endl; + + ETagDBPtr->UpdateETag(ContactFilename, ETagGetResponse.EntityTag, ETagGetResponse.EntityTag); iter->second = 4; break; @@ -556,13 +698,237 @@ 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. + + 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(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); + + } + + } else { + + // Upload the data to the server. + + 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(); @@ -801,7 +1167,7 @@ void frmActivityMgr::ProcessTasksThread() // Decided to use client version. - ConnHandle.ProcessData(); + //ConnHandle.ProcessData(); } else if (ConflictResult == 2){ @@ -819,13 +1185,21 @@ 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; + } + + ETagDBPtr->UpdateETag(ContactFilename, ETagGetResponse.EntityTag, ETagGetResponse.EntityTag); iter->second = 4; break; @@ -864,11 +1238,116 @@ void frmActivityMgr::ProcessTasksThread() while(KeepUpdating == TRUE){ + COConnectResult ConnectResponse = ConnObjectIter->second->Connect(false); + bool ExitLoop = FALSE; while (ExitLoop == FALSE){ - int ErrorCode = ConnHandle.SSLVerifyTest(); + 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; + + } + + /*int ErrorCode = ConnHandle.SSLVerifyTest(); if (ErrorCode != CURLE_OK){ @@ -949,13 +1428,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); @@ -999,7 +1471,7 @@ void frmActivityMgr::ProcessTasksThread() ExitLoop = TRUE; - } + }*/ } @@ -1021,7 +1493,7 @@ void frmActivityMgr::ProcessTasksThread() #endif - ConnHandle.SetUploadMode(FALSE); + /*ConnHandle.SetUploadMode(FALSE); ConnHandle.SetupData(wxT("DELETE"), ContactFilename, wxT("")); ConnHandle.ProcessData(); @@ -1034,12 +1506,19 @@ void frmActivityMgr::ProcessTasksThread() if (ErrorCode != CURLE_OK){ iter->second = 2; break; + }*/ + + COServerResponse DeleteContactResponse = ConnObjectIter->second->DeleteContact(ContactFilename.ToStdString()); + + if (DeleteContactResponse.RequestResult != COREQUEST_OK){ + iter->second = 2; + break; } ETagDBPtr->RemoveETag(ContactFilename); iter->second = 4; - CardDAVIter->second = NULL; + //CardDAVIter->second = NULL; break; } @@ -2074,12 +2553,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; @@ -2101,7 +2580,7 @@ void frmActivityMgr::ProcessTasksThread() ETagServer = ConnHandle.ETagValueResult(); ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer); - } + }*/ break; @@ -2216,6 +2695,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);