From 700c6a4c98319bc09eeb5c0905a5dafac8aa61cc Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Sun, 4 Sep 2016 20:35:11 +0100 Subject: [PATCH] Removed CardDAV class and all uses/references. CardDAV class now succeeded by the CardDAV2 class inherited from ConnectionObject. The change to using ConnectionObject now means that theoretically Xestia Address Book is now no longer limited to supporting CardDAV. --- source/actmgr/frmActivityMgr-tasks.cpp | 28 +- source/actmgr/frmActivityMgr.cpp | 1106 ++++------------------ source/carddav/carddav-connect.cpp | 295 ------ source/carddav/carddav-contactlist.cpp | 932 ------------------ source/carddav/carddav-defaultadrurl.cpp | 707 -------------- source/carddav/carddav-processdata.cpp | 522 ---------- source/carddav/carddav-servercontact.cpp | 376 -------- source/carddav/carddav-serveretag.cpp | 579 ----------- source/carddav/carddav-sslverify.cpp | 181 ---- source/carddav/carddav-sslverify.mm | 29 - source/carddav/carddav.cpp | 563 ----------- source/carddav/carddav.h | 189 ---- source/frmMain.cpp | 9 +- source/frmMain.h | 4 +- source/frmNewAccount.cpp | 1 - source/frmNewAccount.h | 1 - 16 files changed, 189 insertions(+), 5333 deletions(-) delete mode 100644 source/carddav/carddav-connect.cpp delete mode 100644 source/carddav/carddav-contactlist.cpp delete mode 100644 source/carddav/carddav-defaultadrurl.cpp delete mode 100644 source/carddav/carddav-processdata.cpp delete mode 100644 source/carddav/carddav-servercontact.cpp delete mode 100644 source/carddav/carddav-serveretag.cpp delete mode 100644 source/carddav/carddav-sslverify.cpp delete mode 100644 source/carddav/carddav-sslverify.mm delete mode 100644 source/carddav/carddav.cpp delete mode 100644 source/carddav/carddav.h diff --git a/source/actmgr/frmActivityMgr-tasks.cpp b/source/actmgr/frmActivityMgr-tasks.cpp index 61ed510..2efca05 100644 --- a/source/actmgr/frmActivityMgr-tasks.cpp +++ b/source/actmgr/frmActivityMgr-tasks.cpp @@ -26,7 +26,6 @@ int frmActivityMgr::AddTask(int TaskType, wxString TaskDetail, wxString TaskAcco wxListItem coldata; long itemindex = -1; - CardDAV* CardDAVConn = new CardDAV; coldata.SetId(ActivityTaskID); coldata.SetData(ActivityTaskID); @@ -90,11 +89,7 @@ int frmActivityMgr::AddTask(int TaskType, wxString TaskDetail, wxString TaskAcco AccountSettings.Password = AccountPassword; AccountSettings.SSL = AccountSSL; AccountSettings.Prefix = AccountPrefix; - AccountSettings.Dir = AccountDir; - - CardDAVConn->SetupConnection(AccountAddress, AccountPort, AccountUsername, AccountPassword, AccountSSL, AccountPrefix, AccountDir); - CardDAVConn->SetupVariables(&ActivityList, ActivityTaskID); - CardDAVConn->SetupResultBools(&BlankBool, &BlankBool); + AccountSettings.Dir = AccountDir; // TaskType: // 0 - Add a contact. @@ -110,9 +105,6 @@ int frmActivityMgr::AddTask(int TaskType, wxString TaskDetail, wxString TaskAcco lstActivity->SetItem(itemindex, 1, AccountName); lstActivity->SetItem(itemindex, 2, _("Queued")); - CardDAVConn->SetUploadMode(TRUE); - CardDAVConn->SetupData(wxT("PUT"), TaskURL, TaskData); - // Setup all of the task details. ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir); @@ -124,7 +116,6 @@ int frmActivityMgr::AddTask(int TaskType, wxString TaskDetail, wxString TaskAcco ActivityListData.insert(std::make_pair(ActivityTaskID, TaskData)); ActivityListURL.insert(std::make_pair(ActivityTaskID, TaskURL)); ActivityListEditMode.insert(std::make_pair(ActivityTaskID, false)); - ActivityListConn.insert(std::make_pair(ActivityTaskID, CardDAVConn)); ActivityListConnObject.insert(std::make_pair(ActivityTaskID, ConnObject)); ActivityListIndex.insert(std::make_pair(ActivityTaskID, itemindex)); ActivityListTaskDetail.insert(std::make_pair(ActivityTaskID, TaskDetail)); @@ -197,12 +188,15 @@ int frmActivityMgr::AddTask(int TaskType, wxString TaskDetail, wxString TaskAcco lstActivity->SetItem(itemindex, 1, AccountName); lstActivity->SetItem(itemindex, 2, _("Queued")); + CardDAV2 *ConnObject = new CardDAV2(AccountAddress.ToStdString(), AccountPort, AccountUsername.ToStdString(), AccountPassword.ToStdString(), AccountSSL, AccountPrefix.ToStdString(), AccountDir.ToStdString()); + ConnObject->SetupConnectionObject(); + ActivityList.insert(std::make_pair(ActivityTaskID, 0)); ActivityListType.insert(std::make_pair(ActivityTaskID, 3)); ActivityListData.insert(std::make_pair(ActivityTaskID, TaskData)); - ActivityListConn.insert(std::make_pair(ActivityTaskID, CardDAVConn)); ActivityListTaskDetail.insert(std::make_pair(ActivityTaskID, AccountPrefix)); ActivityListAccount.insert(std::make_pair(ActivityTaskID, TaskAccount)); + ActivityListConnObject.insert(std::make_pair(ActivityTaskID, ConnObject)); ActivityListIndex.insert(std::make_pair(ActivityTaskID, itemindex)); ActivityListAccSettings.insert(std::make_pair(ActivityTaskID, AccountSettings)); @@ -252,12 +246,6 @@ void frmActivityMgr::StopTask( wxCommandEvent& event ){ return; } - std::map::iterator CDAVter; - - CDAVter = ActivityListConn.find(intSelectedData); - - CDAVter->second->Abort(); - lstActivity->SetItem(longSelected, 2, _("Stopped")); } @@ -281,12 +269,6 @@ void frmActivityMgr::StopAllTasks( wxCommandEvent& event ){ return; } - std::map::iterator CDAVter; - - CDAVter = ActivityListConn.find(intSelectedData); - - CDAVter->second->Abort(); - lstActivity->SetItem(longSelected, 2, _("Stopped")); AnimationTimer.StopAnimation(); bmpActivity->SetBitmap(SleepBitmap); diff --git a/source/actmgr/frmActivityMgr.cpp b/source/actmgr/frmActivityMgr.cpp index e60ce73..40ab583 100644 --- a/source/actmgr/frmActivityMgr.cpp +++ b/source/actmgr/frmActivityMgr.cpp @@ -213,7 +213,6 @@ 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; @@ -235,7 +234,6 @@ 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); @@ -247,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. @@ -273,8 +259,6 @@ void frmActivityMgr::ProcessTasksThread() XABPreferences PrefData(GetUserPrefDir()); if (iter->second == 0){ - - //CardDAVIter->second. // Wait for process to finish. @@ -460,7 +444,7 @@ void frmActivityMgr::ProcessTasksThread() #else - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData()); + frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection()); #endif @@ -472,177 +456,7 @@ void frmActivityMgr::ProcessTasksThread() break; } - /*while (ExitLoop == FALSE){ - - // Verify that we have a trusted SSL connection first. - - int ErrorCode = ConnHandle.SSLVerifyTest(); - - if (ErrorCode != CURLE_OK){ - - 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__) - - // 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()); - - - } - -#elif defined(__WIN32__) - - BOOL ModifiedCertificateData; - CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(&ConnHandle, (HWND)frmMainPtrGet->GetHandle()); - - if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)){ - wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog")); - } - - if (ModifiedCertificateData == FALSE){ - - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetCertificateContextPointer()); - iter->second = 2; - break; - - } else { - - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer()); - - } - -#else - - // Setup the data to be sent in the wxPostEvent command. - - SSLInvalidCertNotifObj SSLICNProcData; - - SSLCertCollection certcol = ConnHandle.GetSSLVerifyResults(); - - bool *PauseMode = new bool; - QRNotif qrn; - - *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()); - -#elif defined(__WIN32__) - - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer()); - -#else - - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData()); - -#endif - - ConnHandle.SetUploadMode(TRUE); - ConnHandle.SetupData(wxT("PUT"), StringURLIter->second, StringDataIter->second); - ConnHandle.SetEditMode(EditMode); - ConnHandle.ProcessData(); - - int ErrorCode = ConnHandle.GetResultCode(); - - if (ErrorCode != CURLE_OK){ - - iter->second = 4; - break; - - } - - // Add contact to the ETag DB. - - ConnHandle.GetServerETagValueThread(); - ETagServer = ConnHandle.ETagValueResult();*/ - - // TODO: Get the entity tag for the new contact. + // Get the entity tag for the new contact. COServerResponse ETagGetResponse = ConnObjectIter->second->GetServerEntityTagValue(StringURLIter->second.ToStdString()); @@ -747,7 +561,6 @@ void frmActivityMgr::ProcessTasksThread() wxPostEvent(frmMainPtrGet, event); while (*PauseMode == TRUE){ - //nanosleep(&n1, &n2); SleepFor(250000000); } @@ -845,9 +658,6 @@ void frmActivityMgr::ProcessTasksThread() // Load the client data from the filename given. - //ConnHandle.GetServerContactData(); - //ServerContactData = ConnHandle.GetPageData(); - COServerResponse GetContactResponse = ConnObjectIter->second->GetContact(StringURLIter->second.ToStdString(), &ServerContactData); @@ -928,270 +738,6 @@ void frmActivityMgr::ProcessTasksThread() } - /*while (ExitLoop == FALSE){ - - int ErrorCode = ConnHandle.SSLVerifyTest(); - - if (ErrorCode != CURLE_OK){ - - 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__) - - // 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()); - - } - -#elif defined(__WIN32__) - - BOOL ModifiedCertificateData; - CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(&ConnHandle, (HWND)frmMainPtrGet->GetHandle()); - - if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)){ - wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog")); - } - - if (ModifiedCertificateData == FALSE){ - - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetCertificateContextPointer()); - iter->second = 2; - break; - - } else { - - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer()); - - } - -#else - - // Setup the data to be sent in the wxPostEvent command. - - SSLInvalidCertNotifObj SSLICNProcData; - - SSLCertCollection certcol = ConnHandle.GetSSLVerifyResults(); - - bool *PauseMode = new bool; - QRNotif qrn; - - *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.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; - - } - -#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()); - -#elif defined(__WIN32__) - - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer()); - -#else - - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetSSLVerifyResults()); - -#endif - - ConnHandle.SetUploadMode(TRUE); - ConnHandle.SetupData(wxT("PUT"), StringURLIter->second, StringDataIter->second); - ConnHandle.SetEditMode(EditMode); - ConnHandle.GetServerETagValueThread(); - ETagServer = ConnHandle.ETagValueResult(); - - int ErrorCode = ConnHandle.GetResultCode(); - - if (ErrorCode != CURLE_OK){ - iter->second = 2; - break; - } - - // Compare the ETag with the Server ETag. - - if (ETagOriginal != ETagServer){ - - // Server ETag is different from original ETag. - // 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; - vCard ClientData; - vCard ConvertedV4Data; - - // Load the client data from the filename given. - - 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; - 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; - break; - - } else if (ConflictResult == 1){ - - // Decided to use client version. - - //ConnHandle.ProcessData(); - - } else if (ConflictResult == 2){ - - // Decided to use server version. - - // Download server version. - - ConvertedV4Data.WriteFile(FullFilename); - - } - - } else { - - // Update the data to the server. - - ConnHandle.ProcessData(); - - }*/ - - // Update the ETag DB. - - //ConnHandle.GetServerETagValueThread(); - //ETagServer = ConnHandle.ETagValueResult(); - ETagGetResponse = ConnObjectIter->second->GetServerEntityTagValue(StringURLIter->second.ToStdString()); if (ETagGetResponse.RequestResult != COREQUEST_OK){ @@ -1342,136 +888,10 @@ void frmActivityMgr::ProcessTasksThread() } else { ExitLoop = true; - iter->second = 2; - break; - - } - - /*int ErrorCode = ConnHandle.SSLVerifyTest(); - - if (ErrorCode != CURLE_OK){ - - 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__) - - // 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()); - - } - -#elif defined(__WIN32__) - - BOOL ModifiedCertificateData; - CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(&ConnHandle, (HWND)frmMainPtrGet->GetHandle()); - - if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)){ - wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog")); - } - - if (ModifiedCertificateData == FALSE){ - - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetCertificateContextPointer()); - iter->second = 2; - break; - - } else { - - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer()); - - } - -#else - - // Setup the data to be sent in the wxPostEvent command. - - SSLInvalidCertNotifObj SSLICNProcData; - - SSLCertCollection certcol = ConnHandle.GetSSLVerifyResults(); - - bool *PauseMode = new bool; - QRNotif qrn; - - *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.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; - - } - -#endif - - // Resume all the timers. - - frmMainPtrGet->ResumeAllTimers(); - ExitLoop = TRUE; - - } else { - - iter->second = 4; - break; - - } - - } else { - - ExitLoop = TRUE; - - }*/ + iter->second = 2; + break; + + } } @@ -1489,24 +909,9 @@ void frmActivityMgr::ProcessTasksThread() #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){ - iter->second = 2; - break; - }*/ COServerResponse DeleteContactResponse = ConnObjectIter->second->DeleteContact(ContactFilename.ToStdString()); @@ -1518,7 +923,6 @@ void frmActivityMgr::ProcessTasksThread() ETagDBPtr->RemoveETag(ContactFilename); iter->second = 4; - //CardDAVIter->second = NULL; break; } @@ -1565,8 +969,6 @@ void frmActivityMgr::ProcessTasksThread() ContactListData ServerContactList; std::map vCardDownloadData; - //wxArrayString vCardDownload; - //std::map vCardDownloadData; // Get the list of vCard files locally. @@ -1612,151 +1014,118 @@ void frmActivityMgr::ProcessTasksThread() std::map ETagDBData = ETagDBPtr->GetETagData(); + COConnectResult ConnectResponse = ConnObjectIter->second->Connect(false); + bool ExitLoop = FALSE; std::map *SCListData = NULL; - while (ExitLoop == FALSE){ - - // Check if any errors have occured whilst getting the data. - - int ErrorCode = ConnHandle.SSLVerifyTest(); - - if (ErrorCode != CURLE_OK){ - - 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){ - // Stop all the timers. - - frmMainPtrGet->PauseAllTimers(); + 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()); - - } - #elif defined(__WIN32__) - - BOOL ModifiedCertificateData; - CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(&ConnHandle, (HWND)frmMainPtrGet->GetHandle()); - - if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)){ - wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog")); - } - - if (ModifiedCertificateData == FALSE){ - - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetCertificateContextPointer()); - iter->second = 2; - break; - - } else { - - frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer()); - - } #else - - // Setup the data to be sent in the wxPostEvent command. - - SSLInvalidCertNotifObj SSLICNProcData; - - SSLCertCollection certcol = ConnHandle.GetSSLVerifyResults(); + + bool 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); + + 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__) @@ -1768,9 +1137,13 @@ void frmActivityMgr::ProcessTasksThread() #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 @@ -1785,63 +1158,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. @@ -1865,19 +1200,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. @@ -1900,20 +1234,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. @@ -1945,11 +1280,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); @@ -1971,8 +1301,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){ @@ -1988,7 +1318,7 @@ void frmActivityMgr::ProcessTasksThread() ConvertedV4Data.WriteFile(FullFilename); - vCardDownloadData.insert(std::make_pair(srviter->first, vCardNewData)); + vCardDownloadData.insert(std::make_pair(ContactInfo->Location, vCardNewData)); @@ -1998,7 +1328,7 @@ void frmActivityMgr::ProcessTasksThread() // Send vCard to the server. - vCardUpdateRemote.Add(srviter->first, 1); + vCardUpdateRemote.Add(ContactInfo->Location, 1); } @@ -2009,12 +1339,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. @@ -2044,32 +1374,29 @@ 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()); + + ServerETag = wxString::FromUTF8(ServerEntityTag.EntityTag.c_str()); + // Add to the ETag Database. ETagDBPtr->AddETag(additer->first, ServerETag, ServerETag); @@ -2093,8 +1420,10 @@ void frmActivityMgr::ProcessTasksThread() // Update the ETagDB. wxString ServerETag; - ConnHandle.GetServerETagValueThread(); - ServerETag = ConnHandle.ETagValueResult(); + + COServerResponse ServerEntityTag = ConnObjectIter->second->GetServerEntityTagValue(additer->first.ToStdString()); + + ServerETag = wxString::FromUTF8(ServerEntityTag.EntityTag.c_str()); // Add to the ETag Database. @@ -2157,10 +1486,10 @@ 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()); + + ETagServer = wxString::FromUTF8(ServerEntityTag.EntityTag.c_str()); if (ETagOriginal != ETagServer){ @@ -2173,13 +1502,15 @@ 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); + + ServerContactData = wxString::FromUTF8(ServerContactDataString.c_str()); // Process v3 version into v4 version. @@ -2191,11 +1522,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. @@ -2214,11 +1540,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); @@ -2227,8 +1548,6 @@ void frmActivityMgr::ProcessTasksThread() delete PauseMode; PauseMode = NULL; - //intResult = frmMainPtrGet->ShowConflictDialog(&Moo1, &Moo2); - if (ConflictResult == 0){ // Decide Later. @@ -2240,7 +1559,7 @@ void frmActivityMgr::ProcessTasksThread() // Decided to use client version. - ConnHandle.ProcessData(); + COServerResponse EditContactResponse = ConnObjectIter->second->EditContact(vCardAdd[vi].ToStdString(), ClientData.WriteString().ToStdString()); iter->second = 4; @@ -2263,7 +1582,6 @@ void frmActivityMgr::ProcessTasksThread() wxString wxSFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]); wxString wxSCardData; wxString TaskData; - //wxString TaskURL; // Load the data from the file. @@ -2282,22 +1600,16 @@ 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(), TaskData.ToStdString()); // 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()); + + ETagServer = wxString::FromUTF8(EntityTagResponse.EntityTag.c_str()); ETagDBPtr->AddETag(vCardAdd[vi], ETagServer, ETagServer); @@ -2313,19 +1625,19 @@ 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); + + ServerContactData = wxString::FromUTF8(ServerContactDataString.c_str()); + ClientData.LoadFile(FullFilename); // Process v3 version into v4 version. @@ -2350,22 +1662,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. @@ -2377,9 +1681,7 @@ 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(), ClientData.WriteString().ToStdString()); iter->second = 4; @@ -2402,7 +1704,6 @@ void frmActivityMgr::ProcessTasksThread() wxString wxSFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]); wxString wxSCardData; wxString TaskData; - //wxString TaskURL; // Load the data from the file. @@ -2421,23 +1722,14 @@ 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(), TaskData.ToStdString()); // 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()); ETagDBPtr->AddETag(vCardAdd[vi], ETagServer, ETagServer); @@ -2473,9 +1765,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. @@ -2486,7 +1776,7 @@ void frmActivityMgr::ProcessTasksThread() } for (std::list::iterator removeetagiter = DeleteList.begin(); - removeetagiter != DeleteList.end(); removeetagiter++){ + removeetagiter != DeleteList.end(); removeetagiter++){ ETagDBPtr->RemoveETag(*removeetagiter); @@ -2494,7 +1784,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(); @@ -2539,49 +1829,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(125000000); - //nanosleep(&n1, &n2); } - /*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; } @@ -2597,17 +1856,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() @@ -2753,10 +2007,6 @@ 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; diff --git a/source/carddav/carddav-connect.cpp b/source/carddav/carddav-connect.cpp deleted file mode 100644 index a265497..0000000 --- a/source/carddav/carddav-connect.cpp +++ /dev/null @@ -1,295 +0,0 @@ -// carddav-connect.cpp - CardDAV Object - Connect subroutines. -// -// (c) 2012-2015 Xestia Software Development. -// -// This file is part of Xestia Address Book. -// -// Xestia Address Book is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by the -// Free Software Foundation, version 3 of the license. -// -// Xestia Address Book is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License along -// with Xestia Address Book. If not, see - -#include "carddav.h" -#include "../version.h" -#include -#include -#include -#include -#include -#include -#include -#include "../vcard/vcard.h" -#include "../common/dirs.h" - -bool CardDAV::Connect(){ - - // Connect to the CardDAV server. - - PageData.Clear(); - PageHeader.Clear(); - - SSLStatus = TRUE; - AuthPassed = TRUE; - AbortConnection = FALSE; - - CURL *conn; - CURLcode conncode; - wxString ServerAddressURL; - wxString ServerAuth; - wxString ServerAddressSSL; - wxString ServerAddressNormal; - - conn = curl_easy_init(); - - struct CardDAVCURLPasser { - - CardDAV *Data; - bool HeaderMode = TRUE; - - } CardDAVHeader, CardDAVFooter; - - CardDAVHeader.Data = this; - CardDAVHeader.HeaderMode = TRUE; - - CardDAVFooter.Data = this; - CardDAVFooter.HeaderMode = FALSE; - - wxString Data1; - wxString Data2; - - ServerAddressURL = ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/"); - ServerAddressSSL = wxT("https://") + ServerAddressURL; - ServerAddressNormal = wxT("http://") + ServerAddressURL; - - ServerAuth = ServerUser + wxT(":") + ServerPass; - - // Try SSL first. - - if (ServerSSL){ - - union { - struct curl_slist *certdata; - struct curl_certinfo *certinfo; - } ptr; - - ptr.certdata = NULL; - - // Setup two initial connections and attempt to get the certificate data. - - curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L); - curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY); - curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60); - curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE); - curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT); - curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc); - curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData); - curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader); - curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(conn, CURLOPT_CERTINFO, 1); - - conncode = (curl_easy_perform(conn)); - - // Check if the SSL certificate is valid or self-signed or some other - // error occured. - - if (conncode == CURLE_OK){ - - // Connection is OK. Do nothing. - - } else if (conncode == CURLE_SSL_CACERT){ - - // Post message saying SSL certificate is invalid. - - curl_easy_getinfo(conn, CURLINFO_CERTINFO, &ptr.certdata); - - } else { - - fprintf(stderr, "curl_easy_perform() failed: %s\n", - curl_easy_strerror(conncode)); - - ErrorMessage = wxString::Format(wxT("%s"), curl_easy_strerror(conncode)); - - *ServerResult = FALSE; - return FALSE; - - } - - ServerAddressSSL.append("principals/"); - - curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L); - curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY); - curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60); - curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE); - curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT); - curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc); - curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData); - curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader); - curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "OPTIONS"); - curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(conn, CURLOPT_CERTINFO, 1); - - if (AllowSelfSign == TRUE){ - curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 0L); - curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 0L); - } - -#if defined(__APPLE__) || defined(__WIN32__) - - SetConnectionObject(conn); - -#endif - - conncode = (curl_easy_perform(conn)); - - ptr.certdata = NULL; - - curl_easy_getinfo(conn, CURLINFO_CERTINFO, &ptr.certdata); - - if (conncode == CURLE_OK){ - - // Process the server header response and look for - // 'addressbook' within the DAV header. - - wxStringTokenizer wxSHeaderLines(PageHeader, wxT("\r\n")); - wxString wxSHeaderLine; - std::map DAVHeaderLines; - - while (wxSHeaderLines.HasMoreTokens()){ - - wxSHeaderLine = wxSHeaderLines.GetNextToken(); - - if (wxSHeaderLine.Mid(0, 4) == wxT("DAV:")){ - - // Look for address book in the line. - - if (wxSHeaderLine.Find(wxT("addressbook")) != wxNOT_FOUND){ - - HasCalDAVSupport = TRUE; - - } - - } - - } - - *ServerResult = TRUE; - ValidResponse = TRUE; - AuthPassed = TRUE; - SSLStatus = TRUE; - return TRUE; - - } else if (conncode == CURLE_HTTP_RETURNED_ERROR){ - - fprintf(stderr, "curl_easy_perform() failed: %s\n", - curl_easy_strerror(conncode)); - - ErrorMessage = wxString::Format(wxT("%s"), curl_easy_strerror(conncode)); - - *ServerResult = TRUE; - ValidResponse = FALSE; - AuthPassed = FALSE; - SSLStatus = TRUE; - return TRUE; - - } else { - - fprintf(stderr, "curl_easy_perform() failed: %s\n", - curl_easy_strerror(conncode)); - - ErrorMessage = wxString::Format(wxT("%s"), curl_easy_strerror(conncode)); - - *ServerResult = FALSE; - return FALSE; - - } - - } else { - - // No SSL. - - curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressNormal.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L); - curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY); - curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60); - curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE); - curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT); - curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc); - curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData); - curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader); - curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1); - - conncode = (curl_easy_perform(conn)); - - if (conncode == CURLE_OK){ - - // Process the server header response and look for - // 'addressbook' within the DAV header. - - wxStringTokenizer wxSHeaderLines(PageHeader, wxT("\r\n")); - wxString wxSHeaderLine; - std::map DAVHeaderLines; - - while (wxSHeaderLines.HasMoreTokens()){ - - wxSHeaderLine = wxSHeaderLines.GetNextToken(); - - if (wxSHeaderLine.Mid(0, 4) == wxT("DAV:")){ - - // Look for address book in the line. - - if (wxSHeaderLine.Find(wxT("addressbook")) != wxNOT_FOUND){ - - HasCalDAVSupport = TRUE; - - } - - } - - } - - *ServerResult = TRUE; - ValidResponse = TRUE; - AuthPassed = TRUE; - SSLStatus = FALSE; - return TRUE; - - } else if (conncode == CURLE_HTTP_RETURNED_ERROR){ - - fprintf(stderr, "curl_easy_perform() failed: %s\n", - curl_easy_strerror(conncode)); - - *ServerResult = TRUE; - ValidResponse = FALSE; - AuthPassed = FALSE; - SSLStatus = FALSE; - return TRUE; - - } else { - - fprintf(stderr, "curl_easy_perform() failed: %s\n", - curl_easy_strerror(conncode)); - - *ServerResult = FALSE; - return FALSE; - - } - - // TODO: Double check and make sure HTTP Authentication is possible. - - } - - *ServerResult = TRUE; - return TRUE; - -} diff --git a/source/carddav/carddav-contactlist.cpp b/source/carddav/carddav-contactlist.cpp deleted file mode 100644 index 6990876..0000000 --- a/source/carddav/carddav-contactlist.cpp +++ /dev/null @@ -1,932 +0,0 @@ -// carddav-contactlist.cpp - CardDAV Object - Contact list subroutines. -// -// (c) 2012-2015 Xestia Software Development. -// -// This file is part of Xestia Address Book. -// -// Xestia Address Book is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by the -// Free Software Foundation, version 3 of the license. -// -// Xestia Address Book is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License along -// with Xestia Address Book. If not, see - -#include "carddav.h" -#include "../version.h" -#include -#include -#include -#include -#include -#include -#include -#include "../vcard/vcard.h" -#include "../common/dirs.h" - -ContactListData CardDAV::GetContactList(wxString SyncTokenInc){ - - // Get the contact list. - - ContactListData ContactListFinal; - std::map ContactList; - - PageData.Clear(); - PageHeader.Clear(); - - SSLStatus = TRUE; - AuthPassed = TRUE; - AbortConnection = FALSE; - - CURL *conn; - wxString ServerAddressURL; - wxString ServerAuth; - wxString ServerAddressSSL; - wxString ServerAddressNormal; - - conn = curl_easy_init(); - -#if defined(__APPLE__) - - SetConnectionObject(conn); - -#endif - - struct CardDAVCURLPasser { - - CardDAV *Data; - bool HeaderMode = TRUE; - - } CardDAVHeader, CardDAVFooter; - - CardDAVHeader.Data = this; - CardDAVHeader.HeaderMode = TRUE; - - CardDAVFooter.Data = this; - CardDAVFooter.HeaderMode = FALSE; - - wxString Data1; - wxString Data2; - - ServerAddressURL = ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + ServerPrefix; - ServerAddressSSL = wxT("https://") + ServerAddressURL; - ServerAddressNormal = wxT("http://") + ServerAddressURL; - - ServerAuth = ServerUser + wxT(":") + ServerPass; - - // Load the sync token file (if it exists). - - wxCharBuffer SyncDataBuffer; - wxString SyncData; - - SyncData.Clear(); - - SyncTokenInc.Trim(); - - if (!SyncTokenInc.IsEmpty()){ - - SyncData = wxT("\n"); - SyncData.Append(wxT("\n")); - SyncData.Append(wxT("")); - SyncData.Append(SyncTokenInc); - SyncData.Append(wxT("\n")); - SyncData.Append(wxT("1\n")); - SyncData.Append(wxT("\n")); - SyncData.Append(wxT(" \n")); - SyncData.Append(wxT("\n")); - SyncData.Append(wxT("")); - - SyncDataBuffer = SyncData.ToUTF8(); - - } else { - - SyncData = wxT("\n"); - SyncData.Append(wxT("\n")); - SyncData.Append(wxT("\n")); - SyncData.Append(wxT("1\n")); - SyncData.Append(wxT("\n")); - SyncData.Append(wxT(" \n")); - SyncData.Append(wxT("\n")); - SyncData.Append(wxT("\n")); - - SyncDataBuffer = SyncData.ToUTF8(); - - } - - const char* query = SyncDataBuffer.data(); - - // Try SSL first. - - std::map::iterator ActIter; - struct UploadDataStruc UploadData; - - ActIter = ActivityListPtr->find((int)ItemIndex); - - curl_slist *slist = NULL; - - slist = curl_slist_append(slist, "Depth: 1"); - - if (ServerSSL){ - - wxString ServerCertFilename; - bool MatchingCert = FALSE; - - curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0); - curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE); - curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60); - curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE); - curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT); - curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc); - curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData); - curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader); - curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this); - curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc); - curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "REPORT"); - curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(conn, CURLOPT_HTTPHEADER, slist); - curl_easy_setopt(conn, CURLOPT_CERTINFO, 1); - -#if defined(__APPLE__) || defined(__WIN32__) - -#else - - ServerCertFilename = GetAccountDir(ServerAccount, TRUE); - - if (wxFile::Exists(ServerCertFilename) == TRUE){ - - curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 1); - curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 2); - curl_easy_setopt(conn, CURLOPT_CAINFO, (const char*)ServerCertFilename.mb_str(wxConvUTF8)); - - } - -#endif - - curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query); - curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query)); - - claconncode = (curl_easy_perform(conn)); - - // If CURLE_PEER_FAILED_VERIFICATION is returned, retry without - // the local certificate in use. - - if (claconncode == CURLE_PEER_FAILED_VERIFICATION){ - - curl_easy_cleanup(conn); - conn = curl_easy_init(); - - curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0); - curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE); - curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60); - curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE); - curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT); - curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc); - curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData); - curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader); - curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this); - curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc); - curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "REPORT"); - curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(conn, CURLOPT_HTTPHEADER, slist); - curl_easy_setopt(conn, CURLOPT_CERTINFO, 1); - curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query); - curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query)); - - claconncode = (curl_easy_perform(conn)); - - // If claconncode is CURLE_OK then delete the certificate file as that - // is no longer needed. - - if (claconncode == CURLE_OK){ - - // Delete the certificate file. - - wxRemoveFile(ServerCertFilename); - - } - - } - - // Check if it fails with a CURLE_SSL_CACERT then compare - // the certificates as PEM files. - -#if defined(__APPLE__) - -#else - - if (claconncode == CURLE_SSL_CACERT && wxFile::Exists(ServerCertFilename) == TRUE){ - - CURL *sslerrconn; - sslerrconn = curl_easy_init(); - CURLcode sslerrconncode; - - wxString ServerAddressOnly = wxT("https://") + ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/"); - - curl_easy_setopt(sslerrconn, CURLOPT_URL, (const char*)ServerAddressOnly.mb_str(wxConvUTF8)); - curl_easy_setopt(sslerrconn, CURLOPT_NOPROGRESS, 0); - curl_easy_setopt(sslerrconn, CURLOPT_HTTPAUTH, CURLAUTH_ANY); - curl_easy_setopt(sslerrconn, CURLOPT_TIMEOUT, 60); - curl_easy_setopt(sslerrconn, CURLOPT_FAILONERROR, TRUE); - curl_easy_setopt(sslerrconn, CURLOPT_USERAGENT, XSDAB_USERAGENT); - curl_easy_setopt(sslerrconn, CURLOPT_WRITEFUNCTION, WritebackFunc); - curl_easy_setopt(sslerrconn, CURLOPT_WRITEDATA, &PageData); - curl_easy_setopt(sslerrconn, CURLOPT_WRITEHEADER, &PageHeader); - curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSDATA, this); - curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSFUNCTION, ProgressFunc); - curl_easy_setopt(sslerrconn, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(sslerrconn, CURLOPT_SSL_VERIFYPEER, 0); - curl_easy_setopt(sslerrconn, CURLOPT_CERTINFO, 1); - - wxString SSLLocalData; - wxString SSLServerData; - - sslerrconncode = (curl_easy_perform(sslerrconn)); - - SSLCertCol = BuildSSLCollection(sslerrconn); - std::map::iterator SSLCDIter = SSLCertCol.SSLCollection.find(0); - std::multimap::iterator SSLDataIter = SSLCDIter->second.CertData.find(wxT("Cert")); - - wxFFile SSLLocalFile; - -#if wxABI_VERSION < 20900 - SSLLocalFile.Open(ServerCertFilename.c_str(), wxT("r")); -#else - SSLLocalFile.Open(ServerCertFilename, wxT("r")); -#endif - - // Load the recovery database for tasks not done. - - if (SSLLocalFile.IsOpened() == TRUE){ - - // Check if we are using wxWidgets version 2.8 or less and - // execute the required command accordingly. - - SSLLocalFile.ReadAll(&SSLLocalData, wxConvAuto()); - - - } - - SSLServerData = SSLDataIter->second; - - if (SSLLocalData == SSLServerData){ - - // Server key matches with local key so retry with CURLOPT_SSL_VERIFYPEER - // and CURLOPT_SSL_VERIFYHOST off. - - curl_easy_cleanup(conn); - conn = curl_easy_init(); - - PageHeader.clear(); - PageData.clear(); - - curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0); - curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY); - curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60); - curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE); - curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT); - curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc); - curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData); - curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader); - curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this); - curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc); - curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "REPORT"); - curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(conn, CURLOPT_HTTPHEADER, slist); - curl_easy_setopt(conn, CURLOPT_CERTINFO, 1); - curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query); - curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query)); - curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 0); - curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 0); - - claconncode = (curl_easy_perform(conn)); - - MatchingCert = TRUE; - - } - - if (MatchingCert == FALSE){ - - claconncode = CURLE_SSL_CACERT; - return ContactListFinal; - - } - - curl_easy_cleanup(sslerrconn); - - } - -#endif - - // Sort out SSL error. - - // When SSL cert error occurs, connect again and fetch certificates. - // Display a message to the user explaining that an invalid - // certificate has been given and let the user decide what - // to do next. - - if (claconncode == CURLE_OK){ - - } else if (claconncode == CURLE_SSL_CACERT || claconncode == CURLE_PEER_FAILED_VERIFICATION){ - - CURL *sslerrconn; - sslerrconn = curl_easy_init(); - CURLcode sslerrconncode; - - wxString ServerAddressOnly = wxT("https://") + ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/"); - - // Replace conn with sslerrconn! - - curl_easy_setopt(sslerrconn, CURLOPT_URL, (const char*)ServerAddressOnly.mb_str(wxConvUTF8)); - curl_easy_setopt(sslerrconn, CURLOPT_NOPROGRESS, 0); - curl_easy_setopt(sslerrconn, CURLOPT_HTTPAUTH, CURLAUTH_ANY); - curl_easy_setopt(sslerrconn, CURLOPT_TIMEOUT, 60); - curl_easy_setopt(sslerrconn, CURLOPT_FAILONERROR, TRUE); - curl_easy_setopt(sslerrconn, CURLOPT_USERAGENT, XSDAB_USERAGENT); - curl_easy_setopt(sslerrconn, CURLOPT_WRITEFUNCTION, WritebackFunc); - curl_easy_setopt(sslerrconn, CURLOPT_WRITEDATA, &PageData); - curl_easy_setopt(sslerrconn, CURLOPT_WRITEHEADER, &PageHeader); - curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSDATA, this); - curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSFUNCTION, ProgressFunc); - curl_easy_setopt(sslerrconn, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(sslerrconn, CURLOPT_SSL_VERIFYPEER, 0); - curl_easy_setopt(sslerrconn, CURLOPT_CERTINFO, 1); - -#if defined(__APPLE__) - - SetConnectionObject(sslerrconn); - -#endif - - sslerrconncode = (curl_easy_perform(sslerrconn)); - - SSLCertCol = BuildSSLCollection(sslerrconn); - SSLCertCol.SuccessCode = 1; - - return ContactListFinal; - - } else if (claconncode == CURLE_HTTP_RETURNED_ERROR){ - - fprintf(stderr, "curl_easy_perform() failed: %s\n", - curl_easy_strerror(claconncode)); - int http_code = 0; - curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &http_code); - fprintf(stderr, "Error code was: %d\n", http_code); - - return ContactListFinal; - - } else { - - fprintf(stderr, "curl_easy_perform() failed: %s\n", - curl_easy_strerror(claconncode)); - int http_code = 0; - curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &http_code); - fprintf(stderr, "Error code was: %d\n", http_code); - - return ContactListFinal; - - } - - SSLCertCol = BuildSSLCollection(conn); - - } else { - - // No SSL. - - wxString EmptyString; - - curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressNormal.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0); - curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY); - curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60); - curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE); - curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT); - curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc); - curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData); - curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader); - curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this); - curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc); - curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "REPORT"); - curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(conn, CURLOPT_HTTPHEADER, slist); - curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query); - curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query)); - - PageData.Clear(); - PageHeader.Clear(); - - claconncode = (curl_easy_perform(conn)); - - if (claconncode == CURLE_OK){ - - - - } else if (claconncode == CURLE_HTTP_RETURNED_ERROR){ - - fprintf(stderr, "curl_easy_perform() failed: %s\n", - curl_easy_strerror(claconncode)); - int http_code = 0; - curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &http_code); - fprintf(stderr, "Error code was: %i\n", http_code); - - return ContactListFinal; - - } else { - - fprintf(stderr, "curl_easy_perform() failed: %s\n", - curl_easy_strerror(claconncode)); - int http_code = 0; - curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &http_code); - fprintf(stderr, "Error code was: %i\n", http_code); - - return ContactListFinal; - - } - - } - - xmlDocPtr xmlCardDAVDoc; - xmlCardDAVDoc = xmlReadMemory(PageData.mb_str(wxConvUTF8), (int)PageData.Len(), "noname.xml", NULL, 0); - - xmlNodePtr nodeLevel1; - xmlNodePtr nodeLevel2; - xmlNodePtr nodeLevel3; - xmlNodePtr nodeLevel4; - xmlNodePtr nodeLevel5; - xmlNodePtr nodeLevel6; - - xmlNodePtr nodeStatusLv1; - xmlNodePtr nodeStatusLv2; - - std::map xmlDataMap; - std::map ServerETagData; - - wxString DataFilename; - wxString DataSyncToken; - int DataFileStatus; - wxString ETagData; - bool SyncTokenFound = FALSE; - - std::string xmlStringSafe; - - // Tranverse through the catacombs of the response to get our ETag for the file and - // the server syncronisation token. - - // Start by getting all the server ETag data. - - for (nodeLevel1 = xmlCardDAVDoc->children; - nodeLevel1 != NULL; - nodeLevel1 = nodeLevel1->next) - { - - for (nodeLevel2 = nodeLevel1->children; - nodeLevel2 != NULL; - nodeLevel2 = nodeLevel2->next) - { - - for (nodeLevel3 = nodeLevel2->children; - nodeLevel3 != NULL; - nodeLevel3 = nodeLevel3->next) - { - - DataFileStatus = 0; - bool HREFFound = FALSE; - bool ETagFound = FALSE; - bool HTTPStatus = FALSE; - - if (!xmlStrcmp(nodeLevel3->name, (const xmlChar *)"href") || - !xmlStrcmp(nodeLevel3->name, (const xmlChar *)"d:href") || - !xmlStrcmp(nodeLevel3->name, (const xmlChar *)"D:href") - ){ - - // Get the filename. - - for (nodeLevel4 = nodeLevel3->children; - nodeLevel4 != NULL; - nodeLevel4 = nodeLevel4->next) - { - - if (!xmlStrcmp(nodeLevel4->name, (const xmlChar *)"text") || - !xmlStrcmp(nodeLevel4->name, (const xmlChar *)"d:text") || - !xmlStrcmp(nodeLevel4->name, (const xmlChar *)"D:text") - ){ - - DataFilename = wxString::FromUTF8((const char*)nodeLevel4->content); - wxStringTokenizer wSTDFilename(DataFilename, wxT("/")); - - while (wSTDFilename.HasMoreTokens()){ - - DataFilename = wSTDFilename.GetNextToken(); - - } - - HREFFound = TRUE; - - } - - - - } - - - } else { - - for (nodeLevel4 = nodeLevel3->children; - nodeLevel4 != NULL; - nodeLevel4 = nodeLevel4->next) - { - - for (nodeStatusLv1 = nodeLevel3->children; - nodeStatusLv1 != NULL; - nodeStatusLv1 = nodeStatusLv1->next) - { - - if (wxString::FromUTF8((const char*)nodeStatusLv1->content) == wxT("HTTP/1.1 404 Not Found")){ - - DataFileStatus = 2; - - HTTPStatus = TRUE; - - } - - if ((!xmlStrcmp(nodeStatusLv1->name, (const xmlChar *)"status") || - !xmlStrcmp(nodeStatusLv1->name, (const xmlChar *)"d:status") || - !xmlStrcmp(nodeStatusLv1->name, (const xmlChar *)"D:status")) && HTTPStatus == FALSE) - { - - // Get the filename. - - for (nodeStatusLv2 = nodeStatusLv1->children; - nodeStatusLv2 != NULL; - nodeStatusLv2 = nodeStatusLv2->next) - { - - if (!xmlStrcmp(nodeStatusLv2->name, (const xmlChar *)"text") || - !xmlStrcmp(nodeStatusLv2->name, (const xmlChar *)"d:text") || - !xmlStrcmp(nodeStatusLv2->name, (const xmlChar *)"D:text") - ){ - - if (wxString::FromUTF8((const char*)nodeStatusLv2->content) == wxT("HTTP/1.1 200 OK")){ - - DataFileStatus = 1; - - HTTPStatus = TRUE; - - // This is currently in a WebDAV draft and may hopefully be enabled when this changes. - - //} else if (wxString::FromUTF8((const char*)nodeStatusLv2->content) == wxT("HTTP/1.1 201 Created")){ - - // DataFileStatus = 0; - - } - - } - - - - } - - } - - - } - - for (nodeLevel5 = nodeLevel4->children; - nodeLevel5 != NULL; - nodeLevel5 = nodeLevel5->next) - { - - if (!xmlStrcmp(nodeLevel5->name, (const xmlChar *)"getetag") || - !xmlStrcmp(nodeLevel5->name, (const xmlChar *)"d:getetag") || - !xmlStrcmp(nodeLevel5->name, (const xmlChar *)"D:getetag") - ){ - - for (nodeLevel6 = nodeLevel5->children; - nodeLevel6 != NULL; - nodeLevel6 = nodeLevel6->next) - { - - // Strip the quotes from the ETag. - - ETagData = wxString::FromUTF8((const char*)nodeLevel6->content); - if (ETagData.Mid(0, 1) == wxT("\"") && ETagData.Mid((ETagData.Len() - 1), 1) == wxT("\"")){ - - ETagData.Remove(0, 1); - ETagData.RemoveLast(); - - } - - ETagFound = TRUE; - - } - - } - - } - - } - - } - - if (HREFFound == TRUE && ETagFound == TRUE && HTTPStatus == TRUE){ - - // Add to the map data. - - FileSyncData SData; - - SData.ETagData = ETagData; - SData.DataFlag = DataFileStatus; - - ContactListFinal.ListData.insert(std::make_pair(DataFilename, SData)); - - } - - // Reset the values. - - HREFFound = FALSE; - ETagFound = FALSE; - HTTPStatus = FALSE; - - } - - if ((!xmlStrcmp(nodeLevel2->name, (const xmlChar *)"sync-token") || - !xmlStrcmp(nodeLevel2->name, (const xmlChar *)"d:sync-token") || - !xmlStrcmp(nodeLevel2->name, (const xmlChar *)"D:sync-token")) && - SyncTokenFound == FALSE - ){ - - for (nodeLevel3 = nodeLevel2->children; - nodeLevel3 != NULL; - nodeLevel3 = nodeLevel3->next) - { - - if (!xmlStrcmp(nodeLevel3->name, (const xmlChar *)"text") || - !xmlStrcmp(nodeLevel3->name, (const xmlChar *)"d:text") || - !xmlStrcmp(nodeLevel3->name, (const xmlChar *)"D:text") - ){ - - DataSyncToken = wxString::FromUTF8((const char*)nodeLevel3->content); - - SyncTokenFound = TRUE; - - } - - } - - } - - } - - } - - for (nodeLevel1 = xmlCardDAVDoc->children; - nodeLevel1 != NULL; - nodeLevel1 = nodeLevel1->next) - { - - for (nodeLevel2 = nodeLevel1->children; - nodeLevel2 != NULL; - nodeLevel2 = nodeLevel2->next) - { - - DataFileStatus = 0; - bool HREFFound = FALSE; - bool ETagFound = FALSE; - bool HTTPStatus = FALSE; - - for (nodeLevel3 = nodeLevel2->children; - nodeLevel3 != NULL; - nodeLevel3 = nodeLevel3->next) - { - - if (!xmlStrcmp(nodeLevel3->name, (const xmlChar *)"href") || - !xmlStrcmp(nodeLevel3->name, (const xmlChar *)"d:href") || - !xmlStrcmp(nodeLevel3->name, (const xmlChar *)"D:href") - ){ - - // Get the filename. - - for (nodeLevel4 = nodeLevel3->children; - nodeLevel4 != NULL; - nodeLevel4 = nodeLevel4->next) - { - - if (!xmlStrcmp(nodeLevel4->name, (const xmlChar *)"text") || - !xmlStrcmp(nodeLevel4->name, (const xmlChar *)"d:text") || - !xmlStrcmp(nodeLevel4->name, (const xmlChar *)"D:text") - ){ - - DataFilename = wxString::FromUTF8((const char*)nodeLevel4->content); - wxStringTokenizer wSTDFilename(DataFilename, wxT("/")); - - while (wSTDFilename.HasMoreTokens()){ - - DataFilename = wSTDFilename.GetNextToken(); - - } - - HREFFound = TRUE; - - } - - - - } - - - } else { - - for (nodeLevel4 = nodeLevel3->children; - nodeLevel4 != NULL; - nodeLevel4 = nodeLevel4->next) - { - - for (nodeStatusLv1 = nodeLevel3->children; - nodeStatusLv1 != NULL; - nodeStatusLv1 = nodeStatusLv1->next) - { - - if (wxString::FromUTF8((const char*)nodeStatusLv1->content) == wxT("HTTP/1.1 404 Not Found")){ - - DataFileStatus = 2; - - HTTPStatus = TRUE; - - } - - if ((!xmlStrcmp(nodeStatusLv1->name, (const xmlChar *)"status") || - !xmlStrcmp(nodeStatusLv1->name, (const xmlChar *)"d:status") || - !xmlStrcmp(nodeStatusLv1->name, (const xmlChar *)"D:status")) && HTTPStatus == FALSE) - { - - // Get the filename. - - for (nodeStatusLv2 = nodeStatusLv1->children; - nodeStatusLv2 != NULL; - nodeStatusLv2 = nodeStatusLv2->next) - { - - if (!xmlStrcmp(nodeStatusLv2->name, (const xmlChar *)"text") || - !xmlStrcmp(nodeStatusLv2->name, (const xmlChar *)"d:text") || - !xmlStrcmp(nodeStatusLv2->name, (const xmlChar *)"D:text") - ){ - - if (wxString::FromUTF8((const char*)nodeStatusLv2->content) == wxT("HTTP/1.1 200 OK")){ - - DataFileStatus = 1; - - HTTPStatus = TRUE; - - // This is currently in a WebDAV draft and may hopefully be enabled when this changes. - - //} else if (wxString::FromUTF8((const char*)nodeStatusLv2->content) == wxT("HTTP/1.1 201 Created")){ - - // DataFileStatus = 0; - - } - - } - - - - } - - } - - - } - - for (nodeLevel5 = nodeLevel4->children; - nodeLevel5 != NULL; - nodeLevel5 = nodeLevel5->next) - { - - if (!xmlStrcmp(nodeLevel5->name, (const xmlChar *)"getetag") || - !xmlStrcmp(nodeLevel5->name, (const xmlChar *)"d:getetag") || - !xmlStrcmp(nodeLevel5->name, (const xmlChar *)"D:getetag") - ){ - - for (nodeLevel6 = nodeLevel5->children; - nodeLevel6 != NULL; - nodeLevel6 = nodeLevel6->next) - { - - // Strip the quotes from the ETag. - - ETagData = wxString::FromUTF8((const char*)nodeLevel6->content); - if (ETagData.Mid(0, 1) == wxT("\"") && ETagData.Mid((ETagData.Len() - 1), 1) == wxT("\"")){ - - ETagData.Remove(0, 1); - ETagData.RemoveLast(); - - } - - ETagFound = TRUE; - - } - - } - - } - - } - - } - - } - - if (HREFFound == TRUE && HTTPStatus == TRUE && DataFileStatus == 2){ - - FileSyncData SData; - - SData.ETagData = wxT(""); - SData.DataFlag = DataFileStatus; - - ContactListFinal.ListData.insert(std::make_pair(DataFilename, SData)); - - } - - if (HREFFound == TRUE && ETagFound == TRUE && HTTPStatus == TRUE){ - - // Add to the map data. - - FileSyncData SData; - - SData.ETagData = ETagData; - SData.DataFlag = DataFileStatus; - - ContactListFinal.ListData.insert(std::make_pair(DataFilename, SData)); - - } - - // Reset the values. - - HREFFound = FALSE; - ETagFound = FALSE; - HTTPStatus = FALSE; - DataFilename.Clear(); - - if ((!xmlStrcmp(nodeLevel2->name, (const xmlChar *)"sync-token") || - !xmlStrcmp(nodeLevel2->name, (const xmlChar *)"d:sync-token") || - !xmlStrcmp(nodeLevel2->name, (const xmlChar *)"D:sync-token")) && - SyncTokenFound == FALSE - ){ - - for (nodeLevel3 = nodeLevel2->children; - nodeLevel3 != NULL; - nodeLevel3 = nodeLevel3->next) - { - - if (!xmlStrcmp(nodeLevel3->name, (const xmlChar *)"text") || - !xmlStrcmp(nodeLevel3->name, (const xmlChar *)"d:text") || - !xmlStrcmp(nodeLevel3->name, (const xmlChar *)"D:text") - ){ - - DataSyncToken = wxString::FromUTF8((const char*)nodeLevel3->content); - - SyncTokenFound = TRUE; - - } - - } - - } - - } - - } - - // Get the sync token. - - if (SyncTokenFound == TRUE){ - - ContactListFinal.SyncToken = DataSyncToken; - - } else { - - } - - SleepFor(2000000000); - - xmlFreeDoc(xmlCardDAVDoc); - curl_easy_cleanup(conn); - - SyncDataBuffer.reset(); - - // Get the first result. - - return ContactListFinal; - -} \ No newline at end of file diff --git a/source/carddav/carddav-defaultadrurl.cpp b/source/carddav/carddav-defaultadrurl.cpp deleted file mode 100644 index b2fec75..0000000 --- a/source/carddav/carddav-defaultadrurl.cpp +++ /dev/null @@ -1,707 +0,0 @@ -// carddav-defaultadrurl.cpp - CardDAV Object - Default Address URL subroutines. -// -// (c) 2012-2015 Xestia Software Development. -// -// This file is part of Xestia Address Book. -// -// Xestia Address Book is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by the -// Free Software Foundation, version 3 of the license. -// -// Xestia Address Book is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License along -// with Xestia Address Book. If not, see - -#include "carddav.h" -#include "../version.h" -#include -#include -#include -#include -#include -#include -#include -#include "../vcard/vcard.h" -#include "../common/dirs.h" - -wxString CardDAV::GetDefaultAddressBookURL(){ - - // Get the default address book URL. - - PageData.Clear(); - PageHeader.Clear(); - - SSLStatus = TRUE; - AuthPassed = TRUE; - AbortConnection = FALSE; - - CURL *conn; - CURLcode conncode; - wxString ServerAddressURL; - wxString ServerAuth; - wxString ServerAddressSSL; - wxString ServerAddressNormal; - - // First: Get the principal UID address. - - conn = curl_easy_init(); - -#if defined(__APPLE__) - - SetConnectionObject(conn); - -#endif - - struct curl_slist *connhd = NULL; - struct curl_slist *connhd2 = NULL; - struct curl_slist *connhd3 = NULL; - - connhd = curl_slist_append(connhd, "Depth: 0"); - connhd = curl_slist_append(connhd, "Prefer: return-minimal"); - connhd = curl_slist_append(connhd, "Content-Type: application/xml; charset=utf-8"); - - connhd2 = curl_slist_append(connhd2, "Depth: 0"); - connhd2 = curl_slist_append(connhd2, "Prefer: return-minimal"); - connhd2 = curl_slist_append(connhd2, "Content-Type: application/xml; charset=utf-8"); - - connhd3 = curl_slist_append(connhd3, "Depth: 1"); - connhd3 = curl_slist_append(connhd3, "Prefer: return-minimal"); - connhd3 = curl_slist_append(connhd3, "Content-Type: application/xml; charset=utf-8"); - - struct CardDAVCURLPasser { - - CardDAV *Data; - bool HeaderMode = TRUE; - - } CardDAVHeader, CardDAVFooter; - - CardDAVHeader.Data = this; - CardDAVHeader.HeaderMode = TRUE; - - CardDAVFooter.Data = this; - CardDAVFooter.HeaderMode = FALSE; - - wxString Data1; - wxString Data2; - - wxString ETag; - wxString ETagOriginal; - wxString ETagServer; - - ServerAddressURL = ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/"); - ServerAddressSSL = wxT("https://") + ServerAddressURL; - ServerAddressNormal = wxT("http://") + ServerAddressURL; - - ServerAuth = ServerUser + wxT(":") + ServerPass; - - wxString SAURLPrincipals; - wxString SAURLPrincipalURL; - wxString SAURLAddressURL; - - if (ServerSSL){ - - SAURLPrincipals = ServerAddressSSL + wxT("principals/"); - SAURLPrincipalURL = ServerAddressSSL; - SAURLAddressURL = ServerAddressSSL; - - } else { - - SAURLPrincipals = ServerAddressNormal + wxT("principals/"); - SAURLPrincipalURL = ServerAddressNormal; - SAURLAddressURL = ServerAddressNormal; - - } - - wxString FinalPrefix; - - struct UploadDataStruc UploadData; - - // Setup the first query finding out where the principal URL is. - - const char* query = "\n" - "\n" - " " - " \n" - " " - ""; - - // Setup the second query finding out where the address book home URL is. - - const char* query2 = "\n" - "\n" - " \n" - " \n" - " \n" - ""; - - // Setup the third query finding out where the default address book URL is. - - const char* query3 = "\n" - "\n" - " \n" - " \n" - " \n" - ""; - - if (ServerSSL){ - - curl_easy_setopt(conn, CURLOPT_URL, (const char*)SAURLPrincipals.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L); - curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY); - curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60); - curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE); - curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT); - curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc); - curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData); - curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader); - curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "PROPFIND"); - curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query); - curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query)); - curl_easy_setopt(conn, CURLOPT_HTTPHEADER, connhd); - - if (AllowSelfSign == TRUE){ - curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 0L); - curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 0L); - } - -#if defined(__APPLE__) - - SetConnectionObject(conn); - -#endif - - conncode = (curl_easy_perform(conn)); - - if (conncode == CURLE_OK){ - - *ServerResult = TRUE; - AuthPassed = TRUE; - ValidResponse = TRUE; - SSLStatus = TRUE; - - } else { - - fprintf(stderr, "curl_easy_perform() failed: %s\n", - curl_easy_strerror(conncode)); - - *ServerResult = FALSE; - - curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode); - - return wxT(""); - - } - - } else { - - // No SSL. - - // Do an initial connection (incase of Digest authentication). - - PageData.Clear(); - PageHeader.Clear(); - - curl_easy_setopt(conn, CURLOPT_URL, (const char*)SAURLPrincipals.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0); - curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE); - curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60); - curl_easy_setopt(conn, CURLOPT_FAILONERROR, FALSE); - curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT); - curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc); - curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData); - curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader); - curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this); - curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc); - curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "PROPFIND"); - curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query); - curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query)); - curl_easy_setopt(conn, CURLOPT_HTTPHEADER, connhd); - - conncode = (curl_easy_perform(conn)); - - // If the ETag is different to the non-matching X-XAB-ETAG and X-XAB-ETAG-ORIG, - // then bring up the conflict resolution form. - - if (EditMode == TRUE){ - - } - - if (conncode == CURLE_OK){ - - } else if (conncode == CURLE_HTTP_RETURNED_ERROR){ - - curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode); - - fprintf(stderr, "curl_easy_perform() failed: %s\n", - curl_easy_strerror(conncode)); - - fprintf(stderr, "curl_easy_perform() HTTP code was: %i\n", - GetHTTPCode()); - - return wxT(""); - - } else { - - fprintf(stderr, "curl_easy_perform() failed: %s\n", - curl_easy_strerror(conncode)); - return wxT(""); - - } - - } - - // Process the XML data from the application. - - xmlDocPtr xmlCardDAVDoc; - xmlCardDAVDoc = xmlReadMemory(PageData.mb_str(wxConvUTF8), (int)PageData.Len(), "noname.xml", NULL, 0); - - xmlNodePtr nodeLevel1; - xmlNodePtr nodeLevel2; - xmlNodePtr nodeLevel3; - xmlNodePtr nodeLevel4; - xmlNodePtr nodeLevel5; - xmlNodePtr nodeLevel6; - xmlNodePtr nodeLevel7; - - for (nodeLevel1 = xmlCardDAVDoc->children; - nodeLevel1 != NULL; - nodeLevel1 = nodeLevel1->next) - { - - for (nodeLevel2 = nodeLevel1->children; - nodeLevel2 != NULL; - nodeLevel2 = nodeLevel2->next) - { - - - for (nodeLevel3 = nodeLevel2->children; - nodeLevel3 != NULL; - nodeLevel3 = nodeLevel3->next) - { - - for (nodeLevel4 = nodeLevel3->children; - nodeLevel4 != NULL; - nodeLevel4 = nodeLevel4->next) - { - - for (nodeLevel5 = nodeLevel4->children; - nodeLevel5 != NULL; - nodeLevel5 = nodeLevel5->next) - { - - for (nodeLevel6 = nodeLevel5->children; - nodeLevel6 != NULL; - nodeLevel6 = nodeLevel6->next) - { - - if (!xmlStrcmp(nodeLevel6->name, (const xmlChar *)"href") || - !xmlStrcmp(nodeLevel6->name, (const xmlChar *)"d:href") || - !xmlStrcmp(nodeLevel6->name, (const xmlChar *)"D:href") - ){ - - // Found the part so extract the principal URL address. - - for (nodeLevel7 = nodeLevel6->children; - nodeLevel7 != NULL; - nodeLevel7 = nodeLevel7->next) - { - - SAURLPrincipalURL.Append(wxString::FromUTF8((const char*)nodeLevel7->content)); - - } - - } - - } - - } - - } - - } - - } - - } - - xmlFreeDoc(xmlCardDAVDoc); - PageData.Clear(); - PageHeader.Clear(); - - // Second: Get the addressbook-home-set - - curl_easy_reset(conn); - - if (ServerSSL){ - - curl_easy_setopt(conn, CURLOPT_URL, (const char*)SAURLPrincipalURL.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L); - curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE); - curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60); - curl_easy_setopt(conn, CURLOPT_FAILONERROR, FALSE); - curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT); - curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc); - curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData); - curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader); - curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "PROPFIND"); - curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query2); - curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query2)); - curl_easy_setopt(conn, CURLOPT_HTTPHEADER, connhd2); - - if (AllowSelfSign == TRUE){ - curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 0L); - curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 0L); - } - -#if defined(__APPLE__) - - SetConnectionObject(conn); - -#endif - - conncode = (curl_easy_perform(conn)); - - if (conncode == CURLE_OK){ - - *ServerResult = TRUE; - AuthPassed = TRUE; - SSLStatus = TRUE; - - } else { - - fprintf(stderr, "curl_easy_perform() failed: %s\n", - curl_easy_strerror(conncode)); - - *ServerResult = FALSE; - ValidResponse = FALSE; - - curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode); - - return wxT(""); - - } - - } else { - - // No SSL. - - curl_easy_setopt(conn, CURLOPT_URL, (const char*)SAURLPrincipalURL.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0); - curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE); - curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60); - curl_easy_setopt(conn, CURLOPT_FAILONERROR, FALSE); - curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT); - curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc); - curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData); - curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader); - curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this); - curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc); - curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "PROPFIND"); - curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query2); - curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query2)); - curl_easy_setopt(conn, CURLOPT_HTTPHEADER, connhd2); - - conncode = (curl_easy_perform(conn)); - - // If the ETag is different to the non-matching X-XAB-ETAG and X-XAB-ETAG-ORIG, - // then bring up the conflict resolution form. - - if (EditMode == TRUE){ - - } - - if (conncode == CURLE_OK){ - - } else if (conncode == CURLE_HTTP_RETURNED_ERROR){ - - curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode); - - fprintf(stderr, "curl_easy_perform() failed: %s\n", - curl_easy_strerror(conncode)); - - fprintf(stderr, "curl_easy_perform() HTTP code was: %i\n", - GetHTTPCode()); - - ValidResponse = FALSE; - - return wxT(""); - - } else { - - fprintf(stderr, "curl_easy_perform() failed: %s\n", - curl_easy_strerror(conncode)); - - ValidResponse = FALSE; - - return wxT(""); - - } - - } - - xmlCardDAVDoc = xmlReadMemory(PageData.mb_str(wxConvUTF8), (int)PageData.Len(), "noname.xml", NULL, 0); - - for (nodeLevel1 = xmlCardDAVDoc->children; - nodeLevel1 != NULL; - nodeLevel1 = nodeLevel1->next) - { - - for (nodeLevel2 = nodeLevel1->children; - nodeLevel2 != NULL; - nodeLevel2 = nodeLevel2->next) - { - - - for (nodeLevel3 = nodeLevel2->children; - nodeLevel3 != NULL; - nodeLevel3 = nodeLevel3->next) - { - - for (nodeLevel4 = nodeLevel3->children; - nodeLevel4 != NULL; - nodeLevel4 = nodeLevel4->next) - { - - for (nodeLevel5 = nodeLevel4->children; - nodeLevel5 != NULL; - nodeLevel5 = nodeLevel5->next) - { - - for (nodeLevel6 = nodeLevel5->children; - nodeLevel6 != NULL; - nodeLevel6 = nodeLevel6->next) - { - - if (!xmlStrcmp(nodeLevel6->name, (const xmlChar *)"href") || - !xmlStrcmp(nodeLevel6->name, (const xmlChar *)"d:href") || - !xmlStrcmp(nodeLevel6->name, (const xmlChar *)"D:href") - ){ - - // Found the part so extract the principal URL address. - - for (nodeLevel7 = nodeLevel6->children; - nodeLevel7 != NULL; - nodeLevel7 = nodeLevel7->next) - { - - SAURLAddressURL.Append(wxString::FromUTF8((const char*)nodeLevel7->content)); - - } - - } - - } - - } - - } - - } - - } - - } - - xmlFreeDoc(xmlCardDAVDoc); - PageData.Clear(); - PageHeader.Clear(); - - // Finally: Get the default-addressbook-URL from the addressbook-home-set address. - - curl_easy_reset(conn); - - if (ServerSSL){ - - curl_easy_setopt(conn, CURLOPT_URL, (const char*)SAURLAddressURL.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L); - curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE); - curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60); - curl_easy_setopt(conn, CURLOPT_FAILONERROR, FALSE); - curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT); - curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc); - curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData); - curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader); - curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "PROPFIND"); - curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query3); - curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query3)); - curl_easy_setopt(conn, CURLOPT_HTTPHEADER, connhd3); - - if (AllowSelfSign == TRUE){ - curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 0L); - curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 0L); - } - -#if defined(__APPLE__) - - SetConnectionObject(conn); - -#endif - - conncode = (curl_easy_perform(conn)); - - if (conncode == CURLE_OK){ - - *ServerResult = TRUE; - AuthPassed = TRUE; - SSLStatus = TRUE; - - } else { - - fprintf(stderr, "curl_easy_perform() failed: %s\n", - curl_easy_strerror(conncode)); - - *ServerResult = FALSE; - ValidResponse = FALSE; - - curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode); - - return wxT(""); - - } - - } else { - - // No SSL. - - curl_easy_setopt(conn, CURLOPT_URL, (const char*)SAURLAddressURL.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0); - curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE); - curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60); - curl_easy_setopt(conn, CURLOPT_FAILONERROR, FALSE); - curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT); - curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc); - curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData); - curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader); - curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this); - curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc); - curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "PROPFIND"); - curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query3); - curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query3)); - curl_easy_setopt(conn, CURLOPT_HTTPHEADER, connhd3); - - conncode = (curl_easy_perform(conn)); - - // If the ETag is different to the non-matching X-XAB-ETAG and X-XAB-ETAG-ORIG, - // then bring up the conflict resolution form. - - if (EditMode == TRUE){ - - } - - if (conncode == CURLE_OK){ - - } else if (conncode == CURLE_HTTP_RETURNED_ERROR){ - - curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode); - - fprintf(stderr, "curl_easy_perform() failed: %s\n", - curl_easy_strerror(conncode)); - - fprintf(stderr, "curl_easy_perform() HTTP code was: %i\n", - GetHTTPCode()); - - ValidResponse = FALSE; - - return wxT(""); - - } else { - - fprintf(stderr, "curl_easy_perform() failed: %s\n", - curl_easy_strerror(conncode)); - - ValidResponse = FALSE; - - return wxT(""); - - } - - } - - xmlCardDAVDoc = xmlReadMemory(PageData.mb_str(wxConvUTF8), (int)PageData.Len(), "noname.xml", NULL, 0); - - for (nodeLevel1 = xmlCardDAVDoc->children; - nodeLevel1 != NULL; - nodeLevel1 = nodeLevel1->next) - { - - for (nodeLevel2 = nodeLevel1->children; - nodeLevel2 != NULL; - nodeLevel2 = nodeLevel2->next) - { - - - for (nodeLevel3 = nodeLevel2->children; - nodeLevel3 != NULL; - nodeLevel3 = nodeLevel3->next) - { - - for (nodeLevel4 = nodeLevel3->children; - nodeLevel4 != NULL; - nodeLevel4 = nodeLevel4->next) - { - - for (nodeLevel5 = nodeLevel4->children; - nodeLevel5 != NULL; - nodeLevel5 = nodeLevel5->next) - { - - for (nodeLevel6 = nodeLevel5->children; - nodeLevel6 != NULL; - nodeLevel6 = nodeLevel6->next) - { - - if (!xmlStrcmp(nodeLevel6->name, (const xmlChar *)"href") || - !xmlStrcmp(nodeLevel6->name, (const xmlChar *)"d:href") || - !xmlStrcmp(nodeLevel6->name, (const xmlChar *)"D:href") - ){ - - // Found the part so extract the principal URL address. - - for (nodeLevel7 = nodeLevel6->children; - nodeLevel7 != NULL; - nodeLevel7 = nodeLevel7->next) - { - - FinalPrefix = wxString::FromUTF8((const char*)nodeLevel7->content); - - } - - } - - } - - } - - } - - } - - } - - } - - xmlFreeDoc(xmlCardDAVDoc); - PageData.Clear(); - PageHeader.Clear(); - - return FinalPrefix; - -} diff --git a/source/carddav/carddav-processdata.cpp b/source/carddav/carddav-processdata.cpp deleted file mode 100644 index 1e5a603..0000000 --- a/source/carddav/carddav-processdata.cpp +++ /dev/null @@ -1,522 +0,0 @@ -// carddav-processdata.cpp - CardDAV Object - Process Data subroutines. -// -// (c) 2012-2015 Xestia Software Development. -// -// This file is part of Xestia Address Book. -// -// Xestia Address Book is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by the -// Free Software Foundation, version 3 of the license. -// -// Xestia Address Book is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License along -// with Xestia Address Book. If not, see - -#include "carddav.h" -#include "../version.h" -#include -#include -#include -#include -#include -#include -#include -#include "../vcard/vcard.h" -#include "../common/dirs.h" - -void CardDAV::ProcessDataThread(){ - - // Process the data (threaded). - - PageData.Clear(); - PageHeader.Clear(); - - SSLStatus = TRUE; - AuthPassed = TRUE; - AbortConnection = FALSE; - - CURL *conn; - CURLcode conncode; - wxString ServerAddressURL; - wxString ServerAuth; - wxString ServerAddressSSL; - wxString ServerAddressNormal; - - conn = curl_easy_init(); - -#if defined(__APPLE__) - - SetConnectionObject(conn); - -#endif - - struct CardDAVCURLPasser { - - CardDAV *Data; - bool HeaderMode = TRUE; - - } CardDAVHeader, CardDAVFooter; - - CardDAVHeader.Data = this; - CardDAVHeader.HeaderMode = TRUE; - - CardDAVFooter.Data = this; - CardDAVFooter.HeaderMode = FALSE; - - wxString Data1; - wxString Data2; - - wxString ETag; - wxString ETagOriginal; - wxString ETagServer; - - ServerAddressURL = ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + ServerPrefix + ServerFilenameLocation; - ServerAddressSSL = wxT("https://") + ServerAddressURL; - ServerAddressNormal = wxT("http://") + ServerAddressURL; - - ServerAuth = ServerUser + wxT(":") + ServerPass; - - std::map::iterator ActIter; - struct UploadDataStruc UploadData; - - - ActIter = ActivityListPtr->find((int)ItemIndex); - - // Update result flag. - - ActIter->second = 1; - - // Setup the request mode if it is not empty. - - if (!ServerMethod.IsEmpty()){ - - curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, (const char*)ServerMethod.mb_str(wxConvUTF8)); - - } - - // Try SSL first. - - if (ServerSSL){ - - wxString ServerCertFilename; - bool MatchingCert = FALSE; - - curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0); - curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY); - curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60); - curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE); - curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT); - curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc); - curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData); - curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader); - curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this); - curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc); - curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1); - - if (UploadMode == TRUE){ - - UploadData.readptr = &ServerUploadData; - UploadData.sizeleft = ServerUploadData.Len(); - curl_easy_setopt(conn, CURLOPT_UPLOAD, 1); - curl_easy_setopt(conn, CURLOPT_READDATA, &UploadData); - curl_easy_setopt(conn, CURLOPT_READFUNCTION, UploadReadFunc); - - } - -#if defined(__APPLE__) || defined(__WIN32__) - -#else - - ServerCertFilename = GetAccountDir(ServerAccount, TRUE); - - if (wxFile::Exists(ServerCertFilename) == TRUE){ - - curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 1); - curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 2); - curl_easy_setopt(conn, CURLOPT_CAINFO, (const char*)ServerCertFilename.mb_str(wxConvUTF8)); - - } - -#endif - - claconncode = (curl_easy_perform(conn)); - - // If CURLE_PEER_FAILED_VERIFICATION is returned, retry without - // the local certificate in use. - - if (claconncode == CURLE_PEER_FAILED_VERIFICATION){ - - curl_easy_cleanup(conn); - conn = curl_easy_init(); - - curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0); - curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY); - curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60); - curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE); - curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT); - curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc); - curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData); - curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader); - curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this); - curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc); - curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1); - - if (UploadMode == TRUE){ - - UploadData.readptr = &ServerUploadData; - UploadData.sizeleft = ServerUploadData.Len(); - curl_easy_setopt(conn, CURLOPT_UPLOAD, 1); - curl_easy_setopt(conn, CURLOPT_READDATA, &UploadData); - curl_easy_setopt(conn, CURLOPT_READFUNCTION, UploadReadFunc); - - } - - claconncode = (curl_easy_perform(conn)); - - // If claconncode is CURLE_OK then delete the certificate file as that - // is no longer needed. - - if (claconncode == CURLE_OK){ - - // Delete the certificate file. - - wxRemoveFile(ServerCertFilename); - - } - - } - - // Check if it fails with a CURLE_SSL_CACERT then compare - // the certificates as PEM files. - -#if defined(__APPLE__) - -#else - - if (claconncode == CURLE_SSL_CACERT && wxFile::Exists(ServerCertFilename) == TRUE){ - - CURL *sslerrconn; - sslerrconn = curl_easy_init(); - CURLcode sslerrconncode; - - wxString ServerAddressOnly = wxT("https://") + ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/"); - - curl_easy_setopt(sslerrconn, CURLOPT_URL, (const char*)ServerAddressOnly.mb_str(wxConvUTF8)); - curl_easy_setopt(sslerrconn, CURLOPT_NOPROGRESS, 0); - curl_easy_setopt(sslerrconn, CURLOPT_HTTPAUTH, CURLAUTH_ANY); - curl_easy_setopt(sslerrconn, CURLOPT_TIMEOUT, 60); - curl_easy_setopt(sslerrconn, CURLOPT_FAILONERROR, TRUE); - curl_easy_setopt(sslerrconn, CURLOPT_USERAGENT, XSDAB_USERAGENT); - curl_easy_setopt(sslerrconn, CURLOPT_WRITEFUNCTION, WritebackFunc); - curl_easy_setopt(sslerrconn, CURLOPT_WRITEDATA, &PageData); - curl_easy_setopt(sslerrconn, CURLOPT_WRITEHEADER, &PageHeader); - curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSDATA, this); - curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSFUNCTION, ProgressFunc); - curl_easy_setopt(sslerrconn, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(sslerrconn, CURLOPT_SSL_VERIFYPEER, 0); - curl_easy_setopt(sslerrconn, CURLOPT_CERTINFO, 1); - - wxString SSLLocalData; - wxString SSLServerData; - - sslerrconncode = (curl_easy_perform(sslerrconn)); - - SSLCertCol = BuildSSLCollection(sslerrconn); - std::map::iterator SSLCDIter = SSLCertCol.SSLCollection.find(0); - std::multimap::iterator SSLDataIter = SSLCDIter->second.CertData.find(wxT("Cert")); - - wxFFile SSLLocalFile; - -#if wxABI_VERSION < 20900 - SSLLocalFile.Open(ServerCertFilename.c_str(), wxT("r")); -#else - SSLLocalFile.Open(ServerCertFilename, wxT("r")); -#endif - - // Load the recovery database for tasks not done. - - if (SSLLocalFile.IsOpened() == TRUE){ - - // Check if we are using wxWidgets version 2.8 or less and - // execute the required command accordingly. - - SSLLocalFile.ReadAll(&SSLLocalData, wxConvAuto()); - - - } - - SSLServerData = SSLDataIter->second; - - if (SSLLocalData == SSLServerData){ - - // Server key matches with local key so retry with CURLOPT_SSL_VERIFYPEER - // and CURLOPT_SSL_VERIFYHOST off. - - curl_easy_cleanup(conn); - conn = curl_easy_init(); - - PageData.clear(); - PageHeader.clear(); - - curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0); - curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY); - curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60); - curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE); - curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT); - curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc); - curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData); - curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader); - curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this); - curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc); - curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1); - - if (UploadMode == TRUE){ - - UploadData.readptr = &ServerUploadData; - UploadData.sizeleft = ServerUploadData.Len(); - curl_easy_setopt(conn, CURLOPT_UPLOAD, 1); - curl_easy_setopt(conn, CURLOPT_READDATA, &UploadData); - curl_easy_setopt(conn, CURLOPT_READFUNCTION, UploadReadFunc); - - } - - curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 0); - curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 0); - - claconncode = (curl_easy_perform(conn)); - - MatchingCert = TRUE; - - } - - if (MatchingCert == FALSE){ - - claconncode = CURLE_SSL_CACERT; - return; - - } - - curl_easy_cleanup(sslerrconn); - - } - -#endif - - // Sort out SSL error. - - // When SSL cert error occurs, connect again and fetch certificates. - // Display a message to the user explaining that an invalid - // certificate has been given and let the user decide what - // to do next. - - if (claconncode == CURLE_OK){ - - } else if (claconncode == CURLE_SSL_CACERT || claconncode == CURLE_PEER_FAILED_VERIFICATION){ - - CURL *sslerrconn; - sslerrconn = curl_easy_init(); - CURLcode sslerrconncode; - - wxString ServerAddressOnly = wxT("https://") + ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/"); - - // Replace conn with sslerrconn! - - curl_easy_setopt(sslerrconn, CURLOPT_URL, (const char*)ServerAddressOnly.mb_str(wxConvUTF8)); - curl_easy_setopt(sslerrconn, CURLOPT_NOPROGRESS, 0); - curl_easy_setopt(sslerrconn, CURLOPT_HTTPAUTH, CURLAUTH_ANY); - curl_easy_setopt(sslerrconn, CURLOPT_TIMEOUT, 60); - curl_easy_setopt(sslerrconn, CURLOPT_FAILONERROR, TRUE); - curl_easy_setopt(sslerrconn, CURLOPT_USERAGENT, XSDAB_USERAGENT); - curl_easy_setopt(sslerrconn, CURLOPT_WRITEFUNCTION, WritebackFunc); - curl_easy_setopt(sslerrconn, CURLOPT_WRITEDATA, &PageData); - curl_easy_setopt(sslerrconn, CURLOPT_WRITEHEADER, &PageHeader); - curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSDATA, this); - curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSFUNCTION, ProgressFunc); - curl_easy_setopt(sslerrconn, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(sslerrconn, CURLOPT_SSL_VERIFYPEER, 0); - curl_easy_setopt(sslerrconn, CURLOPT_CERTINFO, 1); - -#if defined(__APPLE__) - - SetConnectionObject(sslerrconn); - -#endif - - sslerrconncode = (curl_easy_perform(sslerrconn)); - -#if defined(__APPLE__) - -#else - - SSLCertCol = BuildSSLCollection(sslerrconn); - SSLCertCol.SuccessCode = 1; - -#endif - - return; - - } else if (claconncode == CURLE_HTTP_RETURNED_ERROR){ - - fprintf(stderr, "ProcessDataThrad(): curl_easy_perform() failed: %s\n", - curl_easy_strerror(claconncode)); - int http_code = 0; - curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &http_code); - fprintf(stderr, "Error code was: %d\n", http_code); - - return; - - } else { - - fprintf(stderr, "curl_easy_perform() failed: %s\n", - curl_easy_strerror(claconncode)); - int http_code = 0; - curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &http_code); - fprintf(stderr, "Error code was: %d\n", http_code); - - return; - - } - - } else { - - // No SSL. - - curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressNormal.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0); - curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY); - curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60); - curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE); - curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT); - curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc); - curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData); - curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader); - curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this); - curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc); - curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1); - - if (UploadMode == TRUE){ - - UploadData.readptr = &ServerUploadData; - UploadData.sizeleft = ServerUploadData.Len(); - curl_easy_setopt(conn, CURLOPT_UPLOAD, 1); - curl_easy_setopt(conn, CURLOPT_READDATA, &UploadData); - curl_easy_setopt(conn, CURLOPT_READFUNCTION, UploadReadFunc); - - } - - conncode = (curl_easy_perform(conn)); - - if (conncode == CURLE_OK){ - - // Process the server header response and look for - // 'addressbook' within the DAV header. - - wxStringTokenizer wxSHeaderLines(PageHeader, wxT("\r\n")); - wxString wxSHeaderLine; - std::map DAVHeaderLines; - - while (wxSHeaderLines.HasMoreTokens()){ - - wxSHeaderLine = wxSHeaderLines.GetNextToken(); - - if (wxSHeaderLine.Mid(0, 5) == wxT("ETag:")){ - - ETagData = wxSHeaderLine.Mid(5); - ETagData.Trim(); - ETagData.Trim(FALSE); - - // Check for commas. - - if (ETagData.Mid(0, 1) == wxT("\"") && ETagData.Mid((ETagData.Len() - 1), 1) == wxT("\"")){ - - ETagData.Remove(0, 1); - ETagData.RemoveLast(); - - } - - } - - if (wxSHeaderLine.Mid(0, 4) == wxT("DAV:")){ - - // Look for address book in the line. - - if (wxSHeaderLine.Find(wxT("addressbook")) != wxNOT_FOUND){ - - HasCalDAVSupport = TRUE; - - } - - } - - } - - // Get the ETag from the header. - - if (UploadMode == TRUE){ - - wxString PageHeaderLine; - - wxStringTokenizer PageHeaderSplit(PageHeader, wxT("\r\n")); - - if (PageHeaderSplit.HasMoreTokens()){ - - PageHeaderLine = PageHeaderSplit.GetNextToken(); - - } - - } - - ActIter->second = 4; - return; - - } else if (conncode == CURLE_HTTP_RETURNED_ERROR){ - - curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode); - - fprintf(stderr, "curl_easy_perform() failed: %s\n", - curl_easy_strerror(conncode)); - - fprintf(stderr, "curl_easy_perform() HTTP code was: %i\n", - GetHTTPCode()); - - ActIter->second = 2; - return; - - } else { - - fprintf(stderr, "curl_easy_perform() failed: %s\n", - curl_easy_strerror(conncode)); - - ActIter->second = 2; - return; - - } - - } - - // Catch all. - - *ServerResult = TRUE; - return; - -} - -void CardDAV::ProcessData(){ - - // Process the data. - - std::thread ConnectThread(&CardDAV::ProcessDataThread, this); - ConnectThread.detach(); - -} \ No newline at end of file diff --git a/source/carddav/carddav-servercontact.cpp b/source/carddav/carddav-servercontact.cpp deleted file mode 100644 index a3c70c3..0000000 --- a/source/carddav/carddav-servercontact.cpp +++ /dev/null @@ -1,376 +0,0 @@ -// carddav-servercontact.cpp - CardDAV Object - Server Contact subroutines. -// -// (c) 2012-2015 Xestia Software Development. -// -// This file is part of Xestia Address Book. -// -// Xestia Address Book is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by the -// Free Software Foundation, version 3 of the license. -// -// Xestia Address Book is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License along -// with Xestia Address Book. If not, see - -#include "carddav.h" -#include "../version.h" -#include -#include -#include -#include -#include -#include -#include -#include "../vcard/vcard.h" -#include "../common/dirs.h" - -void CardDAV::GetServerContactData() -{ - - // Get the server contact data. - - PageData.Clear(); - PageHeader.Clear(); - - SSLStatus = TRUE; - AuthPassed = TRUE; - AbortConnection = FALSE; - - wxString ServerCertFilename; - bool MatchingCert = FALSE; - - CURL *conn; - CURLcode conncode; - wxString ServerAddressURL; - wxString ServerAuth; - wxString ServerAddressSSL; - wxString ServerAddressNormal; - - conn = curl_easy_init(); - -#if defined(__APPLE__) - - SetConnectionObject(conn); - -#endif - - struct CardDAVCURLPasser { - - CardDAV *Data; - bool HeaderMode = TRUE; - - } CardDAVHeader, CardDAVFooter; - - CardDAVHeader.Data = this; - CardDAVHeader.HeaderMode = TRUE; - - CardDAVFooter.Data = this; - CardDAVFooter.HeaderMode = FALSE; - - wxString Data1; - wxString Data2; - - ServerAddressURL = ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/") + ServerPrefix + ServerFilenameLocation; - ServerAddressSSL = wxT("https://") + ServerAddressURL; - ServerAddressNormal = wxT("http://") + ServerAddressURL; - - ServerAuth = ServerUser + wxT(":") + ServerPass; - - std::map::iterator ActIter; - struct UploadDataStruc UploadData; - - ActIter = ActivityListPtr->find((int)ItemIndex); - - // Try SSL first. - - if (ServerSSL){ - - curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L); - curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY); - curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60); - curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE); - curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT); - curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc); - curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData); - curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader); - curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1); - -#if defined(__APPLE__) || defined(__WIN32__) - -#else - - ServerCertFilename = GetAccountDir(ServerAccount, TRUE); - - if (wxFile::Exists(ServerCertFilename) == TRUE){ - - curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 1); - curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 2); - curl_easy_setopt(conn, CURLOPT_CAINFO, (const char*)ServerCertFilename.mb_str(wxConvUTF8)); - - } - -#endif - - claconncode = (curl_easy_perform(conn)); - - // If CURLE_PEER_FAILED_VERIFICATION is returned, retry without - // the local certificate in use. - - if (claconncode == CURLE_PEER_FAILED_VERIFICATION){ - - curl_easy_cleanup(conn); - conn = curl_easy_init(); - - curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L); - curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY); - curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60); - curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE); - curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT); - curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc); - curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData); - curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader); - curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1); - - claconncode = (curl_easy_perform(conn)); - - // If claconncode is CURLE_OK then delete the certificate file as that - // is no longer needed. - - if (claconncode == CURLE_OK){ - - // Delete the certificate file. - - wxRemoveFile(ServerCertFilename); - - } - - } - - // Check if it fails with a CURLE_SSL_CACERT then compare - // the certificates as PEM files. - -#if defined(__APPLE__) - -#else - - if (claconncode == CURLE_SSL_CACERT && wxFile::Exists(ServerCertFilename) == TRUE){ - - CURL *sslerrconn; - sslerrconn = curl_easy_init(); - CURLcode sslerrconncode; - - wxString ServerAddressOnly = wxT("https://") + ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/"); - - curl_easy_setopt(sslerrconn, CURLOPT_URL, (const char*)ServerAddressOnly.mb_str(wxConvUTF8)); - curl_easy_setopt(sslerrconn, CURLOPT_NOPROGRESS, 1L); - curl_easy_setopt(sslerrconn, CURLOPT_HTTPAUTH, CURLAUTH_ANY); - curl_easy_setopt(sslerrconn, CURLOPT_TIMEOUT, 60); - curl_easy_setopt(sslerrconn, CURLOPT_FAILONERROR, TRUE); - curl_easy_setopt(sslerrconn, CURLOPT_USERAGENT, XSDAB_USERAGENT); - curl_easy_setopt(sslerrconn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8)); - curl_easy_setopt(sslerrconn, CURLOPT_WRITEFUNCTION, WritebackFunc); - curl_easy_setopt(sslerrconn, CURLOPT_WRITEDATA, &PageData); - curl_easy_setopt(sslerrconn, CURLOPT_WRITEHEADER, &PageHeader); - curl_easy_setopt(sslerrconn, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(sslerrconn, CURLOPT_SSL_VERIFYPEER, 0); - curl_easy_setopt(sslerrconn, CURLOPT_SSL_VERIFYHOST, 0); - curl_easy_setopt(sslerrconn, CURLOPT_CERTINFO, 1); - - wxString SSLLocalData; - wxString SSLServerData; - - sslerrconncode = (curl_easy_perform(sslerrconn)); - - SSLCertCol = BuildSSLCollection(sslerrconn); - std::map::iterator SSLCDIter = SSLCertCol.SSLCollection.find(0); - std::multimap::iterator SSLDataIter = SSLCDIter->second.CertData.find(wxT("Cert")); - - wxFFile SSLLocalFile; - -#if wxABI_VERSION < 20900 - SSLLocalFile.Open(ServerCertFilename.c_str(), wxT("r")); -#else - SSLLocalFile.Open(ServerCertFilename, wxT("r")); -#endif - - // Load the recovery database for tasks not done. - - if (SSLLocalFile.IsOpened() == TRUE){ - - SSLLocalFile.ReadAll(&SSLLocalData, wxConvAuto()); - - - } - - SSLServerData = SSLDataIter->second; - - if (SSLLocalData == SSLServerData){ - - // Server key matches with local key so retry with CURLOPT_SSL_VERIFYPEER - // and CURLOPT_SSL_VERIFYHOST off. - - curl_easy_cleanup(conn); - conn = curl_easy_init(); - - PageData.clear(); - PageHeader.clear(); - - curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L); - curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY); - curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60); - curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE); - curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT); - curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc); - curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData); - curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader); - curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 0); - curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 0); - - claconncode = (curl_easy_perform(conn)); - - MatchingCert = TRUE; - - } - - if (MatchingCert == FALSE){ - - claconncode = CURLE_SSL_CACERT; - return; - - } - - curl_easy_cleanup(sslerrconn); - - } - -#endif - - // Sort out SSL error. - - // When SSL cert error occurs, connect again and fetch certificates. - // Display a message to the user explaining that an invalid - // certificate has been given and let the user decide what - // to do next. - - if (claconncode == CURLE_OK){ - - } else if (claconncode == CURLE_SSL_CACERT || claconncode == CURLE_PEER_FAILED_VERIFICATION){ - - CURL *sslerrconn; - sslerrconn = curl_easy_init(); - CURLcode sslerrconncode; - - wxString ServerAddressOnly = wxT("https://") + ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/"); - - // Replace conn with sslerrconn! - - curl_easy_setopt(sslerrconn, CURLOPT_URL, (const char*)ServerAddressOnly.mb_str(wxConvUTF8)); - curl_easy_setopt(sslerrconn, CURLOPT_NOPROGRESS, 0); - curl_easy_setopt(sslerrconn, CURLOPT_HTTPAUTH, CURLAUTH_ANY); - curl_easy_setopt(sslerrconn, CURLOPT_TIMEOUT, 60); - curl_easy_setopt(sslerrconn, CURLOPT_FAILONERROR, TRUE); - curl_easy_setopt(sslerrconn, CURLOPT_USERAGENT, XSDAB_USERAGENT); - curl_easy_setopt(sslerrconn, CURLOPT_WRITEFUNCTION, WritebackFunc); - curl_easy_setopt(sslerrconn, CURLOPT_WRITEDATA, &PageData); - curl_easy_setopt(sslerrconn, CURLOPT_WRITEHEADER, &PageHeader); - curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSDATA, this); - curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSFUNCTION, ProgressFunc); - curl_easy_setopt(sslerrconn, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(sslerrconn, CURLOPT_SSL_VERIFYPEER, 0); - curl_easy_setopt(sslerrconn, CURLOPT_CERTINFO, 1); - -#if defined(__APPLE__) - - SetConnectionObject(sslerrconn); - -#endif - - sslerrconncode = (curl_easy_perform(sslerrconn)); - - SSLCertCol = BuildSSLCollection(sslerrconn); - SSLCertCol.SuccessCode = 1; - - return; - - } else if (claconncode == CURLE_HTTP_RETURNED_ERROR){ - - fprintf(stderr, "curl_easy_perform() failed: %s\n", - curl_easy_strerror(claconncode)); - int http_code = 0; - curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &http_code); - fprintf(stderr, "Error code was: %d\n", http_code); - - return; - - } else { - - fprintf(stderr, "curl_easy_perform() failed: %s\n", - curl_easy_strerror(claconncode)); - int http_code = 0; - curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &http_code); - fprintf(stderr, "Error code was: %d\n", http_code); - - return; - - } - - } else { - - // No SSL. - - wxString EmptyString; - - curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressNormal.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L); - curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY); - curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60); - curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE); - curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT); - curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc); - curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData); - curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader); - curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1); - - PageData.Clear(); - PageHeader.Clear(); - - conncode = (curl_easy_perform(conn)); - - if (conncode == CURLE_OK){ - - } else if (conncode == CURLE_HTTP_RETURNED_ERROR){ - - fprintf(stderr, "curl_easy_perform() failed: %s\n", - curl_easy_strerror(conncode)); - - fprintf(stderr, "curl_easy_perform() HTTP code was: %i\n", - GetHTTPCode()); - - return; - - } else { - - fprintf(stderr, "curl_easy_perform() failed: %s\n", - curl_easy_strerror(conncode)); - - return; - - } - - } - - return; - -} \ No newline at end of file diff --git a/source/carddav/carddav-serveretag.cpp b/source/carddav/carddav-serveretag.cpp deleted file mode 100644 index 8784218..0000000 --- a/source/carddav/carddav-serveretag.cpp +++ /dev/null @@ -1,579 +0,0 @@ -// carddav-serveretag.cpp - CardDAV Object - Server ETag subroutines. -// -// (c) 2012-2015 Xestia Software Development. -// -// This file is part of Xestia Address Book. -// -// Xestia Address Book is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by the -// Free Software Foundation, version 3 of the license. -// -// Xestia Address Book is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License along -// with Xestia Address Book. If not, see - -#include "carddav.h" -#include "../version.h" -#include -#include -#include -#include -#include -#include -#include -#include "../vcard/vcard.h" -#include "../common/dirs.h" - -void CardDAV::GetServerETagValueThread() -{ - - // Get the server etag value (threaded). - - PageData.Clear(); - PageHeader.Clear(); - - SSLStatus = TRUE; - AuthPassed = TRUE; - AbortConnection = FALSE; - - bool FilenameIsDirectory = FALSE; - CURL *conn; - CURLcode conncode; - wxString ServerAddressURL; - wxString ServerAuth; - wxString ServerAddressSSL; - wxString ServerAddressNormal; - - conn = curl_easy_init(); - -#if defined(__APPLE__) - - SetConnectionObject(conn); - -#endif - - struct CardDAVCURLPasser { - - CardDAV *Data; - bool HeaderMode = TRUE; - - } CardDAVHeader, CardDAVFooter; - - CardDAVHeader.Data = this; - CardDAVHeader.HeaderMode = TRUE; - - CardDAVFooter.Data = this; - CardDAVFooter.HeaderMode = FALSE; - - wxString Data1; - wxString Data2; - - ServerAddressURL = ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + ServerPrefix + ServerFilenameLocation; - ServerAddressSSL = wxT("https://") + ServerAddressURL; - ServerAddressNormal = wxT("http://") + ServerAddressURL; - - ServerAuth = ServerUser + wxT(":") + ServerPass; - - std::map::iterator ActIter; - struct UploadDataStruc UploadData; - - - ActIter = ActivityListPtr->find((int)ItemIndex); - - static const char* query = - "" - "" - "" - "" - "" - ""; - - if (ServerSSL){ - - wxString ServerCertFilename; - bool MatchingCert = FALSE; - - curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0); - curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY); - curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60); - curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE); - curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT); - curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc); - curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData); - curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader); - curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this); - curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc); - curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "REPORT"); - curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query); - curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query)); - -#if defined(__APPLE__) || defined(__WIN32__) - -#else - - ServerCertFilename = GetAccountDir(ServerAccount, TRUE); - - if (wxFile::Exists(ServerCertFilename) == TRUE){ - - curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 1); - curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 2); - curl_easy_setopt(conn, CURLOPT_CAINFO, (const char*)ServerCertFilename.mb_str(wxConvUTF8)); - - } - -#endif - - claconncode = (curl_easy_perform(conn)); - - // If CURLE_PEER_FAILED_VERIFICATION is returned, retry without - // the local certificate in use. - - if (claconncode == CURLE_PEER_FAILED_VERIFICATION){ - - curl_easy_cleanup(conn); - conn = curl_easy_init(); - - curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0); - curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY); - curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60); - curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE); - curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT); - curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc); - curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData); - curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader); - curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this); - curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc); - curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "REPORT"); - curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query); - curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query)); - - claconncode = (curl_easy_perform(conn)); - - // If claconncode is CURLE_OK then delete the certificate file as that - // is no longer needed. - - if (claconncode == CURLE_OK){ - - // Delete the certificate file. - - wxRemoveFile(ServerCertFilename); - - } - - } - - // Check if it fails with a CURLE_SSL_CACERT then compare - // the certificates as PEM files. - -#if defined(__APPLE__) - -#else - - if (claconncode == CURLE_SSL_CACERT && wxFile::Exists(ServerCertFilename) == TRUE){ - - CURL *sslerrconn; - sslerrconn = curl_easy_init(); - CURLcode sslerrconncode; - - wxString ServerAddressOnly = wxT("https://") + ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/"); - - PageData.clear(); - PageHeader.clear(); - - curl_easy_setopt(sslerrconn, CURLOPT_URL, (const char*)ServerAddressOnly.mb_str(wxConvUTF8)); - curl_easy_setopt(sslerrconn, CURLOPT_NOPROGRESS, 0); - curl_easy_setopt(sslerrconn, CURLOPT_HTTPAUTH, CURLAUTH_ANY); - curl_easy_setopt(sslerrconn, CURLOPT_TIMEOUT, 60); - curl_easy_setopt(sslerrconn, CURLOPT_FAILONERROR, TRUE); - curl_easy_setopt(sslerrconn, CURLOPT_USERAGENT, XSDAB_USERAGENT); - curl_easy_setopt(sslerrconn, CURLOPT_WRITEFUNCTION, WritebackFunc); - curl_easy_setopt(sslerrconn, CURLOPT_WRITEDATA, &PageData); - curl_easy_setopt(sslerrconn, CURLOPT_WRITEHEADER, &PageHeader); - curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSDATA, this); - curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSFUNCTION, ProgressFunc); - curl_easy_setopt(sslerrconn, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(sslerrconn, CURLOPT_SSL_VERIFYPEER, 0); - curl_easy_setopt(sslerrconn, CURLOPT_CERTINFO, 1); - curl_easy_setopt(sslerrconn, CURLOPT_SSL_VERIFYPEER, 1); - curl_easy_setopt(sslerrconn, CURLOPT_SSL_VERIFYHOST, 2); - curl_easy_setopt(sslerrconn, CURLOPT_CAINFO, (const char*)ServerCertFilename.mb_str(wxConvUTF8)); - - wxString SSLLocalData; - wxString SSLServerData; - - sslerrconncode = (curl_easy_perform(sslerrconn)); - - SSLCertCol = BuildSSLCollection(sslerrconn); - std::map::iterator SSLCDIter = SSLCertCol.SSLCollection.find(0); - std::multimap::iterator SSLDataIter = SSLCDIter->second.CertData.find(wxT("Cert")); - - wxFFile SSLLocalFile; - -#if wxABI_VERSION < 20900 - SSLLocalFile.Open(ServerCertFilename.c_str(), wxT("r")); -#else - SSLLocalFile.Open(ServerCertFilename, wxT("r")); -#endif - - // Load the recovery database for tasks not done. - - if (SSLLocalFile.IsOpened() == TRUE){ - - // Check if we are using wxWidgets version 2.8 or less and - // execute the required command accordingly. - - SSLLocalFile.ReadAll(&SSLLocalData, wxConvAuto()); - - - } - - SSLServerData = SSLDataIter->second; - - if (SSLLocalData == SSLServerData){ - - // Server key matches with local key so retry with CURLOPT_SSL_VERIFYPEER - // and CURLOPT_SSL_VERIFYHOST off. - - curl_easy_cleanup(conn); - conn = curl_easy_init(); - - PageData.clear(); - PageHeader.clear(); - - curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0); - curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY); - curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60); - curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE); - curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT); - curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc); - curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData); - curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader); - curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this); - curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc); - curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "REPORT"); - curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query); - curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query)); - curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 0); - curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 0); - - claconncode = (curl_easy_perform(conn)); - - MatchingCert = TRUE; - - } - - if (MatchingCert == FALSE){ - - claconncode = CURLE_SSL_CACERT; - return; - - } - - curl_easy_cleanup(sslerrconn); - - } - -#endif - - // Sort out SSL error. - - // When SSL cert error occurs, connect again and fetch certificates. - // Display a message to the user explaining that an invalid - // certificate has been given and let the user decide what - // to do next. - - if (claconncode == CURLE_OK){ - - } else if (claconncode == CURLE_SSL_CACERT || claconncode == CURLE_PEER_FAILED_VERIFICATION){ - - CURL *sslerrconn; - sslerrconn = curl_easy_init(); - CURLcode sslerrconncode; - - wxString ServerAddressOnly = wxT("https://") + ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/"); - - // Replace conn with sslerrconn! - - curl_easy_setopt(sslerrconn, CURLOPT_URL, (const char*)ServerAddressOnly.mb_str(wxConvUTF8)); - curl_easy_setopt(sslerrconn, CURLOPT_NOPROGRESS, 0); - curl_easy_setopt(sslerrconn, CURLOPT_HTTPAUTH, CURLAUTH_ANY); - curl_easy_setopt(sslerrconn, CURLOPT_TIMEOUT, 60); - curl_easy_setopt(sslerrconn, CURLOPT_FAILONERROR, TRUE); - curl_easy_setopt(sslerrconn, CURLOPT_USERAGENT, XSDAB_USERAGENT); - curl_easy_setopt(sslerrconn, CURLOPT_WRITEFUNCTION, WritebackFunc); - curl_easy_setopt(sslerrconn, CURLOPT_WRITEDATA, &PageData); - curl_easy_setopt(sslerrconn, CURLOPT_WRITEHEADER, &PageHeader); - curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSDATA, this); - curl_easy_setopt(sslerrconn, CURLOPT_PROGRESSFUNCTION, ProgressFunc); - curl_easy_setopt(sslerrconn, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(sslerrconn, CURLOPT_SSL_VERIFYPEER, 0); - curl_easy_setopt(sslerrconn, CURLOPT_CERTINFO, 1); - - sslerrconncode = (curl_easy_perform(sslerrconn)); - -#if defined(__APPLE__) - - SetConnectionObject(sslerrconn); - -#endif - - SSLCertCol = BuildSSLCollection(sslerrconn); - SSLCertCol.SuccessCode = 1; - - curl_easy_cleanup(conn); - curl_easy_cleanup(sslerrconn); - - return; - - } else if (claconncode == CURLE_HTTP_RETURNED_ERROR){ - - fprintf(stderr, "GetServerETagValueThread(): curl_easy_perform() failed: %s\n", - curl_easy_strerror(claconncode)); - int http_code = 0; - curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &http_code); - fprintf(stderr, "Error code was: %d\n", http_code); - - curl_easy_cleanup(conn); - - return; - - } else { - - fprintf(stderr, "GetServerETagValueThread(): curl_easy_perform() failed: %s\n", - curl_easy_strerror(claconncode)); - int http_code = 0; - curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &http_code); - fprintf(stderr, "Error code was: %d\n", http_code); - - curl_easy_cleanup(conn); - - return; - - } - - } else { - - // No SSL. - - wxString EmptyString; - - curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressNormal.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0); - curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY); - curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60); - curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE); - curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT); - curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc); - curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData); - curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader); - curl_easy_setopt(conn, CURLOPT_PROGRESSDATA, this); - curl_easy_setopt(conn, CURLOPT_PROGRESSFUNCTION, ProgressFunc); - curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "REPORT"); - curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query); - curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query)); - - PageData.Clear(); - PageHeader.Clear(); - - conncode = (curl_easy_perform(conn)); - - if (conncode == CURLE_OK){ - - } else if (conncode == CURLE_HTTP_RETURNED_ERROR){ - - fprintf(stderr, "curl_easy_perform() failed: %s\n", - curl_easy_strerror(conncode)); - - return; - - } else { - - fprintf(stderr, "curl_easy_perform() failed: %s\n", - curl_easy_strerror(conncode)); - - return; - - } - - } - - xmlDocPtr xmlCardDAVDoc; - - xmlCardDAVDoc = xmlReadMemory(PageData.mb_str(wxConvUTF8), (int)PageData.Len(), "noname.xml", NULL, 0); - - xmlNodePtr nodeLevel1; - xmlNodePtr nodeLevel2; - xmlNodePtr nodeLevel3; - xmlNodePtr nodeLevel4; - xmlNodePtr nodeLevel5; - xmlNodePtr nodeLevel6; - - std::map xmlDataMap; - - wxString DataFilename; - wxString ETagData; - - std::string xmlStringSafe; - - // Tranverse through the catacombs of the response to get our ETag for the file. - - for (nodeLevel1 = xmlCardDAVDoc->children; - nodeLevel1 != NULL; - nodeLevel1 = nodeLevel1->next) - { - - bool HREFFound = FALSE; - bool ETagFound = FALSE; - - for (nodeLevel2 = nodeLevel1->children; - nodeLevel2 != NULL; - nodeLevel2 = nodeLevel2->next) - { - - for (nodeLevel3 = nodeLevel2->children; - nodeLevel3 != NULL; - nodeLevel3 = nodeLevel3->next) - { - - if (!xmlStrcmp(nodeLevel3->name, (const xmlChar *)"href") || - !xmlStrcmp(nodeLevel3->name, (const xmlChar *)"d:href") || - !xmlStrcmp(nodeLevel3->name, (const xmlChar *)"D:href") - ){ - - // Get the filename. - - for (nodeLevel4 = nodeLevel3->children; - nodeLevel4 != NULL; - nodeLevel4 = nodeLevel4->next) - { - - if (!xmlStrcmp(nodeLevel4->name, (const xmlChar *)"text") || - !xmlStrcmp(nodeLevel4->name, (const xmlChar *)"d:text") || - !xmlStrcmp(nodeLevel4->name, (const xmlChar *)"D:text") - ){ - - DataFilename = wxString::FromUTF8((const char*)nodeLevel4->content); - wxStringTokenizer wSTDFilename(DataFilename, wxT("/")); - - while (wSTDFilename.HasMoreTokens()){ - - DataFilename = wSTDFilename.GetNextToken(); - - } - - HREFFound = TRUE; - - } - - - - } - - } else { - - for (nodeLevel4 = nodeLevel3->children; - nodeLevel4 != NULL; - nodeLevel4 = nodeLevel4->next) - { - - for (nodeLevel5 = nodeLevel4->children; - nodeLevel5 != NULL; - nodeLevel5 = nodeLevel5->next) - { - - if (!xmlStrcmp(nodeLevel5->name, (const xmlChar *)"getetag") || - !xmlStrcmp(nodeLevel5->name, (const xmlChar *)"d:getetag") || - !xmlStrcmp(nodeLevel5->name, (const xmlChar *)"D:getetag") - ){ - - for (nodeLevel6 = nodeLevel5->children; - nodeLevel6 != NULL; - nodeLevel6 = nodeLevel6->next) - { - - // Strip the quotes from the ETag. - - ETagData = wxString::FromUTF8((const char*)nodeLevel6->content); - if (ETagData.Mid(0, 1) == wxT("\"") && ETagData.Mid((ETagData.Len() - 1), 1) == wxT("\"")){ - - ETagData.Remove(0, 1); - ETagData.RemoveLast(); - - } - - ETagFound = TRUE; - - } - - } - - } - - } - - } - - } - - } - - if (HREFFound == TRUE && ETagFound == TRUE){ - - // Add to the map data. - - xmlDataMap.insert(std::make_pair(DataFilename, ETagData)); - - HREFFound = FALSE; - ETagFound = FALSE; - - } - - - } - - xmlFreeDoc(xmlCardDAVDoc); - - // Get the first result. - - for (std::map::iterator iter = xmlDataMap.begin(); - iter != xmlDataMap.end(); ++iter){ - - ETagResult = iter->second; - break; - - } - - if (ETagResult.IsEmpty()){ - - return; - - } - - return; - -} - -void CardDAV::GetServerETagValue(){ - - // Get the server etag value. - - std::thread ConnectThread(&CardDAV::GetServerETagValueThread, this); - ConnectThread.detach(); - -} \ No newline at end of file diff --git a/source/carddav/carddav-sslverify.cpp b/source/carddav/carddav-sslverify.cpp deleted file mode 100644 index c082a90..0000000 --- a/source/carddav/carddav-sslverify.cpp +++ /dev/null @@ -1,181 +0,0 @@ -// carddav-sslverify.cpp - CardDAV Object - SSL verification subroutines. -// -// (c) 2012-2015 Xestia Software Development. -// -// This file is part of Xestia Address Book. -// -// Xestia Address Book is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by the -// Free Software Foundation, version 3 of the license. -// -// Xestia Address Book is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License along -// with Xestia Address Book. If not, see - -#include "carddav.h" -#include "../version.h" -#include -#include -#include -#include -#include -#include -#include -#include "../vcard/vcard.h" -#include "../common/dirs.h" - -CURLcode CardDAV::SSLVerifyTest(){ - - // Verify the SSL information. - - PageData.Clear(); - PageHeader.Clear(); - - SSLStatus = TRUE; - AuthPassed = TRUE; - AbortConnection = FALSE; - - CURL *conn; - CURL *connssldata; - CURLcode conncode = CURLE_OK; - wxString ServerAddressURL; - wxString ServerAuth; - wxString ServerAddressSSL; - wxString ServerAddressNormal; - - conn = curl_easy_init(); - - wxString Data1; - wxString Data2; - - ServerAddressURL = ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/"); - ServerAddressSSL = wxT("https://") + ServerAddressURL; - - if (ServerSSL){ - - union { - struct curl_slist *certdata; - struct curl_certinfo *certinfo; - } ptr; - - ptr.certdata = NULL; - - // Setup two initial connections and attempt to get the certificate data. - - curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_CERTINFO, 1); - curl_easy_setopt(conn, CURLOPT_VERBOSE, 1L); - curl_easy_setopt(conn, CURLOPT_ERRORBUFFER, curlerrbuffer); - curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc); - curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData); - curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader); - -#if defined(__APPLE__) || defined(__WIN32__) - - SetConnectionObject(conn); - -#else - - if (ServerAccount != ""){ - - wxString ServerCertFilename = GetAccountDir(ServerAccount, TRUE); - - if (wxFile::Exists(ServerCertFilename) == TRUE){ - - curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 1); - curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 2); - curl_easy_setopt(conn, CURLOPT_CAINFO, (const char*)ServerCertFilename.mb_str(wxConvUTF8)); - - } - - } - -#endif - - conncode = (curl_easy_perform(conn)); - - // Check if the SSL certificate is valid or self-signed or some other - // error occured. - - if (conncode == CURLE_OK){ - - // Connection is OK. Do nothing. - - *ServerResult = TRUE; - -#if !defined(__APPLE__) && !defined(__WIN32__) - - VerifyCertCollection = BuildSSLCollection(conn); - -#endif - - } else if (conncode == CURLE_SSL_CACERT || - conncode == CURLE_SSL_CONNECT_ERROR || - conncode == CURLE_PEER_FAILED_VERIFICATION){ - - connssldata = curl_easy_init(); - - // Retry but get the certificates without peer/host verification. - - curl_easy_setopt(connssldata, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8)); - curl_easy_setopt(connssldata, CURLOPT_CERTINFO, 1); - curl_easy_setopt(connssldata, CURLOPT_VERBOSE, 1L); - curl_easy_setopt(connssldata, CURLOPT_ERRORBUFFER, curlerrbuffer); - curl_easy_setopt(connssldata, CURLOPT_WRITEFUNCTION, WritebackFunc); - curl_easy_setopt(connssldata, CURLOPT_WRITEDATA, &PageData); - curl_easy_setopt(connssldata, CURLOPT_WRITEHEADER, &PageHeader); - curl_easy_setopt(connssldata, CURLOPT_SSL_VERIFYPEER, 0L); - curl_easy_setopt(connssldata, CURLOPT_SSL_VERIFYHOST, 0L); - -#if defined(__APPLE__) || defined(__WIN32__) - - SetConnectionObject(connssldata); - -#endif - - CURLcode certfetchcode; - - certfetchcode = (curl_easy_perform(connssldata)); - -#if !defined(__APPLE__) && !defined(__WIN32__) - - VerifyCertCollection = BuildSSLCollection(connssldata); - - if (certfetchcode == CURLE_OK){ - - curl_easy_getinfo(connssldata, CURLINFO_CERTINFO, &ptr.certdata); - - VerifyCertCollection = BuildSSLCollection(connssldata); - - } else { - - conncode = certfetchcode; - - } - -#endif - - *ServerResult = FALSE; - - } else { - - fprintf(stderr, "curl_easy_perform() failed: %s\n", - curl_easy_strerror(conncode)); - - ErrorMessage = wxString::Format(wxT("%s"), curl_easy_strerror(conncode)); - - *ServerResult = FALSE; - - } - - } - - curl_easy_cleanup(conn); - - return conncode; - -} \ No newline at end of file diff --git a/source/carddav/carddav-sslverify.mm b/source/carddav/carddav-sslverify.mm deleted file mode 100644 index c41e092..0000000 --- a/source/carddav/carddav-sslverify.mm +++ /dev/null @@ -1,29 +0,0 @@ -// carddav-sslverify.mm - OS X specific functions for verifying the SSL connection. -// -// (c) 2012-2015 Xestia Software Development. -// -// This file is part of Xestia Address Book. -// -// Xestia Address Book is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by the -// Free Software Foundation, version 3 of the license. -// -// Xestia Address Book is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License along -// with Xestia Address Book. If not, see - -#import - -#include "carddav.h" - -SecTrustRef CardDAV::GetTrustObject(){ - - // Return the Security Trust Reference for the CardDAV object. - - return SecTrustObject; - -} \ No newline at end of file diff --git a/source/carddav/carddav.cpp b/source/carddav/carddav.cpp deleted file mode 100644 index 52ae03a..0000000 --- a/source/carddav/carddav.cpp +++ /dev/null @@ -1,563 +0,0 @@ -// carddav.cpp - Main CardDAV Object file. -// -// (c) 2012-2015 Xestia Software Development. -// -// This file is part of Xestia Address Book. -// -// Xestia Address Book is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by the -// Free Software Foundation, version 3 of the license. -// -// Xestia Address Book is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License along -// with Xestia Address Book. If not, see - -#include "carddav.h" -#include "../version.h" -#include -#include -#include -#include -#include -#include -#include -#include "../vcard/vcard.h" -#include "../common/dirs.h" - -size_t CardDAV::WritebackFunc(char *ptr, size_t size, size_t nmemb, wxString *stream){ - - // Writeback function for the CardDAV object. - - wxString Data; - Data = wxString::FromUTF8((char *)ptr); - - stream->Append(Data); - - // Get the SSL engine pointer and trust if required on certain operating systems. - -#if defined(__APPLE__) - - const struct curl_tlssessioninfo *TLSInfo; - CURLcode TLSCode; - CURL *Connection = GetConnectionObject(); - TLSCode = curl_easy_getinfo(Connection, CURLINFO_TLS_SSL_PTR, &TLSInfo); - - if (TLSInfo->internals != nullptr && TLSCode == CURLE_OK){ - SSLCopyPeerTrust((SSLContext*)TLSInfo->internals, &SecTrustObject); - } - -#elif defined(__WIN32__) - - const struct curl_tlssessioninfo *TLSInfo; - CURLcode TLSCode; - CURL *Connection = GetConnectionObject(); - TLSCode = curl_easy_getinfo(Connection, CURLINFO_TLS_SSL_PTR, &TLSInfo); - - std::string CertName; - - if (TLSInfo->internals != nullptr && TLSCode == CURLE_OK){ - - // Free the previous certificate data. - - CertFreeCertificateContext(CertificateData); - - PCtxtHandle SSLHandle = (PCtxtHandle)TLSInfo->internals; - SECURITY_STATUS GetData = QueryContextAttributes(SSLHandle, SECPKG_ATTR_REMOTE_CERT_CONTEXT, &CertificateData); - - } - -#endif - - return size * nmemb; - -} - -int ProgressFunc(void *clientdata, double TTDown, double NDown, double TTUp, double NUp){ - - // Progress function for the CardDAV object. - - int ProgressRet; - - CardDAV *IncCardDAV = static_cast(clientdata); - ProgressRet = IncCardDAV->ProgressFuncProc(clientdata, TTDown, NDown, TTUp, NUp); - if (ProgressRet != 0){ - return 1; - } - return 0; - -} - -wxString CardDAV::ServerAddress; -int CardDAV::ServerPort; -wxString CardDAV::ServerUser; -wxString CardDAV::ServerPass; -wxString CardDAV::ServerPrefix; -wxString CardDAV::ServerAccount; -bool CardDAV::ServerSSL; -bool *CardDAV::ServerResult; -bool *CardDAV::ServerMonitor; -bool CardDAV::SSLStatus; -bool CardDAV::SSLVerified; -bool CardDAV::ValidResponse; -bool CardDAV::AuthPassed; -bool CardDAV::HasCalDAVSupport; -bool CardDAV::AbortConnection; -wxString CardDAV::ServerResponse; -wxString CardDAV::ServerMethod; -wxString CardDAV::ServerFilenameLocation; -wxString CardDAV::ServerUploadData; -wxString CardDAV::ETagData; -wxString CardDAV::ETagResult; -bool CardDAV::UploadMode; -bool CardDAV::EditMode; -long CardDAV::ItemIndex; -std::map *CardDAV::ActivityListPtr; -char CardDAV::curlerrbuffer[CURL_ERROR_SIZE]; -SSLCertCollection CardDAV::SSLCertCol; -int CardDAV::SSLErrorCode; -int CardDAV::ConnectionErrorCode; -wxString CardDAV::PageHeader; -wxString CardDAV::PageData; -CURLcode CardDAV::claconncode; -int CardDAV::HTTPErrorCode; -wxString CardDAV::ErrorMessage; -SSLCertCollection CardDAV::VerifyCertCollection; -bool CardDAV::AllowSelfSign; -#if defined(__APPLE__) -SSLContext *CardDAV::SSLContextPointer; -SecTrustRef CardDAV::SecTrustObject; -#endif -#if defined(__WIN32__) -PCCERT_CONTEXT CardDAV::CertificateData; -#endif -#if defined(__APPLE__) || defined(__WIN32__) -CURL *CardDAV::ConnectionObject; -#endif - -CardDAV::CardDAV(){ - - // Setup the CardDAV object. - - ServerPort = 8080; - SSLStatus = FALSE; - SSLVerified = FALSE; - AuthPassed = FALSE; - ValidResponse = FALSE; - HasCalDAVSupport = FALSE; - SSLCertCol.SuccessCode = 0; - AllowSelfSign = FALSE; - - AbortConnection = FALSE; - UploadMode = FALSE; - EditMode = FALSE; - HTTPErrorCode = 0; - -} - -CardDAV::~CardDAV(){ - - // Destroy the CardDAV object. - -} - -size_t UploadReadFunc(void *ptr, size_t size, size_t nmemb, void *userdata){ - - - // Upload function for the CardDAV object. - - struct UploadDataStruc *UploadPtr = (struct UploadDataStruc *)userdata; - - if (UploadPtr->sizeleft){ - - //MeepMoop->sizeleft--; - //return 1; - - UploadPtr->sizeleft--; - wxString wxSChar; - - wxSChar = UploadPtr->readptr->Mid(UploadPtr->seek,1); - - //*(char *)ptr = (char)wxSChar.mb_str(); - - strncpy((char *)ptr, (const char*)wxSChar.mb_str(wxConvUTF8), 1); - - UploadPtr->seek++; - - return 1; - - } - - return 0; - -} - -bool CardDAV::SetupConnection(wxString SvrAddress, int SvrPort, wxString SvrUser, wxString SvrPass, bool SvrSSL){ - - // Setup the CardDAV connection without the prefix/account. - - ServerAddress = SvrAddress; - ServerPort = SvrPort; - ServerUser = SvrUser; - ServerPass = SvrPass; - ServerSSL = SvrSSL; - - return TRUE; - -} - -bool CardDAV::SetupConnection(wxString SvrAddress, int SvrPort, wxString SvrUser, wxString SvrPass, bool SvrSSL, wxString SvrPrefix, wxString SvrAccount){ - - // Setup the CardDAV connection with the prefix/account. - - ServerAddress = SvrAddress; - ServerPort = SvrPort; - ServerUser = SvrUser; - ServerPass = SvrPass; - ServerSSL = SvrSSL; - ServerPrefix = SvrPrefix; - ServerAccount = SvrAccount; - - return TRUE; - -} - -bool CardDAV::SetupResultBools(bool *SvrResult, bool *SvrMonitor){ - - // Setup the result booleans. - - ServerResult = SvrResult; - ServerMonitor = SvrMonitor; - - return TRUE; - -} - -bool CardDAV::HasValidResponse(){ - - // Check that CardDAV server gave a valid response. - - return ValidResponse; - -} - -bool CardDAV::CanDoCardDAV(){ - - // Check that the server has CardDAV support. - - return HasCalDAVSupport; - -} - -bool CardDAV::CanDoSSL(){ - - // Check that the server can do SSL. - - return SSLStatus; - -} - -bool CardDAV::SSLVerify(){ - - // Check that the server can verify SSL. - - return SSLVerified; - -} - -bool CardDAV::AbleToLogin(){ - - // Check that the user is able to login. - - return AuthPassed; - -} - -bool CardDAV::IsSelfSigned(){ - - // Check that self-signed certificates are allowed. - - return AllowSelfSign; - -} - -int CardDAV::ProgressFuncProc(void *clientdata, double TTUp, double NUp, double TTDown, double NDown){ - - // Progress function processing. - - if (AbortConnection == TRUE){ - - return -1; - - } else { - - return 0; - - } - -} - -void CardDAV::Abort(){ - - // Abort (close) the connection. - - AbortConnection = TRUE; - -} - -SSLCertCollection CardDAV::GetSSLVerifyResults(){ - - // Get the SSL verification results. - - return VerifyCertCollection; - -} - -void CardDAV::AllowSelfSignTest(bool AllowSelfSignIn){ - - // Set the value to enable/disable SSL self-signed certificates. - - AllowSelfSign = AllowSelfSignIn; -} - -void CardDAV::GetSSLResults(){ - - // Get the SSL results. - -} - -void CardDAV::SetServerFilename(wxString Filename){ - - // Set the server filename. - - ServerFilenameLocation = Filename; - -} - -wxString CardDAV::GetPageData() -{ - - // Get the server page data. - - return PageData; - -} - -wxString CardDAV::ETagValueResult(){ - - // Get the ETag Result value. - - return ETagResult; - -} - -void CardDAV::SetupData(wxString Method, wxString FilenameLocation, wxString UploadData){ - - // Setup the data to use with the CardDAV connection. - - ServerMethod = Method; - ServerFilenameLocation = FilenameLocation; - ServerUploadData = UploadData; - - // Check if ServerFilenameLocation has a / at - // the start and if not then append it. - - /*if (ServerFilenameLocation.Left(1) != wxT("/")){ - - // Not there so insert. - - ServerFilenameLocation = wxT("/") + ServerFilenameLocation; - - }*/ - -} - -void CardDAV::SetupVariables(std::map *actlist, int actindex){ - - // Setup the variable pointers. - - ActivityListPtr = actlist; - ItemIndex = actindex; - -} - -wxString CardDAV::GetETagData(){ - - // Get the ETag data. - - return ETagData; - -} - -void CardDAV::SetUploadMode(bool IncMode){ - - // Set the upload mode. - - UploadMode = IncMode; - -} - -void CardDAV::SetEditMode(bool EditModeInc){ - - // Set the edit mode. - - EditMode = EditModeInc; - -} - -int CardDAV::GetResultCode(){ - - // Get the result code. - - return (int)claconncode; - -} - -int CardDAV::GetHTTPCode(){ - - // Get the HTTP error code. - - return HTTPErrorCode; - -} - -wxString CardDAV::GetErrorBuffer(){ - - // Get the error buffer. - - wxString ErrorBuffer = wxString::FromUTF8(curlerrbuffer); - - return ErrorBuffer; - -} - -SSLCertCollection CardDAV::BuildSSLCollection(CURL *conn){ - - // Build and return the SSL collection. - - SSLCertCollection SSLCertInfo; - - // Grab the certificate data. - - union { - struct curl_slist *certdata; - struct curl_certinfo *certinfo; - } certptr; - - certptr.certdata = NULL; - - curl_easy_getinfo(conn, CURLINFO_CERTINFO, &certptr.certinfo); - - wxString CertPropName; - wxString CertPropValue; - - for (int i = 0; i < certptr.certinfo->num_of_certs; i++){ - - struct curl_slist *slist; - SSLCertData SSLCertDataInc; - - for (slist = certptr.certinfo->certinfo[i]; slist; slist = slist->next){ - - wxStringTokenizer CertDataInc(wxString::FromUTF8(slist->data), ":"); - - // Get first token as the property name. - - CertPropName = CertDataInc.GetNextToken(); - - // Get remaining tokens as the property value. - - while(CertDataInc.HasMoreTokens()){ - - CertPropValue.Append(CertDataInc.GetNextToken()); - - } - - SSLCertDataInc.CertData.insert(std::make_pair(CertPropName, CertPropValue)); - CertPropName.clear(); - CertPropValue.clear(); - - } - - SSLCertInfo.SSLCollection.insert(std::make_pair(i, SSLCertDataInc)); - - } - - return SSLCertInfo; - -} - -SSLCertCollection CardDAV::GetCertificateData(){ - - // Pass on the collected certificate data. - - return SSLCertCol; - -} - -wxString CardDAV::GetErrorMessage(){ - - // Get the error message. - - return ErrorMessage; - -} - -#if defined(__APPLE__) || defined(__WIN32__) - -CURL* CardDAV::GetConnectionObject(){ - - // Get the CardDAV connection object. - - return ConnectionObject; - -} - -void CardDAV::SetConnectionObject(CURL *ConnectionObjectIn){ - - // Set the connection object. - - ConnectionObject = ConnectionObjectIn; - -} - -#endif - -#if defined(__WIN32__) - -PCCERT_CONTEXT CardDAV::GetCertificateContextPointer(){ - - // Check that the PCCERT_CONTEXT has an address - // other than NULL. Return nullptr if this is the - // case. - - if (CertificateData == NULL){ - return NULL; - } - - // Get the certificate data. - - return CertificateData; - -} - -CERT_CONTEXT CardDAV::GetCertificateContext(){ - - // Check that the PCCERT_CONTEXT has an address - // other than NULL. Return nullptr if this is the - // case. - - if (CertificateData == NULL){ - CERT_CONTEXT EmptyCertificateData = { 0 }; - return EmptyCertificateData; - } - - // Get the certificate data. - - return *CertificateData; - -} - -#endif \ No newline at end of file diff --git a/source/carddav/carddav.h b/source/carddav/carddav.h deleted file mode 100644 index d4ac957..0000000 --- a/source/carddav/carddav.h +++ /dev/null @@ -1,189 +0,0 @@ -// carddav.h - CardDAV Object header file. -// -// (c) 2012-2015 Xestia Software Development. -// -// This file is part of Xestia Address Book. -// -// Xestia Address Book is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by the -// Free Software Foundation, version 3 of the license. -// -// Xestia Address Book is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License along -// with Xestia Address Book. If not, see - -#ifndef CALDAV_CALDAV_H -#define CALDAV_CALDAV_H - -#include -#include -#include -#include -#include -#include -#if defined(__WIN32__) -#include -#include -#include -#include -#include -#include -#include -#endif -#include "../vcard/vcard.h" -#include "../actmgr/frmActivityMgr.h" -#include "../common/sslcertstructs.h" - -struct FileSyncData{ - unsigned int DataFlag:2; - wxString ETagData; -}; - -struct ContactListData{ - wxString SyncToken; - std::map ListData; -}; - -struct UploadDataStruc{ - wxString *readptr; - long sizeleft; - int seek = 0; -}; - -/*struct CertificateData{ - std::multimap CertificateData; - bool CertValid; - int CertError; -}; - -struct CertificateCollection{ - std::map Certificates; - std::map ParentCerticiate; - bool AllCertsValid; - std::map CertErrors; -};*/ - -//size_t WritebackFunc(char *ptr, size_t size, size_t nmemb, FILE *userdata); - -size_t WritebackFunc(char *ptr, size_t size, size_t nmemb, wxString *userdata); -int ProgressFunc(void *clientdata, double TTDown, double NDown, double TTUp, double NUp); -size_t UploadReadFunc(void *ptr, size_t size, size_t nmemb, void *userdata); - -class CardDAV -{ - public: - CardDAV(); - ~CardDAV(); - bool SetupConnection(wxString SvrAddress, int SvrPort, wxString SvrUser, wxString SvrPass, bool SvrSSL); - bool SetupConnection(wxString SvrAddress, int SvrPort, wxString SvrUser, wxString SvrPass, bool SvrSSL, wxString SvrPrefix, wxString SvrAccount); - bool CanDoCardDAV(); - bool CanDoSSL(); - bool SSLVerify(); - bool AbleToLogin(); - bool HasValidResponse(); - bool IsSelfSigned(); - wxString GetResponseData(); - void AllowSelfSignTest(bool AllowSelfSignIn); - bool Connect(); - bool ConnectThread(); - void ProcessData(); - void SetupData(wxString Method, wxString FilenameLocation, wxString UploadData); - void ProcessDataThread(); - void SetUploadMode(bool IncMode); - void Abort(); - bool SetupResultBools(bool *SvrResult, bool *SvrMonitor); - int ProgressFuncProc(void *clientdata, double TTUp, double NUp, double TTDown, double NDown); - void SetupVariables(std::map *actlist, int actindex); - wxString GetETagData(); - void GetServerETagValue(); - void GetServerETagValueThread(); - void GetServerContactData(); - wxString GetPageData(); - void SetEditMode(bool EditModeInc); - ContactListData GetContactList(wxString SyncTokenInc); - void SetServerFilename(wxString Filename); - int GetResultCode(); - static int GetHTTPCode(); - wxString GetErrorBuffer(); - wxString GetDefaultAddressBookURL(); - void GetSSLResults(); - SSLCertCollection GetCertificateData(); - static SSLCertCollection BuildSSLCollection(CURL *conn); - wxString ETagValueResult(); - wxString GetErrorMessage(); - static size_t WritebackFunc(char *ptr, size_t size, size_t nmemb, wxString *stream); -#if defined(__APPLE__) || defined(__WIN32__) - static CURL* GetConnectionObject(); - static void SetConnectionObject(CURL *ConnectionObject); -#endif - -#if defined(__APPLE__) - SecTrustRef GetTrustObject(); -#elif defined(__WIN32__) - PCCERT_CONTEXT GetCertificateContextPointer(); - CERT_CONTEXT GetCertificateContext(); -#endif - - // SSL Verification tests when connecting. - - static CURLcode SSLVerifyTest(); - static SSLCertCollection GetSSLVerifyResults(); - - //size_t WritebackFunc(char *ptr, size_t size, size_t nmemb, FILE *userdata); - private: -#if defined(__APPLE__) || defined(__WIN32__) - static CURL* ConnectionObject; -#endif -#if defined(__APPLE__) - static SSLContext *SSLContextPointer; - static SecTrustRef SecTrustObject; -#elif defined(__WIN32__) - static PCCERT_CONTEXT CertificateData; -#endif - static wxString ServerAddress; - static int ServerPort; - static wxString ServerUser; - static wxString ServerPass; - static wxString ServerPrefix; - static wxString ServerAccount; - static bool ServerSSL; - static bool *ServerResult; - static bool *ServerMonitor; - static bool SSLStatus; - static bool SSLVerified; - static bool ValidResponse; - static bool AuthPassed; - static bool HasCalDAVSupport; - static bool AbortConnection; - static wxString ServerResponse; - static wxString ServerMethod; - static wxString ServerFilenameLocation; - static wxString ServerUploadData; - static wxString ETagData; - static wxString ETagResult; - static bool UploadMode; - static bool EditMode; - static long ItemIndex; - static std::map *ActivityListPtr; - //frmActivityMgr *ActMgrPtr; - static char curlerrbuffer[CURL_ERROR_SIZE]; - static SSLCertCollection SSLCertCol; - static wxString ErrorMessage; - static wxString ErrorBufferMessage; - static bool AllowSelfSign; - protected: - static int SSLErrorCode; - static int ConnectionErrorCode; - static wxString PageHeader; - static wxString PageData; - static CURLcode claconncode; - static int HTTPErrorCode; - static SSLCertCollection VerifyCertCollection; - -}; - -#endif \ No newline at end of file diff --git a/source/frmMain.cpp b/source/frmMain.cpp index 4c0e354..0986e18 100644 --- a/source/frmMain.cpp +++ b/source/frmMain.cpp @@ -54,7 +54,6 @@ #include "common/events.h" #include "common/dirs.h" #include "vcard/vcard.h" -#include "carddav/carddav.h" #include "contacteditor/frmContactEditor.h" #include "import/import.h" #include "export/export.h" @@ -2653,7 +2652,7 @@ void frmMain::ShowSSLCertificates( wxCommandEvent &event ){ #else - std::map::iterator SSLColIter; + std::map::iterator SSLColIter; for (int i = 0; i < prefaccounts.GetCount(); i++){ @@ -2680,11 +2679,11 @@ void frmMain::ShowSSLCertificates( wxCommandEvent &event ){ SSLColIter = AccountSSLData.find(i); - SSLCertCollection SSLCertInfo = SSLColIter->second; + SSLCertCollectionString SSLCertInfo = SSLColIter->second; frmSSLCertificate *frameSSLCert = new frmSSLCertificate ( this ); frameSSLCert->StartCertFrom(0); - frameSSLCert->SetupCerts(SSLCertInfo); + frameSSLCert->SetupCertsString(SSLCertInfo); frameSSLCert->ShowModal(); delete frameSSLCert; @@ -2830,7 +2829,7 @@ void frmMain::UpdateSSLAccountStatus(int AccountID, int SSLStatus, PCCERT_CONTEX #else -void frmMain::UpdateSSLAccountStatus(int AccountID, int SSLStatus, SSLCertCollection SSLCertInc){ +void frmMain::UpdateSSLAccountStatus(int AccountID, int SSLStatus, SSLCertCollectionString SSLCertInc){ // Delete existing data. diff --git a/source/frmMain.h b/source/frmMain.h index 6d3e578..744bf32 100644 --- a/source/frmMain.h +++ b/source/frmMain.h @@ -133,7 +133,7 @@ class frmMain : public frmMainADT #elif defined(__WIN32__) std::map AccountCertificateData; #else - std::map AccountSSLData; + std::map AccountSSLData; #endif std::map AccountSSLResult; std::multimap AccountGroupList; @@ -284,7 +284,7 @@ class frmMain : public frmMainADT #elif defined(__WIN32__) void UpdateSSLAccountStatus(int AccountID, int SSLStatus, PCCERT_CONTEXT CertificateContext); #else - void UpdateSSLAccountStatus(int AccountID, int SSLStatus, SSLCertCollection SSLCertInc); + void UpdateSSLAccountStatus(int AccountID, int SSLStatus, SSLCertCollectionString SSLCertInc); #endif DECLARE_EVENT_TABLE() diff --git a/source/frmNewAccount.cpp b/source/frmNewAccount.cpp index 23ab525..b6a6c2e 100644 --- a/source/frmNewAccount.cpp +++ b/source/frmNewAccount.cpp @@ -27,7 +27,6 @@ #include "common/win32ssl.h" #endif -#include "carddav/carddav.h" #include "common/dirs.h" #include "common/svrblist.h" #include "frmInvalidSSLCertificate.h" diff --git a/source/frmNewAccount.h b/source/frmNewAccount.h index b652607..30e2a3e 100644 --- a/source/frmNewAccount.h +++ b/source/frmNewAccount.h @@ -25,7 +25,6 @@ */ #include "AppXestiaAddrBk.h" -#include "carddav/carddav.h" #include "carddav2/carddav2.h" #include "frmInvalidSSLCertificate.h" -- 2.39.5