Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Implemented EditContact and GetContact in CardDAV2
[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                                         ETagDBPtr->AddETag(ContactFilename, ETagGetResponse.EntityTag, ETagGetResponse.EntityTag);
655                                         
656                                         iter->second = 4;
657                                         break;
658                                         
659                                 }
660                                 
661                         } else if (TypeIter->second == 1){
662                                 
663                                 // Update a contact.
664                                 
665                                 StringDataIter = ActivityListData.find(iter->first);
666                                 StringURLIter = ActivityListURL.find(iter->first);
667                                 
668                                 AccountDir = StringAccountIter->second;
669                                 ContactFilename = StringFilenameIter->second;
670                                 wxString AccountNameFriendly;
671                                 
672                                 int AccountID = 0;
673                                 
674                                 for (int i = 0; i < PrefData.accounts.GetCount(); i++){
675                                         
676                                         wxString AccountDirCheck = PrefData.accounts.GetAccountDirectory(i);
677                                         
678                                         AccountDirCheck.Trim();
679                                         AccountDirCheck.Append(wxT(".carddav"));
680                                         
681                                         if (AccountDirCheck == StringAccountIter->second){
682                                                 
683                                                 AccountNameFriendly = PrefData.accounts.GetAccountName(i);
684                                                 AccountID = i;
685                                                 
686                                         }
687                                         
688                                 }
689                                 
690                                 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
691                                 
692                                 ETag = StringETagIter->second;
693                                 ETagOriginal = StringETagOrigIter->second;
694                                 AccountDir = StringAccountIter->second;
695                                 ContactFilename = StringFilenameIter->second;
696                                 FullFilename = StringFullFilenameIter->second;
697                                 EditMode = ActivityListEditMode.find(iter->first)->second;
698                                 
699                                 bool KeepUpdating = true;
700                                 
701                                 while(KeepUpdating == true){
702                                         
703                                         COConnectResult ConnectResponse = ConnObjectIter->second->Connect(false);
704                                         
705                                         bool ExitLoop = false;
706                                         
707                                         while(ExitLoop == false){
708                                                 
709                                                 if (ConnObjectIter->second->SSLVerify() == COSSL_UNABLETOVERIFY){
710                                                         
711                                                         frmMainPtrGet->PauseAllTimers();
712                                                         
713 #if defined(__APPLE__)
714 #elif defined(__WIN32__)
715 #else
716         
717                                                         bool UsingSSLBypass = false;
718                                                         int SSLResult = 0;
719                                                         
720                                                         // Connect again and fetch SSL certificate information.
721                 
722                                                         ConnObjectIter->second->BypassSSLVerification(true);
723                 
724                                                         COConnectResult ConnectionSSLResult = ConnObjectIter->second->Connect(false);
726                                                         ConnObjectIter->second->BypassSSLVerification(false);
728                                                         SSLInvalidCertNotifObjString SSLICNProcData;
729                                                         
730                                                         SSLCertCollectionString certcol = ConnObjectIter->second->BuildSSLCollection();
731                                                                 
732                                                         bool *PauseMode = new bool;
733                                                         QRNotif qrn;
734                                                                 
735                                                         *PauseMode = TRUE;
736                                                         qrn.QResponse = &SSLResult;
737                                                         qrn.PausePtr = PauseMode;
738                                                                 
739                                                         SSLICNProcData.CertCollection = certcol;
740                                                         SSLICNProcData.QRNotifData = &qrn;
741                                                         SSLICNProcData.AccountName = AccountNameFriendly;
742                                                                 
743                                                         wxCommandEvent event(INVALIDSSLCERTSTRING);
744                                                         event.SetClientData(&SSLICNProcData);
745                                                         wxPostEvent(frmMainPtrGet, event);
746                                                                 
747                                                         while (*PauseMode == TRUE){
748                                                                 //nanosleep(&n1, &n2);
749                                                                 SleepFor(250000000);
750                                                         }
751                                                         
752                                                         // Process the response from the user.
753                                                         
754                                                         if (SSLResult == 1){
755                                                                 
756                                                                 // Accept the Certificate.
758                                                                 UsingSSLBypass = true;
759                                                                 ConnObjectIter->second->BypassSSLVerification(true);
760                 
761                                                                 COConnectResult TestConnectionResult = ConnObjectIter->second->Connect(true);
762                                                                 WriteServerCertificate(AccountDir, certcol);
763                                                                 
764                                                                 ConnObjectIter->second->BypassSSLVerification(false);
765                                                                 
766                                                         } else if (SSLResult == 2){
767                                                 
768                                                                 // Reject the certificate, abort the task and mark as failed.
770                                                                 iter->second = 2;
771                                                                 break;
772                                                                 
773                                                         }
774                 
775 #endif
776                                                         
777                                                         frmMainPtrGet->ResumeAllTimers();
778                                                         ExitLoop = true;
779                                                         
780                                                 } else if (ConnectResponse == COCONNECT_AUTHFAIL){
781                                                         
782                                                         ConnectResponse = ConnObjectIter->second->Connect(true);
783                                                         
784                                                         if (ConnectResponse == COCONNECT_OK){
785                                                                 
786                                                                 ExitLoop = true;
787                                                                 break;
788                                                                 
789                                                         } else {
790                                                                 
791                                                                 ExitLoop = true;                                                        
792                                                                 iter->second = 2;
793                                                                 break;
794                                                                 
795                                                         }
796                                                         
797                                                 } else if (ConnectResponse == COCONNECT_OK){
798                                                         
799                                                         ConnectResponse = ConnObjectIter->second->Connect(true);
800                                                         
801                                                         ExitLoop = true;
802                                                         break;
803                                                         
804                                                 } else {
805                                                         
806                                                         ExitLoop = true;                                                        
807                                                         iter->second = 2;
808                                                         break;
809                                                         
810                                                 }
811                                                 
812                                         }
813                                         
814                                         if (iter->second == 2 || iter->second == 3 || iter->second == 4){
815                                                 break;
816                                         }
817                                         
818                                         COServerResponse ETagGetResponse = ConnObjectIter->second->GetServerEntityTagValue(StringURLIter->second.ToStdString());
819                                         
820                                         if (ETagGetResponse.RequestResult != COREQUEST_OK){
821                                                 iter->second = 2;
822                                                 break;
823                                         }
824                                         
825                                         ETagServer = ETagGetResponse.EntityTag;
826                                         
827                                         // Compare the ETag with the Server ETag.
828                                         
829                                         std::cout << ETagOriginal << std::endl;
830                                         std::cout << ETagServer << std::endl;
831                                         
832                                         if (ETagOriginal != ETagServer){
833                                                 
834                                                 // Server ETag is different from original ETag.
835                                                 // This is a conflict which the user will now
836                                                 // need to resolve.
837                                                 
838                                                 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
839                                                 
840                                                 vCard34Conv vCard34Obj;
841                                                 
842                                                 std::string ServerContactData;
843                                                 wxString wxStringServerContactData;
844                                                 vCard ClientData;
845                                                 vCard ConvertedV4Data;
846                                                 
847                                                 // Load the client data from the filename given.
848                                                 
849                                                 //ConnHandle.GetServerContactData();
850                                                 //ServerContactData = ConnHandle.GetPageData();
851                                                 
852                                                 COServerResponse GetContactResponse = ConnObjectIter->second->GetContact(StringURLIter->second.ToStdString(),
853                                                         &ServerContactData);
854                                                 
855                                                 if (GetContactResponse.RequestResult != COREQUEST_OK){
856                                                         iter->second = 2;
857                                                         break;
858                                                 }
859                                                 
860                                                 wxStringServerContactData = wxString::FromUTF8((const char*)ServerContactData.c_str());
861                                                 
862                                                 // Process v3 version into v4 version.
863                                                 
864                                                 vCard34Obj.ConvertToV4(&wxStringServerContactData, &ConvertedV4Data);
865                                                 
866                                                 vCardConflictObj vCardProcData;
867                                                 
868                                                 vCardProcData.vCardLocalData = &ClientData;
869                                                 vCardProcData.vCardServerData = &ConvertedV4Data;
870                                                 ClientData.LoadFile(FullFilename);
871                                                 
872                                                 // Setup Conflict Resolution Dialog.
873                                                 
874                                                 // Fetch Data from Server and convert.
875                                                 
876                                                 bool *PauseMode = new bool;
877                                                 int ConflictResult;
878                                                 QRNotif qrn;
879                                                 
880                                                 *PauseMode = TRUE;
881                                                 qrn.QResponse = &ConflictResult;
882                                                 qrn.PausePtr = PauseMode;
883                                                 
884                                                 vCardProcData.QRNotifData = &qrn;
885                                                 
886                                                 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
887                                                 event.SetClientData(&vCardProcData);
888                                                 wxPostEvent(frmMainPtrGet, event);
889                                                 
890                                                 while (*PauseMode == TRUE){
891                                                         SleepFor(250000000);
892                                                 }
893                                                 
894                                                 delete PauseMode;
895                                                 PauseMode = NULL;
896                                                 
897                                                 if (ConflictResult == 0){
898                                                         
899                                                         // Decide Later.
900                                                         
901                                                         iter->second = 4;
902                                                         break;
903                                                         
904                                                 } else if (ConflictResult == 1){
905                                                         
906                                                         // Decided to use client version.
907                                                         
908                                                 } else if (ConflictResult == 2){
909                                                         
910                                                         // Decided to use server version.
911                                                         
912                                                         // Download server version.
913                                                         
914                                                         ConvertedV4Data.WriteFile(FullFilename);
915                                                         
916                                                 }
917                                                 
918                                         } else {
919                                                 
920                                                 // Upload the data to the server.
921                                                 
922                                                 COServerResponse EditContactResponse = ConnObjectIter->second->EditContact(StringURLIter->second.ToStdString(), 
923                                                         StringDataIter->second.ToStdString());
924                                         
925                                                 if (EditContactResponse.RequestResult != COREQUEST_OK){
926                                                         iter->second = 2;
927                                                         break;
928                                                 }
929                                                 
930                                         }
931                                         
932                                         /*while (ExitLoop == FALSE){
933                                                  
934                                                 int ErrorCode = ConnHandle.SSLVerifyTest();
935                                                 
936                                                 if (ErrorCode != CURLE_OK){
937                                                         
938                                                         if (ErrorCode == CURLE_SSL_CACERT ||
939                                                                 ErrorCode == CURLE_PEER_FAILED_VERIFICATION ||
940                                                                 ErrorCode == CURLE_SSL_CONNECT_ERROR){
941                                                                 
942                                                                 // Invalid SSL certificate so bring up a dialog to the user
943                                                                 // explaining what has happened and the options available.
944                                                                 
945                                                                 // Stop all the timers.
946                                                                 
947                                                                 frmMainPtrGet->PauseAllTimers();
948                                                                 
949                                                                 int SSLResult;
950                                                                 
951 #if defined(__APPLE__)
952                                                                 
953                                                                 // Bring up the trust panel and display the SSL certificate dialog.
954                                                                 
955                                                                 SSLResult = DisplayTrustPanel(ConnHandle.GetTrustObject(), AccountNameFriendly);
956                                                                 
957                                                                 // Update the SSL account with the trust object.
958                                                                 
959                                                                 if (SSLResult != NSOKButton){
960                                                                         
961                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetTrustObject());
962                                                                         iter->second = 2;
963                                                                         break;
964                                                                         
965                                                                 } else {
966                                                                         
967                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
968                                                                         
969                                                                 }
971 #elif defined(__WIN32__)
973                                                                 BOOL ModifiedCertificateData;
974                                                                 CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(&ConnHandle, (HWND)frmMainPtrGet->GetHandle());
976                                                                 if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)){
977                                                                         wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog"));
978                                                                 }
980                                                                 if (ModifiedCertificateData == FALSE){
982                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetCertificateContextPointer());
983                                                                         iter->second = 2;
984                                                                         break;
986                                                                 } else {
988                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer());
990                                                                 }
992 #else
993                                                                 
994                                                                 // Setup the data to be sent in the wxPostEvent command.
995                                                                 
996                                                                 SSLInvalidCertNotifObj SSLICNProcData;
997                                                                 
998                                                                 SSLCertCollection certcol = ConnHandle.GetSSLVerifyResults();
999                                                                 
1000                                                                 bool *PauseMode = new bool;
1001                                                                 QRNotif qrn;
1002                                                                 
1003                                                                 *PauseMode = TRUE;
1004                                                                 qrn.QResponse = &SSLResult;
1005                                                                 qrn.PausePtr = PauseMode;
1006                                                                 
1007                                                                 SSLICNProcData.CertCollection = certcol;
1008                                                                 SSLICNProcData.QRNotifData = &qrn;
1009                                                                 SSLICNProcData.AccountName = AccountNameFriendly;
1010                                                                 
1011                                                                 wxCommandEvent event(INVALIDSSLCERT);
1012                                                                 event.SetClientData(&SSLICNProcData);
1013                                                                 wxPostEvent(frmMainPtrGet, event);
1014                                                                 
1015                                                                 while (*PauseMode == TRUE){
1016                                                                         //nanosleep(&n1, &n2);
1017                                                                         SleepFor(250000000);
1018                                                                 }
1019                                                                 
1020                                                                 // Process the response from the user.
1021                                                                 
1022                                                                 if (SSLResult == 1){
1023                                                                         
1024                                                                         // Accept the certificate. Write the certificate into the account
1025                                                                         // directory (as server.crt) - will overwrite old certificate.
1026                                                                         
1027                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetSSLVerifyResults());
1028                                                                         WriteServerCertificate(AccountDir, ConnHandle.GetSSLVerifyResults());
1029                                                                         
1030                                                                 } else if (SSLResult == 2){
1031                                                                         
1032                                                                         // Reject the certificate, abort the task and mark as failed.
1033                                                                         
1034                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetSSLVerifyResults());
1035                                                                         iter->second = 2;
1036                                                                         break;
1037                                                                         
1038                                                                 }
1039                                                                 
1040 #endif
1041                                                                 
1042                                                                 // Resume all the timers.
1043                                                                 
1044                                                                 frmMainPtrGet->ResumeAllTimers();
1045                                                                 ExitLoop = TRUE;
1046                                                                 
1047                                                         } else {
1048                                                                 
1049                                                                 iter->second = 2;
1050                                                                 break;
1051                                                                 
1052                                                         }
1053                                                         
1054                                                 } else {
1055                                                         
1056                                                         ExitLoop = TRUE;
1057                                                         
1058                                                 }
1059                                                 
1060                                         }
1061                                         
1062                                         if (iter->second == 2 || iter->second == 3 || iter->second == 4){
1063                                                 break;
1064                                         }
1065                                         
1066 #if defined(__APPLE__)
1067                                         
1068                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
1070 #elif defined(__WIN32__)
1072                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer());
1074 #else
1075                                         
1076                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetSSLVerifyResults());
1077                                         
1078 #endif
1079                                         
1080                                         ConnHandle.SetUploadMode(TRUE);
1081                                         ConnHandle.SetupData(wxT("PUT"), StringURLIter->second, StringDataIter->second);
1082                                         ConnHandle.SetEditMode(EditMode);
1083                                         ConnHandle.GetServerETagValueThread();
1084                                         ETagServer = ConnHandle.ETagValueResult();
1086                                         int ErrorCode = ConnHandle.GetResultCode();
1088                                         if (ErrorCode != CURLE_OK){
1089                                                 iter->second = 2;
1090                                                 break;
1091                                         }
1093                                         // Compare the ETag with the Server ETag.
1094                                         
1095                                         if (ETagOriginal != ETagServer){
1096                                                 
1097                                                 // Server ETag is different from original ETag.
1098                                                 // This is a conflict which the user will now
1099                                                 // need to resolve.
1100                                                 
1101                                                 vCard Moo1;
1102                                                 vCard Moo2;
1103                                                 
1104                                                 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
1105                                                 
1106                                                 vCard34Conv vCard34Obj;
1107                                                 
1108                                                 wxString ServerContactData;
1109                                                 vCard ClientData;
1110                                                 vCard ConvertedV4Data;
1111                                                 
1112                                                 // Load the client data from the filename given.
1113                                                 
1114                                                 ConnHandle.GetServerContactData();
1115                                                 ServerContactData = ConnHandle.GetPageData();
1116                                                 
1117                                                 // Process v3 version into v4 version.
1118                                                 
1119                                                 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
1120                                                 
1121                                                 vCardConflictObj vCardProcData;
1122                                                 
1123                                                 vCardProcData.vCardLocalData = &ClientData;
1124                                                 vCardProcData.vCardServerData = &ConvertedV4Data;
1125                                                 ClientData.LoadFile(FullFilename);
1126                                                 
1127                                                 //ContactConflictEvent event(ContactConflictCmdEnv);
1128                                                 //event.SetData(ContactFilename, Moo1, Moo2);
1129                                                 
1130                                                 //wxPostEvent(frmMainPtrGet, event);
1131                                                 
1132                                                 // Setup Conflict Resolution Dialog.
1133                                                 
1134                                                 // Fetch Data from Server and convert.
1135                                                 
1136                                                 bool *PauseMode = new bool;
1137                                                 int ConflictResult;
1138                                                 QRNotif qrn;
1139                                                 
1140                                                 *PauseMode = TRUE;
1141                                                 qrn.QResponse = &ConflictResult;
1142                                                 qrn.PausePtr = PauseMode;
1143                                                 
1144                                                 vCardProcData.QRNotifData = &qrn;
1145                                                 
1146                                                 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
1147                                                 event.SetClientData(&vCardProcData);
1148                                                 wxPostEvent(frmMainPtrGet, event);
1149                                                 
1150                                                 while (*PauseMode == TRUE){
1151                                                         //nanosleep(&n1, &n2);
1152                                                         SleepFor(250000000);
1153                                                 }
1154                                                 
1155                                                 delete PauseMode;
1156                                                 PauseMode = NULL;
1157                                                 
1158                                                 //intResult = frmMainPtrGet->ShowConflictDialog(&Moo1, &Moo2);
1159                                                 
1160                                                 if (ConflictResult == 0){
1161                                                         
1162                                                         // Decide Later.
1163                                                         
1164                                                         iter->second = 4;
1165                                                         break;
1166                                                         
1167                                                 } else if (ConflictResult == 1){
1168                                                         
1169                                                         // Decided to use client version.
1170                                                         
1171                                                         //ConnHandle.ProcessData();
1172                                                         
1173                                                 } else if (ConflictResult == 2){
1174                                                         
1175                                                         // Decided to use server version.
1176                                                         
1177                                                         // Download server version.
1178                                                         
1179                                                         ConvertedV4Data.WriteFile(FullFilename);
1180                                                         
1181                                                 }
1182                                                 
1183                                         } else {
1184                                                 
1185                                                 // Update the data to the server.
1186                                                 
1187                                                 ConnHandle.ProcessData();
1188                                                 
1189                                         }*/
1190                                         
1191                                         // Update the ETag DB.
1192                                         
1193                                         //ConnHandle.GetServerETagValueThread();
1194                                         //ETagServer = ConnHandle.ETagValueResult();
1195                                         
1196                                         ETagGetResponse = ConnObjectIter->second->GetServerEntityTagValue(StringURLIter->second.ToStdString());
1197                                         
1198                                         if (ETagGetResponse.RequestResult != COREQUEST_OK){
1199                                                 iter->second = 2;
1200                                                 break;
1201                                         }
1202                                         
1203                                         std::cout << "Etag Update!" << std::endl;
1204                                         std::cout << ETagGetResponse.EntityTag << std::endl;
1205                                         
1206                                         ETagDBPtr->UpdateETag(ContactFilename, ETagGetResponse.EntityTag, ETagGetResponse.EntityTag);
1207                                         
1208                                         iter->second = 4;
1209                                         break;
1210                                         
1211                                 }
1212                         
1213                         } else if (TypeIter->second == 2) {
1214                         
1215                                 // Delete the contact from the server and update the ETag DB.
1216                                 
1217                                 AccountDir = StringAccountIter->second;
1218                                 ContactFilename = StringFilenameIter->second;
1219                                 wxString AccountNameFriendly;
1220                                 
1221                                 int AccountID = 0;
1222                                 
1223                                 for (int i = 0; i < PrefData.accounts.GetCount(); i++){
1224                                         
1225                                         wxString AccountDirCheck = PrefData.accounts.GetAccountDirectory(i);
1226                                         
1227                                         AccountDirCheck.Trim();
1228                                         AccountDirCheck.Append(wxT(".carddav"));
1229                                         
1230                                         if (AccountDirCheck == StringAccountIter->second){
1231                                                 
1232                                                 AccountNameFriendly = PrefData.accounts.GetAccountName(i);
1233                                                 AccountID = i;
1234                                                 
1235                                         }
1236                                         
1237                                 }
1238                                 
1239                                 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
1240                                 
1241                                 bool KeepUpdating = TRUE;
1242                                 
1243                                 while(KeepUpdating == TRUE){
1244                                 
1245                                         bool ExitLoop = FALSE;
1246                                         
1247                                         while (ExitLoop == FALSE){
1248                                                 
1249                                                 int ErrorCode = ConnHandle.SSLVerifyTest();
1251                                                 if (ErrorCode != CURLE_OK){
1252                                                         
1253                                                         if (ErrorCode == CURLE_SSL_CACERT ||
1254                                                                 ErrorCode == CURLE_PEER_FAILED_VERIFICATION ||
1255                                                                 ErrorCode == CURLE_SSL_CONNECT_ERROR){
1256                                                                 
1257                                                                 // Invalid SSL certificate so bring up a dialog to the user
1258                                                                 // explaining what has happened and the options available.
1259                                                                 
1260                                                                 // Stop all the timers.
1261                                                                 
1262                                                                 frmMainPtrGet->PauseAllTimers();
1263                                                                 
1264                                                                 int SSLResult;
1265                                                                 
1266 #if defined(__APPLE__)
1267                                                                 
1268                                                                 // Bring up the trust panel and display the SSL certificate dialog.
1269                                                                 
1270                                                                 SSLResult = DisplayTrustPanel(ConnHandle.GetTrustObject(), AccountNameFriendly);
1271                                                                 
1272                                                                 // Update the SSL account with the trust object.
1273                                                                 
1274                                                                 if (SSLResult != NSOKButton){
1275                                                                         
1276                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetTrustObject());
1277                                                                         iter->second = 2;
1278                                                                         break;
1279                                                                         
1280                                                                 } else {
1281                                                                         
1282                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
1283                                                                         
1284                                                                 }
1286 #elif defined(__WIN32__)
1288                                                                 BOOL ModifiedCertificateData;
1289                                                                 CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(&ConnHandle, (HWND)frmMainPtrGet->GetHandle());
1291                                                                 if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)){
1292                                                                         wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog"));
1293                                                                 }
1295                                                                 if (ModifiedCertificateData == FALSE){
1297                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetCertificateContextPointer());
1298                                                                         iter->second = 2;
1299                                                                         break;
1301                                                                 } else {
1303                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer());
1305                                                                 }
1307 #else
1308                                                                 
1309                                                                 // Setup the data to be sent in the wxPostEvent command.
1310                                                                 
1311                                                                 SSLInvalidCertNotifObj SSLICNProcData;
1312                                                                 
1313                                                                 SSLCertCollection certcol = ConnHandle.GetSSLVerifyResults();
1314                                                                 
1315                                                                 bool *PauseMode = new bool;
1316                                                                 QRNotif qrn;
1317                                                                 
1318                                                                 *PauseMode = TRUE;
1319                                                                 qrn.QResponse = &SSLResult;
1320                                                                 qrn.PausePtr = PauseMode;
1321                                                                 
1322                                                                 SSLICNProcData.CertCollection = certcol;
1323                                                                 SSLICNProcData.QRNotifData = &qrn;
1324                                                                 SSLICNProcData.AccountName = AccountNameFriendly;
1325                                                                 
1326                                                                 wxCommandEvent event(INVALIDSSLCERT);
1327                                                                 event.SetClientData(&SSLICNProcData);
1328                                                                 wxPostEvent(frmMainPtrGet, event);
1329                                                                 
1330                                                                 /*timespec n1, n2;
1331                                                                  
1332                                                                         // Fall asleep until we get an response.
1333                                                                  
1334                                                                         n1.tv_sec = 0;
1335                                                                         n1.tv_nsec = 250000000L;*/
1336                                                                 
1337                                                                 while (*PauseMode == TRUE){
1338                                                                         //nanosleep(&n1, &n2);
1339                                                                         SleepFor(250000000);
1340                                                                 }
1341                                                         
1342                                                                 // Process the response from the user.
1343                                                         
1344                                                                 if (SSLResult == 1){
1345                                                                 
1346                                                                         // Accept the certificate. Write the certificate into the account
1347                                                                         // directory (as server.crt) - will overwrite old certificate.
1348                                                                 
1349                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetSSLVerifyResults());
1350                                                                         WriteServerCertificate(AccountDir, ConnHandle.GetSSLVerifyResults());
1351                                                                 
1352                                                                 } else if (SSLResult == 2){
1353                                                                 
1354                                                                 // Reject the certificate, abort the task and mark as failed.
1355                                                                 
1356                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetSSLVerifyResults());
1357                                                                         iter->second = 2;
1358                                                                         break;
1359                                                                 
1360                                                                 }
1361                                                         
1362 #endif
1363                                                         
1364                                                                 // Resume all the timers.
1365                                                         
1366                                                                 frmMainPtrGet->ResumeAllTimers();
1367                                                                 ExitLoop = TRUE;
1368                                                         
1369                                                         } else {
1370                                                         
1371                                                                 iter->second = 4;
1372                                                                 break;
1373                                                         
1374                                                         }
1375                                                 
1376                                                 } else {
1377                                                 
1378                                                         ExitLoop = TRUE;
1379                                                 
1380                                                 }
1381                                         
1382                                         }
1383                                 
1384                                         if (iter->second == 2 || iter->second == 3 || iter->second == 4){
1385                                                 break;
1386                                         }
1387                         
1388 #if defined(__APPLE__)
1389                                 
1390                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
1392 #elif defined(__WIN32__)
1394                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer());
1396 #else
1397                                 
1398                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetSSLVerifyResults());
1399                                 
1400 #endif
1402                                         ConnHandle.SetUploadMode(FALSE);
1403                                         ConnHandle.SetupData(wxT("DELETE"), ContactFilename, wxT(""));
1404                                         ConnHandle.ProcessData();
1405                                         
1406                                         SSLCertCollection certcol = ConnHandle.GetCertificateData();
1408                                         // Check if any errors have occured whilst getting the data.
1410                                         int ErrorCode = ConnHandle.GetResultCode();
1412                                         if (ErrorCode != CURLE_OK){
1413                                                 iter->second = 2;
1414                                                 break;
1415                                         }
1416                                 
1417                                         ETagDBPtr->RemoveETag(ContactFilename);
1418                                 
1419                                         iter->second = 4;
1420                                         CardDAVIter->second = NULL;
1421                                         break;
1422                                 
1423                                 }
1424                         
1425                         } else if (TypeIter->second == 3) {
1427                                 wxString AccountNameFriendly;
1428         
1429                                 int AccountID = 0;
1431                                 for (int i = 0; i < PrefData.accounts.GetCount(); i++){
1432         
1433                                         wxString AccountDirCheck = PrefData.accounts.GetAccountDirectory(i);
1434                 
1435                                         AccountDirCheck.Trim();
1436                                         AccountDirCheck.Append(wxT(".carddav"));
1437         
1438                                         if (AccountDirCheck == StringAccountIter->second){
1439                                         
1440                                                 AccountNameFriendly = PrefData.accounts.GetAccountName(i);
1441                                                 AccountID = i;
1442                 
1443                                         }
1444         
1445                                 }
1446                         
1447                                 bool KeepUpdating = TRUE;
1449                                 while (KeepUpdating == TRUE){
1451                                         StringTaskDetailIter = ActivityListTaskDetail.find(iter->first);
1452                         
1453                                         AccountDir = StringAccountIter->second;
1455                                         ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
1456                                 
1457                                         wxArrayString vCardAdd;
1458                                         wxArrayString vCardDelete;
1459                                         wxArrayString vCardList;
1460                                         wxArrayString vCardUpdateLocal;
1461                                         wxArrayString vCardUpdateRemote;
1462                                         wxArrayString vCardUpdateLog;
1463                                         std::map<wxString,wxString> vCardETag;
1464                                         ContactListData ServerContactList;
1465                                 
1466                                         std::map<wxString,vCardDownloadDataFileClass> vCardDownloadData;
1467                                         //wxArrayString vCardDownload;
1468                                         //std::map<wxString,wxString> vCardDownloadData;
1469                                 
1470                                         // Get the list of vCard files locally.
1471         
1472                                         wxString AccountDirFinal;
1473                                         wxString AccountSyncTokenFilename;
1474                                         wxString SyncTokenLoad;
1475         
1476 #if defined(__HAIKU__)
1477     
1478                                             //preffilename = wxT("noo");
1480 #elif defined(__WIN32__)
1482                                         AccountDirFinal = GetAccountDir(AccountDir, FALSE);
1483                                         AccountSyncTokenFilename = AccountDirFinal;
1484                                         AccountSyncTokenFilename.Append(wxT("synctoken"));
1486 #else
1488                                         AccountDirFinal = GetAccountDir(AccountDir, FALSE);
1489                                         AccountSyncTokenFilename = AccountDirFinal;
1490                                         AccountSyncTokenFilename.Append(wxT("synctoken"));
1491         
1492 #endif
1494                                         // Suppress Error Messages.
1495                                 
1496                                         wxLogNull PleaseDoNotDisturb;
1498                                         wxFFile SyncLoad;
1499                                         SyncLoad.Open(AccountSyncTokenFilename, wxT("r"));
1500                                 
1501                                         if (SyncLoad.IsOpened()){
1502                                 
1503                                                 SyncLoad.ReadAll(&SyncTokenLoad, wxMBConvUTF8());
1504                                                 SyncLoad.Close();
1505                                 
1506                                         }
1508                                         // Get a list of vCard files from the server.
1510                                         // Get the list of vCard files from the ETagDB.
1511                                 
1512                                         std::map<wxString,ETagData> ETagDBData = ETagDBPtr->GetETagData();
1513                                         
1514                                         bool ExitLoop = FALSE;
1516                                         std::map<wxString,FileSyncData> *SCListData = NULL;
1517                                         
1518                                         while (ExitLoop == FALSE){
1519                                 
1520                                                 // Check if any errors have occured whilst getting the data.
1521                                 
1522                                                 int ErrorCode = ConnHandle.SSLVerifyTest();
1523                                 
1524                                                 if (ErrorCode != CURLE_OK){
1525                                         
1526                                                         if (ErrorCode == CURLE_SSL_CACERT ||
1527                                                                 ErrorCode == CURLE_PEER_FAILED_VERIFICATION ||
1528                                                                 ErrorCode == CURLE_SSL_CONNECT_ERROR){
1529                                                 
1530                                                                 // Invalid SSL certificate so bring up a dialog to the user
1531                                                                 // explaining what has happened and the options available.
1532                                                         
1533                                                                 // Stop all the timers.
1534                                                                 
1535                                                                 frmMainPtrGet->PauseAllTimers();
1536                                                         
1537                                                                 int SSLResult;
1539 #if defined(__APPLE__)
1540                                                                 
1541                                                                 // Bring up the trust panel and display the SSL certificate dialog.
1542                                                                 
1543                                                                 SSLResult = DisplayTrustPanel(ConnHandle.GetTrustObject(), AccountNameFriendly);
1544                                 
1545                                                                 // Update the SSL account with the trust object.
1546                                                                 
1547                                                                 if (SSLResult != NSOKButton){
1548                                                                         
1549                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetTrustObject());
1550                                                                         iter->second = 2;
1551                                                                         break;
1552                                                                         
1553                                                                 } else {
1555                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
1556                                                                         
1557                                                                 }
1559 #elif defined(__WIN32__)
1561                                                                 BOOL ModifiedCertificateData;
1562                                                                 CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateData = BuildCertificateData(&ConnHandle, (HWND)frmMainPtrGet->GetHandle());
1564                                                                 if (!CryptUIDlgViewCertificate(&CertificateData, &ModifiedCertificateData)){
1565                                                                         wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog"));
1566                                                                 }
1568                                                                 if (ModifiedCertificateData == FALSE){
1570                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetCertificateContextPointer());
1571                                                                         iter->second = 2;
1572                                                                         break;
1574                                                                 } else {
1576                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer());
1578                                                                 }
1579 #else
1580                                 
1581                                                                 // Setup the data to be sent in the wxPostEvent command.
1583                                                                 SSLInvalidCertNotifObj SSLICNProcData;
1585                                                                 SSLCertCollection certcol = ConnHandle.GetSSLVerifyResults();
1587                                                                 bool *PauseMode = new bool;
1588                                                                 QRNotif qrn;
1590                                                                 *PauseMode = TRUE;                                              
1591                                                                 qrn.QResponse = &SSLResult;
1592                                                                 qrn.PausePtr = PauseMode;
1593                                                                 
1594                                                                 SSLICNProcData.CertCollection = certcol;
1595                                                                 SSLICNProcData.QRNotifData = &qrn;
1596                                                                 SSLICNProcData.AccountName = AccountNameFriendly;
1597                                                         
1598                                                                 wxCommandEvent event(INVALIDSSLCERT);
1599                                                                 event.SetClientData(&SSLICNProcData);
1600                                                                 wxPostEvent(frmMainPtrGet, event);
1601                                         
1602                                                                 /*timespec n1, n2;
1603                                                 
1604                                                                 // Fall asleep until we get an response.
1605                                                 
1606                                                                 n1.tv_sec = 0;
1607                                                                 n1.tv_nsec = 250000000L;*/
1608                                         
1609                                                                 while (*PauseMode == TRUE){
1610                                                                         //nanosleep(&n1, &n2);
1611                                                                         SleepFor(250000000);
1612                                                                 }
1613                                                         
1614                                                                 // Process the response from the user.
1615                                                         
1616                                                                 if (SSLResult == 1){
1617                                                                 
1618                                                                         // Accept the certificate. Write the certificate into the account
1619                                                                         // directory (as server.crt) - will overwrite old certificate.
1621                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetSSLVerifyResults());
1622                                                                         WriteServerCertificate(AccountDir, ConnHandle.GetSSLVerifyResults());
1623                                                                 
1624                                                                 } else if (SSLResult == 2){
1625                                                                 
1626                                                                         // Reject the certificate, abort the task and mark as failed.
1628                                                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 1, ConnHandle.GetSSLVerifyResults());
1629                                                                         iter->second = 2;
1630                                                                         break;
1631                                                                 
1632                                                                 }
1633                                                                 
1634 #endif
1635                                                         
1636                                                                 // Resume all the timers.
1637                                                                 
1638                                                                 frmMainPtrGet->ResumeAllTimers();
1639                                                                 ExitLoop = TRUE;
1640                                                 
1641                                                         } else {
1642                                                         
1643                                                                 iter->second = 4;
1644                                                                 break;
1645                                                         
1646                                                         }
1647                                         
1648                                                 } else {
1649                                         
1650                                                         ExitLoop = TRUE;
1651                                         
1652                                                 }
1653                                         
1654                                         }
1655                                         
1656                                         if (iter->second == 2 || iter->second == 3 || iter->second == 4){
1657                                                 break;
1658                                         }
1659                                 
1660 #if defined(__APPLE__)
1661                                         
1662                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetTrustObject());
1664 #elif defined(__WIN32__)
1666                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetCertificateContextPointer());
1668 #else
1669                                         
1670                                         frmMainPtrGet->UpdateSSLAccountStatus(AccountID, 0, ConnHandle.GetSSLVerifyResults());
1671                         
1672 #endif
1673                                         
1674                                         // Look in directory and see which vCards to add and delete
1675                                 
1676                                         // In short:
1677                                         // vCard exists but not in ETagDB - Add (and upload).
1678                                         // vCard missing but in ETagDB - Delete (from server).
1679                                 
1680                                         // Start by looking for vCards that are not in the ETagDB.
1681                                 
1682                                         wxDir AccDir(AccountDirFinal);
1683                                         wxString AccDirFilename;
1684                                 
1685                                         bool ContinueProcess = AccDir.GetFirst(&AccDirFilename, wxEmptyString, wxDIR_DEFAULT);
1686                                 
1687                                         ServerContactList = ConnHandle.GetContactList(SyncTokenLoad.ToUTF8());
1689                                         int ErrorCode = ConnHandle.GetResultCode();
1691                                         if (ErrorCode != CURLE_OK){
1693                                                 iter->second = 4;
1694                                                 break;
1696                                         }
1698                                         SSLCertCollection certcol = ConnHandle.GetCertificateData();
1700                                         // Create a pointer for the std::map<wxString,FileSyncData>.
1702                                         SCListData = &ServerContactList.ListData;
1704                                         // Process the server data.
1706                                         if (SCListData != NULL){
1708                                                 for (std::map<wxString, FileSyncData>::iterator fsiter = SCListData->begin();
1709                                                         fsiter != SCListData->end(); fsiter++){
1711                                                         // Check the mode of the file before adding.
1713                                                         // Get the HTTP status of the file from the list.
1715                                                         FileSyncData fsd = fsiter->second;
1717                                                         if (fsd.DataFlag == 1){
1719                                                                 // Added or modified contact.
1721                                                                 //vCardAdd.Add(fsiter->first, 1);
1723                                                                 vCardDownloadDataFileClass vCardNewData;
1724                                                                 vCardNewData.DataType = 0;
1725                                                                 vCardDownloadData.insert(std::make_pair(fsiter->first, vCardNewData));
1727                                                                 //} else if (fsd.DataFlag == 1){
1729                                                                 // Contact has been modified on the server.
1731                                                                 //      vCardUpdateLocal.Add(fsiter->first, 1);
1733                                                         }
1734                                                         else if (fsd.DataFlag == 2){
1736                                                                 // Contact has been deleted.
1738                                                                 vCardDelete.Add(fsiter->first, 1);
1740                                                         }
1742                                                 }
1744                                         }
1745                                 
1746                                         // Look for vCards that are missing but in the ETagDB.
1747         
1748                                         for (std::map<wxString,ETagData>::iterator etagiter = ETagDBData.begin();
1749                                                 etagiter != ETagDBData.end(); etagiter++){
1750                                 
1751                                                 // Check if the vCard exists.
1752                                         
1753                                                 if (!wxFileExists(AccountDirFinal + etagiter->first)){
1754                                         
1755                                                         // vCard doesn't exist so mark for deleting.
1756                                         
1757                                                         vCardDelete.Add(etagiter->first, 1);
1758                                         
1759                                                 }
1760                                 
1761                                         }
1763                                         // Compare Server with the ETag DB. Work out which
1764                                         // needs to updated remotely and which needs to be
1765                                         // updated locally.
1767                                         for (std::map<wxString,FileSyncData>::iterator srviter = SCListData->begin();
1768                                                 srviter != SCListData->end(); srviter++){
1770                                                 if (ETagDBData.find(srviter->first) == ETagDBData.end()){
1771                                                         continue;
1772                                                 }
1773                                         
1774                                                 std::map<wxString,ETagData>::iterator lociter = ETagDBData.find(srviter->first);
1775                                 
1776                                                 ETagData etd = lociter->second;
1777                                                 FileSyncData fsd = srviter->second;
1778                                         
1779                                                 wxString ETagSrv = fsd.ETagData;
1781                                                 // Check if the local ETag value has 'DELETED' set and skip
1782                                                 // checking this file if it does.
1783                                         
1784                                                 if (etd.ETagValue == "DELETED"){
1785                                                         
1786                                                         continue;
1787                                                         
1788                                                 }
1789                                                 
1790                                                 // Compare local ETag with original local ETag.
1791                                                 // If different, update to server is required.
1792                                 
1793                                                 if (etd.ETagValue != etd.ETagOrigValue){
1794                                 
1795                                                         // Check if local original ETag is different from server ETag.
1796                                                         // If it is then throw up a conflict resolution dialog.
1797                                 
1798                                                         if (etd.ETagOrigValue != ETagSrv){
1799                                         
1800                                                                 vCard34Conv vCard34Obj;
1801                                                 
1802                                                                 wxString ServerContactData;
1803                                                                 wxString FullFilename;
1804                                                                 vCard ClientData;
1805                                                                 vCard ConvertedV4Data;
1806                                         
1807                                                                 // Conflict. Bring up conflict resolution dialog.
1808                                                         
1809                                                                 // Get the server contact data for comparison.
1810                                                         
1811                                                                 ConnHandle.SetServerFilename(srviter->first);
1812                                                                 ConnHandle.GetServerContactData();
1813                                                                 ServerContactData = ConnHandle.GetPageData();
1814                                                         
1815                                                                 FullFilename = CreateFilenamePath(AccountDirFinal, srviter->first);
1816                                                         
1817                                                                 // Convert it to v4.
1818                                         
1819                                                                 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
1820                                         
1821                                                                 vCardConflictObj vCardProcData;
1822                                         
1823                                                                 vCardProcData.vCardLocalData = &ClientData;
1824                                                                 vCardProcData.vCardServerData = &ConvertedV4Data;
1825                                                         
1826                                                                 // Load the client data from the filename given.
1827                                                         
1828                                                                 ClientData.LoadFile(FullFilename);
1829                                                         
1830                                                                 // Show dialog.
1831                                         
1832                                                                 bool *PauseMode = new bool;
1833                                                                 int ConflictResult;
1834                                                                 QRNotif qrn;
1835                                                                 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
1837                                                                 *PauseMode = TRUE;
1838                                                                 qrn.QResponse = &ConflictResult;
1839                                                                 qrn.PausePtr = PauseMode;
1840                                                 
1841                                                                 vCardProcData.QRNotifData = &qrn;
1842                                         
1843                                                                 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
1844                                                                 event.SetClientData(&vCardProcData);
1845                                                                 wxPostEvent(frmMainPtrGet, event);
1846                                                 
1847                                                                 /*timespec n1, n2;
1848                                                 
1849                                                                 n1.tv_sec = 0;
1850                                                                 n1.tv_nsec = 250000000L;*/
1851                                                 
1852                                                                 while (*PauseMode == TRUE){
1853                                                                         //nanosleep(&n1, &n2);
1854                                                                         SleepFor(250000000);
1855                                                                 }
1856                                         
1857                                                                 delete PauseMode;
1858                                                                 PauseMode = NULL;
1859                                                         
1860                                                                 // If replacing local version, store copy for now.
1861                                                                 // Otherwise upload to server.
1862                                         
1863                                                                 if (ConflictResult == 0){
1864                                         
1865                                                                         // Decide Later.
1866                                         
1867                                                                         continue;
1868                                         
1869                                                                 } else if (ConflictResult == 1){
1870                                         
1871                                                                         // Decided to use client version.
1872                                         
1873                                                                         vCardUpdateLocal.Remove(srviter->first);
1874                                                                         vCardUpdateRemote.Add(srviter->first, 1);                                                               
1875                                         
1876                                                                 } else if (ConflictResult == 2){
1877                                         
1878                                                                         // Decided to use server version.
1879                                                                         // Store the converted downloaded copy for
1880                                                                         // processing later.
1882                                                                         //vCardUpdateLocal.Add(srviter->first, 1);
1883                                                                 
1884                                                                         vCardDownloadDataFileClass vCardNewData;
1885                                                                         vCardNewData.DataType = 1;
1886                                                                         vCardNewData.FileData = ConvertedV4Data.WriteString();
1888                                                                         ConvertedV4Data.WriteFile(FullFilename);
1889                                                                 
1890                                                                         vCardDownloadData.insert(std::make_pair(srviter->first, vCardNewData)); 
1891                                                                 
1892                                                                 
1893                                                                 
1894                                                                 }
1895                                         
1896                                                         } else {
1897                                         
1898                                                                 // Send vCard to the server.
1899                                                 
1900                                                                 vCardUpdateRemote.Add(srviter->first, 1);
1901                                         
1902                                                         }
1903                                 
1904                                                 } else {
1905                                 
1906                                                         // Check if local ETag is different from server ETag.
1907                                                         // If different, obtain the vCard from the server.
1908                                         
1909                                                         if (etd.ETagOrigValue != ETagSrv){
1910                                         
1911                                                                 vCardUpdateLocal.Add(srviter->first, 1);
1912                                         
1913                                                         }
1914                                 
1915                                                 }
1916                         
1917                                         }
1918                                 
1919                                         // Process the vCards that need to be downloaded and added/overwritten.
1920                                 
1921                                         wxString vCardFilenameFinal;
1922                                         wxString vCardOutputData;
1923                                         wxString vCardInputData;
1924                                         wxString ETagFileData;
1925                                         wxFFile vCardFile;
1926                                 
1927                                         for (std::map<wxString,vCardDownloadDataFileClass>::iterator additer = vCardDownloadData.begin();
1928                                                 additer != vCardDownloadData.end(); additer++){
1929                                         
1930                                                 vCardFilenameFinal.Clear();
1931                                                 vCardInputData.Clear();
1932                                                 vCardOutputData.Clear();
1933                                                 ETagFileData.Clear();
1934                                         
1935                                                 vCardFilenameFinal = CreateFilenamePath(AccountDirFinal, additer->first);
1936                                         
1937                                                 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
1938                                         
1939                                                 if (additer->second.DataType == 0){
1940                                         
1941                                                         vCard ConvertedV4Data;
1942                                         
1943                                                         // Grab the file from the server and write the contact out.
1944                                         
1945                                                         vCard34Conv vCard34Obj;
1946                                                 
1947                                                         ConnHandle.SetServerFilename(additer->first);
1948                                                         ConnHandle.GetServerContactData();
1949                                                         vCardInputData = ConnHandle.GetPageData();
1950                                                 
1951                                                         vCard34Obj.ConvertToV4(&vCardInputData, &ConvertedV4Data);
1952                                                 
1953                                                         ConvertedV4Data.WriteFile(vCardFilenameFinal);
1954                                                 
1955                                                         // Update the ETagDB.
1956                                                 
1957                                                         //vCardFile.Open(vCardFilenameFinal, wxT("w"));
1958                                 
1959                                                         //if (vCardFile.IsOpened()){
1960                                 
1961                                                         //      vCardFile.Write(vCardOutputData, wxConvAuto());
1962                                                         //      vCardFile.Close();
1963                                 
1964                                                         //}
1965                                                 
1966                                                         // Get the server ETag.
1967                                                 
1968                                                         wxString ServerETag;
1969                                                         ConnHandle.GetServerETagValueThread();
1970                                                         ServerETag = ConnHandle.ETagValueResult();
1971                                                 
1972                                                         // Add to the ETag Database.
1973                                                 
1974                                                         ETagDBPtr->AddETag(additer->first, ServerETag, ServerETag);
1975                                                 
1976                                                 } else if (additer->second.DataType == 1){
1977                                         
1978                                                         // Write out the contact to the account directory.
1979                                         
1980                                                         vCardFilenameFinal = CreateFilenamePath(AccountDirFinal, additer->first);
1981                                                         vCardOutputData = additer->second.FileData;
1982                                                 
1983                                                         vCardFile.Open(vCardFilenameFinal, wxT("w"));
1984                                 
1985                                                         if (vCardFile.IsOpened()){
1986                                 
1987                                                                 vCardFile.Write(vCardOutputData, wxConvAuto());
1988                                                                 vCardFile.Close();
1989                                 
1990                                                         }
1991                                                 
1992                                                         // Update the ETagDB.
1994                                                         wxString ServerETag;
1995                                                         ConnHandle.GetServerETagValueThread();
1996                                                         ServerETag = ConnHandle.ETagValueResult();
1997                                                 
1998                                                         // Add to the ETag Database.
1999                                                 
2000                                                         ETagDBPtr->AddETag(additer->first, ServerETag, ServerETag);
2001                                                                                         
2002                                                 }
2003                                         }
2004         
2005                                         // Look for vCard files which aren't in the ETagDB.
2006         
2007                                         while(ContinueProcess){
2008                                 
2009                                                 // Check and make sure that the filename ends in .vcf/.vcard
2010                                                 // Skip any file that beings with a dot.
2011                                         
2012                                                 if (AccDirFilename.Left(1) == wxT(".")){
2013                                         
2014                                                         ContinueProcess = AccDir.GetNext(&AccDirFilename);
2015                                                         continue;
2016                                         
2017                                                 }
2018                                         
2019                                                 if (AccDirFilename.Right(4) != wxT(".vcf") && 
2020                                                 AccDirFilename.Right(6) != wxT(".vcard")){
2021                                         
2022                                                         ContinueProcess = AccDir.GetNext(&AccDirFilename);
2023                                                         continue;
2024                                         
2025                                                 }
2026                                 
2027                                                 // Look in the ETagDB for the file.
2028                                         
2029                                                 bool ETagExists = ETagDBPtr->CheckETagExists(AccDirFilename);
2030                                         
2031                                                 if (ETagExists == FALSE){
2032                                         
2033                                                         // Add the vCard to the list to be added.
2034                                                 
2035                                                         vCardAdd.Add(AccDirFilename, 1);
2036                                         
2037                                                 }
2038                                         
2039                                                 ContinueProcess = AccDir.GetNext(&AccDirFilename);
2040                                 
2041                                         }
2042                                 
2043                                         // Process the vCards to add/update to the server.
2044                                 
2045                                         for (int vi = 0; vi < vCardAdd.GetCount(); vi++){
2047                                                 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
2048                                                 ETag = ETagDBPtr->GetETag(vCardAdd[vi]);
2049                                                 ETagOriginal = ETagDBPtr->GetETagOriginal(vCardAdd[vi]);
2050                                                 
2051                                                 ContactFilename = vCardAdd[vi];
2052                                                 FullFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
2054                                                 ContactFilename.Trim();
2055                         
2056                                                 if (ETag == ETagOriginal && ETagDBPtr->ETagExists(vCardAdd[vi])){
2057                         
2058                                                         // Compare the ETag with the Server ETag.
2059                                                 
2060                                                         ConnHandle.SetServerFilename(vCardAdd[vi]);
2061                                                         ConnHandle.GetServerETagValueThread();
2062                                                         ETagServer = ConnHandle.ETagValueResult();
2063                                 
2064                                                         if (ETagOriginal != ETagServer){
2065                                 
2066                                                                 // Server ETag is different from original ETag.
2067                                                                 // This is a conflict which the user will now
2068                                                                 // need to resolve.
2069                                         
2070                                                                 frmMain *frmMainPtrGet = static_cast<frmMain*>(frmMainPtr);
2071                                         
2072                                                                 vCard34Conv vCard34Obj;
2073                                                 
2074                                                                 wxString ServerContactData;
2075                                                                 vCard ClientData;
2076                                                                 vCard ConvertedV4Data;
2077                                         
2078                                                                 // Load the client data from the filename given.
2079                                         
2080                                                                 ConnHandle.GetServerContactData();
2081                                                                 ServerContactData = ConnHandle.GetPageData();
2082                                                 
2083                                                                 // Process v3 version into v4 version.
2084                                                 
2085                                                                 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
2086                                         
2087                                                                 vCardConflictObj vCardProcData;
2088                                         
2089                                                                 vCardProcData.vCardLocalData = &ClientData;
2090                                                                 vCardProcData.vCardServerData = &ConvertedV4Data;
2091                                                                 ClientData.LoadFile(FullFilename);
2093                                                                 //ContactConflictEvent event(ContactConflictCmdEnv);
2094                                                                 //event.SetData(ContactFilename, Moo1, Moo2);
2095                                         
2096                                                                 //wxPostEvent(frmMainPtrGet, event);
2097                                         
2098                                                                 // Setup Conflict Resolution Dialog.
2099                                         
2100                                                                 // Fetch Data from Server and convert.
2101                                         
2102                                                                 bool *PauseMode = new bool;
2103                                                                 int ConflictResult;
2104                                                                 QRNotif qrn;
2106                                                                 *PauseMode = TRUE;                                              
2107                                                                 qrn.QResponse = &ConflictResult;
2108                                                                 qrn.PausePtr = PauseMode;
2109                                                 
2110                                                                 vCardProcData.QRNotifData = &qrn;
2111                                         
2112                                                                 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
2113                                                                 event.SetClientData(&vCardProcData);
2114                                                                 wxPostEvent(frmMainPtrGet, event);
2115                                                 
2116                                                                 /*timespec n1, n2;
2117                                                 
2118                                                                 n1.tv_sec = 0;
2119                                                                 n1.tv_nsec = 250000000L;*/
2120                                                 
2121                                                                 while (*PauseMode == TRUE){
2122                                                                         //nanosleep(&n1, &n2);
2123                                                                         SleepFor(250000000);
2124                                                                 }
2125                                         
2126                                                                 delete PauseMode;
2127                                                                 PauseMode = NULL;
2128                                         
2129                                                                 //intResult = frmMainPtrGet->ShowConflictDialog(&Moo1, &Moo2);
2130                                         
2131                                                                 if (ConflictResult == 0){
2132                                         
2133                                                                         // Decide Later.
2134                                         
2135                                                                         iter->second = 4;
2136                                                                         continue;
2137                                         
2138                                                                 } else if (ConflictResult == 1){
2139                                         
2140                                                                         // Decided to use client version.
2141                                         
2142                                                                         ConnHandle.ProcessData();
2143                                                 
2144                                                                         iter->second = 4;
2145                                         
2146                                                                 } else if (ConflictResult == 2){
2147                                         
2148                                                                         // Decided to use server version.
2149                                                 
2150                                                                         // Download server version.
2151                                                                 
2152                                                                         ConvertedV4Data.WriteFile(CreateFilenamePath(AccountDirFinal, vCardAdd[vi]));
2153                                                 
2154                                                                         iter->second = 4;
2155                                         
2156                                                                 }
2157                                 
2158                                                         } else {
2159                                 
2160                                                                 // Setup the filename for the contact being added.
2161                                                         
2162                                                                 wxString wxSFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
2163                                                                 wxString wxSCardData;
2164                                                                 wxString TaskData;
2165                                                                 //wxString TaskURL;
2166                                                         
2167                                                                 // Load the data from the file.
2168                                                         
2169                                                                 wxFFile wxFCard;
2170                                                                 wxFCard.Open(wxSFilename, wxT("r"));
2171                                 
2172                                                                 if (wxFCard.IsOpened()){
2173                                 
2174                                                                         wxFCard.ReadAll(&wxSCardData, wxConvAuto());
2175                                                                         wxFCard.Close();
2176                                 
2177                                                                 }
2178                                                         
2179                                                                 // Convert the data to v3.
2180                                                         
2181                                                                 vCard34Conv vCard34Obj;
2182                                                         
2183                                                                 vCard34Obj.ConvertToV3(wxSFilename, &TaskData);
2184                                                         
2185                                                                 // Setup the URL address.
2186                                                         
2187                                                                 //TaskURL = StringTaskDetailIter->second + wxT("/") + vCardAdd[vi];
2189                                                                 // Upload the data to the server.
2190                                         
2191                                                                 ConnHandle.SetUploadMode(TRUE);
2192                                                                 ConnHandle.SetupData(wxT("PUT"), vCardAdd[vi], TaskData);
2193                                                                 ConnHandle.ProcessData();
2194                                                         
2195                                                                 // Get the Server ETag and put it in the ETag database.
2196                                                         
2197                                                                 ConnHandle.SetServerFilename(vCardAdd[vi]);
2198                                                                 ConnHandle.GetServerETagValueThread();
2199                                                                 ETagServer = ConnHandle.ETagValueResult();
2200                                 
2201                                                                 ETagDBPtr->AddETag(vCardAdd[vi], ETagServer, ETagServer);
2202                                 
2203                                                         }
2204                         
2205                                                 } else {
2206                         
2207                                                         if (ETagOriginal != ETagServer){
2208                                 
2209                                                                 // Server ETag is different from original ETag.
2210                                                                 // This is a conflict which the user will now
2211                                                                 // need to resolve.
2212                                         
2213                                                                 frmMain *frmMainPtrGet = (frmMain *)frmMainPtr;
2214                                         
2215                                                                 //ContactConflictEvent event(ContactConflictCmdEnv);
2216                                                                 //event.SetData(ContactFilename, Moo1, Moo2);
2217                                         
2218                                                                 vCard34Conv vCard34Obj;
2219                                                 
2220                                                                 wxString ServerContactData;
2221                                                                 vCard ClientData;
2222                                                                 vCard ConvertedV4Data;
2223                                         
2224                                                                 // Load the client data from the filename given.
2225                                         
2226                                                                 ConnHandle.GetServerContactData();
2227                                                                 ServerContactData = ConnHandle.GetPageData();
2228                                                                 ClientData.LoadFile(FullFilename);
2229                                                 
2230                                                                 // Process v3 version into v4 version.
2231                                                 
2232                                                                 vCard34Obj.ConvertToV4(&ServerContactData, &ConvertedV4Data);
2233                                         
2234                                                                 vCardConflictObj vCardProcData;
2235                                         
2236                                                                 vCardProcData.vCardLocalData = &ClientData;
2237                                                                 vCardProcData.vCardServerData = &ConvertedV4Data;
2238                                         
2239                                                                 bool *PauseMode = new bool;
2240                                                                 int ConflictResult;
2241                                                                 QRNotif qrn;
2243                                                                 *PauseMode = TRUE;                                              
2244                                                                 qrn.QResponse = &ConflictResult;
2245                                                                 qrn.PausePtr = PauseMode;
2246                                                 
2247                                                                 vCardProcData.QRNotifData = &qrn;
2248                                         
2249                                                                 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
2250                                                                 event.SetClientData(&vCardProcData);
2251                                                                 wxPostEvent(frmMainPtrGet, event);
2252                                         
2253                                                                 /*timespec n1, n2;
2254                                                 
2255                                                                 n1.tv_sec = 0;
2256                                                                 n1.tv_nsec = 250000000L;*/
2257                                         
2258                                                                 while (*PauseMode == TRUE){
2259                                                                         //nanosleep(&n1, &n2);
2260                                                                         SleepFor(250000000);
2261                                                                 }
2262                                         
2263                                                                 delete PauseMode;
2264                                                                 PauseMode = NULL;
2265                                         
2266                                                                 //intResult = frmMainPtrGet->ShowConflictDialog(&Moo1, &Moo2);
2267                                         
2268                                                                 if (ConflictResult == 0){
2269                                         
2270                                                                         // Decide Later.
2271                                         
2272                                                                         iter->second = 4;
2273                                                                         continue;
2274                                         
2275                                                                 } else if (ConflictResult == 1){
2276                                         
2277                                                                         // Decided to use client version.
2278                                                                 
2279                                                                         ConnHandle.ProcessData();
2280                                                                         //ETagServer = CardDAVIter->second.GetServerETagValueThread();
2281                                                                         //ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
2282                                                 
2283                                                                         iter->second = 4;
2284                                         
2285                                                                 } else if (ConflictResult == 2){
2286                                         
2287                                                                         // Decided to use server version.
2288                                                 
2289                                                                         // Write server version to file.
2290                                                                 
2291                                                                         ConvertedV4Data.WriteFile(CreateFilenamePath(AccountDirFinal, vCardAdd[vi]));
2292                                                 
2293                                                                         iter->second = 4;
2294                                         
2295                                                                 }
2296                                 
2297                                                         } else {
2298                                 
2299                                                                 // Setup the filename for the contact being added.
2300                                                         
2301                                                                 wxString wxSFilename = CreateFilenamePath(AccountDirFinal, vCardAdd[vi]);
2302                                                                 wxString wxSCardData;
2303                                                                 wxString TaskData;
2304                                                                 //wxString TaskURL;
2305                                                         
2306                                                                 // Load the data from the file.
2307                                                         
2308                                                                 wxFFile wxFCard;
2309                                                                 wxFCard.Open(wxSFilename, wxT("r"));
2310                                 
2311                                                                 if (wxFCard.IsOpened()){
2312                                 
2313                                                                         wxFCard.ReadAll(&wxSCardData, wxConvAuto());
2314                                                                         wxFCard.Close();
2315                                 
2316                                                                 }
2317                                                         
2318                                                                 // Convert the data to v3.
2319                                                         
2320                                                                 vCard34Conv vCard34Obj;
2321                                                         
2322                                                                 vCard34Obj.ConvertToV3(wxSFilename, &TaskData);
2323                                                         
2324                                                                 // Setup the URL address.
2325                                                         
2326                                                                 //TaskURL = StringTaskDetailIter->second + wxT("/") + vCardAdd[vi];
2328                                                                 // Upload the data to the server.
2329                                         
2330                                                                 ConnHandle.SetUploadMode(TRUE);
2331                                                                 ConnHandle.SetupData(wxT("PUT"), vCardAdd[vi], TaskData);
2332                                                                 ConnHandle.ProcessData();
2333                                                         
2334                                                                 // Get the Server ETag and put it in the ETag database.
2335                                                         
2336                                                                 ConnHandle.SetServerFilename(vCardAdd[vi]);
2337                                                                 ConnHandle.GetServerETagValueThread();
2338                                                                 ETagServer = ConnHandle.ETagValueResult();
2339                                 
2340                                 
2341                                                                 ETagDBPtr->AddETag(vCardAdd[vi], ETagServer, ETagServer);
2342                                 
2343                                                         }
2344                                         
2345                                                 }
2347                                         }                       
2348                                 
2349                                         // Process the vCards to delete locally.
2350                                 
2351                                         for (int vi = 0; vi < vCardDelete.GetCount(); vi++){
2353                                                 if (!wxRemoveFile(CreateFilenamePath(AccountDirFinal, vCardDelete[vi]))){
2355                                                 } else {
2356                                         
2357                                                         ETagDBPtr->RemoveETag(vCardDelete[vi]);
2358                                         
2359                                                 }
2361                                         }
2362                                 
2363                                         // Process the vCards to delete from the server.
2364                                 
2365                                         std::map<wxString,wxString> *ETagFilenameMap = ETagDBPtr->GetFilenamePointer();
2366                                         std::list<wxString> DeleteList;
2367                                 
2368                                         for (std::map<wxString,wxString>::iterator deliter = ETagFilenameMap->begin();
2369                                                 deliter != ETagFilenameMap->end(); deliter++){
2370                                 
2371                                                 // Look through the ETagDB and find contacts which are marked as DELETED.
2372                                         
2373                                                 if (deliter->second == wxT("DELETED")){
2375                                                         ConnHandle.SetUploadMode(FALSE);
2376                                                         ConnHandle.SetupData(wxT("DELETE"), deliter->first, wxT(""));
2377                                                         ConnHandle.ProcessDataThread();
2378                                         
2379                                                         // Delete the ETag as the file has now been deleted.
2380                                         
2381                                                         DeleteList.push_back(deliter->first);
2382                                         
2383                                                 }
2384                                 
2385                                         }
2386                                         
2387                                         for (std::list<wxString>::iterator removeetagiter = DeleteList.begin();
2388                                              removeetagiter != DeleteList.end(); removeetagiter++){
2389                                         
2390                                                 ETagDBPtr->RemoveETag(*removeetagiter);
2391                                                 
2392                                         }
2393                                 
2394                                         // Write out the update server sync token.
2396                                         wxString ServerSyncToken = ServerContactList.SyncToken;
2397                                 
2398                                         ServerSyncToken.Trim();
2399                                 
2400                                         if (!ServerSyncToken.IsEmpty()){
2401                                 
2402                                                 wxFFile SyncWrite;
2403                                                 SyncWrite.Open(AccountSyncTokenFilename, wxT("w"));
2404                                 
2405                                                 if (SyncWrite.IsOpened()){
2406                                 
2407                                                         SyncWrite.Write(ServerSyncToken, wxConvAuto());
2408                                                         SyncWrite.Close();
2409                                 
2410                                                 }
2411                                 
2412                                         }
2413                                 
2414                                         // Check for another sync token. If there is another 
2415                                         // sync token then repeat this. If token matches then stop processing.
2416                                 
2417                                         if (SyncTokenLoad == ServerSyncToken){
2418                                         
2419                                                 KeepUpdating = FALSE;
2420                                         
2421                                         }
2422                                         
2423                                 }
2424                                 
2425                                 // Mark as completed.
2426                         
2427                                 wxString AccountNameFinal;
2428                                 AccountNameFinal = PrefData.accounts.GetAccountDirectory(AccountID);
2429                                 AccountNameFinal.Append(wxT(".carddav"));
2430                                 
2431                                 wxCommandEvent reloadevent(RELOADCONTACTLIST);
2432                                 reloadevent.SetString(AccountNameFinal);
2433                                 wxPostEvent(this->GetParent(), reloadevent);
2434                                 
2435                                 iter->second = 4;
2436                                 continue;
2437                         
2438                         } else {
2439                         
2440                                 // Update the data to the server.
2441                                         
2442                                 ConnHandle.ProcessData();
2443                                 iter->second = 4;
2444                                 continue;
2445                         
2446                         }
2448                         /*timespec n1, n2;
2449                                                 
2450                         n1.tv_sec = 0;
2451                         n1.tv_nsec = 250000000L;*/
2453                         while (iter->second == 1){
2455                                 SleepFor(125000000);
2456                                 //nanosleep(&n1, &n2);
2457         
2458                         }
2459                         
2460                         /*if ((iter->second == 4 && TypeIter->second == 0) || 
2461                         (iter->second == 8 && TypeIter->second == 0)){
2463                                 AccountDir = StringAccountIter->second;
2464                                 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);
2465                                 
2466                                 ConnHandle.GetServerETagValueThread();
2467                                 ETagServer = ConnHandle.ETagValueResult();
2468                                 ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
2469                         
2470                         }
2471                         
2472                         if ((iter->second == 4 && TypeIter->second == 1) || 
2473                         (iter->second == 8 && TypeIter->second == 1)){
2474                         
2475                                 AccountDir = StringAccountIter->second;
2476                                 ETagDB *ETagDBPtr = ETagTmrPtr->GetPointer(AccountDir);                 
2478                                 ConnHandle.GetServerETagValueThread();
2479                                 ETagServer = ConnHandle.ETagValueResult();
2480                                 ETagDBPtr->UpdateETag(ContactFilename, ETagServer, ETagServer);
2481                         
2482                         }*/
2483                         
2484                         break;
2485                         
2486                 }
2488         }
2489         
2490         if (TasksFoundProc == FALSE){
2491         
2492                 TasksActive = FALSE;
2493                 ProcessTasksData = FALSE;
2494         
2495         } else {
2497                 wxCommandEvent eventp(ACTMGR_STARTTIMER);
2498                 wxPostEvent(this, eventp);
2500                 //AnimationTimer.StartAnimation();
2501                 //ActListProcTimer.Start();
2502         
2503         }
2504         
2505         wxCommandEvent event(ACTMGR_STARTPROCESSTIMER);
2506         wxPostEvent(this, event);
2508         //ActProcessTimer.Start();
2512 void frmActivityMgr::ProcessTasks()
2514         
2515         std::thread ProcessThread(&frmActivityMgr::ProcessTasksThread, this);
2516         ProcessThread.detach();
2520 void frmActivityMgr::SetupPointers(wxETagProcessTimer *ETagTmrPtrInc, void *frmMainPtrInc)
2523         ETagTmrPtr = ETagTmrPtrInc;
2524         
2525         frmMainPtr = frmMainPtrInc;
2529 void frmActivityMgr::ResumeProcessing(wxCommandEvent &event){
2531         QRNotif *qrn = (QRNotif *)event.GetClientData(); 
2532         
2533         int *QRes = qrn->QResponse;
2535         *qrn->PausePtr = FALSE;
2537         *QRes = event.GetInt();
2538         
2541 void frmActivityMgr::ToggleConnectionStatus( wxCommandEvent &event ){
2543         wxCommandEvent connevent(CONNSTAT_UPDATE);
2544         
2545         if (ApplicationSleepMode == FALSE){
2546         
2547                 connevent.SetInt(1);
2548                 ApplicationSleepMode = TRUE;
2549                 mnuSleepMode->Check(true);
2550         
2551         } else {
2552         
2553                 connevent.SetInt(0);
2554                 ApplicationSleepMode = FALSE;
2555                 mnuSleepMode->Check(false);
2556                 
2557                 wxCommandEvent event(ACTMGR_STARTTIMER);
2558                 wxPostEvent(this, event);
2560                 wxCommandEvent eventp(ACTMGR_STARTPROCESSTIMER);
2561                 wxPostEvent(this, eventp);
2562         
2563         }
2565         wxPostEvent(GetParent(), connevent);
2569 void frmActivityMgr::SleepMode( wxCommandEvent &event ){
2570         
2571         wxCommandEvent connevent(ACTMGR_TOGGLECONN);
2572         
2573         wxPostEvent(this, connevent);
2574         
2577 void frmActivityMgr::WriteServerCertificate(wxString AccountName, SSLCertCollection SSLCertInc){
2579         wxString ServerCertFinal;
2581         // Get the Cert section of the certificate and write it to the file.
2583         ServerCertFinal = GetAccountDir(AccountName, TRUE);
2585         wxFile CertFile;
2586         
2587         std::map<int, SSLCertData>::iterator SSLCDIter = SSLCertInc.SSLCollection.find(0);
2588         std::multimap<wxString,wxString>::iterator SSLDataIter = SSLCDIter->second.CertData.find(wxT("Cert"));
2589         
2590         CertFile.Open(ServerCertFinal, wxFile::write);  
2591         
2592         CertFile.Write(SSLDataIter->second, wxConvUTF8);
2593         CertFile.Close();
2597 void frmActivityMgr::WriteServerCertificate(wxString AccountName, SSLCertCollectionString SSLCertInc){
2599         wxString ServerCertFinal;
2601         // Get the Cert section of the certificate and write it to the file.
2603         ServerCertFinal = GetAccountDir(AccountName, TRUE);
2605         wxFile CertFile;
2606         
2607         std::map<int, SSLCertDataString>::iterator SSLCDIter = SSLCertInc.SSLCollection.find(0);
2608         std::multimap<string,string>::iterator SSLDataIter = SSLCDIter->second.CertData.find("Cert");
2609         
2610         CertFile.Open(ServerCertFinal, wxFile::write);  
2611         
2612         CertFile.Write(SSLDataIter->second, wxConvUTF8);
2613         CertFile.Close();
2617 void frmActivityMgr::StartTimer(wxCommandEvent& event){
2619         ActListProcTimer.Start(1000, FALSE);
2623 void frmActivityMgr::StopTimer(wxCommandEvent& event){
2625         ActListProcTimer.Stop();
2629 void frmActivityMgr::StartProcessTimer(wxCommandEvent& event){
2631         ActProcessTimer.Start(1000, FALSE);
2635 void frmActivityMgr::StopProcessTimer(wxCommandEvent& event){
2637         ActProcessTimer.Stop();
2641 void frmActivityMgr::StartAnimationTimer(wxCommandEvent& event){
2642         
2643         AnimationTimer.StartAnimation();
2644         
2647 void frmActivityMgr::UpdateStatusLabel(wxCommandEvent& event){
2649         ActivityMgrLabelUpdate *actmgrudata = (ActivityMgrLabelUpdate*)event.GetClientData();
2650         
2651         if (actmgrudata != NULL){
2652         
2653                 lstActivity->SetItem(actmgrudata->ItemIndex, 2, actmgrudata->ItemLabel);
2654         
2655                 /*if (!actmgrudata->ItemDes.IsEmpty()){
2656                 lstActivity->SetItem(actmgrudata->ItemIndex, 0, actmgrudata->ItemDes);
2657                 }*/
2658         
2659                 delete actmgrudata;
2660                 actmgrudata = NULL;
2661         
2662         }
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