wxListItem coldata;
long itemindex = -1;
- CardDAV* CardDAVConn = new CardDAV;
coldata.SetId(ActivityTaskID);
coldata.SetData(ActivityTaskID);
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.
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);
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));
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));
return;
}
- std::map<int,CardDAV*>::iterator CDAVter;
-
- CDAVter = ActivityListConn.find(intSelectedData);
-
- CDAVter->second->Abort();
-
lstActivity->SetItem(longSelected, 2, _("Stopped"));
}
return;
}
- std::map<int,CardDAV*>::iterator CDAVter;
-
- CDAVter = ActivityListConn.find(intSelectedData);
-
- CDAVter->second->Abort();
-
lstActivity->SetItem(longSelected, 2, _("Stopped"));
AnimationTimer.StopAnimation();
bmpActivity->SetBitmap(SleepBitmap);
std::map<int,wxString>::iterator StringTaskDetailIter;
std::map<int,wxString>::iterator StringETagIter;
std::map<int,wxString>::iterator StringETagOrigIter;
- std::map<int,CardDAV*>::iterator CardDAVIter;
std::map<int,ConnectionObject*>::iterator ConnObjectIter;
std::map<int,ActivityMgrAccountSettings>::iterator AccountSettingsIter;
std::map<int,long>::iterator LongIter;
// 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);
// 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.
XABPreferences PrefData(GetUserPrefDir());
if (iter->second == 0){
-
- //CardDAVIter->second.
// Wait for process to finish.
#else
- frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData());
+ frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnObjectIter->second->BuildSSLCollection());
#endif
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());
wxPostEvent(frmMainPtrGet, event);
while (*PauseMode == TRUE){
- //nanosleep(&n1, &n2);
SleepFor(250000000);
}
// Load the client data from the filename given.
- //ConnHandle.GetServerContactData();
- //ServerContactData = ConnHandle.GetPageData();
-
COServerResponse GetContactResponse = ConnObjectIter->second->GetContact(StringURLIter->second.ToStdString(),
&ServerContactData);
}
- /*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<frmMain*>(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){
} 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;
+
+ }
}
#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());
ETagDBPtr->RemoveETag(ContactFilename);
iter->second = 4;
- //CardDAVIter->second = NULL;
break;
}
ContactListData ServerContactList;
std::map<wxString,vCardDownloadDataFileClass> vCardDownloadData;
- //wxArrayString vCardDownload;
- //std::map<wxString,wxString> vCardDownloadData;
// Get the list of vCard files locally.
std::map<wxString,ETagData> ETagDBData = ETagDBPtr->GetETagData();
+ COConnectResult ConnectResponse = ConnObjectIter->second->Connect(false);
+
bool ExitLoop = FALSE;
std::map<wxString,FileSyncData> *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__)
#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
bool ContinueProcess = AccDir.GetFirst(&AccDirFilename, wxEmptyString, wxDIR_DEFAULT);
- ServerContactList = ConnHandle.GetContactList(SyncTokenLoad.ToUTF8());
-
- int ErrorCode = ConnHandle.GetResultCode();
-
- if (ErrorCode != CURLE_OK){
-
- iter->second = 4;
- break;
-
- }
-
- SSLCertCollection certcol = ConnHandle.GetCertificateData();
-
- // Create a pointer for the std::map<wxString,FileSyncData>.
-
- SCListData = &ServerContactList.ListData;
+ COContactList ServerContactList2 = ConnObjectIter->second->GetContactList(SyncTokenLoad.ToStdString());
// Process the server data.
- if (SCListData != NULL){
-
- for (std::map<wxString, FileSyncData>::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<COContactData>::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.
// needs to updated remotely and which needs to be
// updated locally.
- for (std::map<wxString,FileSyncData>::iterator srviter = SCListData->begin();
- srviter != SCListData->end(); srviter++){
-
- if (ETagDBData.find(srviter->first) == ETagDBData.end()){
+ for (std::vector<COContactData>::iterator ContactInfo = ServerContactList2.ListData.begin();
+ ContactInfo != ServerContactList2.ListData.end(); ContactInfo++){
+
+ if (ETagDBData.find(ContactInfo->Location) == ETagDBData.end()){
continue;
}
-
- std::map<wxString,ETagData>::iterator lociter = ETagDBData.find(srviter->first);
-
+
+ std::map<wxString,ETagData>::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.
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.
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);
// 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){
ConvertedV4Data.WriteFile(FullFilename);
- vCardDownloadData.insert(std::make_pair(srviter->first, vCardNewData));
+ vCardDownloadData.insert(std::make_pair(ContactInfo->Location, vCardNewData));
// Send vCard to the server.
- vCardUpdateRemote.Add(srviter->first, 1);
+ vCardUpdateRemote.Add(ContactInfo->Location, 1);
}
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.
// 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);
// 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.
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){
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.
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.
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.
// Decided to use client version.
- ConnHandle.ProcessData();
+ COServerResponse EditContactResponse = ConnObjectIter->second->EditContact(vCardAdd[vi].ToStdString(), ClientData.WriteString().ToStdString());
iter->second = 4;
wxString wxSFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
wxString wxSCardData;
wxString TaskData;
- //wxString TaskURL;
// Load the data from the file.
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);
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.
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.
// 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;
wxString wxSFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
wxString wxSCardData;
wxString TaskData;
- //wxString TaskURL;
// Load the data from the file.
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);
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.
}
for (std::list<wxString>::iterator removeetagiter = DeleteList.begin();
- removeetagiter != DeleteList.end(); removeetagiter++){
+ removeetagiter != DeleteList.end(); removeetagiter++){
ETagDBPtr->RemoveETag(*removeetagiter);
// Write out the update server sync token.
- wxString ServerSyncToken = ServerContactList.SyncToken;
+ wxString ServerSyncToken = wxString::FromUTF8(ServerContactList2.SyncToken.c_str());
ServerSyncToken.Trim();
} 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;
}
wxCommandEvent eventp(ACTMGR_STARTTIMER);
wxPostEvent(this, eventp);
-
- //AnimationTimer.StartAnimation();
- //ActListProcTimer.Start();
}
wxCommandEvent event(ACTMGR_STARTPROCESSTIMER);
wxPostEvent(this, event);
- //ActProcessTimer.Start();
-
}
void frmActivityMgr::ProcessTasks()
lstActivity->SetItem(actmgrudata->ItemIndex, 2, actmgrudata->ItemLabel);
- /*if (!actmgrudata->ItemDes.IsEmpty()){
- lstActivity->SetItem(actmgrudata->ItemIndex, 0, actmgrudata->ItemDes);
- }*/
-
delete actmgrudata;
actmgrudata = NULL;
+++ /dev/null
-// 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 <http://www.gnu.org/licenses/>
-
-#include "carddav.h"
-#include "../version.h"
-#include <wx/wx.h>
-#include <wx/tokenzr.h>
-#include <wx/ffile.h>
-#include <libxml/parser.h>
-#include <libxml/tree.h>
-#include <map>
-#include <thread>
-#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<int, wxString> 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<int, wxString> 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;
-
-}
+++ /dev/null
-// 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 <http://www.gnu.org/licenses/>
-
-#include "carddav.h"
-#include "../version.h"
-#include <wx/wx.h>
-#include <wx/tokenzr.h>
-#include <wx/ffile.h>
-#include <libxml/parser.h>
-#include <libxml/tree.h>
-#include <map>
-#include <thread>
-#include "../vcard/vcard.h"
-#include "../common/dirs.h"
-
-ContactListData CardDAV::GetContactList(wxString SyncTokenInc){
-
- // Get the contact list.
-
- ContactListData ContactListFinal;
- std::map<wxString,FileSyncData> 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("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n");
- SyncData.Append(wxT("<D:sync-collection xmlns:D=\"DAV:\"\n"));
- SyncData.Append(wxT(" xmlns:C=\"urn:ietf:params:xml:ns:carddav\">\n"));
- SyncData.Append(wxT("<D:sync-token>"));
- SyncData.Append(SyncTokenInc);
- SyncData.Append(wxT("</D:sync-token>\n"));
- SyncData.Append(wxT("<D:sync-level>1</D:sync-level>\n"));
- SyncData.Append(wxT("<D:prop>\n"));
- SyncData.Append(wxT(" <D:getetag/>\n"));
- SyncData.Append(wxT("</D:prop>\n"));
- SyncData.Append(wxT("</D:sync-collection>"));
-
- SyncDataBuffer = SyncData.ToUTF8();
-
- } else {
-
- SyncData = wxT("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
- SyncData.Append(wxT("<D:sync-collection xmlns:D=\"DAV:\""));
- SyncData.Append(wxT(" xmlns:C=\"urn:ietf:params:xml:ns:carddav\">\n"));
- SyncData.Append(wxT("<D:sync-token/>\n"));
- SyncData.Append(wxT("<D:sync-level>1</D:sync-level>\n"));
- SyncData.Append(wxT("<D:prop>\n"));
- SyncData.Append(wxT(" <D:getetag/>\n"));
- SyncData.Append(wxT("</D:prop>\n"));
- SyncData.Append(wxT("</D:sync-collection>\n"));
-
- SyncDataBuffer = SyncData.ToUTF8();
-
- }
-
- const char* query = SyncDataBuffer.data();
-
- // Try SSL first.
-
- std::map<int,int>::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<int, SSLCertData>::iterator SSLCDIter = SSLCertCol.SSLCollection.find(0);
- std::multimap<wxString,wxString>::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<wxString,wxString> xmlDataMap;
- std::map<wxString,wxString> 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
+++ /dev/null
-// 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 <http://www.gnu.org/licenses/>
-
-#include "carddav.h"
-#include "../version.h"
-#include <wx/wx.h>
-#include <wx/tokenzr.h>
-#include <wx/ffile.h>
-#include <libxml/parser.h>
-#include <libxml/tree.h>
-#include <map>
-#include <thread>
-#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 = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"
- "<D:propfind xmlns:D=\"DAV:\">\n"
- " <D:prop>"
- " <D:current-user-principal/>\n"
- " </D:prop>"
- "</D:propfind>";
-
- // Setup the second query finding out where the address book home URL is.
-
- const char* query2 = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"
- "<D:propfind xmlns:D=\"DAV:\""
- " xmlns:C=\"urn:ietf:params:xml:ns:carddav\">\n"
- " <D:prop>\n"
- " <C:addressbook-home-set/>\n"
- " </D:prop>\n"
- "</D:propfind>";
-
- // Setup the third query finding out where the default address book URL is.
-
- const char* query3 = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"
- "<D:propfind xmlns:D=\"DAV:\""
- " xmlns:C=\"urn:ietf:params:xml:ns:carddav\">\n"
- " <D:prop>\n"
- " <C:default-addressbook-URL/>\n"
- " </D:prop>\n"
- "</D:propfind>";
-
- 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 <href> 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 <href> 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 <href> 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;
-
-}
+++ /dev/null
-// 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 <http://www.gnu.org/licenses/>
-
-#include "carddav.h"
-#include "../version.h"
-#include <wx/wx.h>
-#include <wx/tokenzr.h>
-#include <wx/ffile.h>
-#include <libxml/parser.h>
-#include <libxml/tree.h>
-#include <map>
-#include <thread>
-#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<int,int>::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<int, SSLCertData>::iterator SSLCDIter = SSLCertCol.SSLCollection.find(0);
- std::multimap<wxString,wxString>::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<int, wxString> 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
+++ /dev/null
-// 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 <http://www.gnu.org/licenses/>
-
-#include "carddav.h"
-#include "../version.h"
-#include <wx/wx.h>
-#include <wx/tokenzr.h>
-#include <wx/ffile.h>
-#include <libxml/parser.h>
-#include <libxml/tree.h>
-#include <map>
-#include <thread>
-#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<int,int>::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<int, SSLCertData>::iterator SSLCDIter = SSLCertCol.SSLCollection.find(0);
- std::multimap<wxString,wxString>::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
+++ /dev/null
-// 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 <http://www.gnu.org/licenses/>
-
-#include "carddav.h"
-#include "../version.h"
-#include <wx/wx.h>
-#include <wx/tokenzr.h>
-#include <wx/ffile.h>
-#include <libxml/parser.h>
-#include <libxml/tree.h>
-#include <map>
-#include <thread>
-#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<int,int>::iterator ActIter;
- struct UploadDataStruc UploadData;
-
-
- ActIter = ActivityListPtr->find((int)ItemIndex);
-
- static const char* query =
- "<?xml version=\"1.0\" encoding=\"utf-8\" ?>"
- "<C:addressbook-query xmlns:D=\"DAV:\""
- " xmlns:C=\"urn:ietf:params:xml:ns:carddav\">"
- "<D:prop><D:getetag/>"
- "</D:prop>"
- "<C:filter/>"
- "</C:addressbook-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<int, SSLCertData>::iterator SSLCDIter = SSLCertCol.SSLCollection.find(0);
- std::multimap<wxString,wxString>::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<wxString,wxString> 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<wxString,wxString>::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
+++ /dev/null
-// 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 <http://www.gnu.org/licenses/>
-
-#include "carddav.h"
-#include "../version.h"
-#include <wx/wx.h>
-#include <wx/tokenzr.h>
-#include <wx/ffile.h>
-#include <libxml/parser.h>
-#include <libxml/tree.h>
-#include <map>
-#include <thread>
-#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
+++ /dev/null
-// 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 <http://www.gnu.org/licenses/>
-
-#import <Foundation/Foundation.h>
-
-#include "carddav.h"
-
-SecTrustRef CardDAV::GetTrustObject(){
-
- // Return the Security Trust Reference for the CardDAV object.
-
- return SecTrustObject;
-
-}
\ No newline at end of file
+++ /dev/null
-// carddav.cpp - Main CardDAV Object file.\r
-//\r
-// (c) 2012-2015 Xestia Software Development.\r
-//\r
-// This file is part of Xestia Address Book.\r
-//\r
-// Xestia Address Book is free software: you can redistribute it and/or modify\r
-// it under the terms of the GNU General Public License as published by the\r
-// Free Software Foundation, version 3 of the license.\r
-//\r
-// Xestia Address Book is distributed in the hope that it will be useful,\r
-// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
-// GNU General Public License for more details.\r
-//\r
-// You should have received a copy of the GNU General Public License along\r
-// with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>\r
-\r
-#include "carddav.h"\r
-#include "../version.h"\r
-#include <wx/wx.h>\r
-#include <wx/tokenzr.h>\r
-#include <wx/ffile.h>\r
-#include <libxml/parser.h>\r
-#include <libxml/tree.h>\r
-#include <map>\r
-#include <thread>\r
-#include "../vcard/vcard.h"\r
-#include "../common/dirs.h"\r
-\r
-size_t CardDAV::WritebackFunc(char *ptr, size_t size, size_t nmemb, wxString *stream){\r
- \r
- // Writeback function for the CardDAV object.\r
- \r
- wxString Data;\r
- Data = wxString::FromUTF8((char *)ptr);\r
- \r
- stream->Append(Data);\r
- \r
- // Get the SSL engine pointer and trust if required on certain operating systems.\r
- \r
-#if defined(__APPLE__)\r
- \r
- const struct curl_tlssessioninfo *TLSInfo;\r
- CURLcode TLSCode;\r
- CURL *Connection = GetConnectionObject();\r
- TLSCode = curl_easy_getinfo(Connection, CURLINFO_TLS_SSL_PTR, &TLSInfo);\r
- \r
- if (TLSInfo->internals != nullptr && TLSCode == CURLE_OK){\r
- SSLCopyPeerTrust((SSLContext*)TLSInfo->internals, &SecTrustObject);\r
- }\r
- \r
-#elif defined(__WIN32__)\r
-\r
- const struct curl_tlssessioninfo *TLSInfo;\r
- CURLcode TLSCode;\r
- CURL *Connection = GetConnectionObject();\r
- TLSCode = curl_easy_getinfo(Connection, CURLINFO_TLS_SSL_PTR, &TLSInfo);\r
-\r
- std::string CertName;\r
-\r
- if (TLSInfo->internals != nullptr && TLSCode == CURLE_OK){\r
-\r
- // Free the previous certificate data.\r
-\r
- CertFreeCertificateContext(CertificateData);\r
-\r
- PCtxtHandle SSLHandle = (PCtxtHandle)TLSInfo->internals;\r
- SECURITY_STATUS GetData = QueryContextAttributes(SSLHandle, SECPKG_ATTR_REMOTE_CERT_CONTEXT, &CertificateData);\r
-\r
- }\r
-\r
-#endif\r
- \r
- return size * nmemb;\r
-\r
-}\r
-\r
-int ProgressFunc(void *clientdata, double TTDown, double NDown, double TTUp, double NUp){\r
-\r
- // Progress function for the CardDAV object.\r
- \r
- int ProgressRet;\r
- \r
- CardDAV *IncCardDAV = static_cast<CardDAV*>(clientdata);\r
- ProgressRet = IncCardDAV->ProgressFuncProc(clientdata, TTDown, NDown, TTUp, NUp);\r
- if (ProgressRet != 0){\r
- return 1;\r
- }\r
- return 0;\r
-\r
-}\r
-\r
-wxString CardDAV::ServerAddress;\r
-int CardDAV::ServerPort;\r
-wxString CardDAV::ServerUser;\r
-wxString CardDAV::ServerPass;\r
-wxString CardDAV::ServerPrefix;\r
-wxString CardDAV::ServerAccount;\r
-bool CardDAV::ServerSSL;\r
-bool *CardDAV::ServerResult;\r
-bool *CardDAV::ServerMonitor;\r
-bool CardDAV::SSLStatus;\r
-bool CardDAV::SSLVerified;\r
-bool CardDAV::ValidResponse;\r
-bool CardDAV::AuthPassed;\r
-bool CardDAV::HasCalDAVSupport;\r
-bool CardDAV::AbortConnection;\r
-wxString CardDAV::ServerResponse;\r
-wxString CardDAV::ServerMethod;\r
-wxString CardDAV::ServerFilenameLocation;\r
-wxString CardDAV::ServerUploadData;\r
-wxString CardDAV::ETagData;\r
-wxString CardDAV::ETagResult;\r
-bool CardDAV::UploadMode;\r
-bool CardDAV::EditMode;\r
-long CardDAV::ItemIndex;\r
-std::map<int, int> *CardDAV::ActivityListPtr;\r
-char CardDAV::curlerrbuffer[CURL_ERROR_SIZE];\r
-SSLCertCollection CardDAV::SSLCertCol;\r
-int CardDAV::SSLErrorCode;\r
-int CardDAV::ConnectionErrorCode;\r
-wxString CardDAV::PageHeader;\r
-wxString CardDAV::PageData;\r
-CURLcode CardDAV::claconncode;\r
-int CardDAV::HTTPErrorCode;\r
-wxString CardDAV::ErrorMessage;\r
-SSLCertCollection CardDAV::VerifyCertCollection;\r
-bool CardDAV::AllowSelfSign;\r
-#if defined(__APPLE__)\r
-SSLContext *CardDAV::SSLContextPointer;\r
-SecTrustRef CardDAV::SecTrustObject;\r
-#endif\r
-#if defined(__WIN32__)\r
-PCCERT_CONTEXT CardDAV::CertificateData;\r
-#endif\r
-#if defined(__APPLE__) || defined(__WIN32__)\r
-CURL *CardDAV::ConnectionObject;\r
-#endif\r
-\r
-CardDAV::CardDAV(){\r
- \r
- // Setup the CardDAV object.\r
- \r
- ServerPort = 8080;\r
- SSLStatus = FALSE;\r
- SSLVerified = FALSE;\r
- AuthPassed = FALSE;\r
- ValidResponse = FALSE;\r
- HasCalDAVSupport = FALSE;\r
- SSLCertCol.SuccessCode = 0;\r
- AllowSelfSign = FALSE;\r
-\r
- AbortConnection = FALSE;\r
- UploadMode = FALSE;\r
- EditMode = FALSE;\r
- HTTPErrorCode = 0;\r
- \r
-}\r
-\r
-CardDAV::~CardDAV(){\r
-\r
- // Destroy the CardDAV object.\r
- \r
-}\r
-\r
-size_t UploadReadFunc(void *ptr, size_t size, size_t nmemb, void *userdata){\r
-\r
- \r
- // Upload function for the CardDAV object.\r
- \r
- struct UploadDataStruc *UploadPtr = (struct UploadDataStruc *)userdata;\r
-\r
- if (UploadPtr->sizeleft){\r
-\r
- //MeepMoop->sizeleft--;\r
- //return 1;\r
-\r
- UploadPtr->sizeleft--;\r
- wxString wxSChar;\r
-\r
- wxSChar = UploadPtr->readptr->Mid(UploadPtr->seek,1);\r
-\r
- //*(char *)ptr = (char)wxSChar.mb_str();\r
-\r
- strncpy((char *)ptr, (const char*)wxSChar.mb_str(wxConvUTF8), 1);\r
-\r
- UploadPtr->seek++;\r
-\r
- return 1;\r
-\r
- }\r
-\r
- return 0;\r
-\r
-}\r
-\r
-bool CardDAV::SetupConnection(wxString SvrAddress, int SvrPort, wxString SvrUser, wxString SvrPass, bool SvrSSL){\r
-\r
- // Setup the CardDAV connection without the prefix/account.\r
- \r
- ServerAddress = SvrAddress;\r
- ServerPort = SvrPort;\r
- ServerUser = SvrUser;\r
- ServerPass = SvrPass;\r
- ServerSSL = SvrSSL;\r
- \r
- return TRUE;\r
-\r
-}\r
-\r
-bool CardDAV::SetupConnection(wxString SvrAddress, int SvrPort, wxString SvrUser, wxString SvrPass, bool SvrSSL, wxString SvrPrefix, wxString SvrAccount){\r
-\r
- // Setup the CardDAV connection with the prefix/account.\r
- \r
- ServerAddress = SvrAddress;\r
- ServerPort = SvrPort;\r
- ServerUser = SvrUser;\r
- ServerPass = SvrPass;\r
- ServerSSL = SvrSSL;\r
- ServerPrefix = SvrPrefix;\r
- ServerAccount = SvrAccount;\r
-\r
- return TRUE;\r
-\r
-}\r
-\r
-bool CardDAV::SetupResultBools(bool *SvrResult, bool *SvrMonitor){\r
-\r
- // Setup the result booleans.\r
- \r
- ServerResult = SvrResult;\r
- ServerMonitor = SvrMonitor;\r
-\r
- return TRUE;\r
-\r
-}\r
-\r
-bool CardDAV::HasValidResponse(){\r
-\r
- // Check that CardDAV server gave a valid response.\r
- \r
- return ValidResponse;\r
-\r
-}\r
-\r
-bool CardDAV::CanDoCardDAV(){\r
-\r
- // Check that the server has CardDAV support.\r
- \r
- return HasCalDAVSupport;\r
-\r
-}\r
-\r
-bool CardDAV::CanDoSSL(){\r
-\r
- // Check that the server can do SSL.\r
- \r
- return SSLStatus;\r
-\r
-}\r
-\r
-bool CardDAV::SSLVerify(){\r
-\r
- // Check that the server can verify SSL.\r
- \r
- return SSLVerified;\r
-\r
-}\r
-\r
-bool CardDAV::AbleToLogin(){\r
-\r
- // Check that the user is able to login.\r
- \r
- return AuthPassed;\r
-\r
-}\r
-\r
-bool CardDAV::IsSelfSigned(){\r
-\r
- // Check that self-signed certificates are allowed.\r
- \r
- return AllowSelfSign;\r
-\r
-}\r
-\r
-int CardDAV::ProgressFuncProc(void *clientdata, double TTUp, double NUp, double TTDown, double NDown){\r
-\r
- // Progress function processing.\r
- \r
- if (AbortConnection == TRUE){\r
- \r
- return -1;\r
- \r
- } else {\r
- \r
- return 0;\r
- \r
- }\r
-\r
-}\r
-\r
-void CardDAV::Abort(){\r
-\r
- // Abort (close) the connection.\r
- \r
- AbortConnection = TRUE;\r
-\r
-}\r
-\r
-SSLCertCollection CardDAV::GetSSLVerifyResults(){\r
- \r
- // Get the SSL verification results.\r
- \r
- return VerifyCertCollection;\r
- \r
-}\r
-\r
-void CardDAV::AllowSelfSignTest(bool AllowSelfSignIn){\r
- \r
- // Set the value to enable/disable SSL self-signed certificates.\r
- \r
- AllowSelfSign = AllowSelfSignIn;\r
-}\r
-\r
-void CardDAV::GetSSLResults(){\r
-\r
- // Get the SSL results.\r
-\r
-}\r
-\r
-void CardDAV::SetServerFilename(wxString Filename){\r
-\r
- // Set the server filename.\r
- \r
- ServerFilenameLocation = Filename;\r
-\r
-}\r
-\r
-wxString CardDAV::GetPageData()\r
-{\r
-\r
- // Get the server page data.\r
- \r
- return PageData;\r
-\r
-}\r
-\r
-wxString CardDAV::ETagValueResult(){\r
-\r
- // Get the ETag Result value.\r
- \r
- return ETagResult;\r
-\r
-}\r
-\r
-void CardDAV::SetupData(wxString Method, wxString FilenameLocation, wxString UploadData){\r
-\r
- // Setup the data to use with the CardDAV connection.\r
- \r
- ServerMethod = Method;\r
- ServerFilenameLocation = FilenameLocation;\r
- ServerUploadData = UploadData;\r
-\r
- // Check if ServerFilenameLocation has a / at \r
- // the start and if not then append it.\r
- \r
- /*if (ServerFilenameLocation.Left(1) != wxT("/")){\r
- \r
- // Not there so insert.\r
- \r
- ServerFilenameLocation = wxT("/") + ServerFilenameLocation;\r
- \r
- }*/\r
-\r
-}\r
-\r
-void CardDAV::SetupVariables(std::map<int, int> *actlist, int actindex){\r
-\r
- // Setup the variable pointers.\r
- \r
- ActivityListPtr = actlist;\r
- ItemIndex = actindex;\r
-\r
-}\r
-\r
-wxString CardDAV::GetETagData(){\r
-\r
- // Get the ETag data.\r
- \r
- return ETagData;\r
-\r
-}\r
-\r
-void CardDAV::SetUploadMode(bool IncMode){\r
-\r
- // Set the upload mode.\r
- \r
- UploadMode = IncMode;\r
-\r
-}\r
-\r
-void CardDAV::SetEditMode(bool EditModeInc){\r
-\r
- // Set the edit mode.\r
- \r
- EditMode = EditModeInc;\r
-\r
-}\r
-\r
-int CardDAV::GetResultCode(){\r
-\r
- // Get the result code.\r
- \r
- return (int)claconncode;\r
-\r
-}\r
-\r
-int CardDAV::GetHTTPCode(){\r
-\r
- // Get the HTTP error code.\r
- \r
- return HTTPErrorCode;\r
-\r
-}\r
-\r
-wxString CardDAV::GetErrorBuffer(){\r
-\r
- // Get the error buffer.\r
- \r
- wxString ErrorBuffer = wxString::FromUTF8(curlerrbuffer);\r
-\r
- return ErrorBuffer;\r
-\r
-}\r
-\r
-SSLCertCollection CardDAV::BuildSSLCollection(CURL *conn){\r
-\r
- // Build and return the SSL collection.\r
- \r
- SSLCertCollection SSLCertInfo;\r
-\r
- // Grab the certificate data.\r
-\r
- union {\r
- struct curl_slist *certdata;\r
- struct curl_certinfo *certinfo;\r
- } certptr;\r
-\r
- certptr.certdata = NULL;\r
- \r
- curl_easy_getinfo(conn, CURLINFO_CERTINFO, &certptr.certinfo);\r
-\r
- wxString CertPropName;\r
- wxString CertPropValue;\r
-\r
- for (int i = 0; i < certptr.certinfo->num_of_certs; i++){\r
-\r
- struct curl_slist *slist;\r
- SSLCertData SSLCertDataInc;\r
- \r
- for (slist = certptr.certinfo->certinfo[i]; slist; slist = slist->next){\r
- \r
- wxStringTokenizer CertDataInc(wxString::FromUTF8(slist->data), ":");\r
- \r
- // Get first token as the property name.\r
- \r
- CertPropName = CertDataInc.GetNextToken();\r
- \r
- // Get remaining tokens as the property value.\r
- \r
- while(CertDataInc.HasMoreTokens()){\r
- \r
- CertPropValue.Append(CertDataInc.GetNextToken());\r
- \r
- }\r
- \r
- SSLCertDataInc.CertData.insert(std::make_pair(CertPropName, CertPropValue));\r
- CertPropName.clear();\r
- CertPropValue.clear();\r
- \r
- }\r
- \r
- SSLCertInfo.SSLCollection.insert(std::make_pair(i, SSLCertDataInc));\r
- \r
- }\r
- \r
- return SSLCertInfo;\r
-\r
-}\r
-\r
-SSLCertCollection CardDAV::GetCertificateData(){\r
-\r
- // Pass on the collected certificate data.\r
-\r
- return SSLCertCol;\r
-\r
-}\r
-\r
-wxString CardDAV::GetErrorMessage(){\r
-\r
- // Get the error message.\r
- \r
- return ErrorMessage;\r
-\r
-}\r
-\r
-#if defined(__APPLE__) || defined(__WIN32__)\r
-\r
-CURL* CardDAV::GetConnectionObject(){\r
- \r
- // Get the CardDAV connection object.\r
- \r
- return ConnectionObject;\r
- \r
-}\r
-\r
-void CardDAV::SetConnectionObject(CURL *ConnectionObjectIn){\r
-\r
- // Set the connection object.\r
- \r
- ConnectionObject = ConnectionObjectIn;\r
- \r
-}\r
-\r
-#endif\r
-\r
-#if defined(__WIN32__)\r
-\r
-PCCERT_CONTEXT CardDAV::GetCertificateContextPointer(){\r
-\r
- // Check that the PCCERT_CONTEXT has an address\r
- // other than NULL. Return nullptr if this is the\r
- // case.\r
-\r
- if (CertificateData == NULL){\r
- return NULL;\r
- }\r
-\r
- // Get the certificate data.\r
-\r
- return CertificateData;\r
-\r
-}\r
-\r
-CERT_CONTEXT CardDAV::GetCertificateContext(){\r
-\r
- // Check that the PCCERT_CONTEXT has an address\r
- // other than NULL. Return nullptr if this is the\r
- // case.\r
-\r
- if (CertificateData == NULL){\r
- CERT_CONTEXT EmptyCertificateData = { 0 };\r
- return EmptyCertificateData;\r
- }\r
-\r
- // Get the certificate data.\r
-\r
- return *CertificateData;\r
-\r
-}\r
-\r
-#endif
\ No newline at end of file
+++ /dev/null
-// 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 <http://www.gnu.org/licenses/>
-
-#ifndef CALDAV_CALDAV_H
-#define CALDAV_CALDAV_H
-
-#include <iostream>
-#include <map>
-#include <wx/wx.h>
-#include <libxml/parser.h>
-#include <libxml/tree.h>
-#include <curl/curl.h>
-#if defined(__WIN32__)
-#include <Windows.h>
-#include <basetsd.h>
-#include <winapifamily.h>
-#include <security.h>
-#include <schannel.h>
-#include <cryptuiapi.h>
-#include <sspi.h>
-#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<wxString,FileSyncData> ListData;
-};
-
-struct UploadDataStruc{
- wxString *readptr;
- long sizeleft;
- int seek = 0;
-};
-
-/*struct CertificateData{
- std::multimap<wxString,wxString> CertificateData;
- bool CertValid;
- int CertError;
-};
-
-struct CertificateCollection{
- std::map<int,CertificateData> Certificates;
- std::map<int,int> ParentCerticiate;
- bool AllCertsValid;
- std::map<int,int> 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<int, int> *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<int, int> *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
#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"
#else
- std::map<int, SSLCertCollection>::iterator SSLColIter;
+ std::map<int, SSLCertCollectionString>::iterator SSLColIter;
for (int i = 0; i < prefaccounts.GetCount(); i++){
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;
#else
-void frmMain::UpdateSSLAccountStatus(int AccountID, int SSLStatus, SSLCertCollection SSLCertInc){
+void frmMain::UpdateSSLAccountStatus(int AccountID, int SSLStatus, SSLCertCollectionString SSLCertInc){
// Delete existing data.
#elif defined(__WIN32__)
std::map<int, PCCERT_CONTEXT> AccountCertificateData;
#else
- std::map<int, SSLCertCollection> AccountSSLData;
+ std::map<int, SSLCertCollectionString> AccountSSLData;
#endif
std::map<int, int> AccountSSLResult;
std::multimap<int, int> AccountGroupList;
#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()
#include "common/win32ssl.h"
#endif
-#include "carddav/carddav.h"
#include "common/dirs.h"
#include "common/svrblist.h"
#include "frmInvalidSSLCertificate.h"
*/
#include "AppXestiaAddrBk.h"
-#include "carddav/carddav.h"
#include "carddav2/carddav2.h"
#include "frmInvalidSSLCertificate.h"