#include <wx/dir.h>
#include <wx/filefn.h>
#include <thread>
+#include <list>
#include <curl/curl.h>
#include "../bitmaps.h"
std::map<int,int>::iterator TypeIter;
std::map<int,wxString>::iterator StringIter;
+ std::map<int,wxString>::iterator StringDataIter;
+ std::map<int,wxString>::iterator StringURLIter;
std::map<int,wxString>::iterator StringDetailIter;
std::map<int,wxString>::iterator StringAccountIter;
std::map<int,wxString>::iterator StringFilenameIter;
std::map<int,wxString>::iterator StringETagIter;
std::map<int,wxString>::iterator StringETagOrigIter;
std::map<int,CardDAV*>::iterator CardDAVIter;
+ std::map<int,ActivityMgrAccountSettings>::iterator AccountSettingsIter;
std::map<int,long>::iterator LongIter;
bool TasksFoundProc = FALSE;
wxString TaskDetail;
-
+
for (std::map<int,int>::iterator iter = ActivityList.begin();
iter != ActivityList.end(); ++iter){
StringAccountIter = ActivityListAccount.find(iter->first);
StringFilenameIter = ActivityListFilename.find(iter->first);
StringFullFilenameIter = ActivityListFullFilename.find(iter->first);
+ AccountSettingsIter = ActivityListAccSettings.find(iter->first);
+
+ // 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.
// 7 = (Reserved) (UI Updated).
// 8 = Completed. (UI Updated).
+ frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
+ XABPreferences PrefData(GetUserPrefDir());
+
if (iter->second == 0){
//CardDAVIter->second.
wxString ContactFilename;
wxString FullFilename;
wxString ETagResult;
+ bool EditMode = FALSE;
iter->second = 1;
- if (TypeIter->second == 1){
- CardDAVIter->second->GetServerETagValueThread();
- ETagServer = CardDAVIter->second->ETagValueResult();
- }
-
// Compare the ETags and work out if a conflict has occured.
- if (TypeIter->second == 1){
-
- ETag = StringETagIter->second;
- ETagOriginal = StringETagOrigIter->second;
+ if (TypeIter->second == 0){
+
+ // Add a contact.
+
+ StringDataIter = ActivityListData.find(iter->first);
+ StringURLIter = ActivityListURL.find(iter->first);
+
AccountDir = StringAccountIter->second;
ContactFilename = StringFilenameIter->second;
- FullFilename = StringFullFilenameIter->second;
-
- ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
-
- /*if (ETag == ETagOriginal){*/
-
- // Compare the ETag with the Server ETag.
+ wxString AccountNameFriendly;
- if (ETagOriginal != ETagServer){
+ int AccountID = 0;
- // Server ETag is different from original ETag.
- // This is a conflict which the user will now
- // need to resolve.
+ for (int i = 0; i < PrefData.accounts.GetCount(); i++){
- vCard Moo1;
- vCard Moo2;
+ wxString AccountDirCheck = PrefData.accounts.GetAccountDirectory(i);
- frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
+ AccountDirCheck.Trim();
+ AccountDirCheck.Append(wxT(".carddav"));
- vCard34Conv vCard34Obj;
+ if (AccountDirCheck == StringAccountIter->second){
- wxString ServerContactData;
- vCard ClientData;
- vCard ConvertedV4Data;
+ AccountNameFriendly = PrefData.accounts.GetAccountName(i);
+ AccountID = i;
+
+ }
- // Load the client data from the filename given.
+ }
+
+ ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
+
+ ETag = StringETagIter->second;
+ ETagOriginal = StringETagOrigIter->second;
+ AccountDir = StringAccountIter->second;
+ ContactFilename = StringFilenameIter->second;
+ FullFilename = StringFullFilenameIter->second;
+ EditMode = ActivityListEditMode.find(iter->first)->second;
+
+ bool KeepUpdating = TRUE;
+
+ while(KeepUpdating == TRUE){
+
+ bool ExitLoop = FALSE;
- CardDAVIter->second->GetServerContactData();
- ServerContactData = CardDAVIter->second->GetPageData();
+ while (ExitLoop == FALSE){
- // Process v3 version into v4 version.
+ ConnHandle.SetUploadMode(TRUE);
+ ConnHandle.SetupData(wxT("PUT"), StringURLIter->second, StringDataIter->second);
+ ConnHandle.SetEditMode(EditMode);
+ ConnHandle.ProcessData();
- vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
-
- vCardConflictObj vCardProcData;
-
- vCardProcData.vCardLocalData = &ClientData;
- vCardProcData.vCardServerData = &ConvertedV4Data;
- ClientData.LoadFile(FullFilename);
-
- //ContactConflictEvent event(ContactConflictCmdEnv);
- //event.SetData(ContactFilename, Moo1, Moo2);
+ int ErrorCode = ConnHandle.GetResultCode();
+
+ if (ErrorCode != 0){
+
+ if (ErrorCode == 60 || ErrorCode == 51){
+
+ // 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__)
+
+ // 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());
+
+ }
+#else
+
+ // Setup the data to be sent in the wxPostEvent command.
+
+ SSLInvalidCertNotifObj SSLICNProcData;
+
+ 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(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){
+
+ // 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;
+
+ }
+
+#endif
+
+ // Resume all the timers.
+
+ frmMainPtrGet->ResumeAllTimers();
+ ExitLoop = TRUE;
+
+ } else {
+
+ iter->second = 2;
+ break;
+
+ }
+
+ } else {
+
+ ExitLoop = TRUE;
+
+ }
+
+ }
- //wxPostEvent(frmMainPtrGet, event);
+ if (iter->second == 2 || iter->second == 3 || iter->second == 4){
+ break;
+ }
- // Setup Conflict Resolution Dialog.
+#if defined(__APPLE__)
- // Fetch Data from Server and convert.
+ frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
- bool *PauseMode = new bool;
- int ConflictResult;
- QRNotif qrn;
-
- *PauseMode = TRUE;
- qrn.QResponse = &ConflictResult;
- qrn.PausePtr = PauseMode;
-
- vCardProcData.QRNotifData = &qrn;
+#else
- 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);
- }
+ frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData());
- delete PauseMode;
- PauseMode = NULL;
+#endif
- //intResult = frmMainPtrGet->ShowConflictDialog(&Moo1, &Moo2);
+ // Add contact to the ETag DB.
- if (ConflictResult == 0){
+ ConnHandle.GetServerETagValueThread();
+ ETagServer = ConnHandle.ETagValueResult();
+ ETagDBPtr->AddETag(ContactFilename, ETagServer, ETagServer);
- // Decide Later.
+ iter->second = 4;
+ CardDAVIter->second = NULL;
+ break;
- iter->second = 4;
- continue;
+ }
+
+ } else if (TypeIter->second == 1){
+
+ // Update a contact.
+
+ StringDataIter = ActivityListData.find(iter->first);
+ StringURLIter = ActivityListURL.find(iter->first);
+
+ AccountDir = StringAccountIter->second;
+ ContactFilename = StringFilenameIter->second;
+ wxString AccountNameFriendly;
+
+ int AccountID = 0;
+
+ for (int i = 0; i < PrefData.accounts.GetCount(); i++){
- } else if (ConflictResult == 1){
+ wxString AccountDirCheck = PrefData.accounts.GetAccountDirectory(i);
- // Decided to use client version.
+ AccountDirCheck.Trim();
+ AccountDirCheck.Append(wxT(".carddav"));
- CardDAVIter->second->ProcessData();
+ if (AccountDirCheck == StringAccountIter->second){
- iter->second = 4;
+ AccountNameFriendly = PrefData.accounts.GetAccountName(i);
+ AccountID = i;
+
+ }
- } else if (ConflictResult == 2){
+ }
+
+ ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
+
+ ETag = StringETagIter->second;
+ ETagOriginal = StringETagOrigIter->second;
+ AccountDir = StringAccountIter->second;
+ ContactFilename = StringFilenameIter->second;
+ FullFilename = StringFullFilenameIter->second;
+ EditMode = ActivityListEditMode.find(iter->first)->second;
+
+ bool KeepUpdating = TRUE;
+
+ while(KeepUpdating == TRUE){
- // Decided to use server version.
+ bool ExitLoop = FALSE;
+
+ while (ExitLoop == FALSE){
- // Download server version.
+ ConnHandle.SetUploadMode(TRUE);
+ ConnHandle.SetupData(wxT("PUT"), StringURLIter->second, StringDataIter->second);
+ ConnHandle.SetEditMode(EditMode);
+ ConnHandle.GetServerETagValueThread();
+ ETagServer = ConnHandle.ETagValueResult();
- ConvertedV4Data.WriteFile(FullFilename);
+ int ErrorCode = ConnHandle.GetResultCode();
- iter->second = 4;
+ if (ErrorCode != 0){
+
+ if (ErrorCode == 60 || ErrorCode == 51){
+
+ // 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__)
+
+ // 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());
+
+ }
+#else
+
+ // Setup the data to be sent in the wxPostEvent command.
+
+ SSLInvalidCertNotifObj SSLICNProcData;
+
+ 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(INVALIDSSLCERT);
+ 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. 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;
+
+ }
+
+#endif
+
+ // Resume all the timers.
+
+ frmMainPtrGet->ResumeAllTimers();
+ ExitLoop = TRUE;
+
+ } else {
+
+ iter->second = 2;
+ break;
+
+ }
+
+ } else {
+
+ ExitLoop = TRUE;
+
+ }
+
+ }
+
+ if (iter->second == 2 || iter->second == 3 || iter->second == 4){
+ break;
+ }
+
+#if defined(__APPLE__)
+
+ frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
+
+#else
- }
-
- } else {
-
- // Update the data to the server.
+ frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData());
+
+#endif
+
+ // Compare the ETag with the Server ETag.
- CardDAVIter->second->ProcessData();
-
- }
-
- /*} else {
-
if (ETagOriginal != ETagServer){
-
+
// Server ETag is different from original ETag.
// This is a conflict which the user will now
// need to resolve.
-
- frmMain *frmMainPtrGet = (frmMain *)frmMainPtr;
-
- //ContactConflictEvent event(ContactConflictCmdEnv);
- //event.SetData(ContactFilename, Moo1, Moo2);
-
+
+ vCard Moo1;
+ vCard Moo2;
+
+ frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
+
vCard34Conv vCard34Obj;
wxString ServerContactData;
vCard ClientData;
vCard ConvertedV4Data;
-
+
// Load the client data from the filename given.
-
- CardDAVIter->second->GetServerContactData();
- ServerContactData = CardDAVIter->second->GetPageData();
- ClientData.LoadFile(FullFilename);
+
+ ConnHandle.GetServerContactData();
+ ServerContactData = ConnHandle.GetPageData();
// Process v3 version into v4 version.
vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
-
+
vCardConflictObj vCardProcData;
-
+
vCardProcData.vCardLocalData = &ClientData;
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.
+
bool *PauseMode = new bool;
int ConflictResult;
QRNotif qrn;
-
- *PauseMode = TRUE;
+
+ *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){
//nanosleep(&n1, &n2);
SleepFor(250000000);
}
-
+
delete PauseMode;
PauseMode = NULL;
-
+
//intResult = frmMainPtrGet->ShowConflictDialog(&Moo1, &Moo2);
-
+
if (ConflictResult == 0){
-
+
// Decide Later.
-
+
iter->second = 4;
- continue;
-
+ break;
+
} else if (ConflictResult == 1){
-
+
// Decided to use client version.
-
- CardDAVIter->second->ProcessData();
- //ETagServer = CardDAVIter->second.GetServerETagValueThread();
- //ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
-
- iter->second = 4;
-
+
+ ConnHandle.ProcessData();
+
} else if (ConflictResult == 2){
-
+
// Decided to use server version.
-
- // Write server version to file.
-
+
+ // Download server version.
+
ConvertedV4Data.WriteFile(FullFilename);
-
- iter->second = 4;
-
+
}
-
+
} else {
-
+
// Update the data to the server.
-
- CardDAVIter->second->ProcessData();
-
+
+ ConnHandle.ProcessData();
+
}
-
- }*/
-
- // Update the ETag DB.
-
- CardDAVIter->second->GetServerETagValueThread();
- ETagServer = CardDAVIter->second->ETagValueResult();
- ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
-
- iter->second = 4;
- CardDAVIter->second = NULL;
+
+ // Update the ETag DB.
+
+ ConnHandle.GetServerETagValueThread();
+ ETagServer = ConnHandle.ETagValueResult();
+ ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
+
+ iter->second = 4;
+ break;
+
+ }
} else if (TypeIter->second == 2) {
AccountDir = StringAccountIter->second;
ContactFilename = StringFilenameIter->second;
-
+ wxString AccountNameFriendly;
+
+ int AccountID = 0;
+
+ for (int i = 0; i < PrefData.accounts.GetCount(); i++){
+
+ wxString AccountDirCheck = PrefData.accounts.GetAccountDirectory(i);
+
+ AccountDirCheck.Trim();
+ AccountDirCheck.Append(wxT(".carddav"));
+
+ if (AccountDirCheck == StringAccountIter->second){
+
+ AccountNameFriendly = PrefData.accounts.GetAccountName(i);
+ AccountID = i;
+
+ }
+
+ }
+
ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
- CardDAVIter->second->SetUploadMode(FALSE);
- CardDAVIter->second->SetupData(wxT("DELETE"), ContactFilename, wxT(""));
- //CardDAVIter->second.SetServerFilename();
- CardDAVIter->second->ProcessData();
- ETagDBPtr->RemoveETag(ContactFilename);
+ bool KeepUpdating = TRUE;
- iter->second = 4;
- CardDAVIter->second = NULL;
+ while(KeepUpdating == TRUE){
+
+ bool ExitLoop = FALSE;
+
+ 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){
+
+ if (ErrorCode == 60 || ErrorCode == 51){
+
+ // 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__)
+
+ // 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());
+
+ }
+#else
+
+ // Setup the data to be sent in the wxPostEvent command.
+
+ SSLInvalidCertNotifObj SSLICNProcData;
+
+ 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(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){
+
+ // 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;
+
+ }
+
+#endif
+
+ // Resume all the timers.
+
+ frmMainPtrGet->ResumeAllTimers();
+ ExitLoop = TRUE;
+
+ } else {
+
+ iter->second = 4;
+ break;
+
+ }
+
+ } else {
+
+ ExitLoop = TRUE;
+
+ }
+
+ }
+
+ if (iter->second == 2 || iter->second == 3 || iter->second == 4){
+ break;
+ }
- } else if (TypeIter->second == 3) {
+#if defined(__APPLE__)
+
+ frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
+
+#else
+
+ frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData());
+
+#endif
+
+
+ ETagDBPtr->RemoveETag(ContactFilename);
+
+ iter->second = 4;
+ CardDAVIter->second = NULL;
+ break;
+
+ }
- frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
+ } else if (TypeIter->second == 3) {
wxString AccountNameFriendly;
- wxString PrefFilename = GetUserPrefDir();
- XABPreferences PrefData(PrefFilename);
int AccountID = 0;
for (int i = 0; i < PrefData.accounts.GetCount(); i++){
while (ExitLoop == FALSE){
- ServerContactList = CardDAVIter->second->GetContactList(SyncTokenLoad.ToUTF8());
- SSLCertCollection certcol = CardDAVIter->second->GetCertificateData();
+ ServerContactList = ConnHandle.GetContactList(SyncTokenLoad.ToUTF8());
+ SSLCertCollection certcol = ConnHandle.GetCertificateData();
// Create a pointer for the std::map<wxString,FileSyncData>.
// Check if any errors have occured whilst getting the data.
- int ErrorCode = CardDAVIter->second->GetResultCode();
+ int ErrorCode = ConnHandle.GetResultCode();
if (ErrorCode != 0){
frmMainPtrGet->PauseAllTimers();
+ int SSLResult;
+
+#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());
+
+ }
+#else
+
// Setup the data to be sent in the wxPostEvent command.
SSLInvalidCertNotifObj SSLICNProcData;
bool *PauseMode = new bool;
- int SSLResult;
QRNotif qrn;
*PauseMode = TRUE;
// Accept the certificate. Write the certificate into the account
// directory (as server.crt) - will overwrite old certificate.
- frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, CardDAVIter->second->GetCertificateData());
- WriteServerCertificate(AccountDir, CardDAVIter->second->GetCertificateData());
+ 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, CardDAVIter->second->GetCertificateData());
+ frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetCertificateData());
iter->second = 2;
break;
}
+
+#endif
// Resume all the timers.
frmMainPtrGet->ResumeAllTimers();
+ ExitLoop = TRUE;
} else {
break;
}
- frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, CardDAVIter->second->GetCertificateData());
-
+#if defined(__APPLE__)
+
+ frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
+
+#else
+
+ frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData());
+
+#endif
+
// Look in directory and see which vCards to add and delete
// In short:
wxString ETagSrv = fsd.ETagData;
+ // Check if the local ETag value has 'DELETED' set and skip
+ // checking this file if it does.
+
+ if (etd.ETagValue == "DELETED"){
+
+ continue;
+
+ }
+
// Compare local ETag with original local ETag.
// If different, update to server is required.
// Get the server contact data for comparison.
- CardDAVIter->second->SetServerFilename(srviter->first);
- CardDAVIter->second->GetServerContactData();
- ServerContactData = CardDAVIter->second->GetPageData();
+ ConnHandle.SetServerFilename(srviter->first);
+ ConnHandle.GetServerContactData();
+ ServerContactData = ConnHandle.GetPageData();
FullFilename = CreateFilenamePath(AccountDirFinal, srviter->first);
vCard34Conv vCard34Obj;
- CardDAVIter->second->SetServerFilename(additer->first);
- CardDAVIter->second->GetServerContactData();
- vCardInputData = CardDAVIter->second->GetPageData();
+ ConnHandle.SetServerFilename(additer->first);
+ ConnHandle.GetServerContactData();
+ vCardInputData = ConnHandle.GetPageData();
vCard34Obj.ConvertToV4(&vCardInputData, &ConvertedV4Data);
// Get the server ETag.
wxString ServerETag;
- CardDAVIter->second->GetServerETagValueThread();
- ServerETag = CardDAVIter->second->ETagValueResult();
+ ConnHandle.GetServerETagValueThread();
+ ServerETag = ConnHandle.ETagValueResult();
// Add to the ETag Database.
// Update the ETagDB.
wxString ServerETag;
- CardDAVIter->second->GetServerETagValueThread();
- ServerETag = CardDAVIter->second->ETagValueResult();
+ ConnHandle.GetServerETagValueThread();
+ ServerETag = ConnHandle.ETagValueResult();
// Add to the ETag Database.
// Compare the ETag with the Server ETag.
- CardDAVIter->second->SetServerFilename(vCardAdd[vi]);
- CardDAVIter->second->GetServerETagValueThread();
- ETagServer = CardDAVIter->second->ETagValueResult();
+ ConnHandle.SetServerFilename(vCardAdd[vi]);
+ ConnHandle.GetServerETagValueThread();
+ ETagServer = ConnHandle.ETagValueResult();
if (ETagOriginal != ETagServer){
// Load the client data from the filename given.
- CardDAVIter->second->GetServerContactData();
- ServerContactData = CardDAVIter->second->GetPageData();
+ ConnHandle.GetServerContactData();
+ ServerContactData = ConnHandle.GetPageData();
// Process v3 version into v4 version.
// Decided to use client version.
- CardDAVIter->second->ProcessData();
+ ConnHandle.ProcessData();
iter->second = 4;
// Upload the data to the server.
- CardDAVIter->second->SetUploadMode(TRUE);
- CardDAVIter->second->SetupData(wxT("PUT"), vCardAdd[vi], TaskData);
- CardDAVIter->second->ProcessData();
+ ConnHandle.SetUploadMode(TRUE);
+ ConnHandle.SetupData(wxT("PUT"), vCardAdd[vi], TaskData);
+ ConnHandle.ProcessData();
// Get the Server ETag and put it in the ETag database.
- CardDAVIter->second->SetServerFilename(vCardAdd[vi]);
- CardDAVIter->second->GetServerETagValueThread();
- ETagServer = CardDAVIter->second->ETagValueResult();
+ ConnHandle.SetServerFilename(vCardAdd[vi]);
+ ConnHandle.GetServerETagValueThread();
+ ETagServer = ConnHandle.ETagValueResult();
ETagDBPtr->AddETag(vCardAdd[vi], ETagServer, ETagServer);
// Load the client data from the filename given.
- CardDAVIter->second->GetServerContactData();
- ServerContactData = CardDAVIter->second->GetPageData();
+ ConnHandle.GetServerContactData();
+ ServerContactData = ConnHandle.GetPageData();
ClientData.LoadFile(FullFilename);
// Process v3 version into v4 version.
// Decided to use client version.
- CardDAVIter->second->ProcessData();
+ ConnHandle.ProcessData();
//ETagServer = CardDAVIter->second.GetServerETagValueThread();
//ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
// Upload the data to the server.
- CardDAVIter->second->SetUploadMode(TRUE);
- CardDAVIter->second->SetupData(wxT("PUT"), vCardAdd[vi], TaskData);
- CardDAVIter->second->ProcessData();
+ ConnHandle.SetUploadMode(TRUE);
+ ConnHandle.SetupData(wxT("PUT"), vCardAdd[vi], TaskData);
+ ConnHandle.ProcessData();
// Get the Server ETag and put it in the ETag database.
- CardDAVIter->second->SetServerFilename(vCardAdd[vi]);
- CardDAVIter->second->GetServerETagValueThread();
- ETagServer = CardDAVIter->second->ETagValueResult();
+ ConnHandle.SetServerFilename(vCardAdd[vi]);
+ ConnHandle.GetServerETagValueThread();
+ ETagServer = ConnHandle.ETagValueResult();
ETagDBPtr->AddETag(vCardAdd[vi], ETagServer, ETagServer);
// Process the vCards to delete from the server.
std::map<wxString,wxString> *ETagFilenameMap = ETagDBPtr->GetFilenamePointer();
-
+ std::list<wxString> DeleteList;
for (std::map<wxString,wxString>::iterator deliter = ETagFilenameMap->begin();
deliter != ETagFilenameMap->end(); deliter++){
if (deliter->second == wxT("DELETED")){
- CardDAVIter->second->SetUploadMode(FALSE);
- CardDAVIter->second->SetupData(wxT("DELETE"), deliter->first, wxT(""));
- CardDAVIter->second->ProcessData();
+ ConnHandle.SetUploadMode(FALSE);
+ ConnHandle.SetupData(wxT("DELETE"), deliter->first, wxT(""));
+ ConnHandle.ProcessDataThread();
// Delete the ETag as the file has now been deleted.
- ETagDBPtr->RemoveETag(deliter->first);
+ DeleteList.push_back(deliter->first);
}
}
+
+ for (std::list<wxString>::iterator removeetagiter = DeleteList.begin();
+ removeetagiter != DeleteList.end(); removeetagiter++){
+
+ ETagDBPtr->RemoveETag(*removeetagiter);
+
+ }
// Write out the update server sync token.
// Update the data to the server.
- CardDAVIter->second->ProcessData();
+ ConnHandle.ProcessData();
iter->second = 4;
continue;
AccountDir = StringAccountIter->second;
ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
- CardDAVIter->second->GetServerETagValueThread();
- ETagServer = CardDAVIter->second->ETagValueResult();
+ ConnHandle.GetServerETagValueThread();
+ ETagServer = ConnHandle.ETagValueResult();
ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
}
AccountDir = StringAccountIter->second;
ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
- CardDAVIter->second->GetServerETagValueThread();
- ETagServer = CardDAVIter->second->ETagValueResult();
+ ConnHandle.GetServerETagValueThread();
+ ETagServer = ConnHandle.ETagValueResult();
ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
}