Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Implemented code to delete contact via ConnectionObject
[xestiaab/.git] / source / actmgr / frmActivityMgr.cpp
1 // frmActivityMgr.cpp - Activity Manager form.
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
10 //
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
19 #include "frmActivityMgr.h"
20 #include <wx/mstream.h>
21 #include <wx/file.h>
22 #include <wx/ffile.h>
23 #include <wx/tokenzr.h>
24 #include <wx/dir.h>
25 #include <wx/filefn.h>
26 #include <thread>
27 #include <list>
28 #include <curl/curl.h>
30 #include "../bitmaps.h"
31 #include "../enums.h"
32 #include "../common/preferences.h"
33 #include "../frmConflictResolution.h"
34 #include "../frmInvalidSSLCertificate.h"
35 #include "../frmMain.h"
36 #include "../common/events.h"
37 #include "../common/filename.h"
38 #include "../vcard/vcard34conv.h"
39 #include "../vcard/vcard.h"
41 DEFINE_EVENT_TYPE(ACTMGR_RESUMEPROC);
42 DEFINE_EVENT_TYPE(ACTMGR_TOGGLECONN);
43 DEFINE_EVENT_TYPE(ACTMGR_STARTTIMER);
44 DEFINE_EVENT_TYPE(ACTMGR_STOPTIMER);
45 DEFINE_EVENT_TYPE(ACTMGR_STARTPROCESSTIMER);
46 DEFINE_EVENT_TYPE(ACTMGR_STOPPROCESSTIMER);
47 DEFINE_EVENT_TYPE(ACTMGR_UPDATESTATUSLABEL);
48 DEFINE_EVENT_TYPE(ACTMGR_STARTANIMATIONTIMER);
50 BEGIN_EVENT_TABLE(frmActivityMgr, wxWindow)
51   EVT_COMMAND(wxID_ANY, ACTMGR_RESUMEPROC, frmActivityMgr::ResumeProcessing)
52   EVT_COMMAND(wxID_ANY, ACTMGR_TOGGLECONN, frmActivityMgr::ToggleConnectionStatus)
53   EVT_COMMAND(wxID_ANY, ACTMGR_STARTTIMER, frmActivityMgr::StartTimer)
54   EVT_COMMAND(wxID_ANY, ACTMGR_STOPTIMER, frmActivityMgr::StopTimer)
55   EVT_COMMAND(wxID_ANY, ACTMGR_STARTPROCESSTIMER, frmActivityMgr::StartProcessTimer)
56   EVT_COMMAND(wxID_ANY, ACTMGR_STOPPROCESSTIMER, frmActivityMgr::StopProcessTimer)
57   EVT_COMMAND(wxID_ANY, ACTMGR_UPDATESTATUSLABEL, frmActivityMgr::UpdateStatusLabel)
58   EVT_COMMAND(wxID_ANY, ACTMGR_STARTANIMATIONTIMER, frmActivityMgr::StartAnimationTimer)
59 END_EVENT_TABLE()
61 frmActivityMgr::frmActivityMgr( wxWindow* parent )
62 :
63 frmActivityMgrADT( parent )
64 {
66         wxMemoryInputStream istream(icons_activitywindow_png, sizeof(icons_activitywindow_png));
67         wxImage icons_activitywindow_pngi(istream, wxBITMAP_TYPE_PNG);
68         wxBitmap activityiconbmp(icons_activitywindow_pngi, -1);
69         wxIcon activityicon;
70         activityicon.CopyFromBitmap(activityiconbmp);
71         this->SetIcon(activityicon); 
73         wxMemoryInputStream istream2(misc_activitysleep_png, sizeof(misc_activitysleep_png));
74         wxImage misc_activitysleep_pngi(istream2, wxBITMAP_TYPE_PNG);
75         wxBitmap sleepiconbmp(misc_activitysleep_pngi, -1);
76         SleepBitmap = sleepiconbmp;
77         bmpActivity->SetBitmap(SleepBitmap);
78         ActProcessTimer.SetupPointers(this);
79         lblDetails->SetLabel(_("No activity."));
80         
81         ActListProcTimer.SetupPointers(&ActivityList, &ActivityListIndex, &ActivityListTaskDetail, 
82                                         &TasksActive, lstActivity, lblDetails, GauProgress, this, &AnimationTimer,
83                                         &ActProcessTimer, &ActivityListFinDate, &ActivityListConn);
84         
85         AnimationTimer.SetBitmap(bmpActivity);
86         AnimationTimer.SetSleepBitmap(&SleepBitmap);
87         AnimationTimer.SetupPointer(this->GetParent());
88         
89         wxListItem ColumnData;
90         ColumnData.SetId(0);
91         ColumnData.SetText(_("Activity"));
92         ColumnData.SetWidth(175);
93         lstActivity->InsertColumn(0, ColumnData);
94         
95         wxListItem ColumnData2;
96         ColumnData2.SetId(1);
97         ColumnData2.SetText(_("Account"));
98         ColumnData2.SetWidth(100);
99         lstActivity->InsertColumn(1, ColumnData2);
101         wxListItem ColumnData3;
102         ColumnData3.SetId(2);
103         ColumnData3.SetText(_("Status"));
104         ColumnData3.SetWidth(100);
105         lstActivity->InsertColumn(2, ColumnData3);
106         
107         //AnimationTimer.StartAnimation();
108         
109         // Create recovery database if it doesn't exist.
110         
111         wxString RecoveryFilename = GetRecoveryDB();
112         
113         wxFile RecoveryDB;
114         
115         if (wxFile::Exists(RecoveryFilename) == FALSE){
116         
117                 // Create the recovery database.
119                 RecoveryDB.Open(RecoveryFilename.c_str(), wxFile::write);       
120         
121                 RecoveryDB.Write(wxT("BEGIN:XAB-RECOVERYDB\r\n"), wxConvUTF8);
122                 RecoveryDB.Write(wxT("VERSION:1.0\r\n"), wxConvUTF8);
123                 RecoveryDB.Write(wxT("COMMENT:Please do not alter or delete this file. DATA LOSS IS POSSIBLE!\r\n"), wxConvUTF8);
124                 RecoveryDB.Write(wxT("END:XAB-RECOVERYDB\r\n"), wxConvUTF8);
125                 RecoveryDB.Close();
127         }
128         
129         wxFFile RecoveryDBF;
130         
131 #if wxABI_VERSION < 20900
132         RecoveryDBF.Open(RecoveryFilename.c_str(), wxT("r"));
133 #else
134         RecoveryDBF.Open(RecoveryFilename, wxT("r"));
135 #endif  
136         
137         // Load the recovery database for tasks not done.
138         
139         if (RecoveryDBF.IsOpened() == TRUE){
140         
141                 wxString wxSRecoveryDB;
142                 wxString RecoveryLine;
143         
144                 // Check if we are using wxWidgets version 2.8 or less and
145                 // execute the required command accordingly.
146         
147                 RecoveryDBF.ReadAll(&wxSRecoveryDB, wxConvAuto());
148         
149                 // Split the lines.
150         
151                 std::map<int, wxString> RecoveryFileLines;
152                 std::map<int, wxString>::iterator striter;
153         
154                 wxStringTokenizer wSTRecoveryDBLines(wxSRecoveryDB, wxT("\r\n"));
156                 int RecoveryLineSeek = 0;
158                 while (wSTRecoveryDBLines.HasMoreTokens() == TRUE){
160                         RecoveryLine = wSTRecoveryDBLines.GetNextToken();
161                         RecoveryFileLines.insert(std::make_pair(RecoveryLineSeek, RecoveryLine));
162                         RecoveryLineSeek++;             
163         
164                 }
165         
166         }
167         
170         //TestTimer.Start(50, FALSE);
173 void frmActivityMgr::OpenWindow()
175         WindowOpen = TRUE;
178 void frmActivityMgr::CloseWindow( wxCommandEvent& event )
180         WindowOpen = FALSE;
181         this->Hide();
184 void frmActivityMgr::CloseWindow( wxCloseEvent& event )
186         WindowOpen = FALSE;
187         this->Hide();
190 void frmActivityMgr::ProcessTasksThread()
192         
193         if (ProcessTasksData == FALSE){
194         
195                 return;
196         
197         }
198         
199         if (ApplicationSleepMode == TRUE){
200                 
201                 return;
202                 
203         }
204         
205         std::map<int,int>::iterator TypeIter;
206         std::map<int,wxString>::iterator StringIter;
207         std::map<int,wxString>::iterator StringDataIter;
208         std::map<int,wxString>::iterator StringURLIter;
209         std::map<int,wxString>::iterator StringDetailIter;
210         std::map<int,wxString>::iterator StringAccountIter;
211         std::map<int,wxString>::iterator StringFilenameIter;
212         std::map<int,wxString>::iterator StringFullFilenameIter;
213         std::map<int,wxString>::iterator StringTaskDetailIter;
214         std::map<int,wxString>::iterator StringETagIter;
215         std::map<int,wxString>::iterator StringETagOrigIter;
216         std::map<int,CardDAV*>::iterator CardDAVIter;
217         std::map<int,ConnectionObject*>::iterator ConnObjectIter;
218         std::map<int,ActivityMgrAccountSettings>::iterator AccountSettingsIter;
219         std::map<int,long>::iterator LongIter;
220         bool TasksFoundProc = FALSE;
221         wxString TaskDetail;
222         
223         for (std::map<int,int>::iterator iter = ActivityList.begin(); 
224          iter != ActivityList.end(); ++iter){
225          
226                 // Check for any queued tasks and start one.
227                 
228                 if (iter->second > 4){
229                         continue;
230                 }
231                 
232                 wxCommandEvent StartAnimationEvent(ACTMGR_STARTANIMATIONTIMER);
233                 
234                 wxPostEvent(this, StartAnimationEvent);
235                 
236                 // Start the animation timer if it hasn't started.
237                 
238                 CardDAVIter = ActivityListConn.find(iter->first);
239                 ConnObjectIter = ActivityListConnObject.find(iter->first);
240                 TypeIter = ActivityListType.find(iter->first);
241                 StringETagIter = ActivityListETag.find(iter->first);
242                 StringETagOrigIter = ActivityListETagOriginal.find(iter->first);
243                 StringAccountIter = ActivityListAccount.find(iter->first);
244                 StringFilenameIter = ActivityListFilename.find(iter->first);
245                 StringFullFilenameIter = ActivityListFullFilename.find(iter->first);
246                 AccountSettingsIter = ActivityListAccSettings.find(iter->first);
247                 
248                 // Setup the CardDAV object.
249                 
250                 CardDAV ConnHandle;
251                 
252                 ConnHandle.SetupConnection(AccountSettingsIter->second.Address,
253                                          AccountSettingsIter->second.Port,
254                                          AccountSettingsIter->second.Username,
255                                          AccountSettingsIter->second.Password,
256                                          AccountSettingsIter->second.SSL,
257                                          AccountSettingsIter->second.Prefix,
258                                          AccountSettingsIter->second.Dir);
259                 ConnHandle.SetupVariables(&ActivityList, iter->first);
260                 ConnHandle.SetupResultBools(&BlankBool, &BlankBool);
261                 
262                 // 0 = Queued.
263                 // 1 = Processing.
264                 // 2 = Failed.
265                 // 3 = Stopped.
266                 // 4 = Completed.
267                 // 5 = Failed (UI Updated).
268                 // 6 = Stopped (UI Updated).
269                 // 7 = (Reserved) (UI Updated).
270                 // 8 = Completed. (UI Updated). 
271                 
272                 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
273                 XABPreferences PrefData(GetUserPrefDir());
274                 
275                 if (iter->second == 0){
276                 
277                         //CardDAVIter->second.
278                         
279                         // Wait for process to finish.
281                         TasksActive = TRUE;
282                         TasksFoundProc = TRUE;
283                         wxString ETag;
284                         wxString ETagOriginal;
285                         wxString ETagServer;
286                         wxString AccountDir;
287                         wxString ContactFilename;
288                         wxString FullFilename;
289                         wxString ETagResult;
290                         bool EditMode = FALSE;
292                         iter->second = 1;
293                         
294                         // Compare the ETags and work out if a conflict has occured.
295                         
296                         if (TypeIter->second == 0){
297                         
298                                 // Add a contact.
299                                 
300                                 StringDataIter = ActivityListData.find(iter->first);
301                                 StringURLIter = ActivityListURL.find(iter->first);
302                                 
303                                 AccountDir = StringAccountIter->second;
304                                 ContactFilename = StringFilenameIter->second;
305                                 wxString AccountNameFriendly;
306                                 
307                                 int AccountID = 0;
308                                 
309                                 for (int i = 0; i < PrefData.accounts.GetCount(); i++){
310                                         
311                                         wxString AccountDirCheck = PrefData.accounts.GetAccountDirectory(i);
312                                         
313                                         AccountDirCheck.Trim();
314                                         AccountDirCheck.Append(wxT(".carddav"));
315                                         
316                                         if (AccountDirCheck == StringAccountIter->second){
317                                                 
318                                                 AccountNameFriendly = PrefData.accounts.GetAccountName(i);
319                                                 AccountID = i;
320                                                 
321                                         }
322                                         
323                                 }
324                                 
325                                 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
326                                 
327                                 ETag = StringETagIter->second;
328                                 ETagOriginal = StringETagOrigIter->second;
329                                 AccountDir = StringAccountIter->second;
330                                 ContactFilename = StringFilenameIter->second;
331                                 FullFilename = StringFullFilenameIter->second;
332                                 EditMode = ActivityListEditMode.find(iter->first)->second;
333                                 
334                                 bool KeepUpdating = true;
335                                 
336                                 while(KeepUpdating == true){
337                                         
338                                         COConnectResult ConnectResponse = ConnObjectIter->second->Connect(false);
339                                         
340                                         bool ExitLoop = false;
341                                         
342                                         while (ExitLoop == false){
343                                                 
344                                                 if (ConnObjectIter->second->SSLVerify() == COSSL_UNABLETOVERIFY){
345                                                         
346                                                         frmMainPtrGet->PauseAllTimers();
347                                                         
348 #if defined(__APPLE__)
349 #elif defined(__WIN32__)
350 #else
351         
352                                                         bool UsingSSLBypass = false;
353                                                         int SSLResult = 0;
354                                                         
355                                                         // Connect again and fetch SSL certificate information.
356                 
357                                                         ConnObjectIter->second->BypassSSLVerification(true);
358                 
359                                                         COConnectResult ConnectionSSLResult = ConnObjectIter->second->Connect(false);
361                                                         ConnObjectIter->second->BypassSSLVerification(false);
363                                                         SSLInvalidCertNotifObjString SSLICNProcData;
364                                                         
365                                                         SSLCertCollectionString certcol = ConnObjectIter->second->BuildSSLCollection();
366                                                                 
367                                                         bool *PauseMode = new bool;
368                                                         QRNotif qrn;
369                                                                 
370                                                         *PauseMode = TRUE;
371                                                         qrn.QResponse = &SSLResult;
372                                                         qrn.PausePtr = PauseMode;
373                                                                 
374                                                         SSLICNProcData.CertCollection = certcol;
375                                                         SSLICNProcData.QRNotifData = &qrn;
376                                                         SSLICNProcData.AccountName = AccountNameFriendly;
377                                                                 
378                                                         wxCommandEvent event(INVALIDSSLCERTSTRING);
379                                                         event.SetClientData(&SSLICNProcData);
380                                                         wxPostEvent(frmMainPtrGet, event);
381                                                                 
382                                                         while (*PauseMode == TRUE){
383                                                                 //nanosleep(&n1, &n2);
384                                                                 SleepFor(250000000);
385                                                         }
386                                                         
387                                                         // Process the response from the user.
388                                                         
389                                                         if (SSLResult == 1){
390                                                                 
391                                                                 // Accept the Certificate.
393                                                                 UsingSSLBypass = true;
394                                                                 ConnObjectIter->second->BypassSSLVerification(true);
395                 
396                                                                 COConnectResult TestConnectionResult = ConnObjectIter->second->Connect(true);
397                                                                 WriteServerCertificate(AccountDir, certcol);
398                                                                 
399                                                                 ConnObjectIter->second->BypassSSLVerification(false);
400                                                                 
401                                                         } else if (SSLResult == 2){
402                                                 
403                                                                 // Reject the certificate, abort the task and mark as failed.
405                                                                 iter->second = 2;
406                                                                 break;
407                                                                 
408                                                         }
409                 
410 #endif
411                                                         
412                                                         frmMainPtrGet->ResumeAllTimers();
413                                                         ExitLoop = true;
414                                                         
415                                                 } else if (ConnectResponse == COCONNECT_AUTHFAIL){
416                                                         
417                                                         ConnectResponse = ConnObjectIter->second->Connect(true);
418                                                         
419                                                         if (ConnectResponse == COCONNECT_OK){
420                                                                 
421                                                                 ExitLoop = true;
422                                                                 break;
423                                                                 
424                                                         } else {
425                                                                 
426                                                                 ExitLoop = true;                                                        
427                                                                 iter->second = 2;
428                                                                 break;
429                                                                 
430                                                         }
431                                                         
432                                                 } else if (ConnectResponse == COCONNECT_OK){
433                                                         
434                                                         ConnectResponse = ConnObjectIter->second->Connect(true);
435                                                         
436                                                         ExitLoop = true;
437                                                         break;
438                                                         
439                                                 } else {
440                                                         
441                                                         ExitLoop = true;                                                        
442                                                         iter->second = 2;
443                                                         break;
444                                                         
445                                                 }
446                                                 
447                                         }
448                                         
449                                         if (iter->second == 2 || iter->second == 3 || iter->second == 4){
450                                                 break;
451                                         }
452                                         
453 #if defined(__APPLE__)
454                                         
455                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
457 #elif defined(__WIN32__)
459                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer());
461 #else
462                                         
463                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData());
464                                         
465 #endif
466                                         
467                                         COServerResponse AddContactResponse = ConnObjectIter->second->AddContact(StringURLIter->second.ToStdString(), 
468                                                         StringDataIter->second.ToStdString());
469                                         
470                                         if (AddContactResponse.RequestResult != COREQUEST_OK){
471                                                 iter->second = 2;
472                                                 break;
473                                         }
474                                         
475                                         /*while (ExitLoop == FALSE){
476                                                 
477                                                 // Verify that we have a trusted SSL connection first.
478                                                 
479                                                 int ErrorCode = ConnHandle.SSLVerifyTest();
481                                                 if (ErrorCode != CURLE_OK){
482                                                         
483                                                         if (ErrorCode == CURLE_SSL_CACERT ||
484                                                                 ErrorCode == CURLE_PEER_FAILED_VERIFICATION ||
485                                                                 ErrorCode == CURLE_SSL_CONNECT_ERROR){
486                                                                 
487                                                                 // Invalid SSL certificate so bring up a dialog to the user
488                                                                 // explaining what has happened and the options available.
489                                                                 
490                                                                 // Stop all the timers.
491                                                                 
492                                                                 frmMainPtrGet->PauseAllTimers();
493                                                                 
494                                                                 int SSLResult;
495                                                                 
496 #if defined(__APPLE__)
497                                                                 
498                                                                 // Bring up the trust panel and display the SSL certificate dialog.
499                                                                 
500                                                                 SSLResult = DisplayTrustPanel(ConnHandle.GetTrustObject(), AccountNameFriendly);
501                                                                 
502                                                                 // Update the SSL account with the trust object.
503                                                                 
504                                                                 if (SSLResult != NSOKButton){
505                                                                         
506                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetTrustObject());
507                                                                         iter->second = 2;
508                                                                         break;
509                                                                         
510                                                                 } else {
511                                                                         
512                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
513                                                                         
515                                                                 }
517 #elif defined(__WIN32__)
519                                                                 BOOL ModifiedCertificateData;
520                                                                 CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(&ConnHandle, (HWND)frmMainPtrGet->GetHandle());
522                                                                 if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)){
523                                                                         wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog"));
524                                                                 }
526                                                                 if (ModifiedCertificateData == FALSE){
528                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetCertificateContextPointer());
529                                                                         iter->second = 2;
530                                                                         break;
532                                                                 } else {
534                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer());
536                                                                 }
538 #else
539                                                                 
540                                                                 // Setup the data to be sent in the wxPostEvent command.
541                                                                 
542                                                                 SSLInvalidCertNotifObj SSLICNProcData;
543                                                                 
544                                                                 SSLCertCollection certcol = ConnHandle.GetSSLVerifyResults();
545                                                                 
546                                                                 bool *PauseMode = new bool;
547                                                                 QRNotif qrn;
548                                                                 
549                                                                 *PauseMode = TRUE;
550                                                                 qrn.QResponse = &SSLResult;
551                                                                 qrn.PausePtr = PauseMode;
552                                                                 
553                                                                 SSLICNProcData.CertCollection = certcol;
554                                                                 SSLICNProcData.QRNotifData = &qrn;
555                                                                 SSLICNProcData.AccountName = AccountNameFriendly;
556                                                                 
557                                                                 wxCommandEvent event(INVALIDSSLCERT);
558                                                                 event.SetClientData(&SSLICNProcData);
559                                                                 wxPostEvent(frmMainPtrGet, event);
560                                                                 
561                                                                 while (*PauseMode == TRUE){
562                                                                         //nanosleep(&n1, &n2);
563                                                                         SleepFor(250000000);
564                                                                 }
565                                                                 
566                                                                 // Process the response from the user.
567                                                                 
568                                                                 if (SSLResult == 1){
569                                                                         
570                                                                         // Accept the certificate. Write the certificate into the account
571                                                                         // directory (as server.crt) - will overwrite old certificate.
572                                                                         
573                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData());
574                                                                         WriteServerCertificate(AccountDir, ConnHandle.GetCertificateData());
575                                                                         
576                                                                 } else if (SSLResult == 2){
577                                                                         
578                                                                         // Reject the certificate, abort the task and mark as failed.
579                                                                         
580                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetCertificateData());
581                                                                         iter->second = 2;
582                                                                         break;
583                                                                         
584                                                                 }
585                                                                 
586 #endif
587                                                                 
588                                                                 // Resume all the timers.
589                                                                 
590                                                                 frmMainPtrGet->ResumeAllTimers();
591                                                                 ExitLoop = TRUE;
592                                                                 
593                                                         } else {
594                                                                 
595                                                                 iter->second = 2;
596                                                                 break;
597                                                                 
598                                                         }
599                                                         
600                                                 } else {
601                                                         
602                                                         ExitLoop = TRUE;
603                                                         
604                                                 }
605                                                 
606                                         }
607                                         
608                                         if (iter->second == 2 || iter->second == 3 || iter->second == 4){
609                                                 break;
610                                         }
611                                         
612 #if defined(__APPLE__)
613                                         
614                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
616 #elif defined(__WIN32__)
618                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer());
620 #else
621                                         
622                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateData());
623                                         
624 #endif
625                                         
626                                         ConnHandle.SetUploadMode(TRUE);
627                                         ConnHandle.SetupData(wxT("PUT"), StringURLIter->second, StringDataIter->second);
628                                         ConnHandle.SetEditMode(EditMode);
629                                         ConnHandle.ProcessData();
631                                         int ErrorCode = ConnHandle.GetResultCode();
633                                         if (ErrorCode != CURLE_OK){
635                                                 iter->second = 4;
636                                                 break;
638                                         }
640                                         // Add contact to the ETag DB.
641                                         
642                                         ConnHandle.GetServerETagValueThread();
643                                         ETagServer = ConnHandle.ETagValueResult();*/                                    
644                                         
645                                         // TODO: Get the entity tag for the new contact.
646                                         
647                                         COServerResponse ETagGetResponse = ConnObjectIter->second->GetServerEntityTagValue(StringURLIter->second.ToStdString());
648                                         
649                                         if (ETagGetResponse.RequestResult != COREQUEST_OK){
650                                                 iter->second = 2;
651                                                 break;
652                                         }
653                                         
654                                         std::cout << ETagGetResponse.EntityTag << std::endl;
655                                         
656                                         ETagDBPtr->UpdateETag(ContactFilename, ETagGetResponse.EntityTag, ETagGetResponse.EntityTag);
657                                         
658                                         iter->second = 4;
659                                         break;
660                                         
661                                 }
662                                 
663                         } else if (TypeIter->second == 1){
664                                 
665                                 // Update a contact.
666                                 
667                                 StringDataIter = ActivityListData.find(iter->first);
668                                 StringURLIter = ActivityListURL.find(iter->first);
669                                 
670                                 AccountDir = StringAccountIter->second;
671                                 ContactFilename = StringFilenameIter->second;
672                                 wxString AccountNameFriendly;
673                                 
674                                 int AccountID = 0;
675                                 
676                                 for (int i = 0; i < PrefData.accounts.GetCount(); i++){
677                                         
678                                         wxString AccountDirCheck = PrefData.accounts.GetAccountDirectory(i);
679                                         
680                                         AccountDirCheck.Trim();
681                                         AccountDirCheck.Append(wxT(".carddav"));
682                                         
683                                         if (AccountDirCheck == StringAccountIter->second){
684                                                 
685                                                 AccountNameFriendly = PrefData.accounts.GetAccountName(i);
686                                                 AccountID = i;
687                                                 
688                                         }
689                                         
690                                 }
691                                 
692                                 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
693                                 
694                                 ETag = StringETagIter->second;
695                                 ETagOriginal = StringETagOrigIter->second;
696                                 AccountDir = StringAccountIter->second;
697                                 ContactFilename = StringFilenameIter->second;
698                                 FullFilename = StringFullFilenameIter->second;
699                                 EditMode = ActivityListEditMode.find(iter->first)->second;
700                                 
701                                 bool KeepUpdating = true;
702                                 
703                                 while(KeepUpdating == true){
704                                         
705                                         COConnectResult ConnectResponse = ConnObjectIter->second->Connect(false);
706                                         
707                                         bool ExitLoop = false;
708                                         
709                                         while(ExitLoop == false){
710                                                 
711                                                 if (ConnObjectIter->second->SSLVerify() == COSSL_UNABLETOVERIFY){
712                                                         
713                                                         frmMainPtrGet->PauseAllTimers();
714                                                         
715 #if defined(__APPLE__)
716 #elif defined(__WIN32__)
717 #else
718         
719                                                         bool UsingSSLBypass = false;
720                                                         int SSLResult = 0;
721                                                         
722                                                         // Connect again and fetch SSL certificate information.
723                 
724                                                         ConnObjectIter->second->BypassSSLVerification(true);
725                 
726                                                         COConnectResult ConnectionSSLResult = ConnObjectIter->second->Connect(false);
728                                                         ConnObjectIter->second->BypassSSLVerification(false);
730                                                         SSLInvalidCertNotifObjString SSLICNProcData;
731                                                         
732                                                         SSLCertCollectionString certcol = ConnObjectIter->second->BuildSSLCollection();
733                                                                 
734                                                         bool *PauseMode = new bool;
735                                                         QRNotif qrn;
736                                                                 
737                                                         *PauseMode = TRUE;
738                                                         qrn.QResponse = &SSLResult;
739                                                         qrn.PausePtr = PauseMode;
740                                                                 
741                                                         SSLICNProcData.CertCollection = certcol;
742                                                         SSLICNProcData.QRNotifData = &qrn;
743                                                         SSLICNProcData.AccountName = AccountNameFriendly;
744                                                                 
745                                                         wxCommandEvent event(INVALIDSSLCERTSTRING);
746                                                         event.SetClientData(&SSLICNProcData);
747                                                         wxPostEvent(frmMainPtrGet, event);
748                                                                 
749                                                         while (*PauseMode == TRUE){
750                                                                 //nanosleep(&n1, &n2);
751                                                                 SleepFor(250000000);
752                                                         }
753                                                         
754                                                         // Process the response from the user.
755                                                         
756                                                         if (SSLResult == 1){
757                                                                 
758                                                                 // Accept the Certificate.
760                                                                 UsingSSLBypass = true;
761                                                                 ConnObjectIter->second->BypassSSLVerification(true);
762                 
763                                                                 COConnectResult TestConnectionResult = ConnObjectIter->second->Connect(true);
764                                                                 WriteServerCertificate(AccountDir, certcol);
765                                                                 
766                                                                 ConnObjectIter->second->BypassSSLVerification(false);
767                                                                 
768                                                         } else if (SSLResult == 2){
769                                                 
770                                                                 // Reject the certificate, abort the task and mark as failed.
772                                                                 iter->second = 2;
773                                                                 break;
774                                                                 
775                                                         }
776                 
777 #endif
778                                                         
779                                                         frmMainPtrGet->ResumeAllTimers();
780                                                         ExitLoop = true;
781                                                         
782                                                 } else if (ConnectResponse == COCONNECT_AUTHFAIL){
783                                                         
784                                                         ConnectResponse = ConnObjectIter->second->Connect(true);
785                                                         
786                                                         if (ConnectResponse == COCONNECT_OK){
787                                                                 
788                                                                 ExitLoop = true;
789                                                                 break;
790                                                                 
791                                                         } else {
792                                                                 
793                                                                 ExitLoop = true;                                                        
794                                                                 iter->second = 2;
795                                                                 break;
796                                                                 
797                                                         }
798                                                         
799                                                 } else if (ConnectResponse == COCONNECT_OK){
800                                                         
801                                                         ConnectResponse = ConnObjectIter->second->Connect(true);
802                                                         
803                                                         ExitLoop = true;
804                                                         break;
805                                                         
806                                                 } else {
807                                                         
808                                                         ExitLoop = true;                                                        
809                                                         iter->second = 2;
810                                                         break;
811                                                         
812                                                 }
813                                                 
814                                         }
815                                         
816                                         if (iter->second == 2 || iter->second == 3 || iter->second == 4){
817                                                 break;
818                                         }
819                                         
820                                         COServerResponse ETagGetResponse = ConnObjectIter->second->GetServerEntityTagValue(StringURLIter->second.ToStdString());
821                                         
822                                         if (ETagGetResponse.RequestResult != COREQUEST_OK){
823                                                 iter->second = 2;
824                                                 break;
825                                         }
826                                         
827                                         ETagServer = ETagGetResponse.EntityTag;
828                                         
829                                         // Compare the ETag with the Server ETag.
830                                         
831                                         if (ETagOriginal != ETagServer){
832                                                 
833                                                 // Server ETag is different from original ETag.
834                                                 // This is a conflict which the user will now
835                                                 // need to resolve.
836                                                 
837                                                 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
838                                                 
839                                                 vCard34Conv vCard34Obj;
840                                                 
841                                                 std::string ServerContactData;
842                                                 wxString wxStringServerContactData;
843                                                 vCard ClientData;
844                                                 vCard ConvertedV4Data;
845                                                 
846                                                 // Load the client data from the filename given.
847                                                 
848                                                 //ConnHandle.GetServerContactData();
849                                                 //ServerContactData = ConnHandle.GetPageData();
850                                                 
851                                                 COServerResponse GetContactResponse = ConnObjectIter->second->GetContact(StringURLIter->second.ToStdString(),
852                                                         &ServerContactData);
853                                                 
854                                                 if (GetContactResponse.RequestResult != COREQUEST_OK){
855                                                         iter->second = 2;
856                                                         break;
857                                                 }
858                                                 
859                                                 wxStringServerContactData = wxString::FromUTF8((const char*)ServerContactData.c_str());
860                                                 
861                                                 // Process v3 version into v4 version.
862                                                 
863                                                 vCard34Obj.ConvertToV4(&wxStringServerContactData, &ConvertedV4Data);
864                                                 
865                                                 vCardConflictObj vCardProcData;
866                                                 
867                                                 vCardProcData.vCardLocalData = &ClientData;
868                                                 vCardProcData.vCardServerData = &ConvertedV4Data;
869                                                 ClientData.LoadFile(FullFilename);
870                                                 
871                                                 // Setup Conflict Resolution Dialog.
872                                                 
873                                                 // Fetch Data from Server and convert.
874                                                 
875                                                 bool *PauseMode = new bool;
876                                                 int ConflictResult;
877                                                 QRNotif qrn;
878                                                 
879                                                 *PauseMode = TRUE;
880                                                 qrn.QResponse = &ConflictResult;
881                                                 qrn.PausePtr = PauseMode;
882                                                 
883                                                 vCardProcData.QRNotifData = &qrn;
884                                                 
885                                                 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
886                                                 event.SetClientData(&vCardProcData);
887                                                 wxPostEvent(frmMainPtrGet, event);
888                                                 
889                                                 while (*PauseMode == TRUE){
890                                                         SleepFor(250000000);
891                                                 }
892                                                 
893                                                 delete PauseMode;
894                                                 PauseMode = NULL;
895                                                 
896                                                 if (ConflictResult == 0){
897                                                         
898                                                         // Decide Later.
899                                                         
900                                                         iter->second = 4;
901                                                         break;
902                                                         
903                                                 } else if (ConflictResult == 1){
904                                                         
905                                                         // Decided to use client version.
906                                                         
907                                                 } else if (ConflictResult == 2){
908                                                         
909                                                         // Decided to use server version.
910                                                         
911                                                         // Download server version.
912                                                         
913                                                         ConvertedV4Data.WriteFile(FullFilename);
914                                                         
915                                                 }
916                                                 
917                                         } else {
918                                                 
919                                                 // Upload the data to the server.
920                                                 
921                                                 COServerResponse EditContactResponse = ConnObjectIter->second->EditContact(StringURLIter->second.ToStdString(), 
922                                                         StringDataIter->second.ToStdString());
923                                         
924                                                 if (EditContactResponse.RequestResult != COREQUEST_OK){
925                                                         iter->second = 2;
926                                                         break;
927                                                 }
928                                                 
929                                         }
930                                         
931                                         /*while (ExitLoop == FALSE){
932                                                  
933                                                 int ErrorCode = ConnHandle.SSLVerifyTest();
934                                                 
935                                                 if (ErrorCode != CURLE_OK){
936                                                         
937                                                         if (ErrorCode == CURLE_SSL_CACERT ||
938                                                                 ErrorCode == CURLE_PEER_FAILED_VERIFICATION ||
939                                                                 ErrorCode == CURLE_SSL_CONNECT_ERROR){
940                                                                 
941                                                                 // Invalid SSL certificate so bring up a dialog to the user
942                                                                 // explaining what has happened and the options available.
943                                                                 
944                                                                 // Stop all the timers.
945                                                                 
946                                                                 frmMainPtrGet->PauseAllTimers();
947                                                                 
948                                                                 int SSLResult;
949                                                                 
950 #if defined(__APPLE__)
951                                                                 
952                                                                 // Bring up the trust panel and display the SSL certificate dialog.
953                                                                 
954                                                                 SSLResult = DisplayTrustPanel(ConnHandle.GetTrustObject(), AccountNameFriendly);
955                                                                 
956                                                                 // Update the SSL account with the trust object.
957                                                                 
958                                                                 if (SSLResult != NSOKButton){
959                                                                         
960                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetTrustObject());
961                                                                         iter->second = 2;
962                                                                         break;
963                                                                         
964                                                                 } else {
965                                                                         
966                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
967                                                                         
968                                                                 }
970 #elif defined(__WIN32__)
972                                                                 BOOL ModifiedCertificateData;
973                                                                 CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(&ConnHandle, (HWND)frmMainPtrGet->GetHandle());
975                                                                 if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)){
976                                                                         wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog"));
977                                                                 }
979                                                                 if (ModifiedCertificateData == FALSE){
981                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetCertificateContextPointer());
982                                                                         iter->second = 2;
983                                                                         break;
985                                                                 } else {
987                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer());
989                                                                 }
991 #else
992                                                                 
993                                                                 // Setup the data to be sent in the wxPostEvent command.
994                                                                 
995                                                                 SSLInvalidCertNotifObj SSLICNProcData;
996                                                                 
997                                                                 SSLCertCollection certcol = ConnHandle.GetSSLVerifyResults();
998                                                                 
999                                                                 bool *PauseMode = new bool;
1000                                                                 QRNotif qrn;
1001                                                                 
1002                                                                 *PauseMode = TRUE;
1003                                                                 qrn.QResponse = &SSLResult;
1004                                                                 qrn.PausePtr = PauseMode;
1005                                                                 
1006                                                                 SSLICNProcData.CertCollection = certcol;
1007                                                                 SSLICNProcData.QRNotifData = &qrn;
1008                                                                 SSLICNProcData.AccountName = AccountNameFriendly;
1009                                                                 
1010                                                                 wxCommandEvent event(INVALIDSSLCERT);
1011                                                                 event.SetClientData(&SSLICNProcData);
1012                                                                 wxPostEvent(frmMainPtrGet, event);
1013                                                                 
1014                                                                 while (*PauseMode == TRUE){
1015                                                                         //nanosleep(&n1, &n2);
1016                                                                         SleepFor(250000000);
1017                                                                 }
1018                                                                 
1019                                                                 // Process the response from the user.
1020                                                                 
1021                                                                 if (SSLResult == 1){
1022                                                                         
1023                                                                         // Accept the certificate. Write the certificate into the account
1024                                                                         // directory (as server.crt) - will overwrite old certificate.
1025                                                                         
1026                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetSSLVerifyResults());
1027                                                                         WriteServerCertificate(AccountDir, ConnHandle.GetSSLVerifyResults());
1028                                                                         
1029                                                                 } else if (SSLResult == 2){
1030                                                                         
1031                                                                         // Reject the certificate, abort the task and mark as failed.
1032                                                                         
1033                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetSSLVerifyResults());
1034                                                                         iter->second = 2;
1035                                                                         break;
1036                                                                         
1037                                                                 }
1038                                                                 
1039 #endif
1040                                                                 
1041                                                                 // Resume all the timers.
1042                                                                 
1043                                                                 frmMainPtrGet->ResumeAllTimers();
1044                                                                 ExitLoop = TRUE;
1045                                                                 
1046                                                         } else {
1047                                                                 
1048                                                                 iter->second = 2;
1049                                                                 break;
1050                                                                 
1051                                                         }
1052                                                         
1053                                                 } else {
1054                                                         
1055                                                         ExitLoop = TRUE;
1056                                                         
1057                                                 }
1058                                                 
1059                                         }
1060                                         
1061                                         if (iter->second == 2 || iter->second == 3 || iter->second == 4){
1062                                                 break;
1063                                         }
1064                                         
1065 #if defined(__APPLE__)
1066                                         
1067                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
1069 #elif defined(__WIN32__)
1071                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer());
1073 #else
1074                                         
1075                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetSSLVerifyResults());
1076                                         
1077 #endif
1078                                         
1079                                         ConnHandle.SetUploadMode(TRUE);
1080                                         ConnHandle.SetupData(wxT("PUT"), StringURLIter->second, StringDataIter->second);
1081                                         ConnHandle.SetEditMode(EditMode);
1082                                         ConnHandle.GetServerETagValueThread();
1083                                         ETagServer = ConnHandle.ETagValueResult();
1085                                         int ErrorCode = ConnHandle.GetResultCode();
1087                                         if (ErrorCode != CURLE_OK){
1088                                                 iter->second = 2;
1089                                                 break;
1090                                         }
1092                                         // Compare the ETag with the Server ETag.
1093                                         
1094                                         if (ETagOriginal != ETagServer){
1095                                                 
1096                                                 // Server ETag is different from original ETag.
1097                                                 // This is a conflict which the user will now
1098                                                 // need to resolve.
1099                                                 
1100                                                 vCard Moo1;
1101                                                 vCard Moo2;
1102                                                 
1103                                                 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
1104                                                 
1105                                                 vCard34Conv vCard34Obj;
1106                                                 
1107                                                 wxString ServerContactData;
1108                                                 vCard ClientData;
1109                                                 vCard ConvertedV4Data;
1110                                                 
1111                                                 // Load the client data from the filename given.
1112                                                 
1113                                                 ConnHandle.GetServerContactData();
1114                                                 ServerContactData = ConnHandle.GetPageData();
1115                                                 
1116                                                 // Process v3 version into v4 version.
1117                                                 
1118                                                 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
1119                                                 
1120                                                 vCardConflictObj vCardProcData;
1121                                                 
1122                                                 vCardProcData.vCardLocalData = &ClientData;
1123                                                 vCardProcData.vCardServerData = &ConvertedV4Data;
1124                                                 ClientData.LoadFile(FullFilename);
1125                                                 
1126                                                 //ContactConflictEvent event(ContactConflictCmdEnv);
1127                                                 //event.SetData(ContactFilename, Moo1, Moo2);
1128                                                 
1129                                                 //wxPostEvent(frmMainPtrGet, event);
1130                                                 
1131                                                 // Setup Conflict Resolution Dialog.
1132                                                 
1133                                                 // Fetch Data from Server and convert.
1134                                                 
1135                                                 bool *PauseMode = new bool;
1136                                                 int ConflictResult;
1137                                                 QRNotif qrn;
1138                                                 
1139                                                 *PauseMode = TRUE;
1140                                                 qrn.QResponse = &ConflictResult;
1141                                                 qrn.PausePtr = PauseMode;
1142                                                 
1143                                                 vCardProcData.QRNotifData = &qrn;
1144                                                 
1145                                                 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
1146                                                 event.SetClientData(&vCardProcData);
1147                                                 wxPostEvent(frmMainPtrGet, event);
1148                                                 
1149                                                 while (*PauseMode == TRUE){
1150                                                         //nanosleep(&n1, &n2);
1151                                                         SleepFor(250000000);
1152                                                 }
1153                                                 
1154                                                 delete PauseMode;
1155                                                 PauseMode = NULL;
1156                                                 
1157                                                 //intResult = frmMainPtrGet->ShowConflictDialog(&Moo1, &Moo2);
1158                                                 
1159                                                 if (ConflictResult == 0){
1160                                                         
1161                                                         // Decide Later.
1162                                                         
1163                                                         iter->second = 4;
1164                                                         break;
1165                                                         
1166                                                 } else if (ConflictResult == 1){
1167                                                         
1168                                                         // Decided to use client version.
1169                                                         
1170                                                         //ConnHandle.ProcessData();
1171                                                         
1172                                                 } else if (ConflictResult == 2){
1173                                                         
1174                                                         // Decided to use server version.
1175                                                         
1176                                                         // Download server version.
1177                                                         
1178                                                         ConvertedV4Data.WriteFile(FullFilename);
1179                                                         
1180                                                 }
1181                                                 
1182                                         } else {
1183                                                 
1184                                                 // Update the data to the server.
1185                                                 
1186                                                 ConnHandle.ProcessData();
1187                                                 
1188                                         }*/
1189                                         
1190                                         // Update the ETag DB.
1191                                         
1192                                         //ConnHandle.GetServerETagValueThread();
1193                                         //ETagServer = ConnHandle.ETagValueResult();
1194                                         
1195                                         ETagGetResponse = ConnObjectIter->second->GetServerEntityTagValue(StringURLIter->second.ToStdString());
1196                                         
1197                                         if (ETagGetResponse.RequestResult != COREQUEST_OK){
1198                                                 iter->second = 2;
1199                                                 break;
1200                                         }
1201                                         
1202                                         ETagDBPtr->UpdateETag(ContactFilename, ETagGetResponse.EntityTag, ETagGetResponse.EntityTag);
1203                                         
1204                                         iter->second = 4;
1205                                         break;
1206                                         
1207                                 }
1208                         
1209                         } else if (TypeIter->second == 2) {
1210                         
1211                                 // Delete the contact from the server and update the ETag DB.
1212                                 
1213                                 AccountDir = StringAccountIter->second;
1214                                 ContactFilename = StringFilenameIter->second;
1215                                 wxString AccountNameFriendly;
1216                                 
1217                                 int AccountID = 0;
1218                                 
1219                                 for (int i = 0; i < PrefData.accounts.GetCount(); i++){
1220                                         
1221                                         wxString AccountDirCheck = PrefData.accounts.GetAccountDirectory(i);
1222                                         
1223                                         AccountDirCheck.Trim();
1224                                         AccountDirCheck.Append(wxT(".carddav"));
1225                                         
1226                                         if (AccountDirCheck == StringAccountIter->second){
1227                                                 
1228                                                 AccountNameFriendly = PrefData.accounts.GetAccountName(i);
1229                                                 AccountID = i;
1230                                                 
1231                                         }
1232                                         
1233                                 }
1234                                 
1235                                 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
1236                                 
1237                                 bool KeepUpdating = TRUE;
1238                                 
1239                                 while(KeepUpdating == TRUE){
1240                                 
1241                                         COConnectResult ConnectResponse = ConnObjectIter->second->Connect(false);
1242                                         
1243                                         bool ExitLoop = FALSE;
1244                                         
1245                                         while (ExitLoop == FALSE){
1246                                                 
1247                                                 if (ConnObjectIter->second->SSLVerify() == COSSL_UNABLETOVERIFY){
1248                                                         
1249                                                         frmMainPtrGet->PauseAllTimers();
1250                                                         
1251 #if defined(__APPLE__)
1252 #elif defined(__WIN32__)
1253 #else
1254         
1255                                                         bool UsingSSLBypass = false;
1256                                                         int SSLResult = 0;
1257                                                         
1258                                                         // Connect again and fetch SSL certificate information.
1259                 
1260                                                         ConnObjectIter->second->BypassSSLVerification(true);
1261                 
1262                                                         COConnectResult ConnectionSSLResult = ConnObjectIter->second->Connect(false);
1264                                                         ConnObjectIter->second->BypassSSLVerification(false);
1266                                                         SSLInvalidCertNotifObjString SSLICNProcData;
1267                                                         
1268                                                         SSLCertCollectionString certcol = ConnObjectIter->second->BuildSSLCollection();
1269                                                                 
1270                                                         bool *PauseMode = new bool;
1271                                                         QRNotif qrn;
1272                                                                 
1273                                                         *PauseMode = TRUE;
1274                                                         qrn.QResponse = &SSLResult;
1275                                                         qrn.PausePtr = PauseMode;
1276                                                                 
1277                                                         SSLICNProcData.CertCollection = certcol;
1278                                                         SSLICNProcData.QRNotifData = &qrn;
1279                                                         SSLICNProcData.AccountName = AccountNameFriendly;
1280                                                                 
1281                                                         wxCommandEvent event(INVALIDSSLCERTSTRING);
1282                                                         event.SetClientData(&SSLICNProcData);
1283                                                         wxPostEvent(frmMainPtrGet, event);
1284                                                                 
1285                                                         while (*PauseMode == TRUE){
1286                                                                 //nanosleep(&n1, &n2);
1287                                                                 SleepFor(250000000);
1288                                                         }
1289                                                         
1290                                                         // Process the response from the user.
1291                                                         
1292                                                         if (SSLResult == 1){
1293                                                                 
1294                                                                 // Accept the Certificate.
1296                                                                 UsingSSLBypass = true;
1297                                                                 ConnObjectIter->second->BypassSSLVerification(true);
1298                 
1299                                                                 COConnectResult TestConnectionResult = ConnObjectIter->second->Connect(true);
1300                                                                 WriteServerCertificate(AccountDir, certcol);
1301                                                                 
1302                                                                 ConnObjectIter->second->BypassSSLVerification(false);
1303                                                                 
1304                                                         } else if (SSLResult == 2){
1305                                                 
1306                                                                 // Reject the certificate, abort the task and mark as failed.
1308                                                                 iter->second = 2;
1309                                                                 break;
1310                                                                 
1311                                                         }
1312                 
1313 #endif
1314                                                         
1315                                                         frmMainPtrGet->ResumeAllTimers();
1316                                                         ExitLoop = true;
1317                                                         
1318                                                 } else if (ConnectResponse == COCONNECT_AUTHFAIL){
1319                                                         
1320                                                         ConnectResponse = ConnObjectIter->second->Connect(true);
1321                                                         
1322                                                         if (ConnectResponse == COCONNECT_OK){
1323                                                                 
1324                                                                 ExitLoop = true;
1325                                                                 break;
1326                                                                 
1327                                                         } else {
1328                                                                 
1329                                                                 ExitLoop = true;                                                        
1330                                                                 iter->second = 2;
1331                                                                 break;
1332                                                                 
1333                                                         }
1334                                                         
1335                                                 } else if (ConnectResponse == COCONNECT_OK){
1336                                                         
1337                                                         ConnectResponse = ConnObjectIter->second->Connect(true);
1338                                                         
1339                                                         ExitLoop = true;
1340                                                         break;
1341                                                         
1342                                                 } else {
1343                                                         
1344                                                         ExitLoop = true;                                                        
1345                                                         iter->second = 2;
1346                                                         break;
1347                                                         
1348                                                 }
1349                                                 
1350                                                 /*int ErrorCode = ConnHandle.SSLVerifyTest();
1352                                                 if (ErrorCode != CURLE_OK){
1353                                                         
1354                                                         if (ErrorCode == CURLE_SSL_CACERT ||
1355                                                                 ErrorCode == CURLE_PEER_FAILED_VERIFICATION ||
1356                                                                 ErrorCode == CURLE_SSL_CONNECT_ERROR){
1357                                                                 
1358                                                                 // Invalid SSL certificate so bring up a dialog to the user
1359                                                                 // explaining what has happened and the options available.
1360                                                                 
1361                                                                 // Stop all the timers.
1362                                                                 
1363                                                                 frmMainPtrGet->PauseAllTimers();
1364                                                                 
1365                                                                 int SSLResult;
1366                                                                 
1367 #if defined(__APPLE__)
1368                                                                 
1369                                                                 // Bring up the trust panel and display the SSL certificate dialog.
1370                                                                 
1371                                                                 SSLResult = DisplayTrustPanel(ConnHandle.GetTrustObject(), AccountNameFriendly);
1372                                                                 
1373                                                                 // Update the SSL account with the trust object.
1374                                                                 
1375                                                                 if (SSLResult != NSOKButton){
1376                                                                         
1377                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetTrustObject());
1378                                                                         iter->second = 2;
1379                                                                         break;
1380                                                                         
1381                                                                 } else {
1382                                                                         
1383                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
1384                                                                         
1385                                                                 }
1387 #elif defined(__WIN32__)
1389                                                                 BOOL ModifiedCertificateData;
1390                                                                 CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(&ConnHandle, (HWND)frmMainPtrGet->GetHandle());
1392                                                                 if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)){
1393                                                                         wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog"));
1394                                                                 }
1396                                                                 if (ModifiedCertificateData == FALSE){
1398                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetCertificateContextPointer());
1399                                                                         iter->second = 2;
1400                                                                         break;
1402                                                                 } else {
1404                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer());
1406                                                                 }
1408 #else
1409                                                                 
1410                                                                 // Setup the data to be sent in the wxPostEvent command.
1411                                                                 
1412                                                                 SSLInvalidCertNotifObj SSLICNProcData;
1413                                                                 
1414                                                                 SSLCertCollection certcol = ConnHandle.GetSSLVerifyResults();
1415                                                                 
1416                                                                 bool *PauseMode = new bool;
1417                                                                 QRNotif qrn;
1418                                                                 
1419                                                                 *PauseMode = TRUE;
1420                                                                 qrn.QResponse = &SSLResult;
1421                                                                 qrn.PausePtr = PauseMode;
1422                                                                 
1423                                                                 SSLICNProcData.CertCollection = certcol;
1424                                                                 SSLICNProcData.QRNotifData = &qrn;
1425                                                                 SSLICNProcData.AccountName = AccountNameFriendly;
1426                                                                 
1427                                                                 wxCommandEvent event(INVALIDSSLCERT);
1428                                                                 event.SetClientData(&SSLICNProcData);
1429                                                                 wxPostEvent(frmMainPtrGet, event);
1430                                                                 
1431                                                                 while (*PauseMode == TRUE){
1432                                                                         //nanosleep(&n1, &n2);
1433                                                                         SleepFor(250000000);
1434                                                                 }
1435                                                         
1436                                                                 // Process the response from the user.
1437                                                         
1438                                                                 if (SSLResult == 1){
1439                                                                 
1440                                                                         // Accept the certificate. Write the certificate into the account
1441                                                                         // directory (as server.crt) - will overwrite old certificate.
1442                                                                 
1443                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetSSLVerifyResults());
1444                                                                         WriteServerCertificate(AccountDir, ConnHandle.GetSSLVerifyResults());
1445                                                                 
1446                                                                 } else if (SSLResult == 2){
1447                                                                 
1448                                                                 // Reject the certificate, abort the task and mark as failed.
1449                                                                 
1450                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetSSLVerifyResults());
1451                                                                         iter->second = 2;
1452                                                                         break;
1453                                                                 
1454                                                                 }
1455                                                         
1456 #endif
1457                                                         
1458                                                                 // Resume all the timers.
1459                                                         
1460                                                                 frmMainPtrGet->ResumeAllTimers();
1461                                                                 ExitLoop = TRUE;
1462                                                         
1463                                                         } else {
1464                                                         
1465                                                                 iter->second = 4;
1466                                                                 break;
1467                                                         
1468                                                         }
1469                                                 
1470                                                 } else {
1471                                                 
1472                                                         ExitLoop = TRUE;
1473                                                 
1474                                                 }*/
1475                                         
1476                                         }
1477                                 
1478                                         if (iter->second == 2 || iter->second == 3 || iter->second == 4){
1479                                                 break;
1480                                         }
1481                         
1482 #if defined(__APPLE__)
1483                                 
1484                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
1486 #elif defined(__WIN32__)
1488                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer());
1490 #else
1491                                 
1492                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetSSLVerifyResults());
1493                                 
1494 #endif
1496                                         /*ConnHandle.SetUploadMode(FALSE);
1497                                         ConnHandle.SetupData(wxT("DELETE"), ContactFilename, wxT(""));
1498                                         ConnHandle.ProcessData();
1499                                         
1500                                         SSLCertCollection certcol = ConnHandle.GetCertificateData();
1502                                         // Check if any errors have occured whilst getting the data.
1504                                         int ErrorCode = ConnHandle.GetResultCode();
1506                                         if (ErrorCode != CURLE_OK){
1507                                                 iter->second = 2;
1508                                                 break;
1509                                         }*/
1510                                         
1511                                         COServerResponse DeleteContactResponse = ConnObjectIter->second->DeleteContact(ContactFilename.ToStdString());
1512                                         
1513                                         if (DeleteContactResponse.RequestResult != COREQUEST_OK){
1514                                                 iter->second = 2;
1515                                                 break;
1516                                         }
1517                                 
1518                                         ETagDBPtr->RemoveETag(ContactFilename);
1519                                 
1520                                         iter->second = 4;
1521                                         //CardDAVIter->second = NULL;
1522                                         break;
1523                                 
1524                                 }
1525                         
1526                         } else if (TypeIter->second == 3) {
1528                                 wxString AccountNameFriendly;
1529         
1530                                 int AccountID = 0;
1532                                 for (int i = 0; i < PrefData.accounts.GetCount(); i++){
1533         
1534                                         wxString AccountDirCheck = PrefData.accounts.GetAccountDirectory(i);
1535                 
1536                                         AccountDirCheck.Trim();
1537                                         AccountDirCheck.Append(wxT(".carddav"));
1538         
1539                                         if (AccountDirCheck == StringAccountIter->second){
1540                                         
1541                                                 AccountNameFriendly = PrefData.accounts.GetAccountName(i);
1542                                                 AccountID = i;
1543                 
1544                                         }
1545         
1546                                 }
1547                         
1548                                 bool KeepUpdating = TRUE;
1550                                 while (KeepUpdating == TRUE){
1552                                         StringTaskDetailIter = ActivityListTaskDetail.find(iter->first);
1553                         
1554                                         AccountDir = StringAccountIter->second;
1556                                         ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
1557                                 
1558                                         wxArrayString vCardAdd;
1559                                         wxArrayString vCardDelete;
1560                                         wxArrayString vCardList;
1561                                         wxArrayString vCardUpdateLocal;
1562                                         wxArrayString vCardUpdateRemote;
1563                                         wxArrayString vCardUpdateLog;
1564                                         std::map<wxString,wxString> vCardETag;
1565                                         ContactListData ServerContactList;
1566                                 
1567                                         std::map<wxString,vCardDownloadDataFileClass> vCardDownloadData;
1568                                         //wxArrayString vCardDownload;
1569                                         //std::map<wxString,wxString> vCardDownloadData;
1570                                 
1571                                         // Get the list of vCard files locally.
1572         
1573                                         wxString AccountDirFinal;
1574                                         wxString AccountSyncTokenFilename;
1575                                         wxString SyncTokenLoad;
1576         
1577 #if defined(__HAIKU__)
1578     
1579                                             //preffilename = wxT("noo");
1581 #elif defined(__WIN32__)
1583                                         AccountDirFinal = GetAccountDir(AccountDir, FALSE);
1584                                         AccountSyncTokenFilename = AccountDirFinal;
1585                                         AccountSyncTokenFilename.Append(wxT("synctoken"));
1587 #else
1589                                         AccountDirFinal = GetAccountDir(AccountDir, FALSE);
1590                                         AccountSyncTokenFilename = AccountDirFinal;
1591                                         AccountSyncTokenFilename.Append(wxT("synctoken"));
1592         
1593 #endif
1595                                         // Suppress Error Messages.
1596                                 
1597                                         wxLogNull PleaseDoNotDisturb;
1599                                         wxFFile SyncLoad;
1600                                         SyncLoad.Open(AccountSyncTokenFilename, wxT("r"));
1601                                 
1602                                         if (SyncLoad.IsOpened()){
1603                                 
1604                                                 SyncLoad.ReadAll(&SyncTokenLoad, wxMBConvUTF8());
1605                                                 SyncLoad.Close();
1606                                 
1607                                         }
1609                                         // Get a list of vCard files from the server.
1611                                         // Get the list of vCard files from the ETagDB.
1612                                 
1613                                         std::map<wxString,ETagData> ETagDBData = ETagDBPtr->GetETagData();
1614                                         
1615                                         bool ExitLoop = FALSE;
1617                                         std::map<wxString,FileSyncData> *SCListData = NULL;
1618                                         
1619                                         while (ExitLoop == FALSE){
1620                                 
1621                                                 // Check if any errors have occured whilst getting the data.
1622                                 
1623                                                 int ErrorCode = ConnHandle.SSLVerifyTest();
1624                                 
1625                                                 if (ErrorCode != CURLE_OK){
1626                                         
1627                                                         if (ErrorCode == CURLE_SSL_CACERT ||
1628                                                                 ErrorCode == CURLE_PEER_FAILED_VERIFICATION ||
1629                                                                 ErrorCode == CURLE_SSL_CONNECT_ERROR){
1630                                                 
1631                                                                 // Invalid SSL certificate so bring up a dialog to the user
1632                                                                 // explaining what has happened and the options available.
1633                                                         
1634                                                                 // Stop all the timers.
1635                                                                 
1636                                                                 frmMainPtrGet->PauseAllTimers();
1637                                                         
1638                                                                 int SSLResult;
1640 #if defined(__APPLE__)
1641                                                                 
1642                                                                 // Bring up the trust panel and display the SSL certificate dialog.
1643                                                                 
1644                                                                 SSLResult = DisplayTrustPanel(ConnHandle.GetTrustObject(), AccountNameFriendly);
1645                                 
1646                                                                 // Update the SSL account with the trust object.
1647                                                                 
1648                                                                 if (SSLResult != NSOKButton){
1649                                                                         
1650                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetTrustObject());
1651                                                                         iter->second = 2;
1652                                                                         break;
1653                                                                         
1654                                                                 } else {
1656                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
1657                                                                         
1658                                                                 }
1660 #elif defined(__WIN32__)
1662                                                                 BOOL ModifiedCertificateData;
1663                                                                 CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(&ConnHandle, (HWND)frmMainPtrGet->GetHandle());
1665                                                                 if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)){
1666                                                                         wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog"));
1667                                                                 }
1669                                                                 if (ModifiedCertificateData == FALSE){
1671                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetCertificateContextPointer());
1672                                                                         iter->second = 2;
1673                                                                         break;
1675                                                                 } else {
1677                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer());
1679                                                                 }
1680 #else
1681                                 
1682                                                                 // Setup the data to be sent in the wxPostEvent command.
1684                                                                 SSLInvalidCertNotifObj SSLICNProcData;
1686                                                                 SSLCertCollection certcol = ConnHandle.GetSSLVerifyResults();
1688                                                                 bool *PauseMode = new bool;
1689                                                                 QRNotif qrn;
1691                                                                 *PauseMode = TRUE;                                              
1692                                                                 qrn.QResponse = &SSLResult;
1693                                                                 qrn.PausePtr = PauseMode;
1694                                                                 
1695                                                                 SSLICNProcData.CertCollection = certcol;
1696                                                                 SSLICNProcData.QRNotifData = &qrn;
1697                                                                 SSLICNProcData.AccountName = AccountNameFriendly;
1698                                                         
1699                                                                 wxCommandEvent event(INVALIDSSLCERT);
1700                                                                 event.SetClientData(&SSLICNProcData);
1701                                                                 wxPostEvent(frmMainPtrGet, event);
1702                                         
1703                                                                 /*timespec n1, n2;
1704                                                 
1705                                                                 // Fall asleep until we get an response.
1706                                                 
1707                                                                 n1.tv_sec = 0;
1708                                                                 n1.tv_nsec = 250000000L;*/
1709                                         
1710                                                                 while (*PauseMode == TRUE){
1711                                                                         //nanosleep(&n1, &n2);
1712                                                                         SleepFor(250000000);
1713                                                                 }
1714                                                         
1715                                                                 // Process the response from the user.
1716                                                         
1717                                                                 if (SSLResult == 1){
1718                                                                 
1719                                                                         // Accept the certificate. Write the certificate into the account
1720                                                                         // directory (as server.crt) - will overwrite old certificate.
1722                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetSSLVerifyResults());
1723                                                                         WriteServerCertificate(AccountDir, ConnHandle.GetSSLVerifyResults());
1724                                                                 
1725                                                                 } else if (SSLResult == 2){
1726                                                                 
1727                                                                         // Reject the certificate, abort the task and mark as failed.
1729                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetSSLVerifyResults());
1730                                                                         iter->second = 2;
1731                                                                         break;
1732                                                                 
1733                                                                 }
1734                                                                 
1735 #endif
1736                                                         
1737                                                                 // Resume all the timers.
1738                                                                 
1739                                                                 frmMainPtrGet->ResumeAllTimers();
1740                                                                 ExitLoop = TRUE;
1741                                                 
1742                                                         } else {
1743                                                         
1744                                                                 iter->second = 4;
1745                                                                 break;
1746                                                         
1747                                                         }
1748                                         
1749                                                 } else {
1750                                         
1751                                                         ExitLoop = TRUE;
1752                                         
1753                                                 }
1754                                         
1755                                         }
1756                                         
1757                                         if (iter->second == 2 || iter->second == 3 || iter->second == 4){
1758                                                 break;
1759                                         }
1760                                 
1761 #if defined(__APPLE__)
1762                                         
1763                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
1765 #elif defined(__WIN32__)
1767                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer());
1769 #else
1770                                         
1771                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetSSLVerifyResults());
1772                         
1773 #endif
1774                                         
1775                                         // Look in directory and see which vCards to add and delete
1776                                 
1777                                         // In short:
1778                                         // vCard exists but not in ETagDB - Add (and upload).
1779                                         // vCard missing but in ETagDB - Delete (from server).
1780                                 
1781                                         // Start by looking for vCards that are not in the ETagDB.
1782                                 
1783                                         wxDir AccDir(AccountDirFinal);
1784                                         wxString AccDirFilename;
1785                                 
1786                                         bool ContinueProcess = AccDir.GetFirst(&AccDirFilename, wxEmptyString, wxDIR_DEFAULT);
1787                                 
1788                                         ServerContactList = ConnHandle.GetContactList(SyncTokenLoad.ToUTF8());
1790                                         int ErrorCode = ConnHandle.GetResultCode();
1792                                         if (ErrorCode != CURLE_OK){
1794                                                 iter->second = 4;
1795                                                 break;
1797                                         }
1799                                         SSLCertCollection certcol = ConnHandle.GetCertificateData();
1801                                         // Create a pointer for the std::map<wxString,FileSyncData>.
1803                                         SCListData = &ServerContactList.ListData;
1805                                         // Process the server data.
1807                                         if (SCListData != NULL){
1809                                                 for (std::map<wxString, FileSyncData>::iterator fsiter = SCListData->begin();
1810                                                         fsiter != SCListData->end(); fsiter++){
1812                                                         // Check the mode of the file before adding.
1814                                                         // Get the HTTP status of the file from the list.
1816                                                         FileSyncData fsd = fsiter->second;
1818                                                         if (fsd.DataFlag == 1){
1820                                                                 // Added or modified contact.
1822                                                                 //vCardAdd.Add(fsiter->first, 1);
1824                                                                 vCardDownloadDataFileClass vCardNewData;
1825                                                                 vCardNewData.DataType = 0;
1826                                                                 vCardDownloadData.insert(std::make_pair(fsiter->first, vCardNewData));
1828                                                                 //} else if (fsd.DataFlag == 1){
1830                                                                 // Contact has been modified on the server.
1832                                                                 //      vCardUpdateLocal.Add(fsiter->first, 1);
1834                                                         }
1835                                                         else if (fsd.DataFlag == 2){
1837                                                                 // Contact has been deleted.
1839                                                                 vCardDelete.Add(fsiter->first, 1);
1841                                                         }
1843                                                 }
1845                                         }
1846                                 
1847                                         // Look for vCards that are missing but in the ETagDB.
1848         
1849                                         for (std::map<wxString,ETagData>::iterator etagiter = ETagDBData.begin();
1850                                                 etagiter != ETagDBData.end(); etagiter++){
1851                                 
1852                                                 // Check if the vCard exists.
1853                                         
1854                                                 if (!wxFileExists(AccountDirFinal + etagiter->first)){
1855                                         
1856                                                         // vCard doesn't exist so mark for deleting.
1857                                         
1858                                                         vCardDelete.Add(etagiter->first, 1);
1859                                         
1860                                                 }
1861                                 
1862                                         }
1864                                         // Compare Server with the ETag DB. Work out which
1865                                         // needs to updated remotely and which needs to be
1866                                         // updated locally.
1868                                         for (std::map<wxString,FileSyncData>::iterator srviter = SCListData->begin();
1869                                                 srviter != SCListData->end(); srviter++){
1871                                                 if (ETagDBData.find(srviter->first) == ETagDBData.end()){
1872                                                         continue;
1873                                                 }
1874                                         
1875                                                 std::map<wxString,ETagData>::iterator lociter = ETagDBData.find(srviter->first);
1876                                 
1877                                                 ETagData etd = lociter->second;
1878                                                 FileSyncData fsd = srviter->second;
1879                                         
1880                                                 wxString ETagSrv = fsd.ETagData;
1882                                                 // Check if the local ETag value has 'DELETED' set and skip
1883                                                 // checking this file if it does.
1884                                         
1885                                                 if (etd.ETagValue == "DELETED"){
1886                                                         
1887                                                         continue;
1888                                                         
1889                                                 }
1890                                                 
1891                                                 // Compare local ETag with original local ETag.
1892                                                 // If different, update to server is required.
1893                                 
1894                                                 if (etd.ETagValue != etd.ETagOrigValue){
1895                                 
1896                                                         // Check if local original ETag is different from server ETag.
1897                                                         // If it is then throw up a conflict resolution dialog.
1898                                 
1899                                                         if (etd.ETagOrigValue != ETagSrv){
1900                                         
1901                                                                 vCard34Conv vCard34Obj;
1902                                                 
1903                                                                 wxString ServerContactData;
1904                                                                 wxString FullFilename;
1905                                                                 vCard ClientData;
1906                                                                 vCard ConvertedV4Data;
1907                                         
1908                                                                 // Conflict. Bring up conflict resolution dialog.
1909                                                         
1910                                                                 // Get the server contact data for comparison.
1911                                                         
1912                                                                 ConnHandle.SetServerFilename(srviter->first);
1913                                                                 ConnHandle.GetServerContactData();
1914                                                                 ServerContactData = ConnHandle.GetPageData();
1915                                                         
1916                                                                 FullFilename = CreateFilenamePath(AccountDirFinal, srviter->first);
1917                                                         
1918                                                                 // Convert it to v4.
1919                                         
1920                                                                 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
1921                                         
1922                                                                 vCardConflictObj vCardProcData;
1923                                         
1924                                                                 vCardProcData.vCardLocalData = &ClientData;
1925                                                                 vCardProcData.vCardServerData = &ConvertedV4Data;
1926                                                         
1927                                                                 // Load the client data from the filename given.
1928                                                         
1929                                                                 ClientData.LoadFile(FullFilename);
1930                                                         
1931                                                                 // Show dialog.
1932                                         
1933                                                                 bool *PauseMode = new bool;
1934                                                                 int ConflictResult;
1935                                                                 QRNotif qrn;
1936                                                                 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
1938                                                                 *PauseMode = TRUE;
1939                                                                 qrn.QResponse = &ConflictResult;
1940                                                                 qrn.PausePtr = PauseMode;
1941                                                 
1942                                                                 vCardProcData.QRNotifData = &qrn;
1943                                         
1944                                                                 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
1945                                                                 event.SetClientData(&vCardProcData);
1946                                                                 wxPostEvent(frmMainPtrGet, event);
1947                                                 
1948                                                                 /*timespec n1, n2;
1949                                                 
1950                                                                 n1.tv_sec = 0;
1951                                                                 n1.tv_nsec = 250000000L;*/
1952                                                 
1953                                                                 while (*PauseMode == TRUE){
1954                                                                         //nanosleep(&n1, &n2);
1955                                                                         SleepFor(250000000);
1956                                                                 }
1957                                         
1958                                                                 delete PauseMode;
1959                                                                 PauseMode = NULL;
1960                                                         
1961                                                                 // If replacing local version, store copy for now.
1962                                                                 // Otherwise upload to server.
1963                                         
1964                                                                 if (ConflictResult == 0){
1965                                         
1966                                                                         // Decide Later.
1967                                         
1968                                                                         continue;
1969                                         
1970                                                                 } else if (ConflictResult == 1){
1971                                         
1972                                                                         // Decided to use client version.
1973                                         
1974                                                                         vCardUpdateLocal.Remove(srviter->first);
1975                                                                         vCardUpdateRemote.Add(srviter->first, 1);                                                               
1976                                         
1977                                                                 } else if (ConflictResult == 2){
1978                                         
1979                                                                         // Decided to use server version.
1980                                                                         // Store the converted downloaded copy for
1981                                                                         // processing later.
1983                                                                         //vCardUpdateLocal.Add(srviter->first, 1);
1984                                                                 
1985                                                                         vCardDownloadDataFileClass vCardNewData;
1986                                                                         vCardNewData.DataType = 1;
1987                                                                         vCardNewData.FileData = ConvertedV4Data.WriteString();
1989                                                                         ConvertedV4Data.WriteFile(FullFilename);
1990                                                                 
1991                                                                         vCardDownloadData.insert(std::make_pair(srviter->first, vCardNewData)); 
1992                                                                 
1993                                                                 
1994                                                                 
1995                                                                 }
1996                                         
1997                                                         } else {
1998                                         
1999                                                                 // Send vCard to the server.
2000                                                 
2001                                                                 vCardUpdateRemote.Add(srviter->first, 1);
2002                                         
2003                                                         }
2004                                 
2005                                                 } else {
2006                                 
2007                                                         // Check if local ETag is different from server ETag.
2008                                                         // If different, obtain the vCard from the server.
2009                                         
2010                                                         if (etd.ETagOrigValue != ETagSrv){
2011                                         
2012                                                                 vCardUpdateLocal.Add(srviter->first, 1);
2013                                         
2014                                                         }
2015                                 
2016                                                 }
2017                         
2018                                         }
2019                                 
2020                                         // Process the vCards that need to be downloaded and added/overwritten.
2021                                 
2022                                         wxString vCardFilenameFinal;
2023                                         wxString vCardOutputData;
2024                                         wxString vCardInputData;
2025                                         wxString ETagFileData;
2026                                         wxFFile vCardFile;
2027                                 
2028                                         for (std::map<wxString,vCardDownloadDataFileClass>::iterator additer = vCardDownloadData.begin();
2029                                                 additer != vCardDownloadData.end(); additer++){
2030                                         
2031                                                 vCardFilenameFinal.Clear();
2032                                                 vCardInputData.Clear();
2033                                                 vCardOutputData.Clear();
2034                                                 ETagFileData.Clear();
2035                                         
2036                                                 vCardFilenameFinal = CreateFilenamePath(AccountDirFinal, additer->first);
2037                                         
2038                                                 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
2039                                         
2040                                                 if (additer->second.DataType == 0){
2041                                         
2042                                                         vCard ConvertedV4Data;
2043                                         
2044                                                         // Grab the file from the server and write the contact out.
2045                                         
2046                                                         vCard34Conv vCard34Obj;
2047                                                 
2048                                                         ConnHandle.SetServerFilename(additer->first);
2049                                                         ConnHandle.GetServerContactData();
2050                                                         vCardInputData = ConnHandle.GetPageData();
2051                                                 
2052                                                         vCard34Obj.ConvertToV4(&vCardInputData, &ConvertedV4Data);
2053                                                 
2054                                                         ConvertedV4Data.WriteFile(vCardFilenameFinal);
2055                                                 
2056                                                         // Update the ETagDB.
2057                                                 
2058                                                         //vCardFile.Open(vCardFilenameFinal, wxT("w"));
2059                                 
2060                                                         //if (vCardFile.IsOpened()){
2061                                 
2062                                                         //      vCardFile.Write(vCardOutputData, wxConvAuto());
2063                                                         //      vCardFile.Close();
2064                                 
2065                                                         //}
2066                                                 
2067                                                         // Get the server ETag.
2068                                                 
2069                                                         wxString ServerETag;
2070                                                         ConnHandle.GetServerETagValueThread();
2071                                                         ServerETag = ConnHandle.ETagValueResult();
2072                                                 
2073                                                         // Add to the ETag Database.
2074                                                 
2075                                                         ETagDBPtr->AddETag(additer->first, ServerETag, ServerETag);
2076                                                 
2077                                                 } else if (additer->second.DataType == 1){
2078                                         
2079                                                         // Write out the contact to the account directory.
2080                                         
2081                                                         vCardFilenameFinal = CreateFilenamePath(AccountDirFinal, additer->first);
2082                                                         vCardOutputData = additer->second.FileData;
2083                                                 
2084                                                         vCardFile.Open(vCardFilenameFinal, wxT("w"));
2085                                 
2086                                                         if (vCardFile.IsOpened()){
2087                                 
2088                                                                 vCardFile.Write(vCardOutputData, wxConvAuto());
2089                                                                 vCardFile.Close();
2090                                 
2091                                                         }
2092                                                 
2093                                                         // Update the ETagDB.
2095                                                         wxString ServerETag;
2096                                                         ConnHandle.GetServerETagValueThread();
2097                                                         ServerETag = ConnHandle.ETagValueResult();
2098                                                 
2099                                                         // Add to the ETag Database.
2100                                                 
2101                                                         ETagDBPtr->AddETag(additer->first, ServerETag, ServerETag);
2102                                                                                         
2103                                                 }
2104                                         }
2105         
2106                                         // Look for vCard files which aren't in the ETagDB.
2107         
2108                                         while(ContinueProcess){
2109                                 
2110                                                 // Check and make sure that the filename ends in .vcf/.vcard
2111                                                 // Skip any file that beings with a dot.
2112                                         
2113                                                 if (AccDirFilename.Left(1) == wxT(".")){
2114                                         
2115                                                         ContinueProcess = AccDir.GetNext(&AccDirFilename);
2116                                                         continue;
2117                                         
2118                                                 }
2119                                         
2120                                                 if (AccDirFilename.Right(4) != wxT(".vcf") && 
2121                                                 AccDirFilename.Right(6) != wxT(".vcard")){
2122                                         
2123                                                         ContinueProcess = AccDir.GetNext(&AccDirFilename);
2124                                                         continue;
2125                                         
2126                                                 }
2127                                 
2128                                                 // Look in the ETagDB for the file.
2129                                         
2130                                                 bool ETagExists = ETagDBPtr->CheckETagExists(AccDirFilename);
2131                                         
2132                                                 if (ETagExists == FALSE){
2133                                         
2134                                                         // Add the vCard to the list to be added.
2135                                                 
2136                                                         vCardAdd.Add(AccDirFilename, 1);
2137                                         
2138                                                 }
2139                                         
2140                                                 ContinueProcess = AccDir.GetNext(&AccDirFilename);
2141                                 
2142                                         }
2143                                 
2144                                         // Process the vCards to add/update to the server.
2145                                 
2146                                         for (int vi = 0; vi < vCardAdd.GetCount(); vi++){
2148                                                 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
2149                                                 ETag = ETagDBPtr->GetETag(vCardAdd[vi]);
2150                                                 ETagOriginal = ETagDBPtr->GetETagOriginal(vCardAdd[vi]);
2151                                                 
2152                                                 ContactFilename = vCardAdd[vi];
2153                                                 FullFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
2155                                                 ContactFilename.Trim();
2156                         
2157                                                 if (ETag == ETagOriginal && ETagDBPtr->ETagExists(vCardAdd[vi])){
2158                         
2159                                                         // Compare the ETag with the Server ETag.
2160                                                 
2161                                                         ConnHandle.SetServerFilename(vCardAdd[vi]);
2162                                                         ConnHandle.GetServerETagValueThread();
2163                                                         ETagServer = ConnHandle.ETagValueResult();
2164                                 
2165                                                         if (ETagOriginal != ETagServer){
2166                                 
2167                                                                 // Server ETag is different from original ETag.
2168                                                                 // This is a conflict which the user will now
2169                                                                 // need to resolve.
2170                                         
2171                                                                 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
2172                                         
2173                                                                 vCard34Conv vCard34Obj;
2174                                                 
2175                                                                 wxString ServerContactData;
2176                                                                 vCard ClientData;
2177                                                                 vCard ConvertedV4Data;
2178                                         
2179                                                                 // Load the client data from the filename given.
2180                                         
2181                                                                 ConnHandle.GetServerContactData();
2182                                                                 ServerContactData = ConnHandle.GetPageData();
2183                                                 
2184                                                                 // Process v3 version into v4 version.
2185                                                 
2186                                                                 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
2187                                         
2188                                                                 vCardConflictObj vCardProcData;
2189                                         
2190                                                                 vCardProcData.vCardLocalData = &ClientData;
2191                                                                 vCardProcData.vCardServerData = &ConvertedV4Data;
2192                                                                 ClientData.LoadFile(FullFilename);
2194                                                                 //ContactConflictEvent event(ContactConflictCmdEnv);
2195                                                                 //event.SetData(ContactFilename, Moo1, Moo2);
2196                                         
2197                                                                 //wxPostEvent(frmMainPtrGet, event);
2198                                         
2199                                                                 // Setup Conflict Resolution Dialog.
2200                                         
2201                                                                 // Fetch Data from Server and convert.
2202                                         
2203                                                                 bool *PauseMode = new bool;
2204                                                                 int ConflictResult;
2205                                                                 QRNotif qrn;
2207                                                                 *PauseMode = TRUE;                                              
2208                                                                 qrn.QResponse = &ConflictResult;
2209                                                                 qrn.PausePtr = PauseMode;
2210                                                 
2211                                                                 vCardProcData.QRNotifData = &qrn;
2212                                         
2213                                                                 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
2214                                                                 event.SetClientData(&vCardProcData);
2215                                                                 wxPostEvent(frmMainPtrGet, event);
2216                                                 
2217                                                                 /*timespec n1, n2;
2218                                                 
2219                                                                 n1.tv_sec = 0;
2220                                                                 n1.tv_nsec = 250000000L;*/
2221                                                 
2222                                                                 while (*PauseMode == TRUE){
2223                                                                         //nanosleep(&n1, &n2);
2224                                                                         SleepFor(250000000);
2225                                                                 }
2226                                         
2227                                                                 delete PauseMode;
2228                                                                 PauseMode = NULL;
2229                                         
2230                                                                 //intResult = frmMainPtrGet->ShowConflictDialog(&Moo1, &Moo2);
2231                                         
2232                                                                 if (ConflictResult == 0){
2233                                         
2234                                                                         // Decide Later.
2235                                         
2236                                                                         iter->second = 4;
2237                                                                         continue;
2238                                         
2239                                                                 } else if (ConflictResult == 1){
2240                                         
2241                                                                         // Decided to use client version.
2242                                         
2243                                                                         ConnHandle.ProcessData();
2244                                                 
2245                                                                         iter->second = 4;
2246                                         
2247                                                                 } else if (ConflictResult == 2){
2248                                         
2249                                                                         // Decided to use server version.
2250                                                 
2251                                                                         // Download server version.
2252                                                                 
2253                                                                         ConvertedV4Data.WriteFile(CreateFilenamePath(AccountDirFinal, vCardAdd[vi]));
2254                                                 
2255                                                                         iter->second = 4;
2256                                         
2257                                                                 }
2258                                 
2259                                                         } else {
2260                                 
2261                                                                 // Setup the filename for the contact being added.
2262                                                         
2263                                                                 wxString wxSFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
2264                                                                 wxString wxSCardData;
2265                                                                 wxString TaskData;
2266                                                                 //wxString TaskURL;
2267                                                         
2268                                                                 // Load the data from the file.
2269                                                         
2270                                                                 wxFFile wxFCard;
2271                                                                 wxFCard.Open(wxSFilename, wxT("r"));
2272                                 
2273                                                                 if (wxFCard.IsOpened()){
2274                                 
2275                                                                         wxFCard.ReadAll(&wxSCardData, wxConvAuto());
2276                                                                         wxFCard.Close();
2277                                 
2278                                                                 }
2279                                                         
2280                                                                 // Convert the data to v3.
2281                                                         
2282                                                                 vCard34Conv vCard34Obj;
2283                                                         
2284                                                                 vCard34Obj.ConvertToV3(wxSFilename, &TaskData);
2285                                                         
2286                                                                 // Setup the URL address.
2287                                                         
2288                                                                 //TaskURL = StringTaskDetailIter->second + wxT("/") + vCardAdd[vi];
2290                                                                 // Upload the data to the server.
2291                                         
2292                                                                 ConnHandle.SetUploadMode(TRUE);
2293                                                                 ConnHandle.SetupData(wxT("PUT"), vCardAdd[vi], TaskData);
2294                                                                 ConnHandle.ProcessData();
2295                                                         
2296                                                                 // Get the Server ETag and put it in the ETag database.
2297                                                         
2298                                                                 ConnHandle.SetServerFilename(vCardAdd[vi]);
2299                                                                 ConnHandle.GetServerETagValueThread();
2300                                                                 ETagServer = ConnHandle.ETagValueResult();
2301                                 
2302                                                                 ETagDBPtr->AddETag(vCardAdd[vi], ETagServer, ETagServer);
2303                                 
2304                                                         }
2305                         
2306                                                 } else {
2307                         
2308                                                         if (ETagOriginal != ETagServer){
2309                                 
2310                                                                 // Server ETag is different from original ETag.
2311                                                                 // This is a conflict which the user will now
2312                                                                 // need to resolve.
2313                                         
2314                                                                 frmMain *frmMainPtrGet = (frmMain *)frmMainPtr;
2315                                         
2316                                                                 //ContactConflictEvent event(ContactConflictCmdEnv);
2317                                                                 //event.SetData(ContactFilename, Moo1, Moo2);
2318                                         
2319                                                                 vCard34Conv vCard34Obj;
2320                                                 
2321                                                                 wxString ServerContactData;
2322                                                                 vCard ClientData;
2323                                                                 vCard ConvertedV4Data;
2324                                         
2325                                                                 // Load the client data from the filename given.
2326                                         
2327                                                                 ConnHandle.GetServerContactData();
2328                                                                 ServerContactData = ConnHandle.GetPageData();
2329                                                                 ClientData.LoadFile(FullFilename);
2330                                                 
2331                                                                 // Process v3 version into v4 version.
2332                                                 
2333                                                                 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
2334                                         
2335                                                                 vCardConflictObj vCardProcData;
2336                                         
2337                                                                 vCardProcData.vCardLocalData = &ClientData;
2338                                                                 vCardProcData.vCardServerData = &ConvertedV4Data;
2339                                         
2340                                                                 bool *PauseMode = new bool;
2341                                                                 int ConflictResult;
2342                                                                 QRNotif qrn;
2344                                                                 *PauseMode = TRUE;                                              
2345                                                                 qrn.QResponse = &ConflictResult;
2346                                                                 qrn.PausePtr = PauseMode;
2347                                                 
2348                                                                 vCardProcData.QRNotifData = &qrn;
2349                                         
2350                                                                 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
2351                                                                 event.SetClientData(&vCardProcData);
2352                                                                 wxPostEvent(frmMainPtrGet, event);
2353                                         
2354                                                                 /*timespec n1, n2;
2355                                                 
2356                                                                 n1.tv_sec = 0;
2357                                                                 n1.tv_nsec = 250000000L;*/
2358                                         
2359                                                                 while (*PauseMode == TRUE){
2360                                                                         //nanosleep(&n1, &n2);
2361                                                                         SleepFor(250000000);
2362                                                                 }
2363                                         
2364                                                                 delete PauseMode;
2365                                                                 PauseMode = NULL;
2366                                         
2367                                                                 //intResult = frmMainPtrGet->ShowConflictDialog(&Moo1, &Moo2);
2368                                         
2369                                                                 if (ConflictResult == 0){
2370                                         
2371                                                                         // Decide Later.
2372                                         
2373                                                                         iter->second = 4;
2374                                                                         continue;
2375                                         
2376                                                                 } else if (ConflictResult == 1){
2377                                         
2378                                                                         // Decided to use client version.
2379                                                                 
2380                                                                         ConnHandle.ProcessData();
2381                                                                         //ETagServer = CardDAVIter->second.GetServerETagValueThread();
2382                                                                         //ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
2383                                                 
2384                                                                         iter->second = 4;
2385                                         
2386                                                                 } else if (ConflictResult == 2){
2387                                         
2388                                                                         // Decided to use server version.
2389                                                 
2390                                                                         // Write server version to file.
2391                                                                 
2392                                                                         ConvertedV4Data.WriteFile(CreateFilenamePath(AccountDirFinal, vCardAdd[vi]));
2393                                                 
2394                                                                         iter->second = 4;
2395                                         
2396                                                                 }
2397                                 
2398                                                         } else {
2399                                 
2400                                                                 // Setup the filename for the contact being added.
2401                                                         
2402                                                                 wxString wxSFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
2403                                                                 wxString wxSCardData;
2404                                                                 wxString TaskData;
2405                                                                 //wxString TaskURL;
2406                                                         
2407                                                                 // Load the data from the file.
2408                                                         
2409                                                                 wxFFile wxFCard;
2410                                                                 wxFCard.Open(wxSFilename, wxT("r"));
2411                                 
2412                                                                 if (wxFCard.IsOpened()){
2413                                 
2414                                                                         wxFCard.ReadAll(&wxSCardData, wxConvAuto());
2415                                                                         wxFCard.Close();
2416                                 
2417                                                                 }
2418                                                         
2419                                                                 // Convert the data to v3.
2420                                                         
2421                                                                 vCard34Conv vCard34Obj;
2422                                                         
2423                                                                 vCard34Obj.ConvertToV3(wxSFilename, &TaskData);
2424                                                         
2425                                                                 // Setup the URL address.
2426                                                         
2427                                                                 //TaskURL = StringTaskDetailIter->second + wxT("/") + vCardAdd[vi];
2429                                                                 // Upload the data to the server.
2430                                         
2431                                                                 ConnHandle.SetUploadMode(TRUE);
2432                                                                 ConnHandle.SetupData(wxT("PUT"), vCardAdd[vi], TaskData);
2433                                                                 ConnHandle.ProcessData();
2434                                                         
2435                                                                 // Get the Server ETag and put it in the ETag database.
2436                                                         
2437                                                                 ConnHandle.SetServerFilename(vCardAdd[vi]);
2438                                                                 ConnHandle.GetServerETagValueThread();
2439                                                                 ETagServer = ConnHandle.ETagValueResult();
2440                                 
2441                                 
2442                                                                 ETagDBPtr->AddETag(vCardAdd[vi], ETagServer, ETagServer);
2443                                 
2444                                                         }
2445                                         
2446                                                 }
2448                                         }                       
2449                                 
2450                                         // Process the vCards to delete locally.
2451                                 
2452                                         for (int vi = 0; vi < vCardDelete.GetCount(); vi++){
2454                                                 if (!wxRemoveFile(CreateFilenamePath(AccountDirFinal, vCardDelete[vi]))){
2456                                                 } else {
2457                                         
2458                                                         ETagDBPtr->RemoveETag(vCardDelete[vi]);
2459                                         
2460                                                 }
2462                                         }
2463                                 
2464                                         // Process the vCards to delete from the server.
2465                                 
2466                                         std::map<wxString,wxString> *ETagFilenameMap = ETagDBPtr->GetFilenamePointer();
2467                                         std::list<wxString> DeleteList;
2468                                 
2469                                         for (std::map<wxString,wxString>::iterator deliter = ETagFilenameMap->begin();
2470                                                 deliter != ETagFilenameMap->end(); deliter++){
2471                                 
2472                                                 // Look through the ETagDB and find contacts which are marked as DELETED.
2473                                         
2474                                                 if (deliter->second == wxT("DELETED")){
2476                                                         ConnHandle.SetUploadMode(FALSE);
2477                                                         ConnHandle.SetupData(wxT("DELETE"), deliter->first, wxT(""));
2478                                                         ConnHandle.ProcessDataThread();
2479                                         
2480                                                         // Delete the ETag as the file has now been deleted.
2481                                         
2482                                                         DeleteList.push_back(deliter->first);
2483                                         
2484                                                 }
2485                                 
2486                                         }
2487                                         
2488                                         for (std::list<wxString>::iterator removeetagiter = DeleteList.begin();
2489                                              removeetagiter != DeleteList.end(); removeetagiter++){
2490                                         
2491                                                 ETagDBPtr->RemoveETag(*removeetagiter);
2492                                                 
2493                                         }
2494                                 
2495                                         // Write out the update server sync token.
2497                                         wxString ServerSyncToken = ServerContactList.SyncToken;
2498                                 
2499                                         ServerSyncToken.Trim();
2500                                 
2501                                         if (!ServerSyncToken.IsEmpty()){
2502                                 
2503                                                 wxFFile SyncWrite;
2504                                                 SyncWrite.Open(AccountSyncTokenFilename, wxT("w"));
2505                                 
2506                                                 if (SyncWrite.IsOpened()){
2507                                 
2508                                                         SyncWrite.Write(ServerSyncToken, wxConvAuto());
2509                                                         SyncWrite.Close();
2510                                 
2511                                                 }
2512                                 
2513                                         }
2514                                 
2515                                         // Check for another sync token. If there is another 
2516                                         // sync token then repeat this. If token matches then stop processing.
2517                                 
2518                                         if (SyncTokenLoad == ServerSyncToken){
2519                                         
2520                                                 KeepUpdating = FALSE;
2521                                         
2522                                         }
2523                                         
2524                                 }
2525                                 
2526                                 // Mark as completed.
2527                         
2528                                 wxString AccountNameFinal;
2529                                 AccountNameFinal = PrefData.accounts.GetAccountDirectory(AccountID);
2530                                 AccountNameFinal.Append(wxT(".carddav"));
2531                                 
2532                                 wxCommandEvent reloadevent(RELOADCONTACTLIST);
2533                                 reloadevent.SetString(AccountNameFinal);
2534                                 wxPostEvent(this->GetParent(), reloadevent);
2535                                 
2536                                 iter->second = 4;
2537                                 continue;
2538                         
2539                         } else {
2540                         
2541                                 // Update the data to the server.
2542                                         
2543                                 ConnHandle.ProcessData();
2544                                 iter->second = 4;
2545                                 continue;
2546                         
2547                         }
2549                         /*timespec n1, n2;
2550                                                 
2551                         n1.tv_sec = 0;
2552                         n1.tv_nsec = 250000000L;*/
2554                         while (iter->second == 1){
2556                                 SleepFor(125000000);
2557                                 //nanosleep(&n1, &n2);
2558         
2559                         }
2560                         
2561                         /*if ((iter->second == 4 && TypeIter->second == 0) || 
2562                         (iter->second == 8 && TypeIter->second == 0)){
2564                                 AccountDir = StringAccountIter->second;
2565                                 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
2566                                 
2567                                 ConnHandle.GetServerETagValueThread();
2568                                 ETagServer = ConnHandle.ETagValueResult();
2569                                 ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
2570                         
2571                         }
2572                         
2573                         if ((iter->second == 4 && TypeIter->second == 1) || 
2574                         (iter->second == 8 && TypeIter->second == 1)){
2575                         
2576                                 AccountDir = StringAccountIter->second;
2577                                 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);                 
2579                                 ConnHandle.GetServerETagValueThread();
2580                                 ETagServer = ConnHandle.ETagValueResult();
2581                                 ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
2582                         
2583                         }*/
2584                         
2585                         break;
2586                         
2587                 }
2589         }
2590         
2591         if (TasksFoundProc == FALSE){
2592         
2593                 TasksActive = FALSE;
2594                 ProcessTasksData = FALSE;
2595         
2596         } else {
2598                 wxCommandEvent eventp(ACTMGR_STARTTIMER);
2599                 wxPostEvent(this, eventp);
2601                 //AnimationTimer.StartAnimation();
2602                 //ActListProcTimer.Start();
2603         
2604         }
2605         
2606         wxCommandEvent event(ACTMGR_STARTPROCESSTIMER);
2607         wxPostEvent(this, event);
2609         //ActProcessTimer.Start();
2613 void frmActivityMgr::ProcessTasks()
2615         
2616         std::thread ProcessThread(&frmActivityMgr::ProcessTasksThread, this);
2617         ProcessThread.detach();
2621 void frmActivityMgr::SetupPointers(wxETagProcessTimer *ETagTmrPtrInc, void *frmMainPtrInc)
2624         ETagTmrPtr = ETagTmrPtrInc;
2625         
2626         frmMainPtr = frmMainPtrInc;
2630 void frmActivityMgr::ResumeProcessing(wxCommandEvent &event){
2632         QRNotif *qrn = (QRNotif *)event.GetClientData(); 
2633         
2634         int *QRes = qrn->QResponse;
2636         *qrn->PausePtr = FALSE;
2638         *QRes = event.GetInt();
2639         
2642 void frmActivityMgr::ToggleConnectionStatus( wxCommandEvent &event ){
2644         wxCommandEvent connevent(CONNSTAT_UPDATE);
2645         
2646         if (ApplicationSleepMode == FALSE){
2647         
2648                 connevent.SetInt(1);
2649                 ApplicationSleepMode = TRUE;
2650                 mnuSleepMode->Check(true);
2651         
2652         } else {
2653         
2654                 connevent.SetInt(0);
2655                 ApplicationSleepMode = FALSE;
2656                 mnuSleepMode->Check(false);
2657                 
2658                 wxCommandEvent event(ACTMGR_STARTTIMER);
2659                 wxPostEvent(this, event);
2661                 wxCommandEvent eventp(ACTMGR_STARTPROCESSTIMER);
2662                 wxPostEvent(this, eventp);
2663         
2664         }
2666         wxPostEvent(GetParent(), connevent);
2670 void frmActivityMgr::SleepMode( wxCommandEvent &event ){
2671         
2672         wxCommandEvent connevent(ACTMGR_TOGGLECONN);
2673         
2674         wxPostEvent(this, connevent);
2675         
2678 void frmActivityMgr::WriteServerCertificate(wxString AccountName, SSLCertCollection SSLCertInc){
2680         wxString ServerCertFinal;
2682         // Get the Cert section of the certificate and write it to the file.
2684         ServerCertFinal = GetAccountDir(AccountName, TRUE);
2686         wxFile CertFile;
2687         
2688         std::map<int, SSLCertData>::iterator SSLCDIter = SSLCertInc.SSLCollection.find(0);
2689         std::multimap<wxString,wxString>::iterator SSLDataIter = SSLCDIter->second.CertData.find(wxT("Cert"));
2690         
2691         CertFile.Open(ServerCertFinal, wxFile::write);  
2692         
2693         CertFile.Write(SSLDataIter->second, wxConvUTF8);
2694         CertFile.Close();
2698 void frmActivityMgr::WriteServerCertificate(wxString AccountName, SSLCertCollectionString SSLCertInc){
2700         wxString ServerCertFinal;
2702         // Get the Cert section of the certificate and write it to the file.
2704         ServerCertFinal = GetAccountDir(AccountName, TRUE);
2706         wxFile CertFile;
2707         
2708         std::map<int, SSLCertDataString>::iterator SSLCDIter = SSLCertInc.SSLCollection.find(0);
2709         std::multimap<string,string>::iterator SSLDataIter = SSLCDIter->second.CertData.find("Cert");
2710         
2711         CertFile.Open(ServerCertFinal, wxFile::write);  
2712         
2713         CertFile.Write(SSLDataIter->second, wxConvUTF8);
2714         CertFile.Close();
2718 void frmActivityMgr::StartTimer(wxCommandEvent& event){
2720         ActListProcTimer.Start(1000, FALSE);
2724 void frmActivityMgr::StopTimer(wxCommandEvent& event){
2726         ActListProcTimer.Stop();
2730 void frmActivityMgr::StartProcessTimer(wxCommandEvent& event){
2732         ActProcessTimer.Start(1000, FALSE);
2736 void frmActivityMgr::StopProcessTimer(wxCommandEvent& event){
2738         ActProcessTimer.Stop();
2742 void frmActivityMgr::StartAnimationTimer(wxCommandEvent& event){
2743         
2744         AnimationTimer.StartAnimation();
2745         
2748 void frmActivityMgr::UpdateStatusLabel(wxCommandEvent& event){
2750         ActivityMgrLabelUpdate *actmgrudata = (ActivityMgrLabelUpdate*)event.GetClientData();
2751         
2752         if (actmgrudata != NULL){
2753         
2754                 lstActivity->SetItem(actmgrudata->ItemIndex, 2, actmgrudata->ItemLabel);
2755         
2756                 /*if (!actmgrudata->ItemDes.IsEmpty()){
2757                 lstActivity->SetItem(actmgrudata->ItemIndex, 0, actmgrudata->ItemDes);
2758                 }*/
2759         
2760                 delete actmgrudata;
2761                 actmgrudata = NULL;
2762         
2763         }
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy